mirror of
https://github.com/vacp2p/zerokit.git
synced 2026-01-09 21:58:06 -05:00
Add BE functions in public API too
This commit is contained in:
@@ -7,8 +7,8 @@ use crate::protocol::{
|
||||
serialize_proof_values, serialize_witness, verify_proof,
|
||||
};
|
||||
use crate::utils::{
|
||||
bytes_le_to_fr, bytes_le_to_vec_fr, bytes_le_to_vec_u8, fr_byte_size, fr_to_bytes_le,
|
||||
vec_fr_to_bytes_le, vec_u8_to_bytes_le,
|
||||
bytes_le_to_fr, bytes_le_to_vec_fr, bytes_le_to_vec_u8, fr_byte_size, fr_to_bytes_be,
|
||||
fr_to_bytes_le, vec_fr_to_bytes_le, vec_u8_to_bytes_le,
|
||||
};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use {
|
||||
@@ -1139,6 +1139,15 @@ impl RLN {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Same as key_gen but serialized in BE format
|
||||
pub fn key_gen_be<W: Write>(&self, mut output_data: W) -> Result<(), RLNError> {
|
||||
let (identity_secret_hash, id_commitment) = keygen();
|
||||
output_data.write_all(&fr_to_bytes_be(&identity_secret_hash))?;
|
||||
output_data.write_all(&fr_to_bytes_be(&id_commitment))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns an identity trapdoor, nullifier, secret and commitment tuple.
|
||||
///
|
||||
/// The identity secret is the Poseidon hash of the identity trapdoor and identity nullifier.
|
||||
@@ -1172,6 +1181,18 @@ impl RLN {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Same as extend_key_gen but serialized in BE format.
|
||||
pub fn extended_key_gen_be<W: Write>(&self, mut output_data: W) -> Result<(), RLNError> {
|
||||
let (identity_trapdoor, identity_nullifier, identity_secret_hash, id_commitment) =
|
||||
extended_keygen();
|
||||
output_data.write_all(&fr_to_bytes_be(&identity_trapdoor))?;
|
||||
output_data.write_all(&fr_to_bytes_be(&identity_nullifier))?;
|
||||
output_data.write_all(&fr_to_bytes_be(&identity_secret_hash))?;
|
||||
output_data.write_all(&fr_to_bytes_be(&id_commitment))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns an identity secret and identity commitment pair generated using a seed.
|
||||
///
|
||||
/// The identity commitment is the Poseidon hash of the identity secret.
|
||||
@@ -1211,6 +1232,22 @@ impl RLN {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Same as seeded_key_gen but in BE format
|
||||
pub fn seeded_key_gen_be<R: Read, W: Write>(
|
||||
&self,
|
||||
mut input_data: R,
|
||||
mut output_data: W,
|
||||
) -> Result<(), RLNError> {
|
||||
let mut serialized: Vec<u8> = Vec::new();
|
||||
input_data.read_to_end(&mut serialized)?;
|
||||
|
||||
let (identity_secret_hash, id_commitment) = seeded_keygen(&serialized);
|
||||
output_data.write_all(&fr_to_bytes_be(&identity_secret_hash))?;
|
||||
output_data.write_all(&fr_to_bytes_be(&id_commitment))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns an identity trapdoor, nullifier, secret and commitment tuple generated using a seed.
|
||||
///
|
||||
/// The identity secret is the Poseidon hash of the identity trapdoor and identity nullifier.
|
||||
@@ -1257,6 +1294,25 @@ impl RLN {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// same as seeded_extended_key_gen but in BE format
|
||||
pub fn seeded_extended_key_gen_be<R: Read, W: Write>(
|
||||
&self,
|
||||
mut input_data: R,
|
||||
mut output_data: W,
|
||||
) -> Result<(), RLNError> {
|
||||
let mut serialized: Vec<u8> = Vec::new();
|
||||
input_data.read_to_end(&mut serialized)?;
|
||||
|
||||
let (identity_trapdoor, identity_nullifier, identity_secret_hash, id_commitment) =
|
||||
extended_seeded_keygen(&serialized);
|
||||
output_data.write_all(&fr_to_bytes_be(&identity_trapdoor))?;
|
||||
output_data.write_all(&fr_to_bytes_be(&identity_nullifier))?;
|
||||
output_data.write_all(&fr_to_bytes_be(&identity_secret_hash))?;
|
||||
output_data.write_all(&fr_to_bytes_be(&id_commitment))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Recovers the identity secret from two set of proof values computed for same secret in same epoch with same rln identifier.
|
||||
///
|
||||
/// Input values are:
|
||||
|
||||
Reference in New Issue
Block a user