faceliveness-web 0.0.0-stage → 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 +176 -0
- package/README.md +53 -2
- package/liveness_wasm.d.ts +190 -0
- package/liveness_wasm.js +699 -0
- package/liveness_wasm_bg.wasm +0 -0
- package/liveness_wasm_bg.wasm.d.ts +22 -0
- package/package.json +25 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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
|
package/README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# faceliveness-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
On-device face liveness checks in the browser: the Face Liveness Rust engine compiled to
|
|
4
|
+
WebAssembly. The user performs random actions (blink, turn left, turn right, open mouth) in
|
|
5
|
+
front of the camera; face detection, landmarks and passive anti-spoofing run locally, and the
|
|
6
|
+
session's best face is kept as an aligned face record for matching.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install faceliveness-web
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
For servers use [`faceliveness`](https://www.npmjs.com/package/faceliveness) (Node.js, native)
|
|
13
|
+
or [`faceliveness`](https://pypi.org/project/faceliveness/) (Python).
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Run the engine in a Web Worker: a frame takes tens of milliseconds.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
// worker.js
|
|
21
|
+
import init, { Engine } from 'faceliveness-web'
|
|
22
|
+
|
|
23
|
+
await init() // loads liveness_wasm_bg.wasm (~24 MB, ~8 MB compressed)
|
|
24
|
+
const engine = Engine.random(3) // e.g. ['turn_left', 'blink', 'open_mouth']
|
|
25
|
+
|
|
26
|
+
self.onmessage = ({ data }) => {
|
|
27
|
+
// data.pixels: ctx.getImageData(0, 0, w, h).data from a canvas showing the camera
|
|
28
|
+
const result = engine.process(data.pixels, { width: data.width, height: data.height, timestampMs: data.ts })
|
|
29
|
+
self.postMessage({ result, capture: result.done ? engine.capture() : null })
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`result.currentChallenge` is what to ask for next; `result.done` and `result.status`
|
|
34
|
+
(`'passed'` / `'failed'`) end the attempt. `engine.capture()` returns the face record:
|
|
35
|
+
a 112x112 aligned face as PNG bytes plus its quality.
|
|
36
|
+
|
|
37
|
+
The frame layout defaults to `'rgba'` (canvas `ImageData`); pass `format`, `rotation` and
|
|
38
|
+
`mirrored` for other sources. Full types ship in `liveness_wasm.d.ts`.
|
|
39
|
+
|
|
40
|
+
## Trust
|
|
41
|
+
|
|
42
|
+
A result computed in the browser can be changed by the user, so it is **not tamper-proof**. Use
|
|
43
|
+
it for instant feedback, and let your server make the decision: stream frames to a server
|
|
44
|
+
running `faceliveness` (`Engine.fromTicket`), which signs a receipt; `verifyReceipt` and
|
|
45
|
+
`verifyFaceRecord` are also available here to check one.
|
|
46
|
+
|
|
47
|
+
Working example (browser + server): the
|
|
48
|
+
[demo](https://github.com/wiseman-umanah/Face-Liveness/tree/master/demo).
|
|
49
|
+
Threat model: [docs/threat-model.md](https://github.com/wiseman-umanah/Face-Liveness/blob/master/docs/threat-model.md).
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
Apache-2.0. Bundles MediaPipe face models and minivision MiniFASNet anti-spoofing models
|
|
54
|
+
(both Apache-2.0).
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export type Challenge = 'blink' | 'turn_left' | 'turn_right' | 'open_mouth'
|
|
5
|
+
export type PixelFormat = 'rgb' | 'bgr' | 'rgba' | 'bgra' | 'nv21'
|
|
6
|
+
export type LivenessStatus = 'in_progress' | 'passed' | 'failed'
|
|
7
|
+
export type FailReason = 'timeout' | 'step_timeout' | 'face_lost' | 'multiple_faces' | 'spoof_suspected'
|
|
8
|
+
|
|
9
|
+
export interface SessionOptions {
|
|
10
|
+
/** Fail if the whole check takes longer than this (default 30000). */
|
|
11
|
+
totalTimeoutMs?: number
|
|
12
|
+
/** Fail if one challenge takes longer than this (default 10000). */
|
|
13
|
+
stepTimeoutMs?: number
|
|
14
|
+
/** Fail if the face is out of view longer than this (default 1000). */
|
|
15
|
+
faceLostMs?: number
|
|
16
|
+
/** Fail a completed session whose mean realScore is below this (off by default). */
|
|
17
|
+
minRealScore?: number
|
|
18
|
+
/** Side of the face record crop, engine.capture() (default 112; 32-512). */
|
|
19
|
+
captureSize?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface FrameOptions {
|
|
23
|
+
width: number
|
|
24
|
+
height: number
|
|
25
|
+
/** Capture time in milliseconds; drives every timeout. */
|
|
26
|
+
timestampMs: number
|
|
27
|
+
/** Default 'rgba', the layout of canvas ImageData. */
|
|
28
|
+
format?: PixelFormat
|
|
29
|
+
/** Bytes per row; defaults to width x bytes per pixel. */
|
|
30
|
+
stride?: number
|
|
31
|
+
/** Clockwise degrees (0, 90, 180, 270) that turn the frame upright. */
|
|
32
|
+
rotation?: number
|
|
33
|
+
/** True for selfie-style mirrored frames. */
|
|
34
|
+
mirrored?: boolean
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Signals { ear: number; mouth: number; yaw: number }
|
|
38
|
+
export interface FaceBox { x: number; y: number; width: number; height: number; score: number }
|
|
39
|
+
|
|
40
|
+
export interface FrameResult {
|
|
41
|
+
status: LivenessStatus
|
|
42
|
+
/** True once passed or failed; later frames won't change the outcome. */
|
|
43
|
+
done: boolean
|
|
44
|
+
currentChallenge?: Challenge
|
|
45
|
+
remaining: number
|
|
46
|
+
failReason?: FailReason
|
|
47
|
+
/** Actions recognised in this frame. */
|
|
48
|
+
actions: Challenge[]
|
|
49
|
+
faceCount: number
|
|
50
|
+
signals?: Signals
|
|
51
|
+
faces: FaceBox[]
|
|
52
|
+
/** 478 face-mesh landmarks [x, y] of the primary face, in upright pixels. */
|
|
53
|
+
landmarks?: Array<[number, number]>
|
|
54
|
+
/** Passive anti-spoofing score (0-1), on every 3rd frame with a face. Uncalibrated. */
|
|
55
|
+
realScore?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface Ticket { nonce: string; challenges: Challenge[]; issuedAt: number; expiresAt: number }
|
|
59
|
+
/** The best face of a session, aligned for face matching. */
|
|
60
|
+
export interface FaceCapture {
|
|
61
|
+
/** The aligned face as PNG: store and send these exact bytes. */
|
|
62
|
+
png: Uint8Array
|
|
63
|
+
/** The same image as raw RGB bytes (size * size * 3). */
|
|
64
|
+
rgb: Uint8Array
|
|
65
|
+
size: number
|
|
66
|
+
/** 0-1 suitability for matching (frontal, eyes open, mouth closed, sharp, well lit). */
|
|
67
|
+
quality: number
|
|
68
|
+
timestampMs: number
|
|
69
|
+
/** Hex SHA-256 of png, as recorded in the receipt. */
|
|
70
|
+
sha256: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Receipt {
|
|
74
|
+
nonce: string
|
|
75
|
+
challenges: Challenge[]
|
|
76
|
+
passed: boolean
|
|
77
|
+
failReason?: FailReason
|
|
78
|
+
frames: number
|
|
79
|
+
framesSha256: string
|
|
80
|
+
realScore?: number
|
|
81
|
+
faceSha256?: string
|
|
82
|
+
faceQuality?: number
|
|
83
|
+
issuedAt: number
|
|
84
|
+
expiresAt: number
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Frames in, liveness verdict out. One engine is one attempt; create a new one per attempt.
|
|
91
|
+
* Model loading takes a moment, so create it before showing the camera.
|
|
92
|
+
*/
|
|
93
|
+
export class Engine {
|
|
94
|
+
free(): void;
|
|
95
|
+
[Symbol.dispose](): void;
|
|
96
|
+
/**
|
|
97
|
+
* The best face of the session so far, aligned for face matching, or null.
|
|
98
|
+
* On-device results are not tamper-proof: a server should produce the face record it trusts.
|
|
99
|
+
*/
|
|
100
|
+
capture(): FaceCapture | null;
|
|
101
|
+
constructor(challenges: Challenge[], options: SessionOptions | undefined);
|
|
102
|
+
/**
|
|
103
|
+
* Processes one frame, e.g. `ctx.getImageData(...).data` with format 'rgba' (the default).
|
|
104
|
+
*/
|
|
105
|
+
process(pixels: Uint8Array, options: FrameOptions): FrameResult;
|
|
106
|
+
/**
|
|
107
|
+
* `count` challenges in an order drawn from the browser's crypto randomness.
|
|
108
|
+
*/
|
|
109
|
+
static random(count: number, options: SessionOptions | undefined): Engine;
|
|
110
|
+
readonly challenges: Challenge[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The challenge flow from measurements you compute yourself (no image processing).
|
|
115
|
+
*/
|
|
116
|
+
export class Session {
|
|
117
|
+
free(): void;
|
|
118
|
+
[Symbol.dispose](): void;
|
|
119
|
+
constructor(challenges: Challenge[], options: SessionOptions | undefined);
|
|
120
|
+
/**
|
|
121
|
+
* One frame: faces in view and the main face's measurements, if known.
|
|
122
|
+
*/
|
|
123
|
+
update(timestamp_ms: number, observation: { faceCount?: number; ear?: number; mouth?: number; yaw?: number } | undefined): FrameResult;
|
|
124
|
+
readonly challenges: Challenge[];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* For the face-matching service: checks the receipt, that the session passed, and that
|
|
129
|
+
* `facePng` is exactly the face record it vouches for; throws otherwise.
|
|
130
|
+
*/
|
|
131
|
+
export function verifyFaceRecord(token: string, public_key: Uint8Array, face_png: Uint8Array, now?: number | null): Receipt;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Checks a receipt (signature and expiry); throws if invalid.
|
|
135
|
+
*/
|
|
136
|
+
export function verifyReceipt(token: string, public_key: Uint8Array, now?: number | null): Receipt;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Checks a ticket from your server (signature and expiry); throws if invalid.
|
|
140
|
+
*/
|
|
141
|
+
export function verifyTicket(token: string, public_key: Uint8Array, now?: number | null): Ticket;
|
|
142
|
+
|
|
143
|
+
export function version(): string;
|
|
144
|
+
|
|
145
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
146
|
+
|
|
147
|
+
export interface InitOutput {
|
|
148
|
+
readonly memory: WebAssembly.Memory;
|
|
149
|
+
readonly __wbg_engine_free: (a: number, b: number) => void;
|
|
150
|
+
readonly __wbg_session_free: (a: number, b: number) => void;
|
|
151
|
+
readonly engine_capture: (a: number) => number;
|
|
152
|
+
readonly engine_challenges: (a: number) => number;
|
|
153
|
+
readonly engine_new: (a: number, b: number, c: number, d: number) => void;
|
|
154
|
+
readonly engine_process: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
155
|
+
readonly engine_random: (a: number, b: number, c: number) => void;
|
|
156
|
+
readonly session_challenges: (a: number) => number;
|
|
157
|
+
readonly session_new: (a: number, b: number, c: number, d: number) => void;
|
|
158
|
+
readonly session_update: (a: number, b: number, c: number, d: number) => void;
|
|
159
|
+
readonly verifyFaceRecord: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
160
|
+
readonly verifyReceipt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
161
|
+
readonly verifyTicket: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
162
|
+
readonly version: (a: number) => void;
|
|
163
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
164
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
165
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
166
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
167
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
174
|
+
* a precompiled `WebAssembly.Module`.
|
|
175
|
+
*
|
|
176
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
177
|
+
*
|
|
178
|
+
* @returns {InitOutput}
|
|
179
|
+
*/
|
|
180
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
184
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
185
|
+
*
|
|
186
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
187
|
+
*
|
|
188
|
+
* @returns {Promise<InitOutput>}
|
|
189
|
+
*/
|
|
190
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/liveness_wasm.js
ADDED
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
/* @ts-self-types="./liveness_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Frames in, liveness verdict out. One engine is one attempt; create a new one per attempt.
|
|
5
|
+
* Model loading takes a moment, so create it before showing the camera.
|
|
6
|
+
*/
|
|
7
|
+
export class Engine {
|
|
8
|
+
static __wrap(ptr) {
|
|
9
|
+
const obj = Object.create(Engine.prototype);
|
|
10
|
+
obj.__wbg_ptr = ptr;
|
|
11
|
+
EngineFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
__destroy_into_raw() {
|
|
15
|
+
const ptr = this.__wbg_ptr;
|
|
16
|
+
this.__wbg_ptr = 0;
|
|
17
|
+
EngineFinalization.unregister(this);
|
|
18
|
+
return ptr;
|
|
19
|
+
}
|
|
20
|
+
free() {
|
|
21
|
+
const ptr = this.__destroy_into_raw();
|
|
22
|
+
wasm.__wbg_engine_free(ptr, 0);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The best face of the session so far, aligned for face matching, or null.
|
|
26
|
+
* On-device results are not tamper-proof: a server should produce the face record it trusts.
|
|
27
|
+
* @returns {FaceCapture | null}
|
|
28
|
+
*/
|
|
29
|
+
capture() {
|
|
30
|
+
const ret = wasm.engine_capture(this.__wbg_ptr);
|
|
31
|
+
return takeObject(ret);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @returns {Challenge[]}
|
|
35
|
+
*/
|
|
36
|
+
get challenges() {
|
|
37
|
+
const ret = wasm.engine_challenges(this.__wbg_ptr);
|
|
38
|
+
return takeObject(ret);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @param {Challenge[]} challenges
|
|
42
|
+
* @param {SessionOptions | undefined} options
|
|
43
|
+
*/
|
|
44
|
+
constructor(challenges, options) {
|
|
45
|
+
try {
|
|
46
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
47
|
+
const ptr0 = passArrayJsValueToWasm0(challenges, wasm.__wbindgen_export);
|
|
48
|
+
const len0 = WASM_VECTOR_LEN;
|
|
49
|
+
wasm.engine_new(retptr, ptr0, len0, addHeapObject(options));
|
|
50
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
51
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
52
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
53
|
+
if (r2) {
|
|
54
|
+
throw takeObject(r1);
|
|
55
|
+
}
|
|
56
|
+
this.__wbg_ptr = r0;
|
|
57
|
+
EngineFinalization.register(this, this.__wbg_ptr, this);
|
|
58
|
+
return this;
|
|
59
|
+
} finally {
|
|
60
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Processes one frame, e.g. `ctx.getImageData(...).data` with format 'rgba' (the default).
|
|
65
|
+
* @param {Uint8Array} pixels
|
|
66
|
+
* @param {FrameOptions} options
|
|
67
|
+
* @returns {FrameResult}
|
|
68
|
+
*/
|
|
69
|
+
process(pixels, options) {
|
|
70
|
+
try {
|
|
71
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
72
|
+
const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_export);
|
|
73
|
+
const len0 = WASM_VECTOR_LEN;
|
|
74
|
+
wasm.engine_process(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(options));
|
|
75
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
76
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
77
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
78
|
+
if (r2) {
|
|
79
|
+
throw takeObject(r1);
|
|
80
|
+
}
|
|
81
|
+
return takeObject(r0);
|
|
82
|
+
} finally {
|
|
83
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* `count` challenges in an order drawn from the browser's crypto randomness.
|
|
88
|
+
* @param {number} count
|
|
89
|
+
* @param {SessionOptions | undefined} options
|
|
90
|
+
* @returns {Engine}
|
|
91
|
+
*/
|
|
92
|
+
static random(count, options) {
|
|
93
|
+
try {
|
|
94
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
95
|
+
wasm.engine_random(retptr, count, addHeapObject(options));
|
|
96
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
97
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
98
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
99
|
+
if (r2) {
|
|
100
|
+
throw takeObject(r1);
|
|
101
|
+
}
|
|
102
|
+
return Engine.__wrap(r0);
|
|
103
|
+
} finally {
|
|
104
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The challenge flow from measurements you compute yourself (no image processing).
|
|
112
|
+
*/
|
|
113
|
+
export class Session {
|
|
114
|
+
__destroy_into_raw() {
|
|
115
|
+
const ptr = this.__wbg_ptr;
|
|
116
|
+
this.__wbg_ptr = 0;
|
|
117
|
+
SessionFinalization.unregister(this);
|
|
118
|
+
return ptr;
|
|
119
|
+
}
|
|
120
|
+
free() {
|
|
121
|
+
const ptr = this.__destroy_into_raw();
|
|
122
|
+
wasm.__wbg_session_free(ptr, 0);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @returns {Challenge[]}
|
|
126
|
+
*/
|
|
127
|
+
get challenges() {
|
|
128
|
+
const ret = wasm.session_challenges(this.__wbg_ptr);
|
|
129
|
+
return takeObject(ret);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @param {Challenge[]} challenges
|
|
133
|
+
* @param {SessionOptions | undefined} options
|
|
134
|
+
*/
|
|
135
|
+
constructor(challenges, options) {
|
|
136
|
+
try {
|
|
137
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
138
|
+
const ptr0 = passArrayJsValueToWasm0(challenges, wasm.__wbindgen_export);
|
|
139
|
+
const len0 = WASM_VECTOR_LEN;
|
|
140
|
+
wasm.session_new(retptr, ptr0, len0, addHeapObject(options));
|
|
141
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
142
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
143
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
144
|
+
if (r2) {
|
|
145
|
+
throw takeObject(r1);
|
|
146
|
+
}
|
|
147
|
+
this.__wbg_ptr = r0;
|
|
148
|
+
SessionFinalization.register(this, this.__wbg_ptr, this);
|
|
149
|
+
return this;
|
|
150
|
+
} finally {
|
|
151
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* One frame: faces in view and the main face's measurements, if known.
|
|
156
|
+
* @param {number} timestamp_ms
|
|
157
|
+
* @param {{ faceCount?: number; ear?: number; mouth?: number; yaw?: number } | undefined} observation
|
|
158
|
+
* @returns {FrameResult}
|
|
159
|
+
*/
|
|
160
|
+
update(timestamp_ms, observation) {
|
|
161
|
+
try {
|
|
162
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
163
|
+
wasm.session_update(retptr, this.__wbg_ptr, timestamp_ms, addHeapObject(observation));
|
|
164
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
165
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
166
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
167
|
+
if (r2) {
|
|
168
|
+
throw takeObject(r1);
|
|
169
|
+
}
|
|
170
|
+
return takeObject(r0);
|
|
171
|
+
} finally {
|
|
172
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (Symbol.dispose) Session.prototype[Symbol.dispose] = Session.prototype.free;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* For the face-matching service: checks the receipt, that the session passed, and that
|
|
180
|
+
* `facePng` is exactly the face record it vouches for; throws otherwise.
|
|
181
|
+
* @param {string} token
|
|
182
|
+
* @param {Uint8Array} public_key
|
|
183
|
+
* @param {Uint8Array} face_png
|
|
184
|
+
* @param {number | null} [now]
|
|
185
|
+
* @returns {Receipt}
|
|
186
|
+
*/
|
|
187
|
+
export function verifyFaceRecord(token, public_key, face_png, now) {
|
|
188
|
+
try {
|
|
189
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
190
|
+
const ptr0 = passStringToWasm0(token, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
191
|
+
const len0 = WASM_VECTOR_LEN;
|
|
192
|
+
const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_export);
|
|
193
|
+
const len1 = WASM_VECTOR_LEN;
|
|
194
|
+
const ptr2 = passArray8ToWasm0(face_png, wasm.__wbindgen_export);
|
|
195
|
+
const len2 = WASM_VECTOR_LEN;
|
|
196
|
+
wasm.verifyFaceRecord(retptr, ptr0, len0, ptr1, len1, ptr2, len2, !isLikeNone(now), isLikeNone(now) ? 0 : now);
|
|
197
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
198
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
199
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
200
|
+
if (r2) {
|
|
201
|
+
throw takeObject(r1);
|
|
202
|
+
}
|
|
203
|
+
return takeObject(r0);
|
|
204
|
+
} finally {
|
|
205
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Checks a receipt (signature and expiry); throws if invalid.
|
|
211
|
+
* @param {string} token
|
|
212
|
+
* @param {Uint8Array} public_key
|
|
213
|
+
* @param {number | null} [now]
|
|
214
|
+
* @returns {Receipt}
|
|
215
|
+
*/
|
|
216
|
+
export function verifyReceipt(token, public_key, now) {
|
|
217
|
+
try {
|
|
218
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
219
|
+
const ptr0 = passStringToWasm0(token, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
220
|
+
const len0 = WASM_VECTOR_LEN;
|
|
221
|
+
const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_export);
|
|
222
|
+
const len1 = WASM_VECTOR_LEN;
|
|
223
|
+
wasm.verifyReceipt(retptr, ptr0, len0, ptr1, len1, !isLikeNone(now), isLikeNone(now) ? 0 : now);
|
|
224
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
225
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
226
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
227
|
+
if (r2) {
|
|
228
|
+
throw takeObject(r1);
|
|
229
|
+
}
|
|
230
|
+
return takeObject(r0);
|
|
231
|
+
} finally {
|
|
232
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Checks a ticket from your server (signature and expiry); throws if invalid.
|
|
238
|
+
* @param {string} token
|
|
239
|
+
* @param {Uint8Array} public_key
|
|
240
|
+
* @param {number | null} [now]
|
|
241
|
+
* @returns {Ticket}
|
|
242
|
+
*/
|
|
243
|
+
export function verifyTicket(token, public_key, now) {
|
|
244
|
+
try {
|
|
245
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
246
|
+
const ptr0 = passStringToWasm0(token, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
247
|
+
const len0 = WASM_VECTOR_LEN;
|
|
248
|
+
const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_export);
|
|
249
|
+
const len1 = WASM_VECTOR_LEN;
|
|
250
|
+
wasm.verifyTicket(retptr, ptr0, len0, ptr1, len1, !isLikeNone(now), isLikeNone(now) ? 0 : now);
|
|
251
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
252
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
253
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
254
|
+
if (r2) {
|
|
255
|
+
throw takeObject(r1);
|
|
256
|
+
}
|
|
257
|
+
return takeObject(r0);
|
|
258
|
+
} finally {
|
|
259
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @returns {string}
|
|
265
|
+
*/
|
|
266
|
+
export function version() {
|
|
267
|
+
let deferred1_0;
|
|
268
|
+
let deferred1_1;
|
|
269
|
+
try {
|
|
270
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
271
|
+
wasm.version(retptr);
|
|
272
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
273
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
274
|
+
deferred1_0 = r0;
|
|
275
|
+
deferred1_1 = r1;
|
|
276
|
+
return getStringFromWasm0(r0, r1);
|
|
277
|
+
} finally {
|
|
278
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
279
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function __wbg_get_imports() {
|
|
283
|
+
const import0 = {
|
|
284
|
+
__proto__: null,
|
|
285
|
+
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
|
|
286
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
287
|
+
return addHeapObject(ret);
|
|
288
|
+
},
|
|
289
|
+
__wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
|
|
290
|
+
const v = getObject(arg0);
|
|
291
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
292
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
293
|
+
},
|
|
294
|
+
__wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
|
|
295
|
+
const ret = debugString(getObject(arg1));
|
|
296
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
297
|
+
const len1 = WASM_VECTOR_LEN;
|
|
298
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
299
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
300
|
+
},
|
|
301
|
+
__wbg___wbindgen_is_null_e343b7d08827ba72: function(arg0) {
|
|
302
|
+
const ret = getObject(arg0) === null;
|
|
303
|
+
return ret;
|
|
304
|
+
},
|
|
305
|
+
__wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
|
|
306
|
+
const ret = getObject(arg0) === undefined;
|
|
307
|
+
return ret;
|
|
308
|
+
},
|
|
309
|
+
__wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
|
|
310
|
+
const obj = getObject(arg1);
|
|
311
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
312
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
313
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
314
|
+
},
|
|
315
|
+
__wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
|
|
316
|
+
const obj = getObject(arg1);
|
|
317
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
318
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
319
|
+
var len1 = WASM_VECTOR_LEN;
|
|
320
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
321
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
322
|
+
},
|
|
323
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
324
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
325
|
+
},
|
|
326
|
+
__wbg_getRandomValues_436a51d0629d84e1: function() { return handleError(function (arg0, arg1) {
|
|
327
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
328
|
+
}, arguments); },
|
|
329
|
+
__wbg_getRandomValues_a608c4436c19407a: function() { return handleError(function (arg0, arg1) {
|
|
330
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
331
|
+
}, arguments); },
|
|
332
|
+
__wbg_get_31af05bd4842a84f: function() { return handleError(function (arg0, arg1) {
|
|
333
|
+
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
|
334
|
+
return addHeapObject(ret);
|
|
335
|
+
}, arguments); },
|
|
336
|
+
__wbg_new_617a8cdb8bb1130e: function() {
|
|
337
|
+
const ret = new Object();
|
|
338
|
+
return addHeapObject(ret);
|
|
339
|
+
},
|
|
340
|
+
__wbg_new_ee2291f50781bf1d: function() {
|
|
341
|
+
const ret = new Array();
|
|
342
|
+
return addHeapObject(ret);
|
|
343
|
+
},
|
|
344
|
+
__wbg_new_from_slice_9a868026ffa4208a: function(arg0, arg1) {
|
|
345
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
346
|
+
return addHeapObject(ret);
|
|
347
|
+
},
|
|
348
|
+
__wbg_now_aa4ccb83129e9e55: function() {
|
|
349
|
+
const ret = Date.now();
|
|
350
|
+
return ret;
|
|
351
|
+
},
|
|
352
|
+
__wbg_of_20798cb14708764f: function(arg0, arg1) {
|
|
353
|
+
const ret = Array.of(getObject(arg0), getObject(arg1));
|
|
354
|
+
return addHeapObject(ret);
|
|
355
|
+
},
|
|
356
|
+
__wbg_push_2baf45db356cf468: function(arg0, arg1) {
|
|
357
|
+
const ret = getObject(arg0).push(getObject(arg1));
|
|
358
|
+
return ret;
|
|
359
|
+
},
|
|
360
|
+
__wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
|
|
361
|
+
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
362
|
+
return ret;
|
|
363
|
+
}, arguments); },
|
|
364
|
+
__wbindgen_generic_0000000000000001: function(arg0) {
|
|
365
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
366
|
+
const ret = arg0;
|
|
367
|
+
return addHeapObject(ret);
|
|
368
|
+
},
|
|
369
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
370
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
371
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
372
|
+
return addHeapObject(ret);
|
|
373
|
+
},
|
|
374
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
375
|
+
takeObject(arg0);
|
|
376
|
+
},
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
__proto__: null,
|
|
380
|
+
"./liveness_wasm_bg.js": import0,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const EngineFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
385
|
+
? { register: () => {}, unregister: () => {} }
|
|
386
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_engine_free(ptr, 1));
|
|
387
|
+
const SessionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
388
|
+
? { register: () => {}, unregister: () => {} }
|
|
389
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_session_free(ptr, 1));
|
|
390
|
+
|
|
391
|
+
function addHeapObject(obj) {
|
|
392
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
393
|
+
const idx = heap_next;
|
|
394
|
+
heap_next = heap[idx];
|
|
395
|
+
|
|
396
|
+
heap[idx] = obj;
|
|
397
|
+
return idx;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function debugString(val) {
|
|
401
|
+
// primitive types
|
|
402
|
+
const type = typeof val;
|
|
403
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
404
|
+
return `${val}`;
|
|
405
|
+
}
|
|
406
|
+
if (type == 'string') {
|
|
407
|
+
return `"${val}"`;
|
|
408
|
+
}
|
|
409
|
+
if (type == 'symbol') {
|
|
410
|
+
const description = val.description;
|
|
411
|
+
if (description == null) {
|
|
412
|
+
return 'Symbol';
|
|
413
|
+
} else {
|
|
414
|
+
return `Symbol(${description})`;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (type == 'function') {
|
|
418
|
+
const name = val.name;
|
|
419
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
420
|
+
return `Function(${name})`;
|
|
421
|
+
} else {
|
|
422
|
+
return 'Function';
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
// objects
|
|
426
|
+
if (Array.isArray(val)) {
|
|
427
|
+
const length = val.length;
|
|
428
|
+
let debug = '[';
|
|
429
|
+
if (length > 0) {
|
|
430
|
+
debug += debugString(val[0]);
|
|
431
|
+
}
|
|
432
|
+
for(let i = 1; i < length; i++) {
|
|
433
|
+
debug += ', ' + debugString(val[i]);
|
|
434
|
+
}
|
|
435
|
+
debug += ']';
|
|
436
|
+
return debug;
|
|
437
|
+
}
|
|
438
|
+
// Test for built-in
|
|
439
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
440
|
+
let className;
|
|
441
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
442
|
+
className = builtInMatches[1];
|
|
443
|
+
} else {
|
|
444
|
+
// Failed to match the standard '[object ClassName]'
|
|
445
|
+
return toString.call(val);
|
|
446
|
+
}
|
|
447
|
+
if (className == 'Object') {
|
|
448
|
+
// we're a user defined class or Object
|
|
449
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
450
|
+
// easier than looping through ownProperties of `val`.
|
|
451
|
+
try {
|
|
452
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
453
|
+
} catch (_) {
|
|
454
|
+
return 'Object';
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
// errors
|
|
458
|
+
if (val instanceof Error) {
|
|
459
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
460
|
+
}
|
|
461
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
462
|
+
return className;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function dropObject(idx) {
|
|
466
|
+
if (idx < 1028) return;
|
|
467
|
+
heap[idx] = heap_next;
|
|
468
|
+
heap_next = idx;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
472
|
+
ptr = ptr >>> 0;
|
|
473
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
let cachedDataViewMemory0 = null;
|
|
477
|
+
function getDataViewMemory0() {
|
|
478
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
479
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
480
|
+
}
|
|
481
|
+
return cachedDataViewMemory0;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function getStringFromWasm0(ptr, len) {
|
|
485
|
+
return decodeText(ptr >>> 0, len);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
let cachedUint8ArrayMemory0 = null;
|
|
489
|
+
function getUint8ArrayMemory0() {
|
|
490
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
491
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
492
|
+
}
|
|
493
|
+
return cachedUint8ArrayMemory0;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function getObject(idx) { return heap[idx]; }
|
|
497
|
+
|
|
498
|
+
function handleError(f, args) {
|
|
499
|
+
try {
|
|
500
|
+
return f.apply(this, args);
|
|
501
|
+
} catch (e) {
|
|
502
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
let heap = new Array(1024).fill(undefined);
|
|
507
|
+
heap.push(undefined, null, true, false);
|
|
508
|
+
|
|
509
|
+
let heap_next = heap.length;
|
|
510
|
+
|
|
511
|
+
function isLikeNone(x) {
|
|
512
|
+
return x === undefined || x === null;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
516
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
517
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
518
|
+
WASM_VECTOR_LEN = arg.length;
|
|
519
|
+
return ptr;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function passArrayJsValueToWasm0(array, malloc) {
|
|
523
|
+
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
524
|
+
const mem = getDataViewMemory0();
|
|
525
|
+
for (let i = 0; i < array.length; i++) {
|
|
526
|
+
mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
|
|
527
|
+
}
|
|
528
|
+
WASM_VECTOR_LEN = array.length;
|
|
529
|
+
return ptr;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
533
|
+
if (realloc === undefined) {
|
|
534
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
535
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
536
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
537
|
+
WASM_VECTOR_LEN = buf.length;
|
|
538
|
+
return ptr;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
let len = arg.length;
|
|
542
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
543
|
+
|
|
544
|
+
const mem = getUint8ArrayMemory0();
|
|
545
|
+
|
|
546
|
+
let offset = 0;
|
|
547
|
+
|
|
548
|
+
for (; offset < len; offset++) {
|
|
549
|
+
const code = arg.charCodeAt(offset);
|
|
550
|
+
if (code > 0x7F) break;
|
|
551
|
+
mem[ptr + offset] = code;
|
|
552
|
+
}
|
|
553
|
+
if (offset !== len) {
|
|
554
|
+
if (offset !== 0) {
|
|
555
|
+
arg = arg.slice(offset);
|
|
556
|
+
}
|
|
557
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
558
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
559
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
560
|
+
|
|
561
|
+
offset += ret.written;
|
|
562
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
WASM_VECTOR_LEN = offset;
|
|
566
|
+
return ptr;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function takeObject(idx) {
|
|
570
|
+
const ret = getObject(idx);
|
|
571
|
+
dropObject(idx);
|
|
572
|
+
return ret;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
576
|
+
cachedTextDecoder.decode();
|
|
577
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
578
|
+
let numBytesDecoded = 0;
|
|
579
|
+
function decodeText(ptr, len) {
|
|
580
|
+
numBytesDecoded += len;
|
|
581
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
582
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
583
|
+
cachedTextDecoder.decode();
|
|
584
|
+
numBytesDecoded = len;
|
|
585
|
+
}
|
|
586
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const cachedTextEncoder = new TextEncoder();
|
|
590
|
+
|
|
591
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
592
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
593
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
594
|
+
view.set(buf);
|
|
595
|
+
return {
|
|
596
|
+
read: arg.length,
|
|
597
|
+
written: buf.length
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
let WASM_VECTOR_LEN = 0;
|
|
603
|
+
|
|
604
|
+
let wasmModule, wasmInstance, wasm;
|
|
605
|
+
function __wbg_finalize_init(instance, module) {
|
|
606
|
+
wasmInstance = instance;
|
|
607
|
+
wasm = instance.exports;
|
|
608
|
+
wasmModule = module;
|
|
609
|
+
cachedDataViewMemory0 = null;
|
|
610
|
+
cachedUint8ArrayMemory0 = null;
|
|
611
|
+
return wasm;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
async function __wbg_load(module, imports) {
|
|
615
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
616
|
+
if (!module.ok) {
|
|
617
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
621
|
+
try {
|
|
622
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
623
|
+
} catch (e) {
|
|
624
|
+
const validResponse = expectedResponseType(module.type);
|
|
625
|
+
|
|
626
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
627
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
628
|
+
|
|
629
|
+
} else { throw e; }
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const bytes = await module.arrayBuffer();
|
|
634
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
635
|
+
} else {
|
|
636
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
637
|
+
|
|
638
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
639
|
+
return { instance, module };
|
|
640
|
+
} else {
|
|
641
|
+
return instance;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function expectedResponseType(type) {
|
|
646
|
+
switch (type) {
|
|
647
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
648
|
+
}
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function initSync(module) {
|
|
654
|
+
if (wasm !== undefined) return wasm;
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
if (module !== undefined) {
|
|
658
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
659
|
+
({module} = module)
|
|
660
|
+
} else {
|
|
661
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const imports = __wbg_get_imports();
|
|
666
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
667
|
+
module = new WebAssembly.Module(module);
|
|
668
|
+
}
|
|
669
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
670
|
+
return __wbg_finalize_init(instance, module);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
async function __wbg_init(module_or_path) {
|
|
674
|
+
if (wasm !== undefined) return wasm;
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
if (module_or_path !== undefined) {
|
|
678
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
679
|
+
({module_or_path} = module_or_path)
|
|
680
|
+
} else {
|
|
681
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (module_or_path === undefined) {
|
|
686
|
+
module_or_path = new URL('liveness_wasm_bg.wasm', import.meta.url);
|
|
687
|
+
}
|
|
688
|
+
const imports = __wbg_get_imports();
|
|
689
|
+
|
|
690
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
691
|
+
module_or_path = fetch(module_or_path);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
695
|
+
|
|
696
|
+
return __wbg_finalize_init(instance, module);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_engine_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_session_free: (a: number, b: number) => void;
|
|
6
|
+
export const engine_capture: (a: number) => number;
|
|
7
|
+
export const engine_challenges: (a: number) => number;
|
|
8
|
+
export const engine_new: (a: number, b: number, c: number, d: number) => void;
|
|
9
|
+
export const engine_process: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
10
|
+
export const engine_random: (a: number, b: number, c: number) => void;
|
|
11
|
+
export const session_challenges: (a: number) => number;
|
|
12
|
+
export const session_new: (a: number, b: number, c: number, d: number) => void;
|
|
13
|
+
export const session_update: (a: number, b: number, c: number, d: number) => void;
|
|
14
|
+
export const verifyFaceRecord: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
15
|
+
export const verifyReceipt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
16
|
+
export const verifyTicket: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
17
|
+
export const version: (a: number) => void;
|
|
18
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
19
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
20
|
+
export const __wbindgen_export3: (a: number) => void;
|
|
21
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
22
|
+
export const __wbindgen_export4: (a: number, b: number, c: number) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "faceliveness-web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "On-device face liveness checks in the browser (WebAssembly): blink, head turn, mouth open, face record for matching",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "liveness_wasm.js",
|
|
7
|
+
"module": "liveness_wasm.js",
|
|
8
|
+
"types": "liveness_wasm.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"liveness_wasm.js",
|
|
11
|
+
"liveness_wasm.d.ts",
|
|
12
|
+
"liveness_wasm_bg.wasm",
|
|
13
|
+
"liveness_wasm_bg.wasm.d.ts",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"keywords": ["face", "liveness", "anti-spoofing", "biometrics", "kyc", "webassembly", "wasm"],
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/wiseman-umanah/Face-Liveness.git",
|
|
22
|
+
"directory": "crates/liveness-wasm"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
}
|
|
27
|
+
}
|