diff --git a/TangemSdk/TangemSdk/Common/Core/TangemSdkError.swift b/TangemSdk/TangemSdk/Common/Core/TangemSdkError.swift index 283d3d2e6..56d1b1716 100644 --- a/TangemSdk/TangemSdk/Common/Core/TangemSdkError.swift +++ b/TangemSdk/TangemSdk/Common/Core/TangemSdkError.swift @@ -275,7 +275,9 @@ public enum TangemSdkError: Error, LocalizedError, Encodable { case backupFailedNotEnoughWallets case backupFailedFirmware case backupFailedIncompatibleBatch - + case backupFailedIncompatibleFirmware + case backupFailedKeysImportSettings + //MARK: Settings case filesDisabled case hdWalletDisabled @@ -394,6 +396,8 @@ public enum TangemSdkError: Error, LocalizedError, Encodable { case .issuerSignatureLoadingFailed: return 41229 case .backupFailedFirmware: return 41230 case .backupFailedIncompatibleBatch: return 41231 + case .backupFailedIncompatibleFirmware: return 41232 + case .backupFailedKeysImportSettings: return 41233 case .resetPinNoCardToReset: return 41300 case .resetPinWrongCard(let internalCode): return internalCode ?? 41301 @@ -503,7 +507,7 @@ public enum TangemSdkError: Error, LocalizedError, Encodable { case .backupCardRequired, .backupCardAlreadyAdded: return "error_backup_card_already_added".localized case .backupFailedNotEmptyWallets: return "error_backup_not_empty_wallets".localized case .backupFailedWrongIssuer, .backupFailedHDWalletSettings, .backupFailedNotEnoughCurves, .backupFailedNotEnoughWallets, - .backupFailedFirmware, .backupNotAllowed, .backupFailedIncompatibleBatch: + .backupFailedFirmware, .backupNotAllowed, .backupFailedIncompatibleBatch, .backupFailedIncompatibleFirmware, .backupFailedKeysImportSettings: return "error_backup_wrong_card".localized("\(self.code)") case .resetPinWrongCard: return "error_reset_wrong_card".localized("\(self.code)") diff --git a/TangemSdk/TangemSdk/Operations/Backup/BackupService.swift b/TangemSdk/TangemSdk/Operations/Backup/BackupService.swift index ec6544474..7db573f2f 100644 --- a/TangemSdk/TangemSdk/Operations/Backup/BackupService.swift +++ b/TangemSdk/TangemSdk/Operations/Backup/BackupService.swift @@ -386,7 +386,9 @@ public struct RawPrimaryCard { public let isHDWalletAllowed: Bool public let issuer: Card.Issuer public let walletCurves: [EllipticCurve] - public let batchId: String? //for compatibility with interrupted backups + public let batchId: String? // Optional for compatibility with interrupted backups + public let firmwareVersion: FirmwareVersion? // Optional for compatibility with interrupted backups + public let isKeysImportAllowed: Bool? // Optional for compatibility with interrupted backups } @available(iOS 13.0, *) @@ -401,7 +403,9 @@ public struct PrimaryCard: Codable, CertificateProvider { public let isHDWalletAllowed: Bool public let issuer: Card.Issuer public let walletCurves: [EllipticCurve] - public let batchId: String? //for compatibility with interrupted backups + public let batchId: String? // Optional for compatibility with interrupted backups + public let firmwareVersion: FirmwareVersion? // Optional for compatibility with interrupted backups + public let isKeysImportAllowed: Bool? // Optional for compatibility with interrupted backups public init(_ rawPrimaryCard: RawPrimaryCard, issuerSignature: Data) { self.cardId = rawPrimaryCard.cardId @@ -413,6 +417,8 @@ public struct PrimaryCard: Codable, CertificateProvider { self.issuer = rawPrimaryCard.issuer self.walletCurves = rawPrimaryCard.walletCurves self.batchId = rawPrimaryCard.batchId + self.firmwareVersion = rawPrimaryCard.firmwareVersion + self.isKeysImportAllowed = rawPrimaryCard.isKeysImportAllowed } } diff --git a/TangemSdk/TangemSdk/Operations/Backup/StartBackupCardLinkingTask.swift b/TangemSdk/TangemSdk/Operations/Backup/StartBackupCardLinkingTask.swift index 0329b5f0b..97a869dc4 100644 --- a/TangemSdk/TangemSdk/Operations/Backup/StartBackupCardLinkingTask.swift +++ b/TangemSdk/TangemSdk/Operations/Backup/StartBackupCardLinkingTask.swift @@ -55,6 +55,16 @@ final class StartBackupCardLinkingTask: CardSessionRunnable { completion(.failure(.backupFailedIncompatibleBatch)) return } + + if let firmwareVersion = primaryCard.firmwareVersion, firmwareVersion != card.firmwareVersion { + completion(.failure(.backupFailedIncompatibleFirmware)) + return + } + } + + if let isKeysImportAllowed = primaryCard.isKeysImportAllowed, isKeysImportAllowed != card.settings.isKeysImportAllowed { + completion(.failure(.backupFailedKeysImportSettings)) + return } if !primaryWalletCurves.isSubset(of: backupCardSupportedCurves) { diff --git a/TangemSdk/TangemSdk/Operations/Backup/StartPrimaryCardLinkingCommand.swift b/TangemSdk/TangemSdk/Operations/Backup/StartPrimaryCardLinkingCommand.swift index 72ecdb057..70275c2a4 100644 --- a/TangemSdk/TangemSdk/Operations/Backup/StartPrimaryCardLinkingCommand.swift +++ b/TangemSdk/TangemSdk/Operations/Backup/StartPrimaryCardLinkingCommand.swift @@ -64,6 +64,8 @@ public final class StartPrimaryCardLinkingCommand: Command { isHDWalletAllowed: card.settings.isHDWalletAllowed, issuer: card.issuer, walletCurves: card.wallets.map { $0.curve }, - batchId: card.batchId) + batchId: card.batchId, + firmwareVersion: card.firmwareVersion, + isKeysImportAllowed: card.settings.isKeysImportAllowed) } }