Metadata-Version: 2.5
Name: sm-revocation
Version: 0.2.0
Summary: Freshness-bounded revocation feeds for agent meshes on intermittent links: REVOKED, NOT_REVOKED(as_of) or UNKNOWN, from signed feeds any carrier can forward.
Project-URL: Homepage, https://agentclock.ai
Project-URL: Documentation, https://pypi.org/project/sm-revocation/#files
Author-email: StellarMinds <hello@stellarminds.ai>
License-Expression: MIT
License-File: LICENSE
Keywords: ai-agents,delay-tolerant,did,nanda,partition,revocation,verifiable
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: jcs>=0.2.1
Requires-Dist: sm-arp>=0.3.0
Requires-Dist: sm-feed>=0.3.1
Provides-Extra: dev
Requires-Dist: coverage>=7.0; extra == 'dev'
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff==0.15.13; extra == 'dev'
Requires-Dist: sm-renewal>=0.6.0; extra == 'dev'
Description-Content-Type: text/markdown

# sm-revocation

**Freshness-bounded revocation feeds for agent meshes on intermittent links**

Revocation assumes a reachable issuer. A CRL or an OCSP responder tells a relying
party that a credential is revoked only if the relying party can reach it, and a
mesh cut off from its issuer either keeps acting on old information without
knowing how old it is, or stops. `sm-revocation` is the third option: the issuer
publishes revocations on a signed, hash-chained [`sm-feed`](https://pypi.org/project/sm-feed/)
feed and re-signs the feed's head on a declared cadence; anyone who met the issuer
— a member, a relay, a vehicle, a store-and-forward bundle — can carry entries,
heads and pages onward; and a holder's view answers one of three things about a
subject at a time:

- **`REVOKED(effective_at, reason)`** — an issuer-signed revocation it holds;
- **`NOT_REVOKED(as_of)`** — it holds every revocation the issuer had signed up to a
  head the issuer itself dated `as_of`, and none names the subject;
- **`UNKNOWN(reason)`** — `behind`, `stale`, `not_covered`, `before_anchor` or
  `feed_misbehaved`, each a statement of what the view cannot rule out.

The caller bounds how old `as_of` may be. Past the bound the answer is `UNKNOWN`,
so a partitioned mesh knows how old its revocation information is and refuses past
the bound, instead of acting on it blind. This package owns the revocation payload
profile on `sm-feed`, the issuer's time obligations, the view, its conflict
evidence, and the adapters for [`sm-renewal`](https://pypi.org/project/sm-renewal/)
and [`sm-dat`](https://pypi.org/project/sm-dat/).

## What's new in 0.2.0 (`revocation/0.2`)

- **Witnessed heads.** A feed may name witnesses and a threshold in its genesis policy (`RevocationIssuer(..., witnesses=[...], witness_threshold=k)`). A view of such a feed counts a head towards `as_of` only when `k` named witnesses have co-signed it with `sm-feed` 0.3's `feed-cosignature/0.1` (SPEC §6.8). It takes them via `ingest_cosignature(c)` or `ingest_head(head, cosignatures=[...])`.
- **The freeze, closed for isolated holders that pin their witnesses.** A holder names the witness set it trusts (`FeedView(feed_id, witnesses=..., witness_threshold=...)`; a `renewal/0.5` attester uses its manifest's), and a policy naming another set breaks its chain. Without a pin, the issuer's own genesis chooses the witnesses, and a forked genesis can name ones it controls. A witness co-signs only the tip of the chain it has walked, never while it holds a later head, and only heads dated within its clock tolerance (`sm-feed` SPEC §9.2). Once a revoke has reached `n − k + 1` honest witnesses at `T`, no head below it is witnessed with a date past `T + D`. A frozen holder therefore goes `stale` on schedule without meeting anyone (vector 31; THREATMODEL).
- **Model-checked.** `proofs/witness_model.py` explores every interleaving of a Byzantine issuer against a fixed witness set, with n = 3 or 4, k = 2 or 3 and 0 to k − 1 deviating witnesses, up to a horizon of 3 or 4 steps. That is 13 cases, the largest 5.9 million states. The bound holds in every state. Dropping W2, W4 or durable witness state, or allowing `k` deviating witnesses, yields a counterexample.
- **`renewal/0.5` stapling.** `view.complete_cosignatures` returns the cosignatures to staple with `complete_head`.
- **End to end with `sm-renewal` 0.6.0.** Three integration tests:
  - an honest feed bounds renewal at exactly `t_rev + R + L + E + S` (T5);
  - a freezing feed without witnesses carries renewal past that;
  - with witnesses, the same freeze is refused: the attester's view never counts the frozen heartbeat, and sm-renewal's verifier refuses it at the `witness` stage even from an attester that staples it anyway (T6).

## What it does (0.1)

- **A revocation counts as soon as it is seen.** A single signed revoke entry,
  flooded through any carrier on its own, makes every holder that receives it
  answer `REVOKED`, without the rest of the chain (SPEC §6.3).
- **`NOT_REVOKED` only from a complete chain and a matching head.** Entries extend
  the view's chain one at a time, in any order and from any carrier; a missing,
  reordered or corrupt entry stops the chain at the gap and the view answers
  `UNKNOWN(behind)`, never `NOT_REVOKED` (§6.4).
- **Monotone state.** Nothing a carrier sends, in any order, moves the view's
  cursor, frontier, revocations or evidence backwards. A replayed old page or head
  changes nothing; there is no un-revoke (§4.5, §6.1).
- **Freshness from the issuer's own signatures.** `as_of` is the `generated_at` of
  the newest head the chain is complete to. The view reads no clock, so equal
  inputs give equal answers anywhere (§6.7).
- **Issuer misbehaviour becomes transferable evidence.** The issuer's signed times
  must never decrease (§5.3). Two signed objects that bind one position to two
  hashes (a fork), or whose times run backwards along the feed (an order
  conflict), form a `revocation-conflict/0.1` proof anyone can re-check. An order
  conflict is what exposes an issuer that keeps heartbeating a holder while hiding
  a later entry from it, as soon as the hidden entry and a heartbeat meet at any
  holder (§7).
- **Late joiners.** A `revocation-snapshot/0.1` lets a view start from a signed
  checkpoint, whose state digest every view walking through it recomputes (§8).
- **Adversarially tested.** 35 deterministic conformance vectors (seven for `revocation/0.2`) and a hostile-path
  suite: forged, tampered, mistyped and non-canonical objects, profile violations,
  chain-rule breaks, out-of-order and partial carriage, replays, forks of every
  kind, order conflicts at either holder, tampered proofs, snapshot refusals and
  false checkpoint digests. Hostile values are substituted into every field of
  every object; the view names the failing stage and never raises.

## What it does not do

- **Deliver a revocation to a node nothing can reach.** A mesh with no path to the
  issuer, direct or carried, learns nothing new. Its answers go `stale` on
  schedule. That is the inherited revocation residual, made visible, not removed.
- **Catch a freeze at a holder of a `revocation/0.1` feed that meets no one.** A
  holder that hears only from the issuer cannot tell "nothing was revoked" from
  "nothing is being shown to me". Freeze detection then needs contact between
  holders. A `revocation/0.2` feed's witnesses close this case (above); they
  cannot help if `k` of them deviate or the issuer never shows them the entry.
- **Check the issuer's word.** `effective_at`, `reason`, `prune_after` and every
  signed time are the issuer's statements. A caller that wants to cap future-dated
  heads does so against its own clock, outside the view.
- **Transport, scheduling or the decision to revoke.** Those are the consumer's.

`THREATMODEL.md` states every boundary.

## Installation

```bash
pip install sm-revocation
```

Requires Python 3.11+ and `sm-feed` 0.2.1 or later.

## Quick start

```python
from sm_arp import Identity
from sm_revocation import RENEWAL_KINDS, FeedView, RevocationIssuer, revoked_set

issuer = RevocationIssuer(
    Identity.generate(),
    heartbeat_seconds=60,
    subject_kinds=["credential_hash", "manifest_hash"],
    issued_at="2026-11-01T09:00:00Z",
)
issuer.revoke(
    subject_kind="credential_hash",
    subject="sha256:" + "a1" * 32,
    effective_at="2026-11-01T09:02:00Z",
    issued_at="2026-11-01T09:02:00Z",
    reason="key_compromise",
)

# Any carrier forwards the page; the holder verifies everything itself.
view = FeedView(issuer.feed_id)
view.ingest_page(issuer.page(None, generated_at="2026-11-01T09:05:00Z"))

view.status("credential_hash", "sha256:" + "a1" * 32, "2026-11-01T09:06:00Z", 300)
# Status(outcome='REVOKED', effective_at='2026-11-01T09:02:00Z', reason='key_compromise', ...)

# For sm-renewal: the set to pass as revoked_credential_hashes, or None.
revoked = revoked_set(view, RENEWAL_KINDS, "2026-11-01T09:06:00Z", 300)
if revoked is None:
    ...  # decline to attest. Never substitute an empty set.
```

A `Status` deliberately has no truth value: test `.revoked`, `.not_revoked` or
`.unknown`. `examples/quick_start.py` runs a fuller version, including a freeze
being caught.

## Using it with sm-renewal and sm-dat

- **`revoked_set(view, kinds, at, max_staleness_seconds)`** returns the
  `frozenset` `sm-renewal` takes as `revoked_credential_hashes`, or `None` when the
  view cannot vouch for completeness and freshness. An attester that gets `None`
  declines; a relying party fails its revocation step. **Never pass an empty set in
  place of `None`**: `sm-renewal` reads an empty set as "complete, fresh, and
  nothing revoked" (SPEC §9.1).
- **`renewal/0.4` stapling** (`sm-renewal` ≥ 0.5.0). When the manifest names this
  feed, pass `revoked_set(view, RENEWAL_KINDS, as_of, max_revocation_staleness_seconds)`
  as `revoked_credential_hashes` and `view.complete_head` as `revocation_head`, both
  read from the same view. `complete_head` is the newest head the view's chain is
  complete to. Never staple a newer head the view holds but has not caught up to:
  `sm-renewal` checks the head, not the view, and would accept it (SPEC §9.1).
- **`renewal/0.5` with witnesses** (`sm-renewal` ≥ 0.6.0). Also pass
  `view.complete_cosignatures` as `revocation_cosignatures`, from the same view.
  Make the feed `revocation/0.2` with the manifest's `revocation_witnesses` and
  `revocation_witness_threshold`, and pin the view to them
  (`FeedView(feed_id, witnesses=..., witness_threshold=...)`). The view then counts
  exactly the heads the relying party will accept, and a forked genesis naming other
  witnesses breaks its chain.
- **`dat_checker(resolve)`** returns the `revocation_checker` `sm-dat` takes.
  `sm-dat` calls one checker for every grant in a chain, ancestors included, so
  `resolve(grant_id)` returns that grant's own feed views and its
  `max_revocation_age_seconds`. `REVOKED` → `True`, `NOT_REVOKED` → `False`,
  anything else → `None` (SPEC §9.2).

## Reference fixtures

`conformance/vectors/*.json` — 35 deterministic scenarios from fixed, non-secret
seeds, each a script of ingests and queries with the answer the SPEC requires at
every step. `conformance/_vector_gen.py` regenerates them byte for byte, and checks
each hand-written expectation against the implementation while it writes.

## Specification

- [`SPEC.md`](./SPEC.md) — normative wire format and behaviour, working draft.
- [`WHITEPAPER.md`](./WHITEPAPER.md) — design rationale.
- [`THREATMODEL.md`](./THREATMODEL.md) — what it defends, and what it does not.
- [`proofs/witness_model.py`](./proofs/witness_model.py) — the exhaustive model check of the witness bound (`python proofs/witness_model.py`).

## Related packages

| Package | Role |
| --- | --- |
| [`sm-feed`](https://pypi.org/project/sm-feed/) | The substrate: signed, hash-chained, cursor-based feed, and (0.3) the witness and `feed-cosignature/0.1` |
| [`sm-renewal`](https://pypi.org/project/sm-renewal/) | Partition-tolerant renewal; consumes `revoked_set`, `complete_head` under `renewal/0.4`, and `complete_cosignatures` under `renewal/0.5` |
| [`sm-dat`](https://pypi.org/project/sm-dat/) | Delegated authority tokens; consumes `dat_checker` |
| [`sm-arp`](https://pypi.org/project/sm-arp/) | Ed25519, JCS and `did:key`, shared across the family |

## License

[MIT](./LICENSE)

---

*First published: 2026-11-28 | Last modified: 2026-11-28*

*Personal research contributions aligned with [Project NANDA](https://projectnanda.org) standards. [Stellarminds.ai](https://stellarminds.ai)*
