sf-x402x 0.6.6-patch.3

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