mirror of
https://github.com/logos-messaging/go-rln.git
synced 2026-01-07 15:33:11 +00:00
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 "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ type RLN struct {
|
|||||||
ptr *C.RLN_Bn256
|
ptr *C.RLN_Bn256
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(depth int, parameters []byte) *RLN {
|
func New(depth int, parameters []byte) (*RLN, error) {
|
||||||
r := &RLN{}
|
r := &RLN{}
|
||||||
|
|
||||||
buf := toBuffer(parameters)
|
buf := toBuffer(parameters)
|
||||||
@ -22,9 +23,11 @@ func New(depth int, parameters []byte) *RLN {
|
|||||||
in := (*C.Buffer)(C.malloc(C.size_t(size)))
|
in := (*C.Buffer)(C.malloc(C.size_t(size)))
|
||||||
*in = buf
|
*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 {
|
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))
|
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)
|
proofBuf := toBuffer(proof)
|
||||||
inputs := toBuffer(publicInputs)
|
inputs := toBuffer(publicInputs)
|
||||||
res := C.uint(result)
|
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 {
|
func toBuffer(data []byte) C.Buffer {
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
package rln
|
package rln_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/decanus/go-rln/rln"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
@ -11,9 +13,8 @@ func TestNew(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rln := New(32, params)
|
_, err = rln.New(32, params)
|
||||||
|
if err != nil {
|
||||||
if rln.ptr == nil {
|
t.Fatal(err)
|
||||||
t.Fatal("pointer not initialized.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user