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.

44 lines
910 B

  1. package types
  2. import (
  3. fmt "fmt"
  4. "github.com/tendermint/tendermint/crypto/ed25519"
  5. cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
  6. "github.com/tendermint/tendermint/crypto/secp256k1"
  7. )
  8. func Ed25519ValidatorUpdate(pk []byte, power int64) ValidatorUpdate {
  9. pke := ed25519.PubKey(pk)
  10. pkp, err := cryptoenc.PubKeyToProto(pke)
  11. if err != nil {
  12. panic(err)
  13. }
  14. return ValidatorUpdate{
  15. // Address:
  16. PubKey: pkp,
  17. Power: power,
  18. }
  19. }
  20. func UpdateValidator(pk []byte, power int64, keyType string) ValidatorUpdate {
  21. switch keyType {
  22. case "", ed25519.KeyType:
  23. return Ed25519ValidatorUpdate(pk, power)
  24. case secp256k1.KeyType:
  25. pke := secp256k1.PubKey(pk)
  26. pkp, err := cryptoenc.PubKeyToProto(pke)
  27. if err != nil {
  28. panic(err)
  29. }
  30. return ValidatorUpdate{
  31. // Address:
  32. PubKey: pkp,
  33. Power: power,
  34. }
  35. default:
  36. panic(fmt.Sprintf("key type %s not supported", keyType))
  37. }
  38. }