Updated on 2026-08-14

This commit is contained in:
Tangem 2025-01-09 13:04:15 +03:00
parent edfe927c7c
commit 820578708c
17 changed files with 290 additions and 1 deletions

View file

@ -0,0 +1,70 @@
package com.tangem.data.visa
import com.tangem.datasource.api.visa.TangemVisaAuthApi
import com.tangem.domain.visa.model.VisaAuthChallenge
import com.tangem.domain.visa.model.VisaAuthSession
import com.tangem.domain.visa.model.VisaAuthSignedChallenge
import com.tangem.domain.visa.model.VisaAuthTokens
import com.tangem.domain.visa.repository.VisaAuthRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.withContext
import javax.inject.Inject
internal class DefaultVisaAuthRepository @Inject constructor(
private val visaAuthApi: TangemVisaAuthApi,
private val dispatchers: CoroutineDispatcherProvider,
) : VisaAuthRepository {
override suspend fun getCardAuthChallenge(cardId: String, cardPublicKey: String): VisaAuthChallenge.Card =
withContext(dispatchers.io) {
val response = visaAuthApi.generateNonceByCard(
cardId = cardId,
cardPublicKey = cardPublicKey,
)
VisaAuthChallenge.Card(
challenge = response.nonce,
session = VisaAuthSession(response.sessionId),
)
}
override suspend fun getCustomerWalletAuthChallenge(
cardId: String,
walletPublicKey: String,
): VisaAuthChallenge.Wallet = withContext(dispatchers.io) {
val response = visaAuthApi.generateNonceByWalletAddress(
customerId = cardId,
customerWalletAddress = walletPublicKey,
)
VisaAuthChallenge.Wallet(
challenge = response.nonce,
session = VisaAuthSession(response.sessionId),
)
}
override suspend fun getAccessTokens(signedChallenge: VisaAuthSignedChallenge): VisaAuthTokens =
withContext(dispatchers.io) {
val response = when (signedChallenge) {
is VisaAuthSignedChallenge.ByCardPublicKey -> {
visaAuthApi.getAccessToken(
sessionId = signedChallenge.challenge.session.sessionId,
signature = signedChallenge.signature,
salt = signedChallenge.salt,
)
}
is VisaAuthSignedChallenge.ByWallet -> {
visaAuthApi.getAccessToken(
sessionId = signedChallenge.challenge.session.sessionId,
signature = signedChallenge.signature,
salt = null,
)
}
}
VisaAuthTokens(
accessToken = response.accessToken,
refreshToken = response.refreshToken,
)
}
}

View file

@ -1,7 +1,10 @@
package com.tangem.data.visa.di
import com.tangem.data.visa.DefaultVisaAuthRepository
import com.tangem.data.visa.DummyVisaRepository
import com.tangem.domain.visa.repository.VisaAuthRepository
import com.tangem.domain.visa.repository.VisaRepository
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@ -21,4 +24,13 @@ internal object VisaDataModule {
): VisaRepository {
return implementedVisaRepository.getOrNull() ?: DummyVisaRepository()
}
}
@Module
@InstallIn(SingletonComponent::class)
internal interface VisaDataBindsModule {
@Binds
@Singleton
fun bindVisaAuthRepository(repository: DefaultVisaAuthRepository): VisaAuthRepository
}