wallet.rs - Key Management

The wallet module implements Ed25519 cryptographic key management, transaction creation, and secure wallet persistence for Bunkercoin. It provides the cryptographic foundation for all user operations while maintaining compatibility with radio-constrained environments.

Wallet Structure and Key Management

// src/wallet.rs (lines 6-12)
pub struct Wallet {
    secret_key: SecretKey,
    public_key: PublicKey,
    current_nonce: u64,
}

Ed25519 Key Generation

// src/wallet.rs (lines 14-23)
impl Wallet {
    pub fn generate() -> Self {
        let mut csprng = OsRng;
        let secret_key = SecretKey::generate(&mut csprng);
        let public_key: PublicKey = (&secret_key).into();
        Self {
            secret_key,
            public_key,
            current_nonce: 0,
        }
    }
}

Cryptographically Secure Random Generation: The wallet uses OsRng (Operating System Random Number Generator) which provides cryptographically secure randomness from the OS entropy pool, ensuring unpredictable private key generation.

Wallet Persistence and Recovery

JSON Serialization Format

Security Considerations

Transaction Creation and Signing

Deterministic Nonce Management

The wallet implements a simplified nonce system for transaction ordering:

Feature
Implementation
Radio Benefits

Sequential Nonces

Incremented for each transaction

Prevents replay attacks

Persistent State

Saved with wallet data

Survives node restarts

Deterministic Ordering

Enables consistent transaction processing

Critical for disconnected networks

Public Key Operations

Address Generation

The wallet provides both hexadecimal and binary address formats:

  • Hex format: Human-readable for CLI operations and radio transmission

  • Binary format: Efficient for programmatic use and blockchain storage

Integration with CLI Commands

Wallet Command Implementations

Radio-Optimized Features

Compact Key Format

  • 32-byte public keys: Ed25519 provides optimal size-to-security ratio

  • 64-byte signatures: Minimal signature overhead for radio transmission

  • Hex encoding: Human-readable format suitable for voice transmission

Offline Operation Capability

The wallet is designed for disconnected operation:

  • No network dependencies: All operations work offline

  • File-based persistence: Survives power failures and restarts

  • Manual transaction export: Transactions can be saved to files for radio transmission

Error Handling and Recovery

Graceful Degradation

Backup and Recovery Strategies

  • JSON export: Wallet data can be manually copied for backup

  • Key derivation: Future enhancement for BIP32-style HD wallets

  • Paper backup: Hex-encoded private keys suitable for paper storage

Security Model

Cryptographic Properties

Property
Implementation
Security Level

Private Key Security

Ed25519 scalar (32 bytes)

128-bit security equivalent

Signature Algorithm

EdDSA with Curve25519

Post-quantum resistant candidate

Random Number Generation

OS entropy pool (OsRng)

Cryptographically secure

Key Derivation

Direct from secret scalar

No key stretching (future enhancement)

Threat Model Considerations

  • Physical access: Private keys stored in plaintext on disk

  • Memory attacks: Private keys held in process memory during operation

  • Side-channel attacks: No specific protections against timing attacks

  • Quantum resistance: Ed25519 provides some quantum resistance but not full protection

Future Enhancements

Planned Wallet Features

  • Hardware security module support: Integration with HSMs for enhanced security

  • Multi-signature wallets: m-of-n signature schemes for shared control

  • Hierarchical deterministic keys: BIP32-style key derivation for better backup

  • Encrypted storage: Password-protected wallet files

Radio Integration Enhancements

  • QR code generation: Visual encoding for air-gapped key transfer

  • Voice encoding: Audio-friendly private key backup formats

  • Radio-specific addressing: Ham radio callsign integration for addressing

  • Mesh network routing: Wallet-aware routing for packet radio networks

Last updated