Updated on 2026-08-14
This commit is contained in:
parent
22e6daa5d6
commit
b9c1113f8d
6 changed files with 33 additions and 20 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<List<UserWalletEncryptionKey>> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ internal class WalletSelectorViewModel : ViewModel(), StoreSubscriber<WalletSele
|
|||
isPermanent = error.isPermanent,
|
||||
onDismiss = this::dismissWarningDialog,
|
||||
)
|
||||
is UserWalletsListError.InvalidEncryptionKey -> WarningModel.KeyInvalidatedWarning(
|
||||
is UserWalletsListError.EncryptionKeyInvalidated -> WarningModel.KeyInvalidatedWarning(
|
||||
onDismiss = this::dismissWarningDialog,
|
||||
)
|
||||
else -> currentDialog
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ internal class WelcomeViewModel : ViewModel(), StoreSubscriber<WelcomeState> {
|
|||
isPermanent = error.isPermanent,
|
||||
onDismiss = this::dismissWarning,
|
||||
)
|
||||
is UserWalletsListError.InvalidEncryptionKey -> WarningModel.KeyInvalidatedWarning(
|
||||
is UserWalletsListError.EncryptionKeyInvalidated -> WarningModel.KeyInvalidatedWarning(
|
||||
onDismiss = this::dismissWarning,
|
||||
)
|
||||
else -> null
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue