UNPKG

bry-biometric-collector

Version:

BRy web-collector component for biometric capture.

133 lines (132 loc) 5.4 kB
import { u as D, $ as C, n as b, g as y, i as M, s as l, a as F, l as U, F as L, b as x, c as E, v as P, d as B, e as W, A as v, f as $, h as I, j as g, k, m as q, o as R, p as V, q as X, r as p, t as G } from "./main_8f1a8854_3.3.6.js"; import "./face_api_d3d25326_3.3.6.js"; const f = D(C); var Q = /* @__PURE__ */ ((n) => (n.EXTENSION_MISSING = "EXTENSION_MISSING", n.USER_CANCELLED = "USER_CANCELLED", n.UNAUTHORIZED_EXTENSION = "UNAUTHORIZED_EXTENSION", n.SCANNER_NOT_FOUND = "SCANNER_NOT_FOUND", n.EXTENSION_MODULE_NOT_INSTALLED = "EXTENSION_MODULE_NOT_INSTALLED", n.FINGER_NOT_REMOVED = "FINGER_NOT_REMOVED", n.UNKNOWN_ERROR = "UNKNOWN_ERROR", n.EVALUATE_BIOMETRICS_TIMEOUT = "EVALUATE_BIOMETRICS_TIMEOUT", n.EVALUATE_BIOMETRICS_NETWORK_ISSUE = "EVALUATE_BIOMETRICS_NETWORK_ISSUE", n))(Q || {}); class r extends Error { constructor(a, d) { super(a), this.status = d; } } async function z(n, a) { const d = b([n])[0], T = y(); if (M(T)) throw new r( "Attempting to capture finger but the extension apparently hasn't been properly injected. Received: " + T, "EXTENSION_MISSING" /* EXTENSION_MISSING */ ); if (l(!0), F()) throw l(!1), p(!1), new r( "User cancelled", "USER_CANCELLED" /* USER_CANCELLED */ ); let c = null; try { c = await T.getFingerprint( // @ts-ignore TODO: Alex has to fix this functions signature to accept pojo JSON.stringify( a ?? { outputFormat: "BASE64", imageFormat: "BMP", nonce: "webCollector", timeout: 3 } ) ); } catch (e) { U(e); const t = e; throw l(!1), t.key === "fingerprint.scanner.timeout" ? new r( "Fingerprint scan timed out (didn't read a finger.)", "USER_CANCELLED" /* USER_CANCELLED */ ) : t.key === "extension.authorization.canceled" ? new r( "Extension wasn't given authorization.", "UNAUTHORIZED_EXTENSION" /* UNAUTHORIZED_EXTENSION */ ) : t.key === "fingerprint.scanner.not.found" ? new r( "Couldn't find fingerprint scanner.", "SCANNER_NOT_FOUND" /* SCANNER_NOT_FOUND */ ) : t.key === "signer.not.installed" ? new r( "The extension module isn't installed.", "EXTENSION_MODULE_NOT_INSTALLED" /* EXTENSION_MODULE_NOT_INSTALLED */ ) : new r( "Couldn't capture fingerprint: " + t.description, "UNKNOWN_ERROR" /* UNKNOWN_ERROR */ ); } if (F()) throw l(!1), p(!1), new r( "User cancelled", "USER_CANCELLED" /* USER_CANCELLED */ ); const i = H(d); i.image = c?.content.image?.data, i.base64WSQ = c?.content.fingerprint.data, i.nfiqRating = (c?.content.score || 0) + 98, i.status = L.AVAILABLE; const w = x(E()); let s, O = !1; try { s = await P(w, i); } catch (e) { if (i.nfiqRating = -1, i.base64WSQ = "", i.image = "", B("caught while validating fingerprint: ", e.toString()), W(e) && "message" in e && e.message === "error.template.extraction") O = !0; else if (e instanceof XMLHttpRequest) { const t = e; "response" in t && "data" in t.response.data && t.response.data.message === "error.template.extraction" && (O = !0); } else { if (e instanceof v) throw e.code === "ECONNABORTED" ? ($("The evaluate biometrics request took too long to answer!"), new r( "Evaluate biometrics took too long to reply", "EVALUATE_BIOMETRICS_TIMEOUT" /* EVALUATE_BIOMETRICS_TIMEOUT */ )) : (U("Error evaluating biometrics!", e), I(E()), l(!1), new r( "Network issue while validating biometrics, check logs", "EVALUATE_BIOMETRICS_NETWORK_ISSUE" /* EVALUATE_BIOMETRICS_NETWORK_ISSUE */ )); I(E()), l(!1); } } let S, N, _, A, u, o = g.LOW_QUALITY; if (s) { const e = s.bodyParts.find( (t) => t.bodyPart === i.bodyPart ); i.nfiqRating = e.quality, (e.quality > k() || e.status === "LOW_QUALITY") && (S = !0, o = g.LOW_QUALITY), s.bodyParts.find((t) => t.status === "DUPLICATE") && (N = !0, o = g.DUPLICATE), s.bodyParts.find((t) => t.status === "FORBIDDEN") && (_ = !0, o = g.FORBIDDEN), s.bodyParts.find((t) => t.status === "AGR") && (A = !0, o = g.AGR_DETECTED), s.bodyParts.find((t) => t.status === "AGR_NOT_MATCH") && (u = !0, o = g.AGR_NO_MATCH); } if (N || S || _ || u || A || O) { i.nfiqRating = -1, i.base64WSQ = "", i.image = "", i.status = L.AVAILABLE; let e = "badFingerQualitySwal"; N ? e = "unknownDuplicateFingerSwal" : _ ? e = "forbiddenFingerSwal" : A ? e = "agrFinger" : u && (e = "agrFingerNotMatched"); let t = f(`${e}.text`); if (q(G) && N) { e = "duplicateFingerSwal", t = f(`${e}.text`, { values: { finger1: f(`${e}.${s.matchingFingers?.[0]}`), finger2: f(`${e}.${s.matchingFingers?.[1]}`) } }); const m = R(); return { returnCode: o, bodyParts: m, matchingFingers: s.matchingFingers, message: t }; } const h = R(); return { returnCode: o, bodyParts: h, message: t }; } return I(E()), l(!1), V(), { returnCode: g.CAPTURED, bodyParts: R() }; } function H(n) { X(); for (const a of E()) if (a.index === n) return a.selected = !0, a; throw new Error(`Finger ${n} not found`); } export { r as CaptureApiError, Q as CaptureErrorStatusEnum, z as captureSingleFinger };