From a0622629ae2d388e8c770fac78c6e882bf9e7033 Mon Sep 17 00:00:00 2001 From: Sameh Abouel-saad Date: Wed, 4 Jun 2025 16:43:54 +0300 Subject: [PATCH] feat: Add function to retrieve the current keyspace name in WebAssembly bindings --- wasm_app/src/vault_bindings.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wasm_app/src/vault_bindings.rs b/wasm_app/src/vault_bindings.rs index e38e4fd..95ecfee 100644 --- a/wasm_app/src/vault_bindings.rs +++ b/wasm_app/src/vault_bindings.rs @@ -270,6 +270,22 @@ pub async fn sign(message: &[u8]) -> Result { } } +/// Get the current keyspace name +#[wasm_bindgen] +pub fn get_current_keyspace_name() -> Result { + 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 {