GhostTrackingService
Provides timing randomization and fee normalization to defeat transaction pattern analysis.
Import
import { GhostTrackingService } from '@knight-shield/core';
Constructor
const tracking = new GhostTrackingService();
Methods
enable(config): void
Enables tracking protection with the given configuration.
tracking.enable({
timing: {
minDelayMs: 500,
maxDelayMs: 8000,
},
feeNormalization: {
flatFee: 1_000_000n,
poolContractAddress: '0xFeePool...',
},
});
disable(): void
Disables all tracking protection.
tracking.disable();
isEnabled(): boolean
Returns whether tracking protection is currently active.
applyTimingDelay(): Promise<number>
Applies a random delay within the configured range. Returns the actual delay in milliseconds.
const ms = await tracking.applyTimingDelay();
// Waited between 500ms and 8000ms
Does nothing if tracking is disabled.
normalizeFee(actualFee): bigint
Returns the flat fee regardless of the actual fee amount.
const displayFee = tracking.normalizeFee(actualFee);
// Always returns the configured flatFee
getFlatFee(): bigint
Returns the configured flat fee amount.
const fee = tracking.getFlatFee();
// e.g., 1_000_000n
Configuration Types
interface TimingConfig {
minDelayMs: number; // Minimum delay (default: 500)
maxDelayMs: number; // Maximum delay (default: 8000)
}
interface FeeNormalizationConfig {
flatFee: bigint; // Flat fee amount
poolContractAddress: string; // FeePool contract address
}