@xmtp/browser-sdk 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/ClientWorkerClass.ts","../src/utils/conversions.ts","../src/DecodedMessage.ts","../src/Conversation.ts","../src/utils/date.ts","../src/Conversations.ts","../src/utils/signer.ts","../src/Client.ts","../src/UtilsWorkerClass.ts","../src/Utils.ts","../src/constants.ts"],"sourcesContent":["import { v4 } from \"uuid\";\nimport type {\n ClientEventsActions,\n ClientEventsErrorData,\n ClientEventsResult,\n ClientEventsWorkerMessageData,\n ClientSendMessageData,\n} from \"@/types\";\n\nconst handleError = (event: ErrorEvent) => {\n console.error(`Worker error on line ${event.lineno} in \"${event.filename}\"`);\n console.error(event.message);\n};\n\nexport class ClientWorkerClass {\n #worker: Worker;\n\n #enableLogging: boolean;\n\n #promises = new Map<\n string,\n { resolve: (value: any) => void; reject: (reason?: any) => void }\n >();\n\n constructor(worker: Worker, enableLogging: boolean) {\n this.#worker = worker;\n this.#worker.addEventListener(\"message\", this.handleMessage);\n this.#worker.addEventListener(\"error\", handleError);\n this.#enableLogging = enableLogging;\n }\n\n sendMessage<A extends ClientEventsActions>(\n action: A,\n data: ClientSendMessageData<A>,\n ) {\n const promiseId = v4();\n this.#worker.postMessage({\n action,\n id: promiseId,\n data,\n });\n const promise = new Promise<ClientEventsResult<A>>((resolve, reject) => {\n this.#promises.set(promiseId, { resolve, reject });\n });\n return promise;\n }\n\n handleMessage = (\n event: MessageEvent<ClientEventsWorkerMessageData | ClientEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (this.#enableLogging) {\n console.log(\"client received event data\", eventData);\n }\n const promise = this.#promises.get(eventData.id);\n if (promise) {\n this.#promises.delete(eventData.id);\n if (\"error\" in eventData) {\n promise.reject(new Error(eventData.error));\n } else {\n promise.resolve(eventData.result);\n }\n }\n };\n\n close() {\n this.#worker.removeEventListener(\"message\", this.handleMessage);\n this.#worker.removeEventListener(\"error\", handleError);\n this.#worker.terminate();\n }\n}\n","import {\n ContentTypeId,\n type EncodedContent,\n} from \"@xmtp/content-type-primitives\";\nimport {\n Consent,\n CreateGroupOptions,\n GroupMember,\n GroupPermissionsOptions,\n ListConversationsOptions,\n ListMessagesOptions,\n PermissionPolicySet,\n ContentTypeId as WasmContentTypeId,\n EncodedContent as WasmEncodedContent,\n type ConsentEntityType,\n type ConsentState,\n type ConversationType,\n type DeliveryStatus,\n type GroupMembershipState,\n type GroupMessageKind,\n type HmacKey,\n type InboxState,\n type Installation,\n type Message,\n type PermissionLevel,\n type PermissionPolicy,\n type SortDirection,\n} from \"@xmtp/wasm-bindings\";\nimport type { WorkerConversation } from \"@/WorkerConversation\";\n\nexport const toContentTypeId = (\n contentTypeId: WasmContentTypeId,\n): ContentTypeId =>\n new ContentTypeId({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n });\n\nexport const fromContentTypeId = (\n contentTypeId: ContentTypeId,\n): WasmContentTypeId =>\n new WasmContentTypeId(\n contentTypeId.authorityId,\n contentTypeId.typeId,\n contentTypeId.versionMajor,\n contentTypeId.versionMinor,\n );\n\nexport type SafeContentTypeId = {\n authorityId: string;\n typeId: string;\n versionMajor: number;\n versionMinor: number;\n};\n\nexport const toSafeContentTypeId = (\n contentTypeId: ContentTypeId,\n): SafeContentTypeId => ({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n});\n\nexport const fromSafeContentTypeId = (\n contentTypeId: SafeContentTypeId,\n): ContentTypeId =>\n new ContentTypeId({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n });\n\nexport const toEncodedContent = (\n content: WasmEncodedContent,\n): EncodedContent => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n type: toContentTypeId(content.type!),\n parameters: Object.fromEntries(content.parameters as Map<string, string>),\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport const fromEncodedContent = (\n content: EncodedContent,\n): WasmEncodedContent =>\n new WasmEncodedContent(\n fromContentTypeId(content.type),\n new Map(Object.entries(content.parameters)),\n content.fallback,\n content.compression,\n content.content,\n );\n\nexport type SafeEncodedContent = {\n type: SafeContentTypeId;\n parameters: Record<string, string>;\n fallback?: string;\n compression?: number;\n content: Uint8Array;\n};\n\nexport const toSafeEncodedContent = (\n content: EncodedContent,\n): SafeEncodedContent => ({\n type: toSafeContentTypeId(content.type),\n parameters: content.parameters,\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport const fromSafeEncodedContent = (\n content: SafeEncodedContent,\n): EncodedContent => ({\n type: fromSafeContentTypeId(content.type),\n parameters: content.parameters,\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport type SafeMessage = {\n content: SafeEncodedContent;\n convoId: string;\n deliveryStatus: DeliveryStatus;\n id: string;\n kind: GroupMessageKind;\n senderInboxId: string;\n sentAtNs: bigint;\n};\n\nexport const toSafeMessage = (message: Message): SafeMessage => ({\n content: toSafeEncodedContent(toEncodedContent(message.content)),\n convoId: message.convoId,\n deliveryStatus: message.deliveryStatus,\n id: message.id,\n kind: message.kind,\n senderInboxId: message.senderInboxId,\n sentAtNs: message.sentAtNs,\n});\n\nexport type SafeListMessagesOptions = {\n deliveryStatus?: DeliveryStatus;\n direction?: SortDirection;\n limit?: bigint;\n sentAfterNs?: bigint;\n sentBeforeNs?: bigint;\n};\n\nexport const toSafeListMessagesOptions = (\n options: ListMessagesOptions,\n): SafeListMessagesOptions => ({\n deliveryStatus: options.deliveryStatus,\n direction: options.direction,\n limit: options.limit,\n sentAfterNs: options.sentAfterNs,\n sentBeforeNs: options.sentBeforeNs,\n});\n\nexport const fromSafeListMessagesOptions = (\n options: SafeListMessagesOptions,\n): ListMessagesOptions =>\n new ListMessagesOptions(\n options.sentBeforeNs,\n options.sentAfterNs,\n options.limit,\n options.deliveryStatus,\n options.direction,\n );\n\nexport type SafeListConversationsOptions = {\n allowedStates?: GroupMembershipState[];\n conversationType?: ConversationType;\n createdAfterNs?: bigint;\n createdBeforeNs?: bigint;\n limit?: bigint;\n};\n\nexport const toSafeListConversationsOptions = (\n options: ListConversationsOptions,\n): SafeListConversationsOptions => ({\n allowedStates: options.allowedStates,\n conversationType: options.conversationType,\n createdAfterNs: options.createdAfterNs,\n createdBeforeNs: options.createdBeforeNs,\n limit: options.limit,\n});\n\nexport const fromSafeListConversationsOptions = (\n options: SafeListConversationsOptions,\n): ListConversationsOptions =>\n new ListConversationsOptions(\n options.allowedStates,\n options.conversationType,\n options.createdAfterNs,\n options.createdBeforeNs,\n options.limit,\n );\n\nexport type SafePermissionPolicySet = {\n addAdminPolicy: PermissionPolicy;\n addMemberPolicy: PermissionPolicy;\n removeAdminPolicy: PermissionPolicy;\n removeMemberPolicy: PermissionPolicy;\n updateGroupDescriptionPolicy: PermissionPolicy;\n updateGroupImageUrlSquarePolicy: PermissionPolicy;\n updateGroupNamePolicy: PermissionPolicy;\n updateGroupPinnedFrameUrlPolicy: PermissionPolicy;\n updateMessageExpirationPolicy: PermissionPolicy;\n};\n\nexport const toSafePermissionPolicySet = (\n policySet: PermissionPolicySet,\n): SafePermissionPolicySet => ({\n addAdminPolicy: policySet.addAdminPolicy,\n addMemberPolicy: policySet.addMemberPolicy,\n removeAdminPolicy: policySet.removeAdminPolicy,\n removeMemberPolicy: policySet.removeMemberPolicy,\n updateGroupDescriptionPolicy: policySet.updateGroupDescriptionPolicy,\n updateGroupImageUrlSquarePolicy: policySet.updateGroupImageUrlSquarePolicy,\n updateGroupNamePolicy: policySet.updateGroupNamePolicy,\n updateGroupPinnedFrameUrlPolicy: policySet.updateGroupPinnedFrameUrlPolicy,\n updateMessageExpirationPolicy: policySet.updateMessageExpirationPolicy,\n});\n\nexport const fromSafePermissionPolicySet = (\n policySet: SafePermissionPolicySet,\n): PermissionPolicySet =>\n new PermissionPolicySet(\n policySet.addMemberPolicy,\n policySet.removeMemberPolicy,\n policySet.addAdminPolicy,\n policySet.removeAdminPolicy,\n policySet.updateGroupNamePolicy,\n policySet.updateGroupDescriptionPolicy,\n policySet.updateGroupImageUrlSquarePolicy,\n policySet.updateGroupPinnedFrameUrlPolicy,\n policySet.updateMessageExpirationPolicy,\n );\n\nexport type SafeCreateGroupOptions = {\n customPermissionPolicySet?: SafePermissionPolicySet;\n description?: string;\n imageUrlSquare?: string;\n name?: string;\n permissions?: GroupPermissionsOptions;\n pinnedFrameUrl?: string;\n};\n\nexport const toSafeCreateGroupOptions = (\n options: CreateGroupOptions,\n): SafeCreateGroupOptions => ({\n description: options.groupDescription,\n imageUrlSquare: options.groupImageUrlSquare,\n name: options.groupName,\n pinnedFrameUrl: options.groupPinnedFrameUrl,\n permissions: options.permissions,\n customPermissionPolicySet: options.customPermissionPolicySet,\n});\n\nexport const fromSafeCreateGroupOptions = (\n options: SafeCreateGroupOptions,\n): CreateGroupOptions =>\n new CreateGroupOptions(\n options.permissions,\n options.name,\n options.imageUrlSquare,\n options.description,\n options.pinnedFrameUrl,\n // only include custom policy set if permissions are set to CustomPolicy\n options.customPermissionPolicySet &&\n options.permissions === GroupPermissionsOptions.CustomPolicy\n ? fromSafePermissionPolicySet(options.customPermissionPolicySet)\n : undefined,\n );\n\nexport type SafeConversation = {\n id: string;\n name: string;\n imageUrl: string;\n description: string;\n pinnedFrameUrl: string;\n permissions: {\n policyType: GroupPermissionsOptions;\n policySet: {\n addAdminPolicy: PermissionPolicy;\n addMemberPolicy: PermissionPolicy;\n removeAdminPolicy: PermissionPolicy;\n removeMemberPolicy: PermissionPolicy;\n updateGroupDescriptionPolicy: PermissionPolicy;\n updateGroupImageUrlSquarePolicy: PermissionPolicy;\n updateGroupNamePolicy: PermissionPolicy;\n updateGroupPinnedFrameUrlPolicy: PermissionPolicy;\n updateMessageExpirationPolicy: PermissionPolicy;\n };\n };\n isActive: boolean;\n addedByInboxId: string;\n metadata: {\n creatorInboxId: string;\n conversationType: string;\n };\n admins: string[];\n superAdmins: string[];\n createdAtNs: bigint;\n};\n\nexport const toSafeConversation = async (\n conversation: WorkerConversation,\n): Promise<SafeConversation> => {\n const id = conversation.id;\n const name = conversation.name;\n const imageUrl = conversation.imageUrl;\n const description = conversation.description;\n const pinnedFrameUrl = conversation.pinnedFrameUrl;\n const permissions = conversation.permissions;\n const isActive = conversation.isActive;\n const addedByInboxId = conversation.addedByInboxId;\n const metadata = await conversation.metadata();\n const admins = conversation.admins;\n const superAdmins = conversation.superAdmins;\n const createdAtNs = conversation.createdAtNs;\n const policyType = permissions.policyType;\n const policySet = permissions.policySet;\n return {\n id,\n name,\n imageUrl,\n description,\n pinnedFrameUrl,\n permissions: {\n policyType,\n policySet: {\n addAdminPolicy: policySet.addAdminPolicy,\n addMemberPolicy: policySet.addMemberPolicy,\n removeAdminPolicy: policySet.removeAdminPolicy,\n removeMemberPolicy: policySet.removeMemberPolicy,\n updateGroupDescriptionPolicy: policySet.updateGroupDescriptionPolicy,\n updateGroupImageUrlSquarePolicy:\n policySet.updateGroupImageUrlSquarePolicy,\n updateGroupNamePolicy: policySet.updateGroupNamePolicy,\n updateGroupPinnedFrameUrlPolicy:\n policySet.updateGroupPinnedFrameUrlPolicy,\n updateMessageExpirationPolicy: policySet.updateMessageExpirationPolicy,\n },\n },\n isActive,\n addedByInboxId,\n metadata,\n admins,\n superAdmins,\n createdAtNs,\n };\n};\n\nexport type SafeInstallation = {\n bytes: Uint8Array;\n clientTimestampNs?: bigint;\n id: string;\n};\n\nexport const toSafeInstallation = (\n installation: Installation,\n): SafeInstallation => ({\n bytes: installation.bytes,\n clientTimestampNs: installation.clientTimestampNs,\n id: installation.id,\n});\n\nexport type SafeInboxState = {\n accountAddresses: string[];\n inboxId: string;\n installations: SafeInstallation[];\n recoveryAddress: string;\n};\n\nexport const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({\n accountAddresses: inboxState.accountAddresses,\n inboxId: inboxState.inboxId,\n installations: inboxState.installations.map(toSafeInstallation),\n recoveryAddress: inboxState.recoveryAddress,\n});\n\nexport type SafeConsent = {\n entity: string;\n entityType: ConsentEntityType;\n state: ConsentState;\n};\n\nexport const toSafeConsent = (consent: Consent): SafeConsent => ({\n entity: consent.entity,\n entityType: consent.entityType,\n state: consent.state,\n});\n\nexport const fromSafeConsent = (consent: SafeConsent): Consent =>\n new Consent(consent.entityType, consent.state, consent.entity);\n\nexport type SafeGroupMember = {\n accountAddresses: string[];\n consentState: ConsentState;\n inboxId: string;\n installationIds: string[];\n permissionLevel: PermissionLevel;\n};\n\nexport const toSafeGroupMember = (member: GroupMember): SafeGroupMember => ({\n accountAddresses: member.accountAddresses,\n consentState: member.consentState,\n inboxId: member.inboxId,\n installationIds: member.installationIds,\n permissionLevel: member.permissionLevel,\n});\n\nexport const fromSafeGroupMember = (member: SafeGroupMember): GroupMember =>\n new GroupMember(\n member.inboxId,\n member.accountAddresses,\n member.installationIds,\n member.permissionLevel,\n member.consentState,\n );\n\nexport type SafeHmacKey = {\n key: Uint8Array;\n epoch: bigint;\n};\n\nexport const toSafeHmacKey = (hmacKey: HmacKey): SafeHmacKey => ({\n key: hmacKey.key,\n epoch: hmacKey.epoch,\n});\n\nexport type HmacKeys = Map<string, HmacKey[]>;\nexport type SafeHmacKeys = Record<string, SafeHmacKey[]>;\n","import type { ContentTypeId } from \"@xmtp/content-type-primitives\";\nimport { DeliveryStatus, GroupMessageKind } from \"@xmtp/wasm-bindings\";\nimport type { Client } from \"@/Client\";\nimport { fromSafeContentTypeId, type SafeMessage } from \"@/utils/conversions\";\n\nexport type MessageKind = \"application\" | \"membership_change\";\nexport type MessageDeliveryStatus = \"unpublished\" | \"published\" | \"failed\";\n\nexport class DecodedMessage {\n #client: Client;\n\n content: any;\n\n contentType: ContentTypeId;\n\n conversationId: string;\n\n deliveryStatus: MessageDeliveryStatus;\n\n fallback?: string;\n\n compression?: number;\n\n id: string;\n\n kind: MessageKind;\n\n parameters: Map<string, string>;\n\n encodedContent: SafeMessage[\"content\"];\n\n senderInboxId: string;\n\n sentAtNs: bigint;\n\n constructor(client: Client, message: SafeMessage) {\n this.#client = client;\n this.id = message.id;\n this.sentAtNs = message.sentAtNs;\n this.conversationId = message.convoId;\n this.senderInboxId = message.senderInboxId;\n this.encodedContent = message.content;\n\n switch (message.kind) {\n case GroupMessageKind.Application:\n this.kind = \"application\";\n break;\n case GroupMessageKind.MembershipChange:\n this.kind = \"membership_change\";\n break;\n // no default\n }\n\n switch (message.deliveryStatus) {\n case DeliveryStatus.Unpublished:\n this.deliveryStatus = \"unpublished\";\n break;\n case DeliveryStatus.Published:\n this.deliveryStatus = \"published\";\n break;\n case DeliveryStatus.Failed:\n this.deliveryStatus = \"failed\";\n break;\n // no default\n }\n\n this.contentType = fromSafeContentTypeId(message.content.type);\n this.parameters = new Map(Object.entries(message.content.parameters));\n this.fallback = message.content.fallback;\n this.compression = message.content.compression;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this.content = this.#client.decodeContent(message, this.contentType);\n }\n}\n","import type { ContentTypeId } from \"@xmtp/content-type-primitives\";\nimport { ContentTypeText } from \"@xmtp/content-type-text\";\nimport type {\n ConsentState,\n MetadataField,\n PermissionPolicy,\n PermissionUpdateType,\n} from \"@xmtp/wasm-bindings\";\nimport type { Client } from \"@/Client\";\nimport { DecodedMessage } from \"@/DecodedMessage\";\nimport type {\n SafeConversation,\n SafeListMessagesOptions,\n} from \"@/utils/conversions\";\nimport { nsToDate } from \"@/utils/date\";\n\nexport class Conversation {\n #client: Client;\n\n #id: string;\n\n #name?: SafeConversation[\"name\"];\n\n #imageUrl?: SafeConversation[\"imageUrl\"];\n\n #description?: SafeConversation[\"description\"];\n\n #pinnedFrameUrl?: SafeConversation[\"pinnedFrameUrl\"];\n\n #isActive?: SafeConversation[\"isActive\"];\n\n #addedByInboxId?: SafeConversation[\"addedByInboxId\"];\n\n #metadata?: SafeConversation[\"metadata\"];\n\n #createdAtNs?: SafeConversation[\"createdAtNs\"];\n\n #admins: SafeConversation[\"admins\"] = [];\n\n #superAdmins: SafeConversation[\"superAdmins\"] = [];\n\n constructor(client: Client, id: string, data?: SafeConversation) {\n this.#client = client;\n this.#id = id;\n this.#syncData(data);\n }\n\n #syncData(data?: SafeConversation) {\n this.#name = data?.name ?? \"\";\n this.#imageUrl = data?.imageUrl ?? \"\";\n this.#description = data?.description ?? \"\";\n this.#pinnedFrameUrl = data?.pinnedFrameUrl ?? \"\";\n this.#isActive = data?.isActive ?? undefined;\n this.#addedByInboxId = data?.addedByInboxId ?? \"\";\n this.#metadata = data?.metadata ?? undefined;\n this.#createdAtNs = data?.createdAtNs ?? undefined;\n this.#admins = data?.admins ?? [];\n this.#superAdmins = data?.superAdmins ?? [];\n }\n\n get id() {\n return this.#id;\n }\n\n get name() {\n return this.#name;\n }\n\n async updateName(name: string) {\n await this.#client.sendMessage(\"updateGroupName\", {\n id: this.#id,\n name,\n });\n this.#name = name;\n }\n\n get imageUrl() {\n return this.#imageUrl;\n }\n\n async updateImageUrl(imageUrl: string) {\n await this.#client.sendMessage(\"updateGroupImageUrlSquare\", {\n id: this.#id,\n imageUrl,\n });\n this.#imageUrl = imageUrl;\n }\n\n get description() {\n return this.#description;\n }\n\n async updateDescription(description: string) {\n await this.#client.sendMessage(\"updateGroupDescription\", {\n id: this.#id,\n description,\n });\n this.#description = description;\n }\n\n get pinnedFrameUrl() {\n return this.#pinnedFrameUrl;\n }\n\n async updatePinnedFrameUrl(pinnedFrameUrl: string) {\n await this.#client.sendMessage(\"updateGroupPinnedFrameUrl\", {\n id: this.#id,\n pinnedFrameUrl,\n });\n this.#pinnedFrameUrl = pinnedFrameUrl;\n }\n\n get isActive() {\n return this.#isActive;\n }\n\n get addedByInboxId() {\n return this.#addedByInboxId;\n }\n\n get createdAtNs() {\n return this.#createdAtNs;\n }\n\n get createdAt() {\n return this.#createdAtNs ? nsToDate(this.#createdAtNs) : undefined;\n }\n\n get metadata() {\n return this.#metadata;\n }\n\n async members() {\n return this.#client.sendMessage(\"getGroupMembers\", {\n id: this.#id,\n });\n }\n\n get admins() {\n return this.#admins;\n }\n\n get superAdmins() {\n return this.#superAdmins;\n }\n\n async syncAdmins() {\n const admins = await this.#client.sendMessage(\"getGroupAdmins\", {\n id: this.#id,\n });\n this.#admins = admins;\n }\n\n async syncSuperAdmins() {\n const superAdmins = await this.#client.sendMessage(\"getGroupSuperAdmins\", {\n id: this.#id,\n });\n this.#superAdmins = superAdmins;\n }\n\n async permissions() {\n return this.#client.sendMessage(\"getGroupPermissions\", {\n id: this.#id,\n });\n }\n\n async updatePermission(\n permissionType: PermissionUpdateType,\n policy: PermissionPolicy,\n metadataField?: MetadataField,\n ) {\n return this.#client.sendMessage(\"updateGroupPermissionPolicy\", {\n id: this.#id,\n permissionType,\n policy,\n metadataField,\n });\n }\n\n async isAdmin(inboxId: string) {\n await this.syncAdmins();\n return this.#admins.includes(inboxId);\n }\n\n async isSuperAdmin(inboxId: string) {\n await this.syncSuperAdmins();\n return this.#superAdmins.includes(inboxId);\n }\n\n async sync() {\n const data = await this.#client.sendMessage(\"syncGroup\", {\n id: this.#id,\n });\n this.#syncData(data);\n }\n\n async addMembers(accountAddresses: string[]) {\n return this.#client.sendMessage(\"addGroupMembers\", {\n id: this.#id,\n accountAddresses,\n });\n }\n\n async addMembersByInboxId(inboxIds: string[]) {\n return this.#client.sendMessage(\"addGroupMembersByInboxId\", {\n id: this.#id,\n inboxIds,\n });\n }\n\n async removeMembers(accountAddresses: string[]) {\n return this.#client.sendMessage(\"removeGroupMembers\", {\n id: this.#id,\n accountAddresses,\n });\n }\n\n async removeMembersByInboxId(inboxIds: string[]) {\n return this.#client.sendMessage(\"removeGroupMembersByInboxId\", {\n id: this.#id,\n inboxIds,\n });\n }\n\n async addAdmin(inboxId: string) {\n return this.#client.sendMessage(\"addGroupAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async removeAdmin(inboxId: string) {\n return this.#client.sendMessage(\"removeGroupAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async addSuperAdmin(inboxId: string) {\n return this.#client.sendMessage(\"addGroupSuperAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async removeSuperAdmin(inboxId: string) {\n return this.#client.sendMessage(\"removeGroupSuperAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async publishMessages() {\n return this.#client.sendMessage(\"publishGroupMessages\", {\n id: this.#id,\n });\n }\n\n async sendOptimistic(content: any, contentType?: ContentTypeId) {\n if (typeof content !== \"string\" && !contentType) {\n throw new Error(\n \"Content type is required when sending content other than text\",\n );\n }\n\n const safeEncodedContent =\n typeof content === \"string\"\n ? this.#client.encodeContent(content, contentType ?? ContentTypeText)\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#client.encodeContent(content, contentType!);\n\n return this.#client.sendMessage(\"sendOptimisticGroupMessage\", {\n id: this.#id,\n content: safeEncodedContent,\n });\n }\n\n async send(content: any, contentType?: ContentTypeId) {\n if (typeof content !== \"string\" && !contentType) {\n throw new Error(\n \"Content type is required when sending content other than text\",\n );\n }\n\n const safeEncodedContent =\n typeof content === \"string\"\n ? this.#client.encodeContent(content, contentType ?? ContentTypeText)\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#client.encodeContent(content, contentType!);\n\n return this.#client.sendMessage(\"sendGroupMessage\", {\n id: this.#id,\n content: safeEncodedContent,\n });\n }\n\n async messages(options?: SafeListMessagesOptions) {\n const messages = await this.#client.sendMessage(\"getGroupMessages\", {\n id: this.#id,\n options,\n });\n\n return messages.map((message) => new DecodedMessage(this.#client, message));\n }\n\n async consentState() {\n return this.#client.sendMessage(\"getGroupConsentState\", {\n id: this.#id,\n });\n }\n\n async updateConsentState(state: ConsentState) {\n return this.#client.sendMessage(\"updateGroupConsentState\", {\n id: this.#id,\n state,\n });\n }\n\n async dmPeerInboxId() {\n return this.#client.sendMessage(\"getDmPeerInboxId\", {\n id: this.#id,\n });\n }\n}\n","export function nsToDate(ns: bigint): Date {\n return new Date(Number(ns / 1_000_000n));\n}\n","import type { Client } from \"@/Client\";\nimport { Conversation } from \"@/Conversation\";\nimport { DecodedMessage } from \"@/DecodedMessage\";\nimport type {\n SafeCreateGroupOptions,\n SafeListConversationsOptions,\n} from \"@/utils/conversions\";\n\nexport class Conversations {\n #client: Client;\n\n constructor(client: Client) {\n this.#client = client;\n }\n\n async sync() {\n return this.#client.sendMessage(\"syncConversations\", undefined);\n }\n\n async syncAll() {\n return this.#client.sendMessage(\"syncAllConversations\", undefined);\n }\n\n async getConversationById(id: string) {\n const data = await this.#client.sendMessage(\"getConversationById\", {\n id,\n });\n return data ? new Conversation(this.#client, id, data) : undefined;\n }\n\n async getMessageById(id: string) {\n const data = await this.#client.sendMessage(\"getMessageById\", {\n id,\n });\n return data ? new DecodedMessage(this.#client, data) : undefined;\n }\n\n async getDmByInboxId(inboxId: string) {\n const data = await this.#client.sendMessage(\"getDmByInboxId\", {\n inboxId,\n });\n return data ? new Conversation(this.#client, data.id, data) : undefined;\n }\n\n async list(options?: SafeListConversationsOptions) {\n const conversations = await this.#client.sendMessage(\"getConversations\", {\n options,\n });\n\n return conversations.map(\n (conversation) =>\n new Conversation(this.#client, conversation.id, conversation),\n );\n }\n\n async listGroups(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const conversations = await this.#client.sendMessage(\"getGroups\", {\n options,\n });\n\n return conversations.map(\n (conversation) =>\n new Conversation(this.#client, conversation.id, conversation),\n );\n }\n\n async listDms(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const conversations = await this.#client.sendMessage(\"getDms\", {\n options,\n });\n\n return conversations.map(\n (conversation) =>\n new Conversation(this.#client, conversation.id, conversation),\n );\n }\n\n async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {\n const conversation = await this.#client.sendMessage(\"newGroup\", {\n accountAddresses,\n options,\n });\n\n return new Conversation(this.#client, conversation.id, conversation);\n }\n\n async newDm(accountAddress: string) {\n const conversation = await this.#client.sendMessage(\"newDm\", {\n accountAddress,\n });\n\n return new Conversation(this.#client, conversation.id, conversation);\n }\n\n async getHmacKeys() {\n return this.#client.sendMessage(\"getHmacKeys\", undefined);\n }\n}\n","export type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;\nexport type GetAddress = () => Promise<string> | string;\nexport type GetChainId = () => bigint;\nexport type GetBlockNumber = () => bigint;\n\nexport type Signer = {\n getAddress: GetAddress;\n signMessage: SignMessage;\n // these fields indicate that the signer is a smart contract wallet\n getBlockNumber?: GetBlockNumber;\n getChainId?: GetChainId;\n};\n\nexport type SmartContractSigner = Required<Signer>;\n\nexport const isSmartContractSigner = (\n signer: Signer,\n): signer is SmartContractSigner =>\n \"getBlockNumber\" in signer && \"getChainId\" in signer;\n","import {\n ContentTypeGroupUpdated,\n GroupUpdatedCodec,\n} from \"@xmtp/content-type-group-updated\";\nimport type {\n ContentCodec,\n ContentTypeId,\n} from \"@xmtp/content-type-primitives\";\nimport { TextCodec } from \"@xmtp/content-type-text\";\nimport {\n GroupMessageKind,\n SignatureRequestType,\n type ConsentEntityType,\n} from \"@xmtp/wasm-bindings\";\nimport { ClientWorkerClass } from \"@/ClientWorkerClass\";\nimport { Conversations } from \"@/Conversations\";\nimport type { ClientOptions, XmtpEnv } from \"@/types\";\nimport {\n fromSafeEncodedContent,\n toSafeEncodedContent,\n type SafeConsent,\n type SafeMessage,\n} from \"@/utils/conversions\";\nimport { isSmartContractSigner, type Signer } from \"@/utils/signer\";\n\nexport class Client extends ClientWorkerClass {\n #accountAddress: string;\n #codecs: Map<string, ContentCodec>;\n #conversations: Conversations;\n #encryptionKey: Uint8Array;\n #inboxId: string | undefined;\n #installationId: string | undefined;\n #installationIdBytes: Uint8Array | undefined;\n #isReady = false;\n #signer: Signer;\n options?: ClientOptions;\n\n constructor(\n signer: Signer,\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: ClientOptions,\n ) {\n const worker = new Worker(new URL(\"./workers/client\", import.meta.url), {\n type: \"module\",\n });\n super(\n worker,\n options?.loggingLevel !== undefined && options.loggingLevel !== \"off\",\n );\n this.#accountAddress = accountAddress;\n this.options = options;\n this.#encryptionKey = encryptionKey;\n this.#signer = signer;\n this.#conversations = new Conversations(this);\n const codecs = [\n new GroupUpdatedCodec(),\n new TextCodec(),\n ...(options?.codecs ?? []),\n ];\n this.#codecs = new Map(\n codecs.map((codec) => [codec.contentType.toString(), codec]),\n );\n }\n\n get accountAddress() {\n return this.#accountAddress;\n }\n\n async init() {\n const result = await this.sendMessage(\"init\", {\n address: this.accountAddress,\n encryptionKey: this.#encryptionKey,\n options: this.options,\n });\n this.#inboxId = result.inboxId;\n this.#installationId = result.installationId;\n this.#installationIdBytes = result.installationIdBytes;\n this.#isReady = true;\n }\n\n static async create(\n signer: Signer,\n encryptionKey: Uint8Array,\n options?: ClientOptions,\n ) {\n const address = await signer.getAddress();\n const client = new Client(signer, address, encryptionKey, options);\n\n await client.init();\n\n if (!options?.disableAutoRegister) {\n await client.register();\n }\n\n return client;\n }\n\n get isReady() {\n return this.#isReady;\n }\n\n get inboxId() {\n return this.#inboxId;\n }\n\n get installationId() {\n return this.#installationId;\n }\n\n get installationIdBytes() {\n return this.#installationIdBytes;\n }\n\n async #createInboxSignatureText() {\n return this.sendMessage(\"createInboxSignatureText\", undefined);\n }\n\n async #addAccountSignatureText(newAccountAddress: string) {\n return this.sendMessage(\"addAccountSignatureText\", {\n newAccountAddress,\n });\n }\n\n async #removeAccountSignatureText(accountAddress: string) {\n return this.sendMessage(\"removeAccountSignatureText\", { accountAddress });\n }\n\n async #revokeAllOtherInstallationsSignatureText() {\n return this.sendMessage(\n \"revokeAllOtherInstallationsSignatureText\",\n undefined,\n );\n }\n\n async #revokeInstallationsSignatureText(installationIds: Uint8Array[]) {\n return this.sendMessage(\"revokeInstallationsSignatureText\", {\n installationIds,\n });\n }\n\n async #addSignature(\n signatureType: SignatureRequestType,\n signatureText: string,\n signer: Signer,\n ) {\n const signature = await signer.signMessage(signatureText);\n\n if (isSmartContractSigner(signer)) {\n await this.sendMessage(\"addScwSignature\", {\n type: signatureType,\n bytes: signature,\n chainId: signer.getChainId(),\n blockNumber: signer.getBlockNumber(),\n });\n } else {\n await this.sendMessage(\"addSignature\", {\n type: signatureType,\n bytes: signature,\n });\n }\n }\n\n async #applySignatures() {\n return this.sendMessage(\"applySignatures\", undefined);\n }\n\n async register() {\n const signatureText = await this.#createInboxSignatureText();\n\n // if the signature text is not available, the client is already registered\n if (!signatureText) {\n return;\n }\n\n await this.#addSignature(\n SignatureRequestType.CreateInbox,\n signatureText,\n this.#signer,\n );\n\n return this.sendMessage(\"registerIdentity\", undefined);\n }\n\n async addAccount(newAccountSigner: Signer) {\n const signatureText = await this.#addAccountSignatureText(\n await newAccountSigner.getAddress(),\n );\n\n if (!signatureText) {\n throw new Error(\"Unable to generate add account signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.AddWallet,\n signatureText,\n newAccountSigner,\n );\n\n await this.#applySignatures();\n }\n\n async removeAccount(accountAddress: string) {\n const signatureText =\n await this.#removeAccountSignatureText(accountAddress);\n\n if (!signatureText) {\n throw new Error(\"Unable to generate remove account signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.RevokeWallet,\n signatureText,\n this.#signer,\n );\n\n await this.#applySignatures();\n }\n\n async revokeAllOtherInstallations() {\n const signatureText =\n await this.#revokeAllOtherInstallationsSignatureText();\n\n if (!signatureText) {\n throw new Error(\n \"Unable to generate revoke all other installations signature text\",\n );\n }\n\n await this.#addSignature(\n SignatureRequestType.RevokeInstallations,\n signatureText,\n this.#signer,\n );\n\n await this.#applySignatures();\n }\n\n async revokeInstallations(installationIds: Uint8Array[]) {\n const signatureText =\n await this.#revokeInstallationsSignatureText(installationIds);\n\n if (!signatureText) {\n throw new Error(\"Unable to generate revoke installations signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.RevokeInstallations,\n signatureText,\n this.#signer,\n );\n\n await this.#applySignatures();\n }\n\n async isRegistered() {\n return this.sendMessage(\"isRegistered\", undefined);\n }\n\n async canMessage(accountAddresses: string[]) {\n return this.sendMessage(\"canMessage\", { accountAddresses });\n }\n\n static async canMessage(accountAddresses: string[], env?: XmtpEnv) {\n const accountAddress = \"0x0000000000000000000000000000000000000000\";\n const signer: Signer = {\n getAddress: () => accountAddress,\n signMessage: () => new Uint8Array(),\n };\n const client = await Client.create(\n signer,\n window.crypto.getRandomValues(new Uint8Array(32)),\n {\n disableAutoRegister: true,\n env,\n },\n );\n return client.canMessage(accountAddresses);\n }\n\n async findInboxIdByAddress(address: string) {\n return this.sendMessage(\"findInboxIdByAddress\", { address });\n }\n\n async inboxState(refreshFromNetwork?: boolean) {\n return this.sendMessage(\"inboxState\", {\n refreshFromNetwork: refreshFromNetwork ?? false,\n });\n }\n\n async getLatestInboxState(inboxId: string) {\n return this.sendMessage(\"getLatestInboxState\", { inboxId });\n }\n\n async setConsentStates(records: SafeConsent[]) {\n return this.sendMessage(\"setConsentStates\", { records });\n }\n\n async getConsentState(entityType: ConsentEntityType, entity: string) {\n return this.sendMessage(\"getConsentState\", { entityType, entity });\n }\n\n get conversations() {\n return this.#conversations;\n }\n\n codecFor(contentType: ContentTypeId) {\n return this.#codecs.get(contentType.toString());\n }\n\n encodeContent(content: any, contentType: ContentTypeId) {\n const codec = this.codecFor(contentType);\n if (!codec) {\n throw new Error(\n `Codec not found for \"${contentType.toString()}\" content type`,\n );\n }\n const encoded = codec.encode(content, this);\n const fallback = codec.fallback(content);\n if (fallback) {\n encoded.fallback = fallback;\n }\n return toSafeEncodedContent(encoded);\n }\n\n decodeContent(message: SafeMessage, contentType: ContentTypeId) {\n const codec = this.codecFor(contentType);\n if (!codec) {\n throw new Error(\n `Codec not found for \"${contentType.toString()}\" content type`,\n );\n }\n\n // throw an error if there's an invalid group membership change message\n if (\n contentType.sameAs(ContentTypeGroupUpdated) &&\n message.kind !== GroupMessageKind.MembershipChange\n ) {\n throw new Error(\"Error decoding group membership change\");\n }\n\n const encodedContent = fromSafeEncodedContent(message.content);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return codec.decode(encodedContent, this);\n }\n\n signWithInstallationKey(signatureText: string) {\n return this.sendMessage(\"signWithInstallationKey\", { signatureText });\n }\n\n verifySignedWithInstallationKey(\n signatureText: string,\n signatureBytes: Uint8Array,\n ) {\n return this.sendMessage(\"verifySignedWithInstallationKey\", {\n signatureText,\n signatureBytes,\n });\n }\n\n verifySignedWithPublicKey(\n signatureText: string,\n signatureBytes: Uint8Array,\n publicKey: Uint8Array,\n ) {\n return this.sendMessage(\"verifySignedWithPublicKey\", {\n signatureText,\n signatureBytes,\n publicKey,\n });\n }\n}\n","import { v4 } from \"uuid\";\nimport type {\n UtilsEventsActions,\n UtilsEventsErrorData,\n UtilsEventsResult,\n UtilsEventsWorkerMessageData,\n UtilsSendMessageData,\n} from \"@/types\";\n\nconst handleError = (event: ErrorEvent) => {\n console.error(`Worker error on line ${event.lineno} in \"${event.filename}\"`);\n console.error(event.message);\n};\n\nexport class UtilsWorkerClass {\n #worker: Worker;\n\n #enableLogging: boolean;\n\n #promises = new Map<\n string,\n { resolve: (value: any) => void; reject: (reason?: any) => void }\n >();\n\n constructor(worker: Worker, enableLogging: boolean) {\n this.#worker = worker;\n this.#worker.addEventListener(\"message\", this.handleMessage);\n this.#worker.addEventListener(\"error\", handleError);\n this.#enableLogging = enableLogging;\n }\n\n sendMessage<A extends UtilsEventsActions>(\n action: A,\n data: UtilsSendMessageData<A>,\n ) {\n const promiseId = v4();\n this.#worker.postMessage({\n action,\n id: promiseId,\n data,\n });\n const promise = new Promise<UtilsEventsResult<A>>((resolve, reject) => {\n this.#promises.set(promiseId, { resolve, reject });\n });\n return promise;\n }\n\n handleMessage = (\n event: MessageEvent<UtilsEventsWorkerMessageData | UtilsEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (this.#enableLogging) {\n console.log(\"utils received event data\", eventData);\n }\n const promise = this.#promises.get(eventData.id);\n if (promise) {\n this.#promises.delete(eventData.id);\n if (\"error\" in eventData) {\n promise.reject(new Error(eventData.error));\n } else {\n promise.resolve(eventData.result);\n }\n }\n };\n\n close() {\n this.#worker.removeEventListener(\"message\", this.handleMessage);\n this.#worker.removeEventListener(\"error\", handleError);\n this.#worker.terminate();\n }\n}\n","import type { XmtpEnv } from \"@/types/options\";\nimport { UtilsWorkerClass } from \"@/UtilsWorkerClass\";\n\nexport class Utils extends UtilsWorkerClass {\n #enableLogging: boolean;\n constructor(enableLogging?: boolean) {\n const worker = new Worker(new URL(\"./workers/utils\", import.meta.url), {\n type: \"module\",\n });\n super(worker, enableLogging ?? false);\n this.#enableLogging = enableLogging ?? false;\n }\n\n async generateInboxId(address: string) {\n return this.sendMessage(\"generateInboxId\", {\n address,\n enableLogging: this.#enableLogging,\n });\n }\n\n async getInboxIdForAddress(address: string, env?: XmtpEnv) {\n return this.sendMessage(\"getInboxIdForAddress\", {\n address,\n env,\n enableLogging: this.#enableLogging,\n });\n }\n}\n","export const ApiUrls = {\n local: \"http://localhost:5555\",\n dev: \"https://dev.xmtp.network\",\n production: \"https://production.xmtp.network\",\n} as const;\n\nexport const HistorySyncUrls = {\n local: \"http://localhost:5558\",\n dev: \"https://message-history.dev.ephemera.network\",\n production: \"https://message-history.production.ephemera.network\",\n} as const;\n"],"names":["handleError","event","console","error","lineno","filename","message","ClientWorkerClass","worker","enableLogging","promises","Map","constructor","this","addEventListener","handleMessage","sendMessage","action","data","promiseId","v4","postMessage","id","Promise","resolve","reject","set","eventData","log","promise","get","delete","Error","result","close","removeEventListener","terminate","toContentTypeId","contentTypeId","ContentTypeId","authorityId","typeId","versionMajor","versionMinor","fromContentTypeId","WasmContentTypeId","toSafeContentTypeId","fromSafeContentTypeId","toEncodedContent","content","type","parameters","Object","fromEntries","fallback","compression","fromEncodedContent","WasmEncodedContent","entries","toSafeEncodedContent","fromSafeEncodedContent","toSafeMessage","convoId","deliveryStatus","kind","senderInboxId","sentAtNs","toSafeListMessagesOptions","options","direction","limit","sentAfterNs","sentBeforeNs","fromSafeListMessagesOptions","ListMessagesOptions","toSafeListConversationsOptions","allowedStates","conversationType","createdAfterNs","createdBeforeNs","fromSafeListConversationsOptions","ListConversationsOptions","toSafePermissionPolicySet","policySet","addAdminPolicy","addMemberPolicy","removeAdminPolicy","removeMemberPolicy","updateGroupDescriptionPolicy","updateGroupImageUrlSquarePolicy","updateGroupNamePolicy","updateGroupPinnedFrameUrlPolicy","updateMessageExpirationPolicy","fromSafePermissionPolicySet","PermissionPolicySet","toSafeCreateGroupOptions","description","groupDescription","imageUrlSquare","groupImageUrlSquare","name","groupName","pinnedFrameUrl","groupPinnedFrameUrl","permissions","customPermissionPolicySet","fromSafeCreateGroupOptions","CreateGroupOptions","GroupPermissionsOptions","CustomPolicy","undefined","toSafeConversation","async","conversation","imageUrl","isActive","addedByInboxId","metadata","admins","superAdmins","createdAtNs","policyType","toSafeInstallation","installation","bytes","clientTimestampNs","toSafeInboxState","inboxState","accountAddresses","inboxId","installations","map","recoveryAddress","toSafeConsent","consent","entity","entityType","state","fromSafeConsent","Consent","toSafeGroupMember","member","consentState","installationIds","permissionLevel","fromSafeGroupMember","GroupMember","toSafeHmacKey","hmacKey","key","epoch","DecodedMessage","client","contentType","conversationId","encodedContent","GroupMessageKind","Application","MembershipChange","DeliveryStatus","Unpublished","Published","Failed","decodeContent","Conversation","syncData","updateName","updateImageUrl","updateDescription","updatePinnedFrameUrl","createdAt","ns","Date","Number","members","syncAdmins","syncSuperAdmins","updatePermission","permissionType","policy","metadataField","isAdmin","includes","isSuperAdmin","sync","addMembers","addMembersByInboxId","inboxIds","removeMembers","removeMembersByInboxId","addAdmin","removeAdmin","addSuperAdmin","removeSuperAdmin","publishMessages","sendOptimistic","safeEncodedContent","encodeContent","ContentTypeText","send","messages","updateConsentState","dmPeerInboxId","Conversations","syncAll","getConversationById","getMessageById","getDmByInboxId","list","listGroups","listDms","newGroup","newDm","accountAddress","getHmacKeys","isSmartContractSigner","signer","Client","codecs","conversations","encryptionKey","installationId","installationIdBytes","isReady","super","Worker","URL","url","loggingLevel","GroupUpdatedCodec","TextCodec","codec","toString","init","address","create","getAddress","disableAutoRegister","register","createInboxSignatureText","addAccountSignatureText","newAccountAddress","removeAccountSignatureText","revokeAllOtherInstallationsSignatureText","revokeInstallationsSignatureText","addSignature","signatureType","signatureText","signature","signMessage","chainId","getChainId","blockNumber","getBlockNumber","applySignatures","SignatureRequestType","CreateInbox","addAccount","newAccountSigner","AddWallet","removeAccount","RevokeWallet","revokeAllOtherInstallations","RevokeInstallations","revokeInstallations","isRegistered","canMessage","env","Uint8Array","window","crypto","getRandomValues","findInboxIdByAddress","refreshFromNetwork","getLatestInboxState","setConsentStates","records","getConsentState","codecFor","encoded","encode","sameAs","ContentTypeGroupUpdated","decode","signWithInstallationKey","verifySignedWithInstallationKey","signatureBytes","verifySignedWithPublicKey","publicKey","UtilsWorkerClass","Utils","generateInboxId","getInboxIdForAddress","ApiUrls","local","dev","production","HistorySyncUrls"],"mappings":"mgCASA,MAAMA,EAAeC,IACnBC,QAAQC,MAAM,wBAAwBF,EAAMG,cAAcH,EAAMI,aAChEH,QAAQC,MAAMF,EAAMK,QAAQ,QAGjBC,EACXC,GAEAC,GAEAC,GAAY,IAAIC,IAKhB,WAAAC,CAAYJ,EAAgBC,GAC1BI,MAAKL,EAAUA,EACfK,MAAKL,EAAQM,iBAAiB,UAAWD,KAAKE,eAC9CF,MAAKL,EAAQM,iBAAiB,QAASd,GACvCa,MAAKJ,EAAiBA,EAGxB,WAAAO,CACEC,EACAC,GAEA,MAAMC,EAAYC,IAClBP,MAAKL,EAAQa,YAAY,CACvBJ,SACAK,GAAIH,EACJD,SAKF,OAHgB,IAAIK,SAA+B,CAACC,EAASC,KAC3DZ,MAAKH,EAAUgB,IAAIP,EAAW,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AM0B,EAAY1B,EAAMiB,KACpBL,MAAKJ,GACPP,QAAQ0B,IAAI,4BAA6BD,GAE3C,MAAME,EAAUhB,MAAKH,EAAUoB,IAAIH,EAAUL,IACzCO,IACFhB,MAAKH,EAAUqB,OAAOJ,EAAUL,IAC5B,UAAWK,EACbE,EAAQJ,OAAO,IAAIO,MAAML,EAAUxB,QAEnC0B,EAAQL,QAAQG,EAAUM,UAKhC,KAAAC,GACErB,MAAKL,EAAQ2B,oBAAoB,UAAWtB,KAAKE,eACjDF,MAAKL,EAAQ2B,oBAAoB,QAASnC,GAC1Ca,MAAKL,EAAQ4B,aCjEX,MAAO8P,UAAcD,EACzBxR,GACA,WAAAG,CAAYH,GAIVuN,MAHe,IAAIC,OAAO,IAAIC,IAAI,8BAA+BC,KAAM,CACrEjL,KAAM,WAEMzC,IAAiB,GAC/BI,MAAKJ,EAAiBA,IAAiB,EAGzC,qBAAM0R,CAAgBzD,GACpB,OAAO7N,KAAKG,YAAY,kBAAmB,CACzC0N,UACAjO,cAAeI,MAAKJ,IAIxB,0BAAM2R,CAAqB1D,EAAiBiC,GAC1C,OAAO9P,KAAKG,YAAY,uBAAwB,CAC9C0N,UACAiC,MACAlQ,cAAeI,MAAKJ,KCxBb,MAAA4R,EAAU,CACrBC,MAAO,wBACPC,IAAK,2BACLC,WAAY,mCAGDC,GAAkB,CAC7BH,MAAO,wBACPC,IAAK,+CACLC,WAAY"}
1
+ {"version":3,"file":"index.js","sources":["../src/ClientWorkerClass.ts","../src/AsyncStream.ts","../src/utils/conversions.ts","../src/DecodedMessage.ts","../src/Conversation.ts","../src/utils/date.ts","../src/Conversations.ts","../src/utils/signer.ts","../src/Client.ts","../src/UtilsWorkerClass.ts","../src/Utils.ts","../src/constants.ts"],"sourcesContent":["import { v4 } from \"uuid\";\nimport type {\n ClientEventsActions,\n ClientEventsErrorData,\n ClientEventsResult,\n ClientEventsWorkerMessageData,\n ClientSendMessageData,\n} from \"@/types\";\nimport type {\n ClientStreamEvents,\n ClientStreamEventsErrorData,\n} from \"@/types/clientStreamEvents\";\n\nconst handleError = (event: ErrorEvent) => {\n console.error(`Worker error on line ${event.lineno} in \"${event.filename}\"`);\n console.error(event.message);\n};\n\nexport class ClientWorkerClass {\n #worker: Worker;\n\n #enableLogging: boolean;\n\n #promises = new Map<\n string,\n { resolve: (value: any) => void; reject: (reason?: any) => void }\n >();\n\n constructor(worker: Worker, enableLogging: boolean) {\n this.#worker = worker;\n this.#worker.addEventListener(\"message\", this.handleMessage);\n this.#worker.addEventListener(\"error\", handleError);\n this.#enableLogging = enableLogging;\n }\n\n sendMessage<A extends ClientEventsActions>(\n action: A,\n data: ClientSendMessageData<A>,\n ) {\n const promiseId = v4();\n this.#worker.postMessage({\n action,\n id: promiseId,\n data,\n });\n const promise = new Promise<ClientEventsResult<A>>((resolve, reject) => {\n this.#promises.set(promiseId, { resolve, reject });\n });\n return promise;\n }\n\n handleMessage = (\n event: MessageEvent<ClientEventsWorkerMessageData | ClientEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (this.#enableLogging) {\n console.log(\"client received event data\", eventData);\n }\n const promise = this.#promises.get(eventData.id);\n if (promise) {\n this.#promises.delete(eventData.id);\n if (\"error\" in eventData) {\n promise.reject(new Error(eventData.error));\n } else {\n promise.resolve(eventData.result);\n }\n }\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters\n handleStreamMessage = <T extends ClientStreamEvents[\"result\"]>(\n streamId: string,\n callback: (error: Error | null, value: T | null) => void,\n ) => {\n const streamHandler = (\n event: MessageEvent<ClientStreamEvents | ClientStreamEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (eventData.streamId === streamId) {\n if (\"error\" in eventData) {\n callback(new Error(eventData.error), null);\n } else {\n callback(null, eventData.result as T);\n }\n }\n };\n this.#worker.addEventListener(\"message\", streamHandler);\n\n return () => {\n this.#worker.removeEventListener(\"message\", streamHandler);\n };\n };\n\n close() {\n this.#worker.removeEventListener(\"message\", this.handleMessage);\n this.#worker.removeEventListener(\"error\", handleError);\n this.#worker.terminate();\n }\n}\n","type ResolveValue<T> = {\n value: T | undefined;\n done: boolean;\n};\n\ntype ResolveNext<T> = (resolveValue: ResolveValue<T>) => void;\n\nexport type StreamCallback<T> = (\n err: Error | null,\n value: T | undefined,\n) => void | Promise<void>;\n\nexport class AsyncStream<T> {\n #done = false;\n #resolveNext: ResolveNext<T> | null;\n #queue: (T | undefined)[];\n\n onReturn: (() => void) | undefined = undefined;\n\n constructor() {\n this.#queue = [];\n this.#resolveNext = null;\n this.#done = false;\n }\n\n get isDone() {\n return this.#done;\n }\n\n callback: StreamCallback<T> = (error, value) => {\n if (error) {\n throw error;\n }\n\n if (this.#done) {\n return;\n }\n\n if (this.#resolveNext) {\n this.#resolveNext({\n done: false,\n value,\n });\n this.#resolveNext = null;\n } else {\n this.#queue.push(value);\n }\n };\n\n next = (): Promise<ResolveValue<T>> => {\n if (this.#queue.length > 0) {\n return Promise.resolve({\n done: false,\n value: this.#queue.shift(),\n });\n } else if (this.#done) {\n return Promise.resolve({\n done: true,\n value: undefined,\n });\n } else {\n return new Promise((resolve) => {\n this.#resolveNext = resolve;\n });\n }\n };\n\n return = (value: T | undefined) => {\n this.#done = true;\n this.onReturn?.();\n return Promise.resolve({\n done: true,\n value,\n });\n };\n\n [Symbol.asyncIterator]() {\n return this;\n }\n}\n","import {\n ContentTypeId,\n type EncodedContent,\n} from \"@xmtp/content-type-primitives\";\nimport {\n Consent,\n CreateGroupOptions,\n GroupMember,\n GroupPermissionsOptions,\n ListConversationsOptions,\n ListMessagesOptions,\n PermissionPolicySet,\n ContentTypeId as WasmContentTypeId,\n EncodedContent as WasmEncodedContent,\n type ConsentEntityType,\n type ConsentState,\n type ConversationType,\n type DeliveryStatus,\n type GroupMembershipState,\n type GroupMessageKind,\n type HmacKey,\n type InboxState,\n type Installation,\n type Message,\n type PermissionLevel,\n type PermissionPolicy,\n type SortDirection,\n} from \"@xmtp/wasm-bindings\";\nimport type { WorkerConversation } from \"@/WorkerConversation\";\n\nexport const toContentTypeId = (\n contentTypeId: WasmContentTypeId,\n): ContentTypeId =>\n new ContentTypeId({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n });\n\nexport const fromContentTypeId = (\n contentTypeId: ContentTypeId,\n): WasmContentTypeId =>\n new WasmContentTypeId(\n contentTypeId.authorityId,\n contentTypeId.typeId,\n contentTypeId.versionMajor,\n contentTypeId.versionMinor,\n );\n\nexport type SafeContentTypeId = {\n authorityId: string;\n typeId: string;\n versionMajor: number;\n versionMinor: number;\n};\n\nexport const toSafeContentTypeId = (\n contentTypeId: ContentTypeId,\n): SafeContentTypeId => ({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n});\n\nexport const fromSafeContentTypeId = (\n contentTypeId: SafeContentTypeId,\n): ContentTypeId =>\n new ContentTypeId({\n authorityId: contentTypeId.authorityId,\n typeId: contentTypeId.typeId,\n versionMajor: contentTypeId.versionMajor,\n versionMinor: contentTypeId.versionMinor,\n });\n\nexport const toEncodedContent = (\n content: WasmEncodedContent,\n): EncodedContent => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n type: toContentTypeId(content.type!),\n parameters: Object.fromEntries(content.parameters as Map<string, string>),\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport const fromEncodedContent = (\n content: EncodedContent,\n): WasmEncodedContent =>\n new WasmEncodedContent(\n fromContentTypeId(content.type),\n new Map(Object.entries(content.parameters)),\n content.fallback,\n content.compression,\n content.content,\n );\n\nexport type SafeEncodedContent = {\n type: SafeContentTypeId;\n parameters: Record<string, string>;\n fallback?: string;\n compression?: number;\n content: Uint8Array;\n};\n\nexport const toSafeEncodedContent = (\n content: EncodedContent,\n): SafeEncodedContent => ({\n type: toSafeContentTypeId(content.type),\n parameters: content.parameters,\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport const fromSafeEncodedContent = (\n content: SafeEncodedContent,\n): EncodedContent => ({\n type: fromSafeContentTypeId(content.type),\n parameters: content.parameters,\n fallback: content.fallback,\n compression: content.compression,\n content: content.content,\n});\n\nexport type SafeMessage = {\n content: SafeEncodedContent;\n convoId: string;\n deliveryStatus: DeliveryStatus;\n id: string;\n kind: GroupMessageKind;\n senderInboxId: string;\n sentAtNs: bigint;\n};\n\nexport const toSafeMessage = (message: Message): SafeMessage => ({\n content: toSafeEncodedContent(toEncodedContent(message.content)),\n convoId: message.convoId,\n deliveryStatus: message.deliveryStatus,\n id: message.id,\n kind: message.kind,\n senderInboxId: message.senderInboxId,\n sentAtNs: message.sentAtNs,\n});\n\nexport type SafeListMessagesOptions = {\n deliveryStatus?: DeliveryStatus;\n direction?: SortDirection;\n limit?: bigint;\n sentAfterNs?: bigint;\n sentBeforeNs?: bigint;\n};\n\nexport const toSafeListMessagesOptions = (\n options: ListMessagesOptions,\n): SafeListMessagesOptions => ({\n deliveryStatus: options.deliveryStatus,\n direction: options.direction,\n limit: options.limit,\n sentAfterNs: options.sentAfterNs,\n sentBeforeNs: options.sentBeforeNs,\n});\n\nexport const fromSafeListMessagesOptions = (\n options: SafeListMessagesOptions,\n): ListMessagesOptions =>\n new ListMessagesOptions(\n options.sentBeforeNs,\n options.sentAfterNs,\n options.limit,\n options.deliveryStatus,\n options.direction,\n );\n\nexport type SafeListConversationsOptions = {\n allowedStates?: GroupMembershipState[];\n conversationType?: ConversationType;\n createdAfterNs?: bigint;\n createdBeforeNs?: bigint;\n limit?: bigint;\n};\n\nexport const toSafeListConversationsOptions = (\n options: ListConversationsOptions,\n): SafeListConversationsOptions => ({\n allowedStates: options.allowedStates,\n conversationType: options.conversationType,\n createdAfterNs: options.createdAfterNs,\n createdBeforeNs: options.createdBeforeNs,\n limit: options.limit,\n});\n\nexport const fromSafeListConversationsOptions = (\n options: SafeListConversationsOptions,\n): ListConversationsOptions =>\n new ListConversationsOptions(\n options.allowedStates,\n options.conversationType,\n options.createdAfterNs,\n options.createdBeforeNs,\n options.limit,\n );\n\nexport type SafePermissionPolicySet = {\n addAdminPolicy: PermissionPolicy;\n addMemberPolicy: PermissionPolicy;\n removeAdminPolicy: PermissionPolicy;\n removeMemberPolicy: PermissionPolicy;\n updateGroupDescriptionPolicy: PermissionPolicy;\n updateGroupImageUrlSquarePolicy: PermissionPolicy;\n updateGroupNamePolicy: PermissionPolicy;\n updateMessageDisappearingPolicy: PermissionPolicy;\n};\n\nexport const toSafePermissionPolicySet = (\n policySet: PermissionPolicySet,\n): SafePermissionPolicySet => ({\n addAdminPolicy: policySet.addAdminPolicy,\n addMemberPolicy: policySet.addMemberPolicy,\n removeAdminPolicy: policySet.removeAdminPolicy,\n removeMemberPolicy: policySet.removeMemberPolicy,\n updateGroupDescriptionPolicy: policySet.updateGroupDescriptionPolicy,\n updateGroupImageUrlSquarePolicy: policySet.updateGroupImageUrlSquarePolicy,\n updateGroupNamePolicy: policySet.updateGroupNamePolicy,\n updateMessageDisappearingPolicy: policySet.updateMessageDisappearingPolicy,\n});\n\nexport const fromSafePermissionPolicySet = (\n policySet: SafePermissionPolicySet,\n): PermissionPolicySet =>\n new PermissionPolicySet(\n policySet.addMemberPolicy,\n policySet.removeMemberPolicy,\n policySet.addAdminPolicy,\n policySet.removeAdminPolicy,\n policySet.updateGroupNamePolicy,\n policySet.updateGroupDescriptionPolicy,\n policySet.updateGroupImageUrlSquarePolicy,\n policySet.updateMessageDisappearingPolicy,\n );\n\nexport type SafeCreateGroupOptions = {\n customPermissionPolicySet?: SafePermissionPolicySet;\n description?: string;\n imageUrlSquare?: string;\n name?: string;\n permissions?: GroupPermissionsOptions;\n};\n\nexport const toSafeCreateGroupOptions = (\n options: CreateGroupOptions,\n): SafeCreateGroupOptions => ({\n description: options.groupDescription,\n imageUrlSquare: options.groupImageUrlSquare,\n name: options.groupName,\n permissions: options.permissions,\n customPermissionPolicySet: options.customPermissionPolicySet,\n});\n\nexport const fromSafeCreateGroupOptions = (\n options: SafeCreateGroupOptions,\n): CreateGroupOptions =>\n new CreateGroupOptions(\n options.permissions,\n options.name,\n options.imageUrlSquare,\n options.description,\n // only include custom policy set if permissions are set to CustomPolicy\n options.customPermissionPolicySet &&\n options.permissions === GroupPermissionsOptions.CustomPolicy\n ? fromSafePermissionPolicySet(options.customPermissionPolicySet)\n : undefined,\n );\n\nexport type SafeConversation = {\n id: string;\n name: string;\n imageUrl: string;\n description: string;\n permissions: {\n policyType: GroupPermissionsOptions;\n policySet: {\n addAdminPolicy: PermissionPolicy;\n addMemberPolicy: PermissionPolicy;\n removeAdminPolicy: PermissionPolicy;\n removeMemberPolicy: PermissionPolicy;\n updateGroupDescriptionPolicy: PermissionPolicy;\n updateGroupImageUrlSquarePolicy: PermissionPolicy;\n updateGroupNamePolicy: PermissionPolicy;\n updateMessageDisappearingPolicy: PermissionPolicy;\n };\n };\n isActive: boolean;\n addedByInboxId: string;\n metadata: {\n creatorInboxId: string;\n conversationType: string;\n };\n admins: string[];\n superAdmins: string[];\n createdAtNs: bigint;\n};\n\nexport const toSafeConversation = async (\n conversation: WorkerConversation,\n): Promise<SafeConversation> => {\n const id = conversation.id;\n const name = conversation.name;\n const imageUrl = conversation.imageUrl;\n const description = conversation.description;\n const permissions = conversation.permissions;\n const isActive = conversation.isActive;\n const addedByInboxId = conversation.addedByInboxId;\n const metadata = await conversation.metadata();\n const admins = conversation.admins;\n const superAdmins = conversation.superAdmins;\n const createdAtNs = conversation.createdAtNs;\n const policyType = permissions.policyType;\n const policySet = permissions.policySet;\n return {\n id,\n name,\n imageUrl,\n description,\n permissions: {\n policyType,\n policySet: {\n addAdminPolicy: policySet.addAdminPolicy,\n addMemberPolicy: policySet.addMemberPolicy,\n removeAdminPolicy: policySet.removeAdminPolicy,\n removeMemberPolicy: policySet.removeMemberPolicy,\n updateGroupDescriptionPolicy: policySet.updateGroupDescriptionPolicy,\n updateGroupImageUrlSquarePolicy:\n policySet.updateGroupImageUrlSquarePolicy,\n updateGroupNamePolicy: policySet.updateGroupNamePolicy,\n updateMessageDisappearingPolicy:\n policySet.updateMessageDisappearingPolicy,\n },\n },\n isActive,\n addedByInboxId,\n metadata,\n admins,\n superAdmins,\n createdAtNs,\n };\n};\n\nexport type SafeInstallation = {\n bytes: Uint8Array;\n clientTimestampNs?: bigint;\n id: string;\n};\n\nexport const toSafeInstallation = (\n installation: Installation,\n): SafeInstallation => ({\n bytes: installation.bytes,\n clientTimestampNs: installation.clientTimestampNs,\n id: installation.id,\n});\n\nexport type SafeInboxState = {\n accountAddresses: string[];\n inboxId: string;\n installations: SafeInstallation[];\n recoveryAddress: string;\n};\n\nexport const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({\n accountAddresses: inboxState.accountAddresses,\n inboxId: inboxState.inboxId,\n installations: inboxState.installations.map(toSafeInstallation),\n recoveryAddress: inboxState.recoveryAddress,\n});\n\nexport type SafeConsent = {\n entity: string;\n entityType: ConsentEntityType;\n state: ConsentState;\n};\n\nexport const toSafeConsent = (consent: Consent): SafeConsent => ({\n entity: consent.entity,\n entityType: consent.entityType,\n state: consent.state,\n});\n\nexport const fromSafeConsent = (consent: SafeConsent): Consent =>\n new Consent(consent.entityType, consent.state, consent.entity);\n\nexport type SafeGroupMember = {\n accountAddresses: string[];\n consentState: ConsentState;\n inboxId: string;\n installationIds: string[];\n permissionLevel: PermissionLevel;\n};\n\nexport const toSafeGroupMember = (member: GroupMember): SafeGroupMember => ({\n accountAddresses: member.accountAddresses,\n consentState: member.consentState,\n inboxId: member.inboxId,\n installationIds: member.installationIds,\n permissionLevel: member.permissionLevel,\n});\n\nexport const fromSafeGroupMember = (member: SafeGroupMember): GroupMember =>\n new GroupMember(\n member.inboxId,\n member.accountAddresses,\n member.installationIds,\n member.permissionLevel,\n member.consentState,\n );\n\nexport type SafeHmacKey = {\n key: Uint8Array;\n epoch: bigint;\n};\n\nexport const toSafeHmacKey = (hmacKey: HmacKey): SafeHmacKey => ({\n key: hmacKey.key,\n epoch: hmacKey.epoch,\n});\n\nexport type HmacKeys = Map<string, HmacKey[]>;\nexport type SafeHmacKeys = Record<string, SafeHmacKey[]>;\n","import type { ContentTypeId } from \"@xmtp/content-type-primitives\";\nimport { DeliveryStatus, GroupMessageKind } from \"@xmtp/wasm-bindings\";\nimport type { Client } from \"@/Client\";\nimport { fromSafeContentTypeId, type SafeMessage } from \"@/utils/conversions\";\n\nexport type MessageKind = \"application\" | \"membership_change\";\nexport type MessageDeliveryStatus = \"unpublished\" | \"published\" | \"failed\";\n\nexport class DecodedMessage {\n #client: Client;\n\n content: any;\n\n contentType: ContentTypeId;\n\n conversationId: string;\n\n deliveryStatus: MessageDeliveryStatus;\n\n fallback?: string;\n\n compression?: number;\n\n id: string;\n\n kind: MessageKind;\n\n parameters: Map<string, string>;\n\n encodedContent: SafeMessage[\"content\"];\n\n senderInboxId: string;\n\n sentAtNs: bigint;\n\n constructor(client: Client, message: SafeMessage) {\n this.#client = client;\n this.id = message.id;\n this.sentAtNs = message.sentAtNs;\n this.conversationId = message.convoId;\n this.senderInboxId = message.senderInboxId;\n this.encodedContent = message.content;\n\n switch (message.kind) {\n case GroupMessageKind.Application:\n this.kind = \"application\";\n break;\n case GroupMessageKind.MembershipChange:\n this.kind = \"membership_change\";\n break;\n // no default\n }\n\n switch (message.deliveryStatus) {\n case DeliveryStatus.Unpublished:\n this.deliveryStatus = \"unpublished\";\n break;\n case DeliveryStatus.Published:\n this.deliveryStatus = \"published\";\n break;\n case DeliveryStatus.Failed:\n this.deliveryStatus = \"failed\";\n break;\n // no default\n }\n\n this.contentType = fromSafeContentTypeId(message.content.type);\n this.parameters = new Map(Object.entries(message.content.parameters));\n this.fallback = message.content.fallback;\n this.compression = message.content.compression;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this.content = this.#client.decodeContent(message, this.contentType);\n }\n}\n","import type { ContentTypeId } from \"@xmtp/content-type-primitives\";\nimport { ContentTypeText } from \"@xmtp/content-type-text\";\nimport type {\n ConsentState,\n MetadataField,\n PermissionPolicy,\n PermissionUpdateType,\n} from \"@xmtp/wasm-bindings\";\nimport { v4 } from \"uuid\";\nimport { AsyncStream, type StreamCallback } from \"@/AsyncStream\";\nimport type { Client } from \"@/Client\";\nimport { DecodedMessage } from \"@/DecodedMessage\";\nimport type {\n SafeConversation,\n SafeListMessagesOptions,\n SafeMessage,\n} from \"@/utils/conversions\";\nimport { nsToDate } from \"@/utils/date\";\n\nexport class Conversation {\n #client: Client;\n\n #id: string;\n\n #name?: SafeConversation[\"name\"];\n\n #imageUrl?: SafeConversation[\"imageUrl\"];\n\n #description?: SafeConversation[\"description\"];\n\n #isActive?: SafeConversation[\"isActive\"];\n\n #addedByInboxId?: SafeConversation[\"addedByInboxId\"];\n\n #metadata?: SafeConversation[\"metadata\"];\n\n #createdAtNs?: SafeConversation[\"createdAtNs\"];\n\n #admins: SafeConversation[\"admins\"] = [];\n\n #superAdmins: SafeConversation[\"superAdmins\"] = [];\n\n constructor(client: Client, id: string, data?: SafeConversation) {\n this.#client = client;\n this.#id = id;\n this.#syncData(data);\n }\n\n #syncData(data?: SafeConversation) {\n this.#name = data?.name ?? \"\";\n this.#imageUrl = data?.imageUrl ?? \"\";\n this.#description = data?.description ?? \"\";\n this.#isActive = data?.isActive ?? undefined;\n this.#addedByInboxId = data?.addedByInboxId ?? \"\";\n this.#metadata = data?.metadata ?? undefined;\n this.#createdAtNs = data?.createdAtNs ?? undefined;\n this.#admins = data?.admins ?? [];\n this.#superAdmins = data?.superAdmins ?? [];\n }\n\n get id() {\n return this.#id;\n }\n\n get name() {\n return this.#name;\n }\n\n async updateName(name: string) {\n await this.#client.sendMessage(\"updateGroupName\", {\n id: this.#id,\n name,\n });\n this.#name = name;\n }\n\n get imageUrl() {\n return this.#imageUrl;\n }\n\n async updateImageUrl(imageUrl: string) {\n await this.#client.sendMessage(\"updateGroupImageUrlSquare\", {\n id: this.#id,\n imageUrl,\n });\n this.#imageUrl = imageUrl;\n }\n\n get description() {\n return this.#description;\n }\n\n async updateDescription(description: string) {\n await this.#client.sendMessage(\"updateGroupDescription\", {\n id: this.#id,\n description,\n });\n this.#description = description;\n }\n\n get isActive() {\n return this.#isActive;\n }\n\n get addedByInboxId() {\n return this.#addedByInboxId;\n }\n\n get createdAtNs() {\n return this.#createdAtNs;\n }\n\n get createdAt() {\n return this.#createdAtNs ? nsToDate(this.#createdAtNs) : undefined;\n }\n\n get metadata() {\n return this.#metadata;\n }\n\n async members() {\n return this.#client.sendMessage(\"getGroupMembers\", {\n id: this.#id,\n });\n }\n\n get admins() {\n return this.#admins;\n }\n\n get superAdmins() {\n return this.#superAdmins;\n }\n\n async syncAdmins() {\n const admins = await this.#client.sendMessage(\"getGroupAdmins\", {\n id: this.#id,\n });\n this.#admins = admins;\n }\n\n async syncSuperAdmins() {\n const superAdmins = await this.#client.sendMessage(\"getGroupSuperAdmins\", {\n id: this.#id,\n });\n this.#superAdmins = superAdmins;\n }\n\n async permissions() {\n return this.#client.sendMessage(\"getGroupPermissions\", {\n id: this.#id,\n });\n }\n\n async updatePermission(\n permissionType: PermissionUpdateType,\n policy: PermissionPolicy,\n metadataField?: MetadataField,\n ) {\n return this.#client.sendMessage(\"updateGroupPermissionPolicy\", {\n id: this.#id,\n permissionType,\n policy,\n metadataField,\n });\n }\n\n async isAdmin(inboxId: string) {\n await this.syncAdmins();\n return this.#admins.includes(inboxId);\n }\n\n async isSuperAdmin(inboxId: string) {\n await this.syncSuperAdmins();\n return this.#superAdmins.includes(inboxId);\n }\n\n async sync() {\n const data = await this.#client.sendMessage(\"syncGroup\", {\n id: this.#id,\n });\n this.#syncData(data);\n }\n\n async addMembers(accountAddresses: string[]) {\n return this.#client.sendMessage(\"addGroupMembers\", {\n id: this.#id,\n accountAddresses,\n });\n }\n\n async addMembersByInboxId(inboxIds: string[]) {\n return this.#client.sendMessage(\"addGroupMembersByInboxId\", {\n id: this.#id,\n inboxIds,\n });\n }\n\n async removeMembers(accountAddresses: string[]) {\n return this.#client.sendMessage(\"removeGroupMembers\", {\n id: this.#id,\n accountAddresses,\n });\n }\n\n async removeMembersByInboxId(inboxIds: string[]) {\n return this.#client.sendMessage(\"removeGroupMembersByInboxId\", {\n id: this.#id,\n inboxIds,\n });\n }\n\n async addAdmin(inboxId: string) {\n return this.#client.sendMessage(\"addGroupAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async removeAdmin(inboxId: string) {\n return this.#client.sendMessage(\"removeGroupAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async addSuperAdmin(inboxId: string) {\n return this.#client.sendMessage(\"addGroupSuperAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async removeSuperAdmin(inboxId: string) {\n return this.#client.sendMessage(\"removeGroupSuperAdmin\", {\n id: this.#id,\n inboxId,\n });\n }\n\n async publishMessages() {\n return this.#client.sendMessage(\"publishGroupMessages\", {\n id: this.#id,\n });\n }\n\n async sendOptimistic(content: any, contentType?: ContentTypeId) {\n if (typeof content !== \"string\" && !contentType) {\n throw new Error(\n \"Content type is required when sending content other than text\",\n );\n }\n\n const safeEncodedContent =\n typeof content === \"string\"\n ? this.#client.encodeContent(content, contentType ?? ContentTypeText)\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#client.encodeContent(content, contentType!);\n\n return this.#client.sendMessage(\"sendOptimisticGroupMessage\", {\n id: this.#id,\n content: safeEncodedContent,\n });\n }\n\n async send(content: any, contentType?: ContentTypeId) {\n if (typeof content !== \"string\" && !contentType) {\n throw new Error(\n \"Content type is required when sending content other than text\",\n );\n }\n\n const safeEncodedContent =\n typeof content === \"string\"\n ? this.#client.encodeContent(content, contentType ?? ContentTypeText)\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#client.encodeContent(content, contentType!);\n\n return this.#client.sendMessage(\"sendGroupMessage\", {\n id: this.#id,\n content: safeEncodedContent,\n });\n }\n\n async messages(options?: SafeListMessagesOptions) {\n const messages = await this.#client.sendMessage(\"getGroupMessages\", {\n id: this.#id,\n options,\n });\n\n return messages.map((message) => new DecodedMessage(this.#client, message));\n }\n\n async consentState() {\n return this.#client.sendMessage(\"getGroupConsentState\", {\n id: this.#id,\n });\n }\n\n async updateConsentState(state: ConsentState) {\n return this.#client.sendMessage(\"updateGroupConsentState\", {\n id: this.#id,\n state,\n });\n }\n\n async dmPeerInboxId() {\n return this.#client.sendMessage(\"getDmPeerInboxId\", {\n id: this.#id,\n });\n }\n\n async stream(callback?: StreamCallback<DecodedMessage>) {\n const streamId = v4();\n const asyncStream = new AsyncStream<DecodedMessage>();\n const endStream = this.#client.handleStreamMessage<SafeMessage>(\n streamId,\n (error, value) => {\n const decodedMessage = value\n ? new DecodedMessage(this.#client, value)\n : undefined;\n void asyncStream.callback(error, decodedMessage);\n void callback?.(error, decodedMessage);\n },\n );\n await this.#client.sendMessage(\"streamGroupMessages\", {\n groupId: this.#id,\n streamId,\n });\n asyncStream.onReturn = () => {\n void this.#client.sendMessage(\"endStream\", {\n streamId,\n });\n endStream();\n };\n return asyncStream;\n }\n}\n","export function nsToDate(ns: bigint): Date {\n return new Date(Number(ns / 1_000_000n));\n}\n","import { ConversationType } from \"@xmtp/wasm-bindings\";\nimport { v4 } from \"uuid\";\nimport { AsyncStream, type StreamCallback } from \"@/AsyncStream\";\nimport type { Client } from \"@/Client\";\nimport { Conversation } from \"@/Conversation\";\nimport { DecodedMessage } from \"@/DecodedMessage\";\nimport type {\n SafeConversation,\n SafeCreateGroupOptions,\n SafeListConversationsOptions,\n SafeMessage,\n} from \"@/utils/conversions\";\n\nexport class Conversations {\n #client: Client;\n\n constructor(client: Client) {\n this.#client = client;\n }\n\n async sync() {\n return this.#client.sendMessage(\"syncConversations\", undefined);\n }\n\n async syncAll() {\n return this.#client.sendMessage(\"syncAllConversations\", undefined);\n }\n\n async getConversationById(id: string) {\n const data = await this.#client.sendMessage(\"getConversationById\", {\n id,\n });\n return data ? new Conversation(this.#client, id, data) : undefined;\n }\n\n async getMessageById(id: string) {\n const data = await this.#client.sendMessage(\"getMessageById\", {\n id,\n });\n return data ? new DecodedMessage(this.#client, data) : undefined;\n }\n\n async getDmByInboxId(inboxId: string) {\n const data = await this.#client.sendMessage(\"getDmByInboxId\", {\n inboxId,\n });\n return data ? new Conversation(this.#client, data.id, data) : undefined;\n }\n\n async list(options?: SafeListConversationsOptions) {\n const conversations = await this.#client.sendMessage(\"getConversations\", {\n options,\n });\n\n return conversations.map(\n (conversation) =>\n new Conversation(this.#client, conversation.id, conversation),\n );\n }\n\n async listGroups(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const conversations = await this.#client.sendMessage(\"getGroups\", {\n options,\n });\n\n return conversations.map(\n (conversation) =>\n new Conversation(this.#client, conversation.id, conversation),\n );\n }\n\n async listDms(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const conversations = await this.#client.sendMessage(\"getDms\", {\n options,\n });\n\n return conversations.map(\n (conversation) =>\n new Conversation(this.#client, conversation.id, conversation),\n );\n }\n\n async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {\n const conversation = await this.#client.sendMessage(\"newGroup\", {\n accountAddresses,\n options,\n });\n\n return new Conversation(this.#client, conversation.id, conversation);\n }\n\n async newDm(accountAddress: string) {\n const conversation = await this.#client.sendMessage(\"newDm\", {\n accountAddress,\n });\n\n return new Conversation(this.#client, conversation.id, conversation);\n }\n\n async getHmacKeys() {\n return this.#client.sendMessage(\"getHmacKeys\", undefined);\n }\n\n async stream(\n callback?: StreamCallback<Conversation>,\n conversationType?: ConversationType,\n ) {\n const streamId = v4();\n const asyncStream = new AsyncStream<Conversation>();\n const endStream = this.#client.handleStreamMessage<SafeConversation>(\n streamId,\n (error, value) => {\n const conversation = value\n ? new Conversation(this.#client, value.id, value)\n : undefined;\n void asyncStream.callback(error, conversation);\n void callback?.(error, conversation);\n },\n );\n await this.#client.sendMessage(\"streamAllGroups\", {\n streamId,\n conversationType,\n });\n asyncStream.onReturn = () => {\n void this.#client.sendMessage(\"endStream\", {\n streamId,\n });\n endStream();\n };\n return asyncStream;\n }\n\n async streamGroups(callback?: StreamCallback<Conversation>) {\n return this.stream(callback, ConversationType.Group);\n }\n\n async streamDms(callback?: StreamCallback<Conversation>) {\n return this.stream(callback, ConversationType.Dm);\n }\n\n async streamAllMessages(\n callback?: StreamCallback<DecodedMessage>,\n conversationType?: ConversationType,\n ) {\n const streamId = v4();\n const asyncStream = new AsyncStream<DecodedMessage>();\n const endStream = this.#client.handleStreamMessage<SafeMessage>(\n streamId,\n (error, value) => {\n const decodedMessage = value\n ? new DecodedMessage(this.#client, value)\n : undefined;\n void asyncStream.callback(error, decodedMessage);\n void callback?.(error, decodedMessage);\n },\n );\n await this.#client.sendMessage(\"streamAllMessages\", {\n streamId,\n conversationType,\n });\n asyncStream.onReturn = () => {\n void this.#client.sendMessage(\"endStream\", {\n streamId,\n });\n endStream();\n };\n return asyncStream;\n }\n\n async streamAllGroupMessages(callback?: StreamCallback<DecodedMessage>) {\n return this.streamAllMessages(callback, ConversationType.Group);\n }\n\n async streamAllDmMessages(callback?: StreamCallback<DecodedMessage>) {\n return this.streamAllMessages(callback, ConversationType.Dm);\n }\n}\n","export type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;\nexport type GetAddress = () => Promise<string> | string;\nexport type GetChainId = () => bigint;\nexport type GetBlockNumber = () => bigint;\n\nexport type Signer = {\n getAddress: GetAddress;\n signMessage: SignMessage;\n // these fields indicate that the signer is a smart contract wallet\n getBlockNumber?: GetBlockNumber;\n getChainId?: GetChainId;\n};\n\nexport type SmartContractSigner = Required<Signer>;\n\nexport const isSmartContractSigner = (\n signer: Signer,\n): signer is SmartContractSigner =>\n \"getBlockNumber\" in signer && \"getChainId\" in signer;\n","import {\n ContentTypeGroupUpdated,\n GroupUpdatedCodec,\n} from \"@xmtp/content-type-group-updated\";\nimport type {\n ContentCodec,\n ContentTypeId,\n} from \"@xmtp/content-type-primitives\";\nimport { TextCodec } from \"@xmtp/content-type-text\";\nimport {\n GroupMessageKind,\n SignatureRequestType,\n type ConsentEntityType,\n} from \"@xmtp/wasm-bindings\";\nimport { ClientWorkerClass } from \"@/ClientWorkerClass\";\nimport { Conversations } from \"@/Conversations\";\nimport type { ClientOptions, XmtpEnv } from \"@/types\";\nimport {\n fromSafeEncodedContent,\n toSafeEncodedContent,\n type SafeConsent,\n type SafeMessage,\n} from \"@/utils/conversions\";\nimport { isSmartContractSigner, type Signer } from \"@/utils/signer\";\n\nexport class Client extends ClientWorkerClass {\n #accountAddress: string;\n #codecs: Map<string, ContentCodec>;\n #conversations: Conversations;\n #encryptionKey: Uint8Array;\n #inboxId: string | undefined;\n #installationId: string | undefined;\n #installationIdBytes: Uint8Array | undefined;\n #isReady = false;\n #signer: Signer;\n options?: ClientOptions;\n\n constructor(\n signer: Signer,\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: ClientOptions,\n ) {\n const worker = new Worker(new URL(\"./workers/client\", import.meta.url), {\n type: \"module\",\n });\n super(\n worker,\n options?.loggingLevel !== undefined && options.loggingLevel !== \"off\",\n );\n this.#accountAddress = accountAddress;\n this.options = options;\n this.#encryptionKey = encryptionKey;\n this.#signer = signer;\n this.#conversations = new Conversations(this);\n const codecs = [\n new GroupUpdatedCodec(),\n new TextCodec(),\n ...(options?.codecs ?? []),\n ];\n this.#codecs = new Map(\n codecs.map((codec) => [codec.contentType.toString(), codec]),\n );\n }\n\n get accountAddress() {\n return this.#accountAddress;\n }\n\n async init() {\n const result = await this.sendMessage(\"init\", {\n address: this.accountAddress,\n encryptionKey: this.#encryptionKey,\n options: this.options,\n });\n this.#inboxId = result.inboxId;\n this.#installationId = result.installationId;\n this.#installationIdBytes = result.installationIdBytes;\n this.#isReady = true;\n }\n\n static async create(\n signer: Signer,\n encryptionKey: Uint8Array,\n options?: ClientOptions,\n ) {\n const address = await signer.getAddress();\n const client = new Client(signer, address, encryptionKey, options);\n\n await client.init();\n\n if (!options?.disableAutoRegister) {\n await client.register();\n }\n\n return client;\n }\n\n get isReady() {\n return this.#isReady;\n }\n\n get inboxId() {\n return this.#inboxId;\n }\n\n get installationId() {\n return this.#installationId;\n }\n\n get installationIdBytes() {\n return this.#installationIdBytes;\n }\n\n async #createInboxSignatureText() {\n return this.sendMessage(\"createInboxSignatureText\", undefined);\n }\n\n async #addAccountSignatureText(newAccountAddress: string) {\n return this.sendMessage(\"addAccountSignatureText\", {\n newAccountAddress,\n });\n }\n\n async #removeAccountSignatureText(accountAddress: string) {\n return this.sendMessage(\"removeAccountSignatureText\", { accountAddress });\n }\n\n async #revokeAllOtherInstallationsSignatureText() {\n return this.sendMessage(\n \"revokeAllOtherInstallationsSignatureText\",\n undefined,\n );\n }\n\n async #revokeInstallationsSignatureText(installationIds: Uint8Array[]) {\n return this.sendMessage(\"revokeInstallationsSignatureText\", {\n installationIds,\n });\n }\n\n async #addSignature(\n signatureType: SignatureRequestType,\n signatureText: string,\n signer: Signer,\n ) {\n const signature = await signer.signMessage(signatureText);\n\n if (isSmartContractSigner(signer)) {\n await this.sendMessage(\"addScwSignature\", {\n type: signatureType,\n bytes: signature,\n chainId: signer.getChainId(),\n blockNumber: signer.getBlockNumber(),\n });\n } else {\n await this.sendMessage(\"addSignature\", {\n type: signatureType,\n bytes: signature,\n });\n }\n }\n\n async #applySignatures() {\n return this.sendMessage(\"applySignatures\", undefined);\n }\n\n async register() {\n const signatureText = await this.#createInboxSignatureText();\n\n // if the signature text is not available, the client is already registered\n if (!signatureText) {\n return;\n }\n\n await this.#addSignature(\n SignatureRequestType.CreateInbox,\n signatureText,\n this.#signer,\n );\n\n return this.sendMessage(\"registerIdentity\", undefined);\n }\n\n async addAccount(newAccountSigner: Signer) {\n const signatureText = await this.#addAccountSignatureText(\n await newAccountSigner.getAddress(),\n );\n\n if (!signatureText) {\n throw new Error(\"Unable to generate add account signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.AddWallet,\n signatureText,\n newAccountSigner,\n );\n\n await this.#applySignatures();\n }\n\n async removeAccount(accountAddress: string) {\n const signatureText =\n await this.#removeAccountSignatureText(accountAddress);\n\n if (!signatureText) {\n throw new Error(\"Unable to generate remove account signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.RevokeWallet,\n signatureText,\n this.#signer,\n );\n\n await this.#applySignatures();\n }\n\n async revokeAllOtherInstallations() {\n const signatureText =\n await this.#revokeAllOtherInstallationsSignatureText();\n\n if (!signatureText) {\n throw new Error(\n \"Unable to generate revoke all other installations signature text\",\n );\n }\n\n await this.#addSignature(\n SignatureRequestType.RevokeInstallations,\n signatureText,\n this.#signer,\n );\n\n await this.#applySignatures();\n }\n\n async revokeInstallations(installationIds: Uint8Array[]) {\n const signatureText =\n await this.#revokeInstallationsSignatureText(installationIds);\n\n if (!signatureText) {\n throw new Error(\"Unable to generate revoke installations signature text\");\n }\n\n await this.#addSignature(\n SignatureRequestType.RevokeInstallations,\n signatureText,\n this.#signer,\n );\n\n await this.#applySignatures();\n }\n\n async isRegistered() {\n return this.sendMessage(\"isRegistered\", undefined);\n }\n\n async canMessage(accountAddresses: string[]) {\n return this.sendMessage(\"canMessage\", { accountAddresses });\n }\n\n static async canMessage(accountAddresses: string[], env?: XmtpEnv) {\n const accountAddress = \"0x0000000000000000000000000000000000000000\";\n const signer: Signer = {\n getAddress: () => accountAddress,\n signMessage: () => new Uint8Array(),\n };\n const client = await Client.create(\n signer,\n window.crypto.getRandomValues(new Uint8Array(32)),\n {\n disableAutoRegister: true,\n env,\n },\n );\n return client.canMessage(accountAddresses);\n }\n\n async findInboxIdByAddress(address: string) {\n return this.sendMessage(\"findInboxIdByAddress\", { address });\n }\n\n async inboxState(refreshFromNetwork?: boolean) {\n return this.sendMessage(\"inboxState\", {\n refreshFromNetwork: refreshFromNetwork ?? false,\n });\n }\n\n async getLatestInboxState(inboxId: string) {\n return this.sendMessage(\"getLatestInboxState\", { inboxId });\n }\n\n async setConsentStates(records: SafeConsent[]) {\n return this.sendMessage(\"setConsentStates\", { records });\n }\n\n async getConsentState(entityType: ConsentEntityType, entity: string) {\n return this.sendMessage(\"getConsentState\", { entityType, entity });\n }\n\n get conversations() {\n return this.#conversations;\n }\n\n codecFor(contentType: ContentTypeId) {\n return this.#codecs.get(contentType.toString());\n }\n\n encodeContent(content: any, contentType: ContentTypeId) {\n const codec = this.codecFor(contentType);\n if (!codec) {\n throw new Error(\n `Codec not found for \"${contentType.toString()}\" content type`,\n );\n }\n const encoded = codec.encode(content, this);\n const fallback = codec.fallback(content);\n if (fallback) {\n encoded.fallback = fallback;\n }\n return toSafeEncodedContent(encoded);\n }\n\n decodeContent(message: SafeMessage, contentType: ContentTypeId) {\n const codec = this.codecFor(contentType);\n if (!codec) {\n throw new Error(\n `Codec not found for \"${contentType.toString()}\" content type`,\n );\n }\n\n // throw an error if there's an invalid group membership change message\n if (\n contentType.sameAs(ContentTypeGroupUpdated) &&\n message.kind !== GroupMessageKind.MembershipChange\n ) {\n throw new Error(\"Error decoding group membership change\");\n }\n\n const encodedContent = fromSafeEncodedContent(message.content);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return codec.decode(encodedContent, this);\n }\n\n signWithInstallationKey(signatureText: string) {\n return this.sendMessage(\"signWithInstallationKey\", { signatureText });\n }\n\n verifySignedWithInstallationKey(\n signatureText: string,\n signatureBytes: Uint8Array,\n ) {\n return this.sendMessage(\"verifySignedWithInstallationKey\", {\n signatureText,\n signatureBytes,\n });\n }\n\n verifySignedWithPublicKey(\n signatureText: string,\n signatureBytes: Uint8Array,\n publicKey: Uint8Array,\n ) {\n return this.sendMessage(\"verifySignedWithPublicKey\", {\n signatureText,\n signatureBytes,\n publicKey,\n });\n }\n}\n","import { v4 } from \"uuid\";\nimport type {\n UtilsEventsActions,\n UtilsEventsErrorData,\n UtilsEventsResult,\n UtilsEventsWorkerMessageData,\n UtilsSendMessageData,\n} from \"@/types\";\n\nconst handleError = (event: ErrorEvent) => {\n console.error(`Worker error on line ${event.lineno} in \"${event.filename}\"`);\n console.error(event.message);\n};\n\nexport class UtilsWorkerClass {\n #worker: Worker;\n\n #enableLogging: boolean;\n\n #promises = new Map<\n string,\n { resolve: (value: any) => void; reject: (reason?: any) => void }\n >();\n\n constructor(worker: Worker, enableLogging: boolean) {\n this.#worker = worker;\n this.#worker.addEventListener(\"message\", this.handleMessage);\n this.#worker.addEventListener(\"error\", handleError);\n this.#enableLogging = enableLogging;\n }\n\n sendMessage<A extends UtilsEventsActions>(\n action: A,\n data: UtilsSendMessageData<A>,\n ) {\n const promiseId = v4();\n this.#worker.postMessage({\n action,\n id: promiseId,\n data,\n });\n const promise = new Promise<UtilsEventsResult<A>>((resolve, reject) => {\n this.#promises.set(promiseId, { resolve, reject });\n });\n return promise;\n }\n\n handleMessage = (\n event: MessageEvent<UtilsEventsWorkerMessageData | UtilsEventsErrorData>,\n ) => {\n const eventData = event.data;\n if (this.#enableLogging) {\n console.log(\"utils received event data\", eventData);\n }\n const promise = this.#promises.get(eventData.id);\n if (promise) {\n this.#promises.delete(eventData.id);\n if (\"error\" in eventData) {\n promise.reject(new Error(eventData.error));\n } else {\n promise.resolve(eventData.result);\n }\n }\n };\n\n close() {\n this.#worker.removeEventListener(\"message\", this.handleMessage);\n this.#worker.removeEventListener(\"error\", handleError);\n this.#worker.terminate();\n }\n}\n","import type { XmtpEnv } from \"@/types/options\";\nimport { UtilsWorkerClass } from \"@/UtilsWorkerClass\";\n\nexport class Utils extends UtilsWorkerClass {\n #enableLogging: boolean;\n constructor(enableLogging?: boolean) {\n const worker = new Worker(new URL(\"./workers/utils\", import.meta.url), {\n type: \"module\",\n });\n super(worker, enableLogging ?? false);\n this.#enableLogging = enableLogging ?? false;\n }\n\n async generateInboxId(address: string) {\n return this.sendMessage(\"generateInboxId\", {\n address,\n enableLogging: this.#enableLogging,\n });\n }\n\n async getInboxIdForAddress(address: string, env?: XmtpEnv) {\n return this.sendMessage(\"getInboxIdForAddress\", {\n address,\n env,\n enableLogging: this.#enableLogging,\n });\n }\n}\n","export const ApiUrls = {\n local: \"http://localhost:5555\",\n dev: \"https://dev.xmtp.network\",\n production: \"https://production.xmtp.network\",\n} as const;\n\nexport const HistorySyncUrls = {\n local: \"http://localhost:5558\",\n dev: \"https://message-history.dev.ephemera.network\",\n production: \"https://message-history.production.ephemera.network\",\n} as const;\n"],"names":["handleError","event","console","error","lineno","filename","message","ClientWorkerClass","worker","enableLogging","promises","Map","constructor","this","addEventListener","handleMessage","sendMessage","action","data","promiseId","v4","postMessage","id","Promise","resolve","reject","set","eventData","log","promise","get","delete","Error","result","handleStreamMessage","streamId","callback","streamHandler","removeEventListener","close","terminate","AsyncStream","done","resolveNext","queue","onReturn","undefined","isDone","value","push","next","length","shift","return","Symbol","asyncIterator","toContentTypeId","contentTypeId","ContentTypeId","authorityId","typeId","versionMajor","versionMinor","fromContentTypeId","WasmContentTypeId","toSafeContentTypeId","fromSafeContentTypeId","toEncodedContent","content","type","parameters","Object","fromEntries","fallback","compression","fromEncodedContent","WasmEncodedContent","entries","toSafeEncodedContent","fromSafeEncodedContent","toSafeMessage","convoId","deliveryStatus","kind","senderInboxId","sentAtNs","toSafeListMessagesOptions","options","direction","limit","sentAfterNs","sentBeforeNs","fromSafeListMessagesOptions","ListMessagesOptions","toSafeListConversationsOptions","allowedStates","conversationType","createdAfterNs","createdBeforeNs","fromSafeListConversationsOptions","ListConversationsOptions","toSafePermissionPolicySet","policySet","addAdminPolicy","addMemberPolicy","removeAdminPolicy","removeMemberPolicy","updateGroupDescriptionPolicy","updateGroupImageUrlSquarePolicy","updateGroupNamePolicy","updateMessageDisappearingPolicy","fromSafePermissionPolicySet","PermissionPolicySet","toSafeCreateGroupOptions","description","groupDescription","imageUrlSquare","groupImageUrlSquare","name","groupName","permissions","customPermissionPolicySet","fromSafeCreateGroupOptions","CreateGroupOptions","GroupPermissionsOptions","CustomPolicy","toSafeConversation","async","conversation","imageUrl","isActive","addedByInboxId","metadata","admins","superAdmins","createdAtNs","policyType","toSafeInstallation","installation","bytes","clientTimestampNs","toSafeInboxState","inboxState","accountAddresses","inboxId","installations","map","recoveryAddress","toSafeConsent","consent","entity","entityType","state","fromSafeConsent","Consent","toSafeGroupMember","member","consentState","installationIds","permissionLevel","fromSafeGroupMember","GroupMember","toSafeHmacKey","hmacKey","key","epoch","DecodedMessage","client","contentType","conversationId","encodedContent","GroupMessageKind","Application","MembershipChange","DeliveryStatus","Unpublished","Published","Failed","decodeContent","Conversation","syncData","updateName","updateImageUrl","updateDescription","createdAt","ns","Date","Number","members","syncAdmins","syncSuperAdmins","updatePermission","permissionType","policy","metadataField","isAdmin","includes","isSuperAdmin","sync","addMembers","addMembersByInboxId","inboxIds","removeMembers","removeMembersByInboxId","addAdmin","removeAdmin","addSuperAdmin","removeSuperAdmin","publishMessages","sendOptimistic","safeEncodedContent","encodeContent","ContentTypeText","send","messages","updateConsentState","dmPeerInboxId","stream","asyncStream","endStream","decodedMessage","groupId","Conversations","syncAll","getConversationById","getMessageById","getDmByInboxId","list","listGroups","listDms","newGroup","newDm","accountAddress","getHmacKeys","streamGroups","ConversationType","Group","streamDms","Dm","streamAllMessages","streamAllGroupMessages","streamAllDmMessages","isSmartContractSigner","signer","Client","codecs","conversations","encryptionKey","installationId","installationIdBytes","isReady","super","Worker","URL","url","loggingLevel","GroupUpdatedCodec","TextCodec","codec","toString","init","address","create","getAddress","disableAutoRegister","register","createInboxSignatureText","addAccountSignatureText","newAccountAddress","removeAccountSignatureText","revokeAllOtherInstallationsSignatureText","revokeInstallationsSignatureText","addSignature","signatureType","signatureText","signature","signMessage","chainId","getChainId","blockNumber","getBlockNumber","applySignatures","SignatureRequestType","CreateInbox","addAccount","newAccountSigner","AddWallet","removeAccount","RevokeWallet","revokeAllOtherInstallations","RevokeInstallations","revokeInstallations","isRegistered","canMessage","env","Uint8Array","window","crypto","getRandomValues","findInboxIdByAddress","refreshFromNetwork","getLatestInboxState","setConsentStates","records","getConsentState","codecFor","encoded","encode","sameAs","ContentTypeGroupUpdated","decode","signWithInstallationKey","verifySignedWithInstallationKey","signatureBytes","verifySignedWithPublicKey","publicKey","UtilsWorkerClass","Utils","generateInboxId","getInboxIdForAddress","ApiUrls","local","dev","production","HistorySyncUrls"],"mappings":"yhCAaA,MAAMA,EAAeC,IACnBC,QAAQC,MAAM,wBAAwBF,EAAMG,cAAcH,EAAMI,aAChEH,QAAQC,MAAMF,EAAMK,QAAQ,QAGjBC,EACXC,GAEAC,GAEAC,GAAY,IAAIC,IAKhB,WAAAC,CAAYJ,EAAgBC,GAC1BI,MAAKL,EAAUA,EACfK,MAAKL,EAAQM,iBAAiB,UAAWD,KAAKE,eAC9CF,MAAKL,EAAQM,iBAAiB,QAASd,GACvCa,MAAKJ,EAAiBA,EAGxB,WAAAO,CACEC,EACAC,GAEA,MAAMC,EAAYC,IAClBP,MAAKL,EAAQa,YAAY,CACvBJ,SACAK,GAAIH,EACJD,SAKF,OAHgB,IAAIK,SAA+B,CAACC,EAASC,KAC3DZ,MAAKH,EAAUgB,IAAIP,EAAW,CAAEK,UAASC,UAAS,IAKtDV,cACEd,IAEA,MAAM0B,EAAY1B,EAAMiB,KACpBL,MAAKJ,GACPP,QAAQ0B,IAAI,6BAA8BD,GAE5C,MAAME,EAAUhB,MAAKH,EAAUoB,IAAIH,EAAUL,IACzCO,IACFhB,MAAKH,EAAUqB,OAAOJ,EAAUL,IAC5B,UAAWK,EACbE,EAAQJ,OAAO,IAAIO,MAAML,EAAUxB,QAEnC0B,EAAQL,QAAQG,EAAUM,UAMhCC,oBAAsB,CACpBC,EACAC,KAEA,MAAMC,EACJpC,IAEA,MAAM0B,EAAY1B,EAAMiB,KACpBS,EAAUQ,WAAaA,IACrB,UAAWR,EACbS,EAAS,IAAIJ,MAAML,EAAUxB,OAAQ,MAErCiC,EAAS,KAAMT,EAAUM,UAM/B,OAFApB,MAAKL,EAAQM,iBAAiB,UAAWuB,GAElC,KACLxB,MAAKL,EAAQ8B,oBAAoB,UAAWD,EAAc,CAC3D,EAGH,KAAAE,GACE1B,MAAKL,EAAQ8B,oBA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kB,CAC7BH,MAAO,wBACPC,IAAK,+CACLC,WAAY"}
@@ -1,2 +1,2 @@
1
- import{ContentTypeId as e}from"@xmtp/content-type-primitives";import t,{EncodedContent as n,ContentTypeId as i,Consent as r,ListConversationsOptions as o,CreateGroupOptions as s,GroupPermissionsOptions as a,ListMessagesOptions as d,PermissionPolicySet as c,getInboxIdForAddress as u,generateInboxId as l,createClient as p,LogOptions as y,verifySignedWithPublicKey as g}from"@xmtp/wasm-bindings";const m=e=>{return new n((t=e.type,new i(t.authorityId,t.typeId,t.versionMajor,t.versionMinor)),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content);var t},v=e=>{return{type:(t=e.type,{authorityId:t.authorityId,typeId:t.typeId,versionMajor:t.versionMajor,versionMinor:t.versionMinor}),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content};var t},I=t=>{return{type:(n=t.type,new e({authorityId:n.authorityId,typeId:n.typeId,versionMajor:n.versionMajor,versionMinor:n.versionMinor})),parameters:t.parameters,fallback:t.fallback,compression:t.compression,content:t.content};var n},b=t=>{return{content:v((n=t.content,{type:(i=n.type,new e({authorityId:i.authorityId,typeId:i.typeId,versionMajor:i.versionMajor,versionMinor:i.versionMinor})),parameters:Object.fromEntries(n.parameters),fallback:n.fallback,compression:n.compression,content:n.content})),convoId:t.convoId,deliveryStatus:t.deliveryStatus,id:t.id,kind:t.kind,senderInboxId:t.senderInboxId,sentAtNs:t.sentAtNs};var n,i},h=e=>new o(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),w=e=>{return new s(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl,e.customPermissionPolicySet&&e.permissions===a.CustomPolicy?(t=e.customPermissionPolicySet,new c(t.addMemberPolicy,t.removeMemberPolicy,t.addAdminPolicy,t.removeAdminPolicy,t.updateGroupNamePolicy,t.updateGroupDescriptionPolicy,t.updateGroupImageUrlSquarePolicy,t.updateGroupPinnedFrameUrlPolicy,t.updateMessageExpirationPolicy)):void 0);var t},S=async e=>{const t=e.id,n=e.name,i=e.imageUrl,r=e.description,o=e.pinnedFrameUrl,s=e.permissions,a=e.isActive,d=e.addedByInboxId,c=await e.metadata(),u=e.admins,l=e.superAdmins,p=e.createdAtNs,y=s.policyType,g=s.policySet;return{id:t,name:n,imageUrl:i,description:r,pinnedFrameUrl:o,permissions:{policyType:y,policySet:{addAdminPolicy:g.addAdminPolicy,addMemberPolicy:g.addMemberPolicy,removeAdminPolicy:g.removeAdminPolicy,removeMemberPolicy:g.removeMemberPolicy,updateGroupDescriptionPolicy:g.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:g.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:g.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:g.updateGroupPinnedFrameUrlPolicy,updateMessageExpirationPolicy:g.updateMessageExpirationPolicy}},isActive:a,addedByInboxId:d,metadata:c,admins:u,superAdmins:l,createdAtNs:p}},x=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),A=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(x),recoveryAddress:e.recoveryAddress}),k=e=>new r(e.entityType,e.state,e.entity),G=e=>({key:e.key,epoch:e.epoch}),f={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},B={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};class M{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get id(){return this.#t.id()}get name(){return this.#t.groupName()}async updateName(e){return this.#t.updateGroupName(e)}get imageUrl(){return this.#t.groupImageUrlSquare()}async updateImageUrl(e){return this.#t.updateGroupImageUrlSquare(e)}get description(){return this.#t.groupDescription()}async updateDescription(e){return this.#t.updateGroupDescription(e)}get pinnedFrameUrl(){return this.#t.groupPinnedFrameUrl()}async updatePinnedFrameUrl(e){return this.#t.updateGroupPinnedFrameUrl(e)}get isActive(){return this.#t.isActive()}get addedByInboxId(){return this.#t.addedByInboxId()}get createdAtNs(){return this.#t.createdAtNs()}async metadata(){const e=await this.#t.groupMetadata();return{creatorInboxId:e.creatorInboxId(),conversationType:e.conversationType()}}async members(){return(await this.#t.listMembers()).map((e=>(e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}))(e)))}get admins(){return this.#t.adminList()}get superAdmins(){return this.#t.superAdminList()}get permissions(){const e=this.#t.groupPermissions();return{policyType:e.policyType(),policySet:e.policySet()}}async updatePermission(e,t,n){return this.#t.updatePermissionPolicy(e,t,n)}isAdmin(e){return this.#t.isAdmin(e)}isSuperAdmin(e){return this.#t.isSuperAdmin(e)}async sync(){return this.#t.sync()}async addMembers(e){return this.#t.addMembers(e)}async addMembersByInboxId(e){return this.#t.addMembersByInboxId(e)}async removeMembers(e){return this.#t.removeMembers(e)}async removeMembersByInboxId(e){return this.#t.removeMembersByInboxId(e)}async addAdmin(e){return this.#t.addAdmin(e)}async removeAdmin(e){return this.#t.removeAdmin(e)}async addSuperAdmin(e){return this.#t.addSuperAdmin(e)}async removeSuperAdmin(e){return this.#t.removeSuperAdmin(e)}async publishMessages(){return this.#t.publishMessages()}sendOptimistic(e){return this.#t.sendOptimistic(e)}async send(e){return this.#t.send(e)}async messages(e){return this.#t.findMessages(e?(e=>new d(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction))(e):void 0)}get consentState(){return this.#t.consentState()}updateConsentState(e){this.#t.updateConsentState(e)}dmPeerInboxId(){return this.#t.dmPeerInboxId()}}class P{#e;#n;constructor(e,t){this.#e=e,this.#n=t}async sync(){return this.#n.sync()}async syncAll(){return this.#n.syncAllConversations()}getConversationById(e){try{const t=this.#n.findGroupById(e);return new M(this.#e,t)}catch{return}}getMessageById(e){try{return this.#n.findMessageById(e)}catch{return}}getDmByInboxId(e){try{const t=this.#n.findDmByTargetInboxId(e);return new M(this.#e,t)}catch{return}}list(e){return this.#n.list(e?h(e):void 0).map((e=>new M(this.#e,e)))}listGroups(e){return this.#n.listGroups(e?h(e):void 0).map((e=>new M(this.#e,e)))}listDms(e){return this.#n.listDms(e?h(e):void 0).map((e=>new M(this.#e,e)))}async newGroup(e,t){const n=await this.#n.createGroup(e,t?w(t):void 0);return new M(this.#e,n)}async newDm(e){const t=await this.#n.createDm(e);return new M(this.#e,t)}getHmacKeys(){return this.#n.getHmacKeys()}}class C{#e;#n;#i;constructor(e){this.#e=e,this.#i=e.accountAddress,this.#n=new P(this,e.conversations())}static async create(e,n,i){const r=await(async(e,n,i)=>{await t();const r=i?.apiUrl||f[i?.env||"dev"],o=i?.dbPath||`xmtp-${i?.env||"dev"}-${e}.db3`,s=await u(r,e)||l(e),a=i&&(void 0!==i.loggingLevel||i.structuredLogging||i.performanceLogging);return p(r,s,e,o,n,i?.historySyncUrl||B[i?.env||"dev"],a?new y(i.structuredLogging??!1,i.performanceLogging??!1,i.loggingLevel):void 0)})(e,n,i);return new C(r)}get accountAddress(){return this.#i}get inboxId(){return this.#e.inboxId}get installationId(){return this.#e.installationId}get installationIdBytes(){return this.#e.installationIdBytes}get isRegistered(){return this.#e.isRegistered}async createInboxSignatureText(){try{return await this.#e.createInboxSignatureText()}catch{return}}async addAccountSignatureText(e){try{return await this.#e.addWalletSignatureText(e)}catch{return}}async removeAccountSignatureText(e){try{return await this.#e.revokeWalletSignatureText(e)}catch{return}}async revokeAllAOtherInstallationsSignatureText(){try{return await this.#e.revokeAllOtherInstallationsSignatureText()}catch{return}}async revokeInstallationsSignatureText(e){try{return await this.#e.revokeInstallationsSignatureText(e)}catch{return}}async addSignature(e,t){return this.#e.addSignature(e,t)}async addScwSignature(e,t,n,i){return this.#e.addScwSignature(e,t,n,i)}async applySignatures(){return this.#e.applySignatureRequests()}async canMessage(e){return this.#e.canMessage(e)}async registerIdentity(){return this.#e.registerIdentity()}async findInboxIdByAddress(e){return this.#e.findInboxIdByAddress(e)}async inboxState(e){return this.#e.inboxState(e)}async getLatestInboxState(e){return this.#e.getLatestInboxState(e)}async setConsentStates(e){return this.#e.setConsentStates(e.map(k))}async getConsentState(e,t){return this.#e.getConsentState(e,t)}get conversations(){return this.#n}signWithInstallationKey(e){return this.#e.signWithInstallationKey(e)}verifySignedWithInstallationKey(e,t){try{return this.#e.verifySignedWithInstallationKey(e,t),!0}catch{return!1}}verifySignedWithPublicKey(e,t,n){try{return g(e,t,n),!0}catch{return!1}}}let T,U=!1;const N=e=>{self.postMessage(e)},D=e=>{self.postMessage(e)};self.onmessage=async e=>{const{action:t,id:n,data:i}=e.data;if(U&&console.log("client worker received event data",e.data),"init"===t||T)try{switch(t){case"init":T=await C.create(i.address,i.encryptionKey,i.options),U=void 0!==i.options?.loggingLevel&&"off"!==i.options.loggingLevel,N({id:n,action:t,result:{inboxId:T.inboxId,installationId:T.installationId,installationIdBytes:T.installationIdBytes}});break;case"createInboxSignatureText":{const e=await T.createInboxSignatureText();N({id:n,action:t,result:e});break}case"addAccountSignatureText":{const e=await T.addAccountSignatureText(i.newAccountAddress);N({id:n,action:t,result:e});break}case"removeAccountSignatureText":{const e=await T.removeAccountSignatureText(i.accountAddress);N({id:n,action:t,result:e});break}case"revokeAllOtherInstallationsSignatureText":{const e=await T.revokeAllAOtherInstallationsSignatureText();N({id:n,action:t,result:e});break}case"revokeInstallationsSignatureText":{const e=await T.revokeInstallationsSignatureText(i.installationIds);N({id:n,action:t,result:e});break}case"addSignature":await T.addSignature(i.type,i.bytes),N({id:n,action:t,result:void 0});break;case"addScwSignature":await T.addScwSignature(i.type,i.bytes,i.chainId,i.blockNumber),N({id:n,action:t,result:void 0});break;case"applySignatures":await T.applySignatures(),N({id:n,action:t,result:void 0});break;case"registerIdentity":await T.registerIdentity(),N({id:n,action:t,result:void 0});break;case"isRegistered":{const e=T.isRegistered;N({id:n,action:t,result:e});break}case"canMessage":{const e=await T.canMessage(i.accountAddresses);N({id:n,action:t,result:e});break}case"inboxState":{const e=await T.inboxState(i.refreshFromNetwork);N({id:n,action:t,result:A(e)});break}case"getLatestInboxState":{const e=await T.getLatestInboxState(i.inboxId);N({id:n,action:t,result:A(e)});break}case"setConsentStates":await T.setConsentStates(i.records),N({id:n,action:t,result:void 0});break;case"getConsentState":{const e=await T.getConsentState(i.entityType,i.entity);N({id:n,action:t,result:e});break}case"findInboxIdByAddress":{const e=await T.findInboxIdByAddress(i.address);N({id:n,action:t,result:e});break}case"signWithInstallationKey":{const e=T.signWithInstallationKey(i.signatureText);N({id:n,action:t,result:e});break}case"verifySignedWithInstallationKey":{const e=T.verifySignedWithInstallationKey(i.signatureText,i.signatureBytes);N({id:n,action:t,result:e});break}case"verifySignedWithPublicKey":{const e=T.verifySignedWithPublicKey(i.signatureText,i.signatureBytes,i.publicKey);N({id:n,action:t,result:e});break}case"getConversations":{const e=T.conversations.list(i.options);N({id:n,action:t,result:await Promise.all(e.map((e=>S(e))))});break}case"getGroups":{const e=T.conversations.listGroups(i.options);N({id:n,action:t,result:await Promise.all(e.map((e=>S(e))))});break}case"getDms":{const e=T.conversations.listDms(i.options);N({id:n,action:t,result:await Promise.all(e.map((e=>S(e))))});break}case"newGroup":{const e=await T.conversations.newGroup(i.accountAddresses,i.options);N({id:n,action:t,result:await S(e)});break}case"newDm":{const e=await T.conversations.newDm(i.accountAddress);N({id:n,action:t,result:await S(e)});break}case"syncConversations":await T.conversations.sync(),N({id:n,action:t,result:void 0});break;case"syncAllConversations":await T.conversations.syncAll(),N({id:n,action:t,result:void 0});break;case"getConversationById":{const e=T.conversations.getConversationById(i.id);N({id:n,action:t,result:e?await S(e):void 0});break}case"getMessageById":{const e=T.conversations.getMessageById(i.id);N({id:n,action:t,result:e?b(e):void 0});break}case"getDmByInboxId":{const e=T.conversations.getDmByInboxId(i.inboxId);N({id:n,action:t,result:e?await S(e):void 0});break}case"getHmacKeys":{const e=T.conversations.getHmacKeys();N({id:n,action:t,result:Object.fromEntries(Array.from(e.entries()).map((([e,t])=>[e,t.map(G)])))});break}case"syncGroup":{const e=T.conversations.getConversationById(i.id);e?(await e.sync(),N({id:n,action:t,result:await S(e)})):D({id:n,action:t,error:"Group not found"});break}case"updateGroupName":{const e=T.conversations.getConversationById(i.id);e?(await e.updateName(i.name),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"updateGroupDescription":{const e=T.conversations.getConversationById(i.id);e?(await e.updateDescription(i.description),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"updateGroupImageUrlSquare":{const e=T.conversations.getConversationById(i.id);e?(await e.updateImageUrl(i.imageUrl),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"updateGroupPinnedFrameUrl":{const e=T.conversations.getConversationById(i.id);e?(await e.updatePinnedFrameUrl(i.pinnedFrameUrl),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"sendGroupMessage":{const e=T.conversations.getConversationById(i.id);if(e){const r=await e.send(m(I(i.content)));N({id:n,action:t,result:r})}else D({id:n,action:t,error:"Group not found"});break}case"sendOptimisticGroupMessage":{const e=T.conversations.getConversationById(i.id);if(e){const r=e.sendOptimistic(m(I(i.content)));N({id:n,action:t,result:r})}else D({id:n,action:t,error:"Group not found"});break}case"publishGroupMessages":{const e=T.conversations.getConversationById(i.id);e?(await e.publishMessages(),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"getGroupMessages":{const e=T.conversations.getConversationById(i.id);if(e){const r=await e.messages(i.options);N({id:n,action:t,result:r.map((e=>b(e)))})}else D({id:n,action:t,error:"Group not found"});break}case"getGroupMembers":{const e=T.conversations.getConversationById(i.id);if(e){const i=await e.members();N({id:n,action:t,result:i})}else D({id:n,action:t,error:"Group not found"});break}case"getGroupAdmins":{const e=T.conversations.getConversationById(i.id);e?N({id:n,action:t,result:e.admins}):D({id:n,action:t,error:"Group not found"});break}case"getGroupSuperAdmins":{const e=T.conversations.getConversationById(i.id);e?N({id:n,action:t,result:e.superAdmins}):D({id:n,action:t,error:"Group not found"});break}case"getGroupConsentState":{const e=T.conversations.getConversationById(i.id);e?N({id:n,action:t,result:e.consentState}):D({id:n,action:t,error:"Group not found"});break}case"updateGroupConsentState":{const e=T.conversations.getConversationById(i.id);e?(e.updateConsentState(i.state),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"addGroupAdmin":{const e=T.conversations.getConversationById(i.id);e?(await e.addAdmin(i.inboxId),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"removeGroupAdmin":{const e=T.conversations.getConversationById(i.id);e?(await e.removeAdmin(i.inboxId),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"addGroupSuperAdmin":{const e=T.conversations.getConversationById(i.id);e?(await e.addSuperAdmin(i.inboxId),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"removeGroupSuperAdmin":{const e=T.conversations.getConversationById(i.id);e?(await e.removeSuperAdmin(i.inboxId),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"addGroupMembers":{const e=T.conversations.getConversationById(i.id);e?(await e.addMembers(i.accountAddresses),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"removeGroupMembers":{const e=T.conversations.getConversationById(i.id);e?(await e.removeMembers(i.accountAddresses),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"addGroupMembersByInboxId":{const e=T.conversations.getConversationById(i.id);e?(await e.addMembersByInboxId(i.inboxIds),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"removeGroupMembersByInboxId":{const e=T.conversations.getConversationById(i.id);e?(await e.removeMembersByInboxId(i.inboxIds),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"isGroupAdmin":{const e=T.conversations.getConversationById(i.id);if(e){const r=e.isAdmin(i.inboxId);N({id:n,action:t,result:r})}else D({id:n,action:t,error:"Group not found"});break}case"isGroupSuperAdmin":{const e=T.conversations.getConversationById(i.id);if(e){const r=e.isSuperAdmin(i.inboxId);N({id:n,action:t,result:r})}else D({id:n,action:t,error:"Group not found"});break}case"getDmPeerInboxId":{const e=T.conversations.getConversationById(i.id);if(e){const i=e.dmPeerInboxId();N({id:n,action:t,result:i})}else D({id:n,action:t,error:"Group not found"});break}case"updateGroupPermissionPolicy":{const e=T.conversations.getConversationById(i.id);e?(await e.updatePermission(i.permissionType,i.policy,i.metadataField),N({id:n,action:t,result:void 0})):D({id:n,action:t,error:"Group not found"});break}case"getGroupPermissions":{const e=T.conversations.getConversationById(i.id);if(e){const i=await S(e);N({id:n,action:t,result:i.permissions})}else D({id:n,action:t,error:"Group not found"});break}}}catch(e){D({id:n,action:t,error:e.message})}else D({id:n,action:t,error:"Client not initialized"})};
1
+ import{ContentTypeId as e}from"@xmtp/content-type-primitives";import t,{EncodedContent as n,ContentTypeId as s,ListMessagesOptions as r,Consent as o,ListConversationsOptions as i,CreateGroupOptions as a,GroupPermissionsOptions as c,PermissionPolicySet as d,getInboxIdForAddress as u,generateInboxId as l,createClient as p,LogOptions as m,ConversationType as g,verifySignedWithPublicKey as y}from"@xmtp/wasm-bindings";const v=e=>{return new n((t=e.type,new s(t.authorityId,t.typeId,t.versionMajor,t.versionMinor)),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content);var t},I=e=>{return{type:(t=e.type,{authorityId:t.authorityId,typeId:t.typeId,versionMajor:t.versionMajor,versionMinor:t.versionMinor}),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content};var t},b=t=>{return{type:(n=t.type,new e({authorityId:n.authorityId,typeId:n.typeId,versionMajor:n.versionMajor,versionMinor:n.versionMinor})),parameters:t.parameters,fallback:t.fallback,compression:t.compression,content:t.content};var n},h=t=>{return{content:I((n=t.content,{type:(s=n.type,new e({authorityId:s.authorityId,typeId:s.typeId,versionMajor:s.versionMajor,versionMinor:s.versionMinor})),parameters:Object.fromEntries(n.parameters),fallback:n.fallback,compression:n.compression,content:n.content})),convoId:t.convoId,deliveryStatus:t.deliveryStatus,id:t.id,kind:t.kind,senderInboxId:t.senderInboxId,sentAtNs:t.sentAtNs};var n,s},S=e=>new i(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),w=e=>{return new a(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===c.CustomPolicy?(t=e.customPermissionPolicySet,new d(t.addMemberPolicy,t.removeMemberPolicy,t.addAdminPolicy,t.removeAdminPolicy,t.updateGroupNamePolicy,t.updateGroupDescriptionPolicy,t.updateGroupImageUrlSquarePolicy,t.updateMessageDisappearingPolicy)):void 0);var t},A=async e=>{const t=e.id,n=e.name,s=e.imageUrl,r=e.description,o=e.permissions,i=e.isActive,a=e.addedByInboxId,c=await e.metadata(),d=e.admins,u=e.superAdmins,l=e.createdAtNs,p=o.policyType,m=o.policySet;return{id:t,name:n,imageUrl:s,description:r,permissions:{policyType:p,policySet:{addAdminPolicy:m.addAdminPolicy,addMemberPolicy:m.addMemberPolicy,removeAdminPolicy:m.removeAdminPolicy,removeMemberPolicy:m.removeMemberPolicy,updateGroupDescriptionPolicy:m.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:m.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:m.updateGroupNamePolicy,updateMessageDisappearingPolicy:m.updateMessageDisappearingPolicy}},isActive:i,addedByInboxId:a,metadata:c,admins:d,superAdmins:u,createdAtNs:l}},k=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),x=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(k),recoveryAddress:e.recoveryAddress}),f=e=>new o(e.entityType,e.state,e.entity),G=e=>({key:e.key,epoch:e.epoch}),M={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},B={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};class C{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get id(){return this.#t.id()}get name(){return this.#t.groupName()}async updateName(e){return this.#t.updateGroupName(e)}get imageUrl(){return this.#t.groupImageUrlSquare()}async updateImageUrl(e){return this.#t.updateGroupImageUrlSquare(e)}get description(){return this.#t.groupDescription()}async updateDescription(e){return this.#t.updateGroupDescription(e)}get isActive(){return this.#t.isActive()}get addedByInboxId(){return this.#t.addedByInboxId()}get createdAtNs(){return this.#t.createdAtNs()}async metadata(){const e=await this.#t.groupMetadata();return{creatorInboxId:e.creatorInboxId(),conversationType:e.conversationType()}}async members(){return(await this.#t.listMembers()).map((e=>(e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}))(e)))}get admins(){return this.#t.adminList()}get superAdmins(){return this.#t.superAdminList()}get permissions(){const e=this.#t.groupPermissions();return{policyType:e.policyType(),policySet:e.policySet()}}async updatePermission(e,t,n){return this.#t.updatePermissionPolicy(e,t,n)}isAdmin(e){return this.#t.isAdmin(e)}isSuperAdmin(e){return this.#t.isSuperAdmin(e)}async sync(){return this.#t.sync()}async addMembers(e){return this.#t.addMembers(e)}async addMembersByInboxId(e){return this.#t.addMembersByInboxId(e)}async removeMembers(e){return this.#t.removeMembers(e)}async removeMembersByInboxId(e){return this.#t.removeMembersByInboxId(e)}async addAdmin(e){return this.#t.addAdmin(e)}async removeAdmin(e){return this.#t.removeAdmin(e)}async addSuperAdmin(e){return this.#t.addSuperAdmin(e)}async removeSuperAdmin(e){return this.#t.removeSuperAdmin(e)}async publishMessages(){return this.#t.publishMessages()}sendOptimistic(e){return this.#t.sendOptimistic(e)}async send(e){return this.#t.send(e)}async messages(e){return this.#t.findMessages(e?(e=>new r(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction))(e):void 0)}get consentState(){return this.#t.consentState()}updateConsentState(e){this.#t.updateConsentState(e)}dmPeerInboxId(){return this.#t.dmPeerInboxId()}stream(e){return this.#t.stream({on_message:t=>{e?.(null,t)},on_error:t=>{e?.(t,void 0)}})}}class P{#e;#n;constructor(e,t){this.#e=e,this.#n=t}async sync(){return this.#n.sync()}async syncAll(){return this.#n.syncAllConversations()}getConversationById(e){try{const t=this.#n.findGroupById(e);return new C(this.#e,t)}catch{return}}getMessageById(e){try{return this.#n.findMessageById(e)}catch{return}}getDmByInboxId(e){try{const t=this.#n.findDmByTargetInboxId(e);return new C(this.#e,t)}catch{return}}list(e){return this.#n.list(e?S(e):void 0).map((e=>new C(this.#e,e)))}listGroups(e){return this.#n.listGroups(e?S(e):void 0).map((e=>new C(this.#e,e)))}listDms(e){return this.#n.listDms(e?S(e):void 0).map((e=>new C(this.#e,e)))}async newGroup(e,t){const n=await this.#n.createGroup(e,t?w(t):void 0);return new C(this.#e,n)}async newDm(e){const t=await this.#n.createDm(e);return new C(this.#e,t)}getHmacKeys(){return this.#n.getHmacKeys()}stream(e,t){return this.#n.stream({on_conversation:t=>{e?.(null,t)},on_error:t=>{e?.(t,void 0)}},t)}streamGroups(e){return this.#n.stream(e,g.Group)}streamDms(e){return this.#n.stream(e,g.Dm)}streamAllMessages(e,t){return this.#n.streamAllMessages({on_message:t=>{e?.(null,t)},on_error:t=>{e?.(t,void 0)}},t)}}class T{#e;#n;#s;constructor(e){this.#e=e,this.#s=e.accountAddress,this.#n=new P(this,e.conversations())}static async create(e,n,s){const r=await(async(e,n,s)=>{await t();const r=s?.apiUrl||M[s?.env||"dev"],o=s?.dbPath||`xmtp-${s?.env||"dev"}-${e}.db3`,i=await u(r,e)||l(e),a=s&&(void 0!==s.loggingLevel||s.structuredLogging||s.performanceLogging);return p(r,i,e,o,n,s?.historySyncUrl||B[s?.env||"dev"],a?new m(s.structuredLogging??!1,s.performanceLogging??!1,s.loggingLevel):void 0)})(e,n,s);return new T(r)}get accountAddress(){return this.#s}get inboxId(){return this.#e.inboxId}get installationId(){return this.#e.installationId}get installationIdBytes(){return this.#e.installationIdBytes}get isRegistered(){return this.#e.isRegistered}createInboxSignatureText(){try{return this.#e.createInboxSignatureText()}catch{return}}async addAccountSignatureText(e){try{return await this.#e.addWalletSignatureText(e)}catch{return}}async removeAccountSignatureText(e){try{return await this.#e.revokeWalletSignatureText(e)}catch{return}}async revokeAllAOtherInstallationsSignatureText(){try{return await this.#e.revokeAllOtherInstallationsSignatureText()}catch{return}}async revokeInstallationsSignatureText(e){try{return await this.#e.revokeInstallationsSignatureText(e)}catch{return}}async addSignature(e,t){return this.#e.addSignature(e,t)}async addScwSignature(e,t,n,s){return this.#e.addScwSignature(e,t,n,s)}async applySignatures(){return this.#e.applySignatureRequests()}async canMessage(e){return this.#e.canMessage(e)}async registerIdentity(){return this.#e.registerIdentity()}async findInboxIdByAddress(e){return this.#e.findInboxIdByAddress(e)}async inboxState(e){return this.#e.inboxState(e)}async getLatestInboxState(e){return this.#e.getLatestInboxState(e)}async setConsentStates(e){return this.#e.setConsentStates(e.map(f))}async getConsentState(e,t){return this.#e.getConsentState(e,t)}get conversations(){return this.#n}signWithInstallationKey(e){return this.#e.signWithInstallationKey(e)}verifySignedWithInstallationKey(e,t){try{return this.#e.verifySignedWithInstallationKey(e,t),!0}catch{return!1}}verifySignedWithPublicKey(e,t,n){try{return y(e,t,n),!0}catch{return!1}}}let D,N=!1;const K=new Map,L=e=>{self.postMessage(e)},U=e=>{self.postMessage(e)},W=e=>{self.postMessage(e)},O=e=>{self.postMessage(e)};self.onmessage=async e=>{const{action:t,id:n,data:s}=e.data;if(N&&console.log("client worker received event data",e.data),"init"===t||D)try{switch(t){case"endStream":{const e=K.get(s.streamId);e?(e.end(),K.delete(s.streamId),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:`Stream "${s.streamId}" not found`});break}case"init":D=await T.create(s.address,s.encryptionKey,s.options),N=void 0!==s.options?.loggingLevel&&"off"!==s.options.loggingLevel,L({id:n,action:t,result:{inboxId:D.inboxId,installationId:D.installationId,installationIdBytes:D.installationIdBytes}});break;case"createInboxSignatureText":{const e=D.createInboxSignatureText();L({id:n,action:t,result:e});break}case"addAccountSignatureText":{const e=await D.addAccountSignatureText(s.newAccountAddress);L({id:n,action:t,result:e});break}case"removeAccountSignatureText":{const e=await D.removeAccountSignatureText(s.accountAddress);L({id:n,action:t,result:e});break}case"revokeAllOtherInstallationsSignatureText":{const e=await D.revokeAllAOtherInstallationsSignatureText();L({id:n,action:t,result:e});break}case"revokeInstallationsSignatureText":{const e=await D.revokeInstallationsSignatureText(s.installationIds);L({id:n,action:t,result:e});break}case"addSignature":await D.addSignature(s.type,s.bytes),L({id:n,action:t,result:void 0});break;case"addScwSignature":await D.addScwSignature(s.type,s.bytes,s.chainId,s.blockNumber),L({id:n,action:t,result:void 0});break;case"applySignatures":await D.applySignatures(),L({id:n,action:t,result:void 0});break;case"registerIdentity":await D.registerIdentity(),L({id:n,action:t,result:void 0});break;case"isRegistered":{const e=D.isRegistered;L({id:n,action:t,result:e});break}case"canMessage":{const e=await D.canMessage(s.accountAddresses);L({id:n,action:t,result:e});break}case"inboxState":{const e=await D.inboxState(s.refreshFromNetwork);L({id:n,action:t,result:x(e)});break}case"getLatestInboxState":{const e=await D.getLatestInboxState(s.inboxId);L({id:n,action:t,result:x(e)});break}case"setConsentStates":await D.setConsentStates(s.records),L({id:n,action:t,result:void 0});break;case"getConsentState":{const e=await D.getConsentState(s.entityType,s.entity);L({id:n,action:t,result:e});break}case"findInboxIdByAddress":{const e=await D.findInboxIdByAddress(s.address);L({id:n,action:t,result:e});break}case"signWithInstallationKey":{const e=D.signWithInstallationKey(s.signatureText);L({id:n,action:t,result:e});break}case"verifySignedWithInstallationKey":{const e=D.verifySignedWithInstallationKey(s.signatureText,s.signatureBytes);L({id:n,action:t,result:e});break}case"verifySignedWithPublicKey":{const e=D.verifySignedWithPublicKey(s.signatureText,s.signatureBytes,s.publicKey);L({id:n,action:t,result:e});break}case"streamAllGroups":{const e=async(e,t)=>{e?O({type:"group",streamId:s.streamId,error:e.message}):W({type:"group",streamId:s.streamId,result:t?await A(new C(D,t)):void 0})},r=D.conversations.stream(e,s.conversationType);K.set(s.streamId,r),L({id:n,action:t,result:void 0});break}case"streamAllMessages":{const e=(e,t)=>{e?O({type:"message",streamId:s.streamId,error:e.message}):W({type:"message",streamId:s.streamId,result:t?h(t):void 0})},r=D.conversations.streamAllMessages(e,s.conversationType);K.set(s.streamId,r),L({id:n,action:t,result:void 0});break}case"getConversations":{const e=D.conversations.list(s.options);L({id:n,action:t,result:await Promise.all(e.map((e=>A(e))))});break}case"getGroups":{const e=D.conversations.listGroups(s.options);L({id:n,action:t,result:await Promise.all(e.map((e=>A(e))))});break}case"getDms":{const e=D.conversations.listDms(s.options);L({id:n,action:t,result:await Promise.all(e.map((e=>A(e))))});break}case"newGroup":{const e=await D.conversations.newGroup(s.accountAddresses,s.options);L({id:n,action:t,result:await A(e)});break}case"newDm":{const e=await D.conversations.newDm(s.accountAddress);L({id:n,action:t,result:await A(e)});break}case"syncConversations":await D.conversations.sync(),L({id:n,action:t,result:void 0});break;case"syncAllConversations":await D.conversations.syncAll(),L({id:n,action:t,result:void 0});break;case"getConversationById":{const e=D.conversations.getConversationById(s.id);L({id:n,action:t,result:e?await A(e):void 0});break}case"getMessageById":{const e=D.conversations.getMessageById(s.id);L({id:n,action:t,result:e?h(e):void 0});break}case"getDmByInboxId":{const e=D.conversations.getDmByInboxId(s.inboxId);L({id:n,action:t,result:e?await A(e):void 0});break}case"getHmacKeys":{const e=D.conversations.getHmacKeys();L({id:n,action:t,result:Object.fromEntries(Array.from(e.entries()).map((([e,t])=>[e,t.map(G)])))});break}case"syncGroup":{const e=D.conversations.getConversationById(s.id);e?(await e.sync(),L({id:n,action:t,result:await A(e)})):U({id:n,action:t,error:"Group not found"});break}case"updateGroupName":{const e=D.conversations.getConversationById(s.id);e?(await e.updateName(s.name),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"updateGroupDescription":{const e=D.conversations.getConversationById(s.id);e?(await e.updateDescription(s.description),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"updateGroupImageUrlSquare":{const e=D.conversations.getConversationById(s.id);e?(await e.updateImageUrl(s.imageUrl),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"sendGroupMessage":{const e=D.conversations.getConversationById(s.id);if(e){const r=await e.send(v(b(s.content)));L({id:n,action:t,result:r})}else U({id:n,action:t,error:"Group not found"});break}case"sendOptimisticGroupMessage":{const e=D.conversations.getConversationById(s.id);if(e){const r=e.sendOptimistic(v(b(s.content)));L({id:n,action:t,result:r})}else U({id:n,action:t,error:"Group not found"});break}case"publishGroupMessages":{const e=D.conversations.getConversationById(s.id);e?(await e.publishMessages(),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"getGroupMessages":{const e=D.conversations.getConversationById(s.id);if(e){const r=await e.messages(s.options);L({id:n,action:t,result:r.map((e=>h(e)))})}else U({id:n,action:t,error:"Group not found"});break}case"getGroupMembers":{const e=D.conversations.getConversationById(s.id);if(e){const s=await e.members();L({id:n,action:t,result:s})}else U({id:n,action:t,error:"Group not found"});break}case"getGroupAdmins":{const e=D.conversations.getConversationById(s.id);e?L({id:n,action:t,result:e.admins}):U({id:n,action:t,error:"Group not found"});break}case"getGroupSuperAdmins":{const e=D.conversations.getConversationById(s.id);e?L({id:n,action:t,result:e.superAdmins}):U({id:n,action:t,error:"Group not found"});break}case"getGroupConsentState":{const e=D.conversations.getConversationById(s.id);e?L({id:n,action:t,result:e.consentState}):U({id:n,action:t,error:"Group not found"});break}case"updateGroupConsentState":{const e=D.conversations.getConversationById(s.id);e?(e.updateConsentState(s.state),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"addGroupAdmin":{const e=D.conversations.getConversationById(s.id);e?(await e.addAdmin(s.inboxId),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"removeGroupAdmin":{const e=D.conversations.getConversationById(s.id);e?(await e.removeAdmin(s.inboxId),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"addGroupSuperAdmin":{const e=D.conversations.getConversationById(s.id);e?(await e.addSuperAdmin(s.inboxId),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"removeGroupSuperAdmin":{const e=D.conversations.getConversationById(s.id);e?(await e.removeSuperAdmin(s.inboxId),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"addGroupMembers":{const e=D.conversations.getConversationById(s.id);e?(await e.addMembers(s.accountAddresses),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"removeGroupMembers":{const e=D.conversations.getConversationById(s.id);e?(await e.removeMembers(s.accountAddresses),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"addGroupMembersByInboxId":{const e=D.conversations.getConversationById(s.id);e?(await e.addMembersByInboxId(s.inboxIds),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"removeGroupMembersByInboxId":{const e=D.conversations.getConversationById(s.id);e?(await e.removeMembersByInboxId(s.inboxIds),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"isGroupAdmin":{const e=D.conversations.getConversationById(s.id);if(e){const r=e.isAdmin(s.inboxId);L({id:n,action:t,result:r})}else U({id:n,action:t,error:"Group not found"});break}case"isGroupSuperAdmin":{const e=D.conversations.getConversationById(s.id);if(e){const r=e.isSuperAdmin(s.inboxId);L({id:n,action:t,result:r})}else U({id:n,action:t,error:"Group not found"});break}case"getDmPeerInboxId":{const e=D.conversations.getConversationById(s.id);if(e){const s=e.dmPeerInboxId();L({id:n,action:t,result:s})}else U({id:n,action:t,error:"Group not found"});break}case"updateGroupPermissionPolicy":{const e=D.conversations.getConversationById(s.id);e?(await e.updatePermission(s.permissionType,s.policy,s.metadataField),L({id:n,action:t,result:void 0})):U({id:n,action:t,error:"Group not found"});break}case"getGroupPermissions":{const e=D.conversations.getConversationById(s.id);if(e){const s=await A(e);L({id:n,action:t,result:s.permissions})}else U({id:n,action:t,error:"Group not found"});break}case"streamGroupMessages":{const e=D.conversations.getConversationById(s.groupId);if(e){const r=(e,t)=>{e?O({type:"message",streamId:s.streamId,error:e.message}):W({type:"message",streamId:s.streamId,result:t?h(t):void 0})},o=e.stream(r);K.set(s.streamId,o),L({id:n,action:t,result:void 0})}else U({id:n,action:t,error:"Group not found"});break}}}catch(e){U({id:n,action:t,error:e.message})}else U({id:n,action:t,error:"Client not initialized"})};
2
2
  //# sourceMappingURL=client.js.map