Add generate publickey from keystore
package cli
import (
+ "encoding/hex"
"fmt"
- "io/ioutil"
- "log"
-
"github.com/icon-project/goloop/common/wallet"
"github.com/spf13/cobra"
+ "io/ioutil"
+ "log"
)
func newKeystoreGenCmd(c string) *cobra.Command {
@@ -36,5 +36,38 @@ func newKeystoreGenCmd(c string) *cobra.Command {
func NewKeystoreCmd(c string) *cobra.Command {
cmd := &cobra.Command{Use: c, Short: "Keystore manipulation"}
cmd.AddCommand(newKeystoreGenCmd("gen"))
+ cmd.AddCommand(publickeyFromKeyStore("pubkey"))
+ return cmd
+}
+
+func publickeyFromKeyStore(c string) *cobra.Command {
+ cmd := &cobra.Command{
+ Use: c,
+ Short: "Generate publickey from keystore",
+ }
+ flags := cmd.PersistentFlags()
+ keystorePath := flags.StringP("keystore", "k", "keystore.json", "Keystore file path")
+ secret := flags.StringP("secret", "s", "", "KeySecret file path")
+ pass := flags.StringP("password", "p", "gochain", "Password for the keystore")
+ cmd.Run = func(cmd *cobra.Command, args []string) {
+ var pb []byte
+ if kb, err := ioutil.ReadFile(*keystorePath); err != nil {
+ log.Panicf("fail to open keystore file err=%+v", err)
+ } else {
+ if *secret != "" {
+ if pb, err = ioutil.ReadFile(*secret); err != nil {
+ log.Panicf("fail to open KeySecret err=%+v", err)
+ }
+ } else {
+ pb = []byte(*pass)
+ }
+
+ w, err := wallet.NewFromKeyStore(kb, pb)
+ if err != nil {
+ log.Panicf("Fail to decrypt KeyStore err=%+v", err)
+ }
+ fmt.Println("0x" + hex.EncodeToString(w.PublicKey()))
+ }
+ }
return cmd
}
