package crypto import ( "testing" "github.com/stretchr/testify/assert" ) func TestSignAndValidateEd25519(t *testing.T) { privKey := GenPrivKeyEd25519() pubKey := privKey.PubKey() msg := CRandBytes(128) sig := privKey.Sign(msg) // Test the signature assert.True(t, pubKey.VerifyBytes(msg, sig)) // Mutate the signature, just one bit. sigEd := sig.(SignatureEd25519) sigEd[7] ^= byte(0x01) sig = sigEd assert.False(t, pubKey.VerifyBytes(msg, sig)) } func TestSignAndValidateSecp256k1(t *testing.T) { privKey := GenPrivKeySecp256k1() pubKey := privKey.PubKey() msg := CRandBytes(128) sig := privKey.Sign(msg) assert.True(t, pubKey.VerifyBytes(msg, sig)) // Mutate the signature, just one bit. sigEd := sig.(SignatureSecp256k1) sigEd[3] ^= byte(0x01) sig = sigEd assert.False(t, pubKey.VerifyBytes(msg, sig)) }