You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chantools/cmd/chantools/showrootkey.go

50 lines
1.1 KiB
Go

package main
import (
"fmt"
"github.com/spf13/cobra"
)
const showRootKeyFormat = `
Your BIP32 HD root key is: %v
`
type showRootKeyCommand struct {
rootKey *rootKey
cmd *cobra.Command
}
func newShowRootKeyCommand() *cobra.Command {
cc := &showRootKeyCommand{}
cc.cmd = &cobra.Command{
Use: "showrootkey",
Short: "Extract and show the BIP32 HD root key from the 24 " +
"word lnd aezeed",
Long: `This command converts the 24 word lnd aezeed phrase and
password to the BIP32 HD root key that is used as the --rootkey flag in other
commands of this tool.`,
Example: `chantools showrootkey`,
RunE: cc.Execute,
}
cc.rootKey = newRootKey(cc.cmd, "decrypting the backup")
return cc.cmd
}
func (c *showRootKeyCommand) Execute(_ *cobra.Command, _ []string) error {
extendedKey, err := c.rootKey.read()
if err != nil {
return fmt.Errorf("error reading root key: %w", err)
}
result := fmt.Sprintf(showRootKeyFormat, extendedKey)
fmt.Println(result)
// For the tests, also log as trace level which is disabled by default.
log.Tracef(result)
return nil
}