fix: hash message before signing on keycard

This commit is contained in:
Igor Sirotin 2024-07-17 13:24:26 +01:00
parent cf7e10c76a
commit 2748d705e7
1 changed files with 15 additions and 2 deletions

View File

@ -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,