How to verify a signature in a Solidity contract
Sample code and tests
Here's some initial code and hardhat test, and a Sign Message with Ethers.js and Verify with Solidity Contract video from Taz.
Background
Though you may be wondering what ecrecover
is (it's a built in method for verifying signatures in Solidity) and why messages are signed again with "\x19Ethereum Signed Message:\n32"
.
The Magic of Digital Signatures on Ethereum has a lot of useful background.
In that article you'll also learn:
- about personal_sign which explains "\x19Ethereum Signed Message:\n32"
- and the lead-up to EIP-712 which "makes signing data more verifiable, by presenting it in a human-readable way".