Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bigshowx opened this issue Aug 22, 2024 · 0 comments

Comments

@bigshowx
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant