Skip to content

Commit

Permalink
remove v1 and v2 conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 3, 2024
1 parent a39b6c2 commit 2055f48
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 2,872 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class ClientTest {

runBlocking {
client.conversations.newGroup(listOf(client2.address))
client.conversations.syncGroups()
client.conversations.syncConversations()
assertEquals(client.conversations.listGroups().size, 1)
}

Expand All @@ -233,7 +233,7 @@ class ClientTest {
)
}
runBlocking {
client.conversations.syncGroups()
client.conversations.syncConversations()
assertEquals(client.conversations.listGroups().size, 0)
}
}
Expand Down Expand Up @@ -422,7 +422,7 @@ class ClientTest {

runBlocking {
boClient.conversations.newGroup(listOf(alixClient.address))
boClient.conversations.syncGroups()
boClient.conversations.syncConversations()
}

runBlocking {
Expand Down
95 changes: 0 additions & 95 deletions library/src/androidTest/java/org/xmtp/android/library/CodecTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,99 +75,4 @@ class CodecTest {
assertEquals("Error: This app does not support numbers.", messages[0].fallbackContent)
}
}

@Test
@Ignore("Flaky: CI")
fun testCanGetPushInfoBeforeDecoded() {
val codec = NumberCodec()
Client.register(codec = codec)
val fixtures = fixtures()
val aliceClient = fixtures.aliceClient
val aliceConversation = runBlocking {
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
}
runBlocking {
aliceConversation.send(
content = 3.14,
options = SendOptions(contentType = codec.contentType),
)
}
val messages = runBlocking { aliceConversation.messages() }
assert(messages.isNotEmpty())

val message = MessageV2Builder.buildEncode(
client = aliceClient,
encodedContent = messages[0].encodedContent,
topic = aliceConversation.topic,
keyMaterial = aliceConversation.keyMaterial!!,
codec = codec,
)

assertEquals(false, message.shouldPush)
assertEquals(true, message.senderHmac?.isNotEmpty())
}

@Test
fun testReturnsAllHMACKeys() {
val alix = PrivateKeyBuilder()
val clientOptions =
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false))
val alixClient = runBlocking { Client().create(alix, clientOptions) }
val conversations = mutableListOf<Conversation>()
repeat(5) {
val account = PrivateKeyBuilder()
val client = runBlocking { Client().create(account, clientOptions) }
runBlocking {
conversations.add(
alixClient.conversations.newConversation(
client.address,
context = InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi")
)
)
}
}

val thirtyDayPeriodsSinceEpoch = Instant.now().epochSecond / 60 / 60 / 24 / 30

val hmacKeys = alixClient.conversations.getHmacKeys()

val topics = hmacKeys.hmacKeysMap.keys
conversations.forEach { convo ->
assertTrue(topics.contains(convo.topic))
}

val topicHmacs = mutableMapOf<String, ByteArray>()
val headerBytes = ByteArray(10)

conversations.forEach { conversation ->
val topic = conversation.topic
val payload = TextCodec().encode(content = "Hello, world!")

val message = MessageV2Builder.buildEncode(
client = alixClient,
encodedContent = payload,
topic = topic,
keyMaterial = headerBytes,
codec = TextCodec()
)

val keyMaterial = conversation.keyMaterial
val info = "$thirtyDayPeriodsSinceEpoch-${alixClient.address}"
val key = Crypto.deriveKey(keyMaterial!!, ByteArray(0), info.toByteArray())
val hmac = Crypto.calculateMac(key, headerBytes)

topicHmacs[topic] = hmac
}

hmacKeys.hmacKeysMap.forEach { (topic, hmacData) ->
hmacData.valuesList.forEachIndexed { idx, hmacKeyThirtyDayPeriod ->
val valid = verifyHmacSignature(
hmacKeyThirtyDayPeriod.hmacKey.toByteArray(),
topicHmacs[topic]!!,
headerBytes
)
assertTrue(valid == (idx == 1))
}
}
}
}
Loading

0 comments on commit 2055f48

Please sign in to comment.