@predictasiax/api 2.2.0 → 2.5.1
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 +56 -0
- package/README.md +33 -22
- package/dist/index.cjs +348 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -10
- package/dist/index.d.ts +128 -10
- package/dist/index.js +0 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @predictasiax/api Changelog
|
|
2
2
|
|
|
3
|
+
## v2.5.1 — 2026-10-31
|
|
4
|
+
|
|
5
|
+
**Bugfix: Merkle inclusion-proof verifier now hashes raw bytes, not hex strings —
|
|
6
|
+
and `verifyProof()` no longer crashes under native ESM.**
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- `Audit.verifyProof()` / `verifyProofAsync()` previously hashed the 64-character
|
|
10
|
+
hex **strings** of each digest (UTF-8 bytes), instead of decoding each hex
|
|
11
|
+
digest to its raw 32 bytes first. The publisher builds `merkle_root` as a
|
|
12
|
+
sorted-pair SHA-256 over the **raw 32-byte digests**, so the SDK computed a
|
|
13
|
+
different root and rejected every authentic proof returned by
|
|
14
|
+
`/v1/audit/proof/{seq}`. Fail-closed — the bug could only reject valid proofs,
|
|
15
|
+
never accept a forged one, so no verification was ever falsely passed.
|
|
16
|
+
- Both code paths now decode hex to raw bytes, sort the pair by byte value,
|
|
17
|
+
concat the raw bytes, then SHA-256 — bit-identical to the publisher and to
|
|
18
|
+
OpenZeppelin's `bytes32` `MerkleProof.verify`. Proofs from the live API now
|
|
19
|
+
verify locally.
|
|
20
|
+
- `verifyProof()` (the synchronous variant) previously called `require("crypto")`,
|
|
21
|
+
which throws `Dynamic require of "crypto" is not supported` in the ESM build
|
|
22
|
+
(`dist/index.js`) — so every ESM consumer calling it crashed rather than
|
|
23
|
+
verifying. It is now **isomorphic**: it uses Node's native SHA-256 when a
|
|
24
|
+
synchronous `require` is available (CommonJS) and otherwise a self-contained,
|
|
25
|
+
dependency-free SHA-256, so it runs unchanged in Node (CJS + ESM), browsers,
|
|
26
|
+
Deno, Bun and edge runtimes. The fallback is pinned by tests to be byte-identical
|
|
27
|
+
to `node:crypto` (fixed vectors + 500 random inputs) and to reconstruct the
|
|
28
|
+
live anchored root. No static `node:` imports were added — the package stays
|
|
29
|
+
safe to import in the browser.
|
|
30
|
+
|
|
31
|
+
### Compatibility
|
|
32
|
+
- Verifier-side only. No change to request signing, wire format, response
|
|
33
|
+
envelopes, or any other resource. Zero new runtime dependencies. Matches
|
|
34
|
+
Python SDK `pax-api` 2.5.1.
|
|
35
|
+
|
|
36
|
+
## v2.5.0 — 2026-09-26
|
|
37
|
+
|
|
38
|
+
**Auth positioning correction + API 2.6.1 compatibility notice.** Content-only release — no wire-format changes vs v2.4.0. All 61 tests unchanged.
|
|
39
|
+
|
|
40
|
+
### Compatibility
|
|
41
|
+
- **Compatible with** PredictAsiaX Trader Track API **v2.5.0 → v2.6.1** (69 paths / 76 operations, current REST surface at docs.predictasiax.com/openapi).
|
|
42
|
+
- No breaking changes since v2.2.0. All resources added in v2.3.0 / v2.4.0 remain shipped and stable in v2.5.0.
|
|
43
|
+
|
|
44
|
+
### Changed — README auth positioning
|
|
45
|
+
- Repositioned **Bearer `sk_live_*` as the standard path** (formerly listed as "Option 1: API Key" with `X-Api-Key`-first framing). Bearer is what 100% of standard integrations should use.
|
|
46
|
+
- **HMAC section demoted to enterprise-only** — clarified that HMAC signing requires ops provisioning of the signing secret and that submitting HMAC credentials without provisioning returns `401 AUTH_INVALID`. Standard integrations should not attempt HMAC.
|
|
47
|
+
- **OAuth 2.1 + PKCE** promoted to a proper `#2` section (was buried at `#3` "Bearer token — browser / mobile").
|
|
48
|
+
- Corrected package description away from "HMAC 5-header signing" as headline feature → Bearer-first framing.
|
|
49
|
+
|
|
50
|
+
### Notes on wire format (unchanged in this release)
|
|
51
|
+
- HMAC header prefix on-wire is still `POLY_*` — backend accepts this as a legacy alias for the canonical `PAX_*` prefix (which the docs and Portal both document as the canonical form). A future SDK release will emit `PAX_*` by default; both prefixes will be accepted server-side indefinitely for backward compat.
|
|
52
|
+
- `X-Api-Key` header is still emitted alongside `Authorization: Bearer` for the api-key auth path — legacy compat, no plan to remove.
|
|
53
|
+
|
|
54
|
+
### CHANGELOG gap acknowledgment
|
|
55
|
+
v2.3.0 and v2.4.0 shipped on npm without changelog entries. The additive resource surface accumulated in those versions (Merkle audit resource, batch orders, fee estimate — see v2.1.0 / v2.2.0 above for the surface added just before that gap) remains stable in v2.5.0.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
3
59
|
## v2.2.0 — 2026-09-05
|
|
4
60
|
|
|
5
61
|
**Trust Layer — public Merkle verifier.**
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @predictasiax/api
|
|
2
2
|
|
|
3
|
-
Official TypeScript / JavaScript SDK for the **PredictAsiaX Trader Track API** — Web3-native prediction markets, REST + WebSocket,
|
|
3
|
+
Official TypeScript / JavaScript SDK for the **PredictAsiaX Trader Track API** — Web3-native prediction markets, REST + WebSocket, Bearer `sk_live_*` auth (HMAC 5-header available for enterprise-provisioned partners), deterministic market IDs, envelope response, public Merkle audit chain.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@predictasiax/api)
|
|
6
6
|
[](https://docs.predictasiax.com)
|
|
@@ -63,46 +63,57 @@ More runnable examples: [`examples/`](./examples).
|
|
|
63
63
|
|
|
64
64
|
## Authentication
|
|
65
65
|
|
|
66
|
-
Three modes, auto-detected from your constructor arguments.
|
|
66
|
+
Three modes, auto-detected from your constructor arguments. **Bearer `sk_live_*` is the standard path for the vast majority of integrations** — read-only aggregators, creator profiles, automated trading, agent frameworks. HMAC 5-header signing is available to enterprise-provisioned partners (contact ops for the signing secret); it is not required for standard use.
|
|
67
67
|
|
|
68
|
-
### 1.
|
|
68
|
+
### 1. Bearer `sk_live_*` (standard — start here)
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`
|
|
73
|
-
production).
|
|
70
|
+
The canonical path. Capability is scoped by the `tier` flag on the key
|
|
71
|
+
(`self_serve` for sandbox testing with $10/$100 caps; `read_live` /
|
|
72
|
+
`trade_capped` / `trade_full` / `genesis` / `partner` for production).
|
|
74
73
|
|
|
75
74
|
```ts
|
|
76
75
|
const pax = new PaxClient({ apiKey: "sk_live_..." });
|
|
77
76
|
```
|
|
78
77
|
|
|
79
|
-
Sent as `
|
|
80
|
-
Tier-mismatched operations
|
|
78
|
+
Sent as `Authorization: Bearer sk_live_...` header (the legacy `X-Api-Key`
|
|
79
|
+
header is still accepted for backward compat). Tier-mismatched operations
|
|
80
|
+
reject with `PaxWrongEnvKeyError`.
|
|
81
81
|
|
|
82
|
-
### 2.
|
|
82
|
+
### 2. OAuth 2.1 bearer token (hosted apps on behalf of a PAX user)
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
Session-based, obtained via `connect.predictasiax.com` OAuth 2.1 + PKCE S256.
|
|
85
|
+
Use for third-party apps acting on behalf of an end user.
|
|
85
86
|
|
|
86
87
|
```ts
|
|
87
|
-
const pax = new PaxClient({
|
|
88
|
-
apiKey: "sk_live_ABC",
|
|
89
|
-
secret: "your-64-char-secret",
|
|
90
|
-
passphrase: "your-passphrase",
|
|
91
|
-
env: "production",
|
|
92
|
-
});
|
|
88
|
+
const pax = new PaxClient({ bearerToken: "eyJ...", env: "production" });
|
|
93
89
|
```
|
|
94
90
|
|
|
95
|
-
Sent as
|
|
91
|
+
Sent as `Authorization: Bearer <token>` header — same wire path as the
|
|
92
|
+
`sk_live_*` bearer, differentiated by token format.
|
|
96
93
|
|
|
97
|
-
### 3.
|
|
94
|
+
### 3. HMAC 5-header (enterprise / ops-provisioned)
|
|
98
95
|
|
|
99
|
-
|
|
96
|
+
Reserved for enterprise partners who need per-request replay guards on top of
|
|
97
|
+
the transport-layer HTTPS. Requires ops provisioning of the HMAC signing
|
|
98
|
+
secret into the server's KV store; any HMAC-shaped credential submitted
|
|
99
|
+
without provisioning returns `401 AUTH_INVALID` with a directive to use
|
|
100
|
+
Bearer. Not required for standard integrations.
|
|
100
101
|
|
|
101
102
|
```ts
|
|
102
|
-
const pax = new PaxClient({
|
|
103
|
+
const pax = new PaxClient({
|
|
104
|
+
apiKey: "sk_live_ABC",
|
|
105
|
+
secret: "your-64-char-secret", // provisioned by ops
|
|
106
|
+
passphrase: "your-passphrase", // provisioned by ops
|
|
107
|
+
env: "production",
|
|
108
|
+
});
|
|
103
109
|
```
|
|
104
110
|
|
|
105
|
-
|
|
111
|
+
Signed with the 5-header pattern. Canonical header prefix is `PAX_*`
|
|
112
|
+
(`PAX_ACCESS_KEY` / `PAX_TIMESTAMP` / `PAX_PASSPHRASE` / `PAX_SIGNATURE`);
|
|
113
|
+
the legacy `POLY_*` prefix is still accepted server-side for backward compat
|
|
114
|
+
and is the format this SDK currently emits — a `PAX_*`-emitting client is
|
|
115
|
+
planned in a future SDK release. Server accepts ±30 s clock skew — sync your
|
|
116
|
+
machine via NTP.
|
|
106
117
|
|
|
107
118
|
---
|
|
108
119
|
|
package/dist/index.cjs
CHANGED
|
@@ -58,8 +58,10 @@ __export(index_exports, {
|
|
|
58
58
|
SandboxResource: () => SandboxResource,
|
|
59
59
|
TemplatesResource: () => TemplatesResource,
|
|
60
60
|
VERSION: () => VERSION2,
|
|
61
|
+
attachRef: () => attachRef,
|
|
61
62
|
buildError: () => buildError,
|
|
62
63
|
buildMessage: () => buildMessage,
|
|
64
|
+
clearRef: () => clearRef,
|
|
63
65
|
computeBackoff: () => computeBackoff,
|
|
64
66
|
runWithRetry: () => runWithRetry,
|
|
65
67
|
signRequest: () => signRequest
|
|
@@ -787,6 +789,166 @@ var AccountResource = class extends Resource {
|
|
|
787
789
|
};
|
|
788
790
|
|
|
789
791
|
// src/resources/audit.ts
|
|
792
|
+
function hexToBytes(hex) {
|
|
793
|
+
const out = new Uint8Array(hex.length / 2);
|
|
794
|
+
for (let i = 0; i < out.length; i++) out[i] = parseInt(hex.substr(i * 2, 2), 16);
|
|
795
|
+
return out;
|
|
796
|
+
}
|
|
797
|
+
function bytesToHex(bytes) {
|
|
798
|
+
let s = "";
|
|
799
|
+
for (let i = 0; i < bytes.length; i++) s += bytes[i].toString(16).padStart(2, "0");
|
|
800
|
+
return s;
|
|
801
|
+
}
|
|
802
|
+
function cmpBytes(a, b) {
|
|
803
|
+
const n = Math.min(a.length, b.length);
|
|
804
|
+
for (let i = 0; i < n; i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
805
|
+
return a.length - b.length;
|
|
806
|
+
}
|
|
807
|
+
function sha256Pure(msg) {
|
|
808
|
+
const K = new Uint32Array([
|
|
809
|
+
1116352408,
|
|
810
|
+
1899447441,
|
|
811
|
+
3049323471,
|
|
812
|
+
3921009573,
|
|
813
|
+
961987163,
|
|
814
|
+
1508970993,
|
|
815
|
+
2453635748,
|
|
816
|
+
2870763221,
|
|
817
|
+
3624381080,
|
|
818
|
+
310598401,
|
|
819
|
+
607225278,
|
|
820
|
+
1426881987,
|
|
821
|
+
1925078388,
|
|
822
|
+
2162078206,
|
|
823
|
+
2614888103,
|
|
824
|
+
3248222580,
|
|
825
|
+
3835390401,
|
|
826
|
+
4022224774,
|
|
827
|
+
264347078,
|
|
828
|
+
604807628,
|
|
829
|
+
770255983,
|
|
830
|
+
1249150122,
|
|
831
|
+
1555081692,
|
|
832
|
+
1996064986,
|
|
833
|
+
2554220882,
|
|
834
|
+
2821834349,
|
|
835
|
+
2952996808,
|
|
836
|
+
3210313671,
|
|
837
|
+
3336571891,
|
|
838
|
+
3584528711,
|
|
839
|
+
113926993,
|
|
840
|
+
338241895,
|
|
841
|
+
666307205,
|
|
842
|
+
773529912,
|
|
843
|
+
1294757372,
|
|
844
|
+
1396182291,
|
|
845
|
+
1695183700,
|
|
846
|
+
1986661051,
|
|
847
|
+
2177026350,
|
|
848
|
+
2456956037,
|
|
849
|
+
2730485921,
|
|
850
|
+
2820302411,
|
|
851
|
+
3259730800,
|
|
852
|
+
3345764771,
|
|
853
|
+
3516065817,
|
|
854
|
+
3600352804,
|
|
855
|
+
4094571909,
|
|
856
|
+
275423344,
|
|
857
|
+
430227734,
|
|
858
|
+
506948616,
|
|
859
|
+
659060556,
|
|
860
|
+
883997877,
|
|
861
|
+
958139571,
|
|
862
|
+
1322822218,
|
|
863
|
+
1537002063,
|
|
864
|
+
1747873779,
|
|
865
|
+
1955562222,
|
|
866
|
+
2024104815,
|
|
867
|
+
2227730452,
|
|
868
|
+
2361852424,
|
|
869
|
+
2428436474,
|
|
870
|
+
2756734187,
|
|
871
|
+
3204031479,
|
|
872
|
+
3329325298
|
|
873
|
+
]);
|
|
874
|
+
let h0 = 1779033703, h1 = 3144134277, h2 = 1013904242, h3 = 2773480762;
|
|
875
|
+
let h4 = 1359893119, h5 = 2600822924, h6 = 528734635, h7 = 1541459225;
|
|
876
|
+
const l = msg.length;
|
|
877
|
+
const bitLen = l * 8;
|
|
878
|
+
const k = (56 - (l + 1) % 64 + 64) % 64;
|
|
879
|
+
const total = l + 1 + k + 8;
|
|
880
|
+
const m = new Uint8Array(total);
|
|
881
|
+
m.set(msg, 0);
|
|
882
|
+
m[l] = 128;
|
|
883
|
+
const hi = Math.floor(bitLen / 4294967296);
|
|
884
|
+
const lo = bitLen >>> 0;
|
|
885
|
+
m[total - 8] = hi >>> 24 & 255;
|
|
886
|
+
m[total - 7] = hi >>> 16 & 255;
|
|
887
|
+
m[total - 6] = hi >>> 8 & 255;
|
|
888
|
+
m[total - 5] = hi & 255;
|
|
889
|
+
m[total - 4] = lo >>> 24 & 255;
|
|
890
|
+
m[total - 3] = lo >>> 16 & 255;
|
|
891
|
+
m[total - 2] = lo >>> 8 & 255;
|
|
892
|
+
m[total - 1] = lo & 255;
|
|
893
|
+
const w = new Uint32Array(64);
|
|
894
|
+
const rotr = (x, n) => x >>> n | x << 32 - n;
|
|
895
|
+
for (let off = 0; off < total; off += 64) {
|
|
896
|
+
for (let i = 0; i < 16; i++) {
|
|
897
|
+
w[i] = (m[off + i * 4] << 24 | m[off + i * 4 + 1] << 16 | m[off + i * 4 + 2] << 8 | m[off + i * 4 + 3]) >>> 0;
|
|
898
|
+
}
|
|
899
|
+
for (let i = 16; i < 64; i++) {
|
|
900
|
+
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
|
|
901
|
+
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ w[i - 2] >>> 10;
|
|
902
|
+
w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
|
|
903
|
+
}
|
|
904
|
+
let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
|
|
905
|
+
for (let i = 0; i < 64; i++) {
|
|
906
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
907
|
+
const ch = e & f ^ ~e & g;
|
|
908
|
+
const t1 = h + S1 + ch + K[i] + w[i] >>> 0;
|
|
909
|
+
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
910
|
+
const maj = a & b ^ a & c ^ b & c;
|
|
911
|
+
const t2 = S0 + maj >>> 0;
|
|
912
|
+
h = g;
|
|
913
|
+
g = f;
|
|
914
|
+
f = e;
|
|
915
|
+
e = d + t1 >>> 0;
|
|
916
|
+
d = c;
|
|
917
|
+
c = b;
|
|
918
|
+
b = a;
|
|
919
|
+
a = t1 + t2 >>> 0;
|
|
920
|
+
}
|
|
921
|
+
h0 = h0 + a >>> 0;
|
|
922
|
+
h1 = h1 + b >>> 0;
|
|
923
|
+
h2 = h2 + c >>> 0;
|
|
924
|
+
h3 = h3 + d >>> 0;
|
|
925
|
+
h4 = h4 + e >>> 0;
|
|
926
|
+
h5 = h5 + f >>> 0;
|
|
927
|
+
h6 = h6 + g >>> 0;
|
|
928
|
+
h7 = h7 + h >>> 0;
|
|
929
|
+
}
|
|
930
|
+
const out = new Uint8Array(32);
|
|
931
|
+
const hs = [h0, h1, h2, h3, h4, h5, h6, h7];
|
|
932
|
+
for (let i = 0; i < 8; i++) {
|
|
933
|
+
out[i * 4] = hs[i] >>> 24 & 255;
|
|
934
|
+
out[i * 4 + 1] = hs[i] >>> 16 & 255;
|
|
935
|
+
out[i * 4 + 2] = hs[i] >>> 8 & 255;
|
|
936
|
+
out[i * 4 + 3] = hs[i] & 255;
|
|
937
|
+
}
|
|
938
|
+
return out;
|
|
939
|
+
}
|
|
940
|
+
function resolveSyncSha256() {
|
|
941
|
+
if (typeof require === "function") {
|
|
942
|
+
try {
|
|
943
|
+
const nodeCrypto = require("crypto");
|
|
944
|
+
if (nodeCrypto && typeof nodeCrypto.createHash === "function") {
|
|
945
|
+
return (bytes) => new Uint8Array(nodeCrypto.createHash("sha256").update(bytes).digest());
|
|
946
|
+
}
|
|
947
|
+
} catch {
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
return sha256Pure;
|
|
951
|
+
}
|
|
790
952
|
var AuditResource = class extends Resource {
|
|
791
953
|
status(opts) {
|
|
792
954
|
return this._apiPromise(
|
|
@@ -819,36 +981,36 @@ var AuditResource = class extends Resource {
|
|
|
819
981
|
);
|
|
820
982
|
}
|
|
821
983
|
/**
|
|
822
|
-
* Verify a Merkle inclusion proof locally (client-side).
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
* without trusting the API response.
|
|
984
|
+
* Verify a Merkle inclusion proof locally (client-side). Sorted-pair SHA-256
|
|
985
|
+
* over the raw 32-byte digests — identical logic to the server-side batcher,
|
|
986
|
+
* so callers can independently confirm inclusion without trusting the API.
|
|
826
987
|
*/
|
|
827
988
|
static verifyProof(leaf, root, proof) {
|
|
828
|
-
const
|
|
829
|
-
let hash = leaf;
|
|
989
|
+
const sha256 = resolveSyncSha256();
|
|
990
|
+
let hash = hexToBytes(leaf);
|
|
830
991
|
for (const sibling of proof) {
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
992
|
+
const sib = hexToBytes(sibling);
|
|
993
|
+
const [a, b] = cmpBytes(hash, sib) <= 0 ? [hash, sib] : [sib, hash];
|
|
994
|
+
const pair = new Uint8Array(a.length + b.length);
|
|
995
|
+
pair.set(a, 0);
|
|
996
|
+
pair.set(b, a.length);
|
|
997
|
+
hash = sha256(pair);
|
|
836
998
|
}
|
|
837
|
-
return hash === root;
|
|
999
|
+
return bytesToHex(hash) === root;
|
|
838
1000
|
}
|
|
839
1001
|
/** Async variant using WebCrypto — works in browsers, Deno, Bun, edge runtimes. */
|
|
840
1002
|
static async verifyProofAsync(leaf, root, proof) {
|
|
841
|
-
const
|
|
842
|
-
|
|
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;
|
|
1003
|
+
const subtle = globalThis.crypto.subtle;
|
|
1004
|
+
let hash = hexToBytes(leaf);
|
|
847
1005
|
for (const sibling of proof) {
|
|
848
|
-
const
|
|
849
|
-
|
|
1006
|
+
const sib = hexToBytes(sibling);
|
|
1007
|
+
const [a, b] = cmpBytes(hash, sib) <= 0 ? [hash, sib] : [sib, hash];
|
|
1008
|
+
const pair = new Uint8Array(a.length + b.length);
|
|
1009
|
+
pair.set(a, 0);
|
|
1010
|
+
pair.set(b, a.length);
|
|
1011
|
+
hash = new Uint8Array(await subtle.digest("SHA-256", pair));
|
|
850
1012
|
}
|
|
851
|
-
return hash === root;
|
|
1013
|
+
return bytesToHex(hash) === root;
|
|
852
1014
|
}
|
|
853
1015
|
};
|
|
854
1016
|
|
|
@@ -1165,6 +1327,55 @@ var ApplyResource = class extends Resource {
|
|
|
1165
1327
|
var SandboxResource = class extends Resource {
|
|
1166
1328
|
};
|
|
1167
1329
|
|
|
1330
|
+
// src/resources/settle.ts
|
|
1331
|
+
var SettleResource = class extends Resource {
|
|
1332
|
+
/** Builder self-serve settle — POST /v1/builders/me/settle. */
|
|
1333
|
+
me(params, opts) {
|
|
1334
|
+
const body = {
|
|
1335
|
+
address: params.address,
|
|
1336
|
+
asset: params.asset ?? "USDT",
|
|
1337
|
+
network: params.network ?? "polygon",
|
|
1338
|
+
min_amount: params.min_amount ?? 0
|
|
1339
|
+
};
|
|
1340
|
+
return this._apiPromise(
|
|
1341
|
+
() => this._http.request("POST", "/v1/builders/me/settle", void 0, body, opts)
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
/** Admin settle a specific builder's fees — POST /v1/admin/builders/{userId}/settle.
|
|
1345
|
+
* Requires X-Admin-Key header. */
|
|
1346
|
+
adminBuilder(userId, params, adminKey, opts) {
|
|
1347
|
+
const body = {
|
|
1348
|
+
address: params.address,
|
|
1349
|
+
asset: params.asset ?? "USDT",
|
|
1350
|
+
network: params.network ?? "polygon",
|
|
1351
|
+
min_amount: params.min_amount ?? 0
|
|
1352
|
+
};
|
|
1353
|
+
const mergedOpts = {
|
|
1354
|
+
...opts || {},
|
|
1355
|
+
headers: { ...opts?.headers || {}, "X-Admin-Key": adminKey }
|
|
1356
|
+
};
|
|
1357
|
+
return this._apiPromise(
|
|
1358
|
+
() => this._http.request("POST", `/v1/admin/builders/${encodeURIComponent(userId)}/settle`, void 0, body, mergedOpts)
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
/** Admin settle a market creator's fees — POST /v1/admin/creators/{userId}/settle. */
|
|
1362
|
+
adminCreator(userId, params, adminKey, opts) {
|
|
1363
|
+
const body = {
|
|
1364
|
+
address: params.address,
|
|
1365
|
+
asset: params.asset ?? "USDT",
|
|
1366
|
+
network: params.network ?? "polygon",
|
|
1367
|
+
min_amount: params.min_amount ?? 0
|
|
1368
|
+
};
|
|
1369
|
+
const mergedOpts = {
|
|
1370
|
+
...opts || {},
|
|
1371
|
+
headers: { ...opts?.headers || {}, "X-Admin-Key": adminKey }
|
|
1372
|
+
};
|
|
1373
|
+
return this._apiPromise(
|
|
1374
|
+
() => this._http.request("POST", `/v1/admin/creators/${encodeURIComponent(userId)}/settle`, void 0, body, mergedOpts)
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
};
|
|
1378
|
+
|
|
1168
1379
|
// src/resources/templates.ts
|
|
1169
1380
|
var TemplatesResource = class extends Resource {
|
|
1170
1381
|
list(params = {}, opts) {
|
|
@@ -1203,6 +1414,8 @@ var PaxClient = class {
|
|
|
1203
1414
|
// v2.1+: GET /v1/fees/estimate
|
|
1204
1415
|
audit;
|
|
1205
1416
|
// v2.2+: public Merkle chain verifier (no-auth)
|
|
1417
|
+
settle;
|
|
1418
|
+
// v2.4+: claim accrued fee revenue
|
|
1206
1419
|
constructor(opts) {
|
|
1207
1420
|
this._http = new HttpClient(opts);
|
|
1208
1421
|
this.markets = new MarketsResource(this._http);
|
|
@@ -1216,6 +1429,7 @@ var PaxClient = class {
|
|
|
1216
1429
|
this.grants = new GrantsResource(this._http);
|
|
1217
1430
|
this.fees = new FeesResource(this._http);
|
|
1218
1431
|
this.audit = new AuditResource(this._http);
|
|
1432
|
+
this.settle = new SettleResource(this._http);
|
|
1219
1433
|
}
|
|
1220
1434
|
get baseUrl() {
|
|
1221
1435
|
return this._http.baseUrl;
|
|
@@ -1239,6 +1453,117 @@ var PaxClient = class {
|
|
|
1239
1453
|
}
|
|
1240
1454
|
};
|
|
1241
1455
|
|
|
1456
|
+
// src/attach-ref.ts
|
|
1457
|
+
var DEFAULT_STORAGE_KEY = "pax_builder_ref";
|
|
1458
|
+
var DEFAULT_COOKIE_MAX_AGE = 90 * 24 * 3600;
|
|
1459
|
+
var HEADER_NAME = "X-Builder-Ref";
|
|
1460
|
+
var _memoryStore = null;
|
|
1461
|
+
function _isBrowser() {
|
|
1462
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
1463
|
+
}
|
|
1464
|
+
function _sanitize(v) {
|
|
1465
|
+
if (v == null) return null;
|
|
1466
|
+
const s = String(v).trim().slice(0, 64);
|
|
1467
|
+
if (!/^[A-Za-z0-9_-]{3,64}$/.test(s)) return null;
|
|
1468
|
+
return s;
|
|
1469
|
+
}
|
|
1470
|
+
function _readCookie(name) {
|
|
1471
|
+
if (!_isBrowser()) return null;
|
|
1472
|
+
const parts = document.cookie.split(";").map((s) => s.trim());
|
|
1473
|
+
for (const p of parts) {
|
|
1474
|
+
const eq = p.indexOf("=");
|
|
1475
|
+
if (eq === -1) continue;
|
|
1476
|
+
const k = p.slice(0, eq).trim();
|
|
1477
|
+
if (k === name) return decodeURIComponent(p.slice(eq + 1));
|
|
1478
|
+
}
|
|
1479
|
+
return null;
|
|
1480
|
+
}
|
|
1481
|
+
function _writeCookie(name, value, maxAgeSec, domain) {
|
|
1482
|
+
if (!_isBrowser()) return;
|
|
1483
|
+
const parts = [
|
|
1484
|
+
`${name}=${encodeURIComponent(value)}`,
|
|
1485
|
+
`Path=/`,
|
|
1486
|
+
`Max-Age=${maxAgeSec}`,
|
|
1487
|
+
`SameSite=Lax`
|
|
1488
|
+
];
|
|
1489
|
+
if (window.location && window.location.protocol === "https:") parts.push("Secure");
|
|
1490
|
+
if (domain) parts.push(`Domain=${domain}`);
|
|
1491
|
+
document.cookie = parts.join("; ");
|
|
1492
|
+
}
|
|
1493
|
+
function _readLocalStorage(key) {
|
|
1494
|
+
try {
|
|
1495
|
+
if (!_isBrowser() || !window.localStorage) return null;
|
|
1496
|
+
return window.localStorage.getItem(key);
|
|
1497
|
+
} catch {
|
|
1498
|
+
return null;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
function _writeLocalStorage(key, value) {
|
|
1502
|
+
try {
|
|
1503
|
+
if (!_isBrowser() || !window.localStorage) return;
|
|
1504
|
+
window.localStorage.setItem(key, value);
|
|
1505
|
+
} catch {
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
function _parseRefFromUrl(url, param) {
|
|
1509
|
+
const src = url ?? (_isBrowser() ? window.location.href : "");
|
|
1510
|
+
if (!src) return null;
|
|
1511
|
+
try {
|
|
1512
|
+
const u = new URL(src);
|
|
1513
|
+
return _sanitize(u.searchParams.get(param));
|
|
1514
|
+
} catch {
|
|
1515
|
+
return null;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
function attachRef(opts = {}) {
|
|
1519
|
+
const param = opts.queryParam ?? "ref";
|
|
1520
|
+
const key = opts.storageKey ?? DEFAULT_STORAGE_KEY;
|
|
1521
|
+
const storage = opts.storage ?? (_isBrowser() ? "cookie" : "memory");
|
|
1522
|
+
if (opts.ref) {
|
|
1523
|
+
const s = _sanitize(opts.ref);
|
|
1524
|
+
if (s) {
|
|
1525
|
+
_persist(s, key, storage, opts);
|
|
1526
|
+
return { ref: s, headers: { [HEADER_NAME]: s }, persisted: true, source: "explicit" };
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
const urlRef = _parseRefFromUrl(opts.url, param);
|
|
1530
|
+
if (urlRef) {
|
|
1531
|
+
_persist(urlRef, key, storage, opts);
|
|
1532
|
+
return { ref: urlRef, headers: { [HEADER_NAME]: urlRef }, persisted: true, source: "url" };
|
|
1533
|
+
}
|
|
1534
|
+
const ck = _sanitize(_readCookie(key));
|
|
1535
|
+
if (ck) return { ref: ck, headers: { [HEADER_NAME]: ck }, persisted: false, source: "cookie" };
|
|
1536
|
+
const ls = _sanitize(_readLocalStorage(key));
|
|
1537
|
+
if (ls) return { ref: ls, headers: { [HEADER_NAME]: ls }, persisted: false, source: "localStorage" };
|
|
1538
|
+
const mem = _sanitize(_memoryStore);
|
|
1539
|
+
if (mem) return { ref: mem, headers: { [HEADER_NAME]: mem }, persisted: false, source: "memory" };
|
|
1540
|
+
return { ref: null, headers: {}, persisted: false, source: "none" };
|
|
1541
|
+
}
|
|
1542
|
+
function _persist(value, key, storage, opts) {
|
|
1543
|
+
switch (storage) {
|
|
1544
|
+
case "cookie":
|
|
1545
|
+
_writeCookie(key, value, opts.cookieMaxAgeSec ?? DEFAULT_COOKIE_MAX_AGE, opts.cookieDomain);
|
|
1546
|
+
break;
|
|
1547
|
+
case "localStorage":
|
|
1548
|
+
_writeLocalStorage(key, value);
|
|
1549
|
+
break;
|
|
1550
|
+
case "memory":
|
|
1551
|
+
_memoryStore = value;
|
|
1552
|
+
break;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
function clearRef(opts = {}) {
|
|
1556
|
+
const key = opts.storageKey ?? DEFAULT_STORAGE_KEY;
|
|
1557
|
+
_memoryStore = null;
|
|
1558
|
+
if (_isBrowser()) {
|
|
1559
|
+
_writeCookie(key, "", 0, opts.cookieDomain);
|
|
1560
|
+
try {
|
|
1561
|
+
window.localStorage && window.localStorage.removeItem(key);
|
|
1562
|
+
} catch {
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1242
1567
|
// src/ws-client.ts
|
|
1243
1568
|
var ENV_URLS2 = {
|
|
1244
1569
|
production: "wss://predictasiax.com/ws",
|
|
@@ -1513,8 +1838,10 @@ var PaxWSClient = class {
|
|
|
1513
1838
|
SandboxResource,
|
|
1514
1839
|
TemplatesResource,
|
|
1515
1840
|
VERSION,
|
|
1841
|
+
attachRef,
|
|
1516
1842
|
buildError,
|
|
1517
1843
|
buildMessage,
|
|
1844
|
+
clearRef,
|
|
1518
1845
|
computeBackoff,
|
|
1519
1846
|
runWithRetry,
|
|
1520
1847
|
signRequest
|