DarkStrata Credential Check SDK for Rust
A Rust SDK for checking if credentials have been exposed in data breaches using the DarkStrata API with k-anonymity privacy protection.
Features
- Privacy-First: Uses k-anonymity to ensure your credentials are never exposed
- Async/Await: Built on tokio for efficient async operations
- Batch Processing: Check multiple credentials efficiently with optimized API calls
- Automatic Retries: Exponential backoff for transient failures
- Response Caching: Reduces API calls with intelligent caching
- Type-Safe: Comprehensive Rust types with full error handling
- Zero Unsafe Code: 100% safe Rust implementation
Prerequisites
- Get an API key from https://darkstrata.io
- Rust 1.70 or higher
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1.0", = ["rt-multi-thread", "macros"] }
Quick Start
use ;
async
Usage
Check a Single Credential
let result = client.check.await?;
println!;
println!;
println!;
Check a Pre-computed Hash
If you've already computed the SHA-256 hash of the credential (email:password):
use crypto_utils;
// Compute hash yourself
let hash = hash_credential;
// Or use a pre-computed hash
let result = client.check_hash.await?;
Batch Check
Check multiple credentials efficiently:
use Credential;
let credentials = vec!;
let results = client.check_batch.await?;
for in credentials.iter.zip
Check Options
Filter by date or use a custom HMAC key:
use CheckOptions;
// Filter to breaches since a specific date
let options = new
.since_epoch_day; // 2024-01-01
let result = client.check.await?;
// Use a custom HMAC key for deterministic results
let options = new
.client_hmac;
let result = client.check.await?;
Client Configuration
use Duration;
let client = new?;
Error Handling
The SDK provides detailed error types for comprehensive error handling:
use DarkStrataError;
match client.check.await
How It Works
The SDK uses k-anonymity to protect your credentials:
- Your credential is hashed using SHA-256:
SHA256(email:password) - Only the first 5 characters (prefix) are sent to the API
- The API returns all hashes matching that prefix (1-in-1,000,000 anonymity)
- The SDK checks locally if your full hash exists in the returned set
- Timing-safe comparison prevents timing attacks
Your actual credentials or full hashes are never sent to the server.
API Reference
DarkStrataCredentialCheck
The main client for interacting with the DarkStrata API.
| Method | Description |
|---|---|
new(options) |
Create a new client |
check(email, password, options) |
Check a single credential |
check_hash(hash, options) |
Check a pre-computed hash |
check_batch(credentials, options) |
Check multiple credentials |
clear_cache() |
Clear the response cache |
cache_size() |
Get the current cache size |
ClientOptions
| Option | Type | Default | Description |
|---|---|---|---|
api_key |
String |
Required | Your API key |
base_url |
Option<String> |
https://api.darkstrata.io/v1/ |
API base URL |
timeout |
Option<Duration> |
30 seconds | Request timeout |
retries |
Option<u32> |
3 | Number of retry attempts |
enable_caching |
Option<bool> |
true | Enable response caching |
cache_ttl |
Option<Duration> |
1 hour | Cache time-to-live |
CheckOptions
| Option | Type | Description |
|---|---|---|
client_hmac |
Option<String> |
Custom HMAC key (64+ hex chars) |
since |
Option<SinceFilter> |
Filter by breach date |
CheckResult
| Field | Type | Description |
|---|---|---|
found |
bool |
Whether credential was found in a breach |
credential |
CredentialInfo |
Info about the checked credential |
metadata |
CheckMetadata |
Additional metadata about the check |
Examples
Run the examples with:
DARKSTRATA_API_KEY=your-key
DARKSTRATA_API_KEY=your-key
DARKSTRATA_API_KEY=your-key
Testing
# Run unit tests
# Run with all features
Requirements
- Rust 1.70 or later
- tokio runtime
License
Apache License 2.0 - see LICENSE for details.