mtree

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashLength          = 16  // bytes
	WordLength          = 128 // bytes
	BranchElementLength = 32  // bytes
)

Variables

This section is empty.

Functions

func BytesToBig

func BytesToBig(data []byte) *big.Int

Types

type BranchElement

type BranchElement [BranchElementLength]byte

func BranchElementFromHash

func BranchElementFromHash(a, b Hash) BranchElement

func HashesToBranchesArray

func HashesToBranchesArray(hashes []Hash) []BranchElement

func (BranchElement) Big

func (h BranchElement) Big() *big.Int

func (BranchElement) Bytes

func (h BranchElement) Bytes() []byte

func (BranchElement) Hex

func (h BranchElement) Hex() string

func (BranchElement) String

func (h BranchElement) String() string

type BranchNode

type BranchNode struct {
	Hash             NodeData
	Left             *BranchNode
	Right            *BranchNode
	ElementOnTheLeft bool
}

func AcceptLeftSibling

func AcceptLeftSibling(b *BranchNode, h NodeData) *BranchNode

explain the operation

func AcceptRightSibling

func AcceptRightSibling(b *BranchNode, h NodeData) *BranchNode

func (BranchNode) ToNodeArray

func (b BranchNode) ToNodeArray() []NodeData

type BranchTree

type BranchTree struct {
	RawData    ElementData
	HashedData NodeData
	Root       *BranchNode
}

func (BranchTree) ToNodeArray

func (t BranchTree) ToNodeArray() []NodeData

type DagData

type DagData Hash

func (DagData) Copy

func (dd DagData) Copy() NodeData

type DagTree

type DagTree struct {
	MerkleTree
}

func NewKeccak256DagTree

func NewKeccak256DagTree() *DagTree

func NewSHA256DagTree

func NewSHA256DagTree() *DagTree

func (DagTree) AllBranchesArray

func (dt DagTree) AllBranchesArray() []BranchElement

return only one array with necessary hashes for each index in order. Element's hash and root are not included eg. registered indexes are 1, 2, each needs 2 hashes then the function return an array of 4 hashes [a1, a2, b1, b2] where a1, a2 are proof branch for element at index 1 b1, b2 are proof branch for element at index 2

func (DagTree) AllDAGElements

func (dt DagTree) AllDAGElements() []Word

func (DagTree) ProofsForRegisteredIndices

func (dt DagTree) ProofsForRegisteredIndices() [][]Hash

func (DagTree) RootHash

func (dt DagTree) RootHash() Hash

type ElementData

type ElementData interface{}

type Hash

type Hash [HashLength]byte

func (Hash) Big

func (h Hash) Big() *big.Int

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (Hash) Hex

func (h Hash) Hex() string

func (Hash) String

func (h Hash) String() string

type MerkleTree

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

func (MerkleTree) Branches

func (mt MerkleTree) Branches() map[uint32]BranchTree

func (MerkleTree) ExportNodes

func (mt MerkleTree) ExportNodes() []NodeData

func (*MerkleTree) Finalize

func (mt *MerkleTree) Finalize()

func (MerkleTree) Indices

func (mt MerkleTree) Indices() []uint32

func (*MerkleTree) Insert

func (mt *MerkleTree) Insert(data ElementData, index uint32)

func (*MerkleTree) RegisterIndex

func (mt *MerkleTree) RegisterIndex(indexes ...uint32)

register indexes to build branches

func (*MerkleTree) RegisterStoredLevel

func (mt *MerkleTree) RegisterStoredLevel(depth, level uint32)

func (MerkleTree) Root

func (mt MerkleTree) Root() NodeData

func (*MerkleTree) SetElementHashFunction

func (mt *MerkleTree) SetElementHashFunction(_h elementHashFunc)

func (*MerkleTree) SetHashFunction

func (mt *MerkleTree) SetHashFunction(_h hashFunc)

func (*MerkleTree) StoredLevel

func (mt *MerkleTree) StoredLevel() uint32

type NodeData

type NodeData interface {
	Copy() NodeData
}

type Word

type Word [WordLength]byte

func (Word) ToUint256Array

func (w Word) ToUint256Array() []*big.Int

Jump to

Keyboard shortcuts

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