DecaneDocs
APIDecaneClient
API

DecaneClient

The main entry point. Construct once per project and reuse — the JWKS cache (or the imported static key) lives on the instance. A createDecaneClient(options) factory is also exported and does exactly the same thing.

ts
import { DecaneClient, createDecaneClient } from "decane-node";

const decane = new DecaneClient({
  appId: "proj_…",             // optional — enforce project_id
  verificationKey: "-----BEGIN PUBLIC KEY-----…", // optional — offline mode
  apiKey: "dck_live_…",         // optional — needed only for sign-in methods
  apiBase: "https://backend.decane.app",          // optional — the default
  jwksUrl: undefined,           // optional — full JWKS URL override
  fetch: undefined,             // optional — injected fetch (Node < 18, tests)
});

All options are optional; see Configuration for the env-var fallbacks and defaults of each.

verifyAccessToken(token)

ts
const claims = await decane.verifyAccessToken(token);
// → DecaneClaims:
claims.userId;    // stable Decane user id (uid) — key your records off this
claims.subject;   // hashed subject (HMAC of the auth-provider identity)
claims.projectId; // project the token was issued for
claims.tokenId;   // unique per issued token (jti)
claims.issuedAt;  // seconds since epoch
claims.expiresAt; // seconds since epoch
claims.raw;       // full verified JWT payload

Verifies the signature and expiry, checks project_id against appId when configured, and requires a uid claim. Resolves to normalised DecaneClaims, or throws DecaneAuthError if the token cannot be trusted.

safeVerifyAccessToken(token)

ts
const claims = await decane.safeVerifyAccessToken(token); // DecaneClaims | null
if (!claims) return res.status(401).json({ error: "unauthorized" });

Identical to verifyAccessToken but returns null instead of throwing when the token is untrusted. Only DecaneAuthError is swallowed — anything else (a network failure fetching the JWKS, say) still throws.

getAddresses(token)

ts
const { evm, solana, tron } = await decane.getAddresses(token);
// evm:    "0x…"  | null
// solana: "BxY…" | null
// tron:   "T…"   | null

Fetches the token owner’s public wallet addresses from the Decane backend (GET /share/addresses with the token as bearer). Either address may be null. Throws DecaneAuthError if the backend rejects the token. The response never contains key material — addresses only.

getUser(token)

ts
const user = await decane.getUser(token);
user.id;             // uid
user.addresses.evm;  // "0x…" | null
user.addresses.solana;
user.addresses.tron;
user.linkedAccounts; // Privy-compatible:
// [{ type: "wallet", chainType: "ethereum", address: "0x…" },
//  { type: "wallet", chainType: "solana",   address: "BxY…" },
//  { type: "wallet", chainType: "tron",     address: "T…" }]

Verifies the token, then resolves the full user: id plus wallet addresses, also exposed as linkedAccounts in a Privy-compatible shape. Addresses are best-effort — if the address fetch fails, they come back null rather than failing the whole call, since the identity is already verified.

Standalone verifyAccessToken

A function-form export, the drop-in for @privy-io/node’s verifyAccessToken. It caches a client per unique config internally, so it is cheap to call per request — the JWKS is not refetched each time.

ts
import { verifyAccessToken } from "decane-node";

const claims = await verifyAccessToken({
  token,
  appId: process.env.DECANE_APP_ID,
  verificationKey: process.env.DECANE_VERIFICATION_KEY, // optional
});