iroh-persist

Crates.ioiroh-persist
lib.rsiroh-persist
version0.1.5
created_at2025-10-30 19:34:49.415028+00
updated_at2025-11-14 15:58:28.246234+00
descriptionLibrary to persist Iroh secret keys
homepagehttps://github.com/node2own/iroh-persist
repositoryhttps://github.com/node2own/iroh-persist
max_upload_size
id1908867
size131,494
Jeroen van Maanen (jeroenvanmaanen)

documentation

README

iroh-persist

Library to persist Iroh secret keys.

Usage pattern

Build a command-line app with clap and declare a struct for common arguments like this:

#[derive(Parser, Debug)]
pub struct CommonArgs {
    /// Use a persistent secret key
    #[arg(long)]
    persist: bool,
    /// Write and read the secret key at the given location
    #[arg(long)]
    persist_at: Option<PathBuf>,
    /// More arguments...
}

Then use the parsed flags (assumed they ended up in a variable named common) like so:

let secret_key = iroh_persist::KeyRetriever::new("my-app")
    .persist(common.persist)
    .persist_at(common.persist_at.as_ref())
    .lenient()
    .get()
    .await;
let endpoint = Endpoint::builder().secret_key(secret_key).bind().await?;

Without .lenient() the .get().await will not fallback to an ephemeral key and returns a Result<SecretKey> rather than a SecretKey.

Migrate from IROH_SECRET to iroh-persist

If you used to invoke:

IROH_SECRET=<hex-key> my-app args...

Then invoke this at least once:

IROH_SECRET=<hex-key> my-app --persist args...

Then iroh-persist will save the key on disk. After that, the following invocation will suffice:

my-app --persist args...

Specify the key file

Use --persist-at <file> instead of --persist if you need more than one secret key for the same app.

Logging

To get some messages from the app, invoke it with:

RUST_LOG='iroh_persist=info' my-app --persist args...

Replace info with debug, warn, or error to see either more or less messages. (See also env_logger.)

Commit count: 0

cargo fmt