@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,44 @@
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 { StorageAdapter, ReferenceId } from "../core/types";
17
+ /**
18
+ * Create a default storage adapter using react-native-keychain and FileSystem.
19
+ *
20
+ * This implementation:
21
+ * - Stores reference templates in Keychain (secure, hardware-backed)
22
+ * - Stores ZK proofs in FileSystem (large, persistent)
23
+ * - Maintains indices for listing all stored items
24
+ *
25
+ * @returns StorageAdapter implementation
26
+ */
27
+ export declare function createDefaultStorageAdapter(): StorageAdapter;
28
+ /**
29
+ * Get all reference IDs from the index
30
+ */
31
+ export declare function getAllReferenceIds(): Promise<ReferenceId[]>;
32
+ /**
33
+ * Get all proof IDs from the index
34
+ */
35
+ export declare function getAllProofIds(): Promise<string[]>;
36
+ /**
37
+ * Clear all stored references and proofs (for testing/debugging)
38
+ */
39
+ export declare function clearAllStorage(): Promise<void>;
40
+ /**
41
+ * Singleton instance for convenience.
42
+ * Use this if you don't need custom configuration.
43
+ */
44
+ export declare const defaultStorageAdapter: StorageAdapter;
@@ -0,0 +1,344 @@
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.defaultStorageAdapter = void 0;
52
+ exports.createDefaultStorageAdapter = createDefaultStorageAdapter;
53
+ exports.getAllReferenceIds = getAllReferenceIds;
54
+ exports.getAllProofIds = getAllProofIds;
55
+ exports.clearAllStorage = clearAllStorage;
56
+ /**
57
+ * Default Storage Adapter for React Native
58
+ *
59
+ * Implements the StorageAdapter interface using react-native-keychain for metadata
60
+ * and FileSystem for larger data (embeddings, proofs).
61
+ *
62
+ * Storage strategy:
63
+ * - Reference templates: Keychain (embeddings are securely encrypted)
64
+ * - ZK proofs: FileSystem (proofs can be large)
65
+ */
66
+ const Keychain = __importStar(require("react-native-keychain"));
67
+ const FileSystem = __importStar(require("expo-file-system/legacy"));
68
+ /**
69
+ * Storage keys
70
+ */
71
+ const STORAGE_KEYS = {
72
+ REFERENCE_PREFIX: "@face-zk-sdk/reference/",
73
+ PROOF_PREFIX: "@face-zk-sdk/proof/",
74
+ REFERENCE_INDEX: "@face-zk-sdk/reference-index",
75
+ PROOF_INDEX: "@face-zk-sdk/proof-index",
76
+ };
77
+ /**
78
+ * File paths for FileSystem storage
79
+ */
80
+ const getFilePaths = () => {
81
+ const baseDir = `${FileSystem.documentDirectory}face-zk-sdk/`;
82
+ return {
83
+ baseDir,
84
+ proofsDir: `${baseDir}proofs/`,
85
+ };
86
+ };
87
+ /**
88
+ * Ensure storage directories exist
89
+ */
90
+ async function ensureDirectoriesExist() {
91
+ const { baseDir, proofsDir } = getFilePaths();
92
+ try {
93
+ // Check if base directory exists
94
+ const baseDirInfo = await FileSystem.getInfoAsync(baseDir);
95
+ if (!baseDirInfo.exists) {
96
+ await FileSystem.makeDirectoryAsync(baseDir, { intermediates: true });
97
+ }
98
+ // Check if proofs directory exists
99
+ const proofsDirInfo = await FileSystem.getInfoAsync(proofsDir);
100
+ if (!proofsDirInfo.exists) {
101
+ await FileSystem.makeDirectoryAsync(proofsDir, { intermediates: true });
102
+ }
103
+ }
104
+ catch (error) {
105
+ console.error("[DefaultStorageAdapter] Error creating directories:", error);
106
+ throw error;
107
+ }
108
+ }
109
+ /**
110
+ * Create a default storage adapter using react-native-keychain and FileSystem.
111
+ *
112
+ * This implementation:
113
+ * - Stores reference templates in Keychain (secure, hardware-backed)
114
+ * - Stores ZK proofs in FileSystem (large, persistent)
115
+ * - Maintains indices for listing all stored items
116
+ *
117
+ * @returns StorageAdapter implementation
118
+ */
119
+ function createDefaultStorageAdapter() {
120
+ return {
121
+ // ========================================================================
122
+ // Reference Template Storage
123
+ // ========================================================================
124
+ async saveReference(template) {
125
+ const key = `${STORAGE_KEYS.REFERENCE_PREFIX}${template.referenceId}`;
126
+ try {
127
+ // Serialize template to JSON
128
+ const json = JSON.stringify(template);
129
+ // Store in Keychain
130
+ await Keychain.setGenericPassword("face_zk_user", json, { service: key });
131
+ // Update index
132
+ await updateReferenceIndex(template.referenceId, "add");
133
+ console.log(`[DefaultStorageAdapter] Saved reference: ${template.referenceId}`);
134
+ return template.referenceId;
135
+ }
136
+ catch (error) {
137
+ console.error("[DefaultStorageAdapter] Error saving reference:", error);
138
+ throw new Error(`Failed to save reference: ${error instanceof Error ? error.message : "Unknown error"}`);
139
+ }
140
+ },
141
+ async loadReference(referenceId) {
142
+ const key = `${STORAGE_KEYS.REFERENCE_PREFIX}${referenceId}`;
143
+ try {
144
+ const credentials = await Keychain.getGenericPassword({ service: key });
145
+ const json = credentials ? credentials.password : null;
146
+ if (!json) {
147
+ console.log(`[DefaultStorageAdapter] Reference not found: ${referenceId}`);
148
+ return null;
149
+ }
150
+ const template = JSON.parse(json);
151
+ console.log(`[DefaultStorageAdapter] Loaded reference: ${referenceId}`);
152
+ return template;
153
+ }
154
+ catch (error) {
155
+ console.error("[DefaultStorageAdapter] Error loading reference:", error);
156
+ return null;
157
+ }
158
+ },
159
+ async deleteReference(referenceId) {
160
+ const key = `${STORAGE_KEYS.REFERENCE_PREFIX}${referenceId}`;
161
+ try {
162
+ await Keychain.resetGenericPassword({ service: key });
163
+ // Update index
164
+ await updateReferenceIndex(referenceId, "remove");
165
+ console.log(`[DefaultStorageAdapter] Deleted reference: ${referenceId}`);
166
+ }
167
+ catch (error) {
168
+ console.error("[DefaultStorageAdapter] Error deleting reference:", error);
169
+ throw new Error(`Failed to delete reference: ${error instanceof Error ? error.message : "Unknown error"}`);
170
+ }
171
+ },
172
+ // ========================================================================
173
+ // ZK Proof Storage (FileSystem)
174
+ // ========================================================================
175
+ async saveProof(record) {
176
+ const proofId = `proof_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
177
+ const { proofsDir } = getFilePaths();
178
+ const filePath = `${proofsDir}${proofId}.json`;
179
+ try {
180
+ // Ensure directories exist
181
+ await ensureDirectoriesExist();
182
+ // Serialize proof record to JSON
183
+ const json = JSON.stringify(record);
184
+ // Write to file
185
+ await FileSystem.writeAsStringAsync(filePath, json, {
186
+ encoding: FileSystem.EncodingType.UTF8,
187
+ });
188
+ // Update index
189
+ await updateProofIndex(proofId, "add");
190
+ console.log(`[DefaultStorageAdapter] Saved proof: ${proofId}`);
191
+ return proofId;
192
+ }
193
+ catch (error) {
194
+ console.error("[DefaultStorageAdapter] Error saving proof:", error);
195
+ throw new Error(`Failed to save proof: ${error instanceof Error ? error.message : "Unknown error"}`);
196
+ }
197
+ },
198
+ async loadProof(proofId) {
199
+ const { proofsDir } = getFilePaths();
200
+ const filePath = `${proofsDir}${proofId}.json`;
201
+ try {
202
+ // Check if file exists
203
+ const fileInfo = await FileSystem.getInfoAsync(filePath);
204
+ if (!fileInfo.exists) {
205
+ console.log(`[DefaultStorageAdapter] Proof not found: ${proofId}`);
206
+ return null;
207
+ }
208
+ // Read file
209
+ const json = await FileSystem.readAsStringAsync(filePath, {
210
+ encoding: FileSystem.EncodingType.UTF8,
211
+ });
212
+ const record = JSON.parse(json);
213
+ console.log(`[DefaultStorageAdapter] Loaded proof: ${proofId}`);
214
+ return record;
215
+ }
216
+ catch (error) {
217
+ console.error("[DefaultStorageAdapter] Error loading proof:", error);
218
+ return null;
219
+ }
220
+ },
221
+ };
222
+ }
223
+ // ============================================================================
224
+ // Helper Functions for Index Management
225
+ // ============================================================================
226
+ /**
227
+ * Update the reference index (list of all reference IDs)
228
+ */
229
+ async function updateReferenceIndex(referenceId, action) {
230
+ try {
231
+ const credentials = await Keychain.getGenericPassword({ service: STORAGE_KEYS.REFERENCE_INDEX });
232
+ const indexJson = credentials ? credentials.password : null;
233
+ const index = indexJson ? JSON.parse(indexJson) : [];
234
+ if (action === "add") {
235
+ if (!index.includes(referenceId)) {
236
+ index.push(referenceId);
237
+ }
238
+ }
239
+ else {
240
+ const idx = index.indexOf(referenceId);
241
+ if (idx !== -1) {
242
+ index.splice(idx, 1);
243
+ }
244
+ }
245
+ await Keychain.setGenericPassword("face_zk_user", JSON.stringify(index), { service: STORAGE_KEYS.REFERENCE_INDEX });
246
+ }
247
+ catch (error) {
248
+ console.error("[DefaultStorageAdapter] Error updating reference index:", error);
249
+ }
250
+ }
251
+ /**
252
+ * Update the proof index (list of all proof IDs)
253
+ */
254
+ async function updateProofIndex(proofId, action) {
255
+ try {
256
+ const credentials = await Keychain.getGenericPassword({ service: STORAGE_KEYS.PROOF_INDEX });
257
+ const indexJson = credentials ? credentials.password : null;
258
+ const index = indexJson ? JSON.parse(indexJson) : [];
259
+ if (action === "add") {
260
+ if (!index.includes(proofId)) {
261
+ index.push(proofId);
262
+ }
263
+ }
264
+ else {
265
+ const idx = index.indexOf(proofId);
266
+ if (idx !== -1) {
267
+ index.splice(idx, 1);
268
+ }
269
+ }
270
+ await Keychain.setGenericPassword("face_zk_user", JSON.stringify(index), { service: STORAGE_KEYS.PROOF_INDEX });
271
+ }
272
+ catch (error) {
273
+ console.error("[DefaultStorageAdapter] Error updating proof index:", error);
274
+ }
275
+ }
276
+ /**
277
+ * Get all reference IDs from the index
278
+ */
279
+ async function getAllReferenceIds() {
280
+ try {
281
+ const credentials = await Keychain.getGenericPassword({ service: STORAGE_KEYS.REFERENCE_INDEX });
282
+ const indexJson = credentials ? credentials.password : null;
283
+ return indexJson ? JSON.parse(indexJson) : [];
284
+ }
285
+ catch (error) {
286
+ console.error("[DefaultStorageAdapter] Error getting reference index:", error);
287
+ return [];
288
+ }
289
+ }
290
+ /**
291
+ * Get all proof IDs from the index
292
+ */
293
+ async function getAllProofIds() {
294
+ try {
295
+ const credentials = await Keychain.getGenericPassword({ service: STORAGE_KEYS.PROOF_INDEX });
296
+ const indexJson = credentials ? credentials.password : null;
297
+ return indexJson ? JSON.parse(indexJson) : [];
298
+ }
299
+ catch (error) {
300
+ console.error("[DefaultStorageAdapter] Error getting proof index:", error);
301
+ return [];
302
+ }
303
+ }
304
+ /**
305
+ * Clear all stored references and proofs (for testing/debugging)
306
+ */
307
+ async function clearAllStorage() {
308
+ try {
309
+ // Get all reference IDs
310
+ const referenceIds = await getAllReferenceIds();
311
+ // Delete all references
312
+ for (const refId of referenceIds) {
313
+ const key = `${STORAGE_KEYS.REFERENCE_PREFIX}${refId}`;
314
+ await Keychain.resetGenericPassword({ service: key });
315
+ }
316
+ // Clear reference index
317
+ await Keychain.resetGenericPassword({ service: STORAGE_KEYS.REFERENCE_INDEX });
318
+ // Get all proof IDs
319
+ const proofIds = await getAllProofIds();
320
+ // Delete all proof files
321
+ const { proofsDir } = getFilePaths();
322
+ for (const proofId of proofIds) {
323
+ const filePath = `${proofsDir}${proofId}.json`;
324
+ try {
325
+ await FileSystem.deleteAsync(filePath, { idempotent: true });
326
+ }
327
+ catch (error) {
328
+ console.warn(`[DefaultStorageAdapter] Error deleting proof file: ${proofId}`, error);
329
+ }
330
+ }
331
+ // Clear proof index
332
+ await Keychain.resetGenericPassword({ service: STORAGE_KEYS.PROOF_INDEX });
333
+ console.log("[DefaultStorageAdapter] All storage cleared");
334
+ }
335
+ catch (error) {
336
+ console.error("[DefaultStorageAdapter] Error clearing storage:", error);
337
+ throw error;
338
+ }
339
+ }
340
+ /**
341
+ * Singleton instance for convenience.
342
+ * Use this if you don't need custom configuration.
343
+ */
344
+ exports.defaultStorageAdapter = createDefaultStorageAdapter();