@dynamic-labs/ethereum 0.19.0-alpha.9 → 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.
- package/CHANGELOG.md +292 -0
- package/package.json +14 -11
- package/src/EthWalletConnector.cjs +189 -193
- package/src/EthWalletConnector.d.ts +298 -41
- package/src/EthWalletConnector.js +190 -194
- package/src/coinbase/client/client.cjs +78 -0
- package/src/coinbase/client/client.d.ts +6 -0
- package/src/coinbase/client/client.js +71 -0
- package/src/coinbase/client/index.d.ts +2 -0
- package/src/coinbase/client/types.d.ts +14 -0
- package/src/coinbase/coinbase.cjs +71 -0
- package/src/coinbase/coinbase.d.ts +535 -0
- package/src/coinbase/coinbase.js +67 -0
- package/src/coinbase/index.d.ts +3 -0
- package/src/constants.d.ts +1 -1
- package/src/ethProviderHelper.cjs +129 -127
- package/src/ethProviderHelper.d.ts +28 -27
- package/src/ethProviderHelper.js +130 -128
- package/src/index.cjs +10 -8
- package/src/index.d.ts +9 -9
- package/src/index.js +10 -7
- package/src/injected/BloctoInjected.cjs +5 -5
- package/src/injected/BloctoInjected.d.ts +4 -4
- package/src/injected/BloctoInjected.js +5 -5
- package/src/injected/BraveEvm.cjs +5 -5
- package/src/injected/BraveEvm.d.ts +4 -4
- package/src/injected/BraveEvm.js +5 -5
- package/src/injected/Dawn.cjs +5 -5
- package/src/injected/Dawn.d.ts +4 -4
- package/src/injected/Dawn.js +5 -5
- package/src/injected/ExodusEvm.cjs +6 -6
- package/src/injected/ExodusEvm.d.ts +5 -5
- package/src/injected/ExodusEvm.js +6 -6
- package/src/injected/Frame.cjs +5 -5
- package/src/injected/Frame.d.ts +4 -4
- package/src/injected/Frame.js +5 -5
- package/src/injected/GameStop.cjs +5 -5
- package/src/injected/GameStop.d.ts +4 -4
- package/src/injected/GameStop.js +5 -5
- package/src/injected/InjectedWalletBase.cjs +86 -78
- package/src/injected/InjectedWalletBase.d.ts +29 -29
- package/src/injected/InjectedWalletBase.js +86 -78
- package/src/injected/LegacyInjectedWalletBase.cjs +71 -65
- package/src/injected/LegacyInjectedWalletBase.d.ts +24 -24
- package/src/injected/LegacyInjectedWalletBase.js +71 -65
- package/src/injected/Opera.cjs +5 -5
- package/src/injected/Opera.d.ts +4 -4
- package/src/injected/Opera.js +5 -5
- package/src/injected/PhantomEvm.cjs +27 -27
- package/src/injected/PhantomEvm.d.ts +5 -5
- package/src/injected/PhantomEvm.js +27 -27
- package/src/injected/Rabby.cjs +6 -6
- package/src/injected/Rabby.d.ts +5 -5
- package/src/injected/Rabby.js +6 -6
- package/src/injected/Superb.cjs +5 -5
- package/src/injected/Superb.d.ts +4 -4
- package/src/injected/Superb.js +5 -5
- package/src/injected/Trust.cjs +6 -6
- package/src/injected/Trust.d.ts +5 -5
- package/src/injected/Trust.js +6 -6
- package/src/injected/Zerion.cjs +6 -6
- package/src/injected/Zerion.d.ts +5 -5
- package/src/injected/Zerion.js +6 -6
- package/src/injected/fetchInjectedWalletConnectors.cjs +23 -22
- package/src/injected/fetchInjectedWalletConnectors.d.ts +6 -6
- package/src/injected/fetchInjectedWalletConnectors.js +23 -22
- package/src/injected/index.d.ts +13 -14
- package/src/injected/legacyInjectedWallets.cjs +27 -30
- package/src/injected/legacyInjectedWallets.d.ts +3 -3
- package/src/injected/legacyInjectedWallets.js +27 -30
- package/src/legacyEthProviderHelper.cjs +175 -181
- package/src/legacyEthProviderHelper.d.ts +34 -33
- package/src/legacyEthProviderHelper.js +175 -181
- package/src/polyfills.cjs +11 -11
- package/src/polyfills.d.ts +1 -1
- package/src/polyfills.js +11 -11
- package/src/types.d.ts +37 -35
- package/src/utils/eventListenerHandlers.cjs +25 -25
- package/src/utils/eventListenerHandlers.d.ts +8 -8
- package/src/utils/eventListenerHandlers.js +25 -25
- package/src/utils/findEvmNetwork.cjs +13 -13
- package/src/utils/findEvmNetwork.d.ts +6 -6
- package/src/utils/findEvmNetwork.js +13 -13
- package/src/utils/isString.d.ts +1 -1
- package/src/utils/isUnsupportedProviderError/index.d.ts +1 -1
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.cjs +6 -6
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +6 -6
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.js +6 -6
- package/src/utils/last.d.ts +1 -1
- package/src/utils/parseIntSafe.cjs +13 -13
- package/src/utils/parseIntSafe.d.ts +1 -1
- package/src/utils/parseIntSafe.js +13 -13
- package/src/walletConnect/client/client.cjs +179 -175
- package/src/walletConnect/client/client.d.ts +17 -17
- package/src/walletConnect/client/client.js +179 -175
- package/src/walletConnect/client/index.d.ts +1 -1
- package/src/walletConnect/client/types.d.ts +4 -4
- package/src/walletConnect/fetchWalletConnectWallets.cjs +37 -37
- package/src/walletConnect/fetchWalletConnectWallets.d.ts +9 -9
- package/src/walletConnect/fetchWalletConnectWallets.js +37 -37
- package/src/walletConnect/index.d.ts +3 -3
- package/src/walletConnect/walletConnect.cjs +131 -129
- package/src/walletConnect/walletConnect.d.ts +52 -52
- package/src/walletConnect/walletConnect.js +131 -129
- package/src/walletConnect/walletConnectV2.cjs +419 -387
- package/src/walletConnect/walletConnectV2.d.ts +326 -64
- package/src/walletConnect/walletConnectV2.js +420 -388
- package/src/injected/MetaMask.cjs +0 -15
- package/src/injected/MetaMask.d.ts +0 -5
- package/src/injected/MetaMask.js +0 -11
|
@@ -3,137 +3,139 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _tslib = require('../_virtual/_tslib.cjs');
|
|
6
|
-
var
|
|
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 isUnsupportedProviderError = require('./utils/isUnsupportedProviderError/isUnsupportedProviderError.cjs');
|
|
10
9
|
var eventListenerHandlers = require('./utils/eventListenerHandlers.cjs');
|
|
11
10
|
|
|
12
|
-
class EthProviderHelper {
|
|
13
|
-
constructor(wallet) {
|
|
14
|
-
this.wallet = wallet;
|
|
15
|
-
}
|
|
16
|
-
getInstalledProvider() {
|
|
17
|
-
const config = this.getInjectedConfig();
|
|
18
|
-
if (!config ||
|
|
19
|
-
!config.extensionLocators ||
|
|
20
|
-
!config.extensionLocators.length)
|
|
21
|
-
return undefined;
|
|
22
|
-
return this.installedProviderLookup(config.extensionLocators);
|
|
23
|
-
}
|
|
24
|
-
getInjectedConfig() {
|
|
25
|
-
if (!this.wallet || !this.wallet.injectedConfig)
|
|
26
|
-
return;
|
|
27
|
-
const { injectedConfig } = this.wallet;
|
|
28
|
-
return injectedConfig.find((c) => c.chain === 'evm');
|
|
29
|
-
}
|
|
30
|
-
installedProviders() {
|
|
31
|
-
const config = this.getInjectedConfig();
|
|
32
|
-
if (!config)
|
|
33
|
-
return [];
|
|
34
|
-
const providers = [];
|
|
35
|
-
if (config.windowLocations) {
|
|
36
|
-
for (const windowLocation of config.windowLocations) {
|
|
37
|
-
const foundProviders = utils.
|
|
38
|
-
if (foundProviders && foundProviders.length)
|
|
39
|
-
providers.push(...foundProviders);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (window.ethereum) {
|
|
43
|
-
if (!window.ethereum.providers || !window.ethereum.providers.length) {
|
|
44
|
-
providers.push(window.ethereum);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
window.ethereum.providers.forEach((p) => providers.push(p));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return providers;
|
|
51
|
-
}
|
|
52
|
-
installedProviderLookup(providerFlags) {
|
|
53
|
-
const allInstalledProviders = this.installedProviders();
|
|
54
|
-
return walletConnectorCore.ProviderLookup(allInstalledProviders, providerFlags);
|
|
55
|
-
}
|
|
56
|
-
isInstalledHelper() {
|
|
57
|
-
return this.findProvider() !== undefined;
|
|
58
|
-
}
|
|
59
|
-
findProvider() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
if (!
|
|
101
|
-
return Promise.resolve(undefined);
|
|
102
|
-
}
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
|
|
11
|
+
class EthProviderHelper {
|
|
12
|
+
constructor(wallet) {
|
|
13
|
+
this.wallet = wallet;
|
|
14
|
+
}
|
|
15
|
+
getInstalledProvider() {
|
|
16
|
+
const config = this.getInjectedConfig();
|
|
17
|
+
if (!config ||
|
|
18
|
+
!config.extensionLocators ||
|
|
19
|
+
!config.extensionLocators.length)
|
|
20
|
+
return undefined;
|
|
21
|
+
return this.installedProviderLookup(config.extensionLocators);
|
|
22
|
+
}
|
|
23
|
+
getInjectedConfig() {
|
|
24
|
+
if (!this.wallet || !this.wallet.injectedConfig)
|
|
25
|
+
return;
|
|
26
|
+
const { injectedConfig } = this.wallet;
|
|
27
|
+
return injectedConfig.find((c) => c.chain === 'evm');
|
|
28
|
+
}
|
|
29
|
+
installedProviders() {
|
|
30
|
+
const config = this.getInjectedConfig();
|
|
31
|
+
if (!config)
|
|
32
|
+
return [];
|
|
33
|
+
const providers = [];
|
|
34
|
+
if (config.windowLocations) {
|
|
35
|
+
for (const windowLocation of config.windowLocations) {
|
|
36
|
+
const foundProviders = utils.getProvidersFromWindow(windowLocation);
|
|
37
|
+
if (foundProviders && foundProviders.length)
|
|
38
|
+
providers.push(...foundProviders);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (window.ethereum) {
|
|
42
|
+
if (!window.ethereum.providers || !window.ethereum.providers.length) {
|
|
43
|
+
providers.push(window.ethereum);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
window.ethereum.providers.forEach((p) => providers.push(p));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return providers;
|
|
50
|
+
}
|
|
51
|
+
installedProviderLookup(providerFlags) {
|
|
52
|
+
const allInstalledProviders = this.installedProviders();
|
|
53
|
+
return walletConnectorCore.ProviderLookup(allInstalledProviders, providerFlags);
|
|
54
|
+
}
|
|
55
|
+
isInstalledHelper() {
|
|
56
|
+
return this.findProvider() !== undefined;
|
|
57
|
+
}
|
|
58
|
+
findProvider() {
|
|
59
|
+
return this.getInstalledProvider();
|
|
60
|
+
}
|
|
61
|
+
findWalletClient() {
|
|
62
|
+
const provider = this.findProvider();
|
|
63
|
+
if (!provider) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return viem.createWalletClient({
|
|
67
|
+
transport: viem.custom(provider),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
fetchPublicAddress() {
|
|
71
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const client = this.findWalletClient();
|
|
73
|
+
if (!client) {
|
|
74
|
+
return Promise.resolve(undefined);
|
|
75
|
+
}
|
|
76
|
+
return this.fetchPublicAddressWithProvider(client);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
fetchPublicAddressWithProvider(client) {
|
|
80
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
try {
|
|
82
|
+
const [lowercaseAddress] = yield client.requestAddresses();
|
|
83
|
+
const publicAddress = viem.getAddress(lowercaseAddress);
|
|
84
|
+
return publicAddress;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
walletConnectorCore.logger.error(err);
|
|
88
|
+
return Promise.reject(err);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
signMessage(messageToSign) {
|
|
93
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const walletAddress = yield this.fetchPublicAddress();
|
|
95
|
+
if (!walletAddress) {
|
|
96
|
+
return Promise.resolve(undefined);
|
|
97
|
+
}
|
|
98
|
+
const client = this.findWalletClient();
|
|
99
|
+
if (!client) {
|
|
100
|
+
return Promise.resolve(undefined);
|
|
101
|
+
}
|
|
102
|
+
const signedMessage = yield client.signMessage({
|
|
103
|
+
account: walletAddress,
|
|
104
|
+
message: messageToSign,
|
|
105
|
+
});
|
|
106
|
+
return signedMessage;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
_setupEventListeners(walletConnector, publicClient) {
|
|
110
|
+
const web3Provider = this.findProvider();
|
|
111
|
+
if (!web3Provider) {
|
|
112
|
+
return {
|
|
113
|
+
tearDownEventListeners: () => { },
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers.eventListenerHandlers(walletConnector, publicClient);
|
|
117
|
+
web3Provider.on('accountsChanged', handleAccountChange);
|
|
118
|
+
web3Provider.on('chainChanged', handleChainChange);
|
|
119
|
+
web3Provider.on('disconnect', handleDisconnect);
|
|
120
|
+
const tearDownEventListeners = () => {
|
|
121
|
+
const web3Provider = this.findProvider();
|
|
122
|
+
if (!web3Provider) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (handleAccountChange) {
|
|
126
|
+
web3Provider.removeListener('accountsChanged', handleAccountChange);
|
|
127
|
+
}
|
|
128
|
+
if (handleChainChange) {
|
|
129
|
+
web3Provider.removeListener('chainChanged', handleChainChange);
|
|
130
|
+
}
|
|
131
|
+
if (handleDisconnect) {
|
|
132
|
+
web3Provider.removeListener('disconnect', handleDisconnect);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
tearDownEventListeners,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
exports.EthProviderHelper = EthProviderHelper;
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ProviderCondition, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
4
|
-
import { IEthereum, ProviderFlag } from './types';
|
|
5
|
-
export declare class EthProviderHelper {
|
|
6
|
-
private wallet;
|
|
7
|
-
constructor(wallet: WalletSchema);
|
|
8
|
-
getInstalledProvider(): IEthereum | undefined;
|
|
9
|
-
getInjectedConfig(): {
|
|
10
|
-
chain: string;
|
|
11
|
-
extensionLocators: {
|
|
12
|
-
value: boolean;
|
|
13
|
-
flag: string;
|
|
14
|
-
}[];
|
|
15
|
-
windowLocations?: string[] | undefined;
|
|
16
|
-
} | undefined;
|
|
17
|
-
installedProviders(): IEthereum[];
|
|
18
|
-
installedProviderLookup(providerFlags: Array<ProviderCondition<ProviderFlag>>): IEthereum | undefined;
|
|
19
|
-
isInstalledHelper(): boolean;
|
|
20
|
-
findProvider():
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
1
|
+
import { Hex, PublicClient, WalletClient } from 'viem';
|
|
2
|
+
import { ProviderCondition, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
4
|
+
import { IEthereum, ProviderFlag } from './types';
|
|
5
|
+
export declare class EthProviderHelper {
|
|
6
|
+
private wallet;
|
|
7
|
+
constructor(wallet: WalletSchema);
|
|
8
|
+
getInstalledProvider(): IEthereum | undefined;
|
|
9
|
+
getInjectedConfig(): {
|
|
10
|
+
chain: string;
|
|
11
|
+
extensionLocators: {
|
|
12
|
+
value: boolean;
|
|
13
|
+
flag: string;
|
|
14
|
+
}[];
|
|
15
|
+
windowLocations?: string[] | undefined;
|
|
16
|
+
} | undefined;
|
|
17
|
+
installedProviders(): IEthereum[];
|
|
18
|
+
installedProviderLookup(providerFlags: Array<ProviderCondition<ProviderFlag>>): IEthereum | undefined;
|
|
19
|
+
isInstalledHelper(): boolean;
|
|
20
|
+
findProvider(): IEthereum | undefined;
|
|
21
|
+
findWalletClient(): WalletClient | undefined;
|
|
22
|
+
fetchPublicAddress(): Promise<Hex | undefined>;
|
|
23
|
+
fetchPublicAddressWithProvider(client: WalletClient): Promise<Hex | undefined>;
|
|
24
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
25
|
+
_setupEventListeners(walletConnector: WalletConnector, publicClient: PublicClient): {
|
|
26
|
+
tearDownEventListeners: () => void;
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/ethProviderHelper.js
CHANGED
|
@@ -1,135 +1,137 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
-
import {
|
|
2
|
+
import { createWalletClient, custom, getAddress } from 'viem';
|
|
3
3
|
import { ProviderLookup, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import {
|
|
5
|
-
import { isUnsupportedProviderError } from './utils/isUnsupportedProviderError/isUnsupportedProviderError.js';
|
|
4
|
+
import { getProvidersFromWindow } from '@dynamic-labs/utils';
|
|
6
5
|
import { eventListenerHandlers } from './utils/eventListenerHandlers.js';
|
|
7
6
|
|
|
8
|
-
class EthProviderHelper {
|
|
9
|
-
constructor(wallet) {
|
|
10
|
-
this.wallet = wallet;
|
|
11
|
-
}
|
|
12
|
-
getInstalledProvider() {
|
|
13
|
-
const config = this.getInjectedConfig();
|
|
14
|
-
if (!config ||
|
|
15
|
-
!config.extensionLocators ||
|
|
16
|
-
!config.extensionLocators.length)
|
|
17
|
-
return undefined;
|
|
18
|
-
return this.installedProviderLookup(config.extensionLocators);
|
|
19
|
-
}
|
|
20
|
-
getInjectedConfig() {
|
|
21
|
-
if (!this.wallet || !this.wallet.injectedConfig)
|
|
22
|
-
return;
|
|
23
|
-
const { injectedConfig } = this.wallet;
|
|
24
|
-
return injectedConfig.find((c) => c.chain === 'evm');
|
|
25
|
-
}
|
|
26
|
-
installedProviders() {
|
|
27
|
-
const config = this.getInjectedConfig();
|
|
28
|
-
if (!config)
|
|
29
|
-
return [];
|
|
30
|
-
const providers = [];
|
|
31
|
-
if (config.windowLocations) {
|
|
32
|
-
for (const windowLocation of config.windowLocations) {
|
|
33
|
-
const foundProviders =
|
|
34
|
-
if (foundProviders && foundProviders.length)
|
|
35
|
-
providers.push(...foundProviders);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (window.ethereum) {
|
|
39
|
-
if (!window.ethereum.providers || !window.ethereum.providers.length) {
|
|
40
|
-
providers.push(window.ethereum);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
window.ethereum.providers.forEach((p) => providers.push(p));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return providers;
|
|
47
|
-
}
|
|
48
|
-
installedProviderLookup(providerFlags) {
|
|
49
|
-
const allInstalledProviders = this.installedProviders();
|
|
50
|
-
return ProviderLookup(allInstalledProviders, providerFlags);
|
|
51
|
-
}
|
|
52
|
-
isInstalledHelper() {
|
|
53
|
-
return this.findProvider() !== undefined;
|
|
54
|
-
}
|
|
55
|
-
findProvider() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
97
|
-
return Promise.resolve(undefined);
|
|
98
|
-
}
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
|
|
7
|
+
class EthProviderHelper {
|
|
8
|
+
constructor(wallet) {
|
|
9
|
+
this.wallet = wallet;
|
|
10
|
+
}
|
|
11
|
+
getInstalledProvider() {
|
|
12
|
+
const config = this.getInjectedConfig();
|
|
13
|
+
if (!config ||
|
|
14
|
+
!config.extensionLocators ||
|
|
15
|
+
!config.extensionLocators.length)
|
|
16
|
+
return undefined;
|
|
17
|
+
return this.installedProviderLookup(config.extensionLocators);
|
|
18
|
+
}
|
|
19
|
+
getInjectedConfig() {
|
|
20
|
+
if (!this.wallet || !this.wallet.injectedConfig)
|
|
21
|
+
return;
|
|
22
|
+
const { injectedConfig } = this.wallet;
|
|
23
|
+
return injectedConfig.find((c) => c.chain === 'evm');
|
|
24
|
+
}
|
|
25
|
+
installedProviders() {
|
|
26
|
+
const config = this.getInjectedConfig();
|
|
27
|
+
if (!config)
|
|
28
|
+
return [];
|
|
29
|
+
const providers = [];
|
|
30
|
+
if (config.windowLocations) {
|
|
31
|
+
for (const windowLocation of config.windowLocations) {
|
|
32
|
+
const foundProviders = getProvidersFromWindow(windowLocation);
|
|
33
|
+
if (foundProviders && foundProviders.length)
|
|
34
|
+
providers.push(...foundProviders);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (window.ethereum) {
|
|
38
|
+
if (!window.ethereum.providers || !window.ethereum.providers.length) {
|
|
39
|
+
providers.push(window.ethereum);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
window.ethereum.providers.forEach((p) => providers.push(p));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return providers;
|
|
46
|
+
}
|
|
47
|
+
installedProviderLookup(providerFlags) {
|
|
48
|
+
const allInstalledProviders = this.installedProviders();
|
|
49
|
+
return ProviderLookup(allInstalledProviders, providerFlags);
|
|
50
|
+
}
|
|
51
|
+
isInstalledHelper() {
|
|
52
|
+
return this.findProvider() !== undefined;
|
|
53
|
+
}
|
|
54
|
+
findProvider() {
|
|
55
|
+
return this.getInstalledProvider();
|
|
56
|
+
}
|
|
57
|
+
findWalletClient() {
|
|
58
|
+
const provider = this.findProvider();
|
|
59
|
+
if (!provider) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return createWalletClient({
|
|
63
|
+
transport: custom(provider),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
fetchPublicAddress() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const client = this.findWalletClient();
|
|
69
|
+
if (!client) {
|
|
70
|
+
return Promise.resolve(undefined);
|
|
71
|
+
}
|
|
72
|
+
return this.fetchPublicAddressWithProvider(client);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
fetchPublicAddressWithProvider(client) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
try {
|
|
78
|
+
const [lowercaseAddress] = yield client.requestAddresses();
|
|
79
|
+
const publicAddress = getAddress(lowercaseAddress);
|
|
80
|
+
return publicAddress;
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
logger.error(err);
|
|
84
|
+
return Promise.reject(err);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
signMessage(messageToSign) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const walletAddress = yield this.fetchPublicAddress();
|
|
91
|
+
if (!walletAddress) {
|
|
92
|
+
return Promise.resolve(undefined);
|
|
93
|
+
}
|
|
94
|
+
const client = this.findWalletClient();
|
|
95
|
+
if (!client) {
|
|
96
|
+
return Promise.resolve(undefined);
|
|
97
|
+
}
|
|
98
|
+
const signedMessage = yield client.signMessage({
|
|
99
|
+
account: walletAddress,
|
|
100
|
+
message: messageToSign,
|
|
101
|
+
});
|
|
102
|
+
return signedMessage;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
_setupEventListeners(walletConnector, publicClient) {
|
|
106
|
+
const web3Provider = this.findProvider();
|
|
107
|
+
if (!web3Provider) {
|
|
108
|
+
return {
|
|
109
|
+
tearDownEventListeners: () => { },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers(walletConnector, publicClient);
|
|
113
|
+
web3Provider.on('accountsChanged', handleAccountChange);
|
|
114
|
+
web3Provider.on('chainChanged', handleChainChange);
|
|
115
|
+
web3Provider.on('disconnect', handleDisconnect);
|
|
116
|
+
const tearDownEventListeners = () => {
|
|
117
|
+
const web3Provider = this.findProvider();
|
|
118
|
+
if (!web3Provider) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (handleAccountChange) {
|
|
122
|
+
web3Provider.removeListener('accountsChanged', handleAccountChange);
|
|
123
|
+
}
|
|
124
|
+
if (handleChainChange) {
|
|
125
|
+
web3Provider.removeListener('chainChanged', handleChainChange);
|
|
126
|
+
}
|
|
127
|
+
if (handleDisconnect) {
|
|
128
|
+
web3Provider.removeListener('disconnect', handleDisconnect);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
tearDownEventListeners,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
export { EthProviderHelper };
|
package/src/index.cjs
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
require('./polyfills.cjs');
|
|
6
|
+
var turnkey = require('@dynamic-labs/turnkey');
|
|
6
7
|
var BloctoInjected = require('./injected/BloctoInjected.cjs');
|
|
7
8
|
var BraveEvm = require('./injected/BraveEvm.cjs');
|
|
8
9
|
var Dawn = require('./injected/Dawn.cjs');
|
|
9
10
|
var ExodusEvm = require('./injected/ExodusEvm.cjs');
|
|
10
11
|
var Frame = require('./injected/Frame.cjs');
|
|
11
12
|
var GameStop = require('./injected/GameStop.cjs');
|
|
12
|
-
var MetaMask = require('./injected/MetaMask.cjs');
|
|
13
13
|
var Opera = require('./injected/Opera.cjs');
|
|
14
14
|
var PhantomEvm = require('./injected/PhantomEvm.cjs');
|
|
15
15
|
var Trust = require('./injected/Trust.cjs');
|
|
@@ -19,7 +19,7 @@ var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConne
|
|
|
19
19
|
var legacyInjectedWallets = require('./injected/legacyInjectedWallets.cjs');
|
|
20
20
|
require('./walletConnect/walletConnectV2.cjs');
|
|
21
21
|
require('@walletconnect/ethereum-provider');
|
|
22
|
-
require('
|
|
22
|
+
require('viem');
|
|
23
23
|
require('@dynamic-labs/wallet-connector-core');
|
|
24
24
|
require('@dynamic-labs/wallet-book');
|
|
25
25
|
require('@dynamic-labs/utils');
|
|
@@ -27,14 +27,17 @@ var EthWalletConnector = require('./EthWalletConnector.cjs');
|
|
|
27
27
|
var constants = require('./constants.cjs');
|
|
28
28
|
require('@walletconnect/client');
|
|
29
29
|
var fetchWalletConnectWallets = require('./walletConnect/fetchWalletConnectWallets.cjs');
|
|
30
|
+
var coinbase = require('./coinbase/coinbase.cjs');
|
|
30
31
|
var ethProviderHelper = require('./ethProviderHelper.cjs');
|
|
31
32
|
var legacyEthProviderHelper = require('./legacyEthProviderHelper.cjs');
|
|
32
33
|
|
|
33
|
-
const EthereumWalletConnectors = (props) => [
|
|
34
|
-
...legacyInjectedWallets.legacyInjectedWallets,
|
|
35
|
-
...fetchInjectedWalletConnectors.fetchInjectedWalletConnector(props),
|
|
36
|
-
...fetchWalletConnectWallets.fetchWalletConnectWallets(props),
|
|
37
|
-
|
|
34
|
+
const EthereumWalletConnectors = (props) => [
|
|
35
|
+
...legacyInjectedWallets.legacyInjectedWallets,
|
|
36
|
+
...fetchInjectedWalletConnectors.fetchInjectedWalletConnector(props),
|
|
37
|
+
...fetchWalletConnectWallets.fetchWalletConnectWallets(props),
|
|
38
|
+
...turnkey.TurnkeyWalletConnectors(props),
|
|
39
|
+
coinbase.Coinbase,
|
|
40
|
+
fetchWalletConnectWallets.getWalletConnectConnector(props),
|
|
38
41
|
];
|
|
39
42
|
|
|
40
43
|
exports.BloctoInjected = BloctoInjected.BloctoInjected;
|
|
@@ -43,7 +46,6 @@ exports.Dawn = Dawn.Dawn;
|
|
|
43
46
|
exports.ExodusEvm = ExodusEvm.ExodusEvm;
|
|
44
47
|
exports.Frame = Frame.Frame;
|
|
45
48
|
exports.GameStop = GameStop.GameStop;
|
|
46
|
-
exports.MetaMask = MetaMask.MetaMask;
|
|
47
49
|
exports.Opera = Opera.Opera;
|
|
48
50
|
exports.PhantomEvm = PhantomEvm.PhantomEvm;
|
|
49
51
|
exports.Trust = Trust.Trust;
|