Only support ECDSA compressed public keys (#4667)

Some fixes after: https://github.com/paritytech/substrate/pull/4502

This removes the unwanted `expect`s from `MultiSigner`. Instead we
convert from full to compressed in `TryFrom` and can return an error on
invalid input.
This commit is contained in:
Bastian Köcher
2020-01-20 17:28:27 +01:00
committed by Gavin Wood
parent 164dec95e5
commit 1f18964f01
3 changed files with 46 additions and 84 deletions
+2 -4
View File
@@ -238,9 +238,7 @@ impl traits::IdentifyAccount for MultiSigner {
match self {
MultiSigner::Ed25519(who) => <[u8; 32]>::from(who).into(),
MultiSigner::Sr25519(who) => <[u8; 32]>::from(who).into(),
MultiSigner::Ecdsa(who) => sp_io::hashing::blake2_256(
&who.as_compressed().expect("`who` is a valid `ECDSA` public key; qed")[..],
).into(),
MultiSigner::Ecdsa(who) => sp_io::hashing::blake2_256(&who.as_ref()[..]).into(),
}
}
}
@@ -724,7 +722,7 @@ mod tests {
let multi_signer = MultiSigner::from(pair.public());
assert!(multi_sig.verify(msg, &multi_signer.into_account()));
let multi_signer = MultiSigner::from(pair.public().into_compressed().unwrap());
let multi_signer = MultiSigner::from(pair.public());
assert!(multi_sig.verify(msg, &multi_signer.into_account()));
}
}
+2 -2
View File
@@ -102,7 +102,7 @@ impl Verify for sp_core::ecdsa::Signature {
self.as_ref(),
&sp_io::hashing::blake2_256(msg.get()),
) {
Ok(pubkey) => signer.as_compressed().map(|s| &s[..] == &pubkey[..]).unwrap_or(false),
Ok(pubkey) => &signer.as_ref()[..] == &pubkey[..],
_ => false,
}
}
@@ -1357,6 +1357,6 @@ mod tests {
assert!(ecdsa::Pair::verify(&signature, msg, &pair.public()));
assert!(signature.verify(msg, &pair.public()));
assert!(signature.verify(msg, &pair.public().into_compressed().unwrap()));
assert!(signature.verify(msg, &pair.public()));
}
}