@wtflabs/x402 0.0.1-beta.0 → 0.0.1-beta.2

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.
@@ -0,0 +1,533 @@
1
+ import { Address, Transport, Chain, LocalAccount, Hex, Account } from 'viem';
2
+ import { S as SignerWallet, C as ConnectedClient } from '../wallet-SJKJpUgQ.mjs';
3
+ import { P as PaymentRequirements, p as UnsignedEip3009PaymentPayload, o as Eip3009PaymentPayload, e as ExactEvmPayloadAuthorization, J as VerifyResponse, S as SettleResponse, r as UnsignedPermitPaymentPayload, q as PermitPaymentPayload, g as PermitEvmPayloadAuthorization, u as UnsignedPermit2PaymentPayload, t as Permit2PaymentPayload, i as Permit2EvmPayloadAuthorization, a as PaymentPayload, b as ErrorReasons, E as ExactSvmPayload } from '../x402Specs-CYq5tSY1.mjs';
4
+ import { X as X402Config } from '../config-Dfuvno71.mjs';
5
+ import { KeyPairSigner, signTransaction, RpcDevnet, SolanaRpcApiDevnet, RpcMainnet, SolanaRpcApiMainnet, SendTransactionApi, CompilableTransactionMessage, Instruction, AccountLookupMeta, AccountMeta } from '@solana/kit';
6
+ import { b as getRpcSubscriptions } from '../rpc-DyKXu0SX.mjs';
7
+ import * as _solana_program_token from '@solana-program/token';
8
+ import { parseTransferCheckedInstruction } from '@solana-program/token-2022';
9
+ import 'viem/chains';
10
+ import 'zod';
11
+ import '../network-FrFmmiyj.mjs';
12
+
13
+ /**
14
+ * Prepares an unsigned EIP-3009 payment header with the given sender address and payment requirements.
15
+ *
16
+ * @param from - The sender's address from which the payment will be made
17
+ * @param x402Version - The version of the X402 protocol to use
18
+ * @param paymentRequirements - The payment requirements containing scheme and network information
19
+ * @returns An unsigned EIP-3009 payment payload containing authorization details
20
+ */
21
+ declare function preparePaymentHeader$2(from: Address, x402Version: number, paymentRequirements: PaymentRequirements): UnsignedEip3009PaymentPayload;
22
+ /**
23
+ * Signs an EIP-3009 payment header using the provided client and payment requirements.
24
+ *
25
+ * @param client - The signer wallet instance used to sign the payment header
26
+ * @param paymentRequirements - The payment requirements containing scheme and network information
27
+ * @param unsignedPaymentHeader - The unsigned EIP-3009 payment payload to be signed
28
+ * @returns A promise that resolves to the signed EIP-3009 payment payload
29
+ */
30
+ declare function signPaymentHeader$2<transport extends Transport, chain extends Chain>(client: SignerWallet<chain, transport> | LocalAccount, paymentRequirements: PaymentRequirements, unsignedPaymentHeader: UnsignedEip3009PaymentPayload): Promise<Eip3009PaymentPayload>;
31
+ /**
32
+ * Creates a complete EIP-3009 payment payload by preparing and signing a payment header.
33
+ *
34
+ * @param client - The signer wallet instance used to create and sign the payment
35
+ * @param x402Version - The version of the X402 protocol to use
36
+ * @param paymentRequirements - The payment requirements containing scheme and network information
37
+ * @returns A promise that resolves to the complete signed EIP-3009 payment payload
38
+ */
39
+ declare function createPayment$2<transport extends Transport, chain extends Chain>(client: SignerWallet<chain, transport> | LocalAccount, x402Version: number, paymentRequirements: PaymentRequirements): Promise<Eip3009PaymentPayload>;
40
+ /**
41
+ * Creates and encodes an EIP-3009 payment header for the given client and payment requirements.
42
+ *
43
+ * @param client - The signer wallet instance used to create the payment header
44
+ * @param x402Version - The version of the X402 protocol to use
45
+ * @param paymentRequirements - The payment requirements containing scheme and network information
46
+ * @returns A promise that resolves to the encoded EIP-3009 payment header string
47
+ */
48
+ declare function createPaymentHeader$3(client: SignerWallet | LocalAccount, x402Version: number, paymentRequirements: PaymentRequirements): Promise<string>;
49
+
50
+ /**
51
+ * Signs an EIP-3009 authorization for USDC transfer
52
+ *
53
+ * @param walletClient - The wallet client that will sign the authorization
54
+ * @param params - The authorization parameters containing transfer details
55
+ * @param params.from - The address tokens will be transferred from
56
+ * @param params.to - The address tokens will be transferred to
57
+ * @param params.value - The amount of USDC tokens to transfer (in base units)
58
+ * @param params.validAfter - Unix timestamp after which the authorization becomes valid
59
+ * @param params.validBefore - Unix timestamp before which the authorization is valid
60
+ * @param params.nonce - Random 32-byte nonce to prevent replay attacks
61
+ * @param paymentRequirements - The payment requirements containing asset and network information
62
+ * @param paymentRequirements.asset - The address of the USDC contract
63
+ * @param paymentRequirements.network - The network where the USDC contract exists
64
+ * @param paymentRequirements.extra - The extra information containing the name and version of the ERC20 contract
65
+ * @returns The signature for the authorization
66
+ */
67
+ declare function signAuthorization<transport extends Transport, chain extends Chain>(walletClient: SignerWallet<chain, transport> | LocalAccount, { from, to, value, validAfter, validBefore, nonce }: ExactEvmPayloadAuthorization, { asset, network, extra }: PaymentRequirements): Promise<{
68
+ signature: Hex;
69
+ }>;
70
+ /**
71
+ * Generates a random 32-byte nonce for use in authorization signatures
72
+ *
73
+ * @returns A random 32-byte nonce as a hex string
74
+ */
75
+ declare function createNonce(): Hex;
76
+
77
+ /**
78
+ * Verifies an EIP-3009 payment payload against the required payment details
79
+ *
80
+ * This function performs several verification steps:
81
+ * - Verifies protocol version compatibility
82
+ * - Validates the permit signature
83
+ * - Confirms USDC contract address is correct for the chain
84
+ * - Checks permit deadline is sufficiently in the future
85
+ * - Verifies client has sufficient USDC balance
86
+ * - Ensures payment amount meets required minimum
87
+ *
88
+ * @param client - The public client used for blockchain interactions
89
+ * @param payload - The signed payment payload containing transfer parameters and signature
90
+ * @param paymentRequirements - The payment requirements that the payload must satisfy
91
+ * @returns A ValidPaymentRequest indicating if the payment is valid and any invalidation reason
92
+ */
93
+ declare function verify$4<transport extends Transport, chain extends Chain, account extends Account | undefined>(client: ConnectedClient<transport, chain, account>, payload: Eip3009PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
94
+ /**
95
+ * Settles an EIP-3009 payment by executing a USDC transferWithAuthorization transaction
96
+ *
97
+ * This function executes the actual USDC transfer using the signed authorization from the user.
98
+ * The facilitator wallet submits the transaction but does not need to hold or transfer any tokens itself.
99
+ *
100
+ * @param wallet - The facilitator wallet that will submit the transaction
101
+ * @param paymentPayload - The signed payment payload containing the transfer parameters and signature
102
+ * @param paymentRequirements - The original payment details that were used to create the payload
103
+ * @returns A PaymentExecutionResponse containing the transaction status and hash
104
+ */
105
+ declare function settle$4<transport extends Transport, chain extends Chain>(wallet: SignerWallet<chain, transport>, paymentPayload: Eip3009PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
106
+
107
+ declare const index$5_createNonce: typeof createNonce;
108
+ declare const index$5_signAuthorization: typeof signAuthorization;
109
+ declare namespace index$5 {
110
+ export { index$5_createNonce as createNonce, createPayment$2 as createPayment, createPaymentHeader$3 as createPaymentHeader, preparePaymentHeader$2 as preparePaymentHeader, settle$4 as settle, index$5_signAuthorization as signAuthorization, signPaymentHeader$2 as signPaymentHeader, verify$4 as verify };
111
+ }
112
+
113
+ /**
114
+ * Prepares an unsigned EIP-2612 Permit payment header
115
+ *
116
+ * @param from - The token owner's address
117
+ * @param x402Version - The version of the X402 protocol to use
118
+ * @param paymentRequirements - The payment requirements containing scheme and network information
119
+ * @returns An unsigned Permit payment payload containing permit authorization details
120
+ */
121
+ declare function preparePaymentHeader$1(from: Address, x402Version: number, paymentRequirements: PaymentRequirements): UnsignedPermitPaymentPayload;
122
+ /**
123
+ * Signs a Permit payment header using the provided client and payment requirements.
124
+ *
125
+ * @param client - The signer wallet instance used to sign the permit
126
+ * @param paymentRequirements - The payment requirements containing scheme and network information
127
+ * @param unsignedPaymentHeader - The unsigned Permit payment payload to be signed
128
+ * @returns A promise that resolves to the signed Permit payment payload
129
+ */
130
+ declare function signPaymentHeader$1<transport extends Transport, chain extends Chain>(client: SignerWallet<chain, transport> | LocalAccount, paymentRequirements: PaymentRequirements, unsignedPaymentHeader: UnsignedPermitPaymentPayload): Promise<PermitPaymentPayload>;
131
+ /**
132
+ * Creates a complete Permit payment payload by preparing and signing a payment header.
133
+ *
134
+ * @param client - The signer wallet instance used to create and sign the payment
135
+ * @param x402Version - The version of the X402 protocol to use
136
+ * @param paymentRequirements - The payment requirements containing scheme and network information
137
+ * @returns A promise that resolves to the complete signed Permit payment payload
138
+ */
139
+ declare function createPayment$1<transport extends Transport, chain extends Chain>(client: SignerWallet<chain, transport> | LocalAccount, x402Version: number, paymentRequirements: PaymentRequirements): Promise<PermitPaymentPayload>;
140
+ /**
141
+ * Creates and encodes a Permit payment header for the given client and payment requirements.
142
+ *
143
+ * @param client - The signer wallet instance used to create the payment header
144
+ * @param x402Version - The version of the X402 protocol to use
145
+ * @param paymentRequirements - The payment requirements containing scheme and network information
146
+ * @returns A promise that resolves to the encoded payment header string
147
+ */
148
+ declare function createPaymentHeader$2(client: SignerWallet | LocalAccount, x402Version: number, paymentRequirements: PaymentRequirements): Promise<string>;
149
+
150
+ /**
151
+ * Signs an EIP-2612 Permit authorization for ERC20 approval
152
+ *
153
+ * @param walletClient - The wallet client that will sign the permit
154
+ * @param params - The permit parameters
155
+ * @param params.owner - The address of the token owner
156
+ * @param params.spender - The address authorized to spend tokens
157
+ * @param params.value - The amount of tokens to approve (in base units)
158
+ * @param params.deadline - Unix timestamp after which the permit is no longer valid
159
+ * @param paymentRequirements - The payment requirements containing asset and network information
160
+ * @param paymentRequirements.asset - The address of the ERC20 token contract
161
+ * @param paymentRequirements.network - The network where the token exists
162
+ * @returns The signature and nonce for the permit
163
+ */
164
+ declare function signPermit<transport extends Transport, chain extends Chain>(walletClient: SignerWallet<chain, transport> | LocalAccount, { owner, spender, value, deadline }: Omit<PermitEvmPayloadAuthorization, "nonce">, { asset, network }: PaymentRequirements): Promise<{
165
+ signature: Hex;
166
+ nonce: string;
167
+ }>;
168
+ /**
169
+ * Helper function to split signature into v, r, s components
170
+ * Required for calling the permit function on-chain
171
+ *
172
+ * @param signature - The signature to split
173
+ * @returns The v, r, s components of the signature
174
+ */
175
+ declare function splitSignature(signature: Hex): {
176
+ v: number;
177
+ r: Hex;
178
+ s: Hex;
179
+ };
180
+
181
+ /**
182
+ * Verifies an EIP-2612 Permit payment payload
183
+ *
184
+ * @param client - The public client used for blockchain interactions
185
+ * @param payload - The signed payment payload containing permit parameters and signature
186
+ * @param paymentRequirements - The payment requirements that the payload must satisfy
187
+ * @returns A VerifyResponse indicating if the payment is valid and any invalidation reason
188
+ */
189
+ declare function verify$3<transport extends Transport, chain extends Chain, account extends Account | undefined>(client: ConnectedClient<transport, chain, account>, payload: PermitPaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
190
+ /**
191
+ * Settles an EIP-2612 Permit payment by calling permit() then transferFrom()
192
+ *
193
+ * @param wallet - The facilitator wallet that will execute the permit and transfer
194
+ * @param paymentPayload - The signed payment payload containing permit parameters and signature
195
+ * @param paymentRequirements - The payment requirements
196
+ * @returns A SettleResponse containing the transaction status and hash
197
+ */
198
+ declare function settle$3<transport extends Transport, chain extends Chain>(wallet: SignerWallet<chain, transport>, paymentPayload: PermitPaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
199
+
200
+ declare const index$4_signPermit: typeof signPermit;
201
+ declare const index$4_splitSignature: typeof splitSignature;
202
+ declare namespace index$4 {
203
+ export { createPayment$1 as createPayment, createPaymentHeader$2 as createPaymentHeader, preparePaymentHeader$1 as preparePaymentHeader, settle$3 as settle, signPaymentHeader$1 as signPaymentHeader, index$4_signPermit as signPermit, index$4_splitSignature as splitSignature, verify$3 as verify };
204
+ }
205
+
206
+ /**
207
+ * Prepares an unsigned Permit2 payment header
208
+ *
209
+ * @param from - The token owner's address
210
+ * @param x402Version - The version of the X402 protocol to use
211
+ * @param paymentRequirements - The payment requirements containing scheme and network information
212
+ * @returns An unsigned Permit2 payment payload containing permit2 authorization details
213
+ */
214
+ declare function preparePaymentHeader(from: Address, x402Version: number, paymentRequirements: PaymentRequirements): UnsignedPermit2PaymentPayload;
215
+ /**
216
+ * Signs a Permit2 payment header using the provided client and payment requirements.
217
+ *
218
+ * @param client - The signer wallet instance used to sign the permit2
219
+ * @param paymentRequirements - The payment requirements containing scheme and network information
220
+ * @param unsignedPaymentHeader - The unsigned Permit2 payment payload to be signed
221
+ * @returns A promise that resolves to the signed Permit2 payment payload
222
+ */
223
+ declare function signPaymentHeader<transport extends Transport, chain extends Chain>(client: SignerWallet<chain, transport> | LocalAccount, paymentRequirements: PaymentRequirements, unsignedPaymentHeader: UnsignedPermit2PaymentPayload): Promise<Permit2PaymentPayload>;
224
+ /**
225
+ * Creates a complete Permit2 payment payload by preparing and signing a payment header.
226
+ *
227
+ * @param client - The signer wallet instance used to create and sign the payment
228
+ * @param x402Version - The version of the X402 protocol to use
229
+ * @param paymentRequirements - The payment requirements containing scheme and network information
230
+ * @returns A promise that resolves to the complete signed Permit2 payment payload
231
+ */
232
+ declare function createPayment<transport extends Transport, chain extends Chain>(client: SignerWallet<chain, transport> | LocalAccount, x402Version: number, paymentRequirements: PaymentRequirements): Promise<Permit2PaymentPayload>;
233
+ /**
234
+ * Creates and encodes a Permit2 payment header for the given client and payment requirements.
235
+ *
236
+ * @param client - The signer wallet instance used to create the payment header
237
+ * @param x402Version - The version of the X402 protocol to use
238
+ * @param paymentRequirements - The payment requirements containing scheme and network information
239
+ * @returns A promise that resolves to the encoded payment header string
240
+ */
241
+ declare function createPaymentHeader$1(client: SignerWallet | LocalAccount, x402Version: number, paymentRequirements: PaymentRequirements): Promise<string>;
242
+
243
+ /**
244
+ * Signs a Permit2 PermitTransferFrom authorization
245
+ *
246
+ * @param walletClient - The wallet client that will sign the permit
247
+ * @param params - The permit2 parameters
248
+ * @param params.owner - The address of the token owner
249
+ * @param params.spender - The address authorized to transfer tokens
250
+ * @param params.token - The address of the token to transfer
251
+ * @param params.amount - The amount of tokens to transfer (in base units)
252
+ * @param params.deadline - Unix timestamp after which the permit is no longer valid
253
+ * @param paymentRequirements - The payment requirements containing network information
254
+ * @param paymentRequirements.network - The network where the token exists
255
+ * @returns The signature and nonce for the permit2
256
+ */
257
+ declare function signPermit2<transport extends Transport, chain extends Chain>(walletClient: SignerWallet<chain, transport> | LocalAccount, { owner, spender, token, amount, deadline }: Omit<Permit2EvmPayloadAuthorization, "nonce">, { network }: PaymentRequirements): Promise<{
258
+ signature: Hex;
259
+ nonce: string;
260
+ }>;
261
+ /**
262
+ * Generates a unique nonce for Permit2 SignatureTransfer
263
+ * Uses timestamp-based approach with nonceBitmap verification
264
+ *
265
+ * @param walletClient - The wallet client used to check nonce bitmap
266
+ * @param ownerAddress - The address of the token owner
267
+ * @returns A unique nonce for the permit2 authorization
268
+ */
269
+ declare function createPermit2Nonce<transport extends Transport, chain extends Chain>(walletClient: SignerWallet<chain, transport> | LocalAccount, ownerAddress: `0x${string}`): Promise<bigint>;
270
+
271
+ /**
272
+ * Verifies a Permit2 payment payload
273
+ *
274
+ * @param client - The public client used for blockchain interactions
275
+ * @param payload - The signed payment payload containing permit2 parameters and signature
276
+ * @param paymentRequirements - The payment requirements that the payload must satisfy
277
+ * @returns A VerifyResponse indicating if the payment is valid and any invalidation reason
278
+ */
279
+ declare function verify$2<transport extends Transport, chain extends Chain, account extends Account | undefined>(client: ConnectedClient<transport, chain, account>, payload: Permit2PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
280
+ /**
281
+ * Settles a Permit2 payment by calling permitTransferFrom()
282
+ *
283
+ * @param wallet - The facilitator wallet that will execute the permit transfer
284
+ * @param paymentPayload - The signed payment payload containing permit2 parameters and signature
285
+ * @param paymentRequirements - The payment requirements
286
+ * @returns A SettleResponse containing the transaction status and hash
287
+ */
288
+ declare function settle$2<transport extends Transport, chain extends Chain>(wallet: SignerWallet<chain, transport>, paymentPayload: Permit2PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
289
+
290
+ declare const index$3_createPayment: typeof createPayment;
291
+ declare const index$3_createPermit2Nonce: typeof createPermit2Nonce;
292
+ declare const index$3_preparePaymentHeader: typeof preparePaymentHeader;
293
+ declare const index$3_signPaymentHeader: typeof signPaymentHeader;
294
+ declare const index$3_signPermit2: typeof signPermit2;
295
+ declare namespace index$3 {
296
+ export { index$3_createPayment as createPayment, createPaymentHeader$1 as createPaymentHeader, index$3_createPermit2Nonce as createPermit2Nonce, index$3_preparePaymentHeader as preparePaymentHeader, settle$2 as settle, index$3_signPaymentHeader as signPaymentHeader, index$3_signPermit2 as signPermit2, verify$2 as verify };
297
+ }
298
+
299
+ /**
300
+ * Encodes a payment payload into a base64 string, ensuring bigint values are properly stringified
301
+ *
302
+ * @param payment - The payment payload to encode
303
+ * @returns A base64 encoded string representation of the payment payload
304
+ */
305
+ declare function encodePayment(payment: PaymentPayload): string;
306
+ /**
307
+ * Decodes a base64 encoded payment string back into a PaymentPayload object
308
+ *
309
+ * @param payment - The base64 encoded payment string to decode
310
+ * @returns The decoded and validated PaymentPayload object
311
+ */
312
+ declare function decodePayment(payment: string): PaymentPayload;
313
+
314
+ /**
315
+ * Unified verify function that routes to the appropriate authorization type handler
316
+ *
317
+ * @param client - The public client used for blockchain interactions
318
+ * @param payload - The signed payment payload
319
+ * @param paymentRequirements - The payment requirements that the payload must satisfy
320
+ * @returns A VerifyResponse indicating if the payment is valid
321
+ */
322
+ declare function verify$1<transport extends Transport, chain extends Chain, account extends Account | undefined>(client: ConnectedClient<transport, chain, account>, payload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
323
+ /**
324
+ * Unified settle function that routes to the appropriate authorization type handler
325
+ *
326
+ * @param wallet - The facilitator wallet that will execute the transaction
327
+ * @param paymentPayload - The signed payment payload
328
+ * @param paymentRequirements - The payment requirements
329
+ * @returns A SettleResponse containing the transaction status and hash
330
+ */
331
+ declare function settle$1<transport extends Transport, chain extends Chain>(wallet: SignerWallet<chain, transport>, paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
332
+
333
+ declare const index$2_decodePayment: typeof decodePayment;
334
+ declare const index$2_encodePayment: typeof encodePayment;
335
+ declare namespace index$2 {
336
+ export { index$2_decodePayment as decodePayment, index$5 as eip3009, index$2_encodePayment as encodePayment, index$4 as permit, index$3 as permit2, settle$1 as settle, verify$1 as verify };
337
+ }
338
+
339
+ /**
340
+ * Settle the payment payload against the payment requirements.
341
+ * TODO: handle durable nonce lifetime transactions
342
+ *
343
+ * @param signer - The signer that will sign the transaction
344
+ * @param payload - The payment payload to settle
345
+ * @param paymentRequirements - The payment requirements to settle against
346
+ * @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
347
+ * @returns A SettleResponse indicating if the payment is settled and any error reason
348
+ */
349
+ declare function settle(signer: KeyPairSigner, payload: PaymentPayload, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<SettleResponse>;
350
+ /**
351
+ * Send a signed transaction to the RPC.
352
+ * TODO: should this be moved to the shared/svm/rpc.ts file?
353
+ *
354
+ * @param signedTransaction - The signed transaction to send
355
+ * @param rpc - The RPC client to use to send the transaction
356
+ * @param sendTxConfig - The configuration for the transaction send
357
+ * @returns The signature of the sent transaction
358
+ */
359
+ declare function sendSignedTransaction(signedTransaction: Awaited<ReturnType<typeof signTransaction>>, rpc: RpcDevnet<SolanaRpcApiDevnet> | RpcMainnet<SolanaRpcApiMainnet>, sendTxConfig?: Parameters<SendTransactionApi["sendTransaction"]>[1]): Promise<string>;
360
+ /**
361
+ * Confirm a signed transaction.
362
+ * TODO: can some of this be refactored to be moved to the shared/svm/rpc.ts file?
363
+ * TODO: should the commitment and the timeout be passed in as parameters?
364
+ *
365
+ * @param signedTransaction - The signed transaction to confirm
366
+ * @param rpc - The RPC client to use to confirm the transaction
367
+ * @param rpcSubscriptions - The RPC subscriptions to use to confirm the transaction
368
+ * @returns The success and signature of the confirmed transaction
369
+ */
370
+ declare function confirmSignedTransaction(signedTransaction: Awaited<ReturnType<typeof signTransaction>>, rpc: RpcDevnet<SolanaRpcApiDevnet> | RpcMainnet<SolanaRpcApiMainnet>, rpcSubscriptions: ReturnType<typeof getRpcSubscriptions>): Promise<{
371
+ success: boolean;
372
+ errorReason?: (typeof ErrorReasons)[number];
373
+ signature: string;
374
+ }>;
375
+ /**
376
+ * Send and confirm a signed transaction.
377
+ *
378
+ * @param signedTransaction - The signed transaction to send and confirm
379
+ * @param rpc - The RPC client to use to send and confirm the transaction
380
+ * @param rpcSubscriptions - The RPC subscriptions to use to send and confirm the transaction
381
+ * @returns The success and signature of the confirmed transaction
382
+ */
383
+ declare function sendAndConfirmSignedTransaction(signedTransaction: Awaited<ReturnType<typeof signTransaction>>, rpc: RpcDevnet<SolanaRpcApiDevnet> | RpcMainnet<SolanaRpcApiMainnet>, rpcSubscriptions: ReturnType<typeof getRpcSubscriptions>): Promise<{
384
+ success: boolean;
385
+ errorReason?: (typeof ErrorReasons)[number];
386
+ signature: string;
387
+ }>;
388
+
389
+ /**
390
+ * Verify the payment payload against the payment requirements.
391
+ *
392
+ * @param signer - The signer that will sign and simulate the transaction
393
+ * @param payload - The payment payload to verify
394
+ * @param paymentRequirements - The payment requirements to verify against
395
+ * @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
396
+ * @returns A VerifyResponse indicating if the payment is valid and any invalidation reason
397
+ */
398
+ declare function verify(signer: KeyPairSigner, payload: PaymentPayload, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<VerifyResponse>;
399
+ /**
400
+ * Verify that the scheme and network are supported.
401
+ *
402
+ * @param payload - The payment payload to verify
403
+ * @param paymentRequirements - The payment requirements to verify against
404
+ */
405
+ declare function verifySchemesAndNetworks(payload: PaymentPayload, paymentRequirements: PaymentRequirements): void;
406
+ /**
407
+ * Perform transaction introspection to validate the transaction structure and transfer details.
408
+ * This function handles decoding the transaction, validating the transfer instruction,
409
+ * and verifying all transfer details against the payment requirements.
410
+ *
411
+ * @param svmPayload - The SVM payload containing the transaction
412
+ * @param paymentRequirements - The payment requirements to verify against
413
+ * @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
414
+ */
415
+ declare function transactionIntrospection(svmPayload: ExactSvmPayload, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<void>;
416
+ /**
417
+ * Verify that the transaction contains the expected instructions.
418
+ *
419
+ * @param transactionMessage - The transaction message to verify
420
+ * @param paymentRequirements - The payment requirements to verify against
421
+ * @param rpc - The RPC client to use for verifying account existence
422
+ * @throws Error if the transaction does not contain the expected instructions
423
+ */
424
+ declare function verifyTransactionInstructions(transactionMessage: CompilableTransactionMessage, paymentRequirements: PaymentRequirements, rpc: RpcDevnet<SolanaRpcApiDevnet> | RpcMainnet<SolanaRpcApiMainnet>): Promise<void>;
425
+ /**
426
+ * Verify that the compute limit instruction is valid.
427
+ *
428
+ * @param instruction - The compute limit instruction to verify
429
+ * @throws Error if the compute limit instruction is invalid
430
+ */
431
+ declare function verifyComputeLimitInstruction(instruction: Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>): void;
432
+ /**
433
+ * Verify that the compute price instruction is valid.
434
+ * This function throws an error if the compute unit price is greater than 5 lamports,
435
+ * to protect the facilitator against gas fee abuse from the client.
436
+ *
437
+ * @param instruction - The compute price instruction to verify
438
+ * @throws Error if the compute price instruction is invalid
439
+ */
440
+ declare function verifyComputePriceInstruction(instruction: Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>): void;
441
+ /**
442
+ * Verify that the create ATA instruction is valid.
443
+ *
444
+ * @param instruction - The create ATA instruction to verify
445
+ * @param paymentRequirements - The payment requirements to verify against
446
+ * @throws Error if the create ATA instruction is invalid
447
+ */
448
+ declare function verifyCreateATAInstruction(instruction: Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>, paymentRequirements: PaymentRequirements): void;
449
+ /**
450
+ * Verify that the transfer instruction is valid.
451
+ *
452
+ * @param instruction - The transfer instruction to verify
453
+ * @param paymentRequirements - The payment requirements to verify against
454
+ * @param {object} options - The options for the verification of the transfer instruction
455
+ * @param {boolean} options.txHasCreateDestATAInstruction - Whether the transaction has a create destination ATA instruction
456
+ * @param rpc - The RPC client to use for verifying account existence
457
+ * @throws Error if the transfer instruction is invalid
458
+ */
459
+ declare function verifyTransferInstruction(instruction: Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>, paymentRequirements: PaymentRequirements, { txHasCreateDestATAInstruction }: {
460
+ txHasCreateDestATAInstruction: boolean;
461
+ }, rpc: RpcDevnet<SolanaRpcApiDevnet> | RpcMainnet<SolanaRpcApiMainnet>): Promise<void>;
462
+ /**
463
+ * Verify that the transfer checked instruction is valid.
464
+ *
465
+ * @param parsedInstruction - The parsed transfer checked instruction to verify
466
+ * @param paymentRequirements - The payment requirements to verify against
467
+ * @param {object} options - The options for the verification of the transfer checked instruction
468
+ * @param {boolean} options.txHasCreateDestATAInstruction - Whether the transaction has a create destination ATA instruction
469
+ * @param rpc - The RPC client to use for verifying account existence
470
+ * @throws Error if the transfer checked instruction is invalid
471
+ */
472
+ declare function verifyTransferCheckedInstruction(parsedInstruction: ReturnType<typeof parseTransferCheckedInstruction>, paymentRequirements: PaymentRequirements, { txHasCreateDestATAInstruction }: {
473
+ txHasCreateDestATAInstruction: boolean;
474
+ }, rpc: RpcDevnet<SolanaRpcApiDevnet> | RpcMainnet<SolanaRpcApiMainnet>): Promise<void>;
475
+ /**
476
+ * Inspect the decompiled transaction message to make sure that it is a valid
477
+ * transfer instruction.
478
+ *
479
+ * @param instruction - The instruction to get the transfer instruction from
480
+ * @returns The validated transfer instruction
481
+ * @throws Error if the instruction is not a valid transfer checked instruction
482
+ */
483
+ declare function getValidatedTransferCheckedInstruction(instruction: Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>): _solana_program_token.ParsedTransferCheckedInstruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>;
484
+
485
+ /**
486
+ * Creates and encodes a payment header for the given client and payment requirements.
487
+ *
488
+ * @param client - The signer instance used to create the payment header
489
+ * @param x402Version - The version of the X402 protocol to use
490
+ * @param paymentRequirements - The payment requirements containing scheme and network information
491
+ * @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
492
+ * @returns A promise that resolves to a base64 encoded payment header string
493
+ */
494
+ declare function createPaymentHeader(client: KeyPairSigner, x402Version: number, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<string>;
495
+ /**
496
+ * Creates and signs a payment for the given client and payment requirements.
497
+ *
498
+ * @param client - The signer instance used to create and sign the payment tx
499
+ * @param x402Version - The version of the X402 protocol to use
500
+ * @param paymentRequirements - The payment requirements
501
+ * @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
502
+ * @returns A promise that resolves to a payment payload containing a base64 encoded solana token transfer tx
503
+ */
504
+ declare function createAndSignPayment(client: KeyPairSigner, x402Version: number, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<PaymentPayload>;
505
+
506
+ declare const index$1_confirmSignedTransaction: typeof confirmSignedTransaction;
507
+ declare const index$1_createAndSignPayment: typeof createAndSignPayment;
508
+ declare const index$1_createPaymentHeader: typeof createPaymentHeader;
509
+ declare const index$1_getValidatedTransferCheckedInstruction: typeof getValidatedTransferCheckedInstruction;
510
+ declare const index$1_sendAndConfirmSignedTransaction: typeof sendAndConfirmSignedTransaction;
511
+ declare const index$1_sendSignedTransaction: typeof sendSignedTransaction;
512
+ declare const index$1_settle: typeof settle;
513
+ declare const index$1_transactionIntrospection: typeof transactionIntrospection;
514
+ declare const index$1_verify: typeof verify;
515
+ declare const index$1_verifyComputeLimitInstruction: typeof verifyComputeLimitInstruction;
516
+ declare const index$1_verifyComputePriceInstruction: typeof verifyComputePriceInstruction;
517
+ declare const index$1_verifyCreateATAInstruction: typeof verifyCreateATAInstruction;
518
+ declare const index$1_verifySchemesAndNetworks: typeof verifySchemesAndNetworks;
519
+ declare const index$1_verifyTransactionInstructions: typeof verifyTransactionInstructions;
520
+ declare const index$1_verifyTransferCheckedInstruction: typeof verifyTransferCheckedInstruction;
521
+ declare const index$1_verifyTransferInstruction: typeof verifyTransferInstruction;
522
+ declare namespace index$1 {
523
+ export { index$1_confirmSignedTransaction as confirmSignedTransaction, index$1_createAndSignPayment as createAndSignPayment, index$1_createPaymentHeader as createPaymentHeader, index$1_getValidatedTransferCheckedInstruction as getValidatedTransferCheckedInstruction, index$1_sendAndConfirmSignedTransaction as sendAndConfirmSignedTransaction, index$1_sendSignedTransaction as sendSignedTransaction, index$1_settle as settle, index$1_transactionIntrospection as transactionIntrospection, index$1_verify as verify, index$1_verifyComputeLimitInstruction as verifyComputeLimitInstruction, index$1_verifyComputePriceInstruction as verifyComputePriceInstruction, index$1_verifyCreateATAInstruction as verifyCreateATAInstruction, index$1_verifySchemesAndNetworks as verifySchemesAndNetworks, index$1_verifyTransactionInstructions as verifyTransactionInstructions, index$1_verifyTransferCheckedInstruction as verifyTransferCheckedInstruction, index$1_verifyTransferInstruction as verifyTransferInstruction };
524
+ }
525
+
526
+ declare const SCHEME = "exact";
527
+
528
+ declare const index_SCHEME: typeof SCHEME;
529
+ declare namespace index {
530
+ export { index_SCHEME as SCHEME, index$2 as evm, index$1 as svm };
531
+ }
532
+
533
+ export { decodePayment, encodePayment, index as exact };
@@ -0,0 +1,71 @@
1
+ import { Transport, Chain, Account, Client, Address } from 'viem';
2
+ import { C as ChainConfig } from '../../config-CFBSAuxW.mjs';
3
+ import { C as ConnectedClient } from '../../wallet-SJKJpUgQ.mjs';
4
+ import '@solana/kit';
5
+ import 'viem/chains';
6
+
7
+ /**
8
+ * Gets the USDC contract address for the current chain from the client
9
+ *
10
+ * @param client - The Viem client instance connected to the blockchain
11
+ * @returns The USDC contract address for the current chain
12
+ */
13
+ declare function getUsdcAddress<transport extends Transport, chain extends Chain | undefined = undefined, account extends Account | undefined = undefined>(client: Client<transport, chain, account>): Address;
14
+ /**
15
+ * Gets the USDC contract address for a specific chain ID
16
+ *
17
+ * @deprecated Use `getUsdcChainConfigForChain` instead
18
+ * @param chainId - The chain ID to get the USDC contract address for
19
+ * @returns The USDC contract address for the specified chain
20
+ */
21
+ declare function getUsdcAddressForChain(chainId: number): Address;
22
+ /**
23
+ * Gets the USDC address and eip712 domain name for a specific chain ID
24
+ *
25
+ * @param chainId - The chain ID
26
+ * @returns The USDC contract address and eip712 domain name for the specified chain
27
+ */
28
+ declare function getUsdcChainConfigForChain(chainId: number): ChainConfig | undefined;
29
+ /**
30
+ * Gets the version of an ERC20 Permit contract, using a cache to avoid repeated calls
31
+ *
32
+ * Priority order:
33
+ * 1. Try eip712Domain() (EIP-5267, OpenZeppelin v5+)
34
+ * 2. Fallback to version() function (OpenZeppelin v4)
35
+ * 3. Default to "1" if neither is available
36
+ *
37
+ * @param client - The Viem client instance connected to the blockchain
38
+ * @param tokenAddress - Optional token address. If not provided, uses USDC address
39
+ * @returns A promise that resolves to the ERC20 contract version string
40
+ */
41
+ declare function getVersion<transport extends Transport, chain extends Chain, account extends Account | undefined = undefined>(client: ConnectedClient<transport, chain, account>, tokenAddress?: Address): Promise<string>;
42
+ /**
43
+ * Gets the USDC balance for a specific address
44
+ *
45
+ * @param client - The Viem client instance connected to the blockchain
46
+ * @param address - The address to check the USDC balance for
47
+ * @returns A promise that resolves to the USDC balance as a bigint
48
+ */
49
+ declare function getUSDCBalance<transport extends Transport, chain extends Chain, account extends Account | undefined = undefined>(client: ConnectedClient<transport, chain, account>, address: Address): Promise<bigint>;
50
+
51
+ /**
52
+ * Gets the USDC balance for a specific address
53
+ *
54
+ * @param client - The Viem client instance connected to the blockchain
55
+ * @param erc20Address - The address of the ERC20 contract
56
+ * @param address - The address to check the USDC balance for
57
+ * @returns A promise that resolves to the USDC balance as a bigint
58
+ */
59
+ declare function getERC20Balance<transport extends Transport, chain extends Chain, account extends Account | undefined = undefined>(client: ConnectedClient<transport, chain, account>, erc20Address: Address, address: Address): Promise<bigint>;
60
+ /**
61
+ * Gets the ERC20 allowance for a spender
62
+ *
63
+ * @param client - The Viem client instance connected to the blockchain
64
+ * @param erc20Address - The address of the ERC20 contract
65
+ * @param owner - The address of the token owner
66
+ * @param spender - The address of the spender
67
+ * @returns A promise that resolves to the allowance as a bigint
68
+ */
69
+ declare function getERC20Allowance<transport extends Transport, chain extends Chain, account extends Account | undefined = undefined>(client: ConnectedClient<transport, chain, account>, erc20Address: Address, owner: Address, spender: Address): Promise<bigint>;
70
+
71
+ export { getERC20Allowance, getERC20Balance, getUSDCBalance, getUsdcAddress, getUsdcAddressForChain, getUsdcChainConfigForChain, getVersion };