2018-02-22 07:17:19 -08:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-12-10 06:27:25 -08:00
|
|
|
|
2018-02-23 01:40:10 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2018-02-22 07:17:19 -08:00
|
|
|
|
2018-10-24 06:37:06 -07:00
|
|
|
"github.com/spf13/cobra"
|
2018-02-22 07:17:19 -08:00
|
|
|
)
|
|
|
|
|
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,
|
2018-04-26 14:32:20 -07:00
|
|
|
Args: cobra.ExactArgs(1),
|
2018-02-22 08:20:25 -08:00
|
|
|
}
|
|
|
|
return cmd
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func runUpdateCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
name := args[0]
|
|
|
|
|
2018-02-28 06:20:46 -08:00
|
|
|
buf := client.BufferStdin()
|
2019-02-06 11:23:49 -08:00
|
|
|
kb, err := NewKeyBaseFromHomeFlag()
|
2018-02-22 07:17:19 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-07-10 19:56:09 -07:00
|
|
|
oldpass, err := client.GetPassword(
|
|
|
|
"Enter the current passphrase:", buf)
|
2018-02-22 07:17:19 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-10 19:56:09 -07:00
|
|
|
getNewpass := func() (string, error) {
|
|
|
|
return client.GetCheckPassword(
|
|
|
|
"Enter the new passphrase:",
|
|
|
|
"Repeat the new passphrase:", buf)
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|
2018-07-10 19:56:09 -07:00
|
|
|
|
|
|
|
err = kb.Update(name, oldpass, getNewpass)
|
2018-02-22 07:17:19 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println("Password successfully updated!")
|
|
|
|
return nil
|
|
|
|
}
|