feat: Add function to retrieve the current keyspace name in WebAssembly bindings

This commit is contained in:
Sameh Abouel-saad 2025-06-04 16:43:54 +03:00
parent 4e1e707f85
commit a0622629ae

View File

@ -270,6 +270,22 @@ pub async fn sign(message: &[u8]) -> Result<JsValue, JsValue> {
}
}
/// Get the current keyspace name
#[wasm_bindgen]
pub fn get_current_keyspace_name() -> Result<String, JsValue> {
SESSION_MANAGER.with(|cell| {
if let Some(session) = cell.borrow().as_ref() {
if let Some(keyspace_name) = session.current_keyspace_name() {
Ok(keyspace_name.to_string())
} else {
Err(JsValue::from_str("No keyspace unlocked"))
}
} else {
Err(JsValue::from_str("Session not initialized"))
}
})
}
/// Sign message with default keypair (first keypair in keyspace) without changing session state
#[wasm_bindgen]
pub async fn sign_with_default_keypair(message: &[u8]) -> Result<JsValue, JsValue> {