@tomo-inc/wallet-adaptor-base 0.0.17 → 0.0.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.cjs CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var walletUtils = require('@tomo-inc/wallet-utils');
4
+ var chains = require('viem/chains');
3
5
  var core = require('@wallet-standard/core');
4
6
  var walletConnectProtocol = require('@tomo-inc/wallet-connect-protocol');
5
7
  var viem = require('viem');
@@ -72,23 +74,49 @@ function uint8arrayToHex(uint8array) {
72
74
  return Array.from(uint8array, (byte) => byte.toString(16).padStart(2, "0")).join("");
73
75
  }
74
76
 
75
- // src/type.ts
76
- var ProviderProtocol = /* @__PURE__ */ ((ProviderProtocol2) => {
77
- ProviderProtocol2["EIP6963"] = "eip6963";
78
- ProviderProtocol2["WALLET_STANDARD"] = "wallet-standard";
79
- ProviderProtocol2["WALLET_CONNECT"] = "wallet-connect";
80
- ProviderProtocol2["INJECT"] = "inject";
81
- return ProviderProtocol2;
82
- })(ProviderProtocol || {});
83
- var ProviderChainType = /* @__PURE__ */ ((ProviderChainType2) => {
84
- ProviderChainType2["inject"] = "inject";
85
- ProviderChainType2["deeplink"] = "deeplink";
86
- ProviderChainType2["walletConnect"] = "walletConnect";
87
- return ProviderChainType2;
88
- })(ProviderChainType || {});
89
- var SupportedChainTypes = ["evm", "solana", "aptos", "dogecoin"];
77
+ // src/utils/wallet-config.ts
78
+ function hasWalletConfigProperties(config) {
79
+ if (!config || typeof config !== "object") {
80
+ return false;
81
+ }
82
+ return typeof config.id === "string" && typeof config.name === "string" && typeof config.icon === "string" && typeof config.iconBackground === "string";
83
+ }
84
+ function hasWagmiConnectorProperties(config) {
85
+ if (!config || typeof config !== "object") {
86
+ return false;
87
+ }
88
+ if (typeof config.createConnector === "function") {
89
+ return true;
90
+ }
91
+ const hasConnectorMethods = typeof config.connect === "function" || typeof config.disconnect === "function" || typeof config.getAccounts === "function" || typeof config.getChainId === "function";
92
+ const hasConnectorId = typeof config.id === "string" || typeof config.name === "string";
93
+ return hasConnectorMethods && hasConnectorId;
94
+ }
95
+ function isWagmiConnector(config) {
96
+ if (typeof config === "function") {
97
+ return true;
98
+ }
99
+ if (config && typeof config === "object") {
100
+ const hasWalletConfigProps = hasWalletConfigProperties(config);
101
+ if (!hasWalletConfigProps) {
102
+ return hasWagmiConnectorProperties(config);
103
+ }
104
+ }
105
+ return false;
106
+ }
90
107
 
91
- // src/wallets/detector.ts
108
+ // src/wallets/index.ts
109
+ var walletBaseUrl = "https://web3-assets.tomo.inc";
110
+ var allWallets = [];
111
+ var getAllWallets = async (baseUrl) => {
112
+ if (allWallets.length > 0) {
113
+ return allWallets;
114
+ }
115
+ const walletListResponse = await fetch((baseUrl || walletBaseUrl) + "/api/wallets");
116
+ const walletListData = await walletListResponse.json();
117
+ const walletList = allWallets = walletListData == null ? void 0 : walletListData.data;
118
+ return walletList;
119
+ };
92
120
  function getEvmExplicitInjectedProvider(flag) {
93
121
  const _window = typeof window !== "undefined" ? window : void 0;
94
122
  if (typeof _window === "undefined" || typeof _window.ethereum === "undefined") return;
@@ -133,17 +161,67 @@ var supportedWalletConfigTypes = {
133
161
  tomo: true,
134
162
  wagmi: true
135
163
  };
136
- function walletConfigAdapter(walletConfig, connectorType) {
164
+ function findWalletInDefaultConnectors(id, name, defaultWallets) {
165
+ let found = defaultWallets.find(
166
+ (wallet) => {
167
+ var _a, _b;
168
+ return ((_a = wallet.id) == null ? void 0 : _a.toLowerCase()) === id.toLowerCase() || ((_b = wallet.id) == null ? void 0 : _b.toLowerCase()) === id.toLowerCase().replace(/\s+/g, "-");
169
+ }
170
+ );
171
+ if (!found) {
172
+ const normalizedName = name.toLowerCase();
173
+ found = defaultWallets.find((wallet) => {
174
+ const walletName = wallet.name.toLowerCase();
175
+ return walletName === normalizedName || walletName.includes(normalizedName) || normalizedName.includes(walletName) || // support common wallet name variations matching
176
+ normalizedName.includes("metamask") && walletName.includes("metamask") || normalizedName.includes("coinbase") && walletName.includes("coinbase") || normalizedName.includes("safe") && walletName.includes("safe") || normalizedName.includes("walletconnect") && walletName.includes("walletconnect") || normalizedName.includes("injected") && walletName.includes("injected");
177
+ });
178
+ }
179
+ return found || null;
180
+ }
181
+ function adaptWagmiConnectorToWalletConfig(wagmiConnector, allWallets2, baseUrl) {
182
+ var _a, _b, _c, _d;
183
+ const tempConfig = { chains: [chains.mainnet] };
184
+ const connector = wagmiConnector(tempConfig);
185
+ const id = connector.id || "unknown";
186
+ const name = connector.name || "Unknown Wallet";
187
+ const defaultWallet = findWalletInDefaultConnectors(id, name, allWallets2);
188
+ const walletConfig = {
189
+ id,
190
+ name,
191
+ namespace: (defaultWallet == null ? void 0 : defaultWallet.namespace) || "eip155",
192
+ // default EVM namespace
193
+ icon: baseUrl + (defaultWallet == null ? void 0 : defaultWallet.icon) || "",
194
+ iconBackground: (defaultWallet == null ? void 0 : defaultWallet.iconBackground) || "#666666",
195
+ rdns: defaultWallet == null ? void 0 : defaultWallet.rdns,
196
+ downloadUrls: (defaultWallet == null ? void 0 : defaultWallet.downloadUrls) || {},
197
+ installed: (defaultWallet == null ? void 0 : defaultWallet.installed) || false,
198
+ flag: (defaultWallet == null ? void 0 : defaultWallet.flag) || "",
199
+ solana: {
200
+ namespace: ((_a = defaultWallet == null ? void 0 : defaultWallet.solana) == null ? void 0 : _a.namespace) || "",
201
+ flag: ((_b = defaultWallet == null ? void 0 : defaultWallet.solana) == null ? void 0 : _b.flag) || ""
202
+ },
203
+ aptos: {
204
+ namespace: ((_c = defaultWallet == null ? void 0 : defaultWallet.aptos) == null ? void 0 : _c.namespace) || "",
205
+ flag: ((_d = defaultWallet == null ? void 0 : defaultWallet.aptos) == null ? void 0 : _d.flag) || ""
206
+ },
207
+ createConnector: wagmiConnector
208
+ };
209
+ return walletConfig;
210
+ }
211
+ function walletConfigAdapter(walletConfig, connectorType, allWallets2, baseUrl) {
137
212
  switch (connectorType) {
138
213
  case "tomo":
139
214
  return walletConfig;
140
215
  case "wagmi":
141
- return null;
216
+ if (typeof walletConfig === "function") {
217
+ return adaptWagmiConnectorToWalletConfig(walletConfig, allWallets2, baseUrl);
218
+ }
219
+ return walletConfig;
142
220
  default:
143
221
  return walletConfig;
144
222
  }
145
223
  }
146
- function connectorDector(wallet) {
224
+ function tomoConnectorDector(wallet) {
147
225
  var _a, _b, _c, _d, _e, _f, _g;
148
226
  const evmNS = {
149
227
  namespace: (wallet == null ? void 0 : wallet.namespace) || "",
@@ -163,42 +241,39 @@ function connectorDector(wallet) {
163
241
  const isAptosExists = hasInjectedProvider(aptosNS);
164
242
  const isDogecoinExists = hasInjectedProvider(dogecoinNS);
165
243
  const isInstalled = isEvmExists || isSolanaExists || isAptosExists || isDogecoinExists;
244
+ const DEFAULT_PROVIDER = {
245
+ provider: void 0,
246
+ protocol: void 0,
247
+ standard: walletUtils.ProviderStandard.NORMAL
248
+ };
166
249
  const providers = {};
167
250
  if (evmNS.namespace || evmNS.flag) {
168
251
  providers.evm = isEvmExists ? {
169
252
  provider: getInjectedProvider(evmNS),
170
- protocol: "eip6963" /* EIP6963 */
171
- } : {
172
- provider: void 0,
173
- protocol: void 0
174
- };
253
+ protocol: walletUtils.ProviderProtocol.INJECT,
254
+ standard: walletUtils.ProviderStandard.EIP1193
255
+ } : DEFAULT_PROVIDER;
175
256
  }
176
257
  if (solanaNS.namespace) {
177
258
  providers.solana = isSolanaExists ? {
178
259
  provider: getInjectedProvider(solanaNS),
179
- protocol: "inject" /* INJECT */
180
- } : {
181
- provider: void 0,
182
- protocol: void 0
183
- };
260
+ protocol: walletUtils.ProviderProtocol.INJECT,
261
+ standard: walletUtils.ProviderStandard.NORMAL
262
+ } : DEFAULT_PROVIDER;
184
263
  }
185
264
  if (aptosNS.namespace) {
186
265
  providers.aptos = isAptosExists ? {
187
266
  provider: getInjectedProvider(aptosNS),
188
- protocol: "inject" /* INJECT */
189
- } : {
190
- provider: void 0,
191
- protocol: void 0
192
- };
267
+ protocol: walletUtils.ProviderProtocol.INJECT,
268
+ standard: walletUtils.ProviderStandard.NORMAL
269
+ } : DEFAULT_PROVIDER;
193
270
  }
194
271
  if (dogecoinNS.namespace) {
195
272
  providers.dogecoin = isDogecoinExists ? {
196
273
  provider: getInjectedProvider(dogecoinNS),
197
- protocol: "inject" /* INJECT */
198
- } : {
199
- provider: void 0,
200
- protocol: void 0
201
- };
274
+ protocol: walletUtils.ProviderProtocol.INJECT,
275
+ standard: walletUtils.ProviderStandard.NORMAL
276
+ } : DEFAULT_PROVIDER;
202
277
  }
203
278
  return {
204
279
  info: {
@@ -217,25 +292,53 @@ function connectorDector(wallet) {
217
292
  }
218
293
  },
219
294
  isInstalled,
220
- providers
295
+ connectors: providers
221
296
  };
222
297
  }
298
+ function wagmiConnectorDector(wallet) {
299
+ var _a, _b, _c, _d;
300
+ const tempConfig = {};
301
+ const connector = wallet.createConnector(tempConfig);
302
+ const providers = {
303
+ evm: {
304
+ provider: connector,
305
+ protocol: walletUtils.ProviderProtocol.INJECT,
306
+ standard: walletUtils.ProviderStandard.EIP1193
307
+ }
308
+ };
309
+ return {
310
+ info: {
311
+ uuid: wallet == null ? void 0 : wallet.id,
312
+ name: wallet == null ? void 0 : wallet.name,
313
+ icon: wallet == null ? void 0 : wallet.icon,
314
+ iconBackground: wallet == null ? void 0 : wallet.iconBackground,
315
+ rdns: wallet == null ? void 0 : wallet.rdns,
316
+ links: {
317
+ homepage: ((_a = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _a.qrCode) || "",
318
+ ios_install: ((_b = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _b.ios) || "",
319
+ android_install: ((_c = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _c.android) || "",
320
+ chrome_install: ((_d = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _d.chrome) || ""
321
+ }
322
+ },
323
+ isInstalled: true,
324
+ connectors: providers
325
+ };
326
+ }
327
+ function connectorDector(wallet, connectorType) {
328
+ if (connectorType === "wagmi") {
329
+ return wagmiConnectorDector(wallet);
330
+ }
331
+ return tomoConnectorDector(wallet);
332
+ }
223
333
 
224
334
  // src/wallets/defaultConnectors.ts
225
- var defaultWallets = [];
226
335
  var getDefaultConnectors = async (baseUrl) => {
227
- if (defaultWallets.length > 0) {
228
- return defaultWallets.map((wallet) => connectorDector(wallet));
229
- }
230
- const walletListResponse = await fetch((baseUrl || "https://web3-assets.tomo.inc") + "/api/wallets");
231
- const walletList = await walletListResponse.json();
232
- defaultWallets = walletList == null ? void 0 : walletList.data.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
233
- icon: (baseUrl || "https://web3-assets.tomo.inc") + wallet.icon
336
+ const walletList = await getAllWallets(baseUrl);
337
+ const defaultWallets = walletList == null ? void 0 : walletList.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
338
+ icon: (baseUrl || walletBaseUrl) + wallet.icon
234
339
  }));
235
- return defaultWallets == null ? void 0 : defaultWallets.map((wallet) => connectorDector(wallet));
340
+ return defaultWallets == null ? void 0 : defaultWallets.map((wallet) => connectorDector(wallet, "tomo"));
236
341
  };
237
-
238
- // src/wallets/wallet-eip6963.ts
239
342
  var announceEvent = "eip6963:announceProvider";
240
343
  var requestEvent = "eip6963:requestProvider";
241
344
  var walletType = "evm";
@@ -266,17 +369,18 @@ async function eip6963Wallets() {
266
369
  }
267
370
  },
268
371
  isInstalled: true,
269
- providers: {
372
+ connectors: {
270
373
  [walletType]: {
271
374
  provider,
272
- protocol: "eip6963" /* EIP6963 */
375
+ standard: walletUtils.ProviderStandard.EIP1193,
376
+ protocol: walletUtils.ProviderProtocol.INJECT
273
377
  }
274
378
  }
275
379
  });
276
380
  }
277
381
  }
278
382
  } catch (error) {
279
- console.warn(`${"eip6963" /* EIP6963 */} detect error:`, error);
383
+ console.warn(`${walletUtils.ProviderProtocol.INJECT} detect error:`, error);
280
384
  }
281
385
  }
282
386
  window.addEventListener(announceEvent, handleProviderAnnouncement);
@@ -335,10 +439,11 @@ async function walletStandardWallets() {
335
439
  }
336
440
  },
337
441
  isInstalled: true,
338
- providers: {
442
+ connectors: {
339
443
  solana: {
340
444
  provider: wallet.features,
341
- protocol: "wallet-standard" /* WALLET_STANDARD */
445
+ standard: walletUtils.ProviderStandard.WALLET_STANDARD,
446
+ protocol: walletUtils.ProviderProtocol.INJECT
342
447
  }
343
448
  }
344
449
  });
@@ -361,10 +466,11 @@ async function walletStandardWallets() {
361
466
  }
362
467
  },
363
468
  isInstalled: true,
364
- providers: {
469
+ connectors: {
365
470
  aptos: {
366
471
  provider: wallet.features,
367
- protocol: "wallet-standard" /* WALLET_STANDARD */
472
+ standard: walletUtils.ProviderStandard.WALLET_STANDARD,
473
+ protocol: walletUtils.ProviderProtocol.INJECT
368
474
  }
369
475
  }
370
476
  });
@@ -387,10 +493,11 @@ async function walletStandardWallets() {
387
493
  }
388
494
  },
389
495
  isInstalled: true,
390
- providers: {
496
+ connectors: {
391
497
  sui: {
392
498
  provider: wallet.features,
393
- protocol: "wallet-standard" /* WALLET_STANDARD */
499
+ standard: walletUtils.ProviderStandard.WALLET_STANDARD,
500
+ protocol: walletUtils.ProviderProtocol.INJECT
394
501
  }
395
502
  }
396
503
  });
@@ -1006,9 +1113,7 @@ async function walletConnectWallets(baseUrl) {
1006
1113
  if (wcWallets.length > 0) {
1007
1114
  return wcWallets.map((wallet) => convertWalletToConnector(wallet));
1008
1115
  }
1009
- const walletListResponse = await fetch(
1010
- (baseUrl || "https://web3-assets.tomo.inc") + "/api/wallets?walletId=walletConnect"
1011
- );
1116
+ const walletListResponse = await fetch((baseUrl || walletBaseUrl) + "/api/wallets?walletId=walletConnect");
1012
1117
  const walletList = await walletListResponse.json();
1013
1118
  if (((_a = walletList == null ? void 0 : walletList.data) == null ? void 0 : _a.length) === 0) {
1014
1119
  return [];
@@ -1032,15 +1137,24 @@ function convertWalletToConnector(wallet) {
1032
1137
  },
1033
1138
  isInstalled: true,
1034
1139
  // Always available
1035
- providers: {
1036
- evm: {
1037
- provider: createWalletConnectEVMProvider(walletConnectConfig == null ? void 0 : walletConnectConfig.evmNamespaces),
1038
- protocol: "wallet-connect" /* WALLET_CONNECT */
1140
+ connectors: {
1141
+ [walletUtils.ChainTypeEnum.EVM]: {
1142
+ standard: walletUtils.ProviderStandard.NORMAL,
1143
+ protocol: walletUtils.ProviderProtocol.WALLET_CONNECT,
1144
+ provider: createWalletConnectEVMProvider(walletConnectConfig == null ? void 0 : walletConnectConfig.evmNamespaces)
1039
1145
  },
1040
- solana: {
1041
- provider: createWalletConnectSolanaProvider(walletConnectConfig == null ? void 0 : walletConnectConfig.solanaNamespaces),
1042
- protocol: "wallet-connect" /* WALLET_CONNECT */
1146
+ [walletUtils.ChainTypeEnum.SOLANA]: {
1147
+ standard: walletUtils.ProviderStandard.NORMAL,
1148
+ protocol: walletUtils.ProviderProtocol.WALLET_CONNECT,
1149
+ provider: createWalletConnectSolanaProvider(walletConnectConfig == null ? void 0 : walletConnectConfig.solanaNamespaces)
1043
1150
  }
1151
+ // [ChainTypeEnum.BITCOIN]: null,
1152
+ // [ChainTypeEnum.DOGECOIN]: null,
1153
+ // [ChainTypeEnum.APTOS]: null,
1154
+ // [ChainTypeEnum.COSMOS]: null,
1155
+ // [ChainTypeEnum.TON]: null,
1156
+ // [ChainTypeEnum.TRON]: null,
1157
+ // [ChainTypeEnum.SUI]: null,
1044
1158
  }
1045
1159
  };
1046
1160
  }
@@ -1182,9 +1296,16 @@ var connect = async (connectParams, walletOptions) => {
1182
1296
  let address = "";
1183
1297
  let network = "";
1184
1298
  if (chainType === "evm") {
1185
- const res = await provider.request({ method: "eth_requestAccounts" });
1186
- address = (res == null ? void 0 : res[0]) || "";
1187
- chainId = await provider.request({ method: "eth_chainId" });
1299
+ if (provider == null ? void 0 : provider.request) {
1300
+ const res = await provider.request({ method: "eth_requestAccounts" });
1301
+ address = (res == null ? void 0 : res[0]) || "";
1302
+ chainId = await provider.request({ method: "eth_chainId" });
1303
+ } else {
1304
+ const wagmiProvider = await provider.getProvider();
1305
+ const res = await wagmiProvider.request({ method: "eth_requestAccounts" });
1306
+ address = (res == null ? void 0 : res[0]) || "";
1307
+ chainId = await provider.request({ method: "eth_chainId" });
1308
+ }
1188
1309
  }
1189
1310
  if (chainType === "solana") {
1190
1311
  let res = null;
@@ -1694,53 +1815,51 @@ var getBalance = async (token, walletOptions) => {
1694
1815
  throw new Error(`getBalance not supported in ${chainType}`);
1695
1816
  };
1696
1817
 
1697
- // src/wallets/index.ts
1698
- var getAllWallets = async (baseUrl) => {
1699
- const walletListResponse = await fetch((baseUrl || "https://web3-assets.tomo.inc") + "/api/wallets");
1700
- const walletList = await walletListResponse.json();
1701
- return walletList;
1702
- };
1703
-
1704
1818
  // src/index.ts
1705
- var walletBaseUrl = "https://embedded-wallet.tomo.inc";
1706
1819
  async function loadConnectors({
1707
1820
  chainType = "all",
1708
- recommonedConnectors,
1821
+ recommendedConnectors,
1709
1822
  connectorTypes = [],
1710
1823
  options = {
1711
1824
  baseUrl: walletBaseUrl
1712
1825
  }
1713
1826
  }) {
1714
- const recommonedWalletConfigs = recommonedConnectors || [];
1827
+ const recommonedWalletConfigs = recommendedConnectors || [];
1715
1828
  const evmWallets = await eip6963Wallets();
1716
1829
  const { solanaWallets, aptosWallets } = await walletStandardWallets();
1717
1830
  const wcWallets2 = await walletConnectWallets(options.baseUrl);
1718
- let recommonedConnectorsDetected = [];
1831
+ const allWallets2 = await getAllWallets(options.baseUrl);
1832
+ let recommendedConnectorsDetected = [];
1719
1833
  if (recommonedWalletConfigs.length > 0) {
1720
- recommonedConnectorsDetected = recommonedWalletConfigs.map((walletConfig, index) => {
1834
+ recommendedConnectorsDetected = recommonedWalletConfigs.map((walletConfig, index) => {
1721
1835
  const connectorType = connectorTypes[index];
1722
1836
  if (!supportedWalletConfigTypes[connectorType]) {
1723
1837
  throw new Error(`Unsupported wallet config type: ${connectorType}`);
1724
1838
  }
1725
- const _walletConfig = walletConfigAdapter(walletConfig, connectorType);
1726
- return __spreadProps(__spreadValues({}, connectorDector(_walletConfig)), {
1839
+ const _walletConfig = walletConfigAdapter(
1840
+ walletConfig,
1841
+ connectorType,
1842
+ allWallets2,
1843
+ options.baseUrl || walletBaseUrl
1844
+ );
1845
+ return __spreadProps(__spreadValues({}, connectorDector(_walletConfig, connectorType)), {
1727
1846
  recommoned: true
1728
1847
  });
1729
1848
  });
1730
1849
  }
1731
1850
  const defaultConnectors = await getDefaultConnectors(options.baseUrl);
1732
- const connectorsFromConfig = uniqueConnectors([...recommonedConnectorsDetected, ...defaultConnectors]);
1851
+ const connectorsFromConfig = uniqueConnectors([...recommendedConnectorsDetected, ...defaultConnectors]);
1733
1852
  const connectorsDetecteds = [...evmWallets, ...solanaWallets, ...aptosWallets, ...wcWallets2];
1734
1853
  for (const connector of connectorsDetecteds) {
1735
1854
  const _connector = connectorsFromConfig.find((c) => c.info.name === connector.info.name);
1736
1855
  if (_connector) {
1737
1856
  _connector.isInstalled = true;
1738
- _connector.providers = __spreadValues(__spreadValues({}, _connector.providers), connector.providers);
1857
+ _connector.connectors = __spreadValues(__spreadValues({}, _connector.connectors), connector.connectors);
1739
1858
  } else {
1740
1859
  connectorsFromConfig.push(connector);
1741
1860
  }
1742
1861
  }
1743
- const allConnectors = connectorsFromConfig.filter((wallet) => chainType !== "all" ? !!wallet.providers[chainType] : true).sort((a, b) => {
1862
+ const allConnectors = connectorsFromConfig.filter((wallet) => chainType !== "all" ? !!wallet.connectors[chainType] : true).sort((a, b) => {
1744
1863
  if (a.recommoned && !b.recommoned) return -1;
1745
1864
  if (!a.recommoned && b.recommoned) return 1;
1746
1865
  if (a.isInstalled && !b.isInstalled) return -1;
@@ -1749,13 +1868,10 @@ async function loadConnectors({
1749
1868
  });
1750
1869
  return {
1751
1870
  all: allConnectors,
1752
- recommoned: recommonedConnectorsDetected
1871
+ recommoned: recommendedConnectorsDetected
1753
1872
  };
1754
1873
  }
1755
1874
 
1756
- exports.ProviderChainType = ProviderChainType;
1757
- exports.ProviderProtocol = ProviderProtocol;
1758
- exports.SupportedChainTypes = SupportedChainTypes;
1759
1875
  exports.addChain = addChain;
1760
1876
  exports.connect = connect;
1761
1877
  exports.connectMobile = connectMobile;
@@ -1763,8 +1879,10 @@ exports.disconnect = disconnect;
1763
1879
  exports.getAllWallets = getAllWallets;
1764
1880
  exports.getBalance = getBalance;
1765
1881
  exports.isMobile = isMobile;
1882
+ exports.isWagmiConnector = isWagmiConnector;
1766
1883
  exports.loadConnectors = loadConnectors;
1767
1884
  exports.setWalletConnectConfig = setWalletConnectConfig;
1768
1885
  exports.signInWithWallet = signInWithWallet;
1769
1886
  exports.signMessage = signMessage;
1770
1887
  exports.switchChain = switchChain;
1888
+ exports.walletBaseUrl = walletBaseUrl;
package/dist/index.d.cts CHANGED
@@ -1,18 +1,8 @@
1
+ import { ChainTypeEnum, ProviderProtocol, ProviderStandard } from '@tomo-inc/wallet-utils';
2
+
1
3
  type WalletProvider = any;
2
- declare enum ProviderProtocol {
3
- EIP6963 = "eip6963",
4
- WALLET_STANDARD = "wallet-standard",
5
- WALLET_CONNECT = "wallet-connect",
6
- INJECT = "inject"
7
- }
8
- declare enum ProviderChainType {
9
- inject = "inject",
10
- deeplink = "deeplink",
11
- walletConnect = "walletConnect"
12
- }
13
4
  type WalletConnectorType = "wagmi" | "tomo";
14
- type AdaptorChainType = "all" | "evm" | "solana" | "aptos" | "dogecoin";
15
- declare const SupportedChainTypes: string[];
5
+ type AdaptorChainType = ChainTypeEnum | "all";
16
6
  interface WalletInfo {
17
7
  uuid: string;
18
8
  name: string;
@@ -45,19 +35,16 @@ interface WalletInfo {
45
35
  };
46
36
  }
47
37
  interface ConnectorProvider {
48
- provider: any;
38
+ provider: WalletProvider;
49
39
  protocol: ProviderProtocol;
40
+ standard: ProviderStandard;
50
41
  }
42
+ type ConnectorProviders = Partial<Record<ChainTypeEnum, ConnectorProvider | null>>;
51
43
  interface Connector {
52
44
  info: WalletInfo;
53
45
  isInstalled?: boolean;
54
46
  recommoned?: boolean;
55
- providers: {
56
- evm?: ConnectorProvider;
57
- solana?: ConnectorProvider;
58
- aptos?: ConnectorProvider;
59
- dogecoin?: ConnectorProvider;
60
- };
47
+ connectors: Partial<Record<ChainTypeEnum, ConnectorProvider | null>>;
61
48
  }
62
49
  interface ConnectParams {
63
50
  dappLink: string;
@@ -156,6 +143,25 @@ type WalletConfig = {
156
143
  };
157
144
  type WagmiWalletConfig = any;
158
145
 
146
+ /**
147
+ * Detect if the given config is a wagmi connector
148
+ * Wagmi connector is usually a function (CreateConnectorFn) with specific properties
149
+ *
150
+ * @param config - The wallet config to check (WalletConfig | WagmiWalletConfig)
151
+ * @returns true if the config is a wagmi connector, false otherwise
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * import { isWagmiConnector } from '@tomo-inc/wallet-adaptor-base';
156
+ *
157
+ * const connector = injected({ target: 'metamask' });
158
+ * if (isWagmiConnector(connector)) {
159
+ * // Handle wagmi connector
160
+ * }
161
+ * ```
162
+ */
163
+ declare function isWagmiConnector(config: WalletConfig | WagmiWalletConfig): boolean;
164
+
159
165
  /**
160
166
  * Set WalletConnect configuration
161
167
  * Must be called before using WalletConnect wallet
@@ -215,11 +221,12 @@ declare const signMessage: (data: {
215
221
  isInstalled?: boolean;
216
222
  }) => Promise<string>;
217
223
 
224
+ declare const walletBaseUrl = "https://web3-assets.tomo.inc";
218
225
  declare const getAllWallets: (baseUrl?: string) => Promise<any>;
219
226
 
220
- declare function loadConnectors({ chainType, recommonedConnectors, connectorTypes, options, }: {
227
+ declare function loadConnectors({ chainType, recommendedConnectors, connectorTypes, options, }: {
221
228
  chainType?: AdaptorChainType;
222
- recommonedConnectors?: (WalletConfig | WagmiWalletConfig)[];
229
+ recommendedConnectors?: (WalletConfig | WagmiWalletConfig)[];
223
230
  connectorTypes?: WalletConnectorType[];
224
231
  options?: {
225
232
  baseUrl?: string;
@@ -229,4 +236,4 @@ declare function loadConnectors({ chainType, recommonedConnectors, connectorType
229
236
  recommoned: Connector[];
230
237
  }>;
231
238
 
232
- export { type AdaptorChainType, type BalanceParams, type ChainInfo, type ConnectParams, type Connector, type ConnectorProvider, type ITokenInfo, ProviderChainType, ProviderProtocol, type SignInParams, SupportedChainTypes, type WalletConfig, type WalletConnectConfig, type WalletConnectorType, type WalletInfo, type WalletOptions, type WalletProvider, addChain, connect, connectMobile, disconnect, getAllWallets, getBalance, isMobile, loadConnectors, setWalletConnectConfig, signInWithWallet, signMessage, switchChain };
239
+ export { type AdaptorChainType, type BalanceParams, type ChainInfo, type ConnectParams, type Connector, type ConnectorProvider, type ConnectorProviders, type ITokenInfo, type SignInParams, type WalletConfig, type WalletConnectConfig, type WalletConnectorType, type WalletInfo, type WalletOptions, type WalletProvider, addChain, connect, connectMobile, disconnect, getAllWallets, getBalance, isMobile, isWagmiConnector, loadConnectors, setWalletConnectConfig, signInWithWallet, signMessage, switchChain, walletBaseUrl };
package/dist/index.d.ts CHANGED
@@ -1,18 +1,8 @@
1
+ import { ChainTypeEnum, ProviderProtocol, ProviderStandard } from '@tomo-inc/wallet-utils';
2
+
1
3
  type WalletProvider = any;
2
- declare enum ProviderProtocol {
3
- EIP6963 = "eip6963",
4
- WALLET_STANDARD = "wallet-standard",
5
- WALLET_CONNECT = "wallet-connect",
6
- INJECT = "inject"
7
- }
8
- declare enum ProviderChainType {
9
- inject = "inject",
10
- deeplink = "deeplink",
11
- walletConnect = "walletConnect"
12
- }
13
4
  type WalletConnectorType = "wagmi" | "tomo";
14
- type AdaptorChainType = "all" | "evm" | "solana" | "aptos" | "dogecoin";
15
- declare const SupportedChainTypes: string[];
5
+ type AdaptorChainType = ChainTypeEnum | "all";
16
6
  interface WalletInfo {
17
7
  uuid: string;
18
8
  name: string;
@@ -45,19 +35,16 @@ interface WalletInfo {
45
35
  };
46
36
  }
47
37
  interface ConnectorProvider {
48
- provider: any;
38
+ provider: WalletProvider;
49
39
  protocol: ProviderProtocol;
40
+ standard: ProviderStandard;
50
41
  }
42
+ type ConnectorProviders = Partial<Record<ChainTypeEnum, ConnectorProvider | null>>;
51
43
  interface Connector {
52
44
  info: WalletInfo;
53
45
  isInstalled?: boolean;
54
46
  recommoned?: boolean;
55
- providers: {
56
- evm?: ConnectorProvider;
57
- solana?: ConnectorProvider;
58
- aptos?: ConnectorProvider;
59
- dogecoin?: ConnectorProvider;
60
- };
47
+ connectors: Partial<Record<ChainTypeEnum, ConnectorProvider | null>>;
61
48
  }
62
49
  interface ConnectParams {
63
50
  dappLink: string;
@@ -156,6 +143,25 @@ type WalletConfig = {
156
143
  };
157
144
  type WagmiWalletConfig = any;
158
145
 
146
+ /**
147
+ * Detect if the given config is a wagmi connector
148
+ * Wagmi connector is usually a function (CreateConnectorFn) with specific properties
149
+ *
150
+ * @param config - The wallet config to check (WalletConfig | WagmiWalletConfig)
151
+ * @returns true if the config is a wagmi connector, false otherwise
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * import { isWagmiConnector } from '@tomo-inc/wallet-adaptor-base';
156
+ *
157
+ * const connector = injected({ target: 'metamask' });
158
+ * if (isWagmiConnector(connector)) {
159
+ * // Handle wagmi connector
160
+ * }
161
+ * ```
162
+ */
163
+ declare function isWagmiConnector(config: WalletConfig | WagmiWalletConfig): boolean;
164
+
159
165
  /**
160
166
  * Set WalletConnect configuration
161
167
  * Must be called before using WalletConnect wallet
@@ -215,11 +221,12 @@ declare const signMessage: (data: {
215
221
  isInstalled?: boolean;
216
222
  }) => Promise<string>;
217
223
 
224
+ declare const walletBaseUrl = "https://web3-assets.tomo.inc";
218
225
  declare const getAllWallets: (baseUrl?: string) => Promise<any>;
219
226
 
220
- declare function loadConnectors({ chainType, recommonedConnectors, connectorTypes, options, }: {
227
+ declare function loadConnectors({ chainType, recommendedConnectors, connectorTypes, options, }: {
221
228
  chainType?: AdaptorChainType;
222
- recommonedConnectors?: (WalletConfig | WagmiWalletConfig)[];
229
+ recommendedConnectors?: (WalletConfig | WagmiWalletConfig)[];
223
230
  connectorTypes?: WalletConnectorType[];
224
231
  options?: {
225
232
  baseUrl?: string;
@@ -229,4 +236,4 @@ declare function loadConnectors({ chainType, recommonedConnectors, connectorType
229
236
  recommoned: Connector[];
230
237
  }>;
231
238
 
232
- export { type AdaptorChainType, type BalanceParams, type ChainInfo, type ConnectParams, type Connector, type ConnectorProvider, type ITokenInfo, ProviderChainType, ProviderProtocol, type SignInParams, SupportedChainTypes, type WalletConfig, type WalletConnectConfig, type WalletConnectorType, type WalletInfo, type WalletOptions, type WalletProvider, addChain, connect, connectMobile, disconnect, getAllWallets, getBalance, isMobile, loadConnectors, setWalletConnectConfig, signInWithWallet, signMessage, switchChain };
239
+ export { type AdaptorChainType, type BalanceParams, type ChainInfo, type ConnectParams, type Connector, type ConnectorProvider, type ConnectorProviders, type ITokenInfo, type SignInParams, type WalletConfig, type WalletConnectConfig, type WalletConnectorType, type WalletInfo, type WalletOptions, type WalletProvider, addChain, connect, connectMobile, disconnect, getAllWallets, getBalance, isMobile, isWagmiConnector, loadConnectors, setWalletConnectConfig, signInWithWallet, signMessage, switchChain, walletBaseUrl };