Closed drakstik closed 1 year ago
Changed my code to this instead:
// instantiate hash function
hFunc := hash.MIMC_BN254.New()
// create a eddsa key pair
privateKey, _ := eddsa.GenerateKey(rand.Reader)
publicKey := privateKey.PublicKey
// // generate a message (the size must be a multiple of the size of Fr)
// var _msg fr.Element
// _msg.SetRandom()
// msg := _msg.Marshal()
msg := []byte{0xde, 0xad, 0xf0, 0x0d}
var msgFr fr.Element
msgFr.SetBytes(msg)
msg = msgFr.Marshal()
// sign the message
signature, _ := privateKey.Sign(msg, hFunc)
// verifies signature
isValid, _ := publicKey.Verify(signature, msg, hFunc)
if !isValid {
fmt.Println("1. invalid signature")
} else {
fmt.Println("1. valid signature")
}```
And that did the trick. Sorry for the silly question :)
I had issues with eddsa.GenerateKey(), changed it to gnark-crypto's eddsa.New(). Have to import "github.com/consensys/gnark-crypto/signature/eddsa"
import ceddsa "github.com/consensys/gnark-crypto/signature/eddsa"
// instantiate hash function
hFunc := hash.MIMC_BN254.New()
// create a eddsa key pair
privateKey, _ := ceddsa.New(1, rand.Reader) // secret
publicKey := privateKey.Public()
// generate a message (the size must be a multiple of the size of Fr)
msg := []byte{0xde, 0xad, 0xf0, 0x0d}
var msgFr fr.Element
msgFr.SetBytes(msg)
msg = msgFr.Marshal()
// sign the message
signature, _ := privateKey.Sign(msg, hFunc)
// verifies signature
isValid, _ := publicKey.Verify(signature, msg, hFunc)
if !isValid {
fmt.Println("1. invalid signature")
} else {
fmt.Println("1. valid signature")
}
So I'm trying something that seems like it should be working, but do not know why I get the output I get. Any help would be appreciated.
In my main function I run:
I get this output, which seems to me like it is not working appropriately. Would appreciate any help with understanding why the signature is invalid and why I get those two errors.