-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement private keys export/import symmetric functionalities
Ref #2020
- Loading branch information
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package keys | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/input" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/mintkey" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func exportKeyCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "export <name>", | ||
Short: "Export private keys", | ||
Long: `Export a private key from the local keybase in ASCII armor format.`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: runExportCmd, | ||
} | ||
return cmd | ||
} | ||
|
||
func runExportCmd(_ *cobra.Command, args []string) error { | ||
kb, err := NewKeyBaseFromHomeFlag() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
buf := input.BufferStdin() | ||
encryptPassword, err := input.GetPassword("Enter passphrase to decrypt your key:", buf) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
priv, err := kb.ExportPrivateKeyObject(args[0], encryptPassword) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
armored := mintkey.EncryptArmorPrivKey(priv, encryptPassword) | ||
fmt.Println(armored) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package keys | ||
|
||
import ( | ||
"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(_ *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 := input.BufferStdin() | ||
passphrase, err := input.GetPassword("Enter passphrase to decrypt your key:", buf) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return kb.ImportPrivKey(args[0], string(bz), passphrase) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters