@relai-fi/x402 0.5.18 → 0.5.20

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 CHANGED
@@ -37,7 +37,8 @@ var NETWORK_CAIP2 = {
37
37
  "skale-base-sepolia": "eip155:324705682",
38
38
  "skale-bite": "eip155:103698795",
39
39
  "polygon": "eip155:137",
40
- "ethereum": "eip155:1"
40
+ "ethereum": "eip155:1",
41
+ "telos": "eip155:40"
41
42
  };
42
43
  var CAIP2_TO_NETWORK = Object.fromEntries(
43
44
  Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k])
@@ -49,7 +50,139 @@ var CHAIN_IDS = {
49
50
  "skale-base-sepolia": 324705682,
50
51
  "skale-bite": 103698795,
51
52
  "polygon": 137,
52
- "ethereum": 1
53
+ "ethereum": 1,
54
+ "telos": 40
55
+ };
56
+ var NETWORK_TOKENS = {
57
+ "solana": [
58
+ {
59
+ address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
60
+ symbol: "USDC",
61
+ name: "USD Coin",
62
+ decimals: 6
63
+ }
64
+ ],
65
+ "base": [
66
+ { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", symbol: "USDC", name: "USD Coin", decimals: 6, domainVersion: "2", isStableUsd: true }
67
+ ],
68
+ "avalanche": [
69
+ {
70
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
71
+ symbol: "USDC",
72
+ name: "USD Coin",
73
+ decimals: 6,
74
+ domainVersion: "2",
75
+ isStableUsd: true
76
+ }
77
+ ],
78
+ "telos": [
79
+ {
80
+ address: "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b",
81
+ symbol: "USDC",
82
+ name: "USD Coin",
83
+ decimals: 6,
84
+ isStableUsd: true,
85
+ standards: ["eip2612"]
86
+ }
87
+ ],
88
+ "skale-base": [
89
+ {
90
+ address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
91
+ symbol: "USDC",
92
+ name: "Bridged USDC (SKALE Bridge)",
93
+ decimals: 6,
94
+ domainVersion: "2",
95
+ isStableUsd: true
96
+ },
97
+ {
98
+ address: "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA",
99
+ symbol: "USDT",
100
+ name: "Bridged USDT (SKALE Bridge)",
101
+ decimals: 6,
102
+ domainVersion: "1",
103
+ isStableUsd: true
104
+ },
105
+ {
106
+ address: "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e",
107
+ symbol: "WBTC",
108
+ name: "Wrapped Bitcoin",
109
+ decimals: 8,
110
+ domainVersion: "1",
111
+ isStableUsd: false
112
+ },
113
+ {
114
+ address: "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486",
115
+ symbol: "WETH",
116
+ name: "Wrapped Ether",
117
+ decimals: 18,
118
+ domainVersion: "1",
119
+ isStableUsd: false
120
+ }
121
+ ],
122
+ "skale-base-sepolia": [
123
+ {
124
+ address: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
125
+ symbol: "USDC",
126
+ name: "Bridged USDC (SKALE Bridge)",
127
+ decimals: 6,
128
+ domainVersion: "2",
129
+ isStableUsd: true
130
+ },
131
+ {
132
+ address: "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf",
133
+ symbol: "USDT",
134
+ name: "Bridged USDT (SKALE Bridge)",
135
+ decimals: 6,
136
+ domainVersion: "1",
137
+ isStableUsd: true
138
+ },
139
+ {
140
+ address: "0x4512eacd4186b025186e1cf6cc0d89497c530e87",
141
+ symbol: "WBTC",
142
+ name: "Wrapped Bitcoin",
143
+ decimals: 8,
144
+ domainVersion: "1",
145
+ isStableUsd: false
146
+ },
147
+ {
148
+ address: "0xf94056bd7f6965db3757e1b145f200b7346b4fc0",
149
+ symbol: "WETH",
150
+ name: "Wrapped Ether",
151
+ decimals: 18,
152
+ domainVersion: "1",
153
+ isStableUsd: false
154
+ }
155
+ ],
156
+ "skale-bite": [
157
+ {
158
+ address: "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
159
+ symbol: "USDC",
160
+ name: "USDC",
161
+ decimals: 6,
162
+ domainVersion: "1",
163
+ isStableUsd: true
164
+ }
165
+ ],
166
+ "polygon": [
167
+ {
168
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
169
+ symbol: "USDC",
170
+ name: "USD Coin",
171
+ decimals: 6,
172
+ domainVersion: "2",
173
+ isStableUsd: true
174
+ }
175
+ ],
176
+ "ethereum": [
177
+ {
178
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
179
+ symbol: "USDC",
180
+ name: "USD Coin",
181
+ decimals: 6,
182
+ domainVersion: "2",
183
+ isStableUsd: true
184
+ }
185
+ ]
53
186
  };
54
187
  var USDC_ADDRESSES = {
55
188
  "solana": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
@@ -59,7 +192,8 @@ var USDC_ADDRESSES = {
59
192
  "skale-base-sepolia": "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
60
193
  "skale-bite": "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
61
194
  "polygon": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
62
- "ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
195
+ "ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
196
+ "telos": "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b"
63
197
  };
64
198
  var SOLANA_MAINNET_NETWORK = NETWORK_CAIP2["solana"];
65
199
  var BASE_MAINNET_NETWORK = NETWORK_CAIP2["base"];
@@ -73,13 +207,14 @@ var RELAI_NETWORKS = [
73
207
  "skale-base-sepolia",
74
208
  "skale-bite",
75
209
  "polygon",
76
- "ethereum"
210
+ "ethereum",
211
+ "telos"
77
212
  ];
78
213
  function isSolana(network) {
79
214
  return network === "solana" || network.startsWith("solana:");
80
215
  }
81
216
  function isEvm(network) {
82
- 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:");
83
218
  }
84
219
  function normalizeNetwork(network) {
85
220
  if (RELAI_NETWORKS.includes(network)) return network;
@@ -103,7 +238,8 @@ var DEFAULT_EVM_RPC_URLS = {
103
238
  "base": "https://mainnet.base.org",
104
239
  "avalanche": "https://api.avax.network/ext/bc/C/rpc",
105
240
  "polygon": "https://polygon-rpc.com",
106
- "ethereum": "https://ethereum-rpc.publicnode.com"
241
+ "ethereum": "https://ethereum-rpc.publicnode.com",
242
+ "telos": "https://rpc.telos.net"
107
243
  };
108
244
  function createX402Client(config) {
109
245
  const {
@@ -712,41 +848,93 @@ function createX402Client(config) {
712
848
  chainId,
713
849
  verifyingContract: useRelayer ? extra.relayerContract : accept.asset
714
850
  };
715
- const validAfter = 0;
716
- const validBefore = Math.floor(Date.now() / 1e3) + 3600;
717
- const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
718
- const types = {
719
- TransferWithAuthorization: [
720
- { name: "from", type: "address" },
721
- { name: "to", type: "address" },
722
- { name: "value", type: "uint256" },
723
- { name: "validAfter", type: "uint256" },
724
- { name: "validBefore", type: "uint256" },
725
- { name: "nonce", type: "bytes32" }
726
- ]
727
- };
728
- const message = {
729
- from: evmWallet.address,
730
- to: accept.payTo,
731
- value: paymentAmount,
732
- validAfter: String(validAfter),
733
- validBefore: String(validBefore),
734
- nonce
735
- };
736
- log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
737
- const signature = await evmWallet.signTypedData({
738
- domain,
739
- types,
740
- message,
741
- primaryType: "TransferWithAuthorization"
742
- });
851
+ const tokenNetworkKey = network || rawNetwork;
852
+ const networkTokens = NETWORK_TOKENS[tokenNetworkKey];
853
+ const assetLower = (accept.asset || "").toLowerCase();
854
+ const tokenInfo = networkTokens?.find((t) => t.address.toLowerCase() === assetLower) || networkTokens?.[0];
855
+ const tokenStandards = Array.isArray(tokenInfo?.standards) ? tokenInfo.standards : [];
856
+ const hasEip3009 = tokenStandards.some((s) => s.toLowerCase() === "eip3009");
857
+ const hasEip2612 = tokenStandards.some((s) => s.toLowerCase() === "eip2612");
858
+ const usePermit2612 = !hasEip3009 && hasEip2612;
859
+ let message;
860
+ let signature;
861
+ let authorizationScheme;
862
+ if (usePermit2612) {
863
+ const spender = extra.feePayer || accept.payTo;
864
+ const deadline = Math.floor(Date.now() / 1e3) + 3600;
865
+ let nonce = 0;
866
+ if (rpcUrl) {
867
+ try {
868
+ const paddedAddress = evmWallet.address.toLowerCase().replace("0x", "").padStart(64, "0");
869
+ const nonceHex = await evmRpcCall(rpcUrl, accept.asset, "0x7ecebe00" + paddedAddress);
870
+ nonce = nonceHex ? parseInt(nonceHex, 16) : 0;
871
+ } catch {
872
+ nonce = 0;
873
+ }
874
+ }
875
+ const permitTypes = {
876
+ Permit: [
877
+ { name: "owner", type: "address" },
878
+ { name: "spender", type: "address" },
879
+ { name: "value", type: "uint256" },
880
+ { name: "nonce", type: "uint256" },
881
+ { name: "deadline", type: "uint256" }
882
+ ]
883
+ };
884
+ message = {
885
+ owner: evmWallet.address,
886
+ spender,
887
+ value: paymentAmount,
888
+ nonce: String(nonce),
889
+ deadline: String(deadline)
890
+ };
891
+ log("Signing EIP-2612 permit on chain", chainId);
892
+ signature = await evmWallet.signTypedData({
893
+ domain,
894
+ types: permitTypes,
895
+ message,
896
+ primaryType: "Permit"
897
+ });
898
+ authorizationScheme = "eip2612";
899
+ } else {
900
+ const validAfter = 0;
901
+ const validBefore = Math.floor(Date.now() / 1e3) + 3600;
902
+ const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
903
+ const transferTypes = {
904
+ TransferWithAuthorization: [
905
+ { name: "from", type: "address" },
906
+ { name: "to", type: "address" },
907
+ { name: "value", type: "uint256" },
908
+ { name: "validAfter", type: "uint256" },
909
+ { name: "validBefore", type: "uint256" },
910
+ { name: "nonce", type: "bytes32" }
911
+ ]
912
+ };
913
+ message = {
914
+ from: evmWallet.address,
915
+ to: accept.payTo,
916
+ value: paymentAmount,
917
+ validAfter: String(validAfter),
918
+ validBefore: String(validBefore),
919
+ nonce
920
+ };
921
+ log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
922
+ signature = await evmWallet.signTypedData({
923
+ domain,
924
+ types: transferTypes,
925
+ message,
926
+ primaryType: "TransferWithAuthorization"
927
+ });
928
+ authorizationScheme = "eip3009";
929
+ }
743
930
  const paymentPayload = {
744
931
  x402Version: 2,
745
932
  resource: requirements.resource || { url },
746
933
  accepted: accept,
747
934
  payload: {
748
935
  authorization: message,
749
- signature
936
+ signature,
937
+ authorizationScheme
750
938
  },
751
939
  facilitatorUrl
752
940
  };
@@ -775,7 +963,7 @@ function createX402Client(config) {
775
963
  const sourceAta = await (0, import_spl_token.getAssociatedTokenAddress)(
776
964
  mintPubkey,
777
965
  userPubkey,
778
- false,
966
+ true,
779
967
  programId
780
968
  );
781
969
  const destinationAta = await (0, import_spl_token.getAssociatedTokenAddress)(