-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from Think-and-Dev/update_03Erc20Enforcer
Update 03 erc20 enforcer
- Loading branch information
Showing
2 changed files
with
106 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.13; | ||
|
||
contract PermitSigUtils { | ||
bytes32 internal DOMAIN_SEPARATOR; | ||
|
||
constructor(bytes32 _DOMAIN_SEPARATOR) { | ||
DOMAIN_SEPARATOR = _DOMAIN_SEPARATOR; | ||
} | ||
|
||
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); | ||
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; | ||
|
||
struct Permit { | ||
address owner; | ||
address spender; | ||
uint256 value; | ||
uint256 nonce; | ||
uint256 deadline; | ||
} | ||
|
||
// computes the hash of a permit | ||
function getStructHash(Permit memory _permit) internal pure returns (bytes32) { | ||
return | ||
keccak256( | ||
abi.encode(PERMIT_TYPEHASH, _permit.owner, _permit.spender, _permit.value, _permit.nonce, _permit.deadline) | ||
); | ||
} | ||
|
||
// computes the hash of the fully encoded EIP-712 message for the domain, which can be used to recover the signer | ||
function getTypedDataHash(Permit memory _permit) public view returns (bytes32) { | ||
return keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, getStructHash(_permit))); | ||
} | ||
} |