convert jsonld in credentials for dpps
This commit is contained in:
parent
b2e6406fb6
commit
7f44d88b61
41
did/template_credential.py
Normal file
41
did/template_credential.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
dpp_tmpl = {
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/credentials/v2",
|
||||||
|
"https://test.uncefact.org/vocabulary/untp/dpp/0.5.0/"
|
||||||
|
],
|
||||||
|
"type": [
|
||||||
|
"DigitalProductPassport",
|
||||||
|
"VerifiableCredential"
|
||||||
|
],
|
||||||
|
"id": "https://example.ereuse.org/credentials/2a423366-a0d6-4855-ba65-2e0c926d09b0",
|
||||||
|
"issuer": {
|
||||||
|
"type": [
|
||||||
|
"CredentialIssuer"
|
||||||
|
],
|
||||||
|
"id": "did:web:r1.identifiers.ereuse.org:did-registry:z6Mkoreij5y9bD9fL5SGW6TfMUmcbaV7LCPwZHCFEEZBrVYQ#z6Mkoreij5y9bD9fL5SGW6TfMUmcbaV7LCPwZHCFEEZBrVYQ",
|
||||||
|
"name": "Refurbisher One"
|
||||||
|
},
|
||||||
|
"validFrom": "2024-11-15T12:00:00",
|
||||||
|
"validUntil": "2034-11-15T12:00:00",
|
||||||
|
"credentialSubject": {
|
||||||
|
"type": [
|
||||||
|
"Product"
|
||||||
|
],
|
||||||
|
"id": "https://id.ereuse.org/01/09520123456788/21/12345",
|
||||||
|
"name": "Refurbished XYZ Lenovo laptop item",
|
||||||
|
"registeredId": "09520123456788.21.12345",
|
||||||
|
"description": "XYZ Lenovo laptop refurbished by Refurbisher One",
|
||||||
|
"data": ""
|
||||||
|
},
|
||||||
|
"credentialSchema": {
|
||||||
|
"id": "https://idhub.pangea.org/vc_schemas/dpp.json",
|
||||||
|
"type": "FullJsonSchemaValidator2021",
|
||||||
|
"proof": {
|
||||||
|
"type": "Ed25519Signature2018",
|
||||||
|
"proofPurpose": "assertionMethod",
|
||||||
|
"verificationMethod": "did:web:r1.identifiers.ereuse.org:did-registry:z6Mkoreij5y9bD9fL5SGW6TfMUmcbaV7LCPwZHCFEEZBrVYQ#z6Mkoreij5y9bD9fL5SGW6TfMUmcbaV7LCPwZHCFEEZBrVYQ",
|
||||||
|
"created": "2024-12-03T15:33:42Z",
|
||||||
|
"jws": "eyJhbGciOiJFZERTQSIsImNyaXQiOlsiYjY0Il0sImI2NCI6ZmFsc2V9..rBPqbOcZCXB7GAnq1XIfV9Jvw4MKXlHff7qZkRfgwQ0Hnd9Ujt5s1xT4O0K6VESzWvdP2mOvMvu780fVNfraBQ"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
did/views.py
27
did/views.py
|
@ -8,6 +8,7 @@ from evidence.parse import Build
|
||||||
from dpp.api_dlt import ALGORITHM
|
from dpp.api_dlt import ALGORITHM
|
||||||
from dpp.models import Proof
|
from dpp.models import Proof
|
||||||
from dpp.api_dlt import PROOF_TYPE
|
from dpp.api_dlt import PROOF_TYPE
|
||||||
|
from did.template_credential import dpp_tmpl
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('django')
|
logger = logging.getLogger('django')
|
||||||
|
@ -89,21 +90,21 @@ class PublicDeviceWebView(TemplateView):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def get_result(self):
|
def get_result(self):
|
||||||
components = []
|
|
||||||
|
if len(self.pk.split(":")) > 1:
|
||||||
|
return self.build_from_dpp()
|
||||||
|
else:
|
||||||
|
return self.build_from_chid()
|
||||||
|
|
||||||
|
def build_from_dpp(self):
|
||||||
data = {
|
data = {
|
||||||
'document': {},
|
'document': {},
|
||||||
'dpp': self.pk,
|
'dpp': self.pk,
|
||||||
'algorithm': ALGORITHM,
|
'algorithm': ALGORITHM,
|
||||||
'components': components,
|
'components': [],
|
||||||
'manufacturer DPP': '',
|
'manufacturer DPP': '',
|
||||||
'device': {},
|
'device': {},
|
||||||
}
|
}
|
||||||
result = {
|
|
||||||
'@context': ['https://ereuse.org/dpp0.json'],
|
|
||||||
'data': data,
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(self.pk.split(":")) > 1:
|
|
||||||
dev = Build(self.object.last_evidence.doc, None, check=True)
|
dev = Build(self.object.last_evidence.doc, None, check=True)
|
||||||
doc = dev.get_phid()
|
doc = dev.get_phid()
|
||||||
data['document'] = json.dumps(doc)
|
data['document'] = json.dumps(doc)
|
||||||
|
@ -124,8 +125,11 @@ class PublicDeviceWebView(TemplateView):
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
data['url_last'] = url
|
data['url_last'] = url
|
||||||
return result
|
tmpl = dpp_tmpl.copy()
|
||||||
|
tmpl["credentialSubject"]["data"] = data
|
||||||
|
return tmpl
|
||||||
|
|
||||||
|
def build_from_chid(self):
|
||||||
dpps = []
|
dpps = []
|
||||||
self.object.initial()
|
self.object.initial()
|
||||||
for d in self.object.evidences:
|
for d in self.object.evidences:
|
||||||
|
@ -144,7 +148,10 @@ class PublicDeviceWebView(TemplateView):
|
||||||
'components': dev.components
|
'components': dev.components
|
||||||
}
|
}
|
||||||
|
|
||||||
dpps.append(rr)
|
tmpl = dpp_tmpl.copy()
|
||||||
|
tmpl["credentialSubject"]["data"] = rr
|
||||||
|
|
||||||
|
dpps.append(tmpl)
|
||||||
return {
|
return {
|
||||||
'@context': ['https://ereuse.org/dpp0.json'],
|
'@context': ['https://ereuse.org/dpp0.json'],
|
||||||
'data': dpps,
|
'data': dpps,
|
||||||
|
|
Loading…
Reference in a new issue