Skip to content

feat(keyring-controller): add withKeyringV2 and deprecate withKeyring#8372

Draft
mathieuartu wants to merge 3 commits intomainfrom
ma/add-withkeyringv2-keyring-controller
Draft

feat(keyring-controller): add withKeyringV2 and deprecate withKeyring#8372
mathieuartu wants to merge 3 commits intomainfrom
ma/add-withkeyringv2-keyring-controller

Conversation

@mathieuartu
Copy link
Copy Markdown
Contributor

@mathieuartu mathieuartu commented Apr 2, 2026

Explanation

References

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 communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Adds a new atomic keyring-operation API that wraps V1 keyrings into KeyringV2 adapters and introduces new builder registration, which could affect keyring mutation/persistence and error handling paths. Dependency bumps for keyring packages also change transitive behavior/types used by the controller.

Overview
Introduces KeyringController.withKeyringV2 (and messenger action KeyringController:withKeyringV2) to run mutually-exclusive, persist-or-rollback operations against a selected keyring using the KeyringV2 API, including safeguards against returning the wrapped keyring instance.

Adds a keyringV2Builders constructor option plus default V2 builders for HD and Simple keyrings (HdKeyringV2, SimpleKeyringV2), and throws a new KeyringV2NotSupported error when no builder exists. Marks withKeyring as deprecated in favor of withKeyringV2, updates tests accordingly, and bumps @metamask/eth-hd-keyring / @metamask/eth-simple-keyring to versions that provide the V2 adapters.

Written by Cursor Bugbot for commit 5b9a85a. This will update automatically on new commits. Configure here.

@mathieuartu mathieuartu self-assigned this Apr 2, 2026
@mathieuartu mathieuartu requested review from a team as code owners April 2, 2026 20:09
@mathieuartu mathieuartu changed the title feat(keyring-controller): add withKeyringV2 and deprecate withKeyring feat(keyring-controller): add withKeyringV2 and deprecate withKeyring Apr 2, 2026
@socket-security
Copy link
Copy Markdown

socket-security bot commented Apr 2, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​metamask/​eth-simple-keyring@​11.0.0 ⏵ 11.1.19910010092 +8100

View full report

@mathieuartu mathieuartu marked this pull request as draft April 2, 2026 20:20
github-merge-queue bot pushed a commit that referenced this pull request Apr 13, 2026
## Explanation

Another approach for `withKeyringV2` where we actually extend the
existing list of keyring instances to have an optional `keyringV2`
field.

This allow to keep them in memory and have the same lifecycle than v1
keyring instance (and since all v2 implementations are wrappers for now,
they are "bound" to v1 instances anyway).

Original PR:
- #8372

## References

N/A

## 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 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)
- [ ] 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]
> **Medium Risk**
> Introduces new V2 keyring selection/execution paths and caches V2
adapters alongside legacy keyrings, which could affect keyring
lifecycle, rollback/persistence behavior, and error handling. Dependency
bumps to keyring packages may also subtly change signing/account
behavior.
> 
> **Overview**
> Adds first-class `KeyringV2` support by storing an optional in-memory
V2 adapter next to each legacy keyring entry and creating/destroying
these adapters during keyring create/restore/clear flows.
> 
> Introduces `withKeyringV2` (locked, persisted/rollback) and
`withKeyringV2Unsafe` (lock-free, no rollback) APIs plus messenger
action types, including a new `KeyringSelectorV2`
(`type`/`address`/`id`/`filter`) and a `KeyringV2NotSupported` error
when no V2 builder exists for a selected keyring.
> 
> Updates tests to cover selector variants, lock/rollback semantics, and
messenger callability; bumps
`@metamask/eth-hd-keyring`/`@metamask/eth-simple-keyring` versions and
adjusts Jest coverage thresholds accordingly.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d8bc565. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Mathieu Artu <mathieu.artu@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant