Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds blocking callback before auth inbox sign action occurs #282

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading