@metamask-previews/keyring-controller 19.0.1-preview-953c11ad → 19.0.2-preview-28a9753
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 +12 -1
- package/dist/KeyringController.cjs +13 -75
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +5 -21
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +5 -21
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +13 -75
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +6 -16
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.
|
|
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
|
|
306
|
+
async addNewAccount(accountCount) {
|
|
312
307
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
|
|
313
|
-
|
|
314
|
-
if (
|
|
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
|
|
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
|
|
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
|
*
|
|
@@ -450,18 +431,12 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
450
431
|
* Gets the seed phrase of the HD keyring.
|
|
451
432
|
*
|
|
452
433
|
* @param password - Password of the keyring.
|
|
453
|
-
* @param typeIndex - Hd keyring identifier
|
|
454
434
|
* @returns Promise resolving to the seed phrase.
|
|
455
435
|
*/
|
|
456
|
-
async exportSeedPhrase(password
|
|
436
|
+
async exportSeedPhrase(password) {
|
|
457
437
|
await this.verifyPassword(password);
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (!keyring) {
|
|
461
|
-
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
462
|
-
}
|
|
463
|
-
assertHasUint8ArrayMnemonic(keyring);
|
|
464
|
-
return keyring.mnemonic;
|
|
438
|
+
assertHasUint8ArrayMnemonic(__classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]);
|
|
439
|
+
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0].mnemonic;
|
|
465
440
|
}
|
|
466
441
|
/**
|
|
467
442
|
* Gets the private key from the keyring controlling an address.
|
|
@@ -481,13 +456,10 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
481
456
|
/**
|
|
482
457
|
* Returns the public addresses of all accounts from every keyring.
|
|
483
458
|
*
|
|
484
|
-
* @param keyringId - The id of the keyring to get the accounts from.
|
|
485
459
|
* @returns A promise resolving to an array of addresses.
|
|
486
460
|
*/
|
|
487
|
-
async getAccounts(
|
|
488
|
-
return this.state.keyrings
|
|
489
|
-
.filter((keyring) => (keyringId ? keyring.id === keyringId : true))
|
|
490
|
-
.reduce((accounts, keyring) => accounts.concat(keyring.accounts), []);
|
|
461
|
+
async getAccounts() {
|
|
462
|
+
return this.state.keyrings.reduce((accounts, keyring) => accounts.concat(keyring.accounts), []);
|
|
491
463
|
}
|
|
492
464
|
/**
|
|
493
465
|
* Get encryption public key.
|
|
@@ -521,19 +493,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
521
493
|
}
|
|
522
494
|
return keyring.decryptMessage(address, messageParams.data);
|
|
523
495
|
}
|
|
524
|
-
/**
|
|
525
|
-
* Returns the keyring with the given id.
|
|
526
|
-
*
|
|
527
|
-
* @param id - The id of the keyring to return.
|
|
528
|
-
* @returns The keyring with the given id.
|
|
529
|
-
*/
|
|
530
|
-
getKeyringById(id) {
|
|
531
|
-
const keyring = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find((item) => item.opts.id === id);
|
|
532
|
-
if (!keyring) {
|
|
533
|
-
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
534
|
-
}
|
|
535
|
-
return keyring;
|
|
536
|
-
}
|
|
537
496
|
/**
|
|
538
497
|
* Returns the currently initialized keyring that manages
|
|
539
498
|
* the specified `address` if one exists.
|
|
@@ -923,15 +882,12 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
923
882
|
if ('address' in selector) {
|
|
924
883
|
keyring = (await this.getKeyringForAccount(selector.address));
|
|
925
884
|
}
|
|
926
|
-
else
|
|
885
|
+
else {
|
|
927
886
|
keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
|
|
928
887
|
if (!keyring && options.createIfMissing) {
|
|
929
888
|
keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
|
|
930
889
|
}
|
|
931
890
|
}
|
|
932
|
-
else if ('id' in selector) {
|
|
933
|
-
keyring = this.getKeyringById(selector.id);
|
|
934
|
-
}
|
|
935
891
|
if (!keyring) {
|
|
936
892
|
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
937
893
|
}
|
|
@@ -1395,7 +1351,6 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
|
|
|
1395
1351
|
if (!firstAccount) {
|
|
1396
1352
|
throw new Error(constants_1.KeyringControllerError.NoFirstAccount);
|
|
1397
1353
|
}
|
|
1398
|
-
return firstAccount;
|
|
1399
1354
|
}, _KeyringController_newKeyring =
|
|
1400
1355
|
/**
|
|
1401
1356
|
* Instantiate, initialize and return a new keyring of the given `type`,
|
|
@@ -1415,25 +1370,8 @@ async function _KeyringController_newKeyring(type, data) {
|
|
|
1415
1370
|
throw new Error(`${constants_1.KeyringControllerError.NoKeyringBuilder}. Keyring type: ${type}`);
|
|
1416
1371
|
}
|
|
1417
1372
|
const keyring = keyringBuilder();
|
|
1418
|
-
//
|
|
1419
|
-
|
|
1420
|
-
if (item.type === type) {
|
|
1421
|
-
return Math.max(maxIndex, item.opts
|
|
1422
|
-
?.typeIndex ?? 0);
|
|
1423
|
-
}
|
|
1424
|
-
return maxIndex;
|
|
1425
|
-
}, 0);
|
|
1426
|
-
if (type === KeyringTypes.hd) {
|
|
1427
|
-
await keyring.deserialize({
|
|
1428
|
-
...(data ?? {}),
|
|
1429
|
-
typeIndex: lastIndexOfType + 1,
|
|
1430
|
-
id: (0, ulid_1.ulid)(),
|
|
1431
|
-
});
|
|
1432
|
-
}
|
|
1433
|
-
else {
|
|
1434
|
-
// @ts-expect-error Enforce data type after updating clients
|
|
1435
|
-
await keyring.deserialize(data);
|
|
1436
|
-
}
|
|
1373
|
+
// @ts-expect-error Enforce data type after updating clients
|
|
1374
|
+
await keyring.deserialize(data);
|
|
1437
1375
|
if (keyring.init) {
|
|
1438
1376
|
await keyring.init();
|
|
1439
1377
|
}
|