Skip to content

node2own/iroh-persist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.)

About

Library to persist Iroh secret keys

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •