Add better serde error handling to wasm functions

This commit is contained in:
onyinyang 2023-12-20 18:45:04 -05:00
parent c1f6ab0b77
commit 075d51b088
4 changed files with 238 additions and 72 deletions

View File

@ -6,7 +6,7 @@ use lox_library::{
blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite,
redeem_invite, trust_promotion,
},
BridgeAuth, BridgeDb, OpenInvitationError, IssuerPubKey,
BridgeAuth, BridgeDb, IssuerPubKey, OpenInvitationError,
};
use rdsys_backend::proto::{Resource, ResourceState};
use serde::{Deserialize, Serialize};

View File

@ -230,7 +230,7 @@ impl BridgeDb {
self.daily_bridges_distributed = 0;
}
if self.openinv_buckets.is_empty() {
return Err(OpenInvitationError::NoBridgesAvailable)
return Err(OpenInvitationError::NoBridgesAvailable);
}
if self.daily_bridges_distributed < MAX_DAILY_BRIDGES {
if self.current_k < OPENINV_K && !self.distributed_buckets.is_empty() {

View File

@ -16,7 +16,7 @@ import init, {
handle_check_blockage,
blockage_migration,
handle_blockage_migration,
set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_issued_invite_expiry, get_received_invite_expiry} from "./pkg/lox_wasm.js";
set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_issued_invite_expiry, get_received_invite_expiry, get_bridgelines_from_bucket} from "./pkg/lox_wasm.js";
let pubkeys = await simple_request("/pubkeys");
console.log("Got pubkeys: " + pubkeys);
@ -41,14 +41,12 @@ let open_lox_cred = await init().then(() => {
return cred;
});
let info = get_last_upgrade_time(open_lox_cred);
console.log("Last upgrade time: "+info);
let info_two = get_trust_level(open_lox_cred);
console.log("Last upgrade time: "+info_two);
let info_three = get_invites_remaining(open_lox_cred);
console.log("Last upgrade time: "+info_three);
let info_four = get_issued_invite_expiry(open_lox_cred);
console.log("Last upgrade time: "+info_four);
get_last_upgrade_time(open_lox_cred);
get_trust_level(open_lox_cred);
get_invites_remaining(open_lox_cred);
let encrypted_table = await simple_request("/reachability");
let info_five = get_bridgelines_from_bucket(open_lox_cred, encrypted_table);
console.log("Bridgelines available: "+info_five);
let requested_trust_promo = trust_promotion(open_lox_cred, pubkeys);
// Get Migration credential for Trust Promotion from Trust Level 0 -> 1
@ -74,7 +72,7 @@ let lox_cred = await init().then(() => {
return cred;
});
let encrypted_table = await simple_request("/reachability");
encrypted_table = await simple_request("/reachability");
console.log("Got Encrypted Table: " + encrypted_table);
let requested_level_two = level_up(lox_cred, encrypted_table, pubkeys);

View File

@ -41,7 +41,10 @@ pub fn open_invite(invite: &[u8]) -> Result<String, JsValue> {
"Formatted open invite request: {}",
serde_json::to_string(&req_state).unwrap()
));
Ok(serde_json::to_string(&req_state).unwrap())
match serde_json::to_string(&req_state) {
Ok(req_state) => Ok(req_state),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -98,8 +101,14 @@ pub fn handle_new_lox_credential(
#[wasm_bindgen]
pub fn trust_promotion(open_lox_cred: String, lox_pub: String) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&open_lox_cred).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&open_lox_cred) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let tp_result =
match trust_promotion::request(&lox_cred.lox_credential, &pubkeys.lox_pub, today()) {
Ok(tp_result) => tp_result,
@ -116,7 +125,10 @@ pub fn trust_promotion(open_lox_cred: String, lox_pub: String) -> Result<String,
"Formatted Trust Promotion request: {}",
serde_json::to_string(&req_state).unwrap()
));
Ok(serde_json::to_string(&req_state).unwrap())
match serde_json::to_string(&req_state) {
Ok(req_state) => Ok(req_state),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -124,9 +136,15 @@ pub fn handle_trust_promotion(
trust_promo_request: String,
trust_promo_response: String,
) -> Result<String, JsValue> {
let req_state: lox_utils::TrustReqState = serde_json::from_str(&trust_promo_request).unwrap();
let req_state: lox_utils::TrustReqState = match serde_json::from_str(&trust_promo_request) {
Ok(req_state) => req_state,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&trust_promo_response).unwrap();
let deserialized_response = match serde_json::from_str(&trust_promo_response) {
Ok(deserialized_response) => deserialized_response,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let migration_cred =
match trust_promotion::handle_response(deserialized_state, deserialized_response) {
Ok(migration_cred) => migration_cred,
@ -139,7 +157,10 @@ pub fn handle_trust_promotion(
"Got new Migration Credential: {}",
serde_json::to_string(&migration_cred).unwrap()
));
Ok(serde_json::to_string(&migration_cred).unwrap())
match serde_json::to_string(&migration_cred) {
Ok(migration_cred) => Ok(migration_cred),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -148,8 +169,14 @@ pub fn trust_migration(
trust_promo_cred: String,
lox_pub: String,
) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&open_lox_cred).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&open_lox_cred) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let mig_cred: Migration = serde_json::from_str(&trust_promo_cred).unwrap();
let tm_result = match migration::request(
&lox_cred.lox_credential,
@ -171,7 +198,10 @@ pub fn trust_migration(
"Formatted Trust Migration request: {}",
serde_json::to_string(&req_state).unwrap()
));
Ok(serde_json::to_string(&req_state).unwrap())
match serde_json::to_string(&req_state) {
Ok(req_state) => Ok(req_state),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -180,10 +210,19 @@ pub fn handle_trust_migration(
trust_migration_response: String,
lox_pub: String,
) -> Result<String, JsValue> {
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let req_state: lox_utils::MigReqState = serde_json::from_str(&trust_migration_request).unwrap();
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let req_state: lox_utils::MigReqState = match serde_json::from_str(&trust_migration_request) {
Ok(req_state) => req_state,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&trust_migration_response).unwrap();
let deserialized_response = match serde_json::from_str(&trust_migration_response) {
Ok(deserialized_response) => deserialized_response,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let level_one_cred = match migration::handle_response(
deserialized_state,
deserialized_response,
@ -203,7 +242,11 @@ pub fn handle_trust_migration(
"Got new Level 1 Credential: {}",
serde_json::to_string(&level_one_cred).unwrap()
));
Ok(serde_json::to_string(&level_one_cred).unwrap())
match serde_json::to_string(&level_one_cred) {
Ok(level_one_cred) => Ok(level_one_cred),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -212,8 +255,14 @@ pub fn level_up(
encrypted_table: String,
lox_pub: String,
) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&level_one_cred).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&level_one_cred) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let reach_cred =
lox_utils::generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
@ -238,7 +287,10 @@ pub fn level_up(
"Formatted Level Up request: {}",
serde_json::to_string(&req_state).unwrap()
));
Ok(serde_json::to_string(&req_state).unwrap())
match serde_json::to_string(&req_state) {
Ok(req_state) => Ok(req_state),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -247,10 +299,19 @@ pub fn handle_level_up(
levelup_response: String,
lox_pub: String,
) -> Result<String, JsValue> {
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let req_state: lox_utils::LevelupReqState = serde_json::from_str(&levelup_request).unwrap();
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let req_state: lox_utils::LevelupReqState = match serde_json::from_str(&levelup_request) {
Ok(req_state) => req_state,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&levelup_response).unwrap();
let deserialized_response = match serde_json::from_str(&levelup_response) {
Ok(deserialized_response) => deserialized_response,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let level_up_cred = match level_up::handle_response(
deserialized_state,
deserialized_response,
@ -270,7 +331,10 @@ pub fn handle_level_up(
"Got new Level Up Credential: {}",
serde_json::to_string(&level_up_cred).unwrap()
));
Ok(serde_json::to_string(&level_up_cred).unwrap())
match serde_json::to_string(&level_up_cred) {
Ok(level_up_cred) => Ok(level_up_cred),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -279,8 +343,14 @@ pub fn issue_invite(
encrypted_table: String,
lox_pub: String,
) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&trusted_cred).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&trusted_cred) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let reach_cred =
lox_utils::generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
@ -305,7 +375,10 @@ pub fn issue_invite(
"Formatted Issue Invite request: {}",
serde_json::to_string(&req_state).unwrap()
));
Ok(serde_json::to_string(&req_state).unwrap())
match serde_json::to_string(&req_state) {
Ok(req_state) => Ok(req_state),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -314,11 +387,20 @@ pub fn handle_issue_invite(
issue_invite_response: String,
lox_pub: String,
) -> Result<String, JsValue> {
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let req_state: lox_utils::IssueInviteReqState =
serde_json::from_str(&issue_invite_request).unwrap();
match serde_json::from_str(&issue_invite_request) {
Ok(req_state) => req_state,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&issue_invite_response).unwrap();
let deserialized_response = match serde_json::from_str(&issue_invite_response) {
Ok(deserialized_response) => deserialized_response,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let issue_invite_cred = match issue_invite::handle_response(
deserialized_state,
deserialized_response,
@ -341,25 +423,40 @@ pub fn handle_issue_invite(
"Got new Invitation Credential and Lox Credential: {}",
serde_json::to_string(&invitation_cred).unwrap()
));
Ok(serde_json::to_string(&invitation_cred).unwrap())
match serde_json::to_string(&invitation_cred) {
Ok(invitation_cred) => Ok(invitation_cred),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
// Separate Trusted Invite from credential prior to passing it to friend
#[wasm_bindgen]
pub fn prepare_invite(invitation_cred: String) -> String {
let cred: lox_utils::LoxCredential = serde_json::from_str(&invitation_cred).unwrap();
pub fn prepare_invite(invitation_cred: String) -> Result<String, JsValue> {
let cred: lox_utils::LoxCredential = match serde_json::from_str(&invitation_cred) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
log(&format!(
"Prepared Invitation: {}",
serde_json::to_string(&cred.invitation).unwrap()
));
serde_json::to_string(&cred.invitation).unwrap()
match serde_json::to_string(&cred.invitation) {
Ok(invitation) => Ok(invitation),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
//
#[wasm_bindgen]
pub fn redeem_invite(invitation: String, lox_pub: String) -> Result<String, JsValue> {
let invitation_cred: Invitation = serde_json::from_str(&invitation).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let invitation_cred: Invitation = match serde_json::from_str(&invitation) {
Ok(invitation_cred) => invitation_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let redeem_result =
match redeem_invite::request(&invitation_cred, &pubkeys.invitation_pub, today()) {
Ok(redeem_result) => redeem_result,
@ -376,7 +473,10 @@ pub fn redeem_invite(invitation: String, lox_pub: String) -> Result<String, JsVa
"Formatted Redeem Invite request: {}",
serde_json::to_string(&req_state).unwrap()
));
Ok(serde_json::to_string(&req_state).unwrap())
match serde_json::to_string(&req_state) {
Ok(req_state) => Ok(req_state),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -385,11 +485,19 @@ pub fn handle_redeem_invite(
redeem_invite_response: String,
lox_pub: String,
) -> Result<String, JsValue> {
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let req_state: lox_utils::RedeemReqState =
serde_json::from_str(&redeem_invite_request).unwrap();
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let req_state: lox_utils::RedeemReqState = match serde_json::from_str(&redeem_invite_request) {
Ok(req_state) => req_state,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&redeem_invite_response).unwrap();
let deserialized_response = match serde_json::from_str(&redeem_invite_response) {
Ok(deserialized_response) => deserialized_response,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let redeem_invite_cred = match redeem_invite::handle_response(
deserialized_state,
deserialized_response,
@ -409,14 +517,23 @@ pub fn handle_redeem_invite(
"Got new Trusted Lox Credential from Invitation: {}",
serde_json::to_string(&redeem_invite_cred).unwrap()
));
Ok(serde_json::to_string(&redeem_invite_cred).unwrap())
match serde_json::to_string(&redeem_invite_cred) {
Ok(redeem_invite_cred) => Ok(redeem_invite_cred),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
pub fn check_blockage(lox_cred: String, lox_pub: String) -> Result<String, JsValue> {
let lox: lox_utils::LoxCredential = serde_json::from_str(&lox_cred).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let cb_result = match check_blockage::request(&lox.lox_credential, &pubkeys.lox_pub) {
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let cb_result = match check_blockage::request(&lox_cred.lox_credential, &pubkeys.lox_pub) {
Ok(cb_result) => cb_result,
Err(e) => {
log(&format!("Error: {:?}", e.to_string()));
@ -431,7 +548,10 @@ pub fn check_blockage(lox_cred: String, lox_pub: String) -> Result<String, JsVal
"Formatted Check Blockage request: {}",
serde_json::to_string(&req_state).unwrap()
));
Ok(serde_json::to_string(&req_state).unwrap())
match serde_json::to_string(&req_state) {
Ok(req_state) => Ok(req_state),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -440,9 +560,15 @@ pub fn handle_check_blockage(
check_blockage_response: String,
) -> Result<String, JsValue> {
let req_state: lox_utils::CheckBlockageReqState =
serde_json::from_str(&check_blockage_request).unwrap();
match serde_json::from_str(&check_blockage_request) {
Ok(req_state) => req_state,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&check_blockage_response).unwrap();
let deserialized_response = match serde_json::from_str(&check_blockage_response) {
Ok(deserialized_response) => deserialized_response,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let migration_cred =
match check_blockage::handle_response(deserialized_state, deserialized_response) {
Ok(migration_cred) => migration_cred,
@ -455,7 +581,10 @@ pub fn handle_check_blockage(
"Got new Blockage Migration Credential: {}",
serde_json::to_string(&migration_cred).unwrap()
));
Ok(serde_json::to_string(&migration_cred).unwrap())
match serde_json::to_string(&migration_cred) {
Ok(migration_cred) => Ok(migration_cred),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -464,8 +593,14 @@ pub fn blockage_migration(
check_migration_cred: String,
lox_pub: String,
) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let mig_cred: Migration = serde_json::from_str(&check_migration_cred).unwrap();
let bm_result = match blockage_migration::request(
&lox_cred.lox_credential,
@ -487,7 +622,10 @@ pub fn blockage_migration(
"Formatted Blockage Migration request: {}",
serde_json::to_string(&req_state).unwrap()
));
Ok(serde_json::to_string(&req_state).unwrap())
match serde_json::to_string(&req_state) {
Ok(req_state) => Ok(req_state),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
@ -496,11 +634,20 @@ pub fn handle_blockage_migration(
blockage_migration_response: String,
lox_pub: String,
) -> Result<String, JsValue> {
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
Ok(pubkeys) => pubkeys,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let req_state: lox_utils::BlockageMigReqState =
serde_json::from_str(&blockage_migration_request).unwrap();
match serde_json::from_str(&blockage_migration_request) {
Ok(req_state) => req_state,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let deserialized_state = req_state.state;
let deserialized_response = serde_json::from_str(&blockage_migration_response).unwrap();
let deserialized_response = match serde_json::from_str(&blockage_migration_response) {
Ok(deserialized_response) => deserialized_response,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let lox_cred = match blockage_migration::handle_response(
deserialized_state,
deserialized_response,
@ -520,12 +667,18 @@ pub fn handle_blockage_migration(
"Got new Lox Credential after Migration: {}",
serde_json::to_string(&lox_cred).unwrap()
));
Ok(serde_json::to_string(&lox_cred).unwrap())
match serde_json::to_string(&lox_cred) {
Ok(lox_cred) => Ok(lox_cred),
Err(e) => Err(JsValue::from(e.to_string())),
}
}
#[wasm_bindgen]
pub fn get_last_upgrade_time(lox_cred_str: String) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let upgrade_date = scalar_u32(&lox_cred.lox_credential.level_since).unwrap();
let date_time = JulianDay::new(upgrade_date as i32).to_date();
log(&format!(
@ -540,7 +693,10 @@ pub fn get_last_upgrade_time(lox_cred_str: String) -> Result<String, JsValue> {
#[wasm_bindgen]
pub fn get_trust_level(lox_cred_str: String) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let trust_level = scalar_u32(&lox_cred.lox_credential.trust_level).unwrap();
log(&format!(
"Trust level {}",
@ -554,7 +710,10 @@ pub fn get_trust_level(lox_cred_str: String) -> Result<String, JsValue> {
#[wasm_bindgen]
pub fn get_invites_remaining(lox_cred_str: String) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let invites = scalar_u32(&lox_cred.lox_credential.invites_remaining);
log(&format!(
"Invites remaining {}",
@ -568,7 +727,10 @@ pub fn get_invites_remaining(lox_cred_str: String) -> Result<String, JsValue> {
#[wasm_bindgen]
pub fn get_issued_invite_expiry(lox_cred_str: String) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
match lox_cred.invitation {
Some(invitation) => {
let expiry = (scalar_u32(&invitation.date).unwrap() + 15) as i32;
@ -589,7 +751,10 @@ pub fn get_issued_invite_expiry(lox_cred_str: String) -> Result<String, JsValue>
#[wasm_bindgen]
pub fn get_received_invite_expiry(invite_cred_str: String) -> Result<String, JsValue> {
let invite_cred: lox_utils::IssuedInvitation = serde_json::from_str(&invite_cred_str).unwrap();
let invite_cred: lox_utils::IssuedInvitation = match serde_json::from_str(&invite_cred_str) {
Ok(invite_cred) => invite_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let expiry = (scalar_u32(&invite_cred.invitation.date).unwrap() + 15) as i32;
let date_time = JulianDay::new(expiry).to_date();
println!("Datetime is: {:?}", date_time);
@ -608,11 +773,14 @@ pub fn get_bridgelines_from_bucket(
lox_cred_str: String,
encrypted_table: String,
) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) {
Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())),
};
let bridgelines =
lox_utils::get_credential_bridgelines(&lox_cred.lox_credential, encrypted_table);
log(&format!(
"Lox BridgeLines Expiry {}",
"Lox BridgeLines available {}",
serde_json::to_string(&bridgelines).unwrap()
));
match serde_json::to_string(&bridgelines) {