Skip to content

feat(account-tree-controller): add import support - #9864

Merged
ccharly merged 15 commits into
mainfrom
cc/feat/account-tree-import
Aug 14, 2026
Merged

feat(account-tree-controller): add import support#9864
ccharly merged 15 commits into
mainfrom
cc/feat/account-tree-import

Conversation

@ccharly

@ccharly ccharly 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
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.

Reviewed by Cursor Bugbot for commit 8344c9c. Bugbot is set up for automated code reviews on this repo. Configure here.

@ccharly

ccharly commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

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 force-pushed the cc/feat/account-tree-import branch from c408031 to 439c7af Compare August 13, 2026 11:06
@ccharly
ccharly changed the base branch from main to cc/feat/account-tree-export August 13, 2026 11:06
@ccharly
ccharly marked this pull request as ready for review August 13, 2026 11:06
@ccharly
ccharly requested a review from a team as a code owner August 13, 2026 11:06
Comment thread packages/account-tree-controller/src/state/import.ts Outdated
Comment thread packages/account-tree-controller/src/state/import.ts
Base automatically changed from cc/feat/account-tree-export to main August 13, 2026 17:02
@ccharly
ccharly requested a review from a team as a code owner August 13, 2026 17:02

@gantunesr gantunesr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No major comments on my end. Will approve when the Bugbot comments and conflicts are resolved

@cursor cursor Bot 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 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

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 83f3c0d. Configure here.

Comment thread packages/account-tree-controller/src/state/import.ts
@ccharly
ccharly enabled auto-merge August 14, 2026 11:21
@ccharly
ccharly added this pull request to the merge queue Aug 14, 2026
Merged via the queue into main with commit bfa741b Aug 14, 2026
144 checks passed
@ccharly
ccharly deleted the cc/feat/account-tree-import branch August 14, 2026 11:55
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants