Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed May 13, 2024
1 parent 0ffe9eb commit f006e38
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions crates/credentials/src/vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::{
fmt::{Display, Formatter},
sync::Arc,
};
use uuid::Uuid;

const BASE_CONTEXT: &str = "https://www.w3.org/2018/credentials/v1";
const BASE_TYPE: &str = "VerifiableCredential";
Expand Down Expand Up @@ -212,7 +211,7 @@ impl VerifiableCredential {
Ok(jwt)
}

pub async fn verify(jwt: &str) -> Result<Self, CredentialError> {
pub async fn verify(jwt: &str) -> Result<Arc<VerifiableCredential>, CredentialError> {
let jwt_decoded = Jwt::verify::<VcJwtClaims>(jwt).await?;
let mut vc = jwt_decoded.claims.vc;
let registered_claims = jwt_decoded.claims.registered_claims;
Expand Down Expand Up @@ -300,7 +299,7 @@ impl VerifiableCredential {
}

validate_vc_data_model(&vc).map_err(CredentialError::ValidationError)?;
Ok(vc)
Ok(Arc::new(vc))
}

pub fn decode(jwt: &str) -> Result<Self, CredentialError> {
Expand Down Expand Up @@ -572,20 +571,21 @@ mod test {
);
}

#[tokio::test]
async fn test_minified_jwt() {
let minified_vc_jwt = "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpqd2s6ZXlKaGJHY2lPaUpGWkVSVFFTSXNJbU55ZGlJNklrVmtNalUxTVRraUxDSnJkSGtpT2lKUFMxQWlMQ0o0SWpvaVJFNU5kRGhyWVVOUGFubFNWbms0UVdoSGJWVmxkbTUzUkZGTlJYTlVkemxQY2s1M05DMHlOWFJ5VlNKOSMwIiwidHlwIjoiSldUIn0.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJpZCI6IiIsInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiIiwiaXNzdWFuY2VEYXRlIjowLCJleHBpcmF0aW9uRGF0ZSI6MCwiY3JlZGVudGlhbF9zdWJqZWN0Ijp7ImlkIjoiIn19LCJpc3MiOiJkaWQ6andrOmV5SmhiR2NpT2lKRlpFUlRRU0lzSW1OeWRpSTZJa1ZrTWpVMU1Ua2lMQ0pyZEhraU9pSlBTMUFpTENKNElqb2lSRTVOZERocllVTlBhbmxTVm5rNFFXaEhiVlZsZG01M1JGRk5SWE5VZHpsUGNrNTNOQzB5TlhSeVZTSjkiLCJzdWIiOiJkaWQ6andrOmV5SmhiR2NpT2lKRlpFUlRRU0lzSW1OeWRpSTZJa1ZrTWpVMU1Ua2lMQ0pyZEhraU9pSlBTMUFpTENKNElqb2lSRTVOZERocllVTlBhbmxTVm5rNFFXaEhiVlZsZG01M1JGRk5SWE5VZHpsUGNrNTNOQzB5TlhSeVZTSjkiLCJleHAiOjE3MTUzNzA1OTIsIm5iZiI6MTcxNTM2ODc5MiwianRpIjoidXJuOnZjOnV1aWQ6MTMwMjMwOWMtMDcyOS00YTAwLThmNDAtOTNkZjc3ZDQxODg5In0.u5SCPyx6Una88BYmztZ3-fbWnfDHCXIU6vBHva0SZtZQ8CYUaSjMvWRRCYY7j99JgHZU7R5wPHR1f7sb10qEBw";

let jwt_decoded = Jwt::verify::<VcJwtClaims>(&minified_vc_jwt).await.unwrap();
let registered_claims = jwt_decoded.claims.registered_claims;

let verify_result = VerifiableCredential::verify(minified_vc_jwt).await;
let verify_vc = verify_result.unwrap();

assert_eq!(registered_claims.jti.unwrap(), verify_vc.id);
assert_eq!(registered_claims.issuer.unwrap(), verify_vc.issuer.get_id());
assert_eq!(registered_claims.subject.unwrap(), verify_vc.credential_subject.id);
assert_eq!(registered_claims.not_before.unwrap(), verify_vc.issuance_date);
assert_eq!(registered_claims.expiration.unwrap(), verify_vc.expiration_date.unwrap());
}
// TODO: Add this test after doing this issuer - https://github.com/TBD54566975/web5-rs/issues/202
// #[tokio::test]
// async fn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PHR1f7sb10qEBw";
//
// let jwt_decoded = Jwt::verify::<VcJwtClaims>(&minified_vc_jwt).await.unwrap();
// let registered_claims = jwt_decoded.claims.registered_claims;
//
// let verify_result = VerifiableCredential::verify(minified_vc_jwt).await;
// let verify_vc = verify_result.unwrap();
//
// assert_eq!(registered_claims.jti.unwrap(), verify_vc.id);
// assert_eq!(registered_claims.issuer.unwrap(), verify_vc.issuer.get_id());
// assert_eq!(registered_claims.subject.unwrap(), verify_vc.credential_subject.id);
// assert_eq!(registered_claims.not_before.unwrap(), verify_vc.issuance_date);
// assert_eq!(registered_claims.expiration.unwrap(), verify_vc.expiration_date.unwrap());
// }
}

0 comments on commit f006e38

Please sign in to comment.