Documentation ¶
Index ¶
- func GobDecode(data []byte, e any) error
- func GobEncode(e any) ([]byte, error)
- func IndexOfElement(elements []Element, element Element, fromIndex int, ...) int
- func MIMC7(left Element, right Element) []byte
- func Poseidon(left Element, right Element) []byte
- func Poseidon2(left Element, right Element) []byte
- func SHA256Hash(left Element, right Element) []byte
- type BaseTree
- func (bt *BaseTree) BulkInsert(elements []Element) error
- func (bt BaseTree) Capacity() int
- func (bt BaseTree) Elements() []Element
- func (bt *BaseTree) Insert(element Element) error
- func (bt BaseTree) Layers() [][]Element
- func (bt *BaseTree) Path(index int) (ProofPath, error)
- func (bt BaseTree) Root() Element
- func (bt *BaseTree) SetLayer(i, j int, val Element)
- func (bt *BaseTree) Update(index int, element Element) error
- func (bt *BaseTree) VerifyProof(elem Element, proof ProofPath) error
- func (bt BaseTree) Zeros() []Element
- type ComparatorFunction
- type Element
- type HashFunction
- type MerkleTree
- func (mt *MerkleTree) BulkInsert(elements []Element) error
- func (mt MerkleTree) GetTreeSlices(count int) ([]TreeSlice, error)
- func (mt MerkleTree) IndexOf(element Element) int
- func (mt MerkleTree) Proof(element Element) (ProofPath, error)
- func (mt MerkleTree) Serialize() (SerializedTreeState, error)
- type ProofPath
- type SerializedTreeState
- type TreeEdge
- type TreeSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IndexOfElement ¶
func IndexOfElement(elements []Element, element Element, fromIndex int, comparator ComparatorFunction) int
* * Find an element in the tree * @param elements elements of tree * @param element An element to find * @param comparator A function that checks leaf value equality * @param fromIndex The index to start the search at. If the index is greater than or equal to the array's length, -1 is returned * @returns {number} Index if element is found, otherwise -1
func SHA256Hash ¶ added in v1.1.0
Types ¶
type BaseTree ¶
type BaseTree struct {
// contains filtered or unexported fields
}
func (*BaseTree) BulkInsert ¶
func (*BaseTree) Path ¶
* * Get merkle path to a leaf * @param {number} index Leaf index to generate path for * @returns {{pathElements: Object[], pathIndex: number[]}} An object containing adjacent elements and left-right index
func (*BaseTree) Update ¶
* * Change an element in the tree * @param {number} index Index of element to change * @param element Updated element value
func (*BaseTree) VerifyProof ¶ added in v1.2.0
* VerifyProof *
type ComparatorFunction ¶
type HashFunction ¶
type MerkleTree ¶
type MerkleTree struct {
*BaseTree
}
func DeserializeMerkleTree ¶
func DeserializeMerkleTree(data SerializedTreeState, hashFn HashFunction) (*MerkleTree, error)
func NewMerkleTree ¶
func NewMerkleTree(levels int, elements []Element, zeroElement Element, hashFn HashFunction) (*MerkleTree, error)
func (*MerkleTree) BulkInsert ¶
func (mt *MerkleTree) BulkInsert(elements []Element) error
* * Insert multiple elements into the tree. * @param elements Elements to insert
func (MerkleTree) GetTreeSlices ¶
func (mt MerkleTree) GetTreeSlices(count int) ([]TreeSlice, error)
func (MerkleTree) IndexOf ¶
func (mt MerkleTree) IndexOf(element Element) int
func (MerkleTree) Serialize ¶
func (mt MerkleTree) Serialize() (SerializedTreeState, error)
* * Serialize entire tree state including intermediate layers into a plain object * Deserializing it back will not require to recompute any hashes * Elements are not converted to a plain type, this is responsibility of the caller
type SerializedTreeState ¶
type SerializedTreeState interface { GetLevels() int GetRoot() Element GetLayers() ([][]Element, error) GetZeros() ([]Element, error) }
func NewSerializedTreeState ¶
func NewSerializedTreeState(tree *MerkleTree) (SerializedTreeState, error)