diff --git a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt index 0fed1cadb..7606afac3 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt @@ -99,7 +99,7 @@ class ClientTest { val bundle = client.privateKeyBundle val clientFromV1Bundle = - Client().buildFromBundle(bundle, account = fakeWallet, options = options) + Client().buildFromBundle(bundle, options = options) assertEquals(client.address, clientFromV1Bundle.address) assertEquals( client.privateKeyBundleV1.identityKey, diff --git a/library/src/main/java/libxmtp-version.txt b/library/src/main/java/libxmtp-version.txt index 585cee73e..830325fe7 100644 --- a/library/src/main/java/libxmtp-version.txt +++ b/library/src/main/java/libxmtp-version.txt @@ -1,3 +1,3 @@ -Version: 2137e4f1 +Version: 46fad302 Branch: main -Date: 2024-05-30 18:16:18 +0000 +Date: 2024-06-04 02:30:29 +0000 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 71fca3f27..594ff5724 100644 --- a/library/src/main/java/org/xmtp/android/library/Client.kt +++ b/library/src/main/java/org/xmtp/android/library/Client.kt @@ -44,7 +44,6 @@ 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 uniffi.xmtpv3.generateInboxId import uniffi.xmtpv3.getInboxIdForAddress @@ -216,7 +215,7 @@ class Client() { val clientOptions = options ?: ClientOptions() return runBlocking { try { - val (privateKeyBundleV1, legacyIdentityKey) = loadOrCreateKeys( + val privateKeyBundleV1 = loadOrCreateKeys( account, apiClient, clientOptions @@ -228,7 +227,6 @@ class Client() { account, clientOptions.appContext, privateKeyBundleV1, - legacyIdentityKey, account.address ) @@ -276,7 +274,6 @@ class Client() { account, options?.appContext, v1Bundle, - LegacyIdentitySource.STATIC, address ) } @@ -302,10 +299,10 @@ class Client() { account: SigningKey?, appContext: Context?, privateKeyBundleV1: PrivateKeyBundleV1, - legacyIdentitySource: LegacyIdentitySource, - accountAddress: String, + address: String, ): Pair { var dbPath = "" + val accountAddress = address.lowercase() val v3Client: FfiXmtpClient? = if (isAlphaMlsEnabled(options)) { var inboxId = getInboxIdForAddress( @@ -314,9 +311,11 @@ class Client() { isSecure = options.api.isSecure, accountAddress = accountAddress ) + if (inboxId.isNullOrBlank()) { inboxId = generateInboxId(accountAddress, 0.toULong()) } + val alias = "xmtp-${options.api.env}-$inboxId" val dbDir = if (options.dbDirectory == null) { @@ -367,7 +366,8 @@ class Client() { db = dbPath, encryptionKey = encryptionKey, accountAddress = accountAddress, - legacyIdentitySource = legacyIdentitySource, + inboxId = inboxId, + nonce = 0.toULong(), legacySignedPrivateKeyProto = privateKeyBundleV1.toV2().identityKey.toByteArray() ) } else { @@ -408,16 +408,16 @@ class Client() { account: SigningKey, apiClient: ApiClient, options: ClientOptions? = null, - ): Pair { + ): PrivateKeyBundleV1 { val keys = loadPrivateKeys(account, apiClient, options) return if (keys != null) { - Pair(keys, LegacyIdentitySource.NETWORK) + keys } else { val v1Keys = PrivateKeyBundleV1.newBuilder().build().generate(account, options) val keyBundle = PrivateKeyBundleBuilder.buildFromV1Key(v1Keys) val encryptedKeys = keyBundle.encrypted(account, options?.preEnableIdentityCallback) authSave(apiClient, keyBundle.v1, encryptedKeys) - Pair(v1Keys, LegacyIdentitySource.KEY_GENERATOR) + v1Keys } } diff --git a/library/src/main/java/xmtpv3.kt b/library/src/main/java/xmtpv3.kt index fd99a4a99..ff09042a6 100644 --- a/library/src/main/java/xmtpv3.kt +++ b/library/src/main/java/xmtpv3.kt @@ -1023,6 +1023,10 @@ internal interface UniffiLib : Library { `chainRpcUrl`: RustBuffer.ByValue, ): Long + fun uniffi_xmtpv3_fn_method_ffisignaturerequest_is_ready( + `ptr`: Pointer, + ): Long + fun uniffi_xmtpv3_fn_method_ffisignaturerequest_missing_address_signatures( `ptr`: Pointer, ): Long @@ -1157,8 +1161,9 @@ internal interface UniffiLib : Library { `isSecure`: Byte, `db`: RustBuffer.ByValue, `encryptionKey`: RustBuffer.ByValue, + `inboxId`: RustBuffer.ByValue, `accountAddress`: RustBuffer.ByValue, - `legacyIdentitySource`: RustBuffer.ByValue, + `nonce`: Long, `legacySignedPrivateKeyProto`: RustBuffer.ByValue, ): Long @@ -1626,6 +1631,9 @@ internal interface UniffiLib : Library { fun uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_erc1271_signature( ): Short + fun uniffi_xmtpv3_checksum_method_ffisignaturerequest_is_ready( + ): Short + fun uniffi_xmtpv3_checksum_method_ffisignaturerequest_missing_address_signatures( ): Short @@ -1718,7 +1726,7 @@ private fun uniffiCheckContractApiVersion(lib: UniffiLib) { @Suppress("UNUSED_PARAMETER") private fun uniffiCheckApiChecksums(lib: UniffiLib) { - if (lib.uniffi_xmtpv3_checksum_func_create_client() != 30339.toShort()) { + if (lib.uniffi_xmtpv3_checksum_func_create_client() != 51078.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_xmtpv3_checksum_func_create_v2_client() != 48060.toShort()) { @@ -1877,6 +1885,9 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_erc1271_signature() != 27040.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_xmtpv3_checksum_method_ffisignaturerequest_is_ready() != 65051.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_xmtpv3_checksum_method_ffisignaturerequest_missing_address_signatures() != 34688.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -4149,6 +4160,8 @@ public interface FfiSignatureRequestInterface { `chainRpcUrl`: kotlin.String, ) + suspend fun `isReady`(): kotlin.Boolean + /** * missing signatures that are from [MemberKind::Address] */ @@ -4313,6 +4326,37 @@ open class FfiSignatureRequest : Disposable, AutoCloseable, FfiSignatureRequestI } + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + override suspend fun `isReady`(): kotlin.Boolean { + return uniffiRustCallAsync( + callWithPointer { thisPtr -> + UniffiLib.INSTANCE.uniffi_xmtpv3_fn_method_ffisignaturerequest_is_ready( + thisPtr, + + ) + }, + { future, callback, continuation -> + UniffiLib.INSTANCE.ffi_xmtpv3_rust_future_poll_i8( + future, + callback, + continuation + ) + }, + { future, continuation -> + UniffiLib.INSTANCE.ffi_xmtpv3_rust_future_complete_i8( + future, + continuation + ) + }, + { future -> UniffiLib.INSTANCE.ffi_xmtpv3_rust_future_free_i8(future) }, + // lift function + { FfiConverterBoolean.lift(it) }, + // Error FFI converter + UniffiNullRustCallStatusErrorHandler, + ) + } + + /** * missing signatures that are from [MemberKind::Address] */ @@ -6372,40 +6416,6 @@ public object FfiConverterTypeGroupPermissions : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer) = try { - LegacyIdentitySource.values()[buf.getInt() - 1] - } catch (e: IndexOutOfBoundsException) { - throw RuntimeException("invalid enum value, something is very wrong!!", e) - } - - override fun allocationSize(value: LegacyIdentitySource) = 4UL - - override fun write(value: LegacyIdentitySource, buf: ByteBuffer) { - buf.putInt(value.ordinal + 1) - } -} - - sealed class SigningException(message: String) : Exception(message) { class Generic(message: String) : SigningException(message) @@ -7149,6 +7159,27 @@ public object FfiConverterMapStringBoolean : } +/** + * It returns a new client of the specified `inbox_id`. + * Note that the `inbox_id` must be either brand new or already associated with the `account_address`. + * i.e. `inbox_id` cannot be associated with another account address. + * + * Prior to calling this function, it's suggested to form `inbox_id`, `account_address`, and `nonce` like below. + * + * ```text + * inbox_id = get_inbox_id_for_address(account_address) + * nonce = 0 + * + * // if inbox_id is not associated, we will create new one. + * if !inbox_id { + * if !legacy_key { nonce = random_u64() } + * inbox_id = generate_inbox_id(account_address, nonce) + * } // Otherwise, we will just use the inbox and ignore the nonce. + * db_path = $inbox_id-$env + * + * xmtp.create_client(account_address, nonce, inbox_id, Option) + * ``` + */ @Throws(GenericException::class) @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") suspend fun `createClient`( @@ -7157,8 +7188,9 @@ suspend fun `createClient`( `isSecure`: kotlin.Boolean, `db`: kotlin.String?, `encryptionKey`: kotlin.ByteArray?, + `inboxId`: kotlin.String, `accountAddress`: kotlin.String, - `legacyIdentitySource`: LegacyIdentitySource, + `nonce`: kotlin.ULong, `legacySignedPrivateKeyProto`: kotlin.ByteArray?, ): FfiXmtpClient { return uniffiRustCallAsync( @@ -7170,8 +7202,9 @@ suspend fun `createClient`( FfiConverterBoolean.lower(`isSecure`), FfiConverterOptionalString.lower(`db`), FfiConverterOptionalByteArray.lower(`encryptionKey`), + FfiConverterString.lower(`inboxId`), FfiConverterString.lower(`accountAddress`), - FfiConverterTypeLegacyIdentitySource.lower(`legacyIdentitySource`), + FfiConverterULong.lower(`nonce`), FfiConverterOptionalByteArray.lower(`legacySignedPrivateKeyProto`), ), { future, callback, continuation -> diff --git a/library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so b/library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so index 4116bb7c0..3dcc9eaa8 100755 Binary files a/library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so and b/library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so differ diff --git a/library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so b/library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so index 1b8eed19b..dee7732ed 100755 Binary files a/library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so and b/library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so differ diff --git a/library/src/main/jniLibs/x86/libuniffi_xmtpv3.so b/library/src/main/jniLibs/x86/libuniffi_xmtpv3.so index 6d763879b..faa1ab333 100755 Binary files a/library/src/main/jniLibs/x86/libuniffi_xmtpv3.so and b/library/src/main/jniLibs/x86/libuniffi_xmtpv3.so differ diff --git a/library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so b/library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so index 7e5975174..2f8aab8c3 100755 Binary files a/library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so and b/library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so differ