
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
@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.
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
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.