From d3f0336d1a0dd3b9190d1df89104e3baba6b6f14 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 2 Feb 2024 15:23:56 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20cargo-fmt=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/vc_util/src/custom.rs | 3 +-- src/vc_util/src/issuer_api.rs | 2 +- src/vc_util/src/lib.rs | 14 ++++---------- src/vc_util_js/src/lib.rs | 20 +++++++++++++------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/vc_util/src/custom.rs b/src/vc_util/src/custom.rs index 7d25042a71..95a996954e 100644 --- a/src/vc_util/src/custom.rs +++ b/src/vc_util/src/custom.rs @@ -67,8 +67,7 @@ pub fn validate_verified_presentation( "missing vc in id_alias JWT claims", )))?; - validate_claims_match_spec(vc_claims, credential_spec) - .map_err(invalid_requested_vc)?; + validate_claims_match_spec(vc_claims, credential_spec).map_err(invalid_requested_vc)?; Ok(()) } diff --git a/src/vc_util/src/issuer_api.rs b/src/vc_util/src/issuer_api.rs index 2c4ed55b16..0c92eb4162 100644 --- a/src/vc_util/src/issuer_api.rs +++ b/src/vc_util/src/issuer_api.rs @@ -1,5 +1,5 @@ use candid::{CandidType, Nat}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use serde_bytes::ByteBuf; use serde_json::Value; use std::collections::HashMap; diff --git a/src/vc_util/src/lib.rs b/src/vc_util/src/lib.rs index beee098ec1..526a192848 100644 --- a/src/vc_util/src/lib.rs +++ b/src/vc_util/src/lib.rs @@ -356,11 +356,9 @@ fn validate_claims_match_spec( vc_claims: &Map, spec: &CredentialSpec, ) -> Result<(), JwtValidationError> { - let credential_type = vc_claims - .get("type"); + let credential_type = vc_claims.get("type"); - let credential_type = credential_type - .ok_or(inconsistent_jwt_claims("missing type JWT vc"))?; + let credential_type = credential_type.ok_or(inconsistent_jwt_claims("missing type JWT vc"))?; let types = credential_type .as_array() .ok_or(inconsistent_jwt_claims("wrong types in JWT vc"))?; @@ -378,7 +376,7 @@ fn validate_claims_match_spec( let empty_hashmap = HashMap::new(); // TODO: why iterate over an empty map? - let iter = spec.arguments.as_ref().unwrap_or(&empty_hashmap).iter() ; + let iter = spec.arguments.as_ref().unwrap_or(&empty_hashmap).iter(); for (key, value) in iter { let foo = subject.properties.get(key); if let Some(v) = foo { @@ -387,7 +385,6 @@ fn validate_claims_match_spec( } } else { return Err(help(format!("missing TODO, {}, {}", key, value))); - } } Ok(()) @@ -438,10 +435,7 @@ fn invalid_signature_err(custom_message: &str) -> SignatureVerificationError { } fn help(msg: String) -> JwtValidationError { - JwtValidationError::CredentialStructure(JwtVcError::InvalidStatus( - msg, - )) - + JwtValidationError::CredentialStructure(JwtVcError::InvalidStatus(msg)) } fn inconsistent_jwt_claims(custom_message: &'static str) -> JwtValidationError { diff --git a/src/vc_util_js/src/lib.rs b/src/vc_util_js/src/lib.rs index 05478743a5..88273dfcb3 100644 --- a/src/vc_util_js/src/lib.rs +++ b/src/vc_util_js/src/lib.rs @@ -1,14 +1,14 @@ use candid::Principal; +use canister_sig_util::extract_raw_root_pk_from_der; use std::collections::HashMap; -use canister_sig_util::{extract_raw_root_pk_from_der}; -use vc_util::{VcFlowSigners, CredentialSpec}; use vc_util::issuer_api::ArgumentValue; +use vc_util::{CredentialSpec, VcFlowSigners}; use wasm_bindgen::prelude::wasm_bindgen; // TODO: clarify encoding of all those &[u8] #[wasm_bindgen(js_name = validateVerifiedPresentation)] pub fn validate_verified_presentation( - _credential_type: String /* TODO: USEME */, + _credential_type: String, /* TODO: USEME */ vp_jwt: &[u8], vc_subject_principal: &[u8], ii_canister_id: &[u8], @@ -21,13 +21,19 @@ pub fn validate_verified_presentation( // TODO; proper args // XXX: right now, somehow the employerName is nested in the issued jwt let arguments = None; // Some(HashMap::from([("employerName".to_string(), ArgumentValue::String("DFINITY Foundation".to_string()))])); - let credential_spec = CredentialSpec { credential_type, arguments}; + let credential_spec = CredentialSpec { + credential_type, + arguments, + }; let vp_jwt = String::from_utf8(vp_jwt.to_vec()).expect("wrong vp_jwt"); // TODO: panic does not work (unreachable) // TODO: why does Principal::from_slice not work? what is expected encoding? - let effective_vc_subject = Principal::from_text(&String::from_utf8(vc_subject_principal.to_vec()).unwrap()).unwrap(); - let ii_canister_id = Principal::from_text(&String::from_utf8(ii_canister_id.to_vec()).unwrap()).unwrap(); - let issuer_canister_id = Principal::from_text(&String::from_utf8(issuer_canister_id.to_vec()).unwrap()).unwrap(); + let effective_vc_subject = + Principal::from_text(&String::from_utf8(vc_subject_principal.to_vec()).unwrap()).unwrap(); + let ii_canister_id = + Principal::from_text(&String::from_utf8(ii_canister_id.to_vec()).unwrap()).unwrap(); + let issuer_canister_id = + Principal::from_text(&String::from_utf8(issuer_canister_id.to_vec()).unwrap()).unwrap(); let root_pk_raw = extract_raw_root_pk_from_der(root_pk_raw).unwrap(); let vc_flow_signers: VcFlowSigners = VcFlowSigners { ii_canister_id,