@elhamdev/tracejs
Version:
A modern, privacy-conscious alternative to browser fingerprinting for unique user identification.
83 lines (82 loc) • 2.56 kB
TypeScript
import { BrowserCharacteristics, FingerprintStrength } from "../interfaces/BrowserCharacteristics";
import { BehaviorProfile } from "../types/behavior";
import { BaseFingerprint } from "./BaseFingerprint";
export interface BehaviorOptions {
/**
* Whether to track mouse movements and clicks
* @default true
*/
trackMouse?: boolean;
/**
* Whether to track keyboard activity
* @default true
*/
trackKeyboard?: boolean;
/**
* Whether to track touch interactions
* @default true
*/
trackTouch?: boolean;
/**
* Privacy level for data collection
* - full: Collect all data including key values
* - balanced: Collect data but anonymize sensitive information
* - minimal: Collect only timing data, not content
* @default "balanced"
*/
privacyMode?: "full" | "balanced" | "minimal";
/**
* Milliseconds between data samples
* @default 100
*/
sampleRate?: number;
/**
* How long to collect data before generating a profile (milliseconds)
* @default 10000 (10 seconds)
*/
trainingDuration?: number;
/**
* Callback when the behavior profile is updated
*/
onProfileUpdate?: (profile: BehaviorProfile) => void;
}
export declare class BehaviorFingerprint extends BaseFingerprint {
private options;
private behaviorProfile;
private initialized;
private profileReady;
private mouseData;
private keyData;
private touchData;
private dataCollectionStartTime;
private mouseMoveHandler;
private mouseClickHandler;
private keyDownHandler;
private keyUpHandler;
private touchHandler;
private keysDown;
private cachedProfile;
private profileTimestamp;
private readonly PROFILE_VALIDITY_PERIOD;
constructor(options?: BehaviorOptions);
/**
* Loads previously cached behavior profile from localStorage if available
* and if it's still within the validity period
*/
private loadCachedProfile;
/**
* Saves the current behavior profile to localStorage for future consistency
*/
private saveCachedProfile;
initialize(): void;
cleanup(): void;
private setupMouseTracking;
private setupKeyboardTracking;
private setupTouchTracking;
private calculateMouseMetrics;
private calculateKeyboardMetrics;
private calculateTouchMetrics;
private processCollectedData;
getCharacteristics(): Promise<Partial<BrowserCharacteristics>>;
getStrengthScore(): FingerprintStrength;
}