feat: Remove debug logging from various components for cleaner code
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.rosetta.messenger.providers
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.*
|
||||
import com.rosetta.messenger.crypto.CryptoManager
|
||||
import com.rosetta.messenger.database.DatabaseService
|
||||
@@ -61,7 +60,6 @@ class AuthStateManager(
|
||||
// 🚀 ОПТИМИЗАЦИЯ: Используем кэш если он свежий
|
||||
val currentTime = System.currentTimeMillis()
|
||||
if (accountsCache != null && (currentTime - lastAccountsLoadTime) < accountsCacheTTL) {
|
||||
Log.d(TAG, "📚 Using cached accounts list")
|
||||
_state.update { it.copy(
|
||||
hasExistingAccounts = accountsCache!!.isNotEmpty(),
|
||||
availableAccounts = accountsCache!!
|
||||
@@ -77,14 +75,11 @@ class AuthStateManager(
|
||||
accountsCache = accountKeys
|
||||
lastAccountsLoadTime = currentTime
|
||||
|
||||
Log.d(TAG, "📚 Loaded ${accounts.size} accounts from database")
|
||||
|
||||
_state.update { it.copy(
|
||||
hasExistingAccounts = hasAccounts,
|
||||
availableAccounts = accountKeys
|
||||
)}
|
||||
)}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to load accounts", e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +96,6 @@ class AuthStateManager(
|
||||
)}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to check auth status", e)
|
||||
_state.update { it.copy(
|
||||
status = AuthStatus.Unauthenticated
|
||||
)}
|
||||
@@ -118,31 +112,21 @@ class AuthStateManager(
|
||||
password: String
|
||||
): Result<DecryptedAccountData> = withContext(Dispatchers.Default) {
|
||||
try {
|
||||
Log.d(TAG, "🔧 Creating new account from seed phrase")
|
||||
Log.d(TAG, " - Seed phrase: ${seedPhrase.size} words")
|
||||
Log.d(TAG, " - Password length: ${password.length}")
|
||||
|
||||
// Step 1: Generate key pair from seed phrase (using BIP39)
|
||||
val keyPair = CryptoManager.generateKeyPairFromSeed(seedPhrase)
|
||||
Log.d(TAG, "🔑 Generated keys from seed phrase")
|
||||
Log.d(TAG, " - Public Key: ${keyPair.publicKey.take(20)}...")
|
||||
Log.d(TAG, " - Private Key length: ${keyPair.privateKey.length}")
|
||||
|
||||
// Step 2: Generate private key hash for protocol
|
||||
val privateKeyHash = CryptoManager.generatePrivateKeyHash(keyPair.privateKey)
|
||||
Log.d(TAG, "🔐 Generated private key hash: $privateKeyHash")
|
||||
|
||||
// Step 3: Encrypt private key with password
|
||||
val encryptedPrivateKey = CryptoManager.encryptWithPassword(
|
||||
keyPair.privateKey, password
|
||||
)
|
||||
Log.d(TAG, "🔒 Encrypted private key: ${encryptedPrivateKey.take(50)}...")
|
||||
|
||||
// Step 4: Encrypt seed phrase with password
|
||||
val encryptedSeedPhrase = CryptoManager.encryptWithPassword(
|
||||
seedPhrase.joinToString(" "), password
|
||||
)
|
||||
Log.d(TAG, "🔒 Encrypted seed phrase: ${encryptedSeedPhrase.take(50)}...")
|
||||
|
||||
// Step 5: Save to database
|
||||
val saved = withContext(Dispatchers.IO) {
|
||||
@@ -157,8 +141,6 @@ class AuthStateManager(
|
||||
return@withContext Result.failure(Exception("Failed to save account to database"))
|
||||
}
|
||||
|
||||
Log.d(TAG, "✅ Account saved to database successfully")
|
||||
|
||||
// Step 6: Create decrypted account object
|
||||
val decryptedAccount = DecryptedAccountData(
|
||||
publicKey = keyPair.publicKey,
|
||||
@@ -176,19 +158,15 @@ class AuthStateManager(
|
||||
loadAccounts()
|
||||
|
||||
// Step 8: Connect and authenticate with protocol
|
||||
Log.d(TAG, "🌐 Connecting to protocol server...")
|
||||
ProtocolManager.connect()
|
||||
|
||||
// Give WebSocket time to connect before authenticating
|
||||
kotlinx.coroutines.delay(500)
|
||||
|
||||
Log.d(TAG, "🌐 Authenticating with protocol server...")
|
||||
ProtocolManager.authenticate(keyPair.publicKey, privateKeyHash)
|
||||
|
||||
Log.d(TAG, "✅ Account created and authenticated successfully!")
|
||||
Result.success(decryptedAccount)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to create account", e)
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
@@ -200,7 +178,6 @@ class AuthStateManager(
|
||||
seedPhrase: List<String>,
|
||||
password: String
|
||||
): Result<DecryptedAccountData> {
|
||||
Log.d(TAG, "📥 Importing account from seed phrase")
|
||||
return createAccount(seedPhrase, password)
|
||||
}
|
||||
|
||||
@@ -213,24 +190,15 @@ class AuthStateManager(
|
||||
password: String
|
||||
): Result<DecryptedAccountData> = withContext(Dispatchers.Default) {
|
||||
try {
|
||||
Log.d(TAG, "🔓 Unlocking account: ${publicKey.take(20)}...")
|
||||
Log.d(TAG, " - Password length: ${password.length}")
|
||||
|
||||
// Decrypt account from database
|
||||
val decryptedAccount = withContext(Dispatchers.IO) {
|
||||
databaseService.decryptAccount(publicKey, password)
|
||||
}
|
||||
|
||||
if (decryptedAccount == null) {
|
||||
Log.e(TAG, "❌ Failed to decrypt account - wrong password or account not found")
|
||||
return@withContext Result.failure(Exception("Invalid password or account not found"))
|
||||
}
|
||||
|
||||
Log.d(TAG, "✅ Account decrypted successfully")
|
||||
Log.d(TAG, " - Public Key: ${decryptedAccount.publicKey.take(20)}...")
|
||||
Log.d(TAG, " - Private Key Hash: ${decryptedAccount.privateKeyHash}")
|
||||
Log.d(TAG, " - Seed Phrase: ${decryptedAccount.seedPhrase.size} words")
|
||||
|
||||
// Update last used timestamp
|
||||
withContext(Dispatchers.IO) {
|
||||
databaseService.updateLastUsed(publicKey)
|
||||
@@ -243,19 +211,15 @@ class AuthStateManager(
|
||||
)}
|
||||
|
||||
// Connect and authenticate with protocol
|
||||
Log.d(TAG, "🌐 Connecting to protocol server...")
|
||||
ProtocolManager.connect()
|
||||
|
||||
// Give WebSocket time to connect before authenticating
|
||||
kotlinx.coroutines.delay(500)
|
||||
|
||||
Log.d(TAG, "🌐 Authenticating with protocol server...")
|
||||
ProtocolManager.authenticate(decryptedAccount.publicKey, decryptedAccount.privateKeyHash)
|
||||
|
||||
Log.d(TAG, "✅ Account unlocked and authenticated successfully!")
|
||||
Result.success(decryptedAccount)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to unlock account", e)
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
@@ -264,7 +228,6 @@ class AuthStateManager(
|
||||
* Logout - clears decrypted account from memory
|
||||
*/
|
||||
fun logout() {
|
||||
Log.d(TAG, "🚪 Logging out, clearing decrypted keys from memory")
|
||||
currentDecryptedAccount = null
|
||||
_state.update { it.copy(
|
||||
status = AuthStatus.Unauthenticated
|
||||
@@ -276,8 +239,6 @@ class AuthStateManager(
|
||||
*/
|
||||
suspend fun deleteAccount(publicKey: String): Result<Unit> = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
Log.d(TAG, "🗑️ Deleting account: ${publicKey.take(20)}...")
|
||||
|
||||
val success = databaseService.deleteAccount(publicKey)
|
||||
if (!success) {
|
||||
return@withContext Result.failure(Exception("Failed to delete account"))
|
||||
@@ -291,10 +252,8 @@ class AuthStateManager(
|
||||
}
|
||||
|
||||
loadAccounts()
|
||||
Log.d(TAG, "✅ Account deleted successfully")
|
||||
Result.success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to delete account", e)
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user