Logic for level up, reachability credential unimplemented
This commit is contained in:
parent
f44ac0ae9f
commit
d8cdf3ccab
|
@ -5,6 +5,8 @@ import init, {
|
||||||
handle_trust_promotion,
|
handle_trust_promotion,
|
||||||
trust_migration,
|
trust_migration,
|
||||||
handle_trust_migration,
|
handle_trust_migration,
|
||||||
|
level_up,
|
||||||
|
handle_level_up,
|
||||||
set_panic_hook } from "./pkg/lox_wasm.js";
|
set_panic_hook } from "./pkg/lox_wasm.js";
|
||||||
let pubkeys = await simple_request("/pubkeys");
|
let pubkeys = await simple_request("/pubkeys");
|
||||||
console.log("Got pubkeys: " + pubkeys);
|
console.log("Got pubkeys: " + pubkeys);
|
||||||
|
@ -38,12 +40,11 @@ let trust_promo_cred = await init().then(() => {
|
||||||
return cred;
|
return cred;
|
||||||
});
|
});
|
||||||
|
|
||||||
let reachability_cred = await simple_request("/reachability");
|
|
||||||
console.log("Got reachability credential: " + reachability_cred);
|
console.log("Got reachability credential: " + reachability_cred);
|
||||||
|
|
||||||
let requested_trust_migration = trust_migration(open_lox_cred, trust_promo_cred, pubkeys);
|
let requested_trust_migration = trust_migration(open_lox_cred, trust_promo_cred, pubkeys);
|
||||||
|
|
||||||
let level_1_cred = await init().then(() => {
|
let level_one_cred = await init().then(() => {
|
||||||
set_panic_hook();
|
set_panic_hook();
|
||||||
let cred = requested_cred("/trustmig", requested_trust_migration).then((response)=> {
|
let cred = requested_cred("/trustmig", requested_trust_migration).then((response)=> {
|
||||||
console.log("Got new Level 1 Lox Credential: " + response);
|
console.log("Got new Level 1 Lox Credential: " + response);
|
||||||
|
@ -52,6 +53,18 @@ let level_1_cred = await init().then(() => {
|
||||||
return cred;
|
return cred;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let reachability_cred = await simple_request("/reachability");
|
||||||
|
let requested_level_two = level_up(level_one_cred, reachability_cred, pubkeys);
|
||||||
|
|
||||||
|
let level_two_cred = await init().then(() => {
|
||||||
|
set_panic_hook();
|
||||||
|
let cred = requested_cred("/levelup", requested_level_two).then((response)=> {
|
||||||
|
console.log("Got new Level 2 Lox Credential: " + response);
|
||||||
|
return handle_level_up(requested_level_two, response, pubkeys);
|
||||||
|
});
|
||||||
|
return cred;
|
||||||
|
});
|
||||||
|
|
||||||
function requested_cred(command, requested) {
|
function requested_cred(command, requested) {
|
||||||
return new Promise((fulfill, reject) => {
|
return new Promise((fulfill, reject) => {
|
||||||
let req = JSON.parse(requested);
|
let req = JSON.parse(requested);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
use julianday::JulianDay;
|
use julianday::JulianDay;
|
||||||
use lox::bridge_table::BridgeLine;
|
use lox::bridge_table::BridgeLine;
|
||||||
use lox::cred::Lox;
|
use lox::cred::{BucketReachability, Lox, Migration};
|
||||||
use lox::proto::{open_invite, trust_promotion, migration, level_up,
|
use lox::proto::{open_invite, trust_promotion, migration, level_up,
|
||||||
issue_invite, redeem_invite, check_blockage, blockage_migration};
|
issue_invite, redeem_invite, check_blockage, blockage_migration};
|
||||||
use lox::{IssuerPubKey, OPENINV_LENGTH};
|
use lox::{IssuerPubKey, OPENINV_LENGTH};
|
||||||
|
@ -30,6 +30,11 @@ struct MigReqState {
|
||||||
state: migration::State,
|
state: migration::State,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
struct LevelupReqState {
|
||||||
|
request: level_up::Request,
|
||||||
|
state: level_up::State,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
struct PubKeys {
|
struct PubKeys {
|
||||||
|
@ -192,11 +197,8 @@ pub fn handle_trust_promotion(
|
||||||
pub fn trust_migration(open_lox_cred: String, trust_promo_cred: String, lox_pub: String) -> Result<String, JsValue> {
|
pub fn trust_migration(open_lox_cred: String, trust_promo_cred: String, lox_pub: String) -> Result<String, JsValue> {
|
||||||
let lox_cred: Credential = serde_json::from_str(&open_lox_cred).unwrap();
|
let lox_cred: Credential = serde_json::from_str(&open_lox_cred).unwrap();
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
let mig_cred = serde_json::from_str(&trust_promo_cred).unwrap();
|
let mig_cred: Migration = serde_json::from_str(&trust_promo_cred).unwrap();
|
||||||
// To test creation of the credential we need to advance the day to 30
|
|
||||||
// in production this should just use the today() function
|
|
||||||
let tm_result =
|
let tm_result =
|
||||||
//CHANGE add_today(31) to today() for production
|
|
||||||
match migration::request(&lox_cred.lox_credential, &mig_cred, &pubkeys.lox_pub, &pubkeys.migration_pub) {
|
match migration::request(&lox_cred.lox_credential, &mig_cred, &pubkeys.lox_pub, &pubkeys.migration_pub) {
|
||||||
Ok(tm_result) => tm_result,
|
Ok(tm_result) => tm_result,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -227,7 +229,7 @@ pub fn handle_trust_migration(
|
||||||
let req_state: MigReqState = serde_json::from_str(&trust_migration_request).unwrap();
|
let req_state: MigReqState = serde_json::from_str(&trust_migration_request).unwrap();
|
||||||
let deserialized_state = req_state.state;
|
let deserialized_state = req_state.state;
|
||||||
let deserialized_response = serde_json::from_str(&trust_migration_response).unwrap();
|
let deserialized_response = serde_json::from_str(&trust_migration_response).unwrap();
|
||||||
let level_1_cred =
|
let level_one_cred =
|
||||||
match migration::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
|
match migration::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
|
||||||
Ok(level_1_cred) => level_1_cred,
|
Ok(level_1_cred) => level_1_cred,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -238,10 +240,71 @@ pub fn handle_trust_migration(
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!(
|
log(&format!(
|
||||||
"Got new Level 1 Credential: {}",
|
"Got new Level 1 Credential: {}",
|
||||||
serde_json::to_string(&level_1_cred).unwrap()
|
serde_json::to_string(&level_one_cred).unwrap()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(serde_json::to_string(&level_1_cred).unwrap())
|
Ok(serde_json::to_string(&level_one_cred).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn level_up(level_one_cred: String, reachability_cred: String, lox_pub: String) -> Result<String, JsValue> {
|
||||||
|
let lox_cred: Lox = serde_json::from_str(&level_one_cred).unwrap();
|
||||||
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
|
let reach_cred: BucketReachability = serde_json::from_str(&reachability_cred).unwrap();
|
||||||
|
// To test level up of the credential we need to advance the day to the correct interval
|
||||||
|
// In this case, the maximum of 85 can be used to test all level ups
|
||||||
|
// in production this should just use the today() function
|
||||||
|
log(&format!(
|
||||||
|
"TEST ONLY: Add 85 days to today's date: {}",
|
||||||
|
add_today(85)
|
||||||
|
));
|
||||||
|
let lu_result =
|
||||||
|
//CHANGE add_today(31) to today() for production
|
||||||
|
match level_up::request(&lox_cred, &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, add_today(85)) {
|
||||||
|
Ok(lu_result) => lu_result,
|
||||||
|
Err(e) => {
|
||||||
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let req_state = LevelupReqState {
|
||||||
|
request: lu_result.0,
|
||||||
|
state: lu_result.1,
|
||||||
|
};
|
||||||
|
unsafe {
|
||||||
|
log(&format!(
|
||||||
|
"Formatted Level Up request: {}",
|
||||||
|
serde_json::to_string(&req_state).unwrap()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(serde_json::to_string(&req_state).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn handle_level_up(
|
||||||
|
levelup_request: String,
|
||||||
|
levelup_response: String,
|
||||||
|
lox_pub: String
|
||||||
|
) -> Result<String, JsValue> {
|
||||||
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
|
let req_state: LevelupReqState = serde_json::from_str(&levelup_request).unwrap();
|
||||||
|
let deserialized_state = req_state.state;
|
||||||
|
let deserialized_response = serde_json::from_str(&levelup_response).unwrap();
|
||||||
|
let level_up_cred =
|
||||||
|
match level_up::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
|
||||||
|
Ok(level_up_cred) => level_up_cred,
|
||||||
|
Err(e) => {
|
||||||
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
unsafe {
|
||||||
|
log(&format!(
|
||||||
|
"Got new Level Up Credential: {}",
|
||||||
|
serde_json::to_string(&level_up_cred).unwrap()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(serde_json::to_string(&level_up_cred).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue