Blockchain Diploma Verification Contract

What it does:
Verifies diplomas and academic credentials on-chain, allowing students, employers, and institutions to confirm authenticity instantly.

Why it matters:
Eliminates resume fraud, streamlines hiring and admissions, and provides a permanent, tamper-proof academic record.

How it works:

  • Universities or accredited institutions register as trusted issuers

  • Students’ diplomas are hashed and stored on-chain

  • Students can share their credential hash with employers or other institutions

  • Third parties verify the hash against on-chain records

  • Institutions can revoke or update credentials if needed

  • All verification and issuance actions are auditable

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

/**
 * @title BlockchainDiplomaVerification
 * @author Nam
 * @notice On-chain verification of diplomas and academic credentials
 */
contract BlockchainDiplomaVerification {

    // -------------------- ROLES --------------------

    address public admin;

    mapping(address => bool) public trustedInstitutions;

    // -------------------- STRUCTS --------------------

    struct Diploma {
        string diplomaHash; // IPFS / encrypted diploma
        address issuer;
        uint256 issuedAt;
        bool valid;
    }

    mapping(address => Diploma[]) public studentDiplomas;

    // -------------------- EVENTS --------------------

    event InstitutionAuthorized(address indexed institution);
    event DiplomaIssued(address indexed student, uint256 diplomaId, address indexed issuer);
    event DiplomaRevoked(address indexed student, uint256 diplomaId);

    // -------------------- MODIFIERS --------------------

    modifier onlyAdmin() {
        require(msg.sender == admin, "Not admin");
        _;
    }

    modifier onlyInstitution() {
        require(trustedInstitutions[msg.sender], "Not authorized institution");
        _;
    }

    // -------------------- CONSTRUCTOR --------------------

    constructor() {
        admin = msg.sender;
    }

    // -------------------- INSTITUTION MANAGEMENT --------------------

    function authorizeInstitution(address _institution) external onlyAdmin {
        require(_institution != address(0), "Invalid address");
        trustedInstitutions[_institution] = true;
        emit InstitutionAuthorized(_institution);
    }

    // -------------------- DIPLOMA MANAGEMENT --------------------

    function issueDiploma(address _student, string calldata _diplomaHash) external onlyInstitution {
        require(_student != address(0), "Invalid student");

        studentDiplomas[_student].push(Diploma({
            diplomaHash: _diplomaHash,
            issuer: msg.sender,
            issuedAt: block.timestamp,
            valid: true
        }));

        emit DiplomaIssued(_student, studentDiplomas[_student].length - 1, msg.sender);
    }

    function revokeDiploma(address _student, uint256 _diplomaId) external onlyInstitution {
        require(_diplomaId < studentDiplomas[_student].length, "Invalid diploma ID");
        Diploma storage d = studentDiplomas[_student][_diplomaId];
        require(d.valid, "Already revoked");

        d.valid = false;
        emit DiplomaRevoked(_student, _diplomaId);
    }

    // -------------------- VERIFICATION --------------------

    function verifyDiploma(address _student, uint256 _diplomaId) external view returns (
        string memory diplomaHash,
        address issuer,
        bool valid
    ) {
        require(_diplomaId < studentDiplomas[_student].length, "Invalid diploma ID");
        Diploma memory d = studentDiplomas[_student][_diplomaId];
        return (d.diplomaHash, d.issuer, d.valid);
    }
}