|
@@ -18,6 +18,7 @@ The notation follows that of the paper "Hyphae: Social Secret Sharing"
|
|
|
extern crate zkp;
|
|
|
|
|
|
pub mod bridge_table;
|
|
|
+pub mod cred;
|
|
|
pub mod dup_filter;
|
|
|
|
|
|
use sha2::Sha512;
|
|
@@ -114,11 +115,11 @@ pub const OPENINV_LENGTH: usize = 32 // the length of the random
|
|
|
|
|
|
impl BridgeDb {
|
|
|
/// Create the BridgeDb.
|
|
|
- pub fn new(num_openinv_buckets: u32) -> BridgeDb {
|
|
|
+ pub fn new(num_openinv_buckets: u32) -> Self {
|
|
|
let mut csprng = OsRng {};
|
|
|
let keypair = Keypair::generate(&mut csprng);
|
|
|
let pubkey = keypair.public;
|
|
|
- BridgeDb {
|
|
|
+ Self {
|
|
|
keypair,
|
|
|
pubkey,
|
|
|
num_openinv_buckets,
|
|
@@ -165,3 +166,62 @@ impl BridgeDb {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+/// The bridge authority. This will typically be a singleton object.
|
|
|
+#[derive(Debug)]
|
|
|
+pub struct BridgeAuth {
|
|
|
+ /// The private key for the main Lox credential
|
|
|
+ lox_priv: IssuerPrivKey,
|
|
|
+ /// The public key for the main Lox credential
|
|
|
+ pub lox_pub: IssuerPubKey,
|
|
|
+ /// The private key for migration credentials
|
|
|
+ migration_priv: IssuerPrivKey,
|
|
|
+ /// The public key for migration credentials
|
|
|
+ pub migration_pub: IssuerPubKey,
|
|
|
+
|
|
|
+ /// The public key of the BridgeDb issuing open invitations
|
|
|
+ pub bridgedb_pub: PublicKey,
|
|
|
+
|
|
|
+ /// Duplicate filter for open invitations
|
|
|
+ openinv_filter: dup_filter::DupFilter<Scalar>,
|
|
|
+ /// Duplicate filter for credential ids
|
|
|
+ id_filter: dup_filter::DupFilter<Scalar>,
|
|
|
+
|
|
|
+ /// For testing only: offset of the true time to the simulated time
|
|
|
+ time_offset: time::Duration,
|
|
|
+}
|
|
|
+
|
|
|
+impl BridgeAuth {
|
|
|
+ pub fn new(bridgedb_pub: PublicKey) -> Self {
|
|
|
+ let lox_priv = IssuerPrivKey::new(6);
|
|
|
+ let lox_pub = IssuerPubKey::new(&lox_priv);
|
|
|
+ let migration_priv = IssuerPrivKey::new(3);
|
|
|
+ let migration_pub = IssuerPubKey::new(&migration_priv);
|
|
|
+ Self {
|
|
|
+ lox_priv,
|
|
|
+ lox_pub,
|
|
|
+ migration_priv,
|
|
|
+ migration_pub,
|
|
|
+ bridgedb_pub,
|
|
|
+ openinv_filter: Default::default(),
|
|
|
+ id_filter: Default::default(),
|
|
|
+ time_offset: time::Duration::zero(),
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// For testing only: manually advance the day by 1 day
|
|
|
+ pub fn advance_day(&mut self) {
|
|
|
+ self.time_offset += time::Duration::days(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// For testing only: manually advance the day by the given number
|
|
|
+ /// of days
|
|
|
+ pub fn advance_days(&mut self, days: u16) {
|
|
|
+ self.time_offset += time::Duration::days(days.into());
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Get today's (real or simulated) date
|
|
|
+ fn today(&self) -> i64 {
|
|
|
+ (time::OffsetDateTime::now_utc().date() + self.time_offset).julian_day()
|
|
|
+ }
|
|
|
+}
|