@x402/evm 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exact/client/index.d.ts +2 -2
- package/dist/cjs/exact/client/index.js +284 -192
- package/dist/cjs/exact/client/index.js.map +1 -1
- package/dist/cjs/exact/facilitator/index.d.ts +18 -18
- package/dist/cjs/exact/facilitator/index.js +454 -234
- package/dist/cjs/exact/facilitator/index.js.map +1 -1
- package/dist/cjs/exact/v1/client/index.d.ts +1 -1
- package/dist/cjs/exact/v1/client/index.js +17 -18
- package/dist/cjs/exact/v1/client/index.js.map +1 -1
- package/dist/cjs/exact/v1/facilitator/index.d.ts +1 -1
- package/dist/cjs/exact/v1/facilitator/index.js +7 -8
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -390
- package/dist/cjs/index.js +225 -132
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/permit2-CQbXqCMC.d.ts +517 -0
- package/dist/cjs/{signer-3KGwtdNT.d.ts → signer-DC81R8wQ.d.ts} +37 -0
- package/dist/cjs/v1/index.d.ts +11 -2
- package/dist/cjs/v1/index.js +14 -11
- package/dist/cjs/v1/index.js.map +1 -1
- package/dist/esm/{chunk-GSU4DHTC.mjs → chunk-7KHQD5KT.mjs} +72 -37
- package/dist/esm/chunk-7KHQD5KT.mjs.map +1 -0
- package/dist/esm/{chunk-CJHYX7BQ.mjs → chunk-GY6X5A3G.mjs} +119 -56
- package/dist/esm/chunk-GY6X5A3G.mjs.map +1 -0
- package/dist/esm/{chunk-PFULIQAE.mjs → chunk-TKN5V2BV.mjs} +1 -1
- package/dist/esm/chunk-TKN5V2BV.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +2 -2
- package/dist/esm/exact/client/index.mjs +4 -3
- package/dist/esm/exact/facilitator/index.d.mts +18 -18
- package/dist/esm/exact/facilitator/index.mjs +385 -176
- package/dist/esm/exact/facilitator/index.mjs.map +1 -1
- package/dist/esm/exact/v1/client/index.d.mts +1 -1
- package/dist/esm/exact/v1/client/index.mjs +2 -2
- package/dist/esm/exact/v1/facilitator/index.d.mts +1 -1
- package/dist/esm/exact/v1/facilitator/index.mjs +2 -2
- package/dist/esm/index.d.mts +3 -390
- package/dist/esm/index.mjs +18 -5
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/permit2-CGOcN7Et.d.mts +517 -0
- package/dist/esm/{signer-3KGwtdNT.d.mts → signer-DC81R8wQ.d.mts} +37 -0
- package/dist/esm/v1/index.d.mts +11 -2
- package/dist/esm/v1/index.mjs +6 -4
- package/package.json +3 -3
- package/dist/cjs/permit2-CzKPU5By.d.ts +0 -130
- package/dist/esm/chunk-CJHYX7BQ.mjs.map +0 -1
- package/dist/esm/chunk-GSU4DHTC.mjs.map +0 -1
- package/dist/esm/chunk-PFULIQAE.mjs.map +0 -1
- package/dist/esm/permit2-C2FkNEHT.d.mts +0 -130
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import { SchemeNetworkClient, PaymentRequirements, PaymentPayloadContext, PaymentPayloadResult } from '@x402/core/types';
|
|
2
|
+
import { C as ClientEvmSigner } from './signer-DC81R8wQ.js';
|
|
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
|
+
* When the server advertises `eip2612GasSponsoring` and the asset transfer
|
|
13
|
+
* method is `permit2`, the scheme automatically signs an EIP-2612 permit
|
|
14
|
+
* if the user lacks Permit2 approval. This requires `readContract` on the signer.
|
|
15
|
+
*/
|
|
16
|
+
declare class ExactEvmScheme implements SchemeNetworkClient {
|
|
17
|
+
private readonly signer;
|
|
18
|
+
readonly scheme = "exact";
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new ExactEvmClient instance.
|
|
21
|
+
*
|
|
22
|
+
* @param signer - The EVM signer for client operations.
|
|
23
|
+
* Must support `readContract` for EIP-2612 gas sponsoring.
|
|
24
|
+
* Use `createWalletClient(...).extend(publicActions)` or `toClientEvmSigner(account, publicClient)`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(signer: ClientEvmSigner);
|
|
27
|
+
/**
|
|
28
|
+
* Creates a payment payload for the Exact scheme.
|
|
29
|
+
* Routes to EIP-3009 or Permit2 based on requirements.extra.assetTransferMethod.
|
|
30
|
+
*
|
|
31
|
+
* For Permit2 flows, if the server advertises `eip2612GasSponsoring` and the
|
|
32
|
+
* signer supports `readContract`, automatically signs an EIP-2612 permit
|
|
33
|
+
* when Permit2 allowance is insufficient.
|
|
34
|
+
*
|
|
35
|
+
* @param x402Version - The x402 protocol version
|
|
36
|
+
* @param paymentRequirements - The payment requirements
|
|
37
|
+
* @param context - Optional context with server-declared extensions
|
|
38
|
+
* @returns Promise resolving to a payment payload result (with optional extensions)
|
|
39
|
+
*/
|
|
40
|
+
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements, context?: PaymentPayloadContext): Promise<PaymentPayloadResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Attempts to sign an EIP-2612 permit for gasless Permit2 approval.
|
|
43
|
+
*
|
|
44
|
+
* Returns extension data if:
|
|
45
|
+
* 1. Server advertises eip2612GasSponsoring
|
|
46
|
+
* 2. Signer has readContract capability
|
|
47
|
+
* 3. Current Permit2 allowance is insufficient
|
|
48
|
+
*
|
|
49
|
+
* Returns undefined if the extension should not be used.
|
|
50
|
+
*
|
|
51
|
+
* @param requirements - The payment requirements from the server
|
|
52
|
+
* @param result - The payment payload result from the scheme
|
|
53
|
+
* @param context - Optional context containing server extensions and metadata
|
|
54
|
+
* @returns Extension data for EIP-2612 gas sponsoring, or undefined if not applicable
|
|
55
|
+
*/
|
|
56
|
+
private trySignEip2612Permit;
|
|
57
|
+
/**
|
|
58
|
+
* Attempts to sign an ERC-20 approval transaction for gasless Permit2 approval.
|
|
59
|
+
*
|
|
60
|
+
* This is the fallback path when the token does not support EIP-2612. The client
|
|
61
|
+
* signs (but does not broadcast) a raw `approve(Permit2, MaxUint256)` transaction.
|
|
62
|
+
* The facilitator broadcasts it atomically before settling.
|
|
63
|
+
*
|
|
64
|
+
* Returns extension data if:
|
|
65
|
+
* 1. Server advertises erc20ApprovalGasSponsoring
|
|
66
|
+
* 2. Signer has signTransaction + getTransactionCount capabilities
|
|
67
|
+
* 3. Current Permit2 allowance is insufficient
|
|
68
|
+
*
|
|
69
|
+
* Returns undefined if the extension should not be used.
|
|
70
|
+
*
|
|
71
|
+
* @param requirements - The payment requirements from the server
|
|
72
|
+
* @param _result - The payment payload result from the scheme (unused)
|
|
73
|
+
* @param context - Optional context containing server extensions and metadata
|
|
74
|
+
* @returns Extension data for ERC-20 approval gas sponsoring, or undefined if not applicable
|
|
75
|
+
*/
|
|
76
|
+
private trySignErc20Approval;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare const authorizationTypes: {
|
|
80
|
+
readonly TransferWithAuthorization: readonly [{
|
|
81
|
+
readonly name: "from";
|
|
82
|
+
readonly type: "address";
|
|
83
|
+
}, {
|
|
84
|
+
readonly name: "to";
|
|
85
|
+
readonly type: "address";
|
|
86
|
+
}, {
|
|
87
|
+
readonly name: "value";
|
|
88
|
+
readonly type: "uint256";
|
|
89
|
+
}, {
|
|
90
|
+
readonly name: "validAfter";
|
|
91
|
+
readonly type: "uint256";
|
|
92
|
+
}, {
|
|
93
|
+
readonly name: "validBefore";
|
|
94
|
+
readonly type: "uint256";
|
|
95
|
+
}, {
|
|
96
|
+
readonly name: "nonce";
|
|
97
|
+
readonly type: "bytes32";
|
|
98
|
+
}];
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Permit2 EIP-712 types for signing PermitWitnessTransferFrom.
|
|
102
|
+
* Must match the exact format expected by the Permit2 contract.
|
|
103
|
+
* Note: Types must be in ALPHABETICAL order after the primary type (TokenPermissions < Witness).
|
|
104
|
+
*/
|
|
105
|
+
declare const permit2WitnessTypes: {
|
|
106
|
+
readonly PermitWitnessTransferFrom: readonly [{
|
|
107
|
+
readonly name: "permitted";
|
|
108
|
+
readonly type: "TokenPermissions";
|
|
109
|
+
}, {
|
|
110
|
+
readonly name: "spender";
|
|
111
|
+
readonly type: "address";
|
|
112
|
+
}, {
|
|
113
|
+
readonly name: "nonce";
|
|
114
|
+
readonly type: "uint256";
|
|
115
|
+
}, {
|
|
116
|
+
readonly name: "deadline";
|
|
117
|
+
readonly type: "uint256";
|
|
118
|
+
}, {
|
|
119
|
+
readonly name: "witness";
|
|
120
|
+
readonly type: "Witness";
|
|
121
|
+
}];
|
|
122
|
+
readonly TokenPermissions: readonly [{
|
|
123
|
+
readonly name: "token";
|
|
124
|
+
readonly type: "address";
|
|
125
|
+
}, {
|
|
126
|
+
readonly name: "amount";
|
|
127
|
+
readonly type: "uint256";
|
|
128
|
+
}];
|
|
129
|
+
readonly Witness: readonly [{
|
|
130
|
+
readonly name: "to";
|
|
131
|
+
readonly type: "address";
|
|
132
|
+
}, {
|
|
133
|
+
readonly name: "validAfter";
|
|
134
|
+
readonly type: "uint256";
|
|
135
|
+
}];
|
|
136
|
+
};
|
|
137
|
+
declare const eip3009ABI: readonly [{
|
|
138
|
+
readonly inputs: readonly [{
|
|
139
|
+
readonly name: "from";
|
|
140
|
+
readonly type: "address";
|
|
141
|
+
}, {
|
|
142
|
+
readonly name: "to";
|
|
143
|
+
readonly type: "address";
|
|
144
|
+
}, {
|
|
145
|
+
readonly name: "value";
|
|
146
|
+
readonly type: "uint256";
|
|
147
|
+
}, {
|
|
148
|
+
readonly name: "validAfter";
|
|
149
|
+
readonly type: "uint256";
|
|
150
|
+
}, {
|
|
151
|
+
readonly name: "validBefore";
|
|
152
|
+
readonly type: "uint256";
|
|
153
|
+
}, {
|
|
154
|
+
readonly name: "nonce";
|
|
155
|
+
readonly type: "bytes32";
|
|
156
|
+
}, {
|
|
157
|
+
readonly name: "v";
|
|
158
|
+
readonly type: "uint8";
|
|
159
|
+
}, {
|
|
160
|
+
readonly name: "r";
|
|
161
|
+
readonly type: "bytes32";
|
|
162
|
+
}, {
|
|
163
|
+
readonly name: "s";
|
|
164
|
+
readonly type: "bytes32";
|
|
165
|
+
}];
|
|
166
|
+
readonly name: "transferWithAuthorization";
|
|
167
|
+
readonly outputs: readonly [];
|
|
168
|
+
readonly stateMutability: "nonpayable";
|
|
169
|
+
readonly type: "function";
|
|
170
|
+
}, {
|
|
171
|
+
readonly inputs: readonly [{
|
|
172
|
+
readonly name: "from";
|
|
173
|
+
readonly type: "address";
|
|
174
|
+
}, {
|
|
175
|
+
readonly name: "to";
|
|
176
|
+
readonly type: "address";
|
|
177
|
+
}, {
|
|
178
|
+
readonly name: "value";
|
|
179
|
+
readonly type: "uint256";
|
|
180
|
+
}, {
|
|
181
|
+
readonly name: "validAfter";
|
|
182
|
+
readonly type: "uint256";
|
|
183
|
+
}, {
|
|
184
|
+
readonly name: "validBefore";
|
|
185
|
+
readonly type: "uint256";
|
|
186
|
+
}, {
|
|
187
|
+
readonly name: "nonce";
|
|
188
|
+
readonly type: "bytes32";
|
|
189
|
+
}, {
|
|
190
|
+
readonly name: "signature";
|
|
191
|
+
readonly type: "bytes";
|
|
192
|
+
}];
|
|
193
|
+
readonly name: "transferWithAuthorization";
|
|
194
|
+
readonly outputs: readonly [];
|
|
195
|
+
readonly stateMutability: "nonpayable";
|
|
196
|
+
readonly type: "function";
|
|
197
|
+
}, {
|
|
198
|
+
readonly inputs: readonly [{
|
|
199
|
+
readonly name: "account";
|
|
200
|
+
readonly type: "address";
|
|
201
|
+
}];
|
|
202
|
+
readonly name: "balanceOf";
|
|
203
|
+
readonly outputs: readonly [{
|
|
204
|
+
readonly name: "";
|
|
205
|
+
readonly type: "uint256";
|
|
206
|
+
}];
|
|
207
|
+
readonly stateMutability: "view";
|
|
208
|
+
readonly type: "function";
|
|
209
|
+
}, {
|
|
210
|
+
readonly inputs: readonly [];
|
|
211
|
+
readonly name: "version";
|
|
212
|
+
readonly outputs: readonly [{
|
|
213
|
+
readonly name: "";
|
|
214
|
+
readonly type: "string";
|
|
215
|
+
}];
|
|
216
|
+
readonly stateMutability: "view";
|
|
217
|
+
readonly type: "function";
|
|
218
|
+
}];
|
|
219
|
+
/** ERC-20 allowance(address,address) ABI for checking spender approval. */
|
|
220
|
+
declare const erc20AllowanceAbi: readonly [{
|
|
221
|
+
readonly type: "function";
|
|
222
|
+
readonly name: "allowance";
|
|
223
|
+
readonly inputs: readonly [{
|
|
224
|
+
readonly name: "owner";
|
|
225
|
+
readonly type: "address";
|
|
226
|
+
}, {
|
|
227
|
+
readonly name: "spender";
|
|
228
|
+
readonly type: "address";
|
|
229
|
+
}];
|
|
230
|
+
readonly outputs: readonly [{
|
|
231
|
+
readonly type: "uint256";
|
|
232
|
+
}];
|
|
233
|
+
readonly stateMutability: "view";
|
|
234
|
+
}];
|
|
235
|
+
/**
|
|
236
|
+
* Canonical Permit2 contract address.
|
|
237
|
+
* Same address on all EVM chains via CREATE2 deployment.
|
|
238
|
+
*
|
|
239
|
+
* @see https://github.com/Uniswap/permit2
|
|
240
|
+
*/
|
|
241
|
+
declare const PERMIT2_ADDRESS: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
242
|
+
/**
|
|
243
|
+
* x402ExactPermit2Proxy contract address.
|
|
244
|
+
* Vanity address: 0x4020...0001 for easy recognition.
|
|
245
|
+
* This address is deterministic based on:
|
|
246
|
+
* - Arachnid's deterministic deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C)
|
|
247
|
+
* - Vanity-mined salt for prefix 0x4020 and suffix 0001
|
|
248
|
+
* - Contract bytecode + constructor args (PERMIT2_ADDRESS)
|
|
249
|
+
*/
|
|
250
|
+
declare const x402ExactPermit2ProxyAddress: "0x402085c248EeA27D92E8b30b2C58ed07f9E20001";
|
|
251
|
+
/**
|
|
252
|
+
* x402UptoPermit2Proxy contract address.
|
|
253
|
+
* Vanity address: 0x4020...0002 for easy recognition.
|
|
254
|
+
* This address is deterministic based on:
|
|
255
|
+
* - Arachnid's deterministic deployer (0x4e59b44847b379578588920cA78FbF26c0B4956C)
|
|
256
|
+
* - Vanity-mined salt for prefix 0x4020 and suffix 0002
|
|
257
|
+
* - Contract bytecode + constructor args (PERMIT2_ADDRESS)
|
|
258
|
+
*/
|
|
259
|
+
declare const x402UptoPermit2ProxyAddress: "0x402039b3d6E6BEC5A02c2C9fd937ac17A6940002";
|
|
260
|
+
/**
|
|
261
|
+
* x402ExactPermit2Proxy ABI - settle function for exact payment scheme.
|
|
262
|
+
*/
|
|
263
|
+
declare const x402ExactPermit2ProxyABI: readonly [{
|
|
264
|
+
readonly type: "function";
|
|
265
|
+
readonly name: "PERMIT2";
|
|
266
|
+
readonly inputs: readonly [];
|
|
267
|
+
readonly outputs: readonly [{
|
|
268
|
+
readonly name: "";
|
|
269
|
+
readonly type: "address";
|
|
270
|
+
readonly internalType: "contract ISignatureTransfer";
|
|
271
|
+
}];
|
|
272
|
+
readonly stateMutability: "view";
|
|
273
|
+
}, {
|
|
274
|
+
readonly type: "function";
|
|
275
|
+
readonly name: "WITNESS_TYPEHASH";
|
|
276
|
+
readonly inputs: readonly [];
|
|
277
|
+
readonly outputs: readonly [{
|
|
278
|
+
readonly name: "";
|
|
279
|
+
readonly type: "bytes32";
|
|
280
|
+
readonly internalType: "bytes32";
|
|
281
|
+
}];
|
|
282
|
+
readonly stateMutability: "view";
|
|
283
|
+
}, {
|
|
284
|
+
readonly type: "function";
|
|
285
|
+
readonly name: "WITNESS_TYPE_STRING";
|
|
286
|
+
readonly inputs: readonly [];
|
|
287
|
+
readonly outputs: readonly [{
|
|
288
|
+
readonly name: "";
|
|
289
|
+
readonly type: "string";
|
|
290
|
+
readonly internalType: "string";
|
|
291
|
+
}];
|
|
292
|
+
readonly stateMutability: "view";
|
|
293
|
+
}, {
|
|
294
|
+
readonly type: "function";
|
|
295
|
+
readonly name: "settle";
|
|
296
|
+
readonly inputs: readonly [{
|
|
297
|
+
readonly name: "permit";
|
|
298
|
+
readonly type: "tuple";
|
|
299
|
+
readonly internalType: "struct ISignatureTransfer.PermitTransferFrom";
|
|
300
|
+
readonly components: readonly [{
|
|
301
|
+
readonly name: "permitted";
|
|
302
|
+
readonly type: "tuple";
|
|
303
|
+
readonly internalType: "struct ISignatureTransfer.TokenPermissions";
|
|
304
|
+
readonly components: readonly [{
|
|
305
|
+
readonly name: "token";
|
|
306
|
+
readonly type: "address";
|
|
307
|
+
readonly internalType: "address";
|
|
308
|
+
}, {
|
|
309
|
+
readonly name: "amount";
|
|
310
|
+
readonly type: "uint256";
|
|
311
|
+
readonly internalType: "uint256";
|
|
312
|
+
}];
|
|
313
|
+
}, {
|
|
314
|
+
readonly name: "nonce";
|
|
315
|
+
readonly type: "uint256";
|
|
316
|
+
readonly internalType: "uint256";
|
|
317
|
+
}, {
|
|
318
|
+
readonly name: "deadline";
|
|
319
|
+
readonly type: "uint256";
|
|
320
|
+
readonly internalType: "uint256";
|
|
321
|
+
}];
|
|
322
|
+
}, {
|
|
323
|
+
readonly name: "owner";
|
|
324
|
+
readonly type: "address";
|
|
325
|
+
readonly internalType: "address";
|
|
326
|
+
}, {
|
|
327
|
+
readonly name: "witness";
|
|
328
|
+
readonly type: "tuple";
|
|
329
|
+
readonly internalType: "struct x402ExactPermit2Proxy.Witness";
|
|
330
|
+
readonly components: readonly [{
|
|
331
|
+
readonly name: "to";
|
|
332
|
+
readonly type: "address";
|
|
333
|
+
readonly internalType: "address";
|
|
334
|
+
}, {
|
|
335
|
+
readonly name: "validAfter";
|
|
336
|
+
readonly type: "uint256";
|
|
337
|
+
readonly internalType: "uint256";
|
|
338
|
+
}];
|
|
339
|
+
}, {
|
|
340
|
+
readonly name: "signature";
|
|
341
|
+
readonly type: "bytes";
|
|
342
|
+
readonly internalType: "bytes";
|
|
343
|
+
}];
|
|
344
|
+
readonly outputs: readonly [];
|
|
345
|
+
readonly stateMutability: "nonpayable";
|
|
346
|
+
}, {
|
|
347
|
+
readonly type: "function";
|
|
348
|
+
readonly name: "settleWithPermit";
|
|
349
|
+
readonly inputs: readonly [{
|
|
350
|
+
readonly name: "permit2612";
|
|
351
|
+
readonly type: "tuple";
|
|
352
|
+
readonly internalType: "struct x402ExactPermit2Proxy.EIP2612Permit";
|
|
353
|
+
readonly components: readonly [{
|
|
354
|
+
readonly name: "value";
|
|
355
|
+
readonly type: "uint256";
|
|
356
|
+
readonly internalType: "uint256";
|
|
357
|
+
}, {
|
|
358
|
+
readonly name: "deadline";
|
|
359
|
+
readonly type: "uint256";
|
|
360
|
+
readonly internalType: "uint256";
|
|
361
|
+
}, {
|
|
362
|
+
readonly name: "r";
|
|
363
|
+
readonly type: "bytes32";
|
|
364
|
+
readonly internalType: "bytes32";
|
|
365
|
+
}, {
|
|
366
|
+
readonly name: "s";
|
|
367
|
+
readonly type: "bytes32";
|
|
368
|
+
readonly internalType: "bytes32";
|
|
369
|
+
}, {
|
|
370
|
+
readonly name: "v";
|
|
371
|
+
readonly type: "uint8";
|
|
372
|
+
readonly internalType: "uint8";
|
|
373
|
+
}];
|
|
374
|
+
}, {
|
|
375
|
+
readonly name: "permit";
|
|
376
|
+
readonly type: "tuple";
|
|
377
|
+
readonly internalType: "struct ISignatureTransfer.PermitTransferFrom";
|
|
378
|
+
readonly components: readonly [{
|
|
379
|
+
readonly name: "permitted";
|
|
380
|
+
readonly type: "tuple";
|
|
381
|
+
readonly internalType: "struct ISignatureTransfer.TokenPermissions";
|
|
382
|
+
readonly components: readonly [{
|
|
383
|
+
readonly name: "token";
|
|
384
|
+
readonly type: "address";
|
|
385
|
+
readonly internalType: "address";
|
|
386
|
+
}, {
|
|
387
|
+
readonly name: "amount";
|
|
388
|
+
readonly type: "uint256";
|
|
389
|
+
readonly internalType: "uint256";
|
|
390
|
+
}];
|
|
391
|
+
}, {
|
|
392
|
+
readonly name: "nonce";
|
|
393
|
+
readonly type: "uint256";
|
|
394
|
+
readonly internalType: "uint256";
|
|
395
|
+
}, {
|
|
396
|
+
readonly name: "deadline";
|
|
397
|
+
readonly type: "uint256";
|
|
398
|
+
readonly internalType: "uint256";
|
|
399
|
+
}];
|
|
400
|
+
}, {
|
|
401
|
+
readonly name: "owner";
|
|
402
|
+
readonly type: "address";
|
|
403
|
+
readonly internalType: "address";
|
|
404
|
+
}, {
|
|
405
|
+
readonly name: "witness";
|
|
406
|
+
readonly type: "tuple";
|
|
407
|
+
readonly internalType: "struct x402ExactPermit2Proxy.Witness";
|
|
408
|
+
readonly components: readonly [{
|
|
409
|
+
readonly name: "to";
|
|
410
|
+
readonly type: "address";
|
|
411
|
+
readonly internalType: "address";
|
|
412
|
+
}, {
|
|
413
|
+
readonly name: "validAfter";
|
|
414
|
+
readonly type: "uint256";
|
|
415
|
+
readonly internalType: "uint256";
|
|
416
|
+
}];
|
|
417
|
+
}, {
|
|
418
|
+
readonly name: "signature";
|
|
419
|
+
readonly type: "bytes";
|
|
420
|
+
readonly internalType: "bytes";
|
|
421
|
+
}];
|
|
422
|
+
readonly outputs: readonly [];
|
|
423
|
+
readonly stateMutability: "nonpayable";
|
|
424
|
+
}, {
|
|
425
|
+
readonly type: "event";
|
|
426
|
+
readonly name: "Settled";
|
|
427
|
+
readonly inputs: readonly [];
|
|
428
|
+
readonly anonymous: false;
|
|
429
|
+
}, {
|
|
430
|
+
readonly type: "event";
|
|
431
|
+
readonly name: "SettledWithPermit";
|
|
432
|
+
readonly inputs: readonly [];
|
|
433
|
+
readonly anonymous: false;
|
|
434
|
+
}, {
|
|
435
|
+
readonly type: "error";
|
|
436
|
+
readonly name: "InvalidAmount";
|
|
437
|
+
readonly inputs: readonly [];
|
|
438
|
+
}, {
|
|
439
|
+
readonly type: "error";
|
|
440
|
+
readonly name: "InvalidDestination";
|
|
441
|
+
readonly inputs: readonly [];
|
|
442
|
+
}, {
|
|
443
|
+
readonly type: "error";
|
|
444
|
+
readonly name: "InvalidOwner";
|
|
445
|
+
readonly inputs: readonly [];
|
|
446
|
+
}, {
|
|
447
|
+
readonly type: "error";
|
|
448
|
+
readonly name: "InvalidPermit2Address";
|
|
449
|
+
readonly inputs: readonly [];
|
|
450
|
+
}, {
|
|
451
|
+
readonly type: "error";
|
|
452
|
+
readonly name: "PaymentTooEarly";
|
|
453
|
+
readonly inputs: readonly [];
|
|
454
|
+
}, {
|
|
455
|
+
readonly type: "error";
|
|
456
|
+
readonly name: "Permit2612AmountMismatch";
|
|
457
|
+
readonly inputs: readonly [];
|
|
458
|
+
}, {
|
|
459
|
+
readonly type: "error";
|
|
460
|
+
readonly name: "ReentrancyGuardReentrantCall";
|
|
461
|
+
readonly inputs: readonly [];
|
|
462
|
+
}];
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Creates transaction data to approve Permit2 to spend tokens.
|
|
466
|
+
* The user sends this transaction (paying gas) before using Permit2 flow.
|
|
467
|
+
*
|
|
468
|
+
* @param tokenAddress - The ERC20 token contract address
|
|
469
|
+
* @returns Transaction data to send for approval
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```typescript
|
|
473
|
+
* const tx = createPermit2ApprovalTx("0x...");
|
|
474
|
+
* await walletClient.sendTransaction({
|
|
475
|
+
* to: tx.to,
|
|
476
|
+
* data: tx.data,
|
|
477
|
+
* });
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
declare function createPermit2ApprovalTx(tokenAddress: `0x${string}`): {
|
|
481
|
+
to: `0x${string}`;
|
|
482
|
+
data: `0x${string}`;
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* Parameters for checking Permit2 allowance.
|
|
486
|
+
* Application provides these to check if approval is needed.
|
|
487
|
+
*/
|
|
488
|
+
interface Permit2AllowanceParams {
|
|
489
|
+
tokenAddress: `0x${string}`;
|
|
490
|
+
ownerAddress: `0x${string}`;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Returns contract read parameters for checking Permit2 allowance.
|
|
494
|
+
* Use with a public client to check if the user has approved Permit2.
|
|
495
|
+
*
|
|
496
|
+
* @param params - The allowance check parameters
|
|
497
|
+
* @returns Contract read parameters for checking allowance
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```typescript
|
|
501
|
+
* const readParams = getPermit2AllowanceReadParams({
|
|
502
|
+
* tokenAddress: "0x...",
|
|
503
|
+
* ownerAddress: "0x...",
|
|
504
|
+
* });
|
|
505
|
+
*
|
|
506
|
+
* const allowance = await publicClient.readContract(readParams);
|
|
507
|
+
* const needsApproval = allowance < requiredAmount;
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
declare function getPermit2AllowanceReadParams(params: Permit2AllowanceParams): {
|
|
511
|
+
address: `0x${string}`;
|
|
512
|
+
abi: typeof erc20AllowanceAbi;
|
|
513
|
+
functionName: "allowance";
|
|
514
|
+
args: [`0x${string}`, `0x${string}`];
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
export { ExactEvmScheme as E, PERMIT2_ADDRESS as P, type Permit2AllowanceParams as a, authorizationTypes as b, createPermit2ApprovalTx as c, erc20AllowanceAbi as d, eip3009ABI as e, x402ExactPermit2ProxyAddress as f, getPermit2AllowanceReadParams as g, x402UptoPermit2ProxyAddress as h, permit2WitnessTypes as p, x402ExactPermit2ProxyABI as x };
|
|
@@ -26,6 +26,34 @@ type ClientEvmSigner = {
|
|
|
26
26
|
functionName: string;
|
|
27
27
|
args?: readonly unknown[];
|
|
28
28
|
}): Promise<unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Optional: Signs a raw EIP-1559 transaction without broadcasting.
|
|
31
|
+
* Required for ERC-20 approval gas sponsoring when the token lacks EIP-2612.
|
|
32
|
+
*/
|
|
33
|
+
signTransaction?(args: {
|
|
34
|
+
to: `0x${string}`;
|
|
35
|
+
data: `0x${string}`;
|
|
36
|
+
nonce: number;
|
|
37
|
+
gas: bigint;
|
|
38
|
+
maxFeePerGas: bigint;
|
|
39
|
+
maxPriorityFeePerGas: bigint;
|
|
40
|
+
chainId: number;
|
|
41
|
+
}): Promise<`0x${string}`>;
|
|
42
|
+
/**
|
|
43
|
+
* Optional: Gets the current transaction count (nonce) for an address.
|
|
44
|
+
* Required for ERC-20 approval gas sponsoring.
|
|
45
|
+
*/
|
|
46
|
+
getTransactionCount?(args: {
|
|
47
|
+
address: `0x${string}`;
|
|
48
|
+
}): Promise<number>;
|
|
49
|
+
/**
|
|
50
|
+
* Optional: Estimates current gas fees per gas.
|
|
51
|
+
* Required for ERC-20 approval gas sponsoring.
|
|
52
|
+
*/
|
|
53
|
+
estimateFeesPerGas?(): Promise<{
|
|
54
|
+
maxFeePerGas: bigint;
|
|
55
|
+
maxPriorityFeePerGas: bigint;
|
|
56
|
+
}>;
|
|
29
57
|
};
|
|
30
58
|
/**
|
|
31
59
|
* FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments
|
|
@@ -91,6 +119,8 @@ type FacilitatorEvmSigner = {
|
|
|
91
119
|
* @param signer - A signer with `address` and `signTypedData` (and optionally `readContract`)
|
|
92
120
|
* @param publicClient - A client with `readContract` (required if signer lacks it)
|
|
93
121
|
* @param publicClient.readContract - The readContract method from the public client
|
|
122
|
+
* @param publicClient.getTransactionCount - Optional getTransactionCount for ERC-20 approval
|
|
123
|
+
* @param publicClient.estimateFeesPerGas - Optional estimateFeesPerGas for ERC-20 approval
|
|
94
124
|
* @returns A complete ClientEvmSigner
|
|
95
125
|
*
|
|
96
126
|
* @example
|
|
@@ -109,6 +139,13 @@ declare function toClientEvmSigner(signer: Omit<ClientEvmSigner, "readContract">
|
|
|
109
139
|
functionName: string;
|
|
110
140
|
args?: readonly unknown[];
|
|
111
141
|
}): Promise<unknown>;
|
|
142
|
+
getTransactionCount?(args: {
|
|
143
|
+
address: `0x${string}`;
|
|
144
|
+
}): Promise<number>;
|
|
145
|
+
estimateFeesPerGas?(): Promise<{
|
|
146
|
+
maxFeePerGas: bigint;
|
|
147
|
+
maxPriorityFeePerGas: bigint;
|
|
148
|
+
}>;
|
|
112
149
|
}): ClientEvmSigner;
|
|
113
150
|
/**
|
|
114
151
|
* Converts a viem client with single address to a FacilitatorEvmSigner
|
package/dist/cjs/v1/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { ExactEvmSchemeV1 } from '../exact/v1/client/index.js';
|
|
2
2
|
import '@x402/core/types';
|
|
3
|
-
import '../signer-
|
|
3
|
+
import '../signer-DC81R8wQ.js';
|
|
4
4
|
|
|
5
5
|
declare const EVM_NETWORK_CHAIN_ID_MAP: {
|
|
6
6
|
readonly ethereum: 1;
|
|
@@ -21,8 +21,17 @@ declare const EVM_NETWORK_CHAIN_ID_MAP: {
|
|
|
21
21
|
readonly educhain: 41923;
|
|
22
22
|
readonly "skale-base-sepolia": 324705682;
|
|
23
23
|
readonly megaeth: 4326;
|
|
24
|
+
readonly monad: 143;
|
|
24
25
|
};
|
|
25
26
|
type EvmNetworkV1 = keyof typeof EVM_NETWORK_CHAIN_ID_MAP;
|
|
26
27
|
declare const NETWORKS: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Extract chain ID from a v1 legacy network name.
|
|
30
|
+
*
|
|
31
|
+
* @param network - The v1 network name (e.g., "base-sepolia", "polygon")
|
|
32
|
+
* @returns The numeric chain ID
|
|
33
|
+
* @throws Error if the network name is not a known v1 network
|
|
34
|
+
*/
|
|
35
|
+
declare function getEvmChainIdV1(network: string): number;
|
|
27
36
|
|
|
28
|
-
export { EVM_NETWORK_CHAIN_ID_MAP, type EvmNetworkV1, NETWORKS };
|
|
37
|
+
export { EVM_NETWORK_CHAIN_ID_MAP, type EvmNetworkV1, NETWORKS, getEvmChainIdV1 };
|
package/dist/cjs/v1/index.js
CHANGED
|
@@ -22,7 +22,8 @@ var v1_exports = {};
|
|
|
22
22
|
__export(v1_exports, {
|
|
23
23
|
EVM_NETWORK_CHAIN_ID_MAP: () => EVM_NETWORK_CHAIN_ID_MAP,
|
|
24
24
|
ExactEvmSchemeV1: () => ExactEvmSchemeV1,
|
|
25
|
-
NETWORKS: () => NETWORKS
|
|
25
|
+
NETWORKS: () => NETWORKS,
|
|
26
|
+
getEvmChainIdV1: () => getEvmChainIdV1
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(v1_exports);
|
|
28
29
|
|
|
@@ -43,13 +44,6 @@ var authorizationTypes = {
|
|
|
43
44
|
|
|
44
45
|
// src/utils.ts
|
|
45
46
|
var import_viem = require("viem");
|
|
46
|
-
function getEvmChainId(network) {
|
|
47
|
-
const chainId = EVM_NETWORK_CHAIN_ID_MAP[network];
|
|
48
|
-
if (!chainId) {
|
|
49
|
-
throw new Error(`Unsupported network: ${network}`);
|
|
50
|
-
}
|
|
51
|
-
return chainId;
|
|
52
|
-
}
|
|
53
47
|
function getCrypto() {
|
|
54
48
|
const cryptoObj = globalThis.crypto;
|
|
55
49
|
if (!cryptoObj) {
|
|
@@ -112,7 +106,7 @@ var ExactEvmSchemeV1 = class {
|
|
|
112
106
|
* @returns Promise resolving to the signature
|
|
113
107
|
*/
|
|
114
108
|
async signAuthorization(authorization, requirements) {
|
|
115
|
-
const chainId =
|
|
109
|
+
const chainId = getEvmChainIdV1(requirements.network);
|
|
116
110
|
if (!requirements.extra?.name || !requirements.extra?.version) {
|
|
117
111
|
throw new Error(
|
|
118
112
|
`EIP-712 domain parameters (name, version) are required in payment requirements for asset ${requirements.asset}`
|
|
@@ -164,13 +158,22 @@ var EVM_NETWORK_CHAIN_ID_MAP = {
|
|
|
164
158
|
story: 1514,
|
|
165
159
|
educhain: 41923,
|
|
166
160
|
"skale-base-sepolia": 324705682,
|
|
167
|
-
megaeth: 4326
|
|
161
|
+
megaeth: 4326,
|
|
162
|
+
monad: 143
|
|
168
163
|
};
|
|
169
164
|
var NETWORKS = Object.keys(EVM_NETWORK_CHAIN_ID_MAP);
|
|
165
|
+
function getEvmChainIdV1(network) {
|
|
166
|
+
const chainId = EVM_NETWORK_CHAIN_ID_MAP[network];
|
|
167
|
+
if (!chainId) {
|
|
168
|
+
throw new Error(`Unsupported v1 network: ${network}`);
|
|
169
|
+
}
|
|
170
|
+
return chainId;
|
|
171
|
+
}
|
|
170
172
|
// Annotate the CommonJS export names for ESM import in node:
|
|
171
173
|
0 && (module.exports = {
|
|
172
174
|
EVM_NETWORK_CHAIN_ID_MAP,
|
|
173
175
|
ExactEvmSchemeV1,
|
|
174
|
-
NETWORKS
|
|
176
|
+
NETWORKS,
|
|
177
|
+
getEvmChainIdV1
|
|
175
178
|
});
|
|
176
179
|
//# sourceMappingURL=index.js.map
|