[Fix] Wallet import fails or decodes the wrong key when mnemonic words are capitalized - #4
Merged
Conversation
…ases decode correctly
Author
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.
What changed
mnemonicToPrivateKeynow lowercases the entire phrase once at the decode entry point, before any validation or decoding happens. Previously, word validation lowercased a throwaway copy while the checksum derivation and word-list index lookup used the original casing, so a capitalized word (e.g. autocapitalized "Iodine" from a mobile keyboard) made the phrase either fail to decode or decode through a missed word-list lookup that produced wordlist-size indexes and garbage key bytes.Why this change was made
A user retyping their 25-word phrase on a mobile keyboard with autocapitalize could end up importing nothing or — worse — a valid-looking but wrong private key, with no clear error pointing at the casing. Normalizing case once up front makes word validation, checksum verification, and index lookup all operate on identical input, so any casing variation of a valid mnemonic decodes to the same key it did before.
Impact
Mixed-case mnemonic phrases now decode to exactly the same private key as their lowercase originals, instead of failing or silently decoding a different key. Already-lowercase phrases are unaffected (
toloweris a no-op), and rejection behavior is preserved: unknown words and tampered checksums are still rejected exactly as before.Verified with a standalone g++ harness compiled against both the pre-fix and fixed sources: pre-fix, every mixed-case variant (all-capitalized and single-capitalized word) failed to decode to the correct key; post-fix all variants decode correctly and invalid phrases are still rejected.
npm run lint,npm run check, andnpm run cpppass. This repo has no JS test suite, and a full native build requires a host RN app, so those were not run.