Post
Topic
Board Development & Technical Discussion
Re: Bitcoin script. Need help.
by
Coding Enthusiast
on 13/10/2018, 16:37:15 UTC
Code:
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 & <=9
This can be simplified with regex or something!