Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
justAnIdentity committed Aug 15, 2023
1 parent 0b58d3c commit 55c16b7
Showing 1 changed file with 17 additions and 178 deletions.
195 changes: 17 additions & 178 deletions src/mdl_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub fn prepare_mdl_request_object(
response_uri: String,
presentation_id: String,
) -> Result<RequestObject, Openid4vpError> {
let jwks = json!({"keys": vec![jwk]});
let presentation_definition = mdl_presentation_definition(requested_fields, presentation_id)?;
let client_metadata = ClientMetadata {
authorization_encrypted_response_alg: "ES256".to_string(),
Expand All @@ -77,7 +78,7 @@ pub fn prepare_mdl_request_object(
"ES256"
]
}}),
jwks: json!(jwk),
jwks: jwks,
require_signed_request_object: false,
};

Expand Down Expand Up @@ -118,11 +119,6 @@ fn build_input_descriptors(
) -> Vec<InputDescriptor> {
let path_base = "$['org.iso.18013.5.1']";

// let doc_type_filter = json!({
// "type": "string",
// "const": "org.iso.18013.5.1.mDL"
// });

let input_descriptors: Vec<InputDescriptor> = namespaces
.iter()
.map(|namespace| {
Expand Down Expand Up @@ -187,185 +183,28 @@ pub fn x509_public_key(der: Vec<u8>) -> Result<p256::PublicKey, String> {
.map_err(|e| format!("could not parse p256 public key from pkcs8 spki: {e}"))
}

fn _minimal_mdl_request_isomdl() -> BTreeMap<String, bool> {
BTreeMap::from([
("org.iso.18013.5.1.family_name".to_string(), false),
("org.iso.18013.5.1.given_name".to_string(), false),
("org.iso.18013.5.1.birth_date".to_string(), false),
("org.iso.18013.5.1.issue_date".to_string(), false),
("org.iso.18013.5.1.expiry_date".to_string(), false),
("org.iso.18013.5.1.issuing_country".to_string(), false),
("org.iso.18013.5.1.issuing_authority".to_string(), false),
("org.iso.18013.5.1.document_number".to_string(), false),
("org.iso.18013.5.1.portrait".to_string(), false),
("org.iso.18013.5.1.driving_privileges".to_string(), false),
(
"org.iso.18013.5.1.un_distinguishing_sign".to_string(),
false,
),
("org.iso.18013.5.1.administrative_number".to_string(), false),
("org.iso.18013.5.1.sex".to_string(), false),
("org.iso.18013.5.1.height".to_string(), false),
("org.iso.18013.5.1.weight".to_string(), false),
("org.iso.18013.5.1.eye_colour".to_string(), false),
("org.iso.18013.5.1.hair_colour".to_string(), false),
("org.iso.18013.5.1.birth_place".to_string(), false),
("org.iso.18013.5.1.resident_address".to_string(), false),
("org.iso.18013.5.1.portrait_capture_date".to_string(), false),
("org.iso.18013.5.1.age_in_years".to_string(), false),
("org.iso.18013.5.1.age_birth_year".to_string(), false),
("org.iso.18013.5.1.age_over_18".to_string(), true),
("org.iso.18013.5.1.age_over_21".to_string(), true),
("org.iso.18013.5.1.issuing_jurisdiction".to_string(), false),
("org.iso.18013.5.1.nationality".to_string(), false),
("org.iso.18013.5.1.resident_city".to_string(), false),
("org.iso.18013.5.1.resident_state".to_string(), false),
("org.iso.18013.5.1.resident_postal_code".to_string(), false),
("org.iso.18013.5.1.resident_country".to_string(), false),
])
}

fn _aamva_isomdl_data() -> BTreeMap<String, bool> {
BTreeMap::from([
("domestic_driving_privileges".to_string(), false),
("name_suffix".to_string(), false),
("organ_donor".to_string(), false),
("veteran".to_string(), false),
("family_name_truncation".to_string(), false),
("given_name_truncation".to_string(), false),
("aka_family_name.v2".to_string(), false),
("aka_given_name.v2".to_string(), false),
("weight_range".to_string(), false),
("race_ethnicity".to_string(), false),
("EDL_credential".to_string(), false),
("DHS_compliance".to_string(), false),
("sex".to_string(), false),
("resident_county".to_string(), false),
("hazmat_endorsement_expiration_date".to_string(), false),
("CDL_indicator".to_string(), false),
("DHS_compliance_text".to_string(), false),
("DHS_temporary_lawful_status".to_string(), false),
])
}

pub fn minimal_mdl_request() -> BTreeMap<Option<String>, Option<bool>> {
BTreeMap::from([
(
Some("org.iso.18013.5.1.family_name".to_string()),
Some(true),
),
(Some("org.iso.18013.5.1.given_name".to_string()), Some(true)),
(
Some("org.iso.18013.5.1.birth_date".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.issue_date".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.expiry_date".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.issuing_country".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.issuing_authority".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.document_number".to_string()),
Some(false),
),
(Some("org.iso.18013.5.1.portrait".to_string()), Some(false)),
(
Some("org.iso.18013.5.1.driving_privileges".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.un_distinguishing_sign".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.administrative_number".to_string()),
Some(false),
),
(Some("org.iso.18013.5.1.sex".to_string()), Some(false)),
(Some("org.iso.18013.5.1.height".to_string()), Some(false)),
(Some("org.iso.18013.5.1.weight".to_string()), Some(false)),
(
Some("org.iso.18013.5.1.eye_colour".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.hair_colour".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.birth_place".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.resident_address".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.portrait_capture_date".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.age_in_years".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.age_birth_year".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.age_over_18".to_string()),
Some(true),
),
(
Some("org.iso.18013.5.1.age_over_21".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.issuing_jurisdiction".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.nationality".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.resident_city".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.resident_state".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.resident_postal_code".to_string()),
Some(false),
),
(
Some("org.iso.18013.5.1.resident_country".to_string()),
Some(false),
),
])
}

#[cfg(test)]
pub(crate) mod tests {
use super::*;

fn prove_name_request() -> BTreeMap<Option<String>, Option<bool>> {
BTreeMap::from([
(
Some("org.iso.18013.5.1.family_name".to_string()),
Some(true),
),
(Some("org.iso.18013.5.1.given_name".to_string()), Some(true)),
(
Some("org.iso.18013.5.1.birth_date".to_string()),
Some(false),
),
])
}

#[test]
fn request_example() {
const DID_JWK: &str = r#"{"kty":"EC","crv":"secp256k1","x":"nrVtymZmqiSu9lU8DmVnB6W7XayJUj4uN7hC3uujZ9s","y":"XZA56MU96ne2c2K-ldbZxrAmLOsneJL1lE4PFnkyQnA","d":"mojL_WMJuMp1vmHNLUkc4es6IeAfcDB7qyZqTeKCEqE"}"#;
let minimal_mdl_request = NonEmptyMap::try_from(minimal_mdl_request()).unwrap();
let minimal_mdl_request = NonEmptyMap::try_from(prove_name_request()).unwrap();
let namespaces = NonEmptyMap::new("org.iso.18013.5.1".to_string(), minimal_mdl_request);
let client_id = "nonce".to_string();
let redirect_uri = "localhost::3000".to_string();
Expand Down

0 comments on commit 55c16b7

Please sign in to comment.