@@ -2,6 +2,7 @@ package org.xmtp.android.library.frames
2
2
3
3
import android.util.Base64
4
4
import org.xmtp.android.library.Client
5
+ import org.xmtp.android.library.XMTPException
5
6
import org.xmtp.android.library.frames.FramesConstants.PROTOCOL_VERSION
6
7
import org.xmtp.android.library.messages.PrivateKeyBuilder
7
8
import org.xmtp.android.library.messages.Signature
@@ -10,6 +11,8 @@ import org.xmtp.proto.message.contents.PublicKeyOuterClass.SignedPublicKeyBundle
10
11
import java.security.MessageDigest
11
12
import org.xmtp.proto.message.contents.Frames.FrameActionBody
12
13
import org.xmtp.proto.message.contents.Frames.FrameAction
14
+ import java.util.Date
15
+ import kotlin.time.Duration.Companion.nanoseconds
13
16
14
17
class FramesClient (private val xmtpClient : Client , var proxy : OpenFramesProxy = OpenFramesProxy ()) {
15
18
@@ -19,20 +22,19 @@ class FramesClient(private val xmtpClient: Client, var proxy: OpenFramesProxy =
19
22
val buttonIndex = inputs.buttonIndex
20
23
val inputText = inputs.inputText
21
24
val state = inputs.state
22
- val now = System .currentTimeMillis() / 1000
23
- val frameActionBuilder = FrameActionBody
24
- .newBuilder()
25
- .setFrameUrl(frameUrl)
26
- .setButtonIndex(buttonIndex)
27
- .setOpaqueConversationIdentifier(opaqueConversationIdentifier)
28
- .setTimestamp(now)
29
- .setUnixTimestamp(now.toInt())
30
-
31
- if (inputText != null ) {
32
- frameActionBuilder.inputText = inputText
33
- }
34
- if (state != null ) {
35
- frameActionBuilder.state = state
25
+ val now = Date ().time * 1_000_000
26
+ val frameActionBuilder = FrameActionBody .newBuilder().also { frame ->
27
+ frame.frameUrl = frameUrl
28
+ frame.buttonIndex = buttonIndex
29
+ frame.opaqueConversationIdentifier = opaqueConversationIdentifier
30
+ frame.timestamp = now
31
+ frame.unixTimestamp = now.toInt()
32
+ if (inputText != null ) {
33
+ frame.inputText = inputText
34
+ }
35
+ if (state != null ) {
36
+ frame.state = state
37
+ }
36
38
}
37
39
38
40
val toSign = frameActionBuilder.build()
@@ -59,10 +61,11 @@ class FramesClient(private val xmtpClient: Client, var proxy: OpenFramesProxy =
59
61
val signature = signDigest(digest)
60
62
61
63
val publicKeyBundle = getPublicKeyBundle()
62
- val frameAction = FrameAction .newBuilder()
63
- .setActionBody(actionBodyInputs.toByteString())
64
- .setSignature(signature)
65
- .setSignedPublicKeyBundle(publicKeyBundle).build()
64
+ val frameAction = FrameAction .newBuilder().also {
65
+ it.actionBody = actionBodyInputs.toByteString()
66
+ it.signature = signature
67
+ it.signedPublicKeyBundle = publicKeyBundle
68
+ }.build()
66
69
67
70
return frameAction.toByteArray()
68
71
}
@@ -77,7 +80,7 @@ class FramesClient(private val xmtpClient: Client, var proxy: OpenFramesProxy =
77
80
}
78
81
is ConversationActionInputs .Dm -> {
79
82
val dmInputs = inputs.conversationInputs.inputs
80
- val conversationTopic = dmInputs.conversationTopic ? : throw InvalidArgumentsError ( )
83
+ val conversationTopic = dmInputs.conversationTopic ? : throw XMTPException ( " No conversation topic " )
81
84
val combined = (conversationTopic.lowercase() + dmInputs.participantAccountAddresses.map { it.lowercase() }.sorted().joinToString(" " )).toByteArray()
82
85
val digest = sha256(combined)
83
86
Base64 .encodeToString(digest, Base64 .NO_WRAP )
0 commit comments