|
|
@@ -16,7 +16,7 @@ import init, {
|
|
|
handle_check_blockage,
|
|
|
blockage_migration,
|
|
|
handle_blockage_migration,
|
|
|
- set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_next_unlock, get_received_invite_expiry, get_bridgelines_from_bucket} from "./pkg/lox_wasm.js";
|
|
|
+ set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_next_unlock, get_received_invite_expiry, get_bridgelines_from_bucket, get_bridge_fingerprint} from "./pkg/lox_wasm.js";
|
|
|
let pubkeys = await simple_request("/pubkeys");
|
|
|
console.log("Got pubkeys: " + pubkeys);
|
|
|
let constants = await simple_request("/constants");
|
|
|
@@ -26,7 +26,7 @@ console.log("Got constants: " + constants);
|
|
|
let requested_invite = await init().then(() => {
|
|
|
set_panic_hook();
|
|
|
let requested_invite = request_open_invite().then((token) => {
|
|
|
- return open_invite(token);
|
|
|
+ return open_invite(token, pubkeys);
|
|
|
});
|
|
|
return requested_invite;
|
|
|
});
|
|
|
@@ -36,9 +36,9 @@ console.log("Got request and state: "+requested_invite);
|
|
|
// Trust Level 0
|
|
|
let open_lox_cred = await init().then(() => {
|
|
|
set_panic_hook();
|
|
|
- let cred = requested_cred("/openreq", requested_invite).then((response) => {
|
|
|
+ let cred = open_requested_cred("/openreq", requested_invite).then((response) => {
|
|
|
console.log("Got new Level 0 Lox Credential: " + response);
|
|
|
- return handle_new_lox_credential(requested_invite, response, pubkeys);
|
|
|
+ return handle_new_lox_credential(requested_invite, response);
|
|
|
});
|
|
|
return cred;
|
|
|
});
|
|
|
@@ -49,22 +49,33 @@ get_trust_level(open_lox_cred);
|
|
|
get_invites_remaining(open_lox_cred);
|
|
|
|
|
|
let encrypted_table = await simple_request("/reachability");
|
|
|
-let info_five = get_bridgelines_from_bucket(open_lox_cred, encrypted_table);
|
|
|
+let info_five = get_bridgelines_from_bucket(open_lox_cred, encrypted_table, pubkeys);
|
|
|
console.log("Bridgelines available: "+info_five);
|
|
|
-let requested_trust_promo = trust_promotion(open_lox_cred, pubkeys);
|
|
|
+let requested_trust_promo = await init().then(() => {
|
|
|
+ set_panic_hook();
|
|
|
+ let num = 35;
|
|
|
+ let req = requested_days("/advancedays", num.toString()).then((today)=> {
|
|
|
+ console.log("Advanced days by "+num+" days to: "+today);
|
|
|
+
|
|
|
+ return trust_promotion(open_lox_cred, pubkeys, today);
|
|
|
+ });
|
|
|
+ return req;
|
|
|
+});
|
|
|
+
|
|
|
+console.log("Got request and state: "+requested_trust_promo);
|
|
|
|
|
|
// Get Migration credential for Trust Promotion from Trust Level 0 -> 1
|
|
|
let trust_promo_cred = await init().then(() => {
|
|
|
set_panic_hook();
|
|
|
let cred = requested_cred("/trustpromo", requested_trust_promo).then((response)=> {
|
|
|
console.log("Got Migration Credential for Trust Promotion: " + response);
|
|
|
- return handle_trust_promotion(requested_trust_promo, response);
|
|
|
+ return handle_trust_promotion(requested_trust_promo, response, pubkeys);
|
|
|
});
|
|
|
return cred;
|
|
|
});
|
|
|
|
|
|
|
|
|
-let requested_trust_migration = trust_migration(open_lox_cred, trust_promo_cred, pubkeys);
|
|
|
+let requested_trust_migration = trust_migration(open_lox_cred, trust_promo_cred);
|
|
|
|
|
|
// Trust Promotion from Trust Level 0 -> 1
|
|
|
let lox_cred = await init().then(() => {
|
|
|
@@ -75,10 +86,15 @@ let lox_cred = await init().then(() => {
|
|
|
});
|
|
|
return cred;
|
|
|
});
|
|
|
+// Level Up days + 15
|
|
|
+ let num = 15;
|
|
|
+ let server_today = await requested_days("/advancedays", num.toString());
|
|
|
+ console.log("Advanced days by "+num+" days to: "+ server_today.toString());
|
|
|
+
|
|
|
|
|
|
encrypted_table = await simple_request("/reachability");
|
|
|
console.log("Got Encrypted Table: " + encrypted_table);
|
|
|
-let requested_level_two = level_up(lox_cred, encrypted_table, pubkeys);
|
|
|
+let requested_level_two = level_up(lox_cred, encrypted_table, pubkeys, server_today);
|
|
|
|
|
|
// Level Up to Trust Level 2
|
|
|
lox_cred = await init().then(() => {
|
|
|
@@ -90,10 +106,16 @@ lox_cred = await init().then(() => {
|
|
|
return cred;
|
|
|
});
|
|
|
|
|
|
+ // Level Up days + 29
|
|
|
+ num = 29;
|
|
|
+ server_today = await requested_days("/advancedays", num.toString());
|
|
|
+ console.log("Advanced days by "+num+" days to: "+ server_today.toString());
|
|
|
+
|
|
|
+
|
|
|
// Update reachability cred
|
|
|
encrypted_table = await simple_request("/reachability");
|
|
|
console.log("Got Encrypted Table: " + encrypted_table);
|
|
|
- let requested_level_three = level_up(lox_cred, encrypted_table, pubkeys);
|
|
|
+ let requested_level_three = level_up(lox_cred, encrypted_table, pubkeys, server_today);
|
|
|
|
|
|
// Level Up to Trust Level 3
|
|
|
lox_cred = await init().then(() => {
|
|
|
@@ -108,10 +130,17 @@ lox_cred = await init().then(() => {
|
|
|
let info_three = get_invites_remaining(lox_cred);
|
|
|
console.log("Last upgrade time: "+info_three);
|
|
|
|
|
|
+
|
|
|
+ // Level Up days + 57
|
|
|
+ num = 57;
|
|
|
+ server_today = await requested_days("/advancedays", num.toString());
|
|
|
+ console.log("Advanced days by "+num+" days to: "+ server_today.toString());
|
|
|
+
|
|
|
+
|
|
|
// Update reachability cred
|
|
|
encrypted_table = await simple_request("/reachability");
|
|
|
console.log("Got Encrypted Table: " + encrypted_table);
|
|
|
-let requested_level_four = level_up(lox_cred, encrypted_table, pubkeys);
|
|
|
+let requested_level_four = level_up(lox_cred, encrypted_table, pubkeys, server_today);
|
|
|
|
|
|
// Level Up to Trust Level 4
|
|
|
lox_cred = await init().then(() => {
|
|
|
@@ -126,7 +155,7 @@ lox_cred = await init().then(() => {
|
|
|
// Update reachability cred
|
|
|
encrypted_table = await simple_request("/reachability");
|
|
|
console.log("Got Encrypted Table: " + encrypted_table);
|
|
|
-let requested_issue_invitation = issue_invite(lox_cred, encrypted_table, pubkeys);
|
|
|
+let requested_issue_invitation = issue_invite(lox_cred, encrypted_table, pubkeys, server_today);
|
|
|
|
|
|
// Issue an Invitation cred
|
|
|
lox_cred = await init().then(() => {
|
|
|
@@ -140,7 +169,7 @@ lox_cred = await init().then(() => {
|
|
|
|
|
|
let prepared_invitation = prepare_invite(lox_cred);
|
|
|
// Trusted Invitation Request
|
|
|
-let requested_invitation = redeem_invite(prepared_invitation, pubkeys);
|
|
|
+let requested_invitation = redeem_invite(prepared_invitation, pubkeys, server_today);
|
|
|
// Redeem an Invitation cred
|
|
|
|
|
|
let info_four = get_received_invite_expiry(lox_cred);
|
|
|
@@ -155,6 +184,18 @@ let lox_cred_from_invite = await init().then(() => {
|
|
|
return cred;
|
|
|
});
|
|
|
|
|
|
+
|
|
|
+ let bridgelines = get_bridgelines_from_bucket(lox_cred, encrypted_table, pubkeys);
|
|
|
+ console.log("Bridgelines available: "+bridgelines);
|
|
|
+ let single_bridgeline = get_bridge_fingerprint(bridgelines, 2);
|
|
|
+ console.log("Bridgelines available: "+single_bridgeline);
|
|
|
+
|
|
|
+ await loxServerBlockageRequest("/blockbridges", JSON.parse(single_bridgeline));
|
|
|
+ let second_bridgeline = get_bridge_fingerprint(bridgelines, 1);
|
|
|
+ console.log("Bridgelines available: "+second_bridgeline);
|
|
|
+
|
|
|
+ await loxServerBlockageRequest("/blockbridges", JSON.parse(second_bridgeline));
|
|
|
+
|
|
|
let requested_check_blockage = check_blockage(lox_cred, pubkeys);
|
|
|
|
|
|
// Check whether or not a bucket is blocked
|
|
|
@@ -162,7 +203,7 @@ let lox_cred_from_invite = await init().then(() => {
|
|
|
set_panic_hook();
|
|
|
let cred = requested_cred("/checkblockage", requested_check_blockage).then((response)=> {
|
|
|
console.log("Got check blockage Migration Credential: " + response);
|
|
|
- return handle_check_blockage(requested_check_blockage, response);
|
|
|
+ return handle_check_blockage(requested_check_blockage, response, pubkeys);
|
|
|
});
|
|
|
return cred;
|
|
|
});
|
|
|
@@ -179,6 +220,19 @@ let requested_blockage_migration = blockage_migration(lox_cred, check_migration_
|
|
|
return cred;
|
|
|
});
|
|
|
|
|
|
+function open_requested_cred(command, requested) {
|
|
|
+ return new Promise((fulfill, reject) => {
|
|
|
+ let req = JSON.parse(requested);
|
|
|
+ loxServerPostRequest(command, req.open_inv_req).then((response) => {
|
|
|
+ fulfill(JSON.stringify(response));
|
|
|
+ return;
|
|
|
+ }).catch(() => {
|
|
|
+ console.log("Error requesting new Lox credential from server");
|
|
|
+ reject();
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
function requested_cred(command, requested) {
|
|
|
return new Promise((fulfill, reject) => {
|
|
|
@@ -193,6 +247,20 @@ function requested_cred(command, requested) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+function requested_days(command, days) {
|
|
|
+ return new Promise((fulfill, reject) => {
|
|
|
+ let req = JSON.parse(days)
|
|
|
+ loxServerPostRequest(command, req).then((response) => {
|
|
|
+ fulfill(response);
|
|
|
+ return;
|
|
|
+ }).catch(() => {
|
|
|
+ console.log("Error requesting new Lox credential from server");
|
|
|
+ reject();
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
function request_open_invite() {
|
|
|
return new Promise((fulfill, reject) => {
|
|
|
loxServerPostRequest("/invite", null).then((response) => {
|
|
|
@@ -247,6 +315,34 @@ function loxServerPostRequest(data, payload) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+function loxServerBlockageRequest(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;
|
|
|
+ }
|
|
|
+ fulfill();
|
|
|
+ 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) {
|