Add invitation_is_trusted function, fixup error handling
This commit is contained in:
parent
39449cabe8
commit
9d4a293ee9
|
@ -50,10 +50,19 @@ pub fn handle_new_lox_credential(
|
|||
open_lox_response: String,
|
||||
lox_pub: String,
|
||||
) -> Result<String, JsValue> {
|
||||
let req_state: lox_utils::OpenReqState = serde_json::from_str(&open_lox_result).unwrap();
|
||||
let req_state: lox_utils::OpenReqState = match serde_json::from_str(&open_lox_result) {
|
||||
Ok(req_state) => req_state,
|
||||
Err(e) => return Err(JsValue::from(e.to_string())),
|
||||
};
|
||||
let deserialized_state = req_state.state;
|
||||
let deserialized_response = serde_json::from_str(&open_lox_response).unwrap();
|
||||
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||
let deserialized_response = match serde_json::from_str(&open_lox_response) {
|
||||
Ok(deserialized_response) => deserialized_response,
|
||||
Err(e) => return Err(JsValue::from(e.to_string())),
|
||||
};
|
||||
let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) {
|
||||
Ok(pubkeys) => pubkeys,
|
||||
Err(e) => return Err(JsValue::from(e.to_string())),
|
||||
};
|
||||
let lox_cred = match open_invite::handle_response(
|
||||
deserialized_state,
|
||||
deserialized_response,
|
||||
|
@ -78,7 +87,13 @@ pub fn handle_new_lox_credential(
|
|||
"Got new bridgeline: {}",
|
||||
serde_json::to_string(&lox_cred.bridgelines).unwrap()
|
||||
));
|
||||
Ok(serde_json::to_string(&lox_cred).unwrap())
|
||||
match serde_json::to_string(&lox_cred) {
|
||||
Ok(lox_cred) => Ok(lox_cred),
|
||||
Err(e) => {
|
||||
log(&format!("Error: {:?}", e.to_string()));
|
||||
Err(JsValue::from(e.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -563,11 +578,10 @@ pub fn get_issued_invite_expiry(lox_cred_str: String) -> Result<String, JsValue>
|
|||
"Invitation Expiry {}",
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
));
|
||||
let inv_date_str = match serde_json::to_string(&date_time) {
|
||||
match serde_json::to_string(&date_time) {
|
||||
Ok(inv_date_str) => Ok(inv_date_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
};
|
||||
inv_date_str
|
||||
}
|
||||
}
|
||||
None => Err(JsValue::from("No Invitation Issued")),
|
||||
}
|
||||
|
@ -613,3 +627,16 @@ pub fn get_constants() -> Result<String, JsValue> {
|
|||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn invitation_is_trusted(unspecified_invitation_str: String) -> Result<bool, JsValue> {
|
||||
match serde_json::from_str::<Invitation>(&unspecified_invitation_str) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(_) => {
|
||||
let invite = unspecified_invitation_str.as_bytes();
|
||||
match lox_utils::validate(invite) {
|
||||
Ok(_) => Ok(false),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue