How to use the @zilliqa-js/util.bytes.isEqual function in @zilliqa-js/util

To help you get started, we’ve selected a few @zilliqa-js/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-crypto / src / keystore.ts View on Github external
// @ts-ignore
    .hmac(hashjs.sha256, derivedKey, 'hex')
    .update(
      Buffer.concat([
        derivedKey.slice(16, 32),
        ciphertext,
        iv,
        Buffer.from(ALGO_IDENTIFIER),
      ]),
      'hex',
    )
    .digest('hex');

  // we need to do a byte-by-byte comparison to avoid non-constant time side
  // channel attacks.
  if (!bytes.isEqual(mac.toUpperCase(), keystore.crypto.mac.toUpperCase())) {
    return Promise.reject('Failed to decrypt.');
  }

  const cipher = new aes.ModeOfOperation.ctr(
    derivedKey.slice(0, 16),
    new aes.Counter(iv),
  );

  return Buffer.from(cipher.decrypt(ciphertext)).toString('hex');
};