@@ -23,7 +23,6 @@ final class StartBackupCardLinkingTask: CardSessionRunnable {
23
23
private let primaryCard : PrimaryCard
24
24
private let addedBackupCards : [ String ]
25
25
private let skipCompatibilityChecks : Bool
26
- private var linkingCommand : StartBackupCardLinkingCommand ? = nil
27
26
28
27
init ( primaryCard: PrimaryCard , addedBackupCards: [ String ] , skipCompatibilityChecks: Bool = false ) {
29
28
self . primaryCard = primaryCard
@@ -93,19 +92,36 @@ final class StartBackupCardLinkingTask: CardSessionRunnable {
93
92
}
94
93
}
95
94
96
- linkingCommand = StartBackupCardLinkingCommand ( primaryCardLinkingKey: primaryCard. linkingKey)
97
- linkingCommand! . run ( in: session) { result in
95
+ let linkingCommand = StartBackupCardLinkingCommand ( primaryCardLinkingKey: primaryCard. linkingKey)
96
+ linkingCommand. run ( in: session) { result in
98
97
switch result {
99
98
case . success( let backupCard) :
100
99
guard let card = session. environment. card else {
101
100
completion ( . failure( . missingPreflightRead) )
102
101
return
103
102
}
104
-
105
- completion ( . success( . init( backupCard: backupCard, card: card) ) )
103
+
104
+ let response = StartBackupCardLinkingTaskResponse ( backupCard: backupCard, card: card)
105
+ self . runAttestation ( session, response: response, completion: completion)
106
+ case . failure( let error) :
107
+ completion ( . failure( error) )
108
+ }
109
+
110
+ withExtendedLifetime ( linkingCommand) { }
111
+ }
112
+ }
113
+
114
+ private func runAttestation( _ session: CardSession , response: StartBackupCardLinkingTaskResponse , completion: @escaping CompletionResult < StartBackupCardLinkingTaskResponse > ) {
115
+ let attestationTask = AttestationTask ( mode: session. environment. config. attestationMode)
116
+ attestationTask. run ( in: session) { result in
117
+ switch result {
118
+ case . success:
119
+ completion ( . success( response) )
106
120
case . failure( let error) :
107
121
completion ( . failure( error) )
108
122
}
123
+
124
+ withExtendedLifetime ( attestationTask) { }
109
125
}
110
126
}
111
127
0 commit comments