2019-05-30 08:44:28 -07:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
2019-06-22 02:24:59 -07:00
|
|
|
"bufio"
|
2019-05-30 08:44:28 -07:00
|
|
|
"io/ioutil"
|
|
|
|
|
2019-06-08 03:04:52 -07:00
|
|
|
"github.com/spf13/cobra"
|
2019-07-22 08:26:42 -07:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/input"
|
2019-05-30 08:44:28 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func importKeyCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "import <name> <keyfile>",
|
|
|
|
Short: "Import private keys into the local keybase",
|
|
|
|
Long: "Import a ASCII armored private key into the local keybase.",
|
|
|
|
Args: cobra.ExactArgs(2),
|
|
|
|
RunE: runImportCmd,
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2019-06-22 02:24:59 -07:00
|
|
|
func runImportCmd(cmd *cobra.Command, args []string) error {
|
2019-11-14 06:17:21 -08:00
|
|
|
buf := bufio.NewReader(cmd.InOrStdin())
|
|
|
|
kb, err := NewKeyringFromHomeFlag(buf)
|
2019-05-30 08:44:28 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
bz, err := ioutil.ReadFile(args[1])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
passphrase, err := input.GetPassword("Enter passphrase to decrypt your key:", buf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return kb.ImportPrivKey(args[0], string(bz), passphrase)
|
|
|
|
}
|