python – Unable to get Taproot address using bitcoinlib


I tried several ways to get a Taproot address from a Private Key with bitcoinlib, but I kept getting different addresses than those I get with Taproot wallets such as Unisat and OKX Wallet.

Then, after a lot of attempts, I found the command Address.parse and with it I tried to get all the parameters of my address, in order to replicate it.

With much surprise, even if I create a class with the exact same parameters and of course same private keys, the derived address is different.

from bitcoinlib.keys import Key, Address

# keys are for testing purposes
private_key_hex = '25eee8288d42567475d1453843ce57b16b6ba5b6c0661cb2a439fff44c4d455d'
private_key_wif="KxVSwjuqNb6qe3KTLsHG5nYA3WFEqrjyKnGbwgHAreiWsqrwffuh"

k = Key(private_key_wif)
#k.info()
public_key_hex = '02fdf741bc2b1efe52873d748ca438798ad0133b25c388bc50423aed26df8ffbd7'
public_key_hex_uncompressed = '04fdf741bc2b1efe52873d748ca438798ad0133b25c388bc50423aed26df8ffbd7db6b1b700bd2475709f586d7a0105d29b0e4a3017b259e01bc32b220342ab33a'

addr = Address.parse('bc1pfkde37d8chuqa6tgwvp7rwmtl7vvd20ql6g5433xxpdah30t7nushrsrlu')
print(addr.as_dict())

testAddr = Address(
    data = public_key_hex,
    hashed_data = None,
    prefix = 'bc',
    script_type="p2tr",
    compressed = None,
    encoding = 'bech32',
    witness_type="taproot",
    witver = 1,
    depth = None,
    change = None,
    address_index = None,
    network = 'bitcoin',
    network_overrides = None
)
print(testAddr)

I don’t know if the problem is that bitcoinlib doesn’t have bech32m encoding.

If anyone knows how to solve this issue or knows any workaround, it would be really appreciated!



Source link

Leave a Comment