Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
beefy: small simplifications
Browse files Browse the repository at this point in the history
Signed-off-by: Serban Iorga <serban@parity.io>
  • Loading branch information
serban300 committed Sep 19, 2022
1 parent ee405e0 commit c418cb1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions client/beefy/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use sp_application_crypto::RuntimeAppPublic;
use sp_application_crypto::{RuntimeAppPublic, Wraps};
use sp_core::keccak_256;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use sp_runtime::traits::{CustomVerify, Identity, Keccak256};

use log::warn;

Expand Down Expand Up @@ -98,11 +99,11 @@ impl BeefyKeystore {
///
/// Return `true` if the signature is authentic, `false` otherwise.
pub fn verify(public: &Public, sig: &Signature, message: &[u8]) -> bool {
let msg = keccak_256(message);
let sig = sig.as_ref();
let public = public.as_ref();

sp_core::ecdsa::Pair::verify_prehashed(sig, &msg, public)
CustomVerify::<Keccak256, _, Identity>::custom_verify(
sig.as_inner_ref(),
message,
public.as_inner_ref(),
)
}
}

Expand Down
8 changes: 2 additions & 6 deletions frame/beefy-mmr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ where
/// Convert BEEFY secp256k1 public keys into Ethereum addresses
pub struct BeefyEcdsaToEthereum;
impl Convert<beefy_primitives::crypto::AuthorityId, Vec<u8>> for BeefyEcdsaToEthereum {
fn convert(a: beefy_primitives::crypto::AuthorityId) -> Vec<u8> {
sp_core::ecdsa::Public::try_from(a.as_ref())
.map_err(|_| {
log::error!(target: "runtime::beefy", "Invalid BEEFY PublicKey format!");
})
.unwrap_or(sp_core::ecdsa::Public::from_raw([0u8; 33]))
fn convert(beefy_id: beefy_primitives::crypto::AuthorityId) -> Vec<u8> {
sp_core::ecdsa::Public::from(beefy_id)
.to_eth_address()
.map(|v| v.to_vec())
.map_err(|_| {
Expand Down
5 changes: 5 additions & 0 deletions primitives/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ pub trait IsWrappedBy<Outer>: From<Outer> + Into<Outer> {
pub trait Wraps: Sized {
/// The inner type it is wrapping.
type Inner: IsWrappedBy<Self>;

/// Get a reference to the inner type that is wrapped.
fn as_inner_ref(&self) -> &Self::Inner {
Self::Inner::from_ref(self)
}
}

impl<T, Outer> IsWrappedBy<Outer> for T
Expand Down

0 comments on commit c418cb1

Please sign in to comment.