From 3fd9099e17b8f7f17ed5f97f7ca84e0698eb418f Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 25 Jan 2024 13:48:40 -0800 Subject: [PATCH] update to the latest client creation flow --- .../java/org/xmtp/android/library/Client.kt | 21 +++++++++++++++---- .../org/xmtp/android/library/SigningKey.kt | 8 ++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/library/src/main/java/org/xmtp/android/library/Client.kt b/library/src/main/java/org/xmtp/android/library/Client.kt index dff5ab93e..ddf56c690 100644 --- a/library/src/main/java/org/xmtp/android/library/Client.kt +++ b/library/src/main/java/org/xmtp/android/library/Client.kt @@ -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 @@ -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() @@ -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) { @@ -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 } diff --git a/library/src/main/java/org/xmtp/android/library/SigningKey.kt b/library/src/main/java/org/xmtp/android/library/SigningKey.kt index bcf44a4ce..1b2952f86 100644 --- a/library/src/main/java/org/xmtp/android/library/SigningKey.kt +++ b/library/src/main/java/org/xmtp/android/library/SigningKey.kt @@ -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 } /**