Add up to level up 4

This commit is contained in:
onyinyang 2023-02-23 22:16:45 -05:00
parent 62094dc8cf
commit 45e729d107
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
3 changed files with 62 additions and 4 deletions

View File

@ -23,6 +23,7 @@ serde-wasm-bindgen = "0.4.5"
console_error_panic_hook = "0.1.7" console_error_panic_hook = "0.1.7"
js-sys = "0.3.61" js-sys = "0.3.61"
rand = { version = "0.7", features = ["wasm-bindgen"] } rand = { version = "0.7", features = ["wasm-bindgen"] }
zkp = "0.8.0"
[dependencies.chrono] [dependencies.chrono]
version = "0.4.19" version = "0.4.19"

View File

@ -65,6 +65,35 @@ let level_two_cred = await init().then(() => {
return cred; return cred;
}); });
//Update reachability cred
encrypted_table = await simple_request("/reachability");
console.log("Got Encrypted Table: " + encrypted_table);
let requested_level_three = level_up(level_two_cred, encrypted_table, pubkeys);
let level_three_cred = await init().then(() => {
set_panic_hook();
let cred = requested_cred("/levelup", requested_level_three).then((response)=> {
console.log("Got new Level 3 Lox Credential: " + response);
return handle_level_up(requested_level_three, response, pubkeys);
});
return cred;
});
//Update reachability cred
encrypted_table = await simple_request("/reachability");
console.log("Got Encrypted Table: " + encrypted_table);
let requested_level_four = level_up(level_three_cred, encrypted_table, pubkeys);
let level_four_cred = await init().then(() => {
set_panic_hook();
let cred = requested_cred("/levelup", requested_level_four).then((response)=> {
console.log("Got new Level 4 Lox Credential: " + response);
return handle_level_up(requested_level_four, 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);

View File

@ -6,7 +6,7 @@ use lox::bridge_table::{BridgeLine,from_scalar,BridgeTable, ENC_BUCKET_BYTES};
use lox::cred::{BucketReachability, Lox, Migration}; 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, scalar_u32};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::{serde_as}; use serde_with::{serde_as};
use serde_json; use serde_json;
@ -14,6 +14,7 @@ use serde_json;
use std::array::TryFromSliceError; use std::array::TryFromSliceError;
use std::{panic}; use std::{panic};
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use zkp::ProofError;
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
@ -74,6 +75,23 @@ fn test_today(days: i64) -> u32 {
JulianDay::from(naive_now_plus).inner().try_into().unwrap() JulianDay::from(naive_now_plus).inner().try_into().unwrap()
} }
//pub const MAX_LEVEL: usize = 4;
//pub const LEVEL_INTERVAL: [u32; MAX_LEVEL + 1] = [0, 14, 28, 56, 84];
fn calc_test_days(lox_cred: &Lox) -> Result<i64, ProofError> {
let trust_level: i64 = match scalar_u32(&lox_cred.trust_level) {
Some(v) => v as i64,
None => return Err(ProofError::VerificationFailure),
};
let mut total = 31;
// for level in 0..trust_level {
// let level_interval: u32 = LEVEL_INTERVAL[trust_level as usize];
// total += level_interval;
total += trust_level*85;
// }
Ok(total)
}
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(js_namespace = console)] #[wasm_bindgen(js_namespace = console)]
@ -269,13 +287,22 @@ pub fn level_up(level_one_cred: String, encrypted_table: String, lox_pub: String
// In this case, the maximum of 85 can be used to test all level ups // In this case, the maximum of 85 can be used to test all level ups
// in production this should just use the today() function // in production this should just use the today() function
// decrypt trust level and use to calculate the correct date for now // decrypt trust level and use to calculate the correct date for now
// The trust level has to be at least 1
let test_cumulative_days = match calc_test_days(&lox_cred) {
Ok(v) => v,
Err(e) => {
log(&format!("Error: {:?}", e.to_string()));
return Err(JsValue::from(e.to_string()));
}
};
log(&format!( log(&format!(
"TEST ONLY: Add 31 (open invitation) + x*85 days to today's date: {}", "TEST ONLY: Add 31 (open invitation) + Trust Level*85 days to today's date: {}", test_today(test_cumulative_days)
test_today(31+85)
)); ));
let lu_result = let lu_result =
//CHANGE add_today(31) to today() for production //CHANGE add_today(31) to today() for production
match level_up::request(&lox_cred, &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, test_today(31+85)) { match level_up::request(&lox_cred, &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, test_today(test_cumulative_days)) {
Ok(lu_result) => lu_result, Ok(lu_result) => lu_result,
Err(e) => { Err(e) => {
log(&format!("Error: {:?}", e.to_string())); log(&format!("Error: {:?}", e.to_string()));
@ -295,6 +322,7 @@ pub fn level_up(level_one_cred: String, encrypted_table: String, lox_pub: String
Ok(serde_json::to_string(&req_state).unwrap()) Ok(serde_json::to_string(&req_state).unwrap())
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn handle_level_up( pub fn handle_level_up(
levelup_request: String, levelup_request: String,