From 711a34cc2dd5596d7d29cf21ca1761784fb8a33e Mon Sep 17 00:00:00 2001 From: onyinyang Date: Mon, 18 Dec 2023 16:06:57 -0500 Subject: [PATCH] Add bridgeline getters to wasm and Lox system info --- crates/lox-utils/src/lib.rs | 32 ++++++++++++++++++++++++++++++-- crates/lox-wasm/src/lib.rs | 30 +++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/crates/lox-utils/src/lib.rs b/crates/lox-utils/src/lib.rs index bb0bde2..8f1d7a2 100644 --- a/crates/lox-utils/src/lib.rs +++ b/crates/lox-utils/src/lib.rs @@ -1,4 +1,6 @@ -use lox_library::bridge_table::{from_scalar, BridgeLine, BridgeTable, EncryptedBucket}; +use lox_library::bridge_table::{ + from_scalar, BridgeLine, BridgeTable, EncryptedBucket, MAX_BRIDGES_PER_BUCKET, +}; use lox_library::cred::{BucketReachability, Invitation, Lox}; use lox_library::proto; use lox_library::{IssuerPubKey, OPENINV_LENGTH}; @@ -71,6 +73,21 @@ pub struct PubKeys { pub invitation_pub: IssuerPubKey, } +#[derive(Debug, Deserialize, Serialize)] +pub struct LoxSystemInfo { + max_blockages: [u32; proto::level_up::MAX_LEVEL + 1], + level_interval: [u32; proto::level_up::MAX_LEVEL + 1], + level_invitations: [u32; proto::level_up::MAX_LEVEL + 1], + min_trust_level: u32, +} + +pub const LOX_SYSTEM_INFO: LoxSystemInfo = LoxSystemInfo { + max_blockages: proto::level_up::MAX_BLOCKAGES, + level_interval: proto::level_up::LEVEL_INTERVAL, + level_invitations: proto::level_up::LEVEL_INVITATIONS, + min_trust_level: proto::check_blockage::MIN_TRUST_LEVEL, +}; + #[serde_as] #[derive(Serialize, Deserialize)] pub struct EncBridgeTable { @@ -80,7 +97,7 @@ pub struct EncBridgeTable { #[derive(Debug, Deserialize, Serialize)] pub struct LoxCredential { pub lox_credential: Lox, - pub bridgeline: Option, + pub bridgelines: Option>, pub invitation: Option, } @@ -102,6 +119,17 @@ pub fn generate_reachability_cred(lox_cred: &Lox, encrypted_table: String) -> Bu bucket.1.unwrap() } +pub fn get_credential_bridgelines( + lox_cred: &Lox, + encrypted_table: String, +) -> [BridgeLine; MAX_BRIDGES_PER_BUCKET] { + let (id, key) = from_scalar(lox_cred.bucket).unwrap(); + let enc_buckets: EncBridgeTable = serde_json::from_str(&encrypted_table).unwrap(); + let bucket = + BridgeTable::decrypt_bucket(id, &key, enc_buckets.etable.get(&id).unwrap()).unwrap(); + bucket.0 +} + //pub const MAX_LEVEL: usize = 4; //pub const LEVEL_INTERVAL: [u32; MAX_LEVEL + 1] = [0, 14, 28, 56, 84]; pub fn calc_test_days(trust_level: i64) -> i64 { diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index 51abf22..f106b4e 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -67,7 +67,7 @@ pub fn handle_new_lox_credential( }; let lox_cred = lox_utils::LoxCredential { lox_credential: lox_cred.0, - bridgeline: Some(lox_cred.1), + bridgelines: Some(vec![lox_cred.1]), invitation: None, }; log(&format!( @@ -76,7 +76,7 @@ pub fn handle_new_lox_credential( )); log(&format!( "Got new bridgeline: {}", - serde_json::to_string(&lox_cred.bridgeline).unwrap() + serde_json::to_string(&lox_cred.bridgelines).unwrap() )); Ok(serde_json::to_string(&lox_cred).unwrap()) } @@ -176,7 +176,7 @@ pub fn handle_trust_migration( ) { Ok(level_1_cred) => lox_utils::LoxCredential { lox_credential: level_1_cred, - bridgeline: None, + bridgelines: None, invitation: None, }, Err(e) => { @@ -243,7 +243,7 @@ pub fn handle_level_up( ) { Ok(level_up_cred) => lox_utils::LoxCredential { lox_credential: level_up_cred, - bridgeline: None, + bridgelines: None, invitation: None, }, Err(e) => { @@ -318,7 +318,7 @@ pub fn handle_issue_invite( }; let invitation_cred = lox_utils::LoxCredential { lox_credential: issue_invite_cred.0, - bridgeline: None, + bridgelines: None, invitation: Some(issue_invite_cred.1), }; @@ -382,7 +382,7 @@ pub fn handle_redeem_invite( ) { Ok(issue_invite_cred) => lox_utils::LoxCredential { lox_credential: issue_invite_cred, - bridgeline: None, + bridgelines: None, invitation: None, }, Err(e) => { @@ -493,7 +493,7 @@ pub fn handle_blockage_migration( ) { Ok(lox_cred) => lox_utils::LoxCredential { lox_credential: lox_cred, - bridgeline: None, + bridgelines: None, invitation: None, }, Err(e) => { @@ -572,3 +572,19 @@ pub fn get_received_invite_expiry(invite_cred_str: String) -> String { )); serde_json::to_string(&date_time).unwrap() } + +#[wasm_bindgen] +pub fn get_bridgelines_from_bucket(lox_cred_str: String, encrypted_table: String) -> String { + let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let bridgelines = + lox_utils::get_credential_bridgelines(&lox_cred.lox_credential, encrypted_table); + log(&format!( + "Lox BridgeLines Expiry {}", + serde_json::to_string(&bridgelines).unwrap() + )); + serde_json::to_string(&bridgelines).unwrap() +} + +pub fn get_constants() -> String { + serde_json::to_string(&lox_utils::LOX_SYSTEM_INFO).unwrap() +}