@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,268 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var tslib = require('tslib');
|
|
4
|
-
var Provider = require('@walletconnect/universal-provider');
|
|
5
|
-
var ethers = require('ethers');
|
|
6
|
-
var walletBook = require('@dynamic-labs/wallet-book');
|
|
7
|
-
var EthWalletConnector = require('../ethereum/EthWalletConnector.cjs');
|
|
8
|
-
var isMobile = require('../../utils/isMobile.cjs');
|
|
9
|
-
var walletConnect = require('../clients/walletConnect/walletConnect.cjs');
|
|
10
|
-
var errors = require('../../errors.cjs');
|
|
11
|
-
var logger = require('../../utils/logger.cjs');
|
|
12
|
-
var encoding = require('../../utils/encoding.cjs');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
-
|
|
16
|
-
var Provider__default = /*#__PURE__*/_interopDefaultLegacy(Provider);
|
|
17
|
-
|
|
18
|
-
const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
|
|
19
|
-
var _a, _b, _c;
|
|
20
|
-
if (isMobile.isMobile()) {
|
|
21
|
-
const deepLink = walletConnect.getDeepLink(uri, metadata);
|
|
22
|
-
window.location.href = deepLink;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
|
|
26
|
-
const desktopUri = walletConnect.getDeepLink(uri, metadata);
|
|
27
|
-
(_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, desktopUri);
|
|
28
|
-
}
|
|
29
|
-
(_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, uri);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
|
|
33
|
-
class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
34
|
-
constructor(opts) {
|
|
35
|
-
super({ evmNetworks: opts.evmNetworks });
|
|
36
|
-
this.supportedChains = ['EVM', 'ETH'];
|
|
37
|
-
this.connectedChain = 'EVM';
|
|
38
|
-
this.canConnectViaQrCode = true;
|
|
39
|
-
this.isWalletConnect = true;
|
|
40
|
-
this.name = opts.walletName;
|
|
41
|
-
this.projectId = opts.projectId;
|
|
42
|
-
}
|
|
43
|
-
initProvider() {
|
|
44
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
if (this.projectId && !WalletConnectV2.provider) {
|
|
46
|
-
WalletConnectV2.provider = yield Provider__default["default"].init({
|
|
47
|
-
projectId: this.projectId,
|
|
48
|
-
});
|
|
49
|
-
const connection = yield WalletConnectV2.provider.client.connect({
|
|
50
|
-
requiredNamespaces: {
|
|
51
|
-
eip155: {
|
|
52
|
-
chains: this.evmNetworks
|
|
53
|
-
// filtering out Palm for now since it causes Trust to crash
|
|
54
|
-
.filter((network) => network.chainId !== 11297108109)
|
|
55
|
-
.map((network) => `eip155:${network.chainId}`),
|
|
56
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
57
|
-
methods: [
|
|
58
|
-
'eth_sendTransaction',
|
|
59
|
-
'eth_signTransaction',
|
|
60
|
-
'eth_sign',
|
|
61
|
-
'personal_sign',
|
|
62
|
-
'eth_signTypedData',
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
// eslint-disable-next-line prefer-destructuring
|
|
68
|
-
WalletConnectV2.provider.uri = connection.uri;
|
|
69
|
-
WalletConnectV2.createSession = connection.approval;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
init() {
|
|
74
|
-
var _a, _b, _c, _d;
|
|
75
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
yield this.initProvider();
|
|
77
|
-
if ((_b = (_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.topic) {
|
|
78
|
-
if (localStorage.getItem(this.sessionTopicKey) ===
|
|
79
|
-
((_d = (_c = WalletConnectV2.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
|
|
80
|
-
this.session = WalletConnectV2.provider.session;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
get sessionTopicKey() {
|
|
86
|
-
return sessionTopicKey(this.key);
|
|
87
|
-
}
|
|
88
|
-
supportsNetworkSwitching() {
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
setupEventListeners(listeners) {
|
|
92
|
-
if (!WalletConnectV2.provider) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
WalletConnectV2.provider.client.on('session_event', ({ params }) => {
|
|
96
|
-
var _a, _b;
|
|
97
|
-
if (!params || !params.event) {
|
|
98
|
-
logger.logger.debug('session_event was called without params or params.event');
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const { name, data } = params.event;
|
|
102
|
-
if (name === 'chainChanged') {
|
|
103
|
-
if (typeof data !== 'string') {
|
|
104
|
-
logger.logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
(_a = listeners.onChainChange) === null || _a === void 0 ? void 0 : _a.call(listeners, data);
|
|
108
|
-
}
|
|
109
|
-
else if (name === 'accountsChanged') {
|
|
110
|
-
if (typeof data !== 'string' || !Array.isArray(data)) {
|
|
111
|
-
logger.logger.debug(`received unexpected data for accountsChanged: ${data} with type ${typeof data}}`);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
(_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, data);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
WalletConnectV2.provider.client.on('session_delete', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
var _a;
|
|
119
|
-
localStorage.removeItem(this.sessionTopicKey);
|
|
120
|
-
yield ((_a = listeners.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(listeners));
|
|
121
|
-
}));
|
|
122
|
-
}
|
|
123
|
-
teardownEventListeners() {
|
|
124
|
-
if (!WalletConnectV2.provider) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
WalletConnectV2.provider.client.removeAllListeners('session_event');
|
|
128
|
-
WalletConnectV2.provider.client.removeAllListeners('session_delete');
|
|
129
|
-
}
|
|
130
|
-
getDeepLink() {
|
|
131
|
-
var _a, _b;
|
|
132
|
-
if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.uri))
|
|
133
|
-
return;
|
|
134
|
-
const wallet = walletBook.getWalletBookWallet(this.name);
|
|
135
|
-
if (!isMobile.isMobile() && !((_b = wallet.desktop) === null || _b === void 0 ? void 0 : _b.native)) {
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
|
-
return walletConnect.getDeepLink(WalletConnectV2.provider.uri, wallet);
|
|
139
|
-
}
|
|
140
|
-
getWeb3Provider() {
|
|
141
|
-
if (!WalletConnectV2.provider) {
|
|
142
|
-
throw new Error('No provider found');
|
|
143
|
-
}
|
|
144
|
-
return new ethers.ethers.providers.Web3Provider(WalletConnectV2.provider, 'any');
|
|
145
|
-
}
|
|
146
|
-
fetchPublicAddress(opts) {
|
|
147
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
if (this.session) {
|
|
149
|
-
return this.session.namespaces.eip155.accounts[0].split(':')[2];
|
|
150
|
-
}
|
|
151
|
-
const metadata = walletBook.getWalletBookWallet(this.name);
|
|
152
|
-
if (!WalletConnectV2.provider) {
|
|
153
|
-
throw new errors.DynamicError('No provider found');
|
|
154
|
-
}
|
|
155
|
-
if (!WalletConnectV2.provider.uri || !WalletConnectV2.createSession) {
|
|
156
|
-
throw new errors.DynamicError('No uri or approval found');
|
|
157
|
-
}
|
|
158
|
-
performPlatformSpecificConnectionMethod(WalletConnectV2.provider.uri, metadata, {
|
|
159
|
-
onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
|
|
160
|
-
onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
|
|
161
|
-
});
|
|
162
|
-
const session = yield WalletConnectV2.createSession();
|
|
163
|
-
if (!session) {
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
this.session = session;
|
|
167
|
-
localStorage.setItem(this.sessionTopicKey, session.topic);
|
|
168
|
-
// need to "reconnect" the provider so that we can tell it what the rpc urls are
|
|
169
|
-
yield WalletConnectV2.provider.connect({
|
|
170
|
-
namespaces: {
|
|
171
|
-
eip155: {
|
|
172
|
-
chains: this.evmNetworks
|
|
173
|
-
// filtering out Palm for now since it causes Trust to crash
|
|
174
|
-
.filter((network) => network.chainId !== 11297108109)
|
|
175
|
-
.map((network) => `eip155:${network.chainId}`),
|
|
176
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
177
|
-
methods: [
|
|
178
|
-
'eth_sendTransaction',
|
|
179
|
-
'eth_signTransaction',
|
|
180
|
-
'eth_sign',
|
|
181
|
-
'personal_sign',
|
|
182
|
-
'eth_signTypedData',
|
|
183
|
-
],
|
|
184
|
-
rpcMap: this.evmNetworkRpcMap(),
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
skipPairing: true,
|
|
188
|
-
});
|
|
189
|
-
// THIS LINE IS SUPER IMPORTANT
|
|
190
|
-
// since we are skipping pairing, (see: skipPairing: true above), we need to manually set the session
|
|
191
|
-
// so that future provider requests work (like getNetwork)
|
|
192
|
-
WalletConnectV2.provider.session = session;
|
|
193
|
-
return session.namespaces.eip155.accounts[0].split(':')[2];
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
signMessage(messageToSign) {
|
|
197
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
if (!this.session) {
|
|
199
|
-
throw new errors.DynamicError('no session');
|
|
200
|
-
}
|
|
201
|
-
if (!WalletConnectV2.provider) {
|
|
202
|
-
throw new errors.DynamicError('No WalletConnect provider found to handle signing');
|
|
203
|
-
}
|
|
204
|
-
const metadata = walletBook.getWalletBookWallet(this.name);
|
|
205
|
-
if (isMobile.isMobile()) {
|
|
206
|
-
// for sign message, no uri is needed because the uri encodes connection details,
|
|
207
|
-
// and at this point we are already connected
|
|
208
|
-
const deepLink = walletConnect.getDeepLink('', metadata);
|
|
209
|
-
window.location.href = deepLink;
|
|
210
|
-
}
|
|
211
|
-
// eslint-disable-next-line prefer-destructuring
|
|
212
|
-
const address = this.session.namespaces.eip155.accounts[0].split(':')[2];
|
|
213
|
-
const web3Provider = this.getWeb3Provider();
|
|
214
|
-
return web3Provider.send('personal_sign', [
|
|
215
|
-
encoding.utf8ToHex(messageToSign, true),
|
|
216
|
-
address,
|
|
217
|
-
]);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
endSession() {
|
|
221
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
222
|
-
if (!this.session) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
if (!WalletConnectV2.provider) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
try {
|
|
229
|
-
yield WalletConnectV2.provider.disconnect();
|
|
230
|
-
localStorage.removeItem(this.sessionTopicKey);
|
|
231
|
-
}
|
|
232
|
-
catch (e) {
|
|
233
|
-
logger.logger.debug(e);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
providerSwitchNetwork({ network, provider, }) {
|
|
238
|
-
const _super = Object.create(null, {
|
|
239
|
-
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
240
|
-
});
|
|
241
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
242
|
-
const currentNetworkId = yield this.getNetwork();
|
|
243
|
-
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (this.switchNetworkOnlyFromWallet) {
|
|
247
|
-
throw new errors.DynamicError('Network switching is only supported through the wallet');
|
|
248
|
-
}
|
|
249
|
-
if (!this.supportsNetworkSwitching()) {
|
|
250
|
-
throw new errors.DynamicError('Network switching not supported');
|
|
251
|
-
}
|
|
252
|
-
if (!provider) {
|
|
253
|
-
throw new errors.DynamicError('Provider not found');
|
|
254
|
-
}
|
|
255
|
-
return _super.providerSwitchNetwork.call(this, { network, provider });
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
getConnectedAccounts() {
|
|
259
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
260
|
-
if (!this.session) {
|
|
261
|
-
return [];
|
|
262
|
-
}
|
|
263
|
-
return [this.session.namespaces.eip155.accounts[0].split(':')[2]];
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
module.exports = WalletConnectV2;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import type { SessionTypes } from '@walletconnect/types';
|
|
3
|
-
import { Chain, FetchPublicAddressOpts, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { EvmNetwork } from '../ethereum/evm-network';
|
|
5
|
-
import { EthWalletConnector } from '../ethereum/EthWalletConnector';
|
|
6
|
-
declare class WalletConnectV2 extends EthWalletConnector {
|
|
7
|
-
supportedChains: Chain[];
|
|
8
|
-
connectedChain: Chain;
|
|
9
|
-
name: string;
|
|
10
|
-
session: SessionTypes.Struct | undefined;
|
|
11
|
-
canConnectViaQrCode: boolean;
|
|
12
|
-
isWalletConnect: boolean;
|
|
13
|
-
private static provider;
|
|
14
|
-
private static createSession;
|
|
15
|
-
private projectId?;
|
|
16
|
-
constructor(opts: {
|
|
17
|
-
evmNetworks: EvmNetwork[];
|
|
18
|
-
projectId?: string;
|
|
19
|
-
walletName: string;
|
|
20
|
-
});
|
|
21
|
-
private initProvider;
|
|
22
|
-
init(): Promise<void>;
|
|
23
|
-
get sessionTopicKey(): string;
|
|
24
|
-
supportsNetworkSwitching(): boolean;
|
|
25
|
-
setupEventListeners(listeners: WalletEventListeners): void;
|
|
26
|
-
teardownEventListeners(): void;
|
|
27
|
-
getDeepLink(): string | undefined;
|
|
28
|
-
getWeb3Provider(): ethers.providers.Web3Provider;
|
|
29
|
-
fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
|
|
30
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
31
|
-
endSession(): Promise<void>;
|
|
32
|
-
providerSwitchNetwork({ network, provider, }: {
|
|
33
|
-
network: EvmNetwork;
|
|
34
|
-
provider: ethers.providers.Web3Provider;
|
|
35
|
-
}): Promise<void>;
|
|
36
|
-
getConnectedAccounts(): Promise<string[]>;
|
|
37
|
-
}
|
|
38
|
-
export default WalletConnectV2;
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
|
-
import Provider from '@walletconnect/universal-provider';
|
|
3
|
-
import { ethers } from 'ethers';
|
|
4
|
-
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
|
-
import { EthWalletConnector } from '../ethereum/EthWalletConnector.js';
|
|
6
|
-
import { isMobile } from '../../utils/isMobile.js';
|
|
7
|
-
import { getDeepLink } from '../clients/walletConnect/walletConnect.js';
|
|
8
|
-
import { DynamicError } from '../../errors.js';
|
|
9
|
-
import { logger } from '../../utils/logger.js';
|
|
10
|
-
import { utf8ToHex } from '../../utils/encoding.js';
|
|
11
|
-
|
|
12
|
-
const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
|
|
13
|
-
var _a, _b, _c;
|
|
14
|
-
if (isMobile()) {
|
|
15
|
-
const deepLink = getDeepLink(uri, metadata);
|
|
16
|
-
window.location.href = deepLink;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
|
|
20
|
-
const desktopUri = getDeepLink(uri, metadata);
|
|
21
|
-
(_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, desktopUri);
|
|
22
|
-
}
|
|
23
|
-
(_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, uri);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
|
|
27
|
-
class WalletConnectV2 extends EthWalletConnector {
|
|
28
|
-
constructor(opts) {
|
|
29
|
-
super({ evmNetworks: opts.evmNetworks });
|
|
30
|
-
this.supportedChains = ['EVM', 'ETH'];
|
|
31
|
-
this.connectedChain = 'EVM';
|
|
32
|
-
this.canConnectViaQrCode = true;
|
|
33
|
-
this.isWalletConnect = true;
|
|
34
|
-
this.name = opts.walletName;
|
|
35
|
-
this.projectId = opts.projectId;
|
|
36
|
-
}
|
|
37
|
-
initProvider() {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
if (this.projectId && !WalletConnectV2.provider) {
|
|
40
|
-
WalletConnectV2.provider = yield Provider.init({
|
|
41
|
-
projectId: this.projectId,
|
|
42
|
-
});
|
|
43
|
-
const connection = yield WalletConnectV2.provider.client.connect({
|
|
44
|
-
requiredNamespaces: {
|
|
45
|
-
eip155: {
|
|
46
|
-
chains: this.evmNetworks
|
|
47
|
-
// filtering out Palm for now since it causes Trust to crash
|
|
48
|
-
.filter((network) => network.chainId !== 11297108109)
|
|
49
|
-
.map((network) => `eip155:${network.chainId}`),
|
|
50
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
51
|
-
methods: [
|
|
52
|
-
'eth_sendTransaction',
|
|
53
|
-
'eth_signTransaction',
|
|
54
|
-
'eth_sign',
|
|
55
|
-
'personal_sign',
|
|
56
|
-
'eth_signTypedData',
|
|
57
|
-
],
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
// eslint-disable-next-line prefer-destructuring
|
|
62
|
-
WalletConnectV2.provider.uri = connection.uri;
|
|
63
|
-
WalletConnectV2.createSession = connection.approval;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
init() {
|
|
68
|
-
var _a, _b, _c, _d;
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
yield this.initProvider();
|
|
71
|
-
if ((_b = (_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.topic) {
|
|
72
|
-
if (localStorage.getItem(this.sessionTopicKey) ===
|
|
73
|
-
((_d = (_c = WalletConnectV2.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
|
|
74
|
-
this.session = WalletConnectV2.provider.session;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
get sessionTopicKey() {
|
|
80
|
-
return sessionTopicKey(this.key);
|
|
81
|
-
}
|
|
82
|
-
supportsNetworkSwitching() {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
setupEventListeners(listeners) {
|
|
86
|
-
if (!WalletConnectV2.provider) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
WalletConnectV2.provider.client.on('session_event', ({ params }) => {
|
|
90
|
-
var _a, _b;
|
|
91
|
-
if (!params || !params.event) {
|
|
92
|
-
logger.debug('session_event was called without params or params.event');
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const { name, data } = params.event;
|
|
96
|
-
if (name === 'chainChanged') {
|
|
97
|
-
if (typeof data !== 'string') {
|
|
98
|
-
logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
(_a = listeners.onChainChange) === null || _a === void 0 ? void 0 : _a.call(listeners, data);
|
|
102
|
-
}
|
|
103
|
-
else if (name === 'accountsChanged') {
|
|
104
|
-
if (typeof data !== 'string' || !Array.isArray(data)) {
|
|
105
|
-
logger.debug(`received unexpected data for accountsChanged: ${data} with type ${typeof data}}`);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
(_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, data);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
WalletConnectV2.provider.client.on('session_delete', () => __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
var _a;
|
|
113
|
-
localStorage.removeItem(this.sessionTopicKey);
|
|
114
|
-
yield ((_a = listeners.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(listeners));
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
teardownEventListeners() {
|
|
118
|
-
if (!WalletConnectV2.provider) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
WalletConnectV2.provider.client.removeAllListeners('session_event');
|
|
122
|
-
WalletConnectV2.provider.client.removeAllListeners('session_delete');
|
|
123
|
-
}
|
|
124
|
-
getDeepLink() {
|
|
125
|
-
var _a, _b;
|
|
126
|
-
if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.uri))
|
|
127
|
-
return;
|
|
128
|
-
const wallet = getWalletBookWallet(this.name);
|
|
129
|
-
if (!isMobile() && !((_b = wallet.desktop) === null || _b === void 0 ? void 0 : _b.native)) {
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
return getDeepLink(WalletConnectV2.provider.uri, wallet);
|
|
133
|
-
}
|
|
134
|
-
getWeb3Provider() {
|
|
135
|
-
if (!WalletConnectV2.provider) {
|
|
136
|
-
throw new Error('No provider found');
|
|
137
|
-
}
|
|
138
|
-
return new ethers.providers.Web3Provider(WalletConnectV2.provider, 'any');
|
|
139
|
-
}
|
|
140
|
-
fetchPublicAddress(opts) {
|
|
141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
if (this.session) {
|
|
143
|
-
return this.session.namespaces.eip155.accounts[0].split(':')[2];
|
|
144
|
-
}
|
|
145
|
-
const metadata = getWalletBookWallet(this.name);
|
|
146
|
-
if (!WalletConnectV2.provider) {
|
|
147
|
-
throw new DynamicError('No provider found');
|
|
148
|
-
}
|
|
149
|
-
if (!WalletConnectV2.provider.uri || !WalletConnectV2.createSession) {
|
|
150
|
-
throw new DynamicError('No uri or approval found');
|
|
151
|
-
}
|
|
152
|
-
performPlatformSpecificConnectionMethod(WalletConnectV2.provider.uri, metadata, {
|
|
153
|
-
onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
|
|
154
|
-
onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
|
|
155
|
-
});
|
|
156
|
-
const session = yield WalletConnectV2.createSession();
|
|
157
|
-
if (!session) {
|
|
158
|
-
return undefined;
|
|
159
|
-
}
|
|
160
|
-
this.session = session;
|
|
161
|
-
localStorage.setItem(this.sessionTopicKey, session.topic);
|
|
162
|
-
// need to "reconnect" the provider so that we can tell it what the rpc urls are
|
|
163
|
-
yield WalletConnectV2.provider.connect({
|
|
164
|
-
namespaces: {
|
|
165
|
-
eip155: {
|
|
166
|
-
chains: this.evmNetworks
|
|
167
|
-
// filtering out Palm for now since it causes Trust to crash
|
|
168
|
-
.filter((network) => network.chainId !== 11297108109)
|
|
169
|
-
.map((network) => `eip155:${network.chainId}`),
|
|
170
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
171
|
-
methods: [
|
|
172
|
-
'eth_sendTransaction',
|
|
173
|
-
'eth_signTransaction',
|
|
174
|
-
'eth_sign',
|
|
175
|
-
'personal_sign',
|
|
176
|
-
'eth_signTypedData',
|
|
177
|
-
],
|
|
178
|
-
rpcMap: this.evmNetworkRpcMap(),
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
skipPairing: true,
|
|
182
|
-
});
|
|
183
|
-
// THIS LINE IS SUPER IMPORTANT
|
|
184
|
-
// since we are skipping pairing, (see: skipPairing: true above), we need to manually set the session
|
|
185
|
-
// so that future provider requests work (like getNetwork)
|
|
186
|
-
WalletConnectV2.provider.session = session;
|
|
187
|
-
return session.namespaces.eip155.accounts[0].split(':')[2];
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
signMessage(messageToSign) {
|
|
191
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
if (!this.session) {
|
|
193
|
-
throw new DynamicError('no session');
|
|
194
|
-
}
|
|
195
|
-
if (!WalletConnectV2.provider) {
|
|
196
|
-
throw new DynamicError('No WalletConnect provider found to handle signing');
|
|
197
|
-
}
|
|
198
|
-
const metadata = getWalletBookWallet(this.name);
|
|
199
|
-
if (isMobile()) {
|
|
200
|
-
// for sign message, no uri is needed because the uri encodes connection details,
|
|
201
|
-
// and at this point we are already connected
|
|
202
|
-
const deepLink = getDeepLink('', metadata);
|
|
203
|
-
window.location.href = deepLink;
|
|
204
|
-
}
|
|
205
|
-
// eslint-disable-next-line prefer-destructuring
|
|
206
|
-
const address = this.session.namespaces.eip155.accounts[0].split(':')[2];
|
|
207
|
-
const web3Provider = this.getWeb3Provider();
|
|
208
|
-
return web3Provider.send('personal_sign', [
|
|
209
|
-
utf8ToHex(messageToSign, true),
|
|
210
|
-
address,
|
|
211
|
-
]);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
endSession() {
|
|
215
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
if (!this.session) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (!WalletConnectV2.provider) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
yield WalletConnectV2.provider.disconnect();
|
|
224
|
-
localStorage.removeItem(this.sessionTopicKey);
|
|
225
|
-
}
|
|
226
|
-
catch (e) {
|
|
227
|
-
logger.debug(e);
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
providerSwitchNetwork({ network, provider, }) {
|
|
232
|
-
const _super = Object.create(null, {
|
|
233
|
-
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
234
|
-
});
|
|
235
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
-
const currentNetworkId = yield this.getNetwork();
|
|
237
|
-
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if (this.switchNetworkOnlyFromWallet) {
|
|
241
|
-
throw new DynamicError('Network switching is only supported through the wallet');
|
|
242
|
-
}
|
|
243
|
-
if (!this.supportsNetworkSwitching()) {
|
|
244
|
-
throw new DynamicError('Network switching not supported');
|
|
245
|
-
}
|
|
246
|
-
if (!provider) {
|
|
247
|
-
throw new DynamicError('Provider not found');
|
|
248
|
-
}
|
|
249
|
-
return _super.providerSwitchNetwork.call(this, { network, provider });
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
getConnectedAccounts() {
|
|
253
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
if (!this.session) {
|
|
255
|
-
return [];
|
|
256
|
-
}
|
|
257
|
-
return [this.session.namespaces.eip155.accounts[0].split(':')[2]];
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export { WalletConnectV2 as default };
|
package/src/wallets/window.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is super hacky, but:
|
|
3
|
-
*
|
|
4
|
-
* Most ethereum wallet extensions populate window.ethereum.
|
|
5
|
-
* Coinbase adds itself to window.coinbaseWalletExtension
|
|
6
|
-
* and also provider and previousProvider
|
|
7
|
-
*/
|
|
8
|
-
import { Transaction } from '@solana/web3.js';
|
|
9
|
-
import { IStarknetWindowObject } from 'get-starknet';
|
|
10
|
-
export interface IProvider {
|
|
11
|
-
isBlocto?: boolean;
|
|
12
|
-
isBraveWallet?: boolean;
|
|
13
|
-
isCoinbaseWallet?: boolean;
|
|
14
|
-
isDawn?: boolean;
|
|
15
|
-
isExodus?: boolean;
|
|
16
|
-
isFrame?: boolean;
|
|
17
|
-
isGamestop?: boolean;
|
|
18
|
-
isGlow?: boolean;
|
|
19
|
-
isMetaMask?: boolean;
|
|
20
|
-
isOpera?: boolean;
|
|
21
|
-
isPhantom?: boolean;
|
|
22
|
-
isSolflare?: boolean;
|
|
23
|
-
isTrustWallet?: boolean;
|
|
24
|
-
isZerion?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export type ProviderFlag = 'isDawn' | 'isBraveWallet' | 'isCoinbaseWallet' | 'isFrame' | 'isGamestop' | 'isMetaMask' | 'isExodus' | 'isOpera' | 'isBlocto' | 'isTrustWallet' | 'isZerion';
|
|
27
|
-
export type ProviderCondition = {
|
|
28
|
-
flag: ProviderFlag | SolProviderFlag;
|
|
29
|
-
value: boolean;
|
|
30
|
-
};
|
|
31
|
-
export type SolProviderFlag = 'isBraveWallet' | 'isGlow' | 'isPhantom' | 'isSolflare';
|
|
32
|
-
export interface IWindow {
|
|
33
|
-
Slope: {
|
|
34
|
-
new (): ISolana;
|
|
35
|
-
};
|
|
36
|
-
coinbaseSolana: ISolana;
|
|
37
|
-
coinbaseWalletExtension: IEthereum;
|
|
38
|
-
ethereum: IEthereum;
|
|
39
|
-
fcl_extensions: IFclProvider[] | undefined;
|
|
40
|
-
glowSolana: ISolana;
|
|
41
|
-
location: Window['location'];
|
|
42
|
-
phantom: IPhantom;
|
|
43
|
-
solana: ISolana;
|
|
44
|
-
solflare: ISolana;
|
|
45
|
-
starknet: IStarknetWindowObject;
|
|
46
|
-
starknet_argentX: IStarknetWindowObject;
|
|
47
|
-
starknet_braavos: IStarknetWindowObject;
|
|
48
|
-
zerionWallet: IEthereum;
|
|
49
|
-
}
|
|
50
|
-
export interface IEthereum {
|
|
51
|
-
isBraveWallet: boolean;
|
|
52
|
-
isCoinbaseWallet: boolean;
|
|
53
|
-
isDawn: boolean;
|
|
54
|
-
isMetaMask: boolean;
|
|
55
|
-
isOpera: boolean;
|
|
56
|
-
isPhantom: boolean;
|
|
57
|
-
isTrustWallet: boolean;
|
|
58
|
-
isZerion: boolean;
|
|
59
|
-
providers: object[];
|
|
60
|
-
request: <T extends string>(params: {
|
|
61
|
-
method: T;
|
|
62
|
-
} | object) => Promise<T extends 'eth_requestAccounts' ? [string] : object>;
|
|
63
|
-
}
|
|
64
|
-
type PublicKey = {
|
|
65
|
-
toString: () => string;
|
|
66
|
-
};
|
|
67
|
-
export type ConnectionResult = {
|
|
68
|
-
address?: string;
|
|
69
|
-
publicKey?: PublicKey;
|
|
70
|
-
} | undefined;
|
|
71
|
-
export interface ISolana {
|
|
72
|
-
connect: (args?: {
|
|
73
|
-
onlyIfTrusted: boolean;
|
|
74
|
-
}) => Promise<ConnectionResult>;
|
|
75
|
-
disconnect: () => Promise<void | object>;
|
|
76
|
-
isBraveWallet: boolean;
|
|
77
|
-
isGlow: boolean;
|
|
78
|
-
isPhantom: boolean;
|
|
79
|
-
isSolflare: boolean;
|
|
80
|
-
on: (eventMessage: string, callback?: (publickey: string) => void) => Promise<void | object>;
|
|
81
|
-
providers: object[];
|
|
82
|
-
publicKey: PublicKey;
|
|
83
|
-
removeAllListeners: () => void;
|
|
84
|
-
removeListener: (eventMessage: string, callback?: (publickey: string) => void) => Promise<void | object>;
|
|
85
|
-
signMessage: (message: Uint8Array, encoding?: string) => Promise<void | object>;
|
|
86
|
-
signTransaction: (transaction: Transaction) => Promise<Transaction>;
|
|
87
|
-
}
|
|
88
|
-
export interface IFclProvider {
|
|
89
|
-
id: string;
|
|
90
|
-
}
|
|
91
|
-
export interface IPhantom {
|
|
92
|
-
ethereum: IEthereum;
|
|
93
|
-
solana: ISolana;
|
|
94
|
-
}
|
|
95
|
-
export {};
|