-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Bug description
The current implementation of the impl_wasm_json macro and the TryFrom<&Object> for MapStringAny implementation use the deprecated JsValue::from_serde() function (just search for #[allow(deprecated)] in the repository to find it).
Replacing JsValue::from_serde() with serde_wasm_bindgen::to_value() is currently not possible because this leads to an [JwkDocumentExtensionError]: storage operation failed: key storage error in the identity_wasm examples, which is caused by the usage of serde_wasm_bindgen::to_value() in the impl_wasm_json macro.
Printing the return values of the impl_wasm_json macro (using the instrumented macro code listed at the bottom of this ticket) while executing example 0_create_did leads to the following console logs:
With JsValue::from_serde():
Received gas from faucet: 1000000000000 for owner 0xcb86154f74585c6e84129c666e0e271cbab6a20429b5fc3ae8831b3de8b076bc
--------------------------JsValue(Object({"key_id":"mcnfZ9bU5Z7FMjcK_vMCc_laHUA","jwk":{"kty":"OKP","alg":"EdDSA","kid":"fwhUCyr3tPqRxQ0QMTjXtynkBlg2zsP3eZU9DcpQTBA","crv":"Ed25519","x":"sHxo3xkueENGo7BMV1qqLm31IegWme5OzsV-NLsKc-I"}}))
With serde_wasm_bindgen::to_value():
Received gas from faucet: 1000000000000 for owner 0xa58f56e7128106dd2b3405fafe1f326d67a4aa4afc16462fc841fc16503c636f
--------------------------JsValue(Object({"key_id":"z1KXwMdCrBUuk1CYzBo-tyOOa5o","jwk":{}}))
We need to find out why the jwk field serealization/de-serialization fails and after having fixed that, replace all JsValue::from_serde() usages with serde_wasm_bindgen::to_value().
This is the instrumented impl_wasm_json macro code:
macro_rules! impl_wasm_json {
($wasm_class:ident, $js_class:ident) => {
#[wasm_bindgen(js_class = $js_class)]
impl $wasm_class {
/// Serializes this to a JSON object.
#[wasm_bindgen(js_name = toJSON)]
pub fn to_json(&self) -> $crate::bindings::wasm_error::Result<wasm_bindgen::JsValue> {
use $crate::bindings::wasm_error::WasmResult;
//let ret_val = serde_wasm_bindgen::to_value(&self.0).wasm_result();
let ret_val = wasm_bindgen::JsValue::from_serde(&self.0).wasm_result();
if let Ok(val) = &ret_val {
$crate::console_log!("--------------------------{:?}", val);
}
ret_val
}
/// Deserializes an instance from a JSON object.
#[wasm_bindgen(js_name = fromJSON)]
pub fn from_json(json: &wasm_bindgen::JsValue) -> $crate::bindings::wasm_error::Result<$wasm_class> {
use $crate::bindings::wasm_error::WasmResult;
json.into_serde().map(Self).wasm_result()
}
}
};
}Expected behavior
No response
Can the issue reliably be reproduced?
Yes
Example repository
No response
Steps to reproduce
See above
Language
Rust
Language Version
rustc 1.87.0
Version
iota v1.2.3
Hardware specifications
Additional info
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status