Constant-time over digests, so neither the length nor a prefix of the token leaks.
(provided: string, expected: string)
| 545 | |
| 546 | /** Constant-time over digests, so neither the length nor a prefix of the token leaks. */ |
| 547 | async function tokenMatches(provided: string, expected: string): Promise<boolean> { |
| 548 | const encoder = new TextEncoder(); |
| 549 | const [a, b] = await Promise.all([ |
| 550 | crypto.subtle.digest('SHA-256', encoder.encode(provided)), |
| 551 | crypto.subtle.digest('SHA-256', encoder.encode(expected)), |
| 552 | ]); |
| 553 | return crypto.subtle.timingSafeEqual(a, b); |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * `POST /admin/rollup?day=YYYY-MM-DD[&days=N][&reset=1]`, header `x-admin-token`. |
no test coverage detected