Define a `CustomVerify` trait for signatures
Context:
Beefy introduces some cryptographic types here. The current underlying crypto scheme used is ECDSA, but the idea is to be able to use these types as beefy_primitives::crypto::Public, beefy_primitives::crypto::Signature, etc, without caring about the underlying crypto scheme ( ideally it should be possible for the underlying crypto scheme to be changed without impacting the code that uses these types).
The problem is that I couldn't find any generic way to check that a beefy authority signature is valid without calling sp_core::ecdsa::Pair::verify_prehashed() or sp_io::crypto::secp256k1_ecdsa_recover_compressed(), so we would need to use ECDSA specifically.
Description of changes:
This PR defines a CustomVerify trait (for signatures) and implements it for the ECDSA signature.
This is a more customizable version of the Verify trait, that enables the caller to provide a msg hashing function and a conversion function for the signer.
This trait probably doesn't make sense for all signature schemes, but I think it should be implemented by the underlying signature scheme of beefy_primitives::crypto::Signature.
With these new abstractions we can do something like:
CustomVerify::<Keccak256, _, Identity>::custom_verify(
sig.as_inner_ref(),
message,
public.as_inner_ref(),
)
instead of calling ECDSA logic specifically.
Notes:
I'm not super familiar with signature schemes so I'm not sure if this approach is the one that makes the most sense and if this trait could bring any value for other signature schemes as well. I thought about it a bit and in the end I implemented it like this since it seems to help with the MultiSignature validation as well, reducing the code duplication. But worst case scenario we could implement a function that does this in the beefy_primitives::crypto module directly.
Related to: https://github.com/paritytech/parity-bridges-common/issues/1574