A TypeScript SDK for local-first encrypted storage with optional IPFS backup capabilities.
- Local-First Storage: Encrypted chat data stored locally using SQLite compiled to WebAssembly
- Strong Encryption: End-to-end encryption using the WebCrypto API
- Cross-Platform: Works in browsers, Node.js, and React Native
- Modular Design: Easily integrate specific components or use the full SDK
- Comprehensive Error Handling: Detailed error codes and messages for effective debugging
- Configurable Logging: Flexible logging system that adapts to your application needs
# Using npm
npm install lumox
# Using yarn
yarn add lumox
# Using pnpm
pnpm add lumox
import { LumoxClient, SqliteStorageProvider, WebCryptoProvider } from 'lumox';
import initSqlJs from 'sql.js';
async function main() {
// Initialize SQL.js
const SQL = await initSqlJs();
// Create storage and crypto providers
const storage = new SqliteStorageProvider({ sqlInstance: SQL });
const crypto = new WebCryptoProvider();
// Initialize Lumox client
const lumox = new LumoxClient({ storage, crypto });
await lumox.initialize();
// Generate encryption key
await lumox.generateEncryptionKey();
// Send an encrypted message
const messageId = await lumox.sendMessage('alice', 'bob', 'Hello, encrypted world!');
console.log(`Message sent with ID: ${messageId}`);
// Retrieve and decrypt messages
const messages = await lumox.getMessages('alice', 'bob');
console.log('Messages:', messages);
// Export database for backup
const dbExport = await lumox.exportData();
console.log(`Exported ${dbExport.byteLength} bytes of data`);
// Clean up
await lumox.close();
}
main().catch(console.error);
The main client for interacting with the Lumox system.
const lumox = new LumoxClient({
storage: storageProvider,
crypto: cryptoProvider,
logger: loggerInstance // Optional
});
- initialize(): Initialize the client components
- generateEncryptionKey(): Create a new encryption key
- exportEncryptionKey(): Export the current encryption key as a string
- importEncryptionKey(keyData): Import an encryption key
- sendMessage(senderId, receiverId, content, metadata?): Send an encrypted message
- getMessages(user1Id, user2Id, limit?, offset?): Retrieve and decrypt messages
- exportData(): Export the database as a Uint8Array
- importData(data, overwrite?): Import database data
- close(): Clean up resources
Interface for storage implementations.
// Default SQLite implementation
const storage = new SqliteStorageProvider({
sqlInstance: SQL,
// Optional: filename for persistent storage in browsers
filename: '/sql/chat.db',
// Optional: initial data to load
initialData: existingDbData,
// Optional: logger instance
logger: loggerInstance
});
Interface for encryption implementations.
// Default WebCrypto implementation
const crypto = new WebCryptoProvider({
// Optional: logger instance
logger: loggerInstance
});
Lumox provides a comprehensive error handling and logging system. See Error Handling and Logging for details.
For persistent storage in browsers, you can use the optional absurd-sql
integration:
import { SQLiteFS } from 'absurd-sql';
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend';
// Set up absurd-sql for persistence
const sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend());
SQL.register_for_idb(sqlFS);
SQL.FS.mkdir('/sql');
SQL.FS.mount(sqlFS, {}, '/sql');
// Create storage with persistence
const storage = new SqliteStorageProvider({
sqlInstance: SQL,
filename: '/sql/chat.db'
});
Export and import database for backup or migration:
// Export database
const dbData = await lumox.exportData();
// Save to a file in Node.js
await fs.promises.writeFile('backup.sqlite', Buffer.from(dbData));
// Later, import the database
const importData = await fs.promises.readFile('backup.sqlite');
await lumox.importData(new Uint8Array(importData.buffer), true);
- Local storage using SQLite-WASM
- End-to-end encryption with WebCrypto
- Comprehensive error handling and logging
- Identity integration for key derivation
- Support for Web3 wallets (Ethereum, Solana)
- DID integration
- IPFS backup capabilities
- Conflict resolution for multi-device sync
- Enhanced privacy features
# Install dependencies
pnpm install
# Build the project
pnpm build
# Run tests
pnpm test
# Run example
pnpm example
# Run error handling example
pnpm example:errors
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License.
- SQL.js for SQLite compilation to WebAssembly
- The WebCrypto API team for browser encryption capabilities
- IPFS project for decentralized storage concepts
Built with ❤️ for secure, local-first communications.