| Crates.io | authia |
| lib.rs | authia |
| version | 0.3.4 |
| created_at | 2026-01-22 20:19:56.953419+00 |
| updated_at | 2026-01-23 04:49:57.524542+00 |
| description | High-performance JWT verification library for Ed25519 using WebAssembly |
| homepage | https://github.com/Taniyama2024/authia |
| repository | https://github.com/Taniyama2024/authia |
| max_upload_size | |
| id | 2062547 |
| size | 77,470 |
High-performance JWT verification library for Ed25519 using WebAssembly.
Performance varies significantly by runtime environment:
Cloudflare Workers / Edge Runtimes:
| Library | Avg (ms) | p50 (ms) | p95 (ms) |
|---|---|---|---|
| authia (WASM) | 0.20ms | 0.17ms | 0.36ms |
| jose (WebCrypto) | 0.30ms | 0.28ms | 0.50ms |
Node.js (native crypto):
| Library | Avg (ms) |
|---|---|
| jose (native) | 0.01-0.03ms ⚡ |
| authia (WASM) | 0.17-0.20ms |
In Node.js, jose uses native C++ crypto bindings and is significantly faster. authia is optimized for edge runtimes where both libraries use similar APIs.
npm install authia
The library automatically detects the environment (Node.js or Bundler/Workers) and handles WebAssembly loading.
import { verifyAccessToken } from "authia";
try {
// ⚡ RECOMMENDED: Use publicKeyJwkRaw for better performance (v0.2.0+)
const payload = await verifyAccessToken(token, {
publicKeyJwkRaw: process.env.JWT_PUBLIC_KEY, // Raw JWK JSON string
audience: "kapock-app",
issuer: "https://auth.kapock.com",
});
console.log(`User ID: ${payload.sub}, Email: ${payload.email}`);
} catch (error) {
console.error("Token verification failed:", error);
}
Legacy (still supported, but slower):
// Base64-encoded JWK (backward compatible)
const payload = await verifyAccessToken(token, {
publicKeyJwk: btoa(process.env.JWT_PUBLIC_KEY), // Requires base64 encoding
audience: "kapock-app",
issuer: "https://auth.kapock.com",
});
import { verifyRefreshToken } from "authia";
const payload = await verifyRefreshToken(token, {
publicKeyJwkRaw: process.env.JWT_PUBLIC_KEY, // Use raw JWK for better performance
audience: "kapock-app",
issuer: "https://auth.kapock.com",
});
console.log(`JTI: ${payload.jti}`);
publicKeyJwkRaw instead of publicKeyJwk (2-5x faster in high-throughput scenarios)// Worker-level caching example (Cloudflare Workers)
let cachedPublicKey: string | null = null;
export async function verifyToken(token: string, env: Env) {
if (!cachedPublicKey) {
cachedPublicKey = env.JWT_PUBLIC_KEY.trim();
}
return verifyAccessToken(token, {
publicKeyJwkRaw: cachedPublicKey, // Avoid repeated trim() calls
audience: "kapock-app",
issuer: "https://auth.kapock.com",
});
}
Verification is synchronous. The WebAssembly module is loaded and instantiated at startup using the optimized Node.js target.
Verification is also synchronous. The library automatically handles WebAssembly instantiation during module load. The await in examples is supported but not strictly required for the verification itself (it returns the payload directly).
See API Documentation for detailed information.
⚠️ Important Notes for Production Use
Node.js Environments:
jose library uses native C++ crypto bindings and is typically faster in Node.js (0.01-0.03ms)jose instead of authiaCloudflare Workers / Edge Runtimes:
jose also uses WebCrypto APIsemail) may cause verification to failOption<T> typespublicKeyJwkRaw option (recommended)✅ Good fit:
❌ Consider alternatives:
josejosejoseMIT