@authme/identity-verification 2.8.51 → 2.8.54

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.
Files changed (3) hide show
  1. package/index.cjs.js +51 -12
  2. package/index.esm.js +51 -12
  3. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -34998,12 +34998,14 @@ class MRZModule {
34998
34998
  let uploadFullFrame = false;
34999
34999
  let pubKey = '';
35000
35000
  let latestTField = null;
35001
+ let currentCardType = null;
35001
35002
  const virtualCanvas = document.createElement('canvas');
35002
35003
  const docInfos = {};
35003
35004
  let shouldEncrypt = false;
35004
35005
  const encryptImageBase64 = async function encryptImageBase64(blob) {
35005
35006
  const imageArrayBuffer = await blobToArrayBuffer(blob);
35006
- const resultEncrypt = await _this.mrzService.encryptBlob(imageArrayBuffer, pubKey);
35007
+ const uint8Array = new Uint8Array(imageArrayBuffer);
35008
+ const resultEncrypt = await _this.mrzService.encryptBlob(uint8Array, pubKey);
35007
35009
  return resultEncrypt;
35008
35010
  };
35009
35011
  const blobToArrayBuffer = async function blobToArrayBuffer(blob) {
@@ -35040,6 +35042,8 @@ class MRZModule {
35040
35042
  frameHeight = height;
35041
35043
  const resp = await SendRequestWithRetry$1(() => idRecognition.initScan(config.type, config.country, config.needConfirm, config.cardTypes));
35042
35044
  shouldEncrypt = (_resp$shouldEncrypt = resp.shouldEncrypt) != null ? _resp$shouldEncrypt : shouldEncrypt;
35045
+ util.Storage.setItem('shouldEncrypt', shouldEncrypt);
35046
+ util.Storage.setItem('encryptDataBase64', encryptDataBase64);
35043
35047
  pubKey = resp.parameters.pubKey;
35044
35048
  scanId = resp.scanId;
35045
35049
  uploadFullFrame = (_resp$parameters$frau = (_resp$parameters$frau2 = resp.parameters.fraud) == null ? void 0 : _resp$parameters$frau2.collectAllFrames) != null ? _resp$parameters$frau : config.uploadFullFrame;
@@ -35059,9 +35063,15 @@ class MRZModule {
35059
35063
  });
35060
35064
  },
35061
35065
  ocrStart: async function (points, type, setBorderType, setCardBorderColor, setBorderSuccess, scanAnimationContainer, successAnimationContainer, frameImage, frameText, faceMode, cardType, retry = false) {
35066
+ currentCardType = type;
35062
35067
  await _this.mrzService.init();
35063
35068
  await _this.mrzService.setFrameSize(frameWidth, frameHeight);
35064
35069
  await _this.mrzService.setMaskPosition(points.map(([x, y]) => [Number(x.toFixed(2)), Number(y.toFixed(2))]));
35070
+ const oldParams = await _this.mrzService.getParams();
35071
+ await _this.mrzService.setParams(Object.assign({}, oldParams, {
35072
+ fImageBlurTh: 750,
35073
+ fCardMatchTh: 0.3
35074
+ }));
35065
35075
  await _this.mrzService.startSession();
35066
35076
  if (retry) {
35067
35077
  docInfos[type].ocrImg = null;
@@ -35100,6 +35110,7 @@ class MRZModule {
35100
35110
  },
35101
35111
  acceptTypes,
35102
35112
  recognition: async function (data) {
35113
+ var _docInfos$currentCard;
35103
35114
  const mrzResult = await _this.mrzService.recognition(data);
35104
35115
  if (_this.canvas) {
35105
35116
  var _this$mrzService;
@@ -35114,8 +35125,28 @@ class MRZModule {
35114
35125
  imgData.data.set(debugData);
35115
35126
  ctx.putImageData(imgData, 0, 0);
35116
35127
  }
35117
- if (mrzResult.eStatus === idRecognition.EAuthMeMRZServiceStatus.Success && !!docInfos[idRecognition.EAuthMeCardClass.Passport].docId) {
35118
- docInfos[idRecognition.EAuthMeCardClass.Passport].ocrOriginImg = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
35128
+ if (mrzResult.eStatus === idRecognition.EAuthMeMRZServiceStatus.Success) {
35129
+ const cardType = currentCardType;
35130
+ const ocrOriginImg = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
35131
+ // V9: 如果有卡片圖像就使用它,否則使用原始幀圖像
35132
+ let resultOcrImg;
35133
+ if (mrzResult.imageData && mrzResult.iWidth > 0 && mrzResult.iHeight > 0) {
35134
+ resultOcrImg = util.UintArrayToBlob(mrzResult.iWidth, mrzResult.iHeight, mrzResult.imageData, virtualCanvas);
35135
+ } else {
35136
+ resultOcrImg = ocrOriginImg;
35137
+ }
35138
+ // 存圖不等 docId — 避免競態條件導致圖片遺失
35139
+ if (!docInfos[cardType]) {
35140
+ docInfos[cardType] = {
35141
+ docId: '',
35142
+ ocrImg: null,
35143
+ ocrOriginImg: null,
35144
+ fraudOriginImg: null,
35145
+ fraudResult: null
35146
+ };
35147
+ }
35148
+ docInfos[cardType].ocrImg = resultOcrImg;
35149
+ docInfos[cardType].ocrOriginImg = ocrOriginImg;
35119
35150
  await _this.mrzService.stop();
35120
35151
  // 1. 最後結果統一使用 getFinalResult 取得的結果。
35121
35152
  // 2. 由於 engine-lib 限制,getFinalResult 必須要在 stop 之後呼叫。
@@ -35159,13 +35190,13 @@ class MRZModule {
35159
35190
  }
35160
35191
  }
35161
35192
  }
35162
- } else if (uploadFullFrame) {
35193
+ } else if (uploadFullFrame && currentCardType && (_docInfos$currentCard = docInfos[currentCardType]) != null && _docInfos$currentCard.docId) {
35163
35194
  const image = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
35164
35195
  const requestImg = await encryptImageBase64(image);
35165
- // downloadImage(image, `${frameIndex}-${docInfos[type as EAuthMeCardClass].docId}-${new Date().getTime().toString()}.jpg`)
35196
+ const uploadCardType = currentCardType;
35166
35197
  util.backgroundRequest(async function () {
35167
35198
  const postData = {
35168
- scanDocumentId: docInfos[idRecognition.EAuthMeCardClass.Passport].docId,
35199
+ scanDocumentId: docInfos[uploadCardType].docId,
35169
35200
  image: requestImg,
35170
35201
  type: idRecognition.ResourceImageType.Recognition,
35171
35202
  info: {
@@ -35194,10 +35225,15 @@ class MRZModule {
35194
35225
  }
35195
35226
  },
35196
35227
  confirmImage: async function (option) {
35197
- const docId = docInfos[option.type].docId;
35228
+ var _docInfos$option$type;
35229
+ const docId = (_docInfos$option$type = docInfos[option.type]) == null ? void 0 : _docInfos$option$type.docId;
35198
35230
  if (docId) {
35199
35231
  docInfos[option.type].docId = '';
35200
- const requestImg = await encryptImageBase64(docInfos[option.type].ocrOriginImg);
35232
+ const ocrOriginImg = docInfos[option.type].ocrOriginImg;
35233
+ if (!ocrOriginImg) {
35234
+ throw new core.AuthmeError(core.ErrorCode.SDK_INTERNAL_ERROR, 'MRZ card image not available for upload');
35235
+ }
35236
+ const requestImg = await encryptImageBase64(ocrOriginImg);
35201
35237
  const report = await _this.mrzService.getReport();
35202
35238
  await SendRequestWithRetry$1(async function () {
35203
35239
  const postData = {
@@ -35210,7 +35246,7 @@ class MRZModule {
35210
35246
  }
35211
35247
  };
35212
35248
  if (shouldEncrypt) {
35213
- postData.image = await blobToBase64(docInfos[option.type].ocrOriginImg);
35249
+ postData.image = await blobToBase64(ocrOriginImg);
35214
35250
  return idRecognition.uploadFrameBase64({
35215
35251
  id: scanId,
35216
35252
  encryptedBase64String: await encryptDataBase64(postData)
@@ -35638,7 +35674,8 @@ class OCRModule {
35638
35674
  const docInfos = {};
35639
35675
  const encryptImageBase64 = async function encryptImageBase64(blob) {
35640
35676
  const imageArrayBuffer = await blobToArrayBuffer(blob);
35641
- const resultEncrypt = await _this.ocrService.encryptBlob(imageArrayBuffer, pubKey);
35677
+ const uint8Array = new Uint8Array(imageArrayBuffer);
35678
+ const resultEncrypt = await _this.ocrService.encryptBlob(uint8Array, pubKey);
35642
35679
  return resultEncrypt;
35643
35680
  };
35644
35681
  const blobToArrayBuffer = async function blobToArrayBuffer(blob) {
@@ -35775,6 +35812,9 @@ class OCRModule {
35775
35812
  _this.engine.setPublicKeyForJson('');
35776
35813
  }
35777
35814
  if (config.type === idRecognition.IdRecognitionCardType.IDCard && config.needAntiFraud) {
35815
+ if (!resp.parameters.fraud) {
35816
+ throw new core.AuthmeError(core.ErrorCode.ANTI_FRAUD_INIT_ERROR, 'Anti-fraud feature is not enabled on the server');
35817
+ }
35778
35818
  // 先設定 stage 再 init,避免使用預設的 Frontal stage
35779
35819
  await _this.antiFraudInstance.setStage(antiFraudStageList);
35780
35820
  await _this.antiFraudInstance.init();
@@ -36841,7 +36881,6 @@ class OCRModule {
36841
36881
  throw new core.AuthmeError(core.ErrorCode.EVENT_NAME_WRONG);
36842
36882
  }))).pipe(rxjs.tap(downloadDebugLogs)));
36843
36883
  } catch (error) {
36844
- console.error(error);
36845
36884
  const catchedError = error instanceof core.AuthmeError ? error : new core.AuthmeError(core.ErrorCode.SDK_INTERNAL_ERROR, error);
36846
36885
  downloadDebugLogs();
36847
36886
  return {
@@ -37322,7 +37361,7 @@ class AuthmeIdentityVerification extends engine.AuthmeFunctionModule {
37322
37361
  }
37323
37362
 
37324
37363
  var name = "authme/sdk";
37325
- var version$1 = "2.8.51";
37364
+ var version$1 = "2.8.54";
37326
37365
  var packageInfo = {
37327
37366
  name: name,
37328
37367
  version: version$1};
package/index.esm.js CHANGED
@@ -34996,12 +34996,14 @@ class MRZModule {
34996
34996
  let uploadFullFrame = false;
34997
34997
  let pubKey = '';
34998
34998
  let latestTField = null;
34999
+ let currentCardType = null;
34999
35000
  const virtualCanvas = document.createElement('canvas');
35000
35001
  const docInfos = {};
35001
35002
  let shouldEncrypt = false;
35002
35003
  const encryptImageBase64 = async function encryptImageBase64(blob) {
35003
35004
  const imageArrayBuffer = await blobToArrayBuffer(blob);
35004
- const resultEncrypt = await _this.mrzService.encryptBlob(imageArrayBuffer, pubKey);
35005
+ const uint8Array = new Uint8Array(imageArrayBuffer);
35006
+ const resultEncrypt = await _this.mrzService.encryptBlob(uint8Array, pubKey);
35005
35007
  return resultEncrypt;
35006
35008
  };
35007
35009
  const blobToArrayBuffer = async function blobToArrayBuffer(blob) {
@@ -35038,6 +35040,8 @@ class MRZModule {
35038
35040
  frameHeight = height;
35039
35041
  const resp = await SendRequestWithRetry$1(() => initScan(config.type, config.country, config.needConfirm, config.cardTypes));
35040
35042
  shouldEncrypt = (_resp$shouldEncrypt = resp.shouldEncrypt) != null ? _resp$shouldEncrypt : shouldEncrypt;
35043
+ Storage.setItem('shouldEncrypt', shouldEncrypt);
35044
+ Storage.setItem('encryptDataBase64', encryptDataBase64);
35041
35045
  pubKey = resp.parameters.pubKey;
35042
35046
  scanId = resp.scanId;
35043
35047
  uploadFullFrame = (_resp$parameters$frau = (_resp$parameters$frau2 = resp.parameters.fraud) == null ? void 0 : _resp$parameters$frau2.collectAllFrames) != null ? _resp$parameters$frau : config.uploadFullFrame;
@@ -35057,9 +35061,15 @@ class MRZModule {
35057
35061
  });
35058
35062
  },
35059
35063
  ocrStart: async function (points, type, setBorderType, setCardBorderColor, setBorderSuccess, scanAnimationContainer, successAnimationContainer, frameImage, frameText, faceMode, cardType, retry = false) {
35064
+ currentCardType = type;
35060
35065
  await _this.mrzService.init();
35061
35066
  await _this.mrzService.setFrameSize(frameWidth, frameHeight);
35062
35067
  await _this.mrzService.setMaskPosition(points.map(([x, y]) => [Number(x.toFixed(2)), Number(y.toFixed(2))]));
35068
+ const oldParams = await _this.mrzService.getParams();
35069
+ await _this.mrzService.setParams(Object.assign({}, oldParams, {
35070
+ fImageBlurTh: 750,
35071
+ fCardMatchTh: 0.3
35072
+ }));
35063
35073
  await _this.mrzService.startSession();
35064
35074
  if (retry) {
35065
35075
  docInfos[type].ocrImg = null;
@@ -35098,6 +35108,7 @@ class MRZModule {
35098
35108
  },
35099
35109
  acceptTypes,
35100
35110
  recognition: async function (data) {
35111
+ var _docInfos$currentCard;
35101
35112
  const mrzResult = await _this.mrzService.recognition(data);
35102
35113
  if (_this.canvas) {
35103
35114
  var _this$mrzService;
@@ -35112,8 +35123,28 @@ class MRZModule {
35112
35123
  imgData.data.set(debugData);
35113
35124
  ctx.putImageData(imgData, 0, 0);
35114
35125
  }
35115
- if (mrzResult.eStatus === EAuthMeMRZServiceStatus.Success && !!docInfos[EAuthMeCardClass.Passport].docId) {
35116
- docInfos[EAuthMeCardClass.Passport].ocrOriginImg = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
35126
+ if (mrzResult.eStatus === EAuthMeMRZServiceStatus.Success) {
35127
+ const cardType = currentCardType;
35128
+ const ocrOriginImg = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
35129
+ // V9: 如果有卡片圖像就使用它,否則使用原始幀圖像
35130
+ let resultOcrImg;
35131
+ if (mrzResult.imageData && mrzResult.iWidth > 0 && mrzResult.iHeight > 0) {
35132
+ resultOcrImg = UintArrayToBlob(mrzResult.iWidth, mrzResult.iHeight, mrzResult.imageData, virtualCanvas);
35133
+ } else {
35134
+ resultOcrImg = ocrOriginImg;
35135
+ }
35136
+ // 存圖不等 docId — 避免競態條件導致圖片遺失
35137
+ if (!docInfos[cardType]) {
35138
+ docInfos[cardType] = {
35139
+ docId: '',
35140
+ ocrImg: null,
35141
+ ocrOriginImg: null,
35142
+ fraudOriginImg: null,
35143
+ fraudResult: null
35144
+ };
35145
+ }
35146
+ docInfos[cardType].ocrImg = resultOcrImg;
35147
+ docInfos[cardType].ocrOriginImg = ocrOriginImg;
35117
35148
  await _this.mrzService.stop();
35118
35149
  // 1. 最後結果統一使用 getFinalResult 取得的結果。
35119
35150
  // 2. 由於 engine-lib 限制,getFinalResult 必須要在 stop 之後呼叫。
@@ -35157,13 +35188,13 @@ class MRZModule {
35157
35188
  }
35158
35189
  }
35159
35190
  }
35160
- } else if (uploadFullFrame) {
35191
+ } else if (uploadFullFrame && currentCardType && (_docInfos$currentCard = docInfos[currentCardType]) != null && _docInfos$currentCard.docId) {
35161
35192
  const image = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
35162
35193
  const requestImg = await encryptImageBase64(image);
35163
- // downloadImage(image, `${frameIndex}-${docInfos[type as EAuthMeCardClass].docId}-${new Date().getTime().toString()}.jpg`)
35194
+ const uploadCardType = currentCardType;
35164
35195
  backgroundRequest(async function () {
35165
35196
  const postData = {
35166
- scanDocumentId: docInfos[EAuthMeCardClass.Passport].docId,
35197
+ scanDocumentId: docInfos[uploadCardType].docId,
35167
35198
  image: requestImg,
35168
35199
  type: ResourceImageType.Recognition,
35169
35200
  info: {
@@ -35192,10 +35223,15 @@ class MRZModule {
35192
35223
  }
35193
35224
  },
35194
35225
  confirmImage: async function (option) {
35195
- const docId = docInfos[option.type].docId;
35226
+ var _docInfos$option$type;
35227
+ const docId = (_docInfos$option$type = docInfos[option.type]) == null ? void 0 : _docInfos$option$type.docId;
35196
35228
  if (docId) {
35197
35229
  docInfos[option.type].docId = '';
35198
- const requestImg = await encryptImageBase64(docInfos[option.type].ocrOriginImg);
35230
+ const ocrOriginImg = docInfos[option.type].ocrOriginImg;
35231
+ if (!ocrOriginImg) {
35232
+ throw new AuthmeError(ErrorCode.SDK_INTERNAL_ERROR, 'MRZ card image not available for upload');
35233
+ }
35234
+ const requestImg = await encryptImageBase64(ocrOriginImg);
35199
35235
  const report = await _this.mrzService.getReport();
35200
35236
  await SendRequestWithRetry$1(async function () {
35201
35237
  const postData = {
@@ -35208,7 +35244,7 @@ class MRZModule {
35208
35244
  }
35209
35245
  };
35210
35246
  if (shouldEncrypt) {
35211
- postData.image = await blobToBase64(docInfos[option.type].ocrOriginImg);
35247
+ postData.image = await blobToBase64(ocrOriginImg);
35212
35248
  return uploadFrameBase64({
35213
35249
  id: scanId,
35214
35250
  encryptedBase64String: await encryptDataBase64(postData)
@@ -35636,7 +35672,8 @@ class OCRModule {
35636
35672
  const docInfos = {};
35637
35673
  const encryptImageBase64 = async function encryptImageBase64(blob) {
35638
35674
  const imageArrayBuffer = await blobToArrayBuffer(blob);
35639
- const resultEncrypt = await _this.ocrService.encryptBlob(imageArrayBuffer, pubKey);
35675
+ const uint8Array = new Uint8Array(imageArrayBuffer);
35676
+ const resultEncrypt = await _this.ocrService.encryptBlob(uint8Array, pubKey);
35640
35677
  return resultEncrypt;
35641
35678
  };
35642
35679
  const blobToArrayBuffer = async function blobToArrayBuffer(blob) {
@@ -35773,6 +35810,9 @@ class OCRModule {
35773
35810
  _this.engine.setPublicKeyForJson('');
35774
35811
  }
35775
35812
  if (config.type === IdRecognitionCardType.IDCard && config.needAntiFraud) {
35813
+ if (!resp.parameters.fraud) {
35814
+ throw new AuthmeError(ErrorCode.ANTI_FRAUD_INIT_ERROR, 'Anti-fraud feature is not enabled on the server');
35815
+ }
35776
35816
  // 先設定 stage 再 init,避免使用預設的 Frontal stage
35777
35817
  await _this.antiFraudInstance.setStage(antiFraudStageList);
35778
35818
  await _this.antiFraudInstance.init();
@@ -36839,7 +36879,6 @@ class OCRModule {
36839
36879
  throw new AuthmeError(ErrorCode.EVENT_NAME_WRONG);
36840
36880
  }))).pipe(tap(downloadDebugLogs)));
36841
36881
  } catch (error) {
36842
- console.error(error);
36843
36882
  const catchedError = error instanceof AuthmeError ? error : new AuthmeError(ErrorCode.SDK_INTERNAL_ERROR, error);
36844
36883
  downloadDebugLogs();
36845
36884
  return {
@@ -37320,7 +37359,7 @@ class AuthmeIdentityVerification extends AuthmeFunctionModule {
37320
37359
  }
37321
37360
 
37322
37361
  var name = "authme/sdk";
37323
- var version$1 = "2.8.51";
37362
+ var version$1 = "2.8.54";
37324
37363
  var packageInfo = {
37325
37364
  name: name,
37326
37365
  version: version$1};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authme/identity-verification",
3
- "version": "2.8.51",
3
+ "version": "2.8.54",
4
4
  "peerDependencies": {
5
5
  "core-js": "^3.6.0",
6
6
  "lottie-web": "^5.9.2",