-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
import.go
40 lines (33 loc) · 839 Bytes
/
import.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package keys
import (
"bufio"
"io/ioutil"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/spf13/cobra"
)
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
}
func runImportCmd(cmd *cobra.Command, args []string) error {
kb, err := NewKeyBaseFromHomeFlag()
if err != nil {
return err
}
bz, err := ioutil.ReadFile(args[1])
if err != nil {
return err
}
buf := bufio.NewReader(cmd.InOrStdin())
passphrase, err := input.GetPassword("Enter passphrase to decrypt your key:", buf)
if err != nil {
return err
}
return kb.ImportPrivKey(args[0], string(bz), passphrase)
}