@metamask-previews/keyring-controller 21.0.4-preview-28cd3de3 → 21.0.4-preview-f603e07
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 +10 -1
- 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 +11 -2
- 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
|
+
- Don't emit `: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]
|
|
@@ -49,6 +49,7 @@ 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
51
|
// When generating a ULID within the same millisecond, monotonicFactory provides some guarantees regarding sort order.
|
|
52
|
+
const lodash_1 = require("lodash");
|
|
52
53
|
const ulid_1 = require("ulid");
|
|
53
54
|
const constants_1 = require("./constants.cjs");
|
|
54
55
|
const name = 'KeyringController';
|
|
@@ -893,8 +894,9 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
893
894
|
createIfMissing: false,
|
|
894
895
|
}) {
|
|
895
896
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
|
|
896
|
-
return __classPrivateFieldGet(this, _KeyringController_instances, "m",
|
|
897
|
+
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
|
|
897
898
|
let keyring;
|
|
899
|
+
let forceUpdate = false;
|
|
898
900
|
if ('address' in selector) {
|
|
899
901
|
keyring = (await this.getKeyringForAccount(selector.address));
|
|
900
902
|
}
|
|
@@ -902,6 +904,8 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
902
904
|
keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
|
|
903
905
|
if (!keyring && options.createIfMissing) {
|
|
904
906
|
keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
|
|
907
|
+
// This is a new keyring, so we force the vault update in that case.
|
|
908
|
+
forceUpdate = true;
|
|
905
909
|
}
|
|
906
910
|
}
|
|
907
911
|
else if ('id' in selector) {
|
|
@@ -910,6 +914,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
910
914
|
if (!keyring) {
|
|
911
915
|
throw new Error(constants_1.KeyringControllerError.KeyringNotFound);
|
|
912
916
|
}
|
|
917
|
+
const oldKeyringState = await keyring.serialize();
|
|
913
918
|
const result = await operation({
|
|
914
919
|
keyring,
|
|
915
920
|
metadata: __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, keyring),
|
|
@@ -921,6 +926,10 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
921
926
|
// as a way to get a reference to a keyring instance.
|
|
922
927
|
throw new Error(constants_1.KeyringControllerError.UnsafeDirectKeyringAccess);
|
|
923
928
|
}
|
|
929
|
+
if (forceUpdate || !(0, lodash_1.isEqual)(oldKeyringState, await keyring.serialize())) {
|
|
930
|
+
// Keyring has been updated, we need to update the vault.
|
|
931
|
+
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
932
|
+
}
|
|
924
933
|
return result;
|
|
925
934
|
});
|
|
926
935
|
}
|