github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/periphery/faucet/authmodules/AdminFaucetAuthModule.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity 0.8.15;
     3  
     4  import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
     5  import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
     6  import { IFaucetAuthModule } from "./IFaucetAuthModule.sol";
     7  import { Faucet } from "../Faucet.sol";
     8  
     9  /// @title  AdminFaucetAuthModule
    10  /// @notice FaucetAuthModule that allows an admin to sign off on a given faucet drip. Takes an admin
    11  ///         as the constructor argument.
    12  contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 {
    13      /// @notice Admin address that can sign off on drips.
    14      address public immutable ADMIN;
    15  
    16      /// @notice EIP712 typehash for the Proof type.
    17      bytes32 public immutable PROOF_TYPEHASH = keccak256("Proof(address recipient,bytes32 nonce,bytes32 id)");
    18  
    19      /// @notice Struct that represents a proof that verifies the admin.
    20      /// @custom:field recipient Address that will be receiving the faucet funds.
    21      /// @custom:field nonce     Pseudorandom nonce to prevent replay attacks.
    22      /// @custom:field id        id for the user requesting the faucet funds.
    23      struct Proof {
    24          address recipient;
    25          bytes32 nonce;
    26          bytes32 id;
    27      }
    28  
    29      /// @param _admin   Admin address that can sign off on drips.
    30      /// @param _name    Contract name.
    31      /// @param _version The current major version of the signing domain.
    32      constructor(address _admin, string memory _name, string memory _version) EIP712(_name, _version) {
    33          ADMIN = _admin;
    34      }
    35  
    36      /// @inheritdoc IFaucetAuthModule
    37      function verify(
    38          Faucet.DripParameters memory _params,
    39          bytes32 _id,
    40          bytes memory _proof
    41      )
    42          external
    43          view
    44          returns (bool valid_)
    45      {
    46          // Generate a EIP712 typed data hash to compare against the proof.
    47          valid_ = SignatureChecker.isValidSignatureNow(
    48              ADMIN,
    49              _hashTypedDataV4(keccak256(abi.encode(PROOF_TYPEHASH, _params.recipient, _params.nonce, _id))),
    50              _proof
    51          );
    52      }
    53  }