* Constant-time string equality. Both sides are hashed first so the digests are * always the same length — `timingSafeEqual` throws on a length mismatch, and a * throw would itself leak the length of the secret.
(a: string, b: string)
| 75 | * throw would itself leak the length of the secret. |
| 76 | */ |
| 77 | async function equalsInConstantTime(a: string, b: string): Promise<boolean> { |
| 78 | const [digestA, digestB] = await Promise.all([ |
| 79 | crypto.subtle.digest('SHA-256', encoder.encode(a)), |
| 80 | crypto.subtle.digest('SHA-256', encoder.encode(b)), |
| 81 | ]); |
| 82 | return crypto.subtle.timingSafeEqual(digestA, digestB); |
| 83 | } |
| 84 | |
| 85 | /** Short, non-reversible marker of the current password, embedded in the session. */ |
| 86 | async function passwordFingerprint(password: string): Promise<string> { |