@armory-sh/base 0.2.32 → 0.2.33-alpha.26.93
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/data/tokens.d.ts +0 -2
- package/dist/eip712.d.ts +0 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +218 -126
- package/package.json +1 -1
- package/src/data/tokens.ts +0 -11
- package/src/eip712.ts +20 -11
- package/src/index.ts +0 -2
- package/src/payment-requirements.ts +1 -1
- package/src/types/networks.ts +100 -1
package/dist/data/tokens.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export declare const USDC_BASE: CustomToken;
|
|
|
3
3
|
export declare const EURC_BASE: CustomToken;
|
|
4
4
|
export declare const USDC_BASE_SEPOLIA: CustomToken;
|
|
5
5
|
export declare const USDC_SKALE_BASE: CustomToken;
|
|
6
|
-
export declare const SKL_SKALE_BASE: CustomToken;
|
|
7
6
|
export declare const USDT_SKALE_BASE: CustomToken;
|
|
8
7
|
export declare const WBTC_SKALE_BASE: CustomToken;
|
|
9
8
|
export declare const WETH_SKALE_BASE: CustomToken;
|
|
@@ -20,7 +19,6 @@ export declare const TOKENS: {
|
|
|
20
19
|
readonly USDT_SKALE_BASE: CustomToken;
|
|
21
20
|
readonly WBTC_SKALE_BASE: CustomToken;
|
|
22
21
|
readonly WETH_SKALE_BASE: CustomToken;
|
|
23
|
-
readonly SKL_SKALE_BASE: CustomToken;
|
|
24
22
|
readonly SKL_SKALE_BASE_SEPOLIA: CustomToken;
|
|
25
23
|
readonly USDC_SKALE_BASE_SEPOLIA: CustomToken;
|
|
26
24
|
readonly USDT_SKALE_BASE_SEPOLIA: CustomToken;
|
package/dist/eip712.d.ts
CHANGED
|
@@ -48,10 +48,6 @@ export declare const EIP712_TYPES: {
|
|
|
48
48
|
readonly type: "bytes32";
|
|
49
49
|
}];
|
|
50
50
|
};
|
|
51
|
-
export declare const USDC_DOMAIN: {
|
|
52
|
-
readonly NAME: "USD Coin";
|
|
53
|
-
readonly VERSION: "2";
|
|
54
|
-
};
|
|
55
51
|
export declare const createEIP712Domain: (chainId: number, contractAddress: `0x${string}`) => EIP712Domain;
|
|
56
52
|
export declare const createTransferWithAuthorization: (params: Omit<TransferWithAuthorization, "value" | "validAfter" | "validBefore" | "nonce"> & {
|
|
57
53
|
value: bigint | number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export type { BalanceOfParams, BalanceOfReturnType, ERC20Abi, NameReturnType, ReceiveWithAuthorizationParams, SymbolReturnType, TransferWithAuthorizationParams, } from "./abi/erc20";
|
|
2
2
|
export { ERC20_ABI } from "./abi/erc20";
|
|
3
3
|
export { runAfterPaymentResponseHooks, runBeforeSignPaymentHooks, runOnPaymentRequiredHooks, selectRequirementWithHooks, } from "./client-hooks-runtime";
|
|
4
|
-
export { EURC_BASE, getAllTokens, getEURCTokens, getSKLTokens, getToken, getTokensByChain, getTokensBySymbol, getUSDCTokens, getUSDTTokens, getWBTCTokens, getWETHTokens,
|
|
4
|
+
export { EURC_BASE, getAllTokens, getEURCTokens, getSKLTokens, getToken, getTokensByChain, getTokensBySymbol, getUSDCTokens, getUSDTTokens, getWBTCTokens, getWETHTokens, SKL_SKALE_BASE_SEPOLIA, TOKENS, USDC_BASE, USDC_BASE_SEPOLIA, USDC_SKALE_BASE, USDC_SKALE_BASE_SEPOLIA, USDT_SKALE_BASE, USDT_SKALE_BASE_SEPOLIA, WBTC_SKALE_BASE, WBTC_SKALE_BASE_SEPOLIA, WETH_SKALE_BASE, WETH_SKALE_BASE_SEPOLIA, } from "./data/tokens";
|
|
5
5
|
export type { EIP712Domain, EIP712Types, TransferWithAuthorization, TypedDataDomain, TypedDataField, } from "./eip712";
|
|
6
|
-
export { createEIP712Domain, createTransferWithAuthorization, EIP712_TYPES,
|
|
6
|
+
export { createEIP712Domain, createTransferWithAuthorization, EIP712_TYPES, validateTransferWithAuthorization, } from "./eip712";
|
|
7
7
|
export { decodePaymentV2, decodeSettlementV2, encodePaymentV2, encodeSettlementV2, isPaymentV2, isSettlementV2, } from "./encoding";
|
|
8
8
|
export type { PaymentRequiredOptions } from "./encoding/x402";
|
|
9
9
|
export { createPaymentRequiredHeaders, createSettlementHeaders, decodePayment, decodeSettlementResponse, decodeX402Response, detectPaymentVersion, encodePayment, encodeSettlementResponse, encodeX402Response, extractPaymentFromHeaders, safeBase64Decode, safeBase64Encode, } from "./encoding/x402";
|
package/dist/index.js
CHANGED
|
@@ -190,14 +190,6 @@ var USDC_SKALE_BASE = {
|
|
|
190
190
|
chainId: 1187947933,
|
|
191
191
|
decimals: 6
|
|
192
192
|
};
|
|
193
|
-
var SKL_SKALE_BASE = {
|
|
194
|
-
symbol: "SKL",
|
|
195
|
-
name: "SKALE",
|
|
196
|
-
version: "1",
|
|
197
|
-
contractAddress: "0xE0595a049d02b7674572b0d59cd4880Db60EDC50",
|
|
198
|
-
chainId: 1187947933,
|
|
199
|
-
decimals: 18
|
|
200
|
-
};
|
|
201
193
|
var USDT_SKALE_BASE = {
|
|
202
194
|
symbol: "USDT",
|
|
203
195
|
name: "Tether USD",
|
|
@@ -270,7 +262,6 @@ var TOKENS = {
|
|
|
270
262
|
USDT_SKALE_BASE,
|
|
271
263
|
WBTC_SKALE_BASE,
|
|
272
264
|
WETH_SKALE_BASE,
|
|
273
|
-
SKL_SKALE_BASE,
|
|
274
265
|
SKL_SKALE_BASE_SEPOLIA,
|
|
275
266
|
USDC_SKALE_BASE_SEPOLIA,
|
|
276
267
|
USDT_SKALE_BASE_SEPOLIA,
|
|
@@ -313,6 +304,209 @@ function getWETHTokens() {
|
|
|
313
304
|
return getTokensBySymbol("WETH");
|
|
314
305
|
}
|
|
315
306
|
|
|
307
|
+
// src/types/networks.ts
|
|
308
|
+
var isEvmAddress = (value) => /^0x[a-fA-F0-9]{40}$/.test(value);
|
|
309
|
+
var tokenKey = (chainId, contractAddress) => `${chainId}:${contractAddress.toLowerCase()}`;
|
|
310
|
+
var tokenRegistry = /* @__PURE__ */ new Map([
|
|
311
|
+
[tokenKey(8453, "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"), {
|
|
312
|
+
symbol: "USDC",
|
|
313
|
+
name: "USDC",
|
|
314
|
+
version: "2",
|
|
315
|
+
contractAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
316
|
+
chainId: 8453,
|
|
317
|
+
decimals: 6
|
|
318
|
+
}],
|
|
319
|
+
[tokenKey(84532, "0x036CbD53842c5426634e7929541eC2318f3dCF7e"), {
|
|
320
|
+
symbol: "USDC",
|
|
321
|
+
name: "USDC",
|
|
322
|
+
version: "2",
|
|
323
|
+
contractAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
324
|
+
chainId: 84532,
|
|
325
|
+
decimals: 6
|
|
326
|
+
}],
|
|
327
|
+
[tokenKey(8453, "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"), {
|
|
328
|
+
symbol: "EURC",
|
|
329
|
+
name: "EURC",
|
|
330
|
+
version: "2",
|
|
331
|
+
contractAddress: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
|
|
332
|
+
chainId: 8453,
|
|
333
|
+
decimals: 6
|
|
334
|
+
}],
|
|
335
|
+
[tokenKey(1187947933, "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20"), {
|
|
336
|
+
symbol: "USDC",
|
|
337
|
+
name: "USDC",
|
|
338
|
+
version: "2",
|
|
339
|
+
contractAddress: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
|
|
340
|
+
chainId: 1187947933,
|
|
341
|
+
decimals: 6
|
|
342
|
+
}],
|
|
343
|
+
[tokenKey(1187947933, "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA"), {
|
|
344
|
+
symbol: "USDT",
|
|
345
|
+
name: "USDT",
|
|
346
|
+
version: "1",
|
|
347
|
+
contractAddress: "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA",
|
|
348
|
+
chainId: 1187947933,
|
|
349
|
+
decimals: 6
|
|
350
|
+
}],
|
|
351
|
+
[tokenKey(1187947933, "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e"), {
|
|
352
|
+
symbol: "WBTC",
|
|
353
|
+
name: "Wrapped BTC",
|
|
354
|
+
version: "1",
|
|
355
|
+
contractAddress: "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e",
|
|
356
|
+
chainId: 1187947933,
|
|
357
|
+
decimals: 8
|
|
358
|
+
}],
|
|
359
|
+
[tokenKey(1187947933, "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486"), {
|
|
360
|
+
symbol: "WETH",
|
|
361
|
+
name: "Wrapped Ether",
|
|
362
|
+
version: "1",
|
|
363
|
+
contractAddress: "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486",
|
|
364
|
+
chainId: 1187947933,
|
|
365
|
+
decimals: 6
|
|
366
|
+
}],
|
|
367
|
+
[tokenKey(324705682, "0xaf2e0ff5b5f51553fdb34ce7f04a6c3201cee57b"), {
|
|
368
|
+
symbol: "SKL",
|
|
369
|
+
name: "SKALE",
|
|
370
|
+
version: "1",
|
|
371
|
+
contractAddress: "0xaf2e0ff5b5f51553fdb34ce7f04a6c3201cee57b",
|
|
372
|
+
chainId: 324705682,
|
|
373
|
+
decimals: 18
|
|
374
|
+
}],
|
|
375
|
+
[tokenKey(324705682, "0x036CbD53842c5426634e7929541eC2318f3dCF7e"), {
|
|
376
|
+
symbol: "USDC",
|
|
377
|
+
name: "USDC",
|
|
378
|
+
version: "2",
|
|
379
|
+
contractAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
380
|
+
chainId: 324705682,
|
|
381
|
+
decimals: 6
|
|
382
|
+
}],
|
|
383
|
+
[tokenKey(324705682, "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf"), {
|
|
384
|
+
symbol: "USDT",
|
|
385
|
+
name: "USDT",
|
|
386
|
+
version: "1",
|
|
387
|
+
contractAddress: "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf",
|
|
388
|
+
chainId: 324705682,
|
|
389
|
+
decimals: 6
|
|
390
|
+
}],
|
|
391
|
+
[tokenKey(324705682, "0x4512eacd4186b025186e1cf6cc0d89497c530e87"), {
|
|
392
|
+
symbol: "WBTC",
|
|
393
|
+
name: "Wrapped BTC",
|
|
394
|
+
version: "1",
|
|
395
|
+
contractAddress: "0x4512eacd4186b025186e1cf6cc0d89497c530e87",
|
|
396
|
+
chainId: 324705682,
|
|
397
|
+
decimals: 8
|
|
398
|
+
}],
|
|
399
|
+
[tokenKey(324705682, "0xf94056bd7f6965db3757e1b145f200b7346b4fc0"), {
|
|
400
|
+
symbol: "WETH",
|
|
401
|
+
name: "Wrapped Ether",
|
|
402
|
+
version: "1",
|
|
403
|
+
contractAddress: "0xf94056bd7f6965db3757e1b145f200b7346b4fc0",
|
|
404
|
+
chainId: 324705682,
|
|
405
|
+
decimals: 18
|
|
406
|
+
}]
|
|
407
|
+
]);
|
|
408
|
+
var NETWORKS = {
|
|
409
|
+
ethereum: {
|
|
410
|
+
name: "Ethereum Mainnet",
|
|
411
|
+
chainId: 1,
|
|
412
|
+
usdcAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
413
|
+
rpcUrl: "https://eth.llamarpc.com",
|
|
414
|
+
caip2Id: "eip155:1",
|
|
415
|
+
caipAssetId: "eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
416
|
+
},
|
|
417
|
+
base: {
|
|
418
|
+
name: "Base Mainnet",
|
|
419
|
+
chainId: 8453,
|
|
420
|
+
usdcAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
421
|
+
rpcUrl: "https://mainnet.base.org",
|
|
422
|
+
caip2Id: "eip155:8453",
|
|
423
|
+
caipAssetId: "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
424
|
+
},
|
|
425
|
+
"base-sepolia": {
|
|
426
|
+
name: "Base Sepolia",
|
|
427
|
+
chainId: 84532,
|
|
428
|
+
usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
429
|
+
rpcUrl: "https://sepolia.base.org",
|
|
430
|
+
caip2Id: "eip155:84532",
|
|
431
|
+
caipAssetId: "eip155:84532/erc20:0x036CbD53842c5426634e7929541eC2318f3dCF7e"
|
|
432
|
+
},
|
|
433
|
+
"skale-base": {
|
|
434
|
+
name: "SKALE Base",
|
|
435
|
+
chainId: 1187947933,
|
|
436
|
+
usdcAddress: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
|
|
437
|
+
rpcUrl: "https://skale-base.skalenodes.com/v1/base",
|
|
438
|
+
caip2Id: "eip155:1187947933",
|
|
439
|
+
caipAssetId: "eip155:1187947933/erc20:0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20"
|
|
440
|
+
},
|
|
441
|
+
"skale-base-sepolia": {
|
|
442
|
+
name: "SKALE Base Sepolia",
|
|
443
|
+
chainId: 324705682,
|
|
444
|
+
usdcAddress: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
|
|
445
|
+
rpcUrl: "https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha",
|
|
446
|
+
caip2Id: "eip155:324705682",
|
|
447
|
+
caipAssetId: "eip155:324705682/erc20:0x2e08028E3C4c2356572E096d8EF835cD5C6030bD"
|
|
448
|
+
},
|
|
449
|
+
"ethereum-sepolia": {
|
|
450
|
+
name: "Ethereum Sepolia",
|
|
451
|
+
chainId: 11155111,
|
|
452
|
+
usdcAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
|
|
453
|
+
rpcUrl: "https://rpc.sepolia.org",
|
|
454
|
+
caip2Id: "eip155:11155111",
|
|
455
|
+
caipAssetId: "eip155:11155111/erc20:0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
var getNetworkConfig = (name) => NETWORKS[name];
|
|
459
|
+
var getNetworkByChainId = (chainId) => Object.values(NETWORKS).find((c) => c.chainId === chainId);
|
|
460
|
+
var getMainnets = () => Object.values(NETWORKS).filter(
|
|
461
|
+
(c) => !c.name.toLowerCase().includes("sepolia")
|
|
462
|
+
);
|
|
463
|
+
var getTestnets = () => Object.values(NETWORKS).filter(
|
|
464
|
+
(c) => c.name.toLowerCase().includes("sepolia")
|
|
465
|
+
);
|
|
466
|
+
var registerToken = (token) => {
|
|
467
|
+
if (typeof token !== "object" || token === null) {
|
|
468
|
+
throw new Error("Invalid token: must be an object");
|
|
469
|
+
}
|
|
470
|
+
const t = token;
|
|
471
|
+
if (typeof t.symbol !== "string") {
|
|
472
|
+
throw new Error("Invalid token: symbol must be a string");
|
|
473
|
+
}
|
|
474
|
+
if (typeof t.name !== "string") {
|
|
475
|
+
throw new Error("Invalid token: name must be a string");
|
|
476
|
+
}
|
|
477
|
+
if (typeof t.version !== "string") {
|
|
478
|
+
throw new Error("Invalid token: version must be a string");
|
|
479
|
+
}
|
|
480
|
+
if (typeof t.contractAddress !== "string" || !isEvmAddress(t.contractAddress)) {
|
|
481
|
+
throw new Error(
|
|
482
|
+
"Invalid token: contractAddress must be a valid EVM address"
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
if (typeof t.chainId !== "number" || !Number.isInteger(t.chainId) || t.chainId <= 0) {
|
|
486
|
+
throw new Error("Invalid token: chainId must be a positive integer");
|
|
487
|
+
}
|
|
488
|
+
if (t.decimals !== void 0 && (typeof t.decimals !== "number" || !Number.isInteger(t.decimals) || t.decimals < 0)) {
|
|
489
|
+
throw new Error("Invalid token: decimals must be a non-negative integer");
|
|
490
|
+
}
|
|
491
|
+
const validated = {
|
|
492
|
+
symbol: t.symbol,
|
|
493
|
+
name: t.name,
|
|
494
|
+
version: t.version,
|
|
495
|
+
contractAddress: t.contractAddress,
|
|
496
|
+
chainId: t.chainId,
|
|
497
|
+
decimals: t.decimals
|
|
498
|
+
};
|
|
499
|
+
tokenRegistry.set(
|
|
500
|
+
tokenKey(validated.chainId, validated.contractAddress),
|
|
501
|
+
validated
|
|
502
|
+
);
|
|
503
|
+
return validated;
|
|
504
|
+
};
|
|
505
|
+
var getCustomToken = (chainId, contractAddress) => tokenRegistry.get(tokenKey(chainId, contractAddress));
|
|
506
|
+
var getAllCustomTokens = () => Array.from(tokenRegistry.values());
|
|
507
|
+
var unregisterToken = (chainId, contractAddress) => tokenRegistry.delete(tokenKey(chainId, contractAddress));
|
|
508
|
+
var isCustomToken = (chainId, contractAddress) => tokenRegistry.has(tokenKey(chainId, contractAddress));
|
|
509
|
+
|
|
316
510
|
// src/eip712.ts
|
|
317
511
|
var EIP712_TYPES = {
|
|
318
512
|
TransferWithAuthorization: [
|
|
@@ -324,16 +518,20 @@ var EIP712_TYPES = {
|
|
|
324
518
|
{ name: "nonce", type: "bytes32" }
|
|
325
519
|
]
|
|
326
520
|
};
|
|
327
|
-
var
|
|
328
|
-
|
|
329
|
-
|
|
521
|
+
var createEIP712Domain = (chainId, contractAddress) => {
|
|
522
|
+
const token = getCustomToken(chainId, contractAddress);
|
|
523
|
+
if (!token) {
|
|
524
|
+
throw new Error(
|
|
525
|
+
`Token not found in registry: chainId=${chainId}, contractAddress=${contractAddress}. Please register the token using registerToken() before use.`
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
name: token.name,
|
|
530
|
+
version: token.version,
|
|
531
|
+
chainId,
|
|
532
|
+
verifyingContract: contractAddress
|
|
533
|
+
};
|
|
330
534
|
};
|
|
331
|
-
var createEIP712Domain = (chainId, contractAddress) => ({
|
|
332
|
-
name: USDC_DOMAIN.NAME,
|
|
333
|
-
version: USDC_DOMAIN.VERSION,
|
|
334
|
-
chainId,
|
|
335
|
-
verifyingContract: contractAddress
|
|
336
|
-
});
|
|
337
535
|
var createTransferWithAuthorization = (params) => ({
|
|
338
536
|
from: params.from,
|
|
339
537
|
to: params.to,
|
|
@@ -726,112 +924,6 @@ function extractPayerAddress(payload) {
|
|
|
726
924
|
}
|
|
727
925
|
throw new Error("Unable to extract payer address from payload");
|
|
728
926
|
}
|
|
729
|
-
|
|
730
|
-
// src/types/networks.ts
|
|
731
|
-
var isEvmAddress = (value) => /^0x[a-fA-F0-9]{40}$/.test(value);
|
|
732
|
-
var tokenRegistry = /* @__PURE__ */ new Map();
|
|
733
|
-
var tokenKey = (chainId, contractAddress) => `${chainId}:${contractAddress.toLowerCase()}`;
|
|
734
|
-
var NETWORKS = {
|
|
735
|
-
ethereum: {
|
|
736
|
-
name: "Ethereum Mainnet",
|
|
737
|
-
chainId: 1,
|
|
738
|
-
usdcAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
739
|
-
rpcUrl: "https://eth.llamarpc.com",
|
|
740
|
-
caip2Id: "eip155:1",
|
|
741
|
-
caipAssetId: "eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
742
|
-
},
|
|
743
|
-
base: {
|
|
744
|
-
name: "Base Mainnet",
|
|
745
|
-
chainId: 8453,
|
|
746
|
-
usdcAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
747
|
-
rpcUrl: "https://mainnet.base.org",
|
|
748
|
-
caip2Id: "eip155:8453",
|
|
749
|
-
caipAssetId: "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
750
|
-
},
|
|
751
|
-
"base-sepolia": {
|
|
752
|
-
name: "Base Sepolia",
|
|
753
|
-
chainId: 84532,
|
|
754
|
-
usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
755
|
-
rpcUrl: "https://sepolia.base.org",
|
|
756
|
-
caip2Id: "eip155:84532",
|
|
757
|
-
caipAssetId: "eip155:84532/erc20:0x036CbD53842c5426634e7929541eC2318f3dCF7e"
|
|
758
|
-
},
|
|
759
|
-
"skale-base": {
|
|
760
|
-
name: "SKALE Base",
|
|
761
|
-
chainId: 1187947933,
|
|
762
|
-
usdcAddress: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
|
|
763
|
-
rpcUrl: "https://skale-base.skalenodes.com/v1/base",
|
|
764
|
-
caip2Id: "eip155:1187947933",
|
|
765
|
-
caipAssetId: "eip155:1187947933/erc20:0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20"
|
|
766
|
-
},
|
|
767
|
-
"skale-base-sepolia": {
|
|
768
|
-
name: "SKALE Base Sepolia",
|
|
769
|
-
chainId: 324705682,
|
|
770
|
-
usdcAddress: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
|
|
771
|
-
rpcUrl: "https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha",
|
|
772
|
-
caip2Id: "eip155:324705682",
|
|
773
|
-
caipAssetId: "eip155:324705682/erc20:0x2e08028E3C4c2356572E096d8EF835cD5C6030bD"
|
|
774
|
-
},
|
|
775
|
-
"ethereum-sepolia": {
|
|
776
|
-
name: "Ethereum Sepolia",
|
|
777
|
-
chainId: 11155111,
|
|
778
|
-
usdcAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
|
|
779
|
-
rpcUrl: "https://rpc.sepolia.org",
|
|
780
|
-
caip2Id: "eip155:11155111",
|
|
781
|
-
caipAssetId: "eip155:11155111/erc20:0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
|
|
782
|
-
}
|
|
783
|
-
};
|
|
784
|
-
var getNetworkConfig = (name) => NETWORKS[name];
|
|
785
|
-
var getNetworkByChainId = (chainId) => Object.values(NETWORKS).find((c) => c.chainId === chainId);
|
|
786
|
-
var getMainnets = () => Object.values(NETWORKS).filter(
|
|
787
|
-
(c) => !c.name.toLowerCase().includes("sepolia")
|
|
788
|
-
);
|
|
789
|
-
var getTestnets = () => Object.values(NETWORKS).filter(
|
|
790
|
-
(c) => c.name.toLowerCase().includes("sepolia")
|
|
791
|
-
);
|
|
792
|
-
var registerToken = (token) => {
|
|
793
|
-
if (typeof token !== "object" || token === null) {
|
|
794
|
-
throw new Error("Invalid token: must be an object");
|
|
795
|
-
}
|
|
796
|
-
const t = token;
|
|
797
|
-
if (typeof t.symbol !== "string") {
|
|
798
|
-
throw new Error("Invalid token: symbol must be a string");
|
|
799
|
-
}
|
|
800
|
-
if (typeof t.name !== "string") {
|
|
801
|
-
throw new Error("Invalid token: name must be a string");
|
|
802
|
-
}
|
|
803
|
-
if (typeof t.version !== "string") {
|
|
804
|
-
throw new Error("Invalid token: version must be a string");
|
|
805
|
-
}
|
|
806
|
-
if (typeof t.contractAddress !== "string" || !isEvmAddress(t.contractAddress)) {
|
|
807
|
-
throw new Error(
|
|
808
|
-
"Invalid token: contractAddress must be a valid EVM address"
|
|
809
|
-
);
|
|
810
|
-
}
|
|
811
|
-
if (typeof t.chainId !== "number" || !Number.isInteger(t.chainId) || t.chainId <= 0) {
|
|
812
|
-
throw new Error("Invalid token: chainId must be a positive integer");
|
|
813
|
-
}
|
|
814
|
-
if (t.decimals !== void 0 && (typeof t.decimals !== "number" || !Number.isInteger(t.decimals) || t.decimals < 0)) {
|
|
815
|
-
throw new Error("Invalid token: decimals must be a non-negative integer");
|
|
816
|
-
}
|
|
817
|
-
const validated = {
|
|
818
|
-
symbol: t.symbol,
|
|
819
|
-
name: t.name,
|
|
820
|
-
version: t.version,
|
|
821
|
-
contractAddress: t.contractAddress,
|
|
822
|
-
chainId: t.chainId,
|
|
823
|
-
decimals: t.decimals
|
|
824
|
-
};
|
|
825
|
-
tokenRegistry.set(
|
|
826
|
-
tokenKey(validated.chainId, validated.contractAddress),
|
|
827
|
-
validated
|
|
828
|
-
);
|
|
829
|
-
return validated;
|
|
830
|
-
};
|
|
831
|
-
var getCustomToken = (chainId, contractAddress) => tokenRegistry.get(tokenKey(chainId, contractAddress));
|
|
832
|
-
var getAllCustomTokens = () => Array.from(tokenRegistry.values());
|
|
833
|
-
var unregisterToken = (chainId, contractAddress) => tokenRegistry.delete(tokenKey(chainId, contractAddress));
|
|
834
|
-
var isCustomToken = (chainId, contractAddress) => tokenRegistry.has(tokenKey(chainId, contractAddress));
|
|
835
927
|
function createNonce() {
|
|
836
928
|
const bytes = randomBytes(32);
|
|
837
929
|
return `0x${bytes.toString("hex")}`;
|
|
@@ -1369,7 +1461,7 @@ var isResolvedToken = (value) => {
|
|
|
1369
1461
|
|
|
1370
1462
|
// src/payment-requirements.ts
|
|
1371
1463
|
function resolveAmountForNetwork(config, network) {
|
|
1372
|
-
const defaultAmount = config.amount ?? "
|
|
1464
|
+
const defaultAmount = config.amount ?? "0.01";
|
|
1373
1465
|
if (!config.amounts) {
|
|
1374
1466
|
return defaultAmount;
|
|
1375
1467
|
}
|
|
@@ -1933,4 +2025,4 @@ function validateRouteConfig(config) {
|
|
|
1933
2025
|
return null;
|
|
1934
2026
|
}
|
|
1935
2027
|
|
|
1936
|
-
export { EIP712_TYPES, ERC20_ABI, EURC_BASE, NETWORKS, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PAYMENT_SIGNATURE_HEADER, PaymentException, SCHEMES,
|
|
2028
|
+
export { EIP712_TYPES, ERC20_ABI, EURC_BASE, NETWORKS, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PAYMENT_SIGNATURE_HEADER, PaymentException, SCHEMES, SKL_SKALE_BASE_SEPOLIA, SigningError, TOKENS, USDC_BASE, USDC_BASE_SEPOLIA, USDC_SKALE_BASE, USDC_SKALE_BASE_SEPOLIA, USDT_SKALE_BASE, USDT_SKALE_BASE_SEPOLIA, V2_HEADERS, WBTC_SKALE_BASE, WBTC_SKALE_BASE_SEPOLIA, WETH_SKALE_BASE, WETH_SKALE_BASE_SEPOLIA, X402ClientError, X402_VERSION, addressToAssetId, assetIdToAddress, caip2ToNetwork, calculateValidBefore, checkFacilitatorSupport, clearFacilitatorCapabilityCache, combineSignature as combineSignatureV2, createEIP712Domain, createError, createNonce, createPaymentRequiredHeaders, createPaymentRequirements, createSettlementHeaders, createTransferWithAuthorization, decodeBase64ToUtf8, decodePayloadHeader, decodePayment, decodePaymentV2, decodeSettlementResponse, decodeSettlementV2, decodeX402Response, detectPaymentVersion, detectX402Version, encodePayment, encodePaymentV2, encodeSettlementResponse, encodeSettlementV2, encodeUtf8ToBase64, encodeX402Response, enrichPaymentRequirement, enrichPaymentRequirements, extractPayerAddress, extractPaymentFromHeaders, filterExtensionsForFacilitator, filterExtensionsForFacilitators, filterExtensionsForRequirements, findMatchingRoute, findRequirementByAccepted, findRequirementByNetwork, fromAtomicUnits, generateNonce, getAllCustomTokens, getAllTokens, getAvailableNetworks, getAvailableTokens, getCurrentTimestamp, getCustomToken, getEURCTokens, getMainnets, getNetworkByChainId, getNetworkConfig, getPaymentHeaderName, getSKLTokens, getSupported, getTestnets, getToken, getTokensByChain, getTokensBySymbol, getTxHash, getUSDCTokens, getUSDTTokens, getWBTCTokens, getWETHTokens, isAddress2 as isAddress, isCAIP2ChainId, isCAIPAssetId, isCustomToken, isExactEvmPayload, isPaymentPayload, isPaymentPayloadV2, isPaymentRequiredV2, isPaymentV2, isResolvedNetwork, isResolvedToken, isSettlementSuccessful, isSettlementV2, isValidAddress, isValidationError, isX402V2Payload, isX402V2PaymentRequired, isX402V2Requirements, isX402V2Settlement, matchRoute, networkToCaip2, normalizeAddress, normalizeBase64Url, normalizeNetworkName, parseJsonOrBase64, parseRoutePattern, parseSignature as parseSignatureV2, registerToken, resolveFacilitator, resolveFacilitatorUrlFromRequirement, resolveNetwork, resolveToken, runAfterPaymentResponseHooks, runBeforeSignPaymentHooks, runOnPaymentRequiredHooks, safeBase64Decode2 as safeBase64Decode, safeBase64Encode2 as safeBase64Encode, selectRequirementWithHooks, settlePayment, toAtomicUnits, toBase64Url, unregisterToken, validateAcceptConfig, validatePaymentConfig, validateRouteConfig, validateTransferWithAuthorization, verifyPayment };
|
package/package.json
CHANGED
package/src/data/tokens.ts
CHANGED
|
@@ -40,16 +40,6 @@ export const USDC_SKALE_BASE: CustomToken = {
|
|
|
40
40
|
decimals: 6,
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
export const SKL_SKALE_BASE: CustomToken = {
|
|
44
|
-
symbol: "SKL",
|
|
45
|
-
name: "SKALE",
|
|
46
|
-
version: "1",
|
|
47
|
-
contractAddress:
|
|
48
|
-
"0xE0595a049d02b7674572b0d59cd4880Db60EDC50" as `0x${string}`,
|
|
49
|
-
chainId: 1187947933,
|
|
50
|
-
decimals: 18,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
43
|
export const USDT_SKALE_BASE: CustomToken = {
|
|
54
44
|
symbol: "USDT",
|
|
55
45
|
name: "Tether USD",
|
|
@@ -138,7 +128,6 @@ export const TOKENS = {
|
|
|
138
128
|
USDT_SKALE_BASE,
|
|
139
129
|
WBTC_SKALE_BASE,
|
|
140
130
|
WETH_SKALE_BASE,
|
|
141
|
-
SKL_SKALE_BASE,
|
|
142
131
|
SKL_SKALE_BASE_SEPOLIA,
|
|
143
132
|
USDC_SKALE_BASE_SEPOLIA,
|
|
144
133
|
USDT_SKALE_BASE_SEPOLIA,
|
package/src/eip712.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { CustomToken } from "./types/networks";
|
|
2
|
+
import { getCustomToken } from "./types/networks";
|
|
3
|
+
|
|
1
4
|
export type TypedDataDomain = {
|
|
2
5
|
name?: string;
|
|
3
6
|
version?: string;
|
|
@@ -42,20 +45,26 @@ export const EIP712_TYPES = {
|
|
|
42
45
|
] as const,
|
|
43
46
|
} as const satisfies EIP712Types;
|
|
44
47
|
|
|
45
|
-
export const USDC_DOMAIN = {
|
|
46
|
-
NAME: "USD Coin",
|
|
47
|
-
VERSION: "2",
|
|
48
|
-
} as const;
|
|
49
|
-
|
|
50
48
|
export const createEIP712Domain = (
|
|
51
49
|
chainId: number,
|
|
52
50
|
contractAddress: `0x${string}`,
|
|
53
|
-
): EIP712Domain =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
51
|
+
): EIP712Domain => {
|
|
52
|
+
const token = getCustomToken(chainId, contractAddress);
|
|
53
|
+
|
|
54
|
+
if (!token) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Token not found in registry: chainId=${chainId}, contractAddress=${contractAddress}. ` +
|
|
57
|
+
`Please register the token using registerToken() before use.`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
name: token.name,
|
|
63
|
+
version: token.version,
|
|
64
|
+
chainId,
|
|
65
|
+
verifyingContract: contractAddress,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
59
68
|
|
|
60
69
|
export const createTransferWithAuthorization = (
|
|
61
70
|
params: Omit<
|
package/src/index.ts
CHANGED
|
@@ -33,7 +33,6 @@ export {
|
|
|
33
33
|
getUSDTTokens,
|
|
34
34
|
getWBTCTokens,
|
|
35
35
|
getWETHTokens,
|
|
36
|
-
SKL_SKALE_BASE,
|
|
37
36
|
SKL_SKALE_BASE_SEPOLIA,
|
|
38
37
|
TOKENS,
|
|
39
38
|
USDC_BASE,
|
|
@@ -61,7 +60,6 @@ export {
|
|
|
61
60
|
createEIP712Domain,
|
|
62
61
|
createTransferWithAuthorization,
|
|
63
62
|
EIP712_TYPES,
|
|
64
|
-
USDC_DOMAIN,
|
|
65
63
|
validateTransferWithAuthorization,
|
|
66
64
|
} from "./eip712";
|
|
67
65
|
// ============================================
|
package/src/types/networks.ts
CHANGED
|
@@ -19,10 +19,109 @@ export interface CustomToken {
|
|
|
19
19
|
decimals?: number;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const tokenRegistry = new Map<string, CustomToken>();
|
|
23
22
|
const tokenKey = (chainId: number, contractAddress: string): string =>
|
|
24
23
|
`${chainId}:${contractAddress.toLowerCase()}`;
|
|
25
24
|
|
|
25
|
+
// Built-in tokens - hardcoded in registry
|
|
26
|
+
const tokenRegistry = new Map<string, CustomToken>([
|
|
27
|
+
[tokenKey(8453, "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"), {
|
|
28
|
+
symbol: "USDC",
|
|
29
|
+
name: "USDC",
|
|
30
|
+
version: "2",
|
|
31
|
+
contractAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" as `0x${string}`,
|
|
32
|
+
chainId: 8453,
|
|
33
|
+
decimals: 6,
|
|
34
|
+
}],
|
|
35
|
+
[tokenKey(84532, "0x036CbD53842c5426634e7929541eC2318f3dCF7e"), {
|
|
36
|
+
symbol: "USDC",
|
|
37
|
+
name: "USDC",
|
|
38
|
+
version: "2",
|
|
39
|
+
contractAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e" as `0x${string}`,
|
|
40
|
+
chainId: 84532,
|
|
41
|
+
decimals: 6,
|
|
42
|
+
}],
|
|
43
|
+
[tokenKey(8453, "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"), {
|
|
44
|
+
symbol: "EURC",
|
|
45
|
+
name: "EURC",
|
|
46
|
+
version: "2",
|
|
47
|
+
contractAddress: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42" as `0x${string}`,
|
|
48
|
+
chainId: 8453,
|
|
49
|
+
decimals: 6,
|
|
50
|
+
}],
|
|
51
|
+
[tokenKey(1187947933, "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20"), {
|
|
52
|
+
symbol: "USDC",
|
|
53
|
+
name: "USDC",
|
|
54
|
+
version: "2",
|
|
55
|
+
contractAddress: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20" as `0x${string}`,
|
|
56
|
+
chainId: 1187947933,
|
|
57
|
+
decimals: 6,
|
|
58
|
+
}],
|
|
59
|
+
[tokenKey(1187947933, "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA"), {
|
|
60
|
+
symbol: "USDT",
|
|
61
|
+
name: "USDT",
|
|
62
|
+
version: "1",
|
|
63
|
+
contractAddress: "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA" as `0x${string}`,
|
|
64
|
+
chainId: 1187947933,
|
|
65
|
+
decimals: 6,
|
|
66
|
+
}],
|
|
67
|
+
[tokenKey(1187947933, "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e"), {
|
|
68
|
+
symbol: "WBTC",
|
|
69
|
+
name: "Wrapped BTC",
|
|
70
|
+
version: "1",
|
|
71
|
+
contractAddress: "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e" as `0x${string}`,
|
|
72
|
+
chainId: 1187947933,
|
|
73
|
+
decimals: 8,
|
|
74
|
+
}],
|
|
75
|
+
[tokenKey(1187947933, "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486"), {
|
|
76
|
+
symbol: "WETH",
|
|
77
|
+
name: "Wrapped Ether",
|
|
78
|
+
version: "1",
|
|
79
|
+
contractAddress: "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486" as `0x${string}`,
|
|
80
|
+
chainId: 1187947933,
|
|
81
|
+
decimals: 6,
|
|
82
|
+
}],
|
|
83
|
+
[tokenKey(324705682, "0xaf2e0ff5b5f51553fdb34ce7f04a6c3201cee57b"), {
|
|
84
|
+
symbol: "SKL",
|
|
85
|
+
name: "SKALE",
|
|
86
|
+
version: "1",
|
|
87
|
+
contractAddress: "0xaf2e0ff5b5f51553fdb34ce7f04a6c3201cee57b" as `0x${string}`,
|
|
88
|
+
chainId: 324705682,
|
|
89
|
+
decimals: 18,
|
|
90
|
+
}],
|
|
91
|
+
[tokenKey(324705682, "0x036CbD53842c5426634e7929541eC2318f3dCF7e"), {
|
|
92
|
+
symbol: "USDC",
|
|
93
|
+
name: "USDC",
|
|
94
|
+
version: "2",
|
|
95
|
+
contractAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e" as `0x${string}`,
|
|
96
|
+
chainId: 324705682,
|
|
97
|
+
decimals: 6,
|
|
98
|
+
}],
|
|
99
|
+
[tokenKey(324705682, "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf"), {
|
|
100
|
+
symbol: "USDT",
|
|
101
|
+
name: "USDT",
|
|
102
|
+
version: "1",
|
|
103
|
+
contractAddress: "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf" as `0x${string}`,
|
|
104
|
+
chainId: 324705682,
|
|
105
|
+
decimals: 6,
|
|
106
|
+
}],
|
|
107
|
+
[tokenKey(324705682, "0x4512eacd4186b025186e1cf6cc0d89497c530e87"), {
|
|
108
|
+
symbol: "WBTC",
|
|
109
|
+
name: "Wrapped BTC",
|
|
110
|
+
version: "1",
|
|
111
|
+
contractAddress: "0x4512eacd4186b025186e1cf6cc0d89497c530e87" as `0x${string}`,
|
|
112
|
+
chainId: 324705682,
|
|
113
|
+
decimals: 8,
|
|
114
|
+
}],
|
|
115
|
+
[tokenKey(324705682, "0xf94056bd7f6965db3757e1b145f200b7346b4fc0"), {
|
|
116
|
+
symbol: "WETH",
|
|
117
|
+
name: "Wrapped Ether",
|
|
118
|
+
version: "1",
|
|
119
|
+
contractAddress: "0xf94056bd7f6965db3757e1b145f200b7346b4fc0" as `0x${string}`,
|
|
120
|
+
chainId: 324705682,
|
|
121
|
+
decimals: 18,
|
|
122
|
+
}],
|
|
123
|
+
]);
|
|
124
|
+
|
|
26
125
|
export const NETWORKS: Record<string, NetworkConfig> = {
|
|
27
126
|
ethereum: {
|
|
28
127
|
name: "Ethereum Mainnet",
|