Skip to content

Commit a1e5919

Browse files
committed
move draft-EIP712 to utils/cryptography
1 parent e32a07c commit a1e5919

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

contracts/mocks/EIP712External.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
pragma solidity ^0.8.0;
44

5-
import "../utils/draft-EIP712.sol";
5+
import "../utils/cryptography/draft-EIP712.sol";
66
import "../utils/cryptography/ECDSA.sol";
77

88
contract EIP712External is EIP712 {

contracts/token/ERC20/extensions/draft-ERC20Permit.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ pragma solidity ^0.8.0;
44

55
import "./draft-IERC20Permit.sol";
66
import "../ERC20.sol";
7+
import "../../../utils/cryptography/draft-EIP712.sol";
78
import "../../../utils/cryptography/ECDSA.sol";
89
import "../../../utils/Counters.sol";
9-
import "../../../utils/draft-EIP712.sol";
1010

1111
/**
1212
* @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in

contracts/utils/cryptography/ECDSA.sol

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ library ECDSA {
7272

7373
/**
7474
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
75-
* replicates the behavior of the
76-
* https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
77-
* JSON-RPC method.
75+
* produces hash corresponding to the one signed with the
76+
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
77+
* JSON-RPC method as part of EIP-191.
7878
*
7979
* See {recover}.
8080
*/
@@ -83,4 +83,17 @@ library ECDSA {
8383
// enforced by the type signature above
8484
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
8585
}
86+
87+
/**
88+
* @dev Returns an Ethereum Signed Typed Data, created from a
89+
* `domainSeparator` and a `structHash`. This produces hash corresponding
90+
* to the one signed with the
91+
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
92+
* JSON-RPC method as part of EIP-712.
93+
*
94+
* See {recover}.
95+
*/
96+
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
97+
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
98+
}
8699
}

contracts/utils/draft-EIP712.sol renamed to contracts/utils/cryptography/draft-EIP712.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
pragma solidity ^0.8.0;
44

5+
import "./ECDSA.sol";
6+
57
/**
68
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
79
*
@@ -95,6 +97,6 @@ abstract contract EIP712 {
9597
* ```
9698
*/
9799
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
98-
return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash));
100+
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
99101
}
100102
}

0 commit comments

Comments
 (0)