Signing a transaction(Signature must be zero for failed CHECK(MULTI)SIG operation)

Signing a transaction(Signature must be zero for failed CHECK(MULTI)SIG operation)

 

I try to sign raw transaction. Here is the instruction I used for it Redeeming a raw transaction step by step example required

Python code I used to sign the transaction

import hashlib
import codecs
from ecdsa import SigningKey, SECP256k1, util
import base58

def Hash(data):
    h1 = hashlib.sha256()
    h2 = hashlib.sha256()
    h1.update(data.encode())
    h2.update(h1.hexdigest().encode())
    return h2.hexdigest()


print ("Private key")
pk_encoded = input()
pk_with_prefix = base58.b58decode_check(pk_encoded).hex()
pk = pk_with_prefix[2:(len(pk_with_prefix)-2)]
sk = SigningKey.from_string(string=codecs.decode(pk, 'hex_codec'), curve=SECP256k1)
print("Public Key:")
print (sk.get_verifying_key().to_string().hex())
print("Private Key:")
print(pk)

print("Message")
message = input()
message_hash = Hash(message)

signature = sk.sign_digest(codecs.decode(message_hash, 'hex_codec'), sigencode = util.sigencode_der)
print("Signature:")
print(signature.hex())

here is the unsigned raw transaction

0100000001d6a70f1fb489d8e8a71fef1f242737fc01314b6fd43acb69259c0e550dcb508c010000001976a914c116463ed8c7f547fb03321104fd714887003aa488acffffffff0258020000000000001976a914de5ff6a389177223929ac97f0a2dbd559ff60c8e88ac0b040000000000001976a914c116463ed8c7f547fb03321104fd714887003aa488ac0000000001000000

and here is the signed one

0100000001d6a70f1fb489d8e8a71fef1f242737fc01314b6fd43acb69259c0e550dcb508c010000006b483045022100d60882af5857c1badca6dc25af8a891b3327f12bbdf710186ab16c5d4695f22a02200a52b81ed738db0b608e1d2691705d27e50b0182cd47b8231dcc425037de35fb01210257f359264c6e26a26495a4f26960cab40ee4d944406144d35eae6207cb90d0c0ffffffff0258020000000000001976a914de5ff6a389177223929ac97f0a2dbd559ff60c8e88ac0b040000000000001976a914c116463ed8c7f547fb03321104fd714887003aa488ac00000000

When I try to push it through https://www.blockchain.com/ru/btc/pushtx I get this error

Code: -26, Error: mandatory-script-verify-flag-failed (Signature must
be zero for failed CHECK(MULTI)SIG operation)

Can anyone help me with this?



Source link

Leave a Comment

Your email address will not be published.