@idmission/websdk-core 0.2.0-rc.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -1
- package/dist/attestation/clientAttestation.d.ts +5 -0
- package/dist/attestation/clientAttestation.d.ts.map +1 -1
- package/dist/attestation/clientAttestation.js +4 -4
- package/dist/attestation/collectClientAttestation.d.ts +3 -1
- package/dist/attestation/collectClientAttestation.d.ts.map +1 -1
- package/dist/attestation/collectClientAttestation.js +4 -3
- package/dist/camera/acquireCamera.d.ts +5 -0
- package/dist/camera/acquireCamera.d.ts.map +1 -1
- package/dist/camera/acquireCamera.js +25 -5
- package/dist/captureProgress/actor.d.ts +30 -0
- package/dist/captureProgress/actor.d.ts.map +1 -0
- package/dist/captureProgress/actor.js +754 -0
- package/dist/captureProgress/encoder.d.ts +7 -0
- package/dist/captureProgress/encoder.d.ts.map +1 -0
- package/dist/captureProgress/encoder.js +195 -0
- package/dist/captureProgress/index.d.ts +4 -0
- package/dist/captureProgress/index.d.ts.map +1 -0
- package/dist/captureProgress/index.js +45 -0
- package/dist/captureProgress/internal.d.ts +3 -0
- package/dist/captureProgress/internal.d.ts.map +1 -0
- package/dist/captureProgress/internal.js +1 -0
- package/dist/captureProgress/protocol.d.ts +224 -0
- package/dist/captureProgress/protocol.d.ts.map +1 -0
- package/dist/captureProgress/protocol.js +106 -0
- package/dist/captureProgress/recorder.d.ts +32 -0
- package/dist/captureProgress/recorder.d.ts.map +1 -0
- package/dist/captureProgress/recorder.js +554 -0
- package/dist/captureProgress/transport.d.ts +33 -0
- package/dist/captureProgress/transport.d.ts.map +1 -0
- package/dist/captureProgress/transport.js +109 -0
- package/dist/captureProgress/types.d.ts +35 -0
- package/dist/captureProgress/types.d.ts.map +1 -0
- package/dist/captureProgress/types.js +27 -0
- package/dist/client/IdmissionClient.d.ts +8 -1
- package/dist/client/IdmissionClient.d.ts.map +1 -1
- package/dist/client/IdmissionClient.js +96 -27
- package/dist/client/approval.d.ts +15 -0
- package/dist/client/approval.d.ts.map +1 -0
- package/dist/client/approval.js +19 -0
- package/dist/client/artifacts.d.ts +2 -0
- package/dist/client/artifacts.d.ts.map +1 -1
- package/dist/client/documentFileMetadata.d.ts +13 -0
- package/dist/client/documentFileMetadata.d.ts.map +1 -0
- package/dist/client/documentFileMetadata.js +51 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -0
- package/dist/client/payload.d.ts +3 -0
- package/dist/client/payload.d.ts.map +1 -1
- package/dist/client/payload.js +3 -1
- package/dist/client/submissionMetadata.d.ts +4 -1
- package/dist/client/submissionMetadata.d.ts.map +1 -1
- package/dist/client/submissionMetadata.js +13 -8
- package/dist/client/types.d.ts +8 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/validateSession.d.ts +2 -0
- package/dist/client/validateSession.d.ts.map +1 -1
- package/dist/client/validateSession.js +53 -24
- package/dist/documentCapture/autoCaptureEngine.d.ts +106 -0
- package/dist/documentCapture/autoCaptureEngine.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureEngine.js +475 -0
- package/dist/documentCapture/autoCaptureGeometry.d.ts +514 -0
- package/dist/documentCapture/autoCaptureGeometry.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureGeometry.js +475 -0
- package/dist/documentCapture/autoCaptureGuidance.d.ts +61 -0
- package/dist/documentCapture/autoCaptureGuidance.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureGuidance.js +73 -0
- package/dist/documentCapture/autoCaptureMetadata.d.ts +193 -0
- package/dist/documentCapture/autoCaptureMetadata.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureMetadata.js +200 -0
- package/dist/documentCapture/autoCaptureOptions.d.ts +211 -0
- package/dist/documentCapture/autoCaptureOptions.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureOptions.js +177 -0
- package/dist/documentCapture/autoCaptureShutter.d.ts +162 -0
- package/dist/documentCapture/autoCaptureShutter.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureShutter.js +183 -0
- package/dist/documentCapture/controller.d.ts +38 -1
- package/dist/documentCapture/controller.d.ts.map +1 -1
- package/dist/documentCapture/controller.js +620 -40
- package/dist/documentCapture/index.d.ts +8 -2
- package/dist/documentCapture/index.d.ts.map +1 -1
- package/dist/documentCapture/index.js +6 -0
- package/dist/documentCapture/reducer.d.ts +26 -1
- package/dist/documentCapture/reducer.d.ts.map +1 -1
- package/dist/documentCapture/reducer.js +43 -0
- package/dist/documentCapture/state.d.ts +118 -0
- package/dist/documentCapture/state.d.ts.map +1 -1
- package/dist/documentCapture/state.js +24 -0
- package/dist/idCapture/controller.d.ts +24 -1
- package/dist/idCapture/controller.d.ts.map +1 -1
- package/dist/idCapture/controller.js +111 -13
- package/dist/idCapture/index.d.ts +1 -1
- package/dist/idCapture/index.d.ts.map +1 -1
- package/dist/idCapture/index.js +12 -1
- package/dist/idCapture/pipeline.d.ts +30 -0
- package/dist/idCapture/pipeline.d.ts.map +1 -1
- package/dist/idCapture/pipeline.js +33 -10
- package/dist/idCapture/state.d.ts +1 -3
- package/dist/idCapture/state.d.ts.map +1 -1
- package/dist/idCapture/submit.d.ts.map +1 -1
- package/dist/idCapture/submit.js +35 -1
- package/dist/idCapture/types.d.ts +2 -0
- package/dist/idCapture/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/liveness/challengeGeometry.d.ts +48 -17
- package/dist/liveness/challengeGeometry.d.ts.map +1 -1
- package/dist/liveness/challengeGeometry.js +101 -54
- package/dist/models/DocumentDetection.d.ts +29 -1
- package/dist/models/DocumentDetection.d.ts.map +1 -1
- package/dist/models/DocumentDetection.js +75 -7
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +2 -2
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -1
- package/dist/models/defaults/DocumentDetectorLiteRT.js +27 -2
- package/dist/models/defaults/HandLandmarkLiteRT.d.ts +3 -0
- package/dist/models/defaults/HandLandmarkLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/HandLandmarkLiteRT.js +5 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.d.ts +3 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.js +5 -0
- package/dist/models/defaults/PalmDetectionLiteRT.d.ts +3 -0
- package/dist/models/defaults/PalmDetectionLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/PalmDetectionLiteRT.js +5 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts +3 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.js +19 -0
- package/dist/models/defaults/index.d.ts +13 -1
- package/dist/models/defaults/index.d.ts.map +1 -1
- package/dist/models/defaults/index.js +16 -0
- package/dist/models/preloadModels.d.ts +24 -16
- package/dist/models/preloadModels.d.ts.map +1 -1
- package/dist/models/preloadModels.js +33 -3
- package/dist/models/providers/litert/FaceLandmarker.d.ts +8 -1
- package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -1
- package/dist/models/providers/litert/FaceLandmarker.js +95 -3
- package/dist/models/providers/litert/HandOverFaceDetector.d.ts +27 -0
- package/dist/models/providers/litert/HandOverFaceDetector.d.ts.map +1 -0
- package/dist/models/providers/litert/HandOverFaceDetector.js +162 -0
- package/dist/models/providers/litert/blazeFacePrePost.js +4 -2
- package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -1
- package/dist/models/providers/litert/docDetectPrePost.js +20 -3
- package/dist/models/providers/litert/handLandmarkPrePost.d.ts +20 -0
- package/dist/models/providers/litert/handLandmarkPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/handLandmarkPrePost.js +72 -0
- package/dist/models/providers/litert/handOverFace.d.ts +44 -0
- package/dist/models/providers/litert/handOverFace.d.ts.map +1 -0
- package/dist/models/providers/litert/handOverFace.js +139 -0
- package/dist/models/providers/litert/irisPrePost.d.ts +38 -0
- package/dist/models/providers/litert/irisPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/irisPrePost.js +101 -0
- package/dist/models/providers/litert/palmPrePost.d.ts +55 -0
- package/dist/models/providers/litert/palmPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/palmPrePost.js +151 -0
- package/dist/sdkVersions.d.ts +18 -0
- package/dist/sdkVersions.d.ts.map +1 -0
- package/dist/sdkVersions.js +8 -0
- package/dist/selfieCapture/captureQuality.d.ts +43 -0
- package/dist/selfieCapture/captureQuality.d.ts.map +1 -0
- package/dist/selfieCapture/captureQuality.js +87 -0
- package/dist/selfieCapture/challengeRunner.d.ts +9 -2
- package/dist/selfieCapture/challengeRunner.d.ts.map +1 -1
- package/dist/selfieCapture/challengeRunner.js +2 -5
- package/dist/selfieCapture/controller.d.ts +62 -1
- package/dist/selfieCapture/controller.d.ts.map +1 -1
- package/dist/selfieCapture/controller.js +470 -105
- package/dist/selfieCapture/faceTracking.d.ts +69 -1
- package/dist/selfieCapture/faceTracking.d.ts.map +1 -1
- package/dist/selfieCapture/faceTracking.js +134 -6
- package/dist/selfieCapture/guidance.d.ts +64 -0
- package/dist/selfieCapture/guidance.d.ts.map +1 -1
- package/dist/selfieCapture/guidance.js +74 -0
- package/dist/selfieCapture/index.d.ts +4 -3
- package/dist/selfieCapture/index.d.ts.map +1 -1
- package/dist/selfieCapture/index.js +2 -2
- package/dist/selfieCapture/livenessMachine.d.ts +2 -0
- package/dist/selfieCapture/livenessMachine.d.ts.map +1 -1
- package/dist/selfieCapture/livenessMachine.js +8 -0
- package/dist/selfieCapture/pipeline.d.ts +8 -0
- package/dist/selfieCapture/pipeline.d.ts.map +1 -1
- package/dist/selfieCapture/pipeline.js +2 -2
- package/dist/selfieCapture/reducer.d.ts +7 -0
- package/dist/selfieCapture/reducer.d.ts.map +1 -1
- package/dist/selfieCapture/reducer.js +45 -4
- package/dist/selfieCapture/state.d.ts +6 -0
- package/dist/selfieCapture/state.d.ts.map +1 -1
- package/dist/selfieCapture/state.js +1 -0
- package/dist/signature/frameDecode.d.ts.map +1 -1
- package/dist/signature/frameDecode.js +29 -0
- package/dist/signature/metadata.d.ts +10 -1
- package/dist/signature/metadata.d.ts.map +1 -1
- package/dist/signature/quality.d.ts +14 -6
- package/dist/signature/quality.d.ts.map +1 -1
- package/dist/signature/quality.js +13 -4
- package/dist/signatureCapture/controller.d.ts +2 -1
- package/dist/signatureCapture/controller.d.ts.map +1 -1
- package/dist/signatureCapture/controller.js +118 -23
- package/dist/signatureCapture/pipeline.d.ts +14 -2
- package/dist/signatureCapture/pipeline.d.ts.map +1 -1
- package/dist/signatureCapture/pipeline.js +36 -8
- package/dist/signatureCapture/state.d.ts +15 -0
- package/dist/signatureCapture/state.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/videoIdCapture/controller.d.ts.map +1 -1
- package/dist/videoIdCapture/controller.js +64 -3
- package/package.json +10 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Detection } from './blazeFacePrePost';
|
|
2
|
+
export declare const PALM_INPUT_SIZE = 192;
|
|
3
|
+
export declare const PALM_NUM_ANCHORS = 2016;
|
|
4
|
+
export declare const PALM_WRIST = 0;
|
|
5
|
+
export declare const PALM_MIDDLE_MCP = 2;
|
|
6
|
+
/** Frame-pixel box, the shape of `Face.box`. */
|
|
7
|
+
export type Box = {
|
|
8
|
+
xMin: number;
|
|
9
|
+
yMin: number;
|
|
10
|
+
xMax: number;
|
|
11
|
+
yMax: number;
|
|
12
|
+
};
|
|
13
|
+
export type Rect = {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Where a (cropped) source frame lands inside the 192×192 letterboxed input,
|
|
21
|
+
* and the inverse that maps model-space [0, 1] coordinates back to
|
|
22
|
+
* source-frame [0, 1] coordinates: `frame = a + b * model`.
|
|
23
|
+
*/
|
|
24
|
+
export type PalmInputTransform = {
|
|
25
|
+
crop: Rect;
|
|
26
|
+
draw: Rect;
|
|
27
|
+
ax: number;
|
|
28
|
+
bx: number;
|
|
29
|
+
ay: number;
|
|
30
|
+
by: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Letterbox `crop` (frame pixels, default the whole frame, clamped to it) into
|
|
34
|
+
* the model input. Pure so the coordinate round trip is testable without a
|
|
35
|
+
* canvas.
|
|
36
|
+
*/
|
|
37
|
+
export declare function palmInputTransform(frameWidth: number, frameHeight: number, crop?: Box): PalmInputTransform;
|
|
38
|
+
/**
|
|
39
|
+
* Letterbox the frame (or `crop` of it, in frame pixels) into a 192×192 NHWC
|
|
40
|
+
* float32 buffer in [0, 1].
|
|
41
|
+
*/
|
|
42
|
+
export declare function preprocessPalmInput(source: HTMLVideoElement | HTMLCanvasElement, crop?: Box): {
|
|
43
|
+
data: Float32Array;
|
|
44
|
+
transform: PalmInputTransform;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Decode `Identity` [1, 2016, 18] regressors and `Identity_1` [1, 2016, 1]
|
|
48
|
+
* score logits into palms in source-frame [0, 1] coordinates, after MediaPipe's
|
|
49
|
+
* weighted NMS. Keypoint 0 is the wrist, 2 the middle-finger MCP.
|
|
50
|
+
* `scoreThreshold` defaults to MediaPipe's 0.5, which MediaPipe can afford
|
|
51
|
+
* because its hand-landmark stage rejects false palms; alone, faces seen small
|
|
52
|
+
* in the frame score above it.
|
|
53
|
+
*/
|
|
54
|
+
export declare function decodePalms(regressors: Float32Array, classifiers: Float32Array, transform: PalmInputTransform, scoreThreshold?: number): Detection[];
|
|
55
|
+
//# sourceMappingURL=palmPrePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"palmP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EAAE,YAAY,EACxB,WAAW,EAAE,YAAY,EACzB,SAAS,EAAE,kBAAkB,EAC7B,cAAc,SAAkB,GAC/B,SAAS,EAAE,CAqCb"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// MediaPipe palm detection (`palm_detection_lite` / `_full`) pre/post-processing
|
|
2
|
+
// for direct .tflite inference via @litertjs/core.
|
|
3
|
+
//
|
|
4
|
+
// Same SSD family as BlazeFace (see blazeFacePrePost.ts) with the constants
|
|
5
|
+
// from MediaPipe's palm_detection_cpu.pbtxt: 192×192 input, strides
|
|
6
|
+
// [8, 16, 16, 16] → 2 anchors/cell on 24×24 + 6 anchors/cell on 12×12 = 2016
|
|
7
|
+
// anchors, 18 regressors per anchor (4 box + 7 keypoints × 2).
|
|
8
|
+
//
|
|
9
|
+
// Input range is [0, 1], NOT BlazeFace's [-1, 1]. The .tflite carries no
|
|
10
|
+
// normalization metadata; measured 2026-09-13 against MediaPipe's own hand test
|
|
11
|
+
// images, [0, 1] scores 0.95–0.97 on all seven while [-1, 1] misses four of
|
|
12
|
+
// them outright (fist 0.43, both two-hands shots 0.00).
|
|
13
|
+
import { nonMaxSuppression } from './blazeFacePrePost';
|
|
14
|
+
export const PALM_INPUT_SIZE = 192;
|
|
15
|
+
export const PALM_NUM_ANCHORS = 2016;
|
|
16
|
+
const NUM_KEYPOINTS = 7;
|
|
17
|
+
const REGRESSOR_STRIDE = 4 + NUM_KEYPOINTS * 2;
|
|
18
|
+
const SCORE_THRESHOLD = 0.5;
|
|
19
|
+
const IOU_THRESHOLD = 0.3;
|
|
20
|
+
// The keypoint pair MediaPipe orients its hand ROI by.
|
|
21
|
+
export const PALM_WRIST = 0;
|
|
22
|
+
export const PALM_MIDDLE_MCP = 2;
|
|
23
|
+
let cachedAnchors = null;
|
|
24
|
+
function getAnchors() {
|
|
25
|
+
if (cachedAnchors)
|
|
26
|
+
return cachedAnchors;
|
|
27
|
+
const anchors = new Float32Array(PALM_NUM_ANCHORS * 2);
|
|
28
|
+
let i = 0;
|
|
29
|
+
for (const [stride, perCell] of [
|
|
30
|
+
[8, 2],
|
|
31
|
+
[16, 6],
|
|
32
|
+
]) {
|
|
33
|
+
const grid = PALM_INPUT_SIZE / stride;
|
|
34
|
+
for (let y = 0; y < grid; y++) {
|
|
35
|
+
for (let x = 0; x < grid; x++) {
|
|
36
|
+
for (let n = 0; n < perCell; n++) {
|
|
37
|
+
anchors[i++] = (x + 0.5) / grid;
|
|
38
|
+
anchors[i++] = (y + 0.5) / grid;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
cachedAnchors = anchors;
|
|
44
|
+
return anchors;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Letterbox `crop` (frame pixels, default the whole frame, clamped to it) into
|
|
48
|
+
* the model input. Pure so the coordinate round trip is testable without a
|
|
49
|
+
* canvas.
|
|
50
|
+
*/
|
|
51
|
+
export function palmInputTransform(frameWidth, frameHeight, crop) {
|
|
52
|
+
const x = Math.max(0, crop?.xMin ?? 0);
|
|
53
|
+
const y = Math.max(0, crop?.yMin ?? 0);
|
|
54
|
+
const width = Math.min(frameWidth, crop?.xMax ?? frameWidth) - x;
|
|
55
|
+
const height = Math.min(frameHeight, crop?.yMax ?? frameHeight) - y;
|
|
56
|
+
const scale = Math.min(PALM_INPUT_SIZE / width, PALM_INPUT_SIZE / height);
|
|
57
|
+
const drawW = Math.round(width * scale);
|
|
58
|
+
const drawH = Math.round(height * scale);
|
|
59
|
+
const padX = (PALM_INPUT_SIZE - drawW) / 2;
|
|
60
|
+
const padY = (PALM_INPUT_SIZE - drawH) / 2;
|
|
61
|
+
// model → crop: (m * S - pad) / draw * cropSize; crop → frame: (x + ·) / frame.
|
|
62
|
+
const bx = (PALM_INPUT_SIZE * width) / (drawW * frameWidth);
|
|
63
|
+
const by = (PALM_INPUT_SIZE * height) / (drawH * frameHeight);
|
|
64
|
+
return {
|
|
65
|
+
crop: { x, y, width, height },
|
|
66
|
+
draw: { x: padX, y: padY, width: drawW, height: drawH },
|
|
67
|
+
ax: x / frameWidth - (padX / PALM_INPUT_SIZE) * bx,
|
|
68
|
+
bx,
|
|
69
|
+
ay: y / frameHeight - (padY / PALM_INPUT_SIZE) * by,
|
|
70
|
+
by,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
let preprocessCtx = null;
|
|
74
|
+
function getPreprocessContext() {
|
|
75
|
+
if (!preprocessCtx) {
|
|
76
|
+
const canvas = document.createElement('canvas');
|
|
77
|
+
canvas.width = PALM_INPUT_SIZE;
|
|
78
|
+
canvas.height = PALM_INPUT_SIZE;
|
|
79
|
+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
80
|
+
if (!ctx)
|
|
81
|
+
throw new Error('palmPrePost: 2d context unavailable');
|
|
82
|
+
preprocessCtx = ctx;
|
|
83
|
+
}
|
|
84
|
+
return preprocessCtx;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Letterbox the frame (or `crop` of it, in frame pixels) into a 192×192 NHWC
|
|
88
|
+
* float32 buffer in [0, 1].
|
|
89
|
+
*/
|
|
90
|
+
export function preprocessPalmInput(source, crop) {
|
|
91
|
+
const sw = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
|
|
92
|
+
const sh = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
|
|
93
|
+
const transform = palmInputTransform(sw, sh, crop);
|
|
94
|
+
const { crop: c, draw: d } = transform;
|
|
95
|
+
const ctx = getPreprocessContext();
|
|
96
|
+
ctx.fillStyle = 'black';
|
|
97
|
+
ctx.fillRect(0, 0, PALM_INPUT_SIZE, PALM_INPUT_SIZE);
|
|
98
|
+
ctx.drawImage(source, c.x, c.y, c.width, c.height, d.x, d.y, d.width, d.height);
|
|
99
|
+
const pixels = ctx.getImageData(0, 0, PALM_INPUT_SIZE, PALM_INPUT_SIZE).data;
|
|
100
|
+
const data = new Float32Array(PALM_INPUT_SIZE * PALM_INPUT_SIZE * 3);
|
|
101
|
+
for (let i = 0, j = 0; i < pixels.length; i += 4, j += 3) {
|
|
102
|
+
data[j] = pixels[i] / 255;
|
|
103
|
+
data[j + 1] = pixels[i + 1] / 255;
|
|
104
|
+
data[j + 2] = pixels[i + 2] / 255;
|
|
105
|
+
}
|
|
106
|
+
return { data, transform };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Decode `Identity` [1, 2016, 18] regressors and `Identity_1` [1, 2016, 1]
|
|
110
|
+
* score logits into palms in source-frame [0, 1] coordinates, after MediaPipe's
|
|
111
|
+
* weighted NMS. Keypoint 0 is the wrist, 2 the middle-finger MCP.
|
|
112
|
+
* `scoreThreshold` defaults to MediaPipe's 0.5, which MediaPipe can afford
|
|
113
|
+
* because its hand-landmark stage rejects false palms; alone, faces seen small
|
|
114
|
+
* in the frame score above it.
|
|
115
|
+
*/
|
|
116
|
+
export function decodePalms(regressors, classifiers, transform, scoreThreshold = SCORE_THRESHOLD) {
|
|
117
|
+
const anchors = getAnchors();
|
|
118
|
+
const { ax, bx, ay, by } = transform;
|
|
119
|
+
const S = PALM_INPUT_SIZE;
|
|
120
|
+
const detections = [];
|
|
121
|
+
for (let i = 0; i < PALM_NUM_ANCHORS; i++) {
|
|
122
|
+
// Same score clipping as MediaPipe's TfLiteTensorsToDetectionsCalculator.
|
|
123
|
+
const logit = Math.max(-100, Math.min(100, classifiers[i]));
|
|
124
|
+
const score = 1 / (1 + Math.exp(-logit));
|
|
125
|
+
if (score < scoreThreshold)
|
|
126
|
+
continue;
|
|
127
|
+
const anchorX = anchors[i * 2];
|
|
128
|
+
const anchorY = anchors[i * 2 + 1];
|
|
129
|
+
const r = i * REGRESSOR_STRIDE;
|
|
130
|
+
const xc = anchorX + regressors[r] / S;
|
|
131
|
+
const yc = anchorY + regressors[r + 1] / S;
|
|
132
|
+
const w = regressors[r + 2] / S;
|
|
133
|
+
const h = regressors[r + 3] / S;
|
|
134
|
+
const keypoints = [];
|
|
135
|
+
for (let k = 0; k < NUM_KEYPOINTS; k++) {
|
|
136
|
+
keypoints.push({
|
|
137
|
+
x: ax + bx * (anchorX + regressors[r + 4 + k * 2] / S),
|
|
138
|
+
y: ay + by * (anchorY + regressors[r + 5 + k * 2] / S),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
detections.push({
|
|
142
|
+
xMin: ax + bx * (xc - w / 2),
|
|
143
|
+
yMin: ay + by * (yc - h / 2),
|
|
144
|
+
xMax: ax + bx * (xc + w / 2),
|
|
145
|
+
yMax: ay + by * (yc + h / 2),
|
|
146
|
+
keypoints,
|
|
147
|
+
score,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return nonMaxSuppression(detections, IOU_THRESHOLD);
|
|
151
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versions of the packages layered on top of core, supplied by whoever builds
|
|
3
|
+
* the client (e.g. the 2.x façade passes its own and websdk-ui's version).
|
|
4
|
+
*/
|
|
5
|
+
export type SdkLayerVersions = {
|
|
6
|
+
/** The customer-facing SDK version (the 2.x façade's `webSdkVersion`). */
|
|
7
|
+
sdkVersion?: string;
|
|
8
|
+
sdkUiVersion?: string;
|
|
9
|
+
};
|
|
10
|
+
/** Every version reported on the wire, with core's always present. */
|
|
11
|
+
export type ResolvedSdkVersions = {
|
|
12
|
+
/** The customer-facing version; falls back to core's when core is used directly. */
|
|
13
|
+
sdkVersion: string;
|
|
14
|
+
sdkCoreVersion: string;
|
|
15
|
+
sdkUiVersion?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function resolveSdkVersions(layers?: SdkLayerVersions): ResolvedSdkVersions;
|
|
18
|
+
//# sourceMappingURL=sdkVersions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkVersions.d.ts","sourceRoot":"","sources":["../src/sdkVersions.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG;IAChC,oFAAoF;IACpF,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAgB,kBAAkB,CAChC,MAAM,GAAE,gBAAqB,GAC5B,mBAAmB,CAMrB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LightingSample } from './lighting';
|
|
2
|
+
import type { FaceDetectionPrediction } from './faceTracking';
|
|
3
|
+
export type LightingThresholds = {
|
|
4
|
+
minCaptureBrightnessThreshold: number;
|
|
5
|
+
minCaptureRangeThreshold: number;
|
|
6
|
+
minCaptureVarianceThreshold: number;
|
|
7
|
+
};
|
|
8
|
+
/** Opt-in recovery from persistent lighting failures. Framing gates stay on. */
|
|
9
|
+
export type SelfieCaptureRecoveryOptions = {
|
|
10
|
+
/** Offer manual capture after this much active capture time. Default 15000. */
|
|
11
|
+
manualCaptureAfterMs?: number;
|
|
12
|
+
/** When omitted, contrast thresholds do not change. Brightness never decays. */
|
|
13
|
+
lightingRelaxation?: {
|
|
14
|
+
startAfterMs: number;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
rangeFloor: number;
|
|
17
|
+
varianceFloor: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type SelfieCaptureQualityException = {
|
|
21
|
+
reason: 'manual_override' | 'relaxed_thresholds';
|
|
22
|
+
failedChecks: ('brightness' | 'range' | 'variance' | 'unavailable')[];
|
|
23
|
+
measurements: Pick<LightingSample, 'brightness' | 'range' | 'variance'>;
|
|
24
|
+
originalThresholds: LightingThresholds;
|
|
25
|
+
effectiveThresholds: LightingThresholds;
|
|
26
|
+
elapsedMs: number;
|
|
27
|
+
};
|
|
28
|
+
export type SelfieCaptureRecoveryState = {
|
|
29
|
+
elapsedMs: number;
|
|
30
|
+
manualCaptureAvailable: boolean;
|
|
31
|
+
manualCaptureReady: boolean;
|
|
32
|
+
effectiveThresholds: LightingThresholds;
|
|
33
|
+
};
|
|
34
|
+
export declare function resolveLightingThresholds(thresholds: Partial<LightingThresholds>): LightingThresholds;
|
|
35
|
+
/** Reject invalid policies rather than silently disabling a capture barrier. */
|
|
36
|
+
export declare function validateCaptureRecovery(options: SelfieCaptureRecoveryOptions): void;
|
|
37
|
+
/** Linear, bounded contrast relaxation; a floor above the baseline cannot tighten it. */
|
|
38
|
+
export declare function captureRecoveryState(options: SelfieCaptureRecoveryOptions, original: LightingThresholds, elapsedMs: number): SelfieCaptureRecoveryState;
|
|
39
|
+
/** Manual recovery bypasses lighting only; the subject must still be ready. */
|
|
40
|
+
export declare function faceReadyWithoutLighting(prediction: FaceDetectionPrediction | null): boolean;
|
|
41
|
+
/** Records what the original policy would have rejected on the committed frame. */
|
|
42
|
+
export declare function captureQualityException(reason: SelfieCaptureQualityException['reason'], measurements: SelfieCaptureQualityException['measurements'], originalThresholds: LightingThresholds, recovery: SelfieCaptureRecoveryState): SelfieCaptureQualityException | undefined;
|
|
43
|
+
//# sourceMappingURL=captureQuality.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureQuality.d.ts","sourceRoot":"","sources":["../../src/selfieCapture/captureQuality.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAE7D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,6BAA6B,EAAE,MAAM,CAAA;IACrC,wBAAwB,EAAE,MAAM,CAAA;IAChC,2BAA2B,EAAE,MAAM,CAAA;CACpC,CAAA;AAED,gFAAgF;AAChF,MAAM,MAAM,4BAA4B,GAAG;IACzC,+EAA+E;IAC/E,oBAAoB,CAAC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AAY,EAAE,6BAA6B,CAAC,cAAc,CAAC,EAC3D,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,0BAA0B,GACnC,6BAA6B,GAAG,SAAS,CAsB3C"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { DEFAULT_MIN_CAPTURE_BRIGHTNESS_THRESHOLD, DEFAULT_MIN_CAPTURE_RANGE_THRESHOLD, DEFAULT_MIN_CAPTURE_VARIANCE_THRESHOLD, } from './lighting';
|
|
2
|
+
export function resolveLightingThresholds(thresholds) {
|
|
3
|
+
return {
|
|
4
|
+
minCaptureBrightnessThreshold: thresholds.minCaptureBrightnessThreshold ??
|
|
5
|
+
DEFAULT_MIN_CAPTURE_BRIGHTNESS_THRESHOLD,
|
|
6
|
+
minCaptureRangeThreshold: thresholds.minCaptureRangeThreshold ??
|
|
7
|
+
DEFAULT_MIN_CAPTURE_RANGE_THRESHOLD,
|
|
8
|
+
minCaptureVarianceThreshold: thresholds.minCaptureVarianceThreshold ??
|
|
9
|
+
DEFAULT_MIN_CAPTURE_VARIANCE_THRESHOLD,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** Reject invalid policies rather than silently disabling a capture barrier. */
|
|
13
|
+
export function validateCaptureRecovery(options) {
|
|
14
|
+
const values = [options.manualCaptureAfterMs ?? 15000];
|
|
15
|
+
const relaxation = options.lightingRelaxation;
|
|
16
|
+
if (relaxation) {
|
|
17
|
+
values.push(relaxation.startAfterMs, relaxation.durationMs, relaxation.rangeFloor, relaxation.varianceFloor);
|
|
18
|
+
}
|
|
19
|
+
if (values.some((value) => !Number.isFinite(value) || value < 0)) {
|
|
20
|
+
throw new Error('Capture recovery durations and contrast floors must be finite and nonnegative.');
|
|
21
|
+
}
|
|
22
|
+
if (options.lightingRelaxation?.durationMs === 0) {
|
|
23
|
+
throw new Error('Lighting relaxation duration must be greater than zero.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Linear, bounded contrast relaxation; a floor above the baseline cannot tighten it. */
|
|
27
|
+
export function captureRecoveryState(options, original, elapsedMs) {
|
|
28
|
+
const relaxation = options.lightingRelaxation;
|
|
29
|
+
const progress = relaxation
|
|
30
|
+
? Math.max(0, Math.min(1, (elapsedMs - relaxation.startAfterMs) / relaxation.durationMs))
|
|
31
|
+
: 0;
|
|
32
|
+
const relax = (threshold, floor) => threshold - (threshold - Math.min(threshold, floor)) * progress;
|
|
33
|
+
return {
|
|
34
|
+
elapsedMs,
|
|
35
|
+
manualCaptureAvailable: elapsedMs >= (options.manualCaptureAfterMs ?? 15000),
|
|
36
|
+
manualCaptureReady: false,
|
|
37
|
+
effectiveThresholds: {
|
|
38
|
+
...original,
|
|
39
|
+
minCaptureRangeThreshold: relaxation
|
|
40
|
+
? relax(original.minCaptureRangeThreshold, relaxation.rangeFloor)
|
|
41
|
+
: original.minCaptureRangeThreshold,
|
|
42
|
+
minCaptureVarianceThreshold: relaxation
|
|
43
|
+
? relax(original.minCaptureVarianceThreshold, relaxation.varianceFloor)
|
|
44
|
+
: original.minCaptureVarianceThreshold,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Manual recovery bypasses lighting only; the subject must still be ready. */
|
|
49
|
+
export function faceReadyWithoutLighting(prediction) {
|
|
50
|
+
return Boolean(prediction?.face &&
|
|
51
|
+
!prediction.faceNotDetected &&
|
|
52
|
+
!prediction.faceNotCentered &&
|
|
53
|
+
!prediction.faceLookingAway &&
|
|
54
|
+
!prediction.faceTooClose &&
|
|
55
|
+
!prediction.faceTooFar &&
|
|
56
|
+
prediction.faceIsStable &&
|
|
57
|
+
prediction.noseIsStable &&
|
|
58
|
+
!prediction.eyesClosed &&
|
|
59
|
+
!prediction.eyesCalibrating);
|
|
60
|
+
}
|
|
61
|
+
/** Records what the original policy would have rejected on the committed frame. */
|
|
62
|
+
export function captureQualityException(reason, measurements, originalThresholds, recovery) {
|
|
63
|
+
const failedChecks = [];
|
|
64
|
+
for (const [check, threshold] of [
|
|
65
|
+
['brightness', originalThresholds.minCaptureBrightnessThreshold],
|
|
66
|
+
['range', originalThresholds.minCaptureRangeThreshold],
|
|
67
|
+
['variance', originalThresholds.minCaptureVarianceThreshold],
|
|
68
|
+
]) {
|
|
69
|
+
const value = measurements[check];
|
|
70
|
+
if (value === undefined || !Number.isFinite(value)) {
|
|
71
|
+
if (!failedChecks.includes('unavailable'))
|
|
72
|
+
failedChecks.push('unavailable');
|
|
73
|
+
}
|
|
74
|
+
else if (value < threshold)
|
|
75
|
+
failedChecks.push(check);
|
|
76
|
+
}
|
|
77
|
+
if (failedChecks.length === 0)
|
|
78
|
+
return undefined;
|
|
79
|
+
return {
|
|
80
|
+
reason,
|
|
81
|
+
failedChecks,
|
|
82
|
+
measurements,
|
|
83
|
+
originalThresholds,
|
|
84
|
+
effectiveThresholds: recovery.effectiveThresholds,
|
|
85
|
+
elapsedMs: recovery.elapsedMs,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChallengeKind, DetectorFrame } from '../liveness/challengeGeometry';
|
|
1
|
+
import type { ChallengeKind, DetectorFrame, EarPair } from '../liveness/challengeGeometry';
|
|
2
2
|
import type { ChallengeResult } from '../liveness/challengeSequence';
|
|
3
3
|
/** Post-sequence settle fallback (sdk2 SETTLE_TIMEOUT_MS, :269). */
|
|
4
4
|
export declare const SETTLE_TIMEOUT_MS = 2000;
|
|
@@ -29,10 +29,17 @@ export type ChallengeRunner = {
|
|
|
29
29
|
step(event: ChallengeRunnerEvent): ChallengeRunnerSnapshot;
|
|
30
30
|
snapshot(): ChallengeRunnerSnapshot;
|
|
31
31
|
};
|
|
32
|
-
export declare function createChallengeRunner({ challengeCount, responseWindowMs, rng, }?: {
|
|
32
|
+
export declare function createChallengeRunner({ challengeCount, responseWindowMs, rng, earBaseline, }?: {
|
|
33
33
|
challengeCount?: number;
|
|
34
34
|
responseWindowMs?: number;
|
|
35
35
|
/** Test seam forwarded to generateSequence; production omits it. */
|
|
36
36
|
rng?: () => number;
|
|
37
|
+
/**
|
|
38
|
+
* Reads the per-eye open-eye EAR baseline the blink and settle detectors
|
|
39
|
+
* judge against. The runner never writes it: the controller passes its
|
|
40
|
+
* tracking state's estimate, which the capture loop calibrates before any
|
|
41
|
+
* challenge starts, so a blink-first sequence starts calibrated. Omitted, the detectors use absolute gates.
|
|
42
|
+
*/
|
|
43
|
+
earBaseline?: () => EarPair;
|
|
37
44
|
}): ChallengeRunner;
|
|
38
45
|
//# sourceMappingURL=challengeRunner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"challengeRunner.d.ts","sourceRoot":"","sources":["../../src/selfieCapture/challengeRunner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"challengeRunner.d.ts","sourceRoot":"","sources":["../../src/selfieCapture/challengeRunner.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,OAAO,EACR,MAAM,+BAA+B,CAAA;AAOtC,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,+BAA+B,CAAA;AAEtC,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,OAAO,CAAA;AACrC,eAAO,MAAM,uBAAuB,IAAI,CAAA;AACxC,eAAO,MAAM,0BAA0B,OAAO,CAAA;AAE9C,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,aAAa,GAAG,IAAI,CAAA;IAChC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,OAAO,CAAA;IAClB,MAAM,EAAE,eAAe,GAAG,IAAI,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAElC,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,KAAK,EAAE,oBAAoB,GAAG,uBAAuB,CAAA;IAC1D,QAAQ,IAAI,uBAAuB,CAAA;CACpC,CAAA;AAED,wBAAgB,qBAAqB,CAAC,EACpC,cAAwC,EACxC,gBAA6C,EAC7C,GAAG,EACH,WAAmC,GACpC,GAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;IAClB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,OAAO,CAAA;CACvB,GAAG,eAAe,CA4KvB"}
|
|
@@ -6,14 +6,13 @@
|
|
|
6
6
|
// events; the settle fallback is a deadline checked on every event). The
|
|
7
7
|
// controller (plan 3) arms a coarse safety tick so deadlines fire even if
|
|
8
8
|
// frames stall. All times are caller-provided epoch ms — no wall-clock reads.
|
|
9
|
-
import {
|
|
9
|
+
import { createEventDetector, createSettleDetector, NO_EAR_BASELINE, } from '../liveness/challengeGeometry';
|
|
10
10
|
import { challengeSequenceReducer, generateSequence, initialChallengeState, setLastChallengeResult, } from '../liveness/challengeSequence';
|
|
11
11
|
/** Post-sequence settle fallback (sdk2 SETTLE_TIMEOUT_MS, :269). */
|
|
12
12
|
export const SETTLE_TIMEOUT_MS = 2000;
|
|
13
13
|
export const DEFAULT_CHALLENGE_COUNT = 2;
|
|
14
14
|
export const DEFAULT_RESPONSE_WINDOW_MS = 8000;
|
|
15
|
-
export function createChallengeRunner({ challengeCount = DEFAULT_CHALLENGE_COUNT, responseWindowMs = DEFAULT_RESPONSE_WINDOW_MS, rng, } = {}) {
|
|
16
|
-
const earBaseline = createEarBaseline();
|
|
15
|
+
export function createChallengeRunner({ challengeCount = DEFAULT_CHALLENGE_COUNT, responseWindowMs = DEFAULT_RESPONSE_WINDOW_MS, rng, earBaseline = () => NO_EAR_BASELINE, } = {}) {
|
|
17
16
|
let seqState = initialChallengeState(rng ? generateSequence(challengeCount, rng) : generateSequence(challengeCount));
|
|
18
17
|
let detector = null;
|
|
19
18
|
let settleDetector = null;
|
|
@@ -128,8 +127,6 @@ export function createChallengeRunner({ challengeCount = DEFAULT_CHALLENGE_COUNT
|
|
|
128
127
|
}
|
|
129
128
|
// 'face'
|
|
130
129
|
const { frame, atMs } = event;
|
|
131
|
-
// Baseline fed every frame, single writer (sdk2 :484-486).
|
|
132
|
-
earBaseline.push(frame.mesh ? computeEAR(frame.mesh) : null);
|
|
133
130
|
if (settleDetector) {
|
|
134
131
|
settleDetector.push(frame);
|
|
135
132
|
if (settleDetector.settled) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { acquireCamera, type AcquireCameraOptions } from '../camera/acquireCamera';
|
|
2
2
|
import { createFrameLoop } from '../models/FrameLoop';
|
|
3
|
+
import { type SelfieCaptureQualityException, type SelfieCaptureRecoveryOptions, type SelfieCaptureRecoveryState } from './captureQuality';
|
|
3
4
|
import type { CaptureAttemptMetadata, LivenessCheckResponse } from '../client/types';
|
|
4
5
|
import { type SelfieCaptureFlowState, type SelfieCaptureThresholds } from './state';
|
|
5
6
|
import { type SelfieGuidanceCode } from './guidance';
|
|
7
|
+
import type { HandOverFaceCheck, HandOverFaceDetector } from '../models/providers/litert/HandOverFaceDetector';
|
|
6
8
|
import { createSelfiePipeline, type SelfieDetectorKind } from './pipeline';
|
|
7
9
|
import type { RuntimeName } from '../models/CapabilityProbing';
|
|
8
10
|
import { type LivenessMachineState } from './livenessMachine';
|
|
@@ -40,8 +42,34 @@ export type SelfieLivenessConfig = {
|
|
|
40
42
|
onLivenessChecked?: (response: LivenessCheckResponse) => void;
|
|
41
43
|
rng?: () => number;
|
|
42
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Opt-in hand-over-face check (docs/research/palm-detection-occlusion.md).
|
|
47
|
+
* Before an auto-capture is sent, palm detection
|
|
48
|
+
* looks for a hand covering the face on that exact frame; a covered frame is
|
|
49
|
+
* dropped and the user is asked to remove their hand. Needs detector
|
|
50
|
+
* 'face-landmarker' (its head box is calibrated on the mesh's bbox).
|
|
51
|
+
*
|
|
52
|
+
* Fails open: until its two models (~4 MB, fetched once the face models have
|
|
53
|
+
* loaded) are ready, or after either fails, selfies are sent unchecked.
|
|
54
|
+
* Timed lighting recovery uses the same check. Legacy manual fallback skips it.
|
|
55
|
+
*/
|
|
56
|
+
export type HandOverFaceCheckConfig = {
|
|
57
|
+
enabled?: boolean;
|
|
58
|
+
mode?: 'enforce' | 'observe';
|
|
59
|
+
/** Fraction of the head box a hand may cover before the frame is dropped. Default 0.1. */
|
|
60
|
+
coverageThreshold?: number;
|
|
61
|
+
};
|
|
62
|
+
export type HandOverFaceState = {
|
|
63
|
+
/** 'off' while disabled or detached. 'error' lasts for the rest of the attach. */
|
|
64
|
+
status: 'off' | 'loading' | 'active' | 'error';
|
|
65
|
+
/** The last frame the check ran on; kept across attempts for diagnostics. */
|
|
66
|
+
lastCheck: HandOverFaceCheck | null;
|
|
67
|
+
};
|
|
43
68
|
export type SelfieCaptureControllerConfig = {
|
|
44
69
|
thresholds?: SelfieCaptureThresholds;
|
|
70
|
+
captureRecovery?: SelfieCaptureRecoveryOptions;
|
|
71
|
+
/** Notification after committing a capture that failed the original quality gates. */
|
|
72
|
+
onCaptureQualityException?: (exception: SelfieCaptureQualityException) => void;
|
|
45
73
|
detector?: SelfieDetectorKind;
|
|
46
74
|
runtime?: RuntimeName;
|
|
47
75
|
modelAssetPath?: string;
|
|
@@ -67,6 +95,8 @@ export type SelfieCaptureControllerConfig = {
|
|
|
67
95
|
initialCaptureDelayMs?: number;
|
|
68
96
|
/** Liveness integration (task 4). Absent = the pure capture flow only. */
|
|
69
97
|
liveness?: SelfieLivenessConfig;
|
|
98
|
+
/** Opt-in check for a hand over the face before an auto-capture is sent. */
|
|
99
|
+
handOverFaceCheck?: HandOverFaceCheckConfig;
|
|
70
100
|
io?: {
|
|
71
101
|
now?: () => Date;
|
|
72
102
|
setTimeout?: typeof setTimeout;
|
|
@@ -75,6 +105,7 @@ export type SelfieCaptureControllerConfig = {
|
|
|
75
105
|
createPipeline?: typeof createSelfiePipeline;
|
|
76
106
|
createCanvas?: () => HTMLCanvasElement;
|
|
77
107
|
createFrameLoop?: typeof createFrameLoop;
|
|
108
|
+
loadHandOverFaceDetector?: () => Promise<HandOverFaceDetector>;
|
|
78
109
|
};
|
|
79
110
|
};
|
|
80
111
|
export type SelfieCameraState = {
|
|
@@ -86,6 +117,7 @@ type InternalState = SelfieCaptureFlowState & {
|
|
|
86
117
|
camera: SelfieCameraState;
|
|
87
118
|
capturedAttempt: CaptureAttemptMetadata | null;
|
|
88
119
|
capturedImageUrl: string | null;
|
|
120
|
+
captureRecovery: SelfieCaptureRecoveryState | null;
|
|
89
121
|
liveness: LivenessMachineState | null;
|
|
90
122
|
challenge: ChallengeRunnerSnapshot | null;
|
|
91
123
|
/**
|
|
@@ -97,6 +129,15 @@ type InternalState = SelfieCaptureFlowState & {
|
|
|
97
129
|
* outcome is published here. Cleared by retry() and by attach/detach.
|
|
98
130
|
*/
|
|
99
131
|
livenessTimedOut: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* True while retry() waits for a camera a terminal screen released. The
|
|
134
|
+
* terminal state (phase, liveness verdict) is held until the camera is
|
|
135
|
+
* back, so the view keeps that screen up instead of showing a feed with no
|
|
136
|
+
* stream; a view shows the retry as in progress meanwhile.
|
|
137
|
+
*/
|
|
138
|
+
retryPending: boolean;
|
|
139
|
+
/** The hand-over-face check (config.handOverFaceCheck). */
|
|
140
|
+
handOverFace: HandOverFaceState;
|
|
100
141
|
};
|
|
101
142
|
export type SelfieCaptureControllerState = Omit<InternalState, 'guidance'> & {
|
|
102
143
|
/** Held guidance event (idCapture parity shape): the code the stabilizer is
|
|
@@ -149,17 +190,37 @@ export type SelfieCaptureController = {
|
|
|
149
190
|
* legacy head-presence gate can keep observing the shared camera.
|
|
150
191
|
*/
|
|
151
192
|
startTracking(): void;
|
|
152
|
-
/**
|
|
193
|
+
/** Pauses live predictions while keeping the shared camera and models.
|
|
194
|
+
* Capture start/retry or startTracking() resumes them. */
|
|
153
195
|
stopTracking(): void;
|
|
154
196
|
/** Replaces sdk2's context override -- recreates the frame loop if running. */
|
|
155
197
|
setThrottleMs(ms: number): void;
|
|
198
|
+
/**
|
|
199
|
+
* Hands the camera back while the session stays attached, for screens that
|
|
200
|
+
* cover the feed (the liveness success and lockout screens) so the camera
|
|
201
|
+
* light goes out. Models stay loaded; `retry()` re-acquires the camera
|
|
202
|
+
* before capture resumes, and `detach()` still ends the session.
|
|
203
|
+
*/
|
|
204
|
+
releaseCamera(): void;
|
|
156
205
|
/**
|
|
157
206
|
* From error/completed/processing/failed: re-enters capturing with fresh tracking.
|
|
158
207
|
* Camera-acquisition failures (public phase 'error' via the `error` field) are NOT
|
|
159
208
|
* recoverable via retry() — the recovery path for camera errors is `requestCamera()`
|
|
160
209
|
* (matching idCapture).
|
|
210
|
+
*
|
|
211
|
+
* After `releaseCamera()`, the terminal state holds (with `retryPending`
|
|
212
|
+
* set) until the camera is back. If it can't be re-acquired, the attempt
|
|
213
|
+
* is still reset and the camera error lands in `error`.
|
|
161
214
|
*/
|
|
162
215
|
retry(): void;
|
|
216
|
+
/**
|
|
217
|
+
* The exit button (sdk2's `onExitCallback`, FaceLivenessWizard.tsx:394
|
|
218
|
+
* and SelfieCaptureWizard.tsx:247): abandons the attempt and returns to
|
|
219
|
+
* 'loading', so the instructions overlay is back up and `start()` begins
|
|
220
|
+
* a fresh attempt. Models and camera stay up; a camera a terminal screen
|
|
221
|
+
* released is re-acquired. A no-op before capture has started.
|
|
222
|
+
*/
|
|
223
|
+
exitCapture(): void;
|
|
163
224
|
};
|
|
164
225
|
};
|
|
165
226
|
export declare function createSelfieCaptureController(config?: SelfieCaptureControllerConfig): SelfieCaptureController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/selfieCapture/controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/selfieCapture/controller.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EAE1B,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,eAAe,EAAkB,MAAM,qBAAqB,CAAA;AAErE,OAAO,EAML,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAChC,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAGL,KAAK,sBAAsB,EAE3B,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,iDAAiD,CAAA;AACxD,OAAO,EACL,oBAAoB,EAEpB,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,EAML,KAAK,oBAAoB,EAC1B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAKL,KAAK,uBAAuB,EAC7B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAMpE,eAAO,MAAM,8BAA8B,KAAK,CAAA;AAGhD,eAAO,MA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