@payai/x402-evm 2.3.1 → 2.3.2

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.
@@ -0,0 +1,103 @@
1
+ import { SchemeNetworkClient, PaymentRequirements, PaymentPayloadResult } from '@x402/core/types';
2
+ import { C as ClientEvmSigner } from './signer-5OVDxViv.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
+ 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 };
@@ -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 };
@@ -0,0 +1,79 @@
1
+ /**
2
+ * ClientEvmSigner - Used by x402 clients to sign payment authorizations
3
+ * This is typically a LocalAccount or wallet that holds private keys
4
+ * and can sign EIP-712 typed data for payment authorizations
5
+ */
6
+ type ClientEvmSigner = {
7
+ readonly address: `0x${string}`;
8
+ signTypedData(message: {
9
+ domain: Record<string, unknown>;
10
+ types: Record<string, unknown>;
11
+ primaryType: string;
12
+ message: Record<string, unknown>;
13
+ }): Promise<`0x${string}`>;
14
+ };
15
+ /**
16
+ * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments
17
+ * This is typically a viem PublicClient + WalletClient combination that can
18
+ * read contract state, verify signatures, write transactions, and wait for receipts
19
+ *
20
+ * Supports multiple addresses for load balancing, key rotation, and high availability
21
+ */
22
+ type FacilitatorEvmSigner = {
23
+ /**
24
+ * Get all addresses this facilitator can use for signing
25
+ * Enables dynamic address selection for load balancing and key rotation
26
+ */
27
+ getAddresses(): readonly `0x${string}`[];
28
+ readContract(args: {
29
+ address: `0x${string}`;
30
+ abi: readonly unknown[];
31
+ functionName: string;
32
+ args?: readonly unknown[];
33
+ }): Promise<unknown>;
34
+ verifyTypedData(args: {
35
+ address: `0x${string}`;
36
+ domain: Record<string, unknown>;
37
+ types: Record<string, unknown>;
38
+ primaryType: string;
39
+ message: Record<string, unknown>;
40
+ signature: `0x${string}`;
41
+ }): Promise<boolean>;
42
+ writeContract(args: {
43
+ address: `0x${string}`;
44
+ abi: readonly unknown[];
45
+ functionName: string;
46
+ args: readonly unknown[];
47
+ }): Promise<`0x${string}`>;
48
+ sendTransaction(args: {
49
+ to: `0x${string}`;
50
+ data: `0x${string}`;
51
+ }): Promise<`0x${string}`>;
52
+ waitForTransactionReceipt(args: {
53
+ hash: `0x${string}`;
54
+ }): Promise<{
55
+ status: string;
56
+ }>;
57
+ getCode(args: {
58
+ address: `0x${string}`;
59
+ }): Promise<`0x${string}` | undefined>;
60
+ };
61
+ /**
62
+ * Converts a signer to a ClientEvmSigner
63
+ *
64
+ * @param signer - The signer to convert to a ClientEvmSigner
65
+ * @returns The converted signer
66
+ */
67
+ declare function toClientEvmSigner(signer: ClientEvmSigner): ClientEvmSigner;
68
+ /**
69
+ * Converts a viem client with single address to a FacilitatorEvmSigner
70
+ * Wraps the single address in a getAddresses() function for compatibility
71
+ *
72
+ * @param client - The client to convert (must have 'address' property)
73
+ * @returns FacilitatorEvmSigner with getAddresses() support
74
+ */
75
+ declare function toFacilitatorEvmSigner(client: Omit<FacilitatorEvmSigner, "getAddresses"> & {
76
+ address: `0x${string}`;
77
+ }): FacilitatorEvmSigner;
78
+
79
+ export { type ClientEvmSigner as C, type FacilitatorEvmSigner as F, toFacilitatorEvmSigner as a, toClientEvmSigner as t };
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@payai/x402-evm",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/cjs/index.d.ts",
7
+ "scripts": {
8
+ "build": "node ./scripts/build.js"
9
+ },
7
10
  "keywords": [
8
11
  "x402",
9
12
  "payment",
@@ -100,8 +103,5 @@
100
103
  ],
101
104
  "publishConfig": {
102
105
  "access": "public"
103
- },
104
- "scripts": {
105
- "build": "node ./scripts/build.js"
106
106
  }
107
- }
107
+ }