Changelog - 2026-11-06
Hash.verify compares a digest or signature in constant time
New Feature SecurityIn one line. Hash.verify checks a received digest or HMAC signature (a webhook, a payment callback) against the one your value produces, and does not leak how many leading characters were right.
What changed
- A new method.
Hash.withAlgorithm('sha256').verify({ value, expected, secret?, opts? })returnstruewhenexpectedis the digest ofvalue, or its HMAC whensecretis given. - No throw on a mismatch. A different value, a different length or a wrong encoding answers
false. An emptysecretis refused, ashmacrefuses it. - Same options as
digestandhmac.opts.outputEncoding(hex,base64,base64url) says howexpectedis written; the default ishex. The text must match exactly, so upper-case hex does not equal lower-case hex.
typescript
const ok = Hash.withAlgorithm('sha256').verify({
value: rawBody,
secret: webhookSecret,
expected: request.headers.get('x-signature') ?? '',
});Who is affected
- Apps that compare a digest or signature with
===. Switch toverify;===stops at the first differing character. - Everyone else. No action needed.
Details
| File | Package |
|---|---|
src/modules/crypto/algorithms/hash.algorithm.ts | helpers |