refactor sign VCs
This commit is contained in:
parent
e91eaf1652
commit
a9cca75323
9
did.py
9
did.py
|
@ -57,7 +57,7 @@ def generate_keys():
|
||||||
# Generate an Ed25519 key pair
|
# Generate an Ed25519 key pair
|
||||||
key = jwk.JWK.generate(kty='OKP', crv='Ed25519')
|
key = jwk.JWK.generate(kty='OKP', crv='Ed25519')
|
||||||
key['kid'] = 'Generated'
|
key['kid'] = 'Generated'
|
||||||
return key.export()
|
return key.export_private(True)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -67,7 +67,8 @@ def main():
|
||||||
args=parser.parse_args()
|
args=parser.parse_args()
|
||||||
|
|
||||||
if args.new == 'keys':
|
if args.new == 'keys':
|
||||||
print(generate_keys())
|
keyspair = generate_keys()
|
||||||
|
print(json.dumps(keyspair))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not args.key_path and args.new == 'did':
|
if not args.key_path and args.new == 'did':
|
||||||
|
@ -76,8 +77,8 @@ def main():
|
||||||
|
|
||||||
if args.new == 'did':
|
if args.new == 'did':
|
||||||
key = key_read(args.key_path)
|
key = key_read(args.key_path)
|
||||||
keyspair = generate_did(key)
|
did = generate_did(key)
|
||||||
print(json.dumps(keyspair))
|
print(json.dumps(did))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
28
sign_vc.py
28
sign_vc.py
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
|
import argparse
|
||||||
from utils import now
|
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 templates import credential_tmpl, proof_tmpl
|
||||||
from sign import sign_proof
|
from sign import sign_proof
|
||||||
|
|
||||||
|
@ -21,18 +22,25 @@ def sign(credential, key, issuer_did):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
key = generate_keys()
|
parser=argparse.ArgumentParser(description='Generates a new credential')
|
||||||
did = generate_did(key)
|
parser.add_argument("-k", "--key-path", required=True)
|
||||||
signing_key = get_signing_key(key)
|
args=parser.parse_args()
|
||||||
|
|
||||||
credential = credential_tmpl.copy()
|
if args.key_path:
|
||||||
credential["issuer"] = did
|
key = key_read(args.key_path)
|
||||||
credential["issuanceDate"] = now()
|
did = generate_did(key)
|
||||||
cred = json.dumps(credential)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue