Handle open invite credential
This commit is contained in:
parent
efbc822be6
commit
e39761ae7c
|
@ -1,4 +1,4 @@
|
|||
import init, { open_invite, set_panic_hook } from "./pkg/lox_wasm.js";
|
||||
import init, { open_invite, handle_new_lox_credential, set_panic_hook } from "./pkg/lox_wasm.js";
|
||||
let pubkeys = await request_pubkeys();
|
||||
console.log(pubkeys);
|
||||
|
||||
|
@ -9,16 +9,36 @@ let requested = await init().then(() => {
|
|||
return open_invite(token);
|
||||
});
|
||||
return requested;
|
||||
// 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);
|
||||
// })
|
||||
});
|
||||
console.log("Got request and state "+requested);
|
||||
|
||||
let open_lox_cred = await init().then(() => {
|
||||
set_panic_hook();
|
||||
let cred = request_new_lox_credential(requested).then((response) => {
|
||||
return handle_new_lox_credential(requested, response, pubkeys);
|
||||
});
|
||||
return cred;
|
||||
});
|
||||
console.log("Got request and state "+requested);
|
||||
|
||||
function request_new_lox_credential(requested) {
|
||||
let req = JSON.parse(requested);
|
||||
console.log("Request? "+req.request);
|
||||
return new Promise((fulfill, reject) => {
|
||||
loxServerPostRequest("/openreq", req.request).then((response) => {
|
||||
console.log("Got new Lox Credential: " + response);
|
||||
fulfill(response);
|
||||
return;
|
||||
}).catch(() => {
|
||||
console.log("Error requesting new Lox credential from server");
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function request_open_invite() {
|
||||
return new Promise((fulfill, reject) => {
|
||||
loxServerRequest("/invite").then((response) => {
|
||||
loxServerGetRequest("/invite").then((response) => {
|
||||
console.log("Got invitation token: " + response.invite);
|
||||
fulfill(response.invite);
|
||||
return;
|
||||
|
@ -31,8 +51,8 @@ function request_open_invite() {
|
|||
|
||||
function request_pubkeys() {
|
||||
return new Promise((fulfill, reject) => {
|
||||
loxServerRequest("/pubkeys").then((response) => {
|
||||
console.log("Got pubkeys: " + JSON.parse(response));
|
||||
loxServerGetRequest("/pubkeys").then((response) => {
|
||||
console.log("Got pubkeys: " + response);
|
||||
fulfill(JSON.parse(response));
|
||||
return;
|
||||
}).catch(() => {
|
||||
|
@ -42,9 +62,9 @@ function request_pubkeys() {
|
|||
});
|
||||
}
|
||||
|
||||
function loxServerRequest(data) {
|
||||
function loxServerGetRequest(data) {
|
||||
return new Promise((fulfill, reject) => {
|
||||
const xhr = new XMLHttpRequest(data);
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.DONE !== xhr.readyState) {
|
||||
return;
|
||||
|
@ -61,9 +81,6 @@ function loxServerRequest(data) {
|
|||
};
|
||||
try {
|
||||
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();
|
||||
|
@ -73,6 +90,36 @@ function loxServerRequest(data) {
|
|||
});
|
||||
}
|
||||
|
||||
function loxServerPostRequest(data, payload) {
|
||||
return new Promise((fulfill, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.DONE !== xhr.readyState) {
|
||||
return;
|
||||
}
|
||||
if (xhr.status !== 200) {
|
||||
console.log("Error. Status code: "+xhr.status);
|
||||
console.log(xhr);
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
console.log("Received: "+response);
|
||||
fulfill(response);
|
||||
return;
|
||||
};
|
||||
try {
|
||||
xhr.open('POST', "http://localhost:8001"+data, true)
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
} catch (err) {
|
||||
console.log("Error connecting to lox bridge db");
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
xhr.send(JSON.stringify(payload));
|
||||
});
|
||||
}
|
||||
|
||||
// The correct key should be matched against a public commit to the key to
|
||||
// verify that the key issuer is in fact the correct Bridge Authority
|
||||
function loxKeyRequest(key_type) {
|
||||
|
|
Loading…
Reference in New Issue