Skip to content

Commit

Permalink
feat: Key Material
Browse files Browse the repository at this point in the history
Exposed Key Material for conversations

Added test
  • Loading branch information
Alex Risch authored and Alex Risch committed Jan 24, 2024
1 parent 1d16938 commit 08b6396
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
)
}

Expand Down
28 changes: 28 additions & 0 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
1 change: 1 addition & 0 deletions ios/Wrappers/ConversationWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ConversationWrapper {
"peerAddress": conversation.peerAddress,
"version": conversation.version == .v1 ? "v1" : "v2",
"conversationID": conversation.conversationID ?? "",
"keyMaterial": conversation.keyMaterial?.base64EncodedString() ?? ""
]
}

Expand Down
6 changes: 6 additions & 0 deletions src/lib/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class Conversation<ContentTypes> {
peerAddress: string
version: string
conversationID?: string | undefined
/**
* Base64 encoded key material for the conversation.
*/
keyMaterial?: string | undefined

constructor(
client: XMTP.Client<ContentTypes>,
Expand All @@ -24,6 +28,7 @@ export class Conversation<ContentTypes> {
peerAddress: string
version: string
conversationID?: string | undefined
keyMaterial?: string | undefined
}
) {
this.client = client
Expand All @@ -33,6 +38,7 @@ export class Conversation<ContentTypes> {
this.peerAddress = params.peerAddress
this.version = params.version
this.conversationID = params.conversationID
this.keyMaterial = params.keyMaterial
}

get clientAddress(): string {
Expand Down

0 comments on commit 08b6396

Please sign in to comment.