diff --git a/backends/backend.nim b/backends/backend.nim index c15c68c..fe2aeb2 100644 --- a/backends/backend.nim +++ b/backends/backend.nim @@ -5,9 +5,11 @@ from base/bookmarks as bookmarks_methods import storeBookmark, updateBookmark, g export storeBookmark, updateBookmark, getBookmarks, deleteBookmark from base/keycard as keycard_methods import keycardStart, keycardStop, keycardSelect, keycardPair, - keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication + keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication, + keycardUnpair, keycardGenerateKey export keycardStart, keycardStop, keycardSelect, keycardPair, - keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication + keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication, + keycardUnpair, keycardGenerateKey import statusgo/bookmarks as statusgo_bookmarks import mock/bookmarks as mock_bookmarks diff --git a/backends/base/keycard.nim b/backends/base/keycard.nim index 742007b..3f6bfbf 100644 --- a/backends/base/keycard.nim +++ b/backends/base/keycard.nim @@ -24,3 +24,10 @@ method keycardExportKey*(self: Backend, derive: bool, makeCurrent: bool, onlyPub method keycardGetStatusApplication*(self: Backend): KeycardStatus = raise newException(ValueError, "No implementation available") + +method keycardUnpair*(self: Backend, index: int) = + raise newException(ValueError, "No implementation available") + +method keycardGenerateKey*(self: Backend): string = + raise newException(ValueError, "No implementation available") + diff --git a/backends/mock/keycard.nim b/backends/mock/keycard.nim index 39484e1..3b1cb2b 100644 --- a/backends/mock/keycard.nim +++ b/backends/mock/keycard.nim @@ -20,3 +20,8 @@ method keycardExportKey*(self: MockBackend, derive: bool, makeCurrent: bool, onl method keycardGetStatusApplication*(self: MockBackend): KeycardStatus = result = KeycardStatus() + +method keycardUnpair*(self: MockBackend, index: int) = discard + +method keycardGenerateKey*(self: MockBackend): string = + result = "0x00" diff --git a/backends/statusgo/keycard.nim b/backends/statusgo/keycard.nim index 77e2155..bb9e880 100644 --- a/backends/statusgo/keycard.nim +++ b/backends/statusgo/keycard.nim @@ -91,3 +91,19 @@ method keycardGetStatusApplication*(self: StatusGoBackend): KeycardStatus = pukRetryCount: parsedResponse["status"]["pukRetryCount"].getInt(), keyInitialized: parsedResponse["status"]["keyInitialized"].getBool() ) + +method keycardUnpair*(self: StatusGoBackend, index: int) = + let inputJSON = %* { + "index": index, + } + let response = keycard_go.unpair($inputJSON) + let parsedResponse = parseJson(response) + if not parsedResponse{"ok"}.getBool(): + raise KeycardUnpairException(error: parsedResponse{"error"}.getStr()) + +method keycardGenerateKey*(self: StatusGoBackend): string = + let response = keycard_go.generateKey() + let parsedResponse = parseJson(response) + if not parsedResponse{"ok"}.getBool(): + raise KeycardGenerateKeyException(error: parsedResponse{"error"}.getStr()) + result = parsedResponse["keyUID"].getStr() diff --git a/status/keycard.nim b/status/keycard.nim index 1f26e3d..b2a8214 100644 --- a/status/keycard.nim +++ b/status/keycard.nim @@ -58,3 +58,15 @@ proc getStatusApplication*(self: KeycardModel): KeycardStatus = result = self.backend.keycardGetStatusApplication() except: raise + +proc unpair*(self: KeycardModel, index: int) = + try: + self.backend.keycardUnpair(index) + except: + raise + +proc generateKey*(self: KeycardModel): string = + try: + result = self.backend.keycardGenerateKey() + except: + raise diff --git a/types/keycard.nim b/types/keycard.nim index 7396b80..a5295ae 100644 --- a/types/keycard.nim +++ b/types/keycard.nim @@ -13,6 +13,10 @@ type KeycardOpenSecureChannelException* = ref object of KeycardException type KeycardGetStatusException* = ref object of KeycardException +type KeycardUnpairException* = ref object of KeycardException + +type KeycardGenerateKeyException* = ref object of KeycardException + type KeycardVerifyPINException* = ref object of KeycardException pinRetry*: int64