@dynamic-labs/multi-wallet 0.17.0-RC.0 → 0.17.0-RC.1
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 +23 -0
- package/package.json +3 -3
- package/src/index.cjs +2 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/multi-wallet.cjs +5 -8
- package/src/multi-wallet.js +5 -8
- package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.d.ts +2 -2
- package/src/utils/isEmailWalletConnector/isEmailWalletConnector.d.ts +2 -2
- package/src/utils/message.cjs +1 -1
- package/src/utils/message.js +1 -1
- package/src/utils/walletConnect.cjs +1 -1
- package/src/wallets/algorand/{myalgo.cjs → MyAlgoWalletConnector.cjs} +4 -42
- package/src/wallets/algorand/MyAlgoWalletConnector.d.ts +21 -0
- package/src/wallets/algorand/{myalgo.js → MyAlgoWalletConnector.js} +4 -42
- package/src/wallets/clients/coinbase/coinbase.cjs +2 -6
- package/src/wallets/clients/coinbase/coinbase.js +1 -1
- package/src/wallets/cosmos/{keplrWalletConnect.cjs → KeplrWalletConnect.cjs} +9 -25
- package/src/wallets/cosmos/{keplrWalletConnect.d.ts → KeplrWalletConnect.d.ts} +6 -14
- package/src/wallets/cosmos/{keplrWalletConnect.js → KeplrWalletConnect.js} +9 -25
- package/src/wallets/cosmos/{keplr.cjs → KeplrWalletConnector.cjs} +5 -17
- package/src/wallets/cosmos/{keplr.d.ts → KeplrWalletConnector.d.ts} +5 -13
- package/src/wallets/cosmos/{keplr.js → KeplrWalletConnector.js} +5 -17
- package/src/wallets/cosmos/getKeplrConnector.cjs +6 -6
- package/src/wallets/cosmos/getKeplrConnector.d.ts +3 -3
- package/src/wallets/cosmos/getKeplrConnector.js +3 -3
- package/src/wallets/cosmos/index.d.ts +1 -1
- package/src/wallets/ethereum/BloctoEvm.cjs +2 -31
- package/src/wallets/ethereum/BloctoEvm.d.ts +4 -13
- package/src/wallets/ethereum/BloctoEvm.js +2 -31
- package/src/wallets/ethereum/{ethProvider.cjs → EthWalletConnector.cjs} +38 -18
- package/src/wallets/ethereum/{ethProvider.d.ts → EthWalletConnector.d.ts} +4 -4
- package/src/wallets/ethereum/{ethProvider.js → EthWalletConnector.js} +38 -18
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.cjs +9 -4
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.d.ts +5 -5
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.js +9 -4
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.cjs +1 -1
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.d.ts +2 -2
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.js +1 -1
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.cjs +1 -2
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.d.ts +2 -3
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.js +1 -2
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.cjs +0 -1
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.js +0 -1
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.cjs +6 -13
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.d.ts +3 -10
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.js +6 -13
- package/src/wallets/ethereum/coinbase.cjs +2 -18
- package/src/wallets/ethereum/coinbase.d.ts +3 -8
- package/src/wallets/ethereum/coinbase.js +2 -18
- package/src/wallets/ethereum/ethProviderHelper.cjs +16 -9
- package/src/wallets/ethereum/ethProviderHelper.js +16 -9
- package/src/wallets/ethereum/fortmatic.cjs +2 -25
- package/src/wallets/ethereum/fortmatic.d.ts +3 -11
- package/src/wallets/ethereum/fortmatic.js +2 -25
- package/src/wallets/ethereum/meta-mask.cjs +2 -9
- package/src/wallets/ethereum/meta-mask.d.ts +3 -7
- package/src/wallets/ethereum/meta-mask.js +2 -9
- package/src/wallets/flow/{flow-provider.cjs → FlowWalletConnector.cjs} +6 -33
- package/src/wallets/flow/{flow-provider.d.ts → FlowWalletConnector.d.ts} +4 -11
- package/src/wallets/flow/{flow-provider.js → FlowWalletConnector.js} +6 -33
- package/src/wallets/flow/blocto.cjs +2 -10
- package/src/wallets/flow/blocto.d.ts +2 -8
- package/src/wallets/flow/blocto.js +2 -10
- package/src/wallets/flow/dapper.cjs +2 -10
- package/src/wallets/flow/dapper.d.ts +2 -8
- package/src/wallets/flow/dapper.js +2 -10
- package/src/wallets/flow/lilico.cjs +2 -11
- package/src/wallets/flow/lilico.d.ts +2 -9
- package/src/wallets/flow/lilico.js +2 -11
- package/src/wallets/getMobileOrInjectedWallet.cjs +1 -1
- package/src/wallets/getMobileOrInjectedWallet.d.ts +1 -3
- package/src/wallets/getWalletConnectConnector.cjs +3 -2
- package/src/wallets/getWalletConnectConnector.d.ts +2 -1
- package/src/wallets/getWalletConnectConnector.js +2 -1
- package/src/wallets/solana/CoinbaseSolana.cjs +2 -25
- package/src/wallets/solana/CoinbaseSolana.d.ts +3 -12
- package/src/wallets/solana/CoinbaseSolana.js +2 -25
- package/src/wallets/solana/glow.cjs +2 -25
- package/src/wallets/solana/glow.d.ts +3 -12
- package/src/wallets/solana/glow.js +2 -25
- package/src/wallets/solana/phantom.cjs +2 -25
- package/src/wallets/solana/phantom.d.ts +3 -12
- package/src/wallets/solana/phantom.js +2 -25
- package/src/wallets/solana/slope.cjs +2 -31
- package/src/wallets/solana/slope.d.ts +2 -14
- package/src/wallets/solana/slope.js +2 -31
- package/src/wallets/solana/{solProvider.cjs → solWalletConnector.cjs} +6 -11
- package/src/wallets/solana/{solProvider.d.ts → solWalletConnector.d.ts} +4 -4
- package/src/wallets/solana/{solProvider.js → solWalletConnector.js} +6 -11
- package/src/wallets/solana/solflare.cjs +2 -31
- package/src/wallets/solana/solflare.d.ts +2 -14
- package/src/wallets/solana/solflare.js +2 -31
- package/src/wallets/starknet/argentx.cjs +2 -2
- package/src/wallets/starknet/argentx.d.ts +1 -1
- package/src/wallets/starknet/argentx.js +2 -2
- package/src/wallets/starknet/braavos.cjs +2 -2
- package/src/wallets/starknet/braavos.d.ts +1 -1
- package/src/wallets/starknet/braavos.js +2 -2
- package/src/wallets/starknet/{starknetProvider.cjs → starknetWalletConnector.cjs} +4 -34
- package/src/wallets/starknet/{starknetProvider.d.ts → starknetWalletConnector.d.ts} +3 -14
- package/src/wallets/starknet/{starknetProvider.js → starknetWalletConnector.js} +4 -34
- package/src/wallets/walletConnect/walletConnect.cjs +2 -19
- package/src/wallets/walletConnect/walletConnect.d.ts +3 -8
- package/src/wallets/walletConnect/walletConnect.js +2 -19
- package/src/wallets/walletConnect/walletConnectV2.cjs +69 -83
- package/src/wallets/walletConnect/walletConnectV2.d.ts +10 -12
- package/src/wallets/walletConnect/walletConnectV2.js +69 -80
- package/src/wallets/algorand/myalgo.d.ts +0 -36
- package/src/wallets/initializeWalletProviders.cjs +0 -14
- package/src/wallets/initializeWalletProviders.d.ts +0 -6
- package/src/wallets/initializeWalletProviders.js +0 -10
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var tslib = require('tslib');
|
|
6
4
|
var Provider = require('@walletconnect/universal-provider');
|
|
7
5
|
var ethers = require('ethers');
|
|
8
6
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
9
|
-
var
|
|
10
|
-
var ethProvider = require('../ethereum/ethProvider.cjs');
|
|
7
|
+
var EthWalletConnector = require('../ethereum/EthWalletConnector.cjs');
|
|
11
8
|
var isMobile = require('../../utils/isMobile.cjs');
|
|
12
9
|
var walletConnect = require('../clients/walletConnect/walletConnect.cjs');
|
|
13
10
|
var errors = require('../../errors.cjs');
|
|
@@ -18,35 +15,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
18
15
|
|
|
19
16
|
var Provider__default = /*#__PURE__*/_interopDefaultLegacy(Provider);
|
|
20
17
|
|
|
21
|
-
let provider;
|
|
22
|
-
let createSession;
|
|
23
|
-
const getInitializedProvider = (providerOpts, evmNetworks) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
if (!provider) {
|
|
25
|
-
provider = yield Provider__default["default"].init(providerOpts);
|
|
26
|
-
const connection = yield provider.client.connect({
|
|
27
|
-
requiredNamespaces: {
|
|
28
|
-
eip155: {
|
|
29
|
-
chains: evmNetworks
|
|
30
|
-
// filtering out Palm for now since it causes Trust to crash
|
|
31
|
-
.filter((network) => network.chainId !== 11297108109)
|
|
32
|
-
.map((network) => `eip155:${network.chainId}`),
|
|
33
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
34
|
-
methods: [
|
|
35
|
-
'eth_sendTransaction',
|
|
36
|
-
'eth_signTransaction',
|
|
37
|
-
'eth_sign',
|
|
38
|
-
'personal_sign',
|
|
39
|
-
'eth_signTypedData',
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
// eslint-disable-next-line prefer-destructuring
|
|
45
|
-
provider.uri = connection.uri;
|
|
46
|
-
createSession = connection.approval;
|
|
47
|
-
}
|
|
48
|
-
return provider;
|
|
49
|
-
});
|
|
50
18
|
const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
|
|
51
19
|
var _a, _b, _c;
|
|
52
20
|
if (isMobile.isMobile()) {
|
|
@@ -62,37 +30,69 @@ const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
|
|
|
62
30
|
}
|
|
63
31
|
};
|
|
64
32
|
const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
|
|
65
|
-
class WalletConnectV2 extends
|
|
66
|
-
constructor(
|
|
67
|
-
|
|
68
|
-
super({ evmNetworks });
|
|
33
|
+
class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
34
|
+
constructor(opts) {
|
|
35
|
+
super({ evmNetworks: opts.evmNetworks });
|
|
69
36
|
this.supportedChains = ['EVM', 'ETH'];
|
|
70
37
|
this.connectedChain = 'EVM';
|
|
71
38
|
this.canConnectViaQrCode = true;
|
|
72
|
-
this.canConnectViaCustodialService = false;
|
|
73
39
|
this.isWalletConnect = true;
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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;
|
|
79
70
|
}
|
|
80
|
-
}
|
|
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
|
+
});
|
|
81
84
|
}
|
|
82
85
|
get sessionTopicKey() {
|
|
83
86
|
return sessionTopicKey(this.key);
|
|
84
87
|
}
|
|
85
|
-
get key() {
|
|
86
|
-
return normalizeWalletName.normalizeWalletName(this.name);
|
|
87
|
-
}
|
|
88
88
|
supportsNetworkSwitching() {
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
91
|
setupEventListeners(listeners) {
|
|
92
|
-
if (!provider) {
|
|
92
|
+
if (!WalletConnectV2.provider) {
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
|
-
provider.client.on('session_event', ({ params }) => {
|
|
95
|
+
WalletConnectV2.provider.client.on('session_event', ({ params }) => {
|
|
96
96
|
var _a, _b;
|
|
97
97
|
if (!params || !params.event) {
|
|
98
98
|
logger.logger.debug('session_event was called without params or params.event');
|
|
@@ -114,42 +114,34 @@ class WalletConnectV2 extends ethProvider.EthProvider {
|
|
|
114
114
|
(_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, data);
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
provider.client.on('session_delete', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
WalletConnectV2.provider.client.on('session_delete', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
118
118
|
var _a;
|
|
119
119
|
localStorage.removeItem(this.sessionTopicKey);
|
|
120
120
|
yield ((_a = listeners.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(listeners));
|
|
121
121
|
}));
|
|
122
122
|
}
|
|
123
123
|
teardownEventListeners() {
|
|
124
|
-
if (!provider) {
|
|
124
|
+
if (!WalletConnectV2.provider) {
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
127
|
-
provider.client.removeAllListeners('session_event');
|
|
128
|
-
provider.client.removeAllListeners('session_delete');
|
|
127
|
+
WalletConnectV2.provider.client.removeAllListeners('session_event');
|
|
128
|
+
WalletConnectV2.provider.client.removeAllListeners('session_delete');
|
|
129
129
|
}
|
|
130
130
|
getDeepLink() {
|
|
131
|
-
var _a;
|
|
132
|
-
if (!(provider === null ||
|
|
131
|
+
var _a, _b;
|
|
132
|
+
if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.uri))
|
|
133
133
|
return;
|
|
134
134
|
const wallet = walletBook.getWalletBookWallet(this.name);
|
|
135
|
-
if (!isMobile.isMobile() && !((
|
|
135
|
+
if (!isMobile.isMobile() && !((_b = wallet.desktop) === null || _b === void 0 ? void 0 : _b.native)) {
|
|
136
136
|
return undefined;
|
|
137
137
|
}
|
|
138
|
-
return walletConnect.getDeepLink(provider.uri, wallet);
|
|
138
|
+
return walletConnect.getDeepLink(WalletConnectV2.provider.uri, wallet);
|
|
139
139
|
}
|
|
140
140
|
getWeb3Provider() {
|
|
141
|
-
if (!provider) {
|
|
141
|
+
if (!WalletConnectV2.provider) {
|
|
142
142
|
throw new Error('No provider found');
|
|
143
143
|
}
|
|
144
|
-
return new ethers.ethers.providers.Web3Provider(provider, 'any');
|
|
145
|
-
}
|
|
146
|
-
isInstalledOnBrowser() {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
connect() {
|
|
150
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
yield this.fetchPublicAddress();
|
|
152
|
-
});
|
|
144
|
+
return new ethers.ethers.providers.Web3Provider(WalletConnectV2.provider, 'any');
|
|
153
145
|
}
|
|
154
146
|
fetchPublicAddress(opts) {
|
|
155
147
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -157,24 +149,24 @@ class WalletConnectV2 extends ethProvider.EthProvider {
|
|
|
157
149
|
return this.session.namespaces.eip155.accounts[0].split(':')[2];
|
|
158
150
|
}
|
|
159
151
|
const metadata = walletBook.getWalletBookWallet(this.name);
|
|
160
|
-
if (!provider) {
|
|
152
|
+
if (!WalletConnectV2.provider) {
|
|
161
153
|
throw new errors.DynamicError('No provider found');
|
|
162
154
|
}
|
|
163
|
-
if (!provider.uri || !createSession) {
|
|
155
|
+
if (!WalletConnectV2.provider.uri || !WalletConnectV2.createSession) {
|
|
164
156
|
throw new errors.DynamicError('No uri or approval found');
|
|
165
157
|
}
|
|
166
|
-
performPlatformSpecificConnectionMethod(provider.uri, metadata, {
|
|
158
|
+
performPlatformSpecificConnectionMethod(WalletConnectV2.provider.uri, metadata, {
|
|
167
159
|
onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
|
|
168
160
|
onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
|
|
169
161
|
});
|
|
170
|
-
const session = yield createSession();
|
|
162
|
+
const session = yield WalletConnectV2.createSession();
|
|
171
163
|
if (!session) {
|
|
172
164
|
return undefined;
|
|
173
165
|
}
|
|
174
166
|
this.session = session;
|
|
175
167
|
localStorage.setItem(this.sessionTopicKey, session.topic);
|
|
176
168
|
// need to "reconnect" the provider so that we can tell it what the rpc urls are
|
|
177
|
-
yield provider.connect({
|
|
169
|
+
yield WalletConnectV2.provider.connect({
|
|
178
170
|
namespaces: {
|
|
179
171
|
eip155: {
|
|
180
172
|
chains: this.evmNetworks
|
|
@@ -197,7 +189,7 @@ class WalletConnectV2 extends ethProvider.EthProvider {
|
|
|
197
189
|
// THIS LINE IS SUPER IMPORTANT
|
|
198
190
|
// since we are skipping pairing, (see: skipPairing: true above), we need to manually set the session
|
|
199
191
|
// so that future provider requests work (like getNetwork)
|
|
200
|
-
provider.session = session;
|
|
192
|
+
WalletConnectV2.provider.session = session;
|
|
201
193
|
return session.namespaces.eip155.accounts[0].split(':')[2];
|
|
202
194
|
});
|
|
203
195
|
}
|
|
@@ -206,7 +198,7 @@ class WalletConnectV2 extends ethProvider.EthProvider {
|
|
|
206
198
|
if (!this.session) {
|
|
207
199
|
throw new errors.DynamicError('no session');
|
|
208
200
|
}
|
|
209
|
-
if (!provider) {
|
|
201
|
+
if (!WalletConnectV2.provider) {
|
|
210
202
|
throw new errors.DynamicError('No WalletConnect provider found to handle signing');
|
|
211
203
|
}
|
|
212
204
|
const metadata = walletBook.getWalletBookWallet(this.name);
|
|
@@ -225,21 +217,16 @@ class WalletConnectV2 extends ethProvider.EthProvider {
|
|
|
225
217
|
]);
|
|
226
218
|
});
|
|
227
219
|
}
|
|
228
|
-
proveOwnership(messageToSign) {
|
|
229
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
230
|
-
return this.signMessage(messageToSign);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
220
|
endSession() {
|
|
234
221
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
235
222
|
if (!this.session) {
|
|
236
223
|
return;
|
|
237
224
|
}
|
|
238
|
-
if (!provider) {
|
|
225
|
+
if (!WalletConnectV2.provider) {
|
|
239
226
|
return;
|
|
240
227
|
}
|
|
241
228
|
try {
|
|
242
|
-
yield provider.disconnect();
|
|
229
|
+
yield WalletConnectV2.provider.disconnect();
|
|
243
230
|
localStorage.removeItem(this.sessionTopicKey);
|
|
244
231
|
}
|
|
245
232
|
catch (e) {
|
|
@@ -278,5 +265,4 @@ class WalletConnectV2 extends ethProvider.EthProvider {
|
|
|
278
265
|
}
|
|
279
266
|
}
|
|
280
267
|
|
|
281
|
-
exports
|
|
282
|
-
exports.getInitializedProvider = getInitializedProvider;
|
|
268
|
+
module.exports = WalletConnectV2;
|
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
import Provider, { UniversalProviderOpts } from '@walletconnect/universal-provider';
|
|
2
1
|
import { ethers } from 'ethers';
|
|
3
2
|
import type { SessionTypes } from '@walletconnect/types';
|
|
4
|
-
import {
|
|
3
|
+
import { Chain, FetchPublicAddressOpts, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
5
4
|
import { EvmNetwork } from '../ethereum/evm-network';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
declare class WalletConnectV2 extends EthProvider implements WalletConnector {
|
|
5
|
+
import { EthWalletConnector } from '../ethereum/EthWalletConnector';
|
|
6
|
+
declare class WalletConnectV2 extends EthWalletConnector {
|
|
9
7
|
supportedChains: Chain[];
|
|
10
8
|
connectedChain: Chain;
|
|
11
9
|
name: string;
|
|
12
10
|
session: SessionTypes.Struct | undefined;
|
|
13
11
|
canConnectViaQrCode: boolean;
|
|
14
|
-
canConnectViaCustodialService: boolean;
|
|
15
12
|
isWalletConnect: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
private static provider;
|
|
14
|
+
private static createSession;
|
|
15
|
+
private projectId?;
|
|
16
|
+
constructor(opts: {
|
|
18
17
|
evmNetworks: EvmNetwork[];
|
|
18
|
+
projectId?: string;
|
|
19
19
|
walletName: string;
|
|
20
20
|
});
|
|
21
|
+
private initProvider;
|
|
22
|
+
init(): Promise<void>;
|
|
21
23
|
get sessionTopicKey(): string;
|
|
22
|
-
get key(): string;
|
|
23
24
|
supportsNetworkSwitching(): boolean;
|
|
24
25
|
setupEventListeners(listeners: WalletEventListeners): void;
|
|
25
26
|
teardownEventListeners(): void;
|
|
26
27
|
getDeepLink(): string | undefined;
|
|
27
28
|
getWeb3Provider(): ethers.providers.Web3Provider;
|
|
28
|
-
isInstalledOnBrowser(): boolean;
|
|
29
|
-
connect(): Promise<void>;
|
|
30
29
|
fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
|
|
31
30
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
32
|
-
proveOwnership(messageToSign: string): Promise<string | undefined>;
|
|
33
31
|
endSession(): Promise<void>;
|
|
34
32
|
providerSwitchNetwork({ network, provider, }: {
|
|
35
33
|
network: EvmNetwork;
|
|
@@ -2,43 +2,13 @@ import { __awaiter } from 'tslib';
|
|
|
2
2
|
import Provider from '@walletconnect/universal-provider';
|
|
3
3
|
import { ethers } from 'ethers';
|
|
4
4
|
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
|
-
import {
|
|
6
|
-
import { EthProvider } from '../ethereum/ethProvider.js';
|
|
5
|
+
import { EthWalletConnector } from '../ethereum/EthWalletConnector.js';
|
|
7
6
|
import { isMobile } from '../../utils/isMobile.js';
|
|
8
7
|
import { getDeepLink } from '../clients/walletConnect/walletConnect.js';
|
|
9
8
|
import { DynamicError } from '../../errors.js';
|
|
10
9
|
import { logger } from '../../utils/logger.js';
|
|
11
10
|
import { utf8ToHex } from '../../utils/encoding.js';
|
|
12
11
|
|
|
13
|
-
let provider;
|
|
14
|
-
let createSession;
|
|
15
|
-
const getInitializedProvider = (providerOpts, evmNetworks) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
if (!provider) {
|
|
17
|
-
provider = yield Provider.init(providerOpts);
|
|
18
|
-
const connection = yield provider.client.connect({
|
|
19
|
-
requiredNamespaces: {
|
|
20
|
-
eip155: {
|
|
21
|
-
chains: evmNetworks
|
|
22
|
-
// filtering out Palm for now since it causes Trust to crash
|
|
23
|
-
.filter((network) => network.chainId !== 11297108109)
|
|
24
|
-
.map((network) => `eip155:${network.chainId}`),
|
|
25
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
26
|
-
methods: [
|
|
27
|
-
'eth_sendTransaction',
|
|
28
|
-
'eth_signTransaction',
|
|
29
|
-
'eth_sign',
|
|
30
|
-
'personal_sign',
|
|
31
|
-
'eth_signTypedData',
|
|
32
|
-
],
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
// eslint-disable-next-line prefer-destructuring
|
|
37
|
-
provider.uri = connection.uri;
|
|
38
|
-
createSession = connection.approval;
|
|
39
|
-
}
|
|
40
|
-
return provider;
|
|
41
|
-
});
|
|
42
12
|
const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
|
|
43
13
|
var _a, _b, _c;
|
|
44
14
|
if (isMobile()) {
|
|
@@ -54,37 +24,69 @@ const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
|
|
|
54
24
|
}
|
|
55
25
|
};
|
|
56
26
|
const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
|
|
57
|
-
class WalletConnectV2 extends
|
|
58
|
-
constructor(
|
|
59
|
-
|
|
60
|
-
super({ evmNetworks });
|
|
27
|
+
class WalletConnectV2 extends EthWalletConnector {
|
|
28
|
+
constructor(opts) {
|
|
29
|
+
super({ evmNetworks: opts.evmNetworks });
|
|
61
30
|
this.supportedChains = ['EVM', 'ETH'];
|
|
62
31
|
this.connectedChain = 'EVM';
|
|
63
32
|
this.canConnectViaQrCode = true;
|
|
64
|
-
this.canConnectViaCustodialService = false;
|
|
65
33
|
this.isWalletConnect = true;
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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;
|
|
71
64
|
}
|
|
72
|
-
}
|
|
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
|
+
});
|
|
73
78
|
}
|
|
74
79
|
get sessionTopicKey() {
|
|
75
80
|
return sessionTopicKey(this.key);
|
|
76
81
|
}
|
|
77
|
-
get key() {
|
|
78
|
-
return normalizeWalletName(this.name);
|
|
79
|
-
}
|
|
80
82
|
supportsNetworkSwitching() {
|
|
81
83
|
return true;
|
|
82
84
|
}
|
|
83
85
|
setupEventListeners(listeners) {
|
|
84
|
-
if (!provider) {
|
|
86
|
+
if (!WalletConnectV2.provider) {
|
|
85
87
|
return;
|
|
86
88
|
}
|
|
87
|
-
provider.client.on('session_event', ({ params }) => {
|
|
89
|
+
WalletConnectV2.provider.client.on('session_event', ({ params }) => {
|
|
88
90
|
var _a, _b;
|
|
89
91
|
if (!params || !params.event) {
|
|
90
92
|
logger.debug('session_event was called without params or params.event');
|
|
@@ -106,42 +108,34 @@ class WalletConnectV2 extends EthProvider {
|
|
|
106
108
|
(_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, data);
|
|
107
109
|
}
|
|
108
110
|
});
|
|
109
|
-
provider.client.on('session_delete', () => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
WalletConnectV2.provider.client.on('session_delete', () => __awaiter(this, void 0, void 0, function* () {
|
|
110
112
|
var _a;
|
|
111
113
|
localStorage.removeItem(this.sessionTopicKey);
|
|
112
114
|
yield ((_a = listeners.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(listeners));
|
|
113
115
|
}));
|
|
114
116
|
}
|
|
115
117
|
teardownEventListeners() {
|
|
116
|
-
if (!provider) {
|
|
118
|
+
if (!WalletConnectV2.provider) {
|
|
117
119
|
return;
|
|
118
120
|
}
|
|
119
|
-
provider.client.removeAllListeners('session_event');
|
|
120
|
-
provider.client.removeAllListeners('session_delete');
|
|
121
|
+
WalletConnectV2.provider.client.removeAllListeners('session_event');
|
|
122
|
+
WalletConnectV2.provider.client.removeAllListeners('session_delete');
|
|
121
123
|
}
|
|
122
124
|
getDeepLink() {
|
|
123
|
-
var _a;
|
|
124
|
-
if (!(provider === null ||
|
|
125
|
+
var _a, _b;
|
|
126
|
+
if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.uri))
|
|
125
127
|
return;
|
|
126
128
|
const wallet = getWalletBookWallet(this.name);
|
|
127
|
-
if (!isMobile() && !((
|
|
129
|
+
if (!isMobile() && !((_b = wallet.desktop) === null || _b === void 0 ? void 0 : _b.native)) {
|
|
128
130
|
return undefined;
|
|
129
131
|
}
|
|
130
|
-
return getDeepLink(provider.uri, wallet);
|
|
132
|
+
return getDeepLink(WalletConnectV2.provider.uri, wallet);
|
|
131
133
|
}
|
|
132
134
|
getWeb3Provider() {
|
|
133
|
-
if (!provider) {
|
|
135
|
+
if (!WalletConnectV2.provider) {
|
|
134
136
|
throw new Error('No provider found');
|
|
135
137
|
}
|
|
136
|
-
return new ethers.providers.Web3Provider(provider, 'any');
|
|
137
|
-
}
|
|
138
|
-
isInstalledOnBrowser() {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
connect() {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
yield this.fetchPublicAddress();
|
|
144
|
-
});
|
|
138
|
+
return new ethers.providers.Web3Provider(WalletConnectV2.provider, 'any');
|
|
145
139
|
}
|
|
146
140
|
fetchPublicAddress(opts) {
|
|
147
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -149,24 +143,24 @@ class WalletConnectV2 extends EthProvider {
|
|
|
149
143
|
return this.session.namespaces.eip155.accounts[0].split(':')[2];
|
|
150
144
|
}
|
|
151
145
|
const metadata = getWalletBookWallet(this.name);
|
|
152
|
-
if (!provider) {
|
|
146
|
+
if (!WalletConnectV2.provider) {
|
|
153
147
|
throw new DynamicError('No provider found');
|
|
154
148
|
}
|
|
155
|
-
if (!provider.uri || !createSession) {
|
|
149
|
+
if (!WalletConnectV2.provider.uri || !WalletConnectV2.createSession) {
|
|
156
150
|
throw new DynamicError('No uri or approval found');
|
|
157
151
|
}
|
|
158
|
-
performPlatformSpecificConnectionMethod(provider.uri, metadata, {
|
|
152
|
+
performPlatformSpecificConnectionMethod(WalletConnectV2.provider.uri, metadata, {
|
|
159
153
|
onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
|
|
160
154
|
onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
|
|
161
155
|
});
|
|
162
|
-
const session = yield createSession();
|
|
156
|
+
const session = yield WalletConnectV2.createSession();
|
|
163
157
|
if (!session) {
|
|
164
158
|
return undefined;
|
|
165
159
|
}
|
|
166
160
|
this.session = session;
|
|
167
161
|
localStorage.setItem(this.sessionTopicKey, session.topic);
|
|
168
162
|
// need to "reconnect" the provider so that we can tell it what the rpc urls are
|
|
169
|
-
yield provider.connect({
|
|
163
|
+
yield WalletConnectV2.provider.connect({
|
|
170
164
|
namespaces: {
|
|
171
165
|
eip155: {
|
|
172
166
|
chains: this.evmNetworks
|
|
@@ -189,7 +183,7 @@ class WalletConnectV2 extends EthProvider {
|
|
|
189
183
|
// THIS LINE IS SUPER IMPORTANT
|
|
190
184
|
// since we are skipping pairing, (see: skipPairing: true above), we need to manually set the session
|
|
191
185
|
// so that future provider requests work (like getNetwork)
|
|
192
|
-
provider.session = session;
|
|
186
|
+
WalletConnectV2.provider.session = session;
|
|
193
187
|
return session.namespaces.eip155.accounts[0].split(':')[2];
|
|
194
188
|
});
|
|
195
189
|
}
|
|
@@ -198,7 +192,7 @@ class WalletConnectV2 extends EthProvider {
|
|
|
198
192
|
if (!this.session) {
|
|
199
193
|
throw new DynamicError('no session');
|
|
200
194
|
}
|
|
201
|
-
if (!provider) {
|
|
195
|
+
if (!WalletConnectV2.provider) {
|
|
202
196
|
throw new DynamicError('No WalletConnect provider found to handle signing');
|
|
203
197
|
}
|
|
204
198
|
const metadata = getWalletBookWallet(this.name);
|
|
@@ -217,21 +211,16 @@ class WalletConnectV2 extends EthProvider {
|
|
|
217
211
|
]);
|
|
218
212
|
});
|
|
219
213
|
}
|
|
220
|
-
proveOwnership(messageToSign) {
|
|
221
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
-
return this.signMessage(messageToSign);
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
214
|
endSession() {
|
|
226
215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
227
216
|
if (!this.session) {
|
|
228
217
|
return;
|
|
229
218
|
}
|
|
230
|
-
if (!provider) {
|
|
219
|
+
if (!WalletConnectV2.provider) {
|
|
231
220
|
return;
|
|
232
221
|
}
|
|
233
222
|
try {
|
|
234
|
-
yield provider.disconnect();
|
|
223
|
+
yield WalletConnectV2.provider.disconnect();
|
|
235
224
|
localStorage.removeItem(this.sessionTopicKey);
|
|
236
225
|
}
|
|
237
226
|
catch (e) {
|
|
@@ -270,4 +259,4 @@ class WalletConnectV2 extends EthProvider {
|
|
|
270
259
|
}
|
|
271
260
|
}
|
|
272
261
|
|
|
273
|
-
export { WalletConnectV2 as default
|
|
262
|
+
export { WalletConnectV2 as default };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Connection } from '@solana/web3.js';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
import { Chain, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { IMyAlgoSigner } from './myalgoSigner';
|
|
5
|
-
declare class MyAlgo implements WalletConnector {
|
|
6
|
-
private client?;
|
|
7
|
-
private cache;
|
|
8
|
-
name: string;
|
|
9
|
-
canConnectViaSocial: boolean;
|
|
10
|
-
canConnectViaQrCode: boolean;
|
|
11
|
-
canConnectViaCustodialService: boolean;
|
|
12
|
-
isWalletConnect: boolean;
|
|
13
|
-
connectedChain: Chain;
|
|
14
|
-
supportedChains: Chain[];
|
|
15
|
-
constructor();
|
|
16
|
-
get key(): string;
|
|
17
|
-
private getClient;
|
|
18
|
-
getNetwork(): Promise<number | undefined>;
|
|
19
|
-
getDeepLink(): string | undefined;
|
|
20
|
-
fetchPublicAddress(): Promise<string | undefined>;
|
|
21
|
-
connect(): Promise<void>;
|
|
22
|
-
getSigner(): Promise<IMyAlgoSigner>;
|
|
23
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
24
|
-
proveOwnership(messageToSign: string): Promise<string | undefined>;
|
|
25
|
-
getBalance(): Promise<string | undefined>;
|
|
26
|
-
endSession(): Promise<void>;
|
|
27
|
-
isInstalledOnBrowser(): boolean;
|
|
28
|
-
supportsNetworkSwitching(): boolean;
|
|
29
|
-
switchNetwork(): Promise<void>;
|
|
30
|
-
getWeb3Provider(): void | ethers.providers.Web3Provider | Connection | undefined;
|
|
31
|
-
getRpcProvider(): Promise<void>;
|
|
32
|
-
setupEventListeners(): void;
|
|
33
|
-
teardownEventListeners(): void;
|
|
34
|
-
getConnectedAccounts(): Promise<string[]>;
|
|
35
|
-
}
|
|
36
|
-
export default MyAlgo;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var tslib = require('tslib');
|
|
6
|
-
var walletConnectV2 = require('./walletConnect/walletConnectV2.cjs');
|
|
7
|
-
|
|
8
|
-
const initializeWalletProviders = ({ evmNetworks, isWalletConnectV2Enabled, walletConnectProjectId, }) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
-
if (isWalletConnectV2Enabled) {
|
|
10
|
-
yield walletConnectV2.getInitializedProvider({ projectId: walletConnectProjectId }, evmNetworks);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
exports.initializeWalletProviders = initializeWalletProviders;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { EvmNetwork } from './ethereum/evm-network';
|
|
2
|
-
export declare const initializeWalletProviders: ({ evmNetworks, isWalletConnectV2Enabled, walletConnectProjectId, }: {
|
|
3
|
-
evmNetworks: EvmNetwork[];
|
|
4
|
-
isWalletConnectV2Enabled: boolean;
|
|
5
|
-
walletConnectProjectId: string | undefined;
|
|
6
|
-
}) => Promise<void>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
|
-
import { getInitializedProvider } from './walletConnect/walletConnectV2.js';
|
|
3
|
-
|
|
4
|
-
const initializeWalletProviders = ({ evmNetworks, isWalletConnectV2Enabled, walletConnectProjectId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
5
|
-
if (isWalletConnectV2Enabled) {
|
|
6
|
-
yield getInitializedProvider({ projectId: walletConnectProjectId }, evmNetworks);
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export { initializeWalletProviders };
|