From b602caf72736252b2584c753ce83dd990f2bac1f Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Wed, 6 Oct 2021 10:59:16 +0200 Subject: [PATCH] keycardExportKey returns priv/pub key --- backends/base/keycard.nim | 2 +- backends/mock/keycard.nim | 4 ++-- backends/statusgo/keycard.nim | 7 +++++-- status/keycard.nim | 2 +- types/keycard.nim | 5 +++++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backends/base/keycard.nim b/backends/base/keycard.nim index 3f6bfbf..9dad1eb 100644 --- a/backends/base/keycard.nim +++ b/backends/base/keycard.nim @@ -19,7 +19,7 @@ method keycardOpenSecureChannel*(self: Backend, index: int, key: string) = method keycardVerifyPin*(self: Backend, pin: string) = raise newException(ValueError, "No implementation available") -method keycardExportKey*(self: Backend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string = +method keycardExportKey*(self: Backend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey = raise newException(ValueError, "No implementation available") method keycardGetStatusApplication*(self: Backend): KeycardStatus = diff --git a/backends/mock/keycard.nim b/backends/mock/keycard.nim index 3b1cb2b..19fa839 100644 --- a/backends/mock/keycard.nim +++ b/backends/mock/keycard.nim @@ -15,8 +15,8 @@ method keycardOpenSecureChannel*(self: MockBackend, index: int, key: string) = d method keycardVerifyPin*(self: MockBackend, pin: string) = discard -method keycardExportKey*(self: MockBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string = - result = "0x00" +method keycardExportKey*(self: MockBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey = + result = KeycardExportedKey() method keycardGetStatusApplication*(self: MockBackend): KeycardStatus = result = KeycardStatus() diff --git a/backends/statusgo/keycard.nim b/backends/statusgo/keycard.nim index bb9e880..1bf9242 100644 --- a/backends/statusgo/keycard.nim +++ b/backends/statusgo/keycard.nim @@ -67,7 +67,7 @@ method keycardVerifyPin*(self: StatusGoBackend, pin: string) = if not parsedResponse{"ok"}.getBool(): raise KeycardVerifyPINException(error: parsedResponse{"error"}.getStr()) -method keycardExportKey*(self: StatusGoBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string = +method keycardExportKey*(self: StatusGoBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey = let inputJSON = %* { "derive": derive, "makeCurrent": makeCurrent, @@ -79,7 +79,10 @@ method keycardExportKey*(self: StatusGoBackend, derive: bool, makeCurrent: bool, if not parsedResponse{"ok"}.getBool(): raise KeycardSelectException(error: parsedResponse{"error"}.getStr()) - result = parsedResponse["key"].getStr() + result = KeycardExportedKey( + privKey: parsedResponse["privateKey"].getStr(), + pubKey: parsedResponse["publicKey"].getStr() + ) method keycardGetStatusApplication*(self: StatusGoBackend): KeycardStatus = let response = keycard_go.getStatusApplication() diff --git a/status/keycard.nim b/status/keycard.nim index b2a8214..ac18021 100644 --- a/status/keycard.nim +++ b/status/keycard.nim @@ -47,7 +47,7 @@ proc verifyPin*(self: KeycardModel, pin: string) = except: raise -proc exportKey*(self: KeycardModel, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string = +proc exportKey*(self: KeycardModel, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey = try: result = self.backend.keycardExportKey(derive, makeCurrent, onlyPublic, path) except: diff --git a/types/keycard.nim b/types/keycard.nim index a5295ae..227d51d 100644 --- a/types/keycard.nim +++ b/types/keycard.nim @@ -41,3 +41,8 @@ type KeycardStatus* = ref object pukRetryCount *: int64 keyInitialized*: bool path*: string + +type KeycardExportedKey* = ref object + privKey*: string + pubKey*: string +