Skip to content

Commit

Permalink
Merge pull request #270 from tangem/IOS-3467_backup_prechecks
Browse files Browse the repository at this point in the history
  • Loading branch information
tureck1y authored Apr 18, 2023
2 parents 6558d79 + 5945868 commit 2d7c6ec
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions TangemSdk/TangemSdk/Common/Core/TangemSdkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)")
Expand Down
10 changes: 8 additions & 2 deletions TangemSdk/TangemSdk/Operations/Backup/BackupService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, *)
Expand All @@ -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
Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 2d7c6ec

Please sign in to comment.