| Crates.io | iroh-persist |
| lib.rs | iroh-persist |
| version | 0.1.5 |
| created_at | 2025-10-30 19:34:49.415028+00 |
| updated_at | 2025-11-14 15:58:28.246234+00 |
| description | Library to persist Iroh secret keys |
| homepage | https://github.com/node2own/iroh-persist |
| repository | https://github.com/node2own/iroh-persist |
| max_upload_size | |
| id | 1908867 |
| size | 131,494 |
Library to persist Iroh secret keys.
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.
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...
Use --persist-at <file> instead of --persist if you need more than one
secret key for the same app.
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.)