FIX: dead mnemonic validation on wallet import - #145
Merged
theanmolsharma merged 3 commits intoSep 1, 2026
Merged
Conversation
notTanveer
reviewed
Aug 21, 2026
theanmolsharma
requested changes
Aug 29, 2026
wallet.getSecret() is always non-empty after setSecret() runs on the line above, so `!wallet.getSecret()` in the && condition was always false and validateMnemonic()'s result was never checked. Any garbage string passed silently and created an unrecoverable wallet.
Renders ImportWallet end to end and asserts that a garbage string is rejected with the invalid-mnemonic alert (and never reaches addAndSaveWallet), while a real BIP39 phrase still imports normally. Confirmed this test fails against the pre-fix condition and passes against the fix.
chaitika
force-pushed
the
fix/import-wallet-mnemonic-validation
branch
from
September 1, 2026 06:46
97afb4e to
c7e0011
Compare
Drop the now-false "or private key" copy from the mnemonic error strings, remove redundant setIsLoading(false) calls made unreachable by the finally block, close a second dead branch (unreachable 'network' birth-height error) with a compiler-checked message map, and tighten the regression test (diagnostics, exact-count assertion, rename to match repo convention, assert saved wallet state).
chaitika
force-pushed
the
fix/import-wallet-mnemonic-validation
branch
from
September 1, 2026 06:50
c7e0011 to
be39af8
Compare
theanmolsharma
approved these changes
Sep 1, 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.
The finding
ImportWallet.tsx:146was supposed to reject invalid seed phrases:setSecret()on line 142 runs first and always leaves the wallet's secret non-empty (worst case, a garbage input like"!!!"still normalizes to a single space). So by the time theifruns,wallet.getSecret()is never empty,!wallet.getSecret()is alwaysfalse, andanything && falseis alwaysfalse. The result:validateMnemonic()is called, but its answer is never actually acted on. The error branch is unreachable.Implications
The BIP39 checksum is the only thing that catches a mistyped or garbage recovery phrase before it's used. Downstream,
bip39.mnemonicToSeedSyncdoesn't validate anything either — it will grind any string into a seed via PBKDF2. AndaddAndSaveWallet/addWallet(StorageProvider.tsx) have no validation of their own.So the full path from broken input to "success" is unguarded end to end: type
"asdf"into Import Wallet, and the app derives a wallet from it, saves it, fires a success haptic, shows "Wallet imported successfully," and lands you on the wallet list with a 0 balance. Nothing tells you the phrase you typed wasn't valid. If this happens on a real restore (a mistyped word from a backup), the user has no way to know their actual funds weren't recovered — they're looking at a different, unrelated wallet that just happens to be empty.The fix
Delete the dead clause. The condition now does what it always should have:
Invalid phrases are now rejected with the existing
error_invalid_mnemonicalert before a wallet is ever created.Testing
tests/unit/import-wallet-mnemonic-validation.test.tsx: rendersImportWalletend to end and asserts a garbage string is rejected (alert shown,addAndSaveWalletnever called), while a real BIP39 phrase still imports and navigates normally.&& !wallet.getSecret()condition and passes with the fix.npm run lint && npm run tslint && npm run unitall pass.