Repository navigation
refactor(key): share derivation between generate and restore - #383
chukwudiikeh wants to merge 1 commit into
Conversation
|
@vadim-anfv @tvpeter this is the follow-up from issue #373, ready for review whenever you have time. No behaviour change the existing key tests cover both paths. |
3ecf3b8 to
c7ed372
Compare
c7ed372 to
86cf70b
Compare
GenerateKeyCommand and RestoreKeyCommand repeated the same steps to derive the master key from a mnemonic, and the duplication is how bitcoindevkit#372 happened. Move them into key_from_mnemonic, called by both, and use the Display impl of Mnemonic instead of the manual fold, which gives the same output. Fixes bitcoindevkit#382
86cf70b to
a302315
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #383 +/- ##
==========================================
- Coverage 60.00% 59.96% -0.05%
==========================================
Files 25 25
Lines 4736 4726 -10
==========================================
- Hits 2842 2834 -8
+ Misses 1894 1892 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks @emma31-dev . I stacked it on purpose: #384 is built on top of this PR #382 first, then the #381 rename, so this one should land first. I've rebased #384 onto the current commit here so it only adds the rename on top. |
Musab1258
left a comment
There was a problem hiding this comment.
tACK
I fetched the PR and ran just pre-push. All tests pass across the three feature configurations (including test_cli_key_restore_with_password), and clippy -D warnings (no-default-features and all-features) and fmt --check are clean.
I reviewed the diff for both commands. The only change that could affect output is key generate building the mnemonic via to_string() instead of fold + trim.
To check that, I wrote a throwaway test that generated 1000 English mnemonics (500 × 12-word, 500 × 24-word) via Mnemonic::generate and asserted the old fold expression equals to_string(). All matched. This backs the 40-mnemonic comparison in the PR description with a larger sample.
I also replaced password with None in key_from_mnemonic, which made test_cli_key_restore_with_password fail at the “restore without password must differ” assertion (tests/integration/init.rs:170). So the existing test guards the shared function against a regression of #372.
Fixes #382
key generateandkey restorerepeated the same steps to derive the master key from a mnemonic and passphrase, differing only in where the mnemonic comes from. That duplication is how issue #372 happened: one copy dropped the passphrase.This PR moves the shared steps into
key_from_mnemonic, which both commands call, and replaces the manualfoldinkey generatewith theDisplayimpl ofMnemonic, askey restorealready did.Displayjoins the words with single spaces, the same output as the fold; I compared generate and restore output for 40 mnemonics (12 and 24 words) and all matched.No behaviour change. The existingkeytests cover both paths and pass unchanged.