Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor clean up #5284

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions prdoc/pr_5284.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Minor clean up
author: conr2d
topic: runtime

crates:
- name: sp-runtime
bump: none
31 changes: 11 additions & 20 deletions substrate/primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,34 +438,25 @@ impl TryFrom<MultiSigner> for ecdsa::Public {
#[cfg(feature = "std")]
impl std::fmt::Display for MultiSigner {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Self::Ed25519(ref who) => write!(fmt, "ed25519: {}", who),
Self::Sr25519(ref who) => write!(fmt, "sr25519: {}", who),
Self::Ecdsa(ref who) => write!(fmt, "ecdsa: {}", who),
match self {
Self::Ed25519(who) => write!(fmt, "ed25519: {}", who),
Self::Sr25519(who) => write!(fmt, "sr25519: {}", who),
Self::Ecdsa(who) => write!(fmt, "ecdsa: {}", who),
}
}
}

impl Verify for MultiSignature {
type Signer = MultiSigner;
fn verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &AccountId32) -> bool {
match (self, signer) {
(Self::Ed25519(ref sig), who) => match ed25519::Public::from_slice(who.as_ref()) {
Ok(signer) => sig.verify(msg, &signer),
Err(()) => false,
},
(Self::Sr25519(ref sig), who) => match sr25519::Public::from_slice(who.as_ref()) {
Ok(signer) => sig.verify(msg, &signer),
Err(()) => false,
},
(Self::Ecdsa(ref sig), who) => {
let who: [u8; 32] = *signer.as_ref();
match self {
Self::Ed25519(sig) => sig.verify(msg, &who.into()),
Self::Sr25519(sig) => sig.verify(msg, &who.into()),
Self::Ecdsa(sig) => {
let m = sp_io::hashing::blake2_256(msg.get());
match sp_io::crypto::secp256k1_ecdsa_recover_compressed(sig.as_ref(), &m) {
Ok(pubkey) =>
&sp_io::hashing::blake2_256(pubkey.as_ref()) ==
<dyn AsRef<[u8; 32]>>::as_ref(who),
_ => false,
}
sp_io::crypto::secp256k1_ecdsa_recover_compressed(sig.as_ref(), &m)
.map_or(false, |pubkey| sp_io::hashing::blake2_256(&pubkey) == who)
},
}
}
Expand Down
Loading