Skip to content

Commit

Permalink
update to the latest client creation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 25, 2024
1 parent ca7537f commit 3fd9099
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
21 changes: 17 additions & 4 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.BatchQueryResponse
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
import uniffi.xmtpv3.FfiXmtpClient
import uniffi.xmtpv3.LegacyIdentitySource
import uniffi.xmtpv3.createClient
import java.io.File
import java.nio.charset.StandardCharsets
Expand Down Expand Up @@ -189,7 +190,7 @@ class Client() {
try {
val privateKeyBundleV1 = loadOrCreateKeys(account, apiClient, options)
val libXMTPClient: FfiXmtpClient? =
ffiXmtpClient(options, account, options?.appContext)
ffiXmtpClient(options, account, options?.appContext, privateKeyBundleV1)
val client =
Client(account.getAddress(), privateKeyBundleV1, apiClient, libXMTPClient)
client.ensureUserContactPublished()
Expand All @@ -204,6 +205,7 @@ class Client() {
options: ClientOptions?,
account: SigningKey,
appContext: Context?,
privateKeyBundleV1: PrivateKeyBundleV1,
): FfiXmtpClient? {
val libXMTPClient: FfiXmtpClient? =
if (options != null && options.enableLibXmtpV3 && options.appContext != null) {
Expand All @@ -229,16 +231,27 @@ class Client() {

createClient(
logger = logger,
ffiInboxOwner = account,
host = "http://10.0.2.2:5556",
isSecure = false,
db = dbPath,
encryptionKey = retrievedKey
encryptionKey = retrievedKey,
accountAddress = account.getAddress(),
// Figure out where the keys came from
// NONE,
// STATIC, // someone passed in a bundle
// NETWORK, // v2 keys already on the network
// KEY_GENERATOR; // I created them
legacyIdentitySource = LegacyIdentitySource.NETWORK,
legacySignedPrivateKeyProto = privateKeyBundleV1.toV2().toByteArray()
)
} else {
null
}
libXMTPClient?.registerIdentity()

libXMTPClient?.textToSign()?.let {
libXMTPClient.registerIdentity(account.sign(it))
}

return libXMTPClient
}

Expand Down
8 changes: 5 additions & 3 deletions library/src/main/java/org/xmtp/android/library/SigningKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ import org.xmtp.android.library.messages.rawData
import org.xmtp.proto.message.contents.PrivateKeyOuterClass
import org.xmtp.proto.message.contents.PublicKeyOuterClass
import org.xmtp.proto.message.contents.SignatureOuterClass
import uniffi.xmtpv3.FfiInboxOwner
import java.math.BigInteger
import java.util.Date

interface SigningKey: FfiInboxOwner {
interface SigningKey {

fun getAddress(): String

suspend fun sign(data: ByteArray): SignatureOuterClass.Signature?

suspend fun signLegacy(message: String): SignatureOuterClass.Signature?

override fun sign(text: String): ByteArray
fun sign(text: String): ByteArray
}

/**
Expand Down

0 comments on commit 3fd9099

Please sign in to comment.