feat: Implement protocol packet classes and binary stream for network communication

This commit is contained in:
k1ngsterr1
2026-01-08 22:00:32 +05:00
parent b877d6fa73
commit 28a0d7a601
7 changed files with 790 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
package com.rosetta.messenger.ui.auth
import android.util.Log
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.*
@@ -27,6 +28,7 @@ import androidx.compose.ui.unit.sp
import com.rosetta.messenger.crypto.CryptoManager
import com.rosetta.messenger.data.AccountManager
import com.rosetta.messenger.data.EncryptedAccount
import com.rosetta.messenger.network.ProtocolManager
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
import kotlinx.coroutines.launch
@@ -426,6 +428,11 @@ fun SetPasswordScreen(
accountManager.saveAccount(account)
accountManager.setCurrentAccount(keyPair.publicKey)
// 🔌 Connect to server and authenticate
val privateKeyHash = CryptoManager.generatePrivateKeyHash(keyPair.privateKey)
Log.d("SetPasswordScreen", "🔌 Connecting to server...")
ProtocolManager.authenticate(keyPair.publicKey, privateKeyHash)
onAccountCreated()
} catch (e: Exception) {
error = "Failed to create account: ${e.message}"

View File

@@ -1,5 +1,6 @@
package com.rosetta.messenger.ui.auth
import android.util.Log
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.*
@@ -29,6 +30,8 @@ import com.rosetta.messenger.R
import com.rosetta.messenger.crypto.CryptoManager
import com.rosetta.messenger.data.AccountManager
import com.rosetta.messenger.data.DecryptedAccount
import com.rosetta.messenger.network.ProtocolManager
import com.rosetta.messenger.network.ProtocolState
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
@@ -249,6 +252,10 @@ fun UnlockScreen(
name = account.name
)
// 🔌 Connect to server and authenticate
Log.d("UnlockScreen", "🔌 Connecting to server...")
ProtocolManager.authenticate(account.publicKey, privateKeyHash)
accountManager.setCurrentAccount(publicKey)
onUnlocked(decryptedAccount)