@metamask-previews/keyring-controller 19.2.1-preview-def92ff7 → 19.2.1-preview-4a9b4a93
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 +7 -0
- package/dist/KeyringController.cjs +19 -10
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +18 -11
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +18 -11
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +21 -12
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
11
11
|
|
|
12
12
|
### Changed
|
|
13
13
|
|
|
14
|
+
- **BREAKING:** `addNewKeyring` method now returns `Promise<KeyringMetadata>` instead of `Promise<unknown>` ([#5372](https://github.com/MetaMask/core/pull/5372))
|
|
15
|
+
- Consumers can use the returned `KeyringMetadata.id` to access the created keyring instance via `withKeyring`.
|
|
16
|
+
- **BREAKING:** `withKeyring` method now requires a callback argument of type `({ keyring: SelectedKeyring; metadata: KeyringMetadata }) => Promise<CallbackResult>` ([#5372](https://github.com/MetaMask/core/pull/5372))
|
|
14
17
|
- Bump `@metamask/keyring-api"` from `^17.0.0` to `^17.2.0` ([#5366](https://github.com/MetaMask/core/pull/5366))
|
|
15
18
|
- Bump `@metamask/keyring-internal-api` from `^4.0.1` to `^4.0.3` ([#5356](https://github.com/MetaMask/core/pull/5356)), ([#5366](https://github.com/MetaMask/core/pull/5366))
|
|
16
19
|
|
|
@@ -27,6 +30,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
27
30
|
- The action can be used to consume the `withKeyring` method of the `KeyringController` class
|
|
28
31
|
- Support keyring metadata in KeyringController ([#5112](https://github.com/MetaMask/core/pull/5112))
|
|
29
32
|
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- Bump `@ethereumjs/util` from `^8.1.0` to `^9.1.0` ([#5347](https://github.com/MetaMask/core/pull/5347))
|
|
36
|
+
|
|
30
37
|
## [19.1.0]
|
|
31
38
|
|
|
32
39
|
### Added
|
|
@@ -36,13 +36,13 @@ 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_keyringsMetadata, _KeyringController_password, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _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;
|
|
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");
|
|
43
43
|
const base_controller_1 = require("@metamask/base-controller");
|
|
44
44
|
const encryptorUtils = __importStar(require("@metamask/browser-passworder"));
|
|
45
|
-
const eth_hd_keyring_1 =
|
|
45
|
+
const eth_hd_keyring_1 = require("@metamask/eth-hd-keyring");
|
|
46
46
|
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
47
47
|
const eth_simple_keyring_1 = __importDefault(require("@metamask/eth-simple-keyring"));
|
|
48
48
|
const utils_1 = require("@metamask/utils");
|
|
@@ -115,7 +115,7 @@ const defaultKeyringBuilders = [
|
|
|
115
115
|
// @ts-expect-error keyring types are mismatched
|
|
116
116
|
keyringBuilderFactory(eth_simple_keyring_1.default),
|
|
117
117
|
// @ts-expect-error keyring types are mismatched
|
|
118
|
-
keyringBuilderFactory(eth_hd_keyring_1.
|
|
118
|
+
keyringBuilderFactory(eth_hd_keyring_1.HdKeyring),
|
|
119
119
|
];
|
|
120
120
|
const getDefaultKeyringState = () => {
|
|
121
121
|
return {
|
|
@@ -395,14 +395,14 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
395
395
|
* @param type - Keyring type name.
|
|
396
396
|
* @param opts - Keyring options.
|
|
397
397
|
* @throws If a builder for the given `type` does not exist.
|
|
398
|
-
* @returns Promise resolving to the
|
|
398
|
+
* @returns Promise resolving to the new keyring metadata.
|
|
399
399
|
*/
|
|
400
400
|
async addNewKeyring(type, opts) {
|
|
401
401
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
402
402
|
if (type === KeyringTypes.qr) {
|
|
403
|
-
return this.getOrAddQRKeyring();
|
|
403
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, await this.getOrAddQRKeyring());
|
|
404
404
|
}
|
|
405
|
-
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, opts));
|
|
405
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, opts)));
|
|
406
406
|
}
|
|
407
407
|
/**
|
|
408
408
|
* Method to verify a given password validity. Throws an
|
|
@@ -580,7 +580,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
580
580
|
const prefixed = (0, utils_1.add0x)(importedKey);
|
|
581
581
|
let bufferedPrivateKey;
|
|
582
582
|
try {
|
|
583
|
-
bufferedPrivateKey = (0,
|
|
583
|
+
bufferedPrivateKey = (0, utils_1.hexToBytes)(prefixed);
|
|
584
584
|
}
|
|
585
585
|
catch {
|
|
586
586
|
throw new Error('Cannot import invalid private key.');
|
|
@@ -910,7 +910,10 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
910
910
|
if (!keyring) {
|
|
911
911
|
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
912
912
|
}
|
|
913
|
-
const result = await operation(
|
|
913
|
+
const result = await operation({
|
|
914
|
+
keyring,
|
|
915
|
+
metadata: __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, keyring),
|
|
916
|
+
});
|
|
914
917
|
if (Object.is(result, keyring)) {
|
|
915
918
|
// Access to a keyring instance outside of controller safeguards
|
|
916
919
|
// should be discouraged, as it can lead to unexpected behavior.
|
|
@@ -1144,6 +1147,10 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
|
|
|
1144
1147
|
return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0];
|
|
1145
1148
|
}
|
|
1146
1149
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, keyringId);
|
|
1150
|
+
}, _KeyringController_getKeyringMetadata = function _KeyringController_getKeyringMetadata(keyring) {
|
|
1151
|
+
const index = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").findIndex((keyringCandidate) => keyringCandidate === keyring);
|
|
1152
|
+
(0, utils_1.assert)(index !== -1, constants_1.KeyringControllerError.KeyringNotFound);
|
|
1153
|
+
return __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f")[index];
|
|
1147
1154
|
}, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
|
|
1148
1155
|
return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
|
|
1149
1156
|
}, _KeyringController_addQRKeyring =
|
|
@@ -1492,8 +1499,10 @@ async function _KeyringController_createKeyring(type, data) {
|
|
|
1492
1499
|
throw new Error(`${constants_1.KeyringControllerError.NoKeyringBuilder}. Keyring type: ${type}`);
|
|
1493
1500
|
}
|
|
1494
1501
|
const keyring = keyringBuilder();
|
|
1495
|
-
|
|
1496
|
-
|
|
1502
|
+
if (data) {
|
|
1503
|
+
// @ts-expect-error Enforce data type after updating clients
|
|
1504
|
+
await keyring.deserialize(data);
|
|
1505
|
+
}
|
|
1497
1506
|
if (keyring.init) {
|
|
1498
1507
|
await keyring.init();
|
|
1499
1508
|
}
|