libsoliton/soliton_wasm/src/call.rs
Kamal Tufekcic 1d99048c95
Some checks failed
CI / lint (push) Successful in 1m37s
CI / test-python (push) Successful in 1m49s
CI / test-zig (push) Successful in 1m39s
CI / test-wasm (push) Successful in 1m54s
CI / test (push) Successful in 14m44s
CI / miri (push) Successful in 14m18s
CI / build (push) Successful in 1m9s
CI / fuzz-regression (push) Successful in 9m9s
CI / publish (push) Failing after 1m10s
CI / publish-python (push) Failing after 1m46s
CI / publish-wasm (push) Has been cancelled
initial commit
Signed-off-by: Kamal Tufekcic <kamal@lo.sh>
2026-04-02 23:48:10 +03:00

54 lines
1.4 KiB
Rust

//! Call key derivation.
use crate::errors::to_js_err;
use wasm_bindgen::prelude::*;
/// Call keys for encrypted voice/video media.
///
/// Call `free()` when done to zeroize key material.
#[wasm_bindgen]
pub struct CallKeys {
inner: Option<soliton::call::CallKeys>,
}
#[wasm_bindgen]
impl CallKeys {
/// Current send key (32 bytes).
#[wasm_bindgen(js_name = "sendKey")]
pub fn send_key(&self) -> Result<Vec<u8>, JsValue> {
let inner = self
.inner
.as_ref()
.ok_or_else(|| crate::errors::js_error("call keys consumed"))?;
Ok(inner.send_key().to_vec())
}
/// Current recv key (32 bytes).
#[wasm_bindgen(js_name = "recvKey")]
pub fn recv_key(&self) -> Result<Vec<u8>, JsValue> {
let inner = self
.inner
.as_ref()
.ok_or_else(|| crate::errors::js_error("call keys consumed"))?;
Ok(inner.recv_key().to_vec())
}
/// Advance the call chain — derives fresh keys, zeroizes old ones.
pub fn advance(&mut self) -> Result<(), JsValue> {
let inner = self
.inner
.as_mut()
.ok_or_else(|| crate::errors::js_error("call keys consumed"))?;
inner.advance().map_err(to_js_err)
}
pub fn free(&mut self) {
self.inner = None;
}
}
impl CallKeys {
pub fn from_inner(inner: soliton::call::CallKeys) -> Self {
Self { inner: Some(inner) }
}
}