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
604 stars 200 forks source link

sighash problems #402

Open ellacodecamp opened 4 months ago

ellacodecamp commented 4 months ago
  1. In config.py, SIGHASH_ANYONECANPAY should be set to 0x80, not to 80.
  2. sighash_type is not properly reflected in the signature. The last byte in the signature is always set to 01, instead to the value passed Transaction.sign() method.
mccwdev commented 4 months ago

You are right, will take a look at it

mccwdev commented 4 months ago

This issue is addressed in commit 33dd52d1502a5085a946989eb7e8c8762007a402

However hash_types other than SIGHASH_ALL are not supported at the moment. You can create transactions with other hash types but signing is not possible. I will transform this issue in a 'feature request'.

ellacodecamp commented 4 months ago

It is actually pretty easy to fix. Do not pass hash_type to sign function, the one that comes from keys.py file, just get the signature and append your hash_type to your signature in the sign function that belongs to Transaction object. You would probably need to fix all the other places where 01 is expected to be appended to the signature.