@metamask-previews/keyring-controller 25.0.0-preview-6bed60a6 → 25.0.0-preview-bbf1f2af

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
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
  - Added an action to call `removeAccount` ([#7241](https://github.com/MetaMask/core/pull/7241))
14
14
  - This action is meant to be consumed by the `MultichainAccountService` to encapsulate the act of removing a wallet when seed phrase backup fails in the clients.
15
15
 
16
+ ### Changed
17
+
18
+ - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
19
+
16
20
  ## [25.0.0]
17
21
 
18
22
  ### Added
@@ -51,13 +51,15 @@ const lodash_1 = require("lodash");
51
51
  // When generating a ULID within the same millisecond, monotonicFactory provides some guarantees regarding sort order.
52
52
  const ulid_1 = require("ulid");
53
53
  const constants_1 = require("./constants.cjs");
54
- const errors_1 = require("./errors.cjs");
55
54
  const name = 'KeyringController';
56
55
  /**
57
56
  * Available keyring types
58
57
  */
59
58
  var KeyringTypes;
60
59
  (function (KeyringTypes) {
60
+ // Changing this would be a breaking change, and not worth the effort at this
61
+ // time, so we disable the linting rule for this block.
62
+ /* eslint-disable @typescript-eslint/naming-convention */
61
63
  KeyringTypes["simple"] = "Simple Key Pair";
62
64
  KeyringTypes["hd"] = "HD Key Tree";
63
65
  KeyringTypes["qr"] = "QR Hardware Wallet Device";
@@ -66,6 +68,7 @@ var KeyringTypes;
66
68
  KeyringTypes["ledger"] = "Ledger Hardware";
67
69
  KeyringTypes["lattice"] = "Lattice Hardware";
68
70
  KeyringTypes["snap"] = "Snap Keyring";
71
+ /* eslint-enable @typescript-eslint/naming-convention */
69
72
  })(KeyringTypes || (exports.KeyringTypes = KeyringTypes = {}));
70
73
  /**
71
74
  * Custody keyring types are a special case, as they are not a single type
@@ -83,8 +86,12 @@ exports.isCustodyKeyring = isCustodyKeyring;
83
86
  */
84
87
  var AccountImportStrategy;
85
88
  (function (AccountImportStrategy) {
89
+ // Changing this would be a breaking change, and not worth the effort at this
90
+ // time, so we disable the linting rule for this block.
91
+ /* eslint-disable @typescript-eslint/naming-convention */
86
92
  AccountImportStrategy["privateKey"] = "privateKey";
87
93
  AccountImportStrategy["json"] = "json";
94
+ /* eslint-enable @typescript-eslint/naming-convention */
88
95
  })(AccountImportStrategy || (exports.AccountImportStrategy = AccountImportStrategy = {}));
89
96
  /**
90
97
  * The `signTypedMessage` version
@@ -133,7 +140,7 @@ exports.getDefaultKeyringState = getDefaultKeyringState;
133
140
  */
134
141
  function assertHasUint8ArrayMnemonic(keyring) {
135
142
  if (!((0, utils_1.hasProperty)(keyring, 'mnemonic') && keyring.mnemonic instanceof Uint8Array)) {
136
- throw new errors_1.KeyringControllerError("Can't get mnemonic bytes from keyring");
143
+ throw new Error("Can't get mnemonic bytes from keyring");
137
144
  }
138
145
  }
139
146
  /**
@@ -144,10 +151,10 @@ function assertHasUint8ArrayMnemonic(keyring) {
144
151
  */
145
152
  function assertIsValidPassword(password) {
146
153
  if (typeof password !== 'string') {
147
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.WrongPasswordType);
154
+ throw new Error(constants_1.KeyringControllerError.WrongPasswordType);
148
155
  }
149
156
  if (!password?.length) {
150
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.InvalidEmptyPassword);
157
+ throw new Error(constants_1.KeyringControllerError.InvalidEmptyPassword);
151
158
  }
152
159
  }
153
160
  /**
@@ -158,7 +165,7 @@ function assertIsValidPassword(password) {
158
165
  */
159
166
  function assertIsEncryptionKeySet(encryptionKey) {
160
167
  if (!encryptionKey) {
161
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.EncryptionKeyNotSet);
168
+ throw new Error(constants_1.KeyringControllerError.EncryptionKeyNotSet);
162
169
  }
163
170
  }
164
171
  /**
@@ -311,17 +318,17 @@ class KeyringController extends base_controller_1.BaseController {
311
318
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
312
319
  const primaryKeyring = this.getKeyringsByType('HD Key Tree')[0];
313
320
  if (!primaryKeyring) {
314
- throw new errors_1.KeyringControllerError('No HD keyring found');
321
+ throw new Error('No HD keyring found');
315
322
  }
316
323
  const oldAccounts = await primaryKeyring.getAccounts();
317
324
  if (accountCount && oldAccounts.length !== accountCount) {
318
325
  if (accountCount > oldAccounts.length) {
319
- throw new errors_1.KeyringControllerError('Account out of sequence');
326
+ throw new Error('Account out of sequence');
320
327
  }
321
328
  // we return the account already existing at index `accountCount`
322
329
  const existingAccount = oldAccounts[accountCount];
323
330
  if (!existingAccount) {
324
- throw new errors_1.KeyringControllerError(`Can't find account at index ${accountCount}`);
331
+ throw new Error(`Can't find account at index ${accountCount}`);
325
332
  }
326
333
  return existingAccount;
327
334
  }
@@ -347,7 +354,7 @@ class KeyringController extends base_controller_1.BaseController {
347
354
  const oldAccounts = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getAccountsFromKeyrings).call(this);
348
355
  if (accountCount && oldAccounts.length !== accountCount) {
349
356
  if (accountCount > oldAccounts.length) {
350
- throw new errors_1.KeyringControllerError('Account out of sequence');
357
+ throw new Error('Account out of sequence');
351
358
  }
352
359
  const existingAccount = oldAccounts[accountCount];
353
360
  (0, utils_1.assertIsStrictHexString)(existingAccount);
@@ -419,7 +426,7 @@ class KeyringController extends base_controller_1.BaseController {
419
426
  */
420
427
  async verifyPassword(password) {
421
428
  if (!this.state.vault) {
422
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.VaultError);
429
+ throw new Error(constants_1.KeyringControllerError.VaultError);
423
430
  }
424
431
  await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decrypt(password, this.state.vault);
425
432
  }
@@ -443,7 +450,7 @@ class KeyringController extends base_controller_1.BaseController {
443
450
  await this.verifyPassword(password);
444
451
  const selectedKeyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringByIdOrDefault).call(this, keyringId);
445
452
  if (!selectedKeyring) {
446
- throw new errors_1.KeyringControllerError('Keyring not found');
453
+ throw new Error('Keyring not found');
447
454
  }
448
455
  assertHasUint8ArrayMnemonic(selectedKeyring);
449
456
  return selectedKeyring.mnemonic;
@@ -459,7 +466,7 @@ class KeyringController extends base_controller_1.BaseController {
459
466
  await this.verifyPassword(password);
460
467
  const keyring = (await this.getKeyringForAccount(address));
461
468
  if (!keyring.exportAccount) {
462
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedExportAccount);
469
+ throw new Error(constants_1.KeyringControllerError.UnsupportedExportAccount);
463
470
  }
464
471
  return await keyring.exportAccount(normalize(address));
465
472
  }
@@ -485,7 +492,7 @@ class KeyringController extends base_controller_1.BaseController {
485
492
  const address = (0, eth_sig_util_1.normalize)(account);
486
493
  const keyring = (await this.getKeyringForAccount(account));
487
494
  if (!keyring.getEncryptionPublicKey) {
488
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedGetEncryptionPublicKey);
495
+ throw new Error(constants_1.KeyringControllerError.UnsupportedGetEncryptionPublicKey);
489
496
  }
490
497
  return await keyring.getEncryptionPublicKey(address, opts);
491
498
  }
@@ -502,7 +509,7 @@ class KeyringController extends base_controller_1.BaseController {
502
509
  const address = (0, eth_sig_util_1.normalize)(messageParams.from);
503
510
  const keyring = (await this.getKeyringForAccount(address));
504
511
  if (!keyring.decryptMessage) {
505
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedDecryptMessage);
512
+ throw new Error(constants_1.KeyringControllerError.UnsupportedDecryptMessage);
506
513
  }
507
514
  return keyring.decryptMessage(address, messageParams.data);
508
515
  }
@@ -537,7 +544,7 @@ class KeyringController extends base_controller_1.BaseController {
537
544
  else if (!winners.length) {
538
545
  errorInfo = 'There are keyrings, but none match the address';
539
546
  }
540
- throw new errors_1.KeyringControllerError(`${constants_1.KeyringControllerError.NoKeyring}. Error info: ${errorInfo}`);
547
+ throw new Error(`${constants_1.KeyringControllerError.NoKeyring}. Error info: ${errorInfo}`);
541
548
  }
542
549
  /**
543
550
  * Returns all keyrings of the given type.
@@ -587,7 +594,7 @@ class KeyringController extends base_controller_1.BaseController {
587
594
  case AccountImportStrategy.privateKey: {
588
595
  const [importedKey] = args;
589
596
  if (!importedKey) {
590
- throw new errors_1.KeyringControllerError('Cannot import an empty key.');
597
+ throw new Error('Cannot import an empty key.');
591
598
  }
592
599
  const prefixed = (0, utils_1.add0x)(importedKey);
593
600
  let bufferedPrivateKey;
@@ -595,12 +602,12 @@ class KeyringController extends base_controller_1.BaseController {
595
602
  bufferedPrivateKey = (0, utils_1.hexToBytes)(prefixed);
596
603
  }
597
604
  catch {
598
- throw new errors_1.KeyringControllerError('Cannot import invalid private key.');
605
+ throw new Error('Cannot import invalid private key.');
599
606
  }
600
607
  if (!(0, util_1.isValidPrivate)(bufferedPrivateKey) ||
601
608
  // ensures that the key is 64 bytes long
602
609
  (0, util_1.getBinarySize)(prefixed) !== 64 + '0x'.length) {
603
- throw new errors_1.KeyringControllerError('Cannot import invalid private key.');
610
+ throw new Error('Cannot import invalid private key.');
604
611
  }
605
612
  privateKey = (0, utils_1.remove0x)(prefixed);
606
613
  break;
@@ -618,7 +625,7 @@ class KeyringController extends base_controller_1.BaseController {
618
625
  break;
619
626
  }
620
627
  default:
621
- throw new errors_1.KeyringControllerError(`Unexpected import strategy: '${String(strategy)}'`);
628
+ throw new Error(`Unexpected import strategy: '${String(strategy)}'`);
622
629
  }
623
630
  const newKeyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, KeyringTypes.simple, [
624
631
  privateKey,
@@ -643,11 +650,11 @@ class KeyringController extends base_controller_1.BaseController {
643
650
  const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;
644
651
  // Primary keyring should never be removed, so we need to keep at least one account in it
645
652
  if (isPrimaryKeyring && shouldRemoveKeyring) {
646
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.LastAccountInPrimaryKeyring);
653
+ throw new Error(constants_1.KeyringControllerError.LastAccountInPrimaryKeyring);
647
654
  }
648
655
  // Not all the keyrings support this, so we have to check
649
656
  if (!keyring.removeAccount) {
650
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedRemoveAccount);
657
+ throw new Error(constants_1.KeyringControllerError.UnsupportedRemoveAccount);
651
658
  }
652
659
  // The `removeAccount` method of snaps keyring is async. We have to update
653
660
  // the interface of the other keyrings to be async as well.
@@ -689,12 +696,12 @@ class KeyringController extends base_controller_1.BaseController {
689
696
  async signMessage(messageParams) {
690
697
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
691
698
  if (!messageParams.data) {
692
- throw new errors_1.KeyringControllerError("Can't sign an empty message");
699
+ throw new Error("Can't sign an empty message");
693
700
  }
694
701
  const address = (0, eth_sig_util_1.normalize)(messageParams.from);
695
702
  const keyring = (await this.getKeyringForAccount(address));
696
703
  if (!keyring.signMessage) {
697
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedSignMessage);
704
+ throw new Error(constants_1.KeyringControllerError.UnsupportedSignMessage);
698
705
  }
699
706
  return await keyring.signMessage(address, messageParams.data);
700
707
  }
@@ -709,12 +716,12 @@ class KeyringController extends base_controller_1.BaseController {
709
716
  const from = (0, eth_sig_util_1.normalize)(params.from);
710
717
  const keyring = (await this.getKeyringForAccount(from));
711
718
  if (!keyring.signEip7702Authorization) {
712
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedSignEip7702Authorization);
719
+ throw new Error(constants_1.KeyringControllerError.UnsupportedSignEip7702Authorization);
713
720
  }
714
721
  const { chainId, nonce } = params;
715
722
  const contractAddress = (0, eth_sig_util_1.normalize)(params.contractAddress);
716
723
  if (contractAddress === undefined) {
717
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.MissingEip7702AuthorizationContractAddress);
724
+ throw new Error(constants_1.KeyringControllerError.MissingEip7702AuthorizationContractAddress);
718
725
  }
719
726
  return await keyring.signEip7702Authorization(from, [
720
727
  chainId,
@@ -733,7 +740,7 @@ class KeyringController extends base_controller_1.BaseController {
733
740
  const address = (0, eth_sig_util_1.normalize)(messageParams.from);
734
741
  const keyring = (await this.getKeyringForAccount(address));
735
742
  if (!keyring.signPersonalMessage) {
736
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedSignPersonalMessage);
743
+ throw new Error(constants_1.KeyringControllerError.UnsupportedSignPersonalMessage);
737
744
  }
738
745
  const normalizedData = normalize(messageParams.data);
739
746
  return await keyring.signPersonalMessage(address, normalizedData);
@@ -754,14 +761,14 @@ class KeyringController extends base_controller_1.BaseController {
754
761
  SignTypedDataVersion.V3,
755
762
  SignTypedDataVersion.V4,
756
763
  ].includes(version)) {
757
- throw new errors_1.KeyringControllerError(`Unexpected signTypedMessage version: '${version}'`);
764
+ throw new Error(`Unexpected signTypedMessage version: '${version}'`);
758
765
  }
759
766
  // Cast to `Hex` here is safe here because `messageParams.from` is not nullish.
760
767
  // `normalize` returns `Hex` unless given a nullish value.
761
768
  const address = (0, eth_sig_util_1.normalize)(messageParams.from);
762
769
  const keyring = (await this.getKeyringForAccount(address));
763
770
  if (!keyring.signTypedData) {
764
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedSignTypedMessage);
771
+ throw new Error(constants_1.KeyringControllerError.UnsupportedSignTypedMessage);
765
772
  }
766
773
  return await keyring.signTypedData(address, version !== SignTypedDataVersion.V1 &&
767
774
  typeof messageParams.data === 'string'
@@ -769,10 +776,9 @@ class KeyringController extends base_controller_1.BaseController {
769
776
  : messageParams.data, { version });
770
777
  }
771
778
  catch (error) {
772
- const errorMessage = error instanceof Error
773
- ? `${error.name}: ${error.message}`
774
- : String(error);
775
- throw new errors_1.KeyringControllerError(`Keyring Controller signTypedMessage: ${errorMessage}`, error instanceof Error ? error : undefined);
779
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
780
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
781
+ throw new Error(`Keyring Controller signTypedMessage: ${error}`);
776
782
  }
777
783
  }
778
784
  /**
@@ -788,7 +794,7 @@ class KeyringController extends base_controller_1.BaseController {
788
794
  const address = (0, eth_sig_util_1.normalize)(from);
789
795
  const keyring = (await this.getKeyringForAccount(address));
790
796
  if (!keyring.signTransaction) {
791
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedSignTransaction);
797
+ throw new Error(constants_1.KeyringControllerError.UnsupportedSignTransaction);
792
798
  }
793
799
  return await keyring.signTransaction(address, transaction, opts);
794
800
  }
@@ -805,7 +811,7 @@ class KeyringController extends base_controller_1.BaseController {
805
811
  const address = (0, eth_sig_util_1.normalize)(from);
806
812
  const keyring = (await this.getKeyringForAccount(address));
807
813
  if (!keyring.prepareUserOperation) {
808
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedPrepareUserOperation);
814
+ throw new Error(constants_1.KeyringControllerError.UnsupportedPrepareUserOperation);
809
815
  }
810
816
  return await keyring.prepareUserOperation(address, transactions, executionContext);
811
817
  }
@@ -823,7 +829,7 @@ class KeyringController extends base_controller_1.BaseController {
823
829
  const address = (0, eth_sig_util_1.normalize)(from);
824
830
  const keyring = (await this.getKeyringForAccount(address));
825
831
  if (!keyring.patchUserOperation) {
826
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedPatchUserOperation);
832
+ throw new Error(constants_1.KeyringControllerError.UnsupportedPatchUserOperation);
827
833
  }
828
834
  return await keyring.patchUserOperation(address, userOp, executionContext);
829
835
  }
@@ -840,7 +846,7 @@ class KeyringController extends base_controller_1.BaseController {
840
846
  const address = (0, eth_sig_util_1.normalize)(from);
841
847
  const keyring = (await this.getKeyringForAccount(address));
842
848
  if (!keyring.signUserOperation) {
843
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedSignUserOperation);
849
+ throw new Error(constants_1.KeyringControllerError.UnsupportedSignUserOperation);
844
850
  }
845
851
  return await keyring.signUserOperation(address, userOp, executionContext);
846
852
  }
@@ -968,7 +974,7 @@ class KeyringController extends base_controller_1.BaseController {
968
974
  keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, selector.id);
969
975
  }
970
976
  if (!keyring) {
971
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.KeyringNotFound);
977
+ throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
972
978
  }
973
979
  const result = await operation({
974
980
  keyring,
@@ -979,7 +985,7 @@ class KeyringController extends base_controller_1.BaseController {
979
985
  // should be discouraged, as it can lead to unexpected behavior.
980
986
  // This error is thrown to prevent consumers using `withKeyring`
981
987
  // as a way to get a reference to a keyring instance.
982
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsafeDirectKeyringAccess);
988
+ throw new Error(constants_1.KeyringControllerError.UnsafeDirectKeyringAccess);
983
989
  }
984
990
  return result;
985
991
  });
@@ -1022,7 +1028,7 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1022
1028
  }, _KeyringController_getKeyringMetadata = function _KeyringController_getKeyringMetadata(keyring) {
1023
1029
  const keyringWithMetadata = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find((candidate) => candidate.keyring === keyring);
1024
1030
  if (!keyringWithMetadata) {
1025
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.KeyringNotFound);
1031
+ throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
1026
1032
  }
1027
1033
  return keyringWithMetadata.metadata;
1028
1034
  }, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
@@ -1109,7 +1115,7 @@ async function _KeyringController_deriveAndSetEncryptionKey(password, options =
1109
1115
  }
1110
1116
  const { vault } = this.state;
1111
1117
  if (vault && JSON.parse(vault).salt !== keyDerivationSalt) {
1112
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.ExpiredCredentials);
1118
+ throw new Error(constants_1.KeyringControllerError.ExpiredCredentials);
1113
1119
  }
1114
1120
  __classPrivateFieldSet(this, _KeyringController_encryptionKey, {
1115
1121
  salt: keyDerivationSalt,
@@ -1126,17 +1132,17 @@ async function _KeyringController_verifySeedPhrase(keyringId) {
1126
1132
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1127
1133
  const keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringByIdOrDefault).call(this, keyringId);
1128
1134
  if (!keyring) {
1129
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.KeyringNotFound);
1135
+ throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
1130
1136
  }
1131
1137
  if (keyring.type !== KeyringTypes.hd) {
1132
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedVerifySeedPhrase);
1138
+ throw new Error(constants_1.KeyringControllerError.UnsupportedVerifySeedPhrase);
1133
1139
  }
1134
1140
  assertHasUint8ArrayMnemonic(keyring);
1135
1141
  const seedWords = keyring.mnemonic;
1136
1142
  const accounts = await keyring.getAccounts();
1137
1143
  /* istanbul ignore if */
1138
1144
  if (accounts.length === 0) {
1139
- throw new errors_1.KeyringControllerError('Cannot verify an empty keyring.');
1145
+ throw new Error('Cannot verify an empty keyring.');
1140
1146
  }
1141
1147
  // The HD Keyring Builder is a default keyring builder
1142
1148
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -1151,12 +1157,12 @@ async function _KeyringController_verifySeedPhrase(keyringId) {
1151
1157
  const testAccounts = await hdKeyring.getAccounts();
1152
1158
  /* istanbul ignore if */
1153
1159
  if (testAccounts.length !== accounts.length) {
1154
- throw new errors_1.KeyringControllerError('Seed phrase imported incorrect number of accounts.');
1160
+ throw new Error('Seed phrase imported incorrect number of accounts.');
1155
1161
  }
1156
1162
  testAccounts.forEach((account, i) => {
1157
1163
  /* istanbul ignore if */
1158
1164
  if (account.toLowerCase() !== accounts[i].toLowerCase()) {
1159
- throw new errors_1.KeyringControllerError('Seed phrase imported different accounts.');
1165
+ throw new Error('Seed phrase imported different accounts.');
1160
1166
  }
1161
1167
  });
1162
1168
  return seedWords;
@@ -1237,7 +1243,7 @@ async function _KeyringController_restoreSerializedKeyrings(serializedKeyrings)
1237
1243
  async function _KeyringController_unlockKeyrings(credentials) {
1238
1244
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async () => {
1239
1245
  if (!this.state.vault) {
1240
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.VaultError);
1246
+ throw new Error(constants_1.KeyringControllerError.VaultError);
1241
1247
  }
1242
1248
  const parsedEncryptedVault = JSON.parse(this.state.vault);
1243
1249
  if ('password' in credentials) {
@@ -1248,12 +1254,12 @@ async function _KeyringController_unlockKeyrings(credentials) {
1248
1254
  }
1249
1255
  const encryptionKey = __classPrivateFieldGet(this, _KeyringController_encryptionKey, "f")?.serialized;
1250
1256
  if (!encryptionKey) {
1251
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.MissingCredentials);
1257
+ throw new Error(constants_1.KeyringControllerError.MissingCredentials);
1252
1258
  }
1253
1259
  const key = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").importKey(encryptionKey);
1254
1260
  const vault = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decryptWithKey(key, parsedEncryptedVault);
1255
1261
  if (!isSerializedKeyringsArray(vault)) {
1256
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.VaultDataError);
1262
+ throw new Error(constants_1.KeyringControllerError.VaultDataError);
1257
1263
  }
1258
1264
  const { keyrings, newMetadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, vault);
1259
1265
  const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
@@ -1269,11 +1275,11 @@ async function _KeyringController_unlockKeyrings(credentials) {
1269
1275
  // Ensure no duplicate accounts are persisted.
1270
1276
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this);
1271
1277
  if (!__classPrivateFieldGet(this, _KeyringController_encryptionKey, "f")) {
1272
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.MissingCredentials);
1278
+ throw new Error(constants_1.KeyringControllerError.MissingCredentials);
1273
1279
  }
1274
1280
  const serializedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this);
1275
1281
  if (!serializedKeyrings.some((keyring) => keyring.type === KeyringTypes.hd)) {
1276
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.NoHdKeyring);
1282
+ throw new Error(constants_1.KeyringControllerError.NoHdKeyring);
1277
1283
  }
1278
1284
  const key = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").importKey(__classPrivateFieldGet(this, _KeyringController_encryptionKey, "f").serialized);
1279
1285
  const encryptedVault = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").encryptWithKey(key, serializedKeyrings);
@@ -1332,7 +1338,7 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
1332
1338
  const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, opts);
1333
1339
  const [firstAccount] = await keyring.getAccounts();
1334
1340
  if (!firstAccount) {
1335
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.NoFirstAccount);
1341
+ throw new Error(constants_1.KeyringControllerError.NoFirstAccount);
1336
1342
  }
1337
1343
  return firstAccount;
1338
1344
  }, _KeyringController_newKeyring =
@@ -1375,7 +1381,7 @@ async function _KeyringController_createKeyring(type, data) {
1375
1381
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1376
1382
  const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
1377
1383
  if (!keyringBuilder) {
1378
- throw new errors_1.KeyringControllerError(`${constants_1.KeyringControllerError.NoKeyringBuilder}. Keyring type: ${type}`);
1384
+ throw new Error(`${constants_1.KeyringControllerError.NoKeyringBuilder}. Keyring type: ${type}`);
1379
1385
  }
1380
1386
  const keyring = keyringBuilder();
1381
1387
  if (data) {
@@ -1385,10 +1391,9 @@ async function _KeyringController_createKeyring(type, data) {
1385
1391
  if (keyring.init) {
1386
1392
  await keyring.init();
1387
1393
  }
1388
- if (type === KeyringTypes.hd &&
1389
- (!(0, utils_1.isObject)(data) || !data.mnemonic)) {
1394
+ if (type === KeyringTypes.hd && (!(0, utils_1.isObject)(data) || !data.mnemonic)) {
1390
1395
  if (!keyring.generateRandomMnemonic) {
1391
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.UnsupportedGenerateRandomMnemonic);
1396
+ throw new Error(constants_1.KeyringControllerError.UnsupportedGenerateRandomMnemonic);
1392
1397
  }
1393
1398
  // NOTE: Not all keyrings implement this method in a asynchronous-way. Using `await` for
1394
1399
  // non-thenable will still be valid (despite not being really useful). It allows us to cover both
@@ -1489,7 +1494,7 @@ async function _KeyringController_removeEmptyKeyrings() {
1489
1494
  async function _KeyringController_assertNoDuplicateAccounts(additionalKeyrings = []) {
1490
1495
  const accounts = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getAccountsFromKeyrings).call(this, additionalKeyrings);
1491
1496
  if (new Set(accounts).size !== accounts.length) {
1492
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.DuplicatedAccount);
1497
+ throw new Error(constants_1.KeyringControllerError.DuplicatedAccount);
1493
1498
  }
1494
1499
  }, _KeyringController_setUnlocked = function _KeyringController_setUnlocked() {
1495
1500
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
@@ -1499,7 +1504,7 @@ async function _KeyringController_assertNoDuplicateAccounts(additionalKeyrings =
1499
1504
  this.messenger.publish(`${name}:unlock`);
1500
1505
  }, _KeyringController_assertIsUnlocked = function _KeyringController_assertIsUnlocked() {
1501
1506
  if (!this.state.isUnlocked) {
1502
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.ControllerLocked);
1507
+ throw new Error(constants_1.KeyringControllerError.ControllerLocked);
1503
1508
  }
1504
1509
  }, _KeyringController_persistOrRollback =
1505
1510
  /**
@@ -1545,7 +1550,7 @@ async function _KeyringController_withRollback(callback) {
1545
1550
  });
1546
1551
  }, _KeyringController_assertControllerMutexIsLocked = function _KeyringController_assertControllerMutexIsLocked() {
1547
1552
  if (!__classPrivateFieldGet(this, _KeyringController_controllerOperationMutex, "f").isLocked()) {
1548
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerError.ControllerLockRequired);
1553
+ throw new Error(constants_1.KeyringControllerError.ControllerLockRequired);
1549
1554
  }
1550
1555
  }, _KeyringController_withControllerLock =
1551
1556
  /**