All files / src/util keccak.js

100% Statements 17/17
100% Branches 2/2
100% Functions 2/2
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2212x   48x   43x 3x 3x 22x   3x   40x   43x 43x     12x 12x 12x 12x  
const createKeccakHash = require('keccak');
 
const keccak = bits => str => {
  let msg;
  if (str.slice(0, 2) === '0x') {
    msg = [];
    for (let i = 2, l = str.length; i < l; i += 2) {
      msg.push(parseInt(str.slice(i, i + 2), 16));
    }
    msg = Buffer.from(msg);
  } else {
    msg = str;
  }
  const instance = createKeccakHash(`keccak${bits}`);
  return `0x${instance.update(msg).digest('hex')}`;
};
 
export const keccak256 = keccak(256);
export const keccak512 = keccak(512);
export const keccak256s = keccak(256);
export const keccak512s = keccak(512);