Updated on 2026-08-14
This commit is contained in:
commit
ac621b6bad
466 changed files with 12729 additions and 3984 deletions
|
|
@ -0,0 +1,46 @@
|
|||
package com.tangem.domain.card
|
||||
|
||||
import com.tangem.common.card.EllipticCurve
|
||||
import com.tangem.domain.card.configs.CardConfig
|
||||
import com.tangem.domain.models.scan.CardDTO
|
||||
|
||||
object BackupValidator {
|
||||
|
||||
fun isValidFull(cardDTO: CardDTO): Boolean {
|
||||
return validateBackupStatus(cardDTO) && validateCurves(cardDTO)
|
||||
}
|
||||
|
||||
fun isValidBackupStatus(cardDTO: CardDTO): Boolean {
|
||||
return validateBackupStatus(cardDTO)
|
||||
}
|
||||
|
||||
private fun validateCurves(cardDTO: CardDTO): Boolean {
|
||||
val config = CardConfig.createConfig(cardDTO)
|
||||
// / Since the curve `bls12381_G2_AUG` was added later into first generation of wallets,
|
||||
// we cannot determine whether this curve is missing due to an error or because the user
|
||||
// did not want to recreate the wallet.
|
||||
val expectedCurves = config.mandatoryCurves
|
||||
.filterNot { it == EllipticCurve.Bls12381G2Aug }
|
||||
val curves = cardDTO.wallets.map { it.curve }
|
||||
for (expectedCurve in expectedCurves) {
|
||||
val cardCurvesCount = curves.count { it == expectedCurve }
|
||||
|
||||
// missing curve
|
||||
if (cardCurvesCount == 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
// duplicated curve
|
||||
if (cardCurvesCount > 1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun validateBackupStatus(cardDTO: CardDTO): Boolean {
|
||||
val backupStatus = cardDTO.backupStatus
|
||||
backupStatus ?: return true // for card with null backup status, validation should always returns true
|
||||
return backupStatus !is CardDTO.BackupStatus.CardLinked
|
||||
}
|
||||
}
|
||||
|
|
@ -212,9 +212,9 @@ data object Wallet2CardConfig : CardConfig {
|
|||
Blockchain.HyperliquidTestnet -> EllipticCurve.Secp256k1
|
||||
Blockchain.Quai -> EllipticCurve.Secp256k1
|
||||
Blockchain.QuaiTestnet -> EllipticCurve.Secp256k1
|
||||
// Blockchain.Linea -> EllipticCurve.Secp256k1
|
||||
// Blockchain.LineaTestnet -> EllipticCurve.Secp256k1
|
||||
// Blockchain.ArbitrumNova -> EllipticCurve.Secp256k1
|
||||
Blockchain.Linea -> EllipticCurve.Secp256k1
|
||||
Blockchain.LineaTestnet -> EllipticCurve.Secp256k1
|
||||
Blockchain.ArbitrumNova -> EllipticCurve.Secp256k1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -168,9 +168,9 @@ class Wallet2CardConfigTest {
|
|||
Blockchain.HyperliquidTestnet to EllipticCurve.Secp256k1,
|
||||
Blockchain.Quai to EllipticCurve.Secp256k1,
|
||||
Blockchain.QuaiTestnet to EllipticCurve.Secp256k1,
|
||||
// Blockchain.Linea to EllipticCurve.Secp256k1,
|
||||
// Blockchain.LineaTestnet to EllipticCurve.Secp256k1,
|
||||
// Blockchain.ArbitrumNova to EllipticCurve.Secp256k1,
|
||||
Blockchain.Linea to EllipticCurve.Secp256k1,
|
||||
Blockchain.LineaTestnet to EllipticCurve.Secp256k1,
|
||||
Blockchain.ArbitrumNova to EllipticCurve.Secp256k1,
|
||||
)
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue