From 7a3c9a3f0b24e9d7810b57e642704712be02fcb7 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Sun, 2 May 2021 16:45:36 +0200 Subject: [PATCH] derivekey: add new --identity flag for lnd identity_pubkey --- cmd/chantools/derivekey.go | 18 +++++++++++++++--- doc/chantools_derivekey.md | 5 ++++- lnd/hdkeychain.go | 7 +++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/cmd/chantools/derivekey.go b/cmd/chantools/derivekey.go index dcaa982..d21da17 100644 --- a/cmd/chantools/derivekey.go +++ b/cmd/chantools/derivekey.go @@ -21,8 +21,9 @@ Extended private key (xprv): %s ` type deriveKeyCommand struct { - Path string - Neuter bool + Path string + Neuter bool + Identity bool rootKey *rootKey cmd *cobra.Command @@ -36,7 +37,9 @@ func newDeriveKeyCommand() *cobra.Command { Long: `This command derives a single key with the given BIP32 derivation path from the root key and prints it to the console.`, Example: `chantools derivekey --path "m/1017'/0'/5'/0/0'" \ - --neuter`, + --neuter + +chantools derivekey --identity`, RunE: cc.Execute, } cc.cmd.Flags().StringVar( @@ -47,6 +50,10 @@ derivation path from the root key and prints it to the console.`, &cc.Neuter, "neuter", false, "don't output private key(s), "+ "only public key(s)", ) + cc.cmd.Flags().BoolVar( + &cc.Identity, "identity", false, "derive the lnd "+ + "identity_pubkey", + ) cc.rootKey = newRootKey(cc.cmd, "decrypting the backup") @@ -59,6 +66,11 @@ func (c *deriveKeyCommand) Execute(_ *cobra.Command, _ []string) error { return fmt.Errorf("error reading root key: %v", err) } + if c.Identity { + c.Path = lnd.IdentityPath(chainParams) + c.Neuter = true + } + return deriveKey(extendedKey, c.Path, c.Neuter) } diff --git a/doc/chantools_derivekey.md b/doc/chantools_derivekey.md index a7437ef..a75ea92 100644 --- a/doc/chantools_derivekey.md +++ b/doc/chantools_derivekey.md @@ -15,7 +15,9 @@ chantools derivekey [flags] ``` chantools derivekey --path "m/1017'/0'/5'/0/0'" \ - --neuter + --neuter + +chantools derivekey --identity ``` ### Options @@ -23,6 +25,7 @@ chantools derivekey --path "m/1017'/0'/5'/0/0'" \ ``` --bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag -h, --help help for derivekey + --identity derive the lnd identity_pubkey --neuter don't output private key(s), only public key(s) --path string BIP32 derivation path to derive; must start with "m/" --rootkey string BIP32 HD root key of the wallet to use for decrypting the backup; leave empty to prompt for lnd 24 word aezeed diff --git a/lnd/hdkeychain.go b/lnd/hdkeychain.go index 3d08077..09f5b8e 100644 --- a/lnd/hdkeychain.go +++ b/lnd/hdkeychain.go @@ -133,6 +133,13 @@ func ShaChainFromPath(extendedKey *hdkeychain.ExtendedKey, return shachain.NewRevocationProducer(*revRoot), nil } +func IdentityPath(params *chaincfg.Params) string { + return fmt.Sprintf( + LndDerivationPath+"/0/0", params.HDCoinType, + keychain.KeyFamilyNodeKey, + ) +} + func AllDerivationPaths(params *chaincfg.Params) ([]string, [][]uint32, error) { mkPath := func(f keychain.KeyFamily) string { return fmt.Sprintf(