Skip to content

feat(contracts): implement role-based access control (RBAC)#214

Open
DammyAji wants to merge 1 commit into
AetherEdu:mainfrom
DammyAji:main
Open

feat(contracts): implement role-based access control (RBAC)#214
DammyAji wants to merge 1 commit into
AetherEdu:mainfrom
DammyAji:main

Conversation

@DammyAji

Copy link
Copy Markdown
Contributor

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

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
@DammyAji

Copy link
Copy Markdown
Contributor Author

@Penielka please kindly review. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contracts] Implement role-based access control

1 participant