tree

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: AGPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyProof

func VerifyProof(hashFunc arbo.HashFunction, key, value, proof, root []byte) (bool, error)

VerifyProof checks the proof for the given key, value and root, using the passed hash function

Types

type Options

type Options struct {
	// DB defines the database that will be used for the tree
	DB db.Database
	// MaxLevels that the Tree will have
	MaxLevels int
	// HashFunc defines the hash function that the tree will use
	HashFunc arbo.HashFunction
}

Options is used to pass the parameters to load a new Tree

type Tree

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

Tree defines the struct that implements the MerkleTree functionalities

func New

func New(wTx db.WriteTx, opts Options) (*Tree, error)

New returns a new Tree, if there already is a Tree in the database, it will load it

func (*Tree) Add

func (t *Tree) Add(wTx db.WriteTx, key, value []byte) error

Add adds a new leaf, if the key already exists will return error

func (*Tree) AddBatch

func (t *Tree) AddBatch(wTx db.WriteTx, keys, values [][]byte) ([]int, error)

AddBatch adds a batch of key-values to the Tree. Returns an array containing the indexes of the keys failed to add. Supports empty values as input parameters, which is equivalent to 0 valued byte array.

func (*Tree) DB

func (t *Tree) DB() db.Database

DB returns the db.Database from the Tree

func (*Tree) Del added in v1.8.0

func (t *Tree) Del(wTx db.WriteTx, key []byte) error

Del deletes a key from the Tree.

func (*Tree) Dump

func (t *Tree) Dump() ([]byte, error)

Dump exports all the Tree leafs in a byte array.

func (*Tree) DumpWriter

func (t *Tree) DumpWriter(w io.Writer) error

DumpWriter exports all the Tree leafs in a byte writer.

func (*Tree) FromRoot

func (t *Tree) FromRoot(root []byte) (*Tree, error)

FromRoot returns a new read-only Tree for the given root, that uses the same underlying db.

func (*Tree) GenProof

func (t *Tree) GenProof(rTx db.Reader, key []byte) ([]byte, []byte, error)

GenProof returns a byte array with the necessary data to verify that the key&value are in a leaf under the current root

func (*Tree) Get

func (t *Tree) Get(rTx db.Reader, key []byte) ([]byte, error)

Get returns the value for a given key.

func (*Tree) ImportDump

func (t *Tree) ImportDump(b []byte) error

ImportDump imports the leafs (that have been exported with the Dump method) in the Tree.

func (*Tree) Iterate

func (t *Tree) Iterate(rTx db.Reader, callback func(key, value []byte) bool) error

Iterate over all the database-encoded nodes of the tree. When callback returns true, the iteration is stopped and this function returns.

func (*Tree) IterateLeaves

func (t *Tree) IterateLeaves(rTx db.Reader, callback func(key, value []byte) bool) error

IterateLeaves iterates over all leafs of the tree. When callback returns true, the iteration is stopped and this function returns.

func (*Tree) PrintGraphviz

func (t *Tree) PrintGraphviz(rTx db.Reader) error

func (*Tree) Root

func (t *Tree) Root(rTx db.Reader) ([]byte, error)

Root returns the current root.

func (*Tree) Set

func (t *Tree) Set(wTx db.WriteTx, key, value []byte) error

Set adds or updates a key. First performs a Get, and if the key does not exist yet it will call Add, while if the key already exists, it will perform an Update. If the non-existence or existence of the key is already known, is more efficient to directly call Add or Update.

func (*Tree) SetRoot

func (t *Tree) SetRoot(wTx db.WriteTx, root []byte) error

func (*Tree) Size

func (t *Tree) Size(rTx db.Reader) (uint64, error)

Size returns the number of leafs under the current root

func (*Tree) VerifyProof

func (t *Tree) VerifyProof(key, value, proof, root []byte) (bool, error)

VerifyProof checks the proof for the given key, value and root, using the hash function of the Tree

Directories

Path Synopsis
Package arbo implements a Merkle Tree compatible with the circomlib implementation of the MerkleTree, following the specification from https://docs.iden3.io/publications/pdfs/Merkle-Tree.pdf and https://eprint.iacr.org/2018/955.
Package arbo implements a Merkle Tree compatible with the circomlib implementation of the MerkleTree, following the specification from https://docs.iden3.io/publications/pdfs/Merkle-Tree.pdf and https://eprint.iacr.org/2018/955.

Jump to

Keyboard shortcuts

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