chore(@desktop/keycard): shared keycard popup module extension

shared keycard popup module is extended with:
- `uniqueIdentifier`
- `settingsService`
- `walletAccountService`
- `keychainService`
This commit is contained in:
Sale Djenic 2022-09-13 11:53:10 +02:00 committed by saledjenic
parent 6e9cb37766
commit 3042a0cffa
12 changed files with 233 additions and 31 deletions

View File

@ -1,4 +1,4 @@
import ../shared_models/section_item, io_interface, chronicles import chronicles
import ../../global/app_sections_config as conf import ../../global/app_sections_config as conf
import ../../global/global_singleton import ../../global/global_singleton
import ../../global/app_signals import ../../global/app_signals
@ -18,9 +18,14 @@ import ../../../app_service/service/mailservers/service as mailservers_service
import ../../../app_service/service/privacy/service as privacy_service import ../../../app_service/service/privacy/service as privacy_service
import ../../../app_service/service/node/service as node_service import ../../../app_service/service/node/service as node_service
import ../shared_models/section_item, io_interface
import ../shared_modules/keycard_popup/io_interface as keycard_shared_module
logScope: logScope:
topics = "main-module-controller" topics = "main-module-controller"
const UNIQUE_MAIN_MODULE_IDENTIFIER* = "MainModule"
type type
Controller* = ref object of RootObj Controller* = ref object of RootObj
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
@ -37,6 +42,7 @@ type
mailserversService: mailservers_service.Service mailserversService: mailservers_service.Service
nodeService: node_service.Service nodeService: node_service.Service
activeSectionId: string activeSectionId: string
authenticateUserFlowRequestedBy: string
# Forward declaration # Forward declaration
proc setActiveSection*(self: Controller, sectionId: string) proc setActiveSection*(self: Controller, sectionId: string)
@ -91,9 +97,7 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_KEYCHAIN_SERVICE_ERROR) do(e:Args): self.events.on(SIGNAL_KEYCHAIN_SERVICE_ERROR) do(e:Args):
let args = KeyChainServiceArg(e) let args = KeyChainServiceArg(e)
# with the following condition we guard unintentional props deletion from the `.ini` file
if self.accountsService.getLoggedInAccount().isValid(): if self.accountsService.getLoggedInAccount().isValid():
singletonInstance.localAccountSettings.removeKey(LS_KEY_STORE_TO_KEYCHAIN)
self.delegate.emitStoringPasswordError(args.errDescription) self.delegate.emitStoringPasswordError(args.errDescription)
self.events.on(SIGNAL_COMMUNITY_JOINED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_JOINED) do(e:Args):
@ -226,6 +230,33 @@ proc init*(self: Controller) =
let args = chat_service.ChatArgs(e) let args = chat_service.ChatArgs(e)
self.delegate.onChatLeft(args.chatId) self.delegate.onChatLeft(args.chatId)
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_FLOW_TERMINATED) do(e: Args):
let args = SharedKeycarModuleFlowTerminatedArgs(e)
if args.uniqueIdentifier != UNIQUE_MAIN_MODULE_IDENTIFIER or
self.authenticateUserFlowRequestedBy.len == 0:
return
self.delegate.onSharedKeycarModuleFlowTerminated(args.lastStepInTheCurrentFlow)
let data = SharedKeycarModuleArgs(uniqueIdentifier: self.authenticateUserFlowRequestedBy,
data: args.data,
keyUid: args.keyUid,
txR: args.txR,
txS: args.txS,
txV: args.txV)
self.authenticateUserFlowRequestedBy = ""
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED, data)
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_DISPLAY_POPUP) do(e: Args):
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_MAIN_MODULE_IDENTIFIER or
self.authenticateUserFlowRequestedBy.len == 0:
return
self.delegate.onDisplayKeycardSharedModuleFlow()
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER) do(e: Args):
let args = SharedKeycarModuleAuthenticationArgs(e)
self.authenticateUserFlowRequestedBy = args.uniqueIdentifier
self.delegate.runAuthenticationPopup(args.keyUid, args.bip44Path, args.txHash)
proc isConnected*(self: Controller): bool = proc isConnected*(self: Controller): bool =
return self.nodeService.isConnected() return self.nodeService.isConnected()

View File

@ -205,6 +205,18 @@ method onStatusUrlRequested*(self: AccessInterface, action: StatusUrlAction, com
method getVerificationRequestFrom*(self: AccessInterface, publicKey: string): VerificationRequest {.base.} = method getVerificationRequestFrom*(self: AccessInterface, publicKey: string): VerificationRequest {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getKeycardSharedModule*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method onDisplayKeycardSharedModuleFlow*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method onSharedKeycarModuleFlowTerminated*(self: AccessInterface, lastStepInTheCurrentFlow: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method runAuthenticationPopup*(self: AccessInterface, keyUid: string, bip44Path: string, txHash: string) {.base.} =
raise newException(ValueError, "No implementation available")
# This way (using concepts) is used only for the modules managed by AppController # This way (using concepts) is used only for the modules managed by AppController
type type
DelegateInterface* = concept c DelegateInterface* = concept c

View File

@ -4,6 +4,7 @@ import io_interface, view, controller, chat_search_item, chat_search_model
import ephemeral_notification_item, ephemeral_notification_model import ephemeral_notification_item, ephemeral_notification_model
import ./communities/models/[pending_request_item, pending_request_model] import ./communities/models/[pending_request_item, pending_request_model]
import ../shared_models/[user_item, member_item, member_model, section_item, section_model, active_section] import ../shared_models/[user_item, member_item, member_model, section_item, section_model, active_section]
import ../shared_modules/keycard_popup/module as keycard_shared_module
import ../../global/app_sections_config as conf import ../../global/app_sections_config as conf
import ../../global/app_signals import ../../global/app_signals
import ../../global/global_singleton import ../../global/global_singleton
@ -73,6 +74,13 @@ type
viewVariant: QVariant viewVariant: QVariant
controller: Controller controller: Controller
channelGroupModules: OrderedTable[string, chat_section_module.AccessInterface] channelGroupModules: OrderedTable[string, chat_section_module.AccessInterface]
events: EventEmitter
keycardService: keycard_service.Service
settingsService: settings_service.Service
privacyService: privacy_service.Service
accountsService: accounts_service.Service
walletAccountService: wallet_account_service.Service
keychainService: keychain_service.Service
walletSectionModule: wallet_section_module.AccessInterface walletSectionModule: wallet_section_module.AccessInterface
browserSectionModule: browser_section_module.AccessInterface browserSectionModule: browser_section_module.AccessInterface
profileSectionModule: profile_section_module.AccessInterface profileSectionModule: profile_section_module.AccessInterface
@ -82,6 +90,7 @@ type
appSearchModule: app_search_module.AccessInterface appSearchModule: app_search_module.AccessInterface
nodeSectionModule: node_section_module.AccessInterface nodeSectionModule: node_section_module.AccessInterface
networksModule: networks_module.AccessInterface networksModule: networks_module.AccessInterface
keycardSharedModule: keycard_shared_module.AccessInterface
moduleLoaded: bool moduleLoaded: bool
statusUrlGroupName: string statusUrlGroupName: string
statusUrlGroupMembers: seq[string] # used only for creating group chat from the status url statusUrlGroupMembers: seq[string] # used only for creating group chat from the status url
@ -145,6 +154,14 @@ proc newModule*[T](
) )
result.moduleLoaded = false result.moduleLoaded = false
result.events = events
result.keycardService = keycardService
result.settingsService = settingsService
result.privacyService = privacyService
result.accountsService = accountsService
result.walletAccountService = walletAccountService
result.keychainService = keychainService
# Submodules # Submodules
result.channelGroupModules = initOrderedTable[string, chat_section_module.AccessInterface]() result.channelGroupModules = initOrderedTable[string, chat_section_module.AccessInterface]()
result.walletSectionModule = wallet_section_module.newModule( result.walletSectionModule = wallet_section_module.newModule(
@ -160,7 +177,7 @@ proc newModule*[T](
result, events, accountsService, settingsService, stickersService, result, events, accountsService, settingsService, stickersService,
profileService, contactsService, aboutService, languageService, privacyService, nodeConfigurationService, profileService, contactsService, aboutService, languageService, privacyService, nodeConfigurationService,
devicesService, mailserversService, chatService, ensService, walletAccountService, generalService, communityService, devicesService, mailserversService, chatService, ensService, walletAccountService, generalService, communityService,
networkService, keycardService networkService, keycardService, keychainService
) )
result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService, networkService) result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService, networkService)
result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService, result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService,
@ -184,6 +201,8 @@ method delete*[T](self: Module[T]) =
self.appSearchModule.delete self.appSearchModule.delete
self.nodeSectionModule.delete self.nodeSectionModule.delete
self.networksModule.delete self.networksModule.delete
if not self.keycardSharedModule.isNil:
self.keycardSharedModule.delete
self.view.delete self.view.delete
self.viewVariant.delete self.viewVariant.delete
self.controller.delete self.controller.delete
@ -927,3 +946,29 @@ method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, commun
cModule.makeChatWithIdActive(chatId) cModule.makeChatWithIdActive(chatId)
break break
method getKeycardSharedModule*[T](self: Module[T]): QVariant =
return self.keycardSharedModule.getModuleAsVariant()
proc createSharedKeycardModule[T](self: Module[T]) =
self.keycardSharedModule = keycard_shared_module.newModule[Module[T]](self, UNIQUE_MAIN_MODULE_IDENTIFIER,
self.events, self.keycardService, self.settingsService, self.privacyService, self.accountsService,
self.walletAccountService, self.keychainService)
proc isSharedKeycardModuleFlowRunning[T](self: Module[T]): bool =
return not self.keycardSharedModule.isNil
method onSharedKeycarModuleFlowTerminated*[T](self: Module[T], lastStepInTheCurrentFlow: bool) =
if self.isSharedKeycardModuleFlowRunning():
self.view.emitDestroyKeycardSharedModuleFlow()
self.keycardSharedModule.delete
self.keycardSharedModule = nil
method runAuthenticationPopup*[T](self: Module[T], keyUid: string, bip44Path: string, txHash: string) =
self.createSharedKeycardModule()
if self.keycardSharedModule.isNil:
return
self.keycardSharedModule.runFlow(keycard_shared_module.FlowType.Authentication, keyUid, bip44Path, txHash)
method onDisplayKeycardSharedModuleFlow*[T](self: Module[T]) =
self.view.emitDisplayKeycardSharedModuleFlow()

View File

@ -9,6 +9,8 @@ import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_modu
logScope: logScope:
topics = "profile-section-keycard-module-controller" topics = "profile-section-keycard-module-controller"
const UNIQUE_SETTING_KEYCARD_MODULE_IDENTIFIER* = "Settings-KeycardModule"
type type
Controller* = ref object of RootObj Controller* = ref object of RootObj
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
@ -25,9 +27,14 @@ proc delete*(self: Controller) =
discard discard
proc init*(self: Controller) = proc init*(self: Controller) =
self.events.on(SignalSharedKeycarModuleFlowTerminated) do(e: Args): self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_FLOW_TERMINATED) do(e: Args):
let args = SharedKeycarModuleFlowTerminatedArgs(e) let args = SharedKeycarModuleFlowTerminatedArgs(e)
if args.uniqueIdentifier != UNIQUE_SETTING_KEYCARD_MODULE_IDENTIFIER:
return
self.delegate.onSharedKeycarModuleFlowTerminated(args.lastStepInTheCurrentFlow) self.delegate.onSharedKeycarModuleFlowTerminated(args.lastStepInTheCurrentFlow)
self.events.on(SignalSharedKeycarModuleDisplayPopup) do(e: Args): self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_DISPLAY_POPUP) do(e: Args):
self.delegate.onDisplayKeycardSharedModuleFlow() let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_SETTING_KEYCARD_MODULE_IDENTIFIER:
return
self.delegate.onDisplayKeycardSharedModuleFlow()

View File

@ -6,9 +6,11 @@ import ../io_interface as delegate_interface
import ../../../../core/eventemitter import ../../../../core/eventemitter
import ../../../../../app_service/service/keycard/service as keycard_service import ../../../../../app_service/service/keycard/service as keycard_service
import ../../../../../app_service/service/settings/service as settings_service
import ../../../../../app_service/service/privacy/service as privacy_service import ../../../../../app_service/service/privacy/service as privacy_service
import ../../../../../app_service/service/accounts/service as accounts_service import ../../../../../app_service/service/accounts/service as accounts_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/keychain/service as keychain_service
import ../../../shared_modules/keycard_popup/module as keycard_shared_module import ../../../shared_modules/keycard_popup/module as keycard_shared_module
@ -26,24 +28,30 @@ type
moduleLoaded: bool moduleLoaded: bool
events: EventEmitter events: EventEmitter
keycardService: keycard_service.Service keycardService: keycard_service.Service
settingsService: settings_service.Service
privacyService: privacy_service.Service privacyService: privacy_service.Service
accountsService: accounts_service.Service accountsService: accounts_service.Service
walletAccountService: wallet_account_service.Service walletAccountService: wallet_account_service.Service
keychainService: keychain_service.Service
keycardSharedModule: keycard_shared_module.AccessInterface keycardSharedModule: keycard_shared_module.AccessInterface
proc newModule*(delegate: delegate_interface.AccessInterface, proc newModule*(delegate: delegate_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
keycardService: keycard_service.Service, keycardService: keycard_service.Service,
settingsService: settings_service.Service,
privacyService: privacy_service.Service, privacyService: privacy_service.Service,
accountsService: accounts_service.Service, accountsService: accounts_service.Service,
walletAccountService: wallet_account_service.Service): Module = walletAccountService: wallet_account_service.Service,
keychainService: keychain_service.Service): Module =
result = Module() result = Module()
result.delegate = delegate result.delegate = delegate
result.events = events result.events = events
result.keycardService = keycardService result.keycardService = keycardService
result.settingsService = settingsService
result.privacyService = privacyService result.privacyService = privacyService
result.accountsService = accountsService result.accountsService = accountsService
result.walletAccountService = walletAccountService result.walletAccountService = walletAccountService
result.keychainService = keychainService
result.view = view.newView(result) result.view = view.newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, events) result.controller = controller.newController(result, events)
@ -74,8 +82,9 @@ method getKeycardSharedModule*(self: Module): QVariant =
return self.keycardSharedModule.getModuleAsVariant() return self.keycardSharedModule.getModuleAsVariant()
proc createSharedKeycardModule(self: Module) = proc createSharedKeycardModule(self: Module) =
self.keycardSharedModule = keycard_shared_module.newModule[Module](self, self.events, self.keycardService, self.keycardSharedModule = keycard_shared_module.newModule[Module](self, UNIQUE_SETTING_KEYCARD_MODULE_IDENTIFIER,
self.privacyService, self.accountsService, self.walletAccountService) self.events, self.keycardService, self.settingsService, self.privacyService, self.accountsService,
self.walletAccountService, self.keychainService)
proc isSharedKeycardModuleFlowRunning(self: Module): bool = proc isSharedKeycardModuleFlowRunning(self: Module): bool =
return not self.keycardSharedModule.isNil return not self.keycardSharedModule.isNil

View File

@ -21,6 +21,7 @@ import ../../../../app_service/service/wallet_account/service as wallet_account_
import ../../../../app_service/service/general/service as general_service import ../../../../app_service/service/general/service as general_service
import ../../../../app_service/service/community/service as community_service import ../../../../app_service/service/community/service as community_service
import ../../../../app_service/service/keycard/service as keycard_service import ../../../../app_service/service/keycard/service as keycard_service
import ../../../../app_service/service/keychain/service as keychain_service
import ./profile/module as profile_module import ./profile/module as profile_module
import ./contacts/module as contacts_module import ./contacts/module as contacts_module
@ -77,7 +78,8 @@ proc newModule*(delegate: delegate_interface.AccessInterface,
generalService: general_service.Service, generalService: general_service.Service,
communityService: community_service.Service, communityService: community_service.Service,
networkService: network_service.Service, networkService: network_service.Service,
keycardService: keycard_service.Service keycardService: keycard_service.Service,
keychainService: keychain_service.Service
): Module = ): Module =
result = Module() result = Module()
result.delegate = delegate result.delegate = delegate
@ -99,8 +101,8 @@ proc newModule*(delegate: delegate_interface.AccessInterface,
result, events, settingsService, ensService, walletAccountService, networkService result, events, settingsService, ensService, walletAccountService, networkService
) )
result.communitiesModule = communities_module.newModule(result, communityService) result.communitiesModule = communities_module.newModule(result, communityService)
result.keycardModule = keycard_module.newModule(result, events, keycardService, privacyService, accountsService, result.keycardModule = keycard_module.newModule(result, events, keycardService, settingsService, privacyService,
walletAccountService) accountsService, walletAccountService, keychainService)
singletonInstance.engine.setRootContextProperty("profileSectionModule", result.viewVariant) singletonInstance.engine.setRootContextProperty("profileSectionModule", result.viewVariant)

View File

@ -217,4 +217,17 @@ QtObject:
proc displayUserProfile*(self:View, publicKey: string) {.signal.} proc displayUserProfile*(self:View, publicKey: string) {.signal.}
proc emitDisplayUserProfileSignal*(self: View, publicKey: string) = proc emitDisplayUserProfileSignal*(self: View, publicKey: string) =
self.displayUserProfile(publicKey) self.displayUserProfile(publicKey)
proc getKeycardSharedModule(self: View): QVariant {.slot.} =
return self.delegate.getKeycardSharedModule()
QtProperty[QVariant] keycardSharedModule:
read = getKeycardSharedModule
proc displayKeycardSharedModuleFlow*(self: View) {.signal.}
proc emitDisplayKeycardSharedModuleFlow*(self: View) =
self.displayKeycardSharedModuleFlow()
proc destroyKeycardSharedModuleFlow*(self: View) {.signal.}
proc emitDestroyKeycardSharedModuleFlow*(self: View) =
self.destroyKeycardSharedModuleFlow()

View File

@ -6,9 +6,11 @@ import ../../../global/global_singleton
import ../../../core/signals/types import ../../../core/signals/types
import ../../../core/eventemitter import ../../../core/eventemitter
import ../../../../app_service/service/keycard/service as keycard_service import ../../../../app_service/service/keycard/service as keycard_service
import ../../../../app_service/service/settings/service as settings_service
import ../../../../app_service/service/privacy/service as privacy_service import ../../../../app_service/service/privacy/service as privacy_service
import ../../../../app_service/service/accounts/service as accounts_service import ../../../../app_service/service/accounts/service as accounts_service
import ../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../app_service/service/keychain/service as keychain_service
logScope: logScope:
topics = "keycard-popup-controller" topics = "keycard-popup-controller"
@ -16,12 +18,17 @@ logScope:
type type
Controller* = ref object of RootObj Controller* = ref object of RootObj
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
uniqueIdentifier: string
events: EventEmitter events: EventEmitter
keycardService: keycard_service.Service keycardService: keycard_service.Service
settingsService: settings_service.Service
privacyService: privacy_service.Service privacyService: privacy_service.Service
accountsService: accounts_service.Service accountsService: accounts_service.Service
walletAccountService: wallet_account_service.Service walletAccountService: wallet_account_service.Service
keychainService: keychain_service.Service
connectionIds: seq[UUID] connectionIds: seq[UUID]
keychainConnectionIds: seq[UUID]
connectionKeycardResponse: UUID
tmpKeycardContainsMetadata: bool tmpKeycardContainsMetadata: bool
tmpPin: string tmpPin: string
tmpPinMatch: bool tmpPinMatch: bool
@ -34,19 +41,25 @@ type
tmpSeedPhraseLength: int tmpSeedPhraseLength: int
proc newController*(delegate: io_interface.AccessInterface, proc newController*(delegate: io_interface.AccessInterface,
uniqueIdentifier: string,
events: EventEmitter, events: EventEmitter,
keycardService: keycard_service.Service, keycardService: keycard_service.Service,
settingsService: settings_service.Service,
privacyService: privacy_service.Service, privacyService: privacy_service.Service,
accountsService: accounts_service.Service, accountsService: accounts_service.Service,
walletAccountService: wallet_account_service.Service): walletAccountService: wallet_account_service.Service,
keychainService: keychain_service.Service):
Controller = Controller =
result = Controller() result = Controller()
result.delegate = delegate result.delegate = delegate
result.uniqueIdentifier = uniqueIdentifier
result.events = events result.events = events
result.keycardService = keycardService result.keycardService = keycardService
result.settingsService = settingsService
result.privacyService = privacyService result.privacyService = privacyService
result.accountsService = accountsService result.accountsService = accountsService
result.walletAccountService = walletAccountService result.walletAccountService = walletAccountService
result.keychainService = keychainService
result.tmpKeycardContainsMetadata = false result.tmpKeycardContainsMetadata = false
result.tmpPinMatch = false result.tmpPinMatch = false
result.tmpSeedPhraseLength = 0 result.tmpSeedPhraseLength = 0
@ -60,19 +73,51 @@ proc serviceApplicable[T](service: T): bool =
serviceName = "WalletAccountService" serviceName = "WalletAccountService"
when (service is privacy_service.Service): when (service is privacy_service.Service):
serviceName = "PrivacyService" serviceName = "PrivacyService"
when (service is settings_service.Service):
serviceName = "SettingsService"
debug "service doesn't meant to be used from the context it's used, check the context shared popup module is used", service=serviceName debug "service doesn't meant to be used from the context it's used, check the context shared popup module is used", service=serviceName
proc disconnect*(self: Controller) = proc disconnectKeycardReponseSignal(self: Controller) =
self.events.disconnect(self.connectionKeycardResponse)
proc connectKeycardReponseSignal(self: Controller) =
self.connectionKeycardResponse = self.events.onWithUUID(SIGNAL_KEYCARD_RESPONSE) do(e: Args):
let args = KeycardArgs(e)
self.delegate.onKeycardResponse(args.flowType, args.flowEvent)
proc connectKeychainSignals*(self: Controller) =
var handlerId = self.events.onWithUUID(SIGNAL_KEYCHAIN_SERVICE_SUCCESS) do(e:Args):
let args = KeyChainServiceArg(e)
self.delegate.keychainObtainedDataSuccess(args.data)
self.keychainConnectionIds.add(handlerId)
handlerId = self.events.onWithUUID(SIGNAL_KEYCHAIN_SERVICE_ERROR) do(e:Args):
let args = KeyChainServiceArg(e)
self.delegate.keychainObtainedDataFailure(args.errDescription, args.errType)
self.keychainConnectionIds.add(handlerId)
proc disconnectKeychainSignals(self: Controller) =
for id in self.keychainConnectionIds:
self.events.disconnect(id)
proc disconnectAll*(self: Controller) =
self.disconnectKeycardReponseSignal()
self.disconnectKeychainSignals()
for id in self.connectionIds: for id in self.connectionIds:
self.events.disconnect(id) self.events.disconnect(id)
proc delete*(self: Controller) = proc delete*(self: Controller) =
self.disconnect() self.disconnectAll()
proc init*(self: Controller) = proc init*(self: Controller) =
let handlerId = self.events.onWithUUID(SignalKeycardResponse) do(e: Args): self.connectKeycardReponseSignal()
let args = KeycardArgs(e)
self.delegate.onKeycardResponse(args.flowType, args.flowEvent) let handlerId = self.events.onWithUUID(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != self.uniqueIdentifier:
return
self.connectKeycardReponseSignal()
self.delegate.onUserAuthenticated(args.data)
self.connectionIds.add(handlerId) self.connectionIds.add(handlerId)
proc getKeycardData*(self: Controller): string = proc getKeycardData*(self: Controller): string =

View File

@ -3,17 +3,38 @@ import ../../../../app/core/eventemitter
from ../../../../app_service/service/keycard/service import KeycardEvent, CardMetadata, KeyDetails from ../../../../app_service/service/keycard/service import KeycardEvent, CardMetadata, KeyDetails
import models/key_pair_item import models/key_pair_item
const SignalSharedKeycarModuleDisplayPopup* = "SignalSharedKeycarModuleDisplayPopup" const SIGNAL_SHARED_KEYCARD_MODULE_DISPLAY_POPUP* = "sharedKeycarModuleDisplayPopup"
const SignalSharedKeycarModuleFlowTerminated* = "sharedKeycarModuleFlowTerminated" const SIGNAL_SHARED_KEYCARD_MODULE_FLOW_TERMINATED* = "sharedKeycarModuleFlowTerminated"
const SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER* = "sharedKeycarModuleAuthenticateUser"
const SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED* = "sharedKeycarModuleUserAuthenticated"
type type
SharedKeycarModuleFlowTerminatedArgs* = ref object of Args SharedKeycarModuleBaseArgs* = ref object of Args
uniqueIdentifier*: string
type
SharedKeycarModuleArgs* = ref object of SharedKeycarModuleBaseArgs
data*: string
keyUid*: string
txR*: string
txS*: string
txV*: string
type
SharedKeycarModuleFlowTerminatedArgs* = ref object of SharedKeycarModuleArgs
lastStepInTheCurrentFlow*: bool lastStepInTheCurrentFlow*: bool
type
SharedKeycarModuleAuthenticationArgs* = ref object of SharedKeycarModuleBaseArgs
keyUid*: string
bip44Path*: string
txHash*: string
type FlowType* {.pure.} = enum type FlowType* {.pure.} = enum
General = "General" General = "General"
FactoryReset = "FactoryReset" FactoryReset = "FactoryReset"
SetupNewKeycard = "SetupNewKeycard" SetupNewKeycard = "SetupNewKeycard"
Authentication = "Authentication"
type type
AccessInterface* {.pure inheritable.} = ref object of RootObj AccessInterface* {.pure inheritable.} = ref object of RootObj

View File

@ -8,9 +8,11 @@ import ../../../global/global_singleton
import ../../../core/eventemitter import ../../../core/eventemitter
import ../../../../app_service/service/keycard/service as keycard_service import ../../../../app_service/service/keycard/service as keycard_service
import ../../../../app_service/service/settings/service as settings_service
import ../../../../app_service/service/privacy/service as privacy_service import ../../../../app_service/service/privacy/service as privacy_service
import ../../../../app_service/service/accounts/service as accounts_service import ../../../../app_service/service/accounts/service as accounts_service
import ../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../app_service/service/keychain/service as keychain_service
export io_interface export io_interface
@ -25,21 +27,26 @@ type
controller: Controller controller: Controller
initialized: bool initialized: bool
tmpLocalState: State # used when flow is run, until response arrives to determine next state appropriatelly tmpLocalState: State # used when flow is run, until response arrives to determine next state appropriatelly
authenticationPopupIsAlreadyRunning: bool
proc newModule*[T](delegate: T, proc newModule*[T](delegate: T,
uniqueIdentifier: string,
events: EventEmitter, events: EventEmitter,
keycardService: keycard_service.Service, keycardService: keycard_service.Service,
settingsService: settings_service.Service,
privacyService: privacy_service.Service, privacyService: privacy_service.Service,
accountsService: accounts_service.Service, accountsService: accounts_service.Service,
walletAccountService: wallet_account_service.Service): walletAccountService: wallet_account_service.Service,
keychainService: keychain_service.Service):
Module[T] = Module[T] =
result = Module[T]() result = Module[T]()
result.delegate = delegate result.delegate = delegate
result.view = view.newView(result) result.view = view.newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, events, keycardService, privacyService, accountsService, result.controller = controller.newController(result, uniqueIdentifier, events, keycardService, settingsService,
walletAccountService) privacyService, accountsService, walletAccountService, keychainService)
result.initialized = false result.initialized = false
result.authenticationPopupIsAlreadyRunning = false
method delete*[T](self: Module[T]) = method delete*[T](self: Module[T]) =
self.view.delete self.view.delete

View File

@ -16,6 +16,8 @@ import ../shared_modules/keycard_popup/io_interface as keycard_shared_module
logScope: logScope:
topics = "startup-controller" topics = "startup-controller"
const UNIQUE_STARTUP_MODULE_IDENTIFIER* = "SartupModule"
type ProfileImageDetails = object type ProfileImageDetails = object
url*: string url*: string
croppedImage*: string croppedImage*: string
@ -110,17 +112,22 @@ proc init*(self: Controller) =
self.delegate.emitObtainingPasswordError(args.errDescription, args.errType) self.delegate.emitObtainingPasswordError(args.errDescription, args.errType)
self.connectionIds.add(handlerId) self.connectionIds.add(handlerId)
handlerId = self.events.onWithUUID(SignalKeycardResponse) do(e: Args): handlerId = self.events.onWithUUID(SIGNAL_KEYCARD_RESPONSE) do(e: Args):
let args = KeycardArgs(e) let args = KeycardArgs(e)
self.delegate.onKeycardResponse(args.flowType, args.flowEvent) self.delegate.onKeycardResponse(args.flowType, args.flowEvent)
self.connectionIds.add(handlerId) self.connectionIds.add(handlerId)
handlerId = self.events.onWithUUID(SignalSharedKeycarModuleFlowTerminated) do(e: Args): handlerId = self.events.onWithUUID(SIGNAL_SHARED_KEYCARD_MODULE_FLOW_TERMINATED) do(e: Args):
let args = SharedKeycarModuleFlowTerminatedArgs(e) let args = SharedKeycarModuleFlowTerminatedArgs(e)
if args.uniqueIdentifier != UNIQUE_STARTUP_MODULE_IDENTIFIER:
return
self.delegate.onSharedKeycarModuleFlowTerminated(args.lastStepInTheCurrentFlow) self.delegate.onSharedKeycarModuleFlowTerminated(args.lastStepInTheCurrentFlow)
self.connectionIds.add(handlerId) self.connectionIds.add(handlerId)
handlerId = self.events.onWithUUID(SignalSharedKeycarModuleDisplayPopup) do(e: Args): handlerId = self.events.onWithUUID(SIGNAL_SHARED_KEYCARD_MODULE_DISPLAY_POPUP) do(e: Args):
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_STARTUP_MODULE_IDENTIFIER:
return
self.delegate.onDisplayKeycardSharedModuleFlow() self.delegate.onDisplayKeycardSharedModuleFlow()
self.connectionIds.add(handlerId) self.connectionIds.add(handlerId)

View File

@ -30,6 +30,7 @@ type
events: EventEmitter events: EventEmitter
keycardService: keycard_service.Service keycardService: keycard_service.Service
accountsService: accounts_service.Service accountsService: accounts_service.Service
keychainService: keychain_service.Service
keycardSharedModule: keycard_shared_module.AccessInterface keycardSharedModule: keycard_shared_module.AccessInterface
proc newModule*[T](delegate: T, proc newModule*[T](delegate: T,
@ -45,6 +46,7 @@ proc newModule*[T](delegate: T,
result.events = events result.events = events
result.keycardService = keycardService result.keycardService = keycardService
result.accountsService = accountsService result.accountsService = accountsService
result.keychainService = keychainService
result.view = view.newView(result) result.view = view.newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, events, generalService, accountsService, keychainService, result.controller = controller.newController(result, events, generalService, accountsService, keychainService,
@ -104,8 +106,9 @@ method getKeycardSharedModule*[T](self: Module[T]): QVariant =
return self.keycardSharedModule.getModuleAsVariant() return self.keycardSharedModule.getModuleAsVariant()
proc createSharedKeycardModule[T](self: Module[T]) = proc createSharedKeycardModule[T](self: Module[T]) =
self.keycardSharedModule = keycard_shared_module.newModule[Module[T]](self, self.events, self.keycardService, self.keycardSharedModule = keycard_shared_module.newModule[Module[T]](self, UNIQUE_STARTUP_MODULE_IDENTIFIER,
privacyService = nil, self.accountsService, walletAccountService = nil) self.events, self.keycardService, settingsService = nil, privacyService = nil, self.accountsService,
walletAccountService = nil, self.keychainService)
proc isSharedKeycardModuleFlowRunning[T](self: Module[T]): bool = proc isSharedKeycardModuleFlowRunning[T](self: Module[T]): bool =
return not self.keycardSharedModule.isNil return not self.keycardSharedModule.isNil