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.

57 lines
1.8 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/secp256k1"
  7. )
  8. var cdc = amino.NewCodec()
  9. func init() {
  10. // NOTE: It's important that there be no conflicts here,
  11. // as that would change the canonical representations,
  12. // and therefore change the address.
  13. // TODO: Remove above note when
  14. // https://github.com/tendermint/go-amino/issues/9
  15. // is resolved
  16. RegisterAmino(cdc)
  17. }
  18. // RegisterAmino registers all crypto related types in the given (amino) codec.
  19. func RegisterAmino(cdc *amino.Codec) {
  20. // These are all written here instead of
  21. cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
  22. cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
  23. "tendermint/PubKeyEd25519", nil)
  24. cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{},
  25. "tendermint/PubKeySecp256k1", nil)
  26. cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
  27. cdc.RegisterConcrete(ed25519.PrivKeyEd25519{},
  28. "tendermint/PrivKeyEd25519", nil)
  29. cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{},
  30. "tendermint/PrivKeySecp256k1", nil)
  31. cdc.RegisterInterface((*crypto.Signature)(nil), nil)
  32. cdc.RegisterConcrete(ed25519.SignatureEd25519{},
  33. "tendermint/SignatureEd25519", nil)
  34. cdc.RegisterConcrete(secp256k1.SignatureSecp256k1{},
  35. "tendermint/SignatureSecp256k1", nil)
  36. }
  37. func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) {
  38. err = cdc.UnmarshalBinaryBare(privKeyBytes, &privKey)
  39. return
  40. }
  41. func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) {
  42. err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
  43. return
  44. }
  45. func SignatureFromBytes(pubKeyBytes []byte) (pubKey crypto.Signature, err error) {
  46. err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
  47. return
  48. }