feat(snap-account-service): add SnapAccountService#8414
feat(snap-account-service): add SnapAccountService#8414
SnapAccountService#8414Conversation
SnapAccountService
…er multiple keyrings
| @@ -0,0 +1,15 @@ | |||
| # `@metamask/snap-account-service` | |||
|
|
|||
| Service for Account Management Snaps | |||
There was a problem hiding this comment.
Can we have little bit more explanation here? For example, what is the main purpose of this service, what we should keep or implement here. So we build up some integrity of this package.
| * Initializes the snap account service. | ||
| */ | ||
| async init(): Promise<void> { | ||
| // TODO: Add initialization logic here. |
There was a problem hiding this comment.
When is this supposed to be implemented? Looks redundant at this moment.
f570e75 to
2963d98
Compare
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 2963d98. Configure here.
| keyring: SelectedKeyring; | ||
| metadata: KeyringMetadata; | ||
| }) => Promise<CallbackResult>, | ||
| operation: ({ keyring, metadata }: KeyringEntry) => Promise<CallbackResult>, |
There was a problem hiding this comment.
Overloads lose generic narrowing and expose phantom property
Medium Severity
The two public withKeyring overloads were refactored from { keyring: SelectedKeyring; metadata: KeyringMetadata } to KeyringEntry. This introduces two problems: (1) the callback's keyring is now typed as EthKeyring instead of SelectedKeyring, silently dropping the generic type narrowing that the filter type guard in KeyringSelector was designed to propagate; and (2) the callback type now includes keyringV2?: KeyringV2, but the implementation only passes { keyring, metadata }, so keyringV2 is always undefined at runtime — a misleading type that can lead to dead code branches.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 2963d98. Configure here.


Explanation
A new service where we will move the common logic of the current monolith
SnapKeyring.The idea is to be able to split this keyring into multiple ones and move the
KeyringEvents logic in this service.High-level architecture is the following:
For now, it's just an empty service, but we will move forward with more follow-up change as we are rewriting the existing
SnapKeyringto use the newKeyringV2.References
N/A
Checklist
Note
Medium Risk
Adds a new atomic multi-keyring transaction API in
KeyringControllerthat can create/remove keyrings and persists or rolls back vault updates, which is a sensitive area for account storage consistency. The new@metamask/snap-account-servicepackage is mostly scaffolding and low risk on its own.Overview
Introduces a new workspace package,
@metamask/snap-account-service, with initial service scaffolding (SnapAccountService) and basic test/config/docs, and wires it into the monorepo (tsconfigs, README, yarn workspace, CODEOWNERS/teams).Extends
@metamask/keyring-controllerwith a newwithControllermessenger action/method to run atomic, mutex-protected operations across all keyrings via aRestrictedControllerthat exposes a live read-only view plus stagedaddNewKeyring/removeKeyring; on success it commits + persists, and on error it rolls back and cleans up created/removed keyrings. Adds extensive tests for locking behavior, commit/rollback, immediate visibility, and unsafe direct keyring-return protection.Reviewed by Cursor Bugbot for commit 2963d98. Bugbot is set up for automated code reviews on this repo. Configure here.