@secondlayer/stacks 3.3.0 → 4.0.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 (65) hide show
  1. package/dist/shared/{stacks-6bgh2c9h.js → stacks-27fmgajb.js} +11 -3
  2. package/dist/shared/{stacks-b221qkst.cjs.map → stacks-27fmgajb.js.map} +4 -3
  3. package/dist/shared/{stacks-jknrzd6v.js → stacks-2evvn48s.js} +2 -2
  4. package/dist/shared/{stacks-s361pmzs.cjs → stacks-90jcxs98.js} +84 -2
  5. package/dist/shared/{stacks-9d2d0qjc.js.map → stacks-90jcxs98.js.map} +6 -4
  6. package/dist/shared/{stacks-8e5atbps.cjs → stacks-dr5en54r.cjs} +9 -2
  7. package/dist/shared/{stacks-8e5atbps.cjs.map → stacks-dr5en54r.cjs.map} +2 -2
  8. package/dist/shared/{stacks-bm49tsh0.js → stacks-fse1f76h.js} +2 -3
  9. package/dist/shared/{stacks-bm49tsh0.js.map → stacks-fse1f76h.js.map} +1 -1
  10. package/dist/shared/{stacks-b221qkst.cjs → stacks-nyaw1z2a.cjs} +7 -2
  11. package/dist/shared/{stacks-6bgh2c9h.js.map → stacks-nyaw1z2a.cjs.map} +4 -3
  12. package/dist/shared/{stacks-9d2d0qjc.js → stacks-tdsp5gsb.cjs} +54 -23
  13. package/dist/shared/{stacks-s361pmzs.cjs.map → stacks-tdsp5gsb.cjs.map} +6 -4
  14. package/dist/shared/{stacks-r1m1r72q.js → stacks-thkhfwz8.js} +35 -5
  15. package/dist/shared/{stacks-r1m1r72q.js.map → stacks-thkhfwz8.js.map} +4 -3
  16. package/dist/shared/{stacks-v1hzk599.js → stacks-z3vztaz1.js} +7 -9
  17. package/dist/shared/{stacks-v1hzk599.js.map → stacks-z3vztaz1.js.map} +2 -2
  18. package/dist/shared/{stacks-fvnxj77s.cjs → stacks-zwgsbbb2.cjs} +28 -2
  19. package/dist/shared/{stacks-fvnxj77s.cjs.map → stacks-zwgsbbb2.cjs.map} +4 -3
  20. package/dist/src/actions/index.js +18 -23
  21. package/dist/src/actions/index.js.map +1 -1
  22. package/dist/src/bitcoin/index.js +3 -5
  23. package/dist/src/bitcoin/index.js.map +2 -2
  24. package/dist/src/bns/index.js +5 -8
  25. package/dist/src/bns/index.js.map +2 -2
  26. package/dist/src/index.js +19 -25
  27. package/dist/src/index.js.map +2 -2
  28. package/dist/src/postconditions/index.js +2 -3
  29. package/dist/src/postconditions/index.js.map +1 -1
  30. package/dist/src/pox/index.js +5 -8
  31. package/dist/src/pox/index.js.map +2 -2
  32. package/dist/src/pox5/index.js +5 -7
  33. package/dist/src/pox5/index.js.map +2 -2
  34. package/dist/src/sbtc/index.cjs +2 -2
  35. package/dist/src/sbtc/index.cjs.map +3 -3
  36. package/dist/src/sbtc/index.d.cts +3 -3
  37. package/dist/src/sbtc/index.d.ts +3 -3
  38. package/dist/src/sbtc/index.js +5 -7
  39. package/dist/src/sbtc/index.js.map +3 -3
  40. package/dist/src/stackingdao/index.js +5 -8
  41. package/dist/src/stackingdao/index.js.map +2 -2
  42. package/package.json +1 -6
  43. package/dist/shared/stacks-1mpmzzyp.js +0 -85
  44. package/dist/shared/stacks-1mpmzzyp.js.map +0 -11
  45. package/dist/shared/stacks-44y18a8e.cjs +0 -28
  46. package/dist/shared/stacks-44y18a8e.cjs.map +0 -10
  47. package/dist/shared/stacks-8khy9v27.cjs +0 -7
  48. package/dist/shared/stacks-8khy9v27.cjs.map +0 -10
  49. package/dist/shared/stacks-d6pgp4qk.cjs +0 -9
  50. package/dist/shared/stacks-d6pgp4qk.cjs.map +0 -9
  51. package/dist/shared/stacks-fh48neva.js +0 -13
  52. package/dist/shared/stacks-fh48neva.js.map +0 -10
  53. package/dist/shared/stacks-fjrpnkt3.cjs +0 -55
  54. package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
  55. package/dist/shared/stacks-w8tt1fmt.js +0 -44
  56. package/dist/shared/stacks-w8tt1fmt.js.map +0 -10
  57. package/dist/shared/stacks-z53fwfcm.js +0 -3
  58. package/dist/shared/stacks-z53fwfcm.js.map +0 -9
  59. package/dist/src/x402/index.cjs +0 -65
  60. package/dist/src/x402/index.cjs.map +0 -11
  61. package/dist/src/x402/index.d.cts +0 -501
  62. package/dist/src/x402/index.d.ts +0 -501
  63. package/dist/src/x402/index.js +0 -90
  64. package/dist/src/x402/index.js.map +0 -11
  65. /package/dist/shared/{stacks-jknrzd6v.js.map → stacks-2evvn48s.js.map} +0 -0
@@ -1,501 +0,0 @@
1
- /** Full chain descriptor used by clients and transports for network-aware operations. */
2
- type StacksChain = {
3
- /** Chain ID (e.g. 0x00000001 for mainnet) */
4
- id: number
5
- /** Human-readable name */
6
- name: string
7
- /** Network type */
8
- network: "mainnet" | "testnet"
9
- /** Transaction version byte for serialization */
10
- transactionVersion: number
11
- /** Peer network ID for P2P broadcasting */
12
- peerNetworkId: number
13
- /** Address version bytes */
14
- addressVersion: {
15
- singleSig: number
16
- multiSig: number
17
- }
18
- /** Magic bytes for network identification */
19
- magicBytes: string
20
- /** Boot address (system contracts deployer) */
21
- bootAddress: string
22
- /** Native currency info */
23
- nativeCurrency: {
24
- name: string
25
- symbol: string
26
- decimals: number
27
- }
28
- /** Default RPC URLs */
29
- rpcUrls: {
30
- default: {
31
- http: string[]
32
- ws?: string[]
33
- }
34
- }
35
- /** Block explorer URLs */
36
- blockExplorers?: {
37
- default: {
38
- name: string
39
- url: string
40
- }
41
- }
42
- };
43
- type IntCV = {
44
- readonly type: "int"
45
- readonly value: bigint
46
- };
47
- type UIntCV = {
48
- readonly type: "uint"
49
- readonly value: bigint
50
- };
51
- type BooleanCV = TrueCV | FalseCV;
52
- type TrueCV = {
53
- readonly type: "true"
54
- };
55
- type FalseCV = {
56
- readonly type: "false"
57
- };
58
- type BufferCV = {
59
- readonly type: "buffer"
60
- readonly value: string
61
- };
62
- type NoneCV = {
63
- readonly type: "none"
64
- };
65
- type SomeCV = {
66
- readonly type: "some"
67
- readonly value: ClarityValue
68
- };
69
- type ResponseOkCV = {
70
- readonly type: "ok"
71
- readonly value: ClarityValue
72
- };
73
- type ResponseErrorCV = {
74
- readonly type: "err"
75
- readonly value: ClarityValue
76
- };
77
- type StandardPrincipalCV = {
78
- readonly type: "address"
79
- readonly value: string
80
- };
81
- type ContractPrincipalCV = {
82
- readonly type: "contract"
83
- readonly value: string
84
- };
85
- type ListCV = {
86
- type: "list"
87
- value: ClarityValue[]
88
- };
89
- type TupleData = {
90
- [key: string]: ClarityValue
91
- };
92
- type TupleCV = {
93
- type: "tuple"
94
- value: TupleData
95
- };
96
- type StringAsciiCV = {
97
- readonly type: "ascii"
98
- readonly value: string
99
- };
100
- type StringUtf8CV = {
101
- readonly type: "utf8"
102
- readonly value: string
103
- };
104
- type ClarityValue = IntCV | UIntCV | BooleanCV | BufferCV | NoneCV | SomeCV | ResponseOkCV | ResponseErrorCV | StandardPrincipalCV | ContractPrincipalCV | ListCV | TupleCV | StringAsciiCV | StringUtf8CV;
105
- declare const AuthType: {
106
- readonly Standard: 0x04
107
- readonly Sponsored: 0x05
108
- };
109
- type AuthType = (typeof AuthType)[keyof typeof AuthType];
110
- declare const PayloadType: {
111
- readonly TokenTransfer: 0x00
112
- readonly SmartContract: 0x01
113
- readonly ContractCall: 0x02
114
- readonly PoisonMicroblock: 0x03
115
- readonly Coinbase: 0x04
116
- readonly CoinbaseToAltRecipient: 0x05
117
- readonly VersionedSmartContract: 0x06
118
- readonly TenureChange: 0x07
119
- readonly NakamotoCoinbase: 0x08
120
- };
121
- type PayloadType = (typeof PayloadType)[keyof typeof PayloadType];
122
- declare const ClarityVersion: {
123
- readonly Clarity1: 1
124
- readonly Clarity2: 2
125
- readonly Clarity3: 3
126
- readonly Clarity4: 4
127
- readonly Clarity5: 5
128
- readonly Clarity6: 6
129
- };
130
- type ClarityVersion = (typeof ClarityVersion)[keyof typeof ClarityVersion];
131
- declare const AnchorMode: {
132
- readonly OnChainOnly: 0x01
133
- readonly OffChainOnly: 0x02
134
- readonly Any: 0x03
135
- };
136
- type AnchorMode = (typeof AnchorMode)[keyof typeof AnchorMode];
137
- declare const PostConditionModeWire: {
138
- readonly Allow: 0x01
139
- readonly Deny: 0x02
140
- };
141
- type PostConditionModeWire = (typeof PostConditionModeWire)[keyof typeof PostConditionModeWire];
142
- declare const AddressHashMode: {
143
- readonly P2PKH: 0x00
144
- readonly P2SH: 0x01
145
- readonly P2WPKH: 0x02
146
- readonly P2WSH: 0x03
147
- readonly P2SH_NonSequential: 0x05
148
- readonly P2WSH_P2SH_NonSequential: 0x07
149
- };
150
- type AddressHashMode = (typeof AddressHashMode)[keyof typeof AddressHashMode];
151
- declare const PubKeyEncoding: {
152
- readonly Compressed: 0x00
153
- readonly Uncompressed: 0x01
154
- };
155
- type PubKeyEncoding = (typeof PubKeyEncoding)[keyof typeof PubKeyEncoding];
156
- declare const PoxConditionCode: {
157
- readonly WillNotPerform: 0x30
158
- readonly MayPerform: 0x31
159
- readonly WillPerform: 0x32
160
- };
161
- type PoxConditionCode = (typeof PoxConditionCode)[keyof typeof PoxConditionCode];
162
- declare const TenureChangeCause: {
163
- readonly BlockFound: 0x00
164
- readonly Extended: 0x01
165
- readonly ExtendedRuntime: 0x02
166
- readonly ExtendedReadCount: 0x03
167
- readonly ExtendedReadLength: 0x04
168
- readonly ExtendedWriteCount: 0x05
169
- readonly ExtendedWriteLength: 0x06
170
- };
171
- type TenureChangeCause = (typeof TenureChangeCause)[keyof typeof TenureChangeCause];
172
- type TokenTransferPayload = {
173
- payloadType: typeof PayloadType.TokenTransfer
174
- recipient: ClarityValue
175
- amount: bigint
176
- memo: string
177
- };
178
- type ContractCallPayload = {
179
- payloadType: typeof PayloadType.ContractCall
180
- contractAddress: string
181
- contractName: string
182
- functionName: string
183
- functionArgs: ClarityValue[]
184
- };
185
- type SmartContractPayload = {
186
- payloadType: typeof PayloadType.SmartContract | typeof PayloadType.VersionedSmartContract
187
- clarityVersion?: ClarityVersion
188
- contractName: string
189
- codeBody: string
190
- };
191
- type CoinbasePayload = {
192
- payloadType: typeof PayloadType.Coinbase
193
- coinbaseBuffer: string
194
- };
195
- type CoinbaseToAltRecipientPayload = {
196
- payloadType: typeof PayloadType.CoinbaseToAltRecipient
197
- coinbaseBuffer: string
198
- recipient: ClarityValue
199
- };
200
- type PoisonMicroblockPayload = {
201
- payloadType: typeof PayloadType.PoisonMicroblock
202
- header1: string
203
- header2: string
204
- };
205
- type TenureChangePayload = {
206
- payloadType: typeof PayloadType.TenureChange
207
- tenureConsensusHash: string
208
- prevTenureConsensusHash: string
209
- burnViewConsensusHash: string
210
- previousTenureEnd: string
211
- previousTenureBlocks: number
212
- cause: TenureChangeCause
213
- pubkeyHash: string
214
- };
215
- type NakamotoCoinbasePayload = {
216
- payloadType: typeof PayloadType.NakamotoCoinbase
217
- coinbaseBuffer: string
218
- recipient: ClarityValue | null
219
- vrfProof: string
220
- };
221
- type TransactionPayload = TokenTransferPayload | ContractCallPayload | SmartContractPayload | CoinbasePayload | CoinbaseToAltRecipientPayload | PoisonMicroblockPayload | TenureChangePayload | NakamotoCoinbasePayload;
222
- type SingleSigSpendingCondition = {
223
- hashMode: typeof AddressHashMode.P2PKH | typeof AddressHashMode.P2WPKH
224
- signer: string
225
- nonce: bigint
226
- fee: bigint
227
- keyEncoding: PubKeyEncoding
228
- signature: string
229
- };
230
- type TransactionAuthField = {
231
- pubKeyEncoding: PubKeyEncoding
232
- type: "publicKey" | "signature"
233
- data: string
234
- };
235
- type MultiSigHashMode = typeof AddressHashMode.P2SH | typeof AddressHashMode.P2WSH | typeof AddressHashMode.P2SH_NonSequential | typeof AddressHashMode.P2WSH_P2SH_NonSequential;
236
- type MultiSigSpendingCondition = {
237
- hashMode: MultiSigHashMode
238
- signer: string
239
- nonce: bigint
240
- fee: bigint
241
- fields: TransactionAuthField[]
242
- signaturesRequired: number
243
- };
244
- type SpendingCondition = SingleSigSpendingCondition | MultiSigSpendingCondition;
245
- type StandardAuthorization = {
246
- authType: typeof AuthType.Standard
247
- spendingCondition: SpendingCondition
248
- };
249
- type SponsoredAuthorization = {
250
- authType: typeof AuthType.Sponsored
251
- spendingCondition: SpendingCondition
252
- sponsorSpendingCondition: SpendingCondition
253
- };
254
- type Authorization = StandardAuthorization | SponsoredAuthorization;
255
- type StacksTransaction = {
256
- version: number
257
- chainId: number
258
- auth: Authorization
259
- anchorMode: AnchorMode
260
- postConditionMode: PostConditionModeWire
261
- postConditions: PostConditionWire[]
262
- payload: TransactionPayload
263
- /** Multi-sig signer metadata — not part of the wire format, preserved
264
- * through serialize/deserialize round-trip for auto-detection. */
265
- _multisig?: {
266
- publicKeys: string[]
267
- }
268
- };
269
- type PostConditionWire = StxPostConditionWire | FtPostConditionWire | NftPostConditionWire | StakingPostConditionWire | PoxPostConditionWire;
270
- type StxPostConditionWire = {
271
- type: "stx"
272
- principal: PostConditionPrincipalWire
273
- conditionCode: number
274
- amount: bigint
275
- };
276
- type FtPostConditionWire = {
277
- type: "ft"
278
- principal: PostConditionPrincipalWire
279
- asset: AssetInfoWire
280
- conditionCode: number
281
- amount: bigint
282
- };
283
- type NftPostConditionWire = {
284
- type: "nft"
285
- principal: PostConditionPrincipalWire
286
- asset: AssetInfoWire
287
- conditionCode: number
288
- assetId: ClarityValue
289
- };
290
- type StakingPostConditionWire = {
291
- type: "staking"
292
- principal: PostConditionPrincipalWire
293
- conditionCode: number
294
- amount: bigint
295
- };
296
- type PoxPostConditionWire = {
297
- type: "pox"
298
- principal: PostConditionPrincipalWire
299
- conditionCode: PoxConditionCode
300
- };
301
- type PostConditionPrincipalWire = {
302
- type: "origin"
303
- } | {
304
- type: "standard"
305
- address: string
306
- } | {
307
- type: "contract"
308
- address: string
309
- contractName: string
310
- };
311
- type AssetInfoWire = {
312
- address: string
313
- contractName: string
314
- assetName: string
315
- };
316
- type IntegerType = number | string | bigint | Uint8Array;
317
- /**
318
- * The asset an x402 payment moves. Either native STX or a SIP-010 token,
319
- * in which case the fully-qualified contract id and the fungible-token asset
320
- * name (the `::<asset-name>` suffix, e.g. `sbtc-token`) are both required —
321
- * the asset name is not always equal to the contract name.
322
- */
323
- type X402Asset = {
324
- kind: "stx"
325
- } | {
326
- kind: "sip010"
327
- contractId: string
328
- assetName: string
329
- };
330
- type BuildExactTransferOptions = {
331
- /** The asset and amount to move. */
332
- asset: X402Asset
333
- amount: IntegerType
334
- /** Recipient principal (the resource server's `payTo`). */
335
- payTo: string
336
- /** Origin/payer principal — pinned by the post-condition. */
337
- payer: string
338
- /** Origin compressed public key (the payer signs origin-only). */
339
- payerPublicKey: string
340
- /** The payer account's next nonce. */
341
- accountNonce: IntegerType
342
- /**
343
- * The x402 challenge nonce, carried in the on-chain memo so the facilitator
344
- * can correlate the settled tx with the challenge. Bound to ≤ 34 bytes
345
- * (UTF-8) — both the STX memo and the SIP-010 `(buff 34)` memo arg cap there.
346
- */
347
- nonce: string
348
- chain?: StacksChain
349
- };
350
- /**
351
- * Build an exact-amount, Deny-mode, post-conditioned, **sponsored** transfer
352
- * (origin-only, un-broadcast). The origin sets fee `0`; the facilitator's
353
- * sponsor fills in + pays the fee at settle time. The Deny-mode post-condition
354
- * asserts EXACTLY `amount` leaves `payer` to `payTo`, so settlement aborts
355
- * on-chain if anything differs — the "exact amount" x402 guarantee is enforced
356
- * by Clarity, not just by facilitator simulation.
357
- */
358
- declare function buildExactTransfer(options: BuildExactTransferOptions): StacksTransaction;
359
- /** Account derived from a local private key (mnemonic or raw key). */
360
- type LocalAccount = {
361
- type: "local"
362
- address: string
363
- /** Compressed public key (hex) */
364
- publicKey: string
365
- /** Raw ECDSA sign over a hash */
366
- sign(hash: Uint8Array): Uint8Array
367
- /** Sign a structured message (SIP-018) */
368
- signMessage(message: string | Uint8Array): string
369
- };
370
- /** Account with a user-provided signing function (sync or async). */
371
- type CustomAccount = {
372
- type: "custom"
373
- address: string
374
- publicKey: string
375
- sign(hash: Uint8Array): Promise<Uint8Array> | Uint8Array
376
- };
377
- /** Browser wallet provider interface (e.g. Leather, Xverse). */
378
- type StacksProvider = {
379
- request(method: string, params?: any): Promise<any>
380
- };
381
- /** Account backed by a browser wallet {@link StacksProvider}. */
382
- type ProviderAccount = {
383
- type: "provider"
384
- address: string
385
- publicKey: string
386
- provider: StacksProvider
387
- };
388
- /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
389
- type NonceManager = {
390
- consume(params: {
391
- client: Client
392
- address: string
393
- }): Promise<bigint>
394
- reset(params: {
395
- client: Client
396
- address: string
397
- }): void | Promise<void>
398
- /** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */
399
- peek(params: {
400
- client: Client
401
- address: string
402
- }): Promise<bigint | undefined>
403
- };
404
- /** Function that sends an HTTP request to a Stacks node API path. */
405
- type RequestFn = (path: string, options?: RequestOptions) => Promise<any>;
406
- /** Options for a transport-level HTTP request. */
407
- type RequestOptions = {
408
- method?: "GET" | "POST" | "PUT" | "DELETE"
409
- body?: unknown
410
- headers?: Record<string, string>
411
- };
412
- /** Shared configuration for all transport types. */
413
- type TransportConfig = {
414
- url?: string
415
- timeout?: number
416
- retryCount?: number
417
- retryDelay?: number
418
- fetchOptions?: RequestInit
419
- apiKey?: string
420
- };
421
- /** A resolved transport instance with a bound request function. */
422
- type Transport = {
423
- type: string
424
- request: RequestFn
425
- config: TransportConfig
426
- destroy?: () => void
427
- };
428
- /** Union of all supported account types (local key, custom signer, or browser provider). */
429
- type Account = LocalAccount | CustomAccount | ProviderAccount;
430
- /**
431
- * Core client instance that holds chain context, transport, and extensible actions.
432
- * Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}.
433
- */
434
- type Client<TExtended extends Record<string, unknown> = Record<string, unknown>> = {
435
- chain?: StacksChain
436
- account?: Account
437
- transport: Transport
438
- request: RequestFn
439
- /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
440
- nonceManager?: NonceManager
441
- extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
442
- } & TExtended;
443
- /**
444
- * Pluggable transaction-status sources for {@link getTransaction} /
445
- * `waitForTransactionReceipt`.
446
- *
447
- * A bare stacks-node has no confirmed-transaction endpoint, so status reads
448
- * need a host that indexes transactions. Where that data comes from is
449
- * pluggable, mirroring the nonce sources:
450
- *
451
- * - {@link extendedApiSource} — default; `/extended/v1/tx/{txid}` on the
452
- * client's transport host (Hiro API or any extended-API-compatible host).
453
- * - {@link indexTxSource} — Secondlayer's `/v1/index/transactions/{txid}`;
454
- * returns the chain tip in the same response, so N-confirmation waits
455
- * need no second request.
456
- */
457
- type TransactionStatus = "pending" | "success" | "abort_by_response" | "abort_by_post_condition" | "dropped";
458
- type TransactionReceipt = {
459
- txid: string
460
- status: TransactionStatus
461
- /** Anchor block height; absent while pending. */
462
- blockHeight?: number
463
- blockHash?: string
464
- /** Decoded Clarity result; absent while pending or when the source omits it. */
465
- result?: ClarityValue
466
- resultHex?: string
467
- events: unknown[]
468
- /** The source's unnormalized response, for fields the receipt doesn't model. */
469
- raw: unknown
470
- };
471
- type SponsorAndBroadcastOptions = {
472
- /** Override the sponsor fee (µSTX). Defaults to a fee estimate. */
473
- fee?: IntegerType
474
- /** Override the sponsor account nonce. Defaults to the on-chain nonce. */
475
- nonce?: IntegerType
476
- /**
477
- * Wait for the payment to be mined before returning (`true` = 1
478
- * confirmation, a number = that many). Settlement rejects if the payment
479
- * aborts or drops, instead of reporting a txid that never lands.
480
- */
481
- wait?: boolean | number
482
- };
483
- type SponsorAndBroadcastResult = {
484
- txid: string
485
- /** Present when `wait` was requested. */
486
- receipt?: TransactionReceipt
487
- };
488
- /**
489
- * Take an origin-signed, sponsored transfer (hex) from the payer, sponsor-sign
490
- * it with `client`'s account (paying the STX fee), and broadcast it.
491
- *
492
- * The payer never holds STX: they sign origin-only with fee `0`; this fills in
493
- * the sponsor spending condition + fee and POSTs to `/v2/transactions`. The
494
- * sponsor cannot grief the payer — amount/recipient/asset are pinned by the
495
- * origin signature + Deny-mode post-conditions baked into the tx.
496
- *
497
- * @param client a wallet client whose `account` is the funded sponsor signer.
498
- * @param signedTxHex the payer's origin-signed sponsored tx, hex-serialized.
499
- */
500
- declare function sponsorAndBroadcast(client: Client, signedTxHex: string, options?: SponsorAndBroadcastOptions): Promise<SponsorAndBroadcastResult>;
501
- export { sponsorAndBroadcast, buildExactTransfer, X402Asset, SponsorAndBroadcastResult, SponsorAndBroadcastOptions, BuildExactTransferOptions };
@@ -1,90 +0,0 @@
1
- import {
2
- sponsorTransaction
3
- } from "../../shared/stacks-w8tt1fmt.js";
4
- import {
5
- sendTransaction
6
- } from "../../shared/stacks-9d2d0qjc.js";
7
- import"../../shared/stacks-fh48neva.js";
8
- import"../../shared/stacks-709tra19.js";
9
- import {
10
- Pc
11
- } from "../../shared/stacks-bm49tsh0.js";
12
- import {
13
- deserializeTransaction
14
- } from "../../shared/stacks-gkf9tsws.js";
15
- import {
16
- MEMO_MAX_LENGTH_BYTES,
17
- buildContractCall,
18
- buildTokenTransfer
19
- } from "../../shared/stacks-jx146qf1.js";
20
- import {
21
- Cl
22
- } from "../../shared/stacks-ttdk2g2f.js";
23
- import {
24
- parseContractId
25
- } from "../../shared/stacks-bfan7ex7.js";
26
- import {
27
- utf8ToBytes
28
- } from "../../shared/stacks-qs5fzts5.js";
29
-
30
- // src/x402/build.ts
31
- function buildExactTransfer(options) {
32
- const { asset, amount, payTo, payer, payerPublicKey, accountNonce, chain } = options;
33
- if (utf8ToBytes(options.nonce).byteLength > MEMO_MAX_LENGTH_BYTES) {
34
- throw new Error(`x402 nonce exceeds the ${MEMO_MAX_LENGTH_BYTES}-byte memo budget`);
35
- }
36
- if (asset.kind === "stx") {
37
- return buildTokenTransfer({
38
- recipient: payTo,
39
- amount,
40
- memo: options.nonce,
41
- fee: 0,
42
- nonce: accountNonce,
43
- publicKey: payerPublicKey,
44
- chain,
45
- sponsored: true
46
- });
47
- }
48
- const [contractAddress, contractName] = parseContractId(asset.contractId);
49
- const postConditions = [
50
- Pc.principal(payer).willSendEq(amount).ft(asset.contractId, asset.assetName)
51
- ];
52
- return buildContractCall({
53
- contractAddress,
54
- contractName,
55
- functionName: "transfer",
56
- functionArgs: [
57
- Cl.uint(amount),
58
- Cl.principal(payer),
59
- Cl.principal(payTo),
60
- Cl.some(Cl.bufferFromUtf8(options.nonce))
61
- ],
62
- fee: 0,
63
- nonce: accountNonce,
64
- publicKey: payerPublicKey,
65
- chain,
66
- postConditionMode: "deny",
67
- postConditions,
68
- sponsored: true
69
- });
70
- }
71
- // src/x402/settle.ts
72
- async function sponsorAndBroadcast(client, signedTxHex, options = {}) {
73
- const transaction = deserializeTransaction(signedTxHex);
74
- const sponsored = await sponsorTransaction(client, {
75
- transaction,
76
- fee: options.fee,
77
- nonce: options.nonce
78
- });
79
- return sendTransaction(client, {
80
- transaction: sponsored,
81
- wait: options.wait
82
- });
83
- }
84
- export {
85
- sponsorAndBroadcast,
86
- buildExactTransfer
87
- };
88
-
89
- //# debugId=F83B60203303BF2E64756E2164756E21
90
- //# sourceMappingURL=index.js.map
@@ -1,11 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/x402/build.ts", "../src/x402/settle.ts"],
4
- "sourcesContent": [
5
- "import type { StacksChain } from \"../chains/types.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport { Pc } from \"../postconditions/builder.ts\";\nimport type { PostCondition } from \"../postconditions/types.ts\";\nimport {\n\tbuildContractCall,\n\tbuildTokenTransfer,\n} from \"../transactions/build.ts\";\nimport {\n\tMEMO_MAX_LENGTH_BYTES,\n\ttype StacksTransaction,\n} from \"../transactions/types.ts\";\nimport { parseContractId } from \"../utils/address.ts\";\nimport { type IntegerType, utf8ToBytes } from \"../utils/encoding.ts\";\n\n/**\n * The asset an x402 payment moves. Either native STX or a SIP-010 token,\n * in which case the fully-qualified contract id and the fungible-token asset\n * name (the `::<asset-name>` suffix, e.g. `sbtc-token`) are both required —\n * the asset name is not always equal to the contract name.\n */\nexport type X402Asset =\n\t| { kind: \"stx\" }\n\t| { kind: \"sip010\"; contractId: string; assetName: string };\n\nexport type BuildExactTransferOptions = {\n\t/** The asset and amount to move. */\n\tasset: X402Asset;\n\tamount: IntegerType;\n\t/** Recipient principal (the resource server's `payTo`). */\n\tpayTo: string;\n\t/** Origin/payer principal — pinned by the post-condition. */\n\tpayer: string;\n\t/** Origin compressed public key (the payer signs origin-only). */\n\tpayerPublicKey: string;\n\t/** The payer account's next nonce. */\n\taccountNonce: IntegerType;\n\t/**\n\t * The x402 challenge nonce, carried in the on-chain memo so the facilitator\n\t * can correlate the settled tx with the challenge. Bound to ≤ 34 bytes\n\t * (UTF-8) — both the STX memo and the SIP-010 `(buff 34)` memo arg cap there.\n\t */\n\tnonce: string;\n\tchain?: StacksChain;\n};\n\n/**\n * Build an exact-amount, Deny-mode, post-conditioned, **sponsored** transfer\n * (origin-only, un-broadcast). The origin sets fee `0`; the facilitator's\n * sponsor fills in + pays the fee at settle time. The Deny-mode post-condition\n * asserts EXACTLY `amount` leaves `payer` to `payTo`, so settlement aborts\n * on-chain if anything differs — the \"exact amount\" x402 guarantee is enforced\n * by Clarity, not just by facilitator simulation.\n */\nexport function buildExactTransfer(\n\toptions: BuildExactTransferOptions,\n): StacksTransaction {\n\tconst { asset, amount, payTo, payer, payerPublicKey, accountNonce, chain } =\n\t\toptions;\n\n\tif (utf8ToBytes(options.nonce).byteLength > MEMO_MAX_LENGTH_BYTES) {\n\t\tthrow new Error(\n\t\t\t`x402 nonce exceeds the ${MEMO_MAX_LENGTH_BYTES}-byte memo budget`,\n\t\t);\n\t}\n\n\tif (asset.kind === \"stx\") {\n\t\t// A TokenTransfer payload CANNOT carry post-conditions (Stacks consensus\n\t\t// rejects it: \"TokenTransfer transactions do not support post-conditions\").\n\t\t// STX exactness is inherent — the amount + recipient are in the signed\n\t\t// payload, so there is nothing a post-condition would add.\n\t\treturn buildTokenTransfer({\n\t\t\trecipient: payTo,\n\t\t\tamount,\n\t\t\tmemo: options.nonce,\n\t\t\tfee: 0,\n\t\t\tnonce: accountNonce,\n\t\t\tpublicKey: payerPublicKey,\n\t\t\tchain,\n\t\t\tsponsored: true,\n\t\t});\n\t}\n\n\tconst [contractAddress, contractName] = parseContractId(asset.contractId);\n\tconst postConditions: PostCondition[] = [\n\t\tPc.principal(payer)\n\t\t\t.willSendEq(amount)\n\t\t\t.ft(asset.contractId, asset.assetName),\n\t];\n\t// SIP-010: (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))\n\treturn buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: \"transfer\",\n\t\tfunctionArgs: [\n\t\t\tCl.uint(amount),\n\t\t\tCl.principal(payer),\n\t\t\tCl.principal(payTo),\n\t\t\tCl.some(Cl.bufferFromUtf8(options.nonce)),\n\t\t],\n\t\tfee: 0,\n\t\tnonce: accountNonce,\n\t\tpublicKey: payerPublicKey,\n\t\tchain,\n\t\tpostConditionMode: \"deny\",\n\t\tpostConditions,\n\t\tsponsored: true,\n\t});\n}\n",
6
- "import type { TransactionReceipt } from \"../actions/public/txSources.ts\";\nimport { sendTransaction } from \"../actions/wallet/sendTransaction.ts\";\nimport { sponsorTransaction } from \"../actions/wallet/sponsorTransaction.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport { deserializeTransaction } from \"../transactions/wire/deserialize.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\n\nexport type SponsorAndBroadcastOptions = {\n\t/** Override the sponsor fee (µSTX). Defaults to a fee estimate. */\n\tfee?: IntegerType;\n\t/** Override the sponsor account nonce. Defaults to the on-chain nonce. */\n\tnonce?: IntegerType;\n\t/**\n\t * Wait for the payment to be mined before returning (`true` = 1\n\t * confirmation, a number = that many). Settlement rejects if the payment\n\t * aborts or drops, instead of reporting a txid that never lands.\n\t */\n\twait?: boolean | number;\n};\n\nexport type SponsorAndBroadcastResult = {\n\ttxid: string;\n\t/** Present when `wait` was requested. */\n\treceipt?: TransactionReceipt;\n};\n\n/**\n * Take an origin-signed, sponsored transfer (hex) from the payer, sponsor-sign\n * it with `client`'s account (paying the STX fee), and broadcast it.\n *\n * The payer never holds STX: they sign origin-only with fee `0`; this fills in\n * the sponsor spending condition + fee and POSTs to `/v2/transactions`. The\n * sponsor cannot grief the payer — amount/recipient/asset are pinned by the\n * origin signature + Deny-mode post-conditions baked into the tx.\n *\n * @param client a wallet client whose `account` is the funded sponsor signer.\n * @param signedTxHex the payer's origin-signed sponsored tx, hex-serialized.\n */\nexport async function sponsorAndBroadcast(\n\tclient: Client,\n\tsignedTxHex: string,\n\toptions: SponsorAndBroadcastOptions = {},\n): Promise<SponsorAndBroadcastResult> {\n\tconst transaction = deserializeTransaction(signedTxHex);\n\tconst sponsored = await sponsorTransaction(client, {\n\t\ttransaction,\n\t\tfee: options.fee,\n\t\tnonce: options.nonce,\n\t});\n\treturn sendTransaction(client, {\n\t\ttransaction: sponsored,\n\t\twait: options.wait,\n\t});\n}\n"
7
- ],
8
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDO,SAAS,kBAAkB,CACjC,SACoB;AAAA,EACpB,QAAQ,OAAO,QAAQ,OAAO,OAAO,gBAAgB,cAAc,UAClE;AAAA,EAED,IAAI,YAAY,QAAQ,KAAK,EAAE,aAAa,uBAAuB;AAAA,IAClE,MAAM,IAAI,MACT,0BAA0B,wCAC3B;AAAA,EACD;AAAA,EAEA,IAAI,MAAM,SAAS,OAAO;AAAA,IAKzB,OAAO,mBAAmB;AAAA,MACzB,WAAW;AAAA,MACX;AAAA,MACA,MAAM,QAAQ;AAAA,MACd,KAAK;AAAA,MACL,OAAO;AAAA,MACP,WAAW;AAAA,MACX;AAAA,MACA,WAAW;AAAA,IACZ,CAAC;AAAA,EACF;AAAA,EAEA,OAAO,iBAAiB,gBAAgB,gBAAgB,MAAM,UAAU;AAAA,EACxE,MAAM,iBAAkC;AAAA,IACvC,GAAG,UAAU,KAAK,EAChB,WAAW,MAAM,EACjB,GAAG,MAAM,YAAY,MAAM,SAAS;AAAA,EACvC;AAAA,EAEA,OAAO,kBAAkB;AAAA,IACxB;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,cAAc;AAAA,MACb,GAAG,KAAK,MAAM;AAAA,MACd,GAAG,UAAU,KAAK;AAAA,MAClB,GAAG,UAAU,KAAK;AAAA,MAClB,GAAG,KAAK,GAAG,eAAe,QAAQ,KAAK,CAAC;AAAA,IACzC;AAAA,IACA,KAAK;AAAA,IACL,OAAO;AAAA,IACP,WAAW;AAAA,IACX;AAAA,IACA,mBAAmB;AAAA,IACnB;AAAA,IACA,WAAW;AAAA,EACZ,CAAC;AAAA;;ACrEF,eAAsB,mBAAmB,CACxC,QACA,aACA,UAAsC,CAAC,GACF;AAAA,EACrC,MAAM,cAAc,uBAAuB,WAAW;AAAA,EACtD,MAAM,YAAY,MAAM,mBAAmB,QAAQ;AAAA,IAClD;AAAA,IACA,KAAK,QAAQ;AAAA,IACb,OAAO,QAAQ;AAAA,EAChB,CAAC;AAAA,EACD,OAAO,gBAAgB,QAAQ;AAAA,IAC9B,aAAa;AAAA,IACb,MAAM,QAAQ;AAAA,EACf,CAAC;AAAA;",
9
- "debugId": "F83B60203303BF2E64756E2164756E21",
10
- "names": []
11
- }