@bankofai/x402-evm 2.6.0-beta.2 → 2.6.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -4
- package/dist/cjs/exact_permit/client/index.d.ts +0 -57
- package/dist/cjs/exact_permit/client/index.js +0 -223
- package/dist/cjs/exact_permit/client/index.js.map +0 -1
- package/dist/cjs/exact_permit/facilitator/index.d.ts +0 -82
- package/dist/cjs/exact_permit/facilitator/index.js +0 -437
- package/dist/cjs/exact_permit/facilitator/index.js.map +0 -1
- package/dist/cjs/exact_permit/server/index.d.ts +0 -71
- package/dist/cjs/exact_permit/server/index.js +0 -186
- package/dist/cjs/exact_permit/server/index.js.map +0 -1
- package/dist/cjs/permit2-D65OQ5yU.d.ts +0 -517
- package/dist/cjs/permit2-DvsTlAyj.d.ts +0 -531
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bankofai/x402-evm",
|
|
3
|
-
"version": "2.6.0-beta.
|
|
3
|
+
"version": "2.6.0-beta.3",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/cjs/index.d.ts",
|
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
],
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"author": "bankofai",
|
|
28
|
-
"repository":
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/BofAI/x402.git"
|
|
31
|
+
},
|
|
29
32
|
"description": "x402 Payment Protocol EVM Implementation",
|
|
30
33
|
"devDependencies": {
|
|
31
34
|
"@eslint/js": "^9.24.0",
|
|
@@ -45,8 +48,8 @@
|
|
|
45
48
|
"vitest": "^3.0.5"
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
|
-
"@bankofai/x402-core": "
|
|
49
|
-
"@bankofai/x402-extensions": "
|
|
51
|
+
"@bankofai/x402-core": "workspace:~",
|
|
52
|
+
"@bankofai/x402-extensions": "workspace:~",
|
|
50
53
|
"viem": "^2.39.3",
|
|
51
54
|
"zod": "^3.24.2"
|
|
52
55
|
},
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { SchemeNetworkClient, PaymentRequirements, PaymentPayloadContext, PaymentPayloadResult, Network } from '@bankofai/x402-core/types';
|
|
2
|
-
import { C as ClientEvmSigner } from '../../signer-DC81R8wQ.js';
|
|
3
|
-
import { PaymentPolicy, x402Client } from '@bankofai/x402-core/client';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* EVM client implementation for the exact_permit payment scheme.
|
|
7
|
-
* Uses EIP-712 PaymentPermit for token transfers via the PaymentPermit contract.
|
|
8
|
-
*/
|
|
9
|
-
declare class ExactPermitEvmScheme implements SchemeNetworkClient {
|
|
10
|
-
private readonly signer;
|
|
11
|
-
readonly scheme = "exact_permit";
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new ExactPermitEvmScheme client instance.
|
|
14
|
-
*
|
|
15
|
-
* @param signer - The EVM signer for client operations
|
|
16
|
-
*/
|
|
17
|
-
constructor(signer: ClientEvmSigner);
|
|
18
|
-
/**
|
|
19
|
-
* Creates a payment payload for the exact_permit scheme on EVM.
|
|
20
|
-
* Uses EIP-712 signed PaymentPermit.
|
|
21
|
-
*
|
|
22
|
-
* @param x402Version - The x402 protocol version
|
|
23
|
-
* @param paymentRequirements - The payment requirements from the server
|
|
24
|
-
* @param _context - Optional context (unused, reserved for extensions)
|
|
25
|
-
* @returns Promise resolving to a payment payload result
|
|
26
|
-
*/
|
|
27
|
-
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements, _context?: PaymentPayloadContext): Promise<PaymentPayloadResult>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Configuration options for registering EVM exact_permit schemes to an x402Client.
|
|
32
|
-
*/
|
|
33
|
-
interface EvmPermitClientConfig {
|
|
34
|
-
/**
|
|
35
|
-
* The EVM signer to use for creating payment payloads.
|
|
36
|
-
*/
|
|
37
|
-
signer: ClientEvmSigner;
|
|
38
|
-
/**
|
|
39
|
-
* Optional policies to apply to the client.
|
|
40
|
-
*/
|
|
41
|
-
policies?: PaymentPolicy[];
|
|
42
|
-
/**
|
|
43
|
-
* Optional specific networks to register.
|
|
44
|
-
* If not provided, registers wildcard support (eip155:*).
|
|
45
|
-
*/
|
|
46
|
-
networks?: Network[];
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Registers EVM exact_permit payment schemes to an x402Client instance.
|
|
50
|
-
*
|
|
51
|
-
* @param client - The x402Client instance to register schemes to
|
|
52
|
-
* @param config - Configuration for EVM permit client registration
|
|
53
|
-
* @returns The client instance for chaining
|
|
54
|
-
*/
|
|
55
|
-
declare function registerExactPermitEvmScheme(client: x402Client, config: EvmPermitClientConfig): x402Client;
|
|
56
|
-
|
|
57
|
-
export { type EvmPermitClientConfig, ExactPermitEvmScheme, registerExactPermitEvmScheme };
|
|
@@ -1,223 +0,0 @@
|
|
|
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/client/index.ts
|
|
21
|
-
var client_exports = {};
|
|
22
|
-
__export(client_exports, {
|
|
23
|
-
ExactPermitEvmScheme: () => ExactPermitEvmScheme,
|
|
24
|
-
registerExactPermitEvmScheme: () => registerExactPermitEvmScheme
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(client_exports);
|
|
27
|
-
|
|
28
|
-
// src/exact_permit/client/eip712.ts
|
|
29
|
-
var import_viem2 = require("viem");
|
|
30
|
-
|
|
31
|
-
// src/constants.ts
|
|
32
|
-
var paymentPermitTypes = {
|
|
33
|
-
PaymentPermitDetails: [
|
|
34
|
-
{ name: "meta", type: "PermitMeta" },
|
|
35
|
-
{ name: "buyer", type: "address" },
|
|
36
|
-
{ name: "caller", type: "address" },
|
|
37
|
-
{ name: "payment", type: "Payment" },
|
|
38
|
-
{ name: "fee", type: "Fee" }
|
|
39
|
-
],
|
|
40
|
-
PermitMeta: [
|
|
41
|
-
{ name: "kind", type: "uint8" },
|
|
42
|
-
{ name: "paymentId", type: "bytes16" },
|
|
43
|
-
{ name: "nonce", type: "uint256" },
|
|
44
|
-
{ name: "validAfter", type: "uint256" },
|
|
45
|
-
{ name: "validBefore", type: "uint256" }
|
|
46
|
-
],
|
|
47
|
-
Payment: [
|
|
48
|
-
{ name: "payToken", type: "address" },
|
|
49
|
-
{ name: "payAmount", type: "uint256" },
|
|
50
|
-
{ name: "payTo", type: "address" }
|
|
51
|
-
],
|
|
52
|
-
Fee: [
|
|
53
|
-
{ name: "feeTo", type: "address" },
|
|
54
|
-
{ name: "feeAmount", type: "uint256" }
|
|
55
|
-
]
|
|
56
|
-
};
|
|
57
|
-
var PAYMENT_PERMIT_ADDRESSES = {
|
|
58
|
-
"eip155:56": "0x402085c248EeA27D92E8b30b2C58ed07f9E30001",
|
|
59
|
-
// BSC Mainnet
|
|
60
|
-
"eip155:97": "0x402085c248EeA27D92E8b30b2C58ed07f9E30002",
|
|
61
|
-
// BSC Testnet
|
|
62
|
-
"eip155:8453": "0x402085c248EeA27D92E8b30b2C58ed07f9E30003",
|
|
63
|
-
// Base
|
|
64
|
-
"eip155:84532": "0x402085c248EeA27D92E8b30b2C58ed07f9E30004"
|
|
65
|
-
// Base Sepolia
|
|
66
|
-
};
|
|
67
|
-
var PERMIT_KIND = {
|
|
68
|
-
PAYMENT_ONLY: 0
|
|
69
|
-
};
|
|
70
|
-
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
71
|
-
|
|
72
|
-
// src/utils.ts
|
|
73
|
-
var import_viem = require("viem");
|
|
74
|
-
function getEvmChainId(network) {
|
|
75
|
-
if (network.startsWith("eip155:")) {
|
|
76
|
-
const idStr = network.split(":")[1];
|
|
77
|
-
const chainId = parseInt(idStr, 10);
|
|
78
|
-
if (isNaN(chainId)) {
|
|
79
|
-
throw new Error(`Invalid CAIP-2 chain ID: ${network}`);
|
|
80
|
-
}
|
|
81
|
-
return chainId;
|
|
82
|
-
}
|
|
83
|
-
throw new Error(`Unsupported network format: ${network} (expected eip155:CHAIN_ID)`);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/exact_permit/client/eip712.ts
|
|
87
|
-
async function createPermitEIP712Payload(signer, x402Version, paymentRequirements) {
|
|
88
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
89
|
-
const nonceBytes = getCrypto().getRandomValues(new Uint8Array(32));
|
|
90
|
-
const nonce = BigInt((0, import_viem2.toHex)(nonceBytes)).toString();
|
|
91
|
-
const paymentIdBytes = getCrypto().getRandomValues(new Uint8Array(16));
|
|
92
|
-
const paymentId = (0, import_viem2.toHex)(paymentIdBytes);
|
|
93
|
-
const buyerAddress = signer.address;
|
|
94
|
-
const payToAddress = paymentRequirements.payTo;
|
|
95
|
-
const tokenAddress = paymentRequirements.asset;
|
|
96
|
-
const feeTo = paymentRequirements.extra?.feeTo || ZERO_ADDRESS;
|
|
97
|
-
const feeAmount = paymentRequirements.extra?.feeAmount || "0";
|
|
98
|
-
const caller = paymentRequirements.extra?.caller || ZERO_ADDRESS;
|
|
99
|
-
const permit = {
|
|
100
|
-
meta: {
|
|
101
|
-
kind: PERMIT_KIND.PAYMENT_ONLY,
|
|
102
|
-
paymentId,
|
|
103
|
-
nonce,
|
|
104
|
-
validAfter: (now - 600).toString(),
|
|
105
|
-
// 10-min clock skew tolerance
|
|
106
|
-
validBefore: (now + paymentRequirements.maxTimeoutSeconds).toString()
|
|
107
|
-
},
|
|
108
|
-
buyer: buyerAddress,
|
|
109
|
-
caller,
|
|
110
|
-
payment: {
|
|
111
|
-
payToken: tokenAddress,
|
|
112
|
-
payAmount: paymentRequirements.amount,
|
|
113
|
-
payTo: payToAddress
|
|
114
|
-
},
|
|
115
|
-
fee: {
|
|
116
|
-
feeTo,
|
|
117
|
-
feeAmount
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
const signature = await signPermitEIP712(signer, permit, paymentRequirements);
|
|
121
|
-
const payload = {
|
|
122
|
-
permit,
|
|
123
|
-
signature
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
x402Version,
|
|
127
|
-
payload
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
async function signPermitEIP712(signer, permit, requirements) {
|
|
131
|
-
const chainId = getEvmChainId(requirements.network);
|
|
132
|
-
const permitAddress = PAYMENT_PERMIT_ADDRESSES[requirements.network];
|
|
133
|
-
if (!permitAddress) {
|
|
134
|
-
throw new Error(`No PaymentPermit contract address for network: ${requirements.network}`);
|
|
135
|
-
}
|
|
136
|
-
const domain = {
|
|
137
|
-
name: "PaymentPermit",
|
|
138
|
-
chainId,
|
|
139
|
-
verifyingContract: permitAddress
|
|
140
|
-
};
|
|
141
|
-
const message = {
|
|
142
|
-
meta: {
|
|
143
|
-
kind: permit.meta.kind,
|
|
144
|
-
paymentId: permit.meta.paymentId,
|
|
145
|
-
nonce: BigInt(permit.meta.nonce),
|
|
146
|
-
validAfter: BigInt(permit.meta.validAfter),
|
|
147
|
-
validBefore: BigInt(permit.meta.validBefore)
|
|
148
|
-
},
|
|
149
|
-
buyer: permit.buyer,
|
|
150
|
-
caller: permit.caller,
|
|
151
|
-
payment: {
|
|
152
|
-
payToken: permit.payment.payToken,
|
|
153
|
-
payAmount: BigInt(permit.payment.payAmount),
|
|
154
|
-
payTo: permit.payment.payTo
|
|
155
|
-
},
|
|
156
|
-
fee: {
|
|
157
|
-
feeTo: permit.fee.feeTo,
|
|
158
|
-
feeAmount: BigInt(permit.fee.feeAmount)
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
return await signer.signTypedData({
|
|
162
|
-
domain,
|
|
163
|
-
types: paymentPermitTypes,
|
|
164
|
-
primaryType: "PaymentPermitDetails",
|
|
165
|
-
message
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
function getCrypto() {
|
|
169
|
-
const cryptoObj = globalThis.crypto;
|
|
170
|
-
if (!cryptoObj) {
|
|
171
|
-
throw new Error("Crypto API not available");
|
|
172
|
-
}
|
|
173
|
-
return cryptoObj;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// src/exact_permit/client/scheme.ts
|
|
177
|
-
var ExactPermitEvmScheme = class {
|
|
178
|
-
/**
|
|
179
|
-
* Creates a new ExactPermitEvmScheme client instance.
|
|
180
|
-
*
|
|
181
|
-
* @param signer - The EVM signer for client operations
|
|
182
|
-
*/
|
|
183
|
-
constructor(signer) {
|
|
184
|
-
this.signer = signer;
|
|
185
|
-
this.scheme = "exact_permit";
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Creates a payment payload for the exact_permit scheme on EVM.
|
|
189
|
-
* Uses EIP-712 signed PaymentPermit.
|
|
190
|
-
*
|
|
191
|
-
* @param x402Version - The x402 protocol version
|
|
192
|
-
* @param paymentRequirements - The payment requirements from the server
|
|
193
|
-
* @param _context - Optional context (unused, reserved for extensions)
|
|
194
|
-
* @returns Promise resolving to a payment payload result
|
|
195
|
-
*/
|
|
196
|
-
async createPaymentPayload(x402Version, paymentRequirements, _context) {
|
|
197
|
-
return createPermitEIP712Payload(this.signer, x402Version, paymentRequirements);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
// src/exact_permit/client/register.ts
|
|
202
|
-
function registerExactPermitEvmScheme(client, config) {
|
|
203
|
-
const evmScheme = new ExactPermitEvmScheme(config.signer);
|
|
204
|
-
if (config.networks && config.networks.length > 0) {
|
|
205
|
-
config.networks.forEach((network) => {
|
|
206
|
-
client.register(network, evmScheme);
|
|
207
|
-
});
|
|
208
|
-
} else {
|
|
209
|
-
client.register("eip155:*", evmScheme);
|
|
210
|
-
}
|
|
211
|
-
if (config.policies) {
|
|
212
|
-
config.policies.forEach((policy) => {
|
|
213
|
-
client.registerPolicy(policy);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
return client;
|
|
217
|
-
}
|
|
218
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
219
|
-
0 && (module.exports = {
|
|
220
|
-
ExactPermitEvmScheme,
|
|
221
|
-
registerExactPermitEvmScheme
|
|
222
|
-
});
|
|
223
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/exact_permit/client/index.ts","../../../../src/exact_permit/client/eip712.ts","../../../../src/constants.ts","../../../../src/utils.ts","../../../../src/exact_permit/client/scheme.ts","../../../../src/exact_permit/client/register.ts"],"sourcesContent":["export { ExactPermitEvmScheme } from \"./scheme\";\nexport { registerExactPermitEvmScheme } from \"./register\";\nexport type { EvmPermitClientConfig } from \"./register\";\n","import { toHex } from \"viem\";\nimport { PaymentRequirements, PaymentPayloadResult } from \"@bankofai/x402-core/types\";\nimport {\n paymentPermitTypes,\n PAYMENT_PERMIT_ADDRESSES,\n PERMIT_KIND,\n ZERO_ADDRESS,\n} from \"../../constants\";\nimport { ClientEvmSigner } from \"../../signer\";\nimport { ExactPermitEvmPayload, PaymentPermit } from \"../../types\";\nimport { getEvmChainId } from \"../../utils\";\n\n/**\n * Creates an EIP-712 PaymentPermit payload for EVM exact_permit scheme.\n *\n * @param signer - The EVM client signer\n * @param x402Version - The x402 protocol version\n * @param paymentRequirements - The payment requirements from the server\n * @returns Promise resolving to a payment payload result\n */\nexport async function createPermitEIP712Payload(\n signer: ClientEvmSigner,\n x402Version: number,\n paymentRequirements: PaymentRequirements,\n): Promise<PaymentPayloadResult> {\n const now = Math.floor(Date.now() / 1000);\n\n // Generate a random nonce (uint256)\n const nonceBytes = getCrypto().getRandomValues(new Uint8Array(32));\n const nonce = BigInt(toHex(nonceBytes)).toString();\n\n // Generate a random paymentId (16 bytes)\n const paymentIdBytes = getCrypto().getRandomValues(new Uint8Array(16));\n const paymentId = toHex(paymentIdBytes) as `0x${string}`;\n\n const buyerAddress = signer.address;\n const payToAddress = paymentRequirements.payTo as `0x${string}`;\n const tokenAddress = paymentRequirements.asset as `0x${string}`;\n\n // Get fee from paymentRequirements.extra or default to zero\n const feeTo = (paymentRequirements.extra?.feeTo as `0x${string}`) || ZERO_ADDRESS;\n const feeAmount = (paymentRequirements.extra?.feeAmount as string) || \"0\";\n\n // Get caller from extra or default to zero (facilitator fills it)\n const caller = (paymentRequirements.extra?.caller as `0x${string}`) || ZERO_ADDRESS;\n\n const permit: PaymentPermit = {\n meta: {\n kind: PERMIT_KIND.PAYMENT_ONLY,\n paymentId,\n nonce,\n validAfter: (now - 600).toString(), // 10-min clock skew tolerance\n validBefore: (now + paymentRequirements.maxTimeoutSeconds).toString(),\n },\n buyer: buyerAddress,\n caller,\n payment: {\n payToken: tokenAddress,\n payAmount: paymentRequirements.amount,\n payTo: payToAddress,\n },\n fee: {\n feeTo,\n feeAmount,\n },\n };\n\n const signature = await signPermitEIP712(signer, permit, paymentRequirements);\n\n const payload: ExactPermitEvmPayload = {\n permit,\n signature,\n };\n\n return {\n x402Version,\n payload,\n };\n}\n\n/**\n * Sign a PaymentPermit using EIP-712 typed data signing.\n *\n * @param signer - The EVM client signer\n * @param permit - The PaymentPermit struct to sign\n * @param requirements - The payment requirements (contains network info)\n * @returns Promise resolving to the hex-encoded signature\n */\nasync function signPermitEIP712(\n signer: ClientEvmSigner,\n permit: PaymentPermit,\n requirements: PaymentRequirements,\n): Promise<`0x${string}`> {\n const chainId = getEvmChainId(requirements.network);\n\n const permitAddress = PAYMENT_PERMIT_ADDRESSES[requirements.network];\n if (!permitAddress) {\n throw new Error(`No PaymentPermit contract address for network: ${requirements.network}`);\n }\n\n const domain = {\n name: \"PaymentPermit\",\n chainId,\n verifyingContract: permitAddress,\n };\n\n const message = {\n meta: {\n kind: permit.meta.kind,\n paymentId: permit.meta.paymentId,\n nonce: BigInt(permit.meta.nonce),\n validAfter: BigInt(permit.meta.validAfter),\n validBefore: BigInt(permit.meta.validBefore),\n },\n buyer: permit.buyer,\n caller: permit.caller,\n payment: {\n payToken: permit.payment.payToken,\n payAmount: BigInt(permit.payment.payAmount),\n payTo: permit.payment.payTo,\n },\n fee: {\n feeTo: permit.fee.feeTo,\n feeAmount: BigInt(permit.fee.feeAmount),\n },\n };\n\n return await signer.signTypedData({\n domain,\n types: paymentPermitTypes,\n primaryType: \"PaymentPermitDetails\",\n message,\n });\n}\n\n/**\n * Get the crypto object from the global scope.\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","// 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","import {\n PaymentRequirements,\n SchemeNetworkClient,\n PaymentPayloadResult,\n PaymentPayloadContext,\n} from \"@bankofai/x402-core/types\";\nimport { ClientEvmSigner } from \"../../signer\";\nimport { createPermitEIP712Payload } from \"./eip712\";\n\n/**\n * EVM client implementation for the exact_permit payment scheme.\n * Uses EIP-712 PaymentPermit for token transfers via the PaymentPermit contract.\n */\nexport class ExactPermitEvmScheme implements SchemeNetworkClient {\n readonly scheme = \"exact_permit\";\n\n /**\n * Creates a new ExactPermitEvmScheme client instance.\n *\n * @param signer - The EVM signer for client operations\n */\n constructor(private readonly signer: ClientEvmSigner) {}\n\n /**\n * Creates a payment payload for the exact_permit scheme on EVM.\n * Uses EIP-712 signed PaymentPermit.\n *\n * @param x402Version - The x402 protocol version\n * @param paymentRequirements - The payment requirements from the server\n * @param _context - Optional context (unused, reserved for extensions)\n * @returns Promise resolving to a payment payload result\n */\n async createPaymentPayload(\n x402Version: number,\n paymentRequirements: PaymentRequirements,\n _context?: PaymentPayloadContext,\n ): Promise<PaymentPayloadResult> {\n return createPermitEIP712Payload(this.signer, x402Version, paymentRequirements);\n }\n}\n","import { x402Client, PaymentPolicy } from \"@bankofai/x402-core/client\";\nimport { Network } from \"@bankofai/x402-core/types\";\nimport { ClientEvmSigner } from \"../../signer\";\nimport { ExactPermitEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM exact_permit schemes to an x402Client.\n */\nexport interface EvmPermitClientConfig {\n /**\n * The EVM signer to use for creating payment payloads.\n */\n signer: ClientEvmSigner;\n\n /**\n * Optional policies to apply to the client.\n */\n policies?: PaymentPolicy[];\n\n /**\n * Optional specific networks to register.\n * If not provided, registers wildcard support (eip155:*).\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact_permit payment schemes to an x402Client instance.\n *\n * @param client - The x402Client instance to register schemes to\n * @param config - Configuration for EVM permit client registration\n * @returns The client instance for chaining\n */\nexport function registerExactPermitEvmScheme(\n client: x402Client,\n config: EvmPermitClientConfig,\n): x402Client {\n const evmScheme = new ExactPermitEvmScheme(config.signer);\n\n if (config.networks && config.networks.length > 0) {\n config.networks.forEach(network => {\n client.register(network, evmScheme);\n });\n } else {\n client.register(\"eip155:*\", evmScheme);\n }\n\n if (config.policies) {\n config.policies.forEach(policy => {\n client.registerPolicy(policy);\n });\n }\n\n return client;\n}\n"],"mappings":"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","names":["import_viem"]}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, FacilitatorContext, VerifyResponse, SettleResponse, Network } from '@bankofai/x402-core/types';
|
|
2
|
-
import { F as FacilitatorEvmSigner } from '../../signer-DC81R8wQ.js';
|
|
3
|
-
import { x402Facilitator } from '@bankofai/x402-core/facilitator';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* EVM facilitator implementation for the exact_permit payment scheme.
|
|
7
|
-
* Verifies EIP-712 PaymentPermit signatures and executes on-chain settlement
|
|
8
|
-
* via the PaymentPermit contract's permitTransferFrom.
|
|
9
|
-
*/
|
|
10
|
-
declare class ExactPermitEvmScheme implements SchemeNetworkFacilitator {
|
|
11
|
-
private readonly signer;
|
|
12
|
-
private readonly baseFeeLimit?;
|
|
13
|
-
readonly scheme = "exact_permit";
|
|
14
|
-
readonly caipFamily = "eip155:*";
|
|
15
|
-
/**
|
|
16
|
-
* Creates a new ExactPermitEvmScheme facilitator instance.
|
|
17
|
-
*
|
|
18
|
-
* @param signer - The EVM signer for facilitator operations
|
|
19
|
-
* @param baseFeeLimit - Optional maximum fee amount the facilitator accepts
|
|
20
|
-
*/
|
|
21
|
-
constructor(signer: FacilitatorEvmSigner, baseFeeLimit?: bigint | undefined);
|
|
22
|
-
/**
|
|
23
|
-
* Returns the PaymentPermit contract address for the network.
|
|
24
|
-
*
|
|
25
|
-
* @param network - The network identifier
|
|
26
|
-
* @returns Extra data containing the permit contract address
|
|
27
|
-
*/
|
|
28
|
-
getExtra(network: string): Record<string, unknown> | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Returns facilitator wallet addresses.
|
|
31
|
-
*
|
|
32
|
-
* @param _ - The network identifier (unused)
|
|
33
|
-
* @returns Array of facilitator wallet addresses
|
|
34
|
-
*/
|
|
35
|
-
getSigners(_: string): string[];
|
|
36
|
-
/**
|
|
37
|
-
* Verifies an EVM exact_permit payment payload.
|
|
38
|
-
*
|
|
39
|
-
* @param payload - The payment payload to verify
|
|
40
|
-
* @param requirements - The payment requirements
|
|
41
|
-
* @param _context - Optional facilitator context (unused)
|
|
42
|
-
* @returns Promise resolving to verification response
|
|
43
|
-
*/
|
|
44
|
-
verify(payload: PaymentPayload, requirements: PaymentRequirements, _context?: FacilitatorContext): Promise<VerifyResponse>;
|
|
45
|
-
/**
|
|
46
|
-
* Settles an EVM exact_permit payment by calling permitTransferFrom.
|
|
47
|
-
*
|
|
48
|
-
* @param payload - The payment payload to settle
|
|
49
|
-
* @param requirements - The payment requirements
|
|
50
|
-
* @param _context - Optional facilitator context (unused)
|
|
51
|
-
* @returns Promise resolving to settlement response
|
|
52
|
-
*/
|
|
53
|
-
settle(payload: PaymentPayload, requirements: PaymentRequirements, _context?: FacilitatorContext): Promise<SettleResponse>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Configuration options for registering EVM exact_permit schemes to an x402Facilitator.
|
|
58
|
-
*/
|
|
59
|
-
interface EvmPermitFacilitatorConfig {
|
|
60
|
-
/**
|
|
61
|
-
* The EVM signer for facilitator operations (verify and settle).
|
|
62
|
-
*/
|
|
63
|
-
signer: FacilitatorEvmSigner;
|
|
64
|
-
/**
|
|
65
|
-
* Networks to register (single network or array of networks).
|
|
66
|
-
*/
|
|
67
|
-
networks: Network | Network[];
|
|
68
|
-
/**
|
|
69
|
-
* Optional maximum fee amount the facilitator accepts.
|
|
70
|
-
*/
|
|
71
|
-
baseFeeLimit?: bigint;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Registers EVM exact_permit payment schemes to an x402Facilitator instance.
|
|
75
|
-
*
|
|
76
|
-
* @param facilitator - The x402Facilitator instance to register schemes to
|
|
77
|
-
* @param config - Configuration for EVM permit facilitator registration
|
|
78
|
-
* @returns The facilitator instance for chaining
|
|
79
|
-
*/
|
|
80
|
-
declare function registerExactPermitEvmScheme(facilitator: x402Facilitator, config: EvmPermitFacilitatorConfig): x402Facilitator;
|
|
81
|
-
|
|
82
|
-
export { type EvmPermitFacilitatorConfig, ExactPermitEvmScheme, registerExactPermitEvmScheme };
|