Skip to main content

Access Control Temporal Data Module

Manages temporal role assignments and their expiry

Key Features
  • Provides internal functions for temporal role management.
  • Leverages diamond storage for temporal role data.
  • Reverts with specific errors for expired roles or unauthorized accounts.
  • No external dependencies; designed for direct integration into facets.
Module Usage

This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.

Overview

This module provides internal functions to manage temporal role assignments, including their expiry. Facets can import this module to check and enforce role validity using shared diamond storage. Changes to role expiry are immediately visible to all facets accessing the same storage.

Storage

AccessControlStorage

Storage struct for AccessControl (reused struct definition). Must match the struct definition in AccessControlDataFacet. storage-location: erc8042:compose.accesscontrol

Definition
struct AccessControlStorage {
mapping(address account => mapping(bytes32 role => bool hasRole)) hasRole;
mapping(bytes32 role => bytes32 adminRole) adminRole;
}

AccessControlTemporalStorage

Storage struct for AccessControlTemporal. storage-location: erc8042:compose.accesscontrol.temporal

Definition
struct AccessControlTemporalStorage {
mapping(address account => mapping(bytes32 role => uint256 expiryTimestamp)) roleExpiry;
}

State Variables

PropertyTypeDescription
ACCESS_CONTROL_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol"))
TEMPORAL_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol.temporal"))

Functions

getAccessControlStorage

Returns the storage for AccessControl.

function getAccessControlStorage() pure returns (AccessControlStorage storage s);

Returns:

PropertyTypeDescription
sAccessControlStorageThe AccessControl storage struct.

getRoleExpiry

Returns the expiry timestamp for a role assignment.

function getRoleExpiry(bytes32 _role, address _account) view returns (uint256);

Parameters:

PropertyTypeDescription
_rolebytes32The role to check.
_accountaddressThe account to check.

Returns:

PropertyTypeDescription
-uint256The expiry timestamp, or 0 if no expiry is set.

getStorage

Returns the storage for AccessControlTemporal.

function getStorage() pure returns (AccessControlTemporalStorage storage s);

Returns:

PropertyTypeDescription
sAccessControlTemporalStorageThe AccessControlTemporal storage struct.

isRoleExpired

Checks if a role assignment has expired.

function isRoleExpired(bytes32 _role, address _account) view returns (bool);

Parameters:

PropertyTypeDescription
_rolebytes32The role to check.
_accountaddressThe account to check.

Returns:

PropertyTypeDescription
-boolTrue if the role has expired or doesn't exist, false if still valid.

requireValidRole

Checks 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.

function requireValidRole(bytes32 _role, address _account) view;

Parameters:

PropertyTypeDescription
_rolebytes32The role to check.
_accountaddressThe account to check the role for.

Events

Errors

Best Practices

Best Practice
  • Ensure temporal role expiry checks are performed before critical operations.
  • Handle AccessControlRoleExpired and AccessControlUnauthorizedAccount errors explicitly when calling requireValidRole.
  • Verify that the AccessControlTemporalDataMod is initialized with correct storage slot and that related modules are compatible.

Integration Notes

Shared Storage

This module interacts with diamond storage at the ACCESS_CONTROL_STORAGE_POSITION, identified by keccak256("compose.accesscontrol"), to store and retrieve temporal role assignment data. The AccessControlTemporalStorage struct is managed implicitly through this slot. Changes made via functions like getRoleExpiry or checks performed by isRoleExpired and requireValidRole directly access and reflect the state within the diamond's shared storage, making them immediately visible to any other facet that reads from the same storage position.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.