diff --git a/Makefile b/Makefile index 1061d59..0474079 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ .PHONY: rlnlib + rlnlib: cd lib/rln && cargo build --release - cp lib/rln/target/release/librln.* lib/ + cbindgen --config ../cbindgen.toml --crate rln --output librln.h --lang c + mv lib/rln/target/release/librln.* lib/ # @TODO TARGET FOR BINDINGS. \ No newline at end of file diff --git a/lib/librln.h b/lib/librln.h index 2394ac7..8cca80a 100644 --- a/lib/librln.h +++ b/lib/librln.h @@ -1,37 +1,35 @@ -#include -#include -#include -#include -#include +#include +#include +#include +#include -template -struct RLN; +typedef struct RLN_Bn256 RLN_Bn256; -/// Buffer struct is taken from -/// https://github.com/celo-org/celo-threshold-bls-rs/blob/master/crates/threshold-bls-ffi/src/ffi.rs -struct Buffer { +/** + * Buffer struct is taken from + * https://github.com/celo-org/celo-threshold-bls-rs/blob/master/crates/threshold-bls-ffi/src/ffi.rs + */ +typedef struct Buffer { const uint8_t *ptr; uintptr_t len; -}; - -extern "C" { +} Buffer; bool new_circuit_from_params(uintptr_t merkle_depth, - const Buffer *parameters_buffer, - RLN **ctx); + const struct Buffer *parameters_buffer, + struct RLN_Bn256 **ctx); -bool generate_proof(const RLN *ctx, const Buffer *input_buffer, Buffer *output_buffer); +bool generate_proof(const struct RLN_Bn256 *ctx, + const struct Buffer *input_buffer, + struct Buffer *output_buffer); -bool verify(const RLN *ctx, - const Buffer *proof_buffer, - const Buffer *public_inputs_buffer, +bool verify(const struct RLN_Bn256 *ctx, + const struct Buffer *proof_buffer, + const struct Buffer *public_inputs_buffer, uint32_t *result_ptr); -bool hash(const RLN *ctx, - const Buffer *inputs_buffer, +bool hash(const struct RLN_Bn256 *ctx, + const struct Buffer *inputs_buffer, const uintptr_t *input_len, - Buffer *output_buffer); + struct Buffer *output_buffer); -bool key_gen(const RLN *ctx, Buffer *keypair_buffer); - -} // extern "C" +bool key_gen(const struct RLN_Bn256 *ctx, struct Buffer *keypair_buffer); diff --git a/rln.go b/rln.go index 2c65ab1..23d708c 100644 --- a/rln.go +++ b/rln.go @@ -1,12 +1,11 @@ package main /* -//#cgo CFLAGS: -I../lib -#cgo LDFLAGS: -L./lib -llibrnl +#cgo CFLAGS: -I../lib #include "./lib/librln.h" */ import "C" func main() { - C.verify() + //C }