feat(@desktop/keycard): `startSignFlow` added to the keycard service

This commit is contained in:
Sale Djenic 2022-09-13 11:56:59 +02:00 committed by saledjenic
parent 7a998b0e21
commit fb5065da16
4 changed files with 50 additions and 12 deletions

View File

@ -15,6 +15,8 @@ const ErrorChanging* = "changing-credentials"
const ErrorLoadingKeys* = "loading-keys"
const ErrorStoreMeta* = "storing-metadata"
const ErrorNoData* = "no-data"
const ErrorFreePairingSlots* = "free-pairing-slots"
const ErrorPIN* = "pin"
const RequestParamAppInfo* = "application-info"
const RequestParamInstanceUID* = "instance-uid"
@ -70,7 +72,7 @@ const ResponseTypeValueEnterCardName* = "keycard.action.enter-cardname"
const ResponseTypeValueEnterWallets* = "keycard.action.enter-wallets"
const ResponseParamInitialized* = "initialized"
const ResponseParamInstanceUID* = "instanceUID"
const ResponseParamAppInfoInstanceUID* = "instanceUID"
const ResponseParamVersion* = "version"
const ResponseParamAvailableSlots* = "availableSlots"
const ResponseParamAppInfoKeyUID* = "keyUID"
@ -80,7 +82,11 @@ const ResponseParamPath* = "path"
const ResponseParamAddress* = "address"
const ResponseParamPublicKey* = "publicKey"
const ResponseParamPrivateKey* = "privateKey"
const ResponseParamTxSignatureR* = "r"
const ResponseParamTxSignatureS* = "s"
const ResponseParamTxSignatureV* = "v"
const ResponseParamErrorKey* = ErrorKey
const ResponseParamInstanceUID* =RequestParamInstanceUID
const ResponseParamCardMeta* = RequestParamCardMeta
const ResponseParamFreeSlots* = RequestParamFreeSlots
const ResponseParamPINRetries* = RequestParamPINRetries
@ -94,3 +100,4 @@ const ResponseParamWalletKey* = RequestParamWalletKey
const ResponseParamWalleRootKey* = RequestParamWalleRootKey
const ResponseParamWhisperKey* = RequestParamWhisperKey
const ResponseParamMnemonicIdxs* = RequestParamMnemonicIdxs
const ResponseParamTXSignature* = RequestParamTXSignature

View File

@ -19,8 +19,14 @@ type
name*: string
walletAccounts*: seq[WalletAccount]
TransactionSignature* = object
r*: string
s*: string
v*: string
KeycardEvent* = object
error*: string
instanceUID*: string
applicationInfo*: ApplicationInfo
seedPhraseIndexes*: seq[int]
freePairingSlots*: int
@ -28,6 +34,7 @@ type
pinRetries*: int
pukRetries*: int
cardMetadata*: CardMetadata
txSignature*: TransactionSignature
eip1581Key*: KeyDetails
encryptionKey*: KeyDetails
masterKey*: KeyDetails
@ -43,7 +50,7 @@ proc toKeyDetails(jsonObj: JsonNode): KeyDetails =
proc toApplicationInfo(jsonObj: JsonNode): ApplicationInfo =
discard jsonObj.getProp(ResponseParamInitialized, result.initialized)
discard jsonObj.getProp(ResponseParamInstanceUID, result.instanceUID)
discard jsonObj.getProp(ResponseParamAppInfoInstanceUID, result.instanceUID)
discard jsonObj.getProp(ResponseParamVersion, result.version)
discard jsonObj.getProp(ResponseParamAvailableSlots, result.availableSlots)
discard jsonObj.getProp(ResponseParamAppInfoKeyUID, result.keyUID)
@ -59,8 +66,14 @@ proc toCardMetadata(jsonObj: JsonNode): CardMetadata =
for acc in accountsArr:
result.walletAccounts.add(acc.toWalletAccount())
proc toTransactionSignature(jsonObj: JsonNode): TransactionSignature =
discard jsonObj.getProp(ResponseParamTxSignatureR, result.r)
discard jsonObj.getProp(ResponseParamTxSignatureS, result.s)
discard jsonObj.getProp(ResponseParamTxSignatureV, result.v)
proc toKeycardEvent(jsonObj: JsonNode): KeycardEvent =
discard jsonObj.getProp(ResponseParamErrorKey, result.error)
discard jsonObj.getProp(ResponseParamInstanceUID, result.instanceUID)
discard jsonObj.getProp(ResponseParamFreeSlots, result.freePairingSlots)
discard jsonObj.getProp(ResponseParamPINRetries, result.pinRetries)
discard jsonObj.getProp(ResponseParamPUKRetries, result.pukRetries)
@ -96,3 +109,6 @@ proc toKeycardEvent(jsonObj: JsonNode): KeycardEvent =
if(jsonObj.getProp(ResponseParamCardMeta, obj)):
result.cardMetadata = toCardMetadata(obj)
if(jsonObj.getProp(ResponseParamTXSignature, obj)):
result.txSignature = toTransactionSignature(obj)

View File

@ -23,6 +23,9 @@ type KCSFlowType* {.pure.} = enum
StoreMetadata
GetMetadata
const EmptyTxHash = "0000000000000000000000000000000000000000000000000000000000000000"
const DefaultBIP44Path = "m/0"
const PINLengthForStatusApp* = 6
const PUKLengthForStatusApp* = 12
@ -33,7 +36,7 @@ const SupportedMnemonicLength24* = 24
const MnemonicLengthForStatusApp = SupportedMnemonicLength12
const TimerIntervalInMilliseconds = 3 * 1000 # 3 seconds
const SignalKeycardResponse* = "keycardResponse"
const SIGNAL_KEYCARD_RESPONSE* = "keycardResponse"
logScope:
topics = "keycard-service"
@ -101,7 +104,7 @@ QtObject:
let flowType = typeObj.getStr
let flowEvent = toKeycardEvent(eventObj)
self.lastReceivedKeycardData = (flowType: flowType, flowEvent: flowEvent)
self.events.emit(SignalKeycardResponse, KeycardArgs(flowType: flowType, flowEvent: flowEvent))
self.events.emit(SIGNAL_KEYCARD_RESPONSE, KeycardArgs(flowType: flowType, flowEvent: flowEvent))
proc receiveKeycardSignal(self: Service, signal: string) {.slot.} =
self.processSignal(signal)
@ -170,7 +173,7 @@ QtObject:
proc startLoadAccountFlowWithSeedPhrase*(self: Service, seedPhraseLength: int, seedPhrase: string, factoryReset: bool) =
if seedPhrase.len == 0:
info "empty seed phrase provided"
error "empty seed phrase provided"
return
var payload = %* {
RequestParamOverwrite: true,
@ -223,9 +226,21 @@ QtObject:
self.currentFlow = KCSFlowType.StoreMetadata
self.startFlow(payload)
proc startSignFlow*(self: Service, bip44Path: string, txHash: string) =
var payload = %* {
RequestParamTXHash: EmptyTxHash,
RequestParamBIP44Path: DefaultBIP44Path
}
if txHash.len > 0:
payload[RequestParamTXHash] = %* txHash
if bip44Path.len > 0:
payload[RequestParamBIP44Path] = %* bip44Path
self.currentFlow = KCSFlowType.Sign
self.startFlow(payload)
proc storePin*(self: Service, pin: string, puk: string) =
if pin.len == 0:
info "empty pin provided"
error "empty pin provided"
return
var payload = %* {
RequestParamOverwrite: true,
@ -239,7 +254,7 @@ QtObject:
proc enterPin*(self: Service, pin: string) =
if pin.len == 0:
info "empty pin provided"
error "empty pin provided"
return
var payload = %* {
RequestParamPIN: pin
@ -248,7 +263,7 @@ QtObject:
proc enterPuk*(self: Service, puk: string) =
if puk.len == 0:
info "empty puk provided"
error "empty puk provided"
return
var payload = %* {
RequestParamPUK: puk
@ -257,7 +272,7 @@ QtObject:
proc storeSeedPhrase*(self: Service, seedPhraseLength: int, seedPhrase: string) =
if seedPhrase.len == 0:
info "empty seed phrase provided"
error "empty seed phrase provided"
return
var payload = %* {
RequestParamOverwrite: true,

@ -1 +1 @@
Subproject commit 16f37cb459b4aa2d24fa194bb40fd8a4e6541f93
Subproject commit 7ffa0cc32d6b8fad681742cfe5693f05f64b5e68