// Clear sensitive data from memory after useprivateKey = nilkeyShares = nil// Use secure enclave when availableif SecureEnclave.isAvailable { // Store sensitive data in secure enclave}
// Use Keychain for sensitive data storageimport Securityfunc storePrivateKeySecurely(_ privateKey: String, for walletAddress: String) { let query: [String: Any] = [ kSecClass as String: kSecClassGenericPassword, kSecAttrAccount as String: walletAddress, kSecValueData as String: privateKey.data(using: .utf8)!, kSecAttrAccessible as String: kSecAttrAccessibleWhenUnlockedThisDeviceOnly ] SecItemAdd(query as CFDictionary, nil)}
do { let privateKey = try await ethereumWallet.exportPrivateKey()} catch { if let nsError = error as NSError? { switch nsError.code { case 1001: print("Access denied - authentication required") case 1002: print("Private key not available") case 1003: print("Security validation failed") default: print("Security error: \(error)") } }}