You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

  1. package cryptoAmino
  2. import (
  3. amino "github.com/tendermint/go-amino"
  4. "github.com/tendermint/tendermint/crypto"
  5. "github.com/tendermint/tendermint/crypto/ed25519"
  6. "github.com/tendermint/tendermint/crypto/multisig"
  7. "github.com/tendermint/tendermint/crypto/secp256k1"
  8. )
  9. var cdc = amino.NewCodec()
  10. func init() {
  11. // NOTE: It's important that there be no conflicts here,
  12. // as that would change the canonical representations,
  13. // and therefore change the address.
  14. // TODO: Remove above note when
  15. // https://github.com/tendermint/go-amino/issues/9
  16. // is resolved
  17. RegisterAmino(cdc)
  18. }
  19. // RegisterAmino registers all crypto related types in the given (amino) codec.
  20. func RegisterAmino(cdc *amino.Codec) {
  21. // These are all written here instead of
  22. cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
  23. cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
  24. ed25519.PubKeyAminoRoute, nil)
  25. cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{},
  26. secp256k1.PubKeyAminoRoute, nil)
  27. cdc.RegisterConcrete(multisig.PubKeyMultisigThreshold{},
  28. multisig.PubKeyMultisigThresholdAminoRoute, nil)
  29. cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
  30. cdc.RegisterConcrete(ed25519.PrivKeyEd25519{},
  31. ed25519.PrivKeyAminoRoute, nil)
  32. cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{},
  33. secp256k1.PrivKeyAminoRoute, nil)
  34. }
  35. func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) {
  36. err = cdc.UnmarshalBinaryBare(privKeyBytes, &privKey)
  37. return
  38. }
  39. func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) {
  40. err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
  41. return
  42. }