@xmtp/browser-sdk 0.0.3 → 0.0.4
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.d.ts +35 -21
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/package.json +1 -1
- package/src/Client.ts +146 -45
- package/src/WorkerClient.ts +4 -4
- package/src/index.ts +5 -0
- package/src/types/clientEvents.ts +5 -5
- package/src/types/options.ts +4 -0
- package/src/utils/signer.ts +19 -0
- package/src/workers/client.ts +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../src/utils/conversions.ts","../../src/constants.ts","../../src/WorkerConversation.ts","../../src/WorkerConversations.ts","../../src/WorkerClient.ts","../../src/utils/createClient.ts","../../src/workers/client.ts"],"sourcesContent":["import {\n ContentTypeId,\n type EncodedContent,\n} from \"@xmtp/content-type-primitives\";\nimport {\n Consent,\n CreateGroupOptions,\n GroupMember,\n ListConversationsOptions,\n ListMessagesOptions,\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 GroupPermissionsOptions,\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 SafeCreateGroupOptions = {\n permissions?: GroupPermissionsOptions;\n name?: string;\n imageUrlSquare?: string;\n description?: string;\n pinnedFrameUrl?: string;\n};\n\nexport const toSafeCreateGroupOptions = (\n options: CreateGroupOptions,\n): SafeCreateGroupOptions => ({\n permissions: options.permissions,\n name: options.groupName,\n imageUrlSquare: options.groupImageUrlSquare,\n description: options.groupDescription,\n pinnedFrameUrl: options.groupPinnedFrameUrl,\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 );\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 };\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 = (\n conversation: WorkerConversation,\n): SafeConversation => ({\n id: conversation.id,\n name: conversation.name,\n imageUrl: conversation.imageUrl,\n description: conversation.description,\n pinnedFrameUrl: conversation.pinnedFrameUrl,\n permissions: {\n policyType: conversation.permissions.policyType,\n policySet: {\n addAdminPolicy: conversation.permissions.policySet.addAdminPolicy,\n addMemberPolicy: conversation.permissions.policySet.addMemberPolicy,\n removeAdminPolicy: conversation.permissions.policySet.removeAdminPolicy,\n removeMemberPolicy: conversation.permissions.policySet.removeMemberPolicy,\n updateGroupDescriptionPolicy:\n conversation.permissions.policySet.updateGroupDescriptionPolicy,\n updateGroupImageUrlSquarePolicy:\n conversation.permissions.policySet.updateGroupImageUrlSquarePolicy,\n updateGroupNamePolicy:\n conversation.permissions.policySet.updateGroupNamePolicy,\n updateGroupPinnedFrameUrlPolicy:\n conversation.permissions.policySet.updateGroupPinnedFrameUrlPolicy,\n },\n },\n isActive: conversation.isActive,\n addedByInboxId: conversation.addedByInboxId,\n metadata: conversation.metadata,\n admins: conversation.admins,\n superAdmins: conversation.superAdmins,\n createdAtNs: conversation.createdAtNs,\n});\n\nexport type SafeInstallation = {\n id: string;\n clientTimestampNs?: bigint;\n};\n\nexport const toSafeInstallation = (\n installation: Installation,\n): SafeInstallation => ({\n id: installation.id,\n clientTimestampNs: installation.clientTimestampNs,\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","export const ApiUrls = {\n local: \"http://localhost:5555\",\n dev: \"https://dev.xmtp.network\",\n production: \"https://production.xmtp.network\",\n} as const;\n","import type {\n ConsentState,\n Conversation,\n EncodedContent,\n GroupMember,\n} from \"@xmtp/wasm-bindings\";\nimport {\n fromSafeListMessagesOptions,\n toSafeGroupMember,\n type SafeListMessagesOptions,\n} from \"@/utils/conversions\";\nimport type { WorkerClient } from \"@/WorkerClient\";\n\nexport class WorkerConversation {\n // eslint-disable-next-line no-unused-private-class-members\n #client: WorkerClient;\n\n #group: Conversation;\n\n constructor(client: WorkerClient, group: Conversation) {\n this.#client = client;\n this.#group = group;\n }\n\n get id() {\n return this.#group.id();\n }\n\n get name() {\n return this.#group.groupName();\n }\n\n async updateName(name: string) {\n return this.#group.updateGroupName(name);\n }\n\n get imageUrl() {\n return this.#group.groupImageUrlSquare();\n }\n\n async updateImageUrl(imageUrl: string) {\n return this.#group.updateGroupImageUrlSquare(imageUrl);\n }\n\n get description() {\n return this.#group.groupDescription();\n }\n\n async updateDescription(description: string) {\n return this.#group.updateGroupDescription(description);\n }\n\n get pinnedFrameUrl() {\n return this.#group.groupPinnedFrameUrl();\n }\n\n async updatePinnedFrameUrl(pinnedFrameUrl: string) {\n return this.#group.updateGroupPinnedFrameUrl(pinnedFrameUrl);\n }\n\n get isActive() {\n return this.#group.isActive();\n }\n\n get addedByInboxId() {\n return this.#group.addedByInboxId();\n }\n\n get createdAtNs() {\n return this.#group.createdAtNs();\n }\n\n get metadata() {\n const metadata = this.#group.groupMetadata();\n return {\n creatorInboxId: metadata.creatorInboxId(),\n conversationType: metadata.conversationType(),\n };\n }\n\n async members() {\n const members = (await this.#group.listMembers()) as GroupMember[];\n return members.map((member) => toSafeGroupMember(member));\n }\n\n get admins() {\n return this.#group.adminList();\n }\n\n get superAdmins() {\n return this.#group.superAdminList();\n }\n\n get permissions() {\n const permissions = this.#group.groupPermissions();\n return {\n policyType: permissions.policyType(),\n policySet: permissions.policySet(),\n };\n }\n\n isAdmin(inboxId: string) {\n return this.#group.isAdmin(inboxId);\n }\n\n isSuperAdmin(inboxId: string) {\n return this.#group.isSuperAdmin(inboxId);\n }\n\n async sync() {\n return this.#group.sync();\n }\n\n async addMembers(accountAddresses: string[]) {\n return this.#group.addMembers(accountAddresses);\n }\n\n async addMembersByInboxId(inboxIds: string[]) {\n return this.#group.addMembersByInboxId(inboxIds);\n }\n\n async removeMembers(accountAddresses: string[]) {\n return this.#group.removeMembers(accountAddresses);\n }\n\n async removeMembersByInboxId(inboxIds: string[]) {\n return this.#group.removeMembersByInboxId(inboxIds);\n }\n\n async addAdmin(inboxId: string) {\n return this.#group.addAdmin(inboxId);\n }\n\n async removeAdmin(inboxId: string) {\n return this.#group.removeAdmin(inboxId);\n }\n\n async addSuperAdmin(inboxId: string) {\n return this.#group.addSuperAdmin(inboxId);\n }\n\n async removeSuperAdmin(inboxId: string) {\n return this.#group.removeSuperAdmin(inboxId);\n }\n\n async publishMessages() {\n return this.#group.publishMessages();\n }\n\n sendOptimistic(encodedContent: EncodedContent) {\n return this.#group.sendOptimistic(encodedContent);\n }\n\n async send(encodedContent: EncodedContent) {\n return this.#group.send(encodedContent);\n }\n\n messages(options?: SafeListMessagesOptions) {\n return this.#group.findMessages(\n options ? fromSafeListMessagesOptions(options) : undefined,\n );\n }\n\n get consentState() {\n return this.#group.consentState();\n }\n\n updateConsentState(state: ConsentState) {\n this.#group.updateConsentState(state);\n }\n\n dmPeerInboxId() {\n return this.#group.dmPeerInboxId();\n }\n}\n","import type { Conversation, Conversations } from \"@xmtp/wasm-bindings\";\nimport {\n fromSafeCreateGroupOptions,\n fromSafeListConversationsOptions,\n toSafeMessage,\n type SafeCreateGroupOptions,\n type SafeListConversationsOptions,\n} from \"@/utils/conversions\";\nimport type { WorkerClient } from \"@/WorkerClient\";\nimport { WorkerConversation } from \"@/WorkerConversation\";\n\nexport class WorkerConversations {\n #client: WorkerClient;\n\n #conversations: Conversations;\n\n constructor(client: WorkerClient, conversations: Conversations) {\n this.#client = client;\n this.#conversations = conversations;\n }\n\n async sync() {\n return this.#conversations.sync();\n }\n\n getConversationById(id: string) {\n try {\n const group = this.#conversations.findGroupById(id);\n // findGroupById will throw if group is not found\n return new WorkerConversation(this.#client, group);\n } catch {\n return undefined;\n }\n }\n\n getMessageById(id: string) {\n try {\n // findMessageById will throw if message is not found\n const message = this.#conversations.findMessageById(id);\n return toSafeMessage(message);\n } catch {\n return undefined;\n }\n }\n\n getDmByInboxId(inboxId: string) {\n try {\n const group = this.#conversations.findDmByTargetInboxId(inboxId);\n return new WorkerConversation(this.#client, group);\n } catch {\n return undefined;\n }\n }\n\n async list(options?: SafeListConversationsOptions) {\n const groups = (await this.#conversations.list(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async listGroups(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const groups = (await this.#conversations.listGroups(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async listDms(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const groups = (await this.#conversations.listDms(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {\n const group = await this.#conversations.createGroup(\n accountAddresses,\n options ? fromSafeCreateGroupOptions(options) : undefined,\n );\n return new WorkerConversation(this.#client, group);\n }\n\n async newDm(accountAddress: string) {\n const group = await this.#conversations.createDm(accountAddress);\n return new WorkerConversation(this.#client, group);\n }\n}\n","import {\n type Client,\n type ConsentEntityType,\n type SignatureRequestType,\n} from \"@xmtp/wasm-bindings\";\nimport type { ClientOptions } from \"@/types\";\nimport { fromSafeConsent, type SafeConsent } from \"@/utils/conversions\";\nimport { createClient } from \"@/utils/createClient\";\nimport { WorkerConversations } from \"@/WorkerConversations\";\n\nexport class WorkerClient {\n #client: Client;\n\n #conversations: WorkerConversations;\n\n #accountAddress: string;\n\n constructor(client: Client) {\n this.#client = client;\n this.#accountAddress = client.accountAddress;\n this.#conversations = new WorkerConversations(this, client.conversations());\n }\n\n static async create(\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: Omit<ClientOptions, \"codecs\">,\n ) {\n const client = await createClient(accountAddress, encryptionKey, options);\n return new WorkerClient(client);\n }\n\n get accountAddress() {\n return this.#accountAddress;\n }\n\n get inboxId() {\n return this.#client.inboxId;\n }\n\n get installationId() {\n return this.#client.installationId;\n }\n\n get isRegistered() {\n return this.#client.isRegistered;\n }\n\n async getCreateInboxSignatureText() {\n try {\n return await this.#client.createInboxSignatureText();\n } catch {\n return undefined;\n }\n }\n\n async getAddWalletSignatureText(accountAddress: string) {\n try {\n return await this.#client.addWalletSignatureText(\n this.#accountAddress,\n accountAddress,\n );\n } catch {\n return undefined;\n }\n }\n\n async getRevokeWalletSignatureText(accountAddress: string) {\n try {\n return await this.#client.revokeWalletSignatureText(accountAddress);\n } catch {\n return undefined;\n }\n }\n\n async getRevokeInstallationsSignatureText() {\n try {\n return await this.#client.revokeInstallationsSignatureText();\n } catch {\n return undefined;\n }\n }\n\n async addSignature(type: SignatureRequestType, bytes: Uint8Array) {\n return this.#client.addSignature(type, bytes);\n }\n\n async addScwSignature(\n type: SignatureRequestType,\n bytes: Uint8Array,\n chainId: bigint,\n blockNumber?: bigint,\n ) {\n return this.#client.addScwSignature(type, bytes, chainId, blockNumber);\n }\n\n async applySignatures() {\n return this.#client.applySignatureRequests();\n }\n\n async canMessage(accountAddresses: string[]) {\n return this.#client.canMessage(accountAddresses) as Promise<\n Map<string, boolean>\n >;\n }\n\n async registerIdentity() {\n return this.#client.registerIdentity();\n }\n\n async findInboxIdByAddress(address: string) {\n return this.#client.findInboxIdByAddress(address);\n }\n\n async inboxState(refreshFromNetwork: boolean) {\n return this.#client.inboxState(refreshFromNetwork);\n }\n\n async getLatestInboxState(inboxId: string) {\n return this.#client.getLatestInboxState(inboxId);\n }\n\n async setConsentStates(records: SafeConsent[]) {\n return this.#client.setConsentStates(records.map(fromSafeConsent));\n }\n\n async getConsentState(entityType: ConsentEntityType, entity: string) {\n return this.#client.getConsentState(entityType, entity);\n }\n\n get conversations() {\n return this.#conversations;\n }\n}\n","import init, {\n createClient as createWasmClient,\n generateInboxId,\n getInboxIdForAddress,\n LogOptions,\n} from \"@xmtp/wasm-bindings\";\nimport { ApiUrls } from \"@/constants\";\nimport type { ClientOptions } from \"@/types\";\n\nexport const createClient = async (\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: Omit<ClientOptions, \"codecs\">,\n) => {\n // initialize WASM module\n await init();\n\n const host = options?.apiUrl ?? ApiUrls[options?.env ?? \"dev\"];\n // TODO: add db path validation\n // - must end with .db3\n // - must not contain invalid characters\n // - must not start with a dot\n const dbPath =\n options?.dbPath ?? `xmtp-${options?.env ?? \"dev\"}-${accountAddress}.db3`;\n\n const inboxId =\n (await getInboxIdForAddress(host, accountAddress)) ||\n generateInboxId(accountAddress);\n\n const isLogging =\n options &&\n (options.loggingLevel !== undefined ||\n options.structuredLogging ||\n options.performanceLogging);\n\n return createWasmClient(\n host,\n inboxId,\n accountAddress,\n dbPath,\n encryptionKey,\n undefined,\n isLogging\n ? new LogOptions(\n options.structuredLogging ?? false,\n options.performanceLogging ?? false,\n options.loggingLevel,\n )\n : undefined,\n );\n};\n","import type {\n ClientEventsActions,\n ClientEventsClientMessageData,\n ClientEventsErrorData,\n ClientEventsWorkerPostMessageData,\n} from \"@/types\";\nimport {\n fromEncodedContent,\n fromSafeEncodedContent,\n toSafeConversation,\n toSafeInboxState,\n toSafeMessage,\n} from \"@/utils/conversions\";\nimport { WorkerClient } from \"@/WorkerClient\";\n\nlet client: WorkerClient;\nlet enableLogging = false;\n\n/**\n * Type-safe postMessage\n */\nconst postMessage = <A extends ClientEventsActions>(\n data: ClientEventsWorkerPostMessageData<A>,\n) => {\n self.postMessage(data);\n};\n\n/**\n * Type-safe postMessage for errors\n */\nconst postMessageError = (data: ClientEventsErrorData) => {\n self.postMessage(data);\n};\n\nself.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {\n const { action, id, data } = event.data;\n\n if (enableLogging) {\n console.log(\"client worker received event data\", event.data);\n }\n\n // a client is required for all actions except init\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (action !== \"init\" && !client) {\n postMessageError({\n id,\n action,\n error: \"Client not initialized\",\n });\n return;\n }\n\n try {\n switch (action) {\n /**\n * Client actions\n */\n case \"init\":\n client = await WorkerClient.create(\n data.address,\n data.encryptionKey,\n data.options,\n );\n enableLogging =\n data.options?.loggingLevel !== undefined &&\n data.options.loggingLevel !== \"off\";\n postMessage({\n id,\n action,\n result: {\n inboxId: client.inboxId,\n installationId: client.installationId,\n },\n });\n break;\n case \"getCreateInboxSignatureText\": {\n const result = await client.getCreateInboxSignatureText();\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"getAddWalletSignatureText\": {\n const result = await client.getAddWalletSignatureText(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"getRevokeWalletSignatureText\": {\n const result = await client.getRevokeWalletSignatureText(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"getRevokeInstallationsSignatureText\": {\n const result = await client.getRevokeInstallationsSignatureText();\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"addSignature\":\n await client.addSignature(data.type, data.bytes);\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"addScwSignature\":\n await client.addScwSignature(\n data.type,\n data.bytes,\n data.chainId,\n data.blockNumber,\n );\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"applySignatures\":\n await client.applySignatures();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"registerIdentity\":\n await client.registerIdentity();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"isRegistered\": {\n const result = client.isRegistered;\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"canMessage\": {\n const result = await client.canMessage(data.accountAddresses);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"inboxState\": {\n const result = await client.inboxState(data.refreshFromNetwork);\n postMessage({\n id,\n action,\n result: toSafeInboxState(result),\n });\n break;\n }\n case \"getLatestInboxState\": {\n const result = await client.getLatestInboxState(data.inboxId);\n postMessage({\n id,\n action,\n result: toSafeInboxState(result),\n });\n break;\n }\n case \"setConsentStates\": {\n await client.setConsentStates(data.records);\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"getConsentState\": {\n const result = await client.getConsentState(\n data.entityType,\n data.entity,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"findInboxIdByAddress\": {\n const result = await client.findInboxIdByAddress(data.address);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n /**\n * Conversations actions\n */\n case \"getConversations\": {\n const conversations = await client.conversations.list(data.options);\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"getGroups\": {\n const conversations = await client.conversations.listGroups(\n data.options,\n );\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"getDms\": {\n const conversations = await client.conversations.listDms(data.options);\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"newGroup\": {\n const conversation = await client.conversations.newGroup(\n data.accountAddresses,\n data.options,\n );\n postMessage({\n id,\n action,\n result: toSafeConversation(conversation),\n });\n break;\n }\n case \"newDm\": {\n const conversation = await client.conversations.newDm(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result: toSafeConversation(conversation),\n });\n break;\n }\n case \"syncConversations\": {\n await client.conversations.sync();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"getConversationById\": {\n const conversation = client.conversations.getConversationById(data.id);\n postMessage({\n id,\n action,\n result: conversation ? toSafeConversation(conversation) : undefined,\n });\n break;\n }\n case \"getMessageById\": {\n const message = client.conversations.getMessageById(data.id);\n postMessage({\n id,\n action,\n result: message,\n });\n break;\n }\n case \"getDmByInboxId\": {\n const conversation = client.conversations.getDmByInboxId(data.inboxId);\n postMessage({\n id,\n action,\n result: conversation ? toSafeConversation(conversation) : undefined,\n });\n break;\n }\n /**\n * Group actions\n */\n case \"syncGroup\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.sync();\n postMessage({\n id,\n action,\n result: toSafeConversation(group),\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupName\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateName(data.name);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupDescription\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateDescription(data.description);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupImageUrlSquare\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateImageUrl(data.imageUrl);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupPinnedFrameUrl\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updatePinnedFrameUrl(data.pinnedFrameUrl);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"sendGroupMessage\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = await group.send(\n fromEncodedContent(fromSafeEncodedContent(data.content)),\n );\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"sendOptimisticGroupMessage\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.sendOptimistic(\n fromEncodedContent(fromSafeEncodedContent(data.content)),\n );\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"publishGroupMessages\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.publishMessages();\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupMessages\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const messages = group.messages(data.options);\n postMessage({\n id,\n action,\n result: messages.map((message) => toSafeMessage(message)),\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = await group.members();\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupAdmins\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.admins,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupSuperAdmins\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.superAdmins,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupConsentState\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.consentState,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupConsentState\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n group.updateConsentState(data.state);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addMembers(data.accountAddresses);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeMembers(data.accountAddresses);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupMembersByInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addMembersByInboxId(data.inboxIds);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupMembersByInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeMembersByInboxId(data.inboxIds);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"isGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.isAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"isGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.isSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getDmPeerInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.dmPeerInboxId();\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n }\n } catch (e) {\n postMessageError({\n id,\n action,\n error: (e as Error).message,\n });\n }\n};\n"],"names":["fromEncodedContent","content","WasmEncodedContent","contentTypeId","type","WasmContentTypeId","authorityId","typeId","versionMajor","versionMinor","Map","Object","entries","parameters","fallback","compression","toSafeEncodedContent","fromSafeEncodedContent","ContentTypeId","toSafeMessage","message","fromEntries","convoId","deliveryStatus","id","kind","senderInboxId","sentAtNs","fromSafeListConversationsOptions","options","ListConversationsOptions","allowedStates","conversationType","createdAfterNs","createdBeforeNs","limit","toSafeConversation","conversation","name","imageUrl","description","pinnedFrameUrl","permissions","policyType","policySet","addAdminPolicy","addMemberPolicy","removeAdminPolicy","removeMemberPolicy","updateGroupDescriptionPolicy","updateGroupImageUrlSquarePolicy","updateGroupNamePolicy","updateGroupPinnedFrameUrlPolicy","isActive","addedByInboxId","metadata","admins","superAdmins","createdAtNs","toSafeInstallation","installation","clientTimestampNs","toSafeInboxState","inboxState","accountAddresses","inboxId","installations","map","recoveryAddress","fromSafeConsent","consent","Consent","entityType","state","entity","ApiUrls","local","dev","production","WorkerConversation","client","group","constructor","this","groupName","updateName","updateGroupName","groupImageUrlSquare","updateImageUrl","updateGroupImageUrlSquare","groupDescription","updateDescription","updateGroupDescription","groupPinnedFrameUrl","updatePinnedFrameUrl","updateGroupPinnedFrameUrl","groupMetadata","creatorInboxId","members","listMembers","member","consentState","installationIds","permissionLevel","toSafeGroupMember","adminList","superAdminList","groupPermissions","isAdmin","isSuperAdmin","sync","addMembers","addMembersByInboxId","inboxIds","removeMembers","removeMembersByInboxId","addAdmin","removeAdmin","addSuperAdmin","removeSuperAdmin","publishMessages","sendOptimistic","encodedContent","send","messages","findMessages","ListMessagesOptions","sentBeforeNs","sentAfterNs","direction","fromSafeListMessagesOptions","undefined","updateConsentState","dmPeerInboxId","WorkerConversations","conversations","getConversationById","findGroupById","getMessageById","findMessageById","getDmByInboxId","findDmByTargetInboxId","list","listGroups","listDms","newGroup","createGroup","CreateGroupOptions","imageUrlSquare","fromSafeCreateGroupOptions","newDm","accountAddress","createDm","WorkerClient","create","encryptionKey","async","init","host","apiUrl","env","dbPath","getInboxIdForAddress","generateInboxId","isLogging","loggingLevel","structuredLogging","performanceLogging","createWasmClient","LogOptions","createClient","installationId","isRegistered","getCreateInboxSignatureText","createInboxSignatureText","getAddWalletSignatureText","addWalletSignatureText","getRevokeWalletSignatureText","revokeWalletSignatureText","getRevokeInstallationsSignatureText","revokeInstallationsSignatureText","addSignature","bytes","addScwSignature","chainId","blockNumber","applySignatures","applySignatureRequests","canMessage","registerIdentity","findInboxIdByAddress","address","refreshFromNetwork","getLatestInboxState","setConsentStates","records","getConsentState","enableLogging","postMessage","data","self","postMessageError","onmessage","event","action","console","log","result","error","e"],"mappings":"sTA4BO,MAyDMA,EACXC,IAEA,WAAIC,GAjDJC,EAkDoBF,EAAQG,KAhD5B,IAAIC,EACFF,EAAcG,YACdH,EAAcI,OACdJ,EAAcK,aACdL,EAAcM,eA6Cd,IAAIC,IAAIC,OAAOC,QAAQX,EAAQY,aAC/BZ,EAAQa,SACRb,EAAQc,YACRd,EAAQA,SAvDqB,IAC/BE,CAuDC,EAU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
{"version":3,"file":"client.js","sources":["../../src/utils/conversions.ts","../../src/constants.ts","../../src/WorkerConversation.ts","../../src/WorkerConversations.ts","../../src/WorkerClient.ts","../../src/utils/createClient.ts","../../src/workers/client.ts"],"sourcesContent":["import {\n ContentTypeId,\n type EncodedContent,\n} from \"@xmtp/content-type-primitives\";\nimport {\n Consent,\n CreateGroupOptions,\n GroupMember,\n ListConversationsOptions,\n ListMessagesOptions,\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 GroupPermissionsOptions,\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 SafeCreateGroupOptions = {\n permissions?: GroupPermissionsOptions;\n name?: string;\n imageUrlSquare?: string;\n description?: string;\n pinnedFrameUrl?: string;\n};\n\nexport const toSafeCreateGroupOptions = (\n options: CreateGroupOptions,\n): SafeCreateGroupOptions => ({\n permissions: options.permissions,\n name: options.groupName,\n imageUrlSquare: options.groupImageUrlSquare,\n description: options.groupDescription,\n pinnedFrameUrl: options.groupPinnedFrameUrl,\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 );\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 };\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 = (\n conversation: WorkerConversation,\n): SafeConversation => ({\n id: conversation.id,\n name: conversation.name,\n imageUrl: conversation.imageUrl,\n description: conversation.description,\n pinnedFrameUrl: conversation.pinnedFrameUrl,\n permissions: {\n policyType: conversation.permissions.policyType,\n policySet: {\n addAdminPolicy: conversation.permissions.policySet.addAdminPolicy,\n addMemberPolicy: conversation.permissions.policySet.addMemberPolicy,\n removeAdminPolicy: conversation.permissions.policySet.removeAdminPolicy,\n removeMemberPolicy: conversation.permissions.policySet.removeMemberPolicy,\n updateGroupDescriptionPolicy:\n conversation.permissions.policySet.updateGroupDescriptionPolicy,\n updateGroupImageUrlSquarePolicy:\n conversation.permissions.policySet.updateGroupImageUrlSquarePolicy,\n updateGroupNamePolicy:\n conversation.permissions.policySet.updateGroupNamePolicy,\n updateGroupPinnedFrameUrlPolicy:\n conversation.permissions.policySet.updateGroupPinnedFrameUrlPolicy,\n },\n },\n isActive: conversation.isActive,\n addedByInboxId: conversation.addedByInboxId,\n metadata: conversation.metadata,\n admins: conversation.admins,\n superAdmins: conversation.superAdmins,\n createdAtNs: conversation.createdAtNs,\n});\n\nexport type SafeInstallation = {\n id: string;\n clientTimestampNs?: bigint;\n};\n\nexport const toSafeInstallation = (\n installation: Installation,\n): SafeInstallation => ({\n id: installation.id,\n clientTimestampNs: installation.clientTimestampNs,\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","export const ApiUrls = {\n local: \"http://localhost:5555\",\n dev: \"https://dev.xmtp.network\",\n production: \"https://production.xmtp.network\",\n} as const;\n","import type {\n ConsentState,\n Conversation,\n EncodedContent,\n GroupMember,\n} from \"@xmtp/wasm-bindings\";\nimport {\n fromSafeListMessagesOptions,\n toSafeGroupMember,\n type SafeListMessagesOptions,\n} from \"@/utils/conversions\";\nimport type { WorkerClient } from \"@/WorkerClient\";\n\nexport class WorkerConversation {\n // eslint-disable-next-line no-unused-private-class-members\n #client: WorkerClient;\n\n #group: Conversation;\n\n constructor(client: WorkerClient, group: Conversation) {\n this.#client = client;\n this.#group = group;\n }\n\n get id() {\n return this.#group.id();\n }\n\n get name() {\n return this.#group.groupName();\n }\n\n async updateName(name: string) {\n return this.#group.updateGroupName(name);\n }\n\n get imageUrl() {\n return this.#group.groupImageUrlSquare();\n }\n\n async updateImageUrl(imageUrl: string) {\n return this.#group.updateGroupImageUrlSquare(imageUrl);\n }\n\n get description() {\n return this.#group.groupDescription();\n }\n\n async updateDescription(description: string) {\n return this.#group.updateGroupDescription(description);\n }\n\n get pinnedFrameUrl() {\n return this.#group.groupPinnedFrameUrl();\n }\n\n async updatePinnedFrameUrl(pinnedFrameUrl: string) {\n return this.#group.updateGroupPinnedFrameUrl(pinnedFrameUrl);\n }\n\n get isActive() {\n return this.#group.isActive();\n }\n\n get addedByInboxId() {\n return this.#group.addedByInboxId();\n }\n\n get createdAtNs() {\n return this.#group.createdAtNs();\n }\n\n get metadata() {\n const metadata = this.#group.groupMetadata();\n return {\n creatorInboxId: metadata.creatorInboxId(),\n conversationType: metadata.conversationType(),\n };\n }\n\n async members() {\n const members = (await this.#group.listMembers()) as GroupMember[];\n return members.map((member) => toSafeGroupMember(member));\n }\n\n get admins() {\n return this.#group.adminList();\n }\n\n get superAdmins() {\n return this.#group.superAdminList();\n }\n\n get permissions() {\n const permissions = this.#group.groupPermissions();\n return {\n policyType: permissions.policyType(),\n policySet: permissions.policySet(),\n };\n }\n\n isAdmin(inboxId: string) {\n return this.#group.isAdmin(inboxId);\n }\n\n isSuperAdmin(inboxId: string) {\n return this.#group.isSuperAdmin(inboxId);\n }\n\n async sync() {\n return this.#group.sync();\n }\n\n async addMembers(accountAddresses: string[]) {\n return this.#group.addMembers(accountAddresses);\n }\n\n async addMembersByInboxId(inboxIds: string[]) {\n return this.#group.addMembersByInboxId(inboxIds);\n }\n\n async removeMembers(accountAddresses: string[]) {\n return this.#group.removeMembers(accountAddresses);\n }\n\n async removeMembersByInboxId(inboxIds: string[]) {\n return this.#group.removeMembersByInboxId(inboxIds);\n }\n\n async addAdmin(inboxId: string) {\n return this.#group.addAdmin(inboxId);\n }\n\n async removeAdmin(inboxId: string) {\n return this.#group.removeAdmin(inboxId);\n }\n\n async addSuperAdmin(inboxId: string) {\n return this.#group.addSuperAdmin(inboxId);\n }\n\n async removeSuperAdmin(inboxId: string) {\n return this.#group.removeSuperAdmin(inboxId);\n }\n\n async publishMessages() {\n return this.#group.publishMessages();\n }\n\n sendOptimistic(encodedContent: EncodedContent) {\n return this.#group.sendOptimistic(encodedContent);\n }\n\n async send(encodedContent: EncodedContent) {\n return this.#group.send(encodedContent);\n }\n\n messages(options?: SafeListMessagesOptions) {\n return this.#group.findMessages(\n options ? fromSafeListMessagesOptions(options) : undefined,\n );\n }\n\n get consentState() {\n return this.#group.consentState();\n }\n\n updateConsentState(state: ConsentState) {\n this.#group.updateConsentState(state);\n }\n\n dmPeerInboxId() {\n return this.#group.dmPeerInboxId();\n }\n}\n","import type { Conversation, Conversations } from \"@xmtp/wasm-bindings\";\nimport {\n fromSafeCreateGroupOptions,\n fromSafeListConversationsOptions,\n toSafeMessage,\n type SafeCreateGroupOptions,\n type SafeListConversationsOptions,\n} from \"@/utils/conversions\";\nimport type { WorkerClient } from \"@/WorkerClient\";\nimport { WorkerConversation } from \"@/WorkerConversation\";\n\nexport class WorkerConversations {\n #client: WorkerClient;\n\n #conversations: Conversations;\n\n constructor(client: WorkerClient, conversations: Conversations) {\n this.#client = client;\n this.#conversations = conversations;\n }\n\n async sync() {\n return this.#conversations.sync();\n }\n\n getConversationById(id: string) {\n try {\n const group = this.#conversations.findGroupById(id);\n // findGroupById will throw if group is not found\n return new WorkerConversation(this.#client, group);\n } catch {\n return undefined;\n }\n }\n\n getMessageById(id: string) {\n try {\n // findMessageById will throw if message is not found\n const message = this.#conversations.findMessageById(id);\n return toSafeMessage(message);\n } catch {\n return undefined;\n }\n }\n\n getDmByInboxId(inboxId: string) {\n try {\n const group = this.#conversations.findDmByTargetInboxId(inboxId);\n return new WorkerConversation(this.#client, group);\n } catch {\n return undefined;\n }\n }\n\n async list(options?: SafeListConversationsOptions) {\n const groups = (await this.#conversations.list(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async listGroups(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const groups = (await this.#conversations.listGroups(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async listDms(\n options?: Omit<SafeListConversationsOptions, \"conversation_type\">,\n ) {\n const groups = (await this.#conversations.listDms(\n options ? fromSafeListConversationsOptions(options) : undefined,\n )) as Conversation[];\n return groups.map((group) => new WorkerConversation(this.#client, group));\n }\n\n async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {\n const group = await this.#conversations.createGroup(\n accountAddresses,\n options ? fromSafeCreateGroupOptions(options) : undefined,\n );\n return new WorkerConversation(this.#client, group);\n }\n\n async newDm(accountAddress: string) {\n const group = await this.#conversations.createDm(accountAddress);\n return new WorkerConversation(this.#client, group);\n }\n}\n","import {\n type Client,\n type ConsentEntityType,\n type SignatureRequestType,\n} from \"@xmtp/wasm-bindings\";\nimport type { ClientOptions } from \"@/types\";\nimport { fromSafeConsent, type SafeConsent } from \"@/utils/conversions\";\nimport { createClient } from \"@/utils/createClient\";\nimport { WorkerConversations } from \"@/WorkerConversations\";\n\nexport class WorkerClient {\n #client: Client;\n\n #conversations: WorkerConversations;\n\n #accountAddress: string;\n\n constructor(client: Client) {\n this.#client = client;\n this.#accountAddress = client.accountAddress;\n this.#conversations = new WorkerConversations(this, client.conversations());\n }\n\n static async create(\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: Omit<ClientOptions, \"codecs\">,\n ) {\n const client = await createClient(accountAddress, encryptionKey, options);\n return new WorkerClient(client);\n }\n\n get accountAddress() {\n return this.#accountAddress;\n }\n\n get inboxId() {\n return this.#client.inboxId;\n }\n\n get installationId() {\n return this.#client.installationId;\n }\n\n get isRegistered() {\n return this.#client.isRegistered;\n }\n\n async createInboxSignatureText() {\n try {\n return await this.#client.createInboxSignatureText();\n } catch {\n return undefined;\n }\n }\n\n async addAccountSignatureText(accountAddress: string) {\n try {\n return await this.#client.addWalletSignatureText(\n this.#accountAddress,\n accountAddress,\n );\n } catch {\n return undefined;\n }\n }\n\n async removeAccountSignatureText(accountAddress: string) {\n try {\n return await this.#client.revokeWalletSignatureText(accountAddress);\n } catch {\n return undefined;\n }\n }\n\n async revokeInstallationsSignatureText() {\n try {\n return await this.#client.revokeInstallationsSignatureText();\n } catch {\n return undefined;\n }\n }\n\n async addSignature(type: SignatureRequestType, bytes: Uint8Array) {\n return this.#client.addSignature(type, bytes);\n }\n\n async addScwSignature(\n type: SignatureRequestType,\n bytes: Uint8Array,\n chainId: bigint,\n blockNumber?: bigint,\n ) {\n return this.#client.addScwSignature(type, bytes, chainId, blockNumber);\n }\n\n async applySignatures() {\n return this.#client.applySignatureRequests();\n }\n\n async canMessage(accountAddresses: string[]) {\n return this.#client.canMessage(accountAddresses) as Promise<\n Map<string, boolean>\n >;\n }\n\n async registerIdentity() {\n return this.#client.registerIdentity();\n }\n\n async findInboxIdByAddress(address: string) {\n return this.#client.findInboxIdByAddress(address);\n }\n\n async inboxState(refreshFromNetwork: boolean) {\n return this.#client.inboxState(refreshFromNetwork);\n }\n\n async getLatestInboxState(inboxId: string) {\n return this.#client.getLatestInboxState(inboxId);\n }\n\n async setConsentStates(records: SafeConsent[]) {\n return this.#client.setConsentStates(records.map(fromSafeConsent));\n }\n\n async getConsentState(entityType: ConsentEntityType, entity: string) {\n return this.#client.getConsentState(entityType, entity);\n }\n\n get conversations() {\n return this.#conversations;\n }\n}\n","import init, {\n createClient as createWasmClient,\n generateInboxId,\n getInboxIdForAddress,\n LogOptions,\n} from \"@xmtp/wasm-bindings\";\nimport { ApiUrls } from \"@/constants\";\nimport type { ClientOptions } from \"@/types\";\n\nexport const createClient = async (\n accountAddress: string,\n encryptionKey: Uint8Array,\n options?: Omit<ClientOptions, \"codecs\">,\n) => {\n // initialize WASM module\n await init();\n\n const host = options?.apiUrl ?? ApiUrls[options?.env ?? \"dev\"];\n // TODO: add db path validation\n // - must end with .db3\n // - must not contain invalid characters\n // - must not start with a dot\n const dbPath =\n options?.dbPath ?? `xmtp-${options?.env ?? \"dev\"}-${accountAddress}.db3`;\n\n const inboxId =\n (await getInboxIdForAddress(host, accountAddress)) ||\n generateInboxId(accountAddress);\n\n const isLogging =\n options &&\n (options.loggingLevel !== undefined ||\n options.structuredLogging ||\n options.performanceLogging);\n\n return createWasmClient(\n host,\n inboxId,\n accountAddress,\n dbPath,\n encryptionKey,\n undefined,\n isLogging\n ? new LogOptions(\n options.structuredLogging ?? false,\n options.performanceLogging ?? false,\n options.loggingLevel,\n )\n : undefined,\n );\n};\n","import type {\n ClientEventsActions,\n ClientEventsClientMessageData,\n ClientEventsErrorData,\n ClientEventsWorkerPostMessageData,\n} from \"@/types\";\nimport {\n fromEncodedContent,\n fromSafeEncodedContent,\n toSafeConversation,\n toSafeInboxState,\n toSafeMessage,\n} from \"@/utils/conversions\";\nimport { WorkerClient } from \"@/WorkerClient\";\n\nlet client: WorkerClient;\nlet enableLogging = false;\n\n/**\n * Type-safe postMessage\n */\nconst postMessage = <A extends ClientEventsActions>(\n data: ClientEventsWorkerPostMessageData<A>,\n) => {\n self.postMessage(data);\n};\n\n/**\n * Type-safe postMessage for errors\n */\nconst postMessageError = (data: ClientEventsErrorData) => {\n self.postMessage(data);\n};\n\nself.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {\n const { action, id, data } = event.data;\n\n if (enableLogging) {\n console.log(\"client worker received event data\", event.data);\n }\n\n // a client is required for all actions except init\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (action !== \"init\" && !client) {\n postMessageError({\n id,\n action,\n error: \"Client not initialized\",\n });\n return;\n }\n\n try {\n switch (action) {\n /**\n * Client actions\n */\n case \"init\":\n client = await WorkerClient.create(\n data.address,\n data.encryptionKey,\n data.options,\n );\n enableLogging =\n data.options?.loggingLevel !== undefined &&\n data.options.loggingLevel !== \"off\";\n postMessage({\n id,\n action,\n result: {\n inboxId: client.inboxId,\n installationId: client.installationId,\n },\n });\n break;\n case \"createInboxSignatureText\": {\n const result = await client.createInboxSignatureText();\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"addAccountSignatureText\": {\n const result = await client.addAccountSignatureText(\n data.newAccountAddress,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"removeAccountSignatureText\": {\n const result = await client.removeAccountSignatureText(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"revokeInstallationsSignatureText\": {\n const result = await client.revokeInstallationsSignatureText();\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"addSignature\":\n await client.addSignature(data.type, data.bytes);\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"addScwSignature\":\n await client.addScwSignature(\n data.type,\n data.bytes,\n data.chainId,\n data.blockNumber,\n );\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"applySignatures\":\n await client.applySignatures();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"registerIdentity\":\n await client.registerIdentity();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n case \"isRegistered\": {\n const result = client.isRegistered;\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"canMessage\": {\n const result = await client.canMessage(data.accountAddresses);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"inboxState\": {\n const result = await client.inboxState(data.refreshFromNetwork);\n postMessage({\n id,\n action,\n result: toSafeInboxState(result),\n });\n break;\n }\n case \"getLatestInboxState\": {\n const result = await client.getLatestInboxState(data.inboxId);\n postMessage({\n id,\n action,\n result: toSafeInboxState(result),\n });\n break;\n }\n case \"setConsentStates\": {\n await client.setConsentStates(data.records);\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"getConsentState\": {\n const result = await client.getConsentState(\n data.entityType,\n data.entity,\n );\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n case \"findInboxIdByAddress\": {\n const result = await client.findInboxIdByAddress(data.address);\n postMessage({\n id,\n action,\n result,\n });\n break;\n }\n /**\n * Conversations actions\n */\n case \"getConversations\": {\n const conversations = await client.conversations.list(data.options);\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"getGroups\": {\n const conversations = await client.conversations.listGroups(\n data.options,\n );\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"getDms\": {\n const conversations = await client.conversations.listDms(data.options);\n postMessage({\n id,\n action,\n result: conversations.map((conversation) =>\n toSafeConversation(conversation),\n ),\n });\n break;\n }\n case \"newGroup\": {\n const conversation = await client.conversations.newGroup(\n data.accountAddresses,\n data.options,\n );\n postMessage({\n id,\n action,\n result: toSafeConversation(conversation),\n });\n break;\n }\n case \"newDm\": {\n const conversation = await client.conversations.newDm(\n data.accountAddress,\n );\n postMessage({\n id,\n action,\n result: toSafeConversation(conversation),\n });\n break;\n }\n case \"syncConversations\": {\n await client.conversations.sync();\n postMessage({\n id,\n action,\n result: undefined,\n });\n break;\n }\n case \"getConversationById\": {\n const conversation = client.conversations.getConversationById(data.id);\n postMessage({\n id,\n action,\n result: conversation ? toSafeConversation(conversation) : undefined,\n });\n break;\n }\n case \"getMessageById\": {\n const message = client.conversations.getMessageById(data.id);\n postMessage({\n id,\n action,\n result: message,\n });\n break;\n }\n case \"getDmByInboxId\": {\n const conversation = client.conversations.getDmByInboxId(data.inboxId);\n postMessage({\n id,\n action,\n result: conversation ? toSafeConversation(conversation) : undefined,\n });\n break;\n }\n /**\n * Group actions\n */\n case \"syncGroup\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.sync();\n postMessage({\n id,\n action,\n result: toSafeConversation(group),\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupName\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateName(data.name);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupDescription\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateDescription(data.description);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupImageUrlSquare\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updateImageUrl(data.imageUrl);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupPinnedFrameUrl\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.updatePinnedFrameUrl(data.pinnedFrameUrl);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"sendGroupMessage\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = await group.send(\n fromEncodedContent(fromSafeEncodedContent(data.content)),\n );\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"sendOptimisticGroupMessage\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.sendOptimistic(\n fromEncodedContent(fromSafeEncodedContent(data.content)),\n );\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"publishGroupMessages\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.publishMessages();\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupMessages\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const messages = group.messages(data.options);\n postMessage({\n id,\n action,\n result: messages.map((message) => toSafeMessage(message)),\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = await group.members();\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupAdmins\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.admins,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupSuperAdmins\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.superAdmins,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getGroupConsentState\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n postMessage({\n id,\n action,\n result: group.consentState,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"updateGroupConsentState\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n group.updateConsentState(data.state);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addMembers(data.accountAddresses);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupMembers\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeMembers(data.accountAddresses);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"addGroupMembersByInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.addMembersByInboxId(data.inboxIds);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"removeGroupMembersByInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n await group.removeMembersByInboxId(data.inboxIds);\n postMessage({\n id,\n action,\n result: undefined,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"isGroupAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.isAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"isGroupSuperAdmin\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.isSuperAdmin(data.inboxId);\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n case \"getDmPeerInboxId\": {\n const group = client.conversations.getConversationById(data.id);\n if (group) {\n const result = group.dmPeerInboxId();\n postMessage({\n id,\n action,\n result,\n });\n } else {\n postMessageError({\n id,\n action,\n error: \"Group not found\",\n });\n }\n break;\n }\n }\n } catch (e) {\n postMessageError({\n id,\n action,\n error: (e as Error).message,\n });\n }\n};\n"],"names":["fromEncodedContent","content","WasmEncodedContent","contentTypeId","type","WasmContentTypeId","authorityId","typeId","versionMajor","versionMinor","Map","Object","entries","parameters","fallback","compression","toSafeEncodedContent","fromSafeEncodedContent","ContentTypeId","toSafeMessage","message","fromEntries","convoId","deliveryStatus","id","kind","senderInboxId","sentAtNs","fromSafeListConversationsOptions","options","ListConversationsOptions","allowedStates","conversationType","createdAfterNs","createdBeforeNs","limit","toSafeConversation","conversation","name","imageUrl","description","pinnedFrameUrl","permissions","policyType","policySet","addAdminPolicy","addMemberPolicy","removeAdminPolicy","removeMemberPolicy","updateGroupDescriptionPolicy","updateGroupImageUrlSquarePolicy","updateGroupNamePolicy","updateGroupPinnedFrameUrlPolicy","isActive","addedByInboxId","metadata","admins","superAdmins","createdAtNs","toSafeInstallation","installation","clientTimestampNs","toSafeInboxState","inboxState","accountAddresses","inboxId","installations","map","recoveryAddress","fromSafeConsent","consent","Consent","entityType","state","entity","ApiUrls","local","dev","production","WorkerConversation","client","group","constructor","this","groupName","updateName","updateGroupName","groupImageUrlSquare","updateImageUrl","updateGroupImageUrlSquare","groupDescription","updateDescription","updateGroupDescription","groupPinnedFrameUrl","updatePinnedFrameUrl","updateGroupPinnedFrameUrl","groupMetadata","creatorInboxId","members","listMembers","member","consentState","installationIds","permissionLevel","toSafeGroupMember","adminList","superAdminList","groupPermissions","isAdmin","isSuperAdmin","sync","addMembers","addMembersByInboxId","inboxIds","removeMembers","removeMembersByInboxId","addAdmin","removeAdmin","addSuperAdmin","removeSuperAdmin","publishMessages","sendOptimistic","encodedContent","send","messages","findMessages","ListMessagesOptions","sentBeforeNs","sentAfterNs","direction","fromSafeListMessagesOptions","undefined","updateConsentState","dmPeerInboxId","WorkerConversations","conversations","getConversationById","findGroupById","getMessageById","findMessageById","getDmByInboxId","findDmByTargetInboxId","list","listGroups","listDms","newGroup","createGroup","CreateGroupOptions","imageUrlSquare","fromSafeCreateGroupOptions","newDm","accountAddress","createDm","WorkerClient","create","encryptionKey","async","init","host","apiUrl","env","dbPath","getInboxIdForAddress","generateInboxId","isLogging","loggingLevel","structuredLogging","performanceLogging","createWasmClient","LogOptions","createClient","installationId","isRegistered","createInboxSignatureText","addAccountSignatureText","addWalletSignatureText","removeAccountSignatureText","revokeWalletSignatureText","revokeInstallationsSignatureText","addSignature","bytes","addScwSignature","chainId","blockNumber","applySignatures","applySignatureRequests","canMessage","registerIdentity","findInboxIdByAddress","address","refreshFromNetwork","getLatestInboxState","setConsentStates","records","getConsentState","enableLogging","postMessage","data","self","postMessageError","onmessage","event","action","console","log","result","newAccountAddress","error","e"],"mappings":"sTA4BO,MAyDMA,EACXC,IAEA,WAAIC,GAjDJC,EAkDoBF,EAAQG,KAhD5B,IAAIC,EACFF,EAAcG,YACdH,EAAcI,OACdJ,EAAcK,aACdL,EAAcM,eA6Cd,IAAIC,IAAIC,OAAOC,QAAQX,EAAQY,aAC/BZ,EAAQa,SACRb,EAAQc,YACRd,EAAQA,SAvDqB,IAC/BE,CAuDC,EAUUa,EACXf,IACwB,OACxBG,MAnDAD,EAmD0BF,EAAQG,KAlDX,CACvBE,YAAaH,EAAcG,YAC3BC,OAAQJ,EAAcI,OACtBC,aAAcL,EAAcK,aAC5BC,aAAcN,EAAcM,eA+C5BI,WAAYZ,EAAQY,WACpBC,SAAUb,EAAQa,SAClBC,YAAad,EAAQc,YACrBd,QAASA,EAAQA,SAxDgB,IACjCE,CAwDA,EAEWc,EACXhB,IACoB,OACpBG,MApDAD,EAoD4BF,EAAQG,KAlDpC,IAAIc,EAAc,CAChBZ,YAAaH,EAAcG,YAC3BC,OAAQJ,EAAcI,OACtBC,aAAcL,EAAcK,aAC5BC,aAAcN,EAAcM,gBA+C9BI,WAAYZ,EAAQY,WACpBC,SAAUb,EAAQa,SAClBC,YAAad,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O,CACT,MAAM4H,EAAS5H,EAAM2B,QAAQyF,EAAKpI,SAClCmI,EAAY,CACV5K,KACAkL,SACAG,UAEH,MACCN,EAAiB,CACf/K,KACAkL,SACAK,MAAO,oBAGX,KACD,CACD,IAAK,oBAAqB,CACxB,MAAM9H,EAAQD,EAAOuD,cAAcC,oBAAoB6D,EAAK7K,IAC5D,GAAIyD,EAAO,CACT,MAAM4H,EAAS5H,EAAM4B,aAAawF,EAAKpI,SACvCmI,EAAY,CACV5K,KACAkL,SACAG,UAEH,MACCN,EAAiB,CACf/K,KACAkL,SACAK,MAAO,oBAGX,KACD,CACD,IAAK,mBAAoB,CACvB,MAAM9H,EAAQD,EAAOuD,cAAcC,oBAAoB6D,EAAK7K,IAC5D,GAAIyD,EAAO,CACT,MAAM4H,EAAS5H,EAAMoD,gBACrB+D,EAAY,CACV5K,KACAkL,SACAG,UAEH,MACCN,EAAiB,CACf/K,KACAkL,SACAK,MAAO,oBAGX,KACD,EAEJ,CAAC,MAAOC,GACPT,EAAiB,CACf/K,KACAkL,SACAK,MAAQC,EAAY5L,SAEvB,MA5tBCmL,EAAiB,CACf/K,KACAkL,SACAK,MAAO,0BAytBV"}
|
package/package.json
CHANGED
package/src/Client.ts
CHANGED
|
@@ -9,38 +9,34 @@ import type {
|
|
|
9
9
|
import { TextCodec } from "@xmtp/content-type-text";
|
|
10
10
|
import {
|
|
11
11
|
GroupMessageKind,
|
|
12
|
+
SignatureRequestType,
|
|
12
13
|
type ConsentEntityType,
|
|
13
|
-
type SignatureRequestType,
|
|
14
14
|
} from "@xmtp/wasm-bindings";
|
|
15
15
|
import { ClientWorkerClass } from "@/ClientWorkerClass";
|
|
16
16
|
import { Conversations } from "@/Conversations";
|
|
17
|
-
import type { ClientOptions } from "@/types";
|
|
17
|
+
import type { ClientOptions, XmtpEnv } from "@/types";
|
|
18
18
|
import {
|
|
19
19
|
fromSafeEncodedContent,
|
|
20
20
|
toSafeEncodedContent,
|
|
21
21
|
type SafeConsent,
|
|
22
22
|
type SafeMessage,
|
|
23
23
|
} from "@/utils/conversions";
|
|
24
|
+
import { isSmartContractSigner, type Signer } from "@/utils/signer";
|
|
24
25
|
|
|
25
26
|
export class Client extends ClientWorkerClass {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
options?: ClientOptions;
|
|
29
|
-
|
|
30
|
-
#isReady = false;
|
|
31
|
-
|
|
32
|
-
#inboxId: string | undefined;
|
|
33
|
-
|
|
34
|
-
#installationId: string | undefined;
|
|
35
|
-
|
|
36
|
-
#conversations: Conversations;
|
|
37
|
-
|
|
27
|
+
#accountAddress: string;
|
|
38
28
|
#codecs: Map<string, ContentCodec>;
|
|
39
|
-
|
|
29
|
+
#conversations: Conversations;
|
|
40
30
|
#encryptionKey: Uint8Array;
|
|
31
|
+
#inboxId: string | undefined;
|
|
32
|
+
#installationId: string | undefined;
|
|
33
|
+
#isReady = false;
|
|
34
|
+
#signer: Signer;
|
|
35
|
+
options?: ClientOptions;
|
|
41
36
|
|
|
42
37
|
constructor(
|
|
43
|
-
|
|
38
|
+
signer: Signer,
|
|
39
|
+
accountAddress: string,
|
|
44
40
|
encryptionKey: Uint8Array,
|
|
45
41
|
options?: ClientOptions,
|
|
46
42
|
) {
|
|
@@ -51,9 +47,10 @@ export class Client extends ClientWorkerClass {
|
|
|
51
47
|
worker,
|
|
52
48
|
options?.loggingLevel !== undefined && options.loggingLevel !== "off",
|
|
53
49
|
);
|
|
54
|
-
this
|
|
50
|
+
this.#accountAddress = accountAddress;
|
|
55
51
|
this.options = options;
|
|
56
52
|
this.#encryptionKey = encryptionKey;
|
|
53
|
+
this.#signer = signer;
|
|
57
54
|
this.#conversations = new Conversations(this);
|
|
58
55
|
const codecs = [
|
|
59
56
|
new GroupUpdatedCodec(),
|
|
@@ -65,9 +62,13 @@ export class Client extends ClientWorkerClass {
|
|
|
65
62
|
);
|
|
66
63
|
}
|
|
67
64
|
|
|
65
|
+
get accountAddress() {
|
|
66
|
+
return this.#accountAddress;
|
|
67
|
+
}
|
|
68
|
+
|
|
68
69
|
async init() {
|
|
69
70
|
const result = await this.sendMessage("init", {
|
|
70
|
-
address: this.
|
|
71
|
+
address: this.accountAddress,
|
|
71
72
|
encryptionKey: this.#encryptionKey,
|
|
72
73
|
options: this.options,
|
|
73
74
|
});
|
|
@@ -77,12 +78,19 @@ export class Client extends ClientWorkerClass {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
static async create(
|
|
80
|
-
|
|
81
|
+
signer: Signer,
|
|
81
82
|
encryptionKey: Uint8Array,
|
|
82
83
|
options?: ClientOptions,
|
|
83
84
|
) {
|
|
84
|
-
const
|
|
85
|
+
const address = await signer.getAddress();
|
|
86
|
+
const client = new Client(signer, address, encryptionKey, options);
|
|
87
|
+
|
|
85
88
|
await client.init();
|
|
89
|
+
|
|
90
|
+
if (!options?.disableAutoRegister) {
|
|
91
|
+
await client.register();
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
return client;
|
|
87
95
|
}
|
|
88
96
|
|
|
@@ -98,48 +106,124 @@ export class Client extends ClientWorkerClass {
|
|
|
98
106
|
return this.#installationId;
|
|
99
107
|
}
|
|
100
108
|
|
|
101
|
-
async
|
|
102
|
-
return this.sendMessage("
|
|
109
|
+
async #createInboxSignatureText() {
|
|
110
|
+
return this.sendMessage("createInboxSignatureText", undefined);
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
async
|
|
106
|
-
return this.sendMessage("
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
async getRevokeWalletSignatureText(accountAddress: string) {
|
|
110
|
-
return this.sendMessage("getRevokeWalletSignatureText", { accountAddress });
|
|
113
|
+
async #addAccountSignatureText(newAccountAddress: string) {
|
|
114
|
+
return this.sendMessage("addAccountSignatureText", {
|
|
115
|
+
newAccountAddress,
|
|
116
|
+
});
|
|
111
117
|
}
|
|
112
118
|
|
|
113
|
-
async
|
|
114
|
-
return this.sendMessage("
|
|
119
|
+
async #removeAccountSignatureText(accountAddress: string) {
|
|
120
|
+
return this.sendMessage("removeAccountSignatureText", { accountAddress });
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
async
|
|
118
|
-
return this.sendMessage("
|
|
123
|
+
async #revokeInstallationsSignatureText() {
|
|
124
|
+
return this.sendMessage("revokeInstallationsSignatureText", undefined);
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
async
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
blockNumber?: bigint,
|
|
127
|
+
async #addSignature(
|
|
128
|
+
signatureType: SignatureRequestType,
|
|
129
|
+
signatureText: string,
|
|
130
|
+
signer: Signer,
|
|
126
131
|
) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
const signature = await signer.signMessage(signatureText);
|
|
133
|
+
|
|
134
|
+
if (isSmartContractSigner(signer)) {
|
|
135
|
+
await this.sendMessage("addScwSignature", {
|
|
136
|
+
type: signatureType,
|
|
137
|
+
bytes: signature,
|
|
138
|
+
chainId: signer.getChainId(),
|
|
139
|
+
blockNumber: signer.getBlockNumber(),
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
await this.sendMessage("addSignature", {
|
|
143
|
+
type: signatureType,
|
|
144
|
+
bytes: signature,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
133
147
|
}
|
|
134
148
|
|
|
135
|
-
async applySignatures() {
|
|
149
|
+
async #applySignatures() {
|
|
136
150
|
return this.sendMessage("applySignatures", undefined);
|
|
137
151
|
}
|
|
138
152
|
|
|
139
|
-
async
|
|
153
|
+
async register() {
|
|
154
|
+
const signatureText = await this.#createInboxSignatureText();
|
|
155
|
+
|
|
156
|
+
// if the signature text is not available, the client is already registered
|
|
157
|
+
if (!signatureText) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await this.#addSignature(
|
|
162
|
+
SignatureRequestType.CreateInbox,
|
|
163
|
+
signatureText,
|
|
164
|
+
this.#signer,
|
|
165
|
+
);
|
|
166
|
+
|
|
140
167
|
return this.sendMessage("registerIdentity", undefined);
|
|
141
168
|
}
|
|
142
169
|
|
|
170
|
+
async addAccount(newAccountSigner: Signer) {
|
|
171
|
+
const signatureText = await this.#addAccountSignatureText(
|
|
172
|
+
await newAccountSigner.getAddress(),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
if (!signatureText) {
|
|
176
|
+
throw new Error("Unable to generate add account signature text");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
await this.#addSignature(
|
|
180
|
+
SignatureRequestType.AddWallet,
|
|
181
|
+
signatureText,
|
|
182
|
+
this.#signer,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
await this.#addSignature(
|
|
186
|
+
SignatureRequestType.AddWallet,
|
|
187
|
+
signatureText,
|
|
188
|
+
newAccountSigner,
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
await this.#applySignatures();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async removeAccount(accountAddress: string) {
|
|
195
|
+
const signatureText =
|
|
196
|
+
await this.#removeAccountSignatureText(accountAddress);
|
|
197
|
+
|
|
198
|
+
if (!signatureText) {
|
|
199
|
+
throw new Error("Unable to generate remove account signature text");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
await this.#addSignature(
|
|
203
|
+
SignatureRequestType.RevokeWallet,
|
|
204
|
+
signatureText,
|
|
205
|
+
this.#signer,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
await this.#applySignatures();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async revokeInstallations() {
|
|
212
|
+
const signatureText = await this.#revokeInstallationsSignatureText();
|
|
213
|
+
|
|
214
|
+
if (!signatureText) {
|
|
215
|
+
throw new Error("Unable to generate revoke installations signature text");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
await this.#addSignature(
|
|
219
|
+
SignatureRequestType.RevokeInstallations,
|
|
220
|
+
signatureText,
|
|
221
|
+
this.#signer,
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
await this.#applySignatures();
|
|
225
|
+
}
|
|
226
|
+
|
|
143
227
|
async isRegistered() {
|
|
144
228
|
return this.sendMessage("isRegistered", undefined);
|
|
145
229
|
}
|
|
@@ -148,6 +232,23 @@ export class Client extends ClientWorkerClass {
|
|
|
148
232
|
return this.sendMessage("canMessage", { accountAddresses });
|
|
149
233
|
}
|
|
150
234
|
|
|
235
|
+
static async canMessage(accountAddresses: string[], env?: XmtpEnv) {
|
|
236
|
+
const accountAddress = "0x0000000000000000000000000000000000000000";
|
|
237
|
+
const signer: Signer = {
|
|
238
|
+
getAddress: () => accountAddress,
|
|
239
|
+
signMessage: () => new Uint8Array(),
|
|
240
|
+
};
|
|
241
|
+
const client = await Client.create(
|
|
242
|
+
signer,
|
|
243
|
+
window.crypto.getRandomValues(new Uint8Array(32)),
|
|
244
|
+
{
|
|
245
|
+
disableAutoRegister: true,
|
|
246
|
+
env,
|
|
247
|
+
},
|
|
248
|
+
);
|
|
249
|
+
return client.canMessage(accountAddresses);
|
|
250
|
+
}
|
|
251
|
+
|
|
151
252
|
async findInboxIdByAddress(address: string) {
|
|
152
253
|
return this.sendMessage("findInboxIdByAddress", { address });
|
|
153
254
|
}
|
package/src/WorkerClient.ts
CHANGED
|
@@ -46,7 +46,7 @@ export class WorkerClient {
|
|
|
46
46
|
return this.#client.isRegistered;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
async
|
|
49
|
+
async createInboxSignatureText() {
|
|
50
50
|
try {
|
|
51
51
|
return await this.#client.createInboxSignatureText();
|
|
52
52
|
} catch {
|
|
@@ -54,7 +54,7 @@ export class WorkerClient {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
async
|
|
57
|
+
async addAccountSignatureText(accountAddress: string) {
|
|
58
58
|
try {
|
|
59
59
|
return await this.#client.addWalletSignatureText(
|
|
60
60
|
this.#accountAddress,
|
|
@@ -65,7 +65,7 @@ export class WorkerClient {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
async
|
|
68
|
+
async removeAccountSignatureText(accountAddress: string) {
|
|
69
69
|
try {
|
|
70
70
|
return await this.#client.revokeWalletSignatureText(accountAddress);
|
|
71
71
|
} catch {
|
|
@@ -73,7 +73,7 @@ export class WorkerClient {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
async
|
|
76
|
+
async revokeInstallationsSignatureText() {
|
|
77
77
|
try {
|
|
78
78
|
return await this.#client.revokeInstallationsSignatureText();
|
|
79
79
|
} catch {
|