@dexterai/x402 1.7.2 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ import { Request, RequestHandler } from 'express';
10
10
  * - /verify - Verify a payment signature before processing
11
11
  * - /settle - Submit the payment for execution
12
12
  *
13
+ * Includes retry with exponential backoff and request timeouts.
13
14
  * Works with any x402 v2 facilitator (Dexter or others).
14
15
  */
15
16
 
@@ -33,6 +34,19 @@ interface SupportedKind {
33
34
  */
34
35
  interface SupportedResponse {
35
36
  kinds: SupportedKind[];
37
+ extensions?: string[];
38
+ signers?: Record<string, string[]>;
39
+ }
40
+ /**
41
+ * Configuration for retry and timeout behavior
42
+ */
43
+ interface FacilitatorClientConfig {
44
+ /** Request timeout in milliseconds @default 10000 */
45
+ timeoutMs?: number;
46
+ /** Maximum retry attempts for verify/settle @default 3 */
47
+ maxRetries?: number;
48
+ /** Base delay between retries in milliseconds (doubles each attempt) @default 500 */
49
+ retryBaseMs?: number;
36
50
  }
37
51
  /**
38
52
  * Client for communicating with an x402 v2 facilitator
@@ -42,40 +56,33 @@ declare class FacilitatorClient {
42
56
  private cachedSupported;
43
57
  private cacheTime;
44
58
  private readonly CACHE_TTL_MS;
45
- constructor(facilitatorUrl?: string);
59
+ private readonly timeoutMs;
60
+ private readonly maxRetries;
61
+ private readonly retryBaseMs;
62
+ constructor(facilitatorUrl?: string, config?: FacilitatorClientConfig);
63
+ private fetchWithTimeout;
64
+ private fetchWithRetry;
46
65
  /**
47
- * Get supported payment kinds from the facilitator
48
- * Results are cached for 1 minute to reduce network calls
66
+ * Get supported payment kinds from the facilitator.
67
+ * Results are cached for 1 minute to reduce network calls.
49
68
  */
50
69
  getSupported(): Promise<SupportedResponse>;
51
70
  /**
52
71
  * Get the fee payer address for a specific network
53
- *
54
- * @param network - CAIP-2 network identifier
55
- * @returns Fee payer address
56
72
  */
57
73
  getFeePayer(network: string): Promise<string>;
58
74
  /**
59
75
  * Get extra data for a network (feePayer, decimals, EIP-712 data, etc.)
60
- *
61
- * @param network - CAIP-2 network identifier
62
- * @returns Extra data from /supported
63
76
  */
64
77
  getNetworkExtra(network: string): Promise<SupportedKind['extra']>;
65
78
  /**
66
- * Verify a payment with the facilitator
67
- *
68
- * @param paymentSignatureHeader - Base64-encoded PAYMENT-SIGNATURE header value
69
- * @param requirements - The payment requirements that were sent to the client
70
- * @returns Verification response
79
+ * Verify a payment with the facilitator.
80
+ * Retries on 5xx and network errors with exponential backoff.
71
81
  */
72
82
  verifyPayment(paymentSignatureHeader: string, requirements: PaymentAccept): Promise<VerifyResponse>;
73
83
  /**
74
- * Settle a payment with the facilitator
75
- *
76
- * @param paymentSignatureHeader - Base64-encoded PAYMENT-SIGNATURE header value
77
- * @param requirements - The payment requirements that were sent to the client
78
- * @returns Settlement response with transaction signature on success
84
+ * Settle a payment with the facilitator.
85
+ * Retries on 5xx and network errors with exponential backoff.
79
86
  */
80
87
  settlePayment(paymentSignatureHeader: string, requirements: PaymentAccept): Promise<SettleResponse>;
81
88
  }
@@ -225,32 +232,48 @@ declare function createX402Server(config: X402ServerConfig): X402Server;
225
232
  */
226
233
  interface X402MiddlewareConfig {
227
234
  /**
228
- * Address to receive payments, or a dynamic provider function.
235
+ * Address to receive payments, or a dynamic provider function, or
236
+ * a map of network-specific addresses for multi-chain support.
229
237
  *
230
238
  * - **Static address**: Pass a Solana pubkey or EVM address string.
231
- * - **Stripe**: Use `stripePayTo(process.env.STRIPE_SECRET_KEY)` to generate
232
- * per-request deposit addresses. Payments land in your Stripe Dashboard.
239
+ * - **Stripe**: Use `stripePayTo(process.env.STRIPE_SECRET_KEY)` for Base.
240
+ * - **Multi-chain map**: Keys are CAIP-2 networks or globs (`eip155:*`, `*`).
233
241
  *
234
242
  * @example
235
243
  * ```typescript
236
- * // Static address
244
+ * // Single address (works on one network)
237
245
  * payTo: '0xYourAddress...'
238
246
  *
239
- * // Stripe machine payments
240
- * payTo: stripePayTo(process.env.STRIPE_SECRET_KEY)
247
+ * // Stripe on Base, direct wallet on other chains
248
+ * payTo: { 'eip155:8453': stripePayTo(key), '*': '0xYourAddress...' }
249
+ *
250
+ * // Solana + EVM
251
+ * payTo: { 'solana:*': 'SolAddr', 'eip155:*': '0xEvmAddr' }
241
252
  * ```
242
253
  */
243
- payTo: string | PayToProvider;
254
+ payTo: string | PayToProvider | Record<string, string | PayToProvider>;
244
255
  /**
245
256
  * Payment amount in USD (e.g., '0.01' for 1 cent)
246
257
  * Will be converted to atomic units automatically.
247
258
  */
248
259
  amount: string;
249
260
  /**
250
- * CAIP-2 network identifier
261
+ * CAIP-2 network identifier(s).
262
+ * Pass an array to accept payments on multiple chains simultaneously.
263
+ * The client picks whichever chain it has a wallet for.
264
+ *
251
265
  * @default 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' (Solana mainnet)
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * // Single network
270
+ * network: 'eip155:8453'
271
+ *
272
+ * // Multiple EVM chains (same payTo address works for all)
273
+ * network: ['eip155:8453', 'eip155:137', 'eip155:42161']
274
+ * ```
252
275
  */
253
- network?: string;
276
+ network?: string | string[];
254
277
  /**
255
278
  * Asset to accept
256
279
  * @default USDC on the specified network
@@ -261,7 +284,7 @@ interface X402MiddlewareConfig {
261
284
  };
262
285
  /**
263
286
  * x402 facilitator URL
264
- * @default 'https://x402-facilitator.dexter.cash'
287
+ * @default 'https://x402.dexter.cash'
265
288
  */
266
289
  facilitatorUrl?: string;
267
290
  /**
@@ -350,12 +373,6 @@ interface X402Request extends Request {
350
373
  network: string;
351
374
  };
352
375
  }
353
- /**
354
- * Create x402 middleware for Express
355
- *
356
- * @param config - Middleware configuration
357
- * @returns Express middleware function
358
- */
359
376
  declare function x402Middleware(config: X402MiddlewareConfig): RequestHandler;
360
377
 
361
378
  /**
@@ -455,7 +472,7 @@ interface X402AccessPassConfig {
455
472
  payTo: string;
456
473
  /** CAIP-2 network identifier @default 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' */
457
474
  network?: string;
458
- /** x402 facilitator URL @default 'https://x402-facilitator.dexter.cash' */
475
+ /** x402 facilitator URL @default 'https://x402.dexter.cash' */
459
476
  facilitatorUrl?: string;
460
477
  /** Asset config @default USDC on specified network */
461
478
  asset?: {
@@ -10,6 +10,7 @@ import { Request, RequestHandler } from 'express';
10
10
  * - /verify - Verify a payment signature before processing
11
11
  * - /settle - Submit the payment for execution
12
12
  *
13
+ * Includes retry with exponential backoff and request timeouts.
13
14
  * Works with any x402 v2 facilitator (Dexter or others).
14
15
  */
15
16
 
@@ -33,6 +34,19 @@ interface SupportedKind {
33
34
  */
34
35
  interface SupportedResponse {
35
36
  kinds: SupportedKind[];
37
+ extensions?: string[];
38
+ signers?: Record<string, string[]>;
39
+ }
40
+ /**
41
+ * Configuration for retry and timeout behavior
42
+ */
43
+ interface FacilitatorClientConfig {
44
+ /** Request timeout in milliseconds @default 10000 */
45
+ timeoutMs?: number;
46
+ /** Maximum retry attempts for verify/settle @default 3 */
47
+ maxRetries?: number;
48
+ /** Base delay between retries in milliseconds (doubles each attempt) @default 500 */
49
+ retryBaseMs?: number;
36
50
  }
37
51
  /**
38
52
  * Client for communicating with an x402 v2 facilitator
@@ -42,40 +56,33 @@ declare class FacilitatorClient {
42
56
  private cachedSupported;
43
57
  private cacheTime;
44
58
  private readonly CACHE_TTL_MS;
45
- constructor(facilitatorUrl?: string);
59
+ private readonly timeoutMs;
60
+ private readonly maxRetries;
61
+ private readonly retryBaseMs;
62
+ constructor(facilitatorUrl?: string, config?: FacilitatorClientConfig);
63
+ private fetchWithTimeout;
64
+ private fetchWithRetry;
46
65
  /**
47
- * Get supported payment kinds from the facilitator
48
- * Results are cached for 1 minute to reduce network calls
66
+ * Get supported payment kinds from the facilitator.
67
+ * Results are cached for 1 minute to reduce network calls.
49
68
  */
50
69
  getSupported(): Promise<SupportedResponse>;
51
70
  /**
52
71
  * Get the fee payer address for a specific network
53
- *
54
- * @param network - CAIP-2 network identifier
55
- * @returns Fee payer address
56
72
  */
57
73
  getFeePayer(network: string): Promise<string>;
58
74
  /**
59
75
  * Get extra data for a network (feePayer, decimals, EIP-712 data, etc.)
60
- *
61
- * @param network - CAIP-2 network identifier
62
- * @returns Extra data from /supported
63
76
  */
64
77
  getNetworkExtra(network: string): Promise<SupportedKind['extra']>;
65
78
  /**
66
- * Verify a payment with the facilitator
67
- *
68
- * @param paymentSignatureHeader - Base64-encoded PAYMENT-SIGNATURE header value
69
- * @param requirements - The payment requirements that were sent to the client
70
- * @returns Verification response
79
+ * Verify a payment with the facilitator.
80
+ * Retries on 5xx and network errors with exponential backoff.
71
81
  */
72
82
  verifyPayment(paymentSignatureHeader: string, requirements: PaymentAccept): Promise<VerifyResponse>;
73
83
  /**
74
- * Settle a payment with the facilitator
75
- *
76
- * @param paymentSignatureHeader - Base64-encoded PAYMENT-SIGNATURE header value
77
- * @param requirements - The payment requirements that were sent to the client
78
- * @returns Settlement response with transaction signature on success
84
+ * Settle a payment with the facilitator.
85
+ * Retries on 5xx and network errors with exponential backoff.
79
86
  */
80
87
  settlePayment(paymentSignatureHeader: string, requirements: PaymentAccept): Promise<SettleResponse>;
81
88
  }
@@ -225,32 +232,48 @@ declare function createX402Server(config: X402ServerConfig): X402Server;
225
232
  */
226
233
  interface X402MiddlewareConfig {
227
234
  /**
228
- * Address to receive payments, or a dynamic provider function.
235
+ * Address to receive payments, or a dynamic provider function, or
236
+ * a map of network-specific addresses for multi-chain support.
229
237
  *
230
238
  * - **Static address**: Pass a Solana pubkey or EVM address string.
231
- * - **Stripe**: Use `stripePayTo(process.env.STRIPE_SECRET_KEY)` to generate
232
- * per-request deposit addresses. Payments land in your Stripe Dashboard.
239
+ * - **Stripe**: Use `stripePayTo(process.env.STRIPE_SECRET_KEY)` for Base.
240
+ * - **Multi-chain map**: Keys are CAIP-2 networks or globs (`eip155:*`, `*`).
233
241
  *
234
242
  * @example
235
243
  * ```typescript
236
- * // Static address
244
+ * // Single address (works on one network)
237
245
  * payTo: '0xYourAddress...'
238
246
  *
239
- * // Stripe machine payments
240
- * payTo: stripePayTo(process.env.STRIPE_SECRET_KEY)
247
+ * // Stripe on Base, direct wallet on other chains
248
+ * payTo: { 'eip155:8453': stripePayTo(key), '*': '0xYourAddress...' }
249
+ *
250
+ * // Solana + EVM
251
+ * payTo: { 'solana:*': 'SolAddr', 'eip155:*': '0xEvmAddr' }
241
252
  * ```
242
253
  */
243
- payTo: string | PayToProvider;
254
+ payTo: string | PayToProvider | Record<string, string | PayToProvider>;
244
255
  /**
245
256
  * Payment amount in USD (e.g., '0.01' for 1 cent)
246
257
  * Will be converted to atomic units automatically.
247
258
  */
248
259
  amount: string;
249
260
  /**
250
- * CAIP-2 network identifier
261
+ * CAIP-2 network identifier(s).
262
+ * Pass an array to accept payments on multiple chains simultaneously.
263
+ * The client picks whichever chain it has a wallet for.
264
+ *
251
265
  * @default 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' (Solana mainnet)
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * // Single network
270
+ * network: 'eip155:8453'
271
+ *
272
+ * // Multiple EVM chains (same payTo address works for all)
273
+ * network: ['eip155:8453', 'eip155:137', 'eip155:42161']
274
+ * ```
252
275
  */
253
- network?: string;
276
+ network?: string | string[];
254
277
  /**
255
278
  * Asset to accept
256
279
  * @default USDC on the specified network
@@ -261,7 +284,7 @@ interface X402MiddlewareConfig {
261
284
  };
262
285
  /**
263
286
  * x402 facilitator URL
264
- * @default 'https://x402-facilitator.dexter.cash'
287
+ * @default 'https://x402.dexter.cash'
265
288
  */
266
289
  facilitatorUrl?: string;
267
290
  /**
@@ -350,12 +373,6 @@ interface X402Request extends Request {
350
373
  network: string;
351
374
  };
352
375
  }
353
- /**
354
- * Create x402 middleware for Express
355
- *
356
- * @param config - Middleware configuration
357
- * @returns Express middleware function
358
- */
359
376
  declare function x402Middleware(config: X402MiddlewareConfig): RequestHandler;
360
377
 
361
378
  /**
@@ -455,7 +472,7 @@ interface X402AccessPassConfig {
455
472
  payTo: string;
456
473
  /** CAIP-2 network identifier @default 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' */
457
474
  network?: string;
458
- /** x402 facilitator URL @default 'https://x402-facilitator.dexter.cash' */
475
+ /** x402 facilitator URL @default 'https://x402.dexter.cash' */
459
476
  facilitatorUrl?: string;
460
477
  /** Asset config @default USDC on specified network */
461
478
  asset?: {