1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use mina_curves::pasta::{Fp, Fq};
use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, permutation::poseidon_block_cipher};
use wasm_bindgen::prelude::*;

use crate::{
    arkworks::{WasmPastaFp, WasmPastaFq},
    wasm_flat_vector::WasmFlatVector,
};

// fp

#[wasm_bindgen]
pub fn caml_pasta_fp_poseidon_block_cipher(
    state: WasmFlatVector<WasmPastaFp>,
) -> WasmFlatVector<WasmPastaFp> {
    let mut state_vec: Vec<Fp> = state.into_iter().map(Into::into).collect();
    poseidon_block_cipher::<Fp, PlonkSpongeConstantsKimchi>(
        mina_poseidon::pasta::fp_kimchi::static_params(),
        &mut state_vec,
    );
    state_vec
        .iter()
        .map(|f| WasmPastaFp(*f))
        .collect::<Vec<WasmPastaFp>>()
        .into()
}

// fq

#[wasm_bindgen]
pub fn caml_pasta_fq_poseidon_block_cipher(
    state: WasmFlatVector<WasmPastaFq>,
) -> WasmFlatVector<WasmPastaFq> {
    let mut state_vec: Vec<Fq> = state.into_iter().map(Into::into).collect();
    poseidon_block_cipher::<Fq, PlonkSpongeConstantsKimchi>(
        mina_poseidon::pasta::fq_kimchi::static_params(),
        &mut state_vec,
    );
    state_vec
        .iter()
        .map(|f| WasmPastaFq(*f))
        .collect::<Vec<WasmPastaFq>>()
        .into()
}