Added support for VP issuance

This commit is contained in:
Daniel Armengod 2023-11-22 14:09:08 +01:00
parent 9608add9dd
commit cd35ac1bc8
12 changed files with 195 additions and 108 deletions

View File

@ -3,6 +3,8 @@ import datetime
import didkit import didkit
import json import json
import jinja2 import jinja2
from jinja2 import Environment, FileSystemLoader, select_autoescape
def generate_did_controller_key(): def generate_did_controller_key():
@ -56,3 +58,28 @@ def verify_credential(vc, proof_options):
return didkit.verify_credential(vc, proof_options) return didkit.verify_credential(vc, proof_options)
return asyncio.run(inner()) 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())

86
main.py
View File

@ -4,29 +4,71 @@ import json
from jinja2 import Environment, FileSystemLoader, select_autoescape from jinja2 import Environment, FileSystemLoader, select_autoescape
import idhub_ssikit import idhub_ssikit
jwk_issuer = didkit.generate_ed25519_key()
jwk_subject = didkit.generate_ed25519_key()
did_issuer = didkit.key_to_did("key", jwk_issuer) def issue_vc_test():
did_subject = didkit.key_to_did("key", jwk_subject) 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( def issue_vp_test():
loader=FileSystemLoader("vc_templates"), jwk_issuer = didkit.generate_ed25519_key()
autoescape=select_autoescape() jwk_issuer2 = didkit.generate_ed25519_key()
) jwk_subject = didkit.generate_ed25519_key()
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
)
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)

View File

@ -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 }}"
}
}
}

View File

@ -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 }}"
}
}

30
vc_templates/exo.json Normal file
View File

@ -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"
}
}
}

View File

@ -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"
}
}
}

View File

@ -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"
}
}
}

View File

@ -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}}"
}
}

View File

@ -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 }}
}

View File

@ -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"
}
}
}