mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
Make MultiSigner use compressed ECDSA public key (#4502)
* Don't use compressed ecdsa public key in verify * Make `ECDSA` public support compressed * Make it a proper `expect` message
This commit is contained in:
committed by
Gavin Wood
parent
585f0c0811
commit
8ecc450fd9
@@ -212,7 +212,7 @@ pub enum MultiSigner {
|
||||
Ed25519(ed25519::Public),
|
||||
/// An Sr25519 identity.
|
||||
Sr25519(sr25519::Public),
|
||||
/// An SECP256k1/ECDSA identity (actually, the Blake2 hash of the pub key).
|
||||
/// An SECP256k1/ECDSA identity (actually, the Blake2 hash of the compressed pub key).
|
||||
Ecdsa(ecdsa::Public),
|
||||
}
|
||||
|
||||
@@ -246,7 +246,9 @@ 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_ref()).into(),
|
||||
MultiSigner::Ecdsa(who) => sp_io::hashing::blake2_256(
|
||||
&who.as_compressed().expect("`who` is a valid `ECDSA` public key; qed")[..],
|
||||
).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -688,8 +690,9 @@ pub fn print(print: impl traits::Printable) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::DispatchError;
|
||||
use super::*;
|
||||
use codec::{Encode, Decode};
|
||||
use sp_core::crypto::Pair;
|
||||
|
||||
#[test]
|
||||
fn opaque_extrinsic_serialization() {
|
||||
@@ -716,4 +719,20 @@ mod tests {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_signature_ecdsa_verify_works() {
|
||||
let msg = &b"test-message"[..];
|
||||
let (pair, _) = ecdsa::Pair::generate();
|
||||
|
||||
let signature = pair.sign(&msg);
|
||||
assert!(ecdsa::Pair::verify(&signature, msg, &pair.public()));
|
||||
|
||||
let multi_sig = MultiSignature::from(signature);
|
||||
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());
|
||||
assert!(multi_sig.verify(msg, &multi_signer.into_account()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user