Codehash-Gated Capability Registry

codehash-gated-capability-registry · discovery-registry · 744 B runtime · funds-movement

scores

source

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract CapabilityRegistry {
    mapping(bytes4 => address[]) private _agents;

    event Registered(bytes4 indexed capability, address indexed agent, bytes32 codehash);

    function register(bytes4 capability, bytes32 codehash) external {
        require(msg.sender.codehash == codehash, "bad codehash");
        _agents[capability].push(msg.sender);
        emit Registered(capability, msg.sender, codehash);
    }

    function agents(bytes4 capability) external view returns (address[] memory) {
        return _agents[capability];
    }

    function lookup(bytes4 capability) external view returns (address[] memory) {
        return _agents[capability];
    }

    function count(bytes4 capability) external view returns (uint256) {
        return _agents[capability].length;
    }
}