rmt

package
v0.0.0-...-77dcbbd Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package rmt implements regular merkle tree following LIP-0031.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateRoot

func CalculateRoot(data [][]byte) []byte

CalculateRoot returns a root hash with given data set.

func CalculateRootFromRightWitness

func CalculateRootFromRightWitness(
	nodeIndex uint64,
	appendPath [][]byte,
	rightWitness [][]byte,
) []byte

func CalculateRootFromUpdateData

func CalculateRootFromUpdateData(
	updateData [][]byte,
	proof *Proof,
) ([]byte, error)

func VerifyProof

func VerifyProof(
	queryHashes [][]byte,
	proof *Proof,
	rootHash []byte,
) bool

func VerifyRightWitness

func VerifyRightWitness(
	nodeIndex uint64,
	appendPath [][]byte,
	rightWitness [][]byte,
	root []byte,
) bool

Types

type Database

type Database interface {
	Get(key []byte) ([]byte, bool)
	Del(key []byte)
	Set(key, val []byte)
}

Database represens interface to access the data.

type Proof

type Proof struct {
	Size          uint64   `fieldNumber:"1"`
	Idxs          []uint64 `fieldNumber:"2"`
	SiblingHashes [][]byte `fieldNumber:"3"`
}

Proof holds the proof for lisk tree.

func (*Proof) Decode

func (e *Proof) Decode(data []byte) error

func (*Proof) DecodeFromReader

func (e *Proof) DecodeFromReader(reader *codec.Reader) error

func (*Proof) DecodeStrict

func (e *Proof) DecodeStrict(data []byte) error

func (*Proof) DecodeStrictFromReader

func (e *Proof) DecodeStrictFromReader(reader *codec.Reader) error

func (*Proof) Encode

func (e *Proof) Encode() []byte

func (*Proof) MustDecode

func (e *Proof) MustDecode(data []byte)

type RegularMerkleTree

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

RegularMerkleTree holds lisk markle tree.

func NewRegularMerkleTree

func NewRegularMerkleTree(db Database) *RegularMerkleTree

NewRegularMerkleTree returns new tree with initial value.

func NewRegularMerkleTreeWithPastData

func NewRegularMerkleTreeWithPastData(db Database) (*RegularMerkleTree, error)

NewRegularMerkleTreeWithPastData returns new tree with existing root and append path.

func (*RegularMerkleTree) Append

func (d *RegularMerkleTree) Append(value []byte) error

Append adds value to the tree.

func (*RegularMerkleTree) AppendPath

func (d *RegularMerkleTree) AppendPath() [][]byte

AppendPath returns current append path of the tree.

func (*RegularMerkleTree) GenerateProof

func (d *RegularMerkleTree) GenerateProof(queryHashes [][]byte) (*Proof, error)

func (*RegularMerkleTree) GenerateRightWitness

func (d *RegularMerkleTree) GenerateRightWitness(nodeIndex uint64) ([][]byte, error)

func (*RegularMerkleTree) Root

func (d *RegularMerkleTree) Root() []byte

Root returns current root of the tree.

func (*RegularMerkleTree) Size

func (d *RegularMerkleTree) Size() uint64

Size returns current data length of the tree.

func (*RegularMerkleTree) Update

func (d *RegularMerkleTree) Update(idxs []uint64, updateData [][]byte) error

type RootWithAppendPath

type RootWithAppendPath struct {
	Root       []byte
	AppendPath [][]byte
	Size       uint64
}

func CalculateRootFromAppendPath

func CalculateRootFromAppendPath(value []byte, appendPath [][]byte, size uint64) *RootWithAppendPath

Jump to

Keyboard shortcuts

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