Skip to content

Commit

Permalink
Fix domains deserialization for dataintegrity
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel committed Dec 18, 2024
1 parent 565707b commit cd2ad7a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 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
2 changes: 0 additions & 2 deletions crates/claims/crates/data-integrity/core/src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub struct Proof<S: CryptographicSuite> {

/// Date a creation of the proof.
#[serde(
deserialize_with = "de::deserialize_datetime_utc",
skip_serializing_if = "Option::is_none"
)]
pub created: Option<xsd_types::DateTimeStamp>,
Expand All @@ -63,7 +62,6 @@ pub struct Proof<S: CryptographicSuite> {

/// Specifies when the proof expires.
#[serde(
deserialize_with = "de::deserialize_datetime_utc",
skip_serializing_if = "Option::is_none"
)]
pub expires: Option<xsd_types::DateTimeStamp>,
Expand Down
81 changes: 81 additions & 0 deletions crates/claims/crates/vc/src/v2/syntax/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,84 @@ where
json.expand_with(ld, loader).await
}
}

#[cfg(test)]
mod test {
use ssi_data_integrity::{AnySuite, DataIntegrity};

use super::*;

#[test]
fn deserialize_single_domain() {
let _: DataIntegrity<JsonPresentation, AnySuite> = serde_json::from_value(serde_json::json!(
{
"@context": [
"https://www.w3.org/ns/credentials/v2"
],
"id": "urn:uuid:e6f93061-dcac-46a0-8aba-9d6278e2ada1",
"type": [
"VerifiablePresentation"
],
"holder": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6IndPTjRDTmlHX1BxaWl1R0JEbnpRa1lqVG9jaDJnaTRBTHluWVIwdnN1c0kiLCJ5Ijoia2JlZ25iRzUxZHFETW9wdHgtOVIxcmpIU1B6TkhYLWdQbnFhbWJ6a1pzNCJ9",
"verifiableCredential": {
"@context": [
"https://www.w3.org/ns/credentials/v2",
"https://examples.vcplayground.org/contexts/movie-ticket-vcdm-v2/v1.json"
],
"id": "urn:uuid:df7bbd25-6f01-46dc-b65c-c483a7841739",
"type": [
"VerifiableCredential",
"MovieTicketCredential"
],
"credentialSubject": {
"id": "did:example:b34AA2I0ZdwAACBDu",
"owns": {
"location": {
"address": {
"addressLocality": "Your Town",
"addressRegion": "VA",
"postalCode": "24060",
"streetAddress": "123 Main St."
},
"name": "Hometown Theatres, Inc."
},
"startDate": "2022-08-26T19:00:00.000Z",
"ticketNumber": "457812",
"ticketToken": "urn:1a1e549a-2867",
"ticketedSeat": {
"seatNumber": "11",
"seatRow": "E",
"seatSection": "Theatre 3"
},
"type": "Ticket"
}
},
"issuer": {
"id": "did:key:zDnaerPmH7xAjZoWanUBkRzY6xi9aTywRRoyAaHyRAsAYHCRq",
"name": "Hometown Theatres, Inc."
},
"description": "Admit one: Plan 9 from Outer Space, 3pm showing.",
"image": "data:image/png;base64,iVBO...",
"proof": {
"created": "2024-12-18T09:55:11Z",
"cryptosuite": "ecdsa-rdfc-2019",
"proofPurpose": "assertionMethod",
"proofValue": "znvWgrZtpc9aqGRhyCnf22WLddL6L1rGA1CRPEBPWRbw7sKUCC1DrC2GrASDEyA5W3C3DCV3p4zZg6Zp4sYSKduT",
"type": "DataIntegrityProof",
"verificationMethod": "did:key:zDnaerPmH7xAjZoWanUBkRzY6xi9aTywRRoyAaHyRAsAYHCRq#zDnaerPmH7xAjZoWanUBkRzY6xi9aTywRRoyAaHyRAsAYHCRq"
}
},
"proof": {
"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"
}
}
)).expect("Could not deserialize");
}
}

0 comments on commit cd2ad7a

Please sign in to comment.