diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/DelegatedKeystoreManager.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/DelegatedKeystoreManager.kt index 6073f2de68..3c548bd255 100644 --- a/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/DelegatedKeystoreManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/DelegatedKeystoreManager.kt @@ -8,11 +8,15 @@ internal class DelegatedKeystoreManager( private val keystoreManagerProvider: Provider, ) : KeystoreManager { - override suspend fun authenticateAndGetKey(keyAlias: String): SecretKey? { - return keystoreManagerProvider().authenticateAndGetKey(keyAlias) + override suspend fun get(keyAlias: String): SecretKey? { + return keystoreManagerProvider().get(keyAlias) } - override suspend fun storeKey(keyAlias: String, key: SecretKey) { - keystoreManagerProvider().storeKey(keyAlias, key) + override suspend fun get(keyAliases: Collection): Map { + return keystoreManagerProvider().get(keyAliases) + } + + override suspend fun store(keyAlias: String, key: SecretKey) { + return keystoreManagerProvider().store(keyAlias, key) } } \ No newline at end of file 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 17c733dd35..0b06c9565f 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 @@ -81,41 +81,38 @@ internal class BiometricUserWalletsKeysRepository( } private suspend fun getAllInternal(): CompletionResult> { - return getUserWalletsIds() - .map { userWalletId -> - getEncryptionKey(userWalletId) - .doOnFailure { error -> - when (error) { - is TangemSdkError.UserCanceledAuthentication -> { - // If the user cancels biometric authentication, then cancel operation with error - return CompletionResult.Failure(error) - } - is TangemSdkError.KeystoreInvalidated -> { - // 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 catching { + val userWalletIds = getUserWalletsIds() - return CompletionResult.Failure(error) - } + getEncryptionKeys(userWalletIds) + } + .doOnFailure { error -> + when (error) { + is TangemSdkError.KeystoreInvalidated -> { + // If the biometric cryptography key was invalidated, then delete all encryption keys + getUserWalletsIds().forEach { userWalletId -> + deleteEncryptionKey(userWalletId) } } - } - .fold(listOf()) { acc, data -> - if (data != null) acc + data else acc + else -> Unit + } } } - private suspend fun getEncryptionKey(userWalletId: UserWalletId): CompletionResult { - return catching { authenticatedStorage.get(StorageKey.UserWalletEncryptionKey(userWalletId).name) } - .map { it.decodeToKey() } + private suspend fun getEncryptionKeys(userWalletsIds: List): List { + val keys = userWalletsIds.map { userWalletId -> + StorageKey.UserWalletEncryptionKey(userWalletId).name + } + + return authenticatedStorage.get(keys).mapNotNull { (_, encodedData) -> + encodedData.decodeToKey() + } } private suspend fun storeEncryptionKey(encryptionKey: UserWalletEncryptionKey): CompletionResult { return catching { authenticatedStorage.store( - key = StorageKey.UserWalletEncryptionKey(encryptionKey.walletId).name, + keyAlias = StorageKey.UserWalletEncryptionKey(encryptionKey.walletId).name, data = encryptionKey.encode(), ) } diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index e8e2ee6152..9404d9c15c 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -85,9 +85,9 @@ web3j = "4.10.1" # endregion Other libraries # region Tangem -tangemBlockchainSdk = "release-app_5.7-504" +tangemBlockchainSdk = "release-app_5.7-506" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds -tangemCardSdk = "release-app_5.7-329" +tangemCardSdk = "release-app_5.7-330" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^ # endregion Tangem