From 440ea7ebbecb355ca58b56ad0132e82adb12aacb Mon Sep 17 00:00:00 2001 From: Daniel Armengod Date: Tue, 24 Oct 2023 10:19:55 +0200 Subject: [PATCH] Initial commit, added three sample VC templates and basic code showing how to generate VCs --- README.md | 0 main.py | 33 ++++++++++++++++++ requirements.txt | 2 ++ sample_usage | 27 ++++++++++++++ ssikit_trustchain/__init__.py | 0 .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 188 bytes vc_templates/__init__.py | 0 .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 183 bytes vc_templates/academic.jsonld.j2 | 23 ++++++++++++ vc_templates/affiliation.jsonld.j2 | 17 +++++++++ vc_templates/rescue.jsonld.j2 | 23 ++++++++++++ 11 files changed, 125 insertions(+) create mode 100644 README.md create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 sample_usage create mode 100644 ssikit_trustchain/__init__.py create mode 100644 ssikit_trustchain/__pycache__/__init__.cpython-311.pyc create mode 100644 vc_templates/__init__.py create mode 100644 vc_templates/__pycache__/__init__.cpython-311.pyc create mode 100644 vc_templates/academic.jsonld.j2 create mode 100644 vc_templates/affiliation.jsonld.j2 create mode 100644 vc_templates/rescue.jsonld.j2 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 0000000000000000000000000000000000000000..0cae79f6ad44ae0c2452f0903758788769a7fa00 GIT binary patch literal 188 zcmZ3^%ge<81PPsHsUZ3>h=2h`DC095kTIPhg&~+hlhJP_LlF~@{~09t%U?euKQ~oB zB{45EHAg?7GC3o$C^w)eKPxr4q*%W^F()UrBs;StzNDzMxCAJfnWtY|oQWn9AD@{A rR1>dPQ2C3)CO1E&G$+-rh!to)$OXmxK;i>4BO~Jn1{hJq3={(ZpQkY1 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a8169f74c326a5dcad8d0f12aad0ea6a7b078908 GIT binary patch literal 183 zcmZ3^%ge<81pm{`Q$h4&5CH>>P{wCAAY(d13PUi1CZpd^g?Q2C3)CO1E&G$+-rh!tow$ns)-An}2jk&*EO1B@tQ28say#-}eM literal 0 HcmV?d00001 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}}" + } +}