@kynesyslabs/demosdk 4.0.14 → 4.0.16

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.
Files changed (35) hide show
  1. package/build/abstraction/Identities.js +11 -1
  2. package/build/abstraction/Identities.js.map +1 -1
  3. package/build/bridge/index.d.ts +1 -1
  4. package/build/bridge/index.js +0 -1
  5. package/build/bridge/index.js.map +1 -1
  6. package/build/bridge/rubic.d.ts +1 -0
  7. package/build/bridge/rubic.js +10 -0
  8. package/build/bridge/rubic.js.map +1 -0
  9. package/build/bridge/rubicBridge.d.ts +1 -1
  10. package/build/demoswork/operations/conditional/index.d.ts +1 -1
  11. package/build/demoswork/operations/conditional/index.js +1 -1
  12. package/build/demoswork/operations/conditional/index.js.map +1 -1
  13. package/build/encryption/zK/identity/ProofGenerator.js +10 -2
  14. package/build/encryption/zK/identity/ProofGenerator.js.map +1 -1
  15. package/build/types/index.d.ts +2 -2
  16. package/build/types/index.js +2 -2
  17. package/build/types/index.js.map +1 -1
  18. package/build/types/token/index.d.ts +1 -1
  19. package/build/types/token/index.js +1 -1
  20. package/build/types/token/index.js.map +1 -1
  21. package/build/utils/index.d.ts +1 -1
  22. package/build/utils/index.js +7 -1
  23. package/build/utils/index.js.map +1 -1
  24. package/build/websdk/DemosTransactions.js +8 -8
  25. package/build/websdk/DemosTransactions.js.map +1 -1
  26. package/build/websdk/NonceManager.d.ts +62 -0
  27. package/build/websdk/NonceManager.js +108 -0
  28. package/build/websdk/NonceManager.js.map +1 -0
  29. package/build/websdk/Web2Calls.js +2 -1
  30. package/build/websdk/Web2Calls.js.map +1 -1
  31. package/build/websdk/bridge.d.ts +1 -1
  32. package/build/websdk/demosclass.d.ts +180 -2
  33. package/build/websdk/demosclass.js +239 -7
  34. package/build/websdk/demosclass.js.map +1 -1
  35. package/package.json +6 -2
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Per-address nonce sequencer for a single Demos client.
3
+ *
4
+ * The node reports an address's nonce lagging inclusion: `getAddressNonce()`
5
+ * returns the last confirmed nonce, not counting transactions already
6
+ * broadcast but not yet included. So two sends fired back-to-back both read
7
+ * the same on-chain value, compute the same nonce, and collide — the node
8
+ * rejects the second one. That is the batch-failure mode apps hit when
9
+ * sending several transactions from the same address at once.
10
+ *
11
+ * NonceManager fixes this on the client: it keeps a local "next nonce" per
12
+ * address, seeded once from the node, then hands out strictly increasing
13
+ * nonces without re-reading the lagging chain value between sends.
14
+ * Reservations are serialized per address so concurrent callers never share
15
+ * a nonce.
16
+ *
17
+ * Boundary: this only sequences sends from THIS client. If the same key
18
+ * signs from another client/device concurrently, the local counter drifts
19
+ * from the chain — call {@link reset} to reseed from the node. Likewise, a
20
+ * reserved nonce is consumed at build time; if that transaction never lands
21
+ * the counter runs ahead of the chain, so callers should {@link reset} the
22
+ * address after a nonce-rejection so the next reservation reseeds.
23
+ */
24
+ export declare class NonceManager {
25
+ /** Next nonce to hand out per address (absent = not yet seeded). */
26
+ private readonly next;
27
+ /** Per-address serialization tail so concurrent reservations don't race. */
28
+ private readonly tail;
29
+ /**
30
+ * Per-address reset generation. Bumped by {@link reset}/{@link resetAll}
31
+ * so a reservation whose seed fetch straddled a reset does not write its
32
+ * now-stale seed back into `next`.
33
+ */
34
+ private readonly epoch;
35
+ /**
36
+ * Reserve the next nonce for `address`, serialized against other
37
+ * reservations for the same address. Seeds from `fetchNext` on first use
38
+ * (or after {@link reset}); `fetchNext` must resolve the first usable nonce
39
+ * for the address — the confirmed on-chain nonce plus one
40
+ * (`Demos.getAddressNonce(address) + 1`). Subsequent reservations increment
41
+ * locally, which is what keeps concurrent sends from colliding.
42
+ */
43
+ reserve(address: string, fetchNext: () => Promise<number>): Promise<number>;
44
+ /**
45
+ * Drop local state for `address` so the next {@link reserve} reseeds from
46
+ * the node. Call after a broadcast fails with a nonce error, or when
47
+ * another client may have sent from the same address.
48
+ */
49
+ reset(address: string): void;
50
+ /** Drop local state for every address. */
51
+ resetAll(): void;
52
+ /**
53
+ * Force the next nonce for `address` (advanced use / recovery). The next
54
+ * {@link reserve} returns exactly `nextNonce`.
55
+ */
56
+ seed(address: string, nextNonce: number): void;
57
+ /**
58
+ * The nonce the next {@link reserve} would hand out for `address`, or
59
+ * `undefined` if the address has not been seeded yet.
60
+ */
61
+ peek(address: string): number | undefined;
62
+ }
@@ -0,0 +1,108 @@
1
+ import { assertValidNonce } from "../utils/index.js";
2
+ /**
3
+ * Per-address nonce sequencer for a single Demos client.
4
+ *
5
+ * The node reports an address's nonce lagging inclusion: `getAddressNonce()`
6
+ * returns the last confirmed nonce, not counting transactions already
7
+ * broadcast but not yet included. So two sends fired back-to-back both read
8
+ * the same on-chain value, compute the same nonce, and collide — the node
9
+ * rejects the second one. That is the batch-failure mode apps hit when
10
+ * sending several transactions from the same address at once.
11
+ *
12
+ * NonceManager fixes this on the client: it keeps a local "next nonce" per
13
+ * address, seeded once from the node, then hands out strictly increasing
14
+ * nonces without re-reading the lagging chain value between sends.
15
+ * Reservations are serialized per address so concurrent callers never share
16
+ * a nonce.
17
+ *
18
+ * Boundary: this only sequences sends from THIS client. If the same key
19
+ * signs from another client/device concurrently, the local counter drifts
20
+ * from the chain — call {@link reset} to reseed from the node. Likewise, a
21
+ * reserved nonce is consumed at build time; if that transaction never lands
22
+ * the counter runs ahead of the chain, so callers should {@link reset} the
23
+ * address after a nonce-rejection so the next reservation reseeds.
24
+ */
25
+ export class NonceManager {
26
+ constructor() {
27
+ /** Next nonce to hand out per address (absent = not yet seeded). */
28
+ this.next = new Map();
29
+ /** Per-address serialization tail so concurrent reservations don't race. */
30
+ this.tail = new Map();
31
+ /**
32
+ * Per-address reset generation. Bumped by {@link reset}/{@link resetAll}
33
+ * so a reservation whose seed fetch straddled a reset does not write its
34
+ * now-stale seed back into `next`.
35
+ */
36
+ this.epoch = new Map();
37
+ }
38
+ /**
39
+ * Reserve the next nonce for `address`, serialized against other
40
+ * reservations for the same address. Seeds from `fetchNext` on first use
41
+ * (or after {@link reset}); `fetchNext` must resolve the first usable nonce
42
+ * for the address — the confirmed on-chain nonce plus one
43
+ * (`Demos.getAddressNonce(address) + 1`). Subsequent reservations increment
44
+ * locally, which is what keeps concurrent sends from colliding.
45
+ */
46
+ async reserve(address, fetchNext) {
47
+ const prior = this.tail.get(address) ?? Promise.resolve();
48
+ const run = prior.then(async () => {
49
+ let n = this.next.get(address);
50
+ if (n === undefined) {
51
+ // Seed once. `fetchNext` returns the first usable nonce;
52
+ // validate it so a bad node reply (NaN/negative/fractional)
53
+ // can't poison every later reservation. Subsequent
54
+ // reservations increment locally so rapid sends don't re-read
55
+ // the lagging confirmed nonce.
56
+ const startEpoch = this.epoch.get(address) ?? 0;
57
+ n = assertValidNonce(await fetchNext());
58
+ if ((this.epoch.get(address) ?? 0) !== startEpoch) {
59
+ // A reset() landed while we were fetching the seed. Honour
60
+ // it: hand this value to the caller but don't cache it, so
61
+ // the next reservation reseeds from the node afresh.
62
+ return n;
63
+ }
64
+ }
65
+ this.next.set(address, n + 1);
66
+ return n;
67
+ });
68
+ // Swallow the tail's outcome so one rejected reservation (e.g. a
69
+ // transient getAddressNonce failure during seeding) does not poison
70
+ // every later reservation for this address. The real error still
71
+ // surfaces to this caller via `run`.
72
+ this.tail.set(address, run.then(() => undefined, () => undefined));
73
+ return run;
74
+ }
75
+ /**
76
+ * Drop local state for `address` so the next {@link reserve} reseeds from
77
+ * the node. Call after a broadcast fails with a nonce error, or when
78
+ * another client may have sent from the same address.
79
+ */
80
+ reset(address) {
81
+ this.next.delete(address);
82
+ this.epoch.set(address, (this.epoch.get(address) ?? 0) + 1);
83
+ }
84
+ /** Drop local state for every address. */
85
+ resetAll() {
86
+ this.next.clear();
87
+ // Bump the epoch of every address seen so far (the tail retains them)
88
+ // so any in-flight reservation reseeds instead of writing stale state.
89
+ for (const address of this.tail.keys()) {
90
+ this.epoch.set(address, (this.epoch.get(address) ?? 0) + 1);
91
+ }
92
+ }
93
+ /**
94
+ * Force the next nonce for `address` (advanced use / recovery). The next
95
+ * {@link reserve} returns exactly `nextNonce`.
96
+ */
97
+ seed(address, nextNonce) {
98
+ this.next.set(address, assertValidNonce(nextNonce));
99
+ }
100
+ /**
101
+ * The nonce the next {@link reserve} would hand out for `address`, or
102
+ * `undefined` if the address has not been seeded yet.
103
+ */
104
+ peek(address) {
105
+ return this.next.get(address);
106
+ }
107
+ }
108
+ //# sourceMappingURL=NonceManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NonceManager.js","sourceRoot":"","sources":["../../../src/websdk/NonceManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,YAAY;IAAzB;QACI,oEAAoE;QACnD,SAAI,GAAG,IAAI,GAAG,EAAkB,CAAA;QACjD,4EAA4E;QAC3D,SAAI,GAAG,IAAI,GAAG,EAA4B,CAAA;QAC3D;;;;WAIG;QACc,UAAK,GAAG,IAAI,GAAG,EAAkB,CAAA;IAoFtD,CAAC;IAlFG;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CACT,OAAe,EACf,SAAgC;QAEhC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAA;QACzD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YAC9B,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YAC9B,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;gBAClB,yDAAyD;gBACzD,4DAA4D;gBAC5D,mDAAmD;gBACnD,8DAA8D;gBAC9D,+BAA+B;gBAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;gBAC/C,CAAC,GAAG,gBAAgB,CAAC,MAA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GG;IACH,IAAI,CAAC,OAAe,EAAE,SAAiB;QACnC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAA;IACvD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAe;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;CACJ"}
@@ -135,7 +135,8 @@ export class Web2Proxy {
135
135
  web2Tx.content.type = "web2Request";
136
136
  web2Tx.content.data = ["web2Request", web2Payload];
137
137
  web2Tx.content.timestamp = Date.now();
138
- const nonce = await resolveNonce(options?.nonce, async () => this._demos.getAddressNonce(await this._demos.getEd25519Address()));
138
+ const fromAddress = await this._demos.getEd25519Address();
139
+ const nonce = await resolveNonce(options?.nonce, () => this._demos.getAddressNonce(fromAddress), this._demos._nonceReserver(fromAddress));
139
140
  web2Tx.content.nonce = nonce;
140
141
  const signedWeb2Tx = await this._demos.sign(web2Tx);
141
142
  const validityData = await this._demos.confirm(signedWeb2Tx);
@@ -1 +1 @@
1
- {"version":3,"file":"Web2Calls.js","sourceRoot":"","sources":["../../../src/websdk/Web2Calls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,OAAO,EACH,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,GACtB,MAAM,uBAAuB,CAAA;AAO9B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,MAAM,mBAAoB,SAAQ,KAAK;IAEnC,YAAY,OAAe,EAAE,IAAY;QACrC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;I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C,CAAA;QAClE,CAAC;QAED,kDAAkD;QAClD,MAAM,gBAAgB,GAAG,EAAE,GAAG,YAAY,EAAE,CAAA;QAC5C,gBAAgB,CAAC,GAAG,GAAG;YACnB,GAAG,gBAAgB,CAAC,GAAG;YACvB,MAAM,EAAE,eAAe,CAAC,MAAM;SACjC,CAAA;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAClD,WAAW,EAAE,gBAAgB;SAChC,CAAC,CAAA;QAEF,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAA;QACpD,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;QACrD,CAAC;QAED,OAAO,IAAI,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IAC1C,CAAC;CACJ,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import { RPCResponse } from "../types";
2
2
  import { BridgeTradePayload } from "../types/bridge/bridgeTradePayload";
3
3
  import { Demos } from "./demosclass";
4
- import { WrappedCrossChainTrade } from "rubic-sdk";
4
+ import type { WrappedCrossChainTrade } from "rubic-sdk";
5
5
  export declare class RubicBridge {
6
6
  getTrade(demos: Demos, chain: string, payload: BridgeTradePayload): Promise<RPCResponse>;
7
7
  executeTrade(demos: Demos, chain: string, payload: BridgeTradePayload): Promise<RPCResponse>;
@@ -42,6 +42,14 @@ export declare class Demos {
42
42
  * still see the warning exactly once per instance lifetime.
43
43
  */
44
44
  private static readonly _NETWORK_INFO_FAILURE_TTL_MS;
45
+ /**
46
+ * Client-side nonce sequencer. Opt-in via {@link enableAutoNonce}. When
47
+ * enabled, transaction builders reserve nonces from this manager instead
48
+ * of re-reading the lagging chain nonce, so batched sends from the same
49
+ * address don't collide. See {@link NonceManager}.
50
+ */
51
+ private readonly _nonceManager;
52
+ private _autoNonce;
45
53
  /** Connection status of the RPC URL */
46
54
  connected: boolean;
47
55
  dual_sign: boolean;
@@ -132,6 +140,29 @@ export declare class Demos {
132
140
  */
133
141
  dual_sign?: boolean;
134
142
  }): Promise<string>;
143
+ /**
144
+ * Connect a wallet from a hex-encoded key instead of a mnemonic.
145
+ *
146
+ * `connectWallet(<string>)` treats a non-mnemonic string as a BIP-39
147
+ * *passphrase* (PBKDF2), so passing a raw hex key there silently derives an
148
+ * unexpected identity. This method decodes the hex to bytes and feeds them to
149
+ * `connectWallet` as the master seed — a deterministic identity from the key,
150
+ * on the exact same derivation path as `connectWallet(<bytes>)`. Existing
151
+ * derivation is unchanged.
152
+ *
153
+ * Note: the hex is used as the SDK **master seed**, not as a literal ed25519
154
+ * seed — the keypair is still derived (sha3_512 → HKDF → forge). Use this for
155
+ * service accounts that want a stable identity from a fixed secret; it does not
156
+ * import a keypair produced by an external ed25519 tool.
157
+ *
158
+ * @param privateKeyHex - A 32-byte key as 64 hex chars, optionally `0x`-prefixed.
159
+ * @param options - Same options as {@link connectWallet}.
160
+ * @returns The public key of the connected wallet (hex).
161
+ */
162
+ connectWalletFromPrivateKey(privateKeyHex: string, options?: {
163
+ algorithm?: SigningAlgorithm;
164
+ dual_sign?: boolean;
165
+ }): Promise<string>;
135
166
  /**
136
167
  * Returns the public key of the connected wallet.
137
168
  *
@@ -174,9 +205,13 @@ export declare class Demos {
174
205
  * await demos.pay("0x...", 100) // legacy DEM number (deprecated)
175
206
  * ```
176
207
  *
208
+ * ⚠️ This only **signs** the transaction — it does NOT broadcast it, so
209
+ * on its own it moves no funds. Use {@link payAndWait} (or
210
+ * {@link transferAndWait}) to sign, broadcast, and wait for inclusion.
211
+ *
177
212
  * @param to - The receiver address (0x-prefixed hex).
178
213
  * @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
179
- * @returns The signed transaction.
214
+ * @returns The signed transaction (NOT broadcast).
180
215
  */
181
216
  pay(to: string, amount: number | bigint, options?: {
182
217
  nonce?: number;
@@ -194,13 +229,90 @@ export declare class Demos {
194
229
  * await demos.transfer("0x...", 1_500_000_000n) // raw OS
195
230
  * ```
196
231
  *
232
+ * ⚠️ Like {@link pay}, this only **signs** — it does NOT broadcast. Use
233
+ * {@link transferAndWait} to sign, broadcast, and wait for inclusion.
234
+ *
197
235
  * @param to - The receiver address (0x-prefixed hex).
198
236
  * @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
199
- * @returns The signed transaction.
237
+ * @returns The signed transaction (NOT broadcast).
200
238
  */
201
239
  transfer(to: string, amount: number | bigint, options?: {
202
240
  nonce?: number;
203
241
  }): Promise<Transaction>;
242
+ /**
243
+ * Sign, broadcast, and wait for a native transfer to land on chain.
244
+ *
245
+ * The broadcasting counterpart to {@link pay}: it runs the full path
246
+ * (sign → confirm → broadcastAndWait), so the funds actually move. Prefer
247
+ * this over `pay`/`transfer` unless you deliberately want to handle
248
+ * broadcasting yourself. Throws `BroadcastTimeoutError` if the transaction
249
+ * doesn't reach a terminal state before the timeout.
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * import { denomination } from "@kynesyslabs/demosdk"
254
+ * await demos.payAndWait("0x...", denomination.demToOs(100)) // sent & confirmed
255
+ * ```
256
+ *
257
+ * @param to - The receiver address (0x-prefixed hex).
258
+ * @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
259
+ * @param options.nonce - Optional explicit nonce.
260
+ * @param options.timeoutMs - Max time to wait for on-chain inclusion (the
261
+ * broadcast-and-poll phase). Defaults to 60_000. The preceding confirm
262
+ * RPC is a single call and is not bounded by this.
263
+ * @param options.pollIntervalMs - Delay between inclusion polls. Defaults to 500.
264
+ * @param options.failFastOnBroadcastError - Reject immediately if the broadcast
265
+ * RPC errors, instead of polling for a terminal status.
266
+ * @returns `{ broadcast, status }` — the broadcast RPC response and the
267
+ * terminal on-chain status (`included` | `failed`, with optional `blockNumber`).
268
+ */
269
+ payAndWait(to: string, amount: number | bigint, options?: {
270
+ nonce?: number;
271
+ timeoutMs?: number;
272
+ pollIntervalMs?: number;
273
+ failFastOnBroadcastError?: boolean;
274
+ }): Promise<{
275
+ broadcast: RPCResponse;
276
+ status: {
277
+ state: "included" | "failed";
278
+ blockNumber?: number;
279
+ };
280
+ }>;
281
+ /**
282
+ * Alias of {@link payAndWait}: sign, broadcast, and wait for a native
283
+ * transfer. The broadcasting counterpart to {@link transfer} (which only
284
+ * signs).
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * import { denomination } from "@kynesyslabs/demosdk"
289
+ * await demos.transferAndWait("0x...", denomination.demToOs(100)) // sent & confirmed
290
+ * ```
291
+ *
292
+ * @param to - The receiver address (0x-prefixed hex).
293
+ * @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
294
+ * @param options.nonce - Optional explicit nonce.
295
+ * @param options.timeoutMs - Max time to wait for on-chain inclusion (the
296
+ * broadcast-and-poll phase). Defaults to 60_000. The preceding confirm
297
+ * RPC is a single call and is not bounded by this.
298
+ * @param options.pollIntervalMs - Delay between inclusion polls. Defaults to 500.
299
+ * @param options.failFastOnBroadcastError - Reject immediately if the broadcast
300
+ * RPC errors, instead of polling for a terminal status.
301
+ * @returns `{ broadcast, status }` — the broadcast RPC response and the
302
+ * terminal on-chain status (`included` | `failed`, with optional `blockNumber`).
303
+ */
304
+ transferAndWait(to: string, amount: number | bigint, options?: {
305
+ nonce?: number;
306
+ timeoutMs?: number;
307
+ pollIntervalMs?: number;
308
+ failFastOnBroadcastError?: boolean;
309
+ }): Promise<{
310
+ broadcast: RPCResponse;
311
+ status: {
312
+ state: "included" | "failed";
313
+ blockNumber?: number;
314
+ };
315
+ }>;
204
316
  /**
205
317
  * Create a signed DEMOS transaction to store binary data on the blockchain.
206
318
  * Data is stored in the sender's account.
@@ -257,10 +369,13 @@ export declare class Demos {
257
369
  * @param validationData - The validity data of the transaction
258
370
  * @param opts.timeoutMs - Total time to wait. Defaults to 60_000.
259
371
  * @param opts.pollIntervalMs - Delay between polls. Defaults to 500.
372
+ * @param opts.failFastOnBroadcastError - Reject immediately if the broadcast
373
+ * RPC errors, instead of polling for a terminal status.
260
374
  */
261
375
  broadcastAndWait(validationData: RPCResponseWithValidityData, opts?: {
262
376
  timeoutMs?: number;
263
377
  pollIntervalMs?: number;
378
+ failFastOnBroadcastError?: boolean;
264
379
  }): Promise<{
265
380
  broadcast: RPCResponse;
266
381
  status: {
@@ -465,6 +580,69 @@ export declare class Demos {
465
580
  * @param address - The address
466
581
  */
467
582
  getAddressNonce(address: string): Promise<number>;
583
+ /**
584
+ * Poll the node until the nonce for `address` reaches (or exceeds) `target`.
585
+ *
586
+ * The node's `getAddressNonce` lags inclusion, so sending several transactions
587
+ * back-to-back can silently evict one: the next `pay`/`sign` reads a stale
588
+ * nonce and collides. When you must sequence dependent sends, wait for the
589
+ * nonce to advance past the last-sent one before signing the next.
590
+ *
591
+ * (For a single native transfer, prefer {@link payAndWait}, which already waits
592
+ * for on-chain inclusion.)
593
+ *
594
+ * @param address - The account address (hex).
595
+ * @param target - The nonce value to wait for (e.g. `lastSentNonce + 1`).
596
+ * @param opts.timeoutMs - Total time to wait. Defaults to 60_000.
597
+ * @param opts.pollIntervalMs - Delay between polls. Defaults to 500.
598
+ * @returns The observed nonce (>= `target`).
599
+ * @throws if `target` isn't reached before the timeout elapses.
600
+ */
601
+ waitForNonce(address: string, target: number, opts?: {
602
+ timeoutMs?: number;
603
+ pollIntervalMs?: number;
604
+ }): Promise<number>;
605
+ /**
606
+ * Enable client-side nonce sequencing for this instance.
607
+ *
608
+ * Once enabled, every transaction builder reserves its nonce from a local
609
+ * per-address counter (seeded once from the node) instead of re-reading
610
+ * `getAddressNonce` for each send. This prevents the collisions that make
611
+ * batched sends from the same address fail — the node rejects two txs
612
+ * that reuse a nonce because `getAddressNonce` lags inclusion.
613
+ *
614
+ * Opt-in for now. Passing an explicit `options.nonce` still overrides the
615
+ * manager. If a send is rejected for a nonce error, call
616
+ * {@link resetNonce} so the next send reseeds from the chain.
617
+ */
618
+ enableAutoNonce(): void;
619
+ /** Disable client-side nonce sequencing and clear its local state. */
620
+ disableAutoNonce(): void;
621
+ /** Whether client-side nonce sequencing is enabled for this instance. */
622
+ get autoNonceEnabled(): boolean;
623
+ /**
624
+ * Reseed the local nonce counter for `address` (or every address) from the
625
+ * node on the next send. Call after a nonce-rejection, or when the same
626
+ * key may have sent from another client.
627
+ */
628
+ resetNonce(address?: string): void;
629
+ /**
630
+ * Reserver passed to `resolveNonce` by the transaction builders. Returns a
631
+ * function that sequences the nonce for `address` when auto-nonce is on,
632
+ * or `undefined` so `resolveNonce` keeps its historical per-send read.
633
+ *
634
+ * Seeds once from the confirmed on-chain nonce (`getAddressNonce() + 1`),
635
+ * then increments locally per send. Seeding from the confirmed nonce (not a
636
+ * mempool-aware value) is deliberate: the node accepts any nonce greater
637
+ * than the confirmed one, and the confirmed nonce is consistent across
638
+ * every RPC — whereas a per-RPC mempool count is not. The local counter is
639
+ * what keeps a batch's nonces distinct (`N+1, N+2, …`) so they don't
640
+ * collide; re-reading `getAddressNonce` for each send would not, because it
641
+ * lags inclusion.
642
+ *
643
+ * @internal
644
+ */
645
+ _nonceReserver(address: string): (() => Promise<number>) | undefined;
468
646
  /**
469
647
  * Get a validator's current record (stake, status, unstake timestamps).
470
648
  * Returns null if the address is not (and never was) a validator.