Skip to content

Commit 7a3c9a3

Browse files
committed
derivekey: add new --identity flag for lnd identity_pubkey
1 parent f78b4e0 commit 7a3c9a3

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

cmd/chantools/derivekey.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Extended private key (xprv): %s
2121
`
2222

2323
type deriveKeyCommand struct {
24-
Path string
25-
Neuter bool
24+
Path string
25+
Neuter bool
26+
Identity bool
2627

2728
rootKey *rootKey
2829
cmd *cobra.Command
@@ -36,7 +37,9 @@ func newDeriveKeyCommand() *cobra.Command {
3637
Long: `This command derives a single key with the given BIP32
3738
derivation path from the root key and prints it to the console.`,
3839
Example: `chantools derivekey --path "m/1017'/0'/5'/0/0'" \
39-
--neuter`,
40+
--neuter
41+
42+
chantools derivekey --identity`,
4043
RunE: cc.Execute,
4144
}
4245
cc.cmd.Flags().StringVar(
@@ -47,6 +50,10 @@ derivation path from the root key and prints it to the console.`,
4750
&cc.Neuter, "neuter", false, "don't output private key(s), "+
4851
"only public key(s)",
4952
)
53+
cc.cmd.Flags().BoolVar(
54+
&cc.Identity, "identity", false, "derive the lnd "+
55+
"identity_pubkey",
56+
)
5057

5158
cc.rootKey = newRootKey(cc.cmd, "decrypting the backup")
5259

@@ -59,6 +66,11 @@ func (c *deriveKeyCommand) Execute(_ *cobra.Command, _ []string) error {
5966
return fmt.Errorf("error reading root key: %v", err)
6067
}
6168

69+
if c.Identity {
70+
c.Path = lnd.IdentityPath(chainParams)
71+
c.Neuter = true
72+
}
73+
6274
return deriveKey(extendedKey, c.Path, c.Neuter)
6375
}
6476

doc/chantools_derivekey.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ chantools derivekey [flags]
1515

1616
```
1717
chantools derivekey --path "m/1017'/0'/5'/0/0'" \
18-
--neuter
18+
--neuter
19+
20+
chantools derivekey --identity
1921
```
2022

2123
### Options
2224

2325
```
2426
--bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag
2527
-h, --help help for derivekey
28+
--identity derive the lnd identity_pubkey
2629
--neuter don't output private key(s), only public key(s)
2730
--path string BIP32 derivation path to derive; must start with "m/"
2831
--rootkey string BIP32 HD root key of the wallet to use for decrypting the backup; leave empty to prompt for lnd 24 word aezeed

lnd/hdkeychain.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ func ShaChainFromPath(extendedKey *hdkeychain.ExtendedKey,
133133
return shachain.NewRevocationProducer(*revRoot), nil
134134
}
135135

136+
func IdentityPath(params *chaincfg.Params) string {
137+
return fmt.Sprintf(
138+
LndDerivationPath+"/0/0", params.HDCoinType,
139+
keychain.KeyFamilyNodeKey,
140+
)
141+
}
142+
136143
func AllDerivationPaths(params *chaincfg.Params) ([]string, [][]uint32, error) {
137144
mkPath := func(f keychain.KeyFamily) string {
138145
return fmt.Sprintf(

0 commit comments

Comments
 (0)