refactor sign VCs

This commit is contained in:
Cayo Puigdefabregas 2024-05-24 17:22:35 +02:00
parent e91eaf1652
commit a9cca75323
2 changed files with 23 additions and 14 deletions

9
did.py
View File

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

View File

@ -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__":