@dexterai/x402 6.0.0-rc.4 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/README.md +5 -1
- package/REFERENCE.md +33 -3
- package/dist/adapters/index.d.cts +3 -2
- package/dist/adapters/index.d.ts +3 -2
- package/dist/batch-settlement/index.cjs +1 -1
- package/dist/batch-settlement/index.d.cts +4 -3
- package/dist/batch-settlement/index.d.ts +4 -3
- package/dist/batch-settlement/index.js +1 -1
- package/dist/batch-settlement/seller/index.cjs +1 -1
- package/dist/batch-settlement/seller/index.d.cts +5 -4
- package/dist/batch-settlement/seller/index.d.ts +5 -4
- package/dist/batch-settlement/seller/index.js +1 -1
- package/dist/client/index.d.cts +5 -3
- package/dist/client/index.d.ts +5 -3
- package/dist/mcp/index.cjs +1 -0
- package/dist/mcp/index.d.cts +183 -0
- package/dist/mcp/index.d.ts +183 -0
- package/dist/mcp/index.js +1 -0
- package/dist/react/index.d.cts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.d.cts +5 -4
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.js +1 -1
- package/dist/tab/adapters/solana/index.cjs +1 -1
- package/dist/tab/adapters/solana/index.d.cts +3 -2
- package/dist/tab/adapters/solana/index.d.ts +3 -2
- package/dist/tab/adapters/solana/index.js +1 -1
- package/dist/tab/index.cjs +4 -4
- package/dist/tab/index.d.cts +3 -2
- package/dist/tab/index.d.ts +3 -2
- package/dist/tab/index.js +1 -1
- package/dist/tab/seller/index.cjs +7 -7
- package/dist/tab/seller/index.js +1 -1
- package/dist/{types-CHQzNDR6.d.ts → types-BvK5UjA9.d.ts} +1 -1
- package/dist/{types-BvQpNtFw.d.cts → types-C08JT9MG.d.ts} +2 -236
- package/dist/{types-CkcNYx1Q.d.ts → types-C6IbRTpi.d.ts} +1 -1
- package/dist/{types-BvQpNtFw.d.ts → types-CRs5sEcb.d.cts} +2 -236
- package/dist/{types-CBQKKFxJ.d.cts → types-Cyyl3Cw_.d.cts} +1 -1
- package/dist/{types-DwVhPqOZ.d.ts → types-DGVtb7cl.d.cts} +4 -2
- package/dist/{types-BbvuPNXl.d.cts → types-DjDjuUc6.d.ts} +4 -2
- package/dist/types-DolSK-3d.d.cts +237 -0
- package/dist/types-DolSK-3d.d.ts +237 -0
- package/dist/{types-JpkrtFbZ.d.cts → types-RauRuMb7.d.cts} +1 -1
- package/docs/mcp.md +98 -0
- package/examples/mcp-paid-tool.ts +39 -0
- package/package.json +16 -10
|
@@ -1,238 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* x402 v2 SDK — Shared Types
|
|
3
|
-
*
|
|
4
|
-
* Chain-agnostic types for x402 v2 payments.
|
|
5
|
-
* Works with Solana, Base, and any future x402-compatible networks.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Context passed to a PayToProvider function.
|
|
10
|
-
* Contains request-scoped information for dynamic address resolution.
|
|
11
|
-
*/
|
|
12
|
-
interface PayToContext {
|
|
13
|
-
/** The PAYMENT-SIGNATURE header value (present on retry/verify, undefined on initial 402) */
|
|
14
|
-
paymentHeader?: string;
|
|
15
|
-
/** Amount in atomic units (e.g., '10000' for 0.01 USDC) */
|
|
16
|
-
amountAtomic?: string;
|
|
17
|
-
/** The resource URL being accessed */
|
|
18
|
-
resourceUrl?: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Optional defaults a PayToProvider can advertise for auto-configuration.
|
|
22
|
-
* Attached as `_x402Defaults` on the provider function.
|
|
23
|
-
*/
|
|
24
|
-
interface PayToProviderDefaults {
|
|
25
|
-
/** Default CAIP-2 network (e.g., 'eip155:8453' for Base) */
|
|
26
|
-
network?: string;
|
|
27
|
-
/** Default facilitator URL */
|
|
28
|
-
facilitatorUrl?: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* A function that dynamically resolves a payment address.
|
|
32
|
-
* Used for providers like Stripe that generate per-request deposit addresses.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* import { stripePayTo } from '@dexterai/x402/server';
|
|
37
|
-
*
|
|
38
|
-
* const provider = stripePayTo(process.env.STRIPE_SECRET_KEY);
|
|
39
|
-
* const address = await provider({ amountAtomic: '10000' });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
type PayToProvider = ((context: PayToContext) => Promise<string>) & {
|
|
43
|
-
/** Auto-configuration defaults (set by provider factories like stripePayTo) */
|
|
44
|
-
_x402Defaults?: PayToProviderDefaults;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Resource info included in payment requirements
|
|
48
|
-
*/
|
|
49
|
-
interface ResourceInfo {
|
|
50
|
-
/** Resource URL */
|
|
51
|
-
url: string;
|
|
52
|
-
/** Human-readable description */
|
|
53
|
-
description?: string;
|
|
54
|
-
/** MIME type of the resource */
|
|
55
|
-
mimeType?: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Extra fields in payment requirements
|
|
59
|
-
* Chain-specific fields may vary
|
|
60
|
-
*/
|
|
61
|
-
interface AcceptsExtra {
|
|
62
|
-
/** Facilitator address that pays tx fees (required for Solana) */
|
|
63
|
-
feePayer?: string;
|
|
64
|
-
/** Token decimals (optional - defaults to 6 for USDC) */
|
|
65
|
-
decimals?: number;
|
|
66
|
-
/** EIP-712: Token name (EVM only) */
|
|
67
|
-
name?: string;
|
|
68
|
-
/** EIP-712: Token version (EVM only) */
|
|
69
|
-
version?: string;
|
|
70
|
-
/**
|
|
71
|
-
* batch-settlement: on-chain authorizer that the escrow channel pays into.
|
|
72
|
-
* Provided by the facilitator's batch-settlement kind. EVM only.
|
|
73
|
-
*/
|
|
74
|
-
receiverAuthorizer?: string;
|
|
75
|
-
/** Tab seller-wire header advertised by the default hosted scheme. */
|
|
76
|
-
voucherHeader?: string;
|
|
77
|
-
/** Tab registration encoding carried inside each seller voucher. */
|
|
78
|
-
registrationEncoding?: string;
|
|
79
|
-
/** Immutable commercial-terms version for this Tab offer. */
|
|
80
|
-
termsVersion?: string;
|
|
81
|
-
/** Event that makes usage accepted under the advertised terms version. */
|
|
82
|
-
acceptanceRule?: string;
|
|
83
|
-
/** Additional chain-specific fields */
|
|
84
|
-
[key: string]: unknown;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* A single payment option in the accepts array
|
|
88
|
-
*/
|
|
89
|
-
interface PaymentAccept {
|
|
90
|
-
/** x402 version (1 or 2, defaults to 2 if not specified) */
|
|
91
|
-
x402Version?: 1 | 2;
|
|
92
|
-
/**
|
|
93
|
-
* Payment scheme: 'exact' for EIP-3009 chains, 'exact-approval' for
|
|
94
|
-
* approval-based chains like BSC, 'batch-settlement' for the EVM
|
|
95
|
-
* escrow-channel batching scheme (discrete API purchases, gas-amortized),
|
|
96
|
-
* 'tab' (SVM only) for streaming session-key vouchers against an
|
|
97
|
-
* on-chain vault.
|
|
98
|
-
*/
|
|
99
|
-
scheme: 'exact' | 'exact-approval' | 'batch-settlement' | 'tab';
|
|
100
|
-
/** CAIP-2 network identifier (v1: 'solana', v2: 'solana:5eykt...') */
|
|
101
|
-
network: string;
|
|
102
|
-
/** Payment amount in atomic units (x402 v2 spec field) */
|
|
103
|
-
amount: string;
|
|
104
|
-
/** @deprecated v1 field — use `amount` instead. Kept for backwards compatibility with v1 data. */
|
|
105
|
-
maxAmountRequired?: string;
|
|
106
|
-
/** Token address */
|
|
107
|
-
asset: string;
|
|
108
|
-
/** Seller's address to receive payment */
|
|
109
|
-
payTo: string;
|
|
110
|
-
/** Maximum seconds until payment expires */
|
|
111
|
-
maxTimeoutSeconds: number;
|
|
112
|
-
/** Chain-specific extra data */
|
|
113
|
-
extra?: AcceptsExtra;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Full PaymentRequired structure (sent in PAYMENT-REQUIRED header)
|
|
117
|
-
*/
|
|
118
|
-
interface PaymentRequired {
|
|
119
|
-
/** x402 version (always 2) */
|
|
120
|
-
x402Version: 2;
|
|
121
|
-
/** Resource being accessed */
|
|
122
|
-
resource: ResourceInfo;
|
|
123
|
-
/** Available payment options */
|
|
124
|
-
accepts: PaymentAccept[];
|
|
125
|
-
/** Optional error message */
|
|
126
|
-
error?: string;
|
|
127
|
-
/** Protocol extensions */
|
|
128
|
-
extensions?: Record<string, unknown>;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Response from /verify endpoint
|
|
132
|
-
*/
|
|
133
|
-
interface VerifyResponse {
|
|
134
|
-
/** Whether the payment is valid */
|
|
135
|
-
isValid: boolean;
|
|
136
|
-
/** Reason for invalidity (if invalid) */
|
|
137
|
-
invalidReason?: string;
|
|
138
|
-
/** Payer address */
|
|
139
|
-
payer?: string;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Response from /settle endpoint
|
|
143
|
-
*/
|
|
144
|
-
interface SettleResponse {
|
|
145
|
-
/** Whether settlement succeeded */
|
|
146
|
-
success: boolean;
|
|
147
|
-
/** Transaction signature/hash */
|
|
148
|
-
transaction?: string;
|
|
149
|
-
/** Network the payment was made on */
|
|
150
|
-
network: string;
|
|
151
|
-
/** Error reason (if failed) */
|
|
152
|
-
errorReason?: string;
|
|
153
|
-
/** Error code (if failed) */
|
|
154
|
-
errorCode?: string;
|
|
155
|
-
/** Payer address */
|
|
156
|
-
payer?: string;
|
|
157
|
-
/** Protocol extensions returned by the facilitator (e.g., sponsored-access recommendations) */
|
|
158
|
-
extensions?: Record<string, unknown>;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* A single access pass tier offered by a seller
|
|
162
|
-
*/
|
|
163
|
-
interface AccessPassTier {
|
|
164
|
-
/** Tier ID (e.g., '1h', '24h') */
|
|
165
|
-
id: string;
|
|
166
|
-
/** Human-readable label (e.g., '1 hour') */
|
|
167
|
-
label: string;
|
|
168
|
-
/** Duration in seconds */
|
|
169
|
-
seconds: number;
|
|
170
|
-
/** Price in USD (e.g., '0.50') */
|
|
171
|
-
price: string;
|
|
172
|
-
/** Price in atomic units (e.g., '500000') */
|
|
173
|
-
priceAtomic: string;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Access pass info returned in X-ACCESS-PASS-TIERS header
|
|
177
|
-
*/
|
|
178
|
-
interface AccessPassInfo {
|
|
179
|
-
/** Available tiers (if tier-based pricing) */
|
|
180
|
-
tiers?: AccessPassTier[];
|
|
181
|
-
/** Rate per hour in USD (if custom duration pricing) */
|
|
182
|
-
ratePerHour?: string;
|
|
183
|
-
/** Pass issuer identifier */
|
|
184
|
-
issuer?: string;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* JWT claims inside an access pass token
|
|
188
|
-
*/
|
|
189
|
-
interface AccessPassClaims {
|
|
190
|
-
/** Subject — always 'x402-access-pass' */
|
|
191
|
-
sub: string;
|
|
192
|
-
/** Tier ID or 'custom' */
|
|
193
|
-
tier: string;
|
|
194
|
-
/** Duration in seconds */
|
|
195
|
-
duration: number;
|
|
196
|
-
/** Issued at (unix seconds) */
|
|
197
|
-
iat: number;
|
|
198
|
-
/** Expires at (unix seconds) */
|
|
199
|
-
exp: number;
|
|
200
|
-
/** Payer wallet address */
|
|
201
|
-
payer: string;
|
|
202
|
-
/** Network used for payment */
|
|
203
|
-
network: string;
|
|
204
|
-
/** Issuer identifier */
|
|
205
|
-
iss: string;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Client-side access pass configuration
|
|
209
|
-
*/
|
|
210
|
-
interface AccessPassClientConfig {
|
|
211
|
-
/** Enable access pass mode (default: true when this config is present) */
|
|
212
|
-
enabled?: boolean;
|
|
213
|
-
/** Preferred tier ID (e.g., '1h') — pick this tier if available */
|
|
214
|
-
preferTier?: string;
|
|
215
|
-
/** Preferred custom duration in seconds (e.g., 3600) */
|
|
216
|
-
preferDuration?: number;
|
|
217
|
-
/** Maximum amount willing to spend in USD (e.g., '2.00') */
|
|
218
|
-
maxSpend?: string;
|
|
219
|
-
/** Auto-renew expired passes (default: true) */
|
|
220
|
-
autoRenew?: boolean;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* SDK error codes
|
|
224
|
-
*/
|
|
225
|
-
type X402ErrorCode = 'missing_payment_required_header' | 'invalid_payment_required' | 'unsupported_network' | 'no_matching_payment_option' | 'missing_fee_payer' | 'missing_decimals' | 'missing_amount' | 'amount_exceeds_max' | 'insufficient_balance' | 'wallet_missing_sign_transaction' | 'wallet_not_connected' | 'wallet_disconnected' | 'user_rejected_signature' | 'transaction_build_failed' | 'payment_rejected' | 'rpc_timeout' | 'facilitator_timeout' | 'invalid_payment_signature' | 'facilitator_verify_failed' | 'facilitator_settle_failed' | 'facilitator_request_failed' | 'no_matching_requirement' | 'access_pass_expired' | 'access_pass_invalid' | 'access_pass_tier_not_found' | 'access_pass_exceeds_max_spend';
|
|
226
|
-
/**
|
|
227
|
-
* Custom error class for x402 operations
|
|
228
|
-
*/
|
|
229
|
-
declare class X402Error extends Error {
|
|
230
|
-
/** Error code for programmatic handling */
|
|
231
|
-
code: X402ErrorCode;
|
|
232
|
-
/** Additional error details */
|
|
233
|
-
details?: unknown;
|
|
234
|
-
constructor(code: X402ErrorCode, message: string, details?: unknown);
|
|
235
|
-
}
|
|
1
|
+
import { P as PaymentAccept } from './types-DolSK-3d.cjs';
|
|
236
2
|
|
|
237
3
|
/**
|
|
238
4
|
* EVM Chain Adapter
|
|
@@ -645,4 +411,4 @@ interface BalanceInfo {
|
|
|
645
411
|
asset: string;
|
|
646
412
|
}
|
|
647
413
|
|
|
648
|
-
export { type AdapterConfig as A, type BalanceInfo as B, type ChainAdapter as C, EvmAdapter as E, type GenericWallet as G,
|
|
414
|
+
export { type AdapterConfig as A, type BalanceInfo as B, type ChainAdapter as C, EvmAdapter as E, type GenericWallet as G, SolanaAdapter as S, type WalletSet as W, type EvmWallet as a, type SignedTransaction as b, type SolanaWallet as c, createEvmAdapter as d, createSolanaAdapter as e, isSolanaWallet as f, type SettlementProbe as g, isEvmWallet as i };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientChannelStorage } from '@x402/evm/batch-settlement/client';
|
|
2
|
-
import { a as EvmWallet } from './types-
|
|
2
|
+
import { a as EvmWallet } from './types-CRs5sEcb.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Buyer withdrawal escape hatch for batch-settlement escrow channels.
|
|
@@ -58,7 +58,7 @@ interface OpenBatchChannelOptions {
|
|
|
58
58
|
wallet: EvmWallet;
|
|
59
59
|
/** CAIP-2 network: eip155:8453 (Base), eip155:42161 (Arbitrum), eip155:137 (Polygon). */
|
|
60
60
|
network: string;
|
|
61
|
-
/**
|
|
61
|
+
/** Fixed escrow budget in USDC, e.g. "0.30". Funds once; exhaustion requires a new channel. */
|
|
62
62
|
deposit: string;
|
|
63
63
|
/** Facilitator base URL. Default: https://x402.dexter.cash */
|
|
64
64
|
facilitatorUrl?: string;
|
|
@@ -84,6 +84,8 @@ interface ResumeBatchChannelOptions {
|
|
|
84
84
|
facilitatorUrl?: string;
|
|
85
85
|
rpcUrl?: string;
|
|
86
86
|
store?: ChannelStore;
|
|
87
|
+
/** Per-call USDC limit, e.g. "2.00". Defaults to "1". Resume never adds escrow. */
|
|
88
|
+
maxAmountPerPayment?: string;
|
|
87
89
|
/**
|
|
88
90
|
* 32-byte hex channel-config salt of the channel being resumed — REQUIRED.
|
|
89
91
|
* `channelId` cannot be reversed to a salt, so resuming a channel needs the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientChannelStorage } from '@x402/evm/batch-settlement/client';
|
|
2
|
-
import { a as EvmWallet } from './types-
|
|
2
|
+
import { a as EvmWallet } from './types-C08JT9MG.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Buyer withdrawal escape hatch for batch-settlement escrow channels.
|
|
@@ -58,7 +58,7 @@ interface OpenBatchChannelOptions {
|
|
|
58
58
|
wallet: EvmWallet;
|
|
59
59
|
/** CAIP-2 network: eip155:8453 (Base), eip155:42161 (Arbitrum), eip155:137 (Polygon). */
|
|
60
60
|
network: string;
|
|
61
|
-
/**
|
|
61
|
+
/** Fixed escrow budget in USDC, e.g. "0.30". Funds once; exhaustion requires a new channel. */
|
|
62
62
|
deposit: string;
|
|
63
63
|
/** Facilitator base URL. Default: https://x402.dexter.cash */
|
|
64
64
|
facilitatorUrl?: string;
|
|
@@ -84,6 +84,8 @@ interface ResumeBatchChannelOptions {
|
|
|
84
84
|
facilitatorUrl?: string;
|
|
85
85
|
rpcUrl?: string;
|
|
86
86
|
store?: ChannelStore;
|
|
87
|
+
/** Per-call USDC limit, e.g. "2.00". Defaults to "1". Resume never adds escrow. */
|
|
88
|
+
maxAmountPerPayment?: string;
|
|
87
89
|
/**
|
|
88
90
|
* 32-byte hex channel-config salt of the channel being resumed — REQUIRED.
|
|
89
91
|
* `channelId` cannot be reversed to a salt, so resuming a channel needs the
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 v2 SDK — Shared Types
|
|
3
|
+
*
|
|
4
|
+
* Chain-agnostic types for x402 v2 payments.
|
|
5
|
+
* Works with Solana, Base, and any future x402-compatible networks.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Context passed to a PayToProvider function.
|
|
10
|
+
* Contains request-scoped information for dynamic address resolution.
|
|
11
|
+
*/
|
|
12
|
+
interface PayToContext {
|
|
13
|
+
/** The PAYMENT-SIGNATURE header value (present on retry/verify, undefined on initial 402) */
|
|
14
|
+
paymentHeader?: string;
|
|
15
|
+
/** Amount in atomic units (e.g., '10000' for 0.01 USDC) */
|
|
16
|
+
amountAtomic?: string;
|
|
17
|
+
/** The resource URL being accessed */
|
|
18
|
+
resourceUrl?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Optional defaults a PayToProvider can advertise for auto-configuration.
|
|
22
|
+
* Attached as `_x402Defaults` on the provider function.
|
|
23
|
+
*/
|
|
24
|
+
interface PayToProviderDefaults {
|
|
25
|
+
/** Default CAIP-2 network (e.g., 'eip155:8453' for Base) */
|
|
26
|
+
network?: string;
|
|
27
|
+
/** Default facilitator URL */
|
|
28
|
+
facilitatorUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A function that dynamically resolves a payment address.
|
|
32
|
+
* Used for providers like Stripe that generate per-request deposit addresses.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { stripePayTo } from '@dexterai/x402/server';
|
|
37
|
+
*
|
|
38
|
+
* const provider = stripePayTo(process.env.STRIPE_SECRET_KEY);
|
|
39
|
+
* const address = await provider({ amountAtomic: '10000' });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
type PayToProvider = ((context: PayToContext) => Promise<string>) & {
|
|
43
|
+
/** Auto-configuration defaults (set by provider factories like stripePayTo) */
|
|
44
|
+
_x402Defaults?: PayToProviderDefaults;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Resource info included in payment requirements
|
|
48
|
+
*/
|
|
49
|
+
interface ResourceInfo {
|
|
50
|
+
/** Resource URL */
|
|
51
|
+
url: string;
|
|
52
|
+
/** Human-readable description */
|
|
53
|
+
description?: string;
|
|
54
|
+
/** MIME type of the resource */
|
|
55
|
+
mimeType?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extra fields in payment requirements
|
|
59
|
+
* Chain-specific fields may vary
|
|
60
|
+
*/
|
|
61
|
+
interface AcceptsExtra {
|
|
62
|
+
/** Facilitator address that pays tx fees (required for Solana) */
|
|
63
|
+
feePayer?: string;
|
|
64
|
+
/** Token decimals (optional - defaults to 6 for USDC) */
|
|
65
|
+
decimals?: number;
|
|
66
|
+
/** EIP-712: Token name (EVM only) */
|
|
67
|
+
name?: string;
|
|
68
|
+
/** EIP-712: Token version (EVM only) */
|
|
69
|
+
version?: string;
|
|
70
|
+
/**
|
|
71
|
+
* batch-settlement: on-chain authorizer that the escrow channel pays into.
|
|
72
|
+
* Provided by the facilitator's batch-settlement kind. EVM only.
|
|
73
|
+
*/
|
|
74
|
+
receiverAuthorizer?: string;
|
|
75
|
+
/** Tab seller-wire header advertised by the default hosted scheme. */
|
|
76
|
+
voucherHeader?: string;
|
|
77
|
+
/** Tab registration encoding carried inside each seller voucher. */
|
|
78
|
+
registrationEncoding?: string;
|
|
79
|
+
/** Immutable commercial-terms version for this Tab offer. */
|
|
80
|
+
termsVersion?: string;
|
|
81
|
+
/** Event that makes usage accepted under the advertised terms version. */
|
|
82
|
+
acceptanceRule?: string;
|
|
83
|
+
/** Additional chain-specific fields */
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A single payment option in the accepts array
|
|
88
|
+
*/
|
|
89
|
+
interface PaymentAccept {
|
|
90
|
+
/** x402 version (1 or 2, defaults to 2 if not specified) */
|
|
91
|
+
x402Version?: 1 | 2;
|
|
92
|
+
/**
|
|
93
|
+
* Payment scheme: 'exact' for EIP-3009 chains, 'exact-approval' for
|
|
94
|
+
* approval-based chains like BSC, 'batch-settlement' for the EVM
|
|
95
|
+
* escrow-channel batching scheme (discrete API purchases, gas-amortized),
|
|
96
|
+
* 'tab' (SVM only) for streaming session-key vouchers against an
|
|
97
|
+
* on-chain vault.
|
|
98
|
+
*/
|
|
99
|
+
scheme: 'exact' | 'exact-approval' | 'batch-settlement' | 'tab';
|
|
100
|
+
/** CAIP-2 network identifier (v1: 'solana', v2: 'solana:5eykt...') */
|
|
101
|
+
network: string;
|
|
102
|
+
/** Payment amount in atomic units (x402 v2 spec field) */
|
|
103
|
+
amount: string;
|
|
104
|
+
/** @deprecated v1 field — use `amount` instead. Kept for backwards compatibility with v1 data. */
|
|
105
|
+
maxAmountRequired?: string;
|
|
106
|
+
/** Token address */
|
|
107
|
+
asset: string;
|
|
108
|
+
/** Seller's address to receive payment */
|
|
109
|
+
payTo: string;
|
|
110
|
+
/** Maximum seconds until payment expires */
|
|
111
|
+
maxTimeoutSeconds: number;
|
|
112
|
+
/** Chain-specific extra data */
|
|
113
|
+
extra?: AcceptsExtra;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Full PaymentRequired structure (sent in PAYMENT-REQUIRED header)
|
|
117
|
+
*/
|
|
118
|
+
interface PaymentRequired {
|
|
119
|
+
/** x402 version (always 2) */
|
|
120
|
+
x402Version: 2;
|
|
121
|
+
/** Resource being accessed */
|
|
122
|
+
resource: ResourceInfo;
|
|
123
|
+
/** Available payment options */
|
|
124
|
+
accepts: PaymentAccept[];
|
|
125
|
+
/** Optional error message */
|
|
126
|
+
error?: string;
|
|
127
|
+
/** Protocol extensions */
|
|
128
|
+
extensions?: Record<string, unknown>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Response from /verify endpoint
|
|
132
|
+
*/
|
|
133
|
+
interface VerifyResponse {
|
|
134
|
+
/** Whether the payment is valid */
|
|
135
|
+
isValid: boolean;
|
|
136
|
+
/** Reason for invalidity (if invalid) */
|
|
137
|
+
invalidReason?: string;
|
|
138
|
+
/** Payer address */
|
|
139
|
+
payer?: string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Response from /settle endpoint
|
|
143
|
+
*/
|
|
144
|
+
interface SettleResponse {
|
|
145
|
+
/** Whether settlement succeeded */
|
|
146
|
+
success: boolean;
|
|
147
|
+
/** Transaction signature/hash */
|
|
148
|
+
transaction?: string;
|
|
149
|
+
/** Network the payment was made on */
|
|
150
|
+
network: string;
|
|
151
|
+
/** Error reason (if failed) */
|
|
152
|
+
errorReason?: string;
|
|
153
|
+
/** Error code (if failed) */
|
|
154
|
+
errorCode?: string;
|
|
155
|
+
/** Payer address */
|
|
156
|
+
payer?: string;
|
|
157
|
+
/** Protocol extensions returned by the facilitator (e.g., sponsored-access recommendations) */
|
|
158
|
+
extensions?: Record<string, unknown>;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A single access pass tier offered by a seller
|
|
162
|
+
*/
|
|
163
|
+
interface AccessPassTier {
|
|
164
|
+
/** Tier ID (e.g., '1h', '24h') */
|
|
165
|
+
id: string;
|
|
166
|
+
/** Human-readable label (e.g., '1 hour') */
|
|
167
|
+
label: string;
|
|
168
|
+
/** Duration in seconds */
|
|
169
|
+
seconds: number;
|
|
170
|
+
/** Price in USD (e.g., '0.50') */
|
|
171
|
+
price: string;
|
|
172
|
+
/** Price in atomic units (e.g., '500000') */
|
|
173
|
+
priceAtomic: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Access pass info returned in X-ACCESS-PASS-TIERS header
|
|
177
|
+
*/
|
|
178
|
+
interface AccessPassInfo {
|
|
179
|
+
/** Available tiers (if tier-based pricing) */
|
|
180
|
+
tiers?: AccessPassTier[];
|
|
181
|
+
/** Rate per hour in USD (if custom duration pricing) */
|
|
182
|
+
ratePerHour?: string;
|
|
183
|
+
/** Pass issuer identifier */
|
|
184
|
+
issuer?: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* JWT claims inside an access pass token
|
|
188
|
+
*/
|
|
189
|
+
interface AccessPassClaims {
|
|
190
|
+
/** Subject — always 'x402-access-pass' */
|
|
191
|
+
sub: string;
|
|
192
|
+
/** Tier ID or 'custom' */
|
|
193
|
+
tier: string;
|
|
194
|
+
/** Duration in seconds */
|
|
195
|
+
duration: number;
|
|
196
|
+
/** Issued at (unix seconds) */
|
|
197
|
+
iat: number;
|
|
198
|
+
/** Expires at (unix seconds) */
|
|
199
|
+
exp: number;
|
|
200
|
+
/** Payer wallet address */
|
|
201
|
+
payer: string;
|
|
202
|
+
/** Network used for payment */
|
|
203
|
+
network: string;
|
|
204
|
+
/** Issuer identifier */
|
|
205
|
+
iss: string;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Client-side access pass configuration
|
|
209
|
+
*/
|
|
210
|
+
interface AccessPassClientConfig {
|
|
211
|
+
/** Enable access pass mode (default: true when this config is present) */
|
|
212
|
+
enabled?: boolean;
|
|
213
|
+
/** Preferred tier ID (e.g., '1h') — pick this tier if available */
|
|
214
|
+
preferTier?: string;
|
|
215
|
+
/** Preferred custom duration in seconds (e.g., 3600) */
|
|
216
|
+
preferDuration?: number;
|
|
217
|
+
/** Maximum amount willing to spend in USD (e.g., '2.00') */
|
|
218
|
+
maxSpend?: string;
|
|
219
|
+
/** Auto-renew expired passes (default: true) */
|
|
220
|
+
autoRenew?: boolean;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* SDK error codes
|
|
224
|
+
*/
|
|
225
|
+
type X402ErrorCode = 'missing_payment_required_header' | 'invalid_payment_required' | 'unsupported_network' | 'no_matching_payment_option' | 'missing_fee_payer' | 'missing_decimals' | 'missing_amount' | 'amount_exceeds_max' | 'insufficient_balance' | 'wallet_missing_sign_transaction' | 'wallet_not_connected' | 'wallet_disconnected' | 'user_rejected_signature' | 'transaction_build_failed' | 'payment_rejected' | 'rpc_timeout' | 'facilitator_timeout' | 'invalid_payment_signature' | 'facilitator_verify_failed' | 'facilitator_settle_failed' | 'facilitator_request_failed' | 'no_matching_requirement' | 'access_pass_expired' | 'access_pass_invalid' | 'access_pass_tier_not_found' | 'access_pass_exceeds_max_spend';
|
|
226
|
+
/**
|
|
227
|
+
* Custom error class for x402 operations
|
|
228
|
+
*/
|
|
229
|
+
declare class X402Error extends Error {
|
|
230
|
+
/** Error code for programmatic handling */
|
|
231
|
+
code: X402ErrorCode;
|
|
232
|
+
/** Additional error details */
|
|
233
|
+
details?: unknown;
|
|
234
|
+
constructor(code: X402ErrorCode, message: string, details?: unknown);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { type AccessPassClientConfig as A, type PaymentAccept as P, type ResourceInfo as R, type SettleResponse as S, type VerifyResponse as V, X402Error as X, type AccessPassInfo as a, type AccessPassTier as b, type PaymentRequired as c, type PayToProvider as d, type AccessPassClaims as e, type PayToContext as f, type PayToProviderDefaults as g };
|