2021-02-10 20:51:41 +00:00
|
|
|
# this module contains the Nim wrappers for the rln library https://github.com/kilic/rln/blob/3bbec368a4adc68cd5f9bfae80b17e1bbb4ef373/src/ffi.rs
|
|
|
|
|
2021-02-12 20:12:10 +00:00
|
|
|
import os
|
2021-02-10 20:51:41 +00:00
|
|
|
|
2021-03-02 20:57:48 +00:00
|
|
|
|
|
|
|
const libPath = "vendor/rln/target/debug/"
|
2021-02-12 20:12:10 +00:00
|
|
|
when defined(Windows):
|
|
|
|
const libName* = libPath / "rln.dll"
|
|
|
|
elif defined(Linux):
|
|
|
|
const libName* = libPath / "librln.so"
|
|
|
|
elif defined(MacOsX):
|
|
|
|
const libName* = libPath / "librln.dylib"
|
2021-02-10 20:51:41 +00:00
|
|
|
|
|
|
|
# all the following procedures are Nim wrappers for the functions defined in libName
|
|
|
|
{.push dynlib: libName.}
|
|
|
|
|
2021-03-24 17:26:56 +00:00
|
|
|
type RLN*[E] {.incompleteStruct.} = object
|
|
|
|
type Bn256* = pointer
|
2021-02-10 20:51:41 +00:00
|
|
|
|
2021-03-24 17:26:56 +00:00
|
|
|
## Buffer struct is taken from
|
|
|
|
# https://github.com/celo-org/celo-threshold-bls-rs/blob/master/crates/threshold-bls-ffi/src/ffi.rs
|
|
|
|
type Buffer* = object
|
|
|
|
`ptr`*: ptr uint8
|
|
|
|
len*: uint
|
2021-02-10 20:51:41 +00:00
|
|
|
|
2021-03-24 17:26:56 +00:00
|
|
|
proc key_gen*(ctx: ptr RLN[Bn256], keypair_buffer: ptr Buffer): bool {.importc: "key_gen".}
|
2021-02-10 20:51:41 +00:00
|
|
|
|
2021-03-24 17:26:56 +00:00
|
|
|
proc new_circuit_from_params*(merkle_depth: uint,
|
|
|
|
parameters_buffer: ptr Buffer,
|
|
|
|
ctx: ptr (ptr RLN[Bn256])): bool {.importc: "new_circuit_from_params".}
|
2021-02-10 20:51:41 +00:00
|
|
|
|
2021-03-24 17:26:56 +00:00
|
|
|
#------------------------------Merkle Tree operations -----------------------------------------
|
|
|
|
proc update_next_member*(ctx: ptr RLN[Bn256],
|
|
|
|
input_buffer: ptr Buffer): bool {.importc: "update_next_member".}
|
2021-02-10 20:51:41 +00:00
|
|
|
|
2021-03-24 17:26:56 +00:00
|
|
|
proc delete_member*(ctx: ptr RLN[Bn256], index: uint): bool {.importc: "delete_member".}
|
2021-02-10 20:51:41 +00:00
|
|
|
|
2021-03-24 17:26:56 +00:00
|
|
|
proc get_root*(ctx: ptr RLN[Bn256], output_buffer: ptr Buffer): bool {.importc: "get_root".}
|
|
|
|
#----------------------------------------------------------------------------------------------
|
2021-02-10 20:51:41 +00:00
|
|
|
|
2021-03-16 18:18:40 +00:00
|
|
|
{.pop.}
|