// SPDX-License-Identifier: GPL-3.0 //Source: https://gist.github.com/kadenzipfel/4c4d10f187f43e4ec1117f0229d45484#file-accesscontrol-sol pragma solidity ^0.8.20; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; contract AccessControl { using ECDSA for bytes32; mapping(address => bool) isAdmin; mapping(address => bool) isRegularUser; constructor(){ isAdmin[msg.sender] = true; } // Add admins and regular users. function addUsers(address[] calldata admins, address[] calldata regularUsers, bytes calldata signature) public { if (!isAdmin[msg.sender]) { // Allow calls to be relayed with an admin's signature. bytes32 hash = MessageHashUtils.toEthSignedMessageHash(keccak256(abi.encodePacked(admins, regularUsers))); address signer = hash.recover(signature); require(isAdmin[signer], "Only admins can add users."); } for (uint256 i = 0; i < admins.length; i++) { isAdmin[admins[i]] = true; } for (uint256 i = 0; i < regularUsers.length; i++) { isRegularUser[regularUsers[i]] = true; } } } contract hash { function hashingData(address[] calldata data1, address[] calldata data2) public pure returns(bytes32){ return keccak256(abi.encodePacked(data1, data2)); } }