Initial commit, added three sample VC templates and basic code showing how to generate VCs
This commit is contained in:
commit
440ea7ebbe
|
@ -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())
|
|
@ -0,0 +1,2 @@
|
|||
jinja2
|
||||
didkit
|
|
@ -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"
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -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 }}"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 }}"
|
||||
}
|
||||
}
|
|
@ -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}}"
|
||||
}
|
||||
}
|
Reference in New Issue