facezk-core
Version:
ZKP-AI Proof of Humanity: Live Selfie Check with Biometric Template Extraction and Fuzzy Hashing
264 lines • 7.87 kB
TypeScript
/**
* Core Interfaces for Modular FaceZK Architecture
* ZK-AI Proof of Humanity: Privacy-First Design
*/
import type { Tensor, Tensor4D } from '@tensorflow/tfjs-core';
/** Supported input types for face analysis */
export type Input = HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | ImageData | ImageBitmap | Tensor | Tensor4D;
/** Backend options for TensorFlow.js */
export type Backend = 'webgl' | 'wasm' | 'cpu';
/** Plugin lifecycle states */
export type PluginState = 'initializing' | 'ready' | 'error' | 'disposed';
/** Base plugin interface */
export interface IPlugin {
readonly id: string;
readonly name: string;
readonly version: string;
readonly state: PluginState;
initialize(config: any): Promise<void>;
dispose(): Promise<void>;
isReady(): boolean;
}
/** Face detection plugin interface */
export interface IFaceDetectionPlugin extends IPlugin {
detect(input: Input): Promise<FaceDetectionResult | null>;
extractMesh(input: Input): Promise<FaceMesh | null>;
}
/** Liveness detection plugin interface */
export interface ILivenessDetectionPlugin extends IPlugin {
analyzeFrame(mesh: FaceMesh): Promise<LivenessAnalysis>;
updateState(analysis: LivenessAnalysis): void;
getLivenessScore(): number;
isChallengeComplete(challenge: LivenessChallenge): boolean;
resetState(): void;
}
/** Biometric extraction plugin interface */
export interface IBiometricPlugin extends IPlugin {
extractTemplate(mesh: FaceMesh): Promise<EncryptedBiometricTemplate>;
generateBiometricId(template: EncryptedBiometricTemplate): Promise<string>;
compareTemplates(template1: EncryptedBiometricTemplate, template2: EncryptedBiometricTemplate): Promise<ComparisonResult>;
}
/** Cryptographic plugin interface */
export interface ICryptoPlugin extends IPlugin {
encrypt(data: Uint8Array, key: CryptoKey): Promise<EncryptedData>;
decrypt(data: EncryptedData, key: CryptoKey): Promise<Uint8Array>;
generateKey(): Promise<CryptoKey>;
deriveKey(password: string, salt: Uint8Array): Promise<CryptoKey>;
hash(data: Uint8Array): Promise<string>;
}
/** Memory management plugin interface */
export interface IMemoryPlugin extends IPlugin {
allocate(size: number): Promise<void>;
cleanup(): Promise<void>;
getStats(): MemoryStats;
monitor(): void;
stopMonitoring(): void;
}
/** Audit logging plugin interface */
export interface IAuditPlugin extends IPlugin {
logEvent(event: AuditEvent): Promise<void>;
getAuditTrail(sessionId: string): Promise<AuditEvent[]>;
exportAuditLog(startDate: Date, endDate: Date): Promise<AuditLogExport>;
}
/** Performance monitoring plugin interface */
export interface IPerformancePlugin extends IPlugin {
startTimer(name: string): void;
endTimer(name: string): PerformanceMetric;
getMetrics(): PerformanceMetrics;
resetMetrics(): void;
}
/** Plugin registry interface */
export interface IPluginRegistry {
register(plugin: IPlugin): void;
unregister(pluginId: string): void;
getPlugin<T extends IPlugin>(pluginId: string): T | null;
getPluginsByType<T extends IPlugin>(type: string): T[];
listPlugins(): PluginInfo[];
}
/** Plugin manager interface */
export interface IPluginManager {
readonly registry: IPluginRegistry;
loadPlugin(pluginId: string, config: any): Promise<void>;
unloadPlugin(pluginId: string): Promise<void>;
reloadPlugin(pluginId: string): Promise<void>;
getPluginState(pluginId: string): PluginState;
}
/** Face detection result */
export interface FaceDetectionResult {
confidence: number;
boundingBox: [number, number, number, number];
landmarks: number[][];
mesh: FaceMesh;
timestamp: number;
}
/** Face mesh data */
export interface FaceMesh {
points: number[][];
triangles: number[][];
confidence: number;
timestamp: number;
}
/** Liveness analysis result */
export interface LivenessAnalysis {
timestamp: number;
blinkDetected: boolean;
blinkConfidence: number;
headPose: HeadPose;
facialExpression: FacialExpression;
antiSpoofScore: number;
naturalMovementScore: number;
}
/** Head pose data */
export interface HeadPose {
yaw: number;
pitch: number;
roll: number;
confidence: number;
}
/** Facial expression data */
export interface FacialExpression {
smile: {
detected: boolean;
confidence: number;
};
mouthOpen: {
detected: boolean;
confidence: number;
};
eyebrowRaise: {
detected: boolean;
confidence: number;
};
}
/** Liveness challenge types */
export type LivenessChallenge = 'blink' | 'head-turn' | 'smile' | 'mouth-open' | 'eyebrow-raise';
/** Encrypted biometric template */
export interface EncryptedBiometricTemplate {
id: string;
encryptedData: EncryptedData;
hash: string;
version: string;
timestamp: number;
metadata: TemplateMetadata;
}
/** Encrypted data structure */
export interface EncryptedData {
ciphertext: Uint8Array;
iv: Uint8Array;
salt: Uint8Array;
algorithm: string;
}
/** Template metadata */
export interface TemplateMetadata {
featureCount: number;
extractionMethod: string;
normalizationMethod: string;
qualityScore: number;
}
/** Comparison result */
export interface ComparisonResult {
similarity: number;
match: boolean;
confidence: number;
threshold: number;
}
/** Memory statistics */
export interface MemoryStats {
totalBytes: number;
usedBytes: number;
peakBytes: number;
tensorCount: number;
lastCleanup: Date;
}
/** Audit event */
export interface AuditEvent {
id: string;
sessionId: string;
timestamp: Date;
eventType: AuditEventType;
userId?: string;
data: any;
severity: 'info' | 'warn' | 'error' | 'security';
}
/** Audit event types */
export type AuditEventType = 'session_start' | 'session_end' | 'face_detected' | 'template_extracted' | 'liveness_check' | 'verification_success' | 'verification_failure' | 'security_violation' | 'error';
/** Performance metric */
export interface PerformanceMetric {
name: string;
duration: number;
timestamp: Date;
metadata?: any;
}
/** Performance metrics */
export interface PerformanceMetrics {
timers: {
[key: string]: PerformanceMetric[];
};
averages: {
[key: string]: number;
};
totals: {
[key: string]: number;
};
}
/** Plugin information */
export interface PluginInfo {
id: string;
name: string;
version: string;
type: string;
state: PluginState;
dependencies: string[];
}
/** Audit log export */
export interface AuditLogExport {
events: AuditEvent[];
summary: {
totalEvents: number;
startDate: Date;
endDate: Date;
eventTypes: {
[key: string]: number;
};
};
format: 'json' | 'csv' | 'xml';
}
/** Configuration validation result */
export interface ValidationResult {
valid: boolean;
errors: string[];
warnings: string[];
}
/** Plugin configuration */
export interface PluginConfig {
id: string;
type: string;
config: any;
dependencies?: string[];
enabled: boolean;
}
/** Core configuration */
export interface CoreConfig {
plugins: PluginConfig[];
crypto: {
algorithm: string;
keyDerivation: string;
saltLength: number;
};
performance: {
enableMonitoring: boolean;
enableProfiling: boolean;
cleanupInterval: number;
};
audit: {
enabled: boolean;
retentionDays: number;
logLevel: 'info' | 'warn' | 'error' | 'security';
};
security: {
maxSessionDuration: number;
maxRetryAttempts: number;
rateLimitPerMinute: number;
};
}
//# sourceMappingURL=interfaces.d.ts.map