diff --git a/idhub_ssikit/__init__.py b/idhub_ssikit/__init__.py index f8e03b6..2d2ef27 100644 --- a/idhub_ssikit/__init__.py +++ b/idhub_ssikit/__init__.py @@ -3,6 +3,8 @@ import datetime import didkit import json import jinja2 +from jinja2 import Environment, FileSystemLoader, select_autoescape + def generate_did_controller_key(): @@ -56,3 +58,28 @@ def verify_credential(vc, proof_options): return didkit.verify_credential(vc, proof_options) return asyncio.run(inner()) + + +def issue_verifiable_presentation(vc_list: list[str], jwk_holder: str, holder_did: str) -> str: + async def inner(): + unsigned_vp = unsigned_vp_template.render(data) + signed_vp = await didkit.issue_presentation( + unsigned_vp, + '{"proofFormat": "ldp"}', + jwk_holder + ) + return signed_vp + + env = Environment( + loader=FileSystemLoader("vc_templates"), + autoescape=select_autoescape() + ) + unsigned_vp_template = env.get_template("verifiable_presentation.json") + data = { + "holder_did": holder_did, + "verifiable_credential_list": "[" + ",".join(vc_list) + "]" + } + + return asyncio.run(inner()) + + diff --git a/idhub_ssikit/__pycache__/__init__.cpython-311.pyc b/idhub_ssikit/__pycache__/__init__.cpython-311.pyc index 04f3376..ef2f1d4 100644 Binary files a/idhub_ssikit/__pycache__/__init__.cpython-311.pyc and b/idhub_ssikit/__pycache__/__init__.cpython-311.pyc differ diff --git a/main.py b/main.py index ace19f8..3ef540e 100644 --- a/main.py +++ b/main.py @@ -4,29 +4,71 @@ import json from jinja2 import Environment, FileSystemLoader, select_autoescape import idhub_ssikit -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) +def issue_vc_test(): + 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) + + env = Environment( + loader=FileSystemLoader("vc_templates"), + autoescape=select_autoescape() + ) + unsigned_vc_template = env.get_template("member.json") + data = { + "vc_id": "http://example.org/credentials/3731", + "issuer_did": did_issuer, + "subject_did": did_subject, + "issuance_date": "2020-08-19T21:41:50Z", + + } + signed_credential = idhub_ssikit.render_and_sign_credential( + unsigned_vc_template, + jwk_issuer, + data + ) + + print(signed_credential) -env = Environment( - loader=FileSystemLoader("vc_templates"), - autoescape=select_autoescape() -) -unsigned_vc_template = env.get_template("member-credential.json") -data = { - "vc_id": "http://example.org/credentials/3731", - "issuer_did": did_issuer, - "subject_did": did_subject, - "issuance_date": "2020-08-19T21:41:50Z", - "subject_is_member_of": "Pangea" -} -signed_credential = idhub_ssikit.render_and_sign_credential( - unsigned_vc_template, - jwk_issuer, - data -) +def issue_vp_test(): + jwk_issuer = didkit.generate_ed25519_key() + jwk_issuer2 = didkit.generate_ed25519_key() + jwk_subject = didkit.generate_ed25519_key() -print(signed_credential) + did_issuer = didkit.key_to_did("key", jwk_issuer) + did_issuer2 = didkit.key_to_did("key", jwk_issuer2) + did_subject = didkit.key_to_did("key", jwk_subject) + print(did_issuer) + print(did_issuer2) + print(did_subject) + + env = Environment( + loader=FileSystemLoader("vc_templates"), + autoescape=select_autoescape() + ) + unsigned_vc_template = env.get_template("member.json") + data = { + "vc_id": "http://example.org/credentials/3731", + "issuer_did": did_issuer, + "subject_did": did_subject, + "issuance_date": "2020-08-19T21:41:50Z", + "subject_is_member_of": "Pangea" + } + signed_credential = idhub_ssikit.render_and_sign_credential( + unsigned_vc_template, + jwk_issuer, + data + ) + data2 = data + data2["issuer_did"] = did_issuer2 + signed_credential2 = idhub_ssikit.render_and_sign_credential( + unsigned_vc_template, + jwk_issuer2, + data2 + ) + + signed_presentation = idhub_ssikit.issue_verifiable_presentation([signed_credential, signed_credential2], jwk_subject, did_subject) + print(signed_presentation) diff --git a/vc_templates/academic.jsonld.j2 b/vc_templates/academic.jsonld.j2 deleted file mode 100644 index 1489d49..0000000 --- a/vc_templates/academic.jsonld.j2 +++ /dev/null @@ -1,23 +0,0 @@ -{ - "@context": [ - "https://www.w3.org/2018/credentials/v1", - { - "title" : "trustchain:title", - "name": "trustchain:name", - "grade": "trustchain:grade", - "date_earned": "trustchain:dateearned" - } - ], - "id": "{{ vc_id }}", - "type": ["VerifiableCredential"], - "issuer": "{{ issuer_did }}", - "issuanceDate": "{{ issuance_date }}", - "credentialSubject": { - "id": "{{ subject_did }}", - "title": { - "name": "{{ degree_name }}", - "grade": "{{ degree_grade_obtained }}", - "date_earned": "{{ date_earned }}" - } - } -} diff --git a/vc_templates/affiliation.jsonld.j2 b/vc_templates/affiliation.jsonld.j2 deleted file mode 100644 index ca11faa..0000000 --- a/vc_templates/affiliation.jsonld.j2 +++ /dev/null @@ -1,17 +0,0 @@ -{ - "@context": [ - "https://www.w3.org/2018/credentials/v1", - { - "title" : "trustchain:title", - "member_of": "trustchain:memberof" - } - ], - "id": "{{ vc_id }}", - "type": ["VerifiableCredential"], - "issuer": "{{ issuer_did }}", - "issuanceDate": "{{ issuance_date }}", - "credentialSubject": { - "id": "{{ subject_did }}", - "member_of": "{{ subject_is_member_of }}" - } -} diff --git a/vc_templates/exo.json b/vc_templates/exo.json new file mode 100644 index 0000000..1aee10b --- /dev/null +++ b/vc_templates/exo.json @@ -0,0 +1,30 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + { + "name": "https://schema.org/name", + "email": "https://schema.org/email", + "membershipType": "https://schema.org/memberOf", + "individual": "https://schema.org/Person", + "organization": "https://schema.org/Organization", + "Member": "https://schema.org/Member", + "startDate": "https://schema.org/startDate", + "jsonSchema": "https://schema.org/jsonSchema", + "street_address": "https://schema.org/streetAddress", + "connectivity_option_list": "https://schema.org/connectivityOptionList", + "$ref": "https://schema.org/jsonSchemaRef" + } + ], + "id": "{{ vc_id }}", + "type": ["VerifiableCredential", "HomeConnectivitySurveyCredential"], + "issuer": "{{ issuer_did }}", + "issuanceDate": "{{ issuance_date }}", + "credentialSubject": { + "id": "{{ subject_did }}", + "street_address": "{{ street_address }}", + "connectivity_option_list": "{{ connectivity_option_list }}", + "jsonSchema": { + "$ref": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/UNDEF.json" + } + } +} diff --git a/vc_templates/member-credential.json b/vc_templates/member.json similarity index 100% rename from vc_templates/member-credential.json rename to vc_templates/member.json diff --git a/vc_templates/openarms.json b/vc_templates/openarms.json new file mode 100644 index 0000000..e2ecbc6 --- /dev/null +++ b/vc_templates/openarms.json @@ -0,0 +1,33 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + { + "name": "https://schema.org/name", + "email": "https://schema.org/email", + "membershipType": "https://schema.org/memberOf", + "individual": "https://schema.org/Person", + "organization": "https://schema.org/Organization", + "Member": "https://schema.org/Member", + "startDate": "https://schema.org/startDate", + "jsonSchema": "https://schema.org/jsonSchema", + "destination_country": "https://schema.org/destinationCountry", + "offboarding_date": "https://schema.org/offboardingDate", + "$ref": "https://schema.org/jsonSchemaRef" + } + ], + "id": "{{ vc_id }}", + "type": ["VerifiableCredential", "MigrantRescueCredential"], + "issuer": "{{ issuer_did }}", + "issuanceDate": "{{ issuance_date }}", + "credentialSubject": { + "id": "{{ subject_did }}", + "name": "{{ name }}", + "country_of_origin": "{{ country_of_origin }}", + "rescue_date": "{{ rescue_date }}", + "destination_country": "{{ destination_country }}", + "offboarding_date": "{{ offboarding_date }}", + "jsonSchema": { + "$ref": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/UNDEF.json" + } + } +} diff --git a/vc_templates/paremanel.json b/vc_templates/paremanel.json new file mode 100644 index 0000000..a40396b --- /dev/null +++ b/vc_templates/paremanel.json @@ -0,0 +1,30 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + { + "name": "https://schema.org/name", + "email": "https://schema.org/email", + "membershipType": "https://schema.org/memberOf", + "individual": "https://schema.org/Person", + "organization": "https://schema.org/Organization", + "Member": "https://schema.org/Member", + "startDate": "https://schema.org/startDate", + "jsonSchema": "https://schema.org/jsonSchema", + "street_address": "https://schema.org/streetAddress", + "financial_vulnerability_score": "https://schema.org/financialVulnerabilityScore", + "$ref": "https://schema.org/jsonSchemaRef" + } + ], + "id": "{{ vc_id }}", + "type": ["VerifiableCredential", "FinancialSituationCredential"], + "issuer": "{{ issuer_did }}", + "issuanceDate": "{{ issuance_date }}", + "credentialSubject": { + "id": "{{ subject_did }}", + "street_address": "{{ street_address }}", + "financial_vulnerability_score": "{{ financial_vulnerability_score }}", + "jsonSchema": { + "$ref": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/UNDEF.json" + } + } +} diff --git a/vc_templates/rescue.jsonld.j2 b/vc_templates/rescue.jsonld.j2 deleted file mode 100644 index 5f53cdb..0000000 --- a/vc_templates/rescue.jsonld.j2 +++ /dev/null @@ -1,23 +0,0 @@ -{ - "@context": [ - "https://www.w3.org/2018/credentials/v1", - { - "title" : "trustchain:title", - "first_name": "trustchain:firstname", - "last_name": "trustchain:lastname", - "coutry_of_origin": "trustchain:countryoforigin", - "rescue_date": "trustchain:rescuedate", - } - ], - "id": "{{ vc_id }}", - "type": ["VerifiableCredential"], - "issuer": "{{ issuer_did }}", - "issuanceDate": "{{ issuance_date }}", - "credentialSubject": { - "id": "{{ subject_did }}", - "first_name": "{{ first_name }}", - "last_name": "{{ last_name }}", - "country_of_origin": "{{ country_of_origin }}", - "rescue_date": "{{ rescue_date}}" - } -} diff --git a/vc_templates/verifiable_presentation.json b/vc_templates/verifiable_presentation.json new file mode 100644 index 0000000..752affb --- /dev/null +++ b/vc_templates/verifiable_presentation.json @@ -0,0 +1,11 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1" + ], + "id": "http://example.org/presentations/3731", + "type": [ + "VerifiablePresentation" + ], + "holder": "{{ holder_did }}", + "verifiableCredential": {{ verifiable_credential_list }} +} diff --git a/vc_templates/wikipedia.jsonld.j2 b/vc_templates/wikipedia.jsonld.j2 deleted file mode 100644 index 398a290..0000000 --- a/vc_templates/wikipedia.jsonld.j2 +++ /dev/null @@ -1,23 +0,0 @@ -{ - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://www.w3.org/2018/credentials/examples/v1" - ], - "id": "0892f680-6aeb-11eb-9bcf-f10d8993fde7", - "type": [ - "VerifiableCredential", - "UniversityDegreeCredential" - ], - "issuer": { - "id": "{{ issuer_did }}", - "name": "Acme University" - }, - "issuanceDate": "2021-05-11T23:09:06.803Z", - "credentialSubject": { - "id": "did:example:ebfeb1f712ebc6f1c276e12ec21", - "degree": { - "type": "BachelorDegree", - "name": "Bachelor of Science" - } - } -} \ No newline at end of file