Last active
June 13, 2024 12:51
-
-
Save sras/a4ee2e683b6284df099534397ffe4432 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from web3.auto import w3 | |
from eth_account.messages import (encode_intended_validator, encode_defunct) | |
from base64 import urlsafe_b64encode, urlsafe_b64decode | |
# The message to be hashed and signed | |
endpoint = "changeMPC"; | |
new_address = urlsafe_b64decode("kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL") | |
bridge_address = urlsafe_b64decode("EQDWGekyogF4bnuC93oCTFhgJI6pKvsbDbDBGBWSmecEjDNK") | |
message = endpoint.encode() + new_address[0:20] + bytes([0x00]) + bridge_address[0:20]; | |
# Hash the message using keccak256 | |
message_hash = w3.keccak(hexstr=message.hex()) | |
# Generate a new Ethereum account (for demonstration) | |
signer = w3.eth.account.create() | |
# Generate a new Ethereum account (for demonstration) | |
#validator_account = w3.eth.account.create() | |
# Sign the hashed message using the account's private key | |
#message_encoded = encode_defunct(message_hash) | |
#message_encoded = encode_intended_validator(validator_account.address, message_hash) | |
#print(message_encoded); | |
#signed_message = w3.eth.account.sign_message(message_encoded, private_key=account._private_key) | |
signed_message = w3.eth.account.signHash(message_hash, private_key=signer._private_key) | |
#print(len(signed_message.signature)) | |
print("Sender address:", signer.address) | |
print("Sender address public key:", signer._key_obj.public_key) | |
print("Signature:", signed_message.signature.hex()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment