6 "github.com/spf13/cobra"
7 jww "github.com/spf13/jwalterweatherman"
9 "github.com/vapor/crypto/ed25519/chainkd"
10 "github.com/vapor/util"
13 var createKeyCmd = &cobra.Command{
14 Use: "create-key <alias> <password>",
15 Short: "Create a key",
16 Args: cobra.ExactArgs(2),
17 Run: func(cmd *cobra.Command, args []string) {
19 Alias string `json:"alias"`
20 Password string `json:"password"`
21 }{Alias: args[0], Password: args[1]}
23 data, exitCode := util.ClientCall("/create-key", &key)
24 if exitCode != util.Success {
32 var deleteKeyCmd = &cobra.Command{
33 Use: "delete-key <xpub> <password>",
34 Short: "Delete a key",
35 Args: cobra.ExactArgs(2),
36 Run: func(cmd *cobra.Command, args []string) {
37 xpub := new(chainkd.XPub)
38 if err := xpub.UnmarshalText([]byte(args[0])); err != nil {
39 jww.ERROR.Println("delete-key:", err)
40 os.Exit(util.ErrLocalExe)
45 XPub chainkd.XPub `json:"xpub"`
46 }{XPub: *xpub, Password: args[1]}
48 if _, exitCode := util.ClientCall("/delete-key", &key); exitCode != util.Success {
51 jww.FEEDBACK.Println("Successfully delete key")
55 var listKeysCmd = &cobra.Command{
57 Short: "List the existing keys",
59 Run: func(cmd *cobra.Command, args []string) {
60 data, exitCode := util.ClientCall("/list-keys")
61 if exitCode != util.Success {
69 var resetKeyPwdCmd = &cobra.Command{
70 Use: "reset-key-password <xpub> <old-password> <new-password>",
71 Short: "Reset key password",
72 Args: cobra.ExactArgs(3),
73 Run: func(cmd *cobra.Command, args []string) {
74 xpub := new(chainkd.XPub)
75 if err := xpub.UnmarshalText([]byte(args[0])); err != nil {
76 jww.ERROR.Println("reset-key-password args not valid:", err)
77 os.Exit(util.ErrLocalExe)
81 XPub chainkd.XPub `json:"xpub"`
82 OldPassword string `json:"old_password"`
83 NewPassword string `json:"new_password"`
84 }{XPub: *xpub, OldPassword: args[1], NewPassword: args[2]}
86 data, exitCode := util.ClientCall("/reset-key-password", &ins)
87 if exitCode != util.Success {
95 var checkKeyPwdCmd = &cobra.Command{
96 Use: "check-key-password <xpub> <password>",
97 Short: "check key password",
98 Args: cobra.ExactArgs(2),
99 Run: func(cmd *cobra.Command, args []string) {
100 xpub := new(chainkd.XPub)
101 if err := xpub.UnmarshalText([]byte(args[0])); err != nil {
102 jww.ERROR.Println("check-key-password args not valid:", err)
103 os.Exit(util.ErrLocalExe)
107 XPub chainkd.XPub `json:"xpub"`
108 Password string `json:"password"`
109 }{XPub: *xpub, Password: args[1]}
111 data, exitCode := util.ClientCall("/check-key-password", &ins)
112 if exitCode != util.Success {
120 var signMsgCmd = &cobra.Command{
121 Use: "sign-message <address> <message> <password>",
122 Short: "sign message to generate signature",
123 Args: cobra.ExactArgs(3),
124 Run: func(cmd *cobra.Command, args []string) {
126 Address string `json:"address"`
127 Message string `json:"message"`
128 Password string `json:"password"`
129 }{Address: args[0], Message: args[1], Password: args[2]}
131 data, exitCode := util.ClientCall("/sign-message", &req)
132 if exitCode != util.Success {
139 var verifyMsgCmd = &cobra.Command{
140 Use: "verify-message <address> <xpub> <message> <signature>",
141 Short: "verify signature for specified message",
142 Args: cobra.ExactArgs(4),
143 Run: func(cmd *cobra.Command, args []string) {
144 xpub := chainkd.XPub{}
145 if err := xpub.UnmarshalText([]byte(args[1])); err != nil {
146 jww.ERROR.Println(err)
147 os.Exit(util.ErrLocalExe)
151 Address string `json:"address"`
152 DerivedXPub chainkd.XPub `json:"derived_xpub"`
153 Message string `json:"message"`
154 Signature string `json:"signature"`
155 }{Address: args[0], DerivedXPub: xpub, Message: args[2], Signature: args[3]}
157 data, exitCode := util.ClientCall("/verify-message", &req)
158 if exitCode != util.Success {