@t402/evm 2.0.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.
- package/README.md +183 -0
- package/dist/cjs/exact/client/index.d.ts +53 -0
- package/dist/cjs/exact/client/index.js +270 -0
- package/dist/cjs/exact/client/index.js.map +1 -0
- package/dist/cjs/exact/facilitator/index.d.ts +118 -0
- package/dist/cjs/exact/facilitator/index.js +735 -0
- package/dist/cjs/exact/facilitator/index.js.map +1 -0
- package/dist/cjs/exact/server/index.d.ts +36 -0
- package/dist/cjs/exact/server/index.js +438 -0
- package/dist/cjs/exact/server/index.js.map +1 -0
- package/dist/cjs/exact/v1/client/index.d.ts +37 -0
- package/dist/cjs/exact/v1/client/index.js +147 -0
- package/dist/cjs/exact/v1/client/index.js.map +1 -0
- package/dist/cjs/exact/v1/facilitator/index.d.ts +62 -0
- package/dist/cjs/exact/v1/facilitator/index.js +401 -0
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -0
- package/dist/cjs/index.d.ts +1537 -0
- package/dist/cjs/index.js +2368 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/scheme-C6uD7PdY.d.ts +130 -0
- package/dist/cjs/scheme-OojTBKAz.d.ts +35 -0
- package/dist/cjs/scheme-yqGaK9rK.d.ts +130 -0
- package/dist/cjs/signer-BkcAzwYi.d.ts +79 -0
- package/dist/cjs/v1/index.d.ts +7 -0
- package/dist/cjs/v1/index.js +171 -0
- package/dist/cjs/v1/index.js.map +1 -0
- package/dist/esm/chunk-ACDQ5QNT.mjs +305 -0
- package/dist/esm/chunk-ACDQ5QNT.mjs.map +1 -0
- package/dist/esm/chunk-JBWWBRYY.mjs +92 -0
- package/dist/esm/chunk-JBWWBRYY.mjs.map +1 -0
- package/dist/esm/chunk-LGSG73NJ.mjs +88 -0
- package/dist/esm/chunk-LGSG73NJ.mjs.map +1 -0
- package/dist/esm/chunk-OEXW2OK2.mjs +251 -0
- package/dist/esm/chunk-OEXW2OK2.mjs.map +1 -0
- package/dist/esm/chunk-QLXM7BIB.mjs +23 -0
- package/dist/esm/chunk-QLXM7BIB.mjs.map +1 -0
- package/dist/esm/chunk-XYKAO6KJ.mjs +141 -0
- package/dist/esm/chunk-XYKAO6KJ.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +53 -0
- package/dist/esm/exact/client/index.mjs +36 -0
- package/dist/esm/exact/client/index.mjs.map +1 -0
- package/dist/esm/exact/facilitator/index.d.mts +118 -0
- package/dist/esm/exact/facilitator/index.mjs +324 -0
- package/dist/esm/exact/facilitator/index.mjs.map +1 -0
- package/dist/esm/exact/server/index.d.mts +36 -0
- package/dist/esm/exact/server/index.mjs +218 -0
- package/dist/esm/exact/server/index.mjs.map +1 -0
- package/dist/esm/exact/v1/client/index.d.mts +37 -0
- package/dist/esm/exact/v1/client/index.mjs +8 -0
- package/dist/esm/exact/v1/client/index.mjs.map +1 -0
- package/dist/esm/exact/v1/facilitator/index.d.mts +62 -0
- package/dist/esm/exact/v1/facilitator/index.mjs +8 -0
- package/dist/esm/exact/v1/facilitator/index.mjs.map +1 -0
- package/dist/esm/index.d.mts +1537 -0
- package/dist/esm/index.mjs +1875 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/scheme-D4mOqq9l.d.mts +35 -0
- package/dist/esm/scheme-yqGaK9rK.d.mts +130 -0
- package/dist/esm/signer-BkcAzwYi.d.mts +79 -0
- package/dist/esm/v1/index.d.mts +7 -0
- package/dist/esm/v1/index.mjs +13 -0
- package/dist/esm/v1/index.mjs.map +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,401 @@
|
|
|
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/exact/v1/facilitator/index.ts
|
|
21
|
+
var facilitator_exports = {};
|
|
22
|
+
__export(facilitator_exports, {
|
|
23
|
+
ExactEvmSchemeV1: () => ExactEvmSchemeV1
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(facilitator_exports);
|
|
26
|
+
|
|
27
|
+
// src/exact/v1/facilitator/scheme.ts
|
|
28
|
+
var import_viem2 = require("viem");
|
|
29
|
+
|
|
30
|
+
// src/constants.ts
|
|
31
|
+
var authorizationTypes = {
|
|
32
|
+
TransferWithAuthorization: [
|
|
33
|
+
{ name: "from", type: "address" },
|
|
34
|
+
{ name: "to", type: "address" },
|
|
35
|
+
{ name: "value", type: "uint256" },
|
|
36
|
+
{ name: "validAfter", type: "uint256" },
|
|
37
|
+
{ name: "validBefore", type: "uint256" },
|
|
38
|
+
{ name: "nonce", type: "bytes32" }
|
|
39
|
+
]
|
|
40
|
+
};
|
|
41
|
+
var eip3009ABI = [
|
|
42
|
+
{
|
|
43
|
+
inputs: [
|
|
44
|
+
{ name: "from", type: "address" },
|
|
45
|
+
{ name: "to", type: "address" },
|
|
46
|
+
{ name: "value", type: "uint256" },
|
|
47
|
+
{ name: "validAfter", type: "uint256" },
|
|
48
|
+
{ name: "validBefore", type: "uint256" },
|
|
49
|
+
{ name: "nonce", type: "bytes32" },
|
|
50
|
+
{ name: "v", type: "uint8" },
|
|
51
|
+
{ name: "r", type: "bytes32" },
|
|
52
|
+
{ name: "s", type: "bytes32" }
|
|
53
|
+
],
|
|
54
|
+
name: "transferWithAuthorization",
|
|
55
|
+
outputs: [],
|
|
56
|
+
stateMutability: "nonpayable",
|
|
57
|
+
type: "function"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
inputs: [
|
|
61
|
+
{ name: "from", type: "address" },
|
|
62
|
+
{ name: "to", type: "address" },
|
|
63
|
+
{ name: "value", type: "uint256" },
|
|
64
|
+
{ name: "validAfter", type: "uint256" },
|
|
65
|
+
{ name: "validBefore", type: "uint256" },
|
|
66
|
+
{ name: "nonce", type: "bytes32" },
|
|
67
|
+
{ name: "signature", type: "bytes" }
|
|
68
|
+
],
|
|
69
|
+
name: "transferWithAuthorization",
|
|
70
|
+
outputs: [],
|
|
71
|
+
stateMutability: "nonpayable",
|
|
72
|
+
type: "function"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
inputs: [{ name: "account", type: "address" }],
|
|
76
|
+
name: "balanceOf",
|
|
77
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
78
|
+
stateMutability: "view",
|
|
79
|
+
type: "function"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
inputs: [],
|
|
83
|
+
name: "version",
|
|
84
|
+
outputs: [{ name: "", type: "string" }],
|
|
85
|
+
stateMutability: "view",
|
|
86
|
+
type: "function"
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
// src/utils.ts
|
|
91
|
+
var import_viem = require("viem");
|
|
92
|
+
function getEvmChainId(network) {
|
|
93
|
+
const networkMap = {
|
|
94
|
+
base: 8453,
|
|
95
|
+
"base-sepolia": 84532,
|
|
96
|
+
ethereum: 1,
|
|
97
|
+
sepolia: 11155111,
|
|
98
|
+
polygon: 137,
|
|
99
|
+
"polygon-amoy": 80002
|
|
100
|
+
};
|
|
101
|
+
return networkMap[network] || 1;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/exact/v1/facilitator/scheme.ts
|
|
105
|
+
var ExactEvmSchemeV1 = class {
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new ExactEvmFacilitatorV1 instance.
|
|
108
|
+
*
|
|
109
|
+
* @param signer - The EVM signer for facilitator operations
|
|
110
|
+
* @param config - Optional configuration for the facilitator
|
|
111
|
+
*/
|
|
112
|
+
constructor(signer, config) {
|
|
113
|
+
this.signer = signer;
|
|
114
|
+
this.scheme = "exact";
|
|
115
|
+
this.caipFamily = "eip155:*";
|
|
116
|
+
this.config = {
|
|
117
|
+
deployERC4337WithEIP6492: config?.deployERC4337WithEIP6492 ?? false
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get mechanism-specific extra data for the supported kinds endpoint.
|
|
122
|
+
* For EVM, no extra data is needed.
|
|
123
|
+
*
|
|
124
|
+
* @param _ - The network identifier (unused for EVM)
|
|
125
|
+
* @returns undefined (EVM has no extra data)
|
|
126
|
+
*/
|
|
127
|
+
getExtra(_) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get signer addresses used by this facilitator.
|
|
132
|
+
* Returns all addresses this facilitator can use for signing/settling transactions.
|
|
133
|
+
*
|
|
134
|
+
* @param _ - The network identifier (unused for EVM, addresses are network-agnostic)
|
|
135
|
+
* @returns Array of facilitator wallet addresses
|
|
136
|
+
*/
|
|
137
|
+
getSigners(_) {
|
|
138
|
+
return [...this.signer.getAddresses()];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Verifies a payment payload (V1).
|
|
142
|
+
*
|
|
143
|
+
* @param payload - The payment payload to verify
|
|
144
|
+
* @param requirements - The payment requirements
|
|
145
|
+
* @returns Promise resolving to verification response
|
|
146
|
+
*/
|
|
147
|
+
async verify(payload, requirements) {
|
|
148
|
+
const requirementsV1 = requirements;
|
|
149
|
+
const payloadV1 = payload;
|
|
150
|
+
const exactEvmPayload = payload.payload;
|
|
151
|
+
if (payloadV1.scheme !== "exact" || requirements.scheme !== "exact") {
|
|
152
|
+
return {
|
|
153
|
+
isValid: false,
|
|
154
|
+
invalidReason: "unsupported_scheme",
|
|
155
|
+
payer: exactEvmPayload.authorization.from
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const chainId = getEvmChainId(payloadV1.network);
|
|
159
|
+
if (!requirements.extra?.name || !requirements.extra?.version) {
|
|
160
|
+
return {
|
|
161
|
+
isValid: false,
|
|
162
|
+
invalidReason: "missing_eip712_domain",
|
|
163
|
+
payer: exactEvmPayload.authorization.from
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const { name, version } = requirements.extra;
|
|
167
|
+
const erc20Address = (0, import_viem2.getAddress)(requirements.asset);
|
|
168
|
+
if (payloadV1.network !== requirements.network) {
|
|
169
|
+
return {
|
|
170
|
+
isValid: false,
|
|
171
|
+
invalidReason: "network_mismatch",
|
|
172
|
+
payer: exactEvmPayload.authorization.from
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const permitTypedData = {
|
|
176
|
+
types: authorizationTypes,
|
|
177
|
+
primaryType: "TransferWithAuthorization",
|
|
178
|
+
domain: {
|
|
179
|
+
name,
|
|
180
|
+
version,
|
|
181
|
+
chainId,
|
|
182
|
+
verifyingContract: erc20Address
|
|
183
|
+
},
|
|
184
|
+
message: {
|
|
185
|
+
from: exactEvmPayload.authorization.from,
|
|
186
|
+
to: exactEvmPayload.authorization.to,
|
|
187
|
+
value: BigInt(exactEvmPayload.authorization.value),
|
|
188
|
+
validAfter: BigInt(exactEvmPayload.authorization.validAfter),
|
|
189
|
+
validBefore: BigInt(exactEvmPayload.authorization.validBefore),
|
|
190
|
+
nonce: exactEvmPayload.authorization.nonce
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
try {
|
|
194
|
+
const recoveredAddress = await this.signer.verifyTypedData({
|
|
195
|
+
address: exactEvmPayload.authorization.from,
|
|
196
|
+
...permitTypedData,
|
|
197
|
+
signature: exactEvmPayload.signature
|
|
198
|
+
});
|
|
199
|
+
if (!recoveredAddress) {
|
|
200
|
+
return {
|
|
201
|
+
isValid: false,
|
|
202
|
+
invalidReason: "invalid_exact_evm_payload_signature",
|
|
203
|
+
payer: exactEvmPayload.authorization.from
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
} catch {
|
|
207
|
+
const signature = exactEvmPayload.signature;
|
|
208
|
+
const signatureLength = signature.startsWith("0x") ? signature.length - 2 : signature.length;
|
|
209
|
+
const isSmartWallet = signatureLength > 130;
|
|
210
|
+
if (isSmartWallet) {
|
|
211
|
+
const payerAddress = exactEvmPayload.authorization.from;
|
|
212
|
+
const bytecode = await this.signer.getCode({ address: payerAddress });
|
|
213
|
+
if (!bytecode || bytecode === "0x") {
|
|
214
|
+
const erc6492Data = (0, import_viem2.parseErc6492Signature)(signature);
|
|
215
|
+
const hasDeploymentInfo = erc6492Data.address && erc6492Data.data && !(0, import_viem2.isAddressEqual)(erc6492Data.address, "0x0000000000000000000000000000000000000000");
|
|
216
|
+
if (!hasDeploymentInfo) {
|
|
217
|
+
return {
|
|
218
|
+
isValid: false,
|
|
219
|
+
invalidReason: "invalid_exact_evm_payload_undeployed_smart_wallet",
|
|
220
|
+
payer: payerAddress
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
return {
|
|
225
|
+
isValid: false,
|
|
226
|
+
invalidReason: "invalid_exact_evm_payload_signature",
|
|
227
|
+
payer: exactEvmPayload.authorization.from
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
return {
|
|
232
|
+
isValid: false,
|
|
233
|
+
invalidReason: "invalid_exact_evm_payload_signature",
|
|
234
|
+
payer: exactEvmPayload.authorization.from
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if ((0, import_viem2.getAddress)(exactEvmPayload.authorization.to) !== (0, import_viem2.getAddress)(requirements.payTo)) {
|
|
239
|
+
return {
|
|
240
|
+
isValid: false,
|
|
241
|
+
invalidReason: "invalid_exact_evm_payload_recipient_mismatch",
|
|
242
|
+
payer: exactEvmPayload.authorization.from
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
246
|
+
if (BigInt(exactEvmPayload.authorization.validBefore) < BigInt(now + 6)) {
|
|
247
|
+
return {
|
|
248
|
+
isValid: false,
|
|
249
|
+
invalidReason: "invalid_exact_evm_payload_authorization_valid_before",
|
|
250
|
+
payer: exactEvmPayload.authorization.from
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (BigInt(exactEvmPayload.authorization.validAfter) > BigInt(now)) {
|
|
254
|
+
return {
|
|
255
|
+
isValid: false,
|
|
256
|
+
invalidReason: "invalid_exact_evm_payload_authorization_valid_after",
|
|
257
|
+
payer: exactEvmPayload.authorization.from
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
const balance = await this.signer.readContract({
|
|
262
|
+
address: erc20Address,
|
|
263
|
+
abi: eip3009ABI,
|
|
264
|
+
functionName: "balanceOf",
|
|
265
|
+
args: [exactEvmPayload.authorization.from]
|
|
266
|
+
});
|
|
267
|
+
if (BigInt(balance) < BigInt(requirementsV1.maxAmountRequired)) {
|
|
268
|
+
return {
|
|
269
|
+
isValid: false,
|
|
270
|
+
invalidReason: "insufficient_funds",
|
|
271
|
+
payer: exactEvmPayload.authorization.from
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
} catch {
|
|
275
|
+
}
|
|
276
|
+
if (BigInt(exactEvmPayload.authorization.value) < BigInt(requirementsV1.maxAmountRequired)) {
|
|
277
|
+
return {
|
|
278
|
+
isValid: false,
|
|
279
|
+
invalidReason: "invalid_exact_evm_payload_authorization_value",
|
|
280
|
+
payer: exactEvmPayload.authorization.from
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
isValid: true,
|
|
285
|
+
invalidReason: void 0,
|
|
286
|
+
payer: exactEvmPayload.authorization.from
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Settles a payment by executing the transfer (V1).
|
|
291
|
+
*
|
|
292
|
+
* @param payload - The payment payload to settle
|
|
293
|
+
* @param requirements - The payment requirements
|
|
294
|
+
* @returns Promise resolving to settlement response
|
|
295
|
+
*/
|
|
296
|
+
async settle(payload, requirements) {
|
|
297
|
+
const payloadV1 = payload;
|
|
298
|
+
const exactEvmPayload = payload.payload;
|
|
299
|
+
const valid = await this.verify(payload, requirements);
|
|
300
|
+
if (!valid.isValid) {
|
|
301
|
+
return {
|
|
302
|
+
success: false,
|
|
303
|
+
network: payloadV1.network,
|
|
304
|
+
transaction: "",
|
|
305
|
+
errorReason: valid.invalidReason ?? "invalid_scheme",
|
|
306
|
+
payer: exactEvmPayload.authorization.from
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
const parseResult = (0, import_viem2.parseErc6492Signature)(exactEvmPayload.signature);
|
|
311
|
+
const { signature, address: factoryAddress, data: factoryCalldata } = parseResult;
|
|
312
|
+
if (this.config.deployERC4337WithEIP6492 && factoryAddress && factoryCalldata && !(0, import_viem2.isAddressEqual)(factoryAddress, "0x0000000000000000000000000000000000000000")) {
|
|
313
|
+
const payerAddress = exactEvmPayload.authorization.from;
|
|
314
|
+
const bytecode = await this.signer.getCode({ address: payerAddress });
|
|
315
|
+
if (!bytecode || bytecode === "0x") {
|
|
316
|
+
try {
|
|
317
|
+
console.log(`Deploying ERC-4337 smart wallet for ${payerAddress} via EIP-6492`);
|
|
318
|
+
const deployTx = await this.signer.sendTransaction({
|
|
319
|
+
to: factoryAddress,
|
|
320
|
+
data: factoryCalldata
|
|
321
|
+
});
|
|
322
|
+
await this.signer.waitForTransactionReceipt({ hash: deployTx });
|
|
323
|
+
console.log(`Successfully deployed smart wallet for ${payerAddress}`);
|
|
324
|
+
} catch (deployError) {
|
|
325
|
+
console.error("Smart wallet deployment failed:", deployError);
|
|
326
|
+
throw deployError;
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
console.log(`Smart wallet for ${payerAddress} already deployed, skipping deployment`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const signatureLength = signature.startsWith("0x") ? signature.length - 2 : signature.length;
|
|
333
|
+
const isECDSA = signatureLength === 130;
|
|
334
|
+
let tx;
|
|
335
|
+
if (isECDSA) {
|
|
336
|
+
const parsedSig = (0, import_viem2.parseSignature)(signature);
|
|
337
|
+
tx = await this.signer.writeContract({
|
|
338
|
+
address: (0, import_viem2.getAddress)(requirements.asset),
|
|
339
|
+
abi: eip3009ABI,
|
|
340
|
+
functionName: "transferWithAuthorization",
|
|
341
|
+
args: [
|
|
342
|
+
(0, import_viem2.getAddress)(exactEvmPayload.authorization.from),
|
|
343
|
+
(0, import_viem2.getAddress)(exactEvmPayload.authorization.to),
|
|
344
|
+
BigInt(exactEvmPayload.authorization.value),
|
|
345
|
+
BigInt(exactEvmPayload.authorization.validAfter),
|
|
346
|
+
BigInt(exactEvmPayload.authorization.validBefore),
|
|
347
|
+
exactEvmPayload.authorization.nonce,
|
|
348
|
+
parsedSig.v || parsedSig.yParity,
|
|
349
|
+
parsedSig.r,
|
|
350
|
+
parsedSig.s
|
|
351
|
+
]
|
|
352
|
+
});
|
|
353
|
+
} else {
|
|
354
|
+
tx = await this.signer.writeContract({
|
|
355
|
+
address: (0, import_viem2.getAddress)(requirements.asset),
|
|
356
|
+
abi: eip3009ABI,
|
|
357
|
+
functionName: "transferWithAuthorization",
|
|
358
|
+
args: [
|
|
359
|
+
(0, import_viem2.getAddress)(exactEvmPayload.authorization.from),
|
|
360
|
+
(0, import_viem2.getAddress)(exactEvmPayload.authorization.to),
|
|
361
|
+
BigInt(exactEvmPayload.authorization.value),
|
|
362
|
+
BigInt(exactEvmPayload.authorization.validAfter),
|
|
363
|
+
BigInt(exactEvmPayload.authorization.validBefore),
|
|
364
|
+
exactEvmPayload.authorization.nonce,
|
|
365
|
+
signature
|
|
366
|
+
]
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
const receipt = await this.signer.waitForTransactionReceipt({ hash: tx });
|
|
370
|
+
if (receipt.status !== "success") {
|
|
371
|
+
return {
|
|
372
|
+
success: false,
|
|
373
|
+
errorReason: "invalid_transaction_state",
|
|
374
|
+
transaction: tx,
|
|
375
|
+
network: payloadV1.network,
|
|
376
|
+
payer: exactEvmPayload.authorization.from
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
success: true,
|
|
381
|
+
transaction: tx,
|
|
382
|
+
network: payloadV1.network,
|
|
383
|
+
payer: exactEvmPayload.authorization.from
|
|
384
|
+
};
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.error("Failed to settle transaction:", error);
|
|
387
|
+
return {
|
|
388
|
+
success: false,
|
|
389
|
+
errorReason: "transaction_failed",
|
|
390
|
+
transaction: "",
|
|
391
|
+
network: payloadV1.network,
|
|
392
|
+
payer: exactEvmPayload.authorization.from
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
398
|
+
0 && (module.exports = {
|
|
399
|
+
ExactEvmSchemeV1
|
|
400
|
+
});
|
|
401
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/exact/v1/facilitator/index.ts","../../../../../src/exact/v1/facilitator/scheme.ts","../../../../../src/constants.ts","../../../../../src/utils.ts"],"sourcesContent":["export { ExactEvmSchemeV1 } from \"./scheme\";\nexport type { ExactEvmSchemeV1Config } from \"./scheme\";\n","import {\n PaymentPayload,\n PaymentPayloadV1,\n PaymentRequirements,\n SchemeNetworkFacilitator,\n SettleResponse,\n VerifyResponse,\n} from \"@t402/core/types\";\nimport { PaymentRequirementsV1 } from \"@t402/core/types/v1\";\nimport { getAddress, Hex, isAddressEqual, parseErc6492Signature, parseSignature } from \"viem\";\nimport { authorizationTypes, eip3009ABI } from \"../../../constants\";\nimport { FacilitatorEvmSigner } from \"../../../signer\";\nimport { ExactEvmPayloadV1 } from \"../../../types\";\nimport { getEvmChainId } from \"../../../utils\";\n\nexport interface ExactEvmSchemeV1Config {\n /**\n * If enabled, the facilitator will deploy ERC-4337 smart wallets\n * via EIP-6492 when encountering undeployed contract signatures.\n *\n * @default false\n */\n deployERC4337WithEIP6492?: boolean;\n}\n\n/**\n * EVM facilitator implementation for the Exact payment scheme (V1).\n */\nexport class ExactEvmSchemeV1 implements SchemeNetworkFacilitator {\n readonly scheme = \"exact\";\n readonly caipFamily = \"eip155:*\";\n private readonly config: Required<ExactEvmSchemeV1Config>;\n\n /**\n * Creates a new ExactEvmFacilitatorV1 instance.\n *\n * @param signer - The EVM signer for facilitator operations\n * @param config - Optional configuration for the facilitator\n */\n constructor(\n private readonly signer: FacilitatorEvmSigner,\n config?: ExactEvmSchemeV1Config,\n ) {\n this.config = {\n deployERC4337WithEIP6492: config?.deployERC4337WithEIP6492 ?? false,\n };\n }\n\n /**\n * Get mechanism-specific extra data for the supported kinds endpoint.\n * For EVM, no extra data is needed.\n *\n * @param _ - The network identifier (unused for EVM)\n * @returns undefined (EVM has no extra data)\n */\n getExtra(_: string): Record<string, unknown> | undefined {\n return undefined;\n }\n\n /**\n * Get signer addresses used by this facilitator.\n * Returns all addresses this facilitator can use for signing/settling transactions.\n *\n * @param _ - The network identifier (unused for EVM, addresses are network-agnostic)\n * @returns Array of facilitator wallet addresses\n */\n getSigners(_: string): string[] {\n return [...this.signer.getAddresses()];\n }\n\n /**\n * Verifies a payment payload (V1).\n *\n * @param payload - The payment payload to verify\n * @param requirements - The payment requirements\n * @returns Promise resolving to verification response\n */\n async verify(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n const requirementsV1 = requirements as unknown as PaymentRequirementsV1;\n const payloadV1 = payload as unknown as PaymentPayloadV1;\n const exactEvmPayload = payload.payload as ExactEvmPayloadV1;\n\n // Verify scheme matches\n if (payloadV1.scheme !== \"exact\" || requirements.scheme !== \"exact\") {\n return {\n isValid: false,\n invalidReason: \"unsupported_scheme\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Get chain configuration\n const chainId = getEvmChainId(payloadV1.network);\n\n if (!requirements.extra?.name || !requirements.extra?.version) {\n return {\n isValid: false,\n invalidReason: \"missing_eip712_domain\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n const { name, version } = requirements.extra;\n const erc20Address = getAddress(requirements.asset);\n\n // Verify network matches\n if (payloadV1.network !== requirements.network) {\n return {\n isValid: false,\n invalidReason: \"network_mismatch\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Build typed data for signature verification\n const permitTypedData = {\n types: authorizationTypes,\n primaryType: \"TransferWithAuthorization\" as const,\n domain: {\n name,\n version,\n chainId,\n verifyingContract: erc20Address,\n },\n message: {\n from: exactEvmPayload.authorization.from,\n to: exactEvmPayload.authorization.to,\n value: BigInt(exactEvmPayload.authorization.value),\n validAfter: BigInt(exactEvmPayload.authorization.validAfter),\n validBefore: BigInt(exactEvmPayload.authorization.validBefore),\n nonce: exactEvmPayload.authorization.nonce,\n },\n };\n\n // Verify signature\n try {\n const recoveredAddress = await this.signer.verifyTypedData({\n address: exactEvmPayload.authorization.from,\n ...permitTypedData,\n signature: exactEvmPayload.signature!,\n });\n\n if (!recoveredAddress) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } catch {\n // Signature verification failed - could be an undeployed smart wallet\n // Check if smart wallet is deployed\n const signature = exactEvmPayload.signature!;\n const signatureLength = signature.startsWith(\"0x\") ? signature.length - 2 : signature.length;\n const isSmartWallet = signatureLength > 130; // 65 bytes = 130 hex chars for EOA\n\n if (isSmartWallet) {\n const payerAddress = exactEvmPayload.authorization.from;\n const bytecode = await this.signer.getCode({ address: payerAddress });\n\n if (!bytecode || bytecode === \"0x\") {\n // Wallet is not deployed. Check if it's EIP-6492 with deployment info.\n // EIP-6492 signatures contain factory address and calldata needed for deployment.\n // Non-EIP-6492 undeployed wallets cannot succeed (no way to deploy them).\n const erc6492Data = parseErc6492Signature(signature);\n const hasDeploymentInfo =\n erc6492Data.address &&\n erc6492Data.data &&\n !isAddressEqual(erc6492Data.address, \"0x0000000000000000000000000000000000000000\");\n\n if (!hasDeploymentInfo) {\n // Non-EIP-6492 undeployed smart wallet - will always fail at settlement\n // since EIP-3009 requires on-chain EIP-1271 validation\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_undeployed_smart_wallet\",\n payer: payerAddress,\n };\n }\n // EIP-6492 signature with deployment info - allow through\n // Facilitators with sponsored deployment support can handle this in settle()\n } else {\n // Wallet is deployed but signature still failed - invalid signature\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } else {\n // EOA signature failed\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n }\n\n // Verify payment recipient matches\n if (getAddress(exactEvmPayload.authorization.to) !== getAddress(requirements.payTo)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_recipient_mismatch\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Verify validBefore is in the future (with 6 second buffer for block time)\n const now = Math.floor(Date.now() / 1000);\n if (BigInt(exactEvmPayload.authorization.validBefore) < BigInt(now + 6)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_valid_before\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Verify validAfter is not in the future\n if (BigInt(exactEvmPayload.authorization.validAfter) > BigInt(now)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_valid_after\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Check balance\n try {\n const balance = (await this.signer.readContract({\n address: erc20Address,\n abi: eip3009ABI,\n functionName: \"balanceOf\",\n args: [exactEvmPayload.authorization.from],\n })) as bigint;\n\n if (BigInt(balance) < BigInt(requirementsV1.maxAmountRequired)) {\n return {\n isValid: false,\n invalidReason: \"insufficient_funds\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } catch {\n // If we can't check balance, continue with other validations\n }\n\n // Verify amount is sufficient\n if (BigInt(exactEvmPayload.authorization.value) < BigInt(requirementsV1.maxAmountRequired)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_value\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n return {\n isValid: true,\n invalidReason: undefined,\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n /**\n * Settles a payment by executing the transfer (V1).\n *\n * @param payload - The payment payload to settle\n * @param requirements - The payment requirements\n * @returns Promise resolving to settlement response\n */\n async settle(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<SettleResponse> {\n const payloadV1 = payload as unknown as PaymentPayloadV1;\n const exactEvmPayload = payload.payload as ExactEvmPayloadV1;\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: payloadV1.network,\n transaction: \"\",\n errorReason: valid.invalidReason ?? \"invalid_scheme\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n try {\n // Parse ERC-6492 signature if applicable\n const parseResult = parseErc6492Signature(exactEvmPayload.signature!);\n const { signature, address: factoryAddress, data: factoryCalldata } = parseResult;\n\n // Deploy ERC-4337 smart wallet via EIP-6492 if configured and needed\n if (\n this.config.deployERC4337WithEIP6492 &&\n factoryAddress &&\n factoryCalldata &&\n !isAddressEqual(factoryAddress, \"0x0000000000000000000000000000000000000000\")\n ) {\n // Check if smart wallet is already deployed\n const payerAddress = exactEvmPayload.authorization.from;\n const bytecode = await this.signer.getCode({ address: payerAddress });\n\n if (!bytecode || bytecode === \"0x\") {\n // Wallet not deployed - attempt deployment\n try {\n console.log(`Deploying ERC-4337 smart wallet for ${payerAddress} via EIP-6492`);\n\n // Send the factory calldata directly as a transaction\n // The factoryCalldata already contains the complete encoded function call\n const deployTx = await this.signer.sendTransaction({\n to: factoryAddress as Hex,\n data: factoryCalldata as Hex,\n });\n\n // Wait for deployment transaction\n await this.signer.waitForTransactionReceipt({ hash: deployTx });\n console.log(`Successfully deployed smart wallet for ${payerAddress}`);\n } catch (deployError) {\n console.error(\"Smart wallet deployment failed:\", deployError);\n // Deployment failed - cannot proceed\n throw deployError;\n }\n } else {\n console.log(`Smart wallet for ${payerAddress} already deployed, skipping deployment`);\n }\n }\n\n // Determine if this is an ECDSA signature (EOA) or smart wallet signature\n // ECDSA signatures are exactly 65 bytes (130 hex chars without 0x)\n const signatureLength = signature.startsWith(\"0x\") ? signature.length - 2 : signature.length;\n const isECDSA = signatureLength === 130;\n\n let tx: Hex;\n if (isECDSA) {\n // For EOA wallets, parse signature into v, r, s and use that overload\n const parsedSig = parseSignature(signature);\n\n tx = await this.signer.writeContract({\n address: getAddress(requirements.asset),\n abi: eip3009ABI,\n functionName: \"transferWithAuthorization\",\n args: [\n getAddress(exactEvmPayload.authorization.from),\n getAddress(exactEvmPayload.authorization.to),\n BigInt(exactEvmPayload.authorization.value),\n BigInt(exactEvmPayload.authorization.validAfter),\n BigInt(exactEvmPayload.authorization.validBefore),\n exactEvmPayload.authorization.nonce,\n (parsedSig.v as number | undefined) || parsedSig.yParity,\n parsedSig.r,\n parsedSig.s,\n ],\n });\n } else {\n // For smart wallets, use the bytes signature overload\n // The signature contains WebAuthn/P256 or other ERC-1271 compatible signature data\n tx = await this.signer.writeContract({\n address: getAddress(requirements.asset),\n abi: eip3009ABI,\n functionName: \"transferWithAuthorization\",\n args: [\n getAddress(exactEvmPayload.authorization.from),\n getAddress(exactEvmPayload.authorization.to),\n BigInt(exactEvmPayload.authorization.value),\n BigInt(exactEvmPayload.authorization.validAfter),\n BigInt(exactEvmPayload.authorization.validBefore),\n exactEvmPayload.authorization.nonce,\n signature,\n ],\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: payloadV1.network,\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n return {\n success: true,\n transaction: tx,\n network: payloadV1.network,\n payer: exactEvmPayload.authorization.from,\n };\n } catch (error) {\n console.error(\"Failed to settle transaction:\", error);\n return {\n success: false,\n errorReason: \"transaction_failed\",\n transaction: \"\",\n network: payloadV1.network,\n payer: exactEvmPayload.authorization.from,\n };\n }\n }\n}\n","// EIP-3009 TransferWithAuthorization types for EIP-712 signing\nexport const authorizationTypes = {\n TransferWithAuthorization: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n { name: \"nonce\", type: \"bytes32\" },\n ],\n} as const;\n\n// Legacy transfer authorization types for EIP-712 signing\n// Used for tokens without EIP-3009 support (approve + transferFrom pattern)\nexport const legacyAuthorizationTypes = {\n LegacyTransferAuthorization: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n { name: \"nonce\", type: \"bytes32\" },\n { name: \"spender\", type: \"address\" },\n ],\n} as const;\n\n// EIP3009 ABI for transferWithAuthorization function\nexport const eip3009ABI = [\n {\n inputs: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n { name: \"nonce\", type: \"bytes32\" },\n { name: \"v\", type: \"uint8\" },\n { name: \"r\", type: \"bytes32\" },\n { name: \"s\", type: \"bytes32\" },\n ],\n name: \"transferWithAuthorization\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n { name: \"nonce\", type: \"bytes32\" },\n { name: \"signature\", type: \"bytes\" },\n ],\n name: \"transferWithAuthorization\",\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 {\n inputs: [],\n name: \"version\",\n outputs: [{ name: \"\", type: \"string\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n] as const;\n\n// Standard ERC20 ABI for legacy token operations (approve + transferFrom pattern)\nexport const erc20LegacyABI = [\n {\n inputs: [{ name: \"account\", type: \"address\" }],\n name: \"balanceOf\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"owner\", type: \"address\" },\n { name: \"spender\", type: \"address\" },\n ],\n name: \"allowance\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"spender\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n name: \"approve\",\n outputs: [{ name: \"\", type: \"bool\" }],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n name: \"transferFrom\",\n outputs: [{ name: \"\", type: \"bool\" }],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n] as const;\n","import { toHex } from \"viem\";\nimport { Network } from \"@t402/core/types\";\n\n/**\n * Extract chain ID from network string (e.g., \"base-sepolia\" -> 84532)\n * Used by v1 implementations\n *\n * @param network - The network identifier\n * @returns The numeric chain ID\n */\nexport function getEvmChainId(network: Network): number {\n const networkMap: Record<string, number> = {\n base: 8453,\n \"base-sepolia\": 84532,\n ethereum: 1,\n sepolia: 11155111,\n polygon: 137,\n \"polygon-amoy\": 80002,\n };\n return networkMap[network] || 1;\n}\n\n/**\n * Create a random 32-byte nonce for authorization\n *\n * @returns A hex-encoded 32-byte nonce\n */\nexport function createNonce(): `0x${string}` {\n // Use dynamic import to avoid require() in ESM context\n const cryptoObj =\n typeof globalThis.crypto !== \"undefined\"\n ? globalThis.crypto\n : (globalThis as { crypto?: Crypto }).crypto;\n\n if (!cryptoObj) {\n throw new Error(\"Crypto API not available\");\n }\n\n return toHex(cryptoObj.getRandomValues(new Uint8Array(32)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,IAAAA,eAAuF;;;ACRhF,IAAM,qBAAqB;AAAA,EAChC,2BAA2B;AAAA,IACzB,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,IAChC,EAAE,MAAM,MAAM,MAAM,UAAU;AAAA,IAC9B,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,IACjC,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,IACtC,EAAE,MAAM,eAAe,MAAM,UAAU;AAAA,IACvC,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,EACnC;AACF;AAiBO,IAAM,aAAa;AAAA,EACxB;AAAA,IACE,QAAQ;AAAA,MACN,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,MAChC,EAAE,MAAM,MAAM,MAAM,UAAU;AAAA,MAC9B,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,MACjC,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,MACtC,EAAE,MAAM,eAAe,MAAM,UAAU;AAAA,MACvC,EAAE,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