@t402/core 2.3.1 → 2.5.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 (49) hide show
  1. package/dist/cjs/client/index.d.ts +3 -2
  2. package/dist/cjs/client/index.js +71 -2
  3. package/dist/cjs/client/index.js.map +1 -1
  4. package/dist/cjs/facilitator/index.d.ts +2 -1
  5. package/dist/cjs/http/index.d.ts +13 -6
  6. package/dist/cjs/http/index.js +76 -5
  7. package/dist/cjs/http/index.js.map +1 -1
  8. package/dist/cjs/mechanisms-dYCiYgko.d.ts +1195 -0
  9. package/dist/cjs/server/index.d.ts +3 -2
  10. package/dist/cjs/server/index.js +70 -3
  11. package/dist/cjs/server/index.js.map +1 -1
  12. package/dist/cjs/{t402HTTPClient-GIweW6nh.d.ts → t402HTTPClient-CHaMMGBY.d.ts} +2 -2
  13. package/dist/cjs/{t402HTTPResourceServer-CcpZF3af.d.ts → t402HTTPResourceServer-B-aOi0BZ.d.ts} +2 -2
  14. package/dist/cjs/types/index.d.ts +2 -1
  15. package/dist/cjs/types/index.js +470 -2
  16. package/dist/cjs/types/index.js.map +1 -1
  17. package/dist/cjs/types/v1/index.d.ts +2 -1
  18. package/dist/cjs/utils/index.d.ts +29 -2
  19. package/dist/cjs/utils/index.js +53 -0
  20. package/dist/cjs/utils/index.js.map +1 -1
  21. package/dist/esm/{chunk-773TNE2Y.mjs → chunk-7RHSIMQL.mjs} +18 -7
  22. package/dist/esm/chunk-7RHSIMQL.mjs.map +1 -0
  23. package/dist/esm/{chunk-3IUBYRYG.mjs → chunk-LJ4M5Z5U.mjs} +51 -1
  24. package/dist/esm/chunk-LJ4M5Z5U.mjs.map +1 -0
  25. package/dist/esm/chunk-STKQDKUH.mjs +101 -0
  26. package/dist/esm/chunk-STKQDKUH.mjs.map +1 -0
  27. package/dist/esm/client/index.d.mts +3 -2
  28. package/dist/esm/client/index.mjs +3 -2
  29. package/dist/esm/client/index.mjs.map +1 -1
  30. package/dist/esm/facilitator/index.d.mts +2 -1
  31. package/dist/esm/http/index.d.mts +13 -6
  32. package/dist/esm/http/index.mjs +3 -2
  33. package/dist/esm/mechanisms-dYCiYgko.d.mts +1195 -0
  34. package/dist/esm/server/index.d.mts +3 -2
  35. package/dist/esm/server/index.mjs +3 -2
  36. package/dist/esm/server/index.mjs.map +1 -1
  37. package/dist/esm/{t402HTTPClient-DbZqiMSO.d.mts → t402HTTPClient-DbIXpGXL.d.mts} +2 -2
  38. package/dist/esm/{t402HTTPResourceServer-BbQ6HVBC.d.mts → t402HTTPResourceServer-CstWZOsH.d.mts} +2 -2
  39. package/dist/esm/types/index.d.mts +2 -1
  40. package/dist/esm/types/index.mjs +304 -1
  41. package/dist/esm/types/index.mjs.map +1 -1
  42. package/dist/esm/types/v1/index.d.mts +2 -1
  43. package/dist/esm/utils/index.d.mts +29 -2
  44. package/dist/esm/utils/index.mjs +7 -1
  45. package/package.json +11 -11
  46. package/dist/cjs/mechanisms-B-vz5yOj.d.ts +0 -443
  47. package/dist/esm/chunk-3IUBYRYG.mjs.map +0 -1
  48. package/dist/esm/chunk-773TNE2Y.mjs.map +0 -1
  49. package/dist/esm/mechanisms-B-vz5yOj.d.mts +0 -443
@@ -0,0 +1,1195 @@
1
+ import { z } from 'zod';
2
+
3
+ type PaymentRequirementsV1 = {
4
+ scheme: string;
5
+ network: Network;
6
+ maxAmountRequired: string;
7
+ resource: string;
8
+ description: string;
9
+ mimeType: string;
10
+ outputSchema: Record<string, unknown>;
11
+ payTo: string;
12
+ maxTimeoutSeconds: number;
13
+ asset: string;
14
+ extra: Record<string, unknown>;
15
+ };
16
+ type PaymentRequiredV1 = {
17
+ t402Version: 1;
18
+ error?: string;
19
+ accepts: PaymentRequirementsV1[];
20
+ };
21
+ type PaymentPayloadV1 = {
22
+ t402Version: 1;
23
+ scheme: string;
24
+ network: Network;
25
+ payload: Record<string, unknown>;
26
+ };
27
+ type VerifyRequestV1 = {
28
+ paymentPayload: PaymentPayloadV1;
29
+ paymentRequirements: PaymentRequirementsV1;
30
+ };
31
+ type SettleRequestV1 = {
32
+ paymentPayload: PaymentPayloadV1;
33
+ paymentRequirements: PaymentRequirementsV1;
34
+ };
35
+ type SettleResponseV1 = {
36
+ success: boolean;
37
+ errorReason?: string;
38
+ payer?: string;
39
+ transaction: string;
40
+ network: Network;
41
+ };
42
+ type SupportedResponseV1 = {
43
+ kinds: {
44
+ t402Version: number;
45
+ scheme: string;
46
+ network: Network;
47
+ extra?: Record<string, unknown>;
48
+ }[];
49
+ };
50
+
51
+ interface ResourceServerExtension {
52
+ key: string;
53
+ enrichDeclaration?: (declaration: unknown, transportContext: unknown) => unknown;
54
+ }
55
+
56
+ /**
57
+ * A2A (Agent-to-Agent) Transport Types
58
+ *
59
+ * Implements t402 payment flows over the Agent-to-Agent protocol
60
+ * using JSON-RPC messages and task-based state management.
61
+ *
62
+ * @see https://github.com/google-a2a/a2a-t402/v0.1
63
+ */
64
+
65
+ /**
66
+ * Payment status values used in A2A metadata
67
+ */
68
+ type A2APaymentStatus = "payment-required" | "payment-rejected" | "payment-submitted" | "payment-verified" | "payment-completed" | "payment-failed";
69
+ /**
70
+ * A2A task states that correspond to payment states
71
+ */
72
+ type A2ATaskState = "submitted" | "working" | "input-required" | "completed" | "canceled" | "failed" | "unknown";
73
+ /**
74
+ * A2A message part - text content
75
+ */
76
+ interface A2ATextPart {
77
+ kind: "text";
78
+ text: string;
79
+ }
80
+ /**
81
+ * A2A message part - file content
82
+ */
83
+ interface A2AFilePart {
84
+ kind: "file";
85
+ file: {
86
+ name?: string;
87
+ mimeType?: string;
88
+ bytes?: string;
89
+ uri?: string;
90
+ };
91
+ }
92
+ /**
93
+ * A2A message part - data content
94
+ */
95
+ interface A2ADataPart {
96
+ kind: "data";
97
+ data: Record<string, unknown>;
98
+ }
99
+ type A2AMessagePart = A2ATextPart | A2AFilePart | A2ADataPart;
100
+ /**
101
+ * A2A payment metadata fields
102
+ */
103
+ interface A2APaymentMetadata {
104
+ /** Current payment status */
105
+ "t402.payment.status"?: A2APaymentStatus;
106
+ /** Payment requirements (when status is payment-required) */
107
+ "t402.payment.required"?: PaymentRequired;
108
+ /** Payment payload (when status is payment-submitted) */
109
+ "t402.payment.payload"?: PaymentPayload;
110
+ /** Settlement receipts (when status is payment-completed or payment-failed) */
111
+ "t402.payment.receipts"?: SettleResponse[];
112
+ /** Error code (when status is payment-failed) */
113
+ "t402.payment.error"?: string;
114
+ }
115
+ /**
116
+ * A2A message with payment metadata
117
+ */
118
+ interface A2AMessage {
119
+ kind: "message";
120
+ messageId?: string;
121
+ role: "user" | "agent";
122
+ parts: A2AMessagePart[];
123
+ metadata?: A2APaymentMetadata & Record<string, unknown>;
124
+ }
125
+ /**
126
+ * A2A artifact (output from completed task)
127
+ */
128
+ interface A2AArtifact {
129
+ kind: string;
130
+ name?: string;
131
+ mimeType?: string;
132
+ data?: string;
133
+ uri?: string;
134
+ metadata?: Record<string, unknown>;
135
+ }
136
+ /**
137
+ * A2A task status
138
+ */
139
+ interface A2ATaskStatus {
140
+ state: A2ATaskState;
141
+ message?: A2AMessage;
142
+ timestamp?: string;
143
+ }
144
+ /**
145
+ * A2A task
146
+ */
147
+ interface A2ATask {
148
+ kind: "task";
149
+ id: string;
150
+ sessionId?: string;
151
+ status: A2ATaskStatus;
152
+ artifacts?: A2AArtifact[];
153
+ history?: A2AMessage[];
154
+ metadata?: Record<string, unknown>;
155
+ }
156
+ /**
157
+ * A2A JSON-RPC request
158
+ */
159
+ interface A2ARequest<T = unknown> {
160
+ jsonrpc: "2.0";
161
+ method: string;
162
+ id: string | number;
163
+ params?: T;
164
+ }
165
+ /**
166
+ * A2A JSON-RPC response
167
+ */
168
+ interface A2AResponse<T = unknown> {
169
+ jsonrpc: "2.0";
170
+ id: string | number;
171
+ result?: T;
172
+ error?: A2AError;
173
+ }
174
+ /**
175
+ * A2A JSON-RPC error
176
+ */
177
+ interface A2AError {
178
+ code: number;
179
+ message: string;
180
+ data?: unknown;
181
+ }
182
+ /**
183
+ * A2A extension declaration
184
+ */
185
+ interface A2AExtension {
186
+ uri: string;
187
+ description?: string;
188
+ required?: boolean;
189
+ }
190
+ /**
191
+ * A2A agent capabilities
192
+ */
193
+ interface A2ACapabilities {
194
+ streaming?: boolean;
195
+ pushNotifications?: boolean;
196
+ stateTransitionHistory?: boolean;
197
+ extensions?: A2AExtension[];
198
+ }
199
+ /**
200
+ * A2A agent card (service advertisement)
201
+ */
202
+ interface A2AAgentCard {
203
+ name: string;
204
+ description?: string;
205
+ url: string;
206
+ provider?: {
207
+ organization?: string;
208
+ url?: string;
209
+ };
210
+ version?: string;
211
+ documentationUrl?: string;
212
+ capabilities?: A2ACapabilities;
213
+ authentication?: {
214
+ schemes: string[];
215
+ credentials?: string;
216
+ };
217
+ defaultInputModes?: string[];
218
+ defaultOutputModes?: string[];
219
+ skills?: A2ASkill[];
220
+ }
221
+ /**
222
+ * A2A skill definition
223
+ */
224
+ interface A2ASkill {
225
+ id: string;
226
+ name: string;
227
+ description?: string;
228
+ tags?: string[];
229
+ examples?: string[];
230
+ inputModes?: string[];
231
+ outputModes?: string[];
232
+ }
233
+ /**
234
+ * T402 A2A extension URI
235
+ */
236
+ declare const T402_A2A_EXTENSION_URI = "https://github.com/google-a2a/a2a-t402/v0.1";
237
+ /**
238
+ * HTTP header for A2A extension activation
239
+ */
240
+ declare const A2A_EXTENSIONS_HEADER = "X-A2A-Extensions";
241
+ /**
242
+ * Check if a task is in a payment-required state
243
+ *
244
+ * @param task - The A2A task to check
245
+ * @returns Whether the task requires payment
246
+ */
247
+ declare function isPaymentRequired(task: A2ATask): boolean;
248
+ /**
249
+ * Check if a task has completed payment
250
+ *
251
+ * @param task - The A2A task to check
252
+ * @returns Whether the task has completed payment
253
+ */
254
+ declare function isPaymentCompleted(task: A2ATask): boolean;
255
+ /**
256
+ * Check if a task has failed payment
257
+ *
258
+ * @param task - The A2A task to check
259
+ * @returns Whether the task has failed payment
260
+ */
261
+ declare function isPaymentFailed(task: A2ATask): boolean;
262
+ /**
263
+ * Extract payment requirements from a task
264
+ *
265
+ * @param task - The A2A task to extract requirements from
266
+ * @returns The payment requirements if the task requires payment
267
+ */
268
+ declare function getPaymentRequired(task: A2ATask): PaymentRequired | undefined;
269
+ /**
270
+ * Extract payment receipts from a task
271
+ *
272
+ * @param task - The A2A task to extract receipts from
273
+ * @returns The settlement receipts if available
274
+ */
275
+ declare function getPaymentReceipts(task: A2ATask): SettleResponse[] | undefined;
276
+ /**
277
+ * Create a payment-required message
278
+ *
279
+ * @param paymentRequired - The payment requirements
280
+ * @param text - Optional message text
281
+ * @returns An A2A message with payment-required metadata
282
+ */
283
+ declare function createPaymentRequiredMessage(paymentRequired: PaymentRequired, text?: string): A2AMessage;
284
+ /**
285
+ * Create a payment submission message
286
+ *
287
+ * @param paymentPayload - The payment payload to submit
288
+ * @param text - Optional message text
289
+ * @returns An A2A message with payment-submitted metadata
290
+ */
291
+ declare function createPaymentSubmissionMessage(paymentPayload: PaymentPayload, text?: string): A2AMessage;
292
+ /**
293
+ * Create a payment completed message
294
+ *
295
+ * @param receipts - The settlement receipts
296
+ * @param text - Optional message text
297
+ * @returns An A2A message with payment-completed metadata
298
+ */
299
+ declare function createPaymentCompletedMessage(receipts: SettleResponse[], text?: string): A2AMessage;
300
+ /**
301
+ * Create a payment failed message
302
+ *
303
+ * @param receipts - The settlement receipts
304
+ * @param errorCode - The error code
305
+ * @param text - Optional message text
306
+ * @returns An A2A message with payment-failed metadata
307
+ */
308
+ declare function createPaymentFailedMessage(receipts: SettleResponse[], errorCode: string, text?: string): A2AMessage;
309
+ /**
310
+ * Create a T402 extension declaration for agent cards
311
+ *
312
+ * @param required - Whether the extension is required
313
+ * @returns An A2A extension declaration
314
+ */
315
+ declare function createT402Extension(required?: boolean): A2AExtension;
316
+
317
+ /**
318
+ * Up-To Scheme Types
319
+ *
320
+ * The `upto` scheme authorizes transfer of up to a maximum amount,
321
+ * enabling usage-based billing where the final settlement amount
322
+ * is determined by actual usage.
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * // Client authorizes up to $1.00
327
+ * const requirements: UptoPaymentRequirements = {
328
+ * scheme: 'upto',
329
+ * network: 'eip155:8453',
330
+ * maxAmount: '1000000', // $1.00 in USDC
331
+ * minAmount: '10000', // $0.01 minimum
332
+ * asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
333
+ * payTo: '0x...',
334
+ * maxTimeoutSeconds: 300,
335
+ * extra: {
336
+ * unit: 'token',
337
+ * unitPrice: '100',
338
+ * },
339
+ * };
340
+ *
341
+ * // Server settles for actual usage ($0.15)
342
+ * const settlement: UptoSettlement = {
343
+ * settleAmount: '150000',
344
+ * usageDetails: {
345
+ * tokensGenerated: 1500,
346
+ * unitPrice: '100',
347
+ * },
348
+ * };
349
+ * ```
350
+ */
351
+
352
+ /**
353
+ * Extended payment requirements for the upto scheme.
354
+ */
355
+ interface UptoPaymentRequirements extends Omit<PaymentRequirements, "scheme" | "amount"> {
356
+ /** Scheme identifier - always 'upto' */
357
+ scheme: "upto";
358
+ /** Network identifier (CAIP-2 format) */
359
+ network: Network;
360
+ /** Maximum amount the client authorizes (in smallest denomination) */
361
+ maxAmount: string;
362
+ /** Minimum settlement amount (prevents dust payments) */
363
+ minAmount?: string;
364
+ /** Asset contract address or identifier */
365
+ asset: string;
366
+ /** Recipient address */
367
+ payTo: string;
368
+ /** Maximum time in seconds before payment expires */
369
+ maxTimeoutSeconds: number;
370
+ /** Additional scheme-specific data */
371
+ extra: UptoExtra;
372
+ }
373
+ /**
374
+ * Extra fields specific to the upto scheme.
375
+ */
376
+ interface UptoExtra extends Record<string, unknown> {
377
+ /** Billing unit (e.g., 'token', 'request', 'second', 'byte') */
378
+ unit?: string;
379
+ /** Price per unit in smallest denomination */
380
+ unitPrice?: string;
381
+ /** EIP-712 domain name (for EVM) */
382
+ name?: string;
383
+ /** EIP-712 domain version (for EVM) */
384
+ version?: string;
385
+ /** Router contract address (for EVM) */
386
+ routerAddress?: string;
387
+ }
388
+ /**
389
+ * Base payload structure for upto scheme.
390
+ */
391
+ interface UptoPayloadBase {
392
+ /** Unique nonce to prevent replay attacks */
393
+ nonce: string;
394
+ }
395
+ /**
396
+ * EVM-specific upto payload using EIP-2612 Permit.
397
+ */
398
+ interface UptoEvmPayload extends UptoPayloadBase {
399
+ /** EIP-2612 permit signature components */
400
+ signature: {
401
+ v: number;
402
+ r: `0x${string}`;
403
+ s: `0x${string}`;
404
+ };
405
+ /** Permit authorization parameters */
406
+ authorization: {
407
+ /** Token owner address */
408
+ owner: `0x${string}`;
409
+ /** Spender address (router contract) */
410
+ spender: `0x${string}`;
411
+ /** Maximum authorized value */
412
+ value: string;
413
+ /** Permit deadline (unix timestamp) */
414
+ deadline: string;
415
+ /** Permit nonce (from token contract) */
416
+ nonce: number;
417
+ };
418
+ }
419
+ /**
420
+ * Alternative EVM payload with combined signature.
421
+ */
422
+ interface UptoEvmPayloadCompact extends UptoPayloadBase {
423
+ /** Combined EIP-2612 permit signature */
424
+ signature: `0x${string}`;
425
+ /** Permit authorization parameters */
426
+ authorization: {
427
+ owner: `0x${string}`;
428
+ spender: `0x${string}`;
429
+ value: string;
430
+ deadline: string;
431
+ nonce: number;
432
+ };
433
+ }
434
+ /**
435
+ * Settlement request for upto scheme.
436
+ */
437
+ interface UptoSettlement {
438
+ /** Actual amount to settle (must be <= maxAmount) */
439
+ settleAmount: string;
440
+ /** Optional usage details for auditing */
441
+ usageDetails?: UptoUsageDetails;
442
+ }
443
+ /**
444
+ * Usage details for settlement auditing.
445
+ */
446
+ interface UptoUsageDetails {
447
+ /** Number of units consumed */
448
+ unitsConsumed?: number;
449
+ /** Price per unit used */
450
+ unitPrice?: string;
451
+ /** Type of unit */
452
+ unitType?: string;
453
+ /** Start timestamp of usage period */
454
+ startTime?: number;
455
+ /** End timestamp of usage period */
456
+ endTime?: number;
457
+ /** Additional metadata */
458
+ metadata?: Record<string, unknown>;
459
+ }
460
+ /**
461
+ * Settlement response for upto scheme.
462
+ */
463
+ interface UptoSettlementResponse {
464
+ /** Whether settlement was successful */
465
+ success: boolean;
466
+ /** Transaction hash (if on-chain) */
467
+ transactionHash?: string;
468
+ /** Actual amount settled */
469
+ settledAmount: string;
470
+ /** Maximum amount that was authorized */
471
+ maxAmount: string;
472
+ /** Block number (if on-chain) */
473
+ blockNumber?: number;
474
+ /** Gas used (if on-chain) */
475
+ gasUsed?: string;
476
+ /** Error message if failed */
477
+ error?: string;
478
+ }
479
+ /**
480
+ * Validation result for upto payment.
481
+ */
482
+ interface UptoValidationResult {
483
+ /** Whether the payment is valid */
484
+ isValid: boolean;
485
+ /** Reason if invalid */
486
+ invalidReason?: string;
487
+ /** Validated maximum amount */
488
+ validatedMaxAmount?: string;
489
+ /** Payer address */
490
+ payer?: string;
491
+ /** Expiration timestamp */
492
+ expiresAt?: number;
493
+ }
494
+ /**
495
+ * Type guard for UptoPaymentRequirements.
496
+ *
497
+ * @param requirements - The value to check
498
+ * @returns True if the value is UptoPaymentRequirements
499
+ */
500
+ declare function isUptoPaymentRequirements(requirements: unknown): requirements is UptoPaymentRequirements;
501
+ /**
502
+ * Type guard for UptoEvmPayload.
503
+ *
504
+ * @param payload - The value to check
505
+ * @returns True if the value is UptoEvmPayload
506
+ */
507
+ declare function isUptoEvmPayload(payload: unknown): payload is UptoEvmPayload;
508
+ /**
509
+ * Constants for upto scheme.
510
+ */
511
+ declare const UPTO_SCHEME: "upto";
512
+ declare const UPTO_DEFAULTS: {
513
+ /** Default minimum settlement amount (prevents dust) */
514
+ readonly MIN_AMOUNT: "1000";
515
+ /** Default maximum timeout in seconds (5 minutes) */
516
+ readonly MAX_TIMEOUT_SECONDS: 300;
517
+ /** Supported billing units */
518
+ readonly UNITS: readonly ["token", "request", "second", "minute", "byte", "kb", "mb"];
519
+ };
520
+ type UptoUnit = (typeof UPTO_DEFAULTS.UNITS)[number];
521
+
522
+ /**
523
+ * Standardized T402 error codes returned by the facilitator API.
524
+ * Error codes follow the format T402-XYYY where X is the category (1-8)
525
+ * and YYY is the specific error within that category.
526
+ */
527
+ declare const ERR_INVALID_REQUEST: "T402-1001";
528
+ declare const ERR_MISSING_PAYLOAD: "T402-1002";
529
+ declare const ERR_MISSING_REQUIREMENTS: "T402-1003";
530
+ declare const ERR_INVALID_PAYLOAD: "T402-1004";
531
+ declare const ERR_INVALID_REQUIREMENTS: "T402-1005";
532
+ declare const ERR_INVALID_SIGNATURE: "T402-1006";
533
+ declare const ERR_INVALID_NETWORK: "T402-1007";
534
+ declare const ERR_INVALID_SCHEME: "T402-1008";
535
+ declare const ERR_INVALID_AMOUNT: "T402-1009";
536
+ declare const ERR_INVALID_ADDRESS: "T402-1010";
537
+ declare const ERR_EXPIRED_PAYMENT: "T402-1011";
538
+ declare const ERR_INVALID_NONCE: "T402-1012";
539
+ declare const ERR_INSUFFICIENT_AMOUNT: "T402-1013";
540
+ declare const ERR_INVALID_IDEMPOTENCY_KEY: "T402-1014";
541
+ declare const ERR_SIGNATURE_EXPIRED: "T402-1015";
542
+ declare const ERR_INTERNAL: "T402-2001";
543
+ declare const ERR_DATABASE_UNAVAILABLE: "T402-2002";
544
+ declare const ERR_CACHE_UNAVAILABLE: "T402-2003";
545
+ declare const ERR_RPC_UNAVAILABLE: "T402-2004";
546
+ declare const ERR_RATE_LIMITED: "T402-2005";
547
+ declare const ERR_SERVICE_UNAVAILABLE: "T402-2006";
548
+ declare const ERR_VERIFICATION_FAILED: "T402-3001";
549
+ declare const ERR_SETTLEMENT_FAILED: "T402-3002";
550
+ declare const ERR_INSUFFICIENT_BALANCE: "T402-3003";
551
+ declare const ERR_ALLOWANCE_INSUFFICIENT: "T402-3004";
552
+ declare const ERR_PAYMENT_MISMATCH: "T402-3005";
553
+ declare const ERR_DUPLICATE_PAYMENT: "T402-3006";
554
+ declare const ERR_SETTLEMENT_PENDING: "T402-3007";
555
+ declare const ERR_SETTLEMENT_TIMEOUT: "T402-3008";
556
+ declare const ERR_NONCE_REPLAY: "T402-3009";
557
+ declare const ERR_IDEMPOTENCY_CONFLICT: "T402-3010";
558
+ declare const ERR_IDEMPOTENCY_UNAVAILABLE: "T402-3011";
559
+ declare const ERR_PREVIOUS_REQUEST_FAILED: "T402-3012";
560
+ declare const ERR_REQUEST_IN_PROGRESS: "T402-3013";
561
+ declare const ERR_CHAIN_UNAVAILABLE: "T402-4001";
562
+ declare const ERR_TRANSACTION_FAILED: "T402-4002";
563
+ declare const ERR_TRANSACTION_REVERTED: "T402-4003";
564
+ declare const ERR_GAS_ESTIMATION_FAILED: "T402-4004";
565
+ declare const ERR_NONCE_CONFLICT: "T402-4005";
566
+ declare const ERR_CHAIN_CONGESTED: "T402-4006";
567
+ declare const ERR_CONTRACT_ERROR: "T402-4007";
568
+ declare const ERR_BRIDGE_UNAVAILABLE: "T402-5001";
569
+ declare const ERR_BRIDGE_QUOTE_FAILED: "T402-5002";
570
+ declare const ERR_BRIDGE_TRANSFER_FAILED: "T402-5003";
571
+ declare const ERR_BRIDGE_TIMEOUT: "T402-5004";
572
+ declare const ERR_UNSUPPORTED_ROUTE: "T402-5005";
573
+ declare const ERR_STREAM_NOT_FOUND: "T402-6001";
574
+ declare const ERR_STREAM_ALREADY_CLOSED: "T402-6002";
575
+ declare const ERR_STREAM_ALREADY_PAUSED: "T402-6003";
576
+ declare const ERR_STREAM_NOT_PAUSED: "T402-6004";
577
+ declare const ERR_STREAM_AMOUNT_EXCEEDED: "T402-6005";
578
+ declare const ERR_STREAM_EXPIRED: "T402-6006";
579
+ declare const ERR_STREAM_INVALID_STATE: "T402-6007";
580
+ declare const ERR_STREAM_RATE_LIMITED: "T402-6008";
581
+ declare const ERR_INTENT_NOT_FOUND: "T402-7001";
582
+ declare const ERR_INTENT_ALREADY_EXECUTED: "T402-7002";
583
+ declare const ERR_INTENT_CANCELLED: "T402-7003";
584
+ declare const ERR_INTENT_EXPIRED: "T402-7004";
585
+ declare const ERR_NO_ROUTES_AVAILABLE: "T402-7005";
586
+ declare const ERR_ROUTE_EXPIRED: "T402-7006";
587
+ declare const ERR_ROUTE_NOT_SELECTED: "T402-7007";
588
+ declare const ERR_INTENT_INVALID_STATE: "T402-7008";
589
+ declare const ERR_RESOURCE_NOT_FOUND: "T402-8001";
590
+ declare const ERR_RESOURCE_ALREADY_EXISTS: "T402-8002";
591
+ declare const ERR_INVALID_PARAMETERS: "T402-8003";
592
+ declare const ERR_NOT_AUTHORIZED: "T402-8004";
593
+ /** Union type of all T402 error codes */
594
+ type ErrorCode = typeof ERR_INVALID_REQUEST | typeof ERR_MISSING_PAYLOAD | typeof ERR_MISSING_REQUIREMENTS | typeof ERR_INVALID_PAYLOAD | typeof ERR_INVALID_REQUIREMENTS | typeof ERR_INVALID_SIGNATURE | typeof ERR_INVALID_NETWORK | typeof ERR_INVALID_SCHEME | typeof ERR_INVALID_AMOUNT | typeof ERR_INVALID_ADDRESS | typeof ERR_EXPIRED_PAYMENT | typeof ERR_INVALID_NONCE | typeof ERR_INSUFFICIENT_AMOUNT | typeof ERR_INVALID_IDEMPOTENCY_KEY | typeof ERR_SIGNATURE_EXPIRED | typeof ERR_INTERNAL | typeof ERR_DATABASE_UNAVAILABLE | typeof ERR_CACHE_UNAVAILABLE | typeof ERR_RPC_UNAVAILABLE | typeof ERR_RATE_LIMITED | typeof ERR_SERVICE_UNAVAILABLE | typeof ERR_VERIFICATION_FAILED | typeof ERR_SETTLEMENT_FAILED | typeof ERR_INSUFFICIENT_BALANCE | typeof ERR_ALLOWANCE_INSUFFICIENT | typeof ERR_PAYMENT_MISMATCH | typeof ERR_DUPLICATE_PAYMENT | typeof ERR_SETTLEMENT_PENDING | typeof ERR_SETTLEMENT_TIMEOUT | typeof ERR_NONCE_REPLAY | typeof ERR_IDEMPOTENCY_CONFLICT | typeof ERR_IDEMPOTENCY_UNAVAILABLE | typeof ERR_PREVIOUS_REQUEST_FAILED | typeof ERR_REQUEST_IN_PROGRESS | typeof ERR_CHAIN_UNAVAILABLE | typeof ERR_TRANSACTION_FAILED | typeof ERR_TRANSACTION_REVERTED | typeof ERR_GAS_ESTIMATION_FAILED | typeof ERR_NONCE_CONFLICT | typeof ERR_CHAIN_CONGESTED | typeof ERR_CONTRACT_ERROR | typeof ERR_BRIDGE_UNAVAILABLE | typeof ERR_BRIDGE_QUOTE_FAILED | typeof ERR_BRIDGE_TRANSFER_FAILED | typeof ERR_BRIDGE_TIMEOUT | typeof ERR_UNSUPPORTED_ROUTE | typeof ERR_STREAM_NOT_FOUND | typeof ERR_STREAM_ALREADY_CLOSED | typeof ERR_STREAM_ALREADY_PAUSED | typeof ERR_STREAM_NOT_PAUSED | typeof ERR_STREAM_AMOUNT_EXCEEDED | typeof ERR_STREAM_EXPIRED | typeof ERR_STREAM_INVALID_STATE | typeof ERR_STREAM_RATE_LIMITED | typeof ERR_INTENT_NOT_FOUND | typeof ERR_INTENT_ALREADY_EXECUTED | typeof ERR_INTENT_CANCELLED | typeof ERR_INTENT_EXPIRED | typeof ERR_NO_ROUTES_AVAILABLE | typeof ERR_ROUTE_EXPIRED | typeof ERR_ROUTE_NOT_SELECTED | typeof ERR_INTENT_INVALID_STATE | typeof ERR_RESOURCE_NOT_FOUND | typeof ERR_RESOURCE_ALREADY_EXISTS | typeof ERR_INVALID_PARAMETERS | typeof ERR_NOT_AUTHORIZED;
595
+ /** Structured error response from the facilitator API */
596
+ interface APIError {
597
+ code: ErrorCode;
598
+ message: string;
599
+ details?: string;
600
+ retry?: boolean;
601
+ }
602
+ /**
603
+ * Returns the HTTP status code for a given error code
604
+ *
605
+ * @param code - The T402 error code
606
+ * @returns The corresponding HTTP status code
607
+ */
608
+ declare function httpStatusForCode(code: ErrorCode): number;
609
+ /**
610
+ * Returns true if the error code is a client error (T402-1xxx)
611
+ *
612
+ * @param code - The T402 error code
613
+ * @returns Whether the error is a client error
614
+ */
615
+ declare function isClientError(code: ErrorCode): boolean;
616
+ /**
617
+ * Returns true if the error code is a server error (T402-2xxx)
618
+ *
619
+ * @param code - The T402 error code
620
+ * @returns Whether the error is a server error
621
+ */
622
+ declare function isServerError(code: ErrorCode): boolean;
623
+ /**
624
+ * Returns true if the error code is a facilitator error (T402-3xxx)
625
+ *
626
+ * @param code - The T402 error code
627
+ * @returns Whether the error is a facilitator error
628
+ */
629
+ declare function isFacilitatorError(code: ErrorCode): boolean;
630
+ /**
631
+ * Returns true if the error code is a chain error (T402-4xxx)
632
+ *
633
+ * @param code - The T402 error code
634
+ * @returns Whether the error is a chain error
635
+ */
636
+ declare function isChainError(code: ErrorCode): boolean;
637
+ /**
638
+ * Returns true if the error code is a bridge error (T402-5xxx)
639
+ *
640
+ * @param code - The T402 error code
641
+ * @returns Whether the error is a bridge error
642
+ */
643
+ declare function isBridgeError(code: ErrorCode): boolean;
644
+
645
+ /**
646
+ * Zod schemas for T402 protocol types.
647
+ * Used for runtime validation of incoming data.
648
+ */
649
+ declare const NetworkSchema: z.ZodString;
650
+ declare const ResourceInfoSchema: z.ZodObject<{
651
+ url: z.ZodString;
652
+ description: z.ZodOptional<z.ZodString>;
653
+ mimeType: z.ZodOptional<z.ZodString>;
654
+ }, "strip", z.ZodTypeAny, {
655
+ url: string;
656
+ description?: string | undefined;
657
+ mimeType?: string | undefined;
658
+ }, {
659
+ url: string;
660
+ description?: string | undefined;
661
+ mimeType?: string | undefined;
662
+ }>;
663
+ declare const PaymentRequirementsSchema: z.ZodObject<{
664
+ scheme: z.ZodString;
665
+ network: z.ZodString;
666
+ asset: z.ZodString;
667
+ amount: z.ZodString;
668
+ payTo: z.ZodString;
669
+ maxTimeoutSeconds: z.ZodNumber;
670
+ extra: z.ZodRecord<z.ZodString, z.ZodUnknown>;
671
+ }, "strip", z.ZodTypeAny, {
672
+ scheme: string;
673
+ amount: string;
674
+ network: string;
675
+ asset: string;
676
+ payTo: string;
677
+ maxTimeoutSeconds: number;
678
+ extra: Record<string, unknown>;
679
+ }, {
680
+ scheme: string;
681
+ amount: string;
682
+ network: string;
683
+ asset: string;
684
+ payTo: string;
685
+ maxTimeoutSeconds: number;
686
+ extra: Record<string, unknown>;
687
+ }>;
688
+ declare const PaymentRequiredSchema: z.ZodObject<{
689
+ t402Version: z.ZodLiteral<2>;
690
+ error: z.ZodOptional<z.ZodString>;
691
+ resource: z.ZodObject<{
692
+ url: z.ZodString;
693
+ description: z.ZodOptional<z.ZodString>;
694
+ mimeType: z.ZodOptional<z.ZodString>;
695
+ }, "strip", z.ZodTypeAny, {
696
+ url: string;
697
+ description?: string | undefined;
698
+ mimeType?: string | undefined;
699
+ }, {
700
+ url: string;
701
+ description?: string | undefined;
702
+ mimeType?: string | undefined;
703
+ }>;
704
+ accepts: z.ZodArray<z.ZodObject<{
705
+ scheme: z.ZodString;
706
+ network: z.ZodString;
707
+ asset: z.ZodString;
708
+ amount: z.ZodString;
709
+ payTo: z.ZodString;
710
+ maxTimeoutSeconds: z.ZodNumber;
711
+ extra: z.ZodRecord<z.ZodString, z.ZodUnknown>;
712
+ }, "strip", z.ZodTypeAny, {
713
+ scheme: string;
714
+ amount: string;
715
+ network: string;
716
+ asset: string;
717
+ payTo: string;
718
+ maxTimeoutSeconds: number;
719
+ extra: Record<string, unknown>;
720
+ }, {
721
+ scheme: string;
722
+ amount: string;
723
+ network: string;
724
+ asset: string;
725
+ payTo: string;
726
+ maxTimeoutSeconds: number;
727
+ extra: Record<string, unknown>;
728
+ }>, "many">;
729
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
730
+ }, "strip", z.ZodTypeAny, {
731
+ t402Version: 2;
732
+ resource: {
733
+ url: string;
734
+ description?: string | undefined;
735
+ mimeType?: string | undefined;
736
+ };
737
+ accepts: {
738
+ scheme: string;
739
+ amount: string;
740
+ network: string;
741
+ asset: string;
742
+ payTo: string;
743
+ maxTimeoutSeconds: number;
744
+ extra: Record<string, unknown>;
745
+ }[];
746
+ error?: string | undefined;
747
+ extensions?: Record<string, unknown> | undefined;
748
+ }, {
749
+ t402Version: 2;
750
+ resource: {
751
+ url: string;
752
+ description?: string | undefined;
753
+ mimeType?: string | undefined;
754
+ };
755
+ accepts: {
756
+ scheme: string;
757
+ amount: string;
758
+ network: string;
759
+ asset: string;
760
+ payTo: string;
761
+ maxTimeoutSeconds: number;
762
+ extra: Record<string, unknown>;
763
+ }[];
764
+ error?: string | undefined;
765
+ extensions?: Record<string, unknown> | undefined;
766
+ }>;
767
+ declare const PaymentPayloadSchema: z.ZodObject<{
768
+ t402Version: z.ZodLiteral<2>;
769
+ resource: z.ZodOptional<z.ZodObject<{
770
+ url: z.ZodString;
771
+ description: z.ZodOptional<z.ZodString>;
772
+ mimeType: z.ZodOptional<z.ZodString>;
773
+ }, "strip", z.ZodTypeAny, {
774
+ url: string;
775
+ description?: string | undefined;
776
+ mimeType?: string | undefined;
777
+ }, {
778
+ url: string;
779
+ description?: string | undefined;
780
+ mimeType?: string | undefined;
781
+ }>>;
782
+ accepted: z.ZodObject<{
783
+ scheme: z.ZodString;
784
+ network: z.ZodString;
785
+ asset: z.ZodString;
786
+ amount: z.ZodString;
787
+ payTo: z.ZodString;
788
+ maxTimeoutSeconds: z.ZodNumber;
789
+ extra: z.ZodRecord<z.ZodString, z.ZodUnknown>;
790
+ }, "strip", z.ZodTypeAny, {
791
+ scheme: string;
792
+ amount: string;
793
+ network: string;
794
+ asset: string;
795
+ payTo: string;
796
+ maxTimeoutSeconds: number;
797
+ extra: Record<string, unknown>;
798
+ }, {
799
+ scheme: string;
800
+ amount: string;
801
+ network: string;
802
+ asset: string;
803
+ payTo: string;
804
+ maxTimeoutSeconds: number;
805
+ extra: Record<string, unknown>;
806
+ }>;
807
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
808
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
809
+ }, "strip", z.ZodTypeAny, {
810
+ t402Version: 2;
811
+ accepted: {
812
+ scheme: string;
813
+ amount: string;
814
+ network: string;
815
+ asset: string;
816
+ payTo: string;
817
+ maxTimeoutSeconds: number;
818
+ extra: Record<string, unknown>;
819
+ };
820
+ payload: Record<string, unknown>;
821
+ resource?: {
822
+ url: string;
823
+ description?: string | undefined;
824
+ mimeType?: string | undefined;
825
+ } | undefined;
826
+ extensions?: Record<string, unknown> | undefined;
827
+ }, {
828
+ t402Version: 2;
829
+ accepted: {
830
+ scheme: string;
831
+ amount: string;
832
+ network: string;
833
+ asset: string;
834
+ payTo: string;
835
+ maxTimeoutSeconds: number;
836
+ extra: Record<string, unknown>;
837
+ };
838
+ payload: Record<string, unknown>;
839
+ resource?: {
840
+ url: string;
841
+ description?: string | undefined;
842
+ mimeType?: string | undefined;
843
+ } | undefined;
844
+ extensions?: Record<string, unknown> | undefined;
845
+ }>;
846
+ declare const VerifyResponseSchema: z.ZodObject<{
847
+ isValid: z.ZodBoolean;
848
+ invalidReason: z.ZodOptional<z.ZodString>;
849
+ payer: z.ZodOptional<z.ZodString>;
850
+ }, "strip", z.ZodTypeAny, {
851
+ isValid: boolean;
852
+ invalidReason?: string | undefined;
853
+ payer?: string | undefined;
854
+ }, {
855
+ isValid: boolean;
856
+ invalidReason?: string | undefined;
857
+ payer?: string | undefined;
858
+ }>;
859
+ declare const SettleResponseSchema: z.ZodObject<{
860
+ success: z.ZodBoolean;
861
+ transaction: z.ZodString;
862
+ network: z.ZodString;
863
+ errorReason: z.ZodOptional<z.ZodString>;
864
+ payer: z.ZodOptional<z.ZodString>;
865
+ confirmations: z.ZodOptional<z.ZodString>;
866
+ }, "strip", z.ZodTypeAny, {
867
+ network: string;
868
+ success: boolean;
869
+ transaction: string;
870
+ payer?: string | undefined;
871
+ errorReason?: string | undefined;
872
+ confirmations?: string | undefined;
873
+ }, {
874
+ network: string;
875
+ success: boolean;
876
+ transaction: string;
877
+ payer?: string | undefined;
878
+ errorReason?: string | undefined;
879
+ confirmations?: string | undefined;
880
+ }>;
881
+ declare const PaymentRequirementsV1Schema: z.ZodObject<{
882
+ scheme: z.ZodString;
883
+ network: z.ZodString;
884
+ asset: z.ZodString;
885
+ amount: z.ZodString;
886
+ payTo: z.ZodString;
887
+ maxTimeoutSeconds: z.ZodNumber;
888
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
889
+ }, "strip", z.ZodTypeAny, {
890
+ scheme: string;
891
+ amount: string;
892
+ network: string;
893
+ asset: string;
894
+ payTo: string;
895
+ maxTimeoutSeconds: number;
896
+ extra?: Record<string, unknown> | undefined;
897
+ }, {
898
+ scheme: string;
899
+ amount: string;
900
+ network: string;
901
+ asset: string;
902
+ payTo: string;
903
+ maxTimeoutSeconds: number;
904
+ extra?: Record<string, unknown> | undefined;
905
+ }>;
906
+ declare const PaymentPayloadV1Schema: z.ZodObject<{
907
+ t402Version: z.ZodOptional<z.ZodLiteral<1>>;
908
+ accepted: z.ZodObject<{
909
+ scheme: z.ZodString;
910
+ network: z.ZodString;
911
+ asset: z.ZodString;
912
+ amount: z.ZodString;
913
+ payTo: z.ZodString;
914
+ maxTimeoutSeconds: z.ZodNumber;
915
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
916
+ }, "strip", z.ZodTypeAny, {
917
+ scheme: string;
918
+ amount: string;
919
+ network: string;
920
+ asset: string;
921
+ payTo: string;
922
+ maxTimeoutSeconds: number;
923
+ extra?: Record<string, unknown> | undefined;
924
+ }, {
925
+ scheme: string;
926
+ amount: string;
927
+ network: string;
928
+ asset: string;
929
+ payTo: string;
930
+ maxTimeoutSeconds: number;
931
+ extra?: Record<string, unknown> | undefined;
932
+ }>;
933
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
934
+ }, "strip", z.ZodTypeAny, {
935
+ accepted: {
936
+ scheme: string;
937
+ amount: string;
938
+ network: string;
939
+ asset: string;
940
+ payTo: string;
941
+ maxTimeoutSeconds: number;
942
+ extra?: Record<string, unknown> | undefined;
943
+ };
944
+ payload: Record<string, unknown>;
945
+ t402Version?: 1 | undefined;
946
+ }, {
947
+ accepted: {
948
+ scheme: string;
949
+ amount: string;
950
+ network: string;
951
+ asset: string;
952
+ payTo: string;
953
+ maxTimeoutSeconds: number;
954
+ extra?: Record<string, unknown> | undefined;
955
+ };
956
+ payload: Record<string, unknown>;
957
+ t402Version?: 1 | undefined;
958
+ }>;
959
+ type ValidatedPaymentPayload = z.infer<typeof PaymentPayloadSchema>;
960
+ type ValidatedPaymentRequired = z.infer<typeof PaymentRequiredSchema>;
961
+ type ValidatedPaymentRequirements = z.infer<typeof PaymentRequirementsSchema>;
962
+ type ValidatedVerifyResponse = z.infer<typeof VerifyResponseSchema>;
963
+ type ValidatedSettleResponse = z.infer<typeof SettleResponseSchema>;
964
+ /**
965
+ * Parse and validate a PaymentPayload.
966
+ *
967
+ * @param data - The data to parse
968
+ * @returns The validated payment payload
969
+ * @throws ZodError if validation fails
970
+ */
971
+ declare function parsePaymentPayload(data: unknown): ValidatedPaymentPayload;
972
+ /**
973
+ * Parse and validate a PaymentRequired response.
974
+ *
975
+ * @param data - The data to parse
976
+ * @returns The validated payment required response
977
+ * @throws ZodError if validation fails
978
+ */
979
+ declare function parsePaymentRequired(data: unknown): ValidatedPaymentRequired;
980
+ /**
981
+ * Parse and validate PaymentRequirements.
982
+ *
983
+ * @param data - The data to parse
984
+ * @returns The validated payment requirements
985
+ * @throws ZodError if validation fails
986
+ */
987
+ declare function parsePaymentRequirements(data: unknown): ValidatedPaymentRequirements;
988
+ /**
989
+ * Safely parse a PaymentPayload, returning a result object.
990
+ *
991
+ * @param data - The data to parse
992
+ * @returns The safe parse result
993
+ */
994
+ declare function safeParsePaymentPayload(data: unknown): z.SafeParseReturnType<unknown, ValidatedPaymentPayload>;
995
+ /**
996
+ * Safely parse a PaymentRequired response, returning a result object.
997
+ *
998
+ * @param data - The data to parse
999
+ * @returns The safe parse result
1000
+ */
1001
+ declare function safeParsePaymentRequired(data: unknown): z.SafeParseReturnType<unknown, ValidatedPaymentRequired>;
1002
+ /**
1003
+ * Safely parse PaymentRequirements, returning a result object.
1004
+ *
1005
+ * @param data - The data to parse
1006
+ * @returns The safe parse result
1007
+ */
1008
+ declare function safeParsePaymentRequirements(data: unknown): z.SafeParseReturnType<unknown, ValidatedPaymentRequirements>;
1009
+
1010
+ type Network = `${string}:${string}`;
1011
+ type Money = string | number;
1012
+ type AssetAmount = {
1013
+ asset: string;
1014
+ amount: string;
1015
+ extra?: Record<string, unknown>;
1016
+ };
1017
+ type Price = Money | AssetAmount;
1018
+
1019
+ interface ResourceInfo {
1020
+ url: string;
1021
+ description?: string;
1022
+ mimeType?: string;
1023
+ }
1024
+ type PaymentRequirements = {
1025
+ scheme: string;
1026
+ network: Network;
1027
+ asset: string;
1028
+ amount: string;
1029
+ payTo: string;
1030
+ maxTimeoutSeconds: number;
1031
+ extra: Record<string, unknown>;
1032
+ };
1033
+ type PaymentRequired = {
1034
+ t402Version: number;
1035
+ error?: string;
1036
+ resource: ResourceInfo;
1037
+ accepts: PaymentRequirements[];
1038
+ extensions?: Record<string, unknown>;
1039
+ };
1040
+ type PaymentPayload = {
1041
+ t402Version: number;
1042
+ resource?: ResourceInfo;
1043
+ accepted: PaymentRequirements;
1044
+ payload: Record<string, unknown>;
1045
+ extensions?: Record<string, unknown>;
1046
+ };
1047
+
1048
+ type VerifyRequest = {
1049
+ paymentPayload: PaymentPayload;
1050
+ paymentRequirements: PaymentRequirements;
1051
+ };
1052
+ type VerifyResponse = {
1053
+ isValid: boolean;
1054
+ invalidReason?: string;
1055
+ payer?: string;
1056
+ };
1057
+ type SettleRequest = {
1058
+ paymentPayload: PaymentPayload;
1059
+ paymentRequirements: PaymentRequirements;
1060
+ };
1061
+ type SettleResponse = {
1062
+ success: boolean;
1063
+ errorReason?: string;
1064
+ payer?: string;
1065
+ transaction: string;
1066
+ network: Network;
1067
+ confirmations?: string;
1068
+ };
1069
+ type SupportedKind = {
1070
+ t402Version: number;
1071
+ scheme: string;
1072
+ network: Network;
1073
+ extra?: Record<string, unknown>;
1074
+ };
1075
+ type SupportedResponse = {
1076
+ kinds: SupportedKind[];
1077
+ extensions: string[];
1078
+ signers: Record<string, string[]>;
1079
+ };
1080
+
1081
+ /**
1082
+ * Money parser function that converts a numeric amount to an AssetAmount
1083
+ * Receives the amount as a decimal number (e.g., 1.50 for $1.50)
1084
+ * Returns null to indicate "cannot handle this amount", causing fallback to next parser
1085
+ * Always returns a Promise for consistency - use async/await
1086
+ *
1087
+ * @param amount - The decimal amount (e.g., 1.50)
1088
+ * @param network - The network identifier for context
1089
+ * @returns AssetAmount or null to try next parser
1090
+ */
1091
+ type MoneyParser = (amount: number, network: Network) => Promise<AssetAmount | null>;
1092
+ interface SchemeNetworkClient {
1093
+ readonly scheme: string;
1094
+ createPaymentPayload(t402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "t402Version" | "payload">>;
1095
+ }
1096
+ interface SchemeNetworkFacilitator {
1097
+ readonly scheme: string;
1098
+ /**
1099
+ * CAIP family pattern that this facilitator supports.
1100
+ * Used to group signers by blockchain family in the supported response.
1101
+ *
1102
+ * @example
1103
+ * // EVM facilitators
1104
+ * readonly caipFamily = "eip155:*";
1105
+ *
1106
+ * @example
1107
+ * // SVM facilitators
1108
+ * readonly caipFamily = "solana:*";
1109
+ */
1110
+ readonly caipFamily: string;
1111
+ /**
1112
+ * Get mechanism-specific extra data needed for the supported kinds endpoint.
1113
+ * This method is called when building the facilitator's supported response.
1114
+ *
1115
+ * @param network - The network identifier for context
1116
+ * @returns Extra data object or undefined if no extra data is needed
1117
+ *
1118
+ * @example
1119
+ * // EVM schemes return undefined (no extra data needed)
1120
+ * getExtra(network: Network): undefined {
1121
+ * return undefined;
1122
+ * }
1123
+ *
1124
+ * @example
1125
+ * // SVM schemes return feePayer address
1126
+ * getExtra(network: Network): Record<string, unknown> | undefined {
1127
+ * return { feePayer: this.signer.address };
1128
+ * }
1129
+ */
1130
+ getExtra(network: Network): Record<string, unknown> | undefined;
1131
+ /**
1132
+ * Get signer addresses used by this facilitator for a given network.
1133
+ * These are included in the supported response to help clients understand
1134
+ * which addresses might sign/pay for transactions.
1135
+ *
1136
+ * Supports multiple addresses for load balancing, key rotation, and high availability.
1137
+ *
1138
+ * @param network - The network identifier
1139
+ * @returns Array of signer addresses (wallet addresses, fee payer addresses, etc.)
1140
+ *
1141
+ * @example
1142
+ * // EVM facilitator
1143
+ * getSigners(network: string): string[] {
1144
+ * return [...this.signer.getAddresses()];
1145
+ * }
1146
+ *
1147
+ * @example
1148
+ * // SVM facilitator
1149
+ * getSigners(network: string): string[] {
1150
+ * return [...this.signer.getAddresses()];
1151
+ * }
1152
+ */
1153
+ getSigners(network: string): string[];
1154
+ verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
1155
+ settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
1156
+ }
1157
+ interface SchemeNetworkServer {
1158
+ readonly scheme: string;
1159
+ /**
1160
+ * Convert a user-friendly price to the scheme's specific amount and asset format
1161
+ * Always returns a Promise for consistency
1162
+ *
1163
+ * @param price - User-friendly price (e.g., "$0.10", "0.10", { amount: "100000", asset: "USDC" })
1164
+ * @param network - The network identifier for context
1165
+ * @returns Promise that resolves to the converted amount, asset identifier, and any extra metadata
1166
+ *
1167
+ * @example
1168
+ * // For EVM networks with USDC:
1169
+ * await parsePrice("$0.10", "eip155:8453") => { amount: "100000", asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" }
1170
+ *
1171
+ * // For custom schemes:
1172
+ * await parsePrice("10 points", "custom:network") => { amount: "10", asset: "points" }
1173
+ */
1174
+ parsePrice(price: Price, network: Network): Promise<AssetAmount>;
1175
+ /**
1176
+ * Build payment requirements for this scheme/network combination
1177
+ *
1178
+ * @param paymentRequirements - Base payment requirements with amount/asset already set
1179
+ * @param supportedKind - The supported kind from facilitator's /supported endpoint
1180
+ * @param supportedKind.t402Version - The t402 version
1181
+ * @param supportedKind.scheme - The payment scheme
1182
+ * @param supportedKind.network - The network identifier
1183
+ * @param supportedKind.extra - Optional extra metadata
1184
+ * @param facilitatorExtensions - Extensions supported by the facilitator
1185
+ * @returns Enhanced payment requirements ready to be sent to clients
1186
+ */
1187
+ enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
1188
+ t402Version: number;
1189
+ scheme: string;
1190
+ network: Network;
1191
+ extra?: Record<string, unknown>;
1192
+ }, facilitatorExtensions: string[]): Promise<PaymentRequirements>;
1193
+ }
1194
+
1195
+ export { ERR_GAS_ESTIMATION_FAILED as $, type A2AAgentCard as A, type A2AResponse as B, type A2ASkill as C, type A2ATask as D, type A2ATaskState as E, type A2ATaskStatus as F, type A2ATextPart as G, A2A_EXTENSIONS_HEADER as H, type APIError as I, type AssetAmount as J, ERR_ALLOWANCE_INSUFFICIENT as K, ERR_BRIDGE_QUOTE_FAILED as L, ERR_BRIDGE_TIMEOUT as M, type Network as N, ERR_BRIDGE_TRANSFER_FAILED as O, type PaymentRequirements as P, ERR_BRIDGE_UNAVAILABLE as Q, type ResourceServerExtension as R, type SettleResponse as S, ERR_CACHE_UNAVAILABLE as T, ERR_CHAIN_CONGESTED as U, type VerifyResponse as V, ERR_CHAIN_UNAVAILABLE as W, ERR_CONTRACT_ERROR as X, ERR_DATABASE_UNAVAILABLE as Y, ERR_DUPLICATE_PAYMENT as Z, ERR_EXPIRED_PAYMENT as _, type PaymentPayload as a, type SettleRequest as a$, ERR_IDEMPOTENCY_CONFLICT as a0, ERR_IDEMPOTENCY_UNAVAILABLE as a1, ERR_INSUFFICIENT_AMOUNT as a2, ERR_INSUFFICIENT_BALANCE as a3, ERR_INTENT_ALREADY_EXECUTED as a4, ERR_INTENT_CANCELLED as a5, ERR_INTENT_EXPIRED as a6, ERR_INTENT_INVALID_STATE as a7, ERR_INTENT_NOT_FOUND as a8, ERR_INTERNAL as a9, ERR_SERVICE_UNAVAILABLE as aA, ERR_SETTLEMENT_FAILED as aB, ERR_SETTLEMENT_PENDING as aC, ERR_SETTLEMENT_TIMEOUT as aD, ERR_SIGNATURE_EXPIRED as aE, ERR_STREAM_ALREADY_CLOSED as aF, ERR_STREAM_ALREADY_PAUSED as aG, ERR_STREAM_AMOUNT_EXCEEDED as aH, ERR_STREAM_EXPIRED as aI, ERR_STREAM_INVALID_STATE as aJ, ERR_STREAM_NOT_FOUND as aK, ERR_STREAM_NOT_PAUSED as aL, ERR_STREAM_RATE_LIMITED as aM, ERR_TRANSACTION_FAILED as aN, ERR_TRANSACTION_REVERTED as aO, ERR_UNSUPPORTED_ROUTE as aP, ERR_VERIFICATION_FAILED as aQ, type ErrorCode as aR, type Money as aS, type MoneyParser as aT, NetworkSchema as aU, PaymentPayloadSchema as aV, PaymentPayloadV1Schema as aW, PaymentRequiredSchema as aX, PaymentRequirementsSchema as aY, PaymentRequirementsV1Schema as aZ, ResourceInfoSchema as a_, ERR_INVALID_ADDRESS as aa, ERR_INVALID_AMOUNT as ab, ERR_INVALID_IDEMPOTENCY_KEY as ac, ERR_INVALID_NETWORK as ad, ERR_INVALID_NONCE as ae, ERR_INVALID_PARAMETERS as af, ERR_INVALID_PAYLOAD as ag, ERR_INVALID_REQUEST as ah, ERR_INVALID_REQUIREMENTS as ai, ERR_INVALID_SCHEME as aj, ERR_INVALID_SIGNATURE as ak, ERR_MISSING_PAYLOAD as al, ERR_MISSING_REQUIREMENTS as am, ERR_NONCE_CONFLICT as an, ERR_NONCE_REPLAY as ao, ERR_NOT_AUTHORIZED as ap, ERR_NO_ROUTES_AVAILABLE as aq, ERR_PAYMENT_MISMATCH as ar, ERR_PREVIOUS_REQUEST_FAILED as as, ERR_RATE_LIMITED as at, ERR_REQUEST_IN_PROGRESS as au, ERR_RESOURCE_ALREADY_EXISTS as av, ERR_RESOURCE_NOT_FOUND as aw, ERR_ROUTE_EXPIRED as ax, ERR_ROUTE_NOT_SELECTED as ay, ERR_RPC_UNAVAILABLE as az, type SchemeNetworkFacilitator as b, SettleResponseSchema as b0, T402_A2A_EXTENSION_URI as b1, UPTO_DEFAULTS as b2, UPTO_SCHEME as b3, type UptoEvmPayload as b4, type UptoEvmPayloadCompact as b5, type UptoExtra as b6, type UptoPayloadBase as b7, type UptoPaymentRequirements as b8, type UptoSettlement as b9, isServerError as bA, isUptoEvmPayload as bB, isUptoPaymentRequirements as bC, parsePaymentPayload as bD, parsePaymentRequired as bE, parsePaymentRequirements as bF, safeParsePaymentPayload as bG, safeParsePaymentRequired as bH, safeParsePaymentRequirements as bI, type UptoSettlementResponse as ba, type UptoUnit as bb, type UptoUsageDetails as bc, type UptoValidationResult as bd, type ValidatedPaymentPayload as be, type ValidatedPaymentRequired as bf, type ValidatedPaymentRequirements as bg, type ValidatedSettleResponse as bh, type ValidatedVerifyResponse as bi, type VerifyRequest as bj, VerifyResponseSchema as bk, createPaymentCompletedMessage as bl, createPaymentFailedMessage as bm, createPaymentRequiredMessage as bn, createPaymentSubmissionMessage as bo, createT402Extension as bp, getPaymentReceipts as bq, getPaymentRequired as br, httpStatusForCode as bs, isBridgeError as bt, isChainError as bu, isClientError as bv, isFacilitatorError as bw, isPaymentCompleted as bx, isPaymentFailed as by, isPaymentRequired as bz, type PaymentRequired as c, type SchemeNetworkClient as d, type SupportedResponse as e, type SchemeNetworkServer as f, type SupportedKind 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 A2AArtifact as p, type A2ACapabilities as q, type A2ADataPart as r, type A2AError as s, type A2AExtension as t, type A2AFilePart as u, type A2AMessage as v, type A2AMessagePart as w, type A2APaymentMetadata as x, type A2APaymentStatus as y, type A2ARequest as z };