diff --git a/crates/lox-wasm/index.js b/crates/lox-wasm/index.js index 269d1b4..6b62307 100644 --- a/crates/lox-wasm/index.js +++ b/crates/lox-wasm/index.js @@ -1,9 +1,14 @@ import init, { open_invite, set_panic_hook } from "./pkg/lox_wasm.js"; +var pubkeys = request_pubkeys().then((pubkeys) => { + pubkeys +}); +console.log(pubkeys) init().then(() => { set_panic_hook(); requested = request_open_invite().then((token) => { open_invite(token); }); +// unsigned_open_lox_credential = handle_new_lox_credential(requested, pubkeys); // lox_credential = request_new_lox_credential(request_cred[0]).then((lox_cred) => { // handle_new_lox_credential(request_cred[1], response, pubkey); // }) @@ -11,7 +16,7 @@ requested = request_open_invite().then((token) => { function request_open_invite() { return new Promise((fulfill, reject) => { - loxServerRequest("").then((response) => { + loxServerRequest("/invite").then((response) => { console.log("Got invitation token: " + response.invite); fulfill(response.invite); return; @@ -22,6 +27,19 @@ function request_open_invite() { }); } +function request_pubkeys() { + return new Promise((fulfill, reject) => { + loxServerRequest("/pubkeys").then((response) => { + console.log("Got pubkeys: " + JSON.parse(response)); + fulfill(JSON.parse(response)); + return; + }).catch(() => { + console.log("Error requesting open invite from Lox server"); + reject(); + }); + }); +} + function loxServerRequest(data) { return new Promise((fulfill, reject) => { const xhr = new XMLHttpRequest(data); @@ -40,20 +58,16 @@ function loxServerRequest(data) { return; }; try { - if (data != ""){ - xhr.open('GET', "http://localhost:8001"); - } - else { - xhr.open("Post", "http://localhost:8001") - xhr.setRequestHeader("Content-Type", "application/json"); - var data = JSON.stringify({}) - } + xhr.open('GET', "http://localhost:8001"+data); + //xhr.open("Post", "http://localhost:8001"+data) + //xhr.setRequestHeader("Content-Type", "application/json"); + //var data = JSON.stringify({}) } catch (err) { console.log("Error connecting to lox bridge db"); reject(); return; } - xhr.send(data); + xhr.send(); }); } diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index 56d23e8..b5fa0ba 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -48,12 +48,19 @@ fn concat_string(request: String, state: String) -> String { return new_string; } +fn deconcat_string(concatString: String) -> (String, String) { + + ("hello".to_owned(), "world".to_owned()) + +} + #[wasm_bindgen] -pub fn handle_new_lox_credential(state: String, response: String, lox_pub: String) -> Result { +pub fn handle_new_lox_credential(open_lox_result: String, lox_pub: String) -> Result { unsafe { - log(&format!("Using server response: {:?}", response)); + log(&format!("Using server response: {:?}", open_lox_result)); } + let (state, response) = deconcat_string(open_lox_result); let deserialized_state = serde_json::from_str(&state).unwrap(); let deserialized_response = serde_json::from_str(&response).unwrap(); let deserialized_pubkey = serde_json::from_str(&lox_pub).unwrap();