merkletree

package
v0.0.0-...-89c2401 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package merkletree provides a simple Merkle tree implementation.

Under the hood it uses a Merkle Mountain Range (MMR).

Index

Constants

View Source
const HashLength = 64

HashLength is the number of bytes to read from the Shake hash.

Variables

This section is empty.

Functions

This section is empty.

Types

type MerkleTree

type MerkleTree struct {
	// contains filtered or unexported fields
}

MerkleTree is a simple Merkle Tree data structure.

func New

func New() *MerkleTree

New returns a new empty MerkleTree.

func (*MerkleTree) Append

func (m *MerkleTree) Append(b []byte)

Append adds an entry to the MerkleTree.

func (*MerkleTree) At

func (m *MerkleTree) At(pos int) []byte

At returns the entry at pos in the MerkleTree. If pos does not exist in the MerkleTree, At panics.

func (*MerkleTree) Len

func (m *MerkleTree) Len() int

Len returns the number of entries in the MerkleTree.

func (*MerkleTree) Summary

func (m *MerkleTree) Summary() Summary

Summary returns the length and hash of the Merkle tree.

type Summary

type Summary struct {
	N       int
	Summary [HashLength]byte
}

Summary is a summary of a tree.

var EmptyTreeSummary Summary = Summary{
	N:       0,
	Summary: [HashLength]byte{0x46, 0xb9, 0xdd, 0x2b, 0xb, 0xa8, 0x8d, 0x13, 0x23, 0x3b, 0x3f, 0xeb, 0x74, 0x3e, 0xeb, 0x24, 0x3f, 0xcd, 0x52, 0xea, 0x62, 0xb8, 0x1b, 0x82, 0xb5, 0xc, 0x27, 0x64, 0x6e, 0xd5, 0x76, 0x2f, 0xd7, 0x5d, 0xc4, 0xdd, 0xd8, 0xc0, 0xf2, 0x0, 0xcb, 0x5, 0x1, 0x9d, 0x67, 0xb5, 0x92, 0xf6, 0xfc, 0x82, 0x1c, 0x49, 0x47, 0x9a, 0xb4, 0x86, 0x40, 0x29, 0x2e, 0xac, 0xb3, 0xb7, 0xc4, 0xbe},
}

EmptyTreeSummary is the fixed summary of an empty Merkle tree.

func (Summary) Equals

func (s Summary) Equals(s2 Summary) bool

Equals returns true if the summaries are equal.

func (Summary) String

func (s Summary) String() string

ShortString returns a short string representation of a Summary.

Hashes are truncated to 8 base64-encoded characters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL