@polkadot/extension-base 0.46.1 → 0.46.2
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/handlers/Extension.js +31 -36
- package/background/handlers/State.js +62 -67
- package/background/handlers/Tabs.js +18 -22
- package/cjs/background/handlers/Extension.js +31 -35
- package/cjs/background/handlers/State.js +62 -66
- package/cjs/background/handlers/Tabs.js +18 -21
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/PostMessageProvider.js +14 -18
- package/cjs/stores/Base.js +14 -18
- package/package.json +15 -15
- package/packageInfo.js +1 -1
- package/page/PostMessageProvider.js +14 -18
- package/stores/Base.d.ts +3 -3
- package/stores/Base.js +14 -18
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _Tabs_accountSubs, _Tabs_state;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { checkIfDenied } from '@polkadot/phishing';
|
|
4
2
|
import keyring from '@polkadot/ui-keyring';
|
|
5
3
|
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
|
|
@@ -25,12 +23,11 @@ function transformAccounts(accounts, anyType = false) {
|
|
|
25
23
|
}
|
|
26
24
|
export default class Tabs {
|
|
27
25
|
constructor(state) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
__classPrivateFieldSet(this, _Tabs_state, state, "f");
|
|
26
|
+
this.__internal__accountSubs = {};
|
|
27
|
+
this.__internal__state = state;
|
|
31
28
|
}
|
|
32
29
|
filterForAuthorizedAccounts(accounts, url) {
|
|
33
|
-
const auth =
|
|
30
|
+
const auth = this.__internal__state.authUrls[this.__internal__state.stripUrl(url)];
|
|
34
31
|
return accounts.filter((allAcc) => auth.authorizedAccounts
|
|
35
32
|
// we have a list, use it
|
|
36
33
|
? auth.authorizedAccounts.includes(allAcc.address)
|
|
@@ -38,7 +35,7 @@ export default class Tabs {
|
|
|
38
35
|
: auth.isAllowed);
|
|
39
36
|
}
|
|
40
37
|
authorize(url, request) {
|
|
41
|
-
return
|
|
38
|
+
return this.__internal__state.authorizeUrl(url, request);
|
|
42
39
|
}
|
|
43
40
|
accountsListAuthorized(url, { anyType }) {
|
|
44
41
|
const transformedAccounts = transformAccounts(accountsObservable.subject.getValue(), anyType);
|
|
@@ -46,7 +43,7 @@ export default class Tabs {
|
|
|
46
43
|
}
|
|
47
44
|
accountsSubscribeAuthorized(url, id, port) {
|
|
48
45
|
const cb = createSubscription(id, port);
|
|
49
|
-
|
|
46
|
+
this.__internal__accountSubs[id] = {
|
|
50
47
|
subscription: accountsObservable.subject.subscribe((accounts) => {
|
|
51
48
|
const transformedAccounts = transformAccounts(accounts);
|
|
52
49
|
cb(this.filterForAuthorizedAccounts(transformedAccounts, url));
|
|
@@ -59,11 +56,11 @@ export default class Tabs {
|
|
|
59
56
|
return id;
|
|
60
57
|
}
|
|
61
58
|
accountsUnsubscribe(url, { id }) {
|
|
62
|
-
const sub =
|
|
59
|
+
const sub = this.__internal__accountSubs[id];
|
|
63
60
|
if (!sub || sub.url !== url) {
|
|
64
61
|
return false;
|
|
65
62
|
}
|
|
66
|
-
delete
|
|
63
|
+
delete this.__internal__accountSubs[id];
|
|
67
64
|
unsubscribe(id);
|
|
68
65
|
sub.subscription.unsubscribe();
|
|
69
66
|
return true;
|
|
@@ -76,35 +73,35 @@ export default class Tabs {
|
|
|
76
73
|
bytesSign(url, request) {
|
|
77
74
|
const address = request.address;
|
|
78
75
|
const pair = this.getSigningPair(address);
|
|
79
|
-
return
|
|
76
|
+
return this.__internal__state.sign(url, new RequestBytesSign(request), { address, ...pair.meta });
|
|
80
77
|
}
|
|
81
78
|
extrinsicSign(url, request) {
|
|
82
79
|
const address = request.address;
|
|
83
80
|
const pair = this.getSigningPair(address);
|
|
84
|
-
return
|
|
81
|
+
return this.__internal__state.sign(url, new RequestExtrinsicSign(request), { address, ...pair.meta });
|
|
85
82
|
}
|
|
86
83
|
metadataProvide(url, request) {
|
|
87
|
-
return
|
|
84
|
+
return this.__internal__state.injectMetadata(url, request);
|
|
88
85
|
}
|
|
89
86
|
metadataList(_url) {
|
|
90
|
-
return
|
|
87
|
+
return this.__internal__state.knownMetadata.map(({ genesisHash, specVersion }) => ({
|
|
91
88
|
genesisHash,
|
|
92
89
|
specVersion
|
|
93
90
|
}));
|
|
94
91
|
}
|
|
95
92
|
rpcListProviders() {
|
|
96
|
-
return
|
|
93
|
+
return this.__internal__state.rpcListProviders();
|
|
97
94
|
}
|
|
98
95
|
rpcSend(request, port) {
|
|
99
|
-
return
|
|
96
|
+
return this.__internal__state.rpcSend(request, port);
|
|
100
97
|
}
|
|
101
98
|
rpcStartProvider(key, port) {
|
|
102
|
-
return
|
|
99
|
+
return this.__internal__state.rpcStartProvider(key, port);
|
|
103
100
|
}
|
|
104
101
|
async rpcSubscribe(request, id, port) {
|
|
105
102
|
const innerCb = createSubscription(id, port);
|
|
106
103
|
const cb = (_error, data) => innerCb(data);
|
|
107
|
-
const subscriptionId = await
|
|
104
|
+
const subscriptionId = await this.__internal__state.rpcSubscribe(request, cb, port);
|
|
108
105
|
port.onDisconnect.addListener(() => {
|
|
109
106
|
unsubscribe(id);
|
|
110
107
|
withErrorLog(() => this.rpcUnsubscribe({ ...request, subscriptionId }, port));
|
|
@@ -114,14 +111,14 @@ export default class Tabs {
|
|
|
114
111
|
rpcSubscribeConnected(request, id, port) {
|
|
115
112
|
const innerCb = createSubscription(id, port);
|
|
116
113
|
const cb = (_error, data) => innerCb(data);
|
|
117
|
-
|
|
114
|
+
this.__internal__state.rpcSubscribeConnected(request, cb, port);
|
|
118
115
|
port.onDisconnect.addListener(() => {
|
|
119
116
|
unsubscribe(id);
|
|
120
117
|
});
|
|
121
118
|
return Promise.resolve(true);
|
|
122
119
|
}
|
|
123
120
|
async rpcUnsubscribe(request, port) {
|
|
124
|
-
return
|
|
121
|
+
return this.__internal__state.rpcUnsubscribe(request, port);
|
|
125
122
|
}
|
|
126
123
|
redirectPhishingLanding(phishingWebsite) {
|
|
127
124
|
const nonFragment = phishingWebsite.split('#')[0];
|
|
@@ -147,7 +144,7 @@ export default class Tabs {
|
|
|
147
144
|
return this.redirectIfPhishing(url);
|
|
148
145
|
}
|
|
149
146
|
if (type !== 'pub(authorize.tab)') {
|
|
150
|
-
|
|
147
|
+
this.__internal__state.ensureUrlAuthorized(url);
|
|
151
148
|
}
|
|
152
149
|
switch (type) {
|
|
153
150
|
case 'pub(authorize.tab)':
|
|
@@ -185,4 +182,3 @@ export default class Tabs {
|
|
|
185
182
|
}
|
|
186
183
|
}
|
|
187
184
|
}
|
|
188
|
-
_Tabs_accountSubs = new WeakMap(), _Tabs_state = new WeakMap();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _Extension_cachedUnlocks, _Extension_state;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
4
|
const defaults_1 = require("@polkadot/extension-base/defaults");
|
|
@@ -24,15 +23,13 @@ function isJsonPayload(value) {
|
|
|
24
23
|
}
|
|
25
24
|
class Extension {
|
|
26
25
|
constructor(state) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
tslib_1.__classPrivateFieldSet(this, _Extension_cachedUnlocks, {}, "f");
|
|
30
|
-
tslib_1.__classPrivateFieldSet(this, _Extension_state, state, "f");
|
|
26
|
+
this.__internal__cachedUnlocks = {};
|
|
27
|
+
this.__internal__state = state;
|
|
31
28
|
}
|
|
32
29
|
transformAccounts(accounts) {
|
|
33
30
|
return Object.values(accounts).map(({ json: { address, meta }, type }) => ({
|
|
34
31
|
address,
|
|
35
|
-
isDefaultAuthSelected:
|
|
32
|
+
isDefaultAuthSelected: this.__internal__state.defaultAuthAccountSelection.includes(address),
|
|
36
33
|
...meta,
|
|
37
34
|
type
|
|
38
35
|
}));
|
|
@@ -81,25 +78,25 @@ class Extension {
|
|
|
81
78
|
accountsForget({ address }) {
|
|
82
79
|
const authorizedAccountsDiff = [];
|
|
83
80
|
// cycle through authUrls and prepare the array of diff
|
|
84
|
-
Object.entries(
|
|
81
|
+
Object.entries(this.__internal__state.authUrls).forEach(([url, urlInfo]) => {
|
|
85
82
|
if (!urlInfo.authorizedAccounts.includes(address)) {
|
|
86
83
|
return;
|
|
87
84
|
}
|
|
88
85
|
authorizedAccountsDiff.push([url, urlInfo.authorizedAccounts.filter((previousAddress) => previousAddress !== address)]);
|
|
89
86
|
});
|
|
90
|
-
|
|
87
|
+
this.__internal__state.updateAuthorizedAccounts(authorizedAccountsDiff);
|
|
91
88
|
// cycle through default account selection for auth and remove any occurence of the account
|
|
92
|
-
const newDefaultAuthAccounts =
|
|
93
|
-
|
|
89
|
+
const newDefaultAuthAccounts = this.__internal__state.defaultAuthAccountSelection.filter((defaultSelectionAddress) => defaultSelectionAddress !== address);
|
|
90
|
+
this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
|
|
94
91
|
ui_keyring_1.default.forgetAccount(address);
|
|
95
92
|
return true;
|
|
96
93
|
}
|
|
97
94
|
refreshAccountPasswordCache(pair) {
|
|
98
95
|
const { address } = pair;
|
|
99
|
-
const savedExpiry =
|
|
96
|
+
const savedExpiry = this.__internal__cachedUnlocks[address] || 0;
|
|
100
97
|
const remainingTime = savedExpiry - Date.now();
|
|
101
98
|
if (remainingTime < 0) {
|
|
102
|
-
|
|
99
|
+
this.__internal__cachedUnlocks[address] = 0;
|
|
103
100
|
pair.lock();
|
|
104
101
|
return 0;
|
|
105
102
|
}
|
|
@@ -136,22 +133,22 @@ class Extension {
|
|
|
136
133
|
return true;
|
|
137
134
|
}
|
|
138
135
|
authorizeApprove({ authorizedAccounts, id }) {
|
|
139
|
-
const queued =
|
|
136
|
+
const queued = this.__internal__state.getAuthRequest(id);
|
|
140
137
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
141
138
|
const { resolve } = queued;
|
|
142
139
|
resolve({ authorizedAccounts, result: true });
|
|
143
140
|
return true;
|
|
144
141
|
}
|
|
145
142
|
authorizeUpdate({ authorizedAccounts, url }) {
|
|
146
|
-
return
|
|
143
|
+
return this.__internal__state.updateAuthorizedAccounts([[url, authorizedAccounts]]);
|
|
147
144
|
}
|
|
148
145
|
getAuthList() {
|
|
149
|
-
return { list:
|
|
146
|
+
return { list: this.__internal__state.authUrls };
|
|
150
147
|
}
|
|
151
148
|
// FIXME This looks very much like what we have in accounts
|
|
152
149
|
authorizeSubscribe(id, port) {
|
|
153
150
|
const cb = (0, subscriptions_js_1.createSubscription)(id, port);
|
|
154
|
-
const subscription =
|
|
151
|
+
const subscription = this.__internal__state.authSubject.subscribe((requests) => cb(requests));
|
|
155
152
|
port.onDisconnect.addListener(() => {
|
|
156
153
|
(0, subscriptions_js_1.unsubscribe)(id);
|
|
157
154
|
subscription.unsubscribe();
|
|
@@ -159,21 +156,21 @@ class Extension {
|
|
|
159
156
|
return true;
|
|
160
157
|
}
|
|
161
158
|
metadataApprove({ id }) {
|
|
162
|
-
const queued =
|
|
159
|
+
const queued = this.__internal__state.getMetaRequest(id);
|
|
163
160
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
164
161
|
const { request, resolve } = queued;
|
|
165
|
-
|
|
162
|
+
this.__internal__state.saveMetadata(request);
|
|
166
163
|
resolve(true);
|
|
167
164
|
return true;
|
|
168
165
|
}
|
|
169
166
|
metadataGet(genesisHash) {
|
|
170
|
-
return
|
|
167
|
+
return this.__internal__state.knownMetadata.find((result) => result.genesisHash === genesisHash) || null;
|
|
171
168
|
}
|
|
172
169
|
metadataList() {
|
|
173
|
-
return
|
|
170
|
+
return this.__internal__state.knownMetadata;
|
|
174
171
|
}
|
|
175
172
|
metadataReject({ id }) {
|
|
176
|
-
const queued =
|
|
173
|
+
const queued = this.__internal__state.getMetaRequest(id);
|
|
177
174
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
178
175
|
const { reject } = queued;
|
|
179
176
|
reject(new Error('Rejected'));
|
|
@@ -181,7 +178,7 @@ class Extension {
|
|
|
181
178
|
}
|
|
182
179
|
metadataSubscribe(id, port) {
|
|
183
180
|
const cb = (0, subscriptions_js_1.createSubscription)(id, port);
|
|
184
|
-
const subscription =
|
|
181
|
+
const subscription = this.__internal__state.metaSubject.subscribe((requests) => cb(requests));
|
|
185
182
|
port.onDisconnect.addListener(() => {
|
|
186
183
|
(0, subscriptions_js_1.unsubscribe)(id);
|
|
187
184
|
subscription.unsubscribe();
|
|
@@ -242,7 +239,7 @@ class Extension {
|
|
|
242
239
|
};
|
|
243
240
|
}
|
|
244
241
|
signingApprovePassword({ id, password, savePass }) {
|
|
245
|
-
const queued =
|
|
242
|
+
const queued = this.__internal__state.getSignRequest(id);
|
|
246
243
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
247
244
|
const { reject, request, resolve } = queued;
|
|
248
245
|
const pair = ui_keyring_1.default.getPair(queued.account.address);
|
|
@@ -263,7 +260,7 @@ class Extension {
|
|
|
263
260
|
const { payload } = request;
|
|
264
261
|
if (isJsonPayload(payload)) {
|
|
265
262
|
// Get the metadata for the genesisHash
|
|
266
|
-
const metadata =
|
|
263
|
+
const metadata = this.__internal__state.knownMetadata.find(({ genesisHash }) => genesisHash === payload.genesisHash);
|
|
267
264
|
if (metadata) {
|
|
268
265
|
// we have metadata, expand it and extract the info/registry
|
|
269
266
|
const expanded = (0, extension_chains_1.metadataExpand)(metadata, false);
|
|
@@ -285,7 +282,7 @@ class Extension {
|
|
|
285
282
|
// unlike queued.account.address the following
|
|
286
283
|
// address is encoded with the default prefix
|
|
287
284
|
// which what is used for password caching mapping
|
|
288
|
-
|
|
285
|
+
this.__internal__cachedUnlocks[pair.address] = Date.now() + defaults_1.PASSWORD_EXPIRY_MS;
|
|
289
286
|
}
|
|
290
287
|
else {
|
|
291
288
|
pair.lock();
|
|
@@ -297,21 +294,21 @@ class Extension {
|
|
|
297
294
|
return true;
|
|
298
295
|
}
|
|
299
296
|
signingApproveSignature({ id, signature }) {
|
|
300
|
-
const queued =
|
|
297
|
+
const queued = this.__internal__state.getSignRequest(id);
|
|
301
298
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
302
299
|
const { resolve } = queued;
|
|
303
300
|
resolve({ id, signature });
|
|
304
301
|
return true;
|
|
305
302
|
}
|
|
306
303
|
signingCancel({ id }) {
|
|
307
|
-
const queued =
|
|
304
|
+
const queued = this.__internal__state.getSignRequest(id);
|
|
308
305
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
309
306
|
const { reject } = queued;
|
|
310
307
|
reject(new Error('Cancelled'));
|
|
311
308
|
return true;
|
|
312
309
|
}
|
|
313
310
|
signingIsLocked({ id }) {
|
|
314
|
-
const queued =
|
|
311
|
+
const queued = this.__internal__state.getSignRequest(id);
|
|
315
312
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
316
313
|
const address = queued.request.payload.address;
|
|
317
314
|
const pair = ui_keyring_1.default.getPair(address);
|
|
@@ -325,7 +322,7 @@ class Extension {
|
|
|
325
322
|
// FIXME This looks very much like what we have in authorization
|
|
326
323
|
signingSubscribe(id, port) {
|
|
327
324
|
const cb = (0, subscriptions_js_1.createSubscription)(id, port);
|
|
328
|
-
const subscription =
|
|
325
|
+
const subscription = this.__internal__state.signSubject.subscribe((requests) => cb(requests));
|
|
329
326
|
port.onDisconnect.addListener(() => {
|
|
330
327
|
(0, subscriptions_js_1.unsubscribe)(id);
|
|
331
328
|
subscription.unsubscribe();
|
|
@@ -374,16 +371,16 @@ class Extension {
|
|
|
374
371
|
return true;
|
|
375
372
|
}
|
|
376
373
|
removeAuthorization(url) {
|
|
377
|
-
return { list:
|
|
374
|
+
return { list: this.__internal__state.removeAuthorization(url) };
|
|
378
375
|
}
|
|
379
376
|
deleteAuthRequest(requestId) {
|
|
380
|
-
return
|
|
377
|
+
return this.__internal__state.deleteAuthRequest(requestId);
|
|
381
378
|
}
|
|
382
379
|
updateCurrentTabs({ urls }) {
|
|
383
|
-
|
|
380
|
+
this.__internal__state.udateCurrentTabsUrl(urls);
|
|
384
381
|
}
|
|
385
382
|
getConnectedTabsUrl() {
|
|
386
|
-
return
|
|
383
|
+
return this.__internal__state.getConnectedTabsUrl();
|
|
387
384
|
}
|
|
388
385
|
// Weird thought, the eslint override is not needed in Tabs
|
|
389
386
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -456,7 +453,7 @@ class Extension {
|
|
|
456
453
|
case 'pri(seed.validate)':
|
|
457
454
|
return this.seedValidate(request);
|
|
458
455
|
case 'pri(settings.notification)':
|
|
459
|
-
return
|
|
456
|
+
return this.__internal__state.setNotification(request);
|
|
460
457
|
case 'pri(signing.approve.password)':
|
|
461
458
|
return this.signingApprovePassword(request);
|
|
462
459
|
case 'pri(signing.approve.signature)':
|
|
@@ -475,4 +472,3 @@ class Extension {
|
|
|
475
472
|
}
|
|
476
473
|
}
|
|
477
474
|
exports.default = Extension;
|
|
478
|
-
_Extension_cachedUnlocks = new WeakMap(), _Extension_state = new WeakMap();
|