@digitalpersona/devices
Version:
DigitalPersona Security Devices support library
3 lines (2 loc) • 12.7 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@digitalpersona/core"),require("WebSdk")):"function"==typeof define&&define.amd?define(["exports","@digitalpersona/core","WebSdk"],t):t(((e=e||self).dp=e.dp||{},e.dp.devices=e.dp.devices||{}),e.dp.core)}(this,function(e,t){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function r(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var o,i,a=function(){return function(e){this.type=e}}(),s=function(e){function t(){return e.call(this,"CommunicationFailed")||this}return r(t,e),t}(a),c=function(e){function t(t,n){var r=e.call(this,t)||this;return r.deviceId=n,r}return r(t,e),t}(a),u=function(e){function t(t){return e.call(this,"DeviceConnected",t)||this}return r(t,e),t}(c),d=function(e){function t(t){return e.call(this,"DeviceDisconnected",t)||this}return r(t,e),t}(c);(o=e.CardType||(e.CardType={}))[o.Contact=1]="Contact",o[o.Contactless=2]="Contactless",o[o.Proximity=4]="Proximity",(i=e.CardAttributes||(e.CardAttributes={}))[i.SupportsPIN=1]="SupportsPIN",i[i.SupportsUID=2]="SupportsUID",i[i.IsPKI=65536]="IsPKI",i[i.IsPIV=131072]="IsPIV",i[i.IsReadOnly=2147483648]="IsReadOnly";var f,h=function(e){function t(t,n){var r=e.call(this,"CardInserted",t)||this;return r.cardId=n,r}return r(t,e),t}(c),l=function(e){function t(t,n){var r=e.call(this,"CardRemoved",t)||this;return r.cardId=n,r}return r(t,e),t}(c),p=function(){function e(){this.handlers={}}return e.prototype._on=function(e,t){return this.handlers[e]=this.handlers[e]||[],this.handlers[e].push(t),t},e.prototype._off=function(e,t){if(e){var n=this.handlers[e];n&&(t?this.handlers[e]=n.filter(function(e){return e!==t}):delete this.handlers[e])}else this.handlers={};return this},e.prototype.emit=function(e){var t=this;if(e){var n=e.type,r=this["on"+n];r&&this.invoke(r,e);var o=this.handlers[n];o&&o.forEach(function(n){return t.invoke(n,e)})}},e.prototype.invoke=function(e,t){try{e(t)}catch(e){console.error(e)}},e}();!function(e){e[e.Response=0]="Response",e[e.Notification=1]="Notification"}(f||(f={}));var m,C,v=function(){function e(e,t){this.pending=[],this.webChannel=new WebSdk.WebChannelClient(e,t),this.webChannel.onConnectionSucceed=this.onConnectionSucceed.bind(this),this.webChannel.onConnectionFailed=this.onConnectionFailed.bind(this),this.webChannel.onDataReceivedTxt=this.onDataReceivedTxt.bind(this)}return e.prototype.send=function(e,t){var n=new Promise(function(n,r){e.resolve=n,e.reject=r,t&&(e.timer=window.setTimeout(function(){if(e.timer)try{e.reject(new Error("Timeout"))}catch(e){}},t))});return this.pending.push(e),this.webChannel.isConnected()?this.processRequestQueue():this.webChannel.connect(),n},e.prototype.onConnectionSucceed=function(){this.processRequestQueue()},e.prototype.onConnectionFailed=function(){if(this.pending.forEach(function(e){return e.reject(new Error("Communication failure."))}),this.pending=[],this.onCommunicationError)try{this.onCommunicationError()}catch(e){}},e.prototype.onDataReceivedTxt=function(e){var n=JSON.parse(t.Utf8.fromBase64Url(e));if(n.Type===f.Response){var r=JSON.parse(t.Utf8.fromBase64Url(n.Data||"")),o=this.findRequest(r);if(null!==o){o.timer&&(window.clearTimeout(o.timer),delete o.timer);var i=r.Result>>>0;i>2147483647?o.reject(new Error("0x"+i.toString(16))):o.resolve(r)}else console.log("Orphaned response: "+n.Type)}else if(n.Type===f.Notification){var a=JSON.parse(t.Utf8.fromBase64Url(n.Data||""));if(this.onNotification)try{this.onNotification(a)}catch(e){}}else console.log("Unknown message type: "+n.Type)},e.prototype.processRequestQueue=function(){var e=this;this.pending.forEach(function(n,r,o){n.sent||(e.webChannel.sendDataTxt(t.Base64Url.fromJSON(n.command)),o[r].sent=!0)})},e.prototype.findRequest=function(e){for(var t=0;t<this.pending.length;t++){var n=this.pending[t];if(n.sent&&n.command.Method===e.Method)return this.pending.splice(t,1),n}return null},e}(),w=function(){return function(e,t){this.Method=e,this.Parameters=t}}(),D=function(){return function(e){this.command=e,this.sent=!1}}();!function(e){e[e.EnumerateReaders=1]="EnumerateReaders",e[e.EnumerateCards=2]="EnumerateCards",e[e.GetCardInfo=3]="GetCardInfo",e[e.GetCardUID=4]="GetCardUID",e[e.GetDPCardAuthData=5]="GetDPCardAuthData",e[e.GetDPCardEnrollData=6]="GetDPCardEnrollData",e[e.Subscribe=100]="Subscribe",e[e.Unsubscribe=101]="Unsubscribe"}(m||(m={})),function(e){e[e.ReaderConnected=1]="ReaderConnected",e[e.ReaderDisconnected=2]="ReaderDisconnected",e[e.CardInserted=3]="CardInserted",e[e.CardRemoved=4]="CardRemoved"}(C||(C={}));var y,S,N,U,T,g=function(e){function n(t){var n=e.call(this)||this;return n.channel=new v("smartcards",t),n.channel.onCommunicationError=n.onConnectionFailed.bind(n),n.channel.onNotification=n.processNotification.bind(n),n}return r(n,e),n.prototype.on=function(e,t){return this._on(e,t)},n.prototype.off=function(e,t){return this._off(e,t)},n.prototype.enumerateReaders=function(){return this.channel.send(new D(new w(m.EnumerateReaders))).then(function(e){var n=JSON.parse(t.Utf8.fromBase64Url(e.Data||"{}"));return JSON.parse(n.Readers||"[]")})},n.prototype.enumerateCards=function(){return this.channel.send(new D(new w(m.EnumerateCards))).then(function(e){var n=JSON.parse(t.Utf8.fromBase64Url(e.Data||"{}"));return JSON.parse(n.Cards||"[]").map(function(e){return JSON.parse(t.Utf16.fromBase64Url(e))})})},n.prototype.getCardInfo=function(e){return this.channel.send(new D(new w(m.GetCardInfo,t.Base64Url.fromJSON({Reader:e})))).then(function(e){return JSON.parse(t.Utf8.fromBase64Url(e.Data||"null"))})},n.prototype.getCardUid=function(e){return this.channel.send(new D(new w(m.GetCardUID,t.Base64Url.fromJSON({Reader:e})))).then(function(e){return t.Base64.fromBase64Url(e.Data||"")})},n.prototype.getCardAuthData=function(e,n){return this.channel.send(new D(new w(m.GetDPCardAuthData,t.Base64Url.fromJSON({Reader:e,PIN:n||""})))).then(function(e){return JSON.parse(t.Utf8.fromBase64Url(e.Data||""))})},n.prototype.getCardEnrollData=function(e,n){return this.channel.send(new D(new w(m.GetDPCardEnrollData,t.Base64Url.fromJSON({Reader:e,PIN:n||""})))).then(function(e){return JSON.parse(t.Utf8.fromBase64Url(e.Data||""))})},n.prototype.subscribe=function(e){return this.channel.send(new D(new w(m.Subscribe,e?t.Base64Url.fromJSON({Reader:e}):""))).then()},n.prototype.unsubscribe=function(e){return this.channel.send(new D(new w(m.Unsubscribe,e?t.Base64Url.fromJSON({Reader:e}):""))).then()},n.prototype.onConnectionFailed=function(){this.emit(new s)},n.prototype.processNotification=function(e){switch(e.Event){case C.ReaderConnected:return this.emit(new u(e.Reader));case C.ReaderDisconnected:return this.emit(new d(e.Reader));case C.CardInserted:return this.emit(new h(e.Reader,e.Card));case C.CardRemoved:return this.emit(new l(e.Reader,e.Card));default:console.log("Unknown notification: "+e.Event)}},n}(p);(y=e.DeviceUidType||(e.DeviceUidType={}))[y.Persistent=0]="Persistent",y[y.Volatile=1]="Volatile",(S=e.DeviceModality||(e.DeviceModality={}))[S.Unknown=0]="Unknown",S[S.Swipe=1]="Swipe",S[S.Area=2]="Area",S[S.AreaMultifinger=3]="AreaMultifinger",(N=e.DeviceTechnology||(e.DeviceTechnology={}))[N.Unknown=0]="Unknown",N[N.Optical=1]="Optical",N[N.Capacitive=2]="Capacitive",N[N.Thermal=3]="Thermal",N[N.Pressure=4]="Pressure",(U=e.SampleFormat||(e.SampleFormat={}))[U.Raw=1]="Raw",U[U.Intermediate=2]="Intermediate",U[U.Compressed=3]="Compressed",U[U.PngImage=5]="PngImage",(T=e.QualityCode||(e.QualityCode={}))[T.Good=0]="Good",T[T.NoImage=1]="NoImage",T[T.TooLight=2]="TooLight",T[T.TooDark=3]="TooDark",T[T.TooNoisy=4]="TooNoisy",T[T.LowContrast=5]="LowContrast",T[T.NotEnoughFeatures=6]="NotEnoughFeatures",T[T.NotCentered=7]="NotCentered",T[T.NotAFinger=8]="NotAFinger",T[T.TooHigh=9]="TooHigh",T[T.TooLow=10]="TooLow",T[T.TooLeft=11]="TooLeft",T[T.TooRight=12]="TooRight",T[T.TooStrange=13]="TooStrange",T[T.TooFast=14]="TooFast",T[T.TooSkewed=15]="TooSkewed",T[T.TooShort=16]="TooShort",T[T.TooSlow=17]="TooSlow",T[T.ReverseMotion=18]="ReverseMotion",T[T.PressureTooHard=19]="PressureTooHard",T[T.PressureTooLight=20]="PressureTooLight",T[T.WetFinger=21]="WetFinger",T[T.FakeFinger=22]="FakeFinger",T[T.TooSmall=23]="TooSmall",T[T.RotatedTooMuch=24]="RotatedTooMuch";var R,I,O=function(e){function t(t,n,r){var o=e.call(this,"SamplesAcquired",t)||this;return o.sampleFormat=n,o.samples=JSON.parse(r),o}return r(t,e),t}(c),b=function(e){function t(t,n){var r=e.call(this,"QualityReported",t)||this;return r.quality=n,r}return r(t,e),t}(c),E=function(e){function t(t,n){var r=e.call(this,"ErrorOccurred",t)||this;return r.error=n,r}return r(t,e),t}(c),J=function(e){function t(t){return e.call(this,"AcquisitionStarted",t)||this}return r(t,e),t}(c),P=function(e){function t(t){return e.call(this,"AcquisitionStopped",t)||this}return r(t,e),t}(c);!function(e){e[e.EnumerateDevices=1]="EnumerateDevices",e[e.GetDeviceInfo=2]="GetDeviceInfo",e[e.StartAcquisition=3]="StartAcquisition",e[e.StopAcquisition=4]="StopAcquisition"}(R||(R={})),function(e){e[e.Completed=0]="Completed",e[e.Error=1]="Error",e[e.Disconnected=2]="Disconnected",e[e.Connected=3]="Connected",e[e.Quality=4]="Quality",e[e.Stopped=10]="Stopped",e[e.Started=11]="Started"}(I||(I={}));var A,F,B=function(e){function n(t){var n=e.call(this)||this;return n.options=t,n.channel=new v("fingerprints",n.options),n.channel.onCommunicationError=n.onConnectionFailed.bind(n),n.channel.onNotification=n.processNotification.bind(n),n}return r(n,e),n.prototype.on=function(e,t){return this._on(e,t)},n.prototype.off=function(e,t){return this._off(e,t)},n.prototype.enumerateDevices=function(){return this.channel.send(new D(new w(R.EnumerateDevices))).then(function(e){if(!e)return[];var n=JSON.parse(t.Utf8.fromBase64Url(e.Data||"{}"));return JSON.parse(n.DeviceIDs||"[]")})},n.prototype.getDeviceInfo=function(e){return this.channel.send(new D(new w(R.GetDeviceInfo,t.Base64Url.fromJSON({DeviceID:e})))).then(function(e){return JSON.parse(t.Utf8.fromBase64Url(e.Data||"null"))})},n.prototype.startAcquisition=function(e,n){return this.channel.send(new D(new w(R.StartAcquisition,t.Base64Url.fromJSON({DeviceID:n||"00000000-0000-0000-0000-000000000000",SampleType:e})))).then()},n.prototype.stopAcquisition=function(e){return this.channel.send(new D(new w(R.StopAcquisition,t.Base64Url.fromJSON({DeviceID:e||"00000000-0000-0000-0000-000000000000"})))).then()},n.prototype.onConnectionFailed=function(){this.emit(new s)},n.prototype.processNotification=function(e){switch(e.Event){case I.Completed:var n=JSON.parse(t.Utf8.fromBase64Url(e.Data||""));return this.emit(new O(e.Device,n.SampleFormat,n.Samples));case I.Error:var r=JSON.parse(t.Utf8.fromBase64Url(e.Data||""));return this.emit(new E(e.Device,r.uError));case I.Disconnected:return this.emit(new d(e.Device));case I.Connected:return this.emit(new u(e.Device));case I.Quality:var o=JSON.parse(t.Utf8.fromBase64Url(e.Data||""));return this.emit(new b(e.Device,o.Quality));case I.Stopped:return this.emit(new P(e.Device));case I.Started:return this.emit(new J(e.Device));default:console.log("Unknown notification: "+e.Event)}},n}(p);!function(e){e[e.Init=1]="Init",e[e.Continue=2]="Continue",e[e.Term=3]="Term",e[e.Authenticate=4]="Authenticate"}(A||(A={})),function(e){e[e.Response=0]="Response",e[e.Notification=1]="Notification"}(F||(F={}));var q=function(e){function t(t){var n=e.call(this)||this;return n.channel=new v("wia",t),n.channel.onCommunicationError=n.onConnectionFailed.bind(n),n}return r(t,e),t.prototype.on=function(e,t){return this._on(e,t)},t.prototype.off=function(e,t){return this._off(e,t)},t.prototype.init=function(){return this.channel.send(new D(new w(A.Init)),3e3).then(function(e){var t=JSON.parse(e.Data||"{}");return{handle:t.Handle,data:t.Data}})},t.prototype.continue=function(e,t){return this.channel.send(new D(new w(A.Continue,JSON.stringify({Handle:e,Data:t})))).then(function(e){return JSON.parse(e.Data||"{}").Data})},t.prototype.term=function(e){return this.channel.send(new D(new w(A.Term,JSON.stringify({Handle:e})))).then()},t.prototype.onConnectionFailed=function(){this.emit(new s)},t}(p);e.AcquisitionStarted=J,e.AcquisitionStopped=P,e.CardInserted=h,e.CardRemoved=l,e.CardsReader=g,e.CommunicationFailed=s,e.DeviceConnected=u,e.DeviceDisconnected=d,e.DeviceEvent=c,e.ErrorOccurred=E,e.Event=a,e.FingerprintReader=B,e.QualityReported=b,e.SamplesAcquired=O,e.WindowsAuthClient=q,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=index.umd.min.js.map