2018-02-22 07:17:19 -08:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-02-23 01:40:10 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2018-02-22 07:17:19 -08:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-02-22 08:20:25 -08:00
|
|
|
func updateKeyCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "update <name>",
|
|
|
|
Short: "Change the password used to protect private key",
|
|
|
|
RunE: runUpdateCmd,
|
|
|
|
}
|
|
|
|
return cmd
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func runUpdateCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
if len(args) != 1 || len(args[0]) == 0 {
|
|
|
|
return errors.New("You must provide a name for the key")
|
|
|
|
}
|
|
|
|
name := args[0]
|
|
|
|
|
2018-02-28 06:20:46 -08:00
|
|
|
buf := client.BufferStdin()
|
|
|
|
oldpass, err := client.GetPassword(
|
|
|
|
"Enter the current passphrase:", buf)
|
2018-02-22 07:17:19 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-28 06:20:46 -08:00
|
|
|
newpass, err := client.GetCheckPassword(
|
|
|
|
"Enter the new passphrase:",
|
|
|
|
"Repeat the new passphrase:", buf)
|
2018-02-22 07:17:19 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
kb, err := GetKeyBase()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = kb.Update(name, oldpass, newpass)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println("Password successfully updated!")
|
|
|
|
return nil
|
|
|
|
}
|