Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iden3/go-merkletree
MerkleTree compatible with circomlib/smt
https://github.com/iden3/go-merkletree
Last synced: 2 months ago
JSON representation
MerkleTree compatible with circomlib/smt
- Host: GitHub
- URL: https://github.com/iden3/go-merkletree
- Owner: iden3
- License: gpl-3.0
- Created: 2020-06-30T20:03:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-09T07:35:46.000Z (over 3 years ago)
- Last Synced: 2024-08-03T08:02:36.156Z (5 months ago)
- Language: Go
- Size: 196 KB
- Stars: 13
- Watchers: 7
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-circom - go-merkletree - MerkleTree compatible with circomlib (Cryptographic primitives / Cryptographic primitives in other languages)
README
# 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)
MerkleTree compatible with version from [circomlib](https://github.com/iden3/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](https://github.com/iden3/go-merkletree/blob/master/merkletree_test.go), and in the [documentation](https://godoc.org/github.com/iden3/go-merkletree).```go
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)
}
```