diff --git a/crates/lox-wasm/index.js b/crates/lox-wasm/index.js index bfcdb44..f04ad5b 100644 --- a/crates/lox-wasm/index.js +++ b/crates/lox-wasm/index.js @@ -18,15 +18,15 @@ let open_lox_cred = await init().then(() => { }); return cred; }); -console.log("Got request and state "+requested); +console.log("Got Lox Credential and BridgeLine "+open_lox_cred); function request_new_lox_credential(requested) { return new Promise((fulfill, reject) => { let req = JSON.parse(requested); - console.log("Request? "+req.request); + console.log("Request? "+JSON.stringify(req.request)); loxServerPostRequest("/openreq", req.request).then((response) => { - console.log("Got new Lox Credential: " + response); - fulfill(response); + console.log("Got new Lox Credential: " + JSON.stringify(response)); + fulfill(JSON.stringify(response)); return; }).catch(() => { console.log("Error requesting new Lox credential from server"); diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index 57916d0..6f7f55a 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -1,8 +1,7 @@ -use lox::bridge_table::BridgeLine; use lox::proto::open_invite; use lox::{IssuerPubKey, OPENINV_LENGTH}; +use serde::{Deserialize, Serialize}; use serde_json; -use serde::{Deserialize,Serialize}; //use serde_wasm_bindgen; use std::array::TryFromSliceError; use std::panic; @@ -14,7 +13,7 @@ struct ReqState { state: lox::proto::open_invite::State, } -#[derive(Debug, Deserialize,Serialize)] +#[derive(Debug, Deserialize, Serialize)] struct PubKeys { lox_pub: IssuerPubKey, migration_pub: IssuerPubKey, @@ -23,7 +22,7 @@ struct PubKeys { invitation_pub: IssuerPubKey, } -#[derive(Debug,Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize)] struct Credential { lox_credential: String, bridgeline: String, @@ -53,7 +52,7 @@ pub fn open_invite(invite: &[u8]) -> Result { let req_state = ReqState { request: request, state: state, - }; + }; unsafe { log(&format!( "Formatted open invite request: {}", @@ -63,39 +62,41 @@ pub fn open_invite(invite: &[u8]) -> Result { Ok(serde_json::to_string(&req_state).unwrap()) } - #[wasm_bindgen] -pub fn handle_new_lox_credential(open_lox_result: String, open_lox_response: String, lox_pub: String) -> Result { - unsafe { - log(&format!("Using server response: {:?}", open_lox_result)); - } +pub fn handle_new_lox_credential( + open_lox_result: String, + open_lox_response: String, + lox_pub: String, +) -> Result { let req_state: ReqState = serde_json::from_str(&open_lox_result).unwrap(); let deserialized_state = req_state.state; let deserialized_response = serde_json::from_str(&open_lox_response).unwrap(); let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap(); - unsafe { - log(&format!("pubkeys: {:?}", pubkeys.lox_pub)); - } - let lox_cred = match open_invite::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) { + let lox_cred = match open_invite::handle_response( + deserialized_state, + deserialized_response, + &pubkeys.lox_pub, + ) { Ok(lox_cred) => lox_cred, Err(e) => { log(&format!("Error: {:?}", e.to_string())); return Err(JsValue::from(e.to_string())); } }; - log(&format!("Did this actually work?: {:?}", lox_cred)); let lox_cred = Credential { lox_credential: serde_json::to_string(&lox_cred.0).unwrap(), bridgeline: serde_json::to_string(&lox_cred.1).unwrap(), }; unsafe { - log(&format!("Got new Lox Credential: {}", lox_cred.lox_credential)); + log(&format!( + "Got new Lox Credential: {}", + lox_cred.lox_credential + )); log(&format!("Got new bridgeline: {}", lox_cred.bridgeline)); } Ok(serde_json::to_string(&lox_cred).unwrap()) } - // This should also check the pubkey fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> { invite.try_into()