From a21dbbb38168c585eb4b4c65171007694aca85bd Mon Sep 17 00:00:00 2001 From: solipsis Date: Mon, 19 Mar 2018 12:05:32 -0600 Subject: [PATCH] getPublicKey + xpubs from path --- cmd/getPublicKey.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 cmd/getPublicKey.go diff --git a/cmd/getPublicKey.go b/cmd/getPublicKey.go new file mode 100644 index 0000000..d85d6a0 --- /dev/null +++ b/cmd/getPublicKey.go @@ -0,0 +1,39 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/solipsis/go-keepkey/pkg/keepkey" + "github.com/spf13/cobra" +) + +func init() { + getPublicKeyCmd.Flags().StringVarP(&nodePath, "nodePath", "p", "44'/0'/0'/0/0", "BIP44 node path") + getPublicKeyCmd.Flags().BoolVarP(&buttonProtection, "display", "d", false, "Display the address on the device") + rootCmd.AddCommand(getPublicKeyCmd) +} + +var getPublicKeyCmd = &cobra.Command{ + Use: "getPublicKey", + Short: "Get a public key for a nodePath including the XPUB", + Long: "Gets a public key for a nodePath including the XPUB", + Run: func(cmd *cobra.Command, args []string) { + + // Parse path + path, err := keepkey.ParsePath(nodePath) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + node, xpub, err := kk.GetPublicKey(path, "secp256k1", buttonProtection) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Println("XPUB: ", xpub) + //TODO: prettier node printing + fmt.Println("Node: ", node) + }, +}