From 98c4c0135b7c724ac9c87394b674be594393ccff Mon Sep 17 00:00:00 2001 From: James Wilson Date: Thu, 21 Mar 2024 15:18:00 +0000 Subject: [PATCH] chore: rename sp-core-hashing to sp-crypto-hashing (#1490) * rename sp-core-hashing to sp-crypto-hashing * fmt --- .github/dependabot.yml | 4 ++-- Cargo.lock | 20 +++++++++++++++++--- Cargo.toml | 2 +- examples/parachain-example/Cargo.lock | 8 ++++---- examples/wasm-example/Cargo.lock | 6 +++--- metadata/Cargo.toml | 2 +- metadata/src/utils/validation.rs | 2 +- signer/Cargo.toml | 4 ++-- signer/src/crypto/derive_junction.rs | 2 +- signer/src/ecdsa.rs | 8 ++++---- subxt/Cargo.toml | 2 +- subxt/src/config/substrate.rs | 2 +- subxt/src/events/events_client.rs | 4 ++-- subxt/src/storage/storage_type.rs | 6 ++++-- subxt/src/storage/utils.rs | 16 ++++++++-------- subxt/src/tx/tx_client.rs | 2 +- testing/no-std-tests/Cargo.lock | 6 +++--- testing/wasm-lightclient-tests/Cargo.lock | 6 +++--- testing/wasm-rpc-tests/Cargo.lock | 6 +++--- 19 files changed, 62 insertions(+), 46 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1ccfdde27c..e36427e4ae 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,12 +5,12 @@ updates: schedule: interval: weekly ignore: - # these need to be updated together, so dependabot PRs + # these need to be updated together, so dependabot PRs # are just noise. So, ignore them: - dependency-name: sp-core - dependency-name: sp-keyring - dependency-name: sp-runtime - - dependency-name: sp-core-hashing + - dependency-name: sp-crypto-hashing - dependency-name: sp-version - package-ecosystem: github-actions directory: '/' diff --git a/Cargo.lock b/Cargo.lock index 36324ef1df..d0e71df7bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4150,6 +4150,20 @@ dependencies = [ "twox-hash", ] +[[package]] +name = "sp-crypto-hashing" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc9927a7f81334ed5b8a98a4a978c81324d12bd9713ec76b5c68fd410174c5eb" +dependencies = [ + "blake2b_simd", + "byteorder", + "digest 0.10.7", + "sha2 0.10.8", + "sha3", + "twox-hash", +] + [[package]] name = "sp-debug-derive" version = "14.0.0" @@ -4539,7 +4553,7 @@ dependencies = [ "serde", "serde_json", "sp-core", - "sp-core-hashing", + "sp-crypto-hashing", "sp-keyring", "sp-runtime", "subxt-lightclient", @@ -4653,7 +4667,7 @@ dependencies = [ "hashbrown 0.14.3", "parity-scale-codec", "scale-info", - "sp-core-hashing", + "sp-crypto-hashing", ] [[package]] @@ -4674,7 +4688,7 @@ dependencies = [ "secrecy", "sha2 0.10.8", "sp-core", - "sp-core-hashing", + "sp-crypto-hashing", "sp-keyring", "subxt", "zeroize", diff --git a/Cargo.toml b/Cargo.toml index 6473359b33..005bf9c811 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -130,7 +130,7 @@ tokio-util = "0.7.10" # Substrate crates: sp-core = { version = "28.0.0", default-features = false } -sp-core-hashing = { version = "15.0.0", default-features = false } +sp-crypto-hashing = { version = "0.1.0", default-features = false } sp-runtime = "31.0.0" sp-keyring = "31.0.0" diff --git a/examples/parachain-example/Cargo.lock b/examples/parachain-example/Cargo.lock index c49f261820..2c523c588f 100644 --- a/examples/parachain-example/Cargo.lock +++ b/examples/parachain-example/Cargo.lock @@ -2512,7 +2512,7 @@ dependencies = [ ] [[package]] -name = "sp-core-hashing" +name = "sp-crypto-hashing" version = "13.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb8524f01591ee58b46cd83c9dbc0fcffd2fd730dabec4f59326cd58a00f17e2" @@ -2573,7 +2573,7 @@ dependencies = [ "scale-value", "serde", "serde_json", - "sp-core-hashing", + "sp-crypto-hashing", "subxt-lightclient", "subxt-macro", "subxt-metadata", @@ -2637,7 +2637,7 @@ dependencies = [ "frame-metadata 16.0.0", "parity-scale-codec", "scale-info", - "sp-core-hashing", + "sp-crypto-hashing", "thiserror", ] @@ -2655,7 +2655,7 @@ dependencies = [ "secp256k1", "secrecy", "sha2 0.10.8", - "sp-core-hashing", + "sp-crypto-hashing", "subxt", "thiserror", "zeroize", diff --git a/examples/wasm-example/Cargo.lock b/examples/wasm-example/Cargo.lock index 003fb839bc..c80bf6d404 100644 --- a/examples/wasm-example/Cargo.lock +++ b/examples/wasm-example/Cargo.lock @@ -2460,7 +2460,7 @@ dependencies = [ ] [[package]] -name = "sp-core-hashing" +name = "sp-crypto-hashing" version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0f4990add7b2cefdeca883c0efa99bb4d912cb2196120e1500c0cc099553b0" @@ -2522,7 +2522,7 @@ dependencies = [ "scale-value", "serde", "serde_json", - "sp-core-hashing", + "sp-crypto-hashing", "subxt-lightclient", "subxt-macro", "subxt-metadata", @@ -2598,7 +2598,7 @@ dependencies = [ "hashbrown 0.14.3", "parity-scale-codec", "scale-info", - "sp-core-hashing", + "sp-crypto-hashing", ] [[package]] diff --git a/metadata/Cargo.toml b/metadata/Cargo.toml index a6e15de0aa..1423122ed5 100644 --- a/metadata/Cargo.toml +++ b/metadata/Cargo.toml @@ -21,7 +21,7 @@ std = ["scale-info/std", "frame-metadata/std"] scale-info = { workspace = true, default-features = false } frame-metadata = { workspace = true, default-features = false, features = ["current", "decode"] } codec = { package = "parity-scale-codec", workspace = true, default-features = false, features = ["derive"] } -sp-core-hashing = { workspace = true } +sp-crypto-hashing = { workspace = true } hashbrown = { workspace = true } derive_more = { workspace = true } diff --git a/metadata/src/utils/validation.rs b/metadata/src/utils/validation.rs index 2b1b1f5e33..dfa4f9b829 100644 --- a/metadata/src/utils/validation.rs +++ b/metadata/src/utils/validation.rs @@ -35,7 +35,7 @@ enum TypeBeingHashed { /// Hashing function utilized internally. fn hash(data: &[u8]) -> Hash { - sp_core_hashing::twox_256(data) + sp_crypto_hashing::twox_256(data) } /// XOR two hashes together. Only use this when you don't care about the order diff --git a/signer/Cargo.toml b/signer/Cargo.toml index 7678256460..7e307b2284 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -16,7 +16,7 @@ keywords = ["parity", "subxt", "extrinsic", "signer"] [features] default = ["sr25519", "ecdsa", "subxt", "std", "native"] -std = ["regex/std", "sp-core-hashing/std", "pbkdf2/std", "sha2/std", "hmac/std", "bip39/std", "schnorrkel/std", "secp256k1/std", "sp-core/std"] +std = ["regex/std", "sp-crypto-hashing/std", "pbkdf2/std", "sha2/std", "hmac/std", "bip39/std", "schnorrkel/std", "secp256k1/std", "sp-core/std"] # Pick the signer implementation(s) you need by enabling the # corresponding features. Note: I had more difficulties getting @@ -40,7 +40,7 @@ regex = { workspace = true, features = ["unicode"] } hex = { workspace = true } cfg-if = { workspace = true } codec = { package = "parity-scale-codec", workspace = true, features = ["derive"] } -sp-core-hashing = { workspace = true } +sp-crypto-hashing = { workspace = true } derive_more = { workspace = true } pbkdf2 = { workspace = true } sha2 = { workspace = true } diff --git a/signer/src/crypto/derive_junction.rs b/signer/src/crypto/derive_junction.rs index 87beee1717..b68f079986 100644 --- a/signer/src/crypto/derive_junction.rs +++ b/signer/src/crypto/derive_junction.rs @@ -40,7 +40,7 @@ impl DeriveJunction { let mut cc: [u8; JUNCTION_ID_LEN] = Default::default(); index.using_encoded(|data| { if data.len() > JUNCTION_ID_LEN { - cc.copy_from_slice(&sp_core_hashing::blake2_256(data)); + cc.copy_from_slice(&sp_crypto_hashing::blake2_256(data)); } else { cc[0..data.len()].copy_from_slice(data); } diff --git a/signer/src/ecdsa.rs b/signer/src/ecdsa.rs index a25c8cc776..de84d4bd9a 100644 --- a/signer/src/ecdsa.rs +++ b/signer/src/ecdsa.rs @@ -144,7 +144,7 @@ impl Keypair { DeriveJunction::Soft(_) => return Err(Error::SoftJunction), DeriveJunction::Hard(junction_bytes) => { acc = ("Secp256k1HDKD", acc, junction_bytes) - .using_encoded(sp_core_hashing::blake2_256) + .using_encoded(sp_crypto_hashing::blake2_256) } } } @@ -161,7 +161,7 @@ impl Keypair { /// Sign some message. These bytes can be used directly in a Substrate `MultiSignature::Ecdsa(..)`. pub fn sign(&self, message: &[u8]) -> Signature { // From sp_core::ecdsa::sign: - let message_hash = sp_core_hashing::blake2_256(message); + let message_hash = sp_crypto_hashing::blake2_256(message); // From sp_core::ecdsa::sign_prehashed: let wrapped = Message::from_digest_slice(&message_hash).expect("Message is 32 bytes; qed"); let recsig: RecoverableSignature = @@ -194,7 +194,7 @@ pub fn verify>(sig: &Signature, message: M, pubkey: &PublicKey) - let Ok(public) = secp256k1::PublicKey::from_slice(&pubkey.0) else { return false; }; - let message_hash = sp_core_hashing::blake2_256(message.as_ref()); + let message_hash = sp_crypto_hashing::blake2_256(message.as_ref()); let wrapped = Message::from_digest_slice(&message_hash).expect("Message is 32 bytes; qed"); Secp256k1::verification_only() @@ -299,7 +299,7 @@ mod subxt_compat { /// We often want this type, and using this method avoids any /// ambiguous type resolution issues. pub fn to_account_id(self) -> AccountId32 { - AccountId32(sp_core_hashing::blake2_256(&self.0)) + AccountId32(sp_crypto_hashing::blake2_256(&self.0)) } /// A shortcut to obtain a [`MultiAddress`] from a [`PublicKey`]. /// We often want this type, and using this method avoids any diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 53c0074b3e..f91ec708a0 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -87,7 +87,7 @@ instant = { workspace = true } # Provides some deserialization, types like U256/H256 and hashing impls like twox/blake256: impl-serde = { workspace = true } primitive-types = { workspace = true, features = ["codec", "scale-info", "serde"] } -sp-core-hashing = { workspace = true } +sp-crypto-hashing = { workspace = true } # For ss58 encoding AccountId32 to serialize them properly: base58 = { workspace = true } diff --git a/subxt/src/config/substrate.rs b/subxt/src/config/substrate.rs index 44cfcf7b73..1ee3e83c5f 100644 --- a/subxt/src/config/substrate.rs +++ b/subxt/src/config/substrate.rs @@ -42,7 +42,7 @@ pub struct BlakeTwo256; impl Hasher for BlakeTwo256 { type Output = H256; fn hash(s: &[u8]) -> Self::Output { - sp_core_hashing::blake2_256(s).into() + sp_crypto_hashing::blake2_256(s).into() } } diff --git a/subxt/src/events/events_client.rs b/subxt/src/events/events_client.rs index 834e6cd64f..bb389b828c 100644 --- a/subxt/src/events/events_client.rs +++ b/subxt/src/events/events_client.rs @@ -76,8 +76,8 @@ where // The storage key needed to access events. fn system_events_key() -> [u8; 32] { - let a = sp_core_hashing::twox_128(b"System"); - let b = sp_core_hashing::twox_128(b"Events"); + let a = sp_crypto_hashing::twox_128(b"System"); + let b = sp_crypto_hashing::twox_128(b"Events"); let mut res = [0; 32]; res[0..16].clone_from_slice(&a); res[16..32].clone_from_slice(&b); diff --git a/subxt/src/storage/storage_type.rs b/subxt/src/storage/storage_type.rs index daa0eccf63..d072c1e40b 100644 --- a/subxt/src/storage/storage_type.rs +++ b/subxt/src/storage/storage_type.rs @@ -287,8 +287,10 @@ where // construct the storage key. This is done similarly in `frame_support::traits::metadata::StorageVersion::storage_key()`. pub const STORAGE_VERSION_STORAGE_KEY_POSTFIX: &[u8] = b":__STORAGE_VERSION__:"; let mut key_bytes: Vec = vec![]; - key_bytes.extend(&sp_core_hashing::twox_128(pallet_name.as_ref().as_bytes())); - key_bytes.extend(&sp_core_hashing::twox_128( + key_bytes.extend(&sp_crypto_hashing::twox_128( + pallet_name.as_ref().as_bytes(), + )); + key_bytes.extend(&sp_crypto_hashing::twox_128( STORAGE_VERSION_STORAGE_KEY_POSTFIX, )); diff --git a/subxt/src/storage/utils.rs b/subxt/src/storage/utils.rs index 12db5a922c..6024d9efc8 100644 --- a/subxt/src/storage/utils.rs +++ b/subxt/src/storage/utils.rs @@ -17,8 +17,8 @@ pub fn write_storage_address_root_bytes( addr: &Address, out: &mut Vec, ) { - out.extend(sp_core_hashing::twox_128(addr.pallet_name().as_bytes())); - out.extend(sp_core_hashing::twox_128(addr.entry_name().as_bytes())); + out.extend(sp_crypto_hashing::twox_128(addr.pallet_name().as_bytes())); + out.extend(sp_crypto_hashing::twox_128(addr.entry_name().as_bytes())); } /// Outputs the [`storage_address_root_bytes`] as well as any additional bytes that represent @@ -44,16 +44,16 @@ pub fn storage_address_root_bytes(addr: &Address) -> Ve pub fn hash_bytes(input: &[u8], hasher: StorageHasher, bytes: &mut Vec) { match hasher { StorageHasher::Identity => bytes.extend(input), - StorageHasher::Blake2_128 => bytes.extend(sp_core_hashing::blake2_128(input)), + StorageHasher::Blake2_128 => bytes.extend(sp_crypto_hashing::blake2_128(input)), StorageHasher::Blake2_128Concat => { - bytes.extend(sp_core_hashing::blake2_128(input)); + bytes.extend(sp_crypto_hashing::blake2_128(input)); bytes.extend(input); } - StorageHasher::Blake2_256 => bytes.extend(sp_core_hashing::blake2_256(input)), - StorageHasher::Twox128 => bytes.extend(sp_core_hashing::twox_128(input)), - StorageHasher::Twox256 => bytes.extend(sp_core_hashing::twox_256(input)), + StorageHasher::Blake2_256 => bytes.extend(sp_crypto_hashing::blake2_256(input)), + StorageHasher::Twox128 => bytes.extend(sp_crypto_hashing::twox_128(input)), + StorageHasher::Twox256 => bytes.extend(sp_crypto_hashing::twox_256(input)), StorageHasher::Twox64Concat => { - bytes.extend(sp_core_hashing::twox_64(input)); + bytes.extend(sp_crypto_hashing::twox_64(input)); bytes.extend(input); } } diff --git a/subxt/src/tx/tx_client.rs b/subxt/src/tx/tx_client.rs index 49b940d40c..c4a5924c11 100644 --- a/subxt/src/tx/tx_client.rs +++ b/subxt/src/tx/tx_client.rs @@ -17,7 +17,7 @@ use crate::{ }; use codec::{Compact, Decode, Encode}; use derivative::Derivative; -use sp_core_hashing::blake2_256; +use sp_crypto_hashing::blake2_256; /// A client for working with transactions. #[derive(Derivative)] diff --git a/testing/no-std-tests/Cargo.lock b/testing/no-std-tests/Cargo.lock index c04633ecae..dc29c67571 100644 --- a/testing/no-std-tests/Cargo.lock +++ b/testing/no-std-tests/Cargo.lock @@ -496,7 +496,7 @@ dependencies = [ ] [[package]] -name = "sp-core-hashing" +name = "sp-crypto-hashing" version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0f4990add7b2cefdeca883c0efa99bb4d912cb2196120e1500c0cc099553b0" @@ -540,7 +540,7 @@ dependencies = [ "hashbrown", "parity-scale-codec", "scale-info", - "sp-core-hashing", + "sp-crypto-hashing", ] [[package]] @@ -558,7 +558,7 @@ dependencies = [ "schnorrkel", "secrecy", "sha2", - "sp-core-hashing", + "sp-crypto-hashing", "zeroize", ] diff --git a/testing/wasm-lightclient-tests/Cargo.lock b/testing/wasm-lightclient-tests/Cargo.lock index 3009f03623..90a02bd3c2 100644 --- a/testing/wasm-lightclient-tests/Cargo.lock +++ b/testing/wasm-lightclient-tests/Cargo.lock @@ -2272,7 +2272,7 @@ dependencies = [ ] [[package]] -name = "sp-core-hashing" +name = "sp-crypto-hashing" version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0f4990add7b2cefdeca883c0efa99bb4d912cb2196120e1500c0cc099553b0" @@ -2334,7 +2334,7 @@ dependencies = [ "scale-value", "serde", "serde_json", - "sp-core-hashing", + "sp-crypto-hashing", "subxt-lightclient", "subxt-macro", "subxt-metadata", @@ -2410,7 +2410,7 @@ dependencies = [ "hashbrown", "parity-scale-codec", "scale-info", - "sp-core-hashing", + "sp-crypto-hashing", ] [[package]] diff --git a/testing/wasm-rpc-tests/Cargo.lock b/testing/wasm-rpc-tests/Cargo.lock index 8df1704f97..e2d2a7225a 100644 --- a/testing/wasm-rpc-tests/Cargo.lock +++ b/testing/wasm-rpc-tests/Cargo.lock @@ -2294,7 +2294,7 @@ dependencies = [ ] [[package]] -name = "sp-core-hashing" +name = "sp-crypto-hashing" version = "13.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb8524f01591ee58b46cd83c9dbc0fcffd2fd730dabec4f59326cd58a00f17e2" @@ -2362,7 +2362,7 @@ dependencies = [ "scale-value", "serde", "serde_json", - "sp-core-hashing", + "sp-crypto-hashing", "subxt-lightclient", "subxt-macro", "subxt-metadata", @@ -2434,7 +2434,7 @@ dependencies = [ "frame-metadata 16.0.0", "parity-scale-codec", "scale-info", - "sp-core-hashing", + "sp-crypto-hashing", "thiserror", ]