-
Notifications
You must be signed in to change notification settings - Fork 113
Add support for configurable BIP39 mnemonic word counts #699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for configurable BIP39 mnemonic word counts #699
Conversation
Support generating BIP39 mnemonics with configurable word counts (12, 15, 18, 21, 24). Defaults to 24 words (256-bit entropy) for backward compatibility. - Add MnemonicWordCount enum (12–24 variants) - Update generate_entropy_mnemonic to accept optional word_count - Map word counts to correct entropy sizes per BIP39 - Extend tests for all word count options and defaults - Expose enum and updated function in UDL bindings
|
I've assigned @tnull as a reviewer! |
tnull
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think it makes sense to add this option.
Note that we appreciate human-written descriptions and when AI agent co-authorship is disclosed in the commit message.
src/io/utils.rs
Outdated
| let mut entropy = [0; 32]; | ||
| pub fn generate_entropy_mnemonic(word_count: Option<MnemonicWordCount>) -> Mnemonic { | ||
| let word_count = word_count.unwrap_or(MnemonicWordCount::Words24); | ||
| let entropy_bytes = word_count.entropy_bytes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, rather than dealing with different entropy byte lengths here, can we just use Mnemonic::generate which allows us to specify the word count? Having an enum for it still makes sense (actually we might want to switch to that in the bip39 API rust-bitcoin/rust-bip39#97).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Rename MnemonicWordCount to WordCount and update references as needed - Remove need for entropy_bytes in generate_entropy_mnemonic by passing WordCount enum directly to generate() instead - Add rand feature to bip39 dependency
Summary
This PR introduces support for generating BIP39 mnemonics with configurable word counts - 12, 15, 18, 21, or 24 words.
The
word_countparameter is optional and defaults to 24 words (256-bit entropy).Motivation
Different use cases benefit from different mnemonic lengths:
Changes
WordCountenum (Words12,Words15,Words18,Words21,Words24)generate_entropy_mnemonic()to accept an optionalword_countparameterBreaking Changes
generate_entropy_mnemonic()now requires aword_countparameter.Users will need to update their code from:
To:
Testing
cargo test)Summary was co-created with AI