8 "github.com/spf13/cobra"
9 jww "github.com/spf13/jwalterweatherman"
11 "github.com/bytom/blockchain"
12 "github.com/bytom/crypto/ed25519/chainkd"
13 "github.com/bytom/util"
16 var createKeyCmd = &cobra.Command{
17 Use: "create-key <alias> <password>",
18 Short: "Create a key",
19 Args: cobra.ExactArgs(2),
20 Run: func(cmd *cobra.Command, args []string) {
22 Alias string `json:"alias"`
23 Password string `json:"password"`
24 }{Alias: args[0], Password: args[1]}
26 data, exitCode := util.ClientCall("/create-key", &key)
27 if exitCode != util.Success {
35 var deleteKeyCmd = &cobra.Command{
36 Use: "delete-key <xpub> <password>",
37 Short: "Delete a key",
38 Args: cobra.ExactArgs(2),
39 Run: func(cmd *cobra.Command, args []string) {
40 xpub := new(chainkd.XPub)
41 if err := xpub.UnmarshalText([]byte(args[0])); err != nil {
42 jww.ERROR.Println("delete-key:", err)
43 os.Exit(util.ErrLocalExe)
48 XPub chainkd.XPub `json:"xpubs"`
49 }{XPub: *xpub, Password: args[1]}
51 if _, exitCode := util.ClientCall("/delete-key", &key); exitCode != util.Success {
54 jww.FEEDBACK.Println("Successfully delete key")
58 var listKeysCmd = &cobra.Command{
60 Short: "List the existing keys",
62 Run: func(cmd *cobra.Command, args []string) {
63 data, exitCode := util.ClientCall("/list-keys")
64 if exitCode != util.Success {
72 var exportPrivateCmd = &cobra.Command{
73 Use: "export-private-key <xpub> <password>",
74 Short: "Export the private key",
75 Args: cobra.ExactArgs(2),
76 Run: func(cmd *cobra.Command, args []string) {
82 xpub := new(chainkd.XPub)
83 rawPub, err := hex.DecodeString(args[0])
85 jww.ERROR.Println("error: export-private-key args not vaild", err)
90 key.Password = args[1]
92 data, exitCode := util.ClientCall("/export-private-key", &key)
93 if exitCode != util.Success {
101 var importPrivateCmd = &cobra.Command{
102 Use: "import-private-key <key-alias> <private key> <index> <password> <account-alias>",
103 Short: "Import the private key",
104 Args: cobra.ExactArgs(5),
105 Run: func(cmd *cobra.Command, args []string) {
106 var params blockchain.KeyImportParams
107 params.KeyAlias = args[0]
108 params.XPrv = args[1]
109 params.Password = args[3]
110 params.AccountAlias = args[4]
111 index, err := strconv.ParseUint(args[2], 10, 64)
113 jww.ERROR.Println("params index wrong")
117 data, exitCode := util.ClientCall("/import-private-key", ¶ms)
118 if exitCode != util.Success {