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.

26 lines
555 B

  1. package merkle
  2. import (
  3. "github.com/tendermint/tendermint/crypto/tmhash"
  4. )
  5. // TODO: make these have a large predefined capacity
  6. var (
  7. leafPrefix = []byte{0}
  8. innerPrefix = []byte{1}
  9. )
  10. // returns tmhash(<empty>)
  11. func emptyHash() []byte {
  12. return tmhash.Sum([]byte{})
  13. }
  14. // returns tmhash(0x00 || leaf)
  15. func leafHash(leaf []byte) []byte {
  16. return tmhash.Sum(append(leafPrefix, leaf...))
  17. }
  18. // returns tmhash(0x01 || left || right)
  19. func innerHash(left []byte, right []byte) []byte {
  20. return tmhash.Sum(append(innerPrefix, append(left, right...)...))
  21. }