Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move cryptographic hashing procedures to crypto folder. #2306

Merged
merged 18 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion substrate/primitives/consensus/beefy/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ mod tests {
use super::*;
use crate::{ecdsa_crypto::Signature as EcdsaSignature, known_payloads};
use codec::Decode;
use sp_core::{keccak_256, Pair};
use sp_core::Pair;
use sp_crypto_hashing::keccak_256;

#[cfg(feature = "bls-experimental")]
use crate::bls_crypto::Signature as BlsSignature;
Expand Down
3 changes: 2 additions & 1 deletion substrate/primitives/consensus/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ sp_api::decl_runtime_apis! {
mod tests {
use super::*;
use sp_application_crypto::ecdsa::{self, Public};
use sp_core::{blake2_256, crypto::Wraps, keccak_256, Pair};
use sp_core::crypto::{Pair, Wraps};
use sp_crypto_hashing::{blake2_256, keccak_256};
use sp_runtime::traits::{BlakeTwo256, Keccak256};

#[test]
Expand Down
3 changes: 2 additions & 1 deletion substrate/primitives/consensus/beefy/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ impl<TBlockNumber, TSignatureAccumulator>

#[cfg(test)]
mod tests {
use sp_core::{keccak_256, Pair};
use sp_core::Pair;
use sp_crypto_hashing::keccak_256;

use super::*;
use codec::Decode;
Expand Down
10 changes: 8 additions & 2 deletions substrate/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ pub use sp_debug_derive::RuntimeDebug;
#[cfg(feature = "serde")]
pub use impl_serde::serialize as bytes;

// #[cfg(feature = "full_crypto")]
// pub use sp_crypto_hashing as hashing;
// https://github.com/rust-lang/rust/issues/85388
#[cfg(feature = "full_crypto")]
#[deprecated(
since = "21.0.0",
davxy marked this conversation as resolved.
Show resolved Hide resolved
note = "hashing re-export is scheduled for removal, please use `sp-crypto-hashing` instead"
davxy marked this conversation as resolved.
Show resolved Hide resolved
)]
pub use sp_crypto_hashing::{self as hashing, *};

pub mod crypto;
pub mod hexdisplay;
pub use paste;
Expand Down
7 changes: 4 additions & 3 deletions substrate/primitives/keystore/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,17 @@ mod tests {
let suri = "//Alice";
let pair = ecdsa::Pair::from_string(suri, None).unwrap();

let msg = sp_core::keccak_256(b"this should be a hashed message");
// Lets pretend this to be the hash output as content doesn't really matter here.
davxy marked this conversation as resolved.
Show resolved Hide resolved
let hash = [0xff; 32];

// no key in key store
let res = store.ecdsa_sign_prehashed(ECDSA, &pair.public(), &msg).unwrap();
let res = store.ecdsa_sign_prehashed(ECDSA, &pair.public(), &hash).unwrap();
assert!(res.is_none());

// insert key, sign again
store.insert(ECDSA, suri, pair.public().as_ref()).unwrap();

let res = store.ecdsa_sign_prehashed(ECDSA, &pair.public(), &msg).unwrap();
let res = store.ecdsa_sign_prehashed(ECDSA, &pair.public(), &hash).unwrap();
assert!(res.is_some());
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/statement-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ mod test {
statement.sign_ecdsa_private(&secp256k1_kp);
assert_eq!(
statement.verify_signature(),
SignatureVerificationResult::Valid(sp_core::hashing::blake2_256(
SignatureVerificationResult::Valid(sp_crypto_hashing::blake2_256(
&secp256k1_kp.public().0
))
);
Expand Down