• Welcome to forex.pm forex forum binary options trade. Please login or sign up.
 

How to generate Hash160 from a private key with the Bitcoin module

Started by Bitcoin, Feb 04, 2022, 06:26 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bitcoin

How to generate Hash160 from a private key with the Bitcoin module

I want to fix the script code. The script generates from a random private key Bitcoin Address by function (pubtoaddr) and works
on the Bitcoin module:


https://github.com/primal100/pybitcointools/blob/master/cryptos/main.py


from bitcoin import *
import os

    priv = random_key ()
    pub = privtopub (priv)
    addr = pubtoaddr (pub)

....
....

But I need to get from a Random Private Key in Hash160


For some reason I could not find such a function in main.py


I searched and found an article


>>> import pybitcointools
>>> privkey = pybitcointools.random_key ()
>>> privkey
'34030ce14e32ac982419b3683af3b59d64a29cc93798cf479d610af49d425d13'
>>> pubkey = pybitcointools.privtopub (privkey)
>>> pubkey
'04ce0ed35340803b0c21f2f7f5d5ab9d687e5fa95a79471c9b5c9d97a0bb170eac1045230cc51d13b85a5f64feb80f8fc19358a396797926e3f89d49066b1abc07'
>>> h160 = pybitcointools.hash160 (pubkey.decode ('hex'))
>>> h160
'1558c7cd9825447a31990ff964f347bb2dbfe9be'
>>> addr = pybitcointools.hex_to_b58check (h160)
>>> addr
'12wsYc4B9c9JeREqstLZXNWa3n4i42M5jg'

Unfortunately I could not get from


 priv = random_key ()  --- > Hash160

How to do it?


Source: How to generate Hash160 from a private key with the Bitcoin module