veryfi-lens-wasm 1.2.0 → 1.2.1
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 +61 -46
- package/wasm/{opencv.cjs → opencv.js} +1 -1
- package/wasm/wasm.js +3 -3
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -2,11 +2,6 @@ import DeviceUUID from "./wasm/device-uuid.js";
|
|
|
2
2
|
import { WasmWrapper } from "./wasm/wasm.js";
|
|
3
3
|
import gatherBrowserData from "./wasm/device-data.js";
|
|
4
4
|
import UAParser from "./wasm/ua-parser.cjs";
|
|
5
|
-
import cv from "./wasm/opencv.cjs";
|
|
6
|
-
// if (typeof document !== 'undefined') {
|
|
7
|
-
// const script = document.createElement("script");
|
|
8
|
-
// script.src = "./wasm/opencv.js";
|
|
9
|
-
// }
|
|
10
5
|
|
|
11
6
|
const VeryfiLens = (function () {
|
|
12
7
|
const DEFAULT_BOX_COlOR = "rgba(84, 192, 139, 0.6)";
|
|
@@ -76,6 +71,8 @@ const VeryfiLens = (function () {
|
|
|
76
71
|
let CCPhase = "ScanningFront";
|
|
77
72
|
let timeStamp = 0;
|
|
78
73
|
let ShouldProcessCC = true;
|
|
74
|
+
// let cv = null;
|
|
75
|
+
let cvReady = false;
|
|
79
76
|
|
|
80
77
|
let cardData = {
|
|
81
78
|
status: "",
|
|
@@ -84,7 +81,6 @@ const VeryfiLens = (function () {
|
|
|
84
81
|
date: "",
|
|
85
82
|
cvv: "",
|
|
86
83
|
};
|
|
87
|
-
|
|
88
84
|
const releaseCanvas = (canvas) => {
|
|
89
85
|
if (canvas) {
|
|
90
86
|
canvas.width = 1;
|
|
@@ -452,31 +448,31 @@ const VeryfiLens = (function () {
|
|
|
452
448
|
}
|
|
453
449
|
};
|
|
454
450
|
|
|
455
|
-
// const testCCVideo = async () => {
|
|
456
|
-
// const video = videoRef;
|
|
457
|
-
// video.src = './cardTest.mp4';
|
|
458
|
-
// wasmWrapper.setCardDetectorCallback(logCard);
|
|
459
|
-
// };
|
|
451
|
+
// const testCCVideo = async () => {
|
|
452
|
+
// const video = videoRef;
|
|
453
|
+
// video.src = './cardTest.mp4';
|
|
454
|
+
// wasmWrapper.setCardDetectorCallback(logCard);
|
|
455
|
+
// };
|
|
460
456
|
|
|
461
457
|
const testCCVideo = async () => {
|
|
462
|
-
console.log(
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
};
|
|
458
|
+
console.log("TEST VIDEO");
|
|
459
|
+
// Create a video element
|
|
460
|
+
const video = document.createElement("video");
|
|
461
|
+
video.src = "./cardTest.mp4";
|
|
462
|
+
video.autoplay = true;
|
|
463
|
+
video.muted = true; // Mute the video to avoid audio playback
|
|
464
|
+
video.loop = true; // Loop the video
|
|
465
|
+
|
|
466
|
+
// Attach the video element to the document body
|
|
467
|
+
document.body.appendChild(video);
|
|
468
|
+
|
|
469
|
+
// Set the video element as the source object of the videoRef
|
|
470
|
+
const videoRef = document.getElementById("veryfi-video-ref"); // Assuming you have a video element with this ID
|
|
471
|
+
videoRef.srcObject = video.captureStream();
|
|
472
|
+
|
|
473
|
+
// Mock the behavior of wasmWrapper.setCardDetectorCallback
|
|
474
|
+
wasmWrapper.setCardDetectorCallback(logCard);
|
|
475
|
+
};
|
|
480
476
|
|
|
481
477
|
const loadImage = (src) => {
|
|
482
478
|
return new Promise((resolve, reject) => {
|
|
@@ -714,13 +710,20 @@ const VeryfiLens = (function () {
|
|
|
714
710
|
CCPhase = "FlipCard";
|
|
715
711
|
case "ScanningBack":
|
|
716
712
|
console.log("ITS CASE 2");
|
|
717
|
-
|
|
713
|
+
const scanForNumber = !cardData.number;
|
|
714
|
+
const scanForName = !cardData.name;
|
|
715
|
+
const scanForDate = !cardData.date;
|
|
716
|
+
const scanForCvv = !cardData.cvv;
|
|
717
|
+
wasmWrapper.resetAutoCapture(
|
|
718
|
+
scanForNumber,
|
|
719
|
+
scanForName,
|
|
720
|
+
scanForDate,
|
|
721
|
+
scanForCvv
|
|
722
|
+
);
|
|
718
723
|
if (cardData.status == "AutoCaptureResultDone") {
|
|
719
724
|
ShouldProcessCC = false;
|
|
720
725
|
wasmWrapper.resetAutoCapture(true, true, true, true);
|
|
721
726
|
wasmWrapper.releaseCallback();
|
|
722
|
-
// wasmWrapper.release();
|
|
723
|
-
// CCPhase = "ScanningFront";
|
|
724
727
|
}
|
|
725
728
|
}
|
|
726
729
|
}
|
|
@@ -997,7 +1000,7 @@ const VeryfiLens = (function () {
|
|
|
997
1000
|
};
|
|
998
1001
|
|
|
999
1002
|
const startWasm = async (client_id) => {
|
|
1000
|
-
if(!wasmWrapper.loaded){
|
|
1003
|
+
if (!wasmWrapper.loaded) {
|
|
1001
1004
|
await wasmWrapper.initialize(client_id);
|
|
1002
1005
|
}
|
|
1003
1006
|
if (wasmWrapper) {
|
|
@@ -1013,8 +1016,8 @@ const VeryfiLens = (function () {
|
|
|
1013
1016
|
};
|
|
1014
1017
|
|
|
1015
1018
|
const startWasmLong = async (client_id) => {
|
|
1016
|
-
if(!wasmWrapper.loaded){
|
|
1017
|
-
|
|
1019
|
+
if (!wasmWrapper.loaded) {
|
|
1020
|
+
await wasmWrapper.initialize(client_id);
|
|
1018
1021
|
}
|
|
1019
1022
|
if (wasmWrapper) {
|
|
1020
1023
|
getVideoWasmLong();
|
|
@@ -1049,7 +1052,7 @@ const VeryfiLens = (function () {
|
|
|
1049
1052
|
}
|
|
1050
1053
|
};
|
|
1051
1054
|
const startWasmCC = async (client_id) => {
|
|
1052
|
-
if (!wasmWrapper.loaded){
|
|
1055
|
+
if (!wasmWrapper.loaded) {
|
|
1053
1056
|
await wasmWrapper.initialize(client_id);
|
|
1054
1057
|
}
|
|
1055
1058
|
if (wasmWrapper.loaded) {
|
|
@@ -1069,7 +1072,7 @@ const VeryfiLens = (function () {
|
|
|
1069
1072
|
};
|
|
1070
1073
|
const testWasmCC = async (client_id) => {
|
|
1071
1074
|
await wasmWrapper.initialize(client_id);
|
|
1072
|
-
console.log(
|
|
1075
|
+
console.log("first");
|
|
1073
1076
|
if (wasmWrapper) {
|
|
1074
1077
|
testCCVideo();
|
|
1075
1078
|
requestAnimationFrame(displayVideo);
|
|
@@ -1080,7 +1083,7 @@ const VeryfiLens = (function () {
|
|
|
1080
1083
|
) {
|
|
1081
1084
|
clearInterval(intervalRef); // Stop sending frames once condition is met
|
|
1082
1085
|
} else {
|
|
1083
|
-
sendCardWasm();
|
|
1086
|
+
sendCardWasm();
|
|
1084
1087
|
}
|
|
1085
1088
|
}, INTERVAL);
|
|
1086
1089
|
}
|
|
@@ -1102,8 +1105,20 @@ const VeryfiLens = (function () {
|
|
|
1102
1105
|
}
|
|
1103
1106
|
};
|
|
1104
1107
|
|
|
1108
|
+
function loadOpenCv(url) {
|
|
1109
|
+
return new Promise((resolve, reject) => {
|
|
1110
|
+
const script = document.createElement("script");
|
|
1111
|
+
script.src = url;
|
|
1112
|
+
script.onload = () => resolve(); // Correctly scoped resolve
|
|
1113
|
+
script.onerror = () => reject(new Error(`Script load error for ${url}`));
|
|
1114
|
+
document.body.appendChild(script);
|
|
1115
|
+
cvReady = true;
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1105
1119
|
const isBlurry = async (image) => {
|
|
1106
1120
|
console.log("[EVENT] Checking for blur");
|
|
1121
|
+
|
|
1107
1122
|
const src = cv.imread(image);
|
|
1108
1123
|
let refVariance;
|
|
1109
1124
|
let whiteCanvas = new cv.Mat(490, 866, cv.CV_8UC3, [255, 255, 255, 0]);
|
|
@@ -1251,6 +1266,9 @@ const VeryfiLens = (function () {
|
|
|
1251
1266
|
device_uuid = new DeviceUUID(userAgent).get();
|
|
1252
1267
|
console.log("[EVENT] Device ID", getDeviceID(device_uuid));
|
|
1253
1268
|
if (session) {
|
|
1269
|
+
if (!cvReady) {
|
|
1270
|
+
loadOpenCv("./wasm/opencv.js");
|
|
1271
|
+
}
|
|
1254
1272
|
lensSessionKey = session;
|
|
1255
1273
|
createCanvases();
|
|
1256
1274
|
videoRef = document.getElementById("veryfi-video-ref");
|
|
@@ -1383,7 +1401,7 @@ const VeryfiLens = (function () {
|
|
|
1383
1401
|
}
|
|
1384
1402
|
},
|
|
1385
1403
|
testCC: (client_id) => {
|
|
1386
|
-
console.log(
|
|
1404
|
+
console.log("testing");
|
|
1387
1405
|
isDocumentProcess = true;
|
|
1388
1406
|
userAgent = navigator.userAgent;
|
|
1389
1407
|
device_uuid = new DeviceUUID(userAgent).get();
|
|
@@ -1392,7 +1410,6 @@ const VeryfiLens = (function () {
|
|
|
1392
1410
|
cardData = { status: "", number: "", name: "", date: "", cvv: "" };
|
|
1393
1411
|
testWasmCC(client_id);
|
|
1394
1412
|
},
|
|
1395
|
-
|
|
1396
1413
|
|
|
1397
1414
|
startCamera: () => {
|
|
1398
1415
|
console.log("[EVENT] startCamera");
|
|
@@ -1438,7 +1455,7 @@ const VeryfiLens = (function () {
|
|
|
1438
1455
|
finalImage = await cropWasm();
|
|
1439
1456
|
setImage && setImage(finalImage);
|
|
1440
1457
|
stopWasm();
|
|
1441
|
-
wasmWrapper.releaseCallback()
|
|
1458
|
+
wasmWrapper.releaseCallback();
|
|
1442
1459
|
setIsEditing && setIsEditing(true);
|
|
1443
1460
|
return finalImage;
|
|
1444
1461
|
},
|
|
@@ -1449,7 +1466,7 @@ const VeryfiLens = (function () {
|
|
|
1449
1466
|
setImage && setImage(finalImage);
|
|
1450
1467
|
stopWasm();
|
|
1451
1468
|
if (hasCoordinates) setIsDocument(true);
|
|
1452
|
-
wasmWrapper.releaseCallback()
|
|
1469
|
+
wasmWrapper.releaseCallback();
|
|
1453
1470
|
setIsEditing && setIsEditing(true);
|
|
1454
1471
|
return finalImage;
|
|
1455
1472
|
},
|
|
@@ -1469,7 +1486,7 @@ const VeryfiLens = (function () {
|
|
|
1469
1486
|
const imageData = new ImageData(data, width, height);
|
|
1470
1487
|
ctx.putImageData(imageData, 0, 0);
|
|
1471
1488
|
setBlurStatus(blurLevel);
|
|
1472
|
-
wasmWrapper.releaseCallback()
|
|
1489
|
+
wasmWrapper.releaseCallback();
|
|
1473
1490
|
stopWasm();
|
|
1474
1491
|
|
|
1475
1492
|
const imgString = cropImgCanvas.toDataURL("image/jpeg");
|
|
@@ -1608,9 +1625,7 @@ const VeryfiLens = (function () {
|
|
|
1608
1625
|
|
|
1609
1626
|
getCardPhase: () => {
|
|
1610
1627
|
return CCPhase;
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1628
|
+
},
|
|
1614
1629
|
};
|
|
1615
1630
|
})();
|
|
1616
1631
|
|