diff --git a/src/core/input_descriptor.rs b/src/core/input_descriptor.rs index 7857980..084ac83 100644 --- a/src/core/input_descriptor.rs +++ b/src/core/input_descriptor.rs @@ -650,3 +650,33 @@ pub enum ConstraintsLimitDisclosure { Required, Preferred, } + +#[cfg(test)] +mod tests { + use crate::core::presentation_definition::PresentationDefinition; + + use super::*; + + use anyhow::Result; + + #[test] + fn test_input_descriptor_credential_type() -> Result<()> { + let definition: PresentationDefinition = serde_json::from_str(include_str!( + "../../tests/presentation-definition/iso.org.18013.5.1.mdl.json" + ))?; + + let credentials = definition + .input_descriptors() + .iter() + .flat_map(|descriptor| descriptor.constraints().fields()) + .filter_map(|field| field.credential_type()) + .collect::>(); + + assert_eq!( + credentials.first(), + Some(&"iso.org.18013.5.1.mDL".to_string()) + ); + + Ok(()) + } +} diff --git a/tests/presentation-definition/iso.org.18013.5.1.mdl.json b/tests/presentation-definition/iso.org.18013.5.1.mdl.json new file mode 100644 index 0000000..58f7f0a --- /dev/null +++ b/tests/presentation-definition/iso.org.18013.5.1.mdl.json @@ -0,0 +1,67 @@ +{ + "id": "mDL_presentation_request", + "input_descriptors": [ + { + "id": "mDL_credential", + "name": "Mobile Driving License", + "purpose": "To verify your driving privileges and age.", + "constraints": { + "fields": [ + { + "path": ["$.type"], + "filter": { + "type": "array", + "contains": { + "const": "iso.org.18013.5.1.mDL" + } + } + }, + { + "path": ["$.credentialSubject.family_name", "$.vc.credentialSubject.family_name"], + "purpose": "We need your family name for identification.", + "filter": { + "type": "string" + } + }, + { + "path": ["$.credentialSubject.given_name", "$.vc.credentialSubject.given_name"], + "purpose": "We need your given name for identification.", + "filter": { + "type": "string" + } + }, + { + "path": ["$.credentialSubject.birth_date", "$.vc.credentialSubject.birth_date"], + "purpose": "We need your birth date to verify your age.", + "filter": { + "type": "string", + "format": "date" + } + }, + { + "path": ["$.credentialSubject.driving_privileges", "$.vc.credentialSubject.driving_privileges"], + "purpose": "We need to verify your driving privileges.", + "filter": { + "type": "array" + } + }, + { + "path": ["$.credentialSubject.document_number", "$.vc.credentialSubject.document_number"], + "purpose": "We need your license number for record-keeping.", + "filter": { + "type": "string" + } + }, + { + "path": ["$.credentialSubject.expiry_date", "$.vc.credentialSubject.expiry_date"], + "purpose": "We need to check if your license is still valid.", + "filter": { + "type": "string", + "format": "date" + } + } + ] + } + } + ] +} \ No newline at end of file