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