veryfi-lens-wasm 1.1.13 → 1.1.15

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/veryfi-lens.js CHANGED
@@ -220,8 +220,8 @@ const VeryfiLens = (function () {
220
220
  video: {
221
221
  aspectRatio: isDesktop ? 9 / 16 : 16 / 9,
222
222
  facingMode: "environment",
223
- width: isDesktop ? { ideal: 1440 } : { min: 1280 },
224
- height: isDesktop ? { ideal: 2560 } : { min: 720 },
223
+ width: isDesktop ? { ideal: 1440 } : { min: 1920 },
224
+ height: isDesktop ? { ideal: 2560 } : { min: 1080 },
225
225
  },
226
226
  })
227
227
  .then((stream) => {
@@ -243,8 +243,8 @@ const VeryfiLens = (function () {
243
243
  video: {
244
244
  aspectRatio: isDesktop ? 9 / 16 : 16 / 9,
245
245
  facingMode: "environment",
246
- width: isDesktop ? { ideal: 1440 } : { min: 1280 },
247
- height: isDesktop ? { ideal: 2560 } : { min: 720 },
246
+ width: isDesktop ? { ideal: 1440 } : { min: 1920 },
247
+ height: isDesktop ? { ideal: 2560 } : { min: 1080 },
248
248
  },
249
249
  })
250
250
  .then((stream) => {
@@ -266,8 +266,8 @@ const VeryfiLens = (function () {
266
266
  video: {
267
267
  aspectRatio: isDesktop ? 9 / 16 : 16 / 9,
268
268
  facingMode: "environment",
269
- width: isDesktop ? { ideal: 1440 } : { min: 1280 },
270
- height: isDesktop ? { ideal: 2560 } : { min: 720 },
269
+ width: isDesktop ? { ideal: 1440 } : { min: 1920 },
270
+ height: isDesktop ? { ideal: 2560 } : { min: 1080 },
271
271
  },
272
272
  })
273
273
  .then((stream) => {
@@ -283,23 +283,22 @@ const VeryfiLens = (function () {
283
283
 
284
284
  const getCCVideo = () => {
285
285
  const isDesktop = window.screen.width > window.screen.height;
286
- const camWidth = 1440;
287
- const camHeight = 2560;
288
286
  if (navigator) {
289
287
  navigator.mediaDevices
290
288
  .getUserMedia({
291
289
  video: {
292
290
  aspectRatio: isDesktop ? 9 / 16 : 16 / 9,
293
291
  facingMode: "environment",
294
- width: { camWidth },
295
- height: { camHeight },
292
+ width: isDesktop ? { ideal: 1440 } : { min: 1920 },
293
+ height: isDesktop ? { ideal: 2560 } : { min: 1080 },
296
294
  },
297
295
  })
298
296
  .then((stream) => {
299
297
  console.log("started stream");
300
298
  const video = videoRef;
301
299
  video.srcObject = stream;
302
- wasmWrapper.setCardCallback(logCC);
300
+ // wasmWrapper.setCardCallback(logCard);
301
+ wasmWrapper.initCardDetector();
303
302
  })
304
303
  .catch((err) => {
305
304
  console.log(`[Event] Error: ${err}`);
@@ -479,6 +478,9 @@ const VeryfiLens = (function () {
479
478
  shouldUpdatePreview = status == 0;
480
479
  }
481
480
 
481
+ function logCard(status, x0, y0, x1, y1, x2, y2, x3, y3) {
482
+ }
483
+
482
484
  const drawContours = (contours) => {
483
485
  const video = videoRef;
484
486
  const BoxCanvas = boxRef;
@@ -804,7 +806,7 @@ const VeryfiLens = (function () {
804
806
  wasmWrapper = new WasmWrapper();
805
807
  await wasmWrapper.initialize(client_id);
806
808
  if (wasmWrapper) {
807
- getVideoWasm();
809
+ getCCVideo();
808
810
  requestAnimationFrame(displayVideo);
809
811
  intervalRef = setInterval(() => {
810
812
  sendWasm("Document");
@@ -1076,7 +1078,7 @@ const VeryfiLens = (function () {
1076
1078
  }
1077
1079
  },
1078
1080
 
1079
- initWasmCC: async (session, client_id) => {
1081
+ initCC: async (session, client_id) => {
1080
1082
  isDocumentProcess = true;
1081
1083
  userAgent = navigator.userAgent;
1082
1084
  device_uuid = new DeviceUUID(userAgent).get();
package/wasm/wasm.js CHANGED
@@ -40,9 +40,9 @@ export class WasmWrapper {
40
40
 
41
41
  /** @private */
42
42
  selectDir(useSimd) {
43
- const userAgent = navigator.userAgent;
43
+ // const userAgent = navigator.userAgent;
44
44
  if (!useSimd) return "nonsimd";
45
- if (userAgent.indexOf("AppleWebKit") > -1) return "tfsimd";
45
+ // if (userAgent.indexOf("AppleWebKit") > -1) return "tfsimd";
46
46
  return "simd";
47
47
  }
48
48
 
@@ -57,31 +57,12 @@ export class WasmWrapper {
57
57
  return;
58
58
  }
59
59
  const dir = this.selectDir(useSimd);
60
+ // await this.loadModuleScript_("/wasm/" + dir + "/wasmHelpers.js");
60
61
  await this.loadModuleScript_("/wasm/" + dir + "/veryfi-wasm.js");
61
62
  this.wasmModule = await createModule();
62
63
  this.loaded = true;
63
64
  }
64
65
 
65
- // async initialize(client_id) {
66
- // this.client_id = client_id
67
- // const features = await this.checkFeatures_();
68
- // const { useSimd, useThreads } = features;
69
-
70
- // if (!useThreads) {
71
- // console.warn("Threads disabled, seems that the security requirements for SharedArrayBuffer are not met");
72
- // return;
73
- // }
74
-
75
- // // Select the appropriate directory based on features
76
- // const dir = this.selectDir(useSimd);
77
-
78
- // // Dynamically import the wasm module script
79
- // await import(`./${dir}/veryfi-wasm.js`);
80
-
81
- // // Create the Wasm module
82
- // this.wasmModule = await createModule();
83
- // this.loaded = true;
84
- // }
85
66
 
86
67
  setDocumentCallback(callback) {
87
68
  if (!this.loaded || this.documentDetectorLoaded) return;
@@ -100,13 +81,18 @@ await this.loadModuleScript_("/wasm/" + dir + "/veryfi-wasm.js");
100
81
  );
101
82
  }
102
83
 
84
+ initCardDetector() {
85
+ if (!this.loaded) return false;
86
+ const success = this.wasmModule.ccall('initCardDetector', 'bool', [], []);
87
+ return success;
88
+ }
89
+
90
+
103
91
  setCardCallback(callback) {
104
92
  if (!this.loaded || this.cardDetectorLoaded) return;
105
93
  this.wasmModule.ccall(
106
94
  "initCardDetector",
107
- null,
108
- ["string"],
109
- [this.client_id]
95
+ 'boolean'
110
96
  );
111
97
  let cardDetectorCallback = this.wasmModule.addFunction(callback, "viiiii");
112
98
  this.cardDetectorLoaded = this.wasmModule.ccall(
@@ -117,6 +103,47 @@ await this.loadModuleScript_("/wasm/" + dir + "/veryfi-wasm.js");
117
103
  );
118
104
  }
119
105
 
106
+ setCreditCardCallback(callback) {
107
+ if (!this.loaded) return false;
108
+ let cardDetectorCallback = this.wasmModule.addFunction((autoCaptureState, namePtr, numPtr, datePtr, cvvPtr) => {
109
+ const name = this.wasmModule.UTF8ToString(namePtr);
110
+ const num = this.wasmModule.UTF8ToString(numPtr);
111
+ const date = this.wasmModule.UTF8ToString(datePtr);
112
+ const cvv = this.wasmModule.UTF8ToString(cvvPtr);
113
+ callback(autoCaptureState, name, num, date, cvv);
114
+ }, 'viiiii');
115
+ // viiiii
116
+ // v -> void (return type)
117
+ // i -> autoCaptureState (int)
118
+ // i -> name (pointer to char)
119
+ // i -> num (pointer to char)
120
+ // i -> date (pointer to char)
121
+ // i -> cvv (pointer to char)
122
+
123
+ const success = this.wasmModule.ccall(
124
+ 'setCreditCardCallback',
125
+ 'boolean',
126
+ ['number'],
127
+ [cardDetectorCallback]
128
+ );
129
+ return success;
130
+ }
131
+
132
+ creditCardProcessFrame(inputMatAddress, width, height) {
133
+ if (!this.loaded) return;
134
+ // Assuming inputMatAddress is a pointer to the image data in memory.
135
+ this.wasmModule.ccall('creditCardProcessFrame', null, ['number', 'number', 'number'], [inputMatAddress, width, height]);
136
+ }
137
+
138
+ creditCardGetResult() {
139
+ if (!this.loaded) return null;
140
+ const resultPtr = this.wasmModule.ccall('creditCardGetResult', 'number', [], []);
141
+ // Assuming resultPtr points to a structure or data you need.
142
+ // You'll need to extract that data from the pointer, similar to how you handle strings or other data types.
143
+ }
144
+
145
+
146
+
120
147
  setStitcherCallback(callback) {
121
148
  if (!this.loaded || this.stitcherLoaded) return;
122
149
  this.wasmModule.ccall("initStitcher", null, ["string"], [this.client_id]);
@@ -140,16 +167,10 @@ await this.loadModuleScript_("/wasm/" + dir + "/veryfi-wasm.js");
140
167
  );
141
168
  }
142
169
 
143
- getCC(bitmap) {
170
+ creditCardGetResult(bitmap) {
144
171
  if (!this.cardDetectorLoaded) return;
145
172
  const buffer = this.setBitmapOnWASMMemory_(bitmap);
146
- let outputBuffer = this.wasmModule.ccall(
147
- "getCC",
148
- "number",
149
- ["number", "number", "number", "number", "number"],
150
- [buffer, bitmap.width, bitmap.height, true]
151
- );
152
-
173
+ let outputBuffer = this.wasmModule.ccall("creditCardGetResult",);
153
174
  this.freeBuffer_(buffer);
154
175
  return this.getResultFromBuffer(outputBuffer);
155
176
  }
@@ -229,14 +250,6 @@ await this.loadModuleScript_("/wasm/" + dir + "/veryfi-wasm.js");
229
250
  return { data, blurLevel, outputHeight, outputWidth };
230
251
  }
231
252
 
232
- // /** @private */
233
- // async checkFeatures_() {
234
- // let useSimd = await wasmFeatureDetect.simd();
235
- // let useThreads = await wasmFeatureDetect.threads();
236
- // console.log(`useSimd: ${useSimd}, useThreads: ${useThreads}`);
237
- // return { useSimd, useThreads };
238
- // }
239
-
240
253
  /** @private */
241
254
  async checkFeatures_() {
242
255
  let useSimd = await this.simd();