veryfi-lens-wasm 2.0.1 → 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/package.json +1 -1
- package/veryfi-lens.js +151 -73
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -353,6 +353,11 @@ const VeryfiLens = (function () {
|
|
|
353
353
|
};
|
|
354
354
|
|
|
355
355
|
const sendWasm = async (mode) => {
|
|
356
|
+
if (!wasmWrapper) {
|
|
357
|
+
state.debug_mode && console.log("WASM wrapper not initialized");
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
356
361
|
if (state.isDocumentProcess) {
|
|
357
362
|
mode = "Document";
|
|
358
363
|
} else if (state.isStitchingProcess) {
|
|
@@ -360,50 +365,56 @@ const VeryfiLens = (function () {
|
|
|
360
365
|
} else {
|
|
361
366
|
mode = "StitcherProcess";
|
|
362
367
|
}
|
|
363
|
-
if (state.videoRef) {
|
|
364
|
-
let rCorners;
|
|
365
|
-
const video = state.videoRef;
|
|
366
|
-
let videoHeight = video.videoHeight;
|
|
367
|
-
let videoWidth = video.videoWidth;
|
|
368
|
-
const fullSizeCanvas = document.createElement("canvas");
|
|
369
|
-
fullSizeCanvas.width = videoWidth;
|
|
370
|
-
fullSizeCanvas.height = videoHeight;
|
|
371
|
-
const fullSizeCtx = fullSizeCanvas.getContext("2d");
|
|
372
|
-
|
|
373
|
-
if (fullSizeCtx) {
|
|
374
|
-
fullSizeCtx.save();
|
|
375
|
-
fullSizeCtx.drawImage(video, 0, 0, videoWidth, videoHeight);
|
|
376
|
-
fullSizeCtx.restore();
|
|
377
|
-
const imgString = fullSizeCanvas.toDataURL("image/jpeg");
|
|
378
368
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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
|
+
}
|
|
396
408
|
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
});
|
|
402
|
-
} catch (error) {
|
|
403
|
-
console.log(error);
|
|
404
|
-
}
|
|
409
|
+
});
|
|
410
|
+
} catch (error) {
|
|
411
|
+
console.log(error);
|
|
412
|
+
}
|
|
405
413
|
|
|
406
|
-
|
|
414
|
+
releaseCanvas(fullSizeCanvas);
|
|
415
|
+
}
|
|
416
|
+
} catch (error) {
|
|
417
|
+
console.error("Error in sendWasm:", error);
|
|
407
418
|
}
|
|
408
419
|
}
|
|
409
420
|
};
|
|
@@ -928,9 +939,9 @@ const VeryfiLens = (function () {
|
|
|
928
939
|
try {
|
|
929
940
|
state.updateHandler && state.updateHandler({ status: 'validation_started' });
|
|
930
941
|
const response = await fetch(
|
|
931
|
-
'https://lens.veryfi.com/rest/validate_partner',
|
|
942
|
+
// 'https://lens.veryfi.com/rest/validate_partner',
|
|
932
943
|
// 'https://lens-dev.veryfi.com/rest/validate_partner',
|
|
933
|
-
|
|
944
|
+
'http://localhost:5050/rest/validate_partner',
|
|
934
945
|
|
|
935
946
|
{
|
|
936
947
|
method: 'POST',
|
|
@@ -992,7 +1003,8 @@ const VeryfiLens = (function () {
|
|
|
992
1003
|
};
|
|
993
1004
|
|
|
994
1005
|
const response = await fetch(
|
|
995
|
-
"https://lens.veryfi.com/rest/send-cropped",
|
|
1006
|
+
// "https://lens.veryfi.com/rest/send-cropped",
|
|
1007
|
+
"http://localhost:5050/rest/send-cropped",
|
|
996
1008
|
{
|
|
997
1009
|
method: "POST",
|
|
998
1010
|
headers: {
|
|
@@ -1027,7 +1039,8 @@ const VeryfiLens = (function () {
|
|
|
1027
1039
|
spinner.show();
|
|
1028
1040
|
state.updateHandler && state.updateHandler({ status: 'submission_started' });
|
|
1029
1041
|
|
|
1030
|
-
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";
|
|
1031
1044
|
const deviceData = await getDeviceData();
|
|
1032
1045
|
|
|
1033
1046
|
const requestBody = {
|
|
@@ -1087,14 +1100,38 @@ const VeryfiLens = (function () {
|
|
|
1087
1100
|
};
|
|
1088
1101
|
|
|
1089
1102
|
const removeOverlay = () => {
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
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);
|
|
1096
1134
|
}
|
|
1097
|
-
resetState();
|
|
1098
1135
|
};
|
|
1099
1136
|
|
|
1100
1137
|
const resetState = () => {
|
|
@@ -1247,6 +1284,7 @@ const VeryfiLens = (function () {
|
|
|
1247
1284
|
try {
|
|
1248
1285
|
state.debug_mode && console.log("[EVENT] capture");
|
|
1249
1286
|
state.updateHandler && state.updateHandler({ status: 'capture_started' });
|
|
1287
|
+
!state.uuidv4 && await generateDeviceIDifNeeded();
|
|
1250
1288
|
|
|
1251
1289
|
switch (state.lensFlavor) {
|
|
1252
1290
|
case "long_document":
|
|
@@ -1676,7 +1714,7 @@ const VeryfiLens = (function () {
|
|
|
1676
1714
|
|
|
1677
1715
|
const getDeviceData = async () => {
|
|
1678
1716
|
|
|
1679
|
-
state.uuidv4
|
|
1717
|
+
!state.uuidv4 && await generateDeviceIDifNeeded();
|
|
1680
1718
|
const browserData = await getBrowserData();
|
|
1681
1719
|
const UAData = flattenObject(parseUA());
|
|
1682
1720
|
|
|
@@ -1732,8 +1770,18 @@ const VeryfiLens = (function () {
|
|
|
1732
1770
|
};
|
|
1733
1771
|
|
|
1734
1772
|
const getFingerprint = async () => {
|
|
1773
|
+
state.debug_mode && console.log("Getting fingerprint");
|
|
1735
1774
|
try {
|
|
1736
|
-
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
|
+
});
|
|
1737
1785
|
const result = await fp.get();
|
|
1738
1786
|
state.visitorId = result.visitorId;
|
|
1739
1787
|
state.debug_mode && console.log("Basic fingerprint obtained:", state.visitorId);
|
|
@@ -1744,10 +1792,20 @@ const VeryfiLens = (function () {
|
|
|
1744
1792
|
}
|
|
1745
1793
|
|
|
1746
1794
|
const getFingerprintPro = async () => {
|
|
1795
|
+
state.debug_mode && console.log("Getting fingerprint pro");
|
|
1747
1796
|
try {
|
|
1748
|
-
const
|
|
1749
|
-
apiKey:
|
|
1750
|
-
|
|
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;
|
|
1751
1809
|
const result = await fp.get();
|
|
1752
1810
|
state.visitorId = result.visitorId;
|
|
1753
1811
|
state.debug_mode && console.log("Pro fingerprint obtained:", state.visitorId);
|
|
@@ -1757,6 +1815,41 @@ const VeryfiLens = (function () {
|
|
|
1757
1815
|
}
|
|
1758
1816
|
}
|
|
1759
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
|
+
|
|
1760
1853
|
return {
|
|
1761
1854
|
|
|
1762
1855
|
init: async (clientId, config) => {
|
|
@@ -1769,20 +1862,6 @@ const VeryfiLens = (function () {
|
|
|
1769
1862
|
state.clientData = await validatePartner(state.clientId);
|
|
1770
1863
|
config.debug_mode && console.log(state.clientData);
|
|
1771
1864
|
|
|
1772
|
-
if (typeof window !== 'undefined') {
|
|
1773
|
-
|
|
1774
|
-
try {
|
|
1775
|
-
state.debug_mode && console.log("Getting fingerprint");
|
|
1776
|
-
if (state.clientData.fingerprint_js_on) {
|
|
1777
|
-
await getFingerprintPro();
|
|
1778
|
-
} else {
|
|
1779
|
-
await getFingerprint();
|
|
1780
|
-
}
|
|
1781
|
-
} catch (error) {
|
|
1782
|
-
console.error('Failed to initialize fingerprinting:', error);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
1865
|
await initializeWasmWrapper();
|
|
1787
1866
|
|
|
1788
1867
|
switch (config.lensFlavor) {
|
|
@@ -1877,10 +1956,9 @@ const VeryfiLens = (function () {
|
|
|
1877
1956
|
},
|
|
1878
1957
|
|
|
1879
1958
|
getDeviceData: async () => {
|
|
1880
|
-
state.
|
|
1959
|
+
!state.uuidv4 && await generateDeviceIDifNeeded();
|
|
1881
1960
|
const browserData = await getBrowserData();
|
|
1882
1961
|
const UAData = flattenObject(parseUA());
|
|
1883
|
-
|
|
1884
1962
|
return {
|
|
1885
1963
|
browser_fingerprint: { ...UAData, ...browserData },
|
|
1886
1964
|
uuid: state.uuidv4,
|