facezk-core
Version:
ZKP-AI Proof of Humanity: Live Selfie Check with Biometric Template Extraction and Fuzzy Hashing
199 lines • 6.4 kB
TypeScript
/**
* FaceZK Library Types
* ZK-AI Proof of Humanity: Live Selfie Check
*/
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';
/** Liveness detection challenges */
export type LivenessChallenge = 'blink' | 'head-turn' | 'smile' | 'mouth-open';
/** Error types for better error handling */
export interface FaceZKError extends Error {
code: string;
details?: any;
}
/** Biometric template structure */
export interface BiometricTemplate {
/** Unique identifier for the template */
id: string;
/** Face descriptor vector (normalized) */
descriptor: number[];
/** Face mesh keypoints (468 points) */
mesh: number[][];
/** Face bounding box */
box: [number, number, number, number];
/** Confidence score */
confidence: number;
/** Timestamp of creation */
timestamp: number;
}
/** Liveness detection result */
export interface LivenessResult {
/** Overall liveness score (0-1) */
score: number;
/** Is the person alive */
isAlive: boolean;
/** Detected challenges */
challenges: {
[key in LivenessChallenge]: {
detected: boolean;
confidence: number;
};
};
/** Anti-spoofing score */
antiSpoofScore: number;
/** Timestamp */
timestamp: number;
}
/** Humanity verification result */
export interface HumanityResult {
/** Biometric template */
template: BiometricTemplate;
/** Liveness detection result */
liveness: LivenessResult;
/** Non-reversible ID (Sₐ) */
biometricId: string;
/** Humanity Code (Hₐ) */
humanityCode: string;
/** Verification passed */
verified: boolean;
/** Error message if verification failed */
error?: string;
}
/** Configuration for FaceZK library */
export interface FaceZKConfig {
/** TensorFlow.js backend */
backend: Backend;
/** Debug mode */
debug: boolean;
/** Model base path */
modelBasePath: string;
/** System salt for humanity code generation */
systemSalt: string;
/** Minimum confidence for face detection */
minConfidence: number;
/** Minimum liveness score */
minLivenessScore: number;
/** Liveness challenges to perform */
challenges: LivenessChallenge[];
/** Face detection settings */
face: {
/** Enable face detection */
enabled: boolean;
/** Maximum number of faces to detect */
maxFaces: number;
/** Minimum face size in pixels */
minSize: number;
/** Face rotation correction */
rotation: boolean;
};
/** Liveness detection settings */
liveness: {
/** Enable liveness detection */
enabled: boolean;
/** Number of frames to analyze */
frameCount: number;
/** Timeout for challenge completion */
timeout: number;
};
/** Biometric settings */
biometric: {
/** Enable biometric template extraction */
enabled: boolean;
/** Descriptor vector size */
descriptorSize: number;
/** Normalization method */
normalization: 'l2' | 'minmax';
};
}
/** Liveness detection state */
export interface LivenessState {
/** Collected frame analyses */
frames: any[];
/** Current challenge being performed */
currentChallenge?: LivenessChallenge;
/** Challenge start time */
challengeStartTime: number;
/** Challenge completion status */
challenges: {
[key in LivenessChallenge]: {
completed: boolean;
confidence: number;
frames: number;
};
};
}
/** Session state for live verification */
export interface VerificationSession {
/** Session ID */
id: string;
/** Current state */
state: 'initializing' | 'detecting' | 'challenging' | 'verifying' | 'completed' | 'failed';
/** Current challenge */
currentChallenge?: LivenessChallenge;
/** Collected frames */
frames: Tensor4D[];
/** Progress (0-1) */
progress: number;
/** Start time */
startTime: number;
/** Liveness detection state */
livenessState?: LivenessState;
/** Result */
result?: HumanityResult;
}
/** Event types for verification session */
export type VerificationEvent = 'session-start' | 'face-detected' | 'challenge-start' | 'challenge-complete' | 'verification-complete' | 'verification-failed' | 'error';
/** Event listener callback */
export type VerificationEventListener = (event: VerificationEvent, data?: any) => void;
/** Event data types for better type safety */
export interface SessionStartEvent {
sessionId: string;
}
export interface FaceDetectedEvent {
faceMesh: {
points: number[][];
box: [number, number, number, number];
confidence: number;
};
}
export interface ChallengeStartEvent {
challenge: LivenessChallenge;
sessionId: string;
}
export interface ChallengeCompleteEvent {
challenge: LivenessChallenge;
success: boolean;
confidence: number;
}
export interface VerificationCompleteEvent {
result: HumanityResult;
}
export interface VerificationFailedEvent {
result: HumanityResult;
error?: string;
}
export interface ErrorEvent {
error: Error | string;
sessionId?: string;
}
/** Empty result template */
export declare const emptyHumanityResult: () => HumanityResult;
/** Error codes for better error handling */
export declare const ERROR_CODES: {
readonly NOT_INITIALIZED: "NOT_INITIALIZED";
readonly NO_SESSION: "NO_SESSION";
readonly SESSION_ALREADY_ACTIVE: "SESSION_ALREADY_ACTIVE";
readonly SESSION_COMPLETED: "SESSION_COMPLETED";
readonly INVALID_INPUT: "INVALID_INPUT";
readonly NO_FACE_DETECTED: "NO_FACE_DETECTED";
readonly BACKEND_ERROR: "BACKEND_ERROR";
readonly BROWSER_NOT_SUPPORTED: "BROWSER_NOT_SUPPORTED";
readonly TENSORFLOW_ERROR: "TENSORFLOW_ERROR";
};
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
/** Create a typed error */
export declare function createFaceZKError(code: ErrorCode, message: string, details?: any): FaceZKError;
//# sourceMappingURL=index.d.ts.map