commit 440ea7ebbecb355ca58b56ad0132e82adb12aacb Author: Daniel Armengod Date: Tue Oct 24 10:19:55 2023 +0200 Initial commit, added three sample VC templates and basic code showing how to generate VCs diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..8391945 --- /dev/null +++ b/main.py @@ -0,0 +1,33 @@ +import asyncio +import didkit +import json +from jinja2 import Environment, FileSystemLoader, select_autoescape + +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) + + +async def main(): + env = Environment( + loader=FileSystemLoader("vc_templates"), + autoescape=select_autoescape() + ) + unsigned_vc_template = env.get_template("affiliation.jsonld.j2") + 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" + } + unsigned_vc = unsigned_vc_template.render(data) + signed_credential = await didkit.issue_credential( + unsigned_vc, + json.dumps({"proofFormat": "ldp"}), + jwk_issuer) + print(signed_credential) + +asyncio.run(main()) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6979aae --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +jinja2 +didkit diff --git a/sample_usage b/sample_usage new file mode 100644 index 0000000..e0aba04 --- /dev/null +++ b/sample_usage @@ -0,0 +1,27 @@ +(venv) daniel@doloni04:~/PycharmProjects/walletkit_trustchain$ python main.py | jq . +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + { + "title": "trustchain:title", + "member_of": "trustchain:memberof" + } + ], + "id": "http://example.org/credentials/3731", + "type": [ + "VerifiableCredential" + ], + "credentialSubject": { + "id": "did:key:z6MksWDE2Kppe8sH3rAezmzZkQ2ismxD7dqpVvsGGCLYjeau", + "member_of": "Pangea" + }, + "issuer": "did:key:z6MkqZ9Ga2xaSaLRLcdv3oic4dQt5gNmJ6cpKqUGdJN7L7sd", + "issuanceDate": "2020-08-19T21:41:50Z", + "proof": { + "type": "Ed25519Signature2018", + "proofPurpose": "assertionMethod", + "verificationMethod": "did:key:z6MkqZ9Ga2xaSaLRLcdv3oic4dQt5gNmJ6cpKqUGdJN7L7sd#z6MkqZ9Ga2xaSaLRLcdv3oic4dQt5gNmJ6cpKqUGdJN7L7sd", + "created": "2023-10-24T08:14:31.901Z", + "jws": "eyJhbGciOiJFZERTQSIsImNyaXQiOlsiYjY0Il0sImI2NCI6ZmFsc2V9..0nANd5WsyYCu0FDfLil1LpsIdxNgXNu3SI5G-WuTjcwOaPvU-c2AP_JlOBdIFNx5F6iIbynTOzn0IVi9TzocCQ" + } +} diff --git a/ssikit_trustchain/__init__.py b/ssikit_trustchain/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ssikit_trustchain/__pycache__/__init__.cpython-311.pyc b/ssikit_trustchain/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..0cae79f Binary files /dev/null and b/ssikit_trustchain/__pycache__/__init__.cpython-311.pyc differ diff --git a/vc_templates/__init__.py b/vc_templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vc_templates/__pycache__/__init__.cpython-311.pyc b/vc_templates/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..a8169f7 Binary files /dev/null and b/vc_templates/__pycache__/__init__.cpython-311.pyc differ diff --git a/vc_templates/academic.jsonld.j2 b/vc_templates/academic.jsonld.j2 new file mode 100644 index 0000000..8805101 --- /dev/null +++ b/vc_templates/academic.jsonld.j2 @@ -0,0 +1,23 @@ +{ + "@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 new file mode 100644 index 0000000..ca11faa --- /dev/null +++ b/vc_templates/affiliation.jsonld.j2 @@ -0,0 +1,17 @@ +{ + "@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/rescue.jsonld.j2 b/vc_templates/rescue.jsonld.j2 new file mode 100644 index 0000000..5f53cdb --- /dev/null +++ b/vc_templates/rescue.jsonld.j2 @@ -0,0 +1,23 @@ +{ + "@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}}" + } +}