Updated on 2026-08-14
This commit is contained in:
parent
098681020d
commit
891babfce6
7 changed files with 92 additions and 29 deletions
|
|
@ -21,6 +21,7 @@ import com.tangem.domain.wallets.models.UserWallet
|
|||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.operations.derivation.ExtendedPublicKeysMap
|
||||
import com.tangem.tap.domain.sdk.TangemSdkManager
|
||||
import com.tangem.tap.domain.tasks.UserWalletIdPreflightReadFilter
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
|
@ -92,15 +93,20 @@ internal class DefaultDerivationsRepository(
|
|||
}
|
||||
|
||||
override suspend fun derivePublicKeys(userWalletId: UserWalletId, derivations: Derivations): DerivedKeys {
|
||||
tangemSdkManager.derivePublicKeys(cardId = null, derivations = derivations)
|
||||
.doOnSuccess { response ->
|
||||
updatePublicKeys(userWalletId = userWalletId, keys = response.entries)
|
||||
.doOnSuccess {
|
||||
validateDerivations(scanResponse = it.scanResponse, derivations = derivations)
|
||||
return response.entries
|
||||
}
|
||||
.doOnFailure { throw it }
|
||||
}
|
||||
// todo replace it in task [REDACTED_JIRA]
|
||||
val preflightReadFilter = UserWalletIdPreflightReadFilter(userWalletId)
|
||||
tangemSdkManager.derivePublicKeys(
|
||||
cardId = null,
|
||||
derivations = derivations,
|
||||
preflightReadFilter = preflightReadFilter,
|
||||
).doOnSuccess { response ->
|
||||
updatePublicKeys(userWalletId = userWalletId, keys = response.entries)
|
||||
.doOnSuccess {
|
||||
validateDerivations(scanResponse = it.scanResponse, derivations = derivations)
|
||||
return response.entries
|
||||
}
|
||||
.doOnFailure { throw it }
|
||||
}
|
||||
.doOnFailure { throw it }
|
||||
|
||||
error("This code should never be reached")
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import com.tangem.domain.models.scan.CardDTO
|
|||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.operations.derivation.DerivationTaskResponse
|
||||
import com.tangem.operations.preflightread.PreflightReadFilter
|
||||
import com.tangem.operations.wallet.CreateWalletResponse
|
||||
import com.tangem.tap.domain.tasks.product.CreateProductWalletTaskResponse
|
||||
|
||||
|
|
@ -59,6 +60,7 @@ interface TangemSdkManager {
|
|||
suspend fun derivePublicKeys(
|
||||
cardId: String?,
|
||||
derivations: Map<ByteArrayKey, List<DerivationPath>>,
|
||||
preflightReadFilter: PreflightReadFilter?,
|
||||
): CompletionResult<DerivationTaskResponse>
|
||||
|
||||
suspend fun deriveExtendedPublicKey(
|
||||
|
|
@ -99,6 +101,7 @@ interface TangemSdkManager {
|
|||
)
|
||||
suspend fun <T> runTaskAsync(
|
||||
runnable: CardSessionRunnable<T>,
|
||||
preflightReadFilter: PreflightReadFilter?,
|
||||
cardId: String? = null,
|
||||
initialMessage: Message? = null,
|
||||
accessCode: String? = null,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.tangem.operations.derivation.DerivationTaskResponse
|
|||
import com.tangem.operations.derivation.DeriveMultipleWalletPublicKeysTask
|
||||
import com.tangem.operations.derivation.DeriveWalletPublicKeyTask
|
||||
import com.tangem.operations.pins.SetUserCodeCommand
|
||||
import com.tangem.operations.preflightread.PreflightReadFilter
|
||||
import com.tangem.operations.usersetttings.SetUserCodeRecoveryAllowedTask
|
||||
import com.tangem.operations.wallet.CreateWalletResponse
|
||||
import com.tangem.tap.derivationsFinder
|
||||
|
|
@ -146,6 +147,7 @@ class DefaultTangemSdkManager(
|
|||
cardId = scanResponse.card.cardId,
|
||||
initialMessage = Message(resources.getString(R.string.initial_message_create_wallet_body)),
|
||||
iconScanRes = if (scanResponse.cardTypesResolver.isRing()) R.drawable.img_hand_scan_ring else null,
|
||||
preflightReadFilter = null,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -161,15 +163,16 @@ class DefaultTangemSdkManager(
|
|||
return CompletionResult.Failure(e)
|
||||
}
|
||||
return runTaskAsync(
|
||||
CreateProductWalletTask(
|
||||
runnable = CreateProductWalletTask(
|
||||
cardTypesResolver = scanResponse.cardTypesResolver,
|
||||
derivationStyleProvider = scanResponse.derivationStyleProvider,
|
||||
mnemonic = defaultMnemonic,
|
||||
passphrase = passphrase,
|
||||
shouldReset = shouldReset,
|
||||
),
|
||||
scanResponse.card.cardId,
|
||||
Message(resources.getString(R.string.initial_message_create_wallet_body)),
|
||||
cardId = scanResponse.card.cardId,
|
||||
initialMessage = Message(resources.getString(R.string.initial_message_create_wallet_body)),
|
||||
preflightReadFilter = null,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -184,8 +187,13 @@ class DefaultTangemSdkManager(
|
|||
override suspend fun derivePublicKeys(
|
||||
cardId: String?,
|
||||
derivations: Map<ByteArrayKey, List<DerivationPath>>,
|
||||
preflightReadFilter: PreflightReadFilter?,
|
||||
): CompletionResult<DerivationTaskResponse> {
|
||||
return runTaskAsyncReturnOnMain(DeriveMultipleWalletPublicKeysTask(derivations), cardId)
|
||||
return runTaskAsyncReturnOnMain(
|
||||
runnable = DeriveMultipleWalletPublicKeysTask(derivations),
|
||||
cardId = cardId,
|
||||
preflightReadFilter = preflightReadFilter,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun deriveExtendedPublicKey(
|
||||
|
|
@ -291,13 +299,21 @@ class DefaultTangemSdkManager(
|
|||
|
||||
override suspend fun <T> runTaskAsync(
|
||||
runnable: CardSessionRunnable<T>,
|
||||
preflightReadFilter: PreflightReadFilter?,
|
||||
cardId: String?,
|
||||
initialMessage: Message?,
|
||||
accessCode: String?,
|
||||
@DrawableRes iconScanRes: Int?,
|
||||
): CompletionResult<T> = withContext(Dispatchers.Main) {
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
tangemSdk.startSessionWithRunnable(runnable, cardId, initialMessage, accessCode, iconScanRes) { result ->
|
||||
tangemSdk.startSessionWithRunnable(
|
||||
runnable = runnable,
|
||||
cardId = cardId,
|
||||
initialMessage = initialMessage,
|
||||
accessCode = accessCode,
|
||||
preflightReadFilter = preflightReadFilter,
|
||||
iconScanRes = iconScanRes,
|
||||
) { result ->
|
||||
if (continuation.isActive) continuation.resume(result)
|
||||
}
|
||||
}
|
||||
|
|
@ -307,8 +323,14 @@ class DefaultTangemSdkManager(
|
|||
runnable: CardSessionRunnable<T>,
|
||||
cardId: String? = null,
|
||||
initialMessage: Message? = null,
|
||||
preflightReadFilter: PreflightReadFilter? = null,
|
||||
): CompletionResult<T> {
|
||||
val result = runTaskAsync(runnable, cardId, initialMessage)
|
||||
val result = runTaskAsync(
|
||||
runnable = runnable,
|
||||
cardId = cardId,
|
||||
initialMessage = initialMessage,
|
||||
preflightReadFilter = preflightReadFilter,
|
||||
)
|
||||
return withContext(Dispatchers.Main) { result }
|
||||
}
|
||||
|
||||
|
|
@ -360,6 +382,7 @@ class DefaultTangemSdkManager(
|
|||
runnable = CreateFirstTwinWalletTask(cardId),
|
||||
cardId = cardId,
|
||||
initialMessage = initialMessage,
|
||||
preflightReadFilter = null,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -378,7 +401,7 @@ class DefaultTangemSdkManager(
|
|||
preparingMessage = preparingMessage,
|
||||
creatingWalletMessage = creatingWalletMessage,
|
||||
)
|
||||
return runTaskAsync(task, null, initialMessage)
|
||||
return runTaskAsync(runnable = task, cardId = null, initialMessage = initialMessage, preflightReadFilter = null)
|
||||
}
|
||||
|
||||
override suspend fun finalizeTwin(
|
||||
|
|
@ -391,6 +414,7 @@ class DefaultTangemSdkManager(
|
|||
runnable = FinalizeTwinTask(secondCardPublicKey, issuerKeyPair),
|
||||
cardId = cardId,
|
||||
initialMessage = initialMessage,
|
||||
preflightReadFilter = null,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.tangem.domain.models.scan.CardDTO
|
|||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.operations.derivation.DerivationTaskResponse
|
||||
import com.tangem.operations.preflightread.PreflightReadFilter
|
||||
import com.tangem.operations.wallet.CreateWalletResponse
|
||||
import com.tangem.tap.domain.sdk.TangemSdkManager
|
||||
import com.tangem.tap.domain.sdk.mocks.MockProvider
|
||||
|
|
@ -72,6 +73,7 @@ class MockTangemSdkManager(
|
|||
override suspend fun derivePublicKeys(
|
||||
cardId: String?,
|
||||
derivations: Map<ByteArrayKey, List<DerivationPath>>,
|
||||
preflightReadFilter: PreflightReadFilter?,
|
||||
): CompletionResult<DerivationTaskResponse> {
|
||||
return MockProvider.getDerivationTaskResponse()
|
||||
}
|
||||
|
|
@ -135,6 +137,7 @@ class MockTangemSdkManager(
|
|||
|
||||
override suspend fun <T> runTaskAsync(
|
||||
runnable: CardSessionRunnable<T>,
|
||||
preflightReadFilter: PreflightReadFilter?,
|
||||
cardId: String?,
|
||||
initialMessage: Message?,
|
||||
accessCode: String?,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import com.tangem.tap.domain.tasks.UserWalletIdPreflightReadFilter
|
|||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
// TODO remove it after test after resolve [REDACTED_JIRA]
|
||||
internal class ResetBackupCardTask(
|
||||
private val userWalletId: UserWalletId,
|
||||
) : CardSessionRunnable<Boolean> {
|
||||
|
|
|
|||
|
|
@ -247,7 +247,14 @@ class WalletConnectSdkHelper {
|
|||
walletPublicKey = data.walletManager.wallet.publicKey.seedKey,
|
||||
derivationPath = data.walletManager.wallet.publicKey.derivationPath,
|
||||
)
|
||||
return when (val result = tangemSdkManager.runTaskAsync(command, initialMessage = Message(), cardId = cardId)) {
|
||||
return when (
|
||||
val result = tangemSdkManager.runTaskAsync(
|
||||
runnable = command,
|
||||
initialMessage = Message(),
|
||||
cardId = cardId,
|
||||
preflightReadFilter = null,
|
||||
)
|
||||
) {
|
||||
is CompletionResult.Success -> {
|
||||
val hash = EthereumUtils.prepareTransactionToSend(
|
||||
signature = result.data.signature,
|
||||
|
|
@ -290,7 +297,14 @@ class WalletConnectSdkHelper {
|
|||
walletPublicKey = wallet.publicKey.seedKey,
|
||||
derivationPath = wallet.publicKey.derivationPath,
|
||||
)
|
||||
return when (val result = tangemSdkManager.runTaskAsync(command, initialMessage = Message(), cardId = cardId)) {
|
||||
return when (
|
||||
val result = tangemSdkManager.runTaskAsync(
|
||||
runnable = command,
|
||||
initialMessage = Message(),
|
||||
cardId = cardId,
|
||||
preflightReadFilter = null,
|
||||
)
|
||||
) {
|
||||
is CompletionResult.Success -> {
|
||||
val key = wallet.publicKey.blockchainKey.toDecompressedPublicKey()
|
||||
getBnbResultString(
|
||||
|
|
@ -384,7 +398,13 @@ class WalletConnectSdkHelper {
|
|||
walletPublicKey = wallet.publicKey.seedKey,
|
||||
derivationPath = wallet.publicKey.derivationPath,
|
||||
)
|
||||
return when (val result = tangemSdkManager.runTaskAsync(command, cardId)) {
|
||||
return when (
|
||||
val result = tangemSdkManager.runTaskAsync(
|
||||
runnable = command,
|
||||
cardId = cardId,
|
||||
preflightReadFilter = null,
|
||||
)
|
||||
) {
|
||||
is CompletionResult.Success -> {
|
||||
val signedHash = result.data.signature
|
||||
|
||||
|
|
@ -419,7 +439,13 @@ class WalletConnectSdkHelper {
|
|||
walletPublicKey = wallet.publicKey.seedKey,
|
||||
derivationPath = wallet.publicKey.derivationPath,
|
||||
)
|
||||
return when (val result = tangemSdkManager.runTaskAsync(command, cardId)) {
|
||||
return when (
|
||||
val result = tangemSdkManager.runTaskAsync(
|
||||
runnable = command,
|
||||
cardId = cardId,
|
||||
preflightReadFilter = null,
|
||||
)
|
||||
) {
|
||||
is CompletionResult.Success -> {
|
||||
val signedHash = result.data.signature
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue