/ test / RewardSigUtils.sol
RewardSigUtils.sol
 1  // SPDX-License-Identifier: MIT
 2  pragma solidity ^0.8.20;
 3  
 4  import "../src/GasBroker.sol";
 5  
 6  contract RewardSigUtils {
 7    bytes32 internal DOMAIN_SEPARATOR;
 8  
 9    constructor(bytes32 _DOMAIN_SEPARATOR) {
10        DOMAIN_SEPARATOR = _DOMAIN_SEPARATOR;
11    }
12  
13    // computes the hash of a reward
14    function getStructHash(Reward memory _reward)
15        internal
16        pure
17        returns (bytes32)
18    {
19        return
20            keccak256(
21                abi.encode(
22                    keccak256("Reward(uint256 value,bytes32 permitHash)"),
23                    _reward.value,
24                    _reward.permitHash
25                )
26            );
27    }
28  
29    // computes the hash of the fully encoded EIP-712 message for the domain, which can be used to recover the signer
30    function getTypedDataHash(Reward memory _reward)
31        public
32        view
33        returns (bytes32)
34    {
35        return
36            keccak256(
37                abi.encodePacked(
38                    "\x19\x01",
39                    DOMAIN_SEPARATOR,
40                    getStructHash(_reward)
41                )
42            );
43    }
44  }
45