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

Sync ring logic #378

Merged
merged 3 commits into from
Oct 10, 2024
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
1 change: 1 addition & 0 deletions Example/TangemSdkExample/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AppModel: ObservableObject {
.ed25519_slip0010: [try! DerivationPath(rawPath: "m/0'/1'")],
.bip0340: [try! DerivationPath(rawPath: "m/0'/1")]
]

_tangemSdk.config = config
return _tangemSdk
}
Expand Down
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ let package = Package(
.copy("Haptics"),
.copy("Crypto/BIP39/Wordlists/english.txt"),
.copy("PrivacyInfo.xcprivacy"),
.copy("Assets"),
]
),
.target(
Expand Down
1 change: 1 addition & 0 deletions TangemSdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Tangem is a Swiss-based secure hardware wallet manufacturer that enables blockch
'TangemSdk/TangemSdk/Haptics/*.ahap',
'TangemSdk/TangemSdk/**/Wordlists/*.txt',
'TangemSdk/TangemSdk/PrivacyInfo.xcprivacy',
'TangemSdk/TangemSdk/Assets/*.xcassets',
]
}

Expand Down
12 changes: 12 additions & 0 deletions TangemSdk/TangemSdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
DC7254902A03E20A0003FE1B /* DerivedKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC72548F2A03E20A0003FE1B /* DerivedKeys.swift */; };
DC8B0E3F286F221D009D64F7 /* BiometricsUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8B0E3E286F221D009D64F7 /* BiometricsUtil.swift */; };
DCA9706628E35EAD0046E62E /* GenerateOTPCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA9706528E35EAD0046E62E /* GenerateOTPCommand.swift */; };
DCACA0402CB51FF400A3DD51 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DCACA03F2CB51FF400A3DD51 /* Assets.xcassets */; };
DCB5A4E02A1F969F0021E12D /* HKDFUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCB5A4DF2A1F969F0021E12D /* HKDFUtil.swift */; };
DCB5A4E32A1FAB330021E12D /* BLSUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCB5A4E22A1FAB330021E12D /* BLSUtils.swift */; };
DCB5A4E52A1FAC190021E12D /* BLSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCB5A4E42A1FAC190021E12D /* BLSTests.swift */; };
Expand Down Expand Up @@ -680,6 +681,7 @@
DC72548F2A03E20A0003FE1B /* DerivedKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DerivedKeys.swift; sourceTree = "<group>"; };
DC8B0E3E286F221D009D64F7 /* BiometricsUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BiometricsUtil.swift; sourceTree = "<group>"; };
DCA9706528E35EAD0046E62E /* GenerateOTPCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateOTPCommand.swift; sourceTree = "<group>"; };
DCACA03F2CB51FF400A3DD51 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
DCB5A4DF2A1F969F0021E12D /* HKDFUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HKDFUtil.swift; sourceTree = "<group>"; };
DCB5A4E22A1FAB330021E12D /* BLSUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLSUtils.swift; sourceTree = "<group>"; };
DCB5A4E42A1FAC190021E12D /* BLSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLSTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1243,6 +1245,7 @@
5DA80C9C231D247A00A50A10 /* TangemSdk */ = {
isa = PBXGroup;
children = (
DCACA03E2CB51FDF00A3DD51 /* Assets */,
5DA80C9D231D247A00A50A10 /* TangemSdk.h */,
5D5369D124461F62002886E0 /* module.modulemap */,
DC44C5892B4DC1B200888BED /* PrivacyInfo.xcprivacy */,
Expand Down Expand Up @@ -1558,6 +1561,14 @@
path = PreflightReadFilter;
sourceTree = "<group>";
};
DCACA03E2CB51FDF00A3DD51 /* Assets */ = {
isa = PBXGroup;
children = (
DCACA03F2CB51FF400A3DD51 /* Assets.xcassets */,
);
path = Assets;
sourceTree = "<group>";
};
DCB5A4E12A1FAB190021E12D /* BLS */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1872,6 +1883,7 @@
DC1244B529B60E480037BC05 /* english.txt in Resources */,
5DD5368C2476B3FB00F5DE88 /* Error.ahap in Resources */,
5D5369D224461F62002886E0 /* module.modulemap in Resources */,
DCACA0402CB51FF400A3DD51 /* Assets.xcassets in Resources */,
5D6A92D82344E2D700158457 /* Localizable.strings in Resources */,
5DD5368B2476B3FB00F5DE88 /* Success.ahap in Resources */,
);
Expand Down
6 changes: 6 additions & 0 deletions TangemSdk/TangemSdk/Assets/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "ring_shape_scan.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
10 changes: 7 additions & 3 deletions TangemSdk/TangemSdk/Common/Core/CardSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class CardSession {
private var accessCodeRepository: AccessCodeRepository? = nil
private let filter: SessionFilter?

private var defaultScanMessage: String {
"view_delegate_scan_description_format".localized(environment.config.productType.localizedDescription)
}

private var shouldRequestBiometrics: Bool {
guard let accessCodeRepository = self.accessCodeRepository else {
return false
Expand Down Expand Up @@ -190,7 +194,7 @@ public class CardSession {
self.viewDelegate.tagConnected()
self.viewDelegate.setState(.default)
case .tagLost:
self.viewDelegate.tagLost()
self.viewDelegate.tagLost(message: defaultScanMessage)
self.viewDelegate.setState(.scan)
}
})
Expand Down Expand Up @@ -226,7 +230,7 @@ public class CardSession {
})
.store(in: &nfcReaderSubscriptions)

reader.startSession(with: initialMessage?.alertMessage)
reader.startSession(with: initialMessage?.alertMessage ?? defaultScanMessage)
}

// MARK: - Session stop and pause
Expand Down Expand Up @@ -510,7 +514,7 @@ public class CardSession {
func continueRunnable(code: String) {
self.updateEnvironment(with: type, code: code)
self.viewDelegate.setState(.default)
self.viewDelegate.showAlertMessage("view_delegate_scan_description".localized)
self.viewDelegate.showAlertMessage(defaultScanMessage)
completion(.success(()))
}

Expand Down
40 changes: 39 additions & 1 deletion TangemSdk/TangemSdk/Common/Core/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public struct Config {

/// Card id display format. Full card id will be displayed by default
public var cardIdDisplayFormat: CardIdDisplayFormat = .full


/// Product to work with. Affect animations and texts.
public var productType: ProductType = .any

/// Logger configuration
public var logConfig: Log.Config = .default

Expand All @@ -66,6 +69,23 @@ public struct Config {

/// Localized reason for Touch ID. DO NOT leave it empty.
public var biometricsLocalizedReason: String = "touch_id_localized_reason".localized

public mutating func setupForProduct(_ product: ProductType) {
switch product {
case .card:
productType = .card
cardIdDisplayFormat = .full
style.scanTagImage = .genericCard
case .ring:
productType = .ring
cardIdDisplayFormat = .none
style.scanTagImage = .genericRing
case .any:
productType = .any
cardIdDisplayFormat = .full
style.scanTagImage = .genericCard
}
}
}

public enum CardIdDisplayFormat {
Expand All @@ -89,3 +109,21 @@ public enum AccessCodeRequestPolicy: String, CaseIterable {
/// User code will be requested only if set on the card. Need scan the card twice.
case `default`
}

public enum ProductType {
case any
case card
case ring

@available(iOS 13.0, *)
var localizedDescription: String {
switch self {
case .card:
"common_card".localized
case .ring:
"common_ring".localized
case .any:
"common_card_or_ring".localized
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
"attestation_online_failed_body" = "Der Online-Nachweis/ Prüfung der Karte kann derzeit nicht durchgeführt werden. Du kannst auf eigenem Risiko fortfahren oder es später erneut versuchen.";
"attestation_online_failed_title" = "Online-Nachweis/Prüfung fehlgeschlagen";
"attestation_warning_attest_wallets" = "Eine verdächtige Verwendung der Wallet auf der Karte wurde festgestellt.";
"backup_add_backup_card_message" = "Verbinde dein Telefon und die Karte, die du als Backup verwenden möchten, genau wie oben gezeigt.";
"backup_add_backup_card_message" = "Verbinde dein Telefon und die Karte oder den Ring, die du als Backup verwenden möchten, genau wie oben gezeigt.";
"backup_finalize_backup_card_message_format" = "Halte die Karte mit der Nummer %@ genau wie oben gezeigt, auf deinem Telefon.";
"backup_finalize_backup_ring_message" = "Tippe mit dem Ring genau wie oben gezeigt auf Dein Smartphone.";
"backup_finalize_primary_card_message_format" = "Verbinde dein Telefon und die vorherige Karte mit der Nummer %@ genau wie oben gezeigt.";
"backup_finalize_primary_ring_message" = "Verbinde Dein Telefon und den primären Ring wie oben gezeigt.";
"backup_prepare_primary_card_message" = "Verbinde dein Telefon und die primäre Karte genau wie oben gezeigt.";
"backup_prepare_primary_card_message_format" = "Verbinde dein Telefon und die primäre Karte mit der Nummer %@ genau wie oben gezeigt.";
"cid_format" = "Karte Nr.%@";
"common_cancel" = "Abbrechen";
"common_card" = "card";
"common_card_or_ring" = "card or ring";
"common_continue" = "Fortsetzen";
"common_error" = "Fehler";
"common_ok" = "OK";
"common_retry" = "Wiederholen";
"common_ring" = "ring";
"common_success" = "Erfolg";
"common_understand" = "Ich verstehe";
"common_warning" = "Warnung";
Expand Down Expand Up @@ -55,16 +60,18 @@
"reset_codes_current_card" = "Aktuelle Karte";
"reset_codes_linked_card" = "Verknüpfte Karte";
"reset_codes_message_body_backup" = "Halte die verknüpfte Karte dran";
"reset_codes_message_body_restore" = "Bereite zunächst die Karte für den Wiederherstellungsprozess vor";
"reset_codes_message_body_restore" = "Bereite zunächst die Karte oder den Ring für den Wiederherstellungsprozess vor";
"reset_codes_message_body_restore_final" = "Halte die Karte erneut dran, auf der du den Zugangscode wiederherstellen möchtest";
"reset_codes_message_title_backup" = "Halte eine Backup-Karte dran";
"reset_codes_message_title_restore" = "Halte die Karte dran, die du wiederherstellen möchtest";
"reset_codes_scan_confirmation_card" = "Eine andere verknüpfte Karte scannen";
"reset_codes_message_title_backup" = "Halte eine Backup-Karte oder Ring dran";
"reset_codes_message_title_restore" = "Halte die Karte oder den Ring dran, die du wiederherstellen möchtest";
"reset_codes_scan_confirmation_card" = "Eine andere verknüpfte Karte oder Ring scannen";
"reset_codes_scan_first_card" = "Scanne die Karte, auf der du %@ zurücksetzen möchtest";
"reset_codes_scan_to_reset" = "Scanne die Karte, um Benutzercodes zurückzusetzen";
"reset_codes_scan_to_reset" = "Scanne die Karte oder den Ring, um Benutzercodes zurückzusetzen";
"reset_codes_success_message" = "Code wurde erfolgreich zurückgesetzt";
"sign_multiple_chunks_part" = "Unterzeichnung von Teil %1$li von %2$li";
"touch_id_localized_reason" = "Verwende Touch ID, um Zugangscodes in der App zu speichern";
"view_delegate_scan_description" = "Halte die Karte bis zum Ende des Vorgangs gedrückt, wie oben gezeigt";
"view_delegate_security_delay_description" = "Um die Sicherheit zu gewährleisten, halte die Karte bitte bis zum Abschluss des Vorgangs angedrückt.";
"view_delegate_scan_description" = "Halte die Karte oder den Ring bis zum Ende des Vorgangs gedrückt, wie oben gezeigt";
"view_delegate_scan_description_format" = "Tap the %@ as shown above and hold until the end of the operation";
"view_delegate_security_delay_description" = "Um die Sicherheit zu gewährleisten, halte die Karte oder den Ring bitte bis zum Abschluss des Vorgangs angedrückt.";
"view_delegate_security_delay_description_format" = "To ensure security please hold the %@ until the operation is complete";
"wallet_not_found" = "Sieht so aus, als hättest du die falsche Karte. Der Vorgang kann mit dieser Karte nicht durchgeführt werden.";
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
"attestation_online_failed_body" = "At the moment, online attestation of the card cannot be performed. You can continue at your own risk or try again later.";
"attestation_online_failed_title" = "Online attestation failed";
"attestation_warning_attest_wallets" = "Suspicious use of the wallet on the card has been detected.";
"backup_add_backup_card_message" = "Connect your phone and the card you want to use as a backup exactly as it shown above.";
"backup_add_backup_card_message" = "Connect your phone to the card or ring you want to use as a backup, exactly as shown above.";
"backup_finalize_backup_card_message_format" = "Tap the card with number %@ to your phone exactly as shown above.";
"backup_finalize_backup_ring_message" = "Tap the ring to your phone exactly as shown above.";
"backup_finalize_primary_card_message_format" = "Connect your phone and the primary card with number %@ exactly as it shown above.";
"backup_finalize_primary_ring_message" = "Connect your phone and the primary ring as it shown above.";
"backup_prepare_primary_card_message" = "Connect your phone and the primary card exactly as it shown above.";
"backup_prepare_primary_card_message_format" = "Connect your phone and the primary card with number %@ exactly as it shown above.";
"cid_format" = "Card #%@";
"common_cancel" = "Cancel";
"common_card" = "card";
"common_card_or_ring" = "card or ring";
"common_continue" = "Continue";
"common_error" = "Error";
"common_ok" = "OK";
"common_retry" = "Retry";
"common_ring" = "ring";
"common_success" = "Success";
"common_understand" = "I understand";
"common_warning" = "Warning";
Expand Down Expand Up @@ -55,16 +60,18 @@
"reset_codes_current_card" = "Current card";
"reset_codes_linked_card" = "Linked card";
"reset_codes_message_body_backup" = "Tap the linked card";
"reset_codes_message_body_restore" = "First, prepare the card for restore process";
"reset_codes_message_body_restore" = "First, prepare the card or ring for restore process";
"reset_codes_message_body_restore_final" = "Tap again the card on which you want to restore the access code";
"reset_codes_message_title_backup" = "Tap a backup card";
"reset_codes_message_title_restore" = "Tap the card you want to restore";
"reset_codes_scan_confirmation_card" = "Scan another linked card";
"reset_codes_message_title_backup" = "Tap a backup card or ring";
"reset_codes_message_title_restore" = "Tap the card or ring you want to restore";
"reset_codes_scan_confirmation_card" = "Scan another linked card or ring";
"reset_codes_scan_first_card" = "Scan the card on which you want to reset the %@";
"reset_codes_scan_to_reset" = "Scan card to reset user codes";
"reset_codes_scan_to_reset" = "Scan card or ring to reset user codes";
"reset_codes_success_message" = "Code was reset successfully";
"sign_multiple_chunks_part" = "Signing part %1$li of %2$li";
"touch_id_localized_reason" = "Use Touch ID to save access codes in the app";
"view_delegate_scan_description" = "Tap the card as shown above and hold until the end of the operation";
"view_delegate_security_delay_description" = "To ensure security please hold the card until the operation complete";
"view_delegate_scan_description" = "Tap the card or ring as shown above and hold until the end of the operation";
"view_delegate_scan_description_format" = "Tap the %@ as shown above and hold until the end of the operation";
"view_delegate_security_delay_description" = "To ensure security please hold the card or ring until the operation complete";
"view_delegate_security_delay_description_format" = "To ensure security please hold the %@ until the operation is complete";
"wallet_not_found" = "Looks like you got the wrong card. The operation cannot be performed with this card.";
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
"attestation_warning_attest_wallets" = "Se ha detectado un uso sospechoso del monedero de la tarjeta.";
"backup_add_backup_card_message" = "Conecte su teléfono y la tarjeta que desea usar como respaldo exactamente como se muestra arriba.";
"backup_finalize_backup_card_message_format" = "Toque la tarjeta con el número %@ en su teléfono exactamente como se muestra arriba.";
"backup_finalize_backup_ring_message" = "Tap the ring to your phone exactly as shown above.";
"backup_finalize_primary_card_message_format" = "Conecte su teléfono y la placa principal con el número %@ exactamente como se muestra arriba.";
"backup_finalize_primary_ring_message" = "Connect your phone and the primary ring as it shown above.";
"backup_prepare_primary_card_message" = "Conecte su teléfono y la placa principal exactamente como se muestra arriba.";
"backup_prepare_primary_card_message_format" = "Conecte su teléfono y la placa principal con el número %@ exactamente como se muestra arriba.";
"cid_format" = "Tarjeta no. %@";
"common_cancel" = "Cancelar";
"common_card" = "card";
"common_card_or_ring" = "card or ring";
"common_continue" = "Continuar";
"common_error" = "Error";
"common_ok" = "OK";
"common_retry" = "Inténtalo de nuevo";
"common_ring" = "ring";
"common_success" = "Con éxito";
"common_understand" = "Entiendo";
"common_warning" = "Cuidado";
Expand Down Expand Up @@ -66,5 +71,7 @@
"sign_multiple_chunks_part" = "Parte de firma %1$li de %2$li";
"touch_id_localized_reason" = "Use Touch ID para guardar códigos de acceso en la aplicación";
"view_delegate_scan_description" = "Presione la tarjeta como se muestra arriba y manténgala presionada hasta que se complete la operación.";
"view_delegate_scan_description_format" = "Tap the %@ as shown above and hold until the end of the operation";
"view_delegate_security_delay_description" = "Para garantizar la seguridad, conserve la tarjeta hasta que se complete la transacción.";
"view_delegate_security_delay_description_format" = "To ensure security please hold the %@ until the operation is complete";
"wallet_not_found" = "Parece que se equivocó de mapa. La operación no se puede realizar con esta tarjeta.";
Loading
Loading