merkledb

package
v0.0.7-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateProof

func ValidateProof(key types.ID, value []byte, root types.ID, proof MerkleProof) (bool, error)

ValidateProof validates the merkle proof. If this is an exclusion proof the data should be nil.

Types

type HashVal

type HashVal []byte

func NewHashVal

func NewHashVal() HashVal

func (HashVal) Bytes

func (h HashVal) Bytes() []byte

func (HashVal) Clone

func (h HashVal) Clone() HashVal

func (HashVal) IsData

func (h HashVal) IsData() bool

func (HashVal) IsNil

func (h HashVal) IsNil() bool

func (HashVal) Key

func (h HashVal) Key() []byte

func (HashVal) String

func (h HashVal) String() string

func (HashVal) ValueHash

func (h HashVal) ValueHash() ([]byte, error)

type MerkleDB

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

MerkleDB is a key value database which, in addition to storing key/value pairs, maintains a binary merkle tree of the data stored in the database. This allows us to create a root hash for the database as well as create compact inclusion and exclusion proofs for that data.

func NewMerkleDB

func NewMerkleDB(ds repo.Datastore) (*MerkleDB, error)

NewMerkleDB returns a new database

func (*MerkleDB) Delete

func (mdb *MerkleDB) Delete(key types.ID) error

Delete removes a key/value pair from the database. In the tree structure the value will be set to the nil hash.

func (*MerkleDB) Exists

func (mdb *MerkleDB) Exists(key types.ID) (bool, MerkleProof, error)

Exists returns whether the key exists in the database along with a merkle inclusion or exclusion proof which links either the value, or nil, to the database's merkle root.

func (*MerkleDB) Get

func (mdb *MerkleDB) Get(key types.ID) ([]byte, MerkleProof, error)

Get returns a value from the database for a given key along with a merkle proof linking the value to the database's root hash. This method with not return an exclusion proof if the value does not exist just an error.

func (*MerkleDB) Put

func (mdb *MerkleDB) Put(key types.ID, value []byte) error

Put a new key/value pair into the database. This operation will update the database's merkle root. It will also override any value that is currently stored in the database at this key.

func (*MerkleDB) Root

func (mdb *MerkleDB) Root() (types.ID, error)

Root returns the database's root hash.

type MerkleProof

type MerkleProof []HashVal

MerkleProof represents a merkle inclusion or exclusion proof that links the data to a root hash.

type Node

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

Node represents a branch in the merkle tree. The left and right values can either be: - A zero byte array (represents a nil value) - A hash of data - A hash of a child node

func (*Node) Hash

func (n *Node) Hash() HashVal

Hash returns the hash of the concatenation of the left and right branches.

func (*Node) Left

func (n *Node) Left() HashVal

Left returns the left branch of the node.

func (*Node) Right

func (n *Node) Right() HashVal

Right returns the right branch of the node.

Jump to

Keyboard shortcuts

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