blursec.credentials
Pre-auth prefix-blinded checks against the Blursec stealer-log database. This is the core surface of the SDK.
Methods
check(email, password, options?) → Promise<CredentialRiskResult>
Layer 1 — email + password pair.
The SDK locally:
- Builds the canonical string
lowercase(email) + ":" + password. - SHA-256 hashes it via
crypto.subtle.digest. - Sends only the first 10 hex chars of the digest to
POST /v1/credentials/check. - Compares the remaining 54 chars against returned
hashSuffixvalues. - Returns a
CredentialRiskResult.
checkToken(sessionToken, options?) → Promise<CredentialRiskResult>
Layer 2 — session cookie / bearer token. Same k-anonymity model, but hashes the token alone.
Use on every authenticated request if you suspect a session might have been hijacked (or routinely, e.g. on sensitive endpoints).
For request-aware token extraction (JWT vs opaque auto-detection, cookie/header fallbacks) preferblursec.sessions.verify(req)— it wrapscheckTokenand returnstokenType+compromised.
checkHash(fullSha256HexDigest, options?) → Promise<CredentialRiskResult>
Low-level escape hatch. Pass a 64-char SHA-256 hex digest you computed yourself (e.g. inside a WebAssembly worker, or when integrating with a non-standard transport). The SDK still only sends the prefix.
CheckOptions
All three methods accept the same options bag:
context — Layer 3 risk scoring
Optional metadata about the request. When provided, Blursec factors device & connection signals into the response severity (e.g. a leaked credential coming from a known-good IP scores lower than one coming from a Tor exit node).
failOpen
When true (default), the SDK swallows timeouts, network errors, and 5xx responses, returning { leaked: false, failedOpen: true }. This guarantees a Blursec outage cannot lock out legitimate users.
When false, the SDK throws — see errors.md.
timeoutMs
Per-call timeout. Defaults to 1500 ms (generous headroom above the typical sub-50 ms response time). Combined with failOpen: true, this ensures the worst-case latency added to your login flow is bounded.
signal
Standard AbortSignal. Composes with the SDK’s internal timeout — whichever fires first wins.
severityActions
Override the default severity → recommendedAction mapping for one call:
dryRun
Observe-only mode. When true, the SDK still queries the API and reports the
real leaked / severity / firstSeen, but coerces recommendedAction to
"allow" so the integration never blocks traffic. The action it would have
taken is surfaced on enforcedAction. Recommended for the first 1–2 weeks of
any rollout.
CredentialRiskResult
Default severity → action mapping
When multiple matches come back for the same prefix, the SDK picks the highest severity, sums
sources, and picks the earliest firstSeen.
The convenience shortcut
blursec.checkCredential(email, password, options?) is an exact alias for blursec.credentials.check(email, password, options?). Use whichever reads better:
Manual hashing
If you want to perform the prefix-blinded lookup yourself (e.g. you have a custom transport):Threat model. A 40-bit prefix is one-way (SHA-256 is preimage-resistant) and cannot be reversed back to the credential. However, a malicious or compromised Blursec backend could in principle log prefixes and correlate them across requests to identify specific credentials in its own database. The SDK’s confidentiality story trusts the Blursec backend not to do this. If your threat model does not allow that trust, run the database on-prem.See examples/k-anonymity.ts for a runnable walkthrough.

