Skip to main content

Session Storage

This guide covers session persistence so you don’t need to re-authenticate on every run using the Privacy Boost CLI.

Automatic Session Persistence

After privacy-boost login, the CLI automatically saves the session. Subsequent commands use the saved session:
# First time — requires private key
privacy-boost login --private-key $PRIVATE_KEY

# Subsequent commands — no private key needed
privacy-boost balance --token $TOKEN
privacy-boost deposit --token $TOKEN --amount 1.0 --human

Programmatic Session Export/Import (Rust)

Export Session

if let Some(session) = sdk.export_session() {
    let json = serde_json::to_string(&session)?;
    std::fs::write("session.json", json)?;
    println!("Session saved");
}

Import Session

let json = std::fs::read_to_string("session.json")?;
let session: ExportedSession = serde_json::from_str(&json)?;

match sdk.import_session(&session) {
    Ok(true) => println!("Session restored"),
    Ok(false) => println!("Session invalid or expired"),
    Err(e) => println!("Import failed: {:?}", e),
}

ExportedSession

pub struct ExportedSession {
    pub wallet_public_key_x: String,
    pub wallet_public_key_y: String,
    pub viewing_key: String,
    pub viewing_public_key_x: String,
    pub viewing_public_key_y: String,
    pub nullifying_key: String,
    pub nullifying_public_key_x: String,
    pub nullifying_public_key_y: String,
    pub mpk: String,
    pub account_id: String,
    pub jwt: String,
    pub jwt_expiry: u64,
    pub wallet_address: String,
}

Configuration File

The CLI stores configuration at the default path:
let config_path = CliConfig::default_config_path()?;
println!("Config at: {:?}", config_path);

// Save config
config.save_to_default()?;

// Load config
let config = CliConfig::load_from_default()?;

Logout

# End session, clear saved state
privacy-boost logout
MethodWhat it doesNext login
logout()Clears everythingFull re-auth required
clear_session()Clears JWT onlyQuick re-auth (no signing)
// Full logout
sdk.logout();

// Quick session clear
sdk.clear_session();
Session files contain private keys. Store them securely and restrict file permissions.

Best Practices

1. Protect Session Files

chmod 600 session.json

2. Handle Expired Sessions

match sdk.import_session(&session) {
    Ok(true) => println!("Session restored"),
    Ok(false) | Err(_) => {
        // Re-authenticate
        sdk.authenticate(&private_key, None, None)?;
    }
}

3. Clean Up on Exit

// Delete session file on logout
sdk.logout();
std::fs::remove_file("session.json").ok();

Next Steps