From 79567f77d63fd480903907753e99f7fa07c1e6a2 Mon Sep 17 00:00:00 2001 From: Ed Chapman - Turing Date: Fri, 24 Nov 2023 17:14:08 +0000 Subject: [PATCH] add rss redact test --- trustchain-api/src/api.rs | 136 +++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 67 deletions(-) diff --git a/trustchain-api/src/api.rs b/trustchain-api/src/api.rs index efc3388a..8adcb79e 100644 --- a/trustchain-api/src/api.rs +++ b/trustchain-api/src/api.rs @@ -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() {