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