Unlock seed once at startup, pass identity to all commands

- main.rs unlocks seed once, prompts passphrase once per app launch
- Identity passed as parameter to send, recv, register, chat
- No more redundant load_seed() calls (was prompting passphrase multiple times)
- info command uses pre-unlocked identity directly

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-27 07:49:51 +04:00
parent 37a4c3c54f
commit 3ffac0c751
5 changed files with 36 additions and 47 deletions

View File

@@ -1,16 +1 @@
use crate::keystore;
pub fn run() -> anyhow::Result<()> {
let seed = keystore::load_seed()?;
let identity = seed.derive_identity();
let pub_id = identity.public_identity();
println!("Fingerprint: {}", pub_id.fingerprint);
println!("Signing key: {}", hex::encode(pub_id.signing.as_bytes()));
println!(
"Encryption key: {}",
hex::encode(pub_id.encryption.as_bytes())
);
Ok(())
}
// Info is now handled directly in main.rs with the pre-unlocked identity.

View File

@@ -71,10 +71,11 @@ pub fn run() -> Result<()> {
Ok(())
}
/// Register the local bundle with a server. Called automatically before first send.
pub async fn register_with_server(server_url: &str) -> Result<()> {
let seed = keystore::load_seed()?;
let identity = seed.derive_identity();
/// Register the local bundle with a server using an already-unlocked identity.
pub async fn register_with_server_identity(
server_url: &str,
identity: &warzone_protocol::identity::IdentityKeyPair,
) -> Result<()> {
let pub_id = identity.public_identity();
let fp = pub_id.fingerprint.to_string();

View File

@@ -1,17 +1,15 @@
use anyhow::{Context, Result};
use warzone_protocol::identity::IdentityKeyPair;
use warzone_protocol::ratchet::RatchetState;
use warzone_protocol::types::Fingerprint;
use warzone_protocol::x3dh;
use x25519_dalek::PublicKey;
use crate::cli::send::WireMessage;
use crate::keystore;
use crate::net::ServerClient;
use crate::storage::LocalDb;
pub async fn run(server_url: &str) -> Result<()> {
let seed = keystore::load_seed()?;
let identity = seed.derive_identity();
pub async fn run(server_url: &str, identity: &IdentityKeyPair) -> Result<()> {
let our_pub = identity.public_identity();
let our_fp = our_pub.fingerprint.to_string();
let db = LocalDb::open()?;

View File

@@ -1,10 +1,10 @@
use anyhow::{Context, Result};
use warzone_protocol::identity::IdentityKeyPair;
use warzone_protocol::ratchet::{RatchetMessage, RatchetState};
use warzone_protocol::types::Fingerprint;
use warzone_protocol::x3dh;
use x25519_dalek::PublicKey;
use crate::keystore;
use crate::net::ServerClient;
use crate::storage::LocalDb;
@@ -26,9 +26,7 @@ pub enum WireMessage {
},
}
pub async fn run(recipient_fp: &str, message: &str, server_url: &str) -> Result<()> {
let seed = keystore::load_seed()?;
let identity = seed.derive_identity();
pub async fn run(recipient_fp: &str, message: &str, server_url: &str, identity: &IdentityKeyPair) -> Result<()> {
let our_pub = identity.public_identity();
let db = LocalDb::open()?;
let client = ServerClient::new(server_url);