
Research
/Security News
Fake imToken Chrome Extension Steals Seed Phrases via Phishing Redirects
Mixed-script homoglyphs and a lookalike domain mimic imToken’s import flow to capture mnemonics and private keys.
@darkauth/client
Advanced tools
A TypeScript client library for DarkAuth - providing zero-knowledge authentication and client-side encryption capabilities for web applications.
A TypeScript client library for DarkAuth - providing zero-knowledge authentication and client-side encryption capabilities for web applications.
The client supports both:
npm install @DarkAuth/client
import { setConfig, initiateLogin, handleCallback, getStoredSession } from '@DarkAuth/client';
// Configure the client
setConfig({
issuer: 'https://auth.example.com',
clientId: 'your-client-id',
redirectUri: 'https://app.example.com/callback',
zk: false // Optional: disable ZK request parameters for standard OIDC flows
});
// Start login flow
await initiateLogin();
// Handle OAuth callback (on your callback page)
const session = await handleCallback();
if (session) {
console.log('Logged in!', session.idToken);
}
// Get existing session
const existingSession = getStoredSession();
if (existingSession && isTokenValid(existingSession.idToken)) {
// User is authenticated
}
setConfig(config: Partial<Config>)Configure the DarkAuth client with your authentication settings.
setConfig({
issuer: 'https://auth.example.com', // DarkAuth server URL
clientId: 'your-client-id', // Your application's client ID
redirectUri: 'https://app.example.com/callback', // OAuth callback URL
zk: true // Optional. Default true. Set false for non-ZK flows.
});
The client also supports environment variables for configuration:
DARKAUTH_ISSUER or VITE_DARKAUTH_ISSUERDARKAUTH_CLIENT_ID or VITE_CLIENT_IDVITE_REDIRECT_URIinitiateLogin(): Promise<void>Starts the OAuth2/OIDC login flow with PKCE. Redirects the user to the DarkAuth authorization server.
handleCallback(): Promise<AuthSession | null>Processes the OAuth callback after successful authentication. Returns an AuthSession object containing:
idToken: JWT ID tokendrk: Derived Root Key for encryption operations. In non-ZK flows this is an empty Uint8Array.refreshToken?: Optional refresh tokenBehavior:
logout(): voidClears all authentication data from storage.
getStoredSession(): AuthSession | nullRetrieves the current session from storage if valid. For non-ZK sessions, returns drk as an empty Uint8Array.
refreshSession(): Promise<AuthSession | null>Refreshes the current session using the stored refresh token. For non-ZK sessions, returns drk as an empty Uint8Array.
getCurrentUser(): JwtClaims | nullReturns the parsed JWT claims from the current ID token.
parseJwt(token: string): JwtClaims | nullParses a JWT token and returns its claims.
isTokenValid(token: string): booleanChecks if a JWT token is still valid (not expired).
The library exports comprehensive cryptographic utilities from ./crypto:
bytesToBase64Url(bytes: Uint8Array): stringbase64UrlToBytes(base64url: string): Uint8ArraybytesToBase64(bytes: Uint8Array): stringbase64ToBytes(base64: string): Uint8Arraysha256(bytes: Uint8Array): Promise<Uint8Array>hkdf(key: Uint8Array, salt: Uint8Array, info: Uint8Array, length?: number): Promise<Uint8Array>deriveDek(drk: Uint8Array, noteId: string): Promise<Uint8Array>aeadEncrypt(key: CryptoKey, plaintext: Uint8Array, additionalData: Uint8Array): Promise<{iv: Uint8Array, ciphertext: Uint8Array}>aeadDecrypt(key: CryptoKey, payload: Uint8Array, additionalData: Uint8Array): Promise<Uint8Array>encryptNote(drk: Uint8Array, noteId: string, content: string): Promise<string>decryptNote(drk: Uint8Array, noteId: string, ciphertextBase64: string, aadObject: Record<string, unknown>): Promise<string>wrapPrivateKey(privateKeyJwk: JsonWebKey, drk: Uint8Array): Promise<string>unwrapPrivateKey(wrappedKey: string, drk: Uint8Array): Promise<JsonWebKey>resolveDek(noteId: string, isOwner: boolean, drk: Uint8Array): Promise<Uint8Array>Resolves a data encryption key for a specific resource. If the user is the owner, derives the DEK directly. Otherwise, fetches and decrypts the shared DEK.
clearKeyCache(): voidClears the cached encryption keys.
setHooks(hooks: ClientHooks)Configure hooks for custom data fetching:
setHooks({
fetchNoteDek: async (noteId: string) => {
// Fetch encrypted DEK for a shared note
const response = await fetch(`/api/notes/${noteId}/dek`);
return response.text();
},
fetchWrappedEncPrivateJwk: async () => {
// Fetch user's wrapped private key
const response = await fetch('/api/user/private-key');
return response.text();
}
});
AuthSessioninterface AuthSession {
idToken: string;
drk: Uint8Array;
refreshToken?: string;
}
JwtClaimsinterface JwtClaims {
sub?: string;
email?: string;
name?: string;
exp?: number;
iat?: number;
iss?: string;
}
Configtype Config = {
issuer: string;
clientId: string;
redirectUri: string;
zk?: boolean;
}
ClientHookstype ClientHooks = {
fetchNoteDek?: (noteId: string) => Promise<string>;
fetchWrappedEncPrivateJwk?: () => Promise<string>;
}
This library requires a modern browser with support for:
# Install dependencies
npm install
# Build the package
npm run build
# Type checking
npm run typecheck
# Linting and formatting
npm run lint
npm run format
MIT
Contributions are welcome! Please ensure all code passes linting and type checking before submitting a pull request.
FAQs
A TypeScript client library for DarkAuth - providing zero-knowledge authentication and client-side encryption capabilities for web applications.
The npm package @darkauth/client receives a total of 570 weekly downloads. As such, @darkauth/client popularity was classified as not popular.
We found that @darkauth/client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Mixed-script homoglyphs and a lookalike domain mimic imToken’s import flow to capture mnemonics and private keys.

Security News
Latio’s 2026 report recognizes Socket as a Supply Chain Innovator and highlights our work in 0-day malware detection, SCA, and auto-patching.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.