feat(snap-account-service): add migration logic + keyring v2 support#8732
feat(snap-account-service): add migration logic + keyring v2 support#8732ccharly wants to merge 50 commits into
Conversation
96269d0 to
43c238b
Compare
8452267 to
ce71df1
Compare
a4b5e03 to
47199fa
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
9cae8f4 to
24c3001
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d393781. Configure here.
| return { snapKeyring } as unknown as Result; | ||
| // Remove the legacy Snap keyring after migration. | ||
| log('Removing legacy Snap keyring...'); | ||
| await controller.removeKeyring(legacySnapKeyringEntry.metadata.id); |
There was a problem hiding this comment.
Legacy accounts dropped during migration
High Severity
During #migrate, legacy keyring accounts without metadata.snap are skipped when building v2 state, but the legacy keyring is always removed afterward. Any account on the legacy Snap keyring that lacks snap metadata is not moved to a v2 keyring and is effectively discarded once migration completes.
Reviewed by Cursor Bugbot for commit d393781. Configure here.
There was a problem hiding this comment.
That should really not be possible. All accounts coming out of the legacy SnapKeyring always have a metadata.snap (even though, type-wise, it's not enforced, that's true).
I guess though, if the Snap account tracker does not track the same accounts than the legacy keyring, then yes, we could lose accounts in the process.
That should never happen though...
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |


Explanation
Add migration logic to migrate from the legacy Snap keyring to the new architecture with 1 Snap keyring v2 per Snaps.
Also enhance
:ensureReadyso consumers can safely call:withKeyringV2to get the associated Snap keyring v2 instance before using it.References
N/A
Checklist
Note
High Risk
Breaking keyring APIs and one-time migration on unlock affect account creation, deletion, and Snap message routing; incorrect migration could strand or duplicate Snap accounts.
Overview
Migrates Snap account handling from a single legacy (v1) Snap keyring to one
@metamask/eth-snap-keyring/v2keyring per Snap, bumping@metamask/eth-snap-keyringto ^22.1.0.SnapAccountServiceaddsensureMigrated(runs on unlock, idempotent/concurrent-safe): groups legacy accounts by Snap ID, creates v2 keyrings viaKeyringController:addNewKeyring, then removes the legacy keyring.getLegacySnapKeyringis removed (breaking).ensureReadynow awaits migration, creates a v2 keyring for the Snap if missing, and no longer waits on a global Snap keyring.handleKeyringSnapMessageand selected-account forwarding target per-Snap v2 keyrings viawithKeyringV2/withKeyringV2Unsafe(includingGetSelectedAccountsfiltered byhasAccount).SnapPlatformWatcherdrops the KeyringController wait/timeout for the legacy Snap keyring.multichain-account-serviceSnap providers dropKeyringController:withKeyringin favor ofwithKeyringV2, use the v2 Snap keyring API (createAccount/createAccountswithout a leading snapId), anddeleteAccount(id)instead ofremoveAccount(address)during resync.Reviewed by Cursor Bugbot for commit f188e62. Bugbot is set up for automated code reviews on this repo. Configure here.