@quilibrium/quorum-shared 2.1.0-1
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.
- package/dist/index.d.mts +2414 -0
- package/dist/index.d.ts +2414 -0
- package/dist/index.js +2788 -0
- package/dist/index.mjs +2678 -0
- package/package.json +49 -0
- package/src/api/client.ts +86 -0
- package/src/api/endpoints.ts +87 -0
- package/src/api/errors.ts +179 -0
- package/src/api/index.ts +35 -0
- package/src/crypto/encryption-state.ts +249 -0
- package/src/crypto/index.ts +55 -0
- package/src/crypto/types.ts +307 -0
- package/src/crypto/wasm-provider.ts +298 -0
- package/src/hooks/index.ts +31 -0
- package/src/hooks/keys.ts +62 -0
- package/src/hooks/mutations/index.ts +15 -0
- package/src/hooks/mutations/useDeleteMessage.ts +67 -0
- package/src/hooks/mutations/useEditMessage.ts +87 -0
- package/src/hooks/mutations/useReaction.ts +163 -0
- package/src/hooks/mutations/useSendMessage.ts +131 -0
- package/src/hooks/useChannels.ts +49 -0
- package/src/hooks/useMessages.ts +77 -0
- package/src/hooks/useSpaces.ts +60 -0
- package/src/index.ts +32 -0
- package/src/signing/index.ts +10 -0
- package/src/signing/types.ts +83 -0
- package/src/signing/wasm-provider.ts +75 -0
- package/src/storage/adapter.ts +118 -0
- package/src/storage/index.ts +9 -0
- package/src/sync/index.ts +83 -0
- package/src/sync/service.test.ts +822 -0
- package/src/sync/service.ts +947 -0
- package/src/sync/types.ts +267 -0
- package/src/sync/utils.ts +588 -0
- package/src/transport/browser-websocket.ts +299 -0
- package/src/transport/index.ts +34 -0
- package/src/transport/rn-websocket.ts +321 -0
- package/src/transport/types.ts +56 -0
- package/src/transport/websocket.ts +212 -0
- package/src/types/bookmark.ts +29 -0
- package/src/types/conversation.ts +25 -0
- package/src/types/index.ts +57 -0
- package/src/types/message.ts +178 -0
- package/src/types/space.ts +75 -0
- package/src/types/user.ts +72 -0
- package/src/utils/encoding.ts +106 -0
- package/src/utils/formatting.ts +139 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/logger.ts +141 -0
- package/src/utils/mentions.ts +135 -0
- package/src/utils/validation.ts +84 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync Protocol Types
|
|
3
|
+
*
|
|
4
|
+
* Hash-based delta synchronization for efficient data transfer.
|
|
5
|
+
* Reduces bandwidth by only sending data the recipient is missing.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Message, SpaceMember } from '../types';
|
|
9
|
+
|
|
10
|
+
// ============ Message Sync ============
|
|
11
|
+
|
|
12
|
+
/** Compact message reference for sync comparison */
|
|
13
|
+
export interface MessageDigest {
|
|
14
|
+
/** Unique message identifier */
|
|
15
|
+
messageId: string;
|
|
16
|
+
/** Message creation timestamp */
|
|
17
|
+
createdDate: number;
|
|
18
|
+
/** SHA-256 hash of canonical message content */
|
|
19
|
+
contentHash: string;
|
|
20
|
+
/** Last modification timestamp (for detecting edits) */
|
|
21
|
+
modifiedDate?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Compact reaction reference for sync comparison */
|
|
25
|
+
export interface ReactionDigest {
|
|
26
|
+
/** Message this reaction is on */
|
|
27
|
+
messageId: string;
|
|
28
|
+
/** Emoji/reaction identifier */
|
|
29
|
+
emojiId: string;
|
|
30
|
+
/** Number of users who reacted */
|
|
31
|
+
count: number;
|
|
32
|
+
/** Hash of sorted member IDs who reacted */
|
|
33
|
+
membersHash: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Manifest of all messages in a channel */
|
|
37
|
+
export interface SyncManifest {
|
|
38
|
+
spaceId: string;
|
|
39
|
+
channelId: string;
|
|
40
|
+
messageCount: number;
|
|
41
|
+
oldestTimestamp: number;
|
|
42
|
+
newestTimestamp: number;
|
|
43
|
+
/** Message digests sorted by createdDate ascending */
|
|
44
|
+
digests: MessageDigest[];
|
|
45
|
+
/** Reaction digests for quick comparison */
|
|
46
|
+
reactionDigests: ReactionDigest[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Delta response containing only needed messages */
|
|
50
|
+
export interface MessageDelta {
|
|
51
|
+
spaceId: string;
|
|
52
|
+
channelId: string;
|
|
53
|
+
/** Messages the recipient is missing */
|
|
54
|
+
newMessages: Message[];
|
|
55
|
+
/** Messages that have been edited since recipient's version */
|
|
56
|
+
updatedMessages: Message[];
|
|
57
|
+
/** Message IDs that have been deleted (tombstones) */
|
|
58
|
+
deletedMessageIds: string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Delta response for reactions only */
|
|
62
|
+
export interface ReactionDelta {
|
|
63
|
+
spaceId: string;
|
|
64
|
+
channelId: string;
|
|
65
|
+
/** Reactions to add: { messageId, emojiId, memberIds[] } */
|
|
66
|
+
added: Array<{
|
|
67
|
+
messageId: string;
|
|
68
|
+
emojiId: string;
|
|
69
|
+
memberIds: string[];
|
|
70
|
+
}>;
|
|
71
|
+
/** Reactions to remove: { messageId, emojiId, memberIds[] } */
|
|
72
|
+
removed: Array<{
|
|
73
|
+
messageId: string;
|
|
74
|
+
emojiId: string;
|
|
75
|
+
memberIds: string[];
|
|
76
|
+
}>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ============ Member Sync ============
|
|
80
|
+
|
|
81
|
+
/** Compact member reference */
|
|
82
|
+
export interface MemberDigest {
|
|
83
|
+
/** User's address */
|
|
84
|
+
address: string;
|
|
85
|
+
/** User's inbox address */
|
|
86
|
+
inboxAddress: string;
|
|
87
|
+
/** SHA-256 hash of display_name (or empty string) */
|
|
88
|
+
displayNameHash: string;
|
|
89
|
+
/** SHA-256 hash of icon URL/data (or empty string) */
|
|
90
|
+
iconHash: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Member delta containing only changes */
|
|
94
|
+
export interface MemberDelta {
|
|
95
|
+
spaceId: string;
|
|
96
|
+
/** New or updated members (full data) */
|
|
97
|
+
members: SpaceMember[];
|
|
98
|
+
/** Addresses of removed/kicked members */
|
|
99
|
+
removedAddresses: string[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ============ Peer Map Sync ============
|
|
103
|
+
|
|
104
|
+
/** Peer map entry for Triple Ratchet */
|
|
105
|
+
export interface PeerEntry {
|
|
106
|
+
/** Peer's ID in the ratchet */
|
|
107
|
+
peerId: number;
|
|
108
|
+
/** Peer's public key (hex or base64) */
|
|
109
|
+
publicKey: string;
|
|
110
|
+
/** Peer's identity public key (hex or base64) - optional for minimal sync */
|
|
111
|
+
identityPublicKey?: string;
|
|
112
|
+
/** Peer's signed pre-key (hex or base64) - optional for minimal sync */
|
|
113
|
+
signedPrePublicKey?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Peer map delta */
|
|
117
|
+
export interface PeerMapDelta {
|
|
118
|
+
spaceId: string;
|
|
119
|
+
/** New peer entries */
|
|
120
|
+
added: PeerEntry[];
|
|
121
|
+
/** Updated peer entries (changed keys) */
|
|
122
|
+
updated: PeerEntry[];
|
|
123
|
+
/** Removed peer IDs */
|
|
124
|
+
removed: number[];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ============ Deleted Message Tracking ============
|
|
128
|
+
|
|
129
|
+
/** Tombstone for a deleted message */
|
|
130
|
+
export interface DeletedMessageTombstone {
|
|
131
|
+
messageId: string;
|
|
132
|
+
spaceId: string;
|
|
133
|
+
channelId: string;
|
|
134
|
+
deletedAt: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ============ Control Message Payloads ============
|
|
138
|
+
|
|
139
|
+
/** Summary of sync data for comparison */
|
|
140
|
+
export interface SyncSummary {
|
|
141
|
+
memberCount: number;
|
|
142
|
+
messageCount: number;
|
|
143
|
+
newestMessageTimestamp: number;
|
|
144
|
+
oldestMessageTimestamp: number;
|
|
145
|
+
/** Hash of all message IDs for quick comparison */
|
|
146
|
+
manifestHash?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** sync-request payload (broadcast via hub) */
|
|
150
|
+
export interface SyncRequestPayload {
|
|
151
|
+
type: 'sync-request';
|
|
152
|
+
/** Our inbox address for responses */
|
|
153
|
+
inboxAddress: string;
|
|
154
|
+
/** Request expiry timestamp */
|
|
155
|
+
expiry: number;
|
|
156
|
+
/** Summary of our data */
|
|
157
|
+
summary: SyncSummary;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** sync-info payload (direct to requester) */
|
|
161
|
+
export interface SyncInfoPayload {
|
|
162
|
+
type: 'sync-info';
|
|
163
|
+
/** Our inbox address */
|
|
164
|
+
inboxAddress: string;
|
|
165
|
+
/** Summary of our data */
|
|
166
|
+
summary: SyncSummary;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** sync-initiate payload (direct to best peer) */
|
|
170
|
+
export interface SyncInitiatePayload {
|
|
171
|
+
type: 'sync-initiate';
|
|
172
|
+
/** Our inbox address (for peer to send data back to) */
|
|
173
|
+
inboxAddress: string;
|
|
174
|
+
/** Our manifest for comparison */
|
|
175
|
+
manifest?: SyncManifest;
|
|
176
|
+
/** Our member digests for comparison */
|
|
177
|
+
memberDigests?: MemberDigest[];
|
|
178
|
+
/** Our peer IDs for comparison */
|
|
179
|
+
peerIds?: number[];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** sync-manifest payload (response to sync-initiate with our data summary) */
|
|
183
|
+
export interface SyncManifestPayload {
|
|
184
|
+
type: 'sync-manifest';
|
|
185
|
+
/** Our inbox address (for peer to send data back to) */
|
|
186
|
+
inboxAddress: string;
|
|
187
|
+
/** Our full manifest */
|
|
188
|
+
manifest: SyncManifest;
|
|
189
|
+
/** Our member digests */
|
|
190
|
+
memberDigests: MemberDigest[];
|
|
191
|
+
/** Our peer IDs */
|
|
192
|
+
peerIds: number[];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** sync-delta payload (actual data transfer) */
|
|
196
|
+
export interface SyncDeltaPayload {
|
|
197
|
+
type: 'sync-delta';
|
|
198
|
+
/** Message changes */
|
|
199
|
+
messageDelta?: MessageDelta;
|
|
200
|
+
/** Reaction changes (synced independently) */
|
|
201
|
+
reactionDelta?: ReactionDelta;
|
|
202
|
+
/** Member changes */
|
|
203
|
+
memberDelta?: MemberDelta;
|
|
204
|
+
/** Peer map changes */
|
|
205
|
+
peerMapDelta?: PeerMapDelta;
|
|
206
|
+
/** Whether this is the final delta chunk */
|
|
207
|
+
isFinal?: boolean;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ============ Sync State ============
|
|
211
|
+
|
|
212
|
+
/** Candidate from sync-info response */
|
|
213
|
+
export interface SyncCandidate {
|
|
214
|
+
inboxAddress: string;
|
|
215
|
+
summary: SyncSummary;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Active sync session state */
|
|
219
|
+
export interface SyncSession {
|
|
220
|
+
spaceId: string;
|
|
221
|
+
channelId: string;
|
|
222
|
+
/** Request expiry timestamp */
|
|
223
|
+
expiry: number;
|
|
224
|
+
/** Candidates who responded to sync-request */
|
|
225
|
+
candidates: SyncCandidate[];
|
|
226
|
+
/** Timeout handle for initiating sync */
|
|
227
|
+
timeout?: ReturnType<typeof setTimeout>;
|
|
228
|
+
/** Whether sync is in progress */
|
|
229
|
+
inProgress: boolean;
|
|
230
|
+
/** Target inbox address when we've initiated sync */
|
|
231
|
+
syncTarget?: string;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ============ Union Types ============
|
|
235
|
+
|
|
236
|
+
/** All sync control message payloads */
|
|
237
|
+
export type SyncControlPayload =
|
|
238
|
+
| SyncRequestPayload
|
|
239
|
+
| SyncInfoPayload
|
|
240
|
+
| SyncInitiatePayload
|
|
241
|
+
| SyncManifestPayload
|
|
242
|
+
| SyncDeltaPayload;
|
|
243
|
+
|
|
244
|
+
/** Type guard for sync-request */
|
|
245
|
+
export function isSyncRequest(payload: SyncControlPayload): payload is SyncRequestPayload {
|
|
246
|
+
return payload.type === 'sync-request';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Type guard for sync-info */
|
|
250
|
+
export function isSyncInfo(payload: SyncControlPayload): payload is SyncInfoPayload {
|
|
251
|
+
return payload.type === 'sync-info';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Type guard for sync-initiate */
|
|
255
|
+
export function isSyncInitiate(payload: SyncControlPayload): payload is SyncInitiatePayload {
|
|
256
|
+
return payload.type === 'sync-initiate';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Type guard for sync-manifest */
|
|
260
|
+
export function isSyncManifest(payload: SyncControlPayload): payload is SyncManifestPayload {
|
|
261
|
+
return payload.type === 'sync-manifest';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Type guard for sync-delta */
|
|
265
|
+
export function isSyncDelta(payload: SyncControlPayload): payload is SyncDeltaPayload {
|
|
266
|
+
return payload.type === 'sync-delta';
|
|
267
|
+
}
|