Uh oh!
There was an error while loading. Please reload this page.
feat(account-tree-controller): add export support - #9863
Merged
Conversation
4 tasks
ccharly
commented
Aug 13, 2026
ContributorAuthor
Adding the Main PR changelog got updated here: |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ 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 9e3d744. 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.
ccharly
enabled auto-merge
August 13, 2026 16:49
gantunesr
approved these changes
Aug 13, 2026
Uh oh!
There was an error while loading. Please reload this page.
pullBot
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 freeto 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
Touches mnemonic and private-key export via keyring APIs; mishandling could leak secrets or produce bad import payloads, though behavior is gated on an unlocked vault and covered by tests.
Overview
Adds
exportStateinaccount-tree-controllerto build anAccountTreeSnapshotfrom live account-tree state for the import/export feature.Export maps HD (entropy) wallets to mnemonic payload entries (stable wallet IDs from
HdKeyring.toEntropySourceId, groups sorted bygroupIndexwith a contiguous-index guard) and simple-keyring imported wallets into a singleprivate-keypayload, merging multiple local simple wallets into one entry. Snap and hardware wallets are omitted in this v1 path. OptionalincludeSecretspulls mnemonics viaKeyringController:withKeyringV2Unsafeand private keys viawithKeyringV2/exportAccount; any export fails if the vault is locked, including metadata-only exports.Messenger types now allow the keyring
withKeyringV2actions;@metamask/eth-hd-keyringis added as a dev dependency for tests. A largeexport.test.tssuite covers locking, secrets, ID mapping, edge cases, and wallet-type filtering.Reviewed by Cursor Bugbot for commit 479c6d8. Bugbot is set up for automated code reviews on this repo. Configure here.