@dexterai/x402 1.7.1 → 1.8.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/README.md +47 -5
- package/dist/adapters/index.cjs +408 -412
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +7 -6
- package/dist/adapters/index.d.ts +7 -6
- package/dist/adapters/index.js +385 -415
- package/dist/adapters/index.js.map +1 -1
- package/dist/client/index.cjs +583 -548
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +8 -8
- package/dist/client/index.d.ts +8 -8
- package/dist/client/index.js +594 -555
- package/dist/client/index.js.map +1 -1
- package/dist/react/index.cjs +413 -398
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +4 -4
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +409 -396
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +211 -81
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +88 -38
- package/dist/server/index.d.ts +88 -38
- package/dist/server/index.js +211 -81
- package/dist/server/index.js.map +1 -1
- package/dist/{solana-CnW6P4lJ.d.cts → solana-BeGAqPta.d.cts} +17 -5
- package/dist/{solana-CJdhHls8.d.ts → solana-CQD9yMju.d.ts} +17 -5
- package/dist/{types-ClEZ34n4.d.ts → types-B477nBpg.d.cts} +8 -3
- package/dist/{types-BB-2vowq.d.cts → types-BWnUAPvD.d.ts} +8 -3
- package/dist/{types-C6ty4U6C.d.ts → types-DYLi7SuF.d.cts} +2 -0
- package/dist/{types-C6ty4U6C.d.cts → types-DYLi7SuF.d.ts} +2 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/{x402-client-B9ECWy7k.d.ts → x402-client-D9b3PHai.d.ts} +24 -3
- package/dist/{x402-client-BhLOoqwa.d.cts → x402-client-Dk9q2QQF.d.cts} +24 -3
- package/package.json +9 -3
package/dist/server/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-
|
|
2
|
-
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-
|
|
1
|
+
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-DYLi7SuF.cjs';
|
|
2
|
+
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-DYLi7SuF.cjs';
|
|
3
3
|
import { Request, RequestHandler } from 'express';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -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
|
-
|
|
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)`
|
|
232
|
-
*
|
|
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
|
-
* //
|
|
244
|
+
* // Single address (works on one network)
|
|
237
245
|
* payTo: '0xYourAddress...'
|
|
238
246
|
*
|
|
239
|
-
* // Stripe
|
|
240
|
-
* payTo: stripePayTo(
|
|
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
|
|
287
|
+
* @default 'https://x402.dexter.cash'
|
|
265
288
|
*/
|
|
266
289
|
facilitatorUrl?: string;
|
|
267
290
|
/**
|
|
@@ -300,6 +323,39 @@ interface X402MiddlewareConfig {
|
|
|
300
323
|
* Custom function to get description from request
|
|
301
324
|
*/
|
|
302
325
|
getDescription?: (req: Request) => string;
|
|
326
|
+
/**
|
|
327
|
+
* Enable sponsored-access recommendation delivery.
|
|
328
|
+
*
|
|
329
|
+
* When true, the middleware reads `extensions["sponsored-access"]` from the
|
|
330
|
+
* facilitator's SettlementResponse and injects the recommendations into the
|
|
331
|
+
* JSON response body as a `_x402_sponsored` field. This is the only way
|
|
332
|
+
* recommendations reach the agent's LLM (headers and receipt metadata are
|
|
333
|
+
* not visible to LLMs).
|
|
334
|
+
*
|
|
335
|
+
* Pass `true` for default injection, or an object with a custom `inject`
|
|
336
|
+
* function for full control over how recommendations appear in the response.
|
|
337
|
+
*
|
|
338
|
+
* @default false (off, no injection)
|
|
339
|
+
*
|
|
340
|
+
* @example Default injection
|
|
341
|
+
* ```typescript
|
|
342
|
+
* x402Middleware({ payTo: '...', amount: '0.05', sponsoredAccess: true })
|
|
343
|
+
* // Agent receives: { _x402_sponsored: [...], ...originalResponse }
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* @example Custom injection
|
|
347
|
+
* ```typescript
|
|
348
|
+
* x402Middleware({
|
|
349
|
+
* payTo: '...', amount: '0.05',
|
|
350
|
+
* sponsoredAccess: {
|
|
351
|
+
* inject: (body, recs) => ({ ...body, related_tools: recs })
|
|
352
|
+
* }
|
|
353
|
+
* })
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
sponsoredAccess?: boolean | {
|
|
357
|
+
inject?: (body: unknown, recommendations: unknown[]) => unknown;
|
|
358
|
+
};
|
|
303
359
|
}
|
|
304
360
|
/**
|
|
305
361
|
* Extended request with payment info
|
|
@@ -317,12 +373,6 @@ interface X402Request extends Request {
|
|
|
317
373
|
network: string;
|
|
318
374
|
};
|
|
319
375
|
}
|
|
320
|
-
/**
|
|
321
|
-
* Create x402 middleware for Express
|
|
322
|
-
*
|
|
323
|
-
* @param config - Middleware configuration
|
|
324
|
-
* @returns Express middleware function
|
|
325
|
-
*/
|
|
326
376
|
declare function x402Middleware(config: X402MiddlewareConfig): RequestHandler;
|
|
327
377
|
|
|
328
378
|
/**
|
|
@@ -422,7 +472,7 @@ interface X402AccessPassConfig {
|
|
|
422
472
|
payTo: string;
|
|
423
473
|
/** CAIP-2 network identifier @default 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' */
|
|
424
474
|
network?: string;
|
|
425
|
-
/** x402 facilitator URL @default 'https://x402
|
|
475
|
+
/** x402 facilitator URL @default 'https://x402.dexter.cash' */
|
|
426
476
|
facilitatorUrl?: string;
|
|
427
477
|
/** Asset config @default USDC on specified network */
|
|
428
478
|
asset?: {
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-
|
|
2
|
-
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-
|
|
1
|
+
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-DYLi7SuF.js';
|
|
2
|
+
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-DYLi7SuF.js';
|
|
3
3
|
import { Request, RequestHandler } from 'express';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -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
|
-
|
|
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)`
|
|
232
|
-
*
|
|
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
|
-
* //
|
|
244
|
+
* // Single address (works on one network)
|
|
237
245
|
* payTo: '0xYourAddress...'
|
|
238
246
|
*
|
|
239
|
-
* // Stripe
|
|
240
|
-
* payTo: stripePayTo(
|
|
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
|
|
287
|
+
* @default 'https://x402.dexter.cash'
|
|
265
288
|
*/
|
|
266
289
|
facilitatorUrl?: string;
|
|
267
290
|
/**
|
|
@@ -300,6 +323,39 @@ interface X402MiddlewareConfig {
|
|
|
300
323
|
* Custom function to get description from request
|
|
301
324
|
*/
|
|
302
325
|
getDescription?: (req: Request) => string;
|
|
326
|
+
/**
|
|
327
|
+
* Enable sponsored-access recommendation delivery.
|
|
328
|
+
*
|
|
329
|
+
* When true, the middleware reads `extensions["sponsored-access"]` from the
|
|
330
|
+
* facilitator's SettlementResponse and injects the recommendations into the
|
|
331
|
+
* JSON response body as a `_x402_sponsored` field. This is the only way
|
|
332
|
+
* recommendations reach the agent's LLM (headers and receipt metadata are
|
|
333
|
+
* not visible to LLMs).
|
|
334
|
+
*
|
|
335
|
+
* Pass `true` for default injection, or an object with a custom `inject`
|
|
336
|
+
* function for full control over how recommendations appear in the response.
|
|
337
|
+
*
|
|
338
|
+
* @default false (off, no injection)
|
|
339
|
+
*
|
|
340
|
+
* @example Default injection
|
|
341
|
+
* ```typescript
|
|
342
|
+
* x402Middleware({ payTo: '...', amount: '0.05', sponsoredAccess: true })
|
|
343
|
+
* // Agent receives: { _x402_sponsored: [...], ...originalResponse }
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* @example Custom injection
|
|
347
|
+
* ```typescript
|
|
348
|
+
* x402Middleware({
|
|
349
|
+
* payTo: '...', amount: '0.05',
|
|
350
|
+
* sponsoredAccess: {
|
|
351
|
+
* inject: (body, recs) => ({ ...body, related_tools: recs })
|
|
352
|
+
* }
|
|
353
|
+
* })
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
sponsoredAccess?: boolean | {
|
|
357
|
+
inject?: (body: unknown, recommendations: unknown[]) => unknown;
|
|
358
|
+
};
|
|
303
359
|
}
|
|
304
360
|
/**
|
|
305
361
|
* Extended request with payment info
|
|
@@ -317,12 +373,6 @@ interface X402Request extends Request {
|
|
|
317
373
|
network: string;
|
|
318
374
|
};
|
|
319
375
|
}
|
|
320
|
-
/**
|
|
321
|
-
* Create x402 middleware for Express
|
|
322
|
-
*
|
|
323
|
-
* @param config - Middleware configuration
|
|
324
|
-
* @returns Express middleware function
|
|
325
|
-
*/
|
|
326
376
|
declare function x402Middleware(config: X402MiddlewareConfig): RequestHandler;
|
|
327
377
|
|
|
328
378
|
/**
|
|
@@ -422,7 +472,7 @@ interface X402AccessPassConfig {
|
|
|
422
472
|
payTo: string;
|
|
423
473
|
/** CAIP-2 network identifier @default 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' */
|
|
424
474
|
network?: string;
|
|
425
|
-
/** x402 facilitator URL @default 'https://x402
|
|
475
|
+
/** x402 facilitator URL @default 'https://x402.dexter.cash' */
|
|
426
476
|
facilitatorUrl?: string;
|
|
427
477
|
/** Asset config @default USDC on specified network */
|
|
428
478
|
asset?: {
|