Skip to content

Commit

Permalink
fix: retry decryption if fails on getIdentityFromPublicKeyId
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Jan 31, 2025
1 parent 8ad4312 commit 293dfe4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion wallet/src/de/schildbach/wallet/ui/dashpay/PlatformRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import org.bitcoinj.core.*
import org.bitcoinj.crypto.IDeterministicKey
import org.bitcoinj.crypto.KeyCrypterException
import org.bitcoinj.evolution.AssetLockTransaction
import org.bitcoinj.quorums.InstantSendLock
import org.bitcoinj.wallet.AuthenticationKeyChain
Expand Down Expand Up @@ -954,7 +955,14 @@ class PlatformRepo @Inject constructor(

fun getIdentityFromPublicKeyId(): Identity? {
val encryptionKey = getWalletEncryptionKey()
val firstIdentityKey = getBlockchainIdentityKey(0, encryptionKey) ?: return null
val firstIdentityKey = try {
getBlockchainIdentityKey(0, encryptionKey) ?: return null
} catch (e: KeyCrypterException.InvalidCipherText) {
log.info("failure to decrypt identity keychain", e)
log.info("attempt again to obtain the wallet encryption key and the identity")
val encryptionKeyTwo = getWalletEncryptionKey()
getBlockchainIdentityKey(0, encryptionKeyTwo) ?: return null
}

return try {
platform.stateRepository.fetchIdentityFromPubKeyHash(firstIdentityKey.pubKeyHash)
Expand Down

0 comments on commit 293dfe4

Please # to comment.