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.

37 lines
1.3 KiB

4 years ago
  1. # go-merkletree [![GoDoc](https://godoc.org/github.com/iden3/go-merkletree?status.svg)](https://godoc.org/github.com/iden3/go-merkletree) [![Go Report Card](https://goreportcard.com/badge/github.com/iden3/go-merkletree)](https://goreportcard.com/report/github.com/iden3/go-merkletree) [![Test](https://github.com/iden3/go-merkletree/workflows/Test/badge.svg)](https://github.com/iden3/go-merkletree/actions?query=workflow%3ATest)
  2. MerkleTree compatible with version from [circomlib](https://github.com/iden3/circomlib).
  3. Adaptation of the merkletree from https://github.com/iden3/go-iden3-core/tree/v0.0.8
  4. ## Usage
  5. More detailed examples can be found at the [tests](https://github.com/iden3/go-merkletree/blob/master/merkletree_test.go), and in the [documentation](https://godoc.org/github.com/iden3/go-merkletree).
  6. ```go
  7. import (
  8. "fmt"
  9. "math/big"
  10. "testing"
  11. "github.com/iden3/go-iden3-core/db"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. [...]
  15. func TestExampleMerkleTree(t *testing.T) {
  16. mt, err := NewMerkleTree(db.NewMemoryStorage(), 10)
  17. assert.Nil(t, err)
  18. key := big.NewInt(1)
  19. value := big.NewInt(2)
  20. err = mt.Add(key, value)
  21. assert.Nil(t, err)
  22. fmt.Println(mt.Root().String())
  23. proof, err := mt.GenerateProof(key, nil)
  24. assert.Nil(t, err)
  25. assert.True(t, VerifyProof(mt.Root(), proof, key, value))
  26. }
  27. ```