@relai-fi/x402 0.5.18 → 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 +112 -41
- 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 +112 -41
- 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 +14 -2
- 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 +14 -2
- 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": [
|
|
@@ -104,6 +106,16 @@ var NETWORK_TOKENS = {
|
|
|
104
106
|
isStableUsd: true
|
|
105
107
|
}
|
|
106
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
|
+
],
|
|
107
119
|
"skale-base": [
|
|
108
120
|
{
|
|
109
121
|
address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
|
|
@@ -218,7 +230,8 @@ var USDC_ADDRESSES = {
|
|
|
218
230
|
"skale-base-sepolia": "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
|
|
219
231
|
"skale-bite": "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
|
|
220
232
|
"polygon": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
221
|
-
"ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
233
|
+
"ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
234
|
+
"telos": "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b"
|
|
222
235
|
};
|
|
223
236
|
var EXPLORER_TX_URL = {
|
|
224
237
|
"solana": (tx) => `https://solscan.io/tx/${tx}`,
|
|
@@ -228,7 +241,8 @@ var EXPLORER_TX_URL = {
|
|
|
228
241
|
"skale-base-sepolia": (tx) => `https://base-sepolia-testnet-explorer.skalenodes.com/tx/${tx}`,
|
|
229
242
|
"skale-bite": (tx) => `https://base-sepolia-testnet.explorer.skalenodes.com/tx/${tx}`,
|
|
230
243
|
"polygon": (tx) => `https://polygonscan.com/tx/${tx}`,
|
|
231
|
-
"ethereum": (tx) => `https://etherscan.io/tx/${tx}
|
|
244
|
+
"ethereum": (tx) => `https://etherscan.io/tx/${tx}`,
|
|
245
|
+
"telos": (tx) => `https://teloscan.io/tx/${tx}`
|
|
232
246
|
};
|
|
233
247
|
var NETWORK_LABELS = {
|
|
234
248
|
"solana": "Solana",
|
|
@@ -238,7 +252,8 @@ var NETWORK_LABELS = {
|
|
|
238
252
|
"skale-base-sepolia": "SKALE Base Sepolia",
|
|
239
253
|
"skale-bite": "SKALE BITE V2",
|
|
240
254
|
"polygon": "Polygon",
|
|
241
|
-
"ethereum": "Ethereum"
|
|
255
|
+
"ethereum": "Ethereum",
|
|
256
|
+
"telos": "Telos EVM"
|
|
242
257
|
};
|
|
243
258
|
var SOLANA_MAINNET_NETWORK = NETWORK_CAIP2["solana"];
|
|
244
259
|
var BASE_MAINNET_NETWORK = NETWORK_CAIP2["base"];
|
|
@@ -252,13 +267,14 @@ var RELAI_NETWORKS = [
|
|
|
252
267
|
"skale-base-sepolia",
|
|
253
268
|
"skale-bite",
|
|
254
269
|
"polygon",
|
|
255
|
-
"ethereum"
|
|
270
|
+
"ethereum",
|
|
271
|
+
"telos"
|
|
256
272
|
];
|
|
257
273
|
function isSolana(network) {
|
|
258
274
|
return network === "solana" || network.startsWith("solana:");
|
|
259
275
|
}
|
|
260
276
|
function isEvm(network) {
|
|
261
|
-
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:");
|
|
262
278
|
}
|
|
263
279
|
function normalizeNetwork(network) {
|
|
264
280
|
if (RELAI_NETWORKS.includes(network)) return network;
|
|
@@ -740,7 +756,8 @@ var DEFAULT_EVM_RPC_URLS = {
|
|
|
740
756
|
"base": "https://mainnet.base.org",
|
|
741
757
|
"avalanche": "https://api.avax.network/ext/bc/C/rpc",
|
|
742
758
|
"polygon": "https://polygon-rpc.com",
|
|
743
|
-
"ethereum": "https://ethereum-rpc.publicnode.com"
|
|
759
|
+
"ethereum": "https://ethereum-rpc.publicnode.com",
|
|
760
|
+
"telos": "https://rpc.telos.net"
|
|
744
761
|
};
|
|
745
762
|
function createX402Client(config) {
|
|
746
763
|
const {
|
|
@@ -1349,41 +1366,93 @@ function createX402Client(config) {
|
|
|
1349
1366
|
chainId,
|
|
1350
1367
|
verifyingContract: useRelayer ? extra.relayerContract : accept.asset
|
|
1351
1368
|
};
|
|
1352
|
-
const
|
|
1353
|
-
const
|
|
1354
|
-
const
|
|
1355
|
-
const
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
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
|
+
}
|
|
1380
1448
|
const paymentPayload = {
|
|
1381
1449
|
x402Version: 2,
|
|
1382
1450
|
resource: requirements.resource || { url },
|
|
1383
1451
|
accepted: accept,
|
|
1384
1452
|
payload: {
|
|
1385
1453
|
authorization: message,
|
|
1386
|
-
signature
|
|
1454
|
+
signature,
|
|
1455
|
+
authorizationScheme
|
|
1387
1456
|
},
|
|
1388
1457
|
facilitatorUrl
|
|
1389
1458
|
};
|
|
@@ -1412,7 +1481,7 @@ function createX402Client(config) {
|
|
|
1412
1481
|
const sourceAta = await (0, import_spl_token.getAssociatedTokenAddress)(
|
|
1413
1482
|
mintPubkey,
|
|
1414
1483
|
userPubkey,
|
|
1415
|
-
|
|
1484
|
+
true,
|
|
1416
1485
|
programId
|
|
1417
1486
|
);
|
|
1418
1487
|
const destinationAta = await (0, import_spl_token.getAssociatedTokenAddress)(
|
|
@@ -1669,7 +1738,8 @@ var NETWORK_V1_TO_V2 = {
|
|
|
1669
1738
|
"skale-base": "eip155:1187947933",
|
|
1670
1739
|
"skale-base-sepolia": "eip155:324705682",
|
|
1671
1740
|
"peaq": "eip155:3338",
|
|
1672
|
-
"sei": "eip155:1329"
|
|
1741
|
+
"sei": "eip155:1329",
|
|
1742
|
+
"telos": "eip155:40"
|
|
1673
1743
|
};
|
|
1674
1744
|
var NETWORK_V2_TO_V1 = Object.fromEntries(
|
|
1675
1745
|
Object.entries(NETWORK_V1_TO_V2).map(([k, v]) => [v, k])
|
|
@@ -1696,7 +1766,8 @@ function networkV2ToV1(caip2Network) {
|
|
|
1696
1766
|
"1187947933": "skale-base",
|
|
1697
1767
|
"324705682": "skale-base-sepolia",
|
|
1698
1768
|
"3338": "peaq",
|
|
1699
|
-
"1329": "sei"
|
|
1769
|
+
"1329": "sei",
|
|
1770
|
+
"40": "telos"
|
|
1700
1771
|
};
|
|
1701
1772
|
return mapping[chainId] || caip2Network;
|
|
1702
1773
|
}
|
|
@@ -1780,7 +1851,7 @@ function isSolanaNetwork(network) {
|
|
|
1780
1851
|
return network === "solana" || network === "solana-devnet" || network.startsWith("solana:");
|
|
1781
1852
|
}
|
|
1782
1853
|
function isEvmNetwork(network) {
|
|
1783
|
-
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"];
|
|
1784
1855
|
return evmNetworks.includes(network) || network.startsWith("eip155:");
|
|
1785
1856
|
}
|
|
1786
1857
|
function toAtomicUnits(usd, decimals = 6) {
|