Cavos

Authentication

Use Cavos hosted login (Google / Apple / GitHub / Telegram / email code) or bring your own identity.

Authentication exists for one reason: to produce a stable userId (plus optional email) that the Cavos registry keys on for the embedded wallet (embedded wallets, embedded wallet SDK). The login never signs transactions: that is always the device key.

You have two options: bring your own identity, or use Cavos hosted auth.

Option A: Bring your own identity

If you already authenticate users (Clerk, Auth0, Firebase, your own backend), Cavos needs a way to check who the user is. Register your identity provider once, then pass its token with the user.

  1. In Dashboard → App → Environments → Your own sign-in, set the issuer (iss) of your tokens, the keys URL where your provider publishes its signing keys (JWKS), and optionally the audience (aud). Tokens must be signed with RS256 or ES256 and carry exp.
  2. Pass the user and a way to read their current token:
TypeScript
const cavos = await Cavos.connect({
  chains: ["solana"],
  network: "testnet",
  appSalt: "my-app",
  identity: { userId: user.id, email: user.email },
  auth: {
    authenticate: async () => ({ userId: user.id }),
    getAuthToken: () => currentToken, // a fresh JWT from your auth
  },
  appId: process.env.NEXT_PUBLIC_CAVOS_APP_ID,
});

The vault and the wallet registry verify the token's signature, issuer, audience and expiry, and open the wallet only when its sub equals userId.

userId must be the token's sub, stable and unique per user. If it changes, it is a different user with a different (or new) wallet. Whoever controls the registered provider can sign in as any of your users, so register only the provider you run.

The provider is read from the environment your appId names. Use the environment's cav_… id so development and production each use their own.

In React

Pass the same identity to <CavosProvider> and you get the full React surface (wallet status, device approval, passkeys, recovery), driven by your own auth. Cavos login turns off: the modal is not mounted and login() throws.

app/providers.tsx
export function Providers({ children }) {
  const { user, isLoading } = useMyAuth();   // Clerk, Auth0, your own

  return (
    <CavosProvider
      config={config}
      identity={isLoading || !user ? null : { userId: user.id, email: user.email }}
      identityToken={() => getToken()}
    >
      {children}
    </CavosProvider>
  );
}

Pass null while your auth is loading and once the user signs out. The provider follows you: it connects when an identity appears, clears its state when it goes away, and swaps wallets when the user changes.

The identity is never persisted. Your auth is the source of truth on every mount, so a Cavos session cannot outlive the session that authorized it, unlike Cavos hosted auth, which remembers its own logins so a reload can reconnect silently.

Social recovery also works from your own auth on Starknet, Solana, and Stellar (MasterDEK wrap); see Hardware-isolated recovery.

Option B: Cavos hosted auth (CavosAuth)

CavosAuth provides Google, Apple, GitHub, Telegram, and email-code login that resolves to a Cavos Identity you pass straight into connect.

TypeScript
import { CavosAuth } from "@cavos/kit";

const auth = new CavosAuth({
  appId: process.env.NEXT_PUBLIC_CAVOS_APP_ID,
  // backendUrl defaults to the Cavos hosted services
});

Google and Apple

OAuth is multi-step (redirect out, handle the callback), so resolve the identity first, then call connect with it.

TypeScript
// 1. Redirect the user to the provider
const url = await auth.getGoogleOAuthUrl(/* redirectUri? */);
window.location.href = url;             // or auth.getAppleOAuthUrl()

// 2. On your callback route, exchange the result for an identity.
//    The callback carries a short-lived one-time code (`?cavos_auth_code=…`)
//    that is redeemed server-side; identity material never sits in the URL.
const identity = await auth.handleCallback(window.location.search);

// 3. Connect with the resolved identity
const cavos = await Cavos.connect({
  chains: ["solana"],
  network: "testnet",
  appSalt: "my-app",
  identity,
  appId: process.env.NEXT_PUBLIC_CAVOS_APP_ID,
});

Each sign-in URL carries the hash of a one-time secret the SDK keeps in sessionStorage, and handleCallback rejects a response that does not match it. Build the URL right before redirecting, and handle the callback in the same tab and origin that started the login.

GitHub

GitHub sign-in is live and tested in production. It is an optional web provider, not recommended over Google, Apple, or email. The default modal providers stay those three; add 'github' to show the button, or call login('github') / auth.getGitHubOAuthUrl(). React Native does not offer GitHub: like email, the flow has to verify the enclave's attestation, which that build cannot do.

TypeScript
const url = await auth.getGitHubOAuthUrl(/* redirectUri? */);
window.location.href = url;

const identity = await auth.handleCallback(window.location.search);

getGitHubOAuthUrl creates a login key and a PKCE verifier that live in the vault (in the page's IndexedDB when vault: false), so no script on the page can read them. It keeps only the public nonce in sessionStorage, asks the backend for the authorize URL, and refuses it unless it is https://github.com/login/oauth/authorize with this login's code_challenge and S256. The callback never talks to GitHub. It returns a one-time github_grant; handleCallback sends verify_github with {code_verifier} into the attested enclave, encrypted with the login key. The enclave redeems the code, reads api.github.com/user, discards the access token, and signs an ES256 login token:

ClaimValue
isshttps://enclave.cavos.xyz/github
audcavos-github
subhex(SHA-256("cavos-github-subject-v1:" + client_id + ":" + github_id))
azpthe OAuth client_id the code was redeemed with
nonce<app_id>.<BASE64URL(SHA-256(login public key))>

JWKS: https://enclave.cavos.xyz/.well-known/jwks.json. No GitHub scopes are requested.

Bring your own GitHub OAuth app

Leave Dashboard → App → Environments → GitHub sign-in empty to use Cavos's GitHub app. To put your own name and logo on GitHub's consent screen, create a GitHub OAuth app and save its client ID and client secret on that environment. In the GitHub OAuth app, set Authorization callback URL to the value the dashboard shows under GitHub sign-in (copy button). It is the Cavos dashboard's own origin followed by /api/oauth/github/callback. This is GitHub's callback into Cavos; do not add it to your app's Callback URLs below, which list where Cavos returns the user afterwards. Both fields are required together; the secret is encrypted at rest (AES-256-GCM) and never returned. Leave the secret blank on later saves to keep the stored value.

Identity is derived per OAuth client ID. sub is hex(SHA-256("cavos-github-subject-v1:" + client_id + ":" + github_id)) because GitHub reports the same numeric id to every app. Switching an environment's GitHub app, in either direction, gives every GitHub user a new identity and a new, empty wallet. Tying sub to the app the code was actually redeemed with is also what stops a code from one app becoming a login for another.

The built-in modal only shows GitHub when providers includes 'github':

app/provider.tsx
<CavosProvider
  config={{ appId, environment, chains, defaultChain, network, appSalt }}
  modal={{ appName: "My App", providers: ["google", "apple", "email", "github"] }}
>
  {children}
</CavosProvider>

Enclave failure codes: github_rejected (GitHub did not accept the sign-in) and github_unreachable (the enclave could not reach GitHub). The SDK maps github_rejected to GitHub did not accept this sign-in. Try again. The hosted /api/oauth/github/verify route returns github_rejected as is and every other enclave failure, including github_unreachable, as enclave_unavailable. A stale or reused grant is invalid_grant. See Troubleshooting and the 0.5.0 changelog.

Telegram

Telegram sign-in is live and tested in production (@cavos/kit 0.5.2). It is an optional web provider. The default modal providers are unchanged; add 'telegram' to show the button, or call login('telegram') / auth.getTelegramOAuthUrl(). React Native does not offer Telegram: like email and GitHub, the flow has to verify the enclave's attestation, which that build cannot do. It needs the current Cavos backend and recovery enclave release v4, both live.

TypeScript
const url = await auth.getTelegramOAuthUrl(/* redirectUri? */);
window.location.href = url;

const identity = await auth.handleCallback(window.location.search);

getTelegramOAuthUrl creates a login key and a PKCE verifier that live in the vault (in the page's IndexedDB when vault: false) and keeps only the public nonce in sessionStorage. It asks the backend for the authorize URL. It refuses the URL unless it is https://oauth.telegram.org/auth with:

  • this login's code_challenge and code_challenge_method=S256;
  • nonce exactly <app_id>.<BASE64URL(SHA-256(login public key))>;
  • scope exactly openid profile;
  • response_type=code.

The callback never talks to Telegram. It returns a one-time telegram_grant. handleCallback sends verify_telegram with {code_verifier} into the attested enclave through /api/oauth/telegram/verify, encrypted with the login key. The enclave checks that the token's nonce commits to that key. A stolen authorization code is useless without the login key, whether or not Telegram enforces PKCE.

The enclave redeems the code at oauth.telegram.org/token and verifies Telegram's id_token:

  • signature against https://oauth.telegram.org/.well-known/jwks.json, RS256 or ES256 on P-256;
  • iss is https://oauth.telegram.org;
  • aud is the bot id;
  • exp has not passed, and iat is no older than 5 minutes;
  • nonce matches exactly as above;
  • the numeric Telegram user id is in the id claim.

The enclave then signs its own ES256 login token. Telegram's id_token lives about 30 seconds, and its sub differs per bot.

ClaimValue
isshttps://enclave.cavos.xyz/telegram
audcavos-telegram
subhex(SHA-256("cavos-telegram-subject-v1:" + bot_id + ":" + telegram_user_id))
azpthe bot id
nonce<app_id>.<BASE64URL(SHA-256(login public key))>
name, preferred_usernameonly when Telegram sends them

The token has no email and no phone number: the phone scope is never requested. JWKS: https://enclave.cavos.xyz/.well-known/jwks.json.

The identity is Telegram's numeric user id (the id claim), not Telegram's sub. It is per bot, because the bot id is hashed into sub. A Telegram username change does not change the identity.

Bring your own Telegram bot

Leave Dashboard → App → Environments → Telegram sign-in empty to use Cavos's bot. To show your own bot name and avatar on Telegram's consent screen:

  1. Create a bot with @BotFather.
  2. Open the @BotFather mini app, select the bot, and open Login Widget.
  3. Add the callback the dashboard shows to Allowed URLs: the Cavos dashboard origin followed by /api/oauth/telegram/callback, that is https://cavos.xyz/api/oauth/telegram/callback. This is Telegram's callback into Cavos; do not add it to your app's Callback URLs.
  4. Copy the Client ID (the bot id) and the Client Secret.

Save the Bot ID and Client Secret on the environment. The secret is encrypted at rest and never returned. Leave the field empty on later saves to keep the stored value. Changing the Bot ID requires a new secret.

Use the OIDC Client Secret, not the Bot API token from /newbot. The dashboard refuses anything shaped like a bot token (<digits>:<35 chars>), because a bot token controls the bot.

Keep the bot's signing algorithm on RS256 (the default) or ES256. Telegram restricts EdDSA and ES256K bots to the openid scope, so they do not return the user id, and the login fails.

Switching an environment's bot, in either direction, gives every Telegram user a new identity and a new, empty wallet.

The built-in modal only shows Telegram when providers includes 'telegram':

app/provider.tsx
<CavosProvider
  config={{ appId, environment, chains, defaultChain, network, appSalt }}
  modal={{ appName: "My App", providers: ["google", "apple", "email", "telegram"] }}
>
  {children}
</CavosProvider>

Switching Telegram accounts

Telegram has no prompt=login. It remembers the signed-in user in a cookie on oauth.telegram.org for about a year. To sign in with another Telegram account, use a private window, or end the web session in Telegram → Settings → Devices.

Telegram account security

Per Telegram's FAQ, a Telegram account is reachable with an SMS code to its phone number unless Two-Step Verification (a cloud password) is on. Inactive Telegram accounts are deleted after 18 months by default. Recommend that users turn on Two-Step Verification and keep a second recovery method, for example a passkey.

A Telegram user recovers by signing in with Telegram again through the Cavos-hosted flow (login('telegram') / getTelegramOAuthUrl), not with a token from Clerk or Auth0.

Enclave failure codes: telegram_rejected (Telegram refused the code, or its id_token failed a check) and telegram_unreachable (the enclave could not reach oauth.telegram.org). The SDK maps telegram_rejected to Telegram did not accept this sign-in. Try again. The hosted /api/oauth/telegram/verify route returns telegram_rejected as is and every other enclave failure, including telegram_unreachable, as enclave_unavailable. A stale or reused grant is invalid_grant. See Troubleshooting and the 0.5.2 changelog.

Register every callback URL for your app in Dashboard → App → Settings → Callback URLs, one per line, matched exactly: scheme, host, path, no trailing slash, and no wildcards. OAuth rejects a redirect_uri that is not registered, including when the app has none registered at all. This is deliberate: the callback carries a one-time code, and honouring an unregistered URI would hand that code to whoever asked for it. Remember to add tunnel or preview domains while developing, since each one is a distinct origin.

Email code

TypeScript
await auth.sendOtp(email);
const identity = await auth.verifyOtp(email, code);

const cavos = await Cavos.connect({
  chains: ["solana"],
  network: "testnet",
  appSalt: "my-app",
  identity,
  appId: process.env.NEXT_PUBLIC_CAVOS_APP_ID,
});

The code is 9 characters (lowercase letters and digits). The Cavos recovery enclave, running in AWS Nitro, generates it, mails it directly to the user's mail server, and verifies it. The user enters the code in your app, and the SDK sends it to the enclave encrypted to its attested key. The enclave answers with its own signed token (issuer https://enclave.cavos.xyz, keys at https://enclave.cavos.xyz/.well-known/jwks.json), bound to the login key that requested the code, the same binding Google and Apple tokens have. Email users therefore get hardware-isolated recovery like Google, Apple, GitHub, and Telegram users. The user ID of an email login is derived from the address.

  • Lifetime. A code expires after 5 minutes and allows 3 attempts. A new code for the same address can be requested after 60 seconds.
  • Sender. The mail comes from [email protected], shows your app's name as the sender, and has the subject Your {App} sign-in code. Its design is fixed; per-app email templates do not apply to sign-in codes.
  • Supported addresses. Providers whose domain publishes an MTA-STS policy, for example Gmail, Outlook / Hotmail, and Proton Mail (Yahoo publishes one in testing mode). Other domains get This email provider is not supported yet. (error code email_undeliverable).
  • React Native. Email sign-in is not available yet: sendOtp and verifyOtp throw an unsupported error there. GitHub and Telegram are not on the native API either. Use Google or Apple.

CavosAuthModal shows a 9-character code screen and accepts a pasted code with spaces or hyphens. For the errors the code flow can return, see Troubleshooting.

React Native authentication

React Native apps use NativeCavosAuth from @cavos/kit/react-native. It opens Google or Apple in the system browser and returns through the registered redirectUri. Email, GitHub, and Telegram sign-in are not available on React Native yet.

TypeScript
import { Cavos, NativeCavosAuth } from "@cavos/kit/react-native";

const auth = new NativeCavosAuth({
  appId,
  redirectUri: "myapp://auth",
  backendUrl: "https://cavos.xyz",
});

const identity = await auth.login("google");
const wallet = await Cavos.connect({
  chains: ["stellar"],
  network: "testnet",
  appSalt: "my-app",
  appId,
  identity,
});

The native auth layer persists only the public Identity and pending nonce in application-private storage. It never stores device private keys or OAuth tokens. Register every mobile scheme or universal link exactly in the Cavos dashboard; unregistered redirects are rejected by the backend.

How identity becomes an address

When you call connect, the kit looks up the address in the Cavos registry:

(userId, appId, chain, network) → registry lookup → address

If the registry has an entry, that address is returned. If not, this device computes a candidate address and claims it. The registry is insert-only: the first device to register wins. A second device connecting later sees the existing address and enters needs-device-approval instead of creating a duplicate wallet.

The appSalt parameter names the local device-key slot and is the HKDF salt for the account key on every chain, so changing it derives a different address that will not match the registry row. Never change it. The registry key remains (userId, appId, chain, network).

On this page