@x402/evm 2.2.0 → 2.3.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.
Files changed (48) hide show
  1. package/dist/cjs/exact/client/index.d.ts +2 -2
  2. package/dist/cjs/exact/client/index.js +264 -119
  3. package/dist/cjs/exact/client/index.js.map +1 -1
  4. package/dist/cjs/exact/facilitator/index.d.ts +3 -0
  5. package/dist/cjs/exact/facilitator/index.js +691 -281
  6. package/dist/cjs/exact/facilitator/index.js.map +1 -1
  7. package/dist/cjs/exact/v1/client/index.js +43 -17
  8. package/dist/cjs/exact/v1/client/index.js.map +1 -1
  9. package/dist/cjs/exact/v1/facilitator/index.js +59 -26
  10. package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
  11. package/dist/cjs/index.d.ts +458 -31
  12. package/dist/cjs/index.js +438 -63
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/permit2-BYv82va2.d.ts +103 -0
  15. package/dist/cjs/v1/index.d.ts +21 -1
  16. package/dist/cjs/v1/index.js +33 -29
  17. package/dist/cjs/v1/index.js.map +1 -1
  18. package/dist/esm/chunk-DSSJHWGT.mjs +658 -0
  19. package/dist/esm/chunk-DSSJHWGT.mjs.map +1 -0
  20. package/dist/esm/chunk-PFULIQAE.mjs +13 -0
  21. package/dist/esm/chunk-PFULIQAE.mjs.map +1 -0
  22. package/dist/esm/chunk-U4H6Q62Q.mjs +229 -0
  23. package/dist/esm/chunk-U4H6Q62Q.mjs.map +1 -0
  24. package/dist/esm/exact/client/index.d.mts +2 -2
  25. package/dist/esm/exact/client/index.mjs +10 -30
  26. package/dist/esm/exact/client/index.mjs.map +1 -1
  27. package/dist/esm/exact/facilitator/index.d.mts +3 -0
  28. package/dist/esm/exact/facilitator/index.mjs +491 -241
  29. package/dist/esm/exact/facilitator/index.mjs.map +1 -1
  30. package/dist/esm/exact/v1/client/index.mjs +1 -2
  31. package/dist/esm/exact/v1/facilitator/index.mjs +2 -3
  32. package/dist/esm/index.d.mts +458 -31
  33. package/dist/esm/index.mjs +31 -4
  34. package/dist/esm/index.mjs.map +1 -1
  35. package/dist/esm/permit2-BsAoJiWD.d.mts +103 -0
  36. package/dist/esm/v1/index.d.mts +21 -1
  37. package/dist/esm/v1/index.mjs +4 -6
  38. package/package.json +2 -2
  39. package/dist/esm/chunk-FOUXRQAV.mjs +0 -88
  40. package/dist/esm/chunk-FOUXRQAV.mjs.map +0 -1
  41. package/dist/esm/chunk-JYZWCLMP.mjs +0 -305
  42. package/dist/esm/chunk-JYZWCLMP.mjs.map +0 -1
  43. package/dist/esm/chunk-PSA4YVU2.mjs +0 -92
  44. package/dist/esm/chunk-PSA4YVU2.mjs.map +0 -1
  45. package/dist/esm/chunk-QLXM7BIB.mjs +0 -23
  46. package/dist/esm/chunk-QLXM7BIB.mjs.map +0 -1
  47. package/dist/esm/chunk-ZYXTTU74.mjs +0 -88
  48. package/dist/esm/chunk-ZYXTTU74.mjs.map +0 -1
@@ -1,36 +1,463 @@
1
- import { SchemeNetworkClient, PaymentRequirements, PaymentPayload } from '@x402/core/types';
2
- import { C as ClientEvmSigner } from './signer-5OVDxViv.js';
3
- export { F as FacilitatorEvmSigner, t as toClientEvmSigner, a as toFacilitatorEvmSigner } from './signer-5OVDxViv.js';
1
+ export { E as ExactEvmScheme, P as Permit2AllowanceParams, c as createPermit2ApprovalTx, e as erc20AllowanceAbi, g as getPermit2AllowanceReadParams } from './permit2-BYv82va2.js';
2
+ export { C as ClientEvmSigner, F as FacilitatorEvmSigner, t as toClientEvmSigner, a as toFacilitatorEvmSigner } from './signer-5OVDxViv.js';
3
+ import '@x402/core/types';
4
4
 
5
5
  /**
6
- * EVM client implementation for the Exact payment scheme.
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 class ExactEvmScheme implements SchemeNetworkClient {
10
- private readonly signer;
11
- readonly scheme = "exact";
12
- /**
13
- * Creates a new ExactEvmClient 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 scheme.
20
- *
21
- * @param x402Version - The x402 protocol version
22
- * @param paymentRequirements - The payment requirements
23
- * @returns Promise resolving to a payment payload
24
- */
25
- createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
26
- /**
27
- * Sign the EIP-3009 authorization using EIP-712
28
- *
29
- * @param authorization - The authorization to sign
30
- * @param requirements - The payment requirements
31
- * @returns Promise resolving to the signature
32
- */
33
- private signAuthorization;
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 { ClientEvmSigner, ExactEvmScheme };
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 };