veryfi-lens-wasm 2.0.0 → 2.0.2
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/components/croppedImage.js +0 -1
- package/components/overlayContainer.js +0 -1
- package/components/video.js +2 -2
- package/package.json +1 -1
- package/veryfi-lens.js +154 -81
package/components/video.js
CHANGED
|
@@ -20,7 +20,7 @@ export const createVideo = (container) => {
|
|
|
20
20
|
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
|
21
21
|
|
|
22
22
|
if (!isMobile) {
|
|
23
|
-
console.log('desktop');
|
|
23
|
+
// console.log('desktop');
|
|
24
24
|
video.style.position = 'absolute';
|
|
25
25
|
video.style.width = '100%';
|
|
26
26
|
video.style.height = 'auto';
|
|
@@ -28,7 +28,7 @@ export const createVideo = (container) => {
|
|
|
28
28
|
video.style.top = '';
|
|
29
29
|
video.style.left = '';
|
|
30
30
|
} else {
|
|
31
|
-
console.log('mobile');
|
|
31
|
+
// console.log('mobile');
|
|
32
32
|
video.style.position = 'fixed';
|
|
33
33
|
video.style.top = '0';
|
|
34
34
|
video.style.left = '0';
|
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -28,12 +28,7 @@ import { createCardDataButton } from './components/cardDataButton.js';
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
const VeryfiLens = (function () {
|
|
31
|
-
const DEFAULT_BOX_COlOR = "rgba(84, 192, 139, 0.6)";
|
|
32
|
-
const INTERVAL = 250;
|
|
33
|
-
// const VALIDATE_URL = "https://lens.veryfi.com/rest/validate_partner";
|
|
34
|
-
const VALIDATE_URL = "https://lens.veryfi.com/rest/validate_partner";
|
|
35
31
|
let wasmWrapper = null;
|
|
36
|
-
let creditCardStatus = "AutoCaptureResultWaiting";
|
|
37
32
|
|
|
38
33
|
const state = {
|
|
39
34
|
// Camera and processing state
|
|
@@ -358,6 +353,11 @@ const VeryfiLens = (function () {
|
|
|
358
353
|
};
|
|
359
354
|
|
|
360
355
|
const sendWasm = async (mode) => {
|
|
356
|
+
if (!wasmWrapper) {
|
|
357
|
+
state.debug_mode && console.log("WASM wrapper not initialized");
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
361
|
if (state.isDocumentProcess) {
|
|
362
362
|
mode = "Document";
|
|
363
363
|
} else if (state.isStitchingProcess) {
|
|
@@ -365,50 +365,56 @@ const VeryfiLens = (function () {
|
|
|
365
365
|
} else {
|
|
366
366
|
mode = "StitcherProcess";
|
|
367
367
|
}
|
|
368
|
-
if (state.videoRef) {
|
|
369
|
-
let rCorners;
|
|
370
|
-
const video = state.videoRef;
|
|
371
|
-
let videoHeight = video.videoHeight;
|
|
372
|
-
let videoWidth = video.videoWidth;
|
|
373
|
-
const fullSizeCanvas = document.createElement("canvas");
|
|
374
|
-
fullSizeCanvas.width = videoWidth;
|
|
375
|
-
fullSizeCanvas.height = videoHeight;
|
|
376
|
-
const fullSizeCtx = fullSizeCanvas.getContext("2d");
|
|
377
|
-
|
|
378
|
-
if (fullSizeCtx) {
|
|
379
|
-
fullSizeCtx.save();
|
|
380
|
-
fullSizeCtx.drawImage(video, 0, 0, videoWidth, videoHeight);
|
|
381
|
-
fullSizeCtx.restore();
|
|
382
|
-
const imgString = fullSizeCanvas.toDataURL("image/jpeg");
|
|
383
368
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
369
|
+
if (state.videoRef) {
|
|
370
|
+
try {
|
|
371
|
+
let rCorners;
|
|
372
|
+
const video = state.videoRef;
|
|
373
|
+
let videoHeight = video.videoHeight;
|
|
374
|
+
let videoWidth = video.videoWidth;
|
|
375
|
+
const fullSizeCanvas = document.createElement("canvas");
|
|
376
|
+
fullSizeCanvas.width = videoWidth;
|
|
377
|
+
fullSizeCanvas.height = videoHeight;
|
|
378
|
+
const fullSizeCtx = fullSizeCanvas.getContext("2d");
|
|
379
|
+
|
|
380
|
+
if (fullSizeCtx) {
|
|
381
|
+
fullSizeCtx.save();
|
|
382
|
+
fullSizeCtx.drawImage(video, 0, 0, videoWidth, videoHeight);
|
|
383
|
+
fullSizeCtx.restore();
|
|
384
|
+
const imgString = fullSizeCanvas.toDataURL("image/jpeg");
|
|
385
|
+
|
|
386
|
+
try {
|
|
387
|
+
state.fullSizeImage = await loadImage(imgString);
|
|
388
|
+
createImageBitmap(state.fullSizeImage).then((bitmap) => {
|
|
389
|
+
if (wasmWrapper && typeof wasmWrapper.processDocument === 'function') {
|
|
390
|
+
wasmWrapper.processDocument(bitmap, mode);
|
|
391
|
+
rCorners = state.coordinates.map((corner) => corner);
|
|
392
|
+
if (
|
|
393
|
+
rCorners.length &&
|
|
394
|
+
rCorners.some((subArr) => subArr.reduce((a, b) => a + b, 0) !== 0)
|
|
395
|
+
) {
|
|
396
|
+
drawContours(rCorners);
|
|
397
|
+
if (state.previewData !== null && state.shouldUpdatePreview) {
|
|
398
|
+
state.longPreview && state.longPreview.updatePreview(
|
|
399
|
+
state.previewData.data,
|
|
400
|
+
state.previewData.outputWidth,
|
|
401
|
+
state.previewData.outputHeight
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
} else {
|
|
405
|
+
setHasCoordinates(false);
|
|
406
|
+
state.image = imgString;
|
|
407
|
+
}
|
|
401
408
|
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
});
|
|
407
|
-
} catch (error) {
|
|
408
|
-
console.log(error);
|
|
409
|
-
}
|
|
409
|
+
});
|
|
410
|
+
} catch (error) {
|
|
411
|
+
console.log(error);
|
|
412
|
+
}
|
|
410
413
|
|
|
411
|
-
|
|
414
|
+
releaseCanvas(fullSizeCanvas);
|
|
415
|
+
}
|
|
416
|
+
} catch (error) {
|
|
417
|
+
console.error("Error in sendWasm:", error);
|
|
412
418
|
}
|
|
413
419
|
}
|
|
414
420
|
};
|
|
@@ -721,7 +727,7 @@ const VeryfiLens = (function () {
|
|
|
721
727
|
const ctx = cropImgCanvas.getContext("2d");
|
|
722
728
|
const imageData = new ImageData(data, width, height);
|
|
723
729
|
ctx.putImageData(imageData, 0, 0);
|
|
724
|
-
console.log(blurLevel)
|
|
730
|
+
state.debug_mode && console.log(blurLevel)
|
|
725
731
|
setBlurStatus(blurLevel);
|
|
726
732
|
stopWasm();
|
|
727
733
|
|
|
@@ -884,7 +890,7 @@ const VeryfiLens = (function () {
|
|
|
884
890
|
}
|
|
885
891
|
!state.cardOverlay && (state.cardOverlay = createCreditCardComponent(state.container));
|
|
886
892
|
if (state.exitButton) {
|
|
887
|
-
createExitButton(state.
|
|
893
|
+
createExitButton(state.cardOverlay.element, {
|
|
888
894
|
setter: state.onClose,
|
|
889
895
|
redirectUrl: state.onCloseRedirectUrl,
|
|
890
896
|
}, removeOverlay);
|
|
@@ -933,9 +939,9 @@ const VeryfiLens = (function () {
|
|
|
933
939
|
try {
|
|
934
940
|
state.updateHandler && state.updateHandler({ status: 'validation_started' });
|
|
935
941
|
const response = await fetch(
|
|
936
|
-
'https://lens.veryfi.com/rest/validate_partner',
|
|
942
|
+
// 'https://lens.veryfi.com/rest/validate_partner',
|
|
937
943
|
// 'https://lens-dev.veryfi.com/rest/validate_partner',
|
|
938
|
-
|
|
944
|
+
'http://localhost:5050/rest/validate_partner',
|
|
939
945
|
|
|
940
946
|
{
|
|
941
947
|
method: 'POST',
|
|
@@ -997,7 +1003,8 @@ const VeryfiLens = (function () {
|
|
|
997
1003
|
};
|
|
998
1004
|
|
|
999
1005
|
const response = await fetch(
|
|
1000
|
-
"https://lens.veryfi.com/rest/send-cropped",
|
|
1006
|
+
// "https://lens.veryfi.com/rest/send-cropped",
|
|
1007
|
+
"http://localhost:5050/rest/send-cropped",
|
|
1001
1008
|
{
|
|
1002
1009
|
method: "POST",
|
|
1003
1010
|
headers: {
|
|
@@ -1032,7 +1039,8 @@ const VeryfiLens = (function () {
|
|
|
1032
1039
|
spinner.show();
|
|
1033
1040
|
state.updateHandler && state.updateHandler({ status: 'submission_started' });
|
|
1034
1041
|
|
|
1035
|
-
const processDocumentUrl = "https://lens.veryfi.com/api/document";
|
|
1042
|
+
// const processDocumentUrl = "https://lens.veryfi.com/api/document";
|
|
1043
|
+
const processDocumentUrl = "http://localhost:5050/api/document";
|
|
1036
1044
|
const deviceData = await getDeviceData();
|
|
1037
1045
|
|
|
1038
1046
|
const requestBody = {
|
|
@@ -1092,14 +1100,38 @@ const VeryfiLens = (function () {
|
|
|
1092
1100
|
};
|
|
1093
1101
|
|
|
1094
1102
|
const removeOverlay = () => {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1103
|
+
try {
|
|
1104
|
+
// Clear any existing intervals first
|
|
1105
|
+
if (state.intervalRef) {
|
|
1106
|
+
clearInterval(state.intervalRef);
|
|
1107
|
+
state.intervalRef = null;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// Then proceed with other cleanup
|
|
1111
|
+
if (state.videoRef && state.videoRef.srcObject) {
|
|
1112
|
+
const tracks = state.videoRef.srcObject.getTracks();
|
|
1113
|
+
tracks.forEach(track => track.stop());
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// Reset WASM wrapper
|
|
1117
|
+
if (wasmWrapper) {
|
|
1118
|
+
wasmWrapper.release();
|
|
1119
|
+
wasmWrapper = null;
|
|
1120
|
+
}
|
|
1121
|
+
if (state.usingOverlayContainer) {
|
|
1122
|
+
stopLens();
|
|
1123
|
+
document.body.removeChild(state.container);
|
|
1124
|
+
state.usingOverlayContainer = false;
|
|
1125
|
+
} else {
|
|
1126
|
+
stopLens();
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// Continue with other cleanup...
|
|
1130
|
+
resetState();
|
|
1131
|
+
|
|
1132
|
+
} catch (error) {
|
|
1133
|
+
console.error("Error in removeOverlay:", error);
|
|
1101
1134
|
}
|
|
1102
|
-
resetState();
|
|
1103
1135
|
};
|
|
1104
1136
|
|
|
1105
1137
|
const resetState = () => {
|
|
@@ -1183,7 +1215,7 @@ const VeryfiLens = (function () {
|
|
|
1183
1215
|
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
1184
1216
|
state.resultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
1185
1217
|
}
|
|
1186
|
-
state.
|
|
1218
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1187
1219
|
handleSubmit(state.finalImage);
|
|
1188
1220
|
}, removeOverlay);
|
|
1189
1221
|
state.enableSubmit && state.submitButton.show();
|
|
@@ -1252,6 +1284,7 @@ const VeryfiLens = (function () {
|
|
|
1252
1284
|
try {
|
|
1253
1285
|
state.debug_mode && console.log("[EVENT] capture");
|
|
1254
1286
|
state.updateHandler && state.updateHandler({ status: 'capture_started' });
|
|
1287
|
+
!state.uuidv4 && await generateDeviceIDifNeeded();
|
|
1255
1288
|
|
|
1256
1289
|
switch (state.lensFlavor) {
|
|
1257
1290
|
case "long_document":
|
|
@@ -1681,7 +1714,7 @@ const VeryfiLens = (function () {
|
|
|
1681
1714
|
|
|
1682
1715
|
const getDeviceData = async () => {
|
|
1683
1716
|
|
|
1684
|
-
state.uuidv4
|
|
1717
|
+
!state.uuidv4 && await generateDeviceIDifNeeded();
|
|
1685
1718
|
const browserData = await getBrowserData();
|
|
1686
1719
|
const UAData = flattenObject(parseUA());
|
|
1687
1720
|
|
|
@@ -1737,8 +1770,18 @@ const VeryfiLens = (function () {
|
|
|
1737
1770
|
};
|
|
1738
1771
|
|
|
1739
1772
|
const getFingerprint = async () => {
|
|
1773
|
+
state.debug_mode && console.log("Getting fingerprint");
|
|
1740
1774
|
try {
|
|
1741
|
-
const fp = await FingerprintJS.load(
|
|
1775
|
+
const fp = await FingerprintJS.load({
|
|
1776
|
+
endpoint: [
|
|
1777
|
+
"https://fp.veryfi.com",
|
|
1778
|
+
FingerprintJS.defaultEndpoint
|
|
1779
|
+
],
|
|
1780
|
+
scriptUrlPattern: [
|
|
1781
|
+
"https://fp.veryfi.com/web/v<version>/<apiKey>/loader_v<loaderVersion>.js",
|
|
1782
|
+
FingerprintJS.defaultScriptUrlPattern
|
|
1783
|
+
]
|
|
1784
|
+
});
|
|
1742
1785
|
const result = await fp.get();
|
|
1743
1786
|
state.visitorId = result.visitorId;
|
|
1744
1787
|
state.debug_mode && console.log("Basic fingerprint obtained:", state.visitorId);
|
|
@@ -1749,10 +1792,20 @@ const VeryfiLens = (function () {
|
|
|
1749
1792
|
}
|
|
1750
1793
|
|
|
1751
1794
|
const getFingerprintPro = async () => {
|
|
1795
|
+
state.debug_mode && console.log("Getting fingerprint pro");
|
|
1752
1796
|
try {
|
|
1753
|
-
const
|
|
1754
|
-
apiKey:
|
|
1755
|
-
|
|
1797
|
+
const fpPromise = FingerprintJSPro.load({
|
|
1798
|
+
apiKey: state.clientData.fpjs_key,
|
|
1799
|
+
endpoint: [
|
|
1800
|
+
"https://fp.veryfi.com",
|
|
1801
|
+
FingerprintJS.defaultEndpoint
|
|
1802
|
+
],
|
|
1803
|
+
scriptUrlPattern: [
|
|
1804
|
+
"https://fp.veryfi.com/web/v<version>/<apiKey>/loader_v<loaderVersion>.js",
|
|
1805
|
+
FingerprintJS.defaultScriptUrlPattern
|
|
1806
|
+
]
|
|
1807
|
+
})
|
|
1808
|
+
const fp = await fpPromise;
|
|
1756
1809
|
const result = await fp.get();
|
|
1757
1810
|
state.visitorId = result.visitorId;
|
|
1758
1811
|
state.debug_mode && console.log("Pro fingerprint obtained:", state.visitorId);
|
|
@@ -1762,6 +1815,41 @@ const VeryfiLens = (function () {
|
|
|
1762
1815
|
}
|
|
1763
1816
|
}
|
|
1764
1817
|
|
|
1818
|
+
const generateDeviceIDifNeeded = async () => {
|
|
1819
|
+
const EXPIRATION_DAYS = 7; // Set desired expiration time in days
|
|
1820
|
+
|
|
1821
|
+
const storedData = localStorage.getItem('ldidk');
|
|
1822
|
+
let cachedData = storedData ? JSON.parse(storedData) : null;
|
|
1823
|
+
|
|
1824
|
+
const isValid = cachedData &&
|
|
1825
|
+
cachedData.expiry &&
|
|
1826
|
+
new Date().getTime() < cachedData.expiry;
|
|
1827
|
+
|
|
1828
|
+
if (!isValid) {
|
|
1829
|
+
// Generate new device ID
|
|
1830
|
+
if (state.clientData?.fingerprint_js_on) {
|
|
1831
|
+
await getFingerprintPro();
|
|
1832
|
+
state.uuidv4 = await hexToUUIDv4(state.visitorId);
|
|
1833
|
+
} else {
|
|
1834
|
+
if (!state.visitorId) {
|
|
1835
|
+
await getFingerprint();
|
|
1836
|
+
}
|
|
1837
|
+
state.uuidv4 = await hexToUUIDv4(state.visitorId);
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
// Store with expiration
|
|
1841
|
+
const expiryTime = new Date().getTime() + (EXPIRATION_DAYS * 24 * 60 * 60 * 1000);
|
|
1842
|
+
const dataToStore = {
|
|
1843
|
+
id: state.uuidv4,
|
|
1844
|
+
expiry: expiryTime
|
|
1845
|
+
};
|
|
1846
|
+
|
|
1847
|
+
localStorage.setItem('ldidk', JSON.stringify(dataToStore));
|
|
1848
|
+
} else {
|
|
1849
|
+
state.uuidv4 = cachedData.id;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1765
1853
|
return {
|
|
1766
1854
|
|
|
1767
1855
|
init: async (clientId, config) => {
|
|
@@ -1774,20 +1862,6 @@ const VeryfiLens = (function () {
|
|
|
1774
1862
|
state.clientData = await validatePartner(state.clientId);
|
|
1775
1863
|
config.debug_mode && console.log(state.clientData);
|
|
1776
1864
|
|
|
1777
|
-
if (typeof window !== 'undefined') {
|
|
1778
|
-
|
|
1779
|
-
try {
|
|
1780
|
-
state.debug_mode && console.log("Getting fingerprint");
|
|
1781
|
-
if (state.clientData.fingerprint_js_on) {
|
|
1782
|
-
await getFingerprintPro();
|
|
1783
|
-
} else {
|
|
1784
|
-
await getFingerprint();
|
|
1785
|
-
}
|
|
1786
|
-
} catch (error) {
|
|
1787
|
-
console.error('Failed to initialize fingerprinting:', error);
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
1865
|
await initializeWasmWrapper();
|
|
1792
1866
|
|
|
1793
1867
|
switch (config.lensFlavor) {
|
|
@@ -1882,10 +1956,9 @@ const VeryfiLens = (function () {
|
|
|
1882
1956
|
},
|
|
1883
1957
|
|
|
1884
1958
|
getDeviceData: async () => {
|
|
1885
|
-
state.
|
|
1959
|
+
!state.uuidv4 && await generateDeviceIDifNeeded();
|
|
1886
1960
|
const browserData = await getBrowserData();
|
|
1887
1961
|
const UAData = flattenObject(parseUA());
|
|
1888
|
-
|
|
1889
1962
|
return {
|
|
1890
1963
|
browser_fingerprint: { ...UAData, ...browserData },
|
|
1891
1964
|
uuid: state.uuidv4,
|