bry-biometric-collector
Version:
BRy web-collector component for biometric capture.
133 lines (132 loc) • 5.42 kB
JavaScript
import { u as m, $ as D, n as C, g as b, i as y, s as l, a as F, F as U, b as M, c, v as x, d as P, A as B, e as I, h as g, f as v, j as W, k as R, l as $, m as k, o as w, p as V } from "./main_f7bde95f_3.2.1.js";
import "./face_api_0e3ce8c8_3.2.1.js";
const f = m(D);
var X = /* @__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))(X || {});
class r extends Error {
constructor(a, d) {
super(a), this.status = d;
}
}
async function H(n, a) {
const d = C([n])[0], T = b();
if (y(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), w(!1), new r(
"User cancelled",
"USER_CANCELLED"
/* USER_CANCELLED */
);
let E = null;
try {
E = 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) {
console.error(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), w(!1), new r(
"User cancelled",
"USER_CANCELLED"
/* USER_CANCELLED */
);
const i = q(d);
i.image = E?.content.image?.data, i.base64WSQ = E?.content.fingerprint.data, i.nfiqRating = (E?.content.score || 0) + 98, i.status = U.AVAILABLE;
const L = M(c());
let s, O = !1;
try {
s = await x(L, i);
} catch (e) {
if (i.nfiqRating = -1, i.base64WSQ = "", i.image = "", console.warn("caught while validating fingerprint: ", e.toString()), P(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 B)
throw e.code === "ECONNABORTED" ? (console.log("The evaluate biometrics request took too long to answer!"), new r(
"Evaluate biometrics took too long to reply",
"EVALUATE_BIOMETRICS_TIMEOUT"
/* EVALUATE_BIOMETRICS_TIMEOUT */
)) : (console.error("Error evaluating biometrics!", e), I(c()), l(!1), new r(
"Network issue while validating biometrics, check logs",
"EVALUATE_BIOMETRICS_NETWORK_ISSUE"
/* EVALUATE_BIOMETRICS_NETWORK_ISSUE */
));
I(c()), 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 > v() || 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 = U.AVAILABLE;
let e = "badFingerQualitySwal";
N ? e = "unknownDuplicateFingerSwal" : _ ? e = "forbiddenFingerSwal" : A ? e = "agrFinger" : u && (e = "agrFingerNotMatched");
let t = f(`${e}.text`);
if (W(V) && N) {
e = "duplicateFingerSwal", t = f(`${e}.text`, {
values: {
finger1: f(`${e}.${s.matchingFingers?.[0]}`),
finger2: f(`${e}.${s.matchingFingers?.[1]}`)
}
});
const h = R();
return {
returnCode: o,
bodyParts: h,
matchingFingers: s.matchingFingers,
message: t
};
}
const p = R();
return { returnCode: o, bodyParts: p, message: t };
}
return I(c()), l(!1), $(), { returnCode: g.CAPTURED, bodyParts: R() };
}
function q(n) {
k();
for (const a of c())
if (a.index === n)
return a.selected = !0, a;
throw new Error(`Finger ${n} not found`);
}
export {
r as CaptureApiError,
X as CaptureErrorStatusEnum,
H as captureSingleFinger
};