@dynamic-labs/ethereum 3.0.0-alpha.52 → 3.0.0-alpha.54

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 (37) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/package.json +7 -8
  3. package/src/coinbase/coinbase.cjs +1 -2
  4. package/src/coinbase/coinbase.d.ts +1 -1
  5. package/src/coinbase/coinbase.js +1 -2
  6. package/src/coinbase/types.d.ts +1 -1
  7. package/src/ethProviderHelper.d.ts +1 -1
  8. package/src/index.cjs +5 -7
  9. package/src/index.d.ts +1 -2
  10. package/src/index.js +1 -4
  11. package/src/injected/ExodusEvm.d.ts +1 -1
  12. package/src/injected/FallbackEvmConnector.d.ts +1 -1
  13. package/src/injected/InjectedWalletBase.cjs +4 -3
  14. package/src/injected/InjectedWalletBase.d.ts +2 -2
  15. package/src/injected/InjectedWalletBase.js +3 -2
  16. package/src/injected/PhantomEvm.d.ts +1 -1
  17. package/src/injected/UnknownInjected.d.ts +1 -1
  18. package/src/walletConnect/walletConnect.cjs +1 -2
  19. package/src/walletConnect/walletConnect.d.ts +1 -1
  20. package/src/walletConnect/walletConnect.js +1 -2
  21. package/src/EthWalletConnector.cjs +0 -250
  22. package/src/EthWalletConnector.d.ts +0 -3087
  23. package/src/EthWalletConnector.js +0 -246
  24. package/src/utils/L2ResolverAbi.cjs +0 -1287
  25. package/src/utils/L2ResolverAbi.d.ts +0 -993
  26. package/src/utils/L2ResolverAbi.js +0 -1285
  27. package/src/utils/findEvmNetwork.cjs +0 -21
  28. package/src/utils/findEvmNetwork.d.ts +0 -6
  29. package/src/utils/findEvmNetwork.js +0 -17
  30. package/src/utils/getNameservice.cjs +0 -66
  31. package/src/utils/getNameservice.d.ts +0 -6
  32. package/src/utils/getNameservice.js +0 -62
  33. package/src/utils/index.d.ts +0 -2
  34. package/src/utils/isEthWalletConnector/index.d.ts +0 -1
  35. package/src/utils/isEthWalletConnector/isEthWalletConnector.cjs +0 -8
  36. package/src/utils/isEthWalletConnector/isEthWalletConnector.d.ts +0 -3
  37. package/src/utils/isEthWalletConnector/isEthWalletConnector.js +0 -4
package/CHANGELOG.md CHANGED
@@ -1,4 +1,50 @@
1
1
 
2
+ ## [3.0.0-alpha.54](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.53...v3.0.0-alpha.54) (2024-08-29)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * transaction hanging in confirmation modal ([#6740](https://github.com/dynamic-labs/DynamicAuth/issues/6740)) ([f03d286](https://github.com/dynamic-labs/DynamicAuth/commit/f03d286aaf471dbc7a6149acee10512be7b56b18))
8
+
9
+ ## [3.0.0-alpha.53](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.52...v3.0.0-alpha.53) (2024-08-29)
10
+
11
+
12
+ ### ⚠ BREAKING CHANGES
13
+
14
+ * simplify solana wallet signer types (#6748)
15
+ * deprecate getEoaConnector (#6571)
16
+ * limit methods and props returned by wallet.connector (#6540)
17
+ * move generic solana code to solana-core package (#6701)
18
+ * revamp ether v6 interface (#6548)
19
+ * add ethereum wallet specific methods and intercept to sync when needed (#6662)
20
+ * add solana wallet specific methods and intercept to sync when needed (#6608)
21
+ * don't force primary wallet to be connected (#6128)
22
+
23
+ ### Features
24
+
25
+ * add bitcoin wallet specific methods and intercept to sync when needed ([#6663](https://github.com/dynamic-labs/DynamicAuth/issues/6663)) ([ed699b1](https://github.com/dynamic-labs/DynamicAuth/commit/ed699b1f8c264755779ec4840d105f89ade5500e))
26
+ * add ethereum wallet specific methods and intercept to sync when needed ([#6662](https://github.com/dynamic-labs/DynamicAuth/issues/6662)) ([372360e](https://github.com/dynamic-labs/DynamicAuth/commit/372360ed7ca395f88811fc62c94b2b494eb59971))
27
+ * add solana wallet specific methods and intercept to sync when needed ([#6608](https://github.com/dynamic-labs/DynamicAuth/issues/6608)) ([565f610](https://github.com/dynamic-labs/DynamicAuth/commit/565f6100340296c267e9706fd263e9bd3f7d3732))
28
+ * add useSmartWallets hook to manage aa wallets ([#6564](https://github.com/dynamic-labs/DynamicAuth/issues/6564)) ([a243d36](https://github.com/dynamic-labs/DynamicAuth/commit/a243d361ce7c368d0f1afda55f9c1fabefd75ba8))
29
+ * don't force primary wallet to be connected ([#6128](https://github.com/dynamic-labs/DynamicAuth/issues/6128)) ([018a6f6](https://github.com/dynamic-labs/DynamicAuth/commit/018a6f66f8725914ab97ea3e2e1c80626266e503))
30
+ * new prop to enable prompt for linking when account change is detected ([#6713](https://github.com/dynamic-labs/DynamicAuth/issues/6713)) ([b5a6321](https://github.com/dynamic-labs/DynamicAuth/commit/b5a63212ae33fae24401f141d5ca2356b446dcff))
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * always sync wagmi client with primary wallet ([#6577](https://github.com/dynamic-labs/DynamicAuth/issues/6577)) ([be22fde](https://github.com/dynamic-labs/DynamicAuth/commit/be22fdea3bb61db79b06ba56cb32da6cd8141b66))
36
+ * cosmos wallet intercepts ([#6720](https://github.com/dynamic-labs/DynamicAuth/issues/6720)) ([cfc9df4](https://github.com/dynamic-labs/DynamicAuth/commit/cfc9df48a8032f7348fec14f77b9e378d2e26a22))
37
+ * magiceden wallet events not working correctly on page refresh ([#6735](https://github.com/dynamic-labs/DynamicAuth/issues/6735)) ([6ed5964](https://github.com/dynamic-labs/DynamicAuth/commit/6ed5964134a2cafd392c19f18eb71e6ca2ce238d))
38
+ * use proxy to intercept solana signer methods ([#6743](https://github.com/dynamic-labs/DynamicAuth/issues/6743)) ([ecbe5ea](https://github.com/dynamic-labs/DynamicAuth/commit/ecbe5ea772592d2c693d8222d85b7642acd151a8))
39
+ * wallet.chain references ([525c1ca](https://github.com/dynamic-labs/DynamicAuth/commit/525c1ca9a8fe6402c06eabe6aebc30e310411d9b))
40
+
41
+
42
+ * deprecate getEoaConnector ([#6571](https://github.com/dynamic-labs/DynamicAuth/issues/6571)) ([0226ee5](https://github.com/dynamic-labs/DynamicAuth/commit/0226ee5a13f2418607076ee6f2ec0a579b06dd5d))
43
+ * limit methods and props returned by wallet.connector ([#6540](https://github.com/dynamic-labs/DynamicAuth/issues/6540)) ([9c86e35](https://github.com/dynamic-labs/DynamicAuth/commit/9c86e35c72cd40313bfd19254dd6171ee8f62213))
44
+ * move generic solana code to solana-core package ([#6701](https://github.com/dynamic-labs/DynamicAuth/issues/6701)) ([30815f5](https://github.com/dynamic-labs/DynamicAuth/commit/30815f5d46feeefb2413c1b7d30b43d5370ee032))
45
+ * revamp ether v6 interface ([#6548](https://github.com/dynamic-labs/DynamicAuth/issues/6548)) ([f3b2fb8](https://github.com/dynamic-labs/DynamicAuth/commit/f3b2fb8da7de21f9c58e67fa7f5580166195092a))
46
+ * simplify solana wallet signer types ([#6748](https://github.com/dynamic-labs/DynamicAuth/issues/6748)) ([01d1a42](https://github.com/dynamic-labs/DynamicAuth/commit/01d1a42bc916ab329580b741ba60d706bf6c5491))
47
+
2
48
  ## [3.0.0-alpha.52](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.51...v3.0.0-alpha.52) (2024-08-28)
3
49
 
4
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "3.0.0-alpha.52",
3
+ "version": "3.0.0-alpha.54",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
@@ -26,17 +26,16 @@
26
26
  "./package.json": "./package.json"
27
27
  },
28
28
  "dependencies": {
29
- "@dynamic-labs/sdk-api-core": "0.0.519",
30
29
  "@coinbase/wallet-sdk": "4.0.4",
31
30
  "@walletconnect/ethereum-provider": "2.11.2",
32
31
  "eventemitter3": "5.0.1",
33
32
  "buffer": "6.0.3",
34
- "@dynamic-labs/embedded-wallet-evm": "3.0.0-alpha.52",
35
- "@dynamic-labs/ethereum-core": "3.0.0-alpha.52",
36
- "@dynamic-labs/types": "3.0.0-alpha.52",
37
- "@dynamic-labs/utils": "3.0.0-alpha.52",
38
- "@dynamic-labs/wallet-book": "3.0.0-alpha.52",
39
- "@dynamic-labs/wallet-connector-core": "3.0.0-alpha.52",
33
+ "@dynamic-labs/embedded-wallet-evm": "3.0.0-alpha.54",
34
+ "@dynamic-labs/ethereum-core": "3.0.0-alpha.54",
35
+ "@dynamic-labs/types": "3.0.0-alpha.54",
36
+ "@dynamic-labs/utils": "3.0.0-alpha.54",
37
+ "@dynamic-labs/wallet-book": "3.0.0-alpha.54",
38
+ "@dynamic-labs/wallet-connector-core": "3.0.0-alpha.54",
40
39
  "stream": "0.0.2"
41
40
  },
42
41
  "peerDependencies": {
@@ -7,10 +7,9 @@ var _tslib = require('../../_virtual/_tslib.cjs');
7
7
  var viem = require('viem');
8
8
  var ethereumCore = require('@dynamic-labs/ethereum-core');
9
9
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
10
- var EthWalletConnector = require('../EthWalletConnector.cjs');
11
10
  var helpers = require('./helpers.cjs');
12
11
 
13
- class Coinbase extends EthWalletConnector.EthWalletConnector {
12
+ class Coinbase extends ethereumCore.EthWalletConnector {
14
13
  constructor(_a) {
15
14
  var { appName, appLogoUrl, evmNetworks, coinbaseWalletPreference } = _a, props = _tslib.__rest(_a, ["appName", "appLogoUrl", "evmNetworks", "coinbaseWalletPreference"]);
16
15
  super(Object.assign({ evmNetworks }, props));
@@ -1,7 +1,7 @@
1
1
  import { WalletClient, Account, Transport, Chain as ViemChain } from 'viem';
2
2
  import { ProviderInterface } from '@coinbase/wallet-sdk';
3
+ import { EthWalletConnector } from '@dynamic-labs/ethereum-core';
3
4
  import { Chain } from '@dynamic-labs/wallet-connector-core';
4
- import { EthWalletConnector } from '../EthWalletConnector';
5
5
  import { CoinbaseOpts, GetCoinbaseProviderOpts } from './types';
6
6
  export declare class Coinbase extends EthWalletConnector {
7
7
  name: string;
@@ -1,9 +1,8 @@
1
1
  'use client'
2
2
  import { __rest, __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { toHex, toBytes, createWalletClient, custom } from 'viem';
4
- import { chainsMap } from '@dynamic-labs/ethereum-core';
4
+ import { EthWalletConnector, chainsMap } from '@dynamic-labs/ethereum-core';
5
5
  import { eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
6
- import { EthWalletConnector } from '../EthWalletConnector.js';
7
6
  import { getCoinbaseProvider } from './helpers.js';
8
7
 
9
8
  class Coinbase extends EthWalletConnector {
@@ -1,6 +1,6 @@
1
1
  import { type ProviderInterface } from '@coinbase/wallet-sdk';
2
2
  import { type CoinbaseWalletPreference, type GenericNetwork } from '@dynamic-labs/types';
3
- import { type EthWalletConnectorOpts } from '../EthWalletConnector';
3
+ import { type EthWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
4
4
  export type GetCoinbaseProviderOpts = {
5
5
  appLogoUrl?: string;
6
6
  appName?: string;
@@ -1,8 +1,8 @@
1
1
  import { Hex, WalletClient, Account, Transport, Chain as ViemChain } from 'viem';
2
2
  import { ProviderCondition, WalletConnector } from '@dynamic-labs/wallet-connector-core';
3
3
  import { WalletSchema } from '@dynamic-labs/wallet-book';
4
+ import { EthWalletConnector } from '@dynamic-labs/ethereum-core';
4
5
  import { IEthereum, ExtensionLocator } from './types';
5
- import { EthWalletConnector } from '.';
6
6
  export declare class EthProviderHelper {
7
7
  private wallet;
8
8
  private connector;
package/src/index.cjs CHANGED
@@ -13,12 +13,9 @@ var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConne
13
13
  require('./walletConnect/walletConnect.cjs');
14
14
  var fetchWalletConnectWallets = require('./walletConnect/fetchWalletConnectWallets.cjs');
15
15
  var coinbase = require('./coinbase/coinbase.cjs');
16
- require('@dynamic-labs/ethereum-core');
17
- var EthWalletConnector = require('./EthWalletConnector.cjs');
16
+ var ethereumCore = require('@dynamic-labs/ethereum-core');
18
17
  var ethProviderHelper = require('./ethProviderHelper.cjs');
19
18
  var constants = require('./constants.cjs');
20
- var isEthWalletConnector = require('./utils/isEthWalletConnector/isEthWalletConnector.cjs');
21
- var getNameservice = require('./utils/getNameservice.cjs');
22
19
 
23
20
  const EthereumWalletConnectors = (props) => [
24
21
  ...fetchInjectedWalletConnectors.injectedWalletOverrides,
@@ -37,9 +34,10 @@ exports.UnknownInjected = UnknownInjected.UnknownInjected;
37
34
  exports.FallbackEvmConnector = FallbackEvmConnector.FallbackEvmConnector;
38
35
  exports.fetchInjectedWalletConnector = fetchInjectedWalletConnectors.fetchInjectedWalletConnector;
39
36
  exports.injectedWalletOverrides = fetchInjectedWalletConnectors.injectedWalletOverrides;
40
- exports.EthWalletConnector = EthWalletConnector.EthWalletConnector;
37
+ Object.defineProperty(exports, 'isEthereumWallet', {
38
+ enumerable: true,
39
+ get: function () { return ethereumCore.isEthereumWallet; }
40
+ });
41
41
  exports.EthProviderHelper = ethProviderHelper.EthProviderHelper;
42
42
  exports.INFURA_ID = constants.INFURA_ID;
43
- exports.isEthWalletConnector = isEthWalletConnector.isEthWalletConnector;
44
- exports.getNameservice = getNameservice.getNameservice;
45
43
  exports.EthereumWalletConnectors = EthereumWalletConnectors;
package/src/index.d.ts CHANGED
@@ -2,9 +2,8 @@ import './polyfills';
2
2
  import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
3
3
  import '@dynamic-labs/ethereum-core';
4
4
  export * from './injected';
5
- export * from './EthWalletConnector';
6
5
  export * from './ethProviderHelper';
7
6
  export * from './constants';
8
7
  export * from './types';
9
- export * from './utils';
10
8
  export declare const EthereumWalletConnectors: (props: any) => WalletConnectorConstructor[];
9
+ export { isEthereumWallet } from '@dynamic-labs/ethereum-core';
package/src/index.js CHANGED
@@ -12,12 +12,9 @@ export { fetchInjectedWalletConnector, injectedWalletOverrides } from './injecte
12
12
  import './walletConnect/walletConnect.js';
13
13
  import { fetchWalletConnectWallets, getWalletConnectConnector } from './walletConnect/fetchWalletConnectWallets.js';
14
14
  import { Coinbase } from './coinbase/coinbase.js';
15
- import '@dynamic-labs/ethereum-core';
16
- export { EthWalletConnector } from './EthWalletConnector.js';
15
+ export { isEthereumWallet } from '@dynamic-labs/ethereum-core';
17
16
  export { EthProviderHelper } from './ethProviderHelper.js';
18
17
  export { INFURA_ID } from './constants.js';
19
- export { isEthWalletConnector } from './utils/isEthWalletConnector/isEthWalletConnector.js';
20
- export { getNameservice } from './utils/getNameservice.js';
21
18
 
22
19
  const EthereumWalletConnectors = (props) => [
23
20
  ...injectedWalletOverrides,
@@ -1,4 +1,4 @@
1
- import { EthWalletConnectorOpts } from '..';
1
+ import { EthWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
2
2
  import InjectedWalletBase from './InjectedWalletBase';
3
3
  export declare class ExodusEvm extends InjectedWalletBase {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { EthWalletConnectorOpts } from '..';
1
+ import { EthWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
2
2
  import InjectedWalletBase from './InjectedWalletBase';
3
3
  export declare class FallbackEvmConnector extends InjectedWalletBase {
4
4
  name: string;
@@ -4,11 +4,11 @@
4
4
  var _tslib = require('../../_virtual/_tslib.cjs');
5
5
  var walletBook = require('@dynamic-labs/wallet-book');
6
6
  var utils = require('@dynamic-labs/utils');
7
+ var ethereumCore = require('@dynamic-labs/ethereum-core');
7
8
  var ethProviderHelper = require('../ethProviderHelper.cjs');
8
- var EthWalletConnector = require('../EthWalletConnector.cjs');
9
9
  var walletConnect = require('../walletConnect/walletConnect.cjs');
10
10
 
11
- class InjectedWalletBase extends EthWalletConnector.EthWalletConnector {
11
+ class InjectedWalletBase extends ethereumCore.EthWalletConnector {
12
12
  constructor() {
13
13
  super(...arguments);
14
14
  this.supportedChains = ['ETH', 'EVM'];
@@ -86,8 +86,9 @@ class InjectedWalletBase extends EthWalletConnector.EthWalletConnector {
86
86
  return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.signMessage(messageToSign);
87
87
  });
88
88
  }
89
- proveOwnership(messageToSign) {
89
+ proveOwnership(address, messageToSign) {
90
90
  return _tslib.__awaiter(this, void 0, void 0, function* () {
91
+ yield this.validateActiveWallet(address);
91
92
  return this.signMessage(messageToSign);
92
93
  });
93
94
  }
@@ -2,8 +2,8 @@ import { WalletClient, Transport, Account, Chain as ViemChain } from 'viem';
2
2
  import { Chain } from '@dynamic-labs/wallet-connector-core';
3
3
  import { EvmNetwork } from '@dynamic-labs/types';
4
4
  import { WalletSchema } from '@dynamic-labs/wallet-book';
5
+ import { EthWalletConnector } from '@dynamic-labs/ethereum-core';
5
6
  import { EthProviderHelper } from '../ethProviderHelper';
6
- import { EthWalletConnector } from '../EthWalletConnector';
7
7
  declare abstract class InjectedWalletBase extends EthWalletConnector {
8
8
  supportedChains: Chain[];
9
9
  connectedChain: Chain;
@@ -19,7 +19,7 @@ declare abstract class InjectedWalletBase extends EthWalletConnector {
19
19
  getAddress(): Promise<string | undefined>;
20
20
  connect(): Promise<void>;
21
21
  signMessage(messageToSign: string): Promise<string | undefined>;
22
- proveOwnership(messageToSign: string): Promise<string | undefined>;
22
+ proveOwnership(address: string, messageToSign: string): Promise<string | undefined>;
23
23
  endSession(): Promise<void>;
24
24
  providerSwitchNetwork({ network, provider, }: {
25
25
  network: EvmNetwork;
@@ -2,8 +2,8 @@
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
4
4
  import { isMobile } from '@dynamic-labs/utils';
5
+ import { EthWalletConnector } from '@dynamic-labs/ethereum-core';
5
6
  import { EthProviderHelper } from '../ethProviderHelper.js';
6
- import { EthWalletConnector } from '../EthWalletConnector.js';
7
7
  import { WalletConnect } from '../walletConnect/walletConnect.js';
8
8
 
9
9
  class InjectedWalletBase extends EthWalletConnector {
@@ -84,8 +84,9 @@ class InjectedWalletBase extends EthWalletConnector {
84
84
  return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.signMessage(messageToSign);
85
85
  });
86
86
  }
87
- proveOwnership(messageToSign) {
87
+ proveOwnership(address, messageToSign) {
88
88
  return __awaiter(this, void 0, void 0, function* () {
89
+ yield this.validateActiveWallet(address);
89
90
  return this.signMessage(messageToSign);
90
91
  });
91
92
  }
@@ -1,4 +1,4 @@
1
- import { EthWalletConnectorOpts } from '..';
1
+ import { EthWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
2
2
  import InjectedWalletBase from './InjectedWalletBase';
3
3
  export declare class PhantomEvm extends InjectedWalletBase {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { EthWalletConnectorOpts } from '..';
1
+ import { EthWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
2
2
  import InjectedWalletBase from './InjectedWalletBase';
3
3
  export declare class UnknownInjected extends InjectedWalletBase {
4
4
  name: string;
@@ -11,7 +11,6 @@ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
11
11
  var walletBook = require('@dynamic-labs/wallet-book');
12
12
  var utils = require('@dynamic-labs/utils');
13
13
  var ethereumCore = require('@dynamic-labs/ethereum-core');
14
- var EthWalletConnector = require('../EthWalletConnector.cjs');
15
14
  var parseIntSafe = require('../utils/parseIntSafe.cjs');
16
15
 
17
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -24,7 +23,7 @@ const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}
24
23
  const swicthedNetworkKey = (walletName) => `dynamic-wc2-switched-network-${walletName}`;
25
24
  const currentChainKey = (walletName) => `dynamic-wc2-current-chain-${walletName}`;
26
25
  const ee = new EventEmitter__default["default"]();
27
- class WalletConnect extends EthWalletConnector.EthWalletConnector {
26
+ class WalletConnect extends ethereumCore.EthWalletConnector {
28
27
  constructor(opts) {
29
28
  var _a;
30
29
  super(opts);
@@ -2,7 +2,7 @@ import type { SessionTypes } from '@walletconnect/types';
2
2
  import { WalletClient, Account, Transport, Chain as ViemChain } from 'viem';
3
3
  import { Chain, GetAddressOpts, DeepLinkVariant, IWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
4
4
  import { EvmNetwork } from '@dynamic-labs/types';
5
- import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
5
+ import { EthWalletConnector, EthWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
6
6
  export type WalletConnectOpts = EthWalletConnectorOpts & {
7
7
  projectId?: string;
8
8
  walletName: string;
@@ -6,8 +6,7 @@ import { createWalletClient, custom } from 'viem';
6
6
  import { logger, performPlatformSpecificConnectionMethod, getDeepLink } from '@dynamic-labs/wallet-connector-core';
7
7
  import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
8
8
  import { DynamicError, sleep, isMobile } from '@dynamic-labs/utils';
9
- import { chainsMap } from '@dynamic-labs/ethereum-core';
10
- import { EthWalletConnector } from '../EthWalletConnector.js';
9
+ import { EthWalletConnector, chainsMap } from '@dynamic-labs/ethereum-core';
11
10
  import { parseIntSafe } from '../utils/parseIntSafe.js';
12
11
 
13
12
  const activeAccountKey = (walletName) => `dynamic-wc2-active-account-${walletName}`;
@@ -1,250 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _tslib = require('../_virtual/_tslib.cjs');
7
- var viem = require('viem');
8
- var accounts = require('viem/accounts');
9
- var utils = require('@dynamic-labs/utils');
10
- var ethereumCore = require('@dynamic-labs/ethereum-core');
11
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
12
- var findEvmNetwork = require('./utils/findEvmNetwork.cjs');
13
- var getNameservice = require('./utils/getNameservice.cjs');
14
-
15
- class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
16
- getPublicClient() {
17
- return _tslib.__awaiter(this, void 0, void 0, function* () {
18
- var _a, _b;
19
- const networkId = (_a = (yield this.getNetwork())) !== null && _a !== void 0 ? _a : 1;
20
- if (this.evmNetworks.length === 0) {
21
- return undefined;
22
- }
23
- const configurations = {
24
- cosmos: [],
25
- evm: this.evmNetworks,
26
- solana: [],
27
- starknet: undefined,
28
- };
29
- if (!this.chainRpcProviders)
30
- return undefined;
31
- const providers = this.chainRpcProviders.getProviders(configurations);
32
- return (_b = this.chainRpcProviders.getEvmProviderByChainId(providers, networkId)) === null || _b === void 0 ? void 0 : _b.provider;
33
- });
34
- }
35
- constructor(props) {
36
- var _a;
37
- super(props);
38
- this.evmNetworkRpcMap = () => this.evmNetworks.reduce((acc, network) => {
39
- var _a;
40
- [acc[network.chainId]] = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a.length)
41
- ? network.privateCustomerRpcUrls
42
- : network.rpcUrls;
43
- return acc;
44
- }, {});
45
- this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks);
46
- this.chainRpcProviders = props.chainRpcProviders;
47
- (_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerEvmProviders();
48
- }
49
- getNetwork() {
50
- return _tslib.__awaiter(this, void 0, void 0, function* () {
51
- const provider = this.getWalletClient();
52
- if (!this.supportsNetworkSwitching || !provider) {
53
- return Promise.resolve(undefined);
54
- }
55
- const chainId = yield utils.retryableFn(provider.getChainId, {
56
- fallbackValue: utils.FALLBACK_UNDEFINED,
57
- /**
58
- * The timeout is set to 1 second because the getChainId method
59
- * takes around 500ms to resolve on Brave. If the timeout is not set
60
- * it will use 100ms by default and the method will fail.
61
- * QNTM-815
62
- */
63
- timeoutMs: 1000,
64
- });
65
- this.setActiveChain(ethereumCore.chainsMap[chainId]);
66
- return chainId;
67
- });
68
- }
69
- getNameService(address) {
70
- return _tslib.__awaiter(this, void 0, void 0, function* () {
71
- const rpcProvider = yield this.getPublicClient();
72
- if (!rpcProvider) {
73
- return;
74
- }
75
- return getNameservice.getNameservice({ address, rpcProvider });
76
- });
77
- }
78
- isTestnet() {
79
- return _tslib.__awaiter(this, void 0, void 0, function* () {
80
- var _a, _b, _c;
81
- return (_c = (_b = (_a = (yield this.getPublicClient())) === null || _a === void 0 ? void 0 : _a.chain) === null || _b === void 0 ? void 0 : _b.testnet) !== null && _c !== void 0 ? _c : false;
82
- });
83
- }
84
- parseAddress(address) {
85
- try {
86
- // Ensures the address follows the EIP55 format.
87
- // see: https://eips.ethereum.org/EIPS/eip-55
88
- return viem.getAddress(address);
89
- }
90
- catch (err) {
91
- walletConnectorCore.logger.debug(`Failed to parse EVM address into EIP55 format: error getting checksum, returning default ${address}`, err);
92
- }
93
- return address;
94
- }
95
- getSigner() {
96
- return _tslib.__awaiter(this, void 0, void 0, function* () {
97
- return this.getWalletClient();
98
- });
99
- }
100
- getBalance(address) {
101
- return _tslib.__awaiter(this, void 0, void 0, function* () {
102
- const client = yield this.getPublicClient();
103
- const result = yield (client === null || client === void 0 ? void 0 : client.getBalance({
104
- address: address,
105
- }));
106
- if (!result && result !== BigInt(0))
107
- return;
108
- return viem.formatEther(result);
109
- });
110
- }
111
- supportsNetworkSwitching() {
112
- return true;
113
- }
114
- switchNetwork(_a) {
115
- return _tslib.__awaiter(this, arguments, void 0, function* ({ networkName, networkChainId, }) {
116
- const network = findEvmNetwork.findEvmNetwork({
117
- chainId: networkChainId,
118
- name: networkName,
119
- networks: this.evmNetworks,
120
- });
121
- if (!network) {
122
- throw new utils.DynamicError(`Could not find network mapping for chain ${networkName ? networkName : networkChainId}`);
123
- }
124
- if (!this.supportsNetworkSwitching()) {
125
- throw new utils.DynamicError('Network switching is not supported');
126
- }
127
- const provider = this.getWalletClient();
128
- if (!provider) {
129
- throw new utils.DynamicError('Provider not found');
130
- }
131
- return this.providerSwitchNetwork({ network, provider });
132
- });
133
- }
134
- getConnectedAccounts() {
135
- return _tslib.__awaiter(this, void 0, void 0, function* () {
136
- const provider = this.getWalletClient();
137
- if (!provider)
138
- return [];
139
- const addresses = yield utils.retryableFn(provider.getAddresses, {
140
- fallbackValue: [],
141
- timeoutMs: 500,
142
- });
143
- if (addresses.length) {
144
- this.setActiveAccount(addresses[0]);
145
- }
146
- return addresses;
147
- });
148
- }
149
- providerSwitchNetwork(_a) {
150
- return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
151
- var _b, _c, _d, _e;
152
- const { chainId } = network;
153
- const currentNetworkId = yield this.getNetwork();
154
- if (currentNetworkId && currentNetworkId === chainId) {
155
- return;
156
- }
157
- try {
158
- if (!this.supportsNetworkSwitching()) {
159
- throw new utils.DynamicError('Network switching is not supported');
160
- }
161
- const viemChain = ethereumCore.getOrMapViemChain(network);
162
- yield provider.switchChain(viemChain);
163
- if (this.key === 'magiceden') {
164
- const newChainId = yield provider.getChainId();
165
- this.emit('chainChange', { chain: newChainId.toString() });
166
- }
167
- else {
168
- this.setActiveChain(viemChain);
169
- }
170
- }
171
- catch (error) {
172
- // we need to check for unrecognized chain error first because it also contains 'rejected' in message
173
- if (error.code === 4902 ||
174
- ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Unrecognized chain')) ||
175
- // https://github.com/MetaMask/metamask-mobile/issues/3312#issuecomment-1065923294
176
- ((_d = (_c = error.data) === null || _c === void 0 ? void 0 : _c.orginalError) === null || _d === void 0 ? void 0 : _d.code) === 4902) {
177
- // error code indicates the chain has not been added yet
178
- // https://docs.metamask.io/guide/rpc-api.html#usage-with-wallet-switchethereumchain
179
- return this.providerAddNetwork({ network, provider });
180
- }
181
- else if (((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('rejected')) ||
182
- (typeof error === 'string' && error.includes('rejected'))) {
183
- throw new utils.DynamicError("User rejected the wallet's request to switch network");
184
- }
185
- else {
186
- throw error;
187
- }
188
- }
189
- });
190
- }
191
- providerAddNetwork(_a) {
192
- return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
193
- var _b;
194
- try {
195
- return yield provider.addChain({ chain: ethereumCore.getOrMapViemChain(network) });
196
- }
197
- catch (error) {
198
- if (((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('rejected')) ||
199
- (typeof error === 'string' && error.includes('rejected'))) {
200
- throw new utils.DynamicError("User rejected the wallet's request to add network");
201
- }
202
- else {
203
- throw error;
204
- }
205
- }
206
- });
207
- }
208
- setActiveAccount(account) {
209
- this.activeAccount = account ? accounts.toAccount(account) : undefined;
210
- }
211
- getActiveAccount() {
212
- return this.activeAccount;
213
- }
214
- setActiveChain(chain) {
215
- this.activeChain = chain;
216
- }
217
- getActiveChain() {
218
- return this.activeChain;
219
- }
220
- createUiTransaction(from) {
221
- return _tslib.__awaiter(this, void 0, void 0, function* () {
222
- const walletClient = yield this.getWalletClient();
223
- const publicClient = yield this.getPublicClient();
224
- if (!publicClient || !walletClient) {
225
- throw new utils.DynamicError('No public client available');
226
- }
227
- return ethereumCore.createViemUiTransaction({
228
- from,
229
- publicClient,
230
- walletClient,
231
- });
232
- });
233
- }
234
- confirmTransactionStatus(txHash) {
235
- return _tslib.__awaiter(this, void 0, void 0, function* () {
236
- const publicClient = yield this.getPublicClient();
237
- if (!publicClient) {
238
- throw new utils.DynamicError('No public client available');
239
- }
240
- // The number of confirmations (blocks that have passed) to wait before resolving.
241
- const confirmations = 3;
242
- return publicClient.waitForTransactionReceipt({
243
- confirmations,
244
- hash: txHash,
245
- });
246
- });
247
- }
248
- }
249
-
250
- exports.EthWalletConnector = EthWalletConnector;