interface CloudflareSubtleCrypto extends SubtleCrypto { timingSafeEqual(a: ArrayBuffer | ArrayBufferView, b: ArrayBuffer | ArrayBufferView): boolean; } export const timingSafeEqualBytes = (left: Uint8Array, right: Uint8Array): boolean => { const subtle = crypto.subtle as CloudflareSubtleCrypto; const lengthsMatch = left.byteLength === right.byteLength; return lengthsMatch ? subtle.timingSafeEqual(left, right) : !subtle.timingSafeEqual(left, left); };