Bitcoin
bitcoin core – Why are the results of BTC message signing implemented in Python different from those in Electrum?
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')
The Python result is MEUCIQDGOkOlG2DMAcZ4/nvsUNi4ZxbTKGJFIx0h76QkBLVmqgIgd2McFwd+/ZHxCcktZffZS762gA5o8oRM5u4tqORp6HA=.
The electromagnet result is IDVIF+7m9nKMvxAKo88PNwLJeg8H2MA9WoDZgjDCs0boKyuFdqWnTSCuAobVmzJr+NzqlCg180yvc5vsfsVeBjA=
After repeated verification, it is Electrum.