@bankofai/x402-evm 2.6.0-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.
- package/README.md +184 -0
- package/dist/cjs/exact/client/index.d.ts +53 -0
- package/dist/cjs/exact/client/index.js +661 -0
- package/dist/cjs/exact/client/index.js.map +1 -0
- package/dist/cjs/exact/facilitator/index.d.ts +121 -0
- package/dist/cjs/exact/facilitator/index.js +1458 -0
- package/dist/cjs/exact/facilitator/index.js.map +1 -0
- package/dist/cjs/exact/server/index.d.ts +125 -0
- package/dist/cjs/exact/server/index.js +229 -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 +175 -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 +436 -0
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -0
- package/dist/cjs/exact_permit/client/index.d.ts +57 -0
- package/dist/cjs/exact_permit/client/index.js +223 -0
- package/dist/cjs/exact_permit/client/index.js.map +1 -0
- package/dist/cjs/exact_permit/facilitator/index.d.ts +82 -0
- package/dist/cjs/exact_permit/facilitator/index.js +437 -0
- package/dist/cjs/exact_permit/facilitator/index.js.map +1 -0
- package/dist/cjs/exact_permit/server/index.d.ts +71 -0
- package/dist/cjs/exact_permit/server/index.js +186 -0
- package/dist/cjs/exact_permit/server/index.js.map +1 -0
- package/dist/cjs/index.d.ts +76 -0
- package/dist/cjs/index.js +779 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/permit2-CpuKY2-F.d.ts +509 -0
- package/dist/cjs/permit2-D65OQ5yU.d.ts +517 -0
- package/dist/cjs/permit2-DvsTlAyj.d.ts +531 -0
- package/dist/cjs/signer-DC81R8wQ.d.ts +161 -0
- package/dist/cjs/v1/index.d.ts +39 -0
- package/dist/cjs/v1/index.js +181 -0
- package/dist/cjs/v1/index.js.map +1 -0
- package/dist/esm/chunk-4JGB4GDD.mjs +425 -0
- package/dist/esm/chunk-4JGB4GDD.mjs.map +1 -0
- package/dist/esm/chunk-TKN5V2BV.mjs +13 -0
- package/dist/esm/chunk-TKN5V2BV.mjs.map +1 -0
- package/dist/esm/chunk-UDKSVWSE.mjs +716 -0
- package/dist/esm/chunk-UDKSVWSE.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +53 -0
- package/dist/esm/exact/client/index.mjs +17 -0
- package/dist/esm/exact/client/index.mjs.map +1 -0
- package/dist/esm/exact/facilitator/index.d.mts +121 -0
- package/dist/esm/exact/facilitator/index.mjs +876 -0
- package/dist/esm/exact/facilitator/index.mjs.map +1 -0
- package/dist/esm/exact/server/index.d.mts +125 -0
- package/dist/esm/exact/server/index.mjs +201 -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 +7 -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 +7 -0
- package/dist/esm/exact/v1/facilitator/index.mjs.map +1 -0
- package/dist/esm/index.d.mts +76 -0
- package/dist/esm/index.mjs +71 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/permit2-D7ni3g6s.d.mts +509 -0
- package/dist/esm/signer-DC81R8wQ.d.mts +161 -0
- package/dist/esm/v1/index.d.mts +39 -0
- package/dist/esm/v1/index.mjs +13 -0
- package/dist/esm/v1/index.mjs.map +1 -0
- package/package.json +128 -0
|
@@ -0,0 +1,437 @@
|
|
|
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_permit/facilitator/index.ts
|
|
21
|
+
var facilitator_exports = {};
|
|
22
|
+
__export(facilitator_exports, {
|
|
23
|
+
ExactPermitEvmScheme: () => ExactPermitEvmScheme,
|
|
24
|
+
registerExactPermitEvmScheme: () => registerExactPermitEvmScheme
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(facilitator_exports);
|
|
27
|
+
|
|
28
|
+
// src/constants.ts
|
|
29
|
+
var paymentPermitTypes = {
|
|
30
|
+
PaymentPermitDetails: [
|
|
31
|
+
{ name: "meta", type: "PermitMeta" },
|
|
32
|
+
{ name: "buyer", type: "address" },
|
|
33
|
+
{ name: "caller", type: "address" },
|
|
34
|
+
{ name: "payment", type: "Payment" },
|
|
35
|
+
{ name: "fee", type: "Fee" }
|
|
36
|
+
],
|
|
37
|
+
PermitMeta: [
|
|
38
|
+
{ name: "kind", type: "uint8" },
|
|
39
|
+
{ name: "paymentId", type: "bytes16" },
|
|
40
|
+
{ name: "nonce", type: "uint256" },
|
|
41
|
+
{ name: "validAfter", type: "uint256" },
|
|
42
|
+
{ name: "validBefore", type: "uint256" }
|
|
43
|
+
],
|
|
44
|
+
Payment: [
|
|
45
|
+
{ name: "payToken", type: "address" },
|
|
46
|
+
{ name: "payAmount", type: "uint256" },
|
|
47
|
+
{ name: "payTo", type: "address" }
|
|
48
|
+
],
|
|
49
|
+
Fee: [
|
|
50
|
+
{ name: "feeTo", type: "address" },
|
|
51
|
+
{ name: "feeAmount", type: "uint256" }
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
var paymentPermitABI = [
|
|
55
|
+
{
|
|
56
|
+
type: "function",
|
|
57
|
+
name: "permitTransferFrom",
|
|
58
|
+
inputs: [
|
|
59
|
+
{
|
|
60
|
+
name: "permit",
|
|
61
|
+
type: "tuple",
|
|
62
|
+
components: [
|
|
63
|
+
{
|
|
64
|
+
name: "meta",
|
|
65
|
+
type: "tuple",
|
|
66
|
+
components: [
|
|
67
|
+
{ name: "kind", type: "uint8" },
|
|
68
|
+
{ name: "paymentId", type: "bytes16" },
|
|
69
|
+
{ name: "nonce", type: "uint256" },
|
|
70
|
+
{ name: "validAfter", type: "uint256" },
|
|
71
|
+
{ name: "validBefore", type: "uint256" }
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
{ name: "buyer", type: "address" },
|
|
75
|
+
{ name: "caller", type: "address" },
|
|
76
|
+
{
|
|
77
|
+
name: "payment",
|
|
78
|
+
type: "tuple",
|
|
79
|
+
components: [
|
|
80
|
+
{ name: "payToken", type: "address" },
|
|
81
|
+
{ name: "payAmount", type: "uint256" },
|
|
82
|
+
{ name: "payTo", type: "address" }
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "fee",
|
|
87
|
+
type: "tuple",
|
|
88
|
+
components: [
|
|
89
|
+
{ name: "feeTo", type: "address" },
|
|
90
|
+
{ name: "feeAmount", type: "uint256" }
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{ name: "owner", type: "address" },
|
|
96
|
+
{ name: "signature", type: "bytes" }
|
|
97
|
+
],
|
|
98
|
+
outputs: [],
|
|
99
|
+
stateMutability: "nonpayable"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: "function",
|
|
103
|
+
name: "balanceOf",
|
|
104
|
+
inputs: [{ name: "account", type: "address" }],
|
|
105
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
106
|
+
stateMutability: "view"
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
var PAYMENT_PERMIT_ADDRESSES = {
|
|
110
|
+
"eip155:56": "0x402085c248EeA27D92E8b30b2C58ed07f9E30001",
|
|
111
|
+
// BSC Mainnet
|
|
112
|
+
"eip155:97": "0x402085c248EeA27D92E8b30b2C58ed07f9E30002",
|
|
113
|
+
// BSC Testnet
|
|
114
|
+
"eip155:8453": "0x402085c248EeA27D92E8b30b2C58ed07f9E30003",
|
|
115
|
+
// Base
|
|
116
|
+
"eip155:84532": "0x402085c248EeA27D92E8b30b2C58ed07f9E30004"
|
|
117
|
+
// Base Sepolia
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/utils.ts
|
|
121
|
+
var import_viem = require("viem");
|
|
122
|
+
function getEvmChainId(network) {
|
|
123
|
+
if (network.startsWith("eip155:")) {
|
|
124
|
+
const idStr = network.split(":")[1];
|
|
125
|
+
const chainId = parseInt(idStr, 10);
|
|
126
|
+
if (isNaN(chainId)) {
|
|
127
|
+
throw new Error(`Invalid CAIP-2 chain ID: ${network}`);
|
|
128
|
+
}
|
|
129
|
+
return chainId;
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`Unsupported network format: ${network} (expected eip155:CHAIN_ID)`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/exact_permit/facilitator/errors.ts
|
|
135
|
+
var INVALID_SCHEME = "invalid_exact_permit_evm_scheme";
|
|
136
|
+
var MISSING_PERMIT_ADDRESS = "missing_payment_permit_address";
|
|
137
|
+
var NETWORK_MISMATCH = "invalid_exact_permit_evm_network_mismatch";
|
|
138
|
+
var INVALID_SIGNATURE = "invalid_exact_permit_evm_payload_signature";
|
|
139
|
+
var RECIPIENT_MISMATCH = "invalid_exact_permit_evm_payload_recipient_mismatch";
|
|
140
|
+
var TOKEN_MISMATCH = "invalid_exact_permit_evm_payload_token_mismatch";
|
|
141
|
+
var VALID_BEFORE_EXPIRED = "invalid_exact_permit_evm_payload_valid_before";
|
|
142
|
+
var VALID_AFTER_FUTURE = "invalid_exact_permit_evm_payload_valid_after";
|
|
143
|
+
var VALUE_MISMATCH = "invalid_exact_permit_evm_payload_value_mismatch";
|
|
144
|
+
var FEE_EXCEEDS_LIMIT = "invalid_exact_permit_evm_fee_exceeds_limit";
|
|
145
|
+
var INSUFFICIENT_FUNDS = "insufficient_funds";
|
|
146
|
+
var INVALID_TRANSACTION_STATE = "invalid_transaction_state";
|
|
147
|
+
var TRANSACTION_FAILED = "transaction_failed";
|
|
148
|
+
|
|
149
|
+
// src/exact_permit/facilitator/eip712.ts
|
|
150
|
+
async function verifyPermitEIP712(signer, payload, requirements, evmPayload, baseFeeLimit) {
|
|
151
|
+
const payer = evmPayload.permit.buyer;
|
|
152
|
+
if (payload.accepted.scheme !== "exact_permit" || requirements.scheme !== "exact_permit") {
|
|
153
|
+
return {
|
|
154
|
+
isValid: false,
|
|
155
|
+
invalidReason: INVALID_SCHEME,
|
|
156
|
+
payer
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (payload.accepted.network !== requirements.network) {
|
|
160
|
+
return {
|
|
161
|
+
isValid: false,
|
|
162
|
+
invalidReason: NETWORK_MISMATCH,
|
|
163
|
+
payer
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const permitAddress = PAYMENT_PERMIT_ADDRESSES[requirements.network];
|
|
167
|
+
if (!permitAddress) {
|
|
168
|
+
return {
|
|
169
|
+
isValid: false,
|
|
170
|
+
invalidReason: MISSING_PERMIT_ADDRESS,
|
|
171
|
+
payer
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const chainId = getEvmChainId(requirements.network);
|
|
175
|
+
const typedData = {
|
|
176
|
+
address: evmPayload.permit.buyer,
|
|
177
|
+
types: paymentPermitTypes,
|
|
178
|
+
primaryType: "PaymentPermitDetails",
|
|
179
|
+
domain: {
|
|
180
|
+
name: "PaymentPermit",
|
|
181
|
+
chainId,
|
|
182
|
+
verifyingContract: permitAddress
|
|
183
|
+
},
|
|
184
|
+
message: {
|
|
185
|
+
meta: {
|
|
186
|
+
kind: evmPayload.permit.meta.kind,
|
|
187
|
+
paymentId: evmPayload.permit.meta.paymentId,
|
|
188
|
+
nonce: BigInt(evmPayload.permit.meta.nonce),
|
|
189
|
+
validAfter: BigInt(evmPayload.permit.meta.validAfter),
|
|
190
|
+
validBefore: BigInt(evmPayload.permit.meta.validBefore)
|
|
191
|
+
},
|
|
192
|
+
buyer: evmPayload.permit.buyer,
|
|
193
|
+
caller: evmPayload.permit.caller,
|
|
194
|
+
payment: {
|
|
195
|
+
payToken: evmPayload.permit.payment.payToken,
|
|
196
|
+
payAmount: BigInt(evmPayload.permit.payment.payAmount),
|
|
197
|
+
payTo: evmPayload.permit.payment.payTo
|
|
198
|
+
},
|
|
199
|
+
fee: {
|
|
200
|
+
feeTo: evmPayload.permit.fee.feeTo,
|
|
201
|
+
feeAmount: BigInt(evmPayload.permit.fee.feeAmount)
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
signature: evmPayload.signature
|
|
205
|
+
};
|
|
206
|
+
try {
|
|
207
|
+
const isValid = await signer.verifyTypedData(typedData);
|
|
208
|
+
if (!isValid) {
|
|
209
|
+
return {
|
|
210
|
+
isValid: false,
|
|
211
|
+
invalidReason: INVALID_SIGNATURE,
|
|
212
|
+
payer
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
return {
|
|
217
|
+
isValid: false,
|
|
218
|
+
invalidReason: INVALID_SIGNATURE,
|
|
219
|
+
payer
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const payloadToken = evmPayload.permit.payment.payToken.toLowerCase();
|
|
223
|
+
const requiresAsset = requirements.asset.toLowerCase();
|
|
224
|
+
if (payloadToken !== requiresAsset) {
|
|
225
|
+
return {
|
|
226
|
+
isValid: false,
|
|
227
|
+
invalidReason: TOKEN_MISMATCH,
|
|
228
|
+
payer
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const payloadPayTo = evmPayload.permit.payment.payTo.toLowerCase();
|
|
232
|
+
const requiresPayTo = requirements.payTo.toLowerCase();
|
|
233
|
+
if (payloadPayTo !== requiresPayTo) {
|
|
234
|
+
return {
|
|
235
|
+
isValid: false,
|
|
236
|
+
invalidReason: RECIPIENT_MISMATCH,
|
|
237
|
+
payer
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
241
|
+
if (BigInt(evmPayload.permit.meta.validBefore) < BigInt(now + 6)) {
|
|
242
|
+
return {
|
|
243
|
+
isValid: false,
|
|
244
|
+
invalidReason: VALID_BEFORE_EXPIRED,
|
|
245
|
+
payer
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (BigInt(evmPayload.permit.meta.validAfter) > BigInt(now)) {
|
|
249
|
+
return {
|
|
250
|
+
isValid: false,
|
|
251
|
+
invalidReason: VALID_AFTER_FUTURE,
|
|
252
|
+
payer
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (BigInt(evmPayload.permit.payment.payAmount) !== BigInt(requirements.amount)) {
|
|
256
|
+
return {
|
|
257
|
+
isValid: false,
|
|
258
|
+
invalidReason: VALUE_MISMATCH,
|
|
259
|
+
payer
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (baseFeeLimit !== void 0 && BigInt(evmPayload.permit.fee.feeAmount) > baseFeeLimit) {
|
|
263
|
+
return {
|
|
264
|
+
isValid: false,
|
|
265
|
+
invalidReason: FEE_EXCEEDS_LIMIT,
|
|
266
|
+
payer
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
const totalNeeded = BigInt(evmPayload.permit.payment.payAmount) + BigInt(evmPayload.permit.fee.feeAmount);
|
|
271
|
+
const balance = await signer.readContract({
|
|
272
|
+
address: evmPayload.permit.payment.payToken,
|
|
273
|
+
abi: paymentPermitABI,
|
|
274
|
+
functionName: "balanceOf",
|
|
275
|
+
args: [evmPayload.permit.buyer]
|
|
276
|
+
});
|
|
277
|
+
if (BigInt(balance) < totalNeeded) {
|
|
278
|
+
return {
|
|
279
|
+
isValid: false,
|
|
280
|
+
invalidReason: INSUFFICIENT_FUNDS,
|
|
281
|
+
invalidMessage: `Insufficient funds. Required: ${totalNeeded.toString()}, Available: ${balance.toString()}`,
|
|
282
|
+
payer
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
} catch {
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
isValid: true,
|
|
289
|
+
invalidReason: void 0,
|
|
290
|
+
payer
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
async function settlePermitEIP712(signer, payload, requirements, evmPayload, baseFeeLimit) {
|
|
294
|
+
const payer = evmPayload.permit.buyer;
|
|
295
|
+
const valid = await verifyPermitEIP712(signer, payload, requirements, evmPayload, baseFeeLimit);
|
|
296
|
+
if (!valid.isValid) {
|
|
297
|
+
return {
|
|
298
|
+
success: false,
|
|
299
|
+
network: payload.accepted.network,
|
|
300
|
+
transaction: "",
|
|
301
|
+
errorReason: valid.invalidReason ?? INVALID_SCHEME,
|
|
302
|
+
payer
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const permitAddress = PAYMENT_PERMIT_ADDRESSES[requirements.network];
|
|
307
|
+
const permitTuple = {
|
|
308
|
+
meta: {
|
|
309
|
+
kind: evmPayload.permit.meta.kind,
|
|
310
|
+
paymentId: evmPayload.permit.meta.paymentId,
|
|
311
|
+
nonce: BigInt(evmPayload.permit.meta.nonce),
|
|
312
|
+
validAfter: BigInt(evmPayload.permit.meta.validAfter),
|
|
313
|
+
validBefore: BigInt(evmPayload.permit.meta.validBefore)
|
|
314
|
+
},
|
|
315
|
+
buyer: evmPayload.permit.buyer,
|
|
316
|
+
caller: evmPayload.permit.caller,
|
|
317
|
+
payment: {
|
|
318
|
+
payToken: evmPayload.permit.payment.payToken,
|
|
319
|
+
payAmount: BigInt(evmPayload.permit.payment.payAmount),
|
|
320
|
+
payTo: evmPayload.permit.payment.payTo
|
|
321
|
+
},
|
|
322
|
+
fee: {
|
|
323
|
+
feeTo: evmPayload.permit.fee.feeTo,
|
|
324
|
+
feeAmount: BigInt(evmPayload.permit.fee.feeAmount)
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const tx = await signer.writeContract({
|
|
328
|
+
address: permitAddress,
|
|
329
|
+
abi: paymentPermitABI,
|
|
330
|
+
functionName: "permitTransferFrom",
|
|
331
|
+
args: [permitTuple, evmPayload.permit.buyer, evmPayload.signature]
|
|
332
|
+
});
|
|
333
|
+
const receipt = await signer.waitForTransactionReceipt({ hash: tx });
|
|
334
|
+
if (receipt.status !== "success") {
|
|
335
|
+
return {
|
|
336
|
+
success: false,
|
|
337
|
+
errorReason: INVALID_TRANSACTION_STATE,
|
|
338
|
+
transaction: tx,
|
|
339
|
+
network: payload.accepted.network,
|
|
340
|
+
payer
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
success: true,
|
|
345
|
+
transaction: tx,
|
|
346
|
+
network: payload.accepted.network,
|
|
347
|
+
payer
|
|
348
|
+
};
|
|
349
|
+
} catch {
|
|
350
|
+
return {
|
|
351
|
+
success: false,
|
|
352
|
+
errorReason: TRANSACTION_FAILED,
|
|
353
|
+
transaction: "",
|
|
354
|
+
network: payload.accepted.network,
|
|
355
|
+
payer
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/exact_permit/facilitator/scheme.ts
|
|
361
|
+
var ExactPermitEvmScheme = class {
|
|
362
|
+
/**
|
|
363
|
+
* Creates a new ExactPermitEvmScheme facilitator instance.
|
|
364
|
+
*
|
|
365
|
+
* @param signer - The EVM signer for facilitator operations
|
|
366
|
+
* @param baseFeeLimit - Optional maximum fee amount the facilitator accepts
|
|
367
|
+
*/
|
|
368
|
+
constructor(signer, baseFeeLimit) {
|
|
369
|
+
this.signer = signer;
|
|
370
|
+
this.baseFeeLimit = baseFeeLimit;
|
|
371
|
+
this.scheme = "exact_permit";
|
|
372
|
+
this.caipFamily = "eip155:*";
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Returns the PaymentPermit contract address for the network.
|
|
376
|
+
*
|
|
377
|
+
* @param network - The network identifier
|
|
378
|
+
* @returns Extra data containing the permit contract address
|
|
379
|
+
*/
|
|
380
|
+
getExtra(network) {
|
|
381
|
+
const permitAddress = PAYMENT_PERMIT_ADDRESSES[network];
|
|
382
|
+
if (!permitAddress) {
|
|
383
|
+
return void 0;
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
paymentPermitAddress: permitAddress
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Returns facilitator wallet addresses.
|
|
391
|
+
*
|
|
392
|
+
* @param _ - The network identifier (unused)
|
|
393
|
+
* @returns Array of facilitator wallet addresses
|
|
394
|
+
*/
|
|
395
|
+
getSigners(_) {
|
|
396
|
+
return [...this.signer.getAddresses()];
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Verifies an EVM exact_permit payment payload.
|
|
400
|
+
*
|
|
401
|
+
* @param payload - The payment payload to verify
|
|
402
|
+
* @param requirements - The payment requirements
|
|
403
|
+
* @param _context - Optional facilitator context (unused)
|
|
404
|
+
* @returns Promise resolving to verification response
|
|
405
|
+
*/
|
|
406
|
+
async verify(payload, requirements, _context) {
|
|
407
|
+
const evmPayload = payload.payload;
|
|
408
|
+
return verifyPermitEIP712(this.signer, payload, requirements, evmPayload, this.baseFeeLimit);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Settles an EVM exact_permit payment by calling permitTransferFrom.
|
|
412
|
+
*
|
|
413
|
+
* @param payload - The payment payload to settle
|
|
414
|
+
* @param requirements - The payment requirements
|
|
415
|
+
* @param _context - Optional facilitator context (unused)
|
|
416
|
+
* @returns Promise resolving to settlement response
|
|
417
|
+
*/
|
|
418
|
+
async settle(payload, requirements, _context) {
|
|
419
|
+
const evmPayload = payload.payload;
|
|
420
|
+
return settlePermitEIP712(this.signer, payload, requirements, evmPayload, this.baseFeeLimit);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
// src/exact_permit/facilitator/register.ts
|
|
425
|
+
function registerExactPermitEvmScheme(facilitator, config) {
|
|
426
|
+
facilitator.register(
|
|
427
|
+
config.networks,
|
|
428
|
+
new ExactPermitEvmScheme(config.signer, config.baseFeeLimit)
|
|
429
|
+
);
|
|
430
|
+
return facilitator;
|
|
431
|
+
}
|
|
432
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
433
|
+
0 && (module.exports = {
|
|
434
|
+
ExactPermitEvmScheme,
|
|
435
|
+
registerExactPermitEvmScheme
|
|
436
|
+
});
|
|
437
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/exact_permit/facilitator/index.ts","../../../../src/constants.ts","../../../../src/utils.ts","../../../../src/exact_permit/facilitator/errors.ts","../../../../src/exact_permit/facilitator/eip712.ts","../../../../src/exact_permit/facilitator/scheme.ts","../../../../src/exact_permit/facilitator/register.ts"],"sourcesContent":["export { ExactPermitEvmScheme } from \"./scheme\";\nexport { registerExactPermitEvmScheme } from \"./register\";\nexport type { EvmPermitFacilitatorConfig } from \"./register\";\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/**\n * Permit2 EIP-712 types for signing PermitWitnessTransferFrom.\n * Must match the exact format expected by the Permit2 contract.\n * Note: Types must be in ALPHABETICAL order after the primary type (TokenPermissions < Witness).\n */\nexport const permit2WitnessTypes = {\n PermitWitnessTransferFrom: [\n { name: \"permitted\", type: \"TokenPermissions\" },\n { name: \"spender\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n { name: \"witness\", type: \"Witness\" },\n ],\n TokenPermissions: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n Witness: [\n { name: \"to\", type: \"address\" },\n { name: \"validAfter\", type: \"uint256\" },\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/**\n * EIP-2612 Permit EIP-712 types for signing token.permit().\n */\nexport const eip2612PermitTypes = {\n Permit: [\n { name: \"owner\", type: \"address\" },\n { name: \"spender\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n} as const;\n\n/**\n * EIP-2612 nonces ABI for querying current nonce.\n */\nexport const eip2612NoncesAbi = [\n {\n type: \"function\",\n name: \"nonces\",\n inputs: [{ name: \"owner\", type: \"address\" }],\n outputs: [{ type: \"uint256\" }],\n stateMutability: \"view\",\n },\n] as const;\n\n/** ERC-20 approve(address,uint256) ABI for encoding/decoding approval calldata. */\nexport const erc20ApproveAbi = [\n {\n type: \"function\",\n name: \"approve\",\n inputs: [\n { name: \"spender\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n outputs: [{ type: \"bool\" }],\n stateMutability: \"nonpayable\",\n },\n] as const;\n\n/** ERC-20 allowance(address,address) ABI for checking spender approval. */\nexport const erc20AllowanceAbi = [\n {\n type: \"function\",\n name: \"allowance\",\n inputs: [\n { name: \"owner\", type: \"address\" },\n { name: \"spender\", type: \"address\" },\n ],\n outputs: [{ type: \"uint256\" }],\n stateMutability: \"view\",\n },\n] as const;\n\n/** Gas limit for a standard ERC-20 approve() transaction. */\nexport const ERC20_APPROVE_GAS_LIMIT = 70_000n;\n\n/** Fallback max fee per gas (1 gwei) when fee estimation fails. */\nexport const DEFAULT_MAX_FEE_PER_GAS = 1_000_000_000n;\n\n/** Fallback max priority fee per gas (0.1 gwei) when fee estimation fails. */\nexport const DEFAULT_MAX_PRIORITY_FEE_PER_GAS = 100_000_000n;\n\n/**\n * Canonical Permit2 contract address.\n * Same address on all EVM chains via CREATE2 deployment.\n *\n * @see https://github.com/Uniswap/permit2\n */\nexport const PERMIT2_ADDRESS = \"0x000000000022D473030F116dDEE9F6B43aC78BA3\" as const;\n\n/**\n * x402ExactPermit2Proxy contract address.\n * Vanity address: 0x4020...0001 for easy recognition.\n * This address is deterministic based on:\n * - Arachnid's deterministic deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C)\n * - Vanity-mined salt for prefix 0x4020 and suffix 0001\n * - Contract bytecode + constructor args (PERMIT2_ADDRESS)\n */\nexport const x402ExactPermit2ProxyAddress = \"0x402085c248EeA27D92E8b30b2C58ed07f9E20001\" as const;\n\n/**\n * x402UptoPermit2Proxy contract address.\n * Vanity address: 0x4020...0002 for easy recognition.\n * This address is deterministic based on:\n * - Arachnid's deterministic deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C)\n * - Vanity-mined salt for prefix 0x4020 and suffix 0002\n * - Contract bytecode + constructor args (PERMIT2_ADDRESS)\n */\nexport const x402UptoPermit2ProxyAddress = \"0x402039b3d6E6BEC5A02c2C9fd937ac17A6940002\" as const;\n\n/**\n * Shared ABI components for the Permit2 witness tuple.\n * Used in both x402ExactPermit2ProxyABI and x402UptoPermit2ProxyABI to keep them in sync.\n * The upto contract's witness struct is identical to exact (both remove 'extra' post-audit).\n */\nconst permit2WitnessABIComponents = [\n { name: \"to\", type: \"address\", internalType: \"address\" },\n { name: \"validAfter\", type: \"uint256\", internalType: \"uint256\" },\n] as const;\n\n/**\n * x402UptoPermit2Proxy ABI - settle function for upto payment scheme (variable amounts).\n * Updated post-audit: 'extra' removed from witness struct, 'initialize()' removed (now\n * a constructor arg), and error names aligned with x402ExactPermit2Proxy.\n */\nexport const x402UptoPermit2ProxyABI = [\n {\n type: \"function\",\n name: \"PERMIT2\",\n inputs: [],\n outputs: [{ name: \"\", type: \"address\", internalType: \"contract ISignatureTransfer\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"WITNESS_TYPEHASH\",\n inputs: [],\n outputs: [{ name: \"\", type: \"bytes32\", internalType: \"bytes32\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"WITNESS_TYPE_STRING\",\n inputs: [],\n outputs: [{ name: \"\", type: \"string\", internalType: \"string\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"settle\",\n inputs: [\n {\n name: \"permit\",\n type: \"tuple\",\n internalType: \"struct ISignatureTransfer.PermitTransferFrom\",\n components: [\n {\n name: \"permitted\",\n type: \"tuple\",\n internalType: \"struct ISignatureTransfer.TokenPermissions\",\n components: [\n { name: \"token\", type: \"address\", internalType: \"address\" },\n { name: \"amount\", type: \"uint256\", internalType: \"uint256\" },\n ],\n },\n { name: \"nonce\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"deadline\", type: \"uint256\", internalType: \"uint256\" },\n ],\n },\n { name: \"owner\", type: \"address\", internalType: \"address\" },\n {\n name: \"witness\",\n type: \"tuple\",\n internalType: \"struct x402UptoPermit2Proxy.Witness\",\n components: permit2WitnessABIComponents,\n },\n { name: \"signature\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"settleWithPermit\",\n inputs: [\n {\n name: \"permit2612\",\n type: \"tuple\",\n internalType: \"struct x402UptoPermit2Proxy.EIP2612Permit\",\n components: [\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"deadline\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"r\", type: \"bytes32\", internalType: \"bytes32\" },\n { name: \"s\", type: \"bytes32\", internalType: \"bytes32\" },\n { name: \"v\", type: \"uint8\", internalType: \"uint8\" },\n ],\n },\n {\n name: \"permit\",\n type: \"tuple\",\n internalType: \"struct ISignatureTransfer.PermitTransferFrom\",\n components: [\n {\n name: \"permitted\",\n type: \"tuple\",\n internalType: \"struct ISignatureTransfer.TokenPermissions\",\n components: [\n { name: \"token\", type: \"address\", internalType: \"address\" },\n { name: \"amount\", type: \"uint256\", internalType: \"uint256\" },\n ],\n },\n { name: \"nonce\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"deadline\", type: \"uint256\", internalType: \"uint256\" },\n ],\n },\n { name: \"owner\", type: \"address\", internalType: \"address\" },\n {\n name: \"witness\",\n type: \"tuple\",\n internalType: \"struct x402UptoPermit2Proxy.Witness\",\n components: permit2WitnessABIComponents,\n },\n { name: \"signature\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n { type: \"event\", name: \"Settled\", inputs: [], anonymous: false },\n { type: \"event\", name: \"SettledWithPermit\", inputs: [], anonymous: false },\n { type: \"error\", name: \"InvalidAmount\", inputs: [] },\n { type: \"error\", name: \"InvalidDestination\", inputs: [] },\n { type: \"error\", name: \"InvalidOwner\", inputs: [] },\n { type: \"error\", name: \"InvalidPermit2Address\", inputs: [] },\n { type: \"error\", name: \"PaymentTooEarly\", inputs: [] },\n { type: \"error\", name: \"Permit2612AmountMismatch\", inputs: [] },\n { type: \"error\", name: \"ReentrancyGuardReentrantCall\", inputs: [] },\n] as const;\n\n/**\n * x402ExactPermit2Proxy ABI - settle function for exact payment scheme.\n */\nexport const x402ExactPermit2ProxyABI = [\n {\n type: \"function\",\n name: \"PERMIT2\",\n inputs: [],\n outputs: [{ name: \"\", type: \"address\", internalType: \"contract ISignatureTransfer\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"WITNESS_TYPEHASH\",\n inputs: [],\n outputs: [{ name: \"\", type: \"bytes32\", internalType: \"bytes32\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"WITNESS_TYPE_STRING\",\n inputs: [],\n outputs: [{ name: \"\", type: \"string\", internalType: \"string\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"settle\",\n inputs: [\n {\n name: \"permit\",\n type: \"tuple\",\n internalType: \"struct ISignatureTransfer.PermitTransferFrom\",\n components: [\n {\n name: \"permitted\",\n type: \"tuple\",\n internalType: \"struct ISignatureTransfer.TokenPermissions\",\n components: [\n { name: \"token\", type: \"address\", internalType: \"address\" },\n { name: \"amount\", type: \"uint256\", internalType: \"uint256\" },\n ],\n },\n { name: \"nonce\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"deadline\", type: \"uint256\", internalType: \"uint256\" },\n ],\n },\n { name: \"owner\", type: \"address\", internalType: \"address\" },\n {\n name: \"witness\",\n type: \"tuple\",\n internalType: \"struct x402ExactPermit2Proxy.Witness\",\n components: permit2WitnessABIComponents,\n },\n { name: \"signature\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"settleWithPermit\",\n inputs: [\n {\n name: \"permit2612\",\n type: \"tuple\",\n internalType: \"struct x402ExactPermit2Proxy.EIP2612Permit\",\n components: [\n { name: \"value\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"deadline\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"r\", type: \"bytes32\", internalType: \"bytes32\" },\n { name: \"s\", type: \"bytes32\", internalType: \"bytes32\" },\n { name: \"v\", type: \"uint8\", internalType: \"uint8\" },\n ],\n },\n {\n name: \"permit\",\n type: \"tuple\",\n internalType: \"struct ISignatureTransfer.PermitTransferFrom\",\n components: [\n {\n name: \"permitted\",\n type: \"tuple\",\n internalType: \"struct ISignatureTransfer.TokenPermissions\",\n components: [\n { name: \"token\", type: \"address\", internalType: \"address\" },\n { name: \"amount\", type: \"uint256\", internalType: \"uint256\" },\n ],\n },\n { name: \"nonce\", type: \"uint256\", internalType: \"uint256\" },\n { name: \"deadline\", type: \"uint256\", internalType: \"uint256\" },\n ],\n },\n { name: \"owner\", type: \"address\", internalType: \"address\" },\n {\n name: \"witness\",\n type: \"tuple\",\n internalType: \"struct x402ExactPermit2Proxy.Witness\",\n components: permit2WitnessABIComponents,\n },\n { name: \"signature\", type: \"bytes\", internalType: \"bytes\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n { type: \"event\", name: \"Settled\", inputs: [], anonymous: false },\n { type: \"event\", name: \"SettledWithPermit\", inputs: [], anonymous: false },\n { type: \"error\", name: \"InvalidAmount\", inputs: [] },\n { type: \"error\", name: \"InvalidDestination\", inputs: [] },\n { type: \"error\", name: \"InvalidOwner\", inputs: [] },\n { type: \"error\", name: \"InvalidPermit2Address\", inputs: [] },\n { type: \"error\", name: \"PaymentTooEarly\", inputs: [] },\n { type: \"error\", name: \"Permit2612AmountMismatch\", inputs: [] },\n { type: \"error\", name: \"ReentrancyGuardReentrantCall\", inputs: [] },\n] as const;\n\n// --- PaymentPermit (exact_permit) constants ---\n\n/**\n * EIP-712 type definitions for PaymentPermit on EVM.\n * Used by the exact_permit scheme for structured permit signing.\n */\nexport const paymentPermitTypes = {\n PaymentPermitDetails: [\n { name: \"meta\", type: \"PermitMeta\" },\n { name: \"buyer\", type: \"address\" },\n { name: \"caller\", type: \"address\" },\n { name: \"payment\", type: \"Payment\" },\n { name: \"fee\", type: \"Fee\" },\n ],\n PermitMeta: [\n { name: \"kind\", type: \"uint8\" },\n { name: \"paymentId\", type: \"bytes16\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n ],\n Payment: [\n { name: \"payToken\", type: \"address\" },\n { name: \"payAmount\", type: \"uint256\" },\n { name: \"payTo\", type: \"address\" },\n ],\n Fee: [\n { name: \"feeTo\", type: \"address\" },\n { name: \"feeAmount\", type: \"uint256\" },\n ],\n} as const;\n\n/**\n * ABI for PaymentPermit contract on EVM.\n */\nexport const paymentPermitABI = [\n {\n type: \"function\",\n name: \"permitTransferFrom\",\n inputs: [\n {\n name: \"permit\",\n type: \"tuple\",\n components: [\n {\n name: \"meta\",\n type: \"tuple\",\n components: [\n { name: \"kind\", type: \"uint8\" },\n { name: \"paymentId\", type: \"bytes16\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n ],\n },\n { name: \"buyer\", type: \"address\" },\n { name: \"caller\", type: \"address\" },\n {\n name: \"payment\",\n type: \"tuple\",\n components: [\n { name: \"payToken\", type: \"address\" },\n { name: \"payAmount\", type: \"uint256\" },\n { name: \"payTo\", type: \"address\" },\n ],\n },\n {\n name: \"fee\",\n type: \"tuple\",\n components: [\n { name: \"feeTo\", type: \"address\" },\n { name: \"feeAmount\", type: \"uint256\" },\n ],\n },\n ],\n },\n { name: \"owner\", type: \"address\" },\n { name: \"signature\", type: \"bytes\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"balanceOf\",\n inputs: [{ name: \"account\", type: \"address\" }],\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n] as const;\n\n/**\n * PaymentPermit contract addresses per EVM network.\n */\nexport const PAYMENT_PERMIT_ADDRESSES: Record<string, `0x${string}`> = {\n \"eip155:56\": \"0x402085c248EeA27D92E8b30b2C58ed07f9E30001\", // BSC Mainnet\n \"eip155:97\": \"0x402085c248EeA27D92E8b30b2C58ed07f9E30002\", // BSC Testnet\n \"eip155:8453\": \"0x402085c248EeA27D92E8b30b2C58ed07f9E30003\", // Base\n \"eip155:84532\": \"0x402085c248EeA27D92E8b30b2C58ed07f9E30004\", // Base Sepolia\n};\n\n/**\n * PaymentPermit kind constants.\n */\nexport const PERMIT_KIND = {\n PAYMENT_ONLY: 0,\n} as const;\n\n/**\n * Zero address constant.\n */\nexport const ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\" as `0x${string}`;\n","import { toHex } from \"viem\";\n\n/**\n * Extract chain ID from a CAIP-2 network identifier (eip155:CHAIN_ID).\n *\n * @param network - The network identifier in CAIP-2 format (e.g., \"eip155:8453\")\n * @returns The numeric chain ID\n * @throws Error if the network format is invalid\n */\nexport function getEvmChainId(network: string): number {\n if (network.startsWith(\"eip155:\")) {\n const idStr = network.split(\":\")[1];\n const chainId = parseInt(idStr, 10);\n if (isNaN(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${network}`);\n }\n return chainId;\n }\n\n throw new Error(`Unsupported network format: ${network} (expected eip155:CHAIN_ID)`);\n}\n\n/**\n * Get the crypto object from the global scope.\n *\n * @returns The crypto object\n * @throws Error if crypto API is not available\n */\nfunction getCrypto(): Crypto {\n const cryptoObj = globalThis.crypto as Crypto | undefined;\n if (!cryptoObj) {\n throw new Error(\"Crypto API not available\");\n }\n return cryptoObj;\n}\n\n/**\n * Create a random 32-byte nonce for EIP-3009 authorization.\n *\n * @returns A hex-encoded 32-byte nonce\n */\nexport function createNonce(): `0x${string}` {\n return toHex(getCrypto().getRandomValues(new Uint8Array(32)));\n}\n\n/**\n * Creates a random 256-bit nonce for Permit2.\n * Permit2 uses uint256 nonces (not bytes32 like EIP-3009).\n *\n * @returns A string representation of the random nonce\n */\nexport function createPermit2Nonce(): string {\n const randomBytes = getCrypto().getRandomValues(new Uint8Array(32));\n return BigInt(toHex(randomBytes)).toString();\n}\n","// Verification error reasons for EVM exact_permit scheme.\nexport const INVALID_SCHEME = \"invalid_exact_permit_evm_scheme\";\nexport const MISSING_PERMIT_ADDRESS = \"missing_payment_permit_address\";\nexport const NETWORK_MISMATCH = \"invalid_exact_permit_evm_network_mismatch\";\nexport const INVALID_SIGNATURE = \"invalid_exact_permit_evm_payload_signature\";\nexport const RECIPIENT_MISMATCH = \"invalid_exact_permit_evm_payload_recipient_mismatch\";\nexport const TOKEN_MISMATCH = \"invalid_exact_permit_evm_payload_token_mismatch\";\nexport const VALID_BEFORE_EXPIRED = \"invalid_exact_permit_evm_payload_valid_before\";\nexport const VALID_AFTER_FUTURE = \"invalid_exact_permit_evm_payload_valid_after\";\nexport const VALUE_MISMATCH = \"invalid_exact_permit_evm_payload_value_mismatch\";\nexport const FEE_EXCEEDS_LIMIT = \"invalid_exact_permit_evm_fee_exceeds_limit\";\nexport const INSUFFICIENT_FUNDS = \"insufficient_funds\";\nexport const INVALID_TRANSACTION_STATE = \"invalid_transaction_state\";\nexport const TRANSACTION_FAILED = \"transaction_failed\";\n","import {\n PaymentPayload,\n PaymentRequirements,\n SettleResponse,\n VerifyResponse,\n} from \"@bankofai/x402-core/types\";\nimport {\n paymentPermitTypes,\n paymentPermitABI,\n PAYMENT_PERMIT_ADDRESSES,\n} from \"../../constants\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactPermitEvmPayload } from \"../../types\";\nimport { getEvmChainId } from \"../../utils\";\nimport * as errors from \"./errors\";\n\n/**\n * Verifies an EIP-712 PaymentPermit payload on EVM.\n *\n * @param signer - The facilitator signer for contract reads and signature verification\n * @param payload - The payment payload to verify\n * @param requirements - The payment requirements\n * @param evmPayload - The EVM-specific permit payload data\n * @param baseFeeLimit - Optional maximum fee amount the facilitator accepts\n * @returns Promise resolving to verification response\n */\nexport async function verifyPermitEIP712(\n signer: FacilitatorEvmSigner,\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n evmPayload: ExactPermitEvmPayload,\n baseFeeLimit?: bigint,\n): Promise<VerifyResponse> {\n const payer = evmPayload.permit.buyer;\n\n // Verify scheme matches\n if (payload.accepted.scheme !== \"exact_permit\" || requirements.scheme !== \"exact_permit\") {\n return {\n isValid: false,\n invalidReason: errors.INVALID_SCHEME,\n payer,\n };\n }\n\n // Verify network matches\n if (payload.accepted.network !== requirements.network) {\n return {\n isValid: false,\n invalidReason: errors.NETWORK_MISMATCH,\n payer,\n };\n }\n\n // Verify PaymentPermit contract exists for the network\n const permitAddress = PAYMENT_PERMIT_ADDRESSES[requirements.network];\n if (!permitAddress) {\n return {\n isValid: false,\n invalidReason: errors.MISSING_PERMIT_ADDRESS,\n payer,\n };\n }\n\n const chainId = getEvmChainId(requirements.network);\n\n // Build EIP-712 typed data for signature verification\n const typedData = {\n address: evmPayload.permit.buyer,\n types: paymentPermitTypes,\n primaryType: \"PaymentPermitDetails\" as const,\n domain: {\n name: \"PaymentPermit\",\n chainId,\n verifyingContract: permitAddress,\n },\n message: {\n meta: {\n kind: evmPayload.permit.meta.kind,\n paymentId: evmPayload.permit.meta.paymentId,\n nonce: BigInt(evmPayload.permit.meta.nonce),\n validAfter: BigInt(evmPayload.permit.meta.validAfter),\n validBefore: BigInt(evmPayload.permit.meta.validBefore),\n },\n buyer: evmPayload.permit.buyer,\n caller: evmPayload.permit.caller,\n payment: {\n payToken: evmPayload.permit.payment.payToken,\n payAmount: BigInt(evmPayload.permit.payment.payAmount),\n payTo: evmPayload.permit.payment.payTo,\n },\n fee: {\n feeTo: evmPayload.permit.fee.feeTo,\n feeAmount: BigInt(evmPayload.permit.fee.feeAmount),\n },\n },\n signature: evmPayload.signature!,\n };\n\n // Verify signature\n try {\n const isValid = await signer.verifyTypedData(typedData);\n if (!isValid) {\n return {\n isValid: false,\n invalidReason: errors.INVALID_SIGNATURE,\n payer,\n };\n }\n } catch {\n return {\n isValid: false,\n invalidReason: errors.INVALID_SIGNATURE,\n payer,\n };\n }\n\n // Verify payment token matches asset\n const payloadToken = evmPayload.permit.payment.payToken.toLowerCase();\n const requiresAsset = (requirements.asset as string).toLowerCase();\n if (payloadToken !== requiresAsset) {\n return {\n isValid: false,\n invalidReason: errors.TOKEN_MISMATCH,\n payer,\n };\n }\n\n // Verify recipient matches payTo\n const payloadPayTo = evmPayload.permit.payment.payTo.toLowerCase();\n const requiresPayTo = (requirements.payTo as string).toLowerCase();\n if (payloadPayTo !== requiresPayTo) {\n return {\n isValid: false,\n invalidReason: errors.RECIPIENT_MISMATCH,\n payer,\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(evmPayload.permit.meta.validBefore) < BigInt(now + 6)) {\n return {\n isValid: false,\n invalidReason: errors.VALID_BEFORE_EXPIRED,\n payer,\n };\n }\n\n // Verify validAfter is not in the future\n if (BigInt(evmPayload.permit.meta.validAfter) > BigInt(now)) {\n return {\n isValid: false,\n invalidReason: errors.VALID_AFTER_FUTURE,\n payer,\n };\n }\n\n // Verify payment amount matches requirements\n if (BigInt(evmPayload.permit.payment.payAmount) !== BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: errors.VALUE_MISMATCH,\n payer,\n };\n }\n\n // Verify fee does not exceed configured limit\n if (baseFeeLimit !== undefined && BigInt(evmPayload.permit.fee.feeAmount) > baseFeeLimit) {\n return {\n isValid: false,\n invalidReason: errors.FEE_EXCEEDS_LIMIT,\n payer,\n };\n }\n\n // Check balance (payAmount + feeAmount)\n try {\n const totalNeeded =\n BigInt(evmPayload.permit.payment.payAmount) + BigInt(evmPayload.permit.fee.feeAmount);\n const balance = (await signer.readContract({\n address: evmPayload.permit.payment.payToken,\n abi: paymentPermitABI,\n functionName: \"balanceOf\",\n args: [evmPayload.permit.buyer],\n })) as bigint;\n\n if (BigInt(balance) < totalNeeded) {\n return {\n isValid: false,\n invalidReason: errors.INSUFFICIENT_FUNDS,\n invalidMessage: `Insufficient funds. Required: ${totalNeeded.toString()}, Available: ${balance.toString()}`,\n payer,\n };\n }\n } catch {\n // If balance check fails, continue with other validations\n }\n\n return {\n isValid: true,\n invalidReason: undefined,\n payer,\n };\n}\n\n/**\n * Settles an EIP-712 PaymentPermit payment on EVM.\n * Calls the PaymentPermit contract's permitTransferFrom function.\n *\n * @param signer - The facilitator signer for contract writes\n * @param payload - The payment payload to settle\n * @param requirements - The payment requirements\n * @param evmPayload - The EVM-specific permit payload data\n * @param baseFeeLimit - Optional maximum fee amount the facilitator accepts\n * @returns Promise resolving to settlement response\n */\nexport async function settlePermitEIP712(\n signer: FacilitatorEvmSigner,\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n evmPayload: ExactPermitEvmPayload,\n baseFeeLimit?: bigint,\n): Promise<SettleResponse> {\n const payer = evmPayload.permit.buyer;\n\n // Re-verify before settling\n const valid = await verifyPermitEIP712(signer, payload, requirements, evmPayload, baseFeeLimit);\n if (!valid.isValid) {\n return {\n success: false,\n network: payload.accepted.network,\n transaction: \"\",\n errorReason: valid.invalidReason ?? errors.INVALID_SCHEME,\n payer,\n };\n }\n\n try {\n const permitAddress = PAYMENT_PERMIT_ADDRESSES[requirements.network];\n\n // Build the permit tuple for the contract call\n const permitTuple = {\n meta: {\n kind: evmPayload.permit.meta.kind,\n paymentId: evmPayload.permit.meta.paymentId,\n nonce: BigInt(evmPayload.permit.meta.nonce),\n validAfter: BigInt(evmPayload.permit.meta.validAfter),\n validBefore: BigInt(evmPayload.permit.meta.validBefore),\n },\n buyer: evmPayload.permit.buyer,\n caller: evmPayload.permit.caller,\n payment: {\n payToken: evmPayload.permit.payment.payToken,\n payAmount: BigInt(evmPayload.permit.payment.payAmount),\n payTo: evmPayload.permit.payment.payTo,\n },\n fee: {\n feeTo: evmPayload.permit.fee.feeTo,\n feeAmount: BigInt(evmPayload.permit.fee.feeAmount),\n },\n };\n\n // Call permitTransferFrom on the PaymentPermit contract\n const tx = await signer.writeContract({\n address: permitAddress,\n abi: paymentPermitABI,\n functionName: \"permitTransferFrom\",\n args: [permitTuple, evmPayload.permit.buyer, evmPayload.signature!],\n });\n\n // Wait for transaction confirmation\n const receipt = await signer.waitForTransactionReceipt({ hash: tx as `0x${string}` });\n\n if (receipt.status !== \"success\") {\n return {\n success: false,\n errorReason: errors.INVALID_TRANSACTION_STATE,\n transaction: tx,\n network: payload.accepted.network,\n payer,\n };\n }\n\n return {\n success: true,\n transaction: tx,\n network: payload.accepted.network,\n payer,\n };\n } catch {\n return {\n success: false,\n errorReason: errors.TRANSACTION_FAILED,\n transaction: \"\",\n network: payload.accepted.network,\n payer,\n };\n }\n}\n","import {\n PaymentPayload,\n PaymentRequirements,\n SchemeNetworkFacilitator,\n FacilitatorContext,\n SettleResponse,\n VerifyResponse,\n} from \"@bankofai/x402-core/types\";\nimport { PAYMENT_PERMIT_ADDRESSES } from \"../../constants\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactPermitEvmPayload } from \"../../types\";\nimport { verifyPermitEIP712, settlePermitEIP712 } from \"./eip712\";\n\n/**\n * EVM facilitator implementation for the exact_permit payment scheme.\n * Verifies EIP-712 PaymentPermit signatures and executes on-chain settlement\n * via the PaymentPermit contract's permitTransferFrom.\n */\nexport class ExactPermitEvmScheme implements SchemeNetworkFacilitator {\n readonly scheme = \"exact_permit\";\n readonly caipFamily = \"eip155:*\";\n\n /**\n * Creates a new ExactPermitEvmScheme facilitator instance.\n *\n * @param signer - The EVM signer for facilitator operations\n * @param baseFeeLimit - Optional maximum fee amount the facilitator accepts\n */\n constructor(\n private readonly signer: FacilitatorEvmSigner,\n private readonly baseFeeLimit?: bigint,\n ) {}\n\n /**\n * Returns the PaymentPermit contract address for the network.\n *\n * @param network - The network identifier\n * @returns Extra data containing the permit contract address\n */\n getExtra(network: string): Record<string, unknown> | undefined {\n const permitAddress = PAYMENT_PERMIT_ADDRESSES[network];\n if (!permitAddress) {\n return undefined;\n }\n return {\n paymentPermitAddress: permitAddress,\n };\n }\n\n /**\n * Returns facilitator wallet addresses.\n *\n * @param _ - The network identifier (unused)\n * @returns Array of facilitator wallet addresses\n */\n getSigners(_: string): string[] {\n return [...this.signer.getAddresses()];\n }\n\n /**\n * Verifies an EVM exact_permit payment payload.\n *\n * @param payload - The payment payload to verify\n * @param requirements - The payment requirements\n * @param _context - Optional facilitator context (unused)\n * @returns Promise resolving to verification response\n */\n async verify(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n _context?: FacilitatorContext,\n ): Promise<VerifyResponse> {\n const evmPayload = payload.payload as ExactPermitEvmPayload;\n return verifyPermitEIP712(this.signer, payload, requirements, evmPayload, this.baseFeeLimit);\n }\n\n /**\n * Settles an EVM exact_permit payment by calling permitTransferFrom.\n *\n * @param payload - The payment payload to settle\n * @param requirements - The payment requirements\n * @param _context - Optional facilitator context (unused)\n * @returns Promise resolving to settlement response\n */\n async settle(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n _context?: FacilitatorContext,\n ): Promise<SettleResponse> {\n const evmPayload = payload.payload as ExactPermitEvmPayload;\n return settlePermitEIP712(this.signer, payload, requirements, evmPayload, this.baseFeeLimit);\n }\n}\n","import { x402Facilitator } from \"@bankofai/x402-core/facilitator\";\nimport { Network } from \"@bankofai/x402-core/types\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactPermitEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM exact_permit schemes to an x402Facilitator.\n */\nexport interface EvmPermitFacilitatorConfig {\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 */\n networks: Network | Network[];\n\n /**\n * Optional maximum fee amount the facilitator accepts.\n */\n baseFeeLimit?: bigint;\n}\n\n/**\n * Registers EVM exact_permit payment schemes to an x402Facilitator instance.\n *\n * @param facilitator - The x402Facilitator instance to register schemes to\n * @param config - Configuration for EVM permit facilitator registration\n * @returns The facilitator instance for chaining\n */\nexport function registerExactPermitEvmScheme(\n facilitator: x402Facilitator,\n config: EvmPermitFacilitatorConfig,\n): x402Facilitator {\n facilitator.register(\n config.networks,\n new ExactPermitEvmScheme(config.signer, config.baseFeeLimit),\n );\n\n return facilitator;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0aO,IAAM,qBAAqB;AAAA,EAChC,sBAAsB;AAAA,IACpB,EAAE,MAAM,QAAQ,MAAM,aAAa;AAAA,IACnC,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,IACjC,EAAE,MAAM,UAAU,MAAM,UAAU;AAAA,IAClC,EAAE,MAAM,WAAW,MAAM,UAAU;AAAA,IACnC,EAAE,MAAM,OAAO,MAAM,MAAM;AAAA,EAC7B;AAAA,EACA,YAAY;AAAA,IACV,EAAE,MAAM,QAAQ,MAAM,QAAQ;AAAA,IAC9B,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,IACrC,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,IACjC,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,IACtC,EAAE,MAAM,eAAe,MAAM,UAAU;AAAA,EACzC;AAAA,EACA,SAAS;AAAA,IACP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sB;AAAA,IACxB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,WAAW,GAAqB;AAC9B,WAAO,CAAC,GAAG,KAAK,OAAO,aAAa,CAAC;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,OACJ,SACA,cACA,UACyB;AACzB,UAAM,aAAa,QAAQ;AAC3B,WAAO,mBAAmB,KAAK,QAAQ,SAAS,cAAc,YAAY,KAAK,YAAY;AAAA,EAC7F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,OACJ,SACA,cACA,UACyB;AACzB,UAAM,aAAa,QAAQ;AAC3B,WAAO,mBAAmB,KAAK,QAAQ,SAAS,cAAc,YAAY,KAAK,YAAY;AAAA,EAC7F;AACF;;;AC5DO,SAAS,6BACd,aACA,QACiB;AACjB,cAAY;AAAA,IACV,OAAO;AAAA,IACP,IAAI,qBAAqB,OAAO,QAAQ,OAAO,YAAY;AAAA,EAC7D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from '@bankofai/x402-core/types';
|
|
2
|
+
import { x402ResourceServer } from '@bankofai/x402-core/server';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* EVM server implementation for the exact_permit payment scheme.
|
|
6
|
+
* Handles price parsing and payment requirements with PaymentPermit context.
|
|
7
|
+
* Supports BSC and other EVM networks.
|
|
8
|
+
*/
|
|
9
|
+
declare class ExactPermitEvmScheme implements SchemeNetworkServer {
|
|
10
|
+
readonly scheme = "exact_permit";
|
|
11
|
+
private moneyParsers;
|
|
12
|
+
/**
|
|
13
|
+
* Register a custom money parser in the parser chain.
|
|
14
|
+
*
|
|
15
|
+
* @param parser - Custom function to convert amount to AssetAmount (or null to skip)
|
|
16
|
+
* @returns The server instance for chaining
|
|
17
|
+
*/
|
|
18
|
+
registerMoneyParser(parser: MoneyParser): ExactPermitEvmScheme;
|
|
19
|
+
/**
|
|
20
|
+
* Parses a price into an asset amount for EVM.
|
|
21
|
+
*
|
|
22
|
+
* @param price - The price to parse
|
|
23
|
+
* @param network - The EVM network to use
|
|
24
|
+
* @returns Promise resolving to the parsed asset amount
|
|
25
|
+
*/
|
|
26
|
+
parsePrice(price: Price, network: Network): Promise<AssetAmount>;
|
|
27
|
+
/**
|
|
28
|
+
* Enhance payment requirements for EVM exact_permit scheme.
|
|
29
|
+
* Adds PaymentPermit contract address context.
|
|
30
|
+
*
|
|
31
|
+
* @param paymentRequirements - The base payment requirements
|
|
32
|
+
* @param supportedKind - The supported kind from facilitator
|
|
33
|
+
* @param supportedKind.x402Version - The x402 version
|
|
34
|
+
* @param supportedKind.scheme - The payment scheme
|
|
35
|
+
* @param supportedKind.network - The network identifier
|
|
36
|
+
* @param supportedKind.extra - Optional extra metadata
|
|
37
|
+
* @param extensionKeys - Extension keys supported by the facilitator
|
|
38
|
+
* @returns Enhanced payment requirements with permit context
|
|
39
|
+
*/
|
|
40
|
+
enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
|
|
41
|
+
x402Version: number;
|
|
42
|
+
scheme: string;
|
|
43
|
+
network: Network;
|
|
44
|
+
extra?: Record<string, unknown>;
|
|
45
|
+
}, extensionKeys: string[]): Promise<PaymentRequirements>;
|
|
46
|
+
private parseMoneyToDecimal;
|
|
47
|
+
private defaultMoneyConversion;
|
|
48
|
+
private convertToTokenAmount;
|
|
49
|
+
private getDefaultAsset;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Configuration options for registering EVM exact_permit schemes to an x402ResourceServer.
|
|
54
|
+
*/
|
|
55
|
+
interface EvmPermitResourceServerConfig {
|
|
56
|
+
/**
|
|
57
|
+
* Optional specific networks to register.
|
|
58
|
+
* If not provided, registers wildcard support (eip155:*).
|
|
59
|
+
*/
|
|
60
|
+
networks?: Network[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Registers EVM exact_permit payment schemes to an x402ResourceServer instance.
|
|
64
|
+
*
|
|
65
|
+
* @param server - The x402ResourceServer instance to register schemes to
|
|
66
|
+
* @param config - Configuration for EVM permit resource server registration
|
|
67
|
+
* @returns The server instance for chaining
|
|
68
|
+
*/
|
|
69
|
+
declare function registerExactPermitEvmScheme(server: x402ResourceServer, config?: EvmPermitResourceServerConfig): x402ResourceServer;
|
|
70
|
+
|
|
71
|
+
export { type EvmPermitResourceServerConfig, ExactPermitEvmScheme, registerExactPermitEvmScheme };
|