@dynamic-labs/ethereum 2.1.0-alpha.0 → 2.1.0-alpha.10

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 (56) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/_virtual/_tslib.cjs +1 -0
  3. package/_virtual/_tslib.js +1 -0
  4. package/package.json +10 -9
  5. package/src/EthWalletConnector.cjs +16 -26
  6. package/src/EthWalletConnector.d.ts +2785 -5
  7. package/src/EthWalletConnector.js +16 -26
  8. package/src/coinbase/coinbase.cjs +39 -72
  9. package/src/coinbase/coinbase.d.ts +2806 -291
  10. package/src/coinbase/coinbase.js +40 -73
  11. package/src/coinbase/helpers.cjs +29 -0
  12. package/src/coinbase/helpers.d.ts +3 -0
  13. package/src/coinbase/helpers.js +25 -0
  14. package/src/coinbase/types.d.ts +19 -0
  15. package/src/constants.cjs +1 -0
  16. package/src/constants.js +1 -0
  17. package/src/eip6963Provider.cjs +1 -0
  18. package/src/eip6963Provider.js +1 -0
  19. package/src/ethProviderHelper.cjs +1 -0
  20. package/src/ethProviderHelper.js +1 -0
  21. package/src/index.cjs +3 -0
  22. package/src/index.js +2 -0
  23. package/src/injected/ExodusEvm.cjs +1 -0
  24. package/src/injected/ExodusEvm.js +1 -0
  25. package/src/injected/InjectedWalletBase.cjs +5 -4
  26. package/src/injected/InjectedWalletBase.js +5 -4
  27. package/src/injected/PhantomEvm.cjs +1 -0
  28. package/src/injected/PhantomEvm.js +1 -0
  29. package/src/injected/Zerion.cjs +1 -0
  30. package/src/injected/Zerion.js +1 -0
  31. package/src/injected/fetchInjectedWalletConnectors.cjs +2 -1
  32. package/src/injected/fetchInjectedWalletConnectors.js +2 -1
  33. package/src/polyfills.cjs +1 -0
  34. package/src/polyfills.js +1 -0
  35. package/src/types.d.ts +1 -0
  36. package/src/utils/findEvmNetwork.cjs +1 -0
  37. package/src/utils/findEvmNetwork.d.ts +2 -2
  38. package/src/utils/findEvmNetwork.js +1 -0
  39. package/src/utils/getNameservice.cjs +46 -0
  40. package/src/utils/getNameservice.d.ts +6 -0
  41. package/src/utils/getNameservice.js +42 -0
  42. package/src/utils/index.d.ts +1 -0
  43. package/src/utils/isEthWalletConnector/isEthWalletConnector.cjs +1 -0
  44. package/src/utils/isEthWalletConnector/isEthWalletConnector.js +1 -0
  45. package/src/utils/parseIntSafe.cjs +1 -0
  46. package/src/utils/parseIntSafe.js +1 -0
  47. package/src/walletConnect/fetchWalletConnectWallets.cjs +1 -0
  48. package/src/walletConnect/fetchWalletConnectWallets.js +1 -0
  49. package/src/walletConnect/walletConnect.cjs +6 -5
  50. package/src/walletConnect/walletConnect.d.ts +6883 -17
  51. package/src/walletConnect/walletConnect.js +6 -5
  52. package/src/coinbase/client/client.cjs +0 -72
  53. package/src/coinbase/client/client.d.ts +0 -7
  54. package/src/coinbase/client/client.js +0 -65
  55. package/src/coinbase/client/index.d.ts +0 -2
  56. package/src/coinbase/client/types.d.ts +0 -17
@@ -1,3 +1,4 @@
1
+ 'use client'
1
2
  import { __awaiter } from '../../_virtual/_tslib.js';
2
3
  import EthereumProvider from '@walletconnect/ethereum-provider';
3
4
  import EventEmitter from 'eventemitter3';
@@ -241,8 +242,8 @@ class WalletConnect extends EthWalletConnector {
241
242
  });
242
243
  }
243
244
  getAddress(opts) {
244
- var _a, _b;
245
245
  return __awaiter(this, void 0, void 0, function* () {
246
+ var _a, _b;
246
247
  const activeAccount = this.getActiveAccount();
247
248
  if (activeAccount === null || activeAccount === void 0 ? void 0 : activeAccount.address) {
248
249
  return activeAccount.address;
@@ -404,8 +405,8 @@ class WalletConnect extends EthWalletConnector {
404
405
  this.session = session;
405
406
  }
406
407
  endSession() {
407
- var _a;
408
408
  return __awaiter(this, void 0, void 0, function* () {
409
+ var _a;
409
410
  this.clearActiveAccount();
410
411
  this.clearSession();
411
412
  this.hasSwitchedNetwork = false;
@@ -436,11 +437,11 @@ class WalletConnect extends EthWalletConnector {
436
437
  return _super.getNetwork.call(this);
437
438
  });
438
439
  }
439
- providerSwitchNetwork({ network, }) {
440
+ providerSwitchNetwork(_a) {
440
441
  const _super = Object.create(null, {
441
442
  providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
442
443
  });
443
- return __awaiter(this, void 0, void 0, function* () {
444
+ return __awaiter(this, arguments, void 0, function* ({ network, }) {
444
445
  const supportedNetworks = yield this.getSupportedNetworks();
445
446
  if (!(supportedNetworks === null || supportedNetworks === void 0 ? void 0 : supportedNetworks.includes(network.chainId.toString()))) {
446
447
  const error = new DynamicError('Network switching is not available at this time. The user should manually switch network in their wallet');
@@ -489,8 +490,8 @@ class WalletConnect extends EthWalletConnector {
489
490
  return ((_e = (_d = (_c = (_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.peer) === null || _b === void 0 ? void 0 : _b.metadata) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.toLowerCase().startsWith('metamask')) !== null && _e !== void 0 ? _e : false);
490
491
  }
491
492
  getSupportedNetworks() {
492
- var _a;
493
493
  return __awaiter(this, void 0, void 0, function* () {
494
+ var _a;
494
495
  yield this.initProvider();
495
496
  this.refreshSession();
496
497
  if (this.isMetaMask()) {
@@ -1,72 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('../../../_virtual/_tslib.cjs');
6
- var walletSdk = require('@coinbase/wallet-sdk');
7
- var viem = require('viem');
8
- var utils = require('@dynamic-labs/utils');
9
- var constants = require('../../constants.cjs');
10
-
11
- const jsonRpcUrl = `https://mainnet.infura.io/v3/${constants.INFURA_ID}`;
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
17
- let coinbaseProvider;
18
- const getCoinbaseClient = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
19
- var _a, _b;
20
- if (!coinbaseProvider) {
21
- coinbaseSdk = new walletSdk.CoinbaseWalletSDK({
22
- appLogoUrl,
23
- appName,
24
- enableMobileWalletLink: true,
25
- headlessMode: true,
26
- reloadOnDisconnect: false,
27
- });
28
- const network = evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.find((network) => network.chainId === chainId);
29
- const rpcUrl = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) ||
30
- ((_b = network === null || network === void 0 ? void 0 : network.rpcUrls) === null || _b === void 0 ? void 0 : _b[0]) ||
31
- jsonRpcUrl;
32
- coinbaseProvider = coinbaseSdk.makeWeb3Provider(rpcUrl, chainId);
33
- }
34
- return { provider: coinbaseProvider, sdk: coinbaseSdk };
35
- };
36
- const killCoinbaseSession = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
37
- yield (coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.close());
38
- });
39
- const getAddress = (coinbaseProviderOpts, opts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
40
- var _a;
41
- const { provider, sdk } = getCoinbaseClient({ opts: coinbaseProviderOpts });
42
- const qrUrl = sdk.getQrUrl();
43
- if (!qrUrl) {
44
- throw new utils.DynamicError('no qr url available');
45
- }
46
- (_a = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _a === void 0 ? void 0 : _a.call(opts, qrUrl);
47
- const [address] = yield provider.request({
48
- method: 'eth_requestAccounts',
49
- });
50
- return address;
51
- });
52
- const signMessage = (coinbaseProviderOpts, messageToSign) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
53
- const { provider } = getCoinbaseClient({ opts: coinbaseProviderOpts });
54
- const [address] = yield provider.request({
55
- method: 'eth_requestAccounts',
56
- });
57
- try {
58
- return yield provider.request({
59
- method: 'personal_sign',
60
- params: [viem.toHex(viem.toBytes(messageToSign)), address.toLowerCase()],
61
- });
62
- }
63
- catch (err) {
64
- yield provider.close();
65
- return undefined;
66
- }
67
- });
68
-
69
- exports.getAddress = getAddress;
70
- exports.getCoinbaseClient = getCoinbaseClient;
71
- exports.killCoinbaseSession = killCoinbaseSession;
72
- exports.signMessage = signMessage;
@@ -1,7 +0,0 @@
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;
5
- export declare const killCoinbaseSession: () => Promise<void>;
6
- export declare const getAddress: (coinbaseProviderOpts: GetCoinbaseProviderOpts, opts?: GetAddressOpts) => Promise<string | undefined>;
7
- export declare const signMessage: (coinbaseProviderOpts: GetCoinbaseProviderOpts, messageToSign: string) => Promise<string | undefined>;
@@ -1,65 +0,0 @@
1
- import { __awaiter } from '../../../_virtual/_tslib.js';
2
- import { CoinbaseWalletSDK } from '@coinbase/wallet-sdk';
3
- import { toHex, toBytes } from 'viem';
4
- import { DynamicError } from '@dynamic-labs/utils';
5
- import { INFURA_ID } from '../../constants.js';
6
-
7
- const jsonRpcUrl = `https://mainnet.infura.io/v3/${INFURA_ID}`;
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
13
- let coinbaseProvider;
14
- const getCoinbaseClient = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
15
- var _a, _b;
16
- if (!coinbaseProvider) {
17
- coinbaseSdk = new CoinbaseWalletSDK({
18
- appLogoUrl,
19
- appName,
20
- enableMobileWalletLink: true,
21
- headlessMode: true,
22
- reloadOnDisconnect: false,
23
- });
24
- const network = evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.find((network) => network.chainId === chainId);
25
- const rpcUrl = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) ||
26
- ((_b = network === null || network === void 0 ? void 0 : network.rpcUrls) === null || _b === void 0 ? void 0 : _b[0]) ||
27
- jsonRpcUrl;
28
- coinbaseProvider = coinbaseSdk.makeWeb3Provider(rpcUrl, chainId);
29
- }
30
- return { provider: coinbaseProvider, sdk: coinbaseSdk };
31
- };
32
- const killCoinbaseSession = () => __awaiter(void 0, void 0, void 0, function* () {
33
- yield (coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.close());
34
- });
35
- const getAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, void 0, void 0, function* () {
36
- var _a;
37
- const { provider, sdk } = getCoinbaseClient({ opts: coinbaseProviderOpts });
38
- const qrUrl = sdk.getQrUrl();
39
- if (!qrUrl) {
40
- throw new DynamicError('no qr url available');
41
- }
42
- (_a = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _a === void 0 ? void 0 : _a.call(opts, qrUrl);
43
- const [address] = yield provider.request({
44
- method: 'eth_requestAccounts',
45
- });
46
- return address;
47
- });
48
- const signMessage = (coinbaseProviderOpts, messageToSign) => __awaiter(void 0, void 0, void 0, function* () {
49
- const { provider } = getCoinbaseClient({ opts: coinbaseProviderOpts });
50
- const [address] = yield provider.request({
51
- method: 'eth_requestAccounts',
52
- });
53
- try {
54
- return yield provider.request({
55
- method: 'personal_sign',
56
- params: [toHex(toBytes(messageToSign)), address.toLowerCase()],
57
- });
58
- }
59
- catch (err) {
60
- yield provider.close();
61
- return undefined;
62
- }
63
- });
64
-
65
- export { getAddress, getCoinbaseClient, killCoinbaseSession, signMessage };
@@ -1,2 +0,0 @@
1
- export * from './client';
2
- export * from './types';
@@ -1,17 +0,0 @@
1
- import CoinbaseWalletSDK, { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
2
- import { GenericNetwork } from '@dynamic-labs/types';
3
- export type GetCoinbaseProviderOpts = {
4
- appLogoUrl?: string;
5
- appName?: string;
6
- evmNetworks?: GenericNetwork[];
7
- };
8
- export type CoinbaseProviderHandlerOpts = {
9
- onDisconnect(): Promise<void>;
10
- };
11
- export type GetCoinbaseClient = (args: {
12
- handlers?: CoinbaseProviderHandlerOpts;
13
- opts?: GetCoinbaseProviderOpts;
14
- }) => {
15
- provider: CoinbaseWalletProvider;
16
- sdk: CoinbaseWalletSDK;
17
- };