add nim ffi and genffi build task
This commit is contained in:
parent
63188ae1a4
commit
d3e667e758
|
@ -0,0 +1,4 @@
|
|||
|
||||
task genffi, "update the nim ffi bindings":
|
||||
exec "cargo install --force nbindgen"
|
||||
exec "nbindgen --crate codex-storage-proofs --output codex_proofs_ffi.nim"
|
|
@ -0,0 +1,57 @@
|
|||
const EXT_ID_U256_BE* = 51
|
||||
|
||||
const EXT_ID_U256_LE* = 50
|
||||
|
||||
|
||||
type StorageProofs* {.incompleteStruct.} = object
|
||||
|
||||
type Buffer* = object
|
||||
data: ptr uint8
|
||||
len: uint
|
||||
|
||||
type ProofCtx* = object
|
||||
proof: Buffer
|
||||
public_inputs: Buffer
|
||||
|
||||
## # Safety
|
||||
#
|
||||
# Use on a valid pointer to ProofCtx or panics
|
||||
proc free_proof_ctx*(ctx: ptr ProofCtx) {.importc: "free_proof_ctx".}
|
||||
|
||||
## # Safety
|
||||
#
|
||||
# Use on a valid pointer to StorageProofs or panics
|
||||
proc free_prover*(prover: ptr StorageProofs) {.importc: "free_prover".}
|
||||
|
||||
## # Safety
|
||||
#
|
||||
# Construct a StorageProofs object
|
||||
proc init*(r1cs: ptr (ptr Buffer),
|
||||
wasm: ptr (ptr Buffer),
|
||||
zkey: ptr (ptr Buffer)): (ptr StorageProofs) {.importc: "init".}
|
||||
|
||||
## # Safety
|
||||
#
|
||||
# Use after constructing a StorageProofs object with init
|
||||
proc prove*(prover_ptr: ptr StorageProofs,
|
||||
chunks: ptr Buffer,
|
||||
siblings: ptr Buffer,
|
||||
hashes: ptr Buffer,
|
||||
path: ptr int32,
|
||||
path_len: uint,
|
||||
pubkey: ptr Buffer,
|
||||
root: ptr Buffer,
|
||||
salt: ptr Buffer): (ptr ProofCtx) {.importc: "prove".}
|
||||
|
||||
## # Safety
|
||||
#
|
||||
# Use after constructing a StorageProofs object with init
|
||||
proc prove_mpack_ext*(prover_ptr: ptr StorageProofs,
|
||||
args: ptr Buffer): (ptr ProofCtx) {.importc: "prove_mpack_ext".}
|
||||
|
||||
## # Safety
|
||||
#
|
||||
# Should be called on a valid proof and public inputs previously generated by prove
|
||||
proc verify*(prover_ptr: ptr StorageProofs,
|
||||
proof: ptr Buffer,
|
||||
public_inputs: ptr Buffer): bool {.importc: "verify".}
|
|
@ -20,3 +20,5 @@ static:
|
|||
|
||||
|
||||
{.passl: "-lcodex_storage_proofs" & " -L" & libDir.}
|
||||
|
||||
proc prove_mpack_ext()
|
||||
|
|
|
@ -7,3 +7,5 @@ srcDir = "."
|
|||
# Dependencies
|
||||
|
||||
requires "nim >= 1.6.14"
|
||||
|
||||
include "build.nims"
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
include "build.nims"
|
Loading…
Reference in New Issue