Skip to content

feat: misina/digest — RFC 9530 Repr-Digest / Content-Digest #76

@productdevbook

Description

@productdevbook

Problem

RFC 9530 (Feb 2024, replaces RFC 3230) defines Repr-Digest and Content-Digest for verifying body integrity. Storage backends (S3-style) and bot-auth (Cloudflare) ecosystems are adopting it. Without a helper, users hand-roll WebCrypto + base64 + SF formatting.

Proposal

New subpath misina/digest:

import { withDigest, verifyDigest } from 'misina/digest'

// Auto-add Content-Digest on outgoing requests with body
const api = withDigest(misina, { algorithm: 'sha-256' })

// Verify response Content-Digest
await verifyDigest(response)  // throws DigestMismatchError on failure

Implementation:

  • crypto.subtle.digest (cross-runtime)
  • Base64 encode (RFC 9530 SF byte-sequence)
  • TransformStream for streaming bodies (don't buffer huge requests)

Depends on RFC 9651 SF parser (#20) for output formatting.

Acceptance criteria

  • withDigest(misina, opts) adds Content-Digest: sha-256=:...: header
  • verifyDigest(response) validates and throws on mismatch
  • Streaming digest for non-buffered bodies
  • Test against RFC 9530 examples
  • Doc

Refs

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Future / nice to haverfcRFC / IETF spec implementationsecuritySecurity hardeningsubpathNew misina/* subpath helper

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions