@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/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-CWtUxi3l.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-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-CWtUxi3l.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-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": [
@@ -32,12 +34,7 @@ var NETWORK_TOKENS = {
32
34
  }
33
35
  ],
34
36
  "base": [
35
- { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", symbol: "USDC", name: "USD Coin", decimals: 6, domainVersion: "2", isStableUsd: true },
36
- { address: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2", symbol: "USDT", name: "Tether USD", decimals: 6, domainVersion: "1", isStableUsd: true },
37
- { address: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42", symbol: "EURC", name: "Euro Coin", decimals: 6, domainVersion: "2", isStableUsd: false },
38
- { address: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb", symbol: "DAI", name: "Dai Stablecoin", decimals: 18, domainVersion: "1", isStableUsd: true },
39
- { address: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22", symbol: "cbETH", name: "Coinbase Wrapped Ether", decimals: 18, domainVersion: "1", isStableUsd: false },
40
- { address: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf", symbol: "cbBTC", name: "Coinbase Wrapped BTC", decimals: 8, domainVersion: "1", isStableUsd: false }
37
+ { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", symbol: "USDC", name: "USD Coin", decimals: 6, domainVersion: "2", isStableUsd: true }
41
38
  ],
42
39
  "avalanche": [
43
40
  {
@@ -49,6 +46,16 @@ var NETWORK_TOKENS = {
49
46
  isStableUsd: true
50
47
  }
51
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
+ ],
52
59
  "skale-base": [
53
60
  {
54
61
  address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
@@ -163,7 +170,8 @@ var USDC_ADDRESSES = {
163
170
  "skale-base-sepolia": "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
164
171
  "skale-bite": "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
165
172
  "polygon": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
166
- "ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
173
+ "ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
174
+ "telos": "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b"
167
175
  };
168
176
  var EXPLORER_TX_URL = {
169
177
  "solana": (tx) => `https://solscan.io/tx/${tx}`,
@@ -173,7 +181,8 @@ var EXPLORER_TX_URL = {
173
181
  "skale-base-sepolia": (tx) => `https://base-sepolia-testnet-explorer.skalenodes.com/tx/${tx}`,
174
182
  "skale-bite": (tx) => `https://base-sepolia-testnet.explorer.skalenodes.com/tx/${tx}`,
175
183
  "polygon": (tx) => `https://polygonscan.com/tx/${tx}`,
176
- "ethereum": (tx) => `https://etherscan.io/tx/${tx}`
184
+ "ethereum": (tx) => `https://etherscan.io/tx/${tx}`,
185
+ "telos": (tx) => `https://teloscan.io/tx/${tx}`
177
186
  };
178
187
  var NETWORK_LABELS = {
179
188
  "solana": "Solana",
@@ -183,7 +192,8 @@ var NETWORK_LABELS = {
183
192
  "skale-base-sepolia": "SKALE Base Sepolia",
184
193
  "skale-bite": "SKALE BITE V2",
185
194
  "polygon": "Polygon",
186
- "ethereum": "Ethereum"
195
+ "ethereum": "Ethereum",
196
+ "telos": "Telos EVM"
187
197
  };
188
198
  var SOLANA_MAINNET_NETWORK = NETWORK_CAIP2["solana"];
189
199
  var BASE_MAINNET_NETWORK = NETWORK_CAIP2["base"];
@@ -197,13 +207,14 @@ var RELAI_NETWORKS = [
197
207
  "skale-base-sepolia",
198
208
  "skale-bite",
199
209
  "polygon",
200
- "ethereum"
210
+ "ethereum",
211
+ "telos"
201
212
  ];
202
213
  function isSolana(network) {
203
214
  return network === "solana" || network.startsWith("solana:");
204
215
  }
205
216
  function isEvm(network) {
206
- 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:");
207
218
  }
208
219
  function normalizeNetwork(network) {
209
220
  if (RELAI_NETWORKS.includes(network)) return network;
@@ -696,7 +707,8 @@ var DEFAULT_EVM_RPC_URLS = {
696
707
  "base": "https://mainnet.base.org",
697
708
  "avalanche": "https://api.avax.network/ext/bc/C/rpc",
698
709
  "polygon": "https://polygon-rpc.com",
699
- "ethereum": "https://ethereum-rpc.publicnode.com"
710
+ "ethereum": "https://ethereum-rpc.publicnode.com",
711
+ "telos": "https://rpc.telos.net"
700
712
  };
701
713
  function createX402Client(config) {
702
714
  const {
@@ -1305,41 +1317,93 @@ function createX402Client(config) {
1305
1317
  chainId,
1306
1318
  verifyingContract: useRelayer ? extra.relayerContract : accept.asset
1307
1319
  };
1308
- const validAfter = 0;
1309
- const validBefore = Math.floor(Date.now() / 1e3) + 3600;
1310
- const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
1311
- const types = {
1312
- TransferWithAuthorization: [
1313
- { name: "from", type: "address" },
1314
- { name: "to", type: "address" },
1315
- { name: "value", type: "uint256" },
1316
- { name: "validAfter", type: "uint256" },
1317
- { name: "validBefore", type: "uint256" },
1318
- { name: "nonce", type: "bytes32" }
1319
- ]
1320
- };
1321
- const message = {
1322
- from: evmWallet.address,
1323
- to: accept.payTo,
1324
- value: paymentAmount,
1325
- validAfter: String(validAfter),
1326
- validBefore: String(validBefore),
1327
- nonce
1328
- };
1329
- log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
1330
- const signature = await evmWallet.signTypedData({
1331
- domain,
1332
- types,
1333
- message,
1334
- primaryType: "TransferWithAuthorization"
1335
- });
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
+ }
1336
1399
  const paymentPayload = {
1337
1400
  x402Version: 2,
1338
1401
  resource: requirements.resource || { url },
1339
1402
  accepted: accept,
1340
1403
  payload: {
1341
1404
  authorization: message,
1342
- signature
1405
+ signature,
1406
+ authorizationScheme
1343
1407
  },
1344
1408
  facilitatorUrl
1345
1409
  };
@@ -1368,7 +1432,7 @@ function createX402Client(config) {
1368
1432
  const sourceAta = await getAssociatedTokenAddress(
1369
1433
  mintPubkey,
1370
1434
  userPubkey,
1371
- false,
1435
+ true,
1372
1436
  programId
1373
1437
  );
1374
1438
  const destinationAta = await getAssociatedTokenAddress(
@@ -1625,7 +1689,8 @@ var NETWORK_V1_TO_V2 = {
1625
1689
  "skale-base": "eip155:1187947933",
1626
1690
  "skale-base-sepolia": "eip155:324705682",
1627
1691
  "peaq": "eip155:3338",
1628
- "sei": "eip155:1329"
1692
+ "sei": "eip155:1329",
1693
+ "telos": "eip155:40"
1629
1694
  };
1630
1695
  var NETWORK_V2_TO_V1 = Object.fromEntries(
1631
1696
  Object.entries(NETWORK_V1_TO_V2).map(([k, v]) => [v, k])
@@ -1652,7 +1717,8 @@ function networkV2ToV1(caip2Network) {
1652
1717
  "1187947933": "skale-base",
1653
1718
  "324705682": "skale-base-sepolia",
1654
1719
  "3338": "peaq",
1655
- "1329": "sei"
1720
+ "1329": "sei",
1721
+ "40": "telos"
1656
1722
  };
1657
1723
  return mapping[chainId] || caip2Network;
1658
1724
  }
@@ -1736,7 +1802,7 @@ function isSolanaNetwork(network) {
1736
1802
  return network === "solana" || network === "solana-devnet" || network.startsWith("solana:");
1737
1803
  }
1738
1804
  function isEvmNetwork(network) {
1739
- 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"];
1740
1806
  return evmNetworks.includes(network) || network.startsWith("eip155:");
1741
1807
  }
1742
1808
  function toAtomicUnits(usd, decimals = 6) {