Add blockage migration (untested)
This commit is contained in:
parent
7c770b1310
commit
e12bff83e3
|
@ -14,6 +14,8 @@ import init, {
|
|||
handle_redeem_invite,
|
||||
check_blockage,
|
||||
handle_check_blockage,
|
||||
blockage_migration,
|
||||
handle_blockage_migration,
|
||||
set_panic_hook } from "./pkg/lox_wasm.js";
|
||||
let pubkeys = await simple_request("/pubkeys");
|
||||
console.log("Got pubkeys: " + pubkeys);
|
||||
|
@ -140,7 +142,7 @@ let lox_cred_from_invite = await init().then(() => {
|
|||
let requested_check_blockage = check_blockage(lox_cred, pubkeys);
|
||||
|
||||
// Check whether or not a bucket is blocked
|
||||
let check_cred = await init().then(() => {
|
||||
let check_migration_cred = await init().then(() => {
|
||||
set_panic_hook();
|
||||
let cred = requested_cred("/checkblockage", requested_check_blockage).then((response)=> {
|
||||
console.log("Got check blockage Migration Credential: " + response);
|
||||
|
@ -149,6 +151,18 @@ let lox_cred_from_invite = await init().then(() => {
|
|||
return cred;
|
||||
});
|
||||
|
||||
let requested_blockage_migration = blockage_migration(lox_cred, check_migration_cred, pubkeys);
|
||||
|
||||
// Migrate to a new unblocked bridge
|
||||
lox_cred = await init().then(() => {
|
||||
set_panic_hook();
|
||||
let cred = requested_cred("/blockagemigration", requested_blockage_migration).then((response)=> {
|
||||
console.log("Got Lox Credential for new bucket: " + response);
|
||||
return handle_blockage_migration(requested_check_blockage, response);
|
||||
});
|
||||
return cred;
|
||||
});
|
||||
|
||||
|
||||
function requested_cred(command, requested) {
|
||||
return new Promise((fulfill, reject) => {
|
||||
|
|
|
@ -562,6 +562,64 @@ pub fn handle_check_blockage(
|
|||
Ok(serde_json::to_string(&migration_cred).unwrap())
|
||||
}
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn blockage_migration(lox_cred: String, check_migration_cred: String, lox_pub: String) -> Result<String, JsValue> {
|
||||
let lox_cred: LoxCredential = serde_json::from_str(&lox_cred).unwrap();
|
||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||
let mig_cred: Migration = serde_json::from_str(&check_migration_cred).unwrap();
|
||||
let bm_result =
|
||||
match migration::request(&lox_cred.lox_credential, &mig_cred, &pubkeys.lox_pub, &pubkeys.migration_pub) {
|
||||
Ok(tm_result) => tm_result,
|
||||
Err(e) => {
|
||||
log(&format!("Error: {:?}", e.to_string()));
|
||||
return Err(JsValue::from(e.to_string()));
|
||||
}
|
||||
};
|
||||
let req_state = MigReqState {
|
||||
request: bm_result.0,
|
||||
state: bm_result.1,
|
||||
};
|
||||
unsafe {
|
||||
log(&format!(
|
||||
"Formatted Trust Migration request: {}",
|
||||
serde_json::to_string(&req_state).unwrap()
|
||||
));
|
||||
}
|
||||
Ok(serde_json::to_string(&req_state).unwrap())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn handle_blockage_migration(
|
||||
blockage_migration_request: String,
|
||||
blockage_migration_response: String,
|
||||
lox_pub: String
|
||||
) -> Result<String, JsValue> {
|
||||
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
|
||||
let req_state: MigReqState = serde_json::from_str(&blockage_migration_request).unwrap();
|
||||
let deserialized_state = req_state.state;
|
||||
let deserialized_response = serde_json::from_str(&blockage_migration_response).unwrap();
|
||||
let lox_cred =
|
||||
match migration::handle_response(deserialized_state, deserialized_response, &pubkeys.lox_pub) {
|
||||
Ok(lox_cred) => LoxCredential {
|
||||
lox_credential: lox_cred,
|
||||
bridgeline: None,
|
||||
invitation: None,
|
||||
},
|
||||
Err(e) => {
|
||||
log(&format!("Error: {:?}", e.to_string()));
|
||||
return Err(JsValue::from(e.to_string()));
|
||||
}
|
||||
};
|
||||
unsafe {
|
||||
log(&format!(
|
||||
"Got new Level 1 Credential: {}",
|
||||
serde_json::to_string(&lox_cred).unwrap()
|
||||
));
|
||||
}
|
||||
Ok(serde_json::to_string(&lox_cred).unwrap())
|
||||
}
|
||||
|
||||
// This should also check the pubkey
|
||||
fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> {
|
||||
invite.try_into()
|
||||
|
|
Loading…
Reference in New Issue