Skip to content

Commit

Permalink
🤖 cargo-fmt auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and nmattia committed Feb 8, 2024
1 parent 980ce71 commit d3f0336
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/vc_util/src/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/vc_util/src/issuer_api.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
14 changes: 4 additions & 10 deletions src/vc_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,9 @@ fn validate_claims_match_spec(
vc_claims: &Map<String, Value>,
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"))?;
Expand All @@ -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 {
Expand All @@ -387,7 +385,6 @@ fn validate_claims_match_spec(
}
} else {
return Err(help(format!("missing TODO, {}, {}", key, value)));

}
}
Ok(())
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 13 additions & 7 deletions src/vc_util_js/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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],
Expand All @@ -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,
Expand Down

0 comments on commit d3f0336

Please sign in to comment.