@xmtp/browser-sdk 5.3.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.
Files changed (53) hide show
  1. package/dist/index.d.ts +541 -671
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/workers/client.js +1 -1
  5. package/dist/workers/client.js.map +1 -1
  6. package/dist/workers/opfs.js +2 -0
  7. package/dist/workers/opfs.js.map +1 -0
  8. package/package.json +12 -16
  9. package/src/Client.ts +92 -219
  10. package/src/CodecRegistry.ts +27 -0
  11. package/src/Conversation.ts +275 -104
  12. package/src/Conversations.ts +188 -99
  13. package/src/DebugInformation.ts +10 -27
  14. package/src/DecodedMessage.ts +155 -58
  15. package/src/Dm.ts +25 -9
  16. package/src/Group.ts +30 -29
  17. package/src/Opfs.ts +63 -0
  18. package/src/Preferences.ts +68 -52
  19. package/src/WorkerClient.ts +5 -5
  20. package/src/WorkerConversation.ts +98 -45
  21. package/src/WorkerConversations.ts +35 -74
  22. package/src/WorkerDebugInformation.ts +1 -12
  23. package/src/WorkerPreferences.ts +6 -14
  24. package/src/index.ts +53 -24
  25. package/src/types/actions/client.ts +6 -17
  26. package/src/types/actions/conversation.ts +160 -31
  27. package/src/types/actions/conversations.ts +21 -24
  28. package/src/types/actions/debugInformation.ts +3 -11
  29. package/src/types/actions/dm.ts +1 -1
  30. package/src/types/actions/opfs.ts +66 -0
  31. package/src/types/actions/preferences.ts +6 -13
  32. package/src/types/actions/streams.ts +8 -8
  33. package/src/types/actions.ts +11 -9
  34. package/src/types/options.ts +47 -6
  35. package/src/{ClientWorkerClass.ts → utils/WorkerBridge.ts} +35 -45
  36. package/src/utils/contentTypes.ts +77 -0
  37. package/src/utils/conversions.ts +17 -590
  38. package/src/utils/createClient.ts +16 -11
  39. package/src/utils/errors.ts +13 -19
  40. package/src/utils/inboxId.ts +46 -0
  41. package/src/utils/inboxState.ts +23 -0
  42. package/src/utils/installations.ts +95 -0
  43. package/src/utils/metadata.ts +15 -0
  44. package/src/utils/signer.ts +4 -4
  45. package/src/utils/uuid.ts +8 -0
  46. package/src/workers/client.ts +176 -135
  47. package/src/workers/opfs.ts +127 -0
  48. package/dist/workers/utils.js +0 -2
  49. package/dist/workers/utils.js.map +0 -1
  50. package/src/Utils.ts +0 -143
  51. package/src/UtilsWorkerClass.ts +0 -121
  52. package/src/types/actions/utils.ts +0 -69
  53. package/src/workers/utils.ts +0 -155
@@ -1,359 +1,11 @@
1
- import {
2
- ContentTypeId,
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
- ListConversationsOptions,
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;
@@ -362,258 +14,33 @@ export type SafeConversation = {
362
14
  appData: string;
363
15
  permissions: {
364
16
  policyType: GroupPermissionsOptions;
365
- policySet: {
366
- addAdminPolicy: PermissionPolicy;
367
- addMemberPolicy: PermissionPolicy;
368
- removeAdminPolicy: PermissionPolicy;
369
- removeMemberPolicy: PermissionPolicy;
370
- updateGroupDescriptionPolicy: PermissionPolicy;
371
- updateGroupImageUrlSquarePolicy: PermissionPolicy;
372
- updateGroupNamePolicy: PermissionPolicy;
373
- updateMessageDisappearingPolicy: PermissionPolicy;
374
- };
17
+ policySet: PermissionPolicySet;
375
18
  };
376
19
  addedByInboxId: string;
377
- metadata: {
378
- creatorInboxId: string;
379
- conversationType: string;
380
- };
20
+ metadata: GroupMetadata;
381
21
  admins: string[];
382
22
  superAdmins: string[];
383
23
  createdAtNs: bigint;
384
- isCommitLogForked?: boolean;
385
24
  };
386
25
 
387
26
  export const toSafeConversation = async (
388
27
  conversation: WorkerConversation,
389
28
  ): Promise<SafeConversation> => {
390
- const id = conversation.id;
391
- const name = conversation.name;
392
- const imageUrl = conversation.imageUrl;
393
- const description = conversation.description;
394
- const appData = conversation.appData;
395
- const permissions = conversation.permissions;
396
- const addedByInboxId = conversation.addedByInboxId;
397
- const metadata = await conversation.metadata();
398
- const admins = conversation.admins;
399
- const superAdmins = conversation.superAdmins;
400
- const createdAtNs = conversation.createdAtNs;
401
- const policyType = permissions.policyType;
402
- const policySet = permissions.policySet;
403
- const isCommitLogForked = conversation.isCommitLogForked;
404
29
  return {
405
- id,
406
- name,
407
- imageUrl,
408
- description,
409
- appData,
410
- permissions: {
411
- policyType,
412
- policySet: {
413
- addAdminPolicy: policySet.addAdminPolicy,
414
- addMemberPolicy: policySet.addMemberPolicy,
415
- removeAdminPolicy: policySet.removeAdminPolicy,
416
- removeMemberPolicy: policySet.removeMemberPolicy,
417
- updateGroupDescriptionPolicy: policySet.updateGroupDescriptionPolicy,
418
- updateGroupImageUrlSquarePolicy:
419
- policySet.updateGroupImageUrlSquarePolicy,
420
- updateGroupNamePolicy: policySet.updateGroupNamePolicy,
421
- updateMessageDisappearingPolicy:
422
- policySet.updateMessageDisappearingPolicy,
423
- },
424
- },
425
- addedByInboxId,
426
- metadata,
427
- admins,
428
- superAdmins,
429
- createdAtNs,
430
- 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,
431
41
  };
432
42
  };
433
43
 
434
- export type SafeInstallation = {
435
- bytes: Uint8Array;
436
- clientTimestampNs?: bigint;
437
- id: string;
438
- };
439
-
440
- export const toSafeInstallation = (
441
- installation: Installation,
442
- ): SafeInstallation => ({
443
- bytes: installation.bytes,
444
- clientTimestampNs: installation.clientTimestampNs,
445
- id: installation.id,
446
- });
447
-
448
- export type SafeInboxState = {
449
- identifiers: Identifier[];
450
- inboxId: string;
451
- installations: SafeInstallation[];
452
- recoveryIdentifier: Identifier;
453
- };
454
-
455
- export const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({
456
- identifiers: inboxState.accountIdentifiers,
457
- inboxId: inboxState.inboxId,
458
- installations: inboxState.installations.map(toSafeInstallation),
459
- recoveryIdentifier: inboxState.recoveryIdentifier,
460
- });
461
-
462
- export type SafeConsent = {
463
- entity: string;
464
- entityType: ConsentEntityType;
465
- state: ConsentState;
466
- };
467
-
468
- export const toSafeConsent = (consent: Consent): SafeConsent => ({
469
- entity: consent.entity,
470
- entityType: consent.entityType,
471
- state: consent.state,
472
- });
473
-
474
- export const fromSafeConsent = (consent: SafeConsent): Consent =>
475
- new Consent(consent.entityType, consent.state, consent.entity);
476
-
477
- export type SafeGroupMember = {
478
- accountIdentifiers: Identifier[];
479
- consentState: ConsentState;
480
- inboxId: string;
481
- installationIds: string[];
482
- permissionLevel: PermissionLevel;
483
- };
484
-
485
- export const toSafeGroupMember = (member: GroupMember): SafeGroupMember => ({
486
- accountIdentifiers: member.accountIdentifiers,
487
- consentState: member.consentState,
488
- inboxId: member.inboxId,
489
- installationIds: member.installationIds,
490
- permissionLevel: member.permissionLevel,
491
- });
492
-
493
- export const fromSafeGroupMember = (member: SafeGroupMember): GroupMember =>
494
- new GroupMember(
495
- member.inboxId,
496
- member.accountIdentifiers,
497
- member.installationIds,
498
- member.permissionLevel,
499
- member.consentState,
500
- );
501
-
502
- export type SafeHmacKey = {
503
- key: Uint8Array;
504
- epoch: bigint;
505
- };
506
-
507
- export const toSafeHmacKey = (hmacKey: HmacKey): SafeHmacKey => ({
508
- key: hmacKey.key,
509
- epoch: hmacKey.epoch,
510
- });
511
-
512
44
  export type HmacKeys = Map<string, HmacKey[]>;
513
- export type SafeHmacKeys = Record<string, SafeHmacKey[]>;
514
-
515
- export type SafeMessageDisappearingSettings = {
516
- fromNs: bigint;
517
- inNs: bigint;
518
- };
519
-
520
- export const toSafeMessageDisappearingSettings = (
521
- settings: MessageDisappearingSettings,
522
- ): SafeMessageDisappearingSettings => ({
523
- fromNs: settings.fromNs,
524
- inNs: settings.inNs,
525
- });
526
-
527
- export const fromSafeMessageDisappearingSettings = (
528
- settings: SafeMessageDisappearingSettings,
529
- ): MessageDisappearingSettings =>
530
- new MessageDisappearingSettings(settings.fromNs, settings.inNs);
531
-
532
- export type SafeKeyPackageStatus = {
533
- lifetime?: {
534
- notBefore: bigint;
535
- notAfter: bigint;
536
- };
537
- validationError?: string;
538
- };
539
-
540
- export const toSafeKeyPackageStatus = (
541
- status: KeyPackageStatus,
542
- ): SafeKeyPackageStatus => ({
543
- lifetime: status.lifetime
544
- ? {
545
- notBefore: status.lifetime.not_before,
546
- notAfter: status.lifetime.not_after,
547
- }
548
- : undefined,
549
- validationError: status.validationError,
550
- });
551
-
552
- export type SafeXMTPCursor = {
553
- originatorID: number;
554
- sequenceID: bigint;
555
- };
556
-
557
- export type SafeConversationDebugInfo = {
558
- epoch: bigint;
559
- maybeForked: boolean;
560
- forkDetails: string;
561
- isCommitLogForked?: boolean;
562
- localCommitLog: string;
563
- remoteCommitLog: string;
564
- cursor: SafeXMTPCursor[];
565
- };
566
-
567
- export const toSafeConversationDebugInfo = (
568
- debugInfo: ConversationDebugInfo,
569
- ): SafeConversationDebugInfo => ({
570
- epoch: debugInfo.epoch,
571
- maybeForked: debugInfo.maybeForked,
572
- forkDetails: debugInfo.forkDetails,
573
- isCommitLogForked: debugInfo.isCommitLogForked,
574
- localCommitLog: debugInfo.localCommitLog,
575
- remoteCommitLog: debugInfo.remoteCommitLog,
576
- cursor: debugInfo.cursor.map((cursor) => ({
577
- originatorID: cursor.originator_id,
578
- sequenceID: cursor.sequence_id,
579
- })),
580
- });
581
-
582
- export type SafeApiStats = {
583
- fetchKeyPackage: bigint;
584
- queryGroupMessages: bigint;
585
- queryWelcomeMessages: bigint;
586
- sendGroupMessages: bigint;
587
- sendWelcomeMessages: bigint;
588
- subscribeMessages: bigint;
589
- subscribeWelcomes: bigint;
590
- uploadKeyPackage: bigint;
591
- };
592
-
593
- export const toSafeApiStats = (stats: ApiStats): SafeApiStats => ({
594
- uploadKeyPackage: stats.upload_key_package,
595
- fetchKeyPackage: stats.fetch_key_package,
596
- sendGroupMessages: stats.send_group_messages,
597
- sendWelcomeMessages: stats.send_welcome_messages,
598
- queryGroupMessages: stats.query_group_messages,
599
- queryWelcomeMessages: stats.query_welcome_messages,
600
- subscribeMessages: stats.subscribe_messages,
601
- subscribeWelcomes: stats.subscribe_welcomes,
602
- });
603
-
604
- export type SafeIdentityStats = {
605
- getIdentityUpdatesV2: bigint;
606
- getInboxIds: bigint;
607
- publishIdentityUpdate: bigint;
608
- verifySmartContractWalletSignature: bigint;
609
- };
610
45
 
611
- export const toSafeIdentityStats = (
612
- stats: IdentityStats,
613
- ): SafeIdentityStats => ({
614
- getIdentityUpdatesV2: stats.get_identity_updates_v2,
615
- getInboxIds: stats.get_inbox_ids,
616
- publishIdentityUpdate: stats.publish_identity_update,
617
- verifySmartContractWalletSignature:
618
- stats.verify_smart_contract_wallet_signature,
619
- });
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
- ? "disabled"
38
- : "enabled";
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
- ? new LogOptions(
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
  };