Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-22 20:31:03 +05:00
parent ed26d23a78
commit f3192b6d27
23 changed files with 413 additions and 46 deletions

View file

@ -15,4 +15,7 @@ dependencies {
/** Domain models */
implementation(projects.domain.models)
/** Tangem libraries (derived public keys types for VA activation) */
implementation(tangemDeps.card.core)
}

View file

@ -0,0 +1,16 @@
package com.tangem.domain.visa.model
import com.tangem.common.extensions.ByteArrayKey
import com.tangem.operations.derivation.ExtendedPublicKeysMap
/**
* Result of deriving the Virtual Account key on the card.
*
* @property address the VA deposit address generated from the derived key
* @property derivedKeys the derived extended public key(s) keyed by the seed wallet public key,
* ready to be persisted into the wallet (see `DerivationsRepository.storeDerivedKeys`)
*/
data class VirtualAccountActivationData(
val address: String,
val derivedKeys: Map<ByteArrayKey, ExtendedPublicKeysMap>,
)

View file

@ -4,11 +4,14 @@ import arrow.core.Either
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.pay.WithdrawalSignatureResult
import com.tangem.domain.visa.model.TangemPayInitialCredentials
import com.tangem.domain.visa.model.VirtualAccountActivationData
interface TangemPayAuthDataSource {
suspend fun produceInitialCredentials(userWallet: UserWallet): Either<Throwable, TangemPayInitialCredentials>
suspend fun produceVirtualAccountData(userWallet: UserWallet): Either<Throwable, VirtualAccountActivationData>
suspend fun getWithdrawalSignature(
userWallet: UserWallet,
hash: String,

View file

@ -0,0 +1,13 @@
package com.tangem.domain.virtualaccount.repository
import com.tangem.domain.models.wallet.UserWalletId
interface VirtualAccountActivationRepository {
/**
* Derives the Virtual Account key on the card (NFC) and persists it into the wallet, so the
* on-chain VA balance can later be fetched without re-deriving. Throws on failure.
*/
@Throws
suspend fun activateVirtualAccount(userWalletId: UserWalletId)
}

View file

@ -0,0 +1,17 @@
package com.tangem.domain.virtualaccount.usecase
import arrow.core.Either
import arrow.core.Either.Companion.catch
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.virtualaccount.repository.VirtualAccountActivationRepository
class ActivateVirtualAccountUseCase(
private val repository: VirtualAccountActivationRepository,
) {
suspend operator fun invoke(userWalletId: UserWalletId): Either<Throwable, Unit> {
return catch {
repository.activateVirtualAccount(userWalletId)
}
}
}

View file

@ -27,6 +27,9 @@ interface ColdMapDerivationsRepository {
derivations: Map<ByteArrayKey, List<DerivationPath>>,
): Pair<UserWallet.Cold, Map<ByteArrayKey, ExtendedPublicKeysMap>>
/** Merges already-derived [keys] into [userWallet]'s stored derivations without deriving on the card. */
fun mergeDerivedKeys(userWallet: UserWallet.Cold, keys: Map<ByteArrayKey, ExtendedPublicKeysMap>): UserWallet.Cold
/** Check if user [userWallet] has missed derivations using map of [Network.ID] with extraDerivationPath */
suspend fun hasMissedDerivations(
userWallet: UserWallet.Cold,

View file

@ -29,6 +29,14 @@ interface DerivationsRepository {
derivations: Map<ByteArrayKey, List<DerivationPath>>,
): Map<ByteArrayKey, ExtendedPublicKeysMap>
/**
* Merges already-derived [derivedKeys] into the wallet's stored derivations and persists it.
* Does NOT derive on the card (no NFC): use it to save a key that was obtained by a dedicated
* card task. Keyed by the seed wallet public key ([ByteArrayKey]).
*/
@Throws
suspend fun storeDerivedKeys(userWalletId: UserWalletId, derivedKeys: Map<ByteArrayKey, ExtendedPublicKeysMap>)
/** Returns already derived extended public keys for the given [seedKey] */
suspend fun getExistingDerivedKeys(userWalletId: UserWalletId, seedKey: ByteArrayKey): ExtendedPublicKeysMap

View file

@ -29,6 +29,9 @@ interface HotMapDerivationsRepository {
derivations: Map<ByteArrayKey, List<DerivationPath>>,
): Pair<UserWallet.Hot, Map<ByteArrayKey, ExtendedPublicKeysMap>>
/** Merges already-derived [keys] into [userWallet]'s stored derivations. */
fun mergeDerivedKeys(userWallet: UserWallet.Hot, keys: Map<ByteArrayKey, ExtendedPublicKeysMap>): UserWallet.Hot
/** Check if user [userWallet] has missed derivations using map of [Network.ID] with extraDerivationPath */
suspend fun hasMissedDerivations(
userWallet: UserWallet.Hot,