@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.
@@ -41,7 +41,8 @@ var NETWORK_CAIP2 = {
41
41
  "skale-base-sepolia": "eip155:324705682",
42
42
  "skale-bite": "eip155:103698795",
43
43
  "polygon": "eip155:137",
44
- "ethereum": "eip155:1"
44
+ "ethereum": "eip155:1",
45
+ "telos": "eip155:40"
45
46
  };
46
47
  var CAIP2_TO_NETWORK = Object.fromEntries(
47
48
  Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k])
@@ -53,7 +54,139 @@ var CHAIN_IDS = {
53
54
  "skale-base-sepolia": 324705682,
54
55
  "skale-bite": 103698795,
55
56
  "polygon": 137,
56
- "ethereum": 1
57
+ "ethereum": 1,
58
+ "telos": 40
59
+ };
60
+ var NETWORK_TOKENS = {
61
+ "solana": [
62
+ {
63
+ address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
64
+ symbol: "USDC",
65
+ name: "USD Coin",
66
+ decimals: 6
67
+ }
68
+ ],
69
+ "base": [
70
+ { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", symbol: "USDC", name: "USD Coin", decimals: 6, domainVersion: "2", isStableUsd: true }
71
+ ],
72
+ "avalanche": [
73
+ {
74
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
75
+ symbol: "USDC",
76
+ name: "USD Coin",
77
+ decimals: 6,
78
+ domainVersion: "2",
79
+ isStableUsd: true
80
+ }
81
+ ],
82
+ "telos": [
83
+ {
84
+ address: "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b",
85
+ symbol: "USDC",
86
+ name: "USD Coin",
87
+ decimals: 6,
88
+ isStableUsd: true,
89
+ standards: ["eip2612"]
90
+ }
91
+ ],
92
+ "skale-base": [
93
+ {
94
+ address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
95
+ symbol: "USDC",
96
+ name: "Bridged USDC (SKALE Bridge)",
97
+ decimals: 6,
98
+ domainVersion: "2",
99
+ isStableUsd: true
100
+ },
101
+ {
102
+ address: "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA",
103
+ symbol: "USDT",
104
+ name: "Bridged USDT (SKALE Bridge)",
105
+ decimals: 6,
106
+ domainVersion: "1",
107
+ isStableUsd: true
108
+ },
109
+ {
110
+ address: "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e",
111
+ symbol: "WBTC",
112
+ name: "Wrapped Bitcoin",
113
+ decimals: 8,
114
+ domainVersion: "1",
115
+ isStableUsd: false
116
+ },
117
+ {
118
+ address: "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486",
119
+ symbol: "WETH",
120
+ name: "Wrapped Ether",
121
+ decimals: 18,
122
+ domainVersion: "1",
123
+ isStableUsd: false
124
+ }
125
+ ],
126
+ "skale-base-sepolia": [
127
+ {
128
+ address: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
129
+ symbol: "USDC",
130
+ name: "Bridged USDC (SKALE Bridge)",
131
+ decimals: 6,
132
+ domainVersion: "2",
133
+ isStableUsd: true
134
+ },
135
+ {
136
+ address: "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf",
137
+ symbol: "USDT",
138
+ name: "Bridged USDT (SKALE Bridge)",
139
+ decimals: 6,
140
+ domainVersion: "1",
141
+ isStableUsd: true
142
+ },
143
+ {
144
+ address: "0x4512eacd4186b025186e1cf6cc0d89497c530e87",
145
+ symbol: "WBTC",
146
+ name: "Wrapped Bitcoin",
147
+ decimals: 8,
148
+ domainVersion: "1",
149
+ isStableUsd: false
150
+ },
151
+ {
152
+ address: "0xf94056bd7f6965db3757e1b145f200b7346b4fc0",
153
+ symbol: "WETH",
154
+ name: "Wrapped Ether",
155
+ decimals: 18,
156
+ domainVersion: "1",
157
+ isStableUsd: false
158
+ }
159
+ ],
160
+ "skale-bite": [
161
+ {
162
+ address: "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
163
+ symbol: "USDC",
164
+ name: "USDC",
165
+ decimals: 6,
166
+ domainVersion: "1",
167
+ isStableUsd: true
168
+ }
169
+ ],
170
+ "polygon": [
171
+ {
172
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
173
+ symbol: "USDC",
174
+ name: "USD Coin",
175
+ decimals: 6,
176
+ domainVersion: "2",
177
+ isStableUsd: true
178
+ }
179
+ ],
180
+ "ethereum": [
181
+ {
182
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
183
+ symbol: "USDC",
184
+ name: "USD Coin",
185
+ decimals: 6,
186
+ domainVersion: "2",
187
+ isStableUsd: true
188
+ }
189
+ ]
57
190
  };
58
191
  var USDC_ADDRESSES = {
59
192
  "solana": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
@@ -63,7 +196,8 @@ var USDC_ADDRESSES = {
63
196
  "skale-base-sepolia": "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
64
197
  "skale-bite": "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
65
198
  "polygon": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
66
- "ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
199
+ "ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
200
+ "telos": "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b"
67
201
  };
68
202
  var EXPLORER_TX_URL = {
69
203
  "solana": (tx) => `https://solscan.io/tx/${tx}`,
@@ -73,7 +207,8 @@ var EXPLORER_TX_URL = {
73
207
  "skale-base-sepolia": (tx) => `https://base-sepolia-testnet-explorer.skalenodes.com/tx/${tx}`,
74
208
  "skale-bite": (tx) => `https://base-sepolia-testnet.explorer.skalenodes.com/tx/${tx}`,
75
209
  "polygon": (tx) => `https://polygonscan.com/tx/${tx}`,
76
- "ethereum": (tx) => `https://etherscan.io/tx/${tx}`
210
+ "ethereum": (tx) => `https://etherscan.io/tx/${tx}`,
211
+ "telos": (tx) => `https://teloscan.io/tx/${tx}`
77
212
  };
78
213
  var NETWORK_LABELS = {
79
214
  "solana": "Solana",
@@ -83,7 +218,8 @@ var NETWORK_LABELS = {
83
218
  "skale-base-sepolia": "SKALE Base Sepolia",
84
219
  "skale-bite": "SKALE BITE V2",
85
220
  "polygon": "Polygon",
86
- "ethereum": "Ethereum"
221
+ "ethereum": "Ethereum",
222
+ "telos": "Telos EVM"
87
223
  };
88
224
  var SOLANA_MAINNET_NETWORK = NETWORK_CAIP2["solana"];
89
225
  var BASE_MAINNET_NETWORK = NETWORK_CAIP2["base"];
@@ -97,13 +233,14 @@ var RELAI_NETWORKS = [
97
233
  "skale-base-sepolia",
98
234
  "skale-bite",
99
235
  "polygon",
100
- "ethereum"
236
+ "ethereum",
237
+ "telos"
101
238
  ];
102
239
  function isSolana(network) {
103
240
  return network === "solana" || network.startsWith("solana:");
104
241
  }
105
242
  function isEvm(network) {
106
- return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum"].includes(network) || network.startsWith("eip155:");
243
+ return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum", "telos"].includes(network) || network.startsWith("eip155:");
107
244
  }
108
245
  function normalizeNetwork(network) {
109
246
  if (RELAI_NETWORKS.includes(network)) return network;
@@ -127,7 +264,8 @@ var DEFAULT_EVM_RPC_URLS = {
127
264
  "base": "https://mainnet.base.org",
128
265
  "avalanche": "https://api.avax.network/ext/bc/C/rpc",
129
266
  "polygon": "https://polygon-rpc.com",
130
- "ethereum": "https://ethereum-rpc.publicnode.com"
267
+ "ethereum": "https://ethereum-rpc.publicnode.com",
268
+ "telos": "https://rpc.telos.net"
131
269
  };
132
270
  function createX402Client(config) {
133
271
  const {
@@ -736,41 +874,93 @@ function createX402Client(config) {
736
874
  chainId,
737
875
  verifyingContract: useRelayer ? extra.relayerContract : accept.asset
738
876
  };
739
- const validAfter = 0;
740
- const validBefore = Math.floor(Date.now() / 1e3) + 3600;
741
- const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
742
- const types = {
743
- TransferWithAuthorization: [
744
- { name: "from", type: "address" },
745
- { name: "to", type: "address" },
746
- { name: "value", type: "uint256" },
747
- { name: "validAfter", type: "uint256" },
748
- { name: "validBefore", type: "uint256" },
749
- { name: "nonce", type: "bytes32" }
750
- ]
751
- };
752
- const message = {
753
- from: evmWallet.address,
754
- to: accept.payTo,
755
- value: paymentAmount,
756
- validAfter: String(validAfter),
757
- validBefore: String(validBefore),
758
- nonce
759
- };
760
- log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
761
- const signature = await evmWallet.signTypedData({
762
- domain,
763
- types,
764
- message,
765
- primaryType: "TransferWithAuthorization"
766
- });
877
+ const tokenNetworkKey = network || rawNetwork;
878
+ const networkTokens = NETWORK_TOKENS[tokenNetworkKey];
879
+ const assetLower = (accept.asset || "").toLowerCase();
880
+ const tokenInfo = networkTokens?.find((t) => t.address.toLowerCase() === assetLower) || networkTokens?.[0];
881
+ const tokenStandards = Array.isArray(tokenInfo?.standards) ? tokenInfo.standards : [];
882
+ const hasEip3009 = tokenStandards.some((s) => s.toLowerCase() === "eip3009");
883
+ const hasEip2612 = tokenStandards.some((s) => s.toLowerCase() === "eip2612");
884
+ const usePermit2612 = !hasEip3009 && hasEip2612;
885
+ let message;
886
+ let signature;
887
+ let authorizationScheme;
888
+ if (usePermit2612) {
889
+ const spender = extra.feePayer || accept.payTo;
890
+ const deadline = Math.floor(Date.now() / 1e3) + 3600;
891
+ let nonce = 0;
892
+ if (rpcUrl) {
893
+ try {
894
+ const paddedAddress = evmWallet.address.toLowerCase().replace("0x", "").padStart(64, "0");
895
+ const nonceHex = await evmRpcCall(rpcUrl, accept.asset, "0x7ecebe00" + paddedAddress);
896
+ nonce = nonceHex ? parseInt(nonceHex, 16) : 0;
897
+ } catch {
898
+ nonce = 0;
899
+ }
900
+ }
901
+ const permitTypes = {
902
+ Permit: [
903
+ { name: "owner", type: "address" },
904
+ { name: "spender", type: "address" },
905
+ { name: "value", type: "uint256" },
906
+ { name: "nonce", type: "uint256" },
907
+ { name: "deadline", type: "uint256" }
908
+ ]
909
+ };
910
+ message = {
911
+ owner: evmWallet.address,
912
+ spender,
913
+ value: paymentAmount,
914
+ nonce: String(nonce),
915
+ deadline: String(deadline)
916
+ };
917
+ log("Signing EIP-2612 permit on chain", chainId);
918
+ signature = await evmWallet.signTypedData({
919
+ domain,
920
+ types: permitTypes,
921
+ message,
922
+ primaryType: "Permit"
923
+ });
924
+ authorizationScheme = "eip2612";
925
+ } else {
926
+ const validAfter = 0;
927
+ const validBefore = Math.floor(Date.now() / 1e3) + 3600;
928
+ const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
929
+ const transferTypes = {
930
+ TransferWithAuthorization: [
931
+ { name: "from", type: "address" },
932
+ { name: "to", type: "address" },
933
+ { name: "value", type: "uint256" },
934
+ { name: "validAfter", type: "uint256" },
935
+ { name: "validBefore", type: "uint256" },
936
+ { name: "nonce", type: "bytes32" }
937
+ ]
938
+ };
939
+ message = {
940
+ from: evmWallet.address,
941
+ to: accept.payTo,
942
+ value: paymentAmount,
943
+ validAfter: String(validAfter),
944
+ validBefore: String(validBefore),
945
+ nonce
946
+ };
947
+ log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
948
+ signature = await evmWallet.signTypedData({
949
+ domain,
950
+ types: transferTypes,
951
+ message,
952
+ primaryType: "TransferWithAuthorization"
953
+ });
954
+ authorizationScheme = "eip3009";
955
+ }
767
956
  const paymentPayload = {
768
957
  x402Version: 2,
769
958
  resource: requirements.resource || { url },
770
959
  accepted: accept,
771
960
  payload: {
772
961
  authorization: message,
773
- signature
962
+ signature,
963
+ authorizationScheme
774
964
  },
775
965
  facilitatorUrl
776
966
  };
@@ -799,7 +989,7 @@ function createX402Client(config) {
799
989
  const sourceAta = await (0, import_spl_token.getAssociatedTokenAddress)(
800
990
  mintPubkey,
801
991
  userPubkey,
802
- false,
992
+ true,
803
993
  programId
804
994
  );
805
995
  const destinationAta = await (0, import_spl_token.getAssociatedTokenAddress)(