Skip to content

Commit

Permalink
add rss redact test
Browse files Browse the repository at this point in the history
  • Loading branch information
edchapman88 committed Nov 24, 2023
1 parent 316b0ab commit 79567f7
Showing 1 changed file with 69 additions and 67 deletions.
136 changes: 69 additions & 67 deletions trustchain-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,73 +388,75 @@ mod tests {
assert!(res.is_ok());
}

// #[ignore = "requires a running Sidetree node listening on http://localhost:3000"]
// #[tokio::test]
// async fn test_redact_verify_rss_credential() {
// // **NOT** using init(), because the chain written to a temp dir in init() does not have any
// // RSS keys.
// // init();

// // DID with RSS verification method
// let issuer_did_suffix = "did:ion:test:EiDSE2lEM65nYrEqVvQO5C3scYhkv1KmZzq0S0iZmNKf1Q";
// let resolver = trustchain_resolver("http://localhost:3000/");
// let vc: Credential = serde_json::from_str(UNSIGNED_DRIVERS_LICENCE_VC).unwrap();
// let attestor = IONAttestor::new(issuer_did_suffix);

// let mut signed_vc = attestor
// .sign(
// &vc,
// None,
// Some("Un2E28ffH75_lvA59p7R0wUaGaACzbg8i2H9ksviS34"),
// &resolver,
// &mut ContextLoader::default(),
// )
// .await
// .unwrap();
// // derive redacted RSignature
// let masked_cred_sub: CredentialSubject = serde_json::from_str(
// r###"{
// "id": "did:example:12347abcd",
// "Iso18013DriversLicense": {
// "height": null,
// "weight": null,
// "nationality": null,
// "given_name": null,
// "family_name": null,
// "issuing_country": "US",
// "birth_date": null,
// "age_in_years": 30,
// "age_birth_year": null
// }
// }"###,
// )
// .unwrap();
// let mut masked_copy = signed_vc.clone();
// masked_copy.credential_subject = OneOrMany::One(masked_cred_sub);

// // produce redacted vc from redacted json
// let mut context_loader = ContextLoader::default();
// let verifier = TrustchainVerifier::new(resolver);
// signed_vc
// .rss_redact(
// masked_copy,
// &trustchain_resolver("http://localhost:3000/"),
// &mut context_loader,
// )
// .await
// .unwrap();

// let res = TrustchainAPI::verify_credential(
// &signed_vc,
// None,
// 1697213008,
// &verifier,
// &mut context_loader,
// )
// .await;
// println!("{:?}", &res);
// assert!(res.is_ok());
// }
#[ignore = "requires a running Sidetree node listening on http://localhost:3000"]
#[tokio::test]
async fn test_redact_verify_rss_credential() {
// **NOT** using init(), because the chain written to a temp dir in init() does not have any
// RSS keys.
// init();

// DID with RSS verification method
let issuer_did_suffix = "did:ion:test:EiDSE2lEM65nYrEqVvQO5C3scYhkv1KmZzq0S0iZmNKf1Q";
let resolver = trustchain_resolver("http://localhost:3000/");
let vc: Credential = serde_json::from_str(UNSIGNED_DRIVERS_LICENCE_VC).unwrap();
let attestor = IONAttestor::new(issuer_did_suffix);

let mut signed_vc = attestor
.sign(
&vc,
None,
Some("Un2E28ffH75_lvA59p7R0wUaGaACzbg8i2H9ksviS34"),
&resolver,
&mut ContextLoader::default(),
)
.await
.unwrap();
// println!("{}", serde_json::to_string_pretty(&signed_vc).unwrap());
// derive redacted RSignature
let masked_cred_sub: CredentialSubject = serde_json::from_str(
r###"{
"id": "did:example:12347abcd",
"Iso18013DriversLicense": {
"height": null,
"weight": null,
"nationality": null,
"given_name": null,
"family_name": null,
"issuing_country": "US",
"birth_date": null,
"age_in_years": 30,
"age_birth_year": null
}
}"###,
)
.unwrap();
let mut masked_copy = signed_vc.clone();
masked_copy.credential_subject = OneOrMany::One(masked_cred_sub);

// produce redacted vc from redacted json
let mut context_loader = ContextLoader::default();
let verifier = TrustchainVerifier::new(resolver);
signed_vc
.rss_redact(
masked_copy,
&trustchain_resolver("http://localhost:3000/"),
&mut context_loader,
)
.await
.unwrap();
// println!("{}", serde_json::to_string_pretty(&signed_vc).unwrap());

let res = TrustchainAPI::verify_credential(
&signed_vc,
None,
1697213008,
&verifier,
&mut context_loader,
)
.await;
// println!("{:?}", &res);
assert!(res.is_ok());
}

#[tokio::test]
async fn test_verify_presentation() {
Expand Down

0 comments on commit 79567f7

Please sign in to comment.