Skip to content

Commit

Permalink
adds blocking callback before auth inbox sign action occurs (#282)
Browse files Browse the repository at this point in the history
Co-authored-by: cameronvoell <[email protected]>
  • Loading branch information
cameronvoell and cameronvoell authored Aug 1, 2024
1 parent 85c8bb2 commit 89d4d0f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,33 @@ class ClientTest {
}
}

@Test
fun testPreAuthenticateToInboxCallback() {
val fakeWallet = PrivateKeyBuilder()
val expectation = CompletableFuture<Unit>()
val key = SecureRandom().generateSeed(32)
val context = InstrumentationRegistry.getInstrumentation().targetContext

val preAuthenticateToInboxCallback: suspend () -> Unit = {
expectation.complete(Unit)
}

val opts = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
preAuthenticateToInboxCallback = preAuthenticateToInboxCallback,
enableV3 = true,
appContext = context,
dbEncryptionKey = key
)

try {
runBlocking { Client().create(account = fakeWallet, options = opts) }
expectation.get(5, TimeUnit.SECONDS)
} catch (e: Exception) {
fail("Error: $e")
}
}

@Test
fun testCanDropReconnectDatabase() {
val key = SecureRandom().generateSeed(32)
Expand Down
7 changes: 7 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 @@ -5,6 +5,7 @@ import android.os.Build
import android.util.Log
import com.google.crypto.tink.subtle.Base64
import com.google.gson.GsonBuilder
import kotlinx.coroutines.runBlocking
import org.web3j.crypto.Keys
import org.web3j.crypto.Keys.toChecksumAddress
import org.xmtp.android.library.codecs.ContentCodec
Expand Down Expand Up @@ -61,6 +62,7 @@ data class ClientOptions(
val api: Api = Api(),
val preCreateIdentityCallback: PreEventCallback? = null,
val preEnableIdentityCallback: PreEventCallback? = null,
val preAuthenticateToInboxCallback: PreEventCallback? = null,
val appContext: Context? = null,
val enableV3: Boolean = false,
val dbDirectory: String? = null,
Expand Down Expand Up @@ -349,6 +351,11 @@ class Client() {
}

if (v3Client != null) {
options.preAuthenticateToInboxCallback?.let {
runBlocking {
it.invoke()
}
}
v3Client.signatureRequest()?.let { signatureRequest ->
if (account != null) {
account.sign(signatureRequest.signatureText())?.let {
Expand Down

0 comments on commit 89d4d0f

Please sign in to comment.