Skip to content

Why are the results of BTC message signature implemented in Python different from those on electrum? #189

Description

@bigshowx

from bit import Key
from bit.format import verify_sig
import base64
from hashlib import sha256

Use WIF format private key

wif_private_key = 'Kxb19KFrrqrmT79bvG4tnKibVcgppavcvjkP1iBGGjnH787H39QG'
key = Key(wif_private_key)

Message to be signed

message = '''ok 666'''
message_bytes = message.encode('utf-8')

Compute SHA-256 hash of the message

message_hash = sha256(message_bytes).digest()

Sign the hash of the message

signature_bytes = key.sign(message_hash)

Convert the signature to Base64 encoding

signature_base64 = base64.b64encode(signature_bytes).decode('utf-8')
print(f'Signature (Base64): {signature_base64}')

Verify the signature

Decode the actual Base64 encoded signature

signature_bytes = base64.b64decode(signature_base64)
is_valid = verify_sig(signature_bytes, message_hash, key.public_key)
print(f'Is the signature valid? {is_valid}')

python result is MEUCIQDGOkOlG2DMAcZ4/nvsUNi4ZxbTKGJFIx0h76QkBLVmqgIgd2McFwd+/ZHxCcktZffZS762gA5o8oRM5u4tqORp6HA=

The electrum result is IDVIF+7m9nKMvxAKo88PNwLJeg8H2MA9WoDZgjDCs0boKyuFdqWnTSCuAobVmzJr+NzqlCg180yvc5vsfsVeBjA=

After multiple verifications, electrum is correct.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions