@xmtp/browser-sdk 0.0.17 → 0.0.19

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/README.md CHANGED
@@ -7,7 +7,7 @@ To keep up with the latest SDK developments, see the [Issues tab](https://githu
7
7
  To learn more about XMTP and get answers to frequently asked questions, see the [XMTP documentation](https://xmtp.org/docs).
8
8
 
9
9
  > [!CAUTION]
10
- > This SDK is currently in alpha. The API is subject to change and it is not yet recommended for production use.
10
+ > This SDK is in beta status and ready for you to build with in production. Software in this status may change based on feedback.
11
11
 
12
12
  ## Requirements
13
13
 
@@ -79,8 +79,7 @@ import { defineConfig } from "vite";
79
79
 
80
80
  export default defineConfig({
81
81
  optimizeDeps: {
82
- exclude: ["@xmtp/browser-sdk"],
83
- include: ["@xmtp/proto"],
82
+ exclude: ["@xmtp/wasm-bindings"],
84
83
  },
85
84
  });
86
85
  ```
package/dist/index.d.ts CHANGED
@@ -1,8 +1,27 @@
1
1
  import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
2
- import { SignatureRequestType, ConsentState, ConsentEntityType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Client as Client$1, Conversation as Conversation$1, EncodedContent, ContentTypeId, DeliveryStatus, GroupMessageKind, Message, SortDirection, ListMessagesOptions, GroupMembershipState, ConversationType, ListConversationsOptions, PermissionPolicySet, GroupPermissionsOptions, CreateGroupOptions, Installation, InboxState, Consent, PermissionLevel, GroupMember, HmacKey } from '@xmtp/wasm-bindings';
2
+ import { SignatureRequestType, ConsentState, ConsentEntityType, ConversationType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Message, Conversation as Conversation$1, Client as Client$1, EncodedContent, MessageDisappearingSettings, ContentTypeId, DeliveryStatus, GroupMessageKind, SortDirection, ListMessagesOptions, GroupMembershipState, ListConversationsOptions, PermissionPolicySet, GroupPermissionsOptions, CreateGroupOptions, CreateDMOptions, Installation, InboxState, Consent, PermissionLevel, GroupMember, HmacKey } from '@xmtp/wasm-bindings';
3
3
  export { Consent, ConsentEntityType, ConsentState, ContentTypeId, ConversationType, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, HmacKey, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, Message, MetadataField, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection } from '@xmtp/wasm-bindings';
4
4
  import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
5
5
 
6
+ type ResolveValue<T> = {
7
+ value: T | undefined;
8
+ done: boolean;
9
+ };
10
+ type StreamCallback<T> = (err: Error | null, value: T | undefined) => void | Promise<void>;
11
+ declare class AsyncStream<T> {
12
+ #private;
13
+ onReturn: (() => void) | undefined;
14
+ constructor();
15
+ get isDone(): boolean;
16
+ callback: StreamCallback<T>;
17
+ next: () => Promise<ResolveValue<T>>;
18
+ return: (value: T | undefined) => Promise<{
19
+ done: boolean;
20
+ value: T | undefined;
21
+ }>;
22
+ [Symbol.asyncIterator](): this;
23
+ }
24
+
6
25
  declare const ApiUrls: {
7
26
  readonly local: "http://localhost:5555";
8
27
  readonly dev: "https://dev.xmtp.network";
@@ -71,9 +90,20 @@ type ClientOptions = NetworkOptions & ContentOptions & StorageOptions & OtherOpt
71
90
 
72
91
  type ClientEvents =
73
92
  /**
74
- * Client actions
93
+ * Stream actions
75
94
  */
76
95
  {
96
+ action: "endStream";
97
+ id: string;
98
+ result: undefined;
99
+ data: {
100
+ streamId: string;
101
+ };
102
+ }
103
+ /**
104
+ * Client actions
105
+ */
106
+ | {
77
107
  action: "init";
78
108
  id: string;
79
109
  result: {
@@ -271,12 +301,29 @@ type ClientEvents =
271
301
  accountAddresses: string[];
272
302
  options?: SafeCreateGroupOptions;
273
303
  };
304
+ } | {
305
+ action: "newGroupByInboxIds";
306
+ id: string;
307
+ result: SafeConversation;
308
+ data: {
309
+ inboxIds: string[];
310
+ options?: SafeCreateGroupOptions;
311
+ };
274
312
  } | {
275
313
  action: "newDm";
276
314
  id: string;
277
315
  result: SafeConversation;
278
316
  data: {
279
317
  accountAddress: string;
318
+ options?: SafeCreateDmOptions;
319
+ };
320
+ } | {
321
+ action: "newDmByInboxId";
322
+ id: string;
323
+ result: SafeConversation;
324
+ data: {
325
+ inboxId: string;
326
+ options?: SafeCreateDmOptions;
280
327
  };
281
328
  } | {
282
329
  action: "syncConversations";
@@ -287,12 +334,30 @@ type ClientEvents =
287
334
  action: "syncAllConversations";
288
335
  id: string;
289
336
  result: undefined;
290
- data: undefined;
337
+ data: {
338
+ consentStates?: ConsentState[];
339
+ };
291
340
  } | {
292
341
  action: "getHmacKeys";
293
342
  id: string;
294
343
  result: SafeHmacKeys;
295
344
  data: undefined;
345
+ } | {
346
+ action: "streamAllGroups";
347
+ id: string;
348
+ result: undefined;
349
+ data: {
350
+ streamId: string;
351
+ conversationType?: ConversationType;
352
+ };
353
+ } | {
354
+ action: "streamAllMessages";
355
+ id: string;
356
+ result: undefined;
357
+ data: {
358
+ streamId: string;
359
+ conversationType?: ConversationType;
360
+ };
296
361
  }
297
362
  /**
298
363
  * Group actions
@@ -460,14 +525,6 @@ type ClientEvents =
460
525
  id: string;
461
526
  imageUrl: string;
462
527
  };
463
- } | {
464
- action: "updateGroupPinnedFrameUrl";
465
- id: string;
466
- result: undefined;
467
- data: {
468
- id: string;
469
- pinnedFrameUrl: string;
470
- };
471
528
  } | {
472
529
  action: "getGroupConsentState";
473
530
  id: string;
@@ -507,6 +564,42 @@ type ClientEvents =
507
564
  data: {
508
565
  id: string;
509
566
  };
567
+ } | {
568
+ action: "getGroupMessageDisappearingSettings";
569
+ id: string;
570
+ result: SafeMessageDisappearingSettings | undefined;
571
+ data: {
572
+ id: string;
573
+ };
574
+ } | {
575
+ action: "updateGroupMessageDisappearingSettings";
576
+ id: string;
577
+ result: undefined;
578
+ data: SafeMessageDisappearingSettings & {
579
+ id: string;
580
+ };
581
+ } | {
582
+ action: "removeGroupMessageDisappearingSettings";
583
+ id: string;
584
+ result: undefined;
585
+ data: {
586
+ id: string;
587
+ };
588
+ } | {
589
+ action: "isGroupMessageDisappearingEnabled";
590
+ id: string;
591
+ result: boolean;
592
+ data: {
593
+ id: string;
594
+ };
595
+ } | {
596
+ action: "streamGroupMessages";
597
+ id: string;
598
+ result: undefined;
599
+ data: {
600
+ groupId: string;
601
+ streamId: string;
602
+ };
510
603
  };
511
604
  type ClientEventsActions = ClientEvents["action"];
512
605
  type ClientEventsClientMessageData = EventsClientMessageData<ClientEvents>;
@@ -577,21 +670,48 @@ type EventsErrorData<Events extends GenericEvent> = {
577
670
  action: Events["action"];
578
671
  error: string;
579
672
  };
673
+ type GenericStreamEvent = {
674
+ type: string;
675
+ streamId: string;
676
+ result: unknown;
677
+ };
678
+ type StreamEventsClientMessageData<Events extends GenericStreamEvent> = {
679
+ [Type in Events["type"]]: Omit<Extract<Events, {
680
+ type: Type;
681
+ }>, "result">;
682
+ }[Events["type"]];
683
+ type StreamEventsResult<Events extends GenericStreamEvent, Type extends Events["type"]> = Extract<Events, {
684
+ type: Type;
685
+ }>["result"];
686
+ type StreamEventsClientPostMessageData<Events extends GenericStreamEvent, Type extends Events["type"]> = Extract<Events, {
687
+ type: Type;
688
+ }>;
689
+ type StreamEventsErrorData<Events extends GenericStreamEvent> = {
690
+ streamId: string;
691
+ type: Events["type"];
692
+ error: string;
693
+ };
580
694
 
581
695
  declare class WorkerConversations {
582
696
  #private;
583
697
  constructor(client: WorkerClient, conversations: Conversations$1);
584
698
  sync(): Promise<void>;
585
- syncAll(): Promise<number>;
699
+ syncAll(consentStates?: ConsentState[]): Promise<number>;
586
700
  getConversationById(id: string): WorkerConversation | undefined;
587
- getMessageById(id: string): _xmtp_wasm_bindings.Message | undefined;
701
+ getMessageById(id: string): Message | undefined;
588
702
  getDmByInboxId(inboxId: string): WorkerConversation | undefined;
589
703
  list(options?: SafeListConversationsOptions): WorkerConversation[];
590
704
  listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): WorkerConversation[];
591
705
  listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): WorkerConversation[];
592
706
  newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
593
- newDm(accountAddress: string): Promise<WorkerConversation>;
707
+ newGroupByInboxIds(inboxIds: string[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
708
+ newDm(accountAddress: string, options?: SafeCreateDmOptions): Promise<WorkerConversation>;
709
+ newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions): Promise<WorkerConversation>;
594
710
  getHmacKeys(): HmacKeys;
711
+ stream(callback?: StreamCallback<Conversation$1>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
712
+ streamGroups(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
713
+ streamDms(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
714
+ streamAllMessages(callback?: StreamCallback<Message>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
595
715
  }
596
716
 
597
717
  declare class WorkerClient {
@@ -603,7 +723,7 @@ declare class WorkerClient {
603
723
  get installationId(): string;
604
724
  get installationIdBytes(): Uint8Array<ArrayBufferLike>;
605
725
  get isRegistered(): boolean;
606
- createInboxSignatureText(): Promise<string | undefined>;
726
+ createInboxSignatureText(): string | undefined;
607
727
  addAccountSignatureText(accountAddress: string): Promise<string | undefined>;
608
728
  removeAccountSignatureText(accountAddress: string): Promise<string | undefined>;
609
729
  revokeAllAOtherInstallationsSignatureText(): Promise<string | undefined>;
@@ -634,8 +754,6 @@ declare class WorkerConversation {
634
754
  updateImageUrl(imageUrl: string): Promise<void>;
635
755
  get description(): string;
636
756
  updateDescription(description: string): Promise<void>;
637
- get pinnedFrameUrl(): string;
638
- updatePinnedFrameUrl(pinnedFrameUrl: string): Promise<void>;
639
757
  get isActive(): boolean;
640
758
  get addedByInboxId(): string;
641
759
  get createdAtNs(): bigint;
@@ -665,10 +783,15 @@ declare class WorkerConversation {
665
783
  publishMessages(): Promise<void>;
666
784
  sendOptimistic(encodedContent: EncodedContent): string;
667
785
  send(encodedContent: EncodedContent): Promise<string>;
668
- messages(options?: SafeListMessagesOptions): Promise<_xmtp_wasm_bindings.Message[]>;
786
+ messages(options?: SafeListMessagesOptions): Promise<Message[]>;
669
787
  get consentState(): ConsentState;
670
788
  updateConsentState(state: ConsentState): void;
671
789
  dmPeerInboxId(): string;
790
+ messageDisappearingSettings(): MessageDisappearingSettings | undefined;
791
+ updateMessageDisappearingSettings(fromNs: bigint, inNs: bigint): Promise<void>;
792
+ removeMessageDisappearingSettings(): Promise<void>;
793
+ isMessageDisappearingEnabled(): boolean;
794
+ stream(callback?: StreamCallback<Message>): _xmtp_wasm_bindings.StreamCloser;
672
795
  }
673
796
 
674
797
  declare const toContentTypeId: (contentTypeId: ContentTypeId) => ContentTypeId$1;
@@ -713,9 +836,12 @@ declare const toSafeListMessagesOptions: (options: ListMessagesOptions) => SafeL
713
836
  declare const fromSafeListMessagesOptions: (options: SafeListMessagesOptions) => ListMessagesOptions;
714
837
  type SafeListConversationsOptions = {
715
838
  allowedStates?: GroupMembershipState[];
839
+ consentStates?: ConsentState[];
716
840
  conversationType?: ConversationType;
717
841
  createdAfterNs?: bigint;
718
842
  createdBeforeNs?: bigint;
843
+ includeDuplicateDms?: boolean;
844
+ includeSyncGroups?: boolean;
719
845
  limit?: bigint;
720
846
  };
721
847
  declare const toSafeListConversationsOptions: (options: ListConversationsOptions) => SafeListConversationsOptions;
@@ -728,8 +854,7 @@ type SafePermissionPolicySet = {
728
854
  updateGroupDescriptionPolicy: PermissionPolicy;
729
855
  updateGroupImageUrlSquarePolicy: PermissionPolicy;
730
856
  updateGroupNamePolicy: PermissionPolicy;
731
- updateGroupPinnedFrameUrlPolicy: PermissionPolicy;
732
- updateMessageExpirationPolicy: PermissionPolicy;
857
+ updateMessageDisappearingPolicy: PermissionPolicy;
733
858
  };
734
859
  declare const toSafePermissionPolicySet: (policySet: PermissionPolicySet) => SafePermissionPolicySet;
735
860
  declare const fromSafePermissionPolicySet: (policySet: SafePermissionPolicySet) => PermissionPolicySet;
@@ -737,18 +862,22 @@ type SafeCreateGroupOptions = {
737
862
  customPermissionPolicySet?: SafePermissionPolicySet;
738
863
  description?: string;
739
864
  imageUrlSquare?: string;
865
+ messageDisappearingSettings?: SafeMessageDisappearingSettings;
740
866
  name?: string;
741
867
  permissions?: GroupPermissionsOptions;
742
- pinnedFrameUrl?: string;
743
868
  };
744
869
  declare const toSafeCreateGroupOptions: (options: CreateGroupOptions) => SafeCreateGroupOptions;
745
870
  declare const fromSafeCreateGroupOptions: (options: SafeCreateGroupOptions) => CreateGroupOptions;
871
+ type SafeCreateDmOptions = {
872
+ messageDisappearingSettings?: SafeMessageDisappearingSettings;
873
+ };
874
+ declare const toSafeCreateDmOptions: (options: CreateDMOptions) => SafeCreateDmOptions;
875
+ declare const fromSafeCreateDmOptions: (options: SafeCreateDmOptions) => CreateDMOptions;
746
876
  type SafeConversation = {
747
877
  id: string;
748
878
  name: string;
749
879
  imageUrl: string;
750
880
  description: string;
751
- pinnedFrameUrl: string;
752
881
  permissions: {
753
882
  policyType: GroupPermissionsOptions;
754
883
  policySet: {
@@ -759,8 +888,7 @@ type SafeConversation = {
759
888
  updateGroupDescriptionPolicy: PermissionPolicy;
760
889
  updateGroupImageUrlSquarePolicy: PermissionPolicy;
761
890
  updateGroupNamePolicy: PermissionPolicy;
762
- updateGroupPinnedFrameUrlPolicy: PermissionPolicy;
763
- updateMessageExpirationPolicy: PermissionPolicy;
891
+ updateMessageDisappearingPolicy: PermissionPolicy;
764
892
  };
765
893
  };
766
894
  isActive: boolean;
@@ -810,12 +938,29 @@ type SafeHmacKey = {
810
938
  declare const toSafeHmacKey: (hmacKey: HmacKey) => SafeHmacKey;
811
939
  type HmacKeys = Map<string, HmacKey[]>;
812
940
  type SafeHmacKeys = Record<string, SafeHmacKey[]>;
941
+ type SafeMessageDisappearingSettings = {
942
+ fromNs: bigint;
943
+ inNs: bigint;
944
+ };
945
+ declare const toSafeMessageDisappearingSettings: (settings: MessageDisappearingSettings) => SafeMessageDisappearingSettings;
946
+ declare const fromSafeMessageDisappearingSettings: (settings: SafeMessageDisappearingSettings) => MessageDisappearingSettings;
947
+
948
+ type ClientStreamEvents = {
949
+ type: "message";
950
+ streamId: string;
951
+ result: SafeMessage | undefined;
952
+ } | {
953
+ type: "group";
954
+ streamId: string;
955
+ result: SafeConversation | undefined;
956
+ };
813
957
 
814
958
  declare class ClientWorkerClass {
815
959
  #private;
816
960
  constructor(worker: Worker, enableLogging: boolean);
817
961
  sendMessage<A extends ClientEventsActions>(action: A, data: ClientSendMessageData<A>): Promise<ClientEventsResult<A>>;
818
962
  handleMessage: (event: MessageEvent<ClientEventsWorkerMessageData | ClientEventsErrorData>) => void;
963
+ handleStreamMessage: <T extends ClientStreamEvents["result"]>(streamId: string, callback: (error: Error | null, value: T | null) => void) => () => void;
819
964
  close(): void;
820
965
  }
821
966
 
@@ -848,8 +993,6 @@ declare class Conversation {
848
993
  updateImageUrl(imageUrl: string): Promise<void>;
849
994
  get description(): string | undefined;
850
995
  updateDescription(description: string): Promise<void>;
851
- get pinnedFrameUrl(): string | undefined;
852
- updatePinnedFrameUrl(pinnedFrameUrl: string): Promise<void>;
853
996
  get isActive(): boolean | undefined;
854
997
  get addedByInboxId(): string | undefined;
855
998
  get createdAtNs(): bigint | undefined;
@@ -873,8 +1016,7 @@ declare class Conversation {
873
1016
  updateGroupDescriptionPolicy: PermissionPolicy;
874
1017
  updateGroupImageUrlSquarePolicy: PermissionPolicy;
875
1018
  updateGroupNamePolicy: PermissionPolicy;
876
- updateGroupPinnedFrameUrlPolicy: PermissionPolicy;
877
- updateMessageExpirationPolicy: PermissionPolicy;
1019
+ updateMessageDisappearingPolicy: PermissionPolicy;
878
1020
  };
879
1021
  }>;
880
1022
  updatePermission(permissionType: PermissionUpdateType, policy: PermissionPolicy, metadataField?: MetadataField): Promise<undefined>;
@@ -896,13 +1038,18 @@ declare class Conversation {
896
1038
  consentState(): Promise<ConsentState>;
897
1039
  updateConsentState(state: ConsentState): Promise<undefined>;
898
1040
  dmPeerInboxId(): Promise<string>;
1041
+ messageDisappearingSettings(): Promise<SafeMessageDisappearingSettings | undefined>;
1042
+ updateMessageDisappearingSettings(fromNs: bigint, inNs: bigint): Promise<undefined>;
1043
+ removeMessageDisappearingSettings(): Promise<undefined>;
1044
+ isMessageDisappearingEnabled(): Promise<boolean>;
1045
+ stream(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
899
1046
  }
900
1047
 
901
1048
  declare class Conversations {
902
1049
  #private;
903
1050
  constructor(client: Client);
904
1051
  sync(): Promise<undefined>;
905
- syncAll(): Promise<undefined>;
1052
+ syncAll(consentStates?: ConsentState[]): Promise<undefined>;
906
1053
  getConversationById(id: string): Promise<Conversation | undefined>;
907
1054
  getMessageById(id: string): Promise<DecodedMessage | undefined>;
908
1055
  getDmByInboxId(inboxId: string): Promise<Conversation | undefined>;
@@ -910,8 +1057,16 @@ declare class Conversations {
910
1057
  listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Conversation[]>;
911
1058
  listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Conversation[]>;
912
1059
  newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<Conversation>;
913
- newDm(accountAddress: string): Promise<Conversation>;
1060
+ newGroupByInboxIds(inboxIds: string[], options?: SafeCreateGroupOptions): Promise<Conversation>;
1061
+ newDm(accountAddress: string, options?: SafeCreateDmOptions): Promise<Conversation>;
1062
+ newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions): Promise<Conversation>;
914
1063
  getHmacKeys(): Promise<SafeHmacKeys>;
1064
+ stream(callback?: StreamCallback<Conversation>, conversationType?: ConversationType): Promise<AsyncStream<Conversation>>;
1065
+ streamGroups(callback?: StreamCallback<Conversation>): Promise<AsyncStream<Conversation>>;
1066
+ streamDms(callback?: StreamCallback<Conversation>): Promise<AsyncStream<Conversation>>;
1067
+ streamAllMessages(callback?: StreamCallback<DecodedMessage>, conversationType?: ConversationType): Promise<AsyncStream<DecodedMessage>>;
1068
+ streamAllGroupMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
1069
+ streamAllDmMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
915
1070
  }
916
1071
 
917
1072
  type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
@@ -975,4 +1130,4 @@ declare class Utils extends UtilsWorkerClass {
975
1130
  getInboxIdForAddress(address: string, env?: XmtpEnv): Promise<string | undefined>;
976
1131
  }
977
1132
 
978
- export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, HistorySyncUrls, type HmacKeys, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeHmacKey, type SafeHmacKeys, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SafePermissionPolicySet, type SendMessageData, type Signer, type SmartContractSigner, type StorageOptions, Utils, type UtilsEvents, type UtilsEventsActions, type UtilsEventsClientMessageData, type UtilsEventsClientPostMessageData, type UtilsEventsErrorData, type UtilsEventsResult, type UtilsEventsWorkerMessageData, type UtilsEventsWorkerPostMessageData, type UtilsSendMessageData, type XmtpEnv, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, fromSafePermissionPolicySet, isSmartContractSigner, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafePermissionPolicySet };
1133
+ export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type GenericStreamEvent, HistorySyncUrls, type HmacKeys, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateDmOptions, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeHmacKey, type SafeHmacKeys, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SafeMessageDisappearingSettings, type SafePermissionPolicySet, type SendMessageData, type Signer, type SmartContractSigner, type StorageOptions, type StreamEventsClientMessageData, type StreamEventsClientPostMessageData, type StreamEventsErrorData, type StreamEventsResult, Utils, type UtilsEvents, type UtilsEventsActions, type UtilsEventsClientMessageData, type UtilsEventsClientPostMessageData, type UtilsEventsErrorData, type UtilsEventsResult, type UtilsEventsWorkerMessageData, type UtilsEventsWorkerPostMessageData, type UtilsSendMessageData, type XmtpEnv, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateDmOptions, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, fromSafeMessageDisappearingSettings, fromSafePermissionPolicySet, isSmartContractSigner, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateDmOptions, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafeMessageDisappearingSettings, toSafePermissionPolicySet };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{ContentTypeId as i,EncodedContent as r,ListMessagesOptions as a,ListConversationsOptions as o,PermissionPolicySet as d,CreateGroupOptions as c,GroupPermissionsOptions as l,Consent as p,GroupMember as u,GroupMessageKind as g,DeliveryStatus as m,SignatureRequestType as h}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentTypeId,ConversationType,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,Message,MetadataField,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as y}from"uuid";import{ContentTypeId as v}from"@xmtp/content-type-primitives";const I=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class w{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",I),this.#t=t}sendMessage(e,t){const s=y();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("client received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",I),this.#e.terminate()}}const b=e=>new v({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),M=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),A=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),S=e=>new v({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),x=e=>({type:b(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),P=e=>new r(M(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),k=e=>({type:A(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),f=e=>({type:S(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),G=e=>({content:k(x(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),U=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),N=e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),C=e=>({allowedStates:e.allowedStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,limit:e.limit}),T=e=>new o(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),B=e=>({addAdminPolicy:e.addAdminPolicy,addMemberPolicy:e.addMemberPolicy,removeAdminPolicy:e.removeAdminPolicy,removeMemberPolicy:e.removeMemberPolicy,updateGroupDescriptionPolicy:e.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:e.updateGroupPinnedFrameUrlPolicy,updateMessageExpirationPolicy:e.updateMessageExpirationPolicy}),L=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateGroupPinnedFrameUrlPolicy,e.updateMessageExpirationPolicy),E=e=>({description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,name:e.groupName,pinnedFrameUrl:e.groupPinnedFrameUrl,permissions:e.permissions,customPermissionPolicySet:e.customPermissionPolicySet}),F=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl,e.customPermissionPolicySet&&e.permissions===l.CustomPolicy?L(e.customPermissionPolicySet):void 0),D=async e=>{const t=e.id,s=e.name,n=e.imageUrl,i=e.description,r=e.pinnedFrameUrl,a=e.permissions,o=e.isActive,d=e.addedByInboxId,c=await e.metadata(),l=e.admins,p=e.superAdmins,u=e.createdAtNs,g=a.policyType,m=a.policySet;return{id:t,name:s,imageUrl:n,description:i,pinnedFrameUrl:r,permissions:{policyType:g,policySet:{addAdminPolicy:m.addAdminPolicy,addMemberPolicy:m.addMemberPolicy,removeAdminPolicy:m.removeAdminPolicy,removeMemberPolicy:m.removeMemberPolicy,updateGroupDescriptionPolicy:m.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:m.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:m.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:m.updateGroupPinnedFrameUrlPolicy,updateMessageExpirationPolicy:m.updateMessageExpirationPolicy}},isActive:o,addedByInboxId:d,metadata:c,admins:l,superAdmins:p,createdAtNs:u}},K=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),R=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(K),recoveryAddress:e.recoveryAddress}),j=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),O=e=>new p(e.entityType,e.state,e.entity),q=e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),W=e=>new u(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState),$=e=>({key:e.key,epoch:e.epoch});class H{#n;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;encodedContent;senderInboxId;sentAtNs;constructor(e,t){switch(this.#n=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,this.encodedContent=t.content,t.kind){case g.Application:this.kind="application";break;case g.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case m.Unpublished:this.deliveryStatus="unpublished";break;case m.Published:this.deliveryStatus="published";break;case m.Failed:this.deliveryStatus="failed"}this.contentType=S(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression,this.content=this.#n.decodeContent(t,this.contentType)}}class V{#n;#i;#r;#a;#o;#d;#c;#l;#p;#u;#g=[];#m=[];constructor(e,t,s){this.#n=e,this.#i=t,this.#h(s)}#h(e){this.#r=e?.name??"",this.#a=e?.imageUrl??"",this.#o=e?.description??"",this.#d=e?.pinnedFrameUrl??"",this.#c=e?.isActive??void 0,this.#l=e?.addedByInboxId??"",this.#p=e?.metadata??void 0,this.#u=e?.createdAtNs??void 0,this.#g=e?.admins??[],this.#m=e?.superAdmins??[]}get id(){return this.#i}get name(){return this.#r}async updateName(e){await this.#n.sendMessage("updateGroupName",{id:this.#i,name:e}),this.#r=e}get imageUrl(){return this.#a}async updateImageUrl(e){await this.#n.sendMessage("updateGroupImageUrlSquare",{id:this.#i,imageUrl:e}),this.#a=e}get description(){return this.#o}async updateDescription(e){await this.#n.sendMessage("updateGroupDescription",{id:this.#i,description:e}),this.#o=e}get pinnedFrameUrl(){return this.#d}async updatePinnedFrameUrl(e){await this.#n.sendMessage("updateGroupPinnedFrameUrl",{id:this.#i,pinnedFrameUrl:e}),this.#d=e}get isActive(){return this.#c}get addedByInboxId(){return this.#l}get createdAtNs(){return this.#u}get createdAt(){return this.#u?(e=this.#u,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#p}async members(){return this.#n.sendMessage("getGroupMembers",{id:this.#i})}get admins(){return this.#g}get superAdmins(){return this.#m}async syncAdmins(){const e=await this.#n.sendMessage("getGroupAdmins",{id:this.#i});this.#g=e}async syncSuperAdmins(){const e=await this.#n.sendMessage("getGroupSuperAdmins",{id:this.#i});this.#m=e}async permissions(){return this.#n.sendMessage("getGroupPermissions",{id:this.#i})}async updatePermission(e,t,s){return this.#n.sendMessage("updateGroupPermissionPolicy",{id:this.#i,permissionType:e,policy:t,metadataField:s})}async isAdmin(e){return await this.syncAdmins(),this.#g.includes(e)}async isSuperAdmin(e){return await this.syncSuperAdmins(),this.#m.includes(e)}async sync(){const e=await this.#n.sendMessage("syncGroup",{id:this.#i});this.#h(e)}async addMembers(e){return this.#n.sendMessage("addGroupMembers",{id:this.#i,accountAddresses:e})}async addMembersByInboxId(e){return this.#n.sendMessage("addGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async removeMembers(e){return this.#n.sendMessage("removeGroupMembers",{id:this.#i,accountAddresses:e})}async removeMembersByInboxId(e){return this.#n.sendMessage("removeGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async addAdmin(e){return this.#n.sendMessage("addGroupAdmin",{id:this.#i,inboxId:e})}async removeAdmin(e){return this.#n.sendMessage("removeGroupAdmin",{id:this.#i,inboxId:e})}async addSuperAdmin(e){return this.#n.sendMessage("addGroupSuperAdmin",{id:this.#i,inboxId:e})}async removeSuperAdmin(e){return this.#n.sendMessage("removeGroupSuperAdmin",{id:this.#i,inboxId:e})}async publishMessages(){return this.#n.sendMessage("publishGroupMessages",{id:this.#i})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendOptimisticGroupMessage",{id:this.#i,content:n})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendGroupMessage",{id:this.#i,content:n})}async messages(e){return(await this.#n.sendMessage("getGroupMessages",{id:this.#i,options:e})).map((e=>new H(this.#n,e)))}async consentState(){return this.#n.sendMessage("getGroupConsentState",{id:this.#i})}async updateConsentState(e){return this.#n.sendMessage("updateGroupConsentState",{id:this.#i,state:e})}async dmPeerInboxId(){return this.#n.sendMessage("getDmPeerInboxId",{id:this.#i})}}class _{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async syncAll(){return this.#n.sendMessage("syncAllConversations",void 0)}async getConversationById(e){const t=await this.#n.sendMessage("getConversationById",{id:e});return t?new V(this.#n,e,t):void 0}async getMessageById(e){const t=await this.#n.sendMessage("getMessageById",{id:e});return t?new H(this.#n,t):void 0}async getDmByInboxId(e){const t=await this.#n.sendMessage("getDmByInboxId",{inboxId:e});return t?new V(this.#n,t.id,t):void 0}async list(e){return(await this.#n.sendMessage("getConversations",{options:e})).map((e=>new V(this.#n,e.id,e)))}async listGroups(e){return(await this.#n.sendMessage("getGroups",{options:e})).map((e=>new V(this.#n,e.id,e)))}async listDms(e){return(await this.#n.sendMessage("getDms",{options:e})).map((e=>new V(this.#n,e.id,e)))}async newGroup(e,t){const s=await this.#n.sendMessage("newGroup",{accountAddresses:e,options:t});return new V(this.#n,s.id,s)}async newDm(e){const t=await this.#n.sendMessage("newDm",{accountAddress:e});return new V(this.#n,t.id,t)}async getHmacKeys(){return this.#n.sendMessage("getHmacKeys",void 0)}}const z=e=>"getBlockNumber"in e&&"getChainId"in e;class J extends w{#y;#v;#I;#w;#b;#M;#A;#S=!1;#x;options;constructor(t,s,i,r){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==r?.loggingLevel&&"off"!==r.loggingLevel),this.#y=s,this.options=r,this.#w=i,this.#x=t,this.#I=new _(this);const a=[new e,new n,...r?.codecs??[]];this.#v=new Map(a.map((e=>[e.contentType.toString(),e])))}get accountAddress(){return this.#y}async init(){const e=await this.sendMessage("init",{address:this.accountAddress,encryptionKey:this.#w,options:this.options});this.#b=e.inboxId,this.#M=e.installationId,this.#A=e.installationIdBytes,this.#S=!0}static async create(e,t,s){const n=await e.getAddress(),i=new J(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#S}get inboxId(){return this.#b}get installationId(){return this.#M}get installationIdBytes(){return this.#A}async#P(){return this.sendMessage("createInboxSignatureText",void 0)}async#k(e){return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async#f(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async#G(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async#U(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async#N(e,t,s){const n=await s.signMessage(t);z(s)?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async#C(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.#P();if(e)return await this.#N(h.CreateInbox,e,this.#x),this.sendMessage("registerIdentity",void 0)}async addAccount(e){const t=await this.#k(await e.getAddress());if(!t)throw new Error("Unable to generate add account signature text");await this.#N(h.AddWallet,t,e),await this.#C()}async removeAccount(e){const t=await this.#f(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.#N(h.RevokeWallet,t,this.#x),await this.#C()}async revokeAllOtherInstallations(){const e=await this.#G();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.#N(h.RevokeInstallations,e,this.#x),await this.#C()}async revokeInstallations(e){const t=await this.#U(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.#N(h.RevokeInstallations,t,this.#x),await this.#C()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}static async canMessage(e,t){const s={getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await J.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(e)}async findInboxIdByAddress(e){return this.sendMessage("findInboxIdByAddress",{address:e})}async inboxState(e){return this.sendMessage("inboxState",{refreshFromNetwork:e??!1})}async getLatestInboxState(e){return this.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.sendMessage("getConsentState",{entityType:e,entity:t})}get conversations(){return this.#I}codecFor(e){return this.#v.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),k(n)}decodeContent(e,s){const n=this.codecFor(s);if(!n)throw new Error(`Codec not found for "${s.toString()}" content type`);if(s.sameAs(t)&&e.kind!==g.MembershipChange)throw new Error("Error decoding group membership change");const i=f(e.content);return n.decode(i,this)}signWithInstallationKey(e){return this.sendMessage("signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}}const Q=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class X{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",Q),this.#t=t}sendMessage(e,t){const s=y();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("utils received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",Q),this.#e.terminate()}}class Y extends X{#t;constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1),this.#t=e??!1}async generateInboxId(e){return this.sendMessage("generateInboxId",{address:e,enableLogging:this.#t})}async getInboxIdForAddress(e,t){return this.sendMessage("getInboxIdForAddress",{address:e,env:t,enableLogging:this.#t})}}const Z={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},ee={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{Z as ApiUrls,J as Client,V as Conversation,_ as Conversations,H as DecodedMessage,ee as HistorySyncUrls,Y as Utils,M as fromContentTypeId,P as fromEncodedContent,O as fromSafeConsent,S as fromSafeContentTypeId,F as fromSafeCreateGroupOptions,f as fromSafeEncodedContent,W as fromSafeGroupMember,T as fromSafeListConversationsOptions,N as fromSafeListMessagesOptions,L as fromSafePermissionPolicySet,z as isSmartContractSigner,b as toContentTypeId,x as toEncodedContent,j as toSafeConsent,A as toSafeContentTypeId,D as toSafeConversation,E as toSafeCreateGroupOptions,k as toSafeEncodedContent,q as toSafeGroupMember,$ as toSafeHmacKey,R as toSafeInboxState,K as toSafeInstallation,C as toSafeListConversationsOptions,U as toSafeListMessagesOptions,G as toSafeMessage,B as toSafePermissionPolicySet};
1
+ import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{ContentTypeId as i,EncodedContent as r,ListMessagesOptions as a,ListConversationsOptions as o,PermissionPolicySet as d,CreateGroupOptions as c,GroupPermissionsOptions as l,CreateDMOptions as u,Consent as g,GroupMember as p,MessageDisappearingSettings as h,GroupMessageKind as m,DeliveryStatus as y,ConversationType as v,SignatureRequestType as w}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentTypeId,ConversationType,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,Message,MetadataField,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as I}from"uuid";import{ContentTypeId as M}from"@xmtp/content-type-primitives";const b=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class S{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",b),this.#t=t}sendMessage(e,t){const s=I();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("client received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};handleStreamMessage=(e,t)=>{const s=s=>{const n=s.data;n.streamId===e&&("error"in n?t(new Error(n.error),null):t(null,n.result))};return this.#e.addEventListener("message",s),()=>{this.#e.removeEventListener("message",s)}};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",b),this.#e.terminate()}}class A{#n=!1;#i;#r;onReturn=void 0;constructor(){this.#r=[],this.#i=null,this.#n=!1}get isDone(){return this.#n}callback=(e,t)=>{if(e)throw e;this.#n||(this.#i?(this.#i({done:!1,value:t}),this.#i=null):this.#r.push(t))};next=()=>this.#r.length>0?Promise.resolve({done:!1,value:this.#r.shift()}):this.#n?Promise.resolve({done:!0,value:void 0}):new Promise((e=>{this.#i=e}));return=e=>(this.#n=!0,this.onReturn?.(),Promise.resolve({done:!0,value:e}));[Symbol.asyncIterator](){return this}}const x=e=>new M({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),k=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),P=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),f=e=>new M({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),G=e=>({type:x(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),D=e=>new r(k(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),N=e=>({type:P(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({type:f(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({content:N(G(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),B=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),L=e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),U=e=>({allowedStates:e.allowedStates,consentStates:e.consentStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,includeSyncGroups:e.includeSyncGroups,limit:e.limit}),E=e=>new o(e.allowedStates,e.consentStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!1,e.includeSyncGroups??!1,e.limit),R=e=>({addAdminPolicy:e.addAdminPolicy,addMemberPolicy:e.addMemberPolicy,removeAdminPolicy:e.removeAdminPolicy,removeMemberPolicy:e.removeMemberPolicy,updateGroupDescriptionPolicy:e.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.updateGroupNamePolicy,updateMessageDisappearingPolicy:e.updateMessageDisappearingPolicy}),q=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),K=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),j=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===l.CustomPolicy?q(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),O=e=>({messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0}),W=e=>new u(e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),F=async e=>{const t=e.id,s=e.name,n=e.imageUrl,i=e.description,r=e.permissions,a=e.isActive,o=e.addedByInboxId,d=await e.metadata(),c=e.admins,l=e.superAdmins,u=e.createdAtNs,g=r.policyType,p=r.policySet;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:g,policySet:{addAdminPolicy:p.addAdminPolicy,addMemberPolicy:p.addMemberPolicy,removeAdminPolicy:p.removeAdminPolicy,removeMemberPolicy:p.removeMemberPolicy,updateGroupDescriptionPolicy:p.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:p.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:p.updateGroupNamePolicy,updateMessageDisappearingPolicy:p.updateMessageDisappearingPolicy}},isActive:a,addedByInboxId:o,metadata:d,admins:c,superAdmins:l,createdAtNs:u}},$=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),H=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map($),recoveryAddress:e.recoveryAddress}),V=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),_=e=>new g(e.entityType,e.state,e.entity),z=e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),J=e=>new p(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState),Q=e=>({key:e.key,epoch:e.epoch}),X=e=>({fromNs:e.fromNs,inNs:e.inNs}),Y=e=>new h(e.fromNs,e.inNs);class Z{#a;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;encodedContent;senderInboxId;sentAtNs;constructor(e,t){switch(this.#a=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,this.encodedContent=t.content,t.kind){case m.Application:this.kind="application";break;case m.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case y.Unpublished:this.deliveryStatus="unpublished";break;case y.Published:this.deliveryStatus="published";break;case y.Failed:this.deliveryStatus="failed"}this.contentType=f(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression,this.content=this.#a.decodeContent(t,this.contentType)}}class ee{#a;#o;#d;#c;#l;#u;#g;#p;#h;#m=[];#y=[];constructor(e,t,s){this.#a=e,this.#o=t,this.#v(s)}#v(e){this.#d=e?.name??"",this.#c=e?.imageUrl??"",this.#l=e?.description??"",this.#u=e?.isActive??void 0,this.#g=e?.addedByInboxId??"",this.#p=e?.metadata??void 0,this.#h=e?.createdAtNs??void 0,this.#m=e?.admins??[],this.#y=e?.superAdmins??[]}get id(){return this.#o}get name(){return this.#d}async updateName(e){await this.#a.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#d=e}get imageUrl(){return this.#c}async updateImageUrl(e){await this.#a.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#c=e}get description(){return this.#l}async updateDescription(e){await this.#a.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#l=e}get isActive(){return this.#u}get addedByInboxId(){return this.#g}get createdAtNs(){return this.#h}get createdAt(){return this.#h?(e=this.#h,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#p}async members(){return this.#a.sendMessage("getGroupMembers",{id:this.#o})}get admins(){return this.#m}get superAdmins(){return this.#y}async syncAdmins(){const e=await this.#a.sendMessage("getGroupAdmins",{id:this.#o});this.#m=e}async syncSuperAdmins(){const e=await this.#a.sendMessage("getGroupSuperAdmins",{id:this.#o});this.#y=e}async permissions(){return this.#a.sendMessage("getGroupPermissions",{id:this.#o})}async updatePermission(e,t,s){return this.#a.sendMessage("updateGroupPermissionPolicy",{id:this.#o,permissionType:e,policy:t,metadataField:s})}async isAdmin(e){return await this.syncAdmins(),this.#m.includes(e)}async isSuperAdmin(e){return await this.syncSuperAdmins(),this.#y.includes(e)}async sync(){const e=await this.#a.sendMessage("syncGroup",{id:this.#o});this.#v(e)}async addMembers(e){return this.#a.sendMessage("addGroupMembers",{id:this.#o,accountAddresses:e})}async addMembersByInboxId(e){return this.#a.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembers(e){return this.#a.sendMessage("removeGroupMembers",{id:this.#o,accountAddresses:e})}async removeMembersByInboxId(e){return this.#a.sendMessage("removeGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async addAdmin(e){return this.#a.sendMessage("addGroupAdmin",{id:this.#o,inboxId:e})}async removeAdmin(e){return this.#a.sendMessage("removeGroupAdmin",{id:this.#o,inboxId:e})}async addSuperAdmin(e){return this.#a.sendMessage("addGroupSuperAdmin",{id:this.#o,inboxId:e})}async removeSuperAdmin(e){return this.#a.sendMessage("removeGroupSuperAdmin",{id:this.#o,inboxId:e})}async publishMessages(){return this.#a.sendMessage("publishGroupMessages",{id:this.#o})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendOptimisticGroupMessage",{id:this.#o,content:n})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendGroupMessage",{id:this.#o,content:n})}async messages(e){return(await this.#a.sendMessage("getGroupMessages",{id:this.#o,options:e})).map((e=>new Z(this.#a,e)))}async consentState(){return this.#a.sendMessage("getGroupConsentState",{id:this.#o})}async updateConsentState(e){return this.#a.sendMessage("updateGroupConsentState",{id:this.#o,state:e})}async dmPeerInboxId(){return this.#a.sendMessage("getDmPeerInboxId",{id:this.#o})}async messageDisappearingSettings(){return this.#a.sendMessage("getGroupMessageDisappearingSettings",{id:this.#o})}async updateMessageDisappearingSettings(e,t){return this.#a.sendMessage("updateGroupMessageDisappearingSettings",{id:this.#o,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#a.sendMessage("removeGroupMessageDisappearingSettings",{id:this.#o})}async isMessageDisappearingEnabled(){return this.#a.sendMessage("isGroupMessageDisappearingEnabled",{id:this.#o})}async stream(e){const t=I(),s=new A,n=this.#a.handleStreamMessage(t,((t,n)=>{const i=n?new Z(this.#a,n):void 0;s.callback(t,i),e?.(t,i)}));return await this.#a.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}}class te{#a;constructor(e){this.#a=e}async sync(){return this.#a.sendMessage("syncConversations",void 0)}async syncAll(e){return this.#a.sendMessage("syncAllConversations",{consentStates:e})}async getConversationById(e){const t=await this.#a.sendMessage("getConversationById",{id:e});return t?new ee(this.#a,e,t):void 0}async getMessageById(e){const t=await this.#a.sendMessage("getMessageById",{id:e});return t?new Z(this.#a,t):void 0}async getDmByInboxId(e){const t=await this.#a.sendMessage("getDmByInboxId",{inboxId:e});return t?new ee(this.#a,t.id,t):void 0}async list(e){return(await this.#a.sendMessage("getConversations",{options:e})).map((e=>new ee(this.#a,e.id,e)))}async listGroups(e){return(await this.#a.sendMessage("getGroups",{options:e})).map((e=>new ee(this.#a,e.id,e)))}async listDms(e){return(await this.#a.sendMessage("getDms",{options:e})).map((e=>new ee(this.#a,e.id,e)))}async newGroup(e,t){const s=await this.#a.sendMessage("newGroup",{accountAddresses:e,options:t});return new ee(this.#a,s.id,s)}async newGroupByInboxIds(e,t){const s=await this.#a.sendMessage("newGroupByInboxIds",{inboxIds:e,options:t});return new ee(this.#a,s.id,s)}async newDm(e,t){const s=await this.#a.sendMessage("newDm",{accountAddress:e,options:t});return new ee(this.#a,s.id,s)}async newDmByInboxId(e,t){const s=await this.#a.sendMessage("newDmByInboxId",{inboxId:e,options:t});return new ee(this.#a,s.id,s)}async getHmacKeys(){return this.#a.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=I(),n=new A,i=this.#a.handleStreamMessage(s,((t,s)=>{const i=s?new ee(this.#a,s.id,s):void 0;n.callback(t,i),e?.(t,i)}));return await this.#a.sendMessage("streamAllGroups",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),i()},n}async streamGroups(e){return this.stream(e,v.Group)}async streamDms(e){return this.stream(e,v.Dm)}async streamAllMessages(e,t){const s=I(),n=new A,i=this.#a.handleStreamMessage(s,((t,s)=>{const i=s?new Z(this.#a,s):void 0;n.callback(t,i),e?.(t,i)}));return await this.#a.sendMessage("streamAllMessages",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),i()},n}async streamAllGroupMessages(e){return this.streamAllMessages(e,v.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,v.Dm)}}const se=e=>"getBlockNumber"in e&&"getChainId"in e;class ne extends S{#w;#I;#M;#b;#S;#A;#x;#k=!1;#P;options;constructor(t,s,i,r){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==r?.loggingLevel&&"off"!==r.loggingLevel),this.#w=s,this.options=r,this.#b=i,this.#P=t,this.#M=new te(this);const a=[new e,new n,...r?.codecs??[]];this.#I=new Map(a.map((e=>[e.contentType.toString(),e])))}get accountAddress(){return this.#w}async init(){const e=await this.sendMessage("init",{address:this.accountAddress,encryptionKey:this.#b,options:this.options});this.#S=e.inboxId,this.#A=e.installationId,this.#x=e.installationIdBytes,this.#k=!0}static async create(e,t,s){const n=await e.getAddress(),i=new ne(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#k}get inboxId(){return this.#S}get installationId(){return this.#A}get installationIdBytes(){return this.#x}async#f(){return this.sendMessage("createInboxSignatureText",void 0)}async#G(e){return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async#D(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async#N(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async#T(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async#C(e,t,s){const n=await s.signMessage(t);se(s)?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async#B(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.#f();if(e)return await this.#C(w.CreateInbox,e,this.#P),this.sendMessage("registerIdentity",void 0)}async addAccount(e){const t=await this.#G(await e.getAddress());if(!t)throw new Error("Unable to generate add account signature text");await this.#C(w.AddWallet,t,e),await this.#B()}async removeAccount(e){const t=await this.#D(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.#C(w.RevokeWallet,t,this.#P),await this.#B()}async revokeAllOtherInstallations(){const e=await this.#N();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.#C(w.RevokeInstallations,e,this.#P),await this.#B()}async revokeInstallations(e){const t=await this.#T(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.#C(w.RevokeInstallations,t,this.#P),await this.#B()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}static async canMessage(e,t){const s={getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await ne.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(e)}async findInboxIdByAddress(e){return this.sendMessage("findInboxIdByAddress",{address:e})}async inboxState(e){return this.sendMessage("inboxState",{refreshFromNetwork:e??!1})}async getLatestInboxState(e){return this.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.sendMessage("getConsentState",{entityType:e,entity:t})}get conversations(){return this.#M}codecFor(e){return this.#I.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),N(n)}decodeContent(e,s){const n=this.codecFor(s);if(!n)throw new Error(`Codec not found for "${s.toString()}" content type`);if(s.sameAs(t)&&e.kind!==m.MembershipChange)throw new Error("Error decoding group membership change");const i=T(e.content);return n.decode(i,this)}signWithInstallationKey(e){return this.sendMessage("signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}}const ie=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class re{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",ie),this.#t=t}sendMessage(e,t){const s=I();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("utils received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",ie),this.#e.terminate()}}class ae extends re{#t;constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1),this.#t=e??!1}async generateInboxId(e){return this.sendMessage("generateInboxId",{address:e,enableLogging:this.#t})}async getInboxIdForAddress(e,t){return this.sendMessage("getInboxIdForAddress",{address:e,env:t,enableLogging:this.#t})}}const oe={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},de={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{oe as ApiUrls,ne as Client,ee as Conversation,te as Conversations,Z as DecodedMessage,de as HistorySyncUrls,ae as Utils,k as fromContentTypeId,D as fromEncodedContent,_ as fromSafeConsent,f as fromSafeContentTypeId,W as fromSafeCreateDmOptions,j as fromSafeCreateGroupOptions,T as fromSafeEncodedContent,J as fromSafeGroupMember,E as fromSafeListConversationsOptions,L as fromSafeListMessagesOptions,Y as fromSafeMessageDisappearingSettings,q as fromSafePermissionPolicySet,se as isSmartContractSigner,x as toContentTypeId,G as toEncodedContent,V as toSafeConsent,P as toSafeContentTypeId,F as toSafeConversation,O as toSafeCreateDmOptions,K as toSafeCreateGroupOptions,N as toSafeEncodedContent,z as toSafeGroupMember,Q as toSafeHmacKey,H as toSafeInboxState,$ as toSafeInstallation,U as toSafeListConversationsOptions,B as toSafeListMessagesOptions,C as toSafeMessage,X as toSafeMessageDisappearingSettings,R as toSafePermissionPolicySet};
2
2
  //# sourceMappingURL=index.js.map