From b9c1113f8dcf0138e6ef55981bbaf32348351d07 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 30 Mar 2023 10:12:16 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../userWalletList/UserWalletsListError.kt | 4 +-- .../BiometricUserWalletsListManager.kt | 8 +++-- .../BiometricUserWalletsKeysRepository.kt | 33 ++++++++++++------- .../ui/WalletSelectorViewModel.kt | 2 +- .../features/welcome/ui/WelcomeViewModel.kt | 2 +- gradle/dependencies.toml | 4 +-- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/UserWalletsListError.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/UserWalletsListError.kt index 03ec981f62..c73891df83 100644 --- a/app/src/main/java/com/tangem/tap/domain/userWalletList/UserWalletsListError.kt +++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/UserWalletsListError.kt @@ -14,8 +14,8 @@ sealed class UserWalletsListError(code: Int) : TangemError(code) { override val messageResId: Int = R.string.user_wallet_list_error_wallet_already_saved } - object InvalidEncryptionKey : UserWalletsListError(code = 60002) { - override var customMessage: String = "Invalid encryption key" + object EncryptionKeyInvalidated : UserWalletsListError(code = 60002) { + override var customMessage: String = "Encryption key invalidated" } data class BiometricsAuthenticationLockout(val isPermanent: Boolean) : UserWalletsListError(code = 60003) { diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt index 72244a8bf8..ad29020162 100644 --- a/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt @@ -183,7 +183,11 @@ internal class BiometricUserWalletsListManager( return saveEncryptionKeyIfNotNull(userWallet) .flatMap { sensitiveInformationRepository.save(userWallet, encryptionKey = it) } .flatMap { publicInformationRepository.save(userWallet) } - .map { selectedUserWalletRepository.set(userWallet.walletId) } + .map { + if (changeSelectedUserWallet) { + selectedUserWalletRepository.set(userWallet.walletId) + } + } .flatMap { loadModels() } .doOnSuccess { state.update { prevState -> @@ -259,7 +263,7 @@ internal class BiometricUserWalletsListManager( } } .doOnFailure { error -> - if (error is UserWalletsListError.InvalidEncryptionKey) { + if (error is UserWalletsListError.EncryptionKeyInvalidated) { state.update { prevState -> prevState.copy( hasLockedUserWalletsAfterUnlock = true, diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/implementation/BiometricUserWalletsKeysRepository.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/implementation/BiometricUserWalletsKeysRepository.kt index 0307b8b7d4..5d39710ca7 100644 --- a/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/implementation/BiometricUserWalletsKeysRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/implementation/BiometricUserWalletsKeysRepository.kt @@ -46,7 +46,8 @@ internal class BiometricUserWalletsKeysRepository( UserWalletsListError.BiometricsAuthenticationLockout(isPermanent = false) is TangemSdkError.BiometricsAuthenticationPermanentLockout -> UserWalletsListError.BiometricsAuthenticationLockout(isPermanent = true) - is TangemSdkError.InvalidEncryptionKey -> UserWalletsListError.InvalidEncryptionKey + is TangemSdkError.BiometricCryptographyKeyInvalidated -> + UserWalletsListError.EncryptionKeyInvalidated else -> error } } @@ -91,28 +92,36 @@ internal class BiometricUserWalletsKeysRepository( private suspend fun getAllInternal(): CompletionResult> { return getUserWalletsIds() .map { userWalletId -> - // This is possible because the Card SDK cipher key has an expiration time - // If this operation runs more than that expiration time, the user will have to re-authorize - // to receive all keys + // It is possible to request multiple user wallet keys from biometric storage because + // the biometric cryptography key has an expiration time. + // If this operation runs more than that expiration time, then the user will have to re-authorize + // to receive all user wallets encryption keys getEncryptionKey(userWalletId) .flatMapOnFailure { error -> - // If key decryption failed then skip it - if (error is TangemSdkError.EncryptionOperationFailed) { - CompletionResult.Success(data = null) - } else { - CompletionResult.Failure(error) + when (error) { + is TangemSdkError.InvalidBiometricCryptographyKey, + is TangemSdkError.BiometricCryptographyOperationFailed, + -> { + // These errors can be skipped as the user has the option to re-save their wallets + // in case they occur + CompletionResult.Success(data = null) + } + else -> CompletionResult.Failure(error) } } .doOnFailure { error -> when (error) { is TangemSdkError.UserCanceledBiometricsAuthentication -> { - // If the user cancels biometric authentication, cancel the request for all keys + // If the user cancels biometric authentication, then cancel operation with error return CompletionResult.Failure(error) } - is TangemSdkError.InvalidEncryptionKey -> { - if (error.isKeyRegenerated) { + is TangemSdkError.BiometricCryptographyKeyInvalidated -> { + // If the biometric cryptography key was invalidated, + // then delete all user wallets encryption keys and cancel operation with error + getUserWalletsIds().forEach { userWalletId -> deleteEncryptionKey(userWalletId) } + return CompletionResult.Failure(error) } } } diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt index 0bdae60f69..2637e44e3b 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt @@ -196,7 +196,7 @@ internal class WalletSelectorViewModel : ViewModel(), StoreSubscriber WarningModel.KeyInvalidatedWarning( + is UserWalletsListError.EncryptionKeyInvalidated -> WarningModel.KeyInvalidatedWarning( onDismiss = this::dismissWarningDialog, ) else -> currentDialog diff --git a/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt b/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt index 4bbcdf76ea..3687df607c 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt @@ -68,7 +68,7 @@ internal class WelcomeViewModel : ViewModel(), StoreSubscriber { isPermanent = error.isPermanent, onDismiss = this::dismissWarning, ) - is UserWalletsListError.InvalidEncryptionKey -> WarningModel.KeyInvalidatedWarning( + is UserWalletsListError.EncryptionKeyInvalidated -> WarningModel.KeyInvalidatedWarning( onDismiss = this::dismissWarning, ) else -> null diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index b5543ac9e5..556b4d84ca 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -73,8 +73,8 @@ kotlinSerialization = "1.4.1" # region Tangem tangemBlockchainSdk = "develop-204" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds -tangemCardSdk = "develop-218" -# tangemCardSdk = "0.0.1" # Keep it! - used for local builds +tangemCardSdk = "develop-225" +#tangemCardSdk = "0.0.1" # Keep it! - used for local builds # endregion Tangem # region Tools