@dynamic-labs/ethereum 0.19.0-alpha.8 → 0.19.0

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 (118) hide show
  1. package/CHANGELOG.md +321 -0
  2. package/package.json +13 -10
  3. package/src/EthWalletConnector.cjs +189 -193
  4. package/src/EthWalletConnector.d.ts +298 -41
  5. package/src/EthWalletConnector.js +190 -194
  6. package/src/coinbase/client/client.cjs +78 -0
  7. package/src/coinbase/client/client.d.ts +6 -0
  8. package/src/coinbase/client/client.js +71 -0
  9. package/src/coinbase/client/index.d.ts +2 -0
  10. package/src/coinbase/client/types.d.ts +14 -0
  11. package/src/coinbase/coinbase.cjs +71 -0
  12. package/src/coinbase/coinbase.d.ts +535 -0
  13. package/src/coinbase/coinbase.js +67 -0
  14. package/src/coinbase/index.d.ts +3 -0
  15. package/src/constants.d.ts +1 -1
  16. package/src/ethProviderHelper.cjs +132 -208
  17. package/src/ethProviderHelper.d.ts +28 -36
  18. package/src/ethProviderHelper.js +133 -209
  19. package/src/index.cjs +30 -26
  20. package/src/index.d.ts +9 -8
  21. package/src/index.js +25 -20
  22. package/src/injected/BloctoInjected.cjs +6 -6
  23. package/src/injected/BloctoInjected.d.ts +4 -4
  24. package/src/injected/BloctoInjected.js +6 -6
  25. package/src/injected/BraveEvm.cjs +6 -6
  26. package/src/injected/BraveEvm.d.ts +4 -4
  27. package/src/injected/BraveEvm.js +6 -6
  28. package/src/injected/Dawn.cjs +6 -6
  29. package/src/injected/Dawn.d.ts +4 -4
  30. package/src/injected/Dawn.js +6 -6
  31. package/src/injected/ExodusEvm.cjs +8 -8
  32. package/src/injected/ExodusEvm.d.ts +5 -5
  33. package/src/injected/ExodusEvm.js +7 -7
  34. package/src/injected/Frame.cjs +6 -6
  35. package/src/injected/Frame.d.ts +4 -4
  36. package/src/injected/Frame.js +6 -6
  37. package/src/injected/GameStop.cjs +6 -6
  38. package/src/injected/GameStop.d.ts +4 -4
  39. package/src/injected/GameStop.js +6 -6
  40. package/src/injected/InjectedWalletBase.cjs +86 -65
  41. package/src/injected/InjectedWalletBase.d.ts +29 -24
  42. package/src/injected/InjectedWalletBase.js +86 -65
  43. package/src/injected/LegacyInjectedWalletBase.cjs +83 -0
  44. package/src/injected/LegacyInjectedWalletBase.d.ts +24 -0
  45. package/src/injected/LegacyInjectedWalletBase.js +81 -0
  46. package/src/injected/Opera.cjs +6 -6
  47. package/src/injected/Opera.d.ts +4 -4
  48. package/src/injected/Opera.js +6 -6
  49. package/src/injected/PhantomEvm.cjs +28 -28
  50. package/src/injected/PhantomEvm.d.ts +5 -5
  51. package/src/injected/PhantomEvm.js +28 -28
  52. package/src/injected/Rabby.cjs +8 -8
  53. package/src/injected/Rabby.d.ts +5 -5
  54. package/src/injected/Rabby.js +7 -7
  55. package/src/injected/Superb.cjs +6 -6
  56. package/src/injected/Superb.d.ts +4 -4
  57. package/src/injected/Superb.js +6 -6
  58. package/src/injected/Trust.cjs +8 -8
  59. package/src/injected/Trust.d.ts +5 -5
  60. package/src/injected/Trust.js +7 -7
  61. package/src/injected/Zerion.cjs +8 -8
  62. package/src/injected/Zerion.d.ts +5 -5
  63. package/src/injected/Zerion.js +7 -7
  64. package/src/injected/fetchInjectedWalletConnectors.cjs +33 -0
  65. package/src/injected/fetchInjectedWalletConnectors.d.ts +6 -0
  66. package/src/injected/fetchInjectedWalletConnectors.js +29 -0
  67. package/src/injected/index.d.ts +13 -16
  68. package/src/injected/legacyInjectedWallets.cjs +48 -0
  69. package/src/injected/legacyInjectedWallets.d.ts +3 -0
  70. package/src/injected/legacyInjectedWallets.js +43 -0
  71. package/src/legacyEthProviderHelper.cjs +187 -0
  72. package/src/legacyEthProviderHelper.d.ts +34 -0
  73. package/src/legacyEthProviderHelper.js +183 -0
  74. package/src/polyfills.cjs +11 -11
  75. package/src/polyfills.d.ts +1 -1
  76. package/src/polyfills.js +11 -11
  77. package/src/types.d.ts +37 -24
  78. package/src/utils/eventListenerHandlers.cjs +34 -0
  79. package/src/utils/eventListenerHandlers.d.ts +8 -0
  80. package/src/utils/eventListenerHandlers.js +30 -0
  81. package/src/utils/findEvmNetwork.cjs +13 -13
  82. package/src/utils/findEvmNetwork.d.ts +6 -6
  83. package/src/utils/findEvmNetwork.js +13 -13
  84. package/src/utils/isString.d.ts +1 -1
  85. package/src/utils/isUnsupportedProviderError/index.d.ts +1 -1
  86. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.cjs +6 -6
  87. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +6 -6
  88. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.js +6 -6
  89. package/src/utils/last.d.ts +1 -1
  90. package/src/utils/parseIntSafe.cjs +13 -13
  91. package/src/utils/parseIntSafe.d.ts +1 -1
  92. package/src/utils/parseIntSafe.js +13 -13
  93. package/src/walletConnect/client/client.cjs +179 -175
  94. package/src/walletConnect/client/client.d.ts +17 -17
  95. package/src/walletConnect/client/client.js +179 -175
  96. package/src/walletConnect/client/index.d.ts +1 -1
  97. package/src/walletConnect/client/types.d.ts +4 -4
  98. package/src/walletConnect/fetchWalletConnectWallets.cjs +37 -52
  99. package/src/walletConnect/fetchWalletConnectWallets.d.ts +9 -10
  100. package/src/walletConnect/fetchWalletConnectWallets.js +38 -52
  101. package/src/walletConnect/index.d.ts +3 -3
  102. package/src/walletConnect/walletConnect.cjs +131 -129
  103. package/src/walletConnect/walletConnect.d.ts +52 -52
  104. package/src/walletConnect/walletConnect.js +131 -129
  105. package/src/walletConnect/walletConnectV2.cjs +419 -385
  106. package/src/walletConnect/walletConnectV2.d.ts +326 -64
  107. package/src/walletConnect/walletConnectV2.js +420 -386
  108. package/src/injected/MetaMask.cjs +0 -15
  109. package/src/injected/MetaMask.d.ts +0 -5
  110. package/src/injected/MetaMask.js +0 -11
  111. package/src/injected/OKX.cjs +0 -15
  112. package/src/injected/OKX.d.ts +0 -5
  113. package/src/injected/OKX.js +0 -11
  114. package/src/injected/UnknownInjectedWallet.cjs +0 -14
  115. package/src/injected/UnknownInjectedWallet.d.ts +0 -4
  116. package/src/injected/UnknownInjectedWallet.js +0 -10
  117. package/src/injected/index.cjs +0 -53
  118. package/src/injected/index.js +0 -49
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../../_virtual/_tslib.cjs');
6
6
  var WalletConnectProvider = require('@walletconnect/ethereum-provider');
7
- var ethers = require('ethers');
7
+ var viem = require('viem');
8
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
9
  var walletBook = require('@dynamic-labs/wallet-book');
10
10
  var utils = require('@dynamic-labs/utils');
@@ -16,134 +16,136 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
16
16
 
17
17
  var WalletConnectProvider__default = /*#__PURE__*/_interopDefaultLegacy(WalletConnectProvider);
18
18
 
19
- class WalletConnect extends EthWalletConnector.EthWalletConnector {
20
- constructor(_a) {
21
- var { walletConnectV1Bridge, walletName } = _a, props = _tslib.__rest(_a, ["walletConnectV1Bridge", "walletName"]);
22
- super(props);
23
- this.supportedChains = ['EVM', 'ETH'];
24
- this.connectedChain = 'EVM';
25
- this.bridge = 'https://bridge.walletconnect.org';
26
- this.canConnectViaQrCode = true;
27
- this.isWalletConnect = true;
28
- this.switchNetworkOnlyFromWallet = false;
29
- this.name = walletName;
30
- if (walletConnectV1Bridge) {
31
- this.bridge = walletConnectV1Bridge;
32
- }
33
- this.deepLinkPreference = props.deepLinkPreference || 'native';
34
- }
35
- getClient() {
36
- if (this.client) {
37
- return this.client;
38
- }
39
- this.client = client.initClient(walletConnectorCore.normalizeWalletName(this.name), this.bridge, this.clientOptions);
40
- return this.client;
41
- }
42
- supportsNetworkSwitching() {
43
- if (this.connectedChain === 'EVM') {
44
- return true;
45
- }
46
- else {
47
- const client = this.getClient();
48
- return Boolean(client === null || client === void 0 ? void 0 : client.chainId);
49
- }
50
- }
51
- setupEventListeners() {
52
- client.setupWalletConnectEventListeners(this, this.getClient());
53
- }
54
- teardownEventListeners() {
55
- client.teardownWalletConnectEventListeners(this.getClient());
56
- }
57
- getWeb3Provider() {
58
- const client = this.getClient();
59
- return client
60
- ? new ethers.ethers.providers.Web3Provider(new WalletConnectProvider__default["default"]({
61
- connector: client,
62
- infuraId: constants.INFURA_ID,
63
- rpc: this.evmNetworkRpcMap(),
64
- }), 'any')
65
- : undefined;
66
- }
67
- fetchPublicAddress(opts) {
68
- return _tslib.__awaiter(this, void 0, void 0, function* () {
69
- return client.fetchWalletConnectEVMPublicAddress(walletBook.getWalletBookWallet(this.walletBook, this.key), this.getClient(), this.deepLinkPreference, Object.assign(Object.assign({}, opts), { onConnect: (payload) => {
70
- var _a;
71
- (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
72
- this.connectedChain = payload.params[0].chainId ? 'EVM' : 'SOL';
73
- } }));
74
- });
75
- }
76
- getDeepLink() {
77
- var _a;
78
- const wallet = walletBook.getWalletBookWallet(this.walletBook, this.key);
79
- if (!utils.isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
80
- return undefined;
81
- }
82
- return walletConnectorCore.getDeepLink({
83
- metadata: wallet,
84
- mode: 'regular',
85
- preference: this.deepLinkPreference,
86
- uri: this.getClient().uri,
87
- });
88
- }
89
- signMessage(messageToSign) {
90
- return _tslib.__awaiter(this, void 0, void 0, function* () {
91
- return client.signWalletConnectPersonalMessage(messageToSign, walletBook.getWalletBookWallet(this.walletBook, this.key), this.getClient(), this.deepLinkPreference,
92
- // don't call getRpcProvider until we really need to
93
- () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.getRpcProvider(); }));
94
- });
95
- }
96
- endSession() {
97
- return _tslib.__awaiter(this, void 0, void 0, function* () {
98
- client.killWalletConnectSession(this.getClient());
99
- });
100
- }
101
- providerSwitchNetwork({ network, provider, }) {
102
- const _super = Object.create(null, {
103
- providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
104
- });
105
- return _tslib.__awaiter(this, void 0, void 0, function* () {
106
- const client = this.getClient();
107
- const currentNetworkId = yield this.getNetwork();
108
- if (currentNetworkId && currentNetworkId === network.chainId) {
109
- return;
110
- }
111
- if (this.switchNetworkOnlyFromWallet !== undefined &&
112
- this.switchNetworkOnlyFromWallet) {
113
- throw new utils.DynamicError('Network switching is only supported through the wallet');
114
- }
115
- if (!this.supportsNetworkSwitching()) {
116
- throw new utils.DynamicError('Network switching not supported');
117
- }
118
- if (!client) {
119
- throw new utils.DynamicError('Client not found');
120
- }
121
- if (utils.isMobile()) {
122
- const deepLink = walletConnectorCore.getDeepLink({
123
- metadata: walletBook.getWalletBookWallet(this.walletBook, this.key),
124
- mode: 'regular',
125
- preference: this.deepLinkPreference,
126
- uri: client.uri,
127
- });
128
- window.location.href = deepLink;
129
- }
130
- return _super.providerSwitchNetwork.call(this, { network, provider });
131
- });
132
- }
133
- getConnectedAccounts() {
134
- return _tslib.__awaiter(this, void 0, void 0, function* () {
135
- const client = this.getClient();
136
- if (!client.connected)
137
- return [];
138
- return client.accounts;
139
- });
140
- }
141
- getSession() {
142
- var _a;
143
- return _tslib.__awaiter(this, void 0, void 0, function* () {
144
- return (_a = this.client) === null || _a === void 0 ? void 0 : _a.session;
145
- });
146
- }
19
+ class WalletConnect extends EthWalletConnector.EthWalletConnector {
20
+ constructor(_a) {
21
+ var { walletConnectV1Bridge, walletName } = _a, props = _tslib.__rest(_a, ["walletConnectV1Bridge", "walletName"]);
22
+ super(props);
23
+ this.supportedChains = ['EVM', 'ETH'];
24
+ this.connectedChain = 'EVM';
25
+ this.bridge = 'https://bridge.walletconnect.org';
26
+ this.canConnectViaQrCode = true;
27
+ this.isWalletConnect = true;
28
+ this.switchNetworkOnlyFromWallet = false;
29
+ this.name = walletName;
30
+ if (walletConnectV1Bridge) {
31
+ this.bridge = walletConnectV1Bridge;
32
+ }
33
+ this.deepLinkPreference = props.deepLinkPreference || 'native';
34
+ }
35
+ getClient() {
36
+ if (this.client) {
37
+ return this.client;
38
+ }
39
+ this.client = client.initClient(walletConnectorCore.normalizeWalletName(this.name), this.bridge, this.clientOptions);
40
+ return this.client;
41
+ }
42
+ supportsNetworkSwitching() {
43
+ if (this.connectedChain === 'EVM') {
44
+ return true;
45
+ }
46
+ else {
47
+ const client = this.getClient();
48
+ return Boolean(client === null || client === void 0 ? void 0 : client.chainId);
49
+ }
50
+ }
51
+ setupEventListeners() {
52
+ client.setupWalletConnectEventListeners(this, this.getClient());
53
+ }
54
+ teardownEventListeners() {
55
+ client.teardownWalletConnectEventListeners(this.getClient());
56
+ }
57
+ getWalletClient() {
58
+ const client = this.getClient();
59
+ return client
60
+ ? viem.createWalletClient({
61
+ transport: viem.custom(new WalletConnectProvider__default["default"]({
62
+ connector: client,
63
+ infuraId: constants.INFURA_ID,
64
+ rpc: this.evmNetworkRpcMap(),
65
+ })),
66
+ })
67
+ : undefined;
68
+ }
69
+ fetchPublicAddress(opts) {
70
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
71
+ return client.fetchWalletConnectEVMPublicAddress(walletBook.getWalletBookWallet(this.walletBook, this.key), this.getClient(), this.deepLinkPreference, Object.assign(Object.assign({}, opts), { onConnect: (payload) => {
72
+ var _a;
73
+ (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
74
+ this.connectedChain = payload.params[0].chainId ? 'EVM' : 'SOL';
75
+ } }));
76
+ });
77
+ }
78
+ getDeepLink() {
79
+ var _a;
80
+ const wallet = walletBook.getWalletBookWallet(this.walletBook, this.key);
81
+ if (!utils.isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
82
+ return undefined;
83
+ }
84
+ return walletConnectorCore.getDeepLink({
85
+ metadata: wallet,
86
+ mode: 'regular',
87
+ preference: this.deepLinkPreference,
88
+ uri: this.getClient().uri,
89
+ });
90
+ }
91
+ signMessage(messageToSign) {
92
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
93
+ return client.signWalletConnectPersonalMessage(messageToSign, walletBook.getWalletBookWallet(this.walletBook, this.key), this.getClient(), this.deepLinkPreference,
94
+ // don't call getPublicClient until we really need to
95
+ () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.getPublicClient(); }));
96
+ });
97
+ }
98
+ endSession() {
99
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
100
+ client.killWalletConnectSession(this.getClient());
101
+ });
102
+ }
103
+ providerSwitchNetwork({ network, provider, }) {
104
+ const _super = Object.create(null, {
105
+ providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
106
+ });
107
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
108
+ const client = this.getClient();
109
+ const currentNetworkId = yield this.getNetwork();
110
+ if (currentNetworkId && currentNetworkId === network.chainId) {
111
+ return;
112
+ }
113
+ if (this.switchNetworkOnlyFromWallet !== undefined &&
114
+ this.switchNetworkOnlyFromWallet) {
115
+ throw new utils.DynamicError('Network switching is only supported through the wallet');
116
+ }
117
+ if (!this.supportsNetworkSwitching()) {
118
+ throw new utils.DynamicError('Network switching not supported');
119
+ }
120
+ if (!client) {
121
+ throw new utils.DynamicError('Client not found');
122
+ }
123
+ if (utils.isMobile()) {
124
+ const deepLink = walletConnectorCore.getDeepLink({
125
+ metadata: walletBook.getWalletBookWallet(this.walletBook, this.key),
126
+ mode: 'regular',
127
+ preference: this.deepLinkPreference,
128
+ uri: client.uri,
129
+ });
130
+ window.location.href = deepLink;
131
+ }
132
+ return _super.providerSwitchNetwork.call(this, { network, provider });
133
+ });
134
+ }
135
+ getConnectedAccounts() {
136
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
137
+ const client = this.getClient();
138
+ if (!client.connected)
139
+ return [];
140
+ return client.accounts;
141
+ });
142
+ }
143
+ getSession() {
144
+ var _a;
145
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
146
+ return (_a = this.client) === null || _a === void 0 ? void 0 : _a.session;
147
+ });
148
+ }
147
149
  }
148
150
 
149
151
  exports.WalletConnect = WalletConnect;
@@ -1,52 +1,52 @@
1
- import Client from '@walletconnect/client';
2
- import { ethers } from 'ethers';
3
- import { Chain, FetchPublicAddressOpts, DeepLinkVariant } from '@dynamic-labs/wallet-connector-core';
4
- import { EvmNetwork } from '@dynamic-labs/types';
5
- import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
6
- type ConnectorSession = {
7
- connected: boolean;
8
- accounts: string[];
9
- chainId: number;
10
- bridge: string;
11
- key: string;
12
- clientId: string;
13
- clientMeta: any;
14
- peerId: string;
15
- peerMeta: any;
16
- handshakeId: number;
17
- handshakeTopic: string;
18
- };
19
- export type WalletConnectOpts = EthWalletConnectorOpts & {
20
- walletConnectV1Bridge: string;
21
- walletName: string;
22
- deepLinkPreference?: DeepLinkVariant;
23
- };
24
- export declare class WalletConnect extends EthWalletConnector {
25
- supportedChains: Chain[];
26
- connectedChain: Chain;
27
- name: string;
28
- bridge: string;
29
- canConnectViaQrCode: boolean;
30
- isWalletConnect: boolean;
31
- switchNetworkOnlyFromWallet: boolean;
32
- private deepLinkPreference;
33
- client?: Client;
34
- clientOptions?: any;
35
- constructor({ walletConnectV1Bridge, walletName, ...props }: WalletConnectOpts);
36
- getClient(): Client;
37
- supportsNetworkSwitching(): boolean;
38
- setupEventListeners(): void;
39
- teardownEventListeners(): void;
40
- getWeb3Provider(): ethers.providers.Web3Provider | undefined;
41
- fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
42
- getDeepLink(): string | undefined;
43
- signMessage(messageToSign: string): Promise<string | undefined>;
44
- endSession(): Promise<void>;
45
- providerSwitchNetwork({ network, provider, }: {
46
- network: EvmNetwork;
47
- provider: ethers.providers.Web3Provider;
48
- }): Promise<void>;
49
- getConnectedAccounts(): Promise<string[]>;
50
- getSession(): Promise<ConnectorSession | undefined>;
51
- }
52
- export {};
1
+ import Client from '@walletconnect/client';
2
+ import { Hex, WalletClient } from 'viem';
3
+ import { Chain, FetchPublicAddressOpts, DeepLinkVariant } from '@dynamic-labs/wallet-connector-core';
4
+ import { EvmNetwork } from '@dynamic-labs/types';
5
+ import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
6
+ type ConnectorSession = {
7
+ connected: boolean;
8
+ accounts: string[];
9
+ chainId: number;
10
+ bridge: string;
11
+ key: string;
12
+ clientId: string;
13
+ clientMeta: any;
14
+ peerId: string;
15
+ peerMeta: any;
16
+ handshakeId: number;
17
+ handshakeTopic: string;
18
+ };
19
+ export type WalletConnectOpts = EthWalletConnectorOpts & {
20
+ walletConnectV1Bridge: string;
21
+ walletName: string;
22
+ deepLinkPreference?: DeepLinkVariant;
23
+ };
24
+ export declare class WalletConnect extends EthWalletConnector {
25
+ supportedChains: Chain[];
26
+ connectedChain: Chain;
27
+ name: string;
28
+ bridge: string;
29
+ canConnectViaQrCode: boolean;
30
+ isWalletConnect: boolean;
31
+ switchNetworkOnlyFromWallet: boolean;
32
+ private deepLinkPreference;
33
+ client?: Client;
34
+ clientOptions?: any;
35
+ constructor({ walletConnectV1Bridge, walletName, ...props }: WalletConnectOpts);
36
+ getClient(): Client;
37
+ supportsNetworkSwitching(): boolean;
38
+ setupEventListeners(): void;
39
+ teardownEventListeners(): void;
40
+ getWalletClient(): WalletClient | undefined;
41
+ fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
42
+ getDeepLink(): string | undefined;
43
+ signMessage(messageToSign: string): Promise<string | undefined>;
44
+ endSession(): Promise<void>;
45
+ providerSwitchNetwork({ network, provider, }: {
46
+ network: EvmNetwork;
47
+ provider: WalletClient;
48
+ }): Promise<void>;
49
+ getConnectedAccounts(): Promise<Hex[]>;
50
+ getSession(): Promise<ConnectorSession | undefined>;
51
+ }
52
+ export {};