@hexar/biometric-identity-sdk-core 1.0.14 → 1.0.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.
|
@@ -79,6 +79,16 @@ export declare class BiometricIdentitySDK {
|
|
|
79
79
|
* Convert Blob to base64
|
|
80
80
|
*/
|
|
81
81
|
private blobToBase64;
|
|
82
|
+
/**
|
|
83
|
+
* Compress base64 image - simplified version that works in all environments
|
|
84
|
+
* For React Native, images should be compressed at capture time
|
|
85
|
+
* This is a no-op for now - compression should happen at capture time in React Native
|
|
86
|
+
*/
|
|
87
|
+
private compressImage;
|
|
88
|
+
/**
|
|
89
|
+
* Compress image in browser environment using Canvas API
|
|
90
|
+
*/
|
|
91
|
+
private compressImageBrowser;
|
|
82
92
|
/**
|
|
83
93
|
* Get current SDK state
|
|
84
94
|
*/
|
|
@@ -299,7 +299,7 @@ class BiometricIdentitySDK {
|
|
|
299
299
|
minimumRequired: 10
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
|
-
const MAX_FRAMES =
|
|
302
|
+
const MAX_FRAMES = 20;
|
|
303
303
|
if (videoFrames.length > MAX_FRAMES) {
|
|
304
304
|
const step = Math.floor(videoFrames.length / MAX_FRAMES);
|
|
305
305
|
videoFrames = videoFrames.filter((_, index) => index % step === 0).slice(0, MAX_FRAMES);
|
|
@@ -308,17 +308,25 @@ class BiometricIdentitySDK {
|
|
|
308
308
|
sampledCount: videoFrames.length
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
|
+
const compressedFrontImage = await this.compressImage(this.state.frontID.data);
|
|
312
|
+
const compressedBackImage = this.state.backID?.data
|
|
313
|
+
? await this.compressImage(this.state.backID.data)
|
|
314
|
+
: undefined;
|
|
315
|
+
const compressedFrames = await Promise.all(videoFrames.map(frame => this.compressImage(frame)));
|
|
311
316
|
logger_1.logger.info('Sending validation request to backend', {
|
|
312
|
-
framesCount:
|
|
317
|
+
framesCount: compressedFrames.length,
|
|
313
318
|
duration: this.state.videoData.duration,
|
|
314
319
|
challengesCount: this.state.videoData.challengesCompleted?.length || 0,
|
|
315
|
-
frontImageSize:
|
|
316
|
-
backImageSize:
|
|
320
|
+
frontImageSize: compressedFrontImage.length,
|
|
321
|
+
backImageSize: compressedBackImage?.length || 0,
|
|
322
|
+
originalFrontSize: this.state.frontID.data?.length || 0,
|
|
323
|
+
originalBackSize: this.state.backID?.data?.length || 0,
|
|
324
|
+
compressionRatio: compressedFrontImage.length / (this.state.frontID.data?.length || 1)
|
|
317
325
|
});
|
|
318
326
|
const response = await this.backendClient.fullValidation({
|
|
319
|
-
frontIdImage:
|
|
320
|
-
backIdImage:
|
|
321
|
-
videoFrames:
|
|
327
|
+
frontIdImage: compressedFrontImage,
|
|
328
|
+
backIdImage: compressedBackImage,
|
|
329
|
+
videoFrames: compressedFrames,
|
|
322
330
|
videoDurationMs: this.state.videoData.duration,
|
|
323
331
|
challengesCompleted: this.state.videoData.challengesCompleted || [],
|
|
324
332
|
});
|
|
@@ -387,6 +395,63 @@ class BiometricIdentitySDK {
|
|
|
387
395
|
reader.readAsDataURL(blob);
|
|
388
396
|
});
|
|
389
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Compress base64 image - simplified version that works in all environments
|
|
400
|
+
* For React Native, images should be compressed at capture time
|
|
401
|
+
* This is a no-op for now - compression should happen at capture time in React Native
|
|
402
|
+
*/
|
|
403
|
+
async compressImage(base64Image) {
|
|
404
|
+
if (!base64Image || base64Image.length === 0) {
|
|
405
|
+
return base64Image;
|
|
406
|
+
}
|
|
407
|
+
const MAX_SIZE = 1024 * 1024;
|
|
408
|
+
if (base64Image.length < MAX_SIZE) {
|
|
409
|
+
return base64Image;
|
|
410
|
+
}
|
|
411
|
+
try {
|
|
412
|
+
const globalWindow = globalThis.window;
|
|
413
|
+
if (globalWindow && globalWindow.Image && globalWindow.document) {
|
|
414
|
+
return await this.compressImageBrowser(base64Image, globalWindow);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
logger_1.logger.warn('Image compression not available, using original', error);
|
|
419
|
+
}
|
|
420
|
+
return base64Image;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Compress image in browser environment using Canvas API
|
|
424
|
+
*/
|
|
425
|
+
async compressImageBrowser(base64Image, window) {
|
|
426
|
+
return new Promise((resolve, reject) => {
|
|
427
|
+
const img = new window.Image();
|
|
428
|
+
img.onload = () => {
|
|
429
|
+
const canvas = window.document.createElement('canvas');
|
|
430
|
+
const maxWidth = 1920;
|
|
431
|
+
const maxHeight = 1920;
|
|
432
|
+
let width = img.width;
|
|
433
|
+
let height = img.height;
|
|
434
|
+
if (width > maxWidth || height > maxHeight) {
|
|
435
|
+
const ratio = Math.min(maxWidth / width, maxHeight / height);
|
|
436
|
+
width = width * ratio;
|
|
437
|
+
height = height * ratio;
|
|
438
|
+
}
|
|
439
|
+
canvas.width = width;
|
|
440
|
+
canvas.height = height;
|
|
441
|
+
const ctx = canvas.getContext('2d');
|
|
442
|
+
if (!ctx) {
|
|
443
|
+
reject(new Error('Could not get canvas context'));
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
447
|
+
const compressedBase64 = canvas.toDataURL('image/jpeg', 0.85);
|
|
448
|
+
const base64 = compressedBase64.split(',')[1];
|
|
449
|
+
resolve(base64);
|
|
450
|
+
};
|
|
451
|
+
img.onerror = reject;
|
|
452
|
+
img.src = `data:image/jpeg;base64,${base64Image}`;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
390
455
|
/**
|
|
391
456
|
* Get current SDK state
|
|
392
457
|
*/
|
package/package.json
CHANGED
|
@@ -381,7 +381,7 @@ export class BiometricIdentitySDK {
|
|
|
381
381
|
});
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
const MAX_FRAMES =
|
|
384
|
+
const MAX_FRAMES = 20;
|
|
385
385
|
if (videoFrames.length > MAX_FRAMES) {
|
|
386
386
|
const step = Math.floor(videoFrames.length / MAX_FRAMES);
|
|
387
387
|
videoFrames = videoFrames.filter((_, index) => index % step === 0).slice(0, MAX_FRAMES);
|
|
@@ -391,18 +391,29 @@ export class BiometricIdentitySDK {
|
|
|
391
391
|
});
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
+
const compressedFrontImage = await this.compressImage(this.state.frontID.data);
|
|
395
|
+
const compressedBackImage = this.state.backID?.data
|
|
396
|
+
? await this.compressImage(this.state.backID.data)
|
|
397
|
+
: undefined;
|
|
398
|
+
const compressedFrames = await Promise.all(
|
|
399
|
+
videoFrames.map(frame => this.compressImage(frame))
|
|
400
|
+
);
|
|
401
|
+
|
|
394
402
|
logger.info('Sending validation request to backend', {
|
|
395
|
-
framesCount:
|
|
403
|
+
framesCount: compressedFrames.length,
|
|
396
404
|
duration: this.state.videoData.duration,
|
|
397
405
|
challengesCount: this.state.videoData.challengesCompleted?.length || 0,
|
|
398
|
-
frontImageSize:
|
|
399
|
-
backImageSize:
|
|
406
|
+
frontImageSize: compressedFrontImage.length,
|
|
407
|
+
backImageSize: compressedBackImage?.length || 0,
|
|
408
|
+
originalFrontSize: this.state.frontID.data?.length || 0,
|
|
409
|
+
originalBackSize: this.state.backID?.data?.length || 0,
|
|
410
|
+
compressionRatio: compressedFrontImage.length / (this.state.frontID.data?.length || 1)
|
|
400
411
|
});
|
|
401
412
|
|
|
402
413
|
const response = await this.backendClient.fullValidation({
|
|
403
|
-
frontIdImage:
|
|
404
|
-
backIdImage:
|
|
405
|
-
videoFrames:
|
|
414
|
+
frontIdImage: compressedFrontImage,
|
|
415
|
+
backIdImage: compressedBackImage,
|
|
416
|
+
videoFrames: compressedFrames,
|
|
406
417
|
videoDurationMs: this.state.videoData.duration,
|
|
407
418
|
challengesCompleted: this.state.videoData.challengesCompleted || [],
|
|
408
419
|
});
|
|
@@ -486,6 +497,72 @@ export class BiometricIdentitySDK {
|
|
|
486
497
|
});
|
|
487
498
|
}
|
|
488
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Compress base64 image - simplified version that works in all environments
|
|
502
|
+
* For React Native, images should be compressed at capture time
|
|
503
|
+
* This is a no-op for now - compression should happen at capture time in React Native
|
|
504
|
+
*/
|
|
505
|
+
private async compressImage(base64Image: string): Promise<string> {
|
|
506
|
+
if (!base64Image || base64Image.length === 0) {
|
|
507
|
+
return base64Image;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const MAX_SIZE = 1024 * 1024;
|
|
511
|
+
if (base64Image.length < MAX_SIZE) {
|
|
512
|
+
return base64Image;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
try {
|
|
516
|
+
const globalWindow = (globalThis as any).window;
|
|
517
|
+
if (globalWindow && globalWindow.Image && globalWindow.document) {
|
|
518
|
+
return await this.compressImageBrowser(base64Image, globalWindow);
|
|
519
|
+
}
|
|
520
|
+
} catch (error) {
|
|
521
|
+
logger.warn('Image compression not available, using original', error);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return base64Image;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Compress image in browser environment using Canvas API
|
|
529
|
+
*/
|
|
530
|
+
private async compressImageBrowser(base64Image: string, window: any): Promise<string> {
|
|
531
|
+
return new Promise((resolve, reject) => {
|
|
532
|
+
const img = new window.Image();
|
|
533
|
+
img.onload = () => {
|
|
534
|
+
const canvas = window.document.createElement('canvas');
|
|
535
|
+
const maxWidth = 1920;
|
|
536
|
+
const maxHeight = 1920;
|
|
537
|
+
let width = img.width;
|
|
538
|
+
let height = img.height;
|
|
539
|
+
|
|
540
|
+
if (width > maxWidth || height > maxHeight) {
|
|
541
|
+
const ratio = Math.min(maxWidth / width, maxHeight / height);
|
|
542
|
+
width = width * ratio;
|
|
543
|
+
height = height * ratio;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
canvas.width = width;
|
|
547
|
+
canvas.height = height;
|
|
548
|
+
|
|
549
|
+
const ctx = canvas.getContext('2d');
|
|
550
|
+
if (!ctx) {
|
|
551
|
+
reject(new Error('Could not get canvas context'));
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
556
|
+
|
|
557
|
+
const compressedBase64 = canvas.toDataURL('image/jpeg', 0.85);
|
|
558
|
+
const base64 = compressedBase64.split(',')[1];
|
|
559
|
+
resolve(base64);
|
|
560
|
+
};
|
|
561
|
+
img.onerror = reject;
|
|
562
|
+
img.src = `data:image/jpeg;base64,${base64Image}`;
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
|
|
489
566
|
/**
|
|
490
567
|
* Get current SDK state
|
|
491
568
|
*/
|