richardkiss / pycoin

Python-based Bitcoin and alt-coin utility library.
MIT License
1.4k stars 497 forks source link

need function #372

Closed arshiay closed 4 years ago

arshiay commented 4 years ago

hi i need a function to calculate all wallet address (Bitcoin address,Bitcoin address uncompressed, Bitcoin segwit address, p2sh segwit )correspond to a secret exponent can anyone help me(of corse in python)?

richardkiss commented 4 years ago
from pycoin.symbols.btc import network
k = network.keys.private(10000)
print(k.address(is_compressed=True))
print(k.address(is_compressed=False))
print(network.address.for_p2pkh_wit(k.hash160()))
p2sh_script = network.contract.for_p2pkh_wit(k.hash160())
print(network.address.for_p2s(p2sh_script))

Copy & paste to python console

>>> k = network.keys.private(10000)
>>> print(k.address(is_compressed=True))
1M1Fb86yHP2F1PC5uhmm5jcjj7KXMzGTQv
>>> print(k.address(is_compressed=False))
1Ahg5CRMjBNmdgF5kaEeux4ATY4qWq6Qpy
>>> print(network.address.for_p2pkh_wit(k.hash160()))
bc1qmdhtrqsffl99f9rc5tjc59k0zw6dk03wwhpvun
>>> p2sh_script = network.contract.for_p2pkh_wit(k.hash160())
>>> print(network.address.for_p2s(p2sh_script))
39GF2q5AYD7YH3inTX9WoB7GSEPPMFMeJD
>>> 

Compare to output of ku:


input                        : 10000
network                      : Bitcoin mainnet
symbol                       : BTC
secret exponent              : 10000
 hex                         : 2710
wif                          : KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFVau5eSEKDV
 uncompressed                : 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsrycrXyhh5
public pair x                : 55279067612272658004429375184716238028207484982037227804583126224321918234542
public pair y                : 93139664895507357192565643142424306097487832058389223752321585898830257071353
 x as hex                    : 7a36d7efeac579690f7b89c8982329303a02bd710bc87f4eaaf5cfd84c2f6fae
 y as hex                    : cdeb2ea308a7e64028781419882b4619644b637acc3ea59824452172e52e24f9
y parity                     : odd
key pair as sec              : 037a36d7efeac579690f7b89c8982329303a02bd710bc87f4eaaf5cfd84c2f6fae
 uncompressed                : 047a36d7efeac579690f7b89c8982329303a02bd710bc87f4eaaf5cfd84c2f6fae\
                                 cdeb2ea308a7e64028781419882b4619644b637acc3ea59824452172e52e24f9
hash160                      : db6eb182094fca549478a2e58a16cf13b4db3e2e
 uncompressed                : 6a6a62f0f813963432fcf26b60a1359999b25b56
Bitcoin address              : 1M1Fb86yHP2F1PC5uhmm5jcjj7KXMzGTQv
Bitcoin address uncompressed : 1Ahg5CRMjBNmdgF5kaEeux4ATY4qWq6Qpy
Bitcoin segwit address       : bc1qmdhtrqsffl99f9rc5tjc59k0zw6dk03wwhpvun
p2sh segwit                  : 39GF2q5AYD7YH3inTX9WoB7GSEPPMFMeJD
 corresponding p2sh script   : 0014db6eb182094fca549478a2e58a16cf13b4db3e2e
arshiay commented 4 years ago

thanks a lot you are life saver