Uh oh!
There was an error while loading. Please reload this page.
feat(account-tree-controller)!: add {import,export}State actions - #9663
Conversation
ccharly
commented
Jul 27, 2026
@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. |
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 7cd414f. Configure here.
Uh oh!
There was an error while loading. Please reload this page.
ccharly
commented
Aug 14, 2026
@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. |
ccharly
commented
Aug 14, 2026
Re-tested with preview builds, it works fine. Merging now! |
Uh oh!
There was an error while loading. Please reload this page.
## Explanation Add the export functions for the import/export feature of the account-tree. ## References - MetaMask#9663 ## 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** > Import decodes mnemonics and private keys and drives keyring/multichain wallet creation; mistakes could corrupt vault state or mishandle secrets. > > **Overview** > Adds **`importState`** to apply a deserialized `AccountTreeSnapshot` to 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 `MultichainAccountService` when a mnemonic is present, batches missing account groups with `createMultichainAccountGroups`, 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:withController` pass (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 gain `WithController` and `createMultichainAccountWallet`; the package build excludes test-only paths. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8344c9c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->

Explanation
New
{export,import}Stateactions.This is the implementation for this ADR:
References
Checklist
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:exportStateandAccountTreeController:importStateso clients can snapshot and restore the account tree via a version-1 wire format (AccountTreeSnapshot, payload types, andIdMapare re-exported from the package).exportStatebuilds a snapshot of wallets/groups (names, pinned, hidden, etc.); withincludeSecrets: trueand an unlocked vault it can include mnemonics and private keys.exportStaterejects when the vault is locked, including metadata-only exports.importStateaccepts only validatedAccountTreeSnapshotinstances (untrusted data must usedeserializefirst); it can create new HD wallets viaMultichainAccountServiceand private-key accounts viaKeyringController, 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).Reviewed by Cursor Bugbot for commit 6078457. Bugbot is set up for automated code reviews on this repo. Configure here.