@dynamic-labs/multi-wallet 0.17.0-RC.7 → 0.17.0-RC.9

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.
Files changed (233) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/package.json +8 -14
  3. package/src/index.cjs +0 -57
  4. package/src/index.d.ts +0 -13
  5. package/src/index.js +1 -18
  6. package/src/multi-wallet.cjs +27 -87
  7. package/src/multi-wallet.d.ts +0 -1
  8. package/src/multi-wallet.js +25 -84
  9. package/src/types.d.ts +2 -23
  10. package/src/utils/getApiProviders.cjs +15 -0
  11. package/src/utils/getApiProviders.d.ts +10 -0
  12. package/src/utils/getApiProviders.js +11 -0
  13. package/src/utils/message.cjs +3 -4
  14. package/src/utils/message.js +1 -2
  15. package/src/wallets/algorand/MyAlgoWalletConnector.cjs +3 -3
  16. package/src/wallets/algorand/MyAlgoWalletConnector.js +1 -1
  17. package/src/wallets/constants.cjs +0 -2
  18. package/src/wallets/constants.js +1 -2
  19. package/src/wallets/cosmos/KeplrWalletConnect.cjs +16 -17
  20. package/src/wallets/cosmos/KeplrWalletConnect.d.ts +9 -5
  21. package/src/wallets/cosmos/KeplrWalletConnect.js +9 -10
  22. package/src/wallets/cosmos/KeplrWalletConnector.cjs +13 -5
  23. package/src/wallets/cosmos/KeplrWalletConnector.d.ts +6 -4
  24. package/src/wallets/cosmos/KeplrWalletConnector.js +13 -5
  25. package/src/wallets/cosmos/wcClient.lib.cjs +141 -0
  26. package/src/wallets/{clients/walletConnect/walletConnect.d.ts → cosmos/wcClient.lib.d.ts} +8 -11
  27. package/src/wallets/cosmos/wcClient.lib.js +126 -0
  28. package/src/wallets/flow/FlowWalletConnector.cjs +7 -8
  29. package/src/wallets/flow/FlowWalletConnector.js +2 -3
  30. package/src/wallets/flow/lilico.cjs +2 -2
  31. package/src/wallets/flow/lilico.js +1 -1
  32. package/src/wallets/solana/CoinbaseSolana.cjs +8 -11
  33. package/src/wallets/solana/CoinbaseSolana.d.ts +1 -3
  34. package/src/wallets/solana/CoinbaseSolana.js +8 -11
  35. package/src/wallets/solana/glow.cjs +8 -11
  36. package/src/wallets/solana/glow.d.ts +1 -3
  37. package/src/wallets/solana/glow.js +8 -11
  38. package/src/wallets/solana/injected/BraveSol.cjs +2 -1
  39. package/src/wallets/solana/injected/BraveSol.js +2 -1
  40. package/src/wallets/solana/phantom-ledger.cjs +5 -5
  41. package/src/wallets/solana/phantom-ledger.js +1 -1
  42. package/src/wallets/solana/phantom.cjs +11 -15
  43. package/src/wallets/solana/phantom.d.ts +1 -3
  44. package/src/wallets/solana/phantom.js +9 -13
  45. package/src/wallets/solana/slope.cjs +4 -4
  46. package/src/wallets/solana/slope.js +1 -1
  47. package/src/wallets/solana/solProviderHelper.cjs +49 -51
  48. package/src/wallets/solana/solProviderHelper.d.ts +20 -20
  49. package/src/wallets/solana/solProviderHelper.js +48 -50
  50. package/src/wallets/solana/solWalletConnector.cjs +2 -2
  51. package/src/wallets/solana/solWalletConnector.js +1 -1
  52. package/src/wallets/solana/solflare.cjs +6 -7
  53. package/src/wallets/solana/solflare.d.ts +0 -2
  54. package/src/wallets/solana/solflare.js +6 -7
  55. package/src/wallets/starknet/braavos.cjs +2 -2
  56. package/src/wallets/starknet/braavos.js +1 -1
  57. package/src/wallets/starknet/starknetWalletConnector.cjs +5 -6
  58. package/src/wallets/starknet/starknetWalletConnector.js +2 -3
  59. package/src/wallets/window.d.ts +10 -22
  60. package/src/errors.cjs +0 -66
  61. package/src/errors.d.ts +0 -34
  62. package/src/errors.js +0 -54
  63. package/src/utils/CancellablePromise/CancellablePromise.cjs +0 -33
  64. package/src/utils/CancellablePromise/CancellablePromise.d.ts +0 -9
  65. package/src/utils/CancellablePromise/CancellablePromise.js +0 -29
  66. package/src/utils/CancellablePromise/index.d.ts +0 -1
  67. package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.cjs +0 -54
  68. package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.d.ts +0 -3
  69. package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.js +0 -50
  70. package/src/utils/assignConfirmationScreenToProvider/index.d.ts +0 -1
  71. package/src/utils/encoding.cjs +0 -18
  72. package/src/utils/encoding.d.ts +0 -4
  73. package/src/utils/encoding.js +0 -12
  74. package/src/utils/findProvider/findProvider.cjs +0 -7
  75. package/src/utils/findProvider/findProvider.d.ts +0 -2
  76. package/src/utils/findProvider/findProvider.js +0 -3
  77. package/src/utils/findProvider/index.d.ts +0 -1
  78. package/src/utils/getChainInfo/getChainInfo.cjs +0 -59
  79. package/src/utils/getChainInfo/getChainInfo.d.ts +0 -2
  80. package/src/utils/getChainInfo/getChainInfo.js +0 -55
  81. package/src/utils/getChainInfo/index.d.ts +0 -1
  82. package/src/utils/getWalletConnectorByName.cjs +0 -19
  83. package/src/utils/getWalletConnectorByName.d.ts +0 -2
  84. package/src/utils/getWalletConnectorByName.js +0 -15
  85. package/src/utils/isEmailOTPWalletConnector/index.d.ts +0 -1
  86. package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.cjs +0 -7
  87. package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.d.ts +0 -2
  88. package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.js +0 -3
  89. package/src/utils/isEmailWalletConnector/index.d.ts +0 -1
  90. package/src/utils/isEmailWalletConnector/isEmailWalletConnector.cjs +0 -7
  91. package/src/utils/isEmailWalletConnector/isEmailWalletConnector.d.ts +0 -2
  92. package/src/utils/isEmailWalletConnector/isEmailWalletConnector.js +0 -3
  93. package/src/utils/isFunction/index.d.ts +0 -1
  94. package/src/utils/isFunction/isFunction.cjs +0 -8
  95. package/src/utils/isFunction/isFunction.d.ts +0 -1
  96. package/src/utils/isFunction/isFunction.js +0 -4
  97. package/src/utils/isMobile.cjs +0 -54
  98. package/src/utils/isMobile.d.ts +0 -13
  99. package/src/utils/isMobile.js +0 -46
  100. package/src/utils/isSameAddress/index.d.ts +0 -1
  101. package/src/utils/isSameAddress/isSameAddress.cjs +0 -9
  102. package/src/utils/isSameAddress/isSameAddress.d.ts +0 -1
  103. package/src/utils/isSameAddress/isSameAddress.js +0 -5
  104. package/src/utils/isSameAddress/utils/index.d.ts +0 -1
  105. package/src/utils/isSameAddress/utils/normalizeAddress/index.d.ts +0 -1
  106. package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.cjs +0 -17
  107. package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.d.ts +0 -1
  108. package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.js +0 -13
  109. package/src/utils/isSocialWalletConnector/index.d.ts +0 -1
  110. package/src/utils/isSocialWalletConnector/isSocialWalletConnector.cjs +0 -7
  111. package/src/utils/isSocialWalletConnector/isSocialWalletConnector.d.ts +0 -2
  112. package/src/utils/isSocialWalletConnector/isSocialWalletConnector.js +0 -3
  113. package/src/utils/isUnsupportedProviderError/index.d.ts +0 -1
  114. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.cjs +0 -13
  115. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +0 -6
  116. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.js +0 -9
  117. package/src/utils/logger.cjs +0 -9
  118. package/src/utils/logger.d.ts +0 -2
  119. package/src/utils/logger.js +0 -5
  120. package/src/utils/normalizeWalletName/index.d.ts +0 -1
  121. package/src/utils/normalizeWalletName/normalizeWalletName.cjs +0 -7
  122. package/src/utils/normalizeWalletName/normalizeWalletName.d.ts +0 -1
  123. package/src/utils/normalizeWalletName/normalizeWalletName.js +0 -3
  124. package/src/utils/shouldLowercaseAddress.cjs +0 -11
  125. package/src/utils/shouldLowercaseAddress.d.ts +0 -1
  126. package/src/utils/shouldLowercaseAddress.js +0 -7
  127. package/src/utils/walletConnect.cjs +0 -31
  128. package/src/utils/walletConnect.d.ts +0 -5
  129. package/src/utils/walletConnect.js +0 -27
  130. package/src/wallets/ProviderLookup.cjs +0 -18
  131. package/src/wallets/ProviderLookup.d.ts +0 -4
  132. package/src/wallets/ProviderLookup.js +0 -14
  133. package/src/wallets/clients/coinbase/coinbase.cjs +0 -73
  134. package/src/wallets/clients/coinbase/coinbase.d.ts +0 -6
  135. package/src/wallets/clients/coinbase/coinbase.js +0 -66
  136. package/src/wallets/clients/coinbase/index.d.ts +0 -2
  137. package/src/wallets/clients/coinbase/types.d.ts +0 -14
  138. package/src/wallets/clients/walletConnect/index.d.ts +0 -1
  139. package/src/wallets/clients/walletConnect/types.d.ts +0 -4
  140. package/src/wallets/clients/walletConnect/walletConnect.cjs +0 -250
  141. package/src/wallets/clients/walletConnect/walletConnect.js +0 -233
  142. package/src/wallets/cosmos/getKeplrConnector.cjs +0 -18
  143. package/src/wallets/cosmos/getKeplrConnector.d.ts +0 -6
  144. package/src/wallets/cosmos/getKeplrConnector.js +0 -14
  145. package/src/wallets/ethereum/BloctoEvm.cjs +0 -111
  146. package/src/wallets/ethereum/BloctoEvm.d.ts +0 -22
  147. package/src/wallets/ethereum/BloctoEvm.js +0 -105
  148. package/src/wallets/ethereum/EthWalletConnector.cjs +0 -207
  149. package/src/wallets/ethereum/EthWalletConnector.d.ts +0 -38
  150. package/src/wallets/ethereum/EthWalletConnector.js +0 -203
  151. package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.cjs +0 -63
  152. package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.d.ts +0 -12
  153. package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.js +0 -59
  154. package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/index.d.ts +0 -1
  155. package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.cjs +0 -62
  156. package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.d.ts +0 -11
  157. package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.js +0 -58
  158. package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/index.d.ts +0 -1
  159. package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.cjs +0 -103
  160. package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.d.ts +0 -33
  161. package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.js +0 -99
  162. package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/index.d.ts +0 -2
  163. package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.cjs +0 -56
  164. package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.d.ts +0 -12
  165. package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.js +0 -52
  166. package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/index.d.ts +0 -1
  167. package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.cjs +0 -177
  168. package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.d.ts +0 -54
  169. package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.js +0 -173
  170. package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/index.d.ts +0 -2
  171. package/src/wallets/ethereum/MagicConnector/index.d.ts +0 -5
  172. package/src/wallets/ethereum/coinbase.cjs +0 -66
  173. package/src/wallets/ethereum/coinbase.d.ts +0 -25
  174. package/src/wallets/ethereum/coinbase.js +0 -64
  175. package/src/wallets/ethereum/ethProviderHelper.cjs +0 -197
  176. package/src/wallets/ethereum/ethProviderHelper.d.ts +0 -40
  177. package/src/wallets/ethereum/ethProviderHelper.js +0 -193
  178. package/src/wallets/ethereum/evm-network.cjs +0 -20
  179. package/src/wallets/ethereum/evm-network.d.ts +0 -6
  180. package/src/wallets/ethereum/evm-network.js +0 -16
  181. package/src/wallets/ethereum/fortmatic.cjs +0 -76
  182. package/src/wallets/ethereum/fortmatic.d.ts +0 -25
  183. package/src/wallets/ethereum/fortmatic.js +0 -70
  184. package/src/wallets/ethereum/injected/BloctoInjected.cjs +0 -13
  185. package/src/wallets/ethereum/injected/BloctoInjected.d.ts +0 -6
  186. package/src/wallets/ethereum/injected/BloctoInjected.js +0 -11
  187. package/src/wallets/ethereum/injected/BraveEvm.cjs +0 -13
  188. package/src/wallets/ethereum/injected/BraveEvm.d.ts +0 -6
  189. package/src/wallets/ethereum/injected/BraveEvm.js +0 -11
  190. package/src/wallets/ethereum/injected/Dawn.cjs +0 -13
  191. package/src/wallets/ethereum/injected/Dawn.d.ts +0 -6
  192. package/src/wallets/ethereum/injected/Dawn.js +0 -11
  193. package/src/wallets/ethereum/injected/ExodusEvm.cjs +0 -13
  194. package/src/wallets/ethereum/injected/ExodusEvm.d.ts +0 -6
  195. package/src/wallets/ethereum/injected/ExodusEvm.js +0 -11
  196. package/src/wallets/ethereum/injected/Frame.cjs +0 -13
  197. package/src/wallets/ethereum/injected/Frame.d.ts +0 -6
  198. package/src/wallets/ethereum/injected/Frame.js +0 -11
  199. package/src/wallets/ethereum/injected/GameStop.cjs +0 -13
  200. package/src/wallets/ethereum/injected/GameStop.d.ts +0 -6
  201. package/src/wallets/ethereum/injected/GameStop.js +0 -11
  202. package/src/wallets/ethereum/injected/Opera.cjs +0 -13
  203. package/src/wallets/ethereum/injected/Opera.d.ts +0 -6
  204. package/src/wallets/ethereum/injected/Opera.js +0 -11
  205. package/src/wallets/ethereum/injected/PhantomEvm.cjs +0 -37
  206. package/src/wallets/ethereum/injected/PhantomEvm.d.ts +0 -7
  207. package/src/wallets/ethereum/injected/PhantomEvm.js +0 -35
  208. package/src/wallets/ethereum/injected/Trust.cjs +0 -13
  209. package/src/wallets/ethereum/injected/Trust.d.ts +0 -6
  210. package/src/wallets/ethereum/injected/Trust.js +0 -11
  211. package/src/wallets/ethereum/injected/UnknownInjectedWallet.cjs +0 -13
  212. package/src/wallets/ethereum/injected/UnknownInjectedWallet.d.ts +0 -6
  213. package/src/wallets/ethereum/injected/UnknownInjectedWallet.js +0 -11
  214. package/src/wallets/ethereum/injected/Zerion.cjs +0 -13
  215. package/src/wallets/ethereum/injected/Zerion.d.ts +0 -6
  216. package/src/wallets/ethereum/injected/Zerion.js +0 -11
  217. package/src/wallets/ethereum/meta-mask.cjs +0 -63
  218. package/src/wallets/ethereum/meta-mask.d.ts +0 -26
  219. package/src/wallets/ethereum/meta-mask.js +0 -61
  220. package/src/wallets/getMobileOrInjectedWallet.cjs +0 -22
  221. package/src/wallets/getMobileOrInjectedWallet.d.ts +0 -9
  222. package/src/wallets/getMobileOrInjectedWallet.js +0 -18
  223. package/src/wallets/getWalletConnectConnector.cjs +0 -16
  224. package/src/wallets/getWalletConnectConnector.d.ts +0 -5
  225. package/src/wallets/getWalletConnectConnector.js +0 -12
  226. package/src/wallets/walletConnect/index.d.ts +0 -2
  227. package/src/wallets/walletConnect/walletConnect.cjs +0 -133
  228. package/src/wallets/walletConnect/walletConnect.d.ts +0 -34
  229. package/src/wallets/walletConnect/walletConnect.js +0 -127
  230. package/src/wallets/walletConnect/walletConnectV2.cjs +0 -268
  231. package/src/wallets/walletConnect/walletConnectV2.d.ts +0 -38
  232. package/src/wallets/walletConnect/walletConnectV2.js +0 -262
  233. package/src/wallets/walletConnect/zerion.d.ts +0 -6
@@ -1,233 +0,0 @@
1
- import { __awaiter } from 'tslib';
2
- import Client from '@walletconnect/client';
3
- import { Contract, ethers } from 'ethers';
4
- import { isMobile, isIOS } from '../../../utils/isMobile.js';
5
- import { isSameAddress } from '../../../utils/isSameAddress/isSameAddress.js';
6
- import { logger } from '../../../utils/logger.js';
7
-
8
- const initClient = (name, settings) => {
9
- const storageId = `walletconnect-${name}`;
10
- const session = localStorage.getItem(storageId);
11
- const clientArgs = session
12
- ? { session: JSON.parse(session), storageId }
13
- : { bridge: 'https://bridge.walletconnect.org', storageId };
14
- return new Client(Object.assign(Object.assign({}, clientArgs), settings));
15
- };
16
- /**
17
- * Attach event handlers to WalletConnect events.
18
- */
19
- const setupWalletConnectEventListeners = (opts, client) => {
20
- if (!client) {
21
- return () => {
22
- // nothing to teardown
23
- };
24
- }
25
- let prevAccount;
26
- let prevChain;
27
- if (client.connected) {
28
- // eslint-disable-next-line prefer-destructuring
29
- prevAccount = client.accounts[0];
30
- prevChain = client.chainId;
31
- }
32
- client.on('disconnect', () => __awaiter(void 0, void 0, void 0, function* () {
33
- var _a;
34
- yield ((_a = opts.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(opts));
35
- }));
36
- client.on('session_update', (_, payload) => __awaiter(void 0, void 0, void 0, function* () {
37
- var _b, _c;
38
- // eslint-disable-next-line prefer-destructuring
39
- const { accounts, chainId } = payload.params[0];
40
- const didAccountChange = !isSameAddress(prevAccount || '', accounts[0], 'eip155');
41
- const didChainChange = prevChain !== chainId;
42
- // eslint-disable-next-line prefer-destructuring
43
- prevAccount = accounts[0];
44
- prevChain = chainId;
45
- if (didAccountChange) {
46
- yield ((_b = opts.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(opts, accounts));
47
- }
48
- if (didChainChange) {
49
- yield ((_c = opts.onChainChange) === null || _c === void 0 ? void 0 : _c.call(opts, String(chainId)));
50
- }
51
- }));
52
- return () => {
53
- client.off('disconnect');
54
- client.off('session_update');
55
- };
56
- };
57
- const teardownWalletConnectEventListeners = (client) => {
58
- client.off('disconnect');
59
- client.off('session_update');
60
- };
61
- /**
62
- * Initialize a client from a stored session and terminate the connection.
63
- */
64
- const killWalletConnectSession = (client) => __awaiter(void 0, void 0, void 0, function* () {
65
- try {
66
- if (client === null || client === void 0 ? void 0 : client.connected) {
67
- yield client.killSession();
68
- }
69
- }
70
- catch (e) {
71
- logger.debug(e);
72
- }
73
- });
74
- const getDeepLink = (uri, metadata, { removeWCUri = false, } = {}) => {
75
- var _a, _b, _c, _d;
76
- if (!isMobile()) {
77
- const origin = ((_a = metadata.desktop) === null || _a === void 0 ? void 0 : _a.universal) || ((_b = metadata.desktop) === null || _b === void 0 ? void 0 : _b.native);
78
- if (removeWCUri)
79
- return origin || '';
80
- return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
81
- }
82
- // deeplinks for ios require special treatment
83
- // see: https://docs.walletconnect.com/mobile-linking#for-ios
84
- else if (isIOS()) {
85
- const origin = ((_c = metadata.mobile) === null || _c === void 0 ? void 0 : _c.universal) || ((_d = metadata.mobile) === null || _d === void 0 ? void 0 : _d.native);
86
- if (removeWCUri)
87
- return origin || '';
88
- return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
89
- }
90
- // on android, the deeplink is simply the uri
91
- // see: https://docs.walletconnect.com/mobile-linking#for-android
92
- return uri;
93
- };
94
- const createSession = (client) => __awaiter(void 0, void 0, void 0, function* () {
95
- return new Promise((resolve, reject) => {
96
- client.on('connect', (error, payload) => __awaiter(void 0, void 0, void 0, function* () {
97
- if (error)
98
- throw error;
99
- resolve(payload);
100
- }));
101
- client.on('disconnect', (error, payload) => {
102
- reject(error || payload.params[0].message);
103
- });
104
- });
105
- });
106
- const useDeepLink = (metadata, wcClient, opts) => {
107
- var _a, _b, _c;
108
- const deepLink = getDeepLink(wcClient.uri, metadata);
109
- if (isMobile()) {
110
- window.location.href = deepLink;
111
- }
112
- else {
113
- if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
114
- (_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, deepLink);
115
- }
116
- (_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, wcClient.uri);
117
- }
118
- };
119
- const fetchWalletConnectCosmosPublicAddress = (metadata, wcClient, provider, opts) => __awaiter(void 0, void 0, void 0, function* () {
120
- var _a;
121
- if (wcClient.connected) {
122
- const key = yield provider.getKey(opts.chainId);
123
- return key.bech32Address;
124
- }
125
- yield wcClient.createSession();
126
- useDeepLink(metadata, wcClient, opts);
127
- const payload = yield createSession(wcClient);
128
- const key = yield provider.getKey(opts.chainId);
129
- (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
130
- wcClient.accounts = [key.bech32Address];
131
- return key.bech32Address;
132
- });
133
- const fetchWalletConnectEVMPublicAddress = (metadata, wcClient, opts) => __awaiter(void 0, void 0, void 0, function* () {
134
- var _b;
135
- if (wcClient.connected) {
136
- const [accountPublicAddress] = wcClient.accounts;
137
- return accountPublicAddress;
138
- }
139
- // createSession will trigger the QR code...
140
- yield wcClient.createSession();
141
- useDeepLink(metadata, wcClient, opts);
142
- const payload = yield createSession(wcClient);
143
- (_b = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _b === void 0 ? void 0 : _b.call(opts, payload);
144
- const [accountPublicAddress] = payload.params[0].accounts;
145
- return accountPublicAddress;
146
- });
147
- const signWalletConnectPersonalMessage = (messageToSign, metadata, client, rpcProvider) => __awaiter(void 0, void 0, void 0, function* () {
148
- var _c, _d;
149
- const isCryptoWallet = ((_c = client === null || client === void 0 ? void 0 : client.peerMeta) === null || _c === void 0 ? void 0 : _c.name) === 'Crypto.com | DeFi Wallet' ||
150
- ((_d = client === null || client === void 0 ? void 0 : client.peerMeta) === null || _d === void 0 ? void 0 : _d.name) === 'DeFi Wallet';
151
- if (!client || !client.connected) {
152
- return;
153
- }
154
- const [accountPublicAddress] = client.accounts;
155
- if (isMobile()) {
156
- const deepLink = getDeepLink(client.uri, metadata, {
157
- removeWCUri: isIOS() && isCryptoWallet,
158
- });
159
- window.location.href = deepLink;
160
- }
161
- try {
162
- // This delay is required for Crypto.com DeFi wallet, when there is no delay the app
163
- // will not open the pop-up to sign. That seems to be a limitation in the standalone client
164
- // so the delay is required to allow the users to sign the message
165
- if (isCryptoWallet && isMobile()) {
166
- yield sleep(4000);
167
- }
168
- else {
169
- // The delay of 1 second is necessary for some of the wallets to open the sign UI in the
170
- // correct order, without this some wallets like Trust or OKX will no open properly,
171
- // and not allowing the user to sign the message
172
- yield sleep(1000);
173
- }
174
- const signature = yield client.signPersonalMessage([
175
- messageToSign,
176
- accountPublicAddress,
177
- ]);
178
- yield waitForSafeTransactionOrTimeout(accountPublicAddress, signature, messageToSign, client, rpcProvider);
179
- return signature;
180
- }
181
- catch (e) {
182
- logger.debug(e);
183
- throw e;
184
- }
185
- });
186
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
187
- // Successful value as defined by the EIP
188
- // https://eips.ethereum.org/EIPS/eip-1271#specification
189
- const MAGIC_VALUE = '0x1626ba7e';
190
- const IS_VALID_SIGNATURE_ABI = [
191
- 'function isValidSignature(bytes32 _message, bytes _signature) public view returns (bytes4)',
192
- ];
193
- const waitForSafeTransactionOrTimeout = (accountPublicAddress, signature, messageToSign, client, rpcProvider) => __awaiter(void 0, void 0, void 0, function* () {
194
- var _e;
195
- if (signature === '0x' &&
196
- // this is what wallet connect client returns there's no `safe` or `Safe`
197
- // exact string anywhere, so this seems like the best proxy
198
- ((_e = client.peerMeta) === null || _e === void 0 ? void 0 : _e.name) === 'WalletConnect Safe App') {
199
- if (!rpcProvider) {
200
- return;
201
- }
202
- const contract = new Contract(accountPublicAddress, IS_VALID_SIGNATURE_ABI, yield rpcProvider());
203
- const safeTransactionPromise = waitForSafeTransaction(signature, messageToSign, contract);
204
- const timeoutPromise = new Promise((resolve) => {
205
- setTimeout(resolve, 120000);
206
- });
207
- yield Promise.race([safeTransactionPromise, timeoutPromise]);
208
- }
209
- });
210
- // this is a hack for safe
211
- // before sending the signature downstream, we need to make sure
212
- // the transaction is recorded first on the blockchain
213
- // redcoast verify WILL fail if it attempts to verify the signature
214
- // that has not yet been properly processed!
215
- const waitForSafeTransaction = (signature, messageToSign, contract) => __awaiter(void 0, void 0, void 0, function* () {
216
- // wait for safe wallet to finish txn on the blockchain contract
217
- for (let i = 0; i < 120; i++) {
218
- try {
219
- // this will result in an exception if the transaction is still not ready
220
- // we need to catch it below
221
- const result = yield contract.isValidSignature(ethers.utils.hashMessage(messageToSign), signature);
222
- if (result === MAGIC_VALUE)
223
- return;
224
- }
225
- catch (err) {
226
- logger.info('Safe transaction cannot be validated yet. Retrying.');
227
- }
228
- // try again after 2 seconds
229
- yield sleep(2000);
230
- }
231
- });
232
-
233
- export { createSession, fetchWalletConnectCosmosPublicAddress, fetchWalletConnectEVMPublicAddress, getDeepLink, initClient, killWalletConnectSession, setupWalletConnectEventListeners, signWalletConnectPersonalMessage, teardownWalletConnectEventListeners, useDeepLink };
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var KeplrWalletConnector = require('./KeplrWalletConnector.cjs');
6
- var KeplrWalletConnect = require('./KeplrWalletConnect.cjs');
7
-
8
- const getKeplerConnector = ({ evmNetworks, }) => {
9
- const keplr = new KeplrWalletConnector.KeplrWalletConnector({ evmNetworks });
10
- if (keplr.isInstalledOnBrowser()) {
11
- return keplr;
12
- }
13
- else {
14
- return new KeplrWalletConnect({ evmNetworks });
15
- }
16
- };
17
-
18
- exports.getKeplerConnector = getKeplerConnector;
@@ -1,6 +0,0 @@
1
- import { GenericNetwork } from '@dynamic-labs/types';
2
- import { KeplrWalletConnector } from './KeplrWalletConnector';
3
- import KeplrWalletConnect from './KeplrWalletConnect';
4
- export declare const getKeplerConnector: ({ evmNetworks, }: {
5
- evmNetworks: GenericNetwork[];
6
- }) => KeplrWalletConnector | KeplrWalletConnect;
@@ -1,14 +0,0 @@
1
- import { KeplrWalletConnector } from './KeplrWalletConnector.js';
2
- import KeplrWalletConnect from './KeplrWalletConnect.js';
3
-
4
- const getKeplerConnector = ({ evmNetworks, }) => {
5
- const keplr = new KeplrWalletConnector({ evmNetworks });
6
- if (keplr.isInstalledOnBrowser()) {
7
- return keplr;
8
- }
9
- else {
10
- return new KeplrWalletConnect({ evmNetworks });
11
- }
12
- };
13
-
14
- export { getKeplerConnector };
@@ -1,111 +0,0 @@
1
- 'use strict';
2
-
3
- var tslib = require('tslib');
4
- var BloctoSDK = require('@blocto/sdk');
5
- var ethers = require('ethers');
6
- var logger = require('../../utils/logger.cjs');
7
- var EthWalletConnector = require('./EthWalletConnector.cjs');
8
- var ethProviderHelper = require('./ethProviderHelper.cjs');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
-
12
- var BloctoSDK__default = /*#__PURE__*/_interopDefaultLegacy(BloctoSDK);
13
-
14
- class BloctoEvm extends EthWalletConnector.EthWalletConnector {
15
- constructor(props) {
16
- var _a, _b;
17
- super(props);
18
- this.LOCAL_STORAGE_KEY = 'dynamic_blocto_evm_chain_id';
19
- this.name = 'bloctoevm';
20
- this.canConnectViaCustodialService = true;
21
- this.connectedChain = 'EVM';
22
- this.supportedChains = ['EVM', 'ETH'];
23
- this.ethProviderHelper = new ethProviderHelper.EthProviderHelper();
24
- this.supportsNetworkSwitching = () => false;
25
- // Taken from : https://docs.blocto.app/blocto-sdk/javascript-sdk/evm-sdk/provider
26
- const BLOCTO_SUPPORTED_CHAIN_IDS = [1, 4, 56, 97, 137, 80001, 43114, 43113];
27
- this.evmNetworks = this.evmNetworks.filter((n) => BLOCTO_SUPPORTED_CHAIN_IDS.includes(n.chainId));
28
- this.chainId =
29
- Number(localStorage.getItem(this.LOCAL_STORAGE_KEY)) ||
30
- ((_a = this.evmNetworks.find((n) => n.chainId === 137)) === null || _a === void 0 ? void 0 : _a.chainId) ||
31
- ((_b = this.evmNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId);
32
- }
33
- getClient() {
34
- if (!this.client) {
35
- const network = this.evmNetworks.find((n) => n.chainId === this.chainId);
36
- if (network) {
37
- this.client = new BloctoSDK__default["default"]({
38
- ethereum: {
39
- chainId: `0x${this.chainId.toString(16)}`,
40
- rpc: network.rpcUrls[0],
41
- },
42
- });
43
- }
44
- else {
45
- logger.logger.error("Couldn't find a configured network for Blocto EVM");
46
- }
47
- }
48
- return this.client;
49
- }
50
- getWeb3Provider() {
51
- const client = this.getClient();
52
- // If there are no accounts yet, we shouldn't wrap the provider in ethers
53
- if (client && client.ethereum && client.ethereum.accounts.length > 0) {
54
- return new ethers.ethers.providers.Web3Provider(client.ethereum);
55
- }
56
- else {
57
- return undefined;
58
- }
59
- }
60
- // We are calling the client directly and not via Web3Provider because if we will wrap it in Ethers,
61
- // Ethers will be making retries on failure. This becomes an issue on the connect step.
62
- // When Blocto's modal closes prior to receiving a response with the address on the connect step,
63
- // then ethers would retry and the modal will open again.
64
- fetchPublicAddress() {
65
- return tslib.__awaiter(this, void 0, void 0, function* () {
66
- try {
67
- const client = this.getClient();
68
- if (client && client.ethereum) {
69
- const addresses = yield client.ethereum.request({
70
- method: 'eth_requestAccounts',
71
- });
72
- if (addresses.length > 0) {
73
- return addresses[0];
74
- }
75
- }
76
- return undefined;
77
- }
78
- catch (e) {
79
- logger.logger.error(e);
80
- return Promise.reject(e);
81
- }
82
- });
83
- }
84
- signMessage(messageToSign) {
85
- return tslib.__awaiter(this, void 0, void 0, function* () {
86
- try {
87
- const signer = yield this.getSigner();
88
- return yield (signer === null || signer === void 0 ? void 0 : signer.signMessage(messageToSign));
89
- }
90
- catch (e) {
91
- if (e.message === 'User declined the signing request') {
92
- return Promise.reject({ code: '4001' });
93
- }
94
- else {
95
- return Promise.reject(e);
96
- }
97
- }
98
- });
99
- }
100
- endSession() {
101
- return tslib.__awaiter(this, void 0, void 0, function* () {
102
- const client = this.getClient();
103
- localStorage.removeItem('sdk.session');
104
- if (client && client.ethereum && client.ethereum.accounts.length > 0) {
105
- yield client.ethereum.request({ method: 'wallet_disconnect' });
106
- }
107
- });
108
- }
109
- }
110
-
111
- module.exports = BloctoEvm;
@@ -1,22 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { Chain } from '@dynamic-labs/wallet-connector-core';
3
- import { EthWalletConnector, EthWalletConnectorOpts } from './EthWalletConnector';
4
- import { EthProviderHelper } from './ethProviderHelper';
5
- declare class BloctoEvm extends EthWalletConnector {
6
- LOCAL_STORAGE_KEY: string;
7
- private client?;
8
- name: string;
9
- canConnectViaCustodialService: boolean;
10
- connectedChain: Chain;
11
- supportedChains: Chain[];
12
- chainId: number;
13
- ethProviderHelper: EthProviderHelper;
14
- supportsNetworkSwitching: () => boolean;
15
- constructor(props: EthWalletConnectorOpts);
16
- private getClient;
17
- getWeb3Provider(): ethers.providers.Web3Provider | undefined;
18
- fetchPublicAddress(): Promise<string | undefined>;
19
- signMessage(messageToSign: string): Promise<string | undefined>;
20
- endSession(): Promise<void>;
21
- }
22
- export default BloctoEvm;
@@ -1,105 +0,0 @@
1
- import { __awaiter } from 'tslib';
2
- import BloctoSDK from '@blocto/sdk';
3
- import { ethers } from 'ethers';
4
- import { logger } from '../../utils/logger.js';
5
- import { EthWalletConnector } from './EthWalletConnector.js';
6
- import { EthProviderHelper } from './ethProviderHelper.js';
7
-
8
- class BloctoEvm extends EthWalletConnector {
9
- constructor(props) {
10
- var _a, _b;
11
- super(props);
12
- this.LOCAL_STORAGE_KEY = 'dynamic_blocto_evm_chain_id';
13
- this.name = 'bloctoevm';
14
- this.canConnectViaCustodialService = true;
15
- this.connectedChain = 'EVM';
16
- this.supportedChains = ['EVM', 'ETH'];
17
- this.ethProviderHelper = new EthProviderHelper();
18
- this.supportsNetworkSwitching = () => false;
19
- // Taken from : https://docs.blocto.app/blocto-sdk/javascript-sdk/evm-sdk/provider
20
- const BLOCTO_SUPPORTED_CHAIN_IDS = [1, 4, 56, 97, 137, 80001, 43114, 43113];
21
- this.evmNetworks = this.evmNetworks.filter((n) => BLOCTO_SUPPORTED_CHAIN_IDS.includes(n.chainId));
22
- this.chainId =
23
- Number(localStorage.getItem(this.LOCAL_STORAGE_KEY)) ||
24
- ((_a = this.evmNetworks.find((n) => n.chainId === 137)) === null || _a === void 0 ? void 0 : _a.chainId) ||
25
- ((_b = this.evmNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId);
26
- }
27
- getClient() {
28
- if (!this.client) {
29
- const network = this.evmNetworks.find((n) => n.chainId === this.chainId);
30
- if (network) {
31
- this.client = new BloctoSDK({
32
- ethereum: {
33
- chainId: `0x${this.chainId.toString(16)}`,
34
- rpc: network.rpcUrls[0],
35
- },
36
- });
37
- }
38
- else {
39
- logger.error("Couldn't find a configured network for Blocto EVM");
40
- }
41
- }
42
- return this.client;
43
- }
44
- getWeb3Provider() {
45
- const client = this.getClient();
46
- // If there are no accounts yet, we shouldn't wrap the provider in ethers
47
- if (client && client.ethereum && client.ethereum.accounts.length > 0) {
48
- return new ethers.providers.Web3Provider(client.ethereum);
49
- }
50
- else {
51
- return undefined;
52
- }
53
- }
54
- // We are calling the client directly and not via Web3Provider because if we will wrap it in Ethers,
55
- // Ethers will be making retries on failure. This becomes an issue on the connect step.
56
- // When Blocto's modal closes prior to receiving a response with the address on the connect step,
57
- // then ethers would retry and the modal will open again.
58
- fetchPublicAddress() {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- try {
61
- const client = this.getClient();
62
- if (client && client.ethereum) {
63
- const addresses = yield client.ethereum.request({
64
- method: 'eth_requestAccounts',
65
- });
66
- if (addresses.length > 0) {
67
- return addresses[0];
68
- }
69
- }
70
- return undefined;
71
- }
72
- catch (e) {
73
- logger.error(e);
74
- return Promise.reject(e);
75
- }
76
- });
77
- }
78
- signMessage(messageToSign) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- try {
81
- const signer = yield this.getSigner();
82
- return yield (signer === null || signer === void 0 ? void 0 : signer.signMessage(messageToSign));
83
- }
84
- catch (e) {
85
- if (e.message === 'User declined the signing request') {
86
- return Promise.reject({ code: '4001' });
87
- }
88
- else {
89
- return Promise.reject(e);
90
- }
91
- }
92
- });
93
- }
94
- endSession() {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- const client = this.getClient();
97
- localStorage.removeItem('sdk.session');
98
- if (client && client.ethereum && client.ethereum.accounts.length > 0) {
99
- yield client.ethereum.request({ method: 'wallet_disconnect' });
100
- }
101
- });
102
- }
103
- }
104
-
105
- export { BloctoEvm as default };