Skip to content

Instantly share code, notes, and snippets.

@JSeam2
Created October 25, 2021 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JSeam2/7f37329d60cf2f097c706e4f77f785ed to your computer and use it in GitHub Desktop.
Save JSeam2/7f37329d60cf2f097c706e4f77f785ed to your computer and use it in GitHub Desktop.
Recover eth account on web3.py signed with signMessage() on ethers.js
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)
@JSeam2
Copy link
Author

JSeam2 commented Oct 25, 2021

You will call something like library.getSigner().signMessage(unsigned_message) on the client.

library and .getSigner() is web3-react specific.

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