UNPKG

@waiting/fingerprint-reader-bp8903

Version:
13 lines (11 loc) 2.48 kB
/** * @waiting/fingerprint-reader-bp8903 * 南天 BP8903 集成键盘 指纹采集、验证 * * @version 2.1.2 * @author waiting * @license MIT * @link https://github.com/waitingsong/node-fingerprint-reader-bp8903#readme */ import{DTypes as e}from"win32-def";import{info as t}from"@waiting/log";import{validateDllFile as r,normalize as n}from"@waiting/shared-core";import{Library as o}from"ffi";import{of as i,forkJoin as c}from"rxjs";import{tap as p,retry as s,mergeMap as l}from"rxjs/operators";const a={dllTxt:"",dllSearchPath:"",debug:!1,port:0,searchAll:!1},f={ABC_GetFeature:[e.INT,[e.BYTE,e.POINT,e.INT]],ABC_GetTemplate:[e.INT,[e.BYTE,e.POINT,e.INT]],ABC_Match:[e.INT,[e.POINT,e.POINT]]};function u(e,t){const r=[];if(!(e.port>0))throw new Error("deviceOpts.port must be specified");{const n=d(e.port,e,t);n.openPort>0&&r.push(n)}return r}function d(e,t,r){const n={apib:r,deviceOpts:t,inUse:!1,openPort:e};return n}function m(e,r=1024){e.deviceOpts.debug&&t("staring read once...");const n=Buffer.alloc(r),o=e.apib.ABC_GetFeature(e.openPort,n,r),i=1===o?n:Buffer.alloc(0);return e.deviceOpts.debug&&t(`Fingerprint readOnce code: ${o}. (1:succeed, 0/others:failed)`),i}function g(e,r=1024){e.deviceOpts.debug&&t("staring read thrice...");const n=Buffer.alloc(r),o=e.apib.ABC_GetTemplate(e.openPort,n,r),i=1===o?n:Buffer.alloc(0);return e.deviceOpts.debug&&t(`Fingerprint readThice code: ${o}. (1:succeed, 0/others:failed)`),i}function h(e,t,r){return new Promise(n=>{e.apib.ABC_Match.async(t,r,(e,t)=>(n(1===t),t))})}async function T(e){const n=B(e),{debug:i}=n;i&&t(n),await r(n.dllTxt);const c=o(n.dllTxt,f),p=u(n,c);if(p&&p.length)return p;throw new Error("未找到读卡设备")}function b(e,t="strict"){const r="simple"===t?m(e):g(e),n=O(r);return Promise.resolve(n)}function w(e,t){const r=i(m(e)).pipe(p(e=>{if(!e.byteLength)throw new Error("Sampling result empty. will retry once")}),s(1),p(e=>{if(!e.byteLength)throw new Error("Sampling result empty")})),n=i(Buffer.from(t)).pipe(p(e=>{if(!e.byteLength)throw new Error("Input fingerprint key being validated is invalid")})),o=c(r,n).pipe(l(([t,r])=>h(e,t,r)));return o.toPromise()}function B(e){const t=Object.assign({},a,e);if(!e.dllTxt)throw new Error("params dllTxt undefined or blank");return t.dllTxt=n(t.dllTxt),t}function O(e){const t=e.byteLength?e.toString().replace(/\0+$/,""):"";return t}export{a as initialOpts,T as init,b as sampleFP,w as verifyFP}; //# sourceMappingURL=index.esm.min.js.map