From e5d478e09fb4683da5e668c9a16c843ec9af1d92 Mon Sep 17 00:00:00 2001 From: decanus <7621705+decanus@users.noreply.github.com> Date: Mon, 13 Sep 2021 23:13:04 +0200 Subject: [PATCH] fix --- rln/rln.go | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/rln/rln.go b/rln/rln.go index 38bffcd..2b1f200 100644 --- a/rln/rln.go +++ b/rln/rln.go @@ -42,6 +42,26 @@ func New(depth int, parameters []byte) (*RLN, error) { return r, nil } +// GenerateKey generates a KeyPair for an RLN. +func (r *RLN) GenerateKey() (*KeyPair, error) { + buffer := toBuffer([]byte{}) + if !bool(C.key_gen(r.ptr, &buffer)) { + return nil, errors.New("failed to genenrate key") + } + + key := &KeyPair{ + Key: [32]byte{}, + Commitment: [32]byte{}, + } + + b := C.GoBytes(unsafe.Pointer(buffer.ptr), C.int(buffer.len)) + + copy(key.Key[:], b[:32]) + copy(key.Commitment[:], b[32:64]) + + return key, nil +} + func (r *RLN) Hash(input []byte) []byte { size := int(unsafe.Sizeof(C.Buffer{})) in := (*C.Buffer)(C.malloc(C.size_t(size))) @@ -66,25 +86,6 @@ func (r *RLN) GenerateProof(input, output []byte) bool { return bool(C.generate_proof(r.ptr, &inputBuf, &outputBuf)) } -func (r *RLN) GenerateKey() (*KeyPair, error) { - buffer := toBuffer([]byte{}) - if !bool(C.key_gen(r.ptr, &buffer)) { - return nil, errors.New("failed to genenrate key") - } - - key := &KeyPair{ - Key: [32]byte{}, - Commitment: [32]byte{}, - } - - b := C.GoBytes(unsafe.Pointer(buffer.ptr), C.int(buffer.len)) - - copy(key.Key[:], b[:32]) - copy(key.Commitment[:], b[:32]) - - return key, nil -} - func (r *RLN) Verify(proof []byte, publicInputs []byte, result uint32) bool { proofBuf := toBuffer(proof) inputs := toBuffer(publicInputs)