Content-Digest
HTTP Digest Fields (RFC 9530) — emit and verify the Content-Digest / Repr-Digest fields that carry a hash of a message body so a recipient can detect corruption or tampering in transit. The field is an RFC 8941 dictionary of algorithm=:base64-digest: entries; this module computes and checks the modern algorithms (SHA-256, SHA-512) and ignores the legacy ones (MD5, SHA-1, the unix checksums) that RFC 9530 §6 marks insecure — refusing to accept a body whose only digest is a legacy algorithm.
Content-Digest is the integrity companion to HTTP Message Signatures (b.httpSig, RFC 9421): rather than signing a whole body, sign its Content-Digest and let this module bind the digest to the bytes.
b.contentDigest.create(body, opts?) #
{
{
algorithms: string[], // subset of ["sha-256","sha-512"]; default ["sha-256"]
}
}
Build a Content-Digest (or Repr-Digest) field value over a message body (RFC 9530 §2): an RFC 8941 dictionary of algorithm=:base64(digest): members. Defaults to SHA-256; pass algorithms to emit several. Only the modern algorithms are offered — the digest is over the exact body bytes.
b.contentDigest.create('{"hello": "world"}');
// → "sha-256=:X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=:"
b.contentDigest.verify(fieldValue, body, opts?) #
{
{
required: string[], // algorithms that MUST be present and match (e.g. ["sha-256"])
}
}
Verify a Content-Digest / Repr-Digest field value against a body (RFC 9530). Every modern (SHA-256 / SHA-512) entry is recomputed over the body and compared in constant time; a mismatch is refused. Legacy / unknown algorithms are ignored, but a field that carries no modern digest is refused (so an attacker cannot downgrade to an MD5-only digest). opts.required forces specific algorithms to be present and to match.
b.contentDigest.verify("sha-256=:X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=:", '{"hello": "world"}');
// → { ok: true, verified: ["sha-256"] }
Last updated 2026-08-08T16:39:49.652Z by seeder.