@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,268 +0,0 @@
1
- 'use strict';
2
-
3
- var tslib = require('tslib');
4
- var Provider = require('@walletconnect/universal-provider');
5
- var ethers = require('ethers');
6
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
7
- var walletBook = require('@dynamic-labs/wallet-book');
8
- var utils = require('@dynamic-labs/utils');
9
- var EthWalletConnector = require('../ethereum/EthWalletConnector.cjs');
10
- var isMobile = require('../../utils/isMobile.cjs');
11
- var walletConnect = require('../clients/walletConnect/walletConnect.cjs');
12
- var encoding = require('../../utils/encoding.cjs');
13
-
14
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
-
16
- var Provider__default = /*#__PURE__*/_interopDefaultLegacy(Provider);
17
-
18
- const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
19
- var _a, _b, _c;
20
- if (isMobile.isMobile()) {
21
- const deepLink = walletConnect.getDeepLink(uri, metadata);
22
- window.location.href = deepLink;
23
- }
24
- else {
25
- if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
26
- const desktopUri = walletConnect.getDeepLink(uri, metadata);
27
- (_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, desktopUri);
28
- }
29
- (_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, uri);
30
- }
31
- };
32
- const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
33
- class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
34
- constructor(opts) {
35
- super(opts);
36
- this.supportedChains = ['EVM', 'ETH'];
37
- this.connectedChain = 'EVM';
38
- this.canConnectViaQrCode = true;
39
- this.isWalletConnect = true;
40
- this.name = opts.walletName;
41
- this.projectId = opts.projectId;
42
- }
43
- initProvider() {
44
- return tslib.__awaiter(this, void 0, void 0, function* () {
45
- if (this.projectId && !WalletConnectV2.provider) {
46
- WalletConnectV2.provider = yield Provider__default["default"].init({
47
- projectId: this.projectId,
48
- });
49
- const connection = yield WalletConnectV2.provider.client.connect({
50
- requiredNamespaces: {
51
- eip155: {
52
- chains: this.evmNetworks
53
- // filtering out Palm for now since it causes Trust to crash
54
- .filter((network) => network.chainId !== 11297108109)
55
- .map((network) => `eip155:${network.chainId}`),
56
- events: ['chainChanged', 'accountsChanged'],
57
- methods: [
58
- 'eth_sendTransaction',
59
- 'eth_signTransaction',
60
- 'eth_sign',
61
- 'personal_sign',
62
- 'eth_signTypedData',
63
- ],
64
- },
65
- },
66
- });
67
- // eslint-disable-next-line prefer-destructuring
68
- WalletConnectV2.provider.uri = connection.uri;
69
- WalletConnectV2.createSession = connection.approval;
70
- }
71
- });
72
- }
73
- init() {
74
- var _a, _b, _c, _d;
75
- return tslib.__awaiter(this, void 0, void 0, function* () {
76
- yield this.initProvider();
77
- if ((_b = (_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.topic) {
78
- if (localStorage.getItem(this.sessionTopicKey) ===
79
- ((_d = (_c = WalletConnectV2.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
80
- this.session = WalletConnectV2.provider.session;
81
- }
82
- }
83
- });
84
- }
85
- get sessionTopicKey() {
86
- return sessionTopicKey(this.key);
87
- }
88
- supportsNetworkSwitching() {
89
- return true;
90
- }
91
- setupEventListeners(listeners) {
92
- if (!WalletConnectV2.provider) {
93
- return;
94
- }
95
- WalletConnectV2.provider.client.on('session_event', ({ params }) => {
96
- var _a, _b;
97
- if (!params || !params.event) {
98
- walletConnectorCore.logger.debug('session_event was called without params or params.event');
99
- return;
100
- }
101
- const { name, data } = params.event;
102
- if (name === 'chainChanged') {
103
- if (typeof data !== 'string') {
104
- walletConnectorCore.logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
105
- return;
106
- }
107
- (_a = listeners.onChainChange) === null || _a === void 0 ? void 0 : _a.call(listeners, data);
108
- }
109
- else if (name === 'accountsChanged') {
110
- if (typeof data !== 'string' || !Array.isArray(data)) {
111
- walletConnectorCore.logger.debug(`received unexpected data for accountsChanged: ${data} with type ${typeof data}}`);
112
- return;
113
- }
114
- (_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, data);
115
- }
116
- });
117
- WalletConnectV2.provider.client.on('session_delete', () => tslib.__awaiter(this, void 0, void 0, function* () {
118
- var _a;
119
- localStorage.removeItem(this.sessionTopicKey);
120
- yield ((_a = listeners.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(listeners));
121
- }));
122
- }
123
- teardownEventListeners() {
124
- if (!WalletConnectV2.provider) {
125
- return;
126
- }
127
- WalletConnectV2.provider.client.removeAllListeners('session_event');
128
- WalletConnectV2.provider.client.removeAllListeners('session_delete');
129
- }
130
- getDeepLink() {
131
- var _a, _b;
132
- if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.uri))
133
- return;
134
- const wallet = walletBook.getWalletBookWallet(this.name);
135
- if (!isMobile.isMobile() && !((_b = wallet.desktop) === null || _b === void 0 ? void 0 : _b.native)) {
136
- return undefined;
137
- }
138
- return walletConnect.getDeepLink(WalletConnectV2.provider.uri, wallet);
139
- }
140
- getWeb3Provider() {
141
- if (!WalletConnectV2.provider) {
142
- throw new Error('No provider found');
143
- }
144
- return new ethers.ethers.providers.Web3Provider(WalletConnectV2.provider, 'any');
145
- }
146
- fetchPublicAddress(opts) {
147
- return tslib.__awaiter(this, void 0, void 0, function* () {
148
- if (this.session) {
149
- return this.session.namespaces.eip155.accounts[0].split(':')[2];
150
- }
151
- const metadata = walletBook.getWalletBookWallet(this.name);
152
- if (!WalletConnectV2.provider) {
153
- throw new utils.DynamicError('No provider found');
154
- }
155
- if (!WalletConnectV2.provider.uri || !WalletConnectV2.createSession) {
156
- throw new utils.DynamicError('No uri or approval found');
157
- }
158
- performPlatformSpecificConnectionMethod(WalletConnectV2.provider.uri, metadata, {
159
- onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
160
- onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
161
- });
162
- const session = yield WalletConnectV2.createSession();
163
- if (!session) {
164
- return undefined;
165
- }
166
- this.session = session;
167
- localStorage.setItem(this.sessionTopicKey, session.topic);
168
- // need to "reconnect" the provider so that we can tell it what the rpc urls are
169
- yield WalletConnectV2.provider.connect({
170
- namespaces: {
171
- eip155: {
172
- chains: this.evmNetworks
173
- // filtering out Palm for now since it causes Trust to crash
174
- .filter((network) => network.chainId !== 11297108109)
175
- .map((network) => `eip155:${network.chainId}`),
176
- events: ['chainChanged', 'accountsChanged'],
177
- methods: [
178
- 'eth_sendTransaction',
179
- 'eth_signTransaction',
180
- 'eth_sign',
181
- 'personal_sign',
182
- 'eth_signTypedData',
183
- ],
184
- rpcMap: this.evmNetworkRpcMap(),
185
- },
186
- },
187
- skipPairing: true,
188
- });
189
- // THIS LINE IS SUPER IMPORTANT
190
- // since we are skipping pairing, (see: skipPairing: true above), we need to manually set the session
191
- // so that future provider requests work (like getNetwork)
192
- WalletConnectV2.provider.session = session;
193
- return session.namespaces.eip155.accounts[0].split(':')[2];
194
- });
195
- }
196
- signMessage(messageToSign) {
197
- return tslib.__awaiter(this, void 0, void 0, function* () {
198
- if (!this.session) {
199
- throw new utils.DynamicError('no session');
200
- }
201
- if (!WalletConnectV2.provider) {
202
- throw new utils.DynamicError('No WalletConnect provider found to handle signing');
203
- }
204
- const metadata = walletBook.getWalletBookWallet(this.name);
205
- if (isMobile.isMobile()) {
206
- // for sign message, no uri is needed because the uri encodes connection details,
207
- // and at this point we are already connected
208
- const deepLink = walletConnect.getDeepLink('', metadata);
209
- window.location.href = deepLink;
210
- }
211
- // eslint-disable-next-line prefer-destructuring
212
- const address = this.session.namespaces.eip155.accounts[0].split(':')[2];
213
- const web3Provider = this.getWeb3Provider();
214
- return web3Provider.send('personal_sign', [
215
- encoding.utf8ToHex(messageToSign, true),
216
- address,
217
- ]);
218
- });
219
- }
220
- endSession() {
221
- return tslib.__awaiter(this, void 0, void 0, function* () {
222
- if (!this.session) {
223
- return;
224
- }
225
- if (!WalletConnectV2.provider) {
226
- return;
227
- }
228
- try {
229
- yield WalletConnectV2.provider.disconnect();
230
- localStorage.removeItem(this.sessionTopicKey);
231
- }
232
- catch (e) {
233
- walletConnectorCore.logger.debug(e);
234
- }
235
- });
236
- }
237
- providerSwitchNetwork({ network, provider, }) {
238
- const _super = Object.create(null, {
239
- providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
240
- });
241
- return tslib.__awaiter(this, void 0, void 0, function* () {
242
- const currentNetworkId = yield this.getNetwork();
243
- if (currentNetworkId && currentNetworkId === network.chainId) {
244
- return;
245
- }
246
- if (this.switchNetworkOnlyFromWallet) {
247
- throw new utils.DynamicError('Network switching is only supported through the wallet');
248
- }
249
- if (!this.supportsNetworkSwitching()) {
250
- throw new utils.DynamicError('Network switching not supported');
251
- }
252
- if (!provider) {
253
- throw new utils.DynamicError('Provider not found');
254
- }
255
- return _super.providerSwitchNetwork.call(this, { network, provider });
256
- });
257
- }
258
- getConnectedAccounts() {
259
- return tslib.__awaiter(this, void 0, void 0, function* () {
260
- if (!this.session) {
261
- return [];
262
- }
263
- return [this.session.namespaces.eip155.accounts[0].split(':')[2]];
264
- });
265
- }
266
- }
267
-
268
- module.exports = WalletConnectV2;
@@ -1,38 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import type { SessionTypes } from '@walletconnect/types';
3
- import { Chain, FetchPublicAddressOpts, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
4
- import { EvmNetwork } from '@dynamic-labs/types';
5
- import { EthWalletConnector, EthWalletConnectorOpts } from '../ethereum/EthWalletConnector';
6
- export type WalletConnectorV2Opts = EthWalletConnectorOpts & {
7
- projectId?: string;
8
- walletName: string;
9
- };
10
- declare class WalletConnectV2 extends EthWalletConnector {
11
- supportedChains: Chain[];
12
- connectedChain: Chain;
13
- name: string;
14
- session: SessionTypes.Struct | undefined;
15
- canConnectViaQrCode: boolean;
16
- isWalletConnect: boolean;
17
- private static provider;
18
- private static createSession;
19
- private projectId?;
20
- constructor(opts: WalletConnectorV2Opts);
21
- private initProvider;
22
- init(): Promise<void>;
23
- get sessionTopicKey(): string;
24
- supportsNetworkSwitching(): boolean;
25
- setupEventListeners(listeners: WalletEventListeners): void;
26
- teardownEventListeners(): void;
27
- getDeepLink(): string | undefined;
28
- getWeb3Provider(): ethers.providers.Web3Provider;
29
- fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
30
- signMessage(messageToSign: string): Promise<string | undefined>;
31
- endSession(): Promise<void>;
32
- providerSwitchNetwork({ network, provider, }: {
33
- network: EvmNetwork;
34
- provider: ethers.providers.Web3Provider;
35
- }): Promise<void>;
36
- getConnectedAccounts(): Promise<string[]>;
37
- }
38
- export default WalletConnectV2;
@@ -1,262 +0,0 @@
1
- import { __awaiter } from 'tslib';
2
- import Provider from '@walletconnect/universal-provider';
3
- import { ethers } from 'ethers';
4
- import { logger } from '@dynamic-labs/wallet-connector-core';
5
- import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
6
- import { DynamicError } from '@dynamic-labs/utils';
7
- import { EthWalletConnector } from '../ethereum/EthWalletConnector.js';
8
- import { isMobile } from '../../utils/isMobile.js';
9
- import { getDeepLink } from '../clients/walletConnect/walletConnect.js';
10
- import { utf8ToHex } from '../../utils/encoding.js';
11
-
12
- const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
13
- var _a, _b, _c;
14
- if (isMobile()) {
15
- const deepLink = getDeepLink(uri, metadata);
16
- window.location.href = deepLink;
17
- }
18
- else {
19
- if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
20
- const desktopUri = getDeepLink(uri, metadata);
21
- (_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, desktopUri);
22
- }
23
- (_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, uri);
24
- }
25
- };
26
- const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
27
- class WalletConnectV2 extends EthWalletConnector {
28
- constructor(opts) {
29
- super(opts);
30
- this.supportedChains = ['EVM', 'ETH'];
31
- this.connectedChain = 'EVM';
32
- this.canConnectViaQrCode = true;
33
- this.isWalletConnect = true;
34
- this.name = opts.walletName;
35
- this.projectId = opts.projectId;
36
- }
37
- initProvider() {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- if (this.projectId && !WalletConnectV2.provider) {
40
- WalletConnectV2.provider = yield Provider.init({
41
- projectId: this.projectId,
42
- });
43
- const connection = yield WalletConnectV2.provider.client.connect({
44
- requiredNamespaces: {
45
- eip155: {
46
- chains: this.evmNetworks
47
- // filtering out Palm for now since it causes Trust to crash
48
- .filter((network) => network.chainId !== 11297108109)
49
- .map((network) => `eip155:${network.chainId}`),
50
- events: ['chainChanged', 'accountsChanged'],
51
- methods: [
52
- 'eth_sendTransaction',
53
- 'eth_signTransaction',
54
- 'eth_sign',
55
- 'personal_sign',
56
- 'eth_signTypedData',
57
- ],
58
- },
59
- },
60
- });
61
- // eslint-disable-next-line prefer-destructuring
62
- WalletConnectV2.provider.uri = connection.uri;
63
- WalletConnectV2.createSession = connection.approval;
64
- }
65
- });
66
- }
67
- init() {
68
- var _a, _b, _c, _d;
69
- return __awaiter(this, void 0, void 0, function* () {
70
- yield this.initProvider();
71
- if ((_b = (_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.topic) {
72
- if (localStorage.getItem(this.sessionTopicKey) ===
73
- ((_d = (_c = WalletConnectV2.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
74
- this.session = WalletConnectV2.provider.session;
75
- }
76
- }
77
- });
78
- }
79
- get sessionTopicKey() {
80
- return sessionTopicKey(this.key);
81
- }
82
- supportsNetworkSwitching() {
83
- return true;
84
- }
85
- setupEventListeners(listeners) {
86
- if (!WalletConnectV2.provider) {
87
- return;
88
- }
89
- WalletConnectV2.provider.client.on('session_event', ({ params }) => {
90
- var _a, _b;
91
- if (!params || !params.event) {
92
- logger.debug('session_event was called without params or params.event');
93
- return;
94
- }
95
- const { name, data } = params.event;
96
- if (name === 'chainChanged') {
97
- if (typeof data !== 'string') {
98
- logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
99
- return;
100
- }
101
- (_a = listeners.onChainChange) === null || _a === void 0 ? void 0 : _a.call(listeners, data);
102
- }
103
- else if (name === 'accountsChanged') {
104
- if (typeof data !== 'string' || !Array.isArray(data)) {
105
- logger.debug(`received unexpected data for accountsChanged: ${data} with type ${typeof data}}`);
106
- return;
107
- }
108
- (_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, data);
109
- }
110
- });
111
- WalletConnectV2.provider.client.on('session_delete', () => __awaiter(this, void 0, void 0, function* () {
112
- var _a;
113
- localStorage.removeItem(this.sessionTopicKey);
114
- yield ((_a = listeners.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(listeners));
115
- }));
116
- }
117
- teardownEventListeners() {
118
- if (!WalletConnectV2.provider) {
119
- return;
120
- }
121
- WalletConnectV2.provider.client.removeAllListeners('session_event');
122
- WalletConnectV2.provider.client.removeAllListeners('session_delete');
123
- }
124
- getDeepLink() {
125
- var _a, _b;
126
- if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.uri))
127
- return;
128
- const wallet = getWalletBookWallet(this.name);
129
- if (!isMobile() && !((_b = wallet.desktop) === null || _b === void 0 ? void 0 : _b.native)) {
130
- return undefined;
131
- }
132
- return getDeepLink(WalletConnectV2.provider.uri, wallet);
133
- }
134
- getWeb3Provider() {
135
- if (!WalletConnectV2.provider) {
136
- throw new Error('No provider found');
137
- }
138
- return new ethers.providers.Web3Provider(WalletConnectV2.provider, 'any');
139
- }
140
- fetchPublicAddress(opts) {
141
- return __awaiter(this, void 0, void 0, function* () {
142
- if (this.session) {
143
- return this.session.namespaces.eip155.accounts[0].split(':')[2];
144
- }
145
- const metadata = getWalletBookWallet(this.name);
146
- if (!WalletConnectV2.provider) {
147
- throw new DynamicError('No provider found');
148
- }
149
- if (!WalletConnectV2.provider.uri || !WalletConnectV2.createSession) {
150
- throw new DynamicError('No uri or approval found');
151
- }
152
- performPlatformSpecificConnectionMethod(WalletConnectV2.provider.uri, metadata, {
153
- onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
154
- onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
155
- });
156
- const session = yield WalletConnectV2.createSession();
157
- if (!session) {
158
- return undefined;
159
- }
160
- this.session = session;
161
- localStorage.setItem(this.sessionTopicKey, session.topic);
162
- // need to "reconnect" the provider so that we can tell it what the rpc urls are
163
- yield WalletConnectV2.provider.connect({
164
- namespaces: {
165
- eip155: {
166
- chains: this.evmNetworks
167
- // filtering out Palm for now since it causes Trust to crash
168
- .filter((network) => network.chainId !== 11297108109)
169
- .map((network) => `eip155:${network.chainId}`),
170
- events: ['chainChanged', 'accountsChanged'],
171
- methods: [
172
- 'eth_sendTransaction',
173
- 'eth_signTransaction',
174
- 'eth_sign',
175
- 'personal_sign',
176
- 'eth_signTypedData',
177
- ],
178
- rpcMap: this.evmNetworkRpcMap(),
179
- },
180
- },
181
- skipPairing: true,
182
- });
183
- // THIS LINE IS SUPER IMPORTANT
184
- // since we are skipping pairing, (see: skipPairing: true above), we need to manually set the session
185
- // so that future provider requests work (like getNetwork)
186
- WalletConnectV2.provider.session = session;
187
- return session.namespaces.eip155.accounts[0].split(':')[2];
188
- });
189
- }
190
- signMessage(messageToSign) {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- if (!this.session) {
193
- throw new DynamicError('no session');
194
- }
195
- if (!WalletConnectV2.provider) {
196
- throw new DynamicError('No WalletConnect provider found to handle signing');
197
- }
198
- const metadata = getWalletBookWallet(this.name);
199
- if (isMobile()) {
200
- // for sign message, no uri is needed because the uri encodes connection details,
201
- // and at this point we are already connected
202
- const deepLink = getDeepLink('', metadata);
203
- window.location.href = deepLink;
204
- }
205
- // eslint-disable-next-line prefer-destructuring
206
- const address = this.session.namespaces.eip155.accounts[0].split(':')[2];
207
- const web3Provider = this.getWeb3Provider();
208
- return web3Provider.send('personal_sign', [
209
- utf8ToHex(messageToSign, true),
210
- address,
211
- ]);
212
- });
213
- }
214
- endSession() {
215
- return __awaiter(this, void 0, void 0, function* () {
216
- if (!this.session) {
217
- return;
218
- }
219
- if (!WalletConnectV2.provider) {
220
- return;
221
- }
222
- try {
223
- yield WalletConnectV2.provider.disconnect();
224
- localStorage.removeItem(this.sessionTopicKey);
225
- }
226
- catch (e) {
227
- logger.debug(e);
228
- }
229
- });
230
- }
231
- providerSwitchNetwork({ network, provider, }) {
232
- const _super = Object.create(null, {
233
- providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
234
- });
235
- return __awaiter(this, void 0, void 0, function* () {
236
- const currentNetworkId = yield this.getNetwork();
237
- if (currentNetworkId && currentNetworkId === network.chainId) {
238
- return;
239
- }
240
- if (this.switchNetworkOnlyFromWallet) {
241
- throw new DynamicError('Network switching is only supported through the wallet');
242
- }
243
- if (!this.supportsNetworkSwitching()) {
244
- throw new DynamicError('Network switching not supported');
245
- }
246
- if (!provider) {
247
- throw new DynamicError('Provider not found');
248
- }
249
- return _super.providerSwitchNetwork.call(this, { network, provider });
250
- });
251
- }
252
- getConnectedAccounts() {
253
- return __awaiter(this, void 0, void 0, function* () {
254
- if (!this.session) {
255
- return [];
256
- }
257
- return [this.session.namespaces.eip155.accounts[0].split(':')[2]];
258
- });
259
- }
260
- }
261
-
262
- export { WalletConnectV2 as default };
@@ -1,6 +0,0 @@
1
- import { EthWalletConnectorOpts } from '../ethereum/EthWalletConnector';
2
- import WalletConnect from '.';
3
- declare class TrustWalletConnect extends WalletConnect {
4
- constructor(props: EthWalletConnectorOpts);
5
- }
6
- export default TrustWalletConnect;