func Root(hashes []*[sha256.Size]byte) *[sha256.Size]byte {
	h := Tree(hashes)
	if h == nil {
		return nil
	}
	return h[len(h)-1]
}
Root returns only the merkle root of an array of digests.
package merkle
import (
	"bytes"
	"crypto/sha256"
	"errors"
	"fmt"
	"math"
	"math/bits"
	"sort"
)
var (
	ErrEmpty = errors.New("empty merkle branch")
)
type sortableSlice []*[sha256.Size]byte
func (s sortableSlice) Len() int      { return len(s) }
func (s sortableSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s sortableSlice) Less(i, j int) bool {
	ii := *s[i]
	jj := *s[j]
	return bytes.Compare(ii[:], jj[:]) < 0
}
func bytes2bits(b []byte) []byte {
	bits := make([]byte, 0, len(b)*8)
	for i := 0; i < len(b); i++ {
		for j := uint(0); j < 8; j++ {
			bits = append(bits, (b[i]>>j)&0x01)
		}
	}
	return bits
}
func calcTreeWidth(num, height uint32) uint32 {
	return (num + (1 << height) - 1) >> height
}
func concatDigests(hashes ...*[sha256.Size]byte) *[sha256.Size]byte {
	h := sha256.New()
	for _, hash := range hashes {
		h.Write(hash[:])
	}
	var rv [sha256.Size]byte
	copy(rv[:], h.Sum(nil))
	return &rv
}
func nextPowerOfTwo(n int) int {
	if n&(n-1) == 0 {
		return n
	}
	return 1 << uint64(bits.Len(uint(n)))
}
func Tree(hashes []*[sha256.Size]byte) []*[sha256.Size]byte {
	if len(hashes) == 0 {
		return nil
	}
	sort.Sort(sortableSlice(hashes))
	nextPoT := nextPowerOfTwo(len(hashes))
	arraySize := nextPoT*2 - 1
	merkles := make([]*[sha256.Size]byte, arraySize)
	copy(merkles, hashes)
	offset := nextPoT
	for i := 0; i < arraySize-1; i += 2 {
		switch {
		case merkles[i] == nil:
			merkles[offset] = nil
		case merkles[i+1] == nil:
			newHash := concatDigests(merkles[i], merkles[i])
			merkles[offset] = newHash
		default:
			newHash := concatDigests(merkles[i], merkles[i+1])
			merkles[offset] = newHash
		}
		offset++
	}
	return merkles
}