Skip to content

refactor(key): share derivation between generate and restore - #383

Open
chukwudiikeh wants to merge 1 commit into
bitcoindevkit:masterfrom
chukwudiikeh:refactor/key-shared-derivation
Open

chukwudiikeh wants to merge 1 commit into
bitcoindevkit:masterfrom
chukwudiikeh:refactor/key-shared-derivation

Conversation

@chukwudiikeh

Copy link
Copy Markdown
Contributor

Fixes #382

key generate and key restore repeated 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 manual fold in key generate with the Display impl of Mnemonic, as key restore already did. Display joins 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 existing key tests cover both paths and pass unchanged.

@chukwudiikeh

Copy link
Copy Markdown
Contributor Author

@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.

@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.

This overlaps with #384 . If #384 gets merged first this change is then redundant. It is not an exact duplicate but It's worth deciding which lands first and rebasing the other on top.

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
@chukwudiikeh
chukwudiikeh force-pushed the refactor/key-shared-derivation branch from 86cf70b to a302315 Compare November 12, 2026 11:09
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.96%. Comparing base (5558555) to head (a302315).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/handlers/key.rs 90.00% 2 Missing ⚠️
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     
Flag Coverage Δ
rust 59.96% <90.00%> (-0.05%) ⬇️

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.

@chukwudiikeh

Copy link
Copy Markdown
Contributor Author

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.

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 command: extract the shared key derivation into one function

2 participants