Skip to content

Commit 2c255a6

Browse files
authored
feat: add isUnlocked action (MetaMask#8573)
## Explanation This is needed to handle keyring controller locked scenarios when account creation is mid-flight in the multichain account service. Alternative was to do `KeyringController:getState`, but I'd rather not pull in the whole state to do a boolean check. ## References N/A ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [x] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: adds a new read-only messenger action that returns the existing `state.isUnlocked` boolean, with no changes to unlock/lock behavior or vault persistence. > > **Overview** > Adds a new `KeyringController:isUnlocked` messenger action so consumers can query vault lock status without fetching full controller state or holding a controller reference. > > This updates the allowed action types/exports and exposes `isUnlocked` via `MESSENGER_EXPOSED_METHODS`, with a changelog entry documenting the new capability. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 83fffcb. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 5a3fa25 commit 2c255a6

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/keyring-controller/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Expose `KeyringController:isUnlocked` method through `KeyringController` messenger ([#8573](https://github.com/MetaMask/core/pull/8573))
13+
- Returns `true` when the vault is unlocked, `false` otherwise. Mirrors `state.isUnlocked` and the `isUnlocked()` instance method, allowing consumers to check lock status via the messenger without holding a controller reference.
1214
- Add `withController` action to run atomic operations on multiple keyrings (within a single transaction) ([#8416](https://github.com/MetaMask/core/pull/8416))
1315
- This action uses a `RestrictedController` object that exposes `addNewKeyring` and `removeKeyring` methods to add and remove keyring during the transaction (atomic) call.
1416
- Expose `KeyringController:signTransaction` method through `KeyringController` messenger ([#8408](https://github.com/MetaMask/core/pull/8408))

packages/keyring-controller/src/KeyringController-method-action-types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ export type KeyringControllerAddNewKeyringAction = {
5858
handler: KeyringController['addNewKeyring'];
5959
};
6060

61+
/**
62+
* Returns the status of the vault.
63+
*
64+
* @returns Boolean returning true if the vault is unlocked.
65+
*/
66+
export type KeyringControllerIsUnlockedAction = {
67+
type: `KeyringController:isUnlocked`;
68+
handler: KeyringController['isUnlocked'];
69+
};
70+
6171
/**
6272
* Returns the public addresses of all accounts from every keyring.
6373
*
@@ -401,6 +411,7 @@ export type KeyringControllerMethodActions =
401411
| KeyringControllerCreateNewVaultAndRestoreAction
402412
| KeyringControllerCreateNewVaultAndKeychainAction
403413
| KeyringControllerAddNewKeyringAction
414+
| KeyringControllerIsUnlockedAction
404415
| KeyringControllerGetAccountsAction
405416
| KeyringControllerGetEncryptionPublicKeyAction
406417
| KeyringControllerDecryptMessageAction

packages/keyring-controller/src/KeyringController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const MESSENGER_EXPOSED_METHODS = [
7676
'createNewVaultAndKeychain',
7777
'createNewVaultAndRestore',
7878
'removeAccount',
79+
'isUnlocked',
7980
] as const;
8081

8182
/**

packages/keyring-controller/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type {
44
KeyringControllerCreateNewVaultAndRestoreAction,
55
KeyringControllerCreateNewVaultAndKeychainAction,
66
KeyringControllerAddNewKeyringAction,
7+
KeyringControllerIsUnlockedAction,
78
KeyringControllerGetAccountsAction,
89
KeyringControllerGetEncryptionPublicKeyAction,
910
KeyringControllerDecryptMessageAction,

0 commit comments

Comments
 (0)