Repository navigation
fix(bip39): accept any whitespace between mnemonic words - #164
Merged
prestwich merged 3 commits intoNov 9, 2026
Merged
Conversation
new_from_phrase split the normalized phrase on single spaces, so a valid phrase with a trailing newline, leading space, repeated spaces or tabs was rejected as InvalidWord or InvalidWordCount. Split with split_whitespace instead. The seed is unchanged, since to_seed hashes the canonical to_phrase output rather than the caller's input. Also close the parenthesis in the InvalidWordCount error message.
Author
|
@prestwich please can you take a look |
prestwich
approved these changes
Nov 9, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Mnemonic::new_from_phrasesplit the NFKD-normalized phrase withsplit(' '), so a valid phrase with a trailing newline, leading space, repeated spaces or tabs was rejected with a misleadingInvalidWord/InvalidWordCounterror. It now usessplit_whitespace().The derived seed is unchanged:
to_seedhashes the canonicalto_phrase()output, not the caller's input. Ideographic spaces in Japanese phrases still work.Also closes the missing parenthesis in the
InvalidWordCounterror message.Closes #163
New tests are in
crates/bip39/ai-tests/mnemonic.rs. Three of them fail onmainand pass with this change.