@metamask-previews/keyring-controller 19.0.2-preview-9e831370 → 19.0.2-preview-03f094b7
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 +4 -0
- package/dist/KeyringController.cjs +44 -35
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +44 -35
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Bump `@metamask/base-controller` from `^7.0.0` to `^7.1.0` ([#5079](https://github.com/MetaMask/core/pull/5079))
|
|
13
|
+
|
|
10
14
|
## [19.0.2]
|
|
11
15
|
|
|
12
16
|
### Changed
|
|
@@ -36,7 +36,7 @@ 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_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_password, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_checkForDuplicate, _KeyringController_setUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
|
|
39
|
+
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_password, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _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_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_checkForDuplicate, _KeyringController_setUnlocked, _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");
|
|
@@ -322,7 +322,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
322
322
|
return existingAccount;
|
|
323
323
|
}
|
|
324
324
|
const [addedAccountAddress] = await primaryKeyring.addAccounts(1);
|
|
325
|
-
await this.
|
|
325
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this);
|
|
326
326
|
return addedAccountAddress;
|
|
327
327
|
});
|
|
328
328
|
}
|
|
@@ -840,39 +840,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
840
840
|
* @returns Promise resolving to the seed phrase as Uint8Array.
|
|
841
841
|
*/
|
|
842
842
|
async verifySeedPhrase() {
|
|
843
|
-
|
|
844
|
-
if (!primaryKeyring) {
|
|
845
|
-
throw new Error('No HD keyring found.');
|
|
846
|
-
}
|
|
847
|
-
assertHasUint8ArrayMnemonic(primaryKeyring);
|
|
848
|
-
const seedWords = primaryKeyring.mnemonic;
|
|
849
|
-
const accounts = await primaryKeyring.getAccounts();
|
|
850
|
-
/* istanbul ignore if */
|
|
851
|
-
if (accounts.length === 0) {
|
|
852
|
-
throw new Error('Cannot verify an empty keyring.');
|
|
853
|
-
}
|
|
854
|
-
// The HD Keyring Builder is a default keyring builder
|
|
855
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
856
|
-
const hdKeyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, KeyringTypes.hd);
|
|
857
|
-
const hdKeyring = hdKeyringBuilder();
|
|
858
|
-
// @ts-expect-error @metamask/eth-hd-keyring correctly handles
|
|
859
|
-
// Uint8Array seed phrases in the `deserialize` method.
|
|
860
|
-
await hdKeyring.deserialize({
|
|
861
|
-
mnemonic: seedWords,
|
|
862
|
-
numberOfAccounts: accounts.length,
|
|
863
|
-
});
|
|
864
|
-
const testAccounts = await hdKeyring.getAccounts();
|
|
865
|
-
/* istanbul ignore if */
|
|
866
|
-
if (testAccounts.length !== accounts.length) {
|
|
867
|
-
throw new Error('Seed phrase imported incorrect number of accounts.');
|
|
868
|
-
}
|
|
869
|
-
testAccounts.forEach((account, i) => {
|
|
870
|
-
/* istanbul ignore if */
|
|
871
|
-
if (account.toLowerCase() !== accounts[i].toLowerCase()) {
|
|
872
|
-
throw new Error('Seed phrase imported different accounts.');
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
return seedWords;
|
|
843
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_verifySeedPhrase).call(this));
|
|
876
844
|
}
|
|
877
845
|
async withKeyring(selector, operation, options = {
|
|
878
846
|
createIfMissing: false,
|
|
@@ -1156,6 +1124,47 @@ async function _KeyringController_createNewVaultWithKeyring(password, keyring) {
|
|
|
1156
1124
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
|
|
1157
1125
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyringWithFirstAccount).call(this, keyring.type, keyring.opts);
|
|
1158
1126
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
|
|
1127
|
+
}, _KeyringController_verifySeedPhrase =
|
|
1128
|
+
/**
|
|
1129
|
+
* Internal non-exclusive method to verify the seed phrase.
|
|
1130
|
+
*
|
|
1131
|
+
* @returns A promise resolving to the seed phrase as Uint8Array.
|
|
1132
|
+
*/
|
|
1133
|
+
async function _KeyringController_verifySeedPhrase() {
|
|
1134
|
+
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1135
|
+
const primaryKeyring = this.getKeyringsByType(KeyringTypes.hd)[0];
|
|
1136
|
+
if (!primaryKeyring) {
|
|
1137
|
+
throw new Error('No HD keyring found.');
|
|
1138
|
+
}
|
|
1139
|
+
assertHasUint8ArrayMnemonic(primaryKeyring);
|
|
1140
|
+
const seedWords = primaryKeyring.mnemonic;
|
|
1141
|
+
const accounts = await primaryKeyring.getAccounts();
|
|
1142
|
+
/* istanbul ignore if */
|
|
1143
|
+
if (accounts.length === 0) {
|
|
1144
|
+
throw new Error('Cannot verify an empty keyring.');
|
|
1145
|
+
}
|
|
1146
|
+
// The HD Keyring Builder is a default keyring builder
|
|
1147
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1148
|
+
const hdKeyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, KeyringTypes.hd);
|
|
1149
|
+
const hdKeyring = hdKeyringBuilder();
|
|
1150
|
+
// @ts-expect-error @metamask/eth-hd-keyring correctly handles
|
|
1151
|
+
// Uint8Array seed phrases in the `deserialize` method.
|
|
1152
|
+
await hdKeyring.deserialize({
|
|
1153
|
+
mnemonic: seedWords,
|
|
1154
|
+
numberOfAccounts: accounts.length,
|
|
1155
|
+
});
|
|
1156
|
+
const testAccounts = await hdKeyring.getAccounts();
|
|
1157
|
+
/* istanbul ignore if */
|
|
1158
|
+
if (testAccounts.length !== accounts.length) {
|
|
1159
|
+
throw new Error('Seed phrase imported incorrect number of accounts.');
|
|
1160
|
+
}
|
|
1161
|
+
testAccounts.forEach((account, i) => {
|
|
1162
|
+
/* istanbul ignore if */
|
|
1163
|
+
if (account.toLowerCase() !== accounts[i].toLowerCase()) {
|
|
1164
|
+
throw new Error('Seed phrase imported different accounts.');
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
return seedWords;
|
|
1159
1168
|
}, _KeyringController_getUpdatedKeyrings =
|
|
1160
1169
|
/**
|
|
1161
1170
|
* Get the updated array of each keyring's type and
|