This contract is a decentralized endorsement system for trust scores between users. It allows users to endorse each other with a score, a confidence level, and a topic ID. The scores are stored on the Ethereum blockchain and can be queried to create a trust graph. The contract also supports EIP-712 signatures for off-chain signing and on-chain verification.
The ReputationGraph
contract has the following features:
- Role-based access control for administrative tasks and endorsement management.
- Endorsement submission with EIP-712 signatures.
- Querying scores to create a trust graph.
- Solidity compiler version ^0.8.9.
- OpenZeppelin Contracts for role-based access control.
To use this contract in your project, you can either copy the source code or import it from a package manager such as NPM.
Upon contract deployment, an admin and an endorser role will be set up. The admin is responsible for managing the contract's metadata, while the endorser is responsible for submitting endorsements.
Admin can set a metadata URI using the setMetadataURI
function, which will emit a MetadataUpdated
event.
Users with the endorser role can submit endorsements. Each endorsement consists of a from
address, a to
address, a timestamp, and an array of RawScore
objects. Each RawScore
object contains a topic ID, a score, and a confidence level. The endorsement must be signed using the EIP-712 standard. The _endorse
function will save the endorsement data and emit a Scored
event.
The contract provides two public view functions for querying scores:
getScoresLength
: Returns the length of the scores array.getScores
: Returns a slice of the scores array based on the givenfromIndex
andtoIndex
.
Scored
: Emitted when an endorsement is successfully saved. Contains the endorsement data.MetadataUpdated
: Emitted when the metadata URI is updated by the admin.
The contract defines the following custom errors:
NotSigner
: The signer of the endorsement is not the same as thefrom
address in the endorsement.InvalidTimestamp
: The provided timestamp is earlier than the last endorsement timestamp.