mirror of https://github.com/waku-org/go-rln.git
fix
This commit is contained in:
parent
3482f3b885
commit
e5d478e09f
39
rln/rln.go
39
rln/rln.go
|
@ -42,6 +42,26 @@ func New(depth int, parameters []byte) (*RLN, error) {
|
||||||
return r, nil
|
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 {
|
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 := (*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))
|
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 {
|
func (r *RLN) Verify(proof []byte, publicInputs []byte, result uint32) bool {
|
||||||
proofBuf := toBuffer(proof)
|
proofBuf := toBuffer(proof)
|
||||||
inputs := toBuffer(publicInputs)
|
inputs := toBuffer(publicInputs)
|
||||||
|
|
Loading…
Reference in New Issue