forked from cerc-io/laconicd-deprecated
Remove unused encoding package (#214)
This commit is contained in:
parent
30f34e6c59
commit
3ab019b727
@ -1,35 +0,0 @@
|
||||
package encoding
|
||||
|
||||
import (
|
||||
emintcrypto "github.com/cosmos/ethermint/crypto"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
var cdc = amino.NewCodec()
|
||||
|
||||
func init() {
|
||||
RegisterAmino(cdc)
|
||||
}
|
||||
|
||||
// RegisterAmino registers all crypto related types in the given (amino) codec.
|
||||
func RegisterAmino(cdc *amino.Codec) {
|
||||
// These are all written here instead of
|
||||
cdc.RegisterInterface((*tmcrypto.PubKey)(nil), nil)
|
||||
cdc.RegisterConcrete(emintcrypto.PubKeySecp256k1{}, emintcrypto.PubKeyAminoName, nil)
|
||||
|
||||
cdc.RegisterInterface((*tmcrypto.PrivKey)(nil), nil)
|
||||
cdc.RegisterConcrete(emintcrypto.PrivKeySecp256k1{}, emintcrypto.PrivKeyAminoName, nil)
|
||||
}
|
||||
|
||||
// PrivKeyFromBytes unmarshalls emint private key from encoded bytes
|
||||
func PrivKeyFromBytes(privKeyBytes []byte) (privKey tmcrypto.PrivKey, err error) {
|
||||
err = cdc.UnmarshalBinaryBare(privKeyBytes, &privKey)
|
||||
return
|
||||
}
|
||||
|
||||
// PubKeyFromBytes unmarshalls emint public key from encoded bytes
|
||||
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey tmcrypto.PubKey, err error) {
|
||||
err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
|
||||
return
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package encoding
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
emintcrypto "github.com/cosmos/ethermint/crypto"
|
||||
)
|
||||
|
||||
func TestKeyEncodingDecoding(t *testing.T) {
|
||||
// Priv Key encoding and decoding
|
||||
privKey, err := emintcrypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
privBytes := privKey.Bytes()
|
||||
|
||||
decodedPriv, err := PrivKeyFromBytes(privBytes)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, privKey, decodedPriv)
|
||||
|
||||
// Pub key encoding and decoding
|
||||
pubKey := privKey.PubKey()
|
||||
pubBytes := pubKey.Bytes()
|
||||
|
||||
decodedPub, err := PubKeyFromBytes(pubBytes)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, pubKey, decodedPub)
|
||||
}
|
Loading…
Reference in New Issue
Block a user