@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,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
|
+
/**
|
|
17
|
+
* Hook for loading Plonky3 WASM resources
|
|
18
|
+
*
|
|
19
|
+
* Loads the WASM binary and worker HTML, converts them to base64
|
|
20
|
+
* for injection into WebView. Plonky3 STARKs don't require proving keys.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useWasmLoader(): {
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
error: string | null;
|
|
25
|
+
isReady: boolean;
|
|
26
|
+
wasmData: {
|
|
27
|
+
wasmBase64: string;
|
|
28
|
+
workerHtml: string;
|
|
29
|
+
} | null;
|
|
30
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.useWasmLoader = useWasmLoader;
|
|
37
|
+
const expo_asset_1 = require("expo-asset");
|
|
38
|
+
const FileSystem = __importStar(require("expo-file-system/legacy"));
|
|
39
|
+
const react_1 = require("react");
|
|
40
|
+
const FaceZkSdk_1 = require("../../FaceZkSdk");
|
|
41
|
+
const resolveModelUri_1 = require("../utils/resolveModelUri");
|
|
42
|
+
/**
|
|
43
|
+
* Copyright 2026 JupiterMeta Labs
|
|
44
|
+
*
|
|
45
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
46
|
+
* you may not use this file except in compliance with the License.
|
|
47
|
+
* You may obtain a copy of the License at
|
|
48
|
+
*
|
|
49
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
50
|
+
*
|
|
51
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
52
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
53
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
54
|
+
* See the License for the specific language governing permissions and
|
|
55
|
+
* limitations under the License.
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Hook for loading Plonky3 WASM resources
|
|
59
|
+
*
|
|
60
|
+
* Loads the WASM binary and worker HTML, converts them to base64
|
|
61
|
+
* for injection into WebView. Plonky3 STARKs don't require proving keys.
|
|
62
|
+
*/
|
|
63
|
+
function useWasmLoader() {
|
|
64
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
65
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
66
|
+
const [isReady, setIsReady] = (0, react_1.useState)(false);
|
|
67
|
+
const [wasmData, setWasmData] = (0, react_1.useState)(null);
|
|
68
|
+
(0, react_1.useEffect)(() => {
|
|
69
|
+
let mounted = true;
|
|
70
|
+
async function loadWasmResources() {
|
|
71
|
+
try {
|
|
72
|
+
setIsLoading(true);
|
|
73
|
+
setError(null);
|
|
74
|
+
console.log('[useWasmLoader] Starting Plonky3 WASM load...');
|
|
75
|
+
let wasmLocalUri;
|
|
76
|
+
let workerLocalUri;
|
|
77
|
+
if (FaceZkSdk_1.FaceZkSdk.isInitialized()) {
|
|
78
|
+
// ── SDK-configured WASM sources ────────────────────────
|
|
79
|
+
const sdkConfig = FaceZkSdk_1.FaceZkSdk.getConfig();
|
|
80
|
+
if (sdkConfig.models.wasm) {
|
|
81
|
+
wasmLocalUri = await (0, resolveModelUri_1.resolveModelUri)(sdkConfig.models.wasm, undefined, sdkConfig.allowedDomains);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// No wasm override – use bundled fallback
|
|
85
|
+
const wasmAsset = expo_asset_1.Asset.fromModule(require('../../assets/wasm/zk_face_wasm_bg.wasm'));
|
|
86
|
+
await wasmAsset.downloadAsync();
|
|
87
|
+
if (!wasmAsset.localUri)
|
|
88
|
+
throw new Error('Failed to download bundled WASM asset');
|
|
89
|
+
wasmLocalUri = wasmAsset.localUri;
|
|
90
|
+
}
|
|
91
|
+
if (sdkConfig.models.zkWorkerHtml) {
|
|
92
|
+
workerLocalUri = await (0, resolveModelUri_1.resolveModelUri)(sdkConfig.models.zkWorkerHtml, undefined, sdkConfig.allowedDomains);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const workerAsset = expo_asset_1.Asset.fromModule(require('../../assets/zk-worker.html'));
|
|
96
|
+
await workerAsset.downloadAsync();
|
|
97
|
+
if (!workerAsset.localUri)
|
|
98
|
+
throw new Error('Failed to download bundled worker HTML asset');
|
|
99
|
+
workerLocalUri = workerAsset.localUri;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// ── Bundled fallback (in-repo / monorepo usage) ────────
|
|
104
|
+
const wasmAsset = expo_asset_1.Asset.fromModule(require('../../assets/wasm/zk_face_wasm_bg.wasm'));
|
|
105
|
+
await wasmAsset.downloadAsync();
|
|
106
|
+
console.log('[useWasmLoader] WASM asset downloaded:', wasmAsset.localUri);
|
|
107
|
+
const workerAsset = expo_asset_1.Asset.fromModule(require('../../assets/zk-worker.html'));
|
|
108
|
+
await workerAsset.downloadAsync();
|
|
109
|
+
console.log('[useWasmLoader] Worker HTML downloaded:', workerAsset.localUri);
|
|
110
|
+
if (!wasmAsset.localUri || !workerAsset.localUri) {
|
|
111
|
+
throw new Error('Failed to download WASM assets');
|
|
112
|
+
}
|
|
113
|
+
wasmLocalUri = wasmAsset.localUri;
|
|
114
|
+
workerLocalUri = workerAsset.localUri;
|
|
115
|
+
}
|
|
116
|
+
// Read WASM as base64 and clean it
|
|
117
|
+
let wasmBase64 = await FileSystem.readAsStringAsync(wasmLocalUri, {
|
|
118
|
+
encoding: 'base64'
|
|
119
|
+
});
|
|
120
|
+
// Remove any whitespace/newlines that might cause atob failure
|
|
121
|
+
wasmBase64 = wasmBase64.replace(/\s/g, '');
|
|
122
|
+
console.log('[useWasmLoader] WASM base64 size:', wasmBase64.length);
|
|
123
|
+
// Read worker HTML
|
|
124
|
+
const workerHtml = await FileSystem.readAsStringAsync(workerLocalUri, {
|
|
125
|
+
encoding: 'utf8'
|
|
126
|
+
});
|
|
127
|
+
console.log('[useWasmLoader] Worker HTML size:', workerHtml.length);
|
|
128
|
+
if (mounted) {
|
|
129
|
+
setWasmData({
|
|
130
|
+
wasmBase64,
|
|
131
|
+
workerHtml
|
|
132
|
+
});
|
|
133
|
+
setIsReady(true);
|
|
134
|
+
setIsLoading(false);
|
|
135
|
+
console.log('[useWasmLoader] ✅ Plonky3 WASM ready');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
console.error('[useWasmLoader] Error loading WASM:', err);
|
|
140
|
+
if (mounted) {
|
|
141
|
+
setError(err.message || 'Failed to load WASM resources');
|
|
142
|
+
setIsLoading(false);
|
|
143
|
+
setIsReady(false);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
loadWasmResources();
|
|
148
|
+
return () => {
|
|
149
|
+
mounted = false;
|
|
150
|
+
};
|
|
151
|
+
}, []);
|
|
152
|
+
return {
|
|
153
|
+
isLoading,
|
|
154
|
+
error,
|
|
155
|
+
isReady,
|
|
156
|
+
wasmData
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { type SdkDependencies } from "./dependencies";
|
|
17
|
+
import type { FaceZkConfig } from "../config/types";
|
|
18
|
+
export { clearModelCache, resolveModelUri } from "./utils/resolveModelUri";
|
|
19
|
+
export { modelInitialisationChecks, type ModelReadinessResult, type ModelKey, } from "./utils/modelInitialisationChecks";
|
|
20
|
+
/**
|
|
21
|
+
* Bootstraps the Face+ZK SDK and prepares local dependency injection within a React Native application.
|
|
22
|
+
*
|
|
23
|
+
* You must call this function at the very root of your application lifecycle (e.g., in `App.tsx` or `index.js`) before attempting to mount any SDK UI flows or headless hooks.
|
|
24
|
+
*
|
|
25
|
+
* **Initialization Context:** Unlike non-React contexts, React Native needs explicit dependency injection to handle native File System access and WebView bridging. This unified setup replaces the deprecated two-step initialization process and registers the `defaultSdkDependencies` globally.
|
|
26
|
+
*
|
|
27
|
+
* @param {FaceZkConfig} config - The global SDK configuration, including model CDN URLs and threshold limits.
|
|
28
|
+
* @param {SdkDependencies} [deps] - Optional override to inject custom Platform Adapters (e.g., custom WebViews for debugging).
|
|
29
|
+
* @returns {Promise<void>} Resolves when the core singleton is ready.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* await initializeSdk({
|
|
33
|
+
* models: { cdnBaseUrl: 'https://cdn.mycompany.com/zk' }
|
|
34
|
+
* });
|
|
35
|
+
*/
|
|
36
|
+
export declare function initializeSdk(config: FaceZkConfig, deps?: SdkDependencies): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Reset the SDK and clear any cached model files.
|
|
39
|
+
* Use this instead of `FaceZkSdk.reset()` in React Native apps.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resetSdk(): Promise<void>;
|
|
42
|
+
export type { FaceZkConfig, FaceZkModelsConfig, FaceZkFeaturesConfig, FaceZkSetupConfig, ModelSource, } from "../config/types";
|
|
43
|
+
export type { FaceZkTheme, FaceZkStrings, } from "../core/types";
|
|
44
|
+
export type { FloatVector, Pose, LivenessCheckId, ReferenceId, ReferenceTemplate, ReferenceTemplateInput, LiveImageInfo, LiveCaptureResult, LivenessCheckResult, LivenessResult, FaceMatchResult, ZkProofSummary, SdkErrorCode, SdkError, VerificationOutcome, LivenessConfig, ZkProofEngine, ZkConfig, StorageAdapter, ReferenceStorageRecord, ProofStorageRecord, SdkLogger, FaceZkRuntimeConfig, VerificationOptions, EnrollmentOptions, ZkProofOptions, VerificationStage, UiConfig, } from "../core/types";
|
|
45
|
+
export { l2SquaredDistance, l2SquaredToPercentage, computeFaceMatchResult, } from "../core/matching";
|
|
46
|
+
export type { LivenessProvider, ImageDataProvider, } from "../core/verification-core";
|
|
47
|
+
export type { FaceEmbeddingProvider } from "../core/enrollment-core";
|
|
48
|
+
export { initializeSdkDependencies, getSdkDependencies, areSdkDependenciesInitialized, clearSdkDependencies, type SdkDependencies, } from "./dependencies";
|
|
49
|
+
export { ReferenceEnrollmentFlow, type ReferenceEnrollmentFlowProps, } from "./ui/ReferenceEnrollmentFlow";
|
|
50
|
+
export { FaceZkVerificationFlow, type FaceZkVerificationFlowProps, } from "./ui/FaceZkVerificationFlow";
|
|
51
|
+
export { OnnxRuntimeWebView, OnnxRuntimeBridge, } from "./components/OnnxRuntimeWebView";
|
|
52
|
+
export { faceRecognitionService } from "./services/FaceRecognition";
|
|
53
|
+
export { createFaceEmbeddingProvider, defaultFaceEmbeddingProvider, } from "./adapters/faceEmbeddingProvider";
|
|
54
|
+
export { createLivenessResultFromWebView, createWebViewLivenessProvider, createLivenessProvider, createZkFaceAuthLivenessProvider, type LivenessProviderConfig, type ZkFaceAuthLivenessService, } from "./adapters/livenessProvider";
|
|
55
|
+
export { createDefaultImageDataProvider, defaultImageDataProvider, } from "./adapters/imageDataProvider";
|
|
56
|
+
export { createZkProofEngineWebView, initializeZkProofEngine, isZkProofBridgeReady, getZkProofBridgeStatusMessage, } from "./adapters/zkProofEngine-webview";
|
|
57
|
+
export { createDefaultStorageAdapter, defaultStorageAdapter, getAllReferenceIds, getAllProofIds, clearAllStorage, } from "../storage/defaultStorageAdapter";
|
|
58
|
+
export { createReferenceFromImage, } from "../core/enrollment-core";
|
|
59
|
+
export { verifyOnly, verifyWithProof, type VerifyCallOptions, } from "../core/verification-core";
|
|
60
|
+
export { generateZkProofOnly, generateAndPersistZkProof, } from "../core/zk-core";
|
|
61
|
+
export { getDefaultSdkDependencies } from "./dependencies";
|
|
@@ -0,0 +1,144 @@
|
|
|
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.getDefaultSdkDependencies = exports.generateAndPersistZkProof = exports.generateZkProofOnly = exports.verifyWithProof = exports.verifyOnly = exports.createReferenceFromImage = exports.clearAllStorage = exports.getAllProofIds = exports.getAllReferenceIds = exports.defaultStorageAdapter = exports.createDefaultStorageAdapter = exports.getZkProofBridgeStatusMessage = exports.isZkProofBridgeReady = exports.initializeZkProofEngine = exports.createZkProofEngineWebView = exports.defaultImageDataProvider = exports.createDefaultImageDataProvider = exports.createZkFaceAuthLivenessProvider = exports.createLivenessProvider = exports.createWebViewLivenessProvider = exports.createLivenessResultFromWebView = exports.defaultFaceEmbeddingProvider = exports.createFaceEmbeddingProvider = exports.faceRecognitionService = exports.OnnxRuntimeBridge = exports.OnnxRuntimeWebView = exports.FaceZkVerificationFlow = exports.ReferenceEnrollmentFlow = exports.clearSdkDependencies = exports.areSdkDependenciesInitialized = exports.getSdkDependencies = exports.initializeSdkDependencies = exports.computeFaceMatchResult = exports.l2SquaredToPercentage = exports.l2SquaredDistance = exports.modelInitialisationChecks = exports.resolveModelUri = exports.clearModelCache = void 0;
|
|
19
|
+
exports.initializeSdk = initializeSdk;
|
|
20
|
+
exports.resetSdk = resetSdk;
|
|
21
|
+
/**
|
|
22
|
+
* Face+ZK SDK – React Native Exports
|
|
23
|
+
*
|
|
24
|
+
* Entry point for React Native-specific components and adapters.
|
|
25
|
+
* Includes UI flows and platform-specific implementations.
|
|
26
|
+
*
|
|
27
|
+
* For core (headless) functionality, import from '@jupitermetalabs/face-zk-sdk'
|
|
28
|
+
*/
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// SDK Initialization (re-exported for convenience)
|
|
31
|
+
// ============================================================================
|
|
32
|
+
const FaceZkSdk_1 = require("../FaceZkSdk");
|
|
33
|
+
const resolveModelUri_1 = require("./utils/resolveModelUri");
|
|
34
|
+
const dependencies_1 = require("./dependencies");
|
|
35
|
+
// FaceZkSdk class is intentionally NOT re-exported here.
|
|
36
|
+
// React Native apps should use initializeSdk() and resetSdk() below,
|
|
37
|
+
// which wire up RN-specific dependencies (file system, model cache) before
|
|
38
|
+
// calling FaceZkSdk.init(). Bypassing that step causes model loading to fail.
|
|
39
|
+
var resolveModelUri_2 = require("./utils/resolveModelUri");
|
|
40
|
+
Object.defineProperty(exports, "clearModelCache", { enumerable: true, get: function () { return resolveModelUri_2.clearModelCache; } });
|
|
41
|
+
Object.defineProperty(exports, "resolveModelUri", { enumerable: true, get: function () { return resolveModelUri_2.resolveModelUri; } });
|
|
42
|
+
var modelInitialisationChecks_1 = require("./utils/modelInitialisationChecks");
|
|
43
|
+
Object.defineProperty(exports, "modelInitialisationChecks", { enumerable: true, get: function () { return modelInitialisationChecks_1.modelInitialisationChecks; } });
|
|
44
|
+
/**
|
|
45
|
+
* Bootstraps the Face+ZK SDK and prepares local dependency injection within a React Native application.
|
|
46
|
+
*
|
|
47
|
+
* You must call this function at the very root of your application lifecycle (e.g., in `App.tsx` or `index.js`) before attempting to mount any SDK UI flows or headless hooks.
|
|
48
|
+
*
|
|
49
|
+
* **Initialization Context:** Unlike non-React contexts, React Native needs explicit dependency injection to handle native File System access and WebView bridging. This unified setup replaces the deprecated two-step initialization process and registers the `defaultSdkDependencies` globally.
|
|
50
|
+
*
|
|
51
|
+
* @param {FaceZkConfig} config - The global SDK configuration, including model CDN URLs and threshold limits.
|
|
52
|
+
* @param {SdkDependencies} [deps] - Optional override to inject custom Platform Adapters (e.g., custom WebViews for debugging).
|
|
53
|
+
* @returns {Promise<void>} Resolves when the core singleton is ready.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* await initializeSdk({
|
|
57
|
+
* models: { cdnBaseUrl: 'https://cdn.mycompany.com/zk' }
|
|
58
|
+
* });
|
|
59
|
+
*/
|
|
60
|
+
async function initializeSdk(config, deps = (0, dependencies_1.getDefaultSdkDependencies)()) {
|
|
61
|
+
(0, dependencies_1.initializeSdkDependencies)(deps);
|
|
62
|
+
await FaceZkSdk_1.FaceZkSdk.init(config);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Reset the SDK and clear any cached model files.
|
|
66
|
+
* Use this instead of `FaceZkSdk.reset()` in React Native apps.
|
|
67
|
+
*/
|
|
68
|
+
async function resetSdk() {
|
|
69
|
+
FaceZkSdk_1.FaceZkSdk.reset();
|
|
70
|
+
await (0, resolveModelUri_1.clearModelCache)();
|
|
71
|
+
}
|
|
72
|
+
var matching_1 = require("../core/matching");
|
|
73
|
+
Object.defineProperty(exports, "l2SquaredDistance", { enumerable: true, get: function () { return matching_1.l2SquaredDistance; } });
|
|
74
|
+
Object.defineProperty(exports, "l2SquaredToPercentage", { enumerable: true, get: function () { return matching_1.l2SquaredToPercentage; } });
|
|
75
|
+
Object.defineProperty(exports, "computeFaceMatchResult", { enumerable: true, get: function () { return matching_1.computeFaceMatchResult; } });
|
|
76
|
+
// ============================================================================
|
|
77
|
+
// Dependency Injection
|
|
78
|
+
// ============================================================================
|
|
79
|
+
var dependencies_2 = require("./dependencies");
|
|
80
|
+
Object.defineProperty(exports, "initializeSdkDependencies", { enumerable: true, get: function () { return dependencies_2.initializeSdkDependencies; } });
|
|
81
|
+
Object.defineProperty(exports, "getSdkDependencies", { enumerable: true, get: function () { return dependencies_2.getSdkDependencies; } });
|
|
82
|
+
Object.defineProperty(exports, "areSdkDependenciesInitialized", { enumerable: true, get: function () { return dependencies_2.areSdkDependenciesInitialized; } });
|
|
83
|
+
Object.defineProperty(exports, "clearSdkDependencies", { enumerable: true, get: function () { return dependencies_2.clearSdkDependencies; } });
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// React Native UI Flows
|
|
86
|
+
// ============================================================================
|
|
87
|
+
var ReferenceEnrollmentFlow_1 = require("./ui/ReferenceEnrollmentFlow");
|
|
88
|
+
Object.defineProperty(exports, "ReferenceEnrollmentFlow", { enumerable: true, get: function () { return ReferenceEnrollmentFlow_1.ReferenceEnrollmentFlow; } });
|
|
89
|
+
var FaceZkVerificationFlow_1 = require("./ui/FaceZkVerificationFlow");
|
|
90
|
+
Object.defineProperty(exports, "FaceZkVerificationFlow", { enumerable: true, get: function () { return FaceZkVerificationFlow_1.FaceZkVerificationFlow; } });
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// React Native Components (default implementations)
|
|
93
|
+
// ============================================================================
|
|
94
|
+
var OnnxRuntimeWebView_1 = require("./components/OnnxRuntimeWebView");
|
|
95
|
+
Object.defineProperty(exports, "OnnxRuntimeWebView", { enumerable: true, get: function () { return OnnxRuntimeWebView_1.OnnxRuntimeWebView; } });
|
|
96
|
+
Object.defineProperty(exports, "OnnxRuntimeBridge", { enumerable: true, get: function () { return OnnxRuntimeWebView_1.OnnxRuntimeBridge; } });
|
|
97
|
+
var FaceRecognition_1 = require("./services/FaceRecognition");
|
|
98
|
+
Object.defineProperty(exports, "faceRecognitionService", { enumerable: true, get: function () { return FaceRecognition_1.faceRecognitionService; } });
|
|
99
|
+
// ============================================================================
|
|
100
|
+
// React Native Adapters
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// Face Embedding
|
|
103
|
+
var faceEmbeddingProvider_1 = require("./adapters/faceEmbeddingProvider");
|
|
104
|
+
Object.defineProperty(exports, "createFaceEmbeddingProvider", { enumerable: true, get: function () { return faceEmbeddingProvider_1.createFaceEmbeddingProvider; } });
|
|
105
|
+
Object.defineProperty(exports, "defaultFaceEmbeddingProvider", { enumerable: true, get: function () { return faceEmbeddingProvider_1.defaultFaceEmbeddingProvider; } });
|
|
106
|
+
// Liveness
|
|
107
|
+
var livenessProvider_1 = require("./adapters/livenessProvider");
|
|
108
|
+
Object.defineProperty(exports, "createLivenessResultFromWebView", { enumerable: true, get: function () { return livenessProvider_1.createLivenessResultFromWebView; } });
|
|
109
|
+
Object.defineProperty(exports, "createWebViewLivenessProvider", { enumerable: true, get: function () { return livenessProvider_1.createWebViewLivenessProvider; } });
|
|
110
|
+
Object.defineProperty(exports, "createLivenessProvider", { enumerable: true, get: function () { return livenessProvider_1.createLivenessProvider; } });
|
|
111
|
+
Object.defineProperty(exports, "createZkFaceAuthLivenessProvider", { enumerable: true, get: function () { return livenessProvider_1.createZkFaceAuthLivenessProvider; } });
|
|
112
|
+
// Image Data
|
|
113
|
+
var imageDataProvider_1 = require("./adapters/imageDataProvider");
|
|
114
|
+
Object.defineProperty(exports, "createDefaultImageDataProvider", { enumerable: true, get: function () { return imageDataProvider_1.createDefaultImageDataProvider; } });
|
|
115
|
+
Object.defineProperty(exports, "defaultImageDataProvider", { enumerable: true, get: function () { return imageDataProvider_1.defaultImageDataProvider; } });
|
|
116
|
+
// ZK Proof Engine
|
|
117
|
+
var zkProofEngine_webview_1 = require("./adapters/zkProofEngine-webview");
|
|
118
|
+
Object.defineProperty(exports, "createZkProofEngineWebView", { enumerable: true, get: function () { return zkProofEngine_webview_1.createZkProofEngineWebView; } });
|
|
119
|
+
Object.defineProperty(exports, "initializeZkProofEngine", { enumerable: true, get: function () { return zkProofEngine_webview_1.initializeZkProofEngine; } });
|
|
120
|
+
Object.defineProperty(exports, "isZkProofBridgeReady", { enumerable: true, get: function () { return zkProofEngine_webview_1.isZkProofBridgeReady; } });
|
|
121
|
+
Object.defineProperty(exports, "getZkProofBridgeStatusMessage", { enumerable: true, get: function () { return zkProofEngine_webview_1.getZkProofBridgeStatusMessage; } });
|
|
122
|
+
// Storage
|
|
123
|
+
var defaultStorageAdapter_1 = require("../storage/defaultStorageAdapter");
|
|
124
|
+
Object.defineProperty(exports, "createDefaultStorageAdapter", { enumerable: true, get: function () { return defaultStorageAdapter_1.createDefaultStorageAdapter; } });
|
|
125
|
+
Object.defineProperty(exports, "defaultStorageAdapter", { enumerable: true, get: function () { return defaultStorageAdapter_1.defaultStorageAdapter; } });
|
|
126
|
+
Object.defineProperty(exports, "getAllReferenceIds", { enumerable: true, get: function () { return defaultStorageAdapter_1.getAllReferenceIds; } });
|
|
127
|
+
Object.defineProperty(exports, "getAllProofIds", { enumerable: true, get: function () { return defaultStorageAdapter_1.getAllProofIds; } });
|
|
128
|
+
Object.defineProperty(exports, "clearAllStorage", { enumerable: true, get: function () { return defaultStorageAdapter_1.clearAllStorage; } });
|
|
129
|
+
// ============================================================================
|
|
130
|
+
// Headless Core Functions (re-exported for React Native consumers)
|
|
131
|
+
// ============================================================================
|
|
132
|
+
var enrollment_core_1 = require("../core/enrollment-core");
|
|
133
|
+
Object.defineProperty(exports, "createReferenceFromImage", { enumerable: true, get: function () { return enrollment_core_1.createReferenceFromImage; } });
|
|
134
|
+
var verification_core_1 = require("../core/verification-core");
|
|
135
|
+
Object.defineProperty(exports, "verifyOnly", { enumerable: true, get: function () { return verification_core_1.verifyOnly; } });
|
|
136
|
+
Object.defineProperty(exports, "verifyWithProof", { enumerable: true, get: function () { return verification_core_1.verifyWithProof; } });
|
|
137
|
+
var zk_core_1 = require("../core/zk-core");
|
|
138
|
+
Object.defineProperty(exports, "generateZkProofOnly", { enumerable: true, get: function () { return zk_core_1.generateZkProofOnly; } });
|
|
139
|
+
Object.defineProperty(exports, "generateAndPersistZkProof", { enumerable: true, get: function () { return zk_core_1.generateAndPersistZkProof; } });
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// Default Dependencies
|
|
142
|
+
// ============================================================================
|
|
143
|
+
var dependencies_3 = require("./dependencies");
|
|
144
|
+
Object.defineProperty(exports, "getDefaultSdkDependencies", { enumerable: true, get: function () { return dependencies_3.getDefaultSdkDependencies; } });
|
|
@@ -0,0 +1,92 @@
|
|
|
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 { OnnxRuntimeBridge } from "../components/OnnxRuntimeWebView";
|
|
17
|
+
import { Point } from "../utils/faceAlignment";
|
|
18
|
+
type DetectionBox = {
|
|
19
|
+
x1: number;
|
|
20
|
+
y1: number;
|
|
21
|
+
x2: number;
|
|
22
|
+
y2: number;
|
|
23
|
+
score: number;
|
|
24
|
+
landmarks: Point[];
|
|
25
|
+
};
|
|
26
|
+
type DetectionStatus = "ok" | "no_face" | "multiple_faces" | "error";
|
|
27
|
+
export interface FaceProcessResult {
|
|
28
|
+
status: DetectionStatus;
|
|
29
|
+
embedding?: number[];
|
|
30
|
+
box?: DetectionBox;
|
|
31
|
+
pose?: {
|
|
32
|
+
yaw: number;
|
|
33
|
+
pitch: number;
|
|
34
|
+
roll: number;
|
|
35
|
+
};
|
|
36
|
+
message?: string;
|
|
37
|
+
gender?: "Male" | "Female" | "Unknown";
|
|
38
|
+
age?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Unified Face Recognition Service for iOS and Android
|
|
42
|
+
* Uses ONNX Runtime Web in WebView for cross-platform compatibility
|
|
43
|
+
* Models: buffalo_sc (SCRFD detection + MobileFaceNet recognition)
|
|
44
|
+
*/
|
|
45
|
+
export declare class FaceRecognitionService {
|
|
46
|
+
private bridge;
|
|
47
|
+
private modelsLoaded;
|
|
48
|
+
setBridge(bridge: OnnxRuntimeBridge): void;
|
|
49
|
+
isBridgeSet(): boolean;
|
|
50
|
+
loadModels(): Promise<void>;
|
|
51
|
+
processImageForEmbedding(imageUri: string): Promise<FaceProcessResult>;
|
|
52
|
+
getEmbeddings(imageUri: string): Promise<number[] | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Process a pre-cropped reference image without face detection.
|
|
55
|
+
* This skips bounding box detection and directly extracts the embedding.
|
|
56
|
+
* Use this for small, already-cropped document photos to preserve quality.
|
|
57
|
+
*/
|
|
58
|
+
processPreCroppedImage(imageUri: string): Promise<FaceProcessResult>;
|
|
59
|
+
private preprocessImage;
|
|
60
|
+
private parseDetectionOutput;
|
|
61
|
+
private applyNMS;
|
|
62
|
+
private calculateIOU;
|
|
63
|
+
private expandBox;
|
|
64
|
+
private normalizeEmbedding;
|
|
65
|
+
/**
|
|
66
|
+
* Converts a CHW tensor from ArcFace normalization [-1, 1] back to raw pixel
|
|
67
|
+
* values [0, 255] as expected by the genderage model (scalefactor=1, mean=0).
|
|
68
|
+
* ArcFace: v = (pixel - 127.5) / 128.0 → pixel = v * 128.0 + 127.5
|
|
69
|
+
*/
|
|
70
|
+
private renormalizeForGenderAge;
|
|
71
|
+
/**
|
|
72
|
+
* Replicates the Python yakhyo/facial-analysis center-crop for genderage:
|
|
73
|
+
* scale = 96 / (max(w, h) * 1.5) ← 1.5× padding around the face
|
|
74
|
+
* SimilarityTransform(scale, translate_to_center)
|
|
75
|
+
* cv2.warpAffine → 96×96, borderValue=0
|
|
76
|
+
* blobFromImage scalefactor=1, mean=0, swapRB=True → [0, 255] RGB
|
|
77
|
+
*
|
|
78
|
+
* Crops directly from the normalized 640×640 tensor and denormalizes.
|
|
79
|
+
*/
|
|
80
|
+
private cropFaceForGenderAge;
|
|
81
|
+
/**
|
|
82
|
+
* Resizes a CHW normalized float32 tensor using bilinear interpolation
|
|
83
|
+
*/
|
|
84
|
+
private resizeTensorCHW;
|
|
85
|
+
/**
|
|
86
|
+
* Estimate Pose (Yaw, Pitch, Roll) from 5 landmarks (SCRFD)
|
|
87
|
+
* Landmarks: [LeftEye, RightEye, Nose, LeftMouth, RightMouth]
|
|
88
|
+
*/
|
|
89
|
+
private estimatePoseFromLandmarks;
|
|
90
|
+
}
|
|
91
|
+
export declare const faceRecognitionService: FaceRecognitionService;
|
|
92
|
+
export {};
|