derivekey: support xpubs in addition to xprvs#179
Merged
guggero merged 3 commits intolightninglabs:masterfrom Jan 12, 2025
Merged
derivekey: support xpubs in addition to xprvs#179guggero merged 3 commits intolightninglabs:masterfrom
guggero merged 3 commits intolightninglabs:masterfrom
Conversation
This test checks that "chantools derivekey --rootkey xpriv..." works.
starius
added a commit
to starius/taproot-assets
that referenced
this pull request
Jan 9, 2025
Added more derivation paths and corresponding public keys, check in the test that the values returned by the method match to expected values. Also added tpub (testnet xpub). To run "chantools derivekey" with xpubs, use PR lightninglabs/chantools#179
ffranr
reviewed
Jan 10, 2025
cmd/chantools/derivekey.go
Outdated
Comment on lines
+90
to
+98
| if neuter { | ||
| child, pubKey, err = lnd.DerivePubKey( | ||
| extendedKey, path, | ||
| ) | ||
| } else { | ||
| child, pubKey, wif, err = lnd.DeriveKey( | ||
| extendedKey, path, chainParams, | ||
| ) | ||
| } |
There was a problem hiding this comment.
I think pubKey is the same in both cases. Which means we can just keep the lnd.DeriveKey call, remove the lnd.DerivePubKey calling clause, and then later ignore wif if neuter == true.
Contributor
Author
There was a problem hiding this comment.
DeriveKey fails if an xpub is passed to it (in derivedKey.ECPrivKey call):
Error: could not derive keys: could not derive private key: unable to create private keys from a public extended key
ffranr
pushed a commit
to lightninglabs/taproot-assets
that referenced
this pull request
Jan 10, 2025
Added more derivation paths and corresponding public keys, check in the test that the values returned by the method match to expected values. Also added tpub (testnet xpub). To run "chantools derivekey" with xpubs, use PR lightninglabs/chantools#179
ffranr
pushed a commit
to lightninglabs/taproot-assets
that referenced
this pull request
Jan 10, 2025
Added more derivation paths and corresponding public keys, check in the test that the values returned by the method match to expected values. Also added tpub (testnet xpub). To run "chantools derivekey" with xpubs, use PR lightninglabs/chantools#179
guggero
reviewed
Jan 12, 2025
Collaborator
guggero
left a comment
There was a problem hiding this comment.
Thanks for the feature, definitely makes sense.
I think this can be simplified quite a bit, see inline comment.
If the extendedKey is an xpub, then private key is not generated and the returned WIF will be nil. This enables passing an xpub to "chantools derivekey --rootkey". Added a test for this new feature.
Previously, if xpub was passed, the tool crashed without --neuter option. Now it is optional if the input is an xpub.
ffranr
pushed a commit
to lightninglabs/taproot-assets
that referenced
this pull request
Jan 14, 2025
Added more derivation paths and corresponding public keys, check in the test that the values returned by the method match to expected values. Also added tpub (testnet xpub). To run "chantools derivekey" with xpubs, use PR lightninglabs/chantools#179
ffranr
pushed a commit
to lightninglabs/taproot-assets
that referenced
this pull request
Jan 16, 2025
Added more derivation paths and corresponding public keys, check in the test that the values returned by the method match to expected values. Also added tpub (testnet xpub). To run "chantools derivekey" with xpubs, use PR lightninglabs/chantools#179
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Now it is possible to derive a public key from xpub if
--neuteris passed:Example:
Also added tests
TestDeriveKeyXprvandTestDeriveKeyXpub.