SDK Dependencies
Frompackage.json:
Crypto Implementation
Sable uses the modern Rust crypto backend:- @matrix-org/matrix-sdk-crypto-wasm - WebAssembly-based encryption
- Provides E2EE (end-to-end encryption)
- Replaces the legacy JavaScript crypto implementation
- Significantly faster and more secure
Import Boundary
All Matrix SDK imports go throughsrc/types/matrix-sdk.ts for consistency:
Client Initialization
Client initialization is handled insrc/client/initMatrix.ts.
Creating a Client
Initializing Rust Crypto
After client creation, initialize the Rust crypto backend:Starting the Client
Once initialized, start the sync loop:Session Storage
Sable supports multiple accounts with isolated storage:Store Cleanup
Before initialization, clean up mismatched stores:- User data doesn’t match session
- Old accounts have orphaned databases
- Store names conflict
E2EE (End-to-End Encryption)
Crypto Callbacks
Handle secret storage and cross-signing:Device Verification
Sable supports SAS (Short Authentication String) verification:Encryption Status
Check if a room is encrypted:Event Handling
Sable uses hooks to subscribe to Matrix events reactively.Room Events
Listen for timeline events:State Events
Listen for state changes:Custom Event Listeners
For more control, use Matrix client events directly:Widget Integration
Sable supports Matrix widgets via matrix-widget-api:Build Configuration
Vite Setup for WASM
The Vite config handles WebAssembly loading:Service Worker for Media
Authenticated media requests are handled by the service worker:Common Operations
Sending Messages
Uploading Files
Reading Receipts
Typing Indicators
Best Practices
- Always use the import boundary - Import from
$types/matrix-sdk, notmatrix-js-sdk - Initialize crypto - Always call
initRustCrypto()after creating a client - Clean up listeners - Remove event listeners in
useEffectcleanup - Handle sync states - Listen for
syncevents to show connection status - Use hooks - Prefer Sable’s Matrix hooks over direct SDK usage
- Lazy load members - Enable
lazyLoadMembersto reduce memory usage - Persist sessions - Store sessions in localStorage for multi-account support
- Verify devices - Implement device verification flows for security
- Handle errors - Matrix operations can fail; always handle rejections
- Test with encryption - Ensure features work in encrypted rooms