From 6df9da4db98c6cdbadecfe65de72426af66a5cd1 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Wed, 24 Jan 2024 13:52:38 -0800 Subject: [PATCH 01/14] Added setup for testing against local xmtp-android --- android/build.gradle | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index bdfb96053..09754f62f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -95,8 +95,19 @@ repositories { dependencies { implementation project(':expo-modules-core') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}" - implementation "org.xmtp:android:0.7.3" + // implementation "org.xmtp:android:0.7.6" implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.facebook.react:react-native:0.71.3' implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1" + // xmtp-android local testing + implementation files('/Users/cameronvoell/XMTP/xmtp-android/library/build/outputs/aar/library-debug.aar') + implementation 'com.google.crypto.tink:tink-android:1.7.0' + implementation 'io.grpc:grpc-kotlin-stub:1.3.0' + implementation 'io.grpc:grpc-okhttp:1.51.1' + implementation 'io.grpc:grpc-protobuf-lite:1.51.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' + implementation 'org.web3j:crypto:5.0.0' + implementation "net.java.dev.jna:jna:5.13.0@aar" + implementation 'com.google.protobuf:protobuf-kotlin-lite:3.22.3' + implementation 'org.xmtp:proto-kotlin:3.31.0' } From eb11dee5d9df15c044578db39a858762053e7857 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Wed, 31 Jan 2024 11:00:27 -0800 Subject: [PATCH 02/14] Add missing SigningKey methods --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 4e79d8979..5cb1bbf3f 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.suspendCancellableCoroutine import org.json.JSONObject import org.xmtp.android.library.Client @@ -76,16 +77,25 @@ class ReactNativeSigner(var module: XMTPModule, override var address: String) : continuations.remove(id) } - override suspend fun sign(data: ByteArray): Signature { - val request = SignatureRequest(message = String(data, Charsets.UTF_8)) + override suspend fun sign(data: ByteArray): Signature? { + val message = String(data, Charsets.UTF_8) + return signLegacy(message) + } + + override suspend fun signLegacy(message: String): Signature { + val request = SignatureRequest(message = message) module.sendEvent("sign", mapOf("id" to request.id, "message" to request.message)) return suspendCancellableCoroutine { continuation -> continuations[request.id] = continuation } } - override suspend fun sign(message: String): Signature = - sign(message.toByteArray()) + override fun sign(message: String): ByteArray { + return runBlocking { + signLegacy(message).toByteArray() + } + } + } data class SignatureRequest( From d9378de8661c5a8eb180dfe238dc5dacb0aae739 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Wed, 31 Jan 2024 12:57:57 -0800 Subject: [PATCH 03/14] Added enableAlphaMls ClientOption --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 18 ++++++---- example/src/LaunchScreen.tsx | 36 +++++++++++++++++++ src/lib/Client.ts | 14 +++++--- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 5cb1bbf3f..1ede5ab1e 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -55,6 +55,7 @@ import java.util.UUID import kotlin.coroutines.Continuation import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException +import uniffi.xmtpv3.LegacyIdentitySource class ReactNativeSigner(var module: XMTPModule, override var address: String) : SigningKey { private val continuations: MutableMap> = mutableMapOf() @@ -160,7 +161,7 @@ class XMTPModule : Module() { // // Auth functions // - AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean? -> + AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean? -> logV("auth") val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address) signer = reactSigner @@ -176,7 +177,8 @@ class XMTPModule : Module() { val options = ClientOptions( api = apiEnvironments(environment, appVersion), preCreateIdentityCallback = preCreateIdentityCallback, - preEnableIdentityCallback = preEnableIdentityCallback + preEnableIdentityCallback = preEnableIdentityCallback, + enableAlphaMls = enableAlphaMls == true ) clients[address] = Client().create(account = reactSigner, options = options) ContentJson.Companion @@ -190,7 +192,7 @@ class XMTPModule : Module() { } // Generate a random wallet and set the client to that - AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean? -> + AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean? -> logV("createRandom") val privateKey = PrivateKeyBuilder() @@ -206,7 +208,8 @@ class XMTPModule : Module() { val options = ClientOptions( api = apiEnvironments(environment, appVersion), preCreateIdentityCallback = preCreateIdentityCallback, - preEnableIdentityCallback = preEnableIdentityCallback + preEnableIdentityCallback = preEnableIdentityCallback, + enableAlphaMls = enableAlphaMls == true ) val randomClient = Client().create(account = privateKey, options = options) ContentJson.Companion @@ -214,10 +217,13 @@ class XMTPModule : Module() { randomClient.address } - AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String? -> + AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean? -> try { logV("createFromKeyBundle") - val options = ClientOptions(api = apiEnvironments(environment, appVersion)) + val options = ClientOptions( + api = apiEnvironments(environment, appVersion), + enableAlphaMls = enableAlphaMls == true + ) val bundle = PrivateKeyOuterClass.PrivateKeyBundle.parseFrom( Base64.decode( diff --git a/example/src/LaunchScreen.tsx b/example/src/LaunchScreen.tsx index 3bf8f37bb..e2806068f 100644 --- a/example/src/LaunchScreen.tsx +++ b/example/src/LaunchScreen.tsx @@ -189,6 +189,25 @@ export default function LaunchScreen({ }} /> + +