If you want a constant time comparison function to compare the HMACs, you can use this function:
function constantTimeCompare(str1: string, str2: string): boolean {
if (str1.length !== str2.length) {
return false;
}
let result = 0;
for (let i = 0; i < str1.length; i++) {
result |= str1.charCodeAt(i) ^ str2.charCodeAt(i);
}
return result === 0;
}
constantTimeCompare(receivedHmac, generatedHmac)
The error you’re receiving in your code is in reference to trying to import the crypto library.