Updated on 2026-08-14

This commit is contained in:
Tangem 2024-03-15 13:30:57 +05:00
parent c1af0daa09
commit 39e8abe1bb
18 changed files with 208 additions and 14 deletions

View file

@ -69,4 +69,12 @@ internal object CardDomainModule {
fun provideIsNeedToBackupUseCase(walletStateHolder: WalletsStateHolder): IsNeedToBackupUseCase {
return IsNeedToBackupUseCase(walletStateHolder)
}
@Provides
@ViewModelScoped
fun provideGetExtendedPublicKeyForCurrencyUseCase(
derivationsRepository: DerivationsRepository,
): GetExtendedPublicKeyForCurrencyUseCase {
return GetExtendedPublicKeyForCurrencyUseCase(derivationsRepository)
}
}

View file

@ -26,6 +26,8 @@ import com.tangem.operations.derivation.DerivationTaskResponse
import com.tangem.operations.derivation.DeriveMultipleWalletPublicKeysTask
import com.tangem.operations.pins.SetUserCodeCommand
import com.tangem.operations.usersetttings.SetUserCodeRecoveryAllowedTask
import com.tangem.crypto.hdWallet.bip32.ExtendedPublicKey
import com.tangem.operations.derivation.DeriveWalletPublicKeyTask
import com.tangem.tap.derivationsFinder
import com.tangem.tap.domain.tasks.product.CreateProductWalletTask
import com.tangem.tap.domain.tasks.product.CreateProductWalletTaskResponse
@ -138,6 +140,17 @@ class TangemSdkManager(
return runTaskAsyncReturnOnMain(DeriveMultipleWalletPublicKeysTask(derivations), cardId)
}
suspend fun deriveExtendedPublicKey(
cardId: String?,
walletPublicKey: ByteArray,
derivation: DerivationPath,
): CompletionResult<ExtendedPublicKey> = withContext(Dispatchers.Main) {
runTaskAsyncReturnOnMain(
DeriveWalletPublicKeyTask(walletPublicKey, derivation),
cardId,
)
}
suspend fun resetToFactorySettings(
cardId: String,
allowsRequestAccessCodeFromRepository: Boolean,

View file

@ -1,12 +1,15 @@
package com.tangem.tap.domain.card
import com.tangem.common.CompletionResult
import com.tangem.common.doOnFailure
import com.tangem.common.doOnSuccess
import com.tangem.common.extensions.ByteArrayKey
import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.crypto.hdWallet.bip32.ExtendedPublicKey
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.card.repository.DerivationsRepository
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.userwallets.UserWalletIdBuilder
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.operations.derivation.ExtendedPublicKeysMap
@ -51,6 +54,28 @@ internal class DefaultDerivationsRepository(
error("This code should never be reached")
}
override suspend fun deriveExtendedPublicKey(
userWalletId: UserWalletId,
derivation: DerivationPath,
): ExtendedPublicKey? {
val userWallet = userWalletsStore.getSyncOrNull(userWalletId) ?: error("User wallet not found")
val walletCard = userWallet.scanResponse.card.wallets.firstOrNull {
UserWalletIdBuilder.scanResponse(userWallet.scanResponse).build()?.value
.contentEquals(userWallet.walletId.value)
} ?: return null
val result = tangemSdkManager.deriveExtendedPublicKey(
cardId = null,
walletPublicKey = walletCard.publicKey,
derivation = derivation,
)
return when (result) {
is CompletionResult.Failure -> throw result.error
is CompletionResult.Success -> result.data
}
}
private suspend fun updatePublicKeys(userWalletId: UserWalletId, keys: DerivedKeys): Result<Unit> {
return runCatching(dispatchers.io) {
userWalletsStore.update(