mirror of
https://github.com/arnaucube/go-merkletree-iden3.git
synced 2026-02-06 19:16:43 +01:00
Update golint warnings
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# go-merkletree
|
||||
# go-merkletree [](https://goreportcard.com/report/github.com/iden3/go-merkletree)
|
||||
|
||||
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
|
||||
|
||||
@@ -46,26 +46,31 @@ var (
|
||||
ErrEntryIndexAlreadyExists = errors.New("the entry index already exists in the tree")
|
||||
// ErrNotWritable is used when the MerkleTree is not writable and a write function is called
|
||||
ErrNotWritable = errors.New("Merkle Tree not writable")
|
||||
|
||||
rootNodeValue = []byte("currentroot")
|
||||
HashZero = Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
rootNodeValue = []byte("currentroot")
|
||||
// HashZero is used at Empty nodes
|
||||
HashZero = Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
)
|
||||
|
||||
// Hash is the generic type stored in the MerkleTree
|
||||
type Hash [32]byte
|
||||
|
||||
func (h Hash) String() string {
|
||||
return new(big.Int).SetBytes(h[:]).String()
|
||||
}
|
||||
|
||||
// BigInt returns the *big.Int representation of the *Hash
|
||||
func (h *Hash) BigInt() *big.Int {
|
||||
return new(big.Int).SetBytes(common.SwapEndianness(h[:]))
|
||||
}
|
||||
|
||||
// NewHashFromBigInt returns a *Hash representation of the given *big.Int
|
||||
func NewHashFromBigInt(b *big.Int) *Hash {
|
||||
r := &Hash{}
|
||||
copy(r[:], common.SwapEndianness(b.Bytes()))
|
||||
return r
|
||||
}
|
||||
|
||||
// MerkleTree is the struct with the main elements of the MerkleTree
|
||||
type MerkleTree struct {
|
||||
sync.RWMutex
|
||||
db db.Storage
|
||||
@@ -74,6 +79,7 @@ type MerkleTree struct {
|
||||
maxLevels int
|
||||
}
|
||||
|
||||
// NewMerkleTree loads a new Merkletree. If in the sotrage already exists one will open that one, if not, will create a new one.
|
||||
func NewMerkleTree(storage db.Storage, maxLevels int) (*MerkleTree, error) {
|
||||
mt := MerkleTree{db: storage, maxLevels: maxLevels, writable: true}
|
||||
|
||||
@@ -96,10 +102,12 @@ func NewMerkleTree(storage db.Storage, maxLevels int) (*MerkleTree, error) {
|
||||
return &mt, nil
|
||||
}
|
||||
|
||||
// Root returns the MerkleRoot
|
||||
func (mt *MerkleTree) Root() *Hash {
|
||||
return mt.rootKey
|
||||
}
|
||||
|
||||
// Add adds a Key & Value into the MerkleTree. Where the `k` determines the path from the Root to the Leaf.
|
||||
func (mt *MerkleTree) Add(k, v *big.Int) error {
|
||||
// verify that the MerkleTree is writable
|
||||
if !mt.writable {
|
||||
|
||||
2
node.go
2
node.go
@@ -69,7 +69,7 @@ func NewNodeFromBytes(b []byte) (*Node, error) {
|
||||
if len(b) != 2*ElemBytesLen {
|
||||
return nil, ErrNodeDataBadSize
|
||||
}
|
||||
n.Entry = [2]*Hash{&Hash{}, &Hash{}}
|
||||
n.Entry = [2]*Hash{{}, {}}
|
||||
copy(n.Entry[0][:], b[0:32])
|
||||
copy(n.Entry[1][:], b[32:64])
|
||||
case NodeTypeEmpty:
|
||||
|
||||
1
utils.go
1
utils.go
@@ -52,6 +52,7 @@ func HashElemsKey(key *big.Int, elems ...*big.Int) (*Hash, error) {
|
||||
return NewHashFromBigInt(poseidonHash), nil
|
||||
}
|
||||
|
||||
// BigIntsToPoseidonInput takes *big.Ints and returns a fixed-length array of the size `poseidon.T`
|
||||
func BigIntsToPoseidonInput(bigints ...*big.Int) ([poseidon.T]*big.Int, error) {
|
||||
z := big.NewInt(0)
|
||||
b := [poseidon.T]*big.Int{z, z, z, z, z, z}
|
||||
|
||||
Reference in New Issue
Block a user