tendermint/types/signable.go

31 lines
824 B
Go
Raw Normal View History

2015-11-01 11:34:08 -08:00
package types
import (
"bytes"
"io"
2017-04-21 15:12:54 -07:00
. "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/merkle"
2015-11-01 11:34:08 -08:00
)
// Signable is an interface for all signable things.
// It typically removes signatures before serializing.
type Signable interface {
2015-11-10 13:10:43 -08:00
WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
2015-11-01 11:34:08 -08:00
}
// SignBytes is a convenience method for getting the bytes to sign of a Signable.
func SignBytes(chainID string, o Signable) []byte {
2015-11-10 13:10:43 -08:00
buf, n, err := new(bytes.Buffer), new(int), new(error)
2015-11-01 11:34:08 -08:00
o.WriteSignBytes(chainID, buf, n, err)
if *err != nil {
PanicCrisis(err)
}
return buf.Bytes()
}
// HashSignBytes is a convenience method for getting the hash of the bytes of a signable
func HashSignBytes(chainID string, o Signable) []byte {
return merkle.SimpleHashFromBinary(SignBytes(chainID, o))
}