From ac9d2eddf0cfbf00086728eca10240eda5fe2fe6 Mon Sep 17 00:00:00 2001 From: Yasir Date: Tue, 12 Nov 2024 23:36:49 +0300 Subject: [PATCH 1/4] Add serialization for usize as string in StatusList2021Entry --- .../src/revocation/status_list_2021/entry.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/identity_credential/src/revocation/status_list_2021/entry.rs b/identity_credential/src/revocation/status_list_2021/entry.rs index 7eecf2f28e..54eb67d1d2 100644 --- a/identity_credential/src/revocation/status_list_2021/entry.rs +++ b/identity_credential/src/revocation/status_list_2021/entry.rs @@ -37,6 +37,14 @@ where .map(ToOwned::to_owned) } +/// Serialize usize as string. +fn serialize_number_as_string(value: &usize, serializer: S) -> Result +where + S: serde::Serializer, +{ + serializer.serialize_str(&value.to_string()) +} + /// [StatusList2021Entry](https://www.w3.org/TR/2023/WD-vc-status-list-20230427/#statuslist2021entry) implementation. #[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)] #[serde(rename_all = "camelCase")] @@ -45,7 +53,10 @@ pub struct StatusList2021Entry { #[serde(rename = "type", deserialize_with = "deserialize_status_entry_type")] type_: String, status_purpose: StatusPurpose, - #[serde(deserialize_with = "serde_aux::prelude::deserialize_number_from_string")] + #[serde( + deserialize_with = "serde_aux::prelude::deserialize_number_from_string", + serialize_with = "serialize_number_as_string" + )] status_list_index: usize, status_list_credential: Url, } From b5e19dc0f626ab43e8d5ed4bfda7f5a21d242fcc Mon Sep 17 00:00:00 2001 From: Yasir Date: Tue, 12 Nov 2024 23:41:52 +0300 Subject: [PATCH 2/4] Add test for statusListIndex serialization in StatusList2021Entry --- .../src/revocation/status_list_2021/entry.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/identity_credential/src/revocation/status_list_2021/entry.rs b/identity_credential/src/revocation/status_list_2021/entry.rs index 54eb67d1d2..92415d06b7 100644 --- a/identity_credential/src/revocation/status_list_2021/entry.rs +++ b/identity_credential/src/revocation/status_list_2021/entry.rs @@ -153,4 +153,13 @@ mod tests { }); serde_json::from_value::(status).expect("wrong type"); } + + #[test] + fn test_status_list_index_serialization() { + let base_url = Url::parse("https://example.com/credentials/status/3").unwrap(); + + let entry1 = StatusList2021Entry::new(base_url.clone(), StatusPurpose::Revocation, 94567, None); + let json1 = serde_json::to_value(&entry1).unwrap(); + assert_eq!(json1["statusListIndex"], "94567"); + } } From ab12d391bc66f0f6ea6bd13db36ad1d3ed910e4e Mon Sep 17 00:00:00 2001 From: Yasir Date: Wed, 13 Nov 2024 15:00:26 +0300 Subject: [PATCH 3/4] chore: downgrade rust version for wasm crate --- bindings/wasm/rust-toolchain.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/wasm/rust-toolchain.toml b/bindings/wasm/rust-toolchain.toml index 825d39b571..3a9e267a24 100644 --- a/bindings/wasm/rust-toolchain.toml +++ b/bindings/wasm/rust-toolchain.toml @@ -1,5 +1,6 @@ [toolchain] -channel = "stable" +#@itsyaasir - Update to latest stable version when wasm-bindgen is updated +channel = "1.81" components = ["rustfmt"] targets = ["wasm32-unknown-unknown"] profile = "minimal" From 4cc13b3d1848bf0de12e0a6814c9adbe77670e70 Mon Sep 17 00:00:00 2001 From: Yasir Date: Wed, 13 Nov 2024 15:02:54 +0300 Subject: [PATCH 4/4] chore: fmt --- bindings/wasm/rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/wasm/rust-toolchain.toml b/bindings/wasm/rust-toolchain.toml index 3a9e267a24..eb46cc977d 100644 --- a/bindings/wasm/rust-toolchain.toml +++ b/bindings/wasm/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -#@itsyaasir - Update to latest stable version when wasm-bindgen is updated +# @itsyaasir - Update to latest stable version when wasm-bindgen is updated channel = "1.81" components = ["rustfmt"] targets = ["wasm32-unknown-unknown"]