feat(account-tree-controller): add import support - #9864
Merged
Conversation
4 tasks
Contributor
Author
|
Adding the Main PR changelog got updated here: |
ccharly
force-pushed
the
cc/feat/account-tree-import
branch
from
August 13, 2026 11:06
c408031 to
439c7af
Compare
ccharly
marked this pull request as ready for review
August 13, 2026 11:06
gantunesr
reviewed
Aug 13, 2026
gantunesr
left a comment
Member
There was a problem hiding this comment.
No major comments on my end. Will approve when the Bugbot comments and conflicts are resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ 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 83f3c0d. Configure here.
ccharly
enabled auto-merge
August 14, 2026 11:21
gantunesr
approved these changes
Aug 14, 2026
pull Bot
pushed a commit
to dmrazzy/core
that referenced
this pull request
Aug 14, 2026
…etaMask#9663) ## Explanation New `{export,import}State` actions. This is the implementation for this ADR: - MetaMask/decisions#231 ## References - ADR MetaMask/decisions#231 - Split to: - MetaMask#9826 - MetaMask#9863 - MetaMask#9864 ## 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] > **High Risk** > Touches secret export/import and keyring/multichain wallet creation; incorrect handling could leak or corrupt credentials or account metadata. > > **Overview** > **Adds `AccountTreeController:exportState` and `AccountTreeController:importState`** so clients can snapshot and restore the account tree via a **version-1 wire format** (`AccountTreeSnapshot`, payload types, and `IdMap` are re-exported from the package). > > `exportState` builds a snapshot of wallets/groups (names, pinned, hidden, etc.); with **`includeSecrets: true`** and an unlocked vault it can include mnemonics and private keys. **`exportState` rejects when the vault is locked**, including metadata-only exports. `importState` accepts only validated `AccountTreeSnapshot` instances (untrusted data must use `deserialize` first); it can create new HD wallets via `MultichainAccountService` and private-key accounts via `KeyringController`, then apply metadata to existing and new entries. > > Tests add messenger action coverage, a controller-level metadata round-trip, dedicated **export→serialize→deserialize→import** integration tests for mnemonic/private-key secrets, and test harness updates (`KeyringController:withController`, multichain create actions, shared wallet fixtures). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6078457. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Explanation
Add the export functions for the import/export feature of the account-tree.
References
{import,export}Stateactions #9663Checklist
Note
High Risk
Import decodes mnemonics and private keys and drives keyring/multichain wallet creation; mistakes could corrupt vault state or mishandle secrets.
Overview
Adds
importStateto apply a deserializedAccountTreeSnapshotto local account-tree state, complementing the existing export path.For mnemonic wallets, it matches wallets by stable entropy payload ID (via keyring), creates HD wallets through
MultichainAccountServicewhen a mnemonic is present, batches missing account groups withcreateMultichainAccountGroups, and applies wallet/group metadata (name, pinned, hidden). Existing groups get metadata before group creation so partial failures still update what is already local.For private-key wallets, it imports missing EVM EOA keys in one
KeyringController:withControllerpass (create simple keyring if needed), skips non-EOA entries for forward compatibility, and applies group metadata without renaming the keyring wallet.Shared test helpers (
makeLocalMnemonicWallet, payload builders, etc.) replace inline fixtures in export tests and back a large new import test suite. Messenger types gainWithControllerandcreateMultichainAccountWallet; the package build excludes test-only paths.Reviewed by Cursor Bugbot for commit 8344c9c. Bugbot is set up for automated code reviews on this repo. Configure here.