1

For the private key KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb, I have the following addresses:

  • 1N7jKvQ1fHezb61eNsGEaF4gcj5sQXhb2m (P2PKH)
  • 14MNoFYWheu7sLkj8urvXCpYEdCuL4m2PH (P2PKH)
  • 3G4BoJsFB6N3Eejtovr8PUnvz4LRDhWmxk (P2SH)
  • bc1qu7s8s2ga69a9068s85e9vpxh7uvneet292wa5n (P2WPKH)
  • bc1qxr7lhfgnynvw7dk3e0asw2hsxhdvp4cgp7u0z09stm26gaxqn6zqd9muau (P2WSH)

I am looking for a utility (like the ku utility from https://github.com/richardkiss/pycoin) which can generate all these address given the private key (the ku does not generate the P2WSH address). The utility I am searching for can be in C, C++, Go or Python.

3
  • @RedGrittyBrick Thanks but I already know about this one. Looking for a executable like ku so that I don't have to write any code.
    – GMaster
    Feb 24, 2020 at 11:57
  • It's not clear to me why you would generate a *SH address from a single key. Could you outline what sort of script that should contain?
    – Murch
    Jul 14, 2022 at 12:55

3 Answers 3

0
from bitcoinlib.keys import *

pk = 567
address_U = Key(import_key=pk, network='bitcoin', compressed=False)
print(address_U.address())
print(address_U.public_hex)
print(address_U._x)
print(address_U._y)
print(address_U.hash160.hex())
print(address_U.wif())
print('***************')
address_C = Key(import_key=pk, network='bitcoin', compressed=True)
print(address_C.address())
print(address_C.public_hex)
print(address_C._x)
print(address_C._y)
print(address_C.hash160.hex())
print(address_C.wif())
print('***************')
print(Address(address_C.public_hex, encoding='base58', script_type='p2sh', witness_type='p2sh-segwit').address)
print(Address(address_C.public_hex, encoding='bech32', script_type='p2wpkh').address)
print(Address(address_C.public_hex, encoding='bech32', script_type='p2wsh').address)
0

I have a tool which does that in my bcutils repository:

python3 bcaddr.py KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb
privkey             : 0ab9bb56315ce08019d61dd3480e51c35d6339c4618ad5c9824d0e47bedcc957
wallet              : 5Hu1YsmBoMwCLsdZRSbSfVNZsTCt1oZpSkunncS2ptsitRnbe3m
cwallet             : KwaZRh42fdQD4iUN6sy2GtEC5gfSAYXrQgp16KPV4Pxsspi5ChRb
version: 128          compressed: 1
compressed          : 03418fe8f11fa50cd9584b290fcbfc60c5af9a713facf3faac27792921910dbd5a
full                : 04418fe8f11fa50cd9584b290fcbfc60c5af9a713facf3faac27792921910dbd5a7ccb3081ca2a2f06f2944b2405c622860af42ce5e91351f428c0199c6055dc85
comp: e7a078291dd17a57e8f03d325604d7f7193ce56a:   0 1N7jKvQ1fHezb61eNsGEaF4gcj5sQXhb2m - bc1qu7s8s2ga69a9068s85e9vpxh7uvneet292wa5n
full: 24c2e464c447a78950949c8649729865dd41e5e7:   0 14MNoFYWheu7sLkj8urvXCpYEdCuL4m2PH - bc1qynpwgexyg7ncj5y5njryju5cvhw5re08yvasde
p2sh: 9d92bd57e9a882fe08c200b8f325efecbb2cb2c0:   5 3G4BoJsFB6N3Eejtovr8PUnvz4LRDhWmxk - bc19nkft64lf4zp0uzxzqzu0xf00ajajevkqvgd0xt
p2sh(full): 6ce28aa65204eabc762e5adcc7b7146810a54bc0:   5 3BckHeXP5Gb6n5iXRepyDpWAVjXu58YRb4 - bc19dn3g4fjjqn4tca3wttwv0dc5dqg22j7qtkf620
p2wsh: 30fdfba51324d8ef36d1cbfb072af035dac0d7080fb8f13cb05ed5a474c09e84: - bc1qxr7lhfgnynvw7dk3e0asw2hsxhdvp4cgp7u0z09stm26gaxqn6zqd9muau
0
from bitcoinlib.keys import *

priv_key = '0000000000000000000000000000000000000000000000000000000000000237'

U_pub_key = Key(import_key=priv_key, network='bitcoin', compressed=False)
C_pub_key = Key(import_key=priv_key, network='bitcoin', compressed=True)
C_hex = C_pub_key.public_hex

U_wif = U_pub_key.wif()
C_wif = C_pub_key.wif()

add_U = U_pub_key.address()
add_C = C_pub_key.address()

p2sh_segwit = Address(C_hex, encoding='base58', script_type='p2sh', witness_type='p2sh-segwit').address
p2wpkh = Address(C_hex, encoding='bech32', script_type='p2wpkh').address
p2wsh = Address(C_hex, encoding='bech32', script_type='p2wsh').address

print(add_U)
print(add_C)
print(p2sh_segwit)
print(p2wpkh)
print(p2wsh)
print(U_wif)
print(C_wif)
print(priv_key)
print(U_pub_key)
print(C_pub_key)
13sjRRtRsDD3gQVW2XDXHM8ahBEBzVNyrK
1KCvMjHxAKv7pdzCFLhhKrQNpVWN1eyeAb
32MAGHunMfYDb1cCC1hDxiovYCUg6oNxhU
bc1qc7ekz48gzmds2sedh9vm59j3yezg33d392fzj3
bc1qu4t4gt4dpzjhr357yxmnjjsqaakuc75vt8qhct9kgraq7pd7xgys8hw8eg
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsrfGd4hTb9
KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFUBuithWYeP
0000000000000000000000000000000000000000000000000000000000000237
0455faaaee59a20b9a3784d1719ea529cc1b7ab3a329f26dfaa3b11bd667ba15c1a9f8939b52ac53e35ed4771d8e47065c0d7f2805a7e5475c37353ddf182f4a65
0355faaaee59a20b9a3784d1719ea529cc1b7ab3a329f26dfaa3b11bd667ba15c1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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