@metamask-previews/keyring-controller 21.0.6-preview-956e6bf8 → 21.0.6-preview-1341545b
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/CHANGELOG.md +5 -1
- package/dist/KeyringController.cjs +87 -87
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +5 -4
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +5 -4
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +88 -88
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **BREAKING** `keyringsMetadata` has been removed from the controller state ([#5725](https://github.com/MetaMask/core/pull/5725))
|
|
13
|
+
- The metadata is now stored in each keyring object in the `state.keyrings` array.
|
|
14
|
+
|
|
10
15
|
### Fixed
|
|
11
16
|
|
|
12
17
|
- Discard keyrings with duplicate accounts when unlock the wallet ([#5775](https://github.com/MetaMask/core/pull/5775))
|
|
13
|
-
- Metadata for unsupported keyring is removed on unlock ([#5725](https://github.com/MetaMask/core/pull/5725))
|
|
14
18
|
|
|
15
19
|
## [21.0.6]
|
|
16
20
|
|
|
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
36
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
39
|
-
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings,
|
|
39
|
+
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_password, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_getSessionState, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_isNewEncryptionAvailable, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_createKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_assertNoDuplicateAccounts, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.KeyringController = exports.getDefaultKeyringState = exports.keyringBuilderFactory = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.isCustodyKeyring = exports.KeyringTypes = void 0;
|
|
42
42
|
const util_1 = require("@ethereumjs/util");
|
|
@@ -122,7 +122,6 @@ const getDefaultKeyringState = () => {
|
|
|
122
122
|
return {
|
|
123
123
|
isUnlocked: false,
|
|
124
124
|
keyrings: [],
|
|
125
|
-
keyringsMetadata: [],
|
|
126
125
|
};
|
|
127
126
|
};
|
|
128
127
|
exports.getDefaultKeyringState = getDefaultKeyringState;
|
|
@@ -185,16 +184,19 @@ function isSerializedKeyringsArray(array) {
|
|
|
185
184
|
*
|
|
186
185
|
* Is used for adding the current keyrings to the state object.
|
|
187
186
|
*
|
|
188
|
-
* @param
|
|
187
|
+
* @param keyringWithMetadata - The keyring and its metadata.
|
|
188
|
+
* @param keyringWithMetadata.keyring - The keyring to display.
|
|
189
|
+
* @param keyringWithMetadata.metadata - The metadata of the keyring.
|
|
189
190
|
* @returns A keyring display object, with type and accounts properties.
|
|
190
191
|
*/
|
|
191
|
-
async function displayForKeyring(keyring) {
|
|
192
|
+
async function displayForKeyring({ keyring, metadata, }) {
|
|
192
193
|
const accounts = await keyring.getAccounts();
|
|
193
194
|
return {
|
|
194
195
|
type: keyring.type,
|
|
195
196
|
// Cast to `string[]` here is safe here because `accounts` has no nullish
|
|
196
197
|
// values, and `normalize` returns `string` unless given a nullish value
|
|
197
198
|
accounts: accounts.map(normalize),
|
|
199
|
+
metadata,
|
|
198
200
|
};
|
|
199
201
|
}
|
|
200
202
|
/**
|
|
@@ -254,7 +256,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
254
256
|
vault: { persist: true, anonymous: false },
|
|
255
257
|
isUnlocked: { persist: false, anonymous: true },
|
|
256
258
|
keyrings: { persist: false, anonymous: false },
|
|
257
|
-
keyringsMetadata: { persist: true, anonymous: false },
|
|
258
259
|
encryptionKey: { persist: false, anonymous: false },
|
|
259
260
|
encryptionSalt: { persist: false, anonymous: false },
|
|
260
261
|
},
|
|
@@ -272,7 +273,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
272
273
|
_KeyringController_cacheEncryptionKey.set(this, void 0);
|
|
273
274
|
_KeyringController_keyrings.set(this, void 0);
|
|
274
275
|
_KeyringController_unsupportedKeyrings.set(this, void 0);
|
|
275
|
-
_KeyringController_keyringsMetadata.set(this, void 0);
|
|
276
276
|
_KeyringController_password.set(this, void 0);
|
|
277
277
|
_KeyringController_qrKeyringStateListener.set(this, void 0);
|
|
278
278
|
__classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
|
|
@@ -280,7 +280,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
280
280
|
: defaultKeyringBuilders, "f");
|
|
281
281
|
__classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
|
|
282
282
|
__classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
|
|
283
|
-
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, state?.keyringsMetadata?.slice() ?? [], "f");
|
|
284
283
|
__classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
|
|
285
284
|
// This option allows the controller to cache an exported key
|
|
286
285
|
// for use in decrypting and encrypting data without password
|
|
@@ -513,7 +512,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
513
512
|
async getKeyringForAccount(account) {
|
|
514
513
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
515
514
|
const address = normalize(account);
|
|
516
|
-
const candidates = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring) => {
|
|
515
|
+
const candidates = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async ({ keyring }) => {
|
|
517
516
|
return Promise.all([keyring, keyring.getAccounts()]);
|
|
518
517
|
}));
|
|
519
518
|
const winners = candidates.filter((candidate) => {
|
|
@@ -544,7 +543,9 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
544
543
|
*/
|
|
545
544
|
getKeyringsByType(type) {
|
|
546
545
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
547
|
-
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")
|
|
546
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")
|
|
547
|
+
.filter(({ keyring }) => keyring.type === type)
|
|
548
|
+
.map(({ keyring }) => keyring);
|
|
548
549
|
}
|
|
549
550
|
/**
|
|
550
551
|
* Persist all serialized keyrings in the vault.
|
|
@@ -865,10 +866,25 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
865
866
|
* @returns Promise resolving when the operation completes.
|
|
866
867
|
*/
|
|
867
868
|
async submitEncryptionKey(encryptionKey, encryptionSalt) {
|
|
868
|
-
|
|
869
|
-
|
|
869
|
+
const { newMetadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
|
|
870
|
+
const result = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unlockKeyrings).call(this, undefined, encryptionKey, encryptionSalt);
|
|
870
871
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
|
|
872
|
+
return result;
|
|
871
873
|
});
|
|
874
|
+
try {
|
|
875
|
+
// if new metadata has been generated during login, we
|
|
876
|
+
// can attempt to upgrade the vault.
|
|
877
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
|
|
878
|
+
if (newMetadata) {
|
|
879
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
catch (error) {
|
|
884
|
+
// We don't want to throw an error if the upgrade fails
|
|
885
|
+
// since the controller is already unlocked.
|
|
886
|
+
console.error('Failed to update vault during login:', error);
|
|
887
|
+
}
|
|
872
888
|
}
|
|
873
889
|
/**
|
|
874
890
|
* Attempts to decrypt the current vault and load its keyrings,
|
|
@@ -878,19 +894,25 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
878
894
|
* @returns Promise resolving when the operation completes.
|
|
879
895
|
*/
|
|
880
896
|
async submitPassword(password) {
|
|
881
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
|
|
882
|
-
|
|
897
|
+
const { newMetadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
|
|
898
|
+
const result = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unlockKeyrings).call(this, password);
|
|
883
899
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
|
|
900
|
+
return result;
|
|
884
901
|
});
|
|
885
902
|
try {
|
|
886
|
-
// If there are stronger encryption params available,
|
|
903
|
+
// If there are stronger encryption params available, or
|
|
904
|
+
// if new metadata has been generated during login, we
|
|
887
905
|
// can attempt to upgrade the vault.
|
|
888
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () =>
|
|
906
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
|
|
907
|
+
if (newMetadata || __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_isNewEncryptionAvailable).call(this)) {
|
|
908
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
909
|
+
}
|
|
910
|
+
});
|
|
889
911
|
}
|
|
890
912
|
catch (error) {
|
|
891
913
|
// We don't want to throw an error if the upgrade fails
|
|
892
914
|
// since the controller is already unlocked.
|
|
893
|
-
console.error('Failed to
|
|
915
|
+
console.error('Failed to update vault during login:', error);
|
|
894
916
|
}
|
|
895
917
|
}
|
|
896
918
|
/**
|
|
@@ -1137,7 +1159,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
1137
1159
|
}
|
|
1138
1160
|
}
|
|
1139
1161
|
exports.KeyringController = KeyringController;
|
|
1140
|
-
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(),
|
|
1162
|
+
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
1141
1163
|
this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
|
|
1142
1164
|
this.messagingSystem.registerActionHandler(`${name}:signEip7702Authorization`, this.signEip7702Authorization.bind(this));
|
|
1143
1165
|
this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
|
|
@@ -1154,17 +1176,19 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
|
|
|
1154
1176
|
this.messagingSystem.registerActionHandler(`${name}:addNewAccount`, this.addNewAccount.bind(this));
|
|
1155
1177
|
this.messagingSystem.registerActionHandler(`${name}:withKeyring`, this.withKeyring.bind(this));
|
|
1156
1178
|
}, _KeyringController_getKeyringById = function _KeyringController_getKeyringById(keyringId) {
|
|
1157
|
-
|
|
1158
|
-
|
|
1179
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId)
|
|
1180
|
+
?.keyring;
|
|
1159
1181
|
}, _KeyringController_getKeyringByIdOrDefault = function _KeyringController_getKeyringByIdOrDefault(keyringId) {
|
|
1160
1182
|
if (!keyringId) {
|
|
1161
|
-
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0];
|
|
1183
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]?.keyring;
|
|
1162
1184
|
}
|
|
1163
1185
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, keyringId);
|
|
1164
1186
|
}, _KeyringController_getKeyringMetadata = function _KeyringController_getKeyringMetadata(keyring) {
|
|
1165
|
-
const
|
|
1166
|
-
(
|
|
1167
|
-
|
|
1187
|
+
const keyringWithMetadata = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find((candidate) => candidate.keyring === keyring);
|
|
1188
|
+
if (!keyringWithMetadata) {
|
|
1189
|
+
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
1190
|
+
}
|
|
1191
|
+
return keyringWithMetadata.metadata;
|
|
1168
1192
|
}, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
|
|
1169
1193
|
return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
|
|
1170
1194
|
}, _KeyringController_addQRKeyring =
|
|
@@ -1217,7 +1241,6 @@ async function _KeyringController_createNewVaultWithKeyring(password, keyring) {
|
|
|
1217
1241
|
});
|
|
1218
1242
|
__classPrivateFieldSet(this, _KeyringController_password, password, "f");
|
|
1219
1243
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
|
|
1220
|
-
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, [], "f");
|
|
1221
1244
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyringWithFirstAccount).call(this, keyring.type, keyring.opts);
|
|
1222
1245
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
|
|
1223
1246
|
}, _KeyringController_verifySeedPhrase =
|
|
@@ -1287,12 +1310,12 @@ async function _KeyringController_getUpdatedKeyrings() {
|
|
|
1287
1310
|
async function _KeyringController_getSerializedKeyrings({ includeUnsupported } = {
|
|
1288
1311
|
includeUnsupported: true,
|
|
1289
1312
|
}) {
|
|
1290
|
-
const serializedKeyrings = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring) => {
|
|
1291
|
-
|
|
1292
|
-
keyring.type,
|
|
1293
|
-
keyring.serialize(),
|
|
1294
|
-
|
|
1295
|
-
|
|
1313
|
+
const serializedKeyrings = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async ({ keyring, metadata }) => {
|
|
1314
|
+
return {
|
|
1315
|
+
type: keyring.type,
|
|
1316
|
+
data: await keyring.serialize(),
|
|
1317
|
+
metadata,
|
|
1318
|
+
};
|
|
1296
1319
|
}));
|
|
1297
1320
|
if (includeUnsupported) {
|
|
1298
1321
|
serializedKeyrings.push(...__classPrivateFieldGet(this, _KeyringController_unsupportedKeyrings, "f"));
|
|
@@ -1308,7 +1331,6 @@ async function _KeyringController_getSerializedKeyrings({ includeUnsupported } =
|
|
|
1308
1331
|
async function _KeyringController_getSessionState() {
|
|
1309
1332
|
return {
|
|
1310
1333
|
keyrings: await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this),
|
|
1311
|
-
keyringsMetadata: __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice(),
|
|
1312
1334
|
password: __classPrivateFieldGet(this, _KeyringController_password, "f"),
|
|
1313
1335
|
};
|
|
1314
1336
|
}, _KeyringController_restoreSerializedKeyrings =
|
|
@@ -1316,12 +1338,23 @@ async function _KeyringController_getSessionState() {
|
|
|
1316
1338
|
* Restore a serialized keyrings array.
|
|
1317
1339
|
*
|
|
1318
1340
|
* @param serializedKeyrings - The serialized keyrings array.
|
|
1341
|
+
* @returns A promise resolving to the restored keyrings.
|
|
1319
1342
|
*/
|
|
1320
1343
|
async function _KeyringController_restoreSerializedKeyrings(serializedKeyrings) {
|
|
1321
1344
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
|
|
1345
|
+
const keyrings = [];
|
|
1346
|
+
let newMetadata = false;
|
|
1322
1347
|
for (const serializedKeyring of serializedKeyrings) {
|
|
1323
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreKeyring).call(this, serializedKeyring);
|
|
1348
|
+
const result = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreKeyring).call(this, serializedKeyring);
|
|
1349
|
+
if (result) {
|
|
1350
|
+
const { keyring, metadata } = result;
|
|
1351
|
+
keyrings.push({ keyring, metadata });
|
|
1352
|
+
if (result.newMetadata) {
|
|
1353
|
+
newMetadata = true;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1324
1356
|
}
|
|
1357
|
+
return { keyrings, newMetadata };
|
|
1325
1358
|
}, _KeyringController_unlockKeyrings =
|
|
1326
1359
|
/**
|
|
1327
1360
|
* Unlock Keyrings, decrypting the vault and deserializing all
|
|
@@ -1378,22 +1411,16 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1378
1411
|
if (!isSerializedKeyringsArray(vault)) {
|
|
1379
1412
|
throw new Error(constants_1.KeyringControllerError.VaultDataError);
|
|
1380
1413
|
}
|
|
1381
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, vault);
|
|
1382
|
-
// The keyrings array and the keyringsMetadata array should
|
|
1383
|
-
// always have the same length while the controller is unlocked.
|
|
1384
|
-
if (__classPrivateFieldGet(this, _KeyringController_keyrings, "f").length !== __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length) {
|
|
1385
|
-
throw new Error(constants_1.KeyringControllerError.KeyringMetadataLengthMismatch);
|
|
1386
|
-
}
|
|
1414
|
+
const { keyrings, newMetadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, vault);
|
|
1387
1415
|
const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
|
|
1388
1416
|
this.update((state) => {
|
|
1389
1417
|
state.keyrings = updatedKeyrings;
|
|
1390
|
-
state.keyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
|
|
1391
1418
|
if (updatedState.encryptionKey || updatedState.encryptionSalt) {
|
|
1392
1419
|
state.encryptionKey = updatedState.encryptionKey;
|
|
1393
1420
|
state.encryptionSalt = updatedState.encryptionSalt;
|
|
1394
1421
|
}
|
|
1395
1422
|
});
|
|
1396
|
-
return
|
|
1423
|
+
return { keyrings, newMetadata };
|
|
1397
1424
|
});
|
|
1398
1425
|
}, _KeyringController_updateVault = function _KeyringController_updateVault() {
|
|
1399
1426
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async () => {
|
|
@@ -1437,13 +1464,9 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1437
1464
|
throw new Error(constants_1.KeyringControllerError.MissingVaultData);
|
|
1438
1465
|
}
|
|
1439
1466
|
const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
|
|
1440
|
-
if (updatedKeyrings.length !== __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length) {
|
|
1441
|
-
throw new Error(constants_1.KeyringControllerError.KeyringMetadataLengthMismatch);
|
|
1442
|
-
}
|
|
1443
1467
|
this.update((state) => {
|
|
1444
1468
|
state.vault = updatedState.vault;
|
|
1445
1469
|
state.keyrings = updatedKeyrings;
|
|
1446
|
-
state.keyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
|
|
1447
1470
|
if (updatedState.encryptionKey) {
|
|
1448
1471
|
state.encryptionKey = updatedState.encryptionKey;
|
|
1449
1472
|
state.encryptionSalt = JSON.parse(updatedState.vault).salt;
|
|
@@ -1451,21 +1474,12 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1451
1474
|
});
|
|
1452
1475
|
return true;
|
|
1453
1476
|
});
|
|
1454
|
-
},
|
|
1455
|
-
/**
|
|
1456
|
-
* Upgrade the vault encryption parameters if needed.
|
|
1457
|
-
*
|
|
1458
|
-
* @returns A promise resolving to `void`.
|
|
1459
|
-
*/
|
|
1460
|
-
async function _KeyringController_upgradeVaultEncryptionParams() {
|
|
1461
|
-
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1477
|
+
}, _KeyringController_isNewEncryptionAvailable = function _KeyringController_isNewEncryptionAvailable() {
|
|
1462
1478
|
const { vault } = this.state;
|
|
1463
|
-
if (vault
|
|
1464
|
-
|
|
1465
|
-
__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated &&
|
|
1466
|
-
!__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated(vault)) {
|
|
1467
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
1479
|
+
if (!vault || !__classPrivateFieldGet(this, _KeyringController_password, "f") || !__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated) {
|
|
1480
|
+
return false;
|
|
1468
1481
|
}
|
|
1482
|
+
return !__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated(vault);
|
|
1469
1483
|
}, _KeyringController_getAccountsFromKeyrings =
|
|
1470
1484
|
/**
|
|
1471
1485
|
* Retrieves all the accounts from keyrings instances
|
|
@@ -1475,7 +1489,7 @@ async function _KeyringController_upgradeVaultEncryptionParams() {
|
|
|
1475
1489
|
* @returns A promise resolving to an array of accounts.
|
|
1476
1490
|
*/
|
|
1477
1491
|
async function _KeyringController_getAccountsFromKeyrings(additionalKeyrings = []) {
|
|
1478
|
-
const keyrings = __classPrivateFieldGet(this, _KeyringController_keyrings, "f");
|
|
1492
|
+
const keyrings = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(({ keyring }) => keyring);
|
|
1479
1493
|
const keyringArrays = await Promise.all([...keyrings, ...additionalKeyrings].map(async (keyring) => keyring.getAccounts()));
|
|
1480
1494
|
const addresses = keyringArrays.reduce((res, arr) => {
|
|
1481
1495
|
return res.concat(arr);
|
|
@@ -1516,11 +1530,7 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
|
|
|
1516
1530
|
*/
|
|
1517
1531
|
async function _KeyringController_newKeyring(type, data) {
|
|
1518
1532
|
const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
|
|
1519
|
-
|
|
1520
|
-
throw new Error('Keyring metadata missing');
|
|
1521
|
-
}
|
|
1522
|
-
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
|
|
1523
|
-
__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").push(getDefaultKeyringMetadata());
|
|
1533
|
+
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring, metadata: getDefaultKeyringMetadata() });
|
|
1524
1534
|
return keyring;
|
|
1525
1535
|
}, _KeyringController_createKeyring =
|
|
1526
1536
|
/**
|
|
@@ -1577,7 +1587,7 @@ async function _KeyringController_createKeyring(type, data) {
|
|
|
1577
1587
|
*/
|
|
1578
1588
|
async function _KeyringController_clearKeyrings() {
|
|
1579
1589
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1580
|
-
for (const keyring of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
|
|
1590
|
+
for (const { keyring } of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
|
|
1581
1591
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
|
|
1582
1592
|
}
|
|
1583
1593
|
__classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
|
|
@@ -1593,28 +1603,28 @@ async function _KeyringController_clearKeyrings() {
|
|
|
1593
1603
|
async function _KeyringController_restoreKeyring(serialized) {
|
|
1594
1604
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1595
1605
|
try {
|
|
1596
|
-
const { type, data } = serialized;
|
|
1606
|
+
const { type, data, metadata: serializedMetadata } = serialized;
|
|
1607
|
+
let newMetadata = false;
|
|
1608
|
+
let metadata = serializedMetadata;
|
|
1597
1609
|
const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
|
|
1598
1610
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
|
|
1599
1611
|
// If metadata is missing, assume the data is from an installation before
|
|
1600
1612
|
// we had keyring metadata.
|
|
1601
|
-
if (
|
|
1602
|
-
|
|
1603
|
-
|
|
1613
|
+
if (!metadata) {
|
|
1614
|
+
newMetadata = true;
|
|
1615
|
+
metadata = getDefaultKeyringMetadata();
|
|
1604
1616
|
}
|
|
1605
1617
|
// The keyring is added to the keyrings array only if it's successfully restored
|
|
1606
1618
|
// and the metadata is successfully added to the controller
|
|
1607
|
-
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(
|
|
1608
|
-
|
|
1619
|
+
__classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({
|
|
1620
|
+
keyring,
|
|
1621
|
+
metadata,
|
|
1622
|
+
});
|
|
1623
|
+
return { keyring, metadata, newMetadata };
|
|
1609
1624
|
}
|
|
1610
1625
|
catch (error) {
|
|
1611
1626
|
console.error(error);
|
|
1612
1627
|
__classPrivateFieldGet(this, _KeyringController_unsupportedKeyrings, "f").push(serialized);
|
|
1613
|
-
if (__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length > __classPrivateFieldGet(this, _KeyringController_keyrings, "f").length) {
|
|
1614
|
-
// There was already a metadata entry for the keyring, so
|
|
1615
|
-
// we need to remove it
|
|
1616
|
-
__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").splice(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").length, 1);
|
|
1617
|
-
}
|
|
1618
1628
|
return undefined;
|
|
1619
1629
|
}
|
|
1620
1630
|
}, _KeyringController_destroyKeyring =
|
|
@@ -1639,22 +1649,19 @@ async function _KeyringController_destroyKeyring(keyring) {
|
|
|
1639
1649
|
async function _KeyringController_removeEmptyKeyrings() {
|
|
1640
1650
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1641
1651
|
const validKeyrings = [];
|
|
1642
|
-
const validKeyringMetadata = [];
|
|
1643
1652
|
// Since getAccounts returns a Promise
|
|
1644
1653
|
// We need to wait to hear back form each keyring
|
|
1645
1654
|
// in order to decide which ones are now valid (accounts.length > 0)
|
|
1646
|
-
await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring,
|
|
1655
|
+
await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async ({ keyring, metadata }) => {
|
|
1647
1656
|
const accounts = await keyring.getAccounts();
|
|
1648
1657
|
if (accounts.length > 0) {
|
|
1649
|
-
validKeyrings.push(keyring);
|
|
1650
|
-
validKeyringMetadata.push(__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f")[index]);
|
|
1658
|
+
validKeyrings.push({ keyring, metadata });
|
|
1651
1659
|
}
|
|
1652
1660
|
else {
|
|
1653
1661
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
|
|
1654
1662
|
}
|
|
1655
1663
|
}));
|
|
1656
1664
|
__classPrivateFieldSet(this, _KeyringController_keyrings, validKeyrings, "f");
|
|
1657
|
-
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, validKeyringMetadata, "f");
|
|
1658
1665
|
}, _KeyringController_assertNoDuplicateAccounts =
|
|
1659
1666
|
/**
|
|
1660
1667
|
* Assert that there are no duplicate accounts in the keyrings.
|
|
@@ -1671,11 +1678,6 @@ async function _KeyringController_assertNoDuplicateAccounts(additionalKeyrings =
|
|
|
1671
1678
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1672
1679
|
this.update((state) => {
|
|
1673
1680
|
state.isUnlocked = true;
|
|
1674
|
-
// If new keyringsMetadata was generated during the unlock operation,
|
|
1675
|
-
// we'll have to update the state with the new array
|
|
1676
|
-
if (__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length > state.keyringsMetadata.length) {
|
|
1677
|
-
state.keyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
|
|
1678
|
-
}
|
|
1679
1681
|
});
|
|
1680
1682
|
this.messagingSystem.publish(`${name}:unlock`);
|
|
1681
1683
|
}, _KeyringController_assertIsUnlocked = function _KeyringController_assertIsUnlocked() {
|
|
@@ -1714,13 +1716,11 @@ async function _KeyringController_withRollback(callback) {
|
|
|
1714
1716
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async ({ releaseLock }) => {
|
|
1715
1717
|
const currentSerializedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this);
|
|
1716
1718
|
const currentPassword = __classPrivateFieldGet(this, _KeyringController_password, "f");
|
|
1717
|
-
const currentKeyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
|
|
1718
1719
|
try {
|
|
1719
1720
|
return await callback({ releaseLock });
|
|
1720
1721
|
}
|
|
1721
1722
|
catch (e) {
|
|
1722
1723
|
// Keyrings and password are restored to their previous state
|
|
1723
|
-
__classPrivateFieldSet(this, _KeyringController_keyringsMetadata, currentKeyringsMetadata, "f");
|
|
1724
1724
|
__classPrivateFieldSet(this, _KeyringController_password, currentPassword, "f");
|
|
1725
1725
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, currentSerializedKeyrings);
|
|
1726
1726
|
throw e;
|