feat(contracts): implement role-based access control (RBAC)#214
Open
DammyAji wants to merge 1 commit into
Open
feat(contracts): implement role-based access control (RBAC)#214DammyAji wants to merge 1 commit into
DammyAji wants to merge 1 commit into
Conversation
Closes AetherEdu#24 - Added access_control.rs module with Role enum (Admin, Issuer, Instructor, Student) - Modified initialize() to bootstrap Admin role for RBAC - Updated issue_credential() and issue_credential_with_expiration() to require Issuer role - Updated create_course() and create_course_metadata() to require Instructor role - Added grant_role() and revoke_role() public functions (Admin only) - Added has_role() public function - Updated revoke_credential in credentials and credential_registry to use Admin role - Multiple roles per address supported via Vec<u32> storage
Contributor
Author
|
@Penielka please kindly review. Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #24
Summary
This PR implements role-based access control (RBAC) for the smart contracts, replacing the simple admin check with granular permissions.
Changes Made
New Files
contracts/src/access_control.rs - RBAC module with:
Role enum: Admin(0), Issuer(1), Instructor(2), Student(3)
Role storage per address using AccessKey::Roles(Address)
grant_role() / revoke_role() - Admin-only functions
has_role() / require_role() - Helper functions
Modified Files
contracts/src/lib.rs:
Added pub mod access_control; module declaration
initialize() now bootstraps Admin role via access_control::set_initial_admin()
issue_credential() now requires Issuer role
create_course() now requires Instructor role
Added public grant_role(), revoke_role(), has_role() functions
contracts/src/credentials.rs:
issue_credential() now uses require_role() for Issuer
revoke_credential() now uses require_role() for Admin
contracts/src/credential_registry.rs:
issue_credential_with_expiration() now uses require_role() for Issuer
issue_credentials_batch() now uses require_role() for Issuer
revoke_credential() now uses require_role() for Admin
contracts/src/courseMetadata.rs:
create_course_metadata() now requires Instructor role
Acceptance Criteria Met
✅ Role enum: Admin, Issuer, Instructor, Student
✅ Role storage per address
✅ Admin can grant/revoke roles (via grant_role/revoke_role)
✅ Issuer can issue credentials (enforced in issue_credential*)
✅ Instructor can create courses (enforced in create_course)
✅ Only Admin can change roles (enforced in grant_role/revoke_role)
✅ Role check helper functions (has_role, require_role)
✅ Role revocation prevents future operations (roles checked on each call)
✅ Multiple roles per address supported (Vec storage)
Closes #24