# Local signing and explicit public-key trust

Local portability signatures use Ed25519. A valid signature proves possession
of a key, not a person's identity, permission to import, or release authority.
Trust is a separate, explicit local decision. Bundle verification never adds a
signer automatically. The current archive format is v2; explicit untrusted
recovery is a separate governed operation, never a trust-store import.

## Exchange public keys, not state directories

Initialize each ledger with `op-sys init` before changing trust. Each command
below uses the normally resolved local ledger; select a different one with
the global `--state-root` flag **before** the command.

```bash
op-sys trust list --local
op-sys trust fingerprint --key <local-key-id>
op-sys trust public export --key <local-key-id> --out /private/exchange/public.json
```

Send only that public JSON file. The recipient obtains the complete fingerprint
through an independently authenticated channel, such as a known in-person or
voice contact, and compares it before adding the key:

```bash
op-sys trust fingerprint --file /private/exchange/public.json
op-sys trust add --file /private/exchange/public.json \
  --expect-fingerprint <independently-confirmed-fingerprint> --label <known-owner>
op-sys trust list --trusted
```

Copying the fingerprint from the same unverified file or message is not
independent confirmation. The fingerprint binds the algorithm and public key,
not the file's owner, validity or revocation metadata. Review those assertions
through the authenticated owner channel too; the file is not a certificate.
`--expect-fingerprint` and a nonempty label are
mandatory; a mismatch fails before trust-store mutation. Re-adding an existing
fingerprint is idempotent only for identical public metadata and label. It
cannot silently erase a revocation. Deliberately removing and re-adding trust
is a new owner decision and can replace that history; preserve your records.

`fingerprint`, `list`, public export, legacy status, and signature verification
never create, migrate, repair or add local trust. Permission drift fails closed;
use `op-sys state permissions --repair` explicitly. Public export requires a
safe no-follow path outside the state root, writes only public fields, and
does not chmod the recipient's general output directory. The output file is
private by default (`0600`, or the protected Windows DACL); sharing is explicit.

## Storage and identity

Within the private state root, `trust/index.json` publishes the active local
key ID and non-secret local/external references. `trust/private/<key-id>.json`
holds a 32-byte seed and matching public metadata. `trust/public/` retains
local public documents; `trust/trusted/` holds external public documents plus
label, source (`public-key-file`) and the local trust time. Directories are
`0700` and files `0600` on POSIX; Windows uses the existing current-user/SYSTEM
protected-DACL model. A normal user account and its agents share that account's
authority: this is not protection against malicious same-account code.

The fingerprint is `ed25519:sha256:` followed by canonical unpadded base64url
of SHA-256 over `b"Ed25519\x00" + raw_public_key`. Key IDs are `ed25519_` plus
that digest in lowercase hex. Public/trusted filenames encode the fingerprint
as `ed25519-sha256-<base64url-digest>.json` because colons are not portable to
Windows. There are no alternate accepted fingerprint spellings.

Public JSON has exactly `schema` (`op-sys.public-key.v1`), `algorithm`
(`Ed25519`), `public_key` (canonical base64url), `fingerprint`, `owner`,
`created_at`, `not_before`, `sign_until`, `revoked_at`, `revocation_reason`,
`compromised_at`, and `compromise_reason`. Times are integer UTC Unix seconds;
unset lifecycle fields are null. Treat owner/reason labels as public data.
The index, list results, public export and CLI outputs never contain seeds.
Private and public identity/lifecycle metadata must agree before signing.

The complete trust tree and legacy `keystore.json` are excluded from signed
and unsigned bundles, even if a workflow reference selects them under a
different archive name. An archive containing any normalized `trust/` member
fails with `bundle_trust_reserved`; legacy keystores fail with
`legacy_private_material`. Import never replaces local keys or trust decisions.
Users can still put sensitive content in ordinary artifacts; review those
independently. The system cannot identify arbitrary user-made secret copies.

## Rotation, revocation and historical signatures

```bash
op-sys trust rotate --owner <public-owner-label>
op-sys trust revoke <fingerprint-or-local-key-id> --reason <public-reason>
op-sys trust revoke <fingerprint> --reason <public-reason> --compromised-at <unix-seconds>
op-sys trust remove <external-fingerprint>
```

`keygen` and `rotate` activate a fresh key with a 90-day signing interval.
Rotation retains historical public metadata and private files; it does not
revoke the previous key. Exchange and confirm the new public fingerprint.
Revocation immediately disables local signing; no fallback key is activated.
Compromise time must be between creation and now; repeated reports retain the
earliest known compromise. Notify every recipient: local revocation does not
automatically propagate. Recipients must record it in their own trusted store.
`remove` removes external trust only, not local private custody.

The byte-oriented Python API is `sign_bytes(root, message)` and
`verify_signature(root, message, signature)`. The JSON signature envelope
(`op-sys.signature.v1`) includes algorithm, key ID, fingerprint, public-key
reference, public key, signed-at and a canonical base64url 64-byte signature.
All identity fields and signed-at are authenticated with a domain-separated,
length-framed message. This is not a raw-signature interchange format.
Verification returns independent facts:

- `cryptographically_valid`: the strict Ed25519 signature verifies;
- `trusted`: this key is currently a retained local identity or explicitly trusted external key;
- `signer_status_at_signing`: `valid`, `expired`, `not_yet_valid`, `revoked`,
  `compromised`, `future`, or `unknown`;
- `trust_evaluated_at`: the verifier's local evaluation time.

Current expiry does not invalidate a signature made during the signing interval.
Revocation/compromise apply at their recorded effective times. Cryptographic
validity alone is insufficient: the current bundle bridge requires it, local
trust, and `valid` historical status, plus all normal archive/state/policy gates.
`signed_at` is the signer's authenticated **claim**, not a trusted timestamp.
A stolen key can backdate signatures; historical status is not proof that an
artifact predates compromise. Obtain independent time evidence or distrust all
affected artifacts when that distinction matters. Clock rollback and manual
metadata edits by the account owner are not prevented.

## Legacy migration and destruction

First upgraded initialization, key generation, trust add or low-level signing quarantines
an existing valid HMAC keystore under `trust/private/legacy-hmac.json`. It
publishes a non-secret index reference before checked removal of the old file,
then creates a fresh Ed25519 identity. This never converts, activates or exports
an HMAC key. Old HMAC signatures cannot become verified Ed25519 signatures.

Bundle-v2 export is deliberately different from low-level key provisioning:
it requires an existing active signer and fails with `no_active_key` otherwise,
without generating keys or quarantining the old keystore. Explicit `trust
keygen` performs that custody transition. Bundle verification is read-only;
default import accepts only `verified_trusted` v2 using the separate
[archival policy](/docs/raw/manuals/bundle-v2.md). Unsigned or v1 inspection is not authorization.

The quarantine's recovery window is 30 days from first migration, preserved
across retries. It is inactive and marked insecure throughout. Expiry closes
the window, but does not automatically delete material. The separate
[bundle-v2 legacy recovery flow](/docs/raw/manuals/bundle-v2.md#explicit-untrusted-recovery-policy-proposed)
discards incoming private-key material without changing this custody window.
Its proposed global deadline is December 22, 2026 UTC; every recovery also needs
an exact reason and a one-shot approval valid for no more than six hours.
The state owner must finish any separately authorized recovery and destruction
within the window, or obtain a separately reviewed recovery plan; do not extend
the deadline by editing files or roll back to HMAC signing.

```bash
op-sys trust legacy status
op-sys trust legacy destroy --yes
```

Destruction first permanently fences recovery in the index, then unlinks only
the checked quarantine file. If interrupted, status reports
`destruction_pending=true`, not successful deletion; repeat the command to
finish. Successful logical deletion does **not** guarantee physical erasure
from SSDs, snapshots, backups or memory. No plaintext recovery copy is created.
Deleting independently held backups requires their custodian's own authorized
procedure. An expired quarantine remains visible for explicit cleanup.

## Custody, failures and recovery responsibilities

Portable bundles are not private-key backups. A state owner who requires key
recovery must arrange a separately authorized encrypted, offline,
access-controlled backup, preserve public lifecycle history and verify recovery
in an isolated location. Never put private keys in Git, cloud sync, a bundle,
an artifact, a ticket, or a command argument. Loss of the only seed loses that
signing identity; generate a new key and repeat fingerprint exchange instead
of claiming an old identity was recovered. Suspected exposure requires
revocation/compromise recording and recipient notification.

Cooperating mutations share the state-operation lock. New key files are
published before the index activates them. An interrupted generation can leave
private orphan files; these are never auto-adopted or deleted. Stop and inspect
private custody before manually reconciling them. Revocation disables the
active index entry before publishing public/private metadata; retries complete
only monotonic revocation updates. Corrupt or mismatched private/public data
fails closed, not automatic regeneration. Patch forward; an old binary must
not be used to reactivate HMAC or overwrite the trust directory.

Admission is bounded to 1,024 local/trusted/notary entries combined (including
disabled notary history), 16 KiB per individual key record, 256 KiB each for
the index and public notary catalog, and 1 MiB for legacy quarantine. These are safety limits,
not a key-retention policy; orphan files still consume disk. File operations
reuse the existing bounded, pinned no-follow portability primitives and their
documented same-account/OS limitations. No promise of hardware-backed custody,
untrusted co-tenant isolation, or guaranteed secret zeroization is made.

## Separate archival notary authority

Ordinary signer trust never confers authority to attest time. A local or trusted
signer key cannot simultaneously be a notary. Notary addition is public-only,
requires an initialized ledger/trust store, and does not generate a signing key.
Before adding it, independently authenticate its fingerprint, lifecycle, role,
clock, receipt retention and incident policy; different fingerprints alone do
not prove organizational independence. No production authority is built in.

```bash
op-sys trust notary add --file notary-public.json --expect-fingerprint '<confirmed>' --label '<authority>' --incident-policy op-sys.pre-cutoff-anchor.v1
op-sys trust notary list
op-sys trust notary revoke '<fingerprint>' --reason '<incident>' --compromised-at <unix-seconds>
op-sys trust notary remove '<fingerprint>'
```

The private `trust/notaries.json` contains only public keys/metadata and is
excluded with the whole trust tree from every portable export/import. It is
bounded, no-follow read, and atomically replaced under the same operation lock.
Verification snapshots are observation-only, include no seed/legacy read, and
never bootstrap state or repair permissions. An orphan catalog without the
normal trust index cannot be automatically adopted. Corruption fails closed.

Revocation is monotonic and compromise preserves the earliest reported time.
Any known notary revocation/compromise invalidates all its receipts under this
incident policy. `remove` retains a permanently disabled public history record;
the same fingerprint cannot be re-added as either notary or ordinary signer to
erase its history. Removal does not recover capacity under the combined bound.
There is no automatic history cleanup or manual-reset recommendation; review
retention/limits with the trust owner and introduce a newly authenticated key.

Verification and import apply their own policy and authorization checks.
Configure actual trust roots and any notary service explicitly.

## Provider and updates

The runtime uses an MIT-licensed subset of `warner/python-pure25519`
(commit `c88a6aeee0653c46c429f096ec3090388f77525a`). The wrapper enforces
canonical encodings, `S < L` and nonidentity prime-subgroup public/R points.
The pure-Python provider is **not constant-time**. Do not use it as a
side-channel-resistant signing service or assume that valid signatures establish
trust in a signer. Protect signing keys and configure accepted roots explicitly.
