@xmtp/browser-sdk 0.0.21 → 0.0.22

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
@@ -9,62 +9,11 @@ To learn more about XMTP and get answers to frequently asked questions, see the
9
9
  > [!CAUTION]
10
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
- ## Requirements
12
+ ## Limitations
13
13
 
14
- ### Response headers
14
+ This SDK uses the [origin private file system](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system) (OPFS) to persist a SQLite database and the [SyncAccessHandle Pool VFS](https://sqlite.org/wasm/doc/trunk/persistence.md#vfs-opfs-sahpool) to access it. This VFS does not support multiple simultaneous connections.
15
15
 
16
- Server response headers must be set to the following values:
17
-
18
- - `Cross-Origin-Embedder-Policy: require-corp`
19
- - `Cross-Origin-Opener-Policy: same-origin`
20
-
21
- #### Vite
22
-
23
- Add the following to `vite.config.ts`:
24
-
25
- ```typescript
26
- import { defineConfig } from "vite";
27
-
28
- export default defineConfig({
29
- server: {
30
- headers: {
31
- "Cross-Origin-Embedder-Policy": "require-corp",
32
- "Cross-Origin-Opener-Policy": "same-origin",
33
- },
34
- },
35
- });
36
- ```
37
-
38
- #### Next.js
39
-
40
- Add the following to `next.config.ts`:
41
-
42
- ```typescript
43
- import type { NextConfig } from "next";
44
-
45
- const nextConfig: NextConfig = {
46
- async headers() {
47
- return [
48
- {
49
- // adjust ":path*" as needed
50
- source: "/:path*",
51
- headers: [
52
- {
53
- key: "Cross-Origin-Embedder-Policy",
54
- value: "require-corp",
55
- },
56
- {
57
- key: "Cross-Origin-Opener-Policy",
58
- value: "same-origin",
59
- },
60
- ],
61
- },
62
- ];
63
- },
64
- };
65
-
66
- export default nextConfig;
67
- ```
16
+ This means that when using this SDK in your application, you must prevent multiple browser tabs or windows from accessing your application at the same time.
68
17
 
69
18
  ### Bundlers
70
19
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _xmtp_wasm_bindings 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
- 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';
2
+ import { SignatureRequestType, ConsentState, ConsentEntityType, ConversationType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Message, Conversation as Conversation$1, Consent, UserPreference, Client as Client$1, EncodedContent, MessageDisappearingSettings, ContentTypeId, DeliveryStatus, GroupMessageKind, ContentType, SortDirection, ListMessagesOptions, ListConversationsOptions, PermissionPolicySet, GroupPermissionsOptions, CreateGroupOptions, CreateDMOptions, Installation, InboxState, PermissionLevel, GroupMember, HmacKey } from '@xmtp/wasm-bindings';
3
+ export { Consent, ConsentEntityType, ConsentState, ContentType, ContentTypeId, ConversationListItem, ConversationType, CreateDMOptions, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, HmacKey, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, LogOptions, Message, MessageDisappearingSettings, MetadataField, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection, UserPreference } from '@xmtp/wasm-bindings';
4
4
  import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
5
5
 
6
6
  type ResolveValue<T> = {
@@ -358,6 +358,20 @@ type ClientEvents =
358
358
  streamId: string;
359
359
  conversationType?: ConversationType;
360
360
  };
361
+ } | {
362
+ action: "streamConsent";
363
+ id: string;
364
+ result: undefined;
365
+ data: {
366
+ streamId: string;
367
+ };
368
+ } | {
369
+ action: "streamPreferences";
370
+ id: string;
371
+ result: undefined;
372
+ data: {
373
+ streamId: string;
374
+ };
361
375
  }
362
376
  /**
363
377
  * Group actions
@@ -712,6 +726,8 @@ declare class WorkerConversations {
712
726
  streamGroups(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
713
727
  streamDms(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
714
728
  streamAllMessages(callback?: StreamCallback<Message>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
729
+ streamConsent(callback?: StreamCallback<Consent[]>): _xmtp_wasm_bindings.StreamCloser;
730
+ streamPreferences(callback?: StreamCallback<UserPreference[]>): _xmtp_wasm_bindings.StreamCloser;
715
731
  }
716
732
 
717
733
  declare class WorkerClient {
@@ -826,6 +842,7 @@ type SafeMessage = {
826
842
  };
827
843
  declare const toSafeMessage: (message: Message) => SafeMessage;
828
844
  type SafeListMessagesOptions = {
845
+ contentTypes?: ContentType[];
829
846
  deliveryStatus?: DeliveryStatus;
830
847
  direction?: SortDirection;
831
848
  limit?: bigint;
@@ -835,13 +852,10 @@ type SafeListMessagesOptions = {
835
852
  declare const toSafeListMessagesOptions: (options: ListMessagesOptions) => SafeListMessagesOptions;
836
853
  declare const fromSafeListMessagesOptions: (options: SafeListMessagesOptions) => ListMessagesOptions;
837
854
  type SafeListConversationsOptions = {
838
- allowedStates?: GroupMembershipState[];
839
855
  consentStates?: ConsentState[];
840
- conversationType?: ConversationType;
841
856
  createdAfterNs?: bigint;
842
857
  createdBeforeNs?: bigint;
843
858
  includeDuplicateDms?: boolean;
844
- includeSyncGroups?: boolean;
845
859
  limit?: bigint;
846
860
  };
847
861
  declare const toSafeListConversationsOptions: (options: ListConversationsOptions) => SafeListConversationsOptions;
@@ -953,6 +967,14 @@ type ClientStreamEvents = {
953
967
  type: "group";
954
968
  streamId: string;
955
969
  result: SafeConversation | undefined;
970
+ } | {
971
+ type: "consent";
972
+ streamId: string;
973
+ result: SafeConsent[] | undefined;
974
+ } | {
975
+ type: "preferences";
976
+ streamId: string;
977
+ result: UserPreference[] | undefined;
956
978
  };
957
979
 
958
980
  declare class ClientWorkerClass {
@@ -987,12 +1009,6 @@ declare class Conversation {
987
1009
  #private;
988
1010
  constructor(client: Client, id: string, data?: SafeConversation);
989
1011
  get id(): string;
990
- get name(): string | undefined;
991
- updateName(name: string): Promise<void>;
992
- get imageUrl(): string | undefined;
993
- updateImageUrl(imageUrl: string): Promise<void>;
994
- get description(): string | undefined;
995
- updateDescription(description: string): Promise<void>;
996
1012
  get isActive(): boolean | undefined;
997
1013
  get addedByInboxId(): string | undefined;
998
1014
  get createdAtNs(): bigint | undefined;
@@ -1002,10 +1018,40 @@ declare class Conversation {
1002
1018
  conversationType: string;
1003
1019
  } | undefined;
1004
1020
  members(): Promise<SafeGroupMember[]>;
1021
+ sync(): Promise<SafeConversation>;
1022
+ publishMessages(): Promise<undefined>;
1023
+ sendOptimistic(content: any, contentType?: ContentTypeId$1): Promise<string>;
1024
+ send(content: any, contentType?: ContentTypeId$1): Promise<string>;
1025
+ messages(options?: SafeListMessagesOptions): Promise<DecodedMessage[]>;
1026
+ consentState(): Promise<ConsentState>;
1027
+ updateConsentState(state: ConsentState): Promise<undefined>;
1028
+ messageDisappearingSettings(): Promise<SafeMessageDisappearingSettings | undefined>;
1029
+ updateMessageDisappearingSettings(fromNs: bigint, inNs: bigint): Promise<undefined>;
1030
+ removeMessageDisappearingSettings(): Promise<undefined>;
1031
+ isMessageDisappearingEnabled(): Promise<boolean>;
1032
+ stream(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
1033
+ }
1034
+
1035
+ declare class Dm extends Conversation {
1036
+ #private;
1037
+ constructor(client: Client, id: string, data?: SafeConversation);
1038
+ peerInboxId(): Promise<string>;
1039
+ }
1040
+
1041
+ declare class Group extends Conversation {
1042
+ #private;
1043
+ constructor(client: Client, id: string, data?: SafeConversation);
1044
+ sync(): Promise<SafeConversation>;
1045
+ get name(): string | undefined;
1046
+ updateName(name: string): Promise<void>;
1047
+ get imageUrl(): string | undefined;
1048
+ updateImageUrl(imageUrl: string): Promise<void>;
1049
+ get description(): string | undefined;
1050
+ updateDescription(description: string): Promise<void>;
1005
1051
  get admins(): string[];
1006
1052
  get superAdmins(): string[];
1007
- syncAdmins(): Promise<void>;
1008
- syncSuperAdmins(): Promise<void>;
1053
+ listAdmins(): Promise<string[]>;
1054
+ listSuperAdmins(): Promise<string[]>;
1009
1055
  permissions(): Promise<{
1010
1056
  policyType: _xmtp_wasm_bindings.GroupPermissionsOptions;
1011
1057
  policySet: {
@@ -1022,7 +1068,6 @@ declare class Conversation {
1022
1068
  updatePermission(permissionType: PermissionUpdateType, policy: PermissionPolicy, metadataField?: MetadataField): Promise<undefined>;
1023
1069
  isAdmin(inboxId: string): Promise<boolean>;
1024
1070
  isSuperAdmin(inboxId: string): Promise<boolean>;
1025
- sync(): Promise<void>;
1026
1071
  addMembers(accountAddresses: string[]): Promise<undefined>;
1027
1072
  addMembersByInboxId(inboxIds: string[]): Promise<undefined>;
1028
1073
  removeMembers(accountAddresses: string[]): Promise<undefined>;
@@ -1031,18 +1076,6 @@ declare class Conversation {
1031
1076
  removeAdmin(inboxId: string): Promise<undefined>;
1032
1077
  addSuperAdmin(inboxId: string): Promise<undefined>;
1033
1078
  removeSuperAdmin(inboxId: string): Promise<undefined>;
1034
- publishMessages(): Promise<undefined>;
1035
- sendOptimistic(content: any, contentType?: ContentTypeId$1): Promise<string>;
1036
- send(content: any, contentType?: ContentTypeId$1): Promise<string>;
1037
- messages(options?: SafeListMessagesOptions): Promise<DecodedMessage[]>;
1038
- consentState(): Promise<ConsentState>;
1039
- updateConsentState(state: ConsentState): Promise<undefined>;
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>>;
1046
1079
  }
1047
1080
 
1048
1081
  declare class Conversations {
@@ -1050,23 +1083,25 @@ declare class Conversations {
1050
1083
  constructor(client: Client);
1051
1084
  sync(): Promise<undefined>;
1052
1085
  syncAll(consentStates?: ConsentState[]): Promise<undefined>;
1053
- getConversationById(id: string): Promise<Conversation | undefined>;
1086
+ getConversationById(id: string): Promise<Dm | Group | undefined>;
1054
1087
  getMessageById(id: string): Promise<DecodedMessage | undefined>;
1055
- getDmByInboxId(inboxId: string): Promise<Conversation | undefined>;
1056
- list(options?: SafeListConversationsOptions): Promise<Conversation[]>;
1057
- listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Conversation[]>;
1058
- listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Conversation[]>;
1059
- newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): 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>;
1088
+ getDmByInboxId(inboxId: string): Promise<Dm | undefined>;
1089
+ list(options?: SafeListConversationsOptions): Promise<(Dm | Group)[]>;
1090
+ listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Group[]>;
1091
+ listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<Dm[]>;
1092
+ newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<Group>;
1093
+ newGroupByInboxIds(inboxIds: string[], options?: SafeCreateGroupOptions): Promise<Group>;
1094
+ newDm(accountAddress: string, options?: SafeCreateDmOptions): Promise<Dm>;
1095
+ newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions): Promise<Dm>;
1063
1096
  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>>;
1097
+ stream<T extends Group | Dm = Group | Dm>(callback?: StreamCallback<T>, conversationType?: ConversationType): Promise<AsyncStream<T>>;
1098
+ streamGroups(callback?: StreamCallback<Group>): Promise<AsyncStream<Group>>;
1099
+ streamDms(callback?: StreamCallback<Dm>): Promise<AsyncStream<Dm>>;
1067
1100
  streamAllMessages(callback?: StreamCallback<DecodedMessage>, conversationType?: ConversationType): Promise<AsyncStream<DecodedMessage>>;
1068
1101
  streamAllGroupMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
1069
1102
  streamAllDmMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
1103
+ streamConsent(callback?: StreamCallback<SafeConsent[]>): Promise<AsyncStream<SafeConsent[]>>;
1104
+ streamPreferences(callback?: StreamCallback<UserPreference[]>): Promise<AsyncStream<UserPreference[]>>;
1070
1105
  }
1071
1106
 
1072
1107
  type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
@@ -1096,8 +1131,80 @@ declare class Client extends ClientWorkerClass {
1096
1131
  get inboxId(): string | undefined;
1097
1132
  get installationId(): string | undefined;
1098
1133
  get installationIdBytes(): Uint8Array<ArrayBufferLike> | undefined;
1134
+ /**
1135
+ * WARNING: This function should be used with caution. It is only provided
1136
+ * for use in special cases where the provided workflows do not meet the
1137
+ * requirements of an application.
1138
+ *
1139
+ * It is highly recommended to use the `register` function instead.
1140
+ */
1141
+ unsafe_createInboxSignatureText(): Promise<string | undefined>;
1142
+ /**
1143
+ * WARNING: This function should be used with caution. It is only provided
1144
+ * for use in special cases where the provided workflows do not meet the
1145
+ * requirements of an application.
1146
+ *
1147
+ * It is highly recommended to use the `unsafe_addAccount` function instead.
1148
+ *
1149
+ * The `allowInboxReassign` parameter must be true or this function will
1150
+ * throw an error.
1151
+ */
1152
+ unsafe_addAccountSignatureText(newAccountAddress: string, allowInboxReassign?: boolean): Promise<string | undefined>;
1153
+ /**
1154
+ * WARNING: This function should be used with caution. It is only provided
1155
+ * for use in special cases where the provided workflows do not meet the
1156
+ * requirements of an application.
1157
+ *
1158
+ * It is highly recommended to use the `removeAccount` function instead.
1159
+ */
1160
+ unsafe_removeAccountSignatureText(accountAddress: string): Promise<string | undefined>;
1161
+ /**
1162
+ * WARNING: This function should be used with caution. It is only provided
1163
+ * for use in special cases where the provided workflows do not meet the
1164
+ * requirements of an application.
1165
+ *
1166
+ * It is highly recommended to use the `revokeAllOtherInstallations` function
1167
+ * instead.
1168
+ */
1169
+ unsafe_revokeAllOtherInstallationsSignatureText(): Promise<string | undefined>;
1170
+ /**
1171
+ * WARNING: This function should be used with caution. It is only provided
1172
+ * for use in special cases where the provided workflows do not meet the
1173
+ * requirements of an application.
1174
+ *
1175
+ * It is highly recommended to use the `revokeInstallations` function instead.
1176
+ */
1177
+ unsafe_revokeInstallationsSignatureText(installationIds: Uint8Array[]): Promise<string | undefined>;
1178
+ /**
1179
+ * WARNING: This function should be used with caution. It is only provided
1180
+ * for use in special cases where the provided workflows do not meet the
1181
+ * requirements of an application.
1182
+ *
1183
+ * It is highly recommended to use the `register`, `addAccount`,
1184
+ * `removeAccount`, `revokeAllOtherInstallations`, or `revokeInstallations`
1185
+ * functions instead.
1186
+ */
1187
+ unsafe_addSignature(signatureType: SignatureRequestType, signatureText: string, signer: Signer): Promise<void>;
1188
+ /**
1189
+ * WARNING: This function should be used with caution. It is only provided
1190
+ * for use in special cases where the provided workflows do not meet the
1191
+ * requirements of an application.
1192
+ *
1193
+ * It is highly recommended to use the `register`, `addAccount`,
1194
+ * `removeAccount`, `revokeAllOtherInstallations`, or `revokeInstallations`
1195
+ * functions instead.
1196
+ */
1197
+ unsafe_applySignatures(): Promise<undefined>;
1099
1198
  register(): Promise<undefined>;
1100
- addAccount(newAccountSigner: Signer): Promise<void>;
1199
+ /**
1200
+ * WARNING: This function should be used with caution. Adding a wallet already
1201
+ * associated with an inboxId will cause the wallet to lose access to
1202
+ * that inbox.
1203
+ *
1204
+ * The `allowInboxReassign` parameter must be true to reassign an inbox
1205
+ * already associated with a different account.
1206
+ */
1207
+ unsafe_addAccount(newAccountSigner: Signer, allowInboxReassign?: boolean): Promise<void>;
1101
1208
  removeAccount(accountAddress: string): Promise<void>;
1102
1209
  revokeAllOtherInstallations(): Promise<void>;
1103
1210
  revokeInstallations(installationIds: Uint8Array[]): Promise<void>;
@@ -1133,4 +1240,4 @@ declare class Utils extends UtilsWorkerClass {
1133
1240
  getInboxIdForAddress(address: string, env?: XmtpEnv): Promise<string | undefined>;
1134
1241
  }
1135
1242
 
1136
- 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 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, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateDmOptions, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafeMessageDisappearingSettings, toSafePermissionPolicySet };
1243
+ 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, Dm, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type GenericStreamEvent, Group, 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 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, 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,CreateDMOptions as u,Consent as p,GroupMember as g,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 M}from"uuid";import{ContentTypeId as I}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=M();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 I({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 I({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),E=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}),U=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,p=r.policyType,g=r.policySet;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:p,policySet:{addAdminPolicy:g.addAdminPolicy,addMemberPolicy:g.addMemberPolicy,removeAdminPolicy:g.removeAdminPolicy,removeMemberPolicy:g.removeMemberPolicy,updateGroupDescriptionPolicy:g.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:g.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:g.updateGroupNamePolicy,updateMessageDisappearingPolicy:g.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 p(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 g(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;#p;#g;#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.#p=e?.addedByInboxId??"",this.#g=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.#p}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.#g}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=M(),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=M(),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=M(),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)}}class se extends S{#w;#M;#I;#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.#I=new te(this);const a=[new e,new n,...r?.codecs??[]];this.#M=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 se(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);"SCW"===s.walletType?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={walletType:"EOA",getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await se.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.#M.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 ne=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class ie{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",ne),this.#t=t}sendMessage(e,t){const s=M();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",ne),this.#e.terminate()}}class re extends ie{#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 ae={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},oe={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{ae as ApiUrls,se as Client,ee as Conversation,te as Conversations,Z as DecodedMessage,oe as HistorySyncUrls,re 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,U as fromSafeListConversationsOptions,L as fromSafeListMessagesOptions,Y as fromSafeMessageDisappearingSettings,q as fromSafePermissionPolicySet,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,E as toSafeListConversationsOptions,B as toSafeListMessagesOptions,C as toSafeMessage,X as toSafeMessageDisappearingSettings,R 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 a,ListMessagesOptions as r,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,ContentType,ContentTypeId,ConversationListItem,ConversationType,CreateDMOptions,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,LogOptions,Message,MessageDisappearingSettings,MetadataField,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as M}from"uuid";import{ContentTypeId as I}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=M();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;#a;onReturn=void 0;constructor(){this.#a=[],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.#a.push(t))};next=()=>this.#a.length>0?Promise.resolve({done:!1,value:this.#a.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 I({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),f=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),k=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),P=e=>new I({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),D=e=>({type:x(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),G=e=>new a(f(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),N=e=>({type:k(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({type:P(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({content:N(D(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),B=e=>({contentTypes:e.contentTypes,deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),L=e=>new r(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction,e.contentTypes),E=e=>({consentStates:e.consentStates,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,limit:e.limit}),U=e=>new o(e.consentStates,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!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}),_=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),q=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),O=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===l.CustomPolicy?_(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),K=e=>({messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0}),j=e=>new u(e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),W=async e=>{const t=e.id,s=e.name,n=e.imageUrl,i=e.description,a=e.permissions,r=e.isActive,o=e.addedByInboxId,d=await e.metadata(),c=e.admins,l=e.superAdmins,u=e.createdAtNs,g=a.policyType,p=a.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:r,addedByInboxId:o,metadata:d,admins:c,superAdmins:l,createdAtNs:u}},F=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),$=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(F),recoveryAddress:e.recoveryAddress}),H=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),V=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{#r;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;encodedContent;senderInboxId;sentAtNs;constructor(e,t){switch(this.#r=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=P(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.#r.decodeContent(t,this.contentType)}}class ee{#r;#o;#d;#c;#l;#u;constructor(e,t,s){this.#r=e,this.#o=t,this.#g(s)}#g(e){this.#d=e?.isActive??void 0,this.#c=e?.addedByInboxId??"",this.#l=e?.metadata??void 0,this.#u=e?.createdAtNs??void 0}get id(){return this.#o}get isActive(){return this.#d}get addedByInboxId(){return this.#c}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.#l}async members(){return this.#r.sendMessage("getGroupMembers",{id:this.#o})}async sync(){const e=await this.#r.sendMessage("syncGroup",{id:this.#o});return this.#g(e),e}async publishMessages(){return this.#r.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.#r.encodeContent(e,t??s):this.#r.encodeContent(e,t);return this.#r.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.#r.encodeContent(e,t??s):this.#r.encodeContent(e,t);return this.#r.sendMessage("sendGroupMessage",{id:this.#o,content:n})}async messages(e){return(await this.#r.sendMessage("getGroupMessages",{id:this.#o,options:e})).map((e=>new Z(this.#r,e)))}async consentState(){return this.#r.sendMessage("getGroupConsentState",{id:this.#o})}async updateConsentState(e){return this.#r.sendMessage("updateGroupConsentState",{id:this.#o,state:e})}async messageDisappearingSettings(){return this.#r.sendMessage("getGroupMessageDisappearingSettings",{id:this.#o})}async updateMessageDisappearingSettings(e,t){return this.#r.sendMessage("updateGroupMessageDisappearingSettings",{id:this.#o,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#r.sendMessage("removeGroupMessageDisappearingSettings",{id:this.#o})}async isMessageDisappearingEnabled(){return this.#r.sendMessage("isGroupMessageDisappearingEnabled",{id:this.#o})}async stream(e){const t=M(),s=new A,n=this.#r.handleStreamMessage(t,((t,n)=>{if(t)return s.callback(t,void 0),void e?.(t,void 0);const i=n?new Z(this.#r,n):void 0;s.callback(null,i),e?.(null,i)}));return await this.#r.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:t}),n()},s}}class te extends ee{#r;#o;constructor(e,t,s){super(e,t,s),this.#r=e,this.#o=t}async peerInboxId(){return this.#r.sendMessage("getDmPeerInboxId",{id:this.#o})}}class se extends ee{#r;#o;#p;#h;#m;#y=[];#v=[];#g(e){this.#p=e?.name??"",this.#h=e?.imageUrl??"",this.#m=e?.description??"",this.#y=e?.admins??[],this.#v=e?.superAdmins??[]}constructor(e,t,s){super(e,t,s),this.#r=e,this.#o=t,this.#g(s)}async sync(){const e=await super.sync();return this.#g(e),e}get name(){return this.#p}async updateName(e){await this.#r.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#p=e}get imageUrl(){return this.#h}async updateImageUrl(e){await this.#r.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#h=e}get description(){return this.#m}async updateDescription(e){await this.#r.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#m=e}get admins(){return this.#y}get superAdmins(){return this.#v}async listAdmins(){const e=await this.#r.sendMessage("getGroupAdmins",{id:this.#o});return this.#y=e,e}async listSuperAdmins(){const e=await this.#r.sendMessage("getGroupSuperAdmins",{id:this.#o});return this.#v=e,e}async permissions(){return this.#r.sendMessage("getGroupPermissions",{id:this.#o})}async updatePermission(e,t,s){return this.#r.sendMessage("updateGroupPermissionPolicy",{id:this.#o,permissionType:e,policy:t,metadataField:s})}async isAdmin(e){return(await this.listAdmins()).includes(e)}async isSuperAdmin(e){return(await this.listSuperAdmins()).includes(e)}async addMembers(e){return this.#r.sendMessage("addGroupMembers",{id:this.#o,accountAddresses:e})}async addMembersByInboxId(e){return this.#r.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembers(e){return this.#r.sendMessage("removeGroupMembers",{id:this.#o,accountAddresses:e})}async removeMembersByInboxId(e){return this.#r.sendMessage("removeGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async addAdmin(e){return this.#r.sendMessage("addGroupAdmin",{id:this.#o,inboxId:e})}async removeAdmin(e){return this.#r.sendMessage("removeGroupAdmin",{id:this.#o,inboxId:e})}async addSuperAdmin(e){return this.#r.sendMessage("addGroupSuperAdmin",{id:this.#o,inboxId:e})}async removeSuperAdmin(e){return this.#r.sendMessage("removeGroupSuperAdmin",{id:this.#o,inboxId:e})}}class ne{#r;constructor(e){this.#r=e}async sync(){return this.#r.sendMessage("syncConversations",void 0)}async syncAll(e){return this.#r.sendMessage("syncAllConversations",{consentStates:e})}async getConversationById(e){const t=await this.#r.sendMessage("getConversationById",{id:e});if(t)return"group"===t.metadata.conversationType?new se(this.#r,t.id,t):new te(this.#r,t.id,t)}async getMessageById(e){const t=await this.#r.sendMessage("getMessageById",{id:e});return t?new Z(this.#r,t):void 0}async getDmByInboxId(e){const t=await this.#r.sendMessage("getDmByInboxId",{inboxId:e});return t?new te(this.#r,t.id,t):void 0}async list(e){return(await this.#r.sendMessage("getConversations",{options:e})).map((e=>"group"===e.metadata.conversationType?new se(this.#r,e.id,e):new te(this.#r,e.id,e)))}async listGroups(e){return(await this.#r.sendMessage("getGroups",{options:e})).map((e=>new se(this.#r,e.id,e)))}async listDms(e){return(await this.#r.sendMessage("getDms",{options:e})).map((e=>new te(this.#r,e.id,e)))}async newGroup(e,t){const s=await this.#r.sendMessage("newGroup",{accountAddresses:e,options:t});return new se(this.#r,s.id,s)}async newGroupByInboxIds(e,t){const s=await this.#r.sendMessage("newGroupByInboxIds",{inboxIds:e,options:t});return new se(this.#r,s.id,s)}async newDm(e,t){const s=await this.#r.sendMessage("newDm",{accountAddress:e,options:t});return new te(this.#r,s.id,s)}async newDmByInboxId(e,t){const s=await this.#r.sendMessage("newDmByInboxId",{inboxId:e,options:t});return new te(this.#r,s.id,s)}async getHmacKeys(){return this.#r.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=M(),n=new A,i=this.#r.handleStreamMessage(s,((t,s)=>{if(t)return n.callback(t,void 0),void e?.(t,void 0);let i;s&&(i="group"===s.metadata.conversationType?new se(this.#r,s.id,s):new te(this.#r,s.id,s)),n.callback(null,i),e?.(null,i)}));return await this.#r.sendMessage("streamAllGroups",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#r.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=M(),n=new A,i=this.#r.handleStreamMessage(s,((t,s)=>{if(t)return n.callback(t,void 0),void e?.(t,void 0);const i=s?new Z(this.#r,s):void 0;n.callback(null,i),e?.(null,i)}));return await this.#r.sendMessage("streamAllMessages",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:s}),i()},n}async streamAllGroupMessages(e){return this.streamAllMessages(e,v.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,v.Dm)}async streamConsent(e){const t=M(),s=new A,n=this.#r.handleStreamMessage(t,((t,n)=>{s.callback(t,n??void 0),e?.(t,n??void 0)}));return await this.#r.sendMessage("streamConsent",{streamId:t}),s.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:t}),n()},s}async streamPreferences(e){const t=M(),s=new A,n=this.#r.handleStreamMessage(t,((t,n)=>{s.callback(t,n??void 0),e?.(t,n??void 0)}));return await this.#r.sendMessage("streamPreferences",{streamId:t}),s.onReturn=()=>{this.#r.sendMessage("endStream",{streamId:t}),n()},s}}class ie extends S{#w;#M;#I;#b;#S;#A;#x;#f=!1;#k;options;constructor(t,s,i,a){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==a?.loggingLevel&&"off"!==a.loggingLevel),this.#w=s,this.options=a,this.#b=i,this.#k=t,this.#I=new ne(this);const r=[new e,new n,...a?.codecs??[]];this.#M=new Map(r.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.#f=!0}static async create(e,t,s){const n=await e.getAddress(),i=new ie(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#f}get inboxId(){return this.#S}get installationId(){return this.#A}get installationIdBytes(){return this.#x}async unsafe_createInboxSignatureText(){return this.sendMessage("createInboxSignatureText",void 0)}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new Error("Unable to create add account signature text, `allowInboxReassign` must be true");return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async unsafe_removeAccountSignatureText(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async unsafe_revokeInstallationsSignatureText(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async unsafe_addSignature(e,t,s){const n=await s.signMessage(t);"SCW"===s.walletType?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber?.()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async unsafe_applySignatures(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.unsafe_createInboxSignatureText();if(e)return await this.unsafe_addSignature(w.CreateInbox,e,this.#k),this.sendMessage("registerIdentity",void 0)}async unsafe_addAccount(e,t=!1){const s=await this.findInboxIdByAddress(await e.getAddress());if(s&&!t)throw new Error(`Signer address already associated with inbox ${s}`);const n=await this.unsafe_addAccountSignatureText(await e.getAddress(),!0);if(!n)throw new Error("Unable to generate add account signature text");await this.unsafe_addSignature(w.AddWallet,n,e),await this.unsafe_applySignatures()}async removeAccount(e){const t=await this.unsafe_removeAccountSignatureText(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.unsafe_addSignature(w.RevokeWallet,t,this.#k),await this.unsafe_applySignatures()}async revokeAllOtherInstallations(){const e=await this.unsafe_revokeAllOtherInstallationsSignatureText();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.unsafe_addSignature(w.RevokeInstallations,e,this.#k),await this.unsafe_applySignatures()}async revokeInstallations(e){const t=await this.unsafe_revokeInstallationsSignatureText(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.unsafe_addSignature(w.RevokeInstallations,t,this.#k),await this.unsafe_applySignatures()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}static async canMessage(e,t){const s={walletType:"EOA",getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await ie.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.#M.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 ae=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",ae),this.#t=t}sendMessage(e,t){const s=M();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",ae),this.#e.terminate()}}class oe 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 de={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},ce={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{de as ApiUrls,ie as Client,ee as Conversation,ne as Conversations,Z as DecodedMessage,te as Dm,se as Group,ce as HistorySyncUrls,oe as Utils,f as fromContentTypeId,G as fromEncodedContent,V as fromSafeConsent,P as fromSafeContentTypeId,j as fromSafeCreateDmOptions,O as fromSafeCreateGroupOptions,T as fromSafeEncodedContent,J as fromSafeGroupMember,U as fromSafeListConversationsOptions,L as fromSafeListMessagesOptions,Y as fromSafeMessageDisappearingSettings,_ as fromSafePermissionPolicySet,x as toContentTypeId,D as toEncodedContent,H as toSafeConsent,k as toSafeContentTypeId,W as toSafeConversation,K as toSafeCreateDmOptions,q as toSafeCreateGroupOptions,N as toSafeEncodedContent,z as toSafeGroupMember,Q as toSafeHmacKey,$ as toSafeInboxState,F as toSafeInstallation,E as toSafeListConversationsOptions,B as toSafeListMessagesOptions,C as toSafeMessage,X as toSafeMessageDisappearingSettings,R as toSafePermissionPolicySet};
2
2
  //# sourceMappingURL=index.js.map