@polkadot/extension-base 0.48.2 → 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 +12 -11
- package/background/handlers/State.d.ts +6 -4
- package/background/handlers/State.js +38 -27
- package/background/handlers/Tabs.js +1 -1
- package/background/handlers/index.js +1 -0
- package/cjs/background/handlers/Extension.js +12 -11
- package/cjs/background/handlers/State.js +38 -27
- package/cjs/background/handlers/Tabs.js +1 -1
- 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.
|
|
@@ -74,7 +74,7 @@ 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]) => {
|
|
@@ -84,10 +84,10 @@ export default class Extension {
|
|
|
84
84
|
authorizedAccountsDiff.push([url, urlInfo.authorizedAccounts.filter((previousAddress) => previousAddress !== address)]);
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
|
-
this.__internal__state.updateAuthorizedAccounts(authorizedAccountsDiff);
|
|
87
|
+
await this.__internal__state.updateAuthorizedAccounts(authorizedAccountsDiff);
|
|
88
88
|
// cycle through default account selection for auth and remove any occurrence of the account
|
|
89
89
|
const newDefaultAuthAccounts = this.__internal__state.defaultAuthAccountSelection.filter((defaultSelectionAddress) => defaultSelectionAddress !== address);
|
|
90
|
-
this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
|
|
90
|
+
await this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
|
|
91
91
|
keyring.forgetAccount(address);
|
|
92
92
|
return true;
|
|
93
93
|
}
|
|
@@ -139,8 +139,8 @@ export default class Extension {
|
|
|
139
139
|
resolve({ authorizedAccounts, result: true });
|
|
140
140
|
return true;
|
|
141
141
|
}
|
|
142
|
-
authorizeUpdate({ authorizedAccounts, url }) {
|
|
143
|
-
return this.__internal__state.updateAuthorizedAccounts([[url, authorizedAccounts]]);
|
|
142
|
+
async authorizeUpdate({ authorizedAccounts, url }) {
|
|
143
|
+
return await this.__internal__state.updateAuthorizedAccounts([[url, authorizedAccounts]]);
|
|
144
144
|
}
|
|
145
145
|
getAuthList() {
|
|
146
146
|
return { list: this.__internal__state.authUrls };
|
|
@@ -155,11 +155,11 @@ export default class Extension {
|
|
|
155
155
|
});
|
|
156
156
|
return true;
|
|
157
157
|
}
|
|
158
|
-
metadataApprove({ id }) {
|
|
158
|
+
async metadataApprove({ id }) {
|
|
159
159
|
const queued = this.__internal__state.getMetaRequest(id);
|
|
160
160
|
assert(queued, 'Unable to find request');
|
|
161
161
|
const { request, resolve } = queued;
|
|
162
|
-
this.__internal__state.saveMetadata(request);
|
|
162
|
+
await this.__internal__state.saveMetadata(request);
|
|
163
163
|
resolve(true);
|
|
164
164
|
return true;
|
|
165
165
|
}
|
|
@@ -330,7 +330,7 @@ export default class Extension {
|
|
|
330
330
|
return true;
|
|
331
331
|
}
|
|
332
332
|
windowOpen(path) {
|
|
333
|
-
const url = `${chrome.
|
|
333
|
+
const url = `${chrome.runtime.getURL('index.html')}#${path}`;
|
|
334
334
|
if (!ALLOWED_PATH.includes(path)) {
|
|
335
335
|
console.error('Not allowed to open the url:', url);
|
|
336
336
|
return false;
|
|
@@ -370,8 +370,9 @@ export default class Extension {
|
|
|
370
370
|
keyring.addPair(childPair, password);
|
|
371
371
|
return true;
|
|
372
372
|
}
|
|
373
|
-
removeAuthorization(url) {
|
|
374
|
-
|
|
373
|
+
async removeAuthorization(url) {
|
|
374
|
+
const remAuth = await this.__internal__state.removeAuthorization(url);
|
|
375
|
+
return { list: remAuth };
|
|
375
376
|
}
|
|
376
377
|
deleteAuthRequest(requestId) {
|
|
377
378
|
return this.__internal__state.deleteAuthRequest(requestId);
|
|
@@ -423,7 +424,7 @@ export default class Extension {
|
|
|
423
424
|
case 'pri(accounts.validate)':
|
|
424
425
|
return this.accountsValidate(request);
|
|
425
426
|
case 'pri(metadata.approve)':
|
|
426
|
-
return this.metadataApprove(request);
|
|
427
|
+
return await this.metadataApprove(request);
|
|
427
428
|
case 'pri(metadata.get)':
|
|
428
429
|
return this.metadataGet(request);
|
|
429
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
|
}
|
|
@@ -6,7 +6,7 @@ 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) {
|
|
@@ -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) {
|
|
@@ -76,7 +76,7 @@ class Extension {
|
|
|
76
76
|
exportedJson: await ui_keyring_1.keyring.backupAccounts(addresses, password)
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
accountsForget({ address }) {
|
|
79
|
+
async accountsForget({ address }) {
|
|
80
80
|
const authorizedAccountsDiff = [];
|
|
81
81
|
// cycle through authUrls and prepare the array of diff
|
|
82
82
|
Object.entries(this.__internal__state.authUrls).forEach(([url, urlInfo]) => {
|
|
@@ -86,10 +86,10 @@ class Extension {
|
|
|
86
86
|
authorizedAccountsDiff.push([url, urlInfo.authorizedAccounts.filter((previousAddress) => previousAddress !== address)]);
|
|
87
87
|
}
|
|
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);
|
|
92
|
+
await this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
|
|
93
93
|
ui_keyring_1.keyring.forgetAccount(address);
|
|
94
94
|
return true;
|
|
95
95
|
}
|
|
@@ -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
|
}
|
|
@@ -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;
|
|
@@ -372,8 +372,9 @@ class Extension {
|
|
|
372
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)':
|
|
@@ -9,7 +9,7 @@ const util_1 = require("@polkadot/util");
|
|
|
9
9
|
const index_js_1 = require("../../stores/index.js");
|
|
10
10
|
const getId_js_1 = require("../../utils/getId.js");
|
|
11
11
|
const helpers_js_1 = require("./helpers.js");
|
|
12
|
-
const NOTIFICATION_URL = chrome.
|
|
12
|
+
const NOTIFICATION_URL = chrome.runtime.getURL('notification.html');
|
|
13
13
|
const POPUP_WINDOW_OPTS = {
|
|
14
14
|
focused: true,
|
|
15
15
|
height: 621,
|
|
@@ -32,8 +32,8 @@ var NotificationOptions;
|
|
|
32
32
|
})(NotificationOptions || (exports.NotificationOptions = NotificationOptions = {}));
|
|
33
33
|
const AUTH_URLS_KEY = 'authUrls';
|
|
34
34
|
const DEFAULT_AUTH_ACCOUNTS = 'defaultAuthAccounts';
|
|
35
|
-
function extractMetadata(store) {
|
|
36
|
-
store.allMap((map) => {
|
|
35
|
+
async function extractMetadata(store) {
|
|
36
|
+
await store.allMap(async (map) => {
|
|
37
37
|
const knownEntries = Object.entries(defaults_1.knownGenesis);
|
|
38
38
|
const defs = {};
|
|
39
39
|
const removals = [];
|
|
@@ -59,7 +59,9 @@ function extractMetadata(store) {
|
|
|
59
59
|
defs[key] = { def, index: 0, key };
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
for (const key of removals) {
|
|
63
|
+
await store.remove(key);
|
|
64
|
+
}
|
|
63
65
|
Object.values(defs).forEach(({ def }) => (0, extension_chains_1.addMetadata)(def));
|
|
64
66
|
});
|
|
65
67
|
}
|
|
@@ -82,13 +84,17 @@ class State {
|
|
|
82
84
|
defaultAuthAccountSelection = [];
|
|
83
85
|
constructor(providers = {}) {
|
|
84
86
|
this.__internal__providers = providers;
|
|
85
|
-
|
|
87
|
+
}
|
|
88
|
+
async init() {
|
|
89
|
+
await extractMetadata(this.__internal__metaStore);
|
|
86
90
|
// retrieve previously set authorizations
|
|
87
|
-
const
|
|
91
|
+
const storageAuthUrls = await chrome.storage.local.get(AUTH_URLS_KEY);
|
|
92
|
+
const authString = storageAuthUrls?.[AUTH_URLS_KEY] || '{}';
|
|
88
93
|
const previousAuth = JSON.parse(authString);
|
|
89
94
|
this.__internal__authUrls = previousAuth;
|
|
90
95
|
// retrieve previously set default auth accounts
|
|
91
|
-
const
|
|
96
|
+
const storageDefaultAuthAccounts = await chrome.storage.local.get(DEFAULT_AUTH_ACCOUNTS);
|
|
97
|
+
const defaultAuthString = storageDefaultAuthAccounts?.[DEFAULT_AUTH_ACCOUNTS] || '[]';
|
|
92
98
|
const previousDefaultAuth = JSON.parse(defaultAuthString);
|
|
93
99
|
this.defaultAuthAccountSelection = previousDefaultAuth;
|
|
94
100
|
}
|
|
@@ -122,6 +128,9 @@ class State {
|
|
|
122
128
|
get authUrls() {
|
|
123
129
|
return this.__internal__authUrls;
|
|
124
130
|
}
|
|
131
|
+
set authUrls(urls) {
|
|
132
|
+
this.__internal__authUrls = urls;
|
|
133
|
+
}
|
|
125
134
|
popupClose() {
|
|
126
135
|
this.__internal__windows.forEach((id) => (0, helpers_js_1.withErrorLog)(() => chrome.windows.remove(id)));
|
|
127
136
|
this.__internal__windows = [];
|
|
@@ -137,7 +146,7 @@ class State {
|
|
|
137
146
|
});
|
|
138
147
|
}
|
|
139
148
|
authComplete = (id, resolve, reject) => {
|
|
140
|
-
const complete = (authorizedAccounts = []) => {
|
|
149
|
+
const complete = async (authorizedAccounts = []) => {
|
|
141
150
|
const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
|
|
142
151
|
this.__internal__authUrls[this.stripUrl(url)] = {
|
|
143
152
|
authorizedAccounts,
|
|
@@ -146,18 +155,20 @@ class State {
|
|
|
146
155
|
origin,
|
|
147
156
|
url
|
|
148
157
|
};
|
|
149
|
-
this.saveCurrentAuthList();
|
|
150
|
-
this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
158
|
+
await this.saveCurrentAuthList();
|
|
159
|
+
await this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
151
160
|
delete this.__internal__authRequests[id];
|
|
152
161
|
this.updateIconAuth(true);
|
|
153
162
|
};
|
|
154
163
|
return {
|
|
155
|
-
|
|
156
|
-
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
165
|
+
reject: async (error) => {
|
|
166
|
+
await complete();
|
|
157
167
|
reject(error);
|
|
158
168
|
},
|
|
159
|
-
|
|
160
|
-
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
170
|
+
resolve: async ({ authorizedAccounts, result }) => {
|
|
171
|
+
await complete(authorizedAccounts);
|
|
161
172
|
resolve({ authorizedAccounts, result });
|
|
162
173
|
}
|
|
163
174
|
};
|
|
@@ -187,15 +198,15 @@ class State {
|
|
|
187
198
|
delete this.__internal__authRequests[requestId];
|
|
188
199
|
this.updateIconAuth(true);
|
|
189
200
|
}
|
|
190
|
-
saveCurrentAuthList() {
|
|
191
|
-
|
|
201
|
+
async saveCurrentAuthList() {
|
|
202
|
+
await chrome.storage.local.set({ [AUTH_URLS_KEY]: JSON.stringify(this.__internal__authUrls) });
|
|
192
203
|
}
|
|
193
|
-
saveDefaultAuthAccounts() {
|
|
194
|
-
|
|
204
|
+
async saveDefaultAuthAccounts() {
|
|
205
|
+
await chrome.storage.local.set({ [DEFAULT_AUTH_ACCOUNTS]: JSON.stringify(this.defaultAuthAccountSelection) });
|
|
195
206
|
}
|
|
196
|
-
updateDefaultAuthAccounts(newList) {
|
|
207
|
+
async updateDefaultAuthAccounts(newList) {
|
|
197
208
|
this.defaultAuthAccountSelection = newList;
|
|
198
|
-
this.saveDefaultAuthAccounts();
|
|
209
|
+
await this.saveDefaultAuthAccounts();
|
|
199
210
|
}
|
|
200
211
|
metaComplete = (id, resolve, reject) => {
|
|
201
212
|
const complete = () => {
|
|
@@ -243,16 +254,16 @@ class State {
|
|
|
243
254
|
: metaCount
|
|
244
255
|
? 'Meta'
|
|
245
256
|
: (signCount ? `${signCount}` : ''));
|
|
246
|
-
(0, helpers_js_1.withErrorLog)(() => chrome.
|
|
257
|
+
(0, helpers_js_1.withErrorLog)(() => chrome.action.setBadgeText({ text }));
|
|
247
258
|
if (shouldClose && text === '') {
|
|
248
259
|
this.popupClose();
|
|
249
260
|
}
|
|
250
261
|
}
|
|
251
|
-
removeAuthorization(url) {
|
|
262
|
+
async removeAuthorization(url) {
|
|
252
263
|
const entry = this.__internal__authUrls[url];
|
|
253
264
|
(0, util_1.assert)(entry, `The source ${url} is not known`);
|
|
254
265
|
delete this.__internal__authUrls[url];
|
|
255
|
-
this.saveCurrentAuthList();
|
|
266
|
+
await this.saveCurrentAuthList();
|
|
256
267
|
return this.__internal__authUrls;
|
|
257
268
|
}
|
|
258
269
|
updateIconAuth(shouldClose) {
|
|
@@ -267,11 +278,11 @@ class State {
|
|
|
267
278
|
this.signSubject.next(this.allSignRequests);
|
|
268
279
|
this.updateIcon(shouldClose);
|
|
269
280
|
}
|
|
270
|
-
updateAuthorizedAccounts(authorizedAccountDiff) {
|
|
281
|
+
async updateAuthorizedAccounts(authorizedAccountDiff) {
|
|
271
282
|
authorizedAccountDiff.forEach(([url, authorizedAccountDiff]) => {
|
|
272
283
|
this.__internal__authUrls[url].authorizedAccounts = authorizedAccountDiff;
|
|
273
284
|
});
|
|
274
|
-
this.saveCurrentAuthList();
|
|
285
|
+
await this.saveCurrentAuthList();
|
|
275
286
|
}
|
|
276
287
|
async authorizeUrl(url, request) {
|
|
277
288
|
const idStr = this.stripUrl(url);
|
|
@@ -375,8 +386,8 @@ class State {
|
|
|
375
386
|
(0, util_1.assert)(provider, 'Cannot call pub(rpc.unsubscribe) before provider is set');
|
|
376
387
|
return provider.unsubscribe(request.type, request.method, request.subscriptionId);
|
|
377
388
|
}
|
|
378
|
-
saveMetadata(meta) {
|
|
379
|
-
this.__internal__metaStore.set(meta.genesisHash, meta);
|
|
389
|
+
async saveMetadata(meta) {
|
|
390
|
+
await this.__internal__metaStore.set(meta.genesisHash, meta);
|
|
380
391
|
(0, extension_chains_1.addMetadata)(meta);
|
|
381
392
|
}
|
|
382
393
|
setNotification(notification) {
|
|
@@ -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
|
}
|