Skip to content

Commit

Permalink
feat: compute_hash_on_elements takes ExactSizeIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Jun 17, 2024
1 parent 9b6ffb2 commit ef5484e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions starknet-core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ mod errors {
}
pub use errors::{EcdsaSignError, EcdsaVerifyError};

pub fn compute_hash_on_elements(data: &[Felt]) -> Felt {
pub fn compute_hash_on_elements<'a, ESI, II>(data: II) -> Felt
where
ESI: ExactSizeIterator<Item = &'a Felt>,
II: IntoIterator<IntoIter = ESI>,
{
let mut current_hash = Felt::ZERO;
let data_iter = data.into_iter();
let data_len = Felt::from(data_iter.len());

for item in data.iter() {
current_hash = pedersen_hash(&current_hash, item);
for elem in data_iter {
current_hash = pedersen_hash(&current_hash, elem);
}

let data_len = Felt::from(data.len());
pedersen_hash(&current_hash, &data_len)
}

Expand Down

0 comments on commit ef5484e

Please sign in to comment.