@bankofai/x402-core 2.6.0-beta.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.
Files changed (74) hide show
  1. package/README.md +293 -0
  2. package/dist/cjs/assetRegistry-CL0zA4s0.d.ts +831 -0
  3. package/dist/cjs/assetRegistry-CRVM0KEs.d.ts +831 -0
  4. package/dist/cjs/client/index.d.ts +329 -0
  5. package/dist/cjs/client/index.js +712 -0
  6. package/dist/cjs/client/index.js.map +1 -0
  7. package/dist/cjs/facilitator/index.d.ts +206 -0
  8. package/dist/cjs/facilitator/index.js +625 -0
  9. package/dist/cjs/facilitator/index.js.map +1 -0
  10. package/dist/cjs/http/index.d.ts +51 -0
  11. package/dist/cjs/http/index.js +1178 -0
  12. package/dist/cjs/http/index.js.map +1 -0
  13. package/dist/cjs/index.d.ts +13 -0
  14. package/dist/cjs/index.js +250 -0
  15. package/dist/cjs/index.js.map +1 -0
  16. package/dist/cjs/mechanisms-q7I6xfUE.d.ts +726 -0
  17. package/dist/cjs/schemas/index.d.ts +825 -0
  18. package/dist/cjs/schemas/index.js +212 -0
  19. package/dist/cjs/schemas/index.js.map +1 -0
  20. package/dist/cjs/server/index.d.ts +2 -0
  21. package/dist/cjs/server/index.js +1782 -0
  22. package/dist/cjs/server/index.js.map +1 -0
  23. package/dist/cjs/types/index.d.ts +1 -0
  24. package/dist/cjs/types/index.js +72 -0
  25. package/dist/cjs/types/index.js.map +1 -0
  26. package/dist/cjs/types/v1/index.d.ts +1 -0
  27. package/dist/cjs/types/v1/index.js +19 -0
  28. package/dist/cjs/types/v1/index.js.map +1 -0
  29. package/dist/cjs/utils/index.d.ts +48 -0
  30. package/dist/cjs/utils/index.js +116 -0
  31. package/dist/cjs/utils/index.js.map +1 -0
  32. package/dist/cjs/x402HTTPResourceServer-BFVo1_74.d.ts +433 -0
  33. package/dist/cjs/x402HTTPResourceServer-DaU2yFzy.d.ts +434 -0
  34. package/dist/cjs/x402HTTPResourceServer-DswI2hZQ.d.ts +434 -0
  35. package/dist/esm/assetRegistry-CRVM0KEs.d.mts +831 -0
  36. package/dist/esm/chunk-BJTO5JO5.mjs +11 -0
  37. package/dist/esm/chunk-BJTO5JO5.mjs.map +1 -0
  38. package/dist/esm/chunk-DACUCTGT.mjs +891 -0
  39. package/dist/esm/chunk-DACUCTGT.mjs.map +1 -0
  40. package/dist/esm/chunk-DFUINDLZ.mjs +221 -0
  41. package/dist/esm/chunk-DFUINDLZ.mjs.map +1 -0
  42. package/dist/esm/chunk-HRQUGJ3Y.mjs +45 -0
  43. package/dist/esm/chunk-HRQUGJ3Y.mjs.map +1 -0
  44. package/dist/esm/chunk-TDLQZ6MP.mjs +86 -0
  45. package/dist/esm/chunk-TDLQZ6MP.mjs.map +1 -0
  46. package/dist/esm/client/index.d.mts +329 -0
  47. package/dist/esm/client/index.mjs +330 -0
  48. package/dist/esm/client/index.mjs.map +1 -0
  49. package/dist/esm/facilitator/index.d.mts +206 -0
  50. package/dist/esm/facilitator/index.mjs +398 -0
  51. package/dist/esm/facilitator/index.mjs.map +1 -0
  52. package/dist/esm/http/index.d.mts +51 -0
  53. package/dist/esm/http/index.mjs +29 -0
  54. package/dist/esm/http/index.mjs.map +1 -0
  55. package/dist/esm/index.d.mts +13 -0
  56. package/dist/esm/index.mjs +14 -0
  57. package/dist/esm/index.mjs.map +1 -0
  58. package/dist/esm/schemas/index.d.mts +825 -0
  59. package/dist/esm/schemas/index.mjs +158 -0
  60. package/dist/esm/schemas/index.mjs.map +1 -0
  61. package/dist/esm/server/index.d.mts +2 -0
  62. package/dist/esm/server/index.mjs +712 -0
  63. package/dist/esm/server/index.mjs.map +1 -0
  64. package/dist/esm/types/index.d.mts +1 -0
  65. package/dist/esm/types/index.mjs +10 -0
  66. package/dist/esm/types/index.mjs.map +1 -0
  67. package/dist/esm/types/v1/index.d.mts +1 -0
  68. package/dist/esm/types/v1/index.mjs +1 -0
  69. package/dist/esm/types/v1/index.mjs.map +1 -0
  70. package/dist/esm/utils/index.d.mts +48 -0
  71. package/dist/esm/utils/index.mjs +20 -0
  72. package/dist/esm/utils/index.mjs.map +1 -0
  73. package/dist/esm/x402HTTPResourceServer-B6uf_UDm.d.mts +434 -0
  74. package/package.json +139 -0
@@ -0,0 +1,831 @@
1
+ interface ResourceInfo {
2
+ url: string;
3
+ description?: string;
4
+ mimeType?: string;
5
+ }
6
+ type PaymentRequirements = {
7
+ scheme: string;
8
+ network: Network;
9
+ asset: string;
10
+ amount: string;
11
+ payTo: string;
12
+ maxTimeoutSeconds: number;
13
+ extra: Record<string, unknown>;
14
+ };
15
+ type PaymentRequired = {
16
+ x402Version: number;
17
+ error?: string;
18
+ resource: ResourceInfo;
19
+ accepts: PaymentRequirements[];
20
+ extensions?: Record<string, unknown>;
21
+ };
22
+ type PaymentPayload = {
23
+ x402Version: number;
24
+ resource?: ResourceInfo;
25
+ accepted: PaymentRequirements;
26
+ payload: Record<string, unknown>;
27
+ extensions?: Record<string, unknown>;
28
+ };
29
+
30
+ type VerifyRequest = {
31
+ x402Version: number;
32
+ paymentPayload: PaymentPayload;
33
+ paymentRequirements: PaymentRequirements;
34
+ };
35
+ type VerifyResponse = {
36
+ isValid: boolean;
37
+ invalidReason?: string;
38
+ invalidMessage?: string;
39
+ payer?: string;
40
+ extensions?: Record<string, unknown>;
41
+ };
42
+ type SettleRequest = {
43
+ x402Version: number;
44
+ paymentPayload: PaymentPayload;
45
+ paymentRequirements: PaymentRequirements;
46
+ };
47
+ type SettleResponse = {
48
+ success: boolean;
49
+ errorReason?: string;
50
+ errorMessage?: string;
51
+ payer?: string;
52
+ transaction: string;
53
+ network: Network;
54
+ extensions?: Record<string, unknown>;
55
+ };
56
+ type SupportedKind = {
57
+ x402Version: number;
58
+ scheme: string;
59
+ network: Network;
60
+ extra?: Record<string, unknown>;
61
+ };
62
+ type SupportedResponse = {
63
+ kinds: SupportedKind[];
64
+ extensions: string[];
65
+ signers: Record<string, string[]>;
66
+ };
67
+ /**
68
+ * Error thrown when payment verification fails.
69
+ */
70
+ declare class VerifyError extends Error {
71
+ readonly invalidReason?: string;
72
+ readonly invalidMessage?: string;
73
+ readonly payer?: string;
74
+ readonly statusCode: number;
75
+ /**
76
+ * Creates a VerifyError from a failed verification response.
77
+ *
78
+ * @param statusCode - HTTP status code from the facilitator
79
+ * @param response - The verify response containing error details
80
+ */
81
+ constructor(statusCode: number, response: VerifyResponse);
82
+ }
83
+ /**
84
+ * Error thrown when payment settlement fails.
85
+ */
86
+ declare class SettleError extends Error {
87
+ readonly errorReason?: string;
88
+ readonly errorMessage?: string;
89
+ readonly payer?: string;
90
+ readonly transaction: string;
91
+ readonly network: Network;
92
+ readonly statusCode: number;
93
+ /**
94
+ * Creates a SettleError from a failed settlement response.
95
+ *
96
+ * @param statusCode - HTTP status code from the facilitator
97
+ * @param response - The settle response containing error details
98
+ */
99
+ constructor(statusCode: number, response: SettleResponse);
100
+ }
101
+
102
+ interface FacilitatorConfig {
103
+ url?: string;
104
+ createAuthHeaders?: () => Promise<{
105
+ verify: Record<string, string>;
106
+ settle: Record<string, string>;
107
+ supported: Record<string, string>;
108
+ }>;
109
+ }
110
+ /**
111
+ * Interface for facilitator clients
112
+ * Can be implemented for HTTP-based or local facilitators
113
+ */
114
+ interface FacilitatorClient {
115
+ /**
116
+ * Verify a payment with the facilitator
117
+ *
118
+ * @param paymentPayload - The payment to verify
119
+ * @param paymentRequirements - The requirements to verify against
120
+ * @returns Verification response
121
+ */
122
+ verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
123
+ /**
124
+ * Settle a payment with the facilitator
125
+ *
126
+ * @param paymentPayload - The payment to settle
127
+ * @param paymentRequirements - The requirements for settlement
128
+ * @returns Settlement response
129
+ */
130
+ settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
131
+ /**
132
+ * Get supported payment kinds and extensions from the facilitator
133
+ *
134
+ * @returns Supported payment kinds and extensions
135
+ */
136
+ getSupported(): Promise<SupportedResponse>;
137
+ }
138
+ /**
139
+ * HTTP-based client for interacting with x402 facilitator services
140
+ * Handles HTTP communication with facilitator endpoints
141
+ */
142
+ declare class HTTPFacilitatorClient implements FacilitatorClient {
143
+ readonly url: string;
144
+ private readonly _createAuthHeaders?;
145
+ /**
146
+ * Creates a new HTTPFacilitatorClient instance.
147
+ *
148
+ * @param config - Configuration options for the facilitator client
149
+ */
150
+ constructor(config?: FacilitatorConfig);
151
+ /**
152
+ * Verify a payment with the facilitator
153
+ *
154
+ * @param paymentPayload - The payment to verify
155
+ * @param paymentRequirements - The requirements to verify against
156
+ * @returns Verification response
157
+ */
158
+ verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
159
+ /**
160
+ * Settle a payment with the facilitator
161
+ *
162
+ * @param paymentPayload - The payment to settle
163
+ * @param paymentRequirements - The requirements for settlement
164
+ * @returns Settlement response
165
+ */
166
+ settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
167
+ /**
168
+ * Get supported payment kinds and extensions from the facilitator.
169
+ * Retries with exponential backoff on 429 rate limit errors.
170
+ *
171
+ * @returns Supported payment kinds and extensions
172
+ */
173
+ getSupported(): Promise<SupportedResponse>;
174
+ /**
175
+ * Creates authentication headers for a specific path.
176
+ *
177
+ * @param path - The path to create authentication headers for (e.g., "verify", "settle", "supported")
178
+ * @returns An object containing the authentication headers for the specified path
179
+ */
180
+ createAuthHeaders(path: string): Promise<{
181
+ headers: Record<string, string>;
182
+ }>;
183
+ /**
184
+ * Helper to convert objects to JSON-safe format.
185
+ * Handles BigInt and other non-JSON types.
186
+ *
187
+ * @param obj - The object to convert
188
+ * @returns The JSON-safe representation of the object
189
+ */
190
+ private toJsonSafe;
191
+ }
192
+
193
+ /**
194
+ * Configuration for a protected resource
195
+ * Only contains payment-specific configuration, not resource metadata
196
+ */
197
+ interface ResourceConfig {
198
+ scheme: string;
199
+ payTo: string;
200
+ price: Price;
201
+ network: Network;
202
+ maxTimeoutSeconds?: number;
203
+ extra?: Record<string, unknown>;
204
+ assets?: string[];
205
+ }
206
+ /**
207
+ * Lifecycle Hook Context Interfaces
208
+ */
209
+ interface PaymentRequiredContext {
210
+ requirements: PaymentRequirements[];
211
+ resourceInfo: ResourceInfo;
212
+ error?: string;
213
+ paymentRequiredResponse: PaymentRequired;
214
+ transportContext?: unknown;
215
+ }
216
+ interface VerifyContext {
217
+ paymentPayload: PaymentPayload;
218
+ requirements: PaymentRequirements;
219
+ }
220
+ interface VerifyResultContext extends VerifyContext {
221
+ result: VerifyResponse;
222
+ }
223
+ interface VerifyFailureContext extends VerifyContext {
224
+ error: Error;
225
+ }
226
+ interface SettleContext {
227
+ paymentPayload: PaymentPayload;
228
+ requirements: PaymentRequirements;
229
+ }
230
+ interface SettleResultContext extends SettleContext {
231
+ result: SettleResponse;
232
+ transportContext?: unknown;
233
+ }
234
+ interface SettleFailureContext extends SettleContext {
235
+ error: Error;
236
+ }
237
+ /**
238
+ * Lifecycle Hook Type Definitions
239
+ */
240
+ type BeforeVerifyHook = (context: VerifyContext) => Promise<void | {
241
+ abort: true;
242
+ reason: string;
243
+ message?: string;
244
+ }>;
245
+ type AfterVerifyHook = (context: VerifyResultContext) => Promise<void>;
246
+ type OnVerifyFailureHook = (context: VerifyFailureContext) => Promise<void | {
247
+ recovered: true;
248
+ result: VerifyResponse;
249
+ }>;
250
+ type BeforeSettleHook = (context: SettleContext) => Promise<void | {
251
+ abort: true;
252
+ reason: string;
253
+ message?: string;
254
+ }>;
255
+ type AfterSettleHook = (context: SettleResultContext) => Promise<void>;
256
+ type OnSettleFailureHook = (context: SettleFailureContext) => Promise<void | {
257
+ recovered: true;
258
+ result: SettleResponse;
259
+ }>;
260
+ /**
261
+ * Core x402 protocol server for resource protection
262
+ * Transport-agnostic implementation of the x402 payment protocol
263
+ */
264
+ declare class x402ResourceServer {
265
+ readonly assetRegistry: AssetRegistry;
266
+ private facilitatorClients;
267
+ private registeredServerSchemes;
268
+ private supportedResponsesMap;
269
+ private facilitatorClientsMap;
270
+ private registeredExtensions;
271
+ private beforeVerifyHooks;
272
+ private afterVerifyHooks;
273
+ private onVerifyFailureHooks;
274
+ private beforeSettleHooks;
275
+ private afterSettleHooks;
276
+ private onSettleFailureHooks;
277
+ /**
278
+ * Creates a new x402ResourceServer instance.
279
+ *
280
+ * @param facilitatorClients - Optional facilitator client(s) for payment processing
281
+ * @param assetRegistry - Optional asset registry for symbol-based asset resolution
282
+ */
283
+ constructor(facilitatorClients?: FacilitatorClient | FacilitatorClient[], assetRegistry?: AssetRegistry);
284
+ /**
285
+ * Register a scheme/network server implementation.
286
+ *
287
+ * @param network - The network identifier
288
+ * @param server - The scheme/network server implementation
289
+ * @returns The x402ResourceServer instance for chaining
290
+ */
291
+ register(network: Network, server: SchemeNetworkServer): x402ResourceServer;
292
+ /**
293
+ * Check if a scheme is registered for a given network.
294
+ *
295
+ * @param network - The network identifier
296
+ * @param scheme - The payment scheme name
297
+ * @returns True if the scheme is registered for the network, false otherwise
298
+ */
299
+ hasRegisteredScheme(network: Network, scheme: string): boolean;
300
+ /**
301
+ * Registers a resource service extension that can enrich extension declarations.
302
+ *
303
+ * @param extension - The extension to register
304
+ * @returns The x402ResourceServer instance for chaining
305
+ */
306
+ registerExtension(extension: ResourceServerExtension): this;
307
+ /**
308
+ * Check if an extension is registered.
309
+ *
310
+ * @param key - The extension key
311
+ * @returns True if the extension is registered
312
+ */
313
+ hasExtension(key: string): boolean;
314
+ /**
315
+ * Get all registered extensions.
316
+ *
317
+ * @returns Array of registered extensions
318
+ */
319
+ getExtensions(): ResourceServerExtension[];
320
+ /**
321
+ * Enriches declared extensions using registered extension hooks.
322
+ *
323
+ * @param declaredExtensions - Extensions declared on the route
324
+ * @param transportContext - Transport-specific context (HTTP, A2A, MCP, etc.)
325
+ * @returns Enriched extensions map
326
+ */
327
+ enrichExtensions(declaredExtensions: Record<string, unknown>, transportContext: unknown): Record<string, unknown>;
328
+ /**
329
+ * Register a hook to execute before payment verification.
330
+ * Can abort verification by returning { abort: true, reason: string }
331
+ *
332
+ * @param hook - The hook function to register
333
+ * @returns The x402ResourceServer instance for chaining
334
+ */
335
+ onBeforeVerify(hook: BeforeVerifyHook): x402ResourceServer;
336
+ /**
337
+ * Register a hook to execute after successful payment verification.
338
+ *
339
+ * @param hook - The hook function to register
340
+ * @returns The x402ResourceServer instance for chaining
341
+ */
342
+ onAfterVerify(hook: AfterVerifyHook): x402ResourceServer;
343
+ /**
344
+ * Register a hook to execute when payment verification fails.
345
+ * Can recover from failure by returning { recovered: true, result: VerifyResponse }
346
+ *
347
+ * @param hook - The hook function to register
348
+ * @returns The x402ResourceServer instance for chaining
349
+ */
350
+ onVerifyFailure(hook: OnVerifyFailureHook): x402ResourceServer;
351
+ /**
352
+ * Register a hook to execute before payment settlement.
353
+ * Can abort settlement by returning { abort: true, reason: string }
354
+ *
355
+ * @param hook - The hook function to register
356
+ * @returns The x402ResourceServer instance for chaining
357
+ */
358
+ onBeforeSettle(hook: BeforeSettleHook): x402ResourceServer;
359
+ /**
360
+ * Register a hook to execute after successful payment settlement.
361
+ *
362
+ * @param hook - The hook function to register
363
+ * @returns The x402ResourceServer instance for chaining
364
+ */
365
+ onAfterSettle(hook: AfterSettleHook): x402ResourceServer;
366
+ /**
367
+ * Register a hook to execute when payment settlement fails.
368
+ * Can recover from failure by returning { recovered: true, result: SettleResponse }
369
+ *
370
+ * @param hook - The hook function to register
371
+ * @returns The x402ResourceServer instance for chaining
372
+ */
373
+ onSettleFailure(hook: OnSettleFailureHook): x402ResourceServer;
374
+ /**
375
+ * Initialize by fetching supported kinds from all facilitators
376
+ * Creates mappings for supported responses and facilitator clients
377
+ * Earlier facilitators in the array get precedence
378
+ */
379
+ initialize(): Promise<void>;
380
+ /**
381
+ * Get supported kind for a specific version, network, and scheme
382
+ *
383
+ * @param x402Version - The x402 version
384
+ * @param network - The network identifier
385
+ * @param scheme - The payment scheme
386
+ * @returns The supported kind or undefined if not found
387
+ */
388
+ getSupportedKind(x402Version: number, network: Network, scheme: string): SupportedKind | undefined;
389
+ /**
390
+ * Get facilitator extensions for a specific version, network, and scheme
391
+ *
392
+ * @param x402Version - The x402 version
393
+ * @param network - The network identifier
394
+ * @param scheme - The payment scheme
395
+ * @returns The facilitator extensions or empty array if not found
396
+ */
397
+ getFacilitatorExtensions(x402Version: number, network: Network, scheme: string): string[];
398
+ /**
399
+ * Build payment requirements for a protected resource
400
+ *
401
+ * @param resourceConfig - Configuration for the protected resource
402
+ * @returns Array of payment requirements
403
+ */
404
+ buildPaymentRequirements(resourceConfig: ResourceConfig): Promise<PaymentRequirements[]>;
405
+ /**
406
+ * Build payment requirements from multiple payment options
407
+ * This method handles resolving dynamic payTo/price functions and builds requirements for each option
408
+ *
409
+ * @param paymentOptions - Array of payment options to convert
410
+ * @param context - HTTP request context for resolving dynamic functions
411
+ * @returns Array of payment requirements (one per option)
412
+ */
413
+ buildPaymentRequirementsFromOptions<TContext = unknown>(paymentOptions: Array<{
414
+ scheme: string;
415
+ payTo: string | ((context: TContext) => string | Promise<string>);
416
+ price: Price | ((context: TContext) => Price | Promise<Price>);
417
+ network: Network;
418
+ maxTimeoutSeconds?: number;
419
+ extra?: Record<string, unknown>;
420
+ assets?: string[];
421
+ }>, context: TContext): Promise<PaymentRequirements[]>;
422
+ /**
423
+ * Create a payment required response
424
+ *
425
+ * @param requirements - Payment requirements
426
+ * @param resourceInfo - Resource information
427
+ * @param error - Error message
428
+ * @param extensions - Optional declared extensions (for per-key enrichment)
429
+ * @param transportContext - Optional transport-specific context (e.g., HTTP request, MCP tool context)
430
+ * @returns Payment required response object
431
+ */
432
+ createPaymentRequiredResponse(requirements: PaymentRequirements[], resourceInfo: ResourceInfo, error?: string, extensions?: Record<string, unknown>, transportContext?: unknown): Promise<PaymentRequired>;
433
+ /**
434
+ * Verify a payment against requirements
435
+ *
436
+ * @param paymentPayload - The payment payload to verify
437
+ * @param requirements - The payment requirements
438
+ * @returns Verification response
439
+ */
440
+ verifyPayment(paymentPayload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
441
+ /**
442
+ * Settle a verified payment
443
+ *
444
+ * @param paymentPayload - The payment payload to settle
445
+ * @param requirements - The payment requirements
446
+ * @param declaredExtensions - Optional declared extensions (for per-key enrichment)
447
+ * @param transportContext - Optional transport-specific context (e.g., HTTP request/response, MCP tool context)
448
+ * @returns Settlement response
449
+ */
450
+ settlePayment(paymentPayload: PaymentPayload, requirements: PaymentRequirements, declaredExtensions?: Record<string, unknown>, transportContext?: unknown): Promise<SettleResponse>;
451
+ /**
452
+ * Find matching payment requirements for a payment
453
+ *
454
+ * @param availableRequirements - Array of available payment requirements
455
+ * @param paymentPayload - The payment payload
456
+ * @returns Matching payment requirements or undefined
457
+ */
458
+ findMatchingRequirements(availableRequirements: PaymentRequirements[], paymentPayload: PaymentPayload): PaymentRequirements | undefined;
459
+ /**
460
+ * Process a payment request
461
+ *
462
+ * @param paymentPayload - Optional payment payload if provided
463
+ * @param resourceConfig - Configuration for the protected resource
464
+ * @param resourceInfo - Information about the resource being accessed
465
+ * @param extensions - Optional extensions to include in the response
466
+ * @returns Processing result
467
+ */
468
+ processPaymentRequest(paymentPayload: PaymentPayload | null, resourceConfig: ResourceConfig, resourceInfo: ResourceInfo, extensions?: Record<string, unknown>): Promise<{
469
+ success: boolean;
470
+ requiresPayment?: PaymentRequired;
471
+ verificationResult?: VerifyResponse;
472
+ settlementResult?: SettleResponse;
473
+ error?: string;
474
+ }>;
475
+ /**
476
+ * Get facilitator client for a specific version, network, and scheme
477
+ *
478
+ * @param x402Version - The x402 version
479
+ * @param network - The network identifier
480
+ * @param scheme - The payment scheme
481
+ * @returns The facilitator client or undefined if not found
482
+ */
483
+ private getFacilitatorClient;
484
+ }
485
+
486
+ /**
487
+ * Base interface for facilitator extensions.
488
+ * Extensions registered with x402Facilitator are stored by key and made
489
+ * available to mechanism implementations via FacilitatorContext.
490
+ *
491
+ * Specific extensions extend this with additional capabilities:
492
+ *
493
+ * @example
494
+ * interface Erc20GasSponsoringExtension extends FacilitatorExtension {
495
+ * batchSigner: SmartWalletBatchSigner;
496
+ * }
497
+ */
498
+ interface FacilitatorExtension {
499
+ key: string;
500
+ }
501
+ interface ResourceServerExtension {
502
+ key: string;
503
+ /**
504
+ * Enrich extension declaration with extension-specific data.
505
+ *
506
+ * @param declaration - Extension declaration from route config
507
+ * @param transportContext - Transport-specific context (HTTP, A2A, MCP, etc.)
508
+ * @returns Enriched extension declaration
509
+ */
510
+ enrichDeclaration?: (declaration: unknown, transportContext: unknown) => unknown;
511
+ /**
512
+ * Called when generating a 402 PaymentRequired response.
513
+ * Return extension data to add to extensions[key], or undefined to skip.
514
+ *
515
+ * @param declaration - Extension declaration from route config
516
+ * @param context - PaymentRequired context containing response, requirements, and optional transportContext
517
+ * @returns Extension data to add to response.extensions[key]
518
+ */
519
+ enrichPaymentRequiredResponse?: (declaration: unknown, context: PaymentRequiredContext) => Promise<unknown>;
520
+ /**
521
+ * Called after successful payment settlement.
522
+ * Return extension data to add to response.extensions[key], or undefined to skip.
523
+ *
524
+ * @param declaration - Extension declaration from route config
525
+ * @param context - Settlement result context containing payment payload, requirements, result and optional transportContext
526
+ * @returns Extension data to add to response.extensions[key]
527
+ */
528
+ enrichSettlementResponse?: (declaration: unknown, context: SettleResultContext) => Promise<unknown>;
529
+ }
530
+
531
+ /**
532
+ * Money parser function that converts a numeric amount to an AssetAmount
533
+ * Receives the amount as a decimal number (e.g., 1.50 for $1.50)
534
+ * Returns null to indicate "cannot handle this amount", causing fallback to next parser
535
+ * Always returns a Promise for consistency - use async/await
536
+ *
537
+ * @param amount - The decimal amount (e.g., 1.50)
538
+ * @param network - The network identifier for context
539
+ * @returns AssetAmount or null to try next parser
540
+ */
541
+ type MoneyParser = (amount: number, network: Network) => Promise<AssetAmount | null>;
542
+ /**
543
+ * Result of createPaymentPayload - the core payload fields.
544
+ * Contains the x402 version, scheme-specific payload data, and optional extension data.
545
+ * Schemes may return extensions (e.g., EIP-2612 gas sponsoring) that get merged
546
+ * with server-declared extensions in the final PaymentPayload.
547
+ */
548
+ type PaymentPayloadResult = Pick<PaymentPayload, "x402Version" | "payload"> & {
549
+ extensions?: Record<string, unknown>;
550
+ };
551
+ /**
552
+ * Context passed to scheme's createPaymentPayload for extensions awareness.
553
+ * Contains the server-declared extensions from PaymentRequired so the scheme
554
+ * can check which extensions are advertised and respond accordingly.
555
+ */
556
+ interface PaymentPayloadContext {
557
+ extensions?: Record<string, unknown>;
558
+ }
559
+ interface SchemeNetworkClient {
560
+ readonly scheme: string;
561
+ createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements, context?: PaymentPayloadContext): Promise<PaymentPayloadResult>;
562
+ }
563
+ /**
564
+ * Context passed to SchemeNetworkFacilitator.verify/settle, providing
565
+ * access to registered facilitator extensions. Mechanism implementations
566
+ * use this to retrieve extension-provided capabilities (e.g., a batch signer).
567
+ */
568
+ interface FacilitatorContext {
569
+ getExtension<T extends FacilitatorExtension = FacilitatorExtension>(key: string): T | undefined;
570
+ }
571
+ interface SchemeNetworkFacilitator {
572
+ readonly scheme: string;
573
+ /**
574
+ * CAIP family pattern that this facilitator supports.
575
+ * Used to group signers by blockchain family in the supported response.
576
+ *
577
+ * @example
578
+ * // EVM facilitators
579
+ * readonly caipFamily = "eip155:*";
580
+ *
581
+ * @example
582
+ * // SVM facilitators
583
+ * readonly caipFamily = "solana:*";
584
+ */
585
+ readonly caipFamily: string;
586
+ /**
587
+ * Get mechanism-specific extra data needed for the supported kinds endpoint.
588
+ * This method is called when building the facilitator's supported response.
589
+ *
590
+ * @param network - The network identifier for context
591
+ * @returns Extra data object or undefined if no extra data is needed
592
+ *
593
+ * @example
594
+ * // EVM schemes return undefined (no extra data needed)
595
+ * getExtra(network: Network): undefined {
596
+ * return undefined;
597
+ * }
598
+ *
599
+ * @example
600
+ * // SVM schemes return feePayer address
601
+ * getExtra(network: Network): Record<string, unknown> | undefined {
602
+ * return { feePayer: this.signer.address };
603
+ * }
604
+ */
605
+ getExtra(network: Network): Record<string, unknown> | undefined;
606
+ /**
607
+ * Get signer addresses used by this facilitator for a given network.
608
+ * These are included in the supported response to help clients understand
609
+ * which addresses might sign/pay for transactions.
610
+ *
611
+ * Supports multiple addresses for load balancing, key rotation, and high availability.
612
+ *
613
+ * @param network - The network identifier
614
+ * @returns Array of signer addresses (wallet addresses, fee payer addresses, etc.)
615
+ *
616
+ * @example
617
+ * // EVM facilitator
618
+ * getSigners(network: string): string[] {
619
+ * return [...this.signer.getAddresses()];
620
+ * }
621
+ *
622
+ * @example
623
+ * // SVM facilitator
624
+ * getSigners(network: string): string[] {
625
+ * return [...this.signer.getAddresses()];
626
+ * }
627
+ */
628
+ getSigners(network: string): string[];
629
+ verify(payload: PaymentPayload, requirements: PaymentRequirements, context?: FacilitatorContext): Promise<VerifyResponse>;
630
+ settle(payload: PaymentPayload, requirements: PaymentRequirements, context?: FacilitatorContext): Promise<SettleResponse>;
631
+ }
632
+ interface SchemeNetworkServer {
633
+ readonly scheme: string;
634
+ /**
635
+ * Convert a user-friendly price to the scheme's specific amount and asset format
636
+ * Always returns a Promise for consistency
637
+ *
638
+ * @param price - User-friendly price (e.g., "$0.10", "0.10", { amount: "100000", asset: "USDC" })
639
+ * @param network - The network identifier for context
640
+ * @returns Promise that resolves to the converted amount, asset identifier, and any extra metadata
641
+ *
642
+ * @example
643
+ * // For EVM networks with USDC:
644
+ * await parsePrice("$0.10", "eip155:8453") => { amount: "100000", asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" }
645
+ *
646
+ * // For custom schemes:
647
+ * await parsePrice("10 points", "custom:network") => { amount: "10", asset: "points" }
648
+ */
649
+ parsePrice(price: Price, network: Network): Promise<AssetAmount>;
650
+ /**
651
+ * Build payment requirements for this scheme/network combination
652
+ *
653
+ * @param paymentRequirements - Base payment requirements with amount/asset already set
654
+ * @param supportedKind - The supported kind from facilitator's /supported endpoint
655
+ * @param supportedKind.x402Version - The x402 version
656
+ * @param supportedKind.scheme - The payment scheme
657
+ * @param supportedKind.network - The network identifier
658
+ * @param supportedKind.extra - Optional extra metadata
659
+ * @param facilitatorExtensions - Extensions supported by the facilitator
660
+ * @returns Enhanced payment requirements ready to be sent to clients
661
+ */
662
+ enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
663
+ x402Version: number;
664
+ scheme: string;
665
+ network: Network;
666
+ extra?: Record<string, unknown>;
667
+ }, facilitatorExtensions: string[]): Promise<PaymentRequirements>;
668
+ }
669
+
670
+ type PaymentRequirementsV1 = {
671
+ scheme: string;
672
+ network: Network;
673
+ maxAmountRequired: string;
674
+ resource: string;
675
+ description: string;
676
+ mimeType: string;
677
+ outputSchema: Record<string, unknown>;
678
+ payTo: string;
679
+ maxTimeoutSeconds: number;
680
+ asset: string;
681
+ extra: Record<string, unknown>;
682
+ };
683
+ type PaymentRequiredV1 = {
684
+ x402Version: 1;
685
+ error?: string;
686
+ accepts: PaymentRequirementsV1[];
687
+ };
688
+ type PaymentPayloadV1 = {
689
+ x402Version: 1;
690
+ scheme: string;
691
+ network: Network;
692
+ payload: Record<string, unknown>;
693
+ };
694
+ type VerifyRequestV1 = {
695
+ x402Version: number;
696
+ paymentPayload: PaymentPayloadV1;
697
+ paymentRequirements: PaymentRequirementsV1;
698
+ };
699
+ type SettleRequestV1 = {
700
+ x402Version: number;
701
+ paymentPayload: PaymentPayloadV1;
702
+ paymentRequirements: PaymentRequirementsV1;
703
+ };
704
+ type SettleResponseV1 = {
705
+ success: boolean;
706
+ errorReason?: string;
707
+ errorMessage?: string;
708
+ payer?: string;
709
+ transaction: string;
710
+ network: Network;
711
+ };
712
+ type SupportedResponseV1 = {
713
+ kinds: {
714
+ x402Version: number;
715
+ scheme: string;
716
+ network: Network;
717
+ extra?: Record<string, unknown>;
718
+ }[];
719
+ };
720
+
721
+ type Network = `${string}:${string}`;
722
+ type Money = string | number;
723
+ type AssetAmount = {
724
+ asset: string;
725
+ amount: string;
726
+ extra?: Record<string, unknown>;
727
+ };
728
+ type Price = Money | AssetAmount;
729
+
730
+ /**
731
+ * Information about a token asset on a specific network.
732
+ */
733
+ interface AssetInfo {
734
+ /** Token contract address */
735
+ address: string;
736
+ /** Number of decimal places */
737
+ decimals: number;
738
+ /** Human-readable token name (used in EIP-712 domain) */
739
+ name?: string;
740
+ /** Token version string (used in EIP-712 domain) */
741
+ version?: string;
742
+ /** Transfer method identifier (e.g. "permit2") */
743
+ assetTransferMethod?: string;
744
+ /** Whether the token supports EIP-2612 permit */
745
+ supportsEip2612?: boolean;
746
+ /** Additional metadata */
747
+ [key: string]: unknown;
748
+ }
749
+ /**
750
+ * Registry of known token assets across networks.
751
+ * Provides symbol-based lookup for token metadata.
752
+ */
753
+ declare class AssetRegistry {
754
+ private assets;
755
+ private defaults;
756
+ /** Creates a new AssetRegistry pre-populated with built-in token data. */
757
+ constructor();
758
+ /**
759
+ * Register a single asset for a network.
760
+ *
761
+ * @param network - The network identifier (e.g. "eip155:1")
762
+ * @param symbol - The token symbol (e.g. "USDT")
763
+ * @param info - Asset metadata
764
+ */
765
+ register(network: Network, symbol: string, info: AssetInfo): void;
766
+ /**
767
+ * Batch-register multiple assets for a network.
768
+ *
769
+ * @param network - The network identifier
770
+ * @param assets - Map of symbol to AssetInfo
771
+ */
772
+ registerAll(network: Network, assets: Record<string, AssetInfo>): void;
773
+ /**
774
+ * Set the default asset symbol for a network.
775
+ *
776
+ * @param network - The network identifier
777
+ * @param symbol - The symbol to set as default
778
+ */
779
+ setDefault(network: Network, symbol: string): void;
780
+ /**
781
+ * Resolve a symbol to its AssetInfo on a network.
782
+ *
783
+ * @param network - The network identifier
784
+ * @param symbol - The token symbol
785
+ * @returns The resolved AssetInfo
786
+ * @throws If the asset is not registered
787
+ */
788
+ resolve(network: Network, symbol: string): AssetInfo;
789
+ /**
790
+ * Get the default asset for a network.
791
+ *
792
+ * @param network - The network identifier
793
+ * @returns The default symbol and its AssetInfo
794
+ * @throws If no default is configured
795
+ */
796
+ getDefault(network: Network): {
797
+ symbol: string;
798
+ info: AssetInfo;
799
+ };
800
+ /**
801
+ * List all registered symbols for a network.
802
+ *
803
+ * @param network - The network identifier
804
+ * @returns Array of registered symbols
805
+ */
806
+ getSymbols(network: Network): string[];
807
+ /**
808
+ * Check if an asset is registered on a network.
809
+ *
810
+ * @param network - The network identifier
811
+ * @param symbol - The token symbol
812
+ * @returns True if the asset is registered
813
+ */
814
+ has(network: Network, symbol: string): boolean;
815
+ /**
816
+ * Register built-in known assets.
817
+ * Data sourced from EVM mechanism's getDefaultAsset() and x402-deprecated token registry.
818
+ */
819
+ private registerBuiltins;
820
+ }
821
+ /**
822
+ * Convert a Money value (e.g., "$1.50", 1.5) to token smallest-unit string
823
+ * using the given decimals.
824
+ *
825
+ * @param price - The price as a string or number
826
+ * @param decimals - The number of decimal places for the token
827
+ * @returns The amount in smallest units as a string
828
+ */
829
+ declare function convertMoney(price: string | number, decimals: number): string;
830
+
831
+ export { AssetRegistry as A, type SchemeNetworkServer as B, SettleError as C, type SettleRequest as D, type SupportedResponse as E, type FacilitatorExtension as F, VerifyError as G, HTTPFacilitatorClient as H, type VerifyRequest as I, type Money as M, type Network as N, type PaymentPayload as P, type ResourceConfig as R, type SettleResponse as S, type VerifyResponse as V, type PaymentRequirements as a, type SchemeNetworkFacilitator as b, type PaymentRequired as c, type FacilitatorClient as d, type FacilitatorConfig as e, type AssetInfo as f, convertMoney as g, type SchemeNetworkClient as h, type SettleResultContext as i, type Price as j, type PaymentPayloadV1 as k, type PaymentRequiredV1 as l, type PaymentRequirementsV1 as m, type SettleRequestV1 as n, type SettleResponseV1 as o, type SupportedResponseV1 as p, type VerifyRequestV1 as q, type AssetAmount as r, type FacilitatorContext as s, type MoneyParser as t, type PaymentPayloadContext as u, type PaymentPayloadResult as v, type PaymentRequiredContext as w, x402ResourceServer as x, type ResourceInfo as y, type ResourceServerExtension as z };