Updated on 2026-08-14
This commit is contained in:
parent
439fb00fb2
commit
416e401d5b
18 changed files with 134 additions and 28 deletions
|
|
@ -5,6 +5,8 @@ import com.tangem.common.CompletionResult
|
|||
import com.tangem.common.core.CardSession
|
||||
import com.tangem.common.core.CardSessionRunnable
|
||||
import com.tangem.common.core.CompletionCallback
|
||||
import com.tangem.common.core.TangemSdkError
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.operations.CommandResponse
|
||||
import com.tangem.operations.sign.SignHashesCommand
|
||||
|
||||
|
|
@ -18,7 +20,9 @@ class TangemSignHashesResponse(
|
|||
class SignHashesTask(
|
||||
private val hashes: Collection<ByteArray>,
|
||||
private val publicKey: Wallet.PublicKey,
|
||||
private val pairWalletPublicKey: ByteArray?,
|
||||
) : CardSessionRunnable<TangemSignHashesResponse> {
|
||||
|
||||
override fun run(session: CardSession, callback: CompletionCallback<TangemSignHashesResponse>) {
|
||||
SignHashesCommand(hashes.toTypedArray(), publicKey.seedKey, publicKey.derivationPath).run(session) { response ->
|
||||
when (response) {
|
||||
|
|
@ -35,8 +39,42 @@ class SignHashesTask(
|
|||
),
|
||||
)
|
||||
}
|
||||
is CompletionResult.Failure ->
|
||||
is CompletionResult.Failure -> {
|
||||
when {
|
||||
response.error is TangemSdkError.WalletNotFound && pairWalletPublicKey != null -> {
|
||||
sign(session, pairWalletPublicKey, publicKey.derivationPath, callback)
|
||||
}
|
||||
else -> callback(CompletionResult.Failure(response.error))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sign(
|
||||
session: CardSession,
|
||||
publicKey: ByteArray,
|
||||
derivationPath: DerivationPath?,
|
||||
callback: CompletionCallback<TangemSignHashesResponse>,
|
||||
) {
|
||||
SignHashesCommand(hashes.toTypedArray(), publicKey, derivationPath).run(session) { response ->
|
||||
when (response) {
|
||||
is CompletionResult.Success -> {
|
||||
val card = session.environment.card
|
||||
callback(
|
||||
CompletionResult.Success(
|
||||
TangemSignHashesResponse(
|
||||
signatures = response.data.signatures,
|
||||
totalSignedHashes = response.data.totalSignedHashes,
|
||||
remainingSignatures = card?.wallet(publicKey)?.remainingSignatures,
|
||||
batchId = card?.batchId,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
is CompletionResult.Failure -> {
|
||||
callback(CompletionResult.Failure(response.error))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue