@x402/evm 2.3.1 → 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.
Files changed (51) hide show
  1. package/dist/cjs/exact/client/index.d.ts +2 -2
  2. package/dist/cjs/exact/client/index.js +412 -169
  3. package/dist/cjs/exact/client/index.js.map +1 -1
  4. package/dist/cjs/exact/facilitator/index.d.ts +18 -18
  5. package/dist/cjs/exact/facilitator/index.js +467 -157
  6. package/dist/cjs/exact/facilitator/index.js.map +1 -1
  7. package/dist/cjs/exact/v1/client/index.d.ts +1 -1
  8. package/dist/cjs/exact/v1/client/index.js +17 -18
  9. package/dist/cjs/exact/v1/client/index.js.map +1 -1
  10. package/dist/cjs/exact/v1/facilitator/index.d.ts +1 -1
  11. package/dist/cjs/exact/v1/facilitator/index.js +7 -8
  12. package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
  13. package/dist/cjs/index.d.ts +3 -390
  14. package/dist/cjs/index.js +363 -110
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/permit2-CQbXqCMC.d.ts +517 -0
  17. package/dist/cjs/signer-DC81R8wQ.d.ts +161 -0
  18. package/dist/cjs/v1/index.d.ts +11 -2
  19. package/dist/cjs/v1/index.js +14 -11
  20. package/dist/cjs/v1/index.js.map +1 -1
  21. package/dist/esm/{chunk-RPL6OFJL.mjs → chunk-7KHQD5KT.mjs} +92 -37
  22. package/dist/esm/chunk-7KHQD5KT.mjs.map +1 -0
  23. package/dist/esm/chunk-GY6X5A3G.mjs +425 -0
  24. package/dist/esm/chunk-GY6X5A3G.mjs.map +1 -0
  25. package/dist/esm/{chunk-PFULIQAE.mjs → chunk-TKN5V2BV.mjs} +1 -1
  26. package/dist/esm/chunk-TKN5V2BV.mjs.map +1 -0
  27. package/dist/esm/exact/client/index.d.mts +2 -2
  28. package/dist/esm/exact/client/index.mjs +4 -3
  29. package/dist/esm/exact/facilitator/index.d.mts +18 -18
  30. package/dist/esm/exact/facilitator/index.mjs +401 -99
  31. package/dist/esm/exact/facilitator/index.mjs.map +1 -1
  32. package/dist/esm/exact/v1/client/index.d.mts +1 -1
  33. package/dist/esm/exact/v1/client/index.mjs +2 -2
  34. package/dist/esm/exact/v1/facilitator/index.d.mts +1 -1
  35. package/dist/esm/exact/v1/facilitator/index.mjs +2 -2
  36. package/dist/esm/index.d.mts +3 -390
  37. package/dist/esm/index.mjs +29 -6
  38. package/dist/esm/index.mjs.map +1 -1
  39. package/dist/esm/permit2-CGOcN7Et.d.mts +517 -0
  40. package/dist/esm/signer-DC81R8wQ.d.mts +161 -0
  41. package/dist/esm/v1/index.d.mts +11 -2
  42. package/dist/esm/v1/index.mjs +6 -4
  43. package/package.json +3 -2
  44. package/dist/cjs/permit2-BYv82va2.d.ts +0 -103
  45. package/dist/cjs/signer-5OVDxViv.d.ts +0 -79
  46. package/dist/esm/chunk-E2YMUI3X.mjs +0 -229
  47. package/dist/esm/chunk-E2YMUI3X.mjs.map +0 -1
  48. package/dist/esm/chunk-PFULIQAE.mjs.map +0 -1
  49. package/dist/esm/chunk-RPL6OFJL.mjs.map +0 -1
  50. package/dist/esm/permit2-BsAoJiWD.d.mts +0 -103
  51. package/dist/esm/signer-5OVDxViv.d.mts +0 -79
@@ -1,5 +1,5 @@
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';
1
+ export { E as ExactEvmScheme, P as PERMIT2_ADDRESS, a as Permit2AllowanceParams, b as authorizationTypes, c as createPermit2ApprovalTx, e as eip3009ABI, d as erc20AllowanceAbi, g as getPermit2AllowanceReadParams, p as permit2WitnessTypes, x as x402ExactPermit2ProxyABI, f as x402ExactPermit2ProxyAddress, h as x402UptoPermit2ProxyAddress } from './permit2-CGOcN7Et.mjs';
2
+ export { C as ClientEvmSigner, F as FacilitatorEvmSigner, t as toClientEvmSigner, a as toFacilitatorEvmSigner } from './signer-DC81R8wQ.mjs';
3
3
  import '@x402/core/types';
4
4
 
5
5
  /**
@@ -30,7 +30,6 @@ type ExactEIP3009Payload = {
30
30
  type Permit2Witness = {
31
31
  to: `0x${string}`;
32
32
  validAfter: string;
33
- extra: `0x${string}`;
34
33
  };
35
34
  /**
36
35
  * Permit2 authorization parameters.
@@ -74,390 +73,4 @@ declare function isPermit2Payload(payload: ExactEvmPayloadV2): payload is ExactP
74
73
  */
75
74
  declare function isEIP3009Payload(payload: ExactEvmPayloadV2): payload is ExactEIP3009Payload;
76
75
 
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.
247
- */
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
- }];
462
-
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 };
76
+ export { type AssetTransferMethod, type ExactEIP3009Payload, type ExactEvmPayloadV1, type ExactEvmPayloadV2, type ExactPermit2Payload, type Permit2Authorization, type Permit2Witness, isEIP3009Payload, isPermit2Payload };
@@ -1,26 +1,49 @@
1
1
  import {
2
2
  ExactEvmScheme,
3
3
  createPermit2ApprovalTx,
4
- erc20AllowanceAbi,
5
4
  getPermit2AllowanceReadParams
6
- } from "./chunk-E2YMUI3X.mjs";
5
+ } from "./chunk-GY6X5A3G.mjs";
7
6
  import {
8
7
  isEIP3009Payload,
9
8
  isPermit2Payload
10
- } from "./chunk-PFULIQAE.mjs";
9
+ } from "./chunk-TKN5V2BV.mjs";
11
10
  import {
12
11
  PERMIT2_ADDRESS,
13
12
  authorizationTypes,
14
13
  eip3009ABI,
14
+ erc20AllowanceAbi,
15
15
  permit2WitnessTypes,
16
16
  x402ExactPermit2ProxyABI,
17
17
  x402ExactPermit2ProxyAddress,
18
18
  x402UptoPermit2ProxyAddress
19
- } from "./chunk-RPL6OFJL.mjs";
19
+ } from "./chunk-7KHQD5KT.mjs";
20
20
 
21
21
  // src/signer.ts
22
- function toClientEvmSigner(signer) {
23
- return signer;
22
+ function toClientEvmSigner(signer, publicClient) {
23
+ const readContract = signer.readContract ?? publicClient?.readContract.bind(publicClient);
24
+ if (!readContract) {
25
+ throw new Error(
26
+ "toClientEvmSigner requires either a signer with readContract or a publicClient. Use createWalletClient(...).extend(publicActions) or pass a publicClient."
27
+ );
28
+ }
29
+ const result = {
30
+ address: signer.address,
31
+ signTypedData: (msg) => signer.signTypedData(msg),
32
+ readContract
33
+ };
34
+ const signTransaction = signer.signTransaction;
35
+ if (signTransaction) {
36
+ result.signTransaction = (args) => signTransaction(args);
37
+ }
38
+ const getTransactionCount = signer.getTransactionCount ?? publicClient?.getTransactionCount?.bind(publicClient);
39
+ if (getTransactionCount) {
40
+ result.getTransactionCount = (args) => getTransactionCount(args);
41
+ }
42
+ const estimateFeesPerGas = signer.estimateFeesPerGas ?? publicClient?.estimateFeesPerGas?.bind(publicClient);
43
+ if (estimateFeesPerGas) {
44
+ result.estimateFeesPerGas = () => estimateFeesPerGas();
45
+ }
46
+ return result;
24
47
  }
25
48
  function toFacilitatorEvmSigner(client) {
26
49
  return {
@@ -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":";;;;;;;;;;;;;;;;;;;;;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":[]}
1
+ {"version":3,"sources":["../../src/signer.ts"],"sourcesContent":["/**\n * ClientEvmSigner - Used by x402 clients to sign payment authorizations.\n *\n * Typically a viem WalletClient extended with publicActions:\n * ```typescript\n * const client = createWalletClient({\n * account: privateKeyToAccount('0x...'),\n * chain: baseSepolia,\n * transport: http(),\n * }).extend(publicActions);\n * ```\n *\n * Or composed via `toClientEvmSigner(account, publicClient)`.\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 readContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args?: readonly unknown[];\n }): Promise<unknown>;\n /**\n * Optional: Signs a raw EIP-1559 transaction without broadcasting.\n * Required for ERC-20 approval gas sponsoring when the token lacks EIP-2612.\n */\n signTransaction?(args: {\n to: `0x${string}`;\n data: `0x${string}`;\n nonce: number;\n gas: bigint;\n maxFeePerGas: bigint;\n maxPriorityFeePerGas: bigint;\n chainId: number;\n }): Promise<`0x${string}`>;\n /**\n * Optional: Gets the current transaction count (nonce) for an address.\n * Required for ERC-20 approval gas sponsoring.\n */\n getTransactionCount?(args: { address: `0x${string}` }): Promise<number>;\n /**\n * Optional: Estimates current gas fees per gas.\n * Required for ERC-20 approval gas sponsoring.\n */\n estimateFeesPerGas?(): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }>;\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 * Composes a ClientEvmSigner from a local account and a public client.\n *\n * Use this when your signer (e.g., `privateKeyToAccount`) doesn't have\n * `readContract`. The `publicClient` provides the on-chain read capability.\n *\n * Alternatively, use a WalletClient extended with publicActions directly:\n * ```typescript\n * const signer = createWalletClient({\n * account: privateKeyToAccount('0x...'),\n * chain: baseSepolia,\n * transport: http(),\n * }).extend(publicActions);\n * ```\n *\n * @param signer - A signer with `address` and `signTypedData` (and optionally `readContract`)\n * @param publicClient - A client with `readContract` (required if signer lacks it)\n * @param publicClient.readContract - The readContract method from the public client\n * @param publicClient.getTransactionCount - Optional getTransactionCount for ERC-20 approval\n * @param publicClient.estimateFeesPerGas - Optional estimateFeesPerGas for ERC-20 approval\n * @returns A complete ClientEvmSigner\n *\n * @example\n * ```typescript\n * const account = privateKeyToAccount(\"0x...\");\n * const publicClient = createPublicClient({ chain: baseSepolia, transport: http() });\n * const signer = toClientEvmSigner(account, publicClient);\n * ```\n */\nexport function toClientEvmSigner(\n signer: Omit<ClientEvmSigner, \"readContract\"> & {\n readContract?: ClientEvmSigner[\"readContract\"];\n },\n publicClient?: {\n readContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args?: readonly unknown[];\n }): Promise<unknown>;\n getTransactionCount?(args: { address: `0x${string}` }): Promise<number>;\n estimateFeesPerGas?(): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }>;\n },\n): ClientEvmSigner {\n const readContract = signer.readContract ?? publicClient?.readContract.bind(publicClient);\n\n if (!readContract) {\n throw new Error(\n \"toClientEvmSigner requires either a signer with readContract or a publicClient. \" +\n \"Use createWalletClient(...).extend(publicActions) or pass a publicClient.\",\n );\n }\n\n const result: ClientEvmSigner = {\n address: signer.address,\n signTypedData: msg => signer.signTypedData(msg),\n readContract,\n };\n\n // Forward optional capabilities from signer or publicClient\n const signTransaction = signer.signTransaction;\n if (signTransaction) {\n result.signTransaction = args => signTransaction(args);\n }\n\n const getTransactionCount =\n signer.getTransactionCount ?? publicClient?.getTransactionCount?.bind(publicClient);\n if (getTransactionCount) {\n result.getTransactionCount = args => getTransactionCount(args);\n }\n\n const estimateFeesPerGas =\n signer.estimateFeesPerGas ?? publicClient?.estimateFeesPerGas?.bind(publicClient);\n if (estimateFeesPerGas) {\n result.estimateFeesPerGas = () => estimateFeesPerGas();\n }\n\n return result;\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":";;;;;;;;;;;;;;;;;;;;;AAyHO,SAAS,kBACd,QAGA,cAUiB;AACjB,QAAM,eAAe,OAAO,gBAAgB,cAAc,aAAa,KAAK,YAAY;AAExF,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,QAAM,SAA0B;AAAA,IAC9B,SAAS,OAAO;AAAA,IAChB,eAAe,SAAO,OAAO,cAAc,GAAG;AAAA,IAC9C;AAAA,EACF;AAGA,QAAM,kBAAkB,OAAO;AAC/B,MAAI,iBAAiB;AACnB,WAAO,kBAAkB,UAAQ,gBAAgB,IAAI;AAAA,EACvD;AAEA,QAAM,sBACJ,OAAO,uBAAuB,cAAc,qBAAqB,KAAK,YAAY;AACpF,MAAI,qBAAqB;AACvB,WAAO,sBAAsB,UAAQ,oBAAoB,IAAI;AAAA,EAC/D;AAEA,QAAM,qBACJ,OAAO,sBAAsB,cAAc,oBAAoB,KAAK,YAAY;AAClF,MAAI,oBAAoB;AACtB,WAAO,qBAAqB,MAAM,mBAAmB;AAAA,EACvD;AAEA,SAAO;AACT;AASO,SAAS,uBACd,QACsB;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,cAAc,MAAM,CAAC,OAAO,OAAO;AAAA,EACrC;AACF;","names":[]}