@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,10 +1,11 @@
1
1
  import init, {
2
+ LogLevel,
2
3
  type Consent,
3
4
  type Conversation,
4
5
  type Message,
5
6
  type SignatureRequestHandle,
6
7
  type StreamCloser,
7
- type UserPreference,
8
+ type UserPreferenceUpdate,
8
9
  } from "@xmtp/wasm-bindings";
9
10
  import type {
10
11
  ActionErrorData,
@@ -18,21 +19,7 @@ import type {
18
19
  StreamActionErrorData,
19
20
  StreamActionName,
20
21
  } from "@/types/actions/streams";
21
- import {
22
- fromEncodedContent,
23
- fromSafeEncodedContent,
24
- fromSafeSendMessageOpts,
25
- toSafeApiStats,
26
- toSafeConsent,
27
- toSafeConversation,
28
- toSafeConversationDebugInfo,
29
- toSafeHmacKey,
30
- toSafeIdentityStats,
31
- toSafeInboxState,
32
- toSafeKeyPackageStatus,
33
- toSafeMessage,
34
- toSafeMessageDisappearingSettings,
35
- } from "@/utils/conversions";
22
+ import { toSafeConversation } from "@/utils/conversions";
36
23
  import {
37
24
  ClientNotInitializedError,
38
25
  GroupNotFoundError,
@@ -97,14 +84,16 @@ self.onmessage = async (
97
84
  maybeClient = await WorkerClient.create(data.identifier, data.options);
98
85
  enableLogging =
99
86
  data.options?.loggingLevel !== undefined &&
100
- data.options.loggingLevel !== "off";
87
+ data.options.loggingLevel !== LogLevel.Off;
101
88
  postMessage({
102
89
  id,
103
90
  action,
104
91
  result: {
92
+ appVersion: maybeClient.appVersion,
105
93
  inboxId: maybeClient.inboxId,
106
94
  installationId: maybeClient.installationId,
107
95
  installationIdBytes: maybeClient.installationIdBytes,
96
+ libxmtpVersion: maybeClient.libxmtpVersion,
108
97
  },
109
98
  });
110
99
  return;
@@ -309,8 +298,8 @@ self.onmessage = async (
309
298
  postMessage({ id, action, result });
310
299
  break;
311
300
  }
312
- case "client.findInboxIdByIdentifier": {
313
- const result = await client.findInboxIdByIdentifier(data.identifier);
301
+ case "client.getInboxIdByIdentifier": {
302
+ const result = await client.getInboxIdByIdentifier(data.identifier);
314
303
  postMessage({ id, action, result });
315
304
  break;
316
305
  }
@@ -336,46 +325,27 @@ self.onmessage = async (
336
325
  postMessage({ id, action, result });
337
326
  break;
338
327
  }
339
- case "client.getKeyPackageStatusesForInstallationIds": {
340
- const result = await client.getKeyPackageStatusesForInstallationIds(
328
+ case "client.fetchKeyPackageStatuses": {
329
+ const result = await client.fetchKeyPackageStatuses(
341
330
  data.installationIds,
342
331
  );
343
- const safeResult = new Map(
344
- Array.from(result.entries()).map(([installationId, status]) => [
345
- installationId,
346
- toSafeKeyPackageStatus(status),
347
- ]),
348
- );
349
332
  postMessage({
350
333
  id,
351
334
  action,
352
- result: safeResult,
335
+ result,
353
336
  });
354
337
  break;
355
338
  }
356
- case "client.libxmtpVersion": {
357
- const result = client.libxmtpVersion;
358
- postMessage({ id, action, result });
359
- break;
360
- }
361
- case "client.appVersion": {
362
- const result = client.appVersion;
363
- postMessage({ id, action, result });
364
- break;
365
- }
366
339
  /**
367
340
  * Debug information actions
368
341
  */
369
342
  case "debugInformation.apiStatistics": {
370
- const apiStats = client.debugInformation.apiStatistics();
371
- const result = toSafeApiStats(apiStats);
343
+ const result = client.debugInformation.apiStatistics();
372
344
  postMessage({ id, action, result });
373
345
  break;
374
346
  }
375
347
  case "debugInformation.apiIdentityStatistics": {
376
- const apiIdentityStats =
377
- client.debugInformation.apiIdentityStatistics();
378
- const result = toSafeIdentityStats(apiIdentityStats);
348
+ const result = client.debugInformation.apiIdentityStatistics();
379
349
  postMessage({ id, action, result });
380
350
  break;
381
351
  }
@@ -389,38 +359,21 @@ self.onmessage = async (
389
359
  postMessage({ id, action, result: undefined });
390
360
  break;
391
361
  }
392
- case "debugInformation.uploadDebugArchive": {
393
- const result = await client.debugInformation.uploadDebugArchive(
394
- data.serverUrl,
395
- );
396
- postMessage({ id, action, result });
397
- break;
398
- }
399
362
  /**
400
363
  * Preferences actions
401
364
  */
402
365
  case "preferences.inboxState": {
403
- const inboxState = await client.preferences.inboxState(
366
+ const result = await client.preferences.inboxState(
404
367
  data.refreshFromNetwork,
405
368
  );
406
- const result = toSafeInboxState(inboxState);
407
369
  postMessage({ id, action, result });
408
370
  break;
409
371
  }
410
- case "preferences.inboxStateFromInboxIds": {
411
- const inboxStates = await client.preferences.inboxStateFromInboxIds(
372
+ case "preferences.getInboxStates": {
373
+ const result = await client.preferences.getInboxStates(
412
374
  data.inboxIds,
413
375
  data.refreshFromNetwork,
414
376
  );
415
- const result = inboxStates.map(toSafeInboxState);
416
- postMessage({ id, action, result });
417
- break;
418
- }
419
- case "preferences.getLatestInboxState": {
420
- const inboxState = await client.preferences.getLatestInboxState(
421
- data.inboxId,
422
- );
423
- const result = toSafeInboxState(inboxState);
424
377
  postMessage({ id, action, result });
425
378
  break;
426
379
  }
@@ -457,7 +410,7 @@ self.onmessage = async (
457
410
  postStreamMessage({
458
411
  action: "stream.consent",
459
412
  streamId: data.streamId,
460
- result: value?.map(toSafeConsent) ?? [],
413
+ result: value ?? [],
461
414
  });
462
415
  }
463
416
  };
@@ -483,7 +436,7 @@ self.onmessage = async (
483
436
  case "preferences.streamPreferences": {
484
437
  const streamCallback = (
485
438
  error: Error | null,
486
- value: UserPreference[] | undefined,
439
+ value: UserPreferenceUpdate[] | undefined,
487
440
  ) => {
488
441
  if (error) {
489
442
  postStreamMessageError({
@@ -585,12 +538,19 @@ self.onmessage = async (
585
538
  streamId: data.streamId,
586
539
  error,
587
540
  });
588
- } else {
589
- postStreamMessage({
590
- action: "stream.message",
591
- streamId: data.streamId,
592
- result: value ? toSafeMessage(value) : undefined,
593
- });
541
+ } else if (value) {
542
+ void client.conversations
543
+ .getMessageById(value.id)
544
+ .then((enrichedMessage) => {
545
+ // guard against any edge cases where the message is not found
546
+ if (enrichedMessage) {
547
+ postStreamMessage({
548
+ action: "stream.message",
549
+ streamId: data.streamId,
550
+ result: enrichedMessage,
551
+ });
552
+ }
553
+ });
594
554
  }
595
555
  };
596
556
  const streamCloser = client.conversations.streamAllMessages(
@@ -660,25 +620,26 @@ self.onmessage = async (
660
620
  postMessage({ id, action, result });
661
621
  break;
662
622
  }
663
- case "conversations.newGroupOptimistic": {
664
- const conversation = client.conversations.newGroupOptimistic(
623
+ case "conversations.createGroupOptimistic": {
624
+ const conversation = client.conversations.createGroupOptimistic(
665
625
  data.options,
666
626
  );
667
627
  const result = await toSafeConversation(conversation);
668
628
  postMessage({ id, action, result });
669
629
  break;
670
630
  }
671
- case "conversations.newGroupWithIdentifiers": {
672
- const conversation = await client.conversations.newGroupWithIdentifiers(
673
- data.identifiers,
674
- data.options,
675
- );
631
+ case "conversations.createGroupWithIdentifiers": {
632
+ const conversation =
633
+ await client.conversations.createGroupWithIdentifiers(
634
+ data.identifiers,
635
+ data.options,
636
+ );
676
637
  const result = await toSafeConversation(conversation);
677
638
  postMessage({ id, action, result });
678
639
  break;
679
640
  }
680
- case "conversations.newGroup": {
681
- const conversation = await client.conversations.newGroup(
641
+ case "conversations.createGroup": {
642
+ const conversation = await client.conversations.createGroup(
682
643
  data.inboxIds,
683
644
  data.options,
684
645
  );
@@ -686,8 +647,8 @@ self.onmessage = async (
686
647
  postMessage({ id, action, result });
687
648
  break;
688
649
  }
689
- case "conversations.newDmWithIdentifier": {
690
- const conversation = await client.conversations.newDmWithIdentifier(
650
+ case "conversations.createDmWithIdentifier": {
651
+ const conversation = await client.conversations.createDmWithIdentifier(
691
652
  data.identifier,
692
653
  data.options,
693
654
  );
@@ -695,8 +656,8 @@ self.onmessage = async (
695
656
  postMessage({ id, action, result });
696
657
  break;
697
658
  }
698
- case "conversations.newDm": {
699
- const conversation = await client.conversations.newDm(
659
+ case "conversations.createDm": {
660
+ const conversation = await client.conversations.createDm(
700
661
  data.inboxId,
701
662
  data.options,
702
663
  );
@@ -723,8 +684,7 @@ self.onmessage = async (
723
684
  break;
724
685
  }
725
686
  case "conversations.getMessageById": {
726
- const message = client.conversations.getMessageById(data.id);
727
- const result = message ? toSafeMessage(message) : undefined;
687
+ const result = await client.conversations.getMessageById(data.id);
728
688
  postMessage({ id, action, result });
729
689
  break;
730
690
  }
@@ -736,15 +696,9 @@ self.onmessage = async (
736
696
  postMessage({ id, action, result });
737
697
  break;
738
698
  }
739
- case "conversations.getHmacKeys": {
740
- const hmacKeys = client.conversations.getHmacKeys();
741
- const result = Object.fromEntries(
742
- Array.from(hmacKeys.entries()).map(([groupId, hmacKeys]) => [
743
- groupId,
744
- hmacKeys.map(toSafeHmacKey),
745
- ]),
746
- );
747
- postMessage({ id, action, result });
699
+ case "conversations.hmacKeys": {
700
+ const hmacKeys = client.conversations.hmacKeys();
701
+ postMessage({ id, action, result: hmacKeys });
748
702
  break;
749
703
  }
750
704
  /**
@@ -759,12 +713,9 @@ self.onmessage = async (
759
713
  }
760
714
  case "conversation.lastMessage": {
761
715
  const group = getGroup(data.id);
716
+ // lastMessage() now returns enriched DecodedMessage directly
762
717
  const result = await group.lastMessage();
763
- postMessage({
764
- id,
765
- action,
766
- result: result ? toSafeMessage(result) : undefined,
767
- });
718
+ postMessage({ id, action, result });
768
719
  break;
769
720
  }
770
721
  case "conversation.isActive": {
@@ -775,7 +726,7 @@ self.onmessage = async (
775
726
  }
776
727
  case "conversation.consentState": {
777
728
  const group = getGroup(data.id);
778
- const result = group.consentState;
729
+ const result = group.consentState();
779
730
  postMessage({ id, action, result });
780
731
  break;
781
732
  }
@@ -811,19 +762,7 @@ self.onmessage = async (
811
762
  }
812
763
  case "conversation.send": {
813
764
  const group = getGroup(data.id);
814
- const result = await group.send(
815
- fromEncodedContent(fromSafeEncodedContent(data.content)),
816
- fromSafeSendMessageOpts(data.sendOptions),
817
- );
818
- postMessage({ id, action, result });
819
- break;
820
- }
821
- case "conversation.sendOptimistic": {
822
- const group = getGroup(data.id);
823
- const result = group.sendOptimistic(
824
- fromEncodedContent(fromSafeEncodedContent(data.content)),
825
- fromSafeSendMessageOpts(data.sendOptions),
826
- );
765
+ const result = await group.send(data.content, data.options);
827
766
  postMessage({ id, action, result });
828
767
  break;
829
768
  }
@@ -836,8 +775,8 @@ self.onmessage = async (
836
775
  case "conversation.messages": {
837
776
  const group = getGroup(data.id);
838
777
  const messages = await group.messages(data.options);
839
- const result = messages.map((message) => toSafeMessage(message));
840
- postMessage({ id, action, result });
778
+ // messages() now returns enriched DecodedMessage[] directly
779
+ postMessage({ id, action, result: messages });
841
780
  break;
842
781
  }
843
782
  case "conversation.countMessages": {
@@ -854,13 +793,13 @@ self.onmessage = async (
854
793
  }
855
794
  case "group.listAdmins": {
856
795
  const group = getGroup(data.id);
857
- const result = group.admins;
796
+ const result = group.listAdmins();
858
797
  postMessage({ id, action, result });
859
798
  break;
860
799
  }
861
800
  case "group.listSuperAdmins": {
862
801
  const group = getGroup(data.id);
863
- const result = group.superAdmins;
802
+ const result = group.listSuperAdmins();
864
803
  postMessage({ id, action, result });
865
804
  break;
866
805
  }
@@ -955,16 +894,13 @@ self.onmessage = async (
955
894
  }
956
895
  case "group.isPendingRemoval": {
957
896
  const group = getGroup(data.id);
958
- const result = group.isPendingRemoval;
897
+ const result = group.isPendingRemoval();
959
898
  postMessage({ id, action, result });
960
899
  break;
961
900
  }
962
901
  case "conversation.messageDisappearingSettings": {
963
902
  const group = getGroup(data.id);
964
- const settings = group.messageDisappearingSettings();
965
- const result = settings
966
- ? toSafeMessageDisappearingSettings(settings)
967
- : undefined;
903
+ const result = group.messageDisappearingSettings();
968
904
  postMessage({ id, action, result });
969
905
  break;
970
906
  }
@@ -998,12 +934,19 @@ self.onmessage = async (
998
934
  streamId: data.streamId,
999
935
  error,
1000
936
  });
1001
- } else {
1002
- postStreamMessage({
1003
- action: "stream.message",
1004
- streamId: data.streamId,
1005
- result: value ? toSafeMessage(value) : undefined,
1006
- });
937
+ } else if (value) {
938
+ void client.conversations
939
+ .getMessageById(value.id)
940
+ .then((enrichedMessage) => {
941
+ // guard against any edge cases where the message is not found
942
+ if (enrichedMessage) {
943
+ postStreamMessage({
944
+ action: "stream.message",
945
+ streamId: data.streamId,
946
+ result: enrichedMessage,
947
+ });
948
+ }
949
+ });
1007
950
  }
1008
951
  };
1009
952
  const streamCloser = group.stream(streamCallback, () => {
@@ -1024,15 +967,15 @@ self.onmessage = async (
1024
967
  postMessage({ id, action, result });
1025
968
  break;
1026
969
  }
1027
- case "conversation.getHmacKeys": {
970
+ case "conversation.hmacKeys": {
1028
971
  const group = getGroup(data.id);
1029
- const result = group.getHmacKeys();
972
+ const result = group.hmacKeys();
1030
973
  postMessage({ id, action, result });
1031
974
  break;
1032
975
  }
1033
- case "dm.getDuplicateDms": {
976
+ case "dm.duplicateDms": {
1034
977
  const group = getGroup(data.id);
1035
- const dms = await group.getDuplicateDms();
978
+ const dms = await group.duplicateDms();
1036
979
  const result = await Promise.all(
1037
980
  dms.map((dm) => toSafeConversation(dm)),
1038
981
  );
@@ -1041,8 +984,106 @@ self.onmessage = async (
1041
984
  }
1042
985
  case "conversation.debugInfo": {
1043
986
  const group = getGroup(data.id);
1044
- const debugInfo = await group.debugInfo();
1045
- const result = toSafeConversationDebugInfo(debugInfo);
987
+ const result = await group.debugInfo();
988
+ postMessage({ id, action, result });
989
+ break;
990
+ }
991
+ case "conversation.lastReadTimes": {
992
+ const group = getGroup(data.id);
993
+ const result = await group.lastReadTimes();
994
+ postMessage({ id, action, result });
995
+ break;
996
+ }
997
+ case "conversation.sendText": {
998
+ const group = getGroup(data.id);
999
+ const result = await group.sendText(data.text, data.isOptimistic);
1000
+ postMessage({ id, action, result });
1001
+ break;
1002
+ }
1003
+ case "conversation.sendMarkdown": {
1004
+ const group = getGroup(data.id);
1005
+ const result = await group.sendMarkdown(
1006
+ data.markdown,
1007
+ data.isOptimistic,
1008
+ );
1009
+ postMessage({ id, action, result });
1010
+ break;
1011
+ }
1012
+ case "conversation.sendReaction": {
1013
+ const group = getGroup(data.id);
1014
+ const result = await group.sendReaction(
1015
+ data.reaction,
1016
+ data.isOptimistic,
1017
+ );
1018
+ postMessage({ id, action, result });
1019
+ break;
1020
+ }
1021
+ case "conversation.sendReadReceipt": {
1022
+ const group = getGroup(data.id);
1023
+ const result = await group.sendReadReceipt(data.isOptimistic);
1024
+ postMessage({ id, action, result });
1025
+ break;
1026
+ }
1027
+ case "conversation.sendReply": {
1028
+ const group = getGroup(data.id);
1029
+ const result = await group.sendReply(data.reply, data.isOptimistic);
1030
+ postMessage({ id, action, result });
1031
+ break;
1032
+ }
1033
+ case "conversation.sendTransactionReference": {
1034
+ const group = getGroup(data.id);
1035
+ const result = await group.sendTransactionReference(
1036
+ data.transactionReference,
1037
+ data.isOptimistic,
1038
+ );
1039
+ postMessage({ id, action, result });
1040
+ break;
1041
+ }
1042
+ case "conversation.sendWalletSendCalls": {
1043
+ const group = getGroup(data.id);
1044
+ const result = await group.sendWalletSendCalls(
1045
+ data.walletSendCalls,
1046
+ data.isOptimistic,
1047
+ );
1048
+ postMessage({ id, action, result });
1049
+ break;
1050
+ }
1051
+ case "conversation.sendActions": {
1052
+ const group = getGroup(data.id);
1053
+ const result = await group.sendActions(data.actions, data.isOptimistic);
1054
+ postMessage({ id, action, result });
1055
+ break;
1056
+ }
1057
+ case "conversation.sendIntent": {
1058
+ const group = getGroup(data.id);
1059
+ const result = await group.sendIntent(data.intent, data.isOptimistic);
1060
+ postMessage({ id, action, result });
1061
+ break;
1062
+ }
1063
+ case "conversation.sendAttachment": {
1064
+ const group = getGroup(data.id);
1065
+ const result = await group.sendAttachment(
1066
+ data.attachment,
1067
+ data.isOptimistic,
1068
+ );
1069
+ postMessage({ id, action, result });
1070
+ break;
1071
+ }
1072
+ case "conversation.sendMultiRemoteAttachment": {
1073
+ const group = getGroup(data.id);
1074
+ const result = await group.sendMultiRemoteAttachment(
1075
+ data.multiRemoteAttachment,
1076
+ data.isOptimistic,
1077
+ );
1078
+ postMessage({ id, action, result });
1079
+ break;
1080
+ }
1081
+ case "conversation.sendRemoteAttachment": {
1082
+ const group = getGroup(data.id);
1083
+ const result = await group.sendRemoteAttachment(
1084
+ data.remoteAttachment,
1085
+ data.isOptimistic,
1086
+ );
1046
1087
  postMessage({ id, action, result });
1047
1088
  break;
1048
1089
  }
@@ -0,0 +1,127 @@
1
+ import init, {
2
+ opfsClearAll,
3
+ opfsDeleteFile,
4
+ opfsExportDb,
5
+ opfsFileCount,
6
+ opfsFileExists,
7
+ opfsImportDb,
8
+ opfsInit,
9
+ opfsListFiles,
10
+ opfsPoolCapacity,
11
+ } from "@xmtp/wasm-bindings";
12
+ import type {
13
+ ActionErrorData,
14
+ ActionName,
15
+ ActionWithoutResult,
16
+ ExtractActionWithoutData,
17
+ } from "@/types/actions";
18
+ import type { OpfsAction } from "@/types/actions/opfs";
19
+ import {
20
+ OpfsInitializationError,
21
+ OpfsNotInitializedError,
22
+ } from "@/utils/errors";
23
+
24
+ let initialized = false;
25
+ let enableLogging = false;
26
+
27
+ /**
28
+ * Type-safe postMessage
29
+ */
30
+ const postMessage = <A extends ActionName<OpfsAction>>(
31
+ data: ExtractActionWithoutData<OpfsAction, A>,
32
+ ) => {
33
+ self.postMessage(data);
34
+ };
35
+
36
+ /**
37
+ * Type-safe postMessage for errors
38
+ */
39
+ const postMessageError = (data: ActionErrorData<OpfsAction>) => {
40
+ self.postMessage(data);
41
+ };
42
+
43
+ self.onmessage = async (
44
+ event: MessageEvent<ActionWithoutResult<OpfsAction>>,
45
+ ) => {
46
+ const { action, id, data } = event.data;
47
+
48
+ // initialize WASM module
49
+ await init();
50
+
51
+ try {
52
+ // init is a special action that initializes the client
53
+ if (action === "opfs.init" && !initialized) {
54
+ try {
55
+ await opfsInit();
56
+ } catch {
57
+ throw new OpfsInitializationError();
58
+ }
59
+ initialized = true;
60
+ enableLogging = data.enableLogging ?? false;
61
+ postMessage({ id, action, result: undefined });
62
+ }
63
+
64
+ if (enableLogging) {
65
+ console.log("[worker] worker received event data", event.data);
66
+ }
67
+
68
+ // nothing else to do
69
+ if (action === "opfs.init") {
70
+ return;
71
+ }
72
+
73
+ // OPFS must be initialized for all other actions
74
+ if (!initialized) {
75
+ throw new OpfsNotInitializedError();
76
+ }
77
+
78
+ switch (action) {
79
+ case "opfs.listFiles": {
80
+ const files = await opfsListFiles();
81
+ postMessage({ id, action, result: files });
82
+ return;
83
+ }
84
+ case "opfs.fileCount": {
85
+ const fileCount = await opfsFileCount();
86
+ postMessage({ id, action, result: fileCount });
87
+ return;
88
+ }
89
+ case "opfs.poolCapacity": {
90
+ const poolCapacity = await opfsPoolCapacity();
91
+ postMessage({ id, action, result: poolCapacity });
92
+ return;
93
+ }
94
+ case "opfs.fileExists": {
95
+ const fileExists = await opfsFileExists(data.path);
96
+ postMessage({ id, action, result: fileExists });
97
+ return;
98
+ }
99
+ case "opfs.deleteFile": {
100
+ const deleted = await opfsDeleteFile(data.path);
101
+ postMessage({ id, action, result: deleted });
102
+ return;
103
+ }
104
+ case "opfs.exportDb": {
105
+ const db = await opfsExportDb(data.path);
106
+ postMessage({ id, action, result: db });
107
+ return;
108
+ }
109
+ case "opfs.importDb": {
110
+ await opfsImportDb(data.path, data.data);
111
+ postMessage({ id, action, result: undefined });
112
+ return;
113
+ }
114
+ case "opfs.clearAll": {
115
+ await opfsClearAll();
116
+ postMessage({ id, action, result: undefined });
117
+ return;
118
+ }
119
+ }
120
+ } catch (e) {
121
+ postMessageError({
122
+ id,
123
+ action,
124
+ error: e as Error,
125
+ });
126
+ }
127
+ };
@@ -1,2 +0,0 @@
1
- import e,{inboxStateFromInboxIds as t,applySignatureRequest as i,revokeInstallationsSignatureRequest as a,generateInboxId as s,getInboxIdForIdentifier as n}from"@xmtp/wasm-bindings";import"@xmtp/content-type-primitives";const r={local:"http://localhost:5557",dev:"https://api.dev.xmtp.network:5558",production:"https://api.production.xmtp.network:5558"},o=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),d=new Map,c=e=>{self.postMessage(e)};let l=!1;self.onmessage=async u=>{const{action:g,id:I,data:p}=u.data;l&&console.log("utils worker received event data",u.data),await e();try{switch(g){case"utils.init":l=p.enableLogging,c({id:I,action:g,result:void 0});break;case"utils.generateInboxId":{const e=s(p.identifier);c({id:I,action:g,result:e});break}case"utils.getInboxIdForIdentifier":{const e=await(async(e,t,i)=>n(t?r[t]:r.dev,i??null,e))(p.identifier,p.env,p.gatewayHost);c({id:I,action:g,result:e});break}case"utils.revokeInstallationsSignatureText":{const e=r[p.env??"dev"],t=a(e,p.gatewayHost,p.identifier,p.inboxId,p.installationIds),i=await t.signatureText();d.set(p.signatureRequestId,t);const s={signatureText:i,signatureRequestId:p.signatureRequestId};c({id:I,action:g,result:s});break}case"utils.revokeInstallations":{const e=r[p.env??"dev"],t=d.get(p.signatureRequestId);if(!t)throw new Error("Signature request not found");switch(p.signer.type){case"EOA":await t.addEcdsaSignature(p.signer.signature);break;case"SCW":await t.addScwSignature(p.signer.identifier,p.signer.signature,p.signer.chainId,p.signer.blockNumber)}await i(e,p.gatewayHost??null,t),d.delete(p.signatureRequestId),c({id:I,action:g,result:[]});break}case"utils.inboxStateFromInboxIds":{const e=r[p.env??"dev"];try{const i=(await t(e,p.gatewayHost??null,p.inboxIds)).map((e=>(e=>({identifiers:e.accountIdentifiers,inboxId:e.inboxId,installations:e.installations.map(o),recoveryIdentifier:e.recoveryIdentifier}))(e)));c({id:I,action:g,result:i})}catch(e){console.error("utils received error",e)}break}}}catch(e){(e=>{self.postMessage(e)})({id:I,action:g,error:e})}};
2
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sources":["../../src/constants.ts","../../src/utils/conversions.ts","../../src/workers/utils.ts"],"sourcesContent":[null,null,null],"names":["ApiUrls","local","dev","production","toSafeInstallation","installation","bytes","clientTimestampNs","id","signatureRequests","Map","postMessage","data","self","enableLogging","onmessage","async","event","action","console","log","init","result","undefined","generateInboxId","identifier","env","gatewayHost","get_inbox_id_for_identifier","getInboxIdForIdentifier","host","signatureRequest","revokeInstallationsSignatureRequest","inboxId","installationIds","signatureText","set","signatureRequestId","get","Error","signer","type","addEcdsaSignature","signature","addScwSignature","chainId","blockNumber","applySignatureRequest","delete","inboxStateFromInboxIds","inboxIds","map","inboxState","identifiers","accountIdentifiers","installations","recoveryIdentifier","toSafeInboxState","e","error","postMessageError"],"mappings":"4NAQO,MAAMA,EAAU,CACrBC,MAAO,wBACPC,IAAK,oCACLC,WAAY,4CC4aDC,EACXC,IAA0B,CAE1BC,MAAOD,EAAaC,MACpBC,kBAAmBF,EAAaE,kBAChCC,GAAIH,EAAaG,KCxabC,EAAoB,IAAIC,IAKxBC,EACJC,IAEAC,KAAKF,YAAYC,EAAK,EAmBxB,IAAIE,GAAgB,EAEpBD,KAAKE,UAAYC,MACfC,IAEA,MAAMC,OAAEA,EAAMV,GAAEA,EAAEI,KAAEA,GAASK,EAAML,KAE/BE,GACFK,QAAQC,IAAI,mCAAoCH,EAAML,YAIlDS,IAEN,IACE,OAAQH,GACN,IAAK,aACHJ,EAAgBF,EAAKE,cACrBH,EAAY,CAAEH,KAAIU,SAAQI,YAAQC,IAClC,MAEF,IAAK,wBAAyB,CAC5B,MAAMD,EAASE,EAAgBZ,EAAKa,YACpCd,EAAY,CACVH,KACAU,SACAI,WAEF,KACF,CACA,IAAK,gCAAiC,CACpC,MAAMA,OAxCkBN,OAC9BS,EACAC,EACAC,IAGOC,EADMF,EAAM1B,EAAQ0B,GAAO1B,EAAQE,IACDyB,GAAe,KAAMF,GAkCnCI,CACnBjB,EAAKa,WACLb,EAAKc,IACLd,EAAKe,aAEPhB,EAAY,CAAEH,KAAIU,SAAQI,WAC1B,KACF,CACA,IAAK,yCAA0C,CAC7C,MAAMQ,EAAO9B,EAAQY,EAAKc,KAAO,OAC3BK,EAAmBC,EACvBF,EACAlB,EAAKe,YACLf,EAAKa,WACLb,EAAKqB,QACLrB,EAAKsB,iBAEDC,QAAsBJ,EAAiBI,gBAC7C1B,EAAkB2B,IAAIxB,EAAKyB,mBAAoBN,GAC/C,MAAMT,EAAS,CACba,gBACAE,mBAAoBzB,EAAKyB,oBAE3B1B,EAAY,CAAEH,KAAIU,SAAQI,WAC1B,KACF,CACA,IAAK,4BAA6B,CAChC,MAAMQ,EAAO9B,EAAQY,EAAKc,KAAO,OAC3BK,EAAmBtB,EAAkB6B,IAAI1B,EAAKyB,oBACpD,IAAKN,EACH,MAAM,IAAIQ,MAAM,+BAElB,OAAQ3B,EAAK4B,OAAOC,MAClB,IAAK,YACGV,EAAiBW,kBAAkB9B,EAAK4B,OAAOG,WACrD,MACF,IAAK,YACGZ,EAAiBa,gBACrBhC,EAAK4B,OAAOf,WACZb,EAAK4B,OAAOG,UACZ/B,EAAK4B,OAAOK,QACZjC,EAAK4B,OAAOM,mBAIZC,EACJjB,EACAlB,EAAKe,aAAe,KACpBI,GAEFtB,EAAkBuC,OAAOpC,EAAKyB,oBAC9B1B,EAAY,CAAEH,KAAIU,SAAQI,OAAQ,KAClC,KACF,CAEA,IAAK,+BAAgC,CACnC,MAAMQ,EAAO9B,EAAQY,EAAKc,KAAO,OACjC,IACE,MAKMJ,SALoB2B,EACxBnB,EACAlB,EAAKe,aAAe,KACpBf,EAAKsC,WAEoBC,KAAKC,GDyTV,CAACA,IAAsB,CACrDC,YAAaD,EAAWE,mBACxBrB,QAASmB,EAAWnB,QACpBsB,cAAeH,EAAWG,cAAcJ,IAAI/C,GAC5CoD,mBAAoBJ,EAAWI,qBC5TrBC,CAAiBL,KAEnBzC,EAAY,CAAEH,KAAIU,SAAQI,UAC5B,CAAE,MAAOoC,GACPvC,QAAQwC,MAAM,uBAAwBD,EACxC,CACA,KACF,EAEJ,CAAE,MAAOA,GArHc,CAAC9C,IACxBC,KAAKF,YAAYC,EAAK,EAqHpBgD,CAAiB,CAAEpD,KAAIU,SAAQyC,MAAOD,GACxC"}