@predictasiax/api 2.1.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @predictasiax/api Changelog
2
2
 
3
+ ## v2.2.0 — 2026-09-05
4
+
5
+ **Trust Layer — public Merkle verifier.**
6
+
7
+ ### Added
8
+ - **`pax.audit`** — new resource for the public no-auth verifier surface. Any
9
+ third party (auditor / investor / external verifier) can independently
10
+ reconstruct the hash-chained event log + Merkle batches + R2 anchors without
11
+ trusting the PAX API at all.
12
+ - **`pax.audit.status()`** — live counts: total events, batches, anchored,
13
+ anchor lag, publisher mode.
14
+ - **`pax.audit.latestBatch()`** — most recent Merkle batch metadata.
15
+ - **`pax.audit.getBatch(batchNum)`** — inspect any historical batch.
16
+ - **`pax.audit.getEvent(seq)`** — inspect one event (payload, event_hash,
17
+ prev_event_hash — full hash-chain surface).
18
+ - **`pax.audit.getProof(seq)`** — Merkle inclusion proof (sibling hashes)
19
+ proving the event is in its batch's `merkle_root`. Algo: OpenZeppelin
20
+ sorted-pair sha256 — Solidity-compatible for on-chain verification.
21
+ - **`pax.audit.getAnchor(batchNum)`** — resolve to external anchor URL
22
+ (R2 signed payload) for out-of-band verification.
23
+ - **`AuditResource.verifyProof(leaf, root, proof)`** — Node-side local
24
+ verification helper.
25
+ - **`AuditResource.verifyProofAsync(leaf, root, proof)`** — WebCrypto
26
+ variant for browsers / edge runtimes.
27
+ - **New types**: `AuditStatus`, `AuditBatch`, `AuditEvent`, `MerkleProof`.
28
+
29
+ ### Why this matters
30
+ Polymarket and OPINION Labs both publish smart-contract audit PDFs, but
31
+ neither exposes a live public verifier over their operational ledger. PAX now
32
+ does — auditors can chain-verify every fill without contacting PAX support.
33
+
34
+ ## v2.1.0 — 2026-09-05
3
35
  ## v2.1.0 — 2026-09-05
4
36
 
5
37
  **Polymarket-parity + surpass surface.**
package/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  APIPromise: () => APIPromise,
34
34
  AccountResource: () => AccountResource,
35
35
  ApplyResource: () => ApplyResource,
36
+ AuditResource: () => AuditResource,
36
37
  CursorPage: () => CursorPage,
37
38
  FeesResource: () => FeesResource,
38
39
  GrantsResource: () => GrantsResource,
@@ -364,7 +365,7 @@ async function runWithRetry(fn, opts = {}) {
364
365
  }
365
366
 
366
367
  // src/http.ts
367
- var VERSION = "2.1.0";
368
+ var VERSION = "2.2.0";
368
369
  var ENV_URLS = {
369
370
  production: "https://api.predictasiax.com/v1",
370
371
  prod: "https://api.predictasiax.com/v1",
@@ -785,6 +786,72 @@ var AccountResource = class extends Resource {
785
786
  }
786
787
  };
787
788
 
789
+ // src/resources/audit.ts
790
+ var AuditResource = class extends Resource {
791
+ status(opts) {
792
+ return this._apiPromise(
793
+ () => this._http.request("GET", "/v1/audit/status", void 0, void 0, opts)
794
+ );
795
+ }
796
+ latestBatch(opts) {
797
+ return this._apiPromise(
798
+ () => this._http.request("GET", "/v1/audit/batches/latest", void 0, void 0, opts)
799
+ );
800
+ }
801
+ getBatch(batchNum, opts) {
802
+ return this._apiPromise(
803
+ () => this._http.request("GET", `/v1/audit/batches/${batchNum}`, void 0, void 0, opts)
804
+ );
805
+ }
806
+ getEvent(seq, opts) {
807
+ return this._apiPromise(
808
+ () => this._http.request("GET", `/v1/audit/events/${seq}`, void 0, void 0, opts)
809
+ );
810
+ }
811
+ getProof(seq, opts) {
812
+ return this._apiPromise(
813
+ () => this._http.request("GET", `/v1/audit/proof/${seq}`, void 0, void 0, opts)
814
+ );
815
+ }
816
+ getAnchor(batchNum, opts) {
817
+ return this._apiPromise(
818
+ () => this._http.request("GET", `/v1/audit/anchor/${batchNum}`, void 0, void 0, opts)
819
+ );
820
+ }
821
+ /**
822
+ * Verify a Merkle inclusion proof locally (client-side). Mirrors
823
+ * OpenZeppelin's sorted-pair sha256 algorithm — identical logic to the
824
+ * server-side batcher, so callers can independently confirm inclusion
825
+ * without trusting the API response.
826
+ */
827
+ static verifyProof(leaf, root, proof) {
828
+ const crypto = globalThis.crypto || require("crypto");
829
+ let hash = leaf;
830
+ for (const sibling of proof) {
831
+ const [a, b] = hash < sibling ? [hash, sibling] : [sibling, hash];
832
+ if (crypto.subtle && typeof crypto.subtle.digest === "function") {
833
+ throw new Error("Use verifyProofAsync() in browser/edge runtimes (WebCrypto is async)");
834
+ }
835
+ hash = crypto.createHash("sha256").update(a + b).digest("hex");
836
+ }
837
+ return hash === root;
838
+ }
839
+ /** Async variant using WebCrypto — works in browsers, Deno, Bun, edge runtimes. */
840
+ static async verifyProofAsync(leaf, root, proof) {
841
+ const enc = new TextEncoder();
842
+ async function sha(s) {
843
+ const buf = await globalThis.crypto.subtle.digest("SHA-256", enc.encode(s));
844
+ return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
845
+ }
846
+ let hash = leaf;
847
+ for (const sibling of proof) {
848
+ const [a, b] = hash < sibling ? [hash, sibling] : [sibling, hash];
849
+ hash = await sha(a + b);
850
+ }
851
+ return hash === root;
852
+ }
853
+ };
854
+
788
855
  // src/resources/fees.ts
789
856
  var FeesResource = class extends Resource {
790
857
  estimate(params, opts) {
@@ -1098,6 +1165,55 @@ var ApplyResource = class extends Resource {
1098
1165
  var SandboxResource = class extends Resource {
1099
1166
  };
1100
1167
 
1168
+ // src/resources/settle.ts
1169
+ var SettleResource = class extends Resource {
1170
+ /** Builder self-serve settle — POST /v1/builders/me/settle. */
1171
+ me(params, opts) {
1172
+ const body = {
1173
+ address: params.address,
1174
+ asset: params.asset ?? "USDT",
1175
+ network: params.network ?? "polygon",
1176
+ min_amount: params.min_amount ?? 0
1177
+ };
1178
+ return this._apiPromise(
1179
+ () => this._http.request("POST", "/v1/builders/me/settle", void 0, body, opts)
1180
+ );
1181
+ }
1182
+ /** Admin settle a specific builder's fees — POST /v1/admin/builders/{userId}/settle.
1183
+ * Requires X-Admin-Key header. */
1184
+ adminBuilder(userId, params, adminKey, opts) {
1185
+ const body = {
1186
+ address: params.address,
1187
+ asset: params.asset ?? "USDT",
1188
+ network: params.network ?? "polygon",
1189
+ min_amount: params.min_amount ?? 0
1190
+ };
1191
+ const mergedOpts = {
1192
+ ...opts || {},
1193
+ headers: { ...opts?.headers || {}, "X-Admin-Key": adminKey }
1194
+ };
1195
+ return this._apiPromise(
1196
+ () => this._http.request("POST", `/v1/admin/builders/${encodeURIComponent(userId)}/settle`, void 0, body, mergedOpts)
1197
+ );
1198
+ }
1199
+ /** Admin settle a market creator's fees — POST /v1/admin/creators/{userId}/settle. */
1200
+ adminCreator(userId, params, adminKey, opts) {
1201
+ const body = {
1202
+ address: params.address,
1203
+ asset: params.asset ?? "USDT",
1204
+ network: params.network ?? "polygon",
1205
+ min_amount: params.min_amount ?? 0
1206
+ };
1207
+ const mergedOpts = {
1208
+ ...opts || {},
1209
+ headers: { ...opts?.headers || {}, "X-Admin-Key": adminKey }
1210
+ };
1211
+ return this._apiPromise(
1212
+ () => this._http.request("POST", `/v1/admin/creators/${encodeURIComponent(userId)}/settle`, void 0, body, mergedOpts)
1213
+ );
1214
+ }
1215
+ };
1216
+
1101
1217
  // src/resources/templates.ts
1102
1218
  var TemplatesResource = class extends Resource {
1103
1219
  list(params = {}, opts) {
@@ -1134,6 +1250,10 @@ var PaxClient = class {
1134
1250
  grants;
1135
1251
  fees;
1136
1252
  // v2.1+: GET /v1/fees/estimate
1253
+ audit;
1254
+ // v2.2+: public Merkle chain verifier (no-auth)
1255
+ settle;
1256
+ // v2.4+: claim accrued fee revenue
1137
1257
  constructor(opts) {
1138
1258
  this._http = new HttpClient(opts);
1139
1259
  this.markets = new MarketsResource(this._http);
@@ -1146,6 +1266,8 @@ var PaxClient = class {
1146
1266
  this.apply = new ApplyResource(this._http);
1147
1267
  this.grants = new GrantsResource(this._http);
1148
1268
  this.fees = new FeesResource(this._http);
1269
+ this.audit = new AuditResource(this._http);
1270
+ this.settle = new SettleResource(this._http);
1149
1271
  }
1150
1272
  get baseUrl() {
1151
1273
  return this._http.baseUrl;
@@ -1418,6 +1540,7 @@ var PaxWSClient = class {
1418
1540
  APIPromise,
1419
1541
  AccountResource,
1420
1542
  ApplyResource,
1543
+ AuditResource,
1421
1544
  CursorPage,
1422
1545
  FeesResource,
1423
1546
  GrantsResource,