@dynamic-labs/multi-wallet 0.17.0-RC.2 → 0.17.0-RC.21
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 +242 -0
- package/package.json +10 -26
- package/src/index.cjs +0 -69
- package/src/index.d.ts +0 -18
- package/src/index.js +1 -23
- package/src/multi-wallet.cjs +38 -182
- package/src/multi-wallet.d.ts +1 -4
- package/src/multi-wallet.js +37 -180
- package/src/types.d.ts +12 -50
- package/src/utils/getApiProviders.cjs +15 -0
- package/src/utils/getApiProviders.d.ts +17 -0
- package/src/utils/getApiProviders.js +11 -0
- package/src/utils/message.cjs +3 -4
- package/src/utils/message.d.ts +2 -2
- package/src/utils/message.js +1 -2
- package/src/errors.cjs +0 -65
- package/src/errors.d.ts +0 -30
- package/src/errors.js +0 -53
- package/src/polyfills.cjs +0 -16
- package/src/polyfills.d.ts +0 -1
- package/src/polyfills.js +0 -14
- package/src/rpcProviders.cjs +0 -76
- package/src/rpcProviders.d.ts +0 -5
- package/src/rpcProviders.js +0 -69
- package/src/utils/CancellablePromise/CancellablePromise.cjs +0 -33
- package/src/utils/CancellablePromise/CancellablePromise.d.ts +0 -9
- package/src/utils/CancellablePromise/CancellablePromise.js +0 -29
- package/src/utils/CancellablePromise/index.d.ts +0 -1
- package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.cjs +0 -54
- package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.d.ts +0 -3
- package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.js +0 -50
- package/src/utils/assignConfirmationScreenToProvider/index.d.ts +0 -1
- package/src/utils/convertors.cjs +0 -43
- package/src/utils/convertors.d.ts +0 -3
- package/src/utils/convertors.js +0 -38
- package/src/utils/encoding.cjs +0 -18
- package/src/utils/encoding.d.ts +0 -4
- package/src/utils/encoding.js +0 -12
- package/src/utils/extractNonce.cjs +0 -13
- package/src/utils/extractNonce.d.ts +0 -1
- package/src/utils/extractNonce.js +0 -9
- package/src/utils/getChainInfo/getChainInfo.cjs +0 -59
- package/src/utils/getChainInfo/getChainInfo.d.ts +0 -2
- package/src/utils/getChainInfo/getChainInfo.js +0 -55
- package/src/utils/getChainInfo/index.d.ts +0 -1
- package/src/utils/getWalletConnectorByName.cjs +0 -19
- package/src/utils/getWalletConnectorByName.d.ts +0 -2
- package/src/utils/getWalletConnectorByName.js +0 -15
- package/src/utils/isEmailOTPWalletConnector/index.d.ts +0 -1
- package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.cjs +0 -7
- package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.d.ts +0 -2
- package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.js +0 -3
- package/src/utils/isEmailWalletConnector/index.d.ts +0 -1
- package/src/utils/isEmailWalletConnector/isEmailWalletConnector.cjs +0 -7
- package/src/utils/isEmailWalletConnector/isEmailWalletConnector.d.ts +0 -2
- package/src/utils/isEmailWalletConnector/isEmailWalletConnector.js +0 -3
- package/src/utils/isFunction/index.d.ts +0 -1
- package/src/utils/isFunction/isFunction.cjs +0 -8
- package/src/utils/isFunction/isFunction.d.ts +0 -1
- package/src/utils/isFunction/isFunction.js +0 -4
- package/src/utils/isMobile.cjs +0 -54
- package/src/utils/isMobile.d.ts +0 -13
- package/src/utils/isMobile.js +0 -46
- package/src/utils/isSameAddress/index.d.ts +0 -1
- package/src/utils/isSameAddress/isSameAddress.cjs +0 -9
- package/src/utils/isSameAddress/isSameAddress.d.ts +0 -1
- package/src/utils/isSameAddress/isSameAddress.js +0 -5
- package/src/utils/isSameAddress/utils/index.d.ts +0 -1
- package/src/utils/isSameAddress/utils/normalizeAddress/index.d.ts +0 -1
- package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.cjs +0 -17
- package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.d.ts +0 -1
- package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.js +0 -13
- package/src/utils/isSocialWalletConnector/index.d.ts +0 -1
- package/src/utils/isSocialWalletConnector/isSocialWalletConnector.cjs +0 -7
- package/src/utils/isSocialWalletConnector/isSocialWalletConnector.d.ts +0 -2
- package/src/utils/isSocialWalletConnector/isSocialWalletConnector.js +0 -3
- package/src/utils/isUnsupportedProviderError/index.d.ts +0 -1
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.cjs +0 -13
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +0 -6
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.js +0 -9
- package/src/utils/localStorageAsync.cjs +0 -28
- package/src/utils/localStorageAsync.d.ts +0 -3
- package/src/utils/localStorageAsync.js +0 -22
- package/src/utils/logger.cjs +0 -9
- package/src/utils/logger.d.ts +0 -2
- package/src/utils/logger.js +0 -5
- package/src/utils/normalizeWalletName/index.d.ts +0 -1
- package/src/utils/normalizeWalletName/normalizeWalletName.cjs +0 -7
- package/src/utils/normalizeWalletName/normalizeWalletName.d.ts +0 -1
- package/src/utils/normalizeWalletName/normalizeWalletName.js +0 -3
- package/src/utils/shouldLowercaseAddress.cjs +0 -11
- package/src/utils/shouldLowercaseAddress.d.ts +0 -1
- package/src/utils/shouldLowercaseAddress.js +0 -7
- package/src/utils/walletConnect.cjs +0 -30
- package/src/utils/walletConnect.d.ts +0 -4
- package/src/utils/walletConnect.js +0 -26
- package/src/wallets/ProviderLookup.cjs +0 -18
- package/src/wallets/ProviderLookup.d.ts +0 -4
- package/src/wallets/ProviderLookup.js +0 -14
- package/src/wallets/algorand/MyAlgoWalletConnector.cjs +0 -149
- package/src/wallets/algorand/MyAlgoWalletConnector.d.ts +0 -21
- package/src/wallets/algorand/MyAlgoWalletConnector.js +0 -143
- package/src/wallets/algorand/myalgoSigner.cjs +0 -24
- package/src/wallets/algorand/myalgoSigner.d.ts +0 -21
- package/src/wallets/algorand/myalgoSigner.js +0 -20
- package/src/wallets/clients/coinbase/coinbase.cjs +0 -73
- package/src/wallets/clients/coinbase/coinbase.d.ts +0 -6
- package/src/wallets/clients/coinbase/coinbase.js +0 -66
- package/src/wallets/clients/coinbase/index.d.ts +0 -2
- package/src/wallets/clients/coinbase/types.d.ts +0 -14
- package/src/wallets/clients/walletConnect/index.d.ts +0 -1
- package/src/wallets/clients/walletConnect/types.d.ts +0 -4
- package/src/wallets/clients/walletConnect/walletConnect.cjs +0 -204
- package/src/wallets/clients/walletConnect/walletConnect.d.ts +0 -22
- package/src/wallets/clients/walletConnect/walletConnect.js +0 -187
- package/src/wallets/constants.cjs +0 -16
- package/src/wallets/constants.d.ts +0 -4
- package/src/wallets/constants.js +0 -10
- package/src/wallets/cosmos/KeplrWalletConnect.cjs +0 -196
- package/src/wallets/cosmos/KeplrWalletConnect.d.ts +0 -46
- package/src/wallets/cosmos/KeplrWalletConnect.js +0 -194
- package/src/wallets/cosmos/KeplrWalletConnector.cjs +0 -193
- package/src/wallets/cosmos/KeplrWalletConnector.d.ts +0 -70
- package/src/wallets/cosmos/KeplrWalletConnector.js +0 -189
- package/src/wallets/cosmos/getKeplrConnector.cjs +0 -18
- package/src/wallets/cosmos/getKeplrConnector.d.ts +0 -6
- package/src/wallets/cosmos/getKeplrConnector.js +0 -14
- package/src/wallets/cosmos/index.d.ts +0 -1
- package/src/wallets/cosmos/utils/indexDB.cjs +0 -97
- package/src/wallets/cosmos/utils/indexDB.d.ts +0 -18
- package/src/wallets/cosmos/utils/indexDB.js +0 -93
- package/src/wallets/cosmos/wcClient.cjs +0 -333
- package/src/wallets/cosmos/wcClient.d.ts +0 -104
- package/src/wallets/cosmos/wcClient.js +0 -325
- package/src/wallets/ethereum/BloctoEvm.cjs +0 -111
- package/src/wallets/ethereum/BloctoEvm.d.ts +0 -25
- package/src/wallets/ethereum/BloctoEvm.js +0 -105
- package/src/wallets/ethereum/EthWalletConnector.cjs +0 -191
- package/src/wallets/ethereum/EthWalletConnector.d.ts +0 -35
- package/src/wallets/ethereum/EthWalletConnector.js +0 -187
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.cjs +0 -63
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.d.ts +0 -12
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.js +0 -59
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/index.d.ts +0 -1
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.cjs +0 -62
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.d.ts +0 -11
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.js +0 -58
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/index.d.ts +0 -1
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.cjs +0 -102
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.d.ts +0 -33
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.js +0 -98
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/index.d.ts +0 -2
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.cjs +0 -55
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.d.ts +0 -12
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.js +0 -51
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/index.d.ts +0 -1
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.cjs +0 -175
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.d.ts +0 -53
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.js +0 -171
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/index.d.ts +0 -2
- package/src/wallets/ethereum/MagicConnector/index.d.ts +0 -5
- package/src/wallets/ethereum/coinbase.cjs +0 -65
- package/src/wallets/ethereum/coinbase.d.ts +0 -26
- package/src/wallets/ethereum/coinbase.js +0 -63
- package/src/wallets/ethereum/ethProviderHelper.cjs +0 -197
- package/src/wallets/ethereum/ethProviderHelper.d.ts +0 -40
- package/src/wallets/ethereum/ethProviderHelper.js +0 -193
- package/src/wallets/ethereum/evm-network.cjs +0 -20
- package/src/wallets/ethereum/evm-network.d.ts +0 -22
- package/src/wallets/ethereum/evm-network.js +0 -16
- package/src/wallets/ethereum/fortmatic.cjs +0 -75
- package/src/wallets/ethereum/fortmatic.d.ts +0 -26
- package/src/wallets/ethereum/fortmatic.js +0 -69
- package/src/wallets/ethereum/injected/BloctoInjected.cjs +0 -13
- package/src/wallets/ethereum/injected/BloctoInjected.d.ts +0 -6
- package/src/wallets/ethereum/injected/BloctoInjected.js +0 -11
- package/src/wallets/ethereum/injected/BraveEvm.cjs +0 -13
- package/src/wallets/ethereum/injected/BraveEvm.d.ts +0 -6
- package/src/wallets/ethereum/injected/BraveEvm.js +0 -11
- package/src/wallets/ethereum/injected/Dawn.cjs +0 -13
- package/src/wallets/ethereum/injected/Dawn.d.ts +0 -6
- package/src/wallets/ethereum/injected/Dawn.js +0 -11
- package/src/wallets/ethereum/injected/ExodusEvm.cjs +0 -13
- package/src/wallets/ethereum/injected/ExodusEvm.d.ts +0 -6
- package/src/wallets/ethereum/injected/ExodusEvm.js +0 -11
- package/src/wallets/ethereum/injected/Frame.cjs +0 -13
- package/src/wallets/ethereum/injected/Frame.d.ts +0 -6
- package/src/wallets/ethereum/injected/Frame.js +0 -11
- package/src/wallets/ethereum/injected/GameStop.cjs +0 -13
- package/src/wallets/ethereum/injected/GameStop.d.ts +0 -6
- package/src/wallets/ethereum/injected/GameStop.js +0 -11
- package/src/wallets/ethereum/injected/Opera.cjs +0 -13
- package/src/wallets/ethereum/injected/Opera.d.ts +0 -6
- package/src/wallets/ethereum/injected/Opera.js +0 -11
- package/src/wallets/ethereum/injected/PhantomEvm.cjs +0 -37
- package/src/wallets/ethereum/injected/PhantomEvm.d.ts +0 -7
- package/src/wallets/ethereum/injected/PhantomEvm.js +0 -35
- package/src/wallets/ethereum/injected/Trust.cjs +0 -13
- package/src/wallets/ethereum/injected/Trust.d.ts +0 -6
- package/src/wallets/ethereum/injected/Trust.js +0 -11
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.cjs +0 -13
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.d.ts +0 -6
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.js +0 -11
- package/src/wallets/ethereum/injected/Zerion.cjs +0 -13
- package/src/wallets/ethereum/injected/Zerion.d.ts +0 -6
- package/src/wallets/ethereum/injected/Zerion.js +0 -11
- package/src/wallets/ethereum/meta-mask.cjs +0 -63
- package/src/wallets/ethereum/meta-mask.d.ts +0 -26
- package/src/wallets/ethereum/meta-mask.js +0 -61
- package/src/wallets/flow/FlowWalletConnector.cjs +0 -163
- package/src/wallets/flow/FlowWalletConnector.d.ts +0 -29
- package/src/wallets/flow/FlowWalletConnector.js +0 -158
- package/src/wallets/flow/blocto.cjs +0 -22
- package/src/wallets/flow/blocto.d.ts +0 -7
- package/src/wallets/flow/blocto.js +0 -20
- package/src/wallets/flow/dapper.cjs +0 -22
- package/src/wallets/flow/dapper.d.ts +0 -7
- package/src/wallets/flow/dapper.js +0 -20
- package/src/wallets/flow/lilico.cjs +0 -42
- package/src/wallets/flow/lilico.d.ts +0 -8
- package/src/wallets/flow/lilico.js +0 -40
- package/src/wallets/getMobileOrInjectedWallet.cjs +0 -26
- package/src/wallets/getMobileOrInjectedWallet.d.ts +0 -8
- package/src/wallets/getMobileOrInjectedWallet.js +0 -22
- package/src/wallets/getWalletConnectConnector.cjs +0 -19
- package/src/wallets/getWalletConnectConnector.d.ts +0 -8
- package/src/wallets/getWalletConnectConnector.js +0 -15
- package/src/wallets/solana/CoinbaseSolana.cjs +0 -54
- package/src/wallets/solana/CoinbaseSolana.d.ts +0 -17
- package/src/wallets/solana/CoinbaseSolana.js +0 -52
- package/src/wallets/solana/glow.cjs +0 -51
- package/src/wallets/solana/glow.d.ts +0 -16
- package/src/wallets/solana/glow.js +0 -49
- package/src/wallets/solana/injected/BraveSol.cjs +0 -18
- package/src/wallets/solana/injected/BraveSol.d.ts +0 -6
- package/src/wallets/solana/injected/BraveSol.js +0 -16
- package/src/wallets/solana/injected/ExodusSol.cjs +0 -12
- package/src/wallets/solana/injected/ExodusSol.d.ts +0 -5
- package/src/wallets/solana/injected/ExodusSol.js +0 -10
- package/src/wallets/solana/phantom-ledger.cjs +0 -71
- package/src/wallets/solana/phantom-ledger.d.ts +0 -16
- package/src/wallets/solana/phantom-ledger.js +0 -65
- package/src/wallets/solana/phantom.cjs +0 -74
- package/src/wallets/solana/phantom.d.ts +0 -17
- package/src/wallets/solana/phantom.js +0 -72
- package/src/wallets/solana/slope.cjs +0 -96
- package/src/wallets/solana/slope.d.ts +0 -27
- package/src/wallets/solana/slope.js +0 -94
- package/src/wallets/solana/solProviderHelper.cjs +0 -164
- package/src/wallets/solana/solProviderHelper.d.ts +0 -29
- package/src/wallets/solana/solProviderHelper.js +0 -160
- package/src/wallets/solana/solWalletConnector.cjs +0 -57
- package/src/wallets/solana/solWalletConnector.d.ts +0 -18
- package/src/wallets/solana/solWalletConnector.js +0 -53
- package/src/wallets/solana/solflare.cjs +0 -65
- package/src/wallets/solana/solflare.d.ts +0 -14
- package/src/wallets/solana/solflare.js +0 -63
- package/src/wallets/starknet/argentx.cjs +0 -20
- package/src/wallets/starknet/argentx.d.ts +0 -7
- package/src/wallets/starknet/argentx.js +0 -18
- package/src/wallets/starknet/braavos.cjs +0 -33
- package/src/wallets/starknet/braavos.d.ts +0 -7
- package/src/wallets/starknet/braavos.js +0 -31
- package/src/wallets/starknet/ethereumContractAbi.cjs +0 -357
- package/src/wallets/starknet/ethereumContractAbi.js +0 -355
- package/src/wallets/starknet/starknetWalletConnector.cjs +0 -171
- package/src/wallets/starknet/starknetWalletConnector.d.ts +0 -34
- package/src/wallets/starknet/starknetWalletConnector.js +0 -169
- package/src/wallets/walletConnect/index.d.ts +0 -2
- package/src/wallets/walletConnect/walletConnect.cjs +0 -130
- package/src/wallets/walletConnect/walletConnect.d.ts +0 -34
- package/src/wallets/walletConnect/walletConnect.js +0 -124
- package/src/wallets/walletConnect/walletConnectV2.cjs +0 -268
- package/src/wallets/walletConnect/walletConnectV2.d.ts +0 -38
- package/src/wallets/walletConnect/walletConnectV2.js +0 -262
- package/src/wallets/walletConnect/zerion.d.ts +0 -8
- package/src/wallets/window.d.ts +0 -95
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
|
-
import { getInstalledWallets, disconnect } from 'get-starknet';
|
|
3
|
-
import { Contract } from 'starknet';
|
|
4
|
-
import { StarknetChainId } from 'starknet/constants.js';
|
|
5
|
-
import { uint256ToBN } from 'starknet/dist/utils/uint256.js';
|
|
6
|
-
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
7
|
-
import { DynamicError } from '../../errors.js';
|
|
8
|
-
import { logger } from '../../utils/logger.js';
|
|
9
|
-
import { formatTypedDataMessage } from '../../utils/convertors.js';
|
|
10
|
-
import { ETH_STARKNET_ADDRESS } from '../constants.js';
|
|
11
|
-
import ETH_CONTRACT_ABI from './ethereumContractAbi.js';
|
|
12
|
-
|
|
13
|
-
const ACCOUNT_CHANGED_EVENT_LISTENER = 'accountsChanged';
|
|
14
|
-
const NETWORK_CHANGED_EVENT_LISTENER = 'networkChanged';
|
|
15
|
-
class StarknetWalletConnector extends WalletConnectorBase {
|
|
16
|
-
constructor(name, windowKey) {
|
|
17
|
-
super();
|
|
18
|
-
this.connectedChain = 'STARK';
|
|
19
|
-
this.supportedChains = ['STARK'];
|
|
20
|
-
this.name = name;
|
|
21
|
-
this.windowKey = windowKey;
|
|
22
|
-
}
|
|
23
|
-
connect() {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const wallet = yield this.getWallet();
|
|
26
|
-
try {
|
|
27
|
-
if (wallet && !wallet.isConnected) {
|
|
28
|
-
yield wallet.enable({ showModal: false });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
logger.error(err);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
fetchPublicAddress() {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const wallet = yield this.getWallet();
|
|
39
|
-
yield this.connect();
|
|
40
|
-
return Promise.resolve(wallet === null || wallet === void 0 ? void 0 : wallet.selectedAddress);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
getSigner() {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const wallet = yield this.getWallet();
|
|
46
|
-
return wallet === null || wallet === void 0 ? void 0 : wallet.account;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
getWallet() {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
if (!this.wallet) {
|
|
52
|
-
const providers = yield getInstalledWallets();
|
|
53
|
-
this.wallet = providers.find((provider) => provider.name === this.name);
|
|
54
|
-
}
|
|
55
|
-
return this.wallet;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
getWeb3Provider() {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const wallet = yield this.getWallet();
|
|
61
|
-
return wallet === null || wallet === void 0 ? void 0 : wallet.provider;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
signMessage(messageToSign) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const wallet = yield this.getWallet();
|
|
67
|
-
const walletAddress = yield this.fetchPublicAddress();
|
|
68
|
-
if (!walletAddress || !wallet) {
|
|
69
|
-
logger.error('Could not fetch wallet address for signing message');
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
const { account } = wallet;
|
|
73
|
-
const chainId = account.chainId === StarknetChainId.TESTNET ? 'SN_GOERLI' : 'SN_MAIN';
|
|
74
|
-
const encodedMessage = formatTypedDataMessage(messageToSign, chainId);
|
|
75
|
-
const signature = yield (account === null || account === void 0 ? void 0 : account.signMessage(encodedMessage));
|
|
76
|
-
return signature === null || signature === void 0 ? void 0 : signature.join(',');
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
getBalance() {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const walletAddress = yield this.fetchPublicAddress();
|
|
82
|
-
const provider = yield this.getWeb3Provider();
|
|
83
|
-
if (!walletAddress || !provider) {
|
|
84
|
-
logger.error('Could not fetch wallet address for getting balance');
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
const contract = new Contract(ETH_CONTRACT_ABI, ETH_STARKNET_ADDRESS, provider);
|
|
88
|
-
try {
|
|
89
|
-
const { balance } = yield contract.balanceOf(walletAddress);
|
|
90
|
-
const gweiBalance = parseInt(uint256ToBN(balance).toString(10));
|
|
91
|
-
/**
|
|
92
|
-
* Dividing by 1e18 as the returned balance is a Gwei number.
|
|
93
|
-
* Read more here: https://www.investopedia.com/terms/g/gwei-ethereum.asp#toc-what-is-gwei
|
|
94
|
-
*/
|
|
95
|
-
return (gweiBalance / 1e18).toFixed(6);
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
throw new DynamicError('Something went wrong');
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
endSession() {
|
|
103
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
disconnect({
|
|
105
|
-
clearLastWallet: true,
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
getStarknetWindowObject() {
|
|
110
|
-
const starknetWindowInstance = window[`starknet_${this.windowKey}`] || window['starknet'];
|
|
111
|
-
if ((starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name) {
|
|
112
|
-
return starknetWindowInstance;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
isInstalledOnBrowser() {
|
|
119
|
-
var _a;
|
|
120
|
-
const starknetWindowInstance = (_a = window[`starknet_${this.windowKey}`]) !== null && _a !== void 0 ? _a : window['starknet'];
|
|
121
|
-
return (starknetWindowInstance === null || starknetWindowInstance === void 0 ? void 0 : starknetWindowInstance.name) === this.name;
|
|
122
|
-
}
|
|
123
|
-
getConnectedAccounts() {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
const wallet = yield this.getWallet();
|
|
126
|
-
return wallet ? [wallet.account.address] : [];
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
setupEventListeners(listeners) {
|
|
130
|
-
const wallet = this.getStarknetWindowObject();
|
|
131
|
-
this.handleAccountChange = (address) => __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
var _a, _b;
|
|
133
|
-
if (!address) {
|
|
134
|
-
yield ((_a = listeners.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(listeners));
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (address.toString()) {
|
|
138
|
-
yield ((_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, [address.toString()]));
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
this.handleNetworkChange = (network) => __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
var _c, _d;
|
|
143
|
-
if (!network) {
|
|
144
|
-
yield ((_c = listeners.onDisconnect) === null || _c === void 0 ? void 0 : _c.call(listeners));
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (network.toString()) {
|
|
148
|
-
yield ((_d = listeners.onChainChange) === null || _d === void 0 ? void 0 : _d.call(listeners, network.toString()));
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.on(ACCOUNT_CHANGED_EVENT_LISTENER, this.handleAccountChange);
|
|
152
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.on(NETWORK_CHANGED_EVENT_LISTENER, this.handleNetworkChange);
|
|
153
|
-
}
|
|
154
|
-
teardownEventListeners() {
|
|
155
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
const wallet = yield this.getWallet();
|
|
157
|
-
if (this.handleAccountChange) {
|
|
158
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.off(ACCOUNT_CHANGED_EVENT_LISTENER, this.handleAccountChange);
|
|
159
|
-
this.handleAccountChange = undefined;
|
|
160
|
-
}
|
|
161
|
-
if (this.handleNetworkChange) {
|
|
162
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.off(NETWORK_CHANGED_EVENT_LISTENER, this.handleNetworkChange);
|
|
163
|
-
this.handleNetworkChange = undefined;
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export { StarknetWalletConnector as default };
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var tslib = require('tslib');
|
|
4
|
-
var WalletConnectProvider = require('@walletconnect/ethereum-provider');
|
|
5
|
-
var ethers = require('ethers');
|
|
6
|
-
var walletBook = require('@dynamic-labs/wallet-book');
|
|
7
|
-
var constants = require('../constants.cjs');
|
|
8
|
-
var EthWalletConnector = require('../ethereum/EthWalletConnector.cjs');
|
|
9
|
-
var walletConnect = require('../clients/walletConnect/walletConnect.cjs');
|
|
10
|
-
var isMobile = require('../../utils/isMobile.cjs');
|
|
11
|
-
var normalizeWalletName = require('../../utils/normalizeWalletName/normalizeWalletName.cjs');
|
|
12
|
-
var errors = require('../../errors.cjs');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
-
|
|
16
|
-
var WalletConnectProvider__default = /*#__PURE__*/_interopDefaultLegacy(WalletConnectProvider);
|
|
17
|
-
|
|
18
|
-
class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
19
|
-
constructor({ walletName, evmNetworks, }) {
|
|
20
|
-
super({ evmNetworks });
|
|
21
|
-
this.supportedChains = ['EVM', 'ETH'];
|
|
22
|
-
this.connectedChain = 'EVM';
|
|
23
|
-
this.canConnectViaQrCode = true;
|
|
24
|
-
this.isWalletConnect = true;
|
|
25
|
-
this.switchNetworkOnlyFromWallet = false;
|
|
26
|
-
this.name = walletName;
|
|
27
|
-
}
|
|
28
|
-
getClient() {
|
|
29
|
-
if (this.client) {
|
|
30
|
-
return this.client;
|
|
31
|
-
}
|
|
32
|
-
this.client = walletConnect.initClient(normalizeWalletName.normalizeWalletName(this.name), this.clientOptions);
|
|
33
|
-
return this.client;
|
|
34
|
-
}
|
|
35
|
-
supportsNetworkSwitching() {
|
|
36
|
-
if (this.connectedChain === 'EVM') {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
const client = this.getClient();
|
|
41
|
-
return Boolean(client === null || client === void 0 ? void 0 : client.chainId);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
setupEventListeners(listeners) {
|
|
45
|
-
return walletConnect.setupWalletConnectEventListeners({
|
|
46
|
-
onAccountChange: listeners.onAccountChange,
|
|
47
|
-
onChainChange: listeners.onChainChange,
|
|
48
|
-
onDisconnect: listeners.onDisconnect,
|
|
49
|
-
}, this.getClient());
|
|
50
|
-
}
|
|
51
|
-
teardownEventListeners() {
|
|
52
|
-
walletConnect.teardownWalletConnectEventListeners(this.getClient());
|
|
53
|
-
}
|
|
54
|
-
getWeb3Provider() {
|
|
55
|
-
const client = this.getClient();
|
|
56
|
-
return client
|
|
57
|
-
? new ethers.ethers.providers.Web3Provider(new WalletConnectProvider__default["default"]({
|
|
58
|
-
connector: client,
|
|
59
|
-
infuraId: constants.infuraId,
|
|
60
|
-
rpc: this.evmNetworkRpcMap(),
|
|
61
|
-
}), 'any')
|
|
62
|
-
: undefined;
|
|
63
|
-
}
|
|
64
|
-
fetchPublicAddress(opts) {
|
|
65
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
return walletConnect.fetchWalletConnectEVMPublicAddress(walletBook.getWalletBookWallet(this.name), this.getClient(), Object.assign(Object.assign({}, opts), { onConnect: (payload) => {
|
|
67
|
-
var _a;
|
|
68
|
-
(_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
|
|
69
|
-
this.connectedChain = payload.params[0].chainId ? 'EVM' : 'SOL';
|
|
70
|
-
} }));
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
getDeepLink() {
|
|
74
|
-
var _a;
|
|
75
|
-
const wallet = walletBook.getWalletBookWallet(this.name);
|
|
76
|
-
if (!isMobile.isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
return walletConnect.getDeepLink(this.getClient().uri, wallet, {
|
|
80
|
-
removeWCUri: isMobile.isIOS() && normalizeWalletName.normalizeWalletName(this.name) === 'cryptocom',
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
signMessage(messageToSign) {
|
|
84
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
return walletConnect.signWalletConnectPersonalMessage(messageToSign, walletBook.getWalletBookWallet(this.name), this.getClient());
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
endSession() {
|
|
89
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
walletConnect.killWalletConnectSession(this.getClient());
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
providerSwitchNetwork({ network, provider, }) {
|
|
94
|
-
const _super = Object.create(null, {
|
|
95
|
-
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
96
|
-
});
|
|
97
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const client = this.getClient();
|
|
99
|
-
const currentNetworkId = yield this.getNetwork();
|
|
100
|
-
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (this.switchNetworkOnlyFromWallet !== undefined &&
|
|
104
|
-
this.switchNetworkOnlyFromWallet) {
|
|
105
|
-
throw new errors.DynamicError('Network switching is only supported through the wallet');
|
|
106
|
-
}
|
|
107
|
-
if (!this.supportsNetworkSwitching()) {
|
|
108
|
-
throw new errors.DynamicError('Network switching not supported');
|
|
109
|
-
}
|
|
110
|
-
if (!client) {
|
|
111
|
-
throw new errors.DynamicError('Client not found');
|
|
112
|
-
}
|
|
113
|
-
if (isMobile.isMobile()) {
|
|
114
|
-
const deepLink = walletConnect.getDeepLink(client.uri, walletBook.getWalletBookWallet(this.name));
|
|
115
|
-
window.location.href = deepLink;
|
|
116
|
-
}
|
|
117
|
-
return _super.providerSwitchNetwork.call(this, { network, provider });
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
getConnectedAccounts() {
|
|
121
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
const client = this.getClient();
|
|
123
|
-
if (!client.connected)
|
|
124
|
-
return [];
|
|
125
|
-
return client.accounts;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
module.exports = WalletConnect;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import Client from '@walletconnect/client';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
import { Chain, FetchPublicAddressOpts, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { EthWalletConnector } from '../ethereum/EthWalletConnector';
|
|
5
|
-
import { EvmNetwork } from '../ethereum/evm-network';
|
|
6
|
-
declare class WalletConnect extends EthWalletConnector {
|
|
7
|
-
supportedChains: Chain[];
|
|
8
|
-
connectedChain: Chain;
|
|
9
|
-
name: string;
|
|
10
|
-
canConnectViaQrCode: boolean;
|
|
11
|
-
isWalletConnect: boolean;
|
|
12
|
-
switchNetworkOnlyFromWallet: boolean;
|
|
13
|
-
client?: Client;
|
|
14
|
-
clientOptions?: any;
|
|
15
|
-
constructor({ walletName, evmNetworks, }: {
|
|
16
|
-
evmNetworks: EvmNetwork[];
|
|
17
|
-
walletName: string;
|
|
18
|
-
});
|
|
19
|
-
getClient(): Client;
|
|
20
|
-
supportsNetworkSwitching(): boolean;
|
|
21
|
-
setupEventListeners(listeners: WalletEventListeners): () => void;
|
|
22
|
-
teardownEventListeners(): void;
|
|
23
|
-
getWeb3Provider(): ethers.providers.Web3Provider | undefined;
|
|
24
|
-
fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
|
|
25
|
-
getDeepLink(): string | undefined;
|
|
26
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
27
|
-
endSession(): Promise<void>;
|
|
28
|
-
providerSwitchNetwork({ network, provider, }: {
|
|
29
|
-
network: EvmNetwork;
|
|
30
|
-
provider: ethers.providers.Web3Provider;
|
|
31
|
-
}): Promise<void>;
|
|
32
|
-
getConnectedAccounts(): Promise<string[]>;
|
|
33
|
-
}
|
|
34
|
-
export default WalletConnect;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
|
-
import WalletConnectProvider from '@walletconnect/ethereum-provider';
|
|
3
|
-
import { ethers } from 'ethers';
|
|
4
|
-
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
|
-
import { infuraId } from '../constants.js';
|
|
6
|
-
import { EthWalletConnector } from '../ethereum/EthWalletConnector.js';
|
|
7
|
-
import { initClient, setupWalletConnectEventListeners, teardownWalletConnectEventListeners, fetchWalletConnectEVMPublicAddress, getDeepLink, signWalletConnectPersonalMessage, killWalletConnectSession } from '../clients/walletConnect/walletConnect.js';
|
|
8
|
-
import { isMobile, isIOS } from '../../utils/isMobile.js';
|
|
9
|
-
import { normalizeWalletName } from '../../utils/normalizeWalletName/normalizeWalletName.js';
|
|
10
|
-
import { DynamicError } from '../../errors.js';
|
|
11
|
-
|
|
12
|
-
class WalletConnect extends EthWalletConnector {
|
|
13
|
-
constructor({ walletName, evmNetworks, }) {
|
|
14
|
-
super({ evmNetworks });
|
|
15
|
-
this.supportedChains = ['EVM', 'ETH'];
|
|
16
|
-
this.connectedChain = 'EVM';
|
|
17
|
-
this.canConnectViaQrCode = true;
|
|
18
|
-
this.isWalletConnect = true;
|
|
19
|
-
this.switchNetworkOnlyFromWallet = false;
|
|
20
|
-
this.name = walletName;
|
|
21
|
-
}
|
|
22
|
-
getClient() {
|
|
23
|
-
if (this.client) {
|
|
24
|
-
return this.client;
|
|
25
|
-
}
|
|
26
|
-
this.client = initClient(normalizeWalletName(this.name), this.clientOptions);
|
|
27
|
-
return this.client;
|
|
28
|
-
}
|
|
29
|
-
supportsNetworkSwitching() {
|
|
30
|
-
if (this.connectedChain === 'EVM') {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
const client = this.getClient();
|
|
35
|
-
return Boolean(client === null || client === void 0 ? void 0 : client.chainId);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
setupEventListeners(listeners) {
|
|
39
|
-
return setupWalletConnectEventListeners({
|
|
40
|
-
onAccountChange: listeners.onAccountChange,
|
|
41
|
-
onChainChange: listeners.onChainChange,
|
|
42
|
-
onDisconnect: listeners.onDisconnect,
|
|
43
|
-
}, this.getClient());
|
|
44
|
-
}
|
|
45
|
-
teardownEventListeners() {
|
|
46
|
-
teardownWalletConnectEventListeners(this.getClient());
|
|
47
|
-
}
|
|
48
|
-
getWeb3Provider() {
|
|
49
|
-
const client = this.getClient();
|
|
50
|
-
return client
|
|
51
|
-
? new ethers.providers.Web3Provider(new WalletConnectProvider({
|
|
52
|
-
connector: client,
|
|
53
|
-
infuraId,
|
|
54
|
-
rpc: this.evmNetworkRpcMap(),
|
|
55
|
-
}), 'any')
|
|
56
|
-
: undefined;
|
|
57
|
-
}
|
|
58
|
-
fetchPublicAddress(opts) {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
return fetchWalletConnectEVMPublicAddress(getWalletBookWallet(this.name), this.getClient(), Object.assign(Object.assign({}, opts), { onConnect: (payload) => {
|
|
61
|
-
var _a;
|
|
62
|
-
(_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
|
|
63
|
-
this.connectedChain = payload.params[0].chainId ? 'EVM' : 'SOL';
|
|
64
|
-
} }));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
getDeepLink() {
|
|
68
|
-
var _a;
|
|
69
|
-
const wallet = getWalletBookWallet(this.name);
|
|
70
|
-
if (!isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
return getDeepLink(this.getClient().uri, wallet, {
|
|
74
|
-
removeWCUri: isIOS() && normalizeWalletName(this.name) === 'cryptocom',
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
signMessage(messageToSign) {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
return signWalletConnectPersonalMessage(messageToSign, getWalletBookWallet(this.name), this.getClient());
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
endSession() {
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
killWalletConnectSession(this.getClient());
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
providerSwitchNetwork({ network, provider, }) {
|
|
88
|
-
const _super = Object.create(null, {
|
|
89
|
-
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
90
|
-
});
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
const client = this.getClient();
|
|
93
|
-
const currentNetworkId = yield this.getNetwork();
|
|
94
|
-
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (this.switchNetworkOnlyFromWallet !== undefined &&
|
|
98
|
-
this.switchNetworkOnlyFromWallet) {
|
|
99
|
-
throw new DynamicError('Network switching is only supported through the wallet');
|
|
100
|
-
}
|
|
101
|
-
if (!this.supportsNetworkSwitching()) {
|
|
102
|
-
throw new DynamicError('Network switching not supported');
|
|
103
|
-
}
|
|
104
|
-
if (!client) {
|
|
105
|
-
throw new DynamicError('Client not found');
|
|
106
|
-
}
|
|
107
|
-
if (isMobile()) {
|
|
108
|
-
const deepLink = getDeepLink(client.uri, getWalletBookWallet(this.name));
|
|
109
|
-
window.location.href = deepLink;
|
|
110
|
-
}
|
|
111
|
-
return _super.providerSwitchNetwork.call(this, { network, provider });
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
getConnectedAccounts() {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
const client = this.getClient();
|
|
117
|
-
if (!client.connected)
|
|
118
|
-
return [];
|
|
119
|
-
return client.accounts;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export { WalletConnect as default };
|