fix tests

This commit is contained in:
Cayo Puigdefabregas 2024-05-24 22:29:14 +02:00
parent 4bcb0911a7
commit b1d119b9ba
2 changed files with 18 additions and 18 deletions

View File

@ -6,7 +6,7 @@ import nacl.encoding
from did import generate_keys, generate_did, get_signing_key from did import generate_keys, generate_did, get_signing_key
from sign_vc import sign from sign_vc import sign
from sign_vp import sign_vp from sign_vp import sign_vp
from verify_vc import verify_vc from verify import verify_vc
from verify_vp import verify_vp from verify_vp import verify_vp
from utils import now from utils import now
@ -107,7 +107,7 @@ def test_verifiable_credential():
cred = json.dumps(credential) cred = json.dumps(credential)
vc = sign(cred, signing_key, did) vc = sign(cred, signing_key, did)
verified = verify_vc(vc) verified = verify_vc(json.dumps(vc))
assert verified assert verified
@ -136,6 +136,6 @@ def test_verifiable_presentation():
holder_did = generate_did(holder_key) holder_did = generate_did(holder_key)
holder_signing_key = get_signing_key(holder_key) holder_signing_key = get_signing_key(holder_key)
vp = sign_vp(holder_signing_key, holder_did, vc_json) vp = sign_vp(holder_signing_key, holder_did, vc_json)
verified = verify_vp(vp) verified = verify_vc(json.dumps(vp))
assert verified assert verified

View File

@ -9,6 +9,20 @@ def get_presentation(path_presentation):
return vc 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(): def main():
parser=argparse.ArgumentParser(description='Verify a presentation') parser=argparse.ArgumentParser(description='Verify a presentation')
parser.add_argument("presentation_path") parser.add_argument("presentation_path")
@ -16,21 +30,7 @@ def main():
if args.presentation_path: if args.presentation_path:
presentation = get_presentation(args.presentation_path) presentation = get_presentation(args.presentation_path)
presentation_verified = verify_vc(presentation) print(verify_vp(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
if __name__ == "__main__": if __name__ == "__main__":