diff --git a/Cargo.lock b/Cargo.lock index 88513718b0dd1..8b96a7367967c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -462,12 +462,6 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" -[[package]] -name = "base64ct" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "874f8444adcb4952a8bc51305c8be95c8ec8237bb0d2e78d2e039f771f8828a0" - [[package]] name = "beef" version = "0.5.1" @@ -5665,7 +5659,6 @@ dependencies = [ "frame-system", "hex", "hex-literal", - "k256", "log 0.4.14", "pallet-beefy", "pallet-mmr", @@ -7073,17 +7066,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkcs8" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" -dependencies = [ - "der", - "spki", - "zeroize", -] - [[package]] name = "pkg-config" version = "0.3.19" @@ -9263,7 +9245,6 @@ checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" dependencies = [ "der", "generic-array 0.14.4", - "pkcs8", "subtle", "zeroize", ] @@ -10476,16 +10457,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "spki" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" -dependencies = [ - "base64ct", - "der", -] - [[package]] name = "ss58-registry" version = "1.11.0" diff --git a/frame/beefy-mmr/Cargo.toml b/frame/beefy-mmr/Cargo.toml index 19703fa79863a..bf72e295c478f 100644 --- a/frame/beefy-mmr/Cargo.toml +++ b/frame/beefy-mmr/Cargo.toml @@ -10,7 +10,6 @@ repository = "https://github.com/paritytech/substrate" [dependencies] hex = { version = "0.4", optional = true } codec = { version = "3.0.0", package = "parity-scale-codec", default-features = false, features = ["derive"] } -k256 = { version = "0.10.2", default-features = false, features = ["arithmetic"] } log = { version = "0.4.13", default-features = false } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } @@ -43,7 +42,6 @@ std = [ "frame-support/std", "frame-system/std", "hex", - "k256/std", "log/std", "pallet-beefy/std", "pallet-mmr-primitives/std", diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index c213e5cc16813..129d6406cb595 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -46,7 +46,6 @@ dyn-clonable = { version = "0.9.0", optional = true } thiserror = { version = "1.0.30", optional = true } bitflags = "1.3" k256 = { version = "0.10.2", default-features = false, features = ["ecdsa"] } -sp-core-hashing = { version = "4.0.0", default-features = false, path = "./hashing" } # full crypto ed25519-dalek = { version = "1.0.1", default-features = false, features = ["u64_backend", "alloc"], optional = true } @@ -60,6 +59,7 @@ libsecp256k1 = { version = "0.7", default-features = false, features = ["static- merlin = { version = "2.0", default-features = false, optional = true } secp256k1 = { version = "0.21.2", default-features = false, features = ["recovery", "alloc"], optional = true } ss58-registry = { version = "1.11.0", default-features = false } +sp-core-hashing = { version = "4.0.0", path = "./hashing", default-features = false, optional = true } sp-runtime-interface = { version = "6.0.0", default-features = false, path = "../runtime-interface" } [dev-dependencies] @@ -134,6 +134,7 @@ full_crypto = [ "hex", "libsecp256k1", "secp256k1", + "sp-core-hashing", "sp-runtime-interface/disable_target_static_assertions", "merlin", ] diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index 717246f5a2aae..3832ea21738f3 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -59,6 +59,7 @@ pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"ecds"); type Seed = [u8; 32]; /// The ECDSA compressed public key. +#[cfg_attr(feature = "full_crypto", derive(Hash))] #[derive( Clone, Copy, @@ -71,7 +72,6 @@ type Seed = [u8; 32]; PartialEq, PartialOrd, Ord, - Hash, )] pub struct Public(pub [u8; 33]); @@ -103,8 +103,7 @@ impl Public { /// Converts self into Ethereum address pub fn to_eth_address(&self) -> Result<[u8; 20], ()> { - use crate::hashing::keccak_256; - use k256::{elliptic_curve::sec1::ToEncodedPoint, PublicKey}; + use k256::{elliptic_curve::sec1::ToEncodedPoint, PublicKey}; PublicKey::from_sec1_bytes(self.as_slice()) .map(|pub_key| { @@ -112,7 +111,7 @@ impl Public { let uncompressed = pub_key.to_encoded_point(false); // convert to ETH address let res: [u8; 20] = - keccak_256(&uncompressed.as_bytes()[1..])[12..].try_into().unwrap(); + sp_io::hashing::keccak_256(&uncompressed.as_bytes()[1..])[12..].try_into().unwrap(); res }) .map_err(|_| ()) diff --git a/primitives/core/src/lib.rs b/primitives/core/src/lib.rs index 36eca35d7fdfb..b7c8b69e8a0ab 100644 --- a/primitives/core/src/lib.rs +++ b/primitives/core/src/lib.rs @@ -48,11 +48,11 @@ pub use sp_debug_derive::RuntimeDebug; #[cfg(feature = "std")] pub use impl_serde::serialize as bytes; +#[cfg(feature = "full_crypto")] pub mod hashing; -pub use hashing::keccak_256; #[cfg(feature = "full_crypto")] -pub use hashing::{blake2_128, blake2_256, twox_128, twox_256, twox_64}; +pub use hashing::{blake2_128, blake2_256, keccak_256, twox_128, twox_256, twox_64}; pub mod crypto; pub mod hexdisplay;