> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xkey.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin SDK

> Build embedded wallets on Android with the 0xkey Kotlin SDK: passkey and email OTP sign-in, sessions, wallets, signing, and policy management.

The [0xkey Kotlin SDK](https://github.com/0xkey-io/sdk-kotlin) is a Kotlin / Android SDK for embedded wallets. Current version: **v0.1.1**.

* Android minSdk 28, compileSdk 36; Kotlin coroutines and `StateFlow`
* All modules share one version
* Same wire format, stamps and HPKE parameters as the JS and Swift SDKs, so they can be used side by side on one organization

| Module | Purpose |
| :- | :- |
| `sdk-kotlin` | `ZeroXKeyContext`: configuration, sign-in (passkey, OTP, OAuth), sessions, wallets, signing, import / export. Depends on all modules below. |
| `http` | `ZeroXKeyClient`: every public API endpoint and Auth Proxy route, activity polling, structured errors |
| `types` | Request / response models |
| `stamper` | API key and passkey request stamps |
| `passkey` | Credential Manager passkey registration / assertion |
| `crypto` | P-256, HPKE, export / import / OTP bundles |
| `encoding` | hex, base64url, base58 |

Most apps only need `sdk-kotlin`.

## Install

The SDK is published on JitPack; no credentials are needed.

In `settings.gradle.kts`:

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://jitpack.io")
            content { includeGroup("com.github.0xkey-io.sdk-kotlin") }
        }
    }
}
```

In `app/build.gradle.kts` (the version is the Git tag):

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
dependencies {
    implementation("com.github.0xkey-io.sdk-kotlin:sdk-kotlin:v0.1.1")
}
```

Other modules follow the same pattern, for example `com.github.0xkey-io.sdk-kotlin:crypto:v0.1.1`. The same modules are also on GitHub Packages as `io.0xkey:<module>:0.1.1`, which requires a GitHub token with `read:packages`; use one source per build.

## App setup

* **Passkeys** need Digital Asset Links at `https://<rpId>/.well-known/assetlinks.json` with the `delegate_permission/common.get_login_creds` relation and the SHA-256 fingerprints of every certificate that signs the app (debug, upload key and, with Play App Signing, the Play signing key). Your RP ID must also be enabled for your organization.
* **Email / SMS OTP, OAuth and passkey sign-up** go through the [Auth Proxy](https://docs.0xkey.io/embedded-wallets/features/auth-proxy.md): create an Auth Proxy configuration in the Dashboard and pass its ID as `authProxyConfigId`.

## Configure

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
import io.zeroxkey.core.ZeroXKeyContext
import io.zeroxkey.core.models.AuthConfig
import io.zeroxkey.core.models.ZeroXKeyConfig

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        ZeroXKeyContext.init(
            this,
            ZeroXKeyConfig(
                organizationId = "<parent organization id>",
                authProxyConfigId = "<auth proxy config id>",
                appScheme = "<your app scheme>",
                authConfig = AuthConfig(rpId = "wallet.example.com"),
                onSessionExpired = { session -> /* return to sign-in */ },
            )
        )
    }
}
```

`apiBaseUrl` and `authProxyBaseUrl` default to the 0xkey production hosts.

## Sign in

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
// Passkey: new user (creates a passkey and a sub-organization), then returning user.
ZeroXKeyContext.signUpWithPasskey(activity, passkeyDisplayName = "Alice")
ZeroXKeyContext.loginWithPasskey(activity)

// Email OTP.
val otp = ZeroXKeyContext.initOtp(otpType = OtpType.OTP_TYPE_EMAIL, contact = "alice@example.com")
ZeroXKeyContext.loginOrSignUpWithOtp(
    otpId = otp.otpId,
    otpCode = code,
    otpEncryptionTargetBundle = otp.otpEncryptionTargetBundle,
    contact = "alice@example.com",
    otpType = OtpType.OTP_TYPE_EMAIL,
)
```

> [!NOTE]
>
> **OTP login fallback.** The SDK first tries an attested login. Only if the server reports that attested login is unavailable, and `authProxyConfigId` is set, it falls back to the Auth Proxy `otp_login_v2` route. It never falls back on **HTTP 403** or an `ATTESTED_LOGIN_*` error (either can mean MFA is required); the original error is thrown. Scoped logins never fall back.

## Wallets and signing

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
ZeroXKeyContext.refreshWallets()
val wallets = ZeroXKeyContext.wallets.value       // StateFlow<List<Wallet>?>

val signedTx = ZeroXKeyContext.signTransaction(
    signWith = address,
    unsignedTransaction = unsignedHex,
    type = V1TransactionType.TRANSACTION_TYPE_ETHEREUM,
)
```

Prefer `signTransaction` over `signRawPayload` for transactions: transaction-field policies (`eth.tx.*`, `solana.tx.*`) apply to transaction-signing activities. See [Policy language](https://docs.0xkey.io/policies/language.md#activity-parameters).

To require a passkey for each signature, create a client with a passkey stamper:

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
import io.zeroxkey.stamper.Stamper

val session = ZeroXKeyContext.session.value ?: error("not signed in")
val passkeyClient = ZeroXKeyContext.createZeroXKeyClient(
    cfg = zeroXKeyConfig,                                   // the config passed to init
    stamper = Stamper.fromPasskey(activity, rpId = "wallet.example.com"),
    organizationId = session.organizationId,
)
```

## Policies

`ZeroXKeyClient` exposes the policy endpoints, including deletion:

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
val client = ZeroXKeyContext.client
val orgId = ZeroXKeyContext.session.value!!.organizationId

client.deletePolicy(TDeletePolicyBody(organizationId = orgId, policyId = policyId))
client.deletePolicies(TDeletePoliciesBody(organizationId = orgId, policyIds = listOf(id1, id2)))
```

A missing policy ID returns HTTP 404. See [Policy overview](https://docs.0xkey.io/policies/overview.md#managing-policies).

## Errors

| Error | When |
| :- | :- |
| `ZeroXKeyHttpError.RequestFailed` | The server rejected the request: `httpStatus`, `code` (gRPC), `errorMessage`, `errorInfoReasons` |
| `ZeroXKeyHttpError.ActivityNotCompleted` | The activity did not complete (failed, rejected, consensus or MFA needed) |

An activity that is not `COMPLETED` is always thrown, never returned as success. Branch on `code` / `httpStatus`, not on message text; see [Errors](https://docs.0xkey.io/developer-reference/api-overview/errors.md).

## More

* README and example app: [github.com/0xkey-io/sdk-kotlin](https://github.com/0xkey-io/sdk-kotlin)
* [CHANGELOG](https://github.com/0xkey-io/sdk-kotlin/blob/main/CHANGELOG.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.