From 0ad35de5d63b5bea0c2e25a0d4adbe9a201e5121 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 23 Oct 2023 19:43:10 +0200 Subject: [PATCH] add new changes of ereuseapitest --- ereuse_devicehub/resources/action/models.py | 7 +++---- ereuse_devicehub/resources/device/models.py | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index f7610475..a63ae110 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -899,7 +899,7 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice): if 'dpp' not in app.blueprints.keys() or not self.device.hid: return - from ereuse_devicehub.modules.dpp.models import Dpp + from ereuse_devicehub.modules.dpp.models import Dpp, ALGORITHM dpp = "{chid}:{phid}".format(chid=self.device.chid, phid=self.phid_dpp) if Dpp.query.filter_by(key=dpp).all(): @@ -916,15 +916,14 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice): api = API(api_dlt, token_dlt, "ethereum") docSig = self.phid_dpp - docID = "{}".format(self.uuid or '') - issuerID = "{dh}:{user}".format(dh=dh_instance, user=g.user.id) - result = api.issue_passport(dpp, docID, docSig, issuerID) + result = api.issue_passport(dpp, ALGORITHM, docSig, dh_instance) if result['Status'] is not StatusCode.Success.value: return timestamp = result['Data'].get('data', {}).get('timestamp', time.time()) + docID = "{}".format(self.uuid or '') d_issue = { "device_id": self.device.id, "snapshot": self, diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 4601b1db..3f5dfdf0 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -954,11 +954,24 @@ class Device(Thing): return API(api_dlt, token_dlt, "ethereum") def register_dlt(self): + if not app.config.get('ID_FEDERATED'): + return + api = self.connect_api() if not api: return - result = api.register_device(self.chid) + snapshot = [x for x in self.actions if x.t == 'Snapshot'] + if not snapshot: + return + snapshot = snapshot[0] + from ereuse_devicehub.modules.dpp.models import ALGORITHM + result = api.register_device( + self.chid, + ALGORITHM, + snapshot.phid_dpp, + app.config.get('ID_FEDERATED') + ) self.register_proof(result) if app.config.get('ID_FEDERATED'):