diff --git a/crates/claims/crates/data-integrity/core/src/proof/de/mod.rs b/crates/claims/crates/data-integrity/core/src/proof/de/mod.rs index 0c06af06c..0c00075cd 100644 --- a/crates/claims/crates/data-integrity/core/src/proof/de/mod.rs +++ b/crates/claims/crates/data-integrity/core/src/proof/de/mod.rs @@ -14,7 +14,7 @@ use serde::{ de::{DeserializeSeed, MapAccess}, Deserialize, }; -use ssi_core::de::WithType; +use ssi_core::{de::WithType, OneOrMany}; use std::{collections::BTreeMap, marker::PhantomData}; mod field; @@ -54,7 +54,7 @@ impl<'de, T: DeserializeCryptographicSuite<'de>> Proof { let mut verification_method = None; let mut proof_purpose = None; let mut expires: Option = None; - let mut domains = None; + let mut domains: Option> = None; let mut challenge = None; let mut nonce = None; @@ -105,7 +105,7 @@ impl<'de, T: DeserializeCryptographicSuite<'de>> Proof { proof_purpose: proof_purpose .ok_or_else(|| serde::de::Error::custom("missing `proofPurpose` property"))?, expires: datetime_to_utc_datetimestamp(expires), - domains: domains.unwrap_or_default(), + domains: domains.map(|d| d.into_vec()).unwrap_or_default(), challenge, nonce, options, diff --git a/crates/claims/crates/data-integrity/core/src/proof/mod.rs b/crates/claims/crates/data-integrity/core/src/proof/mod.rs index 660462792..abb898567 100644 --- a/crates/claims/crates/data-integrity/core/src/proof/mod.rs +++ b/crates/claims/crates/data-integrity/core/src/proof/mod.rs @@ -48,10 +48,7 @@ pub struct Proof { pub type_: S, /// Date a creation of the proof. - #[serde( - deserialize_with = "de::deserialize_datetime_utc", - skip_serializing_if = "Option::is_none" - )] + #[serde(skip_serializing_if = "Option::is_none")] pub created: Option, /// Verification method. @@ -62,10 +59,7 @@ pub struct Proof { pub proof_purpose: ProofPurpose, /// Specifies when the proof expires. - #[serde( - deserialize_with = "de::deserialize_datetime_utc", - skip_serializing_if = "Option::is_none" - )] + #[serde(skip_serializing_if = "Option::is_none")] pub expires: Option, #[allow(rustdoc::bare_urls)] diff --git a/crates/claims/crates/data-integrity/src/core_tests.rs b/crates/claims/crates/data-integrity/src/core_tests.rs new file mode 100644 index 000000000..8fe77075d --- /dev/null +++ b/crates/claims/crates/data-integrity/src/core_tests.rs @@ -0,0 +1,20 @@ +use super::*; + +#[test] +fn single_domain_de_serialization() { + let json_proof = serde_json::json!( + { + "type": "DataIntegrityProof", + "cryptosuite": "ecdsa-rdfc-2019", + "created": "2024-12-18T10:31:42.962679Z", + "verificationMethod": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6IndPTjRDTmlHX1BxaWl1R0JEbnpRa1lqVG9jaDJnaTRBTHluWVIwdnN1c0kiLCJ5Ijoia2JlZ25iRzUxZHFETW9wdHgtOVIxcmpIU1B6TkhYLWdQbnFhbWJ6a1pzNCJ9#0", + "proofPurpose": "authentication", + "domain": "https://qa.veresexchanger.dev/exchangers/z19vRLNoFaBKDeDaMzRjUj8hi/exchanges/z19jYTCujFf4b6JFdCNMTXJ3s/openid/client/authorization/response", + "challenge": "z19jYTCujFf4b6JFdCNMTXJ3s", + "proofValue": "z3H5Bi3cF6BGEgoWdAqp13gQHEibVGtNtVbJECwfQStGmBio1gmjHrq2TGtjJ3L18pd1pKCsb4Pos9oMDpginN68h" + } + ); + let proof: Proof = + serde_json::from_value(json_proof.clone()).expect("Could not deserialize"); + assert_eq!(json_proof, serde_json::to_value(&proof).unwrap()); +} diff --git a/crates/claims/crates/data-integrity/src/lib.rs b/crates/claims/crates/data-integrity/src/lib.rs index 2681c6021..c97f7c841 100644 --- a/crates/claims/crates/data-integrity/src/lib.rs +++ b/crates/claims/crates/data-integrity/src/lib.rs @@ -5,6 +5,9 @@ pub use ssi_data_integrity_suites as suites; mod any; pub use any::*; +#[cfg(test)] +mod core_tests; + /// Any Data-Integrity proof known by this library. pub type AnyProof = Proof;