MessageHashUtils
Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing. The library provides methods for generating a hash of a message that conforms to the https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712] specifications.
Functions
toEthSignedMessageHash
Returns the keccak256 digest of an ERC-191 signed data with version
0x45
(personal_sign
messages).
The digest is calculated by prefixing a bytes32 messageHash
with
"\x19Ethereum Signed Message:\n32"
and hashing the result. It corresponds with the
hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[eth_sign
] JSON-RPC method.
NOTE: The messageHash
parameter is intended to be the result of hashing a raw message with
keccak256, although any bytes32 value can be safely used because the final digest will
be re-hashed.
See ECDSA-recover.
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest);
toEthSignedMessageHash
Returns the keccak256 digest of an ERC-191 signed data with version
0x45
(personal_sign
messages).
The digest is calculated by prefixing an arbitrary message
with
"\x19Ethereum Signed Message:\n" + len(message)
and hashing the result. It corresponds with the
hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[eth_sign
] JSON-RPC method.
See ECDSA-recover.
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32);
toDataWithIntendedValidatorHash
Returns the keccak256 digest of an ERC-191 signed data with version
0x00
(data with intended validator).
The digest is calculated by prefixing an arbitrary data
with "\x19\x00"
and the intended
validator
address. Then hashing the result.
See ECDSA-recover.
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32);
toDataWithIntendedValidatorHash
Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where data
is a bytes32.
function toDataWithIntendedValidatorHash(address validator, bytes32 messageHash)
internal
pure
returns (bytes32 digest);
toTypedDataHash
Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version 0x01
).
The digest is calculated from a domainSeparator
and a structHash
, by prefixing them with
\x19\x01
and hashing the result. It corresponds to the hash signed by the
https://eips.ethereum.org/EIPS/eip-712[eth_signTypedData
] JSON-RPC method as part of EIP-712.
See ECDSA-recover.
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest);