auth.js 271 B

123456789101112
  1. import crypto from 'node:crypto';
  2. export const safeEqual = (a = '', b = '') => {
  3. const aBuffer = Buffer.from(a);
  4. const bBuffer = Buffer.from(b);
  5. if (aBuffer.length !== bBuffer.length) {
  6. return false;
  7. }
  8. return crypto.timingSafeEqual(aBuffer, bBuffer);
  9. };