From 2748d705e7ab2a02eb33ae541061a243f9abaa92 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Wed, 17 Jul 2024 13:24:26 +0100 Subject: [PATCH] fix: hash message before signing on keycard --- src/app/modules/main/communities/controller.nim | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 8dcb07e407..785a9ae63c 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -1,4 +1,4 @@ -import std/strutils, uuids, chronicles +import std/strutils, uuids, chronicles, json import ./io_interface import app/core/signals/types @@ -16,6 +16,8 @@ import app_service/common/types import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module import app_service/service/network/network_item +import status_go + const UNIQUE_COMMUNITIES_MODULE_AUTH_IDENTIFIER* = "CommunitiesModule-Authentication" const UNIQUE_COMMUNITIES_MODULE_SIGNING_IDENTIFIER* = "CommunitiesModule-Signing" @@ -470,11 +472,22 @@ proc runSignFlow(self: Controller, pin, path, dataToSign: string) = self.connectKeycardReponseSignal() self.keycardService.startSignFlow(path, dataToSign, pin) +proc hashMessage(self: Controller, message: string): string = + try: + let response = status_go.hashMessage(message) + let jsonResponse = parseJson(response) + return jsonResponse{"result"}.getStr() + except Exception as e: + error "hashMessage: failed to parse json response", error = e.msg + return "" + proc runSigningOnKeycard*(self: Controller, keyUid: string, path: string, dataToSign: string, pin: string) = debug "<<< runSigningOnKeycard", keyUid, path, dataToSign, pin - var finalDataToSign = dataToSign + + var finalDataToSign = hashMessage(self, dataToSign) if finalDataToSign.startsWith("0x"): finalDataToSign = finalDataToSign[2..^1] + if pin.len == 0: let data = SharedKeycarModuleSigningArgs(uniqueIdentifier: UNIQUE_COMMUNITIES_MODULE_SIGNING_IDENTIFIER, keyUid: keyUid,