@@ -398,12 +398,12 @@ class FulaModule: NSObject {
398398
399399 func createPeerIdentity( privateKey: Data ) throws -> Data {
400400 let secretKey = try Cryptography . generateKey ( privateKey)
401-
401+
402402 var encryptedKey : String ? = userDataHelper. getValue ( FulaModule . PRIVATE_KEY_STORE_ID)
403403 NSLog ( " ReactNative createPeerIdentity encryptedKey= \( encryptedKey ?? " nil " ) " )
404404 if encryptedKey == nil {
405405 let privateKeyString = String ( data: privateKey, encoding: . utf8) ?? " "
406-
406+
407407 guard !privateKeyString. isEmpty else {
408408 throw NSError ( domain: " KeyGenerationError " , code: - 1 , userInfo: [ NSLocalizedDescriptionKey: " Private key string conversion failed " ] )
409409 }
@@ -415,7 +415,7 @@ class FulaModule: NSObject {
415415 NSLog ( " ReactNative createPeerIdentity encryptedKey2= \( encryptedKey) " )
416416 userDataHelper. add ( FulaModule . PRIVATE_KEY_STORE_ID, encryptedKey ?? " " )
417417 }
418-
418+
419419 // Assuming decryptMsg returns Data or throws an error if decryption fails
420420 guard let encryptedKeyData = encryptedKey, !encryptedKeyData. isEmpty else {
421421 throw NSError ( domain: " DecryptionError " , code: - 1 , userInfo: [ NSLocalizedDescriptionKey: " Encrypted key is empty " ] )
@@ -429,12 +429,12 @@ class FulaModule: NSObject {
429429 func decryptLibp2pIdentity( _ encryptedLibp2pId: String , with encryptionSecretKey: Data ) throws -> String {
430430 // Convert Data to [UInt8]
431431 let secretKeyBytes = [ UInt8] ( encryptionSecretKey)
432-
432+
433433 // Attempt decryption
434434 guard let decryptedBytes = try ? Cryptography . decryptMsg ( encryptedLibp2pId, secretKeyBytes) else {
435435 throw NSError ( domain: " DecryptionError " , code: 1 , userInfo: [ NSLocalizedDescriptionKey: " Failed to decrypt Libp2p ID " ] )
436436 }
437-
437+
438438 // Assuming decryptedBytes is an array of UInt8
439439 return String ( decoding: decryptedBytes, as: UTF8 . self)
440440 }
@@ -1519,6 +1519,25 @@ class FulaModule: NSObject {
15191519 reject ( " ERR_FULA " , " fetchContainerLogs failed " , error)
15201520 }
15211521 }
1522+ @objc ( findBestAndTargetInLogs: withTailCount: withResolver: withRejecter: )
1523+ func findBestAndTargetInLogs( containerName: String , tailCount: String , resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) {
1524+ do {
1525+ // Since fetchContainerLogs expects a String for tailCount, pass it directly
1526+ let result = try self . fula!. findBestAndTargetInLogs ( containerName, tailCount: tailCount)
1527+ guard let resultString = result. toUTF8String ( ) else {
1528+ // Handle the case where result.toUTF8String() returns nil
1529+ let error = NSError ( domain: " FULAErrorDomain " ,
1530+ code: 1007 , // Choose a suitable error code
1531+ userInfo: [ NSLocalizedDescriptionKey: " Failed to convert log data to string. " ] )
1532+ reject ( " ERR_FULA " , " Log Conversion Error " , error)
1533+ return
1534+ }
1535+ resolve ( resultString)
1536+ } catch let error as NSError {
1537+ print ( " fetchContainerLogs " , error. localizedDescription)
1538+ reject ( " ERR_FULA " , " fetchContainerLogs failed " , error)
1539+ }
1540+ }
15221541
15231542
15241543
0 commit comments