@t402/evm 2.5.0 → 2.6.1

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 (39) hide show
  1. package/dist/cjs/index-fzI2FyBT.d.ts +122 -0
  2. package/dist/cjs/permit2/client/index.d.ts +81 -0
  3. package/dist/cjs/permit2/client/index.js +150 -0
  4. package/dist/cjs/permit2/client/index.js.map +1 -0
  5. package/dist/cjs/permit2/facilitator/index.d.ts +82 -0
  6. package/dist/cjs/permit2/facilitator/index.js +301 -0
  7. package/dist/cjs/permit2/facilitator/index.js.map +1 -0
  8. package/dist/cjs/permit2/index.d.ts +145 -0
  9. package/dist/cjs/permit2/index.js +1075 -0
  10. package/dist/cjs/permit2/index.js.map +1 -0
  11. package/dist/cjs/permit2/server/index.d.ts +3 -0
  12. package/dist/cjs/permit2/server/index.js +686 -0
  13. package/dist/cjs/permit2/server/index.js.map +1 -0
  14. package/dist/esm/chunk-3KHB6QTD.mjs +112 -0
  15. package/dist/esm/chunk-3KHB6QTD.mjs.map +1 -0
  16. package/dist/esm/{chunk-ZDGWVHD5.mjs → chunk-EEZNFYCW.mjs} +5 -5
  17. package/dist/esm/chunk-MMQSLAA2.mjs +190 -0
  18. package/dist/esm/chunk-MMQSLAA2.mjs.map +1 -0
  19. package/dist/esm/chunk-NIGKNI66.mjs +224 -0
  20. package/dist/esm/chunk-NIGKNI66.mjs.map +1 -0
  21. package/dist/esm/chunk-URG4HEYQ.mjs +74 -0
  22. package/dist/esm/chunk-URG4HEYQ.mjs.map +1 -0
  23. package/dist/esm/index-fzI2FyBT.d.mts +122 -0
  24. package/dist/esm/index.mjs +10 -10
  25. package/dist/esm/permit2/client/index.d.mts +81 -0
  26. package/dist/esm/permit2/client/index.mjs +11 -0
  27. package/dist/esm/permit2/client/index.mjs.map +1 -0
  28. package/dist/esm/permit2/facilitator/index.d.mts +82 -0
  29. package/dist/esm/permit2/facilitator/index.mjs +11 -0
  30. package/dist/esm/permit2/facilitator/index.mjs.map +1 -0
  31. package/dist/esm/permit2/index.d.mts +145 -0
  32. package/dist/esm/permit2/index.mjs +31 -0
  33. package/dist/esm/permit2/index.mjs.map +1 -0
  34. package/dist/esm/permit2/server/index.d.mts +3 -0
  35. package/dist/esm/permit2/server/index.mjs +12 -0
  36. package/dist/esm/permit2/server/index.mjs.map +1 -0
  37. package/dist/esm/upto/index.mjs +2 -2
  38. package/package.json +58 -11
  39. /package/dist/esm/{chunk-ZDGWVHD5.mjs.map → chunk-EEZNFYCW.mjs.map} +0 -0
@@ -0,0 +1,301 @@
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+
22
+ // src/permit2/facilitator/index.ts
23
+ var facilitator_exports = {};
24
+ __export(facilitator_exports, {
25
+ Permit2EvmScheme: () => Permit2EvmScheme,
26
+ registerPermit2EvmScheme: () => registerPermit2EvmScheme
27
+ });
28
+ module.exports = __toCommonJS(facilitator_exports);
29
+
30
+ // src/permit2/facilitator/scheme.ts
31
+ var import_viem = require("viem");
32
+
33
+ // src/permit2/constants.ts
34
+ var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
35
+ var permit2ABI = [
36
+ {
37
+ inputs: [
38
+ {
39
+ components: [
40
+ {
41
+ components: [
42
+ { name: "token", type: "address" },
43
+ { name: "amount", type: "uint256" }
44
+ ],
45
+ name: "permitted",
46
+ type: "tuple"
47
+ },
48
+ { name: "nonce", type: "uint256" },
49
+ { name: "deadline", type: "uint256" }
50
+ ],
51
+ name: "permit",
52
+ type: "tuple"
53
+ },
54
+ {
55
+ components: [
56
+ { name: "to", type: "address" },
57
+ { name: "requestedAmount", type: "uint256" }
58
+ ],
59
+ name: "transferDetails",
60
+ type: "tuple"
61
+ },
62
+ { name: "owner", type: "address" },
63
+ { name: "signature", type: "bytes" }
64
+ ],
65
+ name: "permitTransferFrom",
66
+ outputs: [],
67
+ stateMutability: "nonpayable",
68
+ type: "function"
69
+ },
70
+ {
71
+ inputs: [{ name: "account", type: "address" }],
72
+ name: "balanceOf",
73
+ outputs: [{ name: "", type: "uint256" }],
74
+ stateMutability: "view",
75
+ type: "function"
76
+ }
77
+ ];
78
+ var erc20BalanceABI = [
79
+ {
80
+ inputs: [{ name: "account", type: "address" }],
81
+ name: "balanceOf",
82
+ outputs: [{ name: "", type: "uint256" }],
83
+ stateMutability: "view",
84
+ type: "function"
85
+ }
86
+ ];
87
+
88
+ // src/permit2/facilitator/scheme.ts
89
+ var Permit2EvmScheme = class {
90
+ /**
91
+ * Creates a new Permit2 facilitator instance.
92
+ *
93
+ * @param signer - The facilitator EVM signer
94
+ */
95
+ constructor(signer) {
96
+ this.signer = signer;
97
+ __publicField(this, "scheme", "permit2");
98
+ __publicField(this, "caipFamily", "eip155:*");
99
+ }
100
+ /**
101
+ * Get mechanism-specific extra data for supported kinds.
102
+ *
103
+ * @param _ - The network identifier
104
+ * @returns Extra data including permit2 contract address
105
+ */
106
+ getExtra(_) {
107
+ return { permit2Address: PERMIT2_ADDRESS };
108
+ }
109
+ /**
110
+ * Get signer addresses for this facilitator.
111
+ *
112
+ * @param _ - The network identifier
113
+ * @returns Array of signer addresses
114
+ */
115
+ getSigners(_) {
116
+ return [...this.signer.getAddresses()];
117
+ }
118
+ /**
119
+ * Verify a Permit2 payment payload.
120
+ *
121
+ * @param payload - The payment payload to verify
122
+ * @param requirements - The payment requirements
123
+ * @returns Verification result
124
+ */
125
+ async verify(payload, requirements) {
126
+ const permit2Payload = payload.payload;
127
+ if (!permit2Payload?.permit?.permitted?.token || !permit2Payload?.owner) {
128
+ return {
129
+ isValid: false,
130
+ invalidReason: "invalid_payload_structure",
131
+ payer: void 0
132
+ };
133
+ }
134
+ if (payload.accepted.scheme !== "permit2" || requirements.scheme !== "permit2") {
135
+ return {
136
+ isValid: false,
137
+ invalidReason: "unsupported_scheme",
138
+ payer: permit2Payload.owner
139
+ };
140
+ }
141
+ if (payload.accepted.network !== requirements.network) {
142
+ return {
143
+ isValid: false,
144
+ invalidReason: "network_mismatch",
145
+ payer: permit2Payload.owner
146
+ };
147
+ }
148
+ if ((0, import_viem.getAddress)(permit2Payload.permit.permitted.token) !== (0, import_viem.getAddress)(requirements.asset)) {
149
+ return {
150
+ isValid: false,
151
+ invalidReason: "token_mismatch",
152
+ payer: permit2Payload.owner
153
+ };
154
+ }
155
+ if ((0, import_viem.getAddress)(permit2Payload.transferDetails.to) !== (0, import_viem.getAddress)(requirements.payTo)) {
156
+ return {
157
+ isValid: false,
158
+ invalidReason: "recipient_mismatch",
159
+ payer: permit2Payload.owner
160
+ };
161
+ }
162
+ const now = Math.floor(Date.now() / 1e3);
163
+ if (BigInt(permit2Payload.permit.deadline) < BigInt(now + 6)) {
164
+ return {
165
+ isValid: false,
166
+ invalidReason: "permit_expired",
167
+ payer: permit2Payload.owner
168
+ };
169
+ }
170
+ if (BigInt(permit2Payload.permit.permitted.amount) < BigInt(requirements.amount)) {
171
+ return {
172
+ isValid: false,
173
+ invalidReason: "insufficient_permitted_amount",
174
+ payer: permit2Payload.owner
175
+ };
176
+ }
177
+ if (BigInt(permit2Payload.transferDetails.requestedAmount) < BigInt(requirements.amount)) {
178
+ return {
179
+ isValid: false,
180
+ invalidReason: "insufficient_requested_amount",
181
+ payer: permit2Payload.owner
182
+ };
183
+ }
184
+ try {
185
+ const balance = await this.signer.readContract({
186
+ address: (0, import_viem.getAddress)(requirements.asset),
187
+ abi: erc20BalanceABI,
188
+ functionName: "balanceOf",
189
+ args: [(0, import_viem.getAddress)(permit2Payload.owner)]
190
+ });
191
+ if (BigInt(balance) < BigInt(requirements.amount)) {
192
+ return {
193
+ isValid: false,
194
+ invalidReason: "insufficient_funds",
195
+ payer: permit2Payload.owner
196
+ };
197
+ }
198
+ } catch (error) {
199
+ const errorMessage = error instanceof Error ? error.message : String(error);
200
+ return {
201
+ isValid: false,
202
+ invalidReason: `balance_check_failed: ${errorMessage}`,
203
+ payer: permit2Payload.owner
204
+ };
205
+ }
206
+ return {
207
+ isValid: true,
208
+ invalidReason: void 0,
209
+ payer: permit2Payload.owner
210
+ };
211
+ }
212
+ /**
213
+ * Settle a Permit2 payment by executing permitTransferFrom.
214
+ *
215
+ * @param payload - The payment payload
216
+ * @param requirements - The payment requirements
217
+ * @returns Settlement result
218
+ */
219
+ async settle(payload, requirements) {
220
+ const permit2Payload = payload.payload;
221
+ if (!permit2Payload?.permit?.permitted?.token || !permit2Payload?.owner) {
222
+ return {
223
+ success: false,
224
+ network: payload.accepted.network,
225
+ transaction: "",
226
+ errorReason: "invalid_payload_structure",
227
+ payer: void 0
228
+ };
229
+ }
230
+ const valid = await this.verify(payload, requirements);
231
+ if (!valid.isValid) {
232
+ return {
233
+ success: false,
234
+ network: payload.accepted.network,
235
+ transaction: "",
236
+ errorReason: valid.invalidReason ?? "invalid_scheme",
237
+ payer: permit2Payload.owner
238
+ };
239
+ }
240
+ try {
241
+ const tx = await this.signer.writeContract({
242
+ address: PERMIT2_ADDRESS,
243
+ abi: permit2ABI,
244
+ functionName: "permitTransferFrom",
245
+ args: [
246
+ {
247
+ permitted: {
248
+ token: (0, import_viem.getAddress)(permit2Payload.permit.permitted.token),
249
+ amount: BigInt(permit2Payload.permit.permitted.amount)
250
+ },
251
+ nonce: BigInt(permit2Payload.permit.nonce),
252
+ deadline: BigInt(permit2Payload.permit.deadline)
253
+ },
254
+ {
255
+ to: (0, import_viem.getAddress)(permit2Payload.transferDetails.to),
256
+ requestedAmount: BigInt(permit2Payload.transferDetails.requestedAmount)
257
+ },
258
+ (0, import_viem.getAddress)(permit2Payload.owner),
259
+ permit2Payload.signature
260
+ ]
261
+ });
262
+ const receipt = await this.signer.waitForTransactionReceipt({ hash: tx });
263
+ if (receipt.status !== "success") {
264
+ return {
265
+ success: false,
266
+ errorReason: "invalid_transaction_state",
267
+ transaction: tx,
268
+ network: payload.accepted.network,
269
+ payer: permit2Payload.owner
270
+ };
271
+ }
272
+ return {
273
+ success: true,
274
+ transaction: tx,
275
+ network: payload.accepted.network,
276
+ payer: permit2Payload.owner
277
+ };
278
+ } catch (error) {
279
+ console.error("Failed to settle Permit2 transaction:", error);
280
+ return {
281
+ success: false,
282
+ errorReason: "transaction_failed",
283
+ transaction: "",
284
+ network: payload.accepted.network,
285
+ payer: permit2Payload.owner
286
+ };
287
+ }
288
+ }
289
+ };
290
+
291
+ // src/permit2/facilitator/register.ts
292
+ function registerPermit2EvmScheme(facilitator, config) {
293
+ facilitator.register(config.networks, new Permit2EvmScheme(config.signer));
294
+ return facilitator;
295
+ }
296
+ // Annotate the CommonJS export names for ESM import in node:
297
+ 0 && (module.exports = {
298
+ Permit2EvmScheme,
299
+ registerPermit2EvmScheme
300
+ });
301
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/permit2/facilitator/index.ts","../../../../src/permit2/facilitator/scheme.ts","../../../../src/permit2/constants.ts","../../../../src/permit2/facilitator/register.ts"],"sourcesContent":["export { Permit2EvmScheme } from \"./scheme\";\nexport type { Permit2EvmSchemeConfig } from \"./scheme\";\nexport { registerPermit2EvmScheme } from \"./register\";\nexport type { Permit2EvmFacilitatorConfig } from \"./register\";\n","import {\n PaymentPayload,\n PaymentRequirements,\n SchemeNetworkFacilitator,\n SettleResponse,\n VerifyResponse,\n} from \"@t402/core/types\";\nimport { getAddress } from \"viem\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { Permit2PayloadV2 } from \"../types\";\nimport { PERMIT2_ADDRESS, permit2ABI, erc20BalanceABI } from \"../constants\";\n\n/**\n * Configuration for Permit2 EVM facilitator\n */\nexport interface Permit2EvmSchemeConfig {\n [key: string]: unknown;\n}\n\n/**\n * EVM facilitator implementation for the Permit2 payment scheme.\n *\n * Verifies Permit2 signatures and settles payments by calling\n * permitTransferFrom on the Permit2 contract.\n */\nexport class Permit2EvmScheme implements SchemeNetworkFacilitator {\n readonly scheme = \"permit2\";\n readonly caipFamily = \"eip155:*\";\n\n /**\n * Creates a new Permit2 facilitator instance.\n *\n * @param signer - The facilitator EVM signer\n */\n constructor(private readonly signer: FacilitatorEvmSigner) {}\n\n /**\n * Get mechanism-specific extra data for supported kinds.\n *\n * @param _ - The network identifier\n * @returns Extra data including permit2 contract address\n */\n getExtra(_: string): Record<string, unknown> | undefined {\n return { permit2Address: PERMIT2_ADDRESS };\n }\n\n /**\n * Get signer addresses for this facilitator.\n *\n * @param _ - The network identifier\n * @returns Array of signer addresses\n */\n getSigners(_: string): string[] {\n return [...this.signer.getAddresses()];\n }\n\n /**\n * Verify a Permit2 payment payload.\n *\n * @param payload - The payment payload to verify\n * @param requirements - The payment requirements\n * @returns Verification result\n */\n async verify(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n const permit2Payload = payload.payload as Permit2PayloadV2 | undefined;\n\n // Validate payload structure\n if (!permit2Payload?.permit?.permitted?.token || !permit2Payload?.owner) {\n return {\n isValid: false,\n invalidReason: \"invalid_payload_structure\",\n payer: undefined,\n };\n }\n\n // Verify scheme matches\n if (payload.accepted.scheme !== \"permit2\" || requirements.scheme !== \"permit2\") {\n return {\n isValid: false,\n invalidReason: \"unsupported_scheme\",\n payer: permit2Payload.owner,\n };\n }\n\n // Verify network matches\n if (payload.accepted.network !== requirements.network) {\n return {\n isValid: false,\n invalidReason: \"network_mismatch\",\n payer: permit2Payload.owner,\n };\n }\n\n // Verify token matches\n if (getAddress(permit2Payload.permit.permitted.token) !== getAddress(requirements.asset)) {\n return {\n isValid: false,\n invalidReason: \"token_mismatch\",\n payer: permit2Payload.owner,\n };\n }\n\n // Verify recipient matches\n if (getAddress(permit2Payload.transferDetails.to) !== getAddress(requirements.payTo)) {\n return {\n isValid: false,\n invalidReason: \"recipient_mismatch\",\n payer: permit2Payload.owner,\n };\n }\n\n // Verify deadline is in the future\n const now = Math.floor(Date.now() / 1000);\n if (BigInt(permit2Payload.permit.deadline) < BigInt(now + 6)) {\n return {\n isValid: false,\n invalidReason: \"permit_expired\",\n payer: permit2Payload.owner,\n };\n }\n\n // Verify amount is sufficient\n if (BigInt(permit2Payload.permit.permitted.amount) < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"insufficient_permitted_amount\",\n payer: permit2Payload.owner,\n };\n }\n\n if (BigInt(permit2Payload.transferDetails.requestedAmount) < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"insufficient_requested_amount\",\n payer: permit2Payload.owner,\n };\n }\n\n // Check balance\n try {\n const balance = (await this.signer.readContract({\n address: getAddress(requirements.asset),\n abi: erc20BalanceABI,\n functionName: \"balanceOf\",\n args: [getAddress(permit2Payload.owner)],\n })) as bigint;\n\n if (BigInt(balance) < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"insufficient_funds\",\n payer: permit2Payload.owner,\n };\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n return {\n isValid: false,\n invalidReason: `balance_check_failed: ${errorMessage}`,\n payer: permit2Payload.owner,\n };\n }\n\n return {\n isValid: true,\n invalidReason: undefined,\n payer: permit2Payload.owner,\n };\n }\n\n /**\n * Settle a Permit2 payment by executing permitTransferFrom.\n *\n * @param payload - The payment payload\n * @param requirements - The payment requirements\n * @returns Settlement result\n */\n async settle(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<SettleResponse> {\n const permit2Payload = payload.payload as Permit2PayloadV2 | undefined;\n\n if (!permit2Payload?.permit?.permitted?.token || !permit2Payload?.owner) {\n return {\n success: false,\n network: payload.accepted.network,\n transaction: \"\",\n errorReason: \"invalid_payload_structure\",\n payer: undefined,\n };\n }\n\n // Re-verify before settling\n const valid = await this.verify(payload, requirements);\n if (!valid.isValid) {\n return {\n success: false,\n network: payload.accepted.network,\n transaction: \"\",\n errorReason: valid.invalidReason ?? \"invalid_scheme\",\n payer: permit2Payload.owner,\n };\n }\n\n try {\n // Call permitTransferFrom on the Permit2 contract\n const tx = await this.signer.writeContract({\n address: PERMIT2_ADDRESS,\n abi: permit2ABI,\n functionName: \"permitTransferFrom\",\n args: [\n {\n permitted: {\n token: getAddress(permit2Payload.permit.permitted.token),\n amount: BigInt(permit2Payload.permit.permitted.amount),\n },\n nonce: BigInt(permit2Payload.permit.nonce),\n deadline: BigInt(permit2Payload.permit.deadline),\n },\n {\n to: getAddress(permit2Payload.transferDetails.to),\n requestedAmount: BigInt(permit2Payload.transferDetails.requestedAmount),\n },\n getAddress(permit2Payload.owner),\n permit2Payload.signature,\n ],\n });\n\n // Wait for transaction confirmation\n const receipt = await this.signer.waitForTransactionReceipt({ hash: tx });\n\n if (receipt.status !== \"success\") {\n return {\n success: false,\n errorReason: \"invalid_transaction_state\",\n transaction: tx,\n network: payload.accepted.network,\n payer: permit2Payload.owner,\n };\n }\n\n return {\n success: true,\n transaction: tx,\n network: payload.accepted.network,\n payer: permit2Payload.owner,\n };\n } catch (error) {\n console.error(\"Failed to settle Permit2 transaction:\", error);\n return {\n success: false,\n errorReason: \"transaction_failed\",\n transaction: \"\",\n network: payload.accepted.network,\n payer: permit2Payload.owner,\n };\n }\n }\n}\n","/**\n * Permit2 Constants\n *\n * Uniswap Permit2 contract addresses, type hashes, and ABI fragments.\n */\n\n/** Canonical Permit2 contract address (same on all EVM chains) */\nexport const PERMIT2_ADDRESS = \"0x000000000022D473030F116dDEE9F6B43aC78BA3\" as const;\n\n/** EIP-712 type definitions for Permit2 SignatureTransfer */\nexport const permit2Types = {\n PermitTransferFrom: [\n { name: \"permitted\", type: \"TokenPermissions\" },\n { name: \"spender\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n TokenPermissions: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n} as const;\n\n/** Permit2 ABI for permitTransferFrom */\nexport const permit2ABI = [\n {\n inputs: [\n {\n components: [\n {\n components: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n name: \"permitted\",\n type: \"tuple\",\n },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n name: \"permit\",\n type: \"tuple\",\n },\n {\n components: [\n { name: \"to\", type: \"address\" },\n { name: \"requestedAmount\", type: \"uint256\" },\n ],\n name: \"transferDetails\",\n type: \"tuple\",\n },\n { name: \"owner\", type: \"address\" },\n { name: \"signature\", type: \"bytes\" },\n ],\n name: \"permitTransferFrom\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ name: \"account\", type: \"address\" }],\n name: \"balanceOf\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n] as const;\n\n/** ERC20 balanceOf ABI for balance checks */\nexport const erc20BalanceABI = [\n {\n inputs: [{ name: \"account\", type: \"address\" }],\n name: \"balanceOf\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n] as const;\n","import { t402Facilitator } from \"@t402/core/facilitator\";\nimport { Network } from \"@t402/core/types\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { Permit2EvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering Permit2 schemes to an t402Facilitator\n */\nexport interface Permit2EvmFacilitatorConfig {\n /**\n * The EVM signer for facilitator operations (verify and settle)\n */\n signer: FacilitatorEvmSigner;\n\n /**\n * Networks to register (single network or array of networks)\n * Examples: \"eip155:84532\", [\"eip155:84532\", \"eip155:1\"]\n */\n networks: Network | Network[];\n}\n\n/**\n * Registers Permit2 EVM payment schemes to an t402Facilitator instance.\n *\n * @param facilitator - The t402Facilitator instance to register schemes to\n * @param config - Configuration for Permit2 EVM facilitator registration\n * @returns The facilitator instance for chaining\n */\nexport function registerPermit2EvmScheme(\n facilitator: t402Facilitator,\n config: Permit2EvmFacilitatorConfig,\n): t402Facilitator {\n facilitator.register(config.networks, new Permit2EvmScheme(config.signer));\n\n return facilitator;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,kBAA2B;;;ACApB,IAAM,kBAAkB;AAiBxB,IAAM,aAAa;AAAA,EACxB;AAAA,IACE,QAAQ;AAAA,MACN;AAAA,QACE,YAAY;AAAA,UACV;AAAA,YACE,YAAY;AAAA,cACV,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,cACjC,EAAE,MAAM,UAAU,MAAM,UAAU;AAAA,YACpC;AAAA,YACA,MAAM;AAAA,YACN,MAAM;AAAA,UACR;AAAA,UACA,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,UACjC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,QACtC;AAAA,QACA,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,MACA;AAAA,QACE,YAAY;AAAA,UACV,EAAE,MAAM,MAAM,MAAM,UAAU;AAAA,UAC9B,EAAE,MAAM,mBAAmB,MAAM,UAAU;AAAA,QAC7C;AAAA,QACA,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,MACA,EAAE,M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ACT,WAAO,wBAAW,eAAe,OAAO,UAAU,KAAK;AAAA,cACvD,QAAQ,OAAO,eAAe,OAAO,UAAU,MAAM;AAAA,YACvD;AAAA,YACA,OAAO,OAAO,eAAe,OAAO,KAAK;AAAA,YACzC,UAAU,OAAO,eAAe,OAAO,QAAQ;AAAA,UACjD;AAAA,UACA;AAAA,YACE,QAAI,wBAAW,eAAe,gBAAgB,EAAE;AAAA,YAChD,iBAAiB,OAAO,eAAe,gBAAgB,eAAe;AAAA,UACxE;AAAA,cACA,wBAAW,eAAe,KAAK;AAAA,UAC/B,eAAe;AAAA,QACjB;AAAA,MACF,CAAC;AAGD,YAAM,UAAU,MAAM,KAAK,OAAO,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAExE,UAAI,QAAQ,WAAW,WAAW;AAChC,eAAO;AAAA,UACL,SAAS;AAAA,UACT,aAAa;AAAA,UACb,aAAa;AAAA,UACb,SAAS,QAAQ,SAAS;AAAA,UAC1B,OAAO,eAAe;AAAA,QACxB;AAAA,MACF;AAEA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,aAAa;AAAA,QACb,SAAS,QAAQ,SAAS;AAAA,QAC1B,OAAO,eAAe;AAAA,MACxB;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,yCAAyC,KAAK;AAC5D,aAAO;AAAA,QACL,SAAS;AAAA,QACT,aAAa;AAAA,QACb,aAAa;AAAA,QACb,SAAS,QAAQ,SAAS;AAAA,QAC1B,OAAO,eAAe;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF;;;AE1OO,SAAS,yBACd,aACA,QACiB;AACjB,cAAY,SAAS,OAAO,UAAU,IAAI,iBAAiB,OAAO,MAAM,CAAC;AAEzE,SAAO;AACT;","names":[]}
@@ -0,0 +1,145 @@
1
+ export { Permit2EvmClientConfig, Permit2EvmScheme as Permit2EvmClientScheme, registerPermit2EvmScheme as registerPermit2EvmClientScheme } from './client/index.js';
2
+ export { P as Permit2EvmResourceServerConfig, a as Permit2EvmServerScheme, b as Permit2EvmServerSchemeConfig, r as registerPermit2EvmServerScheme } from '../index-fzI2FyBT.js';
3
+ export { Permit2EvmFacilitatorConfig, Permit2EvmScheme as Permit2EvmFacilitatorScheme, Permit2EvmSchemeConfig as Permit2EvmFacilitatorSchemeConfig, registerPermit2EvmScheme as registerPermit2EvmFacilitatorScheme } from './facilitator/index.js';
4
+ import '@t402/core/types';
5
+ import '../signer-DcavxxZt.js';
6
+ import '@t402/core/client';
7
+ import '@t402/core/server';
8
+ import '@t402/core/facilitator';
9
+
10
+ /**
11
+ * Permit2 Types
12
+ *
13
+ * Type definitions for Uniswap Permit2 SignatureTransfer scheme.
14
+ */
15
+ /**
16
+ * Token permissions for Permit2
17
+ */
18
+ type TokenPermissions = {
19
+ /** ERC20 token address */
20
+ token: `0x${string}`;
21
+ /** Maximum amount permitted to transfer */
22
+ amount: string;
23
+ };
24
+ /**
25
+ * Permit2 PermitTransferFrom parameters
26
+ */
27
+ type PermitTransferFrom = {
28
+ /** Token and amount permissions */
29
+ permitted: TokenPermissions;
30
+ /** Unique nonce (monotonically increasing per owner on the Permit2 contract) */
31
+ nonce: string;
32
+ /** Unix timestamp deadline for the permit */
33
+ deadline: string;
34
+ };
35
+ /**
36
+ * Transfer details for Permit2
37
+ */
38
+ type SignatureTransferDetails = {
39
+ /** Recipient address */
40
+ to: `0x${string}`;
41
+ /** Requested transfer amount */
42
+ requestedAmount: string;
43
+ };
44
+ /**
45
+ * Permit2 payment payload (V2)
46
+ */
47
+ type Permit2PayloadV2 = {
48
+ /** The permit parameters */
49
+ permit: PermitTransferFrom;
50
+ /** Transfer destination and amount */
51
+ transferDetails: SignatureTransferDetails;
52
+ /** EIP-712 signature */
53
+ signature: `0x${string}`;
54
+ /** Token owner address */
55
+ owner: `0x${string}`;
56
+ };
57
+
58
+ /**
59
+ * Permit2 Constants
60
+ *
61
+ * Uniswap Permit2 contract addresses, type hashes, and ABI fragments.
62
+ */
63
+ /** Canonical Permit2 contract address (same on all EVM chains) */
64
+ declare const PERMIT2_ADDRESS: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
65
+ /** EIP-712 type definitions for Permit2 SignatureTransfer */
66
+ declare const permit2Types: {
67
+ readonly PermitTransferFrom: readonly [{
68
+ readonly name: "permitted";
69
+ readonly type: "TokenPermissions";
70
+ }, {
71
+ readonly name: "spender";
72
+ readonly type: "address";
73
+ }, {
74
+ readonly name: "nonce";
75
+ readonly type: "uint256";
76
+ }, {
77
+ readonly name: "deadline";
78
+ readonly type: "uint256";
79
+ }];
80
+ readonly TokenPermissions: readonly [{
81
+ readonly name: "token";
82
+ readonly type: "address";
83
+ }, {
84
+ readonly name: "amount";
85
+ readonly type: "uint256";
86
+ }];
87
+ };
88
+ /** Permit2 ABI for permitTransferFrom */
89
+ declare const permit2ABI: readonly [{
90
+ readonly inputs: readonly [{
91
+ readonly components: readonly [{
92
+ readonly components: readonly [{
93
+ readonly name: "token";
94
+ readonly type: "address";
95
+ }, {
96
+ readonly name: "amount";
97
+ readonly type: "uint256";
98
+ }];
99
+ readonly name: "permitted";
100
+ readonly type: "tuple";
101
+ }, {
102
+ readonly name: "nonce";
103
+ readonly type: "uint256";
104
+ }, {
105
+ readonly name: "deadline";
106
+ readonly type: "uint256";
107
+ }];
108
+ readonly name: "permit";
109
+ readonly type: "tuple";
110
+ }, {
111
+ readonly components: readonly [{
112
+ readonly name: "to";
113
+ readonly type: "address";
114
+ }, {
115
+ readonly name: "requestedAmount";
116
+ readonly type: "uint256";
117
+ }];
118
+ readonly name: "transferDetails";
119
+ readonly type: "tuple";
120
+ }, {
121
+ readonly name: "owner";
122
+ readonly type: "address";
123
+ }, {
124
+ readonly name: "signature";
125
+ readonly type: "bytes";
126
+ }];
127
+ readonly name: "permitTransferFrom";
128
+ readonly outputs: readonly [];
129
+ readonly stateMutability: "nonpayable";
130
+ readonly type: "function";
131
+ }, {
132
+ readonly inputs: readonly [{
133
+ readonly name: "account";
134
+ readonly type: "address";
135
+ }];
136
+ readonly name: "balanceOf";
137
+ readonly outputs: readonly [{
138
+ readonly name: "";
139
+ readonly type: "uint256";
140
+ }];
141
+ readonly stateMutability: "view";
142
+ readonly type: "function";
143
+ }];
144
+
145
+ export { PERMIT2_ADDRESS, type Permit2PayloadV2, type PermitTransferFrom, type SignatureTransferDetails, type TokenPermissions, permit2ABI, permit2Types };