mirror of
https://github.com/waku-org/go-zerokit-rln.git
synced 2025-02-28 20:20:30 +00:00
parent
84d12e61d9
commit
88462cf654
@ -427,6 +427,14 @@ func (r *RLN) InsertMember(idComm IDCommitment, userMessageLimit uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RLN) InsertRawLeaf(rawLeaf MerkleNode) error {
|
||||
insertionSuccess := r.w.SetNextLeaf(rawLeaf[:])
|
||||
if !insertionSuccess {
|
||||
return errors.New("could not insert raw leaf")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Insert multiple members i.e., identity commitments starting from index
|
||||
// This proc is atomic, i.e., if any of the insertions fails, all the previous insertions are rolled back
|
||||
func (r *RLN) InsertMembers(index MembershipIndex, idComms []IDCommitment) error {
|
||||
|
@ -80,6 +80,37 @@ func (s *RLNSuite) TestInsertMember() {
|
||||
s.NoError(err)
|
||||
}
|
||||
|
||||
func (s *RLNSuite) TestInsertRawLeaf() {
|
||||
rln, err := NewRLN()
|
||||
s.NoError(err)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
// Generate a membership
|
||||
memKeys, err := rln.MembershipKeyGen(10)
|
||||
s.NoError(err)
|
||||
|
||||
// Calculate the leaf ourselves
|
||||
userMessageLimitBytes := SerializeUint32(memKeys.UserMessageLimit)
|
||||
hashedLeaf, err := rln.Poseidon(memKeys.IDCommitment[:], userMessageLimitBytes[:])
|
||||
s.NoError(err)
|
||||
|
||||
// Insert the leaf as it is
|
||||
err = rln.InsertRawLeaf(hashedLeaf)
|
||||
s.NoError(err)
|
||||
|
||||
// Get it from the tree
|
||||
retrievedLeaf, err := rln.GetLeaf(uint(i))
|
||||
s.NoError(err)
|
||||
|
||||
// Check the retrieved matches the one we added
|
||||
s.Equal(hashedLeaf, retrievedLeaf)
|
||||
|
||||
// Check tree size matches
|
||||
numLeaves := rln.LeavesSet()
|
||||
s.Equal(uint(i+1), numLeaves)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *RLNSuite) TestInsertMembers() {
|
||||
rln, err := NewRLN()
|
||||
s.NoError(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user