miden-client-web 0.15.0

Web Client library that facilitates interaction with the Miden network
use js_export_macro::js_export;
use miden_client::Felt as NativeFelt;
use miden_client::crypto::Poseidon2 as NativePoseidon2;

use super::felt::Felt;
use super::word::Word;
use crate::models::miden_arrays::FeltArray;

/// Poseidon2 hashing helpers exposed to JavaScript.
#[js_export]
#[derive(Copy, Clone)]
pub struct Poseidon2;

#[js_export]
impl Poseidon2 {
    /// Computes a Poseidon2 digest from the provided field elements.
    #[js_export(js_name = "hashElements")]
    pub fn hash_elements(felt_array: FeltArray) -> Word {
        let felts: Vec<Felt> = felt_array.into();
        let native_felts: Vec<NativeFelt> = felts.iter().map(Into::into).collect();

        let native_digest = NativePoseidon2::hash_elements(&native_felts);

        native_digest.into()
    }
}