From a9cca753233117015af1dcbcb08b9ffc39164669 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 24 May 2024 17:22:35 +0200 Subject: [PATCH] refactor sign VCs --- did.py | 9 +++++---- sign_vc.py | 28 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/did.py b/did.py index 9e7a647..fc4fb94 100644 --- a/did.py +++ b/did.py @@ -57,7 +57,7 @@ def generate_keys(): # Generate an Ed25519 key pair key = jwk.JWK.generate(kty='OKP', crv='Ed25519') key['kid'] = 'Generated' - return key.export() + return key.export_private(True) def main(): @@ -67,7 +67,8 @@ def main(): args=parser.parse_args() if args.new == 'keys': - print(generate_keys()) + keyspair = generate_keys() + print(json.dumps(keyspair)) return if not args.key_path and args.new == 'did': @@ -76,8 +77,8 @@ def main(): if args.new == 'did': key = key_read(args.key_path) - keyspair = generate_did(key) - print(json.dumps(keyspair)) + did = generate_did(key) + print(json.dumps(did)) return diff --git a/sign_vc.py b/sign_vc.py index 9ac79b2..1ff9cb2 100644 --- a/sign_vc.py +++ b/sign_vc.py @@ -1,6 +1,7 @@ import json +import argparse from utils import now -from did import generate_keys, generate_did, get_signing_key +from did import generate_did, get_signing_key, key_read from templates import credential_tmpl, proof_tmpl from sign import sign_proof @@ -21,18 +22,25 @@ def sign(credential, key, issuer_did): def main(): - key = generate_keys() - did = generate_did(key) - signing_key = get_signing_key(key) + parser=argparse.ArgumentParser(description='Generates a new credential') + parser.add_argument("-k", "--key-path", required=True) + args=parser.parse_args() - credential = credential_tmpl.copy() - credential["issuer"] = did - credential["issuanceDate"] = now() - cred = json.dumps(credential) + if args.key_path: + key = key_read(args.key_path) + did = generate_did(key) + signing_key = get_signing_key(key) - vc = sign(cred, signing_key, did) + credential = credential_tmpl.copy() + credential["issuer"] = did + credential["issuanceDate"] = now() + cred = json.dumps(credential) - print(json.dumps(vc, separators=(',', ':'))) + vc = sign(cred, signing_key, did) + + print(json.dumps(vc, separators=(',', ':'))) + + return if __name__ == "__main__":