richardkiss / pycoin

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

python 3.11 #414

Open KrashKrash opened 1 year ago

KrashKrash commented 1 year ago

doesnt work after python 3.7, its a great library. please update it so its usable in python 3.12, 3.11, 3.10

richardkiss commented 1 year ago

What issue are you seeing? I just ran all the tests on 3.11.6 and they passed. Also did a pip install. Anything else you're trying that's failing?

KrashKrash commented 1 year ago

I did the pip install. but it doesnt work on 3.12, i downgrade to 3.11, it doesnt work too. im now on python 3.10, it installs fine but dont work with python. i would love to show my code but i had delete it and work with the ecdsa, base58, bitcoin library instead. i think it was the part where i wanted to decode base58 to derive the public key of a bitcoin address

KrashKrash commented 1 year ago

ok found it.. here is a sample of my code.

from pycoin.key.BIP32Node import BIP32Node from pycoin.serialize import b2h

def derive_private_key(address): try:

Create a BIP32Node object from the Bitcoin address

    bip32node = BIP32Node.from_address(address)

    # Derive the private key from the BIP32Node object
    private_key = bip32node.secret_exponent()

    return b2h(private_key).zfill(64)
except Exception as e:
    print(f"Error while deriving the private key: {e}")
    return None

Get the BTC address as input from the user

btc_address = input("Enter a Bitcoin address: ")

richardkiss commented 1 year ago

Using BIP32Node directly is deprecated. Use it through the network corresponding to the coin network you're interested in. For example:

from pycoin.symbols.btc import network
bip_key = network.keys.bip32_seed(b"foo")
bip_key_as_text = bip_key.as_text(as_private=True)
bip_key_parsed = network.parse(bip_key_as_text)
private_key = bip_key_parsed.secret_exponent()
print(hex(private_key))