Add request_data()
This commit is contained in:
parent
c0adce2b31
commit
feeaedc917
37
src/api.rs
37
src/api.rs
@ -1470,6 +1470,43 @@ pub fn update_process(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn request_data(process_id: String, state_ids: Vec<String>, managers: Vec<String>) -> ApiResult<ApiReturn> {
|
||||||
|
let outpoint = OutPoint::from_str(&process_id)?;
|
||||||
|
let send_to: Vec<String> = managers.iter().flat_map(|m| {
|
||||||
|
let member: Member = serde_json::from_str(m).unwrap();
|
||||||
|
member.get_addresses()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let sender = lock_local_device()?.to_member();
|
||||||
|
|
||||||
|
let prd_request = Prd::new_request(
|
||||||
|
outpoint,
|
||||||
|
sender,
|
||||||
|
state_ids.iter().map(|s| Vec::from_hex(s).unwrap().try_into().unwrap()).collect());
|
||||||
|
|
||||||
|
let local_device = lock_local_device()?;
|
||||||
|
let sp_wallet = local_device.get_wallet();
|
||||||
|
let prd_msg = prd_request.to_network_msg(sp_wallet)?;
|
||||||
|
|
||||||
|
// For now, we just send the request to all admins, but this could be refined
|
||||||
|
let shared_secrets = lock_shared_secrets()?;
|
||||||
|
let mut ciphers = vec![];
|
||||||
|
for address in send_to {
|
||||||
|
if let Some(secret) = shared_secrets.get_secret_for_address(address.try_into()?) {
|
||||||
|
let cipher = encrypt_with_key(secret.as_byte_array(), prd_msg.as_bytes())?;
|
||||||
|
ciphers.push(cipher.to_lower_hex_string());
|
||||||
|
} else {
|
||||||
|
debug!("No shared secret");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(ApiReturn {
|
||||||
|
ciphers_to_send: ciphers,
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn create_update_message(
|
pub fn create_update_message(
|
||||||
process_id: String,
|
process_id: String,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user