-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import unarmored-hex private key in keychain #4024
Comments
I'm looking at my notes on wallets, and I find cosmjs has |
I gather a number of people are hitting this issue via the Google login option of keplr:
|
keyFmt work-aroundGiven the raw key above $ cd ag0/cmd
$ go build keyFmt.go # see source code below
$ ./keyFmt >keyfile
Enter 64 character raw hex private secp256k1 key:
Pick a password, at least 8 chars:
$ cat keyfile
-----BEGIN TENDERMINT PRIVATE KEY-----
kdf: bcrypt
salt: E0C8E18B626209820597AF1136C85F54
0Y4i7ZWCuAbyOYxOSkUQpHuXdofjnb0Aos2NFiC2oxFuqemctRDq+aFJIA3nWnoR
zNpdD+vcnGOMBQijgjIoEtqWMDse+zlwqNaKmdw=
=uXKy
-----END TENDERMINT PRIVATE KEY-----
$ ag0 keys import keyname keyfile
Enter passphrase to decrypt your key: keyFmt.gopackage main
import (
"bufio"
"encoding/hex"
"fmt"
"os"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
)
func main() {
buf := bufio.NewReader(os.Stdin)
privKeyHex, err := input.GetPassword("Enter 64 character raw hex private secp256k1 key:", buf)
passphrase, err := input.GetPassword("Pick a password, at least 8 chars:", buf)
if err != nil {
panic(err)
}
privKeyRaw, err := hex.DecodeString(privKeyHex)
if err != nil {
panic(err)
}
cdc := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(cdc)
privKeyBytes := cdc.MustMarshal(secp256k1.PrivKey{Key: privKeyRaw})
privKey, err := legacy.PrivKeyFromBytes(privKeyBytes)
if err != nil {
panic(err)
}
text := crypto.EncryptArmorPrivKey(privKey, passphrase, "")
fmt.Println(text)
} |
Can confirm - this workaround works. Thanks for your help! |
@dckc Thank you so much for the workaround. I confirm I am able to import my private key. |
Just to bring it all home. You still must import the keyfile using this command |
Thank you @kennyrowe. Yes, I am able to import it. |
Thanks for confirming the work-around, everybody. I added a small section about this in the validator guide. As to an actual fix, we could request that cosmos-sdk fix this bug, but my guess is that they would not consider it a bug. There are good reasons for them to insist on a mnemonic phrase; for example so that you can generate many accounts from the same recovery phrase. We could make an enhancement request, but I'm not sure how that would go over either. Or we could add it to ag0 even though upstream cosmos-sdk doesn't support it. That adds additional cost which doesn't look worthwhile. So I'm re-phrasing this as an enhancement but closing it as wontfix. |
Describe the bug
For now there is no supported way to import unarmored-hex private key through cli.
To Reproduce
Steps to reproduce the behavior:
key add
Example
Example
Example
keys import ...
Example
Expected behavior
Key should be encrypted and imported in keychain
Platform Environment
The text was updated successfully, but these errors were encountered: