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