Up-to-date con la ultima version de schemas y contexts
This commit is contained in:
parent
643a9d2949
commit
62375123f4
Binary file not shown.
|
@ -22,6 +22,30 @@ def generate_generic_vc_id():
|
||||||
return "https://pangea.org/credentials/42"
|
return "https://pangea.org/credentials/42"
|
||||||
|
|
||||||
|
|
||||||
|
async def resolve_keydid(keydid):
|
||||||
|
return await didkit.resolve_did(keydid, "{}")
|
||||||
|
|
||||||
|
|
||||||
|
def webdid_from_controller_key(key):
|
||||||
|
"""
|
||||||
|
Se siguen los pasos para generar un webdid a partir de un keydid.
|
||||||
|
Documentado en la docu de spruceid.
|
||||||
|
"""
|
||||||
|
keydid = keydid_from_controller_key(key) # "did:key:<...>"
|
||||||
|
pubkeyid = keydid.rsplit(":")[-1] # <...>
|
||||||
|
document = json.loads(asyncio.run(resolve_keydid(keydid))) # Documento DID en terminos "key"
|
||||||
|
webdid_url = f"did:web:idhub.pangea.org:{pubkeyid}" # nueva URL: "did:web:idhub.pangea.org:<...>"
|
||||||
|
webdid_url_owner = webdid_url + "#owner"
|
||||||
|
# Reemplazamos los campos del documento DID necesarios:
|
||||||
|
document["id"] = webdid_url
|
||||||
|
document["verificationMethod"][0]["id"] = webdid_url_owner
|
||||||
|
document["verificationMethod"][0]["controller"] = webdid_url
|
||||||
|
document["authentication"][0] = webdid_url_owner
|
||||||
|
document["assertionMethod"][0] = webdid_url_owner
|
||||||
|
document_fixed_serialized = json.dumps(document)
|
||||||
|
return webdid_url, document_fixed_serialized
|
||||||
|
|
||||||
|
|
||||||
def render_and_sign_credential(unsigned_vc: dict, jwk_issuer):
|
def render_and_sign_credential(unsigned_vc: dict, jwk_issuer):
|
||||||
"""
|
"""
|
||||||
Populates a VC template with data for issuance, and signs the result with the provided key.
|
Populates a VC template with data for issuance, and signs the result with the provided key.
|
||||||
|
|
41
main.py
41
main.py
|
@ -44,17 +44,21 @@ def deep_filter_dict(f: Callable[[Any], bool], d: dict):
|
||||||
yield key, val
|
yield key, val
|
||||||
|
|
||||||
|
|
||||||
def test_all_vcs():
|
def test_all_vcs(use_webdid=False):
|
||||||
vcs = [
|
vcs = [
|
||||||
'membership-card',
|
'membership-card',
|
||||||
'financial-vulnerability',
|
'financial-vulnerability',
|
||||||
'course-credential',
|
'course-credential',
|
||||||
'federation-membership',
|
'federation-membership',
|
||||||
|
'e-operator-claim'
|
||||||
]
|
]
|
||||||
for vc in vcs:
|
for vc in vcs:
|
||||||
print(f"trying {vc}... ", end="")
|
print(f"trying {vc}... ", end="")
|
||||||
try:
|
try:
|
||||||
signed_cred = issue_vc_test_newstyle(vc)
|
if use_webdid:
|
||||||
|
signed_cred = did_web_issue_vc_test_newstyle(vc)
|
||||||
|
else:
|
||||||
|
signed_cred = issue_vc_test_newstyle(vc)
|
||||||
ok, err = idhub_ssikit.verify_credential(signed_cred)
|
ok, err = idhub_ssikit.verify_credential(signed_cred)
|
||||||
if ok:
|
if ok:
|
||||||
print("OK")
|
print("OK")
|
||||||
|
@ -66,6 +70,28 @@ def test_all_vcs():
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
def issue_vc_test_newstyle(vc_name):
|
||||||
jwk_issuer = didkit.generate_ed25519_key()
|
jwk_issuer = didkit.generate_ed25519_key()
|
||||||
jwk_subject = didkit.generate_ed25519_key()
|
jwk_subject = didkit.generate_ed25519_key()
|
||||||
|
@ -73,11 +99,11 @@ def issue_vc_test_newstyle(vc_name):
|
||||||
did_issuer = didkit.key_to_did("key", jwk_issuer)
|
did_issuer = didkit.key_to_did("key", jwk_issuer)
|
||||||
did_subject = didkit.key_to_did("key", jwk_subject)
|
did_subject = didkit.key_to_did("key", jwk_subject)
|
||||||
|
|
||||||
vc_template = json.load(open(f'vc_templates/{vc_name}.json'))
|
vc_template = json.load(open(f'../../schemas/vc_templates/{vc_name}.json'))
|
||||||
data_base = json.load(open(f'vc_templates/base--data.json'))
|
data_base = json.load(open(f'../../schemas/vc_examples/base--data.json'))
|
||||||
data_base["issuer"]["id"] = did_issuer
|
data_base["issuer"]["id"] = did_issuer
|
||||||
data_base["credentialSubject"]["id"] = did_subject
|
data_base["credentialSubject"]["id"] = did_subject
|
||||||
data_specific = json.load(open(f'vc_templates/{vc_name}--data.json'))
|
data_specific = json.load(open(f'../../schemas/vc_examples/{vc_name}--data.json'))
|
||||||
data = deep_merge_dict(data_base, data_specific)
|
data = deep_merge_dict(data_base, data_specific)
|
||||||
vc_rendered_unsigned = deep_merge_dict(vc_template, data)
|
vc_rendered_unsigned = deep_merge_dict(vc_template, data)
|
||||||
|
|
||||||
|
@ -121,6 +147,7 @@ def issue_and_sign_vp_test():
|
||||||
print(did_issuer2)
|
print(did_issuer2)
|
||||||
print(did_subject)
|
print(did_subject)
|
||||||
|
|
||||||
|
# TODO: WE'RE NO LONGER USING JINJA2
|
||||||
env = Environment(
|
env = Environment(
|
||||||
loader=FileSystemLoader("vc_templates"),
|
loader=FileSystemLoader("vc_templates"),
|
||||||
autoescape=select_autoescape()
|
autoescape=select_autoescape()
|
||||||
|
@ -153,3 +180,7 @@ def issue_and_sign_vp_test():
|
||||||
res = idhub_ssikit.verify_presentation(signed_presentation)
|
res = idhub_ssikit.verify_presentation(signed_presentation)
|
||||||
print(res)
|
print(res)
|
||||||
|
|
||||||
|
|
||||||
|
def scratch():
|
||||||
|
jwk_issuer = didkit.generate_ed25519_key()
|
||||||
|
did_issuer = didkit.key_to_did("key", jwk_issuer)
|
Reference in New Issue