mirror of https://github.com/vacp2p/zerokit.git
Add identity poseidon test
This commit is contained in:
parent
c718101ff1
commit
15c331db36
|
@ -1,3 +1,6 @@
|
|||
// Adapted from
|
||||
// https://github.com/worldcoin/semaphore-rs/blob/main/src/identity.rs
|
||||
|
||||
use num_bigint::{BigInt, Sign};
|
||||
use once_cell::sync::Lazy;
|
||||
use poseidon_rs::Poseidon;
|
||||
|
@ -5,9 +8,6 @@ use sha2::{Digest, Sha256};
|
|||
|
||||
use crate::util::{bigint_to_fr, fr_to_bigint};
|
||||
|
||||
// Adapted from
|
||||
// https://github.com/worldcoin/semaphore-rs/blob/main/src/identity.rs
|
||||
|
||||
static POSEIDON: Lazy<Poseidon> = Lazy::new(Poseidon::new);
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
|
@ -62,3 +62,22 @@ impl Identity {
|
|||
fr_to_bigint(res)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use super::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
fn test_identity() {
|
||||
let id = Identity::new(b"message");
|
||||
//println!("Commitment: {:#}", id.commitment());
|
||||
// From https://github.com/appliedzkp/zk-kit/blob/1ea410456fc2b95877efa7c671bc390ffbfb5d36/packages/identity/tests/index.test.ts#L63-L70
|
||||
let s = "1720349790382552497189398984241859233944354304766757200361065203741879866188";
|
||||
|
||||
let x = BigInt::from_str(s).unwrap();
|
||||
|
||||
assert!(id.commitment() == x);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue