@polkadot/extension-base 0.48.1 → 0.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/background/handlers/Extension.js +17 -15
- package/background/handlers/State.d.ts +6 -4
- package/background/handlers/State.js +39 -28
- package/background/handlers/Tabs.js +2 -2
- package/background/handlers/index.js +1 -0
- package/cjs/background/handlers/Extension.js +41 -40
- package/cjs/background/handlers/State.js +40 -30
- package/cjs/background/handlers/Tabs.js +3 -3
- package/cjs/background/handlers/index.js +1 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/stores/Accounts.js +2 -2
- package/cjs/stores/Base.js +30 -17
- package/package.json +14 -14
- package/packageInfo.js +1 -1
- package/stores/Accounts.d.ts +1 -1
- package/stores/Accounts.js +2 -2
- package/stores/Base.d.ts +5 -5
- package/stores/Base.js +30 -17
package/README.md
CHANGED
|
@@ -7,4 +7,6 @@ Functions, classes and other utilities used in `@polkadot/extension`. These incl
|
|
|
7
7
|
|
|
8
8
|
They are primarily meant to be used in `@polkadot/extension`, and can be broken without any notice to cater for `@polkadot/extension`'s needs.
|
|
9
9
|
|
|
10
|
-
They are exported here if you wish to use part of them in the development of your
|
|
10
|
+
They are exported here if you wish to use part of them in the development of your
|
|
11
|
+
own extension. Don't forget to add `process.env.EXTENSION_PREFIX` to separate
|
|
12
|
+
ports and stores from the current extension's ones.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@polkadot/extension-base/defaults';
|
|
2
2
|
import { metadataExpand } from '@polkadot/extension-chains';
|
|
3
3
|
import { TypeRegistry } from '@polkadot/types';
|
|
4
|
-
import keyring from '@polkadot/ui-keyring';
|
|
4
|
+
import { keyring } from '@polkadot/ui-keyring';
|
|
5
5
|
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
|
|
6
6
|
import { assert, isHex } from '@polkadot/util';
|
|
7
7
|
import { keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
|
|
@@ -74,19 +74,20 @@ export default class Extension {
|
|
|
74
74
|
exportedJson: await keyring.backupAccounts(addresses, password)
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
accountsForget({ address }) {
|
|
77
|
+
async accountsForget({ address }) {
|
|
78
78
|
const authorizedAccountsDiff = [];
|
|
79
79
|
// cycle through authUrls and prepare the array of diff
|
|
80
80
|
Object.entries(this.__internal__state.authUrls).forEach(([url, urlInfo]) => {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// Note that urlInfo.authorizedAccounts may be undefined if this website entry
|
|
82
|
+
// was created before the "account authorization per website" functionality was introduced
|
|
83
|
+
if (urlInfo.authorizedAccounts?.includes(address)) {
|
|
84
|
+
authorizedAccountsDiff.push([url, urlInfo.authorizedAccounts.filter((previousAddress) => previousAddress !== address)]);
|
|
83
85
|
}
|
|
84
|
-
authorizedAccountsDiff.push([url, urlInfo.authorizedAccounts.filter((previousAddress) => previousAddress !== address)]);
|
|
85
86
|
});
|
|
86
|
-
this.__internal__state.updateAuthorizedAccounts(authorizedAccountsDiff);
|
|
87
|
+
await this.__internal__state.updateAuthorizedAccounts(authorizedAccountsDiff);
|
|
87
88
|
// cycle through default account selection for auth and remove any occurrence of the account
|
|
88
89
|
const newDefaultAuthAccounts = this.__internal__state.defaultAuthAccountSelection.filter((defaultSelectionAddress) => defaultSelectionAddress !== address);
|
|
89
|
-
this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
|
|
90
|
+
await this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
|
|
90
91
|
keyring.forgetAccount(address);
|
|
91
92
|
return true;
|
|
92
93
|
}
|
|
@@ -138,8 +139,8 @@ export default class Extension {
|
|
|
138
139
|
resolve({ authorizedAccounts, result: true });
|
|
139
140
|
return true;
|
|
140
141
|
}
|
|
141
|
-
authorizeUpdate({ authorizedAccounts, url }) {
|
|
142
|
-
return this.__internal__state.updateAuthorizedAccounts([[url, authorizedAccounts]]);
|
|
142
|
+
async authorizeUpdate({ authorizedAccounts, url }) {
|
|
143
|
+
return await this.__internal__state.updateAuthorizedAccounts([[url, authorizedAccounts]]);
|
|
143
144
|
}
|
|
144
145
|
getAuthList() {
|
|
145
146
|
return { list: this.__internal__state.authUrls };
|
|
@@ -154,11 +155,11 @@ export default class Extension {
|
|
|
154
155
|
});
|
|
155
156
|
return true;
|
|
156
157
|
}
|
|
157
|
-
metadataApprove({ id }) {
|
|
158
|
+
async metadataApprove({ id }) {
|
|
158
159
|
const queued = this.__internal__state.getMetaRequest(id);
|
|
159
160
|
assert(queued, 'Unable to find request');
|
|
160
161
|
const { request, resolve } = queued;
|
|
161
|
-
this.__internal__state.saveMetadata(request);
|
|
162
|
+
await this.__internal__state.saveMetadata(request);
|
|
162
163
|
resolve(true);
|
|
163
164
|
return true;
|
|
164
165
|
}
|
|
@@ -329,7 +330,7 @@ export default class Extension {
|
|
|
329
330
|
return true;
|
|
330
331
|
}
|
|
331
332
|
windowOpen(path) {
|
|
332
|
-
const url = `${chrome.
|
|
333
|
+
const url = `${chrome.runtime.getURL('index.html')}#${path}`;
|
|
333
334
|
if (!ALLOWED_PATH.includes(path)) {
|
|
334
335
|
console.error('Not allowed to open the url:', url);
|
|
335
336
|
return false;
|
|
@@ -369,8 +370,9 @@ export default class Extension {
|
|
|
369
370
|
keyring.addPair(childPair, password);
|
|
370
371
|
return true;
|
|
371
372
|
}
|
|
372
|
-
removeAuthorization(url) {
|
|
373
|
-
|
|
373
|
+
async removeAuthorization(url) {
|
|
374
|
+
const remAuth = await this.__internal__state.removeAuthorization(url);
|
|
375
|
+
return { list: remAuth };
|
|
374
376
|
}
|
|
375
377
|
deleteAuthRequest(requestId) {
|
|
376
378
|
return this.__internal__state.deleteAuthRequest(requestId);
|
|
@@ -422,7 +424,7 @@ export default class Extension {
|
|
|
422
424
|
case 'pri(accounts.validate)':
|
|
423
425
|
return this.accountsValidate(request);
|
|
424
426
|
case 'pri(metadata.approve)':
|
|
425
|
-
return this.metadataApprove(request);
|
|
427
|
+
return await this.metadataApprove(request);
|
|
426
428
|
case 'pri(metadata.get)':
|
|
427
429
|
return this.metadataGet(request);
|
|
428
430
|
case 'pri(metadata.list)':
|
|
@@ -45,6 +45,7 @@ export default class State {
|
|
|
45
45
|
readonly signSubject: BehaviorSubject<SigningRequest[]>;
|
|
46
46
|
defaultAuthAccountSelection: string[];
|
|
47
47
|
constructor(providers?: Providers);
|
|
48
|
+
init(): Promise<void>;
|
|
48
49
|
get knownMetadata(): MetadataDef[];
|
|
49
50
|
get numAuthRequests(): number;
|
|
50
51
|
get numMetaRequests(): number;
|
|
@@ -53,6 +54,7 @@ export default class State {
|
|
|
53
54
|
get allMetaRequests(): MetadataRequest[];
|
|
54
55
|
get allSignRequests(): SigningRequest[];
|
|
55
56
|
get authUrls(): AuthUrls;
|
|
57
|
+
private set authUrls(value);
|
|
56
58
|
private popupClose;
|
|
57
59
|
private popupOpen;
|
|
58
60
|
private authComplete;
|
|
@@ -61,16 +63,16 @@ export default class State {
|
|
|
61
63
|
deleteAuthRequest(requestId: string): void;
|
|
62
64
|
private saveCurrentAuthList;
|
|
63
65
|
private saveDefaultAuthAccounts;
|
|
64
|
-
updateDefaultAuthAccounts(newList: string[]): void
|
|
66
|
+
updateDefaultAuthAccounts(newList: string[]): Promise<void>;
|
|
65
67
|
private metaComplete;
|
|
66
68
|
private signComplete;
|
|
67
69
|
stripUrl(url: string): string;
|
|
68
70
|
private updateIcon;
|
|
69
|
-
removeAuthorization(url: string): AuthUrls
|
|
71
|
+
removeAuthorization(url: string): Promise<AuthUrls>;
|
|
70
72
|
private updateIconAuth;
|
|
71
73
|
private updateIconMeta;
|
|
72
74
|
private updateIconSign;
|
|
73
|
-
updateAuthorizedAccounts(authorizedAccountDiff: AuthorizedAccountsDiff): void
|
|
75
|
+
updateAuthorizedAccounts(authorizedAccountDiff: AuthorizedAccountsDiff): Promise<void>;
|
|
74
76
|
authorizeUrl(url: string, request: RequestAuthorizeTab): Promise<AuthResponse>;
|
|
75
77
|
ensureUrlAuthorized(url: string): boolean;
|
|
76
78
|
injectMetadata(url: string, request: MetadataDef): Promise<boolean>;
|
|
@@ -83,7 +85,7 @@ export default class State {
|
|
|
83
85
|
rpcSubscribe({ method, params, type }: RequestRpcSubscribe, cb: ProviderInterfaceCallback, port: chrome.runtime.Port): Promise<number | string>;
|
|
84
86
|
rpcSubscribeConnected(_request: null, cb: ProviderInterfaceCallback, port: chrome.runtime.Port): void;
|
|
85
87
|
rpcUnsubscribe(request: RequestRpcUnsubscribe, port: chrome.runtime.Port): Promise<boolean>;
|
|
86
|
-
saveMetadata(meta: MetadataDef): void
|
|
88
|
+
saveMetadata(meta: MetadataDef): Promise<void>;
|
|
87
89
|
setNotification(notification: string): boolean;
|
|
88
90
|
sign(url: string, request: RequestSign, account: AccountJson): Promise<ResponseSigning>;
|
|
89
91
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
2
|
import { addMetadata, knownMetadata } from '@polkadot/extension-chains';
|
|
3
3
|
import { knownGenesis } from '@polkadot/networks/defaults';
|
|
4
|
-
import settings from '@polkadot/ui-settings';
|
|
4
|
+
import { settings } from '@polkadot/ui-settings';
|
|
5
5
|
import { assert } from '@polkadot/util';
|
|
6
6
|
import { MetadataStore } from '../../stores/index.js';
|
|
7
7
|
import { getId } from '../../utils/getId.js';
|
|
8
8
|
import { withErrorLog } from './helpers.js';
|
|
9
|
-
const NOTIFICATION_URL = chrome.
|
|
9
|
+
const NOTIFICATION_URL = chrome.runtime.getURL('notification.html');
|
|
10
10
|
const POPUP_WINDOW_OPTS = {
|
|
11
11
|
focused: true,
|
|
12
12
|
height: 621,
|
|
@@ -29,8 +29,8 @@ export var NotificationOptions;
|
|
|
29
29
|
})(NotificationOptions || (NotificationOptions = {}));
|
|
30
30
|
const AUTH_URLS_KEY = 'authUrls';
|
|
31
31
|
const DEFAULT_AUTH_ACCOUNTS = 'defaultAuthAccounts';
|
|
32
|
-
function extractMetadata(store) {
|
|
33
|
-
store.allMap((map) => {
|
|
32
|
+
async function extractMetadata(store) {
|
|
33
|
+
await store.allMap(async (map) => {
|
|
34
34
|
const knownEntries = Object.entries(knownGenesis);
|
|
35
35
|
const defs = {};
|
|
36
36
|
const removals = [];
|
|
@@ -56,7 +56,9 @@ function extractMetadata(store) {
|
|
|
56
56
|
defs[key] = { def, index: 0, key };
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
|
-
|
|
59
|
+
for (const key of removals) {
|
|
60
|
+
await store.remove(key);
|
|
61
|
+
}
|
|
60
62
|
Object.values(defs).forEach(({ def }) => addMetadata(def));
|
|
61
63
|
});
|
|
62
64
|
}
|
|
@@ -79,13 +81,17 @@ export default class State {
|
|
|
79
81
|
defaultAuthAccountSelection = [];
|
|
80
82
|
constructor(providers = {}) {
|
|
81
83
|
this.__internal__providers = providers;
|
|
82
|
-
|
|
84
|
+
}
|
|
85
|
+
async init() {
|
|
86
|
+
await extractMetadata(this.__internal__metaStore);
|
|
83
87
|
// retrieve previously set authorizations
|
|
84
|
-
const
|
|
88
|
+
const storageAuthUrls = await chrome.storage.local.get(AUTH_URLS_KEY);
|
|
89
|
+
const authString = storageAuthUrls?.[AUTH_URLS_KEY] || '{}';
|
|
85
90
|
const previousAuth = JSON.parse(authString);
|
|
86
91
|
this.__internal__authUrls = previousAuth;
|
|
87
92
|
// retrieve previously set default auth accounts
|
|
88
|
-
const
|
|
93
|
+
const storageDefaultAuthAccounts = await chrome.storage.local.get(DEFAULT_AUTH_ACCOUNTS);
|
|
94
|
+
const defaultAuthString = storageDefaultAuthAccounts?.[DEFAULT_AUTH_ACCOUNTS] || '[]';
|
|
89
95
|
const previousDefaultAuth = JSON.parse(defaultAuthString);
|
|
90
96
|
this.defaultAuthAccountSelection = previousDefaultAuth;
|
|
91
97
|
}
|
|
@@ -119,6 +125,9 @@ export default class State {
|
|
|
119
125
|
get authUrls() {
|
|
120
126
|
return this.__internal__authUrls;
|
|
121
127
|
}
|
|
128
|
+
set authUrls(urls) {
|
|
129
|
+
this.__internal__authUrls = urls;
|
|
130
|
+
}
|
|
122
131
|
popupClose() {
|
|
123
132
|
this.__internal__windows.forEach((id) => withErrorLog(() => chrome.windows.remove(id)));
|
|
124
133
|
this.__internal__windows = [];
|
|
@@ -134,7 +143,7 @@ export default class State {
|
|
|
134
143
|
});
|
|
135
144
|
}
|
|
136
145
|
authComplete = (id, resolve, reject) => {
|
|
137
|
-
const complete = (authorizedAccounts = []) => {
|
|
146
|
+
const complete = async (authorizedAccounts = []) => {
|
|
138
147
|
const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
|
|
139
148
|
this.__internal__authUrls[this.stripUrl(url)] = {
|
|
140
149
|
authorizedAccounts,
|
|
@@ -143,18 +152,20 @@ export default class State {
|
|
|
143
152
|
origin,
|
|
144
153
|
url
|
|
145
154
|
};
|
|
146
|
-
this.saveCurrentAuthList();
|
|
147
|
-
this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
155
|
+
await this.saveCurrentAuthList();
|
|
156
|
+
await this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
148
157
|
delete this.__internal__authRequests[id];
|
|
149
158
|
this.updateIconAuth(true);
|
|
150
159
|
};
|
|
151
160
|
return {
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
162
|
+
reject: async (error) => {
|
|
163
|
+
await complete();
|
|
154
164
|
reject(error);
|
|
155
165
|
},
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
167
|
+
resolve: async ({ authorizedAccounts, result }) => {
|
|
168
|
+
await complete(authorizedAccounts);
|
|
158
169
|
resolve({ authorizedAccounts, result });
|
|
159
170
|
}
|
|
160
171
|
};
|
|
@@ -184,15 +195,15 @@ export default class State {
|
|
|
184
195
|
delete this.__internal__authRequests[requestId];
|
|
185
196
|
this.updateIconAuth(true);
|
|
186
197
|
}
|
|
187
|
-
saveCurrentAuthList() {
|
|
188
|
-
|
|
198
|
+
async saveCurrentAuthList() {
|
|
199
|
+
await chrome.storage.local.set({ [AUTH_URLS_KEY]: JSON.stringify(this.__internal__authUrls) });
|
|
189
200
|
}
|
|
190
|
-
saveDefaultAuthAccounts() {
|
|
191
|
-
|
|
201
|
+
async saveDefaultAuthAccounts() {
|
|
202
|
+
await chrome.storage.local.set({ [DEFAULT_AUTH_ACCOUNTS]: JSON.stringify(this.defaultAuthAccountSelection) });
|
|
192
203
|
}
|
|
193
|
-
updateDefaultAuthAccounts(newList) {
|
|
204
|
+
async updateDefaultAuthAccounts(newList) {
|
|
194
205
|
this.defaultAuthAccountSelection = newList;
|
|
195
|
-
this.saveDefaultAuthAccounts();
|
|
206
|
+
await this.saveDefaultAuthAccounts();
|
|
196
207
|
}
|
|
197
208
|
metaComplete = (id, resolve, reject) => {
|
|
198
209
|
const complete = () => {
|
|
@@ -240,16 +251,16 @@ export default class State {
|
|
|
240
251
|
: metaCount
|
|
241
252
|
? 'Meta'
|
|
242
253
|
: (signCount ? `${signCount}` : ''));
|
|
243
|
-
withErrorLog(() => chrome.
|
|
254
|
+
withErrorLog(() => chrome.action.setBadgeText({ text }));
|
|
244
255
|
if (shouldClose && text === '') {
|
|
245
256
|
this.popupClose();
|
|
246
257
|
}
|
|
247
258
|
}
|
|
248
|
-
removeAuthorization(url) {
|
|
259
|
+
async removeAuthorization(url) {
|
|
249
260
|
const entry = this.__internal__authUrls[url];
|
|
250
261
|
assert(entry, `The source ${url} is not known`);
|
|
251
262
|
delete this.__internal__authUrls[url];
|
|
252
|
-
this.saveCurrentAuthList();
|
|
263
|
+
await this.saveCurrentAuthList();
|
|
253
264
|
return this.__internal__authUrls;
|
|
254
265
|
}
|
|
255
266
|
updateIconAuth(shouldClose) {
|
|
@@ -264,11 +275,11 @@ export default class State {
|
|
|
264
275
|
this.signSubject.next(this.allSignRequests);
|
|
265
276
|
this.updateIcon(shouldClose);
|
|
266
277
|
}
|
|
267
|
-
updateAuthorizedAccounts(authorizedAccountDiff) {
|
|
278
|
+
async updateAuthorizedAccounts(authorizedAccountDiff) {
|
|
268
279
|
authorizedAccountDiff.forEach(([url, authorizedAccountDiff]) => {
|
|
269
280
|
this.__internal__authUrls[url].authorizedAccounts = authorizedAccountDiff;
|
|
270
281
|
});
|
|
271
|
-
this.saveCurrentAuthList();
|
|
282
|
+
await this.saveCurrentAuthList();
|
|
272
283
|
}
|
|
273
284
|
async authorizeUrl(url, request) {
|
|
274
285
|
const idStr = this.stripUrl(url);
|
|
@@ -372,8 +383,8 @@ export default class State {
|
|
|
372
383
|
assert(provider, 'Cannot call pub(rpc.unsubscribe) before provider is set');
|
|
373
384
|
return provider.unsubscribe(request.type, request.method, request.subscriptionId);
|
|
374
385
|
}
|
|
375
|
-
saveMetadata(meta) {
|
|
376
|
-
this.__internal__metaStore.set(meta.genesisHash, meta);
|
|
386
|
+
async saveMetadata(meta) {
|
|
387
|
+
await this.__internal__metaStore.set(meta.genesisHash, meta);
|
|
377
388
|
addMetadata(meta);
|
|
378
389
|
}
|
|
379
390
|
setNotification(notification) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkIfDenied } from '@polkadot/phishing';
|
|
2
|
-
import keyring from '@polkadot/ui-keyring';
|
|
2
|
+
import { keyring } from '@polkadot/ui-keyring';
|
|
3
3
|
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
|
|
4
4
|
import { assert, isNumber } from '@polkadot/util';
|
|
5
5
|
import { PHISHING_PAGE_REDIRECT } from '../../defaults.js';
|
|
@@ -124,7 +124,7 @@ export default class Tabs {
|
|
|
124
124
|
redirectPhishingLanding(phishingWebsite) {
|
|
125
125
|
const nonFragment = phishingWebsite.split('#')[0];
|
|
126
126
|
const encodedWebsite = encodeURIComponent(nonFragment);
|
|
127
|
-
const url = `${chrome.
|
|
127
|
+
const url = `${chrome.runtime.getURL('index.html')}#${PHISHING_PAGE_REDIRECT}/${encodedWebsite}`;
|
|
128
128
|
chrome.tabs.query({ url: nonFragment }, (tabs) => {
|
|
129
129
|
tabs
|
|
130
130
|
.map(({ id }) => id)
|
|
@@ -5,6 +5,7 @@ import State from './State.js';
|
|
|
5
5
|
import Tabs from './Tabs.js';
|
|
6
6
|
export { withErrorLog } from './helpers.js';
|
|
7
7
|
const state = new State();
|
|
8
|
+
await state.init();
|
|
8
9
|
const extension = new Extension(state);
|
|
9
10
|
const tabs = new Tabs(state);
|
|
10
11
|
export default function handler({ id, message, request }, port, extensionPortName = PORT_EXTENSION) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
const defaults_1 = require("@polkadot/extension-base/defaults");
|
|
5
4
|
const extension_chains_1 = require("@polkadot/extension-chains");
|
|
6
5
|
const types_1 = require("@polkadot/types");
|
|
7
|
-
const ui_keyring_1 =
|
|
6
|
+
const ui_keyring_1 = require("@polkadot/ui-keyring");
|
|
8
7
|
const accounts_1 = require("@polkadot/ui-keyring/observable/accounts");
|
|
9
8
|
const util_1 = require("@polkadot/util");
|
|
10
9
|
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
@@ -37,19 +36,19 @@ class Extension {
|
|
|
37
36
|
}));
|
|
38
37
|
}
|
|
39
38
|
accountsCreateExternal({ address, genesisHash, name }) {
|
|
40
|
-
ui_keyring_1.
|
|
39
|
+
ui_keyring_1.keyring.addExternal(address, { genesisHash, name });
|
|
41
40
|
return true;
|
|
42
41
|
}
|
|
43
42
|
accountsCreateHardware({ accountIndex, address, addressOffset, genesisHash, hardwareType, name }) {
|
|
44
|
-
ui_keyring_1.
|
|
43
|
+
ui_keyring_1.keyring.addHardware(address, hardwareType, { accountIndex, addressOffset, genesisHash, name });
|
|
45
44
|
return true;
|
|
46
45
|
}
|
|
47
46
|
accountsCreateSuri({ genesisHash, name, password, suri, type }) {
|
|
48
|
-
ui_keyring_1.
|
|
47
|
+
ui_keyring_1.keyring.addUri(getSuri(suri, type), password, { genesisHash, name }, type);
|
|
49
48
|
return true;
|
|
50
49
|
}
|
|
51
50
|
accountsChangePassword({ address, newPass, oldPass }) {
|
|
52
|
-
const pair = ui_keyring_1.
|
|
51
|
+
const pair = ui_keyring_1.keyring.getPair(address);
|
|
53
52
|
(0, util_1.assert)(pair, 'Unable to find pair');
|
|
54
53
|
try {
|
|
55
54
|
if (!pair.isLocked) {
|
|
@@ -60,37 +59,38 @@ class Extension {
|
|
|
60
59
|
catch {
|
|
61
60
|
throw new Error('oldPass is invalid');
|
|
62
61
|
}
|
|
63
|
-
ui_keyring_1.
|
|
62
|
+
ui_keyring_1.keyring.encryptAccount(pair, newPass);
|
|
64
63
|
return true;
|
|
65
64
|
}
|
|
66
65
|
accountsEdit({ address, name }) {
|
|
67
|
-
const pair = ui_keyring_1.
|
|
66
|
+
const pair = ui_keyring_1.keyring.getPair(address);
|
|
68
67
|
(0, util_1.assert)(pair, 'Unable to find pair');
|
|
69
|
-
ui_keyring_1.
|
|
68
|
+
ui_keyring_1.keyring.saveAccountMeta(pair, { ...pair.meta, name });
|
|
70
69
|
return true;
|
|
71
70
|
}
|
|
72
71
|
accountsExport({ address, password }) {
|
|
73
|
-
return { exportedJson: ui_keyring_1.
|
|
72
|
+
return { exportedJson: ui_keyring_1.keyring.backupAccount(ui_keyring_1.keyring.getPair(address), password) };
|
|
74
73
|
}
|
|
75
74
|
async accountsBatchExport({ addresses, password }) {
|
|
76
75
|
return {
|
|
77
|
-
exportedJson: await ui_keyring_1.
|
|
76
|
+
exportedJson: await ui_keyring_1.keyring.backupAccounts(addresses, password)
|
|
78
77
|
};
|
|
79
78
|
}
|
|
80
|
-
accountsForget({ address }) {
|
|
79
|
+
async accountsForget({ address }) {
|
|
81
80
|
const authorizedAccountsDiff = [];
|
|
82
81
|
// cycle through authUrls and prepare the array of diff
|
|
83
82
|
Object.entries(this.__internal__state.authUrls).forEach(([url, urlInfo]) => {
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
// Note that urlInfo.authorizedAccounts may be undefined if this website entry
|
|
84
|
+
// was created before the "account authorization per website" functionality was introduced
|
|
85
|
+
if (urlInfo.authorizedAccounts?.includes(address)) {
|
|
86
|
+
authorizedAccountsDiff.push([url, urlInfo.authorizedAccounts.filter((previousAddress) => previousAddress !== address)]);
|
|
86
87
|
}
|
|
87
|
-
authorizedAccountsDiff.push([url, urlInfo.authorizedAccounts.filter((previousAddress) => previousAddress !== address)]);
|
|
88
88
|
});
|
|
89
|
-
this.__internal__state.updateAuthorizedAccounts(authorizedAccountsDiff);
|
|
89
|
+
await this.__internal__state.updateAuthorizedAccounts(authorizedAccountsDiff);
|
|
90
90
|
// cycle through default account selection for auth and remove any occurrence of the account
|
|
91
91
|
const newDefaultAuthAccounts = this.__internal__state.defaultAuthAccountSelection.filter((defaultSelectionAddress) => defaultSelectionAddress !== address);
|
|
92
|
-
this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
|
|
93
|
-
ui_keyring_1.
|
|
92
|
+
await this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
|
|
93
|
+
ui_keyring_1.keyring.forgetAccount(address);
|
|
94
94
|
return true;
|
|
95
95
|
}
|
|
96
96
|
refreshAccountPasswordCache(pair) {
|
|
@@ -105,20 +105,20 @@ class Extension {
|
|
|
105
105
|
return remainingTime;
|
|
106
106
|
}
|
|
107
107
|
accountsShow({ address, isShowing }) {
|
|
108
|
-
const pair = ui_keyring_1.
|
|
108
|
+
const pair = ui_keyring_1.keyring.getPair(address);
|
|
109
109
|
(0, util_1.assert)(pair, 'Unable to find pair');
|
|
110
|
-
ui_keyring_1.
|
|
110
|
+
ui_keyring_1.keyring.saveAccountMeta(pair, { ...pair.meta, isHidden: !isShowing });
|
|
111
111
|
return true;
|
|
112
112
|
}
|
|
113
113
|
accountsTie({ address, genesisHash }) {
|
|
114
|
-
const pair = ui_keyring_1.
|
|
114
|
+
const pair = ui_keyring_1.keyring.getPair(address);
|
|
115
115
|
(0, util_1.assert)(pair, 'Unable to find pair');
|
|
116
|
-
ui_keyring_1.
|
|
116
|
+
ui_keyring_1.keyring.saveAccountMeta(pair, { ...pair.meta, genesisHash });
|
|
117
117
|
return true;
|
|
118
118
|
}
|
|
119
119
|
accountsValidate({ address, password }) {
|
|
120
120
|
try {
|
|
121
|
-
ui_keyring_1.
|
|
121
|
+
ui_keyring_1.keyring.backupAccount(ui_keyring_1.keyring.getPair(address), password);
|
|
122
122
|
return true;
|
|
123
123
|
}
|
|
124
124
|
catch {
|
|
@@ -141,8 +141,8 @@ class Extension {
|
|
|
141
141
|
resolve({ authorizedAccounts, result: true });
|
|
142
142
|
return true;
|
|
143
143
|
}
|
|
144
|
-
authorizeUpdate({ authorizedAccounts, url }) {
|
|
145
|
-
return this.__internal__state.updateAuthorizedAccounts([[url, authorizedAccounts]]);
|
|
144
|
+
async authorizeUpdate({ authorizedAccounts, url }) {
|
|
145
|
+
return await this.__internal__state.updateAuthorizedAccounts([[url, authorizedAccounts]]);
|
|
146
146
|
}
|
|
147
147
|
getAuthList() {
|
|
148
148
|
return { list: this.__internal__state.authUrls };
|
|
@@ -157,11 +157,11 @@ class Extension {
|
|
|
157
157
|
});
|
|
158
158
|
return true;
|
|
159
159
|
}
|
|
160
|
-
metadataApprove({ id }) {
|
|
160
|
+
async metadataApprove({ id }) {
|
|
161
161
|
const queued = this.__internal__state.getMetaRequest(id);
|
|
162
162
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
163
163
|
const { request, resolve } = queued;
|
|
164
|
-
this.__internal__state.saveMetadata(request);
|
|
164
|
+
await this.__internal__state.saveMetadata(request);
|
|
165
165
|
resolve(true);
|
|
166
166
|
return true;
|
|
167
167
|
}
|
|
@@ -189,7 +189,7 @@ class Extension {
|
|
|
189
189
|
}
|
|
190
190
|
jsonRestore({ file, password }) {
|
|
191
191
|
try {
|
|
192
|
-
ui_keyring_1.
|
|
192
|
+
ui_keyring_1.keyring.restoreAccount(file, password);
|
|
193
193
|
}
|
|
194
194
|
catch (error) {
|
|
195
195
|
throw new Error(error.message);
|
|
@@ -197,7 +197,7 @@ class Extension {
|
|
|
197
197
|
}
|
|
198
198
|
batchRestore({ file, password }) {
|
|
199
199
|
try {
|
|
200
|
-
ui_keyring_1.
|
|
200
|
+
ui_keyring_1.keyring.restoreAccounts(file, password);
|
|
201
201
|
}
|
|
202
202
|
catch (error) {
|
|
203
203
|
throw new Error(error.message);
|
|
@@ -205,7 +205,7 @@ class Extension {
|
|
|
205
205
|
}
|
|
206
206
|
jsonGetAccountInfo(json) {
|
|
207
207
|
try {
|
|
208
|
-
const { address, meta: { genesisHash, name }, type } = ui_keyring_1.
|
|
208
|
+
const { address, meta: { genesisHash, name }, type } = ui_keyring_1.keyring.createFromJson(json);
|
|
209
209
|
return {
|
|
210
210
|
address,
|
|
211
211
|
genesisHash,
|
|
@@ -221,7 +221,7 @@ class Extension {
|
|
|
221
221
|
seedCreate({ length = SEED_DEFAULT_LENGTH, seed: _seed, type }) {
|
|
222
222
|
const seed = _seed || (0, util_crypto_1.mnemonicGenerate)(length);
|
|
223
223
|
return {
|
|
224
|
-
address: ui_keyring_1.
|
|
224
|
+
address: ui_keyring_1.keyring.createFromUri(getSuri(seed, type), {}, type).address,
|
|
225
225
|
seed
|
|
226
226
|
};
|
|
227
227
|
}
|
|
@@ -236,7 +236,7 @@ class Extension {
|
|
|
236
236
|
(0, util_1.assert)((0, util_crypto_1.mnemonicValidate)(phrase), 'Not a valid mnemonic seed');
|
|
237
237
|
}
|
|
238
238
|
return {
|
|
239
|
-
address: ui_keyring_1.
|
|
239
|
+
address: ui_keyring_1.keyring.createFromUri(getSuri(suri, type), {}, type).address,
|
|
240
240
|
suri
|
|
241
241
|
};
|
|
242
242
|
}
|
|
@@ -244,7 +244,7 @@ class Extension {
|
|
|
244
244
|
const queued = this.__internal__state.getSignRequest(id);
|
|
245
245
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
246
246
|
const { reject, request, resolve } = queued;
|
|
247
|
-
const pair = ui_keyring_1.
|
|
247
|
+
const pair = ui_keyring_1.keyring.getPair(queued.account.address);
|
|
248
248
|
if (!pair) {
|
|
249
249
|
reject(new Error('Unable to find pair'));
|
|
250
250
|
return false;
|
|
@@ -313,7 +313,7 @@ class Extension {
|
|
|
313
313
|
const queued = this.__internal__state.getSignRequest(id);
|
|
314
314
|
(0, util_1.assert)(queued, 'Unable to find request');
|
|
315
315
|
const address = queued.request.payload.address;
|
|
316
|
-
const pair = ui_keyring_1.
|
|
316
|
+
const pair = ui_keyring_1.keyring.getPair(address);
|
|
317
317
|
(0, util_1.assert)(pair, 'Unable to find pair');
|
|
318
318
|
const remainingTime = this.refreshAccountPasswordCache(pair);
|
|
319
319
|
return {
|
|
@@ -332,7 +332,7 @@ class Extension {
|
|
|
332
332
|
return true;
|
|
333
333
|
}
|
|
334
334
|
windowOpen(path) {
|
|
335
|
-
const url = `${chrome.
|
|
335
|
+
const url = `${chrome.runtime.getURL('index.html')}#${path}`;
|
|
336
336
|
if (!defaults_1.ALLOWED_PATH.includes(path)) {
|
|
337
337
|
console.error('Not allowed to open the url:', url);
|
|
338
338
|
return false;
|
|
@@ -341,7 +341,7 @@ class Extension {
|
|
|
341
341
|
return true;
|
|
342
342
|
}
|
|
343
343
|
derive(parentAddress, suri, password, metadata) {
|
|
344
|
-
const parentPair = ui_keyring_1.
|
|
344
|
+
const parentPair = ui_keyring_1.keyring.getPair(parentAddress);
|
|
345
345
|
try {
|
|
346
346
|
parentPair.decodePkcs8(password);
|
|
347
347
|
}
|
|
@@ -369,11 +369,12 @@ class Extension {
|
|
|
369
369
|
parentAddress,
|
|
370
370
|
suri
|
|
371
371
|
});
|
|
372
|
-
ui_keyring_1.
|
|
372
|
+
ui_keyring_1.keyring.addPair(childPair, password);
|
|
373
373
|
return true;
|
|
374
374
|
}
|
|
375
|
-
removeAuthorization(url) {
|
|
376
|
-
|
|
375
|
+
async removeAuthorization(url) {
|
|
376
|
+
const remAuth = await this.__internal__state.removeAuthorization(url);
|
|
377
|
+
return { list: remAuth };
|
|
377
378
|
}
|
|
378
379
|
deleteAuthRequest(requestId) {
|
|
379
380
|
return this.__internal__state.deleteAuthRequest(requestId);
|
|
@@ -425,7 +426,7 @@ class Extension {
|
|
|
425
426
|
case 'pri(accounts.validate)':
|
|
426
427
|
return this.accountsValidate(request);
|
|
427
428
|
case 'pri(metadata.approve)':
|
|
428
|
-
return this.metadataApprove(request);
|
|
429
|
+
return await this.metadataApprove(request);
|
|
429
430
|
case 'pri(metadata.get)':
|
|
430
431
|
return this.metadataGet(request);
|
|
431
432
|
case 'pri(metadata.list)':
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotificationOptions = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const rxjs_1 = require("rxjs");
|
|
6
5
|
const extension_chains_1 = require("@polkadot/extension-chains");
|
|
7
6
|
const defaults_1 = require("@polkadot/networks/defaults");
|
|
8
|
-
const ui_settings_1 =
|
|
7
|
+
const ui_settings_1 = require("@polkadot/ui-settings");
|
|
9
8
|
const util_1 = require("@polkadot/util");
|
|
10
9
|
const index_js_1 = require("../../stores/index.js");
|
|
11
10
|
const getId_js_1 = require("../../utils/getId.js");
|
|
12
11
|
const helpers_js_1 = require("./helpers.js");
|
|
13
|
-
const NOTIFICATION_URL = chrome.
|
|
12
|
+
const NOTIFICATION_URL = chrome.runtime.getURL('notification.html');
|
|
14
13
|
const POPUP_WINDOW_OPTS = {
|
|
15
14
|
focused: true,
|
|
16
15
|
height: 621,
|
|
@@ -33,8 +32,8 @@ var NotificationOptions;
|
|
|
33
32
|
})(NotificationOptions || (exports.NotificationOptions = NotificationOptions = {}));
|
|
34
33
|
const AUTH_URLS_KEY = 'authUrls';
|
|
35
34
|
const DEFAULT_AUTH_ACCOUNTS = 'defaultAuthAccounts';
|
|
36
|
-
function extractMetadata(store) {
|
|
37
|
-
store.allMap((map) => {
|
|
35
|
+
async function extractMetadata(store) {
|
|
36
|
+
await store.allMap(async (map) => {
|
|
38
37
|
const knownEntries = Object.entries(defaults_1.knownGenesis);
|
|
39
38
|
const defs = {};
|
|
40
39
|
const removals = [];
|
|
@@ -60,7 +59,9 @@ function extractMetadata(store) {
|
|
|
60
59
|
defs[key] = { def, index: 0, key };
|
|
61
60
|
}
|
|
62
61
|
});
|
|
63
|
-
|
|
62
|
+
for (const key of removals) {
|
|
63
|
+
await store.remove(key);
|
|
64
|
+
}
|
|
64
65
|
Object.values(defs).forEach(({ def }) => (0, extension_chains_1.addMetadata)(def));
|
|
65
66
|
});
|
|
66
67
|
}
|
|
@@ -71,7 +72,7 @@ class State {
|
|
|
71
72
|
// Map of providers currently injected in tabs
|
|
72
73
|
__internal__injectedProviders = new Map();
|
|
73
74
|
__internal__metaRequests = {};
|
|
74
|
-
__internal__notification = ui_settings_1.
|
|
75
|
+
__internal__notification = ui_settings_1.settings.notification;
|
|
75
76
|
// Map of all providers exposed by the extension, they are retrievable by key
|
|
76
77
|
__internal__providers;
|
|
77
78
|
__internal__signRequests = {};
|
|
@@ -83,13 +84,17 @@ class State {
|
|
|
83
84
|
defaultAuthAccountSelection = [];
|
|
84
85
|
constructor(providers = {}) {
|
|
85
86
|
this.__internal__providers = providers;
|
|
86
|
-
|
|
87
|
+
}
|
|
88
|
+
async init() {
|
|
89
|
+
await extractMetadata(this.__internal__metaStore);
|
|
87
90
|
// retrieve previously set authorizations
|
|
88
|
-
const
|
|
91
|
+
const storageAuthUrls = await chrome.storage.local.get(AUTH_URLS_KEY);
|
|
92
|
+
const authString = storageAuthUrls?.[AUTH_URLS_KEY] || '{}';
|
|
89
93
|
const previousAuth = JSON.parse(authString);
|
|
90
94
|
this.__internal__authUrls = previousAuth;
|
|
91
95
|
// retrieve previously set default auth accounts
|
|
92
|
-
const
|
|
96
|
+
const storageDefaultAuthAccounts = await chrome.storage.local.get(DEFAULT_AUTH_ACCOUNTS);
|
|
97
|
+
const defaultAuthString = storageDefaultAuthAccounts?.[DEFAULT_AUTH_ACCOUNTS] || '[]';
|
|
93
98
|
const previousDefaultAuth = JSON.parse(defaultAuthString);
|
|
94
99
|
this.defaultAuthAccountSelection = previousDefaultAuth;
|
|
95
100
|
}
|
|
@@ -123,6 +128,9 @@ class State {
|
|
|
123
128
|
get authUrls() {
|
|
124
129
|
return this.__internal__authUrls;
|
|
125
130
|
}
|
|
131
|
+
set authUrls(urls) {
|
|
132
|
+
this.__internal__authUrls = urls;
|
|
133
|
+
}
|
|
126
134
|
popupClose() {
|
|
127
135
|
this.__internal__windows.forEach((id) => (0, helpers_js_1.withErrorLog)(() => chrome.windows.remove(id)));
|
|
128
136
|
this.__internal__windows = [];
|
|
@@ -138,7 +146,7 @@ class State {
|
|
|
138
146
|
});
|
|
139
147
|
}
|
|
140
148
|
authComplete = (id, resolve, reject) => {
|
|
141
|
-
const complete = (authorizedAccounts = []) => {
|
|
149
|
+
const complete = async (authorizedAccounts = []) => {
|
|
142
150
|
const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
|
|
143
151
|
this.__internal__authUrls[this.stripUrl(url)] = {
|
|
144
152
|
authorizedAccounts,
|
|
@@ -147,18 +155,20 @@ class State {
|
|
|
147
155
|
origin,
|
|
148
156
|
url
|
|
149
157
|
};
|
|
150
|
-
this.saveCurrentAuthList();
|
|
151
|
-
this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
158
|
+
await this.saveCurrentAuthList();
|
|
159
|
+
await this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
152
160
|
delete this.__internal__authRequests[id];
|
|
153
161
|
this.updateIconAuth(true);
|
|
154
162
|
};
|
|
155
163
|
return {
|
|
156
|
-
|
|
157
|
-
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
165
|
+
reject: async (error) => {
|
|
166
|
+
await complete();
|
|
158
167
|
reject(error);
|
|
159
168
|
},
|
|
160
|
-
|
|
161
|
-
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
170
|
+
resolve: async ({ authorizedAccounts, result }) => {
|
|
171
|
+
await complete(authorizedAccounts);
|
|
162
172
|
resolve({ authorizedAccounts, result });
|
|
163
173
|
}
|
|
164
174
|
};
|
|
@@ -188,15 +198,15 @@ class State {
|
|
|
188
198
|
delete this.__internal__authRequests[requestId];
|
|
189
199
|
this.updateIconAuth(true);
|
|
190
200
|
}
|
|
191
|
-
saveCurrentAuthList() {
|
|
192
|
-
|
|
201
|
+
async saveCurrentAuthList() {
|
|
202
|
+
await chrome.storage.local.set({ [AUTH_URLS_KEY]: JSON.stringify(this.__internal__authUrls) });
|
|
193
203
|
}
|
|
194
|
-
saveDefaultAuthAccounts() {
|
|
195
|
-
|
|
204
|
+
async saveDefaultAuthAccounts() {
|
|
205
|
+
await chrome.storage.local.set({ [DEFAULT_AUTH_ACCOUNTS]: JSON.stringify(this.defaultAuthAccountSelection) });
|
|
196
206
|
}
|
|
197
|
-
updateDefaultAuthAccounts(newList) {
|
|
207
|
+
async updateDefaultAuthAccounts(newList) {
|
|
198
208
|
this.defaultAuthAccountSelection = newList;
|
|
199
|
-
this.saveDefaultAuthAccounts();
|
|
209
|
+
await this.saveDefaultAuthAccounts();
|
|
200
210
|
}
|
|
201
211
|
metaComplete = (id, resolve, reject) => {
|
|
202
212
|
const complete = () => {
|
|
@@ -244,16 +254,16 @@ class State {
|
|
|
244
254
|
: metaCount
|
|
245
255
|
? 'Meta'
|
|
246
256
|
: (signCount ? `${signCount}` : ''));
|
|
247
|
-
(0, helpers_js_1.withErrorLog)(() => chrome.
|
|
257
|
+
(0, helpers_js_1.withErrorLog)(() => chrome.action.setBadgeText({ text }));
|
|
248
258
|
if (shouldClose && text === '') {
|
|
249
259
|
this.popupClose();
|
|
250
260
|
}
|
|
251
261
|
}
|
|
252
|
-
removeAuthorization(url) {
|
|
262
|
+
async removeAuthorization(url) {
|
|
253
263
|
const entry = this.__internal__authUrls[url];
|
|
254
264
|
(0, util_1.assert)(entry, `The source ${url} is not known`);
|
|
255
265
|
delete this.__internal__authUrls[url];
|
|
256
|
-
this.saveCurrentAuthList();
|
|
266
|
+
await this.saveCurrentAuthList();
|
|
257
267
|
return this.__internal__authUrls;
|
|
258
268
|
}
|
|
259
269
|
updateIconAuth(shouldClose) {
|
|
@@ -268,11 +278,11 @@ class State {
|
|
|
268
278
|
this.signSubject.next(this.allSignRequests);
|
|
269
279
|
this.updateIcon(shouldClose);
|
|
270
280
|
}
|
|
271
|
-
updateAuthorizedAccounts(authorizedAccountDiff) {
|
|
281
|
+
async updateAuthorizedAccounts(authorizedAccountDiff) {
|
|
272
282
|
authorizedAccountDiff.forEach(([url, authorizedAccountDiff]) => {
|
|
273
283
|
this.__internal__authUrls[url].authorizedAccounts = authorizedAccountDiff;
|
|
274
284
|
});
|
|
275
|
-
this.saveCurrentAuthList();
|
|
285
|
+
await this.saveCurrentAuthList();
|
|
276
286
|
}
|
|
277
287
|
async authorizeUrl(url, request) {
|
|
278
288
|
const idStr = this.stripUrl(url);
|
|
@@ -376,8 +386,8 @@ class State {
|
|
|
376
386
|
(0, util_1.assert)(provider, 'Cannot call pub(rpc.unsubscribe) before provider is set');
|
|
377
387
|
return provider.unsubscribe(request.type, request.method, request.subscriptionId);
|
|
378
388
|
}
|
|
379
|
-
saveMetadata(meta) {
|
|
380
|
-
this.__internal__metaStore.set(meta.genesisHash, meta);
|
|
389
|
+
async saveMetadata(meta) {
|
|
390
|
+
await this.__internal__metaStore.set(meta.genesisHash, meta);
|
|
381
391
|
(0, extension_chains_1.addMetadata)(meta);
|
|
382
392
|
}
|
|
383
393
|
setNotification(notification) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const phishing_1 = require("@polkadot/phishing");
|
|
5
|
-
const ui_keyring_1 =
|
|
5
|
+
const ui_keyring_1 = require("@polkadot/ui-keyring");
|
|
6
6
|
const accounts_1 = require("@polkadot/ui-keyring/observable/accounts");
|
|
7
7
|
const util_1 = require("@polkadot/util");
|
|
8
8
|
const defaults_js_1 = require("../../defaults.js");
|
|
@@ -70,7 +70,7 @@ class Tabs {
|
|
|
70
70
|
return true;
|
|
71
71
|
}
|
|
72
72
|
getSigningPair(address) {
|
|
73
|
-
const pair = ui_keyring_1.
|
|
73
|
+
const pair = ui_keyring_1.keyring.getPair(address);
|
|
74
74
|
(0, util_1.assert)(pair, 'Unable to find keypair');
|
|
75
75
|
return pair;
|
|
76
76
|
}
|
|
@@ -127,7 +127,7 @@ class Tabs {
|
|
|
127
127
|
redirectPhishingLanding(phishingWebsite) {
|
|
128
128
|
const nonFragment = phishingWebsite.split('#')[0];
|
|
129
129
|
const encodedWebsite = encodeURIComponent(nonFragment);
|
|
130
|
-
const url = `${chrome.
|
|
130
|
+
const url = `${chrome.runtime.getURL('index.html')}#${defaults_js_1.PHISHING_PAGE_REDIRECT}/${encodedWebsite}`;
|
|
131
131
|
chrome.tabs.query({ url: nonFragment }, (tabs) => {
|
|
132
132
|
tabs
|
|
133
133
|
.map(({ id }) => id)
|
|
@@ -10,6 +10,7 @@ const Tabs_js_1 = tslib_1.__importDefault(require("./Tabs.js"));
|
|
|
10
10
|
var helpers_js_1 = require("./helpers.js");
|
|
11
11
|
Object.defineProperty(exports, "withErrorLog", { enumerable: true, get: function () { return helpers_js_1.withErrorLog; } });
|
|
12
12
|
const state = new State_js_1.default();
|
|
13
|
+
await state.init();
|
|
13
14
|
const extension = new Extension_js_1.default(state);
|
|
14
15
|
const tabs = new Tabs_js_1.default(state);
|
|
15
16
|
function handler({ id, message, request }, port, extensionPortName = defaults_js_1.PORT_EXTENSION) {
|
package/cjs/packageInfo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.packageInfo = void 0;
|
|
4
|
-
exports.packageInfo = { name: '@polkadot/extension-base', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '0.
|
|
4
|
+
exports.packageInfo = { name: '@polkadot/extension-base', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '0.49.1' };
|
package/cjs/stores/Accounts.js
CHANGED
|
@@ -9,13 +9,13 @@ class AccountsStore extends Base_js_1.default {
|
|
|
9
9
|
? `${defaults_js_1.EXTENSION_PREFIX}accounts`
|
|
10
10
|
: null);
|
|
11
11
|
}
|
|
12
|
-
set(key, value, update) {
|
|
12
|
+
async set(key, value, update) {
|
|
13
13
|
// shortcut, don't save testing accounts in extension storage
|
|
14
14
|
if (key.startsWith('account:') && value.meta && value.meta.isTesting) {
|
|
15
15
|
update && update();
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
super.set(key, value, update);
|
|
18
|
+
await super.set(key, value, update);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.default = AccountsStore;
|
package/cjs/stores/Base.js
CHANGED
|
@@ -11,15 +11,17 @@ class BaseStore {
|
|
|
11
11
|
constructor(prefix) {
|
|
12
12
|
this.__internal__prefix = prefix ? `${prefix}:` : '';
|
|
13
13
|
}
|
|
14
|
-
all(update) {
|
|
15
|
-
this.allMap((map) => {
|
|
16
|
-
Object.entries(map)
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
async all(update) {
|
|
15
|
+
await this.allMap(async (map) => {
|
|
16
|
+
const entries = Object.entries(map);
|
|
17
|
+
for (const [key, value] of entries) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
19
|
+
await update(key, value);
|
|
20
|
+
}
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
|
-
allMap(update) {
|
|
22
|
-
chrome.storage.local.get(null
|
|
23
|
+
async allMap(update) {
|
|
24
|
+
await chrome.storage.local.get(null).then(async (result) => {
|
|
23
25
|
lastError('all');
|
|
24
26
|
const entries = Object.entries(result);
|
|
25
27
|
const map = {};
|
|
@@ -29,28 +31,39 @@ class BaseStore {
|
|
|
29
31
|
map[key.replace(this.__internal__prefix, '')] = value;
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
|
-
update(map);
|
|
34
|
+
await update(map);
|
|
35
|
+
}).catch(({ message }) => {
|
|
36
|
+
console.error(`BaseStore error within allMap: ${message}`);
|
|
33
37
|
});
|
|
34
38
|
}
|
|
35
|
-
get(key, update) {
|
|
39
|
+
async get(key, update) {
|
|
36
40
|
const prefixedKey = `${this.__internal__prefix}${key}`;
|
|
37
|
-
chrome.storage.local.get([prefixedKey]
|
|
41
|
+
await chrome.storage.local.get([prefixedKey]).then(async (result) => {
|
|
38
42
|
lastError('get');
|
|
39
|
-
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
44
|
+
await update(result[prefixedKey]);
|
|
45
|
+
}).catch(({ message }) => {
|
|
46
|
+
console.error(`BaseStore error within get: ${message}`);
|
|
40
47
|
});
|
|
41
48
|
}
|
|
42
|
-
remove(key, update) {
|
|
49
|
+
async remove(key, update) {
|
|
43
50
|
const prefixedKey = `${this.__internal__prefix}${key}`;
|
|
44
|
-
chrome.storage.local.remove(prefixedKey
|
|
51
|
+
await chrome.storage.local.remove(prefixedKey).then(async () => {
|
|
45
52
|
lastError('remove');
|
|
46
|
-
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
54
|
+
update && await update();
|
|
55
|
+
}).catch(({ message }) => {
|
|
56
|
+
console.error(`BaseStore error within remove: ${message}`);
|
|
47
57
|
});
|
|
48
58
|
}
|
|
49
|
-
set(key, value, update) {
|
|
59
|
+
async set(key, value, update) {
|
|
50
60
|
const prefixedKey = `${this.__internal__prefix}${key}`;
|
|
51
|
-
chrome.storage.local.set({ [prefixedKey]: value }
|
|
61
|
+
await chrome.storage.local.set({ [prefixedKey]: value }).then(async () => {
|
|
52
62
|
lastError('set');
|
|
53
|
-
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
64
|
+
update && await update();
|
|
65
|
+
}).catch(({ message }) => {
|
|
66
|
+
console.error(`BaseStore error within set: ${message}`);
|
|
54
67
|
});
|
|
55
68
|
}
|
|
56
69
|
}
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"./cjs/packageDetect.js"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"version": "0.
|
|
21
|
+
"version": "0.49.1",
|
|
22
22
|
"main": "./cjs/index.js",
|
|
23
23
|
"module": "./index.js",
|
|
24
24
|
"types": "./index.d.ts",
|
|
@@ -217,19 +217,19 @@
|
|
|
217
217
|
}
|
|
218
218
|
},
|
|
219
219
|
"dependencies": {
|
|
220
|
-
"@polkadot/api": "^12.
|
|
221
|
-
"@polkadot/extension-chains": "0.
|
|
222
|
-
"@polkadot/extension-dapp": "0.
|
|
223
|
-
"@polkadot/extension-inject": "0.
|
|
224
|
-
"@polkadot/keyring": "^
|
|
225
|
-
"@polkadot/networks": "^
|
|
226
|
-
"@polkadot/phishing": "^0.
|
|
227
|
-
"@polkadot/rpc-provider": "^12.
|
|
228
|
-
"@polkadot/types": "^12.
|
|
229
|
-
"@polkadot/ui-keyring": "^3.
|
|
230
|
-
"@polkadot/ui-settings": "^3.
|
|
231
|
-
"@polkadot/util": "^
|
|
232
|
-
"@polkadot/util-crypto": "^
|
|
220
|
+
"@polkadot/api": "^12.2.1",
|
|
221
|
+
"@polkadot/extension-chains": "0.49.1",
|
|
222
|
+
"@polkadot/extension-dapp": "0.49.1",
|
|
223
|
+
"@polkadot/extension-inject": "0.49.1",
|
|
224
|
+
"@polkadot/keyring": "^13.0.2",
|
|
225
|
+
"@polkadot/networks": "^13.0.2",
|
|
226
|
+
"@polkadot/phishing": "^0.23.1",
|
|
227
|
+
"@polkadot/rpc-provider": "^12.2.1",
|
|
228
|
+
"@polkadot/types": "^12.2.1",
|
|
229
|
+
"@polkadot/ui-keyring": "^3.7.1",
|
|
230
|
+
"@polkadot/ui-settings": "^3.7.1",
|
|
231
|
+
"@polkadot/util": "^13.0.2",
|
|
232
|
+
"@polkadot/util-crypto": "^13.0.2",
|
|
233
233
|
"eventemitter3": "^5.0.1",
|
|
234
234
|
"rxjs": "^7.8.1",
|
|
235
235
|
"tslib": "^2.6.2"
|
package/packageInfo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const packageInfo = { name: '@polkadot/extension-base', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '0.
|
|
1
|
+
export const packageInfo = { name: '@polkadot/extension-base', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '0.49.1' };
|
package/stores/Accounts.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { KeyringJson, KeyringStore } from '@polkadot/ui-keyring/types';
|
|
|
2
2
|
import BaseStore from './Base.js';
|
|
3
3
|
export default class AccountsStore extends BaseStore<KeyringJson> implements KeyringStore {
|
|
4
4
|
constructor();
|
|
5
|
-
set(key: string, value: KeyringJson, update?: () => void): void
|
|
5
|
+
set(key: string, value: KeyringJson, update?: () => void): Promise<void>;
|
|
6
6
|
}
|
package/stores/Accounts.js
CHANGED
|
@@ -6,12 +6,12 @@ export default class AccountsStore extends BaseStore {
|
|
|
6
6
|
? `${EXTENSION_PREFIX}accounts`
|
|
7
7
|
: null);
|
|
8
8
|
}
|
|
9
|
-
set(key, value, update) {
|
|
9
|
+
async set(key, value, update) {
|
|
10
10
|
// shortcut, don't save testing accounts in extension storage
|
|
11
11
|
if (key.startsWith('account:') && value.meta && value.meta.isTesting) {
|
|
12
12
|
update && update();
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
super.set(key, value, update);
|
|
15
|
+
await super.set(key, value, update);
|
|
16
16
|
}
|
|
17
17
|
}
|
package/stores/Base.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export default abstract class BaseStore<T> {
|
|
2
2
|
#private;
|
|
3
3
|
constructor(prefix: string | null);
|
|
4
|
-
all(update: (key: string, value: T) => void): void
|
|
5
|
-
allMap(update: (value: Record<string, T>) => void): void
|
|
6
|
-
get(key: string, update: (value: T) => void): void
|
|
7
|
-
remove(key: string, update?: () => void): void
|
|
8
|
-
set(key: string, value: T, update?: () => void): void
|
|
4
|
+
all(update: (key: string, value: T) => void): Promise<void>;
|
|
5
|
+
allMap(update: (value: Record<string, T>) => Promise<void>): Promise<void>;
|
|
6
|
+
get(key: string, update: (value: T) => void): Promise<void>;
|
|
7
|
+
remove(key: string, update?: () => void): Promise<void>;
|
|
8
|
+
set(key: string, value: T, update?: () => void): Promise<void>;
|
|
9
9
|
}
|
package/stores/Base.js
CHANGED
|
@@ -9,15 +9,17 @@ export default class BaseStore {
|
|
|
9
9
|
constructor(prefix) {
|
|
10
10
|
this.__internal__prefix = prefix ? `${prefix}:` : '';
|
|
11
11
|
}
|
|
12
|
-
all(update) {
|
|
13
|
-
this.allMap((map) => {
|
|
14
|
-
Object.entries(map)
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
async all(update) {
|
|
13
|
+
await this.allMap(async (map) => {
|
|
14
|
+
const entries = Object.entries(map);
|
|
15
|
+
for (const [key, value] of entries) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
17
|
+
await update(key, value);
|
|
18
|
+
}
|
|
17
19
|
});
|
|
18
20
|
}
|
|
19
|
-
allMap(update) {
|
|
20
|
-
chrome.storage.local.get(null
|
|
21
|
+
async allMap(update) {
|
|
22
|
+
await chrome.storage.local.get(null).then(async (result) => {
|
|
21
23
|
lastError('all');
|
|
22
24
|
const entries = Object.entries(result);
|
|
23
25
|
const map = {};
|
|
@@ -27,28 +29,39 @@ export default class BaseStore {
|
|
|
27
29
|
map[key.replace(this.__internal__prefix, '')] = value;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
update(map);
|
|
32
|
+
await update(map);
|
|
33
|
+
}).catch(({ message }) => {
|
|
34
|
+
console.error(`BaseStore error within allMap: ${message}`);
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
|
-
get(key, update) {
|
|
37
|
+
async get(key, update) {
|
|
34
38
|
const prefixedKey = `${this.__internal__prefix}${key}`;
|
|
35
|
-
chrome.storage.local.get([prefixedKey]
|
|
39
|
+
await chrome.storage.local.get([prefixedKey]).then(async (result) => {
|
|
36
40
|
lastError('get');
|
|
37
|
-
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
42
|
+
await update(result[prefixedKey]);
|
|
43
|
+
}).catch(({ message }) => {
|
|
44
|
+
console.error(`BaseStore error within get: ${message}`);
|
|
38
45
|
});
|
|
39
46
|
}
|
|
40
|
-
remove(key, update) {
|
|
47
|
+
async remove(key, update) {
|
|
41
48
|
const prefixedKey = `${this.__internal__prefix}${key}`;
|
|
42
|
-
chrome.storage.local.remove(prefixedKey
|
|
49
|
+
await chrome.storage.local.remove(prefixedKey).then(async () => {
|
|
43
50
|
lastError('remove');
|
|
44
|
-
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
52
|
+
update && await update();
|
|
53
|
+
}).catch(({ message }) => {
|
|
54
|
+
console.error(`BaseStore error within remove: ${message}`);
|
|
45
55
|
});
|
|
46
56
|
}
|
|
47
|
-
set(key, value, update) {
|
|
57
|
+
async set(key, value, update) {
|
|
48
58
|
const prefixedKey = `${this.__internal__prefix}${key}`;
|
|
49
|
-
chrome.storage.local.set({ [prefixedKey]: value }
|
|
59
|
+
await chrome.storage.local.set({ [prefixedKey]: value }).then(async () => {
|
|
50
60
|
lastError('set');
|
|
51
|
-
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
62
|
+
update && await update();
|
|
63
|
+
}).catch(({ message }) => {
|
|
64
|
+
console.error(`BaseStore error within set: ${message}`);
|
|
52
65
|
});
|
|
53
66
|
}
|
|
54
67
|
}
|