1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
613 stars 204 forks source link

how to get taproot address from singlekey? #348

Closed iteh3712198 closed 10 months ago

iteh3712198 commented 1 year ago

I'm tring to use this code to get a taproot address , but the result I got is different from the address displayed in my unisat wallet. Address(key.public_hex, script_type='p2tr', encoding='bech32').address

mccwdev commented 12 months ago

Please check if the unisat wallet is not using a different key path.

And I think it should be like this:

 addr = Address(hashed_data=key.hash160, script_type='p2tr', encoding='bech32').address
iteh3712198 commented 11 months ago

Please check if the unisat wallet is not using a different key path.

And I think it should be like this:

 addr = Address(hashed_data=key.hash160, script_type='p2tr', encoding='bech32').address

I used this method, but the address I got was inconsistent with the address shown in my wallet

mccwdev commented 11 months ago

Did you check the key paths?

I did some tests, and compared to other wallets, but could not find any problems.

iteh3712198 commented 11 months ago

Did you check the key paths?

I did some tests, and compared to other wallets, but could not find any problems.

I exported the WIF private key from the unisat wallet and then used the following code to get the taproot address, can you help me see where I might be going wrong?

from bitcoinlib.keys import *
 key = Key(wif_key)
 addr = Address(hashed_data=key.hash160, script_type='p2tr', encoding='bech32').address
mccwdev commented 11 months ago

I think taproot uses the public key instead of the hashed public key for the address.

Can you try it like this:

from bitcoinlib.keys import *
key = Key(wif_key)
addr = Address(hashed_data=key.public_hash, script_type='p2tr', encoding='bech32').address