Revert k256 removal (#14499)

* Revert "Remove k256 crate from frame-support dependencies (#14452)"

This reverts commit 4d426214af.

* Keep the test
This commit is contained in:
Bastian Köcher
2023-07-03 23:38:51 +02:00
committed by GitHub
parent fc36e04dfa
commit 79f600db70
4 changed files with 189 additions and 35 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ impl-trait-for-tuples = "0.2.2"
smallvec = "1.8.0"
log = { version = "0.4.17", default-features = false }
sp-core-hashing-proc-macro = { version = "9.0.0", path = "../../primitives/core/hashing/proc-macro" }
secp256k1 = { version = "0.24.0", default-features = false }
k256 = { version = "0.13.0", default-features = false, features = ["ecdsa"] }
environmental = { version = "1.1.4", default-features = false }
[dev-dependencies]
@@ -52,7 +52,7 @@ array-bytes = "4.1"
default = ["std"]
std = [
"sp-core/std",
"secp256k1/std",
"k256/std",
"serde/std",
"sp-api/std",
"sp-io/std",
+7 -5
View File
@@ -34,14 +34,16 @@ pub trait ECDSAExt {
impl ECDSAExt for Public {
fn to_eth_address(&self) -> Result<[u8; 20], ()> {
use secp256k1::PublicKey;
use k256::{elliptic_curve::sec1::ToEncodedPoint, PublicKey};
PublicKey::from_slice(self.as_slice()).map_err(drop).and_then(|pub_key| {
PublicKey::from_sec1_bytes(self.as_slice()).map_err(drop).and_then(|pub_key| {
// uncompress the key
let uncompressed = pub_key.serialize_uncompressed();
let uncompressed = pub_key.to_encoded_point(false);
// convert to ETH address
<[u8; 20]>::try_from(sp_io::hashing::keccak_256(&uncompressed[1..])[12..].as_ref())
.map_err(drop)
<[u8; 20]>::try_from(
sp_io::hashing::keccak_256(&uncompressed.as_bytes()[1..])[12..].as_ref(),
)
.map_err(drop)
})
}
}