@@ -11,7 +11,6 @@ use ark_relations::r1cs::ConstraintMatrices;
1111use ark_serialize:: { CanonicalDeserialize , CanonicalSerialize , Read , Write } ;
1212use cfg_if:: cfg_if;
1313use color_eyre:: { Report , Result } ;
14- use num_bigint:: BigInt ;
1514use std:: io:: Cursor ;
1615use utils:: { ZerokitMerkleProof , ZerokitMerkleTree } ;
1716
@@ -26,6 +25,7 @@ cfg_if! {
2625 use std:: str :: FromStr ;
2726 } else {
2827 use std:: marker:: * ;
28+ use num_bigint:: BigInt ;
2929 }
3030}
3131
@@ -819,8 +819,7 @@ impl RLN<'_> {
819819 // Generate RLN Proof using a witness calculated from outside zerokit
820820 //
821821 // output_data is [ proof<128> | root<32> | external_nullifier<32> | x<32> | y<32> | nullifier<32>]
822- // we skip it from documentation for now
823- #[ doc( hidden) ]
822+ #[ cfg( target_arch = "wasm32" ) ]
824823 pub fn generate_rln_proof_with_witness < W : Write > (
825824 & mut self ,
826825 calculated_witness : Vec < BigInt > ,
@@ -839,6 +838,30 @@ impl RLN<'_> {
839838 Ok ( ( ) )
840839 }
841840
841+ // Generate RLN Proof using a witness calculated from outside zerokit
842+ //
843+ // output_data is [ proof<128> | root<32> | external_nullifier<32> | x<32> | y<32> | nullifier<32>]
844+ // we skip it from documentation for now
845+ #[ cfg( not( target_arch = "wasm32" ) ) ]
846+ pub fn generate_rln_proof_with_witness < R : Read , W : Write > (
847+ & mut self ,
848+ mut input_data : R ,
849+ mut output_data : W ,
850+ ) -> Result < ( ) > {
851+ let mut witness_byte: Vec < u8 > = Vec :: new ( ) ;
852+ input_data. read_to_end ( & mut witness_byte) ?;
853+ let ( rln_witness, _) = deserialize_witness ( & witness_byte) ?;
854+ let proof_values = proof_values_from_witness ( & rln_witness) ?;
855+
856+ let proof = generate_proof ( self . witness_calculator , & self . proving_key , & rln_witness) ?;
857+
858+ // Note: we export a serialization of ark-groth16::Proof not semaphore::Proof
859+ // This proof is compressed, i.e. 128 bytes long
860+ proof. serialize_compressed ( & mut output_data) ?;
861+ output_data. write_all ( & serialize_proof_values ( & proof_values) ) ?;
862+ Ok ( ( ) )
863+ }
864+
842865 /// Verifies a zkSNARK RLN proof against the provided proof values and the state of the internal Merkle tree.
843866 ///
844867 /// Input values are:
0 commit comments