EIP712ExternalUpgradeable.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../utils/cryptography/draft-EIP712Upgradeable.sol";
  4. import "../utils/cryptography/ECDSAUpgradeable.sol";
  5. import "../proxy/utils/Initializable.sol";
  6. contract EIP712ExternalUpgradeable is Initializable, EIP712Upgradeable {
  7. function __EIP712External_init(string memory name, string memory version) internal onlyInitializing {
  8. __EIP712_init_unchained(name, version);
  9. }
  10. function __EIP712External_init_unchained(string memory, string memory) internal onlyInitializing {}
  11. function domainSeparator() external view returns (bytes32) {
  12. return _domainSeparatorV4();
  13. }
  14. function verify(
  15. bytes memory signature,
  16. address signer,
  17. address mailTo,
  18. string memory mailContents
  19. ) external view {
  20. bytes32 digest = _hashTypedDataV4(
  21. keccak256(abi.encode(keccak256("Mail(address to,string contents)"), mailTo, keccak256(bytes(mailContents))))
  22. );
  23. address recoveredSigner = ECDSAUpgradeable.recover(digest, signature);
  24. require(recoveredSigner == signer);
  25. }
  26. function getChainId() external view returns (uint256) {
  27. return block.chainid;
  28. }
  29. /**
  30. * @dev This empty reserved space is put in place to allow future versions to add new
  31. * variables without shifting down storage in the inheritance chain.
  32. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  33. */
  34. uint256[50] private __gap;
  35. }