@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.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DynamicPrice, PaymentInfo, ProtectOptions, default as Relai, RelaiIntegritasFlow, RelaiIntegritasOptions, RelaiServerConfig, SettleResult, StripePayTo, default, stripePayTo } from './server.cjs';
|
|
2
2
|
export { RelayWebSocketFactory, RelayWebSocketLike, X402Client, X402ClientConfig, X402FetchInit, X402IntegritasConfig, X402IntegritasFlow, X402NetworkSelectionMode, X402RelayWsConfig, X402RelayWsError, X402RelayWsResponse, X402RequestOptions, default as createX402Client } from './client.cjs';
|
|
3
|
-
export { A as AcceptsExtra, B as BASE_MAINNET_NETWORK, C as CAIP2_TO_NETWORK, b as CHAIN_IDS, E as EXPLORER_TX_URL, l as EvmWallet, N as NETWORK_CAIP2, e as NETWORK_LABELS, d as NETWORK_TOKENS, c as NetworkToken, P as PaymentAccept, o as PaymentRequired, R as RELAI_FACILITATOR_URL, h as RELAI_NETWORKS, a as RelaiNetwork, m as ResourceInfo, S as SOLANA_MAINNET_NETWORK, k as SolanaWallet, U as USDC_ADDRESSES, g as USDC_BASE, f as USDC_SOLANA, W as WalletSet, j as isEvm, i as isSolana, n as normalizeNetwork, r as resolveToken } from './types-
|
|
3
|
+
export { A as AcceptsExtra, B as BASE_MAINNET_NETWORK, C as CAIP2_TO_NETWORK, b as CHAIN_IDS, E as EXPLORER_TX_URL, l as EvmWallet, N as NETWORK_CAIP2, e as NETWORK_LABELS, d as NETWORK_TOKENS, c as NetworkToken, P as PaymentAccept, o as PaymentRequired, R as RELAI_FACILITATOR_URL, h as RELAI_NETWORKS, a as RelaiNetwork, m as ResourceInfo, S as SOLANA_MAINNET_NETWORK, k as SolanaWallet, U as USDC_ADDRESSES, g as USDC_BASE, f as USDC_SOLANA, W as WalletSet, j as isEvm, i as isSolana, n as normalizeNetwork, r as resolveToken } from './types-BSCuAZJb.cjs';
|
|
4
4
|
export { NETWORK_V1_TO_V2, NETWORK_V2_TO_V1, convertPayloadToVersion, convertV1ToV2, convertV2ToV1, detectPayloadVersion, formatUsd, fromAtomicUnits, isEvmNetwork, isSolanaNetwork, networkV1ToV2, networkV2ToV1, normalizePaymentHeader, toAtomicUnits } from './utils/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DynamicPrice, PaymentInfo, ProtectOptions, default as Relai, RelaiIntegritasFlow, RelaiIntegritasOptions, RelaiServerConfig, SettleResult, StripePayTo, default, stripePayTo } from './server.js';
|
|
2
2
|
export { RelayWebSocketFactory, RelayWebSocketLike, X402Client, X402ClientConfig, X402FetchInit, X402IntegritasConfig, X402IntegritasFlow, X402NetworkSelectionMode, X402RelayWsConfig, X402RelayWsError, X402RelayWsResponse, X402RequestOptions, default as createX402Client } from './client.js';
|
|
3
|
-
export { A as AcceptsExtra, B as BASE_MAINNET_NETWORK, C as CAIP2_TO_NETWORK, b as CHAIN_IDS, E as EXPLORER_TX_URL, l as EvmWallet, N as NETWORK_CAIP2, e as NETWORK_LABELS, d as NETWORK_TOKENS, c as NetworkToken, P as PaymentAccept, o as PaymentRequired, R as RELAI_FACILITATOR_URL, h as RELAI_NETWORKS, a as RelaiNetwork, m as ResourceInfo, S as SOLANA_MAINNET_NETWORK, k as SolanaWallet, U as USDC_ADDRESSES, g as USDC_BASE, f as USDC_SOLANA, W as WalletSet, j as isEvm, i as isSolana, n as normalizeNetwork, r as resolveToken } from './types-
|
|
3
|
+
export { A as AcceptsExtra, B as BASE_MAINNET_NETWORK, C as CAIP2_TO_NETWORK, b as CHAIN_IDS, E as EXPLORER_TX_URL, l as EvmWallet, N as NETWORK_CAIP2, e as NETWORK_LABELS, d as NETWORK_TOKENS, c as NetworkToken, P as PaymentAccept, o as PaymentRequired, R as RELAI_FACILITATOR_URL, h as RELAI_NETWORKS, a as RelaiNetwork, m as ResourceInfo, S as SOLANA_MAINNET_NETWORK, k as SolanaWallet, U as USDC_ADDRESSES, g as USDC_BASE, f as USDC_SOLANA, W as WalletSet, j as isEvm, i as isSolana, n as normalizeNetwork, r as resolveToken } from './types-BSCuAZJb.js';
|
|
4
4
|
export { NETWORK_V1_TO_V2, NETWORK_V2_TO_V1, convertPayloadToVersion, convertV1ToV2, convertV2ToV1, detectPayloadVersion, formatUsd, fromAtomicUnits, isEvmNetwork, isSolanaNetwork, networkV1ToV2, networkV2ToV1, normalizePaymentHeader, toAtomicUnits } from './utils/index.js';
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,8 @@ var NETWORK_CAIP2 = {
|
|
|
8
8
|
"skale-base-sepolia": "eip155:324705682",
|
|
9
9
|
"skale-bite": "eip155:103698795",
|
|
10
10
|
"polygon": "eip155:137",
|
|
11
|
-
"ethereum": "eip155:1"
|
|
11
|
+
"ethereum": "eip155:1",
|
|
12
|
+
"telos": "eip155:40"
|
|
12
13
|
};
|
|
13
14
|
var CAIP2_TO_NETWORK = Object.fromEntries(
|
|
14
15
|
Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k])
|
|
@@ -20,7 +21,8 @@ var CHAIN_IDS = {
|
|
|
20
21
|
"skale-base-sepolia": 324705682,
|
|
21
22
|
"skale-bite": 103698795,
|
|
22
23
|
"polygon": 137,
|
|
23
|
-
"ethereum": 1
|
|
24
|
+
"ethereum": 1,
|
|
25
|
+
"telos": 40
|
|
24
26
|
};
|
|
25
27
|
var NETWORK_TOKENS = {
|
|
26
28
|
"solana": [
|
|
@@ -44,6 +46,16 @@ var NETWORK_TOKENS = {
|
|
|
44
46
|
isStableUsd: true
|
|
45
47
|
}
|
|
46
48
|
],
|
|
49
|
+
"telos": [
|
|
50
|
+
{
|
|
51
|
+
address: "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b",
|
|
52
|
+
symbol: "USDC",
|
|
53
|
+
name: "USD Coin",
|
|
54
|
+
decimals: 6,
|
|
55
|
+
isStableUsd: true,
|
|
56
|
+
standards: ["eip2612"]
|
|
57
|
+
}
|
|
58
|
+
],
|
|
47
59
|
"skale-base": [
|
|
48
60
|
{
|
|
49
61
|
address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
|
|
@@ -158,7 +170,8 @@ var USDC_ADDRESSES = {
|
|
|
158
170
|
"skale-base-sepolia": "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
|
|
159
171
|
"skale-bite": "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
|
|
160
172
|
"polygon": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
161
|
-
"ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
173
|
+
"ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
174
|
+
"telos": "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b"
|
|
162
175
|
};
|
|
163
176
|
var EXPLORER_TX_URL = {
|
|
164
177
|
"solana": (tx) => `https://solscan.io/tx/${tx}`,
|
|
@@ -168,7 +181,8 @@ var EXPLORER_TX_URL = {
|
|
|
168
181
|
"skale-base-sepolia": (tx) => `https://base-sepolia-testnet-explorer.skalenodes.com/tx/${tx}`,
|
|
169
182
|
"skale-bite": (tx) => `https://base-sepolia-testnet.explorer.skalenodes.com/tx/${tx}`,
|
|
170
183
|
"polygon": (tx) => `https://polygonscan.com/tx/${tx}`,
|
|
171
|
-
"ethereum": (tx) => `https://etherscan.io/tx/${tx}
|
|
184
|
+
"ethereum": (tx) => `https://etherscan.io/tx/${tx}`,
|
|
185
|
+
"telos": (tx) => `https://teloscan.io/tx/${tx}`
|
|
172
186
|
};
|
|
173
187
|
var NETWORK_LABELS = {
|
|
174
188
|
"solana": "Solana",
|
|
@@ -178,7 +192,8 @@ var NETWORK_LABELS = {
|
|
|
178
192
|
"skale-base-sepolia": "SKALE Base Sepolia",
|
|
179
193
|
"skale-bite": "SKALE BITE V2",
|
|
180
194
|
"polygon": "Polygon",
|
|
181
|
-
"ethereum": "Ethereum"
|
|
195
|
+
"ethereum": "Ethereum",
|
|
196
|
+
"telos": "Telos EVM"
|
|
182
197
|
};
|
|
183
198
|
var SOLANA_MAINNET_NETWORK = NETWORK_CAIP2["solana"];
|
|
184
199
|
var BASE_MAINNET_NETWORK = NETWORK_CAIP2["base"];
|
|
@@ -192,13 +207,14 @@ var RELAI_NETWORKS = [
|
|
|
192
207
|
"skale-base-sepolia",
|
|
193
208
|
"skale-bite",
|
|
194
209
|
"polygon",
|
|
195
|
-
"ethereum"
|
|
210
|
+
"ethereum",
|
|
211
|
+
"telos"
|
|
196
212
|
];
|
|
197
213
|
function isSolana(network) {
|
|
198
214
|
return network === "solana" || network.startsWith("solana:");
|
|
199
215
|
}
|
|
200
216
|
function isEvm(network) {
|
|
201
|
-
return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum"].includes(network) || network.startsWith("eip155:");
|
|
217
|
+
return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum", "telos"].includes(network) || network.startsWith("eip155:");
|
|
202
218
|
}
|
|
203
219
|
function normalizeNetwork(network) {
|
|
204
220
|
if (RELAI_NETWORKS.includes(network)) return network;
|
|
@@ -691,7 +707,8 @@ var DEFAULT_EVM_RPC_URLS = {
|
|
|
691
707
|
"base": "https://mainnet.base.org",
|
|
692
708
|
"avalanche": "https://api.avax.network/ext/bc/C/rpc",
|
|
693
709
|
"polygon": "https://polygon-rpc.com",
|
|
694
|
-
"ethereum": "https://ethereum-rpc.publicnode.com"
|
|
710
|
+
"ethereum": "https://ethereum-rpc.publicnode.com",
|
|
711
|
+
"telos": "https://rpc.telos.net"
|
|
695
712
|
};
|
|
696
713
|
function createX402Client(config) {
|
|
697
714
|
const {
|
|
@@ -1300,41 +1317,93 @@ function createX402Client(config) {
|
|
|
1300
1317
|
chainId,
|
|
1301
1318
|
verifyingContract: useRelayer ? extra.relayerContract : accept.asset
|
|
1302
1319
|
};
|
|
1303
|
-
const
|
|
1304
|
-
const
|
|
1305
|
-
const
|
|
1306
|
-
const
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1320
|
+
const tokenNetworkKey = network || rawNetwork;
|
|
1321
|
+
const networkTokens = NETWORK_TOKENS[tokenNetworkKey];
|
|
1322
|
+
const assetLower = (accept.asset || "").toLowerCase();
|
|
1323
|
+
const tokenInfo = networkTokens?.find((t) => t.address.toLowerCase() === assetLower) || networkTokens?.[0];
|
|
1324
|
+
const tokenStandards = Array.isArray(tokenInfo?.standards) ? tokenInfo.standards : [];
|
|
1325
|
+
const hasEip3009 = tokenStandards.some((s) => s.toLowerCase() === "eip3009");
|
|
1326
|
+
const hasEip2612 = tokenStandards.some((s) => s.toLowerCase() === "eip2612");
|
|
1327
|
+
const usePermit2612 = !hasEip3009 && hasEip2612;
|
|
1328
|
+
let message;
|
|
1329
|
+
let signature;
|
|
1330
|
+
let authorizationScheme;
|
|
1331
|
+
if (usePermit2612) {
|
|
1332
|
+
const spender = extra.feePayer || accept.payTo;
|
|
1333
|
+
const deadline = Math.floor(Date.now() / 1e3) + 3600;
|
|
1334
|
+
let nonce = 0;
|
|
1335
|
+
if (rpcUrl) {
|
|
1336
|
+
try {
|
|
1337
|
+
const paddedAddress = evmWallet.address.toLowerCase().replace("0x", "").padStart(64, "0");
|
|
1338
|
+
const nonceHex = await evmRpcCall(rpcUrl, accept.asset, "0x7ecebe00" + paddedAddress);
|
|
1339
|
+
nonce = nonceHex ? parseInt(nonceHex, 16) : 0;
|
|
1340
|
+
} catch {
|
|
1341
|
+
nonce = 0;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
const permitTypes = {
|
|
1345
|
+
Permit: [
|
|
1346
|
+
{ name: "owner", type: "address" },
|
|
1347
|
+
{ name: "spender", type: "address" },
|
|
1348
|
+
{ name: "value", type: "uint256" },
|
|
1349
|
+
{ name: "nonce", type: "uint256" },
|
|
1350
|
+
{ name: "deadline", type: "uint256" }
|
|
1351
|
+
]
|
|
1352
|
+
};
|
|
1353
|
+
message = {
|
|
1354
|
+
owner: evmWallet.address,
|
|
1355
|
+
spender,
|
|
1356
|
+
value: paymentAmount,
|
|
1357
|
+
nonce: String(nonce),
|
|
1358
|
+
deadline: String(deadline)
|
|
1359
|
+
};
|
|
1360
|
+
log("Signing EIP-2612 permit on chain", chainId);
|
|
1361
|
+
signature = await evmWallet.signTypedData({
|
|
1362
|
+
domain,
|
|
1363
|
+
types: permitTypes,
|
|
1364
|
+
message,
|
|
1365
|
+
primaryType: "Permit"
|
|
1366
|
+
});
|
|
1367
|
+
authorizationScheme = "eip2612";
|
|
1368
|
+
} else {
|
|
1369
|
+
const validAfter = 0;
|
|
1370
|
+
const validBefore = Math.floor(Date.now() / 1e3) + 3600;
|
|
1371
|
+
const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1372
|
+
const transferTypes = {
|
|
1373
|
+
TransferWithAuthorization: [
|
|
1374
|
+
{ name: "from", type: "address" },
|
|
1375
|
+
{ name: "to", type: "address" },
|
|
1376
|
+
{ name: "value", type: "uint256" },
|
|
1377
|
+
{ name: "validAfter", type: "uint256" },
|
|
1378
|
+
{ name: "validBefore", type: "uint256" },
|
|
1379
|
+
{ name: "nonce", type: "bytes32" }
|
|
1380
|
+
]
|
|
1381
|
+
};
|
|
1382
|
+
message = {
|
|
1383
|
+
from: evmWallet.address,
|
|
1384
|
+
to: accept.payTo,
|
|
1385
|
+
value: paymentAmount,
|
|
1386
|
+
validAfter: String(validAfter),
|
|
1387
|
+
validBefore: String(validBefore),
|
|
1388
|
+
nonce
|
|
1389
|
+
};
|
|
1390
|
+
log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
|
|
1391
|
+
signature = await evmWallet.signTypedData({
|
|
1392
|
+
domain,
|
|
1393
|
+
types: transferTypes,
|
|
1394
|
+
message,
|
|
1395
|
+
primaryType: "TransferWithAuthorization"
|
|
1396
|
+
});
|
|
1397
|
+
authorizationScheme = "eip3009";
|
|
1398
|
+
}
|
|
1331
1399
|
const paymentPayload = {
|
|
1332
1400
|
x402Version: 2,
|
|
1333
1401
|
resource: requirements.resource || { url },
|
|
1334
1402
|
accepted: accept,
|
|
1335
1403
|
payload: {
|
|
1336
1404
|
authorization: message,
|
|
1337
|
-
signature
|
|
1405
|
+
signature,
|
|
1406
|
+
authorizationScheme
|
|
1338
1407
|
},
|
|
1339
1408
|
facilitatorUrl
|
|
1340
1409
|
};
|
|
@@ -1363,7 +1432,7 @@ function createX402Client(config) {
|
|
|
1363
1432
|
const sourceAta = await getAssociatedTokenAddress(
|
|
1364
1433
|
mintPubkey,
|
|
1365
1434
|
userPubkey,
|
|
1366
|
-
|
|
1435
|
+
true,
|
|
1367
1436
|
programId
|
|
1368
1437
|
);
|
|
1369
1438
|
const destinationAta = await getAssociatedTokenAddress(
|
|
@@ -1620,7 +1689,8 @@ var NETWORK_V1_TO_V2 = {
|
|
|
1620
1689
|
"skale-base": "eip155:1187947933",
|
|
1621
1690
|
"skale-base-sepolia": "eip155:324705682",
|
|
1622
1691
|
"peaq": "eip155:3338",
|
|
1623
|
-
"sei": "eip155:1329"
|
|
1692
|
+
"sei": "eip155:1329",
|
|
1693
|
+
"telos": "eip155:40"
|
|
1624
1694
|
};
|
|
1625
1695
|
var NETWORK_V2_TO_V1 = Object.fromEntries(
|
|
1626
1696
|
Object.entries(NETWORK_V1_TO_V2).map(([k, v]) => [v, k])
|
|
@@ -1647,7 +1717,8 @@ function networkV2ToV1(caip2Network) {
|
|
|
1647
1717
|
"1187947933": "skale-base",
|
|
1648
1718
|
"324705682": "skale-base-sepolia",
|
|
1649
1719
|
"3338": "peaq",
|
|
1650
|
-
"1329": "sei"
|
|
1720
|
+
"1329": "sei",
|
|
1721
|
+
"40": "telos"
|
|
1651
1722
|
};
|
|
1652
1723
|
return mapping[chainId] || caip2Network;
|
|
1653
1724
|
}
|
|
@@ -1731,7 +1802,7 @@ function isSolanaNetwork(network) {
|
|
|
1731
1802
|
return network === "solana" || network === "solana-devnet" || network.startsWith("solana:");
|
|
1732
1803
|
}
|
|
1733
1804
|
function isEvmNetwork(network) {
|
|
1734
|
-
const evmNetworks = ["base", "base-sepolia", "ethereum", "polygon", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "peaq", "sei"];
|
|
1805
|
+
const evmNetworks = ["base", "base-sepolia", "ethereum", "polygon", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "peaq", "sei", "telos"];
|
|
1735
1806
|
return evmNetworks.includes(network) || network.startsWith("eip155:");
|
|
1736
1807
|
}
|
|
1737
1808
|
function toAtomicUnits(usd, decimals = 6) {
|