@wtflabs/x402 0.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) 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 +832 -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 +2574 -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 +2974 -0
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/middleware-6_1ApcJn.d.ts +93 -0
  14. package/dist/cjs/middleware-B_ewwsQp.d.ts +93 -0
  15. package/dist/cjs/middleware-Brgsx32F.d.ts +93 -0
  16. package/dist/cjs/middleware-BwfW7mAs.d.ts +93 -0
  17. package/dist/cjs/middleware-CQb61c1k.d.ts +93 -0
  18. package/dist/cjs/middleware-DB9lqy9f.d.ts +93 -0
  19. package/dist/cjs/middleware-DcHctwQV.d.ts +93 -0
  20. package/dist/cjs/middleware-De0jD3Bp.d.ts +93 -0
  21. package/dist/cjs/middleware-HoFOmpgv.d.ts +93 -0
  22. package/dist/cjs/middleware-Y8AiAfYw.d.ts +93 -0
  23. package/dist/cjs/middleware-pnres9YM.d.ts +93 -0
  24. package/dist/cjs/network-FrFmmiyj.d.ts +11 -0
  25. package/dist/cjs/network-RtNddYQk.d.ts +11 -0
  26. package/dist/cjs/paywall/index.d.ts +30 -0
  27. package/dist/cjs/paywall/index.js +131 -0
  28. package/dist/cjs/paywall/index.js.map +1 -0
  29. package/dist/cjs/rpc-BMvnNNHd.d.ts +35 -0
  30. package/dist/cjs/rpc-Ca8eHCWz.d.ts +35 -0
  31. package/dist/cjs/schemes/index.d.ts +533 -0
  32. package/dist/cjs/schemes/index.js +3144 -0
  33. package/dist/cjs/schemes/index.js.map +1 -0
  34. package/dist/cjs/shared/evm/index.d.ts +71 -0
  35. package/dist/cjs/shared/evm/index.js +947 -0
  36. package/dist/cjs/shared/evm/index.js.map +1 -0
  37. package/dist/cjs/shared/index.d.ts +182 -0
  38. package/dist/cjs/shared/index.js +674 -0
  39. package/dist/cjs/shared/index.js.map +1 -0
  40. package/dist/cjs/types/index.d.ts +1515 -0
  41. package/dist/cjs/types/index.js +1645 -0
  42. package/dist/cjs/types/index.js.map +1 -0
  43. package/dist/cjs/verify/index.d.ts +7 -0
  44. package/dist/cjs/verify/index.js +438 -0
  45. package/dist/cjs/verify/index.js.map +1 -0
  46. package/dist/cjs/wallet-BRWfOM5D.d.ts +153 -0
  47. package/dist/cjs/wallet-BTqCm9Zp.d.ts +27 -0
  48. package/dist/cjs/wallet-BYRAGtOB.d.ts +153 -0
  49. package/dist/cjs/wallet-BmEtlgEf.d.ts +48 -0
  50. package/dist/cjs/wallet-CNOAmyZ6.d.ts +48 -0
  51. package/dist/cjs/wallet-CQ0Fe_M5.d.ts +88 -0
  52. package/dist/cjs/wallet-D1SoxFTw.d.ts +48 -0
  53. package/dist/cjs/wallet-SJ-hbjm9.d.ts +153 -0
  54. package/dist/cjs/wallet-SJKJpUgQ.d.ts +167 -0
  55. package/dist/cjs/wallet-ecnda4Aj.d.ts +48 -0
  56. package/dist/cjs/wallet-gP8Qoi-c.d.ts +74 -0
  57. package/dist/cjs/x402Specs-B7InXo2L.d.ts +1065 -0
  58. package/dist/cjs/x402Specs-BLH3j34O.d.ts +1696 -0
  59. package/dist/cjs/x402Specs-C7LipAZg.d.ts +1715 -0
  60. package/dist/cjs/x402Specs-CYq5tSY1.d.ts +1745 -0
  61. package/dist/cjs/x402Specs-CeajqonG.d.ts +1696 -0
  62. package/dist/cjs/x402Specs-qMujgEV5.d.ts +1715 -0
  63. package/dist/cjs/x402Specs-qUBCpcuz.d.ts +1715 -0
  64. package/dist/esm/chunk-34YNR4LY.mjs +106 -0
  65. package/dist/esm/chunk-34YNR4LY.mjs.map +1 -0
  66. package/dist/esm/chunk-57UEJN5U.mjs +1416 -0
  67. package/dist/esm/chunk-57UEJN5U.mjs.map +1 -0
  68. package/dist/esm/chunk-5LTKIVOA.mjs +858 -0
  69. package/dist/esm/chunk-5LTKIVOA.mjs.map +1 -0
  70. package/dist/esm/chunk-AQQR4PXH.mjs +80 -0
  71. package/dist/esm/chunk-AQQR4PXH.mjs.map +1 -0
  72. package/dist/esm/chunk-LGXWNXCO.mjs +76 -0
  73. package/dist/esm/chunk-LGXWNXCO.mjs.map +1 -0
  74. package/dist/esm/chunk-RX2JKK4O.mjs +349 -0
  75. package/dist/esm/chunk-RX2JKK4O.mjs.map +1 -0
  76. package/dist/esm/chunk-UCBE7FDY.mjs +1041 -0
  77. package/dist/esm/chunk-UCBE7FDY.mjs.map +1 -0
  78. package/dist/esm/client/index.mjs +17 -0
  79. package/dist/esm/client/index.mjs.map +1 -0
  80. package/dist/esm/facilitator/index.mjs +14 -0
  81. package/dist/esm/facilitator/index.mjs.map +1 -0
  82. package/dist/esm/index.mjs +28 -0
  83. package/dist/esm/index.mjs.map +1 -0
  84. package/dist/esm/paywall/index.mjs +46 -0
  85. package/dist/esm/paywall/index.mjs.map +1 -0
  86. package/dist/esm/schemes/index.mjs +16 -0
  87. package/dist/esm/schemes/index.mjs.map +1 -0
  88. package/dist/esm/shared/evm/index.mjs +20 -0
  89. package/dist/esm/shared/evm/index.mjs.map +1 -0
  90. package/dist/esm/shared/index.mjs +31 -0
  91. package/dist/esm/shared/index.mjs.map +1 -0
  92. package/dist/esm/types/index.mjs +87 -0
  93. package/dist/esm/types/index.mjs.map +1 -0
  94. package/dist/esm/verify/index.mjs +105 -0
  95. package/dist/esm/verify/index.mjs.map +1 -0
  96. package/package.json +148 -0
@@ -0,0 +1,2974 @@
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: () => settle6,
27
+ signPaymentHeader: () => signPaymentHeader2,
28
+ verify: () => verify6,
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
+ "56": {
86
+ usdcAddress: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
87
+ usdcName: "USDC"
88
+ },
89
+ "97": {
90
+ usdcAddress: "0x64544969ed7EBf5f083679233325356EbE738930",
91
+ usdcName: "USDC"
92
+ }
93
+ };
94
+
95
+ // src/types/shared/evm/eip3009.ts
96
+ var authorizationTypes = {
97
+ TransferWithAuthorization: [
98
+ { name: "from", type: "address" },
99
+ { name: "to", type: "address" },
100
+ { name: "value", type: "uint256" },
101
+ { name: "validAfter", type: "uint256" },
102
+ { name: "validBefore", type: "uint256" },
103
+ { name: "nonce", type: "bytes32" }
104
+ ]
105
+ };
106
+
107
+ // src/types/shared/evm/eip2612.ts
108
+ var permitTypes = {
109
+ Permit: [
110
+ { name: "owner", type: "address" },
111
+ { name: "spender", type: "address" },
112
+ { name: "value", type: "uint256" },
113
+ { name: "nonce", type: "uint256" },
114
+ { name: "deadline", type: "uint256" }
115
+ ]
116
+ };
117
+ var erc20PermitABI = [
118
+ {
119
+ inputs: [
120
+ { internalType: "address", name: "owner", type: "address" },
121
+ { internalType: "address", name: "spender", type: "address" },
122
+ { internalType: "uint256", name: "value", type: "uint256" },
123
+ { internalType: "uint256", name: "deadline", type: "uint256" },
124
+ { internalType: "uint8", name: "v", type: "uint8" },
125
+ { internalType: "bytes32", name: "r", type: "bytes32" },
126
+ { internalType: "bytes32", name: "s", type: "bytes32" }
127
+ ],
128
+ name: "permit",
129
+ outputs: [],
130
+ stateMutability: "nonpayable",
131
+ type: "function"
132
+ },
133
+ {
134
+ inputs: [{ internalType: "address", name: "owner", type: "address" }],
135
+ name: "nonces",
136
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
137
+ stateMutability: "view",
138
+ type: "function"
139
+ },
140
+ {
141
+ inputs: [],
142
+ name: "name",
143
+ outputs: [{ internalType: "string", name: "", type: "string" }],
144
+ stateMutability: "view",
145
+ type: "function"
146
+ },
147
+ {
148
+ inputs: [],
149
+ name: "DOMAIN_SEPARATOR",
150
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
151
+ stateMutability: "view",
152
+ type: "function"
153
+ },
154
+ {
155
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
156
+ name: "balanceOf",
157
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
158
+ stateMutability: "view",
159
+ type: "function"
160
+ },
161
+ {
162
+ inputs: [
163
+ { internalType: "address", name: "from", type: "address" },
164
+ { internalType: "address", name: "to", type: "address" },
165
+ { internalType: "uint256", name: "amount", type: "uint256" }
166
+ ],
167
+ name: "transferFrom",
168
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
169
+ stateMutability: "nonpayable",
170
+ type: "function"
171
+ },
172
+ {
173
+ inputs: [
174
+ { internalType: "address", name: "owner", type: "address" },
175
+ { internalType: "address", name: "spender", type: "address" }
176
+ ],
177
+ name: "allowance",
178
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
179
+ stateMutability: "view",
180
+ type: "function"
181
+ },
182
+ {
183
+ inputs: [],
184
+ name: "version",
185
+ outputs: [{ internalType: "string", name: "", type: "string" }],
186
+ stateMutability: "view",
187
+ type: "function"
188
+ }
189
+ ];
190
+
191
+ // src/types/shared/evm/permit2.ts
192
+ var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
193
+ var permit2Types = {
194
+ PermitTransferFrom: [
195
+ { name: "permitted", type: "TokenPermissions" },
196
+ { name: "spender", type: "address" },
197
+ { name: "nonce", type: "uint256" },
198
+ { name: "deadline", type: "uint256" }
199
+ ],
200
+ TokenPermissions: [
201
+ { name: "token", type: "address" },
202
+ { name: "amount", type: "uint256" }
203
+ ]
204
+ };
205
+ var permit2ABI = [
206
+ {
207
+ inputs: [
208
+ {
209
+ components: [
210
+ {
211
+ components: [
212
+ { internalType: "address", name: "token", type: "address" },
213
+ { internalType: "uint256", name: "amount", type: "uint256" }
214
+ ],
215
+ internalType: "struct ISignatureTransfer.TokenPermissions",
216
+ name: "permitted",
217
+ type: "tuple"
218
+ },
219
+ { internalType: "uint256", name: "nonce", type: "uint256" },
220
+ { internalType: "uint256", name: "deadline", type: "uint256" }
221
+ ],
222
+ internalType: "struct ISignatureTransfer.PermitTransferFrom",
223
+ name: "permit",
224
+ type: "tuple"
225
+ },
226
+ {
227
+ components: [
228
+ { internalType: "address", name: "to", type: "address" },
229
+ { internalType: "uint256", name: "requestedAmount", type: "uint256" }
230
+ ],
231
+ internalType: "struct ISignatureTransfer.SignatureTransferDetails",
232
+ name: "transferDetails",
233
+ type: "tuple"
234
+ },
235
+ { internalType: "address", name: "owner", type: "address" },
236
+ { internalType: "bytes", name: "signature", type: "bytes" }
237
+ ],
238
+ name: "permitTransferFrom",
239
+ outputs: [],
240
+ stateMutability: "nonpayable",
241
+ type: "function"
242
+ },
243
+ {
244
+ inputs: [
245
+ { internalType: "address", name: "owner", type: "address" },
246
+ { internalType: "address", name: "token", type: "address" },
247
+ { internalType: "address", name: "spender", type: "address" }
248
+ ],
249
+ name: "allowance",
250
+ outputs: [
251
+ { internalType: "uint160", name: "amount", type: "uint160" },
252
+ { internalType: "uint48", name: "expiration", type: "uint48" },
253
+ { internalType: "uint48", name: "nonce", type: "uint48" }
254
+ ],
255
+ stateMutability: "view",
256
+ type: "function"
257
+ },
258
+ {
259
+ inputs: [],
260
+ name: "DOMAIN_SEPARATOR",
261
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
262
+ stateMutability: "view",
263
+ type: "function"
264
+ },
265
+ {
266
+ inputs: [
267
+ { internalType: "address", name: "owner", type: "address" },
268
+ { internalType: "uint256", name: "wordPos", type: "uint256" }
269
+ ],
270
+ name: "nonceBitmap",
271
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
272
+ stateMutability: "view",
273
+ type: "function"
274
+ }
275
+ ];
276
+
277
+ // src/types/shared/evm/erc20PermitABI.ts
278
+ var usdcABI = [
279
+ {
280
+ anonymous: false,
281
+ inputs: [
282
+ {
283
+ indexed: true,
284
+ internalType: "address",
285
+ name: "owner",
286
+ type: "address"
287
+ },
288
+ {
289
+ indexed: true,
290
+ internalType: "address",
291
+ name: "spender",
292
+ type: "address"
293
+ },
294
+ {
295
+ indexed: false,
296
+ internalType: "uint256",
297
+ name: "value",
298
+ type: "uint256"
299
+ }
300
+ ],
301
+ name: "Approval",
302
+ type: "event"
303
+ },
304
+ {
305
+ anonymous: false,
306
+ inputs: [
307
+ {
308
+ indexed: true,
309
+ internalType: "address",
310
+ name: "authorizer",
311
+ type: "address"
312
+ },
313
+ {
314
+ indexed: true,
315
+ internalType: "bytes32",
316
+ name: "nonce",
317
+ type: "bytes32"
318
+ }
319
+ ],
320
+ name: "AuthorizationCanceled",
321
+ type: "event"
322
+ },
323
+ {
324
+ anonymous: false,
325
+ inputs: [
326
+ {
327
+ indexed: true,
328
+ internalType: "address",
329
+ name: "authorizer",
330
+ type: "address"
331
+ },
332
+ {
333
+ indexed: true,
334
+ internalType: "bytes32",
335
+ name: "nonce",
336
+ type: "bytes32"
337
+ }
338
+ ],
339
+ name: "AuthorizationUsed",
340
+ type: "event"
341
+ },
342
+ {
343
+ anonymous: false,
344
+ inputs: [
345
+ {
346
+ indexed: true,
347
+ internalType: "address",
348
+ name: "_account",
349
+ type: "address"
350
+ }
351
+ ],
352
+ name: "Blacklisted",
353
+ type: "event"
354
+ },
355
+ {
356
+ anonymous: false,
357
+ inputs: [
358
+ {
359
+ indexed: true,
360
+ internalType: "address",
361
+ name: "newBlacklister",
362
+ type: "address"
363
+ }
364
+ ],
365
+ name: "BlacklisterChanged",
366
+ type: "event"
367
+ },
368
+ {
369
+ anonymous: false,
370
+ inputs: [
371
+ {
372
+ indexed: true,
373
+ internalType: "address",
374
+ name: "burner",
375
+ type: "address"
376
+ },
377
+ {
378
+ indexed: false,
379
+ internalType: "uint256",
380
+ name: "amount",
381
+ type: "uint256"
382
+ }
383
+ ],
384
+ name: "Burn",
385
+ type: "event"
386
+ },
387
+ {
388
+ anonymous: false,
389
+ inputs: [
390
+ {
391
+ indexed: true,
392
+ internalType: "address",
393
+ name: "newMasterMinter",
394
+ type: "address"
395
+ }
396
+ ],
397
+ name: "MasterMinterChanged",
398
+ type: "event"
399
+ },
400
+ {
401
+ anonymous: false,
402
+ inputs: [
403
+ {
404
+ indexed: true,
405
+ internalType: "address",
406
+ name: "minter",
407
+ type: "address"
408
+ },
409
+ { indexed: true, internalType: "address", name: "to", type: "address" },
410
+ {
411
+ indexed: false,
412
+ internalType: "uint256",
413
+ name: "amount",
414
+ type: "uint256"
415
+ }
416
+ ],
417
+ name: "Mint",
418
+ type: "event"
419
+ },
420
+ {
421
+ anonymous: false,
422
+ inputs: [
423
+ {
424
+ indexed: true,
425
+ internalType: "address",
426
+ name: "minter",
427
+ type: "address"
428
+ },
429
+ {
430
+ indexed: false,
431
+ internalType: "uint256",
432
+ name: "minterAllowedAmount",
433
+ type: "uint256"
434
+ }
435
+ ],
436
+ name: "MinterConfigured",
437
+ type: "event"
438
+ },
439
+ {
440
+ anonymous: false,
441
+ inputs: [
442
+ {
443
+ indexed: true,
444
+ internalType: "address",
445
+ name: "oldMinter",
446
+ type: "address"
447
+ }
448
+ ],
449
+ name: "MinterRemoved",
450
+ type: "event"
451
+ },
452
+ {
453
+ anonymous: false,
454
+ inputs: [
455
+ {
456
+ indexed: false,
457
+ internalType: "address",
458
+ name: "previousOwner",
459
+ type: "address"
460
+ },
461
+ {
462
+ indexed: false,
463
+ internalType: "address",
464
+ name: "newOwner",
465
+ type: "address"
466
+ }
467
+ ],
468
+ name: "OwnershipTransferred",
469
+ type: "event"
470
+ },
471
+ { anonymous: false, inputs: [], name: "Pause", type: "event" },
472
+ {
473
+ anonymous: false,
474
+ inputs: [
475
+ {
476
+ indexed: true,
477
+ internalType: "address",
478
+ name: "newAddress",
479
+ type: "address"
480
+ }
481
+ ],
482
+ name: "PauserChanged",
483
+ type: "event"
484
+ },
485
+ {
486
+ anonymous: false,
487
+ inputs: [
488
+ {
489
+ indexed: true,
490
+ internalType: "address",
491
+ name: "newRescuer",
492
+ type: "address"
493
+ }
494
+ ],
495
+ name: "RescuerChanged",
496
+ type: "event"
497
+ },
498
+ {
499
+ anonymous: false,
500
+ inputs: [
501
+ { indexed: true, internalType: "address", name: "from", type: "address" },
502
+ { indexed: true, internalType: "address", name: "to", type: "address" },
503
+ {
504
+ indexed: false,
505
+ internalType: "uint256",
506
+ name: "value",
507
+ type: "uint256"
508
+ }
509
+ ],
510
+ name: "Transfer",
511
+ type: "event"
512
+ },
513
+ {
514
+ anonymous: false,
515
+ inputs: [
516
+ {
517
+ indexed: true,
518
+ internalType: "address",
519
+ name: "_account",
520
+ type: "address"
521
+ }
522
+ ],
523
+ name: "UnBlacklisted",
524
+ type: "event"
525
+ },
526
+ { anonymous: false, inputs: [], name: "Unpause", type: "event" },
527
+ {
528
+ inputs: [],
529
+ name: "CANCEL_AUTHORIZATION_TYPEHASH",
530
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
531
+ stateMutability: "view",
532
+ type: "function"
533
+ },
534
+ {
535
+ inputs: [],
536
+ name: "DOMAIN_SEPARATOR",
537
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
538
+ stateMutability: "view",
539
+ type: "function"
540
+ },
541
+ {
542
+ inputs: [],
543
+ name: "PERMIT_TYPEHASH",
544
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
545
+ stateMutability: "view",
546
+ type: "function"
547
+ },
548
+ {
549
+ inputs: [],
550
+ name: "RECEIVE_WITH_AUTHORIZATION_TYPEHASH",
551
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
552
+ stateMutability: "view",
553
+ type: "function"
554
+ },
555
+ {
556
+ inputs: [],
557
+ name: "TRANSFER_WITH_AUTHORIZATION_TYPEHASH",
558
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
559
+ stateMutability: "view",
560
+ type: "function"
561
+ },
562
+ {
563
+ inputs: [
564
+ { internalType: "address", name: "owner", type: "address" },
565
+ { internalType: "address", name: "spender", type: "address" }
566
+ ],
567
+ name: "allowance",
568
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
569
+ stateMutability: "view",
570
+ type: "function"
571
+ },
572
+ {
573
+ inputs: [
574
+ { internalType: "address", name: "spender", type: "address" },
575
+ { internalType: "uint256", name: "value", type: "uint256" }
576
+ ],
577
+ name: "approve",
578
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
579
+ stateMutability: "nonpayable",
580
+ type: "function"
581
+ },
582
+ {
583
+ inputs: [
584
+ { internalType: "address", name: "authorizer", type: "address" },
585
+ { internalType: "bytes32", name: "nonce", type: "bytes32" }
586
+ ],
587
+ name: "authorizationState",
588
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
589
+ stateMutability: "view",
590
+ type: "function"
591
+ },
592
+ {
593
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
594
+ name: "balanceOf",
595
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
596
+ stateMutability: "view",
597
+ type: "function"
598
+ },
599
+ {
600
+ inputs: [{ internalType: "address", name: "_account", type: "address" }],
601
+ name: "blacklist",
602
+ outputs: [],
603
+ stateMutability: "nonpayable",
604
+ type: "function"
605
+ },
606
+ {
607
+ inputs: [],
608
+ name: "blacklister",
609
+ outputs: [{ internalType: "address", name: "", type: "address" }],
610
+ stateMutability: "view",
611
+ type: "function"
612
+ },
613
+ {
614
+ inputs: [{ internalType: "uint256", name: "_amount", type: "uint256" }],
615
+ name: "burn",
616
+ outputs: [],
617
+ stateMutability: "nonpayable",
618
+ type: "function"
619
+ },
620
+ {
621
+ inputs: [
622
+ { internalType: "address", name: "authorizer", type: "address" },
623
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
624
+ { internalType: "uint8", name: "v", type: "uint8" },
625
+ { internalType: "bytes32", name: "r", type: "bytes32" },
626
+ { internalType: "bytes32", name: "s", type: "bytes32" }
627
+ ],
628
+ name: "cancelAuthorization",
629
+ outputs: [],
630
+ stateMutability: "nonpayable",
631
+ type: "function"
632
+ },
633
+ {
634
+ inputs: [
635
+ { internalType: "address", name: "authorizer", type: "address" },
636
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
637
+ { internalType: "bytes", name: "signature", type: "bytes" }
638
+ ],
639
+ name: "cancelAuthorization",
640
+ outputs: [],
641
+ stateMutability: "nonpayable",
642
+ type: "function"
643
+ },
644
+ {
645
+ inputs: [
646
+ { internalType: "address", name: "minter", type: "address" },
647
+ { internalType: "uint256", name: "minterAllowedAmount", type: "uint256" }
648
+ ],
649
+ name: "configureMinter",
650
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
651
+ stateMutability: "nonpayable",
652
+ type: "function"
653
+ },
654
+ {
655
+ inputs: [],
656
+ name: "currency",
657
+ outputs: [{ internalType: "string", name: "", type: "string" }],
658
+ stateMutability: "view",
659
+ type: "function"
660
+ },
661
+ {
662
+ inputs: [],
663
+ name: "decimals",
664
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
665
+ stateMutability: "view",
666
+ type: "function"
667
+ },
668
+ {
669
+ inputs: [
670
+ { internalType: "address", name: "spender", type: "address" },
671
+ { internalType: "uint256", name: "decrement", type: "uint256" }
672
+ ],
673
+ name: "decreaseAllowance",
674
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
675
+ stateMutability: "nonpayable",
676
+ type: "function"
677
+ },
678
+ {
679
+ inputs: [
680
+ { internalType: "address", name: "spender", type: "address" },
681
+ { internalType: "uint256", name: "increment", type: "uint256" }
682
+ ],
683
+ name: "increaseAllowance",
684
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
685
+ stateMutability: "nonpayable",
686
+ type: "function"
687
+ },
688
+ {
689
+ inputs: [
690
+ { internalType: "string", name: "tokenName", type: "string" },
691
+ { internalType: "string", name: "tokenSymbol", type: "string" },
692
+ { internalType: "string", name: "tokenCurrency", type: "string" },
693
+ { internalType: "uint8", name: "tokenDecimals", type: "uint8" },
694
+ { internalType: "address", name: "newMasterMinter", type: "address" },
695
+ { internalType: "address", name: "newPauser", type: "address" },
696
+ { internalType: "address", name: "newBlacklister", type: "address" },
697
+ { internalType: "address", name: "newOwner", type: "address" }
698
+ ],
699
+ name: "initialize",
700
+ outputs: [],
701
+ stateMutability: "nonpayable",
702
+ type: "function"
703
+ },
704
+ {
705
+ inputs: [{ internalType: "string", name: "newName", type: "string" }],
706
+ name: "initializeV2",
707
+ outputs: [],
708
+ stateMutability: "nonpayable",
709
+ type: "function"
710
+ },
711
+ {
712
+ inputs: [{ internalType: "address", name: "lostAndFound", type: "address" }],
713
+ name: "initializeV2_1",
714
+ outputs: [],
715
+ stateMutability: "nonpayable",
716
+ type: "function"
717
+ },
718
+ {
719
+ inputs: [
720
+ {
721
+ internalType: "address[]",
722
+ name: "accountsToBlacklist",
723
+ type: "address[]"
724
+ },
725
+ { internalType: "string", name: "newSymbol", type: "string" }
726
+ ],
727
+ name: "initializeV2_2",
728
+ outputs: [],
729
+ stateMutability: "nonpayable",
730
+ type: "function"
731
+ },
732
+ {
733
+ inputs: [{ internalType: "address", name: "_account", type: "address" }],
734
+ name: "isBlacklisted",
735
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
736
+ stateMutability: "view",
737
+ type: "function"
738
+ },
739
+ {
740
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
741
+ name: "isMinter",
742
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
743
+ stateMutability: "view",
744
+ type: "function"
745
+ },
746
+ {
747
+ inputs: [],
748
+ name: "masterMinter",
749
+ outputs: [{ internalType: "address", name: "", type: "address" }],
750
+ stateMutability: "view",
751
+ type: "function"
752
+ },
753
+ {
754
+ inputs: [
755
+ { internalType: "address", name: "_to", type: "address" },
756
+ { internalType: "uint256", name: "_amount", type: "uint256" }
757
+ ],
758
+ name: "mint",
759
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
760
+ stateMutability: "nonpayable",
761
+ type: "function"
762
+ },
763
+ {
764
+ inputs: [{ internalType: "address", name: "minter", type: "address" }],
765
+ name: "minterAllowance",
766
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
767
+ stateMutability: "view",
768
+ type: "function"
769
+ },
770
+ {
771
+ inputs: [],
772
+ name: "name",
773
+ outputs: [{ internalType: "string", name: "", type: "string" }],
774
+ stateMutability: "view",
775
+ type: "function"
776
+ },
777
+ {
778
+ inputs: [{ internalType: "address", name: "owner", type: "address" }],
779
+ name: "nonces",
780
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
781
+ stateMutability: "view",
782
+ type: "function"
783
+ },
784
+ {
785
+ inputs: [],
786
+ name: "owner",
787
+ outputs: [{ internalType: "address", name: "", type: "address" }],
788
+ stateMutability: "view",
789
+ type: "function"
790
+ },
791
+ {
792
+ inputs: [],
793
+ name: "pause",
794
+ outputs: [],
795
+ stateMutability: "nonpayable",
796
+ type: "function"
797
+ },
798
+ {
799
+ inputs: [],
800
+ name: "paused",
801
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
802
+ stateMutability: "view",
803
+ type: "function"
804
+ },
805
+ {
806
+ inputs: [],
807
+ name: "pauser",
808
+ outputs: [{ internalType: "address", name: "", type: "address" }],
809
+ stateMutability: "view",
810
+ type: "function"
811
+ },
812
+ {
813
+ inputs: [
814
+ { internalType: "address", name: "owner", type: "address" },
815
+ { internalType: "address", name: "spender", type: "address" },
816
+ { internalType: "uint256", name: "value", type: "uint256" },
817
+ { internalType: "uint256", name: "deadline", type: "uint256" },
818
+ { internalType: "bytes", name: "signature", type: "bytes" }
819
+ ],
820
+ name: "permit",
821
+ outputs: [],
822
+ stateMutability: "nonpayable",
823
+ type: "function"
824
+ },
825
+ {
826
+ inputs: [
827
+ { internalType: "address", name: "owner", type: "address" },
828
+ { internalType: "address", name: "spender", type: "address" },
829
+ { internalType: "uint256", name: "value", type: "uint256" },
830
+ { internalType: "uint256", name: "deadline", type: "uint256" },
831
+ { internalType: "uint8", name: "v", type: "uint8" },
832
+ { internalType: "bytes32", name: "r", type: "bytes32" },
833
+ { internalType: "bytes32", name: "s", type: "bytes32" }
834
+ ],
835
+ name: "permit",
836
+ outputs: [],
837
+ stateMutability: "nonpayable",
838
+ type: "function"
839
+ },
840
+ {
841
+ inputs: [
842
+ { internalType: "address", name: "from", type: "address" },
843
+ { internalType: "address", name: "to", type: "address" },
844
+ { internalType: "uint256", name: "value", type: "uint256" },
845
+ { internalType: "uint256", name: "validAfter", type: "uint256" },
846
+ { internalType: "uint256", name: "validBefore", type: "uint256" },
847
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
848
+ { internalType: "bytes", name: "signature", type: "bytes" }
849
+ ],
850
+ name: "receiveWithAuthorization",
851
+ outputs: [],
852
+ stateMutability: "nonpayable",
853
+ type: "function"
854
+ },
855
+ {
856
+ inputs: [
857
+ { internalType: "address", name: "from", type: "address" },
858
+ { internalType: "address", name: "to", type: "address" },
859
+ { internalType: "uint256", name: "value", type: "uint256" },
860
+ { internalType: "uint256", name: "validAfter", type: "uint256" },
861
+ { internalType: "uint256", name: "validBefore", type: "uint256" },
862
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
863
+ { internalType: "uint8", name: "v", type: "uint8" },
864
+ { internalType: "bytes32", name: "r", type: "bytes32" },
865
+ { internalType: "bytes32", name: "s", type: "bytes32" }
866
+ ],
867
+ name: "receiveWithAuthorization",
868
+ outputs: [],
869
+ stateMutability: "nonpayable",
870
+ type: "function"
871
+ },
872
+ {
873
+ inputs: [{ internalType: "address", name: "minter", type: "address" }],
874
+ name: "removeMinter",
875
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
876
+ stateMutability: "nonpayable",
877
+ type: "function"
878
+ },
879
+ {
880
+ inputs: [
881
+ {
882
+ internalType: "contract IERC20",
883
+ name: "tokenContract",
884
+ type: "address"
885
+ },
886
+ { internalType: "address", name: "to", type: "address" },
887
+ { internalType: "uint256", name: "amount", type: "uint256" }
888
+ ],
889
+ name: "rescueERC20",
890
+ outputs: [],
891
+ stateMutability: "nonpayable",
892
+ type: "function"
893
+ },
894
+ {
895
+ inputs: [],
896
+ name: "rescuer",
897
+ outputs: [{ internalType: "address", name: "", type: "address" }],
898
+ stateMutability: "view",
899
+ type: "function"
900
+ },
901
+ {
902
+ inputs: [],
903
+ name: "symbol",
904
+ outputs: [{ internalType: "string", name: "", type: "string" }],
905
+ stateMutability: "view",
906
+ type: "function"
907
+ },
908
+ {
909
+ inputs: [],
910
+ name: "totalSupply",
911
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
912
+ stateMutability: "view",
913
+ type: "function"
914
+ },
915
+ {
916
+ inputs: [
917
+ { internalType: "address", name: "to", type: "address" },
918
+ { internalType: "uint256", name: "value", type: "uint256" }
919
+ ],
920
+ name: "transfer",
921
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
922
+ stateMutability: "nonpayable",
923
+ type: "function"
924
+ },
925
+ {
926
+ inputs: [
927
+ { internalType: "address", name: "from", type: "address" },
928
+ { internalType: "address", name: "to", type: "address" },
929
+ { internalType: "uint256", name: "value", type: "uint256" }
930
+ ],
931
+ name: "transferFrom",
932
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
933
+ stateMutability: "nonpayable",
934
+ type: "function"
935
+ },
936
+ {
937
+ inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
938
+ name: "transferOwnership",
939
+ outputs: [],
940
+ stateMutability: "nonpayable",
941
+ type: "function"
942
+ },
943
+ {
944
+ inputs: [
945
+ { internalType: "address", name: "from", type: "address" },
946
+ { internalType: "address", name: "to", type: "address" },
947
+ { internalType: "uint256", name: "value", type: "uint256" },
948
+ { internalType: "uint256", name: "validAfter", type: "uint256" },
949
+ { internalType: "uint256", name: "validBefore", type: "uint256" },
950
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
951
+ { internalType: "bytes", name: "signature", type: "bytes" }
952
+ ],
953
+ name: "transferWithAuthorization",
954
+ outputs: [],
955
+ stateMutability: "nonpayable",
956
+ type: "function"
957
+ },
958
+ {
959
+ inputs: [
960
+ { internalType: "address", name: "from", type: "address" },
961
+ { internalType: "address", name: "to", type: "address" },
962
+ { internalType: "uint256", name: "value", type: "uint256" },
963
+ { internalType: "uint256", name: "validAfter", type: "uint256" },
964
+ { internalType: "uint256", name: "validBefore", type: "uint256" },
965
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
966
+ { internalType: "uint8", name: "v", type: "uint8" },
967
+ { internalType: "bytes32", name: "r", type: "bytes32" },
968
+ { internalType: "bytes32", name: "s", type: "bytes32" }
969
+ ],
970
+ name: "transferWithAuthorization",
971
+ outputs: [],
972
+ stateMutability: "nonpayable",
973
+ type: "function"
974
+ },
975
+ {
976
+ inputs: [{ internalType: "address", name: "_account", type: "address" }],
977
+ name: "unBlacklist",
978
+ outputs: [],
979
+ stateMutability: "nonpayable",
980
+ type: "function"
981
+ },
982
+ {
983
+ inputs: [],
984
+ name: "unpause",
985
+ outputs: [],
986
+ stateMutability: "nonpayable",
987
+ type: "function"
988
+ },
989
+ {
990
+ inputs: [{ internalType: "address", name: "_newBlacklister", type: "address" }],
991
+ name: "updateBlacklister",
992
+ outputs: [],
993
+ stateMutability: "nonpayable",
994
+ type: "function"
995
+ },
996
+ {
997
+ inputs: [{ internalType: "address", name: "_newMasterMinter", type: "address" }],
998
+ name: "updateMasterMinter",
999
+ outputs: [],
1000
+ stateMutability: "nonpayable",
1001
+ type: "function"
1002
+ },
1003
+ {
1004
+ inputs: [{ internalType: "address", name: "_newPauser", type: "address" }],
1005
+ name: "updatePauser",
1006
+ outputs: [],
1007
+ stateMutability: "nonpayable",
1008
+ type: "function"
1009
+ },
1010
+ {
1011
+ inputs: [{ internalType: "address", name: "newRescuer", type: "address" }],
1012
+ name: "updateRescuer",
1013
+ outputs: [],
1014
+ stateMutability: "nonpayable",
1015
+ type: "function"
1016
+ },
1017
+ {
1018
+ inputs: [],
1019
+ name: "version",
1020
+ outputs: [{ internalType: "string", name: "", type: "string" }],
1021
+ stateMutability: "pure",
1022
+ type: "function"
1023
+ }
1024
+ ];
1025
+
1026
+ // src/types/shared/evm/wallet.ts
1027
+ var import_viem = require("viem");
1028
+ var import_chains = require("viem/chains");
1029
+ var import_accounts = require("viem/accounts");
1030
+ function isSignerWallet(wallet) {
1031
+ return typeof wallet === "object" && wallet !== null && "chain" in wallet && "transport" in wallet;
1032
+ }
1033
+ function isAccount(wallet) {
1034
+ const w = wallet;
1035
+ return typeof wallet === "object" && wallet !== null && typeof w.address === "string" && typeof w.type === "string" && // Check for essential signing capabilities
1036
+ typeof w.sign === "function" && typeof w.signMessage === "function" && typeof w.signTypedData === "function" && // Check for transaction signing (required by LocalAccount)
1037
+ typeof w.signTransaction === "function";
1038
+ }
1039
+
1040
+ // src/schemes/exact/evm/eip3009/sign.ts
1041
+ var import_viem2 = require("viem");
1042
+
1043
+ // src/shared/base64.ts
1044
+ var Base64EncodedRegex = /^[A-Za-z0-9+/]*={0,2}$/;
1045
+ function safeBase64Encode(data) {
1046
+ if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") {
1047
+ return globalThis.btoa(data);
1048
+ }
1049
+ return Buffer.from(data).toString("base64");
1050
+ }
1051
+
1052
+ // src/types/shared/money.ts
1053
+ var import_zod = require("zod");
1054
+ 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));
1055
+
1056
+ // src/types/shared/network.ts
1057
+ var import_zod2 = require("zod");
1058
+ var NetworkSchema = import_zod2.z.enum([
1059
+ "base-sepolia",
1060
+ "base",
1061
+ "avalanche-fuji",
1062
+ "avalanche",
1063
+ "iotex",
1064
+ "solana-devnet",
1065
+ "solana",
1066
+ "sei",
1067
+ "sei-testnet",
1068
+ "polygon",
1069
+ "polygon-amoy",
1070
+ "peaq",
1071
+ "bsc",
1072
+ "bsc-testnet"
1073
+ ]);
1074
+ var SupportedEVMNetworks = [
1075
+ "base-sepolia",
1076
+ "base",
1077
+ "avalanche-fuji",
1078
+ "avalanche",
1079
+ "iotex",
1080
+ "sei",
1081
+ "sei-testnet",
1082
+ "polygon",
1083
+ "polygon-amoy",
1084
+ "peaq",
1085
+ "bsc",
1086
+ "bsc-testnet"
1087
+ ];
1088
+ var EvmNetworkToChainId = /* @__PURE__ */ new Map([
1089
+ ["base-sepolia", 84532],
1090
+ ["base", 8453],
1091
+ ["avalanche-fuji", 43113],
1092
+ ["avalanche", 43114],
1093
+ ["iotex", 4689],
1094
+ ["sei", 1329],
1095
+ ["sei-testnet", 1328],
1096
+ ["polygon", 137],
1097
+ ["polygon-amoy", 80002],
1098
+ ["peaq", 3338],
1099
+ ["bsc", 56],
1100
+ ["bsc-testnet", 97]
1101
+ ]);
1102
+ var SupportedSVMNetworks = ["solana-devnet", "solana"];
1103
+ var SvmNetworkToChainId = /* @__PURE__ */ new Map([
1104
+ ["solana-devnet", 103],
1105
+ ["solana", 101]
1106
+ ]);
1107
+ var ChainIdToNetwork = Object.fromEntries(
1108
+ [...SupportedEVMNetworks, ...SupportedSVMNetworks].map((network) => [
1109
+ EvmNetworkToChainId.get(network),
1110
+ network
1111
+ ])
1112
+ );
1113
+
1114
+ // src/shared/svm/wallet.ts
1115
+ var import_kit2 = require("@solana/kit");
1116
+ var import_base = require("@scure/base");
1117
+
1118
+ // src/shared/svm/rpc.ts
1119
+ var import_kit = require("@solana/kit");
1120
+ var DEVNET_RPC_URL = "https://api.devnet.solana.com";
1121
+ var MAINNET_RPC_URL = "https://api.mainnet-beta.solana.com";
1122
+ var DEVNET_WS_URL = "wss://api.devnet.solana.com";
1123
+ var MAINNET_WS_URL = "wss://api.mainnet-beta.solana.com";
1124
+ function createDevnetRpcClient(url) {
1125
+ return (0, import_kit.createSolanaRpc)(
1126
+ url ? (0, import_kit.devnet)(url) : (0, import_kit.devnet)(DEVNET_RPC_URL)
1127
+ );
1128
+ }
1129
+ function createMainnetRpcClient(url) {
1130
+ return (0, import_kit.createSolanaRpc)(
1131
+ url ? (0, import_kit.mainnet)(url) : (0, import_kit.mainnet)(MAINNET_RPC_URL)
1132
+ );
1133
+ }
1134
+ function getRpcClient(network, url) {
1135
+ if (network === "solana-devnet") {
1136
+ return createDevnetRpcClient(url);
1137
+ } else if (network === "solana") {
1138
+ return createMainnetRpcClient(url);
1139
+ } else {
1140
+ throw new Error("Invalid network");
1141
+ }
1142
+ }
1143
+ function getRpcSubscriptions(network, url) {
1144
+ if (network === "solana-devnet") {
1145
+ return (0, import_kit.createSolanaRpcSubscriptions)((0, import_kit.devnet)(url ? httpToWs(url) : DEVNET_WS_URL));
1146
+ } else if (network === "solana") {
1147
+ return (0, import_kit.createSolanaRpcSubscriptions)((0, import_kit.mainnet)(url ? httpToWs(url) : MAINNET_WS_URL));
1148
+ } else {
1149
+ throw new Error("Invalid network");
1150
+ }
1151
+ }
1152
+ function httpToWs(url) {
1153
+ if (url.startsWith("http")) {
1154
+ return url.replace("http", "ws");
1155
+ }
1156
+ return url;
1157
+ }
1158
+
1159
+ // src/shared/svm/wallet.ts
1160
+ function isSignerWallet2(wallet) {
1161
+ return (0, import_kit2.isKeyPairSigner)(wallet);
1162
+ }
1163
+
1164
+ // src/types/shared/wallet.ts
1165
+ function isEvmSignerWallet(wallet) {
1166
+ return isSignerWallet(wallet) || isAccount(wallet);
1167
+ }
1168
+ function isSvmSignerWallet(wallet) {
1169
+ return isSignerWallet2(wallet);
1170
+ }
1171
+ function isMultiNetworkSigner(wallet) {
1172
+ return "evm" in wallet && "svm" in wallet;
1173
+ }
1174
+
1175
+ // src/types/shared/svm/regex.ts
1176
+ var SvmAddressRegex = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
1177
+
1178
+ // src/shared/network.ts
1179
+ function getNetworkId(network) {
1180
+ if (EvmNetworkToChainId.has(network)) {
1181
+ return EvmNetworkToChainId.get(network);
1182
+ }
1183
+ if (SvmNetworkToChainId.has(network)) {
1184
+ return SvmNetworkToChainId.get(network);
1185
+ }
1186
+ throw new Error(`Unsupported network: ${network}`);
1187
+ }
1188
+
1189
+ // src/types/verify/x402Specs.ts
1190
+ var import_zod3 = require("zod");
1191
+ var EvmMaxAtomicUnits = 40;
1192
+ var EvmAddressRegex = /^0x[0-9a-fA-F]{40}$/;
1193
+ var MixedAddressRegex = /^0x[a-fA-F0-9]{40}|[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$/;
1194
+ var HexEncoded64ByteRegex = /^0x[0-9a-fA-F]{64}$/;
1195
+ var EvmSignatureRegex = /^0x[0-9a-fA-F]+$/;
1196
+ var schemes = ["exact"];
1197
+ var x402Versions = [1];
1198
+ var ErrorReasons = [
1199
+ "insufficient_funds",
1200
+ "invalid_exact_evm_payload_authorization_valid_after",
1201
+ "invalid_exact_evm_payload_authorization_valid_before",
1202
+ "invalid_exact_evm_payload_authorization_value",
1203
+ "invalid_exact_evm_payload_signature",
1204
+ "invalid_exact_evm_payload_recipient_mismatch",
1205
+ "invalid_exact_svm_payload_transaction",
1206
+ "invalid_exact_svm_payload_transaction_amount_mismatch",
1207
+ "invalid_exact_svm_payload_transaction_create_ata_instruction",
1208
+ "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee",
1209
+ "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset",
1210
+ "invalid_exact_svm_payload_transaction_instructions",
1211
+ "invalid_exact_svm_payload_transaction_instructions_length",
1212
+ "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction",
1213
+ "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction",
1214
+ "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high",
1215
+ "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked",
1216
+ "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked",
1217
+ "invalid_exact_svm_payload_transaction_not_a_transfer_instruction",
1218
+ "invalid_exact_svm_payload_transaction_receiver_ata_not_found",
1219
+ "invalid_exact_svm_payload_transaction_sender_ata_not_found",
1220
+ "invalid_exact_svm_payload_transaction_simulation_failed",
1221
+ "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata",
1222
+ "invalid_network",
1223
+ "invalid_payload",
1224
+ "invalid_payment_requirements",
1225
+ "invalid_scheme",
1226
+ "invalid_payment",
1227
+ "payment_expired",
1228
+ "unsupported_scheme",
1229
+ "invalid_x402_version",
1230
+ "invalid_transaction_state",
1231
+ "settle_exact_svm_block_height_exceeded",
1232
+ "settle_exact_svm_transaction_confirmation_timed_out",
1233
+ "unexpected_settle_error",
1234
+ "unexpected_verify_error",
1235
+ // New error reasons for Permit and Permit2
1236
+ "unsupported_authorization_type",
1237
+ "invalid_authorization_type",
1238
+ "invalid_permit_signature",
1239
+ "invalid_permit2_signature",
1240
+ "permit_expired",
1241
+ "permit2_expired",
1242
+ "permit2_not_approved",
1243
+ "invalid_token_address",
1244
+ "invalid_spender_address",
1245
+ "token_mismatch",
1246
+ "insufficient_payment_amount",
1247
+ "transaction_failed",
1248
+ "settlement_failed"
1249
+ ];
1250
+ var isInteger = (value) => Number.isInteger(Number(value)) && Number(value) >= 0;
1251
+ var hasMaxLength = (maxLength) => (value) => value.length <= maxLength;
1252
+ var EvmOrSvmAddress = import_zod3.z.string().regex(EvmAddressRegex).or(import_zod3.z.string().regex(SvmAddressRegex));
1253
+ var mixedAddressOrSvmAddress = import_zod3.z.string().regex(MixedAddressRegex).or(import_zod3.z.string().regex(SvmAddressRegex));
1254
+ var PaymentRequirementsSchema = import_zod3.z.object({
1255
+ scheme: import_zod3.z.enum(schemes),
1256
+ network: NetworkSchema,
1257
+ maxAmountRequired: import_zod3.z.string().refine(isInteger),
1258
+ resource: import_zod3.z.string().url(),
1259
+ description: import_zod3.z.string(),
1260
+ mimeType: import_zod3.z.string(),
1261
+ outputSchema: import_zod3.z.record(import_zod3.z.any()).optional(),
1262
+ payTo: EvmOrSvmAddress,
1263
+ maxTimeoutSeconds: import_zod3.z.number().int(),
1264
+ asset: mixedAddressOrSvmAddress,
1265
+ paymentType: import_zod3.z.enum(["eip3009", "permit", "permit2"]).optional(),
1266
+ extra: import_zod3.z.record(import_zod3.z.any()).optional()
1267
+ });
1268
+ var ExactEvmPayloadAuthorizationSchema = import_zod3.z.object({
1269
+ from: import_zod3.z.string().regex(EvmAddressRegex),
1270
+ to: import_zod3.z.string().regex(EvmAddressRegex),
1271
+ value: import_zod3.z.string().refine(isInteger).refine(hasMaxLength(EvmMaxAtomicUnits)),
1272
+ validAfter: import_zod3.z.string().refine(isInteger),
1273
+ validBefore: import_zod3.z.string().refine(isInteger),
1274
+ nonce: import_zod3.z.string().regex(HexEncoded64ByteRegex)
1275
+ });
1276
+ var PermitEvmPayloadAuthorizationSchema = import_zod3.z.object({
1277
+ owner: import_zod3.z.string().regex(EvmAddressRegex),
1278
+ spender: import_zod3.z.string().regex(EvmAddressRegex),
1279
+ value: import_zod3.z.string().refine(isInteger).refine(hasMaxLength(EvmMaxAtomicUnits)),
1280
+ deadline: import_zod3.z.string().refine(isInteger),
1281
+ nonce: import_zod3.z.string().refine(isInteger)
1282
+ });
1283
+ var Permit2EvmPayloadAuthorizationSchema = import_zod3.z.object({
1284
+ owner: import_zod3.z.string().regex(EvmAddressRegex),
1285
+ spender: import_zod3.z.string().regex(EvmAddressRegex),
1286
+ token: import_zod3.z.string().regex(EvmAddressRegex),
1287
+ amount: import_zod3.z.string().refine(isInteger).refine(hasMaxLength(EvmMaxAtomicUnits)),
1288
+ deadline: import_zod3.z.string().refine(isInteger),
1289
+ nonce: import_zod3.z.string().refine(isInteger)
1290
+ });
1291
+ var ExactEvmPayloadSchema = import_zod3.z.discriminatedUnion("authorizationType", [
1292
+ import_zod3.z.object({
1293
+ authorizationType: import_zod3.z.literal("eip3009"),
1294
+ signature: import_zod3.z.string().regex(EvmSignatureRegex),
1295
+ authorization: ExactEvmPayloadAuthorizationSchema
1296
+ }),
1297
+ import_zod3.z.object({
1298
+ authorizationType: import_zod3.z.literal("permit"),
1299
+ signature: import_zod3.z.string().regex(EvmSignatureRegex),
1300
+ authorization: PermitEvmPayloadAuthorizationSchema
1301
+ }),
1302
+ import_zod3.z.object({
1303
+ authorizationType: import_zod3.z.literal("permit2"),
1304
+ signature: import_zod3.z.string().regex(EvmSignatureRegex),
1305
+ authorization: Permit2EvmPayloadAuthorizationSchema
1306
+ })
1307
+ ]);
1308
+ var ExactSvmPayloadSchema = import_zod3.z.object({
1309
+ transaction: import_zod3.z.string().regex(Base64EncodedRegex)
1310
+ });
1311
+ var PaymentPayloadSchema = import_zod3.z.object({
1312
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1313
+ scheme: import_zod3.z.enum(schemes),
1314
+ network: NetworkSchema,
1315
+ payload: import_zod3.z.union([ExactEvmPayloadSchema, ExactSvmPayloadSchema])
1316
+ });
1317
+ var x402ResponseSchema = import_zod3.z.object({
1318
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1319
+ error: import_zod3.z.enum(ErrorReasons).optional(),
1320
+ accepts: import_zod3.z.array(PaymentRequirementsSchema).optional(),
1321
+ payer: import_zod3.z.string().regex(MixedAddressRegex).optional()
1322
+ });
1323
+ var HTTPVerbsSchema = import_zod3.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"]);
1324
+ var HTTPRequestStructureSchema = import_zod3.z.object({
1325
+ type: import_zod3.z.literal("http"),
1326
+ method: HTTPVerbsSchema,
1327
+ queryParams: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.string()).optional(),
1328
+ bodyType: import_zod3.z.enum(["json", "form-data", "multipart-form-data", "text", "binary"]).optional(),
1329
+ bodyFields: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.any()).optional(),
1330
+ headerFields: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.any()).optional()
1331
+ });
1332
+ var RequestStructureSchema = import_zod3.z.discriminatedUnion("type", [
1333
+ HTTPRequestStructureSchema
1334
+ // MCPRequestStructureSchema,
1335
+ // OpenAPIRequestStructureSchema,
1336
+ ]);
1337
+ var DiscoveredResourceSchema = import_zod3.z.object({
1338
+ resource: import_zod3.z.string(),
1339
+ type: import_zod3.z.enum(["http"]),
1340
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1341
+ accepts: import_zod3.z.array(PaymentRequirementsSchema),
1342
+ lastUpdated: import_zod3.z.date(),
1343
+ metadata: import_zod3.z.record(import_zod3.z.any()).optional()
1344
+ });
1345
+ var SettleRequestSchema = import_zod3.z.object({
1346
+ paymentPayload: PaymentPayloadSchema,
1347
+ paymentRequirements: PaymentRequirementsSchema
1348
+ });
1349
+ var VerifyRequestSchema = import_zod3.z.object({
1350
+ paymentPayload: PaymentPayloadSchema,
1351
+ paymentRequirements: PaymentRequirementsSchema
1352
+ });
1353
+ var VerifyResponseSchema = import_zod3.z.object({
1354
+ isValid: import_zod3.z.boolean(),
1355
+ invalidReason: import_zod3.z.enum(ErrorReasons).optional(),
1356
+ payer: EvmOrSvmAddress.optional()
1357
+ });
1358
+ var SettleResponseSchema = import_zod3.z.object({
1359
+ success: import_zod3.z.boolean(),
1360
+ errorReason: import_zod3.z.enum(ErrorReasons).optional(),
1361
+ payer: EvmOrSvmAddress.optional(),
1362
+ transaction: import_zod3.z.string().regex(MixedAddressRegex),
1363
+ network: NetworkSchema
1364
+ });
1365
+ var ListDiscoveryResourcesRequestSchema = import_zod3.z.object({
1366
+ type: import_zod3.z.string().optional(),
1367
+ limit: import_zod3.z.number().optional(),
1368
+ offset: import_zod3.z.number().optional()
1369
+ });
1370
+ var ListDiscoveryResourcesResponseSchema = import_zod3.z.object({
1371
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1372
+ items: import_zod3.z.array(DiscoveredResourceSchema),
1373
+ pagination: import_zod3.z.object({
1374
+ limit: import_zod3.z.number(),
1375
+ offset: import_zod3.z.number(),
1376
+ total: import_zod3.z.number()
1377
+ })
1378
+ });
1379
+ var SupportedPaymentKindSchema = import_zod3.z.object({
1380
+ x402Version: import_zod3.z.number().refine((val) => x402Versions.includes(val)),
1381
+ scheme: import_zod3.z.enum(schemes),
1382
+ network: NetworkSchema,
1383
+ extra: import_zod3.z.record(import_zod3.z.any()).optional()
1384
+ });
1385
+ var SupportedPaymentKindsResponseSchema = import_zod3.z.object({
1386
+ kinds: import_zod3.z.array(SupportedPaymentKindSchema)
1387
+ });
1388
+
1389
+ // src/types/verify/facilitator.ts
1390
+ var import_zod4 = require("zod");
1391
+ var facilitatorRequestSchema = import_zod4.z.object({
1392
+ paymentHeader: import_zod4.z.string(),
1393
+ paymentRequirements: PaymentRequirementsSchema
1394
+ });
1395
+
1396
+ // src/shared/evm/usdc.ts
1397
+ function getUsdcAddress(client) {
1398
+ return config[client.chain.id.toString()].usdcAddress;
1399
+ }
1400
+ function getUsdcChainConfigForChain(chainId) {
1401
+ return config[chainId.toString()];
1402
+ }
1403
+ var versionCache = /* @__PURE__ */ new Map();
1404
+ async function getVersion(client, tokenAddress) {
1405
+ const address = tokenAddress ?? getUsdcAddress(client);
1406
+ const cacheKey = `${client.chain.id}-${address.toLowerCase()}`;
1407
+ if (versionCache.has(cacheKey)) {
1408
+ return versionCache.get(cacheKey);
1409
+ }
1410
+ let version = "1";
1411
+ try {
1412
+ const eip712DomainABI = [
1413
+ {
1414
+ inputs: [],
1415
+ name: "eip712Domain",
1416
+ outputs: [
1417
+ { name: "fields", type: "bytes1" },
1418
+ { name: "name", type: "string" },
1419
+ { name: "version", type: "string" },
1420
+ { name: "chainId", type: "uint256" },
1421
+ { name: "verifyingContract", type: "address" },
1422
+ { name: "salt", type: "bytes32" },
1423
+ { name: "extensions", type: "uint256[]" }
1424
+ ],
1425
+ stateMutability: "view",
1426
+ type: "function"
1427
+ }
1428
+ ];
1429
+ const result = await client.readContract({
1430
+ address,
1431
+ abi: eip712DomainABI,
1432
+ functionName: "eip712Domain"
1433
+ });
1434
+ version = result[2];
1435
+ } catch {
1436
+ try {
1437
+ const result = await client.readContract({
1438
+ address,
1439
+ abi: usdcABI,
1440
+ functionName: "version"
1441
+ });
1442
+ version = result;
1443
+ } catch {
1444
+ console.warn(
1445
+ `Neither eip712Domain() nor version() available for token ${address}, using default: ${version}`
1446
+ );
1447
+ }
1448
+ }
1449
+ versionCache.set(cacheKey, version);
1450
+ return version;
1451
+ }
1452
+
1453
+ // src/shared/evm/erc20.ts
1454
+ async function getERC20Balance(client, erc20Address, address) {
1455
+ const balance = await client.readContract({
1456
+ address: erc20Address,
1457
+ abi: usdcABI,
1458
+ functionName: "balanceOf",
1459
+ args: [address]
1460
+ });
1461
+ return balance;
1462
+ }
1463
+ async function getERC20Allowance(client, erc20Address, owner, spender) {
1464
+ const allowance = await client.readContract({
1465
+ address: erc20Address,
1466
+ abi: usdcABI,
1467
+ functionName: "allowance",
1468
+ args: [owner, spender]
1469
+ });
1470
+ return allowance;
1471
+ }
1472
+
1473
+ // src/shared/svm/transaction.ts
1474
+ var import_kit3 = require("@solana/kit");
1475
+ var import_token = require("@solana-program/token");
1476
+ var import_token_2022 = require("@solana-program/token-2022");
1477
+ function decodeTransactionFromPayload(svmPayload) {
1478
+ try {
1479
+ const base64Encoder = (0, import_kit3.getBase64Encoder)();
1480
+ const transactionBytes = base64Encoder.encode(svmPayload.transaction);
1481
+ const transactionDecoder = (0, import_kit3.getTransactionDecoder)();
1482
+ return transactionDecoder.decode(transactionBytes);
1483
+ } catch (error) {
1484
+ console.error("error", error);
1485
+ throw new Error("invalid_exact_svm_payload_transaction");
1486
+ }
1487
+ }
1488
+ function getTokenPayerFromTransaction(transaction) {
1489
+ const compiled = (0, import_kit3.getCompiledTransactionMessageDecoder)().decode(
1490
+ transaction.messageBytes
1491
+ );
1492
+ const staticAccounts = compiled.staticAccounts ?? [];
1493
+ const instructions = compiled.instructions ?? [];
1494
+ for (const ix of instructions) {
1495
+ const programIndex = ix.programAddressIndex;
1496
+ const programAddress = staticAccounts[programIndex].toString();
1497
+ if (programAddress === import_token.TOKEN_PROGRAM_ADDRESS.toString() || programAddress === import_token_2022.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
1498
+ const accountIndices = ix.accountIndices ?? [];
1499
+ if (accountIndices.length >= 4) {
1500
+ const ownerIndex = accountIndices[3];
1501
+ const ownerAddress = staticAccounts[ownerIndex].toString();
1502
+ if (ownerAddress) return ownerAddress;
1503
+ }
1504
+ }
1505
+ }
1506
+ return "";
1507
+ }
1508
+ async function signAndSimulateTransaction(signer, transaction, rpc) {
1509
+ const signedTransaction = await (0, import_kit3.partiallySignTransaction)([signer.keyPair], transaction);
1510
+ const base64EncodedTransaction = (0, import_kit3.getBase64EncodedWireTransaction)(signedTransaction);
1511
+ const simulateTxConfig = {
1512
+ sigVerify: true,
1513
+ replaceRecentBlockhash: false,
1514
+ commitment: "confirmed",
1515
+ encoding: "base64",
1516
+ accounts: void 0,
1517
+ innerInstructions: void 0,
1518
+ minContextSlot: void 0
1519
+ };
1520
+ const simulateResult = await rpc.simulateTransaction(base64EncodedTransaction, simulateTxConfig).send();
1521
+ return simulateResult;
1522
+ }
1523
+
1524
+ // src/schemes/exact/evm/eip3009/sign.ts
1525
+ async function signAuthorization(walletClient, { from, to, value, validAfter, validBefore, nonce }, { asset, network, extra }) {
1526
+ const chainId = getNetworkId(network);
1527
+ const name = extra?.name;
1528
+ const version = extra?.version;
1529
+ const data = {
1530
+ types: authorizationTypes,
1531
+ domain: {
1532
+ name,
1533
+ version,
1534
+ chainId,
1535
+ verifyingContract: (0, import_viem2.getAddress)(asset)
1536
+ },
1537
+ primaryType: "TransferWithAuthorization",
1538
+ message: {
1539
+ from: (0, import_viem2.getAddress)(from),
1540
+ to: (0, import_viem2.getAddress)(to),
1541
+ value,
1542
+ validAfter,
1543
+ validBefore,
1544
+ nonce
1545
+ }
1546
+ };
1547
+ if (isSignerWallet(walletClient)) {
1548
+ const signature = await walletClient.signTypedData(data);
1549
+ return {
1550
+ signature
1551
+ };
1552
+ } else if (isAccount(walletClient) && walletClient.signTypedData) {
1553
+ const signature = await walletClient.signTypedData(data);
1554
+ return {
1555
+ signature
1556
+ };
1557
+ } else {
1558
+ throw new Error("Invalid wallet client provided does not support signTypedData");
1559
+ }
1560
+ }
1561
+ function createNonce() {
1562
+ const cryptoObj = typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.getRandomValues === "function" ? globalThis.crypto : (
1563
+ // Dynamic require is needed to support node.js
1564
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
1565
+ require("crypto").webcrypto
1566
+ );
1567
+ return (0, import_viem2.toHex)(cryptoObj.getRandomValues(new Uint8Array(32)));
1568
+ }
1569
+
1570
+ // src/schemes/exact/evm/utils/paymentUtils.ts
1571
+ function encodePayment(payment) {
1572
+ let safe;
1573
+ if (SupportedEVMNetworks.includes(payment.network)) {
1574
+ const evmPayload = payment.payload;
1575
+ let processedPayload;
1576
+ if (evmPayload.authorizationType === "eip3009") {
1577
+ processedPayload = {
1578
+ ...evmPayload,
1579
+ authorization: {
1580
+ ...evmPayload.authorization,
1581
+ validAfter: evmPayload.authorization.validAfter.toString(),
1582
+ validBefore: evmPayload.authorization.validBefore.toString()
1583
+ }
1584
+ };
1585
+ } else if (evmPayload.authorizationType === "permit") {
1586
+ processedPayload = {
1587
+ ...evmPayload,
1588
+ authorization: {
1589
+ ...evmPayload.authorization,
1590
+ deadline: evmPayload.authorization.deadline.toString(),
1591
+ nonce: evmPayload.authorization.nonce.toString()
1592
+ }
1593
+ };
1594
+ } else {
1595
+ processedPayload = {
1596
+ ...evmPayload,
1597
+ authorization: {
1598
+ ...evmPayload.authorization,
1599
+ deadline: evmPayload.authorization.deadline.toString(),
1600
+ nonce: evmPayload.authorization.nonce.toString()
1601
+ }
1602
+ };
1603
+ }
1604
+ safe = {
1605
+ ...payment,
1606
+ payload: processedPayload
1607
+ };
1608
+ return safeBase64Encode(JSON.stringify(safe));
1609
+ }
1610
+ if (SupportedSVMNetworks.includes(payment.network)) {
1611
+ safe = { ...payment, payload: payment.payload };
1612
+ return safeBase64Encode(JSON.stringify(safe));
1613
+ }
1614
+ throw new Error("Invalid network");
1615
+ }
1616
+
1617
+ // src/schemes/exact/evm/eip3009/client.ts
1618
+ function preparePaymentHeader(from, x402Version2, paymentRequirements) {
1619
+ const nonce = createNonce();
1620
+ const validAfter = BigInt(
1621
+ Math.floor(Date.now() / 1e3) - 600
1622
+ // 10 minutes before
1623
+ ).toString();
1624
+ const validBefore = BigInt(
1625
+ Math.floor(Date.now() / 1e3 + paymentRequirements.maxTimeoutSeconds)
1626
+ ).toString();
1627
+ return {
1628
+ x402Version: x402Version2,
1629
+ scheme: paymentRequirements.scheme,
1630
+ network: paymentRequirements.network,
1631
+ payload: {
1632
+ authorizationType: "eip3009",
1633
+ signature: void 0,
1634
+ authorization: {
1635
+ from,
1636
+ to: paymentRequirements.payTo,
1637
+ value: paymentRequirements.maxAmountRequired,
1638
+ validAfter: validAfter.toString(),
1639
+ validBefore: validBefore.toString(),
1640
+ nonce
1641
+ }
1642
+ }
1643
+ };
1644
+ }
1645
+ async function signPaymentHeader(client, paymentRequirements, unsignedPaymentHeader) {
1646
+ const { authorization } = unsignedPaymentHeader.payload;
1647
+ const { signature } = await signAuthorization(client, authorization, paymentRequirements);
1648
+ return {
1649
+ ...unsignedPaymentHeader,
1650
+ payload: {
1651
+ authorizationType: "eip3009",
1652
+ signature,
1653
+ authorization
1654
+ }
1655
+ };
1656
+ }
1657
+ async function createPayment(client, x402Version2, paymentRequirements) {
1658
+ const from = isSignerWallet(client) ? client.account.address : client.address;
1659
+ const unsignedPaymentHeader = preparePaymentHeader(from, x402Version2, paymentRequirements);
1660
+ return signPaymentHeader(client, paymentRequirements, unsignedPaymentHeader);
1661
+ }
1662
+ async function createPaymentHeader(client, x402Version2, paymentRequirements) {
1663
+ const payment = await createPayment(client, x402Version2, paymentRequirements);
1664
+ return encodePayment(payment);
1665
+ }
1666
+
1667
+ // src/schemes/exact/svm/client.ts
1668
+ var import_kit4 = require("@solana/kit");
1669
+ var import_token_20222 = require("@solana-program/token-2022");
1670
+ var import_token2 = require("@solana-program/token");
1671
+ var import_compute_budget = require("@solana-program/compute-budget");
1672
+ async function createPaymentHeader2(client, x402Version2, paymentRequirements, config2) {
1673
+ const paymentPayload = await createAndSignPayment(
1674
+ client,
1675
+ x402Version2,
1676
+ paymentRequirements,
1677
+ config2
1678
+ );
1679
+ return encodePayment(paymentPayload);
1680
+ }
1681
+ async function createAndSignPayment(client, x402Version2, paymentRequirements, config2) {
1682
+ const transactionMessage = await createTransferTransactionMessage(
1683
+ client,
1684
+ paymentRequirements,
1685
+ config2
1686
+ );
1687
+ const signedTransaction = await (0, import_kit4.partiallySignTransactionMessageWithSigners)(transactionMessage);
1688
+ const base64EncodedWireTransaction = (0, import_kit4.getBase64EncodedWireTransaction)(signedTransaction);
1689
+ return {
1690
+ scheme: paymentRequirements.scheme,
1691
+ network: paymentRequirements.network,
1692
+ x402Version: x402Version2,
1693
+ payload: {
1694
+ transaction: base64EncodedWireTransaction
1695
+ }
1696
+ };
1697
+ }
1698
+ async function createTransferTransactionMessage(client, paymentRequirements, config2) {
1699
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1700
+ const transferInstructions = await createAtaAndTransferInstructions(
1701
+ client,
1702
+ paymentRequirements,
1703
+ config2
1704
+ );
1705
+ const feePayer = paymentRequirements.extra?.feePayer;
1706
+ const txToSimulate = (0, import_kit4.pipe)(
1707
+ (0, import_kit4.createTransactionMessage)({ version: 0 }),
1708
+ (tx2) => (0, import_compute_budget.setTransactionMessageComputeUnitPrice)(1, tx2),
1709
+ // 1 microlamport priority fee
1710
+ (tx2) => (0, import_kit4.setTransactionMessageFeePayer)(feePayer, tx2),
1711
+ (tx2) => (0, import_kit4.appendTransactionMessageInstructions)(transferInstructions, tx2)
1712
+ );
1713
+ const estimateComputeUnitLimit = (0, import_compute_budget.estimateComputeUnitLimitFactory)({ rpc });
1714
+ const estimatedUnits = await estimateComputeUnitLimit(txToSimulate);
1715
+ const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
1716
+ const tx = (0, import_kit4.pipe)(
1717
+ txToSimulate,
1718
+ (tx2) => (0, import_kit4.prependTransactionMessageInstruction)(
1719
+ (0, import_compute_budget.getSetComputeUnitLimitInstruction)({ units: estimatedUnits }),
1720
+ tx2
1721
+ ),
1722
+ (tx2) => (0, import_kit4.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx2)
1723
+ );
1724
+ return tx;
1725
+ }
1726
+ async function createAtaAndTransferInstructions(client, paymentRequirements, config2) {
1727
+ const { asset } = paymentRequirements;
1728
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1729
+ const tokenMint = await (0, import_token_20222.fetchMint)(rpc, asset);
1730
+ const tokenProgramAddress = tokenMint.programAddress;
1731
+ if (tokenProgramAddress.toString() !== import_token2.TOKEN_PROGRAM_ADDRESS.toString() && tokenProgramAddress.toString() !== import_token_20222.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
1732
+ throw new Error("Asset was not created by a known token program");
1733
+ }
1734
+ const instructions = [];
1735
+ const createAtaIx = await createAtaInstructionOrUndefined(
1736
+ paymentRequirements,
1737
+ tokenProgramAddress,
1738
+ config2
1739
+ );
1740
+ if (createAtaIx) {
1741
+ instructions.push(createAtaIx);
1742
+ }
1743
+ const transferIx = await createTransferInstruction(
1744
+ client,
1745
+ paymentRequirements,
1746
+ tokenMint.data.decimals,
1747
+ tokenProgramAddress
1748
+ );
1749
+ instructions.push(transferIx);
1750
+ return instructions;
1751
+ }
1752
+ async function createAtaInstructionOrUndefined(paymentRequirements, tokenProgramAddress, config2) {
1753
+ const { asset, payTo, extra } = paymentRequirements;
1754
+ const feePayer = extra?.feePayer;
1755
+ if (!feePayer) {
1756
+ throw new Error(
1757
+ "feePayer is required in paymentRequirements.extra in order to set the facilitator as the fee payer for the create associated token account instruction"
1758
+ );
1759
+ }
1760
+ const [destinationATAAddress] = await (0, import_token_20222.findAssociatedTokenPda)({
1761
+ mint: asset,
1762
+ owner: payTo,
1763
+ tokenProgram: tokenProgramAddress
1764
+ });
1765
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1766
+ const maybeAccount = await (0, import_kit4.fetchEncodedAccount)(rpc, destinationATAAddress);
1767
+ if (!maybeAccount.exists) {
1768
+ return (0, import_token_20222.getCreateAssociatedTokenInstruction)({
1769
+ payer: paymentRequirements.extra?.feePayer,
1770
+ ata: destinationATAAddress,
1771
+ owner: payTo,
1772
+ mint: asset,
1773
+ tokenProgram: tokenProgramAddress
1774
+ });
1775
+ }
1776
+ return void 0;
1777
+ }
1778
+ async function createTransferInstruction(client, paymentRequirements, decimals, tokenProgramAddress) {
1779
+ const { asset, maxAmountRequired: amount, payTo } = paymentRequirements;
1780
+ const [sourceATA] = await (0, import_token_20222.findAssociatedTokenPda)({
1781
+ mint: asset,
1782
+ owner: client.address,
1783
+ tokenProgram: tokenProgramAddress
1784
+ });
1785
+ const [destinationATA] = await (0, import_token_20222.findAssociatedTokenPda)({
1786
+ mint: asset,
1787
+ owner: payTo,
1788
+ tokenProgram: tokenProgramAddress
1789
+ });
1790
+ return (0, import_token_20222.getTransferCheckedInstruction)(
1791
+ {
1792
+ source: sourceATA,
1793
+ mint: asset,
1794
+ destination: destinationATA,
1795
+ authority: client,
1796
+ amount: BigInt(amount),
1797
+ decimals
1798
+ },
1799
+ { programAddress: tokenProgramAddress }
1800
+ );
1801
+ }
1802
+
1803
+ // src/client/createPaymentHeader.ts
1804
+ async function createPaymentHeader3(client, x402Version2, paymentRequirements, config2) {
1805
+ if (paymentRequirements.scheme === "exact") {
1806
+ if (SupportedEVMNetworks.includes(paymentRequirements.network)) {
1807
+ const evmClient = isMultiNetworkSigner(client) ? client.evm : client;
1808
+ if (!isEvmSignerWallet(evmClient)) {
1809
+ throw new Error("Invalid evm wallet client provided");
1810
+ }
1811
+ return await createPaymentHeader(
1812
+ evmClient,
1813
+ x402Version2,
1814
+ paymentRequirements
1815
+ );
1816
+ }
1817
+ if (SupportedSVMNetworks.includes(paymentRequirements.network)) {
1818
+ const svmClient = isMultiNetworkSigner(client) ? client.svm : client;
1819
+ if (!isSvmSignerWallet(svmClient)) {
1820
+ throw new Error("Invalid svm wallet client provided");
1821
+ }
1822
+ return await createPaymentHeader2(
1823
+ svmClient,
1824
+ x402Version2,
1825
+ paymentRequirements,
1826
+ config2
1827
+ );
1828
+ }
1829
+ throw new Error("Unsupported network");
1830
+ }
1831
+ throw new Error("Unsupported scheme");
1832
+ }
1833
+
1834
+ // src/client/preparePaymentHeader.ts
1835
+ function preparePaymentHeader2(from, x402Version2, paymentRequirements) {
1836
+ if (paymentRequirements.scheme === "exact" && SupportedEVMNetworks.includes(paymentRequirements.network)) {
1837
+ return preparePaymentHeader(from, x402Version2, paymentRequirements);
1838
+ }
1839
+ throw new Error("Unsupported scheme");
1840
+ }
1841
+
1842
+ // src/client/selectPaymentRequirements.ts
1843
+ function selectPaymentRequirements(paymentRequirements, network, scheme) {
1844
+ paymentRequirements.sort((a, b) => {
1845
+ if (a.network === "base" && b.network !== "base") {
1846
+ return -1;
1847
+ }
1848
+ if (a.network !== "base" && b.network === "base") {
1849
+ return 1;
1850
+ }
1851
+ return 0;
1852
+ });
1853
+ const broadlyAcceptedPaymentRequirements = paymentRequirements.filter((requirement) => {
1854
+ const isExpectedScheme = !scheme || requirement.scheme === scheme;
1855
+ const isExpectedChain = !network || (Array.isArray(network) ? network.includes(requirement.network) : network == requirement.network);
1856
+ return isExpectedScheme && isExpectedChain;
1857
+ });
1858
+ const usdcRequirements = broadlyAcceptedPaymentRequirements.filter((requirement) => {
1859
+ return requirement.asset === getUsdcChainConfigForChain(getNetworkId(requirement.network))?.usdcAddress;
1860
+ });
1861
+ if (usdcRequirements.length > 0) {
1862
+ return usdcRequirements[0];
1863
+ }
1864
+ if (broadlyAcceptedPaymentRequirements.length > 0) {
1865
+ return broadlyAcceptedPaymentRequirements[0];
1866
+ }
1867
+ return paymentRequirements[0];
1868
+ }
1869
+
1870
+ // src/client/signPaymentHeader.ts
1871
+ async function signPaymentHeader2(client, paymentRequirements, unsignedPaymentHeader) {
1872
+ if (paymentRequirements.scheme === "exact" && SupportedEVMNetworks.includes(paymentRequirements.network)) {
1873
+ const evmClient = isMultiNetworkSigner(client) ? client.evm : client;
1874
+ if (!isEvmSignerWallet(evmClient)) {
1875
+ throw new Error("Invalid evm wallet client provided");
1876
+ }
1877
+ const signedPaymentHeader = await signPaymentHeader(evmClient, paymentRequirements, unsignedPaymentHeader);
1878
+ return encodePayment(signedPaymentHeader);
1879
+ }
1880
+ throw new Error("Unsupported scheme");
1881
+ }
1882
+
1883
+ // src/schemes/exact/evm/eip3009/facilitator.ts
1884
+ var import_viem3 = require("viem");
1885
+
1886
+ // src/schemes/exact/svm/facilitator/settle.ts
1887
+ var import_kit6 = require("@solana/kit");
1888
+ var import_transaction_confirmation = require("@solana/transaction-confirmation");
1889
+
1890
+ // src/schemes/exact/svm/facilitator/verify.ts
1891
+ var import_kit5 = require("@solana/kit");
1892
+ var import_compute_budget2 = require("@solana-program/compute-budget");
1893
+ var import_token_20223 = require("@solana-program/token-2022");
1894
+ var import_token3 = require("@solana-program/token");
1895
+ async function verify(signer, payload, paymentRequirements, config2) {
1896
+ try {
1897
+ verifySchemesAndNetworks(payload, paymentRequirements);
1898
+ const svmPayload = payload.payload;
1899
+ const decodedTransaction = decodeTransactionFromPayload(svmPayload);
1900
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1901
+ await transactionIntrospection(svmPayload, paymentRequirements, config2);
1902
+ const simulateResult = await signAndSimulateTransaction(signer, decodedTransaction, rpc);
1903
+ if (simulateResult.value?.err) {
1904
+ throw new Error(`invalid_exact_svm_payload_transaction_simulation_failed`);
1905
+ }
1906
+ return {
1907
+ isValid: true,
1908
+ invalidReason: void 0,
1909
+ payer: getTokenPayerFromTransaction(decodedTransaction)
1910
+ };
1911
+ } catch (error) {
1912
+ if (error instanceof Error) {
1913
+ if (ErrorReasons.includes(error.message)) {
1914
+ return {
1915
+ isValid: false,
1916
+ invalidReason: error.message,
1917
+ payer: (() => {
1918
+ try {
1919
+ const tx = decodeTransactionFromPayload(payload.payload);
1920
+ return getTokenPayerFromTransaction(tx);
1921
+ } catch {
1922
+ return void 0;
1923
+ }
1924
+ })()
1925
+ };
1926
+ }
1927
+ }
1928
+ console.error(error);
1929
+ return {
1930
+ isValid: false,
1931
+ invalidReason: "unexpected_verify_error",
1932
+ payer: (() => {
1933
+ try {
1934
+ const tx = decodeTransactionFromPayload(payload.payload);
1935
+ return getTokenPayerFromTransaction(tx);
1936
+ } catch {
1937
+ return void 0;
1938
+ }
1939
+ })()
1940
+ };
1941
+ }
1942
+ }
1943
+ function verifySchemesAndNetworks(payload, paymentRequirements) {
1944
+ if (payload.scheme !== SCHEME || paymentRequirements.scheme !== SCHEME) {
1945
+ throw new Error("unsupported_scheme");
1946
+ }
1947
+ if (payload.network !== paymentRequirements.network || !SupportedSVMNetworks.includes(paymentRequirements.network)) {
1948
+ throw new Error("invalid_network");
1949
+ }
1950
+ }
1951
+ async function transactionIntrospection(svmPayload, paymentRequirements, config2) {
1952
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
1953
+ const decodedTransaction = decodeTransactionFromPayload(svmPayload);
1954
+ const compiledTransactionMessage = (0, import_kit5.getCompiledTransactionMessageDecoder)().decode(
1955
+ decodedTransaction.messageBytes
1956
+ );
1957
+ const transactionMessage = (0, import_kit5.decompileTransactionMessage)(
1958
+ compiledTransactionMessage
1959
+ );
1960
+ await verifyTransactionInstructions(transactionMessage, paymentRequirements, rpc);
1961
+ }
1962
+ async function verifyTransactionInstructions(transactionMessage, paymentRequirements, rpc) {
1963
+ if (transactionMessage.instructions.length !== 3 && transactionMessage.instructions.length !== 4) {
1964
+ throw new Error(`invalid_exact_svm_payload_transaction_instructions_length`);
1965
+ }
1966
+ verifyComputeLimitInstruction(transactionMessage.instructions[0]);
1967
+ verifyComputePriceInstruction(transactionMessage.instructions[1]);
1968
+ if (transactionMessage.instructions.length === 3) {
1969
+ await verifyTransferInstruction(
1970
+ transactionMessage.instructions[2],
1971
+ paymentRequirements,
1972
+ {
1973
+ txHasCreateDestATAInstruction: false
1974
+ },
1975
+ rpc
1976
+ );
1977
+ } else {
1978
+ verifyCreateATAInstruction(transactionMessage.instructions[2], paymentRequirements);
1979
+ await verifyTransferInstruction(
1980
+ transactionMessage.instructions[3],
1981
+ paymentRequirements,
1982
+ {
1983
+ txHasCreateDestATAInstruction: true
1984
+ },
1985
+ rpc
1986
+ );
1987
+ }
1988
+ }
1989
+ function verifyComputeLimitInstruction(instruction) {
1990
+ try {
1991
+ if (instruction.programAddress.toString() !== import_compute_budget2.COMPUTE_BUDGET_PROGRAM_ADDRESS.toString() || instruction.data?.[0] !== 2) {
1992
+ throw new Error(
1993
+ `invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction`
1994
+ );
1995
+ }
1996
+ (0, import_compute_budget2.parseSetComputeUnitLimitInstruction)(
1997
+ instruction
1998
+ );
1999
+ } catch (error) {
2000
+ console.error(error);
2001
+ throw new Error(`invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction`);
2002
+ }
2003
+ }
2004
+ function verifyComputePriceInstruction(instruction) {
2005
+ if (instruction.programAddress.toString() !== import_compute_budget2.COMPUTE_BUDGET_PROGRAM_ADDRESS.toString() || instruction.data?.[0] !== 3) {
2006
+ throw new Error(`invalid_exact_svm_payload_transaction_instructions_compute_price_instruction`);
2007
+ }
2008
+ const parsedInstruction = (0, import_compute_budget2.parseSetComputeUnitPriceInstruction)(
2009
+ instruction
2010
+ );
2011
+ if (parsedInstruction.data.microLamports > 5 * 1e6) {
2012
+ throw new Error(
2013
+ `invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high`
2014
+ );
2015
+ }
2016
+ }
2017
+ function verifyCreateATAInstruction(instruction, paymentRequirements) {
2018
+ let createATAInstruction;
2019
+ try {
2020
+ (0, import_kit5.assertIsInstructionWithAccounts)(instruction);
2021
+ (0, import_kit5.assertIsInstructionWithData)(instruction);
2022
+ createATAInstruction = (0, import_token_20223.parseCreateAssociatedTokenInstruction)({
2023
+ ...instruction,
2024
+ data: new Uint8Array(instruction.data)
2025
+ });
2026
+ } catch (error) {
2027
+ console.error(error);
2028
+ throw new Error(`invalid_exact_svm_payload_transaction_create_ata_instruction`);
2029
+ }
2030
+ if (createATAInstruction.accounts.owner.address !== paymentRequirements.payTo) {
2031
+ throw new Error(`invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee`);
2032
+ }
2033
+ if (createATAInstruction.accounts.mint.address !== paymentRequirements.asset) {
2034
+ throw new Error(`invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset`);
2035
+ }
2036
+ }
2037
+ async function verifyTransferInstruction(instruction, paymentRequirements, { txHasCreateDestATAInstruction }, rpc) {
2038
+ const tokenInstruction = getValidatedTransferCheckedInstruction(instruction);
2039
+ await verifyTransferCheckedInstruction(
2040
+ tokenInstruction,
2041
+ paymentRequirements,
2042
+ {
2043
+ txHasCreateDestATAInstruction
2044
+ },
2045
+ rpc
2046
+ );
2047
+ }
2048
+ async function verifyTransferCheckedInstruction(parsedInstruction, paymentRequirements, { txHasCreateDestATAInstruction }, rpc) {
2049
+ const tokenProgramAddress = parsedInstruction.programAddress.toString() === import_token3.TOKEN_PROGRAM_ADDRESS.toString() ? import_token3.TOKEN_PROGRAM_ADDRESS : import_token_20223.TOKEN_2022_PROGRAM_ADDRESS;
2050
+ const payToATA = await (0, import_token_20223.findAssociatedTokenPda)({
2051
+ mint: paymentRequirements.asset,
2052
+ owner: paymentRequirements.payTo,
2053
+ tokenProgram: tokenProgramAddress
2054
+ });
2055
+ if (parsedInstruction.accounts.destination.address !== payToATA[0]) {
2056
+ throw new Error(`invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata`);
2057
+ }
2058
+ const addresses = [parsedInstruction.accounts.source.address, payToATA[0]];
2059
+ const maybeAccounts = await (0, import_kit5.fetchEncodedAccounts)(rpc, addresses);
2060
+ const missingAccounts = maybeAccounts.filter((a) => !a.exists);
2061
+ for (const missingAccount of missingAccounts) {
2062
+ if (missingAccount.address === parsedInstruction.accounts.source.address) {
2063
+ throw new Error(`invalid_exact_svm_payload_transaction_sender_ata_not_found`);
2064
+ }
2065
+ if (missingAccount.address === payToATA[0] && !txHasCreateDestATAInstruction) {
2066
+ throw new Error(`invalid_exact_svm_payload_transaction_receiver_ata_not_found`);
2067
+ }
2068
+ }
2069
+ const instructionAmount = parsedInstruction.data.amount;
2070
+ const paymentRequirementsAmount = BigInt(paymentRequirements.maxAmountRequired);
2071
+ if (instructionAmount !== paymentRequirementsAmount) {
2072
+ throw new Error(`invalid_exact_svm_payload_transaction_amount_mismatch`);
2073
+ }
2074
+ }
2075
+ function getValidatedTransferCheckedInstruction(instruction) {
2076
+ try {
2077
+ (0, import_kit5.assertIsInstructionWithData)(instruction);
2078
+ (0, import_kit5.assertIsInstructionWithAccounts)(instruction);
2079
+ } catch (error) {
2080
+ console.error(error);
2081
+ throw new Error(`invalid_exact_svm_payload_transaction_instructions`);
2082
+ }
2083
+ let tokenInstruction;
2084
+ if (instruction.programAddress.toString() === import_token3.TOKEN_PROGRAM_ADDRESS.toString()) {
2085
+ const identifiedInstruction = (0, import_token3.identifyTokenInstruction)(instruction);
2086
+ if (identifiedInstruction !== import_token3.TokenInstruction.TransferChecked) {
2087
+ throw new Error(
2088
+ `invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked`
2089
+ );
2090
+ }
2091
+ tokenInstruction = (0, import_token3.parseTransferCheckedInstruction)({
2092
+ ...instruction,
2093
+ data: new Uint8Array(instruction.data)
2094
+ });
2095
+ } else if (instruction.programAddress.toString() === import_token_20223.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
2096
+ const identifiedInstruction = (0, import_token_20223.identifyToken2022Instruction)(instruction);
2097
+ if (identifiedInstruction !== import_token_20223.Token2022Instruction.TransferChecked) {
2098
+ throw new Error(
2099
+ `invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked`
2100
+ );
2101
+ }
2102
+ tokenInstruction = (0, import_token_20223.parseTransferCheckedInstruction)({
2103
+ ...instruction,
2104
+ data: new Uint8Array(instruction.data)
2105
+ });
2106
+ } else {
2107
+ throw new Error(`invalid_exact_svm_payload_transaction_not_a_transfer_instruction`);
2108
+ }
2109
+ return tokenInstruction;
2110
+ }
2111
+
2112
+ // src/schemes/exact/svm/facilitator/settle.ts
2113
+ async function settle(signer, payload, paymentRequirements, config2) {
2114
+ const verifyResponse = await verify(signer, payload, paymentRequirements, config2);
2115
+ if (!verifyResponse.isValid) {
2116
+ return {
2117
+ success: false,
2118
+ errorReason: verifyResponse.invalidReason,
2119
+ network: payload.network,
2120
+ transaction: ""
2121
+ };
2122
+ }
2123
+ const svmPayload = payload.payload;
2124
+ const decodedTransaction = decodeTransactionFromPayload(svmPayload);
2125
+ const signedTransaction = await (0, import_kit6.signTransaction)([signer.keyPair], decodedTransaction);
2126
+ const payer = getTokenPayerFromTransaction(decodedTransaction);
2127
+ const rpc = getRpcClient(paymentRequirements.network, config2?.svmConfig?.rpcUrl);
2128
+ const rpcSubscriptions = getRpcSubscriptions(
2129
+ paymentRequirements.network,
2130
+ config2?.svmConfig?.rpcUrl
2131
+ );
2132
+ try {
2133
+ const { success, errorReason, signature } = await sendAndConfirmSignedTransaction(
2134
+ signedTransaction,
2135
+ rpc,
2136
+ rpcSubscriptions
2137
+ );
2138
+ return {
2139
+ success,
2140
+ errorReason,
2141
+ payer,
2142
+ transaction: signature,
2143
+ network: payload.network
2144
+ };
2145
+ } catch (error) {
2146
+ console.error("Unexpected error during transaction settlement:", error);
2147
+ return {
2148
+ success: false,
2149
+ errorReason: "unexpected_settle_error",
2150
+ network: payload.network,
2151
+ transaction: (0, import_kit6.getSignatureFromTransaction)(signedTransaction),
2152
+ payer
2153
+ };
2154
+ }
2155
+ }
2156
+ async function sendSignedTransaction(signedTransaction, rpc, sendTxConfig = {
2157
+ skipPreflight: true,
2158
+ encoding: "base64"
2159
+ }) {
2160
+ const base64EncodedTransaction = (0, import_kit6.getBase64EncodedWireTransaction)(signedTransaction);
2161
+ return await rpc.sendTransaction(base64EncodedTransaction, sendTxConfig).send();
2162
+ }
2163
+ async function confirmSignedTransaction(signedTransaction, rpc, rpcSubscriptions) {
2164
+ const signature = (0, import_kit6.getSignatureFromTransaction)(signedTransaction);
2165
+ const abortController = new AbortController();
2166
+ const timeout = setTimeout(() => {
2167
+ abortController.abort("Transaction confirmation timed out after 60 seconds");
2168
+ }, 6e4);
2169
+ try {
2170
+ const compiledTransactionMessage = (0, import_kit6.getCompiledTransactionMessageDecoder)().decode(
2171
+ signedTransaction.messageBytes
2172
+ );
2173
+ const decompiledTransactionMessage = await (0, import_kit6.decompileTransactionMessageFetchingLookupTables)(
2174
+ compiledTransactionMessage,
2175
+ rpc
2176
+ );
2177
+ (0, import_kit6.assertIsTransactionMessageWithBlockhashLifetime)(decompiledTransactionMessage);
2178
+ const signedTransactionWithBlockhashLifetime = {
2179
+ ...signedTransaction,
2180
+ lifetimeConstraint: decompiledTransactionMessage.lifetimeConstraint
2181
+ };
2182
+ const commitment = "confirmed";
2183
+ const getRecentSignatureConfirmationPromise = (0, import_transaction_confirmation.createRecentSignatureConfirmationPromiseFactory)({
2184
+ rpc,
2185
+ rpcSubscriptions
2186
+ });
2187
+ const getBlockHeightExceedencePromise = (0, import_transaction_confirmation.createBlockHeightExceedencePromiseFactory)({
2188
+ rpc,
2189
+ rpcSubscriptions
2190
+ });
2191
+ const config2 = {
2192
+ abortSignal: abortController.signal,
2193
+ commitment,
2194
+ getBlockHeightExceedencePromise,
2195
+ getRecentSignatureConfirmationPromise
2196
+ };
2197
+ await (0, import_transaction_confirmation.waitForRecentTransactionConfirmation)({
2198
+ ...config2,
2199
+ transaction: signedTransactionWithBlockhashLifetime
2200
+ });
2201
+ return {
2202
+ success: true,
2203
+ signature
2204
+ };
2205
+ } catch (error) {
2206
+ console.error(error);
2207
+ if ((0, import_kit6.isSolanaError)(error, import_kit6.SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) {
2208
+ return {
2209
+ success: false,
2210
+ errorReason: "settle_exact_svm_block_height_exceeded",
2211
+ signature
2212
+ };
2213
+ } else if (error instanceof DOMException && error.name === "AbortError") {
2214
+ return {
2215
+ success: false,
2216
+ errorReason: "settle_exact_svm_transaction_confirmation_timed_out",
2217
+ signature
2218
+ };
2219
+ } else {
2220
+ throw error;
2221
+ }
2222
+ } finally {
2223
+ clearTimeout(timeout);
2224
+ }
2225
+ }
2226
+ async function sendAndConfirmSignedTransaction(signedTransaction, rpc, rpcSubscriptions) {
2227
+ await sendSignedTransaction(signedTransaction, rpc);
2228
+ return await confirmSignedTransaction(signedTransaction, rpc, rpcSubscriptions);
2229
+ }
2230
+
2231
+ // src/schemes/exact/index.ts
2232
+ var SCHEME = "exact";
2233
+
2234
+ // src/schemes/exact/evm/eip3009/facilitator.ts
2235
+ async function verify2(client, payload, paymentRequirements) {
2236
+ const exactEvmPayload = payload.payload;
2237
+ if (exactEvmPayload.authorizationType !== "eip3009") {
2238
+ return {
2239
+ isValid: false,
2240
+ invalidReason: "unsupported_authorization_type",
2241
+ payer: ""
2242
+ };
2243
+ }
2244
+ if (payload.scheme !== SCHEME || paymentRequirements.scheme !== SCHEME) {
2245
+ return {
2246
+ isValid: false,
2247
+ invalidReason: `unsupported_scheme`,
2248
+ payer: exactEvmPayload.authorization.from
2249
+ };
2250
+ }
2251
+ let name;
2252
+ let chainId;
2253
+ let erc20Address;
2254
+ let version;
2255
+ try {
2256
+ chainId = getNetworkId(payload.network);
2257
+ name = paymentRequirements.extra?.name ?? config[chainId.toString()].usdcName;
2258
+ erc20Address = paymentRequirements.asset;
2259
+ version = paymentRequirements.extra?.version ?? await getVersion(client, erc20Address);
2260
+ } catch {
2261
+ return {
2262
+ isValid: false,
2263
+ invalidReason: `invalid_network`,
2264
+ payer: exactEvmPayload.authorization.from
2265
+ };
2266
+ }
2267
+ const permitTypedData = {
2268
+ types: authorizationTypes,
2269
+ primaryType: "TransferWithAuthorization",
2270
+ domain: {
2271
+ name,
2272
+ version,
2273
+ chainId,
2274
+ verifyingContract: erc20Address
2275
+ },
2276
+ message: {
2277
+ from: exactEvmPayload.authorization.from,
2278
+ to: exactEvmPayload.authorization.to,
2279
+ value: exactEvmPayload.authorization.value,
2280
+ validAfter: exactEvmPayload.authorization.validAfter,
2281
+ validBefore: exactEvmPayload.authorization.validBefore,
2282
+ nonce: exactEvmPayload.authorization.nonce
2283
+ }
2284
+ };
2285
+ const recoveredAddress = await client.verifyTypedData({
2286
+ address: exactEvmPayload.authorization.from,
2287
+ ...permitTypedData,
2288
+ signature: exactEvmPayload.signature
2289
+ });
2290
+ if (!recoveredAddress) {
2291
+ return {
2292
+ isValid: false,
2293
+ invalidReason: "invalid_exact_evm_payload_signature",
2294
+ //"Invalid permit signature",
2295
+ payer: exactEvmPayload.authorization.from
2296
+ };
2297
+ }
2298
+ if ((0, import_viem3.getAddress)(exactEvmPayload.authorization.to) !== (0, import_viem3.getAddress)(paymentRequirements.payTo)) {
2299
+ return {
2300
+ isValid: false,
2301
+ invalidReason: "invalid_exact_evm_payload_recipient_mismatch",
2302
+ payer: exactEvmPayload.authorization.from
2303
+ };
2304
+ }
2305
+ if (BigInt(exactEvmPayload.authorization.validBefore) < BigInt(Math.floor(Date.now() / 1e3) + 6)) {
2306
+ return {
2307
+ isValid: false,
2308
+ invalidReason: "invalid_exact_evm_payload_authorization_valid_before",
2309
+ //"Deadline on permit isn't far enough in the future",
2310
+ payer: exactEvmPayload.authorization.from
2311
+ };
2312
+ }
2313
+ if (BigInt(exactEvmPayload.authorization.validAfter) > BigInt(Math.floor(Date.now() / 1e3))) {
2314
+ return {
2315
+ isValid: false,
2316
+ invalidReason: "invalid_exact_evm_payload_authorization_valid_after",
2317
+ //"Deadline on permit is in the future",
2318
+ payer: exactEvmPayload.authorization.from
2319
+ };
2320
+ }
2321
+ const balance = await getERC20Balance(
2322
+ client,
2323
+ erc20Address,
2324
+ exactEvmPayload.authorization.from
2325
+ );
2326
+ if (balance < BigInt(paymentRequirements.maxAmountRequired)) {
2327
+ return {
2328
+ isValid: false,
2329
+ invalidReason: "insufficient_funds",
2330
+ //"Client does not have enough funds",
2331
+ payer: exactEvmPayload.authorization.from
2332
+ };
2333
+ }
2334
+ if (BigInt(exactEvmPayload.authorization.value) < BigInt(paymentRequirements.maxAmountRequired)) {
2335
+ return {
2336
+ isValid: false,
2337
+ invalidReason: "invalid_exact_evm_payload_authorization_value",
2338
+ //"Value in payload is not enough to cover paymentRequirements.maxAmountRequired",
2339
+ payer: exactEvmPayload.authorization.from
2340
+ };
2341
+ }
2342
+ return {
2343
+ isValid: true,
2344
+ invalidReason: void 0,
2345
+ payer: exactEvmPayload.authorization.from
2346
+ };
2347
+ }
2348
+ async function settle2(wallet, paymentPayload, paymentRequirements) {
2349
+ const payload = paymentPayload.payload;
2350
+ if (payload.authorizationType !== "eip3009") {
2351
+ return {
2352
+ success: false,
2353
+ errorReason: "unsupported_authorization_type",
2354
+ transaction: "",
2355
+ network: paymentPayload.network,
2356
+ payer: ""
2357
+ };
2358
+ }
2359
+ const valid = await verify2(wallet, paymentPayload, paymentRequirements);
2360
+ if (!valid.isValid) {
2361
+ return {
2362
+ success: false,
2363
+ network: paymentPayload.network,
2364
+ transaction: "",
2365
+ errorReason: valid.invalidReason ?? "invalid_scheme",
2366
+ //`Payment is no longer valid: ${valid.invalidReason}`,
2367
+ payer: payload.authorization.from
2368
+ };
2369
+ }
2370
+ const { signature } = (0, import_viem3.parseErc6492Signature)(payload.signature);
2371
+ const tx = await wallet.writeContract({
2372
+ address: paymentRequirements.asset,
2373
+ abi: usdcABI,
2374
+ functionName: "transferWithAuthorization",
2375
+ args: [
2376
+ payload.authorization.from,
2377
+ payload.authorization.to,
2378
+ BigInt(payload.authorization.value),
2379
+ BigInt(payload.authorization.validAfter),
2380
+ BigInt(payload.authorization.validBefore),
2381
+ payload.authorization.nonce,
2382
+ signature
2383
+ ],
2384
+ chain: wallet.chain
2385
+ });
2386
+ const receipt = await wallet.waitForTransactionReceipt({ hash: tx });
2387
+ if (receipt.status !== "success") {
2388
+ return {
2389
+ success: false,
2390
+ errorReason: "invalid_transaction_state",
2391
+ //`Transaction failed`,
2392
+ transaction: tx,
2393
+ network: paymentPayload.network,
2394
+ payer: payload.authorization.from
2395
+ };
2396
+ }
2397
+ return {
2398
+ success: true,
2399
+ transaction: tx,
2400
+ network: paymentPayload.network,
2401
+ payer: payload.authorization.from
2402
+ };
2403
+ }
2404
+
2405
+ // src/schemes/exact/evm/permit/facilitator.ts
2406
+ var import_viem5 = require("viem");
2407
+
2408
+ // src/schemes/exact/evm/permit/sign.ts
2409
+ var import_viem4 = require("viem");
2410
+ function splitSignature(signature) {
2411
+ const sig = signature.slice(2);
2412
+ const r = `0x${sig.slice(0, 64)}`;
2413
+ const s = `0x${sig.slice(64, 128)}`;
2414
+ let v = parseInt(sig.slice(128, 130), 16);
2415
+ if (v < 27) {
2416
+ v += 27;
2417
+ }
2418
+ return { v, r, s };
2419
+ }
2420
+
2421
+ // src/types/shared/evm/permitProxyABI.ts
2422
+ var permitProxyContractABI = [
2423
+ {
2424
+ inputs: [
2425
+ {
2426
+ internalType: "address",
2427
+ name: "token",
2428
+ type: "address"
2429
+ },
2430
+ {
2431
+ internalType: "address",
2432
+ name: "owner",
2433
+ type: "address"
2434
+ },
2435
+ {
2436
+ internalType: "address",
2437
+ name: "spender",
2438
+ type: "address"
2439
+ },
2440
+ {
2441
+ internalType: "uint256",
2442
+ name: "value",
2443
+ type: "uint256"
2444
+ },
2445
+ {
2446
+ internalType: "uint256",
2447
+ name: "deadline",
2448
+ type: "uint256"
2449
+ },
2450
+ {
2451
+ internalType: "uint8",
2452
+ name: "v",
2453
+ type: "uint8"
2454
+ },
2455
+ {
2456
+ internalType: "bytes32",
2457
+ name: "r",
2458
+ type: "bytes32"
2459
+ },
2460
+ {
2461
+ internalType: "bytes32",
2462
+ name: "s",
2463
+ type: "bytes32"
2464
+ },
2465
+ {
2466
+ internalType: "address",
2467
+ name: "to",
2468
+ type: "address"
2469
+ }
2470
+ ],
2471
+ name: "permitAndTransfer",
2472
+ outputs: [],
2473
+ stateMutability: "nonpayable",
2474
+ type: "function"
2475
+ }
2476
+ ];
2477
+
2478
+ // src/schemes/exact/evm/permit/facilitator.ts
2479
+ async function verify3(client, payload, paymentRequirements) {
2480
+ if (payload.payload.authorizationType !== "permit" || payload.scheme !== SCHEME || paymentRequirements.scheme !== SCHEME) {
2481
+ return {
2482
+ isValid: false,
2483
+ invalidReason: "unsupported_scheme"
2484
+ };
2485
+ }
2486
+ const permitPayload = payload.payload;
2487
+ const { owner, spender, value, deadline, nonce } = permitPayload.authorization;
2488
+ let name;
2489
+ let version;
2490
+ let erc20Address;
2491
+ let chainId;
2492
+ try {
2493
+ chainId = getNetworkId(payload.network);
2494
+ erc20Address = paymentRequirements.asset;
2495
+ name = paymentRequirements.extra?.name ?? await client.readContract({
2496
+ address: erc20Address,
2497
+ abi: erc20PermitABI,
2498
+ functionName: "name"
2499
+ });
2500
+ version = paymentRequirements.extra?.version ?? await getVersion(client, erc20Address);
2501
+ } catch {
2502
+ return {
2503
+ isValid: false,
2504
+ invalidReason: "invalid_network",
2505
+ payer: owner
2506
+ };
2507
+ }
2508
+ const permitTypedData = {
2509
+ types: permitTypes,
2510
+ domain: {
2511
+ name,
2512
+ version,
2513
+ chainId,
2514
+ verifyingContract: erc20Address
2515
+ },
2516
+ primaryType: "Permit",
2517
+ message: {
2518
+ owner: (0, import_viem5.getAddress)(owner),
2519
+ spender: (0, import_viem5.getAddress)(spender),
2520
+ value,
2521
+ nonce,
2522
+ deadline
2523
+ }
2524
+ };
2525
+ const recoveredAddress = await client.verifyTypedData({
2526
+ address: owner,
2527
+ ...permitTypedData,
2528
+ signature: permitPayload.signature
2529
+ });
2530
+ if (!recoveredAddress) {
2531
+ return {
2532
+ isValid: false,
2533
+ invalidReason: "invalid_permit_signature",
2534
+ payer: owner
2535
+ };
2536
+ }
2537
+ const now = Math.floor(Date.now() / 1e3);
2538
+ if (BigInt(deadline) < now) {
2539
+ return {
2540
+ isValid: false,
2541
+ invalidReason: "permit_expired",
2542
+ payer: owner
2543
+ };
2544
+ }
2545
+ if (paymentRequirements.extra?.proxyAddress) {
2546
+ if ((0, import_viem5.getAddress)(spender) !== (0, import_viem5.getAddress)(paymentRequirements.extra?.proxyAddress)) {
2547
+ return {
2548
+ isValid: false,
2549
+ invalidReason: "invalid_spender_address",
2550
+ payer: owner
2551
+ };
2552
+ }
2553
+ } else {
2554
+ if (client.account && (0, import_viem5.getAddress)(spender) !== (0, import_viem5.getAddress)(client.account.address)) {
2555
+ return {
2556
+ isValid: false,
2557
+ invalidReason: "invalid_spender_address",
2558
+ payer: owner
2559
+ };
2560
+ }
2561
+ }
2562
+ const balance = await getERC20Balance(client, erc20Address, owner);
2563
+ if (balance < BigInt(paymentRequirements.maxAmountRequired)) {
2564
+ return {
2565
+ isValid: false,
2566
+ invalidReason: "insufficient_funds",
2567
+ payer: owner
2568
+ };
2569
+ }
2570
+ if (BigInt(value) < BigInt(paymentRequirements.maxAmountRequired)) {
2571
+ return {
2572
+ isValid: false,
2573
+ invalidReason: "invalid_exact_evm_payload_authorization_value",
2574
+ payer: owner
2575
+ };
2576
+ }
2577
+ return {
2578
+ isValid: true,
2579
+ payer: owner
2580
+ };
2581
+ }
2582
+ async function settle3(wallet, paymentPayload, paymentRequirements) {
2583
+ const permitPayload = paymentPayload.payload;
2584
+ if (permitPayload.authorizationType !== "permit") {
2585
+ return {
2586
+ success: false,
2587
+ errorReason: "invalid_authorization_type",
2588
+ transaction: "",
2589
+ network: paymentPayload.network,
2590
+ payer: ""
2591
+ };
2592
+ }
2593
+ const valid = await verify3(wallet, paymentPayload, paymentRequirements);
2594
+ if (!valid.isValid) {
2595
+ return {
2596
+ success: false,
2597
+ network: paymentPayload.network,
2598
+ transaction: "",
2599
+ errorReason: valid.invalidReason ?? "invalid_payment",
2600
+ payer: permitPayload.authorization.owner
2601
+ };
2602
+ }
2603
+ const { owner, spender, value, deadline } = permitPayload.authorization;
2604
+ const { v, r, s } = splitSignature(permitPayload.signature);
2605
+ const tokenAddress = paymentRequirements.asset;
2606
+ const txNonce = await wallet.getTransactionCount({
2607
+ address: wallet.account.address
2608
+ });
2609
+ let transactionHash;
2610
+ if (paymentRequirements.extra?.proxyAddress) {
2611
+ transactionHash = await wallet.writeContract({
2612
+ address: paymentRequirements.extra.proxyAddress,
2613
+ abi: permitProxyContractABI,
2614
+ functionName: "permitAndTransfer",
2615
+ args: [
2616
+ tokenAddress,
2617
+ owner,
2618
+ spender,
2619
+ BigInt(value),
2620
+ BigInt(deadline),
2621
+ v,
2622
+ r,
2623
+ s,
2624
+ paymentRequirements.payTo
2625
+ ],
2626
+ chain: wallet.chain,
2627
+ nonce: txNonce
2628
+ });
2629
+ const receipt = await wallet.waitForTransactionReceipt({ hash: transactionHash });
2630
+ if (receipt.status !== "success") {
2631
+ return {
2632
+ success: false,
2633
+ errorReason: "transaction_failed",
2634
+ transaction: transactionHash,
2635
+ network: paymentPayload.network,
2636
+ payer: owner
2637
+ };
2638
+ }
2639
+ } else {
2640
+ const [permitTx, transferTx] = await Promise.all([
2641
+ // Call permit to approve the spender
2642
+ wallet.writeContract({
2643
+ address: tokenAddress,
2644
+ abi: erc20PermitABI,
2645
+ functionName: "permit",
2646
+ args: [owner, spender, BigInt(value), BigInt(deadline), v, r, s],
2647
+ chain: wallet.chain,
2648
+ nonce: txNonce
2649
+ }),
2650
+ // Call transferFrom to transfer tokens to payTo address
2651
+ wallet.writeContract({
2652
+ address: tokenAddress,
2653
+ abi: erc20PermitABI,
2654
+ functionName: "transferFrom",
2655
+ args: [owner, paymentRequirements.payTo, BigInt(value)],
2656
+ chain: wallet.chain,
2657
+ nonce: txNonce + 1
2658
+ })
2659
+ ]);
2660
+ const [, receipt] = await Promise.all([
2661
+ wallet.waitForTransactionReceipt({ hash: permitTx }),
2662
+ wallet.waitForTransactionReceipt({ hash: transferTx })
2663
+ ]);
2664
+ if (receipt.status !== "success") {
2665
+ return {
2666
+ success: false,
2667
+ errorReason: "transaction_failed",
2668
+ transaction: transferTx,
2669
+ network: paymentPayload.network,
2670
+ payer: owner
2671
+ };
2672
+ }
2673
+ transactionHash = transferTx;
2674
+ }
2675
+ return {
2676
+ success: true,
2677
+ transaction: transactionHash,
2678
+ network: paymentPayload.network,
2679
+ payer: owner
2680
+ };
2681
+ }
2682
+
2683
+ // src/schemes/exact/evm/permit2/facilitator.ts
2684
+ var import_viem6 = require("viem");
2685
+ async function verify4(client, payload, paymentRequirements) {
2686
+ if (payload.payload.authorizationType !== "permit2" || payload.scheme !== SCHEME || paymentRequirements.scheme !== SCHEME) {
2687
+ return {
2688
+ isValid: false,
2689
+ invalidReason: "unsupported_scheme"
2690
+ };
2691
+ }
2692
+ const permit2Payload = payload.payload;
2693
+ const { owner, spender, token, amount, deadline, nonce } = permit2Payload.authorization;
2694
+ const chainId = getNetworkId(payload.network);
2695
+ const tokenAddress = (0, import_viem6.getAddress)(token);
2696
+ const ownerAddress = (0, import_viem6.getAddress)(owner);
2697
+ const permit2TypedData = {
2698
+ types: permit2Types,
2699
+ domain: {
2700
+ name: "Permit2",
2701
+ chainId,
2702
+ verifyingContract: PERMIT2_ADDRESS
2703
+ },
2704
+ primaryType: "PermitTransferFrom",
2705
+ message: {
2706
+ permitted: {
2707
+ token: tokenAddress,
2708
+ amount
2709
+ },
2710
+ spender: (0, import_viem6.getAddress)(spender),
2711
+ nonce,
2712
+ deadline
2713
+ }
2714
+ };
2715
+ const recoveredAddress = await client.verifyTypedData({
2716
+ address: ownerAddress,
2717
+ ...permit2TypedData,
2718
+ signature: permit2Payload.signature
2719
+ });
2720
+ if (!recoveredAddress) {
2721
+ return {
2722
+ isValid: false,
2723
+ invalidReason: "invalid_permit2_signature",
2724
+ payer: owner
2725
+ };
2726
+ }
2727
+ const now = Math.floor(Date.now() / 1e3);
2728
+ if (BigInt(deadline) < now) {
2729
+ return {
2730
+ isValid: false,
2731
+ invalidReason: "permit2_expired",
2732
+ payer: owner
2733
+ };
2734
+ }
2735
+ if (client.account && (0, import_viem6.getAddress)(spender) !== (0, import_viem6.getAddress)(client.account.address)) {
2736
+ return {
2737
+ isValid: false,
2738
+ invalidReason: "invalid_spender_address",
2739
+ payer: owner
2740
+ };
2741
+ }
2742
+ if (tokenAddress.toLowerCase() !== paymentRequirements.asset.toLowerCase()) {
2743
+ return {
2744
+ isValid: false,
2745
+ invalidReason: "token_mismatch",
2746
+ payer: owner
2747
+ };
2748
+ }
2749
+ const allowance = await getERC20Allowance(client, tokenAddress, ownerAddress, PERMIT2_ADDRESS);
2750
+ if (allowance < BigInt(paymentRequirements.maxAmountRequired)) {
2751
+ return {
2752
+ isValid: false,
2753
+ invalidReason: "permit2_not_approved",
2754
+ payer: owner
2755
+ };
2756
+ }
2757
+ const balance = await getERC20Balance(client, tokenAddress, ownerAddress);
2758
+ if (balance < BigInt(paymentRequirements.maxAmountRequired)) {
2759
+ return {
2760
+ isValid: false,
2761
+ invalidReason: "insufficient_funds",
2762
+ payer: owner
2763
+ };
2764
+ }
2765
+ if (BigInt(amount) < BigInt(paymentRequirements.maxAmountRequired)) {
2766
+ return {
2767
+ isValid: false,
2768
+ invalidReason: "invalid_exact_evm_payload_authorization_value",
2769
+ payer: owner
2770
+ };
2771
+ }
2772
+ return {
2773
+ isValid: true,
2774
+ payer: owner
2775
+ };
2776
+ }
2777
+ async function settle4(wallet, paymentPayload, paymentRequirements) {
2778
+ const permit2Payload = paymentPayload.payload;
2779
+ if (permit2Payload.authorizationType !== "permit2") {
2780
+ return {
2781
+ success: false,
2782
+ errorReason: "invalid_authorization_type",
2783
+ transaction: "",
2784
+ network: paymentPayload.network,
2785
+ payer: ""
2786
+ };
2787
+ }
2788
+ const valid = await verify4(wallet, paymentPayload, paymentRequirements);
2789
+ if (!valid.isValid) {
2790
+ return {
2791
+ success: false,
2792
+ network: paymentPayload.network,
2793
+ transaction: "",
2794
+ errorReason: valid.invalidReason ?? "invalid_payment",
2795
+ payer: permit2Payload.authorization.owner
2796
+ };
2797
+ }
2798
+ const { owner, token, amount, deadline, nonce } = permit2Payload.authorization;
2799
+ const tokenAddress = (0, import_viem6.getAddress)(token);
2800
+ const ownerAddress = (0, import_viem6.getAddress)(owner);
2801
+ const tx = await wallet.writeContract({
2802
+ address: PERMIT2_ADDRESS,
2803
+ abi: permit2ABI,
2804
+ functionName: "permitTransferFrom",
2805
+ args: [
2806
+ {
2807
+ permitted: {
2808
+ token: tokenAddress,
2809
+ amount: BigInt(amount)
2810
+ },
2811
+ nonce: BigInt(nonce),
2812
+ deadline: BigInt(deadline)
2813
+ },
2814
+ {
2815
+ to: paymentRequirements.payTo,
2816
+ requestedAmount: BigInt(amount)
2817
+ },
2818
+ ownerAddress,
2819
+ permit2Payload.signature
2820
+ ],
2821
+ chain: wallet.chain
2822
+ });
2823
+ const receipt = await wallet.waitForTransactionReceipt({ hash: tx });
2824
+ if (receipt.status !== "success") {
2825
+ return {
2826
+ success: false,
2827
+ errorReason: "transaction_failed",
2828
+ transaction: tx,
2829
+ network: paymentPayload.network,
2830
+ payer: owner
2831
+ };
2832
+ }
2833
+ return {
2834
+ success: true,
2835
+ transaction: tx,
2836
+ network: paymentPayload.network,
2837
+ payer: owner
2838
+ };
2839
+ }
2840
+
2841
+ // src/schemes/exact/evm/permit2/sign.ts
2842
+ var import_viem7 = require("viem");
2843
+
2844
+ // src/schemes/exact/evm/index.ts
2845
+ async function verify5(client, payload, paymentRequirements) {
2846
+ const exactEvmPayload = payload.payload;
2847
+ switch (exactEvmPayload.authorizationType) {
2848
+ case "eip3009":
2849
+ return verify2(
2850
+ client,
2851
+ payload,
2852
+ paymentRequirements
2853
+ );
2854
+ case "permit":
2855
+ return verify3(client, payload, paymentRequirements);
2856
+ case "permit2":
2857
+ return verify4(
2858
+ client,
2859
+ payload,
2860
+ paymentRequirements
2861
+ );
2862
+ default:
2863
+ return {
2864
+ isValid: false,
2865
+ invalidReason: "unsupported_authorization_type",
2866
+ payer: ""
2867
+ };
2868
+ }
2869
+ }
2870
+ async function settle5(wallet, paymentPayload, paymentRequirements) {
2871
+ const payload = paymentPayload.payload;
2872
+ switch (payload.authorizationType) {
2873
+ case "eip3009":
2874
+ return settle2(
2875
+ wallet,
2876
+ paymentPayload,
2877
+ paymentRequirements
2878
+ );
2879
+ case "permit":
2880
+ return settle3(
2881
+ wallet,
2882
+ paymentPayload,
2883
+ paymentRequirements
2884
+ );
2885
+ case "permit2":
2886
+ return settle4(
2887
+ wallet,
2888
+ paymentPayload,
2889
+ paymentRequirements
2890
+ );
2891
+ default:
2892
+ return {
2893
+ success: false,
2894
+ errorReason: "unsupported_authorization_type",
2895
+ transaction: "",
2896
+ network: paymentPayload.network,
2897
+ payer: ""
2898
+ };
2899
+ }
2900
+ }
2901
+
2902
+ // src/facilitator/facilitator.ts
2903
+ async function verify6(client, payload, paymentRequirements, config2) {
2904
+ if (paymentRequirements.scheme === "exact") {
2905
+ if (SupportedEVMNetworks.includes(paymentRequirements.network)) {
2906
+ return verify5(
2907
+ client,
2908
+ payload,
2909
+ paymentRequirements
2910
+ );
2911
+ }
2912
+ if (SupportedSVMNetworks.includes(paymentRequirements.network)) {
2913
+ return await verify(client, payload, paymentRequirements, config2);
2914
+ }
2915
+ }
2916
+ let payer = "";
2917
+ if (SupportedEVMNetworks.includes(paymentRequirements.network)) {
2918
+ const evmPayload = payload.payload;
2919
+ if (evmPayload.authorizationType === "eip3009") {
2920
+ payer = evmPayload.authorization.from;
2921
+ } else if (evmPayload.authorizationType === "permit" || evmPayload.authorizationType === "permit2") {
2922
+ payer = evmPayload.authorization.owner;
2923
+ }
2924
+ }
2925
+ return {
2926
+ isValid: false,
2927
+ invalidReason: "invalid_scheme",
2928
+ payer
2929
+ };
2930
+ }
2931
+ async function settle6(client, payload, paymentRequirements, config2) {
2932
+ if (paymentRequirements.scheme === "exact") {
2933
+ if (SupportedEVMNetworks.includes(paymentRequirements.network)) {
2934
+ return await settle5(
2935
+ client,
2936
+ payload,
2937
+ paymentRequirements
2938
+ );
2939
+ }
2940
+ if (SupportedSVMNetworks.includes(paymentRequirements.network)) {
2941
+ return await settle(client, payload, paymentRequirements, config2);
2942
+ }
2943
+ }
2944
+ let payer = "";
2945
+ if (SupportedEVMNetworks.includes(paymentRequirements.network)) {
2946
+ const evmPayload = payload.payload;
2947
+ if (evmPayload.authorizationType === "eip3009") {
2948
+ payer = evmPayload.authorization.from;
2949
+ } else if (evmPayload.authorizationType === "permit" || evmPayload.authorizationType === "permit2") {
2950
+ payer = evmPayload.authorization.owner;
2951
+ }
2952
+ }
2953
+ return {
2954
+ success: false,
2955
+ errorReason: "invalid_scheme",
2956
+ transaction: "",
2957
+ network: paymentRequirements.network,
2958
+ payer
2959
+ };
2960
+ }
2961
+
2962
+ // src/index.ts
2963
+ var x402Version = 1;
2964
+ // Annotate the CommonJS export names for ESM import in node:
2965
+ 0 && (module.exports = {
2966
+ createPaymentHeader,
2967
+ preparePaymentHeader,
2968
+ selectPaymentRequirements,
2969
+ settle,
2970
+ signPaymentHeader,
2971
+ verify,
2972
+ x402Version
2973
+ });
2974
+ //# sourceMappingURL=index.js.map