> ## Documentation Index
> Fetch the complete documentation index at: https://docs.privacyboost.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Wallet integration

# Wallet Integration

This guide covers wallet connection and authentication for the Privacy Boost CLI.

## Private Key Authentication

The CLI uses private keys for authentication (no interactive wallet prompts):

```bash theme={null}
privacy-boost login --private-key $PRIVATE_KEY
```

Output:

```
Logged in!
  Wallet Address:  0x1234...5678
  Privacy Address: 0x9abc...def0
  MPK:             0xfedc...ba98

Session saved! Future commands won't require --private-key.
```

## Programmatic Usage (Rust)

```rust theme={null}
use privacy_boost_cli::{PrivacyBoostCLI, CliConfig, AuthResult};

let config = CliConfig::new(
    "https://optimism.sepolia.privacyboost.io".into(),
    0,
    String::new(),
    "https://sepolia.optimism.io".into(),
);

let sdk = PrivacyBoostCLI::new(config)?;

let private_key = std::env::var("PRIVATE_KEY")?;
let result = sdk.authenticate(&private_key, None, None)?;

match result {
    AuthResult::Authenticated(login) => {
        println!("Wallet: {}", login.wallet_address);
        println!("Privacy Address: {}", login.privacy_address);
        println!("MPK: {}", login.mpk);
    }
    AuthResult::CredentialRequired(challenge) => {
        let login = sdk.submit_credential(&credential)?;
        println!("Privacy Address: {}", login.privacy_address);
    }
}
```

## Key Sources

```rust theme={null}
use privacy_boost_cli::KeySource;

// Default: derive keys from wallet signature
sdk.authenticate(&private_key, None, None)?;

// From mnemonic
sdk.authenticate(&private_key, Some(KeySource::Mnemonic {
    phrase: "your twelve word mnemonic phrase goes here ...".into(),
}), None)?;

// From raw seed (testing)
sdk.authenticate(&private_key, Some(KeySource::RawSeed {
    hex_seed: "0x...".into(),
}), None)?;
```

## Network Presets

```rust theme={null}
use privacy_boost_cli::NetworkPreset;

// Use a network preset
let config = NetworkPreset::OpSepolia.config();
let sdk = PrivacyBoostCLI::new(config)?;

// Or local development
let config = NetworkPreset::Local.config();
```

Preset aliases:

* **Local**: `"local"`, `"localhost"`, `"dev"`
* **OpSepolia**: `"op-sepolia"`, `"optimism-sepolia"`, `"opsepolia"`

## Environment Configuration

```bash theme={null}
export SERVER_URL="https://optimism.sepolia.privacyboost.io"
export RPC_URL="https://sepolia.optimism.io"
export WETH_CONTRACT_ADDRESS="0x4200000000000000000000000000000000000006"
export PRIVATE_KEY="0x..."
```

## Logout

```bash theme={null}
# Full logout
privacy-boost logout
```

```rust theme={null}
sdk.logout(); // Clears all state

// Or just clear the JWT (keeps keys)
sdk.clear_session();
```

## Check Status

```bash theme={null}
privacy-boost status
```

Output:

```
Status
------
Connected: Yes
Authenticated: Yes
Wallet Address: 0x1234...5678
Privacy Address: 0x9abc...def0
MPK: 0xfedc...ba98
```

```rust theme={null}
let status = sdk.get_status();
println!("Connected: {}", status.connected);
println!("Authenticated: {}", status.authenticated);
```

## Error Handling

```rust theme={null}
match sdk.authenticate(&private_key, None, None) {
    Ok(result) => { /* handle auth result */ }
    Err(CliError::InvalidPrivateKey { message }) => {
        println!("Invalid private key: {}", message);
    }
    Err(CliError::NetworkError { message }) => {
        println!("Network error: {}", message);
    }
    Err(CliError::InvalidConfig { message }) => {
        println!("Configuration error: {}", message);
    }
    Err(e) => println!("Auth failed: {:?}", e),
}
```

## Best Practices

### 1. Use Environment Variables for Keys

Never hardcode private keys. Use environment variables or config files.

### 2. Save Sessions

After authentication, sessions are saved automatically. Future commands don't need `--private-key`.

## Next Steps

* [Session Storage](./session-storage)
* [Deposits Guide](./deposits)
* [Network Presets](./network-presets)
* [Commands Reference](./commands)
