ping-openmls-sdk
v0.2.0
Published
OpenMLS-based secure messaging SDK — runs in browsers, React Native, RN-Web, and Electron/Tauri.
Readme
ping-openmls-sdk
OpenMLS-based secure messaging for browsers, React Native, RN-Web, and Electron/Tauri. Crypto runs in a Web Worker so the UI is never blocked.
Install
npm install ping-openmls-sdkUsage
import { MessagingClient } from "ping-openmls-sdk";
import { IndexedDbStorage } from "ping-openmls-sdk/storage/indexeddb";
import { WebSocketTransport } from "ping-openmls-sdk/transport/websocket";
// 1. Identity — generate once per user, then persist (encrypted) by your auth flow.
const identityExport = await MessagingClient.generateIdentity();
// 2. Plug in storage + transport.
const storage = new IndexedDbStorage();
const transport = new WebSocketTransport({ baseUrl: "https://relay.example.com" });
// 3. Init.
const client = await MessagingClient.init({
identityExport, deviceLabel: "Web", storage, transport,
});
// 4. Use.
const convo = await client.createConversation({ name: "Team" });
await convo.addMembers([bobKeyPackage]);
await convo.send(new TextEncoder().encode("hello"));
client.onMessage((msg) => {
console.log(new TextDecoder().decode(msg.plaintext));
});
// 5. Catch up after reconnect.
await client.syncConversations();Architecture
The SDK is a thin TypeScript shell over a Rust core compiled to WebAssembly. The Worker owns
the WASM instance; the main thread does not import WASM at all. See
docs/ARCHITECTURE.md for details.
Bundle size
Aim: ≤ 350 KiB gzipped for the WASM blob, ≤ 8 KiB gzipped for the TS surface. We achieve this by:
- Building the WASM with
--release,wasm-opt -O3, and stripping symbols. - Lazy-initializing WASM only on first
init()(soMessagingClient.generateIdentity()doesn't pay the cost on cold pages). - No CBOR or crypto libraries on the main thread.
React Native
On RN, native binaries are preferred — install ping-openmls-sdk-react-native-macos (autolinked). On RN-Web,
this package's WASM build is used as-is.
