@payai/x402-evm 2.3.5 → 2.4.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 +3 -2
- package/dist/cjs/exact/client/index.js +175 -194
- package/dist/cjs/exact/client/index.js.map +1 -1
- package/dist/cjs/exact/facilitator/index.js +201 -185
- package/dist/cjs/exact/facilitator/index.js.map +1 -1
- package/dist/cjs/exact/server/index.d.ts +18 -17
- package/dist/cjs/exact/server/index.js +100 -55
- package/dist/cjs/exact/server/index.js.map +1 -1
- package/dist/cjs/exact/v1/client/index.js +5 -1
- package/dist/cjs/exact/v1/client/index.js.map +1 -1
- package/dist/cjs/exact/v1/facilitator/index.js +5 -1
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -1
- package/dist/cjs/index.d.ts +38 -2
- package/dist/cjs/index.js +443 -191
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/{permit2-U9Zolx3O.d.ts → permit2-CyZxwngN.d.ts} +278 -87
- package/dist/cjs/scheme-CXDF0D2A.d.ts +47 -0
- package/dist/cjs/upto/client/index.d.ts +32 -0
- package/dist/cjs/upto/client/index.js +507 -0
- package/dist/cjs/upto/client/index.js.map +1 -0
- package/dist/cjs/upto/facilitator/index.d.ts +52 -0
- package/dist/cjs/upto/facilitator/index.js +1233 -0
- package/dist/cjs/upto/facilitator/index.js.map +1 -0
- package/dist/cjs/upto/server/index.d.ts +77 -0
- package/dist/cjs/upto/server/index.js +246 -0
- package/dist/cjs/upto/server/index.js.map +1 -0
- package/dist/cjs/v1/index.d.ts +4 -0
- package/dist/cjs/v1/index.js +5 -1
- package/dist/cjs/v1/index.js.map +1 -1
- package/dist/esm/chunk-C4ZQMS77.mjs +629 -0
- package/dist/esm/chunk-C4ZQMS77.mjs.map +1 -0
- package/dist/esm/chunk-CRT6YNY5.mjs +529 -0
- package/dist/esm/chunk-CRT6YNY5.mjs.map +1 -0
- package/dist/esm/chunk-D6RXZXOS.mjs +158 -0
- package/dist/esm/chunk-D6RXZXOS.mjs.map +1 -0
- package/dist/esm/chunk-GJ57SZGI.mjs +121 -0
- package/dist/esm/chunk-GJ57SZGI.mjs.map +1 -0
- package/dist/esm/chunk-JII456TS.mjs +34 -0
- package/dist/esm/chunk-JII456TS.mjs.map +1 -0
- package/dist/esm/chunk-NSFLAANF.mjs +80 -0
- package/dist/esm/chunk-NSFLAANF.mjs.map +1 -0
- package/dist/esm/{chunk-IZEI7JTG.mjs → chunk-RYT6M3PA.mjs} +31 -501
- package/dist/esm/chunk-RYT6M3PA.mjs.map +1 -0
- package/dist/esm/chunk-WKBC5YMI.mjs +291 -0
- package/dist/esm/chunk-WKBC5YMI.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +3 -2
- package/dist/esm/exact/client/index.mjs +8 -5
- package/dist/esm/exact/facilitator/index.mjs +84 -430
- package/dist/esm/exact/facilitator/index.mjs.map +1 -1
- package/dist/esm/exact/server/index.d.mts +18 -17
- package/dist/esm/exact/server/index.mjs +28 -55
- package/dist/esm/exact/server/index.mjs.map +1 -1
- package/dist/esm/exact/v1/client/index.mjs +2 -1
- package/dist/esm/exact/v1/facilitator/index.mjs +2 -1
- package/dist/esm/index.d.mts +38 -2
- package/dist/esm/index.mjs +21 -8
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/{permit2-Bbh3a8_h.d.mts → permit2-CyZxwngN.d.mts} +278 -87
- package/dist/esm/scheme-DCR7hsa3.d.mts +47 -0
- package/dist/esm/upto/client/index.d.mts +32 -0
- package/dist/esm/upto/client/index.mjs +18 -0
- package/dist/esm/upto/client/index.mjs.map +1 -0
- package/dist/esm/upto/facilitator/index.d.mts +52 -0
- package/dist/esm/upto/facilitator/index.mjs +473 -0
- package/dist/esm/upto/facilitator/index.mjs.map +1 -0
- package/dist/esm/upto/server/index.d.mts +77 -0
- package/dist/esm/upto/server/index.mjs +145 -0
- package/dist/esm/upto/server/index.mjs.map +1 -0
- package/dist/esm/v1/index.d.mts +4 -0
- package/dist/esm/v1/index.mjs +2 -1
- package/package.json +31 -1
- package/dist/esm/chunk-GD4MKCN7.mjs +0 -57
- package/dist/esm/chunk-GD4MKCN7.mjs.map +0 -1
- package/dist/esm/chunk-IZEI7JTG.mjs.map +0 -1
- package/dist/esm/chunk-TKN5V2BV.mjs +0 -13
- package/dist/esm/chunk-TKN5V2BV.mjs.map +0 -1
- package/dist/esm/chunk-WJWNS4G4.mjs +0 -518
- package/dist/esm/chunk-WJWNS4G4.mjs.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
ExactEvmScheme: () => ExactEvmScheme,
|
|
24
24
|
PERMIT2_ADDRESS: () => PERMIT2_ADDRESS,
|
|
25
|
+
UptoEvmScheme: () => UptoEvmScheme,
|
|
25
26
|
authorizationTypes: () => authorizationTypes,
|
|
26
27
|
createPermit2ApprovalTx: () => createPermit2ApprovalTx,
|
|
27
28
|
eip3009ABI: () => eip3009ABI,
|
|
@@ -29,15 +30,21 @@ __export(src_exports, {
|
|
|
29
30
|
getPermit2AllowanceReadParams: () => getPermit2AllowanceReadParams,
|
|
30
31
|
isEIP3009Payload: () => isEIP3009Payload,
|
|
31
32
|
isPermit2Payload: () => isPermit2Payload,
|
|
33
|
+
isUptoPermit2Payload: () => isUptoPermit2Payload,
|
|
32
34
|
permit2WitnessTypes: () => permit2WitnessTypes,
|
|
33
35
|
toClientEvmSigner: () => toClientEvmSigner,
|
|
34
36
|
toFacilitatorEvmSigner: () => toFacilitatorEvmSigner,
|
|
37
|
+
uptoPermit2WitnessTypes: () => uptoPermit2WitnessTypes,
|
|
35
38
|
x402ExactPermit2ProxyABI: () => x402ExactPermit2ProxyABI,
|
|
36
39
|
x402ExactPermit2ProxyAddress: () => x402ExactPermit2ProxyAddress,
|
|
40
|
+
x402UptoPermit2ProxyABI: () => x402UptoPermit2ProxyABI,
|
|
37
41
|
x402UptoPermit2ProxyAddress: () => x402UptoPermit2ProxyAddress
|
|
38
42
|
});
|
|
39
43
|
module.exports = __toCommonJS(src_exports);
|
|
40
44
|
|
|
45
|
+
// src/exact/client/eip3009.ts
|
|
46
|
+
var import_viem2 = require("viem");
|
|
47
|
+
|
|
41
48
|
// src/constants.ts
|
|
42
49
|
var authorizationTypes = {
|
|
43
50
|
TransferWithAuthorization: [
|
|
@@ -66,6 +73,24 @@ var permit2WitnessTypes = {
|
|
|
66
73
|
{ name: "validAfter", type: "uint256" }
|
|
67
74
|
]
|
|
68
75
|
};
|
|
76
|
+
var uptoPermit2WitnessTypes = {
|
|
77
|
+
PermitWitnessTransferFrom: [
|
|
78
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
79
|
+
{ name: "spender", type: "address" },
|
|
80
|
+
{ name: "nonce", type: "uint256" },
|
|
81
|
+
{ name: "deadline", type: "uint256" },
|
|
82
|
+
{ name: "witness", type: "Witness" }
|
|
83
|
+
],
|
|
84
|
+
TokenPermissions: [
|
|
85
|
+
{ name: "token", type: "address" },
|
|
86
|
+
{ name: "amount", type: "uint256" }
|
|
87
|
+
],
|
|
88
|
+
Witness: [
|
|
89
|
+
{ name: "to", type: "address" },
|
|
90
|
+
{ name: "facilitator", type: "address" },
|
|
91
|
+
{ name: "validAfter", type: "uint256" }
|
|
92
|
+
]
|
|
93
|
+
};
|
|
69
94
|
var eip3009ABI = [
|
|
70
95
|
{
|
|
71
96
|
inputs: [
|
|
@@ -178,11 +203,131 @@ var DEFAULT_MAX_FEE_PER_GAS = 1000000000n;
|
|
|
178
203
|
var DEFAULT_MAX_PRIORITY_FEE_PER_GAS = 100000000n;
|
|
179
204
|
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
180
205
|
var x402ExactPermit2ProxyAddress = "0x402085c248EeA27D92E8b30b2C58ed07f9E20001";
|
|
181
|
-
var x402UptoPermit2ProxyAddress = "
|
|
206
|
+
var x402UptoPermit2ProxyAddress = "0x4020A4f3b7b90ccA423B9fabCc0CE57C6C240002";
|
|
182
207
|
var permit2WitnessABIComponents = [
|
|
183
208
|
{ name: "to", type: "address", internalType: "address" },
|
|
184
209
|
{ name: "validAfter", type: "uint256", internalType: "uint256" }
|
|
185
210
|
];
|
|
211
|
+
var uptoPermit2WitnessABIComponents = [
|
|
212
|
+
{ name: "to", type: "address", internalType: "address" },
|
|
213
|
+
{ name: "facilitator", type: "address", internalType: "address" },
|
|
214
|
+
{ name: "validAfter", type: "uint256", internalType: "uint256" }
|
|
215
|
+
];
|
|
216
|
+
var x402UptoPermit2ProxyABI = [
|
|
217
|
+
{
|
|
218
|
+
type: "function",
|
|
219
|
+
name: "PERMIT2",
|
|
220
|
+
inputs: [],
|
|
221
|
+
outputs: [{ name: "", type: "address", internalType: "contract ISignatureTransfer" }],
|
|
222
|
+
stateMutability: "view"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
type: "function",
|
|
226
|
+
name: "WITNESS_TYPEHASH",
|
|
227
|
+
inputs: [],
|
|
228
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
229
|
+
stateMutability: "view"
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
type: "function",
|
|
233
|
+
name: "WITNESS_TYPE_STRING",
|
|
234
|
+
inputs: [],
|
|
235
|
+
outputs: [{ name: "", type: "string", internalType: "string" }],
|
|
236
|
+
stateMutability: "view"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
type: "function",
|
|
240
|
+
name: "settle",
|
|
241
|
+
inputs: [
|
|
242
|
+
{
|
|
243
|
+
name: "permit",
|
|
244
|
+
type: "tuple",
|
|
245
|
+
internalType: "struct ISignatureTransfer.PermitTransferFrom",
|
|
246
|
+
components: [
|
|
247
|
+
{
|
|
248
|
+
name: "permitted",
|
|
249
|
+
type: "tuple",
|
|
250
|
+
internalType: "struct ISignatureTransfer.TokenPermissions",
|
|
251
|
+
components: [
|
|
252
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
253
|
+
{ name: "amount", type: "uint256", internalType: "uint256" }
|
|
254
|
+
]
|
|
255
|
+
},
|
|
256
|
+
{ name: "nonce", type: "uint256", internalType: "uint256" },
|
|
257
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" }
|
|
258
|
+
]
|
|
259
|
+
},
|
|
260
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
261
|
+
{ name: "owner", type: "address", internalType: "address" },
|
|
262
|
+
{
|
|
263
|
+
name: "witness",
|
|
264
|
+
type: "tuple",
|
|
265
|
+
internalType: "struct x402UptoPermit2Proxy.Witness",
|
|
266
|
+
components: uptoPermit2WitnessABIComponents
|
|
267
|
+
},
|
|
268
|
+
{ name: "signature", type: "bytes", internalType: "bytes" }
|
|
269
|
+
],
|
|
270
|
+
outputs: [],
|
|
271
|
+
stateMutability: "nonpayable"
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
type: "function",
|
|
275
|
+
name: "settleWithPermit",
|
|
276
|
+
inputs: [
|
|
277
|
+
{
|
|
278
|
+
name: "permit2612",
|
|
279
|
+
type: "tuple",
|
|
280
|
+
internalType: "struct x402UptoPermit2Proxy.EIP2612Permit",
|
|
281
|
+
components: [
|
|
282
|
+
{ name: "value", type: "uint256", internalType: "uint256" },
|
|
283
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" },
|
|
284
|
+
{ name: "r", type: "bytes32", internalType: "bytes32" },
|
|
285
|
+
{ name: "s", type: "bytes32", internalType: "bytes32" },
|
|
286
|
+
{ name: "v", type: "uint8", internalType: "uint8" }
|
|
287
|
+
]
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: "permit",
|
|
291
|
+
type: "tuple",
|
|
292
|
+
internalType: "struct ISignatureTransfer.PermitTransferFrom",
|
|
293
|
+
components: [
|
|
294
|
+
{
|
|
295
|
+
name: "permitted",
|
|
296
|
+
type: "tuple",
|
|
297
|
+
internalType: "struct ISignatureTransfer.TokenPermissions",
|
|
298
|
+
components: [
|
|
299
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
300
|
+
{ name: "amount", type: "uint256", internalType: "uint256" }
|
|
301
|
+
]
|
|
302
|
+
},
|
|
303
|
+
{ name: "nonce", type: "uint256", internalType: "uint256" },
|
|
304
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" }
|
|
305
|
+
]
|
|
306
|
+
},
|
|
307
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
308
|
+
{ name: "owner", type: "address", internalType: "address" },
|
|
309
|
+
{
|
|
310
|
+
name: "witness",
|
|
311
|
+
type: "tuple",
|
|
312
|
+
internalType: "struct x402UptoPermit2Proxy.Witness",
|
|
313
|
+
components: uptoPermit2WitnessABIComponents
|
|
314
|
+
},
|
|
315
|
+
{ name: "signature", type: "bytes", internalType: "bytes" }
|
|
316
|
+
],
|
|
317
|
+
outputs: [],
|
|
318
|
+
stateMutability: "nonpayable"
|
|
319
|
+
},
|
|
320
|
+
{ type: "event", name: "Settled", inputs: [], anonymous: false },
|
|
321
|
+
{ type: "event", name: "SettledWithPermit", inputs: [], anonymous: false },
|
|
322
|
+
{ type: "error", name: "AmountExceedsPermitted", inputs: [] },
|
|
323
|
+
{ type: "error", name: "InvalidDestination", inputs: [] },
|
|
324
|
+
{ type: "error", name: "InvalidOwner", inputs: [] },
|
|
325
|
+
{ type: "error", name: "InvalidPermit2Address", inputs: [] },
|
|
326
|
+
{ type: "error", name: "PaymentTooEarly", inputs: [] },
|
|
327
|
+
{ type: "error", name: "Permit2612AmountMismatch", inputs: [] },
|
|
328
|
+
{ type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] },
|
|
329
|
+
{ type: "error", name: "UnauthorizedFacilitator", inputs: [] }
|
|
330
|
+
];
|
|
186
331
|
var x402ExactPermit2ProxyABI = [
|
|
187
332
|
{
|
|
188
333
|
type: "function",
|
|
@@ -296,9 +441,6 @@ var x402ExactPermit2ProxyABI = [
|
|
|
296
441
|
{ type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] }
|
|
297
442
|
];
|
|
298
443
|
|
|
299
|
-
// src/exact/client/scheme.ts
|
|
300
|
-
var import_viem7 = require("viem");
|
|
301
|
-
|
|
302
444
|
// src/utils.ts
|
|
303
445
|
var import_viem = require("viem");
|
|
304
446
|
function getEvmChainId(network) {
|
|
@@ -327,13 +469,7 @@ function createPermit2Nonce() {
|
|
|
327
469
|
return BigInt((0, import_viem.toHex)(randomBytes)).toString();
|
|
328
470
|
}
|
|
329
471
|
|
|
330
|
-
// src/exact/extensions.ts
|
|
331
|
-
var EIP2612_GAS_SPONSORING_KEY = "eip2612GasSponsoring";
|
|
332
|
-
var ERC20_APPROVAL_GAS_SPONSORING_KEY = "erc20ApprovalGasSponsoring";
|
|
333
|
-
var ERC20_APPROVAL_GAS_SPONSORING_VERSION = "1";
|
|
334
|
-
|
|
335
472
|
// src/exact/client/eip3009.ts
|
|
336
|
-
var import_viem2 = require("viem");
|
|
337
473
|
async function createEIP3009Payload(signer, x402Version, paymentRequirements) {
|
|
338
474
|
const nonce = createNonce();
|
|
339
475
|
const now = Math.floor(Date.now() / 1e3);
|
|
@@ -386,9 +522,24 @@ async function signEIP3009Authorization(signer, authorization, requirements) {
|
|
|
386
522
|
}
|
|
387
523
|
|
|
388
524
|
// src/exact/client/permit2.ts
|
|
525
|
+
var import_viem6 = require("viem");
|
|
526
|
+
|
|
527
|
+
// src/exact/extensions.ts
|
|
528
|
+
var EIP2612_GAS_SPONSORING_KEY = "eip2612GasSponsoring";
|
|
529
|
+
var ERC20_APPROVAL_GAS_SPONSORING_KEY = "erc20ApprovalGasSponsoring";
|
|
530
|
+
var ERC20_APPROVAL_GAS_SPONSORING_VERSION = "1";
|
|
531
|
+
|
|
532
|
+
// src/shared/permit2.ts
|
|
533
|
+
var import_viem5 = require("viem");
|
|
534
|
+
|
|
535
|
+
// src/multicall.ts
|
|
389
536
|
var import_viem3 = require("viem");
|
|
390
|
-
|
|
391
|
-
|
|
537
|
+
|
|
538
|
+
// src/shared/erc20approval.ts
|
|
539
|
+
var import_viem4 = require("viem");
|
|
540
|
+
|
|
541
|
+
// src/shared/permit2.ts
|
|
542
|
+
async function createPermit2PayloadForProxy(proxyAddress, signer, x402Version, paymentRequirements) {
|
|
392
543
|
const now = Math.floor(Date.now() / 1e3);
|
|
393
544
|
const nonce = createPermit2Nonce();
|
|
394
545
|
const validAfter = (now - 600).toString();
|
|
@@ -396,14 +547,14 @@ async function createPermit2Payload(signer, x402Version, paymentRequirements) {
|
|
|
396
547
|
const permit2Authorization = {
|
|
397
548
|
from: signer.address,
|
|
398
549
|
permitted: {
|
|
399
|
-
token: (0,
|
|
550
|
+
token: (0, import_viem5.getAddress)(paymentRequirements.asset),
|
|
400
551
|
amount: paymentRequirements.amount
|
|
401
552
|
},
|
|
402
|
-
spender:
|
|
553
|
+
spender: proxyAddress,
|
|
403
554
|
nonce,
|
|
404
555
|
deadline,
|
|
405
556
|
witness: {
|
|
406
|
-
to: (0,
|
|
557
|
+
to: (0, import_viem5.getAddress)(paymentRequirements.payTo),
|
|
407
558
|
validAfter
|
|
408
559
|
}
|
|
409
560
|
};
|
|
@@ -412,67 +563,71 @@ async function createPermit2Payload(signer, x402Version, paymentRequirements) {
|
|
|
412
563
|
permit2Authorization,
|
|
413
564
|
paymentRequirements
|
|
414
565
|
);
|
|
415
|
-
const payload = {
|
|
416
|
-
signature,
|
|
417
|
-
permit2Authorization
|
|
418
|
-
};
|
|
419
566
|
return {
|
|
420
567
|
x402Version,
|
|
421
|
-
payload
|
|
568
|
+
payload: { signature, permit2Authorization }
|
|
422
569
|
};
|
|
423
570
|
}
|
|
424
571
|
async function signPermit2Authorization(signer, permit2Authorization, requirements) {
|
|
425
572
|
const chainId = getEvmChainId(requirements.network);
|
|
426
|
-
const domain = {
|
|
427
|
-
name: "Permit2",
|
|
428
|
-
chainId,
|
|
429
|
-
verifyingContract: PERMIT2_ADDRESS
|
|
430
|
-
};
|
|
431
|
-
const message = {
|
|
432
|
-
permitted: {
|
|
433
|
-
token: (0, import_viem3.getAddress)(permit2Authorization.permitted.token),
|
|
434
|
-
amount: BigInt(permit2Authorization.permitted.amount)
|
|
435
|
-
},
|
|
436
|
-
spender: (0, import_viem3.getAddress)(permit2Authorization.spender),
|
|
437
|
-
nonce: BigInt(permit2Authorization.nonce),
|
|
438
|
-
deadline: BigInt(permit2Authorization.deadline),
|
|
439
|
-
witness: {
|
|
440
|
-
to: (0, import_viem3.getAddress)(permit2Authorization.witness.to),
|
|
441
|
-
validAfter: BigInt(permit2Authorization.witness.validAfter)
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
573
|
return await signer.signTypedData({
|
|
445
|
-
domain,
|
|
574
|
+
domain: { name: "Permit2", chainId, verifyingContract: PERMIT2_ADDRESS },
|
|
446
575
|
types: permit2WitnessTypes,
|
|
447
576
|
primaryType: "PermitWitnessTransferFrom",
|
|
448
|
-
message
|
|
577
|
+
message: {
|
|
578
|
+
permitted: {
|
|
579
|
+
token: (0, import_viem5.getAddress)(permit2Authorization.permitted.token),
|
|
580
|
+
amount: BigInt(permit2Authorization.permitted.amount)
|
|
581
|
+
},
|
|
582
|
+
spender: (0, import_viem5.getAddress)(permit2Authorization.spender),
|
|
583
|
+
nonce: BigInt(permit2Authorization.nonce),
|
|
584
|
+
deadline: BigInt(permit2Authorization.deadline),
|
|
585
|
+
witness: {
|
|
586
|
+
to: (0, import_viem5.getAddress)(permit2Authorization.witness.to),
|
|
587
|
+
validAfter: BigInt(permit2Authorization.witness.validAfter)
|
|
588
|
+
}
|
|
589
|
+
}
|
|
449
590
|
});
|
|
450
591
|
}
|
|
592
|
+
|
|
593
|
+
// src/exact/client/permit2.ts
|
|
594
|
+
var MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
595
|
+
async function createPermit2Payload(signer, x402Version, paymentRequirements) {
|
|
596
|
+
return createPermit2PayloadForProxy(
|
|
597
|
+
x402ExactPermit2ProxyAddress,
|
|
598
|
+
signer,
|
|
599
|
+
x402Version,
|
|
600
|
+
paymentRequirements
|
|
601
|
+
);
|
|
602
|
+
}
|
|
451
603
|
function createPermit2ApprovalTx(tokenAddress) {
|
|
452
|
-
const data = (0,
|
|
604
|
+
const data = (0, import_viem6.encodeFunctionData)({
|
|
453
605
|
abi: erc20ApproveAbi,
|
|
454
606
|
functionName: "approve",
|
|
455
607
|
args: [PERMIT2_ADDRESS, MAX_UINT256]
|
|
456
608
|
});
|
|
457
609
|
return {
|
|
458
|
-
to: (0,
|
|
610
|
+
to: (0, import_viem6.getAddress)(tokenAddress),
|
|
459
611
|
data
|
|
460
612
|
};
|
|
461
613
|
}
|
|
462
614
|
function getPermit2AllowanceReadParams(params) {
|
|
463
615
|
return {
|
|
464
|
-
address: (0,
|
|
616
|
+
address: (0, import_viem6.getAddress)(params.tokenAddress),
|
|
465
617
|
abi: erc20AllowanceAbi,
|
|
466
618
|
functionName: "allowance",
|
|
467
|
-
args: [(0,
|
|
619
|
+
args: [(0, import_viem6.getAddress)(params.ownerAddress), PERMIT2_ADDRESS]
|
|
468
620
|
};
|
|
469
621
|
}
|
|
470
622
|
|
|
623
|
+
// src/shared/extensions.ts
|
|
624
|
+
var import_viem10 = require("viem");
|
|
625
|
+
|
|
471
626
|
// src/exact/client/eip2612.ts
|
|
472
|
-
var
|
|
627
|
+
var import_viem7 = require("viem");
|
|
473
628
|
async function signEip2612Permit(signer, tokenAddress, tokenName, tokenVersion, chainId, deadline, permittedAmount) {
|
|
474
629
|
const owner = signer.address;
|
|
475
|
-
const spender = (0,
|
|
630
|
+
const spender = (0, import_viem7.getAddress)(PERMIT2_ADDRESS);
|
|
476
631
|
const nonce = await signer.readContract({
|
|
477
632
|
address: tokenAddress,
|
|
478
633
|
abi: eip2612NoncesAbi,
|
|
@@ -512,14 +667,14 @@ async function signEip2612Permit(signer, tokenAddress, tokenName, tokenVersion,
|
|
|
512
667
|
}
|
|
513
668
|
|
|
514
669
|
// src/exact/client/erc20approval.ts
|
|
515
|
-
var
|
|
670
|
+
var import_viem8 = require("viem");
|
|
516
671
|
async function signErc20ApprovalTransaction(signer, tokenAddress, chainId) {
|
|
517
672
|
const from = signer.address;
|
|
518
|
-
const spender = (0,
|
|
519
|
-
const data = (0,
|
|
673
|
+
const spender = (0, import_viem8.getAddress)(PERMIT2_ADDRESS);
|
|
674
|
+
const data = (0, import_viem8.encodeFunctionData)({
|
|
520
675
|
abi: erc20ApproveAbi,
|
|
521
676
|
functionName: "approve",
|
|
522
|
-
args: [spender,
|
|
677
|
+
args: [spender, import_viem8.maxUint256]
|
|
523
678
|
});
|
|
524
679
|
const nonce = await signer.getTransactionCount({ address: from });
|
|
525
680
|
let maxFeePerGas;
|
|
@@ -548,14 +703,14 @@ async function signErc20ApprovalTransaction(signer, tokenAddress, chainId) {
|
|
|
548
703
|
from,
|
|
549
704
|
asset: tokenAddress,
|
|
550
705
|
spender,
|
|
551
|
-
amount:
|
|
706
|
+
amount: import_viem8.maxUint256.toString(),
|
|
552
707
|
signedTransaction,
|
|
553
708
|
version: ERC20_APPROVAL_GAS_SPONSORING_VERSION
|
|
554
709
|
};
|
|
555
710
|
}
|
|
556
711
|
|
|
557
|
-
// src/
|
|
558
|
-
var
|
|
712
|
+
// src/shared/rpc.ts
|
|
713
|
+
var import_viem9 = require("viem");
|
|
559
714
|
var rpcClientCache = /* @__PURE__ */ new Map();
|
|
560
715
|
function isConfigByChainId(options) {
|
|
561
716
|
const keys = Object.keys(options);
|
|
@@ -566,8 +721,8 @@ function getRpcClient(rpcUrl) {
|
|
|
566
721
|
if (existing) {
|
|
567
722
|
return existing;
|
|
568
723
|
}
|
|
569
|
-
const client = (0,
|
|
570
|
-
transport: (0,
|
|
724
|
+
const client = (0, import_viem9.createPublicClient)({
|
|
725
|
+
transport: (0, import_viem9.http)(rpcUrl)
|
|
571
726
|
});
|
|
572
727
|
rpcClientCache.set(rpcUrl, client);
|
|
573
728
|
return client;
|
|
@@ -611,6 +766,93 @@ function resolveExtensionRpcCapabilities(network, signer, options) {
|
|
|
611
766
|
return capabilities;
|
|
612
767
|
}
|
|
613
768
|
|
|
769
|
+
// src/shared/extensions.ts
|
|
770
|
+
async function trySignEip2612PermitExtension(signer, options, requirements, result, context) {
|
|
771
|
+
const capabilities = resolveExtensionRpcCapabilities(requirements.network, signer, options);
|
|
772
|
+
if (!capabilities.readContract) {
|
|
773
|
+
return void 0;
|
|
774
|
+
}
|
|
775
|
+
if (!context?.extensions?.[EIP2612_GAS_SPONSORING_KEY]) {
|
|
776
|
+
return void 0;
|
|
777
|
+
}
|
|
778
|
+
const tokenName = requirements.extra?.name;
|
|
779
|
+
const tokenVersion = requirements.extra?.version;
|
|
780
|
+
if (!tokenName || !tokenVersion) {
|
|
781
|
+
return void 0;
|
|
782
|
+
}
|
|
783
|
+
const chainId = getEvmChainId(requirements.network);
|
|
784
|
+
const tokenAddress = (0, import_viem10.getAddress)(requirements.asset);
|
|
785
|
+
try {
|
|
786
|
+
const allowance = await capabilities.readContract({
|
|
787
|
+
address: tokenAddress,
|
|
788
|
+
abi: erc20AllowanceAbi,
|
|
789
|
+
functionName: "allowance",
|
|
790
|
+
args: [signer.address, PERMIT2_ADDRESS]
|
|
791
|
+
});
|
|
792
|
+
if (allowance >= BigInt(requirements.amount)) {
|
|
793
|
+
return void 0;
|
|
794
|
+
}
|
|
795
|
+
} catch {
|
|
796
|
+
}
|
|
797
|
+
const permit2Auth = result.payload?.permit2Authorization;
|
|
798
|
+
const deadline = permit2Auth?.deadline ?? Math.floor(Date.now() / 1e3 + requirements.maxTimeoutSeconds).toString();
|
|
799
|
+
const info = await signEip2612Permit(
|
|
800
|
+
{
|
|
801
|
+
address: signer.address,
|
|
802
|
+
signTypedData: (msg) => signer.signTypedData(msg),
|
|
803
|
+
readContract: capabilities.readContract
|
|
804
|
+
},
|
|
805
|
+
tokenAddress,
|
|
806
|
+
tokenName,
|
|
807
|
+
tokenVersion,
|
|
808
|
+
chainId,
|
|
809
|
+
deadline,
|
|
810
|
+
requirements.amount
|
|
811
|
+
);
|
|
812
|
+
return {
|
|
813
|
+
[EIP2612_GAS_SPONSORING_KEY]: { info }
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
async function trySignErc20ApprovalExtension(signer, options, requirements, context) {
|
|
817
|
+
const capabilities = resolveExtensionRpcCapabilities(requirements.network, signer, options);
|
|
818
|
+
if (!capabilities.readContract) {
|
|
819
|
+
return void 0;
|
|
820
|
+
}
|
|
821
|
+
if (!context?.extensions?.[ERC20_APPROVAL_GAS_SPONSORING_KEY]) {
|
|
822
|
+
return void 0;
|
|
823
|
+
}
|
|
824
|
+
if (!capabilities.signTransaction || !capabilities.getTransactionCount) {
|
|
825
|
+
return void 0;
|
|
826
|
+
}
|
|
827
|
+
const chainId = getEvmChainId(requirements.network);
|
|
828
|
+
const tokenAddress = (0, import_viem10.getAddress)(requirements.asset);
|
|
829
|
+
try {
|
|
830
|
+
const allowance = await capabilities.readContract({
|
|
831
|
+
address: tokenAddress,
|
|
832
|
+
abi: erc20AllowanceAbi,
|
|
833
|
+
functionName: "allowance",
|
|
834
|
+
args: [signer.address, PERMIT2_ADDRESS]
|
|
835
|
+
});
|
|
836
|
+
if (allowance >= BigInt(requirements.amount)) {
|
|
837
|
+
return void 0;
|
|
838
|
+
}
|
|
839
|
+
} catch {
|
|
840
|
+
}
|
|
841
|
+
const info = await signErc20ApprovalTransaction(
|
|
842
|
+
{
|
|
843
|
+
address: signer.address,
|
|
844
|
+
signTransaction: capabilities.signTransaction,
|
|
845
|
+
getTransactionCount: capabilities.getTransactionCount,
|
|
846
|
+
estimateFeesPerGas: capabilities.estimateFeesPerGas
|
|
847
|
+
},
|
|
848
|
+
tokenAddress,
|
|
849
|
+
chainId
|
|
850
|
+
);
|
|
851
|
+
return {
|
|
852
|
+
[ERC20_APPROVAL_GAS_SPONSORING_KEY]: { info }
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
|
|
614
856
|
// src/exact/client/scheme.ts
|
|
615
857
|
var ExactEvmScheme = class {
|
|
616
858
|
/**
|
|
@@ -644,7 +886,9 @@ var ExactEvmScheme = class {
|
|
|
644
886
|
const assetTransferMethod = paymentRequirements.extra?.assetTransferMethod ?? "eip3009";
|
|
645
887
|
if (assetTransferMethod === "permit2") {
|
|
646
888
|
const result = await createPermit2Payload(this.signer, x402Version, paymentRequirements);
|
|
647
|
-
const eip2612Extensions = await
|
|
889
|
+
const eip2612Extensions = await trySignEip2612PermitExtension(
|
|
890
|
+
this.signer,
|
|
891
|
+
this.options,
|
|
648
892
|
paymentRequirements,
|
|
649
893
|
result,
|
|
650
894
|
context
|
|
@@ -655,7 +899,12 @@ var ExactEvmScheme = class {
|
|
|
655
899
|
extensions: eip2612Extensions
|
|
656
900
|
};
|
|
657
901
|
}
|
|
658
|
-
const erc20Extensions = await
|
|
902
|
+
const erc20Extensions = await trySignErc20ApprovalExtension(
|
|
903
|
+
this.signer,
|
|
904
|
+
this.options,
|
|
905
|
+
paymentRequirements,
|
|
906
|
+
context
|
|
907
|
+
);
|
|
659
908
|
if (erc20Extensions) {
|
|
660
909
|
return {
|
|
661
910
|
...result,
|
|
@@ -666,146 +915,16 @@ var ExactEvmScheme = class {
|
|
|
666
915
|
}
|
|
667
916
|
return createEIP3009Payload(this.signer, x402Version, paymentRequirements);
|
|
668
917
|
}
|
|
669
|
-
/**
|
|
670
|
-
* Attempts to sign an EIP-2612 permit for gasless Permit2 approval.
|
|
671
|
-
*
|
|
672
|
-
* Returns extension data if:
|
|
673
|
-
* 1. Server advertises eip2612GasSponsoring
|
|
674
|
-
* 2. Signer has readContract capability
|
|
675
|
-
* 3. Current Permit2 allowance is insufficient
|
|
676
|
-
*
|
|
677
|
-
* Returns undefined if the extension should not be used.
|
|
678
|
-
*
|
|
679
|
-
* @param requirements - The payment requirements from the server
|
|
680
|
-
* @param result - The payment payload result from the scheme
|
|
681
|
-
* @param context - Optional context containing server extensions and metadata
|
|
682
|
-
* @returns Extension data for EIP-2612 gas sponsoring, or undefined if not applicable
|
|
683
|
-
*/
|
|
684
|
-
async trySignEip2612Permit(requirements, result, context) {
|
|
685
|
-
const capabilities = resolveExtensionRpcCapabilities(
|
|
686
|
-
requirements.network,
|
|
687
|
-
this.signer,
|
|
688
|
-
this.options
|
|
689
|
-
);
|
|
690
|
-
if (!capabilities.readContract) {
|
|
691
|
-
return void 0;
|
|
692
|
-
}
|
|
693
|
-
if (!context?.extensions?.[EIP2612_GAS_SPONSORING_KEY]) {
|
|
694
|
-
return void 0;
|
|
695
|
-
}
|
|
696
|
-
const tokenName = requirements.extra?.name;
|
|
697
|
-
const tokenVersion = requirements.extra?.version;
|
|
698
|
-
if (!tokenName || !tokenVersion) {
|
|
699
|
-
return void 0;
|
|
700
|
-
}
|
|
701
|
-
const chainId = getEvmChainId(requirements.network);
|
|
702
|
-
const tokenAddress = (0, import_viem7.getAddress)(requirements.asset);
|
|
703
|
-
try {
|
|
704
|
-
const allowance = await capabilities.readContract({
|
|
705
|
-
address: tokenAddress,
|
|
706
|
-
abi: erc20AllowanceAbi,
|
|
707
|
-
functionName: "allowance",
|
|
708
|
-
args: [this.signer.address, PERMIT2_ADDRESS]
|
|
709
|
-
});
|
|
710
|
-
if (allowance >= BigInt(requirements.amount)) {
|
|
711
|
-
return void 0;
|
|
712
|
-
}
|
|
713
|
-
} catch {
|
|
714
|
-
}
|
|
715
|
-
const permit2Auth = result.payload?.permit2Authorization;
|
|
716
|
-
const deadline = permit2Auth?.deadline ?? Math.floor(Date.now() / 1e3 + requirements.maxTimeoutSeconds).toString();
|
|
717
|
-
const info = await signEip2612Permit(
|
|
718
|
-
{
|
|
719
|
-
address: this.signer.address,
|
|
720
|
-
signTypedData: (msg) => this.signer.signTypedData(msg),
|
|
721
|
-
readContract: capabilities.readContract
|
|
722
|
-
},
|
|
723
|
-
tokenAddress,
|
|
724
|
-
tokenName,
|
|
725
|
-
tokenVersion,
|
|
726
|
-
chainId,
|
|
727
|
-
deadline,
|
|
728
|
-
requirements.amount
|
|
729
|
-
);
|
|
730
|
-
return {
|
|
731
|
-
[EIP2612_GAS_SPONSORING_KEY]: { info }
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* Attempts to sign an ERC-20 approval transaction for gasless Permit2 approval.
|
|
736
|
-
*
|
|
737
|
-
* This is the fallback path when the token does not support EIP-2612. The client
|
|
738
|
-
* signs (but does not broadcast) a raw `approve(Permit2, MaxUint256)` transaction.
|
|
739
|
-
* The facilitator broadcasts it atomically before settling.
|
|
740
|
-
*
|
|
741
|
-
* Returns extension data if:
|
|
742
|
-
* 1. Server advertises erc20ApprovalGasSponsoring
|
|
743
|
-
* 2. Signer has signTransaction + getTransactionCount capabilities
|
|
744
|
-
* 3. Current Permit2 allowance is insufficient
|
|
745
|
-
*
|
|
746
|
-
* Returns undefined if the extension should not be used.
|
|
747
|
-
*
|
|
748
|
-
* @param requirements - The payment requirements from the server
|
|
749
|
-
* @param _result - The payment payload result from the scheme (unused)
|
|
750
|
-
* @param context - Optional context containing server extensions and metadata
|
|
751
|
-
* @returns Extension data for ERC-20 approval gas sponsoring, or undefined if not applicable
|
|
752
|
-
*/
|
|
753
|
-
async trySignErc20Approval(requirements, _result, context) {
|
|
754
|
-
const capabilities = resolveExtensionRpcCapabilities(
|
|
755
|
-
requirements.network,
|
|
756
|
-
this.signer,
|
|
757
|
-
this.options
|
|
758
|
-
);
|
|
759
|
-
if (!capabilities.readContract) {
|
|
760
|
-
return void 0;
|
|
761
|
-
}
|
|
762
|
-
if (!context?.extensions?.[ERC20_APPROVAL_GAS_SPONSORING_KEY]) {
|
|
763
|
-
return void 0;
|
|
764
|
-
}
|
|
765
|
-
if (!capabilities.signTransaction || !capabilities.getTransactionCount) {
|
|
766
|
-
return void 0;
|
|
767
|
-
}
|
|
768
|
-
const chainId = getEvmChainId(requirements.network);
|
|
769
|
-
const tokenAddress = (0, import_viem7.getAddress)(requirements.asset);
|
|
770
|
-
try {
|
|
771
|
-
const allowance = await capabilities.readContract({
|
|
772
|
-
address: tokenAddress,
|
|
773
|
-
abi: erc20AllowanceAbi,
|
|
774
|
-
functionName: "allowance",
|
|
775
|
-
args: [this.signer.address, PERMIT2_ADDRESS]
|
|
776
|
-
});
|
|
777
|
-
if (allowance >= BigInt(requirements.amount)) {
|
|
778
|
-
return void 0;
|
|
779
|
-
}
|
|
780
|
-
} catch {
|
|
781
|
-
}
|
|
782
|
-
const info = await signErc20ApprovalTransaction(
|
|
783
|
-
{
|
|
784
|
-
address: this.signer.address,
|
|
785
|
-
signTransaction: capabilities.signTransaction,
|
|
786
|
-
getTransactionCount: capabilities.getTransactionCount,
|
|
787
|
-
estimateFeesPerGas: capabilities.estimateFeesPerGas
|
|
788
|
-
},
|
|
789
|
-
tokenAddress,
|
|
790
|
-
chainId
|
|
791
|
-
);
|
|
792
|
-
return {
|
|
793
|
-
[ERC20_APPROVAL_GAS_SPONSORING_KEY]: { info }
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
918
|
};
|
|
797
919
|
|
|
798
920
|
// src/exact/v1/client/scheme.ts
|
|
799
|
-
var
|
|
921
|
+
var import_viem13 = require("viem");
|
|
800
922
|
|
|
801
923
|
// src/exact/v1/facilitator/scheme.ts
|
|
802
|
-
var
|
|
924
|
+
var import_viem12 = require("viem");
|
|
803
925
|
|
|
804
926
|
// src/exact/facilitator/eip3009-utils.ts
|
|
805
|
-
var
|
|
806
|
-
|
|
807
|
-
// src/multicall.ts
|
|
808
|
-
var import_viem8 = require("viem");
|
|
927
|
+
var import_viem11 = require("viem");
|
|
809
928
|
|
|
810
929
|
// src/v1/index.ts
|
|
811
930
|
var EVM_NETWORK_CHAIN_ID_MAP = {
|
|
@@ -827,7 +946,11 @@ var EVM_NETWORK_CHAIN_ID_MAP = {
|
|
|
827
946
|
educhain: 41923,
|
|
828
947
|
"skale-base-sepolia": 324705682,
|
|
829
948
|
megaeth: 4326,
|
|
830
|
-
monad: 143
|
|
949
|
+
monad: 143,
|
|
950
|
+
kiteai: 2366,
|
|
951
|
+
"kiteai-testnet": 2368,
|
|
952
|
+
stable: 988,
|
|
953
|
+
"stable-testnet": 2201
|
|
831
954
|
};
|
|
832
955
|
var NETWORKS = Object.keys(EVM_NETWORK_CHAIN_ID_MAP);
|
|
833
956
|
|
|
@@ -869,10 +992,136 @@ function isPermit2Payload(payload) {
|
|
|
869
992
|
function isEIP3009Payload(payload) {
|
|
870
993
|
return "authorization" in payload;
|
|
871
994
|
}
|
|
995
|
+
function isUptoPermit2Payload(payload) {
|
|
996
|
+
if (typeof payload.signature !== "string") return false;
|
|
997
|
+
if (!("permit2Authorization" in payload)) return false;
|
|
998
|
+
const auth = payload.permit2Authorization;
|
|
999
|
+
if (typeof auth !== "object" || auth === null) return false;
|
|
1000
|
+
const a = auth;
|
|
1001
|
+
if (typeof a.from !== "string") return false;
|
|
1002
|
+
if (typeof a.spender !== "string") return false;
|
|
1003
|
+
if (typeof a.nonce !== "string") return false;
|
|
1004
|
+
if (typeof a.deadline !== "string") return false;
|
|
1005
|
+
const permitted = a.permitted;
|
|
1006
|
+
if (typeof permitted !== "object" || permitted === null) return false;
|
|
1007
|
+
const p = permitted;
|
|
1008
|
+
if (typeof p.token !== "string") return false;
|
|
1009
|
+
if (typeof p.amount !== "string") return false;
|
|
1010
|
+
const witness = a.witness;
|
|
1011
|
+
if (typeof witness !== "object" || witness === null) return false;
|
|
1012
|
+
const w = witness;
|
|
1013
|
+
return typeof w.facilitator === "string" && typeof w.to === "string" && typeof w.validAfter === "string";
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// src/upto/client/permit2.ts
|
|
1017
|
+
var import_viem14 = require("viem");
|
|
1018
|
+
async function createUptoPermit2Payload(signer, x402Version, paymentRequirements) {
|
|
1019
|
+
const facilitatorAddress = paymentRequirements.extra?.facilitatorAddress;
|
|
1020
|
+
if (!facilitatorAddress) {
|
|
1021
|
+
throw new Error(
|
|
1022
|
+
"upto scheme requires facilitatorAddress in paymentRequirements.extra. Ensure the server is configured with an upto facilitator that provides getExtra()."
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
1026
|
+
const nonce = createPermit2Nonce();
|
|
1027
|
+
const validAfter = (now - 600).toString();
|
|
1028
|
+
const deadline = (now + paymentRequirements.maxTimeoutSeconds).toString();
|
|
1029
|
+
if (BigInt(deadline) <= BigInt(validAfter)) {
|
|
1030
|
+
throw new Error(
|
|
1031
|
+
`Invalid time window: deadline (${deadline}) must be after validAfter (${validAfter}). Check that maxTimeoutSeconds (${paymentRequirements.maxTimeoutSeconds}) is positive.`
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
const permit2Authorization = {
|
|
1035
|
+
from: signer.address,
|
|
1036
|
+
permitted: {
|
|
1037
|
+
token: (0, import_viem14.getAddress)(paymentRequirements.asset),
|
|
1038
|
+
amount: paymentRequirements.amount
|
|
1039
|
+
},
|
|
1040
|
+
spender: x402UptoPermit2ProxyAddress,
|
|
1041
|
+
nonce,
|
|
1042
|
+
deadline,
|
|
1043
|
+
witness: {
|
|
1044
|
+
to: (0, import_viem14.getAddress)(paymentRequirements.payTo),
|
|
1045
|
+
facilitator: (0, import_viem14.getAddress)(facilitatorAddress),
|
|
1046
|
+
validAfter
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
const chainId = getEvmChainId(paymentRequirements.network);
|
|
1050
|
+
const signature = await signer.signTypedData({
|
|
1051
|
+
domain: { name: "Permit2", chainId, verifyingContract: PERMIT2_ADDRESS },
|
|
1052
|
+
types: uptoPermit2WitnessTypes,
|
|
1053
|
+
primaryType: "PermitWitnessTransferFrom",
|
|
1054
|
+
message: {
|
|
1055
|
+
permitted: {
|
|
1056
|
+
token: (0, import_viem14.getAddress)(permit2Authorization.permitted.token),
|
|
1057
|
+
amount: BigInt(permit2Authorization.permitted.amount)
|
|
1058
|
+
},
|
|
1059
|
+
spender: (0, import_viem14.getAddress)(permit2Authorization.spender),
|
|
1060
|
+
nonce: BigInt(permit2Authorization.nonce),
|
|
1061
|
+
deadline: BigInt(permit2Authorization.deadline),
|
|
1062
|
+
witness: {
|
|
1063
|
+
to: (0, import_viem14.getAddress)(permit2Authorization.witness.to),
|
|
1064
|
+
facilitator: (0, import_viem14.getAddress)(permit2Authorization.witness.facilitator),
|
|
1065
|
+
validAfter: BigInt(permit2Authorization.witness.validAfter)
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
return {
|
|
1070
|
+
x402Version,
|
|
1071
|
+
payload: { signature, permit2Authorization }
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// src/upto/client/scheme.ts
|
|
1076
|
+
var UptoEvmScheme = class {
|
|
1077
|
+
/**
|
|
1078
|
+
* Creates a new UptoEvmScheme instance.
|
|
1079
|
+
*
|
|
1080
|
+
* @param signer - The EVM signer for client operations
|
|
1081
|
+
* @param options - Optional RPC configuration
|
|
1082
|
+
*/
|
|
1083
|
+
constructor(signer, options) {
|
|
1084
|
+
this.signer = signer;
|
|
1085
|
+
this.options = options;
|
|
1086
|
+
this.scheme = "upto";
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Creates a payment payload for the Upto scheme using Permit2.
|
|
1090
|
+
*
|
|
1091
|
+
* @param x402Version - The x402 protocol version
|
|
1092
|
+
* @param paymentRequirements - The payment requirements
|
|
1093
|
+
* @param context - Optional context with server-declared extensions
|
|
1094
|
+
* @returns Promise resolving to a payment payload result
|
|
1095
|
+
*/
|
|
1096
|
+
async createPaymentPayload(x402Version, paymentRequirements, context) {
|
|
1097
|
+
const result = await createUptoPermit2Payload(this.signer, x402Version, paymentRequirements);
|
|
1098
|
+
const eip2612Extensions = await trySignEip2612PermitExtension(
|
|
1099
|
+
this.signer,
|
|
1100
|
+
this.options,
|
|
1101
|
+
paymentRequirements,
|
|
1102
|
+
result,
|
|
1103
|
+
context
|
|
1104
|
+
);
|
|
1105
|
+
if (eip2612Extensions) {
|
|
1106
|
+
return { ...result, extensions: eip2612Extensions };
|
|
1107
|
+
}
|
|
1108
|
+
const erc20Extensions = await trySignErc20ApprovalExtension(
|
|
1109
|
+
this.signer,
|
|
1110
|
+
this.options,
|
|
1111
|
+
paymentRequirements,
|
|
1112
|
+
context
|
|
1113
|
+
);
|
|
1114
|
+
if (erc20Extensions) {
|
|
1115
|
+
return { ...result, extensions: erc20Extensions };
|
|
1116
|
+
}
|
|
1117
|
+
return result;
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
872
1120
|
// Annotate the CommonJS export names for ESM import in node:
|
|
873
1121
|
0 && (module.exports = {
|
|
874
1122
|
ExactEvmScheme,
|
|
875
1123
|
PERMIT2_ADDRESS,
|
|
1124
|
+
UptoEvmScheme,
|
|
876
1125
|
authorizationTypes,
|
|
877
1126
|
createPermit2ApprovalTx,
|
|
878
1127
|
eip3009ABI,
|
|
@@ -880,11 +1129,14 @@ function isEIP3009Payload(payload) {
|
|
|
880
1129
|
getPermit2AllowanceReadParams,
|
|
881
1130
|
isEIP3009Payload,
|
|
882
1131
|
isPermit2Payload,
|
|
1132
|
+
isUptoPermit2Payload,
|
|
883
1133
|
permit2WitnessTypes,
|
|
884
1134
|
toClientEvmSigner,
|
|
885
1135
|
toFacilitatorEvmSigner,
|
|
1136
|
+
uptoPermit2WitnessTypes,
|
|
886
1137
|
x402ExactPermit2ProxyABI,
|
|
887
1138
|
x402ExactPermit2ProxyAddress,
|
|
1139
|
+
x402UptoPermit2ProxyABI,
|
|
888
1140
|
x402UptoPermit2ProxyAddress
|
|
889
1141
|
});
|
|
890
1142
|
//# sourceMappingURL=index.js.map
|