@dynamic-labs/ethereum 0.17.11 → 0.17.12
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
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
### [0.17.12](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.11...v0.17.12) (2023-06-26)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* more wc2 improvements ([#2484](https://github.com/dynamic-labs/DynamicAuth/issues/2484)) ([482ed5d](https://github.com/dynamic-labs/DynamicAuth/commit/482ed5d699985ff4a96f4af2ce2a3f7565a6cc1f))
|
|
8
|
+
|
|
2
9
|
### [0.17.11](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.10...v0.17.11) (2023-06-26)
|
|
3
10
|
|
|
4
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@walletconnect/client": "1.8.0",
|
|
30
30
|
"@walletconnect/ethereum-provider": "1.8.0",
|
|
31
|
-
"@walletconnect/universal-provider": "2.8.
|
|
31
|
+
"@walletconnect/universal-provider": "2.8.3",
|
|
32
32
|
"ethers": "5.7.2",
|
|
33
33
|
"eventemitter3": "5.0.1",
|
|
34
34
|
"buffer": "6.0.3",
|
|
35
|
-
"@dynamic-labs/rpc-providers": "0.17.
|
|
36
|
-
"@dynamic-labs/types": "0.17.
|
|
37
|
-
"@dynamic-labs/utils": "0.17.
|
|
38
|
-
"@dynamic-labs/wallet-book": "0.17.
|
|
39
|
-
"@dynamic-labs/wallet-connector-core": "0.17.
|
|
35
|
+
"@dynamic-labs/rpc-providers": "0.17.12",
|
|
36
|
+
"@dynamic-labs/types": "0.17.12",
|
|
37
|
+
"@dynamic-labs/utils": "0.17.12",
|
|
38
|
+
"@dynamic-labs/wallet-book": "0.17.12",
|
|
39
|
+
"@dynamic-labs/wallet-connector-core": "0.17.12"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {}
|
|
42
42
|
}
|
|
@@ -89,11 +89,13 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
refreshSession() {
|
|
92
|
-
var _a, _b, _c, _d;
|
|
92
|
+
var _a, _b, _c, _d, _e;
|
|
93
93
|
if ((_b = (_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.topic) {
|
|
94
94
|
if (localStorage.getItem(this.sessionTopicKey) ===
|
|
95
95
|
((_d = (_c = WalletConnectV2.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
|
|
96
96
|
this.session = WalletConnectV2.provider.session;
|
|
97
|
+
this.activeAccount =
|
|
98
|
+
(_e = localStorage.getItem(this.activeAccountKey)) !== null && _e !== void 0 ? _e : undefined;
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
}
|
|
@@ -110,25 +112,6 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
110
112
|
get activeAccountKey() {
|
|
111
113
|
return activeAccountKey(this.key);
|
|
112
114
|
}
|
|
113
|
-
get activeAccount() {
|
|
114
|
-
if (this._activeAccount) {
|
|
115
|
-
return this._activeAccount;
|
|
116
|
-
}
|
|
117
|
-
const account = localStorage.getItem(this.activeAccountKey);
|
|
118
|
-
if (!account) {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
this._activeAccount = account;
|
|
122
|
-
return account;
|
|
123
|
-
}
|
|
124
|
-
set activeAccount(account) {
|
|
125
|
-
if (!account) {
|
|
126
|
-
localStorage.removeItem(this.activeAccountKey);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
localStorage.setItem(this.activeAccountKey, account);
|
|
130
|
-
this._activeAccount = account;
|
|
131
|
-
}
|
|
132
115
|
supportsNetworkSwitching() {
|
|
133
116
|
return true;
|
|
134
117
|
}
|
|
@@ -158,7 +141,7 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
158
141
|
}
|
|
159
142
|
// eslint-disable-next-line prefer-destructuring
|
|
160
143
|
const account = data[0].split(':')[2];
|
|
161
|
-
this.
|
|
144
|
+
this.setActiveAccount(account);
|
|
162
145
|
(_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, [account]);
|
|
163
146
|
}
|
|
164
147
|
});
|
|
@@ -205,6 +188,12 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
205
188
|
walletConnectorCore.logger.debug('No WC2 provider found, re-initializing...');
|
|
206
189
|
yield this.endSession();
|
|
207
190
|
yield this.init();
|
|
191
|
+
// sleep 1 s to wait for connect call to finish
|
|
192
|
+
// the connect call isn't await-ed because it only resolves once
|
|
193
|
+
// the connection is established, but we need to wait for it to
|
|
194
|
+
// finish setting up the connection URI and making it available
|
|
195
|
+
// on the provider
|
|
196
|
+
yield new Promise((resolve) => setTimeout(resolve, 1000));
|
|
208
197
|
if (!WalletConnectV2.provider || !((_b = WalletConnectV2.provider) === null || _b === void 0 ? void 0 : _b.uri)) {
|
|
209
198
|
walletConnectorCore.logger.debug('No WC2 provider found, escaping and throwing error');
|
|
210
199
|
throw new utils.DynamicError('No provider found');
|
|
@@ -223,17 +212,17 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
223
212
|
ee.on('walletconnect_connection_failed', () => {
|
|
224
213
|
const error = new utils.DynamicError('Connection rejected. Please try again.');
|
|
225
214
|
error.code = 'connection_rejected';
|
|
215
|
+
if (WalletConnectV2.provider) {
|
|
216
|
+
WalletConnectV2.provider.uri = undefined;
|
|
217
|
+
}
|
|
226
218
|
reject(error);
|
|
227
219
|
});
|
|
228
220
|
WalletConnectV2.provider.on('connect', ({ session }) => {
|
|
229
221
|
if (!session) {
|
|
230
222
|
reject(new utils.DynamicError('No session found'));
|
|
231
223
|
}
|
|
232
|
-
this.session
|
|
233
|
-
|
|
234
|
-
// eslint-disable-next-line prefer-destructuring
|
|
235
|
-
this.activeAccount =
|
|
236
|
-
this.session.namespaces.eip155.accounts[0].split(':')[2];
|
|
224
|
+
this.setSession(session);
|
|
225
|
+
this.setActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
|
|
237
226
|
resolve(this.activeAccount);
|
|
238
227
|
});
|
|
239
228
|
});
|
|
@@ -275,20 +264,33 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
275
264
|
return response;
|
|
276
265
|
});
|
|
277
266
|
}
|
|
267
|
+
clearActiveAccount() {
|
|
268
|
+
localStorage.removeItem(this.activeAccountKey);
|
|
269
|
+
this.activeAccount = undefined;
|
|
270
|
+
}
|
|
271
|
+
clearSession() {
|
|
272
|
+
localStorage.removeItem(this.sessionTopicKey);
|
|
273
|
+
this.session = undefined;
|
|
274
|
+
}
|
|
275
|
+
setActiveAccount(account) {
|
|
276
|
+
localStorage.setItem(this.activeAccountKey, account);
|
|
277
|
+
this.activeAccount = account;
|
|
278
|
+
}
|
|
279
|
+
setSession(session) {
|
|
280
|
+
localStorage.setItem(this.sessionTopicKey, session.topic);
|
|
281
|
+
this.session = session;
|
|
282
|
+
}
|
|
278
283
|
endSession() {
|
|
284
|
+
var _a;
|
|
279
285
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (!WalletConnectV2.provider) {
|
|
286
|
+
this.clearActiveAccount();
|
|
287
|
+
this.clearSession();
|
|
288
|
+
if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session)) {
|
|
284
289
|
return;
|
|
285
290
|
}
|
|
286
291
|
try {
|
|
287
292
|
yield WalletConnectV2.provider.disconnect();
|
|
288
293
|
WalletConnectV2.provider.uri = undefined;
|
|
289
|
-
localStorage.removeItem(this.sessionTopicKey);
|
|
290
|
-
this.session = undefined;
|
|
291
|
-
this.activeAccount = undefined;
|
|
292
294
|
}
|
|
293
295
|
catch (e) {
|
|
294
296
|
walletConnectorCore.logger.debug(e);
|
|
@@ -12,7 +12,7 @@ export declare class WalletConnectV2 extends EthWalletConnector {
|
|
|
12
12
|
connectedChain: Chain;
|
|
13
13
|
name: string;
|
|
14
14
|
session: SessionTypes.Struct | undefined;
|
|
15
|
-
|
|
15
|
+
activeAccount: string | undefined;
|
|
16
16
|
isInitialized: boolean;
|
|
17
17
|
canConnectViaQrCode: boolean;
|
|
18
18
|
isWalletConnect: boolean;
|
|
@@ -25,8 +25,6 @@ export declare class WalletConnectV2 extends EthWalletConnector {
|
|
|
25
25
|
init(): Promise<void>;
|
|
26
26
|
get sessionTopicKey(): string;
|
|
27
27
|
get activeAccountKey(): string;
|
|
28
|
-
get activeAccount(): string | undefined;
|
|
29
|
-
set activeAccount(account: string | undefined);
|
|
30
28
|
supportsNetworkSwitching(): boolean;
|
|
31
29
|
setupEventListeners(listeners: WalletEventListeners): void;
|
|
32
30
|
teardownEventListeners(): void;
|
|
@@ -34,6 +32,10 @@ export declare class WalletConnectV2 extends EthWalletConnector {
|
|
|
34
32
|
getWeb3Provider(): ethers.providers.Web3Provider;
|
|
35
33
|
fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
|
|
36
34
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
35
|
+
private clearActiveAccount;
|
|
36
|
+
private clearSession;
|
|
37
|
+
private setActiveAccount;
|
|
38
|
+
private setSession;
|
|
37
39
|
endSession(): Promise<void>;
|
|
38
40
|
getNetwork(): Promise<number | undefined>;
|
|
39
41
|
providerSwitchNetwork({ network, provider, }: {
|
|
@@ -80,11 +80,13 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
refreshSession() {
|
|
83
|
-
var _a, _b, _c, _d;
|
|
83
|
+
var _a, _b, _c, _d, _e;
|
|
84
84
|
if ((_b = (_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.topic) {
|
|
85
85
|
if (localStorage.getItem(this.sessionTopicKey) ===
|
|
86
86
|
((_d = (_c = WalletConnectV2.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
|
|
87
87
|
this.session = WalletConnectV2.provider.session;
|
|
88
|
+
this.activeAccount =
|
|
89
|
+
(_e = localStorage.getItem(this.activeAccountKey)) !== null && _e !== void 0 ? _e : undefined;
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
}
|
|
@@ -101,25 +103,6 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
101
103
|
get activeAccountKey() {
|
|
102
104
|
return activeAccountKey(this.key);
|
|
103
105
|
}
|
|
104
|
-
get activeAccount() {
|
|
105
|
-
if (this._activeAccount) {
|
|
106
|
-
return this._activeAccount;
|
|
107
|
-
}
|
|
108
|
-
const account = localStorage.getItem(this.activeAccountKey);
|
|
109
|
-
if (!account) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
this._activeAccount = account;
|
|
113
|
-
return account;
|
|
114
|
-
}
|
|
115
|
-
set activeAccount(account) {
|
|
116
|
-
if (!account) {
|
|
117
|
-
localStorage.removeItem(this.activeAccountKey);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
localStorage.setItem(this.activeAccountKey, account);
|
|
121
|
-
this._activeAccount = account;
|
|
122
|
-
}
|
|
123
106
|
supportsNetworkSwitching() {
|
|
124
107
|
return true;
|
|
125
108
|
}
|
|
@@ -149,7 +132,7 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
149
132
|
}
|
|
150
133
|
// eslint-disable-next-line prefer-destructuring
|
|
151
134
|
const account = data[0].split(':')[2];
|
|
152
|
-
this.
|
|
135
|
+
this.setActiveAccount(account);
|
|
153
136
|
(_b = listeners.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(listeners, [account]);
|
|
154
137
|
}
|
|
155
138
|
});
|
|
@@ -196,6 +179,12 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
196
179
|
logger.debug('No WC2 provider found, re-initializing...');
|
|
197
180
|
yield this.endSession();
|
|
198
181
|
yield this.init();
|
|
182
|
+
// sleep 1 s to wait for connect call to finish
|
|
183
|
+
// the connect call isn't await-ed because it only resolves once
|
|
184
|
+
// the connection is established, but we need to wait for it to
|
|
185
|
+
// finish setting up the connection URI and making it available
|
|
186
|
+
// on the provider
|
|
187
|
+
yield new Promise((resolve) => setTimeout(resolve, 1000));
|
|
199
188
|
if (!WalletConnectV2.provider || !((_b = WalletConnectV2.provider) === null || _b === void 0 ? void 0 : _b.uri)) {
|
|
200
189
|
logger.debug('No WC2 provider found, escaping and throwing error');
|
|
201
190
|
throw new DynamicError('No provider found');
|
|
@@ -214,17 +203,17 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
214
203
|
ee.on('walletconnect_connection_failed', () => {
|
|
215
204
|
const error = new DynamicError('Connection rejected. Please try again.');
|
|
216
205
|
error.code = 'connection_rejected';
|
|
206
|
+
if (WalletConnectV2.provider) {
|
|
207
|
+
WalletConnectV2.provider.uri = undefined;
|
|
208
|
+
}
|
|
217
209
|
reject(error);
|
|
218
210
|
});
|
|
219
211
|
WalletConnectV2.provider.on('connect', ({ session }) => {
|
|
220
212
|
if (!session) {
|
|
221
213
|
reject(new DynamicError('No session found'));
|
|
222
214
|
}
|
|
223
|
-
this.session
|
|
224
|
-
|
|
225
|
-
// eslint-disable-next-line prefer-destructuring
|
|
226
|
-
this.activeAccount =
|
|
227
|
-
this.session.namespaces.eip155.accounts[0].split(':')[2];
|
|
215
|
+
this.setSession(session);
|
|
216
|
+
this.setActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
|
|
228
217
|
resolve(this.activeAccount);
|
|
229
218
|
});
|
|
230
219
|
});
|
|
@@ -266,20 +255,33 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
266
255
|
return response;
|
|
267
256
|
});
|
|
268
257
|
}
|
|
258
|
+
clearActiveAccount() {
|
|
259
|
+
localStorage.removeItem(this.activeAccountKey);
|
|
260
|
+
this.activeAccount = undefined;
|
|
261
|
+
}
|
|
262
|
+
clearSession() {
|
|
263
|
+
localStorage.removeItem(this.sessionTopicKey);
|
|
264
|
+
this.session = undefined;
|
|
265
|
+
}
|
|
266
|
+
setActiveAccount(account) {
|
|
267
|
+
localStorage.setItem(this.activeAccountKey, account);
|
|
268
|
+
this.activeAccount = account;
|
|
269
|
+
}
|
|
270
|
+
setSession(session) {
|
|
271
|
+
localStorage.setItem(this.sessionTopicKey, session.topic);
|
|
272
|
+
this.session = session;
|
|
273
|
+
}
|
|
269
274
|
endSession() {
|
|
275
|
+
var _a;
|
|
270
276
|
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (!WalletConnectV2.provider) {
|
|
277
|
+
this.clearActiveAccount();
|
|
278
|
+
this.clearSession();
|
|
279
|
+
if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session)) {
|
|
275
280
|
return;
|
|
276
281
|
}
|
|
277
282
|
try {
|
|
278
283
|
yield WalletConnectV2.provider.disconnect();
|
|
279
284
|
WalletConnectV2.provider.uri = undefined;
|
|
280
|
-
localStorage.removeItem(this.sessionTopicKey);
|
|
281
|
-
this.session = undefined;
|
|
282
|
-
this.activeAccount = undefined;
|
|
283
285
|
}
|
|
284
286
|
catch (e) {
|
|
285
287
|
logger.debug(e);
|