package crypto import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestSignAndValidateEd25519(t *testing.T) { privKey := GenPrivKeyEd25519() pubKey := privKey.PubKey() msg := CRandBytes(128) sig, err := privKey.Sign(msg) require.Nil(t, err) // 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, err := privKey.Sign(msg) require.Nil(t, err) 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)) }