@jupitermetalabs/face-zk-sdk 0.1.0
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/LICENSE +201 -0
- package/README.md +181 -0
- package/assets/README.md +22 -0
- package/assets/face-guidance/face-logic.js.txt +77 -0
- package/assets/face-guidance/index.html +173 -0
- package/assets/face-guidance/pose-guidance.js.txt +403 -0
- package/assets/liveness/antispoof.js.txt +143 -0
- package/assets/liveness/index.html +451 -0
- package/assets/liveness/liveness.js.txt +1003 -0
- package/assets/mediapipe/face_mesh.js.txt +131 -0
- package/assets/mediapipe/face_mesh_solution_packed_assets.data +0 -0
- package/assets/mediapipe/face_mesh_solution_simd_wasm_bin.wasm +0 -0
- package/assets/mediapipe/face_mesh_solution_wasm_bin.wasm +0 -0
- package/assets/onnx/ort-wasm-simd.wasm +0 -0
- package/assets/onnx/ort-wasm.wasm +0 -0
- package/assets/onnx/ort.min.js.txt +7 -0
- package/assets/wasm/zk_face_wasm_bg.wasm +0 -0
- package/assets/zk-worker.html +472 -0
- package/cli/copy-ort-assets.js +65 -0
- package/cli/setup.js +266 -0
- package/dist/FaceZkSdk.d.ts +69 -0
- package/dist/FaceZkSdk.js +132 -0
- package/dist/assets/onnx/ort-min.d.ts +1 -0
- package/dist/assets/onnx/ort-min.js +8 -0
- package/dist/config/defaults.d.ts +49 -0
- package/dist/config/defaults.js +55 -0
- package/dist/config/types.d.ts +123 -0
- package/dist/config/types.js +16 -0
- package/dist/core/enrollment-core.d.ts +68 -0
- package/dist/core/enrollment-core.js +202 -0
- package/dist/core/matching.d.ts +69 -0
- package/dist/core/matching.js +96 -0
- package/dist/core/types.d.ts +365 -0
- package/dist/core/types.js +34 -0
- package/dist/core/verification-core.d.ts +120 -0
- package/dist/core/verification-core.js +434 -0
- package/dist/core/zk-core.d.ts +69 -0
- package/dist/core/zk-core.js +240 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +39 -0
- package/dist/react-native/adapters/faceEmbeddingProvider.d.ts +38 -0
- package/dist/react-native/adapters/faceEmbeddingProvider.js +41 -0
- package/dist/react-native/adapters/imageDataProvider.d.ts +53 -0
- package/dist/react-native/adapters/imageDataProvider.js +97 -0
- package/dist/react-native/adapters/livenessProvider.d.ts +133 -0
- package/dist/react-native/adapters/livenessProvider.js +144 -0
- package/dist/react-native/adapters/zkProofEngine-webview.d.ts +73 -0
- package/dist/react-native/adapters/zkProofEngine-webview.js +129 -0
- package/dist/react-native/components/FacePoseGuidanceWebView.d.ts +30 -0
- package/dist/react-native/components/FacePoseGuidanceWebView.js +474 -0
- package/dist/react-native/components/LivenessWebView.d.ts +39 -0
- package/dist/react-native/components/LivenessWebView.js +348 -0
- package/dist/react-native/components/OnnxRuntimeWebView.d.ts +54 -0
- package/dist/react-native/components/OnnxRuntimeWebView.js +394 -0
- package/dist/react-native/components/ZkProofWebView.d.ts +59 -0
- package/dist/react-native/components/ZkProofWebView.js +259 -0
- package/dist/react-native/dependencies.d.ts +144 -0
- package/dist/react-native/dependencies.js +123 -0
- package/dist/react-native/hooks/useOnnxLoader.d.ts +38 -0
- package/dist/react-native/hooks/useOnnxLoader.js +81 -0
- package/dist/react-native/hooks/useWasmLoader.d.ts +30 -0
- package/dist/react-native/hooks/useWasmLoader.js +122 -0
- package/dist/react-native/index.d.ts +59 -0
- package/dist/react-native/index.js +96 -0
- package/dist/react-native/services/FaceRecognition.d.ts +70 -0
- package/dist/react-native/services/FaceRecognition.js +517 -0
- package/dist/react-native/ui/FaceZkVerificationFlow.d.ts +97 -0
- package/dist/react-native/ui/FaceZkVerificationFlow.js +433 -0
- package/dist/react-native/ui/ReferenceEnrollmentFlow.d.ts +72 -0
- package/dist/react-native/ui/ReferenceEnrollmentFlow.js +321 -0
- package/dist/react-native/utils/faceAlignment.d.ts +37 -0
- package/dist/react-native/utils/faceAlignment.js +182 -0
- package/dist/react-native/utils/modelInitialisationChecks.d.ts +36 -0
- package/dist/react-native/utils/modelInitialisationChecks.js +92 -0
- package/dist/react-native/utils/resolveModelUri.d.ts +55 -0
- package/dist/react-native/utils/resolveModelUri.js +172 -0
- package/dist/react-native/utils/resolveUiConfig.d.ts +41 -0
- package/dist/react-native/utils/resolveUiConfig.js +76 -0
- package/dist/storage/defaultStorageAdapter.d.ts +44 -0
- package/dist/storage/defaultStorageAdapter.js +299 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/face-zk.config.example.js +88 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 JupiterMeta Labs
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Face+ZK SDK
|
|
2
|
+
|
|
3
|
+
A standalone React Native and Web SDK for face verification and Zero-Knowledge (ZK) proofs.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Face Matching**: High-accuracy face embedding comparison.
|
|
8
|
+
- **Liveness Detection**: Interactive liveness checks with antispoofing protection.
|
|
9
|
+
- **ZK Proofs**: Generate and verify cryptographic proofs of identity without revealing facial biometric data.
|
|
10
|
+
- **Platform Agnostic**: Works on iOS, Android (via Expo), and Web.
|
|
11
|
+
|
|
12
|
+
## Directory Structure
|
|
13
|
+
|
|
14
|
+
To keep documentation clean, each major module has its own dedicated documentation:
|
|
15
|
+
- [**`core/`**](./core/README.md): Headless business logic, types, and matching algorithms.
|
|
16
|
+
- [**`react-native/`**](./react-native/README.md): UI components, platform adapters, and hooks for React Native/Expo.
|
|
17
|
+
- [**`config/`**](./config/README.md): Configuration guides, environments, and CDN settings.
|
|
18
|
+
- `storage/`: Built-in storage adapters for persisting enrolled references and proofs.
|
|
19
|
+
- `assets/`: ONNX models and WebView-based liveness/ZK scripts.
|
|
20
|
+
- `example/`: A complete Expo app demonstrating how to integrate the SDK.
|
|
21
|
+
- `example/`: A complete Expo app demonstrating how to integrate the SDK.
|
|
22
|
+
|
|
23
|
+
## Getting Started
|
|
24
|
+
|
|
25
|
+
### Prerequisites
|
|
26
|
+
|
|
27
|
+
- **Node.js**: >= 20
|
|
28
|
+
- **Expo SDK**: 54 or compatible React Native
|
|
29
|
+
- **Git LFS**: Required for downloading ONNX models and WASM binaries.
|
|
30
|
+
|
|
31
|
+
### Installation
|
|
32
|
+
|
|
33
|
+
1. Install dependencies in the root:
|
|
34
|
+
```bash
|
|
35
|
+
npm install
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Install dependencies in your host app:
|
|
39
|
+
```bash
|
|
40
|
+
npm install @jupitermetalabs/face-zk-sdk
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Detailed Configuration Reference
|
|
44
|
+
|
|
45
|
+
### `FaceZkRuntimeConfig`
|
|
46
|
+
The global runtime configuration for the SDK instance.
|
|
47
|
+
|
|
48
|
+
| Field | Type | Description |
|
|
49
|
+
| :--- | :--- | :--- |
|
|
50
|
+
| **`liveness`** | `Object` | **Optional.** Controls anti-spoofing. |
|
|
51
|
+
| `liveness.enabled` | `boolean` | If `true`, requires liveness check to pass for overall success. |
|
|
52
|
+
| **`zk`** | `Object` | **Optional.** Controls ZK proof generation. |
|
|
53
|
+
| `zk.enabled` | `boolean` | Enables the ZK proof subsystem. |
|
|
54
|
+
| `zk.engine` | `ZkProofEngine` | The engine implementation (e.g., Plonky3 WebView bridge). |
|
|
55
|
+
| `zk.requiredForSuccess` | `boolean` | If `true`, verification fails if ZK proof generation fails. |
|
|
56
|
+
| **`storage`** | `StorageAdapter` | **Optional.** Provider for saving reference images/embeddings. |
|
|
57
|
+
| **`onLog`** | `Function` | **Optional.** Local logging callback for telemetry. |
|
|
58
|
+
|
|
59
|
+
> **Note:** Match pass/fail is determined by the ZK engine (which owns the threshold internally). The SDK exposes the raw L2² distance and match percentage in `VerificationOutcome.match` for informational use.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### `VerifyCallOptions`
|
|
64
|
+
Pass to `verifyOnly` / `verifyWithProof` (5th argument) to supply per-call providers and override global config. Extends `VerificationOptions`.
|
|
65
|
+
|
|
66
|
+
| Field | Type | Description |
|
|
67
|
+
| :--- | :--- | :--- |
|
|
68
|
+
| **`livenessProvider`** | `LivenessProvider` | **Optional.** Liveness provider for this call. |
|
|
69
|
+
| **`imageDataProvider`** | `ImageDataProvider` | **Optional.** Image-data provider (base64, size, quality). |
|
|
70
|
+
| **`liveness`** | `Partial` | Override `enabled` for this check. |
|
|
71
|
+
| **`zk`** | `Partial` | Override `requiredForSuccess` for this session. |
|
|
72
|
+
| **`includeImageData`**| `Object` | Request extra data in the verified event payload. |
|
|
73
|
+
| `*.base64` | `boolean` | Include the captured live frame as a base64 string. |
|
|
74
|
+
| `*.sizeKb` | `boolean` | Include the approximate size of the image. |
|
|
75
|
+
| `*.qualityScore` | `number` | Include an image quality score (0–1, higher = better). |
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
### `EnrollmentOptions`
|
|
80
|
+
Pass these to `ReferenceEnrollmentFlow` or `createReferenceFromImage`.
|
|
81
|
+
|
|
82
|
+
| Field | Type | Description |
|
|
83
|
+
| :--- | :--- | :--- |
|
|
84
|
+
| **`metadata`** | `Object` | Key-value pairs stored alongside the reference (e.g., `userId`). |
|
|
85
|
+
| **`persist`** | `boolean` | If `true`, automatically saves the template via the `storage` adapter. |
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Basic Usage
|
|
90
|
+
|
|
91
|
+
### 0. Prerequisites
|
|
92
|
+
|
|
93
|
+
**Git LFS** is required to clone ONNX model files and WASM binaries (stored via LFS):
|
|
94
|
+
```bash
|
|
95
|
+
git lfs install
|
|
96
|
+
git lfs pull
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Peer dependencies** — install in your host app:
|
|
100
|
+
```bash
|
|
101
|
+
npx expo install react-native-webview expo-camera expo-file-system expo-asset
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Metro config** — add asset extensions so Metro bundles `.onnx`, `.wasm`, and `.html` files.
|
|
105
|
+
In your `metro.config.js`:
|
|
106
|
+
```js
|
|
107
|
+
const { getDefaultConfig } = require('expo/metro-config');
|
|
108
|
+
const config = getDefaultConfig(__dirname);
|
|
109
|
+
config.resolver.assetExts.push('onnx', 'wasm', 'html', 'data');
|
|
110
|
+
module.exports = config;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Camera permissions** — add to your app config:
|
|
114
|
+
- **iOS** (`app.json` or `Info.plist`): `NSCameraUsageDescription`
|
|
115
|
+
- **Android** (`app.json` or `AndroidManifest.xml`): `android.permission.CAMERA`
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### 1. Initialize the SDK
|
|
120
|
+
Call once at app startup:
|
|
121
|
+
```typescript
|
|
122
|
+
import { initializeSdk } from '@jupitermetalabs/face-zk-sdk/react-native';
|
|
123
|
+
|
|
124
|
+
await initializeSdk({
|
|
125
|
+
models: {
|
|
126
|
+
detection: { module: require('./assets/models/det_500m.onnx') },
|
|
127
|
+
recognition: { module: require('./assets/models/w600k_mbf.onnx') },
|
|
128
|
+
antispoof: { module: require('./assets/models/antispoof.onnx') },
|
|
129
|
+
wasm: { module: require('./assets/wasm/zk_face_wasm_bg.wasm') },
|
|
130
|
+
zkWorkerHtml: { module: require('./assets/zk-worker.html') },
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 2. Build a `FaceZkRuntimeConfig`
|
|
136
|
+
Pass this to the UI components or headless core functions to control liveness, ZK, storage, and logging:
|
|
137
|
+
```typescript
|
|
138
|
+
import type { FaceZkRuntimeConfig } from '@jupitermetalabs/face-zk-sdk/react-native';
|
|
139
|
+
|
|
140
|
+
const sdkConfig: FaceZkRuntimeConfig = {
|
|
141
|
+
liveness: { enabled: true },
|
|
142
|
+
zk: { enabled: true, engine: myZkProofEngine, requiredForSuccess: false },
|
|
143
|
+
storage: myStorageAdapter,
|
|
144
|
+
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 3. Liveness Provider
|
|
148
|
+
The SDK ships with a built-in WebView liveness provider. Use the unified factory:
|
|
149
|
+
```typescript
|
|
150
|
+
import { createLivenessProvider } from '@jupitermetalabs/face-zk-sdk/react-native';
|
|
151
|
+
|
|
152
|
+
// Default — uses the SDK's built-in WebView anti-spoof result
|
|
153
|
+
const provider = createLivenessProvider({ spoofScore: metadata.spoofScore });
|
|
154
|
+
|
|
155
|
+
// Custom — plug in your own host-side liveness service
|
|
156
|
+
const provider = createLivenessProvider({ service: myLivenessService, minScore: 0.8 });
|
|
157
|
+
```
|
|
158
|
+
`FaceZkVerificationFlow` uses the built-in WebView provider automatically; you only need `createLivenessProvider` when implementing a headless flow or substituting your own liveness service.
|
|
159
|
+
|
|
160
|
+
### 4. Enrollment Flow
|
|
161
|
+
Capture a reference face and save it to storage.
|
|
162
|
+
```tsx
|
|
163
|
+
<ReferenceEnrollmentFlow
|
|
164
|
+
sdkConfig={sdkConfig}
|
|
165
|
+
onComplete={(template) => console.log("Enrolled!", template)}
|
|
166
|
+
/>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 5. Verification Flow
|
|
170
|
+
Verify a live user against a saved reference.
|
|
171
|
+
```tsx
|
|
172
|
+
<FaceZkVerificationFlow
|
|
173
|
+
sdkConfig={sdkConfig}
|
|
174
|
+
reference={savedReference}
|
|
175
|
+
mode="verify-with-proof"
|
|
176
|
+
onComplete={(outcome) => console.log("Verified!", outcome)}
|
|
177
|
+
/>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Contributing
|
|
181
|
+
Please see the individual `README.md` files in each subdirectory for more technical details on the architecture.
|
package/assets/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# SDK Assets Module
|
|
2
|
+
|
|
3
|
+
This directory contains the binary models, JavaScript workers, and HTML templates that power the SDK's liveness detection and cryptographic proof generation.
|
|
4
|
+
|
|
5
|
+
## Directory Structure
|
|
6
|
+
|
|
7
|
+
- **`models/`**: ONNX models for face detection (`det_500m.onnx`) and recognition (`w600k_mbf.onnx`).
|
|
8
|
+
- **`liveness/`**: JavaScript logic for depth checks, antispoofing, and pose estimation. Runs inside a WebView.
|
|
9
|
+
- **`wasm/`**: WebAssembly binaries for the Zero-Knowledge proof system.
|
|
10
|
+
- **`mediapipe/`**: Local MediaPipe Face Mesh bundles for liveness detection.
|
|
11
|
+
- **`face-guidance/`**: HTML/JS for the interactive enrollment face guidance overlay.
|
|
12
|
+
- **`zk-worker.html`**: The HTML entry point for the Zero-Knowledge proof generation worker.
|
|
13
|
+
|
|
14
|
+
## Data Flow
|
|
15
|
+
|
|
16
|
+
These assets are typically loaded by the `react-native` components (using `expo-asset`) and injected into `react-native-webview` instances.
|
|
17
|
+
|
|
18
|
+
### Models
|
|
19
|
+
Models are downloaded to the device's local filesystem and passed as base64 strings or local URIs to the ONNX Runtime WebView.
|
|
20
|
+
|
|
21
|
+
### Liveness Scripts
|
|
22
|
+
The liveness scripts in `liveness/` perform real-time landmark analysis to ensure the presence of a real, live human. They communicate back to the React Native layer via WebView message events.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* Face Pose Calculation Logic */
|
|
2
|
+
|
|
3
|
+
// --- POSE CALCULATION ---
|
|
4
|
+
// Distance-invariant yaw/pitch calculation with face dimension normalization
|
|
5
|
+
// This matches the calculation in liveness.js for consistent TARGET and CURRENT pose comparison
|
|
6
|
+
function calculatePose(landmarks) {
|
|
7
|
+
const nose = landmarks[1];
|
|
8
|
+
const leftCheek = landmarks[234];
|
|
9
|
+
const rightCheek = landmarks[454];
|
|
10
|
+
|
|
11
|
+
// Face Width for normalization (makes calculation distance-invariant)
|
|
12
|
+
const faceWidth = Math.hypot(
|
|
13
|
+
rightCheek.x - leftCheek.x,
|
|
14
|
+
rightCheek.y - leftCheek.y
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// Yaw: Rotation around Y axis (Turning Left/Right)
|
|
18
|
+
const midPointX = (leftCheek.x + rightCheek.x) / 2;
|
|
19
|
+
// Normalize by face width to get comparable angle regardless of distance
|
|
20
|
+
// Multiplier 180 is heuristic to match standard degrees
|
|
21
|
+
const yaw = ((nose.x - midPointX) / faceWidth) * 180;
|
|
22
|
+
|
|
23
|
+
// Pitch: Rotation around X axis (Looking Up/Down)
|
|
24
|
+
const midEyeY = (landmarks[33].y + landmarks[263].y) / 2;
|
|
25
|
+
const mouthY = (landmarks[13].y + landmarks[14].y) / 2;
|
|
26
|
+
const midFaceY = (midEyeY + mouthY) / 2;
|
|
27
|
+
|
|
28
|
+
// Face Height for normalization (chin to forehead)
|
|
29
|
+
const chin = landmarks[152];
|
|
30
|
+
const forehead = landmarks[10];
|
|
31
|
+
const faceHeight = Math.hypot(
|
|
32
|
+
chin.x - forehead.x,
|
|
33
|
+
chin.y - forehead.y
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const pitch = ((nose.y - midFaceY) / faceHeight) * 180;
|
|
37
|
+
|
|
38
|
+
return { yaw, pitch, roll: 0 };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function calculateGaze(landmarks) {
|
|
42
|
+
if (!landmarks[468] || !landmarks[473]) return { x: 0.5, y: 0.5 }; // Default centered if no iris
|
|
43
|
+
|
|
44
|
+
// Left Eye (User's Left = Right on screen if mirrored, but landmarks are consistent)
|
|
45
|
+
// Left Eye Inner: 362, Outer: 263, Iris: 473
|
|
46
|
+
const rightEyeInner = landmarks[362];
|
|
47
|
+
const rightEyeOuter = landmarks[263];
|
|
48
|
+
const rightIris = landmarks[473];
|
|
49
|
+
|
|
50
|
+
// Right Eye (User's Right)
|
|
51
|
+
// Right Eye Inner: 33, Outer: 133, Iris: 468
|
|
52
|
+
const leftEyeInner = landmarks[33];
|
|
53
|
+
const leftEyeOuter = landmarks[133];
|
|
54
|
+
const leftIris = landmarks[468]; // 468 is Left Iris Center
|
|
55
|
+
|
|
56
|
+
// Calculate Horizontal Ratio (0 = Looking Left, 1 = Looking Right, 0.5 = Center)
|
|
57
|
+
|
|
58
|
+
// Left Eye horizontal distance
|
|
59
|
+
const leftEyeWidth = Math.hypot(leftEyeOuter.x - leftEyeInner.x, leftEyeOuter.y - leftEyeInner.y);
|
|
60
|
+
const leftIrisDist = Math.hypot(leftIris.x - leftEyeInner.x, leftIris.y - leftEyeInner.y);
|
|
61
|
+
const leftRatio = leftIrisDist / leftEyeWidth;
|
|
62
|
+
|
|
63
|
+
// Right Eye horizontal distance
|
|
64
|
+
const rightEyeWidth = Math.hypot(rightEyeOuter.x - rightEyeInner.x, rightEyeOuter.y - rightEyeInner.y);
|
|
65
|
+
const rightIrisDist = Math.hypot(rightIris.x - rightEyeInner.x, rightIris.y - rightEyeInner.y);
|
|
66
|
+
const rightRatio = rightIrisDist / rightEyeWidth;
|
|
67
|
+
|
|
68
|
+
// Average ratio
|
|
69
|
+
const avgRatio = (leftRatio + rightRatio) / 2;
|
|
70
|
+
return { x: avgRatio, y: 0.5 };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Export functions if using modules, but here we likely just inject into global scope
|
|
74
|
+
if (typeof window !== 'undefined') {
|
|
75
|
+
window.calculatePose = calculatePose;
|
|
76
|
+
window.calculateGaze = calculateGaze;
|
|
77
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta
|
|
6
|
+
name="viewport"
|
|
7
|
+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
|
8
|
+
/>
|
|
9
|
+
<title>Face Pose Guidance</title>
|
|
10
|
+
|
|
11
|
+
<!-- Tailwind -->
|
|
12
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
13
|
+
|
|
14
|
+
<!-- MediaPipe -->
|
|
15
|
+
<script
|
|
16
|
+
src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js"
|
|
17
|
+
crossorigin="anonymous"
|
|
18
|
+
></script>
|
|
19
|
+
<script
|
|
20
|
+
src="https://cdn.jsdelivr.net/npm/@mediapipe/control_utils/control_utils.js"
|
|
21
|
+
crossorigin="anonymous"
|
|
22
|
+
></script>
|
|
23
|
+
<script
|
|
24
|
+
src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js"
|
|
25
|
+
crossorigin="anonymous"
|
|
26
|
+
></script>
|
|
27
|
+
<script
|
|
28
|
+
src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js"
|
|
29
|
+
crossorigin="anonymous"
|
|
30
|
+
></script>
|
|
31
|
+
<!-- ONNX Runtime Web -->
|
|
32
|
+
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.14.0/dist/ort.min.js"></script>
|
|
33
|
+
|
|
34
|
+
<style>
|
|
35
|
+
.camera-wrapper {
|
|
36
|
+
position: relative;
|
|
37
|
+
width: 100vw;
|
|
38
|
+
height: 100vh;
|
|
39
|
+
overflow: hidden;
|
|
40
|
+
background: #000;
|
|
41
|
+
display: flex;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
align-items: center;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#input_video {
|
|
47
|
+
display: none;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#output_canvas {
|
|
51
|
+
max-width: 100%;
|
|
52
|
+
max-height: 100%;
|
|
53
|
+
object-fit: contain;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.mirror {
|
|
57
|
+
transform: scaleX(-1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.overlay {
|
|
61
|
+
position: absolute;
|
|
62
|
+
top: 0;
|
|
63
|
+
left: 0;
|
|
64
|
+
right: 0;
|
|
65
|
+
bottom: 0;
|
|
66
|
+
pointer-events: none;
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-direction: column;
|
|
69
|
+
justify-content: space-between;
|
|
70
|
+
padding: 40px 20px;
|
|
71
|
+
z-index: 10;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.message-box {
|
|
75
|
+
background: rgba(0, 0, 0, 0.6);
|
|
76
|
+
backdrop-filter: blur(4px);
|
|
77
|
+
padding: 16px 24px;
|
|
78
|
+
border-radius: 12px;
|
|
79
|
+
text-align: center;
|
|
80
|
+
margin: 0 auto;
|
|
81
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.guidance-arrow {
|
|
85
|
+
position: absolute;
|
|
86
|
+
top: 50%;
|
|
87
|
+
font-size: 4rem;
|
|
88
|
+
color: white;
|
|
89
|
+
text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
|
|
90
|
+
opacity: 0;
|
|
91
|
+
transition: opacity 0.3s;
|
|
92
|
+
transform: translateY(-50%);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.arrow-left {
|
|
96
|
+
left: 20px;
|
|
97
|
+
animation: bounce-left 1s infinite;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.arrow-right {
|
|
101
|
+
right: 20px;
|
|
102
|
+
animation: bounce-right 1s infinite;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@keyframes bounce-left {
|
|
106
|
+
0%,
|
|
107
|
+
100% {
|
|
108
|
+
transform: translate(0, -50%);
|
|
109
|
+
}
|
|
110
|
+
50% {
|
|
111
|
+
transform: translate(-10px, -50%);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@keyframes bounce-right {
|
|
116
|
+
0%,
|
|
117
|
+
100% {
|
|
118
|
+
transform: translate(0, -50%);
|
|
119
|
+
}
|
|
120
|
+
50% {
|
|
121
|
+
transform: translate(10px, -50%);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
</style>
|
|
125
|
+
</head>
|
|
126
|
+
<body class="bg-black m-0 overflow-hidden">
|
|
127
|
+
<div class="camera-wrapper">
|
|
128
|
+
<video id="input_video" playsinline></video>
|
|
129
|
+
<canvas id="output_canvas"></canvas>
|
|
130
|
+
|
|
131
|
+
<div class="overlay">
|
|
132
|
+
<!-- Top Status -->
|
|
133
|
+
<div id="status_box" class="message-box">
|
|
134
|
+
<p id="status_text" class="text-white text-lg font-medium">
|
|
135
|
+
Initializing...
|
|
136
|
+
</p>
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
<!-- Guidance Elements -->
|
|
140
|
+
<div id="arrow_left" class="guidance-arrow arrow-left">⬅️</div>
|
|
141
|
+
<div id="arrow_right" class="guidance-arrow arrow-right">➡️</div>
|
|
142
|
+
|
|
143
|
+
<!-- Bottom Status -->
|
|
144
|
+
<div id="instruction_box" class="message-box hidden">
|
|
145
|
+
<p id="instruction_text" class="text-slate-300 text-sm">
|
|
146
|
+
Align your face
|
|
147
|
+
</p>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<div
|
|
153
|
+
id="debug_info"
|
|
154
|
+
style="
|
|
155
|
+
position: absolute;
|
|
156
|
+
top: 10px;
|
|
157
|
+
left: 10px;
|
|
158
|
+
background: rgba(0, 0, 0, 0.7);
|
|
159
|
+
color: lime;
|
|
160
|
+
font-family: monospace;
|
|
161
|
+
font-size: 12px;
|
|
162
|
+
padding: 8px;
|
|
163
|
+
border-radius: 4px;
|
|
164
|
+
pointer-events: none;
|
|
165
|
+
z-index: 100;
|
|
166
|
+
white-space: pre;
|
|
167
|
+
"
|
|
168
|
+
></div>
|
|
169
|
+
|
|
170
|
+
<!-- Main Logic Script -->
|
|
171
|
+
<script src="pose-guidance.js"></script>
|
|
172
|
+
</body>
|
|
173
|
+
</html>
|