fix flow did

This commit is contained in:
Cayo Puigdefabregas 2024-05-27 11:41:33 +02:00
parent 6054eaa705
commit 84041bf2ed
2 changed files with 11 additions and 8 deletions

6
did.py
View File

@ -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():

View File

@ -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