From 20950f33bfde4875fe6a69f5d43d15bfea6b41d4 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 24 Jul 2024 11:35:05 -0600 Subject: [PATCH] fix: remove all runblockings from the code --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 9c3263a12..d44bda3dd 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -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 @@ -349,29 +348,29 @@ class XMTPModule : Module() { } } - AsyncFunction("sign") { inboxId: String, digest: List, 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, 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 ->