@ping-app/ping-openmls-sdk 0.0.0-stage → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +94 -2
  2. package/dist/index.cjs +2782 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +1229 -0
  5. package/dist/index.d.ts +1229 -0
  6. package/dist/index.js +2715 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/notification-preview.cjs +137 -0
  9. package/dist/notification-preview.cjs.map +1 -0
  10. package/dist/notification-preview.d.cts +85 -0
  11. package/dist/notification-preview.d.ts +85 -0
  12. package/dist/notification-preview.js +98 -0
  13. package/dist/notification-preview.js.map +1 -0
  14. package/dist/storage/indexeddb.cjs +153 -0
  15. package/dist/storage/indexeddb.cjs.map +1 -0
  16. package/dist/storage/indexeddb.d.cts +21 -0
  17. package/dist/storage/indexeddb.d.ts +21 -0
  18. package/dist/storage/indexeddb.js +128 -0
  19. package/dist/storage/indexeddb.js.map +1 -0
  20. package/dist/transport/websocket.cjs +121 -0
  21. package/dist/transport/websocket.cjs.map +1 -0
  22. package/dist/transport/websocket.d.cts +23 -0
  23. package/dist/transport/websocket.d.ts +23 -0
  24. package/dist/transport/websocket.js +94 -0
  25. package/dist/transport/websocket.js.map +1 -0
  26. package/dist/types-B1GFwNXa.d.cts +535 -0
  27. package/dist/types-B1GFwNXa.d.ts +535 -0
  28. package/dist/worker.cjs +841 -0
  29. package/dist/worker.cjs.map +1 -0
  30. package/dist/worker.d.cts +2 -0
  31. package/dist/worker.d.ts +2 -0
  32. package/dist/worker.js +848 -0
  33. package/dist/worker.js.map +1 -0
  34. package/package.json +61 -4
  35. package/wasm/package.json +17 -0
  36. package/wasm/ping_wasm.d.ts +909 -0
  37. package/wasm/ping_wasm.js +3028 -0
  38. package/wasm/ping_wasm_bg.wasm +0 -0
  39. package/wasm/ping_wasm_bg.wasm.d.ts +112 -0
package/README.md CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ # @ping-app/ping-openmls-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ OpenMLS-based secure messaging for browsers, React Native, RN-Web, and Electron/Tauri.
4
+ Crypto runs in a Web Worker so the UI is never blocked.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install @ping-app/ping-openmls-sdk
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```typescript
15
+ import { MessagingClient } from "@ping-app/ping-openmls-sdk";
16
+ import { IndexedDbStorage } from "@ping-app/ping-openmls-sdk/storage/indexeddb";
17
+ import { WebSocketTransport } from "@ping-app/ping-openmls-sdk/transport/websocket";
18
+
19
+ // 1. Identity — generate once per user, then persist (encrypted) by your auth flow.
20
+ const identityExport = await MessagingClient.generateIdentity();
21
+
22
+ // 2. Plug in storage + transport.
23
+ const storage = new IndexedDbStorage();
24
+ const transport = new WebSocketTransport({ baseUrl: "https://relay.example.com" });
25
+
26
+ // 3. Init.
27
+ const client = await MessagingClient.init({
28
+ identityExport, deviceLabel: "Web", storage, transport,
29
+ });
30
+
31
+ // 4. Use.
32
+ const convo = await client.createConversation({ name: "Team" });
33
+ await convo.addMembers([bobKeyPackage]);
34
+ await convo.send(new TextEncoder().encode("hello"));
35
+
36
+ client.onMessage((msg) => {
37
+ console.log(new TextDecoder().decode(msg.plaintext));
38
+ });
39
+
40
+ // 5. Catch up after reconnect.
41
+ await client.syncConversations();
42
+ ```
43
+
44
+ ## Architecture
45
+
46
+ The SDK is a thin TypeScript shell over a Rust core compiled to WebAssembly. The Worker owns
47
+ the WASM instance; the main thread does not import WASM at all. See
48
+ [`docs/ARCHITECTURE.md`](../../docs/ARCHITECTURE.md) for details.
49
+
50
+ ## WASM memory sizing (Safari)
51
+
52
+ The wasm module runs inside a dedicated Worker and boots with a **64 MiB heap
53
+ arena** reserved by the linker (`core/ping-wasm/src/alloc.rs`, a `talc`
54
+ allocator with an arena-first, grow-later source). Ordinary sessions never
55
+ execute the `memory.grow` instruction: the arena covers MLS state,
56
+ KeyPackage churn and envelope buffers; only a multi-megabyte payload (a large
57
+ history bundle, a media blob) grows past it, and then talc extends the heap
58
+ the usual way.
59
+
60
+ Why it matters: Safari/JavaScriptCore on macOS 26 / iOS 26 crashes the whole
61
+ WebContent process ("This webpage was reloaded because an error occurred")
62
+ when a wasm `memory.grow` inside a Worker triggers a GC while the Web
63
+ Inspector is attached to that worker (`JSC::ShadowChicken::update` walks a
64
+ null call frame). With the default 1 MiB initial memory every sign-in grew
65
+ the heap dozens of times. The reservation is virtual: engines commit wasm
66
+ pages lazily, so resident memory is unchanged for an idle client.
67
+
68
+ `initial pages` in the `.wasm` memory section is therefore ~1044 (65 MiB);
69
+ do not "fix" it downwards.
70
+
71
+ The arena alone is not enough: the Argon2id recovery backup allocates 64 MiB
72
+ of blocks in one go and a large history bundle can exceed it too. So every
73
+ realm that instantiates the module (`worker.ts`, `notification-preview.ts`)
74
+ immediately grows the memory **from JavaScript** via
75
+ `WebAssembly.Memory.prototype.grow` (`wasm-memory.ts`, 192 MiB with smaller
76
+ fallbacks). A JS-initiated grow has only JS frames on the stack and does not
77
+ trip the crash; the allocator notices the host-grown pages
78
+ (`memory.size` past its accounted-for end) and claims them before it would
79
+ ever execute the instruction itself. Measured: two back-to-back backups and a
80
+ 32 MiB seal/open with zero wasm-side grows.
81
+
82
+ ## Bundle size
83
+
84
+ Aim: ≤ 350 KiB gzipped for the WASM blob, ≤ 8 KiB gzipped for the TS surface. We achieve this
85
+ by:
86
+
87
+ - Building the WASM with `--release`, `wasm-opt -O3`, and stripping symbols.
88
+ - Lazy-initializing WASM only on first `init()` (so `MessagingClient.generateIdentity()` doesn't
89
+ pay the cost on cold pages).
90
+ - No CBOR or crypto libraries on the main thread.
91
+
92
+ ## React Native
93
+
94
+ On RN, native binaries are preferred — install `@ping-app/ping-openmls-sdk-react-native-macos` (autolinked). On RN-Web,
95
+ this package's WASM build is used as-is.