Skip to content

Commit fed46b8

Browse files
committed
Add wrappers for new auth ffi types
1 parent 423398c commit fed46b8

File tree

8 files changed

+8794
-7179
lines changed

8 files changed

+8794
-7179
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 5597847ab
2-
Branch: cv/release-1.6-rc2
3-
Date: 2025-11-04 22:17:27 +0000
1+
Version: f690f973
2+
Branch: auth-ffi-bindings
3+
Date: 2025-10-28 21:41:34 +0000
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.xmtp.android.library
2+
3+
import uniffi.xmtpv3.FfiAuthCallback
4+
import uniffi.xmtpv3.FfiAuthHandle
5+
import uniffi.xmtpv3.FfiCredential
6+
7+
data class Credential(val name: String, val value: String, val expiresAtSeconds: Long) {
8+
internal fun toFfi(): FfiCredential {
9+
return FfiCredential(name, value, expiresAtSeconds)
10+
}
11+
12+
companion object {
13+
internal fun fromFfi(ffi: FfiCredential): Credential {
14+
return Credential(ffi.`name`, ffi.`value`, ffi.`expiresAtSeconds`)
15+
}
16+
}
17+
}
18+
19+
interface AuthCallback {
20+
suspend fun onAuthRequired(): Credential
21+
22+
fun toFfi(): FfiAuthCallback =
23+
object : FfiAuthCallback {
24+
override suspend fun `onAuthRequired`(): FfiCredential {
25+
return this@toFfi.onAuthRequired().toFfi()
26+
}
27+
}
28+
}
29+
30+
class AuthHandle(private val ffiHandle: FfiAuthHandle) {
31+
constructor() : this(FfiAuthHandle())
32+
33+
suspend fun set(credential: Credential) {
34+
ffiHandle.`set`(credential.toFfi())
35+
}
36+
37+
fun close() {
38+
ffiHandle.close()
39+
}
40+
}

library/src/main/java/org/xmtp/android/library/Client.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import org.xmtp.android.library.libxmtp.InboxState
1616
import org.xmtp.android.library.libxmtp.PublicIdentity
1717
import org.xmtp.android.library.libxmtp.SignatureRequest
1818
import org.xmtp.android.library.libxmtp.toFfi
19+
import uniffi.xmtpv3.FfiAuthCallback
20+
import uniffi.xmtpv3.FfiAuthHandle
1921
import uniffi.xmtpv3.FfiForkRecoveryOpts
2022
import uniffi.xmtpv3.FfiForkRecoveryPolicy
2123
import uniffi.xmtpv3.FfiKeyPackageStatus
@@ -55,6 +57,8 @@ data class ClientOptions(
5557
val isSecure: Boolean = true,
5658
val appVersion: String? = null,
5759
val gatewayHost: String? = null,
60+
val authCallback: AuthCallback? = null,
61+
val authHandle: AuthHandle? = null,
5862
)
5963
}
6064

@@ -196,7 +200,14 @@ class Client(
196200
}
197201

198202
// If not cached or not connected, create a fresh client
199-
val newClient = connectToBackend(api.env.getUrl(), api.gatewayHost, api.isSecure, api.appVersion)
203+
val newClient = connectToBackend(
204+
api.env.getUrl(),
205+
api.gatewayHost,
206+
api.isSecure,
207+
api.appVersion,
208+
api.authCallback?.toFfi(),
209+
api.authHandle?.ffiHandle
210+
)
200211
apiClientCache[cacheKey] = newClient
201212
return@withLock newClient
202213
}
@@ -212,7 +223,14 @@ class Client(
212223
}
213224

214225
// If not cached or not connected, create a fresh client
215-
val newClient = connectToBackend(api.env.getUrl(), api.gatewayHost, api.isSecure, api.appVersion)
226+
val newClient = connectToBackend(
227+
api.env.getUrl(),
228+
api.gatewayHost,
229+
api.isSecure,
230+
api.appVersion,
231+
api.authCallback?.toFfi(),
232+
api.authHandle?.ffiHandle
233+
)
216234
syncApiClientCache[cacheKey] = newClient
217235
return@withLock newClient
218236
}

0 commit comments

Comments
 (0)