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'

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

addr = Address.parse('bc1pfkde37d8chuqa6tgwvp7rwmtl7vvd20ql6g5433xxpdah30t7nushrsrlu')

testAddr = Address(
    data = public_key_hex,
    hashed_data = None,
    prefix = 'bc',
    compressed = None,
    encoding = 'bech32',
    witver = 1,
    depth = None,
    change = None,
    address_index = None,
    network = 'bitcoin',
    network_overrides = None

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