Skip to content

fix(key): support all BIP39 word counts and reject invalid values in key generate - #366

Open
Olorunshogo wants to merge 2 commits into
bitcoindevkit:masterfrom
Olorunshogo:fix/key-generate-word-count
Open

Olorunshogo wants to merge 2 commits into
bitcoindevkit:masterfrom
Olorunshogo:fix/key-generate-word-count

Conversation

@Olorunshogo

Copy link
Copy Markdown
Contributor

PR description

Description

key generate --entropy only matched 12; every other value was silently coerced to a 24-word mnemonic. BIP39 and bdk_wallet support 12, 15, 18, 21 and 24 words.

--entropy now parses into a MnemonicWordCount ValueEnum limited to those five values, so invalid input is rejected at parse time and --help lists the options. The flag name, -e, WORD_COUNT env var and default of 12 are unchanged.

Fixes #362

--entropy Before After
12 / default 12 words 12 words
15 / 18 / 21 24 words 15 / 18 / 21 words
24 24 words 24 words
0 / 13 / 999 24 words error listing valid values

Notes to reviewers

  • WordCount derives no traits (no Clone), so clap can't parse into it directly. MnemonicWordCount mirrors it with a From impl, following the ScriptType pattern used by compile --type.
  • Behavior change: values other than 12 that previously produced 24 words now error. Noted in the CHANGELOG.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Bugfixes:

  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@emma31-dev

Copy link
Copy Markdown

Looks good to me. I'll test it later.

@emma31-dev emma31-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside that minor issue everything looks good. I have tested everything and its adapted well.

Comment thread tests/integration/init.rs
cli.key_cmd(&["generate", "--entropy", word_count])
.assert()
.failure()
.stderr(predicate::str::contains("possible values"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unnecessary assertion but can be overlooked

@Olorunshogo

Copy link
Copy Markdown
Contributor Author

Please take a look at this @tvpeter @vadim-anfv

@emma31-dev

Copy link
Copy Markdown

@Olorunshogo it has been 2 days . Relax as older PRs will get reviewed before this

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.14%. Comparing base (3b514f4) to head (aa72b1c).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #366      +/-   ##
==========================================
+ Coverage   59.08%   59.14%   +0.06%     
==========================================
  Files          25       25              
  Lines        4646     4651       +5     
==========================================
+ Hits         2745     2751       +6     
+ Misses       1901     1900       -1     
Flag Coverage Δ
rust 59.14% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

key generate subcommand silently coerces any word count other than 12 to 24 words

2 participants