@jupitermetalabs/face-zk-sdk 0.3.4 → 0.3.7
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 +46 -1
- package/assets/face-guidance/pose-guidance.js.txt +4 -2
- package/assets/liveness/liveness.js.txt +3 -0
- package/dist/FaceZkSdk.d.ts +69 -0
- package/dist/FaceZkSdk.js +136 -0
- package/dist/assets/face-guidance/pose-guidance.js.txt +4 -2
- package/dist/assets/liveness/liveness.js.txt +3 -0
- package/dist/assets/onnx/ort-min.d.ts +1 -0
- package/dist/assets/onnx/ort-min.js +11 -0
- package/dist/config/defaults.d.ts +51 -0
- package/dist/config/defaults.js +61 -0
- package/dist/config/types.d.ts +169 -0
- package/dist/config/types.js +17 -0
- package/dist/core/enrollment-core.d.ts +70 -0
- package/dist/core/enrollment-core.js +206 -0
- package/dist/core/idGenerator.d.ts +11 -0
- package/dist/core/idGenerator.js +32 -0
- package/dist/core/matching.d.ts +69 -0
- package/dist/core/matching.js +101 -0
- package/dist/core/types.d.ts +379 -0
- package/dist/core/types.js +37 -0
- package/dist/core/verification-core.d.ts +120 -0
- package/dist/core/verification-core.js +442 -0
- package/dist/core/zk-core.d.ts +69 -0
- package/dist/core/zk-core.js +244 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +51 -0
- package/dist/react-native/adapters/faceEmbeddingProvider.d.ts +38 -0
- package/dist/react-native/adapters/faceEmbeddingProvider.js +45 -0
- package/dist/react-native/adapters/imageDataProvider.d.ts +53 -0
- package/dist/react-native/adapters/imageDataProvider.js +134 -0
- package/dist/react-native/adapters/livenessProvider.d.ts +133 -0
- package/dist/react-native/adapters/livenessProvider.js +150 -0
- package/dist/react-native/adapters/zkProofEngine-webview.d.ts +73 -0
- package/dist/react-native/adapters/zkProofEngine-webview.js +135 -0
- package/dist/react-native/bundledRuntimeAssets.d.ts +39 -0
- package/dist/react-native/bundledRuntimeAssets.js +44 -0
- package/dist/react-native/components/FacePoseGuidanceWebView.d.ts +30 -0
- package/dist/react-native/components/FacePoseGuidanceWebView.js +530 -0
- package/dist/react-native/components/LivenessWebView.d.ts +39 -0
- package/dist/react-native/components/LivenessWebView.js +386 -0
- package/dist/react-native/components/OnnxRuntimeWebView.d.ts +58 -0
- package/dist/react-native/components/OnnxRuntimeWebView.js +518 -0
- package/dist/react-native/components/ZkProofWebView.d.ts +59 -0
- package/dist/react-native/components/ZkProofWebView.js +297 -0
- package/dist/react-native/dependencies.d.ts +144 -0
- package/dist/react-native/dependencies.js +130 -0
- package/dist/react-native/hooks/useOnnxLoader.d.ts +37 -0
- package/dist/react-native/hooks/useOnnxLoader.js +74 -0
- package/dist/react-native/hooks/useWasmLoader.d.ts +30 -0
- package/dist/react-native/hooks/useWasmLoader.js +158 -0
- package/dist/react-native/index.d.ts +61 -0
- package/dist/react-native/index.js +144 -0
- package/dist/react-native/services/FaceRecognition.d.ts +92 -0
- package/dist/react-native/services/FaceRecognition.js +674 -0
- package/dist/react-native/ui/FaceZkVerificationFlow.d.ts +97 -0
- package/dist/react-native/ui/FaceZkVerificationFlow.js +477 -0
- package/dist/react-native/ui/ReferenceEnrollmentFlow.d.ts +72 -0
- package/dist/react-native/ui/ReferenceEnrollmentFlow.js +369 -0
- package/dist/react-native/utils/faceAlignment.d.ts +37 -0
- package/dist/react-native/utils/faceAlignment.js +186 -0
- package/dist/react-native/utils/modelInitialisationChecks.d.ts +36 -0
- package/dist/react-native/utils/modelInitialisationChecks.js +128 -0
- package/dist/react-native/utils/resolveModelUri.d.ts +55 -0
- package/dist/react-native/utils/resolveModelUri.js +211 -0
- package/dist/react-native/utils/resolveRuntimeAsset.d.ts +25 -0
- package/dist/react-native/utils/resolveRuntimeAsset.js +94 -0
- package/dist/react-native/utils/resolveUiConfig.d.ts +41 -0
- package/dist/react-native/utils/resolveUiConfig.js +81 -0
- package/dist/storage/defaultStorageAdapter.d.ts +44 -0
- package/dist/storage/defaultStorageAdapter.js +344 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/face-zk.config.example.js +10 -3
- package/package.json +2 -2
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 JupiterMeta Labs
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Liveness Provider Adapter for React Native
|
|
18
|
+
*
|
|
19
|
+
* Bridges the WebView-based liveness engine (liveness.js + antispoof ONNX model)
|
|
20
|
+
* to the SDK's LivenessProvider interface consumed by verifyOnly / verifyWithProof.
|
|
21
|
+
*
|
|
22
|
+
* ARCHITECTURE
|
|
23
|
+
* ============
|
|
24
|
+
* Real-time liveness detection runs entirely inside the ZkFaceAuth WebView component:
|
|
25
|
+
* - MediaPipe FaceMesh: depth checks, challenge/response (blink, head turns),
|
|
26
|
+
* perspective ratio check
|
|
27
|
+
* - ONNX anti-spoof model: EMA-smoothed spoof score over the session
|
|
28
|
+
*
|
|
29
|
+
* When the WebView completes it calls onSuccess(imageUri, metadata) where
|
|
30
|
+
* metadata = { spoofScore: number }. The functions below convert that into
|
|
31
|
+
* the LivenessResult / LivenessProvider types expected by the SDK core.
|
|
32
|
+
*
|
|
33
|
+
* USAGE PATTERN (inside FaceZkVerificationFlow or your own flow)
|
|
34
|
+
* ===============================================================
|
|
35
|
+
* const handleLivenessSuccess = (imageUri: string, metadata?: { spoofScore: number }) => {
|
|
36
|
+
* const result = createLivenessResultFromWebView(metadata?.spoofScore ?? 1.0);
|
|
37
|
+
* const provider = createWebViewLivenessProvider(result);
|
|
38
|
+
* runVerification(imageUri, provider);
|
|
39
|
+
* };
|
|
40
|
+
*/
|
|
41
|
+
import type { LivenessProvider } from "../../core/verification-core";
|
|
42
|
+
import type { LivenessResult } from "../../core/types";
|
|
43
|
+
/**
|
|
44
|
+
* Build a LivenessResult from the metadata emitted by the ZkFaceAuth WebView.
|
|
45
|
+
*
|
|
46
|
+
* @param spoofScore EMA anti-spoof score from the ONNX model (0 = definitely real, 1 = spoof)
|
|
47
|
+
* @param threshold Fail if spoofScore >= threshold (default 0.6, matching liveness.js)
|
|
48
|
+
*/
|
|
49
|
+
export declare function createLivenessResultFromWebView(spoofScore: number, threshold?: number): LivenessResult;
|
|
50
|
+
/**
|
|
51
|
+
* Wrap a pre-computed LivenessResult into a LivenessProvider.
|
|
52
|
+
*
|
|
53
|
+
* Use this after the ZkFaceAuth WebView completes so the SDK's verifyOnly /
|
|
54
|
+
* verifyWithProof can record the real ONNX scores in VerificationOutcome.liveness.
|
|
55
|
+
*
|
|
56
|
+
* The imageUri argument is ignored because the check already ran inside the WebView.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createWebViewLivenessProvider(preComputedResult: LivenessResult): LivenessProvider;
|
|
59
|
+
/**
|
|
60
|
+
* Configuration for {@link createLivenessProvider}.
|
|
61
|
+
*
|
|
62
|
+
* **Default path (WebView):** omit `service` and pass `spoofScore` from the
|
|
63
|
+
* ZkFaceAuth WebView's `onSuccess` callback. The SDK built-in anti-spoof model
|
|
64
|
+
* is used and the result is pre-computed before verification runs.
|
|
65
|
+
*
|
|
66
|
+
* **Custom path:** provide `service` to plug in any host-owned liveness
|
|
67
|
+
* implementation (e.g. iOS FaceID, a cloud API, your own ONNX model).
|
|
68
|
+
*/
|
|
69
|
+
export interface LivenessProviderConfig {
|
|
70
|
+
/** EMA spoof score from the ONNX model (0 = real, 1 = spoof). Default: 0. */
|
|
71
|
+
spoofScore?: number;
|
|
72
|
+
/** Threshold above which the frame is considered a spoof. Default: 0.6. */
|
|
73
|
+
threshold?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Your own liveness service. When provided, `spoofScore` and `threshold`
|
|
76
|
+
* are ignored and the service's `checkLiveness` result is used instead.
|
|
77
|
+
*/
|
|
78
|
+
service?: {
|
|
79
|
+
checkLiveness(imageUri: string): Promise<{
|
|
80
|
+
passed: boolean;
|
|
81
|
+
score?: number;
|
|
82
|
+
checks?: Array<{
|
|
83
|
+
id: string;
|
|
84
|
+
passed: boolean;
|
|
85
|
+
score?: number;
|
|
86
|
+
reason?: string;
|
|
87
|
+
}>;
|
|
88
|
+
}>;
|
|
89
|
+
};
|
|
90
|
+
/** Fail if `score < minScore` (only applied when using `service`). */
|
|
91
|
+
minScore?: number;
|
|
92
|
+
/** Require all listed check IDs to pass (only applied when using `service`). */
|
|
93
|
+
requiredChecks?: string[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Unified liveness provider factory.
|
|
97
|
+
*
|
|
98
|
+
* - **No `service`** (default): wraps the ZkFaceAuth WebView's pre-computed
|
|
99
|
+
* anti-spoof result. Pass `spoofScore` from the WebView's `onSuccess` callback.
|
|
100
|
+
* - **With `service`**: delegates every `checkLiveness` call to your own
|
|
101
|
+
* implementation, applying optional `minScore` and `requiredChecks` guards.
|
|
102
|
+
*
|
|
103
|
+
* @example Default (SDK built-in WebView)
|
|
104
|
+
* ```ts
|
|
105
|
+
* const provider = createLivenessProvider({ spoofScore: metadata.spoofScore });
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example Custom host service
|
|
109
|
+
* ```ts
|
|
110
|
+
* const provider = createLivenessProvider({ service: myLivenessService, minScore: 0.8 });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function createLivenessProvider(config?: LivenessProviderConfig): LivenessProvider;
|
|
114
|
+
/**
|
|
115
|
+
* Interface for a ZkFaceAuth-based liveness analysis service.
|
|
116
|
+
* Used with {@link createZkFaceAuthLivenessProvider} for post-capture re-verification.
|
|
117
|
+
*/
|
|
118
|
+
export interface ZkFaceAuthLivenessService {
|
|
119
|
+
analyzeLiveness(imageUri: string): Promise<{
|
|
120
|
+
passed: boolean;
|
|
121
|
+
score: number;
|
|
122
|
+
checks: Array<{
|
|
123
|
+
type: "blink" | "motion" | "pose_variation" | "spoof_texture" | "depth_or_3d";
|
|
124
|
+
passed: boolean;
|
|
125
|
+
confidence: number;
|
|
126
|
+
}>;
|
|
127
|
+
}>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a liveness provider that wraps a ZkFaceAuth-based `analyzeLiveness` service.
|
|
131
|
+
* Useful for post-capture liveness re-verification on an already-captured image.
|
|
132
|
+
*/
|
|
133
|
+
export declare function createZkFaceAuthLivenessProvider(zkFaceAuthService: ZkFaceAuthLivenessService): LivenessProvider;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2026 JupiterMeta Labs
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createLivenessResultFromWebView = createLivenessResultFromWebView;
|
|
19
|
+
exports.createWebViewLivenessProvider = createWebViewLivenessProvider;
|
|
20
|
+
exports.createLivenessProvider = createLivenessProvider;
|
|
21
|
+
exports.createZkFaceAuthLivenessProvider = createZkFaceAuthLivenessProvider;
|
|
22
|
+
// Default threshold must match SPOOF_EMA_FAIL_THRESHOLD in liveness.js (0.60).
|
|
23
|
+
// The WebView expresses "spoof confidence" (lower = more real), whereas the SDK
|
|
24
|
+
// expresses "liveness score" (higher = more real), so we invert: realScore = 1 - spoofScore.
|
|
25
|
+
const DEFAULT_ANTISPOOF_THRESHOLD = 0.6;
|
|
26
|
+
/**
|
|
27
|
+
* Build a LivenessResult from the metadata emitted by the ZkFaceAuth WebView.
|
|
28
|
+
*
|
|
29
|
+
* @param spoofScore EMA anti-spoof score from the ONNX model (0 = definitely real, 1 = spoof)
|
|
30
|
+
* @param threshold Fail if spoofScore >= threshold (default 0.6, matching liveness.js)
|
|
31
|
+
*/
|
|
32
|
+
function createLivenessResultFromWebView(spoofScore, threshold = DEFAULT_ANTISPOOF_THRESHOLD) {
|
|
33
|
+
const realScore = 1 - spoofScore; // invert: SDK convention is higher = more real
|
|
34
|
+
const passed = spoofScore < threshold;
|
|
35
|
+
const checks = [
|
|
36
|
+
{
|
|
37
|
+
id: "spoof_texture",
|
|
38
|
+
passed,
|
|
39
|
+
score: realScore,
|
|
40
|
+
reason: passed
|
|
41
|
+
? `Anti-spoof check passed (score: ${realScore.toFixed(3)})`
|
|
42
|
+
: `Anti-spoof check failed (spoof score: ${spoofScore.toFixed(3)} ≥ threshold ${threshold})`,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
// The WebView only surfaces the final EMA score; individual challenge checks
|
|
46
|
+
// (blink, head-turn, perspective) are gated inside liveness.js — if the image
|
|
47
|
+
// reached onSuccess() those challenges already passed.
|
|
48
|
+
checks.push({
|
|
49
|
+
id: "motion",
|
|
50
|
+
passed: true,
|
|
51
|
+
reason: "Liveness challenges completed (blink / head-turn / perspective)",
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
passed,
|
|
55
|
+
score: realScore,
|
|
56
|
+
checks,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Wrap a pre-computed LivenessResult into a LivenessProvider.
|
|
61
|
+
*
|
|
62
|
+
* Use this after the ZkFaceAuth WebView completes so the SDK's verifyOnly /
|
|
63
|
+
* verifyWithProof can record the real ONNX scores in VerificationOutcome.liveness.
|
|
64
|
+
*
|
|
65
|
+
* The imageUri argument is ignored because the check already ran inside the WebView.
|
|
66
|
+
*/
|
|
67
|
+
function createWebViewLivenessProvider(preComputedResult) {
|
|
68
|
+
return {
|
|
69
|
+
async checkLiveness(_imageUri) {
|
|
70
|
+
return preComputedResult;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Unified liveness provider factory.
|
|
76
|
+
*
|
|
77
|
+
* - **No `service`** (default): wraps the ZkFaceAuth WebView's pre-computed
|
|
78
|
+
* anti-spoof result. Pass `spoofScore` from the WebView's `onSuccess` callback.
|
|
79
|
+
* - **With `service`**: delegates every `checkLiveness` call to your own
|
|
80
|
+
* implementation, applying optional `minScore` and `requiredChecks` guards.
|
|
81
|
+
*
|
|
82
|
+
* @example Default (SDK built-in WebView)
|
|
83
|
+
* ```ts
|
|
84
|
+
* const provider = createLivenessProvider({ spoofScore: metadata.spoofScore });
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @example Custom host service
|
|
88
|
+
* ```ts
|
|
89
|
+
* const provider = createLivenessProvider({ service: myLivenessService, minScore: 0.8 });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
function createLivenessProvider(config = {}) {
|
|
93
|
+
if (config.service) {
|
|
94
|
+
const { service, minScore, requiredChecks } = config;
|
|
95
|
+
return {
|
|
96
|
+
async checkLiveness(imageUri) {
|
|
97
|
+
const result = await service.checkLiveness(imageUri);
|
|
98
|
+
let passed = result.passed;
|
|
99
|
+
if (minScore !== undefined && result.score !== undefined && result.score < minScore) {
|
|
100
|
+
passed = false;
|
|
101
|
+
}
|
|
102
|
+
if (requiredChecks?.length && result.checks) {
|
|
103
|
+
for (const checkId of requiredChecks) {
|
|
104
|
+
if (!result.checks.find((c) => c.id === checkId)?.passed) {
|
|
105
|
+
passed = false;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
passed,
|
|
112
|
+
score: result.score,
|
|
113
|
+
checks: result.checks?.map((c) => ({
|
|
114
|
+
id: c.id,
|
|
115
|
+
passed: c.passed,
|
|
116
|
+
score: c.score,
|
|
117
|
+
reason: c.reason,
|
|
118
|
+
})),
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// Default: pre-computed WebView result
|
|
124
|
+
const result = createLivenessResultFromWebView(config.spoofScore ?? 0, config.threshold);
|
|
125
|
+
return {
|
|
126
|
+
async checkLiveness(_imageUri) {
|
|
127
|
+
return result;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Create a liveness provider that wraps a ZkFaceAuth-based `analyzeLiveness` service.
|
|
133
|
+
* Useful for post-capture liveness re-verification on an already-captured image.
|
|
134
|
+
*/
|
|
135
|
+
function createZkFaceAuthLivenessProvider(zkFaceAuthService) {
|
|
136
|
+
return {
|
|
137
|
+
async checkLiveness(imageUri) {
|
|
138
|
+
const result = await zkFaceAuthService.analyzeLiveness(imageUri);
|
|
139
|
+
return {
|
|
140
|
+
passed: result.passed,
|
|
141
|
+
score: result.score,
|
|
142
|
+
checks: result.checks.map((check) => ({
|
|
143
|
+
id: check.type,
|
|
144
|
+
passed: check.passed,
|
|
145
|
+
score: check.confidence,
|
|
146
|
+
})),
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 JupiterMeta Labs
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* ZK Proof Engine Adapter for React Native WebView
|
|
18
|
+
*
|
|
19
|
+
* Wraps the ZkProofBridge to implement the ZkProofEngine interface.
|
|
20
|
+
* This adapter bridges the SDK core logic to the Plonky3 WebView implementation.
|
|
21
|
+
*/
|
|
22
|
+
import type { ZkProofEngine } from "../../core/types";
|
|
23
|
+
import type { ZkProofBridge } from "../components/ZkProofWebView";
|
|
24
|
+
/**
|
|
25
|
+
* Create a ZK proof engine that wraps the WebView-based ZkProofBridge.
|
|
26
|
+
*
|
|
27
|
+
* This adapter:
|
|
28
|
+
* - Implements the ZkProofEngine interface
|
|
29
|
+
* - Delegates to ZkProofBridge for proof generation/verification
|
|
30
|
+
* - Handles initialization and ready state checking
|
|
31
|
+
*
|
|
32
|
+
* Note: The bridge must be initialized (loadWasmModule called) before use.
|
|
33
|
+
* The caller is responsible for ensuring the bridge is ready.
|
|
34
|
+
*
|
|
35
|
+
* @param bridge ZkProofBridge instance from ZkProofWebView component
|
|
36
|
+
* @param verificationKey Optional VK string (defaults to empty string for now)
|
|
37
|
+
* @returns ZkProofEngine implementation
|
|
38
|
+
*/
|
|
39
|
+
export declare function createZkProofEngineWebView(bridge: ZkProofBridge, verificationKey?: string): ZkProofEngine;
|
|
40
|
+
/**
|
|
41
|
+
* Helper function to initialize the ZK proof engine.
|
|
42
|
+
*
|
|
43
|
+
* This handles the full initialization flow:
|
|
44
|
+
* 1. Wait for bridge to be ready
|
|
45
|
+
* 2. Load WASM module
|
|
46
|
+
* 3. Create and return the engine
|
|
47
|
+
*
|
|
48
|
+
* Usage:
|
|
49
|
+
* ```ts
|
|
50
|
+
* const bridge = new ZkProofBridge(webViewRef);
|
|
51
|
+
* const engine = await initializeZkProofEngine(bridge);
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param bridge ZkProofBridge instance
|
|
55
|
+
* @param verificationKey Optional VK string
|
|
56
|
+
* @returns Promise<ZkProofEngine> Ready-to-use engine
|
|
57
|
+
* @throws Error if initialization fails
|
|
58
|
+
*/
|
|
59
|
+
export declare function initializeZkProofEngine(bridge: ZkProofBridge, verificationKey?: string): Promise<ZkProofEngine>;
|
|
60
|
+
/**
|
|
61
|
+
* Check if a ZK proof bridge is ready for use.
|
|
62
|
+
*
|
|
63
|
+
* @param bridge ZkProofBridge instance
|
|
64
|
+
* @returns true if bridge is ready, false otherwise
|
|
65
|
+
*/
|
|
66
|
+
export declare function isZkProofBridgeReady(bridge: ZkProofBridge): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Get a human-readable status message for the ZK proof bridge.
|
|
69
|
+
*
|
|
70
|
+
* @param bridge ZkProofBridge instance
|
|
71
|
+
* @returns Status message string
|
|
72
|
+
*/
|
|
73
|
+
export declare function getZkProofBridgeStatusMessage(bridge: ZkProofBridge): string;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2026 JupiterMeta Labs
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createZkProofEngineWebView = createZkProofEngineWebView;
|
|
19
|
+
exports.initializeZkProofEngine = initializeZkProofEngine;
|
|
20
|
+
exports.isZkProofBridgeReady = isZkProofBridgeReady;
|
|
21
|
+
exports.getZkProofBridgeStatusMessage = getZkProofBridgeStatusMessage;
|
|
22
|
+
/**
|
|
23
|
+
* Create a ZK proof engine that wraps the WebView-based ZkProofBridge.
|
|
24
|
+
*
|
|
25
|
+
* This adapter:
|
|
26
|
+
* - Implements the ZkProofEngine interface
|
|
27
|
+
* - Delegates to ZkProofBridge for proof generation/verification
|
|
28
|
+
* - Handles initialization and ready state checking
|
|
29
|
+
*
|
|
30
|
+
* Note: The bridge must be initialized (loadWasmModule called) before use.
|
|
31
|
+
* The caller is responsible for ensuring the bridge is ready.
|
|
32
|
+
*
|
|
33
|
+
* @param bridge ZkProofBridge instance from ZkProofWebView component
|
|
34
|
+
* @param verificationKey Optional VK string (defaults to empty string for now)
|
|
35
|
+
* @returns ZkProofEngine implementation
|
|
36
|
+
*/
|
|
37
|
+
function createZkProofEngineWebView(bridge, verificationKey = "") {
|
|
38
|
+
return {
|
|
39
|
+
async generateProof(referenceEmbedding, liveEmbedding, nonce) {
|
|
40
|
+
// Check if bridge is ready
|
|
41
|
+
if (bridge.status !== "ready") {
|
|
42
|
+
throw new Error(`ZkProofBridge not ready. Current status: ${bridge.status}`);
|
|
43
|
+
}
|
|
44
|
+
// Delegate to bridge
|
|
45
|
+
// Note: ZkProofBridge uses different parameter names (embedding1, embedding2)
|
|
46
|
+
// but the same underlying data
|
|
47
|
+
const result = await bridge.generateProof(referenceEmbedding, liveEmbedding, nonce);
|
|
48
|
+
return {
|
|
49
|
+
proof: result.proof,
|
|
50
|
+
publicInputs: result.publicInputs,
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
async verifyProof(proof, publicInputs) {
|
|
54
|
+
// Check if bridge is ready
|
|
55
|
+
if (bridge.status !== "ready") {
|
|
56
|
+
throw new Error(`ZkProofBridge not ready. Current status: ${bridge.status}`);
|
|
57
|
+
}
|
|
58
|
+
// Delegate to bridge
|
|
59
|
+
// Note: verificationKey is required by the bridge but may be empty for now
|
|
60
|
+
const verified = await bridge.verifyProof(proof, publicInputs, verificationKey);
|
|
61
|
+
return verified;
|
|
62
|
+
},
|
|
63
|
+
async getProofHash(proof) {
|
|
64
|
+
// Check if bridge is ready
|
|
65
|
+
if (bridge.status !== "ready") {
|
|
66
|
+
throw new Error(`ZkProofBridge not ready. Current status: ${bridge.status}`);
|
|
67
|
+
}
|
|
68
|
+
// Delegate to bridge
|
|
69
|
+
const hash = await bridge.getProofHash(proof);
|
|
70
|
+
return hash;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Helper function to initialize the ZK proof engine.
|
|
76
|
+
*
|
|
77
|
+
* This handles the full initialization flow:
|
|
78
|
+
* 1. Wait for bridge to be ready
|
|
79
|
+
* 2. Load WASM module
|
|
80
|
+
* 3. Create and return the engine
|
|
81
|
+
*
|
|
82
|
+
* Usage:
|
|
83
|
+
* ```ts
|
|
84
|
+
* const bridge = new ZkProofBridge(webViewRef);
|
|
85
|
+
* const engine = await initializeZkProofEngine(bridge);
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @param bridge ZkProofBridge instance
|
|
89
|
+
* @param verificationKey Optional VK string
|
|
90
|
+
* @returns Promise<ZkProofEngine> Ready-to-use engine
|
|
91
|
+
* @throws Error if initialization fails
|
|
92
|
+
*/
|
|
93
|
+
async function initializeZkProofEngine(bridge, verificationKey = "") {
|
|
94
|
+
// Load WASM module if not already loaded
|
|
95
|
+
if (bridge.status === "idle" || bridge.status === "error") {
|
|
96
|
+
console.log("[ZkProofEngine] Initializing WASM module...");
|
|
97
|
+
await bridge.loadWasmModule();
|
|
98
|
+
console.log("[ZkProofEngine] WASM module initialized successfully");
|
|
99
|
+
}
|
|
100
|
+
// Check final status
|
|
101
|
+
if (bridge.status !== "ready") {
|
|
102
|
+
throw new Error(`Failed to initialize ZK proof engine. Bridge status: ${bridge.status}`);
|
|
103
|
+
}
|
|
104
|
+
// Create and return engine
|
|
105
|
+
return createZkProofEngineWebView(bridge, verificationKey);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Check if a ZK proof bridge is ready for use.
|
|
109
|
+
*
|
|
110
|
+
* @param bridge ZkProofBridge instance
|
|
111
|
+
* @returns true if bridge is ready, false otherwise
|
|
112
|
+
*/
|
|
113
|
+
function isZkProofBridgeReady(bridge) {
|
|
114
|
+
return bridge.status === "ready";
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get a human-readable status message for the ZK proof bridge.
|
|
118
|
+
*
|
|
119
|
+
* @param bridge ZkProofBridge instance
|
|
120
|
+
* @returns Status message string
|
|
121
|
+
*/
|
|
122
|
+
function getZkProofBridgeStatusMessage(bridge) {
|
|
123
|
+
switch (bridge.status) {
|
|
124
|
+
case "idle":
|
|
125
|
+
return "ZK proof engine not initialized";
|
|
126
|
+
case "loading":
|
|
127
|
+
return "Loading ZK proof WASM module...";
|
|
128
|
+
case "ready":
|
|
129
|
+
return "ZK proof engine ready";
|
|
130
|
+
case "error":
|
|
131
|
+
return "ZK proof engine failed to initialize";
|
|
132
|
+
default:
|
|
133
|
+
return "Unknown status";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 JupiterMeta Labs
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Bundled Runtime Asset Defaults
|
|
18
|
+
*
|
|
19
|
+
* This is the ONLY file in the SDK that contains `require()` calls for runtime
|
|
20
|
+
* WebView assets (HTML pages, JS bundles, WASM binaries, data blobs).
|
|
21
|
+
*
|
|
22
|
+
* All SDK components and hooks must import from here rather than calling
|
|
23
|
+
* `require('../../assets/...')` directly. This keeps Metro asset resolution
|
|
24
|
+
* centralised and makes every asset overridable via `FaceZkConfig.runtimeAssets`.
|
|
25
|
+
*
|
|
26
|
+
* NOTE ON ONNX MODELS: model files (antispoof.onnx, det_500m.onnx, etc.) are NOT
|
|
27
|
+
* included here. They are not shipped in the npm package and must always be provided
|
|
28
|
+
* via `FaceZkConfig.models.*`. Missing model config produces a clear error at runtime.
|
|
29
|
+
*/
|
|
30
|
+
import type { FaceZkRuntimeAssetsConfig } from '../config/types';
|
|
31
|
+
/**
|
|
32
|
+
* Bundled defaults for all `FaceZkRuntimeAssetsConfig` fields.
|
|
33
|
+
* Each entry wraps a Metro `require()` so the asset is resolved at bundle time
|
|
34
|
+
* from the SDK's own `assets/` directory.
|
|
35
|
+
*
|
|
36
|
+
* Components should call `resolveRuntimeAsset()` rather than accessing this
|
|
37
|
+
* object directly — that utility handles the config-override + fallback logic.
|
|
38
|
+
*/
|
|
39
|
+
export declare const BUNDLED_RUNTIME_ASSETS: Required<FaceZkRuntimeAssetsConfig>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2026 JupiterMeta Labs
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.BUNDLED_RUNTIME_ASSETS = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* Bundled defaults for all `FaceZkRuntimeAssetsConfig` fields.
|
|
21
|
+
* Each entry wraps a Metro `require()` so the asset is resolved at bundle time
|
|
22
|
+
* from the SDK's own `assets/` directory.
|
|
23
|
+
*
|
|
24
|
+
* Components should call `resolveRuntimeAsset()` rather than accessing this
|
|
25
|
+
* object directly — that utility handles the config-override + fallback logic.
|
|
26
|
+
*/
|
|
27
|
+
exports.BUNDLED_RUNTIME_ASSETS = {
|
|
28
|
+
// ORT Runtime
|
|
29
|
+
ortJs: { module: require('../assets/onnx/ort.min.js.txt') },
|
|
30
|
+
ortWasm: { module: require('../assets/onnx/ort-wasm-simd.wasm') },
|
|
31
|
+
// Liveness WebView
|
|
32
|
+
livenessHtml: { module: require('../assets/liveness/index.html') },
|
|
33
|
+
antispoofJs: { module: require('../assets/liveness/antispoof.js.txt') },
|
|
34
|
+
livenessJs: { module: require('../assets/liveness/liveness.js.txt') },
|
|
35
|
+
// MediaPipe
|
|
36
|
+
mediapipeFaceMeshJs: { module: require('../assets/mediapipe/face_mesh.js.txt') },
|
|
37
|
+
mediapipeSimdWasm: { module: require('../assets/mediapipe/face_mesh_solution_simd_wasm_bin.wasm') },
|
|
38
|
+
mediapipeWasm: { module: require('../assets/mediapipe/face_mesh_solution_wasm_bin.wasm') },
|
|
39
|
+
mediapipeData: { module: require('../assets/mediapipe/face_mesh_solution_packed_assets.data') },
|
|
40
|
+
// Face Guidance WebView
|
|
41
|
+
faceGuidanceHtml: { module: require('../assets/face-guidance/index.html') },
|
|
42
|
+
faceGuidancePoseJs: { module: require('../assets/face-guidance/pose-guidance.js.txt') },
|
|
43
|
+
faceGuidanceLogicJs: { module: require('../assets/face-guidance/face-logic.js.txt') },
|
|
44
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 JupiterMeta Labs
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import React from "react";
|
|
17
|
+
interface FacePoseGuidanceWebViewProps {
|
|
18
|
+
referenceImageUri?: string;
|
|
19
|
+
headless?: boolean;
|
|
20
|
+
onSuccess: (imageUri: string, metadata?: any) => void;
|
|
21
|
+
onError: (message: string) => void;
|
|
22
|
+
onCancel?: () => void;
|
|
23
|
+
manualTargetPose?: {
|
|
24
|
+
yaw: number;
|
|
25
|
+
pitch: number;
|
|
26
|
+
roll: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare const FacePoseGuidanceWebView: React.FC<FacePoseGuidanceWebViewProps>;
|
|
30
|
+
export {};
|