@wtflabs/x402-server 0.0.1-beta.10

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.
@@ -0,0 +1,1750 @@
1
+ import { PublicClient } from 'viem';
2
+ import { TokenDetector } from '@wtflabs/x402-detector';
3
+ import { Facilitator } from '@wtflabs/x402-facilitator';
4
+ export { WaitUntil } from '@wtflabs/x402-facilitator';
5
+ import { PaymentRequirementsSchema, PaymentPayloadSchema } from '@wtflabs/x402/types';
6
+ export { PaymentPayloadSchema, PaymentRequirementsSchema } from '@wtflabs/x402/types';
7
+ import { z } from 'zod';
8
+
9
+ /**
10
+ * CreateRequirementsConfig Schema
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const config = {
15
+ * asset: "0x1234567890abcdef1234567890abcdef12345678",
16
+ * maxAmountRequired: "1000",
17
+ * };
18
+ * ```
19
+ *
20
+ * @returns CreateRequirementsConfigSchema
21
+ */
22
+ declare const CreateRequirementsConfigSchema: z.ZodObject<{
23
+ asset: z.ZodString;
24
+ maxAmountRequired: z.ZodEffects<z.ZodString, string, string>;
25
+ network: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
26
+ scheme: z.ZodOptional<z.ZodLiteral<"exact">>;
27
+ outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
28
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
29
+ paymentType: z.ZodOptional<z.ZodEnum<["permit", "eip3009", "permit2", "auto"]>>;
30
+ resource: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
31
+ description: z.ZodOptional<z.ZodString>;
32
+ mimeType: z.ZodOptional<z.ZodString>;
33
+ maxTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
34
+ autoDetect: z.ZodOptional<z.ZodBoolean>;
35
+ }, "strip", z.ZodTypeAny, {
36
+ asset: string;
37
+ maxAmountRequired: string;
38
+ network: "base-sepolia" | "base" | "avalanche-fuji" | "avalanche" | "iotex" | "solana-devnet" | "solana" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "bsc" | "bsc-testnet";
39
+ scheme?: "exact" | undefined;
40
+ outputSchema?: Record<string, any> | undefined;
41
+ extra?: Record<string, any> | undefined;
42
+ paymentType?: "permit" | "eip3009" | "permit2" | "auto" | undefined;
43
+ resource?: string | undefined;
44
+ description?: string | undefined;
45
+ mimeType?: string | undefined;
46
+ maxTimeoutSeconds?: number | undefined;
47
+ autoDetect?: boolean | undefined;
48
+ }, {
49
+ asset: string;
50
+ maxAmountRequired: string;
51
+ network: "base-sepolia" | "base" | "avalanche-fuji" | "avalanche" | "iotex" | "solana-devnet" | "solana" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "bsc" | "bsc-testnet";
52
+ scheme?: "exact" | undefined;
53
+ outputSchema?: Record<string, any> | undefined;
54
+ extra?: Record<string, any> | undefined;
55
+ paymentType?: "permit" | "eip3009" | "permit2" | "auto" | undefined;
56
+ resource?: string | undefined;
57
+ description?: string | undefined;
58
+ mimeType?: string | undefined;
59
+ maxTimeoutSeconds?: number | undefined;
60
+ autoDetect?: boolean | undefined;
61
+ }>;
62
+ type CreateRequirementsConfig = z.infer<typeof CreateRequirementsConfigSchema>;
63
+ /**
64
+ * PaymentRequirements Schema
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const requirements = {
69
+ * x402Version: 1,
70
+ * scheme: "exact",
71
+ * network: "ethereum-mainnet",
72
+ * maxAmountRequired: "1000",
73
+ * payTo: "0x1234567890abcdef1234567890abcdef12345678",
74
+ * asset: "0x1234567890abcdef1234567890abcdef12345678",
75
+ * maxTimeoutSeconds: 300,
76
+ * resource: "https://api.example.com/data",
77
+ * description: "API access",
78
+ * mimeType: "application/json",
79
+ * paymentType: "permit",
80
+ * extra: {
81
+ * relayer: "0x1234567890abcdef1234567890abcdef12345678",
82
+ * name: "API access",
83
+ * version: "1.0.0",
84
+ * },
85
+ * };
86
+ * ```
87
+ *
88
+ * @returns PaymentRequirementsSchema
89
+ */
90
+ type PaymentRequirements = z.infer<typeof PaymentRequirementsSchema>;
91
+ /**
92
+ * PaymentPayload Schema
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const payload = {
97
+ * x402Version: 1,
98
+ * scheme: "exact",
99
+ * network: "ethereum-mainnet",
100
+ * payload: {
101
+ * maxAmountRequired: "1000",
102
+ * asset: "0x1234567890abcdef1234567890abcdef12345678",
103
+ * recipient: "0x1234567890abcdef1234567890abcdef12345678",
104
+ * nonce: "1234567890abcdef1234567890abcdef12345678",
105
+ * expiration: 1715000000,
106
+ * },
107
+ * };
108
+ * ```
109
+ */
110
+ type PaymentPayload = z.infer<typeof PaymentPayloadSchema>;
111
+ /**
112
+ * Response402 Schema
113
+ */
114
+ declare const Response402Schema: z.ZodObject<{
115
+ x402Version: z.ZodLiteral<1>;
116
+ accepts: z.ZodArray<z.ZodObject<{
117
+ scheme: z.ZodEnum<["exact"]>;
118
+ network: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
119
+ maxAmountRequired: z.ZodEffects<z.ZodString, string, string>;
120
+ resource: z.ZodString;
121
+ description: z.ZodString;
122
+ mimeType: z.ZodString;
123
+ outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
124
+ payTo: z.ZodUnion<[z.ZodString, z.ZodString]>;
125
+ maxTimeoutSeconds: z.ZodNumber;
126
+ asset: z.ZodUnion<[z.ZodString, z.ZodString]>;
127
+ paymentType: z.ZodOptional<z.ZodEnum<["eip3009", "permit", "permit2"]>>;
128
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
129
+ }, "strip", z.ZodTypeAny, {
130
+ scheme: "exact";
131
+ description: string;
132
+ asset: string;
133
+ maxAmountRequired: string;
134
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
135
+ resource: string;
136
+ mimeType: string;
137
+ payTo: string;
138
+ maxTimeoutSeconds: number;
139
+ outputSchema?: Record<string, any> | undefined;
140
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
141
+ extra?: Record<string, any> | undefined;
142
+ }, {
143
+ scheme: "exact";
144
+ description: string;
145
+ asset: string;
146
+ maxAmountRequired: string;
147
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
148
+ resource: string;
149
+ mimeType: string;
150
+ payTo: string;
151
+ maxTimeoutSeconds: number;
152
+ outputSchema?: Record<string, any> | undefined;
153
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
154
+ extra?: Record<string, any> | undefined;
155
+ }>, "many">;
156
+ error: z.ZodOptional<z.ZodString>;
157
+ }, "strip", z.ZodTypeAny, {
158
+ x402Version: 1;
159
+ accepts: {
160
+ scheme: "exact";
161
+ description: string;
162
+ asset: string;
163
+ maxAmountRequired: string;
164
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
165
+ resource: string;
166
+ mimeType: string;
167
+ payTo: string;
168
+ maxTimeoutSeconds: number;
169
+ outputSchema?: Record<string, any> | undefined;
170
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
171
+ extra?: Record<string, any> | undefined;
172
+ }[];
173
+ error?: string | undefined;
174
+ }, {
175
+ x402Version: 1;
176
+ accepts: {
177
+ scheme: "exact";
178
+ description: string;
179
+ asset: string;
180
+ maxAmountRequired: string;
181
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
182
+ resource: string;
183
+ mimeType: string;
184
+ payTo: string;
185
+ maxTimeoutSeconds: number;
186
+ outputSchema?: Record<string, any> | undefined;
187
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
188
+ extra?: Record<string, any> | undefined;
189
+ }[];
190
+ error?: string | undefined;
191
+ }>;
192
+ type Response402 = z.infer<typeof Response402Schema>;
193
+ /**
194
+ * InitResult Schema
195
+ */
196
+ declare const InitResultSchema: z.ZodDiscriminatedUnion<"success", [z.ZodObject<{
197
+ success: z.ZodLiteral<true>;
198
+ }, "strip", z.ZodTypeAny, {
199
+ success: true;
200
+ }, {
201
+ success: true;
202
+ }>, z.ZodObject<{
203
+ success: z.ZodLiteral<false>;
204
+ error: z.ZodString;
205
+ }, "strip", z.ZodTypeAny, {
206
+ error: string;
207
+ success: false;
208
+ }, {
209
+ error: string;
210
+ success: false;
211
+ }>]>;
212
+ type InitResult = z.infer<typeof InitResultSchema>;
213
+ /**
214
+ * ProcessResult Schema
215
+ */
216
+ declare const ProcessResultSchema: z.ZodDiscriminatedUnion<"success", [z.ZodObject<{
217
+ success: z.ZodLiteral<true>;
218
+ status: z.ZodLiteral<200>;
219
+ data: z.ZodObject<{
220
+ payer: z.ZodString;
221
+ txHash: z.ZodString;
222
+ }, "strip", z.ZodTypeAny, {
223
+ payer: string;
224
+ txHash: string;
225
+ }, {
226
+ payer: string;
227
+ txHash: string;
228
+ }>;
229
+ }, "strip", z.ZodTypeAny, {
230
+ status: 200;
231
+ success: true;
232
+ data: {
233
+ payer: string;
234
+ txHash: string;
235
+ };
236
+ }, {
237
+ status: 200;
238
+ success: true;
239
+ data: {
240
+ payer: string;
241
+ txHash: string;
242
+ };
243
+ }>, z.ZodObject<{
244
+ success: z.ZodLiteral<false>;
245
+ status: z.ZodLiteral<402>;
246
+ response: z.ZodObject<{
247
+ x402Version: z.ZodLiteral<1>;
248
+ accepts: z.ZodArray<z.ZodObject<{
249
+ scheme: z.ZodEnum<["exact"]>;
250
+ network: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
251
+ maxAmountRequired: z.ZodEffects<z.ZodString, string, string>;
252
+ resource: z.ZodString;
253
+ description: z.ZodString;
254
+ mimeType: z.ZodString;
255
+ outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
256
+ payTo: z.ZodUnion<[z.ZodString, z.ZodString]>;
257
+ maxTimeoutSeconds: z.ZodNumber;
258
+ asset: z.ZodUnion<[z.ZodString, z.ZodString]>;
259
+ paymentType: z.ZodOptional<z.ZodEnum<["eip3009", "permit", "permit2"]>>;
260
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
261
+ }, "strip", z.ZodTypeAny, {
262
+ scheme: "exact";
263
+ description: string;
264
+ asset: string;
265
+ maxAmountRequired: string;
266
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
267
+ resource: string;
268
+ mimeType: string;
269
+ payTo: string;
270
+ maxTimeoutSeconds: number;
271
+ outputSchema?: Record<string, any> | undefined;
272
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
273
+ extra?: Record<string, any> | undefined;
274
+ }, {
275
+ scheme: "exact";
276
+ description: string;
277
+ asset: string;
278
+ maxAmountRequired: string;
279
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
280
+ resource: string;
281
+ mimeType: string;
282
+ payTo: string;
283
+ maxTimeoutSeconds: number;
284
+ outputSchema?: Record<string, any> | undefined;
285
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
286
+ extra?: Record<string, any> | undefined;
287
+ }>, "many">;
288
+ error: z.ZodOptional<z.ZodString>;
289
+ }, "strip", z.ZodTypeAny, {
290
+ x402Version: 1;
291
+ accepts: {
292
+ scheme: "exact";
293
+ description: string;
294
+ asset: string;
295
+ maxAmountRequired: string;
296
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
297
+ resource: string;
298
+ mimeType: string;
299
+ payTo: string;
300
+ maxTimeoutSeconds: number;
301
+ outputSchema?: Record<string, any> | undefined;
302
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
303
+ extra?: Record<string, any> | undefined;
304
+ }[];
305
+ error?: string | undefined;
306
+ }, {
307
+ x402Version: 1;
308
+ accepts: {
309
+ scheme: "exact";
310
+ description: string;
311
+ asset: string;
312
+ maxAmountRequired: string;
313
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
314
+ resource: string;
315
+ mimeType: string;
316
+ payTo: string;
317
+ maxTimeoutSeconds: number;
318
+ outputSchema?: Record<string, any> | undefined;
319
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
320
+ extra?: Record<string, any> | undefined;
321
+ }[];
322
+ error?: string | undefined;
323
+ }>;
324
+ }, "strip", z.ZodTypeAny, {
325
+ status: 402;
326
+ success: false;
327
+ response: {
328
+ x402Version: 1;
329
+ accepts: {
330
+ scheme: "exact";
331
+ description: string;
332
+ asset: string;
333
+ maxAmountRequired: string;
334
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
335
+ resource: string;
336
+ mimeType: string;
337
+ payTo: string;
338
+ maxTimeoutSeconds: number;
339
+ outputSchema?: Record<string, any> | undefined;
340
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
341
+ extra?: Record<string, any> | undefined;
342
+ }[];
343
+ error?: string | undefined;
344
+ };
345
+ }, {
346
+ status: 402;
347
+ success: false;
348
+ response: {
349
+ x402Version: 1;
350
+ accepts: {
351
+ scheme: "exact";
352
+ description: string;
353
+ asset: string;
354
+ maxAmountRequired: string;
355
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
356
+ resource: string;
357
+ mimeType: string;
358
+ payTo: string;
359
+ maxTimeoutSeconds: number;
360
+ outputSchema?: Record<string, any> | undefined;
361
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
362
+ extra?: Record<string, any> | undefined;
363
+ }[];
364
+ error?: string | undefined;
365
+ };
366
+ }>]>;
367
+ type ProcessResult = z.infer<typeof ProcessResultSchema>;
368
+ /**
369
+ * ParsedPayment Schema
370
+ */
371
+ declare const ParsedPaymentSchema: z.ZodObject<{
372
+ payload: z.ZodObject<{
373
+ x402Version: z.ZodEffects<z.ZodNumber, number, number>;
374
+ scheme: z.ZodEnum<["exact"]>;
375
+ network: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
376
+ payload: z.ZodUnion<[z.ZodDiscriminatedUnion<"authorizationType", [z.ZodObject<{
377
+ authorizationType: z.ZodLiteral<"eip3009">;
378
+ signature: z.ZodString;
379
+ authorization: z.ZodObject<{
380
+ from: z.ZodString;
381
+ to: z.ZodString;
382
+ value: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
383
+ validAfter: z.ZodEffects<z.ZodString, string, string>;
384
+ validBefore: z.ZodEffects<z.ZodString, string, string>;
385
+ nonce: z.ZodString;
386
+ }, "strip", z.ZodTypeAny, {
387
+ from: string;
388
+ to: string;
389
+ value: string;
390
+ validAfter: string;
391
+ validBefore: string;
392
+ nonce: string;
393
+ }, {
394
+ from: string;
395
+ to: string;
396
+ value: string;
397
+ validAfter: string;
398
+ validBefore: string;
399
+ nonce: string;
400
+ }>;
401
+ }, "strip", z.ZodTypeAny, {
402
+ signature: string;
403
+ authorization: {
404
+ from: string;
405
+ to: string;
406
+ value: string;
407
+ validAfter: string;
408
+ validBefore: string;
409
+ nonce: string;
410
+ };
411
+ authorizationType: "eip3009";
412
+ }, {
413
+ signature: string;
414
+ authorization: {
415
+ from: string;
416
+ to: string;
417
+ value: string;
418
+ validAfter: string;
419
+ validBefore: string;
420
+ nonce: string;
421
+ };
422
+ authorizationType: "eip3009";
423
+ }>, z.ZodObject<{
424
+ authorizationType: z.ZodLiteral<"permit">;
425
+ signature: z.ZodString;
426
+ authorization: z.ZodObject<{
427
+ owner: z.ZodString;
428
+ spender: z.ZodString;
429
+ value: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
430
+ deadline: z.ZodEffects<z.ZodString, string, string>;
431
+ nonce: z.ZodEffects<z.ZodString, string, string>;
432
+ }, "strip", z.ZodTypeAny, {
433
+ value: string;
434
+ nonce: string;
435
+ owner: string;
436
+ spender: string;
437
+ deadline: string;
438
+ }, {
439
+ value: string;
440
+ nonce: string;
441
+ owner: string;
442
+ spender: string;
443
+ deadline: string;
444
+ }>;
445
+ }, "strip", z.ZodTypeAny, {
446
+ signature: string;
447
+ authorization: {
448
+ value: string;
449
+ nonce: string;
450
+ owner: string;
451
+ spender: string;
452
+ deadline: string;
453
+ };
454
+ authorizationType: "permit";
455
+ }, {
456
+ signature: string;
457
+ authorization: {
458
+ value: string;
459
+ nonce: string;
460
+ owner: string;
461
+ spender: string;
462
+ deadline: string;
463
+ };
464
+ authorizationType: "permit";
465
+ }>, z.ZodObject<{
466
+ authorizationType: z.ZodLiteral<"permit2">;
467
+ signature: z.ZodString;
468
+ authorization: z.ZodObject<{
469
+ owner: z.ZodString;
470
+ spender: z.ZodString;
471
+ token: z.ZodString;
472
+ amount: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
473
+ deadline: z.ZodEffects<z.ZodString, string, string>;
474
+ nonce: z.ZodEffects<z.ZodString, string, string>;
475
+ to: z.ZodOptional<z.ZodString>;
476
+ }, "strip", z.ZodTypeAny, {
477
+ nonce: string;
478
+ owner: string;
479
+ spender: string;
480
+ deadline: string;
481
+ amount: string;
482
+ token: string;
483
+ to?: string | undefined;
484
+ }, {
485
+ nonce: string;
486
+ owner: string;
487
+ spender: string;
488
+ deadline: string;
489
+ amount: string;
490
+ token: string;
491
+ to?: string | undefined;
492
+ }>;
493
+ }, "strip", z.ZodTypeAny, {
494
+ signature: string;
495
+ authorization: {
496
+ nonce: string;
497
+ owner: string;
498
+ spender: string;
499
+ deadline: string;
500
+ amount: string;
501
+ token: string;
502
+ to?: string | undefined;
503
+ };
504
+ authorizationType: "permit2";
505
+ }, {
506
+ signature: string;
507
+ authorization: {
508
+ nonce: string;
509
+ owner: string;
510
+ spender: string;
511
+ deadline: string;
512
+ amount: string;
513
+ token: string;
514
+ to?: string | undefined;
515
+ };
516
+ authorizationType: "permit2";
517
+ }>]>, z.ZodObject<{
518
+ transaction: z.ZodString;
519
+ }, "strip", z.ZodTypeAny, {
520
+ transaction: string;
521
+ }, {
522
+ transaction: string;
523
+ }>]>;
524
+ }, "strip", z.ZodTypeAny, {
525
+ scheme: "exact";
526
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
527
+ x402Version: number;
528
+ payload: {
529
+ signature: string;
530
+ authorization: {
531
+ from: string;
532
+ to: string;
533
+ value: string;
534
+ validAfter: string;
535
+ validBefore: string;
536
+ nonce: string;
537
+ };
538
+ authorizationType: "eip3009";
539
+ } | {
540
+ signature: string;
541
+ authorization: {
542
+ value: string;
543
+ nonce: string;
544
+ owner: string;
545
+ spender: string;
546
+ deadline: string;
547
+ };
548
+ authorizationType: "permit";
549
+ } | {
550
+ signature: string;
551
+ authorization: {
552
+ nonce: string;
553
+ owner: string;
554
+ spender: string;
555
+ deadline: string;
556
+ amount: string;
557
+ token: string;
558
+ to?: string | undefined;
559
+ };
560
+ authorizationType: "permit2";
561
+ } | {
562
+ transaction: string;
563
+ };
564
+ }, {
565
+ scheme: "exact";
566
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
567
+ x402Version: number;
568
+ payload: {
569
+ signature: string;
570
+ authorization: {
571
+ from: string;
572
+ to: string;
573
+ value: string;
574
+ validAfter: string;
575
+ validBefore: string;
576
+ nonce: string;
577
+ };
578
+ authorizationType: "eip3009";
579
+ } | {
580
+ signature: string;
581
+ authorization: {
582
+ value: string;
583
+ nonce: string;
584
+ owner: string;
585
+ spender: string;
586
+ deadline: string;
587
+ };
588
+ authorizationType: "permit";
589
+ } | {
590
+ signature: string;
591
+ authorization: {
592
+ nonce: string;
593
+ owner: string;
594
+ spender: string;
595
+ deadline: string;
596
+ amount: string;
597
+ token: string;
598
+ to?: string | undefined;
599
+ };
600
+ authorizationType: "permit2";
601
+ } | {
602
+ transaction: string;
603
+ };
604
+ }>;
605
+ requirements: z.ZodObject<{
606
+ scheme: z.ZodEnum<["exact"]>;
607
+ network: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
608
+ maxAmountRequired: z.ZodEffects<z.ZodString, string, string>;
609
+ resource: z.ZodString;
610
+ description: z.ZodString;
611
+ mimeType: z.ZodString;
612
+ outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
613
+ payTo: z.ZodUnion<[z.ZodString, z.ZodString]>;
614
+ maxTimeoutSeconds: z.ZodNumber;
615
+ asset: z.ZodUnion<[z.ZodString, z.ZodString]>;
616
+ paymentType: z.ZodOptional<z.ZodEnum<["eip3009", "permit", "permit2"]>>;
617
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
618
+ }, "strip", z.ZodTypeAny, {
619
+ scheme: "exact";
620
+ description: string;
621
+ asset: string;
622
+ maxAmountRequired: string;
623
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
624
+ resource: string;
625
+ mimeType: string;
626
+ payTo: string;
627
+ maxTimeoutSeconds: number;
628
+ outputSchema?: Record<string, any> | undefined;
629
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
630
+ extra?: Record<string, any> | undefined;
631
+ }, {
632
+ scheme: "exact";
633
+ description: string;
634
+ asset: string;
635
+ maxAmountRequired: string;
636
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
637
+ resource: string;
638
+ mimeType: string;
639
+ payTo: string;
640
+ maxTimeoutSeconds: number;
641
+ outputSchema?: Record<string, any> | undefined;
642
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
643
+ extra?: Record<string, any> | undefined;
644
+ }>;
645
+ }, "strip", z.ZodTypeAny, {
646
+ payload: {
647
+ scheme: "exact";
648
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
649
+ x402Version: number;
650
+ payload: {
651
+ signature: string;
652
+ authorization: {
653
+ from: string;
654
+ to: string;
655
+ value: string;
656
+ validAfter: string;
657
+ validBefore: string;
658
+ nonce: string;
659
+ };
660
+ authorizationType: "eip3009";
661
+ } | {
662
+ signature: string;
663
+ authorization: {
664
+ value: string;
665
+ nonce: string;
666
+ owner: string;
667
+ spender: string;
668
+ deadline: string;
669
+ };
670
+ authorizationType: "permit";
671
+ } | {
672
+ signature: string;
673
+ authorization: {
674
+ nonce: string;
675
+ owner: string;
676
+ spender: string;
677
+ deadline: string;
678
+ amount: string;
679
+ token: string;
680
+ to?: string | undefined;
681
+ };
682
+ authorizationType: "permit2";
683
+ } | {
684
+ transaction: string;
685
+ };
686
+ };
687
+ requirements: {
688
+ scheme: "exact";
689
+ description: string;
690
+ asset: string;
691
+ maxAmountRequired: string;
692
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
693
+ resource: string;
694
+ mimeType: string;
695
+ payTo: string;
696
+ maxTimeoutSeconds: number;
697
+ outputSchema?: Record<string, any> | undefined;
698
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
699
+ extra?: Record<string, any> | undefined;
700
+ };
701
+ }, {
702
+ payload: {
703
+ scheme: "exact";
704
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
705
+ x402Version: number;
706
+ payload: {
707
+ signature: string;
708
+ authorization: {
709
+ from: string;
710
+ to: string;
711
+ value: string;
712
+ validAfter: string;
713
+ validBefore: string;
714
+ nonce: string;
715
+ };
716
+ authorizationType: "eip3009";
717
+ } | {
718
+ signature: string;
719
+ authorization: {
720
+ value: string;
721
+ nonce: string;
722
+ owner: string;
723
+ spender: string;
724
+ deadline: string;
725
+ };
726
+ authorizationType: "permit";
727
+ } | {
728
+ signature: string;
729
+ authorization: {
730
+ nonce: string;
731
+ owner: string;
732
+ spender: string;
733
+ deadline: string;
734
+ amount: string;
735
+ token: string;
736
+ to?: string | undefined;
737
+ };
738
+ authorizationType: "permit2";
739
+ } | {
740
+ transaction: string;
741
+ };
742
+ };
743
+ requirements: {
744
+ scheme: "exact";
745
+ description: string;
746
+ asset: string;
747
+ maxAmountRequired: string;
748
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
749
+ resource: string;
750
+ mimeType: string;
751
+ payTo: string;
752
+ maxTimeoutSeconds: number;
753
+ outputSchema?: Record<string, any> | undefined;
754
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
755
+ extra?: Record<string, any> | undefined;
756
+ };
757
+ }>;
758
+ type ParsedPayment = z.infer<typeof ParsedPaymentSchema>;
759
+ /**
760
+ * ParseResult Schema
761
+ */
762
+ declare const ParseResultSchema: z.ZodDiscriminatedUnion<"success", [z.ZodObject<{
763
+ success: z.ZodLiteral<true>;
764
+ data: z.ZodObject<{
765
+ payload: z.ZodObject<{
766
+ x402Version: z.ZodEffects<z.ZodNumber, number, number>;
767
+ scheme: z.ZodEnum<["exact"]>;
768
+ network: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
769
+ payload: z.ZodUnion<[z.ZodDiscriminatedUnion<"authorizationType", [z.ZodObject<{
770
+ authorizationType: z.ZodLiteral<"eip3009">;
771
+ signature: z.ZodString;
772
+ authorization: z.ZodObject<{
773
+ from: z.ZodString;
774
+ to: z.ZodString;
775
+ value: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
776
+ validAfter: z.ZodEffects<z.ZodString, string, string>;
777
+ validBefore: z.ZodEffects<z.ZodString, string, string>;
778
+ nonce: z.ZodString;
779
+ }, "strip", z.ZodTypeAny, {
780
+ from: string;
781
+ to: string;
782
+ value: string;
783
+ validAfter: string;
784
+ validBefore: string;
785
+ nonce: string;
786
+ }, {
787
+ from: string;
788
+ to: string;
789
+ value: string;
790
+ validAfter: string;
791
+ validBefore: string;
792
+ nonce: string;
793
+ }>;
794
+ }, "strip", z.ZodTypeAny, {
795
+ signature: string;
796
+ authorization: {
797
+ from: string;
798
+ to: string;
799
+ value: string;
800
+ validAfter: string;
801
+ validBefore: string;
802
+ nonce: string;
803
+ };
804
+ authorizationType: "eip3009";
805
+ }, {
806
+ signature: string;
807
+ authorization: {
808
+ from: string;
809
+ to: string;
810
+ value: string;
811
+ validAfter: string;
812
+ validBefore: string;
813
+ nonce: string;
814
+ };
815
+ authorizationType: "eip3009";
816
+ }>, z.ZodObject<{
817
+ authorizationType: z.ZodLiteral<"permit">;
818
+ signature: z.ZodString;
819
+ authorization: z.ZodObject<{
820
+ owner: z.ZodString;
821
+ spender: z.ZodString;
822
+ value: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
823
+ deadline: z.ZodEffects<z.ZodString, string, string>;
824
+ nonce: z.ZodEffects<z.ZodString, string, string>;
825
+ }, "strip", z.ZodTypeAny, {
826
+ value: string;
827
+ nonce: string;
828
+ owner: string;
829
+ spender: string;
830
+ deadline: string;
831
+ }, {
832
+ value: string;
833
+ nonce: string;
834
+ owner: string;
835
+ spender: string;
836
+ deadline: string;
837
+ }>;
838
+ }, "strip", z.ZodTypeAny, {
839
+ signature: string;
840
+ authorization: {
841
+ value: string;
842
+ nonce: string;
843
+ owner: string;
844
+ spender: string;
845
+ deadline: string;
846
+ };
847
+ authorizationType: "permit";
848
+ }, {
849
+ signature: string;
850
+ authorization: {
851
+ value: string;
852
+ nonce: string;
853
+ owner: string;
854
+ spender: string;
855
+ deadline: string;
856
+ };
857
+ authorizationType: "permit";
858
+ }>, z.ZodObject<{
859
+ authorizationType: z.ZodLiteral<"permit2">;
860
+ signature: z.ZodString;
861
+ authorization: z.ZodObject<{
862
+ owner: z.ZodString;
863
+ spender: z.ZodString;
864
+ token: z.ZodString;
865
+ amount: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
866
+ deadline: z.ZodEffects<z.ZodString, string, string>;
867
+ nonce: z.ZodEffects<z.ZodString, string, string>;
868
+ to: z.ZodOptional<z.ZodString>;
869
+ }, "strip", z.ZodTypeAny, {
870
+ nonce: string;
871
+ owner: string;
872
+ spender: string;
873
+ deadline: string;
874
+ amount: string;
875
+ token: string;
876
+ to?: string | undefined;
877
+ }, {
878
+ nonce: string;
879
+ owner: string;
880
+ spender: string;
881
+ deadline: string;
882
+ amount: string;
883
+ token: string;
884
+ to?: string | undefined;
885
+ }>;
886
+ }, "strip", z.ZodTypeAny, {
887
+ signature: string;
888
+ authorization: {
889
+ nonce: string;
890
+ owner: string;
891
+ spender: string;
892
+ deadline: string;
893
+ amount: string;
894
+ token: string;
895
+ to?: string | undefined;
896
+ };
897
+ authorizationType: "permit2";
898
+ }, {
899
+ signature: string;
900
+ authorization: {
901
+ nonce: string;
902
+ owner: string;
903
+ spender: string;
904
+ deadline: string;
905
+ amount: string;
906
+ token: string;
907
+ to?: string | undefined;
908
+ };
909
+ authorizationType: "permit2";
910
+ }>]>, z.ZodObject<{
911
+ transaction: z.ZodString;
912
+ }, "strip", z.ZodTypeAny, {
913
+ transaction: string;
914
+ }, {
915
+ transaction: string;
916
+ }>]>;
917
+ }, "strip", z.ZodTypeAny, {
918
+ scheme: "exact";
919
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
920
+ x402Version: number;
921
+ payload: {
922
+ signature: string;
923
+ authorization: {
924
+ from: string;
925
+ to: string;
926
+ value: string;
927
+ validAfter: string;
928
+ validBefore: string;
929
+ nonce: string;
930
+ };
931
+ authorizationType: "eip3009";
932
+ } | {
933
+ signature: string;
934
+ authorization: {
935
+ value: string;
936
+ nonce: string;
937
+ owner: string;
938
+ spender: string;
939
+ deadline: string;
940
+ };
941
+ authorizationType: "permit";
942
+ } | {
943
+ signature: string;
944
+ authorization: {
945
+ nonce: string;
946
+ owner: string;
947
+ spender: string;
948
+ deadline: string;
949
+ amount: string;
950
+ token: string;
951
+ to?: string | undefined;
952
+ };
953
+ authorizationType: "permit2";
954
+ } | {
955
+ transaction: string;
956
+ };
957
+ }, {
958
+ scheme: "exact";
959
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
960
+ x402Version: number;
961
+ payload: {
962
+ signature: string;
963
+ authorization: {
964
+ from: string;
965
+ to: string;
966
+ value: string;
967
+ validAfter: string;
968
+ validBefore: string;
969
+ nonce: string;
970
+ };
971
+ authorizationType: "eip3009";
972
+ } | {
973
+ signature: string;
974
+ authorization: {
975
+ value: string;
976
+ nonce: string;
977
+ owner: string;
978
+ spender: string;
979
+ deadline: string;
980
+ };
981
+ authorizationType: "permit";
982
+ } | {
983
+ signature: string;
984
+ authorization: {
985
+ nonce: string;
986
+ owner: string;
987
+ spender: string;
988
+ deadline: string;
989
+ amount: string;
990
+ token: string;
991
+ to?: string | undefined;
992
+ };
993
+ authorizationType: "permit2";
994
+ } | {
995
+ transaction: string;
996
+ };
997
+ }>;
998
+ requirements: z.ZodObject<{
999
+ scheme: z.ZodEnum<["exact"]>;
1000
+ network: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
1001
+ maxAmountRequired: z.ZodEffects<z.ZodString, string, string>;
1002
+ resource: z.ZodString;
1003
+ description: z.ZodString;
1004
+ mimeType: z.ZodString;
1005
+ outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1006
+ payTo: z.ZodUnion<[z.ZodString, z.ZodString]>;
1007
+ maxTimeoutSeconds: z.ZodNumber;
1008
+ asset: z.ZodUnion<[z.ZodString, z.ZodString]>;
1009
+ paymentType: z.ZodOptional<z.ZodEnum<["eip3009", "permit", "permit2"]>>;
1010
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1011
+ }, "strip", z.ZodTypeAny, {
1012
+ scheme: "exact";
1013
+ description: string;
1014
+ asset: string;
1015
+ maxAmountRequired: string;
1016
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1017
+ resource: string;
1018
+ mimeType: string;
1019
+ payTo: string;
1020
+ maxTimeoutSeconds: number;
1021
+ outputSchema?: Record<string, any> | undefined;
1022
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1023
+ extra?: Record<string, any> | undefined;
1024
+ }, {
1025
+ scheme: "exact";
1026
+ description: string;
1027
+ asset: string;
1028
+ maxAmountRequired: string;
1029
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1030
+ resource: string;
1031
+ mimeType: string;
1032
+ payTo: string;
1033
+ maxTimeoutSeconds: number;
1034
+ outputSchema?: Record<string, any> | undefined;
1035
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1036
+ extra?: Record<string, any> | undefined;
1037
+ }>;
1038
+ }, "strip", z.ZodTypeAny, {
1039
+ payload: {
1040
+ scheme: "exact";
1041
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1042
+ x402Version: number;
1043
+ payload: {
1044
+ signature: string;
1045
+ authorization: {
1046
+ from: string;
1047
+ to: string;
1048
+ value: string;
1049
+ validAfter: string;
1050
+ validBefore: string;
1051
+ nonce: string;
1052
+ };
1053
+ authorizationType: "eip3009";
1054
+ } | {
1055
+ signature: string;
1056
+ authorization: {
1057
+ value: string;
1058
+ nonce: string;
1059
+ owner: string;
1060
+ spender: string;
1061
+ deadline: string;
1062
+ };
1063
+ authorizationType: "permit";
1064
+ } | {
1065
+ signature: string;
1066
+ authorization: {
1067
+ nonce: string;
1068
+ owner: string;
1069
+ spender: string;
1070
+ deadline: string;
1071
+ amount: string;
1072
+ token: string;
1073
+ to?: string | undefined;
1074
+ };
1075
+ authorizationType: "permit2";
1076
+ } | {
1077
+ transaction: string;
1078
+ };
1079
+ };
1080
+ requirements: {
1081
+ scheme: "exact";
1082
+ description: string;
1083
+ asset: string;
1084
+ maxAmountRequired: string;
1085
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1086
+ resource: string;
1087
+ mimeType: string;
1088
+ payTo: string;
1089
+ maxTimeoutSeconds: number;
1090
+ outputSchema?: Record<string, any> | undefined;
1091
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1092
+ extra?: Record<string, any> | undefined;
1093
+ };
1094
+ }, {
1095
+ payload: {
1096
+ scheme: "exact";
1097
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1098
+ x402Version: number;
1099
+ payload: {
1100
+ signature: string;
1101
+ authorization: {
1102
+ from: string;
1103
+ to: string;
1104
+ value: string;
1105
+ validAfter: string;
1106
+ validBefore: string;
1107
+ nonce: string;
1108
+ };
1109
+ authorizationType: "eip3009";
1110
+ } | {
1111
+ signature: string;
1112
+ authorization: {
1113
+ value: string;
1114
+ nonce: string;
1115
+ owner: string;
1116
+ spender: string;
1117
+ deadline: string;
1118
+ };
1119
+ authorizationType: "permit";
1120
+ } | {
1121
+ signature: string;
1122
+ authorization: {
1123
+ nonce: string;
1124
+ owner: string;
1125
+ spender: string;
1126
+ deadline: string;
1127
+ amount: string;
1128
+ token: string;
1129
+ to?: string | undefined;
1130
+ };
1131
+ authorizationType: "permit2";
1132
+ } | {
1133
+ transaction: string;
1134
+ };
1135
+ };
1136
+ requirements: {
1137
+ scheme: "exact";
1138
+ description: string;
1139
+ asset: string;
1140
+ maxAmountRequired: string;
1141
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1142
+ resource: string;
1143
+ mimeType: string;
1144
+ payTo: string;
1145
+ maxTimeoutSeconds: number;
1146
+ outputSchema?: Record<string, any> | undefined;
1147
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1148
+ extra?: Record<string, any> | undefined;
1149
+ };
1150
+ }>;
1151
+ }, "strip", z.ZodTypeAny, {
1152
+ success: true;
1153
+ data: {
1154
+ payload: {
1155
+ scheme: "exact";
1156
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1157
+ x402Version: number;
1158
+ payload: {
1159
+ signature: string;
1160
+ authorization: {
1161
+ from: string;
1162
+ to: string;
1163
+ value: string;
1164
+ validAfter: string;
1165
+ validBefore: string;
1166
+ nonce: string;
1167
+ };
1168
+ authorizationType: "eip3009";
1169
+ } | {
1170
+ signature: string;
1171
+ authorization: {
1172
+ value: string;
1173
+ nonce: string;
1174
+ owner: string;
1175
+ spender: string;
1176
+ deadline: string;
1177
+ };
1178
+ authorizationType: "permit";
1179
+ } | {
1180
+ signature: string;
1181
+ authorization: {
1182
+ nonce: string;
1183
+ owner: string;
1184
+ spender: string;
1185
+ deadline: string;
1186
+ amount: string;
1187
+ token: string;
1188
+ to?: string | undefined;
1189
+ };
1190
+ authorizationType: "permit2";
1191
+ } | {
1192
+ transaction: string;
1193
+ };
1194
+ };
1195
+ requirements: {
1196
+ scheme: "exact";
1197
+ description: string;
1198
+ asset: string;
1199
+ maxAmountRequired: string;
1200
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1201
+ resource: string;
1202
+ mimeType: string;
1203
+ payTo: string;
1204
+ maxTimeoutSeconds: number;
1205
+ outputSchema?: Record<string, any> | undefined;
1206
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1207
+ extra?: Record<string, any> | undefined;
1208
+ };
1209
+ };
1210
+ }, {
1211
+ success: true;
1212
+ data: {
1213
+ payload: {
1214
+ scheme: "exact";
1215
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1216
+ x402Version: number;
1217
+ payload: {
1218
+ signature: string;
1219
+ authorization: {
1220
+ from: string;
1221
+ to: string;
1222
+ value: string;
1223
+ validAfter: string;
1224
+ validBefore: string;
1225
+ nonce: string;
1226
+ };
1227
+ authorizationType: "eip3009";
1228
+ } | {
1229
+ signature: string;
1230
+ authorization: {
1231
+ value: string;
1232
+ nonce: string;
1233
+ owner: string;
1234
+ spender: string;
1235
+ deadline: string;
1236
+ };
1237
+ authorizationType: "permit";
1238
+ } | {
1239
+ signature: string;
1240
+ authorization: {
1241
+ nonce: string;
1242
+ owner: string;
1243
+ spender: string;
1244
+ deadline: string;
1245
+ amount: string;
1246
+ token: string;
1247
+ to?: string | undefined;
1248
+ };
1249
+ authorizationType: "permit2";
1250
+ } | {
1251
+ transaction: string;
1252
+ };
1253
+ };
1254
+ requirements: {
1255
+ scheme: "exact";
1256
+ description: string;
1257
+ asset: string;
1258
+ maxAmountRequired: string;
1259
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1260
+ resource: string;
1261
+ mimeType: string;
1262
+ payTo: string;
1263
+ maxTimeoutSeconds: number;
1264
+ outputSchema?: Record<string, any> | undefined;
1265
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1266
+ extra?: Record<string, any> | undefined;
1267
+ };
1268
+ };
1269
+ }>, z.ZodObject<{
1270
+ success: z.ZodLiteral<false>;
1271
+ response402: z.ZodObject<{
1272
+ x402Version: z.ZodLiteral<1>;
1273
+ accepts: z.ZodArray<z.ZodObject<{
1274
+ scheme: z.ZodEnum<["exact"]>;
1275
+ network: z.ZodEnum<["base-sepolia", "base", "avalanche-fuji", "avalanche", "iotex", "solana-devnet", "solana", "sei", "sei-testnet", "polygon", "polygon-amoy", "peaq", "bsc", "bsc-testnet"]>;
1276
+ maxAmountRequired: z.ZodEffects<z.ZodString, string, string>;
1277
+ resource: z.ZodString;
1278
+ description: z.ZodString;
1279
+ mimeType: z.ZodString;
1280
+ outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1281
+ payTo: z.ZodUnion<[z.ZodString, z.ZodString]>;
1282
+ maxTimeoutSeconds: z.ZodNumber;
1283
+ asset: z.ZodUnion<[z.ZodString, z.ZodString]>;
1284
+ paymentType: z.ZodOptional<z.ZodEnum<["eip3009", "permit", "permit2"]>>;
1285
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1286
+ }, "strip", z.ZodTypeAny, {
1287
+ scheme: "exact";
1288
+ description: string;
1289
+ asset: string;
1290
+ maxAmountRequired: string;
1291
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1292
+ resource: string;
1293
+ mimeType: string;
1294
+ payTo: string;
1295
+ maxTimeoutSeconds: number;
1296
+ outputSchema?: Record<string, any> | undefined;
1297
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1298
+ extra?: Record<string, any> | undefined;
1299
+ }, {
1300
+ scheme: "exact";
1301
+ description: string;
1302
+ asset: string;
1303
+ maxAmountRequired: string;
1304
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1305
+ resource: string;
1306
+ mimeType: string;
1307
+ payTo: string;
1308
+ maxTimeoutSeconds: number;
1309
+ outputSchema?: Record<string, any> | undefined;
1310
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1311
+ extra?: Record<string, any> | undefined;
1312
+ }>, "many">;
1313
+ error: z.ZodOptional<z.ZodString>;
1314
+ }, "strip", z.ZodTypeAny, {
1315
+ x402Version: 1;
1316
+ accepts: {
1317
+ scheme: "exact";
1318
+ description: string;
1319
+ asset: string;
1320
+ maxAmountRequired: string;
1321
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1322
+ resource: string;
1323
+ mimeType: string;
1324
+ payTo: string;
1325
+ maxTimeoutSeconds: number;
1326
+ outputSchema?: Record<string, any> | undefined;
1327
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1328
+ extra?: Record<string, any> | undefined;
1329
+ }[];
1330
+ error?: string | undefined;
1331
+ }, {
1332
+ x402Version: 1;
1333
+ accepts: {
1334
+ scheme: "exact";
1335
+ description: string;
1336
+ asset: string;
1337
+ maxAmountRequired: string;
1338
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1339
+ resource: string;
1340
+ mimeType: string;
1341
+ payTo: string;
1342
+ maxTimeoutSeconds: number;
1343
+ outputSchema?: Record<string, any> | undefined;
1344
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1345
+ extra?: Record<string, any> | undefined;
1346
+ }[];
1347
+ error?: string | undefined;
1348
+ }>;
1349
+ }, "strip", z.ZodTypeAny, {
1350
+ success: false;
1351
+ response402: {
1352
+ x402Version: 1;
1353
+ accepts: {
1354
+ scheme: "exact";
1355
+ description: string;
1356
+ asset: string;
1357
+ maxAmountRequired: string;
1358
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1359
+ resource: string;
1360
+ mimeType: string;
1361
+ payTo: string;
1362
+ maxTimeoutSeconds: number;
1363
+ outputSchema?: Record<string, any> | undefined;
1364
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1365
+ extra?: Record<string, any> | undefined;
1366
+ }[];
1367
+ error?: string | undefined;
1368
+ };
1369
+ }, {
1370
+ success: false;
1371
+ response402: {
1372
+ x402Version: 1;
1373
+ accepts: {
1374
+ scheme: "exact";
1375
+ description: string;
1376
+ asset: string;
1377
+ maxAmountRequired: string;
1378
+ network: "base-sepolia" | "avalanche-fuji" | "base" | "avalanche" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "iotex" | "bsc" | "bsc-testnet" | "solana-devnet" | "solana";
1379
+ resource: string;
1380
+ mimeType: string;
1381
+ payTo: string;
1382
+ maxTimeoutSeconds: number;
1383
+ outputSchema?: Record<string, any> | undefined;
1384
+ paymentType?: "permit" | "eip3009" | "permit2" | undefined;
1385
+ extra?: Record<string, any> | undefined;
1386
+ }[];
1387
+ error?: string | undefined;
1388
+ };
1389
+ }>]>;
1390
+ type ParseResult = z.infer<typeof ParseResultSchema>;
1391
+ /**
1392
+ * VerifyResult Schema
1393
+ */
1394
+ declare const VerifyResultSchema: z.ZodDiscriminatedUnion<"success", [z.ZodObject<{
1395
+ success: z.ZodLiteral<true>;
1396
+ payer: z.ZodString;
1397
+ }, "strip", z.ZodTypeAny, {
1398
+ success: true;
1399
+ payer: string;
1400
+ }, {
1401
+ success: true;
1402
+ payer: string;
1403
+ }>, z.ZodObject<{
1404
+ success: z.ZodLiteral<false>;
1405
+ error: z.ZodString;
1406
+ }, "strip", z.ZodTypeAny, {
1407
+ error: string;
1408
+ success: false;
1409
+ }, {
1410
+ error: string;
1411
+ success: false;
1412
+ }>]>;
1413
+ type VerifyResult = z.infer<typeof VerifyResultSchema>;
1414
+ /**
1415
+ * SettleResult Schema
1416
+ */
1417
+ declare const SettleResultSchema: z.ZodDiscriminatedUnion<"success", [z.ZodObject<{
1418
+ success: z.ZodLiteral<true>;
1419
+ txHash: z.ZodString;
1420
+ network: z.ZodString;
1421
+ }, "strip", z.ZodTypeAny, {
1422
+ network: string;
1423
+ success: true;
1424
+ txHash: string;
1425
+ }, {
1426
+ network: string;
1427
+ success: true;
1428
+ txHash: string;
1429
+ }>, z.ZodObject<{
1430
+ success: z.ZodLiteral<false>;
1431
+ error: z.ZodString;
1432
+ }, "strip", z.ZodTypeAny, {
1433
+ error: string;
1434
+ success: false;
1435
+ }, {
1436
+ error: string;
1437
+ success: false;
1438
+ }>]>;
1439
+ type SettleResult = z.infer<typeof SettleResultSchema>;
1440
+
1441
+ /**
1442
+ * X402Server 配置选项
1443
+ */
1444
+ interface X402ServerConfig {
1445
+ /** Viem PublicClient (必填) */
1446
+ client: PublicClient;
1447
+ /** Facilitator 实例 (必填) */
1448
+ facilitator: Facilitator;
1449
+ /** 网络名称,默认从 client 自动检测 */
1450
+ network?: string;
1451
+ }
1452
+
1453
+ /**
1454
+ * X402 Server
1455
+ *
1456
+ * 服务端 SDK,用于处理支付验证和结算
1457
+ *
1458
+ * @example
1459
+ * ```typescript
1460
+ * // 1. 创建 facilitator
1461
+ * const facilitator = new Facilitator({
1462
+ * recipientAddress: "0x1234...",
1463
+ * waitUntil: "confirmed",
1464
+ * });
1465
+ *
1466
+ * // 2. 创建 server
1467
+ * const server = new X402Server({
1468
+ * client: viemClient,
1469
+ * facilitator,
1470
+ * });
1471
+ *
1472
+ * // 3. 可选:预热缓存
1473
+ * await server.initialize([tokenAddress]);
1474
+ *
1475
+ * // 4. 创建支付要求
1476
+ * const requirements = await server.createRequirements({
1477
+ * asset: tokenAddress,
1478
+ * maxAmountRequired: "1000",
1479
+ * });
1480
+ *
1481
+ * // 5. 处理支付
1482
+ * const result = await server.process(paymentHeader, requirements);
1483
+ * ```
1484
+ */
1485
+ declare class X402Server {
1486
+ private client;
1487
+ private detector;
1488
+ private facilitator;
1489
+ private network;
1490
+ /**
1491
+ * 构造函数
1492
+ *
1493
+ * @param config - Server 配置
1494
+ */
1495
+ constructor(config: X402ServerConfig);
1496
+ /**
1497
+ * 可选的初始化 - 预热缓存
1498
+ *
1499
+ * @param tokens - 要预热的 token 地址列表
1500
+ * @returns 初始化结果
1501
+ */
1502
+ initialize(tokens: string[]): Promise<InitResult>;
1503
+ /**
1504
+ * 创建支付要求
1505
+ *
1506
+ * @param config - 配置选项
1507
+ * @returns 支付要求
1508
+ */
1509
+ createRequirements(config: CreateRequirementsConfig): Promise<PaymentRequirements>;
1510
+ /**
1511
+ * 完整的支付处理流程
1512
+ * parse → verify → settle 一步到位
1513
+ *
1514
+ * @param paymentHeader - X-PAYMENT header 的值 (Base64)
1515
+ * @param expectedRequirements - 期望的支付要求
1516
+ * @returns 处理结果
1517
+ */
1518
+ process(paymentHeader: string | undefined, expectedRequirements: PaymentRequirements): Promise<ProcessResult>;
1519
+ /**
1520
+ * 解析支付头
1521
+ *
1522
+ * @param paymentHeader - X-PAYMENT header 的值
1523
+ * @param expectedRequirements - 期望的支付要求
1524
+ * @returns 解析结果
1525
+ */
1526
+ parse(paymentHeader: string | undefined, expectedRequirements: PaymentRequirements): ParseResult;
1527
+ /**
1528
+ * 验证支付签名
1529
+ *
1530
+ * @param parsed - 解析后的支付数据
1531
+ * @returns 验证结果
1532
+ */
1533
+ verify(parsed: ParsedPayment): Promise<VerifyResult>;
1534
+ /**
1535
+ * 结算支付
1536
+ *
1537
+ * @param parsed - 解析后的支付数据
1538
+ * @returns 结算结果
1539
+ */
1540
+ settle(parsed: ParsedPayment): Promise<SettleResult>;
1541
+ /**
1542
+ * 生成 402 响应
1543
+ *
1544
+ * @param requirements - 支付要求
1545
+ * @param error - 可选的错误信息
1546
+ * @returns 402 响应对象
1547
+ */
1548
+ get402Response(requirements: PaymentRequirements, error?: string): Response402;
1549
+ /**
1550
+ * 清除缓存
1551
+ *
1552
+ * @param token - 可选,指定要清除的 token 地址
1553
+ */
1554
+ clearCache(token?: string): Promise<void>;
1555
+ /**
1556
+ * 获取缓存统计
1557
+ *
1558
+ * @returns 缓存统计信息
1559
+ */
1560
+ getCacheStats(): {
1561
+ size: number;
1562
+ keys: string[];
1563
+ };
1564
+ /**
1565
+ * 获取 facilitator 实例(供外部访问)
1566
+ *
1567
+ * @returns Facilitator 实例
1568
+ */
1569
+ getFacilitator(): Facilitator;
1570
+ /**
1571
+ * 获取 detector 实例(供外部访问)
1572
+ *
1573
+ * @returns TokenDetector 实例
1574
+ */
1575
+ getDetector(): TokenDetector;
1576
+ /**
1577
+ * 获取 client 实例(供外部访问)
1578
+ *
1579
+ * @returns PublicClient 实例
1580
+ */
1581
+ getClient(): PublicClient;
1582
+ /**
1583
+ * 获取网络名称
1584
+ *
1585
+ * @returns 网络名称
1586
+ */
1587
+ private getNetworkName;
1588
+ }
1589
+
1590
+ /**
1591
+ * Express 中间件 for x402 Payment Protocol
1592
+ */
1593
+
1594
+ /**
1595
+ * Express-like Request 接口
1596
+ * 定义最小化的类型,避免直接依赖 express
1597
+ */
1598
+ interface ExpressRequest {
1599
+ headers: Record<string, string | string[] | undefined>;
1600
+ body?: unknown;
1601
+ params?: Record<string, string>;
1602
+ query?: Record<string, string | string[] | undefined>;
1603
+ x402?: {
1604
+ payer: string;
1605
+ txHash: string;
1606
+ };
1607
+ }
1608
+ /**
1609
+ * Express-like Response 接口
1610
+ */
1611
+ interface ExpressResponse {
1612
+ status(code: number): this;
1613
+ json(body: unknown): this;
1614
+ }
1615
+ /**
1616
+ * Express-like NextFunction 类型
1617
+ */
1618
+ type ExpressNextFunction = (error?: Error) => void;
1619
+ /**
1620
+ * Express 中间件配置选项
1621
+ */
1622
+ interface ExpressMiddlewareOptions {
1623
+ /** X402Server 实例 */
1624
+ server: X402Server;
1625
+ /** 获取 token 地址的函数 */
1626
+ getToken: (req: ExpressRequest) => string | Promise<string>;
1627
+ /** 获取金额的函数 */
1628
+ getAmount: (req: ExpressRequest) => string | Promise<string>;
1629
+ /** 可选:获取额外配置的函数 */
1630
+ getConfig?: (req: ExpressRequest) => Partial<CreateRequirementsConfig> | Promise<Partial<CreateRequirementsConfig>>;
1631
+ /** 可选:自定义错误处理 */
1632
+ onError?: (error: Error, req: ExpressRequest, res: ExpressResponse) => void;
1633
+ /** 可选:自定义 402 响应处理 */
1634
+ on402?: (req: ExpressRequest, res: ExpressResponse, response402: Response402) => void;
1635
+ /** 可选:支付成功后的回调 */
1636
+ onPaymentSuccess?: (req: ExpressRequest, payer: string, txHash: string) => void | Promise<void>;
1637
+ }
1638
+ /**
1639
+ * 创建 Express 中间件
1640
+ *
1641
+ * @param options - 中间件配置
1642
+ * @returns Express 中间件函数
1643
+ *
1644
+ * @example
1645
+ * ```typescript
1646
+ * const middleware = createExpressMiddleware({
1647
+ * server,
1648
+ * getToken: (req) => req.body.token || USDC,
1649
+ * getAmount: (req) => calculatePrice(req.body),
1650
+ * });
1651
+ *
1652
+ * app.post("/api/resource", middleware, (req, res) => {
1653
+ * // Payment already verified and settled
1654
+ * const { payer, txHash } = req.x402;
1655
+ * res.json({ data: "resource", payer, txHash });
1656
+ * });
1657
+ * ```
1658
+ */
1659
+ declare function createExpressMiddleware(options: ExpressMiddlewareOptions): (req: ExpressRequest, res: ExpressResponse, next: ExpressNextFunction) => Promise<void>;
1660
+
1661
+ /**
1662
+ * Hono 中间件 for x402 Payment Protocol
1663
+ */
1664
+
1665
+ /**
1666
+ * Hono-like Request 接口
1667
+ */
1668
+ interface HonoRequest {
1669
+ header(name: string): string | undefined;
1670
+ json<T = unknown>(): Promise<T>;
1671
+ query(name: string): string | undefined;
1672
+ }
1673
+ /**
1674
+ * Hono-like Context 接口
1675
+ */
1676
+ interface HonoContext {
1677
+ req: HonoRequest;
1678
+ json(body: unknown, status?: number): Response;
1679
+ set(key: string, value: unknown): void;
1680
+ get(key: string): unknown;
1681
+ }
1682
+ /**
1683
+ * Hono-like Next 函数
1684
+ */
1685
+ type HonoNext = () => Promise<void>;
1686
+ /**
1687
+ * Hono 中间件函数类型
1688
+ */
1689
+ type HonoMiddlewareHandler = (c: HonoContext, next: HonoNext) => Promise<Response | void>;
1690
+ /**
1691
+ * Hono 中间件配置选项
1692
+ */
1693
+ interface HonoMiddlewareOptions {
1694
+ /** X402Server 实例 */
1695
+ server: X402Server;
1696
+ /** 获取 token 地址的函数 */
1697
+ getToken: (c: HonoContext) => string | Promise<string>;
1698
+ /** 获取金额的函数 */
1699
+ getAmount: (c: HonoContext) => string | Promise<string>;
1700
+ /** 可选:获取额外配置的函数 */
1701
+ getConfig?: (c: HonoContext) => Partial<CreateRequirementsConfig> | Promise<Partial<CreateRequirementsConfig>>;
1702
+ /** 可选:自定义错误处理 */
1703
+ onError?: (error: Error, c: HonoContext) => Response | Promise<Response>;
1704
+ /** 可选:自定义 402 响应处理 */
1705
+ on402?: (c: HonoContext, response402: Response402) => Response | Promise<Response>;
1706
+ /** 可选:支付成功后的回调 */
1707
+ onPaymentSuccess?: (c: HonoContext, payer: string, txHash: string) => void | Promise<void>;
1708
+ }
1709
+ /**
1710
+ * 创建 Hono 中间件
1711
+ *
1712
+ * @param options - 中间件配置
1713
+ * @returns Hono 中间件函数
1714
+ *
1715
+ * @example
1716
+ * ```typescript
1717
+ * const middleware = createHonoMiddleware({
1718
+ * server,
1719
+ * getToken: (c) => c.req.query("token") || USDC,
1720
+ * getAmount: async (c) => {
1721
+ * const body = await c.req.json();
1722
+ * return calculatePrice(body.complexity);
1723
+ * },
1724
+ * });
1725
+ *
1726
+ * app.post("/api/resource", middleware, (c) => {
1727
+ * // Payment already verified and settled
1728
+ * const { payer, txHash } = c.get("x402");
1729
+ * return c.json({ data: "resource", payer, txHash });
1730
+ * });
1731
+ * ```
1732
+ */
1733
+ declare function createHonoMiddleware(options: HonoMiddlewareOptions): HonoMiddlewareHandler;
1734
+
1735
+ /**
1736
+ * 解码 Base64 字符串
1737
+ *
1738
+ * @param base64 - Base64 编码的字符串
1739
+ * @returns 解码后的字符串
1740
+ */
1741
+ declare function decodeBase64(base64: string): string;
1742
+ /**
1743
+ * 编码为 Base64 字符串
1744
+ *
1745
+ * @param str - 要编码的字符串
1746
+ * @returns Base64 编码的字符串
1747
+ */
1748
+ declare function encodeBase64(str: string): string;
1749
+
1750
+ export { type CreateRequirementsConfig, CreateRequirementsConfigSchema, type ExpressMiddlewareOptions, type HonoMiddlewareOptions, type InitResult, InitResultSchema, type ParseResult, ParseResultSchema, type ParsedPayment, ParsedPaymentSchema, type PaymentPayload, type PaymentRequirements, type ProcessResult, ProcessResultSchema, type Response402, Response402Schema, type SettleResult, SettleResultSchema, type VerifyResult, VerifyResultSchema, X402Server, type X402ServerConfig, createExpressMiddleware, createHonoMiddleware, decodeBase64, encodeBase64 };