mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 05:51:02 +00:00
Replace libsecp256k1 with k256 in FRAME related code (#10883)
* Replace libsecp256k1 with k256 in beefy-mmr * Port of FRAME `contracts` benchmarking from `libsecp256k1` to `k256` * Newtype to allow `Pcg32` rng usage with `k256` in contracts benchmarks * Use `sp-io::crypto` to generate dummy keys in `contracts` bechmarks * More compact code * Cargo fmt * Build `sp-keystore` only for dev profile * Move public key generation back to the `map`
This commit is contained in:
@@ -72,21 +72,20 @@ where
|
||||
pub struct BeefyEcdsaToEthereum;
|
||||
impl Convert<beefy_primitives::crypto::AuthorityId, Vec<u8>> for BeefyEcdsaToEthereum {
|
||||
fn convert(a: beefy_primitives::crypto::AuthorityId) -> Vec<u8> {
|
||||
use k256::{elliptic_curve::sec1::ToEncodedPoint, PublicKey};
|
||||
use sp_core::crypto::ByteArray;
|
||||
let compressed_key = a.as_slice();
|
||||
|
||||
libsecp256k1::PublicKey::parse_slice(
|
||||
compressed_key,
|
||||
Some(libsecp256k1::PublicKeyFormat::Compressed),
|
||||
)
|
||||
// uncompress the key
|
||||
.map(|pub_key| pub_key.serialize().to_vec())
|
||||
// now convert to ETH address
|
||||
.map(|uncompressed| sp_io::hashing::keccak_256(&uncompressed[1..])[12..].to_vec())
|
||||
.map_err(|_| {
|
||||
log::error!(target: "runtime::beefy", "Invalid BEEFY PublicKey format!");
|
||||
})
|
||||
.unwrap_or_default()
|
||||
PublicKey::from_sec1_bytes(a.as_slice())
|
||||
.map(|pub_key| {
|
||||
// uncompress the key
|
||||
let uncompressed = pub_key.to_encoded_point(false);
|
||||
// convert to ETH address
|
||||
sp_io::hashing::keccak_256(&uncompressed.as_bytes()[1..])[12..].to_vec()
|
||||
})
|
||||
.map_err(|_| {
|
||||
log::error!(target: "runtime::beefy", "Invalid BEEFY PublicKey format!");
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user