-
Notifications
You must be signed in to change notification settings - Fork 953
/
SignMessageLib.sol
37 lines (32 loc) · 1.51 KB
/
SignMessageLib.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
import {SafeStorage} from "./SafeStorage.sol";
import {Safe} from "../Safe.sol";
/**
* @title SignMessageLib - Allows to sign messages on-chain by writing the signed message hashes on-chain.
* @author Richard Meissner - @rmeissner
*/
contract SignMessageLib is SafeStorage {
// keccak256("SafeMessage(bytes message)");
bytes32 private constant SAFE_MSG_TYPEHASH = 0x60b3cbf8b4a223d68d641b3b6ddf9a298e7f33710cf3d3a9d1146b5a6150fbca;
event SignMsg(bytes32 indexed msgHash);
/**
* @notice Marks a message (`_data`) as signed.
* @dev Can be verified using EIP-1271 validation method by passing the pre-image of the message hash and empty bytes as the signature.
* @param _data Arbitrary length data that should be marked as signed on the behalf of address(this).
*/
function signMessage(bytes calldata _data) external {
bytes32 msgHash = getMessageHash(_data);
signedMessages[msgHash] = 1;
emit SignMsg(msgHash);
}
/**
* @dev Returns hash of a message that can be signed by owners.
* @param message Message that should be hashed.
* @return Message hash.
*/
function getMessageHash(bytes memory message) public view returns (bytes32) {
bytes32 safeMessageHash = keccak256(abi.encode(SAFE_MSG_TYPEHASH, keccak256(message)));
return keccak256(abi.encodePacked(bytes1(0x19), bytes1(0x01), Safe(payable(address(this))).domainSeparator(), safeMessageHash));
}
}