Añadido el paquete didkit compilado con nuestros cambios y desduplicado los tipos de credencial.

This commit is contained in:
Daniel Armengod 2023-12-12 16:57:37 +01:00
parent d28f013141
commit 451ee9d76a
10 changed files with 189 additions and 243 deletions

View File

@ -2,40 +2,9 @@
This module is a wrapper around the functions exported by SpruceID's `DIDKit` framework. This module is a wrapper around the functions exported by SpruceID's `DIDKit` framework.
## DID generation and storage
For now DIDs are of the kind `did:key`, with planned support for `did:web` in the near future.
Creation of a DID involves two steps:
* Generate a unique DID controller key
* Derive a `did:key` type from the key
Both must be stored in the IdHub database and linked to a `User` for later retrieval.
```python
# Use case: generate and link a new DID for an existing user
user = request.user # ...
controller_key = idhub_ssikit.generate_did_controller_key()
did_string = idhub_ssikit.keydid_from_controller_key(controller_key)
did = idhub.models.DID(
did = did_string,
user = user
)
did_controller_key = idhub.models.DIDControllerKey(
key_material = controller_key,
owner_did = did
)
did.save()
did_controller_key.save()
```
## Verifiable Credential issuance ## Verifiable Credential issuance
Verifiable Credential templates are stored as Jinja2 (TBD) templates in `/schemas` folder. Please examine each template to see what data must be passed to it in order to render. Verifiable Credential templates are stored as Jinja2 (TBD) templates in `/vc_templates` folder. Please examine each template to see what data must be passed to it in order to render.
The data passed to the template must at a minimum include: The data passed to the template must at a minimum include:
* issuer_did * issuer_did
@ -55,12 +24,15 @@ env = Environment(
unsigned_vc_template = env.get_template("member-credential.json") unsigned_vc_template = env.get_template("member-credential.json")
issuer_user = request.user issuer_user = request.user
issuer_did = user.dids[0] # TODO: Django ORM pseudocode jwk_issuer = didkit.generate_ed25519_key()
issuer_did_controller_key = did.keys[0] # TODO: Django ORM pseudocode jwk_subject = didkit.generate_ed25519_key()
did_issuer = didkit.key_to_did("key", jwk_issuer)
did_subject = didkit.key_to_did("key", jwk_subject)
data = { data = {
"vc_id": "http://pangea.org/credentials/3731", "vc_id": "http://pangea.org/credentials/3731",
"issuer_did": issuer_did, "issuer_did": did_issuer,
"subject_did": "did:web:[...]", "subject_did": "did:web:[...]",
"issuance_date": "2020-08-19T21:41:50Z", "issuance_date": "2020-08-19T21:41:50Z",
"subject_is_member_of": "Pangea" "subject_is_member_of": "Pangea"

Binary file not shown.

14
main.py
View File

@ -16,15 +16,11 @@ def issue_vc_test(vc_name):
loader=FileSystemLoader("vc_templates"), loader=FileSystemLoader("vc_templates"),
autoescape=select_autoescape() autoescape=select_autoescape()
) )
unsigned_vc_template = env.get_template(vc_name) unsigned_vc_template = env.get_template(f"{vc_name}.json")
data = { data_raw = open(f"vc_templates/{vc_name}--data.py").read()
"vc_id": "http://trustchain.pangea.org/credentials/42069", data = eval(data_raw)
"issuer_did": did_issuer, data["issuerDid"] = did_issuer
"issuance_date": "2020-08-19T21:41:50Z", data["subjectDid"] = did_subject
"validUntil": "2020-08-19T21:41:50Z",
"subject_did": did_subject,
"membershipType": "lareputa"
}
signed_credential = idhub_ssikit.render_and_sign_credential( signed_credential = idhub_ssikit.render_and_sign_credential(
unsigned_vc_template, unsigned_vc_template,
jwk_issuer, jwk_issuer,

View File

@ -1,2 +1,2 @@
jinja2 jinja2
didkit ./didkit-0.3.2-cp311-cp311-manylinux_2_34_x86_64.whl

View File

@ -0,0 +1,22 @@
{
"vcId": "https://idhub.pangea.org/credentials/987654321",
"issuerDid": "did:example:5678",
"issuerName": "Fundació Pare Manel",
"issuanceDate": "2023-12-06T19:23:24Z",
"validUntil": "2024-12-06T19:23:24Z",
"subjectDid": "did:example:1234",
"firstName": "Joan",
"lastName": "Pera",
"email": "joan.pera@pangea.org",
"phoneNumber": "1234567890",
"identityDocType": "DNI",
"identityNumber": "12345678A",
"streetAddress": "Tallers 19 2-1 Barcelona",
"socialWorkerName": "Mireia",
"socialWorkerSurname": "Pujol",
"financialVulnerabilityScore": "5",
"amountCoveredByOtherAids": "20",
"connectivityOptionList": "fibre, mobile",
"assessmentDate": "2023-12-06"
}

View File

@ -1,101 +0,0 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
{
"credentialSchema": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"value": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"lang": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"description": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"name": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#name",
"surname": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"email": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#email",
"phoneNumber": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#phoneNumber",
"identityDocType": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#identityDocType",
"identityNumber": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#identityNumber",
"streetAddress": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#streetAddress",
"socialWorkerName": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#socialWorkerName",
"socialWorkerSurname": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#socialWorkerSurname",
"financialVulnerabilityScore": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#financialVulnerabilityScore",
"amountCoveredByOtherAids": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#amountCoveredByOtherAids",
"connectivityOptionList": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#connectivityOptionList",
"assessmentDate": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#assessmentDate"
}
],
"id": "{{ vc_id }}",
"type": [
"VerifiableCredential",
"VerifiableAttestation",
"FinancialVulnerabilityCredential"
],
"issuer": {
"id": "{{ issuer_did }}",
"name": "Fundació Pare Manel",
"description": [
{
"value": "The Pare Manel Foundation is a non-profit institution which develops and leads social and educational action projects.",
"lang": "en"
},
{
"value": "La Fundació Pare Manel és una institució sense ànim de lucre que desenvolupa i lidera projectes d'acció social i educativa.",
"lang": "ca_ES"
},
{
"value": "La Fundación Pare Manel es una institución sin ánimo de lucro que desarrolla y lidera proyectos de acción social y educativa.",
"lang": "es"
}
]
},
"issuanceDate": "{{ issuance_date }}",
"validFrom": "{{ issuance_date }}",
"validUntil": "{{ validUntil }}",
"name": [
{
"value": "Financial Vulnerability Credential",
"lang": "en"
},
{
"value": "Credencial de Vulnerabilitat Financera",
"lang": "ca_ES"
},
{
"value": "Credencial de Vulnerabilidad Financiera",
"lang": "es"
}
],
"description": [
{
"value": "The Financial Vulnerability Credential is issued to individuals or families to prove their financial vulnerability based on various factors, with the objective of presenting it to a third party to receive benefits or services.",
"lang": "en"
},
{
"value": "La Credencial de Vulnerabilitat Financera és emesa a persones o famílies per acreditar la seva vulnerabilitat financera sobre la base de diversos factors, amb l'objectiu que la presentin a una tercera part per rebre beneficis o serveis.",
"lang": "ca_ES"
},
{
"value": "La Credencial de Vulnerabilidad Financiera es emitida a personas o familias para acreditar su vulnerabilidad financiera con base en diversos factores, con el objetivo de que la presenten a una tercera parte para recibir beneficios o servicios.",
"lang": "es"
}
],
"credentialSubject": {
"id": "{{ subject_did }}",
"name": "{{ first_name }}",
"surname": "{{ last_name }}",
"email": "{{ email }}",
"phoneNumber": "{{ phone_number }}",
"identityDocType": "{{ identity_doc_type }}",
"identityNumber": "{{ identity_number }}",
"streetAddress": "{{ street_address }}",
"socialWorkerName": "{{ social_worker_name }}",
"socialWorkerSurname": "{{ social_worker_surname }}",
"financialVulnerabilityScore": "{{ financial_vulnerability_score }}",
"amountCoveredByOtherAids": "{{ amount_covered_by_other_aid }}",
"connectivityOptionList": "{{ connectivity_option_list }}",
"assessmentDate": "{{ assessmentDate }}"
},
"credentialSchema": {
"id": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/vc_schemas/financial_vulnerability.json",
"type": "JsonSchema"
}
}

View File

@ -0,0 +1,68 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://idhub.pangea.org/credentials/base/v1",
"https://idhub.pangea.org/credentials/financial-vulnerability/v1"
],
"id": "{{ vcId }}",
"type": [
"VerifiableCredential",
"VerifiableAttestation",
"FinancialVulnerabilityCredential"
],
"issuer": {
"id": "{{ issuerDid }}",
"name": "{{ issuerName }}"
},
"issuanceDate": "{{ issuanceDate }}",
"validFrom": "{{ issuanceDate }}",
"validUntil": "{{ validUntil }}",
"name": [
{
"value": "Financial Vulnerability Credential",
"lang": "en"
},
{
"value": "Credencial de Vulnerabilitat Financera",
"lang": "ca_ES"
},
{
"value": "Credencial de Vulnerabilidad Financiera",
"lang": "es"
}
],
"description": [
{
"value": "The Financial Vulnerability Credential is issued to individuals or families to prove their financial vulnerability based on various factors, with the objective of presenting it to a third party to receive benefits or services.",
"lang": "en"
},
{
"value": "La Credencial de Vulnerabilitat Financera és emesa a persones o famílies per acreditar la seva vulnerabilitat financera sobre la base de diversos factors, amb l'objectiu que la presentin a una tercera part per rebre beneficis o serveis.",
"lang": "ca_ES"
},
{
"value": "La Credencial de Vulnerabilidad Financiera es emitida a personas o familias para acreditar su vulnerabilidad financiera con base en diversos factores, con el objetivo de que la presenten a una tercera parte para recibir beneficios o servicios.",
"lang": "es"
}
],
"credentialSubject": {
"id": "{{ subjectDid }}",
"firstName": "{{ firstName }}",
"lastName": "{{ lastName }}",
"email": "{{ email }}",
"identityDocType": "{{ identityDocType }}",
"identityNumber": "{{ identityNumber }}",
"phoneNumber": "{{ phoneNumber }}",
"streetAddress": "{{ streetAddress }}",
"socialWorkerName": "{{ socialWorkerName }}",
"socialWorkerSurname": "{{ socialWorkerSurname }}",
"financialVulnerabilityScore": "{{ financialVulnerabilityScore }}",
"amountCoveredByOtherAids": "{{ amountCoveredByOtherAids }}",
"connectivityOptionList": "{{ connectivityOptionList }}",
"assessmentDate": "{{ assessmentDate }}"
},
"credentialSchema": {
"id": "https://idhub.pangea.org/vc_schemas/financial_vulnerability.json",
"type": "JsonSchema"
}
}

View File

@ -0,0 +1,19 @@
{
"vcId": "https://idhub.pangea.org/credentials/987654321",
"issuerDid": "did:example:5678",
"issuerName": "Pangea Internet Solidari",
"issuanceDate": "2023-12-06T19:23:24Z",
"validUntil": "2024-12-06T19:23:24Z",
"subjectDid": "did:example:1234",
"firstName": "Joan",
"lastName": "Pera",
"email": "joan.pera@pangea.org",
"membershipType": "individual",
"membershipId": "123456",
"affiliatedSince": "2023-01-01T00:00:00Z",
"affiliatedUntil": "2024-01-01T00:00:00Z",
"typeOfPerson": "natural",
"identityDocType": "DNI",
"identityNumber": "12345678A"
}

View File

@ -1,97 +0,0 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
{
"credentialSchema": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"value": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"lang": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"description": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname",
"name": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#name",
"organisation": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#organisation",
"membershipType": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#membershipType",
"membershipId": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#membershipId",
"affiliatedSince": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#iaffiliatedSince",
"affiliatedUntil": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#affiliatedUntil",
"typeOfPerson": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#typeOfPerson",
"identityDocType": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#identityDocType",
"identityNumber": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#identityNumber",
"email": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#email",
"surname": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/contexts/#surname"
}
],
"type": [
"VerifiableCredential",
"VerifiableAttestation",
"MembershipCard"
],
"id": "{{ vc_id }}",
"issuer": {
"id": "{{ issuer_did }}",
"name": "Pangea",
"description": [
{
"value": "Pangea.org is a service provider leveraging open-source technologies to provide affordable and accessible solutions for social enterprises and solidarity organisations.",
"lang": "en"
},
{
"value": "Pangea.org és un proveïdor de serveis que aprofita les tecnologies de codi obert per oferir solucions assequibles i accessibles per a empreses socials i organitzacions solidàries.",
"lang": "ca_ES"
},
{
"value": "Pangea.org es un proveedor de servicios que aprovecha tecnologías de código abierto para proporcionar soluciones asequibles y accesibles para empresas sociales y organizaciones solidarias.",
"lang": "es"
}
]
},
"issuanceDate": "{{ issuance_date }}",
"issued": "{{ issuance_date }}",
"validFrom": "{{ issuance_date }}",
"validUntil": "{{ validUntil }}",
"name": [
{
"value": "Membership Card",
"lang": "en"
},
{
"value": "Carnet de soci/a",
"lang": "ca_ES"
},
{
"value": "Carnet de socio/a",
"lang": "es"
}
],
"description": [
{
"value": "The membership card specifies an individual's subscription or enrollment in specific services or benefits issued by an organization.",
"lang": "en"
},
{
"value": "El carnet de soci especifica la subscripció o la inscripció d'un individu en serveis o beneficis específics emesos per una organització.",
"lang": "ca_ES"
},
{
"value": "El carnet de socio especifica la suscripción o inscripción de un individuo en servicios o beneficios específicos emitidos por uns organización.",
"lang": "es"
}
],
"credentialSubject": {
"id": "{{ subject_did }}",
"organisation": "Pangea",
"membershipType": "{{ membershipType }}",
"membershipId": "{{ membershipId }}",
"affiliatedSince": "{{ affiliatedSince }}",
"affiliatedUntil": "{{ affiliatedUntil }}",
"typeOfPerson": "{{ typeOfPerson }}",
"identityDocType": "{{ identityDocType }}",
"identityNumber": "{{ identityNumber }}",
"name": "{{ first_name }}",
"surname": "{{ last_name }}",
"email": "{{ email }}"
},
"credentialSchema": {
"id": "https://gitea.pangea.org/trustchain-oc1-orchestral/schemas/vc_schemas/membership-card.json",
"type": "JsonSchema"
}
}

View File

@ -0,0 +1,67 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://idhub.pangea.org/credentials/base/v1",
"https://idhub.pangea.org/credentials/membership-card/v1"
],
"type": [
"VerifiableCredential",
"VerifiableAttestation",
"MembershipCard"
],
"id": "{{ vcId }}",
"issuer": {
"id": "{{ issuerDid }}",
"name": "{{ issuerName }}"
},
"issuanceDate": "{{ issuanceDate }}",
"issued": "{{ issuanceDate }}",
"validFrom": "{{ issuanceDate }}",
"validUntil": "{{ validUntil }}",
"name": [
{
"value": "Membership Card",
"lang": "en"
},
{
"value": "Carnet de soci/a",
"lang": "ca_ES"
},
{
"value": "Carnet de socio/a",
"lang": "es"
}
],
"description": [
{
"value": "The membership card specifies an individual's subscription or enrollment in specific services or benefits issued by an organization.",
"lang": "en"
},
{
"value": "El carnet de soci especifica la subscripció o la inscripció d'un individu en serveis o beneficis específics emesos per una organització.",
"lang": "ca_ES"
},
{
"value": "El carnet de socio especifica la suscripción o inscripción de un individuo en servicios o beneficios específicos emitidos por uns organización.",
"lang": "es"
}
],
"credentialSubject": {
"id": "{{ subjectDid }}",
"firstName": "{{ firstName }}",
"lastName": "{{ lastName }}",
"email": "{{ email }}",
"typeOfPerson": "{{ typeOfPerson }}",
"identityDocType": "{{ identityDocType }}",
"identityNumber": "{{ identityNumber }}",
"organisation": "Pangea",
"membershipType": "{{ membershipType }}",
"membershipId": "{{ membershipId }}",
"affiliatedSince": "{{ affiliatedSince }}",
"affiliatedUntil": "{{ affiliatedUntil }}"
},
"credentialSchema": {
"id": "https://idhub.pangea.org/vc_schemas/membership-card.json",
"type": "JsonSchema"
}
}