function Hash(str)
{
const buffer = str.length % 2 != 0 ? Buffer.from(str) : Buffer.from(str, "hex");
return require('crypto').createHash("ripemd160").update(buffer).digest('hex')
}
Your condition is too simplified and it will pass for non-hex strings too. For instance it will pass for
Hello world! since it is 12 char long and the
length % 2 == 0. You have to do some additional character check too. Psedu code:
if each char is
>=a & <=f || >=A & <=F || >=0 & <=9This can be simplified with regex or something!