AccessControlTemporalMod
Manages time-bound role assignments in a diamond
- Manages roles with specific expiry timestamps.
- Provides
requireValidRolefor immediate validation and reverts on expiry or lack of role. - All functions are
internal, intended for use within facets. - Integrates with the diamond storage pattern.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides functionality to grant roles with specific expiry timestamps. Facets can use this module to enforce time-limited access control, ensuring that roles automatically become invalid after their designated expiry. It leverages the diamond storage pattern for shared state across facets.
Storage
AccessControlStorage
AccessControlTemporalStorage
State Variables
| Property | Type | Description |
|---|---|---|
ACCESS_CONTROL_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol")) |
TEMPORAL_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol.temporal")) |
Functions
getAccessControlStorage
Returns the storage for AccessControl.
Returns:
| Property | Type | Description |
|---|---|---|
s | AccessControlStorage | The AccessControl storage struct. |
getRoleExpiry
function to get the expiry timestamp for a role assignment.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to check. |
_account | address | The account to check. |
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The expiry timestamp, or 0 if no expiry is set. |
getStorage
Returns the storage for AccessControlTemporal.
Returns:
| Property | Type | Description |
|---|---|---|
s | AccessControlTemporalStorage | The AccessControlTemporal storage struct. |
grantRoleWithExpiry
function to grant a role with an expiry timestamp.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to grant. |
_account | address | The account to grant the role to. |
_expiresAt | uint256 | The timestamp when the role should expire. |
Returns:
| Property | Type | Description |
|---|---|---|
- | bool | True if the role was granted, false otherwise. |
isRoleExpired
function to check if a role assignment has expired.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to check. |
_account | address | The account to check. |
Returns:
| Property | Type | Description |
|---|---|---|
- | bool | True if the role has expired or doesn't exist, false if still valid. |
requireValidRole
function to check if an account has a valid (non-expired) role. Notes: - Reverts with AccessControlUnauthorizedAccount If the account does not have the role. - Reverts with AccessControlRoleExpired If the role has expired.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to check. |
_account | address | The account to check the role for. |
revokeTemporalRole
function to revoke a temporal role.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to revoke. |
_account | address | The account to revoke the role from. |
Returns:
| Property | Type | Description |
|---|---|---|
- | bool | True if the role was revoked, false otherwise. |
Events
Errors
Best Practices
- Call
requireValidRolebefore executing sensitive operations to ensure the caller's role is still active. - Use
grantRoleWithExpiryto define clear time boundaries for role permissions. - Handle
AccessControlRoleExpiredandAccessControlUnauthorizedAccounterrors returned byrequireValidRole.
Integration Notes
This module interacts with diamond storage at the ACCESS_CONTROL_STORAGE_POSITION, which is determined by keccak256("compose.accesscontrol"). It utilizes the AccessControlTemporalStorage struct. All state modifications are managed through internal functions, ensuring consistency and visibility across all facets that access the same storage slot.