Created
October 25, 2021 07:41
-
-
Save JSeam2/7f37329d60cf2f097c706e4f77f785ed to your computer and use it in GitHub Desktop.
Recover eth account on web3.py signed with signMessage() on ethers.js
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
import web3 | |
w3 = web3.Web3() | |
prefix = "\x19Ethereum Signed Message:\n" | |
message = "Verify your Eth address. zveyIPmNyiaCNRjJ9hsbYqEJPb7gJTgNzm2ybM_F-SQ" | |
signed = "0x4481dffa200bc4c9cadad4083002585fbe20aebef1916aa7d58e66682860097747df3f7fb608c30ff19adbf52ab4ef2a8eabb553857373b0767d43afd83f09ea1c" | |
prefix = w3.toBytes(text=prefix) | |
msg = w3.toBytes(text=message) | |
sign = w3.toHex(text=signed) | |
hashmsg = w3.keccak(prefix + w3.toBytes(text=str(len(msg))) + msg) | |
recover = w3.eth.account.recoverHash(hashmsg, signature=signed) | |
print(recover) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will call something like
library.getSigner().signMessage(unsigned_message)
on the client.library
and.getSigner()
is web3-react specific.