@neabyte/touchid
Version:
Native macOS Touch ID authentication with device identification, TTL caching, and TypeScript support. Features hardware UUID, device serial, and biometric type detection.
108 lines (107 loc) • 3.8 kB
TypeScript
export interface DeviceData {
readonly biometryType: 'TouchID' | 'FaceID' | 'None' | 'Unsupported';
readonly hardwareUUID: string;
readonly deviceSerial: string;
readonly deviceModel: string;
}
export interface TouchIDResult {
readonly success: boolean;
readonly error?: string;
readonly data?: DeviceData;
}
export type TouchIDMethod = 'direct' | 'cached';
export interface TouchIDOptions {
readonly reason?: string;
readonly method?: TouchIDMethod;
readonly ttl?: number;
}
export interface TouchIDInterface {
isAvailable(): Promise<boolean>;
authenticate(options?: TouchIDOptions): Promise<TouchIDResult>;
}
export interface BiometricInfo {
readonly biometricsAvailable: boolean;
readonly biometryType: 'TouchID' | 'FaceID' | 'None' | 'Unsupported';
readonly deviceSerial: string;
readonly deviceModel: string;
readonly systemVersion: string;
readonly hardwareUUID: string;
}
export declare enum TouchIDError {
NOT_AVAILABLE = "Touch ID not available",
NOT_ENROLLED = "No Touch ID enrolled",
LOCKOUT = "Touch ID is locked out",
USER_CANCEL = "User cancelled authentication",
SYSTEM_CANCEL = "System cancelled authentication",
AUTHENTICATION_FAILED = "Authentication failed",
PASSCODE_NOT_SET = "Passcode not set",
NOT_INTERACTIVE = "Not interactive"
}
export type TouchIDEventType = 'authentication:start' | 'authentication:success' | 'authentication:failure' | 'authentication:cancel' | 'device:lockout' | 'device:available' | 'device:unavailable' | 'cache:created' | 'cache:used' | 'cache:expired' | 'initialization:start' | 'initialization:complete' | 'initialization:error';
export interface TouchIDEventData {
'authentication:start': {
readonly timestamp: number;
readonly method: TouchIDMethod;
readonly reason?: string;
};
'authentication:success': {
readonly timestamp: number;
readonly method: TouchIDMethod;
readonly duration: number;
readonly data?: DeviceData;
};
'authentication:failure': {
readonly timestamp: number;
readonly method: TouchIDMethod;
readonly error: string;
readonly duration: number;
};
'authentication:cancel': {
readonly timestamp: number;
readonly method: TouchIDMethod;
readonly duration: number;
};
'device:lockout': {
readonly timestamp: number;
readonly duration: number;
readonly reason: string;
};
'device:available': {
readonly timestamp: number;
readonly biometryType: string;
};
'device:unavailable': {
readonly timestamp: number;
readonly reason: string;
};
'cache:created': {
readonly timestamp: number;
readonly ttl: number;
};
'cache:used': {
readonly timestamp: number;
readonly remainingTtl: number;
};
'cache:expired': {
readonly timestamp: number;
readonly originalTtl: number;
};
'initialization:start': {
readonly timestamp: number;
};
'initialization:complete': {
readonly timestamp: number;
readonly duration: number;
};
'initialization:error': {
readonly timestamp: number;
readonly error: string;
};
}
export type TouchIDEventHandler<T extends TouchIDEventType = TouchIDEventType> = (event: TouchIDEventData[T]) => void;
export interface TouchIDEventEmitter {
on<T extends TouchIDEventType>(event: T, handler: TouchIDEventHandler<T>): void;
off<T extends TouchIDEventType>(event: T, handler: TouchIDEventHandler<T>): void;
once<T extends TouchIDEventType>(event: T, handler: TouchIDEventHandler<T>): void;
removeAllListeners(event?: TouchIDEventType): void;
}