@x402/evm 2.2.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exact/client/index.d.ts +2 -2
- package/dist/cjs/exact/client/index.js +265 -119
- package/dist/cjs/exact/client/index.js.map +1 -1
- package/dist/cjs/exact/facilitator/index.d.ts +3 -0
- package/dist/cjs/exact/facilitator/index.js +692 -281
- package/dist/cjs/exact/facilitator/index.js.map +1 -1
- package/dist/cjs/exact/server/index.js +8 -1
- package/dist/cjs/exact/server/index.js.map +1 -1
- package/dist/cjs/exact/v1/client/index.js +44 -17
- package/dist/cjs/exact/v1/client/index.js.map +1 -1
- package/dist/cjs/exact/v1/facilitator/index.js +60 -26
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
- package/dist/cjs/index.d.ts +458 -31
- package/dist/cjs/index.js +439 -63
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/permit2-BYv82va2.d.ts +103 -0
- package/dist/cjs/v1/index.d.ts +22 -1
- package/dist/cjs/v1/index.js +34 -29
- package/dist/cjs/v1/index.js.map +1 -1
- package/dist/esm/chunk-E2YMUI3X.mjs +229 -0
- package/dist/esm/chunk-E2YMUI3X.mjs.map +1 -0
- package/dist/esm/chunk-PFULIQAE.mjs +13 -0
- package/dist/esm/chunk-PFULIQAE.mjs.map +1 -0
- package/dist/esm/chunk-RPL6OFJL.mjs +659 -0
- package/dist/esm/chunk-RPL6OFJL.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +2 -2
- package/dist/esm/exact/client/index.mjs +10 -30
- package/dist/esm/exact/client/index.mjs.map +1 -1
- package/dist/esm/exact/facilitator/index.d.mts +3 -0
- package/dist/esm/exact/facilitator/index.mjs +491 -241
- package/dist/esm/exact/facilitator/index.mjs.map +1 -1
- package/dist/esm/exact/server/index.mjs +8 -1
- package/dist/esm/exact/server/index.mjs.map +1 -1
- package/dist/esm/exact/v1/client/index.mjs +1 -2
- package/dist/esm/exact/v1/facilitator/index.mjs +2 -3
- package/dist/esm/index.d.mts +458 -31
- package/dist/esm/index.mjs +31 -4
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/permit2-BsAoJiWD.d.mts +103 -0
- package/dist/esm/v1/index.d.mts +22 -1
- package/dist/esm/v1/index.mjs +4 -6
- package/package.json +2 -2
- package/dist/esm/chunk-FOUXRQAV.mjs +0 -88
- package/dist/esm/chunk-FOUXRQAV.mjs.map +0 -1
- package/dist/esm/chunk-JYZWCLMP.mjs +0 -305
- package/dist/esm/chunk-JYZWCLMP.mjs.map +0 -1
- package/dist/esm/chunk-PSA4YVU2.mjs +0 -92
- package/dist/esm/chunk-PSA4YVU2.mjs.map +0 -1
- package/dist/esm/chunk-QLXM7BIB.mjs +0 -23
- package/dist/esm/chunk-QLXM7BIB.mjs.map +0 -1
- package/dist/esm/chunk-ZYXTTU74.mjs +0 -88
- package/dist/esm/chunk-ZYXTTU74.mjs.map +0 -1
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,36 +1,463 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { E as ExactEvmScheme, P as Permit2AllowanceParams, c as createPermit2ApprovalTx, e as erc20AllowanceAbi, g as getPermit2AllowanceReadParams } from './permit2-BsAoJiWD.mjs';
|
|
2
|
+
export { C as ClientEvmSigner, F as FacilitatorEvmSigner, t as toClientEvmSigner, a as toFacilitatorEvmSigner } from './signer-5OVDxViv.mjs';
|
|
3
|
+
import '@x402/core/types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Asset transfer methods for the exact EVM scheme.
|
|
7
|
+
* - eip3009: Uses transferWithAuthorization (USDC, etc.) - recommended for compatible tokens
|
|
8
|
+
* - permit2: Uses Permit2 + x402Permit2Proxy - universal fallback for any ERC-20
|
|
9
|
+
*/
|
|
10
|
+
type AssetTransferMethod = "eip3009" | "permit2";
|
|
11
|
+
/**
|
|
12
|
+
* EIP-3009 payload for tokens with native transferWithAuthorization support.
|
|
13
|
+
*/
|
|
14
|
+
type ExactEIP3009Payload = {
|
|
15
|
+
signature?: `0x${string}`;
|
|
16
|
+
authorization: {
|
|
17
|
+
from: `0x${string}`;
|
|
18
|
+
to: `0x${string}`;
|
|
19
|
+
value: string;
|
|
20
|
+
validAfter: string;
|
|
21
|
+
validBefore: string;
|
|
22
|
+
nonce: `0x${string}`;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Permit2 witness data structure.
|
|
27
|
+
* Matches the Witness struct in x402Permit2Proxy contract.
|
|
28
|
+
* Note: Upper time bound is enforced by Permit2's `deadline` field, not a witness field.
|
|
29
|
+
*/
|
|
30
|
+
type Permit2Witness = {
|
|
31
|
+
to: `0x${string}`;
|
|
32
|
+
validAfter: string;
|
|
33
|
+
extra: `0x${string}`;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Permit2 authorization parameters.
|
|
37
|
+
* Used to reconstruct the signed message for verification.
|
|
38
|
+
*/
|
|
39
|
+
type Permit2Authorization = {
|
|
40
|
+
permitted: {
|
|
41
|
+
token: `0x${string}`;
|
|
42
|
+
amount: string;
|
|
43
|
+
};
|
|
44
|
+
spender: `0x${string}`;
|
|
45
|
+
nonce: string;
|
|
46
|
+
deadline: string;
|
|
47
|
+
witness: Permit2Witness;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Permit2 payload for tokens using the Permit2 + x402Permit2Proxy flow.
|
|
51
|
+
*/
|
|
52
|
+
type ExactPermit2Payload = {
|
|
53
|
+
signature: `0x${string}`;
|
|
54
|
+
permit2Authorization: Permit2Authorization & {
|
|
55
|
+
from: `0x${string}`;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
type ExactEvmPayloadV1 = ExactEIP3009Payload;
|
|
59
|
+
type ExactEvmPayloadV2 = ExactEIP3009Payload | ExactPermit2Payload;
|
|
60
|
+
/**
|
|
61
|
+
* Type guard to check if a payload is a Permit2 payload.
|
|
62
|
+
* Permit2 payloads have a `permit2Authorization` field.
|
|
63
|
+
*
|
|
64
|
+
* @param payload - The payload to check.
|
|
65
|
+
* @returns True if the payload is a Permit2 payload, false otherwise.
|
|
66
|
+
*/
|
|
67
|
+
declare function isPermit2Payload(payload: ExactEvmPayloadV2): payload is ExactPermit2Payload;
|
|
68
|
+
/**
|
|
69
|
+
* Type guard to check if a payload is an EIP-3009 payload.
|
|
70
|
+
* EIP-3009 payloads have an `authorization` field.
|
|
7
71
|
*
|
|
72
|
+
* @param payload - The payload to check.
|
|
73
|
+
* @returns True if the payload is an EIP-3009 payload, false otherwise.
|
|
74
|
+
*/
|
|
75
|
+
declare function isEIP3009Payload(payload: ExactEvmPayloadV2): payload is ExactEIP3009Payload;
|
|
76
|
+
|
|
77
|
+
declare const authorizationTypes: {
|
|
78
|
+
readonly TransferWithAuthorization: readonly [{
|
|
79
|
+
readonly name: "from";
|
|
80
|
+
readonly type: "address";
|
|
81
|
+
}, {
|
|
82
|
+
readonly name: "to";
|
|
83
|
+
readonly type: "address";
|
|
84
|
+
}, {
|
|
85
|
+
readonly name: "value";
|
|
86
|
+
readonly type: "uint256";
|
|
87
|
+
}, {
|
|
88
|
+
readonly name: "validAfter";
|
|
89
|
+
readonly type: "uint256";
|
|
90
|
+
}, {
|
|
91
|
+
readonly name: "validBefore";
|
|
92
|
+
readonly type: "uint256";
|
|
93
|
+
}, {
|
|
94
|
+
readonly name: "nonce";
|
|
95
|
+
readonly type: "bytes32";
|
|
96
|
+
}];
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Permit2 EIP-712 types for signing PermitWitnessTransferFrom.
|
|
100
|
+
* Must match the exact format expected by the Permit2 contract.
|
|
101
|
+
* Note: Types must be in ALPHABETICAL order after the primary type (TokenPermissions < Witness).
|
|
102
|
+
*/
|
|
103
|
+
declare const permit2WitnessTypes: {
|
|
104
|
+
readonly PermitWitnessTransferFrom: readonly [{
|
|
105
|
+
readonly name: "permitted";
|
|
106
|
+
readonly type: "TokenPermissions";
|
|
107
|
+
}, {
|
|
108
|
+
readonly name: "spender";
|
|
109
|
+
readonly type: "address";
|
|
110
|
+
}, {
|
|
111
|
+
readonly name: "nonce";
|
|
112
|
+
readonly type: "uint256";
|
|
113
|
+
}, {
|
|
114
|
+
readonly name: "deadline";
|
|
115
|
+
readonly type: "uint256";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "witness";
|
|
118
|
+
readonly type: "Witness";
|
|
119
|
+
}];
|
|
120
|
+
readonly TokenPermissions: readonly [{
|
|
121
|
+
readonly name: "token";
|
|
122
|
+
readonly type: "address";
|
|
123
|
+
}, {
|
|
124
|
+
readonly name: "amount";
|
|
125
|
+
readonly type: "uint256";
|
|
126
|
+
}];
|
|
127
|
+
readonly Witness: readonly [{
|
|
128
|
+
readonly name: "to";
|
|
129
|
+
readonly type: "address";
|
|
130
|
+
}, {
|
|
131
|
+
readonly name: "validAfter";
|
|
132
|
+
readonly type: "uint256";
|
|
133
|
+
}, {
|
|
134
|
+
readonly name: "extra";
|
|
135
|
+
readonly type: "bytes";
|
|
136
|
+
}];
|
|
137
|
+
};
|
|
138
|
+
declare const eip3009ABI: readonly [{
|
|
139
|
+
readonly inputs: readonly [{
|
|
140
|
+
readonly name: "from";
|
|
141
|
+
readonly type: "address";
|
|
142
|
+
}, {
|
|
143
|
+
readonly name: "to";
|
|
144
|
+
readonly type: "address";
|
|
145
|
+
}, {
|
|
146
|
+
readonly name: "value";
|
|
147
|
+
readonly type: "uint256";
|
|
148
|
+
}, {
|
|
149
|
+
readonly name: "validAfter";
|
|
150
|
+
readonly type: "uint256";
|
|
151
|
+
}, {
|
|
152
|
+
readonly name: "validBefore";
|
|
153
|
+
readonly type: "uint256";
|
|
154
|
+
}, {
|
|
155
|
+
readonly name: "nonce";
|
|
156
|
+
readonly type: "bytes32";
|
|
157
|
+
}, {
|
|
158
|
+
readonly name: "v";
|
|
159
|
+
readonly type: "uint8";
|
|
160
|
+
}, {
|
|
161
|
+
readonly name: "r";
|
|
162
|
+
readonly type: "bytes32";
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "s";
|
|
165
|
+
readonly type: "bytes32";
|
|
166
|
+
}];
|
|
167
|
+
readonly name: "transferWithAuthorization";
|
|
168
|
+
readonly outputs: readonly [];
|
|
169
|
+
readonly stateMutability: "nonpayable";
|
|
170
|
+
readonly type: "function";
|
|
171
|
+
}, {
|
|
172
|
+
readonly inputs: readonly [{
|
|
173
|
+
readonly name: "from";
|
|
174
|
+
readonly type: "address";
|
|
175
|
+
}, {
|
|
176
|
+
readonly name: "to";
|
|
177
|
+
readonly type: "address";
|
|
178
|
+
}, {
|
|
179
|
+
readonly name: "value";
|
|
180
|
+
readonly type: "uint256";
|
|
181
|
+
}, {
|
|
182
|
+
readonly name: "validAfter";
|
|
183
|
+
readonly type: "uint256";
|
|
184
|
+
}, {
|
|
185
|
+
readonly name: "validBefore";
|
|
186
|
+
readonly type: "uint256";
|
|
187
|
+
}, {
|
|
188
|
+
readonly name: "nonce";
|
|
189
|
+
readonly type: "bytes32";
|
|
190
|
+
}, {
|
|
191
|
+
readonly name: "signature";
|
|
192
|
+
readonly type: "bytes";
|
|
193
|
+
}];
|
|
194
|
+
readonly name: "transferWithAuthorization";
|
|
195
|
+
readonly outputs: readonly [];
|
|
196
|
+
readonly stateMutability: "nonpayable";
|
|
197
|
+
readonly type: "function";
|
|
198
|
+
}, {
|
|
199
|
+
readonly inputs: readonly [{
|
|
200
|
+
readonly name: "account";
|
|
201
|
+
readonly type: "address";
|
|
202
|
+
}];
|
|
203
|
+
readonly name: "balanceOf";
|
|
204
|
+
readonly outputs: readonly [{
|
|
205
|
+
readonly name: "";
|
|
206
|
+
readonly type: "uint256";
|
|
207
|
+
}];
|
|
208
|
+
readonly stateMutability: "view";
|
|
209
|
+
readonly type: "function";
|
|
210
|
+
}, {
|
|
211
|
+
readonly inputs: readonly [];
|
|
212
|
+
readonly name: "version";
|
|
213
|
+
readonly outputs: readonly [{
|
|
214
|
+
readonly name: "";
|
|
215
|
+
readonly type: "string";
|
|
216
|
+
}];
|
|
217
|
+
readonly stateMutability: "view";
|
|
218
|
+
readonly type: "function";
|
|
219
|
+
}];
|
|
220
|
+
/**
|
|
221
|
+
* Canonical Permit2 contract address.
|
|
222
|
+
* Same address on all EVM chains via CREATE2 deployment.
|
|
223
|
+
*
|
|
224
|
+
* @see https://github.com/Uniswap/permit2
|
|
225
|
+
*/
|
|
226
|
+
declare const PERMIT2_ADDRESS: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
227
|
+
/**
|
|
228
|
+
* x402ExactPermit2Proxy contract address.
|
|
229
|
+
* Vanity address: 0x4020...0001 for easy recognition.
|
|
230
|
+
* This address is deterministic based on:
|
|
231
|
+
* - Arachnid's deterministic deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C)
|
|
232
|
+
* - Vanity-mined salt for prefix 0x4020 and suffix 0001
|
|
233
|
+
* - Contract bytecode + constructor args (PERMIT2_ADDRESS)
|
|
234
|
+
*/
|
|
235
|
+
declare const x402ExactPermit2ProxyAddress: "0x4020615294c913F045dc10f0a5cdEbd86c280001";
|
|
236
|
+
/**
|
|
237
|
+
* x402UptoPermit2Proxy contract address.
|
|
238
|
+
* Vanity address: 0x4020...0002 for easy recognition.
|
|
239
|
+
* This address is deterministic based on:
|
|
240
|
+
* - Arachnid's deterministic deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C)
|
|
241
|
+
* - Vanity-mined salt for prefix 0x4020 and suffix 0002
|
|
242
|
+
* - Contract bytecode + constructor args (PERMIT2_ADDRESS)
|
|
243
|
+
*/
|
|
244
|
+
declare const x402UptoPermit2ProxyAddress: "0x4020633461b2895a48930Ff97eE8fCdE8E520002";
|
|
245
|
+
/**
|
|
246
|
+
* x402ExactPermit2Proxy ABI - settle function for exact payment scheme.
|
|
8
247
|
*/
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
readonly
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
248
|
+
declare const x402ExactPermit2ProxyABI: readonly [{
|
|
249
|
+
readonly type: "function";
|
|
250
|
+
readonly name: "PERMIT2";
|
|
251
|
+
readonly inputs: readonly [];
|
|
252
|
+
readonly outputs: readonly [{
|
|
253
|
+
readonly name: "";
|
|
254
|
+
readonly type: "address";
|
|
255
|
+
readonly internalType: "contract ISignatureTransfer";
|
|
256
|
+
}];
|
|
257
|
+
readonly stateMutability: "view";
|
|
258
|
+
}, {
|
|
259
|
+
readonly type: "function";
|
|
260
|
+
readonly name: "WITNESS_TYPEHASH";
|
|
261
|
+
readonly inputs: readonly [];
|
|
262
|
+
readonly outputs: readonly [{
|
|
263
|
+
readonly name: "";
|
|
264
|
+
readonly type: "bytes32";
|
|
265
|
+
readonly internalType: "bytes32";
|
|
266
|
+
}];
|
|
267
|
+
readonly stateMutability: "view";
|
|
268
|
+
}, {
|
|
269
|
+
readonly type: "function";
|
|
270
|
+
readonly name: "WITNESS_TYPE_STRING";
|
|
271
|
+
readonly inputs: readonly [];
|
|
272
|
+
readonly outputs: readonly [{
|
|
273
|
+
readonly name: "";
|
|
274
|
+
readonly type: "string";
|
|
275
|
+
readonly internalType: "string";
|
|
276
|
+
}];
|
|
277
|
+
readonly stateMutability: "view";
|
|
278
|
+
}, {
|
|
279
|
+
readonly type: "function";
|
|
280
|
+
readonly name: "initialize";
|
|
281
|
+
readonly inputs: readonly [{
|
|
282
|
+
readonly name: "_permit2";
|
|
283
|
+
readonly type: "address";
|
|
284
|
+
readonly internalType: "address";
|
|
285
|
+
}];
|
|
286
|
+
readonly outputs: readonly [];
|
|
287
|
+
readonly stateMutability: "nonpayable";
|
|
288
|
+
}, {
|
|
289
|
+
readonly type: "function";
|
|
290
|
+
readonly name: "settle";
|
|
291
|
+
readonly inputs: readonly [{
|
|
292
|
+
readonly name: "permit";
|
|
293
|
+
readonly type: "tuple";
|
|
294
|
+
readonly internalType: "struct ISignatureTransfer.PermitTransferFrom";
|
|
295
|
+
readonly components: readonly [{
|
|
296
|
+
readonly name: "permitted";
|
|
297
|
+
readonly type: "tuple";
|
|
298
|
+
readonly internalType: "struct ISignatureTransfer.TokenPermissions";
|
|
299
|
+
readonly components: readonly [{
|
|
300
|
+
readonly name: "token";
|
|
301
|
+
readonly type: "address";
|
|
302
|
+
readonly internalType: "address";
|
|
303
|
+
}, {
|
|
304
|
+
readonly name: "amount";
|
|
305
|
+
readonly type: "uint256";
|
|
306
|
+
readonly internalType: "uint256";
|
|
307
|
+
}];
|
|
308
|
+
}, {
|
|
309
|
+
readonly name: "nonce";
|
|
310
|
+
readonly type: "uint256";
|
|
311
|
+
readonly internalType: "uint256";
|
|
312
|
+
}, {
|
|
313
|
+
readonly name: "deadline";
|
|
314
|
+
readonly type: "uint256";
|
|
315
|
+
readonly internalType: "uint256";
|
|
316
|
+
}];
|
|
317
|
+
}, {
|
|
318
|
+
readonly name: "owner";
|
|
319
|
+
readonly type: "address";
|
|
320
|
+
readonly internalType: "address";
|
|
321
|
+
}, {
|
|
322
|
+
readonly name: "witness";
|
|
323
|
+
readonly type: "tuple";
|
|
324
|
+
readonly internalType: "struct x402BasePermit2Proxy.Witness";
|
|
325
|
+
readonly components: readonly [{
|
|
326
|
+
readonly name: "to";
|
|
327
|
+
readonly type: "address";
|
|
328
|
+
readonly internalType: "address";
|
|
329
|
+
}, {
|
|
330
|
+
readonly name: "validAfter";
|
|
331
|
+
readonly type: "uint256";
|
|
332
|
+
readonly internalType: "uint256";
|
|
333
|
+
}, {
|
|
334
|
+
readonly name: "extra";
|
|
335
|
+
readonly type: "bytes";
|
|
336
|
+
readonly internalType: "bytes";
|
|
337
|
+
}];
|
|
338
|
+
}, {
|
|
339
|
+
readonly name: "signature";
|
|
340
|
+
readonly type: "bytes";
|
|
341
|
+
readonly internalType: "bytes";
|
|
342
|
+
}];
|
|
343
|
+
readonly outputs: readonly [];
|
|
344
|
+
readonly stateMutability: "nonpayable";
|
|
345
|
+
}, {
|
|
346
|
+
readonly type: "function";
|
|
347
|
+
readonly name: "settleWithPermit";
|
|
348
|
+
readonly inputs: readonly [{
|
|
349
|
+
readonly name: "permit2612";
|
|
350
|
+
readonly type: "tuple";
|
|
351
|
+
readonly internalType: "struct x402BasePermit2Proxy.EIP2612Permit";
|
|
352
|
+
readonly components: readonly [{
|
|
353
|
+
readonly name: "value";
|
|
354
|
+
readonly type: "uint256";
|
|
355
|
+
readonly internalType: "uint256";
|
|
356
|
+
}, {
|
|
357
|
+
readonly name: "deadline";
|
|
358
|
+
readonly type: "uint256";
|
|
359
|
+
readonly internalType: "uint256";
|
|
360
|
+
}, {
|
|
361
|
+
readonly name: "r";
|
|
362
|
+
readonly type: "bytes32";
|
|
363
|
+
readonly internalType: "bytes32";
|
|
364
|
+
}, {
|
|
365
|
+
readonly name: "s";
|
|
366
|
+
readonly type: "bytes32";
|
|
367
|
+
readonly internalType: "bytes32";
|
|
368
|
+
}, {
|
|
369
|
+
readonly name: "v";
|
|
370
|
+
readonly type: "uint8";
|
|
371
|
+
readonly internalType: "uint8";
|
|
372
|
+
}];
|
|
373
|
+
}, {
|
|
374
|
+
readonly name: "permit";
|
|
375
|
+
readonly type: "tuple";
|
|
376
|
+
readonly internalType: "struct ISignatureTransfer.PermitTransferFrom";
|
|
377
|
+
readonly components: readonly [{
|
|
378
|
+
readonly name: "permitted";
|
|
379
|
+
readonly type: "tuple";
|
|
380
|
+
readonly internalType: "struct ISignatureTransfer.TokenPermissions";
|
|
381
|
+
readonly components: readonly [{
|
|
382
|
+
readonly name: "token";
|
|
383
|
+
readonly type: "address";
|
|
384
|
+
readonly internalType: "address";
|
|
385
|
+
}, {
|
|
386
|
+
readonly name: "amount";
|
|
387
|
+
readonly type: "uint256";
|
|
388
|
+
readonly internalType: "uint256";
|
|
389
|
+
}];
|
|
390
|
+
}, {
|
|
391
|
+
readonly name: "nonce";
|
|
392
|
+
readonly type: "uint256";
|
|
393
|
+
readonly internalType: "uint256";
|
|
394
|
+
}, {
|
|
395
|
+
readonly name: "deadline";
|
|
396
|
+
readonly type: "uint256";
|
|
397
|
+
readonly internalType: "uint256";
|
|
398
|
+
}];
|
|
399
|
+
}, {
|
|
400
|
+
readonly name: "owner";
|
|
401
|
+
readonly type: "address";
|
|
402
|
+
readonly internalType: "address";
|
|
403
|
+
}, {
|
|
404
|
+
readonly name: "witness";
|
|
405
|
+
readonly type: "tuple";
|
|
406
|
+
readonly internalType: "struct x402BasePermit2Proxy.Witness";
|
|
407
|
+
readonly components: readonly [{
|
|
408
|
+
readonly name: "to";
|
|
409
|
+
readonly type: "address";
|
|
410
|
+
readonly internalType: "address";
|
|
411
|
+
}, {
|
|
412
|
+
readonly name: "validAfter";
|
|
413
|
+
readonly type: "uint256";
|
|
414
|
+
readonly internalType: "uint256";
|
|
415
|
+
}, {
|
|
416
|
+
readonly name: "extra";
|
|
417
|
+
readonly type: "bytes";
|
|
418
|
+
readonly internalType: "bytes";
|
|
419
|
+
}];
|
|
420
|
+
}, {
|
|
421
|
+
readonly name: "signature";
|
|
422
|
+
readonly type: "bytes";
|
|
423
|
+
readonly internalType: "bytes";
|
|
424
|
+
}];
|
|
425
|
+
readonly outputs: readonly [];
|
|
426
|
+
readonly stateMutability: "nonpayable";
|
|
427
|
+
}, {
|
|
428
|
+
readonly type: "event";
|
|
429
|
+
readonly name: "Settled";
|
|
430
|
+
readonly inputs: readonly [];
|
|
431
|
+
readonly anonymous: false;
|
|
432
|
+
}, {
|
|
433
|
+
readonly type: "event";
|
|
434
|
+
readonly name: "SettledWithPermit";
|
|
435
|
+
readonly inputs: readonly [];
|
|
436
|
+
readonly anonymous: false;
|
|
437
|
+
}, {
|
|
438
|
+
readonly type: "error";
|
|
439
|
+
readonly name: "AlreadyInitialized";
|
|
440
|
+
readonly inputs: readonly [];
|
|
441
|
+
}, {
|
|
442
|
+
readonly type: "error";
|
|
443
|
+
readonly name: "InvalidDestination";
|
|
444
|
+
readonly inputs: readonly [];
|
|
445
|
+
}, {
|
|
446
|
+
readonly type: "error";
|
|
447
|
+
readonly name: "InvalidOwner";
|
|
448
|
+
readonly inputs: readonly [];
|
|
449
|
+
}, {
|
|
450
|
+
readonly type: "error";
|
|
451
|
+
readonly name: "InvalidPermit2Address";
|
|
452
|
+
readonly inputs: readonly [];
|
|
453
|
+
}, {
|
|
454
|
+
readonly type: "error";
|
|
455
|
+
readonly name: "PaymentTooEarly";
|
|
456
|
+
readonly inputs: readonly [];
|
|
457
|
+
}, {
|
|
458
|
+
readonly type: "error";
|
|
459
|
+
readonly name: "ReentrancyGuardReentrantCall";
|
|
460
|
+
readonly inputs: readonly [];
|
|
461
|
+
}];
|
|
35
462
|
|
|
36
|
-
export {
|
|
463
|
+
export { type AssetTransferMethod, type ExactEIP3009Payload, type ExactEvmPayloadV1, type ExactEvmPayloadV2, type ExactPermit2Payload, PERMIT2_ADDRESS, type Permit2Authorization, type Permit2Witness, authorizationTypes, eip3009ABI, isEIP3009Payload, isPermit2Payload, permit2WitnessTypes, x402ExactPermit2ProxyABI, x402ExactPermit2ProxyAddress, x402UptoPermit2ProxyAddress };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ExactEvmScheme
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
ExactEvmScheme,
|
|
3
|
+
createPermit2ApprovalTx,
|
|
4
|
+
erc20AllowanceAbi,
|
|
5
|
+
getPermit2AllowanceReadParams
|
|
6
|
+
} from "./chunk-E2YMUI3X.mjs";
|
|
7
|
+
import {
|
|
8
|
+
isEIP3009Payload,
|
|
9
|
+
isPermit2Payload
|
|
10
|
+
} from "./chunk-PFULIQAE.mjs";
|
|
11
|
+
import {
|
|
12
|
+
PERMIT2_ADDRESS,
|
|
13
|
+
authorizationTypes,
|
|
14
|
+
eip3009ABI,
|
|
15
|
+
permit2WitnessTypes,
|
|
16
|
+
x402ExactPermit2ProxyABI,
|
|
17
|
+
x402ExactPermit2ProxyAddress,
|
|
18
|
+
x402UptoPermit2ProxyAddress
|
|
19
|
+
} from "./chunk-RPL6OFJL.mjs";
|
|
5
20
|
|
|
6
21
|
// src/signer.ts
|
|
7
22
|
function toClientEvmSigner(signer) {
|
|
@@ -15,7 +30,19 @@ function toFacilitatorEvmSigner(client) {
|
|
|
15
30
|
}
|
|
16
31
|
export {
|
|
17
32
|
ExactEvmScheme,
|
|
33
|
+
PERMIT2_ADDRESS,
|
|
34
|
+
authorizationTypes,
|
|
35
|
+
createPermit2ApprovalTx,
|
|
36
|
+
eip3009ABI,
|
|
37
|
+
erc20AllowanceAbi,
|
|
38
|
+
getPermit2AllowanceReadParams,
|
|
39
|
+
isEIP3009Payload,
|
|
40
|
+
isPermit2Payload,
|
|
41
|
+
permit2WitnessTypes,
|
|
18
42
|
toClientEvmSigner,
|
|
19
|
-
toFacilitatorEvmSigner
|
|
43
|
+
toFacilitatorEvmSigner,
|
|
44
|
+
x402ExactPermit2ProxyABI,
|
|
45
|
+
x402ExactPermit2ProxyAddress,
|
|
46
|
+
x402UptoPermit2ProxyAddress
|
|
20
47
|
};
|
|
21
48
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/signer.ts"],"sourcesContent":["/**\n * ClientEvmSigner - Used by x402 clients to sign payment authorizations\n * This is typically a LocalAccount or wallet that holds private keys\n * and can sign EIP-712 typed data for payment authorizations\n */\nexport type ClientEvmSigner = {\n readonly address: `0x${string}`;\n signTypedData(message: {\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<`0x${string}`>;\n};\n\n/**\n * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments\n * This is typically a viem PublicClient + WalletClient combination that can\n * read contract state, verify signatures, write transactions, and wait for receipts\n *\n * Supports multiple addresses for load balancing, key rotation, and high availability\n */\nexport type FacilitatorEvmSigner = {\n /**\n * Get all addresses this facilitator can use for signing\n * Enables dynamic address selection for load balancing and key rotation\n */\n getAddresses(): readonly `0x${string}`[];\n\n readContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args?: readonly unknown[];\n }): Promise<unknown>;\n verifyTypedData(args: {\n address: `0x${string}`;\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n signature: `0x${string}`;\n }): Promise<boolean>;\n writeContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args: readonly unknown[];\n }): Promise<`0x${string}`>;\n sendTransaction(args: { to: `0x${string}`; data: `0x${string}` }): Promise<`0x${string}`>;\n waitForTransactionReceipt(args: { hash: `0x${string}` }): Promise<{ status: string }>;\n getCode(args: { address: `0x${string}` }): Promise<`0x${string}` | undefined>;\n};\n\n/**\n * Converts a signer to a ClientEvmSigner\n *\n * @param signer - The signer to convert to a ClientEvmSigner\n * @returns The converted signer\n */\nexport function toClientEvmSigner(signer: ClientEvmSigner): ClientEvmSigner {\n return signer;\n}\n\n/**\n * Converts a viem client with single address to a FacilitatorEvmSigner\n * Wraps the single address in a getAddresses() function for compatibility\n *\n * @param client - The client to convert (must have 'address' property)\n * @returns FacilitatorEvmSigner with getAddresses() support\n */\nexport function toFacilitatorEvmSigner(\n client: Omit<FacilitatorEvmSigner, \"getAddresses\"> & { address: `0x${string}` },\n): FacilitatorEvmSigner {\n return {\n ...client,\n getAddresses: () => [client.address],\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/signer.ts"],"sourcesContent":["/**\n * ClientEvmSigner - Used by x402 clients to sign payment authorizations\n * This is typically a LocalAccount or wallet that holds private keys\n * and can sign EIP-712 typed data for payment authorizations\n */\nexport type ClientEvmSigner = {\n readonly address: `0x${string}`;\n signTypedData(message: {\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<`0x${string}`>;\n};\n\n/**\n * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments\n * This is typically a viem PublicClient + WalletClient combination that can\n * read contract state, verify signatures, write transactions, and wait for receipts\n *\n * Supports multiple addresses for load balancing, key rotation, and high availability\n */\nexport type FacilitatorEvmSigner = {\n /**\n * Get all addresses this facilitator can use for signing\n * Enables dynamic address selection for load balancing and key rotation\n */\n getAddresses(): readonly `0x${string}`[];\n\n readContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args?: readonly unknown[];\n }): Promise<unknown>;\n verifyTypedData(args: {\n address: `0x${string}`;\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n signature: `0x${string}`;\n }): Promise<boolean>;\n writeContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args: readonly unknown[];\n }): Promise<`0x${string}`>;\n sendTransaction(args: { to: `0x${string}`; data: `0x${string}` }): Promise<`0x${string}`>;\n waitForTransactionReceipt(args: { hash: `0x${string}` }): Promise<{ status: string }>;\n getCode(args: { address: `0x${string}` }): Promise<`0x${string}` | undefined>;\n};\n\n/**\n * Converts a signer to a ClientEvmSigner\n *\n * @param signer - The signer to convert to a ClientEvmSigner\n * @returns The converted signer\n */\nexport function toClientEvmSigner(signer: ClientEvmSigner): ClientEvmSigner {\n return signer;\n}\n\n/**\n * Converts a viem client with single address to a FacilitatorEvmSigner\n * Wraps the single address in a getAddresses() function for compatibility\n *\n * @param client - The client to convert (must have 'address' property)\n * @returns FacilitatorEvmSigner with getAddresses() support\n */\nexport function toFacilitatorEvmSigner(\n client: Omit<FacilitatorEvmSigner, \"getAddresses\"> & { address: `0x${string}` },\n): FacilitatorEvmSigner {\n return {\n ...client,\n getAddresses: () => [client.address],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4DO,SAAS,kBAAkB,QAA0C;AAC1E,SAAO;AACT;AASO,SAAS,uBACd,QACsB;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,cAAc,MAAM,CAAC,OAAO,OAAO;AAAA,EACrC;AACF;","names":[]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { SchemeNetworkClient, PaymentRequirements, PaymentPayloadResult } from '@x402/core/types';
|
|
2
|
+
import { C as ClientEvmSigner } from './signer-5OVDxViv.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* EVM client implementation for the Exact payment scheme.
|
|
6
|
+
* Supports both EIP-3009 (transferWithAuthorization) and Permit2 flows.
|
|
7
|
+
*
|
|
8
|
+
* Routes to the appropriate authorization method based on
|
|
9
|
+
* `requirements.extra.assetTransferMethod`. Defaults to EIP-3009
|
|
10
|
+
* for backward compatibility with older facilitators.
|
|
11
|
+
*/
|
|
12
|
+
declare class ExactEvmScheme implements SchemeNetworkClient {
|
|
13
|
+
private readonly signer;
|
|
14
|
+
readonly scheme = "exact";
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new ExactEvmClient instance.
|
|
17
|
+
*
|
|
18
|
+
* @param signer - The EVM signer for client operations
|
|
19
|
+
*/
|
|
20
|
+
constructor(signer: ClientEvmSigner);
|
|
21
|
+
/**
|
|
22
|
+
* Creates a payment payload for the Exact scheme.
|
|
23
|
+
* Routes to EIP-3009 or Permit2 based on requirements.extra.assetTransferMethod.
|
|
24
|
+
*
|
|
25
|
+
* @param x402Version - The x402 protocol version
|
|
26
|
+
* @param paymentRequirements - The payment requirements
|
|
27
|
+
* @returns Promise resolving to a payment payload result
|
|
28
|
+
*/
|
|
29
|
+
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<PaymentPayloadResult>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ERC20 allowance ABI for checking approval status.
|
|
34
|
+
*/
|
|
35
|
+
declare const erc20AllowanceAbi: readonly [{
|
|
36
|
+
readonly type: "function";
|
|
37
|
+
readonly name: "allowance";
|
|
38
|
+
readonly inputs: readonly [{
|
|
39
|
+
readonly name: "owner";
|
|
40
|
+
readonly type: "address";
|
|
41
|
+
}, {
|
|
42
|
+
readonly name: "spender";
|
|
43
|
+
readonly type: "address";
|
|
44
|
+
}];
|
|
45
|
+
readonly outputs: readonly [{
|
|
46
|
+
readonly type: "uint256";
|
|
47
|
+
}];
|
|
48
|
+
readonly stateMutability: "view";
|
|
49
|
+
}];
|
|
50
|
+
/**
|
|
51
|
+
* Creates transaction data to approve Permit2 to spend tokens.
|
|
52
|
+
* The user sends this transaction (paying gas) before using Permit2 flow.
|
|
53
|
+
*
|
|
54
|
+
* @param tokenAddress - The ERC20 token contract address
|
|
55
|
+
* @returns Transaction data to send for approval
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const tx = createPermit2ApprovalTx("0x...");
|
|
60
|
+
* await walletClient.sendTransaction({
|
|
61
|
+
* to: tx.to,
|
|
62
|
+
* data: tx.data,
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function createPermit2ApprovalTx(tokenAddress: `0x${string}`): {
|
|
67
|
+
to: `0x${string}`;
|
|
68
|
+
data: `0x${string}`;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Parameters for checking Permit2 allowance.
|
|
72
|
+
* Application provides these to check if approval is needed.
|
|
73
|
+
*/
|
|
74
|
+
interface Permit2AllowanceParams {
|
|
75
|
+
tokenAddress: `0x${string}`;
|
|
76
|
+
ownerAddress: `0x${string}`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns contract read parameters for checking Permit2 allowance.
|
|
80
|
+
* Use with a public client to check if the user has approved Permit2.
|
|
81
|
+
*
|
|
82
|
+
* @param params - The allowance check parameters
|
|
83
|
+
* @returns Contract read parameters for checking allowance
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const readParams = getPermit2AllowanceReadParams({
|
|
88
|
+
* tokenAddress: "0x...",
|
|
89
|
+
* ownerAddress: "0x...",
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* const allowance = await publicClient.readContract(readParams);
|
|
93
|
+
* const needsApproval = allowance < requiredAmount;
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare function getPermit2AllowanceReadParams(params: Permit2AllowanceParams): {
|
|
97
|
+
address: `0x${string}`;
|
|
98
|
+
abi: typeof erc20AllowanceAbi;
|
|
99
|
+
functionName: "allowance";
|
|
100
|
+
args: [`0x${string}`, `0x${string}`];
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { ExactEvmScheme as E, type Permit2AllowanceParams as P, createPermit2ApprovalTx as c, erc20AllowanceAbi as e, getPermit2AllowanceReadParams as g };
|
package/dist/esm/v1/index.d.mts
CHANGED
|
@@ -2,6 +2,27 @@ export { ExactEvmSchemeV1 } from '../exact/v1/client/index.mjs';
|
|
|
2
2
|
import '@x402/core/types';
|
|
3
3
|
import '../signer-5OVDxViv.mjs';
|
|
4
4
|
|
|
5
|
+
declare const EVM_NETWORK_CHAIN_ID_MAP: {
|
|
6
|
+
readonly ethereum: 1;
|
|
7
|
+
readonly sepolia: 11155111;
|
|
8
|
+
readonly abstract: 2741;
|
|
9
|
+
readonly "abstract-testnet": 11124;
|
|
10
|
+
readonly "base-sepolia": 84532;
|
|
11
|
+
readonly base: 8453;
|
|
12
|
+
readonly "avalanche-fuji": 43113;
|
|
13
|
+
readonly avalanche: 43114;
|
|
14
|
+
readonly iotex: 4689;
|
|
15
|
+
readonly sei: 1329;
|
|
16
|
+
readonly "sei-testnet": 1328;
|
|
17
|
+
readonly polygon: 137;
|
|
18
|
+
readonly "polygon-amoy": 80002;
|
|
19
|
+
readonly peaq: 3338;
|
|
20
|
+
readonly story: 1514;
|
|
21
|
+
readonly educhain: 41923;
|
|
22
|
+
readonly "skale-base-sepolia": 324705682;
|
|
23
|
+
readonly megaeth: 4326;
|
|
24
|
+
};
|
|
25
|
+
type EvmNetworkV1 = keyof typeof EVM_NETWORK_CHAIN_ID_MAP;
|
|
5
26
|
declare const NETWORKS: string[];
|
|
6
27
|
|
|
7
|
-
export { NETWORKS };
|
|
28
|
+
export { EVM_NETWORK_CHAIN_ID_MAP, type EvmNetworkV1, NETWORKS };
|