@metamask-previews/keyring-controller 19.1.0-preview-7a21cbc → 19.1.0-preview-52c28555

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.
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_unsupportedKeyrings, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_keyringsMetadata, _KeyringController_password, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_createKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_checkForDuplicate, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
12
+ var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_unsupportedKeyrings, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_password, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_checkForDuplicate, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
13
13
  function $importDefault(module) {
14
14
  if (module?.__esModule) {
15
15
  return module.default;
@@ -19,16 +19,16 @@ function $importDefault(module) {
19
19
  import { isValidPrivate, toBuffer, getBinarySize } from "@ethereumjs/util";
20
20
  import { BaseController } from "@metamask/base-controller";
21
21
  import * as encryptorUtils from "@metamask/browser-passworder";
22
- import HDKeyring from "@metamask/eth-hd-keyring";
22
+ import $HDKeyring from "@metamask/eth-hd-keyring";
23
+ const HDKeyring = $importDefault($HDKeyring);
23
24
  import { normalize as ethNormalize } from "@metamask/eth-sig-util";
24
- import SimpleKeyring from "@metamask/eth-simple-keyring";
25
+ import $SimpleKeyring from "@metamask/eth-simple-keyring";
26
+ const SimpleKeyring = $importDefault($SimpleKeyring);
25
27
  import { add0x, assertIsStrictHexString, bytesToHex, hasProperty, isObject, isStrictHexString, isValidHexAddress, isValidJson, remove0x } from "@metamask/utils";
26
28
  import { Mutex } from "async-mutex";
27
29
  import $Wallet from "ethereumjs-wallet";
28
30
  const { thirdparty: importers } = $Wallet;
29
31
  const Wallet = $importDefault($Wallet);
30
- // When generating a ULID within the same millisecond, monotonicFactory provides some guarantees regarding sort order.
31
- import { ulid } from "ulid";
32
32
  import { KeyringControllerError } from "./constants.mjs";
33
33
  const name = 'KeyringController';
34
34
  /**
@@ -88,17 +88,13 @@ export function keyringBuilderFactory(KeyringConstructor) {
88
88
  return builder;
89
89
  }
90
90
  const defaultKeyringBuilders = [
91
- // todo: keyring types are mismatched, this should be fixed in they keyrings themselves
92
- // @ts-expect-error keyring types are mismatched
93
91
  keyringBuilderFactory(SimpleKeyring),
94
- // @ts-expect-error keyring types are mismatched
95
92
  keyringBuilderFactory(HDKeyring),
96
93
  ];
97
94
  export const getDefaultKeyringState = () => {
98
95
  return {
99
96
  isUnlocked: false,
100
97
  keyrings: [],
101
- keyringsMetadata: [],
102
98
  };
103
99
  };
104
100
  /**
@@ -229,7 +225,6 @@ export class KeyringController extends BaseController {
229
225
  vault: { persist: true, anonymous: false },
230
226
  isUnlocked: { persist: false, anonymous: true },
231
227
  keyrings: { persist: false, anonymous: false },
232
- keyringsMetadata: { persist: true, anonymous: false },
233
228
  encryptionKey: { persist: false, anonymous: false },
234
229
  encryptionSalt: { persist: false, anonymous: false },
235
230
  },
@@ -247,7 +242,6 @@ export class KeyringController extends BaseController {
247
242
  _KeyringController_encryptor.set(this, void 0);
248
243
  _KeyringController_cacheEncryptionKey.set(this, void 0);
249
244
  _KeyringController_keyrings.set(this, void 0);
250
- _KeyringController_keyringsMetadata.set(this, void 0);
251
245
  _KeyringController_password.set(this, void 0);
252
246
  _KeyringController_qrKeyringStateListener.set(this, void 0);
253
247
  __classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
@@ -255,7 +249,6 @@ export class KeyringController extends BaseController {
255
249
  : defaultKeyringBuilders, "f");
256
250
  __classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
257
251
  __classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
258
- __classPrivateFieldSet(this, _KeyringController_keyringsMetadata, state?.keyringsMetadata ?? [], "f");
259
252
  __classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
260
253
  // This option allows the controller to cache an exported key
261
254
  // for use in decrypting and encrypting data without password
@@ -404,18 +397,13 @@ export class KeyringController extends BaseController {
404
397
  * Gets the seed phrase of the HD keyring.
405
398
  *
406
399
  * @param password - Password of the keyring.
407
- * @param keyringId - The id of the keyring.
408
400
  * @returns Promise resolving to the seed phrase.
409
401
  */
410
- async exportSeedPhrase(password, keyringId) {
402
+ async exportSeedPhrase(password) {
411
403
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
412
404
  await this.verifyPassword(password);
413
- const selectedKeyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringByIdOrDefault).call(this, keyringId);
414
- if (!selectedKeyring) {
415
- throw new Error('Keyring not found');
416
- }
417
- assertHasUint8ArrayMnemonic(selectedKeyring);
418
- return selectedKeyring.mnemonic;
405
+ assertHasUint8ArrayMnemonic(__classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]);
406
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0].mnemonic;
419
407
  }
420
408
  /**
421
409
  * Gets the private key from the keyring controlling an address.
@@ -600,13 +588,6 @@ export class KeyringController extends BaseController {
600
588
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
601
589
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
602
590
  const keyring = (await this.getKeyringForAccount(address));
603
- const keyringIndex = this.state.keyrings.findIndex((kr) => kr.accounts.includes(address));
604
- const isPrimaryKeyring = keyringIndex === 0;
605
- const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;
606
- // Primary keyring should never be removed, so we need to keep at least one account in it
607
- if (isPrimaryKeyring && shouldRemoveKeyring) {
608
- throw new Error(KeyringControllerError.LastAccountInPrimaryKeyring);
609
- }
610
591
  // Not all the keyrings support this, so we have to check
611
592
  if (!keyring.removeAccount) {
612
593
  throw new Error(KeyringControllerError.UnsupportedRemoveAccount);
@@ -617,7 +598,9 @@ export class KeyringController extends BaseController {
617
598
  // because `Keyring<State>.removeAccount` requires address to be `Hex`. Those
618
599
  // type would need to be updated for a full non-EVM support.
619
600
  keyring.removeAccount(address);
620
- if (shouldRemoveKeyring) {
601
+ const accounts = await keyring.getAccounts();
602
+ // Check if this was the last/only account
603
+ if (accounts.length === 0) {
621
604
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_removeEmptyKeyrings).call(this);
622
605
  }
623
606
  });
@@ -661,27 +644,6 @@ export class KeyringController extends BaseController {
661
644
  }
662
645
  return await keyring.signMessage(address, messageParams.data);
663
646
  }
664
- /**
665
- * Signs EIP-7702 Authorization message by calling down into a specific keyring.
666
- *
667
- * @param params - EIP7702AuthorizationParams object to sign.
668
- * @returns Promise resolving to an EIP-7702 Authorization signature.
669
- * @throws Will throw UnsupportedSignEIP7702Authorization if the keyring does not support signing EIP-7702 Authorization messages.
670
- */
671
- async signEip7702Authorization(params) {
672
- const from = ethNormalize(params.from);
673
- const keyring = (await this.getKeyringForAccount(from));
674
- if (!keyring.signEip7702Authorization) {
675
- throw new Error(KeyringControllerError.UnsupportedSignEip7702Authorization);
676
- }
677
- const { chainId, nonce } = params;
678
- const contractAddress = ethNormalize(params.contractAddress);
679
- return await keyring.signEip7702Authorization(from, [
680
- chainId,
681
- contractAddress,
682
- nonce,
683
- ]);
684
- }
685
647
  /**
686
648
  * Signs personal message by calling down into a specific keyring.
687
649
  *
@@ -855,12 +817,11 @@ export class KeyringController extends BaseController {
855
817
  /**
856
818
  * Verifies the that the seed phrase restores the current keychain's accounts.
857
819
  *
858
- * @param keyringId - The id of the keyring to verify.
859
820
  * @returns Promise resolving to the seed phrase as Uint8Array.
860
821
  */
861
- async verifySeedPhrase(keyringId) {
822
+ async verifySeedPhrase() {
862
823
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
863
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this, keyringId));
824
+ return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this));
864
825
  }
865
826
  async withKeyring(selector, operation, options = {
866
827
  createIfMissing: false,
@@ -871,15 +832,12 @@ export class KeyringController extends BaseController {
871
832
  if ('address' in selector) {
872
833
  keyring = (await this.getKeyringForAccount(selector.address));
873
834
  }
874
- else if ('type' in selector) {
835
+ else {
875
836
  keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
876
837
  if (!keyring && options.createIfMissing) {
877
838
  keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
878
839
  }
879
840
  }
880
- else if ('id' in selector) {
881
- keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, selector.id);
882
- }
883
841
  if (!keyring) {
884
842
  throw new Error(KeyringControllerError.KeyringNotFound);
885
843
  }
@@ -1092,9 +1050,8 @@ export class KeyringController extends BaseController {
1092
1050
  });
1093
1051
  }
1094
1052
  }
1095
- _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_keyringsMetadata = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
1053
+ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
1096
1054
  this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
1097
- this.messagingSystem.registerActionHandler(`${name}:signEip7702Authorization`, this.signEip7702Authorization.bind(this));
1098
1055
  this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
1099
1056
  this.messagingSystem.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
1100
1057
  this.messagingSystem.registerActionHandler(`${name}:decryptMessage`, this.decryptMessage.bind(this));
@@ -1108,14 +1065,6 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1108
1065
  this.messagingSystem.registerActionHandler(`${name}:signUserOperation`, this.signUserOperation.bind(this));
1109
1066
  this.messagingSystem.registerActionHandler(`${name}:addNewAccount`, this.addNewAccount.bind(this));
1110
1067
  this.messagingSystem.registerActionHandler(`${name}:withKeyring`, this.withKeyring.bind(this));
1111
- }, _KeyringController_getKeyringById = function _KeyringController_getKeyringById(keyringId) {
1112
- const index = this.state.keyringsMetadata.findIndex((metadata) => metadata.id === keyringId);
1113
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[index];
1114
- }, _KeyringController_getKeyringByIdOrDefault = function _KeyringController_getKeyringByIdOrDefault(keyringId) {
1115
- if (!keyringId) {
1116
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0];
1117
- }
1118
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, keyringId);
1119
1068
  }, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
1120
1069
  return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
1121
1070
  }, _KeyringController_addQRKeyring =
@@ -1168,29 +1117,23 @@ async function _KeyringController_createNewVaultWithKeyring(password, keyring) {
1168
1117
  });
1169
1118
  __classPrivateFieldSet(this, _KeyringController_password, password, "f");
1170
1119
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
1171
- __classPrivateFieldSet(this, _KeyringController_keyringsMetadata, [], "f");
1172
1120
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyringWithFirstAccount).call(this, keyring.type, keyring.opts);
1173
1121
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
1174
1122
  }, _KeyringController_verifySeedPhrase =
1175
1123
  /**
1176
1124
  * Internal non-exclusive method to verify the seed phrase.
1177
1125
  *
1178
- * @param keyringId - The id of the keyring to verify the seed phrase for.
1179
1126
  * @returns A promise resolving to the seed phrase as Uint8Array.
1180
1127
  */
1181
- async function _KeyringController_verifySeedPhrase(keyringId) {
1128
+ async function _KeyringController_verifySeedPhrase() {
1182
1129
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1183
- const keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringByIdOrDefault).call(this, keyringId);
1184
- if (!keyring) {
1185
- throw new Error(KeyringControllerError.KeyringNotFound);
1130
+ const primaryKeyring = this.getKeyringsByType(KeyringTypes.hd)[0];
1131
+ if (!primaryKeyring) {
1132
+ throw new Error('No HD keyring found.');
1186
1133
  }
1187
- // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
1188
- if (keyring.type !== KeyringTypes.hd) {
1189
- throw new Error(KeyringControllerError.UnsupportedVerifySeedPhrase);
1190
- }
1191
- assertHasUint8ArrayMnemonic(keyring);
1192
- const seedWords = keyring.mnemonic;
1193
- const accounts = await keyring.getAccounts();
1134
+ assertHasUint8ArrayMnemonic(primaryKeyring);
1135
+ const seedWords = primaryKeyring.mnemonic;
1136
+ const accounts = await primaryKeyring.getAccounts();
1194
1137
  /* istanbul ignore if */
1195
1138
  if (accounts.length === 0) {
1196
1139
  throw new Error('Cannot verify an empty keyring.');
@@ -1370,13 +1313,9 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1370
1313
  throw new Error(KeyringControllerError.MissingVaultData);
1371
1314
  }
1372
1315
  const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
1373
- if (updatedKeyrings.length !== __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length) {
1374
- throw new Error(KeyringControllerError.KeyringMetadataLengthMismatch);
1375
- }
1376
1316
  this.update((state) => {
1377
1317
  state.vault = updatedState.vault;
1378
1318
  state.keyrings = updatedKeyrings;
1379
- state.keyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
1380
1319
  if (updatedState.encryptionKey) {
1381
1320
  state.encryptionKey = updatedState.encryptionKey;
1382
1321
  state.encryptionSalt = JSON.parse(updatedState.vault).salt;
@@ -1416,48 +1355,19 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
1416
1355
  if (!firstAccount) {
1417
1356
  throw new Error(KeyringControllerError.NoFirstAccount);
1418
1357
  }
1419
- return firstAccount;
1420
1358
  }, _KeyringController_newKeyring =
1421
1359
  /**
1422
1360
  * Instantiate, initialize and return a new keyring of the given `type`,
1423
1361
  * using the given `opts`. The keyring is built using the keyring builder
1424
1362
  * registered for the given `type`.
1425
1363
  *
1426
- * The internal keyring and keyring metadata arrays are updated with the new
1427
- * keyring as well.
1428
1364
  *
1429
1365
  * @param type - The type of keyring to add.
1430
- * @param data - Keyring initialization options.
1366
+ * @param data - The data to restore a previously serialized keyring.
1431
1367
  * @returns The new keyring.
1432
1368
  * @throws If the keyring includes duplicated accounts.
1433
1369
  */
1434
1370
  async function _KeyringController_newKeyring(type, data) {
1435
- const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1436
- if (__classPrivateFieldGet(this, _KeyringController_keyrings, "f").length !== __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length) {
1437
- throw new Error('Keyring metadata missing');
1438
- }
1439
- __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
1440
- __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").push(getDefaultKeyringMetadata());
1441
- return keyring;
1442
- }, _KeyringController_createKeyring =
1443
- /**
1444
- * Instantiate, initialize and return a keyring of the given `type` using the
1445
- * given `opts`. The keyring is built using the keyring builder registered
1446
- * for the given `type`.
1447
- *
1448
- * The keyring might be new, or it might be restored from the vault. This
1449
- * function should only be called from `#newKeyring` or `#restoreKeyring`,
1450
- * for the "new" and "restore" cases respectively.
1451
- *
1452
- * The internal keyring and keyring metadata arrays are *not* updated, the
1453
- * caller is expected to update them.
1454
- *
1455
- * @param type - The type of keyring to add.
1456
- * @param data - Keyring initialization options.
1457
- * @returns The new keyring.
1458
- * @throws If the keyring includes duplicated accounts.
1459
- */
1460
- async function _KeyringController_createKeyring(type, data) {
1461
1371
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1462
1372
  const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
1463
1373
  if (!keyringBuilder) {
@@ -1485,6 +1395,7 @@ async function _KeyringController_createKeyring(type, data) {
1485
1395
  // to its events after creating it
1486
1396
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_subscribeToQRKeyringEvents).call(this, keyring);
1487
1397
  }
1398
+ __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
1488
1399
  return keyring;
1489
1400
  }, _KeyringController_clearKeyrings =
1490
1401
  /**
@@ -1509,15 +1420,7 @@ async function _KeyringController_restoreKeyring(serialized) {
1509
1420
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1510
1421
  try {
1511
1422
  const { type, data } = serialized;
1512
- const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1513
- __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
1514
- // If metadata is missing, assume the data is from an installation before
1515
- // we had keyring metadata.
1516
- if (__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length < __classPrivateFieldGet(this, _KeyringController_keyrings, "f").length) {
1517
- console.log(`Adding missing metadata for '${type}' keyring`);
1518
- __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").push(getDefaultKeyringMetadata());
1519
- }
1520
- return keyring;
1423
+ return await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, data);
1521
1424
  }
1522
1425
  catch (_) {
1523
1426
  __classPrivateFieldGet(this, _KeyringController_unsupportedKeyrings, "f").push(serialized);
@@ -1545,22 +1448,19 @@ async function _KeyringController_destroyKeyring(keyring) {
1545
1448
  async function _KeyringController_removeEmptyKeyrings() {
1546
1449
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1547
1450
  const validKeyrings = [];
1548
- const validKeyringMetadata = [];
1549
1451
  // Since getAccounts returns a Promise
1550
1452
  // We need to wait to hear back form each keyring
1551
1453
  // in order to decide which ones are now valid (accounts.length > 0)
1552
- await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring, index) => {
1454
+ await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring) => {
1553
1455
  const accounts = await keyring.getAccounts();
1554
1456
  if (accounts.length > 0) {
1555
1457
  validKeyrings.push(keyring);
1556
- validKeyringMetadata.push(__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f")[index]);
1557
1458
  }
1558
1459
  else {
1559
1460
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
1560
1461
  }
1561
1462
  }));
1562
1463
  __classPrivateFieldSet(this, _KeyringController_keyrings, validKeyrings, "f");
1563
- __classPrivateFieldSet(this, _KeyringController_keyringsMetadata, validKeyringMetadata, "f");
1564
1464
  }, _KeyringController_checkForDuplicate =
1565
1465
  /**
1566
1466
  * Checks for duplicate keypairs, using the the first account in the given
@@ -1626,7 +1526,6 @@ async function _KeyringController_withRollback(callback) {
1626
1526
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async ({ releaseLock }) => {
1627
1527
  const currentSerializedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this);
1628
1528
  const currentPassword = __classPrivateFieldGet(this, _KeyringController_password, "f");
1629
- const currentKeyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
1630
1529
  try {
1631
1530
  return await callback({ releaseLock });
1632
1531
  }
@@ -1634,7 +1533,6 @@ async function _KeyringController_withRollback(callback) {
1634
1533
  // Keyrings and password are restored to their previous state
1635
1534
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, currentSerializedKeyrings);
1636
1535
  __classPrivateFieldSet(this, _KeyringController_password, currentPassword, "f");
1637
- __classPrivateFieldSet(this, _KeyringController_keyringsMetadata, currentKeyringsMetadata, "f");
1638
1536
  throw e;
1639
1537
  }
1640
1538
  });
@@ -1691,13 +1589,5 @@ async function withLock(mutex, callback) {
1691
1589
  releaseLock();
1692
1590
  }
1693
1591
  }
1694
- /**
1695
- * Generate a new keyring metadata object.
1696
- *
1697
- * @returns Keyring metadata.
1698
- */
1699
- function getDefaultKeyringMetadata() {
1700
- return { id: ulid(), name: '' };
1701
- }
1702
1592
  export default KeyringController;
1703
1593
  //# sourceMappingURL=KeyringController.mjs.map