@dynamic-labs/ethereum 2.0.0-alpha.6 → 2.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,25 @@
1
1
 
2
+ ## [2.0.0-alpha.8](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.7...v2.0.0-alpha.8) (2024-03-04)
3
+
4
+ ## [2.0.0-alpha.7](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.6...v2.0.0-alpha.7) (2024-02-28)
5
+
6
+
7
+ ### ⚠ BREAKING CHANGES
8
+
9
+ * add networkValidationMode and remove enableForcedNetworkValidation (#4778)
10
+
11
+ ### Features
12
+
13
+ * add bitget and okx wallets ([51fab41](https://github.com/dynamic-labs/DynamicAuth/commit/51fab413096fd89ce99c6c617cf4f3f5db9bf44d))
14
+ * add networkValidationMode and remove enableForcedNetworkValidation ([#4778](https://github.com/dynamic-labs/DynamicAuth/issues/4778)) ([ccb9576](https://github.com/dynamic-labs/DynamicAuth/commit/ccb9576c81b2c570185f5126d6d1fcfcbb5ac9e3))
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **GVTY-1243:** non evm onramp urls ([#4791](https://github.com/dynamic-labs/DynamicAuth/issues/4791)) ([fea602e](https://github.com/dynamic-labs/DynamicAuth/commit/fea602e2835b4bb9bc096b96375fa97297bf35f1))
20
+ * revert use enableForcedNetworkValidation on connect-only ([#4750](https://github.com/dynamic-labs/DynamicAuth/issues/4750)) ([#4772](https://github.com/dynamic-labs/DynamicAuth/issues/4772)) ([b871c22](https://github.com/dynamic-labs/DynamicAuth/commit/b871c2295f39230bc34ae1fca5f8817cd9251a17))
21
+ * use correct chromeId for okx and bitget wallets and remove group from coin98 ([#4795](https://github.com/dynamic-labs/DynamicAuth/issues/4795)) ([e63bad7](https://github.com/dynamic-labs/DynamicAuth/commit/e63bad76ed06636151212c915a102359a03b4218))
22
+
2
23
  ## [2.0.0-alpha.6](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.5...v2.0.0-alpha.6) (2024-02-26)
3
24
 
4
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -30,12 +30,12 @@
30
30
  "@walletconnect/universal-provider": "2.10.6",
31
31
  "eventemitter3": "5.0.1",
32
32
  "buffer": "6.0.3",
33
- "@dynamic-labs/rpc-provider-ethereum": "2.0.0-alpha.6",
34
- "@dynamic-labs/turnkey": "2.0.0-alpha.6",
35
- "@dynamic-labs/types": "2.0.0-alpha.6",
36
- "@dynamic-labs/utils": "2.0.0-alpha.6",
37
- "@dynamic-labs/wallet-book": "2.0.0-alpha.6",
38
- "@dynamic-labs/wallet-connector-core": "2.0.0-alpha.6",
33
+ "@dynamic-labs/rpc-provider-ethereum": "2.0.0-alpha.8",
34
+ "@dynamic-labs/turnkey": "2.0.0-alpha.8",
35
+ "@dynamic-labs/types": "2.0.0-alpha.8",
36
+ "@dynamic-labs/utils": "2.0.0-alpha.8",
37
+ "@dynamic-labs/wallet-book": "2.0.0-alpha.8",
38
+ "@dynamic-labs/wallet-connector-core": "2.0.0-alpha.8",
39
39
  "stream": "0.0.2"
40
40
  },
41
41
  "peerDependencies": {
@@ -19,6 +19,7 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
19
19
  var { appName, appLogoUrl, evmNetworks } = _a, props = _tslib.__rest(_a, ["appName", "appLogoUrl", "evmNetworks"]);
20
20
  super(Object.assign({ evmNetworks }, props));
21
21
  this.name = 'Coinbase';
22
+ this.overrideKey = 'coinbase';
22
23
  this.supportedChains = ['EVM', 'ETH'];
23
24
  this.connectedChain = 'EVM';
24
25
  this.canConnectViaQrCode = true;
@@ -7,6 +7,7 @@ type CoinbaseOpts = EthWalletConnectorOpts & {
7
7
  };
8
8
  export declare class Coinbase extends EthWalletConnector {
9
9
  name: string;
10
+ overrideKey: string;
10
11
  supportedChains: Chain[];
11
12
  connectedChain: Chain;
12
13
  canConnectViaQrCode: boolean;
@@ -15,6 +15,7 @@ class Coinbase extends EthWalletConnector {
15
15
  var { appName, appLogoUrl, evmNetworks } = _a, props = __rest(_a, ["appName", "appLogoUrl", "evmNetworks"]);
16
16
  super(Object.assign({ evmNetworks }, props));
17
17
  this.name = 'Coinbase';
18
+ this.overrideKey = 'coinbase';
18
19
  this.supportedChains = ['EVM', 'ETH'];
19
20
  this.connectedChain = 'EVM';
20
21
  this.canConnectViaQrCode = true;
@@ -10,6 +10,7 @@ class ExodusEvm extends InjectedWalletBase {
10
10
  constructor(props) {
11
11
  super(props);
12
12
  this.name = 'ExodusEvm';
13
+ this.overrideKey = 'exodusevm';
13
14
  this.walletConnectorFallback = true;
14
15
  this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
15
16
  }
@@ -2,6 +2,7 @@ import { EthWalletConnectorOpts } from '..';
2
2
  import InjectedWalletBase from './InjectedWalletBase';
3
3
  export declare class ExodusEvm extends InjectedWalletBase {
4
4
  name: string;
5
+ overrideKey: string;
5
6
  walletConnectorFallback: boolean;
6
7
  constructor(props: EthWalletConnectorOpts);
7
8
  }
@@ -6,6 +6,7 @@ class ExodusEvm extends InjectedWalletBase {
6
6
  constructor(props) {
7
7
  super(props);
8
8
  this.name = 'ExodusEvm';
9
+ this.overrideKey = 'exodusevm';
9
10
  this.walletConnectorFallback = true;
10
11
  this.wallet = findWalletBookWallet(this.walletBook, this.key);
11
12
  }
@@ -11,6 +11,7 @@ class PhantomEvm extends InjectedWalletBase {
11
11
  constructor(props) {
12
12
  super(props);
13
13
  this.name = 'PhantomEvm';
14
+ this.overrideKey = 'phantomevm';
14
15
  this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
15
16
  }
16
17
  fetchPublicAddress() {
@@ -2,6 +2,7 @@ import { EthWalletConnectorOpts } from '..';
2
2
  import InjectedWalletBase from './InjectedWalletBase';
3
3
  export declare class PhantomEvm extends InjectedWalletBase {
4
4
  name: string;
5
+ overrideKey: string;
5
6
  constructor(props: EthWalletConnectorOpts);
6
7
  fetchPublicAddress(): Promise<string | undefined>;
7
8
  }
@@ -7,6 +7,7 @@ class PhantomEvm extends InjectedWalletBase {
7
7
  constructor(props) {
8
8
  super(props);
9
9
  this.name = 'PhantomEvm';
10
+ this.overrideKey = 'phantomevm';
10
11
  this.wallet = findWalletBookWallet(this.walletBook, this.key);
11
12
  }
12
13
  fetchPublicAddress() {
@@ -6,14 +6,15 @@ var walletConnect = require('./walletConnect.cjs');
6
6
 
7
7
  const fetchWalletConnectWallets = ({ walletBook, }) => {
8
8
  var _a;
9
- return Object.values((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
10
- .filter((wallet) => wallet.walletConnect && !wallet.filterFromWalletConnect)
11
- .map((wallet) => {
9
+ return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
10
+ .filter(([, wallet]) => wallet.walletConnect && !wallet.filterFromWalletConnect)
11
+ .map(([key, wallet]) => {
12
12
  const { shortName } = wallet;
13
13
  const name = shortName || wallet.name;
14
14
  return class extends walletConnect.WalletConnect {
15
15
  constructor(props) {
16
16
  super(Object.assign(Object.assign({}, props), { walletName: name }));
17
+ this.overrideKey = key;
17
18
  }
18
19
  };
19
20
  });
@@ -2,14 +2,15 @@ import { WalletConnect } from './walletConnect.js';
2
2
 
3
3
  const fetchWalletConnectWallets = ({ walletBook, }) => {
4
4
  var _a;
5
- return Object.values((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
6
- .filter((wallet) => wallet.walletConnect && !wallet.filterFromWalletConnect)
7
- .map((wallet) => {
5
+ return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
6
+ .filter(([, wallet]) => wallet.walletConnect && !wallet.filterFromWalletConnect)
7
+ .map(([key, wallet]) => {
8
8
  const { shortName } = wallet;
9
9
  const name = shortName || wallet.name;
10
10
  return class extends WalletConnect {
11
11
  constructor(props) {
12
12
  super(Object.assign(Object.assign({}, props), { walletName: name }));
13
+ this.overrideKey = key;
13
14
  }
14
15
  };
15
16
  });
@@ -6,9 +6,9 @@ var _tslib = require('../../_virtual/_tslib.cjs');
6
6
  var Provider = require('@walletconnect/universal-provider');
7
7
  var EventEmitter = require('eventemitter3');
8
8
  var viem = require('viem');
9
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
10
- var walletBook = require('@dynamic-labs/wallet-book');
11
9
  var utils = require('@dynamic-labs/utils');
10
+ var walletBook = require('@dynamic-labs/wallet-book');
11
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
12
12
  var EthWalletConnector = require('../EthWalletConnector.cjs');
13
13
  var parseIntSafe = require('../utils/parseIntSafe.cjs');
14
14
 
@@ -53,11 +53,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
53
53
  .map((network) => `eip155:${network.chainId}`));
54
54
  }
55
55
  getMappedChainsByPreferredOrder() {
56
- // adding Ethereum to avoid an error connecting if none of the evm networks are supported by the wallet
57
56
  const allChains = this.getMappedChains();
58
- if (!allChains.includes('eip155:1')) {
59
- allChains.push('eip155:1');
60
- }
61
57
  const reorderedChains = this.preferredChains.filter((chain) => allChains.includes(chain));
62
58
  const remainingChains = allChains.filter((chain) => !this.preferredChains.includes(chain));
63
59
  return [...reorderedChains, ...remainingChains];
@@ -102,15 +98,17 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
102
98
  }
103
99
  createInitProviderPromise() {
104
100
  return _tslib.__awaiter(this, void 0, void 0, function* () {
105
- const provider = yield Provider__default["default"].init({
101
+ WalletConnect.provider = yield Provider__default["default"].init({
106
102
  logger: walletConnectorCore.logger.logLevel.toLowerCase() === 'debug' ? 'debug' : undefined,
107
103
  projectId: this.projectId,
108
104
  });
109
- WalletConnect.provider = provider;
110
105
  this.teardownEventListeners();
111
106
  this.setupEventListeners();
112
107
  });
113
108
  }
109
+ // We need to add a gate to this method since we will be calling it asynchronously
110
+ // from different places (such as setShowAuthFlow), which means there's a chance for
111
+ // a race condition to happen where createInitProviderPromise is called multiple times
114
112
  initProvider() {
115
113
  return _tslib.__awaiter(this, void 0, void 0, function* () {
116
114
  const { provider } = WalletConnect;
@@ -246,7 +244,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
246
244
  // the connection is established, but we need to wait for it to
247
245
  // finish setting up the connection URI and making it available
248
246
  // on the provider
249
- yield new Promise((resolve) => setTimeout(resolve, 1000));
247
+ yield utils.sleep(1000);
250
248
  if (!WalletConnect.provider || !((_b = WalletConnect.provider) === null || _b === void 0 ? void 0 : _b.uri)) {
251
249
  walletConnectorCore.logger.debug('No WC2 provider found, escaping and throwing error');
252
250
  throw new utils.DynamicError('No provider found');
@@ -262,7 +260,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
262
260
  reject(new utils.DynamicError('No provider found'));
263
261
  return;
264
262
  }
265
- ee.on('walletconnect_connection_failed', () => {
263
+ const onFail = () => {
266
264
  const error = new utils.DynamicError('Connection rejected. Please try again.');
267
265
  error.code = 'connection_rejected';
268
266
  if (WalletConnect.provider) {
@@ -274,15 +272,28 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
274
272
  this.init();
275
273
  }
276
274
  reject(error);
277
- });
278
- WalletConnect.provider.on('connect', ({ session }) => {
275
+ // We must clean up the onConnect and onFail listeners
276
+ // whenever the connection attempt either succeeds or fails
277
+ cleanupListeners();
278
+ };
279
+ const onConnect = ({ session }) => {
279
280
  if (!session) {
280
281
  reject(new utils.DynamicError('No session found'));
281
282
  }
282
283
  this.setSession(session);
283
284
  this.setActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
284
285
  resolve(this.activeAccount);
285
- });
286
+ // We must clean up the onConnect and onFail listeners
287
+ // whenever the connection attempt either succeeds or fails
288
+ cleanupListeners();
289
+ };
290
+ const cleanupListeners = () => {
291
+ var _a;
292
+ ee.off('walletconnect_connection_failed', onFail);
293
+ (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.off('connect', onConnect);
294
+ };
295
+ ee.on('walletconnect_connection_failed', onFail);
296
+ WalletConnect.provider.on('connect', onConnect);
286
297
  });
287
298
  });
288
299
  }
@@ -1,7 +1,7 @@
1
1
  import type { SessionTypes } from '@walletconnect/types';
2
2
  import { Hex, WalletClient } from 'viem';
3
- import { Chain, FetchPublicAddressOpts, DeepLinkVariant } from '@dynamic-labs/wallet-connector-core';
4
3
  import { EvmNetwork } from '@dynamic-labs/types';
4
+ import { Chain, DeepLinkVariant, FetchPublicAddressOpts, IWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
5
5
  import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
6
6
  export type WalletConnectOpts = EthWalletConnectorOpts & {
7
7
  projectId?: string;
@@ -9,7 +9,7 @@ export type WalletConnectOpts = EthWalletConnectorOpts & {
9
9
  deepLinkPreference?: DeepLinkVariant;
10
10
  walletConnectPreferredChains?: `eip155:${number}`[];
11
11
  };
12
- export declare class WalletConnect extends EthWalletConnector {
12
+ export declare class WalletConnect extends EthWalletConnector implements IWalletConnectConnector {
13
13
  supportedChains: Chain[];
14
14
  connectedChain: Chain;
15
15
  name: string;
@@ -329,5 +329,5 @@ export declare class WalletConnect extends EthWalletConnector {
329
329
  }): Promise<void>;
330
330
  getConnectedAccounts(): Promise<string[]>;
331
331
  private isMetaMask;
332
- getSupportedNetworks(): Promise<string[] | undefined>;
332
+ getSupportedNetworks(): Promise<string[]>;
333
333
  }
@@ -2,9 +2,9 @@ import { __awaiter } from '../../_virtual/_tslib.js';
2
2
  import Provider from '@walletconnect/universal-provider';
3
3
  import EventEmitter from 'eventemitter3';
4
4
  import { createWalletClient, custom } from 'viem';
5
- import { logger, performPlatformSpecificConnectionMethod, getDeepLink } from '@dynamic-labs/wallet-connector-core';
5
+ import { DynamicError, sleep, isMobile } from '@dynamic-labs/utils';
6
6
  import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
7
- import { DynamicError, isMobile } from '@dynamic-labs/utils';
7
+ import { logger, performPlatformSpecificConnectionMethod, getDeepLink } from '@dynamic-labs/wallet-connector-core';
8
8
  import { EthWalletConnector } from '../EthWalletConnector.js';
9
9
  import { parseIntSafe } from '../utils/parseIntSafe.js';
10
10
 
@@ -44,11 +44,7 @@ class WalletConnect extends EthWalletConnector {
44
44
  .map((network) => `eip155:${network.chainId}`));
45
45
  }
46
46
  getMappedChainsByPreferredOrder() {
47
- // adding Ethereum to avoid an error connecting if none of the evm networks are supported by the wallet
48
47
  const allChains = this.getMappedChains();
49
- if (!allChains.includes('eip155:1')) {
50
- allChains.push('eip155:1');
51
- }
52
48
  const reorderedChains = this.preferredChains.filter((chain) => allChains.includes(chain));
53
49
  const remainingChains = allChains.filter((chain) => !this.preferredChains.includes(chain));
54
50
  return [...reorderedChains, ...remainingChains];
@@ -93,15 +89,17 @@ class WalletConnect extends EthWalletConnector {
93
89
  }
94
90
  createInitProviderPromise() {
95
91
  return __awaiter(this, void 0, void 0, function* () {
96
- const provider = yield Provider.init({
92
+ WalletConnect.provider = yield Provider.init({
97
93
  logger: logger.logLevel.toLowerCase() === 'debug' ? 'debug' : undefined,
98
94
  projectId: this.projectId,
99
95
  });
100
- WalletConnect.provider = provider;
101
96
  this.teardownEventListeners();
102
97
  this.setupEventListeners();
103
98
  });
104
99
  }
100
+ // We need to add a gate to this method since we will be calling it asynchronously
101
+ // from different places (such as setShowAuthFlow), which means there's a chance for
102
+ // a race condition to happen where createInitProviderPromise is called multiple times
105
103
  initProvider() {
106
104
  return __awaiter(this, void 0, void 0, function* () {
107
105
  const { provider } = WalletConnect;
@@ -237,7 +235,7 @@ class WalletConnect extends EthWalletConnector {
237
235
  // the connection is established, but we need to wait for it to
238
236
  // finish setting up the connection URI and making it available
239
237
  // on the provider
240
- yield new Promise((resolve) => setTimeout(resolve, 1000));
238
+ yield sleep(1000);
241
239
  if (!WalletConnect.provider || !((_b = WalletConnect.provider) === null || _b === void 0 ? void 0 : _b.uri)) {
242
240
  logger.debug('No WC2 provider found, escaping and throwing error');
243
241
  throw new DynamicError('No provider found');
@@ -253,7 +251,7 @@ class WalletConnect extends EthWalletConnector {
253
251
  reject(new DynamicError('No provider found'));
254
252
  return;
255
253
  }
256
- ee.on('walletconnect_connection_failed', () => {
254
+ const onFail = () => {
257
255
  const error = new DynamicError('Connection rejected. Please try again.');
258
256
  error.code = 'connection_rejected';
259
257
  if (WalletConnect.provider) {
@@ -265,15 +263,28 @@ class WalletConnect extends EthWalletConnector {
265
263
  this.init();
266
264
  }
267
265
  reject(error);
268
- });
269
- WalletConnect.provider.on('connect', ({ session }) => {
266
+ // We must clean up the onConnect and onFail listeners
267
+ // whenever the connection attempt either succeeds or fails
268
+ cleanupListeners();
269
+ };
270
+ const onConnect = ({ session }) => {
270
271
  if (!session) {
271
272
  reject(new DynamicError('No session found'));
272
273
  }
273
274
  this.setSession(session);
274
275
  this.setActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
275
276
  resolve(this.activeAccount);
276
- });
277
+ // We must clean up the onConnect and onFail listeners
278
+ // whenever the connection attempt either succeeds or fails
279
+ cleanupListeners();
280
+ };
281
+ const cleanupListeners = () => {
282
+ var _a;
283
+ ee.off('walletconnect_connection_failed', onFail);
284
+ (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.off('connect', onConnect);
285
+ };
286
+ ee.on('walletconnect_connection_failed', onFail);
287
+ WalletConnect.provider.on('connect', onConnect);
277
288
  });
278
289
  });
279
290
  }