@metamask-previews/keyring-controller 21.0.4-preview-5ea27f10 → 21.0.4-preview-b84ab30f
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 +1 -0
- package/dist/KeyringController.cjs +27 -6
- 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 +28 -6
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +2 -1
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
|
### Changed
|
|
11
11
|
|
|
12
|
+
- Prevent emitting `:stateChange` from `withKeyring` unnecessarily ([#5732](https://github.com/MetaMask/core/pull/5732))
|
|
12
13
|
- Bump `@metamask/base-controller` from ^8.0.0 to ^8.0.1 ([#5722](https://github.com/MetaMask/core/pull/5722))
|
|
13
14
|
|
|
14
15
|
## [21.0.4]
|
|
@@ -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_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _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_assertNoDuplicateAccounts, _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_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _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_getSessionState, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_createKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_assertNoDuplicateAccounts, _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");
|
|
@@ -48,6 +48,7 @@ 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 lodash_1 = require("lodash");
|
|
51
52
|
// When generating a ULID within the same millisecond, monotonicFactory provides some guarantees regarding sort order.
|
|
52
53
|
const ulid_1 = require("ulid");
|
|
53
54
|
const constants_1 = require("./constants.cjs");
|
|
@@ -553,8 +554,11 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
553
554
|
* operation completes.
|
|
554
555
|
*/
|
|
555
556
|
async persistAllKeyrings() {
|
|
556
|
-
__classPrivateFieldGet(this, _KeyringController_instances, "m",
|
|
557
|
-
|
|
557
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
|
|
558
|
+
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
559
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
560
|
+
return true;
|
|
561
|
+
});
|
|
558
562
|
}
|
|
559
563
|
/**
|
|
560
564
|
* Imports an account with the specified import strategy.
|
|
@@ -1284,6 +1288,19 @@ async function _KeyringController_getSerializedKeyrings({ includeUnsupported } =
|
|
|
1284
1288
|
serializedKeyrings.push(...__classPrivateFieldGet(this, _KeyringController_unsupportedKeyrings, "f"));
|
|
1285
1289
|
}
|
|
1286
1290
|
return serializedKeyrings;
|
|
1291
|
+
}, _KeyringController_getSessionState =
|
|
1292
|
+
/**
|
|
1293
|
+
* Get a snapshot of session data held by class variables.
|
|
1294
|
+
*
|
|
1295
|
+
* @returns An object with serialized keyrings, keyrings metadata,
|
|
1296
|
+
* and the user password.
|
|
1297
|
+
*/
|
|
1298
|
+
async function _KeyringController_getSessionState() {
|
|
1299
|
+
return {
|
|
1300
|
+
keyrings: await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this),
|
|
1301
|
+
keyringsMetadata: __classPrivateFieldGet(this, _KeyringController_keyringsMetadata, "f").slice(),
|
|
1302
|
+
password: __classPrivateFieldGet(this, _KeyringController_password, "f"),
|
|
1303
|
+
};
|
|
1287
1304
|
}, _KeyringController_restoreSerializedKeyrings =
|
|
1288
1305
|
/**
|
|
1289
1306
|
* Restore a serialized keyrings array.
|
|
@@ -1644,7 +1661,7 @@ async function _KeyringController_assertNoDuplicateAccounts() {
|
|
|
1644
1661
|
}, _KeyringController_persistOrRollback =
|
|
1645
1662
|
/**
|
|
1646
1663
|
* Execute the given function after acquiring the controller lock
|
|
1647
|
-
* and save the
|
|
1664
|
+
* and save the vault to state after it (only if needed), or rollback to their
|
|
1648
1665
|
* previous state in case of error.
|
|
1649
1666
|
*
|
|
1650
1667
|
* @param callback - The function to execute.
|
|
@@ -1652,9 +1669,13 @@ async function _KeyringController_assertNoDuplicateAccounts() {
|
|
|
1652
1669
|
*/
|
|
1653
1670
|
async function _KeyringController_persistOrRollback(callback) {
|
|
1654
1671
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async ({ releaseLock }) => {
|
|
1672
|
+
const oldState = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSessionState).call(this);
|
|
1655
1673
|
const callbackResult = await callback({ releaseLock });
|
|
1656
|
-
|
|
1657
|
-
|
|
1674
|
+
const newState = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSessionState).call(this);
|
|
1675
|
+
// State is committed only if the operation is successful and need to trigger a vault update.
|
|
1676
|
+
if (!(0, lodash_1.isEqual)(oldState, newState)) {
|
|
1677
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
1678
|
+
}
|
|
1658
1679
|
return callbackResult;
|
|
1659
1680
|
});
|
|
1660
1681
|
}, _KeyringController_withRollback =
|