pub mod binding;
pub mod poseidon2_bn254;
pub use binding::{compute_binding_hash_v4, hash_field, SCHEMA_VERSION_V4, DOMAIN_SEPARATOR_V4};
pub use poseidon2_bn254::{
poseidon2_hash as bn254_poseidon2_hash,
poseidon2_hash_5 as bn254_leaf_commitment,
poseidon2_hash_2 as bn254_merkle_hash,
derive_nsec as bn254_derive_nsec,
derive_npub_commitment as bn254_derive_npub,
generate_test_vectors as bn254_generate_test_vectors,
scalar_to_hex, hex_to_scalar,
};
pub const PURPOSE_NONE: u8 = 0;
pub const PURPOSE_ALLOWLIST: u8 = 1;
pub const PURPOSE_ISSUER_BATCH: u8 = 2;
pub const PURPOSE_REVOCATION: u8 = 3;
pub fn get_purpose_id(purpose: &str) -> u8 {
match purpose {
"" => PURPOSE_NONE,
"allowlist" => PURPOSE_ALLOWLIST,
"issuer_batch" => PURPOSE_ISSUER_BATCH,
"revocation" => PURPOSE_REVOCATION,
_ => PURPOSE_NONE,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_purpose_ids() {
assert_eq!(get_purpose_id(""), PURPOSE_NONE);
assert_eq!(get_purpose_id("allowlist"), PURPOSE_ALLOWLIST);
assert_eq!(get_purpose_id("issuer_batch"), PURPOSE_ISSUER_BATCH);
assert_eq!(get_purpose_id("revocation"), PURPOSE_REVOCATION);
assert_eq!(get_purpose_id("unknown"), PURPOSE_NONE);
}
}