@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.
@@ -26,7 +26,8 @@ var NETWORK_CAIP2 = {
26
26
  "skale-base-sepolia": "eip155:324705682",
27
27
  "skale-bite": "eip155:103698795",
28
28
  "polygon": "eip155:137",
29
- "ethereum": "eip155:1"
29
+ "ethereum": "eip155:1",
30
+ "telos": "eip155:40"
30
31
  };
31
32
  var CAIP2_TO_NETWORK = Object.fromEntries(
32
33
  Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k])
@@ -38,7 +39,139 @@ var CHAIN_IDS = {
38
39
  "skale-base-sepolia": 324705682,
39
40
  "skale-bite": 103698795,
40
41
  "polygon": 137,
41
- "ethereum": 1
42
+ "ethereum": 1,
43
+ "telos": 40
44
+ };
45
+ var NETWORK_TOKENS = {
46
+ "solana": [
47
+ {
48
+ address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
49
+ symbol: "USDC",
50
+ name: "USD Coin",
51
+ decimals: 6
52
+ }
53
+ ],
54
+ "base": [
55
+ { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", symbol: "USDC", name: "USD Coin", decimals: 6, domainVersion: "2", isStableUsd: true }
56
+ ],
57
+ "avalanche": [
58
+ {
59
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
60
+ symbol: "USDC",
61
+ name: "USD Coin",
62
+ decimals: 6,
63
+ domainVersion: "2",
64
+ isStableUsd: true
65
+ }
66
+ ],
67
+ "telos": [
68
+ {
69
+ address: "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b",
70
+ symbol: "USDC",
71
+ name: "USD Coin",
72
+ decimals: 6,
73
+ isStableUsd: true,
74
+ standards: ["eip2612"]
75
+ }
76
+ ],
77
+ "skale-base": [
78
+ {
79
+ address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
80
+ symbol: "USDC",
81
+ name: "Bridged USDC (SKALE Bridge)",
82
+ decimals: 6,
83
+ domainVersion: "2",
84
+ isStableUsd: true
85
+ },
86
+ {
87
+ address: "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA",
88
+ symbol: "USDT",
89
+ name: "Bridged USDT (SKALE Bridge)",
90
+ decimals: 6,
91
+ domainVersion: "1",
92
+ isStableUsd: true
93
+ },
94
+ {
95
+ address: "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e",
96
+ symbol: "WBTC",
97
+ name: "Wrapped Bitcoin",
98
+ decimals: 8,
99
+ domainVersion: "1",
100
+ isStableUsd: false
101
+ },
102
+ {
103
+ address: "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486",
104
+ symbol: "WETH",
105
+ name: "Wrapped Ether",
106
+ decimals: 18,
107
+ domainVersion: "1",
108
+ isStableUsd: false
109
+ }
110
+ ],
111
+ "skale-base-sepolia": [
112
+ {
113
+ address: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
114
+ symbol: "USDC",
115
+ name: "Bridged USDC (SKALE Bridge)",
116
+ decimals: 6,
117
+ domainVersion: "2",
118
+ isStableUsd: true
119
+ },
120
+ {
121
+ address: "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf",
122
+ symbol: "USDT",
123
+ name: "Bridged USDT (SKALE Bridge)",
124
+ decimals: 6,
125
+ domainVersion: "1",
126
+ isStableUsd: true
127
+ },
128
+ {
129
+ address: "0x4512eacd4186b025186e1cf6cc0d89497c530e87",
130
+ symbol: "WBTC",
131
+ name: "Wrapped Bitcoin",
132
+ decimals: 8,
133
+ domainVersion: "1",
134
+ isStableUsd: false
135
+ },
136
+ {
137
+ address: "0xf94056bd7f6965db3757e1b145f200b7346b4fc0",
138
+ symbol: "WETH",
139
+ name: "Wrapped Ether",
140
+ decimals: 18,
141
+ domainVersion: "1",
142
+ isStableUsd: false
143
+ }
144
+ ],
145
+ "skale-bite": [
146
+ {
147
+ address: "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
148
+ symbol: "USDC",
149
+ name: "USDC",
150
+ decimals: 6,
151
+ domainVersion: "1",
152
+ isStableUsd: true
153
+ }
154
+ ],
155
+ "polygon": [
156
+ {
157
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
158
+ symbol: "USDC",
159
+ name: "USD Coin",
160
+ decimals: 6,
161
+ domainVersion: "2",
162
+ isStableUsd: true
163
+ }
164
+ ],
165
+ "ethereum": [
166
+ {
167
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
168
+ symbol: "USDC",
169
+ name: "USD Coin",
170
+ decimals: 6,
171
+ domainVersion: "2",
172
+ isStableUsd: true
173
+ }
174
+ ]
42
175
  };
43
176
  var USDC_ADDRESSES = {
44
177
  "solana": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
@@ -48,7 +181,8 @@ var USDC_ADDRESSES = {
48
181
  "skale-base-sepolia": "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
49
182
  "skale-bite": "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
50
183
  "polygon": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
51
- "ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
184
+ "ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
185
+ "telos": "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b"
52
186
  };
53
187
  var EXPLORER_TX_URL = {
54
188
  "solana": (tx) => `https://solscan.io/tx/${tx}`,
@@ -58,7 +192,8 @@ var EXPLORER_TX_URL = {
58
192
  "skale-base-sepolia": (tx) => `https://base-sepolia-testnet-explorer.skalenodes.com/tx/${tx}`,
59
193
  "skale-bite": (tx) => `https://base-sepolia-testnet.explorer.skalenodes.com/tx/${tx}`,
60
194
  "polygon": (tx) => `https://polygonscan.com/tx/${tx}`,
61
- "ethereum": (tx) => `https://etherscan.io/tx/${tx}`
195
+ "ethereum": (tx) => `https://etherscan.io/tx/${tx}`,
196
+ "telos": (tx) => `https://teloscan.io/tx/${tx}`
62
197
  };
63
198
  var NETWORK_LABELS = {
64
199
  "solana": "Solana",
@@ -68,7 +203,8 @@ var NETWORK_LABELS = {
68
203
  "skale-base-sepolia": "SKALE Base Sepolia",
69
204
  "skale-bite": "SKALE BITE V2",
70
205
  "polygon": "Polygon",
71
- "ethereum": "Ethereum"
206
+ "ethereum": "Ethereum",
207
+ "telos": "Telos EVM"
72
208
  };
73
209
  var SOLANA_MAINNET_NETWORK = NETWORK_CAIP2["solana"];
74
210
  var BASE_MAINNET_NETWORK = NETWORK_CAIP2["base"];
@@ -82,13 +218,14 @@ var RELAI_NETWORKS = [
82
218
  "skale-base-sepolia",
83
219
  "skale-bite",
84
220
  "polygon",
85
- "ethereum"
221
+ "ethereum",
222
+ "telos"
86
223
  ];
87
224
  function isSolana(network) {
88
225
  return network === "solana" || network.startsWith("solana:");
89
226
  }
90
227
  function isEvm(network) {
91
- return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum"].includes(network) || network.startsWith("eip155:");
228
+ return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum", "telos"].includes(network) || network.startsWith("eip155:");
92
229
  }
93
230
  function normalizeNetwork(network) {
94
231
  if (RELAI_NETWORKS.includes(network)) return network;
@@ -112,7 +249,8 @@ var DEFAULT_EVM_RPC_URLS = {
112
249
  "base": "https://mainnet.base.org",
113
250
  "avalanche": "https://api.avax.network/ext/bc/C/rpc",
114
251
  "polygon": "https://polygon-rpc.com",
115
- "ethereum": "https://ethereum-rpc.publicnode.com"
252
+ "ethereum": "https://ethereum-rpc.publicnode.com",
253
+ "telos": "https://rpc.telos.net"
116
254
  };
117
255
  function createX402Client(config) {
118
256
  const {
@@ -721,41 +859,93 @@ function createX402Client(config) {
721
859
  chainId,
722
860
  verifyingContract: useRelayer ? extra.relayerContract : accept.asset
723
861
  };
724
- const validAfter = 0;
725
- const validBefore = Math.floor(Date.now() / 1e3) + 3600;
726
- const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
727
- const types = {
728
- TransferWithAuthorization: [
729
- { name: "from", type: "address" },
730
- { name: "to", type: "address" },
731
- { name: "value", type: "uint256" },
732
- { name: "validAfter", type: "uint256" },
733
- { name: "validBefore", type: "uint256" },
734
- { name: "nonce", type: "bytes32" }
735
- ]
736
- };
737
- const message = {
738
- from: evmWallet.address,
739
- to: accept.payTo,
740
- value: paymentAmount,
741
- validAfter: String(validAfter),
742
- validBefore: String(validBefore),
743
- nonce
744
- };
745
- log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
746
- const signature = await evmWallet.signTypedData({
747
- domain,
748
- types,
749
- message,
750
- primaryType: "TransferWithAuthorization"
751
- });
862
+ const tokenNetworkKey = network || rawNetwork;
863
+ const networkTokens = NETWORK_TOKENS[tokenNetworkKey];
864
+ const assetLower = (accept.asset || "").toLowerCase();
865
+ const tokenInfo = networkTokens?.find((t) => t.address.toLowerCase() === assetLower) || networkTokens?.[0];
866
+ const tokenStandards = Array.isArray(tokenInfo?.standards) ? tokenInfo.standards : [];
867
+ const hasEip3009 = tokenStandards.some((s) => s.toLowerCase() === "eip3009");
868
+ const hasEip2612 = tokenStandards.some((s) => s.toLowerCase() === "eip2612");
869
+ const usePermit2612 = !hasEip3009 && hasEip2612;
870
+ let message;
871
+ let signature;
872
+ let authorizationScheme;
873
+ if (usePermit2612) {
874
+ const spender = extra.feePayer || accept.payTo;
875
+ const deadline = Math.floor(Date.now() / 1e3) + 3600;
876
+ let nonce = 0;
877
+ if (rpcUrl) {
878
+ try {
879
+ const paddedAddress = evmWallet.address.toLowerCase().replace("0x", "").padStart(64, "0");
880
+ const nonceHex = await evmRpcCall(rpcUrl, accept.asset, "0x7ecebe00" + paddedAddress);
881
+ nonce = nonceHex ? parseInt(nonceHex, 16) : 0;
882
+ } catch {
883
+ nonce = 0;
884
+ }
885
+ }
886
+ const permitTypes = {
887
+ Permit: [
888
+ { name: "owner", type: "address" },
889
+ { name: "spender", type: "address" },
890
+ { name: "value", type: "uint256" },
891
+ { name: "nonce", type: "uint256" },
892
+ { name: "deadline", type: "uint256" }
893
+ ]
894
+ };
895
+ message = {
896
+ owner: evmWallet.address,
897
+ spender,
898
+ value: paymentAmount,
899
+ nonce: String(nonce),
900
+ deadline: String(deadline)
901
+ };
902
+ log("Signing EIP-2612 permit on chain", chainId);
903
+ signature = await evmWallet.signTypedData({
904
+ domain,
905
+ types: permitTypes,
906
+ message,
907
+ primaryType: "Permit"
908
+ });
909
+ authorizationScheme = "eip2612";
910
+ } else {
911
+ const validAfter = 0;
912
+ const validBefore = Math.floor(Date.now() / 1e3) + 3600;
913
+ const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
914
+ const transferTypes = {
915
+ TransferWithAuthorization: [
916
+ { name: "from", type: "address" },
917
+ { name: "to", type: "address" },
918
+ { name: "value", type: "uint256" },
919
+ { name: "validAfter", type: "uint256" },
920
+ { name: "validBefore", type: "uint256" },
921
+ { name: "nonce", type: "bytes32" }
922
+ ]
923
+ };
924
+ message = {
925
+ from: evmWallet.address,
926
+ to: accept.payTo,
927
+ value: paymentAmount,
928
+ validAfter: String(validAfter),
929
+ validBefore: String(validBefore),
930
+ nonce
931
+ };
932
+ log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
933
+ signature = await evmWallet.signTypedData({
934
+ domain,
935
+ types: transferTypes,
936
+ message,
937
+ primaryType: "TransferWithAuthorization"
938
+ });
939
+ authorizationScheme = "eip3009";
940
+ }
752
941
  const paymentPayload = {
753
942
  x402Version: 2,
754
943
  resource: requirements.resource || { url },
755
944
  accepted: accept,
756
945
  payload: {
757
946
  authorization: message,
758
- signature
947
+ signature,
948
+ authorizationScheme
759
949
  },
760
950
  facilitatorUrl
761
951
  };
@@ -784,7 +974,7 @@ function createX402Client(config) {
784
974
  const sourceAta = await getAssociatedTokenAddress(
785
975
  mintPubkey,
786
976
  userPubkey,
787
- false,
977
+ true,
788
978
  programId
789
979
  );
790
980
  const destinationAta = await getAssociatedTokenAddress(