Skip to content

Commit

Permalink
docs: utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ameeshaagrawal committed May 1, 2023
1 parent 36bc657 commit 5074165
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contracts/utils/AccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ pragma solidity 0.8.7;

import "./Ownable.sol";

/**
* @title AccessControl
* @dev This abstract contract implements access control mechanism based on roles.
* Each role can have one or more addresses associated with it, which are granted
* permission to execute functions with the onlyRole modifier.
*/
abstract contract AccessControl is Ownable {
// role => address => permit
mapping(bytes32 => mapping(address => bool)) private _permits;
Expand Down
4 changes: 4 additions & 0 deletions contracts/utils/Hasher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ pragma solidity 0.8.7;

import "../interfaces/IHasher.sol";

/**
* @title Hasher
* @notice contract for hasher contract that calculates the packed message
*/
contract Hasher is IHasher {
/// @inheritdoc IHasher
function packMessage(
Expand Down
33 changes: 33 additions & 0 deletions contracts/utils/Ownable.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.7;

/**
* @title Ownable
* @dev The Ownable contract provides a simple way to manage ownership of a contract
* and allows for ownership to be transferred to a nominated address.
*/
abstract contract Ownable {
address private _owner;
address private _nominee;
Expand All @@ -11,34 +16,62 @@ abstract contract Ownable {
error OnlyOwner();
error OnlyNominee();

/**
* @dev Sets the contract's owner to the address that deploys the contract.
*/
constructor(address owner_) {
_claimOwner(owner_);
}

/**
* @dev Modifier that restricts access to only the contract's owner.
* Throws an error if the caller is not the owner.
*/
modifier onlyOwner() {
if (msg.sender != _owner) revert OnlyOwner();
_;
}

/**
* @dev Returns the current owner of the contract.
*/
function owner() external view returns (address) {
return _owner;
}

/**
* @dev Returns the current nominee for ownership of the contract.
*/
function nominee() external view returns (address) {
return _nominee;
}

/**
* @dev Allows the current owner to nominate a new owner for the contract.
* Throws an error if the caller is not the owner.
* Emits an `OwnerNominated` event with the address of the nominee.
*/
function nominateOwner(address nominee_) external {
if (msg.sender != _owner) revert OnlyOwner();
_nominee = nominee_;
emit OwnerNominated(_nominee);
}

/**
* @dev Allows the nominated owner to claim ownership of the contract.
* Throws an error if the caller is not the nominee.
* Sets the nominated owner as the new owner of the contract.
* Emits an `OwnerClaimed` event with the address of the new owner.
*/
function claimOwner() external {
if (msg.sender != _nominee) revert OnlyNominee();
_claimOwner(msg.sender);
}

/**
* @dev Internal function that sets the owner of the contract to the specified address
* and sets the nominee to address(0).
*/
function _claimOwner(address claimer_) internal {
_owner = claimer_;
_nominee = address(0);
Expand Down
4 changes: 4 additions & 0 deletions contracts/utils/SignatureVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pragma solidity 0.8.7;
import "../interfaces/ISignatureVerifier.sol";
import "../libraries/SignatureVerifierLib.sol";

/**
* @title Signature Verifier
* @notice Verifies the signatures and returns the address of signer recovered from the input signature or digest.
*/
contract SignatureVerifier is ISignatureVerifier {
/// @inheritdoc ISignatureVerifier
function recoverSigner(
Expand Down

0 comments on commit 5074165

Please sign in to comment.