diff --git a/examples/sign_email.py b/examples/sign_email.py index 5a47b13b..038eb600 100644 --- a/examples/sign_email.py +++ b/examples/sign_email.py @@ -12,8 +12,11 @@ } """) +# Hash the user's email address: +hashed_email = iroha.hash(b"email@address") + # Sign the user's email address: -signature = key_pair.sign(b"email@address") +signature = key_pair.sign(bytes(hashed_email)) # Retrieve the encoded Hex string of the user's `signature` print(f"Encoded signature:\n{bytes(signature).hex()}") diff --git a/src/data_model/crypto.rs b/src/data_model/crypto.rs index 44c4ce20..94664824 100644 --- a/src/data_model/crypto.rs +++ b/src/data_model/crypto.rs @@ -3,7 +3,9 @@ use pyo3::{ prelude::*, }; -use iroha_crypto::{Algorithm, KeyGenConfiguration, KeyPair, PrivateKey, PublicKey, Signature}; +use iroha_crypto::{ + Algorithm, Hash, KeyGenConfiguration, KeyPair, PrivateKey, PublicKey, Signature, +}; use super::PyMirror; @@ -132,6 +134,11 @@ impl PySignature { } } +#[pyfunction] +fn hash(bytes: &[u8]) -> [u8; Hash::LENGTH] { + Hash::new(bytes).into() +} + #[pyclass(name = "KeyGenConfiguration")] #[derive(Clone, derive_more::From, derive_more::Into, derive_more::Deref)] pub struct PyKeyGenConfiguration(pub KeyGenConfiguration); @@ -179,5 +186,6 @@ pub fn register_items(_py: Python<'_>, module: &PyModule) -> PyResult<()> { module.add_class::()?; module.add_class::()?; module.add_class::()?; + module.add_wrapped(wrap_pyfunction!(hash))?; Ok(()) }