diff --git a/libs/x86_64-pc-windows-gnu/librln.a b/libs/x86_64-pc-windows-gnu/librln.a index 411751e..f695c19 100644 Binary files a/libs/x86_64-pc-windows-gnu/librln.a and b/libs/x86_64-pc-windows-gnu/librln.a differ diff --git a/libs/x86_64-unknown-linux-gnu/librln.a b/libs/x86_64-unknown-linux-gnu/librln.a index ec77799..98984e5 100644 Binary files a/libs/x86_64-unknown-linux-gnu/librln.a and b/libs/x86_64-unknown-linux-gnu/librln.a differ diff --git a/libs/x86_64-unknown-linux-musl/librln.a b/libs/x86_64-unknown-linux-musl/librln.a index d58075a..8c06737 100644 Binary files a/libs/x86_64-unknown-linux-musl/librln.a and b/libs/x86_64-unknown-linux-musl/librln.a differ diff --git a/rln/librln.h b/rln/librln.h index 60e4545..2aa3fca 100644 --- a/rln/librln.h +++ b/rln/librln.h @@ -39,6 +39,8 @@ bool delete_leaf(struct RLN *ctx, uintptr_t index); bool set_leaf(struct RLN *ctx, uintptr_t index, const struct Buffer *input_buffer); +bool get_leaf(struct RLN *ctx, uintptr_t index, struct Buffer *output_buffer); + bool set_next_leaf(struct RLN *ctx, const struct Buffer *input_buffer); bool set_leaves_from(struct RLN *ctx, uintptr_t index, const struct Buffer *input_buffer); @@ -88,6 +90,10 @@ bool recover_id_secret(const struct RLN *ctx, const struct Buffer *input_proof_buffer_2, struct Buffer *output_buffer); +bool set_metadata(struct RLN *ctx, const struct Buffer *input_buffer); + +bool get_metadata(const struct RLN *ctx, struct Buffer *output_buffer); + bool hash(const struct Buffer *input_buffer, struct Buffer *output_buffer); bool poseidon_hash(const struct Buffer *input_buffer, struct Buffer *output_buffer); 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..8a365f0 160000 --- a/zerokit +++ b/zerokit @@ -1 +1 @@ -Subproject commit c2d386cb749f551541bb34c4386a3849485356f9 +Subproject commit 8a365f0c9e5c4a744f70c5dd4904ce8d8f926c34