From 08b6396ba6d79984b959b1aff4ea09661f27a5c8 Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Wed, 24 Jan 2024 15:55:06 -0700 Subject: [PATCH] feat: Key Material Exposed Key Material for conversations Added test --- .../wrappers/ConversationWrapper.kt | 4 ++- example/src/tests.ts | 28 +++++++++++++++++++ ios/Wrappers/ConversationWrapper.swift | 1 + src/lib/Conversation.ts | 6 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationWrapper.kt index f3496409e..97d88beed 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationWrapper.kt @@ -1,5 +1,6 @@ package expo.modules.xmtpreactnativesdk.wrappers +import android.util.Base64 import com.google.gson.GsonBuilder import org.xmtp.android.library.Client import org.xmtp.android.library.Conversation @@ -24,7 +25,8 @@ class ConversationWrapper { "topic" to conversation.topic, "peerAddress" to conversation.peerAddress, "version" to if (conversation.version == Conversation.Version.V1) "v1" else "v2", - "conversationID" to (conversation.conversationId ?: "") + "conversationID" to (conversation.conversationId ?: ""), + "keyMaterial" to Base64.encodeToString(conversation.keyMaterial, Base64.NO_WRAP) ) } diff --git a/example/src/tests.ts b/example/src/tests.ts index 94bd74803..814a091b3 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -841,3 +841,31 @@ test('calls preEnableIdentityCallback when supplied', async () => { return isCallbackCalled }) + +test('returns keyMaterial for conversations', async () => { + const bob = await Client.createRandom({ env: 'local' }) + await delayToPropogate() + const alice = await Client.createRandom({ env: 'local' }) + await delayToPropogate() + if (bob.address === alice.address) { + throw new Error('bob and alice should be different') + } + + const bobConversation = await bob.conversations.newConversation(alice.address) + await delayToPropogate() + + const aliceConversation = (await alice.conversations.list())[0] + if (!aliceConversation) { + throw new Error('aliceConversation should exist') + } + + if (!aliceConversation.keyMaterial) { + throw new Error('aliceConversation keyMaterial should exist') + } + + if (!bobConversation.keyMaterial) { + throw new Error('bobConversation keyMaterial should exist') + } + + return true +}) diff --git a/ios/Wrappers/ConversationWrapper.swift b/ios/Wrappers/ConversationWrapper.swift index 116e0a25d..b3a63587e 100644 --- a/ios/Wrappers/ConversationWrapper.swift +++ b/ios/Wrappers/ConversationWrapper.swift @@ -25,6 +25,7 @@ struct ConversationWrapper { "peerAddress": conversation.peerAddress, "version": conversation.version == .v1 ? "v1" : "v2", "conversationID": conversation.conversationID ?? "", + "keyMaterial": conversation.keyMaterial?.base64EncodedString() ?? "" ] } diff --git a/src/lib/Conversation.ts b/src/lib/Conversation.ts index 760aae7be..306b2305d 100644 --- a/src/lib/Conversation.ts +++ b/src/lib/Conversation.ts @@ -14,6 +14,10 @@ export class Conversation { peerAddress: string version: string conversationID?: string | undefined + /** + * Base64 encoded key material for the conversation. + */ + keyMaterial?: string | undefined constructor( client: XMTP.Client, @@ -24,6 +28,7 @@ export class Conversation { peerAddress: string version: string conversationID?: string | undefined + keyMaterial?: string | undefined } ) { this.client = client @@ -33,6 +38,7 @@ export class Conversation { this.peerAddress = params.peerAddress this.version = params.version this.conversationID = params.conversationID + this.keyMaterial = params.keyMaterial } get clientAddress(): string {