I have read that to sign a message we need the private key but in the below code snippet hasing is done in the 'getMessageHash' function and 'signing' is done in the 'getEthSignedMessageHash' function. But here we are not using any private in both the functions then how can it be possible to sign a message without the private key and I have seen the same structure in the 'MessageHashUtils' library and i'm aware that signature generation process occurs off-chain. Am I missing something ?https://medium.com/@solidity101/100daysofsolidity-verifying-signatures-on-the-blockchain-a-solidity-deep-dive-b3b964ad51f5
//Function to hash the message
function getMessageHash(
address _to,
uint _amount,
string memory _message,
uint _nonce
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_to, _amount, _message, _nonce));
}
//function to sign the message
function getEthSignedMessageHash(
bytes32 _messageHash
) public pure returns (bytes32) {
/*
Signature is produced by signing a keccak256 hash with the following format:
"\x19Ethereum Signed Message\n" + len(msg) + msg
*/
return
keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash)
);
}