diff --git a/libs/aarch64-apple-darwin/librln.a b/libs/aarch64-apple-darwin/librln.a index e7b0e94..2018b53 100644 Binary files a/libs/aarch64-apple-darwin/librln.a and b/libs/aarch64-apple-darwin/librln.a differ diff --git a/libs/x86_64-apple-darwin/librln.a b/libs/x86_64-apple-darwin/librln.a index aa76dd3..9df1ba3 100644 Binary files a/libs/x86_64-apple-darwin/librln.a and b/libs/x86_64-apple-darwin/librln.a differ diff --git a/rln/wrapper.go b/rln/wrapper.go index 0d6c153..a23af4f 100644 --- a/rln/wrapper.go +++ b/rln/wrapper.go @@ -63,6 +63,27 @@ func NewWithFolder(depth int, resourcesFolderPath string) (*RLN, error) { return r, nil } +func (r *RLN) SetTree(treeHeight uint) bool { + return bool(C.set_tree(r.ptr, C.uintptr_t(treeHeight))) +} + +func (r *RLN) KeyGen() []byte { + buffer := toBuffer([]byte{}) + if !bool(C.key_gen(r.ptr, &buffer)) { + return nil + } + return C.GoBytes(unsafe.Pointer(buffer.ptr), C.int(buffer.len)) +} + +func (r *RLN) SeededKeyGen(seed []byte) []byte { + seedBuff := toCBufferPtr(seed) + buffer := toBuffer([]byte{}) + if !bool(C.seeded_key_gen(r.ptr, seedBuff, &buffer)) { + return nil + } + return C.GoBytes(unsafe.Pointer(buffer.ptr), C.int(buffer.len)) +} + func (r *RLN) ExtendedKeyGen() []byte { buffer := toBuffer([]byte{}) if !bool(C.extended_key_gen(r.ptr, &buffer)) { @@ -71,6 +92,29 @@ func (r *RLN) ExtendedKeyGen() []byte { return C.GoBytes(unsafe.Pointer(buffer.ptr), C.int(buffer.len)) } +func (r *RLN) ExtendedSeededKeyGen(seed []byte) []byte { + seedBuff := toCBufferPtr(seed) + buffer := toBuffer([]byte{}) + if !bool(C.seeded_extended_key_gen(r.ptr, seedBuff, &buffer)) { + return nil + } + return C.GoBytes(unsafe.Pointer(buffer.ptr), C.int(buffer.len)) +} + +func (r *RLN) RecoverIDSecret(proof1 []byte, proof2 []byte) ([]byte, error) { + proof1Buff := toCBufferPtr(proof1) + proof2Buff := toCBufferPtr(proof2) + + var output []byte + out := toBuffer(output) + + if !bool(C.recover_id_secret(r.ptr, proof1Buff, proof2Buff, &out)) { + return nil, errors.New("failed to hash") + } + + return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len)), nil +} + func (r *RLN) Hash(input []byte) ([]byte, error) { inpBuff := toCBufferPtr(input) @@ -122,6 +166,11 @@ func (r *RLN) VerifyWithRoots(input []byte, roots []byte) (bool, error) { return bool(res), nil } +func (r *RLN) SetLeaf(index uint, idcommitment []byte) bool { + buff := toCBufferPtr(idcommitment[:]) + return bool(C.set_leaf(r.ptr, C.uintptr_t(index), buff)) +} + func (r *RLN) SetNextLeaf(idcommitment []byte) bool { buff := toCBufferPtr(idcommitment[:]) return bool(C.set_next_leaf(r.ptr, buff)) @@ -132,6 +181,27 @@ func (r *RLN) SetLeavesFrom(index uint, idcommitments []byte) bool { return bool(C.set_leaves_from(r.ptr, C.uintptr_t(index), idCommBuffer)) } +func (r *RLN) InitTreeWithLeaves(idcommitments []byte) bool { + idCommBuffer := toCBufferPtr(idcommitments) + return bool(C.init_tree_with_leaves(r.ptr, idCommBuffer)) +} + +func (r *RLN) SetMetadata(metadata []byte) bool { + metadataBuffer := toCBufferPtr(metadata) + return bool(C.set_metadata(r.ptr, metadataBuffer)) +} + +func (r *RLN) GetMetadata() ([]byte, error) { + var output []byte + out := toBuffer(output) + + if !bool(C.get_metadata(r.ptr, &out)) { + return nil, errors.New("could not obtain the metadata") + } + + return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len)), nil +} + func (r *RLN) AtomicOperation(index uint, leaves []byte, indices []byte) bool { leavesBuffer := toCBufferPtr(leaves) indicesBuffer := toCBufferPtr(indices) diff --git a/zerokit b/zerokit index c2d386c..9d4ed68 160000 --- a/zerokit +++ b/zerokit @@ -1 +1 @@ -Subproject commit c2d386cb749f551541bb34c4386a3849485356f9 +Subproject commit 9d4ed68450e20626081e24490ba320278f6d3f7b