Add support for configurable BIP39 mnemonic word counts#699
Conversation
|
I've assigned @tnull as a reviewer! |
tnull
left a comment
There was a problem hiding this comment.
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.
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.
tnull
left a comment
There was a problem hiding this comment.
LGTM, please squash the second commit so we can land this.
Support generating BIP39 mnemonics with configurable word counts (12, 15, 18, 21, 24). Defaults to 24 words (256-bit entropy) for backward compatibility. - Add WordCount enum (12–24 variants) - Update generate_entropy_mnemonic to accept optional word_count - Remove need for entropy_bytes in generate_entropy_mnemonic by passing WordCount enum directly to generate() instead - Add rand feature to bip39 dependency - Extend tests for all word count options and defaults - Expose enum and updated function in UDL bindings
0bf8721 to
0a860d4
Compare
|
Squashed as requested. |
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