@xmtp/browser-sdk 5.2.0 → 6.0.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.
- package/dist/index.d.ts +587 -670
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/dist/workers/opfs.js +2 -0
- package/dist/workers/opfs.js.map +1 -0
- package/package.json +12 -16
- package/src/Client.ts +92 -219
- package/src/CodecRegistry.ts +27 -0
- package/src/Conversation.ts +275 -104
- package/src/Conversations.ts +188 -99
- package/src/DebugInformation.ts +10 -27
- package/src/DecodedMessage.ts +155 -58
- package/src/Dm.ts +25 -9
- package/src/Group.ts +69 -26
- package/src/Opfs.ts +63 -0
- package/src/Preferences.ts +68 -52
- package/src/WorkerClient.ts +5 -5
- package/src/WorkerConversation.ts +119 -44
- package/src/WorkerConversations.ts +35 -74
- package/src/WorkerDebugInformation.ts +1 -12
- package/src/WorkerPreferences.ts +6 -14
- package/src/index.ts +53 -24
- package/src/types/actions/client.ts +6 -17
- package/src/types/actions/conversation.ts +160 -31
- package/src/types/actions/conversations.ts +21 -24
- package/src/types/actions/debugInformation.ts +3 -11
- package/src/types/actions/dm.ts +1 -1
- package/src/types/actions/group.ts +25 -0
- package/src/types/actions/opfs.ts +66 -0
- package/src/types/actions/preferences.ts +6 -13
- package/src/types/actions/streams.ts +8 -8
- package/src/types/actions.ts +11 -9
- package/src/types/options.ts +47 -6
- package/src/{ClientWorkerClass.ts → utils/WorkerBridge.ts} +35 -45
- package/src/utils/contentTypes.ts +77 -0
- package/src/utils/conversions.ts +18 -588
- package/src/utils/createClient.ts +16 -11
- package/src/utils/errors.ts +13 -19
- package/src/utils/inboxId.ts +46 -0
- package/src/utils/inboxState.ts +23 -0
- package/src/utils/installations.ts +95 -0
- package/src/utils/metadata.ts +15 -0
- package/src/utils/signer.ts +4 -4
- package/src/utils/uuid.ts +8 -0
- package/src/workers/client.ts +191 -132
- package/src/workers/opfs.ts +127 -0
- package/dist/workers/utils.js +0 -2
- package/dist/workers/utils.js.map +0 -1
- package/src/Utils.ts +0 -143
- package/src/UtilsWorkerClass.ts +0 -121
- package/src/types/actions/utils.ts +0 -69
- package/src/workers/utils.ts +0 -155
package/src/utils/conversions.ts
CHANGED
|
@@ -1,616 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type EncodedContent,
|
|
4
|
-
} from "@xmtp/content-type-primitives";
|
|
5
|
-
import {
|
|
6
|
-
Consent,
|
|
7
|
-
CreateDMOptions,
|
|
8
|
-
CreateGroupOptions,
|
|
9
|
-
GroupMember,
|
|
1
|
+
import type {
|
|
2
|
+
GroupMetadata,
|
|
10
3
|
GroupPermissionsOptions,
|
|
11
|
-
|
|
12
|
-
ListMessagesOptions,
|
|
13
|
-
MessageDisappearingSettings,
|
|
4
|
+
HmacKey,
|
|
14
5
|
PermissionPolicySet,
|
|
15
|
-
SendMessageOpts,
|
|
16
|
-
ContentTypeId as WasmContentTypeId,
|
|
17
|
-
EncodedContent as WasmEncodedContent,
|
|
18
|
-
type ApiStats,
|
|
19
|
-
type ConsentEntityType,
|
|
20
|
-
type ConsentState,
|
|
21
|
-
type ContentType,
|
|
22
|
-
type ConversationDebugInfo,
|
|
23
|
-
type ConversationType,
|
|
24
|
-
type DeliveryStatus,
|
|
25
|
-
type GroupMessageKind,
|
|
26
|
-
type HmacKey,
|
|
27
|
-
type Identifier,
|
|
28
|
-
type IdentityStats,
|
|
29
|
-
type InboxState,
|
|
30
|
-
type Installation,
|
|
31
|
-
type KeyPackageStatus,
|
|
32
|
-
type ListConversationsOrderBy,
|
|
33
|
-
type Message,
|
|
34
|
-
type MessageSortBy,
|
|
35
|
-
type PermissionLevel,
|
|
36
|
-
type PermissionPolicy,
|
|
37
|
-
type SortDirection,
|
|
38
6
|
} from "@xmtp/wasm-bindings";
|
|
39
7
|
import type { WorkerConversation } from "@/WorkerConversation";
|
|
40
8
|
|
|
41
|
-
export const toContentTypeId = (
|
|
42
|
-
contentTypeId: WasmContentTypeId,
|
|
43
|
-
): ContentTypeId =>
|
|
44
|
-
new ContentTypeId({
|
|
45
|
-
authorityId: contentTypeId.authorityId,
|
|
46
|
-
typeId: contentTypeId.typeId,
|
|
47
|
-
versionMajor: contentTypeId.versionMajor,
|
|
48
|
-
versionMinor: contentTypeId.versionMinor,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export const fromContentTypeId = (
|
|
52
|
-
contentTypeId: ContentTypeId,
|
|
53
|
-
): WasmContentTypeId =>
|
|
54
|
-
new WasmContentTypeId(
|
|
55
|
-
contentTypeId.authorityId,
|
|
56
|
-
contentTypeId.typeId,
|
|
57
|
-
contentTypeId.versionMajor,
|
|
58
|
-
contentTypeId.versionMinor,
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
export type SafeContentTypeId = {
|
|
62
|
-
authorityId: string;
|
|
63
|
-
typeId: string;
|
|
64
|
-
versionMajor: number;
|
|
65
|
-
versionMinor: number;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const toSafeContentTypeId = (
|
|
69
|
-
contentTypeId: ContentTypeId,
|
|
70
|
-
): SafeContentTypeId => ({
|
|
71
|
-
authorityId: contentTypeId.authorityId,
|
|
72
|
-
typeId: contentTypeId.typeId,
|
|
73
|
-
versionMajor: contentTypeId.versionMajor,
|
|
74
|
-
versionMinor: contentTypeId.versionMinor,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
export const fromSafeContentTypeId = (
|
|
78
|
-
contentTypeId: SafeContentTypeId,
|
|
79
|
-
): ContentTypeId =>
|
|
80
|
-
new ContentTypeId({
|
|
81
|
-
authorityId: contentTypeId.authorityId,
|
|
82
|
-
typeId: contentTypeId.typeId,
|
|
83
|
-
versionMajor: contentTypeId.versionMajor,
|
|
84
|
-
versionMinor: contentTypeId.versionMinor,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
export const toEncodedContent = (
|
|
88
|
-
content: WasmEncodedContent,
|
|
89
|
-
): EncodedContent => ({
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
91
|
-
type: toContentTypeId(content.type!),
|
|
92
|
-
parameters: Object.fromEntries(content.parameters as Map<string, string>),
|
|
93
|
-
fallback: content.fallback,
|
|
94
|
-
compression: content.compression,
|
|
95
|
-
content: content.content,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
export const fromEncodedContent = (
|
|
99
|
-
content: EncodedContent,
|
|
100
|
-
): WasmEncodedContent =>
|
|
101
|
-
new WasmEncodedContent(
|
|
102
|
-
fromContentTypeId(content.type),
|
|
103
|
-
new Map(Object.entries(content.parameters)),
|
|
104
|
-
content.fallback,
|
|
105
|
-
content.compression,
|
|
106
|
-
content.content,
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
export type SafeEncodedContent = {
|
|
110
|
-
type: SafeContentTypeId;
|
|
111
|
-
parameters: Record<string, string>;
|
|
112
|
-
fallback?: string;
|
|
113
|
-
compression?: number;
|
|
114
|
-
content: Uint8Array;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export const toSafeEncodedContent = (
|
|
118
|
-
content: EncodedContent,
|
|
119
|
-
): SafeEncodedContent => ({
|
|
120
|
-
type: toSafeContentTypeId(content.type),
|
|
121
|
-
parameters: content.parameters,
|
|
122
|
-
fallback: content.fallback,
|
|
123
|
-
compression: content.compression,
|
|
124
|
-
content: content.content,
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
export const fromSafeEncodedContent = (
|
|
128
|
-
content: SafeEncodedContent,
|
|
129
|
-
): EncodedContent => ({
|
|
130
|
-
type: fromSafeContentTypeId(content.type),
|
|
131
|
-
parameters: content.parameters,
|
|
132
|
-
fallback: content.fallback,
|
|
133
|
-
compression: content.compression,
|
|
134
|
-
content: content.content,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
export type SafeMessage = {
|
|
138
|
-
content: SafeEncodedContent;
|
|
139
|
-
convoId: string;
|
|
140
|
-
deliveryStatus: DeliveryStatus;
|
|
141
|
-
id: string;
|
|
142
|
-
kind: GroupMessageKind;
|
|
143
|
-
senderInboxId: string;
|
|
144
|
-
sentAtNs: bigint;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const toSafeMessage = (message: Message): SafeMessage => ({
|
|
148
|
-
content: toSafeEncodedContent(toEncodedContent(message.content)),
|
|
149
|
-
convoId: message.convoId,
|
|
150
|
-
deliveryStatus: message.deliveryStatus,
|
|
151
|
-
id: message.id,
|
|
152
|
-
kind: message.kind,
|
|
153
|
-
senderInboxId: message.senderInboxId,
|
|
154
|
-
sentAtNs: message.sentAtNs,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
export type SafeListMessagesOptions = {
|
|
158
|
-
contentTypes?: ContentType[];
|
|
159
|
-
deliveryStatus?: DeliveryStatus;
|
|
160
|
-
direction?: SortDirection;
|
|
161
|
-
excludeContentTypes?: ContentType[];
|
|
162
|
-
excludeSenderInboxIds?: string[];
|
|
163
|
-
insertedAfterNs?: bigint;
|
|
164
|
-
insertedBeforeNs?: bigint;
|
|
165
|
-
kind?: GroupMessageKind;
|
|
166
|
-
limit?: bigint;
|
|
167
|
-
sentAfterNs?: bigint;
|
|
168
|
-
sentBeforeNs?: bigint;
|
|
169
|
-
sortBy?: MessageSortBy;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
export const toSafeListMessagesOptions = (
|
|
173
|
-
options: ListMessagesOptions,
|
|
174
|
-
): SafeListMessagesOptions => ({
|
|
175
|
-
contentTypes: options.contentTypes,
|
|
176
|
-
deliveryStatus: options.deliveryStatus,
|
|
177
|
-
direction: options.direction,
|
|
178
|
-
excludeContentTypes: options.excludeContentTypes,
|
|
179
|
-
excludeSenderInboxIds: options.excludeSenderInboxIds,
|
|
180
|
-
insertedAfterNs: options.insertedAfterNs,
|
|
181
|
-
insertedBeforeNs: options.insertedBeforeNs,
|
|
182
|
-
kind: options.kind,
|
|
183
|
-
limit: options.limit,
|
|
184
|
-
sentAfterNs: options.sentAfterNs,
|
|
185
|
-
sentBeforeNs: options.sentBeforeNs,
|
|
186
|
-
sortBy: options.sortBy,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
export const fromSafeListMessagesOptions = (
|
|
190
|
-
options: SafeListMessagesOptions,
|
|
191
|
-
): ListMessagesOptions =>
|
|
192
|
-
new ListMessagesOptions(
|
|
193
|
-
options.sentBeforeNs,
|
|
194
|
-
options.sentAfterNs,
|
|
195
|
-
options.limit,
|
|
196
|
-
options.deliveryStatus,
|
|
197
|
-
options.direction,
|
|
198
|
-
options.contentTypes,
|
|
199
|
-
options.excludeContentTypes,
|
|
200
|
-
options.kind,
|
|
201
|
-
options.excludeSenderInboxIds,
|
|
202
|
-
options.sortBy,
|
|
203
|
-
options.insertedAfterNs,
|
|
204
|
-
options.insertedBeforeNs,
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
export type SafeSendMessageOpts = {
|
|
208
|
-
shouldPush: boolean;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
export const toSafeSendMessageOpts = (
|
|
212
|
-
opts: SendMessageOpts,
|
|
213
|
-
): SafeSendMessageOpts => ({
|
|
214
|
-
shouldPush: opts.shouldPush,
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
export const fromSafeSendMessageOpts = (
|
|
218
|
-
opts: SafeSendMessageOpts,
|
|
219
|
-
): SendMessageOpts => {
|
|
220
|
-
return new SendMessageOpts(opts.shouldPush);
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
export type SafeListConversationsOptions = {
|
|
224
|
-
consentStates?: ConsentState[];
|
|
225
|
-
conversationType?: ConversationType;
|
|
226
|
-
createdAfterNs?: bigint;
|
|
227
|
-
createdBeforeNs?: bigint;
|
|
228
|
-
includeDuplicateDms?: boolean;
|
|
229
|
-
limit?: bigint;
|
|
230
|
-
orderBy?: ListConversationsOrderBy;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
export const toSafeListConversationsOptions = (
|
|
234
|
-
options: ListConversationsOptions,
|
|
235
|
-
): SafeListConversationsOptions => ({
|
|
236
|
-
consentStates: options.consentStates,
|
|
237
|
-
conversationType: options.conversationType,
|
|
238
|
-
createdAfterNs: options.createdAfterNs,
|
|
239
|
-
createdBeforeNs: options.createdBeforeNs,
|
|
240
|
-
includeDuplicateDms: options.includeDuplicateDms,
|
|
241
|
-
limit: options.limit,
|
|
242
|
-
orderBy: options.orderBy,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
export const fromSafeListConversationsOptions = (
|
|
246
|
-
options: SafeListConversationsOptions,
|
|
247
|
-
): ListConversationsOptions =>
|
|
248
|
-
new ListConversationsOptions(
|
|
249
|
-
options.consentStates,
|
|
250
|
-
options.conversationType,
|
|
251
|
-
options.createdAfterNs,
|
|
252
|
-
options.createdBeforeNs,
|
|
253
|
-
options.includeDuplicateDms ?? false,
|
|
254
|
-
options.limit,
|
|
255
|
-
options.orderBy,
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
export type SafePermissionPolicySet = {
|
|
259
|
-
addAdminPolicy: PermissionPolicy;
|
|
260
|
-
addMemberPolicy: PermissionPolicy;
|
|
261
|
-
removeAdminPolicy: PermissionPolicy;
|
|
262
|
-
removeMemberPolicy: PermissionPolicy;
|
|
263
|
-
updateGroupDescriptionPolicy: PermissionPolicy;
|
|
264
|
-
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
265
|
-
updateGroupNamePolicy: PermissionPolicy;
|
|
266
|
-
updateMessageDisappearingPolicy: PermissionPolicy;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
export const toSafePermissionPolicySet = (
|
|
270
|
-
policySet: PermissionPolicySet,
|
|
271
|
-
): SafePermissionPolicySet => ({
|
|
272
|
-
addAdminPolicy: policySet.addAdminPolicy,
|
|
273
|
-
addMemberPolicy: policySet.addMemberPolicy,
|
|
274
|
-
removeAdminPolicy: policySet.removeAdminPolicy,
|
|
275
|
-
removeMemberPolicy: policySet.removeMemberPolicy,
|
|
276
|
-
updateGroupDescriptionPolicy: policySet.updateGroupDescriptionPolicy,
|
|
277
|
-
updateGroupImageUrlSquarePolicy: policySet.updateGroupImageUrlSquarePolicy,
|
|
278
|
-
updateGroupNamePolicy: policySet.updateGroupNamePolicy,
|
|
279
|
-
updateMessageDisappearingPolicy: policySet.updateMessageDisappearingPolicy,
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
export const fromSafePermissionPolicySet = (
|
|
283
|
-
policySet: SafePermissionPolicySet,
|
|
284
|
-
): PermissionPolicySet =>
|
|
285
|
-
new PermissionPolicySet(
|
|
286
|
-
policySet.addMemberPolicy,
|
|
287
|
-
policySet.removeMemberPolicy,
|
|
288
|
-
policySet.addAdminPolicy,
|
|
289
|
-
policySet.removeAdminPolicy,
|
|
290
|
-
policySet.updateGroupNamePolicy,
|
|
291
|
-
policySet.updateGroupDescriptionPolicy,
|
|
292
|
-
policySet.updateGroupImageUrlSquarePolicy,
|
|
293
|
-
policySet.updateMessageDisappearingPolicy,
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
export type SafeCreateGroupOptions = {
|
|
297
|
-
customPermissionPolicySet?: SafePermissionPolicySet;
|
|
298
|
-
description?: string;
|
|
299
|
-
imageUrlSquare?: string;
|
|
300
|
-
messageDisappearingSettings?: SafeMessageDisappearingSettings;
|
|
301
|
-
name?: string;
|
|
302
|
-
permissions?: GroupPermissionsOptions;
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
export const toSafeCreateGroupOptions = (
|
|
306
|
-
options: CreateGroupOptions,
|
|
307
|
-
): SafeCreateGroupOptions => ({
|
|
308
|
-
customPermissionPolicySet: options.customPermissionPolicySet,
|
|
309
|
-
description: options.groupDescription,
|
|
310
|
-
imageUrlSquare: options.groupImageUrlSquare,
|
|
311
|
-
messageDisappearingSettings: options.messageDisappearingSettings
|
|
312
|
-
? toSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
313
|
-
: undefined,
|
|
314
|
-
name: options.groupName,
|
|
315
|
-
permissions: options.permissions,
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
export const fromSafeCreateGroupOptions = (
|
|
319
|
-
options: SafeCreateGroupOptions,
|
|
320
|
-
): CreateGroupOptions =>
|
|
321
|
-
new CreateGroupOptions(
|
|
322
|
-
options.permissions,
|
|
323
|
-
options.name,
|
|
324
|
-
options.imageUrlSquare,
|
|
325
|
-
options.description,
|
|
326
|
-
// only include custom policy set if permissions are set to CustomPolicy
|
|
327
|
-
options.customPermissionPolicySet &&
|
|
328
|
-
options.permissions === GroupPermissionsOptions.CustomPolicy
|
|
329
|
-
? fromSafePermissionPolicySet(options.customPermissionPolicySet)
|
|
330
|
-
: undefined,
|
|
331
|
-
options.messageDisappearingSettings
|
|
332
|
-
? fromSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
333
|
-
: undefined,
|
|
334
|
-
);
|
|
335
|
-
|
|
336
|
-
export type SafeCreateDmOptions = {
|
|
337
|
-
messageDisappearingSettings?: SafeMessageDisappearingSettings;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
export const toSafeCreateDmOptions = (
|
|
341
|
-
options: CreateDMOptions,
|
|
342
|
-
): SafeCreateDmOptions => ({
|
|
343
|
-
messageDisappearingSettings: options.messageDisappearingSettings
|
|
344
|
-
? toSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
345
|
-
: undefined,
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
export const fromSafeCreateDmOptions = (
|
|
349
|
-
options: SafeCreateDmOptions,
|
|
350
|
-
): CreateDMOptions =>
|
|
351
|
-
new CreateDMOptions(
|
|
352
|
-
options.messageDisappearingSettings
|
|
353
|
-
? fromSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
354
|
-
: undefined,
|
|
355
|
-
);
|
|
356
|
-
|
|
357
9
|
export type SafeConversation = {
|
|
358
10
|
id: string;
|
|
359
11
|
name: string;
|
|
360
12
|
imageUrl: string;
|
|
361
13
|
description: string;
|
|
14
|
+
appData: string;
|
|
362
15
|
permissions: {
|
|
363
16
|
policyType: GroupPermissionsOptions;
|
|
364
|
-
policySet:
|
|
365
|
-
addAdminPolicy: PermissionPolicy;
|
|
366
|
-
addMemberPolicy: PermissionPolicy;
|
|
367
|
-
removeAdminPolicy: PermissionPolicy;
|
|
368
|
-
removeMemberPolicy: PermissionPolicy;
|
|
369
|
-
updateGroupDescriptionPolicy: PermissionPolicy;
|
|
370
|
-
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
371
|
-
updateGroupNamePolicy: PermissionPolicy;
|
|
372
|
-
updateMessageDisappearingPolicy: PermissionPolicy;
|
|
373
|
-
};
|
|
17
|
+
policySet: PermissionPolicySet;
|
|
374
18
|
};
|
|
375
19
|
addedByInboxId: string;
|
|
376
|
-
metadata:
|
|
377
|
-
creatorInboxId: string;
|
|
378
|
-
conversationType: string;
|
|
379
|
-
};
|
|
20
|
+
metadata: GroupMetadata;
|
|
380
21
|
admins: string[];
|
|
381
22
|
superAdmins: string[];
|
|
382
23
|
createdAtNs: bigint;
|
|
383
|
-
isCommitLogForked?: boolean;
|
|
384
24
|
};
|
|
385
25
|
|
|
386
26
|
export const toSafeConversation = async (
|
|
387
27
|
conversation: WorkerConversation,
|
|
388
28
|
): Promise<SafeConversation> => {
|
|
389
|
-
const id = conversation.id;
|
|
390
|
-
const name = conversation.name;
|
|
391
|
-
const imageUrl = conversation.imageUrl;
|
|
392
|
-
const description = conversation.description;
|
|
393
|
-
const permissions = conversation.permissions;
|
|
394
|
-
const addedByInboxId = conversation.addedByInboxId;
|
|
395
|
-
const metadata = await conversation.metadata();
|
|
396
|
-
const admins = conversation.admins;
|
|
397
|
-
const superAdmins = conversation.superAdmins;
|
|
398
|
-
const createdAtNs = conversation.createdAtNs;
|
|
399
|
-
const policyType = permissions.policyType;
|
|
400
|
-
const policySet = permissions.policySet;
|
|
401
|
-
const isCommitLogForked = conversation.isCommitLogForked;
|
|
402
29
|
return {
|
|
403
|
-
id,
|
|
404
|
-
name,
|
|
405
|
-
imageUrl,
|
|
406
|
-
description,
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
updateGroupDescriptionPolicy: policySet.updateGroupDescriptionPolicy,
|
|
415
|
-
updateGroupImageUrlSquarePolicy:
|
|
416
|
-
policySet.updateGroupImageUrlSquarePolicy,
|
|
417
|
-
updateGroupNamePolicy: policySet.updateGroupNamePolicy,
|
|
418
|
-
updateMessageDisappearingPolicy:
|
|
419
|
-
policySet.updateMessageDisappearingPolicy,
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
addedByInboxId,
|
|
423
|
-
metadata,
|
|
424
|
-
admins,
|
|
425
|
-
superAdmins,
|
|
426
|
-
createdAtNs,
|
|
427
|
-
isCommitLogForked,
|
|
30
|
+
id: conversation.id,
|
|
31
|
+
name: conversation.name,
|
|
32
|
+
imageUrl: conversation.imageUrl,
|
|
33
|
+
description: conversation.description,
|
|
34
|
+
appData: conversation.appData,
|
|
35
|
+
permissions: conversation.permissions(),
|
|
36
|
+
addedByInboxId: conversation.addedByInboxId,
|
|
37
|
+
metadata: await conversation.metadata(),
|
|
38
|
+
admins: conversation.listAdmins(),
|
|
39
|
+
superAdmins: conversation.listSuperAdmins(),
|
|
40
|
+
createdAtNs: conversation.createdAtNs,
|
|
428
41
|
};
|
|
429
42
|
};
|
|
430
43
|
|
|
431
|
-
export type SafeInstallation = {
|
|
432
|
-
bytes: Uint8Array;
|
|
433
|
-
clientTimestampNs?: bigint;
|
|
434
|
-
id: string;
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
export const toSafeInstallation = (
|
|
438
|
-
installation: Installation,
|
|
439
|
-
): SafeInstallation => ({
|
|
440
|
-
bytes: installation.bytes,
|
|
441
|
-
clientTimestampNs: installation.clientTimestampNs,
|
|
442
|
-
id: installation.id,
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
export type SafeInboxState = {
|
|
446
|
-
identifiers: Identifier[];
|
|
447
|
-
inboxId: string;
|
|
448
|
-
installations: SafeInstallation[];
|
|
449
|
-
recoveryIdentifier: Identifier;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
export const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({
|
|
453
|
-
identifiers: inboxState.accountIdentifiers,
|
|
454
|
-
inboxId: inboxState.inboxId,
|
|
455
|
-
installations: inboxState.installations.map(toSafeInstallation),
|
|
456
|
-
recoveryIdentifier: inboxState.recoveryIdentifier,
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
export type SafeConsent = {
|
|
460
|
-
entity: string;
|
|
461
|
-
entityType: ConsentEntityType;
|
|
462
|
-
state: ConsentState;
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
export const toSafeConsent = (consent: Consent): SafeConsent => ({
|
|
466
|
-
entity: consent.entity,
|
|
467
|
-
entityType: consent.entityType,
|
|
468
|
-
state: consent.state,
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
export const fromSafeConsent = (consent: SafeConsent): Consent =>
|
|
472
|
-
new Consent(consent.entityType, consent.state, consent.entity);
|
|
473
|
-
|
|
474
|
-
export type SafeGroupMember = {
|
|
475
|
-
accountIdentifiers: Identifier[];
|
|
476
|
-
consentState: ConsentState;
|
|
477
|
-
inboxId: string;
|
|
478
|
-
installationIds: string[];
|
|
479
|
-
permissionLevel: PermissionLevel;
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
export const toSafeGroupMember = (member: GroupMember): SafeGroupMember => ({
|
|
483
|
-
accountIdentifiers: member.accountIdentifiers,
|
|
484
|
-
consentState: member.consentState,
|
|
485
|
-
inboxId: member.inboxId,
|
|
486
|
-
installationIds: member.installationIds,
|
|
487
|
-
permissionLevel: member.permissionLevel,
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
export const fromSafeGroupMember = (member: SafeGroupMember): GroupMember =>
|
|
491
|
-
new GroupMember(
|
|
492
|
-
member.inboxId,
|
|
493
|
-
member.accountIdentifiers,
|
|
494
|
-
member.installationIds,
|
|
495
|
-
member.permissionLevel,
|
|
496
|
-
member.consentState,
|
|
497
|
-
);
|
|
498
|
-
|
|
499
|
-
export type SafeHmacKey = {
|
|
500
|
-
key: Uint8Array;
|
|
501
|
-
epoch: bigint;
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
export const toSafeHmacKey = (hmacKey: HmacKey): SafeHmacKey => ({
|
|
505
|
-
key: hmacKey.key,
|
|
506
|
-
epoch: hmacKey.epoch,
|
|
507
|
-
});
|
|
508
|
-
|
|
509
44
|
export type HmacKeys = Map<string, HmacKey[]>;
|
|
510
|
-
export type SafeHmacKeys = Record<string, SafeHmacKey[]>;
|
|
511
|
-
|
|
512
|
-
export type SafeMessageDisappearingSettings = {
|
|
513
|
-
fromNs: bigint;
|
|
514
|
-
inNs: bigint;
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
export const toSafeMessageDisappearingSettings = (
|
|
518
|
-
settings: MessageDisappearingSettings,
|
|
519
|
-
): SafeMessageDisappearingSettings => ({
|
|
520
|
-
fromNs: settings.fromNs,
|
|
521
|
-
inNs: settings.inNs,
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
export const fromSafeMessageDisappearingSettings = (
|
|
525
|
-
settings: SafeMessageDisappearingSettings,
|
|
526
|
-
): MessageDisappearingSettings =>
|
|
527
|
-
new MessageDisappearingSettings(settings.fromNs, settings.inNs);
|
|
528
|
-
|
|
529
|
-
export type SafeKeyPackageStatus = {
|
|
530
|
-
lifetime?: {
|
|
531
|
-
notBefore: bigint;
|
|
532
|
-
notAfter: bigint;
|
|
533
|
-
};
|
|
534
|
-
validationError?: string;
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
export const toSafeKeyPackageStatus = (
|
|
538
|
-
status: KeyPackageStatus,
|
|
539
|
-
): SafeKeyPackageStatus => ({
|
|
540
|
-
lifetime: status.lifetime
|
|
541
|
-
? {
|
|
542
|
-
notBefore: status.lifetime.not_before,
|
|
543
|
-
notAfter: status.lifetime.not_after,
|
|
544
|
-
}
|
|
545
|
-
: undefined,
|
|
546
|
-
validationError: status.validationError,
|
|
547
|
-
});
|
|
548
|
-
|
|
549
|
-
export type SafeXMTPCursor = {
|
|
550
|
-
originatorID: number;
|
|
551
|
-
sequenceID: bigint;
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
export type SafeConversationDebugInfo = {
|
|
555
|
-
epoch: bigint;
|
|
556
|
-
maybeForked: boolean;
|
|
557
|
-
forkDetails: string;
|
|
558
|
-
isCommitLogForked?: boolean;
|
|
559
|
-
localCommitLog: string;
|
|
560
|
-
remoteCommitLog: string;
|
|
561
|
-
cursor: SafeXMTPCursor[];
|
|
562
|
-
};
|
|
563
|
-
|
|
564
|
-
export const toSafeConversationDebugInfo = (
|
|
565
|
-
debugInfo: ConversationDebugInfo,
|
|
566
|
-
): SafeConversationDebugInfo => ({
|
|
567
|
-
epoch: debugInfo.epoch,
|
|
568
|
-
maybeForked: debugInfo.maybeForked,
|
|
569
|
-
forkDetails: debugInfo.forkDetails,
|
|
570
|
-
isCommitLogForked: debugInfo.isCommitLogForked,
|
|
571
|
-
localCommitLog: debugInfo.localCommitLog,
|
|
572
|
-
remoteCommitLog: debugInfo.remoteCommitLog,
|
|
573
|
-
cursor: debugInfo.cursor.map((cursor) => ({
|
|
574
|
-
originatorID: cursor.originator_id,
|
|
575
|
-
sequenceID: cursor.sequence_id,
|
|
576
|
-
})),
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
export type SafeApiStats = {
|
|
580
|
-
fetchKeyPackage: bigint;
|
|
581
|
-
queryGroupMessages: bigint;
|
|
582
|
-
queryWelcomeMessages: bigint;
|
|
583
|
-
sendGroupMessages: bigint;
|
|
584
|
-
sendWelcomeMessages: bigint;
|
|
585
|
-
subscribeMessages: bigint;
|
|
586
|
-
subscribeWelcomes: bigint;
|
|
587
|
-
uploadKeyPackage: bigint;
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
export const toSafeApiStats = (stats: ApiStats): SafeApiStats => ({
|
|
591
|
-
uploadKeyPackage: stats.upload_key_package,
|
|
592
|
-
fetchKeyPackage: stats.fetch_key_package,
|
|
593
|
-
sendGroupMessages: stats.send_group_messages,
|
|
594
|
-
sendWelcomeMessages: stats.send_welcome_messages,
|
|
595
|
-
queryGroupMessages: stats.query_group_messages,
|
|
596
|
-
queryWelcomeMessages: stats.query_welcome_messages,
|
|
597
|
-
subscribeMessages: stats.subscribe_messages,
|
|
598
|
-
subscribeWelcomes: stats.subscribe_welcomes,
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
export type SafeIdentityStats = {
|
|
602
|
-
getIdentityUpdatesV2: bigint;
|
|
603
|
-
getInboxIds: bigint;
|
|
604
|
-
publishIdentityUpdate: bigint;
|
|
605
|
-
verifySmartContractWalletSignature: bigint;
|
|
606
|
-
};
|
|
607
45
|
|
|
608
|
-
export
|
|
609
|
-
stats: IdentityStats,
|
|
610
|
-
): SafeIdentityStats => ({
|
|
611
|
-
getIdentityUpdatesV2: stats.get_identity_updates_v2,
|
|
612
|
-
getInboxIds: stats.get_inbox_ids,
|
|
613
|
-
publishIdentityUpdate: stats.publish_identity_update,
|
|
614
|
-
verifySmartContractWalletSignature:
|
|
615
|
-
stats.verify_smart_contract_wallet_signature,
|
|
616
|
-
});
|
|
46
|
+
export type LastReadTimes = Map<string, bigint>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createClient as createWasmClient,
|
|
3
|
+
DeviceSyncWorkerMode,
|
|
3
4
|
generateInboxId,
|
|
4
5
|
getInboxIdForIdentifier,
|
|
5
|
-
LogOptions,
|
|
6
6
|
type Identifier,
|
|
7
|
+
type LogOptions,
|
|
7
8
|
} from "@xmtp/wasm-bindings";
|
|
8
9
|
import { ApiUrls, HistorySyncUrls } from "@/constants";
|
|
9
10
|
import type { ClientOptions } from "@/types/options";
|
|
@@ -15,8 +16,9 @@ export const createClient = async (
|
|
|
15
16
|
const env = options?.env || "dev";
|
|
16
17
|
const host = options?.apiUrl || ApiUrls[env];
|
|
17
18
|
const gatewayHost = options?.gatewayHost ?? null;
|
|
19
|
+
const isSecure = host.startsWith("https");
|
|
18
20
|
const inboxId =
|
|
19
|
-
(await getInboxIdForIdentifier(host, gatewayHost, identifier)) ||
|
|
21
|
+
(await getInboxIdForIdentifier(host, gatewayHost, isSecure, identifier)) ||
|
|
20
22
|
generateInboxId(identifier);
|
|
21
23
|
const dbPath =
|
|
22
24
|
options?.dbPath === undefined
|
|
@@ -34,8 +36,8 @@ export const createClient = async (
|
|
|
34
36
|
: options.historySyncUrl;
|
|
35
37
|
|
|
36
38
|
const deviceSyncWorkerMode = options?.disableDeviceSync
|
|
37
|
-
?
|
|
38
|
-
:
|
|
39
|
+
? DeviceSyncWorkerMode.Disabled
|
|
40
|
+
: DeviceSyncWorkerMode.Enabled;
|
|
39
41
|
|
|
40
42
|
return createWasmClient(
|
|
41
43
|
host,
|
|
@@ -46,15 +48,18 @@ export const createClient = async (
|
|
|
46
48
|
historySyncUrl,
|
|
47
49
|
deviceSyncWorkerMode,
|
|
48
50
|
isLogging
|
|
49
|
-
?
|
|
50
|
-
options.structuredLogging ?? false,
|
|
51
|
-
options.performanceLogging ?? false,
|
|
52
|
-
options.loggingLevel,
|
|
53
|
-
)
|
|
51
|
+
? ({
|
|
52
|
+
structuredLogging: options.structuredLogging ?? false,
|
|
53
|
+
performanceLogging: options.performanceLogging ?? false,
|
|
54
|
+
loggingLevel: options.loggingLevel,
|
|
55
|
+
} as LogOptions)
|
|
54
56
|
: undefined,
|
|
55
|
-
undefined,
|
|
56
|
-
options?.debugEventsEnabled,
|
|
57
|
+
undefined, // allowOffline
|
|
57
58
|
options?.appVersion,
|
|
58
59
|
options?.gatewayHost,
|
|
60
|
+
undefined, // nonce
|
|
61
|
+
undefined, // authCallback
|
|
62
|
+
undefined, // authHandle
|
|
63
|
+
undefined, // clientMode
|
|
59
64
|
);
|
|
60
65
|
};
|