Expand description
Core types for an on-device face liveness and verification engine.
This crate is intentionally UI-agnostic and Flutter-agnostic. It is meant to be embedded from Flutter (via FFI / WASM), Tauri, native Rust apps, Cloud Run servers, or any host that can call Rust.
§Module map
challenge— six-step liveness challenge generation (face centered, smile, head turns, fingers, touch face).pose— per-frame validation: yaw/pitch, framing, smile score, finger count, hand-to-face distance.session— temporal state machine: accumulates valid frames until a stable capture is ready.verify— final verification across the six captured photos: same person, distinct poses, no duplicates, and NSFW gate.engine— ONNX inference pipeline wired to the [tract] runtime when theruntime-tractCargo feature is enabled.json_bridge—&str-in /String-out wrappers around every public entry point, suitable for FFI bridges that cannot pass Rust types.types— shared value types (ImageInput,FrameAnalysis,VerificationThresholds, …).
§Cargo features
runtime-tract(default off) — enables the in-process ONNX runtime built ontract-onnxplus theimagecrate for JPEG/PNG decoding.server— enables the genericface_verification_serverbinary (axum + tokio HTTP wrappers around this crate). Impliesruntime-tract.
Without any feature the crate exposes only the deterministic logic
(challenge, pose, session, verify, json bridge) and trusts the host
to fill FrameAnalysis from another vision pipeline.
Structs§
- Bounding
Box - Captured
Photo Analysis - One of the six photos captured at the end of a liveness challenge.
- Face
Analysis - Vision result for a single face inside one frame.
- Face
Verification Engine - Headless verification engine.
- Frame
Analysis - Hand
Analysis - Image
Input - Encoded image bytes plus the dimensions the host already knows.
- Landmarks
- Liveness
Challenge - A complete liveness challenge.
- Model
Asset - One model file plus the metadata needed to wire it into a pipeline.
- Model
Bundle - A complete, swappable model set.
- Model
Validation - Summary returned by
ModelBundle::validate. - Nsfw
Scores - Raw NSFW classifier probabilities (range
0..=1). - Point
- Pose
Check - Result of validating one frame or one captured photo against a step.
- Session
Tick Json Result - Verification
Anchor Sample - Verification
Anchors - Verification
Checks - Per-check booleans returned alongside
VerificationResult. - Verification
Result - Verification
Session - In-memory state for a single liveness-capture flow.
- Verification
Thresholds - Runtime knobs used by the liveness pipeline.
Enums§
- Challenge
Step - One step in a liveness challenge.
- Face
Verification Error - Public error type for the core.
- Model
Format - Serialized model format accepted by the Rust runtime.
- Model
Role - Role a model plays in the full image-analysis pipeline.
- Session
Decision - What the session wants the host to do next.
- Touch
Target - Facial target used by hand-to-face liveness checks.
Constants§
- EXPECTED_
PHOTO_ COUNT - Number of photos captured during a full liveness challenge — one per step.
- FRAMES_
OK_ TO_ CAPTURE - Consecutive valid frames required before a capture is auto-triggered.
- TICK_MS
- Recommended cadence for calling
VerificationSession::tickfrom the host.
Traits§
- Analyzer
- Strategy trait for anything that can turn raw image bytes into a
FrameAnalysis. Implemented bycrate::FaceVerificationEnginewhen theruntime-tractfeature is active; hosts can also implement it on their own pipeline (e.g. a platform-native CoreML / NNAPI backend).
Functions§
- analyze_
captured_ image_ json - analyze_
image_ json - analyze_
liveness_ image_ json - build_
bundle_ with_ bytes - Build a
ModelBundleby merging JSON metadata with the raw model bytes. - compute_
yaw - Approximate yaw angle from 68-point face landmarks.
- face_
distance - Euclidean (L2) distance between two embeddings.
- generate_
challenge_ json - new_
session_ json - tick_
session_ json - validate_
model_ bundle_ json - validate_
model_ bundle_ with_ bytes - Split-bytes variant of
validate_model_bundle_json. - validate_
pose - Decide whether the current
framesatisfiesstep. - validate_
pose_ json - verify_
captured_ photos - Apply the full verification pipeline (see module-level docs) to the six captured photos and return the user-facing decision. Pure function: it never touches the network or the model bundle.
- verify_
captured_ photos_ json - verify_
images_ json
Type Aliases§
- Embedding
- L2-normalised face embedding produced by the recognition model.