@secondlayer/stacks 2.5.2 → 2.6.0

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 (54) hide show
  1. package/dist/shared/stacks-1wra341e.cjs +146 -0
  2. package/dist/shared/stacks-1wra341e.cjs.map +15 -0
  3. package/dist/shared/{stacks-jevhg39n.cjs → stacks-7nf5h3qe.cjs} +16 -12
  4. package/dist/shared/{stacks-jevhg39n.cjs.map → stacks-7nf5h3qe.cjs.map} +4 -4
  5. package/dist/shared/{stacks-yq5a5cda.js → stacks-a9cn5ehj.js} +12 -10
  6. package/dist/shared/{stacks-yq5a5cda.js.map → stacks-a9cn5ehj.js.map} +3 -3
  7. package/dist/shared/{stacks-7wfdkhj6.cjs → stacks-e7pmsrbs.cjs} +9 -7
  8. package/dist/shared/{stacks-7wfdkhj6.cjs.map → stacks-e7pmsrbs.cjs.map} +3 -3
  9. package/dist/shared/{stacks-4z1jhw6y.js → stacks-ffsv2t3t.js} +6 -6
  10. package/dist/shared/{stacks-4z1jhw6y.js.map → stacks-ffsv2t3t.js.map} +3 -3
  11. package/dist/shared/{stacks-y8e3gx6w.js → stacks-gxhznn3h.js} +73 -3
  12. package/dist/shared/stacks-gxhznn3h.js.map +15 -0
  13. package/dist/shared/{stacks-hyz7zgdk.js → stacks-hr5rg2et.js} +2 -2
  14. package/dist/shared/{stacks-7wqprfrm.cjs → stacks-hxm7r5ay.cjs} +3 -3
  15. package/dist/shared/{stacks-7wqprfrm.cjs.map → stacks-hxm7r5ay.cjs.map} +3 -3
  16. package/dist/shared/{stacks-5th5dffx.js → stacks-yb8xesdm.js} +20 -16
  17. package/dist/shared/{stacks-5th5dffx.js.map → stacks-yb8xesdm.js.map} +4 -4
  18. package/dist/src/actions/index.d.cts +133 -120
  19. package/dist/src/actions/index.d.ts +133 -120
  20. package/dist/src/actions/index.js +5 -5
  21. package/dist/src/bns/index.d.cts +13 -0
  22. package/dist/src/bns/index.d.ts +13 -0
  23. package/dist/src/bns/index.js +3 -3
  24. package/dist/src/index.cjs +79 -5
  25. package/dist/src/index.cjs.map +6 -5
  26. package/dist/src/index.d.cts +228 -101
  27. package/dist/src/index.d.ts +228 -101
  28. package/dist/src/index.js +89 -9
  29. package/dist/src/index.js.map +6 -5
  30. package/dist/src/pox/index.d.cts +13 -0
  31. package/dist/src/pox/index.d.ts +13 -0
  32. package/dist/src/pox/index.js +3 -3
  33. package/dist/src/sbtc/index.d.cts +13 -0
  34. package/dist/src/sbtc/index.d.ts +13 -0
  35. package/dist/src/sbtc/index.js +3 -3
  36. package/dist/src/stackingdao/index.d.cts +13 -0
  37. package/dist/src/stackingdao/index.d.ts +13 -0
  38. package/dist/src/stackingdao/index.js +3 -3
  39. package/dist/src/subscriptions/index.d.cts +13 -0
  40. package/dist/src/subscriptions/index.d.ts +13 -0
  41. package/dist/src/tools/index.cjs +44 -14
  42. package/dist/src/tools/index.cjs.map +7 -6
  43. package/dist/src/tools/index.d.cts +13 -0
  44. package/dist/src/tools/index.d.ts +13 -0
  45. package/dist/src/tools/index.js +44 -14
  46. package/dist/src/tools/index.js.map +7 -6
  47. package/dist/src/x402/index.d.cts +13 -0
  48. package/dist/src/x402/index.d.ts +13 -0
  49. package/dist/src/x402/index.js +2 -2
  50. package/package.json +1 -1
  51. package/dist/shared/stacks-qk8pdyjy.cjs +0 -76
  52. package/dist/shared/stacks-qk8pdyjy.cjs.map +0 -14
  53. package/dist/shared/stacks-y8e3gx6w.js.map +0 -14
  54. /package/dist/shared/{stacks-hyz7zgdk.js.map → stacks-hr5rg2et.js.map} +0 -0
@@ -27,106 +27,6 @@ type ProviderAccount = {
27
27
  publicKey: string
28
28
  provider: StacksProvider
29
29
  };
30
- /** Full chain descriptor used by clients and transports for network-aware operations. */
31
- type StacksChain = {
32
- /** Chain ID (e.g. 0x00000001 for mainnet) */
33
- id: number
34
- /** Human-readable name */
35
- name: string
36
- /** Network type */
37
- network: "mainnet" | "testnet"
38
- /** Transaction version byte for serialization */
39
- transactionVersion: number
40
- /** Peer network ID for P2P broadcasting */
41
- peerNetworkId: number
42
- /** Address version bytes */
43
- addressVersion: {
44
- singleSig: number
45
- multiSig: number
46
- }
47
- /** Magic bytes for network identification */
48
- magicBytes: string
49
- /** Boot address (system contracts deployer) */
50
- bootAddress: string
51
- /** Native currency info */
52
- nativeCurrency: {
53
- name: string
54
- symbol: string
55
- decimals: number
56
- }
57
- /** Default RPC URLs */
58
- rpcUrls: {
59
- default: {
60
- http: string[]
61
- ws?: string[]
62
- }
63
- }
64
- /** Block explorer URLs */
65
- blockExplorers?: {
66
- default: {
67
- name: string
68
- url: string
69
- }
70
- }
71
- };
72
- /** Function that sends an HTTP request to a Stacks node API path. */
73
- type RequestFn = (path: string, options?: RequestOptions) => Promise<any>;
74
- /** Options for a transport-level HTTP request. */
75
- type RequestOptions = {
76
- method?: "GET" | "POST" | "PUT" | "DELETE"
77
- body?: unknown
78
- headers?: Record<string, string>
79
- };
80
- /** Shared configuration for all transport types. */
81
- type TransportConfig = {
82
- url?: string
83
- timeout?: number
84
- retryCount?: number
85
- retryDelay?: number
86
- fetchOptions?: RequestInit
87
- apiKey?: string
88
- };
89
- /** A resolved transport instance with a bound request function. */
90
- type Transport = {
91
- type: string
92
- request: RequestFn
93
- config: TransportConfig
94
- destroy?: () => void
95
- };
96
- /** Factory that creates a {@link Transport} given an optional chain context. */
97
- type TransportFactory = (params?: {
98
- chain?: StacksChain
99
- }) => Transport;
100
- /** Union of all supported account types (local key, custom signer, or browser provider). */
101
- type Account = LocalAccount | CustomAccount | ProviderAccount;
102
- /**
103
- * Core client instance that holds chain context, transport, and extensible actions.
104
- * Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}.
105
- */
106
- type Client<TExtended extends Record<string, unknown> = Record<string, unknown>> = {
107
- chain?: StacksChain
108
- account?: Account
109
- transport: Transport
110
- request: RequestFn
111
- extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
112
- } & TExtended;
113
- /** Configuration for creating a base {@link Client}. */
114
- type ClientConfig = {
115
- chain?: StacksChain
116
- transport: TransportFactory
117
- account?: Account
118
- };
119
- /** A client pre-extended with read-only {@link PublicActions}. */
120
- type PublicClient<TExtended extends Record<string, unknown> = Record<string, unknown>> = Client<TExtended>;
121
- /** A client pre-extended with {@link WalletActions} and a required account. */
122
- type WalletClient<TExtended extends Record<string, unknown> = Record<string, unknown>> = Client<TExtended> & {
123
- account: Account
124
- };
125
- /**
126
- * Create a base client with transport and optional chain/account.
127
- * Use `.extend()` to compose action decorators (public, wallet, multisig).
128
- */
129
- declare function createClient<TExtended extends Record<string, unknown> = Record<string, unknown>>(config: ClientConfig): Client<TExtended>;
130
30
  type IntCV = {
131
31
  readonly type: "int"
132
32
  readonly value: bigint
@@ -377,6 +277,187 @@ type AssetInfoWire = {
377
277
  contractName: string
378
278
  assetName: string
379
279
  };
280
+ /**
281
+ * Provides the confirmed on-chain nonce floor for an address.
282
+ *
283
+ * The default {@link jsonRpcSource} reads the configured node's `/v2/accounts`
284
+ * endpoint — node-agnostic, no Hiro dependency. Other sources (mempool-aware,
285
+ * first-party Index) can be swapped in without touching the manager.
286
+ */
287
+ type NonceManagerSource = {
288
+ get(params: {
289
+ client: Client
290
+ address: string
291
+ }): Promise<bigint>
292
+ };
293
+ /**
294
+ * Holds per-address allocation state and hands out the next nonce.
295
+ *
296
+ * `reserve` MUST be atomic per `key`: two concurrent reservations for the same
297
+ * key must never return the same value. The in-memory {@link memoryStore}
298
+ * serializes with a per-key promise chain; a persisted store (Redis `INCR`,
299
+ * Postgres `SELECT ... FOR UPDATE`) becomes the cross-process lock for the
300
+ * multi-builder / smart-wallet-as-a-service case.
301
+ */
302
+ type NonceStore = {
303
+ /**
304
+ * Reserve the next nonce for `key`. `getFloor` reads the confirmed on-chain
305
+ * nonce; it is only invoked when the store has no tracked value (cold start
306
+ * or after {@link NonceStore.reset}).
307
+ */
308
+ reserve(key: string, getFloor: () => Promise<bigint>): Promise<bigint>
309
+ /** Forget tracked state for `key` so the next reserve re-syncs from the floor. */
310
+ reset(key: string): void | Promise<void>
311
+ };
312
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
313
+ type NonceManager = {
314
+ consume(params: {
315
+ client: Client
316
+ address: string
317
+ }): Promise<bigint>
318
+ reset(params: {
319
+ client: Client
320
+ address: string
321
+ }): void | Promise<void>
322
+ };
323
+ type CreateNonceManagerParams = {
324
+ source?: NonceManagerSource
325
+ store?: NonceStore
326
+ };
327
+ /** Confirmed-nonce source backed by the configured node's `/v2/accounts` RPC (no Hiro dependency). */
328
+ declare function jsonRpcSource(): NonceManagerSource;
329
+ /**
330
+ * In-memory, single-process store. Tracks the next nonce per key and serializes
331
+ * concurrent reservations with a per-key promise chain.
332
+ *
333
+ * Correct only within one process — swap in a persisted store for multi-process
334
+ * deployments that share a signing key.
335
+ */
336
+ declare function memoryStore(): NonceStore;
337
+ /**
338
+ * Create a nonce manager that floors on a confirmed-nonce {@link NonceManagerSource}
339
+ * and increments a {@link NonceStore} on every {@link NonceManager.consume}.
340
+ *
341
+ * Defaults to {@link jsonRpcSource} + {@link memoryStore} — node-agnostic,
342
+ * single-process, zero external dependencies.
343
+ */
344
+ declare function createNonceManager(params?: CreateNonceManagerParams): NonceManager;
345
+ /** Resolve the next nonce via the client's nonce manager, falling back to a confirmed read. */
346
+ declare function resolveNonce(client: Client, address: string): Promise<bigint>;
347
+ /** True when a broadcast was rejected for a nonce conflict (`ConflictingNonceInMempool`, `BadNonce`). */
348
+ declare function isNonceConflictError(error: unknown): boolean;
349
+ /**
350
+ * Broadcast a signed transaction; on a nonce-conflict rejection, reset the
351
+ * manager so the next build re-syncs to the confirmed floor.
352
+ */
353
+ declare function broadcastWithNonceReset(client: Client, params: {
354
+ transaction: StacksTransaction
355
+ address: string
356
+ }): Promise<string>;
357
+ /** Full chain descriptor used by clients and transports for network-aware operations. */
358
+ type StacksChain = {
359
+ /** Chain ID (e.g. 0x00000001 for mainnet) */
360
+ id: number
361
+ /** Human-readable name */
362
+ name: string
363
+ /** Network type */
364
+ network: "mainnet" | "testnet"
365
+ /** Transaction version byte for serialization */
366
+ transactionVersion: number
367
+ /** Peer network ID for P2P broadcasting */
368
+ peerNetworkId: number
369
+ /** Address version bytes */
370
+ addressVersion: {
371
+ singleSig: number
372
+ multiSig: number
373
+ }
374
+ /** Magic bytes for network identification */
375
+ magicBytes: string
376
+ /** Boot address (system contracts deployer) */
377
+ bootAddress: string
378
+ /** Native currency info */
379
+ nativeCurrency: {
380
+ name: string
381
+ symbol: string
382
+ decimals: number
383
+ }
384
+ /** Default RPC URLs */
385
+ rpcUrls: {
386
+ default: {
387
+ http: string[]
388
+ ws?: string[]
389
+ }
390
+ }
391
+ /** Block explorer URLs */
392
+ blockExplorers?: {
393
+ default: {
394
+ name: string
395
+ url: string
396
+ }
397
+ }
398
+ };
399
+ /** Function that sends an HTTP request to a Stacks node API path. */
400
+ type RequestFn = (path: string, options?: RequestOptions) => Promise<any>;
401
+ /** Options for a transport-level HTTP request. */
402
+ type RequestOptions = {
403
+ method?: "GET" | "POST" | "PUT" | "DELETE"
404
+ body?: unknown
405
+ headers?: Record<string, string>
406
+ };
407
+ /** Shared configuration for all transport types. */
408
+ type TransportConfig = {
409
+ url?: string
410
+ timeout?: number
411
+ retryCount?: number
412
+ retryDelay?: number
413
+ fetchOptions?: RequestInit
414
+ apiKey?: string
415
+ };
416
+ /** A resolved transport instance with a bound request function. */
417
+ type Transport = {
418
+ type: string
419
+ request: RequestFn
420
+ config: TransportConfig
421
+ destroy?: () => void
422
+ };
423
+ /** Factory that creates a {@link Transport} given an optional chain context. */
424
+ type TransportFactory = (params?: {
425
+ chain?: StacksChain
426
+ }) => Transport;
427
+ /** Union of all supported account types (local key, custom signer, or browser provider). */
428
+ type Account = LocalAccount | CustomAccount | ProviderAccount;
429
+ /**
430
+ * Core client instance that holds chain context, transport, and extensible actions.
431
+ * Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}.
432
+ */
433
+ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>> = {
434
+ chain?: StacksChain
435
+ account?: Account
436
+ transport: Transport
437
+ request: RequestFn
438
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
439
+ nonceManager?: NonceManager
440
+ extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
441
+ } & TExtended;
442
+ /** Configuration for creating a base {@link Client}. */
443
+ type ClientConfig = {
444
+ chain?: StacksChain
445
+ transport: TransportFactory
446
+ account?: Account
447
+ /** Optional nonce manager threaded onto the client (see {@link createNonceManager}). */
448
+ nonceManager?: NonceManager
449
+ };
450
+ /** A client pre-extended with read-only {@link PublicActions}. */
451
+ type PublicClient<TExtended extends Record<string, unknown> = Record<string, unknown>> = Client<TExtended>;
452
+ /** A client pre-extended with {@link WalletActions} and a required account. */
453
+ type WalletClient<TExtended extends Record<string, unknown> = Record<string, unknown>> = Client<TExtended> & {
454
+ account: Account
455
+ };
456
+ /**
457
+ * Create a base client with transport and optional chain/account.
458
+ * Use `.extend()` to compose action decorators (public, wallet, multisig).
459
+ */
460
+ declare function createClient<TExtended extends Record<string, unknown> = Record<string, unknown>>(config: ClientConfig): Client<TExtended>;
380
461
  type EstimateFeeParams = {
381
462
  transaction: StacksTransaction
382
463
  };
@@ -812,6 +893,52 @@ type MultiSigClient = Client<MultiSigActions> & MultiSigActions;
812
893
  */
813
894
  declare function createMultiSigClient(config: MultiSigClientConfig): MultiSigClient;
814
895
  /**
896
+ * Persisted {@link NonceStore} adapters for multi-process / multi-builder
897
+ * deployments (the smart-wallet-as-a-service case).
898
+ *
899
+ * The in-memory {@link memoryStore} is correct only within one process: two
900
+ * workers sharing a signing key both read the same confirmed floor and collide.
901
+ * These adapters move the atomic reserve into a shared datastore — Redis `INCR`
902
+ * inside an `EVAL`, or a single Postgres upsert under a row lock — so the store
903
+ * itself becomes the cross-process lock and the durable source of truth.
904
+ *
905
+ * Both are dependency-injected: pass your own `Bun.redis` / `Bun.sql` client.
906
+ * No global `Bun` reference, so importing this module is runtime-agnostic.
907
+ */
908
+ /** Minimal structural shape of a `Bun.redis` client (the `send` escape hatch). */
909
+ type RedisLike = {
910
+ send(command: string, args: string[]): Promise<unknown>
911
+ };
912
+ type RedisStoreParams = {
913
+ redis: RedisLike
914
+ /** Key prefix for stored nonce counters. Default `"stacks:nonce:"`. */
915
+ prefix?: string
916
+ };
917
+ /**
918
+ * Redis-backed nonce store. The atomic reserve lives in a Lua `EVAL`, so it is
919
+ * safe across processes sharing one Redis. The confirmed floor (`getFloor`) is
920
+ * read only once per key, on cold start.
921
+ */
922
+ declare function redisStore(params: RedisStoreParams): NonceStore;
923
+ /** Minimal structural shape of a `Bun.sql` tagged-template client. */
924
+ type SqlLike = (strings: TemplateStringsArray, ...values: unknown[]) => Promise<Array<Record<string, unknown>>>;
925
+ type PostgresStoreParams = {
926
+ sql: SqlLike
927
+ /**
928
+ * Run `CREATE TABLE IF NOT EXISTS stacks_nonce_state` lazily on first use.
929
+ * Default `true`. Set `false` if you manage the schema via migrations.
930
+ */
931
+ ensureTable?: boolean
932
+ };
933
+ /**
934
+ * Postgres-backed nonce store. Each reserve is a single atomic statement under
935
+ * a row lock, so concurrent reservers on the same key serialize and never
936
+ * collide across processes. State is durable — survives restarts.
937
+ *
938
+ * Uses a fixed table `stacks_nonce_state (key text primary key, next numeric)`.
939
+ */
940
+ declare function postgresStore(params: PostgresStoreParams): NonceStore;
941
+ /**
815
942
  * Create an HTTP transport for Stacks node RPC calls.
816
943
  * Falls back to the chain's default RPC URL, then `localhost:3999`.
817
944
  */
@@ -1069,4 +1196,4 @@ declare class ReadOnlyCallError extends BaseError {
1069
1196
  declare class WebSocketError extends BaseError {
1070
1197
  name: string;
1071
1198
  }
1072
- export { webSocket, walletActions, testnet, publicActions, providerToAccount, parseStx, exports_on as on, multisigActions, mocknet, mainnet, isValidAddress, isAddressEqual, http, getContractAddress, formatStx, fallback, devnet, defineChain, custom, createWalletClient, createPublicClient, createMultiSigClient, createClient, ZERO_ADDRESS, WebSocketTransportConfig, WebSocketTransport, WebSocketError, WalletClientConfig, WalletClient, WalletActions, TransportFactory, TransportConfig, Transport, TransactionError, TESTNET_ZERO_ADDRESS, SubscriptionFilterSpec, Subscription, StacksProvider, StacksChain, SimulationError, SigningError, SerializationError, RequestOptions, RequestFn, ReadOnlyCallError, PublicClientConfig, PublicClient, PublicActions, ProviderAccount, PoxFunction, MultiSigClientConfig, MultiSigClient, MultiSigActions, MICROSTX_PER_STX, LocalAccount, FilterPrimitive, FilterOperator, FilterClause, Filter, FactoryTarget, CustomAccount, ContractCallError, ClientConfig, Client, BroadcastError, BnsAction, BaseError, AddressVersion, Account };
1199
+ export { webSocket, walletActions, testnet, resolveNonce, redisStore, publicActions, providerToAccount, postgresStore, parseStx, exports_on as on, multisigActions, mocknet, memoryStore, mainnet, jsonRpcSource, isValidAddress, isNonceConflictError, isAddressEqual, http, getContractAddress, formatStx, fallback, devnet, defineChain, custom, createWalletClient, createPublicClient, createNonceManager, createMultiSigClient, createClient, broadcastWithNonceReset, ZERO_ADDRESS, WebSocketTransportConfig, WebSocketTransport, WebSocketError, WalletClientConfig, WalletClient, WalletActions, TransportFactory, TransportConfig, Transport, TransactionError, TESTNET_ZERO_ADDRESS, SubscriptionFilterSpec, Subscription, StacksProvider, StacksChain, SqlLike, SimulationError, SigningError, SerializationError, RequestOptions, RequestFn, RedisStoreParams, RedisLike, ReadOnlyCallError, PublicClientConfig, PublicClient, PublicActions, ProviderAccount, PoxFunction, PostgresStoreParams, NonceStore, NonceManagerSource, NonceManager, MultiSigClientConfig, MultiSigClient, MultiSigActions, MICROSTX_PER_STX, LocalAccount, FilterPrimitive, FilterOperator, FilterClause, Filter, FactoryTarget, CustomAccount, CreateNonceManagerParams, ContractCallError, ClientConfig, Client, BroadcastError, BnsAction, BaseError, AddressVersion, Account };
package/dist/src/index.js CHANGED
@@ -22,12 +22,12 @@ import {
22
22
  simulateCall,
23
23
  simulateTransaction,
24
24
  transferStx
25
- } from "../shared/stacks-5th5dffx.js";
25
+ } from "../shared/stacks-yb8xesdm.js";
26
26
  import {
27
27
  callContract,
28
28
  getMapEntry,
29
29
  readContract
30
- } from "../shared/stacks-yq5a5cda.js";
30
+ } from "../shared/stacks-a9cn5ehj.js";
31
31
  import {
32
32
  WebSocketError,
33
33
  watchAddress,
@@ -39,16 +39,22 @@ import {
39
39
  } from "../shared/stacks-tjjnkt3r.js";
40
40
  import {
41
41
  sponsorTransaction
42
- } from "../shared/stacks-4z1jhw6y.js";
42
+ } from "../shared/stacks-ffsv2t3t.js";
43
43
  import {
44
44
  BroadcastError,
45
45
  SerializationError,
46
46
  SigningError,
47
47
  TransactionError,
48
+ broadcastWithNonceReset,
49
+ createNonceManager,
48
50
  estimateFee,
49
51
  getNonce,
52
+ isNonceConflictError,
53
+ jsonRpcSource,
54
+ memoryStore,
55
+ resolveNonce,
50
56
  sendTransaction
51
- } from "../shared/stacks-y8e3gx6w.js";
57
+ } from "../shared/stacks-gxhznn3h.js";
52
58
  import {
53
59
  BaseError
54
60
  } from "../shared/stacks-709tra19.js";
@@ -89,6 +95,7 @@ var BASE_KEYS = new Set([
89
95
  "account",
90
96
  "transport",
91
97
  "request",
98
+ "nonceManager",
92
99
  "extend"
93
100
  ]);
94
101
  function bindExtend(base) {
@@ -111,6 +118,7 @@ function createClient(config) {
111
118
  account: config.account,
112
119
  transport,
113
120
  request: transport.request,
121
+ nonceManager: config.nonceManager,
114
122
  extend: null
115
123
  };
116
124
  client.extend = bindExtend(client);
@@ -167,15 +175,17 @@ function multisigActions(client) {
167
175
  if (!msConfig)
168
176
  throw new Error("multisigActions requires a multi-sig client");
169
177
  const { signers, requiredSignatures, hashMode } = msConfig;
170
- async function resolveNonce(nonce) {
178
+ async function resolveNonce2(nonce) {
171
179
  if (nonce !== undefined)
172
180
  return nonce;
173
181
  const address = makeMultiSigAddress(signers, requiredSignatures, client.chain);
182
+ if (client.nonceManager)
183
+ return client.nonceManager.consume({ client, address });
174
184
  return getNonce(client, { address });
175
185
  }
176
186
  return {
177
187
  async transferStx(params) {
178
- const nonce = await resolveNonce(params.nonce);
188
+ const nonce = await resolveNonce2(params.nonce);
179
189
  const unsigned = buildTokenTransfer({
180
190
  recipient: params.to,
181
191
  amount: params.amount,
@@ -200,7 +210,7 @@ function multisigActions(client) {
200
210
  },
201
211
  async callContract(params) {
202
212
  const [contractAddress, contractName] = parseContractId(params.contract);
203
- const nonce = await resolveNonce(params.nonce);
213
+ const nonce = await resolveNonce2(params.nonce);
204
214
  const unsigned = buildContractCall({
205
215
  contractAddress,
206
216
  contractName,
@@ -225,7 +235,7 @@ function multisigActions(client) {
225
235
  return unsigned;
226
236
  },
227
237
  async deployContract(params) {
228
- const nonce = await resolveNonce(params.nonce);
238
+ const nonce = await resolveNonce2(params.nonce);
229
239
  const unsigned = buildContractDeploy({
230
240
  contractName: params.contractName,
231
241
  codeBody: params.codeBody,
@@ -268,6 +278,68 @@ function createMultiSigClient(config) {
268
278
  };
269
279
  return client.extend(multisigActions);
270
280
  }
281
+ // src/actions/wallet/nonceStores.ts
282
+ var TAKE_IF_PRESENT = `local v = redis.call('GET', KEYS[1])
283
+ if v == false then return false end
284
+ redis.call('INCR', KEYS[1])
285
+ return v`;
286
+ var SEED_OR_TAKE = `local v = redis.call('GET', KEYS[1])
287
+ if v == false then redis.call('SET', KEYS[1], ARGV[1]); v = ARGV[1] end
288
+ redis.call('INCR', KEYS[1])
289
+ return v`;
290
+ function redisStore(params) {
291
+ const { redis } = params;
292
+ const prefix = params.prefix ?? "stacks:nonce:";
293
+ return {
294
+ async reserve(key, getFloor) {
295
+ const k = prefix + key;
296
+ const present = await redis.send("EVAL", [TAKE_IF_PRESENT, "1", k]);
297
+ if (present != null)
298
+ return BigInt(present);
299
+ const floor = await getFloor();
300
+ const seeded = await redis.send("EVAL", [
301
+ SEED_OR_TAKE,
302
+ "1",
303
+ k,
304
+ floor.toString()
305
+ ]);
306
+ return BigInt(seeded);
307
+ },
308
+ async reset(key) {
309
+ await redis.send("DEL", [prefix + key]);
310
+ }
311
+ };
312
+ }
313
+ function postgresStore(params) {
314
+ const { sql } = params;
315
+ const shouldEnsure = params.ensureTable ?? true;
316
+ let ensured = false;
317
+ async function ensureTable() {
318
+ if (!shouldEnsure || ensured)
319
+ return;
320
+ await sql`CREATE TABLE IF NOT EXISTS stacks_nonce_state (key text PRIMARY KEY, next numeric NOT NULL)`;
321
+ ensured = true;
322
+ }
323
+ return {
324
+ async reserve(key, getFloor) {
325
+ await ensureTable();
326
+ const updated = await sql`UPDATE stacks_nonce_state SET next = next + 1 WHERE key = ${key} RETURNING next - 1 AS nonce`;
327
+ const warm = updated[0];
328
+ if (warm)
329
+ return BigInt(String(warm.nonce));
330
+ const floor = await getFloor();
331
+ const seeded = await sql`INSERT INTO stacks_nonce_state (key, next) VALUES (${key}, ${(floor + 1n).toString()}) ON CONFLICT (key) DO UPDATE SET next = stacks_nonce_state.next + 1 RETURNING next - 1 AS nonce`;
332
+ const cold = seeded[0];
333
+ if (!cold)
334
+ throw new Error("postgresStore: insert returned no row");
335
+ return BigInt(String(cold.nonce));
336
+ },
337
+ async reset(key) {
338
+ await ensureTable();
339
+ await sql`DELETE FROM stacks_nonce_state WHERE key = ${key}`;
340
+ }
341
+ };
342
+ }
271
343
  // src/transports/createTransport.ts
272
344
  function createTransport(type, config) {
273
345
  return {
@@ -689,14 +761,20 @@ export {
689
761
  webSocket,
690
762
  walletActions,
691
763
  testnet,
764
+ resolveNonce,
765
+ redisStore,
692
766
  publicActions,
693
767
  providerToAccount,
768
+ postgresStore,
694
769
  parseStx,
695
770
  exports_on as on,
696
771
  multisigActions,
697
772
  mocknet,
773
+ memoryStore,
698
774
  mainnet,
775
+ jsonRpcSource,
699
776
  isValidAddress,
777
+ isNonceConflictError,
700
778
  isAddressEqual,
701
779
  http,
702
780
  getContractAddress,
@@ -707,8 +785,10 @@ export {
707
785
  custom,
708
786
  createWalletClient,
709
787
  createPublicClient,
788
+ createNonceManager,
710
789
  createMultiSigClient,
711
790
  createClient,
791
+ broadcastWithNonceReset,
712
792
  ZERO_ADDRESS,
713
793
  WebSocketError,
714
794
  TransactionError,
@@ -724,5 +804,5 @@ export {
724
804
  AddressVersion
725
805
  };
726
806
 
727
- //# debugId=8C2A991E317B310264756E2164756E21
807
+ //# debugId=AD2076118DA65BC464756E2164756E21
728
808
  //# sourceMappingURL=index.js.map