-
Notifications
You must be signed in to change notification settings - Fork 35
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
derivekey: support xpubs in addition to xprvs #179
Conversation
This test checks that "chantools derivekey --rootkey xpriv..." works.
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
cmd/chantools/derivekey.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK, LGTM 🎉
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
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
Now it is possible to derive a public key from xpub if
--neuter
is passed:Example:
Also added tests
TestDeriveKeyXprv
andTestDeriveKeyXpub
.