Add more common functions to lox_utils, clean up lox_wasm
This commit is contained in:
parent
003d9c886b
commit
54c5a837ad
|
@ -912,8 +912,8 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"lox",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"zkp",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -14,8 +14,8 @@ repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox.git/"
|
|||
[dependencies]
|
||||
lox = {path = "../lox-library", version = "0.1.0"}
|
||||
serde = "1"
|
||||
serde_json = "1.0.96"
|
||||
serde_with = "3.0.0"
|
||||
zkp = "0.8.0"
|
||||
|
||||
|
||||
[features]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use lox::bridge_table::{BridgeLine, ENC_BUCKET_BYTES};
|
||||
use lox::cred::{Invitation, Lox};
|
||||
use lox::bridge_table::{from_scalar, BridgeLine, BridgeTable, ENC_BUCKET_BYTES};
|
||||
use lox::cred::{BucketReachability, Invitation, Lox};
|
||||
use lox::proto;
|
||||
use lox::{IssuerPubKey, OPENINV_LENGTH};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -81,3 +81,22 @@ pub struct LoxCredential {
|
|||
pub fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> {
|
||||
invite.try_into()
|
||||
}
|
||||
|
||||
pub fn generate_reachability_cred(lox_cred: &Lox, encrypted_table: String) -> BucketReachability {
|
||||
let (id, key) = from_scalar(lox_cred.bucket).unwrap();
|
||||
let enc_buckets: EncBridgeTable = serde_json::from_str(&encrypted_table).unwrap();
|
||||
let bucket = BridgeTable::decrypt_bucket(id, &key, &enc_buckets.etable[id as usize]).unwrap();
|
||||
bucket.1.unwrap()
|
||||
}
|
||||
|
||||
//pub const MAX_LEVEL: usize = 4;
|
||||
//pub const LEVEL_INTERVAL: [u32; MAX_LEVEL + 1] = [0, 14, 28, 56, 84];
|
||||
pub fn calc_test_days(trust_level: i64) -> i64 {
|
||||
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;
|
||||
// }
|
||||
total
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use chrono::{Duration, Utc};
|
||||
use julianday::JulianDay;
|
||||
use lox::bridge_table::{from_scalar, BridgeTable};
|
||||
use lox::cred::{BucketReachability, Invitation, Lox, Migration};
|
||||
use lox::cred::{Invitation, Lox, Migration};
|
||||
use lox::proto::{
|
||||
blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite,
|
||||
redeem_invite, trust_promotion,
|
||||
|
@ -9,7 +8,6 @@ use lox::proto::{
|
|||
use lox::scalar_u32;
|
||||
use std::panic;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use zkp::ProofError;
|
||||
|
||||
fn today() -> u32 {
|
||||
let naive_now = Utc::now().date_naive();
|
||||
|
@ -22,12 +20,10 @@ fn test_today(days: i64) -> u32 {
|
|||
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> {
|
||||
fn calc_test_days(lox_cred: &Lox) -> Result<i64, String> {
|
||||
let trust_level: i64 = match scalar_u32(&lox_cred.trust_level) {
|
||||
Some(v) => v as i64,
|
||||
None => return Err(ProofError::VerificationFailure),
|
||||
None => return Err("Error: Trust level does not exist".to_string()),
|
||||
};
|
||||
let mut total = 31;
|
||||
// for level in 0..trust_level {
|
||||
|
@ -233,13 +229,6 @@ pub fn handle_trust_migration(
|
|||
Ok(serde_json::to_string(&level_one_cred).unwrap())
|
||||
}
|
||||
|
||||
fn generate_reachability_cred(lox_cred: &Lox, encrypted_table: String) -> BucketReachability {
|
||||
let (id, key) = from_scalar(lox_cred.bucket).unwrap();
|
||||
let enc_buckets: lox_utils::EncBridgeTable = serde_json::from_str(&encrypted_table).unwrap();
|
||||
let bucket = BridgeTable::decrypt_bucket(id, &key, &enc_buckets.etable[id as usize]).unwrap();
|
||||
bucket.1.unwrap()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn level_up(
|
||||
level_one_cred: String,
|
||||
|
@ -248,7 +237,8 @@ pub fn level_up(
|
|||
) -> 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 reach_cred = generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
|
||||
let reach_cred =
|
||||
lox_utils::generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
|
||||
|
||||
// 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
|
||||
|
@ -258,8 +248,8 @@ pub fn level_up(
|
|||
let test_cumulative_days = match calc_test_days(&lox_cred.lox_credential) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
log(&format!("Error: {:?}", e.to_string()));
|
||||
return Err(JsValue::from(e.to_string()));
|
||||
log(&format!("Error: {:?}", e));
|
||||
return Err(JsValue::from(e));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -331,7 +321,8 @@ pub fn issue_invite(
|
|||
) -> 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 reach_cred = generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
|
||||
let reach_cred =
|
||||
lox_utils::generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
|
||||
|
||||
let issue_result = match issue_invite::request(
|
||||
&lox_cred.lox_credential,
|
||||
|
|
Loading…
Reference in New Issue