Uh oh!
There was an error while loading. Please reload this page.
feat(account-tree-controller): add import support - #9864
Conversation
ccharly
commented
Aug 13, 2026
Adding the Main PR changelog got updated here: |
c408031 to
439c7afCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
gantunesr
left a comment
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…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 -->

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.