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
596 stars 199 forks source link

how to get taproot address from singlekey? #348

Closed iteh3712198 closed 7 months ago

iteh3712198 commented 9 months 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 9 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 9 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 9 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 9 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 9 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