You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Explanation
Part of `KeyringController` responsibilies is ensuring each operation is
[mutually exclusive](#4182) and
[atomic](#4192), updating keyring
instances and the vault (or rolling them back) in the same mutex lock.
However, the ability of clients to have direct access to a keyring
instance represents a loophole, as with the current implementation they
don’t have to comply with the rules enforced by the controller: we
should provide a way for clients to interact with a keyring instance
through safeguards provided by KeyringController.
The current behavior is this one:
1. Client obtains a keyring instance through `getKeyringForAccount`
2. Client interacts with the instance
3. Client calls `persistAllKeyrings`
We should, instead, have something like this:
1. Client calls a `withKeyring` method, passing a _keyring selector_ and
a callback
2. KeyringController selects the keyring instance and calls the callback
with it, after locking the controller operation mutex
3. Client interacts with the keyring instance safely, inside the
callback
4. KeyringController, after the callback execution, internally updates
the vault or rolls back changes in case of error, and then releases the
mutex lock
## References
<!--
Are there any issues that this pull request is tied to? Are there other
links that reviewers should consult to understand these changes better?
For example:
* Fixes #12345
* Related to #67890
-->
* Fixes#4198
* Related to #4192
## Changelog
<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.
(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)
Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).
If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.
Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->
### `@metamask/keyring-controller`
- **ADDED**: Added `withKeyring` method
- **DEPRECATED**: Deprecated `persistAllKeyrings` method
- Use `withKeyring` instead
## Checklist
- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
0 commit comments