use serde_json::{Value, json};
use super::VtaClient;
use crate::error::VtaError;
use crate::trust_tasks;
const ROOM_TT_TIMEOUT: u64 = 30;
impl VtaClient {
pub async fn room_present(
&self,
room_id: &str,
action: &str,
audience: Option<&str>,
nonce: Option<&str>,
) -> Result<Value, VtaError> {
let mut payload = json!({
"roomId": room_id,
"action": action,
});
if let Some(audience) = audience {
payload["audience"] = Value::String(audience.to_string());
}
if let Some(nonce) = nonce {
payload["nonce"] = Value::String(nonce.to_string());
}
self.dispatch_trust_task(
trust_tasks::TASK_ROOMS_KEYS_PRESENT_0_1,
payload,
ROOM_TT_TIMEOUT,
)
.await
}
pub async fn room_open(
&self,
room_id: &str,
key: &str,
version: u64,
ciphertext: &str,
nonce: &str,
epoch: u32,
) -> Result<Value, VtaError> {
let payload = json!({
"roomId": room_id,
"key": key,
"version": version,
"sealed": {
"ciphertext": ciphertext,
"nonce": nonce,
"epoch": epoch,
},
});
self.dispatch_trust_task(
trust_tasks::TASK_ROOMS_KEYS_OPEN_0_1,
payload,
ROOM_TT_TIMEOUT,
)
.await
}
}