@abraca/dabra 2.89.0 → 2.91.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 (71) hide show
  1. package/package.json +5 -11
  2. package/src/AbracadabraBaseProvider.ts +0 -963
  3. package/src/AbracadabraClient.ts +0 -1960
  4. package/src/AbracadabraProvider.ts +0 -915
  5. package/src/AbracadabraWS.ts +0 -695
  6. package/src/BackgroundSyncManager.ts +0 -856
  7. package/src/BackgroundSyncPersistence.ts +0 -140
  8. package/src/ChatClient.ts +0 -314
  9. package/src/CloseEvents.ts +0 -49
  10. package/src/ContentManager.ts +0 -246
  11. package/src/CoverReconcile.ts +0 -168
  12. package/src/CryptoIdentityKeystore.ts +0 -754
  13. package/src/DeviceRegistrationService.ts +0 -257
  14. package/src/DocConverters.ts +0 -1859
  15. package/src/DocKeyManager.ts +0 -163
  16. package/src/DocTypes.ts +0 -628
  17. package/src/DocUtils.ts +0 -251
  18. package/src/DocumentCache.ts +0 -210
  19. package/src/DocumentManager.ts +0 -410
  20. package/src/E2EAbracadabraProvider.ts +0 -426
  21. package/src/E2EOfflineStore.ts +0 -55
  22. package/src/EncryptedChatClient.ts +0 -173
  23. package/src/EncryptedY.ts +0 -145
  24. package/src/EventEmitter.ts +0 -59
  25. package/src/FileBlobStore.ts +0 -569
  26. package/src/IdentityDoc.ts +0 -711
  27. package/src/IncomingMessage.ts +0 -63
  28. package/src/MessageReceiver.ts +0 -151
  29. package/src/MessageSender.ts +0 -22
  30. package/src/MetaManager.ts +0 -194
  31. package/src/MnemonicKeyDerivation.ts +0 -171
  32. package/src/NodeConnect.ts +0 -63
  33. package/src/NodeIdentity.ts +0 -378
  34. package/src/NotificationsClient.ts +0 -207
  35. package/src/OfflineStore.ts +0 -294
  36. package/src/OutgoingMessage.ts +0 -25
  37. package/src/OutgoingMessages/AuthenticationMessage.ts +0 -23
  38. package/src/OutgoingMessages/AwarenessMessage.ts +0 -41
  39. package/src/OutgoingMessages/CloseMessage.ts +0 -17
  40. package/src/OutgoingMessages/QueryAwarenessMessage.ts +0 -17
  41. package/src/OutgoingMessages/StatelessMessage.ts +0 -18
  42. package/src/OutgoingMessages/SubdocMessage.ts +0 -35
  43. package/src/OutgoingMessages/SyncStepOneMessage.ts +0 -25
  44. package/src/OutgoingMessages/SyncStepTwoMessage.ts +0 -25
  45. package/src/OutgoingMessages/UpdateMessage.ts +0 -20
  46. package/src/QueryClient.ts +0 -209
  47. package/src/RpcClient.ts +0 -659
  48. package/src/SchemaTypes.ts +0 -179
  49. package/src/SearchIndex.ts +0 -250
  50. package/src/ServerRegistry.ts +0 -220
  51. package/src/ServerReset.ts +0 -222
  52. package/src/TokenManager.ts +0 -337
  53. package/src/TreeManager.ts +0 -894
  54. package/src/TreeTimestamps.ts +0 -101
  55. package/src/auth.ts +0 -62
  56. package/src/awarenessStatesToArray.ts +0 -10
  57. package/src/index.ts +0 -219
  58. package/src/messageRecord.ts +0 -121
  59. package/src/sync/BroadcastChannelSync.ts +0 -235
  60. package/src/types.ts +0 -790
  61. package/src/webrtc/AbracadabraWebRTC.ts +0 -683
  62. package/src/webrtc/DataChannelRouter.ts +0 -179
  63. package/src/webrtc/DevicePairingChannel.ts +0 -496
  64. package/src/webrtc/E2EEChannel.ts +0 -195
  65. package/src/webrtc/FileTransferChannel.ts +0 -367
  66. package/src/webrtc/ManualSignaling.ts +0 -204
  67. package/src/webrtc/PeerConnection.ts +0 -133
  68. package/src/webrtc/SignalingSocket.ts +0 -378
  69. package/src/webrtc/YjsDataChannel.ts +0 -203
  70. package/src/webrtc/index.ts +0 -26
  71. package/src/webrtc/types.ts +0 -177
@@ -1,203 +0,0 @@
1
- import * as Y from "yjs";
2
- import * as syncProtocol from "y-protocols/sync";
3
- import {
4
- encodeAwarenessUpdate,
5
- applyAwarenessUpdate,
6
- type Awareness,
7
- } from "y-protocols/awareness";
8
- import * as encoding from "lib0/encoding";
9
- import * as decoding from "lib0/decoding";
10
- import type { DataChannelRouter } from "./DataChannelRouter.ts";
11
- import { CHANNEL_NAMES, YJS_MSG } from "./types.ts";
12
-
13
- /**
14
- * Handles Y.js document sync and awareness over WebRTC data channels.
15
- *
16
- * Uses the same y-protocols/sync encoding as the WebSocket provider but
17
- * transported over RTCDataChannel instead. A unique origin is used to
18
- * prevent echo loops with the server-based provider.
19
- */
20
- export class YjsDataChannel {
21
- public isSynced = false;
22
- private docUpdateHandler: ((update: Uint8Array, origin: any) => void) | null = null;
23
- private awarenessUpdateHandler: ((changes: { added: number[]; updated: number[]; removed: number[] }, origin: any) => void) | null = null;
24
- private channelOpenHandler: ((data: { name: string; channel: RTCDataChannel }) => void) | null = null;
25
- private channelMessageHandler: ((data: { name: string; data: any }) => void) | null = null;
26
-
27
- /** Channel names used for sync and awareness (supports namespaced subdoc channels). */
28
- private readonly syncChannelName: string;
29
- private readonly awarenessChannelName: string;
30
-
31
- /**
32
- * @param document - The Y.Doc to sync
33
- * @param awareness - Optional Awareness instance
34
- * @param router - DataChannelRouter for the peer connection
35
- * @param channelPrefix - Optional prefix for subdocument channels (e.g. `"{childId}:"`)
36
- */
37
- constructor(
38
- private readonly document: Y.Doc,
39
- private readonly awareness: Awareness | null,
40
- private readonly router: DataChannelRouter,
41
- channelPrefix?: string,
42
- ) {
43
- const prefix = channelPrefix ?? "";
44
- this.syncChannelName = `${prefix}${CHANNEL_NAMES.YJS_SYNC}`;
45
- this.awarenessChannelName = `${prefix}${CHANNEL_NAMES.AWARENESS}`;
46
- }
47
-
48
- /** Start listening for Y.js updates and data channel messages. */
49
- attach(): void {
50
- // Listen for local doc updates and send to peer.
51
- this.docUpdateHandler = (update: Uint8Array, origin: any) => {
52
- // Don't echo updates we received from this data channel.
53
- if (origin === this) return;
54
-
55
- if (!this.router.isOpen(this.syncChannelName)) return;
56
-
57
- const encoder = encoding.createEncoder();
58
- encoding.writeVarUint(encoder, YJS_MSG.UPDATE);
59
- encoding.writeVarUint8Array(encoder, update);
60
- this.router.send(this.syncChannelName, encoding.toUint8Array(encoder));
61
- };
62
- this.document.on("update", this.docUpdateHandler);
63
-
64
- // Listen for local awareness updates and send to peer.
65
- if (this.awareness) {
66
- this.awarenessUpdateHandler = (
67
- { added, updated, removed }: { added: number[]; updated: number[]; removed: number[] },
68
- _origin: any,
69
- ) => {
70
- if (!this.router.isOpen(this.awarenessChannelName)) return;
71
-
72
- const changedClients = added.concat(updated).concat(removed);
73
- const update = encodeAwarenessUpdate(this.awareness!, changedClients);
74
- this.router.send(this.awarenessChannelName, update);
75
- };
76
- this.awareness.on("update", this.awarenessUpdateHandler);
77
- }
78
-
79
- // Handle incoming data channel messages.
80
- this.channelMessageHandler = ({ name, data }: { name: string; data: any }) => {
81
- if (name === this.syncChannelName) {
82
- this.handleSyncMessage(data);
83
- } else if (name === this.awarenessChannelName) {
84
- this.handleAwarenessMessage(data);
85
- }
86
- };
87
- this.router.on("channelMessage", this.channelMessageHandler);
88
-
89
- // When sync channel opens, initiate sync handshake.
90
- this.channelOpenHandler = ({ name }: { name: string; channel: RTCDataChannel }) => {
91
- if (name === this.syncChannelName) {
92
- this.sendSyncStep1();
93
- } else if (name === this.awarenessChannelName && this.awareness) {
94
- // Send full awareness state on channel open.
95
- if (this.router.isOpen(this.awarenessChannelName)) {
96
- const update = encodeAwarenessUpdate(
97
- this.awareness,
98
- Array.from(this.awareness.getStates().keys()),
99
- );
100
- this.router.send(this.awarenessChannelName, update);
101
- }
102
- }
103
- };
104
- this.router.on("channelOpen", this.channelOpenHandler);
105
-
106
- // If sync channel is already open, start sync immediately.
107
- if (this.router.isOpen(this.syncChannelName)) {
108
- this.sendSyncStep1();
109
- }
110
-
111
- // If awareness channel is already open, send state immediately.
112
- if (this.awareness && this.router.isOpen(this.awarenessChannelName)) {
113
- const update = encodeAwarenessUpdate(
114
- this.awareness,
115
- Array.from(this.awareness.getStates().keys()),
116
- );
117
- this.router.send(this.awarenessChannelName, update);
118
- }
119
- }
120
-
121
- /** Stop listening and clean up handlers. */
122
- detach(): void {
123
- if (this.docUpdateHandler) {
124
- this.document.off("update", this.docUpdateHandler);
125
- this.docUpdateHandler = null;
126
- }
127
-
128
- if (this.awarenessUpdateHandler && this.awareness) {
129
- this.awareness.off("update", this.awarenessUpdateHandler);
130
- this.awarenessUpdateHandler = null;
131
- }
132
-
133
- if (this.channelMessageHandler) {
134
- this.router.off("channelMessage", this.channelMessageHandler);
135
- this.channelMessageHandler = null;
136
- }
137
-
138
- if (this.channelOpenHandler) {
139
- this.router.off("channelOpen", this.channelOpenHandler);
140
- this.channelOpenHandler = null;
141
- }
142
-
143
- this.isSynced = false;
144
- }
145
-
146
- destroy(): void {
147
- this.detach();
148
- }
149
-
150
- private sendSyncStep1(): void {
151
- if (!this.router.isOpen(this.syncChannelName)) return;
152
-
153
- const encoder = encoding.createEncoder();
154
- encoding.writeVarUint(encoder, YJS_MSG.SYNC);
155
- syncProtocol.writeSyncStep1(encoder, this.document);
156
- this.router.send(this.syncChannelName, encoding.toUint8Array(encoder));
157
- }
158
-
159
- private handleSyncMessage(data: ArrayBuffer | Uint8Array): void {
160
- const buf = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
161
- const decoder = decoding.createDecoder(buf);
162
- const msgType = decoding.readVarUint(decoder);
163
-
164
- if (msgType === YJS_MSG.SYNC) {
165
- // Standard y-protocols/sync message (SyncStep1, SyncStep2, or Update).
166
- const encoder = encoding.createEncoder();
167
- const syncMessageType = syncProtocol.readSyncMessage(
168
- decoder,
169
- encoder,
170
- this.document,
171
- this,
172
- );
173
-
174
- // If the sync protocol generated a response (SyncStep2), send it.
175
- if (encoding.length(encoder) > 0) {
176
- const responseEncoder = encoding.createEncoder();
177
- encoding.writeVarUint(responseEncoder, YJS_MSG.SYNC);
178
- encoding.writeUint8Array(
179
- responseEncoder,
180
- encoding.toUint8Array(encoder),
181
- );
182
- if (this.router.isOpen(this.syncChannelName)) {
183
- this.router.send(this.syncChannelName, encoding.toUint8Array(responseEncoder));
184
- }
185
- }
186
-
187
- // SyncStep2 means initial sync is complete.
188
- if (syncMessageType === syncProtocol.messageYjsSyncStep2) {
189
- this.isSynced = true;
190
- }
191
- } else if (msgType === YJS_MSG.UPDATE) {
192
- // Raw incremental update.
193
- const update = decoding.readVarUint8Array(decoder);
194
- Y.applyUpdate(this.document, update, this);
195
- }
196
- }
197
-
198
- private handleAwarenessMessage(data: ArrayBuffer | Uint8Array): void {
199
- if (!this.awareness) return;
200
- const buf = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
201
- applyAwarenessUpdate(this.awareness, buf, this);
202
- }
203
- }
@@ -1,26 +0,0 @@
1
- export { AbracadabraWebRTC } from "./AbracadabraWebRTC.ts";
2
- export { SignalingSocket } from "./SignalingSocket.ts";
3
- export { PeerConnection } from "./PeerConnection.ts";
4
- export { DataChannelRouter, KEY_EXCHANGE_CHANNEL } from "./DataChannelRouter.ts";
5
- export { YjsDataChannel } from "./YjsDataChannel.ts";
6
- export { FileTransferChannel, FileTransferHandle } from "./FileTransferChannel.ts";
7
- export { E2EEChannel } from "./E2EEChannel.ts";
8
- export type { E2EEIdentity } from "./E2EEChannel.ts";
9
- export { ManualSignaling } from "./ManualSignaling.ts";
10
- export type { ManualSignalingBlob } from "./ManualSignaling.ts";
11
- export { DevicePairingChannel } from "./DevicePairingChannel.ts";
12
- export type { DevicePairingConfig, PairingRequest, PairingResult } from "./DevicePairingChannel.ts";
13
- export type {
14
- AbracadabraWebRTCConfiguration,
15
- PeerInfo,
16
- PeerState,
17
- FileTransferMeta,
18
- FileTransferStatus,
19
- SignalingIncoming,
20
- SignalingOutgoing,
21
- } from "./types.ts";
22
- export {
23
- CHANNEL_NAMES,
24
- DEFAULT_ICE_SERVERS,
25
- DEFAULT_FILE_CHUNK_SIZE,
26
- } from "./types.ts";
@@ -1,177 +0,0 @@
1
- // ── Signaling Wire Protocol ─────────────────────────────────────────────────
2
- // Mirrors the Rust server's Incoming/Outgoing enums in signaling.rs exactly.
3
- // All messages are JSON text frames with a "type" discriminator.
4
-
5
- export type SignalingIncoming =
6
- | { type: "join" }
7
- | { type: "leave" }
8
- | { type: "offer"; to: string; sdp: string }
9
- | { type: "answer"; to: string; sdp: string }
10
- | { type: "ice"; to: string; candidate: string }
11
- | { type: "mute"; muted: boolean }
12
- | { type: "media-state"; video: boolean; screen: boolean }
13
- | { type: "profile"; name: string; color: string }
14
- | { type: "pong" };
15
-
16
- export type SignalingOutgoing =
17
- | { type: "welcome"; peer_id: string; peers: PeerInfo[] }
18
- | {
19
- type: "joined";
20
- peer_id: string;
21
- user_id: string;
22
- muted: boolean;
23
- video: boolean;
24
- screen: boolean;
25
- name: string | null;
26
- color: string | null;
27
- }
28
- | { type: "left"; peer_id: string }
29
- | { type: "offer"; from: string; sdp: string }
30
- | { type: "answer"; from: string; sdp: string }
31
- | { type: "ice"; from: string; candidate: string }
32
- | { type: "mute"; peer_id: string; muted: boolean }
33
- | {
34
- type: "media-state";
35
- peer_id: string;
36
- video: boolean;
37
- screen: boolean;
38
- }
39
- | { type: "profile"; peer_id: string; name: string; color: string }
40
- | { type: "ping" }
41
- | { type: "error"; code: string; message: string };
42
-
43
- // ── Peer State ──────────────────────────────────────────────────────────────
44
-
45
- export interface PeerInfo {
46
- peer_id: string;
47
- user_id: string;
48
- muted: boolean;
49
- video: boolean;
50
- screen: boolean;
51
- name: string | null;
52
- color: string | null;
53
- }
54
-
55
- export interface PeerState extends PeerInfo {
56
- connectionState: RTCPeerConnectionState | "new";
57
- }
58
-
59
- // ── File Transfer ───────────────────────────────────────────────────────────
60
-
61
- export interface FileTransferMeta {
62
- transferId: string;
63
- filename: string;
64
- mimeType: string;
65
- totalSize: number;
66
- chunkSize: number;
67
- totalChunks: number;
68
- }
69
-
70
- export type FileTransferStatus =
71
- | "pending"
72
- | "sending"
73
- | "receiving"
74
- | "complete"
75
- | "cancelled"
76
- | "error";
77
-
78
- /** Data channel file transfer message type discriminators (first byte). */
79
- export const FILE_MSG = {
80
- START: 0x01,
81
- CHUNK: 0x02,
82
- COMPLETE: 0x03,
83
- CANCEL: 0x04,
84
- } as const;
85
-
86
- /** Data channel Y.js message type discriminators (first byte). */
87
- export const YJS_MSG = {
88
- SYNC: 0x00,
89
- UPDATE: 0x01,
90
- } as const;
91
-
92
- // ── Data Channel Names ──────────────────────────────────────────────────────
93
-
94
- export const CHANNEL_NAMES = {
95
- YJS_SYNC: "yjs-sync",
96
- AWARENESS: "awareness",
97
- FILE_TRANSFER: "file-transfer",
98
- CUSTOM: "custom",
99
- } as const;
100
-
101
- // ── E2EE ────────────────────────────────────────────────────────────────────
102
-
103
- export type { E2EEIdentity } from "./E2EEChannel.ts";
104
-
105
- // ── Configuration ───────────────────────────────────────────────────────────
106
-
107
- export interface AbracadabraWebRTCConfiguration {
108
- /** Document ID for the signaling room. */
109
- docId: string;
110
-
111
- /** Server base URL (http/https). Signaling URL derived automatically. */
112
- url: string;
113
-
114
- /**
115
- * Override the signaling WebSocket URL. When set, signaling connects to
116
- * this server instead of deriving from `url`. Useful for local spaces that
117
- * piggyback a remote server's signaling endpoint.
118
- */
119
- signalingUrl?: string;
120
-
121
- /** JWT token or async token factory. */
122
- token: string | (() => string) | (() => Promise<string>);
123
-
124
- /** Optional Y.Doc to sync over data channels (hybrid mode). */
125
- document?: InstanceType<typeof import("yjs").Doc> | null;
126
-
127
- /** Optional Awareness instance for presence sync over data channels. */
128
- awareness?: InstanceType<
129
- typeof import("y-protocols/awareness").Awareness
130
- > | null;
131
-
132
- /** ICE server configuration. Defaults to Google STUN. */
133
- iceServers?: RTCIceServer[];
134
-
135
- /** Display name for this peer. */
136
- displayName?: string;
137
-
138
- /** Color identifier for this peer. */
139
- color?: string;
140
-
141
- /** Enable Y.js document sync over data channels. Default: true when document is provided. */
142
- enableDocSync?: boolean;
143
-
144
- /** Enable awareness sync over data channels. Default: true when awareness is provided. */
145
- enableAwarenessSync?: boolean;
146
-
147
- /** Enable file transfer channel. Default: false. */
148
- enableFileTransfer?: boolean;
149
-
150
- /** Max file chunk size in bytes. Default: 16384 (16KB). */
151
- fileChunkSize?: number;
152
-
153
- /** Auto-connect on construction. Default: true. */
154
- autoConnect?: boolean;
155
-
156
- /**
157
- * E2EE identity for application-level encryption on data channels.
158
- * When provided, all data channel messages (except key-exchange) are
159
- * encrypted with AES-256-GCM using X25519 ECDH-derived session keys.
160
- */
161
- e2ee?: import("./E2EEChannel.ts").E2EEIdentity | (() => Promise<import("./E2EEChannel.ts").E2EEIdentity>);
162
-
163
- /** WebSocket polyfill for signaling (e.g. for Node.js). */
164
- WebSocketPolyfill?: any;
165
- }
166
-
167
- export const DEFAULT_ICE_SERVERS: RTCIceServer[] = [
168
- { urls: "stun:stun.l.google.com:19302" },
169
- ];
170
-
171
- export const DEFAULT_FILE_CHUNK_SIZE = 16384; // 16KB
172
-
173
- /** UUID v4 transfer ID length when encoded as raw bytes. */
174
- export const TRANSFER_ID_BYTES = 16;
175
-
176
- /** SHA-256 hash length in bytes. */
177
- export const SHA256_BYTES = 32;