File size: 4,783 Bytes
004f460 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | import { apiRequest } from './client'
// ---- Capability / model status (GET /biometrics/status) ----
export type ModalityState = 'available' | 'demo_untrained' | 'unavailable'
export interface ModalityInfo {
available: boolean
trained?: boolean
experimental?: boolean
state: ModalityState
}
export interface BiometricStatus {
device: string
modalities: Record<string, ModalityInfo>
}
export function getBiometricStatus(): Promise<BiometricStatus> {
return apiRequest<BiometricStatus>('/biometrics/status')
}
// ---- Demo samples (bundled face/fingerprint/voice, base64) ----
export interface DemoSamples {
face_image?: string
fingerprint_image?: string
voice_audio?: string
}
export async function getDemoSamples(userId: string): Promise<DemoSamples> {
const r = await apiRequest<{ samples?: DemoSamples }>('/demo/seed', { body: { user_id: userId } })
return r.samples ?? {}
}
// ---- Enrolment ----
export interface UnifiedEnrollInput {
userId: string
faceImage?: string
fingerprintImage?: string
voiceAudio?: string
}
export interface UnifiedEnrollResult {
success: boolean
modalities?: string[]
reason?: string | null
token?: string
}
export function unifiedEnroll(i: UnifiedEnrollInput): Promise<UnifiedEnrollResult> {
const body: Record<string, string> = { user_id: i.userId }
if (i.faceImage) body.face_image = i.faceImage
if (i.fingerprintImage) body.fingerprint_image = i.fingerprintImage
if (i.voiceAudio) body.voice_audio = i.voiceAudio
return apiRequest<UnifiedEnrollResult>('/unified/enroll', { body })
}
// ---- Verification ----
export interface UnifiedAuthResult {
success: boolean
similarity: number
threshold: number
confidence?: number
modalities?: string[]
per_modality?: Record<string, number>
quality_weights?: Record<string, number>
deepfake_score?: number | null
is_deepfake?: boolean
reason?: string | null
}
export function unifiedAuthenticate(i: UnifiedEnrollInput): Promise<UnifiedAuthResult> {
const body: Record<string, string> = { user_id: i.userId }
if (i.faceImage) body.face_image = i.faceImage
if (i.fingerprintImage) body.fingerprint_image = i.fingerprintImage
if (i.voiceAudio) body.voice_audio = i.voiceAudio
return apiRequest<UnifiedAuthResult>('/unified/authenticate', { body })
}
export interface AuthResult {
success: boolean
similarity: number
threshold: number
face_liveness?: number
fp_liveness?: number
confidence?: number
face_quality?: number
fp_quality?: number
deepfake_score?: number | null
is_deepfake?: boolean
reason?: string | null
}
export function authenticate(userId: string, faceImage: string, fingerprintImage: string): Promise<AuthResult> {
return apiRequest<AuthResult>('/authenticate', {
body: { user_id: userId, face_image: faceImage, fingerprint_image: fingerprintImage },
})
}
export interface VerifyResult {
fused_similarity: number
face_similarity: number
fingerprint_similarity: number
}
export function verify1to1(face1: string, fp1: string, face2: string, fp2: string): Promise<VerifyResult> {
return apiRequest<VerifyResult>('/verify', { body: { face1, fp1, face2, fp2 } })
}
// ---- Voice (backend field is `audio`) ----
export function voiceEnroll(userId: string, audio: string): Promise<{ success: boolean }> {
return apiRequest('/voice/enroll', { body: { user_id: userId, audio } })
}
export function voiceVerify(userId: string, audio: string): Promise<{ success: boolean; similarity: number; threshold: number }> {
return apiRequest('/voice/verify', { body: { user_id: userId, audio } })
}
// ---- Liveness ----
export interface LivenessChallenge { session_id: string; challenges: string[] }
export function livenessChallenge(userId: string, n = 3): Promise<LivenessChallenge> {
return apiRequest<LivenessChallenge>('/liveness/challenge', { body: { user_id: userId, n } })
}
export function livenessVerify(sessionId: string, completed: string[], faceImage?: string): Promise<{ success: boolean; reason?: string | null }> {
const body: Record<string, unknown> = { session_id: sessionId, completed }
if (faceImage) body.face_image = faceImage
return apiRequest('/liveness/verify', { body })
}
// ---- Flash liveness (colour reflection) ----
export interface FlashChallenge { session_id: string; sequence: string[]; expires?: number }
export function flashChallenge(userId: string, n = 4): Promise<FlashChallenge> {
return apiRequest<FlashChallenge>('/pad/challenge', { body: { user_id: userId, n } })
}
export function flashVerify(sessionId: string, baseline: number[], measurements: number[][]): Promise<{ success: boolean; score?: number; reason?: string | null }> {
return apiRequest('/pad/verify', { body: { session_id: sessionId, baseline, measurements } })
}
|