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.

53 lines
1.1 KiB

  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. "github.com/tendermint/tendermint/crypto/sr25519"
  8. )
  9. func Ed25519ValidatorUpdate(pk []byte, power int64) ValidatorUpdate {
  10. pke := ed25519.PubKey(pk)
  11. pkp, err := cryptoenc.PubKeyToProto(pke)
  12. if err != nil {
  13. panic(err)
  14. }
  15. return ValidatorUpdate{
  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. PubKey: pkp,
  32. Power: power,
  33. }
  34. case sr25519.KeyType:
  35. pke := sr25519.PubKey(pk)
  36. pkp, err := cryptoenc.PubKeyToProto(pke)
  37. if err != nil {
  38. panic(err)
  39. }
  40. return ValidatorUpdate{
  41. PubKey: pkp,
  42. Power: power,
  43. }
  44. default:
  45. panic(fmt.Sprintf("key type %s not supported", keyType))
  46. }
  47. }