Access Control Temporal Grant Facet
Grants roles with time-based expiry
- Grants roles with a specified expiry timestamp.
- Emits
RoleGrantedWithExpiryevent upon successful role granting. - Reverts with
AccessControlUnauthorizedAccountif the caller lacks permission. - Reverts with
AccessControlRoleExpiredif the role has expired.
Overview
This facet manages role assignments with time-based expiry within a Compose diamond. It provides an external function to grant roles, ensuring they automatically expire. This facet interacts with shared diamond storage to manage role assignments, making role management upgradeable and composable.
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
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). |
exportSelectors
Exports the selectors that are exposed by the facet.
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | Selectors that are exported by the facet. |
Events
Errors
Best Practices
- Initialize the diamond with necessary roles and accounts before using this facet.
- Ensure the caller has the administrative privilege for the role being granted.
- Verify role expiry logic by testing with accounts that have expired roles.
Security Considerations
State-changing functions, specifically grantRoleWithExpiry, are protected by access control, ensuring only authorized accounts can grant roles. The function adheres to the checks-effects-interactions pattern. Input validation for the expiry timestamp should be considered to prevent granting roles with past expiry dates, although the AccessControlRoleExpired error implicitly handles this for role checks. The facet relies on the diamond's internal storage mechanism for role management.