@predictasiax/api 3.0.0 → 3.0.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 +8 -0
- package/README.md +1 -1
- package/dist/index.cjs +62 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.js +0 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @predictasiax/api Changelog
|
|
2
2
|
|
|
3
|
+
## v3.0.1 — 2026-11-23
|
|
4
|
+
|
|
5
|
+
### Security
|
|
6
|
+
- `PaxWSClient` accepts only `wss://` URLs; `ws://` is accepted for a loopback host only. The AUTH frame carries the credential. (REST `baseUrl` already required `https://`.)
|
|
7
|
+
- `attachRef()`: first write wins. A `?ref=` in the URL is persisted only when no ref is stored yet, so a later link cannot replace the referral that brought the user in. An explicit `ref` option (or `clearRef()` first) still replaces it. The previous code overwrote the stored ref on every URL hit, contrary to its own documentation.
|
|
8
|
+
- `verifyEvent` adds a `fields_match_canonical` check: `seq`, `event_type`, `payload`, `event_id`, `emitter`, `schema_version` and `idempotency_key` in the response must equal the values inside the hashed `canonical`. Numbers compare by value (the API serves numbers beyond double precision as decimal strings). New export `fieldsMatchCanonical`.
|
|
9
|
+
- When the API withholds `canonical` (public view of an event that names an account), `verifyEvent` returns `ok: false` and says only Merkle inclusion was checked.
|
|
10
|
+
|
|
3
11
|
## v3.0.0 — 2026-11-23
|
|
4
12
|
|
|
5
13
|
2.x could not authenticate against the gateway. This release aligns the SDK with what `https://api.predictasiax.com` actually serves.
|
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ const pax = new PaxClient({ apiKey: minted.api_key }); // Authorization: Beare
|
|
|
40
40
|
console.log(await pax.account.balance());
|
|
41
41
|
console.log(await pax.account.positions());
|
|
42
42
|
|
|
43
|
-
const order = await pax.orders.place({ marketId: "hadjar-f1-2026", side: "yes", price: "0.05", size: "
|
|
43
|
+
const order = await pax.orders.place({ marketId: "hadjar-f1-2026", side: "yes", price: "0.05", size: "20" });
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
More runnable examples: [`examples/`](./examples).
|
package/dist/index.cjs
CHANGED
|
@@ -65,6 +65,7 @@ __export(index_exports, {
|
|
|
65
65
|
clearRef: () => clearRef,
|
|
66
66
|
computeBackoff: () => computeBackoff,
|
|
67
67
|
expectedProofLength: () => expectedProofLength,
|
|
68
|
+
fieldsMatchCanonical: () => fieldsMatchCanonical,
|
|
68
69
|
normalizeBaseUrl: () => normalizeBaseUrl,
|
|
69
70
|
runWithRetry: () => runWithRetry,
|
|
70
71
|
signRequest: () => signRequest
|
|
@@ -368,7 +369,7 @@ async function runWithRetry(fn, opts = {}) {
|
|
|
368
369
|
}
|
|
369
370
|
|
|
370
371
|
// src/http.ts
|
|
371
|
-
var VERSION = "3.0.
|
|
372
|
+
var VERSION = "3.0.1";
|
|
372
373
|
var DEFAULT_BASE_URL = "https://api.predictasiax.com";
|
|
373
374
|
var API_KEY_PREFIXES = ["sk_live_", "sk_test_", "pax_"];
|
|
374
375
|
function normalizeBaseUrl(url) {
|
|
@@ -1036,6 +1037,7 @@ var AuditResource = class _AuditResource extends Resource {
|
|
|
1036
1037
|
static verifyEvent(event, proof, root) {
|
|
1037
1038
|
const checks = {};
|
|
1038
1039
|
checks.event_hash = _AuditResource.verifyEventHash(event);
|
|
1040
|
+
checks.fields_match_canonical = fieldsMatchCanonical(event);
|
|
1039
1041
|
checks.same_event = proof.seq === event.seq && String(proof.event_hash).toLowerCase() === String(event.event_hash).toLowerCase();
|
|
1040
1042
|
const first = Number(proof.batch?.first_seq);
|
|
1041
1043
|
const last = Number(proof.batch?.last_seq);
|
|
@@ -1053,6 +1055,15 @@ var AuditResource = class _AuditResource extends Resource {
|
|
|
1053
1055
|
expLen
|
|
1054
1056
|
);
|
|
1055
1057
|
const failed = Object.entries(checks).filter(([, v]) => !v).map(([k]) => k);
|
|
1058
|
+
if (event.canonical_withheld) {
|
|
1059
|
+
return {
|
|
1060
|
+
ok: false,
|
|
1061
|
+
checks,
|
|
1062
|
+
leafCount,
|
|
1063
|
+
expectedProofLength: expLen,
|
|
1064
|
+
reason: "canonical withheld for this event (account identifiers redacted); only Merkle inclusion was checked. Fetch it with the key of the account it names to verify content."
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1056
1067
|
return {
|
|
1057
1068
|
ok: failed.length === 0,
|
|
1058
1069
|
checks,
|
|
@@ -1101,6 +1112,36 @@ var AuditResource = class _AuditResource extends Resource {
|
|
|
1101
1112
|
return bytesToHex(hash) === root.toLowerCase();
|
|
1102
1113
|
}
|
|
1103
1114
|
};
|
|
1115
|
+
var BOUND_FIELDS = ["seq", "event_type", "payload", "event_id", "emitter", "schema_version", "idempotency_key"];
|
|
1116
|
+
var NUMERIC_RE = /^-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
1117
|
+
function normForCompare(v) {
|
|
1118
|
+
if (v === null || typeof v === "boolean") return v;
|
|
1119
|
+
if (typeof v === "number") return ["n", v];
|
|
1120
|
+
if (typeof v === "string") return NUMERIC_RE.test(v.trim()) ? ["n", Number(v)] : ["s", v];
|
|
1121
|
+
if (Array.isArray(v)) return v.map(normForCompare);
|
|
1122
|
+
if (typeof v === "object") {
|
|
1123
|
+
const o = {};
|
|
1124
|
+
for (const k of Object.keys(v).sort()) o[k] = normForCompare(v[k]);
|
|
1125
|
+
return o;
|
|
1126
|
+
}
|
|
1127
|
+
return v;
|
|
1128
|
+
}
|
|
1129
|
+
function fieldsMatchCanonical(event) {
|
|
1130
|
+
if (typeof event.canonical !== "string") return false;
|
|
1131
|
+
let c;
|
|
1132
|
+
try {
|
|
1133
|
+
c = JSON.parse(event.canonical);
|
|
1134
|
+
} catch {
|
|
1135
|
+
return false;
|
|
1136
|
+
}
|
|
1137
|
+
if (!c || typeof c !== "object" || Array.isArray(c)) return false;
|
|
1138
|
+
for (const f of BOUND_FIELDS) {
|
|
1139
|
+
if (!(f in event)) continue;
|
|
1140
|
+
if (!(f in c)) return false;
|
|
1141
|
+
if (JSON.stringify(normForCompare(c[f])) !== JSON.stringify(normForCompare(event[f]))) return false;
|
|
1142
|
+
}
|
|
1143
|
+
return true;
|
|
1144
|
+
}
|
|
1104
1145
|
|
|
1105
1146
|
// src/resources/fees.ts
|
|
1106
1147
|
var FeesResource = class extends Resource {
|
|
@@ -1511,17 +1552,17 @@ function attachRef(opts = {}) {
|
|
|
1511
1552
|
return { ref: s, headers: { [HEADER_NAME]: s }, persisted: true, source: "explicit" };
|
|
1512
1553
|
}
|
|
1513
1554
|
}
|
|
1514
|
-
const urlRef = _parseRefFromUrl(opts.url, param);
|
|
1515
|
-
if (urlRef) {
|
|
1516
|
-
_persist(urlRef, key, storage, opts);
|
|
1517
|
-
return { ref: urlRef, headers: { [HEADER_NAME]: urlRef }, persisted: true, source: "url" };
|
|
1518
|
-
}
|
|
1519
1555
|
const ck = _sanitize(_readCookie(key));
|
|
1520
1556
|
if (ck) return { ref: ck, headers: { [HEADER_NAME]: ck }, persisted: false, source: "cookie" };
|
|
1521
1557
|
const ls = _sanitize(_readLocalStorage(key));
|
|
1522
1558
|
if (ls) return { ref: ls, headers: { [HEADER_NAME]: ls }, persisted: false, source: "localStorage" };
|
|
1523
1559
|
const mem = _sanitize(_memoryStore);
|
|
1524
1560
|
if (mem) return { ref: mem, headers: { [HEADER_NAME]: mem }, persisted: false, source: "memory" };
|
|
1561
|
+
const urlRef = _parseRefFromUrl(opts.url, param);
|
|
1562
|
+
if (urlRef) {
|
|
1563
|
+
_persist(urlRef, key, storage, opts);
|
|
1564
|
+
return { ref: urlRef, headers: { [HEADER_NAME]: urlRef }, persisted: true, source: "url" };
|
|
1565
|
+
}
|
|
1525
1566
|
return { ref: null, headers: {}, persisted: false, source: "none" };
|
|
1526
1567
|
}
|
|
1527
1568
|
function _persist(value, key, storage, opts) {
|
|
@@ -1566,6 +1607,19 @@ async function resolveWebSocketCtor(override) {
|
|
|
1566
1607
|
const wsModule = await import("ws");
|
|
1567
1608
|
return wsModule.WebSocket;
|
|
1568
1609
|
}
|
|
1610
|
+
function requireSecureWsUrl(url) {
|
|
1611
|
+
let u;
|
|
1612
|
+
try {
|
|
1613
|
+
u = new URL(url);
|
|
1614
|
+
} catch {
|
|
1615
|
+
throw new Error(`Invalid WebSocket url: ${url}`);
|
|
1616
|
+
}
|
|
1617
|
+
if (u.protocol === "wss:") return url;
|
|
1618
|
+
const host = u.hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
1619
|
+
const loopback = host === "localhost" || host === "127.0.0.1" || host === "::1" || host.endsWith(".localhost");
|
|
1620
|
+
if (u.protocol === "ws:" && loopback) return url;
|
|
1621
|
+
throw new Error(`WebSocket url must use wss:// (ws:// is accepted only for localhost); got ${u.protocol}//${u.hostname}`);
|
|
1622
|
+
}
|
|
1569
1623
|
var PaxWSClient = class {
|
|
1570
1624
|
url;
|
|
1571
1625
|
apiKey;
|
|
@@ -1591,7 +1645,7 @@ var PaxWSClient = class {
|
|
|
1591
1645
|
this.bearerToken = opts.bearerToken;
|
|
1592
1646
|
this.locale = opts.locale;
|
|
1593
1647
|
const env = (opts.env ?? "production").toLowerCase();
|
|
1594
|
-
this.url = opts.url ?? ENV_URLS[env] ?? ENV_URLS.production;
|
|
1648
|
+
this.url = requireSecureWsUrl(opts.url ?? ENV_URLS[env] ?? ENV_URLS.production);
|
|
1595
1649
|
this.reconnect = opts.reconnect ?? true;
|
|
1596
1650
|
this.backoffMinSec = opts.backoffMinSec ?? 1;
|
|
1597
1651
|
this.backoffMaxSec = opts.backoffMaxSec ?? 60;
|
|
@@ -1830,6 +1884,7 @@ var PaxWSClient = class {
|
|
|
1830
1884
|
clearRef,
|
|
1831
1885
|
computeBackoff,
|
|
1832
1886
|
expectedProofLength,
|
|
1887
|
+
fieldsMatchCanonical,
|
|
1833
1888
|
normalizeBaseUrl,
|
|
1834
1889
|
runWithRetry,
|
|
1835
1890
|
signRequest
|