Skip to content

Commit

Permalink
Refactor - move tree initializer to its own module.
Browse files Browse the repository at this point in the history
  • Loading branch information
piohei committed Jun 3, 2024
1 parent b373b2a commit 0ae466a
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 388 deletions.
408 changes: 20 additions & 388 deletions src/app.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::cmp::Ordering;
use std::ops::Deref;
use std::sync::Arc;

use anyhow::{anyhow, Context, Error as ErrReport};
use sqlx::migrate::{Migrate, MigrateDatabase, Migrator};
Expand All @@ -29,6 +30,8 @@ pub struct Database {
pub pool: Pool<Postgres>,
}

pub type SharedDatabase = Arc<Database>;

impl Deref for Database {
type Target = Pool<Postgres>;

Expand Down
1 change: 1 addition & 0 deletions src/identity/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod validator;
32 changes: 32 additions & 0 deletions src/identity/validator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use ruint::uint;
use semaphore::Field;

use crate::identity_tree::Hash;

// See <https://docs.rs/ark-bn254/latest/ark_bn254>
pub const MODULUS: Field =
uint!(21888242871839275222246405745257275088548364400416034343698204186575808495617_U256);

pub struct IdentityValidator {
snark_scalar_field: Hash,
}

// TODO Export the reduced-ness check that this is enabling from the
// `semaphore-rs` library when we bump the version.
impl IdentityValidator {
pub fn new() -> Self {
Self {
snark_scalar_field: Hash::from(MODULUS),
}
}

pub fn identity_is_reduced(&self, commitment: Hash) -> bool {
commitment.lt(&self.snark_scalar_field)
}
}

impl Default for IdentityValidator {
fn default() -> Self {
Self::new()
}
}
Loading

0 comments on commit 0ae466a

Please sign in to comment.