Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-8852 Cleaning #393

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class AccessCodeRepository {
}

public func save(_ accessCode: Data, for cardIds: [String]) throws {
Log.debug("Save the access code for cardIds: \(cardIds)")
guard BiometricsUtil.isAvailable else {
throw TangemSdkError.biometricsUnavailable
}
Expand All @@ -43,47 +42,38 @@ public class AccessCodeRepository {
var savedCardIds = getCards()

for cardId in cardIds {
Log.debug("Start saving the code for \(cardId)")
let storageKey = SecureStorageKey.accessCode(for: cardId)

if savedCardIds.contains(cardId) {
Log.debug("Try delete the code for \(cardId)")
try biometricsStorage.delete(storageKey)
}

Log.debug("Try save the code for \(cardId)")
try biometricsStorage.store(accessCode, forKey: storageKey)

savedCardIds.insert(cardId)
Log.debug("The code saved for \(cardId)")
}

saveCards(cardIds: savedCardIds)
Log.debug("The saving was completed successfully")
}

public func save(_ accessCode: Data, for cardId: String) throws {
Log.debug("Delete the access code for \(cardId)")
try save(accessCode, for: [cardId])
}

public func deleteAccessCode(for cardIds: [String]) throws {
Log.debug("Delete access codes for \(cardIds)")
if cardIds.isEmpty {
return
}

var savedCardIds = getCards()
for cardId in cardIds {
Log.debug("Delete the access code for \(cardId)")
guard savedCardIds.contains(cardId) else {
Log.debug("Skip \(cardId)")
continue
}

try biometricsStorage.delete(SecureStorageKey.accessCode(for: cardId))
savedCardIds.remove(cardId)
Log.debug("The access code for \(cardId) was deleted successfully")
}
saveCards(cardIds: savedCardIds)
Log.debug("The deletion was completed successfully")
Expand All @@ -102,7 +92,6 @@ public class AccessCodeRepository {
func contains(_ cardId: String) -> Bool {
let savedCards = getCards()
let contains = savedCards.contains(cardId)
Log.debug("Check if the repo contains the code for the \(cardId). Result: \(contains)")
return contains
}

Expand Down Expand Up @@ -130,7 +119,6 @@ public class AccessCodeRepository {
for cardId in self.getCards() {
let accessCode = try self.biometricsStorage.get(SecureStorageKey.accessCode(for: cardId), context: context)
fetchedAccessCodes[cardId] = accessCode
Log.debug("Fetch the access code for the \(cardId). Result is \(accessCode != nil)")
}

self.accessCodes = fetchedAccessCodes
Expand All @@ -151,15 +139,13 @@ public class AccessCodeRepository {

func fetch(for cardId: String) -> Data? {
let code = accessCodes[cardId]
Log.debug("Fetch the code for cardId: \(cardId). Result: \(code != nil)")
return code
}

private func updateCodesIfNeeded(with accessCode: Data, for cardIds: [String]) -> Bool {
var hasChanges: Bool = false

for cardId in cardIds {
Log.debug("Try update the access code for \(cardId)")
let existingCode = accessCodes[cardId]

if existingCode == accessCode {
Expand Down
6 changes: 3 additions & 3 deletions TangemSdk/TangemSdkTests/Jsons/Card.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"ed25519",
"secp256r1"
],
"cardPublicKey" : "0400D05BCAC34B58AA48BF998FB68667A3112262275200431EA235EC4616A15287B5D21F15E45740AB6B829F415950DBC7A68493DCF5FD270C8CAAB0E975E9A0D9",
"cardPublicKey" : "0000",
"userSettings" : {
"isUserCodeRecoveryAllowed" : true
},
Expand All @@ -32,7 +32,7 @@
},
"issuer" : {
"name" : "TANGEM AG",
"publicKey" : "0456E7C3376329DFAE7388DF1695670386103C92486A87644FA9E512C9CF4E92FE970EFDFBB7A35446F2A937505E6C70D78E965533B31C252B607F3C6B3112B603"
"publicKey" : "0000"
},
"firmwareVersion" : {
"minor" : 12,
Expand All @@ -51,7 +51,7 @@
"manufacturer" : {
"name" : "TANGEM",
"manufactureDate" : "2021-04-01",
"signature" : "1671A9AB2D9D5B99177E841C8DC35842452A095088CD01B48D753631571AAB21EEAC0F96BC87142268C32EFB3AF8A8C80DB55BE6D1970FAFBC72E00F896F69EA"
"signature" : "0000"
},
"cardId" : "CB79000000018201",
"wallets" : [
Expand Down
20 changes: 10 additions & 10 deletions TangemSdk/TangemSdkTests/Jsons/Personalize/v3.05ada.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,30 @@
},
"manufacturer": {
"keyPair": {
"privateKey": "1b48cfd24bbb5b394771ed81f2bacf57479e4735eb1405083927372d40da9e92",
"publicKey": "04bab86d56298c996f564a84fc88e28aed38184b12f07e519113bef48c76f3df3adc303599b08ac05b55ec3df98d9338573a6242f76f5d28f4f0f364e87e8fca2f"
"privateKey": "0000",
"publicKey": "0000"
},
"name": "Tangem"
},
"issuer": {
"dataKeyPair": {
"privateKey": "11121314151617184771ED81F2BACF57479E4735EB1405083927372D40DA9E92",
"publicKey": "045f16bd1d2eafe463e62a335a09e6b2bbcbd04452526885cb679fc4d27af1bd22f553c7deefb54fd3d4f361d14e6dc3f11b7d4ea183250a60720ebdf9e110cd26"
"privateKey": "0000",
"publicKey": "0000"
},
"transactionKeyPair": {
"privateKey": "11121314151617184771ED81F2BACF57479E4735EB1405081918171615141312",
"publicKey": "0484c5192e9bfa6c528a344f442137a92b89ea835bfef1d04cb4362eb906b508c5889846cfea71ba6dc7b3120c2208df9c46127d3d85cb5cfbd1479e97133a39d8"
"privateKey": "0000",
"publicKey": "0000"
},
"name": "TANGEM SDK",
"id": "TANGEM SDK"
},
"acquirer": {
"keyPair": {
"privateKey": "21222324252627284771ED81F2BACF57479E4735EB1405083927372D40DA9E92",
"publicKey": "0456ad1a82b22bcb40c38fd08939f87e6b80e40dec5b3bdb351c55fcd709e47f9fb2ed00c2304d3a986f79c5ae0ac3c84e88da46dc8f513b7542c716af8c9a2daf"
"privateKey": "0000",
"publicKey": "0000"
},
"name": "Smart Cash",
"id": "Smart Cash"
"name": "Tangem SDK",
"id": "Tangem SDK"
}
},
"id": 1
Expand Down
20 changes: 10 additions & 10 deletions TangemSdk/TangemSdkTests/Jsons/Personalize/v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,30 @@
},
"manufacturer": {
"keyPair": {
"privateKey": "1b48cfd24bbb5b394771ed81f2bacf57479e4735eb1405083927372d40da9e92",
"publicKey": "04bab86d56298c996f564a84fc88e28aed38184b12f07e519113bef48c76f3df3adc303599b08ac05b55ec3df98d9338573a6242f76f5d28f4f0f364e87e8fca2f"
"privateKey": "0000",
"publicKey": "0000"
},
"name": "Tangem"
},
"issuer": {
"dataKeyPair": {
"privateKey": "11121314151617184771ED81F2BACF57479E4735EB1405083927372D40DA9E92",
"publicKey": "045f16bd1d2eafe463e62a335a09e6b2bbcbd04452526885cb679fc4d27af1bd22f553c7deefb54fd3d4f361d14e6dc3f11b7d4ea183250a60720ebdf9e110cd26"
"privateKey": "0000",
"publicKey": "0000"
},
"transactionKeyPair": {
"privateKey": "11121314151617184771ED81F2BACF57479E4735EB1405081918171615141312",
"publicKey": "0484c5192e9bfa6c528a344f442137a92b89ea835bfef1d04cb4362eb906b508c5889846cfea71ba6dc7b3120c2208df9c46127d3d85cb5cfbd1479e97133a39d8"
"privateKey": "0000",
"publicKey": "0000"
},
"name": "TANGEM SDK",
"id": "TANGEM SDK"
},
"acquirer": {
"keyPair": {
"privateKey": "21222324252627284771ED81F2BACF57479E4735EB1405083927372D40DA9E92",
"publicKey": "0456ad1a82b22bcb40c38fd08939f87e6b80e40dec5b3bdb351c55fcd709e47f9fb2ed00c2304d3a986f79c5ae0ac3c84e88da46dc8f513b7542c716af8c9a2daf"
"privateKey": "0000",
"publicKey": "0000"
},
"name": "Smart Cash",
"id": "Smart Cash"
"name": "Tangem SDK",
"id": "Tangem SDK"
}
},
"id": 1
Expand Down
Loading