Add error handling and Invitation expiry getter for wasm
This commit is contained in:
parent
6757702662
commit
aeddbb5d71
|
@ -84,6 +84,11 @@ pub struct LoxCredential {
|
|||
pub invitation: Option<Invitation>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct IssuedInvitation {
|
||||
pub invitation: Invitation,
|
||||
}
|
||||
|
||||
// This should also check the pubkey
|
||||
pub fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> {
|
||||
invite.try_into()
|
||||
|
|
|
@ -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_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} from "./pkg/lox_wasm.js";
|
||||
let pubkeys = await simple_request("/pubkeys");
|
||||
console.log("Got pubkeys: " + pubkeys);
|
||||
|
||||
|
@ -47,7 +47,7 @@ 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_invite_expiry(open_lox_cred);
|
||||
let info_four = get_issued_invite_expiry(open_lox_cred);
|
||||
console.log("Last upgrade time: "+info_four);
|
||||
let requested_trust_promo = trust_promotion(open_lox_cred, pubkeys);
|
||||
|
||||
|
@ -142,6 +142,10 @@ let prepared_invitation = prepare_invite(lox_cred);
|
|||
// Trusted Invitation Request
|
||||
let requested_invitation = redeem_invite(prepared_invitation, pubkeys);
|
||||
// Redeem an Invitation cred
|
||||
|
||||
info_four = get_received_invite_expiry(prepared_invitation);
|
||||
console.log("Last upgrade time: "+info_four);
|
||||
|
||||
let lox_cred_from_invite = await init().then(() => {
|
||||
set_panic_hook();
|
||||
let cred = requested_cred("/redeem", requested_invitation).then((response)=> {
|
||||
|
|
|
@ -520,7 +520,6 @@ pub fn get_last_upgrade_time(lox_cred_str: String) -> String {
|
|||
serde_json::to_string(&date_time).unwrap()
|
||||
}
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_trust_level(lox_cred_str: String) -> String {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
|
@ -544,14 +543,32 @@ pub fn get_invites_remaining(lox_cred_str: String) -> String {
|
|||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_invite_expiry(lox_cred_str: String) -> String {
|
||||
pub fn get_issued_invite_expiry(lox_cred_str: String) -> String {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
let expiry = (scalar_u32(&lox_cred.invitation.unwrap().date).unwrap()+15) as i32;
|
||||
let date_time = JulianDay::new(expiry as i32).to_date();
|
||||
match lox_cred.invitation {
|
||||
Some(invitation) => {
|
||||
let expiry = (scalar_u32(&invitation.date).unwrap() + 15) as i32;
|
||||
let date_time = JulianDay::new(expiry).to_date();
|
||||
println!("Datetime is: {:?}", date_time);
|
||||
log(&format!(
|
||||
"Invitation Expiry {}",
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
));
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
}
|
||||
None => serde_json::to_string("No Invitation Issued").unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_received_invite_expiry(invite_cred_str: String) -> String {
|
||||
let invite_cred: lox_utils::IssuedInvitation = serde_json::from_str(&invite_cred_str).unwrap();
|
||||
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);
|
||||
log(&format!(
|
||||
"Invitation Expiry {}",
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
));
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue