feat(keyring-controller): allow exportSeedPhrase with encryption key credentials#8996
Open
tanguyenvn wants to merge 3 commits into
Open
feat(keyring-controller): allow exportSeedPhrase with encryption key credentials#8996tanguyenvn wants to merge 3 commits into
tanguyenvn wants to merge 3 commits into
Conversation
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 free
to 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
What is the current state of things and why does it need to change?
KeyringController.exportSeedPhrasecurrently accepts only a wallet password string and validates it viaverifyPassword. That works for password-based SRP reveal, but passkey step-up flows need a different credential: the passkey-derived vault encryption key. The extension’srequestRevealSeedWordsWithPasskeyflow retrieves that key fromPasskeyControllerand must prove it can decrypt the vault before returning the mnemonic.Without encryption-key support in
exportSeedPhrase, passkey-based SRP reveal cannot cryptographically bind the passkey to the current vault.What is the solution your changes offer and how does it work?
exportSeedPhrasecredential object — The first argument now accepts:stringpassword (unchanged, backward compatible),{ password: string }, or{ encryptionKey: string }.When
{ encryptionKey }is provided, the method validates the key via the newverifyEncryptionKeyhelper before exporting the mnemonic.verifyEncryptionKey— New method that imports the serialized vault encryption key and attempts to decrypt the vault withdecryptWithKey. Throws if the vault is missing or decryption fails (mirroringverifyPasswordbehavior).Tests — Added coverage for password credential objects, encryption-key success paths (with and without
keyringId), and failure paths for invalid encryption keys and missing vault.Are there any changes whose purpose might not be obvious to those unfamiliar with the domain?
exportSeedPhrase; credentials are step-up re-authentication, not vault unlock.PasskeyController.retrieveVaultKeyWithPasskey;exportSeedPhrase({ encryptionKey })adds a second check that the retrieved key actually decrypts this vault.verifyEncryptionKeyis not exposed through theKeyringControllermessenger action list; it is used internally byexportSeedPhrase(same pattern as howverifyPasswordis exposed but used as a building block).If your primary goal was to update one package but you found you had to update another one along the way, why did you do so?
N/A — changes are scoped to
@metamask/keyring-controlleronly. Consumer adoption is tracked separately in the extension PR.If you had to upgrade a dependency, why did you do so?
N/A — no dependency changes.
References
requestRevealSeedWordsWithPasskey, which callskeyringController.exportSeedPhrase({ encryptionKey: vaultKey }, keyringId)Checklist
Note
High Risk
Changes how seed phrases are gated by adding encryption-key re-auth on a security-critical export path; scope is small but mistakes could weaken step-up guarantees for passkey flows.
Overview
exportSeedPhrasenow accepts step-up credentials as a bare password string (unchanged),{ password }, or{ encryptionKey }. For encryption-key credentials it validates the key before returning the HD mnemonic; the vault must already be unlocked.A new
verifyEncryptionKeyhelper imports the serialized key and attemptsdecryptWithKeyon the vault (mirroringverifyPasswordfor missing vault and bad keys). It is used internally byexportSeedPhraseand is not added to the messenger action list.Docs, messenger action JSDoc, changelog, and tests cover password objects, encryption-key success/failure paths, and optional
keyringId.Reviewed by Cursor Bugbot for commit 986e59e. Bugbot is set up for automated code reviews on this repo. Configure here.