Skip to content

fix(bip39): accept any whitespace between mnemonic words - #164

Merged
prestwich merged 3 commits into
summa-tx:mainfrom
chukwudiikeh:fix/bip39-mnemonic-whitespace
Nov 9, 2026
Merged

prestwich merged 3 commits into
summa-tx:mainfrom
chukwudiikeh:fix/bip39-mnemonic-whitespace

Conversation

@chukwudiikeh

@chukwudiikeh chukwudiikeh commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

Mnemonic::new_from_phrase split the NFKD-normalized phrase with split(' '), so a valid phrase with a trailing newline, leading space, repeated spaces or tabs was rejected with a misleading InvalidWord / InvalidWordCount error. It now uses split_whitespace().

The derived seed is unchanged: to_seed hashes the canonical to_phrase() output, not the caller's input. Ideographic spaces in Japanese phrases still work.

Also closes the missing parenthesis in the InvalidWordCount error message.

Closes #163

New tests are in crates/bip39/ai-tests/mnemonic.rs. Three of them fail on main and pass with this change.

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.
@chukwudiikeh

Copy link
Copy Markdown
Author

@prestwich please can you take a look

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bip39: Mnemonic::new_from_phrase rejects phrases with extra or non-space whitespace

2 participants