diff --git a/rln/rln.go b/rln/rln.go index 0b423fe..bc5d617 100644 --- a/rln/rln.go +++ b/rln/rln.go @@ -13,14 +13,22 @@ type RLN struct { ptr *C.RLN_Bn256 } +func New(depth int, parameters []byte) *RLN { + r := &RLN{} + + buf := toBuffer(parameters) + C.new_circuit_from_params(C.ulong(depth), &buf, &r.ptr) + + return r +} + func (r *RLN) Hash(input []byte) []byte { size := int(unsafe.Sizeof(C.Buffer{})) - - size = int(unsafe.Sizeof(C.Buffer{})) in := (*C.Buffer)(C.malloc(C.size_t(size))) + *in = toBuffer(input) out := (*C.Buffer)(C.malloc(C.size_t(size))) - C.hash(r.ptr, in, size, out) + C.hash(r.ptr, in, &in.len, out) return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len)) } diff --git a/rln/rln_test.go b/rln/rln_test.go index 681f6e4..be1cd0e 100644 --- a/rln/rln_test.go +++ b/rln/rln_test.go @@ -1,8 +1,10 @@ package rln -import "testing" +import ( + "testing" +) func TestHash(t *testing.T) { - rln := &RLN{} + rln := New(0, []byte{}) rln.Hash([]byte{1, 2, 3}) }