AccessControlTemporalFacet
Grants and revokes roles with expiry timestamps
- Manages roles with specific expiry timestamps.
- Integrates seamlessly with the diamond proxy pattern.
- Exposes external functions for temporal role management.
- Utilizes Compose's internal storage access patterns.
Overview
This facet implements temporal role-based access control within a diamond. It provides functions to grant roles with specific expiry dates and to revoke them. Calls are routed through the diamond proxy, allowing for dynamic access management integrated with other diamond functionalities. Developers add this facet to enable time-limited permissions for accounts.
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
getRoleExpiry
Returns 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. |
isRoleExpired
Checks 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. |
grantRoleWithExpiry
Grants a role to an account with an expiry timestamp. Only the admin of the role can grant it with expiry. Emits a RoleGrantedWithExpiry event. Reverts with AccessControlUnauthorizedAccount If the caller is not the admin of the role.
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 (must be in the future). |
revokeTemporalRole
Revokes a temporal role from an account. Only the admin of the role can revoke it. Emits a TemporalRoleRevoked event. Reverts with AccessControlUnauthorizedAccount If the caller is not the admin of the role.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to revoke. |
_account | address | The account to revoke the role from. |
requireValidRole
Checks if an account has a valid (non-expired) role. - 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. |
Events
Errors
Best Practices
- Initialize temporal roles using
grantRoleWithExpiryduring diamond setup or via authorized administrative functions. - Regularly check role expiry using
isRoleExpiredbefore executing sensitive operations. - Ensure that only authorized administrative facets can call
grantRoleWithExpiryandrevokeTemporalRole.
Security Considerations
All state-changing functions (grantRoleWithExpiry, revokeTemporalRole) require the caller to be the admin of the respective role, enforced by AccessControlUnauthorizedAccount revert. The requireValidRole function checks for both role existence and expiry, reverting with AccessControlUnauthorizedAccount or AccessControlRoleExpired respectively. Input validation for expiry timestamps is crucial at the calling facet level.