@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,128 @@
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.modelInitialisationChecks = modelInitialisationChecks;
52
+ /**
53
+ * Face+ZK SDK – Model Initialisation Checks
54
+ *
55
+ * Pre-flight utility that inspects whether each configured model source is
56
+ * already available on device without downloading anything.
57
+ *
58
+ * Call this before mounting any SDK screen to decide whether a download step
59
+ * is needed. The result tells you exactly which models are present and which
60
+ * need to be fetched, so your app can show an appropriate UI (progress bar,
61
+ * "first-time setup" screen, etc.) before calling initializeSdk().
62
+ *
63
+ * Usage:
64
+ * const result = await modelInitialisationChecks(modelConfig);
65
+ * if (!result.ready) {
66
+ * // download missing models, show progress, then proceed
67
+ * }
68
+ */
69
+ const FileSystem = __importStar(require("expo-file-system/legacy"));
70
+ const resolveModelUri_1 = require("./resolveModelUri");
71
+ // ── Implementation ─────────────────────────────────────────────────────────
72
+ /**
73
+ * Returns whether a single ModelSource is already locally available.
74
+ * Does NOT download or resolve assets — read-only check.
75
+ */
76
+ async function isSourceReady(source) {
77
+ if (source.localUri) {
78
+ const info = await FileSystem.getInfoAsync(source.localUri);
79
+ return info.exists;
80
+ }
81
+ if (source.module != null) {
82
+ // Metro-bundled assets are always present in the binary.
83
+ return true;
84
+ }
85
+ if (source.url) {
86
+ const info = await FileSystem.getInfoAsync((0, resolveModelUri_1.deriveStorePath)(source.url));
87
+ return info.exists;
88
+ }
89
+ // Source has no resolvable value — treat as not ready.
90
+ return false;
91
+ }
92
+ /**
93
+ * Check whether all configured model sources are already resolved locally.
94
+ *
95
+ * Does NOT download anything. Safe to call on every app launch — fast when
96
+ * all models are present (only stat calls, no network).
97
+ *
98
+ * @param models The same FaceZkModelsConfig you intend to pass to initializeSdk().
99
+ * @returns Readiness result with `ready` flag and `missing`/`present` arrays.
100
+ */
101
+ async function modelInitialisationChecks(models) {
102
+ const entries = [
103
+ ["detection", models.detection],
104
+ ["recognition", models.recognition],
105
+ ["antispoof", models.antispoof],
106
+ ["wasm", models.wasm],
107
+ ["zkWorkerHtml", models.zkWorkerHtml],
108
+ ];
109
+ const missing = [];
110
+ const present = [];
111
+ for (const [key, source] of entries) {
112
+ if (source == null) {
113
+ // Optional model not configured — not required, skip.
114
+ continue;
115
+ }
116
+ if (await isSourceReady(source)) {
117
+ present.push(key);
118
+ }
119
+ else {
120
+ missing.push(key);
121
+ }
122
+ }
123
+ return {
124
+ ready: missing.length === 0,
125
+ missing,
126
+ present,
127
+ };
128
+ }
@@ -0,0 +1,55 @@
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 { ModelSource } from "../../config/types";
17
+ /** Directory where URL-downloaded models are stored persistently. */
18
+ export declare const MODEL_STORE_DIR: string;
19
+ /**
20
+ * Resolve a ModelSource to a local file URI.
21
+ *
22
+ * @param source The model source to resolve.
23
+ * @param onProgress Optional callback receiving download fraction (0–1).
24
+ * Only fires for `url` sources during active download;
25
+ * silent on cache hits.
26
+ * @param allowedDomains Optional hostname allowlist. When provided and non-empty,
27
+ * any `url` source whose hostname is not in this list is
28
+ * rejected before any network request is made.
29
+ * Pass `FaceZkConfig.allowedDomains` here in production.
30
+ * @throws if the source has none of: module, url, localUri
31
+ * @throws if the download fails (url path)
32
+ */
33
+ export declare function resolveModelUri(source: ModelSource, onProgress?: (fraction: number) => void, allowedDomains?: string[]): Promise<string>;
34
+ /**
35
+ * Derive the local store path for a given URL.
36
+ *
37
+ * Guards against path traversal in two passes:
38
+ * 1. URL-decode the last path segment so encoded separators like `%2F` or
39
+ * `%2E%2E` are normalised before any checks run.
40
+ * 2. Re-extract the basename from the decoded string (a decoded `%2F`
41
+ * becomes `/`, so a second `.split("/")` is needed).
42
+ * 3. Reject the reserved names `.` and `..` outright.
43
+ * 4. Allowlist `[A-Za-z0-9._-]` — the only characters that can appear in a
44
+ * legitimate model filename. Anything outside this set throws so the
45
+ * caller can surface the problem rather than silently storing a bad file.
46
+ *
47
+ * @throws if the derived filename is empty, a traversal component, or contains
48
+ * characters outside the safe allowlist.
49
+ */
50
+ export declare function deriveStorePath(url: string): string;
51
+ /**
52
+ * Clear all URL-downloaded model files from the persistent store.
53
+ * Useful for forcing a re-download after a model version update.
54
+ */
55
+ export declare function clearModelCache(): Promise<void>;
@@ -0,0 +1,211 @@
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.MODEL_STORE_DIR = void 0;
52
+ exports.resolveModelUri = resolveModelUri;
53
+ exports.deriveStorePath = deriveStorePath;
54
+ exports.clearModelCache = clearModelCache;
55
+ /**
56
+ * Face+ZK SDK – Model URI Resolution
57
+ *
58
+ * Resolves a `ModelSource` to a local file URI that can be passed to
59
+ * FileSystem.readAsStringAsync() or similar APIs.
60
+ *
61
+ * Resolution order:
62
+ * 1. localUri – returned as-is (already resolved)
63
+ * 2. module – resolved via expo-asset (Metro-bundled)
64
+ * 3. url – downloaded to documentDirectory on first use, path returned
65
+ *
66
+ * Models are stored in documentDirectory (not cacheDirectory) so they
67
+ * survive cache clears and never need re-downloading.
68
+ */
69
+ const expo_asset_1 = require("expo-asset");
70
+ const FileSystem = __importStar(require("expo-file-system/legacy"));
71
+ /** Directory where URL-downloaded models are stored persistently. */
72
+ exports.MODEL_STORE_DIR = `${FileSystem.documentDirectory}face-zk-models/`;
73
+ /**
74
+ * Resolve a ModelSource to a local file URI.
75
+ *
76
+ * @param source The model source to resolve.
77
+ * @param onProgress Optional callback receiving download fraction (0–1).
78
+ * Only fires for `url` sources during active download;
79
+ * silent on cache hits.
80
+ * @param allowedDomains Optional hostname allowlist. When provided and non-empty,
81
+ * any `url` source whose hostname is not in this list is
82
+ * rejected before any network request is made.
83
+ * Pass `FaceZkConfig.allowedDomains` here in production.
84
+ * @throws if the source has none of: module, url, localUri
85
+ * @throws if the download fails (url path)
86
+ */
87
+ async function resolveModelUri(source, onProgress, allowedDomains) {
88
+ // ── 1. Already a local URI ──────────────────────────────────────────────
89
+ if (source.localUri) {
90
+ return source.localUri;
91
+ }
92
+ // ── 2. Metro-bundled module ─────────────────────────────────────────────
93
+ if (source.module != null) {
94
+ const asset = expo_asset_1.Asset.fromModule(source.module);
95
+ await asset.downloadAsync();
96
+ const uri = asset.localUri ?? asset.uri;
97
+ if (!uri) {
98
+ throw new Error("[FaceZkSdk] Failed to resolve bundled asset URI.");
99
+ }
100
+ return uri;
101
+ }
102
+ // ── 3. Remote URL – download and store persistently ─────────────────────
103
+ if (source.url) {
104
+ return downloadAndStore(source.url, onProgress, allowedDomains);
105
+ }
106
+ throw new Error("[FaceZkSdk] ModelSource must have at least one of: module, url, localUri.");
107
+ }
108
+ /**
109
+ * Derive the local store path for a given URL.
110
+ *
111
+ * Guards against path traversal in two passes:
112
+ * 1. URL-decode the last path segment so encoded separators like `%2F` or
113
+ * `%2E%2E` are normalised before any checks run.
114
+ * 2. Re-extract the basename from the decoded string (a decoded `%2F`
115
+ * becomes `/`, so a second `.split("/")` is needed).
116
+ * 3. Reject the reserved names `.` and `..` outright.
117
+ * 4. Allowlist `[A-Za-z0-9._-]` — the only characters that can appear in a
118
+ * legitimate model filename. Anything outside this set throws so the
119
+ * caller can surface the problem rather than silently storing a bad file.
120
+ *
121
+ * @throws if the derived filename is empty, a traversal component, or contains
122
+ * characters outside the safe allowlist.
123
+ */
124
+ function deriveStorePath(url) {
125
+ // Step 1 – take the last slash-delimited segment and drop any query string
126
+ const raw = url.split("/").pop()?.split("?")[0] ?? "";
127
+ // Step 2 – URL-decode so encoded traversal sequences are normalised
128
+ let decoded;
129
+ try {
130
+ decoded = decodeURIComponent(raw);
131
+ }
132
+ catch {
133
+ decoded = raw;
134
+ }
135
+ // Step 3 – re-extract basename in case decoding introduced new separators
136
+ const basename = decoded.replace(/\\/g, "/").split("/").pop() ?? "";
137
+ // Step 4 – reject empty names and dot-traversal components
138
+ if (!basename || basename === "." || basename === "..") {
139
+ throw new Error(`[FaceZkSdk] Unsafe or empty model filename derived from URL: "${url}"`);
140
+ }
141
+ // Step 5 – allowlist: only alphanumeric, dot, hyphen, underscore
142
+ if (!/^[A-Za-z0-9._-]+$/.test(basename)) {
143
+ throw new Error(`[FaceZkSdk] Model filename contains unsafe characters: "${basename}"`);
144
+ }
145
+ return `${exports.MODEL_STORE_DIR}${basename}`;
146
+ }
147
+ /**
148
+ * Download a remote model URL to documentDirectory.
149
+ * Skips download if the file already exists (store hit).
150
+ *
151
+ * Security layers (in order):
152
+ * 1. HTTPS-only — rejects http://, file://, data: etc.
153
+ * 2. Domain allowlist — rejects hostnames not in allowedDomains (if provided).
154
+ * 3. Path containment — asserts the derived local path stays inside MODEL_STORE_DIR.
155
+ */
156
+ async function downloadAndStore(url, onProgress, allowedDomains) {
157
+ // ── Layer 1: HTTPS-only ────────────────────────────────────────────────
158
+ if (!url.startsWith("https://")) {
159
+ throw new Error(`[FaceZkSdk] Only HTTPS model URLs are permitted. Received: "${url.split("?")[0]}"`);
160
+ }
161
+ // ── Layer 2: Domain allowlist ──────────────────────────────────────────
162
+ if (allowedDomains && allowedDomains.length > 0) {
163
+ const hostnameMatch = url.match(/^https:\/\/([^/?#]+)/);
164
+ const hostname = hostnameMatch ? hostnameMatch[1] : null;
165
+ if (!hostname || !allowedDomains.includes(hostname)) {
166
+ throw new Error(`[FaceZkSdk] Model download blocked: hostname "${hostname ?? "unknown"}" is not in allowedDomains. ` +
167
+ `Allowed: [${allowedDomains.join(", ")}]`);
168
+ }
169
+ }
170
+ const localPath = deriveStorePath(url);
171
+ // ── Layer 3: Path containment ──────────────────────────────────────────
172
+ if (!localPath.startsWith(exports.MODEL_STORE_DIR)) {
173
+ throw new Error(`[FaceZkSdk] Security: derived path escapes model store. This is a bug — please report it.`);
174
+ }
175
+ // Ensure store directory exists
176
+ const dirInfo = await FileSystem.getInfoAsync(exports.MODEL_STORE_DIR);
177
+ if (!dirInfo.exists) {
178
+ await FileSystem.makeDirectoryAsync(exports.MODEL_STORE_DIR, {
179
+ intermediates: true,
180
+ });
181
+ }
182
+ // Return stored file if already present
183
+ const fileInfo = await FileSystem.getInfoAsync(localPath);
184
+ if (fileInfo.exists) {
185
+ return localPath;
186
+ }
187
+ // Download with optional progress reporting
188
+ const downloadResumable = FileSystem.createDownloadResumable(url, localPath, {}, onProgress
189
+ ? (progress) => {
190
+ if (progress.totalBytesExpectedToWrite > 0) {
191
+ onProgress(progress.totalBytesWritten / progress.totalBytesExpectedToWrite);
192
+ }
193
+ }
194
+ : undefined);
195
+ const result = await downloadResumable.downloadAsync();
196
+ if (!result || result.status < 200 || result.status >= 300) {
197
+ await FileSystem.deleteAsync(localPath, { idempotent: true });
198
+ throw new Error(`[FaceZkSdk] Failed to download model from ${url} (HTTP ${result?.status ?? "unknown"}).`);
199
+ }
200
+ return localPath;
201
+ }
202
+ /**
203
+ * Clear all URL-downloaded model files from the persistent store.
204
+ * Useful for forcing a re-download after a model version update.
205
+ */
206
+ async function clearModelCache() {
207
+ const info = await FileSystem.getInfoAsync(exports.MODEL_STORE_DIR);
208
+ if (info.exists) {
209
+ await FileSystem.deleteAsync(exports.MODEL_STORE_DIR, { idempotent: true });
210
+ }
211
+ }
@@ -0,0 +1,25 @@
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 { FaceZkRuntimeAssetsConfig } from '../../config/types';
17
+ /**
18
+ * Resolve a runtime asset key to its file contents as a string.
19
+ *
20
+ * @param key Key from `FaceZkRuntimeAssetsConfig` (e.g. `'ortJs'`, `'livenessHtml'`).
21
+ * @param encoding `'utf8'` for text assets (HTML, JS); `'base64'` for binary assets (WASM, data).
22
+ * @param allowedDomains Optional hostname allowlist forwarded to `resolveModelUri` for URL sources.
23
+ * @returns File contents as a string in the requested encoding.
24
+ */
25
+ export declare function resolveRuntimeAsset(key: keyof FaceZkRuntimeAssetsConfig, encoding: 'utf8' | 'base64', allowedDomains?: string[]): Promise<string>;
@@ -0,0 +1,94 @@
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.resolveRuntimeAsset = resolveRuntimeAsset;
52
+ /**
53
+ * resolveRuntimeAsset
54
+ *
55
+ * Resolves a single runtime asset (HTML page, JS bundle, WASM binary, etc.)
56
+ * to its string contents (utf8 or base64).
57
+ *
58
+ * Resolution order:
59
+ * 1. If the SDK is initialised and `config.runtimeAssets[key]` is set,
60
+ * use that `ModelSource` (supports module / url / localUri).
61
+ * 2. Otherwise fall back to the SDK's bundled copy via `BUNDLED_RUNTIME_ASSETS`.
62
+ *
63
+ * This mirrors the pattern already used by `useWasmLoader` for ZK assets and
64
+ * `FaceRecognition` for ONNX models, but generalised to all runtime assets.
65
+ */
66
+ const FileSystem = __importStar(require("expo-file-system/legacy"));
67
+ const FaceZkSdk_1 = require("../../FaceZkSdk");
68
+ const bundledRuntimeAssets_1 = require("../bundledRuntimeAssets");
69
+ const resolveModelUri_1 = require("./resolveModelUri");
70
+ /**
71
+ * Resolve a runtime asset key to its file contents as a string.
72
+ *
73
+ * @param key Key from `FaceZkRuntimeAssetsConfig` (e.g. `'ortJs'`, `'livenessHtml'`).
74
+ * @param encoding `'utf8'` for text assets (HTML, JS); `'base64'` for binary assets (WASM, data).
75
+ * @param allowedDomains Optional hostname allowlist forwarded to `resolveModelUri` for URL sources.
76
+ * @returns File contents as a string in the requested encoding.
77
+ */
78
+ async function resolveRuntimeAsset(key, encoding, allowedDomains) {
79
+ // Pick the configured source if the SDK is initialised and the key is overridden;
80
+ // otherwise fall back to the SDK-bundled copy.
81
+ let source = bundledRuntimeAssets_1.BUNDLED_RUNTIME_ASSETS[key];
82
+ if (FaceZkSdk_1.FaceZkSdk.isInitialized()) {
83
+ const configured = FaceZkSdk_1.FaceZkSdk.getConfig().runtimeAssets?.[key];
84
+ if (configured) {
85
+ source = configured;
86
+ }
87
+ }
88
+ const localUri = await (0, resolveModelUri_1.resolveModelUri)(source, undefined, allowedDomains);
89
+ return FileSystem.readAsStringAsync(localUri, {
90
+ encoding: encoding === 'base64'
91
+ ? FileSystem.EncodingType.Base64
92
+ : FileSystem.EncodingType.UTF8,
93
+ });
94
+ }
@@ -0,0 +1,41 @@
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
+ * Face+ZK SDK – UI Config Resolver
18
+ *
19
+ * Merges user-supplied UiConfig with SDK defaults so flow components
20
+ * always have a complete, resolved theme and string set.
21
+ */
22
+ import type { UiConfig, FaceZkTheme, FaceZkStrings } from "../../core/types";
23
+ export declare const DEFAULT_THEME: FaceZkTheme;
24
+ export declare const DEFAULT_STRINGS: Required<FaceZkStrings>;
25
+ export interface ResolvedTheme extends FaceZkTheme {
26
+ colors: Required<FaceZkTheme["colors"]>;
27
+ borderRadius: number;
28
+ }
29
+ export interface ResolvedUiConfig {
30
+ theme: ResolvedTheme;
31
+ strings: Required<FaceZkStrings>;
32
+ renderLoading?: UiConfig["renderLoading"];
33
+ renderSuccess?: UiConfig["renderSuccess"];
34
+ renderError?: UiConfig["renderError"];
35
+ renderOverlay?: UiConfig["renderOverlay"];
36
+ }
37
+ export declare function resolveUiConfig(uiConfig?: UiConfig): ResolvedUiConfig;
38
+ /**
39
+ * Replace `{score}` placeholder in a string template.
40
+ */
41
+ export declare function interpolate(template: string, vars: Record<string, string | number>): string;
@@ -0,0 +1,81 @@
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.DEFAULT_STRINGS = exports.DEFAULT_THEME = void 0;
19
+ exports.resolveUiConfig = resolveUiConfig;
20
+ exports.interpolate = interpolate;
21
+ // ============================================================================
22
+ // Defaults
23
+ // ============================================================================
24
+ exports.DEFAULT_THEME = {
25
+ colors: {
26
+ primary: "#4CAF50",
27
+ background: "#000000",
28
+ surface: "rgba(255,255,255,0.1)",
29
+ text: "#ffffff",
30
+ textMuted: "#aaaaaa",
31
+ error: "#F44336",
32
+ },
33
+ borderRadius: 8,
34
+ };
35
+ exports.DEFAULT_STRINGS = {
36
+ loadingInitializing: "Initializing...",
37
+ loadingModels: "Loading face recognition models...",
38
+ loadingCapturing: "Capturing image...",
39
+ loadingProcessing: "Processing reference image...",
40
+ loadingEmbedding: "Processing face...",
41
+ loadingMatching: "Matching face...",
42
+ loadingZkProof: "Generating cryptographic proof...",
43
+ verificationSuccessTitle: "Verified!",
44
+ verificationSuccessSubtitle: "Match: {score}%",
45
+ enrollmentSuccessTitle: "Reference Enrolled",
46
+ enrollmentSuccessSubtitle: "Your reference has been successfully enrolled.",
47
+ verificationErrorTitle: "Verification Failed",
48
+ enrollmentErrorTitle: "Enrollment Failed",
49
+ cancelButton: "Cancel",
50
+ retryButton: "Try Again",
51
+ };
52
+ // ============================================================================
53
+ // Resolver
54
+ // ============================================================================
55
+ function resolveUiConfig(uiConfig = {}) {
56
+ const userColors = uiConfig.theme?.colors ?? {};
57
+ const userTheme = uiConfig.theme ?? {};
58
+ return {
59
+ theme: {
60
+ colors: {
61
+ ...exports.DEFAULT_THEME.colors,
62
+ ...userColors,
63
+ },
64
+ borderRadius: userTheme.borderRadius ?? exports.DEFAULT_THEME.borderRadius,
65
+ },
66
+ strings: {
67
+ ...exports.DEFAULT_STRINGS,
68
+ ...(uiConfig.strings ?? {}),
69
+ },
70
+ renderLoading: uiConfig.renderLoading,
71
+ renderSuccess: uiConfig.renderSuccess,
72
+ renderError: uiConfig.renderError,
73
+ renderOverlay: uiConfig.renderOverlay,
74
+ };
75
+ }
76
+ /**
77
+ * Replace `{score}` placeholder in a string template.
78
+ */
79
+ function interpolate(template, vars) {
80
+ return template.replace(/\{(\w+)\}/g, (_, key) => key in vars ? String(vars[key]) : `{${key}}`);
81
+ }