Skip to content

Commit

Permalink
chore: rename sp-core-hashing to sp-crypto-hashing (#1490)
Browse files Browse the repository at this point in the history
* rename sp-core-hashing to sp-crypto-hashing

* fmt
  • Loading branch information
jsdw committed Mar 21, 2024
1 parent caa6b56 commit 98c4c01
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '/'
Expand Down
20 changes: 17 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 4 additions & 4 deletions examples/parachain-example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/wasm-example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion metadata/src/utils/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion signer/src/crypto/derive_junction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions signer/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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 =
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn verify<M: AsRef<[u8]>>(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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion subxt/src/config/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
4 changes: 2 additions & 2 deletions subxt/src/events/events_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions subxt/src/storage/storage_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = 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,
));

Expand Down
16 changes: 8 additions & 8 deletions subxt/src/storage/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub fn write_storage_address_root_bytes<Address: StorageAddress>(
addr: &Address,
out: &mut Vec<u8>,
) {
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
Expand All @@ -44,16 +44,16 @@ pub fn storage_address_root_bytes<Address: StorageAddress>(addr: &Address) -> Ve
pub fn hash_bytes(input: &[u8], hasher: StorageHasher, bytes: &mut Vec<u8>) {
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion subxt/src/tx/tx_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions testing/no-std-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions testing/wasm-lightclient-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions testing/wasm-rpc-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98c4c01

Please sign in to comment.