Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key sub-command to 'derive' xpub #17

Merged
merged 3 commits into from
Feb 25, 2021

Conversation

notmandatory
Copy link
Member

Description

This PR updates dependencies bdk to 0.4.0 and bdk-macros to 0.3.0 and adds a new key derive subcommand. The key derive sub-command derives an xpub from a given master xprv and derivation path.

The purpose of the derive command is to make it easier to create xpubs for use in testing multisig descriptors. For example an xpub can be derived and stored in an environment variable like this:

echo \"$ALICE_XPRV\"
"tprv8ZgxMBicQKsPfQjJy8ge2cvBfDjLxJSkvNLVQiw7BQ5gTjKadG2rrcQB5zjcdaaUTz5EDNJaS77q4DzjqjogQBfMsaXFFNP3UqoBnwt2kyT"
export ALICE_XPUB=$(bdk-cli key derive --xprv $ALICE_XPRV --path "m/84'/1'/0'/0" | jq -r ".xpub" | sed 's/^\[.*\]//g')
echo \"$ALICE_XPUB\"
"tpubDDrcq8JNTLVwaGnXp7KqZZxFJoic49ikEotWnpm6hpMY2hL2F1hpgbBBkEdsFJHU1iAx9DzMUKYr5mrphBMoXxhsBPhnVdmaoSCaeh6QWgj/0/*"

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

@thunderbiscuit
Copy link
Member

thunderbiscuit commented Feb 21, 2021

A few questions on this. Does the derive subcommand always create an xpub at the last node in the provided --path?

If that is the case (say you give the path to be --path "m/84h/1h/0h/", would it then return an xpub that then needs to be extended (to add the account 0 and the *? In this case it ends up being 2 steps no matter what no?

I'm looking at the test and I'm not sure of how it knows which tpub to derive. Is the tpub the one associated with the account 0 or the one associated with the receive group of addresses (also 0 but unhardened)?

@notmandatory
Copy link
Member Author

notmandatory commented Feb 21, 2021

Yes, derive right now only creates an extended pub key and it always creates to the last hardened part of the path.. so if you use --path "m/84'/1'/0'/123" you'll get an tpub..../123/* , but if you use --path "m/84'/1'/0'" then the result is tpub..../*. So it's just deriving the minimum that's needed, since hardened parts of the path can only be derived from the extended private key.

@thunderbiscuit
Copy link
Member

Ok I see! xpub happens at the last hardened node of the path, plus whatever extra derivation you want added on top. Thanks!

@thunderbiscuit
Copy link
Member

I'm wondering if removing the default BIP32 root node xpub returned by the key generate subcommand should be part of this PR as well. The two feel related since this derive is a more flexible and better option for xpubs, and keeping the default one there in the generate subcommand only leads to more confusion IMO.

@notmandatory
Copy link
Member Author

oh ya I should have mention it but I also removed the root xpub from the output of the generate and restore commands. :-)

@notmandatory notmandatory changed the title Add derive Add 'derive' key sub-command Feb 22, 2021
@notmandatory notmandatory changed the title Add 'derive' key sub-command Add key sub-command to 'derive' xpub Feb 22, 2021
@notmandatory notmandatory merged commit b5b2682 into bitcoindevkit:master Feb 25, 2021
@notmandatory notmandatory deleted the add_derive branch February 25, 2021 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants