Stellar Access Control
Access Control, Ownable, and Role Transfer utilities for Stellar contracts.
Overview
This package provides three main modules for managing access control in Soroban smart contracts:
- Access Control: Role-based access control with hierarchical permissions
- Ownable: Simple single-owner access control pattern
- Role Transfer: Utility module for secure role and ownership transfers
Modules
Access Control
The access_control module provides comprehensive role-based access control functionality:
- Admin Management: Single overarching admin with full privileges
- Role Hierarchy: Roles can have admin roles that can grant/revoke permissions
- Secure Transfers: Two-step admin transfer process for security
Usage Examples
use ;
use ;
use default_impl;
;
With Macros (requires stellar-macros dependency):
use ;
Ownable
The ownable module implements a simple ownership pattern:
- Single Owner: Contract has one owner with exclusive access
- Ownership Transfer: Secure two-step ownership transfer
- Ownership Renouncement: Owner can renounce ownership
Usage Examples
use ;
use ;
use default_impl;
;
With Macros (requires stellar-macros dependency):
use only_owner;
Role Transfer
The role_transfer module is a utility module that provides the underlying infrastructure for secure two-step role and ownership transfers used by both Access Control and Ownable modules.
Security Model
Both Access Control and Ownable modules implement a two-step transfer process for critical role changes:
- Initiate Transfer: Current admin/owner specifies the new recipient and expiration
- Accept Transfer: Designated recipient must explicitly accept the transfer
This mechanism prevents accidental transfers to wrong addresses or loss of control due to typos or errors.
Note: Unlike OpenZeppelin's Solidity library where role transfers can be immediate, all role transfers in this Stellar library are always two-step processes for enhanced security. This applies to both ownership transfers and admin role transfers.
Installation
Add this to your Cargo.toml:
[]
# We recommend pinning to a specific version, because rapid iterations are expected as the library is in an active development phase.
= "=0.5.0"
# Add this if you want to use macros
= "=0.5.0"
Examples
See the following examples in the repository:
examples/ownable/- Simple ownership patternexamples/nft-access-control/- Role-based access control
License
This package is part of the Stellar Contracts library and follows the same licensing terms.