@metamask-previews/keyring-controller 21.0.4-preview-b84ab30f → 21.0.5-preview-377dcaaa
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 +8 -2
- package/dist/KeyringController.cjs +33 -39
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +33 -40
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [21.0.5]
|
|
11
|
+
|
|
10
12
|
### Changed
|
|
11
13
|
|
|
12
|
-
- Prevent emitting `:stateChange` from `withKeyring` unnecessarily ([#5732](https://github.com/MetaMask/core/pull/5732))
|
|
13
14
|
- Bump `@metamask/base-controller` from ^8.0.0 to ^8.0.1 ([#5722](https://github.com/MetaMask/core/pull/5722))
|
|
14
15
|
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- The vault encryption upgrade fails gracefully during login ([#5740](https://github.com/MetaMask/core/pull/5740))
|
|
19
|
+
|
|
15
20
|
## [21.0.4]
|
|
16
21
|
|
|
17
22
|
### Fixed
|
|
@@ -759,7 +764,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
759
764
|
|
|
760
765
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
761
766
|
|
|
762
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@21.0.
|
|
767
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@21.0.5...HEAD
|
|
768
|
+
[21.0.5]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@21.0.4...@metamask/keyring-controller@21.0.5
|
|
763
769
|
[21.0.4]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@21.0.3...@metamask/keyring-controller@21.0.4
|
|
764
770
|
[21.0.3]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@21.0.2...@metamask/keyring-controller@21.0.3
|
|
765
771
|
[21.0.2]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@21.0.1...@metamask/keyring-controller@21.0.2
|
|
@@ -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, _KeyringController_keyringsMetadata, _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,
|
|
39
|
+
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_keyringsMetadata, _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_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_upgradeVaultEncryptionParams, _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");
|
|
@@ -48,7 +48,6 @@ const eth_simple_keyring_1 = __importDefault(require("@metamask/eth-simple-keyri
|
|
|
48
48
|
const utils_1 = require("@metamask/utils");
|
|
49
49
|
const async_mutex_1 = require("async-mutex");
|
|
50
50
|
const ethereumjs_wallet_1 = __importStar(require("ethereumjs-wallet"));
|
|
51
|
-
const lodash_1 = require("lodash");
|
|
52
51
|
// When generating a ULID within the same millisecond, monotonicFactory provides some guarantees regarding sort order.
|
|
53
52
|
const ulid_1 = require("ulid");
|
|
54
53
|
const constants_1 = require("./constants.cjs");
|
|
@@ -554,11 +553,8 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
554
553
|
* operation completes.
|
|
555
554
|
*/
|
|
556
555
|
async persistAllKeyrings() {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
560
|
-
return true;
|
|
561
|
-
});
|
|
556
|
+
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
557
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => true);
|
|
562
558
|
}
|
|
563
559
|
/**
|
|
564
560
|
* Imports an account with the specified import strategy.
|
|
@@ -878,10 +874,20 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
878
874
|
* @returns Promise resolving when the operation completes.
|
|
879
875
|
*/
|
|
880
876
|
async submitPassword(password) {
|
|
881
|
-
|
|
877
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
|
|
882
878
|
__classPrivateFieldSet(this, _KeyringController_keyrings, await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unlockKeyrings).call(this, password), "f");
|
|
883
879
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
|
|
884
880
|
});
|
|
881
|
+
try {
|
|
882
|
+
// If there are stronger encryption params available, we
|
|
883
|
+
// can attempt to upgrade the vault.
|
|
884
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_upgradeVaultEncryptionParams).call(this));
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
// We don't want to throw an error if the upgrade fails
|
|
888
|
+
// since the controller is already unlocked.
|
|
889
|
+
console.error('Failed to upgrade vault encryption params:', error);
|
|
890
|
+
}
|
|
885
891
|
}
|
|
886
892
|
/**
|
|
887
893
|
* Verifies the that the seed phrase restores the current keychain's accounts.
|
|
@@ -1288,19 +1294,6 @@ async function _KeyringController_getSerializedKeyrings({ includeUnsupported } =
|
|
|
1288
1294
|
serializedKeyrings.push(...__classPrivateFieldGet(this, _KeyringController_unsupportedKeyrings, "f"));
|
|
1289
1295
|
}
|
|
1290
1296
|
return serializedKeyrings;
|
|
1291
|
-
}, _KeyringController_getSessionState =
|
|
1292
|
-
/**
|
|
1293
|
-
* Get a snapshot of session data held by class variables.
|
|
1294
|
-
*
|
|
1295
|
-
* @returns An object with serialized keyrings, keyrings metadata,
|
|
1296
|
-
* and the user password.
|
|
1297
|
-
*/
|
|
1298
|
-
async function _KeyringController_getSessionState() {
|
|
1299
|
-
return {
|
|
1300
|
-
keyrings: await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this),
|
|
1301
|
-
keyringsMetadata: __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice(),
|
|
1302
|
-
password: __classPrivateFieldGet(this, _KeyringController_password, "f"),
|
|
1303
|
-
};
|
|
1304
1297
|
}, _KeyringController_restoreSerializedKeyrings =
|
|
1305
1298
|
/**
|
|
1306
1299
|
* Restore a serialized keyrings array.
|
|
@@ -1323,7 +1316,7 @@ async function _KeyringController_restoreSerializedKeyrings(serializedKeyrings)
|
|
|
1323
1316
|
* @returns A promise resolving to the deserialized keyrings array.
|
|
1324
1317
|
*/
|
|
1325
1318
|
async function _KeyringController_unlockKeyrings(password, encryptionKey, encryptionSalt) {
|
|
1326
|
-
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async (
|
|
1319
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async () => {
|
|
1327
1320
|
const encryptedVault = this.state.vault;
|
|
1328
1321
|
if (!encryptedVault) {
|
|
1329
1322
|
throw new Error(constants_1.KeyringControllerError.VaultError);
|
|
@@ -1382,16 +1375,6 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1382
1375
|
state.encryptionSalt = updatedState.encryptionSalt;
|
|
1383
1376
|
}
|
|
1384
1377
|
});
|
|
1385
|
-
if (__classPrivateFieldGet(this, _KeyringController_password, "f") &&
|
|
1386
|
-
(!__classPrivateFieldGet(this, _KeyringController_cacheEncryptionKey, "f") || !encryptionKey) &&
|
|
1387
|
-
__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated &&
|
|
1388
|
-
!__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated(encryptedVault)) {
|
|
1389
|
-
// The lock needs to be released before persisting the keyrings
|
|
1390
|
-
// to avoid deadlock
|
|
1391
|
-
releaseLock();
|
|
1392
|
-
// Re-encrypt the vault with safer method if one is available
|
|
1393
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
1394
|
-
}
|
|
1395
1378
|
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f");
|
|
1396
1379
|
});
|
|
1397
1380
|
}, _KeyringController_updateVault = function _KeyringController_updateVault() {
|
|
@@ -1450,6 +1433,21 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
|
|
|
1450
1433
|
});
|
|
1451
1434
|
return true;
|
|
1452
1435
|
});
|
|
1436
|
+
}, _KeyringController_upgradeVaultEncryptionParams =
|
|
1437
|
+
/**
|
|
1438
|
+
* Upgrade the vault encryption parameters if needed.
|
|
1439
|
+
*
|
|
1440
|
+
* @returns A promise resolving to `void`.
|
|
1441
|
+
*/
|
|
1442
|
+
async function _KeyringController_upgradeVaultEncryptionParams() {
|
|
1443
|
+
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1444
|
+
const { vault } = this.state;
|
|
1445
|
+
if (vault &&
|
|
1446
|
+
__classPrivateFieldGet(this, _KeyringController_password, "f") &&
|
|
1447
|
+
__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated &&
|
|
1448
|
+
!__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated(vault)) {
|
|
1449
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
1450
|
+
}
|
|
1453
1451
|
}, _KeyringController_getAccountsFromKeyrings =
|
|
1454
1452
|
/**
|
|
1455
1453
|
* Retrieves all the accounts from keyrings instances
|
|
@@ -1661,7 +1659,7 @@ async function _KeyringController_assertNoDuplicateAccounts() {
|
|
|
1661
1659
|
}, _KeyringController_persistOrRollback =
|
|
1662
1660
|
/**
|
|
1663
1661
|
* Execute the given function after acquiring the controller lock
|
|
1664
|
-
* and save the
|
|
1662
|
+
* and save the keyrings to state after it, or rollback to their
|
|
1665
1663
|
* previous state in case of error.
|
|
1666
1664
|
*
|
|
1667
1665
|
* @param callback - The function to execute.
|
|
@@ -1669,13 +1667,9 @@ async function _KeyringController_assertNoDuplicateAccounts() {
|
|
|
1669
1667
|
*/
|
|
1670
1668
|
async function _KeyringController_persistOrRollback(callback) {
|
|
1671
1669
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async ({ releaseLock }) => {
|
|
1672
|
-
const oldState = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSessionState).call(this);
|
|
1673
1670
|
const callbackResult = await callback({ releaseLock });
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
if (!(0, lodash_1.isEqual)(oldState, newState)) {
|
|
1677
|
-
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
1678
|
-
}
|
|
1671
|
+
// State is committed only if the operation is successful
|
|
1672
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
1679
1673
|
return callbackResult;
|
|
1680
1674
|
});
|
|
1681
1675
|
}, _KeyringController_withRollback =
|