key generate subcommand silently coerces any word count other than 12 to 24 words
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先找到 issue 中描述的 KeySubCommand::Generate 和 word_count 参数解析器。检查命令如何将解析后的值映射到 bdk_wallet::keys::bip39::WordCount,然后运行相关的 CLI 测试,或尝试 15 个单词和无效值的示例。完成标准是支持全部五种长度,并通过列出有效选项的消息拒绝不支持的值。
由索引模型根据 Issue 内容生成。
描述
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
- Request a 15-word mnemonic:
bdk-cli key generate --word-count 15 - Count the words in the output: it is 24, not 15.
- Confirm nonsense values are also accepted without error:
This also produces 24 words.bdk-cli key generate --word-count 0
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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bitcoindevkit/bdk-cli 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
bitcoindevkit/bdk-cli#360 ·
维护者通常 1 天内回复
-
Expose remaining SignOptions fields in the wallet sign command可能已有人在做 @emma31-dev 于 2 天前认领。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 78/100
bitcoindevkit/bdk-cli#358 · 1 条评论 ·
维护者通常 1 天内回复
-
wallet sign command returns generic error for decoding failures可能已有人在做 @emma31-dev 于 2 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
bitcoindevkit/bdk-cli#357 ·
维护者通常 1 天内回复
-
Remove "wallet" field from `WalletConfigInner`可能已有人在做 @Jennycj 于 10 天前认领。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 72/100
bitcoindevkit/bdk-cli#332 · 2 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 3/5 1-2 天 新手友好度 55/100
bitcoindevkit/bdk-cli#359 · 1 条评论 ·
维护者通常 1 天内回复
查看 bitcoindevkit/bdk-cli 的全部 Issue
相似的 Issue
-
good first issue help wanted r-feature
难度 2/5 1-3 小时 新手友好度 82/100
servo/rust-smallvec#792 ·
维护者通常 1 天内回复
-
A-Unicode C-bug P-low
难度 2/5 1-3 小时 新手友好度 70/100
rust-lang/rustfmt#7210 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
area:sim good first issue kind:feature
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
bitcoindevkit/bdk#2432 ·
维护者通常 3 天内回复