feat(@desktop/keycard): `startSignFlow` added to the keycard service
This commit is contained in:
parent
7a998b0e21
commit
fb5065da16
|
@ -15,6 +15,8 @@ const ErrorChanging* = "changing-credentials"
|
||||||
const ErrorLoadingKeys* = "loading-keys"
|
const ErrorLoadingKeys* = "loading-keys"
|
||||||
const ErrorStoreMeta* = "storing-metadata"
|
const ErrorStoreMeta* = "storing-metadata"
|
||||||
const ErrorNoData* = "no-data"
|
const ErrorNoData* = "no-data"
|
||||||
|
const ErrorFreePairingSlots* = "free-pairing-slots"
|
||||||
|
const ErrorPIN* = "pin"
|
||||||
|
|
||||||
const RequestParamAppInfo* = "application-info"
|
const RequestParamAppInfo* = "application-info"
|
||||||
const RequestParamInstanceUID* = "instance-uid"
|
const RequestParamInstanceUID* = "instance-uid"
|
||||||
|
@ -70,7 +72,7 @@ const ResponseTypeValueEnterCardName* = "keycard.action.enter-cardname"
|
||||||
const ResponseTypeValueEnterWallets* = "keycard.action.enter-wallets"
|
const ResponseTypeValueEnterWallets* = "keycard.action.enter-wallets"
|
||||||
|
|
||||||
const ResponseParamInitialized* = "initialized"
|
const ResponseParamInitialized* = "initialized"
|
||||||
const ResponseParamInstanceUID* = "instanceUID"
|
const ResponseParamAppInfoInstanceUID* = "instanceUID"
|
||||||
const ResponseParamVersion* = "version"
|
const ResponseParamVersion* = "version"
|
||||||
const ResponseParamAvailableSlots* = "availableSlots"
|
const ResponseParamAvailableSlots* = "availableSlots"
|
||||||
const ResponseParamAppInfoKeyUID* = "keyUID"
|
const ResponseParamAppInfoKeyUID* = "keyUID"
|
||||||
|
@ -80,7 +82,11 @@ const ResponseParamPath* = "path"
|
||||||
const ResponseParamAddress* = "address"
|
const ResponseParamAddress* = "address"
|
||||||
const ResponseParamPublicKey* = "publicKey"
|
const ResponseParamPublicKey* = "publicKey"
|
||||||
const ResponseParamPrivateKey* = "privateKey"
|
const ResponseParamPrivateKey* = "privateKey"
|
||||||
|
const ResponseParamTxSignatureR* = "r"
|
||||||
|
const ResponseParamTxSignatureS* = "s"
|
||||||
|
const ResponseParamTxSignatureV* = "v"
|
||||||
const ResponseParamErrorKey* = ErrorKey
|
const ResponseParamErrorKey* = ErrorKey
|
||||||
|
const ResponseParamInstanceUID* =RequestParamInstanceUID
|
||||||
const ResponseParamCardMeta* = RequestParamCardMeta
|
const ResponseParamCardMeta* = RequestParamCardMeta
|
||||||
const ResponseParamFreeSlots* = RequestParamFreeSlots
|
const ResponseParamFreeSlots* = RequestParamFreeSlots
|
||||||
const ResponseParamPINRetries* = RequestParamPINRetries
|
const ResponseParamPINRetries* = RequestParamPINRetries
|
||||||
|
@ -94,3 +100,4 @@ const ResponseParamWalletKey* = RequestParamWalletKey
|
||||||
const ResponseParamWalleRootKey* = RequestParamWalleRootKey
|
const ResponseParamWalleRootKey* = RequestParamWalleRootKey
|
||||||
const ResponseParamWhisperKey* = RequestParamWhisperKey
|
const ResponseParamWhisperKey* = RequestParamWhisperKey
|
||||||
const ResponseParamMnemonicIdxs* = RequestParamMnemonicIdxs
|
const ResponseParamMnemonicIdxs* = RequestParamMnemonicIdxs
|
||||||
|
const ResponseParamTXSignature* = RequestParamTXSignature
|
|
@ -19,8 +19,14 @@ type
|
||||||
name*: string
|
name*: string
|
||||||
walletAccounts*: seq[WalletAccount]
|
walletAccounts*: seq[WalletAccount]
|
||||||
|
|
||||||
|
TransactionSignature* = object
|
||||||
|
r*: string
|
||||||
|
s*: string
|
||||||
|
v*: string
|
||||||
|
|
||||||
KeycardEvent* = object
|
KeycardEvent* = object
|
||||||
error*: string
|
error*: string
|
||||||
|
instanceUID*: string
|
||||||
applicationInfo*: ApplicationInfo
|
applicationInfo*: ApplicationInfo
|
||||||
seedPhraseIndexes*: seq[int]
|
seedPhraseIndexes*: seq[int]
|
||||||
freePairingSlots*: int
|
freePairingSlots*: int
|
||||||
|
@ -28,6 +34,7 @@ type
|
||||||
pinRetries*: int
|
pinRetries*: int
|
||||||
pukRetries*: int
|
pukRetries*: int
|
||||||
cardMetadata*: CardMetadata
|
cardMetadata*: CardMetadata
|
||||||
|
txSignature*: TransactionSignature
|
||||||
eip1581Key*: KeyDetails
|
eip1581Key*: KeyDetails
|
||||||
encryptionKey*: KeyDetails
|
encryptionKey*: KeyDetails
|
||||||
masterKey*: KeyDetails
|
masterKey*: KeyDetails
|
||||||
|
@ -43,7 +50,7 @@ proc toKeyDetails(jsonObj: JsonNode): KeyDetails =
|
||||||
|
|
||||||
proc toApplicationInfo(jsonObj: JsonNode): ApplicationInfo =
|
proc toApplicationInfo(jsonObj: JsonNode): ApplicationInfo =
|
||||||
discard jsonObj.getProp(ResponseParamInitialized, result.initialized)
|
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(ResponseParamVersion, result.version)
|
||||||
discard jsonObj.getProp(ResponseParamAvailableSlots, result.availableSlots)
|
discard jsonObj.getProp(ResponseParamAvailableSlots, result.availableSlots)
|
||||||
discard jsonObj.getProp(ResponseParamAppInfoKeyUID, result.keyUID)
|
discard jsonObj.getProp(ResponseParamAppInfoKeyUID, result.keyUID)
|
||||||
|
@ -59,8 +66,14 @@ proc toCardMetadata(jsonObj: JsonNode): CardMetadata =
|
||||||
for acc in accountsArr:
|
for acc in accountsArr:
|
||||||
result.walletAccounts.add(acc.toWalletAccount())
|
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 =
|
proc toKeycardEvent(jsonObj: JsonNode): KeycardEvent =
|
||||||
discard jsonObj.getProp(ResponseParamErrorKey, result.error)
|
discard jsonObj.getProp(ResponseParamErrorKey, result.error)
|
||||||
|
discard jsonObj.getProp(ResponseParamInstanceUID, result.instanceUID)
|
||||||
discard jsonObj.getProp(ResponseParamFreeSlots, result.freePairingSlots)
|
discard jsonObj.getProp(ResponseParamFreeSlots, result.freePairingSlots)
|
||||||
discard jsonObj.getProp(ResponseParamPINRetries, result.pinRetries)
|
discard jsonObj.getProp(ResponseParamPINRetries, result.pinRetries)
|
||||||
discard jsonObj.getProp(ResponseParamPUKRetries, result.pukRetries)
|
discard jsonObj.getProp(ResponseParamPUKRetries, result.pukRetries)
|
||||||
|
@ -96,3 +109,6 @@ proc toKeycardEvent(jsonObj: JsonNode): KeycardEvent =
|
||||||
|
|
||||||
if(jsonObj.getProp(ResponseParamCardMeta, obj)):
|
if(jsonObj.getProp(ResponseParamCardMeta, obj)):
|
||||||
result.cardMetadata = toCardMetadata(obj)
|
result.cardMetadata = toCardMetadata(obj)
|
||||||
|
|
||||||
|
if(jsonObj.getProp(ResponseParamTXSignature, obj)):
|
||||||
|
result.txSignature = toTransactionSignature(obj)
|
|
@ -23,6 +23,9 @@ type KCSFlowType* {.pure.} = enum
|
||||||
StoreMetadata
|
StoreMetadata
|
||||||
GetMetadata
|
GetMetadata
|
||||||
|
|
||||||
|
const EmptyTxHash = "0000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
const DefaultBIP44Path = "m/0"
|
||||||
|
|
||||||
const PINLengthForStatusApp* = 6
|
const PINLengthForStatusApp* = 6
|
||||||
const PUKLengthForStatusApp* = 12
|
const PUKLengthForStatusApp* = 12
|
||||||
|
|
||||||
|
@ -33,7 +36,7 @@ const SupportedMnemonicLength24* = 24
|
||||||
const MnemonicLengthForStatusApp = SupportedMnemonicLength12
|
const MnemonicLengthForStatusApp = SupportedMnemonicLength12
|
||||||
const TimerIntervalInMilliseconds = 3 * 1000 # 3 seconds
|
const TimerIntervalInMilliseconds = 3 * 1000 # 3 seconds
|
||||||
|
|
||||||
const SignalKeycardResponse* = "keycardResponse"
|
const SIGNAL_KEYCARD_RESPONSE* = "keycardResponse"
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "keycard-service"
|
topics = "keycard-service"
|
||||||
|
@ -101,7 +104,7 @@ QtObject:
|
||||||
let flowType = typeObj.getStr
|
let flowType = typeObj.getStr
|
||||||
let flowEvent = toKeycardEvent(eventObj)
|
let flowEvent = toKeycardEvent(eventObj)
|
||||||
self.lastReceivedKeycardData = (flowType: flowType, flowEvent: flowEvent)
|
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.} =
|
proc receiveKeycardSignal(self: Service, signal: string) {.slot.} =
|
||||||
self.processSignal(signal)
|
self.processSignal(signal)
|
||||||
|
@ -170,7 +173,7 @@ QtObject:
|
||||||
|
|
||||||
proc startLoadAccountFlowWithSeedPhrase*(self: Service, seedPhraseLength: int, seedPhrase: string, factoryReset: bool) =
|
proc startLoadAccountFlowWithSeedPhrase*(self: Service, seedPhraseLength: int, seedPhrase: string, factoryReset: bool) =
|
||||||
if seedPhrase.len == 0:
|
if seedPhrase.len == 0:
|
||||||
info "empty seed phrase provided"
|
error "empty seed phrase provided"
|
||||||
return
|
return
|
||||||
var payload = %* {
|
var payload = %* {
|
||||||
RequestParamOverwrite: true,
|
RequestParamOverwrite: true,
|
||||||
|
@ -223,9 +226,21 @@ QtObject:
|
||||||
self.currentFlow = KCSFlowType.StoreMetadata
|
self.currentFlow = KCSFlowType.StoreMetadata
|
||||||
self.startFlow(payload)
|
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) =
|
proc storePin*(self: Service, pin: string, puk: string) =
|
||||||
if pin.len == 0:
|
if pin.len == 0:
|
||||||
info "empty pin provided"
|
error "empty pin provided"
|
||||||
return
|
return
|
||||||
var payload = %* {
|
var payload = %* {
|
||||||
RequestParamOverwrite: true,
|
RequestParamOverwrite: true,
|
||||||
|
@ -239,7 +254,7 @@ QtObject:
|
||||||
|
|
||||||
proc enterPin*(self: Service, pin: string) =
|
proc enterPin*(self: Service, pin: string) =
|
||||||
if pin.len == 0:
|
if pin.len == 0:
|
||||||
info "empty pin provided"
|
error "empty pin provided"
|
||||||
return
|
return
|
||||||
var payload = %* {
|
var payload = %* {
|
||||||
RequestParamPIN: pin
|
RequestParamPIN: pin
|
||||||
|
@ -248,7 +263,7 @@ QtObject:
|
||||||
|
|
||||||
proc enterPuk*(self: Service, puk: string) =
|
proc enterPuk*(self: Service, puk: string) =
|
||||||
if puk.len == 0:
|
if puk.len == 0:
|
||||||
info "empty puk provided"
|
error "empty puk provided"
|
||||||
return
|
return
|
||||||
var payload = %* {
|
var payload = %* {
|
||||||
RequestParamPUK: puk
|
RequestParamPUK: puk
|
||||||
|
@ -257,7 +272,7 @@ QtObject:
|
||||||
|
|
||||||
proc storeSeedPhrase*(self: Service, seedPhraseLength: int, seedPhrase: string) =
|
proc storeSeedPhrase*(self: Service, seedPhraseLength: int, seedPhrase: string) =
|
||||||
if seedPhrase.len == 0:
|
if seedPhrase.len == 0:
|
||||||
info "empty seed phrase provided"
|
error "empty seed phrase provided"
|
||||||
return
|
return
|
||||||
var payload = %* {
|
var payload = %* {
|
||||||
RequestParamOverwrite: true,
|
RequestParamOverwrite: true,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 16f37cb459b4aa2d24fa194bb40fd8a4e6541f93
|
Subproject commit 7ffa0cc32d6b8fad681742cfe5693f05f64b5e68
|
Loading…
Reference in New Issue