This commit is contained in:
decanus 2021-09-13 23:13:04 +02:00
parent 3482f3b885
commit e5d478e09f
No known key found for this signature in database
GPG Key ID: 3730AAF5D6589867
1 changed files with 20 additions and 19 deletions

View File

@ -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)