2

I am trying to implement JavaScript interpreter for Bitcoin scripts, but I have problem with counting value of OP_HASH160. I found that

Hash160(x) = RIPEMD160(SHA256(x))

However, when I try to count it this way using CryptoJS library, I get different value than on page http://paulkernfeld.com/bse/.

CryptoJS.RIPEMD160(CryptoJS.SHA256("02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f")).toString() = "e81794c3da1564a196665dd0f74483185f524fe2"

where "02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f" is the first element on the top of the stack.

Could somebody explain how exactly operation OP_HASH160 works?

Thx! :)

1

If the output of SHA256 is hex, you must convert hex to bytes before passing that to RIPEMD160.

See http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript

 var hash160 = Crypto.RIPEMD160(Crypto.util.hexToBytes(Crypto.SHA256(publicKeyBytes)))
  • Thank you for answer. However, I still have problem with getting proper value. – me.ex Jun 8 '14 at 9:28
  • Oh, I made mistake in implementation :) It works great! Thank you! – me.ex Jun 8 '14 at 10:44
  • 1
    @me.ex please click "approve" next to the answer, and upvote it. That way hsmiths will get karma :) – kolinko Jul 17 '14 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.