DPP/DLT functionality #36
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
did/views.py
61
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,43 +90,46 @@ 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 = {
|
dev = Build(self.object.last_evidence.doc, None, check=True)
|
||||||
'@context': ['https://ereuse.org/dpp0.json'],
|
doc = dev.get_phid()
|
||||||
'data': data,
|
data['document'] = json.dumps(doc)
|
||||||
}
|
data['device'] = dev.device
|
||||||
|
data['components'] = dev.components
|
||||||
|
|
||||||
if len(self.pk.split(":")) > 1:
|
self.object.get_evidences()
|
||||||
dev = Build(self.object.last_evidence.doc, None, check=True)
|
last_dpp = Proof.objects.filter(
|
||||||
doc = dev.get_phid()
|
uuid__in=self.object.uuids, type=PROOF_TYPE['IssueDPP']
|
||||||
data['document'] = json.dumps(doc)
|
).order_by("-timestamp").first()
|
||||||
data['device'] = dev.device
|
|
||||||
data['components'] = dev.components
|
|
||||||
|
|
||||||
self.object.get_evidences()
|
key = self.pk
|
||||||
last_dpp = Proof.objects.filter(
|
if last_dpp:
|
||||||
uuid__in=self.object.uuids, type=PROOF_TYPE['IssueDPP']
|
key = last_dpp.signature
|
||||||
).order_by("-timestamp").first()
|
|
||||||
|
|
||||||
key = self.pk
|
url = "https://{}/did/{}".format(
|
||||||
if last_dpp:
|
self.request.get_host(),
|
||||||
key = last_dpp.signature
|
key
|
||||||
|
)
|
||||||
url = "https://{}/did/{}".format(
|
data['url_last'] = url
|
||||||
self.request.get_host(),
|
tmpl = dpp_tmpl.copy()
|
||||||
key
|
tmpl["credentialSubject"]["data"] = data
|
||||||
)
|
return tmpl
|
||||||
data['url_last'] = url
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
|
|
@ -12,5 +12,5 @@ odfpy==1.4.1
|
||||||
pytz==2024.2
|
pytz==2024.2
|
||||||
json-repair==0.30.0
|
json-repair==0.30.0
|
||||||
setuptools==75.5.0
|
setuptools==75.5.0
|
||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
wheel==0.45.0
|
wheel==0.45.0
|
||||||
|
|
Loading…
Reference in a new issue