sf-x402x 0.6.6-patch.3

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 (92) hide show
  1. package/README.md +60 -0
  2. package/dist/cjs/client/index.d.ts +64 -0
  3. package/dist/cjs/client/index.js +811 -0
  4. package/dist/cjs/client/index.js.map +1 -0
  5. package/dist/cjs/config-CFBSAuxW.d.ts +10 -0
  6. package/dist/cjs/config-Dfuvno71.d.ts +19 -0
  7. package/dist/cjs/facilitator/index.d.ts +42 -0
  8. package/dist/cjs/facilitator/index.js +1827 -0
  9. package/dist/cjs/facilitator/index.js.map +1 -0
  10. package/dist/cjs/index.d.ts +16 -0
  11. package/dist/cjs/index.js +2207 -0
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/middleware-BcYD9vqv.d.ts +93 -0
  14. package/dist/cjs/middleware-DagbDyNz.d.ts +93 -0
  15. package/dist/cjs/network--RYzQfBg.d.ts +11 -0
  16. package/dist/cjs/network-BGTUrx-D.d.ts +11 -0
  17. package/dist/cjs/paywall/index.d.ts +30 -0
  18. package/dist/cjs/paywall/index.js +141 -0
  19. package/dist/cjs/paywall/index.js.map +1 -0
  20. package/dist/cjs/rpc-De2c0oKR.d.ts +35 -0
  21. package/dist/cjs/rpc-TVntAK7V.d.ts +35 -0
  22. package/dist/cjs/schemes/index.d.ts +298 -0
  23. package/dist/cjs/schemes/index.js +2121 -0
  24. package/dist/cjs/schemes/index.js.map +1 -0
  25. package/dist/cjs/shared/evm/index.d.ts +55 -0
  26. package/dist/cjs/shared/evm/index.js +910 -0
  27. package/dist/cjs/shared/evm/index.js.map +1 -0
  28. package/dist/cjs/shared/index.d.ts +181 -0
  29. package/dist/cjs/shared/index.js +667 -0
  30. package/dist/cjs/shared/index.js.map +1 -0
  31. package/dist/cjs/types/index.d.ts +1214 -0
  32. package/dist/cjs/types/index.js +1408 -0
  33. package/dist/cjs/types/index.js.map +1 -0
  34. package/dist/cjs/verify/index.d.ts +7 -0
  35. package/dist/cjs/verify/index.js +427 -0
  36. package/dist/cjs/verify/index.js.map +1 -0
  37. package/dist/cjs/wallet-BReyvAJs.d.ts +151 -0
  38. package/dist/cjs/wallet-BTqCm9Zp.d.ts +27 -0
  39. package/dist/cjs/wallet-DndoTf1_.d.ts +48 -0
  40. package/dist/cjs/x402Specs-7OH8g851.d.ts +1306 -0
  41. package/dist/cjs/x402Specs-CFX8TBKR.d.ts +1306 -0
  42. package/dist/esm/chunk-5UPAZUO6.mjs +90 -0
  43. package/dist/esm/chunk-5UPAZUO6.mjs.map +1 -0
  44. package/dist/esm/chunk-7CWEZNFA.mjs +812 -0
  45. package/dist/esm/chunk-7CWEZNFA.mjs.map +1 -0
  46. package/dist/esm/chunk-MWDK4RSB.mjs +620 -0
  47. package/dist/esm/chunk-MWDK4RSB.mjs.map +1 -0
  48. package/dist/esm/chunk-R2NI44QI.mjs +327 -0
  49. package/dist/esm/chunk-R2NI44QI.mjs.map +1 -0
  50. package/dist/esm/chunk-WS2W5DJT.mjs +58 -0
  51. package/dist/esm/chunk-WS2W5DJT.mjs.map +1 -0
  52. package/dist/esm/chunk-XZA3USQF.mjs +784 -0
  53. package/dist/esm/chunk-XZA3USQF.mjs.map +1 -0
  54. package/dist/esm/chunk-Z3INM7T4.mjs +106 -0
  55. package/dist/esm/chunk-Z3INM7T4.mjs.map +1 -0
  56. package/dist/esm/client/index.d.mts +64 -0
  57. package/dist/esm/client/index.mjs +17 -0
  58. package/dist/esm/client/index.mjs.map +1 -0
  59. package/dist/esm/config-CFBSAuxW.d.mts +10 -0
  60. package/dist/esm/config-Dfuvno71.d.mts +19 -0
  61. package/dist/esm/facilitator/index.d.mts +42 -0
  62. package/dist/esm/facilitator/index.mjs +14 -0
  63. package/dist/esm/facilitator/index.mjs.map +1 -0
  64. package/dist/esm/index.d.mts +16 -0
  65. package/dist/esm/index.mjs +28 -0
  66. package/dist/esm/index.mjs.map +1 -0
  67. package/dist/esm/middleware-CAOp-bv4.d.mts +93 -0
  68. package/dist/esm/network--RYzQfBg.d.mts +11 -0
  69. package/dist/esm/paywall/index.d.mts +30 -0
  70. package/dist/esm/paywall/index.mjs +46 -0
  71. package/dist/esm/paywall/index.mjs.map +1 -0
  72. package/dist/esm/rpc-22QIQWIu.d.mts +35 -0
  73. package/dist/esm/schemes/index.d.mts +298 -0
  74. package/dist/esm/schemes/index.mjs +16 -0
  75. package/dist/esm/schemes/index.mjs.map +1 -0
  76. package/dist/esm/shared/evm/index.d.mts +55 -0
  77. package/dist/esm/shared/evm/index.mjs +18 -0
  78. package/dist/esm/shared/evm/index.mjs.map +1 -0
  79. package/dist/esm/shared/index.d.mts +181 -0
  80. package/dist/esm/shared/index.mjs +31 -0
  81. package/dist/esm/shared/index.mjs.map +1 -0
  82. package/dist/esm/types/index.d.mts +1214 -0
  83. package/dist/esm/types/index.mjs +81 -0
  84. package/dist/esm/types/index.mjs.map +1 -0
  85. package/dist/esm/verify/index.d.mts +7 -0
  86. package/dist/esm/verify/index.mjs +105 -0
  87. package/dist/esm/verify/index.mjs.map +1 -0
  88. package/dist/esm/wallet-BReyvAJs.d.mts +151 -0
  89. package/dist/esm/wallet-BTqCm9Zp.d.mts +27 -0
  90. package/dist/esm/wallet-C9iHSQbd.d.mts +48 -0
  91. package/dist/esm/x402Specs-7OH8g851.d.mts +1306 -0
  92. package/package.json +152 -0
@@ -0,0 +1,2207 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ createPaymentHeader: () => createPaymentHeader3,
24
+ preparePaymentHeader: () => preparePaymentHeader2,
25
+ selectPaymentRequirements: () => selectPaymentRequirements,
26
+ settle: () => settle3,
27
+ signPaymentHeader: () => signPaymentHeader2,
28
+ verify: () => verify3,
29
+ x402Version: () => x402Version
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+
33
+ // src/types/shared/evm/config.ts
34
+ var config = {
35
+ "84532": {
36
+ usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
37
+ usdcName: "USDC"
38
+ },
39
+ "8453": {
40
+ usdcAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
41
+ usdcName: "USD Coin"
42
+ },
43
+ "43113": {
44
+ usdcAddress: "0x5425890298aed601595a70AB815c96711a31Bc65",
45
+ usdcName: "USD Coin"
46
+ },
47
+ "43114": {
48
+ usdcAddress: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
49
+ usdcName: "USD Coin"
50
+ },
51
+ "4689": {
52
+ usdcAddress: "0xcdf79194c6c285077a58da47641d4dbe51f63542",
53
+ usdcName: "Bridged USDC"
54
+ },
55
+ // solana devnet
56
+ "103": {
57
+ usdcAddress: "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU",
58
+ usdcName: "USDC"
59
+ },
60
+ // solana mainnet
61
+ "101": {
62
+ usdcAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
63
+ usdcName: "USDC"
64
+ },
65
+ "1328": {
66
+ usdcAddress: "0x4fcf1784b31630811181f670aea7a7bef803eaed",
67
+ usdcName: "USDC"
68
+ },
69
+ "1329": {
70
+ usdcAddress: "0xe15fc38f6d8c56af07bbcbe3baf5708a2bf42392",
71
+ usdcName: "USDC"
72
+ },
73
+ "137": {
74
+ usdcAddress: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
75
+ usdcName: "USD Coin"
76
+ },
77
+ "80002": {
78
+ usdcAddress: "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582",
79
+ usdcName: "USDC"
80
+ },
81
+ "3338": {
82
+ usdcAddress: "0xbbA60da06c2c5424f03f7434542280FCAd453d10",
83
+ usdcName: "USDC"
84
+ },
85
+ "196": {
86
+ usdcAddress: "0x74b7f16337b8972027f6196a17a631ac6de26d22",
87
+ usdcName: "USD Coin"
88
+ },
89
+ "1952": {
90
+ usdcAddress: "0xcb8bf24c6ce16ad21d707c9505421a17f2bec79d",
91
+ usdcName: "USDC_TEST"
92
+ },
93
+ // sepolia - using JPYC (JPY Coin)
94
+ "11155111": {
95
+ usdcAddress: "0xE7C3D8C9a439feDe00D2600032D5dB0Be71C3c29",
96
+ usdcName: "JPY Coin"
97
+ },
98
+ // filecoin-calibration - using USD for Filecoin Community
99
+ "314159": {
100
+ usdcAddress: "0xb3042734b608a1B16e9e86B374A3f3e389B4cDf0",
101
+ usdcName: "USD for Filecoin Community"
102
+ }
103
+ };
104
+
105
+ // src/types/shared/evm/eip3009.ts
106
+ var authorizationTypes = {
107
+ TransferWithAuthorization: [
108
+ { name: "from", type: "address" },
109
+ { name: "to", type: "address" },
110
+ { name: "value", type: "uint256" },
111
+ { name: "validAfter", type: "uint256" },
112
+ { name: "validBefore", type: "uint256" },
113
+ { name: "nonce", type: "bytes32" }
114
+ ]
115
+ };
116
+
117
+ // src/types/shared/evm/erc20PermitABI.ts
118
+ var usdcABI = [
119
+ {
120
+ anonymous: false,
121
+ inputs: [
122
+ {
123
+ indexed: true,
124
+ internalType: "address",
125
+ name: "owner",
126
+ type: "address"
127
+ },
128
+ {
129
+ indexed: true,
130
+ internalType: "address",
131
+ name: "spender",
132
+ type: "address"
133
+ },
134
+ {
135
+ indexed: false,
136
+ internalType: "uint256",
137
+ name: "value",
138
+ type: "uint256"
139
+ }
140
+ ],
141
+ name: "Approval",
142
+ type: "event"
143
+ },
144
+ {
145
+ anonymous: false,
146
+ inputs: [
147
+ {
148
+ indexed: true,
149
+ internalType: "address",
150
+ name: "authorizer",
151
+ type: "address"
152
+ },
153
+ {
154
+ indexed: true,
155
+ internalType: "bytes32",
156
+ name: "nonce",
157
+ type: "bytes32"
158
+ }
159
+ ],
160
+ name: "AuthorizationCanceled",
161
+ type: "event"
162
+ },
163
+ {
164
+ anonymous: false,
165
+ inputs: [
166
+ {
167
+ indexed: true,
168
+ internalType: "address",
169
+ name: "authorizer",
170
+ type: "address"
171
+ },
172
+ {
173
+ indexed: true,
174
+ internalType: "bytes32",
175
+ name: "nonce",
176
+ type: "bytes32"
177
+ }
178
+ ],
179
+ name: "AuthorizationUsed",
180
+ type: "event"
181
+ },
182
+ {
183
+ anonymous: false,
184
+ inputs: [
185
+ {
186
+ indexed: true,
187
+ internalType: "address",
188
+ name: "_account",
189
+ type: "address"
190
+ }
191
+ ],
192
+ name: "Blacklisted",
193
+ type: "event"
194
+ },
195
+ {
196
+ anonymous: false,
197
+ inputs: [
198
+ {
199
+ indexed: true,
200
+ internalType: "address",
201
+ name: "newBlacklister",
202
+ type: "address"
203
+ }
204
+ ],
205
+ name: "BlacklisterChanged",
206
+ type: "event"
207
+ },
208
+ {
209
+ anonymous: false,
210
+ inputs: [
211
+ {
212
+ indexed: true,
213
+ internalType: "address",
214
+ name: "burner",
215
+ type: "address"
216
+ },
217
+ {
218
+ indexed: false,
219
+ internalType: "uint256",
220
+ name: "amount",
221
+ type: "uint256"
222
+ }
223
+ ],
224
+ name: "Burn",
225
+ type: "event"
226
+ },
227
+ {
228
+ anonymous: false,
229
+ inputs: [
230
+ {
231
+ indexed: true,
232
+ internalType: "address",
233
+ name: "newMasterMinter",
234
+ type: "address"
235
+ }
236
+ ],
237
+ name: "MasterMinterChanged",
238
+ type: "event"
239
+ },
240
+ {
241
+ anonymous: false,
242
+ inputs: [
243
+ {
244
+ indexed: true,
245
+ internalType: "address",
246
+ name: "minter",
247
+ type: "address"
248
+ },
249
+ { indexed: true, internalType: "address", name: "to", type: "address" },
250
+ {
251
+ indexed: false,
252
+ internalType: "uint256",
253
+ name: "amount",
254
+ type: "uint256"
255
+ }
256
+ ],
257
+ name: "Mint",
258
+ type: "event"
259
+ },
260
+ {
261
+ anonymous: false,
262
+ inputs: [
263
+ {
264
+ indexed: true,
265
+ internalType: "address",
266
+ name: "minter",
267
+ type: "address"
268
+ },
269
+ {
270
+ indexed: false,
271
+ internalType: "uint256",
272
+ name: "minterAllowedAmount",
273
+ type: "uint256"
274
+ }
275
+ ],
276
+ name: "MinterConfigured",
277
+ type: "event"
278
+ },
279
+ {
280
+ anonymous: false,
281
+ inputs: [
282
+ {
283
+ indexed: true,
284
+ internalType: "address",
285
+ name: "oldMinter",
286
+ type: "address"
287
+ }
288
+ ],
289
+ name: "MinterRemoved",
290
+ type: "event"
291
+ },
292
+ {
293
+ anonymous: false,
294
+ inputs: [
295
+ {
296
+ indexed: false,
297
+ internalType: "address",
298
+ name: "previousOwner",
299
+ type: "address"
300
+ },
301
+ {
302
+ indexed: false,
303
+ internalType: "address",
304
+ name: "newOwner",
305
+ type: "address"
306
+ }
307
+ ],
308
+ name: "OwnershipTransferred",
309
+ type: "event"
310
+ },
311
+ { anonymous: false, inputs: [], name: "Pause", type: "event" },
312
+ {
313
+ anonymous: false,
314
+ inputs: [
315
+ {
316
+ indexed: true,
317
+ internalType: "address",
318
+ name: "newAddress",
319
+ type: "address"
320
+ }
321
+ ],
322
+ name: "PauserChanged",
323
+ type: "event"
324
+ },
325
+ {
326
+ anonymous: false,
327
+ inputs: [
328
+ {
329
+ indexed: true,
330
+ internalType: "address",
331
+ name: "newRescuer",
332
+ type: "address"
333
+ }
334
+ ],
335
+ name: "RescuerChanged",
336
+ type: "event"
337
+ },
338
+ {
339
+ anonymous: false,
340
+ inputs: [
341
+ { indexed: true, internalType: "address", name: "from", type: "address" },
342
+ { indexed: true, internalType: "address", name: "to", type: "address" },
343
+ {
344
+ indexed: false,
345
+ internalType: "uint256",
346
+ name: "value",
347
+ type: "uint256"
348
+ }
349
+ ],
350
+ name: "Transfer",
351
+ type: "event"
352
+ },
353
+ {
354
+ anonymous: false,
355
+ inputs: [
356
+ {
357
+ indexed: true,
358
+ internalType: "address",
359
+ name: "_account",
360
+ type: "address"
361
+ }
362
+ ],
363
+ name: "UnBlacklisted",
364
+ type: "event"
365
+ },
366
+ { anonymous: false, inputs: [], name: "Unpause", type: "event" },
367
+ {
368
+ inputs: [],
369
+ name: "CANCEL_AUTHORIZATION_TYPEHASH",
370
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
371
+ stateMutability: "view",
372
+ type: "function"
373
+ },
374
+ {
375
+ inputs: [],
376
+ name: "DOMAIN_SEPARATOR",
377
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
378
+ stateMutability: "view",
379
+ type: "function"
380
+ },
381
+ {
382
+ inputs: [],
383
+ name: "PERMIT_TYPEHASH",
384
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
385
+ stateMutability: "view",
386
+ type: "function"
387
+ },
388
+ {
389
+ inputs: [],
390
+ name: "RECEIVE_WITH_AUTHORIZATION_TYPEHASH",
391
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
392
+ stateMutability: "view",
393
+ type: "function"
394
+ },
395
+ {
396
+ inputs: [],
397
+ name: "TRANSFER_WITH_AUTHORIZATION_TYPEHASH",
398
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
399
+ stateMutability: "view",
400
+ type: "function"
401
+ },
402
+ {
403
+ inputs: [
404
+ { internalType: "address", name: "owner", type: "address" },
405
+ { internalType: "address", name: "spender", type: "address" }
406
+ ],
407
+ name: "allowance",
408
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
409
+ stateMutability: "view",
410
+ type: "function"
411
+ },
412
+ {
413
+ inputs: [
414
+ { internalType: "address", name: "spender", type: "address" },
415
+ { internalType: "uint256", name: "value", type: "uint256" }
416
+ ],
417
+ name: "approve",
418
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
419
+ stateMutability: "nonpayable",
420
+ type: "function"
421
+ },
422
+ {
423
+ inputs: [
424
+ { internalType: "address", name: "authorizer", type: "address" },
425
+ { internalType: "bytes32", name: "nonce", type: "bytes32" }
426
+ ],
427
+ name: "authorizationState",
428
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
429
+ stateMutability: "view",
430
+ type: "function"
431
+ },
432
+ {
433
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
434
+ name: "balanceOf",
435
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
436
+ stateMutability: "view",
437
+ type: "function"
438
+ },
439
+ {
440
+ inputs: [{ internalType: "address", name: "_account", type: "address" }],
441
+ name: "blacklist",
442
+ outputs: [],
443
+ stateMutability: "nonpayable",
444
+ type: "function"
445
+ },
446
+ {
447
+ inputs: [],
448
+ name: "blacklister",
449
+ outputs: [{ internalType: "address", name: "", type: "address" }],
450
+ stateMutability: "view",
451
+ type: "function"
452
+ },
453
+ {
454
+ inputs: [{ internalType: "uint256", name: "_amount", type: "uint256" }],
455
+ name: "burn",
456
+ outputs: [],
457
+ stateMutability: "nonpayable",
458
+ type: "function"
459
+ },
460
+ {
461
+ inputs: [
462
+ { internalType: "address", name: "authorizer", type: "address" },
463
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
464
+ { internalType: "uint8", name: "v", type: "uint8" },
465
+ { internalType: "bytes32", name: "r", type: "bytes32" },
466
+ { internalType: "bytes32", name: "s", type: "bytes32" }
467
+ ],
468
+ name: "cancelAuthorization",
469
+ outputs: [],
470
+ stateMutability: "nonpayable",
471
+ type: "function"
472
+ },
473
+ {
474
+ inputs: [
475
+ { internalType: "address", name: "authorizer", type: "address" },
476
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
477
+ { internalType: "bytes", name: "signature", type: "bytes" }
478
+ ],
479
+ name: "cancelAuthorization",
480
+ outputs: [],
481
+ stateMutability: "nonpayable",
482
+ type: "function"
483
+ },
484
+ {
485
+ inputs: [
486
+ { internalType: "address", name: "minter", type: "address" },
487
+ { internalType: "uint256", name: "minterAllowedAmount", type: "uint256" }
488
+ ],
489
+ name: "configureMinter",
490
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
491
+ stateMutability: "nonpayable",
492
+ type: "function"
493
+ },
494
+ {
495
+ inputs: [],
496
+ name: "currency",
497
+ outputs: [{ internalType: "string", name: "", type: "string" }],
498
+ stateMutability: "view",
499
+ type: "function"
500
+ },
501
+ {
502
+ inputs: [],
503
+ name: "decimals",
504
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
505
+ stateMutability: "view",
506
+ type: "function"
507
+ },
508
+ {
509
+ inputs: [
510
+ { internalType: "address", name: "spender", type: "address" },
511
+ { internalType: "uint256", name: "decrement", type: "uint256" }
512
+ ],
513
+ name: "decreaseAllowance",
514
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
515
+ stateMutability: "nonpayable",
516
+ type: "function"
517
+ },
518
+ {
519
+ inputs: [
520
+ { internalType: "address", name: "spender", type: "address" },
521
+ { internalType: "uint256", name: "increment", type: "uint256" }
522
+ ],
523
+ name: "increaseAllowance",
524
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
525
+ stateMutability: "nonpayable",
526
+ type: "function"
527
+ },
528
+ {
529
+ inputs: [
530
+ { internalType: "string", name: "tokenName", type: "string" },
531
+ { internalType: "string", name: "tokenSymbol", type: "string" },
532
+ { internalType: "string", name: "tokenCurrency", type: "string" },
533
+ { internalType: "uint8", name: "tokenDecimals", type: "uint8" },
534
+ { internalType: "address", name: "newMasterMinter", type: "address" },
535
+ { internalType: "address", name: "newPauser", type: "address" },
536
+ { internalType: "address", name: "newBlacklister", type: "address" },
537
+ { internalType: "address", name: "newOwner", type: "address" }
538
+ ],
539
+ name: "initialize",
540
+ outputs: [],
541
+ stateMutability: "nonpayable",
542
+ type: "function"
543
+ },
544
+ {
545
+ inputs: [{ internalType: "string", name: "newName", type: "string" }],
546
+ name: "initializeV2",
547
+ outputs: [],
548
+ stateMutability: "nonpayable",
549
+ type: "function"
550
+ },
551
+ {
552
+ inputs: [{ internalType: "address", name: "lostAndFound", type: "address" }],
553
+ name: "initializeV2_1",
554
+ outputs: [],
555
+ stateMutability: "nonpayable",
556
+ type: "function"
557
+ },
558
+ {
559
+ inputs: [
560
+ {
561
+ internalType: "address[]",
562
+ name: "accountsToBlacklist",
563
+ type: "address[]"
564
+ },
565
+ { internalType: "string", name: "newSymbol", type: "string" }
566
+ ],
567
+ name: "initializeV2_2",
568
+ outputs: [],
569
+ stateMutability: "nonpayable",
570
+ type: "function"
571
+ },
572
+ {
573
+ inputs: [{ internalType: "address", name: "_account", type: "address" }],
574
+ name: "isBlacklisted",
575
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
576
+ stateMutability: "view",
577
+ type: "function"
578
+ },
579
+ {
580
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
581
+ name: "isMinter",
582
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
583
+ stateMutability: "view",
584
+ type: "function"
585
+ },
586
+ {
587
+ inputs: [],
588
+ name: "masterMinter",
589
+ outputs: [{ internalType: "address", name: "", type: "address" }],
590
+ stateMutability: "view",
591
+ type: "function"
592
+ },
593
+ {
594
+ inputs: [
595
+ { internalType: "address", name: "_to", type: "address" },
596
+ { internalType: "uint256", name: "_amount", type: "uint256" }
597
+ ],
598
+ name: "mint",
599
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
600
+ stateMutability: "nonpayable",
601
+ type: "function"
602
+ },
603
+ {
604
+ inputs: [{ internalType: "address", name: "minter", type: "address" }],
605
+ name: "minterAllowance",
606
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
607
+ stateMutability: "view",
608
+ type: "function"
609
+ },
610
+ {
611
+ inputs: [],
612
+ name: "name",
613
+ outputs: [{ internalType: "string", name: "", type: "string" }],
614
+ stateMutability: "view",
615
+ type: "function"
616
+ },
617
+ {
618
+ inputs: [{ internalType: "address", name: "owner", type: "address" }],
619
+ name: "nonces",
620
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
621
+ stateMutability: "view",
622
+ type: "function"
623
+ },
624
+ {
625
+ inputs: [],
626
+ name: "owner",
627
+ outputs: [{ internalType: "address", name: "", type: "address" }],
628
+ stateMutability: "view",
629
+ type: "function"
630
+ },
631
+ {
632
+ inputs: [],
633
+ name: "pause",
634
+ outputs: [],
635
+ stateMutability: "nonpayable",
636
+ type: "function"
637
+ },
638
+ {
639
+ inputs: [],
640
+ name: "paused",
641
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
642
+ stateMutability: "view",
643
+ type: "function"
644
+ },
645
+ {
646
+ inputs: [],
647
+ name: "pauser",
648
+ outputs: [{ internalType: "address", name: "", type: "address" }],
649
+ stateMutability: "view",
650
+ type: "function"
651
+ },
652
+ {
653
+ inputs: [
654
+ { internalType: "address", name: "owner", type: "address" },
655
+ { internalType: "address", name: "spender", type: "address" },
656
+ { internalType: "uint256", name: "value", type: "uint256" },
657
+ { internalType: "uint256", name: "deadline", type: "uint256" },
658
+ { internalType: "bytes", name: "signature", type: "bytes" }
659
+ ],
660
+ name: "permit",
661
+ outputs: [],
662
+ stateMutability: "nonpayable",
663
+ type: "function"
664
+ },
665
+ {
666
+ inputs: [
667
+ { internalType: "address", name: "owner", type: "address" },
668
+ { internalType: "address", name: "spender", type: "address" },
669
+ { internalType: "uint256", name: "value", type: "uint256" },
670
+ { internalType: "uint256", name: "deadline", type: "uint256" },
671
+ { internalType: "uint8", name: "v", type: "uint8" },
672
+ { internalType: "bytes32", name: "r", type: "bytes32" },
673
+ { internalType: "bytes32", name: "s", type: "bytes32" }
674
+ ],
675
+ name: "permit",
676
+ outputs: [],
677
+ stateMutability: "nonpayable",
678
+ type: "function"
679
+ },
680
+ {
681
+ inputs: [
682
+ { internalType: "address", name: "from", type: "address" },
683
+ { internalType: "address", name: "to", type: "address" },
684
+ { internalType: "uint256", name: "value", type: "uint256" },
685
+ { internalType: "uint256", name: "validAfter", type: "uint256" },
686
+ { internalType: "uint256", name: "validBefore", type: "uint256" },
687
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
688
+ { internalType: "bytes", name: "signature", type: "bytes" }
689
+ ],
690
+ name: "receiveWithAuthorization",
691
+ outputs: [],
692
+ stateMutability: "nonpayable",
693
+ type: "function"
694
+ },
695
+ {
696
+ inputs: [
697
+ { internalType: "address", name: "from", type: "address" },
698
+ { internalType: "address", name: "to", type: "address" },
699
+ { internalType: "uint256", name: "value", type: "uint256" },
700
+ { internalType: "uint256", name: "validAfter", type: "uint256" },
701
+ { internalType: "uint256", name: "validBefore", type: "uint256" },
702
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
703
+ { internalType: "uint8", name: "v", type: "uint8" },
704
+ { internalType: "bytes32", name: "r", type: "bytes32" },
705
+ { internalType: "bytes32", name: "s", type: "bytes32" }
706
+ ],
707
+ name: "receiveWithAuthorization",
708
+ outputs: [],
709
+ stateMutability: "nonpayable",
710
+ type: "function"
711
+ },
712
+ {
713
+ inputs: [{ internalType: "address", name: "minter", type: "address" }],
714
+ name: "removeMinter",
715
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
716
+ stateMutability: "nonpayable",
717
+ type: "function"
718
+ },
719
+ {
720
+ inputs: [
721
+ {
722
+ internalType: "contract IERC20",
723
+ name: "tokenContract",
724
+ type: "address"
725
+ },
726
+ { internalType: "address", name: "to", type: "address" },
727
+ { internalType: "uint256", name: "amount", type: "uint256" }
728
+ ],
729
+ name: "rescueERC20",
730
+ outputs: [],
731
+ stateMutability: "nonpayable",
732
+ type: "function"
733
+ },
734
+ {
735
+ inputs: [],
736
+ name: "rescuer",
737
+ outputs: [{ internalType: "address", name: "", type: "address" }],
738
+ stateMutability: "view",
739
+ type: "function"
740
+ },
741
+ {
742
+ inputs: [],
743
+ name: "symbol",
744
+ outputs: [{ internalType: "string", name: "", type: "string" }],
745
+ stateMutability: "view",
746
+ type: "function"
747
+ },
748
+ {
749
+ inputs: [],
750
+ name: "totalSupply",
751
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
752
+ stateMutability: "view",
753
+ type: "function"
754
+ },
755
+ {
756
+ inputs: [
757
+ { internalType: "address", name: "to", type: "address" },
758
+ { internalType: "uint256", name: "value", type: "uint256" }
759
+ ],
760
+ name: "transfer",
761
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
762
+ stateMutability: "nonpayable",
763
+ type: "function"
764
+ },
765
+ {
766
+ inputs: [
767
+ { internalType: "address", name: "from", type: "address" },
768
+ { internalType: "address", name: "to", type: "address" },
769
+ { internalType: "uint256", name: "value", type: "uint256" }
770
+ ],
771
+ name: "transferFrom",
772
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
773
+ stateMutability: "nonpayable",
774
+ type: "function"
775
+ },
776
+ {
777
+ inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
778
+ name: "transferOwnership",
779
+ outputs: [],
780
+ stateMutability: "nonpayable",
781
+ type: "function"
782
+ },
783
+ {
784
+ inputs: [
785
+ { internalType: "address", name: "from", type: "address" },
786
+ { internalType: "address", name: "to", type: "address" },
787
+ { internalType: "uint256", name: "value", type: "uint256" },
788
+ { internalType: "uint256", name: "validAfter", type: "uint256" },
789
+ { internalType: "uint256", name: "validBefore", type: "uint256" },
790
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
791
+ { internalType: "bytes", name: "signature", type: "bytes" }
792
+ ],
793
+ name: "transferWithAuthorization",
794
+ outputs: [],
795
+ stateMutability: "nonpayable",
796
+ type: "function"
797
+ },
798
+ {
799
+ inputs: [
800
+ { internalType: "address", name: "from", type: "address" },
801
+ { internalType: "address", name: "to", type: "address" },
802
+ { internalType: "uint256", name: "value", type: "uint256" },
803
+ { internalType: "uint256", name: "validAfter", type: "uint256" },
804
+ { internalType: "uint256", name: "validBefore", type: "uint256" },
805
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
806
+ { internalType: "uint8", name: "v", type: "uint8" },
807
+ { internalType: "bytes32", name: "r", type: "bytes32" },
808
+ { internalType: "bytes32", name: "s", type: "bytes32" }
809
+ ],
810
+ name: "transferWithAuthorization",
811
+ outputs: [],
812
+ stateMutability: "nonpayable",
813
+ type: "function"
814
+ },
815
+ {
816
+ inputs: [{ internalType: "address", name: "_account", type: "address" }],
817
+ name: "unBlacklist",
818
+ outputs: [],
819
+ stateMutability: "nonpayable",
820
+ type: "function"
821
+ },
822
+ {
823
+ inputs: [],
824
+ name: "unpause",
825
+ outputs: [],
826
+ stateMutability: "nonpayable",
827
+ type: "function"
828
+ },
829
+ {
830
+ inputs: [{ internalType: "address", name: "_newBlacklister", type: "address" }],
831
+ name: "updateBlacklister",
832
+ outputs: [],
833
+ stateMutability: "nonpayable",
834
+ type: "function"
835
+ },
836
+ {
837
+ inputs: [{ internalType: "address", name: "_newMasterMinter", type: "address" }],
838
+ name: "updateMasterMinter",
839
+ outputs: [],
840
+ stateMutability: "nonpayable",
841
+ type: "function"
842
+ },
843
+ {
844
+ inputs: [{ internalType: "address", name: "_newPauser", type: "address" }],
845
+ name: "updatePauser",
846
+ outputs: [],
847
+ stateMutability: "nonpayable",
848
+ type: "function"
849
+ },
850
+ {
851
+ inputs: [{ internalType: "address", name: "newRescuer", type: "address" }],
852
+ name: "updateRescuer",
853
+ outputs: [],
854
+ stateMutability: "nonpayable",
855
+ type: "function"
856
+ },
857
+ {
858
+ inputs: [],
859
+ name: "version",
860
+ outputs: [{ internalType: "string", name: "", type: "string" }],
861
+ stateMutability: "pure",
862
+ type: "function"
863
+ }
864
+ ];
865
+
866
+ // src/types/shared/evm/wallet.ts
867
+ var import_viem = require("viem");
868
+ var import_chains = require("viem/chains");
869
+ var import_accounts = require("viem/accounts");
870
+ var xLayer = (0, import_viem.defineChain)({
871
+ id: 196,
872
+ name: "X Layer",
873
+ nativeCurrency: { name: "OKB", symbol: "OKB", decimals: 18 },
874
+ rpcUrls: {
875
+ default: { http: ["https://rpc.xlayer.tech"] }
876
+ },
877
+ blockExplorers: {
878
+ default: { name: "OKLink", url: "https://www.oklink.com/xlayer" }
879
+ }
880
+ });
881
+ var xLayerTestnet = (0, import_viem.defineChain)({
882
+ id: 1952,
883
+ name: "X Layer Testnet",
884
+ nativeCurrency: { name: "OKB", symbol: "OKB", decimals: 18 },
885
+ rpcUrls: {
886
+ default: { http: ["https://testrpc.xlayer.tech/terigon"] }
887
+ },
888
+ blockExplorers: {
889
+ default: { name: "OKLink", url: "https://www.oklink.com/xlayer-test" }
890
+ },
891
+ testnet: true
892
+ });
893
+ function isSignerWallet(wallet) {
894
+ return typeof wallet === "object" && wallet !== null && "chain" in wallet && "transport" in wallet;
895
+ }
896
+ function isAccount(wallet) {
897
+ const w = wallet;
898
+ return typeof wallet === "object" && wallet !== null && typeof w.address === "string" && typeof w.type === "string" && // Check for essential signing capabilities
899
+ typeof w.sign === "function" && typeof w.signMessage === "function" && typeof w.signTypedData === "function" && // Check for transaction signing (required by LocalAccount)
900
+ typeof w.signTransaction === "function";
901
+ }
902
+
903
+ // src/schemes/exact/evm/sign.ts
904
+ var import_viem2 = require("viem");
905
+
906
+ // src/shared/base64.ts
907
+ var Base64EncodedRegex = /^[A-Za-z0-9+/]*={0,2}$/;
908
+ function safeBase64Encode(data) {
909
+ if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") {
910
+ return globalThis.btoa(data);
911
+ }
912
+ return Buffer.from(data).toString("base64");
913
+ }
914
+
915
+ // src/types/shared/money.ts
916
+ var import_zod = require("zod");
917
+ var moneySchema = import_zod.z.union([import_zod.z.string().transform((x) => x.replace(/[^0-9.-]+/g, "")), import_zod.z.number()]).pipe(import_zod.z.coerce.number().min(1e-4).max(999999999));
918
+
919
+ // src/types/shared/network.ts
920
+ var import_zod2 = require("zod");
921
+ var NetworkSchema = import_zod2.z.enum([
922
+ "base-sepolia",
923
+ "base",
924
+ "avalanche-fuji",
925
+ "avalanche",
926
+ "iotex",
927
+ "solana-devnet",
928
+ "solana",
929
+ "sei",
930
+ "sei-testnet",
931
+ "polygon",
932
+ "polygon-amoy",
933
+ "peaq",
934
+ "x-layer",
935
+ "x-layer-testnet",
936
+ "sepolia",
937
+ "filecoin-calibration"
938
+ ]);
939
+ var SupportedEVMNetworks = [
940
+ "base-sepolia",
941
+ "base",
942
+ "avalanche-fuji",
943
+ "avalanche",
944
+ "iotex",
945
+ "sei",
946
+ "sei-testnet",
947
+ "polygon",
948
+ "polygon-amoy",
949
+ "peaq",
950
+ "x-layer",
951
+ "x-layer-testnet",
952
+ "sepolia",
953
+ "filecoin-calibration"
954
+ ];
955
+ var EvmNetworkToChainId = /* @__PURE__ */ new Map([
956
+ ["base-sepolia", 84532],
957
+ ["base", 8453],
958
+ ["avalanche-fuji", 43113],
959
+ ["avalanche", 43114],
960
+ ["iotex", 4689],
961
+ ["sei", 1329],
962
+ ["sei-testnet", 1328],
963
+ ["polygon", 137],
964
+ ["polygon-amoy", 80002],
965
+ ["peaq", 3338],
966
+ ["x-layer", 196],
967
+ ["x-layer-testnet", 1952],
968
+ ["sepolia", 11155111],
969
+ ["filecoin-calibration", 314159]
970
+ ]);
971
+ var SupportedSVMNetworks = ["solana-devnet", "solana"];
972
+ var SvmNetworkToChainId = /* @__PURE__ */ new Map([
973
+ ["solana-devnet", 103],
974
+ ["solana", 101]
975
+ ]);
976
+ var ChainIdToNetwork = Object.fromEntries(
977
+ [...SupportedEVMNetworks, ...SupportedSVMNetworks].map((network) => [
978
+ EvmNetworkToChainId.get(network),
979
+ network
980
+ ])
981
+ );
982
+
983
+ // src/shared/svm/wallet.ts
984
+ var import_kit2 = require("@solana/kit");
985
+ var import_base = require("@scure/base");
986
+
987
+ // src/shared/svm/rpc.ts
988
+ var import_kit = require("@solana/kit");
989
+ var DEVNET_RPC_URL = "https://api.devnet.solana.com";
990
+ var MAINNET_RPC_URL = "https://api.mainnet-beta.solana.com";
991
+ var DEVNET_WS_URL = "wss://api.devnet.solana.com";
992
+ var MAINNET_WS_URL = "wss://api.mainnet-beta.solana.com";
993
+ function createDevnetRpcClient(url) {
994
+ return (0, import_kit.createSolanaRpc)(
995
+ url ? (0, import_kit.devnet)(url) : (0, import_kit.devnet)(DEVNET_RPC_URL)
996
+ );
997
+ }
998
+ function createMainnetRpcClient(url) {
999
+ return (0, import_kit.createSolanaRpc)(
1000
+ url ? (0, import_kit.mainnet)(url) : (0, import_kit.mainnet)(MAINNET_RPC_URL)
1001
+ );
1002
+ }
1003
+ function getRpcClient(network, url) {
1004
+ if (network === "solana-devnet") {
1005
+ return createDevnetRpcClient(url);
1006
+ } else if (network === "solana") {
1007
+ return createMainnetRpcClient(url);
1008
+ } else {
1009
+ throw new Error("Invalid network");
1010
+ }
1011
+ }
1012
+ function getRpcSubscriptions(network, url) {
1013
+ if (network === "solana-devnet") {
1014
+ return (0, import_kit.createSolanaRpcSubscriptions)((0, import_kit.devnet)(url ? httpToWs(url) : DEVNET_WS_URL));
1015
+ } else if (network === "solana") {
1016
+ return (0, import_kit.createSolanaRpcSubscriptions)((0, import_kit.mainnet)(url ? httpToWs(url) : MAINNET_WS_URL));
1017
+ } else {
1018
+ throw new Error("Invalid network");
1019
+ }
1020
+ }
1021
+ function httpToWs(url) {
1022
+ if (url.startsWith("http")) {
1023
+ return url.replace("http", "ws");
1024
+ }
1025
+ return url;
1026
+ }
1027
+
1028
+ // src/shared/svm/wallet.ts
1029
+ function isSignerWallet2(wallet) {
1030
+ return (0, import_kit2.isKeyPairSigner)(wallet);
1031
+ }
1032
+
1033
+ // src/types/shared/wallet.ts
1034
+ function isEvmSignerWallet(wallet) {
1035
+ return isSignerWallet(wallet) || isAccount(wallet);
1036
+ }
1037
+ function isSvmSignerWallet(wallet) {
1038
+ return isSignerWallet2(wallet);
1039
+ }
1040
+ function isMultiNetworkSigner(wallet) {
1041
+ return "evm" in wallet && "svm" in wallet;
1042
+ }
1043
+
1044
+ // src/types/shared/svm/regex.ts
1045
+ var SvmAddressRegex = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
1046
+
1047
+ // src/shared/network.ts
1048
+ function getNetworkId(network) {
1049
+ if (EvmNetworkToChainId.has(network)) {
1050
+ return EvmNetworkToChainId.get(network);
1051
+ }
1052
+ if (SvmNetworkToChainId.has(network)) {
1053
+ return SvmNetworkToChainId.get(network);
1054
+ }
1055
+ throw new Error(`Unsupported network: ${network}`);
1056
+ }
1057
+
1058
+ // src/types/verify/x402Specs.ts
1059
+ var import_zod3 = require("zod");
1060
+ var EvmMaxAtomicUnits = 18;
1061
+ var EvmAddressRegex = /^0x[0-9a-fA-F]{40}$/;
1062
+ var MixedAddressRegex = /^0x[a-fA-F0-9]{40}|[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$/;
1063
+ var HexEncoded64ByteRegex = /^0x[0-9a-fA-F]{64}$/;
1064
+ var EvmSignatureRegex = /^0x[0-9a-fA-F]+$/;
1065
+ var schemes = ["exact"];
1066
+ var x402Versions = [1];
1067
+ var ErrorReasons = [
1068
+ "insufficient_funds",
1069
+ "invalid_exact_evm_payload_authorization_valid_after",
1070
+ "invalid_exact_evm_payload_authorization_valid_before",
1071
+ "invalid_exact_evm_payload_authorization_value",
1072
+ "invalid_exact_evm_payload_signature",
1073
+ "invalid_exact_evm_payload_recipient_mismatch",
1074
+ "invalid_exact_svm_payload_transaction",
1075
+ "invalid_exact_svm_payload_transaction_amount_mismatch",
1076
+ "invalid_exact_svm_payload_transaction_create_ata_instruction",
1077
+ "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee",
1078
+ "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset",
1079
+ "invalid_exact_svm_payload_transaction_instructions",
1080
+ "invalid_exact_svm_payload_transaction_instructions_length",
1081
+ "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction",
1082
+ "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction",
1083
+ "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high",
1084
+ "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked",
1085
+ "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked",
1086
+ "invalid_exact_svm_payload_transaction_not_a_transfer_instruction",
1087
+ "invalid_exact_svm_payload_transaction_receiver_ata_not_found",
1088
+ "invalid_exact_svm_payload_transaction_sender_ata_not_found",
1089
+ "invalid_exact_svm_payload_transaction_simulation_failed",
1090
+ "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata",
1091
+ "invalid_network",
1092
+ "invalid_payload",
1093
+ "invalid_payment_requirements",
1094
+ "invalid_scheme",
1095
+ "invalid_payment",
1096
+ "payment_expired",
1097
+ "unsupported_scheme",
1098
+ "invalid_x402_version",
1099
+ "invalid_transaction_state",
1100
+ "invalid_x402_version",
1101
+ "settle_exact_svm_block_height_exceeded",
1102
+ "settle_exact_svm_transaction_confirmation_timed_out",
1103
+ "unsupported_scheme",
1104
+ "unexpected_settle_error",
1105
+ "unexpected_verify_error"
1106
+ ];
1107
+ var isInteger = (value) => Number.isInteger(Number(value)) && Number(value) >= 0;
1108
+ var hasMaxLength = (maxLength) => (value) => value.length <= maxLength;
1109
+ var EvmOrSvmAddress = import_zod3.z.string().regex(EvmAddressRegex).or(import_zod3.z.string().regex(SvmAddressRegex));
1110
+ var mixedAddressOrSvmAddress = import_zod3.z.string().regex(MixedAddressRegex).or(import_zod3.z.string().regex(SvmAddressRegex));
1111
+ var PaymentRequirementsSchema = import_zod3.z.object({
1112
+ scheme: import_zod3.z.enum(schemes),
1113
+ network: NetworkSchema,
1114
+ maxAmountRequired: import_zod3.z.string().refine(isInteger),
1115
+ resource: import_zod3.z.string().url(),
1116
+ description: import_zod3.z.string(),
1117
+ mimeType: import_zod3.z.string(),
1118
+ outputSchema: import_zod3.z.record(import_zod3.z.any()).optional(),
1119
+ payTo: EvmOrSvmAddress,
1120
+ maxTimeoutSeconds: import_zod3.z.number().int(),
1121
+ asset: mixedAddressOrSvmAddress,
1122
+ extra: import_zod3.z.record(import_zod3.z.any()).optional()
1123
+ });
1124
+ var ExactEvmPayloadAuthorizationSchema = import_zod3.z.object({
1125
+ from: import_zod3.z.string().regex(EvmAddressRegex),
1126
+ to: import_zod3.z.string().regex(EvmAddressRegex),
1127
+ value: import_zod3.z.string().refine(isInteger).refine(hasMaxLength(EvmMaxAtomicUnits)),
1128
+ validAfter: import_zod3.z.string().refine(isInteger),
1129
+ validBefore: import_zod3.z.string().refine(isInteger),
1130
+ nonce: import_zod3.z.string().regex(HexEncoded64ByteRegex)
1131
+ });
1132
+ var ExactEvmPayloadSchema = import_zod3.z.object({
1133
+ signature: import_zod3.z.string().regex(EvmSignatureRegex),
1134
+ authorization: ExactEvmPayloadAuthorizationSchema
1135
+ });
1136
+ var ExactSvmPayloadSchema = import_zod3.z.object({
1137
+ transaction: import_zod3.z.string().regex(Base64EncodedRegex)
1138
+ });
1139
+ var PaymentPayloadSchema = import_zod3.z.object({
1140
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1141
+ scheme: import_zod3.z.enum(schemes),
1142
+ network: NetworkSchema,
1143
+ payload: import_zod3.z.union([ExactEvmPayloadSchema, ExactSvmPayloadSchema]),
1144
+ paymentRequirements: PaymentRequirementsSchema.optional()
1145
+ });
1146
+ var x402ResponseSchema = import_zod3.z.object({
1147
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1148
+ error: import_zod3.z.enum(ErrorReasons).optional(),
1149
+ accepts: import_zod3.z.array(PaymentRequirementsSchema).optional(),
1150
+ payer: import_zod3.z.string().regex(MixedAddressRegex).optional()
1151
+ });
1152
+ var HTTPVerbsSchema = import_zod3.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"]);
1153
+ var HTTPRequestStructureSchema = import_zod3.z.object({
1154
+ type: import_zod3.z.literal("http"),
1155
+ method: HTTPVerbsSchema,
1156
+ queryParams: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.string()).optional(),
1157
+ bodyType: import_zod3.z.enum(["json", "form-data", "multipart-form-data", "text", "binary"]).optional(),
1158
+ bodyFields: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.any()).optional(),
1159
+ headerFields: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.any()).optional()
1160
+ });
1161
+ var RequestStructureSchema = import_zod3.z.discriminatedUnion("type", [
1162
+ HTTPRequestStructureSchema
1163
+ // MCPRequestStructureSchema,
1164
+ // OpenAPIRequestStructureSchema,
1165
+ ]);
1166
+ var DiscoveredResourceSchema = import_zod3.z.object({
1167
+ resource: import_zod3.z.string(),
1168
+ type: import_zod3.z.enum(["http"]),
1169
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1170
+ accepts: import_zod3.z.array(PaymentRequirementsSchema),
1171
+ lastUpdated: import_zod3.z.date(),
1172
+ metadata: import_zod3.z.record(import_zod3.z.any()).optional()
1173
+ });
1174
+ var SettleRequestSchema = import_zod3.z.object({
1175
+ paymentPayload: PaymentPayloadSchema,
1176
+ paymentRequirements: PaymentRequirementsSchema
1177
+ });
1178
+ var VerifyRequestSchema = import_zod3.z.object({
1179
+ paymentPayload: PaymentPayloadSchema,
1180
+ paymentRequirements: PaymentRequirementsSchema
1181
+ });
1182
+ var VerifyResponseSchema = import_zod3.z.object({
1183
+ isValid: import_zod3.z.boolean(),
1184
+ invalidReason: import_zod3.z.enum(ErrorReasons).optional(),
1185
+ payer: EvmOrSvmAddress.optional()
1186
+ });
1187
+ var SettleResponseSchema = import_zod3.z.object({
1188
+ success: import_zod3.z.boolean(),
1189
+ errorReason: import_zod3.z.enum(ErrorReasons).optional(),
1190
+ payer: EvmOrSvmAddress.optional(),
1191
+ transaction: import_zod3.z.string().regex(MixedAddressRegex),
1192
+ network: NetworkSchema
1193
+ });
1194
+ var ListDiscoveryResourcesRequestSchema = import_zod3.z.object({
1195
+ type: import_zod3.z.string().optional(),
1196
+ limit: import_zod3.z.number().optional(),
1197
+ offset: import_zod3.z.number().optional()
1198
+ });
1199
+ var ListDiscoveryResourcesResponseSchema = import_zod3.z.object({
1200
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1201
+ items: import_zod3.z.array(DiscoveredResourceSchema),
1202
+ pagination: import_zod3.z.object({
1203
+ limit: import_zod3.z.number(),
1204
+ offset: import_zod3.z.number(),
1205
+ total: import_zod3.z.number()
1206
+ })
1207
+ });
1208
+ var SupportedPaymentKindSchema = import_zod3.z.object({
1209
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1210
+ scheme: import_zod3.z.enum(schemes),
1211
+ network: NetworkSchema,
1212
+ extra: import_zod3.z.record(import_zod3.z.any()).optional()
1213
+ });
1214
+ var SupportedPaymentKindsResponseSchema = import_zod3.z.object({
1215
+ kinds: import_zod3.z.array(SupportedPaymentKindSchema)
1216
+ });
1217
+
1218
+ // src/types/verify/facilitator.ts
1219
+ var import_zod4 = require("zod");
1220
+ var facilitatorRequestSchema = import_zod4.z.object({
1221
+ paymentHeader: import_zod4.z.string(),
1222
+ paymentRequirements: PaymentRequirementsSchema
1223
+ });
1224
+
1225
+ // src/shared/evm/usdc.ts
1226
+ function getUsdcAddress(client) {
1227
+ return config[client.chain.id.toString()].usdcAddress;
1228
+ }
1229
+ function getUsdcChainConfigForChain(chainId) {
1230
+ return config[chainId.toString()];
1231
+ }
1232
+ var versionCache = null;
1233
+ async function getVersion(client) {
1234
+ if (versionCache !== null) {
1235
+ return versionCache;
1236
+ }
1237
+ const version = await client.readContract({
1238
+ address: getUsdcAddress(client),
1239
+ abi: usdcABI,
1240
+ functionName: "version"
1241
+ });
1242
+ versionCache = version;
1243
+ return versionCache;
1244
+ }
1245
+
1246
+ // src/shared/evm/erc20.ts
1247
+ async function getERC20Balance(client, erc20Address, address) {
1248
+ const balance = await client.readContract({
1249
+ address: erc20Address,
1250
+ abi: usdcABI,
1251
+ functionName: "balanceOf",
1252
+ args: [address]
1253
+ });
1254
+ return balance;
1255
+ }
1256
+
1257
+ // src/shared/svm/transaction.ts
1258
+ var import_kit3 = require("@solana/kit");
1259
+ var import_token = require("@solana-program/token");
1260
+ var import_token_2022 = require("@solana-program/token-2022");
1261
+ function decodeTransactionFromPayload(svmPayload) {
1262
+ try {
1263
+ const base64Encoder = (0, import_kit3.getBase64Encoder)();
1264
+ const transactionBytes = base64Encoder.encode(svmPayload.transaction);
1265
+ const transactionDecoder = (0, import_kit3.getTransactionDecoder)();
1266
+ return transactionDecoder.decode(transactionBytes);
1267
+ } catch (error) {
1268
+ console.error("error", error);
1269
+ throw new Error("invalid_exact_svm_payload_transaction");
1270
+ }
1271
+ }
1272
+ function getTokenPayerFromTransaction(transaction) {
1273
+ const compiled = (0, import_kit3.getCompiledTransactionMessageDecoder)().decode(
1274
+ transaction.messageBytes
1275
+ );
1276
+ const staticAccounts = compiled.staticAccounts ?? [];
1277
+ const instructions = compiled.instructions ?? [];
1278
+ for (const ix of instructions) {
1279
+ const programIndex = ix.programAddressIndex;
1280
+ const programAddress = staticAccounts[programIndex].toString();
1281
+ if (programAddress === import_token.TOKEN_PROGRAM_ADDRESS.toString() || programAddress === import_token_2022.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
1282
+ const accountIndices = ix.accountIndices ?? [];
1283
+ if (accountIndices.length >= 4) {
1284
+ const ownerIndex = accountIndices[3];
1285
+ const ownerAddress = staticAccounts[ownerIndex].toString();
1286
+ if (ownerAddress) return ownerAddress;
1287
+ }
1288
+ }
1289
+ }
1290
+ return "";
1291
+ }
1292
+ async function signAndSimulateTransaction(signer, transaction, rpc) {
1293
+ const signedTransaction = await (0, import_kit3.partiallySignTransaction)([signer.keyPair], transaction);
1294
+ const base64EncodedTransaction = (0, import_kit3.getBase64EncodedWireTransaction)(signedTransaction);
1295
+ const simulateTxConfig = {
1296
+ sigVerify: true,
1297
+ replaceRecentBlockhash: false,
1298
+ commitment: "confirmed",
1299
+ encoding: "base64",
1300
+ accounts: void 0,
1301
+ innerInstructions: void 0,
1302
+ minContextSlot: void 0
1303
+ };
1304
+ const simulateResult = await rpc.simulateTransaction(base64EncodedTransaction, simulateTxConfig).send();
1305
+ return simulateResult;
1306
+ }
1307
+
1308
+ // src/schemes/exact/evm/sign.ts
1309
+ async function signAuthorization(walletClient, { from, to, value, validAfter, validBefore, nonce }, { asset, network, extra }) {
1310
+ const chainId = getNetworkId(network);
1311
+ const name = extra?.name;
1312
+ const version = extra?.version;
1313
+ const data = {
1314
+ types: authorizationTypes,
1315
+ domain: {
1316
+ name,
1317
+ version,
1318
+ chainId,
1319
+ verifyingContract: (0, import_viem2.getAddress)(asset)
1320
+ },
1321
+ primaryType: "TransferWithAuthorization",
1322
+ message: {
1323
+ from: (0, import_viem2.getAddress)(from),
1324
+ to: (0, import_viem2.getAddress)(to),
1325
+ value,
1326
+ validAfter,
1327
+ validBefore,
1328
+ nonce
1329
+ }
1330
+ };
1331
+ if (isSignerWallet(walletClient)) {
1332
+ const signature = await walletClient.signTypedData(data);
1333
+ return {
1334
+ signature
1335
+ };
1336
+ } else if (isAccount(walletClient) && walletClient.signTypedData) {
1337
+ const signature = await walletClient.signTypedData(data);
1338
+ return {
1339
+ signature
1340
+ };
1341
+ } else {
1342
+ throw new Error("Invalid wallet client provided does not support signTypedData");
1343
+ }
1344
+ }
1345
+ function createNonce() {
1346
+ const cryptoObj = typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.getRandomValues === "function" ? globalThis.crypto : (
1347
+ // Dynamic require is needed to support node.js
1348
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
1349
+ require("crypto").webcrypto
1350
+ );
1351
+ return (0, import_viem2.toHex)(cryptoObj.getRandomValues(new Uint8Array(32)));
1352
+ }
1353
+
1354
+ // src/schemes/exact/evm/utils/paymentUtils.ts
1355
+ function encodePayment(payment) {
1356
+ let safe;
1357
+ if (SupportedEVMNetworks.includes(payment.network)) {
1358
+ const evmPayload = payment.payload;
1359
+ safe = {
1360
+ ...payment,
1361
+ payload: {
1362
+ ...evmPayload,
1363
+ authorization: Object.fromEntries(
1364
+ Object.entries(evmPayload.authorization).map(([key, value]) => [
1365
+ key,
1366
+ typeof value === "bigint" ? value.toString() : value
1367
+ ])
1368
+ )
1369
+ }
1370
+ };
1371
+ return safeBase64Encode(JSON.stringify(safe));
1372
+ }
1373
+ if (SupportedSVMNetworks.includes(payment.network)) {
1374
+ safe = { ...payment, payload: payment.payload };
1375
+ return safeBase64Encode(JSON.stringify(safe));
1376
+ }
1377
+ throw new Error("Invalid network");
1378
+ }
1379
+
1380
+ // src/schemes/exact/evm/client.ts
1381
+ function preparePaymentHeader(from, x402Version2, paymentRequirements) {
1382
+ const nonce = createNonce();
1383
+ const validAfter = BigInt(
1384
+ Math.floor(Date.now() / 1e3) - 600
1385
+ // 10 minutes before
1386
+ ).toString();
1387
+ const validBefore = BigInt(
1388
+ Math.floor(Date.now() / 1e3 + paymentRequirements.maxTimeoutSeconds)
1389
+ ).toString();
1390
+ return {
1391
+ x402Version: x402Version2,
1392
+ scheme: paymentRequirements.scheme,
1393
+ network: paymentRequirements.network,
1394
+ payload: {
1395
+ signature: void 0,
1396
+ authorization: {
1397
+ from,
1398
+ to: paymentRequirements.payTo,
1399
+ value: paymentRequirements.maxAmountRequired,
1400
+ validAfter: validAfter.toString(),
1401
+ validBefore: validBefore.toString(),
1402
+ nonce
1403
+ }
1404
+ }
1405
+ };
1406
+ }
1407
+ async function signPaymentHeader(client, paymentRequirements, unsignedPaymentHeader) {
1408
+ const { signature } = await signAuthorization(
1409
+ client,
1410
+ unsignedPaymentHeader.payload.authorization,
1411
+ paymentRequirements
1412
+ );
1413
+ return {
1414
+ ...unsignedPaymentHeader,
1415
+ payload: {
1416
+ ...unsignedPaymentHeader.payload,
1417
+ signature
1418
+ }
1419
+ };
1420
+ }
1421
+ async function createPayment(client, x402Version2, paymentRequirements) {
1422
+ const from = isSignerWallet(client) ? client.account.address : client.address;
1423
+ const unsignedPaymentHeader = preparePaymentHeader(from, x402Version2, paymentRequirements);
1424
+ return signPaymentHeader(client, paymentRequirements, unsignedPaymentHeader);
1425
+ }
1426
+ async function createPaymentHeader(client, x402Version2, paymentRequirements) {
1427
+ const payment = await createPayment(client, x402Version2, paymentRequirements);
1428
+ return encodePayment(payment);
1429
+ }
1430
+
1431
+ // src/schemes/exact/svm/client.ts
1432
+ var import_kit4 = require("@solana/kit");
1433
+ var import_token_20222 = require("@solana-program/token-2022");
1434
+ var import_token2 = require("@solana-program/token");
1435
+ var import_compute_budget = require("@solana-program/compute-budget");
1436
+ async function createPaymentHeader2(client, x402Version2, paymentRequirements, config2) {
1437
+ const paymentPayload = await createAndSignPayment(
1438
+ client,
1439
+ x402Version2,
1440
+ paymentRequirements,
1441
+ config2
1442
+ );
1443
+ return encodePayment(paymentPayload);
1444
+ }
1445
+ async function createAndSignPayment(client, x402Version2, paymentRequirements, config2) {
1446
+ const transactionMessage = await createTransferTransactionMessage(
1447
+ client,
1448
+ paymentRequirements,
1449
+ config2
1450
+ );
1451
+ const signedTransaction = await (0, import_kit4.partiallySignTransactionMessageWithSigners)(transactionMessage);
1452
+ const base64EncodedWireTransaction = (0, import_kit4.getBase64EncodedWireTransaction)(signedTransaction);
1453
+ return {
1454
+ scheme: paymentRequirements.scheme,
1455
+ network: paymentRequirements.network,
1456
+ x402Version: x402Version2,
1457
+ payload: {
1458
+ transaction: base64EncodedWireTransaction
1459
+ }
1460
+ };
1461
+ }
1462
+ async function createTransferTransactionMessage(client, paymentRequirements, config2) {
1463
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1464
+ const transferInstructions = await createAtaAndTransferInstructions(
1465
+ client,
1466
+ paymentRequirements,
1467
+ config2
1468
+ );
1469
+ const feePayer = paymentRequirements.extra?.feePayer;
1470
+ const txToSimulate = (0, import_kit4.pipe)(
1471
+ (0, import_kit4.createTransactionMessage)({ version: 0 }),
1472
+ (tx2) => (0, import_compute_budget.setTransactionMessageComputeUnitPrice)(1, tx2),
1473
+ // 1 microlamport priority fee
1474
+ (tx2) => (0, import_kit4.setTransactionMessageFeePayer)(feePayer, tx2),
1475
+ (tx2) => (0, import_kit4.appendTransactionMessageInstructions)(transferInstructions, tx2)
1476
+ );
1477
+ const estimateComputeUnitLimit = (0, import_compute_budget.estimateComputeUnitLimitFactory)({ rpc });
1478
+ const estimatedUnits = await estimateComputeUnitLimit(txToSimulate);
1479
+ const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
1480
+ const tx = (0, import_kit4.pipe)(
1481
+ txToSimulate,
1482
+ (tx2) => (0, import_kit4.prependTransactionMessageInstruction)(
1483
+ (0, import_compute_budget.getSetComputeUnitLimitInstruction)({ units: estimatedUnits }),
1484
+ tx2
1485
+ ),
1486
+ (tx2) => (0, import_kit4.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx2)
1487
+ );
1488
+ return tx;
1489
+ }
1490
+ async function createAtaAndTransferInstructions(client, paymentRequirements, config2) {
1491
+ const { asset } = paymentRequirements;
1492
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1493
+ const tokenMint = await (0, import_token_20222.fetchMint)(rpc, asset);
1494
+ const tokenProgramAddress = tokenMint.programAddress;
1495
+ if (tokenProgramAddress.toString() !== import_token2.TOKEN_PROGRAM_ADDRESS.toString() && tokenProgramAddress.toString() !== import_token_20222.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
1496
+ throw new Error("Asset was not created by a known token program");
1497
+ }
1498
+ const instructions = [];
1499
+ const createAtaIx = await createAtaInstructionOrUndefined(
1500
+ paymentRequirements,
1501
+ tokenProgramAddress,
1502
+ config2
1503
+ );
1504
+ if (createAtaIx) {
1505
+ instructions.push(createAtaIx);
1506
+ }
1507
+ const transferIx = await createTransferInstruction(
1508
+ client,
1509
+ paymentRequirements,
1510
+ tokenMint.data.decimals,
1511
+ tokenProgramAddress
1512
+ );
1513
+ instructions.push(transferIx);
1514
+ return instructions;
1515
+ }
1516
+ async function createAtaInstructionOrUndefined(paymentRequirements, tokenProgramAddress, config2) {
1517
+ const { asset, payTo, extra } = paymentRequirements;
1518
+ const feePayer = extra?.feePayer;
1519
+ if (!feePayer) {
1520
+ throw new Error(
1521
+ "feePayer is required in paymentRequirements.extra in order to set the facilitator as the fee payer for the create associated token account instruction"
1522
+ );
1523
+ }
1524
+ const [destinationATAAddress] = await (0, import_token_20222.findAssociatedTokenPda)({
1525
+ mint: asset,
1526
+ owner: payTo,
1527
+ tokenProgram: tokenProgramAddress
1528
+ });
1529
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1530
+ const maybeAccount = await (0, import_kit4.fetchEncodedAccount)(rpc, destinationATAAddress);
1531
+ if (!maybeAccount.exists) {
1532
+ return (0, import_token_20222.getCreateAssociatedTokenInstruction)({
1533
+ payer: paymentRequirements.extra?.feePayer,
1534
+ ata: destinationATAAddress,
1535
+ owner: payTo,
1536
+ mint: asset,
1537
+ tokenProgram: tokenProgramAddress
1538
+ });
1539
+ }
1540
+ return void 0;
1541
+ }
1542
+ async function createTransferInstruction(client, paymentRequirements, decimals, tokenProgramAddress) {
1543
+ const { asset, maxAmountRequired: amount, payTo } = paymentRequirements;
1544
+ const [sourceATA] = await (0, import_token_20222.findAssociatedTokenPda)({
1545
+ mint: asset,
1546
+ owner: client.address,
1547
+ tokenProgram: tokenProgramAddress
1548
+ });
1549
+ const [destinationATA] = await (0, import_token_20222.findAssociatedTokenPda)({
1550
+ mint: asset,
1551
+ owner: payTo,
1552
+ tokenProgram: tokenProgramAddress
1553
+ });
1554
+ return (0, import_token_20222.getTransferCheckedInstruction)(
1555
+ {
1556
+ source: sourceATA,
1557
+ mint: asset,
1558
+ destination: destinationATA,
1559
+ authority: client,
1560
+ amount: BigInt(amount),
1561
+ decimals
1562
+ },
1563
+ { programAddress: tokenProgramAddress }
1564
+ );
1565
+ }
1566
+
1567
+ // src/client/createPaymentHeader.ts
1568
+ async function createPaymentHeader3(client, x402Version2, paymentRequirements, config2) {
1569
+ if (paymentRequirements.scheme === "exact") {
1570
+ if (SupportedEVMNetworks.includes(paymentRequirements.network)) {
1571
+ const evmClient = isMultiNetworkSigner(client) ? client.evm : client;
1572
+ if (!isEvmSignerWallet(evmClient)) {
1573
+ throw new Error("Invalid evm wallet client provided");
1574
+ }
1575
+ return await createPaymentHeader(
1576
+ evmClient,
1577
+ x402Version2,
1578
+ paymentRequirements
1579
+ );
1580
+ }
1581
+ if (SupportedSVMNetworks.includes(paymentRequirements.network)) {
1582
+ const svmClient = isMultiNetworkSigner(client) ? client.svm : client;
1583
+ if (!isSvmSignerWallet(svmClient)) {
1584
+ throw new Error("Invalid svm wallet client provided");
1585
+ }
1586
+ return await createPaymentHeader2(
1587
+ svmClient,
1588
+ x402Version2,
1589
+ paymentRequirements,
1590
+ config2
1591
+ );
1592
+ }
1593
+ throw new Error("Unsupported network");
1594
+ }
1595
+ throw new Error("Unsupported scheme");
1596
+ }
1597
+
1598
+ // src/client/preparePaymentHeader.ts
1599
+ function preparePaymentHeader2(from, x402Version2, paymentRequirements) {
1600
+ if (paymentRequirements.scheme === "exact" && SupportedEVMNetworks.includes(paymentRequirements.network)) {
1601
+ return preparePaymentHeader(from, x402Version2, paymentRequirements);
1602
+ }
1603
+ throw new Error("Unsupported scheme");
1604
+ }
1605
+
1606
+ // src/client/selectPaymentRequirements.ts
1607
+ function selectPaymentRequirements(paymentRequirements, network, scheme) {
1608
+ paymentRequirements.sort((a, b) => {
1609
+ if (a.network === "base" && b.network !== "base") {
1610
+ return -1;
1611
+ }
1612
+ if (a.network !== "base" && b.network === "base") {
1613
+ return 1;
1614
+ }
1615
+ return 0;
1616
+ });
1617
+ const broadlyAcceptedPaymentRequirements = paymentRequirements.filter((requirement) => {
1618
+ const isExpectedScheme = !scheme || requirement.scheme === scheme;
1619
+ const isExpectedChain = !network || (Array.isArray(network) ? network.includes(requirement.network) : network == requirement.network);
1620
+ return isExpectedScheme && isExpectedChain;
1621
+ });
1622
+ const usdcRequirements = broadlyAcceptedPaymentRequirements.filter((requirement) => {
1623
+ return requirement.asset === getUsdcChainConfigForChain(getNetworkId(requirement.network))?.usdcAddress;
1624
+ });
1625
+ if (usdcRequirements.length > 0) {
1626
+ return usdcRequirements[0];
1627
+ }
1628
+ if (broadlyAcceptedPaymentRequirements.length > 0) {
1629
+ return broadlyAcceptedPaymentRequirements[0];
1630
+ }
1631
+ return paymentRequirements[0];
1632
+ }
1633
+
1634
+ // src/client/signPaymentHeader.ts
1635
+ async function signPaymentHeader2(client, paymentRequirements, unsignedPaymentHeader) {
1636
+ if (paymentRequirements.scheme === "exact" && SupportedEVMNetworks.includes(paymentRequirements.network)) {
1637
+ const evmClient = isMultiNetworkSigner(client) ? client.evm : client;
1638
+ if (!isEvmSignerWallet(evmClient)) {
1639
+ throw new Error("Invalid evm wallet client provided");
1640
+ }
1641
+ const signedPaymentHeader = await signPaymentHeader(evmClient, paymentRequirements, unsignedPaymentHeader);
1642
+ return encodePayment(signedPaymentHeader);
1643
+ }
1644
+ throw new Error("Unsupported scheme");
1645
+ }
1646
+
1647
+ // src/schemes/exact/evm/facilitator.ts
1648
+ var import_viem3 = require("viem");
1649
+
1650
+ // src/schemes/exact/svm/facilitator/settle.ts
1651
+ var import_kit6 = require("@solana/kit");
1652
+ var import_transaction_confirmation = require("@solana/transaction-confirmation");
1653
+
1654
+ // src/schemes/exact/svm/facilitator/verify.ts
1655
+ var import_kit5 = require("@solana/kit");
1656
+ var import_compute_budget2 = require("@solana-program/compute-budget");
1657
+ var import_token_20223 = require("@solana-program/token-2022");
1658
+ var import_token3 = require("@solana-program/token");
1659
+ async function verify(signer, payload, paymentRequirements, config2) {
1660
+ try {
1661
+ verifySchemesAndNetworks(payload, paymentRequirements);
1662
+ const svmPayload = payload.payload;
1663
+ const decodedTransaction = decodeTransactionFromPayload(svmPayload);
1664
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1665
+ await transactionIntrospection(svmPayload, paymentRequirements, config2);
1666
+ const simulateResult = await signAndSimulateTransaction(signer, decodedTransaction, rpc);
1667
+ if (simulateResult.value?.err) {
1668
+ throw new Error(`invalid_exact_svm_payload_transaction_simulation_failed`);
1669
+ }
1670
+ return {
1671
+ isValid: true,
1672
+ invalidReason: void 0,
1673
+ payer: getTokenPayerFromTransaction(decodedTransaction)
1674
+ };
1675
+ } catch (error) {
1676
+ if (error instanceof Error) {
1677
+ if (ErrorReasons.includes(error.message)) {
1678
+ return {
1679
+ isValid: false,
1680
+ invalidReason: error.message,
1681
+ payer: (() => {
1682
+ try {
1683
+ const tx = decodeTransactionFromPayload(payload.payload);
1684
+ return getTokenPayerFromTransaction(tx);
1685
+ } catch {
1686
+ return void 0;
1687
+ }
1688
+ })()
1689
+ };
1690
+ }
1691
+ }
1692
+ console.error(error);
1693
+ return {
1694
+ isValid: false,
1695
+ invalidReason: "unexpected_verify_error",
1696
+ payer: (() => {
1697
+ try {
1698
+ const tx = decodeTransactionFromPayload(payload.payload);
1699
+ return getTokenPayerFromTransaction(tx);
1700
+ } catch {
1701
+ return void 0;
1702
+ }
1703
+ })()
1704
+ };
1705
+ }
1706
+ }
1707
+ function verifySchemesAndNetworks(payload, paymentRequirements) {
1708
+ if (payload.scheme !== SCHEME || paymentRequirements.scheme !== SCHEME) {
1709
+ throw new Error("unsupported_scheme");
1710
+ }
1711
+ if (payload.network !== paymentRequirements.network || !SupportedSVMNetworks.includes(paymentRequirements.network)) {
1712
+ throw new Error("invalid_network");
1713
+ }
1714
+ }
1715
+ async function transactionIntrospection(svmPayload, paymentRequirements, config2) {
1716
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1717
+ const decodedTransaction = decodeTransactionFromPayload(svmPayload);
1718
+ const compiledTransactionMessage = (0, import_kit5.getCompiledTransactionMessageDecoder)().decode(
1719
+ decodedTransaction.messageBytes
1720
+ );
1721
+ const transactionMessage = (0, import_kit5.decompileTransactionMessage)(
1722
+ compiledTransactionMessage
1723
+ );
1724
+ await verifyTransactionInstructions(transactionMessage, paymentRequirements, rpc);
1725
+ }
1726
+ async function verifyTransactionInstructions(transactionMessage, paymentRequirements, rpc) {
1727
+ if (transactionMessage.instructions.length !== 3 && transactionMessage.instructions.length !== 4) {
1728
+ throw new Error(`invalid_exact_svm_payload_transaction_instructions_length`);
1729
+ }
1730
+ verifyComputeLimitInstruction(transactionMessage.instructions[0]);
1731
+ verifyComputePriceInstruction(transactionMessage.instructions[1]);
1732
+ if (transactionMessage.instructions.length === 3) {
1733
+ await verifyTransferInstruction(
1734
+ transactionMessage.instructions[2],
1735
+ paymentRequirements,
1736
+ {
1737
+ txHasCreateDestATAInstruction: false
1738
+ },
1739
+ rpc
1740
+ );
1741
+ } else {
1742
+ verifyCreateATAInstruction(transactionMessage.instructions[2], paymentRequirements);
1743
+ await verifyTransferInstruction(
1744
+ transactionMessage.instructions[3],
1745
+ paymentRequirements,
1746
+ {
1747
+ txHasCreateDestATAInstruction: true
1748
+ },
1749
+ rpc
1750
+ );
1751
+ }
1752
+ }
1753
+ function verifyComputeLimitInstruction(instruction) {
1754
+ try {
1755
+ if (instruction.programAddress.toString() !== import_compute_budget2.COMPUTE_BUDGET_PROGRAM_ADDRESS.toString() || instruction.data?.[0] !== 2) {
1756
+ throw new Error(
1757
+ `invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction`
1758
+ );
1759
+ }
1760
+ (0, import_compute_budget2.parseSetComputeUnitLimitInstruction)(
1761
+ instruction
1762
+ );
1763
+ } catch (error) {
1764
+ console.error(error);
1765
+ throw new Error(`invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction`);
1766
+ }
1767
+ }
1768
+ function verifyComputePriceInstruction(instruction) {
1769
+ if (instruction.programAddress.toString() !== import_compute_budget2.COMPUTE_BUDGET_PROGRAM_ADDRESS.toString() || instruction.data?.[0] !== 3) {
1770
+ throw new Error(`invalid_exact_svm_payload_transaction_instructions_compute_price_instruction`);
1771
+ }
1772
+ const parsedInstruction = (0, import_compute_budget2.parseSetComputeUnitPriceInstruction)(
1773
+ instruction
1774
+ );
1775
+ if (parsedInstruction.data.microLamports > 5 * 1e6) {
1776
+ throw new Error(
1777
+ `invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high`
1778
+ );
1779
+ }
1780
+ }
1781
+ function verifyCreateATAInstruction(instruction, paymentRequirements) {
1782
+ let createATAInstruction;
1783
+ try {
1784
+ (0, import_kit5.assertIsInstructionWithAccounts)(instruction);
1785
+ (0, import_kit5.assertIsInstructionWithData)(instruction);
1786
+ createATAInstruction = (0, import_token_20223.parseCreateAssociatedTokenInstruction)({
1787
+ ...instruction,
1788
+ data: new Uint8Array(instruction.data)
1789
+ });
1790
+ } catch (error) {
1791
+ console.error(error);
1792
+ throw new Error(`invalid_exact_svm_payload_transaction_create_ata_instruction`);
1793
+ }
1794
+ if (createATAInstruction.accounts.owner.address !== paymentRequirements.payTo) {
1795
+ throw new Error(`invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee`);
1796
+ }
1797
+ if (createATAInstruction.accounts.mint.address !== paymentRequirements.asset) {
1798
+ throw new Error(`invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset`);
1799
+ }
1800
+ }
1801
+ async function verifyTransferInstruction(instruction, paymentRequirements, { txHasCreateDestATAInstruction }, rpc) {
1802
+ const tokenInstruction = getValidatedTransferCheckedInstruction(instruction);
1803
+ await verifyTransferCheckedInstruction(
1804
+ tokenInstruction,
1805
+ paymentRequirements,
1806
+ {
1807
+ txHasCreateDestATAInstruction
1808
+ },
1809
+ rpc
1810
+ );
1811
+ }
1812
+ async function verifyTransferCheckedInstruction(parsedInstruction, paymentRequirements, { txHasCreateDestATAInstruction }, rpc) {
1813
+ const tokenProgramAddress = parsedInstruction.programAddress.toString() === import_token3.TOKEN_PROGRAM_ADDRESS.toString() ? import_token3.TOKEN_PROGRAM_ADDRESS : import_token_20223.TOKEN_2022_PROGRAM_ADDRESS;
1814
+ const payToATA = await (0, import_token_20223.findAssociatedTokenPda)({
1815
+ mint: paymentRequirements.asset,
1816
+ owner: paymentRequirements.payTo,
1817
+ tokenProgram: tokenProgramAddress
1818
+ });
1819
+ if (parsedInstruction.accounts.destination.address !== payToATA[0]) {
1820
+ throw new Error(`invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata`);
1821
+ }
1822
+ const addresses = [parsedInstruction.accounts.source.address, payToATA[0]];
1823
+ const maybeAccounts = await (0, import_kit5.fetchEncodedAccounts)(rpc, addresses);
1824
+ const missingAccounts = maybeAccounts.filter((a) => !a.exists);
1825
+ for (const missingAccount of missingAccounts) {
1826
+ if (missingAccount.address === parsedInstruction.accounts.source.address) {
1827
+ throw new Error(`invalid_exact_svm_payload_transaction_sender_ata_not_found`);
1828
+ }
1829
+ if (missingAccount.address === payToATA[0] && !txHasCreateDestATAInstruction) {
1830
+ throw new Error(`invalid_exact_svm_payload_transaction_receiver_ata_not_found`);
1831
+ }
1832
+ }
1833
+ const instructionAmount = parsedInstruction.data.amount;
1834
+ const paymentRequirementsAmount = BigInt(paymentRequirements.maxAmountRequired);
1835
+ if (instructionAmount !== paymentRequirementsAmount) {
1836
+ throw new Error(`invalid_exact_svm_payload_transaction_amount_mismatch`);
1837
+ }
1838
+ }
1839
+ function getValidatedTransferCheckedInstruction(instruction) {
1840
+ try {
1841
+ (0, import_kit5.assertIsInstructionWithData)(instruction);
1842
+ (0, import_kit5.assertIsInstructionWithAccounts)(instruction);
1843
+ } catch (error) {
1844
+ console.error(error);
1845
+ throw new Error(`invalid_exact_svm_payload_transaction_instructions`);
1846
+ }
1847
+ let tokenInstruction;
1848
+ if (instruction.programAddress.toString() === import_token3.TOKEN_PROGRAM_ADDRESS.toString()) {
1849
+ const identifiedInstruction = (0, import_token3.identifyTokenInstruction)(instruction);
1850
+ if (identifiedInstruction !== import_token3.TokenInstruction.TransferChecked) {
1851
+ throw new Error(
1852
+ `invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked`
1853
+ );
1854
+ }
1855
+ tokenInstruction = (0, import_token3.parseTransferCheckedInstruction)({
1856
+ ...instruction,
1857
+ data: new Uint8Array(instruction.data)
1858
+ });
1859
+ } else if (instruction.programAddress.toString() === import_token_20223.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
1860
+ const identifiedInstruction = (0, import_token_20223.identifyToken2022Instruction)(instruction);
1861
+ if (identifiedInstruction !== import_token_20223.Token2022Instruction.TransferChecked) {
1862
+ throw new Error(
1863
+ `invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked`
1864
+ );
1865
+ }
1866
+ tokenInstruction = (0, import_token_20223.parseTransferCheckedInstruction)({
1867
+ ...instruction,
1868
+ data: new Uint8Array(instruction.data)
1869
+ });
1870
+ } else {
1871
+ throw new Error(`invalid_exact_svm_payload_transaction_not_a_transfer_instruction`);
1872
+ }
1873
+ return tokenInstruction;
1874
+ }
1875
+
1876
+ // src/schemes/exact/svm/facilitator/settle.ts
1877
+ async function settle(signer, payload, paymentRequirements, config2) {
1878
+ const verifyResponse = await verify(signer, payload, paymentRequirements, config2);
1879
+ if (!verifyResponse.isValid) {
1880
+ return {
1881
+ success: false,
1882
+ errorReason: verifyResponse.invalidReason,
1883
+ network: payload.network,
1884
+ transaction: ""
1885
+ };
1886
+ }
1887
+ const svmPayload = payload.payload;
1888
+ const decodedTransaction = decodeTransactionFromPayload(svmPayload);
1889
+ const signedTransaction = await (0, import_kit6.signTransaction)([signer.keyPair], decodedTransaction);
1890
+ const payer = getTokenPayerFromTransaction(decodedTransaction);
1891
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1892
+ const rpcSubscriptions = getRpcSubscriptions(
1893
+ paymentRequirements.network,
1894
+ config2?.svmConfig?.rpcUrl
1895
+ );
1896
+ try {
1897
+ const { success, errorReason, signature } = await sendAndConfirmSignedTransaction(
1898
+ signedTransaction,
1899
+ rpc,
1900
+ rpcSubscriptions
1901
+ );
1902
+ return {
1903
+ success,
1904
+ errorReason,
1905
+ payer,
1906
+ transaction: signature,
1907
+ network: payload.network
1908
+ };
1909
+ } catch (error) {
1910
+ console.error("Unexpected error during transaction settlement:", error);
1911
+ return {
1912
+ success: false,
1913
+ errorReason: "unexpected_settle_error",
1914
+ network: payload.network,
1915
+ transaction: (0, import_kit6.getSignatureFromTransaction)(signedTransaction),
1916
+ payer
1917
+ };
1918
+ }
1919
+ }
1920
+ async function sendSignedTransaction(signedTransaction, rpc, sendTxConfig = {
1921
+ skipPreflight: true,
1922
+ encoding: "base64"
1923
+ }) {
1924
+ const base64EncodedTransaction = (0, import_kit6.getBase64EncodedWireTransaction)(signedTransaction);
1925
+ return await rpc.sendTransaction(base64EncodedTransaction, sendTxConfig).send();
1926
+ }
1927
+ async function confirmSignedTransaction(signedTransaction, rpc, rpcSubscriptions) {
1928
+ const signature = (0, import_kit6.getSignatureFromTransaction)(signedTransaction);
1929
+ const abortController = new AbortController();
1930
+ const timeout = setTimeout(() => {
1931
+ abortController.abort("Transaction confirmation timed out after 60 seconds");
1932
+ }, 6e4);
1933
+ try {
1934
+ const compiledTransactionMessage = (0, import_kit6.getCompiledTransactionMessageDecoder)().decode(
1935
+ signedTransaction.messageBytes
1936
+ );
1937
+ const decompiledTransactionMessage = await (0, import_kit6.decompileTransactionMessageFetchingLookupTables)(
1938
+ compiledTransactionMessage,
1939
+ rpc
1940
+ );
1941
+ (0, import_kit6.assertIsTransactionMessageWithBlockhashLifetime)(decompiledTransactionMessage);
1942
+ const signedTransactionWithBlockhashLifetime = {
1943
+ ...signedTransaction,
1944
+ lifetimeConstraint: decompiledTransactionMessage.lifetimeConstraint
1945
+ };
1946
+ const commitment = "confirmed";
1947
+ const getRecentSignatureConfirmationPromise = (0, import_transaction_confirmation.createRecentSignatureConfirmationPromiseFactory)({
1948
+ rpc,
1949
+ rpcSubscriptions
1950
+ });
1951
+ const getBlockHeightExceedencePromise = (0, import_transaction_confirmation.createBlockHeightExceedencePromiseFactory)({
1952
+ rpc,
1953
+ rpcSubscriptions
1954
+ });
1955
+ const config2 = {
1956
+ abortSignal: abortController.signal,
1957
+ commitment,
1958
+ getBlockHeightExceedencePromise,
1959
+ getRecentSignatureConfirmationPromise
1960
+ };
1961
+ await (0, import_transaction_confirmation.waitForRecentTransactionConfirmation)({
1962
+ ...config2,
1963
+ transaction: signedTransactionWithBlockhashLifetime
1964
+ });
1965
+ return {
1966
+ success: true,
1967
+ signature
1968
+ };
1969
+ } catch (error) {
1970
+ console.error(error);
1971
+ if ((0, import_kit6.isSolanaError)(error, import_kit6.SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) {
1972
+ return {
1973
+ success: false,
1974
+ errorReason: "settle_exact_svm_block_height_exceeded",
1975
+ signature
1976
+ };
1977
+ } else if (error instanceof DOMException && error.name === "AbortError") {
1978
+ return {
1979
+ success: false,
1980
+ errorReason: "settle_exact_svm_transaction_confirmation_timed_out",
1981
+ signature
1982
+ };
1983
+ } else {
1984
+ throw error;
1985
+ }
1986
+ } finally {
1987
+ clearTimeout(timeout);
1988
+ }
1989
+ }
1990
+ async function sendAndConfirmSignedTransaction(signedTransaction, rpc, rpcSubscriptions) {
1991
+ await sendSignedTransaction(signedTransaction, rpc);
1992
+ return await confirmSignedTransaction(signedTransaction, rpc, rpcSubscriptions);
1993
+ }
1994
+
1995
+ // src/schemes/exact/index.ts
1996
+ var SCHEME = "exact";
1997
+
1998
+ // src/schemes/exact/evm/facilitator.ts
1999
+ async function verify2(client, payload, paymentRequirements) {
2000
+ const exactEvmPayload = payload.payload;
2001
+ if (payload.scheme !== SCHEME || paymentRequirements.scheme !== SCHEME) {
2002
+ return {
2003
+ isValid: false,
2004
+ invalidReason: `unsupported_scheme`,
2005
+ payer: exactEvmPayload.authorization.from
2006
+ };
2007
+ }
2008
+ let name;
2009
+ let chainId;
2010
+ let erc20Address;
2011
+ let version;
2012
+ try {
2013
+ chainId = getNetworkId(payload.network);
2014
+ name = paymentRequirements.extra?.name ?? config[chainId.toString()].usdcName;
2015
+ erc20Address = paymentRequirements.asset;
2016
+ version = paymentRequirements.extra?.version ?? await getVersion(client);
2017
+ } catch {
2018
+ return {
2019
+ isValid: false,
2020
+ invalidReason: `invalid_network`,
2021
+ payer: payload.payload.authorization.from
2022
+ };
2023
+ }
2024
+ const permitTypedData = {
2025
+ types: authorizationTypes,
2026
+ primaryType: "TransferWithAuthorization",
2027
+ domain: {
2028
+ name,
2029
+ version,
2030
+ chainId,
2031
+ verifyingContract: erc20Address
2032
+ },
2033
+ message: {
2034
+ from: exactEvmPayload.authorization.from,
2035
+ to: exactEvmPayload.authorization.to,
2036
+ value: exactEvmPayload.authorization.value,
2037
+ validAfter: exactEvmPayload.authorization.validAfter,
2038
+ validBefore: exactEvmPayload.authorization.validBefore,
2039
+ nonce: exactEvmPayload.authorization.nonce
2040
+ }
2041
+ };
2042
+ const recoveredAddress = await client.verifyTypedData({
2043
+ address: exactEvmPayload.authorization.from,
2044
+ ...permitTypedData,
2045
+ signature: exactEvmPayload.signature
2046
+ });
2047
+ if (!recoveredAddress) {
2048
+ return {
2049
+ isValid: false,
2050
+ invalidReason: "invalid_exact_evm_payload_signature",
2051
+ //"Invalid permit signature",
2052
+ payer: exactEvmPayload.authorization.from
2053
+ };
2054
+ }
2055
+ if ((0, import_viem3.getAddress)(exactEvmPayload.authorization.to) !== (0, import_viem3.getAddress)(paymentRequirements.payTo)) {
2056
+ return {
2057
+ isValid: false,
2058
+ invalidReason: "invalid_exact_evm_payload_recipient_mismatch",
2059
+ payer: exactEvmPayload.authorization.from
2060
+ };
2061
+ }
2062
+ if (BigInt(exactEvmPayload.authorization.validBefore) < BigInt(Math.floor(Date.now() / 1e3) + 6)) {
2063
+ return {
2064
+ isValid: false,
2065
+ invalidReason: "invalid_exact_evm_payload_authorization_valid_before",
2066
+ //"Deadline on permit isn't far enough in the future",
2067
+ payer: exactEvmPayload.authorization.from
2068
+ };
2069
+ }
2070
+ if (BigInt(exactEvmPayload.authorization.validAfter) > BigInt(Math.floor(Date.now() / 1e3))) {
2071
+ return {
2072
+ isValid: false,
2073
+ invalidReason: "invalid_exact_evm_payload_authorization_valid_after",
2074
+ //"Deadline on permit is in the future",
2075
+ payer: exactEvmPayload.authorization.from
2076
+ };
2077
+ }
2078
+ const balance = await getERC20Balance(
2079
+ client,
2080
+ erc20Address,
2081
+ exactEvmPayload.authorization.from
2082
+ );
2083
+ if (balance < BigInt(paymentRequirements.maxAmountRequired)) {
2084
+ return {
2085
+ isValid: false,
2086
+ invalidReason: "insufficient_funds",
2087
+ //"Client does not have enough funds",
2088
+ payer: exactEvmPayload.authorization.from
2089
+ };
2090
+ }
2091
+ if (BigInt(exactEvmPayload.authorization.value) < BigInt(paymentRequirements.maxAmountRequired)) {
2092
+ return {
2093
+ isValid: false,
2094
+ invalidReason: "invalid_exact_evm_payload_authorization_value",
2095
+ //"Value in payload is not enough to cover paymentRequirements.maxAmountRequired",
2096
+ payer: exactEvmPayload.authorization.from
2097
+ };
2098
+ }
2099
+ return {
2100
+ isValid: true,
2101
+ invalidReason: void 0,
2102
+ payer: exactEvmPayload.authorization.from
2103
+ };
2104
+ }
2105
+ async function settle2(wallet, paymentPayload, paymentRequirements) {
2106
+ const payload = paymentPayload.payload;
2107
+ const valid = await verify2(wallet, paymentPayload, paymentRequirements);
2108
+ if (!valid.isValid) {
2109
+ return {
2110
+ success: false,
2111
+ network: paymentPayload.network,
2112
+ transaction: "",
2113
+ errorReason: valid.invalidReason ?? "invalid_scheme",
2114
+ //`Payment is no longer valid: ${valid.invalidReason}`,
2115
+ payer: payload.authorization.from
2116
+ };
2117
+ }
2118
+ const { signature } = (0, import_viem3.parseErc6492Signature)(payload.signature);
2119
+ const tx = await wallet.writeContract({
2120
+ address: paymentRequirements.asset,
2121
+ abi: usdcABI,
2122
+ functionName: "transferWithAuthorization",
2123
+ args: [
2124
+ payload.authorization.from,
2125
+ payload.authorization.to,
2126
+ BigInt(payload.authorization.value),
2127
+ BigInt(payload.authorization.validAfter),
2128
+ BigInt(payload.authorization.validBefore),
2129
+ payload.authorization.nonce,
2130
+ signature
2131
+ ],
2132
+ chain: wallet.chain
2133
+ });
2134
+ const receipt = await wallet.waitForTransactionReceipt({ hash: tx });
2135
+ if (receipt.status !== "success") {
2136
+ return {
2137
+ success: false,
2138
+ errorReason: "invalid_transaction_state",
2139
+ //`Transaction failed`,
2140
+ transaction: tx,
2141
+ network: paymentPayload.network,
2142
+ payer: payload.authorization.from
2143
+ };
2144
+ }
2145
+ return {
2146
+ success: true,
2147
+ transaction: tx,
2148
+ network: paymentPayload.network,
2149
+ payer: payload.authorization.from
2150
+ };
2151
+ }
2152
+
2153
+ // src/facilitator/facilitator.ts
2154
+ async function verify3(client, payload, paymentRequirements, config2) {
2155
+ if (paymentRequirements.scheme === "exact") {
2156
+ if (SupportedEVMNetworks.includes(paymentRequirements.network)) {
2157
+ return verify2(
2158
+ client,
2159
+ payload,
2160
+ paymentRequirements
2161
+ );
2162
+ }
2163
+ if (SupportedSVMNetworks.includes(paymentRequirements.network)) {
2164
+ return await verify(client, payload, paymentRequirements, config2);
2165
+ }
2166
+ }
2167
+ return {
2168
+ isValid: false,
2169
+ invalidReason: "invalid_scheme",
2170
+ payer: SupportedEVMNetworks.includes(paymentRequirements.network) ? payload.payload.authorization.from : ""
2171
+ };
2172
+ }
2173
+ async function settle3(client, payload, paymentRequirements, config2) {
2174
+ if (paymentRequirements.scheme === "exact") {
2175
+ if (SupportedEVMNetworks.includes(paymentRequirements.network)) {
2176
+ return await settle2(
2177
+ client,
2178
+ payload,
2179
+ paymentRequirements
2180
+ );
2181
+ }
2182
+ if (SupportedSVMNetworks.includes(paymentRequirements.network)) {
2183
+ return await settle(client, payload, paymentRequirements, config2);
2184
+ }
2185
+ }
2186
+ return {
2187
+ success: false,
2188
+ errorReason: "invalid_scheme",
2189
+ transaction: "",
2190
+ network: paymentRequirements.network,
2191
+ payer: SupportedEVMNetworks.includes(paymentRequirements.network) ? payload.payload.authorization.from : ""
2192
+ };
2193
+ }
2194
+
2195
+ // src/index.ts
2196
+ var x402Version = 1;
2197
+ // Annotate the CommonJS export names for ESM import in node:
2198
+ 0 && (module.exports = {
2199
+ createPaymentHeader,
2200
+ preparePaymentHeader,
2201
+ selectPaymentRequirements,
2202
+ settle,
2203
+ signPaymentHeader,
2204
+ verify,
2205
+ x402Version
2206
+ });
2207
+ //# sourceMappingURL=index.js.map