added cbindgen

This commit is contained in:
decanus 2021-09-13 16:42:26 +02:00
parent a69c11dcff
commit 3faa61ce34
No known key found for this signature in database
GPG Key ID: 3730AAF5D6589867
3 changed files with 28 additions and 29 deletions

View File

@ -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.

View File

@ -1,37 +1,35 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
template<typename E = void>
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<Bn256> **ctx);
const struct Buffer *parameters_buffer,
struct RLN_Bn256 **ctx);
bool generate_proof(const RLN<Bn256> *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<Bn256> *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<Bn256> *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<Bn256> *ctx, Buffer *keypair_buffer);
} // extern "C"
bool key_gen(const struct RLN_Bn256 *ctx, struct Buffer *keypair_buffer);

5
rln.go
View File

@ -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
}