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.

30 lines
820 B

  1. package types
  2. import (
  3. "bytes"
  4. "io"
  5. . "github.com/tendermint/go-common"
  6. "github.com/tendermint/go-merkle"
  7. )
  8. // Signable is an interface for all signable things.
  9. // It typically removes signatures before serializing.
  10. type Signable interface {
  11. WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)
  12. }
  13. // SignBytes is a convenience method for getting the bytes to sign of a Signable.
  14. func SignBytes(chainID string, o Signable) []byte {
  15. buf, n, err := new(bytes.Buffer), new(int64), new(error)
  16. o.WriteSignBytes(chainID, buf, n, err)
  17. if *err != nil {
  18. PanicCrisis(err)
  19. }
  20. return buf.Bytes()
  21. }
  22. // HashSignBytes is a convenience method for getting the hash of the bytes of a signable
  23. func HashSignBytes(chainID string, o Signable) []byte {
  24. return merkle.SimpleHashFromBinary(SignBytes(chainID, o))
  25. }