How to convert exported Cosmos SDK private key to format that can be imported by Keplr or Metamask?

3.7k views Asked by At

Keplr just added the feature to import an account using a private key (which is awesome!). This was primarily requested because a number of lunie users lost their mnemonic phrases but maintained their access to lunie itself. That meant lunie could export a private key but not the mnemonic itself. It may also be userful for future Ethermint users who want to migrate from metamask (which also provides the ability to export and import private keys).

The keys command in the Cosmos SDK CLI also allows a user to export a private key, however I'm unsure how to convert a key from that format into one that could be imported in keplr. The CLI command is as follows:

gaiacli keys export [name]

It requests the passphrase to decrypt the key and then a new passphrase to encrypt the exported key. The results are in the following format:

-----BEGIN TENDERMINT PRIVATE KEY-----
type: secp256k1
kdf: bcrypt
salt: C49BCB6A8358745812F5770A63BD09AD

NmqXg+dPDvVKawZwyER6l3V41tKxWaiIU/or2G7t9SBKRJ0oRREchssK4NpRp+Di
5KNHxHz2QXHLhbPQweo9iVkPPrNQ1uiSGH7maoY=
=GHXH
-----END TENDERMINT PRIVATE KEY-----

(this is an example created for the purpose of this question)

How can I convert this key into something I can use for keplr or metamask?

1

There are 1 answers

2
okwme On BEST ANSWER

This feature just got merged!

https://github.com/cosmos/cosmos-sdk/pull/8043

The command is:

packaged export <name> --unarmored-hex and --unsafe

Where packaged is the name of your daemon binary CLI and name is the name of the key you want to export.