import { assert, HmacSha256 } from "./deps.ts";
function compareArrayBuffer(a: ArrayBuffer, b: ArrayBuffer): boolean { assert(a.byteLength === b.byteLength, "ArrayBuffer lengths must match."); const va = new DataView(a); const vb = new DataView(b); const length = va.byteLength; let out = 0; let i = -1; while (++i < length) { out |= va.getUint8(i) ^ vb.getUint8(i); } return out === 0;}
export function compare( a: string | number[] | ArrayBuffer | Uint8Array, b: string | number[] | ArrayBuffer | Uint8Array,): boolean { const key = new Uint8Array(32); window.crypto.getRandomValues(key); const ah = (new HmacSha256(key)).update(a).arrayBuffer(); const bh = (new HmacSha256(key)).update(b).arrayBuffer(); return compareArrayBuffer(ah, bh);}