Skip to content

Commit

Permalink
fix: remove all runblockings from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jul 24, 2024
1 parent d9563cd commit 20950f3
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import org.json.JSONObject
Expand Down Expand Up @@ -349,29 +348,29 @@ class XMTPModule : Module() {
}
}

AsyncFunction("sign") { inboxId: String, digest: List<Int>, keyType: String, preKeyIndex: Int ->
logV("sign")
val client = clients[inboxId] ?: throw XMTPException("No client")
val digestBytes =
digest.foldIndexed(ByteArray(digest.size)) { i, a, v ->
a.apply {
set(
i,
v.toByte()
)
AsyncFunction("sign") Coroutine { inboxId: String, digest: List<Int>, keyType: String, preKeyIndex: Int ->
withContext(Dispatchers.IO) {
logV("sign")
val client = clients[inboxId] ?: throw XMTPException("No client")
val digestBytes =
digest.foldIndexed(ByteArray(digest.size)) { i, a, v ->
a.apply {
set(
i,
v.toByte()
)
}
}
val privateKeyBundle = client.keys
val signedPrivateKey = if (keyType == "prekey") {
privateKeyBundle.preKeysList[preKeyIndex]
} else {
privateKeyBundle.identityKey
}
val privateKeyBundle = client.keys
val signedPrivateKey = if (keyType == "prekey") {
privateKeyBundle.preKeysList[preKeyIndex]
} else {
privateKeyBundle.identityKey
}
val signature = runBlocking {
val privateKey = PrivateKeyBuilder.buildFromSignedPrivateKey(signedPrivateKey)
PrivateKeyBuilder(privateKey).sign(digestBytes)
val signature = PrivateKeyBuilder(privateKey).sign(digestBytes)
signature.toByteArray().map { it.toInt() and 0xFF }
}
signature.toByteArray().map { it.toInt() and 0xFF }
}

AsyncFunction("exportPublicKeyBundle") { inboxId: String ->
Expand Down

0 comments on commit 20950f3

Please sign in to comment.