ofek / bit

Bitcoin made easy.
https://ofek.dev/bit/
MIT License
1.25k stars 216 forks source link

future request uncompressed Key.address #163

Open rockygsm opened 2 years ago

rockygsm commented 2 years ago

Hello i am using Key.from_hex('hexdata').address return compressed address your python lib work fastest then any other. but what is solution for getting uncompressed as i seen all source not found any sort way way i used is

wif_bytes = wif_to_bytes(Key.from_hex('hexdata').to_wif())
wif_bytes_uncompressed = (wif_bytes[0], wif_bytes[2], False)
wif_uncompressed = bytes_to_wif(*wif_bytes_uncompressed)
Key(wif_uncompressed).address

but its not fast like compressed i am missing something ? its possible to implement something like Key.address(False) to display uncompressed address ?

rockygsm commented 2 years ago

update: keyx1 = Key(bytes_to_wif(bytes.fromhex('hexdata'),compressed=False)) seems fastest way currently. still 8% to 10% down from compressed address.

anshukrsingh commented 2 years ago

so you know , how to get native segwit address, key.segwit_address returns only nested p2sh segwit address, not native one that starts from bc1

aserxmail commented 2 years ago

@rockygsm Is there any way to generate the Native segwit address, and tabroot address. I hope if not, it will be supported soon.

mcauser commented 2 years ago

public_key_to_address can display the uncompressed address without creating a new Key instance.

>>> from bit import Key
>>> from bit.format import public_key_to_address
>>> k = Key.from_hex('0000000000000000000000000000000000000000000000000000000000000001')

>>> k.address
'1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH'
# compressed P2PKH

>>> public_key_to_address(k._pk.public_key.format(compressed=True),'main')
'1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH'
# compressed P2PKH

>>> public_key_to_address(k._pk.public_key.format(compressed=False),'main')
'1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm'
# uncompressed P2PKH
a-n-d-r commented 1 year ago

Is there any way to generate the Native segwit address

from bit import PrivateKey

def get_bech32_address():
    byte_public_key_comp = PrivateKey("your_private_key")._pk.public_key.format()
    witprog = ripemd160_sha256(byte_public_key_comp)
    bech32_address = encode('bc', 0, witprog)
    return bech32_address

print("SegWit Native:", get_bech32_address())