Add getter functions for wasm Lox credential attributes
This commit is contained in:
parent
d7613eb514
commit
6757702662
|
@ -16,7 +16,7 @@ import init, {
|
|||
handle_check_blockage,
|
||||
blockage_migration,
|
||||
handle_blockage_migration,
|
||||
set_panic_hook } from "./pkg/lox_wasm.js";
|
||||
set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_invite_expiry} from "./pkg/lox_wasm.js";
|
||||
let pubkeys = await simple_request("/pubkeys");
|
||||
console.log("Got pubkeys: " + pubkeys);
|
||||
|
||||
|
@ -41,6 +41,14 @@ 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_invite_expiry(open_lox_cred);
|
||||
console.log("Last upgrade time: "+info_four);
|
||||
let requested_trust_promo = trust_promotion(open_lox_cred, pubkeys);
|
||||
|
||||
// Get Migration credential for Trust Promotion from Trust Level 0 -> 1
|
||||
|
@ -95,6 +103,10 @@ lox_cred = await init().then(() => {
|
|||
return cred;
|
||||
});
|
||||
|
||||
info_three = get_invites_remaining(lox_cred);
|
||||
console.log("Last upgrade time: "+info_three);
|
||||
info_four = get_invite_expiry(lox_cred);
|
||||
console.log("Last upgrade time: "+info_four);
|
||||
|
||||
// Update reachability cred
|
||||
encrypted_table = await simple_request("/reachability");
|
||||
|
|
|
@ -5,6 +5,7 @@ use lox_library::proto::{
|
|||
blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite,
|
||||
redeem_invite, trust_promotion,
|
||||
};
|
||||
use lox_library::scalar_u32;
|
||||
use std::panic;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
@ -506,3 +507,51 @@ pub fn handle_blockage_migration(
|
|||
));
|
||||
Ok(serde_json::to_string(&lox_cred).unwrap())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_last_upgrade_time(lox_cred_str: String) -> String {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
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!(
|
||||
"Time of last upgrade {}",
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
));
|
||||
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();
|
||||
let trust_level = scalar_u32(&lox_cred.lox_credential.trust_level).unwrap();
|
||||
log(&format!(
|
||||
"Trust level {}",
|
||||
serde_json::to_string(&trust_level).unwrap()
|
||||
));
|
||||
serde_json::to_string(&trust_level).unwrap()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_invites_remaining(lox_cred_str: String) -> String {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
let invites = scalar_u32(&lox_cred.lox_credential.invites_remaining);
|
||||
log(&format!(
|
||||
"Invites remaining {}",
|
||||
serde_json::to_string(&invites).unwrap()
|
||||
));
|
||||
serde_json::to_string(&invites).unwrap()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_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();
|
||||
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