Cleaned up VC issuance example code and verified it works
This commit is contained in:
parent
9d487bce0f
commit
594c1854a5
Binary file not shown.
|
@ -76,6 +76,7 @@ def render_and_sign_credential(unsigned_vc: dict, jwk_issuer):
|
|||
|
||||
# if vc_data.get("issuance_date") is None:
|
||||
# vc_data["issuance_date"] = datetime.datetime.now().replace(microsecond=0).isoformat()
|
||||
#print(json.dumps(unsigned_vc))
|
||||
|
||||
return asyncio.run(inner())
|
||||
|
||||
|
|
74
main.py
74
main.py
|
@ -55,10 +55,7 @@ def test_all_vcs(use_webdid=False):
|
|||
for vc in vcs:
|
||||
print(f"trying {vc}... ", end="")
|
||||
try:
|
||||
if use_webdid:
|
||||
signed_cred = did_web_issue_vc_test_newstyle(vc)
|
||||
else:
|
||||
signed_cred = issue_vc_test_newstyle(vc)
|
||||
signed_cred = issue_vc_test_newstyle(vc, use_webdid)
|
||||
ok, err = idhub_ssikit.verify_credential(signed_cred)
|
||||
if ok:
|
||||
print("OK")
|
||||
|
@ -70,19 +67,25 @@ def test_all_vcs(use_webdid=False):
|
|||
print(e)
|
||||
|
||||
|
||||
def did_web_issue_vc_and_check_revocation(vc_name, revoked=True):
|
||||
def issue_vc_test_newstyle(vc_name, use_web=True, did_revokes_vc=False, check_revocation=False):
|
||||
jwk_issuer = '{"kty":"OKP","crv":"Ed25519","x":"piojLFIHQ4Z6heRuPI87nrfMJKdet1dJIPG15iGjmDE","d":"zpOBTDrp_iNQTY5nZlIxLA34Sl7FXWXNGehFktznxTM"}'
|
||||
jwk_subject = '{"kty":"OKP","crv":"Ed25519","x":"BuKyt44QKYSX6kmAt771ai37lIFNwYlhugWXPiqcyYU","d":"qbvMhSCPKvQ-vSkqNr3q8gWY5zPUj7ry0t2YnmT7agc"}'
|
||||
|
||||
did_issuer = "did:web:idhub.pangea.org:did-registry:allRevoked" if revoked else "did:web:idhub.pangea.org:did-registry:noneRevoked"
|
||||
did_subject = didkit.key_to_did("key", jwk_subject)
|
||||
|
||||
if use_web:
|
||||
if did_revokes_vc:
|
||||
did_issuer = "did:web:idhub.pangea.org:did-registry:allRevoked"
|
||||
else:
|
||||
did_issuer = "did:web:idhub.pangea.org:did-registry:noneRevoked"
|
||||
else:
|
||||
did_issuer = didkit.key_to_did("key", jwk_issuer)
|
||||
vc_template = json.load(open(f'schemas/vc_templates/{vc_name}.json'))
|
||||
data_base = json.load(open(f'schemas/vc_examples/base--data.json'))
|
||||
data_base["issuer"]["id"] = did_issuer
|
||||
data_base["credentialSubject"]["id"] = did_subject
|
||||
data_specific = json.load(open(f'schemas/vc_examples/{vc_name}--data.json'))
|
||||
data = deep_merge_dict(data_base, data_specific)
|
||||
data["issuer"]["id"] = did_issuer
|
||||
data["credentialSubject"]["id"] = did_subject
|
||||
data["credentialStatus"]["id"] = did_issuer
|
||||
data["credentialStatus"]["revocationBitmapIndex"] = "420"
|
||||
vc_rendered_unsigned = deep_merge_dict(vc_template, data)
|
||||
|
||||
signed_credential = idhub_ssikit.render_and_sign_credential(
|
||||
|
@ -90,52 +93,11 @@ def did_web_issue_vc_and_check_revocation(vc_name, revoked=True):
|
|||
jwk_issuer,
|
||||
)
|
||||
|
||||
ok, reason = idhub_ssikit.verify_credential(signed_credential)
|
||||
print(ok)
|
||||
print(reason)
|
||||
|
||||
|
||||
def did_web_issue_vc_test_newstyle(vc_name):
|
||||
jwk_issuer = '{"kty":"OKP","crv":"Ed25519","x":"piojLFIHQ4Z6heRuPI87nrfMJKdet1dJIPG15iGjmDE","d":"zpOBTDrp_iNQTY5nZlIxLA34Sl7FXWXNGehFktznxTM"}'
|
||||
jwk_subject = '{"kty":"OKP","crv":"Ed25519","x":"BuKyt44QKYSX6kmAt771ai37lIFNwYlhugWXPiqcyYU","d":"qbvMhSCPKvQ-vSkqNr3q8gWY5zPUj7ry0t2YnmT7agc"}'
|
||||
|
||||
did_issuer = "did:web:idhub.pangea.org"
|
||||
did_subject = didkit.key_to_did("key", jwk_subject)
|
||||
|
||||
vc_template = json.load(open(f'schemas/vc_templates/{vc_name}.json'))
|
||||
data_base = json.load(open(f'schemas/vc_examples/base--data.json'))
|
||||
data_base["issuer"]["id"] = did_issuer
|
||||
data_base["credentialSubject"]["id"] = did_subject
|
||||
data_specific = json.load(open(f'schemas/vc_examples/{vc_name}--data.json'))
|
||||
data = deep_merge_dict(data_base, data_specific)
|
||||
vc_rendered_unsigned = deep_merge_dict(vc_template, data)
|
||||
|
||||
signed_credential = idhub_ssikit.render_and_sign_credential(
|
||||
vc_rendered_unsigned,
|
||||
jwk_issuer,
|
||||
)
|
||||
return signed_credential
|
||||
|
||||
|
||||
def issue_vc_test_newstyle(vc_name):
|
||||
jwk_issuer = didkit.generate_ed25519_key()
|
||||
jwk_subject = didkit.generate_ed25519_key()
|
||||
|
||||
did_issuer = didkit.key_to_did("key", jwk_issuer)
|
||||
did_subject = didkit.key_to_did("key", jwk_subject)
|
||||
|
||||
vc_template = json.load(open(f'schemas/vc_templates/{vc_name}.json'))
|
||||
data_base = json.load(open(f'schemas/vc_examples/base--data.json'))
|
||||
data_base["issuer"]["id"] = did_issuer
|
||||
data_base["credentialSubject"]["id"] = did_subject
|
||||
data_specific = json.load(open(f'schemas/vc_examples/{vc_name}--data.json'))
|
||||
data = deep_merge_dict(data_base, data_specific)
|
||||
vc_rendered_unsigned = deep_merge_dict(vc_template, data)
|
||||
|
||||
signed_credential = idhub_ssikit.render_and_sign_credential(
|
||||
vc_rendered_unsigned,
|
||||
jwk_issuer,
|
||||
)
|
||||
if check_revocation:
|
||||
assert use_web is True
|
||||
ok, reason = idhub_ssikit.verify_credential(signed_credential)
|
||||
print(ok)
|
||||
print(reason)
|
||||
return signed_credential
|
||||
|
||||
|
||||
|
|
2
schemas
2
schemas
|
@ -1 +1 @@
|
|||
Subproject commit e033da1e8a79f3eae4063b1a8c33e8d503d76f3e
|
||||
Subproject commit f1e6a33d0801a2104bf297292b953b1d138f675b
|
Reference in a new issue