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