Skip to content

Commit

Permalink
push up all the logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 2, 2024
1 parent 99143a2 commit f21d0c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
22 changes: 21 additions & 1 deletion library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ class Client() {
}

suspend fun getOrCreateInboxId(environment: ClientOptions.Api, address: String): String {
val start = Date()
var inboxId = getInboxIdForAddress(
logger = XMTPLogger(),
host = environment.env.getUrl(),
isSecure = environment.isSecure,
accountAddress = address.lowercase()
)
val end = Date()
Log.d("PERF", "Get inboxId in ${(end.time - start.time) / 1000.0}s")
if (inboxId.isNullOrBlank()) {
inboxId = generateInboxId(address.lowercase(), 0.toULong())
}
Expand Down Expand Up @@ -166,6 +169,7 @@ class Client() {
): Pair<FfiXmtpClient, String> {
val alias = "xmtp-${options.api.env}-$inboxId"

val start1 = Date()
val mlsDbDirectory = options.dbDirectory
val directoryFile = if (mlsDbDirectory != null) {
File(mlsDbDirectory)
Expand All @@ -174,7 +178,10 @@ class Client() {
}
directoryFile.mkdir()
dbPath = directoryFile.absolutePath + "/$alias.db3"
val end1 = Date()
Log.d("PERF", "Create database ${(end1.time - start1.time) / 1000.0}s")

val start = Date()
val ffiClient = createClient(
logger = logger,
host = options.api.env.getUrl(),
Expand All @@ -187,18 +194,25 @@ class Client() {
legacySignedPrivateKeyProto = null,
historySyncUrl = options.historySyncUrl
)
val end = Date()
Log.d("PERF", "Create ffi client in ${(end.time - start.time) / 1000.0}s")

options.preAuthenticateToInboxCallback?.let {
runBlocking {
it.invoke()
}
}
val start2 = Date()
ffiClient.signatureRequest()?.let { signatureRequest ->
signingKey?.let { handleSignature(signatureRequest, it) }
?: throw XMTPException("No signer passed but signer was required.")
val start3 = Date()
ffiClient.registerIdentity(signatureRequest)
val end3 = Date()
Log.d("PERF", "Register identity ${(end3.time - start3.time) / 1000.0}s")
}

val end2 = Date()
Log.d("PERF", "Handle signatures ${(end2.time - start2.time) / 1000.0}s")
return Pair(ffiClient, dbPath)
}

Expand Down Expand Up @@ -235,9 +249,15 @@ class Client() {
signingKey.blockNumber?.toULong()
)
} else {
val start1 = Date()
signingKey.sign(signatureRequest.signatureText())?.let {
val start3 = Date()
signatureRequest.addEcdsaSignature(it.rawData)
val end3 = Date()
Log.d("PERF", "Add signature ${(end3.time - start3.time) / 1000.0}s")
}
val end1 = Date()
Log.d("PERF", "Do signing ${(end1.time - start1.time) / 1000.0}s")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.xmtp.android.library.messages

import android.util.Log
import com.google.protobuf.kotlin.toByteString
import org.web3j.crypto.ECKeyPair
import org.web3j.crypto.Sign
Expand Down Expand Up @@ -63,6 +64,7 @@ class PrivateKeyBuilder : SigningKey {
}

override suspend fun sign(data: ByteArray): SignatureOuterClass.Signature {
val start = Date()
val signatureData =
Sign.signMessage(
data,
Expand All @@ -71,12 +73,17 @@ class PrivateKeyBuilder : SigningKey {
)
val signatureKey = KeyUtil.getSignatureBytes(signatureData)

return SignatureOuterClass.Signature.newBuilder().also {
val sign = SignatureOuterClass.Signature.newBuilder().also {
it.ecdsaCompact = it.ecdsaCompact.toBuilder().also { builder ->
builder.bytes = signatureKey.take(64).toByteArray().toByteString()
builder.recovery = signatureKey[64].toInt()
}.build()
}.build()
val end = Date()
val time1 = end.time - start.time
Log.d("PERF", "Did the signature ${time1 / 1000.0}s")

return sign
}

override suspend fun sign(message: String): SignatureOuterClass.Signature {
Expand Down

0 comments on commit f21d0c8

Please sign in to comment.