A comprehensive smart contract system for Stellar/Soroban that provides enterprise-grade account management with multi-signature support, role-based access control, and policy-based authorization. Designed for both human users and AI agents requiring sophisticated permission systems.
- π Multi-Signature Account: Advanced smart account with customizable authentication
- π Contract Factory: Secure deployment system with role-based access control
- π― Role-Based Permissions: Admin and Standard signer roles with optional policies
- π Policy System: Time-based, contract allow/deny lists, external delegation, and extensible policies
- π Plugin System: Extensible architecture with install/uninstall lifecycle and authorization hooks
- π External Delegation: Delegate authorization decisions to external policy contracts
- π€ AI Agent Ready: Built for both human users and automated systems
- β‘ Soroban Native: Leverages Stellar's smart contract platform capabilities
- π Upgradeable: Built-in contract upgrade support with permission controls
- π TypeScript Bindings: Auto-generated JavaScript/TypeScript libraries
The system consists of two main smart contracts and supporting JavaScript libraries:
stellar-smart-account/
βββ contracts/
β βββ smart-account/ # Multi-signature account contract with plugin support
β βββ contract-factory/ # Secure contract deployment factory
β βββ deny-list-policy/ # Example external policy contract
β βββ initializable/ # Contract initialization utilities
β βββ storage/ # Storage management utilities
β βββ upgradeable/ # Contract upgrade utilities
βββ packages/
β βββ smart_account/ # TypeScript bindings for smart account
β βββ factory/ # TypeScript bindings for factory
βββ examples/ # Usage examples and demos
The core smart account provides:
- Multiple Signature Schemes: Ed25519 and Secp256r1 (WebAuthn/passkeys), extensible to others
- Flexible Authorization: Role-based access with policy enforcement
- Multi-Signature Support: Customizable authorization logic
- Plugin Architecture: Extensible functionality through installable plugins
- External Delegation: Delegate authorization to external policy contracts
- Soroban Integration: Native account interface implementation
Secure deployment system featuring:
- Role-Based Deployment: Only authorized deployers can create contracts
- Deterministic Addresses: Predictable contract addresses using salt values
- Access Control Integration: Built on OpenZeppelin Stellar contracts
- Rust 1.75+ with
wasm32-unknown-unknown
target - Stellar CLI
- Node.js 18+ (for JavaScript bindings)
- Clone the repository:
git clone https://github.com/Crossmint/stellar-smart-account.git
cd stellar-smart-account
- Build the contracts:
stellar contract build
- Run tests:
cargo test
- Install JavaScript dependencies (optional):
cd packages/smart_account && npm install
cd ../factory && npm install
Role | Capabilities | Use Cases |
---|---|---|
Admin | Full access, can upgrade contracts | System administrators, emergency access |
Standard | Normal operations, cannot modify signers, optional policy restrictions | Regular users, application accounts, AI agents with policies |
- Time-Based: Restrict signer validity to specific time windows
- Contract Allow List: Only permit interactions with specified contracts
- Contract Deny List: Block interactions with specified contracts
- External Delegation: Delegate authorization decisions to external policy contracts
- Extensible: Add custom policies for spending limits, rate limiting, etc.
// Create an AI agent with time-limited access
let time_policy = TimeWindowPolicy {
not_before: start_timestamp,
not_after: end_timestamp,
};
let ai_signer = Signer::Ed25519(
Ed25519Signer::new(ai_agent_pubkey),
SignerRole::Standard(vec![SignerPolicy::TimeWindowPolicy(time_policy)])
);
// Delegate authorization to an external policy contract
let external_policy = ExternalPolicy {
policy_address: deny_list_contract_address,
};
let restricted_signer = Signer::Ed25519(
Ed25519Signer::new(signer_pubkey),
SignerRole::Standard(vec![SignerPolicy::ExternalValidatorPolicy(external_policy)])
);
// Initialize smart account with plugins
SmartAccount::__constructor(
env,
vec![admin_signer],
vec![analytics_plugin_address, logging_plugin_address]
);
// Install additional plugins after deployment
SmartAccount::install_plugin(&env, new_plugin_address)?;
Run the full test suite:
# Run all tests
cargo test
# Run with coverage
cargo install cargo-tarpaulin
cargo tarpaulin --out Html
For optimal performance and cost on Soroban, this project uses storage types deliberately:
- Persistent storage: durable, TTL-based entries with rent; best for long-lived, potentially larger datasets
- Instance storage: bundled with the contract entry, automatically loaded each call; best for small data needed on most calls
- Temporary storage: short TTL and cheaper rent; not used here for critical state
Applied to the Smart Account:
- Signers (SignerKey -> Signer): Persistent
- Admin count (ADMIN_COUNT_KEY): Persistent
- Plugins registry (PLUGINS_KEY): Instance (invoked on every __check_auth)
- Migration flag (MIGRATING): Instance
Why this mapping:
- Plugins are accessed on every call in __check_auth, so keeping the plugin registry in Instance storage avoids separate persistent reads on each invocation.
- Signers and admin count are long-lived and can grow; storing them in Persistent avoids growing the contract instance entry and respects durability expectations.
Notes:
- Instance storage is limited by the ledger entry size limit (approximately 128 KB for the contract entry), so only small, frequently accessed data should be kept there.
- Persistent entries accrue rent over time and can be restored after archival if TTL expires by paying a fee.
Potential future optimizations (not implemented here):
- Skip plugin callbacks when auth contexts are clearly unrelated
- Maintain a fast βhas_pluginsβ indicator to early-exit
- Track a subset of βauth-hookβ plugins to invoke only those on __check_auth
The project maintains 80%+ test coverage with comprehensive integration tests.
- Define the signer struct in
src/auth/signers/
- Implement the
SignatureVerifier
trait - Add variants to
SignerKey
,Signer
, andSignerProof
enums - Update match statements in implementation files
- Create policy struct in
src/auth/policy/
- Implement
AuthorizationCheck
andPolicyCallback
traits - Add to
SignerPolicy
enum - Update policy validation logic
See the Smart Account Architecture Documentation for detailed extension guides.
The contracts are designed for deployment on:
- Stellar Testnet: For development and testing
- Stellar Futurenet: For experimental features
- Stellar Mainnet: For production deployments
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes and add tests
- Ensure tests pass:
cargo test
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.