@metamask-previews/keyring-controller 21.0.6-preview-d0bf3e9 → 21.0.6-preview-956e6bf8

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 CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Fixed
11
+
12
+ - 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
+
10
15
  ## [21.0.6]
11
16
 
12
17
  ### Changed
@@ -1387,6 +1387,7 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1387
1387
  const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
1388
1388
  this.update((state) => {
1389
1389
  state.keyrings = updatedKeyrings;
1390
+ state.keyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
1390
1391
  if (updatedState.encryptionKey || updatedState.encryptionSalt) {
1391
1392
  state.encryptionKey = updatedState.encryptionKey;
1392
1393
  state.encryptionSalt = updatedState.encryptionSalt;
@@ -1470,11 +1471,12 @@ async function _KeyringController_upgradeVaultEncryptionParams() {
1470
1471
  * Retrieves all the accounts from keyrings instances
1471
1472
  * that are currently in memory.
1472
1473
  *
1474
+ * @param additionalKeyrings - Additional keyrings to include in the search.
1473
1475
  * @returns A promise resolving to an array of accounts.
1474
1476
  */
1475
- async function _KeyringController_getAccountsFromKeyrings() {
1477
+ async function _KeyringController_getAccountsFromKeyrings(additionalKeyrings = []) {
1476
1478
  const keyrings = __classPrivateFieldGet(this, _KeyringController_keyrings, "f");
1477
- const keyringArrays = await Promise.all(keyrings.map(async (keyring) => keyring.getAccounts()));
1479
+ const keyringArrays = await Promise.all([...keyrings, ...additionalKeyrings].map(async (keyring) => keyring.getAccounts()));
1478
1480
  const addresses = keyringArrays.reduce((res, arr) => {
1479
1481
  return res.concat(arr);
1480
1482
  }, []);
@@ -1593,6 +1595,7 @@ async function _KeyringController_restoreKeyring(serialized) {
1593
1595
  try {
1594
1596
  const { type, data } = serialized;
1595
1597
  const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1598
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
1596
1599
  // If metadata is missing, assume the data is from an installation before
1597
1600
  // we had keyring metadata.
1598
1601
  if (__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length <= __classPrivateFieldGet(this, _KeyringController_keyrings, "f").length) {
@@ -1607,6 +1610,11 @@ async function _KeyringController_restoreKeyring(serialized) {
1607
1610
  catch (error) {
1608
1611
  console.error(error);
1609
1612
  __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
+ }
1610
1618
  return undefined;
1611
1619
  }
1612
1620
  }, _KeyringController_destroyKeyring =
@@ -1651,10 +1659,11 @@ async function _KeyringController_removeEmptyKeyrings() {
1651
1659
  /**
1652
1660
  * Assert that there are no duplicate accounts in the keyrings.
1653
1661
  *
1662
+ * @param additionalKeyrings - Additional keyrings to include in the check.
1654
1663
  * @throws If there are duplicate accounts.
1655
1664
  */
1656
- async function _KeyringController_assertNoDuplicateAccounts() {
1657
- const accounts = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getAccountsFromKeyrings).call(this);
1665
+ async function _KeyringController_assertNoDuplicateAccounts(additionalKeyrings = []) {
1666
+ const accounts = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getAccountsFromKeyrings).call(this, additionalKeyrings);
1658
1667
  if (new Set(accounts).size !== accounts.length) {
1659
1668
  throw new Error(constants_1.KeyringControllerError.DuplicatedAccount);
1660
1669
  }