2018-12-18 16:10:04 +00:00
|
|
|
package crypto
|
|
|
|
|
2019-08-11 14:42:46 +00:00
|
|
|
import (
|
2020-08-11 15:01:15 +00:00
|
|
|
cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
|
|
|
|
2019-08-11 14:42:46 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-08-11 15:01:15 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
2019-08-11 14:42:46 +00:00
|
|
|
)
|
2018-12-18 16:10:04 +00:00
|
|
|
|
2020-08-11 15:01:15 +00:00
|
|
|
// CryptoCodec is the default amino codec used by ethermint
|
|
|
|
var CryptoCodec = codec.New()
|
2018-12-18 16:10:04 +00:00
|
|
|
|
2020-08-11 15:01:15 +00:00
|
|
|
// Amino encoding names
|
2019-09-15 16:12:59 +00:00
|
|
|
const (
|
2020-08-11 15:01:15 +00:00
|
|
|
PrivKeyAminoName = "ethermint/PrivKeySecp256k1"
|
|
|
|
PubKeyAminoName = "ethermint/PubKeySecp256k1"
|
2019-09-15 16:12:59 +00:00
|
|
|
)
|
|
|
|
|
2018-12-18 16:10:04 +00:00
|
|
|
func init() {
|
2020-08-11 15:01:15 +00:00
|
|
|
// replace the keyring codec with the ethermint crypto codec to prevent
|
|
|
|
// amino panics because of unregistered Priv/PubKey
|
|
|
|
keyring.CryptoCdc = CryptoCodec
|
|
|
|
keyring.RegisterCodec(CryptoCodec)
|
|
|
|
cryptoamino.RegisterAmino(CryptoCodec)
|
|
|
|
RegisterCodec(CryptoCodec)
|
2018-12-18 16:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterCodec registers all the necessary types with amino for the given
|
|
|
|
// codec.
|
|
|
|
func RegisterCodec(cdc *codec.Codec) {
|
2019-09-15 16:12:59 +00:00
|
|
|
cdc.RegisterConcrete(PubKeySecp256k1{}, PubKeyAminoName, nil)
|
|
|
|
cdc.RegisterConcrete(PrivKeySecp256k1{}, PrivKeyAminoName, nil)
|
2018-12-18 16:10:04 +00:00
|
|
|
}
|