@secondlayer/stacks 2.3.0 → 2.5.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.
- package/dist/shared/{stacks-shh3gp0x.js → stacks-43cxvnr7.js} +4 -3
- package/dist/shared/{stacks-shh3gp0x.js.map → stacks-43cxvnr7.js.map} +3 -3
- package/dist/shared/{stacks-kmnthgj7.js → stacks-4trgpb5a.js} +13 -3
- package/dist/shared/{stacks-kmnthgj7.js.map → stacks-4trgpb5a.js.map} +3 -3
- package/dist/shared/stacks-4z1jhw6y.js +51 -0
- package/dist/shared/stacks-4z1jhw6y.js.map +10 -0
- package/dist/shared/{stacks-fy5h5qyx.js → stacks-5th5dffx.js} +9 -44
- package/dist/shared/{stacks-fy5h5qyx.js.map → stacks-5th5dffx.js.map} +3 -4
- package/dist/shared/stacks-7wfdkhj6.cjs +70 -0
- package/dist/shared/stacks-7wfdkhj6.cjs.map +12 -0
- package/dist/shared/stacks-7wqprfrm.cjs +35 -0
- package/dist/shared/stacks-7wqprfrm.cjs.map +10 -0
- package/dist/shared/{stacks-dr5en54r.cjs → stacks-8e5atbps.cjs} +2 -9
- package/dist/shared/{stacks-dr5en54r.cjs.map → stacks-8e5atbps.cjs.map} +2 -2
- package/dist/shared/{stacks-kmshch4q.js → stacks-a36n7sjz.js} +3 -2
- package/dist/shared/{stacks-kmshch4q.js.map → stacks-a36n7sjz.js.map} +1 -1
- package/dist/shared/stacks-d6pgp4qk.cjs +9 -0
- package/dist/shared/stacks-d6pgp4qk.cjs.map +9 -0
- package/dist/shared/{stacks-xxvz1x0f.cjs → stacks-ertyhttt.cjs} +13 -3
- package/dist/shared/{stacks-xxvz1x0f.cjs.map → stacks-ertyhttt.cjs.map} +3 -3
- package/dist/shared/{stacks-7tn3zsbe.js → stacks-hyz7zgdk.js} +2 -2
- package/dist/shared/{stacks-14pgpkrr.cjs → stacks-jevhg39n.cjs} +2 -35
- package/dist/shared/{stacks-14pgpkrr.cjs.map → stacks-jevhg39n.cjs.map} +3 -4
- package/dist/shared/stacks-qk8pdyjy.cjs +76 -0
- package/dist/shared/stacks-qk8pdyjy.cjs.map +14 -0
- package/dist/shared/{stacks-9a0xebgq.cjs → stacks-vk8fwz0t.cjs} +4 -2
- package/dist/shared/{stacks-9a0xebgq.cjs.map → stacks-vk8fwz0t.cjs.map} +3 -3
- package/dist/shared/{stacks-y2p4h5ks.js → stacks-wqgepfab.js} +2 -2
- package/dist/shared/stacks-y8e3gx6w.js +90 -0
- package/dist/shared/stacks-y8e3gx6w.js.map +14 -0
- package/dist/shared/{stacks-y3nbm8bw.cjs → stacks-yq5a5cda.js} +25 -75
- package/dist/shared/stacks-yq5a5cda.js.map +12 -0
- package/dist/shared/stacks-z53fwfcm.js +3 -0
- package/dist/shared/stacks-z53fwfcm.js.map +9 -0
- package/dist/src/actions/index.js +16 -12
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bns/index.js +8 -6
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/clarity/index.d.cts +6 -2
- package/dist/src/clarity/index.d.ts +6 -2
- package/dist/src/clarity/index.js +4 -2
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/index.cjs.map +4 -4
- package/dist/src/index.d.cts +4 -4
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.js +18 -14
- package/dist/src/index.js.map +6 -6
- package/dist/src/postconditions/index.js +3 -2
- package/dist/src/postconditions/index.js.map +1 -1
- package/dist/src/pox/index.js +7 -5
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/sbtc/index.js +5 -4
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/stackingdao/index.js +7 -5
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/tools/index.cjs +12 -2
- package/dist/src/tools/index.cjs.map +4 -4
- package/dist/src/tools/index.js +12 -2
- package/dist/src/tools/index.js.map +4 -4
- package/dist/src/transactions/index.js +2 -2
- package/dist/src/x402/index.cjs +62 -0
- package/dist/src/x402/index.cjs.map +11 -0
- package/dist/src/x402/index.d.cts +424 -0
- package/dist/src/x402/index.d.ts +424 -0
- package/dist/src/x402/index.js +88 -0
- package/dist/src/x402/index.js.map +11 -0
- package/package.json +7 -1
- package/dist/shared/stacks-g7ys594x.js +0 -168
- package/dist/shared/stacks-g7ys594x.js.map +0 -17
- package/dist/shared/stacks-y3nbm8bw.cjs.map +0 -17
- /package/dist/shared/{stacks-7tn3zsbe.js.map → stacks-hyz7zgdk.js.map} +0 -0
- /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 };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sponsorTransaction
|
|
3
|
+
} from "../../shared/stacks-4z1jhw6y.js";
|
|
4
|
+
import {
|
|
5
|
+
sendTransaction
|
|
6
|
+
} from "../../shared/stacks-y8e3gx6w.js";
|
|
7
|
+
import"../../shared/stacks-709tra19.js";
|
|
8
|
+
import {
|
|
9
|
+
Pc
|
|
10
|
+
} from "../../shared/stacks-a36n7sjz.js";
|
|
11
|
+
import {
|
|
12
|
+
deserializeTransaction
|
|
13
|
+
} from "../../shared/stacks-wqgepfab.js";
|
|
14
|
+
import {
|
|
15
|
+
MEMO_MAX_LENGTH_BYTES,
|
|
16
|
+
buildContractCall,
|
|
17
|
+
buildTokenTransfer
|
|
18
|
+
} from "../../shared/stacks-4trgpb5a.js";
|
|
19
|
+
import {
|
|
20
|
+
Cl
|
|
21
|
+
} from "../../shared/stacks-0zysn74p.js";
|
|
22
|
+
import"../../shared/stacks-xxn5ma6g.js";
|
|
23
|
+
import {
|
|
24
|
+
parseContractId
|
|
25
|
+
} from "../../shared/stacks-6xmk24yw.js";
|
|
26
|
+
import {
|
|
27
|
+
utf8ToBytes
|
|
28
|
+
} from "../../shared/stacks-2h8d2y27.js";
|
|
29
|
+
import"../../shared/stacks-cfazrteq.js";
|
|
30
|
+
|
|
31
|
+
// src/x402/build.ts
|
|
32
|
+
function buildExactTransfer(options) {
|
|
33
|
+
const { asset, amount, payTo, payer, payerPublicKey, accountNonce, chain } = options;
|
|
34
|
+
if (utf8ToBytes(options.nonce).byteLength > MEMO_MAX_LENGTH_BYTES) {
|
|
35
|
+
throw new Error(`x402 nonce exceeds the ${MEMO_MAX_LENGTH_BYTES}-byte memo budget`);
|
|
36
|
+
}
|
|
37
|
+
if (asset.kind === "stx") {
|
|
38
|
+
return buildTokenTransfer({
|
|
39
|
+
recipient: payTo,
|
|
40
|
+
amount,
|
|
41
|
+
memo: options.nonce,
|
|
42
|
+
fee: 0,
|
|
43
|
+
nonce: accountNonce,
|
|
44
|
+
publicKey: payerPublicKey,
|
|
45
|
+
chain,
|
|
46
|
+
sponsored: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const [contractAddress, contractName] = parseContractId(asset.contractId);
|
|
50
|
+
const postConditions = [
|
|
51
|
+
Pc.principal(payer).willSendEq(amount).ft(asset.contractId, asset.assetName)
|
|
52
|
+
];
|
|
53
|
+
return buildContractCall({
|
|
54
|
+
contractAddress,
|
|
55
|
+
contractName,
|
|
56
|
+
functionName: "transfer",
|
|
57
|
+
functionArgs: [
|
|
58
|
+
Cl.uint(amount),
|
|
59
|
+
Cl.principal(payer),
|
|
60
|
+
Cl.principal(payTo),
|
|
61
|
+
Cl.some(Cl.bufferFromUtf8(options.nonce))
|
|
62
|
+
],
|
|
63
|
+
fee: 0,
|
|
64
|
+
nonce: accountNonce,
|
|
65
|
+
publicKey: payerPublicKey,
|
|
66
|
+
chain,
|
|
67
|
+
postConditionMode: "deny",
|
|
68
|
+
postConditions,
|
|
69
|
+
sponsored: true
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// src/x402/settle.ts
|
|
73
|
+
async function sponsorAndBroadcast(client, signedTxHex, options = {}) {
|
|
74
|
+
const transaction = deserializeTransaction(signedTxHex);
|
|
75
|
+
const sponsored = await sponsorTransaction(client, {
|
|
76
|
+
transaction,
|
|
77
|
+
fee: options.fee,
|
|
78
|
+
nonce: options.nonce
|
|
79
|
+
});
|
|
80
|
+
return sendTransaction(client, { transaction: sponsored });
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
sponsorAndBroadcast,
|
|
84
|
+
buildExactTransfer
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//# debugId=42F79D53766B4A5064756E2164756E21
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
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 { 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};\n\nexport type SponsorAndBroadcastResult = {\n\ttxid: string;\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, { transaction: sponsored });\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;;AC9EF,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,EAAE,aAAa,UAAU,CAAC;AAAA;",
|
|
9
|
+
"debugId": "42F79D53766B4A5064756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/stacks",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -98,6 +98,11 @@
|
|
|
98
98
|
"types": "./dist/src/tools/btc/index.d.ts",
|
|
99
99
|
"import": "./dist/src/tools/btc/index.js",
|
|
100
100
|
"require": "./dist/src/tools/btc/index.cjs"
|
|
101
|
+
},
|
|
102
|
+
"./x402": {
|
|
103
|
+
"types": "./dist/src/x402/index.d.ts",
|
|
104
|
+
"import": "./dist/src/x402/index.js",
|
|
105
|
+
"require": "./dist/src/x402/index.cjs"
|
|
101
106
|
}
|
|
102
107
|
},
|
|
103
108
|
"files": [
|
|
@@ -113,6 +118,7 @@
|
|
|
113
118
|
"access": "public"
|
|
114
119
|
},
|
|
115
120
|
"devDependencies": {
|
|
121
|
+
"@stacks/transactions": "7.0.6",
|
|
116
122
|
"@types/bun": "latest"
|
|
117
123
|
},
|
|
118
124
|
"peerDependencies": {
|