Skip to main content

Module webvh_edit

Module webvh_edit 

Source
Expand description

Shared helpers for the webvh edit-did command.

Two flows live here, both producing an UpdateDidWebvhBody that the caller hands to either the SDK client (online) or the local op (offline):

  1. Interactive — pull the latest LogEntry’s published DID document, open it in $EDITOR via dialoguer::Editor, then walk a Confirm/Input chain asking the operator about the webvh parameters (pre-rotation count, watcher set, TTL, audit label).

  2. Non-interactive — load a JSON document from a file and apply CLI flags for the parameters. Suited for scripted flows / CI / TEE-host operators.

Both flows enforce the DID-id invariant: the operator can change everything about the document except the top-level id field. Mutating the DID identifier mid-stream would invalidate every existing reference to it; the WebVH spec treats it as a permanent commitment from the first LogEntry.

Structs§

EditFlags
Non-interactive flag bundle. Fed into build_options_from_flags to produce an UpdateDidWebvhBody. Keeping this separate from UpdateDidWebvhBody avoids parser/clap concerns leaking into the SDK wire type.
PreRotationStatus
Summary of the DID’s currently-effective pre-rotation setup, extracted from the on-disk log without needing to depend on didwebvh-rs. Surfaced before the “Override pre-rotation count?” prompt so the operator can see what they’re choosing to change.

Enums§

EditFlowError
Errors from the editor flow. Variant strings are operator-facing — formatted with leading lowercase so they read naturally after “Error: “ in the CLI output.

Functions§

assert_did_id_unchanged
Verify that the edited document carries the same id as the prior version. Returns Err(DidIdChanged) if mutated.
build_options_from_flags
Build an UpdateDidWebvhBody from the non-interactive flag bundle. The operator either runs in interactive mode (no flags → editor + prompts), supplies a --options-file for full control (witnesses included), or uses the per-field flags below.
confirm_publish
Final confirmation before publishing. Shows a one-line summary of what the body actually contains; operator hits Enter (default false) to abort. Returns Err(PublishCancelled) on false.
diff_summary
Operator-facing summary of how many top-level fields differ between the prior and edited documents. Cheap heuristic — the CLI prints it before asking “looks good?” so the operator has a sanity check on what they touched.
document_id
Read the id field from a DID document. Used to enforce the DID-id invariant after the operator edits the document.
extract_current_document
Extract the published DID document from the most recent non-empty line of a did.jsonl log. The line is parsed as a LogEntry and its state field is returned.
extract_latest_version_id
Extract the versionId of the last non-empty log entry. Used as the optimistic-concurrency precondition on the save call: the VTA rejects the update if the DID has moved on since this versionId. Returns Err(EmptyLog) when the log has no entries; returns Err(LogParse) if the latest entry is malformed or missing versionId (extremely unlikely on a valid did:webvh log — but fall back to None at the call site rather than blocking the save just because we couldn’t read a version).
extract_pre_rotation_status
Walk the log latest-first to find the most recent entry that declared nextKeyHashes. The latest such declaration is authoritative under did:webvh delta-parameter semantics.
launch_editor
Open initial in $EDITOR (via dialoguer::Editor), parse the result as JSON, and verify the DID id wasn’t mutated. Returns Ok(None) when the operator cancels (saves an empty buffer) — the caller treats that as “abort, don’t publish.”
prompt_webvh_params
Walk an interactive Confirm/Input chain asking the operator about the webvh parameters they want to change. edited_doc is the post-editor DID document (or None if the operator declined to edit). Returns the assembled UpdateDidWebvhBody.