@inversealtruism/csd-client 0.1.18 → 0.1.19
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/dist/index.cjs +7 -1
- package/dist/index.d.cts +8 -9
- package/dist/index.d.ts +8 -9
- package/dist/index.js +6 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -21,12 +21,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CsdClient: () => CsdClient,
|
|
24
|
+
parseJsonExact: () => parseJsonExact,
|
|
24
25
|
rpcHeaderToHeader: () => rpcHeaderToHeader,
|
|
25
26
|
rpcTxToTx: () => rpcTxToTx,
|
|
26
27
|
verifyInputValues: () => verifyInputValues
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(index_exports);
|
|
29
30
|
var import_csd_codec = require("@inversealtruism/csd-codec");
|
|
31
|
+
var exactIntReviver = (_key, value, context) => typeof value === "number" && !Number.isSafeInteger(value) && typeof context?.source === "string" && /^-?\d+$/.test(context.source) ? BigInt(context.source) : value;
|
|
32
|
+
function parseJsonExact(text) {
|
|
33
|
+
return JSON.parse(text, exactIntReviver);
|
|
34
|
+
}
|
|
30
35
|
var DEFAULT_MAX_RESPONSE_BYTES = 16 * 1024 * 1024;
|
|
31
36
|
var DEFAULT_RETRIES = 0;
|
|
32
37
|
var finiteOr = (v, dflt) => v !== void 0 && Number.isFinite(v) ? v : dflt;
|
|
@@ -40,7 +45,7 @@ var CsdClient = class {
|
|
|
40
45
|
constructor(opts) {
|
|
41
46
|
this.base = opts.baseUrl.replace(/\/+$/, "");
|
|
42
47
|
this.maxBytes = Math.max(1, finiteOr(opts.maxResponseBytes, DEFAULT_MAX_RESPONSE_BYTES));
|
|
43
|
-
this.parseJson = opts.parseJson ??
|
|
48
|
+
this.parseJson = opts.parseJson ?? parseJsonExact;
|
|
44
49
|
const gf = globalThis.fetch;
|
|
45
50
|
this.f = opts.fetch ?? (gf ? gf.bind(globalThis) : gf);
|
|
46
51
|
this.timeoutMs = opts.timeoutMs ?? 1e4;
|
|
@@ -258,6 +263,7 @@ function rpcHeaderToHeader(h) {
|
|
|
258
263
|
// Annotate the CommonJS export names for ESM import in node:
|
|
259
264
|
0 && (module.exports = {
|
|
260
265
|
CsdClient,
|
|
266
|
+
parseJsonExact,
|
|
261
267
|
rpcHeaderToHeader,
|
|
262
268
|
rpcTxToTx,
|
|
263
269
|
verifyInputValues
|
package/dist/index.d.cts
CHANGED
|
@@ -17,8 +17,9 @@ interface RpcTxJson {
|
|
|
17
17
|
script_sig: string;
|
|
18
18
|
script_sig_text?: string | null;
|
|
19
19
|
}[];
|
|
20
|
+
/** u64 fields arrive as bigint when above 2^53 (parseJsonExact). */
|
|
20
21
|
outputs: {
|
|
21
|
-
value: number;
|
|
22
|
+
value: number | bigint;
|
|
22
23
|
script_pubkey: string;
|
|
23
24
|
}[];
|
|
24
25
|
locktime: number;
|
|
@@ -29,7 +30,7 @@ interface RpcTxJson {
|
|
|
29
30
|
domain: string;
|
|
30
31
|
payload_hash: string;
|
|
31
32
|
uri: string;
|
|
32
|
-
expires_epoch: number;
|
|
33
|
+
expires_epoch: number | bigint;
|
|
33
34
|
} | {
|
|
34
35
|
type: "Attest";
|
|
35
36
|
proposal_id: string;
|
|
@@ -77,7 +78,7 @@ interface RpcProposal {
|
|
|
77
78
|
domain: string;
|
|
78
79
|
payload_hash: string;
|
|
79
80
|
uri: string;
|
|
80
|
-
expires_epoch: number;
|
|
81
|
+
expires_epoch: number | bigint;
|
|
81
82
|
proposer: string;
|
|
82
83
|
height: number;
|
|
83
84
|
attestations?: unknown[];
|
|
@@ -118,13 +119,11 @@ interface ClientOptions {
|
|
|
118
119
|
* path (audit M2). Default 16 MiB ≫ any real block; raise it for an unusually large block source.
|
|
119
120
|
*/
|
|
120
121
|
maxResponseBytes?: number;
|
|
121
|
-
/**
|
|
122
|
-
* M1: optional JSON body parser (default `JSON.parse`). A verifier that must preserve u64 fields
|
|
123
|
-
* (e.g. a Propose's `expires_epoch`, unbounded on-chain) past 2^53 injects a source-preserving
|
|
124
|
-
* reviver here so the exact value survives to the txid recompute. The default is unchanged.
|
|
125
|
-
*/
|
|
122
|
+
/** JSON body parser; default `parseJsonExact`, so a u64 above 2^53 survives to the txid recompute. */
|
|
126
123
|
parseJson?: (text: string) => unknown;
|
|
127
124
|
}
|
|
125
|
+
/** JSON.parse, except that an integer literal outside the safe JS range is returned as an exact bigint. */
|
|
126
|
+
declare function parseJsonExact(text: string): unknown;
|
|
128
127
|
declare class CsdClient {
|
|
129
128
|
private readonly base;
|
|
130
129
|
private readonly f;
|
|
@@ -210,4 +209,4 @@ declare function verifyInputValues(client: {
|
|
|
210
209
|
/** Convert a node /block header JSON into the codec's BlockHeader. */
|
|
211
210
|
declare function rpcHeaderToHeader(h: RpcHeaderJson): BlockHeader;
|
|
212
211
|
|
|
213
|
-
export { type ClientOptions, CsdClient, type RpcBlock, type RpcHeaderJson, type RpcHealth, type RpcProposal, type RpcSubmit, type RpcTip, type RpcTxInfo, type RpcTxJson, type RpcUtxo, type RpcUtxos, type WaitForTxResult, rpcHeaderToHeader, rpcTxToTx, verifyInputValues };
|
|
212
|
+
export { type ClientOptions, CsdClient, type RpcBlock, type RpcHeaderJson, type RpcHealth, type RpcProposal, type RpcSubmit, type RpcTip, type RpcTxInfo, type RpcTxJson, type RpcUtxo, type RpcUtxos, type WaitForTxResult, parseJsonExact, rpcHeaderToHeader, rpcTxToTx, verifyInputValues };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,8 +17,9 @@ interface RpcTxJson {
|
|
|
17
17
|
script_sig: string;
|
|
18
18
|
script_sig_text?: string | null;
|
|
19
19
|
}[];
|
|
20
|
+
/** u64 fields arrive as bigint when above 2^53 (parseJsonExact). */
|
|
20
21
|
outputs: {
|
|
21
|
-
value: number;
|
|
22
|
+
value: number | bigint;
|
|
22
23
|
script_pubkey: string;
|
|
23
24
|
}[];
|
|
24
25
|
locktime: number;
|
|
@@ -29,7 +30,7 @@ interface RpcTxJson {
|
|
|
29
30
|
domain: string;
|
|
30
31
|
payload_hash: string;
|
|
31
32
|
uri: string;
|
|
32
|
-
expires_epoch: number;
|
|
33
|
+
expires_epoch: number | bigint;
|
|
33
34
|
} | {
|
|
34
35
|
type: "Attest";
|
|
35
36
|
proposal_id: string;
|
|
@@ -77,7 +78,7 @@ interface RpcProposal {
|
|
|
77
78
|
domain: string;
|
|
78
79
|
payload_hash: string;
|
|
79
80
|
uri: string;
|
|
80
|
-
expires_epoch: number;
|
|
81
|
+
expires_epoch: number | bigint;
|
|
81
82
|
proposer: string;
|
|
82
83
|
height: number;
|
|
83
84
|
attestations?: unknown[];
|
|
@@ -118,13 +119,11 @@ interface ClientOptions {
|
|
|
118
119
|
* path (audit M2). Default 16 MiB ≫ any real block; raise it for an unusually large block source.
|
|
119
120
|
*/
|
|
120
121
|
maxResponseBytes?: number;
|
|
121
|
-
/**
|
|
122
|
-
* M1: optional JSON body parser (default `JSON.parse`). A verifier that must preserve u64 fields
|
|
123
|
-
* (e.g. a Propose's `expires_epoch`, unbounded on-chain) past 2^53 injects a source-preserving
|
|
124
|
-
* reviver here so the exact value survives to the txid recompute. The default is unchanged.
|
|
125
|
-
*/
|
|
122
|
+
/** JSON body parser; default `parseJsonExact`, so a u64 above 2^53 survives to the txid recompute. */
|
|
126
123
|
parseJson?: (text: string) => unknown;
|
|
127
124
|
}
|
|
125
|
+
/** JSON.parse, except that an integer literal outside the safe JS range is returned as an exact bigint. */
|
|
126
|
+
declare function parseJsonExact(text: string): unknown;
|
|
128
127
|
declare class CsdClient {
|
|
129
128
|
private readonly base;
|
|
130
129
|
private readonly f;
|
|
@@ -210,4 +209,4 @@ declare function verifyInputValues(client: {
|
|
|
210
209
|
/** Convert a node /block header JSON into the codec's BlockHeader. */
|
|
211
210
|
declare function rpcHeaderToHeader(h: RpcHeaderJson): BlockHeader;
|
|
212
211
|
|
|
213
|
-
export { type ClientOptions, CsdClient, type RpcBlock, type RpcHeaderJson, type RpcHealth, type RpcProposal, type RpcSubmit, type RpcTip, type RpcTxInfo, type RpcTxJson, type RpcUtxo, type RpcUtxos, type WaitForTxResult, rpcHeaderToHeader, rpcTxToTx, verifyInputValues };
|
|
212
|
+
export { type ClientOptions, CsdClient, type RpcBlock, type RpcHeaderJson, type RpcHealth, type RpcProposal, type RpcSubmit, type RpcTip, type RpcTxInfo, type RpcTxJson, type RpcUtxo, type RpcUtxos, type WaitForTxResult, parseJsonExact, rpcHeaderToHeader, rpcTxToTx, verifyInputValues };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { txid as codecTxid } from "@inversealtruism/csd-codec";
|
|
3
|
+
var exactIntReviver = (_key, value, context) => typeof value === "number" && !Number.isSafeInteger(value) && typeof context?.source === "string" && /^-?\d+$/.test(context.source) ? BigInt(context.source) : value;
|
|
4
|
+
function parseJsonExact(text) {
|
|
5
|
+
return JSON.parse(text, exactIntReviver);
|
|
6
|
+
}
|
|
3
7
|
var DEFAULT_MAX_RESPONSE_BYTES = 16 * 1024 * 1024;
|
|
4
8
|
var DEFAULT_RETRIES = 0;
|
|
5
9
|
var finiteOr = (v, dflt) => v !== void 0 && Number.isFinite(v) ? v : dflt;
|
|
@@ -13,7 +17,7 @@ var CsdClient = class {
|
|
|
13
17
|
constructor(opts) {
|
|
14
18
|
this.base = opts.baseUrl.replace(/\/+$/, "");
|
|
15
19
|
this.maxBytes = Math.max(1, finiteOr(opts.maxResponseBytes, DEFAULT_MAX_RESPONSE_BYTES));
|
|
16
|
-
this.parseJson = opts.parseJson ??
|
|
20
|
+
this.parseJson = opts.parseJson ?? parseJsonExact;
|
|
17
21
|
const gf = globalThis.fetch;
|
|
18
22
|
this.f = opts.fetch ?? (gf ? gf.bind(globalThis) : gf);
|
|
19
23
|
this.timeoutMs = opts.timeoutMs ?? 1e4;
|
|
@@ -230,6 +234,7 @@ function rpcHeaderToHeader(h) {
|
|
|
230
234
|
}
|
|
231
235
|
export {
|
|
232
236
|
CsdClient,
|
|
237
|
+
parseJsonExact,
|
|
233
238
|
rpcHeaderToHeader,
|
|
234
239
|
rpcTxToTx,
|
|
235
240
|
verifyInputValues
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inversealtruism/csd-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
7
|
-
"description": "Typed HTTP RPC client for a Compute Substrate node (or the Cairn proxy / a discovered gateway)
|
|
7
|
+
"description": "Typed HTTP RPC client for a Compute Substrate node (or the Cairn proxy / a discovered gateway): tip/block/tx/utxos/proposals/top/domains/mempool/submit/templates.",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./dist/index.cjs",
|
|
10
10
|
"module": "./dist/index.js",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"homepage": "https://cairn-substrate.com",
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
48
|
-
"test": "tsx test/
|
|
48
|
+
"test": "tsx test/hostile.test.ts && tsx test/input-canon.test.ts",
|
|
49
|
+
"test:live": "tsx test/client.test.ts"
|
|
49
50
|
}
|
|
50
51
|
}
|