From 5122815df841d3dc5374ed323e83f97b51c98429 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Thu, 4 May 2023 16:34:00 +0200 Subject: [PATCH] feat(@desktop/wallet): removing wallet account without an authentication Closes: #10569 --- .../profile_section/keycard/controller.nim | 8 +++- .../profile_section/keycard/io_interface.nim | 2 +- .../main/profile_section/keycard/module.nim | 19 +++++--- .../wallet/accounts/controller.nim | 22 ++------- .../wallet/accounts/io_interface.nim | 8 +--- .../wallet/accounts/module.nim | 46 ++----------------- .../profile_section/wallet/accounts/view.nim | 4 +- .../wallet_section/accounts/controller.nim | 23 ++-------- .../wallet_section/accounts/io_interface.nim | 10 +--- .../main/wallet_section/accounts/module.nim | 46 ++----------------- .../main/wallet_section/accounts/view.nim | 4 +- .../main/wallet_section/send/io_interface.nim | 3 -- .../keycard_popup/controller.nim | 6 +-- .../internal/migrating_key_pair_state.nim | 18 ++++---- .../service/accounts/async_tasks.nim | 3 +- src/app_service/service/accounts/service.nim | 3 +- .../service/wallet_account/async_tasks.nim | 6 +-- .../service/wallet_account/service.nim | 33 +++---------- src/backend/accounts.nim | 8 ++-- src/backend/backend.nim | 1 - .../AppLayouts/Profile/stores/WalletStore.qml | 4 +- .../Profile/views/wallet/AccountView.qml | 2 +- ui/app/AppLayouts/Wallet/stores/RootStore.qml | 4 +- .../AppLayouts/Wallet/views/LeftTabView.qml | 4 +- .../popups/RemoveAccountConfirmationPopup.qml | 5 +- vendor/nim-status-go | 2 +- vendor/status-go | 2 +- 27 files changed, 77 insertions(+), 219 deletions(-) diff --git a/src/app/modules/main/profile_section/keycard/controller.nim b/src/app/modules/main/profile_section/keycard/controller.nim index 82d1561a5e..89aa14a22e 100644 --- a/src/app/modules/main/profile_section/keycard/controller.nim +++ b/src/app/modules/main/profile_section/keycard/controller.nim @@ -57,7 +57,7 @@ proc init*(self: Controller) = let args = KeycardActivityArgs(e) if not args.success: return - self.delegate.onKeycardsSynchronized() + self.delegate.rebuildKeycardsList() self.events.on(SIGNAL_KEYCARD_LOCKED) do(e: Args): let args = KeycardActivityArgs(e) @@ -85,6 +85,12 @@ proc init*(self: Controller) = let args = WalletAccountUpdated(e) self.delegate.onWalletAccountUpdated(args.account) + self.events.on(SIGNAL_WALLET_ACCOUNT_SAVED) do(e: Args): + self.delegate.rebuildKeycardsList() + + self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e: Args): + self.delegate.rebuildKeycardsList() + proc getAllMigratedKeyPairs*(self: Controller): seq[KeyPairDto] = return self.walletAccountService.getAllMigratedKeyPairs() diff --git a/src/app/modules/main/profile_section/keycard/io_interface.nim b/src/app/modules/main/profile_section/keycard/io_interface.nim index f36c6e6532..7fa8298186 100644 --- a/src/app/modules/main/profile_section/keycard/io_interface.nim +++ b/src/app/modules/main/profile_section/keycard/io_interface.nim @@ -66,7 +66,7 @@ method runCreateNewPairingCodePopup*(self: AccessInterface, keyUid: string) {.ba method onLoggedInUserImageChanged*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -method onKeycardsSynchronized*(self: AccessInterface) {.base.} = +method rebuildKeycardsList*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") method onNewKeycardSet*(self: AccessInterface, keyPair: KeyPairDto) {.base.} = diff --git a/src/app/modules/main/profile_section/keycard/module.nim b/src/app/modules/main/profile_section/keycard/module.nim index 283bfeefdd..c3eb0059fd 100644 --- a/src/app/modules/main/profile_section/keycard/module.nim +++ b/src/app/modules/main/profile_section/keycard/module.nim @@ -220,14 +220,20 @@ proc buildKeycardItem(self: Module, walletAccounts: seq[WalletAccountDto], keyPa # if there are more then one keycard for a single keypair we don't want to add the same keypair more than once continue knownAccounts.add(account) - if knownAccounts.len == 0: - return nil var item = initKeycardItem(keycardUid = keyPair.keycardUid, keyUid = keyPair.keyUid, - pubKey = knownAccounts[0].publicKey, + pubKey = "", locked = keyPair.keycardLocked, - name = keyPair.keycardName, - derivedFrom = knownAccounts[0].derivedfrom) + name = keyPair.keycardName) + if knownAccounts.len == 0: + if reason == BuildItemReason.MainView: + return nil + item.setPairType(KeyPairType.SeedImport.int) + item.setIcon("keycard") + else: + item.setPubKey(knownAccounts[0].publicKey) + item.setDerivedFrom(knownAccounts[0].derivedfrom) + for ka in knownAccounts: var icon = "" if ka.walletType == WalletTypeDefaultStatusAccount: @@ -277,7 +283,8 @@ method onLoggedInUserImageChanged*(self: Module) = return self.view.keycardDetailsModel().setImage(singletonInstance.userProfile.getPubKey(), singletonInstance.userProfile.getIcon()) -method onKeycardsSynchronized*(self: Module) = +method rebuildKeycardsList*(self: Module) = + self.view.setKeycardItems(@[]) self.buildKeycardList() method onNewKeycardSet*(self: Module, keyPair: KeyPairDto) = diff --git a/src/app/modules/main/profile_section/wallet/accounts/controller.nim b/src/app/modules/main/profile_section/wallet/accounts/controller.nim index 183269cb32..6ab3282644 100644 --- a/src/app/modules/main/profile_section/wallet/accounts/controller.nim +++ b/src/app/modules/main/profile_section/wallet/accounts/controller.nim @@ -3,35 +3,24 @@ import ../../../../../../app_service/service/wallet_account/service as wallet_ac import ../../../../shared_modules/keycard_popup/io_interface as keycard_shared_module -import ../../../../../core/eventemitter - -const UNIQUE_PROFILE_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER* = "ProfileSection-AccountsModule-Authentication" - type Controller* = ref object of RootObj delegate: io_interface.AccessInterface - events: EventEmitter walletAccountService: wallet_account_service.Service proc newController*( delegate: io_interface.AccessInterface, - events: EventEmitter, walletAccountService: wallet_account_service.Service, ): Controller = result = Controller() result.delegate = delegate - result.events = events result.walletAccountService = walletAccountService proc delete*(self: Controller) = discard proc init*(self: Controller) = - self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args): - let args = SharedKeycarModuleArgs(e) - if args.uniqueIdentifier != UNIQUE_PROFILE_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER: - return - self.delegate.onUserAuthenticated(args.pin, args.password, args.keyUid, args.keycardUid) + discard proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = return self.walletAccountService.getWalletAccounts() @@ -39,13 +28,8 @@ proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAcco proc updateAccount*(self: Controller, address: string, accountName: string, color: string, emoji: string) = discard self.walletAccountService.updateWalletAccount(address, accountName, color, emoji) -proc deleteAccount*(self: Controller, address: string, password = "", keyUid = "", keycardUid = "") = - self.walletAccountService.deleteAccount(address, password, keyUid, keycardUid) - -proc authenticateKeyPair*(self: Controller, keyUid = "") = - let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_PROFILE_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER, - keyUid: keyUid) - self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data) +proc deleteAccount*(self: Controller, address: string) = + self.walletAccountService.deleteAccount(address) proc getMigratedKeyPairByKeyUid*(self: Controller, keyUid: string): seq[KeyPairDto] = return self.walletAccountService.getMigratedKeyPairByKeyUid(keyUid) diff --git a/src/app/modules/main/profile_section/wallet/accounts/io_interface.nim b/src/app/modules/main/profile_section/wallet/accounts/io_interface.nim index e67da89757..c6391e10f5 100644 --- a/src/app/modules/main/profile_section/wallet/accounts/io_interface.nim +++ b/src/app/modules/main/profile_section/wallet/accounts/io_interface.nim @@ -16,7 +16,7 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method syncKeycard*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -method deleteAccount*(self: AccessInterface, keyUid: string, address: string) {.base.} = +method deleteAccount*(self: AccessInterface, address: string) {.base.} = raise newException(ValueError, "No implementation available") method refreshWalletAccounts*(self: AccessInterface) {.base.} = @@ -31,11 +31,5 @@ method updateAccount*(self: AccessInterface, address: string, accountName: strin method viewDidLoad*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -method authenticateUser*(self: AccessInterface) {.base.} = - raise newException(ValueError, "No implementation available") - -method onUserAuthenticated*(self: AccessInterface, pin: string, password: string, keyUid: string, keycardUid: string) {.base.} = - raise newException(ValueError, "No implementation available") - method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/profile_section/wallet/accounts/module.nim b/src/app/modules/main/profile_section/wallet/accounts/module.nim index 204b7ca9af..a89ae88a16 100644 --- a/src/app/modules/main/profile_section/wallet/accounts/module.nim +++ b/src/app/modules/main/profile_section/wallet/accounts/module.nim @@ -11,19 +11,6 @@ import ../../../../../../app_service/service/network/service as network_service export io_interface -# TODO: remove it completely if after wallet settings part refactore this is not needed. -type - AuthenticationReason {.pure.} = enum - DeleteAccountAuthentication = 0 - -# TODO: remove it completely if after wallet settings part refactore this is not needed. -type WalletAccountDetails = object - address: string - path: string - addressAccountIsDerivedFrom: string - publicKey: string - keyUid: string - type Module* = ref object of io_interface.AccessInterface delegate: delegate_interface.AccessInterface @@ -33,8 +20,6 @@ type controller: Controller moduleLoaded: bool walletAccountService: wallet_account_service.Service - processingWalletAccount: WalletAccountDetails - authentiactionReason: AuthenticationReason proc newModule*( delegate: delegate_interface.AccessInterface, @@ -48,9 +33,8 @@ proc newModule*( result.walletAccountService = walletAccountService result.view = newView(result) result.viewVariant = newQVariant(result.view) - result.controller = controller.newController(result, events, walletAccountService) + result.controller = controller.newController(result, walletAccountService) result.moduleLoaded = false - result.authentiactionReason = AuthenticationReason.DeleteAccountAuthentication method delete*(self: Module) = self.view.delete @@ -106,29 +90,5 @@ method viewDidLoad*(self: Module) = method updateAccount*(self: Module, address: string, accountName: string, color: string, emoji: string) = self.controller.updateAccount(address, accountName, color, emoji) -proc authenticateActivityForKeyUid(self: Module, keyUid: string, reason: AuthenticationReason) = - self.authentiactionReason = reason - let keyPair = self.controller.getMigratedKeyPairByKeyUid(keyUid) - let keyPairMigratedToKeycard = keyPair.len > 0 - if keyPairMigratedToKeycard: - self.controller.authenticateKeyPair(keyUid) - else: - self.processingWalletAccount.keyUid = singletonInstance.userProfile.getKeyUid() - self.controller.authenticateKeyPair() - -method deleteAccount*(self: Module, keyUid: string, address: string) = - let accountDto = self.controller.getWalletAccount(address) - if accountDto.walletType == WalletTypeWatch: - self.controller.deleteAccount(address) - return - self.processingWalletAccount = WalletAccountDetails(keyUid: keyUid, address: address) - self.authenticateActivityForKeyUid(keyUid, AuthenticationReason.DeleteAccountAuthentication) - -method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: string, keycardUid: string) = - if self.authentiactionReason == AuthenticationReason.DeleteAccountAuthentication: - if self.processingWalletAccount.keyUid != keyUid: - error "cannot resolve key uid of an account being deleted", keyUid=keyUid - return - if password.len == 0: - return - self.controller.deleteAccount(self.processingWalletAccount.address, password, keyUid, keycardUid) \ No newline at end of file +method deleteAccount*(self: Module, address: string) = + self.controller.deleteAccount(address) \ No newline at end of file diff --git a/src/app/modules/main/profile_section/wallet/accounts/view.nim b/src/app/modules/main/profile_section/wallet/accounts/view.nim index 729eb3400f..102f589551 100644 --- a/src/app/modules/main/profile_section/wallet/accounts/view.nim +++ b/src/app/modules/main/profile_section/wallet/accounts/view.nim @@ -44,5 +44,5 @@ QtObject: proc onUpdatedAccount*(self: View, account: Item) = self.accounts.onUpdatedAccount(account) - proc deleteAccount*(self: View, keyUid: string, address: string) {.slot.} = - self.delegate.deleteAccount(keyUid, address) \ No newline at end of file + proc deleteAccount*(self: View, address: string) {.slot.} = + self.delegate.deleteAccount(address) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/accounts/controller.nim b/src/app/modules/main/wallet_section/accounts/controller.nim index 7d4bc37c00..e12a7e1c3a 100644 --- a/src/app/modules/main/wallet_section/accounts/controller.nim +++ b/src/app/modules/main/wallet_section/accounts/controller.nim @@ -5,31 +5,23 @@ import ../../../../../app_service/service/network/service as network_service import ../../../../../app_service/service/currency/service as currency_service import ../../../../../app_service/service/currency/dto as currency_dto -import ../../../../global/global_singleton import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_module -import ../../../../core/eventemitter - -const UNIQUE_WALLET_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER* = "WalletSection-AccountsModule-Authentication" - type Controller* = ref object of RootObj delegate: io_interface.AccessInterface - events: EventEmitter walletAccountService: wallet_account_service.Service networkService: network_service.Service currencyService: currency_service.Service proc newController*( delegate: io_interface.AccessInterface, - events: EventEmitter, walletAccountService: wallet_account_service.Service, networkService: network_service.Service, currencyService: currency_service.Service, ): Controller = result = Controller() result.delegate = delegate - result.events = events result.walletAccountService = walletAccountService result.networkService = networkService result.currencyService = currencyService @@ -38,22 +30,13 @@ proc delete*(self: Controller) = discard proc init*(self: Controller) = - self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args): - let args = SharedKeycarModuleArgs(e) - if args.uniqueIdentifier != UNIQUE_WALLET_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER: - return - self.delegate.onUserAuthenticated(args.pin, args.password, args.keyUid, args.keycardUid) + discard proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = return self.walletAccountService.getWalletAccounts() -proc deleteAccount*(self: Controller, address: string, password = "", keyUid = "", keycardUid = "") = - self.walletAccountService.deleteAccount(address, password, keyUid, keycardUid) - -proc authenticateKeyPair*(self: Controller, keyUid = "") = - let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_WALLET_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER, - keyUid: keyUid) - self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data) +proc deleteAccount*(self: Controller, address: string) = + self.walletAccountService.deleteAccount(address) proc getEnabledChainIds*(self: Controller): seq[int] = return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) diff --git a/src/app/modules/main/wallet_section/accounts/io_interface.nim b/src/app/modules/main/wallet_section/accounts/io_interface.nim index db785d4ed6..3aef70814e 100644 --- a/src/app/modules/main/wallet_section/accounts/io_interface.nim +++ b/src/app/modules/main/wallet_section/accounts/io_interface.nim @@ -13,7 +13,7 @@ method load*(self: AccessInterface) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") -method deleteAccount*(self: AccessInterface, keyUid: string, address: string) {.base.} = +method deleteAccount*(self: AccessInterface, address: string) {.base.} = raise newException(ValueError, "No implementation available") method refreshWalletAccounts*(self: AccessInterface) {.base.} = @@ -26,10 +26,4 @@ method updateAccount*(self: AccessInterface, address: string, accountName: strin # Delegate for the view must be declared here due to use of QtObject and multi # inheritance, which is not well supported in Nim. method viewDidLoad*(self: AccessInterface) {.base.} = - raise newException(ValueError, "No implementation available") - -method authenticateUser*(self: AccessInterface) {.base.} = - raise newException(ValueError, "No implementation available") - -method onUserAuthenticated*(self: AccessInterface, pin: string, password: string, keyUid: string, keycardUid: string) {.base.} = - raise newException(ValueError, "No implementation available") + raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/accounts/module.nim b/src/app/modules/main/wallet_section/accounts/module.nim index fd76f3421f..162ef0a182 100644 --- a/src/app/modules/main/wallet_section/accounts/module.nim +++ b/src/app/modules/main/wallet_section/accounts/module.nim @@ -14,19 +14,6 @@ import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_modu export io_interface -# TODO: remove it completely if after wallet settings part refactore this is not needed. -type - AuthenticationReason {.pure.} = enum - DeleteAccountAuthentication = 0 - -# TODO: remove it completely if after wallet settings part refactore this is not needed. -type WalletAccountDetails = object - address: string - path: string - addressAccountIsDerivedFrom: string - publicKey: string - keyUid: string - type Module* = ref object of io_interface.AccessInterface delegate: delegate_interface.AccessInterface @@ -35,8 +22,6 @@ type controller: Controller moduleLoaded: bool walletAccountService: wallet_account_service.Service - processingWalletAccount: WalletAccountDetails - authentiactionReason: AuthenticationReason proc newModule*( delegate: delegate_interface.AccessInterface, @@ -50,9 +35,8 @@ proc newModule*( result.events = events result.walletAccountService = walletAccountService result.view = newView(result) - result.controller = controller.newController(result, events, walletAccountService, networkService, currencyService) + result.controller = controller.newController(result, walletAccountService, networkService, currencyService) result.moduleLoaded = false - result.authentiactionReason = AuthenticationReason.DeleteAccountAuthentication method delete*(self: Module) = self.view.delete @@ -123,32 +107,8 @@ method viewDidLoad*(self: Module) = self.moduleLoaded = true self.delegate.accountsModuleDidLoad() -proc authenticateActivityForKeyUid(self: Module, keyUid: string, reason: AuthenticationReason) = - self.authentiactionReason = reason - let keyPair = self.controller.getMigratedKeyPairByKeyUid(keyUid) - let keyPairMigratedToKeycard = keyPair.len > 0 - if keyPairMigratedToKeycard: - self.controller.authenticateKeyPair(keyUid) - else: - self.processingWalletAccount.keyUid = singletonInstance.userProfile.getKeyUid() - self.controller.authenticateKeyPair() - -method deleteAccount*(self: Module, keyUid: string, address: string) = - let accountDto = self.controller.getWalletAccount(address) - if accountDto.walletType == WalletTypeWatch: - self.controller.deleteAccount(address) - return - self.processingWalletAccount = WalletAccountDetails(keyUid: keyUid, address: address) - self.authenticateActivityForKeyUid(keyUid, AuthenticationReason.DeleteAccountAuthentication) - -method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: string, keycardUid: string) = - if self.authentiactionReason == AuthenticationReason.DeleteAccountAuthentication: - if self.processingWalletAccount.keyUid != keyUid: - error "cannot resolve key uid of an account being deleted", keyUid=keyUid - return - if password.len == 0: - return - self.controller.deleteAccount(self.processingWalletAccount.address, password, keyUid, keycardUid) +method deleteAccount*(self: Module, address: string) = + self.controller.deleteAccount(address) method updateAccount*(self: Module, address: string, accountName: string, color: string, emoji: string) = self.controller.updateAccount(address, accountName, color, emoji) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/accounts/view.nim b/src/app/modules/main/wallet_section/accounts/view.nim index e4644fbbfb..ccab7249d5 100644 --- a/src/app/modules/main/wallet_section/accounts/view.nim +++ b/src/app/modules/main/wallet_section/accounts/view.nim @@ -40,8 +40,8 @@ QtObject: proc setItems*(self: View, items: seq[Item]) = self.accounts.setItems(items) - proc deleteAccount*(self: View, keyUid: string, address: string) {.slot.} = - self.delegate.deleteAccount(keyUid, address) + proc deleteAccount*(self: View, address: string) {.slot.} = + self.delegate.deleteAccount(address) proc updateAccount(self: View, address: string, accountName: string, color: string, emoji: string) {.slot.} = self.delegate.updateAccount(address, accountName, color, emoji) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/send/io_interface.nim b/src/app/modules/main/wallet_section/send/io_interface.nim index 317e35d153..586afb9db7 100644 --- a/src/app/modules/main/wallet_section/send/io_interface.nim +++ b/src/app/modules/main/wallet_section/send/io_interface.nim @@ -14,9 +14,6 @@ method load*(self: AccessInterface) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") -method deleteAccount*(self: AccessInterface, keyUid: string, address: string) {.base.} = - raise newException(ValueError, "No implementation available") - method refreshWalletAccounts*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/shared_modules/keycard_popup/controller.nim b/src/app/modules/shared_modules/keycard_popup/controller.nim index 8863050f85..e673cf9955 100644 --- a/src/app/modules/shared_modules/keycard_popup/controller.nim +++ b/src/app/modules/shared_modules/keycard_popup/controller.nim @@ -380,12 +380,12 @@ proc verifyPassword*(self: Controller, password: string): bool = return return self.accountsService.verifyPassword(password) -proc convertSelectedKeyPairToKeycardAccount*(self: Controller, password: string) = +proc convertSelectedKeyPairToKeycardAccount*(self: Controller, keycardUid: string, password: string) = if not serviceApplicable(self.accountsService): return let acc = self.accountsService.createAccountFromMnemonic(self.getSeedPhrase(), includeEncryption = true) singletonInstance.localAccountSettings.setStoreToKeychainValue(LS_VALUE_NOT_NOW) - self.accountsService.convertToKeycardAccount(currentPassword = password, + self.accountsService.convertToKeycardAccount(keycardUid, currentPassword = password, newPassword = acc.derivedAccounts.encryption.publicKey) proc getConvertingProfileSuccess*(self: Controller): bool = @@ -631,7 +631,7 @@ proc addMigratedKeyPair*(self: Controller, keyPair: KeyPairDto) = return if not serviceApplicable(self.accountsService): return - self.walletAccountService.addMigratedKeyPairAsync(keyPair, self.getPassword()) + self.walletAccountService.addMigratedKeyPairAsync(keyPair) proc removeMigratedAccountsForKeycard*(self: Controller, keyUid: string, keycardUid: string, accountsToRemove: seq[string]) = if not serviceApplicable(self.walletAccountService): diff --git a/src/app/modules/shared_modules/keycard_popup/internal/migrating_key_pair_state.nim b/src/app/modules/shared_modules/keycard_popup/internal/migrating_key_pair_state.nim index b8e247bf5d..45d569d6d5 100644 --- a/src/app/modules/shared_modules/keycard_popup/internal/migrating_key_pair_state.nim +++ b/src/app/modules/shared_modules/keycard_popup/internal/migrating_key_pair_state.nim @@ -26,7 +26,8 @@ proc doMigration(self: MigratingKeyPairState, controller: Controller) = proc doConversion(self: MigratingKeyPairState, controller: Controller) = let password = controller.getPassword() - controller.convertSelectedKeyPairToKeycardAccount(password) + let selectedKeyPairDto = controller.getSelectedKeyPairDto() + controller.convertSelectedKeyPairToKeycardAccount(selectedKeyPairDto.keycardUid, password) proc runStoreMetadataFlow(self: MigratingKeyPairState, controller: Controller) = let selectedKeyPairDto = controller.getSelectedKeyPairDto() @@ -48,12 +49,6 @@ method executePreSecondaryStateCommand*(self: MigratingKeyPairState, controller: let password = controller.getPassword() self.authenticationOk = controller.verifyPassword(password) if self.authenticationOk: - self.doMigration(controller) - return - if not self.addingMigratedKeypairDone: - self.addingMigratedKeypairDone = true - self.addingMigratedKeypairOk = controller.getAddingMigratedKeypairSuccess() - if self.addingMigratedKeypairOk: self.doConversion(controller) return if not self.profileConversionDone: @@ -70,9 +65,12 @@ method executePreSecondaryStateCommand*(self: MigratingKeyPairState, controller: method getNextSecondaryState*(self: MigratingKeyPairState, controller: Controller): State = if self.flowType == FlowType.SetupNewKeycard: - if controller.getSelectedKeyPairIsProfile() and self.authenticationDone and not self.authenticationOk or - self.addingMigratedKeypairDone and not self.addingMigratedKeypairOk or - self.profileConversionDone and not self.profileConversionOk: + if controller.getSelectedKeyPairIsProfile(): + if self.authenticationDone and not self.authenticationOk or + self.profileConversionDone and not self.profileConversionOk: + return createState(StateType.KeyPairMigrateFailure, self.flowType, nil) + else: + if self.addingMigratedKeypairDone and not self.addingMigratedKeypairOk: return createState(StateType.KeyPairMigrateFailure, self.flowType, nil) method resolveKeycardNextState*(self: MigratingKeyPairState, keycardFlowType: string, keycardEvent: KeycardEvent, diff --git a/src/app_service/service/accounts/async_tasks.nim b/src/app_service/service/accounts/async_tasks.nim index bd6e3cf051..910453a2d8 100644 --- a/src/app_service/service/accounts/async_tasks.nim +++ b/src/app_service/service/accounts/async_tasks.nim @@ -6,6 +6,7 @@ type ConvertToKeycardAccountTaskArg* = ref object of QObjectTaskArg accountDataJson: JsonNode settingsJson: JsonNode + keycardUid: string hashedCurrentPassword: string newPassword: string @@ -13,7 +14,7 @@ const convertToKeycardAccountTask*: Task = proc(argEncoded: string) {.gcsafe, ni let arg = decode[ConvertToKeycardAccountTaskArg](argEncoded) try: let response = status_account.convertToKeycardAccount(arg.accountDataJson, arg.settingsJson, - arg.hashedCurrentPassword, arg.newPassword) + arg.keycardUid, arg.hashedCurrentPassword, arg.newPassword) arg.finish(response) except Exception as e: error "error converting profile keypair: ", message = e.msg diff --git a/src/app_service/service/accounts/service.nim b/src/app_service/service/accounts/service.nim index 4e7182ebb3..c3f7b18c09 100644 --- a/src/app_service/service/accounts/service.nim +++ b/src/app_service/service/accounts/service.nim @@ -766,7 +766,7 @@ QtObject: error "error: ", procName="loginAccountKeycard", errName = e.name, errDesription = e.msg return e.msg - proc convertToKeycardAccount*(self: Service, currentPassword: string, newPassword: string) = + proc convertToKeycardAccount*(self: Service, keycardUid, currentPassword: string, newPassword: string) = var accountDataJson = %* { "key-uid": self.getLoggedInAccount().keyUid, "kdfIterations": KDF_ITERATIONS @@ -787,6 +787,7 @@ QtObject: slot: "onConvertToKeycardAccount", accountDataJson: accountDataJson, settingsJson: settingsJson, + keycardUid: keycardUid, hashedCurrentPassword: hashedCurrentPassword, newPassword: newPassword ) diff --git a/src/app_service/service/wallet_account/async_tasks.nim b/src/app_service/service/wallet_account/async_tasks.nim index 7b0c3cfa7d..20fd9f470f 100644 --- a/src/app_service/service/wallet_account/async_tasks.nim +++ b/src/app_service/service/wallet_account/async_tasks.nim @@ -91,8 +91,7 @@ const prepareTokensTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = type AddMigratedKeyPairTaskArg* = ref object of QObjectTaskArg - keyPair: KeyPairDto - password: string + keyPair: KeyPairDto const addMigratedKeyPairTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[AddMigratedKeyPairTaskArg](argEncoded) @@ -101,8 +100,7 @@ const addMigratedKeyPairTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall arg.keyPair.keycardUid, arg.keyPair.keycardName, arg.keyPair.keyUid, - arg.keyPair.accountsAddresses, - arg.password + arg.keyPair.accountsAddresses ) let success = responseHasNoErrors("addMigratedKeyPairOrAddAccountsIfKeyPairIsAdded", response) let responseJson = %*{ diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index a217ce5535..6d012bcdd1 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -465,25 +465,13 @@ QtObject: error "error: ", procName="getRandomMnemonic", errName=e.name, errDesription=e.msg return "" - proc deleteAccount*(self: Service, address: string, password: string, keyUid: string, keycardUid: string) = + proc deleteAccount*(self: Service, address: string) = try: - let isKeycardAccount = keycardUid.len > 0 - var finalPassword = password - if not isKeycardAccount: - finalPassword = utils.hashPassword(password) - let response = status_go_accounts.deleteAccount(address, finalPassword) + let response = status_go_accounts.deleteAccount(address) if not response.error.isNil: error "status-go error", procName="deleteAccount", errCode=response.error.code, errDesription=response.error.message return self.removeAccountFromLocalStoreAndNotify(address) - if isKeycardAccount: - self.removeMigratedAccountsForKeycard(keyUid, keycardUid, @[address]) - let accounts = self.getAccountsByKeyUID(keyUID) - if accounts.len == 0: - let allKnownKeycards = self.getAllKnownKeycards() - for kc in allKnownKeycards: - if kc.keyUid == keyUid: - self.removeMigratedAccountsForKeycard(kc.keyUid, kc.keycardUid, kc.accountsAddresses) except Exception as e: error "error: ", procName="deleteAccount", errName = e.name, errDesription = e.msg @@ -691,18 +679,12 @@ QtObject: return 0.0 - proc addMigratedKeyPairAsync*(self: Service, keyPair: KeyPairDto, password = "") = - # Providing a password corresponding local keystore file will be removed as well, though - # in some contexts we just need to add keypair to the db, so password is not needed. - var hashedPassword = "" - if password.len > 0: - hashedPassword = utils.hashPassword(password) + proc addMigratedKeyPairAsync*(self: Service, keyPair: KeyPairDto) = let arg = AddMigratedKeyPairTaskArg( tptr: cast[ByteAddress](addMigratedKeyPairTask), vptr: cast[ByteAddress](self.vptr), slot: "onMigratedKeyPairAdded", - keyPair: keyPair, - password: hashedPassword + keyPair: keyPair ) self.threadpool.start(arg) @@ -728,16 +710,13 @@ QtObject: error "error handilng migrated keypair response", errDesription=e.msg self.emitAddKeycardAddAccountsChange(success = false, KeyPairDto()) - proc addMigratedKeyPair*(self: Service, keyPair: KeyPairDto, password = ""): bool = - # Providing a password corresponding local keystore file will be removed as well, though - # in some contexts we just need to add keypair to the db, so password is not needed. + proc addMigratedKeyPair*(self: Service, keyPair: KeyPairDto): bool = try: let response = backend.addMigratedKeyPairOrAddAccountsIfKeyPairIsAdded( keyPair.keycardUid, keyPair.keycardName, keyPair.keyUid, - keyPair.accountsAddresses, - password + keyPair.accountsAddresses ) result = responseHasNoErrors("addMigratedKeyPair", response) if result: diff --git a/src/backend/accounts.nim b/src/backend/accounts.nim index 0c07426d7b..95587919f9 100644 --- a/src/backend/accounts.nim +++ b/src/backend/accounts.nim @@ -25,8 +25,8 @@ proc getAccountsByKeyUID*(keyUid: string): RpcResponse[JsonNode] {.raises: [Exce let payload = %* [keyUid] return core.callPrivateRPC("accounts_getAccountsByKeyUID", payload) -proc deleteAccount*(address: string, password: string): RpcResponse[JsonNode] {.raises: [Exception].} = - let payload = %* [address, password] +proc deleteAccount*(address: string): RpcResponse[JsonNode] {.raises: [Exception].} = + let payload = %* [address] return core.callPrivateRPC("accounts_deleteAccount", payload) ## Adds a new account and creates a Keystore file if password is provided, otherwise it only creates a new account. Notifies paired devices. @@ -312,10 +312,10 @@ proc saveAccountAndLoginWithKeycard*(chatKey, password: string, account, subacco error "error doing rpc request", methodName = "saveAccountAndLogin", exception=e.msg raise newException(RpcException, e.msg) -proc convertToKeycardAccount*(account: JsonNode, settings: JsonNode, password: string, newPassword: string): +proc convertToKeycardAccount*(account: JsonNode, settings: JsonNode, keycardUid: string, password: string, newPassword: string): RpcResponse[JsonNode] {.raises: [Exception].} = try: - let response = status_go.convertToKeycardAccount($account, $settings, password, newPassword) + let response = status_go.convertToKeycardAccount($account, $settings, keycardUid, password, newPassword) result.result = Json.decode(response, JsonNode) except RpcException as e: diff --git a/src/backend/backend.nim b/src/backend/backend.nim index 1c1366cfa2..c08b0f9d16 100644 --- a/src/backend/backend.nim +++ b/src/backend/backend.nim @@ -193,7 +193,6 @@ rpc(addMigratedKeyPairOrAddAccountsIfKeyPairIsAdded, "accounts"): keyPairName: string keyUid: string accountAddresses: seq[string] - password: string rpc(removeMigratedAccountsForKeycard, "accounts"): keycardUid: string diff --git a/ui/app/AppLayouts/Profile/stores/WalletStore.qml b/ui/app/AppLayouts/Profile/stores/WalletStore.qml index a993809af6..bad868400f 100644 --- a/ui/app/AppLayouts/Profile/stores/WalletStore.qml +++ b/ui/app/AppLayouts/Profile/stores/WalletStore.qml @@ -23,8 +23,8 @@ QtObject { property var accounts: Global.appIsReady? accountsModule.accounts : null - function deleteAccount(keyUid, address) { - return accountsModule.deleteAccount(keyUid, address) + function deleteAccount(address) { + return accountsModule.deleteAccount(address) } function updateAccount(address, accountName, color, emoji) { diff --git a/ui/app/AppLayouts/Profile/views/wallet/AccountView.qml b/ui/app/AppLayouts/Profile/views/wallet/AccountView.qml index 6a4d17c275..4117d692af 100644 --- a/ui/app/AppLayouts/Profile/views/wallet/AccountView.qml +++ b/ui/app/AppLayouts/Profile/views/wallet/AccountView.qml @@ -161,7 +161,7 @@ Item { onConfirmButtonClicked: { confirmationPopup.close(); root.goBack(); - root.walletStore.deleteAccount(root.account.keyUid, root.account.address); + root.walletStore.deleteAccount(root.account.address); } } diff --git a/ui/app/AppLayouts/Wallet/stores/RootStore.qml b/ui/app/AppLayouts/Wallet/stores/RootStore.qml index 1396127889..bebe2e766d 100644 --- a/ui/app/AppLayouts/Wallet/stores/RootStore.qml +++ b/ui/app/AppLayouts/Wallet/stores/RootStore.qml @@ -132,8 +132,8 @@ QtObject { walletSection.setFilterAddress(address) } - function deleteAccount(keyUid, address) { - return walletSectionAccounts.deleteAccount(keyUid, address) + function deleteAccount(address) { + return walletSectionAccounts.deleteAccount(address) } function updateCurrentAccount(address, accountName, color, emoji) { diff --git a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml index fd1b859f57..6cc91b3e8b 100644 --- a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml @@ -88,7 +88,6 @@ Rectangle { width: 400 simple: removeAccountConfirmation.simple - accountKeyUid: removeAccountConfirmation.accountKeyUid accountName: removeAccountConfirmation.accountName accountAddress: removeAccountConfirmation.accountAddress accountDerivationPath: removeAccountConfirmation.accountDerivationPath @@ -99,7 +98,7 @@ Rectangle { onRemoveAccount: { close() - RootStore.deleteAccount(keyUid, address) + RootStore.deleteAccount(address) } } @@ -303,7 +302,6 @@ Rectangle { onDeleteAccountClicked: { removeAccountConfirmation.simple = model.walletType === Constants.watchWalletType || model.walletType === Constants.keyWalletType - removeAccountConfirmation.accountKeyUid = model.keyUid removeAccountConfirmation.accountName = model.name removeAccountConfirmation.accountAddress = model.address removeAccountConfirmation.accountDerivationPath = model.path diff --git a/ui/imports/shared/popups/RemoveAccountConfirmationPopup.qml b/ui/imports/shared/popups/RemoveAccountConfirmationPopup.qml index 3740d9afc5..bcd47e78b4 100644 --- a/ui/imports/shared/popups/RemoveAccountConfirmationPopup.qml +++ b/ui/imports/shared/popups/RemoveAccountConfirmationPopup.qml @@ -14,12 +14,11 @@ StatusModal { id: root required property bool simple - required property string accountKeyUid required property string accountName required property string accountAddress required property string accountDerivationPath - signal removeAccount(string keyUid, string address) + signal removeAccount(string address) header.title: qsTr("Remove %1").arg(root.accountName) focus: visible @@ -34,7 +33,7 @@ StatusModal { if (!root.simple && !derivationPathWritten.checked) { return } - root.removeAccount(root.accountKeyUid, root.accountAddress) + root.removeAccount(root.accountAddress) } } diff --git a/vendor/nim-status-go b/vendor/nim-status-go index 534c04dc73..934096fe3f 160000 --- a/vendor/nim-status-go +++ b/vendor/nim-status-go @@ -1 +1 @@ -Subproject commit 534c04dc737f681ef49207e1f183e9fc53647fd5 +Subproject commit 934096fe3f3ffb3478d6aaac1a775f75abded0a6 diff --git a/vendor/status-go b/vendor/status-go index c5a8b40d9c..31144ed5a3 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit c5a8b40d9c8b7a0104ea9894b07eb3ca42b530af +Subproject commit 31144ed5a38589fd129945b634f54e800b39645a