Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

future request uncompressed Key.address #163

Open
rockygsm opened this issue Feb 28, 2022 · 5 comments
Open

future request uncompressed Key.address #163

rockygsm opened this issue Feb 28, 2022 · 5 comments

Comments

@rockygsm
Copy link

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
Copy link
Author

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

@anshukrsingh
Copy link

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
Copy link

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

@mcauser
Copy link

mcauser commented Oct 19, 2022

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
Copy link

a-n-d-r commented Oct 23, 2023

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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants