veryfi-lens-wasm 1.0.8 → 1.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/.prettierrc +3 -0
- package/README.md +215 -34
- package/index.d.ts +3 -3
- package/package.json +6 -2
- package/setup.mjs +41 -36
- package/src/device-uuid.js +912 -957
- package/src/feature-detect.js +1 -0
- package/src/fingerprint-id.js +2095 -2287
- package/src/wasm/wasm.js +229 -207
- package/veryfi-lens.js +69 -283
- package/src/lens-wasm.js +0 -730
package/.prettierrc
ADDED
package/README.md
CHANGED
|
@@ -1,36 +1,148 @@
|
|
|
1
|
+
<img src="https://user-images.githubusercontent.com/30125790/212157461-58bdc714-2f89-44c2-8e4d-d42bee74854e.png#gh-dark-mode-only" width="200">
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
<img src="https://user-images.githubusercontent.com/30125790/212157486-bfd08c5d-9337-4b78-be6f-230dc63838ba.png#gh-light-mode-only" width="200">
|
|
4
|
+
|
|
5
|
+
# Veryfi Lens for Web WASM SDK
|
|
6
|
+
|
|
7
|
+
Veryfi Lens for Web SDK is a framework for your web app to give it document capture superpowers in minutes.
|
|
8
|
+
|
|
9
|
+
Lens follows a client-server architecture where the server is for validating your client and getting session key and the client side is for displaying and showing Lens components for capturing documents.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
There are two ways of using Lens for Web:
|
|
13
|
+
1. WebSocket (Only usual receipts, easy to install, slower than WASM)
|
|
14
|
+
2. WASM (Usual and Long Receipts, very fast, some devices are not supported)
|
|
15
|
+
|
|
16
|
+
# WebSocket
|
|
17
|
+
1. Import package `import VeryfiLens from 'veryfi-lens-wasm'`
|
|
18
|
+
or `const lens = require('veryfi-lens-wasm').default` inside `useEffect` for next.js
|
|
19
|
+
2. Add `id='veryfi-container'` to a div you want lens to appear (it should have full height and hidden overflow)
|
|
20
|
+
|
|
21
|
+
For usual receipt (Next.Js example)
|
|
22
|
+
```
|
|
23
|
+
const [veryfiLens, setVeryfiLens] = useState<VeryfiLens | null>(null);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
let intervalRef: number | undefined;
|
|
27
|
+
if (typeof window !== 'undefined') {
|
|
28
|
+
const startLens = async () => {
|
|
29
|
+
const lens = require('../../utils/lens-web-sdk/veryfi-lens').default;
|
|
30
|
+
lens.init(sessionToken);
|
|
31
|
+
setVeryfiLens(lens);
|
|
32
|
+
intervalRef = window.setInterval(() => {
|
|
33
|
+
setSocketStatusColor(lens.getSocketStatusColor());
|
|
34
|
+
}, SOCKET_STATUS_UPDATE_INTERVAL);
|
|
35
|
+
}
|
|
36
|
+
startLens();
|
|
37
|
+
}
|
|
38
|
+
return () => {
|
|
39
|
+
clearInterval(intervalRef);
|
|
40
|
+
};
|
|
41
|
+
}, [sessionToken]);
|
|
42
|
+
|
|
43
|
+
const takePhoto = () => {
|
|
44
|
+
if (veryfiLens) {
|
|
45
|
+
veryfiLens.capture(setImage, setIsEditing)
|
|
46
|
+
} else {
|
|
47
|
+
setError('veryfiLens is not initialized');
|
|
48
|
+
}
|
|
49
|
+
};
|
|
18
50
|
```
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
|
|
52
|
+
# WASM
|
|
53
|
+
**_You can skip first step and copy wasm folder from package directory manually if you want to do so_.**
|
|
54
|
+
|
|
55
|
+
1. run `npm exec veryfi-lens-wasm-setup` and provide it with path to directory where
|
|
56
|
+
**they have to be accessible from your project's entry point with relative paths** (for next.js `public/wasm`)
|
|
57
|
+
2. Import package `import VeryfiLens from 'veryfi-lens-wasm'`
|
|
58
|
+
or `const lens = require('veryfi-lens-wasm').default` inside `useEffect` for next.js
|
|
59
|
+
3. Add `id='veryfi-container'` to a div you want lens to appear (it should have full height and hidden overflow)
|
|
60
|
+
|
|
61
|
+
For usual receipt (Next.Js example)
|
|
62
|
+
|
|
21
63
|
```
|
|
22
|
-
const
|
|
23
|
-
|
|
64
|
+
const [veryfiLens, setVeryfiLens] = useState<{
|
|
65
|
+
setUserAgent: (arg0: string) => void;
|
|
66
|
+
initWasm: (arg0: string) => void;
|
|
67
|
+
startCameraWasm: () => void;
|
|
68
|
+
captureWasm: (
|
|
69
|
+
arg0: React.Dispatch<React.SetStateAction<string>>,
|
|
70
|
+
arg1: React.Dispatch<React.SetStateAction<boolean>>
|
|
71
|
+
) => void;
|
|
72
|
+
} | null>(null);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const startWasm = async () => {
|
|
76
|
+
if (typeof window !== 'undefined') {
|
|
77
|
+
const lens = require('veryfi-lens-wasm').default;
|
|
78
|
+
lens.setUserAgent(navigator.userAgent);
|
|
79
|
+
await lens.initWasm(sessionToken);
|
|
80
|
+
setVeryfiLens(lens);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
startWasm()
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
const takePhoto = () => {
|
|
87
|
+
if (veryfiLens) {
|
|
88
|
+
veryfiLens.captureWasm(setImage, setIsEditing)
|
|
89
|
+
} else {
|
|
90
|
+
console.log('veryfiLens is not initialized')
|
|
91
|
+
}
|
|
92
|
+
};
|
|
24
93
|
// setImage is cropped image setter(for example react's useState hook), returns string
|
|
25
94
|
// setIsEditing returns `true` if image was succesfully cropped (we use it to change screens)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
For Long receipt (Next.Js example)
|
|
98
|
+
```
|
|
99
|
+
const [veryfiLens, setVeryfiLens] = useState<{
|
|
100
|
+
startStitching(): void;
|
|
101
|
+
setUserAgent: (arg0: string) => void;
|
|
102
|
+
initWasmLong: (arg0: string) => void;
|
|
103
|
+
startCameraWasm: () => void;
|
|
104
|
+
captureLong: (
|
|
105
|
+
arg0: React.Dispatch<React.SetStateAction<string>>,
|
|
106
|
+
arg1: React.Dispatch<React.SetStateAction<boolean>>
|
|
107
|
+
) => void;
|
|
108
|
+
} | null>(null);
|
|
109
|
+
const [isStitching, setIsStitching] = useState(false)
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const startWasm = async () => {
|
|
113
|
+
if (typeof window !== 'undefined') {
|
|
114
|
+
const lens = require('veryfi-lens-wasm').default;
|
|
115
|
+
lens.setUserAgent(navigator.userAgent);
|
|
116
|
+
await lens.initWasmLong(sessionToken);
|
|
117
|
+
setVeryfiLens(lens);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
startWasm()
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
// Start button
|
|
124
|
+
const startStitching = () => {
|
|
125
|
+
if (veryfiLens) {
|
|
126
|
+
veryfiLens.startStitching();
|
|
127
|
+
setIsStitching(true);
|
|
128
|
+
} else {
|
|
129
|
+
console.log("veryfiLens is not initialized");
|
|
130
|
+
}
|
|
26
131
|
};
|
|
27
132
|
|
|
133
|
+
// Stop button
|
|
134
|
+
const stopStitching = () => {
|
|
135
|
+
if (veryfiLens) {
|
|
136
|
+
veryfiLens.captureLong(setImage, setIsEditing);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
28
139
|
```
|
|
29
140
|
|
|
30
|
-
To use wasm in dev environment, you have to use https and ssl
|
|
31
|
-
|
|
141
|
+
To use wasm in dev environment, you have to use https and ssl
|
|
142
|
+
If using Next.js add following to next.config.js:
|
|
143
|
+
|
|
32
144
|
```
|
|
33
|
-
async headers() {
|
|
145
|
+
async headers() {
|
|
34
146
|
return [
|
|
35
147
|
{
|
|
36
148
|
source: '/(.*)',
|
|
@@ -47,19 +159,20 @@ async headers() {
|
|
|
47
159
|
}
|
|
48
160
|
]
|
|
49
161
|
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return config;
|
|
56
|
-
},
|
|
57
|
-
```
|
|
58
|
-
This to vite.config.js (if using vite and vue)
|
|
162
|
+
|
|
163
|
+
webpack: (config) => {
|
|
164
|
+
config.resolve.fallback = { fs: false, path:false, "crypto": false };
|
|
165
|
+
return config;
|
|
166
|
+
},
|
|
59
167
|
```
|
|
60
|
-
|
|
168
|
+
|
|
169
|
+
If using Vite and Vue:
|
|
170
|
+
1. install serve `npm i serve`
|
|
171
|
+
2. Add following to your vite config
|
|
172
|
+
```
|
|
173
|
+
server: {
|
|
61
174
|
https: {
|
|
62
|
-
key: fs.readFileSync(path.resolve(__dirname, 'localhost-key.pem')), //path to your
|
|
175
|
+
key: fs.readFileSync(path.resolve(__dirname, 'localhost-key.pem')), //path to your cert
|
|
63
176
|
cert: fs.readFileSync(path.resolve(__dirname, 'localhost.pem')),},
|
|
64
177
|
proxy: {},
|
|
65
178
|
hmr: {
|
|
@@ -79,3 +192,71 @@ server: {
|
|
|
79
192
|
}
|
|
80
193
|
```
|
|
81
194
|
|
|
195
|
+
3. `serve -s dist -p 3000`
|
|
196
|
+
|
|
197
|
+
If using Angular:
|
|
198
|
+
|
|
199
|
+
1. You can copy files to `src` directory, then add it to assets in `angular.json`
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
"assets": [
|
|
203
|
+
"src/favicon.ico",
|
|
204
|
+
"src/assets",
|
|
205
|
+
"src/wasm"
|
|
206
|
+
],
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
2. for dev environment you can use node server (server file has to be in the same folder with your index.html)
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
const http = require("http");
|
|
213
|
+
const fs = require("fs").promises;
|
|
214
|
+
const host = "localhost";
|
|
215
|
+
const port = 3000;
|
|
216
|
+
const typeMap = {
|
|
217
|
+
html: "text/html",
|
|
218
|
+
css: "text/css",
|
|
219
|
+
js: "text/javascript",
|
|
220
|
+
wasm: "application/wasm",
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const requestListener = function (req, res) {
|
|
224
|
+
let url = req.url;
|
|
225
|
+
if (url === "/") url = "/index.html";
|
|
226
|
+
for (const [key, value] of Object.entries(typeMap)) {
|
|
227
|
+
if (url.endsWith(key)) res.setHeader("Content-Type", value);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fs.readFile(__dirname + url)
|
|
231
|
+
.then((contents) => {
|
|
232
|
+
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
|
233
|
+
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
|
|
234
|
+
res.writeHead(200);
|
|
235
|
+
res.end(contents);
|
|
236
|
+
})
|
|
237
|
+
.catch((err) => {
|
|
238
|
+
console.log("error: ", url);
|
|
239
|
+
console.log("Error", err.stack);
|
|
240
|
+
console.log("Error", err.name);
|
|
241
|
+
console.log("Error", err.message);
|
|
242
|
+
res.writeHead(500);
|
|
243
|
+
return;
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const server = http.createServer(requestListener);
|
|
248
|
+
server.listen(port, host, () => {
|
|
249
|
+
console.log(`Server is running on http://${host}:${port}`);
|
|
250
|
+
});
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
1. run it with `node server.js`
|
|
254
|
+
2.`npx local-ssl-proxy --key localhost-key.pem --cert localhost.pem --source 3001 --target 3000` (You will need local certificate, possible to make with `mkcert`)
|
|
255
|
+
3. Go to `https://localhost:3001`
|
|
256
|
+
|
|
257
|
+
For production build (any framework) or if you prefer using build instead of dev environment `wasm` directory should be in your `dist` directory (near your built index.html) and your server should use **https and ssl** and include following headers:
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
'Cross-Origin-Opener-Policy', 'same-origin';
|
|
261
|
+
'Cross-Origin-Embedder-Policy', 'require-corp';
|
|
262
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ declare module 'veryfi-lens-wasm'
|
|
|
2
2
|
declare module 'veryfi-lens-wasm/veryfi-lens'
|
|
3
3
|
declare module 'veryfi-lens-wasm/device-uuid'
|
|
4
4
|
declare module 'veryfi-lens-wasm/fingerprint-id'
|
|
5
|
-
declare module '
|
|
6
|
-
declare module '
|
|
7
|
-
declare module '
|
|
5
|
+
declare module 'veryfi-lens-wasm/lens-wasm'
|
|
6
|
+
declare module 'veryfi-lens-wasm/opencv'
|
|
7
|
+
declare module 'veryfi-lens-wasm/feature-detect'
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "veryfi-lens-wasm",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Lens For Web SDK with WASM",
|
|
5
5
|
"main": "veryfi-lens.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/veryfi/veryfi-lens-wasm"
|
|
9
|
+
},
|
|
6
10
|
"scripts": {
|
|
7
11
|
"setup": "node setup.mjs"
|
|
8
12
|
},
|
|
9
13
|
"bin": {
|
|
10
14
|
"veryfi-lens-wasm-setup": "./setup.sh"
|
|
11
15
|
},
|
|
12
|
-
"author": "",
|
|
16
|
+
"author": "George Veryfi",
|
|
13
17
|
"license": "ISC",
|
|
14
18
|
"dependencies": {
|
|
15
19
|
"fs-extra": "^11.1.1",
|
package/setup.mjs
CHANGED
|
@@ -1,42 +1,47 @@
|
|
|
1
|
-
import inquirer from
|
|
2
|
-
import path from
|
|
3
|
-
import fs from
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
4
|
|
|
5
|
-
const defaultPath = path.join(process.cwd()
|
|
5
|
+
const defaultPath = path.join(process.cwd());
|
|
6
6
|
|
|
7
7
|
const questions = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
{
|
|
9
|
+
type: "input",
|
|
10
|
+
name: "targetPath",
|
|
11
|
+
message: `Enter the path where you want to copy WASM files (They have to be accessible to the browser with relative path)
|
|
12
|
+
current: ${defaultPath} + /public/wasm (you are changing what goes after +):`,
|
|
13
|
+
default: defaultPath + "/public/wasm",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: "confirm",
|
|
17
|
+
name: "confirmCopy",
|
|
18
|
+
message: "Do you want to proceed with the copying?",
|
|
19
|
+
default: true,
|
|
20
|
+
},
|
|
20
21
|
];
|
|
21
22
|
|
|
22
|
-
inquirer
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
inquirer
|
|
24
|
+
.prompt(questions)
|
|
25
|
+
.then((answers) => {
|
|
26
|
+
if (answers.confirmCopy) {
|
|
27
|
+
const sourcePath = path.join(
|
|
28
|
+
process.cwd(),
|
|
29
|
+
"node_modules/veryfi-lens-wasm/src/wasm"
|
|
30
|
+
);
|
|
31
|
+
const targetPath = path.isAbsolute(answers.targetPath)
|
|
32
|
+
? answers.targetPath
|
|
33
|
+
: path.join(process.cwd(), answers.targetPath);
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
fs.copySync(sourcePath, targetPath, { overwrite: true });
|
|
36
|
+
console.log("WASM files copied successfully.");
|
|
37
|
+
} else {
|
|
38
|
+
console.log("WASM files were not copied.");
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
.catch((error) => {
|
|
42
|
+
if (error.isTtyError) {
|
|
43
|
+
console.error("Prompt couldn't be rendered in the current environment.");
|
|
44
|
+
} else {
|
|
45
|
+
console.error("An error occurred:", error);
|
|
46
|
+
}
|
|
47
|
+
});
|