fix(passphrase): clear device session on passphrase toggle so addresses re-derive#234
Merged
Merged
Conversation
…-derives Enabling/disabling BIP-39 passphrase protection from Device Settings left every wallet address — including 'view on device' — showing the previous (standard) wallet until a physical reconnect. Root cause is in firmware: storage_setPassphraseProtected() only flips the passphrase_protection flag and does NOT invalidate session.seedCached. The seed derived earlier in the session (empty passphrase) stays cached, so storage_getRootNode() keeps returning it even after the user enters a new passphrase. A USB unplug power-cycles the device and clears the cache, which is why reconnecting 'fixed' it. Fix without requiring a reconnect: engine.applySettings() now sends ClearSession after toggling usePassphrase, dropping the cached seed + passphrase + PIN so the device re-prompts and re-derives from the correct seed. The device routes back through needs_pin -> needs_passphrase, which also resets the in-memory account managers and remounts the dashboard, so stale addresses/balances in the UI clear too. Skipped on the emulator. DeviceSettingsDrawer: both enable and disable now re-auth, so neither path calls getFeatures inline (would race promptPin's getPublicKeys); the drawer re-fetches features when it next opens.
This was referenced Jun 9, 2026
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.
Problem
Users reported that after enabling a BIP-39 passphrase from Device Settings and entering it, the wallet kept showing the standard (no-passphrase) wallet's addresses — the entire portfolio looked stale/old. Critically, pressing "View on device" showed the wrong address on the device screen too, proving the device itself was deriving from the wrong seed (not a UI cache issue). Only physically reconnecting the KeepKey fixed it.
Root cause (firmware seed cache)
In
keepkey-firmwarestorage.c:GetPublicKey/GetAddress, incl. "view on device") goes throughstorage_getRootNode()→storage_getSeed(), which caches the derived seed insession.seed(seedCached = true). During a standard session this caches the empty-passphrase seed.ApplySettings(use_passphrase=true)callsstorage_setPassphraseProtected(), which only flips thepassphrase_protectionflag — it does not clearsession.seedCached.passphrase_protect()fires and caches the new passphrase, but the next checkif (!session.seedCached)is false, so the device reuses the stale empty-passphrase seed and never re-derives.A USB unplug power-cycles the device, clearing
seedCached— which is why reconnecting "fixed" it.Fix
engine.applySettings()now sendsClearSessionafter togglingusePassphrase.ClearSessionruns the firmware'ssession_clear(true), which zeroesseedCached,passphraseCached, and the seed buffer — a power-cycle equivalent over USB, no physical reconnect or app restart required.The device then routes back through
needs_pin → needs_passphrase, which:needs_passphrasehandling),DeviceSettingsDrawer: since both enable and disable now clear the session and re-auth, neither path callsgetFeaturesinline anymore (it would racepromptPin()'sgetPublicKeys()on the transport lock and hang). The drawer re-fetches features the next time it opens.Emulator is skipped (a
ClearSessionright afterApplySettingscan leave a staleButtonAckin the ring buffer; emulators reconnect for clean state).Test plan
On a real KeepKey with a PIN set:
Notes
setPassphraseProtected) is the true bug; this is the host-side fix that works on already-shipped firmware. A firmware-sidesession_clearinstorage_setPassphraseProtected()would be a good follow-up.