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.

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 c7ed372 to 86cf70b Compare November 11, 2026 15:33

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

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