Skip to content

Commit

Permalink
Fix domains deserialization for dataintegrity (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel authored Dec 20, 2024
1 parent 565707b commit 8764a8b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
6 changes: 3 additions & 3 deletions crates/claims/crates/data-integrity/core/src/proof/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<'de, T: DeserializeCryptographicSuite<'de>> Proof<T> {
let mut verification_method = None;
let mut proof_purpose = None;
let mut expires: Option<xsd_types::DateTime> = None;
let mut domains = None;
let mut domains: Option<OneOrMany<String>> = None;
let mut challenge = None;
let mut nonce = None;

Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'de, T: DeserializeCryptographicSuite<'de>> Proof<T> {
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,
Expand Down
10 changes: 2 additions & 8 deletions crates/claims/crates/data-integrity/core/src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ pub struct Proof<S: CryptographicSuite> {
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<xsd_types::DateTimeStamp>,

/// Verification method.
Expand All @@ -62,10 +59,7 @@ pub struct Proof<S: CryptographicSuite> {
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<xsd_types::DateTimeStamp>,

#[allow(rustdoc::bare_urls)]
Expand Down
20 changes: 20 additions & 0 deletions crates/claims/crates/data-integrity/src/core_tests.rs
Original file line number Diff line number Diff line change
@@ -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<AnySuite> =
serde_json::from_value(json_proof.clone()).expect("Could not deserialize");
assert_eq!(json_proof, serde_json::to_value(&proof).unwrap());
}
3 changes: 3 additions & 0 deletions crates/claims/crates/data-integrity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnySuite>;

Expand Down

0 comments on commit 8764a8b

Please sign in to comment.