Skip to main content

Crate stratum_node_cli

Crate stratum_node_cli 

Source
Expand description

The library behind stratum, the operator’s client for a Stratum node.

Pre-release: this is 0.1.0-alpha. The commands, output and API may change before 0.1.0, and nothing built on it has been deployed yet.

A Stratum node serves an administrative API on loopback only. stratum talks to that API over plain HTTP and holds the operator’s own Nostr key; it never sees the node key or the node’s state volume, except that stratum setup reads the bootstrap token file the operator points it at.

  • URLs. LoopbackUrl accepts http:// URLs whose host is an IPv4 address in 127.0.0.0/8, [::1] or localhost, and nothing else: Step 1 has no TLS. localhost is connected to 127.0.0.1 without a name lookup.
  • Operator keys. generate_key_file writes a fresh key as one nsec1… line to a file created exclusively with mode 0600; load_key_file refuses symbolic links and modes wider than 0600. The secret is never printed, logged or returned as text.
  • Changes. parse_changes reads --set path=value arguments typed by the schema in stratum-node-config.
  • Commands. Session runs each command against one node: status, config (schema, show, preview, apply), setup, sign-challenge, audit checkpoint and backup. Every authenticated request is signed with NostrSecretKey::sign_request over the exact URL, method and body bytes sent.
  • Exit codes. Failures are CliErrors, each mapped to a stable code in exit.

The crate targets Unix: key files rely on Unix permission bits.

§Example

use stratum_node_cli::{Output, OutputFormat, Session};

let output = Output::new(OutputFormat::Human);
let session = Session::new("http://127.0.0.1:7460".parse()?, Some("operator.nsec".into()), output);
let code = session.status().unwrap_or_else(|err| {
    output.error(&err);
    err.exit_code()
});
std::process::exit(i32::from(code));

Modules§

exit
The process exit codes of stratum, stable across releases.

Structs§

ApplyOptions
Options for Session::config_apply.
BootstrapToken
The bootstrap token: 64 lowercase hex digits proving entitlement to claim a node.
LoopbackUrl
A plain-HTTP URL whose host is a loopback literal, kept in canonical form.
Output
The terminal writer used by every command.
Session
One node, one optional operator key file and one output format: the context every stratum command runs in.
SetupOptions
Options for Session::setup.

Enums§

CliError
Why a stratum command failed.
Confirmation
Whether a command that changes the node may proceed without asking.
KeyFileError
Why an operator key file could not be created or loaded.
OutputFormat
How results are written to standard output.
ParseChangeError
Why a --set argument could not be parsed.
ParseUrlError
The reasons a URL is refused by LoopbackUrl.
PrivateFileError
Why a private file could not be created or read.
TokenFileError
Why the bootstrap token file could not be read.

Constants§

DEFAULT_URL
The default node URL: the loopback address the controller listens on by default.

Functions§

generate_key_file
Creates a new operator key file holding a freshly generated key.
load_key_file
Loads an operator key file written by generate_key_file.
parse_changes
Parses --set path=value arguments into configuration changes, typed by the schema in stratum-node-config.