@metamask-previews/keyring-controller 25.0.0-preview-2cd68d1 → 25.0.0-preview-f557eade

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
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Added
11
11
 
12
+ - Added new `KeyringBuilder` type ([#7334](https://github.com/MetaMask/core/pull/7334))
12
13
  - Added an action to call `removeAccount` ([#7241](https://github.com/MetaMask/core/pull/7241))
13
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.
14
15
 
@@ -519,7 +519,7 @@ class KeyringController extends base_controller_1.BaseController {
519
519
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
520
520
  const address = normalize(account);
521
521
  const candidates = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(async ({ keyring }) => {
522
- return Promise.all([keyring, keyring.getAccounts()]);
522
+ return [keyring, await keyring.getAccounts()];
523
523
  }));
524
524
  const winners = candidates.filter((candidate) => {
525
525
  const accounts = candidate[1].map(normalize);
@@ -583,7 +583,7 @@ class KeyringController extends base_controller_1.BaseController {
583
583
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
584
584
  let privateKey;
585
585
  switch (strategy) {
586
- case AccountImportStrategy.privateKey:
586
+ case AccountImportStrategy.privateKey: {
587
587
  const [importedKey] = args;
588
588
  if (!importedKey) {
589
589
  throw new Error('Cannot import an empty key.');
@@ -603,17 +603,19 @@ class KeyringController extends base_controller_1.BaseController {
603
603
  }
604
604
  privateKey = (0, utils_1.remove0x)(prefixed);
605
605
  break;
606
- case AccountImportStrategy.json:
606
+ }
607
+ case AccountImportStrategy.json: {
607
608
  let wallet;
608
609
  const [input, password] = args;
609
610
  try {
610
611
  wallet = ethereumjs_wallet_1.thirdparty.fromEtherWallet(input, password);
611
612
  }
612
- catch (e) {
613
- wallet = wallet || (await ethereumjs_wallet_1.default.fromV3(input, password, true));
613
+ catch {
614
+ wallet = wallet ?? (await ethereumjs_wallet_1.default.fromV3(input, password, true));
614
615
  }
615
- privateKey = (0, utils_1.bytesToHex)(wallet.getPrivateKey());
616
+ privateKey = (0, utils_1.bytesToHex)(new Uint8Array(wallet.getPrivateKey()));
616
617
  break;
618
+ }
617
619
  default:
618
620
  throw new Error(`Unexpected import strategy: '${String(strategy)}'`);
619
621
  }
@@ -955,7 +957,7 @@ class KeyringController extends base_controller_1.BaseController {
955
957
  keyring = (await this.getKeyringForAccount(selector.address));
956
958
  }
957
959
  else if ('type' in selector) {
958
- keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
960
+ keyring = this.getKeyringsByType(selector.type)[selector.index ?? 0];
959
961
  if (!keyring && options.createIfMissing) {
960
962
  keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
961
963
  }
@@ -1240,7 +1242,7 @@ async function _KeyringController_unlockKeyrings(credentials) {
1240
1242
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_deriveAndSetEncryptionKey).call(this, credentials.password);
1241
1243
  }
1242
1244
  else {
1243
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setEncryptionKey).call(this, credentials.encryptionKey, credentials.encryptionSalt || parsedEncryptedVault.salt);
1245
+ __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setEncryptionKey).call(this, credentials.encryptionKey, credentials.encryptionSalt ?? parsedEncryptedVault.salt);
1244
1246
  }
1245
1247
  const encryptionKey = __classPrivateFieldGet(this, _KeyringController_encryptionKey, "f")?.serialized;
1246
1248
  if (!encryptionKey) {
@@ -1531,11 +1533,11 @@ async function _KeyringController_withRollback(callback) {
1531
1533
  try {
1532
1534
  return await callback({ releaseLock });
1533
1535
  }
1534
- catch (e) {
1536
+ catch (error) {
1535
1537
  // Keyrings and encryption credentials are restored to their previous state
1536
1538
  __classPrivateFieldSet(this, _KeyringController_encryptionKey, currentEncryptionKey, "f");
1537
1539
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, currentSerializedKeyrings);
1538
- throw e;
1540
+ throw error;
1539
1541
  }
1540
1542
  });
1541
1543
  }, _KeyringController_assertControllerMutexIsLocked = function _KeyringController_assertControllerMutexIsLocked() {