@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,109 +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
- /** Union of all supported account types (local key, custom signer, or browser provider). */
97
- type Account = LocalAccount | CustomAccount | ProviderAccount;
98
- /**
99
- * Core client instance that holds chain context, transport, and extensible actions.
100
- * Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}.
101
- */
102
- type Client<TExtended extends Record<string, unknown> = Record<string, unknown>> = {
103
- chain?: StacksChain
104
- account?: Account
105
- transport: Transport
106
- request: RequestFn
107
- extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
108
- } & TExtended;
109
- type GetNonceParams = {
110
- address: string
111
- };
112
- declare function getNonce(client: Client, params: GetNonceParams): Promise<bigint>;
113
- type GetBalanceParams = {
114
- address: string
115
- };
116
- declare function getBalance(client: Client, params: GetBalanceParams): Promise<bigint>;
117
- type GetAccountInfoParams = {
118
- address: string
119
- };
120
- type AccountInfo = {
121
- balance: bigint
122
- nonce: bigint
123
- balanceProof: string
124
- nonceProof: string
125
- };
126
- declare function getAccountInfo(client: Client, params: GetAccountInfoParams): Promise<AccountInfo>;
127
- type GetBlockParams = {
128
- height?: number
129
- hash?: string
130
- };
131
- declare function getBlock(client: Client, params?: GetBlockParams): Promise<any>;
132
- declare function getBlockHeight(client: Client): Promise<number>;
133
30
  type IntCV = {
134
31
  readonly type: "int"
135
32
  readonly value: bigint
@@ -192,23 +89,6 @@ type StringUtf8CV = {
192
89
  readonly value: string
193
90
  };
194
91
  type ClarityValue = IntCV | UIntCV | BooleanCV | BufferCV | NoneCV | SomeCV | ResponseOkCV | ResponseErrorCV | StandardPrincipalCV | ContractPrincipalCV | ListCV | TupleCV | StringAsciiCV | StringUtf8CV;
195
- type ReadContractParams = {
196
- contract: string
197
- functionName: string
198
- args?: ClarityValue[]
199
- sender?: string
200
- };
201
- declare function readContract<T extends ClarityValue = ClarityValue>(client: Client, params: ReadContractParams): Promise<T>;
202
- type GetContractAbiParams = {
203
- contract: string
204
- };
205
- declare function getContractAbi(client: Client, params: GetContractAbiParams): Promise<any>;
206
- type GetMapEntryParams = {
207
- contract: string
208
- mapName: string
209
- key: ClarityValue
210
- };
211
- declare function getMapEntry<T extends ClarityValue = ClarityValue>(client: Client, params: GetMapEntryParams): Promise<T>;
212
92
  declare const AuthType: {
213
93
  readonly Standard: 0x04
214
94
  readonly Sponsored: 0x05
@@ -397,6 +277,139 @@ type AssetInfoWire = {
397
277
  contractName: string
398
278
  assetName: string
399
279
  };
280
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
281
+ type NonceManager = {
282
+ consume(params: {
283
+ client: Client
284
+ address: string
285
+ }): Promise<bigint>
286
+ reset(params: {
287
+ client: Client
288
+ address: string
289
+ }): void | Promise<void>
290
+ };
291
+ /** Full chain descriptor used by clients and transports for network-aware operations. */
292
+ type StacksChain = {
293
+ /** Chain ID (e.g. 0x00000001 for mainnet) */
294
+ id: number
295
+ /** Human-readable name */
296
+ name: string
297
+ /** Network type */
298
+ network: "mainnet" | "testnet"
299
+ /** Transaction version byte for serialization */
300
+ transactionVersion: number
301
+ /** Peer network ID for P2P broadcasting */
302
+ peerNetworkId: number
303
+ /** Address version bytes */
304
+ addressVersion: {
305
+ singleSig: number
306
+ multiSig: number
307
+ }
308
+ /** Magic bytes for network identification */
309
+ magicBytes: string
310
+ /** Boot address (system contracts deployer) */
311
+ bootAddress: string
312
+ /** Native currency info */
313
+ nativeCurrency: {
314
+ name: string
315
+ symbol: string
316
+ decimals: number
317
+ }
318
+ /** Default RPC URLs */
319
+ rpcUrls: {
320
+ default: {
321
+ http: string[]
322
+ ws?: string[]
323
+ }
324
+ }
325
+ /** Block explorer URLs */
326
+ blockExplorers?: {
327
+ default: {
328
+ name: string
329
+ url: string
330
+ }
331
+ }
332
+ };
333
+ /** Function that sends an HTTP request to a Stacks node API path. */
334
+ type RequestFn = (path: string, options?: RequestOptions) => Promise<any>;
335
+ /** Options for a transport-level HTTP request. */
336
+ type RequestOptions = {
337
+ method?: "GET" | "POST" | "PUT" | "DELETE"
338
+ body?: unknown
339
+ headers?: Record<string, string>
340
+ };
341
+ /** Shared configuration for all transport types. */
342
+ type TransportConfig = {
343
+ url?: string
344
+ timeout?: number
345
+ retryCount?: number
346
+ retryDelay?: number
347
+ fetchOptions?: RequestInit
348
+ apiKey?: string
349
+ };
350
+ /** A resolved transport instance with a bound request function. */
351
+ type Transport = {
352
+ type: string
353
+ request: RequestFn
354
+ config: TransportConfig
355
+ destroy?: () => void
356
+ };
357
+ /** Union of all supported account types (local key, custom signer, or browser provider). */
358
+ type Account = LocalAccount | CustomAccount | ProviderAccount;
359
+ /**
360
+ * Core client instance that holds chain context, transport, and extensible actions.
361
+ * Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}.
362
+ */
363
+ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>> = {
364
+ chain?: StacksChain
365
+ account?: Account
366
+ transport: Transport
367
+ request: RequestFn
368
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
369
+ nonceManager?: NonceManager
370
+ extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
371
+ } & TExtended;
372
+ type GetNonceParams = {
373
+ address: string
374
+ };
375
+ declare function getNonce(client: Client, params: GetNonceParams): Promise<bigint>;
376
+ type GetBalanceParams = {
377
+ address: string
378
+ };
379
+ declare function getBalance(client: Client, params: GetBalanceParams): Promise<bigint>;
380
+ type GetAccountInfoParams = {
381
+ address: string
382
+ };
383
+ type AccountInfo = {
384
+ balance: bigint
385
+ nonce: bigint
386
+ balanceProof: string
387
+ nonceProof: string
388
+ };
389
+ declare function getAccountInfo(client: Client, params: GetAccountInfoParams): Promise<AccountInfo>;
390
+ type GetBlockParams = {
391
+ height?: number
392
+ hash?: string
393
+ };
394
+ declare function getBlock(client: Client, params?: GetBlockParams): Promise<any>;
395
+ declare function getBlockHeight(client: Client): Promise<number>;
396
+ type ReadContractParams = {
397
+ contract: string
398
+ functionName: string
399
+ args?: ClarityValue[]
400
+ sender?: string
401
+ };
402
+ declare function readContract<T extends ClarityValue = ClarityValue>(client: Client, params: ReadContractParams): Promise<T>;
403
+ type GetContractAbiParams = {
404
+ contract: string
405
+ };
406
+ declare function getContractAbi(client: Client, params: GetContractAbiParams): Promise<any>;
407
+ type GetMapEntryParams = {
408
+ contract: string
409
+ mapName: string
410
+ key: ClarityValue
411
+ };
412
+ declare function getMapEntry<T extends ClarityValue = ClarityValue>(client: Client, params: GetMapEntryParams): Promise<T>;
400
413
  type EstimateFeeParams = {
401
414
  transaction: StacksTransaction
402
415
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ContractResponseError,
3
3
  getContract
4
- } from "../../shared/stacks-hyz7zgdk.js";
4
+ } from "../../shared/stacks-hr5rg2et.js";
5
5
  import {
6
6
  deployContract,
7
7
  getAccountInfo,
@@ -15,12 +15,12 @@ import {
15
15
  simulateCall,
16
16
  simulateTransaction,
17
17
  transferStx
18
- } from "../../shared/stacks-5th5dffx.js";
18
+ } from "../../shared/stacks-yb8xesdm.js";
19
19
  import {
20
20
  callContract,
21
21
  getMapEntry,
22
22
  readContract
23
- } from "../../shared/stacks-yq5a5cda.js";
23
+ } from "../../shared/stacks-a9cn5ehj.js";
24
24
  import {
25
25
  watchAddress,
26
26
  watchAddressBalance,
@@ -31,13 +31,13 @@ import {
31
31
  } from "../../shared/stacks-tjjnkt3r.js";
32
32
  import {
33
33
  sponsorTransaction
34
- } from "../../shared/stacks-4z1jhw6y.js";
34
+ } from "../../shared/stacks-ffsv2t3t.js";
35
35
  import {
36
36
  estimateFee,
37
37
  getNonce,
38
38
  isProviderAccount,
39
39
  sendTransaction
40
- } from "../../shared/stacks-y8e3gx6w.js";
40
+ } from "../../shared/stacks-gxhznn3h.js";
41
41
  import"../../shared/stacks-709tra19.js";
42
42
  import"../../shared/stacks-g7ffp8aj.js";
43
43
  import"../../shared/stacks-wqgepfab.js";
@@ -27,6 +27,17 @@ type ProviderAccount = {
27
27
  publicKey: string
28
28
  provider: StacksProvider
29
29
  };
30
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
31
+ type NonceManager = {
32
+ consume(params: {
33
+ client: Client
34
+ address: string
35
+ }): Promise<bigint>
36
+ reset(params: {
37
+ client: Client
38
+ address: string
39
+ }): void | Promise<void>
40
+ };
30
41
  /** Full chain descriptor used by clients and transports for network-aware operations. */
31
42
  type StacksChain = {
32
43
  /** Chain ID (e.g. 0x00000001 for mainnet) */
@@ -104,6 +115,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
104
115
  account?: Account
105
116
  transport: Transport
106
117
  request: RequestFn
118
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
119
+ nonceManager?: NonceManager
107
120
  extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
108
121
  } & TExtended;
109
122
  interface FullyQualifiedName {
@@ -27,6 +27,17 @@ type ProviderAccount = {
27
27
  publicKey: string
28
28
  provider: StacksProvider
29
29
  };
30
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
31
+ type NonceManager = {
32
+ consume(params: {
33
+ client: Client
34
+ address: string
35
+ }): Promise<bigint>
36
+ reset(params: {
37
+ client: Client
38
+ address: string
39
+ }): void | Promise<void>
40
+ };
30
41
  /** Full chain descriptor used by clients and transports for network-aware operations. */
31
42
  type StacksChain = {
32
43
  /** Chain ID (e.g. 0x00000001 for mainnet) */
@@ -104,6 +115,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
104
115
  account?: Account
105
116
  transport: Transport
106
117
  request: RequestFn
118
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
119
+ nonceManager?: NonceManager
107
120
  extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
108
121
  } & TExtended;
109
122
  interface FullyQualifiedName {
@@ -3,9 +3,9 @@ import"../../shared/stacks-kg1npstf.js";
3
3
  import {
4
4
  ContractResponseError,
5
5
  getContract
6
- } from "../../shared/stacks-hyz7zgdk.js";
7
- import"../../shared/stacks-yq5a5cda.js";
8
- import"../../shared/stacks-y8e3gx6w.js";
6
+ } from "../../shared/stacks-hr5rg2et.js";
7
+ import"../../shared/stacks-a9cn5ehj.js";
8
+ import"../../shared/stacks-gxhznn3h.js";
9
9
  import"../../shared/stacks-709tra19.js";
10
10
  import"../../shared/stacks-g7ffp8aj.js";
11
11
  import"../../shared/stacks-z53fwfcm.js";
@@ -4,14 +4,20 @@ __export(exports_src, {
4
4
  webSocket: () => webSocket,
5
5
  walletActions: () => walletActions,
6
6
  testnet: () => testnet,
7
+ resolveNonce: () => resolveNonce,
8
+ redisStore: () => redisStore,
7
9
  publicActions: () => publicActions,
8
10
  providerToAccount: () => providerToAccount,
11
+ postgresStore: () => postgresStore,
9
12
  parseStx: () => parseStx,
10
13
  on: () => exports_on,
11
14
  multisigActions: () => multisigActions,
12
15
  mocknet: () => mocknet,
16
+ memoryStore: () => memoryStore,
13
17
  mainnet: () => mainnet,
18
+ jsonRpcSource: () => jsonRpcSource,
14
19
  isValidAddress: () => isValidAddress,
20
+ isNonceConflictError: () => isNonceConflictError,
15
21
  isAddressEqual: () => isAddressEqual,
16
22
  http: () => http,
17
23
  getContractAddress: () => getContractAddress,
@@ -22,8 +28,10 @@ __export(exports_src, {
22
28
  custom: () => custom,
23
29
  createWalletClient: () => createWalletClient,
24
30
  createPublicClient: () => createPublicClient,
31
+ createNonceManager: () => createNonceManager,
25
32
  createMultiSigClient: () => createMultiSigClient,
26
33
  createClient: () => createClient,
34
+ broadcastWithNonceReset: () => broadcastWithNonceReset,
27
35
  ZERO_ADDRESS: () => ZERO_ADDRESS,
28
36
  WebSocketError: () => WebSocketError,
29
37
  TransactionError: () => TransactionError,
@@ -46,6 +54,7 @@ var BASE_KEYS = new Set([
46
54
  "account",
47
55
  "transport",
48
56
  "request",
57
+ "nonceManager",
49
58
  "extend"
50
59
  ]);
51
60
  function bindExtend(base) {
@@ -68,6 +77,7 @@ function createClient(config) {
68
77
  account: config.account,
69
78
  transport,
70
79
  request: transport.request,
80
+ nonceManager: config.nonceManager,
71
81
  extend: null
72
82
  };
73
83
  client.extend = bindExtend(client);
@@ -124,15 +134,17 @@ function multisigActions(client) {
124
134
  if (!msConfig)
125
135
  throw new Error("multisigActions requires a multi-sig client");
126
136
  const { signers, requiredSignatures, hashMode } = msConfig;
127
- async function resolveNonce(nonce) {
137
+ async function resolveNonce2(nonce) {
128
138
  if (nonce !== undefined)
129
139
  return nonce;
130
140
  const address = makeMultiSigAddress(signers, requiredSignatures, client.chain);
141
+ if (client.nonceManager)
142
+ return client.nonceManager.consume({ client, address });
131
143
  return getNonce(client, { address });
132
144
  }
133
145
  return {
134
146
  async transferStx(params) {
135
- const nonce = await resolveNonce(params.nonce);
147
+ const nonce = await resolveNonce2(params.nonce);
136
148
  const unsigned = buildTokenTransfer({
137
149
  recipient: params.to,
138
150
  amount: params.amount,
@@ -157,7 +169,7 @@ function multisigActions(client) {
157
169
  },
158
170
  async callContract(params) {
159
171
  const [contractAddress, contractName] = parseContractId(params.contract);
160
- const nonce = await resolveNonce(params.nonce);
172
+ const nonce = await resolveNonce2(params.nonce);
161
173
  const unsigned = buildContractCall({
162
174
  contractAddress,
163
175
  contractName,
@@ -182,7 +194,7 @@ function multisigActions(client) {
182
194
  return unsigned;
183
195
  },
184
196
  async deployContract(params) {
185
- const nonce = await resolveNonce(params.nonce);
197
+ const nonce = await resolveNonce2(params.nonce);
186
198
  const unsigned = buildContractDeploy({
187
199
  contractName: params.contractName,
188
200
  codeBody: params.codeBody,
@@ -225,6 +237,68 @@ function createMultiSigClient(config) {
225
237
  };
226
238
  return client.extend(multisigActions);
227
239
  }
240
+ // src/actions/wallet/nonceStores.ts
241
+ var TAKE_IF_PRESENT = `local v = redis.call('GET', KEYS[1])
242
+ if v == false then return false end
243
+ redis.call('INCR', KEYS[1])
244
+ return v`;
245
+ var SEED_OR_TAKE = `local v = redis.call('GET', KEYS[1])
246
+ if v == false then redis.call('SET', KEYS[1], ARGV[1]); v = ARGV[1] end
247
+ redis.call('INCR', KEYS[1])
248
+ return v`;
249
+ function redisStore(params) {
250
+ const { redis } = params;
251
+ const prefix = params.prefix ?? "stacks:nonce:";
252
+ return {
253
+ async reserve(key, getFloor) {
254
+ const k = prefix + key;
255
+ const present = await redis.send("EVAL", [TAKE_IF_PRESENT, "1", k]);
256
+ if (present != null)
257
+ return BigInt(present);
258
+ const floor = await getFloor();
259
+ const seeded = await redis.send("EVAL", [
260
+ SEED_OR_TAKE,
261
+ "1",
262
+ k,
263
+ floor.toString()
264
+ ]);
265
+ return BigInt(seeded);
266
+ },
267
+ async reset(key) {
268
+ await redis.send("DEL", [prefix + key]);
269
+ }
270
+ };
271
+ }
272
+ function postgresStore(params) {
273
+ const { sql } = params;
274
+ const shouldEnsure = params.ensureTable ?? true;
275
+ let ensured = false;
276
+ async function ensureTable() {
277
+ if (!shouldEnsure || ensured)
278
+ return;
279
+ await sql`CREATE TABLE IF NOT EXISTS stacks_nonce_state (key text PRIMARY KEY, next numeric NOT NULL)`;
280
+ ensured = true;
281
+ }
282
+ return {
283
+ async reserve(key, getFloor) {
284
+ await ensureTable();
285
+ const updated = await sql`UPDATE stacks_nonce_state SET next = next + 1 WHERE key = ${key} RETURNING next - 1 AS nonce`;
286
+ const warm = updated[0];
287
+ if (warm)
288
+ return BigInt(String(warm.nonce));
289
+ const floor = await getFloor();
290
+ 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`;
291
+ const cold = seeded[0];
292
+ if (!cold)
293
+ throw new Error("postgresStore: insert returned no row");
294
+ return BigInt(String(cold.nonce));
295
+ },
296
+ async reset(key) {
297
+ await ensureTable();
298
+ await sql`DELETE FROM stacks_nonce_state WHERE key = ${key}`;
299
+ }
300
+ };
301
+ }
228
302
  // src/transports/createTransport.ts
229
303
  function createTransport(type, config) {
230
304
  return {
@@ -643,5 +717,5 @@ class ReadOnlyCallError extends BaseError {
643
717
  name = "ReadOnlyCallError";
644
718
  }
645
719
 
646
- //# debugId=53C2882DD528F5DF64756E2164756E21
720
+ //# debugId=6ED05F818443D6E764756E2164756E21
647
721
  //# sourceMappingURL=index.cjs.map