Skip to content

Commit

Permalink
update the frames client to use the new signer
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 19, 2024
1 parent 0a21656 commit 0c28805
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 4 additions & 0 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ class Client() {
return Pair(ffiClient, dbPath)
}

fun signInstallationKey(message: String): ByteArray {
return ffiClient.signWithInstallationKey(message)
}

fun findGroup(groupId: String): Group? {
return try {
Group(this, ffiClient.conversation(groupId.hexToByteArray()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import org.xmtp.android.library.XMTPException
import org.xmtp.android.library.frames.FramesConstants.PROTOCOL_VERSION
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.Signature
import org.xmtp.android.library.messages.getPublicKeyBundle
import org.xmtp.proto.message.contents.PublicKeyOuterClass.SignedPublicKeyBundle
import java.security.MessageDigest
import org.xmtp.proto.message.contents.Frames.FrameActionBody
import org.xmtp.proto.message.contents.Frames.FrameAction
Expand Down Expand Up @@ -45,17 +43,14 @@ class FramesClient(private val xmtpClient: Client, var proxy: OpenFramesProxy =
return FramePostPayload("xmtp@$PROTOCOL_VERSION", untrustedData, trustedData)
}

private suspend fun signDigest(digest: ByteArray): Signature {
val signedPrivateKey = xmtpClient.keys.identityKey
val privateKey = PrivateKeyBuilder.buildFromSignedPrivateKey(signedPrivateKey)
return PrivateKeyBuilder(privateKey).sign(digest)
private fun signDigest(message: String): ByteArray {
return xmtpClient.signInstallationKey(message)
}

private suspend fun buildSignedFrameAction(actionBodyInputs: FrameActionBody): ByteArray {
val digest = sha256(actionBodyInputs.toByteArray())
val digest = sha256(actionBodyInputs.toByteArray()).toString()
val signature = signDigest(digest)

val publicKeyBundle = getPublicKeyBundle()
val frameAction = FrameAction.newBuilder().also {
it.actionBody = actionBodyInputs.toByteString()
it.signature = signature
Expand Down

0 comments on commit 0c28805

Please sign in to comment.