Skip to content

Commit

Permalink
Externalize the message computation
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed Mar 28, 2024
1 parent 469086e commit 607fa18
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
36 changes: 23 additions & 13 deletions contracts/reverseRegistrar/L2ReverseRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,36 @@ contract L2ReverseRegistrar is
}
}

function computeOwnerMessage(
bytes32 hash,
address addr,
address owner,
uint256 inceptionDate
) public view returns (bytes32) {
// Follow ERC191 version 0 https://eips.ethereum.org/EIPS/eip-191
return
keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
address(this),
hash,
addr,
owner,
inceptionDate,
coinType
)
).toEthSignedMessageHash();
}

function isOwnerAndAuthorisedWithSignature(
bytes32 hash,
address addr,
address owner,
uint256 inceptionDate,
bytes memory signature
) internal view returns (bool) {
// Follow ERC191 version 0 https://eips.ethereum.org/EIPS/eip-191
bytes32 message = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
address(this),
hash,
addr,
owner,
inceptionDate,
coinType
)
).toEthSignedMessageHash();
bytes32 message = computeOwnerMessage(hash, addr, owner, inceptionDate);
bytes32 node = _getNamehash(addr);

if (!ownsContract(addr, owner)) {
Expand Down
33 changes: 21 additions & 12 deletions contracts/reverseRegistrar/SignatureReverseResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,33 @@ contract SignatureReverseResolver is Ownable, ISignatureReverseResolver {
revert("This function needs to be overridden");
}

function computeMessage(
bytes32 hash,
address addr,
uint256 inceptionDate
) public view returns (bytes32) {
// Follow ERC191 version 0 https://eips.ethereum.org/EIPS/eip-191
return
keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
address(this),
hash,
addr,
inceptionDate,
coinType
)
).toEthSignedMessageHash();
}

function isAuthorisedWithSignature(
bytes32 hash,
address addr,
uint256 inceptionDate,
bytes memory signature
) internal view returns (bool) {
// Follow ERC191 version 0 https://eips.ethereum.org/EIPS/eip-191
bytes32 message = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
address(this),
hash,
addr,
inceptionDate,
coinType
)
).toEthSignedMessageHash();
bytes32 message = computeMessage(hash, addr, inceptionDate);
bytes32 node = _getNamehash(addr);

if (!SignatureChecker.isValidSignatureNow(addr, message, signature)) {
Expand Down

0 comments on commit 607fa18

Please sign in to comment.