From b1d119b9ba36208df1b3a4a8ee235d54cdea5203 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 24 May 2024 22:29:14 +0200 Subject: [PATCH] fix tests --- tests/test_certificate.py | 6 +++--- verify_vp.py | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_certificate.py b/tests/test_certificate.py index 99491de..334ca9d 100644 --- a/tests/test_certificate.py +++ b/tests/test_certificate.py @@ -6,7 +6,7 @@ import nacl.encoding from did import generate_keys, generate_did, get_signing_key from sign_vc import sign from sign_vp import sign_vp -from verify_vc import verify_vc +from verify import verify_vc from verify_vp import verify_vp from utils import now @@ -107,7 +107,7 @@ def test_verifiable_credential(): cred = json.dumps(credential) vc = sign(cred, signing_key, did) - verified = verify_vc(vc) + verified = verify_vc(json.dumps(vc)) assert verified @@ -136,6 +136,6 @@ def test_verifiable_presentation(): holder_did = generate_did(holder_key) holder_signing_key = get_signing_key(holder_key) vp = sign_vp(holder_signing_key, holder_did, vc_json) - verified = verify_vp(vp) + verified = verify_vc(json.dumps(vp)) assert verified diff --git a/verify_vp.py b/verify_vp.py index 394a218..ab2011f 100644 --- a/verify_vp.py +++ b/verify_vp.py @@ -9,6 +9,20 @@ def get_presentation(path_presentation): return vc +def verify_vp(presentation): + vp = json.loads(presentation) + + if not verify_vc(presentation): + return False + + for vc in vp['verifiableCredential']: + vc_str = json.dumps(vc) + if not verify_vc(vc_str): + return False + + return True + + def main(): parser=argparse.ArgumentParser(description='Verify a presentation') parser.add_argument("presentation_path") @@ -16,21 +30,7 @@ def main(): if args.presentation_path: presentation = get_presentation(args.presentation_path) - presentation_verified = verify_vc(presentation) - if not presentation_verified: - print(presentation_verified) - return - - vp = json.loads(presentation) - for vc in vp['verifiableCredential']: - vc_str = json.dumps(vc) - verified = verify_vc(vc_str) - if not verified: - print(verified) - return - - print(True) - return + print(verify_vp(presentation)) if __name__ == "__main__":