Verification modes
Exactly one verification strategy is active per client, chosen at construction time. Both check the ES256 signature and expiry; when appId is set, both also check that the token’s project_id matches (the audience-equivalent — Decane tokens set no iss/aud).
Static verification key
The Privy-style model: verify locally against your project’s ES256 public key (SPKI PEM), copied once from the Decane dashboard’s API Keys page. No network call is ever made for verification — it works offline, in air-gapped environments, and adds no latency.
const decane = new DecaneClient({
appId: process.env.DECANE_APP_ID,
verificationKey: process.env.DECANE_VERIFICATION_KEY,
});Literal \n escapes in the PEM are normalised automatically, so a single-line env value works. If the option is omitted, the SDK falls back to the DECANE_VERIFICATION_KEY env var — a backend can pass only appId in code.
JWKS (default)
When no verification key is present, the client verifies against Decane’s published JWKS at {apiBase}/.well-known/jwks.json. The key set is fetched lazily, cached across calls, and refetched automatically when a token carries an unknown key id — so Decane key rotation needs nothing from you.
const decane = new DecaneClient({
appId: process.env.DECANE_APP_ID,
// jwksUrl: "https://backend.decane.app/.well-known/jwks.json" (the default)
});Which mode should I use? Prefer the static key for production backends: it removes the network dependency from your hot auth path. JWKS is the zero-config option and is what you want if you never touch the dashboard.
Express middleware
import { DecaneClient } from "decane-node";
import type { Request, Response, NextFunction } from "express";
const decane = new DecaneClient({ appId: process.env.DECANE_APP_ID });
export async function requireAuth(req: Request, res: Response, next: NextFunction) {
const token = req.headers.authorization?.replace("Bearer ", "") ?? "";
const claims = await decane.safeVerifyAccessToken(token); // null instead of throwing
if (!claims) return res.status(401).json({ error: "unauthorized" });
(req as any).userId = claims.userId;
next();
}safeVerifyAccessToken is the fail-closed variant: it returns null for any untrusted token instead of throwing, which keeps middleware flat. Unexpected non-auth errors still propagate.
Next.js route handler
import { NextResponse } from "next/server";
import { DecaneClient } from "decane-node";
const decane = new DecaneClient({ appId: process.env.DECANE_APP_ID });
export async function GET(req: Request) {
const token = req.headers.get("authorization")?.replace("Bearer ", "") ?? "";
const claims = await decane.safeVerifyAccessToken(token);
if (!claims) return NextResponse.json({ error: "unauthorized" }, { status: 401 });
const user = await decane.getUser(token); // id + wallet addresses
return NextResponse.json(user);
}Module scope is fine for the client — route handlers share the instance, and with it the cached JWKS, across requests.