Added support for VP issuance
This commit is contained in:
parent
9608add9dd
commit
cd35ac1bc8
|
@ -3,6 +3,8 @@ import datetime
|
|||
import didkit
|
||||
import json
|
||||
import jinja2
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
|
||||
|
||||
|
||||
def generate_did_controller_key():
|
||||
|
@ -56,3 +58,28 @@ def verify_credential(vc, proof_options):
|
|||
return didkit.verify_credential(vc, proof_options)
|
||||
|
||||
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())
|
||||
|
||||
|
||||
|
|
Binary file not shown.
86
main.py
86
main.py
|
@ -4,29 +4,71 @@ import json
|
|||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
import idhub_ssikit
|
||||
|
||||
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)
|
||||
def issue_vc_test():
|
||||
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(
|
||||
loader=FileSystemLoader("vc_templates"),
|
||||
autoescape=select_autoescape()
|
||||
)
|
||||
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
|
||||
)
|
||||
def issue_vp_test():
|
||||
jwk_issuer = didkit.generate_ed25519_key()
|
||||
jwk_issuer2 = didkit.generate_ed25519_key()
|
||||
jwk_subject = didkit.generate_ed25519_key()
|
||||
|
||||
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)
|
||||
|
|
|
@ -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 }}"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 }}"
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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}}"
|
||||
}
|
||||
}
|
|
@ -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 }}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue