-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Make
EIP712DomainSeparator
Module-Friendly (#229)
### 🕓 Changelog This PR refactors the `EIP712DomainSeparator` contract to make it module-friendly and ready for the breaking `0.4.0` release. --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
- Loading branch information
1 parent
40a74ab
commit 8bd2eb1
Showing
7 changed files
with
109 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# pragma version ~=0.4.0b6 | ||
""" | ||
@title EIP712DomainSeparator Module Reference Implementation | ||
@custom:contract-name EIP712DomainSeparatorMock | ||
@license GNU Affero General Public License v3.0 only | ||
@author pcaversaccio | ||
""" | ||
|
||
|
||
# @dev We import and implement the `IERC5267` interface, | ||
# which is written using standard Vyper syntax. | ||
from ..interfaces import IERC5267 | ||
implements: IERC5267 | ||
|
||
|
||
# @dev We import and initialise the `EIP712DomainSeparator` module. | ||
from .. import EIP712DomainSeparator as ed | ||
initializes: ed | ||
|
||
|
||
# @dev We export (i.e. the runtime bytecode exposes these | ||
# functions externally, allowing them to be called using | ||
# the ABI encoding specification) the `external` function | ||
# `eip712Domain` from the `EIP712DomainSeparator` module. | ||
# @notice Please note that you must always also export (if | ||
# required by the contract logic) `public` declared `constant`, | ||
# `immutable`, and state variables, for which Vyper automatically | ||
# generates an `external` getter function for the variable. | ||
exports: ed.eip712Domain | ||
|
||
|
||
@deploy | ||
@payable | ||
def __init__(name_: String[50], version_: String[20]): | ||
""" | ||
@dev Initialises the domain separator and the parameter caches. | ||
To omit the opcodes for checking the `msg.value` in the | ||
creation-time EVM bytecode, the constructor is declared as | ||
`payable`. | ||
@notice The definition of the domain separator can be found here: | ||
https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator. | ||
Since the Vyper design requires strings of fixed size, | ||
we arbitrarily set the maximum length for `name` to 50 | ||
characters and `version` to 20 characters. | ||
@param name_ The maximum 50-character user-readable string name | ||
of the signing domain, i.e. the name of the dApp or protocol. | ||
@param version_ The maximum 20-character current main version of | ||
the signing domain. Signatures from different versions are | ||
not compatible. | ||
""" | ||
ed.__init__(name_, version_) | ||
|
||
|
||
@external | ||
@view | ||
def domain_separator_v4() -> bytes32: | ||
""" | ||
@dev Returns the domain separator for the current chain. | ||
@return bytes32 The 32-byte domain separator. | ||
""" | ||
return ed._domain_separator_v4() | ||
|
||
|
||
@external | ||
@view | ||
def hash_typed_data_v4(struct_hash: bytes32) -> bytes32: | ||
""" | ||
@dev Returns the hash of the fully encoded EIP-712 | ||
message for this domain. | ||
@notice The definition of the hashed struct can be found here: | ||
https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct. | ||
@param struct_hash The 32-byte hashed struct. | ||
@return bytes32 The 32-byte fully encoded EIP712 | ||
message hash for this domain. | ||
""" | ||
return ed._hash_typed_data_v4(struct_hash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters