@@ -6,7 +6,6 @@ import org.junit.Assert.assertEquals
6
6
import org.junit.Assert.assertTrue
7
7
import org.junit.Test
8
8
import org.junit.runner.RunWith
9
- import org.xmtp.android.library.Crypto.Companion.calculateMac
10
9
import org.xmtp.android.library.Crypto.Companion.verifyHmacSignature
11
10
import org.xmtp.android.library.codecs.CompositeCodec
12
11
import org.xmtp.android.library.codecs.ContentCodec
@@ -15,19 +14,11 @@ import org.xmtp.android.library.codecs.ContentTypeIdBuilder
15
14
import org.xmtp.android.library.codecs.DecodedComposite
16
15
import org.xmtp.android.library.codecs.EncodedContent
17
16
import org.xmtp.android.library.codecs.TextCodec
18
- import org.xmtp.android.library.messages.InvitationV1
17
+ import org.xmtp.android.library.messages.InvitationV1ContextBuilder
19
18
import org.xmtp.android.library.messages.MessageV2Builder
20
19
import org.xmtp.android.library.messages.PrivateKeyBuilder
21
- import org.xmtp.android.library.messages.PrivateKeyBundleV1
22
- import org.xmtp.android.library.messages.SealedInvitationBuilder
23
- import org.xmtp.android.library.messages.createDeterministic
24
- import org.xmtp.android.library.messages.generate
25
- import org.xmtp.android.library.messages.getPublicKeyBundle
26
- import org.xmtp.android.library.messages.toV2
27
20
import org.xmtp.android.library.messages.walletAddress
28
- import java.security.Key
29
21
import java.time.Instant
30
- import java.util.Date
31
22
32
23
data class NumberCodec (
33
24
override var contentType : ContentTypeId = ContentTypeIdBuilder .builderFromAuthorityId(
@@ -158,52 +149,48 @@ class CodecTest {
158
149
159
150
@Test
160
151
fun testReturnsAllHMACKeys () {
161
- val baseTime = Instant .now()
162
- val timestamps = List (5 ) { i -> baseTime.plusSeconds(i.toLong()) }
163
- val fixtures = fixtures()
164
-
165
- val invites = timestamps.map { createdAt ->
166
- val fakeWallet = FakeWallet .generate()
167
- val recipient = PrivateKeyBundleV1 .newBuilder().build().generate(wallet = fakeWallet)
168
- InvitationV1 .newBuilder().build().createDeterministic(
169
- sender = fixtures.aliceClient.privateKeyBundleV1.toV2(),
170
- recipient = recipient.toV2().getPublicKeyBundle()
152
+ val alix = PrivateKeyBuilder ()
153
+ val clientOptions =
154
+ ClientOptions (api = ClientOptions .Api (env = XMTPEnvironment .LOCAL , isSecure = false ))
155
+ val alixClient = Client ().create(alix, clientOptions)
156
+ val conversations = mutableListOf<Conversation >()
157
+ repeat(5 ) {
158
+ val account = PrivateKeyBuilder ()
159
+ val client = Client ().create(account, clientOptions)
160
+ conversations.add(
161
+ alixClient.conversations.newConversation(
162
+ client.address,
163
+ context = InvitationV1ContextBuilder .buildFromConversation(conversationId = " hi" )
164
+ )
171
165
)
172
166
}
173
167
174
168
val thirtyDayPeriodsSinceEpoch = Instant .now().epochSecond / 60 / 60 / 24 / 30
175
169
176
- val periods = listOf (
177
- thirtyDayPeriodsSinceEpoch - 1 ,
178
- thirtyDayPeriodsSinceEpoch,
179
- thirtyDayPeriodsSinceEpoch + 1
180
- )
181
-
182
- val hmacKeys = fixtures.aliceClient.conversations.getHmacKeys()
170
+ val hmacKeys = alixClient.conversations.getHmacKeys()
183
171
184
172
val topics = hmacKeys.hmacKeysMap.keys
185
- invites .forEach { invite ->
186
- assertTrue(topics.contains(invite .topic))
173
+ conversations .forEach { convo ->
174
+ assertTrue(topics.contains(convo .topic))
187
175
}
188
176
189
177
val topicHmacs = mutableMapOf<String , ByteArray >()
190
178
val headerBytes = ByteArray (10 )
191
179
192
- invites .map { invite ->
193
- val topic = invite .topic
180
+ conversations .map { conversation ->
181
+ val topic = conversation .topic
194
182
val payload = TextCodec ().encode(content = " Hello, world!" )
195
183
196
184
val message = MessageV2Builder .buildEncode(
197
- client = fixtures.aliceClient ,
185
+ client = alixClient ,
198
186
encodedContent = payload,
199
187
topic = topic,
200
188
keyMaterial = headerBytes,
201
189
codec = TextCodec ()
202
190
)
203
191
204
- val conversation = fixtures.aliceClient.fetchConversation(topic)
205
- val keyMaterial = conversation?.keyMaterial
206
- val info = " $thirtyDayPeriodsSinceEpoch -${fixtures.aliceClient.address} "
192
+ val keyMaterial = conversation.keyMaterial
193
+ val info = " $thirtyDayPeriodsSinceEpoch -${alixClient.address} "
207
194
val hmac = Crypto .calculateMac(
208
195
Crypto .deriveKey(keyMaterial!! , ByteArray (0 ), info.toByteArray()),
209
196
headerBytes
@@ -222,6 +209,5 @@ class CodecTest {
222
209
assertTrue(valid == (idx == 1 ))
223
210
}
224
211
}
225
-
226
212
}
227
213
}
0 commit comments