Add other cargo fmt changes
This commit is contained in:
parent
dc8774f5b8
commit
16ced3c5e0
|
@ -344,7 +344,7 @@ impl BridgeAuth {
|
||||||
}
|
}
|
||||||
while self.bridge_table.unallocated_bridges.len() >= MAX_BRIDGES_PER_BUCKET {
|
while self.bridge_table.unallocated_bridges.len() >= MAX_BRIDGES_PER_BUCKET {
|
||||||
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
|
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
|
||||||
for i in 0..MAX_BRIDGES_PER_BUCKET {
|
for i in 0..MAX_BRIDGES_PER_BUCKET {
|
||||||
bucket[i] = self.bridge_table.unallocated_bridges.pop().unwrap();
|
bucket[i] = self.bridge_table.unallocated_bridges.pop().unwrap();
|
||||||
}
|
}
|
||||||
self.add_openinv_bridges(bucket, bdb);
|
self.add_openinv_bridges(bucket, bdb);
|
||||||
|
@ -413,8 +413,7 @@ impl BridgeAuth {
|
||||||
if let Some(replacement) = available_bridge {
|
if let Some(replacement) = available_bridge {
|
||||||
for (bucketnum, offset) in positions.iter() {
|
for (bucketnum, offset) in positions.iter() {
|
||||||
assert!(self.bridge_table.buckets[*bucketnum as usize][*offset] == *bridge);
|
assert!(self.bridge_table.buckets[*bucketnum as usize][*offset] == *bridge);
|
||||||
self.bridge_table.buckets[*bucketnum as usize][*offset] =
|
self.bridge_table.buckets[*bucketnum as usize][*offset] = *replacement;
|
||||||
*replacement;
|
|
||||||
// Remove the bridge from the reachable bridges and add new bridge
|
// Remove the bridge from the reachable bridges and add new bridge
|
||||||
self.bridge_table
|
self.bridge_table
|
||||||
.reachable
|
.reachable
|
||||||
|
|
|
@ -597,22 +597,48 @@ fn test_allocate_bridges() {
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
distributor_bridges.push(BridgeLine::random());
|
distributor_bridges.push(BridgeLine::random());
|
||||||
}
|
}
|
||||||
assert!(!distributor_bridges.is_empty(), "No BridgeLines in distributor_bridges");
|
assert!(
|
||||||
|
!distributor_bridges.is_empty(),
|
||||||
|
"No BridgeLines in distributor_bridges"
|
||||||
|
);
|
||||||
th.ba.allocate_bridges(distributor_bridges, &mut th.bdb);
|
th.ba.allocate_bridges(distributor_bridges, &mut th.bdb);
|
||||||
assert!(distributor_bridges.is_empty(), "BridgeLines in distributor_bridges were not allocated");
|
assert!(
|
||||||
assert!(th.ba.bridge_table.buckets.len() > table_size, "Size of bridge table did not increase");
|
distributor_bridges.is_empty(),
|
||||||
|
"BridgeLines in distributor_bridges were not allocated"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
th.ba.bridge_table.buckets.len() > table_size,
|
||||||
|
"Size of bridge table did not increase"
|
||||||
|
);
|
||||||
let table_size = th.ba.bridge_table.buckets.len();
|
let table_size = th.ba.bridge_table.buckets.len();
|
||||||
for _ in 0..2 {
|
for _ in 0..2 {
|
||||||
distributor_bridges.push(BridgeLine::random());
|
distributor_bridges.push(BridgeLine::random());
|
||||||
th.ba.bridge_table.unallocated_bridges.push(BridgeLine::random());
|
th.ba
|
||||||
|
.bridge_table
|
||||||
|
.unallocated_bridges
|
||||||
|
.push(BridgeLine::random());
|
||||||
}
|
}
|
||||||
assert!(!th.ba.bridge_table.unallocated_bridges.is_empty(), "No BridgeLines in unallocated bridges");
|
assert!(
|
||||||
assert!(!distributor_bridges.is_empty(), "No BridgeLines in distributor_bridges");
|
!th.ba.bridge_table.unallocated_bridges.is_empty(),
|
||||||
|
"No BridgeLines in unallocated bridges"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
!distributor_bridges.is_empty(),
|
||||||
|
"No BridgeLines in distributor_bridges"
|
||||||
|
);
|
||||||
th.ba.allocate_bridges(distributor_bridges, &mut th.bdb);
|
th.ba.allocate_bridges(distributor_bridges, &mut th.bdb);
|
||||||
assert!(th.ba.bridge_table.unallocated_bridges.len() == 1, "Incorrect number of bridges remain unallocated");
|
assert!(
|
||||||
assert!(distributor_bridges.is_empty(), "BridgeLines in distributor_bridges were not allocated");
|
th.ba.bridge_table.unallocated_bridges.len() == 1,
|
||||||
assert!(th.ba.bridge_table.buckets.len() > table_size, "Size of bridge table did not increase");
|
"Incorrect number of bridges remain unallocated"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
distributor_bridges.is_empty(),
|
||||||
|
"BridgeLines in distributor_bridges were not allocated"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
th.ba.bridge_table.buckets.len() > table_size,
|
||||||
|
"Size of bridge table did not increase"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
use julianday::JulianDay;
|
use julianday::JulianDay;
|
||||||
use lox::bridge_table::{BridgeLine,from_scalar,BridgeTable, ENC_BUCKET_BYTES};
|
use lox::bridge_table::{from_scalar, BridgeLine, BridgeTable, ENC_BUCKET_BYTES};
|
||||||
use lox::cred::{BucketReachability, Invitation, Lox, Migration};
|
use lox::cred::{BucketReachability, Invitation, Lox, Migration};
|
||||||
use lox::proto::{open_invite, trust_promotion, migration, level_up,
|
use lox::proto::{
|
||||||
issue_invite, redeem_invite, check_blockage, blockage_migration};
|
blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite,
|
||||||
use lox::{IssuerPubKey, OPENINV_LENGTH, scalar_u32};
|
redeem_invite, trust_promotion,
|
||||||
|
};
|
||||||
|
use lox::{scalar_u32, IssuerPubKey, OPENINV_LENGTH};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::{serde_as};
|
use serde_with::serde_as;
|
||||||
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;
|
use zkp::ProofError;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
struct OpenReqState {
|
struct OpenReqState {
|
||||||
request: open_invite::Request,
|
request: open_invite::Request,
|
||||||
|
@ -61,8 +62,6 @@ struct BlockageMigReqState {
|
||||||
state: blockage_migration::State,
|
state: blockage_migration::State,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
struct PubKeys {
|
struct PubKeys {
|
||||||
lox_pub: IssuerPubKey,
|
lox_pub: IssuerPubKey,
|
||||||
|
@ -75,7 +74,7 @@ struct PubKeys {
|
||||||
#[serde_as]
|
#[serde_as]
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct EncBridgeTable {
|
pub struct EncBridgeTable {
|
||||||
#[serde_as(as = "Vec<[_; ENC_BUCKET_BYTES]>")]
|
#[serde_as(as = "Vec<[_; ENC_BUCKET_BYTES]>")]
|
||||||
pub etable: Vec<[u8; ENC_BUCKET_BYTES]>,
|
pub etable: Vec<[u8; ENC_BUCKET_BYTES]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,22 +96,21 @@ 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 MAX_LEVEL: usize = 4;
|
||||||
//pub const LEVEL_INTERVAL: [u32; MAX_LEVEL + 1] = [0, 14, 28, 56, 84];
|
//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, ProofError> {
|
||||||
let trust_level: i64 = match scalar_u32(&lox_cred.trust_level) {
|
let trust_level: i64 = match scalar_u32(&lox_cred.trust_level) {
|
||||||
Some(v) => v as i64,
|
Some(v) => v as i64,
|
||||||
None => return Err(ProofError::VerificationFailure),
|
None => return Err(ProofError::VerificationFailure),
|
||||||
};
|
};
|
||||||
let mut total = 31;
|
let mut total = 31;
|
||||||
// for level in 0..trust_level {
|
// for level in 0..trust_level {
|
||||||
// let level_interval: u32 = LEVEL_INTERVAL[trust_level as usize];
|
// let level_interval: u32 = LEVEL_INTERVAL[trust_level as usize];
|
||||||
// total += level_interval;
|
// total += level_interval;
|
||||||
total += trust_level*85;
|
total += trust_level * 85;
|
||||||
// }
|
// }
|
||||||
Ok(total)
|
Ok(total)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -120,7 +118,6 @@ extern "C" {
|
||||||
pub fn log(s: &str);
|
pub fn log(s: &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn set_panic_hook() {
|
pub fn set_panic_hook() {
|
||||||
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||||
|
@ -136,10 +133,7 @@ pub fn open_invite(invite: &[u8]) -> Result<String, JsValue> {
|
||||||
Err(e) => return Err(JsValue::from(e.to_string())),
|
Err(e) => return Err(JsValue::from(e.to_string())),
|
||||||
};
|
};
|
||||||
let (request, state) = open_invite::request(&token);
|
let (request, state) = open_invite::request(&token);
|
||||||
let req_state = OpenReqState {
|
let req_state = OpenReqState { request, state };
|
||||||
request,
|
|
||||||
state,
|
|
||||||
};
|
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!(
|
log(&format!(
|
||||||
"Formatted open invite request: {}",
|
"Formatted open invite request: {}",
|
||||||
|
@ -246,18 +240,26 @@ pub fn handle_trust_promotion(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
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: LoxCredential = serde_json::from_str(&open_lox_cred).unwrap();
|
let lox_cred: LoxCredential = 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: Migration = serde_json::from_str(&trust_promo_cred).unwrap();
|
let mig_cred: Migration = serde_json::from_str(&trust_promo_cred).unwrap();
|
||||||
let tm_result =
|
let tm_result = match migration::request(
|
||||||
match migration::request(&lox_cred.lox_credential, &mig_cred, &pubkeys.lox_pub, &pubkeys.migration_pub) {
|
&lox_cred.lox_credential,
|
||||||
Ok(tm_result) => tm_result,
|
&mig_cred,
|
||||||
Err(e) => {
|
&pubkeys.lox_pub,
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
&pubkeys.migration_pub,
|
||||||
return Err(JsValue::from(e.to_string()));
|
) {
|
||||||
}
|
Ok(tm_result) => tm_result,
|
||||||
};
|
Err(e) => {
|
||||||
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
let req_state = MigReqState {
|
let req_state = MigReqState {
|
||||||
request: tm_result.0,
|
request: tm_result.0,
|
||||||
state: tm_result.1,
|
state: tm_result.1,
|
||||||
|
@ -275,24 +277,27 @@ pub fn trust_migration(open_lox_cred: String, trust_promo_cred: String, lox_pub:
|
||||||
pub fn handle_trust_migration(
|
pub fn handle_trust_migration(
|
||||||
trust_migration_request: String,
|
trust_migration_request: String,
|
||||||
trust_migration_response: String,
|
trust_migration_response: String,
|
||||||
lox_pub: String
|
lox_pub: String,
|
||||||
) -> Result<String, JsValue> {
|
) -> Result<String, JsValue> {
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
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_one_cred =
|
let level_one_cred = match migration::handle_response(
|
||||||
match migration::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
|
deserialized_state,
|
||||||
Ok(level_1_cred) => LoxCredential {
|
deserialized_response,
|
||||||
lox_credential: level_1_cred,
|
&pubkeys.lox_pub,
|
||||||
bridgeline: None,
|
) {
|
||||||
invitation: None,
|
Ok(level_1_cred) => LoxCredential {
|
||||||
},
|
lox_credential: level_1_cred,
|
||||||
Err(e) => {
|
bridgeline: None,
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
invitation: None,
|
||||||
return Err(JsValue::from(e.to_string()));
|
},
|
||||||
}
|
Err(e) => {
|
||||||
};
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!(
|
log(&format!(
|
||||||
"Got new Level 1 Credential: {}",
|
"Got new Level 1 Credential: {}",
|
||||||
|
@ -310,7 +315,11 @@ fn generate_reachability_cred(lox_cred: &Lox, encrypted_table: String) -> Bucket
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn level_up(level_one_cred: String, encrypted_table: String, lox_pub: String) -> Result<String, JsValue> {
|
pub fn level_up(
|
||||||
|
level_one_cred: String,
|
||||||
|
encrypted_table: String,
|
||||||
|
lox_pub: String,
|
||||||
|
) -> Result<String, JsValue> {
|
||||||
let lox_cred: LoxCredential = serde_json::from_str(&level_one_cred).unwrap();
|
let lox_cred: LoxCredential = serde_json::from_str(&level_one_cred).unwrap();
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
let reach_cred = generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
|
let reach_cred = generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
|
||||||
|
@ -319,7 +328,7 @@ 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
|
// The trust level has to be at least 1
|
||||||
let test_cumulative_days = match calc_test_days(&lox_cred.lox_credential) {
|
let test_cumulative_days = match calc_test_days(&lox_cred.lox_credential) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -329,7 +338,8 @@ pub fn level_up(level_one_cred: String, encrypted_table: String, lox_pub: String
|
||||||
};
|
};
|
||||||
|
|
||||||
log(&format!(
|
log(&format!(
|
||||||
"TEST ONLY: Add 31 (open invitation) + Trust Level*85 days to today's date: {}", test_today(test_cumulative_days)
|
"TEST ONLY: Add 31 (open invitation) + Trust Level*85 days to today's date: {}",
|
||||||
|
test_today(test_cumulative_days)
|
||||||
));
|
));
|
||||||
let lu_result =
|
let lu_result =
|
||||||
//CHANGE add_today(31) to today() for production
|
//CHANGE add_today(31) to today() for production
|
||||||
|
@ -353,29 +363,31 @@ 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,
|
||||||
levelup_response: String,
|
levelup_response: String,
|
||||||
lox_pub: String
|
lox_pub: String,
|
||||||
) -> Result<String, JsValue> {
|
) -> Result<String, JsValue> {
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
let req_state: LevelupReqState = serde_json::from_str(&levelup_request).unwrap();
|
let req_state: LevelupReqState = serde_json::from_str(&levelup_request).unwrap();
|
||||||
let deserialized_state = req_state.state;
|
let deserialized_state = req_state.state;
|
||||||
let deserialized_response = serde_json::from_str(&levelup_response).unwrap();
|
let deserialized_response = serde_json::from_str(&levelup_response).unwrap();
|
||||||
let level_up_cred =
|
let level_up_cred = match level_up::handle_response(
|
||||||
match level_up::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
|
deserialized_state,
|
||||||
Ok(level_up_cred) => LoxCredential {
|
deserialized_response,
|
||||||
lox_credential: level_up_cred,
|
&pubkeys.lox_pub,
|
||||||
bridgeline: None,
|
) {
|
||||||
invitation: None,
|
Ok(level_up_cred) => LoxCredential {
|
||||||
},
|
lox_credential: level_up_cred,
|
||||||
Err(e) => {
|
bridgeline: None,
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
invitation: None,
|
||||||
return Err(JsValue::from(e.to_string()));
|
},
|
||||||
}
|
Err(e) => {
|
||||||
};
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!(
|
log(&format!(
|
||||||
"Got new Level Up Credential: {}",
|
"Got new Level Up Credential: {}",
|
||||||
|
@ -386,19 +398,28 @@ pub fn handle_level_up(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn issue_invite(trusted_cred: String, encrypted_table: String, lox_pub: String) -> Result<String, JsValue> {
|
pub fn issue_invite(
|
||||||
|
trusted_cred: String,
|
||||||
|
encrypted_table: String,
|
||||||
|
lox_pub: String,
|
||||||
|
) -> Result<String, JsValue> {
|
||||||
let lox_cred: LoxCredential = serde_json::from_str(&trusted_cred).unwrap();
|
let lox_cred: LoxCredential = serde_json::from_str(&trusted_cred).unwrap();
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
let reach_cred = generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
|
let reach_cred = generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
|
||||||
|
|
||||||
let issue_result =
|
let issue_result = match issue_invite::request(
|
||||||
match issue_invite::request(&lox_cred.lox_credential, &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, test_today(371)) {
|
&lox_cred.lox_credential,
|
||||||
Ok(issue_result) => issue_result,
|
&reach_cred,
|
||||||
Err(e) => {
|
&pubkeys.lox_pub,
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
&pubkeys.reachability_pub,
|
||||||
return Err(JsValue::from(e.to_string()));
|
test_today(371),
|
||||||
}
|
) {
|
||||||
};
|
Ok(issue_result) => issue_result,
|
||||||
|
Err(e) => {
|
||||||
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
let req_state = IssueInviteReqState {
|
let req_state = IssueInviteReqState {
|
||||||
request: issue_result.0,
|
request: issue_result.0,
|
||||||
state: issue_result.1,
|
state: issue_result.1,
|
||||||
|
@ -412,30 +433,33 @@ pub fn issue_invite(trusted_cred: String, encrypted_table: String, lox_pub: Stri
|
||||||
Ok(serde_json::to_string(&req_state).unwrap())
|
Ok(serde_json::to_string(&req_state).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn handle_issue_invite(
|
pub fn handle_issue_invite(
|
||||||
issue_invite_request: String,
|
issue_invite_request: String,
|
||||||
issue_invite_response: String,
|
issue_invite_response: String,
|
||||||
lox_pub: String
|
lox_pub: String,
|
||||||
) -> Result<String, JsValue> {
|
) -> Result<String, JsValue> {
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
let req_state: IssueInviteReqState = serde_json::from_str(&issue_invite_request).unwrap();
|
let req_state: IssueInviteReqState = serde_json::from_str(&issue_invite_request).unwrap();
|
||||||
let deserialized_state = req_state.state;
|
let deserialized_state = req_state.state;
|
||||||
let deserialized_response = serde_json::from_str(&issue_invite_response).unwrap();
|
let deserialized_response = serde_json::from_str(&issue_invite_response).unwrap();
|
||||||
let issue_invite_cred =
|
let issue_invite_cred = match issue_invite::handle_response(
|
||||||
match issue_invite::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub, &pubkeys.invitation_pub) {
|
deserialized_state,
|
||||||
Ok(issue_invite_cred) => issue_invite_cred,
|
deserialized_response,
|
||||||
Err(e) => {
|
&pubkeys.lox_pub,
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
&pubkeys.invitation_pub,
|
||||||
return Err(JsValue::from(e.to_string()));
|
) {
|
||||||
}
|
Ok(issue_invite_cred) => issue_invite_cred,
|
||||||
};
|
Err(e) => {
|
||||||
let invitation_cred = LoxCredential {
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
lox_credential: issue_invite_cred.0,
|
return Err(JsValue::from(e.to_string()));
|
||||||
bridgeline: None,
|
}
|
||||||
invitation: Some(issue_invite_cred.1),
|
};
|
||||||
};
|
let invitation_cred = LoxCredential {
|
||||||
|
lox_credential: issue_invite_cred.0,
|
||||||
|
bridgeline: None,
|
||||||
|
invitation: Some(issue_invite_cred.1),
|
||||||
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!(
|
log(&format!(
|
||||||
|
@ -487,24 +511,27 @@ pub fn redeem_invite(invitation: String, lox_pub: String) -> Result<String, JsVa
|
||||||
pub fn handle_redeem_invite(
|
pub fn handle_redeem_invite(
|
||||||
redeem_invite_request: String,
|
redeem_invite_request: String,
|
||||||
redeem_invite_response: String,
|
redeem_invite_response: String,
|
||||||
lox_pub: String
|
lox_pub: String,
|
||||||
) -> Result<String, JsValue> {
|
) -> Result<String, JsValue> {
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
let req_state: RedeemReqState = serde_json::from_str(&redeem_invite_request).unwrap();
|
let req_state: RedeemReqState = serde_json::from_str(&redeem_invite_request).unwrap();
|
||||||
let deserialized_state = req_state.state;
|
let deserialized_state = req_state.state;
|
||||||
let deserialized_response = serde_json::from_str(&redeem_invite_response).unwrap();
|
let deserialized_response = serde_json::from_str(&redeem_invite_response).unwrap();
|
||||||
let redeem_invite_cred =
|
let redeem_invite_cred = match redeem_invite::handle_response(
|
||||||
match redeem_invite::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
|
deserialized_state,
|
||||||
Ok(issue_invite_cred) => LoxCredential {
|
deserialized_response,
|
||||||
lox_credential: issue_invite_cred,
|
&pubkeys.lox_pub,
|
||||||
bridgeline: None,
|
) {
|
||||||
invitation: None,
|
Ok(issue_invite_cred) => LoxCredential {
|
||||||
},
|
lox_credential: issue_invite_cred,
|
||||||
Err(e) => {
|
bridgeline: None,
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
invitation: None,
|
||||||
return Err(JsValue::from(e.to_string()));
|
},
|
||||||
}
|
Err(e) => {
|
||||||
};
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!(
|
log(&format!(
|
||||||
"Got new Trusted Lox Credential from Invitation: {}",
|
"Got new Trusted Lox Credential from Invitation: {}",
|
||||||
|
@ -514,19 +541,17 @@ pub fn handle_redeem_invite(
|
||||||
Ok(serde_json::to_string(&redeem_invite_cred).unwrap())
|
Ok(serde_json::to_string(&redeem_invite_cred).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn check_blockage(lox_cred: String, lox_pub: String) -> Result<String, JsValue> {
|
pub fn check_blockage(lox_cred: String, lox_pub: String) -> Result<String, JsValue> {
|
||||||
let lox: LoxCredential = serde_json::from_str(&lox_cred).unwrap();
|
let lox: LoxCredential = serde_json::from_str(&lox_cred).unwrap();
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
let cb_result =
|
let cb_result = match check_blockage::request(&lox.lox_credential, &pubkeys.lox_pub) {
|
||||||
match check_blockage::request(&lox.lox_credential, &pubkeys.lox_pub) {
|
Ok(cb_result) => cb_result,
|
||||||
Ok(cb_result) => cb_result,
|
Err(e) => {
|
||||||
Err(e) => {
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
return Err(JsValue::from(e.to_string()));
|
||||||
return Err(JsValue::from(e.to_string()));
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
let req_state = CheckBlockageReqState {
|
let req_state = CheckBlockageReqState {
|
||||||
request: cb_result.0,
|
request: cb_result.0,
|
||||||
state: cb_result.1,
|
state: cb_result.1,
|
||||||
|
@ -565,20 +590,27 @@ pub fn handle_check_blockage(
|
||||||
Ok(serde_json::to_string(&migration_cred).unwrap())
|
Ok(serde_json::to_string(&migration_cred).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn blockage_migration(lox_cred: String, check_migration_cred: String, lox_pub: String) -> Result<String, JsValue> {
|
pub fn blockage_migration(
|
||||||
|
lox_cred: String,
|
||||||
|
check_migration_cred: String,
|
||||||
|
lox_pub: String,
|
||||||
|
) -> Result<String, JsValue> {
|
||||||
let lox_cred: LoxCredential = serde_json::from_str(&lox_cred).unwrap();
|
let lox_cred: LoxCredential = serde_json::from_str(&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: Migration = serde_json::from_str(&check_migration_cred).unwrap();
|
let mig_cred: Migration = serde_json::from_str(&check_migration_cred).unwrap();
|
||||||
let bm_result =
|
let bm_result = match blockage_migration::request(
|
||||||
match blockage_migration::request(&lox_cred.lox_credential, &mig_cred, &pubkeys.lox_pub, &pubkeys.migration_pub) {
|
&lox_cred.lox_credential,
|
||||||
Ok(bm_result) => bm_result,
|
&mig_cred,
|
||||||
Err(e) => {
|
&pubkeys.lox_pub,
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
&pubkeys.migration_pub,
|
||||||
return Err(JsValue::from(e.to_string()));
|
) {
|
||||||
}
|
Ok(bm_result) => bm_result,
|
||||||
};
|
Err(e) => {
|
||||||
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
let req_state = BlockageMigReqState {
|
let req_state = BlockageMigReqState {
|
||||||
request: bm_result.0,
|
request: bm_result.0,
|
||||||
state: bm_result.1,
|
state: bm_result.1,
|
||||||
|
@ -596,24 +628,27 @@ pub fn blockage_migration(lox_cred: String, check_migration_cred: String, lox_pu
|
||||||
pub fn handle_blockage_migration(
|
pub fn handle_blockage_migration(
|
||||||
blockage_migration_request: String,
|
blockage_migration_request: String,
|
||||||
blockage_migration_response: String,
|
blockage_migration_response: String,
|
||||||
lox_pub: String
|
lox_pub: String,
|
||||||
) -> Result<String, JsValue> {
|
) -> Result<String, JsValue> {
|
||||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||||
let req_state: BlockageMigReqState = serde_json::from_str(&blockage_migration_request).unwrap();
|
let req_state: BlockageMigReqState = serde_json::from_str(&blockage_migration_request).unwrap();
|
||||||
let deserialized_state = req_state.state;
|
let deserialized_state = req_state.state;
|
||||||
let deserialized_response = serde_json::from_str(&blockage_migration_response).unwrap();
|
let deserialized_response = serde_json::from_str(&blockage_migration_response).unwrap();
|
||||||
let lox_cred =
|
let lox_cred = match blockage_migration::handle_response(
|
||||||
match blockage_migration::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
|
deserialized_state,
|
||||||
Ok(lox_cred) => LoxCredential {
|
deserialized_response,
|
||||||
lox_credential: lox_cred,
|
&pubkeys.lox_pub,
|
||||||
bridgeline: None,
|
) {
|
||||||
invitation: None,
|
Ok(lox_cred) => LoxCredential {
|
||||||
},
|
lox_credential: lox_cred,
|
||||||
Err(e) => {
|
bridgeline: None,
|
||||||
log(&format!("Error: {:?}", e.to_string()));
|
invitation: None,
|
||||||
return Err(JsValue::from(e.to_string()));
|
},
|
||||||
}
|
Err(e) => {
|
||||||
};
|
log(&format!("Error: {:?}", e.to_string()));
|
||||||
|
return Err(JsValue::from(e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!(
|
log(&format!(
|
||||||
"Got new Lox Credential after Migration: {}",
|
"Got new Lox Credential after Migration: {}",
|
||||||
|
|
Loading…
Reference in New Issue