2023-01-13 14:16:37 -05:00
|
|
|
import init, { open_invite, set_panic_hook } from "./pkg/lox_wasm.js";
|
2023-01-26 00:17:14 -05:00
|
|
|
let pubkeys = await request_pubkeys();
|
|
|
|
console.log(pubkeys);
|
|
|
|
|
|
|
|
|
|
|
|
let requested = await init().then(() => {
|
2023-01-13 14:16:37 -05:00
|
|
|
set_panic_hook();
|
2023-01-26 00:17:14 -05:00
|
|
|
let requested = request_open_invite().then((token) => {
|
|
|
|
return open_invite(token);
|
2023-01-13 14:16:37 -05:00
|
|
|
});
|
2023-01-26 00:17:14 -05:00
|
|
|
return requested;
|
2023-01-25 15:02:53 -05:00
|
|
|
// unsigned_open_lox_credential = handle_new_lox_credential(requested, pubkeys);
|
2023-01-25 15:02:23 -05:00
|
|
|
// lox_credential = request_new_lox_credential(request_cred[0]).then((lox_cred) => {
|
|
|
|
// handle_new_lox_credential(request_cred[1], response, pubkey);
|
|
|
|
// })
|
2023-01-13 14:16:37 -05:00
|
|
|
});
|
2023-01-26 00:17:14 -05:00
|
|
|
console.log("Got request and state "+requested);
|
2023-01-13 14:16:37 -05:00
|
|
|
|
|
|
|
function request_open_invite() {
|
2023-01-13 14:23:35 -05:00
|
|
|
return new Promise((fulfill, reject) => {
|
2023-01-25 15:02:53 -05:00
|
|
|
loxServerRequest("/invite").then((response) => {
|
2023-01-13 14:23:35 -05:00
|
|
|
console.log("Got invitation token: " + response.invite);
|
|
|
|
fulfill(response.invite);
|
|
|
|
return;
|
|
|
|
}).catch(() => {
|
|
|
|
console.log("Error requesting open invite from Lox server");
|
|
|
|
reject();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-25 15:02:53 -05:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-13 14:23:35 -05:00
|
|
|
function loxServerRequest(data) {
|
2023-01-13 14:16:37 -05:00
|
|
|
return new Promise((fulfill, reject) => {
|
2023-01-25 15:02:23 -05:00
|
|
|
const xhr = new XMLHttpRequest(data);
|
2023-01-13 14:16:37 -05:00
|
|
|
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);
|
2023-01-13 14:23:35 -05:00
|
|
|
fulfill(response);
|
2023-01-13 14:16:37 -05:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
try {
|
2023-01-25 15:02:53 -05:00
|
|
|
xhr.open('GET', "http://localhost:8001"+data);
|
|
|
|
//xhr.open("Post", "http://localhost:8001"+data)
|
|
|
|
//xhr.setRequestHeader("Content-Type", "application/json");
|
|
|
|
//var data = JSON.stringify({})
|
2023-01-13 14:16:37 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.log("Error connecting to lox bridge db");
|
|
|
|
reject();
|
|
|
|
return;
|
|
|
|
}
|
2023-01-25 15:02:53 -05:00
|
|
|
xhr.send();
|
2023-01-13 14:16:37 -05:00
|
|
|
});
|
|
|
|
}
|
2023-01-25 15:02:23 -05:00
|
|
|
|
|
|
|
// 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) {
|
|
|
|
return new Promise((fulfull, reject) => {
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|