### `wai.delivery.settlement`: delivery paid on what the party that received it signed

- **The extension** ([settlement](extensions/settlement.md)) registers the record
  `wai.delivery.settlement`. The downstream party of a delivery, a next hop or a sink, signs an
  **acknowledgement**, `WDA1`, of what it received in a window: per object class (`live`, `fetch`,
  `fill`, `ancillary`), the objects by content hash under jwp-receipts §2.2's tree, the byte range
  of each and their byte count, the item lists travelling beside the record under a digest it
  signs. A party's acknowledgements to one upstream form a chain of windows that do not overlap.
  A relay acknowledges upstream and is acknowledged downstream over the same content hashes, and
  a hop's billable bytes are exactly those its downstream parties signed for. An acknowledgement
  whose downstream is its upstream is refused (`self_acknowledged`).
- **Unacknowledged delivery.** A hop whose downstream will not or cannot sign states the delivery
  in a **declaration**, the same record signed by itself, counted in a class of its own: never as
  zero, never billed, and never for a byte the same party acknowledged
  (`declared_and_acknowledged`). A unidirectional bearer settles under unidirectional-delivery §4.
- **Byte-range proofs**, `WBR1`: the covered chunks of a range and the chaining value of every
  subtree of BLAKE3's chunk tree outside them, verified to the object's content hash; the head
  proof of http-delivery §6 is the case of a range that starts at 0. A proof establishes the
  object's length only when it reaches the last chunk, and its verifier says whether it did. An
  auditor asks a downstream party for one over an item it acknowledged.
- **Paid retrieval.** A fetch below the live edge, a recording fetch, or a fill past a cache is
  billed only to a room grant whose `WRP1` proof of possession the request carried, checked by
  live-rooms §10.5.4 steps 2 to 5 and the seek power; one proof pays for one record
  (`pop_replayed`); an ungranted retrieval is free (`paid_without_grant`).
- **The settlement statement**, `WSS1`, per party and period: lines by object class and payer,
  the acknowledged bytes by class, the declared bytes, the party's joules by acquisition class
  from its per-hop records (`WMH1`) and never one total across classes (`classes_summed`), and the
  amount under a declared tariff, in millionths of a minor unit per 10^9 bytes, rounded down once
  per line. A verifier recomputes every figure from the acknowledgements: a line billing bytes no
  acknowledgement covers is `bytes_not_acknowledged`, any other difference `statement_mismatch`.
  A line kind is reserved for a payee that is not a hop.
- **Logs.** Each acknowledged item of an HTTP delivery maps onto a `cdni_http_request_v1` record
  (RFC 7937 §3.4.1), the acknowledgement's digest in a `remark` directive; a log carries no
  counter-signature, so a converter maps a log onto declarations, never onto acknowledgements.
- **Viewers as relays over ciphertext.** An acknowledgement binds a sealed object's content hash,
  over its sealed bytes, so a forwarder that cannot open what it forwards earns acknowledged bytes,
  and proves ranges of them, on the terms of any relay.
- **Reference and corpus.** `wai-rs` module `settlement` (feature `settlement`), its generator
  `wai_settlement_vectors` and `tests/settlement.rs`; the corpus
  [`live-conformance/settlement/`](live-conformance/settlement/), 48 statements and 24 range
  proofs; and its second implementation, `live-conformance/settlement_verify.py`, written from the
  text, which requires every mutated copy of the corpus to fail and every one of its own checks
  to be load-bearing.

