Skip to main content

Crate stratum_node_config

Crate stratum_node_config 

Source
Expand description

Schema, validation, comment-preserving editing and public hashing for a Stratum node’s stratum.toml.

Pre-release. This is 0.1.0-alpha: the API and the file format may change before 0.1.0.

§The model

  • One schema table. schema returns the only definition of the configuration: every field’s dotted path, ValueType, default, description and ApplyClass. Validation, the seed document, the typed Config, the public view and the serialised form served by an HTTP schema endpoint are all derived from it, so they cannot drift.
  • Documents. ConfigDocument::parse turns stratum.toml text into a validated document or a list of every ValidationError: syntax, unknown keys, wrong types, out-of-range values, field rules and cross-field conflicts. A document carries schema_version = SCHEMA_VERSION; any other version is rejected. Omitted fields take their defaults.
  • Preview. preview applies a list of Changes to base text and reports, without side effects, the edited text (comments and order kept), a unified diff, the changed fields in schema order with secret references redacted, each change’s apply class, the strictest class overall, and every validation error of the result.
  • Apply classes. ApplyClass::Live < ApplyClass::Restart < ApplyClass::Redeploy; the strictest class of a set of changes is their maximum and tells the caller what it must do for them to take effect.
  • Public hash. ConfigDocument::public_config is the effective configuration minus secret-reference fields, and ConfigDocument::public_hash is SHA-256 over its documented canonical encoding (PublicConfig::canonical_text) prefixed with PUBLIC_HASH_VERSION. Changing a secret reference leaves the hash unchanged; changing anything else changes it.

The crate is pure: it performs no filesystem, network, clock or environment access and never resolves a secret reference. Text longer than MAX_DOCUMENT_BYTES (256 KiB) is refused before it is parsed. A syntax error reports only its line and column, never the parser’s description, which can quote the input.

backup.age_recipients accepts only post-quantum hybrid age recipients (age1pq1…), checked structurally (lowercase Bech32, checksum, padding, key length) without depending on age. The list holds at most MAX_BACKUP_RECIPIENTS (32) entries, the most a Stratum node encrypts a backup to.

§Examples

use stratum_node_config::{preview, schema, ApplyClass, Change, ConfigDocument};

// Start from the generated seed, which validates and holds the defaults.
let seed = schema().seed_text();
let before = ConfigDocument::parse(&seed)?;

// Preview an edit and inspect it before committing anything.
let p = preview(&seed, &[Change::new("node.name", "alpha")])?;
assert!(p.errors().is_empty());
assert_eq!(p.strictest_apply_class(), Some(ApplyClass::Live));

let after = p.into_document().ok_or("edit should be valid")?;
assert_eq!(after.config().node_name(), "alpha");
assert_ne!(after.public_hash(), before.public_hash());

Structs§

Change
A requested edit: set the field at path to value.
Config
The effective configuration of a valid document, with one strongly typed getter per schema field.
ConfigDocument
A validated stratum.toml document: its exact text plus the effective configuration with defaults filled in.
FieldChange
One entry of a preview’s change list: a field whose effective value the edit changes.
FieldDescriptor
One field of the schema: its path, type, default, description and apply class.
Fields
Iterator over the schema’s FieldDescriptors, returned by Schema::fields.
Preview
The result of preview: what an edit would do, computed without side effects.
PublicConfig
The effective configuration with every secret-reference field removed.
PublicHash
A SHA-256 public-configuration hash, from PublicConfig::hash.
PublicIter
Iterator over a PublicConfig’s (path, value) pairs, returned by PublicConfig::iter.
Schema
The complete stratum.toml schema.
SecretRef
An opaque reference to a secret held by a custody service.
ValidationError
One problem found while validating a configuration document.
ValidationErrors
A non-empty list of every ValidationError found in one document.

Enums§

ApplyClass
When a changed field takes effect.
PreviewError
Why preview could not produce an edited document.
ValidationErrorKind
The category of a ValidationError.
Value
A configuration value, independent of any TOML or JSON library.
ValueType
The type of a schema field, including any range or variant set.

Constants§

MAX_BACKUP_RECIPIENTS
The largest number of entries backup.age_recipients may hold.
MAX_DOCUMENT_BYTES
The largest stratum.toml this crate accepts, in bytes: 256 KiB.
PUBLIC_HASH_VERSION
The version of the public-configuration hash format.
REDACTED
The text that stands in for a secret-reference value in change lists and Debug output.
SCHEMA_VERSION
The version of the stratum.toml schema this library implements.

Functions§

preview
Computes what applying changes to base_text would produce.
schema
Returns the stratum.toml schema.