Appearance
Android SDK Reference
Privy
kotlin
public interface Privy {
// A state flow that can be subscribed to for auth state updates
public val authState: StateFlow<AuthState>
// Entry point for custom auth sign in
public val customAuth: LoginWithCustomAuth
// Entry point for embedded wallet flows
public val embeddedWallet: EmbeddedWalletManager
// A method that allows you to suspend execution until Privy is ready
public suspend fun awaitReady()
// Check if Privy is ready to be used
public val isReady: Boolean
public suspend fun logout()
}
AuthState
kotlin
public sealed interface AuthState {
// AuthState has not been determined yet, show loading
public data object NotReady : AuthState
// User is unauthenticated
public data object Unauthenticated : AuthState
// User is authenticated and has a valid auth session
public data class Authenticated(val session: AuthSession) : AuthState
}
AuthSession and the PrivyUser object
kotlin
public data class AuthSession(
val user: PrivyUser
)
public data class PrivyUser(
val id: String,
val linkedAccounts: List<LinkedAccount>,
val embeddedWallets: List<EmbeddedWallet>
)
public sealed interface LinkedAccount {
public data class CustomAuth(/* Account specific data */) :
LinkedAccount
public data class EmbeddedWalletAccount(/* Account specific data */) :
LinkedAccount
}
Custom Auth
kotlin
public typealias TokenProvider = suspend () -> String?
public interface LoginWithCustomAuth {
/**
* Attempts to log the user in using the access token retrieved from
* `tokenProvider` set at Privy initialization.
*
* @return A Result type with the AuthSession the login attempt was
* successful, or a Result.failure otherwise.
*/
public suspend fun loginWithCustomAccessToken(): Result<AuthSession>
}
EmbeddedWalletManager
kotlin
public interface EmbeddedWalletManager {
/**
* Creates a new embedded wallet for the user
*
* @return A result type with the newly created wallet or a failure
*/
public suspend fun createWallet(): Result<EmbeddedWallet>
}
EmbeddedWallet
kotlin
public interface EmbeddedWallet {
// The wallet's address
public val address: String
// The chain id
public val chainId: String?
// Recovery method type
public val recoveryMethod: String?
// HD wallet index
public val hdWalletIndex: Int
// A hook to RpcProvider, which can be used to make rpc requests
public val provider: RpcProvider
}
RPC Provider and Requests
kotlin
public interface RpcProvider {
/**
* Sends a request to the Ethereum provider
*
* @param The rpc request
* @return The response received
*/
public suspend fun request(request: RpcRequest): Result<RpcResponse>
}
RPC Request and Response
kotlin
public data class RpcRequest(
// Ethereum JSON RPC method, reference can be found in the [JSON RPC
// API](https://ethereum.org/en/developers/docs/apis/json-rpc/).
val method: String,
// Ethereum JSON RPC method params, param reference for each method can
// be found in the [JSON RPC API]
// (https://ethereum.org/en/developers/docs/apis/json-rpc/).
val params: List<String>
)
kotlin
public data class RpcResponse (
// The RPC request method
val method: String,
// The response data
val data: String
)