Created
August 14, 2024 13:54
-
-
Save airled/6e1b5ba7959bdfd3cd86cc2f4322c46e to your computer and use it in GitHub Desktop.
Extract a signer address from signature of a personal signed message
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | |
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; | |
using MessageHashUtils for bytes; | |
using ECDSA for bytes32; | |
contract AddressExtractor { | |
function extract( | |
string calldata message, | |
bytes calldata signature | |
) public pure returns (address) { | |
bytes memory msgBytes = bytes(message); | |
bytes32 signedMessageHash = msgBytes.toEthSignedMessageHash(); | |
return signedMessageHash.recover(signature); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sign message with ruby
eth
gem: