Learning ERC-7208

Data Index

As outlined in the Core Concepts, the IDataIndex interface defines functions to manage access control for Data Managers and their associated Data Points within Data Objects. It extends the IIDManager interface.

In this section, we'll explain the minimalistic implementation of the Data Index.

The implementation follows the standard interface and is divided into two parts: methods for managing permissions and forwarding operations. This implementation includes an access control mechanism, and IDataIndex supports Data Index IDs per the IDManager standard interface.

/**
 * @title Data Index contract
 * @notice Minimalistic implementation of a Data Index contract
 */
contract DataIndex is IDataIndex, AccessControl {
    // Implementation
}

To store and manage permissions for Data Managers allowed to write to specific Data Points, you'll find:

/// @dev Mapping of DataPoint to DataManagers allowed to write to this DP (in any DataObject)
mapping(DataPoint => mapping(address dm => bool allowed)) private _dmApprovals;

Modifiers

The modifiers are crucial for organizing access control and restricting access to certain methods:

1. onlyDPOwner()

    /**
     * @notice Restricts access to the function, allowing only DataPoint admins
     * @param dp DataPoint to check ownership of
     */
    modifier onlyDPOwner(DataPoint dp) {
        (uint32 chainId, address registry, ) = DataPoints.decode(dp);
        ChainidTools.requireCurrentChain(chainId);
        bool isAdmin = IDataPointRegistry(registry).isAdmin(dp, msg.sender);
        if (!isAdmin) revert InvalidDataPointAdmin(dp, msg.sender);
        _;
    }

The Data Point structure holds key information about the processing chain and registry. The Nexera Standard ensures interoperability, storing the source chain ID. We retrieve the chain ID to confirm the correct destination chain and check the registry address to verify if the sender is a Data Point admin, ensuring only trusted users can modify its storage.

2. onlyApprovedDM()

    /**
     * @notice Allows access only to DataManagers which was previously approved
     * @param dp DataPoint to check DataManager approval for
     */
    modifier onlyApprovedDM(DataPoint dp) {
        bool approved = _dmApprovals[dp][msg.sender];
        if (!approved) revert DataManagerNotApproved(dp, msg.sender);
        _;
    }

Only whitelisted Data Managers can transact through the Data Index to Data Points. We verify if the message sender is an authorized Data Manager.

The reference implementation for managing permissions and forwarding operations includes four main methods: isApprovedDataManager(), allowDataManager(), read(), and write(). Additionally, the IDManager interface is used to generate user identifiers and retrieve user information.

The methods inherited from IIDManager provide ownership details for the DataIndex or generate user IDs:

    ///@inheritdoc IIDManager
    function diid(address account, DataPoint) external pure returns (bytes32) {
        return bytes32(uint256(uint160(account)));
    }
 
    ///@inheritdoc IIDManager
    function ownerOf(bytes32 diid_) external view returns (uint32, address) {
        if (diid_ & PREFIX_MASK != 0) revert IncorrectIdentifier(diid_); // Require first 12 bytes empty, leaving only 20 bytes of address non-empty
        address account = address(uint160(uint256(diid_)));
        if (account == address(0)) revert IncorrectIdentifier(diid_);
        return (ChainidTools.chainid(), account);
    }

On this page