One line faster
The code below is the file exactly as it stood in honojs/hono. The defect was introduced on 2024-11-03, reviewed, merged, and fixed on 2026-02-24 in commit e4602ad1 — after 478 days in the tree.
The commit was written by a human contributor to honojs/hono, not by an agent. The ticket and the description on the next two panels are ours — a reconstruction of the case the original change made, so you meet it the way its reviewer did. The code, the defect and the dates are untouched.
Shave allocations off the JWT hot path
`verify` runs on every authenticated request. Profiling shows the timestamp conversion is called once per verification and `Math.floor` is measurably slower than the bitwise alternative in this position.
Small, self-contained wins only. Do not change the validation semantics.
Replaced `Math.floor(Date.now() / 1000)` with `(Date.now() / 1000) | 0`. Bitwise OR with zero truncates toward zero, which is identical to `Math.floor` for any positive number, and a Unix timestamp is always positive. It is a well-known idiom and it benchmarks faster.
Semantics are unchanged: `now` is still the current time in whole seconds, and every comparison below it is untouched. Full JWT suite passes.
Our reconstruction of the argument the real change made, not a quotation of it. Fluent, specific, and not evidence of anything — which is the point.
export const verify = async ( token: string, publicKey: SignatureKey, algOrOptions: SignatureAlgorithm | VerifyOptionsWithAlg): Promise<JWTPayload> => { if (!algOrOptions) { throw new JwtAlgorithmRequired() } const { alg, iss, nbf = true, exp = true, iat = true, aud, } = typeof algOrOptions === 'string' ? { alg: algOrOptions } : algOrOptions if (!alg) { throw new JwtAlgorithmRequired() } const tokenParts = token.split('.') if (tokenParts.length !== 3) { throw new JwtTokenInvalid(token) } const { header, payload } = decode(token) if (!isTokenHeader(header)) { throw new JwtHeaderInvalid(header) } if (header.alg !== alg) { throw new JwtAlgorithmMismatch(alg, header.alg) } const now = (Date.now() / 1000) | 0 if (nbf && payload.nbf && payload.nbf > now) { throw new JwtTokenNotBefore(token) } if (exp && payload.exp && payload.exp <= now) { throw new JwtTokenExpired(token) } if (iat && payload.iat && now < payload.iat) { throw new JwtTokenIssuedAt(now, payload.iat) } if (iss) { if (!payload.iss) { throw new JwtTokenIssuer(iss, null) } if (typeof iss === 'string' && payload.iss !== iss) { throw new JwtTokenIssuer(iss, payload.iss) } if (iss instanceof RegExp && !iss.test(payload.iss)) { throw new JwtTokenIssuer(iss, payload.iss) } }