mirror of https://github.com/waku-org/go-rln.git
fix
This commit is contained in:
parent
2606c6d870
commit
c298e971b1
13
rln/rln.go
13
rln/rln.go
|
@ -6,6 +6,7 @@ package rln
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -13,7 +14,7 @@ type RLN struct {
|
|||
ptr *C.RLN_Bn256
|
||||
}
|
||||
|
||||
func New(depth int, parameters []byte) *RLN {
|
||||
func New(depth int, parameters []byte) (*RLN, error) {
|
||||
r := &RLN{}
|
||||
|
||||
buf := toBuffer(parameters)
|
||||
|
@ -22,9 +23,11 @@ func New(depth int, parameters []byte) *RLN {
|
|||
in := (*C.Buffer)(C.malloc(C.size_t(size)))
|
||||
*in = buf
|
||||
|
||||
C.new_circuit_from_params(C.ulong(depth), in, &r.ptr)
|
||||
if bool(C.new_circuit_from_params(C.ulong(depth), in, &r.ptr)) {
|
||||
return nil, errors.New("failed to initialize")
|
||||
}
|
||||
|
||||
return r
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (r *RLN) Hash(input []byte) []byte {
|
||||
|
@ -56,11 +59,11 @@ func (r *RLN) GenerateKey(buf []byte) bool {
|
|||
return bool(C.key_gen(r.ptr, &buffer))
|
||||
}
|
||||
|
||||
func (r *RLN) Verify(proof []byte, publicInputs []byte, result uint32) {
|
||||
func (r *RLN) Verify(proof []byte, publicInputs []byte, result uint32) bool {
|
||||
proofBuf := toBuffer(proof)
|
||||
inputs := toBuffer(publicInputs)
|
||||
res := C.uint(result)
|
||||
C.verify(r.ptr, &proofBuf, &inputs, &res)
|
||||
return bool(C.verify(r.ptr, &proofBuf, &inputs, &res))
|
||||
}
|
||||
|
||||
func toBuffer(data []byte) C.Buffer {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package rln
|
||||
package rln_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/decanus/go-rln/rln"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
|
@ -11,9 +13,8 @@ func TestNew(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rln := New(32, params)
|
||||
|
||||
if rln.ptr == nil {
|
||||
t.Fatal("pointer not initialized.")
|
||||
_, err = rln.New(32, params)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue