Handle open invite credential
This commit is contained in:
parent
832a252318
commit
dfa2ae4c6f
|
@ -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();
|
let pubkeys = await request_pubkeys();
|
||||||
console.log(pubkeys);
|
console.log(pubkeys);
|
||||||
|
|
||||||
|
@ -9,16 +9,36 @@ let requested = await init().then(() => {
|
||||||
return open_invite(token);
|
return open_invite(token);
|
||||||
});
|
});
|
||||||
return requested;
|
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);
|
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() {
|
function request_open_invite() {
|
||||||
return new Promise((fulfill, reject) => {
|
return new Promise((fulfill, reject) => {
|
||||||
loxServerRequest("/invite").then((response) => {
|
loxServerGetRequest("/invite").then((response) => {
|
||||||
console.log("Got invitation token: " + response.invite);
|
console.log("Got invitation token: " + response.invite);
|
||||||
fulfill(response.invite);
|
fulfill(response.invite);
|
||||||
return;
|
return;
|
||||||
|
@ -31,8 +51,8 @@ function request_open_invite() {
|
||||||
|
|
||||||
function request_pubkeys() {
|
function request_pubkeys() {
|
||||||
return new Promise((fulfill, reject) => {
|
return new Promise((fulfill, reject) => {
|
||||||
loxServerRequest("/pubkeys").then((response) => {
|
loxServerGetRequest("/pubkeys").then((response) => {
|
||||||
console.log("Got pubkeys: " + JSON.parse(response));
|
console.log("Got pubkeys: " + response);
|
||||||
fulfill(JSON.parse(response));
|
fulfill(JSON.parse(response));
|
||||||
return;
|
return;
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
|
@ -42,9 +62,9 @@ function request_pubkeys() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loxServerRequest(data) {
|
function loxServerGetRequest(data) {
|
||||||
return new Promise((fulfill, reject) => {
|
return new Promise((fulfill, reject) => {
|
||||||
const xhr = new XMLHttpRequest(data);
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.DONE !== xhr.readyState) {
|
if (xhr.DONE !== xhr.readyState) {
|
||||||
return;
|
return;
|
||||||
|
@ -61,9 +81,6 @@ function loxServerRequest(data) {
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
xhr.open('GET', "http://localhost:8001"+data);
|
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) {
|
} catch (err) {
|
||||||
console.log("Error connecting to lox bridge db");
|
console.log("Error connecting to lox bridge db");
|
||||||
reject();
|
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
|
// 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
|
// verify that the key issuer is in fact the correct Bridge Authority
|
||||||
function loxKeyRequest(key_type) {
|
function loxKeyRequest(key_type) {
|
||||||
|
|
Loading…
Reference in New Issue