Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: BlackHatCoiner on September 28, 2020, 11:36:42 AM



Title: Problem when I try to create an address from zero
Post by: BlackHatCoiner on September 28, 2020, 11:36:42 AM
https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
^In this link it shows us the procedure to create a bitcoin address (version 1)

I take the public key (0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352) and I hash it with SHA256:

https://i.imgur.com/tyPaE8M.png

Then it says that I have to take the result of SHA256 (0b7c28c9b7290c98d7438e70b3d3f7c848fbd7d1dc194ff83f4f7cc9b1378e98) and perform RIPEMD-160 to it. While the site says that the result should be that:

Code:
f54a5851e9372b87810a8e60cdd2e7cfd80b6e31

I get that:
Code:
6836d8a2986c8c34881114fe0412a1d416ae02a8

https://i.imgur.com/a3fGQaG.png

What do I do wrong? All the "ripemd160 hash online" sites print me the same result.


Title: Re: Problem when I try to create an address from zero
Post by: PawGo on September 28, 2020, 12:05:41 PM
Here it works as expected:
https://learnmeabitcoin.com/technical/public-key-hash


Title: Re: Problem when I try to create an address from zero
Post by: pooya87 on September 28, 2020, 12:23:56 PM
it is because in your first hash you set the input type correctly but then you moved to another website that didn't have that option so your input type is wrong. more accurately your RIPEMD160 is interpreting the input (0b7c28...) as a UTF8 string not hexadecimal input.


Title: Re: Problem when I try to create an address from zero
Post by: o_e_l_e_o on September 28, 2020, 12:28:45 PM
Here, use this site instead: https://www.pelock.com/products/hash-calculator

As pooya87 says, the output of the SHA256 needs to be inputted in to the RIPEMD160 function as hexadecimal bytes, and not as a plain text string. If you take the result of your SHA256 hash:
Code:
0B7C28C9B7290C98D7438E70B3D3F7C848FBD7D1DC194FF83F4F7CC9B1378E98
And enter it in to the second box down titled "Hash hex bytes" and then hit calculate, you will get the correct RIPEMD160 result:
Code:
F54A5851E9372B87810A8E60CDD2E7CFD80B6E31


Title: Re: Problem when I try to create an address from zero
Post by: BlackHatCoiner on September 28, 2020, 12:37:58 PM
Thank you, it works properly.

Are there any libraries that allow me to convert hex to ripemd160 with javascript? I'm trying to build something.


Title: Re: Problem when I try to create an address from zero
Post by: BASE16 on September 28, 2020, 12:59:38 PM
Here https://github.com/bitaps-com/jsbtc (https://github.com/bitaps-com/jsbtc)

Test page: https://github.com/bitaps-com/jsbtc/blob/master/test/jsbtc.test.js (https://github.com/bitaps-com/jsbtc/blob/master/test/jsbtc.test.js)

Or here https://github.com/bitcoinjs/bitcoinjs-lib (https://github.com/bitcoinjs/bitcoinjs-lib)

Test page: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/crypto.ts (https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/crypto.ts)

 :)