Fix beefy mock ecdsa keys (#10854)

Compressed ECDSA keys requires to have 0x02 or 0x03 as their first byte
in order to allow public key recovery.

Nevertheless the test was working because of the `unwrap_or_default()`
at the end of the conversion routine (i.e. the invalid keys were
converted to an empty vector).
This commit is contained in:
Davide Galassi
2022-02-15 14:19:39 +01:00
committed by GitHub
parent 4519145df5
commit 6f53b974b2
3 changed files with 14 additions and 8 deletions
+5 -2
View File
@@ -158,9 +158,12 @@ impl pallet_session::SessionManager<u64> for MockSessionManager {
// Note, that we can't use `UintAuthorityId` here. Reason is that the implementation
// of `to_public_key()` assumes, that a public key is 32 bytes long. This is true for
// ed25519 and sr25519 but *not* for ecdsa. An ecdsa public key is 33 bytes.
// ed25519 and sr25519 but *not* for ecdsa. A compressed ecdsa public key is 33 bytes,
// with the first one containing information to reconstruct the uncompressed key.
pub fn mock_beefy_id(id: u8) -> BeefyId {
let buf: [u8; 33] = [id; 33];
let mut buf: [u8; 33] = [id; 33];
// Set to something valid.
buf[0] = 0x02;
let pk = Public::from_raw(buf);
BeefyId::from(pk)
}