From 84041bf2ed95a943934cc878768e484814577387 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 27 May 2024 11:41:33 +0200 Subject: [PATCH] fix flow did --- did.py | 6 ++++-- tests/test_certificate.py | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/did.py b/did.py index fc4fb94..c4512a2 100644 --- a/did.py +++ b/did.py @@ -34,7 +34,8 @@ def key_read(path_keys): def get_signing_key(jwk_pr): - private_key_material_str = jwk_pr['d'] + key = json.loads(jwk_pr) + private_key_material_str = key['d'] missing_padding = len(private_key_material_str) % 4 if missing_padding: private_key_material_str += '=' * (4 - missing_padding) @@ -57,7 +58,8 @@ def generate_keys(): # Generate an Ed25519 key pair key = jwk.JWK.generate(kty='OKP', crv='Ed25519') key['kid'] = 'Generated' - return key.export_private(True) + key_json = key.export_private(True) + return json.dumps(key_json) def main(): diff --git a/tests/test_certificate.py b/tests/test_certificate.py index 8e30bed..3d5eac6 100644 --- a/tests/test_certificate.py +++ b/tests/test_certificate.py @@ -13,22 +13,23 @@ from utils import now def test_generated_did_key(): key = generate_keys() + key_d = json.loads(key) did = generate_did(key) _did = did.split("#")[0] pub = _did.split(":")[-1] mc = multiformats.multibase.decode(pub) public_key_bytes = multicodec.remove_prefix(mc) x = nacl.encoding.URLSafeBase64Encoder.encode(public_key_bytes).decode('utf-8') - k_x = key.get('x', '') + k_x = key_d.get('x', '') missing_padding = len(k_x) % 4 if missing_padding: k_x += '=' * (4 - missing_padding) - assert key.get('kty') == 'OKP' - assert key.get('crv') == 'Ed25519' - assert key.get('kid') == 'Generated' + assert key_d.get('kty') == 'OKP' + assert key_d.get('crv') == 'Ed25519' + assert key_d.get('kid') == 'Generated' assert k_x == x - assert key.get('d') is not None + assert key_d.get('d') is not None def test_credential(): @@ -135,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_vc(json.dumps(vp)) + verified = verify_vp(json.dumps(vp)) assert verified