@inversealtruism/csd-client 0.1.18 → 0.1.20

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 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 ?? JSON.parse;
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;
@@ -71,17 +72,54 @@ interface RpcSubmit {
71
72
  mempool_len?: number;
72
73
  err?: string | null;
73
74
  }
75
+ interface RpcProposalRecord {
76
+ proposal_id: string;
77
+ domain: string;
78
+ payload_hash: string;
79
+ uri: string;
80
+ proposer: string;
81
+ created_height: number;
82
+ created_epoch: number;
83
+ fee: number | bigint;
84
+ expires_epoch: number | bigint;
85
+ }
86
+ /** `/proposal/:id`. An unknown id answers `{ ok: false, err }`, which `proposal()` throws. */
74
87
  interface RpcProposal {
75
- ok?: boolean;
88
+ ok: boolean;
89
+ proposal: RpcProposalRecord;
90
+ err?: string;
91
+ }
92
+ /** One row of `/proposals/:domain/:limit`; the feed names no proposer. */
93
+ interface RpcProposalItem {
94
+ proposal_id: string;
76
95
  txid: string;
96
+ block_hash: string;
97
+ height: number;
98
+ time: number;
77
99
  domain: string;
78
100
  payload_hash: string;
79
101
  uri: string;
80
- expires_epoch: number;
81
- proposer: string;
102
+ expires_epoch: number | bigint;
103
+ }
104
+ interface RpcProposals {
105
+ ok: boolean;
106
+ tip: string;
82
107
  height: number;
83
- attestations?: unknown[];
84
- [k: string]: unknown;
108
+ scanned_blocks: number;
109
+ count: number;
110
+ proposals: RpcProposalItem[];
111
+ }
112
+ interface RpcDomain {
113
+ domain: string;
114
+ proposals: number;
115
+ attestations: number;
116
+ }
117
+ interface RpcDomains {
118
+ ok: boolean;
119
+ tip: string;
120
+ height: number;
121
+ count: number;
122
+ domains: RpcDomain[];
85
123
  }
86
124
  interface RpcTxInfo {
87
125
  ok: boolean;
@@ -92,12 +130,23 @@ interface RpcTxInfo {
92
130
  tx?: RpcTxJson;
93
131
  err?: string;
94
132
  }
133
+ /** `ok` is false while a node task has stopped. The last three are null until known and absent on nodes before
134
+ * overlay 0.1.7. */
95
135
  interface RpcHealth {
96
136
  ok: boolean;
97
- height?: number;
98
- peers?: number;
99
- mempool_len?: number;
100
- [k: string]: unknown;
137
+ tip: string;
138
+ height: number;
139
+ chainwork: string;
140
+ peer_count: number;
141
+ known_peers: number;
142
+ mempool_tx_count: number;
143
+ mempool_spent_outpoints: number;
144
+ mempool_bytes: number;
145
+ mempool_min_feerate_ppm: number | bigint | null;
146
+ mempool_max_feerate_ppm: number | bigint | null;
147
+ best_peer_height?: number | null;
148
+ blocks_behind?: number | null;
149
+ secs_since_tip_activity?: number | null;
101
150
  }
102
151
  interface WaitForTxResult {
103
152
  txid: string;
@@ -118,13 +167,11 @@ interface ClientOptions {
118
167
  * path (audit M2). Default 16 MiB ≫ any real block; raise it for an unusually large block source.
119
168
  */
120
169
  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
- */
170
+ /** JSON body parser; default `parseJsonExact`, so a u64 above 2^53 survives to the txid recompute. */
126
171
  parseJson?: (text: string) => unknown;
127
172
  }
173
+ /** JSON.parse, except that an integer literal outside the safe JS range is returned as an exact bigint. */
174
+ declare function parseJsonExact(text: string): unknown;
128
175
  declare class CsdClient {
129
176
  private readonly base;
130
177
  private readonly f;
@@ -154,9 +201,9 @@ declare class CsdClient {
154
201
  available?: boolean;
155
202
  }): Promise<RpcUtxos>;
156
203
  proposal(id: string): Promise<RpcProposal>;
157
- proposals(domain: string, limit?: number): Promise<RpcProposal[]>;
204
+ proposals(domain: string, limit?: number): Promise<RpcProposals>;
158
205
  topDomain(domain: string, epoch?: number): Promise<unknown>;
159
- domains(): Promise<string[]>;
206
+ domains(): Promise<RpcDomains>;
160
207
  mempool(): Promise<unknown>;
161
208
  /**
162
209
  * Await a txid reaching `confirmations` (default 1) — the submit-then-confirm flow every
@@ -210,4 +257,4 @@ declare function verifyInputValues(client: {
210
257
  /** Convert a node /block header JSON into the codec's BlockHeader. */
211
258
  declare function rpcHeaderToHeader(h: RpcHeaderJson): BlockHeader;
212
259
 
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 };
260
+ export { type ClientOptions, CsdClient, type RpcBlock, type RpcDomain, type RpcDomains, type RpcHeaderJson, type RpcHealth, type RpcProposal, type RpcProposalItem, type RpcProposalRecord, type RpcProposals, 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;
@@ -71,17 +72,54 @@ interface RpcSubmit {
71
72
  mempool_len?: number;
72
73
  err?: string | null;
73
74
  }
75
+ interface RpcProposalRecord {
76
+ proposal_id: string;
77
+ domain: string;
78
+ payload_hash: string;
79
+ uri: string;
80
+ proposer: string;
81
+ created_height: number;
82
+ created_epoch: number;
83
+ fee: number | bigint;
84
+ expires_epoch: number | bigint;
85
+ }
86
+ /** `/proposal/:id`. An unknown id answers `{ ok: false, err }`, which `proposal()` throws. */
74
87
  interface RpcProposal {
75
- ok?: boolean;
88
+ ok: boolean;
89
+ proposal: RpcProposalRecord;
90
+ err?: string;
91
+ }
92
+ /** One row of `/proposals/:domain/:limit`; the feed names no proposer. */
93
+ interface RpcProposalItem {
94
+ proposal_id: string;
76
95
  txid: string;
96
+ block_hash: string;
97
+ height: number;
98
+ time: number;
77
99
  domain: string;
78
100
  payload_hash: string;
79
101
  uri: string;
80
- expires_epoch: number;
81
- proposer: string;
102
+ expires_epoch: number | bigint;
103
+ }
104
+ interface RpcProposals {
105
+ ok: boolean;
106
+ tip: string;
82
107
  height: number;
83
- attestations?: unknown[];
84
- [k: string]: unknown;
108
+ scanned_blocks: number;
109
+ count: number;
110
+ proposals: RpcProposalItem[];
111
+ }
112
+ interface RpcDomain {
113
+ domain: string;
114
+ proposals: number;
115
+ attestations: number;
116
+ }
117
+ interface RpcDomains {
118
+ ok: boolean;
119
+ tip: string;
120
+ height: number;
121
+ count: number;
122
+ domains: RpcDomain[];
85
123
  }
86
124
  interface RpcTxInfo {
87
125
  ok: boolean;
@@ -92,12 +130,23 @@ interface RpcTxInfo {
92
130
  tx?: RpcTxJson;
93
131
  err?: string;
94
132
  }
133
+ /** `ok` is false while a node task has stopped. The last three are null until known and absent on nodes before
134
+ * overlay 0.1.7. */
95
135
  interface RpcHealth {
96
136
  ok: boolean;
97
- height?: number;
98
- peers?: number;
99
- mempool_len?: number;
100
- [k: string]: unknown;
137
+ tip: string;
138
+ height: number;
139
+ chainwork: string;
140
+ peer_count: number;
141
+ known_peers: number;
142
+ mempool_tx_count: number;
143
+ mempool_spent_outpoints: number;
144
+ mempool_bytes: number;
145
+ mempool_min_feerate_ppm: number | bigint | null;
146
+ mempool_max_feerate_ppm: number | bigint | null;
147
+ best_peer_height?: number | null;
148
+ blocks_behind?: number | null;
149
+ secs_since_tip_activity?: number | null;
101
150
  }
102
151
  interface WaitForTxResult {
103
152
  txid: string;
@@ -118,13 +167,11 @@ interface ClientOptions {
118
167
  * path (audit M2). Default 16 MiB ≫ any real block; raise it for an unusually large block source.
119
168
  */
120
169
  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
- */
170
+ /** JSON body parser; default `parseJsonExact`, so a u64 above 2^53 survives to the txid recompute. */
126
171
  parseJson?: (text: string) => unknown;
127
172
  }
173
+ /** JSON.parse, except that an integer literal outside the safe JS range is returned as an exact bigint. */
174
+ declare function parseJsonExact(text: string): unknown;
128
175
  declare class CsdClient {
129
176
  private readonly base;
130
177
  private readonly f;
@@ -154,9 +201,9 @@ declare class CsdClient {
154
201
  available?: boolean;
155
202
  }): Promise<RpcUtxos>;
156
203
  proposal(id: string): Promise<RpcProposal>;
157
- proposals(domain: string, limit?: number): Promise<RpcProposal[]>;
204
+ proposals(domain: string, limit?: number): Promise<RpcProposals>;
158
205
  topDomain(domain: string, epoch?: number): Promise<unknown>;
159
- domains(): Promise<string[]>;
206
+ domains(): Promise<RpcDomains>;
160
207
  mempool(): Promise<unknown>;
161
208
  /**
162
209
  * Await a txid reaching `confirmations` (default 1) — the submit-then-confirm flow every
@@ -210,4 +257,4 @@ declare function verifyInputValues(client: {
210
257
  /** Convert a node /block header JSON into the codec's BlockHeader. */
211
258
  declare function rpcHeaderToHeader(h: RpcHeaderJson): BlockHeader;
212
259
 
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 };
260
+ export { type ClientOptions, CsdClient, type RpcBlock, type RpcDomain, type RpcDomains, type RpcHeaderJson, type RpcHealth, type RpcProposal, type RpcProposalItem, type RpcProposalRecord, type RpcProposals, 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 ?? JSON.parse;
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.18",
3
+ "version": "0.1.20",
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) — tip/block/tx/utxos/proposals/top/domains/mempool/submit/templates.",
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/client.test.ts && tsx test/hostile.test.ts && tsx test/input-canon.test.ts"
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
  }