feat: getLeaf
This commit is contained in:
parent
86b06ba440
commit
a6fdbf1e35
6
go.mod
6
go.mod
|
@ -4,9 +4,9 @@ go 1.18
|
|||
|
||||
require (
|
||||
github.com/stretchr/testify v1.7.2
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230517215159-cea56434b07a
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230517214322-89b514ad7697
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230517190629-6d0c983d1080
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230731180145-6df4912fe348
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230731180026-8704c2036d2b
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230731175926-d7831a9c95e5
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
6
go.sum
6
go.sum
|
@ -19,14 +19,20 @@ github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327 h1:Q
|
|||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230517215159-cea56434b07a h1:YnpxsRnmQlFwouAdgtj95L/az32rlQ1Jtjx08CVx8tc=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230517215159-cea56434b07a/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230731180145-6df4912fe348 h1:PJC92jv0H3KX0ixVM//ferWlQUnVY1S4AtF3j5e0aOg=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230731180145-6df4912fe348/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230331223149-f90e66aebb0d h1:Kcg85Y2xGU6hqZ/kMfkLQF2jAog8vt+tw1/VNidzNtE=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230331223149-f90e66aebb0d/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230517214322-89b514ad7697 h1:ogFZsxT02kIbo5qHmGBiYPLmfduFVNJYKfz0ozQxI5E=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230517214322-89b514ad7697/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230731180026-8704c2036d2b h1:N87rp2TFcl/76HWdfV5f26Qc1QbtrDbs36QcPiNohvU=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230731180026-8704c2036d2b/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230331181847-cba74520bae9 h1:u+YUlWDltHiK5upSb7M6mStc84zdc4vTCNNOz7R5RaY=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230331181847-cba74520bae9/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230517190629-6d0c983d1080 h1:AO3Sv0ECsxGKdSUOuC4cfqVYtyjXZcKKwrY8lqQk+3g=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230517190629-6d0c983d1080/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230731175926-d7831a9c95e5 h1:yOvPC8M5XoTppHx9kgMfFOaK+k5+TWuQiY+YVBcgRdI=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230731175926-d7831a9c95e5/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
|
|
|
@ -55,6 +55,10 @@ func (i RLNWrapper) GetRoot() ([]byte, error) {
|
|||
return i.ffi.GetRoot()
|
||||
}
|
||||
|
||||
func (i RLNWrapper) GetLeaf(index uint) ([]byte, error) {
|
||||
return i.ffi.GetLeaf(index)
|
||||
}
|
||||
|
||||
func (i RLNWrapper) GenerateRLNProof(input []byte) ([]byte, error) {
|
||||
return i.ffi.GenerateRLNProof(input)
|
||||
}
|
||||
|
|
|
@ -54,6 +54,10 @@ func (i RLNWrapper) GetRoot() ([]byte, error) {
|
|||
return i.ffi.GetRoot()
|
||||
}
|
||||
|
||||
func (i RLNWrapper) GetLeaf(index uint) ([]byte, error) {
|
||||
return i.ffi.GetLeaf(index)
|
||||
}
|
||||
|
||||
func (i RLNWrapper) GenerateRLNProof(input []byte) ([]byte, error) {
|
||||
return i.ffi.GenerateRLNProof(input)
|
||||
}
|
||||
|
|
|
@ -55,6 +55,10 @@ func (i RLNWrapper) GetRoot() ([]byte, error) {
|
|||
return i.ffi.GetRoot()
|
||||
}
|
||||
|
||||
func (i RLNWrapper) GetLeaf(index uint) ([]byte, error) {
|
||||
return i.ffi.GetLeaf(index)
|
||||
}
|
||||
|
||||
func (i RLNWrapper) GenerateRLNProof(input []byte) ([]byte, error) {
|
||||
return i.ffi.GenerateRLNProof(input)
|
||||
}
|
||||
|
|
17
rln/rln.go
17
rln/rln.go
|
@ -328,6 +328,23 @@ func (r *RLN) GetMerkleRoot() (MerkleNode, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// GetLeaf reads the value stored at some index in the Merkle Tree
|
||||
func (r *RLN) GetLeaf(index MembershipIndex) (IDCommitment, error) {
|
||||
b, err := r.w.GetLeaf(index)
|
||||
if err != nil {
|
||||
return IDCommitment{}, err
|
||||
}
|
||||
|
||||
if len(b) != 32 {
|
||||
return IDCommitment{}, errors.New("wrong output size")
|
||||
}
|
||||
|
||||
var result IDCommitment
|
||||
copy(result[:], b)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// AddAll adds members to the Merkle tree
|
||||
func (r *RLN) AddAll(list []IDCommitment) error {
|
||||
for _, member := range list {
|
||||
|
|
|
@ -191,14 +191,18 @@ func (s *RLNSuite) TestValidProof() {
|
|||
s.NoError(err)
|
||||
|
||||
//peer's index in the Merkle Tree
|
||||
index := 5
|
||||
index := uint(5)
|
||||
|
||||
// Create a Merkle tree with random members
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := uint(0); i < 10; i++ {
|
||||
if i == index {
|
||||
// insert the current peer's pk
|
||||
err = rln.InsertMember(memKeys.IDCommitment)
|
||||
s.NoError(err)
|
||||
|
||||
fifthIndexLeaf, err := rln.GetLeaf(index)
|
||||
s.NoError(err)
|
||||
s.Equal(memKeys.IDCommitment, fifthIndexLeaf)
|
||||
} else {
|
||||
// create a new key pair
|
||||
memberKeys, err := rln.MembershipKeyGen()
|
||||
|
@ -206,6 +210,10 @@ func (s *RLNSuite) TestValidProof() {
|
|||
|
||||
err = rln.InsertMember(memberKeys.IDCommitment)
|
||||
s.NoError(err)
|
||||
|
||||
leaf, err := rln.GetLeaf(i)
|
||||
s.NoError(err)
|
||||
s.Equal(memberKeys.IDCommitment, leaf)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue