You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Oleksandr Brezhniev 113995d6f4 Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
.github/workflows Upgrade linter rules 3 years ago
db Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
.golangci.yml Upgrade linter rules 3 years ago
LICENSE Init MT adapting from https://github.com/iden3/go-iden3-core/tree/v0.0.8 3 years ago
README.md Small fixes 3 years ago
data.go Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
db.go WIP. Implementation of Postgres Storage for MerkleTree. Changes in how storage works in general. 2 years ago
elembytes.go Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
entry.go Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
go.mod WIP. Implementation of Postgres Storage for MerkleTree. Changes in how storage works in general. 2 years ago
go.sum WIP. Implementation of Postgres Storage for MerkleTree. Changes in how storage works in general. 2 years ago
hash.go Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
merkletree.go Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
merkletree_test.go Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
node.go WIP. Implementation of Postgres Storage for MerkleTree. Changes in how storage works in general. 2 years ago
proof.go Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago
utils.go Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods. 2 years ago

README.md

go-merkletree GoDoc Go Report Card Test

MerkleTree compatible with version from circomlib.

Adaptation of the merkletree from https://github.com/iden3/go-iden3-core/tree/v0.0.8 with several changes and more functionalities.

Usage

More detailed examples can be found at the tests, and in the documentation.

import (
	"fmt"
	"math/big"
	"testing"

	"github.com/iden3/go-iden3-core/db"
	"github.com/stretchr/testify/assert"
)

[...]

func TestExampleMerkleTree(t *testing.T) {
	mt, err := NewMerkleTree(db.NewMemoryStorage(), 10)
	assert.Nil(t, err)

	key := big.NewInt(1)
	value := big.NewInt(2)
	err = mt.Add(key, value)
	assert.Nil(t, err)
	fmt.Println(mt.Root().String())

	v, err := mt.Get(key)
	asseert.Equal(t, value, v)

	value = big.NewInt(3)
	err = mt.Update(key, value)

	proof, err := mt.GenerateProof(key, nil)
	assert.Nil(t, err)

	assert.True(t, VerifyProof(mt.Root(), proof, key, value))

	err := mt.Delete(big.NewInt(1)) // delete the leaf of key=1
	assert.Nil(t, err)
}