Skip to content

feat(account-tree-controller): add export support - #9863

Merged
ccharly merged 5 commits into
mainfrom
cc/feat/account-tree-export
Aug 13, 2026
Merged

feat(account-tree-controller): add export support#9863
ccharly merged 5 commits into
mainfrom
cc/feat/account-tree-export

Conversation

@ccharly

@ccharlyccharly commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Explanation

Add the export functions for the import/export feature of the account-tree.

References

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
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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 exportState in account-tree-controller to build an AccountTreeSnapshot from 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 by groupIndex with a contiguous-index guard) and simple-keyring imported wallets into a single private-key payload, merging multiple local simple wallets into one entry. Snap and hardware wallets are omitted in this v1 path. Optional includeSecrets pulls mnemonics via KeyringController:withKeyringV2Unsafe and private keys via withKeyringV2 / exportAccount; any export fails if the vault is locked, including metadata-only exports.

Messenger types now allow the keyring withKeyringV2 actions; @metamask/eth-hd-keyring is added as a dev dependency for tests. A large export.test.ts suite 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.

@ccharly

Copy link
Copy Markdown
ContributorAuthor

Adding the no-changelog since this change cannot be used until the main (integration) PR is merged.

Main PR changelog got updated here:

@ccharly
ccharly marked this pull request as ready for review August 13, 2026 10:11
@ccharly
ccharly requested review from a team as code ownersAugust 13, 2026 10:11

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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.

Comment threadpackages/account-tree-controller/src/state/export.ts
Comment threadpackages/account-tree-controller/src/state/export.ts
@ccharly
ccharly enabled auto-merge August 13, 2026 16:49
@ccharly
ccharly added this pull request to the merge queueAug 13, 2026
Merged via the queue into main with commit 27cb9e3Aug 13, 2026
144 checks passed
@ccharly
ccharly deleted the cc/feat/account-tree-export branch August 13, 2026 17:02
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 -->
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@ccharly@gantunesr