Add wasm_bindgen for handling new lox credential

This commit is contained in:
onyinyang 2023-01-25 15:02:39 -05:00
parent 5d60807a42
commit d473b53745
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 9 additions and 8 deletions

View File

@ -10,7 +10,7 @@ license = "MIT"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
lox = { git = "https://gitlab.torproject.org/onyinyang/lox.git" } lox = { git = "https://gitlab.torproject.org/onyinyang/lox.git", branch = "master" }
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
serde_json = "1.0.87" serde_json = "1.0.87"
serde-wasm-bindgen = "0.4.5" serde-wasm-bindgen = "0.4.5"

View File

@ -1,9 +1,8 @@
use lox::bridge_table::BridgeLine; use lox::bridge_table::BridgeLine;
use lox::cred;
use lox::proto::open_invite; use lox::proto::open_invite;
use lox::{IssuerPubKey, OPENINV_LENGTH}; use lox::{IssuerPubKey, OPENINV_LENGTH};
use serde_json; use serde_json;
use serde_wasm_bindgen; //use serde_wasm_bindgen;
use std::array::TryFromSliceError; use std::array::TryFromSliceError;
use std::panic; use std::panic;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
@ -49,15 +48,16 @@ fn concat_string(request: String, state: String) -> String {
return new_string; return new_string;
} }
/*
#[wasm_bindgen] #[wasm_bindgen]
pub fn handle_new_lox_credential(state: String, response: String) -> Result<String, JsValue> { pub fn handle_new_lox_credential(state: String, response: String, lox_pub: String) -> Result<String, JsValue> {
unsafe { unsafe {
log(&format!("Using server response: {:?}", response)); log(&format!("Using server response: {:?}", response));
} }
let deserialized_state = serde_json::from_str(&state).unwrap(); let deserialized_state = serde_json::from_str(&state).unwrap();
let deserialized_response = serde_json::from_str(&response).unwrap(); let deserialized_response = serde_json::from_str(&response).unwrap();
let lox_cred = match open_invite::handle_response(deserialized_state, deserialized_response, lox_pub) { let deserialized_pubkey = serde_json::from_str(&lox_pub).unwrap();
let lox_cred = match open_invite::handle_response(deserialized_state, deserialized_response, &deserialized_pubkey) {
Ok(lox_cred) => lox_cred, Ok(lox_cred) => lox_cred,
Err(e) => return Err(JsValue::from(e.to_string())), Err(e) => return Err(JsValue::from(e.to_string())),
}; };
@ -67,8 +67,9 @@ pub fn handle_new_lox_credential(state: String, response: String) -> Result<Stri
log(&format!("Got new Lox Credential: {}", serialized_credential)); log(&format!("Got new Lox Credential: {}", serialized_credential));
log(&format!("Got new bridgeline: {}", serialized_bridgeline)); log(&format!("Got new bridgeline: {}", serialized_bridgeline));
} }
Ok((serialized_credential, serialized_bridgeline)) let open_lox_response = concat_string(serialized_credential, serialized_bridgeline);
} */ Ok(open_lox_response)
}
/* Somehow get pubkeys and return to function /* Somehow get pubkeys and return to function
#[wasm_bindgen] #[wasm_bindgen]