@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.
@@ -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_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;
39
+ 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;
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,8 +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
- // When generating a ULID within the same millisecond, monotonicFactory provides some guarantees regarding sort order.
52
- const ulid_1 = require("ulid");
53
51
  const constants_1 = require("./constants.cjs");
54
52
  const name = 'KeyringController';
55
53
  /**
@@ -111,17 +109,13 @@ function keyringBuilderFactory(KeyringConstructor) {
111
109
  }
112
110
  exports.keyringBuilderFactory = keyringBuilderFactory;
113
111
  const defaultKeyringBuilders = [
114
- // todo: keyring types are mismatched, this should be fixed in they keyrings themselves
115
- // @ts-expect-error keyring types are mismatched
116
112
  keyringBuilderFactory(eth_simple_keyring_1.default),
117
- // @ts-expect-error keyring types are mismatched
118
113
  keyringBuilderFactory(eth_hd_keyring_1.default),
119
114
  ];
120
115
  const getDefaultKeyringState = () => {
121
116
  return {
122
117
  isUnlocked: false,
123
118
  keyrings: [],
124
- keyringsMetadata: [],
125
119
  };
126
120
  };
127
121
  exports.getDefaultKeyringState = getDefaultKeyringState;
@@ -253,7 +247,6 @@ class KeyringController extends base_controller_1.BaseController {
253
247
  vault: { persist: true, anonymous: false },
254
248
  isUnlocked: { persist: false, anonymous: true },
255
249
  keyrings: { persist: false, anonymous: false },
256
- keyringsMetadata: { persist: true, anonymous: false },
257
250
  encryptionKey: { persist: false, anonymous: false },
258
251
  encryptionSalt: { persist: false, anonymous: false },
259
252
  },
@@ -271,7 +264,6 @@ class KeyringController extends base_controller_1.BaseController {
271
264
  _KeyringController_encryptor.set(this, void 0);
272
265
  _KeyringController_cacheEncryptionKey.set(this, void 0);
273
266
  _KeyringController_keyrings.set(this, void 0);
274
- _KeyringController_keyringsMetadata.set(this, void 0);
275
267
  _KeyringController_password.set(this, void 0);
276
268
  _KeyringController_qrKeyringStateListener.set(this, void 0);
277
269
  __classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
@@ -279,7 +271,6 @@ class KeyringController extends base_controller_1.BaseController {
279
271
  : defaultKeyringBuilders, "f");
280
272
  __classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
281
273
  __classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
282
- __classPrivateFieldSet(this, _KeyringController_keyringsMetadata, state?.keyringsMetadata ?? [], "f");
283
274
  __classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
284
275
  // This option allows the controller to cache an exported key
285
276
  // for use in decrypting and encrypting data without password
@@ -428,18 +419,13 @@ class KeyringController extends base_controller_1.BaseController {
428
419
  * Gets the seed phrase of the HD keyring.
429
420
  *
430
421
  * @param password - Password of the keyring.
431
- * @param keyringId - The id of the keyring.
432
422
  * @returns Promise resolving to the seed phrase.
433
423
  */
434
- async exportSeedPhrase(password, keyringId) {
424
+ async exportSeedPhrase(password) {
435
425
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
436
426
  await this.verifyPassword(password);
437
- const selectedKeyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringByIdOrDefault).call(this, keyringId);
438
- if (!selectedKeyring) {
439
- throw new Error('Keyring not found');
440
- }
441
- assertHasUint8ArrayMnemonic(selectedKeyring);
442
- return selectedKeyring.mnemonic;
427
+ assertHasUint8ArrayMnemonic(__classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]);
428
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0].mnemonic;
443
429
  }
444
430
  /**
445
431
  * Gets the private key from the keyring controlling an address.
@@ -624,13 +610,6 @@ class KeyringController extends base_controller_1.BaseController {
624
610
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
625
611
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
626
612
  const keyring = (await this.getKeyringForAccount(address));
627
- const keyringIndex = this.state.keyrings.findIndex((kr) => kr.accounts.includes(address));
628
- const isPrimaryKeyring = keyringIndex === 0;
629
- const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;
630
- // Primary keyring should never be removed, so we need to keep at least one account in it
631
- if (isPrimaryKeyring && shouldRemoveKeyring) {
632
- throw new Error(constants_1.KeyringControllerError.LastAccountInPrimaryKeyring);
633
- }
634
613
  // Not all the keyrings support this, so we have to check
635
614
  if (!keyring.removeAccount) {
636
615
  throw new Error(constants_1.KeyringControllerError.UnsupportedRemoveAccount);
@@ -641,7 +620,9 @@ class KeyringController extends base_controller_1.BaseController {
641
620
  // because `Keyring<State>.removeAccount` requires address to be `Hex`. Those
642
621
  // type would need to be updated for a full non-EVM support.
643
622
  keyring.removeAccount(address);
644
- if (shouldRemoveKeyring) {
623
+ const accounts = await keyring.getAccounts();
624
+ // Check if this was the last/only account
625
+ if (accounts.length === 0) {
645
626
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_removeEmptyKeyrings).call(this);
646
627
  }
647
628
  });
@@ -685,27 +666,6 @@ class KeyringController extends base_controller_1.BaseController {
685
666
  }
686
667
  return await keyring.signMessage(address, messageParams.data);
687
668
  }
688
- /**
689
- * Signs EIP-7702 Authorization message by calling down into a specific keyring.
690
- *
691
- * @param params - EIP7702AuthorizationParams object to sign.
692
- * @returns Promise resolving to an EIP-7702 Authorization signature.
693
- * @throws Will throw UnsupportedSignEIP7702Authorization if the keyring does not support signing EIP-7702 Authorization messages.
694
- */
695
- async signEip7702Authorization(params) {
696
- const from = (0, eth_sig_util_1.normalize)(params.from);
697
- const keyring = (await this.getKeyringForAccount(from));
698
- if (!keyring.signEip7702Authorization) {
699
- throw new Error(constants_1.KeyringControllerError.UnsupportedSignEip7702Authorization);
700
- }
701
- const { chainId, nonce } = params;
702
- const contractAddress = (0, eth_sig_util_1.normalize)(params.contractAddress);
703
- return await keyring.signEip7702Authorization(from, [
704
- chainId,
705
- contractAddress,
706
- nonce,
707
- ]);
708
- }
709
669
  /**
710
670
  * Signs personal message by calling down into a specific keyring.
711
671
  *
@@ -879,12 +839,11 @@ class KeyringController extends base_controller_1.BaseController {
879
839
  /**
880
840
  * Verifies the that the seed phrase restores the current keychain's accounts.
881
841
  *
882
- * @param keyringId - The id of the keyring to verify.
883
842
  * @returns Promise resolving to the seed phrase as Uint8Array.
884
843
  */
885
- async verifySeedPhrase(keyringId) {
844
+ async verifySeedPhrase() {
886
845
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
887
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this, keyringId));
846
+ return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this));
888
847
  }
889
848
  async withKeyring(selector, operation, options = {
890
849
  createIfMissing: false,
@@ -895,15 +854,12 @@ class KeyringController extends base_controller_1.BaseController {
895
854
  if ('address' in selector) {
896
855
  keyring = (await this.getKeyringForAccount(selector.address));
897
856
  }
898
- else if ('type' in selector) {
857
+ else {
899
858
  keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
900
859
  if (!keyring && options.createIfMissing) {
901
860
  keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
902
861
  }
903
862
  }
904
- else if ('id' in selector) {
905
- keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, selector.id);
906
- }
907
863
  if (!keyring) {
908
864
  throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
909
865
  }
@@ -1117,9 +1073,8 @@ class KeyringController extends base_controller_1.BaseController {
1117
1073
  }
1118
1074
  }
1119
1075
  exports.KeyringController = KeyringController;
1120
- _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() {
1076
+ _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() {
1121
1077
  this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
1122
- this.messagingSystem.registerActionHandler(`${name}:signEip7702Authorization`, this.signEip7702Authorization.bind(this));
1123
1078
  this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
1124
1079
  this.messagingSystem.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
1125
1080
  this.messagingSystem.registerActionHandler(`${name}:decryptMessage`, this.decryptMessage.bind(this));
@@ -1133,14 +1088,6 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1133
1088
  this.messagingSystem.registerActionHandler(`${name}:signUserOperation`, this.signUserOperation.bind(this));
1134
1089
  this.messagingSystem.registerActionHandler(`${name}:addNewAccount`, this.addNewAccount.bind(this));
1135
1090
  this.messagingSystem.registerActionHandler(`${name}:withKeyring`, this.withKeyring.bind(this));
1136
- }, _KeyringController_getKeyringById = function _KeyringController_getKeyringById(keyringId) {
1137
- const index = this.state.keyringsMetadata.findIndex((metadata) => metadata.id === keyringId);
1138
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[index];
1139
- }, _KeyringController_getKeyringByIdOrDefault = function _KeyringController_getKeyringByIdOrDefault(keyringId) {
1140
- if (!keyringId) {
1141
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0];
1142
- }
1143
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, keyringId);
1144
1091
  }, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
1145
1092
  return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
1146
1093
  }, _KeyringController_addQRKeyring =
@@ -1193,29 +1140,23 @@ async function _KeyringController_createNewVaultWithKeyring(password, keyring) {
1193
1140
  });
1194
1141
  __classPrivateFieldSet(this, _KeyringController_password, password, "f");
1195
1142
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
1196
- __classPrivateFieldSet(this, _KeyringController_keyringsMetadata, [], "f");
1197
1143
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyringWithFirstAccount).call(this, keyring.type, keyring.opts);
1198
1144
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
1199
1145
  }, _KeyringController_verifySeedPhrase =
1200
1146
  /**
1201
1147
  * Internal non-exclusive method to verify the seed phrase.
1202
1148
  *
1203
- * @param keyringId - The id of the keyring to verify the seed phrase for.
1204
1149
  * @returns A promise resolving to the seed phrase as Uint8Array.
1205
1150
  */
1206
- async function _KeyringController_verifySeedPhrase(keyringId) {
1151
+ async function _KeyringController_verifySeedPhrase() {
1207
1152
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1208
- const keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringByIdOrDefault).call(this, keyringId);
1209
- if (!keyring) {
1210
- throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
1153
+ const primaryKeyring = this.getKeyringsByType(KeyringTypes.hd)[0];
1154
+ if (!primaryKeyring) {
1155
+ throw new Error('No HD keyring found.');
1211
1156
  }
1212
- // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
1213
- if (keyring.type !== KeyringTypes.hd) {
1214
- throw new Error(constants_1.KeyringControllerError.UnsupportedVerifySeedPhrase);
1215
- }
1216
- assertHasUint8ArrayMnemonic(keyring);
1217
- const seedWords = keyring.mnemonic;
1218
- const accounts = await keyring.getAccounts();
1157
+ assertHasUint8ArrayMnemonic(primaryKeyring);
1158
+ const seedWords = primaryKeyring.mnemonic;
1159
+ const accounts = await primaryKeyring.getAccounts();
1219
1160
  /* istanbul ignore if */
1220
1161
  if (accounts.length === 0) {
1221
1162
  throw new Error('Cannot verify an empty keyring.');
@@ -1395,13 +1336,9 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1395
1336
  throw new Error(constants_1.KeyringControllerError.MissingVaultData);
1396
1337
  }
1397
1338
  const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
1398
- if (updatedKeyrings.length !== __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length) {
1399
- throw new Error(constants_1.KeyringControllerError.KeyringMetadataLengthMismatch);
1400
- }
1401
1339
  this.update((state) => {
1402
1340
  state.vault = updatedState.vault;
1403
1341
  state.keyrings = updatedKeyrings;
1404
- state.keyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
1405
1342
  if (updatedState.encryptionKey) {
1406
1343
  state.encryptionKey = updatedState.encryptionKey;
1407
1344
  state.encryptionSalt = JSON.parse(updatedState.vault).salt;
@@ -1441,48 +1378,19 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
1441
1378
  if (!firstAccount) {
1442
1379
  throw new Error(constants_1.KeyringControllerError.NoFirstAccount);
1443
1380
  }
1444
- return firstAccount;
1445
1381
  }, _KeyringController_newKeyring =
1446
1382
  /**
1447
1383
  * Instantiate, initialize and return a new keyring of the given `type`,
1448
1384
  * using the given `opts`. The keyring is built using the keyring builder
1449
1385
  * registered for the given `type`.
1450
1386
  *
1451
- * The internal keyring and keyring metadata arrays are updated with the new
1452
- * keyring as well.
1453
1387
  *
1454
1388
  * @param type - The type of keyring to add.
1455
- * @param data - Keyring initialization options.
1389
+ * @param data - The data to restore a previously serialized keyring.
1456
1390
  * @returns The new keyring.
1457
1391
  * @throws If the keyring includes duplicated accounts.
1458
1392
  */
1459
1393
  async function _KeyringController_newKeyring(type, data) {
1460
- const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1461
- if (__classPrivateFieldGet(this, _KeyringController_keyrings, "f").length !== __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length) {
1462
- throw new Error('Keyring metadata missing');
1463
- }
1464
- __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
1465
- __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").push(getDefaultKeyringMetadata());
1466
- return keyring;
1467
- }, _KeyringController_createKeyring =
1468
- /**
1469
- * Instantiate, initialize and return a keyring of the given `type` using the
1470
- * given `opts`. The keyring is built using the keyring builder registered
1471
- * for the given `type`.
1472
- *
1473
- * The keyring might be new, or it might be restored from the vault. This
1474
- * function should only be called from `#newKeyring` or `#restoreKeyring`,
1475
- * for the "new" and "restore" cases respectively.
1476
- *
1477
- * The internal keyring and keyring metadata arrays are *not* updated, the
1478
- * caller is expected to update them.
1479
- *
1480
- * @param type - The type of keyring to add.
1481
- * @param data - Keyring initialization options.
1482
- * @returns The new keyring.
1483
- * @throws If the keyring includes duplicated accounts.
1484
- */
1485
- async function _KeyringController_createKeyring(type, data) {
1486
1394
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1487
1395
  const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
1488
1396
  if (!keyringBuilder) {
@@ -1510,6 +1418,7 @@ async function _KeyringController_createKeyring(type, data) {
1510
1418
  // to its events after creating it
1511
1419
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_subscribeToQRKeyringEvents).call(this, keyring);
1512
1420
  }
1421
+ __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
1513
1422
  return keyring;
1514
1423
  }, _KeyringController_clearKeyrings =
1515
1424
  /**
@@ -1534,15 +1443,7 @@ async function _KeyringController_restoreKeyring(serialized) {
1534
1443
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1535
1444
  try {
1536
1445
  const { type, data } = serialized;
1537
- const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1538
- __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push(keyring);
1539
- // If metadata is missing, assume the data is from an installation before
1540
- // we had keyring metadata.
1541
- if (__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").length < __classPrivateFieldGet(this, _KeyringController_keyrings, "f").length) {
1542
- console.log(`Adding missing metadata for '${type}' keyring`);
1543
- __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").push(getDefaultKeyringMetadata());
1544
- }
1545
- return keyring;
1446
+ return await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, data);
1546
1447
  }
1547
1448
  catch (_) {
1548
1449
  __classPrivateFieldGet(this, _KeyringController_unsupportedKeyrings, "f").push(serialized);
@@ -1570,22 +1471,19 @@ async function _KeyringController_destroyKeyring(keyring) {
1570
1471
  async function _KeyringController_removeEmptyKeyrings() {
1571
1472
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1572
1473
  const validKeyrings = [];
1573
- const validKeyringMetadata = [];
1574
1474
  // Since getAccounts returns a Promise
1575
1475
  // We need to wait to hear back form each keyring
1576
1476
  // in order to decide which ones are now valid (accounts.length > 0)
1577
- await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring, index) => {
1477
+ await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async (keyring) => {
1578
1478
  const accounts = await keyring.getAccounts();
1579
1479
  if (accounts.length > 0) {
1580
1480
  validKeyrings.push(keyring);
1581
- validKeyringMetadata.push(__classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f")[index]);
1582
1481
  }
1583
1482
  else {
1584
1483
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
1585
1484
  }
1586
1485
  }));
1587
1486
  __classPrivateFieldSet(this, _KeyringController_keyrings, validKeyrings, "f");
1588
- __classPrivateFieldSet(this, _KeyringController_keyringsMetadata, validKeyringMetadata, "f");
1589
1487
  }, _KeyringController_checkForDuplicate =
1590
1488
  /**
1591
1489
  * Checks for duplicate keypairs, using the the first account in the given
@@ -1651,7 +1549,6 @@ async function _KeyringController_withRollback(callback) {
1651
1549
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async ({ releaseLock }) => {
1652
1550
  const currentSerializedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this);
1653
1551
  const currentPassword = __classPrivateFieldGet(this, _KeyringController_password, "f");
1654
- const currentKeyringsMetadata = __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice();
1655
1552
  try {
1656
1553
  return await callback({ releaseLock });
1657
1554
  }
@@ -1659,7 +1556,6 @@ async function _KeyringController_withRollback(callback) {
1659
1556
  // Keyrings and password are restored to their previous state
1660
1557
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, currentSerializedKeyrings);
1661
1558
  __classPrivateFieldSet(this, _KeyringController_password, currentPassword, "f");
1662
- __classPrivateFieldSet(this, _KeyringController_keyringsMetadata, currentKeyringsMetadata, "f");
1663
1559
  throw e;
1664
1560
  }
1665
1561
  });
@@ -1716,13 +1612,5 @@ async function withLock(mutex, callback) {
1716
1612
  releaseLock();
1717
1613
  }
1718
1614
  }
1719
- /**
1720
- * Generate a new keyring metadata object.
1721
- *
1722
- * @returns Keyring metadata.
1723
- */
1724
- function getDefaultKeyringMetadata() {
1725
- return { id: (0, ulid_1.ulid)(), name: '' };
1726
- }
1727
1615
  exports.default = KeyringController;
1728
1616
  //# sourceMappingURL=KeyringController.cjs.map