From 74792cb26f0cc5666c41d4f5177ab06ae3b93b59 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Fri, 14 Jun 2024 19:32:52 -0500 Subject: [PATCH 1/8] Upgrade @xmtp/mls-client-bindings-node --- packages/mls-client/package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/mls-client/package.json b/packages/mls-client/package.json index d93258f69..abd171b58 100644 --- a/packages/mls-client/package.json +++ b/packages/mls-client/package.json @@ -54,7 +54,7 @@ "dependencies": { "@xmtp/content-type-primitives": "^1.0.1", "@xmtp/content-type-text": "^1.0.0", - "@xmtp/mls-client-bindings-node": "^0.0.4", + "@xmtp/mls-client-bindings-node": "^0.0.5", "@xmtp/proto": "^3.61.1" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index ade7f07ba..00b711cc5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2881,10 +2881,10 @@ __metadata: languageName: node linkType: hard -"@xmtp/mls-client-bindings-node@npm:^0.0.4": - version: 0.0.4 - resolution: "@xmtp/mls-client-bindings-node@npm:0.0.4" - checksum: 10/508839e57a7126f8f2d9898c62c117cd2626279c244b57c2a257bb7681755e19bde985df4a666c61b665b7bb23b9aa8d784527c601797845271c1cf61af26808 +"@xmtp/mls-client-bindings-node@npm:^0.0.5": + version: 0.0.5 + resolution: "@xmtp/mls-client-bindings-node@npm:0.0.5" + checksum: 10/b00582aec3e328106dc8fb95ef2e637d591c91ef7b9b4c8e1f84d8f5323794f3b36ccd96ded5f65390a37ea40203582b6cdb379d60f6d59fa3128c37661110d7 languageName: node linkType: hard @@ -2901,7 +2901,7 @@ __metadata: "@vitest/coverage-v8": "npm:^1.6.0" "@xmtp/content-type-primitives": "npm:^1.0.1" "@xmtp/content-type-text": "npm:^1.0.0" - "@xmtp/mls-client-bindings-node": "npm:^0.0.4" + "@xmtp/mls-client-bindings-node": "npm:^0.0.5" "@xmtp/proto": "npm:^3.61.1" "@xmtp/xmtp-js": "workspace:^" eslint: "npm:^8.57.0" From 25ebe3a8ceaaaf0919948b7764e935a8e497ac6e Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Fri, 14 Jun 2024 19:33:35 -0500 Subject: [PATCH 2/8] Rename addErc1271Signature to addScwSignature --- packages/mls-client/src/Client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mls-client/src/Client.ts b/packages/mls-client/src/Client.ts index 5752d6245..489c4bfea 100644 --- a/packages/mls-client/src/Client.ts +++ b/packages/mls-client/src/Client.ts @@ -139,14 +139,14 @@ export class Client { this.#innerClient.addEcdsaSignature(signatureBytes) } - addErc1271Signature( + addScwSignature( signatureBytes: Uint8Array, chainId: string, accountAddress: string, chainRpcUrl: string, blockNumber: bigint ) { - this.#innerClient.addErc1271Signature( + this.#innerClient.addScwSignature( signatureBytes, chainId, accountAddress, From e46be5ab3c7965cf62869fedb5a7326e070acfae Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Fri, 14 Jun 2024 19:34:01 -0500 Subject: [PATCH 3/8] Refactor newConversation to include more options --- packages/mls-client/src/Conversations.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mls-client/src/Conversations.ts b/packages/mls-client/src/Conversations.ts index 6501a8476..23bdcd20c 100644 --- a/packages/mls-client/src/Conversations.ts +++ b/packages/mls-client/src/Conversations.ts @@ -1,6 +1,6 @@ import type { - GroupPermissions, NapiConversations, + NapiCreateGroupOptions, NapiListMessagesOptions, } from '@xmtp/mls-client-bindings-node' import { AsyncStream, type StreamCallback } from '@/AsyncStream' @@ -25,11 +25,11 @@ export class Conversations { async newConversation( accountAddresses: string[], - permissions?: GroupPermissions + options?: NapiCreateGroupOptions ) { const group = await this.#conversations.createGroup( accountAddresses, - permissions + options ) const conversation = new Conversation(this.#client, group) this.#map.set(conversation.id, conversation) From dc788f821be236223eb894b03996d177ec225548 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Fri, 14 Jun 2024 19:34:18 -0500 Subject: [PATCH 4/8] Add group image URL getter and setter --- packages/mls-client/src/Conversation.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/mls-client/src/Conversation.ts b/packages/mls-client/src/Conversation.ts index c30ebd159..b03806f95 100644 --- a/packages/mls-client/src/Conversation.ts +++ b/packages/mls-client/src/Conversation.ts @@ -29,6 +29,14 @@ export class Conversation { return this.#group.updateGroupName(name) } + get imageUrl() { + return this.#group.groupImageUrlSquare() + } + + async updateImageUrl(imageUrl: string) { + return this.#group.updateGroupImageUrlSquare(imageUrl) + } + get isActive() { return this.#group.isActive() } From c9a6a3f83260f9a5738485828a0f0ec7005e4b6a Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Sat, 15 Jun 2024 09:59:30 -0500 Subject: [PATCH 5/8] Add group permissions getter --- packages/mls-client/src/Conversation.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/mls-client/src/Conversation.ts b/packages/mls-client/src/Conversation.ts index b03806f95..2c44f1325 100644 --- a/packages/mls-client/src/Conversation.ts +++ b/packages/mls-client/src/Conversation.ts @@ -73,6 +73,12 @@ export class Conversation { return this.#group.superAdminList() } + get permissions() { + return { + policyType: this.#group.groupPermissions().policyType(), + } + } + isAdmin(inboxId: string) { return this.#group.isAdmin(inboxId) } From 9000781f18fb926b2495157914e2ff9f51668fa6 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Sat, 15 Jun 2024 09:59:48 -0500 Subject: [PATCH 6/8] Add tests --- packages/mls-client/test/Conversation.test.ts | 26 +++++++++ .../mls-client/test/Conversations.test.ts | 58 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/packages/mls-client/test/Conversation.test.ts b/packages/mls-client/test/Conversation.test.ts index f2cce130e..e72d5d1c8 100644 --- a/packages/mls-client/test/Conversation.test.ts +++ b/packages/mls-client/test/Conversation.test.ts @@ -29,6 +29,32 @@ describe('Conversation', () => { expect(conversation2.messages().length).toBe(1) }) + it('should update conversation image URL', async () => { + const user1 = createUser() + const user2 = createUser() + const client1 = await createRegisteredClient(user1) + const client2 = await createRegisteredClient(user2) + const conversation = await client1.conversations.newConversation([ + user2.account.address, + ]) + const imageUrl = 'https://foo/bar.jpg' + await conversation.updateImageUrl(imageUrl) + expect(conversation.imageUrl).toBe(imageUrl) + const messages = conversation.messages() + expect(messages.length).toBe(2) + + await client2.conversations.sync() + const conversations = await client2.conversations.list() + expect(conversations.length).toBe(1) + + const conversation2 = conversations[0] + expect(conversation2).toBeDefined() + await conversation2.sync() + expect(conversation2.id).toBe(conversation.id) + expect(conversation2.imageUrl).toBe(imageUrl) + expect(conversation2.messages().length).toBe(1) + }) + it('should add and remove members', async () => { const user1 = createUser() const user2 = createUser() diff --git a/packages/mls-client/test/Conversations.test.ts b/packages/mls-client/test/Conversations.test.ts index e6a1fad26..1ab2f4b5f 100644 --- a/packages/mls-client/test/Conversations.test.ts +++ b/packages/mls-client/test/Conversations.test.ts @@ -1,4 +1,5 @@ import { ContentTypeText } from '@xmtp/content-type-text' +import { GroupPermissions } from '@xmtp/mls-client-bindings-node' import { describe, expect, it } from 'vitest' import { createRegisteredClient, createUser } from '@test/helpers' @@ -25,6 +26,9 @@ describe('Conversations', () => { expect(conversation.createdAtNs).toBeDefined() expect(conversation.isActive).toBe(true) expect(conversation.name).toBe('') + expect(conversation.permissions.policyType).toBe( + GroupPermissions.EveryoneIsAdmin + ) expect(conversation.addedByInboxId).toBe(client1.inboxId) expect(conversation.messages().length).toBe(1) expect(conversation.members.length).toBe(2) @@ -49,6 +53,60 @@ describe('Conversations', () => { expect(conversations2[0].id).toBe(conversation.id) }) + it('should create a new conversation with options', async () => { + const user1 = createUser() + const user2 = createUser() + const user3 = createUser() + const user4 = createUser() + const user5 = createUser() + const client1 = await createRegisteredClient(user1) + await createRegisteredClient(user2) + await createRegisteredClient(user3) + await createRegisteredClient(user4) + await createRegisteredClient(user5) + const groupWithName = await client1.conversations.newConversation( + [user2.account.address], + { + groupName: 'foo', + } + ) + expect(groupWithName).toBeDefined() + expect(groupWithName.name).toBe('foo') + expect(groupWithName.imageUrl).toBe('') + + const groupWithImageUrl = await client1.conversations.newConversation( + [user3.account.address], + { + groupImageUrlSquare: 'https://foo/bar.png', + } + ) + expect(groupWithImageUrl).toBeDefined() + expect(groupWithImageUrl.name).toBe('') + expect(groupWithImageUrl.imageUrl).toBe('https://foo/bar.png') + + const groupWithNameAndImageUrl = + await client1.conversations.newConversation([user4.account.address], { + groupImageUrlSquare: 'https://foo/bar.png', + groupName: 'foo', + }) + expect(groupWithNameAndImageUrl).toBeDefined() + expect(groupWithNameAndImageUrl.name).toBe('foo') + expect(groupWithNameAndImageUrl.imageUrl).toBe('https://foo/bar.png') + + const groupWithPermissions = await client1.conversations.newConversation( + [user4.account.address], + { + permissions: GroupPermissions.GroupCreatorIsAdmin, + } + ) + expect(groupWithPermissions).toBeDefined() + expect(groupWithPermissions.name).toBe('') + expect(groupWithPermissions.imageUrl).toBe('') + expect(groupWithPermissions.permissions.policyType).toBe( + GroupPermissions.GroupCreatorIsAdmin + ) + }) + it('should stream new conversations', async () => { const user1 = createUser() const user2 = createUser() From a1e3155e092d92d8ab479900070319a18086c5fe Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Sat, 15 Jun 2024 10:04:22 -0500 Subject: [PATCH 7/8] Export GroupPermissions --- packages/mls-client/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/mls-client/src/index.ts b/packages/mls-client/src/index.ts index b538d9afd..438a6edbc 100644 --- a/packages/mls-client/src/index.ts +++ b/packages/mls-client/src/index.ts @@ -14,3 +14,4 @@ export { GroupUpdatedCodec, } from './codecs/GroupUpdatedCodec' export type { StreamCallback } from './AsyncStream' +export { GroupPermissions } from '@xmtp/mls-client-bindings-node' From a419052af47bc6c194294c214887d0ca5a757238 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Sat, 15 Jun 2024 08:19:19 -0700 Subject: [PATCH 8/8] Create shaggy-buckets-fetch.md --- .changeset/shaggy-buckets-fetch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/shaggy-buckets-fetch.md diff --git a/.changeset/shaggy-buckets-fetch.md b/.changeset/shaggy-buckets-fetch.md new file mode 100644 index 000000000..96c5b0a7d --- /dev/null +++ b/.changeset/shaggy-buckets-fetch.md @@ -0,0 +1,5 @@ +--- +"@xmtp/mls-client": patch +--- + +Upgrade to latest node bindings