@dynamic-labs/ethereum 2.0.0-alpha.3 → 2.0.0-alpha.31

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 (53) hide show
  1. package/CHANGELOG.md +407 -0
  2. package/package.json +11 -12
  3. package/src/EthWalletConnector.cjs +13 -21
  4. package/src/EthWalletConnector.d.ts +16 -14
  5. package/src/EthWalletConnector.js +15 -23
  6. package/src/coinbase/client/client.cjs +14 -14
  7. package/src/coinbase/client/client.d.ts +5 -4
  8. package/src/coinbase/client/client.js +13 -13
  9. package/src/coinbase/client/types.d.ts +6 -3
  10. package/src/coinbase/coinbase.cjs +31 -15
  11. package/src/coinbase/coinbase.d.ts +20 -18
  12. package/src/coinbase/coinbase.js +32 -16
  13. package/src/ethProviderHelper.cjs +11 -6
  14. package/src/ethProviderHelper.d.ts +6 -4
  15. package/src/ethProviderHelper.js +11 -6
  16. package/src/index.cjs +9 -13
  17. package/src/index.d.ts +2 -0
  18. package/src/index.js +8 -13
  19. package/src/injected/ExodusEvm.cjs +1 -0
  20. package/src/injected/ExodusEvm.d.ts +1 -0
  21. package/src/injected/ExodusEvm.js +1 -0
  22. package/src/injected/InjectedWalletBase.cjs +28 -19
  23. package/src/injected/InjectedWalletBase.d.ts +2 -2
  24. package/src/injected/InjectedWalletBase.js +28 -19
  25. package/src/injected/PhantomEvm.cjs +4 -3
  26. package/src/injected/PhantomEvm.d.ts +2 -1
  27. package/src/injected/PhantomEvm.js +4 -3
  28. package/src/injected/Zerion.cjs +38 -0
  29. package/src/injected/Zerion.d.ts +10 -0
  30. package/src/injected/Zerion.js +34 -0
  31. package/src/injected/fetchInjectedWalletConnectors.cjs +25 -0
  32. package/src/injected/fetchInjectedWalletConnectors.d.ts +0 -1
  33. package/src/injected/fetchInjectedWalletConnectors.js +25 -0
  34. package/src/utils/index.d.ts +1 -0
  35. package/src/utils/isEthWalletConnector/index.d.ts +1 -0
  36. package/src/utils/isEthWalletConnector/isEthWalletConnector.cjs +7 -0
  37. package/src/utils/isEthWalletConnector/isEthWalletConnector.d.ts +3 -0
  38. package/src/utils/isEthWalletConnector/isEthWalletConnector.js +3 -0
  39. package/src/walletConnect/fetchWalletConnectWallets.cjs +14 -33
  40. package/src/walletConnect/fetchWalletConnectWallets.d.ts +2 -5
  41. package/src/walletConnect/fetchWalletConnectWallets.js +14 -33
  42. package/src/walletConnect/index.d.ts +0 -1
  43. package/src/walletConnect/walletConnect.cjs +452 -78
  44. package/src/walletConnect/walletConnect.d.ts +313 -31
  45. package/src/walletConnect/walletConnect.js +453 -80
  46. package/src/walletConnect/client/client.cjs +0 -201
  47. package/src/walletConnect/client/client.d.ts +0 -17
  48. package/src/walletConnect/client/client.js +0 -187
  49. package/src/walletConnect/client/index.d.ts +0 -1
  50. package/src/walletConnect/client/types.d.ts +0 -4
  51. package/src/walletConnect/walletConnectV2.cjs +0 -475
  52. package/src/walletConnect/walletConnectV2.d.ts +0 -333
  53. package/src/walletConnect/walletConnectV2.js +0 -466
@@ -1,8 +1,8 @@
1
1
  import { __awaiter } from '../_virtual/_tslib.js';
2
- import { createPublicClient, http, formatEther } from 'viem';
2
+ import { formatEther } from 'viem';
3
+ import { toAccount } from 'viem/accounts';
3
4
  import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
4
- import { parseEvmNetworks, getOrMapViemChain, retryableFn, FALLBACK_UNDEFINED, DynamicError } from '@dynamic-labs/utils';
5
- import { ProviderChain } from '@dynamic-labs/rpc-providers';
5
+ import { parseEvmNetworks, retryableFn, FALLBACK_UNDEFINED, DynamicError, getOrMapViemChain } from '@dynamic-labs/utils';
6
6
  import { findEvmNetwork } from './utils/findEvmNetwork.js';
7
7
 
8
8
  class EthWalletConnector extends WalletConnectorBase {
@@ -34,25 +34,7 @@ class EthWalletConnector extends WalletConnectorBase {
34
34
  }, {});
35
35
  this.evmNetworks = parseEvmNetworks(props.evmNetworks);
36
36
  this.chainRpcProviders = props.chainRpcProviders;
37
- (_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerChainProviders(ProviderChain.EVM, (config) => {
38
- const rpcProviders = {};
39
- if (config === null || config === void 0 ? void 0 : config.evm) {
40
- rpcProviders.evm = parseEvmNetworks(config.evm).map((network) => {
41
- var _a;
42
- const rpcUrl = ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
43
- const provider = createPublicClient({
44
- chain: getOrMapViemChain(network),
45
- transport: http(rpcUrl),
46
- });
47
- return {
48
- chainId: network.chainId,
49
- chainName: network.name,
50
- provider,
51
- };
52
- });
53
- }
54
- return rpcProviders.evm;
55
- });
37
+ (_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerEvmProviders();
56
38
  }
57
39
  getNetwork() {
58
40
  return __awaiter(this, void 0, void 0, function* () {
@@ -145,10 +127,14 @@ class EthWalletConnector extends WalletConnectorBase {
145
127
  const provider = this.getWalletClient();
146
128
  if (!provider)
147
129
  return [];
148
- return retryableFn(provider.getAddresses, {
130
+ const addresses = yield retryableFn(provider.getAddresses, {
149
131
  fallbackValue: [],
150
132
  timeoutMs: 300,
151
133
  });
134
+ if (addresses.length) {
135
+ this.setActiveAccount(addresses[0]);
136
+ }
137
+ return addresses;
152
138
  });
153
139
  }
154
140
  providerSwitchNetwork({ network, provider, }) {
@@ -202,6 +188,12 @@ class EthWalletConnector extends WalletConnectorBase {
202
188
  }
203
189
  });
204
190
  }
191
+ setActiveAccount(account) {
192
+ this.activeAccount = account ? toAccount(account) : undefined;
193
+ }
194
+ getActiveAccount() {
195
+ return this.activeAccount;
196
+ }
205
197
  }
206
198
 
207
199
  export { EthWalletConnector };
@@ -10,11 +10,15 @@ var constants = require('../../constants.cjs');
10
10
 
11
11
  const jsonRpcUrl = `https://mainnet.infura.io/v3/${constants.INFURA_ID}`;
12
12
  const chainId = 1;
13
+ // storing a reference to the coinbase sdk so that we can call getQrUrl on it when we need a fresh qr code
14
+ let coinbaseSdk;
15
+ // storing a reference to the coinbase provider because the provider methods work better when
16
+ // they are called on the same instance
13
17
  let coinbaseProvider;
14
- const getCoinbaseProvider = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
18
+ const getCoinbaseClient = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
15
19
  var _a, _b;
16
20
  if (!coinbaseProvider) {
17
- const coinbaseWalletSDK = new walletSdk.CoinbaseWalletSDK({
21
+ coinbaseSdk = new walletSdk.CoinbaseWalletSDK({
18
22
  appLogoUrl,
19
23
  appName,
20
24
  enableMobileWalletLink: true,
@@ -25,21 +29,17 @@ const getCoinbaseProvider = ({ opts: { appLogoUrl, appName = '', evmNetworks = [
25
29
  const rpcUrl = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) ||
26
30
  ((_b = network === null || network === void 0 ? void 0 : network.rpcUrls) === null || _b === void 0 ? void 0 : _b[0]) ||
27
31
  jsonRpcUrl;
28
- coinbaseProvider = coinbaseWalletSDK.makeWeb3Provider(rpcUrl, chainId);
32
+ coinbaseProvider = coinbaseSdk.makeWeb3Provider(rpcUrl, chainId);
29
33
  }
30
- return coinbaseProvider;
34
+ return { provider: coinbaseProvider, sdk: coinbaseSdk };
31
35
  };
32
36
  const killCoinbaseSession = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
33
37
  yield (coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.close());
34
- coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.disconnect();
35
- // We needed to remove the provider, because after a disconnect the initial settings that
36
- // were set in the SDK reset, and they need to be initialized again.
37
- coinbaseProvider = undefined;
38
38
  });
39
- const fetchPublicAddress = (coinbaseProviderOpts, opts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
39
+ const getAddress = (coinbaseProviderOpts, opts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
40
40
  var _a;
41
- const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
42
- const { qrUrl } = provider;
41
+ const { provider, sdk } = getCoinbaseClient({ opts: coinbaseProviderOpts });
42
+ const qrUrl = sdk.getQrUrl();
43
43
  if (!qrUrl) {
44
44
  throw new utils.DynamicError('no qr url available');
45
45
  }
@@ -50,7 +50,7 @@ const fetchPublicAddress = (coinbaseProviderOpts, opts) => _tslib.__awaiter(void
50
50
  return address;
51
51
  });
52
52
  const signMessage = (coinbaseProviderOpts, messageToSign) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
53
- const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
53
+ const { provider } = getCoinbaseClient({ opts: coinbaseProviderOpts });
54
54
  const [address] = yield provider.request({
55
55
  method: 'eth_requestAccounts',
56
56
  });
@@ -66,7 +66,7 @@ const signMessage = (coinbaseProviderOpts, messageToSign) => _tslib.__awaiter(vo
66
66
  }
67
67
  });
68
68
 
69
- exports.fetchPublicAddress = fetchPublicAddress;
70
- exports.getCoinbaseProvider = getCoinbaseProvider;
69
+ exports.getAddress = getAddress;
70
+ exports.getCoinbaseClient = getCoinbaseClient;
71
71
  exports.killCoinbaseSession = killCoinbaseSession;
72
72
  exports.signMessage = signMessage;
@@ -1,6 +1,7 @@
1
- import { FetchPublicAddressOpts } from '@dynamic-labs/wallet-connector-core';
2
- import { GetCoinbaseProvider, GetCoinbaseProviderOpts } from './types';
3
- export declare const getCoinbaseProvider: GetCoinbaseProvider;
1
+ import { GetAddressOpts } from '@dynamic-labs/wallet-connector-core';
2
+ import { GetCoinbaseClient, GetCoinbaseProviderOpts } from './types';
3
+ export declare const clearClientVariables: () => void;
4
+ export declare const getCoinbaseClient: GetCoinbaseClient;
4
5
  export declare const killCoinbaseSession: () => Promise<void>;
5
- export declare const fetchPublicAddress: (coinbaseProviderOpts: GetCoinbaseProviderOpts, opts?: FetchPublicAddressOpts) => Promise<string | undefined>;
6
+ export declare const getAddress: (coinbaseProviderOpts: GetCoinbaseProviderOpts, opts?: GetAddressOpts) => Promise<string | undefined>;
6
7
  export declare const signMessage: (coinbaseProviderOpts: GetCoinbaseProviderOpts, messageToSign: string) => Promise<string | undefined>;
@@ -6,11 +6,15 @@ import { INFURA_ID } from '../../constants.js';
6
6
 
7
7
  const jsonRpcUrl = `https://mainnet.infura.io/v3/${INFURA_ID}`;
8
8
  const chainId = 1;
9
+ // storing a reference to the coinbase sdk so that we can call getQrUrl on it when we need a fresh qr code
10
+ let coinbaseSdk;
11
+ // storing a reference to the coinbase provider because the provider methods work better when
12
+ // they are called on the same instance
9
13
  let coinbaseProvider;
10
- const getCoinbaseProvider = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
14
+ const getCoinbaseClient = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
11
15
  var _a, _b;
12
16
  if (!coinbaseProvider) {
13
- const coinbaseWalletSDK = new CoinbaseWalletSDK({
17
+ coinbaseSdk = new CoinbaseWalletSDK({
14
18
  appLogoUrl,
15
19
  appName,
16
20
  enableMobileWalletLink: true,
@@ -21,21 +25,17 @@ const getCoinbaseProvider = ({ opts: { appLogoUrl, appName = '', evmNetworks = [
21
25
  const rpcUrl = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) ||
22
26
  ((_b = network === null || network === void 0 ? void 0 : network.rpcUrls) === null || _b === void 0 ? void 0 : _b[0]) ||
23
27
  jsonRpcUrl;
24
- coinbaseProvider = coinbaseWalletSDK.makeWeb3Provider(rpcUrl, chainId);
28
+ coinbaseProvider = coinbaseSdk.makeWeb3Provider(rpcUrl, chainId);
25
29
  }
26
- return coinbaseProvider;
30
+ return { provider: coinbaseProvider, sdk: coinbaseSdk };
27
31
  };
28
32
  const killCoinbaseSession = () => __awaiter(void 0, void 0, void 0, function* () {
29
33
  yield (coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.close());
30
- coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.disconnect();
31
- // We needed to remove the provider, because after a disconnect the initial settings that
32
- // were set in the SDK reset, and they need to be initialized again.
33
- coinbaseProvider = undefined;
34
34
  });
35
- const fetchPublicAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, void 0, void 0, function* () {
35
+ const getAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, void 0, void 0, function* () {
36
36
  var _a;
37
- const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
38
- const { qrUrl } = provider;
37
+ const { provider, sdk } = getCoinbaseClient({ opts: coinbaseProviderOpts });
38
+ const qrUrl = sdk.getQrUrl();
39
39
  if (!qrUrl) {
40
40
  throw new DynamicError('no qr url available');
41
41
  }
@@ -46,7 +46,7 @@ const fetchPublicAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, voi
46
46
  return address;
47
47
  });
48
48
  const signMessage = (coinbaseProviderOpts, messageToSign) => __awaiter(void 0, void 0, void 0, function* () {
49
- const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
49
+ const { provider } = getCoinbaseClient({ opts: coinbaseProviderOpts });
50
50
  const [address] = yield provider.request({
51
51
  method: 'eth_requestAccounts',
52
52
  });
@@ -62,4 +62,4 @@ const signMessage = (coinbaseProviderOpts, messageToSign) => __awaiter(void 0, v
62
62
  }
63
63
  });
64
64
 
65
- export { fetchPublicAddress, getCoinbaseProvider, killCoinbaseSession, signMessage };
65
+ export { getAddress, getCoinbaseClient, killCoinbaseSession, signMessage };
@@ -1,4 +1,4 @@
1
- import { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
1
+ import CoinbaseWalletSDK, { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
2
2
  import { GenericNetwork } from '@dynamic-labs/types';
3
3
  export type GetCoinbaseProviderOpts = {
4
4
  appLogoUrl?: string;
@@ -8,7 +8,10 @@ export type GetCoinbaseProviderOpts = {
8
8
  export type CoinbaseProviderHandlerOpts = {
9
9
  onDisconnect(): Promise<void>;
10
10
  };
11
- export type GetCoinbaseProvider = (args: {
11
+ export type GetCoinbaseClient = (args: {
12
12
  handlers?: CoinbaseProviderHandlerOpts;
13
13
  opts?: GetCoinbaseProviderOpts;
14
- }) => CoinbaseWalletProvider;
14
+ }) => {
15
+ provider: CoinbaseWalletProvider;
16
+ sdk: CoinbaseWalletSDK;
17
+ };
@@ -5,15 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _tslib = require('../../_virtual/_tslib.cjs');
6
6
  var viem = require('viem');
7
7
  var walletBook = require('@dynamic-labs/wallet-book');
8
- require('../polyfills.cjs');
9
- require('@dynamic-labs/turnkey');
10
- require('@dynamic-labs/utils');
8
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
11
9
  var ethProviderHelper = require('../ethProviderHelper.cjs');
12
10
  var EthWalletConnector = require('../EthWalletConnector.cjs');
13
- require('../walletConnect/walletConnectV2.cjs');
14
- require('@walletconnect/ethereum-provider');
15
- require('@dynamic-labs/wallet-connector-core');
16
- require('@walletconnect/client');
17
11
  var client = require('./client/client.cjs');
18
12
 
19
13
  class Coinbase extends EthWalletConnector.EthWalletConnector {
@@ -21,6 +15,7 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
21
15
  var { appName, appLogoUrl, evmNetworks } = _a, props = _tslib.__rest(_a, ["appName", "appLogoUrl", "evmNetworks"]);
22
16
  super(Object.assign({ evmNetworks }, props));
23
17
  this.name = 'Coinbase';
18
+ this.overrideKey = 'coinbase';
24
19
  this.supportedChains = ['EVM', 'ETH'];
25
20
  this.connectedChain = 'EVM';
26
21
  this.canConnectViaQrCode = true;
@@ -32,10 +27,14 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
32
27
  const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
33
28
  if (!wallet)
34
29
  return;
35
- this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(wallet);
30
+ this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(wallet, this);
36
31
  }
37
32
  setupEventListeners() {
38
33
  var _a, _b, _c;
34
+ if (!this.isInstalledOnBrowser()) {
35
+ this.setupCoinbaseProviderEventListeners();
36
+ return;
37
+ }
39
38
  const provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider();
40
39
  if (!provider) {
41
40
  return;
@@ -45,28 +44,28 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
45
44
  return;
46
45
  this.teardownEventListeners = setupResponse.tearDownEventListeners;
47
46
  }
48
- getWalletClient() {
47
+ getWalletClient(chainId) {
49
48
  var _a;
50
49
  if (this.isInstalledOnBrowser()) {
51
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient();
50
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
52
51
  }
53
52
  return viem.createWalletClient({
54
- transport: viem.custom(client.getCoinbaseProvider({
53
+ transport: viem.custom(client.getCoinbaseClient({
55
54
  opts: this.coinbaseProviderOpts,
56
- })),
55
+ }).provider),
57
56
  });
58
57
  }
59
58
  isInstalledOnBrowser() {
60
59
  var _a;
61
60
  return ((_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
62
61
  }
63
- fetchPublicAddress(opts) {
62
+ getAddress(opts) {
64
63
  var _a;
65
64
  return _tslib.__awaiter(this, void 0, void 0, function* () {
66
65
  if (this.isInstalledOnBrowser()) {
67
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress();
66
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.getAddress();
68
67
  }
69
- return client.fetchPublicAddress(this.coinbaseProviderOpts, opts);
68
+ return client.getAddress(this.coinbaseProviderOpts, opts);
70
69
  });
71
70
  }
72
71
  signMessage(messageToSign) {
@@ -85,6 +84,23 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
85
84
  client.killCoinbaseSession();
86
85
  });
87
86
  }
87
+ setupCoinbaseProviderEventListeners() {
88
+ const { provider } = client.getCoinbaseClient({
89
+ opts: this.coinbaseProviderOpts,
90
+ });
91
+ if (!provider) {
92
+ return;
93
+ }
94
+ const { handleAccountChange, handleChainChange, handleDisconnect } = walletConnectorCore.eventListenerHandlers(this);
95
+ provider.on('accountsChanged', handleAccountChange);
96
+ provider.on('chainChanged', handleChainChange);
97
+ provider.on('disconnect', handleDisconnect);
98
+ this.teardownEventListeners = () => {
99
+ provider.removeListener('accountsChanged', handleAccountChange);
100
+ provider.removeListener('chainChanged', handleChainChange);
101
+ provider.removeListener('disconnect', handleDisconnect);
102
+ };
103
+ }
88
104
  }
89
105
 
90
106
  exports.Coinbase = Coinbase;
@@ -1,5 +1,5 @@
1
- import { Chain, FetchPublicAddressOpts } from '@dynamic-labs/wallet-connector-core';
2
- import { EthProviderHelper } from '..';
1
+ import { Chain, GetAddressOpts } from '@dynamic-labs/wallet-connector-core';
2
+ import { EthProviderHelper } from '../ethProviderHelper';
3
3
  import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
4
4
  type CoinbaseOpts = EthWalletConnectorOpts & {
5
5
  appLogoUrl?: string;
@@ -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;
@@ -14,7 +15,7 @@ export declare class Coinbase extends EthWalletConnector {
14
15
  ethProviderHelper: EthProviderHelper | undefined;
15
16
  constructor({ appName, appLogoUrl, evmNetworks, ...props }: CoinbaseOpts);
16
17
  setupEventListeners(): void;
17
- getWalletClient(): {
18
+ getWalletClient(chainId?: string): {
18
19
  account: import("viem").Account | undefined;
19
20
  batch?: {
20
21
  multicall?: boolean | {
@@ -32,20 +33,20 @@ export declare class Coinbase extends EthWalletConnector {
32
33
  type: string;
33
34
  uid: string;
34
35
  addChain: (args: import("viem").AddChainParameters) => Promise<void>;
35
- deployContract: <const TAbi extends import("viem").Abi | readonly unknown[], TChainOverride extends import("viem").Chain | undefined = undefined>(args: import("viem").DeployContractParameters<TAbi, import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride>) => Promise<`0x${string}`>;
36
+ deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<abi, import("viem").Chain | undefined, import("viem").Account | undefined, chainOverride>) => Promise<`0x${string}`>;
36
37
  getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
37
38
  getChainId: () => Promise<number>;
38
39
  getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
39
- prepareTransactionRequest: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_1>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
40
+ prepareTransactionRequest: <TParameterType extends import("viem").PrepareTransactionRequestParameterType, TChainOverride extends import("viem").Chain | undefined = undefined, TAccountOverride extends `0x${string}` | import("viem").Account | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride, TAccountOverride, TParameterType>) => Promise<import("viem").PrepareTransactionRequestReturnType<import("viem").Chain, import("viem").Account | undefined, TChainOverride, TAccountOverride, TParameterType>>;
40
41
  requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
41
42
  requestPermissions: (args: {
42
43
  [x: string]: Record<string, any>;
43
44
  eth_accounts: Record<string, any>;
44
45
  }) => Promise<import("viem").RequestPermissionsReturnType>;
45
- sendRawTransaction: (args: import("node_modules/viem/_types/actions/wallet/sendRawTransaction").SendRawTransactionParameters) => Promise<`0x${string}`>;
46
- sendTransaction: <TChainOverride_2 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
46
+ sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<`0x${string}`>;
47
+ sendTransaction: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_1>) => Promise<`0x${string}`>;
47
48
  signMessage: (args: import("viem").SignMessageParameters<import("viem").Account | undefined>) => Promise<`0x${string}`>;
48
- signTransaction: <TChainOverride_3 extends import("viem").Chain | undefined = undefined>(args: import("node_modules/viem/_types/actions/wallet/signTransaction").SignTransactionParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
49
+ signTransaction: <TChainOverride_2 extends import("viem").Chain | undefined>(args: import("viem").SignTransactionParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
49
50
  signTypedData: <const TTypedData extends {
50
51
  [x: string]: readonly import("viem").TypedDataParameter[];
51
52
  [x: `string[${string}]`]: undefined;
@@ -256,7 +257,7 @@ export declare class Coinbase extends EthWalletConnector {
256
257
  }, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, import("viem").Account | undefined>) => Promise<`0x${string}`>;
257
258
  switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
258
259
  watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
259
- writeContract: <const TAbi_1 extends import("viem").Abi | readonly unknown[], TFunctionName extends string, TChainOverride_4 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<TAbi_1, TFunctionName, import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_4>) => Promise<`0x${string}`>;
260
+ writeContract: <const abi_1 extends import("viem").Abi | readonly unknown[], functionName extends import("viem").ContractFunctionName<abi_1, "nonpayable" | "payable">, args extends import("viem").ContractFunctionArgs<abi_1, "pure" | "view", functionName>, TChainOverride_3 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<abi_1, functionName, args, import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
260
261
  extend: <const client extends {
261
262
  [x: string]: unknown;
262
263
  account?: undefined;
@@ -270,7 +271,7 @@ export declare class Coinbase extends EthWalletConnector {
270
271
  transport?: undefined;
271
272
  type?: undefined;
272
273
  uid?: undefined;
273
- } & Partial<Pick<import("viem").PublicActions, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>>) => client) => import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>>;
274
+ } & Partial<Pick<import("viem").PublicActions<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined>, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>>) => client) => import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>>;
274
275
  } | {
275
276
  account: undefined;
276
277
  batch?: {
@@ -289,20 +290,20 @@ export declare class Coinbase extends EthWalletConnector {
289
290
  type: string;
290
291
  uid: string;
291
292
  addChain: (args: import("viem").AddChainParameters) => Promise<void>;
292
- deployContract: <const TAbi_2 extends import("viem").Abi | readonly unknown[], TChainOverride_5 extends import("viem").Chain | undefined = undefined>(args: import("viem").DeployContractParameters<TAbi_2, undefined, undefined, TChainOverride_5>) => Promise<`0x${string}`>;
293
+ deployContract: <const abi_2 extends import("viem").Abi | readonly unknown[], chainOverride_1 extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<abi_2, undefined, undefined, chainOverride_1>) => Promise<`0x${string}`>;
293
294
  getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
294
295
  getChainId: () => Promise<number>;
295
296
  getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
296
- prepareTransactionRequest: <TChainOverride_6 extends import("viem").Chain | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<undefined, undefined, TChainOverride_6>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
297
+ prepareTransactionRequest: <TParameterType_1 extends import("viem").PrepareTransactionRequestParameterType, TChainOverride_4 extends import("viem").Chain | undefined = undefined, TAccountOverride_1 extends `0x${string}` | import("viem").Account | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<undefined, undefined, TChainOverride_4, TAccountOverride_1, TParameterType_1>) => Promise<import("viem").PrepareTransactionRequestReturnType<import("viem").Chain, undefined, TChainOverride_4, TAccountOverride_1, TParameterType_1>>;
297
298
  requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
298
299
  requestPermissions: (args: {
299
300
  [x: string]: Record<string, any>;
300
301
  eth_accounts: Record<string, any>;
301
302
  }) => Promise<import("viem").RequestPermissionsReturnType>;
302
- sendRawTransaction: (args: import("node_modules/viem/_types/actions/wallet/sendRawTransaction").SendRawTransactionParameters) => Promise<`0x${string}`>;
303
- sendTransaction: <TChainOverride_7 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<undefined, undefined, TChainOverride_7>) => Promise<`0x${string}`>;
303
+ sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<`0x${string}`>;
304
+ sendTransaction: <TChainOverride_5 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<undefined, undefined, TChainOverride_5>) => Promise<`0x${string}`>;
304
305
  signMessage: (args: import("viem").SignMessageParameters<undefined>) => Promise<`0x${string}`>;
305
- signTransaction: <TChainOverride_8 extends import("viem").Chain | undefined = undefined>(args: import("node_modules/viem/_types/actions/wallet/signTransaction").SignTransactionParameters<undefined, undefined, TChainOverride_8>) => Promise<`0x${string}`>;
306
+ signTransaction: <TChainOverride_6 extends import("viem").Chain | undefined>(args: import("viem").SignTransactionParameters<undefined, undefined, TChainOverride_6>) => Promise<`0x${string}`>;
306
307
  signTypedData: <const TTypedData_1 extends {
307
308
  [x: string]: readonly import("viem").TypedDataParameter[];
308
309
  [x: `string[${string}]`]: undefined;
@@ -513,7 +514,7 @@ export declare class Coinbase extends EthWalletConnector {
513
514
  }, TPrimaryType_1 extends string>(args: import("viem").SignTypedDataParameters<TTypedData_1, TPrimaryType_1, undefined>) => Promise<`0x${string}`>;
514
515
  switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
515
516
  watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
516
- writeContract: <const TAbi_3 extends import("viem").Abi | readonly unknown[], TFunctionName_1 extends string, TChainOverride_9 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<TAbi_3, TFunctionName_1, undefined, undefined, TChainOverride_9>) => Promise<`0x${string}`>;
517
+ writeContract: <const abi_3 extends import("viem").Abi | readonly unknown[], functionName_1 extends import("viem").ContractFunctionName<abi_3, "nonpayable" | "payable">, args_1 extends import("viem").ContractFunctionArgs<abi_3, "pure" | "view", functionName_1>, TChainOverride_7 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<abi_3, functionName_1, args_1, undefined, undefined, TChainOverride_7>) => Promise<`0x${string}`>;
517
518
  extend: <const client_1 extends {
518
519
  [x: string]: unknown;
519
520
  account?: undefined;
@@ -527,11 +528,12 @@ export declare class Coinbase extends EthWalletConnector {
527
528
  transport?: undefined;
528
529
  type?: undefined;
529
530
  uid?: undefined;
530
- } & Partial<Pick<import("viem").PublicActions, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<undefined, undefined>>) => client_1) => import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, { [K_1 in keyof client_1]: client_1[K_1]; } & import("viem").WalletActions<undefined, undefined>>;
531
+ } & Partial<Pick<import("viem").PublicActions<import("viem").CustomTransport, undefined, undefined>, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<undefined, undefined>>) => client_1) => import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, { [K_1 in keyof client_1]: client_1[K_1]; } & import("viem").WalletActions<undefined, undefined>>;
531
532
  } | undefined;
532
533
  isInstalledOnBrowser(): boolean;
533
- fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
534
+ getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
534
535
  signMessage(messageToSign: string): Promise<string | undefined>;
535
536
  endSession(): Promise<void>;
537
+ private setupCoinbaseProviderEventListeners;
536
538
  }
537
539
  export {};
@@ -1,22 +1,17 @@
1
1
  import { __rest, __awaiter } from '../../_virtual/_tslib.js';
2
2
  import { createWalletClient, custom } from 'viem';
3
3
  import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
4
- import '../polyfills.js';
5
- import '@dynamic-labs/turnkey';
6
- import '@dynamic-labs/utils';
4
+ import { eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
7
5
  import { EthProviderHelper } from '../ethProviderHelper.js';
8
6
  import { EthWalletConnector } from '../EthWalletConnector.js';
9
- import '../walletConnect/walletConnectV2.js';
10
- import '@walletconnect/ethereum-provider';
11
- import '@dynamic-labs/wallet-connector-core';
12
- import '@walletconnect/client';
13
- import { getCoinbaseProvider, fetchPublicAddress, signMessage, killCoinbaseSession } from './client/client.js';
7
+ import { getCoinbaseClient, getAddress, signMessage, killCoinbaseSession } from './client/client.js';
14
8
 
15
9
  class Coinbase extends EthWalletConnector {
16
10
  constructor(_a) {
17
11
  var { appName, appLogoUrl, evmNetworks } = _a, props = __rest(_a, ["appName", "appLogoUrl", "evmNetworks"]);
18
12
  super(Object.assign({ evmNetworks }, props));
19
13
  this.name = 'Coinbase';
14
+ this.overrideKey = 'coinbase';
20
15
  this.supportedChains = ['EVM', 'ETH'];
21
16
  this.connectedChain = 'EVM';
22
17
  this.canConnectViaQrCode = true;
@@ -28,10 +23,14 @@ class Coinbase extends EthWalletConnector {
28
23
  const wallet = findWalletBookWallet(this.walletBook, this.key);
29
24
  if (!wallet)
30
25
  return;
31
- this.ethProviderHelper = new EthProviderHelper(wallet);
26
+ this.ethProviderHelper = new EthProviderHelper(wallet, this);
32
27
  }
33
28
  setupEventListeners() {
34
29
  var _a, _b, _c;
30
+ if (!this.isInstalledOnBrowser()) {
31
+ this.setupCoinbaseProviderEventListeners();
32
+ return;
33
+ }
35
34
  const provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider();
36
35
  if (!provider) {
37
36
  return;
@@ -41,28 +40,28 @@ class Coinbase extends EthWalletConnector {
41
40
  return;
42
41
  this.teardownEventListeners = setupResponse.tearDownEventListeners;
43
42
  }
44
- getWalletClient() {
43
+ getWalletClient(chainId) {
45
44
  var _a;
46
45
  if (this.isInstalledOnBrowser()) {
47
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient();
46
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
48
47
  }
49
48
  return createWalletClient({
50
- transport: custom(getCoinbaseProvider({
49
+ transport: custom(getCoinbaseClient({
51
50
  opts: this.coinbaseProviderOpts,
52
- })),
51
+ }).provider),
53
52
  });
54
53
  }
55
54
  isInstalledOnBrowser() {
56
55
  var _a;
57
56
  return ((_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
58
57
  }
59
- fetchPublicAddress(opts) {
58
+ getAddress(opts) {
60
59
  var _a;
61
60
  return __awaiter(this, void 0, void 0, function* () {
62
61
  if (this.isInstalledOnBrowser()) {
63
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress();
62
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.getAddress();
64
63
  }
65
- return fetchPublicAddress(this.coinbaseProviderOpts, opts);
64
+ return getAddress(this.coinbaseProviderOpts, opts);
66
65
  });
67
66
  }
68
67
  signMessage(messageToSign) {
@@ -81,6 +80,23 @@ class Coinbase extends EthWalletConnector {
81
80
  killCoinbaseSession();
82
81
  });
83
82
  }
83
+ setupCoinbaseProviderEventListeners() {
84
+ const { provider } = getCoinbaseClient({
85
+ opts: this.coinbaseProviderOpts,
86
+ });
87
+ if (!provider) {
88
+ return;
89
+ }
90
+ const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers(this);
91
+ provider.on('accountsChanged', handleAccountChange);
92
+ provider.on('chainChanged', handleChainChange);
93
+ provider.on('disconnect', handleDisconnect);
94
+ this.teardownEventListeners = () => {
95
+ provider.removeListener('accountsChanged', handleAccountChange);
96
+ provider.removeListener('chainChanged', handleChainChange);
97
+ provider.removeListener('disconnect', handleDisconnect);
98
+ };
99
+ }
84
100
  }
85
101
 
86
102
  export { Coinbase };
@@ -6,11 +6,13 @@ var _tslib = require('../_virtual/_tslib.cjs');
6
6
  var viem = require('viem');
7
7
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
8
  var utils = require('@dynamic-labs/utils');
9
+ var viemUtils = require('@dynamic-labs/viem-utils');
9
10
  var eip6963Provider = require('./eip6963Provider.cjs');
10
11
 
11
12
  class EthProviderHelper {
12
- constructor(wallet) {
13
+ constructor(wallet, connector) {
13
14
  this.wallet = wallet;
15
+ this.connector = connector;
14
16
  }
15
17
  getInstalledProvider() {
16
18
  const eip6963Config = this.getEip6963Config();
@@ -75,29 +77,32 @@ class EthProviderHelper {
75
77
  findProvider() {
76
78
  return this.getInstalledProvider();
77
79
  }
78
- findWalletClient() {
80
+ findWalletClient(chainId) {
79
81
  const provider = this.findProvider();
80
82
  if (!provider) {
81
83
  return undefined;
82
84
  }
83
85
  return viem.createWalletClient({
86
+ account: this.connector.getActiveAccount(),
87
+ chain: chainId ? viemUtils.chainsMap[chainId] : undefined,
84
88
  transport: viem.custom(provider),
85
89
  });
86
90
  }
87
- fetchPublicAddress() {
91
+ getAddress() {
88
92
  return _tslib.__awaiter(this, void 0, void 0, function* () {
89
93
  const client = this.findWalletClient();
90
94
  if (!client) {
91
95
  return Promise.resolve(undefined);
92
96
  }
93
- return this.fetchPublicAddressWithProvider(client);
97
+ return this.getAddressWithProvider(client);
94
98
  });
95
99
  }
96
- fetchPublicAddressWithProvider(client) {
100
+ getAddressWithProvider(client) {
97
101
  return _tslib.__awaiter(this, void 0, void 0, function* () {
98
102
  try {
99
103
  const [lowercaseAddress] = yield client.requestAddresses();
100
104
  const publicAddress = viem.getAddress(lowercaseAddress);
105
+ this.connector.setActiveAccount(publicAddress);
101
106
  return publicAddress;
102
107
  }
103
108
  catch (err) {
@@ -108,7 +113,7 @@ class EthProviderHelper {
108
113
  }
109
114
  signMessage(messageToSign) {
110
115
  return _tslib.__awaiter(this, void 0, void 0, function* () {
111
- const walletAddress = yield this.fetchPublicAddress();
116
+ const walletAddress = yield this.getAddress();
112
117
  if (!walletAddress) {
113
118
  return Promise.resolve(undefined);
114
119
  }