Files
fips/src/main.rs
T
Johnathan Corgan b80b3fbecf Add YAML configuration system and nsec encoding
Configuration system:
- New config module with cascading file search
- Priority: ./fips.yaml > ~/.config/fips/ > ~/.fips.yaml > /etc/fips/
- Identity section with optional nsec (bech32 or hex format)
- Generate new keypair if nsec not configured

Identity module additions:
- encode_nsec() and decode_nsec() for NIP-19 bech32 format
- decode_secret() accepts both nsec and hex formats
- Identity::from_secret_str() constructor

Dependencies: serde, serde_yaml, dirs, hex

41 tests passing (20 identity + 15 config + 6 nsec)
2026-01-25 01:08:02 +00:00

62 lines
1.8 KiB
Rust

use fips::Config;
fn main() {
println!("FIPS Node Startup");
println!("=================\n");
// Load configuration from standard search paths
println!("1. Loading configuration...");
println!(" Search paths (in priority order, lowest to highest):");
for path in Config::search_paths() {
let exists = path.exists();
let status = if exists { "[found]" } else { "[not found]" };
println!(" {} {}", status, path.display());
}
println!();
let (config, loaded_paths) = match Config::load() {
Ok(result) => result,
Err(e) => {
eprintln!(" Error loading config: {}", e);
std::process::exit(1);
}
};
if loaded_paths.is_empty() {
println!(" No config files found, using defaults.");
} else {
println!(" Loaded {} config file(s):", loaded_paths.len());
for path in &loaded_paths {
println!(" - {}", path.display());
}
}
// Create identity from configuration
println!("\n2. Initializing identity...");
let identity = match config.create_identity() {
Ok(id) => id,
Err(e) => {
eprintln!(" Error creating identity: {}", e);
std::process::exit(1);
}
};
if config.has_identity() {
println!(" Using configured identity.");
} else {
println!(" No identity configured, generated new keypair.");
}
println!();
if let Some(nsec) = &config.identity.nsec {
println!(" nsec: {}", nsec);
} else {
println!(" nsec: (generated)");
}
println!(" npub: {}", identity.npub());
println!(" node_id: {}", identity.node_id());
println!(" IPv6 address: {}", identity.address());
println!("\nReady.");
}