feat(wasm): configure serde_wasm_bindgen for plain-object HashMap
Maps serialize as JS objects, not Maps — what the extension popup expects. Also ships hand-written TS declarations for the bridge (consumed by Plan 1C). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -46,7 +46,7 @@ pub fn lock(handle: &SessionHandle) -> bool {
|
||||
|
||||
// Subsequent wasm_bindgen fns added in Tasks 19-21.
|
||||
|
||||
use serde_wasm_bindgen::to_value;
|
||||
use serde_wasm_bindgen::Serializer;
|
||||
use relicario_core::{
|
||||
decrypt_item, decrypt_manifest, decrypt_settings,
|
||||
encrypt_item, encrypt_manifest, encrypt_settings,
|
||||
@@ -58,13 +58,18 @@ fn need_key(handle: &SessionHandle) -> Result<(), JsError> {
|
||||
else { Err(JsError::new("invalid or locked session handle")) }
|
||||
}
|
||||
|
||||
fn js_value_for<T: serde::Serialize>(v: &T) -> Result<JsValue, JsError> {
|
||||
let ser = Serializer::new().serialize_maps_as_objects(true);
|
||||
v.serialize(&ser).map_err(|e| JsError::new(&e.to_string()))
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn manifest_decrypt(handle: &SessionHandle, encrypted: &[u8]) -> Result<JsValue, JsError> {
|
||||
need_key(handle)?;
|
||||
let out = session::with(handle.0, |k| decrypt_manifest(encrypted, k))
|
||||
.unwrap()
|
||||
.map_err(|e| JsError::new(&e.to_string()))?;
|
||||
to_value(&out).map_err(|e| JsError::new(&e.to_string()))
|
||||
js_value_for(&out)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
@@ -83,7 +88,7 @@ pub fn item_decrypt(handle: &SessionHandle, encrypted: &[u8]) -> Result<JsValue,
|
||||
let out = session::with(handle.0, |k| decrypt_item(encrypted, k))
|
||||
.unwrap()
|
||||
.map_err(|e| JsError::new(&e.to_string()))?;
|
||||
to_value(&out).map_err(|e| JsError::new(&e.to_string()))
|
||||
js_value_for(&out)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
@@ -102,7 +107,7 @@ pub fn settings_decrypt(handle: &SessionHandle, encrypted: &[u8]) -> Result<JsVa
|
||||
let out = session::with(handle.0, |k| decrypt_settings(encrypted, k))
|
||||
.unwrap()
|
||||
.map_err(|e| JsError::new(&e.to_string()))?;
|
||||
to_value(&out).map_err(|e| JsError::new(&e.to_string()))
|
||||
js_value_for(&out)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
@@ -185,10 +190,10 @@ pub fn generate_passphrase(request_json: &str) -> Result<String, JsError> {
|
||||
#[wasm_bindgen]
|
||||
pub fn rate_passphrase(p: &str) -> Result<JsValue, JsError> {
|
||||
let est = core_rate_passphrase(p);
|
||||
to_value(&serde_json::json!({
|
||||
js_value_for(&serde_json::json!({
|
||||
"score": est.score,
|
||||
"guesses_log10": est.guesses_log10,
|
||||
})).map_err(|e| JsError::new(&e.to_string()))
|
||||
}))
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
||||
Reference in New Issue
Block a user