Add bridgeline getters to wasm and Lox system info

This commit is contained in:
onyinyang 2023-12-18 16:06:57 -05:00
parent 918a5555b8
commit 711a34cc2d
2 changed files with 53 additions and 9 deletions

View File

@ -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::cred::{BucketReachability, Invitation, Lox};
use lox_library::proto; use lox_library::proto;
use lox_library::{IssuerPubKey, OPENINV_LENGTH}; use lox_library::{IssuerPubKey, OPENINV_LENGTH};
@ -71,6 +73,21 @@ pub struct PubKeys {
pub invitation_pub: IssuerPubKey, 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] #[serde_as]
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct EncBridgeTable { pub struct EncBridgeTable {
@ -80,7 +97,7 @@ pub struct EncBridgeTable {
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct LoxCredential { pub struct LoxCredential {
pub lox_credential: Lox, pub lox_credential: Lox,
pub bridgeline: Option<BridgeLine>, pub bridgelines: Option<Vec<BridgeLine>>,
pub invitation: Option<Invitation>, pub invitation: Option<Invitation>,
} }
@ -102,6 +119,17 @@ pub fn generate_reachability_cred(lox_cred: &Lox, encrypted_table: String) -> Bu
bucket.1.unwrap() 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 MAX_LEVEL: usize = 4;
//pub const LEVEL_INTERVAL: [u32; MAX_LEVEL + 1] = [0, 14, 28, 56, 84]; //pub const LEVEL_INTERVAL: [u32; MAX_LEVEL + 1] = [0, 14, 28, 56, 84];
pub fn calc_test_days(trust_level: i64) -> i64 { pub fn calc_test_days(trust_level: i64) -> i64 {

View File

@ -67,7 +67,7 @@ pub fn handle_new_lox_credential(
}; };
let lox_cred = lox_utils::LoxCredential { let lox_cred = lox_utils::LoxCredential {
lox_credential: lox_cred.0, lox_credential: lox_cred.0,
bridgeline: Some(lox_cred.1), bridgelines: Some(vec![lox_cred.1]),
invitation: None, invitation: None,
}; };
log(&format!( log(&format!(
@ -76,7 +76,7 @@ pub fn handle_new_lox_credential(
)); ));
log(&format!( log(&format!(
"Got new bridgeline: {}", "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()) Ok(serde_json::to_string(&lox_cred).unwrap())
} }
@ -176,7 +176,7 @@ pub fn handle_trust_migration(
) { ) {
Ok(level_1_cred) => lox_utils::LoxCredential { Ok(level_1_cred) => lox_utils::LoxCredential {
lox_credential: level_1_cred, lox_credential: level_1_cred,
bridgeline: None, bridgelines: None,
invitation: None, invitation: None,
}, },
Err(e) => { Err(e) => {
@ -243,7 +243,7 @@ pub fn handle_level_up(
) { ) {
Ok(level_up_cred) => lox_utils::LoxCredential { Ok(level_up_cred) => lox_utils::LoxCredential {
lox_credential: level_up_cred, lox_credential: level_up_cred,
bridgeline: None, bridgelines: None,
invitation: None, invitation: None,
}, },
Err(e) => { Err(e) => {
@ -318,7 +318,7 @@ pub fn handle_issue_invite(
}; };
let invitation_cred = lox_utils::LoxCredential { let invitation_cred = lox_utils::LoxCredential {
lox_credential: issue_invite_cred.0, lox_credential: issue_invite_cred.0,
bridgeline: None, bridgelines: None,
invitation: Some(issue_invite_cred.1), invitation: Some(issue_invite_cred.1),
}; };
@ -382,7 +382,7 @@ pub fn handle_redeem_invite(
) { ) {
Ok(issue_invite_cred) => lox_utils::LoxCredential { Ok(issue_invite_cred) => lox_utils::LoxCredential {
lox_credential: issue_invite_cred, lox_credential: issue_invite_cred,
bridgeline: None, bridgelines: None,
invitation: None, invitation: None,
}, },
Err(e) => { Err(e) => {
@ -493,7 +493,7 @@ pub fn handle_blockage_migration(
) { ) {
Ok(lox_cred) => lox_utils::LoxCredential { Ok(lox_cred) => lox_utils::LoxCredential {
lox_credential: lox_cred, lox_credential: lox_cred,
bridgeline: None, bridgelines: None,
invitation: None, invitation: None,
}, },
Err(e) => { Err(e) => {
@ -572,3 +572,19 @@ pub fn get_received_invite_expiry(invite_cred_str: String) -> String {
)); ));
serde_json::to_string(&date_time).unwrap() 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()
}