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

[fix] #166: Hash email address #167

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion examples/sign_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")
10 changes: 9 additions & 1 deletion src/data_model/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -179,5 +186,6 @@ pub fn register_items(_py: Python<'_>, module: &PyModule) -> PyResult<()> {
module.add_class::<PyPublicKey>()?;
module.add_class::<PyKeyPair>()?;
module.add_class::<PyKeyGenConfiguration>()?;
module.add_wrapped(wrap_pyfunction!(hash))?;
Ok(())
}
Loading