@@ -2,6 +2,7 @@ import CryptoKit
2
2
import Foundation
3
3
import React
4
4
5
+
5
6
enum AccountSecurityMethod : String {
6
7
case pinNoDeviceAuth = " app_pin_no_device_authn "
7
8
case pinWithDeviceAuth = " app_pin_has_device_authn "
@@ -33,6 +34,7 @@ enum DeviceInfoKeys {
33
34
@objcMembers
34
35
@objc ( BcscCore)
35
36
class BcscCore : NSObject {
37
+ let logger = AppLogger ( subsystem: Bundle . main. bundleIdentifier ?? " ca.bc.gov.id.servicescard " , category: " BcscCore " )
36
38
static let generalizedOsName = " iOS "
37
39
static let provider = " https://idsit.gov.bc.ca/device/ "
38
40
static let clientName = " BC Services Wallet "
@@ -144,7 +146,7 @@ class BcscCore: NSObject {
144
146
SecItemDelete ( query as CFDictionary )
145
147
}
146
148
147
- print ( " BcscCore: Keychain cleared for this app." )
149
+ logger . log ( " Keychain cleared for this app. " )
148
150
}
149
151
150
152
// MARK: - Public Methods
@@ -229,60 +231,60 @@ class BcscCore: NSObject {
229
231
let baseId = components. joined ( separator: " / " ) // Reconstruct the base part of the ID
230
232
let newKeyId = " \( baseId) / \( numericSuffix) "
231
233
232
- print (
233
- " BcscCore: generateKeyPair (private) - Latest key found: \( existingTag) . Attempting to generate new incremented key with ID: \( newKeyId) "
234
+ logger . log (
235
+ " generateKeyPair - Latest key found: \( existingTag) . Attempting to generate new incremented key with ID: \( newKeyId) "
234
236
)
235
237
do {
236
238
// Assuming default keyType and keySize are handled by KeyPairManager.generateKeyPair or are acceptable.
237
239
_ = try keyPairManager. generateKeyPair ( withLabel: newKeyId)
238
- print (
239
- " BcscCore: generateKeyPair (private) - Successfully generated new incremented key with ID: \( newKeyId) "
240
+ logger . log (
241
+ " generateKeyPair - Successfully generated new incremented key with ID: \( newKeyId) "
240
242
)
241
243
return newKeyId
242
244
} catch {
243
- print (
244
- " BcscCore: generateKeyPair (private) - Failed to generate new incremented key with ID \( newKeyId) : \( error. localizedDescription) . "
245
+ logger . error (
246
+ " generateKeyPair - Failed to generate new incremented key with ID \( newKeyId) : \( error. localizedDescription) . "
245
247
)
246
248
return nil // Failed to generate the specifically requested incremented key.
247
249
}
248
250
} else {
249
251
// Parsing the existing tag failed (e.g., not in expected format or last part not a number).
250
252
// Fallback: generate a completely new key using a fresh initial ID pattern.
251
- print (
252
- " BcscCore: generateKeyPair (private) - Could not parse or increment existing key tag: \( existingTag) . Attempting to generate a new key with a fresh initial ID pattern. "
253
+ logger . warning (
254
+ " generateKeyPair - Could not parse or increment existing key tag: \( existingTag) . Attempting to generate a new key with a fresh initial ID pattern. "
253
255
)
254
256
// Use the same pattern for the new key ID as in the 'no keys found' case for consistency, but with a new UUID.
255
257
let freshGeneratedKeyId = " \( BcscCore . provider) / \( UUID ( ) . uuidString) /1 "
256
- print (
257
- " BcscCore: generateKeyPair (private) - Attempting to generate a new key with ID: \( freshGeneratedKeyId) due to parsing failure of existing key. "
258
+ logger . log (
259
+ " generateKeyPair - Attempting to generate a new key with ID: \( freshGeneratedKeyId) due to parsing failure of existing key. "
258
260
)
259
261
do {
260
262
_ = try keyPairManager. generateKeyPair ( withLabel: freshGeneratedKeyId)
261
- print (
262
- " BcscCore: generateKeyPair (private) - Successfully generated new key with ID: \( freshGeneratedKeyId) after parsing failure. "
263
+ logger . log (
264
+ " generateKeyPair - Successfully generated new key with ID: \( freshGeneratedKeyId) after parsing failure. "
263
265
)
264
266
return freshGeneratedKeyId
265
267
} catch {
266
- print (
267
- " BcscCore: generateKeyPair (private) - Failed to generate new key with ID \( freshGeneratedKeyId) after parsing failure: \( error. localizedDescription) "
268
+ logger . error (
269
+ " generateKeyPair - Failed to generate new key with ID \( freshGeneratedKeyId) after parsing failure: \( error. localizedDescription) "
268
270
)
269
271
return nil
270
272
}
271
273
}
272
274
} else {
273
275
// No keys found, attempt to generate a new one
274
- print (
275
- " BcscCore: generateKeyPair (private) - No keys found. Attempting to generate a new key with ID: \( initialKeyId) "
276
+ logger . log (
277
+ " generateKeyPair - No keys found. Attempting to generate a new key with ID: \( initialKeyId) "
276
278
)
277
279
do {
278
280
_ = try keyPairManager. generateKeyPair ( withLabel: initialKeyId) // Assuming default keyType and keySize are handled by this method or are acceptable.
279
- print (
280
- " BcscCore: generateKeyPair (private) - Successfully generated new key with ID: \( initialKeyId) "
281
+ logger . log (
282
+ " generateKeyPair - Successfully generated new key with ID: \( initialKeyId) "
281
283
)
282
284
return initialKeyId
283
285
} catch {
284
- print (
285
- " BcscCore: generateKeyPair (private) - Failed to generate new key with ID \( initialKeyId) : \( error. localizedDescription) "
286
+ logger . error (
287
+ " generateKeyPair - Failed to generate new key with ID \( initialKeyId) : \( error. localizedDescription) "
286
288
)
287
289
return nil
288
290
}
@@ -375,7 +377,7 @@ class BcscCore: NSObject {
375
377
376
378
// Add any additional claims
377
379
for (key, value) in claims {
378
- print ( key, value)
380
+ logger . log ( " \( key) , \( value) " )
379
381
builder. claim ( name: key as! String , value: value)
380
382
}
381
383
@@ -393,7 +395,7 @@ class BcscCore: NSObject {
393
395
_ account: NSDictionary , resolve: @escaping RCTPromiseResolveBlock ,
394
396
reject: @escaping RCTPromiseRejectBlock
395
397
) {
396
- print ( " BcscCore: setAccount called with account: \( account) " )
398
+ logger . log ( " setAccount called with account: \( account) " )
397
399
let accountID = UUID ( ) . uuidString
398
400
let storage = StorageService ( )
399
401
@@ -444,7 +446,7 @@ class BcscCore: NSObject {
444
446
)
445
447
446
448
if success {
447
- print ( " BcscCore: setAccount - Account successfully stored" )
449
+ logger . log ( " setAccount - Account successfully stored " )
448
450
resolve ( nil )
449
451
} else {
450
452
reject ( " E_ACCOUNT_STORAGE_FAILED " , " Failed to store account data " , nil )
@@ -659,7 +661,7 @@ class BcscCore: NSObject {
659
661
]
660
662
661
663
do {
662
- // print ("BcscCore: getDynamicClientRegistrationBody - Client Registration Data: \(clientRegistrationData)")
664
+ // logger.log ("BcscCore: getDynamicClientRegistrationBody - Client Registration Data: \(clientRegistrationData)")
663
665
let jsonData = try JSONSerialization . data ( withJSONObject: clientRegistrationData, options: [ ] )
664
666
let jsonString = String ( data: jsonData, encoding: . utf8) ?? " {} "
665
667
@@ -810,7 +812,7 @@ class BcscCore: NSObject {
810
812
return // Error already handled in makeSignedJWT
811
813
}
812
814
813
- print ( " signedJWT: \( signedJWT) " )
815
+ logger . log ( " signedJWT: \( signedJWT) " )
814
816
815
817
// Encrypt the signed JWT with the provided public key
816
818
do {
0 commit comments