@inversealtruism/csd-client 0.1.16 → 0.1.18

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
@@ -27,6 +27,9 @@ __export(index_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(index_exports);
29
29
  var import_csd_codec = require("@inversealtruism/csd-codec");
30
+ var DEFAULT_MAX_RESPONSE_BYTES = 16 * 1024 * 1024;
31
+ var DEFAULT_RETRIES = 0;
32
+ var finiteOr = (v, dflt) => v !== void 0 && Number.isFinite(v) ? v : dflt;
30
33
  var CsdClient = class {
31
34
  base;
32
35
  f;
@@ -36,12 +39,12 @@ var CsdClient = class {
36
39
  parseJson;
37
40
  constructor(opts) {
38
41
  this.base = opts.baseUrl.replace(/\/+$/, "");
39
- this.maxBytes = Math.max(1, opts.maxResponseBytes ?? 16 * 1024 * 1024);
42
+ this.maxBytes = Math.max(1, finiteOr(opts.maxResponseBytes, DEFAULT_MAX_RESPONSE_BYTES));
40
43
  this.parseJson = opts.parseJson ?? JSON.parse;
41
44
  const gf = globalThis.fetch;
42
45
  this.f = opts.fetch ?? (gf ? gf.bind(globalThis) : gf);
43
46
  this.timeoutMs = opts.timeoutMs ?? 1e4;
44
- this.retries = Math.max(0, opts.retries ?? 0);
47
+ this.retries = Math.max(0, Math.floor(finiteOr(opts.retries, DEFAULT_RETRIES)));
45
48
  if (!this.f) throw new Error("no fetch available \u2014 pass opts.fetch");
46
49
  }
47
50
  async req(path, init, opts) {
@@ -137,9 +140,9 @@ var CsdClient = class {
137
140
  tx(id) {
138
141
  return this.get(`/tx/${id}`);
139
142
  }
140
- // Default available=true: excludes immature/locked coinbase UTXOs so callers don't build txs spending
141
- // un-spendable outputs (the node would silently reject them) — audit TXB-1-SDK. Pass {available:false}
142
- // for the full set (e.g. balance display that wants to show locked coinbases).
143
+ // Default available=true: the node drops only outpoints already spent by a tx in its mempool, so a builder
144
+ // does not pick a pending-spent input; coinbase outputs are not filtered. {available:false} returns every
145
+ // unspent output, pending-spent ones included (e.g. a balance display).
143
146
  utxos(addr, opts = {}) {
144
147
  return this.get(`/utxos/${addr}${opts.available === false ? "" : "?available=true"}`);
145
148
  }
@@ -167,6 +170,8 @@ var CsdClient = class {
167
170
  * rejects on timeout (default 10 min — CSD blocks are ~2 min but the live miner is lumpy).
168
171
  * A tx that drops OUT of the chain mid-wait (reorg) keeps polling until it re-confirms or
169
172
  * times out — never resolves on a stale sighting.
173
+ * The count is `tip.height - tx.height + 1` from the RPC's own /tx and /tip answers, with no PoW
174
+ * or inclusion check, so a lying RPC can over-state it. Gate funds on csd-light, not on this.
170
175
  */
171
176
  async waitForTx(txid, opts = {}) {
172
177
  const want = Math.max(1, opts.confirmations ?? 1);
package/dist/index.d.cts CHANGED
@@ -164,6 +164,8 @@ declare class CsdClient {
164
164
  * rejects on timeout (default 10 min — CSD blocks are ~2 min but the live miner is lumpy).
165
165
  * A tx that drops OUT of the chain mid-wait (reorg) keeps polling until it re-confirms or
166
166
  * times out — never resolves on a stale sighting.
167
+ * The count is `tip.height - tx.height + 1` from the RPC's own /tx and /tip answers, with no PoW
168
+ * or inclusion check, so a lying RPC can over-state it. Gate funds on csd-light, not on this.
167
169
  */
168
170
  waitForTx(txid: string, opts?: {
169
171
  confirmations?: number;
@@ -191,8 +193,7 @@ declare function rpcTxToTx(j: RpcTxJson): Tx;
191
193
  * a forged body whose recomputed txid still matches the prevout is impossible. Fail-CLOSED: any
192
194
  * unreachable/forged/missing source aborts. Returns the verified input total (use it to compute
193
195
  * change from REAL values, not the reported ones). RPC-facing builders (wallet, cairn-sdk) should
194
- * call this before assembling a spend; csd-tx itself is pure and cannot fetch.
195
- * (Mirrors the proven cairn-wallet `node.ts` implementation; the wallet's TXB-1 cure made canonical.) */
196
+ * call this before assembling a spend; csd-tx itself is pure and cannot fetch. */
196
197
  declare function verifyInputValues(client: {
197
198
  tx(id: string): Promise<RpcTxInfo>;
198
199
  }, inputs: {
package/dist/index.d.ts CHANGED
@@ -164,6 +164,8 @@ declare class CsdClient {
164
164
  * rejects on timeout (default 10 min — CSD blocks are ~2 min but the live miner is lumpy).
165
165
  * A tx that drops OUT of the chain mid-wait (reorg) keeps polling until it re-confirms or
166
166
  * times out — never resolves on a stale sighting.
167
+ * The count is `tip.height - tx.height + 1` from the RPC's own /tx and /tip answers, with no PoW
168
+ * or inclusion check, so a lying RPC can over-state it. Gate funds on csd-light, not on this.
167
169
  */
168
170
  waitForTx(txid: string, opts?: {
169
171
  confirmations?: number;
@@ -191,8 +193,7 @@ declare function rpcTxToTx(j: RpcTxJson): Tx;
191
193
  * a forged body whose recomputed txid still matches the prevout is impossible. Fail-CLOSED: any
192
194
  * unreachable/forged/missing source aborts. Returns the verified input total (use it to compute
193
195
  * change from REAL values, not the reported ones). RPC-facing builders (wallet, cairn-sdk) should
194
- * call this before assembling a spend; csd-tx itself is pure and cannot fetch.
195
- * (Mirrors the proven cairn-wallet `node.ts` implementation; the wallet's TXB-1 cure made canonical.) */
196
+ * call this before assembling a spend; csd-tx itself is pure and cannot fetch. */
196
197
  declare function verifyInputValues(client: {
197
198
  tx(id: string): Promise<RpcTxInfo>;
198
199
  }, inputs: {
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  // src/index.ts
2
2
  import { txid as codecTxid } from "@inversealtruism/csd-codec";
3
+ var DEFAULT_MAX_RESPONSE_BYTES = 16 * 1024 * 1024;
4
+ var DEFAULT_RETRIES = 0;
5
+ var finiteOr = (v, dflt) => v !== void 0 && Number.isFinite(v) ? v : dflt;
3
6
  var CsdClient = class {
4
7
  base;
5
8
  f;
@@ -9,12 +12,12 @@ var CsdClient = class {
9
12
  parseJson;
10
13
  constructor(opts) {
11
14
  this.base = opts.baseUrl.replace(/\/+$/, "");
12
- this.maxBytes = Math.max(1, opts.maxResponseBytes ?? 16 * 1024 * 1024);
15
+ this.maxBytes = Math.max(1, finiteOr(opts.maxResponseBytes, DEFAULT_MAX_RESPONSE_BYTES));
13
16
  this.parseJson = opts.parseJson ?? JSON.parse;
14
17
  const gf = globalThis.fetch;
15
18
  this.f = opts.fetch ?? (gf ? gf.bind(globalThis) : gf);
16
19
  this.timeoutMs = opts.timeoutMs ?? 1e4;
17
- this.retries = Math.max(0, opts.retries ?? 0);
20
+ this.retries = Math.max(0, Math.floor(finiteOr(opts.retries, DEFAULT_RETRIES)));
18
21
  if (!this.f) throw new Error("no fetch available \u2014 pass opts.fetch");
19
22
  }
20
23
  async req(path, init, opts) {
@@ -110,9 +113,9 @@ var CsdClient = class {
110
113
  tx(id) {
111
114
  return this.get(`/tx/${id}`);
112
115
  }
113
- // Default available=true: excludes immature/locked coinbase UTXOs so callers don't build txs spending
114
- // un-spendable outputs (the node would silently reject them) — audit TXB-1-SDK. Pass {available:false}
115
- // for the full set (e.g. balance display that wants to show locked coinbases).
116
+ // Default available=true: the node drops only outpoints already spent by a tx in its mempool, so a builder
117
+ // does not pick a pending-spent input; coinbase outputs are not filtered. {available:false} returns every
118
+ // unspent output, pending-spent ones included (e.g. a balance display).
116
119
  utxos(addr, opts = {}) {
117
120
  return this.get(`/utxos/${addr}${opts.available === false ? "" : "?available=true"}`);
118
121
  }
@@ -140,6 +143,8 @@ var CsdClient = class {
140
143
  * rejects on timeout (default 10 min — CSD blocks are ~2 min but the live miner is lumpy).
141
144
  * A tx that drops OUT of the chain mid-wait (reorg) keeps polling until it re-confirms or
142
145
  * times out — never resolves on a stale sighting.
146
+ * The count is `tip.height - tx.height + 1` from the RPC's own /tx and /tip answers, with no PoW
147
+ * or inclusion check, so a lying RPC can over-state it. Gate funds on csd-light, not on this.
143
148
  */
144
149
  async waitForTx(txid, opts = {}) {
145
150
  const want = Math.max(1, opts.confirmations ?? 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/csd-client",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
@@ -27,12 +27,12 @@
27
27
  "README.md"
28
28
  ],
29
29
  "dependencies": {
30
- "@inversealtruism/csd-codec": "0.1.16"
30
+ "@inversealtruism/csd-codec": "0.1.18"
31
31
  },
32
32
  "license": "MIT",
33
33
  "sideEffects": false,
34
34
  "devDependencies": {
35
- "@inversealtruism/csd-vectors": "0.1.15"
35
+ "@inversealtruism/csd-vectors": "0.1.16"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
@@ -45,6 +45,6 @@
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"
48
+ "test": "tsx test/client.test.ts && tsx test/hostile.test.ts && tsx test/input-canon.test.ts"
49
49
  }
50
50
  }