@metamask-previews/keyring-controller 19.0.1-preview-5db6a424 → 19.0.2-preview-cdf3e01b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [19.0.2]
11
+
12
+ ### Changed
13
+
14
+ - Remove use of `@metamask/keyring-api` ([#4695](https://github.com/MetaMask/core/pull/4695))
15
+ - `@metamask/providers` and `webextension-polyfill` peer depedencies are no longer required.
16
+ - Use new `@metamask/keyring-internal-api@^1.0.0` ([#4695](https://github.com/MetaMask/core/pull/4695))
17
+ - This package has been split out from the Keyring API. Its types are compatible with the `@metamask/keyring-api` package used previously.
18
+ - Bump `@metamask/message-manager` from `^11.0.2` to `^11.0.3` ([#5048](https://github.com/MetaMask/core/pull/5048))
19
+
10
20
  ## [19.0.1]
11
21
 
12
22
  ### Changed
@@ -608,7 +618,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
608
618
 
609
619
  All changes listed after this point were applied to this package following the monorepo conversion.
610
620
 
611
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0.1...HEAD
621
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0.2...HEAD
622
+ [19.0.2]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0.1...@metamask/keyring-controller@19.0.2
612
623
  [19.0.1]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@19.0.0...@metamask/keyring-controller@19.0.1
613
624
  [19.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@18.0.0...@metamask/keyring-controller@19.0.0
614
625
  [18.0.0]: https://github.com/MetaMask/core/compare/@metamask/keyring-controller@17.3.1...@metamask/keyring-controller@18.0.0
@@ -48,7 +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
- const ulid_1 = require("ulid");
52
51
  const constants_1 = require("./constants.cjs");
53
52
  const name = 'KeyringController';
54
53
  /**
@@ -200,14 +199,11 @@ function isSerializedKeyringsArray(array) {
200
199
  */
201
200
  async function displayForKeyring(keyring) {
202
201
  const accounts = await keyring.getAccounts();
203
- const { opts } = keyring;
204
202
  return {
205
203
  type: keyring.type,
206
204
  // Cast to `string[]` here is safe here because `accounts` has no nullish
207
205
  // values, and `normalize` returns `string` unless given a nullish value
208
206
  accounts: accounts.map(normalize),
209
- typeIndex: opts?.typeIndex,
210
- id: opts?.id,
211
207
  };
212
208
  }
213
209
  /**
@@ -304,23 +300,16 @@ class KeyringController extends base_controller_1.BaseController {
304
300
  * Adds a new account to the default (first) HD seed phrase keyring.
305
301
  *
306
302
  * @param accountCount - Number of accounts before adding a new one, used to
307
- * @param keyringId - The id of the keyring to add the account to.
308
303
  * make the method idempotent.
309
304
  * @returns Promise resolving to the added account address.
310
305
  */
311
- async addNewAccount(accountCount, keyringId) {
306
+ async addNewAccount(accountCount) {
312
307
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
313
- let selectedKeyring;
314
- if (keyringId) {
315
- selectedKeyring = this.getKeyringById(keyringId);
316
- }
317
- else {
318
- selectedKeyring = this.getKeyringsByType(KeyringTypes.hd)[0];
319
- }
320
- if (!selectedKeyring) {
308
+ const primaryKeyring = this.getKeyringsByType('HD Key Tree')[0];
309
+ if (!primaryKeyring) {
321
310
  throw new Error('No HD keyring found');
322
311
  }
323
- const oldAccounts = await selectedKeyring.getAccounts();
312
+ const oldAccounts = await primaryKeyring.getAccounts();
324
313
  if (accountCount && oldAccounts.length !== accountCount) {
325
314
  if (accountCount > oldAccounts.length) {
326
315
  throw new Error('Account out of sequence');
@@ -332,7 +321,7 @@ class KeyringController extends base_controller_1.BaseController {
332
321
  }
333
322
  return existingAccount;
334
323
  }
335
- const [addedAccountAddress] = await selectedKeyring.addAccounts(1);
324
+ const [addedAccountAddress] = await primaryKeyring.addAccounts(1);
336
325
  await this.verifySeedPhrase();
337
326
  return addedAccountAddress;
338
327
  });
@@ -386,14 +375,6 @@ class KeyringController extends base_controller_1.BaseController {
386
375
  });
387
376
  });
388
377
  }
389
- async createKeyringFromMnemonic(mnemonic) {
390
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
391
- return await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyringWithFirstAccount).call(this, KeyringTypes.hd, {
392
- mnemonic,
393
- numberOfAccounts: 1,
394
- });
395
- });
396
- }
397
378
  /**
398
379
  * Create a new vault and primary keyring.
399
380
  *
@@ -475,13 +456,10 @@ class KeyringController extends base_controller_1.BaseController {
475
456
  /**
476
457
  * Returns the public addresses of all accounts from every keyring.
477
458
  *
478
- * @param keyringId - The id of the keyring to get the accounts from.
479
459
  * @returns A promise resolving to an array of addresses.
480
460
  */
481
- async getAccounts(keyringId) {
482
- return this.state.keyrings
483
- .filter((keyring) => (keyringId ? keyring.id === keyringId : true))
484
- .reduce((accounts, keyring) => accounts.concat(keyring.accounts), []);
461
+ async getAccounts() {
462
+ return this.state.keyrings.reduce((accounts, keyring) => accounts.concat(keyring.accounts), []);
485
463
  }
486
464
  /**
487
465
  * Get encryption public key.
@@ -515,19 +493,6 @@ class KeyringController extends base_controller_1.BaseController {
515
493
  }
516
494
  return keyring.decryptMessage(address, messageParams.data);
517
495
  }
518
- /**
519
- * Returns the keyring with the given id.
520
- *
521
- * @param id - The id of the keyring to return.
522
- * @returns The keyring with the given id.
523
- */
524
- getKeyringById(id) {
525
- const keyring = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find((item) => item.opts.id === id);
526
- if (!keyring) {
527
- throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
528
- }
529
- return keyring;
530
- }
531
496
  /**
532
497
  * Returns the currently initialized keyring that manages
533
498
  * the specified `address` if one exists.
@@ -917,15 +882,12 @@ class KeyringController extends base_controller_1.BaseController {
917
882
  if ('address' in selector) {
918
883
  keyring = (await this.getKeyringForAccount(selector.address));
919
884
  }
920
- else if ('type' in selector) {
885
+ else {
921
886
  keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
922
887
  if (!keyring && options.createIfMissing) {
923
888
  keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
924
889
  }
925
890
  }
926
- else if ('id' in selector) {
927
- keyring = this.getKeyringById(selector.id);
928
- }
929
891
  if (!keyring) {
930
892
  throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
931
893
  }
@@ -1389,7 +1351,6 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
1389
1351
  if (!firstAccount) {
1390
1352
  throw new Error(constants_1.KeyringControllerError.NoFirstAccount);
1391
1353
  }
1392
- return firstAccount;
1393
1354
  }, _KeyringController_newKeyring =
1394
1355
  /**
1395
1356
  * Instantiate, initialize and return a new keyring of the given `type`,
@@ -1409,25 +1370,8 @@ async function _KeyringController_newKeyring(type, data) {
1409
1370
  throw new Error(`${constants_1.KeyringControllerError.NoKeyringBuilder}. Keyring type: ${type}`);
1410
1371
  }
1411
1372
  const keyring = keyringBuilder();
1412
- // find the last index of the type
1413
- const lastIndexOfType = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").reduce((maxIndex, item) => {
1414
- if (item.type === type) {
1415
- return Math.max(maxIndex, item.opts
1416
- ?.typeIndex ?? 0);
1417
- }
1418
- return maxIndex;
1419
- }, 0);
1420
- if (type === KeyringTypes.hd) {
1421
- await keyring.deserialize({
1422
- ...(data ?? {}),
1423
- typeIndex: lastIndexOfType,
1424
- id: (0, ulid_1.ulid)(),
1425
- });
1426
- }
1427
- else {
1428
- // @ts-expect-error Enforce data type after updating clients
1429
- await keyring.deserialize(data);
1430
- }
1373
+ // @ts-expect-error Enforce data type after updating clients
1374
+ await keyring.deserialize(data);
1431
1375
  if (keyring.init) {
1432
1376
  await keyring.init();
1433
1377
  }