@secondlayer/stacks 2.4.0 → 2.5.1

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/README.md +10 -1
  2. package/dist/shared/{stacks-kmnthgj7.js → stacks-4trgpb5a.js} +13 -3
  3. package/dist/shared/{stacks-kmnthgj7.js.map → stacks-4trgpb5a.js.map} +3 -3
  4. package/dist/shared/stacks-4z1jhw6y.js +51 -0
  5. package/dist/shared/stacks-4z1jhw6y.js.map +10 -0
  6. package/dist/shared/{stacks-fy5h5qyx.js → stacks-5th5dffx.js} +9 -44
  7. package/dist/shared/{stacks-fy5h5qyx.js.map → stacks-5th5dffx.js.map} +3 -4
  8. package/dist/shared/stacks-7wfdkhj6.cjs +70 -0
  9. package/dist/shared/stacks-7wfdkhj6.cjs.map +12 -0
  10. package/dist/shared/stacks-7wqprfrm.cjs +35 -0
  11. package/dist/shared/stacks-7wqprfrm.cjs.map +10 -0
  12. package/dist/shared/{stacks-dr5en54r.cjs → stacks-8e5atbps.cjs} +2 -9
  13. package/dist/shared/{stacks-dr5en54r.cjs.map → stacks-8e5atbps.cjs.map} +2 -2
  14. package/dist/shared/{stacks-kmshch4q.js → stacks-a36n7sjz.js} +3 -2
  15. package/dist/shared/{stacks-kmshch4q.js.map → stacks-a36n7sjz.js.map} +1 -1
  16. package/dist/shared/stacks-d6pgp4qk.cjs +9 -0
  17. package/dist/shared/stacks-d6pgp4qk.cjs.map +9 -0
  18. package/dist/shared/{stacks-xxvz1x0f.cjs → stacks-ertyhttt.cjs} +13 -3
  19. package/dist/shared/{stacks-xxvz1x0f.cjs.map → stacks-ertyhttt.cjs.map} +3 -3
  20. package/dist/shared/{stacks-7tn3zsbe.js → stacks-hyz7zgdk.js} +2 -2
  21. package/dist/shared/{stacks-14pgpkrr.cjs → stacks-jevhg39n.cjs} +2 -35
  22. package/dist/shared/{stacks-14pgpkrr.cjs.map → stacks-jevhg39n.cjs.map} +3 -4
  23. package/dist/shared/stacks-qk8pdyjy.cjs +76 -0
  24. package/dist/shared/stacks-qk8pdyjy.cjs.map +14 -0
  25. package/dist/shared/{stacks-y2p4h5ks.js → stacks-wqgepfab.js} +2 -2
  26. package/dist/shared/stacks-y8e3gx6w.js +90 -0
  27. package/dist/shared/stacks-y8e3gx6w.js.map +14 -0
  28. package/dist/shared/{stacks-y3nbm8bw.cjs → stacks-yq5a5cda.js} +25 -75
  29. package/dist/shared/stacks-yq5a5cda.js.map +12 -0
  30. package/dist/shared/stacks-z53fwfcm.js +3 -0
  31. package/dist/shared/stacks-z53fwfcm.js.map +9 -0
  32. package/dist/src/actions/index.js +16 -12
  33. package/dist/src/actions/index.js.map +1 -1
  34. package/dist/src/bns/index.js +7 -5
  35. package/dist/src/bns/index.js.map +2 -2
  36. package/dist/src/index.cjs.map +1 -1
  37. package/dist/src/index.d.cts +1 -1
  38. package/dist/src/index.d.ts +1 -1
  39. package/dist/src/index.js +18 -14
  40. package/dist/src/index.js.map +3 -3
  41. package/dist/src/postconditions/index.js +3 -2
  42. package/dist/src/postconditions/index.js.map +1 -1
  43. package/dist/src/pox/index.js +7 -5
  44. package/dist/src/pox/index.js.map +2 -2
  45. package/dist/src/sbtc/index.js +5 -4
  46. package/dist/src/sbtc/index.js.map +2 -2
  47. package/dist/src/stackingdao/index.js +7 -5
  48. package/dist/src/stackingdao/index.js.map +2 -2
  49. package/dist/src/tools/index.cjs +12 -2
  50. package/dist/src/tools/index.cjs.map +3 -3
  51. package/dist/src/tools/index.js +12 -2
  52. package/dist/src/tools/index.js.map +3 -3
  53. package/dist/src/transactions/index.js +2 -2
  54. package/dist/src/x402/index.cjs +62 -0
  55. package/dist/src/x402/index.cjs.map +11 -0
  56. package/dist/src/x402/index.d.cts +424 -0
  57. package/dist/src/x402/index.d.ts +424 -0
  58. package/dist/src/x402/index.js +88 -0
  59. package/dist/src/x402/index.js.map +11 -0
  60. package/package.json +7 -1
  61. package/dist/shared/stacks-g7ys594x.js +0 -168
  62. package/dist/shared/stacks-g7ys594x.js.map +0 -17
  63. package/dist/shared/stacks-y3nbm8bw.cjs.map +0 -17
  64. /package/dist/shared/{stacks-7tn3zsbe.js.map → stacks-hyz7zgdk.js.map} +0 -0
  65. /package/dist/shared/{stacks-y2p4h5ks.js.map → stacks-wqgepfab.js.map} +0 -0
@@ -0,0 +1,424 @@
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
+ };
129
+ type ClarityVersion = (typeof ClarityVersion)[keyof typeof ClarityVersion];
130
+ declare const AnchorMode: {
131
+ readonly OnChainOnly: 0x01
132
+ readonly OffChainOnly: 0x02
133
+ readonly Any: 0x03
134
+ };
135
+ type AnchorMode = (typeof AnchorMode)[keyof typeof AnchorMode];
136
+ declare const PostConditionModeWire: {
137
+ readonly Allow: 0x01
138
+ readonly Deny: 0x02
139
+ };
140
+ type PostConditionModeWire = (typeof PostConditionModeWire)[keyof typeof PostConditionModeWire];
141
+ declare const AddressHashMode: {
142
+ readonly P2PKH: 0x00
143
+ readonly P2SH: 0x01
144
+ readonly P2WPKH: 0x02
145
+ readonly P2WSH: 0x03
146
+ readonly P2SH_NonSequential: 0x05
147
+ readonly P2WSH_P2SH_NonSequential: 0x07
148
+ };
149
+ type AddressHashMode = (typeof AddressHashMode)[keyof typeof AddressHashMode];
150
+ declare const PubKeyEncoding: {
151
+ readonly Compressed: 0x00
152
+ readonly Uncompressed: 0x01
153
+ };
154
+ type PubKeyEncoding = (typeof PubKeyEncoding)[keyof typeof PubKeyEncoding];
155
+ declare const TenureChangeCause: {
156
+ readonly BlockFound: 0x00
157
+ readonly Extended: 0x01
158
+ readonly ExtendedRuntime: 0x02
159
+ readonly ExtendedReadCount: 0x03
160
+ readonly ExtendedReadLength: 0x04
161
+ readonly ExtendedWriteCount: 0x05
162
+ readonly ExtendedWriteLength: 0x06
163
+ };
164
+ type TenureChangeCause = (typeof TenureChangeCause)[keyof typeof TenureChangeCause];
165
+ type TokenTransferPayload = {
166
+ payloadType: typeof PayloadType.TokenTransfer
167
+ recipient: ClarityValue
168
+ amount: bigint
169
+ memo: string
170
+ };
171
+ type ContractCallPayload = {
172
+ payloadType: typeof PayloadType.ContractCall
173
+ contractAddress: string
174
+ contractName: string
175
+ functionName: string
176
+ functionArgs: ClarityValue[]
177
+ };
178
+ type SmartContractPayload = {
179
+ payloadType: typeof PayloadType.SmartContract | typeof PayloadType.VersionedSmartContract
180
+ clarityVersion?: ClarityVersion
181
+ contractName: string
182
+ codeBody: string
183
+ };
184
+ type CoinbasePayload = {
185
+ payloadType: typeof PayloadType.Coinbase
186
+ coinbaseBuffer: string
187
+ };
188
+ type CoinbaseToAltRecipientPayload = {
189
+ payloadType: typeof PayloadType.CoinbaseToAltRecipient
190
+ coinbaseBuffer: string
191
+ recipient: ClarityValue
192
+ };
193
+ type PoisonMicroblockPayload = {
194
+ payloadType: typeof PayloadType.PoisonMicroblock
195
+ header1: string
196
+ header2: string
197
+ };
198
+ type TenureChangePayload = {
199
+ payloadType: typeof PayloadType.TenureChange
200
+ tenureConsensusHash: string
201
+ prevTenureConsensusHash: string
202
+ burnViewConsensusHash: string
203
+ previousTenureEnd: string
204
+ previousTenureBlocks: number
205
+ cause: TenureChangeCause
206
+ pubkeyHash: string
207
+ };
208
+ type NakamotoCoinbasePayload = {
209
+ payloadType: typeof PayloadType.NakamotoCoinbase
210
+ coinbaseBuffer: string
211
+ recipient: ClarityValue | null
212
+ vrfProof: string
213
+ };
214
+ type TransactionPayload = TokenTransferPayload | ContractCallPayload | SmartContractPayload | CoinbasePayload | CoinbaseToAltRecipientPayload | PoisonMicroblockPayload | TenureChangePayload | NakamotoCoinbasePayload;
215
+ type SingleSigSpendingCondition = {
216
+ hashMode: typeof AddressHashMode.P2PKH | typeof AddressHashMode.P2WPKH
217
+ signer: string
218
+ nonce: bigint
219
+ fee: bigint
220
+ keyEncoding: PubKeyEncoding
221
+ signature: string
222
+ };
223
+ type TransactionAuthField = {
224
+ pubKeyEncoding: PubKeyEncoding
225
+ type: "publicKey" | "signature"
226
+ data: string
227
+ };
228
+ type MultiSigHashMode = typeof AddressHashMode.P2SH | typeof AddressHashMode.P2WSH | typeof AddressHashMode.P2SH_NonSequential | typeof AddressHashMode.P2WSH_P2SH_NonSequential;
229
+ type MultiSigSpendingCondition = {
230
+ hashMode: MultiSigHashMode
231
+ signer: string
232
+ nonce: bigint
233
+ fee: bigint
234
+ fields: TransactionAuthField[]
235
+ signaturesRequired: number
236
+ };
237
+ type SpendingCondition = SingleSigSpendingCondition | MultiSigSpendingCondition;
238
+ type StandardAuthorization = {
239
+ authType: typeof AuthType.Standard
240
+ spendingCondition: SpendingCondition
241
+ };
242
+ type SponsoredAuthorization = {
243
+ authType: typeof AuthType.Sponsored
244
+ spendingCondition: SpendingCondition
245
+ sponsorSpendingCondition: SpendingCondition
246
+ };
247
+ type Authorization = StandardAuthorization | SponsoredAuthorization;
248
+ type StacksTransaction = {
249
+ version: number
250
+ chainId: number
251
+ auth: Authorization
252
+ anchorMode: AnchorMode
253
+ postConditionMode: PostConditionModeWire
254
+ postConditions: PostConditionWire[]
255
+ payload: TransactionPayload
256
+ };
257
+ type PostConditionWire = StxPostConditionWire | FtPostConditionWire | NftPostConditionWire;
258
+ type StxPostConditionWire = {
259
+ type: "stx"
260
+ principal: PostConditionPrincipalWire
261
+ conditionCode: number
262
+ amount: bigint
263
+ };
264
+ type FtPostConditionWire = {
265
+ type: "ft"
266
+ principal: PostConditionPrincipalWire
267
+ asset: AssetInfoWire
268
+ conditionCode: number
269
+ amount: bigint
270
+ };
271
+ type NftPostConditionWire = {
272
+ type: "nft"
273
+ principal: PostConditionPrincipalWire
274
+ asset: AssetInfoWire
275
+ conditionCode: number
276
+ assetId: ClarityValue
277
+ };
278
+ type PostConditionPrincipalWire = {
279
+ type: "origin"
280
+ } | {
281
+ type: "standard"
282
+ address: string
283
+ } | {
284
+ type: "contract"
285
+ address: string
286
+ contractName: string
287
+ };
288
+ type AssetInfoWire = {
289
+ address: string
290
+ contractName: string
291
+ assetName: string
292
+ };
293
+ type IntegerType = number | string | bigint | Uint8Array;
294
+ /**
295
+ * The asset an x402 payment moves. Either native STX or a SIP-010 token,
296
+ * in which case the fully-qualified contract id and the fungible-token asset
297
+ * name (the `::<asset-name>` suffix, e.g. `sbtc-token`) are both required —
298
+ * the asset name is not always equal to the contract name.
299
+ */
300
+ type X402Asset = {
301
+ kind: "stx"
302
+ } | {
303
+ kind: "sip010"
304
+ contractId: string
305
+ assetName: string
306
+ };
307
+ type BuildExactTransferOptions = {
308
+ /** The asset and amount to move. */
309
+ asset: X402Asset
310
+ amount: IntegerType
311
+ /** Recipient principal (the resource server's `payTo`). */
312
+ payTo: string
313
+ /** Origin/payer principal — pinned by the post-condition. */
314
+ payer: string
315
+ /** Origin compressed public key (the payer signs origin-only). */
316
+ payerPublicKey: string
317
+ /** The payer account's next nonce. */
318
+ accountNonce: IntegerType
319
+ /**
320
+ * The x402 challenge nonce, carried in the on-chain memo so the facilitator
321
+ * can correlate the settled tx with the challenge. Bound to ≤ 34 bytes
322
+ * (UTF-8) — both the STX memo and the SIP-010 `(buff 34)` memo arg cap there.
323
+ */
324
+ nonce: string
325
+ chain?: StacksChain
326
+ };
327
+ /**
328
+ * Build an exact-amount, Deny-mode, post-conditioned, **sponsored** transfer
329
+ * (origin-only, un-broadcast). The origin sets fee `0`; the facilitator's
330
+ * sponsor fills in + pays the fee at settle time. The Deny-mode post-condition
331
+ * asserts EXACTLY `amount` leaves `payer` to `payTo`, so settlement aborts
332
+ * on-chain if anything differs — the "exact amount" x402 guarantee is enforced
333
+ * by Clarity, not just by facilitator simulation.
334
+ */
335
+ declare function buildExactTransfer(options: BuildExactTransferOptions): StacksTransaction;
336
+ /** Account derived from a local private key (mnemonic or raw key). */
337
+ type LocalAccount = {
338
+ type: "local"
339
+ address: string
340
+ /** Compressed public key (hex) */
341
+ publicKey: string
342
+ /** Raw ECDSA sign over a hash */
343
+ sign(hash: Uint8Array): Uint8Array
344
+ /** Sign a structured message (SIP-018) */
345
+ signMessage(message: string | Uint8Array): string
346
+ };
347
+ /** Account with a user-provided signing function (sync or async). */
348
+ type CustomAccount = {
349
+ type: "custom"
350
+ address: string
351
+ publicKey: string
352
+ sign(hash: Uint8Array): Promise<Uint8Array> | Uint8Array
353
+ };
354
+ /** Browser wallet provider interface (e.g. Leather, Xverse). */
355
+ type StacksProvider = {
356
+ request(method: string, params?: any): Promise<any>
357
+ };
358
+ /** Account backed by a browser wallet {@link StacksProvider}. */
359
+ type ProviderAccount = {
360
+ type: "provider"
361
+ address: string
362
+ publicKey: string
363
+ provider: StacksProvider
364
+ };
365
+ /** Function that sends an HTTP request to a Stacks node API path. */
366
+ type RequestFn = (path: string, options?: RequestOptions) => Promise<any>;
367
+ /** Options for a transport-level HTTP request. */
368
+ type RequestOptions = {
369
+ method?: "GET" | "POST" | "PUT" | "DELETE"
370
+ body?: unknown
371
+ headers?: Record<string, string>
372
+ };
373
+ /** Shared configuration for all transport types. */
374
+ type TransportConfig = {
375
+ url?: string
376
+ timeout?: number
377
+ retryCount?: number
378
+ retryDelay?: number
379
+ fetchOptions?: RequestInit
380
+ apiKey?: string
381
+ };
382
+ /** A resolved transport instance with a bound request function. */
383
+ type Transport = {
384
+ type: string
385
+ request: RequestFn
386
+ config: TransportConfig
387
+ destroy?: () => void
388
+ };
389
+ /** Union of all supported account types (local key, custom signer, or browser provider). */
390
+ type Account = LocalAccount | CustomAccount | ProviderAccount;
391
+ /**
392
+ * Core client instance that holds chain context, transport, and extensible actions.
393
+ * Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}.
394
+ */
395
+ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>> = {
396
+ chain?: StacksChain
397
+ account?: Account
398
+ transport: Transport
399
+ request: RequestFn
400
+ extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
401
+ } & TExtended;
402
+ type SponsorAndBroadcastOptions = {
403
+ /** Override the sponsor fee (µSTX). Defaults to a fee estimate. */
404
+ fee?: IntegerType
405
+ /** Override the sponsor account nonce. Defaults to the on-chain nonce. */
406
+ nonce?: IntegerType
407
+ };
408
+ type SponsorAndBroadcastResult = {
409
+ txid: string
410
+ };
411
+ /**
412
+ * Take an origin-signed, sponsored transfer (hex) from the payer, sponsor-sign
413
+ * it with `client`'s account (paying the STX fee), and broadcast it.
414
+ *
415
+ * The payer never holds STX: they sign origin-only with fee `0`; this fills in
416
+ * the sponsor spending condition + fee and POSTs to `/v2/transactions`. The
417
+ * sponsor cannot grief the payer — amount/recipient/asset are pinned by the
418
+ * origin signature + Deny-mode post-conditions baked into the tx.
419
+ *
420
+ * @param client a wallet client whose `account` is the funded sponsor signer.
421
+ * @param signedTxHex the payer's origin-signed sponsored tx, hex-serialized.
422
+ */
423
+ declare function sponsorAndBroadcast(client: Client, signedTxHex: string, options?: SponsorAndBroadcastOptions): Promise<SponsorAndBroadcastResult>;
424
+ export { sponsorAndBroadcast, buildExactTransfer, X402Asset, SponsorAndBroadcastResult, SponsorAndBroadcastOptions, BuildExactTransferOptions };