Skip to content

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

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

Olorunshogo wants to merge 1 commit into
bitcoindevkit:masterfrom
Olorunshogo:fix/key-generate-word-count

Conversation

@Olorunshogo

Copy link
Copy Markdown

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.

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