socket2jz-core
v1.0.1
Published
Rust-powered, E2EE, real-time chat SDK with <40kB bundle
Maintainers
Readme
@socket2jz/core
TypeScript SDK for socket2jz E2EE real-time chat.
Features
- 🔒 End-to-End Encryption: WASM-powered crypto with AES-256-GCM
- 🌐 WebSocket Transport: Secure WSS connections with auto-reconnect
- 📦 Zero Runtime Dependencies: Pure TypeScript with WASM crypto
- ⚡ High Performance: Optimized bundle size (< 40kB brotli)
- 🧪 Fully Tested: Comprehensive test suite with Vitest
Installation
npm install @socket2jz/coreUsage
import { Socket2jzRoom } from '@socket2jz/core';
// Create a room
const room = new Socket2jzRoom({
url: 'wss://localhost:8443',
e2ee: true
});
// Handle messages
room.on('message', (text) => {
console.log('Received:', text);
});
// Connect and send
await room.join();
room.send('Hello, World!');
// Clean up
room.leave();API
Socket2jzRoom
Constructor
new Socket2jzRoom(config: {
url: string; // WebSocket server URL
e2ee?: boolean; // Enable E2EE (default: true)
})Methods
join(): Promise<void>- Connect to roomsend(text: string): void- Send encrypted messageleave(): void- Disconnect from room
Properties
connected: boolean- Connection statuse2eeEnabled: boolean- E2EE status
Events
connected- Connected to roomdisconnected- Disconnected from roommessage- Received messageerror- Error occurredreconnecting- Reconnection attempt
Development
# Install dependencies
npm install
# Build
npm run build
# Test
npm test
# Check bundle size
npm run sizeBundle Size
- Target: < 40kB brotli compressed
- Check:
npm run size - Build: ESM only, ES2022 target, tree-shaken
Architecture
- Crypto: WASM-based AES-256-GCM encryption
- Transport: WebSocket with auto-reconnect
- Messages: JSON format with timestamp
- Reconnection: Exponential backoff (max 30s)
