diff --git a/.changeset/little-tables-love.md b/.changeset/little-tables-love.md new file mode 100644 index 000000000..0d8834448 --- /dev/null +++ b/.changeset/little-tables-love.md @@ -0,0 +1,5 @@ +--- +"@xmtp/browser-sdk": patch +--- + +Update Browser SDK with latest WASM bindings diff --git a/examples/react-vite-browser-sdk/src/createClient.ts b/examples/react-vite-browser-sdk/src/createClient.ts index c9b362f5b..19874209d 100644 --- a/examples/react-vite-browser-sdk/src/createClient.ts +++ b/examples/react-vite-browser-sdk/src/createClient.ts @@ -1,4 +1,4 @@ -import { Client, WasmSignatureRequestType } from "@xmtp/browser-sdk"; +import { Client, SignatureRequestType } from "@xmtp/browser-sdk"; import { toBytes } from "viem/utils"; import { createWallet } from "./wallets"; @@ -24,10 +24,7 @@ export const createClient = async (walletKey: string) => { if (!isRegistered) { const signature = await getSignature(client, wallet); if (signature) { - await client.addSignature( - WasmSignatureRequestType.CreateInbox, - signature, - ); + await client.addSignature(SignatureRequestType.CreateInbox, signature); } await client.registerIdentity(); } diff --git a/sdks/browser-sdk/package.json b/sdks/browser-sdk/package.json index 7c02434a5..225ce1e9d 100644 --- a/sdks/browser-sdk/package.json +++ b/sdks/browser-sdk/package.json @@ -65,7 +65,7 @@ "@xmtp/content-type-primitives": "^1.0.1", "@xmtp/content-type-text": "^1.0.0", "@xmtp/proto": "^3.70.0", - "@xmtp/wasm-bindings": "^0.0.2", + "@xmtp/wasm-bindings": "^0.0.3", "uuid": "^10.0.0" }, "devDependencies": { diff --git a/sdks/browser-sdk/src/Client.ts b/sdks/browser-sdk/src/Client.ts index 089661a35..da9cfb6f8 100644 --- a/sdks/browser-sdk/src/Client.ts +++ b/sdks/browser-sdk/src/Client.ts @@ -8,9 +8,9 @@ import type { } from "@xmtp/content-type-primitives"; import { TextCodec } from "@xmtp/content-type-text"; import { - WasmGroupMessageKind, - type WasmConsentEntityType, - type WasmSignatureRequestType, + GroupMessageKind, + type ConsentEntityType, + type SignatureRequestType, } from "@xmtp/wasm-bindings"; import { ClientWorkerClass } from "@/ClientWorkerClass"; import { Conversations } from "@/Conversations"; @@ -99,7 +99,7 @@ export class Client extends ClientWorkerClass { return this.sendMessage("getRevokeInstallationsSignatureText", undefined); } - async addSignature(type: WasmSignatureRequestType, bytes: Uint8Array) { + async addSignature(type: SignatureRequestType, bytes: Uint8Array) { return this.sendMessage("addSignature", { type, bytes }); } @@ -137,7 +137,7 @@ export class Client extends ClientWorkerClass { return this.sendMessage("setConsentStates", { records }); } - async getConsentState(entityType: WasmConsentEntityType, entity: string) { + async getConsentState(entityType: ConsentEntityType, entity: string) { return this.sendMessage("getConsentState", { entityType, entity }); } @@ -175,7 +175,7 @@ export class Client extends ClientWorkerClass { // throw an error if there's an invalid group membership change message if ( contentType.sameAs(ContentTypeGroupUpdated) && - message.kind !== WasmGroupMessageKind.MembershipChange + message.kind !== GroupMessageKind.MembershipChange ) { throw new Error("Error decoding group membership change"); } diff --git a/sdks/browser-sdk/src/Conversation.ts b/sdks/browser-sdk/src/Conversation.ts index 5f46256e1..247bf3e7a 100644 --- a/sdks/browser-sdk/src/Conversation.ts +++ b/sdks/browser-sdk/src/Conversation.ts @@ -1,6 +1,6 @@ import type { ContentTypeId } from "@xmtp/content-type-primitives"; import { ContentTypeText } from "@xmtp/content-type-text"; -import type { WasmConsentState } from "@xmtp/wasm-bindings"; +import type { ConsentState } from "@xmtp/wasm-bindings"; import type { Client } from "@/Client"; import { DecodedMessage } from "@/DecodedMessage"; import type { @@ -276,7 +276,7 @@ export class Conversation { }); } - async updateConsentState(state: WasmConsentState) { + async updateConsentState(state: ConsentState) { return this.#client.sendMessage("updateGroupConsentState", { id: this.#id, state, diff --git a/sdks/browser-sdk/src/DecodedMessage.ts b/sdks/browser-sdk/src/DecodedMessage.ts index 37298da21..ea47d2068 100644 --- a/sdks/browser-sdk/src/DecodedMessage.ts +++ b/sdks/browser-sdk/src/DecodedMessage.ts @@ -1,5 +1,5 @@ import type { ContentTypeId } from "@xmtp/content-type-primitives"; -import { WasmDeliveryStatus, WasmGroupMessageKind } from "@xmtp/wasm-bindings"; +import { DeliveryStatus, GroupMessageKind } from "@xmtp/wasm-bindings"; import type { Client } from "@/Client"; import { fromSafeContentTypeId, type SafeMessage } from "@/utils/conversions"; @@ -39,23 +39,23 @@ export class DecodedMessage { this.senderInboxId = message.senderInboxId; switch (message.kind) { - case WasmGroupMessageKind.Application: + case GroupMessageKind.Application: this.kind = "application"; break; - case WasmGroupMessageKind.MembershipChange: + case GroupMessageKind.MembershipChange: this.kind = "membership_change"; break; // no default } switch (message.deliveryStatus) { - case WasmDeliveryStatus.Unpublished: + case DeliveryStatus.Unpublished: this.deliveryStatus = "unpublished"; break; - case WasmDeliveryStatus.Published: + case DeliveryStatus.Published: this.deliveryStatus = "published"; break; - case WasmDeliveryStatus.Failed: + case DeliveryStatus.Failed: this.deliveryStatus = "failed"; break; // no default diff --git a/sdks/browser-sdk/src/WorkerClient.ts b/sdks/browser-sdk/src/WorkerClient.ts index b0ca2a327..821a4cbf8 100644 --- a/sdks/browser-sdk/src/WorkerClient.ts +++ b/sdks/browser-sdk/src/WorkerClient.ts @@ -1,7 +1,7 @@ import { - type WasmClient, - type WasmConsentEntityType, - type WasmSignatureRequestType, + type Client, + type ConsentEntityType, + type SignatureRequestType, } from "@xmtp/wasm-bindings"; import type { ClientOptions } from "@/types"; import { fromSafeConsent, type SafeConsent } from "@/utils/conversions"; @@ -9,13 +9,13 @@ import { createClient } from "@/utils/createClient"; import { WorkerConversations } from "@/WorkerConversations"; export class WorkerClient { - #client: WasmClient; + #client: Client; #conversations: WorkerConversations; #accountAddress: string; - constructor(client: WasmClient) { + constructor(client: Client) { this.#client = client; this.#accountAddress = client.accountAddress; this.#conversations = new WorkerConversations(this, client.conversations()); @@ -80,7 +80,7 @@ export class WorkerClient { } } - async addSignature(type: WasmSignatureRequestType, bytes: Uint8Array) { + async addSignature(type: SignatureRequestType, bytes: Uint8Array) { return this.#client.addSignature(type, bytes); } @@ -114,7 +114,7 @@ export class WorkerClient { return this.#client.setConsentStates(records.map(fromSafeConsent)); } - async getConsentState(entityType: WasmConsentEntityType, entity: string) { + async getConsentState(entityType: ConsentEntityType, entity: string) { return this.#client.getConsentState(entityType, entity); } diff --git a/sdks/browser-sdk/src/WorkerConversation.ts b/sdks/browser-sdk/src/WorkerConversation.ts index 8a2bc9700..8ea03208a 100644 --- a/sdks/browser-sdk/src/WorkerConversation.ts +++ b/sdks/browser-sdk/src/WorkerConversation.ts @@ -1,12 +1,13 @@ import type { - WasmConsentState, - WasmEncodedContent, - WasmGroup, - WasmGroupMember, + ConsentState, + Conversation, + EncodedContent, } from "@xmtp/wasm-bindings"; import { fromSafeListMessagesOptions, + toSafeGroupMember, type SafeListMessagesOptions, + type WasmGroupMember, } from "@/utils/conversions"; import type { WorkerClient } from "@/WorkerClient"; @@ -14,9 +15,9 @@ export class WorkerConversation { // eslint-disable-next-line no-unused-private-class-members #client: WorkerClient; - #group: WasmGroup; + #group: Conversation; - constructor(client: WorkerClient, group: WasmGroup) { + constructor(client: WorkerClient, group: Conversation) { this.#client = client; this.#group = group; } @@ -26,51 +27,51 @@ export class WorkerConversation { } get name() { - return this.#group.group_name(); + return this.#group.groupName(); } async updateName(name: string) { - return this.#group.update_group_name(name); + return this.#group.updateGroupName(name); } get imageUrl() { - return this.#group.group_image_url_square(); + return this.#group.groupImageUrlSquare(); } async updateImageUrl(imageUrl: string) { - return this.#group.update_group_image_url_square(imageUrl); + return this.#group.updateGroupImageUrlSquare(imageUrl); } get description() { - return this.#group.group_description(); + return this.#group.groupDescription(); } async updateDescription(description: string) { - return this.#group.update_group_description(description); + return this.#group.updateGroupDescription(description); } get pinnedFrameUrl() { - return this.#group.group_pinned_frame_url(); + return this.#group.groupPinnedFrameUrl(); } async updatePinnedFrameUrl(pinnedFrameUrl: string) { - return this.#group.update_group_pinned_frame_url(pinnedFrameUrl); + return this.#group.updateGroupPinnedFrameUrl(pinnedFrameUrl); } get isActive() { - return this.#group.is_active(); + return this.#group.isActive(); } get addedByInboxId() { - return this.#group.added_by_inbox_id(); + return this.#group.addedByInboxId(); } get createdAtNs() { - return this.#group.created_at_ns(); + return this.#group.createdAtNs(); } get metadata() { - const metadata = this.#group.group_metadata(); + const metadata = this.#group.groupMetadata(); return { creatorInboxId: metadata.creator_inbox_id(), conversationType: metadata.conversation_type(), @@ -78,31 +79,32 @@ export class WorkerConversation { } async members() { - return this.#group.list_members() as Promise; + const members = (await this.#group.listMembers()) as WasmGroupMember[]; + return members.map((member) => toSafeGroupMember(member)); } get admins() { - return this.#group.admin_list(); + return this.#group.adminList(); } get superAdmins() { - return this.#group.super_admin_list(); + return this.#group.superAdminList(); } get permissions() { - const permissions = this.#group.group_permissions(); + const permissions = this.#group.groupPermissions(); return { - policyType: permissions.policy_type(), - policySet: permissions.policy_set(), + policyType: permissions.policyType(), + policySet: permissions.policySet(), }; } isAdmin(inboxId: string) { - return this.#group.is_admin(inboxId); + return this.#group.isAdmin(inboxId); } isSuperAdmin(inboxId: string) { - return this.#group.is_super_admin(inboxId); + return this.#group.isSuperAdmin(inboxId); } async sync() { @@ -110,64 +112,64 @@ export class WorkerConversation { } async addMembers(accountAddresses: string[]) { - return this.#group.add_members(accountAddresses); + return this.#group.addMembers(accountAddresses); } async addMembersByInboxId(inboxIds: string[]) { - return this.#group.add_members_by_inbox_id(inboxIds); + return this.#group.addMembersByInboxId(inboxIds); } async removeMembers(accountAddresses: string[]) { - return this.#group.remove_members(accountAddresses); + return this.#group.removeMembers(accountAddresses); } async removeMembersByInboxId(inboxIds: string[]) { - return this.#group.remove_members_by_inbox_id(inboxIds); + return this.#group.removeMembersByInboxId(inboxIds); } async addAdmin(inboxId: string) { - return this.#group.add_admin(inboxId); + return this.#group.addAdmin(inboxId); } async removeAdmin(inboxId: string) { - return this.#group.remove_admin(inboxId); + return this.#group.removeAdmin(inboxId); } async addSuperAdmin(inboxId: string) { - return this.#group.add_super_admin(inboxId); + return this.#group.addSuperAdmin(inboxId); } async removeSuperAdmin(inboxId: string) { - return this.#group.remove_super_admin(inboxId); + return this.#group.removeSuperAdmin(inboxId); } async publishMessages() { - return this.#group.publish_messages(); + return this.#group.publishMessages(); } - sendOptimistic(encodedContent: WasmEncodedContent) { - return this.#group.send_optimistic(encodedContent); + sendOptimistic(encodedContent: EncodedContent) { + return this.#group.sendOptimistic(encodedContent); } - async send(encodedContent: WasmEncodedContent) { + async send(encodedContent: EncodedContent) { return this.#group.send(encodedContent); } messages(options?: SafeListMessagesOptions) { - return this.#group.find_messages( + return this.#group.findMessages( options ? fromSafeListMessagesOptions(options) : undefined, ); } get consentState() { - return this.#group.consent_state(); + return this.#group.consentState(); } - updateConsentState(state: WasmConsentState) { - this.#group.update_consent_state(state); + updateConsentState(state: ConsentState) { + this.#group.updateConsentState(state); } dmPeerInboxId() { - return this.#group.dm_peer_inbox_id(); + return this.#group.dmPeerInboxId(); } } diff --git a/sdks/browser-sdk/src/WorkerConversations.ts b/sdks/browser-sdk/src/WorkerConversations.ts index 1f2109de1..257f8d816 100644 --- a/sdks/browser-sdk/src/WorkerConversations.ts +++ b/sdks/browser-sdk/src/WorkerConversations.ts @@ -1,4 +1,4 @@ -import type { WasmConversations, WasmGroup } from "@xmtp/wasm-bindings"; +import type { Conversation, Conversations } from "@xmtp/wasm-bindings"; import { fromSafeCreateGroupOptions, fromSafeListConversationsOptions, @@ -12,9 +12,9 @@ import { WorkerConversation } from "@/WorkerConversation"; export class WorkerConversations { #client: WorkerClient; - #conversations: WasmConversations; + #conversations: Conversations; - constructor(client: WorkerClient, conversations: WasmConversations) { + constructor(client: WorkerClient, conversations: Conversations) { this.#client = client; this.#conversations = conversations; } @@ -25,7 +25,7 @@ export class WorkerConversations { getConversationById(id: string) { try { - const group = this.#conversations.find_group_by_id(id); + const group = this.#conversations.findGroupById(id); // findGroupById will throw if group is not found return new WorkerConversation(this.#client, group); } catch { @@ -36,7 +36,7 @@ export class WorkerConversations { getMessageById(id: string) { try { // findMessageById will throw if message is not found - const message = this.#conversations.find_message_by_id(id); + const message = this.#conversations.findMessageById(id); return toSafeMessage(message); } catch { return undefined; @@ -45,7 +45,7 @@ export class WorkerConversations { getDmByInboxId(inboxId: string) { try { - const group = this.#conversations.find_dm_by_target_inbox_id(inboxId); + const group = this.#conversations.findDmByTargetInboxId(inboxId); return new WorkerConversation(this.#client, group); } catch { return undefined; @@ -55,30 +55,30 @@ export class WorkerConversations { async list(options?: SafeListConversationsOptions) { const groups = (await this.#conversations.list( options ? fromSafeListConversationsOptions(options) : undefined, - )) as WasmGroup[]; + )) as Conversation[]; return groups.map((group) => new WorkerConversation(this.#client, group)); } async listGroups( options?: Omit, ) { - const groups = (await this.#conversations.list_groups( + const groups = (await this.#conversations.listGroups( options ? fromSafeListConversationsOptions(options) : undefined, - )) as WasmGroup[]; + )) as Conversation[]; return groups.map((group) => new WorkerConversation(this.#client, group)); } async listDms( options?: Omit, ) { - const groups = (await this.#conversations.list_dms( + const groups = (await this.#conversations.listDms( options ? fromSafeListConversationsOptions(options) : undefined, - )) as WasmGroup[]; + )) as Conversation[]; return groups.map((group) => new WorkerConversation(this.#client, group)); } async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) { - const group = await this.#conversations.create_group( + const group = await this.#conversations.createGroup( accountAddresses, options ? fromSafeCreateGroupOptions(options) : undefined, ); @@ -86,7 +86,7 @@ export class WorkerConversations { } async newDm(accountAddress: string) { - const group = await this.#conversations.create_dm(accountAddress); + const group = await this.#conversations.createDm(accountAddress); return new WorkerConversation(this.#client, group); } } diff --git a/sdks/browser-sdk/src/types/clientEvents.ts b/sdks/browser-sdk/src/types/clientEvents.ts index c61e3f995..f642c8192 100644 --- a/sdks/browser-sdk/src/types/clientEvents.ts +++ b/sdks/browser-sdk/src/types/clientEvents.ts @@ -1,7 +1,7 @@ import type { - WasmConsentEntityType, - WasmConsentState, - WasmSignatureRequestType, + ConsentEntityType, + ConsentState, + SignatureRequestType, } from "@xmtp/wasm-bindings"; import type { ClientOptions, @@ -74,7 +74,7 @@ export type ClientEvents = id: string; result: undefined; data: { - type: WasmSignatureRequestType; + type: SignatureRequestType; bytes: Uint8Array; }; } @@ -131,9 +131,9 @@ export type ClientEvents = | { action: "getConsentState"; id: string; - result: WasmConsentState; + result: ConsentState; data: { - entityType: WasmConsentEntityType; + entityType: ConsentEntityType; entity: string; }; } @@ -418,7 +418,7 @@ export type ClientEvents = | { action: "getGroupConsentState"; id: string; - result: WasmConsentState; + result: ConsentState; data: { id: string; }; @@ -429,7 +429,7 @@ export type ClientEvents = result: undefined; data: { id: string; - state: WasmConsentState; + state: ConsentState; }; } | { diff --git a/sdks/browser-sdk/src/utils/conversions.ts b/sdks/browser-sdk/src/utils/conversions.ts index da5581c57..093d9c14f 100644 --- a/sdks/browser-sdk/src/utils/conversions.ts +++ b/sdks/browser-sdk/src/utils/conversions.ts @@ -3,26 +3,26 @@ import { type EncodedContent, } from "@xmtp/content-type-primitives"; import { - WasmConsent, - WasmContentTypeId, - WasmCreateGroupOptions, - WasmEncodedContent, - WasmGroupMember, - WasmListConversationsOptions, - WasmListMessagesOptions, - type WasmConsentEntityType, - type WasmConsentState, - type WasmConversationType, - type WasmDeliveryStatus, - type WasmDirection, - type WasmGroupMembershipState, - type WasmGroupMessageKind, - type WasmGroupPermissionsOptions, - type WasmInboxState, - type WasmInstallation, - type WasmMessage, - type WasmPermissionLevel, - type WasmPermissionPolicy, + Consent, + CreateGroupOptions, + GroupMember, + ListConversationsOptions, + ListMessagesOptions, + ContentTypeId as WasmContentTypeId, + EncodedContent as WasmEncodedContent, + type ConsentEntityType, + type ConsentState, + type ConversationType, + type DeliveryStatus, + type GroupMembershipState, + type GroupMessageKind, + type GroupPermissionsOptions, + type InboxState, + type Installation, + type Message, + type PermissionLevel, + type PermissionPolicy, + type SortDirection, } from "@xmtp/wasm-bindings"; import type { WorkerConversation } from "@/WorkerConversation"; @@ -30,10 +30,10 @@ export const toContentTypeId = ( contentTypeId: WasmContentTypeId, ): ContentTypeId => new ContentTypeId({ - authorityId: contentTypeId.authority_id, - typeId: contentTypeId.type_id, - versionMajor: contentTypeId.version_major, - versionMinor: contentTypeId.version_minor, + authorityId: contentTypeId.authorityId, + typeId: contentTypeId.typeId, + versionMajor: contentTypeId.versionMajor, + versionMinor: contentTypeId.versionMinor, }); export const fromContentTypeId = ( @@ -125,83 +125,83 @@ export const fromSafeEncodedContent = ( export type SafeMessage = { content: SafeEncodedContent; convoId: string; - deliveryStatus: WasmDeliveryStatus; + deliveryStatus: DeliveryStatus; id: string; - kind: WasmGroupMessageKind; + kind: GroupMessageKind; senderInboxId: string; sentAtNs: bigint; }; -export const toSafeMessage = (message: WasmMessage): SafeMessage => ({ +export const toSafeMessage = (message: Message): SafeMessage => ({ content: toSafeEncodedContent(toEncodedContent(message.content)), - convoId: message.convo_id, - deliveryStatus: message.delivery_status, + convoId: message.convoId, + deliveryStatus: message.deliveryStatus, id: message.id, kind: message.kind, - senderInboxId: message.sender_inbox_id, - sentAtNs: message.sent_at_ns, + senderInboxId: message.senderInboxId, + sentAtNs: message.sentAtNs, }); export type SafeListMessagesOptions = { - delivery_status?: WasmDeliveryStatus; - direction?: WasmDirection; + deliveryStatus?: DeliveryStatus; + direction?: SortDirection; limit?: bigint; - sent_after_ns?: bigint; - sent_before_ns?: bigint; + sentAfterNs?: bigint; + sentBeforeNs?: bigint; }; export const toSafeListMessagesOptions = ( - options: WasmListMessagesOptions, + options: ListMessagesOptions, ): SafeListMessagesOptions => ({ - delivery_status: options.delivery_status, + deliveryStatus: options.deliveryStatus, direction: options.direction, limit: options.limit, - sent_after_ns: options.sent_after_ns, - sent_before_ns: options.sent_before_ns, + sentAfterNs: options.sentAfterNs, + sentBeforeNs: options.sentBeforeNs, }); export const fromSafeListMessagesOptions = ( options: SafeListMessagesOptions, -): WasmListMessagesOptions => - new WasmListMessagesOptions( - options.sent_before_ns, - options.sent_after_ns, +): ListMessagesOptions => + new ListMessagesOptions( + options.sentBeforeNs, + options.sentAfterNs, options.limit, - options.delivery_status, + options.deliveryStatus, options.direction, ); export type SafeListConversationsOptions = { - allowed_states?: WasmGroupMembershipState[]; - conversation_type?: WasmConversationType; - created_after_ns?: bigint; - created_before_ns?: bigint; + allowedStates?: GroupMembershipState[]; + conversationType?: ConversationType; + createdAfterNs?: bigint; + createdBeforeNs?: bigint; limit?: bigint; }; export const toSafeListConversationsOptions = ( - options: WasmListConversationsOptions, + options: ListConversationsOptions, ): SafeListConversationsOptions => ({ - allowed_states: options.allowed_states, - conversation_type: options.conversation_type, - created_after_ns: options.created_after_ns, - created_before_ns: options.created_before_ns, + allowedStates: options.allowedStates, + conversationType: options.conversationType, + createdAfterNs: options.createdAfterNs, + createdBeforeNs: options.createdBeforeNs, limit: options.limit, }); export const fromSafeListConversationsOptions = ( options: SafeListConversationsOptions, -): WasmListConversationsOptions => - new WasmListConversationsOptions( - options.allowed_states, - options.conversation_type, - options.created_after_ns, - options.created_before_ns, +): ListConversationsOptions => + new ListConversationsOptions( + options.allowedStates, + options.conversationType, + options.createdAfterNs, + options.createdBeforeNs, options.limit, ); export type SafeCreateGroupOptions = { - permissions?: WasmGroupPermissionsOptions; + permissions?: GroupPermissionsOptions; name?: string; imageUrlSquare?: string; description?: string; @@ -209,19 +209,19 @@ export type SafeCreateGroupOptions = { }; export const toSafeCreateGroupOptions = ( - options: WasmCreateGroupOptions, + options: CreateGroupOptions, ): SafeCreateGroupOptions => ({ permissions: options.permissions, - name: options.group_name, - imageUrlSquare: options.group_image_url_square, - description: options.group_description, - pinnedFrameUrl: options.group_pinned_frame_url, + name: options.groupName, + imageUrlSquare: options.groupImageUrlSquare, + description: options.groupDescription, + pinnedFrameUrl: options.groupPinnedFrameUrl, }); export const fromSafeCreateGroupOptions = ( options: SafeCreateGroupOptions, -): WasmCreateGroupOptions => - new WasmCreateGroupOptions( +): CreateGroupOptions => + new CreateGroupOptions( options.permissions, options.name, options.imageUrlSquare, @@ -236,16 +236,16 @@ export type SafeConversation = { description: string; pinnedFrameUrl: string; permissions: { - policyType: WasmGroupPermissionsOptions; + policyType: GroupPermissionsOptions; policySet: { - addAdminPolicy: WasmPermissionPolicy; - addMemberPolicy: WasmPermissionPolicy; - removeAdminPolicy: WasmPermissionPolicy; - removeMemberPolicy: WasmPermissionPolicy; - updateGroupDescriptionPolicy: WasmPermissionPolicy; - updateGroupImageUrlSquarePolicy: WasmPermissionPolicy; - updateGroupNamePolicy: WasmPermissionPolicy; - updateGroupPinnedFrameUrlPolicy: WasmPermissionPolicy; + addAdminPolicy: PermissionPolicy; + addMemberPolicy: PermissionPolicy; + removeAdminPolicy: PermissionPolicy; + removeMemberPolicy: PermissionPolicy; + updateGroupDescriptionPolicy: PermissionPolicy; + updateGroupImageUrlSquarePolicy: PermissionPolicy; + updateGroupNamePolicy: PermissionPolicy; + updateGroupPinnedFrameUrlPolicy: PermissionPolicy; }; }; isActive: boolean; @@ -270,19 +270,18 @@ export const toSafeConversation = ( permissions: { policyType: conversation.permissions.policyType, policySet: { - addAdminPolicy: conversation.permissions.policySet.add_admin_policy, - addMemberPolicy: conversation.permissions.policySet.add_member_policy, - removeAdminPolicy: conversation.permissions.policySet.remove_admin_policy, - removeMemberPolicy: - conversation.permissions.policySet.remove_member_policy, + addAdminPolicy: conversation.permissions.policySet.addAdminPolicy, + addMemberPolicy: conversation.permissions.policySet.addMemberPolicy, + removeAdminPolicy: conversation.permissions.policySet.removeAdminPolicy, + removeMemberPolicy: conversation.permissions.policySet.removeMemberPolicy, updateGroupDescriptionPolicy: - conversation.permissions.policySet.update_group_description_policy, + conversation.permissions.policySet.updateGroupDescriptionPolicy, updateGroupImageUrlSquarePolicy: - conversation.permissions.policySet.update_group_image_url_square_policy, + conversation.permissions.policySet.updateGroupImageUrlSquarePolicy, updateGroupNamePolicy: - conversation.permissions.policySet.update_group_name_policy, + conversation.permissions.policySet.updateGroupNamePolicy, updateGroupPinnedFrameUrlPolicy: - conversation.permissions.policySet.update_group_pinned_frame_url_policy, + conversation.permissions.policySet.updateGroupPinnedFrameUrlPolicy, }, }, isActive: conversation.isActive, @@ -299,10 +298,10 @@ export type SafeInstallation = { }; export const toSafeInstallation = ( - installation: WasmInstallation, + installation: Installation, ): SafeInstallation => ({ id: installation.id, - clientTimestampNs: installation.client_timestamp_ns, + clientTimestampNs: installation.clientTimestampNs, }); export type SafeInboxState = { @@ -312,38 +311,58 @@ export type SafeInboxState = { recoveryAddress: string; }; -export const toSafeInboxState = ( - inboxState: WasmInboxState, -): SafeInboxState => ({ - accountAddresses: inboxState.account_addresses, - inboxId: inboxState.inbox_id, +export const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({ + accountAddresses: inboxState.accountAddresses, + inboxId: inboxState.inboxId, installations: inboxState.installations.map(toSafeInstallation), - recoveryAddress: inboxState.recovery_address, + recoveryAddress: inboxState.recoveryAddress, }); export type SafeConsent = { entity: string; - entityType: WasmConsentEntityType; - state: WasmConsentState; + entityType: ConsentEntityType; + state: ConsentState; }; -export const toSafeConsent = (consent: WasmConsent): SafeConsent => ({ +export const toSafeConsent = (consent: Consent): SafeConsent => ({ entity: consent.entity, - entityType: consent.entity_type, + entityType: consent.entityType, state: consent.state, }); -export const fromSafeConsent = (consent: SafeConsent): WasmConsent => - new WasmConsent(consent.entityType, consent.state, consent.entity); +export const fromSafeConsent = (consent: SafeConsent): Consent => + new Consent(consent.entityType, consent.state, consent.entity); export type SafeGroupMember = { accountAddresses: string[]; - consentState: WasmConsentState; + consentState: ConsentState; inboxId: string; installationIds: string[]; - permissionLevel: WasmPermissionLevel; + permissionLevel: PermissionLevel; }; +export class WasmGroupMember { + account_addresses: string[]; + consent_state: ConsentState; + inbox_id: string; + installation_ids: string[]; + permission_level: PermissionLevel; + + constructor( + inbox_id: string, + account_addresses: string[], + installation_ids: string[], + permission_level: PermissionLevel, + consent_state: ConsentState, + ) { + this.inbox_id = inbox_id; + this.account_addresses = account_addresses; + this.installation_ids = installation_ids; + this.permission_level = permission_level; + this.consent_state = consent_state; + } +} + export const toSafeGroupMember = ( member: WasmGroupMember, ): SafeGroupMember => ({ @@ -354,8 +373,8 @@ export const toSafeGroupMember = ( permissionLevel: member.permission_level, }); -export const fromSafeGroupMember = (member: SafeGroupMember): WasmGroupMember => - new WasmGroupMember( +export const fromSafeGroupMember = (member: SafeGroupMember): GroupMember => + new GroupMember( member.inboxId, member.accountAddresses, member.installationIds, diff --git a/sdks/browser-sdk/src/workers/client.ts b/sdks/browser-sdk/src/workers/client.ts index 8ac3f46d6..49b1b8455 100644 --- a/sdks/browser-sdk/src/workers/client.ts +++ b/sdks/browser-sdk/src/workers/client.ts @@ -8,7 +8,6 @@ import { fromEncodedContent, fromSafeEncodedContent, toSafeConversation, - toSafeGroupMember, toSafeInboxState, toSafeMessage, } from "@/utils/conversions"; @@ -467,11 +466,11 @@ self.onmessage = async (event: MessageEvent) => { case "getGroupMembers": { const group = client.conversations.getConversationById(data.id); if (group) { - const members = await group.members(); + const result = await group.members(); postMessage({ id, action, - result: members.map((member) => toSafeGroupMember(member)), + result, }); } else { postMessageError({ diff --git a/sdks/browser-sdk/test/Client.test.ts b/sdks/browser-sdk/test/Client.test.ts index d5683ccfa..89c3031b5 100644 --- a/sdks/browser-sdk/test/Client.test.ts +++ b/sdks/browser-sdk/test/Client.test.ts @@ -1,7 +1,7 @@ import { - WasmConsentEntityType, - WasmConsentState, - WasmSignatureRequestType, + ConsentEntityType, + ConsentState, + SignatureRequestType, } from "@xmtp/wasm-bindings"; import { v4 } from "uuid"; import { toBytes } from "viem"; @@ -93,11 +93,11 @@ describe.concurrent("Client", () => { }); await client.addSignature( - WasmSignatureRequestType.AddWallet, + SignatureRequestType.AddWallet, toBytes(signature), ); await client.addSignature( - WasmSignatureRequestType.AddWallet, + SignatureRequestType.AddWallet, toBytes(signature2), ); await client.applySignatures(); @@ -130,11 +130,11 @@ describe.concurrent("Client", () => { }); await client.addSignature( - WasmSignatureRequestType.AddWallet, + SignatureRequestType.AddWallet, toBytes(signature), ); await client.addSignature( - WasmSignatureRequestType.AddWallet, + SignatureRequestType.AddWallet, toBytes(signature2), ); await client.applySignatures(); @@ -150,7 +150,7 @@ describe.concurrent("Client", () => { }); await client.addSignature( - WasmSignatureRequestType.RevokeWallet, + SignatureRequestType.RevokeWallet, toBytes(signature3), ); await client.applySignatures(); @@ -186,7 +186,7 @@ describe.concurrent("Client", () => { }); await client3.addSignature( - WasmSignatureRequestType.RevokeInstallations, + SignatureRequestType.RevokeInstallations, toBytes(signature), ); await client3.applySignatures(); @@ -209,29 +209,29 @@ describe.concurrent("Client", () => { expect(group2).not.toBeNull(); expect( - await client2.getConsentState(WasmConsentEntityType.GroupId, group2!.id), - ).toBe(WasmConsentState.Unknown); + await client2.getConsentState(ConsentEntityType.GroupId, group2!.id), + ).toBe(ConsentState.Unknown); await client2.setConsentStates([ { - entityType: WasmConsentEntityType.GroupId, + entityType: ConsentEntityType.GroupId, entity: group2!.id, - state: WasmConsentState.Allowed, + state: ConsentState.Allowed, }, ]); expect( - await client2.getConsentState(WasmConsentEntityType.GroupId, group2!.id), - ).toBe(WasmConsentState.Allowed); + await client2.getConsentState(ConsentEntityType.GroupId, group2!.id), + ).toBe(ConsentState.Allowed); const convo = new Conversation(client2, group2!.id, group2); - expect(await convo.consentState()).toBe(WasmConsentState.Allowed); + expect(await convo.consentState()).toBe(ConsentState.Allowed); - await convo.updateConsentState(WasmConsentState.Denied); + await convo.updateConsentState(ConsentState.Denied); expect( - await client2.getConsentState(WasmConsentEntityType.GroupId, group2!.id), - ).toBe(WasmConsentState.Denied); + await client2.getConsentState(ConsentEntityType.GroupId, group2!.id), + ).toBe(ConsentState.Denied); }); }); diff --git a/sdks/browser-sdk/test/Conversation.test.ts b/sdks/browser-sdk/test/Conversation.test.ts index 696df11bf..d38c62988 100644 --- a/sdks/browser-sdk/test/Conversation.test.ts +++ b/sdks/browser-sdk/test/Conversation.test.ts @@ -1,4 +1,4 @@ -import { WasmConsentState } from "@xmtp/wasm-bindings"; +import { ConsentState } from "@xmtp/wasm-bindings"; import { describe, expect, it } from "vitest"; import { Conversation } from "@/Conversation"; import { @@ -393,9 +393,9 @@ describe.concurrent("Conversation", () => { const groupConvo = new Conversation(client2, group2!.id, group2); - expect(await groupConvo.consentState()).toBe(WasmConsentState.Unknown); + expect(await groupConvo.consentState()).toBe(ConsentState.Unknown); await groupConvo.send("gm!"); - expect(await groupConvo.consentState()).toBe(WasmConsentState.Allowed); + expect(await groupConvo.consentState()).toBe(ConsentState.Allowed); await client3.conversations.sync(); const dmGroup2 = await client3.conversations.getConversationById( @@ -405,8 +405,8 @@ describe.concurrent("Conversation", () => { const dmConvo = new Conversation(client3, dmGroup2!.id, dmGroup2); - expect(await dmConvo.consentState()).toBe(WasmConsentState.Unknown); + expect(await dmConvo.consentState()).toBe(ConsentState.Unknown); await dmConvo.send("gm!"); - expect(await dmConvo.consentState()).toBe(WasmConsentState.Allowed); + expect(await dmConvo.consentState()).toBe(ConsentState.Allowed); }); }); diff --git a/sdks/browser-sdk/test/Conversations.test.ts b/sdks/browser-sdk/test/Conversations.test.ts index bdd2b58f8..58062355c 100644 --- a/sdks/browser-sdk/test/Conversations.test.ts +++ b/sdks/browser-sdk/test/Conversations.test.ts @@ -1,7 +1,4 @@ -import { - WasmConsentState, - WasmGroupPermissionsOptions, -} from "@xmtp/wasm-bindings"; +import { ConsentState, GroupPermissionsOptions } from "@xmtp/wasm-bindings"; import { describe, expect, it } from "vitest"; import { createRegisteredClient, createUser } from "@test/helpers"; @@ -33,7 +30,7 @@ describe.concurrent("Conversations", () => { expect(conversation.isActive).toBe(true); expect(conversation.name).toBe(""); expect(conversation.permissions?.policyType).toBe( - WasmGroupPermissionsOptions.AllMembers, + GroupPermissionsOptions.AllMembers, ); expect(conversation.permissions?.policySet).toEqual({ addMemberPolicy: 0, @@ -87,7 +84,7 @@ describe.concurrent("Conversations", () => { expect(group.isActive).toBe(true); expect(group.name).toBe(""); expect(group.permissions?.policyType).toBe( - WasmGroupPermissionsOptions.CustomPolicy, + GroupPermissionsOptions.CustomPolicy, ); expect(group.permissions?.policySet).toEqual({ addAdminPolicy: 1, @@ -109,7 +106,7 @@ describe.concurrent("Conversations", () => { expect(group.metadata?.conversationType).toBe("dm"); expect(group.metadata?.creatorInboxId).toBe(client1.inboxId); - expect(await group.consentState()).toBe(WasmConsentState.Allowed); + expect(await group.consentState()).toBe(ConsentState.Allowed); const group1 = await client1.conversations.list(); expect(group1.length).toBe(1); @@ -214,14 +211,14 @@ describe.concurrent("Conversations", () => { const groupWithPermissions = await client1.conversations.newGroup( [user4.account.address], { - permissions: WasmGroupPermissionsOptions.AdminOnly, + permissions: GroupPermissionsOptions.AdminOnly, }, ); expect(groupWithPermissions).toBeDefined(); expect(groupWithPermissions.name).toBe(""); expect(groupWithPermissions.imageUrl).toBe(""); expect(groupWithPermissions.permissions?.policyType).toBe( - WasmGroupPermissionsOptions.AdminOnly, + GroupPermissionsOptions.AdminOnly, ); expect(groupWithPermissions.permissions?.policySet).toEqual({ diff --git a/sdks/browser-sdk/test/Utils.test.ts b/sdks/browser-sdk/test/Utils.test.ts index 18b453596..c173dfc2e 100644 --- a/sdks/browser-sdk/test/Utils.test.ts +++ b/sdks/browser-sdk/test/Utils.test.ts @@ -4,8 +4,9 @@ import { createRegisteredClient, createUser } from "@test/helpers"; describe.concurrent("Utils", () => { it("should generate inbox id", async () => { + const user = createUser(); const utils = new Utils(); - const inboxId = await utils.generateInboxId("0x1234"); + const inboxId = await utils.generateInboxId(user.account.address); expect(inboxId).toBeDefined(); }); diff --git a/sdks/browser-sdk/test/helpers.ts b/sdks/browser-sdk/test/helpers.ts index 563d1dedc..f95eed455 100644 --- a/sdks/browser-sdk/test/helpers.ts +++ b/sdks/browser-sdk/test/helpers.ts @@ -3,7 +3,7 @@ import { type ContentCodec, type EncodedContent, } from "@xmtp/content-type-primitives"; -import { WasmSignatureRequestType } from "@xmtp/wasm-bindings"; +import { SignatureRequestType } from "@xmtp/wasm-bindings"; import { v4 } from "uuid"; import { createWalletClient, http, toBytes } from "viem"; import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; @@ -59,10 +59,7 @@ export const createRegisteredClient = async ( if (!isRegistered) { const signature = await getSignature(client, user); if (signature) { - await client.addSignature( - WasmSignatureRequestType.CreateInbox, - signature, - ); + await client.addSignature(SignatureRequestType.CreateInbox, signature); } await client.registerIdentity(); } diff --git a/yarn.lock b/yarn.lock index 28da8a6aa..b170635c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4569,7 +4569,7 @@ __metadata: "@xmtp/content-type-primitives": "npm:^1.0.1" "@xmtp/content-type-text": "npm:^1.0.0" "@xmtp/proto": "npm:^3.70.0" - "@xmtp/wasm-bindings": "npm:^0.0.2" + "@xmtp/wasm-bindings": "npm:^0.0.3" playwright: "npm:^1.48.1" rollup: "npm:^4.18.1" rollup-plugin-dts: "npm:^6.1.1" @@ -4960,10 +4960,10 @@ __metadata: languageName: node linkType: hard -"@xmtp/wasm-bindings@npm:^0.0.2": - version: 0.0.2 - resolution: "@xmtp/wasm-bindings@npm:0.0.2" - checksum: 10/7aea7984776e4928185d76310c98a3c93ebc2288771ef7f385437064ce972ab9afced95a875c71d98f2389d3275b8a805d5da6cbd33aee87cd7922a13eebd5bd +"@xmtp/wasm-bindings@npm:^0.0.3": + version: 0.0.3 + resolution: "@xmtp/wasm-bindings@npm:0.0.3" + checksum: 10/7d7faf7062cf7f08a5063a2d9a61c6eb3ded50343025b349f3a23b5136c983cb4a8d3f4407bfb5d5843fa163f8a53ed18cd5d0d58759f7ba46ee3f342fd70be8 languageName: node linkType: hard