Complete SDKs for integrating AuthLayer role-based access control (RBAC) into frontend applications.
This directory contains comprehensive SDKs for building applications that interact with the AuthLayer smart contract:
- TypeScript SDK - Full-featured TypeScript/JavaScript client library
- Python SDK - Python client library for backend services
- Integration Guide - Step-by-step integration instructions
- Examples - Complete working examples for React and Flask
- TypeScript SDK - npm package
- Python SDK - PyPI package
- Integration Guide - Complete integration instructions
- Examples - Working code examples
- Complete API Coverage: All 54 contract methods
- Type Safety: Full TypeScript support with interfaces
- Error Handling: Comprehensive error types
- React Integration: Custom hooks and components
- Batch Operations: Efficient multi-operation support
npm install @authlayer/sdk-tsKey Files:
src/types.ts- Type definitionssrc/client.ts- Main client classsrc/errors.ts- Error typesREADME.md- Complete documentation
- Complete API Coverage: All 54 contract methods
- Type Hints: Full type annotations
- Error Handling: Clear exception types
- Flask/Django: Framework integration examples
- Async Support: Optional async methods
pip install authlayer-sdkKey Files:
stellar_guard/types.py- Type definitionsstellar_guard/client.py- Main client classstellar_guard/errors.py- Error typesREADME.md- Complete documentation
cd frontend/sdk/typescript
npm install
npm run build
npm publish # Or use locallycd frontend/sdk/python
pip install -e .
# Or for publishing
python -m build
twine upload dist/*import { StellarGuard, Permission } from "@stellar-guard/sdk-ts";
const sg = new StellarGuard({
contractId: "YOUR_CONTRACT_ID",
rpcUrl: "https://soroban-testnet.stellar.org",
networkPassphrase: "Test SDF Network ; September 2015",
});
// Check permissions
const canWrite = await sg.hasPermission(userAddress, Permission.Write);
// Grant role
await sg.grantRole(adminAddress, userAddress, "editor");
// Get user's roles
const roles = await sg.getMemberRoles(userAddress);from stellar_guard import StellarGuard, Permission, StellarGuardConfig
config = StellarGuardConfig(
contract_id="YOUR_CONTRACT_ID",
rpc_url="https://soroban-testnet.stellar.org",
network_passphrase="Test SDF Network ; September 2015",
)
sg = StellarGuard(config)
# Check permissions
can_write = sg.has_permission(user_address, Permission.WRITE)
# Grant role
sg.grant_role(admin_address, user_address, "editor")
# Get user's roles
roles = sg.get_member_roles(user_address)// TypeScript
await sg.createRole(admin, "manager", [Permission.Read, Permission.Write]);
await sg.deleteRole(admin, "manager");
const role = await sg.getRole("manager");
const roles = await sg.listRoles();# Python
sg.create_role(admin, "manager", [Permission.READ, Permission.WRITE])
sg.delete_role(admin, "manager")
role = sg.get_role("manager")
roles = sg.list_roles()// TypeScript
await sg.grantRole(admin, member, "editor");
await sg.revokeRole(admin, member, "editor");
const hasRole = await sg.hasRole(member, "editor");
const hasPermission = await sg.hasPermission(member, Permission.Write);# Python
sg.grant_role(admin, member, "editor")
sg.revoke_role(admin, member, "editor")
has_role = sg.has_role(member, "editor")
has_permission = sg.has_permission(member, Permission.WRITE)// TypeScript
await sg.setAccessPolicy(admin, "resource", { type: "RoleBased", roles: ["admin"] });
const policy = await sg.getAccessPolicy("resource");
const canAccess = await sg.canAccessResource(member, "resource");# Python
sg.set_access_policy(admin, "resource", RoleBasedPolicy(roles=["admin"]))
policy = sg.get_access_policy("resource")
can_access = sg.can_access_resource(member, "resource")// TypeScript
await sg.grantDelegationRights(admin, delegator, "editor");
const canDelegate = await sg.canDelegateRole(delegator, "editor");
await sg.delegateRole(delegator, delegate, "editor");# Python
sg.grant_delegation_rights(admin, delegator, "editor")
can_delegate = sg.can_delegate_role(delegator, "editor")
sg.delegate_role(delegator, delegate, "editor")// TypeScript
await sg.grantRoleWithExpiry(admin, member, "editor", expiresAt);
const expiry = await sg.getRoleExpiry(member, "editor");
const isExpired = await sg.isRoleExpired(member, "editor");
await sg.cleanupExpiredRoles(member);# Python
sg.grant_role_with_expiry(admin, member, "editor", expires_at)
expiry = sg.get_role_expiry(member, "editor")
is_expired = sg.is_role_expired(member, "editor")
sg.cleanup_expired_roles(member)// TypeScript
await sg.grantRolesBatch(admin, member, ["editor", "viewer"]);
await sg.revokeRolesBatch(admin, member, ["editor", "viewer"]);
await sg.grantRoleToMembers(admin, [member1, member2], "viewer");# Python
sg.grant_roles_batch(admin, member, ["editor", "viewer"])
sg.revoke_roles_batch(admin, member, ["editor", "viewer"])
sg.grant_role_to_members(admin, [member1, member2], "viewer")// TypeScript
const count = await sg.getRoleMemberCount("editor");
const members = await sg.getRoleMembers("editor", 50, 0);
const stats = await sg.getContractStats();
const access = await sg.verifyMemberAccess(member);# Python
count = sg.get_role_member_count("editor")
members = sg.get_role_members("editor", limit=50, offset=0)
stats = sg.get_contract_stats()
access = sg.verify_member_access(member)See examples/typescript-react-example.tsx for a complete React example including:
- Custom hooks for roles and permissions
- Permission guards
- Admin panel
- Dashboard
# To use in your React project:
npm install @stellar-guard/sdk-ts
# Then copy relevant patterns from the exampleSee examples/python-flask-example.py for a complete Flask example including:
- Permission decorators
- Role-based access control
- API endpoints
- HTML dashboard
# To use in your Flask project:
pip install stellar-guard-sdk flask
# Then adapt the example to your needs# .env
REACT_APP_CONTRACT_ID=CBDMK2XFZC5RWF5ZFRVX...
REACT_APP_RPC_URL=https://soroban-testnet.stellar.org
REACT_APP_NETWORK_PASSPHRASE=Test SDF Network ; September 2015TypeScript:
const config: StellarGuardConfig = {
contractId: "...",
rpcUrl: "...",
networkPassphrase: "...",
timeout: 30000,
};Python:
config = StellarGuardConfig(
contract_id="...",
rpc_url="...",
network_passphrase="...",
timeout=30000,
)import {
StellarGuardError,
AuthorizationError,
RoleNotFoundError,
PermissionDeniedError,
} from "@stellar-guard/sdk-ts";
try {
await sg.grantRole(admin, member, "nonexistent");
} catch (error) {
if (error instanceof RoleNotFoundError) {
console.error("Role not found");
} else if (error instanceof AuthorizationError) {
console.error("Not authorized");
} else if (error instanceof StellarGuardError) {
console.error(`Error: ${error.message}`);
}
}from stellar_guard import (
StellarGuardError,
AuthorizationError,
RoleNotFoundError,
PermissionDeniedError,
)
try:
sg.grant_role(admin, member, "nonexistent")
except RoleNotFoundError:
print("Role not found")
except AuthorizationError:
print("Not authorized")
except StellarGuardError as error:
print(f"Error: {error.message}")Both SDKs support these standard permissions:
READ/Read- Read dataWRITE/Write- Modify dataDELETE/Delete- Remove dataEXECUTE/Execute- Run functionsMANAGE_MEMBERS/ManageMembers- Control usersMANAGE_ROLES/ManageRoles- Manage rolesMANAGE_PERMISSIONS/ManagePermissions- Manage permissionsAPPROVE/Approve- Approve actions
Both SDKs support custom, application-defined permissions:
TypeScript:
const customPerm: CustomPermission = {
type: "Custom",
value: "publish_content",
};
await sg.grantPermission(admin, member, customPerm);Python:
custom_perm = CustomPermission(value="publish_content")
sg.grant_permission(admin, member, custom_perm)Both SDKs support multiple access policy types:
Public- Open to everyoneAuthenticated- Any memberRoleBased- Specific rolesPermissionBased- Specific permissionsWhitelist- Explicit addressesCustom- Application-defined
cd frontend/sdk/typescript
npm test
npm run lint
npm run formatcd frontend/sdk/python
pytest
pytest --cov=stellar_guard
black stellar_guard tests
isort stellar_guard testscd frontend/sdk/typescript
npm run build
npm publishcd frontend/sdk/python
python -m build
twine upload dist/*- TypeScript SDK Docs - Full TypeScript documentation
- Python SDK Docs - Full Python documentation
- Integration Guide - Integration patterns and examples
- Example Applications - Working example code
- GitHub: https://github.com/authlayer/authlayer
- Issues: https://github.com/authlayer/authlayer/issues
- Discord: AuthLayer community
MIT - See LICENSE file
- Initial release
- TypeScript SDK with 54 contract methods
- Python SDK with 54 contract methods
- Comprehensive documentation
- React and Flask examples
- Full error handling
- Type safety