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