@relai-fi/x402 0.5.17 → 0.5.19
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/client.cjs +224 -36
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +224 -36
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +113 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +113 -47
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +228 -38
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +228 -38
- package/dist/react/index.js.map +1 -1
- package/dist/server.cjs +15 -8
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +15 -8
- package/dist/server.js.map +1 -1
- package/dist/{types-CWtUxi3l.d.cts → types-BSCuAZJb.d.cts} +2 -1
- package/dist/{types-CWtUxi3l.d.ts → types-BSCuAZJb.d.ts} +2 -1
- package/dist/utils/index.cjs +5 -3
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js +5 -3
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -68,7 +68,8 @@ var NETWORK_CAIP2 = {
|
|
|
68
68
|
"skale-base-sepolia": "eip155:324705682",
|
|
69
69
|
"skale-bite": "eip155:103698795",
|
|
70
70
|
"polygon": "eip155:137",
|
|
71
|
-
"ethereum": "eip155:1"
|
|
71
|
+
"ethereum": "eip155:1",
|
|
72
|
+
"telos": "eip155:40"
|
|
72
73
|
};
|
|
73
74
|
var CAIP2_TO_NETWORK = Object.fromEntries(
|
|
74
75
|
Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k])
|
|
@@ -80,7 +81,8 @@ var CHAIN_IDS = {
|
|
|
80
81
|
"skale-base-sepolia": 324705682,
|
|
81
82
|
"skale-bite": 103698795,
|
|
82
83
|
"polygon": 137,
|
|
83
|
-
"ethereum": 1
|
|
84
|
+
"ethereum": 1,
|
|
85
|
+
"telos": 40
|
|
84
86
|
};
|
|
85
87
|
var NETWORK_TOKENS = {
|
|
86
88
|
"solana": [
|
|
@@ -92,12 +94,7 @@ var NETWORK_TOKENS = {
|
|
|
92
94
|
}
|
|
93
95
|
],
|
|
94
96
|
"base": [
|
|
95
|
-
{ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", symbol: "USDC", name: "USD Coin", decimals: 6, domainVersion: "2", isStableUsd: true }
|
|
96
|
-
{ address: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2", symbol: "USDT", name: "Tether USD", decimals: 6, domainVersion: "1", isStableUsd: true },
|
|
97
|
-
{ address: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42", symbol: "EURC", name: "Euro Coin", decimals: 6, domainVersion: "2", isStableUsd: false },
|
|
98
|
-
{ address: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb", symbol: "DAI", name: "Dai Stablecoin", decimals: 18, domainVersion: "1", isStableUsd: true },
|
|
99
|
-
{ address: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22", symbol: "cbETH", name: "Coinbase Wrapped Ether", decimals: 18, domainVersion: "1", isStableUsd: false },
|
|
100
|
-
{ address: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf", symbol: "cbBTC", name: "Coinbase Wrapped BTC", decimals: 8, domainVersion: "1", isStableUsd: false }
|
|
97
|
+
{ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", symbol: "USDC", name: "USD Coin", decimals: 6, domainVersion: "2", isStableUsd: true }
|
|
101
98
|
],
|
|
102
99
|
"avalanche": [
|
|
103
100
|
{
|
|
@@ -109,6 +106,16 @@ var NETWORK_TOKENS = {
|
|
|
109
106
|
isStableUsd: true
|
|
110
107
|
}
|
|
111
108
|
],
|
|
109
|
+
"telos": [
|
|
110
|
+
{
|
|
111
|
+
address: "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b",
|
|
112
|
+
symbol: "USDC",
|
|
113
|
+
name: "USD Coin",
|
|
114
|
+
decimals: 6,
|
|
115
|
+
isStableUsd: true,
|
|
116
|
+
standards: ["eip2612"]
|
|
117
|
+
}
|
|
118
|
+
],
|
|
112
119
|
"skale-base": [
|
|
113
120
|
{
|
|
114
121
|
address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
|
|
@@ -223,7 +230,8 @@ var USDC_ADDRESSES = {
|
|
|
223
230
|
"skale-base-sepolia": "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
|
|
224
231
|
"skale-bite": "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
|
|
225
232
|
"polygon": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
226
|
-
"ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
233
|
+
"ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
234
|
+
"telos": "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b"
|
|
227
235
|
};
|
|
228
236
|
var EXPLORER_TX_URL = {
|
|
229
237
|
"solana": (tx) => `https://solscan.io/tx/${tx}`,
|
|
@@ -233,7 +241,8 @@ var EXPLORER_TX_URL = {
|
|
|
233
241
|
"skale-base-sepolia": (tx) => `https://base-sepolia-testnet-explorer.skalenodes.com/tx/${tx}`,
|
|
234
242
|
"skale-bite": (tx) => `https://base-sepolia-testnet.explorer.skalenodes.com/tx/${tx}`,
|
|
235
243
|
"polygon": (tx) => `https://polygonscan.com/tx/${tx}`,
|
|
236
|
-
"ethereum": (tx) => `https://etherscan.io/tx/${tx}
|
|
244
|
+
"ethereum": (tx) => `https://etherscan.io/tx/${tx}`,
|
|
245
|
+
"telos": (tx) => `https://teloscan.io/tx/${tx}`
|
|
237
246
|
};
|
|
238
247
|
var NETWORK_LABELS = {
|
|
239
248
|
"solana": "Solana",
|
|
@@ -243,7 +252,8 @@ var NETWORK_LABELS = {
|
|
|
243
252
|
"skale-base-sepolia": "SKALE Base Sepolia",
|
|
244
253
|
"skale-bite": "SKALE BITE V2",
|
|
245
254
|
"polygon": "Polygon",
|
|
246
|
-
"ethereum": "Ethereum"
|
|
255
|
+
"ethereum": "Ethereum",
|
|
256
|
+
"telos": "Telos EVM"
|
|
247
257
|
};
|
|
248
258
|
var SOLANA_MAINNET_NETWORK = NETWORK_CAIP2["solana"];
|
|
249
259
|
var BASE_MAINNET_NETWORK = NETWORK_CAIP2["base"];
|
|
@@ -257,13 +267,14 @@ var RELAI_NETWORKS = [
|
|
|
257
267
|
"skale-base-sepolia",
|
|
258
268
|
"skale-bite",
|
|
259
269
|
"polygon",
|
|
260
|
-
"ethereum"
|
|
270
|
+
"ethereum",
|
|
271
|
+
"telos"
|
|
261
272
|
];
|
|
262
273
|
function isSolana(network) {
|
|
263
274
|
return network === "solana" || network.startsWith("solana:");
|
|
264
275
|
}
|
|
265
276
|
function isEvm(network) {
|
|
266
|
-
return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum"].includes(network) || network.startsWith("eip155:");
|
|
277
|
+
return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum", "telos"].includes(network) || network.startsWith("eip155:");
|
|
267
278
|
}
|
|
268
279
|
function normalizeNetwork(network) {
|
|
269
280
|
if (RELAI_NETWORKS.includes(network)) return network;
|
|
@@ -745,7 +756,8 @@ var DEFAULT_EVM_RPC_URLS = {
|
|
|
745
756
|
"base": "https://mainnet.base.org",
|
|
746
757
|
"avalanche": "https://api.avax.network/ext/bc/C/rpc",
|
|
747
758
|
"polygon": "https://polygon-rpc.com",
|
|
748
|
-
"ethereum": "https://ethereum-rpc.publicnode.com"
|
|
759
|
+
"ethereum": "https://ethereum-rpc.publicnode.com",
|
|
760
|
+
"telos": "https://rpc.telos.net"
|
|
749
761
|
};
|
|
750
762
|
function createX402Client(config) {
|
|
751
763
|
const {
|
|
@@ -1354,41 +1366,93 @@ function createX402Client(config) {
|
|
|
1354
1366
|
chainId,
|
|
1355
1367
|
verifyingContract: useRelayer ? extra.relayerContract : accept.asset
|
|
1356
1368
|
};
|
|
1357
|
-
const
|
|
1358
|
-
const
|
|
1359
|
-
const
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1369
|
+
const tokenNetworkKey = network || rawNetwork;
|
|
1370
|
+
const networkTokens = NETWORK_TOKENS[tokenNetworkKey];
|
|
1371
|
+
const assetLower = (accept.asset || "").toLowerCase();
|
|
1372
|
+
const tokenInfo = networkTokens?.find((t) => t.address.toLowerCase() === assetLower) || networkTokens?.[0];
|
|
1373
|
+
const tokenStandards = Array.isArray(tokenInfo?.standards) ? tokenInfo.standards : [];
|
|
1374
|
+
const hasEip3009 = tokenStandards.some((s) => s.toLowerCase() === "eip3009");
|
|
1375
|
+
const hasEip2612 = tokenStandards.some((s) => s.toLowerCase() === "eip2612");
|
|
1376
|
+
const usePermit2612 = !hasEip3009 && hasEip2612;
|
|
1377
|
+
let message;
|
|
1378
|
+
let signature;
|
|
1379
|
+
let authorizationScheme;
|
|
1380
|
+
if (usePermit2612) {
|
|
1381
|
+
const spender = extra.feePayer || accept.payTo;
|
|
1382
|
+
const deadline = Math.floor(Date.now() / 1e3) + 3600;
|
|
1383
|
+
let nonce = 0;
|
|
1384
|
+
if (rpcUrl) {
|
|
1385
|
+
try {
|
|
1386
|
+
const paddedAddress = evmWallet.address.toLowerCase().replace("0x", "").padStart(64, "0");
|
|
1387
|
+
const nonceHex = await evmRpcCall(rpcUrl, accept.asset, "0x7ecebe00" + paddedAddress);
|
|
1388
|
+
nonce = nonceHex ? parseInt(nonceHex, 16) : 0;
|
|
1389
|
+
} catch {
|
|
1390
|
+
nonce = 0;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
const permitTypes = {
|
|
1394
|
+
Permit: [
|
|
1395
|
+
{ name: "owner", type: "address" },
|
|
1396
|
+
{ name: "spender", type: "address" },
|
|
1397
|
+
{ name: "value", type: "uint256" },
|
|
1398
|
+
{ name: "nonce", type: "uint256" },
|
|
1399
|
+
{ name: "deadline", type: "uint256" }
|
|
1400
|
+
]
|
|
1401
|
+
};
|
|
1402
|
+
message = {
|
|
1403
|
+
owner: evmWallet.address,
|
|
1404
|
+
spender,
|
|
1405
|
+
value: paymentAmount,
|
|
1406
|
+
nonce: String(nonce),
|
|
1407
|
+
deadline: String(deadline)
|
|
1408
|
+
};
|
|
1409
|
+
log("Signing EIP-2612 permit on chain", chainId);
|
|
1410
|
+
signature = await evmWallet.signTypedData({
|
|
1411
|
+
domain,
|
|
1412
|
+
types: permitTypes,
|
|
1413
|
+
message,
|
|
1414
|
+
primaryType: "Permit"
|
|
1415
|
+
});
|
|
1416
|
+
authorizationScheme = "eip2612";
|
|
1417
|
+
} else {
|
|
1418
|
+
const validAfter = 0;
|
|
1419
|
+
const validBefore = Math.floor(Date.now() / 1e3) + 3600;
|
|
1420
|
+
const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1421
|
+
const transferTypes = {
|
|
1422
|
+
TransferWithAuthorization: [
|
|
1423
|
+
{ name: "from", type: "address" },
|
|
1424
|
+
{ name: "to", type: "address" },
|
|
1425
|
+
{ name: "value", type: "uint256" },
|
|
1426
|
+
{ name: "validAfter", type: "uint256" },
|
|
1427
|
+
{ name: "validBefore", type: "uint256" },
|
|
1428
|
+
{ name: "nonce", type: "bytes32" }
|
|
1429
|
+
]
|
|
1430
|
+
};
|
|
1431
|
+
message = {
|
|
1432
|
+
from: evmWallet.address,
|
|
1433
|
+
to: accept.payTo,
|
|
1434
|
+
value: paymentAmount,
|
|
1435
|
+
validAfter: String(validAfter),
|
|
1436
|
+
validBefore: String(validBefore),
|
|
1437
|
+
nonce
|
|
1438
|
+
};
|
|
1439
|
+
log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
|
|
1440
|
+
signature = await evmWallet.signTypedData({
|
|
1441
|
+
domain,
|
|
1442
|
+
types: transferTypes,
|
|
1443
|
+
message,
|
|
1444
|
+
primaryType: "TransferWithAuthorization"
|
|
1445
|
+
});
|
|
1446
|
+
authorizationScheme = "eip3009";
|
|
1447
|
+
}
|
|
1385
1448
|
const paymentPayload = {
|
|
1386
1449
|
x402Version: 2,
|
|
1387
1450
|
resource: requirements.resource || { url },
|
|
1388
1451
|
accepted: accept,
|
|
1389
1452
|
payload: {
|
|
1390
1453
|
authorization: message,
|
|
1391
|
-
signature
|
|
1454
|
+
signature,
|
|
1455
|
+
authorizationScheme
|
|
1392
1456
|
},
|
|
1393
1457
|
facilitatorUrl
|
|
1394
1458
|
};
|
|
@@ -1417,7 +1481,7 @@ function createX402Client(config) {
|
|
|
1417
1481
|
const sourceAta = await (0, import_spl_token.getAssociatedTokenAddress)(
|
|
1418
1482
|
mintPubkey,
|
|
1419
1483
|
userPubkey,
|
|
1420
|
-
|
|
1484
|
+
true,
|
|
1421
1485
|
programId
|
|
1422
1486
|
);
|
|
1423
1487
|
const destinationAta = await (0, import_spl_token.getAssociatedTokenAddress)(
|
|
@@ -1674,7 +1738,8 @@ var NETWORK_V1_TO_V2 = {
|
|
|
1674
1738
|
"skale-base": "eip155:1187947933",
|
|
1675
1739
|
"skale-base-sepolia": "eip155:324705682",
|
|
1676
1740
|
"peaq": "eip155:3338",
|
|
1677
|
-
"sei": "eip155:1329"
|
|
1741
|
+
"sei": "eip155:1329",
|
|
1742
|
+
"telos": "eip155:40"
|
|
1678
1743
|
};
|
|
1679
1744
|
var NETWORK_V2_TO_V1 = Object.fromEntries(
|
|
1680
1745
|
Object.entries(NETWORK_V1_TO_V2).map(([k, v]) => [v, k])
|
|
@@ -1701,7 +1766,8 @@ function networkV2ToV1(caip2Network) {
|
|
|
1701
1766
|
"1187947933": "skale-base",
|
|
1702
1767
|
"324705682": "skale-base-sepolia",
|
|
1703
1768
|
"3338": "peaq",
|
|
1704
|
-
"1329": "sei"
|
|
1769
|
+
"1329": "sei",
|
|
1770
|
+
"40": "telos"
|
|
1705
1771
|
};
|
|
1706
1772
|
return mapping[chainId] || caip2Network;
|
|
1707
1773
|
}
|
|
@@ -1785,7 +1851,7 @@ function isSolanaNetwork(network) {
|
|
|
1785
1851
|
return network === "solana" || network === "solana-devnet" || network.startsWith("solana:");
|
|
1786
1852
|
}
|
|
1787
1853
|
function isEvmNetwork(network) {
|
|
1788
|
-
const evmNetworks = ["base", "base-sepolia", "ethereum", "polygon", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "peaq", "sei"];
|
|
1854
|
+
const evmNetworks = ["base", "base-sepolia", "ethereum", "polygon", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "peaq", "sei", "telos"];
|
|
1789
1855
|
return evmNetworks.includes(network) || network.startsWith("eip155:");
|
|
1790
1856
|
}
|
|
1791
1857
|
function toAtomicUnits(usd, decimals = 6) {
|