Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#362 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli

调研方向

首先找到 issue 中描述的 KeySubCommand::Generate 和 word_count 参数解析器。检查命令如何将解析后的值映射到 bdk_wallet::keys::bip39::WordCount,然后运行相关的 CLI 测试,或尝试 15 个单词和无效值的示例。完成标准是支持全部五种长度,并通过列出有效选项的消息拒绝不支持的值。

由索引模型根据 Issue 内容生成。

描述

bug

Describe the bug

key generate accepts any integer for --word-count but only distinguishes 12 from everything else. The match arm is:

let mnemonic_type = match self.word_count {
    12 => WordCount::Words12,
    _ => WordCount::Words24,
};

So --word-count 15 produces a 24-word mnemonic, --word-count 0 produces a 24-word mnemonic, and --word-count 999 produces a 24-word mnemonic. No error, no warning, no indication that the requested value was ignored. BIP39 defines five valid lengths: 12, 15, 18, 21, 24 and bdk_wallet::keys::bip39 WordCount already support all five, so the restriction is purely in the CLI's argument handling.

To Reproduce

  1. Request a 15-word mnemonic:
    bdk-cli key generate --word-count 15
    
  2. Count the words in the output: it is 24, not 15.
  3. Confirm nonsense values are also accepted without error:
    bdk-cli key generate --word-count 0
    
    This also produces 24 words.

Expected behavior

--word-count 15 should produce a 15-word mnemonic, since the library supports it. Invalid values such as 0, 13, or 999 should be rejected at parse time with a message listing the valid options, not silently coerced. PossibleValuesParser or a custom value_parser handles both:

#[arg(
    long = "word-count",
    short = 'w',
    default_value = "WordCount::Words12",
    value_parser = word_count_parser
)]
pub word_count: WordCount,

in the word_count_parser:

let word_count = match word_count {
    "12" => WordCount::Words12,
    "15" => WordCount::Words15,
    "18" => WordCount::Words18,
    "21" => WordCount::Words21,
    "24" => WordCount::Words24,
    _ => return(Error::Generic("...")), 
};

The change is confined to KeySubCommand::Generate; no library or API changes are needed.

Build environment

· BDK-CLI tag/commit: main
· OS+version: macOS 12.7.6 (Monterey)
· Rust/Cargo version: rustc --version output
· Rust/Cargo target: x86_64-apple-darwin

Additional context

The silent coercion means a user's request is never honoured unless it happens to be exactly 12, and the failure mode is invisible. The command just succeeds and returns a valid mnemonic of the wrong length. Since usize parsing already rejects negative values, the only way to reach the match arm with an unintended value is a typo or an unsupported length, and both currently produce 24 words with no diagnostic. Validating at the clap boundary fixes both the missing lengths and the silent acceptance in a single change.

主要语言
Rust
星标
143
派生
103
平均合并
2 天 9 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bitcoindevkit/bdk-cli 的其他 Issue

查看 bitcoindevkit/bdk-cli 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。