- package merkle
-
- import (
- "github.com/tendermint/tendermint/crypto/tmhash"
- )
-
- // TODO: make these have a large predefined capacity
- var (
- leafPrefix = []byte{0}
- innerPrefix = []byte{1}
- )
-
- // returns tmhash(<empty>)
- func emptyHash() []byte {
- return tmhash.Sum([]byte{})
- }
-
- // returns tmhash(0x00 || leaf)
- func leafHash(leaf []byte) []byte {
- return tmhash.Sum(append(leafPrefix, leaf...))
- }
-
- // returns tmhash(0x01 || left || right)
- func innerHash(left []byte, right []byte) []byte {
- data := make([]byte, len(innerPrefix)+len(left)+len(right))
- n := copy(data, innerPrefix)
- n += copy(data[n:], left)
- copy(data[n:], right)
- return tmhash.Sum(data)
- }
|