@inversealtruism/csd-client 0.1.17 → 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 +7 -2
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -2
- package/package.json +3 -3
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
|
|
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
|
|
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) {
|
|
@@ -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
|
|
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
|
|
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) {
|
|
@@ -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.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"README.md"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@inversealtruism/csd-codec": "0.1.
|
|
30
|
+
"@inversealtruism/csd-codec": "0.1.18"
|
|
31
31
|
},
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"sideEffects": false,
|
|
@@ -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
|
}
|