@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.
Files changed (74) hide show
  1. package/README.md +46 -1
  2. package/assets/face-guidance/pose-guidance.js.txt +4 -2
  3. package/assets/liveness/liveness.js.txt +3 -0
  4. package/dist/FaceZkSdk.d.ts +69 -0
  5. package/dist/FaceZkSdk.js +136 -0
  6. package/dist/assets/face-guidance/pose-guidance.js.txt +4 -2
  7. package/dist/assets/liveness/liveness.js.txt +3 -0
  8. package/dist/assets/onnx/ort-min.d.ts +1 -0
  9. package/dist/assets/onnx/ort-min.js +11 -0
  10. package/dist/config/defaults.d.ts +51 -0
  11. package/dist/config/defaults.js +61 -0
  12. package/dist/config/types.d.ts +169 -0
  13. package/dist/config/types.js +17 -0
  14. package/dist/core/enrollment-core.d.ts +70 -0
  15. package/dist/core/enrollment-core.js +206 -0
  16. package/dist/core/idGenerator.d.ts +11 -0
  17. package/dist/core/idGenerator.js +32 -0
  18. package/dist/core/matching.d.ts +69 -0
  19. package/dist/core/matching.js +101 -0
  20. package/dist/core/types.d.ts +379 -0
  21. package/dist/core/types.js +37 -0
  22. package/dist/core/verification-core.d.ts +120 -0
  23. package/dist/core/verification-core.js +442 -0
  24. package/dist/core/zk-core.d.ts +69 -0
  25. package/dist/core/zk-core.js +244 -0
  26. package/dist/index.d.ts +29 -0
  27. package/dist/index.js +51 -0
  28. package/dist/react-native/adapters/faceEmbeddingProvider.d.ts +38 -0
  29. package/dist/react-native/adapters/faceEmbeddingProvider.js +45 -0
  30. package/dist/react-native/adapters/imageDataProvider.d.ts +53 -0
  31. package/dist/react-native/adapters/imageDataProvider.js +134 -0
  32. package/dist/react-native/adapters/livenessProvider.d.ts +133 -0
  33. package/dist/react-native/adapters/livenessProvider.js +150 -0
  34. package/dist/react-native/adapters/zkProofEngine-webview.d.ts +73 -0
  35. package/dist/react-native/adapters/zkProofEngine-webview.js +135 -0
  36. package/dist/react-native/bundledRuntimeAssets.d.ts +39 -0
  37. package/dist/react-native/bundledRuntimeAssets.js +44 -0
  38. package/dist/react-native/components/FacePoseGuidanceWebView.d.ts +30 -0
  39. package/dist/react-native/components/FacePoseGuidanceWebView.js +530 -0
  40. package/dist/react-native/components/LivenessWebView.d.ts +39 -0
  41. package/dist/react-native/components/LivenessWebView.js +386 -0
  42. package/dist/react-native/components/OnnxRuntimeWebView.d.ts +58 -0
  43. package/dist/react-native/components/OnnxRuntimeWebView.js +518 -0
  44. package/dist/react-native/components/ZkProofWebView.d.ts +59 -0
  45. package/dist/react-native/components/ZkProofWebView.js +297 -0
  46. package/dist/react-native/dependencies.d.ts +144 -0
  47. package/dist/react-native/dependencies.js +130 -0
  48. package/dist/react-native/hooks/useOnnxLoader.d.ts +37 -0
  49. package/dist/react-native/hooks/useOnnxLoader.js +74 -0
  50. package/dist/react-native/hooks/useWasmLoader.d.ts +30 -0
  51. package/dist/react-native/hooks/useWasmLoader.js +158 -0
  52. package/dist/react-native/index.d.ts +61 -0
  53. package/dist/react-native/index.js +144 -0
  54. package/dist/react-native/services/FaceRecognition.d.ts +92 -0
  55. package/dist/react-native/services/FaceRecognition.js +674 -0
  56. package/dist/react-native/ui/FaceZkVerificationFlow.d.ts +97 -0
  57. package/dist/react-native/ui/FaceZkVerificationFlow.js +477 -0
  58. package/dist/react-native/ui/ReferenceEnrollmentFlow.d.ts +72 -0
  59. package/dist/react-native/ui/ReferenceEnrollmentFlow.js +369 -0
  60. package/dist/react-native/utils/faceAlignment.d.ts +37 -0
  61. package/dist/react-native/utils/faceAlignment.js +186 -0
  62. package/dist/react-native/utils/modelInitialisationChecks.d.ts +36 -0
  63. package/dist/react-native/utils/modelInitialisationChecks.js +128 -0
  64. package/dist/react-native/utils/resolveModelUri.d.ts +55 -0
  65. package/dist/react-native/utils/resolveModelUri.js +211 -0
  66. package/dist/react-native/utils/resolveRuntimeAsset.d.ts +25 -0
  67. package/dist/react-native/utils/resolveRuntimeAsset.js +94 -0
  68. package/dist/react-native/utils/resolveUiConfig.d.ts +41 -0
  69. package/dist/react-native/utils/resolveUiConfig.js +81 -0
  70. package/dist/storage/defaultStorageAdapter.d.ts +44 -0
  71. package/dist/storage/defaultStorageAdapter.js +344 -0
  72. package/dist/tsconfig.tsbuildinfo +1 -1
  73. package/face-zk.config.example.js +10 -3
  74. package/package.json +2 -2
@@ -0,0 +1,297 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.ZkProofWebView = exports.ZkProofBridge = void 0;
52
+ const react_1 = __importStar(require("react"));
53
+ const react_native_1 = require("react-native");
54
+ const react_native_webview_1 = require("react-native-webview");
55
+ // ZkProofBridge class - Placeholder for Plonky integration
56
+ class ZkProofBridge {
57
+ webViewRef;
58
+ messageCallbacks;
59
+ status = 'idle';
60
+ constructor(webViewRef) {
61
+ this.webViewRef = webViewRef;
62
+ console.log('█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█');
63
+ console.log('█ ZK PROOF WEBVIEW - UPDATED █');
64
+ console.log('█ Version: Plonky3 Fix v2 █');
65
+ console.log('█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█');
66
+ this.messageCallbacks = new Map();
67
+ }
68
+ handleMessage(event) {
69
+ try {
70
+ const message = JSON.parse(event.nativeEvent.data);
71
+ if (message.type === "wasm_initialized") {
72
+ this.status = "ready";
73
+ }
74
+ const callback = this.messageCallbacks.get(message.type);
75
+ if (callback) {
76
+ callback(message);
77
+ }
78
+ }
79
+ catch (error) {
80
+ console.error('[ZkProofBridge] Message parse error:', error);
81
+ }
82
+ }
83
+ async loadWasmModule() {
84
+ // NOTE:
85
+ // ZK WASM initialization is driven by `ZkProofWebView`:
86
+ // - WebView sends `ready`
87
+ // - RN sends `init_wasm` with base64 wasm
88
+ // - Worker sends `wasm_initialized`
89
+ //
90
+ // Therefore, `loadWasmModule()` should act as "wait until initialized",
91
+ // not try to perform initialization itself.
92
+ console.log('[ZkProofBridge] loadWasmModule - waiting for wasm_initialized');
93
+ if (this.status === 'ready')
94
+ return;
95
+ this.status = 'loading';
96
+ return new Promise((resolve, reject) => {
97
+ const timeout = setTimeout(() => {
98
+ this.status = 'error';
99
+ this.messageCallbacks.delete('wasm_initialized');
100
+ this.messageCallbacks.delete('INIT_ERROR');
101
+ reject(new Error('WASM load timeout'));
102
+ }, 30000);
103
+ // Preferred signal from worker
104
+ this.messageCallbacks.set('wasm_initialized', () => {
105
+ clearTimeout(timeout);
106
+ this.status = 'ready';
107
+ this.messageCallbacks.delete('wasm_initialized');
108
+ this.messageCallbacks.delete('INIT_ERROR');
109
+ resolve();
110
+ });
111
+ // Backwards compatible error signal (if worker ever emits it)
112
+ this.messageCallbacks.set('INIT_ERROR', (data) => {
113
+ clearTimeout(timeout);
114
+ this.status = 'error';
115
+ this.messageCallbacks.delete('wasm_initialized');
116
+ this.messageCallbacks.delete('INIT_ERROR');
117
+ reject(new Error(data.error || 'WASM init failed'));
118
+ });
119
+ });
120
+ }
121
+ async generateProof(embedding1, embedding2, nonce) {
122
+ return new Promise((resolve, reject) => {
123
+ const timeout = setTimeout(() => {
124
+ reject(new Error('Proof generation timeout'));
125
+ }, 120000);
126
+ this.messageCallbacks.set('proof_result', (data) => {
127
+ clearTimeout(timeout);
128
+ this.messageCallbacks.delete('proof_result');
129
+ this.messageCallbacks.delete('error');
130
+ const payload = data?.data;
131
+ if (!payload) {
132
+ reject(new Error('Malformed WebView response: missing data'));
133
+ return;
134
+ }
135
+ resolve({
136
+ proof: payload.proof || '',
137
+ publicInputs: payload.public_inputs || []
138
+ });
139
+ });
140
+ this.messageCallbacks.set('error', (data) => {
141
+ clearTimeout(timeout);
142
+ this.messageCallbacks.delete('proof_result');
143
+ this.messageCallbacks.delete('error');
144
+ reject(new Error(data.error || 'Proof generation failed'));
145
+ });
146
+ this.sendMessage('generate_proof', {
147
+ storedEmbedding: embedding1,
148
+ capturedEmbedding: embedding2,
149
+ nonce
150
+ });
151
+ });
152
+ }
153
+ async verifyProof(proof, publicInputs, vk) {
154
+ console.log('[ZkProofBridge] verifyProof - calling WASM');
155
+ return new Promise((resolve, reject) => {
156
+ const timeout = setTimeout(() => {
157
+ reject(new Error('Proof verification timeout'));
158
+ }, 30000);
159
+ this.messageCallbacks.set('verify_result', (data) => {
160
+ clearTimeout(timeout);
161
+ this.messageCallbacks.delete('verify_result');
162
+ this.messageCallbacks.delete('error');
163
+ const payload = data?.data;
164
+ if (!payload) {
165
+ reject(new Error('Malformed WebView response: missing data'));
166
+ return;
167
+ }
168
+ // Result structure from WASM: { "verified": true/false, "error": null }
169
+ resolve(payload.verified === true);
170
+ });
171
+ this.messageCallbacks.set('error', (data) => {
172
+ clearTimeout(timeout);
173
+ this.messageCallbacks.delete('verify_result');
174
+ this.messageCallbacks.delete('error');
175
+ reject(new Error(data.error || 'Proof verification failed'));
176
+ });
177
+ this.sendMessage('verify_proof', {
178
+ proof,
179
+ public_inputs: publicInputs,
180
+ vk
181
+ });
182
+ });
183
+ }
184
+ async getProofHash(proof) {
185
+ return new Promise((resolve, reject) => {
186
+ const timeout = setTimeout(() => {
187
+ reject(new Error('Hash generation timeout'));
188
+ }, 5000);
189
+ this.messageCallbacks.set('hash_result', (data) => {
190
+ clearTimeout(timeout);
191
+ this.messageCallbacks.delete('hash_result');
192
+ this.messageCallbacks.delete('error');
193
+ resolve(data.hash);
194
+ });
195
+ this.messageCallbacks.set('error', (data) => {
196
+ clearTimeout(timeout);
197
+ this.messageCallbacks.delete('hash_result');
198
+ this.messageCallbacks.delete('error');
199
+ reject(new Error(data.error || 'Hash generation failed'));
200
+ });
201
+ this.sendMessage('get_proof_hash', { proof });
202
+ });
203
+ }
204
+ sendMessage(type, payload) {
205
+ const message = JSON.stringify({ type, payload });
206
+ if (this.webViewRef.current) {
207
+ this.webViewRef.current.postMessage(message);
208
+ }
209
+ }
210
+ }
211
+ exports.ZkProofBridge = ZkProofBridge;
212
+ /**
213
+ * ZkProofWebView - Plonky3 WASM WebView Bridge
214
+ *
215
+ * Loads the zk-worker.html containing full WASM bindings and message handlers.
216
+ * Injects WASM binary as base64 for initialization.
217
+ */
218
+ const ZkProofWebView = ({ onReady, onError, wasmData }) => {
219
+ const webViewRef = (0, react_1.useRef)(null);
220
+ const bridgeRef = (0, react_1.useRef)(null);
221
+ (0, react_1.useEffect)(() => {
222
+ console.log('[ZkProofWebView] Component mounted');
223
+ return () => console.log('[ZkProofWebView] Component unmounted');
224
+ }, []);
225
+ const handleMessage = (event) => {
226
+ if (bridgeRef.current) {
227
+ bridgeRef.current.handleMessage(event);
228
+ }
229
+ try {
230
+ const message = JSON.parse(event.nativeEvent.data);
231
+ if (message.type === 'LOG') {
232
+ console.log('[ZkProofWebView]', message.message);
233
+ }
234
+ else if (message.type === 'ready') {
235
+ console.log('[ZkProofWebView] Worker ready signal received. Sending WASM binary...');
236
+ if (bridgeRef.current && wasmData) {
237
+ bridgeRef.current.sendMessage('init_wasm', {
238
+ wasmBase64: wasmData.wasmBase64
239
+ });
240
+ }
241
+ }
242
+ else if (message.type === 'wasm_initialized') {
243
+ console.log('[ZkProofWebView] WASM fully initialized! Bridge is ready.');
244
+ if (bridgeRef.current) {
245
+ bridgeRef.current.status = "ready";
246
+ onReady(bridgeRef.current);
247
+ }
248
+ }
249
+ }
250
+ catch (e) {
251
+ console.error('[ZkProofWebView] Message parse error:', e);
252
+ }
253
+ };
254
+ const handleWebViewLoad = () => {
255
+ console.log('[ZkProofWebView] WebView loaded');
256
+ if (!bridgeRef.current) {
257
+ const bridge = new ZkProofBridge(webViewRef);
258
+ bridgeRef.current = bridge;
259
+ }
260
+ // Don't call onReady here anymore. Wait for 'wasm_initialized'.
261
+ };
262
+ // Don't render until we have WASM data
263
+ if (!wasmData) {
264
+ return null;
265
+ }
266
+ return (<react_native_1.View style={styles.hidden}>
267
+ <react_native_webview_1.WebView ref={webViewRef}
268
+ // CRITICAL: baseUrl must be https://localhost to provide a Secure Context for WebAssembly logic.
269
+ // It does NOT make actual network requests, but prevents the WebView from throwing security errors.
270
+ source={{ html: wasmData.workerHtml, baseUrl: 'https://localhost' }} onMessage={handleMessage} onLoad={handleWebViewLoad} onError={(syntheticEvent) => {
271
+ const { nativeEvent } = syntheticEvent;
272
+ console.error('[ZkProofWebView] WebView error:', nativeEvent);
273
+ onError(nativeEvent.description || 'WebView load error');
274
+ }} javaScriptEnabled={true} injectedJavaScriptBeforeContentLoaded={`
275
+ const originalLog = console.log;
276
+ console.log = function(...args) {
277
+ originalLog.apply(console, args);
278
+ if (window.ReactNativeWebView) {
279
+ window.ReactNativeWebView.postMessage(JSON.stringify({
280
+ type: 'LOG',
281
+ message: args.join(' ')
282
+ }));
283
+ }
284
+ };
285
+ `}/>
286
+ </react_native_1.View>);
287
+ };
288
+ exports.ZkProofWebView = ZkProofWebView;
289
+ const styles = react_native_1.StyleSheet.create({
290
+ hidden: {
291
+ position: 'absolute',
292
+ width: 0,
293
+ height: 0,
294
+ opacity: 0
295
+ }
296
+ });
297
+ exports.default = exports.ZkProofWebView;
@@ -0,0 +1,144 @@
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
+ * SDK Dependencies - Dependency Injection
18
+ *
19
+ * This module provides a dependency injection system for external dependencies
20
+ * that the SDK needs but should not directly import from the host app.
21
+ *
22
+ * This allows the SDK to be published as a standalone package while still
23
+ * integrating with platform-specific implementations.
24
+ */
25
+ import type React from "react";
26
+ /**
27
+ * External dependencies that must be provided by the host application.
28
+ * These are platform-specific implementations that the SDK uses but doesn't own.
29
+ */
30
+ export interface SdkDependencies {
31
+ OnnxRuntimeWebView: React.ComponentType<{
32
+ onReady: (bridge: any) => void;
33
+ onError: (error: string) => void;
34
+ }>;
35
+ OnnxRuntimeBridge: new (webViewRef: any) => any;
36
+ ZkProofWebView: React.ComponentType<{
37
+ onReady: (bridge: any) => void;
38
+ onError: (error: string) => void;
39
+ wasmData: any;
40
+ }>;
41
+ ZkProofBridge: new (webViewRef: any) => any;
42
+ ZkFaceAuth: React.ComponentType<{
43
+ onSuccess: (imageUri: string, metadata?: any) => void;
44
+ onError: (message: string) => void;
45
+ manualTargetPose?: {
46
+ yaw: number;
47
+ pitch: number;
48
+ roll: number;
49
+ };
50
+ referenceImageUri?: string;
51
+ renderOverlay?: (state: any) => React.ReactNode;
52
+ headless?: boolean;
53
+ }>;
54
+ FacePoseGuidanceWebView: React.ComponentType<{
55
+ referenceImageUri?: string;
56
+ headless?: boolean;
57
+ onSuccess: (imageUri: string, metadata?: any) => void;
58
+ onError: (message: string) => void;
59
+ onCancel?: () => void;
60
+ manualTargetPose?: {
61
+ yaw: number;
62
+ pitch: number;
63
+ roll: number;
64
+ };
65
+ }>;
66
+ faceRecognitionService: {
67
+ setBridge(bridge: any): void;
68
+ isBridgeSet(): boolean;
69
+ loadModels(): Promise<void>;
70
+ processImageForEmbedding(imageUri: string): Promise<{
71
+ status: "ok" | "no_face" | "multiple_faces" | "error";
72
+ embedding?: number[];
73
+ pose?: {
74
+ yaw: number;
75
+ pitch: number;
76
+ roll: number;
77
+ };
78
+ message?: string;
79
+ }>;
80
+ };
81
+ useWasmLoader: () => {
82
+ wasmData: any;
83
+ error: string | null;
84
+ isLoading: boolean;
85
+ };
86
+ }
87
+ /**
88
+ * Initialize SDK dependencies.
89
+ * This must be called once at app startup before using any SDK UI components.
90
+ *
91
+ * @param deps Platform-specific dependency implementations
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * import { initializeSdkDependencies } from './sdk/react-native/dependencies';
96
+ * import { OnnxRuntimeWebView, OnnxRuntimeBridge } from './src/components/OnnxRuntimeWebView';
97
+ * import { ZkProofWebView, ZkProofBridge } from './src/components/ZkProofWebView';
98
+ * import { ZkFaceAuth } from './src/components/face-verification/LivenessWebView';
99
+ * import { FacePoseGuidanceWebView } from './src/components/face-verification/FacePoseGuidanceWebView';
100
+ * import { faceRecognitionService } from './src/services/FaceRecognition';
101
+ * import { useWasmLoader } from './src/hooks/useWasmLoader';
102
+ *
103
+ * initializeSdkDependencies({
104
+ * OnnxRuntimeWebView,
105
+ * OnnxRuntimeBridge,
106
+ * ZkProofWebView,
107
+ * ZkProofBridge,
108
+ * ZkFaceAuth,
109
+ * FacePoseGuidanceWebView,
110
+ * faceRecognitionService,
111
+ * useWasmLoader,
112
+ * });
113
+ * ```
114
+ */
115
+ export declare function initializeSdkDependencies(deps: SdkDependencies): void;
116
+ /**
117
+ * Get SDK dependencies.
118
+ * Throws an error if dependencies haven't been initialized.
119
+ *
120
+ * @returns SdkDependencies
121
+ * @throws Error if dependencies not initialized
122
+ */
123
+ export declare function getSdkDependencies(): SdkDependencies;
124
+ /**
125
+ * Check if SDK dependencies are initialized.
126
+ *
127
+ * @returns true if initialized, false otherwise
128
+ */
129
+ export declare function areSdkDependenciesInitialized(): boolean;
130
+ /**
131
+ * Clear SDK dependencies (for testing or cleanup).
132
+ */
133
+ export declare function clearSdkDependencies(): void;
134
+ /**
135
+ * Returns the SDK's built-in default dependencies.
136
+ * Pass the result to `initializeSdkDependencies()` to make the initialization
137
+ * explicit in your app (recommended), while still using the SDK's own components.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * initializeSdkDependencies(getDefaultSdkDependencies());
142
+ * ```
143
+ */
144
+ export declare function getDefaultSdkDependencies(): SdkDependencies;
@@ -0,0 +1,130 @@
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.initializeSdkDependencies = initializeSdkDependencies;
19
+ exports.getSdkDependencies = getSdkDependencies;
20
+ exports.areSdkDependenciesInitialized = areSdkDependenciesInitialized;
21
+ exports.clearSdkDependencies = clearSdkDependencies;
22
+ exports.getDefaultSdkDependencies = getDefaultSdkDependencies;
23
+ // Default (SDK-owned) implementations. These allow the SDK to work out-of-the-box
24
+ // inside this repo (and in apps that bundle these SDK components directly),
25
+ // while still supporting dependency injection for advanced customization.
26
+ const OnnxRuntimeWebView_1 = require("./components/OnnxRuntimeWebView");
27
+ const ZkProofWebView_1 = require("./components/ZkProofWebView");
28
+ const LivenessWebView_1 = require("./components/LivenessWebView");
29
+ const FacePoseGuidanceWebView_1 = require("./components/FacePoseGuidanceWebView");
30
+ const FaceRecognition_1 = require("./services/FaceRecognition");
31
+ const useWasmLoader_1 = require("./hooks/useWasmLoader");
32
+ /**
33
+ * Global dependencies storage
34
+ */
35
+ let dependencies = null;
36
+ /**
37
+ * Initialize SDK dependencies.
38
+ * This must be called once at app startup before using any SDK UI components.
39
+ *
40
+ * @param deps Platform-specific dependency implementations
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import { initializeSdkDependencies } from './sdk/react-native/dependencies';
45
+ * import { OnnxRuntimeWebView, OnnxRuntimeBridge } from './src/components/OnnxRuntimeWebView';
46
+ * import { ZkProofWebView, ZkProofBridge } from './src/components/ZkProofWebView';
47
+ * import { ZkFaceAuth } from './src/components/face-verification/LivenessWebView';
48
+ * import { FacePoseGuidanceWebView } from './src/components/face-verification/FacePoseGuidanceWebView';
49
+ * import { faceRecognitionService } from './src/services/FaceRecognition';
50
+ * import { useWasmLoader } from './src/hooks/useWasmLoader';
51
+ *
52
+ * initializeSdkDependencies({
53
+ * OnnxRuntimeWebView,
54
+ * OnnxRuntimeBridge,
55
+ * ZkProofWebView,
56
+ * ZkProofBridge,
57
+ * ZkFaceAuth,
58
+ * FacePoseGuidanceWebView,
59
+ * faceRecognitionService,
60
+ * useWasmLoader,
61
+ * });
62
+ * ```
63
+ */
64
+ function initializeSdkDependencies(deps) {
65
+ dependencies = deps;
66
+ console.log("[SDK] Dependencies initialized successfully");
67
+ }
68
+ /**
69
+ * Get SDK dependencies.
70
+ * Throws an error if dependencies haven't been initialized.
71
+ *
72
+ * @returns SdkDependencies
73
+ * @throws Error if dependencies not initialized
74
+ */
75
+ function getSdkDependencies() {
76
+ if (!dependencies) {
77
+ // Fall back to SDK-owned defaults.
78
+ // This keeps the SDK usable in this repo without requiring initialization plumbing.
79
+ dependencies = {
80
+ OnnxRuntimeWebView: OnnxRuntimeWebView_1.OnnxRuntimeWebView,
81
+ OnnxRuntimeBridge: OnnxRuntimeWebView_1.OnnxRuntimeBridge,
82
+ ZkProofWebView: ZkProofWebView_1.ZkProofWebView,
83
+ ZkProofBridge: ZkProofWebView_1.ZkProofBridge,
84
+ ZkFaceAuth: LivenessWebView_1.ZkFaceAuth,
85
+ FacePoseGuidanceWebView: FacePoseGuidanceWebView_1.FacePoseGuidanceWebView,
86
+ faceRecognitionService: FaceRecognition_1.faceRecognitionService,
87
+ useWasmLoader: useWasmLoader_1.useWasmLoader,
88
+ };
89
+ console.warn("[SDK] Dependencies not initialized. Falling back to SDK defaults. " +
90
+ "For custom implementations, call initializeSdkDependencies().");
91
+ }
92
+ return dependencies;
93
+ }
94
+ /**
95
+ * Check if SDK dependencies are initialized.
96
+ *
97
+ * @returns true if initialized, false otherwise
98
+ */
99
+ function areSdkDependenciesInitialized() {
100
+ return dependencies !== null;
101
+ }
102
+ /**
103
+ * Clear SDK dependencies (for testing or cleanup).
104
+ */
105
+ function clearSdkDependencies() {
106
+ dependencies = null;
107
+ console.log("[SDK] Dependencies cleared");
108
+ }
109
+ /**
110
+ * Returns the SDK's built-in default dependencies.
111
+ * Pass the result to `initializeSdkDependencies()` to make the initialization
112
+ * explicit in your app (recommended), while still using the SDK's own components.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * initializeSdkDependencies(getDefaultSdkDependencies());
117
+ * ```
118
+ */
119
+ function getDefaultSdkDependencies() {
120
+ return {
121
+ OnnxRuntimeWebView: OnnxRuntimeWebView_1.OnnxRuntimeWebView,
122
+ OnnxRuntimeBridge: OnnxRuntimeWebView_1.OnnxRuntimeBridge,
123
+ ZkProofWebView: ZkProofWebView_1.ZkProofWebView,
124
+ ZkProofBridge: ZkProofWebView_1.ZkProofBridge,
125
+ ZkFaceAuth: LivenessWebView_1.ZkFaceAuth,
126
+ FacePoseGuidanceWebView: FacePoseGuidanceWebView_1.FacePoseGuidanceWebView,
127
+ faceRecognitionService: FaceRecognition_1.faceRecognitionService,
128
+ useWasmLoader: useWasmLoader_1.useWasmLoader,
129
+ };
130
+ }
@@ -0,0 +1,37 @@
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
+ * Data returned by useOnnxLoader, ready to pass to OnnxRuntimeWebView.
18
+ */
19
+ export interface OnnxLoaderData {
20
+ /** Text content of ort.min.js — inlined in the WebView HTML. */
21
+ ortJsContent: string;
22
+ /** Base64-encoded ort-wasm-simd.wasm — sent to the WebView via postMessage after load. */
23
+ wasmBase64: string;
24
+ }
25
+ /**
26
+ * Hook for loading ONNX Runtime assets.
27
+ *
28
+ * Loads ort.min.js and ort-wasm-simd.wasm so the ONNX Runtime WebView can run
29
+ * fully offline. Sources are resolved from `FaceZkConfig.runtimeAssets` when
30
+ * the SDK is initialised; otherwise the SDK's bundled copies are used.
31
+ */
32
+ export declare function useOnnxLoader(): {
33
+ isLoading: boolean;
34
+ error: string | null;
35
+ isReady: boolean;
36
+ onnxData: OnnxLoaderData | null;
37
+ };
@@ -0,0 +1,74 @@
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.useOnnxLoader = useOnnxLoader;
19
+ const react_1 = require("react");
20
+ const FaceZkSdk_1 = require("../../FaceZkSdk");
21
+ const resolveRuntimeAsset_1 = require("../utils/resolveRuntimeAsset");
22
+ /**
23
+ * Hook for loading ONNX Runtime assets.
24
+ *
25
+ * Loads ort.min.js and ort-wasm-simd.wasm so the ONNX Runtime WebView can run
26
+ * fully offline. Sources are resolved from `FaceZkConfig.runtimeAssets` when
27
+ * the SDK is initialised; otherwise the SDK's bundled copies are used.
28
+ */
29
+ function useOnnxLoader() {
30
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
31
+ const [error, setError] = (0, react_1.useState)(null);
32
+ const [isReady, setIsReady] = (0, react_1.useState)(false);
33
+ const [onnxData, setOnnxData] = (0, react_1.useState)(null);
34
+ (0, react_1.useEffect)(() => {
35
+ let mounted = true;
36
+ async function loadOnnxResources() {
37
+ try {
38
+ setIsLoading(true);
39
+ setError(null);
40
+ console.log('[useOnnxLoader] Loading ONNX Runtime assets...');
41
+ const allowedDomains = FaceZkSdk_1.FaceZkSdk.isInitialized()
42
+ ? FaceZkSdk_1.FaceZkSdk.getConfig().allowedDomains
43
+ : undefined;
44
+ // Load ort.min.js as text
45
+ const ortJsContent = await (0, resolveRuntimeAsset_1.resolveRuntimeAsset)('ortJs', 'utf8', allowedDomains);
46
+ console.log('[useOnnxLoader] ORT JS loaded, size:', ortJsContent.length);
47
+ // Load ort-wasm-simd.wasm as base64
48
+ let wasmBase64 = await (0, resolveRuntimeAsset_1.resolveRuntimeAsset)('ortWasm', 'base64', allowedDomains);
49
+ // Strip any whitespace/newlines that may cause atob failure in the WebView
50
+ wasmBase64 = wasmBase64.replace(/\s/g, '');
51
+ console.log('[useOnnxLoader] ORT WASM base64 size:', wasmBase64.length);
52
+ if (mounted) {
53
+ setOnnxData({ ortJsContent, wasmBase64 });
54
+ setIsReady(true);
55
+ setIsLoading(false);
56
+ console.log('[useOnnxLoader] ✅ ONNX Runtime assets ready');
57
+ }
58
+ }
59
+ catch (err) {
60
+ console.error('[useOnnxLoader] Error loading ONNX assets:', err);
61
+ if (mounted) {
62
+ setError(err.message || 'Failed to load ONNX Runtime assets');
63
+ setIsLoading(false);
64
+ setIsReady(false);
65
+ }
66
+ }
67
+ }
68
+ loadOnnxResources();
69
+ return () => {
70
+ mounted = false;
71
+ };
72
+ }, []);
73
+ return { isLoading, error, isReady, onnxData };
74
+ }