Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ernestognw/roles-registry
Attempt to make a registry for on-chain roles.
https://github.com/ernestognw/roles-registry
Last synced: 26 days ago
JSON representation
Attempt to make a registry for on-chain roles.
- Host: GitHub
- URL: https://github.com/ernestognw/roles-registry
- Owner: ernestognw
- Created: 2024-04-05T17:18:43.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-04-05T17:18:51.000Z (9 months ago)
- Last Synced: 2024-10-29T02:00:39.175Z (2 months ago)
- Language: Solidity
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Access Control Roles Registry
Attempt to make a registry for on-chain registration of roles.
## Problem
One of the most widely used patterns in smart contracts is the role-based access control pattern. However, there is no standard way of identifying roles. Concretely, [OpenZeppelin's official recommendation.](https://docs.openzeppelin.com/contracts/5.x/api/access#AccessControl) suggests to hash a string literal, which disallows for indexers to get the preimage in a constant way.
Recent implementations such as the OpenZeppelin Access Manager use bytes64 roles that can be [labeled through a function](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.1/contracts/access/manager/AccessManager.sol#L217) that emits an event for off-chain indexers to pick it up, but there's still no interoperability for roles between smart contracts.
## Solution
This repository introduces a Bytes32Roles Registry that stores labels for roles if such label matches the hash representing the role.
## Usage
### Register a role
```solidity
// Hashed bytes32 string literals (<= 32 bytes)
// bytes32 constant ROLE = keccak256("FOO");
function registerStandardBytes32(bytes32 role, string calldata label) external;// Hashed strings (> 32 bytes)
// bytes32 constant ROLE = keccak256("this is a long string that doesn't fit in 32 bytes");
function registerStandardStringLiteral(bytes32 role, string calldata label) external;
```### Get a role
```solidity
function standardBytes32(bytes32 role) external view returns (bytes32);
function standardStringLiteral(bytes32 role) external view returns (string memory);
```### Events
```solidity
event StandardLabelBytes32(bytes32 indexed key, bytes32 value);
event StandardLabelStringLiteral(bytes32 indexed key, string value);
```