github.com/Finschia/finschia-sdk@v0.48.1/client/keys/import.go (about) 1 package keys 2 3 import ( 4 "bufio" 5 "os" 6 7 "github.com/spf13/cobra" 8 9 "github.com/Finschia/finschia-sdk/client" 10 "github.com/Finschia/finschia-sdk/client/input" 11 ) 12 13 // ImportKeyCommand imports private keys from a keyfile. 14 func ImportKeyCommand() *cobra.Command { 15 return &cobra.Command{ 16 Use: "import <name> <keyfile>", 17 Short: "Import private keys into the local keybase", 18 Long: "Import a ASCII armored private key into the local keybase.", 19 Args: cobra.ExactArgs(2), 20 RunE: func(cmd *cobra.Command, args []string) error { 21 clientCtx, err := client.GetClientQueryContext(cmd) 22 if err != nil { 23 return err 24 } 25 buf := bufio.NewReader(clientCtx.Input) 26 27 bz, err := os.ReadFile(args[1]) 28 if err != nil { 29 return err 30 } 31 32 passphrase, err := input.GetPassword("Enter passphrase to decrypt your key:", buf) 33 if err != nil { 34 return err 35 } 36 37 return clientCtx.Keyring.ImportPrivKey(args[0], string(bz), passphrase) 38 }, 39 } 40 }