httpbis-digest-headers
Version:
Create and verify content digests as found in HTTP headers according to draft-ietf-httpbis-digest-headers
36 lines (23 loc) • 1.23 kB
Markdown
[](https://github.com/interledger/httpbis-digest-headers/actions/workflows/nodejs.yml)
Based on the draft specification for HTTP Digest Headers, this library facilitates the creation and verification of a Content-Digest header.
This is useful when verifying the content of a message body as part of signature verification.
- [HTTPBIS-DIGEST-HEADERS](https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-digest-headers)
The library currently only supports sha-256 and sha-512 algorithms
```js
import { createContentDigestHeader } from 'httpbis-digest-headers';
request.setHeader('Content-Digest', createContentDigestHeader(messageBody, ['sha-256']))
```
```js
import { verifyContentDigest } from 'httpbis-digest-headers';
const server = http.createServer(async (req, res) => {
const buffers = [];
for await (const chunk of req) {
buffers.push(chunk);
}
const verified = verifyContentDigest(Buffer.concat(buffers), req.getHeader('Content-Digest'))
});```