@polkadot/extension-base 0.42.6 → 0.42.7
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/background/RequestBytesSign.js +0 -1
- package/background/RequestExtrinsicSign.js +0 -1
- package/background/handlers/Extension.js +26 -54
- package/background/handlers/State.js +125 -184
- package/background/handlers/Tabs.js +15 -22
- package/package.json +14 -14
- package/packageInfo.cjs +1 -1
- package/packageInfo.js +1 -1
- package/page/Injected.js +0 -4
- package/page/PostMessageProvider.js +18 -38
- package/stores/Base.js +8 -15
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@polkadot/extension-base/defaults';
|
|
@@ -38,22 +36,13 @@ function isJsonPayload(value) {
|
|
|
38
36
|
return value.genesisHash !== undefined;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
var _cachedUnlocks = /*#__PURE__*/_classPrivateFieldLooseKey("cachedUnlocks");
|
|
42
|
-
|
|
43
|
-
var _state = /*#__PURE__*/_classPrivateFieldLooseKey("state");
|
|
44
|
-
|
|
45
39
|
export default class Extension {
|
|
40
|
+
#cachedUnlocks;
|
|
41
|
+
#state;
|
|
42
|
+
|
|
46
43
|
constructor(state) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
value: void 0
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(this, _state, {
|
|
52
|
-
writable: true,
|
|
53
|
-
value: void 0
|
|
54
|
-
});
|
|
55
|
-
_classPrivateFieldLooseBase(this, _cachedUnlocks)[_cachedUnlocks] = {};
|
|
56
|
-
_classPrivateFieldLooseBase(this, _state)[_state] = state;
|
|
44
|
+
this.#cachedUnlocks = {};
|
|
45
|
+
this.#state = state;
|
|
57
46
|
}
|
|
58
47
|
|
|
59
48
|
accountsCreateExternal({
|
|
@@ -162,11 +151,11 @@ export default class Extension {
|
|
|
162
151
|
const {
|
|
163
152
|
address
|
|
164
153
|
} = pair;
|
|
165
|
-
const savedExpiry =
|
|
154
|
+
const savedExpiry = this.#cachedUnlocks[address] || 0;
|
|
166
155
|
const remainingTime = savedExpiry - Date.now();
|
|
167
156
|
|
|
168
157
|
if (remainingTime < 0) {
|
|
169
|
-
|
|
158
|
+
this.#cachedUnlocks[address] = 0;
|
|
170
159
|
pair.lock();
|
|
171
160
|
return 0;
|
|
172
161
|
}
|
|
@@ -224,8 +213,7 @@ export default class Extension {
|
|
|
224
213
|
authorizeApprove({
|
|
225
214
|
id
|
|
226
215
|
}) {
|
|
227
|
-
const queued =
|
|
228
|
-
|
|
216
|
+
const queued = this.#state.getAuthRequest(id);
|
|
229
217
|
assert(queued, 'Unable to find request');
|
|
230
218
|
const {
|
|
231
219
|
resolve
|
|
@@ -236,15 +224,14 @@ export default class Extension {
|
|
|
236
224
|
|
|
237
225
|
getAuthList() {
|
|
238
226
|
return {
|
|
239
|
-
list:
|
|
227
|
+
list: this.#state.authUrls
|
|
240
228
|
};
|
|
241
229
|
}
|
|
242
230
|
|
|
243
231
|
authorizeReject({
|
|
244
232
|
id
|
|
245
233
|
}) {
|
|
246
|
-
const queued =
|
|
247
|
-
|
|
234
|
+
const queued = this.#state.getAuthRequest(id);
|
|
248
235
|
assert(queued, 'Unable to find request');
|
|
249
236
|
const {
|
|
250
237
|
reject
|
|
@@ -256,9 +243,7 @@ export default class Extension {
|
|
|
256
243
|
|
|
257
244
|
authorizeSubscribe(id, port) {
|
|
258
245
|
const cb = createSubscription(id, port);
|
|
259
|
-
|
|
260
|
-
const subscription = _classPrivateFieldLooseBase(this, _state)[_state].authSubject.subscribe(requests => cb(requests));
|
|
261
|
-
|
|
246
|
+
const subscription = this.#state.authSubject.subscribe(requests => cb(requests));
|
|
262
247
|
port.onDisconnect.addListener(() => {
|
|
263
248
|
unsubscribe(id);
|
|
264
249
|
subscription.unsubscribe();
|
|
@@ -269,33 +254,29 @@ export default class Extension {
|
|
|
269
254
|
metadataApprove({
|
|
270
255
|
id
|
|
271
256
|
}) {
|
|
272
|
-
const queued =
|
|
273
|
-
|
|
257
|
+
const queued = this.#state.getMetaRequest(id);
|
|
274
258
|
assert(queued, 'Unable to find request');
|
|
275
259
|
const {
|
|
276
260
|
request,
|
|
277
261
|
resolve
|
|
278
262
|
} = queued;
|
|
279
|
-
|
|
280
|
-
_classPrivateFieldLooseBase(this, _state)[_state].saveMetadata(request);
|
|
281
|
-
|
|
263
|
+
this.#state.saveMetadata(request);
|
|
282
264
|
resolve(true);
|
|
283
265
|
return true;
|
|
284
266
|
}
|
|
285
267
|
|
|
286
268
|
metadataGet(genesisHash) {
|
|
287
|
-
return
|
|
269
|
+
return this.#state.knownMetadata.find(result => result.genesisHash === genesisHash) || null;
|
|
288
270
|
}
|
|
289
271
|
|
|
290
272
|
metadataList() {
|
|
291
|
-
return
|
|
273
|
+
return this.#state.knownMetadata;
|
|
292
274
|
}
|
|
293
275
|
|
|
294
276
|
metadataReject({
|
|
295
277
|
id
|
|
296
278
|
}) {
|
|
297
|
-
const queued =
|
|
298
|
-
|
|
279
|
+
const queued = this.#state.getMetaRequest(id);
|
|
299
280
|
assert(queued, 'Unable to find request');
|
|
300
281
|
const {
|
|
301
282
|
reject
|
|
@@ -306,9 +287,7 @@ export default class Extension {
|
|
|
306
287
|
|
|
307
288
|
metadataSubscribe(id, port) {
|
|
308
289
|
const cb = createSubscription(id, port);
|
|
309
|
-
|
|
310
|
-
const subscription = _classPrivateFieldLooseBase(this, _state)[_state].metaSubject.subscribe(requests => cb(requests));
|
|
311
|
-
|
|
290
|
+
const subscription = this.#state.metaSubject.subscribe(requests => cb(requests));
|
|
312
291
|
port.onDisconnect.addListener(() => {
|
|
313
292
|
unsubscribe(id);
|
|
314
293
|
subscription.unsubscribe();
|
|
@@ -400,8 +379,7 @@ export default class Extension {
|
|
|
400
379
|
password,
|
|
401
380
|
savePass
|
|
402
381
|
}) {
|
|
403
|
-
const queued =
|
|
404
|
-
|
|
382
|
+
const queued = this.#state.getSignRequest(id);
|
|
405
383
|
assert(queued, 'Unable to find request');
|
|
406
384
|
const {
|
|
407
385
|
reject,
|
|
@@ -437,8 +415,7 @@ export default class Extension {
|
|
|
437
415
|
|
|
438
416
|
if (isJsonPayload(payload)) {
|
|
439
417
|
// Get the metadata for the genesisHash
|
|
440
|
-
const currentMetadata =
|
|
441
|
-
|
|
418
|
+
const currentMetadata = this.#state.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash); // set the registry before calling the sign function
|
|
442
419
|
|
|
443
420
|
registry.setSignedExtensions(payload.signedExtensions, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.userExtensions);
|
|
444
421
|
|
|
@@ -450,7 +427,7 @@ export default class Extension {
|
|
|
450
427
|
const result = request.sign(registry, pair);
|
|
451
428
|
|
|
452
429
|
if (savePass) {
|
|
453
|
-
|
|
430
|
+
this.#cachedUnlocks[address] = Date.now() + PASSWORD_EXPIRY_MS;
|
|
454
431
|
} else {
|
|
455
432
|
pair.lock();
|
|
456
433
|
}
|
|
@@ -466,8 +443,7 @@ export default class Extension {
|
|
|
466
443
|
id,
|
|
467
444
|
signature
|
|
468
445
|
}) {
|
|
469
|
-
const queued =
|
|
470
|
-
|
|
446
|
+
const queued = this.#state.getSignRequest(id);
|
|
471
447
|
assert(queued, 'Unable to find request');
|
|
472
448
|
const {
|
|
473
449
|
resolve
|
|
@@ -482,8 +458,7 @@ export default class Extension {
|
|
|
482
458
|
signingCancel({
|
|
483
459
|
id
|
|
484
460
|
}) {
|
|
485
|
-
const queued =
|
|
486
|
-
|
|
461
|
+
const queued = this.#state.getSignRequest(id);
|
|
487
462
|
assert(queued, 'Unable to find request');
|
|
488
463
|
const {
|
|
489
464
|
reject
|
|
@@ -495,8 +470,7 @@ export default class Extension {
|
|
|
495
470
|
signingIsLocked({
|
|
496
471
|
id
|
|
497
472
|
}) {
|
|
498
|
-
const queued =
|
|
499
|
-
|
|
473
|
+
const queued = this.#state.getSignRequest(id);
|
|
500
474
|
assert(queued, 'Unable to find request');
|
|
501
475
|
const address = queued.request.payload.address;
|
|
502
476
|
const pair = keyring.getPair(address);
|
|
@@ -511,9 +485,7 @@ export default class Extension {
|
|
|
511
485
|
|
|
512
486
|
signingSubscribe(id, port) {
|
|
513
487
|
const cb = createSubscription(id, port);
|
|
514
|
-
|
|
515
|
-
const subscription = _classPrivateFieldLooseBase(this, _state)[_state].signSubject.subscribe(requests => cb(requests));
|
|
516
|
-
|
|
488
|
+
const subscription = this.#state.signSubject.subscribe(requests => cb(requests));
|
|
517
489
|
port.onDisconnect.addListener(() => {
|
|
518
490
|
unsubscribe(id);
|
|
519
491
|
subscription.unsubscribe();
|
|
@@ -583,7 +555,7 @@ export default class Extension {
|
|
|
583
555
|
|
|
584
556
|
toggleAuthorization(url) {
|
|
585
557
|
return {
|
|
586
|
-
list:
|
|
558
|
+
list: this.#state.toggleAuthorization(url)
|
|
587
559
|
};
|
|
588
560
|
} // Weird thought, the eslint override is not needed in Tabs
|
|
589
561
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -679,7 +651,7 @@ export default class Extension {
|
|
|
679
651
|
return this.seedValidate(request);
|
|
680
652
|
|
|
681
653
|
case 'pri(settings.notification)':
|
|
682
|
-
return
|
|
654
|
+
return this.#state.setNotification(request);
|
|
683
655
|
|
|
684
656
|
case 'pri(signing.approve.password)':
|
|
685
657
|
return this.signingApprovePassword(request);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2019-2022 @polkadot/extension-bg authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { BehaviorSubject } from 'rxjs';
|
|
@@ -76,146 +74,29 @@ function extractMetadata(store) {
|
|
|
76
74
|
});
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
var _authUrls = /*#__PURE__*/_classPrivateFieldLooseKey("authUrls");
|
|
80
|
-
|
|
81
|
-
var _authRequests = /*#__PURE__*/_classPrivateFieldLooseKey("authRequests");
|
|
82
|
-
|
|
83
|
-
var _metaStore = /*#__PURE__*/_classPrivateFieldLooseKey("metaStore");
|
|
84
|
-
|
|
85
|
-
var _injectedProviders = /*#__PURE__*/_classPrivateFieldLooseKey("injectedProviders");
|
|
86
|
-
|
|
87
|
-
var _metaRequests = /*#__PURE__*/_classPrivateFieldLooseKey("metaRequests");
|
|
88
|
-
|
|
89
|
-
var _notification = /*#__PURE__*/_classPrivateFieldLooseKey("notification");
|
|
90
|
-
|
|
91
|
-
var _providers = /*#__PURE__*/_classPrivateFieldLooseKey("providers");
|
|
92
|
-
|
|
93
|
-
var _signRequests = /*#__PURE__*/_classPrivateFieldLooseKey("signRequests");
|
|
94
|
-
|
|
95
|
-
var _windows = /*#__PURE__*/_classPrivateFieldLooseKey("windows");
|
|
96
|
-
|
|
97
77
|
export default class State {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
Object.defineProperty(this, _authUrls, {
|
|
102
|
-
writable: true,
|
|
103
|
-
value: {}
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(this, _authRequests, {
|
|
106
|
-
writable: true,
|
|
107
|
-
value: {}
|
|
108
|
-
});
|
|
109
|
-
Object.defineProperty(this, _metaStore, {
|
|
110
|
-
writable: true,
|
|
111
|
-
value: new MetadataStore()
|
|
112
|
-
});
|
|
113
|
-
Object.defineProperty(this, _injectedProviders, {
|
|
114
|
-
writable: true,
|
|
115
|
-
value: new Map()
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperty(this, _metaRequests, {
|
|
118
|
-
writable: true,
|
|
119
|
-
value: {}
|
|
120
|
-
});
|
|
121
|
-
Object.defineProperty(this, _notification, {
|
|
122
|
-
writable: true,
|
|
123
|
-
value: settings.notification
|
|
124
|
-
});
|
|
125
|
-
Object.defineProperty(this, _providers, {
|
|
126
|
-
writable: true,
|
|
127
|
-
value: void 0
|
|
128
|
-
});
|
|
129
|
-
Object.defineProperty(this, _signRequests, {
|
|
130
|
-
writable: true,
|
|
131
|
-
value: {}
|
|
132
|
-
});
|
|
133
|
-
Object.defineProperty(this, _windows, {
|
|
134
|
-
writable: true,
|
|
135
|
-
value: []
|
|
136
|
-
});
|
|
137
|
-
this.authSubject = new BehaviorSubject([]);
|
|
138
|
-
this.metaSubject = new BehaviorSubject([]);
|
|
139
|
-
this.signSubject = new BehaviorSubject([]);
|
|
140
|
-
|
|
141
|
-
this.authComplete = (id, resolve, reject) => {
|
|
142
|
-
const complete = result => {
|
|
143
|
-
const isAllowed = result === true;
|
|
144
|
-
|
|
145
|
-
const {
|
|
146
|
-
idStr,
|
|
147
|
-
request: {
|
|
148
|
-
origin
|
|
149
|
-
},
|
|
150
|
-
url
|
|
151
|
-
} = _classPrivateFieldLooseBase(this, _authRequests)[_authRequests][id];
|
|
152
|
-
|
|
153
|
-
_classPrivateFieldLooseBase(this, _authUrls)[_authUrls][this.stripUrl(url)] = {
|
|
154
|
-
count: 0,
|
|
155
|
-
id: idStr,
|
|
156
|
-
isAllowed,
|
|
157
|
-
origin,
|
|
158
|
-
url
|
|
159
|
-
};
|
|
160
|
-
this.saveCurrentAuthList();
|
|
161
|
-
delete _classPrivateFieldLooseBase(this, _authRequests)[_authRequests][id];
|
|
162
|
-
this.updateIconAuth(true);
|
|
163
|
-
};
|
|
78
|
+
#authUrls = {};
|
|
79
|
+
#authRequests = {};
|
|
80
|
+
#metaStore = new MetadataStore(); // Map of providers currently injected in tabs
|
|
164
81
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
reject(error);
|
|
169
|
-
},
|
|
170
|
-
resolve: result => {
|
|
171
|
-
complete(result);
|
|
172
|
-
resolve(result);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
};
|
|
82
|
+
#injectedProviders = new Map();
|
|
83
|
+
#metaRequests = {};
|
|
84
|
+
#notification = settings.notification; // Map of all providers exposed by the extension, they are retrievable by key
|
|
176
85
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
86
|
+
#providers;
|
|
87
|
+
#signRequests = {};
|
|
88
|
+
#windows = [];
|
|
89
|
+
authSubject = new BehaviorSubject([]);
|
|
90
|
+
metaSubject = new BehaviorSubject([]);
|
|
91
|
+
signSubject = new BehaviorSubject([]);
|
|
182
92
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
reject(error);
|
|
187
|
-
},
|
|
188
|
-
resolve: result => {
|
|
189
|
-
complete();
|
|
190
|
-
resolve(result);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
this.signComplete = (id, resolve, reject) => {
|
|
196
|
-
const complete = () => {
|
|
197
|
-
delete _classPrivateFieldLooseBase(this, _signRequests)[_signRequests][id];
|
|
198
|
-
this.updateIconSign(true);
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
reject: error => {
|
|
203
|
-
complete();
|
|
204
|
-
reject(error);
|
|
205
|
-
},
|
|
206
|
-
resolve: result => {
|
|
207
|
-
complete();
|
|
208
|
-
resolve(result);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
_classPrivateFieldLooseBase(this, _providers)[_providers] = providers;
|
|
214
|
-
extractMetadata(_classPrivateFieldLooseBase(this, _metaStore)[_metaStore]); // retrieve previously set authorizations
|
|
93
|
+
constructor(providers = {}) {
|
|
94
|
+
this.#providers = providers;
|
|
95
|
+
extractMetadata(this.#metaStore); // retrieve previously set authorizations
|
|
215
96
|
|
|
216
97
|
const authString = localStorage.getItem(AUTH_URLS_KEY) || '{}';
|
|
217
98
|
const previousAuth = JSON.parse(authString);
|
|
218
|
-
|
|
99
|
+
this.#authUrls = previousAuth;
|
|
219
100
|
}
|
|
220
101
|
|
|
221
102
|
get knownMetadata() {
|
|
@@ -223,19 +104,19 @@ export default class State {
|
|
|
223
104
|
}
|
|
224
105
|
|
|
225
106
|
get numAuthRequests() {
|
|
226
|
-
return Object.keys(
|
|
107
|
+
return Object.keys(this.#authRequests).length;
|
|
227
108
|
}
|
|
228
109
|
|
|
229
110
|
get numMetaRequests() {
|
|
230
|
-
return Object.keys(
|
|
111
|
+
return Object.keys(this.#metaRequests).length;
|
|
231
112
|
}
|
|
232
113
|
|
|
233
114
|
get numSignRequests() {
|
|
234
|
-
return Object.keys(
|
|
115
|
+
return Object.keys(this.#signRequests).length;
|
|
235
116
|
}
|
|
236
117
|
|
|
237
118
|
get allAuthRequests() {
|
|
238
|
-
return Object.values(
|
|
119
|
+
return Object.values(this.#authRequests).map(({
|
|
239
120
|
id,
|
|
240
121
|
request,
|
|
241
122
|
url
|
|
@@ -247,7 +128,7 @@ export default class State {
|
|
|
247
128
|
}
|
|
248
129
|
|
|
249
130
|
get allMetaRequests() {
|
|
250
|
-
return Object.values(
|
|
131
|
+
return Object.values(this.#metaRequests).map(({
|
|
251
132
|
id,
|
|
252
133
|
request,
|
|
253
134
|
url
|
|
@@ -259,7 +140,7 @@ export default class State {
|
|
|
259
140
|
}
|
|
260
141
|
|
|
261
142
|
get allSignRequests() {
|
|
262
|
-
return Object.values(
|
|
143
|
+
return Object.values(this.#signRequests).map(({
|
|
263
144
|
account,
|
|
264
145
|
id,
|
|
265
146
|
request,
|
|
@@ -273,27 +154,95 @@ export default class State {
|
|
|
273
154
|
}
|
|
274
155
|
|
|
275
156
|
get authUrls() {
|
|
276
|
-
return
|
|
157
|
+
return this.#authUrls;
|
|
277
158
|
}
|
|
278
159
|
|
|
279
160
|
popupClose() {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
_classPrivateFieldLooseBase(this, _windows)[_windows] = [];
|
|
161
|
+
this.#windows.forEach(id => withErrorLog(() => chrome.windows.remove(id)));
|
|
162
|
+
this.#windows = [];
|
|
283
163
|
}
|
|
284
164
|
|
|
285
165
|
popupOpen() {
|
|
286
|
-
|
|
166
|
+
this.#notification !== 'extension' && chrome.windows.create(this.#notification === 'window' ? NORMAL_WINDOW_OPTS : POPUP_WINDOW_OPTS, window => {
|
|
287
167
|
if (window) {
|
|
288
|
-
|
|
168
|
+
this.#windows.push(window.id || 0);
|
|
289
169
|
}
|
|
290
170
|
});
|
|
291
171
|
}
|
|
292
172
|
|
|
173
|
+
authComplete = (id, resolve, reject) => {
|
|
174
|
+
const complete = result => {
|
|
175
|
+
const isAllowed = result === true;
|
|
176
|
+
const {
|
|
177
|
+
idStr,
|
|
178
|
+
request: {
|
|
179
|
+
origin
|
|
180
|
+
},
|
|
181
|
+
url
|
|
182
|
+
} = this.#authRequests[id];
|
|
183
|
+
this.#authUrls[this.stripUrl(url)] = {
|
|
184
|
+
count: 0,
|
|
185
|
+
id: idStr,
|
|
186
|
+
isAllowed,
|
|
187
|
+
origin,
|
|
188
|
+
url
|
|
189
|
+
};
|
|
190
|
+
this.saveCurrentAuthList();
|
|
191
|
+
delete this.#authRequests[id];
|
|
192
|
+
this.updateIconAuth(true);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
reject: error => {
|
|
197
|
+
complete(error);
|
|
198
|
+
reject(error);
|
|
199
|
+
},
|
|
200
|
+
resolve: result => {
|
|
201
|
+
complete(result);
|
|
202
|
+
resolve(result);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
|
|
293
207
|
saveCurrentAuthList() {
|
|
294
|
-
localStorage.setItem(AUTH_URLS_KEY, JSON.stringify(
|
|
208
|
+
localStorage.setItem(AUTH_URLS_KEY, JSON.stringify(this.#authUrls));
|
|
295
209
|
}
|
|
296
210
|
|
|
211
|
+
metaComplete = (id, resolve, reject) => {
|
|
212
|
+
const complete = () => {
|
|
213
|
+
delete this.#metaRequests[id];
|
|
214
|
+
this.updateIconMeta(true);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
reject: error => {
|
|
219
|
+
complete();
|
|
220
|
+
reject(error);
|
|
221
|
+
},
|
|
222
|
+
resolve: result => {
|
|
223
|
+
complete();
|
|
224
|
+
resolve(result);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
signComplete = (id, resolve, reject) => {
|
|
229
|
+
const complete = () => {
|
|
230
|
+
delete this.#signRequests[id];
|
|
231
|
+
this.updateIconSign(true);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
reject: error => {
|
|
236
|
+
complete();
|
|
237
|
+
reject(error);
|
|
238
|
+
},
|
|
239
|
+
resolve: result => {
|
|
240
|
+
complete();
|
|
241
|
+
resolve(result);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
|
|
297
246
|
stripUrl(url) {
|
|
298
247
|
assert(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`);
|
|
299
248
|
const parts = url.split('/');
|
|
@@ -315,12 +264,11 @@ export default class State {
|
|
|
315
264
|
}
|
|
316
265
|
|
|
317
266
|
toggleAuthorization(url) {
|
|
318
|
-
const entry =
|
|
319
|
-
|
|
267
|
+
const entry = this.#authUrls[url];
|
|
320
268
|
assert(entry, `The source ${url} is not known`);
|
|
321
|
-
|
|
269
|
+
this.#authUrls[url].isAllowed = !entry.isAllowed;
|
|
322
270
|
this.saveCurrentAuthList();
|
|
323
|
-
return
|
|
271
|
+
return this.#authUrls;
|
|
324
272
|
}
|
|
325
273
|
|
|
326
274
|
updateIconAuth(shouldClose) {
|
|
@@ -341,18 +289,18 @@ export default class State {
|
|
|
341
289
|
async authorizeUrl(url, request) {
|
|
342
290
|
const idStr = this.stripUrl(url); // Do not enqueue duplicate authorization requests.
|
|
343
291
|
|
|
344
|
-
const isDuplicate = Object.values(
|
|
292
|
+
const isDuplicate = Object.values(this.#authRequests).some(request => request.idStr === idStr);
|
|
345
293
|
assert(!isDuplicate, `The source ${url} has a pending authorization request`);
|
|
346
294
|
|
|
347
|
-
if (
|
|
295
|
+
if (this.#authUrls[idStr]) {
|
|
348
296
|
// this url was seen in the past
|
|
349
|
-
assert(
|
|
297
|
+
assert(this.#authUrls[idStr].isAllowed, `The source ${url} is not allowed to interact with this extension`);
|
|
350
298
|
return false;
|
|
351
299
|
}
|
|
352
300
|
|
|
353
301
|
return new Promise((resolve, reject) => {
|
|
354
302
|
const id = getId();
|
|
355
|
-
|
|
303
|
+
this.#authRequests[id] = { ...this.authComplete(id, resolve, reject),
|
|
356
304
|
id,
|
|
357
305
|
idStr,
|
|
358
306
|
request,
|
|
@@ -364,8 +312,7 @@ export default class State {
|
|
|
364
312
|
}
|
|
365
313
|
|
|
366
314
|
ensureUrlAuthorized(url) {
|
|
367
|
-
const entry =
|
|
368
|
-
|
|
315
|
+
const entry = this.#authUrls[this.stripUrl(url)];
|
|
369
316
|
assert(entry, `The source ${url} has not been enabled yet`);
|
|
370
317
|
assert(entry.isAllowed, `The source ${url} is not allowed to interact with this extension`);
|
|
371
318
|
return true;
|
|
@@ -374,7 +321,7 @@ export default class State {
|
|
|
374
321
|
injectMetadata(url, request) {
|
|
375
322
|
return new Promise((resolve, reject) => {
|
|
376
323
|
const id = getId();
|
|
377
|
-
|
|
324
|
+
this.#metaRequests[id] = { ...this.metaComplete(id, resolve, reject),
|
|
378
325
|
id,
|
|
379
326
|
request,
|
|
380
327
|
url
|
|
@@ -385,54 +332,52 @@ export default class State {
|
|
|
385
332
|
}
|
|
386
333
|
|
|
387
334
|
getAuthRequest(id) {
|
|
388
|
-
return
|
|
335
|
+
return this.#authRequests[id];
|
|
389
336
|
}
|
|
390
337
|
|
|
391
338
|
getMetaRequest(id) {
|
|
392
|
-
return
|
|
339
|
+
return this.#metaRequests[id];
|
|
393
340
|
}
|
|
394
341
|
|
|
395
342
|
getSignRequest(id) {
|
|
396
|
-
return
|
|
343
|
+
return this.#signRequests[id];
|
|
397
344
|
} // List all providers the extension is exposing
|
|
398
345
|
|
|
399
346
|
|
|
400
347
|
rpcListProviders() {
|
|
401
|
-
return Promise.resolve(Object.keys(
|
|
402
|
-
acc[key] =
|
|
348
|
+
return Promise.resolve(Object.keys(this.#providers).reduce((acc, key) => {
|
|
349
|
+
acc[key] = this.#providers[key].meta;
|
|
403
350
|
return acc;
|
|
404
351
|
}, {}));
|
|
405
352
|
}
|
|
406
353
|
|
|
407
354
|
rpcSend(request, port) {
|
|
408
|
-
const provider =
|
|
409
|
-
|
|
355
|
+
const provider = this.#injectedProviders.get(port);
|
|
410
356
|
assert(provider, 'Cannot call pub(rpc.subscribe) before provider is set');
|
|
411
357
|
return provider.send(request.method, request.params);
|
|
412
358
|
} // Start a provider, return its meta
|
|
413
359
|
|
|
414
360
|
|
|
415
361
|
rpcStartProvider(key, port) {
|
|
416
|
-
assert(Object.keys(
|
|
362
|
+
assert(Object.keys(this.#providers).includes(key), `Provider ${key} is not exposed by extension`);
|
|
417
363
|
|
|
418
|
-
if (
|
|
419
|
-
return Promise.resolve(
|
|
364
|
+
if (this.#injectedProviders.get(port)) {
|
|
365
|
+
return Promise.resolve(this.#providers[key].meta);
|
|
420
366
|
} // Instantiate the provider
|
|
421
367
|
|
|
422
368
|
|
|
423
|
-
|
|
424
|
-
|
|
369
|
+
this.#injectedProviders.set(port, this.#providers[key].start()); // Close provider connection when page is closed
|
|
425
370
|
|
|
426
371
|
port.onDisconnect.addListener(() => {
|
|
427
|
-
const provider =
|
|
372
|
+
const provider = this.#injectedProviders.get(port);
|
|
428
373
|
|
|
429
374
|
if (provider) {
|
|
430
375
|
withErrorLog(() => provider.disconnect());
|
|
431
376
|
}
|
|
432
377
|
|
|
433
|
-
|
|
378
|
+
this.#injectedProviders.delete(port);
|
|
434
379
|
});
|
|
435
|
-
return Promise.resolve(
|
|
380
|
+
return Promise.resolve(this.#providers[key].meta);
|
|
436
381
|
}
|
|
437
382
|
|
|
438
383
|
rpcSubscribe({
|
|
@@ -440,15 +385,13 @@ export default class State {
|
|
|
440
385
|
params,
|
|
441
386
|
type
|
|
442
387
|
}, cb, port) {
|
|
443
|
-
const provider =
|
|
444
|
-
|
|
388
|
+
const provider = this.#injectedProviders.get(port);
|
|
445
389
|
assert(provider, 'Cannot call pub(rpc.subscribe) before provider is set');
|
|
446
390
|
return provider.subscribe(type, method, params, cb);
|
|
447
391
|
}
|
|
448
392
|
|
|
449
393
|
rpcSubscribeConnected(_request, cb, port) {
|
|
450
|
-
const provider =
|
|
451
|
-
|
|
394
|
+
const provider = this.#injectedProviders.get(port);
|
|
452
395
|
assert(provider, 'Cannot call pub(rpc.subscribeConnected) before provider is set');
|
|
453
396
|
cb(null, provider.isConnected); // Immediately send back current isConnected
|
|
454
397
|
|
|
@@ -457,27 +400,25 @@ export default class State {
|
|
|
457
400
|
}
|
|
458
401
|
|
|
459
402
|
rpcUnsubscribe(request, port) {
|
|
460
|
-
const provider =
|
|
461
|
-
|
|
403
|
+
const provider = this.#injectedProviders.get(port);
|
|
462
404
|
assert(provider, 'Cannot call pub(rpc.unsubscribe) before provider is set');
|
|
463
405
|
return provider.unsubscribe(request.type, request.method, request.subscriptionId);
|
|
464
406
|
}
|
|
465
407
|
|
|
466
408
|
saveMetadata(meta) {
|
|
467
|
-
|
|
468
|
-
|
|
409
|
+
this.#metaStore.set(meta.genesisHash, meta);
|
|
469
410
|
addMetadata(meta);
|
|
470
411
|
}
|
|
471
412
|
|
|
472
413
|
setNotification(notification) {
|
|
473
|
-
|
|
414
|
+
this.#notification = notification;
|
|
474
415
|
return true;
|
|
475
416
|
}
|
|
476
417
|
|
|
477
418
|
sign(url, request, account) {
|
|
478
419
|
const id = getId();
|
|
479
420
|
return new Promise((resolve, reject) => {
|
|
480
|
-
|
|
421
|
+
this.#signRequests[id] = { ...this.signComplete(id, resolve, reject),
|
|
481
422
|
account,
|
|
482
423
|
id,
|
|
483
424
|
request,
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { PHISHING_PAGE_REDIRECT } from '@polkadot/extension-base/defaults';
|
|
@@ -39,19 +37,15 @@ function transformAccounts(accounts, anyType = false) {
|
|
|
39
37
|
}));
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
var _state = /*#__PURE__*/_classPrivateFieldLooseKey("state");
|
|
43
|
-
|
|
44
40
|
export default class Tabs {
|
|
41
|
+
#state;
|
|
42
|
+
|
|
45
43
|
constructor(state) {
|
|
46
|
-
|
|
47
|
-
writable: true,
|
|
48
|
-
value: void 0
|
|
49
|
-
});
|
|
50
|
-
_classPrivateFieldLooseBase(this, _state)[_state] = state;
|
|
44
|
+
this.#state = state;
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
authorize(url, request) {
|
|
54
|
-
return
|
|
48
|
+
return this.#state.authorizeUrl(url, request);
|
|
55
49
|
} // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
56
50
|
|
|
57
51
|
|
|
@@ -81,7 +75,7 @@ export default class Tabs {
|
|
|
81
75
|
bytesSign(url, request) {
|
|
82
76
|
const address = request.address;
|
|
83
77
|
const pair = this.getSigningPair(address);
|
|
84
|
-
return
|
|
78
|
+
return this.#state.sign(url, new RequestBytesSign(request), {
|
|
85
79
|
address,
|
|
86
80
|
...pair.meta
|
|
87
81
|
});
|
|
@@ -90,19 +84,19 @@ export default class Tabs {
|
|
|
90
84
|
extrinsicSign(url, request) {
|
|
91
85
|
const address = request.address;
|
|
92
86
|
const pair = this.getSigningPair(address);
|
|
93
|
-
return
|
|
87
|
+
return this.#state.sign(url, new RequestExtrinsicSign(request), {
|
|
94
88
|
address,
|
|
95
89
|
...pair.meta
|
|
96
90
|
});
|
|
97
91
|
}
|
|
98
92
|
|
|
99
93
|
metadataProvide(url, request) {
|
|
100
|
-
return
|
|
94
|
+
return this.#state.injectMetadata(url, request);
|
|
101
95
|
} // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
102
96
|
|
|
103
97
|
|
|
104
98
|
metadataList(url) {
|
|
105
|
-
return
|
|
99
|
+
return this.#state.knownMetadata.map(({
|
|
106
100
|
genesisHash,
|
|
107
101
|
specVersion
|
|
108
102
|
}) => ({
|
|
@@ -112,15 +106,15 @@ export default class Tabs {
|
|
|
112
106
|
}
|
|
113
107
|
|
|
114
108
|
rpcListProviders() {
|
|
115
|
-
return
|
|
109
|
+
return this.#state.rpcListProviders();
|
|
116
110
|
}
|
|
117
111
|
|
|
118
112
|
rpcSend(request, port) {
|
|
119
|
-
return
|
|
113
|
+
return this.#state.rpcSend(request, port);
|
|
120
114
|
}
|
|
121
115
|
|
|
122
116
|
rpcStartProvider(key, port) {
|
|
123
|
-
return
|
|
117
|
+
return this.#state.rpcStartProvider(key, port);
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
async rpcSubscribe(request, id, port) {
|
|
@@ -128,7 +122,7 @@ export default class Tabs {
|
|
|
128
122
|
|
|
129
123
|
const cb = (_error, data) => innerCb(data);
|
|
130
124
|
|
|
131
|
-
const subscriptionId = await
|
|
125
|
+
const subscriptionId = await this.#state.rpcSubscribe(request, cb, port);
|
|
132
126
|
port.onDisconnect.addListener(() => {
|
|
133
127
|
unsubscribe(id);
|
|
134
128
|
withErrorLog(() => this.rpcUnsubscribe({ ...request,
|
|
@@ -143,8 +137,7 @@ export default class Tabs {
|
|
|
143
137
|
|
|
144
138
|
const cb = (_error, data) => innerCb(data);
|
|
145
139
|
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
this.#state.rpcSubscribeConnected(request, cb, port);
|
|
148
141
|
port.onDisconnect.addListener(() => {
|
|
149
142
|
unsubscribe(id);
|
|
150
143
|
});
|
|
@@ -152,7 +145,7 @@ export default class Tabs {
|
|
|
152
145
|
}
|
|
153
146
|
|
|
154
147
|
async rpcUnsubscribe(request, port) {
|
|
155
|
-
return
|
|
148
|
+
return this.#state.rpcUnsubscribe(request, port);
|
|
156
149
|
}
|
|
157
150
|
|
|
158
151
|
redirectPhishingLanding(phishingWebsite) {
|
|
@@ -187,7 +180,7 @@ export default class Tabs {
|
|
|
187
180
|
}
|
|
188
181
|
|
|
189
182
|
if (type !== 'pub(authorize.tab)') {
|
|
190
|
-
|
|
183
|
+
this.#state.ensureUrlAuthorized(url);
|
|
191
184
|
}
|
|
192
185
|
|
|
193
186
|
switch (type) {
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./detectPackage.cjs"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "0.42.
|
|
20
|
+
"version": "0.42.7",
|
|
21
21
|
"main": "index.cjs",
|
|
22
22
|
"module": "index.js",
|
|
23
23
|
"types": "index.d.ts",
|
|
@@ -178,19 +178,19 @@
|
|
|
178
178
|
},
|
|
179
179
|
"dependencies": {
|
|
180
180
|
"@babel/runtime": "^7.16.7",
|
|
181
|
-
"@polkadot/api": "^7.
|
|
182
|
-
"@polkadot/extension-chains": "^0.42.
|
|
183
|
-
"@polkadot/extension-dapp": "^0.42.
|
|
184
|
-
"@polkadot/extension-inject": "^0.42.
|
|
185
|
-
"@polkadot/keyring": "^8.3.
|
|
186
|
-
"@polkadot/networks": "^8.3.
|
|
187
|
-
"@polkadot/phishing": "^0.8.
|
|
188
|
-
"@polkadot/rpc-provider": "^7.
|
|
189
|
-
"@polkadot/types": "^7.
|
|
190
|
-
"@polkadot/ui-keyring": "^0.89.
|
|
191
|
-
"@polkadot/ui-settings": "^0.89.
|
|
192
|
-
"@polkadot/util": "^8.3.
|
|
193
|
-
"@polkadot/util-crypto": "^8.3.
|
|
181
|
+
"@polkadot/api": "^7.5.1",
|
|
182
|
+
"@polkadot/extension-chains": "^0.42.7",
|
|
183
|
+
"@polkadot/extension-dapp": "^0.42.7",
|
|
184
|
+
"@polkadot/extension-inject": "^0.42.7",
|
|
185
|
+
"@polkadot/keyring": "^8.3.3",
|
|
186
|
+
"@polkadot/networks": "^8.3.3",
|
|
187
|
+
"@polkadot/phishing": "^0.8.71",
|
|
188
|
+
"@polkadot/rpc-provider": "^7.5.1",
|
|
189
|
+
"@polkadot/types": "^7.5.1",
|
|
190
|
+
"@polkadot/ui-keyring": "^0.89.3",
|
|
191
|
+
"@polkadot/ui-settings": "^0.89.3",
|
|
192
|
+
"@polkadot/util": "^8.3.3",
|
|
193
|
+
"@polkadot/util-crypto": "^8.3.3",
|
|
194
194
|
"eventemitter3": "^4.0.7",
|
|
195
195
|
"rxjs": "^7.5.2"
|
|
196
196
|
}
|
package/packageInfo.cjs
CHANGED
package/packageInfo.js
CHANGED
package/page/Injected.js
CHANGED
|
@@ -6,10 +6,6 @@ import PostMessageProvider from "./PostMessageProvider.js";
|
|
|
6
6
|
import Signer from "./Signer.js";
|
|
7
7
|
export default class {
|
|
8
8
|
constructor(sendRequest) {
|
|
9
|
-
this.accounts = void 0;
|
|
10
|
-
this.metadata = void 0;
|
|
11
|
-
this.provider = void 0;
|
|
12
|
-
this.signer = void 0;
|
|
13
9
|
this.accounts = new Accounts(sendRequest);
|
|
14
10
|
this.metadata = new Metadata(sendRequest);
|
|
15
11
|
this.provider = new PostMessageProvider(sendRequest);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import EventEmitter from 'eventemitter3';
|
|
@@ -13,37 +11,22 @@ let sendRequest;
|
|
|
13
11
|
* @description Extension provider to be used by dapps
|
|
14
12
|
*/
|
|
15
13
|
|
|
16
|
-
var _eventemitter = /*#__PURE__*/_classPrivateFieldLooseKey("eventemitter");
|
|
17
|
-
|
|
18
|
-
var _isConnected = /*#__PURE__*/_classPrivateFieldLooseKey("isConnected");
|
|
19
|
-
|
|
20
|
-
var _subscriptions = /*#__PURE__*/_classPrivateFieldLooseKey("subscriptions");
|
|
21
|
-
|
|
22
14
|
export default class PostMessageProvider {
|
|
23
|
-
// Whether or not the actual extension background provider is connected
|
|
24
|
-
|
|
15
|
+
#eventemitter; // Whether or not the actual extension background provider is connected
|
|
16
|
+
|
|
17
|
+
#isConnected = false; // Subscription IDs are (historically) not guaranteed to be globally unique;
|
|
25
18
|
// only unique for a given subscription method; which is why we identify
|
|
26
19
|
// the subscriptions based on subscription id + type
|
|
27
|
-
|
|
20
|
+
|
|
21
|
+
#subscriptions = {}; // {[(type,subscriptionId)]: callback}
|
|
28
22
|
|
|
29
23
|
/**
|
|
30
24
|
* @param {function} sendRequest The function to be called to send requests to the node
|
|
31
25
|
* @param {function} subscriptionNotificationHandler Channel for receiving subscription messages
|
|
32
26
|
*/
|
|
27
|
+
|
|
33
28
|
constructor(_sendRequest) {
|
|
34
|
-
|
|
35
|
-
writable: true,
|
|
36
|
-
value: void 0
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(this, _isConnected, {
|
|
39
|
-
writable: true,
|
|
40
|
-
value: false
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(this, _subscriptions, {
|
|
43
|
-
writable: true,
|
|
44
|
-
value: {}
|
|
45
|
-
});
|
|
46
|
-
_classPrivateFieldLooseBase(this, _eventemitter)[_eventemitter] = new EventEmitter();
|
|
29
|
+
this.#eventemitter = new EventEmitter();
|
|
47
30
|
sendRequest = _sendRequest;
|
|
48
31
|
}
|
|
49
32
|
/**
|
|
@@ -90,7 +73,7 @@ export default class PostMessageProvider {
|
|
|
90
73
|
|
|
91
74
|
|
|
92
75
|
get isConnected() {
|
|
93
|
-
return
|
|
76
|
+
return this.#isConnected;
|
|
94
77
|
}
|
|
95
78
|
|
|
96
79
|
listProviders() {
|
|
@@ -105,10 +88,9 @@ export default class PostMessageProvider {
|
|
|
105
88
|
|
|
106
89
|
|
|
107
90
|
on(type, sub) {
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
this.#eventemitter.on(type, sub);
|
|
110
92
|
return () => {
|
|
111
|
-
|
|
93
|
+
this.#eventemitter.removeListener(type, sub);
|
|
112
94
|
};
|
|
113
95
|
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
114
96
|
|
|
@@ -126,7 +108,7 @@ export default class PostMessageProvider {
|
|
|
126
108
|
}, res => {
|
|
127
109
|
subscription.callback(null, res);
|
|
128
110
|
});
|
|
129
|
-
|
|
111
|
+
this.#subscriptions[`${type}::${id}`] = callback;
|
|
130
112
|
return id;
|
|
131
113
|
}
|
|
132
114
|
|
|
@@ -142,19 +124,17 @@ export default class PostMessageProvider {
|
|
|
142
124
|
|
|
143
125
|
async startProvider(key) {
|
|
144
126
|
// Disconnect from the previous provider
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
_classPrivateFieldLooseBase(this, _eventemitter)[_eventemitter].emit('disconnected');
|
|
148
|
-
|
|
127
|
+
this.#isConnected = false;
|
|
128
|
+
this.#eventemitter.emit('disconnected');
|
|
149
129
|
const meta = await sendRequest('pub(rpc.startProvider)', key); // eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
150
130
|
|
|
151
131
|
sendRequest('pub(rpc.subscribeConnected)', null, connected => {
|
|
152
|
-
|
|
132
|
+
this.#isConnected = connected;
|
|
153
133
|
|
|
154
134
|
if (connected) {
|
|
155
|
-
|
|
135
|
+
this.#eventemitter.emit('connected');
|
|
156
136
|
} else {
|
|
157
|
-
|
|
137
|
+
this.#eventemitter.emit('disconnected');
|
|
158
138
|
}
|
|
159
139
|
|
|
160
140
|
return true;
|
|
@@ -179,12 +159,12 @@ export default class PostMessageProvider {
|
|
|
179
159
|
// a slight complication in solving - since we cannot rely on the send id, but rather
|
|
180
160
|
// need to find the actual subscription id to map it
|
|
181
161
|
|
|
182
|
-
if (isUndefined(
|
|
162
|
+
if (isUndefined(this.#subscriptions[subscription])) {
|
|
183
163
|
l.debug(() => `Unable to find active subscription=${subscription}`);
|
|
184
164
|
return false;
|
|
185
165
|
}
|
|
186
166
|
|
|
187
|
-
delete
|
|
167
|
+
delete this.#subscriptions[subscription];
|
|
188
168
|
return this.send(method, [id]);
|
|
189
169
|
}
|
|
190
170
|
|
package/stores/Base.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
|
-
|
|
4
1
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
5
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
3
|
const lastError = type => {
|
|
@@ -11,15 +8,11 @@ const lastError = type => {
|
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
10
|
|
|
14
|
-
var _prefix = /*#__PURE__*/_classPrivateFieldLooseKey("prefix");
|
|
15
|
-
|
|
16
11
|
export default class BaseStore {
|
|
12
|
+
#prefix;
|
|
13
|
+
|
|
17
14
|
constructor(prefix) {
|
|
18
|
-
|
|
19
|
-
writable: true,
|
|
20
|
-
value: void 0
|
|
21
|
-
});
|
|
22
|
-
_classPrivateFieldLooseBase(this, _prefix)[_prefix] = prefix ? `${prefix}:` : '';
|
|
15
|
+
this.#prefix = prefix ? `${prefix}:` : '';
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
all(update) {
|
|
@@ -39,8 +32,8 @@ export default class BaseStore {
|
|
|
39
32
|
for (let i = 0; i < entries.length; i++) {
|
|
40
33
|
const [key, value] = entries[i];
|
|
41
34
|
|
|
42
|
-
if (key.startsWith(
|
|
43
|
-
map[key.replace(
|
|
35
|
+
if (key.startsWith(this.#prefix)) {
|
|
36
|
+
map[key.replace(this.#prefix, '')] = value;
|
|
44
37
|
}
|
|
45
38
|
}
|
|
46
39
|
|
|
@@ -49,7 +42,7 @@ export default class BaseStore {
|
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
get(_key, update) {
|
|
52
|
-
const key = `${
|
|
45
|
+
const key = `${this.#prefix}${_key}`;
|
|
53
46
|
chrome.storage.local.get([key], result => {
|
|
54
47
|
lastError('get');
|
|
55
48
|
update(result[key]);
|
|
@@ -57,7 +50,7 @@ export default class BaseStore {
|
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
remove(_key, update) {
|
|
60
|
-
const key = `${
|
|
53
|
+
const key = `${this.#prefix}${_key}`;
|
|
61
54
|
chrome.storage.local.remove(key, () => {
|
|
62
55
|
lastError('remove');
|
|
63
56
|
update && update();
|
|
@@ -65,7 +58,7 @@ export default class BaseStore {
|
|
|
65
58
|
}
|
|
66
59
|
|
|
67
60
|
set(_key, value, update) {
|
|
68
|
-
const key = `${
|
|
61
|
+
const key = `${this.#prefix}${_key}`;
|
|
69
62
|
chrome.storage.local.set({
|
|
70
63
|
[key]: value
|
|
71
64
|
}, () => {
|