Skip to content

Commit

Permalink
[fix] #166: Hash email address
Browse files Browse the repository at this point in the history
Signed-off-by: Sam H. Smith <sam.henning.smith@protonmail.com>
  • Loading branch information
SamHSmith committed Apr 2, 2024
1 parent 2985138 commit dfbf752
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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(())
}

0 comments on commit dfbf752

Please sign in to comment.