@tsocial/tvweb-sdk 4.3.3 → 4.4.0

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.
@@ -7135,7 +7135,7 @@ function pse(e,t,n){var r=gg(gie("fusedOps",e,t,n),2),a=r[0],o=r[1],i="biasadd"=
7135
7135
  * See the License for the specific language governing permissions and
7136
7136
  * limitations under the License.
7137
7137
  * =============================================================================
7138
- */var Sse=function(){function e(t,n){var r=this;Jm(this,e),this.graph=t,this.parent=n,this.compiledMap=new Map,this._weightMap={},this.SEPERATOR=",",this._functions={},this._functionExecutorMap={},this._outputs=t.outputs,this._inputs=t.inputs,this._initNodes=t.initNodes,this._signature=t.signature,this._functions=t.functions,null!=t.functions&&Object.keys(t.functions).forEach((function(n){r._functionExecutorMap[n]=new e(t.functions[n],r)}))}var t,n,r,a;return tg(e,[{key:"weightIds",get:function(){return this.parent?this.parent.weightIds:this._weightIds}},{key:"functionExecutorMap",get:function(){return this.parent?this.parent.functionExecutorMap:this._functionExecutorMap}},{key:"weightMap",get:function(){return this.parent?this.parent.weightMap:this._weightMap},set:function(e){var t,n=Object.keys(e).map((function(t){return e[t].map((function(e){return e.id}))}));this._weightIds=(t=[]).concat.apply(t,vg(n)),this._weightMap=e}},{key:"resourceManager",set:function(e){this._resourceManager=e}},{key:"inputs",get:function(){return this._inputs.map((function(e){return{name:e.name,shape:e.attrParams.shape?e.attrParams.shape.value:void 0,dtype:e.attrParams.dtype?e.attrParams.dtype.value:void 0}}))}},{key:"outputs",get:function(){return this._outputs.map((function(e){return{name:e.name,shape:e.attrParams.shape?e.attrParams.shape.value:void 0,dtype:e.attrParams.dtype?e.attrParams.dtype.value:void 0}}))}},{key:"inputNodes",get:function(){return this._inputs.map((function(e){return e.signatureKey||e.name}))}},{key:"outputNodes",get:function(){return this._outputs.map((function(e){var t=e.signatureKey||e.name;return e.defaultOutput?"".concat(t,":").concat(e.defaultOutput):t}))}},{key:"functions",get:function(){var e=this;return Object.keys(this._functions).reduce((function(t,n){return t[n]=e._functions[n].signature,t}),{})}},{key:"getCompilationKey",value:function(e,t){var n=e.map((function(e){return e.name})).sort(),r=t.map((function(e){return e.name})).sort();return n.join(this.SEPERATOR)+"--"+r.join(this.SEPERATOR)}},{key:"compile",value:function(e,t){var n=gse(e,t,this.weightMap,this._initNodes),r=n.missingInputs,a=n.dynamicNode,o=n.syncInputs;if(null!=a)throw new Error("This execution contains the node '".concat(a.name,"', which has the dynamic op '").concat(a.op,"'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [").concat(o,"]"));if(r.length>0){var i=t.map((function(e){return e.name})),s=Object.keys(e);throw new Error("Cannot compute the outputs [".concat(i,"] from the provided inputs [").concat(s,"]. Missing the following inputs: [").concat(r,"]"))}return function(e,t,n){var r=n.usedNodes,a=n.inputs,o=[],i=Object.keys(a).map((function(e){return xie(e)[0]})).map((function(t){return e.nodes[t]})),s=e.initNodes;i.forEach((function(e){r.has(e.name)&&o.push(e)})),e.weights.forEach((function(e){r.has(e.name)&&o.push(e)})),null!=s&&s.forEach((function(e){r.has(e.name)&&o.push(e)}));for(var u=new Set,c=[];o.length>0;){var l=o.pop();u.add(l.name),t[l.name]||c.push(l),l.children.forEach((function(e){!u.has(e.name)&&r.has(e.name)&&e.inputs.every((function(e){return u.has(e.name)}))&&o.push(e)}))}return c}(this.graph,this.weightMap,n)}},{key:"execute",value:function(e,t){var n=this;e=this.mapInputs(e);var r=Object.keys(e).sort();this.checkInputs(e),this.checkInputShapeAndType(e),t=this.mapOutputs(t),this.checkOutputs(t);var a=r.map((function(e){return n.graph.nodes[xie(e)[0]]})),o=t.map((function(e){return xie(e)[0]})),i=o.map((function(e){return n.graph.nodes[e]}));0===i.length&&(i=this._outputs);var s=this.getCompilationKey(a,i),u=this.compiledMap.get(s);null==u&&(u=this.compile(e,i),this.compiledMap.set(s,u));var c={},l={};return Dne((function(){var r=new mse(n.weightMap,c,l,n.functionExecutorMap),a=Object.assign({},n.weightMap);Object.keys(e).forEach((function(t){var n=gg(xie(t),2),r=n[0],o=[];o[n[1]]=e[t],a[r]=o}));for(var i=n.getFrozenTensorIds(a),s={},p=0;p<u.length;p++){var d=u[p];if(!a[d.name]){var f=hse(d,a,r,n._resourceManager);if(qee(f))throw new Error("The execution of the op '".concat(d.op,"' returned a promise. Please use model.executeAsync() instead."));a[d.name]=f,n.checkTensorForDisposal(d.name,d,a,r,i,o,s)}}return null==n.parent&&r.dispose(i),t.map((function(e){return vie(e,a,r)}))}))}},{key:"getFrozenTensorIds",value:function(e){var t=[].concat.apply([],Object.keys(e).map((function(t){return e[t]})).map((function(e){return e.map((function(e){return e.id}))})));return new Set(t)}},{key:"checkTensorForDisposal",value:function(e,t,n,r,a,o,i){"control"!==t.category&&-1===o.indexOf(e)&&(n[e].forEach((function(e){null!=e&&(i[e.id]=(i[e.id]||0)+t.children.length)})),t.inputs.forEach((function(e){if("control"!==e.category){var t=function(e,t,n){return t[bie(e,n.currentContextId)]}(e.name,n,r);null!=t&&t.forEach((function(e){if(e&&!e.kept&&!a.has(e.id)){var t=i[e.id];1===t?(e.dispose(),delete i[e.id]):null!=t&&i[e.id]--}}))}})))}},{key:"executeAsync",value:(a=Zm(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this._executeAsync(t,n));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"_executeAsync",value:(r=Zm(regeneratorRuntime.mark((function e(t,n){var r,a,o,i,s,u,c,l,p,d=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=d.length>2&&void 0!==d[2]&&d[2],a=d.length>3&&void 0!==d[3]?d[3]:{},o=d.length>4&&void 0!==d[4]?d[4]:{},r||(t=this.mapInputs(t),this.checkInputs(t),this.checkInputShapeAndType(t),n=this.mapOutputs(n),this.checkOutputs(n)),i=new mse(this.weightMap,a,o,this.functionExecutorMap),e.next=7,this.executeWithControlFlow(t,i,n,r);case 7:return s=e.sent,u=n.map((function(e){return vie(e,s,i)})),c=u.map((function(e){return e.id})),l=Object.keys(t).map((function(e){return t[e].id})),p=new Set([].concat(vg(c),vg(l),vg(this.weightIds))),e.abrupt("return",(Object.keys(s).forEach((function(e){s[e].forEach((function(e){!e||e.kept||e.isDisposed||p.has(e.id)||e.dispose()}))})),null==this.parent&&i.dispose(p),u));case 13:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"executeFunctionAsync",value:(n=Zm(regeneratorRuntime.mark((function e(t,n,r){var a,o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t.reduce((function(e,t,n){return e[o.inputs[n].name]=t,e}),{}),e.abrupt("return",this._executeAsync(a,this.outputNodes,!0,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"executeWithControlFlow",value:(t=Zm(regeneratorRuntime.mark((function e(t,n,r,a){var o,i,s,u,c,l,p,d,f,h,m,g,v,y,b,x,w,k=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=Object.keys(t),i=o.map((function(e){return k.graph.nodes[xie(e)[0]]})),s=r.map((function(e){return xie(e)[0]})),0===(u=s.map((function(e){return k.graph.nodes[e]}))).length&&(u=this._outputs),c=gse(t,u,this.weightMap,this._initNodes),l=c.usedNodes,p=c.missingInputs,d=c.dynamicNode,f=c.syncInputs,h=[].concat(vg(i),vg(this.graph.weights),vg(this._initNodes||[])).map((function(e){return{node:e,contexts:n.currentContext}})),m=Object.assign({},this.weightMap),Object.keys(t).forEach((function(e){var n=gg(xie(e),2),r=n[0],a=[];a[n[1]]=t[e],m[r]=a})),g={},v=this.getFrozenTensorIds(m),y={};case 6:if(!(h.length>0)){e.next=12;break}return b=this.processStack(i,h,n,m,y,v,s,g,l),e.next=10,Promise.all(b);case 10:e.next=6;break;case 12:if(null!=d||a||console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead."),!((x=u.filter((function(e){return!xse(e)&&!vie(e.name,m,n)})).map((function(e){return e.name}))).length>0)){e.next=17;break}throw w="",null!=d&&(w="Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs [".concat(f,"]")),new Error("Cannot compute the outputs [".concat(x,"] from the provided inputs [").concat(o,"]. Consider providing the following inputs: [").concat(p,"]. ").concat(w));case 17:return e.abrupt("return",m);case 18:case"end":return e.stop()}}),e,this)}))),function(e,n,r,a){return t.apply(this,arguments)})},{key:"processStack",value:function(e,t,n,r,a,o,i,s,u){for(var c=this,l=[],p=function(){var e,p=t.pop();n.currentContext=p.contexts;var d="";if("Enter"===p.node.op&&gie("isConstant",p.node,r,n)&&(e=gg(yie(p.node.name,n),1),d=e[0]),null==r[p.node.name]){var f,h=hse(p.node,r,n,c._resourceManager);d||(f=gg(yie(p.node.name,n),1),d=f[0]);var m=n.currentContext;qee(h)?l.push(h.then((function(e){return r[d]=e,n.currentContext=m,c.checkTensorForDisposal(d,p.node,r,n,o,i,s),c.processChildNodes(p.node,t,n,r,a,u),e}))):(r[d]=h,c.checkTensorForDisposal(d,p.node,r,n,o,i,s),c.processChildNodes(p.node,t,n,r,a,u))}else c.processChildNodes(p.node,t,n,r,a,u)};t.length>0;)p();return l}},{key:"processChildNodes",value:function(e,t,n,r,a,o){e.children.forEach((function(e){var i=gg(yie(e.name,n),1)[0];!a[i]&&o.has(e.name)&&("Merge"===e.op?e.inputNames.some((function(e){return!!vie(e,r,n)}))&&(a[i]=!0,t.push({contexts:n.currentContext,node:e})):e.inputNames.every((function(e){return!!vie(e,r,n)}))&&(a[i]=!0,t.push({contexts:n.currentContext,node:e})))}))}},{key:"dispose",value:function(){var e=this;Object.keys(this.weightMap).forEach((function(t){return e.weightMap[t].forEach((function(e){return e.dispose()}))}))}},{key:"checkInputShapeAndType",value:function(e){var t=this;Object.keys(e).forEach((function(n){var r=e[n],a=gg(xie(n),1)[0],o=t.graph.nodes[a];if(o.attrParams.shape&&o.attrParams.shape.value){var i=o.attrParams.shape.value;Nee(i.length===r.shape.length&&r.shape.every((function(e,t){return-1===i[t]||i[t]===e})),(function(){return"The shape of dict['".concat(o.name,"'] provided in model.execute(dict) must be [").concat(i,"], but was [").concat(r.shape,"]")}))}o.attrParams.dtype&&o.attrParams.dtype.value&&Nee(r.dtype===o.attrParams.dtype.value,(function(){return"The dtype of dict['".concat(o.name,"'] provided in model.execute(dict) must be ").concat(o.attrParams.dtype.value,", but was ").concat(r.dtype)}))}))}},{key:"mapInputs",value:function(e){var t={};for(var n in e)null!=this._signature&&null!=this._signature.inputs&&null!=this._signature.inputs[n]?t[this._signature.inputs[n].name]=e[n]:t[n]=e[n];return t}},{key:"checkInputs",value:function(e){var t=this,n=Object.keys(e).filter((function(e){var n=gg(xie(e),1)[0];return null==t.graph.nodes[n]}));if(n.length>0)throw new Error("The dict provided in model.execute(dict) has keys: [".concat(n,"] that are not part of graph"))}},{key:"mapOutputs",value:function(e){var t=this;return e.map((function(e){return null!=t._signature&&null!=t._signature.outputs&&null!=t._signature.outputs[e]?t._signature.outputs[e].name:e}),{})}},{key:"checkOutputs",value:function(e){var t=this;e.forEach((function(e){var n=gg(xie(e),1)[0];if(!t.graph.nodes[n])throw new Error("The output '".concat(e,"' is not found in the graph"))}))}}]),e}(),Ese=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Jm(this,e),this.hashTableNameToHandle=t,this.hashTableMap=n}return tg(e,[{key:"addHashTable",value:function(e,t){this.hashTableNameToHandle[e]=t.handle,this.hashTableMap[t.id]=t}},{key:"getHashTableHandleByName",value:function(e){return this.hashTableNameToHandle[e]}},{key:"getHashTableById",value:function(e){return this.hashTableMap[e]}},{key:"dispose",value:function(){for(var e in this.hashTableMap)this.hashTableMap[e].clearAndClose(),delete this.hashTableMap[e];for(var t in this.hashTableNameToHandle)this.hashTableNameToHandle[t].dispose(),delete this.hashTableNameToHandle[t]}}]),e}(),Ise=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Jm(this,e),this.modelUrl=t,this.loadOptions=n,this.version="n/a",null==n&&(this.loadOptions={}),this.resourceManager=new Ese}var t,n,r;return tg(e,[{key:"modelVersion",get:function(){return this.version}},{key:"inputNodes",get:function(){return this.executor.inputNodes}},{key:"outputNodes",get:function(){return this.executor.outputNodes}},{key:"inputs",get:function(){return this.executor.inputs}},{key:"outputs",get:function(){return this.executor.outputs}},{key:"weights",get:function(){return this.executor.weightMap}},{key:"metadata",get:function(){return this.artifacts.userDefinedMetadata}},{key:"modelSignature",get:function(){return this.signature}},{key:"findIOHandler",value:function(){var e,t,n=this.modelUrl;if(null!=n.load)this.handler=n;else if(null!=this.loadOptions.requestInit)this.handler=_ne(n,this.loadOptions);else{var r=(e=n,t=this.loadOptions,Zte.getLoadHandlers(e,t));if(0===r.length)r.push(_ne(n,this.loadOptions));else if(r.length>1)throw new Error("Found more than one (".concat(r.length,") load handlers for URL '").concat([n],"'"));this.handler=r[0]}}},{key:"load",value:(r=Zm(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.findIOHandler(),null!=this.handler.load){e.next=2;break}throw new Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");case 2:return e.next=4,this.handler.load();case 4:return t=e.sent,e.abrupt("return",this.loadSync(t));case 6:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"loadSync",value:function(e){this.artifacts=e;var t,n=this.artifacts.modelTopology;t=null!=this.artifacts.userDefinedMetadata&&null!=this.artifacts.userDefinedMetadata.signature?this.artifacts.userDefinedMetadata.signature:this.artifacts.signature,this.signature=t,this.version="".concat(n.versions.producer,".").concat(n.versions.minConsumer);var r=function(e,t){var n,r,a={},o=0,i=xg(t);try{for(i.s();!(r=i.n()).done;){var s=r.value,u=s.name,c=s.dtype,l=s.shape,p=Oee(l),d=void 0;if("quantization"in s){var f=s.quantization;if("uint8"===f.dtype||"uint16"===f.dtype){if(!("min"in f)||!("scale"in f))throw new Error("Weight ".concat(s.name," with quantization ").concat(f.dtype," doesn't have corresponding metadata min and scale."))}else{if("float16"!==f.dtype)throw new Error("Weight ".concat(s.name," has unknown quantization dtype ").concat(f.dtype,". Supported quantization dtypes are: 'uint8', 'uint16', and 'float16'."));if("float32"!==c)throw new Error("Weight ".concat(s.name," is quantized with ").concat(f.dtype," which only supports weights of type float32 not ").concat(c,"."))}var h=Kte[f.dtype],m=e.slice(o,o+p*h),g="uint8"===f.dtype?new Uint8Array(m):new Uint16Array(m);if("float32"===c)if("uint8"===f.dtype||"uint16"===f.dtype){d=new Float32Array(g.length);for(var v=0;v<g.length;v++){var y=g[v];d[v]=y*f.scale+f.min}}else{if("float16"!==f.dtype)throw new Error("Unsupported quantization type ".concat(f.dtype," for weight type float32."));void 0===n&&(n=$te()),d=n(g)}else{if("int32"!==c)throw new Error("Unsupported dtype in weight '".concat(u,"': ").concat(c));if("uint8"!==f.dtype&&"uint16"!==f.dtype)throw new Error("Unsupported quantization type ".concat(f.dtype," for weight type int32."));d=new Int32Array(g.length);for(var b=0;b<g.length;b++){var x=g[b];d[b]=Math.round(x*f.scale+f.min)}}o+=p*h}else if("string"===c){var w=Oee(s.shape);d=[];for(var k=0;k<w;k++){var S=new Uint32Array(e.slice(o,o+4))[0];o+=4;var E=new Uint8Array(e.slice(o,o+S));d.push(E),o+=S}}else{var I=Kte[c],C=e.slice(o,o+p*I);if("float32"===c)d=new Float32Array(C);else if("int32"===c)d=new Int32Array(C);else if("bool"===c)d=new Uint8Array(C);else{if("complex64"!==c)throw new Error("Unsupported dtype in weight '".concat(u,"': ").concat(c));d=new Float32Array(C);for(var T=new Float32Array(d.length/2),_=new Float32Array(d.length/2),N=0;N<T.length;N++)T[N]=d[2*N],_[N]=d[2*N+1];var A=Gte(T,l,"float32"),R=Gte(_,l,"float32");a[u]=Wte(A,R),A.dispose(),R.dispose()}o+=p*I}"complex64"!==c&&(a[u]=Gte(d,l,c))}}catch(e){i.e(e)}finally{i.f()}return a}(this.artifacts.weightData,this.artifacts.weightSpecs);if(this.executor=new Sse(jie.Instance.transformGraph(n,this.signature)),this.executor.weightMap=this.convertTensorMapToTensorsMap(r),this.executor.resourceManager=this.resourceManager,null!=e.modelInitializer&&null!=e.modelInitializer.node){var a=jie.Instance.transformGraph(e.modelInitializer);this.initializer=new Sse(a),this.initializer.weightMap=this.executor.weightMap,this.initializer.resourceManager=this.resourceManager,this.initializer.executeAsync({},[])}return!0}},{key:"save",value:(n=Zm(regeneratorRuntime.mark((function e(t,n){var r,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t){e.next=7;break}if(a=t,0!==(r=Zte.getSaveHandlers(a)).length){e.next=4;break}throw new Error("Cannot find any save handlers for URL '".concat(t,"'"));case 4:if(!(r.length>1)){e.next=6;break}throw new Error("Found more than one (".concat(r.length,") save handlers for URL '").concat(t,"'"));case 6:t=r[0];case 7:if(null!=t.save){e.next=9;break}throw new Error("GraphModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");case 9:return e.abrupt("return",t.save(this.artifacts));case 10:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"predict",value:function(e,t){return this.execute(e,this.outputNodes)}},{key:"normalizeInputs",value:function(e){if(!(e instanceof bte||Array.isArray(e)))return e;if((e=Array.isArray(e)?e:[e]).length!==this.inputNodes.length)throw new Error("Input tensor count mismatch,the graph model has ".concat(this.inputNodes.length," placeholders, while there are ").concat(e.length," input tensors."));return this.inputNodes.reduce((function(t,n,r){return t[n]=e[r],t}),{})}},{key:"normalizeOutputs",value:function(e){return e=e||this.outputNodes,Array.isArray(e)?e:[e]}},{key:"execute",value:function(e,t){e=this.normalizeInputs(e),t=this.normalizeOutputs(t);var n=this.executor.execute(e,t);return n.length>1?n:n[0]}},{key:"executeAsync",value:(t=Zm(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.normalizeInputs(t),n=this.normalizeOutputs(n),e.next=3,this.executor.executeAsync(t,n);case 3:return r=e.sent,e.abrupt("return",r.length>1?r:r[0]);case 5:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"convertTensorMapToTensorsMap",value:function(e){return Object.keys(e).reduce((function(t,n){return t[n]=[e[n]],t}),{})}},{key:"dispose",value:function(){this.executor.dispose(),this.initializer&&this.initializer.dispose(),this.resourceManager.dispose()}}]),e}();function Cse(e){return Tse.apply(this,arguments)}function Tse(){return(Tse=Zm(regeneratorRuntime.mark((function e(t){var n,r,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=a.length>1&&void 0!==a[1]?a[1]:{},null!=t){e.next=3;break}throw new Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");case 3:return null==n&&(n={}),n.fromTFHub&&null==t.load&&(t.endsWith("/")||(t+="/"),t="".concat(t,"model.json?tfjs-format=file")),r=new Ise(t,n),e.next=7,r.load();case 7:return e.abrupt("return",r);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var _se="https://unpkg.com/tv-model-prod@1.0.2/web_model/web_model_uint8/model.json",Nse="https://unpkg.com/tv-model-prod@1.0.2/libs/opencv.js",Ase={0:"top-left",1:"top-right",2:"bottom-right",3:"bottom-left",4:"cccd.front",5:"passport",6:"cmnd_old.front",7:"cmnd_old.back",8:"cmnd_new.front",9:"cmnd_new.back",10:"cccd_new.front",11:"cccd_new.back"};function Rse(e){var t,n,r,a,o,i=e.card,s=e.corners,u=i.box,c={x:(u[1]+u[3])/2,y:(u[0]+u[2])/2},l=u[2]-u[0],p=u[1]-u[3],d=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=r6(e))){n&&(e=n);var r=0,a=function(){};return{s:a,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,s=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,o=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw o}}}}(s);try{for(d.s();!(o=d.n()).done;){var f=o.value;switch(f.label){case"top-left":t||(t=f.location);break;case"top-right":n||(n=f.location);break;case"bottom-right":r||(r=f.location);break;case"bottom-left":a||(a=f.location)}}}catch(e){d.e(e)}finally{d.f()}if(![t,n,r,a].every(Boolean))return console.debug("Not qualified, corners missing"),!1;var h={x:(t.x+r.x)/2,y:(t.y+r.y)/2},m={x:(n.x+a.x)/2,y:(n.y+a.y)/2},g=gee(c,h),v=gee(c,m);return Math.sqrt(g)>(l+p)/8||Math.sqrt(v)>(l+p)/8?(console.debug("Not qualified, not close enough"),!1):(console.debug("Qualified"),!0)}function Ose(e){return Bse.apply(this,arguments)}function Bse(){return(Bse=X4(regeneratorRuntime.mark((function e(t){var n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.url,r=void 0===n?Nse:n,!window.cv){e.next=3;break}return e.abrupt("return",Promise.resolve());case 3:return e.next=5,yx.loadExternalScript({url:r});case 5:return e.abrupt("return",new Promise((function(e){window.cv.onRuntimeInitialized=e})));case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Dse=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n,r,a,o,i,s;return t=e,(n=[{key:"load",value:(s=X4(regeneratorRuntime.mark((function e(){var t,n,r,a,o=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=o.length>0&&void 0!==o[0]?o[0]:{},n=t.opencvUrl,r=t.modelUrl,a=t.tfjsWasmRoot,e.next=3,Promise.all([Ose({url:n}),this.loadModel({modelUrl:r,tfjsWasmRoot:a})]);case 3:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"loadModel",value:(i=X4(regeneratorRuntime.mark((function e(){var t,n,r,a,o,i,s=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=t.modelUrl,r=void 0===n?_se:n,a=t.tfjsWasmRoot,e.next=3,_K.initTensorFlow({tfjsWasmRoot:a});case 3:return e.next=5,Cse(r,{fetchFunc:yx.fetchWithDecryption});case 5:this.model=e.sent,o=this.model.inputs,i=this.model.outputs,this.boxesIndex=i.findIndex((function(e){return"Identity_3"===e.name})),this.classesIndex=i.findIndex((function(e){return"Identity_2"===e.name})),this.scoresIndex=i.findIndex((function(e){return"Identity_1"===e.name})),this.inputSize=[o[0].shape[1],o[0].shape[2]];case 12:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"dispose",value:(o=X4(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.model&&this.model.dispose();case 1:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"predict",value:(a=X4(regeneratorRuntime.mark((function e(t){var n,r,a,o,i,s,u,c,l,p,d,f,h,m,g,v,y,b,x,w,k,S,E,I,C,T,_,N=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=N.length>1&&void 0!==N[1]?N[1]:{},r=n.imgMargin,a=void 0===r?.5:r,o=n.detectThreshold,i=void 0===o?.3:o,s=n.maxNumReturns,u=void 0===s?100:s,c=window,l=c.cv,p={},d=t.width,f=t.height,p.originalWidth=d,p.originalHeight=f,h=yee({canvas:t,imgMargin:a}),m=h.margin,g=h.mat,v=t6(this.inputSize,2),y=v[0],b=v[1],x=new l.Mat,l.resize(g,x,new l.Size(y,b),0,0,l.INTER_AREA),w=g.cols/y,k=g.rows/b,(S=document.createElement("canvas")).width=y,S.height=b,S.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(x.data),x.cols,x.rows),0,0),g.delete(),x.delete(),p.canvas=S,p.margin=m,e.next=24,this.detect(S,{detectThreshold:i,maxNumReturns:u});case 24:if(E=e.sent,I={inputImage:p,card:null},C=[],T=[],E.forEach((function(e){var t=t6(e.box,4),n=t[0],r=t[1],a=t[2],o=t[3];e.clazz<=3?C.push({clazz:e.clazz,label:e.label,score:e.score,location:{x:Tee(Math.floor((o+r)/2*w-m),0,d),y:Tee(Math.floor((n+a)/2*k-m),0,f)},scaledLocation:{x:Tee(Math.floor((o+r)/2),0,S.width),y:Tee(Math.floor((n+a)/2),0,S.height)}}):T.push({label:e.label,score:e.score,box:[Tee(Math.floor(n*k-m),0,f),Tee(Math.floor(r*w-m),0,d),Tee(Math.floor(a*k-m),0,f),Tee(Math.floor(o*w-m),0,d)]})})),C.sort((function(e,t){return t.score-e.score})),T.sort((function(e,t){return t.score-e.score})),!(T.length>0)){e.next=40;break}if(Rse({card:_=T[0],corners:C})){e.next=36;break}return console.debug("Not qualified.",_,C),e.abrupt("return",I);case 36:return C.sort((function(e,t){return e.clazz-t.clazz})),_.corners=C,I.card=_,e.abrupt("return",I);case 40:return e.abrupt("return",I);case 41:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"detect",value:(r=X4(regeneratorRuntime.mark((function e(t){var n,r,a,o,i,s,u,c,l,p,d,f,h,m,g,v,y,b,x,w,k,S,E=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=E.length>1&&void 0!==E[1]?E[1]:{},r=n.detectThreshold,a=n.maxNumReturns,o=t.width,i=t.height,s=Dne((function(){var e=t;return e instanceof bte||(e=Bne(e)),Ure(wne(e,"float32"),0)})),u=this.model.execute(s),s.dispose(),e.next=8,Promise.all([u[this.boxesIndex].array(),u[this.classesIndex].data(),u[this.scoresIndex].data()]);case 8:for(c=e.sent,l=t6(c,3),p=t6(l[0],1),d=p[0],f=l[1],h=l[2],m=[],g=Math.min(h.length,a),v=0;v<g;v++)(y=h[v])>r&&(x=f[v],w=null!==(b=Ase[Math.round(x)])&&void 0!==b?b:"NA",k=d[v],S=[k[0]*i,k[3]*o,k[2]*i,k[1]*o],m.push({score:y,clazz:x,box:S,label:w}));return e.abrupt("return",m);case 18:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,n),e}();function Mse(e){return Fse.apply(this,arguments)}function Fse(){return(Fse=X4(regeneratorRuntime.mark((function e(t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.idCardModel,e.abrupt("return",new Promise((function(e,t){var r=document.createElement("canvas");setTimeout(t,1e3),n.predict(r).then(e)})));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pse(e){return Lse.apply(this,arguments)}function Lse(){return(Lse=X4(regeneratorRuntime.mark((function e(t){var n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.idCardModel,r=!0,e.prev=2,e.next=5,Mse({idCardModel:n});case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),r=!1;case 10:return e.abrupt("return",{fastEnough:r});case 11:case"end":return e.stop()}}),e,null,[[2,7]])})))).apply(this,arguments)}function Use(){return(Use=X4(regeneratorRuntime.mark((function e(){var t,n,r,a,o,i,s,u,c,l,p,d,f,h=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=h.length>0&&void 0!==h[0]?h[0]:{},n=t.opencvUrl,r=t.modelUrl,a=t.blazefaceRoot,o=t.tfjsWasmRoot,!b6.isIOS){e.next=3;break}return e.abrupt("return",{ableToUseModel:!1});case 3:return i=new Dse,e.next=6,Promise.all([_K.loadBlazeface({modelUrl:a}),i.load({opencvUrl:n,modelUrl:r,tfjsWasmRoot:o})]);case 6:return s=e.sent,u=t6(s,1),c=u[0],l=!0,p=document.createElement("canvas"),e.prev=11,e.next=14,i.predict(p);case 14:return e.next=16,Pse({idCardModel:i});case 16:d=e.sent,f=d.fastEnough,l=f,e.next=24;break;case 21:e.prev=21,e.t0=e.catch(11),l=!1;case 24:return e.abrupt("return",{ableToUseModel:l,idCardModel:i,blazefaceModel:c});case 25:case"end":return e.stop()}}),e,null,[[11,21]])})))).apply(this,arguments)}var Vse=function(e){return function(e,t){var n;if("function"!=typeof t)throw new TypeError("Expected a function");return e=Cee(e),function(){return--e>0&&(n=t.apply(this,arguments)),e<=1&&(t=void 0),n}}(2,e)}((function(){return Use.apply(this,arguments)})),zse=Lv.Errors;function jse(){return(jse=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var Wse,Hse,Gse="undefined"!=typeof window?lv.useLayoutEffect:lv.useEffect,Kse={popupContent:{tooltip:{position:"absolute",zIndex:999},modal:{position:"relative",margin:"auto"}},popupArrow:{height:"8px",width:"16px",position:"absolute",background:"transparent",color:"#FFF",zIndex:-1},overlay:{tooltip:{position:"fixed",top:"0",bottom:"0",left:"0",right:"0",zIndex:999},modal:{position:"fixed",top:"0",bottom:"0",left:"0",right:"0",display:"flex",zIndex:999}}},qse=["top left","top center","top right","right top","right center","right bottom","bottom left","bottom center","bottom right","left top","left center","left bottom"],Qse=function(e,t,n,r,a){var o=a.offsetX,i=a.offsetY,s=r?8:0,u=n.split(" "),c=e.top+e.height/2,l=e.left+e.width/2,p=t.height,d=t.width,f=c-p/2,h=l-d/2,m="",g="0%",v="0%";switch(u[0]){case"top":f-=p/2+e.height/2+s,m="rotate(180deg) translateX(50%)",g="100%",v="50%";break;case"bottom":f+=p/2+e.height/2+s,m="rotate(0deg) translateY(-100%) translateX(-50%)",v="50%";break;case"left":h-=d/2+e.width/2+s,m=" rotate(90deg) translateY(50%) translateX(-25%)",v="100%",g="50%";break;case"right":h+=d/2+e.width/2+s,m="rotate(-90deg) translateY(-150%) translateX(25%)",g="50%"}switch(u[1]){case"top":f=e.top,g=e.height/2+"px";break;case"bottom":f=e.top-p+e.height,g=p-e.height/2+"px";break;case"left":h=e.left,v=e.width/2+"px";break;case"right":h=e.left-d+e.width,v=d-e.width/2+"px"}return{top:f="top"===u[0]?f-i:f+i,left:h="left"===u[0]?h-o:h+o,transform:m,arrowLeft:v,arrowTop:g}},Xse=0,Yse=lv.forwardRef((function(e,t){var n=e.trigger,r=void 0===n?null:n,a=e.onOpen,o=void 0===a?function(){}:a,i=e.onClose,s=void 0===i?function(){}:i,u=e.defaultOpen,c=void 0!==u&&u,l=e.open,p=void 0===l?void 0:l,d=e.disabled,f=void 0!==d&&d,h=e.nested,m=void 0!==h&&h,g=e.closeOnDocumentClick,v=void 0===g||g,y=e.repositionOnResize,b=void 0===y||y,x=e.closeOnEscape,w=void 0===x||x,k=e.on,S=void 0===k?["click"]:k,E=e.contentStyle,I=void 0===E?{}:E,C=e.arrowStyle,T=void 0===C?{}:C,_=e.overlayStyle,N=void 0===_?{}:_,A=e.className,R=void 0===A?"":A,O=e.position,B=void 0===O?"bottom center":O,D=e.modal,M=void 0!==D&&D,F=e.lockScroll,P=void 0!==F&&F,L=e.arrow,U=void 0===L||L,V=e.offsetX,z=void 0===V?0:V,j=e.offsetY,W=void 0===j?0:j,H=e.mouseEnterDelay,G=void 0===H?100:H,K=e.mouseLeaveDelay,q=void 0===K?100:K,Q=e.keepTooltipInside,X=void 0!==Q&&Q,Y=e.children,$=lv.useState(p||c),Z=$[0],J=$[1],ee=lv.useRef(null),te=lv.useRef(null),ne=lv.useRef(null),re=lv.useRef(null),ae=lv.useRef("popup-"+ ++Xse),oe=!!M||!r,ie=lv.useRef(0);Gse((function(){return Z?(re.current=document.activeElement,ge(),me(),fe()):he(),function(){clearTimeout(ie.current)}}),[Z]),lv.useEffect((function(){"boolean"==typeof p&&(p?se():ue())}),[p,f]);var se=function(e){Z||f||(J(!0),setTimeout((function(){return o(e)}),0))},ue=function(e){var t;Z&&!f&&(J(!1),oe&&(null===(t=re.current)||void 0===t||t.focus()),setTimeout((function(){return s(e)}),0))},ce=function(e){null==e||e.stopPropagation(),Z?ue(e):se(e)},le=function(e){clearTimeout(ie.current),ie.current=setTimeout((function(){return se(e)}),G)},pe=function(e){null==e||e.preventDefault(),ce()},de=function(e){clearTimeout(ie.current),ie.current=setTimeout((function(){return ue(e)}),q)},fe=function(){oe&&P&&(document.getElementsByTagName("body")[0].style.overflow="hidden")},he=function(){oe&&P&&(document.getElementsByTagName("body")[0].style.overflow="auto")},me=function(){var e,t=null==te||null===(e=te.current)||void 0===e?void 0:e.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]'),n=Array.prototype.slice.call(t)[0];null==n||n.focus()};lv.useImperativeHandle(t,(function(){return{open:function(){se()},close:function(){ue()},toggle:function(){ce()}}}));var ge=function(){if(!oe&&Z&&(null==ee?void 0:ee.current)&&(null==ee?void 0:ee.current)&&(null==te?void 0:te.current)){var e,t,n=function(e,t,n,r,a,o){var i=a.offsetX,s=a.offsetY,u={arrowLeft:"0%",arrowTop:"0%",left:0,top:0,transform:"rotate(135deg)"},c=0,l=function(e){var t={top:0,left:0,width:window.innerWidth,height:window.innerHeight};if("string"==typeof e){var n=document.querySelector(e);null!==n&&(t=n.getBoundingClientRect())}return t}(o),p=Array.isArray(n)?n:[n];for((o||Array.isArray(n))&&(p=[].concat(p,qse));c<p.length;){var d={top:(u=Qse(e,t,p[c],r,{offsetX:i,offsetY:s})).top,left:u.left,width:t.width,height:t.height};if(!(d.top<=l.top||d.left<=l.left||d.top+d.height>=l.top+l.height||d.left+d.width>=l.left+l.width))break;c++}return u}(ee.current.getBoundingClientRect(),te.current.getBoundingClientRect(),B,U,{offsetX:z,offsetY:W},X);te.current.style.top=n.top+window.scrollY+"px",te.current.style.left=n.left+window.scrollX+"px",U&&ne.current&&(ne.current.style.transform=n.transform,ne.current.style.setProperty("-ms-transform",n.transform),ne.current.style.setProperty("-webkit-transform",n.transform),ne.current.style.top=(null===(e=T.top)||void 0===e?void 0:e.toString())||n.arrowTop,ne.current.style.left=(null===(t=T.left)||void 0===t?void 0:t.toString())||n.arrowLeft)}};!function(e,t){void 0===t&&(t=!0),lv.useEffect((function(){if(t){var n=function(t){"Escape"===t.key&&e(t)};return document.addEventListener("keyup",n),function(){t&&document.removeEventListener("keyup",n)}}}),[e,t])}(ue,w),function(e,t){void 0===t&&(t=!0),lv.useEffect((function(){if(t){var n=function(t){if(9===t.keyCode){var n,r=null==e||null===(n=e.current)||void 0===n?void 0:n.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]'),a=Array.prototype.slice.call(r);if(1===a.length)return void t.preventDefault();var o=a[0],i=a[a.length-1];t.shiftKey&&document.activeElement===o?(t.preventDefault(),i.focus()):document.activeElement===i&&(t.preventDefault(),o.focus())}};return document.addEventListener("keydown",n),function(){t&&document.removeEventListener("keydown",n)}}}),[e,t])}(te,Z&&oe),function(e,t){void 0===t&&(t=!0),lv.useEffect((function(){if(t){var n=function(){e()};return window.addEventListener("resize",n),function(){t&&window.removeEventListener("resize",n)}}}),[e,t])}(ge,b),function(e,t,n){void 0===n&&(n=!0),lv.useEffect((function(){if(n){var r=function(n){var r=Array.isArray(e)?e:[e],a=!1;r.forEach((function(e){e.current&&!e.current.contains(n.target)||(a=!0)})),n.stopPropagation(),a||t(n)};return document.addEventListener("mousedown",r),document.addEventListener("touchstart",r),function(){n&&(document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r))}}}),[e,t,n])}(r?[te,ee]:[te],ue,v&&!m);var ve,ye=function(){return lv.createElement("div",Object.assign({},(e=oe?Kse.popupContent.modal:Kse.popupContent.tooltip,t={className:"popup-content "+(""!==R?R.split(" ").map((function(e){return e+"-content"})).join(" "):""),style:jse({},e,I,{pointerEvents:"auto"}),ref:te,onClick:function(e){e.stopPropagation()}},!M&&S.indexOf("hover")>=0&&(t.onMouseEnter=le,t.onMouseLeave=de),t),{key:"C",role:oe?"dialog":"tooltip",id:ae.current}),U&&!oe&&lv.createElement("div",{ref:ne,style:Kse.popupArrow},lv.createElement("svg",{"data-testid":"arrow",className:"popup-arrow "+(""!==R?R.split(" ").map((function(e){return e+"-arrow"})).join(" "):""),viewBox:"0 0 32 16",style:jse({position:"absolute"},T)},lv.createElement("path",{d:"M16 0l16 16H0z",fill:"currentcolor"}))),Y&&"function"==typeof Y?Y(ue,Z):Y);var e,t},be=!(S.indexOf("hover")>=0),xe=oe?Kse.overlay.modal:Kse.overlay.tooltip,we=[be&&lv.createElement("div",{key:"O","data-testid":"overlay","data-popup":oe?"modal":"tooltip",className:"popup-overlay "+(""!==R?R.split(" ").map((function(e){return e+"-overlay"})).join(" "):""),style:jse({},xe,N,{pointerEvents:v&&m||oe?"auto":"none"}),onClick:v&&m?ue:void 0,tabIndex:-1},oe&&ye()),!oe&&ye()];return lv.createElement(lv.Fragment,null,function(){for(var e={key:"T",ref:ee,"aria-describedby":ae.current},t=Array.isArray(S)?S:[S],n=0,a=t.length;n<a;n++)switch(t[n]){case"click":e.onClick=ce;break;case"right-click":e.onContextMenu=pe;break;case"hover":e.onMouseEnter=le,e.onMouseLeave=de;break;case"focus":e.onFocus=le,e.onBlur=de}if("function"==typeof r){var o=r(Z);return!!r&&lv.cloneElement(o,e)}return!!r&&lv.cloneElement(r,e)}(),Z&&K4.createPortal(we,(null===(ve=document.getElementById("popup-root"))&&((ve=document.createElement("div")).setAttribute("id","popup-root"),document.body.appendChild(ve)),ve)))})),$se=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var a=PQ.apply(void 0,[e].concat(n)),o="sc-global-"+jQ(JSON.stringify(a)),i=new ZQ(a,o);function s(e){var t=TQ(),n=_Q(),r=lv.useContext(QQ),a=lv.useRef(t.allocateGSInstance(o)).current;return lv.useLayoutEffect((function(){return u(a,e,t,r,n),function(){return i.removeStyles(a,t)}}),[a,e,t,r,n]),null}function u(e,t,n,r,a){if(i.isStatic)i.renderStyles(e,qq,n,a);else{var o=Fq({},t,{theme:LQ(t,r,s.defaultProps)});i.renderStyles(e,o,n,a)}}return lv.memo(s)}(Wse||(Wse=e6(["\n .popup-content {\n margin: auto;\n background: #fff;\n width: 100%;\n padding: 5px;\n border: 1px solid #d7d7d7;\n max-width: 568px;\n border-radius: 0.25rem;\n }\n\n [role=tooltip].popup-content {\n width: 200px;\n box-shadow: 0 0 3px rgba(0, 0, 0, .16);\n border-radius: 5px\n }\n\n .popup-overlay {\n background: rgba(0, 0, 0, .5);\n padding: 10px;\n }\n\n [data-popup=tooltip].popup-overlay {\n background: transparent\n }\n\n .popup-arrow {\n -webkit-filter: drop-shadow(0 -3px 3px rgba(0, 0, 0, .16));\n filter: drop-shadow(0 -3px 3px rgba(0, 0, 0, .16));\n color: #fff;\n stroke-width: 2px;\n stroke: #d7d7d7;\n stroke-dasharray: 30px;\n stroke-dashoffset: -54px;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0\n }\n"]))),Zse=function(e){var t=e.open,n=e.children;return lv.createElement(lv.Fragment,null,lv.createElement(Yse,{overlayStyle:{zIndex:2e3},closeOnDocumentClick:!1,closeOnEscape:!1,modal:!0,open:t},n),lv.createElement($se,null))};Zse.propTypes={open:Mv.bool,children:Mv.node},Zse.defaultProps={open:!1,children:null};var Jse="default",eue=(Y4(Hse={},Jse,{fill:"none",strokeWidth:2,stroke:"#f4f4f4",strokeDasharray:"7, 4",opacity:.6}),Y4(Hse,"error",{fill:"rgba(234,50,35, 0.1)",strokeWidth:2,stroke:"#ea3223"}),Hse),tue={fill:"rgba(0,0,0, 0.6)"};function nue(e){var t=e.className,n=e.width,r=e.height,a=e.type,o=eue[a];return lv.createElement("svg",{width:n,height:r,className:t},lv.createElement("rect",{x:2,y:2,rx:10,ry:10,width:n-4,height:r-4,style:o}),lv.createElement("path",{d:"M0,".concat(12," Q0,0 ").concat(12,",0 L0,0 Z"),style:tue}),lv.createElement("path",{d:"M0,".concat(r-12," Q0,").concat(r," ").concat(12,",").concat(r," L0,").concat(r," Z"),style:tue}),lv.createElement("path",{d:"M".concat(n-12,",").concat(r," Q").concat(n,",").concat(r," ").concat(n,",").concat(r-12," L").concat(n,",").concat(r," Z"),style:tue}),lv.createElement("path",{d:"M".concat(n-12,",0 Q").concat(n,",0 ").concat(n,",").concat(12," L").concat(n,",0 Z"),style:tue}))}nue.propTypes={className:Mv.string,width:Mv.number,height:Mv.number,type:Mv.oneOf([Jse,"error"])},nue.defaultProps={className:"",width:300,height:200,type:Jse};var rue,aue,oue,iue,sue,uue,cue,lue,pue,due,fue,hue,mue,gue,vue,yue,bue,xue,wue,kue,Sue,Eue,Iue,Cue,Tue=PQ([".flipY-exit{animation-name:",";animation-duration:","ms;animation-timing-function:ease-in;}.flipY-enter{animation-name:",";animation-duration:","ms;animation-timing-function:ease-out;}"],JQ(["from{transform:perspective(400px);}to{transform:perspective(400px) rotateY(90deg);}"]),500,JQ(["from{transform:perspective(400px) rotateY(-90deg);}to{transform:perspective(400px);}"]),500),_ue=Object.freeze({__proto__:null,animationDuration:500,default:Tue}),Nue=PQ([".slide-horizontal{animation-name:",";animation-iteration-count:infinite;animation-duration:2000ms;animation-timing-function:linear;}.slide-vertical{animation-name:",";animation-iteration-count:infinite;animation-duration:2000ms;animation-timing-function:linear;}"],JQ(["from,to{transform:translate3d(-","px,0,0);}50%{transform:translate3d(","px,0,0);}"],20,20),JQ(["from,to{transform:translate3d(0,-","px,0);}50%{transform:translate3d(0,","px,0);}"],20,20)),Aue=Object.freeze({__proto__:null,default:Nue}),Rue=PQ([".blink{animation-name:",";animation-iteration-count:infinite;animation-duration:2000ms;animation-timing-function:linear;}"],JQ(["from,to{opacity:1;}50%{opacity:0;}"])),Oue=Object.freeze({__proto__:null,default:Rue}),Bue=$Q.div(rue||(rue=e6(["\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: ","; // must be higher than BASE_Z_INDEX and lower than other layers\n"])),1001),Due=PQ([".splash-enter{animation-name:",";animation-duration:","ms;animation-timing-function:ease-in;}"],JQ(["from{background:#000;}to{}"]),300),Mue=$Q.div(aue||(aue=e6(["\n ","\n"])),Due),Fue=function(e){var t=e.keyForTransition,n=void 0===t?0:t;return lv.createElement(Mue,null,lv.createElement(nee,null,lv.createElement(Z9,{key:n,timeout:{enter:300,exit:0},classNames:"splash",unmountOnExit:!1},lv.createElement(Bue,null))))},Pue=Object.freeze({__proto__:null,default:Fue}),Lue=PQ([".spin{animation-name:",";animation-iteration-count:infinite;animation-duration:1000ms;animation-timing-function:linear;}"],JQ(["from{transform:rotate(0deg);}to{transform:rotate(360deg);}"])),Uue=Object.freeze({__proto__:null,default:Lue}),Vue=Object.freeze({__proto__:null,flipY:_ue,slide:Aue,blink:Oue,splash:Pue,spin:Uue}),zue=Fue,jue=$Q.div(oue||(oue=e6(["\n ","\n ","\n"])),Tue,Lue),Wue=$Q.img(iue||(iue=e6(["\n border-radius: 5px;\n opacity: 0.7;\n height: 38px;\n"]))),Hue=$Q.div(sue||(sue=e6(["\n cursor: pointer;\n text-align: center;\n width: ","px;\n\n img {\n width: 100%;\n }\n\n z-index: ",";\n position: fixed;\n bottom: ","px;\n"])),60,1020,10),Gue=$Q.div(uue||(uue=e6(["\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n position: absolute;\n margin: auto;\n width: ","px;\n height: ","px;\n img {\n width: 100%;\n }\n"])),100,100),Kue=$Q.div(cue||(cue=e6(["\n color: #fff;\n text-align: center;\n"]))),que=$Q.div(lue||(lue=e6(["\n transform: translateZ(1000px); // to fix rotating bug on safari\n transform-style: preserve-3d;\n position: absolute;\n top: ",";\n z-index: ",";\n"])),(function(e){return e.y}),1020),Que=$Q.div(pue||(pue=e6(["\n display: flex;\n align-items: center;\n"]))),Xue=$Q(Kue)(due||(due=e6(["\n font-size: 20px;\n margin-left: 10px;\n color: #fff;\n"]))),Yue=$Q(Kue)(fue||(fue=e6(["\n font-size: 20px;\n margin-left: 10px;\n color: green;\n position: absolute;\n left: 0;\n top: 10px;\n background: white;\n z-index: ",";\n"])),1030),$ue=$Q(Kue)(hue||(hue=e6(["\n position: absolute;\n font-size: 16px;\n text-align: center;\n color: #fff;\n top: ",";\n z-index: ",";\n"])),(function(e){return e.y}),1020),Zue=$Q($ue)(mue||(mue=e6(["\n background: #ea3223;\n padding: 5px 10px;\n border-radius: 3px;\n"]))),Jue=$Q(Kue)(gue||(gue=e6(["\n position: absolute;\n font-size: 18px;\n text-align: center;\n border-radius: 3px;\n padding: 5px 10px;\n background: #ea3223;\n color: #fff;\n margin: 0 10px;\n top: ",";\n z-index: ",";\n"])),(function(e){return e.y}),1020),ece=$Q.div(vue||(vue=e6(["\n font-size: 18px;\n text-align: center;\n padding: 10px;\n"]))),tce=$Q(nue)(yue||(yue=e6(["\n position: absolute;\n top: 0;\n left: 0;\n"]))),nce={BTN_OK:{en:"OK",vi:"Tôi đã hiểu"},FRONT:{en:"front",vi:"trước"},BACK:{en:"back",vi:"sau"},BTN_USE_THIS_PICTURE:{en:"Use this picture",vi:"Dùng ảnh này"},BTN_TRY_AGAIN:{en:"Try again",vi:"Thử lại"}},rce={WARMUP_INTRO:{en:"Warming up... Please wait a moment",vi:"Đang khởi động, vui lòng chờ trong giây lát..."}},ace=Lv.IDCardMessage,oce=$Q.div(bue||(bue=e6(["\n display: flex;\n justify-content: center;\n align-items: center;\n flex-direction: column;\n padding: 10px;\n"]))),ice=$Q.div(xue||(xue=e6(["\n text-align: center;\n font-size: 1rem;\n"]))),sce=$Q.button(wue||(wue=e6(["\n margin-top: 20px;\n width: 100%;\n max-width: 160px;\n height: 50px;\n background-color: #007bff;\n border: 0;\n outline: none;\n border-radius: 0.25rem;\n color: #fff;\n font-weight: 400;\n cursor: pointer;\n font-size: 1rem;\n"]))),uce=function(e){var t=e.onOk,n=e.maxSessionTime,r=jv.useSDKSettings().lang;return lv.createElement(oce,null,lv.createElement(ice,{className:"popup-message"},t7(ace.TIMEOUT_INSTRUCTION[r])({x:n})),lv.createElement(sce,{className:"popup-button",onClick:t},nce.BTN_OK[r]))};uce.propTypes={onOk:Mv.func,maxSessionTime:Mv.number},uce.defaultProps={onOk:function(){},maxSessionTime:30};var cce=$Q.div(kue||(kue=e6(["\n display: flex;\n justify-content: center;\n align-items: center;\n flex-direction: column;\n padding: 10px;\n"]))),lce=$Q.div(Sue||(Sue=e6(["\n text-align: center;\n font-size: 1rem;\n color: #ea3223;\n margin-top: 10px;\n"]))),pce=$Q.button(Eue||(Eue=e6(["\n margin-top: 20px;\n width: 100%;\n max-width: 160px;\n height: 50px;\n background-color: #007bff;\n border: 0;\n outline: none;\n border-radius: 0.25rem;\n color: #fff;\n font-weight: 400;\n cursor: pointer;\n font-size: 1rem;\n"]))),dce=$Q.img(Iue||(Iue=e6(["\n width: 100%;\n border-radius: 5px;\n"]))),fce=$Q.div(Cue||(Cue=e6(["\n margin: 20px 0;\n width: 100%;\n display: flex;\n justify-content: space-evenly;\n gap: 10px;\n"]))),hce=function(e){var t=e.imageBlobTaken,n=e.onConfirm,r=e.onTryAgain,a=e.error,o=t6(lv.useState(null),2),i=o[0],s=o[1],u=jv.useSDKSettings().lang;return lv.useEffect((function(){var e;return t&&(e=URL.createObjectURL(t),s(e)),function(){URL.revokeObjectURL(e)}}),[t]),lv.createElement(cce,null,lv.createElement(dce,{src:i}),a&&lv.createElement(lce,{className:"confirm-popup-error-message"},a.msg[u]),lv.createElement(fce,null,lv.createElement(pce,{onClick:n},nce.BTN_USE_THIS_PICTURE[u]),lv.createElement(pce,{onClick:r},nce.BTN_TRY_AGAIN[u])))};hce.propTypes={imageBlobTaken:Mv.shape({}),error:Mv.shape({msg:Mv.shape({})}),onConfirm:Mv.func,onTryAgain:Mv.func},hce.defaultProps={imageBlobTaken:{},error:null,onConfirm:function(){},onTryAgain:function(){}};function mce(e){var t=this.__data__=new d7(e);this.size=t.size}mce.prototype.clear=function(){this.__data__=new d7,this.size=0},mce.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},mce.prototype.get=function(e){return this.__data__.get(e)},mce.prototype.has=function(e){return this.__data__.has(e)},mce.prototype.set=function(e,t){var n=this.__data__;if(n instanceof d7){var r=n.__data__;if(!f7||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new g7(r)}return n.set(e,t),this.size=n.size,this};var gce=mce,vce=function(e,t,n){(void 0!==n&&!F5(e[t],n)||void 0===n&&!(t in e))&&M5(e,t,n)},yce=function(e,t,n){for(var r=-1,a=Object(e),o=n(e),i=o.length;i--;){var s=o[++r];if(!1===t(a[s],s,a))break}return e},bce=i6((function(e,t){var n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,a=r&&r.exports===n?e5.Buffer:void 0,o=a?a.allocUnsafe:void 0;e.exports=function(e,t){if(t)return e.slice();var n=e.length,r=o?o(n):new e.constructor(n);return e.copy(r),r}})),xce=e5.Uint8Array,wce=function(e,t){var n=t?function(e){var t=new e.constructor(e.byteLength);return new xce(t).set(new xce(e)),t}(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)},kce=Object.create,Sce=function(){function e(){}return function(t){if(!$6(t))return{};if(kce)return kce(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}(),Ece=function(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]},Ice=function(e,t,n,r,a,o,i){var s=Ece(e,n),u=Ece(t,n),c=i.get(u);if(c)vce(e,n,c);else{var l=o?o(s,u,n+"",e,t,i):void 0,p=void 0===l;if(p){var d=o8(u),f=!d&&s8(u),h=!d&&!f&&p8(u);l=u,d||f||h?o8(s)?l=s:function(e){return l5(e)&&X5(e)}(s)?l=function(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}(s):f?(p=!1,l=bce(u,!0)):h?(p=!1,l=wce(u,!0)):l=[]:T8(u)||a8(u)?(l=s,a8(s)?l=function(e){return U5(e,y8(e))}(s):$6(s)&&!k5(s)||(l=function(e){return"function"!=typeof e.constructor||m8(e)?{}:Sce(w8(e))}(u))):p=!1}p&&(i.set(u,l),a(l,u,r,o,i),i.delete(u)),vce(e,n,l)}},Cce=function e(t,n,r,a,o){t!==n&&yce(n,(function(i,s){if(o||(o=new gce),$6(i))Ice(t,n,s,r,e,a,o);else{var u=a?a(Ece(t,s),i,s+"",t,n,o):void 0;void 0===u&&(u=i),vce(t,s,u)}}),y8)},Tce=J5((function(e,t,n){Cce(e,t,n)})),_ce={data:{settings:{sdk_settings:{id_detection_settings:{auto_capture:{enable:!0,show_capture_button:!0,wait_for_best_image_time_ms:3e3},blur_check:{enable:!0,threshold:.82},disable_capture_button_if_alert:!0,id_detection:{enable:!0},limit_time_settings:{enable:!0,limit_time_second:30,video_partial_length_seconds:15},save_frame_settings:{enable:!1,frames_interval_ms:190,quality_web:80},scan_qr_settings:{enable:!0,limit_time_second:20}}}}}},Nce="SESSION_TIMEOUT",Ace=Lv.IDCardMessage,Rce=Lv.IDCardSide,Oce=Lv.IDCardType,Bce=Lv.Errors;function Dce(e){var t=e.frontCamera,n=e.title,r=e.description,a=e.onClose,o=e.usePortraitMask,i=e.onError,s=e.cardType,u=e.cardSide,c=e.apiCheck,l=e.onSuccess,p=e.frontCardId,d=e.onApiCheck,f=e.enableConfirmPopup,h=e.clientSettings,m=t6(lv.useState(0),2),g=m[0],v=m[1],y=u===Rce.FRONT,b=e.titleIcon||(y?"id_card_front.svg":"id_card_back.svg"),x=Gv.useAsset(b),w=t6(lv.useState({}),2),k=w[0],S=w[1],E=k.yTitle,I=k.yDescription,C=k.yMessage,T=Gv.useAsset("ic_camera.svg"),_=t6(lv.useState(""),2),N=_[0],A=_[1],R=jv.useSDKSettings(),O=R.apiClient,B=R.debug,D=R.lang,M=R.enableAntiDebug,F=lv.useRef(null),P=t6(lv.useState(null),2),L=P[0],U=P[1],V=t6(lv.useState(""),2),z=V[0],j=V[1],W=t6(lv.useState(!1),2),H=W[0],G=W[1],K=t6(lv.useState(null),2),q=K[0],Q=K[1],X=t6(lv.useState(!1),2),Y=X[0],$=X[1],Z=function(){var e=t6(lv.useState(!1),2),t=e[0],n=e[1],r=t6(lv.useState(null),2),a=r[0],o=r[1];return{showPopup:lv.useCallback((function(e){var t=e.popupType;o(t),n(null!==t)}),[]),popupShown:t,popupType:a}}(),J=Z.showPopup,ee=Z.popupShown,te=Z.popupType,ne=lv.useRef(null),re=lv.useRef((function(){})),ae=t6(lv.useState(null),2),oe=ae[0],ie=ae[1],se=lv.useRef(!1),ue=function(e){var t=e.apiCheck,n=e.clientSettings,r=jv.useSDKSettings().apiClient,a=t6(lv.useState(null),2),o=a[0],i=a[1];return lv.useEffect((function(){function e(){return(e=X4(regeneratorRuntime.mark((function e(){var a,o,s,u,c,l,p,d,f,h,m,g,v,y;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a={},!t){e.next=5;break}return e.next=4,r.clientSettings();case 4:a=e.sent;case 5:o=Tce(_ce,n,a),s=E7(o,"data.settings.sdk_settings.id_detection_settings.save_frame_settings.enable"),u=E7(o,"data.settings.sdk_settings.id_detection_settings.save_frame_settings.frames_interval_ms"),c=E7(o,"data.settings.sdk_settings.id_detection_settings.save_frame_settings.quality_web"),l=E7(o,"data.settings.sdk_settings.id_detection_settings.limit_time_settings.enable"),p=E7(o,"data.settings.sdk_settings.id_detection_settings.limit_time_settings.limit_time_second"),d=E7(o,"data.settings.sdk_settings.id_detection_settings.limit_time_settings.video_partial_length_seconds"),f=E7(o,"data.settings.sdk_settings.id_detection_settings.auto_capture.enable"),h=E7(o,"data.settings.sdk_settings.id_detection_settings.auto_capture.wait_for_best_image_time_ms"),m=E7(o,"data.settings.sdk_settings.id_detection_settings.blur_check.enable"),g=E7(o,"data.settings.sdk_settings.id_detection_settings.blur_check.threshold"),v=E7(o,"data.settings.sdk_settings.id_detection_settings.disable_capture_button_if_alert"),y=E7(o,"data.settings.sdk_settings.id_detection_settings.id_detection.enable"),i({enableRecording:s,frameCaptureIntervalMs:u,sessionTime:p,maxRecordingTimePerVideo:d,saveFrameQuality:c,enableTimers:l,enableAutoCapture:f,waitForBestImageTimeMs:h,enableBlurCheck:m,blurThreshold:g,disableCaptureButtonIfAlert:v,enableIdDetection:y});case 19:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[r,t,n]),{settings:o}}({apiCheck:c,clientSettings:h}).settings;lv.useEffect((function(){M&&NK.enableAntiDebug()}),[M]);var ce=lv.useCallback((function(e){j(null===e?"":t7(e.msg[D])({side:y?nce.FRONT[D]:nce.BACK[D]}))}),[D,y]),le=lv.useCallback(function(){var e=X4(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,re.current({imageBlobTaken:t.imageBlob});case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[]),pe=function(e){var t=e.refVideo,n=e.videoPlayed,r=e.cropArea,a=e.settings,o=e.onError,i=e.frontSide,s=e.onAutoCaptureSuccess,u=lv.useRef(null),c=lv.useRef(!1),l=lv.useRef(null),p=t6(lv.useState(!1),2),d=p[0],f=p[1],h=lv.useRef({imageBlob:null,takenAt:null,blurScore:null}),m=lv.useRef({imageBlob:null,blurScore:null,error:null}),g=lv.useRef(!1),v=lv.useRef(!1),y=lv.useRef(null),b=lv.useRef(!1),x=lv.useRef({}),w=jv.useSDKSettings(),k=w.tfjsWasmRoot,S=w.blazefaceRoot,E=w.opencvUrl,I=w.idCardModelUrl;lv.useEffect((function(){function e(){return(e=X4(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!a||d){e.next=10;break}if(!a.enableIdDetection){e.next=8;break}return e.next=4,Vse({opencvUrl:E,modelUrl:I,blazefaceRoot:S,tfjsWasmRoot:k});case 4:x.current=e.sent,y.current=a.enableBlurCheck&&x.current.ableToUseModel,e.next=9;break;case 8:y.current=!1;case 9:f(!0);case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[d,a,k,S,E,I]);var C=lv.useCallback((function(){!0===c.current&&(c.current=!1)}),[]),T=lv.useCallback(function(){var e=X4(regeneratorRuntime.mark((function e(t){var n,r,o,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.blurScore,r=a.blurThreshold,o=h.current,i=m.current,!(n<r&&Ty.hasBetterCardBlurScore(n,o.blurScore))){e.next=14;break}if(!b.current){e.next=9;break}o.imageBlob=i.imageBlob,e.next=12;break;case 9:return e.next=11,Ny.takePicture({canvas:u.current});case 11:o.imageBlob=e.sent;case 12:o.takenAt=(new Date).getTime(),o.blurScore=n;case 14:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[a]),_=lv.useCallback(function(){var e=X4(regeneratorRuntime.mark((function e(t){var n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.blurScore,v.current=!0,r=m.current,!Ty.hasBetterCardBlurScore(n,r.blurScore)){e.next=9;break}return e.next=6,Ny.takePicture({canvas:u.current});case 6:r.imageBlob=e.sent,r.blurScore=n,b.current=!0;case 9:v.current=!1;case 10:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[]),N=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var t,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=a.waitForBestImageTimeMs,null===(n=h.current).imageBlob){e.next=8;break}if(!((new Date).getTime()-n.takenAt>t)){e.next=8;break}return e.next=7,s(n);case 7:C();case 8:case"end":return e.stop()}}),e)}))),[s,a,C]),A=lv.useCallback((function(){g.current=!0}),[]),R=lv.useCallback((function(){return new Promise((function(e){g.current=!1;var t=setInterval((function(){v.current||(clearInterval(t),e())}),150)}))}),[]),O=lv.useCallback(X4(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){var t=a.blurThreshold,n=m.current;y.current?(A(),setTimeout((function(){R().then((function(){Ty.hasBetterCardBlurScore(n.blurScore,t)||(n.error=zse.id_detector_error_blur),e(n)}))}),3e3)):Ny.takePicture({canvas:u.current}).then((function(t){n.imageBlob=t,e(n)}))})));case 1:case"end":return e.stop()}}),e)}))),[a,A,R]),B=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var n,r,s,p,f,v,y,w,k,S,E,I,C,A,R,O,B,D,M,F,P,L,U;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a&&d){e.next=2;break}return e.abrupt("return");case 2:h.current={imageBlob:null,takenAt:null,blurScore:null},m.current={imageBlob:null,blurScore:null,error:null},n=a.enableAutoCapture,r=a.enableBlurCheck,s=a.enableIdDetection,p=x.current,f=p.idCardModel,v=p.blazefaceModel,y=p.ableToUseModel,w=l.current,k=t.current,c.current=!0,S=u.current,E=S.getContext("2d"),I=w.cropX,C=w.cropY,A=w.cropWidth,R=w.cropHeight,O=document.createElement("canvas"),B=O.getContext("2d"),D=s&&y?15:700;case 15:if(E.drawImage(k,I,C,A,R,0,0,A,R),b.current=!1,!s||!y){e.next=72;break}return M=null,e.next=22,f.predict(S,{detectThreshold:.3});case 22:if(!(F=e.sent).card){e.next=68;break}if(!xee({corners:F.card.corners,width:A,height:R})){e.next=65;break}if(!See(F.card.corners)){e.next=62;break}if(P=bee(S,F.card.corners),!((L=Fy.rectAreaRatio({small:{area:P.width*P.height},big:{area:A*R}}))<.5)){e.next=34;break}M=zse.id_detector_card_too_small,e.next=60;break;case 34:if(!(L>.9)){e.next=38;break}M=zse.id_detector_error_incomplete,e.next=60;break;case 38:return O.width=P.width,O.height=P.height,B.putImageData(P,0,0),e.next=43,wee({canvas:O});case 43:if(!e.sent){e.next=48;break}M=zse.glare_detected,e.next=60;break;case 48:return e.next=50,Eee({blazefaceModel:v,predictedIdCardCanvas:O,frontSide:i});case 50:if(M=e.sent){e.next=60;break}if(!r){e.next=60;break}if(U=Ty.calculateIdCardBlurScore({canvas:O}),!g.current){e.next=57;break}return e.next=57,_({blurScore:U});case 57:if(!n){e.next=60;break}return e.next=60,T({blurScore:U});case 60:e.next=63;break;case 62:M=zse.id_detector_validate_angle_error;case 63:e.next=66;break;case 65:M=zse.id_detector_error_incomplete;case 66:e.next=69;break;case 68:M=zse.id_detector_no_cards;case 69:return o(M),e.next=72,N();case 72:if(c.current){e.next=74;break}return e.abrupt("break",78);case 74:return e.next=76,qv.sleep(D);case 76:e.next=15;break;case 78:case"end":return e.stop()}}),e)}))),[t,a,d,i,o,T,_,N]);lv.useEffect((function(){var e=t.current;function a(){return(a=X4(regeneratorRuntime.mark((function t(){var n,a,o,i;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=Ny.analyzeVideoAndWindowSizes(e,r,.05),a=n.cropWidth,o=n.cropHeight,l.current=n,(i=document.createElement("canvas")).width=a,i.height=o,u.current=i,t.next=9,B();case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}n&&r&&d&&function(){a.apply(this,arguments)}()}),[n,r,t,C,B,d]);var D=lv.useCallback((function(){C()}),[C]);return lv.useEffect((function(){return D}),[D]),{refWorkingCanvas:u,stopCheckFrame:C,checkFrame:B,warmupDone:d,takePictureManually:O,refAbleToRunBurstMode:y}}({refVideo:F,videoPlayed:H,cropArea:q,settings:ue,onError:ce,frontSide:y,onAutoCaptureSuccess:le}),de=pe.refWorkingCanvas,fe=pe.stopCheckFrame,he=pe.checkFrame,me=pe.warmupDone,ge=pe.takePictureManually,ve=pe.refAbleToRunBurstMode,ye=function(e){var t=e.refVideo,n=e.videoPlayed,r=e.cropArea,a=e.settings,o=lv.useRef(null),i=lv.useRef(!1),s=lv.useRef([{id:null,frames:[]}]),u=lv.useRef(Xb.createResizer({width:960,height:640})),c=lv.useRef(null),l=lv.useCallback((function(){!0===i.current&&(i.current=!1)}),[]),p=lv.useCallback((function(){s.current=[{id:null,frames:[]}]}),[]),d=lv.useCallback((function(){var e=s.current;e[e.length-1].frames.length>0&&e.push({id:null,frames:[]})}),[]),f=lv.useCallback(function(){var e=X4(regeneratorRuntime.mark((function e(t){var n,r,o,i,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=t.workingCanvas,r=u.current,o=s.current,i=r.resize({srcCanvas:n}),c=i.toDataURL("image/jpeg",a.saveFrameQuality/100).split(",")[1],o[o.length-1].frames.push({base64:c});case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[a]),h=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var n,r,s,u,l,p,d,h,m,g,v;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a){e.next=2;break}return e.abrupt("return");case 2:if(n=a.frameCaptureIntervalMs,a.enableRecording){e.next=5;break}return e.abrupt("return");case 5:r=c.current,s=t.current,i.current=!0,u=o.current,l=u.getContext("2d"),p=r.cropX,d=r.cropY,h=r.cropWidth,m=r.cropHeight,g=null;case 12:if(l.drawImage(s,p,d,h,m,0,0,h,m),!n){e.next=23;break}if(!((v=(new Date).getTime())-g>=n)){e.next=21;break}return e.next=20,f({workingCanvas:u});case 20:g=v;case 21:e.next=25;break;case 23:return e.next=25,f({workingCanvas:u});case 25:if(i.current){e.next=27;break}return e.abrupt("break",31);case 27:return e.next=29,qv.sleep(15);case 29:e.next=12;break;case 31:case"end":return e.stop()}}),e)}))),[t,f,a]);return lv.useEffect((function(){var e=t.current;function a(){return(a=X4(regeneratorRuntime.mark((function t(){var n,a,i,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=Ny.analyzeVideoAndWindowSizes(e,r),a=n.cropWidth,i=n.cropHeight,c.current=n,(s=document.createElement("canvas")).width=a,s.height=i,o.current=s,t.next=9,h();case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}return n&&r&&function(){a.apply(this,arguments)}(),function(){l()}}),[n,r,t,l,d,h]),{refWorkingCanvas:o,stopCheckFrame:l,refRecordedVideos:s,splitVideos:d,resetRecordedVideos:p,checkFrame:h}}({refVideo:F,videoPlayed:H,cropArea:q,settings:ue}),be=ye.stopCheckFrame,xe=ye.refRecordedVideos,we=ye.splitVideos,ke=ye.resetRecordedVideos,Se=ye.checkFrame;!function(e){var t=e.debug,n=e.refRecordedVideos,r=e.refWorkingCanvas,a=e.refVideo,o=e.onChange;lv.useEffect((function(){var e;return t&&(e=setInterval((function(){var e=a.current,t=n.current,i=r.current,s=t[t.length-1],u={videoWidth:e.videoWidth,videoHeight:e.videoHeight,framesCount:s.frames.length,"window.innerWidth":window.innerWidth,"window.innerHeight":window.innerHeight,"canvas.width":null==i?void 0:i.width,"canvas.height":null==i?void 0:i.height};o(JSON.stringify(u,null,2))}),1e3)),function(){return clearInterval(e)}}),[o,t,n,r,a])}({debug:B,refRecordedVideos:xe,refWorkingCanvas:de,refVideo:F,onChange:A});var Ee=Gv.useAsset("ic_loading.png"),Ie=lv.useCallback((function(){be(),fe(),ke(),U(""),J({popupType:Nce})}),[ke,be,fe,J]),Ce=lv.useCallback((function(){we()}),[we]),Te=lv.useCallback((function(e){var t=e.curTimeLeft;U(t7(Ace.REMAINING_TIME[D])({x:t}))}),[D]),_e=function(e){var t=e.videoPlayed,n=e.lang,r=e.onAboutToTimeout,a=e.onSessionTimeout,o=e.onVideoTimeLimitReached,i=e.settings,s=e.warmupDone,u=lv.useRef(),c=t6(lv.useState(0),2),l=c[0],p=c[1],d=lv.useCallback((function(){clearInterval(u.current)}),[]),f=lv.useCallback((function(){p((function(e){return e+1}))}),[]);return lv.useEffect((function(){if(s&&t&&null!=i&&i.enableTimers){var e=i.sessionTime,n=i.maxRecordingTimePerVideo,c=0,l=e/3;u.current=setInterval((function(){var t=e-(c+=1);t<=l&&r({curTimeLeft:t}),c>0&&c%n==0&&o(),0===t&&(d(),a())}),1e3)}return function(){d()}}),[t,n,r,d,a,o,l,i,s]),{stopTimers:d,startTimers:f}}({videoPlayed:H,lang:D,onAboutToTimeout:Te,apiClient:O,apiCheck:c,onSessionTimeout:Ie,onVideoTimeLimitReached:Ce,settings:ue,warmupDone:me}),Ne=_e.stopTimers,Ae=_e.startTimers,Re=lv.useCallback(X4(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return J({popupType:null}),ie(null),se.current=!1,Ae(),e.next=6,Promise.all([Se(),he()]);case 6:case"end":return e.stop()}}),e)}))),[Se,he,Ae,J]),Oe=lv.useCallback((function(e){var t,n,r,a,i,s,u=e.videoAreaWidth,c=e.videoAreaHeight,l=e.lostX,p=e.lostY,d=e.clientHeight;o?(a=.7*(i=c-165),n=(s=(t=p+10)+45)+i+10,r=s+20):(a=b6.isMobile?u-6:Math.floor(.7*u),n=(s=(t=p+10)+50)+(i=Math.floor(Math.min(a/1.5,d-2*p-80-100)))+10,r=s+20);var f=Math.floor((u-a)/2)+l;Q({x:f,y:s,width:a,height:i,surroundStyle:{opacity:.6,background:"#000"}}),S({yTitle:t,yDescription:n,yMessage:r}),G(!0)}),[o]),Be=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var t,n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if($(!0),J({popupType:null}),t=ne.current,n={image:t,recordedVideos:null!=ue&&ue.enableRecording?xe.current:[]},!c){e.next=19;break}return r=null,e.prev=6,d(),e.next=10,fee({image:t,cardSide:u,frontCardId:p,onError:i,apiClient:O,cardType:s,recordedVideos:xe.current});case 10:r=e.sent,e.next=16;break;case 13:e.prev=13,e.t0=e.catch(6),i(J4(J4({},Bce.api_call_error),{},{details:e.t0}));case 16:r&&l(J4(J4({},n),{},{apiResult:r})),e.next=20;break;case 19:l(n);case 20:$(!1);case 21:case"end":return e.stop()}}),e,null,[[6,13]])}))),[c,O,ue,s,u,p,i,l,d,xe,J]),De=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var t,n,r=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.length>0&&void 0!==r[0]?r[0]:{},n=t.imageBlobTaken,!se.current){e.next=3;break}return e.abrupt("return");case 3:se.current=!0,$(!0),be(),fe(),Ne(),U(""),j(""),v((function(e){return e+1})),ne.current=n,f?J({popupType:"CONFIRM"}):Be(),$(!1);case 14:case"end":return e.stop()}}),e)}))),[be,fe,Ne,J,f,Be]);re.current=De;var Me=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var t,n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return $(!0),Ne(),U(""),be(),ve.current||fe(),e.next=7,ge();case 7:return t=e.sent,n=t.imageBlob,r=t.error,ie(r),e.next=13,De({imageBlobTaken:n});case 13:$(!1);case 14:case"end":return e.stop()}}),e)}))),[ge,De,Ne,ve,be,fe]);return lv.createElement(jue,null,lv.createElement(j6,{frontCamera:t,onVideoPlayed:Oe,onClose:a,flipHorizontal:t,ref:F,onError:i},!me&&lv.createElement(Zse,{open:!0},lv.createElement(ece,{className:"warmup-message"},rce.WARMUP_INTRO[D])),H?lv.createElement(lv.Fragment,null,B&&lv.createElement(Yue,null,N),lv.createElement(zue,{keyForTransition:g}),q?lv.createElement(Q6,{x:"".concat(q.x,"px"),y:"".concat(q.y,"px"),width:"".concat(q.width,"px"),height:"".concat(q.height,"px"),surroundStyle:q.surroundStyle},lv.createElement(tce,{width:q.width,height:q.height,type:z?"error":Jse}),Y&&lv.createElement(Gue,null,lv.createElement("img",{src:Ee,alt:"",className:"spin"}))):null,lv.createElement(que,{y:"".concat(E,"px")},lv.createElement(nee,null,lv.createElement(Z9,{key:n,timeout:{enter:500,exit:500},classNames:"flipY",unmountOnExit:!0},lv.createElement(Que,null,lv.createElement(Wue,{src:x,alt:""}),lv.createElement(Xue,{className:"title"},n))))),!z&&lv.createElement($ue,{y:"".concat(I,"px"),className:"description"},r),z&&lv.createElement(Zue,{y:"".concat(I,"px")},z),!Y&&(!(null!=ue&&ue.disableCaptureButtonIfAlert)||!z)&&lv.createElement(Hue,{onClick:Me},lv.createElement("img",{src:T,alt:""})),L&&lv.createElement(Jue,{key:L,className:"message",y:"".concat(C,"px")},L)):null),lv.createElement(Zse,{open:ee},te===Nce&&lv.createElement(uce,{onOk:Re,maxSessionTime:null==ue?void 0:ue.sessionTime}),"CONFIRM"===te&&lv.createElement(hce,{imageBlobTaken:ne.current,error:oe,onConfirm:Be,onTryAgain:Re})))}Dce.propTypes={frontCamera:Mv.bool,usePortraitMask:Mv.bool,cardType:Mv.string,cardSide:Mv.string,title:Mv.string,titleIcon:Mv.string,description:Mv.string,onClose:Mv.func,apiCheck:Mv.bool,onSuccess:Mv.func,onError:Mv.func,frontCardId:Mv.string,onApiCheck:Mv.func,enableConfirmPopup:Mv.bool,clientSettings:Mv.shape({})},Dce.defaultProps={frontCamera:!0,usePortraitMask:!1,cardType:Oce.VN,cardSide:Rce.FRONT,title:"",titleIcon:null,description:"",onClose:function(){},apiCheck:!1,onSuccess:function(){},onError:function(){},frontCardId:null,onApiCheck:function(){},enableConfirmPopup:!0,clientSettings:{}};var Mce,Fce=Object.freeze({__proto__:null,Camera:X6}),Pce="landscape",Lce="portrait",Uce=Lv.Errors,Vce=$Q.div(Mce||(Mce=e6(["\n text-align: center;\n font-size: 20px;\n font-weight: 600;\n"])));function zce(e){var t=$4({},e),n=jv.useSDKSettings().lang,r=Uce.wrong_orientation.msg[n],a=function(){var e=lv.useRef(window.innerWidth>window.innerHeight?Pce:Lce),t=t6(lv.useState(e.current),2),n=t[0],r=t[1];return lv.useEffect((function(){function e(){window.innerWidth>window.innerHeight?r(Pce):r(Lce)}return window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]),b6.isMobile?{curOrientation:n,initOrientation:e.current}:{curOrientation:"desktop"}}().curOrientation;return lv.createElement(lv.Fragment,null,a===Pce&&lv.createElement(Zse,{open:!0},lv.createElement(Vce,null,r)),(a===Lce||"desktop"===a)&&lv.createElement(L9,t))}var jce=z7,Wce=function(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}(U9,["useLivenessDetection"]),Hce=function(e,t,n,r,a,o,i,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,a,o,i,s],l=0;(u=new Error(t.replace(/%s/g,(function(){return c[l++]})))).name="Invariant Violation"}throw u.framesToPop=1,u}},Gce=r(a((function(e,r){!function(e,t){t=t&&t.hasOwnProperty("default")?t.default:t;var r=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/read_id_card_info_sync",e,t)},e}(),a=function(){return(a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};
7138
+ */var Sse=function(){function e(t,n){var r=this;Jm(this,e),this.graph=t,this.parent=n,this.compiledMap=new Map,this._weightMap={},this.SEPERATOR=",",this._functions={},this._functionExecutorMap={},this._outputs=t.outputs,this._inputs=t.inputs,this._initNodes=t.initNodes,this._signature=t.signature,this._functions=t.functions,null!=t.functions&&Object.keys(t.functions).forEach((function(n){r._functionExecutorMap[n]=new e(t.functions[n],r)}))}var t,n,r,a;return tg(e,[{key:"weightIds",get:function(){return this.parent?this.parent.weightIds:this._weightIds}},{key:"functionExecutorMap",get:function(){return this.parent?this.parent.functionExecutorMap:this._functionExecutorMap}},{key:"weightMap",get:function(){return this.parent?this.parent.weightMap:this._weightMap},set:function(e){var t,n=Object.keys(e).map((function(t){return e[t].map((function(e){return e.id}))}));this._weightIds=(t=[]).concat.apply(t,vg(n)),this._weightMap=e}},{key:"resourceManager",set:function(e){this._resourceManager=e}},{key:"inputs",get:function(){return this._inputs.map((function(e){return{name:e.name,shape:e.attrParams.shape?e.attrParams.shape.value:void 0,dtype:e.attrParams.dtype?e.attrParams.dtype.value:void 0}}))}},{key:"outputs",get:function(){return this._outputs.map((function(e){return{name:e.name,shape:e.attrParams.shape?e.attrParams.shape.value:void 0,dtype:e.attrParams.dtype?e.attrParams.dtype.value:void 0}}))}},{key:"inputNodes",get:function(){return this._inputs.map((function(e){return e.signatureKey||e.name}))}},{key:"outputNodes",get:function(){return this._outputs.map((function(e){var t=e.signatureKey||e.name;return e.defaultOutput?"".concat(t,":").concat(e.defaultOutput):t}))}},{key:"functions",get:function(){var e=this;return Object.keys(this._functions).reduce((function(t,n){return t[n]=e._functions[n].signature,t}),{})}},{key:"getCompilationKey",value:function(e,t){var n=e.map((function(e){return e.name})).sort(),r=t.map((function(e){return e.name})).sort();return n.join(this.SEPERATOR)+"--"+r.join(this.SEPERATOR)}},{key:"compile",value:function(e,t){var n=gse(e,t,this.weightMap,this._initNodes),r=n.missingInputs,a=n.dynamicNode,o=n.syncInputs;if(null!=a)throw new Error("This execution contains the node '".concat(a.name,"', which has the dynamic op '").concat(a.op,"'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [").concat(o,"]"));if(r.length>0){var i=t.map((function(e){return e.name})),s=Object.keys(e);throw new Error("Cannot compute the outputs [".concat(i,"] from the provided inputs [").concat(s,"]. Missing the following inputs: [").concat(r,"]"))}return function(e,t,n){var r=n.usedNodes,a=n.inputs,o=[],i=Object.keys(a).map((function(e){return xie(e)[0]})).map((function(t){return e.nodes[t]})),s=e.initNodes;i.forEach((function(e){r.has(e.name)&&o.push(e)})),e.weights.forEach((function(e){r.has(e.name)&&o.push(e)})),null!=s&&s.forEach((function(e){r.has(e.name)&&o.push(e)}));for(var u=new Set,c=[];o.length>0;){var l=o.pop();u.add(l.name),t[l.name]||c.push(l),l.children.forEach((function(e){!u.has(e.name)&&r.has(e.name)&&e.inputs.every((function(e){return u.has(e.name)}))&&o.push(e)}))}return c}(this.graph,this.weightMap,n)}},{key:"execute",value:function(e,t){var n=this;e=this.mapInputs(e);var r=Object.keys(e).sort();this.checkInputs(e),this.checkInputShapeAndType(e),t=this.mapOutputs(t),this.checkOutputs(t);var a=r.map((function(e){return n.graph.nodes[xie(e)[0]]})),o=t.map((function(e){return xie(e)[0]})),i=o.map((function(e){return n.graph.nodes[e]}));0===i.length&&(i=this._outputs);var s=this.getCompilationKey(a,i),u=this.compiledMap.get(s);null==u&&(u=this.compile(e,i),this.compiledMap.set(s,u));var c={},l={};return Dne((function(){var r=new mse(n.weightMap,c,l,n.functionExecutorMap),a=Object.assign({},n.weightMap);Object.keys(e).forEach((function(t){var n=gg(xie(t),2),r=n[0],o=[];o[n[1]]=e[t],a[r]=o}));for(var i=n.getFrozenTensorIds(a),s={},p=0;p<u.length;p++){var d=u[p];if(!a[d.name]){var f=hse(d,a,r,n._resourceManager);if(qee(f))throw new Error("The execution of the op '".concat(d.op,"' returned a promise. Please use model.executeAsync() instead."));a[d.name]=f,n.checkTensorForDisposal(d.name,d,a,r,i,o,s)}}return null==n.parent&&r.dispose(i),t.map((function(e){return vie(e,a,r)}))}))}},{key:"getFrozenTensorIds",value:function(e){var t=[].concat.apply([],Object.keys(e).map((function(t){return e[t]})).map((function(e){return e.map((function(e){return e.id}))})));return new Set(t)}},{key:"checkTensorForDisposal",value:function(e,t,n,r,a,o,i){"control"!==t.category&&-1===o.indexOf(e)&&(n[e].forEach((function(e){null!=e&&(i[e.id]=(i[e.id]||0)+t.children.length)})),t.inputs.forEach((function(e){if("control"!==e.category){var t=function(e,t,n){return t[bie(e,n.currentContextId)]}(e.name,n,r);null!=t&&t.forEach((function(e){if(e&&!e.kept&&!a.has(e.id)){var t=i[e.id];1===t?(e.dispose(),delete i[e.id]):null!=t&&i[e.id]--}}))}})))}},{key:"executeAsync",value:(a=Zm(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this._executeAsync(t,n));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"_executeAsync",value:(r=Zm(regeneratorRuntime.mark((function e(t,n){var r,a,o,i,s,u,c,l,p,d=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=d.length>2&&void 0!==d[2]&&d[2],a=d.length>3&&void 0!==d[3]?d[3]:{},o=d.length>4&&void 0!==d[4]?d[4]:{},r||(t=this.mapInputs(t),this.checkInputs(t),this.checkInputShapeAndType(t),n=this.mapOutputs(n),this.checkOutputs(n)),i=new mse(this.weightMap,a,o,this.functionExecutorMap),e.next=7,this.executeWithControlFlow(t,i,n,r);case 7:return s=e.sent,u=n.map((function(e){return vie(e,s,i)})),c=u.map((function(e){return e.id})),l=Object.keys(t).map((function(e){return t[e].id})),p=new Set([].concat(vg(c),vg(l),vg(this.weightIds))),e.abrupt("return",(Object.keys(s).forEach((function(e){s[e].forEach((function(e){!e||e.kept||e.isDisposed||p.has(e.id)||e.dispose()}))})),null==this.parent&&i.dispose(p),u));case 13:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"executeFunctionAsync",value:(n=Zm(regeneratorRuntime.mark((function e(t,n,r){var a,o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t.reduce((function(e,t,n){return e[o.inputs[n].name]=t,e}),{}),e.abrupt("return",this._executeAsync(a,this.outputNodes,!0,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"executeWithControlFlow",value:(t=Zm(regeneratorRuntime.mark((function e(t,n,r,a){var o,i,s,u,c,l,p,d,f,h,m,g,v,y,b,x,w,k=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=Object.keys(t),i=o.map((function(e){return k.graph.nodes[xie(e)[0]]})),s=r.map((function(e){return xie(e)[0]})),0===(u=s.map((function(e){return k.graph.nodes[e]}))).length&&(u=this._outputs),c=gse(t,u,this.weightMap,this._initNodes),l=c.usedNodes,p=c.missingInputs,d=c.dynamicNode,f=c.syncInputs,h=[].concat(vg(i),vg(this.graph.weights),vg(this._initNodes||[])).map((function(e){return{node:e,contexts:n.currentContext}})),m=Object.assign({},this.weightMap),Object.keys(t).forEach((function(e){var n=gg(xie(e),2),r=n[0],a=[];a[n[1]]=t[e],m[r]=a})),g={},v=this.getFrozenTensorIds(m),y={};case 6:if(!(h.length>0)){e.next=12;break}return b=this.processStack(i,h,n,m,y,v,s,g,l),e.next=10,Promise.all(b);case 10:e.next=6;break;case 12:if(null!=d||a||console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead."),!((x=u.filter((function(e){return!xse(e)&&!vie(e.name,m,n)})).map((function(e){return e.name}))).length>0)){e.next=17;break}throw w="",null!=d&&(w="Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs [".concat(f,"]")),new Error("Cannot compute the outputs [".concat(x,"] from the provided inputs [").concat(o,"]. Consider providing the following inputs: [").concat(p,"]. ").concat(w));case 17:return e.abrupt("return",m);case 18:case"end":return e.stop()}}),e,this)}))),function(e,n,r,a){return t.apply(this,arguments)})},{key:"processStack",value:function(e,t,n,r,a,o,i,s,u){for(var c=this,l=[],p=function(){var e,p=t.pop();n.currentContext=p.contexts;var d="";if("Enter"===p.node.op&&gie("isConstant",p.node,r,n)&&(e=gg(yie(p.node.name,n),1),d=e[0]),null==r[p.node.name]){var f,h=hse(p.node,r,n,c._resourceManager);d||(f=gg(yie(p.node.name,n),1),d=f[0]);var m=n.currentContext;qee(h)?l.push(h.then((function(e){return r[d]=e,n.currentContext=m,c.checkTensorForDisposal(d,p.node,r,n,o,i,s),c.processChildNodes(p.node,t,n,r,a,u),e}))):(r[d]=h,c.checkTensorForDisposal(d,p.node,r,n,o,i,s),c.processChildNodes(p.node,t,n,r,a,u))}else c.processChildNodes(p.node,t,n,r,a,u)};t.length>0;)p();return l}},{key:"processChildNodes",value:function(e,t,n,r,a,o){e.children.forEach((function(e){var i=gg(yie(e.name,n),1)[0];!a[i]&&o.has(e.name)&&("Merge"===e.op?e.inputNames.some((function(e){return!!vie(e,r,n)}))&&(a[i]=!0,t.push({contexts:n.currentContext,node:e})):e.inputNames.every((function(e){return!!vie(e,r,n)}))&&(a[i]=!0,t.push({contexts:n.currentContext,node:e})))}))}},{key:"dispose",value:function(){var e=this;Object.keys(this.weightMap).forEach((function(t){return e.weightMap[t].forEach((function(e){return e.dispose()}))}))}},{key:"checkInputShapeAndType",value:function(e){var t=this;Object.keys(e).forEach((function(n){var r=e[n],a=gg(xie(n),1)[0],o=t.graph.nodes[a];if(o.attrParams.shape&&o.attrParams.shape.value){var i=o.attrParams.shape.value;Nee(i.length===r.shape.length&&r.shape.every((function(e,t){return-1===i[t]||i[t]===e})),(function(){return"The shape of dict['".concat(o.name,"'] provided in model.execute(dict) must be [").concat(i,"], but was [").concat(r.shape,"]")}))}o.attrParams.dtype&&o.attrParams.dtype.value&&Nee(r.dtype===o.attrParams.dtype.value,(function(){return"The dtype of dict['".concat(o.name,"'] provided in model.execute(dict) must be ").concat(o.attrParams.dtype.value,", but was ").concat(r.dtype)}))}))}},{key:"mapInputs",value:function(e){var t={};for(var n in e)null!=this._signature&&null!=this._signature.inputs&&null!=this._signature.inputs[n]?t[this._signature.inputs[n].name]=e[n]:t[n]=e[n];return t}},{key:"checkInputs",value:function(e){var t=this,n=Object.keys(e).filter((function(e){var n=gg(xie(e),1)[0];return null==t.graph.nodes[n]}));if(n.length>0)throw new Error("The dict provided in model.execute(dict) has keys: [".concat(n,"] that are not part of graph"))}},{key:"mapOutputs",value:function(e){var t=this;return e.map((function(e){return null!=t._signature&&null!=t._signature.outputs&&null!=t._signature.outputs[e]?t._signature.outputs[e].name:e}),{})}},{key:"checkOutputs",value:function(e){var t=this;e.forEach((function(e){var n=gg(xie(e),1)[0];if(!t.graph.nodes[n])throw new Error("The output '".concat(e,"' is not found in the graph"))}))}}]),e}(),Ese=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Jm(this,e),this.hashTableNameToHandle=t,this.hashTableMap=n}return tg(e,[{key:"addHashTable",value:function(e,t){this.hashTableNameToHandle[e]=t.handle,this.hashTableMap[t.id]=t}},{key:"getHashTableHandleByName",value:function(e){return this.hashTableNameToHandle[e]}},{key:"getHashTableById",value:function(e){return this.hashTableMap[e]}},{key:"dispose",value:function(){for(var e in this.hashTableMap)this.hashTableMap[e].clearAndClose(),delete this.hashTableMap[e];for(var t in this.hashTableNameToHandle)this.hashTableNameToHandle[t].dispose(),delete this.hashTableNameToHandle[t]}}]),e}(),Ise=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Jm(this,e),this.modelUrl=t,this.loadOptions=n,this.version="n/a",null==n&&(this.loadOptions={}),this.resourceManager=new Ese}var t,n,r;return tg(e,[{key:"modelVersion",get:function(){return this.version}},{key:"inputNodes",get:function(){return this.executor.inputNodes}},{key:"outputNodes",get:function(){return this.executor.outputNodes}},{key:"inputs",get:function(){return this.executor.inputs}},{key:"outputs",get:function(){return this.executor.outputs}},{key:"weights",get:function(){return this.executor.weightMap}},{key:"metadata",get:function(){return this.artifacts.userDefinedMetadata}},{key:"modelSignature",get:function(){return this.signature}},{key:"findIOHandler",value:function(){var e,t,n=this.modelUrl;if(null!=n.load)this.handler=n;else if(null!=this.loadOptions.requestInit)this.handler=_ne(n,this.loadOptions);else{var r=(e=n,t=this.loadOptions,Zte.getLoadHandlers(e,t));if(0===r.length)r.push(_ne(n,this.loadOptions));else if(r.length>1)throw new Error("Found more than one (".concat(r.length,") load handlers for URL '").concat([n],"'"));this.handler=r[0]}}},{key:"load",value:(r=Zm(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.findIOHandler(),null!=this.handler.load){e.next=2;break}throw new Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");case 2:return e.next=4,this.handler.load();case 4:return t=e.sent,e.abrupt("return",this.loadSync(t));case 6:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"loadSync",value:function(e){this.artifacts=e;var t,n=this.artifacts.modelTopology;t=null!=this.artifacts.userDefinedMetadata&&null!=this.artifacts.userDefinedMetadata.signature?this.artifacts.userDefinedMetadata.signature:this.artifacts.signature,this.signature=t,this.version="".concat(n.versions.producer,".").concat(n.versions.minConsumer);var r=function(e,t){var n,r,a={},o=0,i=xg(t);try{for(i.s();!(r=i.n()).done;){var s=r.value,u=s.name,c=s.dtype,l=s.shape,p=Oee(l),d=void 0;if("quantization"in s){var f=s.quantization;if("uint8"===f.dtype||"uint16"===f.dtype){if(!("min"in f)||!("scale"in f))throw new Error("Weight ".concat(s.name," with quantization ").concat(f.dtype," doesn't have corresponding metadata min and scale."))}else{if("float16"!==f.dtype)throw new Error("Weight ".concat(s.name," has unknown quantization dtype ").concat(f.dtype,". Supported quantization dtypes are: 'uint8', 'uint16', and 'float16'."));if("float32"!==c)throw new Error("Weight ".concat(s.name," is quantized with ").concat(f.dtype," which only supports weights of type float32 not ").concat(c,"."))}var h=Kte[f.dtype],m=e.slice(o,o+p*h),g="uint8"===f.dtype?new Uint8Array(m):new Uint16Array(m);if("float32"===c)if("uint8"===f.dtype||"uint16"===f.dtype){d=new Float32Array(g.length);for(var v=0;v<g.length;v++){var y=g[v];d[v]=y*f.scale+f.min}}else{if("float16"!==f.dtype)throw new Error("Unsupported quantization type ".concat(f.dtype," for weight type float32."));void 0===n&&(n=$te()),d=n(g)}else{if("int32"!==c)throw new Error("Unsupported dtype in weight '".concat(u,"': ").concat(c));if("uint8"!==f.dtype&&"uint16"!==f.dtype)throw new Error("Unsupported quantization type ".concat(f.dtype," for weight type int32."));d=new Int32Array(g.length);for(var b=0;b<g.length;b++){var x=g[b];d[b]=Math.round(x*f.scale+f.min)}}o+=p*h}else if("string"===c){var w=Oee(s.shape);d=[];for(var k=0;k<w;k++){var S=new Uint32Array(e.slice(o,o+4))[0];o+=4;var E=new Uint8Array(e.slice(o,o+S));d.push(E),o+=S}}else{var I=Kte[c],C=e.slice(o,o+p*I);if("float32"===c)d=new Float32Array(C);else if("int32"===c)d=new Int32Array(C);else if("bool"===c)d=new Uint8Array(C);else{if("complex64"!==c)throw new Error("Unsupported dtype in weight '".concat(u,"': ").concat(c));d=new Float32Array(C);for(var T=new Float32Array(d.length/2),_=new Float32Array(d.length/2),N=0;N<T.length;N++)T[N]=d[2*N],_[N]=d[2*N+1];var A=Gte(T,l,"float32"),R=Gte(_,l,"float32");a[u]=Wte(A,R),A.dispose(),R.dispose()}o+=p*I}"complex64"!==c&&(a[u]=Gte(d,l,c))}}catch(e){i.e(e)}finally{i.f()}return a}(this.artifacts.weightData,this.artifacts.weightSpecs);if(this.executor=new Sse(jie.Instance.transformGraph(n,this.signature)),this.executor.weightMap=this.convertTensorMapToTensorsMap(r),this.executor.resourceManager=this.resourceManager,null!=e.modelInitializer&&null!=e.modelInitializer.node){var a=jie.Instance.transformGraph(e.modelInitializer);this.initializer=new Sse(a),this.initializer.weightMap=this.executor.weightMap,this.initializer.resourceManager=this.resourceManager,this.initializer.executeAsync({},[])}return!0}},{key:"save",value:(n=Zm(regeneratorRuntime.mark((function e(t,n){var r,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t){e.next=7;break}if(a=t,0!==(r=Zte.getSaveHandlers(a)).length){e.next=4;break}throw new Error("Cannot find any save handlers for URL '".concat(t,"'"));case 4:if(!(r.length>1)){e.next=6;break}throw new Error("Found more than one (".concat(r.length,") save handlers for URL '").concat(t,"'"));case 6:t=r[0];case 7:if(null!=t.save){e.next=9;break}throw new Error("GraphModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");case 9:return e.abrupt("return",t.save(this.artifacts));case 10:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"predict",value:function(e,t){return this.execute(e,this.outputNodes)}},{key:"normalizeInputs",value:function(e){if(!(e instanceof bte||Array.isArray(e)))return e;if((e=Array.isArray(e)?e:[e]).length!==this.inputNodes.length)throw new Error("Input tensor count mismatch,the graph model has ".concat(this.inputNodes.length," placeholders, while there are ").concat(e.length," input tensors."));return this.inputNodes.reduce((function(t,n,r){return t[n]=e[r],t}),{})}},{key:"normalizeOutputs",value:function(e){return e=e||this.outputNodes,Array.isArray(e)?e:[e]}},{key:"execute",value:function(e,t){e=this.normalizeInputs(e),t=this.normalizeOutputs(t);var n=this.executor.execute(e,t);return n.length>1?n:n[0]}},{key:"executeAsync",value:(t=Zm(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.normalizeInputs(t),n=this.normalizeOutputs(n),e.next=3,this.executor.executeAsync(t,n);case 3:return r=e.sent,e.abrupt("return",r.length>1?r:r[0]);case 5:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"convertTensorMapToTensorsMap",value:function(e){return Object.keys(e).reduce((function(t,n){return t[n]=[e[n]],t}),{})}},{key:"dispose",value:function(){this.executor.dispose(),this.initializer&&this.initializer.dispose(),this.resourceManager.dispose()}}]),e}();function Cse(e){return Tse.apply(this,arguments)}function Tse(){return(Tse=Zm(regeneratorRuntime.mark((function e(t){var n,r,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=a.length>1&&void 0!==a[1]?a[1]:{},null!=t){e.next=3;break}throw new Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");case 3:return null==n&&(n={}),n.fromTFHub&&null==t.load&&(t.endsWith("/")||(t+="/"),t="".concat(t,"model.json?tfjs-format=file")),r=new Ise(t,n),e.next=7,r.load();case 7:return e.abrupt("return",r);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var _se="https://unpkg.com/tv-model-prod@1.0.2/web_model/web_model_uint8/model.json",Nse="https://unpkg.com/tv-model-prod@1.0.2/libs/opencv.js",Ase={0:"top-left",1:"top-right",2:"bottom-right",3:"bottom-left",4:"cccd.front",5:"passport",6:"cmnd_old.front",7:"cmnd_old.back",8:"cmnd_new.front",9:"cmnd_new.back",10:"cccd_new.front",11:"cccd_new.back"};function Rse(e){var t,n,r,a,o,i=e.card,s=e.corners,u=i.box,c={x:(u[1]+u[3])/2,y:(u[0]+u[2])/2},l=u[2]-u[0],p=u[1]-u[3],d=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=r6(e))){n&&(e=n);var r=0,a=function(){};return{s:a,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,s=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,o=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw o}}}}(s);try{for(d.s();!(o=d.n()).done;){var f=o.value;switch(f.label){case"top-left":t||(t=f.location);break;case"top-right":n||(n=f.location);break;case"bottom-right":r||(r=f.location);break;case"bottom-left":a||(a=f.location)}}}catch(e){d.e(e)}finally{d.f()}if(![t,n,r,a].every(Boolean))return console.debug("Not qualified, corners missing"),!1;var h={x:(t.x+r.x)/2,y:(t.y+r.y)/2},m={x:(n.x+a.x)/2,y:(n.y+a.y)/2},g=gee(c,h),v=gee(c,m);return Math.sqrt(g)>(l+p)/8||Math.sqrt(v)>(l+p)/8?(console.debug("Not qualified, not close enough"),!1):(console.debug("Qualified"),!0)}function Ose(e){return Bse.apply(this,arguments)}function Bse(){return(Bse=X4(regeneratorRuntime.mark((function e(t){var n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.url,r=void 0===n?Nse:n,!window.cv){e.next=3;break}return e.abrupt("return",Promise.resolve());case 3:return e.next=5,yx.loadExternalScript({url:r});case 5:return e.abrupt("return",new Promise((function(e){window.cv.onRuntimeInitialized=e})));case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Dse=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n,r,a,o,i,s;return t=e,(n=[{key:"load",value:(s=X4(regeneratorRuntime.mark((function e(){var t,n,r,a,o=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=o.length>0&&void 0!==o[0]?o[0]:{},n=t.opencvUrl,r=t.modelUrl,a=t.tfjsWasmRoot,e.next=3,Promise.all([Ose({url:n}),this.loadModel({modelUrl:r,tfjsWasmRoot:a})]);case 3:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"loadModel",value:(i=X4(regeneratorRuntime.mark((function e(){var t,n,r,a,o,i,s=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=t.modelUrl,r=void 0===n?_se:n,a=t.tfjsWasmRoot,e.next=3,_K.initTensorFlow({tfjsWasmRoot:a});case 3:return e.next=5,Cse(r,{fetchFunc:yx.fetchWithDecryption});case 5:this.model=e.sent,o=this.model.inputs,i=this.model.outputs,this.boxesIndex=i.findIndex((function(e){return"Identity_3"===e.name})),this.classesIndex=i.findIndex((function(e){return"Identity_2"===e.name})),this.scoresIndex=i.findIndex((function(e){return"Identity_1"===e.name})),this.inputSize=[o[0].shape[1],o[0].shape[2]];case 12:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"dispose",value:(o=X4(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.model&&this.model.dispose();case 1:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"predict",value:(a=X4(regeneratorRuntime.mark((function e(t){var n,r,a,o,i,s,u,c,l,p,d,f,h,m,g,v,y,b,x,w,k,S,E,I,C,T,_,N=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=N.length>1&&void 0!==N[1]?N[1]:{},r=n.imgMargin,a=void 0===r?.5:r,o=n.detectThreshold,i=void 0===o?.3:o,s=n.maxNumReturns,u=void 0===s?100:s,c=window,l=c.cv,p={},d=t.width,f=t.height,p.originalWidth=d,p.originalHeight=f,h=yee({canvas:t,imgMargin:a}),m=h.margin,g=h.mat,v=t6(this.inputSize,2),y=v[0],b=v[1],x=new l.Mat,l.resize(g,x,new l.Size(y,b),0,0,l.INTER_AREA),w=g.cols/y,k=g.rows/b,(S=document.createElement("canvas")).width=y,S.height=b,S.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(x.data),x.cols,x.rows),0,0),g.delete(),x.delete(),p.canvas=S,p.margin=m,e.next=24,this.detect(S,{detectThreshold:i,maxNumReturns:u});case 24:if(E=e.sent,I={inputImage:p,card:null},C=[],T=[],E.forEach((function(e){var t=t6(e.box,4),n=t[0],r=t[1],a=t[2],o=t[3];e.clazz<=3?C.push({clazz:e.clazz,label:e.label,score:e.score,location:{x:Tee(Math.floor((o+r)/2*w-m),0,d),y:Tee(Math.floor((n+a)/2*k-m),0,f)},scaledLocation:{x:Tee(Math.floor((o+r)/2),0,S.width),y:Tee(Math.floor((n+a)/2),0,S.height)}}):T.push({label:e.label,score:e.score,box:[Tee(Math.floor(n*k-m),0,f),Tee(Math.floor(r*w-m),0,d),Tee(Math.floor(a*k-m),0,f),Tee(Math.floor(o*w-m),0,d)]})})),C.sort((function(e,t){return t.score-e.score})),T.sort((function(e,t){return t.score-e.score})),!(T.length>0)){e.next=40;break}if(Rse({card:_=T[0],corners:C})){e.next=36;break}return console.debug("Not qualified.",_,C),e.abrupt("return",I);case 36:return C.sort((function(e,t){return e.clazz-t.clazz})),_.corners=C,I.card=_,e.abrupt("return",I);case 40:return e.abrupt("return",I);case 41:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"detect",value:(r=X4(regeneratorRuntime.mark((function e(t){var n,r,a,o,i,s,u,c,l,p,d,f,h,m,g,v,y,b,x,w,k,S,E=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=E.length>1&&void 0!==E[1]?E[1]:{},r=n.detectThreshold,a=n.maxNumReturns,o=t.width,i=t.height,s=Dne((function(){var e=t;return e instanceof bte||(e=Bne(e)),Ure(wne(e,"float32"),0)})),u=this.model.execute(s),s.dispose(),e.next=8,Promise.all([u[this.boxesIndex].array(),u[this.classesIndex].data(),u[this.scoresIndex].data()]);case 8:for(c=e.sent,l=t6(c,3),p=t6(l[0],1),d=p[0],f=l[1],h=l[2],m=[],g=Math.min(h.length,a),v=0;v<g;v++)(y=h[v])>r&&(x=f[v],w=null!==(b=Ase[Math.round(x)])&&void 0!==b?b:"NA",k=d[v],S=[k[0]*i,k[3]*o,k[2]*i,k[1]*o],m.push({score:y,clazz:x,box:S,label:w}));return e.abrupt("return",m);case 18:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,n),e}();function Mse(e){return Fse.apply(this,arguments)}function Fse(){return(Fse=X4(regeneratorRuntime.mark((function e(t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.idCardModel,e.abrupt("return",new Promise((function(e,t){var r=document.createElement("canvas");setTimeout(t,1e3),n.predict(r).then(e)})));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pse(e){return Lse.apply(this,arguments)}function Lse(){return(Lse=X4(regeneratorRuntime.mark((function e(t){var n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.idCardModel,r=!0,e.prev=2,e.next=5,Mse({idCardModel:n});case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),r=!1;case 10:return e.abrupt("return",{fastEnough:r});case 11:case"end":return e.stop()}}),e,null,[[2,7]])})))).apply(this,arguments)}function Use(){return(Use=X4(regeneratorRuntime.mark((function e(){var t,n,r,a,o,i,s,u,c,l,p,d,f,h=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=h.length>0&&void 0!==h[0]?h[0]:{},n=t.opencvUrl,r=t.modelUrl,a=t.blazefaceRoot,o=t.tfjsWasmRoot,!b6.isIOS){e.next=3;break}return e.abrupt("return",{ableToUseModel:!1});case 3:return i=new Dse,e.next=6,Promise.all([_K.loadBlazeface({modelUrl:a}),i.load({opencvUrl:n,modelUrl:r,tfjsWasmRoot:o})]);case 6:return s=e.sent,u=t6(s,1),c=u[0],l=!0,p=document.createElement("canvas"),e.prev=11,e.next=14,i.predict(p);case 14:return e.next=16,Pse({idCardModel:i});case 16:d=e.sent,f=d.fastEnough,l=f,e.next=24;break;case 21:e.prev=21,e.t0=e.catch(11),l=!1;case 24:return e.abrupt("return",{ableToUseModel:l,idCardModel:i,blazefaceModel:c});case 25:case"end":return e.stop()}}),e,null,[[11,21]])})))).apply(this,arguments)}var Vse=function(e){return function(e,t){var n;if("function"!=typeof t)throw new TypeError("Expected a function");return e=Cee(e),function(){return--e>0&&(n=t.apply(this,arguments)),e<=1&&(t=void 0),n}}(2,e)}((function(){return Use.apply(this,arguments)})),zse=Lv.Errors;function jse(){return(jse=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var Wse,Hse,Gse="undefined"!=typeof window?lv.useLayoutEffect:lv.useEffect,Kse={popupContent:{tooltip:{position:"absolute",zIndex:999},modal:{position:"relative",margin:"auto"}},popupArrow:{height:"8px",width:"16px",position:"absolute",background:"transparent",color:"#FFF",zIndex:-1},overlay:{tooltip:{position:"fixed",top:"0",bottom:"0",left:"0",right:"0",zIndex:999},modal:{position:"fixed",top:"0",bottom:"0",left:"0",right:"0",display:"flex",zIndex:999}}},qse=["top left","top center","top right","right top","right center","right bottom","bottom left","bottom center","bottom right","left top","left center","left bottom"],Qse=function(e,t,n,r,a){var o=a.offsetX,i=a.offsetY,s=r?8:0,u=n.split(" "),c=e.top+e.height/2,l=e.left+e.width/2,p=t.height,d=t.width,f=c-p/2,h=l-d/2,m="",g="0%",v="0%";switch(u[0]){case"top":f-=p/2+e.height/2+s,m="rotate(180deg) translateX(50%)",g="100%",v="50%";break;case"bottom":f+=p/2+e.height/2+s,m="rotate(0deg) translateY(-100%) translateX(-50%)",v="50%";break;case"left":h-=d/2+e.width/2+s,m=" rotate(90deg) translateY(50%) translateX(-25%)",v="100%",g="50%";break;case"right":h+=d/2+e.width/2+s,m="rotate(-90deg) translateY(-150%) translateX(25%)",g="50%"}switch(u[1]){case"top":f=e.top,g=e.height/2+"px";break;case"bottom":f=e.top-p+e.height,g=p-e.height/2+"px";break;case"left":h=e.left,v=e.width/2+"px";break;case"right":h=e.left-d+e.width,v=d-e.width/2+"px"}return{top:f="top"===u[0]?f-i:f+i,left:h="left"===u[0]?h-o:h+o,transform:m,arrowLeft:v,arrowTop:g}},Xse=0,Yse=lv.forwardRef((function(e,t){var n=e.trigger,r=void 0===n?null:n,a=e.onOpen,o=void 0===a?function(){}:a,i=e.onClose,s=void 0===i?function(){}:i,u=e.defaultOpen,c=void 0!==u&&u,l=e.open,p=void 0===l?void 0:l,d=e.disabled,f=void 0!==d&&d,h=e.nested,m=void 0!==h&&h,g=e.closeOnDocumentClick,v=void 0===g||g,y=e.repositionOnResize,b=void 0===y||y,x=e.closeOnEscape,w=void 0===x||x,k=e.on,S=void 0===k?["click"]:k,E=e.contentStyle,I=void 0===E?{}:E,C=e.arrowStyle,T=void 0===C?{}:C,_=e.overlayStyle,N=void 0===_?{}:_,A=e.className,R=void 0===A?"":A,O=e.position,B=void 0===O?"bottom center":O,D=e.modal,M=void 0!==D&&D,F=e.lockScroll,P=void 0!==F&&F,L=e.arrow,U=void 0===L||L,V=e.offsetX,z=void 0===V?0:V,j=e.offsetY,W=void 0===j?0:j,H=e.mouseEnterDelay,G=void 0===H?100:H,K=e.mouseLeaveDelay,q=void 0===K?100:K,Q=e.keepTooltipInside,X=void 0!==Q&&Q,Y=e.children,$=lv.useState(p||c),Z=$[0],J=$[1],ee=lv.useRef(null),te=lv.useRef(null),ne=lv.useRef(null),re=lv.useRef(null),ae=lv.useRef("popup-"+ ++Xse),oe=!!M||!r,ie=lv.useRef(0);Gse((function(){return Z?(re.current=document.activeElement,ge(),me(),fe()):he(),function(){clearTimeout(ie.current)}}),[Z]),lv.useEffect((function(){"boolean"==typeof p&&(p?se():ue())}),[p,f]);var se=function(e){Z||f||(J(!0),setTimeout((function(){return o(e)}),0))},ue=function(e){var t;Z&&!f&&(J(!1),oe&&(null===(t=re.current)||void 0===t||t.focus()),setTimeout((function(){return s(e)}),0))},ce=function(e){null==e||e.stopPropagation(),Z?ue(e):se(e)},le=function(e){clearTimeout(ie.current),ie.current=setTimeout((function(){return se(e)}),G)},pe=function(e){null==e||e.preventDefault(),ce()},de=function(e){clearTimeout(ie.current),ie.current=setTimeout((function(){return ue(e)}),q)},fe=function(){oe&&P&&(document.getElementsByTagName("body")[0].style.overflow="hidden")},he=function(){oe&&P&&(document.getElementsByTagName("body")[0].style.overflow="auto")},me=function(){var e,t=null==te||null===(e=te.current)||void 0===e?void 0:e.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]'),n=Array.prototype.slice.call(t)[0];null==n||n.focus()};lv.useImperativeHandle(t,(function(){return{open:function(){se()},close:function(){ue()},toggle:function(){ce()}}}));var ge=function(){if(!oe&&Z&&(null==ee?void 0:ee.current)&&(null==ee?void 0:ee.current)&&(null==te?void 0:te.current)){var e,t,n=function(e,t,n,r,a,o){var i=a.offsetX,s=a.offsetY,u={arrowLeft:"0%",arrowTop:"0%",left:0,top:0,transform:"rotate(135deg)"},c=0,l=function(e){var t={top:0,left:0,width:window.innerWidth,height:window.innerHeight};if("string"==typeof e){var n=document.querySelector(e);null!==n&&(t=n.getBoundingClientRect())}return t}(o),p=Array.isArray(n)?n:[n];for((o||Array.isArray(n))&&(p=[].concat(p,qse));c<p.length;){var d={top:(u=Qse(e,t,p[c],r,{offsetX:i,offsetY:s})).top,left:u.left,width:t.width,height:t.height};if(!(d.top<=l.top||d.left<=l.left||d.top+d.height>=l.top+l.height||d.left+d.width>=l.left+l.width))break;c++}return u}(ee.current.getBoundingClientRect(),te.current.getBoundingClientRect(),B,U,{offsetX:z,offsetY:W},X);te.current.style.top=n.top+window.scrollY+"px",te.current.style.left=n.left+window.scrollX+"px",U&&ne.current&&(ne.current.style.transform=n.transform,ne.current.style.setProperty("-ms-transform",n.transform),ne.current.style.setProperty("-webkit-transform",n.transform),ne.current.style.top=(null===(e=T.top)||void 0===e?void 0:e.toString())||n.arrowTop,ne.current.style.left=(null===(t=T.left)||void 0===t?void 0:t.toString())||n.arrowLeft)}};!function(e,t){void 0===t&&(t=!0),lv.useEffect((function(){if(t){var n=function(t){"Escape"===t.key&&e(t)};return document.addEventListener("keyup",n),function(){t&&document.removeEventListener("keyup",n)}}}),[e,t])}(ue,w),function(e,t){void 0===t&&(t=!0),lv.useEffect((function(){if(t){var n=function(t){if(9===t.keyCode){var n,r=null==e||null===(n=e.current)||void 0===n?void 0:n.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]'),a=Array.prototype.slice.call(r);if(1===a.length)return void t.preventDefault();var o=a[0],i=a[a.length-1];t.shiftKey&&document.activeElement===o?(t.preventDefault(),i.focus()):document.activeElement===i&&(t.preventDefault(),o.focus())}};return document.addEventListener("keydown",n),function(){t&&document.removeEventListener("keydown",n)}}}),[e,t])}(te,Z&&oe),function(e,t){void 0===t&&(t=!0),lv.useEffect((function(){if(t){var n=function(){e()};return window.addEventListener("resize",n),function(){t&&window.removeEventListener("resize",n)}}}),[e,t])}(ge,b),function(e,t,n){void 0===n&&(n=!0),lv.useEffect((function(){if(n){var r=function(n){var r=Array.isArray(e)?e:[e],a=!1;r.forEach((function(e){e.current&&!e.current.contains(n.target)||(a=!0)})),n.stopPropagation(),a||t(n)};return document.addEventListener("mousedown",r),document.addEventListener("touchstart",r),function(){n&&(document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r))}}}),[e,t,n])}(r?[te,ee]:[te],ue,v&&!m);var ve,ye=function(){return lv.createElement("div",Object.assign({},(e=oe?Kse.popupContent.modal:Kse.popupContent.tooltip,t={className:"popup-content "+(""!==R?R.split(" ").map((function(e){return e+"-content"})).join(" "):""),style:jse({},e,I,{pointerEvents:"auto"}),ref:te,onClick:function(e){e.stopPropagation()}},!M&&S.indexOf("hover")>=0&&(t.onMouseEnter=le,t.onMouseLeave=de),t),{key:"C",role:oe?"dialog":"tooltip",id:ae.current}),U&&!oe&&lv.createElement("div",{ref:ne,style:Kse.popupArrow},lv.createElement("svg",{"data-testid":"arrow",className:"popup-arrow "+(""!==R?R.split(" ").map((function(e){return e+"-arrow"})).join(" "):""),viewBox:"0 0 32 16",style:jse({position:"absolute"},T)},lv.createElement("path",{d:"M16 0l16 16H0z",fill:"currentcolor"}))),Y&&"function"==typeof Y?Y(ue,Z):Y);var e,t},be=!(S.indexOf("hover")>=0),xe=oe?Kse.overlay.modal:Kse.overlay.tooltip,we=[be&&lv.createElement("div",{key:"O","data-testid":"overlay","data-popup":oe?"modal":"tooltip",className:"popup-overlay "+(""!==R?R.split(" ").map((function(e){return e+"-overlay"})).join(" "):""),style:jse({},xe,N,{pointerEvents:v&&m||oe?"auto":"none"}),onClick:v&&m?ue:void 0,tabIndex:-1},oe&&ye()),!oe&&ye()];return lv.createElement(lv.Fragment,null,function(){for(var e={key:"T",ref:ee,"aria-describedby":ae.current},t=Array.isArray(S)?S:[S],n=0,a=t.length;n<a;n++)switch(t[n]){case"click":e.onClick=ce;break;case"right-click":e.onContextMenu=pe;break;case"hover":e.onMouseEnter=le,e.onMouseLeave=de;break;case"focus":e.onFocus=le,e.onBlur=de}if("function"==typeof r){var o=r(Z);return!!r&&lv.cloneElement(o,e)}return!!r&&lv.cloneElement(r,e)}(),Z&&K4.createPortal(we,(null===(ve=document.getElementById("popup-root"))&&((ve=document.createElement("div")).setAttribute("id","popup-root"),document.body.appendChild(ve)),ve)))})),$se=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var a=PQ.apply(void 0,[e].concat(n)),o="sc-global-"+jQ(JSON.stringify(a)),i=new ZQ(a,o);function s(e){var t=TQ(),n=_Q(),r=lv.useContext(QQ),a=lv.useRef(t.allocateGSInstance(o)).current;return lv.useLayoutEffect((function(){return u(a,e,t,r,n),function(){return i.removeStyles(a,t)}}),[a,e,t,r,n]),null}function u(e,t,n,r,a){if(i.isStatic)i.renderStyles(e,qq,n,a);else{var o=Fq({},t,{theme:LQ(t,r,s.defaultProps)});i.renderStyles(e,o,n,a)}}return lv.memo(s)}(Wse||(Wse=e6(["\n .popup-content {\n margin: auto;\n background: #fff;\n width: 100%;\n padding: 5px;\n border: 1px solid #d7d7d7;\n max-width: 568px;\n border-radius: 0.25rem;\n }\n\n [role=tooltip].popup-content {\n width: 200px;\n box-shadow: 0 0 3px rgba(0, 0, 0, .16);\n border-radius: 5px\n }\n\n .popup-overlay {\n background: rgba(0, 0, 0, .5);\n padding: 10px;\n }\n\n [data-popup=tooltip].popup-overlay {\n background: transparent\n }\n\n .popup-arrow {\n -webkit-filter: drop-shadow(0 -3px 3px rgba(0, 0, 0, .16));\n filter: drop-shadow(0 -3px 3px rgba(0, 0, 0, .16));\n color: #fff;\n stroke-width: 2px;\n stroke: #d7d7d7;\n stroke-dasharray: 30px;\n stroke-dashoffset: -54px;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0\n }\n"]))),Zse=function(e){var t=e.open,n=e.children;return lv.createElement(lv.Fragment,null,lv.createElement(Yse,{overlayStyle:{zIndex:2e3},closeOnDocumentClick:!1,closeOnEscape:!1,modal:!0,open:t},n),lv.createElement($se,null))};Zse.propTypes={open:Mv.bool,children:Mv.node},Zse.defaultProps={open:!1,children:null};var Jse="default",eue=(Y4(Hse={},Jse,{fill:"none",strokeWidth:2,stroke:"#f4f4f4",strokeDasharray:"7, 4",opacity:.6}),Y4(Hse,"error",{fill:"rgba(234,50,35, 0.1)",strokeWidth:2,stroke:"#ea3223"}),Hse),tue={fill:"rgba(0,0,0, 0.6)"};function nue(e){var t=e.className,n=e.width,r=e.height,a=e.type,o=eue[a];return lv.createElement("svg",{width:n,height:r,className:t},lv.createElement("rect",{x:2,y:2,rx:10,ry:10,width:n-4,height:r-4,style:o}),lv.createElement("path",{d:"M0,".concat(12," Q0,0 ").concat(12,",0 L0,0 Z"),style:tue}),lv.createElement("path",{d:"M0,".concat(r-12," Q0,").concat(r," ").concat(12,",").concat(r," L0,").concat(r," Z"),style:tue}),lv.createElement("path",{d:"M".concat(n-12,",").concat(r," Q").concat(n,",").concat(r," ").concat(n,",").concat(r-12," L").concat(n,",").concat(r," Z"),style:tue}),lv.createElement("path",{d:"M".concat(n-12,",0 Q").concat(n,",0 ").concat(n,",").concat(12," L").concat(n,",0 Z"),style:tue}))}nue.propTypes={className:Mv.string,width:Mv.number,height:Mv.number,type:Mv.oneOf([Jse,"error"])},nue.defaultProps={className:"",width:300,height:200,type:Jse};var rue,aue,oue,iue,sue,uue,cue,lue,pue,due,fue,hue,mue,gue,vue,yue,bue,xue,wue,kue,Sue,Eue,Iue,Cue,Tue=PQ([".flipY-exit{animation-name:",";animation-duration:","ms;animation-timing-function:ease-in;}.flipY-enter{animation-name:",";animation-duration:","ms;animation-timing-function:ease-out;}"],JQ(["from{transform:perspective(400px);}to{transform:perspective(400px) rotateY(90deg);}"]),500,JQ(["from{transform:perspective(400px) rotateY(-90deg);}to{transform:perspective(400px);}"]),500),_ue=Object.freeze({__proto__:null,animationDuration:500,default:Tue}),Nue=PQ([".slide-horizontal{animation-name:",";animation-iteration-count:infinite;animation-duration:2000ms;animation-timing-function:linear;}.slide-vertical{animation-name:",";animation-iteration-count:infinite;animation-duration:2000ms;animation-timing-function:linear;}"],JQ(["from,to{transform:translate3d(-","px,0,0);}50%{transform:translate3d(","px,0,0);}"],20,20),JQ(["from,to{transform:translate3d(0,-","px,0);}50%{transform:translate3d(0,","px,0);}"],20,20)),Aue=Object.freeze({__proto__:null,default:Nue}),Rue=PQ([".blink{animation-name:",";animation-iteration-count:infinite;animation-duration:2000ms;animation-timing-function:linear;}"],JQ(["from,to{opacity:1;}50%{opacity:0;}"])),Oue=Object.freeze({__proto__:null,default:Rue}),Bue=$Q.div(rue||(rue=e6(["\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: ","; // must be higher than BASE_Z_INDEX and lower than other layers\n"])),1001),Due=PQ([".splash-enter{animation-name:",";animation-duration:","ms;animation-timing-function:ease-in;}"],JQ(["from{background:#000;}to{}"]),300),Mue=$Q.div(aue||(aue=e6(["\n ","\n"])),Due),Fue=function(e){var t=e.keyForTransition,n=void 0===t?0:t;return lv.createElement(Mue,null,lv.createElement(nee,null,lv.createElement(Z9,{key:n,timeout:{enter:300,exit:0},classNames:"splash",unmountOnExit:!1},lv.createElement(Bue,null))))},Pue=Object.freeze({__proto__:null,default:Fue}),Lue=PQ([".spin{animation-name:",";animation-iteration-count:infinite;animation-duration:1000ms;animation-timing-function:linear;}"],JQ(["from{transform:rotate(0deg);}to{transform:rotate(360deg);}"])),Uue=Object.freeze({__proto__:null,default:Lue}),Vue=Object.freeze({__proto__:null,flipY:_ue,slide:Aue,blink:Oue,splash:Pue,spin:Uue}),zue=Fue,jue=$Q.div(oue||(oue=e6(["\n ","\n ","\n"])),Tue,Lue),Wue=$Q.img(iue||(iue=e6(["\n border-radius: 5px;\n opacity: 0.7;\n height: 38px;\n"]))),Hue=$Q.div(sue||(sue=e6(["\n cursor: pointer;\n text-align: center;\n width: ","px;\n\n img {\n width: 100%;\n }\n\n z-index: ",";\n position: fixed;\n bottom: ","px;\n"])),60,1020,10),Gue=$Q.div(uue||(uue=e6(["\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n position: absolute;\n margin: auto;\n width: ","px;\n height: ","px;\n img {\n width: 100%;\n }\n"])),100,100),Kue=$Q.div(cue||(cue=e6(["\n color: #fff;\n text-align: center;\n"]))),que=$Q.div(lue||(lue=e6(["\n transform: translateZ(1000px); // to fix rotating bug on safari\n transform-style: preserve-3d;\n position: absolute;\n top: ",";\n z-index: ",";\n"])),(function(e){return e.y}),1020),Que=$Q.div(pue||(pue=e6(["\n display: flex;\n align-items: center;\n"]))),Xue=$Q(Kue)(due||(due=e6(["\n font-size: 20px;\n margin-left: 10px;\n color: #fff;\n"]))),Yue=$Q(Kue)(fue||(fue=e6(["\n font-size: 20px;\n margin-left: 10px;\n color: green;\n position: absolute;\n left: 0;\n top: 10px;\n background: white;\n z-index: ",";\n"])),1030),$ue=$Q(Kue)(hue||(hue=e6(["\n position: absolute;\n font-size: 16px;\n text-align: center;\n color: #fff;\n top: ",";\n z-index: ",";\n"])),(function(e){return e.y}),1020),Zue=$Q($ue)(mue||(mue=e6(["\n background: #ea3223;\n padding: 5px 10px;\n border-radius: 3px;\n"]))),Jue=$Q(Kue)(gue||(gue=e6(["\n position: absolute;\n font-size: 18px;\n text-align: center;\n border-radius: 3px;\n padding: 5px 10px;\n background: #ea3223;\n color: #fff;\n margin: 0 10px;\n top: ",";\n z-index: ",";\n"])),(function(e){return e.y}),1020),ece=$Q.div(vue||(vue=e6(["\n font-size: 18px;\n text-align: center;\n padding: 10px;\n"]))),tce=$Q(nue)(yue||(yue=e6(["\n position: absolute;\n top: 0;\n left: 0;\n"]))),nce={BTN_OK:{en:"OK",vi:"Tôi đã hiểu"},FRONT:{en:"front",vi:"trước"},BACK:{en:"back",vi:"sau"},BTN_USE_THIS_PICTURE:{en:"Use this picture",vi:"Dùng ảnh này"},BTN_TRY_AGAIN:{en:"Try again",vi:"Thử lại"}},rce={WARMUP_INTRO:{en:"Warming up... Please wait a moment",vi:"Đang khởi động, vui lòng chờ trong giây lát..."}},ace=Lv.IDCardMessage,oce=$Q.div(bue||(bue=e6(["\n display: flex;\n justify-content: center;\n align-items: center;\n flex-direction: column;\n padding: 10px;\n"]))),ice=$Q.div(xue||(xue=e6(["\n text-align: center;\n font-size: 1rem;\n"]))),sce=$Q.button(wue||(wue=e6(["\n margin-top: 20px;\n width: 100%;\n max-width: 160px;\n height: 50px;\n background-color: #007bff;\n border: 0;\n outline: none;\n border-radius: 0.25rem;\n color: #fff;\n font-weight: 400;\n cursor: pointer;\n font-size: 1rem;\n"]))),uce=function(e){var t=e.onOk,n=e.maxSessionTime,r=jv.useSDKSettings().lang;return lv.createElement(oce,null,lv.createElement(ice,{className:"popup-message"},t7(ace.TIMEOUT_INSTRUCTION[r])({x:n})),lv.createElement(sce,{className:"popup-button",onClick:t},nce.BTN_OK[r]))};uce.propTypes={onOk:Mv.func,maxSessionTime:Mv.number},uce.defaultProps={onOk:function(){},maxSessionTime:30};var cce=$Q.div(kue||(kue=e6(["\n display: flex;\n justify-content: center;\n align-items: center;\n flex-direction: column;\n padding: 10px;\n"]))),lce=$Q.div(Sue||(Sue=e6(["\n text-align: center;\n font-size: 1rem;\n color: #ea3223;\n margin-top: 10px;\n"]))),pce=$Q.button(Eue||(Eue=e6(["\n margin-top: 20px;\n width: 100%;\n max-width: 160px;\n height: 50px;\n background-color: #007bff;\n border: 0;\n outline: none;\n border-radius: 0.25rem;\n color: #fff;\n font-weight: 400;\n cursor: pointer;\n font-size: 1rem;\n"]))),dce=$Q.img(Iue||(Iue=e6(["\n width: 100%;\n border-radius: 5px;\n"]))),fce=$Q.div(Cue||(Cue=e6(["\n margin: 20px 0;\n width: 100%;\n display: flex;\n justify-content: space-evenly;\n gap: 10px;\n"]))),hce=function(e){var t=e.imageBlobTaken,n=e.onConfirm,r=e.onTryAgain,a=e.error,o=t6(lv.useState(null),2),i=o[0],s=o[1],u=jv.useSDKSettings().lang;return lv.useEffect((function(){var e;return t&&(e=URL.createObjectURL(t),s(e)),function(){URL.revokeObjectURL(e)}}),[t]),lv.createElement(cce,null,lv.createElement(dce,{src:i}),a&&lv.createElement(lce,{className:"confirm-popup-error-message"},a.msg[u]),lv.createElement(fce,null,lv.createElement(pce,{onClick:n},nce.BTN_USE_THIS_PICTURE[u]),lv.createElement(pce,{onClick:r},nce.BTN_TRY_AGAIN[u])))};hce.propTypes={imageBlobTaken:Mv.shape({}),error:Mv.shape({msg:Mv.shape({})}),onConfirm:Mv.func,onTryAgain:Mv.func},hce.defaultProps={imageBlobTaken:{},error:null,onConfirm:function(){},onTryAgain:function(){}};function mce(e){var t=this.__data__=new d7(e);this.size=t.size}mce.prototype.clear=function(){this.__data__=new d7,this.size=0},mce.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},mce.prototype.get=function(e){return this.__data__.get(e)},mce.prototype.has=function(e){return this.__data__.has(e)},mce.prototype.set=function(e,t){var n=this.__data__;if(n instanceof d7){var r=n.__data__;if(!f7||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new g7(r)}return n.set(e,t),this.size=n.size,this};var gce=mce,vce=function(e,t,n){(void 0!==n&&!F5(e[t],n)||void 0===n&&!(t in e))&&M5(e,t,n)},yce=function(e,t,n){for(var r=-1,a=Object(e),o=n(e),i=o.length;i--;){var s=o[++r];if(!1===t(a[s],s,a))break}return e},bce=i6((function(e,t){var n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,a=r&&r.exports===n?e5.Buffer:void 0,o=a?a.allocUnsafe:void 0;e.exports=function(e,t){if(t)return e.slice();var n=e.length,r=o?o(n):new e.constructor(n);return e.copy(r),r}})),xce=e5.Uint8Array,wce=function(e,t){var n=t?function(e){var t=new e.constructor(e.byteLength);return new xce(t).set(new xce(e)),t}(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)},kce=Object.create,Sce=function(){function e(){}return function(t){if(!$6(t))return{};if(kce)return kce(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}(),Ece=function(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]},Ice=function(e,t,n,r,a,o,i){var s=Ece(e,n),u=Ece(t,n),c=i.get(u);if(c)vce(e,n,c);else{var l=o?o(s,u,n+"",e,t,i):void 0,p=void 0===l;if(p){var d=o8(u),f=!d&&s8(u),h=!d&&!f&&p8(u);l=u,d||f||h?o8(s)?l=s:function(e){return l5(e)&&X5(e)}(s)?l=function(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}(s):f?(p=!1,l=bce(u,!0)):h?(p=!1,l=wce(u,!0)):l=[]:T8(u)||a8(u)?(l=s,a8(s)?l=function(e){return U5(e,y8(e))}(s):$6(s)&&!k5(s)||(l=function(e){return"function"!=typeof e.constructor||m8(e)?{}:Sce(w8(e))}(u))):p=!1}p&&(i.set(u,l),a(l,u,r,o,i),i.delete(u)),vce(e,n,l)}},Cce=function e(t,n,r,a,o){t!==n&&yce(n,(function(i,s){if(o||(o=new gce),$6(i))Ice(t,n,s,r,e,a,o);else{var u=a?a(Ece(t,s),i,s+"",t,n,o):void 0;void 0===u&&(u=i),vce(t,s,u)}}),y8)},Tce=J5((function(e,t,n){Cce(e,t,n)})),_ce={data:{settings:{sdk_settings:{id_detection_settings:{auto_capture:{enable:!0,show_capture_button:!0,wait_for_best_image_time_ms:3e3},blur_check:{enable:!0,threshold:.82},disable_capture_button_if_alert:!0,id_detection:{enable:!0},limit_time_settings:{enable:!0,limit_time_second:30,video_partial_length_seconds:15},save_frame_settings:{enable:!1,frames_interval_ms:190,quality_web:80},scan_qr_settings:{enable:!0,limit_time_second:20}}}}}},Nce="SESSION_TIMEOUT",Ace=Lv.IDCardMessage,Rce=Lv.IDCardSide,Oce=Lv.IDCardType,Bce=Lv.Errors;function Dce(e){var t=e.frontCamera,n=e.title,r=e.description,a=e.onClose,o=e.usePortraitMask,i=e.onError,s=e.cardType,u=e.cardSide,c=e.apiCheck,l=e.onSuccess,p=e.frontCardId,d=e.onApiCheck,f=e.enableConfirmPopup,h=e.clientSettings,m=e.WorkingCanvasFrame,g=t6(lv.useState(0),2),v=g[0],y=g[1],b=u===Rce.FRONT,x=e.titleIcon||(b?"id_card_front.svg":"id_card_back.svg"),w=Gv.useAsset(x),k=t6(lv.useState({}),2),S=k[0],E=k[1],I=S.yTitle,C=S.yDescription,T=S.yMessage,_=Gv.useAsset("ic_camera.svg"),N=t6(lv.useState(""),2),A=N[0],R=N[1],O=jv.useSDKSettings(),B=O.apiClient,D=O.debug,M=O.lang,F=O.enableAntiDebug,P=lv.useRef(null),L=t6(lv.useState(null),2),U=L[0],V=L[1],z=t6(lv.useState(""),2),j=z[0],W=z[1],H=t6(lv.useState(!1),2),G=H[0],K=H[1],q=t6(lv.useState(null),2),Q=q[0],X=q[1],Y=t6(lv.useState(!1),2),$=Y[0],Z=Y[1],J=function(){var e=t6(lv.useState(!1),2),t=e[0],n=e[1],r=t6(lv.useState(null),2),a=r[0],o=r[1];return{showPopup:lv.useCallback((function(e){var t=e.popupType;o(t),n(null!==t)}),[]),popupShown:t,popupType:a}}(),ee=J.showPopup,te=J.popupShown,ne=J.popupType,re=lv.useRef(null),ae=lv.useRef((function(){})),oe=t6(lv.useState(null),2),ie=oe[0],se=oe[1],ue=lv.useRef(!1),ce=function(e){var t=e.apiCheck,n=e.clientSettings,r=jv.useSDKSettings().apiClient,a=t6(lv.useState(null),2),o=a[0],i=a[1];return lv.useEffect((function(){function e(){return(e=X4(regeneratorRuntime.mark((function e(){var a,o,s,u,c,l,p,d,f,h,m,g,v,y;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a={},!t){e.next=5;break}return e.next=4,r.clientSettings();case 4:a=e.sent;case 5:o=Tce(_ce,n,a),s=E7(o,"data.settings.sdk_settings.id_detection_settings.save_frame_settings.enable"),u=E7(o,"data.settings.sdk_settings.id_detection_settings.save_frame_settings.frames_interval_ms"),c=E7(o,"data.settings.sdk_settings.id_detection_settings.save_frame_settings.quality_web"),l=E7(o,"data.settings.sdk_settings.id_detection_settings.limit_time_settings.enable"),p=E7(o,"data.settings.sdk_settings.id_detection_settings.limit_time_settings.limit_time_second"),d=E7(o,"data.settings.sdk_settings.id_detection_settings.limit_time_settings.video_partial_length_seconds"),f=E7(o,"data.settings.sdk_settings.id_detection_settings.auto_capture.enable"),h=E7(o,"data.settings.sdk_settings.id_detection_settings.auto_capture.wait_for_best_image_time_ms"),m=E7(o,"data.settings.sdk_settings.id_detection_settings.blur_check.enable"),g=E7(o,"data.settings.sdk_settings.id_detection_settings.blur_check.threshold"),v=E7(o,"data.settings.sdk_settings.id_detection_settings.disable_capture_button_if_alert"),y=E7(o,"data.settings.sdk_settings.id_detection_settings.id_detection.enable"),i({enableRecording:s,frameCaptureIntervalMs:u,sessionTime:p,maxRecordingTimePerVideo:d,saveFrameQuality:c,enableTimers:l,enableAutoCapture:f,waitForBestImageTimeMs:h,enableBlurCheck:m,blurThreshold:g,disableCaptureButtonIfAlert:v,enableIdDetection:y});case 19:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[r,t,n]),{settings:o}}({apiCheck:c,clientSettings:h}).settings;lv.useEffect((function(){F&&NK.enableAntiDebug()}),[F]);var le=lv.useCallback((function(e){W(null===e?"":t7(e.msg[M])({side:b?nce.FRONT[M]:nce.BACK[M]}))}),[M,b]),pe=lv.useCallback(function(){var e=X4(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ae.current({imageBlobTaken:t.imageBlob});case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[]),de=function(e){var t=e.refVideo,n=e.videoPlayed,r=e.cropArea,a=e.settings,o=e.onError,i=e.frontSide,s=e.onAutoCaptureSuccess,u=lv.useRef(null),c=lv.useRef(!1),l=lv.useRef(null),p=t6(lv.useState(!1),2),d=p[0],f=p[1],h=lv.useRef({imageBlob:null,takenAt:null,blurScore:null}),m=lv.useRef({imageBlob:null,blurScore:null,error:null}),g=lv.useRef(!1),v=lv.useRef(!1),y=lv.useRef(null),b=lv.useRef(!1),x=lv.useRef({}),w=jv.useSDKSettings(),k=w.tfjsWasmRoot,S=w.blazefaceRoot,E=w.opencvUrl,I=w.idCardModelUrl;lv.useEffect((function(){function e(){return(e=X4(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!a||d){e.next=10;break}if(!a.enableIdDetection){e.next=8;break}return e.next=4,Vse({opencvUrl:E,modelUrl:I,blazefaceRoot:S,tfjsWasmRoot:k});case 4:x.current=e.sent,y.current=a.enableBlurCheck&&x.current.ableToUseModel,e.next=9;break;case 8:y.current=!1;case 9:f(!0);case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[d,a,k,S,E,I]);var C=lv.useCallback((function(){!0===c.current&&(c.current=!1)}),[]),T=lv.useCallback(function(){var e=X4(regeneratorRuntime.mark((function e(t){var n,r,o,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.blurScore,r=a.blurThreshold,o=h.current,i=m.current,!(n<r&&Ty.hasBetterCardBlurScore(n,o.blurScore))){e.next=14;break}if(!b.current){e.next=9;break}o.imageBlob=i.imageBlob,e.next=12;break;case 9:return e.next=11,Ny.takePicture({canvas:u.current});case 11:o.imageBlob=e.sent;case 12:o.takenAt=(new Date).getTime(),o.blurScore=n;case 14:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[a]),_=lv.useCallback(function(){var e=X4(regeneratorRuntime.mark((function e(t){var n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.blurScore,v.current=!0,r=m.current,!Ty.hasBetterCardBlurScore(n,r.blurScore)){e.next=9;break}return e.next=6,Ny.takePicture({canvas:u.current});case 6:r.imageBlob=e.sent,r.blurScore=n,b.current=!0;case 9:v.current=!1;case 10:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[]),N=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var t,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=a.waitForBestImageTimeMs,null===(n=h.current).imageBlob){e.next=8;break}if(!((new Date).getTime()-n.takenAt>t)){e.next=8;break}return e.next=7,s(n);case 7:C();case 8:case"end":return e.stop()}}),e)}))),[s,a,C]),A=lv.useCallback((function(){g.current=!0}),[]),R=lv.useCallback((function(){return new Promise((function(e){g.current=!1;var t=setInterval((function(){v.current||(clearInterval(t),e())}),150)}))}),[]),O=lv.useCallback(X4(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){var t=a.blurThreshold,n=m.current;y.current?(A(),setTimeout((function(){R().then((function(){Ty.hasBetterCardBlurScore(n.blurScore,t)||(n.error=zse.id_detector_error_blur),e(n)}))}),3e3)):Ny.takePicture({canvas:u.current}).then((function(t){n.imageBlob=t,e(n)}))})));case 1:case"end":return e.stop()}}),e)}))),[a,A,R]),B=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var n,r,s,p,f,v,y,w,k,S,E,I,C,A,R,O,B,D,M,F,P,L,U;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a&&d){e.next=2;break}return e.abrupt("return");case 2:h.current={imageBlob:null,takenAt:null,blurScore:null},m.current={imageBlob:null,blurScore:null,error:null},n=a.enableAutoCapture,r=a.enableBlurCheck,s=a.enableIdDetection,p=x.current,f=p.idCardModel,v=p.blazefaceModel,y=p.ableToUseModel,w=l.current,k=t.current,c.current=!0,S=u.current,E=S.getContext("2d"),I=w.cropX,C=w.cropY,A=w.cropWidth,R=w.cropHeight,O=document.createElement("canvas"),B=O.getContext("2d"),D=s&&y?15:700;case 15:if(E.drawImage(k,I,C,A,R,0,0,A,R),b.current=!1,!s||!y){e.next=72;break}return M=null,e.next=22,f.predict(S,{detectThreshold:.3});case 22:if(!(F=e.sent).card){e.next=68;break}if(!xee({corners:F.card.corners,width:A,height:R})){e.next=65;break}if(!See(F.card.corners)){e.next=62;break}if(P=bee(S,F.card.corners),!((L=Fy.rectAreaRatio({small:{area:P.width*P.height},big:{area:A*R}}))<.5)){e.next=34;break}M=zse.id_detector_card_too_small,e.next=60;break;case 34:if(!(L>.9)){e.next=38;break}M=zse.id_detector_error_incomplete,e.next=60;break;case 38:return O.width=P.width,O.height=P.height,B.putImageData(P,0,0),e.next=43,wee({canvas:O});case 43:if(!e.sent){e.next=48;break}M=zse.glare_detected,e.next=60;break;case 48:return e.next=50,Eee({blazefaceModel:v,predictedIdCardCanvas:O,frontSide:i});case 50:if(M=e.sent){e.next=60;break}if(!r){e.next=60;break}if(U=Ty.calculateIdCardBlurScore({canvas:O}),!g.current){e.next=57;break}return e.next=57,_({blurScore:U});case 57:if(!n){e.next=60;break}return e.next=60,T({blurScore:U});case 60:e.next=63;break;case 62:M=zse.id_detector_validate_angle_error;case 63:e.next=66;break;case 65:M=zse.id_detector_error_incomplete;case 66:e.next=69;break;case 68:M=zse.id_detector_no_cards;case 69:return o(M),e.next=72,N();case 72:if(c.current){e.next=74;break}return e.abrupt("break",78);case 74:return e.next=76,qv.sleep(D);case 76:e.next=15;break;case 78:case"end":return e.stop()}}),e)}))),[t,a,d,i,o,T,_,N]);lv.useEffect((function(){var e=t.current;function a(){return(a=X4(regeneratorRuntime.mark((function t(){var n,a,o,i;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=Ny.analyzeVideoAndWindowSizes(e,r,.05),a=n.cropWidth,o=n.cropHeight,l.current=n,(i=document.createElement("canvas")).width=a,i.height=o,u.current=i,t.next=9,B();case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}n&&r&&d&&function(){a.apply(this,arguments)}()}),[n,r,t,C,B,d]);var D=lv.useCallback((function(){C()}),[C]);return lv.useEffect((function(){return D}),[D]),{refWorkingCanvas:u,stopCheckFrame:C,checkFrame:B,warmupDone:d,takePictureManually:O,refAbleToRunBurstMode:y}}({refVideo:P,videoPlayed:G,cropArea:Q,settings:ce,onError:le,frontSide:b,onAutoCaptureSuccess:pe}),fe=de.refWorkingCanvas,he=de.stopCheckFrame,me=de.checkFrame,ge=de.warmupDone,ve=de.takePictureManually,ye=de.refAbleToRunBurstMode,be=function(e){var t=e.refVideo,n=e.videoPlayed,r=e.cropArea,a=e.settings,o=lv.useRef(null),i=lv.useRef(!1),s=lv.useRef([{id:null,frames:[]}]),u=lv.useRef(Xb.createResizer({width:960,height:640})),c=lv.useRef(null),l=lv.useCallback((function(){!0===i.current&&(i.current=!1)}),[]),p=lv.useCallback((function(){s.current=[{id:null,frames:[]}]}),[]),d=lv.useCallback((function(){var e=s.current;e[e.length-1].frames.length>0&&e.push({id:null,frames:[]})}),[]),f=lv.useCallback(function(){var e=X4(regeneratorRuntime.mark((function e(t){var n,r,o,i,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=t.workingCanvas,r=u.current,o=s.current,i=r.resize({srcCanvas:n}),c=i.toDataURL("image/jpeg",a.saveFrameQuality/100).split(",")[1],o[o.length-1].frames.push({base64:c});case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[a]),h=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var n,r,s,u,l,p,d,h,m,g,v;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a){e.next=2;break}return e.abrupt("return");case 2:if(n=a.frameCaptureIntervalMs,a.enableRecording){e.next=5;break}return e.abrupt("return");case 5:r=c.current,s=t.current,i.current=!0,u=o.current,l=u.getContext("2d"),p=r.cropX,d=r.cropY,h=r.cropWidth,m=r.cropHeight,g=null;case 12:if(l.drawImage(s,p,d,h,m,0,0,h,m),!n){e.next=23;break}if(!((v=(new Date).getTime())-g>=n)){e.next=21;break}return e.next=20,f({workingCanvas:u});case 20:g=v;case 21:e.next=25;break;case 23:return e.next=25,f({workingCanvas:u});case 25:if(i.current){e.next=27;break}return e.abrupt("break",31);case 27:return e.next=29,qv.sleep(15);case 29:e.next=12;break;case 31:case"end":return e.stop()}}),e)}))),[t,f,a]);return lv.useEffect((function(){var e=t.current;function a(){return(a=X4(regeneratorRuntime.mark((function t(){var n,a,i,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=Ny.analyzeVideoAndWindowSizes(e,r),a=n.cropWidth,i=n.cropHeight,c.current=n,(s=document.createElement("canvas")).width=a,s.height=i,o.current=s,t.next=9,h();case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}return n&&r&&function(){a.apply(this,arguments)}(),function(){l()}}),[n,r,t,l,d,h]),{refWorkingCanvas:o,stopCheckFrame:l,refRecordedVideos:s,splitVideos:d,resetRecordedVideos:p,checkFrame:h}}({refVideo:P,videoPlayed:G,cropArea:Q,settings:ce}),xe=be.stopCheckFrame,we=be.refRecordedVideos,ke=be.splitVideos,Se=be.resetRecordedVideos,Ee=be.checkFrame;!function(e){var t=e.debug,n=e.refRecordedVideos,r=e.refWorkingCanvas,a=e.refVideo,o=e.onChange;lv.useEffect((function(){var e;return t&&(e=setInterval((function(){var e=a.current,t=n.current,i=r.current,s=t[t.length-1],u={videoWidth:e.videoWidth,videoHeight:e.videoHeight,framesCount:s.frames.length,"window.innerWidth":window.innerWidth,"window.innerHeight":window.innerHeight,"canvas.width":null==i?void 0:i.width,"canvas.height":null==i?void 0:i.height};o(JSON.stringify(u,null,2))}),1e3)),function(){return clearInterval(e)}}),[o,t,n,r,a])}({debug:D,refRecordedVideos:we,refWorkingCanvas:fe,refVideo:P,onChange:R});var Ie=Gv.useAsset("ic_loading.png"),Ce=lv.useCallback((function(){xe(),he(),Se(),V(""),ee({popupType:Nce})}),[Se,xe,he,ee]),Te=lv.useCallback((function(){ke()}),[ke]),_e=lv.useCallback((function(e){var t=e.curTimeLeft;V(t7(Ace.REMAINING_TIME[M])({x:t}))}),[M]),Ne=function(e){var t=e.videoPlayed,n=e.lang,r=e.onAboutToTimeout,a=e.onSessionTimeout,o=e.onVideoTimeLimitReached,i=e.settings,s=e.warmupDone,u=lv.useRef(),c=t6(lv.useState(0),2),l=c[0],p=c[1],d=lv.useCallback((function(){clearInterval(u.current)}),[]),f=lv.useCallback((function(){p((function(e){return e+1}))}),[]);return lv.useEffect((function(){if(s&&t&&null!=i&&i.enableTimers){var e=i.sessionTime,n=i.maxRecordingTimePerVideo,c=0,l=e/3;u.current=setInterval((function(){var t=e-(c+=1);t<=l&&r({curTimeLeft:t}),c>0&&c%n==0&&o(),0===t&&(d(),a())}),1e3)}return function(){d()}}),[t,n,r,d,a,o,l,i,s]),{stopTimers:d,startTimers:f}}({videoPlayed:G,lang:M,onAboutToTimeout:_e,apiClient:B,apiCheck:c,onSessionTimeout:Ce,onVideoTimeLimitReached:Te,settings:ce,warmupDone:ge}),Ae=Ne.stopTimers,Re=Ne.startTimers,Oe=lv.useCallback(X4(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return ee({popupType:null}),se(null),ue.current=!1,Re(),e.next=6,Promise.all([Ee(),me()]);case 6:case"end":return e.stop()}}),e)}))),[Ee,me,Re,ee]),Be=lv.useCallback((function(e){var t,n,r,a,i,s,u=e.videoAreaWidth,c=e.videoAreaHeight,l=e.lostX,p=e.lostY,d=e.clientHeight;o?(a=.7*(i=c-165),n=(s=(t=p+10)+45)+i+10,r=s+20):(a=b6.isMobile?u-6:Math.floor(.7*u),n=(s=(t=p+10)+50)+(i=Math.floor(Math.min(a/1.5,d-2*p-80-100)))+10,r=s+20);var f=Math.floor((u-a)/2)+l;X({x:f,y:s,width:a,height:i,surroundStyle:{opacity:.6,background:"#000"}}),E({yTitle:t,yDescription:n,yMessage:r}),K(!0)}),[o]),De=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var t,n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Z(!0),ee({popupType:null}),t=re.current,n={image:t,recordedVideos:null!=ce&&ce.enableRecording?we.current:[]},!c){e.next=19;break}return r=null,e.prev=6,d(),e.next=10,fee({image:t,cardSide:u,frontCardId:p,onError:i,apiClient:B,cardType:s,recordedVideos:we.current});case 10:r=e.sent,e.next=16;break;case 13:e.prev=13,e.t0=e.catch(6),i(J4(J4({},Bce.api_call_error),{},{details:e.t0}));case 16:r&&l(J4(J4({},n),{},{apiResult:r})),e.next=20;break;case 19:l(n);case 20:Z(!1);case 21:case"end":return e.stop()}}),e,null,[[6,13]])}))),[c,B,ce,s,u,p,i,l,d,we,ee]),Me=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var t,n,r=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.length>0&&void 0!==r[0]?r[0]:{},n=t.imageBlobTaken,!ue.current){e.next=3;break}return e.abrupt("return");case 3:ue.current=!0,Z(!0),xe(),he(),Ae(),V(""),W(""),y((function(e){return e+1})),re.current=n,f?ee({popupType:"CONFIRM"}):De(),Z(!1);case 14:case"end":return e.stop()}}),e)}))),[xe,he,Ae,ee,f,De]);ae.current=Me;var Fe=lv.useCallback(X4(regeneratorRuntime.mark((function e(){var t,n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Z(!0),Ae(),V(""),xe(),ye.current||he(),e.next=7,ve();case 7:return t=e.sent,n=t.imageBlob,r=t.error,se(r),e.next=13,Me({imageBlobTaken:n});case 13:Z(!1);case 14:case"end":return e.stop()}}),e)}))),[ve,Me,Ae,ye,xe,he]);return lv.createElement(jue,null,lv.createElement(j6,{frontCamera:t,onVideoPlayed:Be,onClose:a,flipHorizontal:t,ref:P,onError:i},!ge&&lv.createElement(Zse,{open:!0},lv.createElement(ece,{className:"warmup-message"},rce.WARMUP_INTRO[M])),G?lv.createElement(lv.Fragment,null,D&&lv.createElement(Yue,null,A),lv.createElement(zue,{keyForTransition:v}),Q?lv.createElement(Q6,{x:"".concat(Q.x,"px"),y:"".concat(Q.y,"px"),width:"".concat(Q.width,"px"),height:"".concat(Q.height,"px"),surroundStyle:Q.surroundStyle},lv.createElement(m,{width:Q.width,height:Q.height,type:j?"error":Jse}),$&&lv.createElement(Gue,null,lv.createElement("img",{src:Ie,alt:"",className:"spin"}))):null,lv.createElement(que,{y:"".concat(I,"px")},lv.createElement(nee,null,lv.createElement(Z9,{key:n,timeout:{enter:500,exit:500},classNames:"flipY",unmountOnExit:!0},lv.createElement(Que,null,lv.createElement(Wue,{src:w,alt:""}),lv.createElement(Xue,{className:"title"},n))))),!j&&lv.createElement($ue,{y:"".concat(C,"px"),className:"description"},r),j&&lv.createElement(Zue,{y:"".concat(C,"px")},j),!$&&(!(null!=ce&&ce.disableCaptureButtonIfAlert)||!j)&&lv.createElement(Hue,{onClick:Fe},lv.createElement("img",{src:_,alt:""})),U&&lv.createElement(Jue,{key:U,className:"message",y:"".concat(T,"px")},U)):null),lv.createElement(Zse,{open:te},ne===Nce&&lv.createElement(uce,{onOk:Oe,maxSessionTime:null==ce?void 0:ce.sessionTime}),"CONFIRM"===ne&&lv.createElement(hce,{imageBlobTaken:re.current,error:ie,onConfirm:De,onTryAgain:Oe})))}Dce.propTypes={frontCamera:Mv.bool,usePortraitMask:Mv.bool,cardType:Mv.string,cardSide:Mv.string,title:Mv.string,titleIcon:Mv.string,description:Mv.string,onClose:Mv.func,apiCheck:Mv.bool,onSuccess:Mv.func,onError:Mv.func,frontCardId:Mv.string,onApiCheck:Mv.func,enableConfirmPopup:Mv.bool,clientSettings:Mv.shape({}),WorkingCanvasFrame:Mv.func},Dce.defaultProps={frontCamera:!0,usePortraitMask:!1,cardType:Oce.VN,cardSide:Rce.FRONT,title:"",titleIcon:null,description:"",onClose:function(){},apiCheck:!1,onSuccess:function(){},onError:function(){},frontCardId:null,onApiCheck:function(){},enableConfirmPopup:!0,clientSettings:{},WorkingCanvasFrame:tce};var Mce,Fce=Object.freeze({__proto__:null,Camera:X6}),Pce={LANDSCAPE:"landscape",PORTRAIT:"portrait",DESKTOP:"desktop"},Lce=function(){var e=lv.useRef(window.innerWidth>window.innerHeight?Pce.LANDSCAPE:Pce.PORTRAIT),t=t6(lv.useState(e.current),2),n=t[0],r=t[1];return lv.useEffect((function(){function e(){window.innerWidth>window.innerHeight?r(Pce.LANDSCAPE):r(Pce.PORTRAIT)}return window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]),b6.isMobile?{curOrientation:n,initOrientation:e.current}:{curOrientation:Pce.DESKTOP}},Uce=Lv.Errors,Vce=$Q.div(Mce||(Mce=e6(["\n text-align: center;\n font-size: 20px;\n font-weight: 600;\n"])));function zce(e){var t=$4({},e),n=jv.useSDKSettings().lang,r=Uce.wrong_orientation.msg[n],a=Lce().curOrientation;return lv.createElement(lv.Fragment,null,a===Pce.LANDSCAPE&&lv.createElement(Zse,{open:!0},lv.createElement(Vce,null,r)),(a===Pce.PORTRAIT||a===Pce.DESKTOP)&&lv.createElement(L9,t))}var jce=z7,Wce=function(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}(U9,["useLivenessDetection"]),Hce=function(e,t,n,r,a,o,i,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,a,o,i,s],l=0;(u=new Error(t.replace(/%s/g,(function(){return c[l++]})))).name="Invariant Violation"}throw u.framesToPop=1,u}},Gce=r(a((function(e,r){!function(e,t){t=t&&t.hasOwnProperty("default")?t.default:t;var r=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/read_id_card_info_sync",e,t)},e}(),a=function(){return(a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};
7139
7139
  /*! *****************************************************************************
7140
7140
  Copyright (c) Microsoft Corporation. All rights reserved.
7141
7141
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -7149,4 +7149,4 @@ function pse(e,t,n){var r=gg(gie("fusedOps",e,t,n),2),a=r[0],o=r[1],i="biasadd"=
7149
7149
 
7150
7150
  See the Apache Version 2.0 License for specific language governing permissions
7151
7151
  and limitations under the License.
7152
- ***************************************************************************** */function o(e,t,n,r){var a,o=arguments.length,i=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,n,i):a(t,n))||i);return o>3&&i&&Object.defineProperty(t,n,i),i}function i(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function u(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=(a=i.trys).length>0&&a[a.length-1])&&(6===o[0]||2===o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var c=function(){function e(e){this.httpClient=e}return e.prototype.uploadImage=function(e){return this.httpClient.postFormData("/v1/images",e)},e.prototype.request=function(e){var t="application/pdf"===e.file.type;return this.httpClient.postFormData(t?"/v1/files":"/v1/images",e)},e.prototype.requestWithHeaders=function(e,t){return this.httpClient.postFormData("/v1/images",e,t)},e.prototype.download=function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,this.httpClient.downloadFile("/v1/images/"+e)];case 1:return t=n.sent(),[4,URL.createObjectURL(t)];case 2:return[2,n.sent()]}}))}))},e.prototype.updateMetadata=function(e,t){return this.httpClient.patch("/v1/images/"+e,t)},e}(),l=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/files",e,t)},e.prototype.uploadFile=function(e){return this.httpClient.postFormData("/v1/files",e)},e.prototype.requestWithHeaders=function(e,t){return this.httpClient.postFormData("/v1/files",e,t)},e}(),p=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/compare_faces_sync",e,t)},e}(),d=function(){function e(e){this.httpClient=e}return e.prototype.getClientSettings=function(){return this.httpClient.get("/v1/client_settings")},e.prototype.request=function(){return this.httpClient.get("/v1/client_settings")},e}(),f=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/verify_face_liveness_sync",e,t)},e}(),h=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/verify_id_card_sanity_sync",e,t)},e}(),m=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/verify_portrait_sanity_sync",e,t)},e}(),g=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/detect_id_card_tampering_sync",e,t)},e.prototype.requestWithAuthHeaders=function(e,t){return this.httpClient.post("/v1/detect_id_card_tampering_sync",e,t)},e}(),v=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/search_faces_sync",e,t)},e.prototype.indexFaces=function(e,t){return this.httpClient.post("/v1/index_faces_sync",e,t)},e.prototype.deleteFaces=function(e,t){return this.httpClient.post("/v1/delete_faces",e,t)},e.prototype.downloadFaceImage=function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,this.httpClient.downloadFile("/v1/face_images/"+e)];case 1:return t=n.sent(),[2,URL.createObjectURL(t)]}}))}))},e}(),y=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.postFormData("/v1/convert_pdf_sync",e,t)},e}(),b=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/ekyc_pdf",e,t)},e}(),x="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==n?n:"undefined"!=typeof self?self:{};function w(e,t){return e(t={exports:{}},t.exports),t.exports}var k=w((function(e){var t,n;t=x,n=function(){function e(e){var t=[];if(0===e.length)return"";if("string"!=typeof e[0])throw new TypeError("Url must be a string. Received "+e[0]);if(e[0].match(/^[^/:]+:\/*$/)&&e.length>1){var n=e.shift();e[0]=n+e[0]}e[0].match(/^file:\/\/\//)?e[0]=e[0].replace(/^([^/:]+):\/*/,"$1:///"):e[0]=e[0].replace(/^([^/:]+):\/*/,"$1://");for(var r=0;r<e.length;r++){var a=e[r];if("string"!=typeof a)throw new TypeError("Url must be a string. Received "+a);""!==a&&(r>0&&(a=a.replace(/^[\/]+/,"")),a=r<e.length-1?a.replace(/[\/]+$/,""):a.replace(/[\/]+$/,"/"),t.push(a))}var o=t.join("/"),i=(o=o.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return i.shift()+(i.length>0?"?":"")+i.join("&")}return function(){return e("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},e.exports?e.exports=n():t.urljoin=n()}));function S(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var E=function(e,t,n,r){t=t||"&",n=n||"=";var a={};if("string"!=typeof e||0===e.length)return a;var o=/\+/g;e=e.split(t);var i=1e3;r&&"number"==typeof r.maxKeys&&(i=r.maxKeys);var s=e.length;i>0&&s>i&&(s=i);for(var u=0;u<s;++u){var c,l,p,d,f=e[u].replace(o,"%20"),h=f.indexOf(n);h>=0?(c=f.substr(0,h),l=f.substr(h+1)):(c=f,l=""),p=decodeURIComponent(c),d=decodeURIComponent(l),S(a,p)?Array.isArray(a[p])?a[p].push(d):a[p]=[a[p],d]:a[p]=d}return a},I=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},C=function(e,t,n,r){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map((function(r){var a=encodeURIComponent(I(r))+n;return Array.isArray(e[r])?e[r].map((function(e){return a+encodeURIComponent(I(e))})).join(t):a+encodeURIComponent(I(e[r]))})).join(t):r?encodeURIComponent(I(r))+n+encodeURIComponent(I(e)):""},T=w((function(e,t){t.decode=t.parse=E,t.encode=t.stringify=C})),_=(T.decode,T.parse,T.encode,T.stringify),N=function(){function e(e){this.authorizer=e.authorizer,this.domain=e.domain,this.onError=e.onError,this.configHeaders=e.headers}return e.prototype.get=function(e,t,n){var r=new URL(this.resolveUrl(e));return t&&(r.search=_(t)),this.request(r.toString(),{requestPath:e,method:"GET",headers:n})},e.prototype.post=function(e,t,n){var r=this.resolveUrl(e);return this.request(r,{requestPath:e,method:"POST",body:JSON.stringify(t),headers:a({"Content-Type":"application/json"},n)})},e.prototype.postFormData=function(e,t,n){var r,a=t instanceof FormData?t:(r=t,Object.entries(r).reduce((function(e,t){var n=t[0],r=t[1];return Array.isArray(r)?r.forEach((function(t,a){return e.append(n+"["+a+"]",r)})):!(r instanceof Object)||r instanceof File||r instanceof Date||r instanceof Blob?e.append(n,r):Object.entries(r).forEach((function(t,a){return e.append(n+"["+a+"]",r[a])})),e}),new FormData)),o=this.resolveUrl(e);return this.request(o,{requestPath:e,method:"POST",body:a,headers:n})},e.prototype.patch=function(e,t,n){var r=this.resolveUrl(e);return this.request(r,{requestPath:e,method:"PATCH",body:JSON.stringify(t),headers:a({"Content-Type":"application/json"},n)})},e.prototype.delete=function(e,t,n){var r=this.resolveUrl(e);return this.request(r,{requestPath:e,method:"DELETE",body:JSON.stringify(t),headers:a({"Content-Type":"application/json"},n)})},e.prototype.downloadFile=function(e){var t=this.resolveUrl(e);return this.request(t,{requestPath:e,method:"GET"},"blob")},e.prototype.request=function(e,t,n){return void 0===n&&(n="json"),s(this,void 0,void 0,(function(){var r,o,i,s;return u(this,(function(u){switch(u.label){case 0:return r={},o={},this.authorizer&&(r=this.authorizer.getHeaders(t)),this.configHeaders&&(o=this.configHeaders),t.headers=a(a(a({},t.headers),r),o),[4,fetch(e,t)];case 1:return i=u.sent(),[4,"blob"===n?i.blob():i.json()];case 2:if((s=u.sent()).errors&&this.onError)throw this.onError(s.errors),s;return[2,s]}}))}))},e.prototype.resolveUrl=function(e){return k(this.domain,e)},e}(),A=function(){function e(e){this.mocks=e}return e.prototype.get=function(e,t){return this.findInMocks(e,t)},e.prototype.post=function(e,t){return this.findInMocks(e)},e.prototype.postFormData=function(e,t){return this.findInMocks(e)},e.prototype.patch=function(e,t){return this.findInMocks(e)},e.prototype.delete=function(e,t){return this.findInMocks(e)},e.prototype.downloadFile=function(e){return this.findInMocks(e)},e.prototype.resolveUrl=function(e){return this.mocks.resolveUrl?this.mocks.resolveUrl(e):e},e.prototype.findInMocks=function(e,t){return s(this,void 0,void 0,(function(){return u(this,(function(n){return this.mocks[e]?"function"==typeof this.mocks[e]?[2,Promise.resolve(this.mocks[e](t))]:[2,Promise.resolve(this.mocks[e])]:[2,Promise.reject(new Error(e+" is not presented in mocks"))]}))}))},e}(),R=w((function(e,t){var n;e.exports=n=n||function(e,t){var n=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),r={},a=r.lib={},o=a.Base={extend:function(e){var t=n(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=a.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,a=e.sigBytes;if(this.clamp(),r%4)for(var o=0;o<a;o++){var i=n[o>>>2]>>>24-o%4*8&255;t[r+o>>>2]|=i<<24-(r+o)%4*8}else for(o=0;o<a;o+=4)t[r+o>>>2]=n[o>>>2];return this.sigBytes+=a,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n,r=[],a=function(t){t=t;var n=987654321,r=4294967295;return function(){var a=((n=36969*(65535&n)+(n>>16)&r)<<16)+(t=18e3*(65535&t)+(t>>16)&r)&r;return a/=4294967296,(a+=.5)*(e.random()>.5?1:-1)}},o=0;o<t;o+=4){var s=a(4294967296*(n||e.random()));n=987654071*s(),r.push(4294967296*s()|0)}return new i.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],a=0;a<n;a++){var o=t[a>>>2]>>>24-a%4*8&255;r.push((o>>>4).toString(16)),r.push((15&o).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new i.init(n,t/2)}},c=s.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],a=0;a<n;a++){var o=t[a>>>2]>>>24-a%4*8&255;r.push(String.fromCharCode(o))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new i.init(n,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=a.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,a=n.sigBytes,o=this.blockSize,s=a/(4*o),u=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*o,c=e.min(4*u,a);if(u){for(var l=0;l<u;l+=o)this._doProcessBlock(r,l);var p=r.splice(0,u);n.sigBytes-=c}return new i.init(p,c)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),d=(a.Hasher=p.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){p.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new d.HMAC.init(e,n).finalize(t)}}}),r.algo={});return r}(Math)})),O=w((function(e,t){var n,r,a;e.exports=(r=(n=a=R).lib.WordArray,n.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,r=this._map;e.clamp();for(var a=[],o=0;o<n;o+=3)for(var i=(t[o>>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;s<4&&o+.75*s<n;s++)a.push(r.charAt(i>>>6*(3-s)&63));var u=r.charAt(64);if(u)for(;a.length%4;)a.push(u);return a.join("")},parse:function(e){var t=e.length,n=this._map,a=this._reverseMap;if(!a){a=this._reverseMap=[];for(var o=0;o<n.length;o++)a[n.charCodeAt(o)]=o}var i=n.charAt(64);if(i){var s=e.indexOf(i);-1!==s&&(t=s)}return function(e,t,n){for(var a=[],o=0,i=0;i<t;i++)if(i%4){var s=n[e.charCodeAt(i-1)]<<i%4*2,u=n[e.charCodeAt(i)]>>>6-i%4*2;a[o>>>2]|=(s|u)<<24-o%4*8,o++}return r.create(a,o)}(e,t,a)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},a.enc.Base64)})),B=(w((function(e,t){var n;e.exports=(n=R,function(e){var t=n,r=t.lib,a=r.WordArray,o=r.Hasher,i=t.algo,s=[],u=[];!function(){function t(t){for(var n=e.sqrt(t),r=2;r<=n;r++)if(!(t%r))return!1;return!0}function n(e){return 4294967296*(e-(0|e))|0}for(var r=2,a=0;a<64;)t(r)&&(a<8&&(s[a]=n(e.pow(r,.5))),u[a]=n(e.pow(r,1/3)),a++),r++}();var c=[],l=i.SHA256=o.extend({_doReset:function(){this._hash=new a.init(s.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],a=n[1],o=n[2],i=n[3],s=n[4],l=n[5],p=n[6],d=n[7],f=0;f<64;f++){if(f<16)c[f]=0|e[t+f];else{var h=c[f-15],m=(h<<25|h>>>7)^(h<<14|h>>>18)^h>>>3,g=c[f-2],v=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;c[f]=m+c[f-7]+v+c[f-16]}var y=r&a^r&o^a&o,b=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),x=d+((s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25))+(s&l^~s&p)+u[f]+c[f];d=p,p=l,l=s,s=i+x|0,i=o,o=a,a=r,r=x+(b+y)|0}n[0]=n[0]+r|0,n[1]=n[1]+a|0,n[2]=n[2]+o|0,n[3]=n[3]+i|0,n[4]=n[4]+s|0,n[5]=n[5]+l|0,n[6]=n[6]+p|0,n[7]=n[7]+d|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,a=8*t.sigBytes;return n[a>>>5]|=128<<24-a%32,n[14+(a+64>>>9<<4)]=e.floor(r/4294967296),n[15+(a+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=o._createHelper(l),t.HmacSHA256=o._createHmacHelper(l)}(Math),n.SHA256)})),w((function(e,t){var n,r,a;e.exports=(r=(n=R).lib.Base,a=n.enc.Utf8,void(n.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,u=i.words,c=0;c<n;c++)s[c]^=1549556828,u[c]^=909522486;o.sigBytes=i.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,n=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(n))}})))})),w((function(e,t){e.exports=R.HmacSHA256}))),D=function(){function e(e,t){this.accessKey=e,this.keySecret=t}return e.prototype.getHeaders=function(e){var t=function(e){function t(e){return e<10?"0"+e:e}return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+"T"+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+(0===(n=e.getTimezoneOffset())?"Z":(r=n>0?"-":"+",n=Math.abs(n),r+t(Math.floor(n/60))+":"+t(n%60)));var n,r}(new Date);return{Authorization:this.generateAuthorization(e.requestPath,e.method,t),"X-TV-Timestamp":t}},e.prototype.generateAuthorization=function(e,t,n){var r=this.computeStringToSign(e,t,n),a=O.stringify(this.computeSignature(r));return this.formatAuthToken("TV",a)},e.prototype.formatAuthToken=function(e,t){return e+" "+this.accessKey+":"+t},e.prototype.computeStringToSign=function(e,t,n){return t+"\n"+e+"\n"+n},e.prototype.computeSignature=function(e){return B(e,this.keySecret)},e}();function M(e){switch(e){case"testing":return"https://tv-testing.trustingsocial.com/api";case"staging":return"https://tv-staging.trustingsocial.com/api";case"production":return"https://vn-vision.trustingsocial.com/api";default:return e}}function F(e,t,n,r){void 0===n&&(n="production");var a=(void 0===r?{}:r).headers,o=new D(e,t),i=M(n);return new N({authorizer:o,domain:i,headers:a})}var P=function(){function e(e){void 0===e&&(e="production");var t=new N({domain:M(e)});this.imagesService=new c(t),this.detectIDTamperingService=new g(t)}return e.prototype.uploadImage=function(e,t){return this.imagesService.requestWithHeaders(e,t)},e.prototype.detectTampering=function(e,t){return this.detectIDTamperingService.requestWithAuthHeaders(e,t)},e}();function L(e){var t=e.headerIndex;return function(e,n,r){var o=r.value,i=a({},r);return i.value=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return s(this,void 0,void 0,(function(){var n,r,i,s;return u(this,(function(u){switch(u.label){case 0:return this.transactionEnabled?[4,this.transactionManager.begin()]:[3,4];case 1:return n=u.sent(),r=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),a=0;for(t=0;t<n;t++)for(var o=arguments[t],i=0,s=o.length;i<s;i++,a++)r[a]=o[i];return r}(e),(i=a({},r[t]))["X-TV-Transaction"]=n,r[t]=i,[4,o.apply(this,r)];case 2:return s=u.sent(),[4,this.transactionManager.end()];case 3:return u.sent(),[2,s];case 4:return[4,o.apply(this,e)];case 5:return[2,u.sent()]}}))}))},i}}function U(e){return void 0===e&&(e={encryptedField:"data"}),function(t,n,r){var o=r.value,i=a({},r);return i.value=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return s(this,void 0,void 0,(function(){var n,r;return u(this,(function(a){switch(a.label){case 0:return[4,o.apply(this,t)];case 1:return n=a.sent(),this.encryptionEnabled&&"string"==typeof n[e.encryptedField]?(r=this.encryptionService.decrypt(n[e.encryptedField],{transactionID:this.transactionManager.currentTransactionID}),[2,JSON.parse(r)]):[2,n]}}))}))},i}}var V=function(){function e(e){this.httpClient=e,this.transactionID="",this.totalTransactions=0,this.currentTransaction=0}return Object.defineProperty(e.prototype,"currentTransactionID",{get:function(){return this.transactionID},enumerable:!0,configurable:!0}),e.prototype.begin=function(){return s(this,void 0,void 0,(function(){var e,t,n=this;return u(this,(function(r){switch(r.label){case 0:return e=this.totalTransactions++,[4,new Promise((function(t,r){var a=window.performance.now(),o=setInterval((function(){e===n.currentTransaction&&(clearInterval(o),t(!0)),window.performance.now()-a>=3e3&&(clearInterval(o),r(new Error("Transaction timeout")))}),100)}))];case 1:return r.sent(),[4,this.httpClient.post("/v1/transactions",{})];case 2:return t=r.sent().data,this.transactionID=t.id,[2,t.id]}}))}))},e.prototype.end=function(){return s(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return[4,this.httpClient.post("/v1/transactions/"+this.transactionID+"/finish")];case 1:return e=t.sent(),this.transactionID="",this.currentTransaction++,[2,e]}}))}))},e}(),z={options:{usePureJavaScript:!1}},j={},W=j,H={};j.encode=function(e,t,n){if("string"!=typeof t)throw new TypeError('"alphabet" must be a string.');if(void 0!==n&&"number"!=typeof n)throw new TypeError('"maxline" must be a number.');var r="";if(e instanceof Uint8Array){var a=0,o=t.length,i=t.charAt(0),s=[0];for(a=0;a<e.length;++a){for(var u=0,c=e[a];u<s.length;++u)c+=s[u]<<8,s[u]=c%o,c=c/o|0;for(;c>0;)s.push(c%o),c=c/o|0}for(a=0;0===e[a]&&a<e.length-1;++a)r+=i;for(a=s.length-1;a>=0;--a)r+=t[s[a]]}else r=function(e,t){var n=0,r=t.length,a=t.charAt(0),o=[0];for(n=0;n<e.length();++n){for(var i=0,s=e.at(n);i<o.length;++i)s+=o[i]<<8,o[i]=s%r,s=s/r|0;for(;s>0;)o.push(s%r),s=s/r|0}var u="";for(n=0;0===e.at(n)&&n<e.length()-1;++n)u+=a;for(n=o.length-1;n>=0;--n)u+=t[o[n]];return u}(e,t);if(n){var l=new RegExp(".{1,"+n+"}","g");r=r.match(l).join("\r\n")}return r},j.decode=function(e,t){if("string"!=typeof e)throw new TypeError('"input" must be a string.');if("string"!=typeof t)throw new TypeError('"alphabet" must be a string.');var n=H[t];if(!n){n=H[t]=[];for(var r=0;r<t.length;++r)n[t.charCodeAt(r)]=r}e=e.replace(/\s/g,"");var a=t.length,o=t.charAt(0),i=[0];for(r=0;r<e.length;r++){var s=n[e.charCodeAt(r)];if(void 0===s)return;for(var u=0,c=s;u<i.length;++u)c+=i[u]*a,i[u]=255&c,c>>=8;for(;c>0;)i.push(255&c),c>>=8}for(var l=0;e[l]===o&&l<e.length-1;++l)i.push(0);return"undefined"!=typeof Buffer?Buffer.from(i.reverse()):new Uint8Array(i.reverse())},w((function(e){var t=e.exports=z.util=z.util||{};function n(e){if(8!==e&&16!==e&&24!==e&&32!==e)throw new Error("Only 8, 16, 24, or 32 bits supported: "+e)}function r(e){if(this.data="",this.read=0,"string"==typeof e)this.data=e;else if(t.isArrayBuffer(e)||t.isArrayBufferView(e))if("undefined"!=typeof Buffer&&e instanceof Buffer)this.data=e.toString("binary");else{var n=new Uint8Array(e);try{this.data=String.fromCharCode.apply(null,n)}catch(e){for(var a=0;a<n.length;++a)this.putByte(n[a])}}else(e instanceof r||"object"==typeof e&&"string"==typeof e.data&&"number"==typeof e.read)&&(this.data=e.data,this.read=e.read);this._constructedStringLength=0}!function(){if("undefined"!=typeof process&&process.nextTick&&!process.browser)return t.nextTick=process.nextTick,void("function"==typeof setImmediate?t.setImmediate=setImmediate:t.setImmediate=t.nextTick);if("function"==typeof setImmediate)return t.setImmediate=function(){return setImmediate.apply(void 0,arguments)},void(t.nextTick=function(e){return setImmediate(e)});if(t.setImmediate=function(e){setTimeout(e,0)},"undefined"!=typeof window&&"function"==typeof window.postMessage){var e="forge.setImmediate",n=[];t.setImmediate=function(t){n.push(t),1===n.length&&window.postMessage(e,"*")},window.addEventListener("message",(function(t){if(t.source===window&&t.data===e){t.stopPropagation();var r=n.slice();n.length=0,r.forEach((function(e){e()}))}}),!0)}if("undefined"!=typeof MutationObserver){var r=Date.now(),a=!0,o=document.createElement("div");n=[],new MutationObserver((function(){var e=n.slice();n.length=0,e.forEach((function(e){e()}))})).observe(o,{attributes:!0});var i=t.setImmediate;t.setImmediate=function(e){Date.now()-r>15?(r=Date.now(),i(e)):(n.push(e),1===n.length&&o.setAttribute("a",a=!a))}}t.nextTick=t.setImmediate}(),t.isNodejs="undefined"!=typeof process&&process.versions&&process.versions.node,t.globalScope=t.isNodejs?x:"undefined"==typeof self?window:self,t.isArray=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isArrayBuffer=function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer},t.isArrayBufferView=function(e){return e&&t.isArrayBuffer(e.buffer)&&void 0!==e.byteLength},t.ByteBuffer=r,t.ByteStringBuffer=r,t.ByteStringBuffer.prototype._optimizeConstructedString=function(e){this._constructedStringLength+=e,this._constructedStringLength>4096&&(this.data.substr(0,1),this._constructedStringLength=0)},t.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read},t.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0},t.ByteStringBuffer.prototype.putByte=function(e){return this.putBytes(String.fromCharCode(e))},t.ByteStringBuffer.prototype.fillWithByte=function(e,t){e=String.fromCharCode(e);for(var n=this.data;t>0;)1&t&&(n+=e),(t>>>=1)>0&&(e+=e);return this.data=n,this._optimizeConstructedString(t),this},t.ByteStringBuffer.prototype.putBytes=function(e){return this.data+=e,this._optimizeConstructedString(e.length),this},t.ByteStringBuffer.prototype.putString=function(e){return this.putBytes(t.encodeUtf8(e))},t.ByteStringBuffer.prototype.putInt16=function(e){return this.putBytes(String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},t.ByteStringBuffer.prototype.putInt24=function(e){return this.putBytes(String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},t.ByteStringBuffer.prototype.putInt32=function(e){return this.putBytes(String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},t.ByteStringBuffer.prototype.putInt16Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255))},t.ByteStringBuffer.prototype.putInt24Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255))},t.ByteStringBuffer.prototype.putInt32Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>24&255))},t.ByteStringBuffer.prototype.putInt=function(e,t){n(t);var r="";do{t-=8,r+=String.fromCharCode(e>>t&255)}while(t>0);return this.putBytes(r)},t.ByteStringBuffer.prototype.putSignedInt=function(e,t){return e<0&&(e+=2<<t-1),this.putInt(e,t)},t.ByteStringBuffer.prototype.putBuffer=function(e){return this.putBytes(e.getBytes())},t.ByteStringBuffer.prototype.getByte=function(){return this.data.charCodeAt(this.read++)},t.ByteStringBuffer.prototype.getInt16=function(){var e=this.data.charCodeAt(this.read)<<8^this.data.charCodeAt(this.read+1);return this.read+=2,e},t.ByteStringBuffer.prototype.getInt24=function(){var e=this.data.charCodeAt(this.read)<<16^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2);return this.read+=3,e},t.ByteStringBuffer.prototype.getInt32=function(){var e=this.data.charCodeAt(this.read)<<24^this.data.charCodeAt(this.read+1)<<16^this.data.charCodeAt(this.read+2)<<8^this.data.charCodeAt(this.read+3);return this.read+=4,e},t.ByteStringBuffer.prototype.getInt16Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8;return this.read+=2,e},t.ByteStringBuffer.prototype.getInt24Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16;return this.read+=3,e},t.ByteStringBuffer.prototype.getInt32Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16^this.data.charCodeAt(this.read+3)<<24;return this.read+=4,e},t.ByteStringBuffer.prototype.getInt=function(e){n(e);var t=0;do{t=(t<<8)+this.data.charCodeAt(this.read++),e-=8}while(e>0);return t},t.ByteStringBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),n=2<<e-2;return t>=n&&(t-=n<<1),t},t.ByteStringBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t="":(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},t.ByteStringBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},t.ByteStringBuffer.prototype.at=function(e){return this.data.charCodeAt(this.read+e)},t.ByteStringBuffer.prototype.setAt=function(e,t){return this.data=this.data.substr(0,this.read+e)+String.fromCharCode(t)+this.data.substr(this.read+e+1),this},t.ByteStringBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},t.ByteStringBuffer.prototype.copy=function(){var e=t.createBuffer(this.data);return e.read=this.read,e},t.ByteStringBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},t.ByteStringBuffer.prototype.clear=function(){return this.data="",this.read=0,this},t.ByteStringBuffer.prototype.truncate=function(e){var t=Math.max(0,this.length()-e);return this.data=this.data.substr(this.read,t),this.read=0,this},t.ByteStringBuffer.prototype.toHex=function(){for(var e="",t=this.read;t<this.data.length;++t){var n=this.data.charCodeAt(t);n<16&&(e+="0"),e+=n.toString(16)}return e},t.ByteStringBuffer.prototype.toString=function(){return t.decodeUtf8(this.bytes())},t.DataBuffer=function(e,n){n=n||{},this.read=n.readOffset||0,this.growSize=n.growSize||1024;var r=t.isArrayBuffer(e),a=t.isArrayBufferView(e);if(r||a)return this.data=r?new DataView(e):new DataView(e.buffer,e.byteOffset,e.byteLength),void(this.write="writeOffset"in n?n.writeOffset:this.data.byteLength);this.data=new DataView(new ArrayBuffer(0)),this.write=0,null!=e&&this.putBytes(e),"writeOffset"in n&&(this.write=n.writeOffset)},t.DataBuffer.prototype.length=function(){return this.write-this.read},t.DataBuffer.prototype.isEmpty=function(){return this.length()<=0},t.DataBuffer.prototype.accommodate=function(e,t){if(this.length()>=e)return this;t=Math.max(t||this.growSize,e);var n=new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength),r=new Uint8Array(this.length()+t);return r.set(n),this.data=new DataView(r.buffer),this},t.DataBuffer.prototype.putByte=function(e){return this.accommodate(1),this.data.setUint8(this.write++,e),this},t.DataBuffer.prototype.fillWithByte=function(e,t){this.accommodate(t);for(var n=0;n<t;++n)this.data.setUint8(e);return this},t.DataBuffer.prototype.putBytes=function(e,n){if(t.isArrayBufferView(e)){var r=(a=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)).byteLength-a.byteOffset;return this.accommodate(r),new Uint8Array(this.data.buffer,this.write).set(a),this.write+=r,this}if(t.isArrayBuffer(e)){var a=new Uint8Array(e);return this.accommodate(a.byteLength),new Uint8Array(this.data.buffer).set(a,this.write),this.write+=a.byteLength,this}if(e instanceof t.DataBuffer||"object"==typeof e&&"number"==typeof e.read&&"number"==typeof e.write&&t.isArrayBufferView(e.data))return a=new Uint8Array(e.data.byteLength,e.read,e.length()),this.accommodate(a.byteLength),new Uint8Array(e.data.byteLength,this.write).set(a),this.write+=a.byteLength,this;if(e instanceof t.ByteStringBuffer&&(e=e.data,n="binary"),n=n||"binary","string"==typeof e){var o;if("hex"===n)return this.accommodate(Math.ceil(e.length/2)),o=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.hex.decode(e,o,this.write),this;if("base64"===n)return this.accommodate(3*Math.ceil(e.length/4)),o=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.base64.decode(e,o,this.write),this;if("utf8"===n&&(e=t.encodeUtf8(e),n="binary"),"binary"===n||"raw"===n)return this.accommodate(e.length),o=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.raw.decode(o),this;if("utf16"===n)return this.accommodate(2*e.length),o=new Uint16Array(this.data.buffer,this.write),this.write+=t.text.utf16.encode(o),this;throw new Error("Invalid encoding: "+n)}throw Error("Invalid parameter: "+e)},t.DataBuffer.prototype.putBuffer=function(e){return this.putBytes(e),e.clear(),this},t.DataBuffer.prototype.putString=function(e){return this.putBytes(e,"utf16")},t.DataBuffer.prototype.putInt16=function(e){return this.accommodate(2),this.data.setInt16(this.write,e),this.write+=2,this},t.DataBuffer.prototype.putInt24=function(e){return this.accommodate(3),this.data.setInt16(this.write,e>>8&65535),this.data.setInt8(this.write,e>>16&255),this.write+=3,this},t.DataBuffer.prototype.putInt32=function(e){return this.accommodate(4),this.data.setInt32(this.write,e),this.write+=4,this},t.DataBuffer.prototype.putInt16Le=function(e){return this.accommodate(2),this.data.setInt16(this.write,e,!0),this.write+=2,this},t.DataBuffer.prototype.putInt24Le=function(e){return this.accommodate(3),this.data.setInt8(this.write,e>>16&255),this.data.setInt16(this.write,e>>8&65535,!0),this.write+=3,this},t.DataBuffer.prototype.putInt32Le=function(e){return this.accommodate(4),this.data.setInt32(this.write,e,!0),this.write+=4,this},t.DataBuffer.prototype.putInt=function(e,t){n(t),this.accommodate(t/8);do{t-=8,this.data.setInt8(this.write++,e>>t&255)}while(t>0);return this},t.DataBuffer.prototype.putSignedInt=function(e,t){return n(t),this.accommodate(t/8),e<0&&(e+=2<<t-1),this.putInt(e,t)},t.DataBuffer.prototype.getByte=function(){return this.data.getInt8(this.read++)},t.DataBuffer.prototype.getInt16=function(){var e=this.data.getInt16(this.read);return this.read+=2,e},t.DataBuffer.prototype.getInt24=function(){var e=this.data.getInt16(this.read)<<8^this.data.getInt8(this.read+2);return this.read+=3,e},t.DataBuffer.prototype.getInt32=function(){var e=this.data.getInt32(this.read);return this.read+=4,e},t.DataBuffer.prototype.getInt16Le=function(){var e=this.data.getInt16(this.read,!0);return this.read+=2,e},t.DataBuffer.prototype.getInt24Le=function(){var e=this.data.getInt8(this.read)^this.data.getInt16(this.read+1,!0)<<8;return this.read+=3,e},t.DataBuffer.prototype.getInt32Le=function(){var e=this.data.getInt32(this.read,!0);return this.read+=4,e},t.DataBuffer.prototype.getInt=function(e){n(e);var t=0;do{t=(t<<8)+this.data.getInt8(this.read++),e-=8}while(e>0);return t},t.DataBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),n=2<<e-2;return t>=n&&(t-=n<<1),t},t.DataBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t="":(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},t.DataBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},t.DataBuffer.prototype.at=function(e){return this.data.getUint8(this.read+e)},t.DataBuffer.prototype.setAt=function(e,t){return this.data.setUint8(e,t),this},t.DataBuffer.prototype.last=function(){return this.data.getUint8(this.write-1)},t.DataBuffer.prototype.copy=function(){return new t.DataBuffer(this)},t.DataBuffer.prototype.compact=function(){if(this.read>0){var e=new Uint8Array(this.data.buffer,this.read),t=new Uint8Array(e.byteLength);t.set(e),this.data=new DataView(t),this.write-=this.read,this.read=0}return this},t.DataBuffer.prototype.clear=function(){return this.data=new DataView(new ArrayBuffer(0)),this.read=this.write=0,this},t.DataBuffer.prototype.truncate=function(e){return this.write=Math.max(0,this.length()-e),this.read=Math.min(this.read,this.write),this},t.DataBuffer.prototype.toHex=function(){for(var e="",t=this.read;t<this.data.byteLength;++t){var n=this.data.getUint8(t);n<16&&(e+="0"),e+=n.toString(16)}return e},t.DataBuffer.prototype.toString=function(e){var n=new Uint8Array(this.data,this.read,this.length());if("binary"===(e=e||"utf8")||"raw"===e)return t.binary.raw.encode(n);if("hex"===e)return t.binary.hex.encode(n);if("base64"===e)return t.binary.base64.encode(n);if("utf8"===e)return t.text.utf8.decode(n);if("utf16"===e)return t.text.utf16.decode(n);throw new Error("Invalid encoding: "+e)},t.createBuffer=function(e,n){return n=n||"raw",void 0!==e&&"utf8"===n&&(e=t.encodeUtf8(e)),new t.ByteBuffer(e)},t.fillString=function(e,t){for(var n="";t>0;)1&t&&(n+=e),(t>>>=1)>0&&(e+=e);return n},t.xorBytes=function(e,t,n){for(var r="",a="",o="",i=0,s=0;n>0;--n,++i)a=e.charCodeAt(i)^t.charCodeAt(i),s>=10&&(r+=o,o="",s=0),o+=String.fromCharCode(a),++s;return r+o},t.hexToBytes=function(e){var t="",n=0;for(!0&e.length&&(n=1,t+=String.fromCharCode(parseInt(e[0],16)));n<e.length;n+=2)t+=String.fromCharCode(parseInt(e.substr(n,2),16));return t},t.bytesToHex=function(e){return t.createBuffer(e).toHex()},t.int32ToBytes=function(e){return String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e)};var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],i="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";t.encode64=function(e,t){for(var n,r,o,i="",s="",u=0;u<e.length;)n=e.charCodeAt(u++),r=e.charCodeAt(u++),o=e.charCodeAt(u++),i+=a.charAt(n>>2),i+=a.charAt((3&n)<<4|r>>4),isNaN(r)?i+="==":(i+=a.charAt((15&r)<<2|o>>6),i+=isNaN(o)?"=":a.charAt(63&o)),t&&i.length>t&&(s+=i.substr(0,t)+"\r\n",i=i.substr(t));return s+i},t.decode64=function(e){e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var t,n,r,a,i="",s=0;s<e.length;)t=o[e.charCodeAt(s++)-43],n=o[e.charCodeAt(s++)-43],r=o[e.charCodeAt(s++)-43],a=o[e.charCodeAt(s++)-43],i+=String.fromCharCode(t<<2|n>>4),64!==r&&(i+=String.fromCharCode((15&n)<<4|r>>2),64!==a&&(i+=String.fromCharCode((3&r)<<6|a)));return i},t.encodeUtf8=function(e){return unescape(encodeURIComponent(e))},t.decodeUtf8=function(e){return decodeURIComponent(escape(e))},t.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:W.encode,decode:W.decode}},t.binary.raw.encode=function(e){return String.fromCharCode.apply(null,e)},t.binary.raw.decode=function(e,t,n){var r=t;r||(r=new Uint8Array(e.length));for(var a=n=n||0,o=0;o<e.length;++o)r[a++]=e.charCodeAt(o);return t?a-n:r},t.binary.hex.encode=t.bytesToHex,t.binary.hex.decode=function(e,t,n){var r=t;r||(r=new Uint8Array(Math.ceil(e.length/2)));var a=0,o=n=n||0;for(1&e.length&&(a=1,r[o++]=parseInt(e[0],16));a<e.length;a+=2)r[o++]=parseInt(e.substr(a,2),16);return t?o-n:r},t.binary.base64.encode=function(e,t){for(var n,r,o,i="",s="",u=0;u<e.byteLength;)n=e[u++],r=e[u++],o=e[u++],i+=a.charAt(n>>2),i+=a.charAt((3&n)<<4|r>>4),isNaN(r)?i+="==":(i+=a.charAt((15&r)<<2|o>>6),i+=isNaN(o)?"=":a.charAt(63&o)),t&&i.length>t&&(s+=i.substr(0,t)+"\r\n",i=i.substr(t));return s+i},t.binary.base64.decode=function(e,t,n){var r,a,i,s,u=t;u||(u=new Uint8Array(3*Math.ceil(e.length/4))),e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var c=0,l=n=n||0;c<e.length;)r=o[e.charCodeAt(c++)-43],a=o[e.charCodeAt(c++)-43],i=o[e.charCodeAt(c++)-43],s=o[e.charCodeAt(c++)-43],u[l++]=r<<2|a>>4,64!==i&&(u[l++]=(15&a)<<4|i>>2,64!==s&&(u[l++]=(3&i)<<6|s));return t?l-n:u.subarray(0,l)},t.binary.base58.encode=function(e,n){return t.binary.baseN.encode(e,i,n)},t.binary.base58.decode=function(e,n){return t.binary.baseN.decode(e,i,n)},t.text={utf8:{},utf16:{}},t.text.utf8.encode=function(e,n,r){e=t.encodeUtf8(e);var a=n;a||(a=new Uint8Array(e.length));for(var o=r=r||0,i=0;i<e.length;++i)a[o++]=e.charCodeAt(i);return n?o-r:a},t.text.utf8.decode=function(e){return t.decodeUtf8(String.fromCharCode.apply(null,e))},t.text.utf16.encode=function(e,t,n){var r=t;r||(r=new Uint8Array(2*e.length));for(var a=new Uint16Array(r.buffer),o=n=n||0,i=n,s=0;s<e.length;++s)a[i++]=e.charCodeAt(s),o+=2;return t?o-n:r},t.text.utf16.decode=function(e){return String.fromCharCode.apply(null,new Uint16Array(e.buffer))},t.deflate=function(e,n,r){if(n=t.decode64(e.deflate(t.encode64(n)).rval),r){var a=2;32&n.charCodeAt(1)&&(a=6),n=n.substring(a,n.length-4)}return n},t.inflate=function(e,n,r){var a=e.inflate(t.encode64(n)).rval;return null===a?null:t.decode64(a)};var s=function(e,n,r){if(!e)throw new Error("WebStorage not available.");var a;if(null===r?a=e.removeItem(n):(r=t.encode64(JSON.stringify(r)),a=e.setItem(n,r)),void 0!==a&&!0!==a.rval){var o=new Error(a.error.message);throw o.id=a.error.id,o.name=a.error.name,o}},u=function(e,n){if(!e)throw new Error("WebStorage not available.");var r=e.getItem(n);if(e.init)if(null===r.rval){if(r.error){var a=new Error(r.error.message);throw a.id=r.error.id,a.name=r.error.name,a}r=null}else r=r.rval;return null!==r&&(r=JSON.parse(t.decode64(r))),r},c=function(e,t,n,r){var a=u(e,t);null===a&&(a={}),a[n]=r,s(e,t,a)},l=function(e,t,n){var r=u(e,t);return null!==r&&(r=n in r?r[n]:null),r},p=function(e,t,n){var r=u(e,t);if(null!==r&&n in r){delete r[n];var a=!0;for(var o in r){a=!1;break}a&&(r=null),s(e,t,r)}},d=function(e,t){s(e,t,null)},f=function(e,t,n){var r,a=null;void 0===n&&(n=["web","flash"]);var o=!1,i=null;for(var s in n){r=n[s];try{if("flash"===r||"both"===r){if(null===t[0])throw new Error("Flash local storage not available.");a=e.apply(this,t),o="flash"===r}"web"!==r&&"both"!==r||(t[0]=localStorage,a=e.apply(this,t),o=!0)}catch(e){i=e}if(o)break}if(!o)throw i;return a};t.setItem=function(e,t,n,r,a){f(c,arguments,a)},t.getItem=function(e,t,n,r){return f(l,arguments,r)},t.removeItem=function(e,t,n,r){f(p,arguments,r)},t.clearItems=function(e,t,n){f(d,arguments,n)},t.parseUrl=function(e){var t=/^(https?):\/\/([^:&^\/]*):?(\d*)(.*)$/g;t.lastIndex=0;var n=t.exec(e),r=null===n?null:{full:e,scheme:n[1],host:n[2],port:n[3],path:n[4]};return r&&(r.fullHost=r.host,r.port?(80!==r.port&&"http"===r.scheme||443!==r.port&&"https"===r.scheme)&&(r.fullHost+=":"+r.port):"http"===r.scheme?r.port=80:"https"===r.scheme&&(r.port=443),r.full=r.scheme+"://"+r.fullHost),r};var h=null;t.getQueryVariables=function(e){var t,n=function(e){for(var t={},n=e.split("&"),r=0;r<n.length;r++){var a,o,i=n[r].indexOf("=");i>0?(a=n[r].substring(0,i),o=n[r].substring(i+1)):(a=n[r],o=null),a in t||(t[a]=[]),a in Object.prototype||null===o||t[a].push(unescape(o))}return t};return void 0===e?(null===h&&(h="undefined"!=typeof window&&window.location&&window.location.search?n(window.location.search.substring(1)):{}),t=h):t=n(e),t},t.parseFragment=function(e){var n=e,r="",a=e.indexOf("?");a>0&&(n=e.substring(0,a),r=e.substring(a+1));var o=n.split("/");return o.length>0&&""===o[0]&&o.shift(),{pathString:n,queryString:r,path:o,query:""===r?{}:t.getQueryVariables(r)}},t.makeRequest=function(e){var n=t.parseFragment(e),r={path:n.pathString,query:n.queryString,getPath:function(e){return void 0===e?n.path:n.path[e]},getQuery:function(e,t){var r;return void 0===e?r=n.query:(r=n.query[e])&&void 0!==t&&(r=r[t]),r},getQueryLast:function(e,t){var n=r.getQuery(e);return n?n[n.length-1]:t}};return r},t.makeLink=function(e,t,n){e=jQuery.isArray(e)?e.join("/"):e;var r=jQuery.param(t||{});return n=n||"",e+(r.length>0?"?"+r:"")+(n.length>0?"#"+n:"")},t.setPath=function(e,t,n){if("object"==typeof e&&null!==e)for(var r=0,a=t.length;r<a;){var o=t[r++];if(r==a)e[o]=n;else{var i=o in e;(!i||i&&"object"!=typeof e[o]||i&&null===e[o])&&(e[o]={}),e=e[o]}}},t.getPath=function(e,t,n){for(var r=0,a=t.length,o=!0;o&&r<a&&"object"==typeof e&&null!==e;){var i=t[r++];(o=i in e)&&(e=e[i])}return o?e:n},t.deletePath=function(e,t){if("object"==typeof e&&null!==e)for(var n=0,r=t.length;n<r;){var a=t[n++];if(n==r)delete e[a];else{if(!(a in e)||"object"!=typeof e[a]||null===e[a])break;e=e[a]}}},t.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},t.format=function(e){for(var t,n,r=/%./g,a=0,o=[],i=0;t=r.exec(e);){(n=e.substring(i,r.lastIndex-2)).length>0&&o.push(n),i=r.lastIndex;var s=t[0][1];switch(s){case"s":case"o":a<arguments.length?o.push(arguments[1+a++]):o.push("<?>");break;case"%":o.push("%");break;default:o.push("<%"+s+"?>")}}return o.push(e.substring(i)),o.join("")},t.formatNumber=function(e,t,n,r){var a=e,o=isNaN(t=Math.abs(t))?2:t,i=void 0===n?",":n,s=void 0===r?".":r,u=a<0?"-":"",c=parseInt(a=Math.abs(+a||0).toFixed(o),10)+"",l=c.length>3?c.length%3:0;return u+(l?c.substr(0,l)+s:"")+c.substr(l).replace(/(\d{3})(?=\d)/g,"$1"+s)+(o?i+Math.abs(a-c).toFixed(o).slice(2):"")},t.formatSize=function(e){return e>=1073741824?t.formatNumber(e/1073741824,2,".","")+" GiB":e>=1048576?t.formatNumber(e/1048576,2,".","")+" MiB":e>=1024?t.formatNumber(e/1024,0)+" KiB":t.formatNumber(e,0)+" bytes"},t.bytesFromIP=function(e){return-1!==e.indexOf(".")?t.bytesFromIPv4(e):-1!==e.indexOf(":")?t.bytesFromIPv6(e):null},t.bytesFromIPv4=function(e){if(4!==(e=e.split(".")).length)return null;for(var n=t.createBuffer(),r=0;r<e.length;++r){var a=parseInt(e[r],10);if(isNaN(a))return null;n.putByte(a)}return n.getBytes()},t.bytesFromIPv6=function(e){for(var n=0,r=2*(8-(e=e.split(":").filter((function(e){return 0===e.length&&++n,!0}))).length+n),a=t.createBuffer(),o=0;o<8;++o)if(e[o]&&0!==e[o].length){var i=t.hexToBytes(e[o]);i.length<2&&a.putByte(0),a.putBytes(i)}else a.fillWithByte(0,r),r=0;return a.getBytes()},t.bytesToIP=function(e){return 4===e.length?t.bytesToIPv4(e):16===e.length?t.bytesToIPv6(e):null},t.bytesToIPv4=function(e){if(4!==e.length)return null;for(var t=[],n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t.join(".")},t.bytesToIPv6=function(e){if(16!==e.length)return null;for(var n=[],r=[],a=0,o=0;o<e.length;o+=2){for(var i=t.bytesToHex(e[o]+e[o+1]);"0"===i[0]&&"0"!==i;)i=i.substr(1);if("0"===i){var s=r[r.length-1],u=n.length;s&&u===s.end+1?(s.end=u,s.end-s.start>r[a].end-r[a].start&&(a=r.length-1)):r.push({start:u,end:u})}n.push(i)}if(r.length>0){var c=r[a];c.end-c.start>0&&(n.splice(c.start,c.end-c.start+1,""),0===c.start&&n.unshift(""),7===c.end&&n.push(""))}return n.join(":")},t.estimateCores=function(e,n){if("function"==typeof e&&(n=e,e={}),e=e||{},"cores"in t&&!e.update)return n(null,t.cores);if("undefined"!=typeof navigator&&"hardwareConcurrency"in navigator&&navigator.hardwareConcurrency>0)return t.cores=navigator.hardwareConcurrency,n(null,t.cores);if("undefined"==typeof Worker)return t.cores=1,n(null,t.cores);if("undefined"==typeof Blob)return t.cores=2,n(null,t.cores);var r=URL.createObjectURL(new Blob(["(",function(){self.addEventListener("message",(function(e){var t=Date.now(),n=t+4;self.postMessage({st:t,et:n})}))}.toString(),")()"],{type:"application/javascript"}));!function e(a,o,i){if(0===o){var s=Math.floor(a.reduce((function(e,t){return e+t}),0)/a.length);return t.cores=Math.max(1,s),URL.revokeObjectURL(r),n(null,t.cores)}!function(e,t){for(var n=[],a=[],o=0;o<e;++o){var i=new Worker(r);i.addEventListener("message",(function(r){if(a.push(r.data),a.length===e){for(var o=0;o<e;++o)n[o].terminate();t(null,a)}})),n.push(i)}for(o=0;o<e;++o)n[o].postMessage(o)}(i,(function(t,n){a.push(function(e,t){for(var n=[],r=0;r<e;++r)for(var a=t[r],o=n[r]=[],i=0;i<e;++i)if(r!==i){var s=t[i];(a.st>s.st&&a.st<s.et||s.st>a.st&&s.st<a.et)&&o.push(i)}return n.reduce((function(e,t){return Math.max(e,t.length)}),0)}(i,n)),e(a,o-1,i)}))}([],5,16)}})),z.cipher=z.cipher||{},z.cipher.algorithms=z.cipher.algorithms||{},z.cipher.createCipher=function(e,t){var n=e;if("string"==typeof n&&(n=z.cipher.getAlgorithm(n))&&(n=n()),!n)throw new Error("Unsupported algorithm: "+e);return new z.cipher.BlockCipher({algorithm:n,key:t,decrypt:!1})},z.cipher.createDecipher=function(e,t){var n=e;if("string"==typeof n&&(n=z.cipher.getAlgorithm(n))&&(n=n()),!n)throw new Error("Unsupported algorithm: "+e);return new z.cipher.BlockCipher({algorithm:n,key:t,decrypt:!0})},z.cipher.registerAlgorithm=function(e,t){e=e.toUpperCase(),z.cipher.algorithms[e]=t},z.cipher.getAlgorithm=function(e){return(e=e.toUpperCase())in z.cipher.algorithms?z.cipher.algorithms[e]:null};var G=z.cipher.BlockCipher=function(e){this.algorithm=e.algorithm,this.mode=this.algorithm.mode,this.blockSize=this.mode.blockSize,this._finish=!1,this._input=null,this.output=null,this._op=e.decrypt?this.mode.decrypt:this.mode.encrypt,this._decrypt=e.decrypt,this.algorithm.initialize(e)};function K(e,t){z.cipher.registerAlgorithm(e,(function(){return new z.aes.Algorithm(e,t)}))}G.prototype.start=function(e){e=e||{};var t={};for(var n in e)t[n]=e[n];t.decrypt=this._decrypt,this._finish=!1,this._input=z.util.createBuffer(),this.output=e.output||z.util.createBuffer(),this.mode.start(t)},G.prototype.update=function(e){for(e&&this._input.putBuffer(e);!this._op.call(this.mode,this._input,this.output,this._finish)&&!this._finish;);this._input.compact()},G.prototype.finish=function(e){!e||"ECB"!==this.mode.name&&"CBC"!==this.mode.name||(this.mode.pad=function(t){return e(this.blockSize,t,!1)},this.mode.unpad=function(t){return e(this.blockSize,t,!0)});var t={};return t.decrypt=this._decrypt,t.overflow=this._input.length()%this.blockSize,!(!this._decrypt&&this.mode.pad&&!this.mode.pad(this._input,t)||(this._finish=!0,this.update(),this._decrypt&&this.mode.unpad&&!this.mode.unpad(this.output,t)||this.mode.afterFinish&&!this.mode.afterFinish(this.output,t)))},w((function(e){z.cipher=z.cipher||{};var t=e.exports=z.cipher.modes=z.cipher.modes||{};function n(e,t){if("string"==typeof e&&(e=z.util.createBuffer(e)),z.util.isArray(e)&&e.length>4){var n=e;e=z.util.createBuffer();for(var r=0;r<n.length;++r)e.putByte(n[r])}if(e.length()<t)throw new Error("Invalid IV length; got "+e.length()+" bytes and expected "+t+" bytes.");if(!z.util.isArray(e)){var a=[],o=t/4;for(r=0;r<o;++r)a.push(e.getInt32());e=a}return e}function r(e){e[e.length-1]=e[e.length-1]+1&4294967295}function a(e){return[e/4294967296|0,4294967295&e]}t.ecb=function(e){e=e||{},this.name="ECB",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},t.ecb.prototype.start=function(e){},t.ecb.prototype.encrypt=function(e,t,n){if(e.length()<this.blockSize&&!(n&&e.length()>0))return!0;for(var r=0;r<this._ints;++r)this._inBlock[r]=e.getInt32();for(this.cipher.encrypt(this._inBlock,this._outBlock),r=0;r<this._ints;++r)t.putInt32(this._outBlock[r])},t.ecb.prototype.decrypt=function(e,t,n){if(e.length()<this.blockSize&&!(n&&e.length()>0))return!0;for(var r=0;r<this._ints;++r)this._inBlock[r]=e.getInt32();for(this.cipher.decrypt(this._inBlock,this._outBlock),r=0;r<this._ints;++r)t.putInt32(this._outBlock[r])},t.ecb.prototype.pad=function(e,t){var n=e.length()===this.blockSize?this.blockSize:this.blockSize-e.length();return e.fillWithByte(n,n),!0},t.ecb.prototype.unpad=function(e,t){if(t.overflow>0)return!1;var n=e.length(),r=e.at(n-1);return!(r>this.blockSize<<2||(e.truncate(r),0))},t.cbc=function(e){e=e||{},this.name="CBC",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},t.cbc.prototype.start=function(e){if(null===e.iv){if(!this._prev)throw new Error("Invalid IV parameter.");this._iv=this._prev.slice(0)}else{if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=n(e.iv,this.blockSize),this._prev=this._iv.slice(0)}},t.cbc.prototype.encrypt=function(e,t,n){if(e.length()<this.blockSize&&!(n&&e.length()>0))return!0;for(var r=0;r<this._ints;++r)this._inBlock[r]=this._prev[r]^e.getInt32();for(this.cipher.encrypt(this._inBlock,this._outBlock),r=0;r<this._ints;++r)t.putInt32(this._outBlock[r]);this._prev=this._outBlock},t.cbc.prototype.decrypt=function(e,t,n){if(e.length()<this.blockSize&&!(n&&e.length()>0))return!0;for(var r=0;r<this._ints;++r)this._inBlock[r]=e.getInt32();for(this.cipher.decrypt(this._inBlock,this._outBlock),r=0;r<this._ints;++r)t.putInt32(this._prev[r]^this._outBlock[r]);this._prev=this._inBlock.slice(0)},t.cbc.prototype.pad=function(e,t){var n=e.length()===this.blockSize?this.blockSize:this.blockSize-e.length();return e.fillWithByte(n,n),!0},t.cbc.prototype.unpad=function(e,t){if(t.overflow>0)return!1;var n=e.length(),r=e.at(n-1);return!(r>this.blockSize<<2||(e.truncate(r),0))},t.cfb=function(e){e=e||{},this.name="CFB",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialBlock=new Array(this._ints),this._partialOutput=z.util.createBuffer(),this._partialBytes=0},t.cfb.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=n(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},t.cfb.prototype.encrypt=function(e,t,n){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var a=0;a<this._ints;++a)this._inBlock[a]=e.getInt32()^this._outBlock[a],t.putInt32(this._inBlock[a]);else{var o=(this.blockSize-r)%this.blockSize;for(o>0&&(o=this.blockSize-o),this._partialOutput.clear(),a=0;a<this._ints;++a)this._partialBlock[a]=e.getInt32()^this._outBlock[a],this._partialOutput.putInt32(this._partialBlock[a]);if(o>0)e.read-=this.blockSize;else for(a=0;a<this._ints;++a)this._inBlock[a]=this._partialBlock[a];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!n)return t.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},t.cfb.prototype.decrypt=function(e,t,n){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var a=0;a<this._ints;++a)this._inBlock[a]=e.getInt32(),t.putInt32(this._inBlock[a]^this._outBlock[a]);else{var o=(this.blockSize-r)%this.blockSize;for(o>0&&(o=this.blockSize-o),this._partialOutput.clear(),a=0;a<this._ints;++a)this._partialBlock[a]=e.getInt32(),this._partialOutput.putInt32(this._partialBlock[a]^this._outBlock[a]);if(o>0)e.read-=this.blockSize;else for(a=0;a<this._ints;++a)this._inBlock[a]=this._partialBlock[a];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!n)return t.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},t.ofb=function(e){e=e||{},this.name="OFB",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=z.util.createBuffer(),this._partialBytes=0},t.ofb.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=n(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},t.ofb.prototype.encrypt=function(e,t,n){var r=e.length();if(0===e.length())return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var a=0;a<this._ints;++a)t.putInt32(e.getInt32()^this._outBlock[a]),this._inBlock[a]=this._outBlock[a];else{var o=(this.blockSize-r)%this.blockSize;for(o>0&&(o=this.blockSize-o),this._partialOutput.clear(),a=0;a<this._ints;++a)this._partialOutput.putInt32(e.getInt32()^this._outBlock[a]);if(o>0)e.read-=this.blockSize;else for(a=0;a<this._ints;++a)this._inBlock[a]=this._outBlock[a];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!n)return t.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},t.ofb.prototype.decrypt=t.ofb.prototype.encrypt,t.ctr=function(e){e=e||{},this.name="CTR",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=z.util.createBuffer(),this._partialBytes=0},t.ctr.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=n(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},t.ctr.prototype.encrypt=function(e,t,n){var a=e.length();if(0===a)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&a>=this.blockSize)for(var o=0;o<this._ints;++o)t.putInt32(e.getInt32()^this._outBlock[o]);else{var i=(this.blockSize-a)%this.blockSize;for(i>0&&(i=this.blockSize-i),this._partialOutput.clear(),o=0;o<this._ints;++o)this._partialOutput.putInt32(e.getInt32()^this._outBlock[o]);if(i>0&&(e.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!n)return t.putBytes(this._partialOutput.getBytes(i-this._partialBytes)),this._partialBytes=i,!0;t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=0}r(this._inBlock)},t.ctr.prototype.decrypt=t.ctr.prototype.encrypt,t.gcm=function(e){e=e||{},this.name="GCM",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints),this._partialOutput=z.util.createBuffer(),this._partialBytes=0,this._R=3774873600},t.gcm.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");var t,n=z.util.createBuffer(e.iv);if(this._cipherLength=0,t="additionalData"in e?z.util.createBuffer(e.additionalData):z.util.createBuffer(),this._tagLength="tagLength"in e?e.tagLength:128,this._tag=null,e.decrypt&&(this._tag=z.util.createBuffer(e.tag).getBytes(),this._tag.length!==this._tagLength/8))throw new Error("Authentication tag does not match tag length.");this._hashBlock=new Array(this._ints),this.tag=null,this._hashSubkey=new Array(this._ints),this.cipher.encrypt([0,0,0,0],this._hashSubkey),this.componentBits=4,this._m=this.generateHashTable(this._hashSubkey,this.componentBits);var o=n.length();if(12===o)this._j0=[n.getInt32(),n.getInt32(),n.getInt32(),1];else{for(this._j0=[0,0,0,0];n.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[n.getInt32(),n.getInt32(),n.getInt32(),n.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(a(8*o)))}this._inBlock=this._j0.slice(0),r(this._inBlock),this._partialBytes=0,t=z.util.createBuffer(t),this._aDataLength=a(8*t.length());var i=t.length()%this.blockSize;for(i&&t.fillWithByte(0,this.blockSize-i),this._s=[0,0,0,0];t.length()>0;)this._s=this.ghash(this._hashSubkey,this._s,[t.getInt32(),t.getInt32(),t.getInt32(),t.getInt32()])},t.gcm.prototype.encrypt=function(e,t,n){var a=e.length();if(0===a)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&a>=this.blockSize){for(var o=0;o<this._ints;++o)t.putInt32(this._outBlock[o]^=e.getInt32());this._cipherLength+=this.blockSize}else{var i=(this.blockSize-a)%this.blockSize;for(i>0&&(i=this.blockSize-i),this._partialOutput.clear(),o=0;o<this._ints;++o)this._partialOutput.putInt32(e.getInt32()^this._outBlock[o]);if(i<=0||n){if(n){var s=a%this.blockSize;this._cipherLength+=s,this._partialOutput.truncate(this.blockSize-s)}else this._cipherLength+=this.blockSize;for(o=0;o<this._ints;++o)this._outBlock[o]=this._partialOutput.getInt32();this._partialOutput.read-=this.blockSize}if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!n)return e.read-=this.blockSize,t.putBytes(this._partialOutput.getBytes(i-this._partialBytes)),this._partialBytes=i,!0;t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=0}this._s=this.ghash(this._hashSubkey,this._s,this._outBlock),r(this._inBlock)},t.gcm.prototype.decrypt=function(e,t,n){var a=e.length();if(a<this.blockSize&&!(n&&a>0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),r(this._inBlock),this._hashBlock[0]=e.getInt32(),this._hashBlock[1]=e.getInt32(),this._hashBlock[2]=e.getInt32(),this._hashBlock[3]=e.getInt32(),this._s=this.ghash(this._hashSubkey,this._s,this._hashBlock);for(var o=0;o<this._ints;++o)t.putInt32(this._outBlock[o]^this._hashBlock[o]);a<this.blockSize?this._cipherLength+=a%this.blockSize:this._cipherLength+=this.blockSize},t.gcm.prototype.afterFinish=function(e,t){var n=!0;t.decrypt&&t.overflow&&e.truncate(this.blockSize-t.overflow),this.tag=z.util.createBuffer();var r=this._aDataLength.concat(a(8*this._cipherLength));this._s=this.ghash(this._hashSubkey,this._s,r);var o=[];this.cipher.encrypt(this._j0,o);for(var i=0;i<this._ints;++i)this.tag.putInt32(this._s[i]^o[i]);return this.tag.truncate(this.tag.length()%(this._tagLength/8)),t.decrypt&&this.tag.bytes()!==this._tag&&(n=!1),n},t.gcm.prototype.multiply=function(e,t){for(var n=[0,0,0,0],r=t.slice(0),a=0;a<128;++a)e[a/32|0]&1<<31-a%32&&(n[0]^=r[0],n[1]^=r[1],n[2]^=r[2],n[3]^=r[3]),this.pow(r,r);return n},t.gcm.prototype.pow=function(e,t){for(var n=1&e[3],r=3;r>0;--r)t[r]=e[r]>>>1|(1&e[r-1])<<31;t[0]=e[0]>>>1,n&&(t[0]^=this._R)},t.gcm.prototype.tableMultiply=function(e){for(var t=[0,0,0,0],n=0;n<32;++n){var r=e[n/8|0]>>>4*(7-n%8)&15,a=this._m[n][r];t[0]^=a[0],t[1]^=a[1],t[2]^=a[2],t[3]^=a[3]}return t},t.gcm.prototype.ghash=function(e,t,n){return t[0]^=n[0],t[1]^=n[1],t[2]^=n[2],t[3]^=n[3],this.tableMultiply(t)},t.gcm.prototype.generateHashTable=function(e,t){for(var n=8/t,r=4*n,a=16*n,o=new Array(a),i=0;i<a;++i){var s=[0,0,0,0],u=(r-1-i%r)*t;s[i/r|0]=1<<t-1<<u,o[i]=this.generateSubHashTable(this.multiply(s,e),t)}return o},t.gcm.prototype.generateSubHashTable=function(e,t){var n=1<<t,r=n>>>1,a=new Array(n);a[r]=e.slice(0);for(var o=r>>>1;o>0;)this.pow(a[2*o],a[o]=[]),o>>=1;for(o=2;o<r;){for(var i=1;i<o;++i){var s=a[o],u=a[i];a[o+i]=[s[0]^u[0],s[1]^u[1],s[2]^u[2],s[3]^u[3]]}o*=2}for(a[0]=[0,0,0,0],o=r+1;o<n;++o){var c=a[o^r];a[o]=[e[0]^c[0],e[1]^c[1],e[2]^c[2],e[3]^c[3]]}return a}})),z.aes=z.aes||{},z.aes.startEncrypting=function(e,t,n,r){var a=re({key:e,output:n,decrypt:!1,mode:r});return a.start(t),a},z.aes.createEncryptionCipher=function(e,t){return re({key:e,output:null,decrypt:!1,mode:t})},z.aes.startDecrypting=function(e,t,n,r){var a=re({key:e,output:n,decrypt:!0,mode:r});return a.start(t),a},z.aes.createDecryptionCipher=function(e,t){return re({key:e,output:null,decrypt:!0,mode:t})},z.aes.Algorithm=function(e,t){Z||ee();var n=this;n.name=e,n.mode=new t({blockSize:16,cipher:{encrypt:function(e,t){return ne(n._w,e,t,!1)},decrypt:function(e,t){return ne(n._w,e,t,!0)}}}),n._init=!1},z.aes.Algorithm.prototype.initialize=function(e){if(!this._init){var t,n=e.key;if("string"!=typeof n||16!==n.length&&24!==n.length&&32!==n.length){if(z.util.isArray(n)&&(16===n.length||24===n.length||32===n.length)){t=n,n=z.util.createBuffer();for(var r=0;r<t.length;++r)n.putByte(t[r])}}else n=z.util.createBuffer(n);if(!z.util.isArray(n)){t=n,n=[];var a=t.length();if(16===a||24===a||32===a)for(a>>>=2,r=0;r<a;++r)n.push(t.getInt32())}if(!z.util.isArray(n)||4!==n.length&&6!==n.length&&8!==n.length)throw new Error("Invalid key parameter.");var o=this.mode.name,i=-1!==["CFB","OFB","CTR","GCM"].indexOf(o);this._w=te(n,e.decrypt&&!i),this._init=!0}},z.aes._expandKey=function(e,t){return Z||ee(),te(e,t)},z.aes._updateBlock=ne,K("AES-ECB",z.cipher.modes.ecb),K("AES-CBC",z.cipher.modes.cbc),K("AES-CFB",z.cipher.modes.cfb),K("AES-OFB",z.cipher.modes.ofb),K("AES-CTR",z.cipher.modes.ctr),K("AES-GCM",z.cipher.modes.gcm);var q,Q,X,Y,$,Z=!1,J=4;function ee(){Z=!0,X=[0,1,2,4,8,16,32,64,128,27,54];for(var e=new Array(256),t=0;t<128;++t)e[t]=t<<1,e[t+128]=t+128<<1^283;for(q=new Array(256),Q=new Array(256),Y=new Array(4),$=new Array(4),t=0;t<4;++t)Y[t]=new Array(256),$[t]=new Array(256);var n,r,a,o,i,s,u,c=0,l=0;for(t=0;t<256;++t){o=(o=l^l<<1^l<<2^l<<3^l<<4)>>8^255&o^99,q[c]=o,Q[o]=c,s=(i=e[o])<<24^o<<16^o<<8^o^i,u=((n=e[c])^(r=e[n])^(a=e[r]))<<24^(c^a)<<16^(c^r^a)<<8^c^n^a;for(var p=0;p<4;++p)Y[p][c]=s,$[p][o]=u,s=s<<24|s>>>8,u=u<<24|u>>>8;0===c?c=l=1:(c=n^e[e[e[n^a]]],l^=e[e[l]])}}function te(e,t){for(var n,r=e.slice(0),a=1,o=r.length,i=J*(o+6+1),s=o;s<i;++s)n=r[s-1],s%o==0?(n=q[n>>>16&255]<<24^q[n>>>8&255]<<16^q[255&n]<<8^q[n>>>24]^X[a]<<24,a++):o>6&&s%o==4&&(n=q[n>>>24]<<24^q[n>>>16&255]<<16^q[n>>>8&255]<<8^q[255&n]),r[s]=r[s-o]^n;if(t){for(var u,c=$[0],l=$[1],p=$[2],d=$[3],f=r.slice(0),h=(s=0,(i=r.length)-J);s<i;s+=J,h-=J)if(0===s||s===i-J)f[s]=r[h],f[s+1]=r[h+3],f[s+2]=r[h+2],f[s+3]=r[h+1];else for(var m=0;m<J;++m)u=r[h+m],f[s+(3&-m)]=c[q[u>>>24]]^l[q[u>>>16&255]]^p[q[u>>>8&255]]^d[q[255&u]];r=f}return r}function ne(e,t,n,r){var a,o,i,s,u,c,l,p,d,f,h,m,g=e.length/4-1;r?(a=$[0],o=$[1],i=$[2],s=$[3],u=Q):(a=Y[0],o=Y[1],i=Y[2],s=Y[3],u=q),c=t[0]^e[0],l=t[r?3:1]^e[1],p=t[2]^e[2],d=t[r?1:3]^e[3];for(var v=3,y=1;y<g;++y)f=a[c>>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&d]^e[++v],h=a[l>>>24]^o[p>>>16&255]^i[d>>>8&255]^s[255&c]^e[++v],m=a[p>>>24]^o[d>>>16&255]^i[c>>>8&255]^s[255&l]^e[++v],d=a[d>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^e[++v],c=f,l=h,p=m;n[0]=u[c>>>24]<<24^u[l>>>16&255]<<16^u[p>>>8&255]<<8^u[255&d]^e[++v],n[r?3:1]=u[l>>>24]<<24^u[p>>>16&255]<<16^u[d>>>8&255]<<8^u[255&c]^e[++v],n[2]=u[p>>>24]<<24^u[d>>>16&255]<<16^u[c>>>8&255]<<8^u[255&l]^e[++v],n[r?1:3]=u[d>>>24]<<24^u[c>>>16&255]<<16^u[l>>>8&255]<<8^u[255&p]^e[++v]}function re(e){var t,n="AES-"+((e=e||{}).mode||"CBC").toUpperCase(),r=(t=e.decrypt?z.cipher.createDecipher(n,e.key):z.cipher.createCipher(n,e.key)).start;return t.start=function(e,n){var a=null;n instanceof z.util.ByteBuffer&&(a=n,n={}),(n=n||{}).output=a,n.iv=e,r.call(t,n)},t}function ae(e,t){z.cipher.registerAlgorithm(e,(function(){return new z.des.Algorithm(e,t)}))}w((function(e){z.pki=z.pki||{};var t=e.exports=z.pki.oids=z.oids=z.oids||{};function n(e,n){t[e]=n,t[n]=e}function r(e,n){t[e]=n}n("1.2.840.113549.1.1.1","rsaEncryption"),n("1.2.840.113549.1.1.4","md5WithRSAEncryption"),n("1.2.840.113549.1.1.5","sha1WithRSAEncryption"),n("1.2.840.113549.1.1.7","RSAES-OAEP"),n("1.2.840.113549.1.1.8","mgf1"),n("1.2.840.113549.1.1.9","pSpecified"),n("1.2.840.113549.1.1.10","RSASSA-PSS"),n("1.2.840.113549.1.1.11","sha256WithRSAEncryption"),n("1.2.840.113549.1.1.12","sha384WithRSAEncryption"),n("1.2.840.113549.1.1.13","sha512WithRSAEncryption"),n("1.3.101.112","EdDSA25519"),n("1.2.840.10040.4.3","dsa-with-sha1"),n("1.3.14.3.2.7","desCBC"),n("1.3.14.3.2.26","sha1"),n("2.16.840.1.101.3.4.2.1","sha256"),n("2.16.840.1.101.3.4.2.2","sha384"),n("2.16.840.1.101.3.4.2.3","sha512"),n("1.2.840.113549.2.5","md5"),n("1.2.840.113549.1.7.1","data"),n("1.2.840.113549.1.7.2","signedData"),n("1.2.840.113549.1.7.3","envelopedData"),n("1.2.840.113549.1.7.4","signedAndEnvelopedData"),n("1.2.840.113549.1.7.5","digestedData"),n("1.2.840.113549.1.7.6","encryptedData"),n("1.2.840.113549.1.9.1","emailAddress"),n("1.2.840.113549.1.9.2","unstructuredName"),n("1.2.840.113549.1.9.3","contentType"),n("1.2.840.113549.1.9.4","messageDigest"),n("1.2.840.113549.1.9.5","signingTime"),n("1.2.840.113549.1.9.6","counterSignature"),n("1.2.840.113549.1.9.7","challengePassword"),n("1.2.840.113549.1.9.8","unstructuredAddress"),n("1.2.840.113549.1.9.14","extensionRequest"),n("1.2.840.113549.1.9.20","friendlyName"),n("1.2.840.113549.1.9.21","localKeyId"),n("1.2.840.113549.1.9.22.1","x509Certificate"),n("1.2.840.113549.1.12.10.1.1","keyBag"),n("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag"),n("1.2.840.113549.1.12.10.1.3","certBag"),n("1.2.840.113549.1.12.10.1.4","crlBag"),n("1.2.840.113549.1.12.10.1.5","secretBag"),n("1.2.840.113549.1.12.10.1.6","safeContentsBag"),n("1.2.840.113549.1.5.13","pkcs5PBES2"),n("1.2.840.113549.1.5.12","pkcs5PBKDF2"),n("1.2.840.113549.1.12.1.1","pbeWithSHAAnd128BitRC4"),n("1.2.840.113549.1.12.1.2","pbeWithSHAAnd40BitRC4"),n("1.2.840.113549.1.12.1.3","pbeWithSHAAnd3-KeyTripleDES-CBC"),n("1.2.840.113549.1.12.1.4","pbeWithSHAAnd2-KeyTripleDES-CBC"),n("1.2.840.113549.1.12.1.5","pbeWithSHAAnd128BitRC2-CBC"),n("1.2.840.113549.1.12.1.6","pbewithSHAAnd40BitRC2-CBC"),n("1.2.840.113549.2.7","hmacWithSHA1"),n("1.2.840.113549.2.8","hmacWithSHA224"),n("1.2.840.113549.2.9","hmacWithSHA256"),n("1.2.840.113549.2.10","hmacWithSHA384"),n("1.2.840.113549.2.11","hmacWithSHA512"),n("1.2.840.113549.3.7","des-EDE3-CBC"),n("2.16.840.1.101.3.4.1.2","aes128-CBC"),n("2.16.840.1.101.3.4.1.22","aes192-CBC"),n("2.16.840.1.101.3.4.1.42","aes256-CBC"),n("2.5.4.3","commonName"),n("2.5.4.5","serialName"),n("2.5.4.6","countryName"),n("2.5.4.7","localityName"),n("2.5.4.8","stateOrProvinceName"),n("2.5.4.9","streetAddress"),n("2.5.4.10","organizationName"),n("2.5.4.11","organizationalUnitName"),n("2.5.4.13","description"),n("2.5.4.15","businessCategory"),n("2.5.4.17","postalCode"),n("1.3.6.1.4.1.311.60.2.1.2","jurisdictionOfIncorporationStateOrProvinceName"),n("1.3.6.1.4.1.311.60.2.1.3","jurisdictionOfIncorporationCountryName"),n("2.16.840.1.113730.1.1","nsCertType"),n("2.16.840.1.113730.1.13","nsComment"),r("2.5.29.1","authorityKeyIdentifier"),r("2.5.29.2","keyAttributes"),r("2.5.29.3","certificatePolicies"),r("2.5.29.4","keyUsageRestriction"),r("2.5.29.5","policyMapping"),r("2.5.29.6","subtreesConstraint"),r("2.5.29.7","subjectAltName"),r("2.5.29.8","issuerAltName"),r("2.5.29.9","subjectDirectoryAttributes"),r("2.5.29.10","basicConstraints"),r("2.5.29.11","nameConstraints"),r("2.5.29.12","policyConstraints"),r("2.5.29.13","basicConstraints"),n("2.5.29.14","subjectKeyIdentifier"),n("2.5.29.15","keyUsage"),r("2.5.29.16","privateKeyUsagePeriod"),n("2.5.29.17","subjectAltName"),n("2.5.29.18","issuerAltName"),n("2.5.29.19","basicConstraints"),r("2.5.29.20","cRLNumber"),r("2.5.29.21","cRLReason"),r("2.5.29.22","expirationDate"),r("2.5.29.23","instructionCode"),r("2.5.29.24","invalidityDate"),r("2.5.29.25","cRLDistributionPoints"),r("2.5.29.26","issuingDistributionPoint"),r("2.5.29.27","deltaCRLIndicator"),r("2.5.29.28","issuingDistributionPoint"),r("2.5.29.29","certificateIssuer"),r("2.5.29.30","nameConstraints"),n("2.5.29.31","cRLDistributionPoints"),n("2.5.29.32","certificatePolicies"),r("2.5.29.33","policyMappings"),r("2.5.29.34","policyConstraints"),n("2.5.29.35","authorityKeyIdentifier"),r("2.5.29.36","policyConstraints"),n("2.5.29.37","extKeyUsage"),r("2.5.29.46","freshestCRL"),r("2.5.29.54","inhibitAnyPolicy"),n("1.3.6.1.4.1.11129.2.4.2","timestampList"),n("1.3.6.1.5.5.7.1.1","authorityInfoAccess"),n("1.3.6.1.5.5.7.3.1","serverAuth"),n("1.3.6.1.5.5.7.3.2","clientAuth"),n("1.3.6.1.5.5.7.3.3","codeSigning"),n("1.3.6.1.5.5.7.3.4","emailProtection"),n("1.3.6.1.5.5.7.3.8","timeStamping")})),w((function(e){var t=e.exports=z.asn1=z.asn1||{};function n(e,t,n){if(n>t){var r=new Error("Too few bytes to parse DER.");throw r.available=e.length(),r.remaining=t,r.requested=n,r}}t.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},t.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30},t.create=function(e,n,r,a,o){if(z.util.isArray(a)){for(var i=[],s=0;s<a.length;++s)void 0!==a[s]&&i.push(a[s]);a=i}var u={tagClass:e,type:n,constructed:r,composed:r||z.util.isArray(a),value:a};return o&&"bitStringContents"in o&&(u.bitStringContents=o.bitStringContents,u.original=t.copy(u)),u},t.copy=function(e,n){var r;if(z.util.isArray(e)){r=[];for(var a=0;a<e.length;++a)r.push(t.copy(e[a],n));return r}return"string"==typeof e?e:(r={tagClass:e.tagClass,type:e.type,constructed:e.constructed,composed:e.composed,value:t.copy(e.value,n)},n&&!n.excludeBitStringContents&&(r.bitStringContents=e.bitStringContents),r)},t.equals=function(e,n,r){if(z.util.isArray(e)){if(!z.util.isArray(n))return!1;if(e.length!==n.length)return!1;for(var a=0;a<e.length;++a)if(!t.equals(e[a],n[a]))return!1;return!0}if(typeof e!=typeof n)return!1;if("string"==typeof e)return e===n;var o=e.tagClass===n.tagClass&&e.type===n.type&&e.constructed===n.constructed&&e.composed===n.composed&&t.equals(e.value,n.value);return r&&r.includeBitStringContents&&(o=o&&e.bitStringContents===n.bitStringContents),o},t.getBerValueLength=function(e){var t=e.getByte();if(128!==t)return 128&t?e.getInt((127&t)<<3):t};var r=function(e,t){var r=e.getByte();if(t--,128!==r){var a;if(128&r){var o=127&r;n(e,t,o),a=e.getInt(o<<3)}else a=r;if(a<0)throw new Error("Negative length: "+a);return a}};t.fromDer=function(e,a){return void 0===a&&(a={strict:!0,decodeBitStrings:!0}),"boolean"==typeof a&&(a={strict:a,decodeBitStrings:!0}),"strict"in a||(a.strict=!0),"decodeBitStrings"in a||(a.decodeBitStrings=!0),"string"==typeof e&&(e=z.util.createBuffer(e)),function e(a,o,i,s){var u;n(a,o,2);var c=a.getByte();o--;var l=192&c,p=31&c;u=a.length();var d,f,h=r(a,o);if(o-=u-a.length(),void 0!==h&&h>o){if(s.strict){var m=new Error("Too few bytes to read ASN.1 value.");throw m.available=a.length(),m.remaining=o,m.requested=h,m}h=o}var g=32==(32&c);if(g)if(d=[],void 0===h)for(;;){if(n(a,o,2),a.bytes(2)===String.fromCharCode(0,0)){a.getBytes(2),o-=2;break}u=a.length(),d.push(e(a,o,i+1,s)),o-=u-a.length()}else for(;h>0;)u=a.length(),d.push(e(a,h,i+1,s)),o-=u-a.length(),h-=u-a.length();if(void 0===d&&l===t.Class.UNIVERSAL&&p===t.Type.BITSTRING&&(f=a.bytes(h)),void 0===d&&s.decodeBitStrings&&l===t.Class.UNIVERSAL&&p===t.Type.BITSTRING&&h>1){var v=a.read,y=o,b=0;if(p===t.Type.BITSTRING&&(n(a,o,1),b=a.getByte(),o--),0===b)try{u=a.length();var x=e(a,o,i+1,{verbose:s.verbose,strict:!0,decodeBitStrings:!0}),w=u-a.length();o-=w,p==t.Type.BITSTRING&&w++;var k=x.tagClass;w!==h||k!==t.Class.UNIVERSAL&&k!==t.Class.CONTEXT_SPECIFIC||(d=[x])}catch(e){}void 0===d&&(a.read=v,o=y)}if(void 0===d){if(void 0===h){if(s.strict)throw new Error("Non-constructed ASN.1 object of indefinite length.");h=o}if(p===t.Type.BMPSTRING)for(d="";h>0;h-=2)n(a,o,2),d+=String.fromCharCode(a.getInt16()),o-=2;else d=a.getBytes(h)}var S=void 0===f?null:{bitStringContents:f};return t.create(l,p,g,d,S)}(e,e.length(),0,a)},t.toDer=function(e){var n=z.util.createBuffer(),r=e.tagClass|e.type,a=z.util.createBuffer(),o=!1;if("bitStringContents"in e&&(o=!0,e.original&&(o=t.equals(e,e.original))),o)a.putBytes(e.bitStringContents);else if(e.composed){e.constructed?r|=32:a.putByte(0);for(var i=0;i<e.value.length;++i)void 0!==e.value[i]&&a.putBuffer(t.toDer(e.value[i]))}else if(e.type===t.Type.BMPSTRING)for(i=0;i<e.value.length;++i)a.putInt16(e.value.charCodeAt(i));else e.type===t.Type.INTEGER&&e.value.length>1&&(0===e.value.charCodeAt(0)&&0==(128&e.value.charCodeAt(1))||255===e.value.charCodeAt(0)&&128==(128&e.value.charCodeAt(1)))?a.putBytes(e.value.substr(1)):a.putBytes(e.value);if(n.putByte(r),a.length()<=127)n.putByte(127&a.length());else{var s=a.length(),u="";do{u+=String.fromCharCode(255&s),s>>>=8}while(s>0);for(n.putByte(128|u.length),i=u.length-1;i>=0;--i)n.putByte(u.charCodeAt(i))}return n.putBuffer(a),n},t.oidToDer=function(e){var t,n,r,a,o=e.split("."),i=z.util.createBuffer();i.putByte(40*parseInt(o[0],10)+parseInt(o[1],10));for(var s=2;s<o.length;++s){t=!0,n=[],r=parseInt(o[s],10);do{a=127&r,r>>>=7,t||(a|=128),n.push(a),t=!1}while(r>0);for(var u=n.length-1;u>=0;--u)i.putByte(n[u])}return i},t.derToOid=function(e){var t;"string"==typeof e&&(e=z.util.createBuffer(e));var n=e.getByte();t=Math.floor(n/40)+"."+n%40;for(var r=0;e.length()>0;)r<<=7,128&(n=e.getByte())?r+=127&n:(t+="."+(r+n),r=0);return t},t.utcTimeToDate=function(e){var t=new Date,n=parseInt(e.substr(0,2),10);n=n>=50?1900+n:2e3+n;var r=parseInt(e.substr(2,2),10)-1,a=parseInt(e.substr(4,2),10),o=parseInt(e.substr(6,2),10),i=parseInt(e.substr(8,2),10),s=0;if(e.length>11){var u=e.charAt(10),c=10;"+"!==u&&"-"!==u&&(s=parseInt(e.substr(10,2),10),c+=2)}if(t.setUTCFullYear(n,r,a),t.setUTCHours(o,i,s,0),c&&("+"===(u=e.charAt(c))||"-"===u)){var l=60*parseInt(e.substr(c+1,2),10)+parseInt(e.substr(c+4,2),10);l*=6e4,"+"===u?t.setTime(+t-l):t.setTime(+t+l)}return t},t.generalizedTimeToDate=function(e){var t=new Date,n=parseInt(e.substr(0,4),10),r=parseInt(e.substr(4,2),10)-1,a=parseInt(e.substr(6,2),10),o=parseInt(e.substr(8,2),10),i=parseInt(e.substr(10,2),10),s=parseInt(e.substr(12,2),10),u=0,c=0,l=!1;"Z"===e.charAt(e.length-1)&&(l=!0);var p=e.length-5,d=e.charAt(p);return"+"!==d&&"-"!==d||(c=60*parseInt(e.substr(p+1,2),10)+parseInt(e.substr(p+4,2),10),c*=6e4,"+"===d&&(c*=-1),l=!0),"."===e.charAt(14)&&(u=1e3*parseFloat(e.substr(14),10)),l?(t.setUTCFullYear(n,r,a),t.setUTCHours(o,i,s,u),t.setTime(+t+c)):(t.setFullYear(n,r,a),t.setHours(o,i,s,u)),t},t.dateToUtcTime=function(e){if("string"==typeof e)return e;var t="",n=[];n.push((""+e.getUTCFullYear()).substr(2)),n.push(""+(e.getUTCMonth()+1)),n.push(""+e.getUTCDate()),n.push(""+e.getUTCHours()),n.push(""+e.getUTCMinutes()),n.push(""+e.getUTCSeconds());for(var r=0;r<n.length;++r)n[r].length<2&&(t+="0"),t+=n[r];return t+"Z"},t.dateToGeneralizedTime=function(e){if("string"==typeof e)return e;var t="",n=[];n.push(""+e.getUTCFullYear()),n.push(""+(e.getUTCMonth()+1)),n.push(""+e.getUTCDate()),n.push(""+e.getUTCHours()),n.push(""+e.getUTCMinutes()),n.push(""+e.getUTCSeconds());for(var r=0;r<n.length;++r)n[r].length<2&&(t+="0"),t+=n[r];return t+"Z"},t.integerToDer=function(e){var t=z.util.createBuffer();if(e>=-128&&e<128)return t.putSignedInt(e,8);if(e>=-32768&&e<32768)return t.putSignedInt(e,16);if(e>=-8388608&&e<8388608)return t.putSignedInt(e,24);if(e>=-2147483648&&e<2147483648)return t.putSignedInt(e,32);var n=new Error("Integer too large; max is 32-bits.");throw n.integer=e,n},t.derToInteger=function(e){"string"==typeof e&&(e=z.util.createBuffer(e));var t=8*e.length();if(t>32)throw new Error("Integer too large; max is 32-bits.");return e.getSignedInt(t)},t.validate=function(e,n,r,a){var o=!1;if(e.tagClass!==n.tagClass&&void 0!==n.tagClass||e.type!==n.type&&void 0!==n.type)a&&(e.tagClass!==n.tagClass&&a.push("["+n.name+'] Expected tag class "'+n.tagClass+'", got "'+e.tagClass+'"'),e.type!==n.type&&a.push("["+n.name+'] Expected type "'+n.type+'", got "'+e.type+'"'));else if(e.constructed===n.constructed||void 0===n.constructed){if(o=!0,n.value&&z.util.isArray(n.value))for(var i=0,s=0;o&&s<n.value.length;++s)o=n.value[s].optional||!1,e.value[i]&&((o=t.validate(e.value[i],n.value[s],r,a))?++i:n.value[s].optional&&(o=!0)),!o&&a&&a.push("["+n.name+'] Tag class "'+n.tagClass+'", type "'+n.type+'" expected value length "'+n.value.length+'", got "'+e.value.length+'"');if(o&&r&&(n.capture&&(r[n.capture]=e.value),n.captureAsn1&&(r[n.captureAsn1]=e),n.captureBitStringContents&&"bitStringContents"in e&&(r[n.captureBitStringContents]=e.bitStringContents),n.captureBitStringValue&&"bitStringContents"in e))if(e.bitStringContents.length<2)r[n.captureBitStringValue]="";else{if(0!==e.bitStringContents.charCodeAt(0))throw new Error("captureBitStringValue only supported for zero unused bits");r[n.captureBitStringValue]=e.bitStringContents.slice(1)}}else a&&a.push("["+n.name+'] Expected constructed "'+n.constructed+'", got "'+e.constructed+'"');return o};var a=/[^\\u0000-\\u00ff]/;t.prettyPrint=function(e,n,r){var o="";r=r||2,(n=n||0)>0&&(o+="\n");for(var i="",s=0;s<n*r;++s)i+=" ";switch(o+=i+"Tag: ",e.tagClass){case t.Class.UNIVERSAL:o+="Universal:";break;case t.Class.APPLICATION:o+="Application:";break;case t.Class.CONTEXT_SPECIFIC:o+="Context-Specific:";break;case t.Class.PRIVATE:o+="Private:"}if(e.tagClass===t.Class.UNIVERSAL)switch(o+=e.type,e.type){case t.Type.NONE:o+=" (None)";break;case t.Type.BOOLEAN:o+=" (Boolean)";break;case t.Type.INTEGER:o+=" (Integer)";break;case t.Type.BITSTRING:o+=" (Bit string)";break;case t.Type.OCTETSTRING:o+=" (Octet string)";break;case t.Type.NULL:o+=" (Null)";break;case t.Type.OID:o+=" (Object Identifier)";break;case t.Type.ODESC:o+=" (Object Descriptor)";break;case t.Type.EXTERNAL:o+=" (External or Instance of)";break;case t.Type.REAL:o+=" (Real)";break;case t.Type.ENUMERATED:o+=" (Enumerated)";break;case t.Type.EMBEDDED:o+=" (Embedded PDV)";break;case t.Type.UTF8:o+=" (UTF8)";break;case t.Type.ROID:o+=" (Relative Object Identifier)";break;case t.Type.SEQUENCE:o+=" (Sequence)";break;case t.Type.SET:o+=" (Set)";break;case t.Type.PRINTABLESTRING:o+=" (Printable String)";break;case t.Type.IA5String:o+=" (IA5String (ASCII))";break;case t.Type.UTCTIME:o+=" (UTC time)";break;case t.Type.GENERALIZEDTIME:o+=" (Generalized time)";break;case t.Type.BMPSTRING:o+=" (BMP String)"}else o+=e.type;if(o+="\n",o+=i+"Constructed: "+e.constructed+"\n",e.composed){var u=0,c="";for(s=0;s<e.value.length;++s)void 0!==e.value[s]&&(u+=1,c+=t.prettyPrint(e.value[s],n+1,r),s+1<e.value.length&&(c+=","));o+=i+"Sub values: "+u+c}else{if(o+=i+"Value: ",e.type===t.Type.OID){var l=t.derToOid(e.value);o+=l,z.pki&&z.pki.oids&&l in z.pki.oids&&(o+=" ("+z.pki.oids[l]+") ")}if(e.type===t.Type.INTEGER)try{o+=t.derToInteger(e.value)}catch(t){o+="0x"+z.util.bytesToHex(e.value)}else if(e.type===t.Type.BITSTRING){if(e.value.length>1?o+="0x"+z.util.bytesToHex(e.value.slice(1)):o+="(none)",e.value.length>0){var p=e.value.charCodeAt(0);1==p?o+=" (1 unused bit shown)":p>1&&(o+=" ("+p+" unused bits shown)")}}else e.type===t.Type.OCTETSTRING?(a.test(e.value)||(o+="("+e.value+") "),o+="0x"+z.util.bytesToHex(e.value)):e.type===t.Type.UTF8?o+=z.util.decodeUtf8(e.value):e.type===t.Type.PRINTABLESTRING||e.type===t.Type.IA5String?o+=e.value:a.test(e.value)?o+="0x"+z.util.bytesToHex(e.value):0===e.value.length?o+="[null]":o+=e.value}return o}})),z.md=z.md||{},z.md.algorithms=z.md.algorithms||{},w((function(e){(e.exports=z.hmac=z.hmac||{}).create=function(){var e=null,t=null,n=null,r=null,a={start:function(a,o){if(null!==a)if("string"==typeof a){if(!((a=a.toLowerCase())in z.md.algorithms))throw new Error('Unknown hash algorithm "'+a+'"');t=z.md.algorithms[a].create()}else t=a;if(null===o)o=e;else{if("string"==typeof o)o=z.util.createBuffer(o);else if(z.util.isArray(o)){var i=o;o=z.util.createBuffer();for(var s=0;s<i.length;++s)o.putByte(i[s])}var u=o.length();for(u>t.blockLength&&(t.start(),t.update(o.bytes()),o=t.digest()),n=z.util.createBuffer(),r=z.util.createBuffer(),u=o.length(),s=0;s<u;++s)i=o.at(s),n.putByte(54^i),r.putByte(92^i);if(u<t.blockLength)for(i=t.blockLength-u,s=0;s<i;++s)n.putByte(54),r.putByte(92);e=o,n=n.bytes(),r=r.bytes()}t.start(),t.update(n)},update:function(e){t.update(e)},getMac:function(){var e=t.digest().bytes();return t.start(),t.update(r),t.update(e),t.digest()}};return a.digest=a.getMac,a}})),w((function(e){var t=e.exports=z.md5=z.md5||{};z.md.md5=z.md.algorithms.md5=t,t.create=function(){i||function(){n=String.fromCharCode(128),n+=z.util.fillString(String.fromCharCode(0),64),r=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12,5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2,0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9],a=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],o=new Array(64);for(var e=0;e<64;++e)o[e]=Math.floor(4294967296*Math.abs(Math.sin(e+1)));i=!0}();var e=null,t=z.util.createBuffer(),u=new Array(16),c={algorithm:"md5",blockLength:64,digestLength:16,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){c.messageLength=0,c.fullMessageLength=c.messageLength64=[];for(var n=c.messageLengthSize/4,r=0;r<n;++r)c.fullMessageLength.push(0);return t=z.util.createBuffer(),e={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878},c}};return c.start(),c.update=function(n,r){"utf8"===r&&(n=z.util.encodeUtf8(n));var a=n.length;c.messageLength+=a,a=[a/4294967296>>>0,a>>>0];for(var o=c.fullMessageLength.length-1;o>=0;--o)c.fullMessageLength[o]+=a[1],a[1]=a[0]+(c.fullMessageLength[o]/4294967296>>>0),c.fullMessageLength[o]=c.fullMessageLength[o]>>>0,a[0]=a[1]/4294967296>>>0;return t.putBytes(n),s(e,u,t),(t.read>2048||0===t.length())&&t.compact(),c},c.digest=function(){var r=z.util.createBuffer();r.putBytes(t.bytes());var a=c.fullMessageLength[c.fullMessageLength.length-1]+c.messageLengthSize&c.blockLength-1;r.putBytes(n.substr(0,c.blockLength-a));for(var o,i=0,l=c.fullMessageLength.length-1;l>=0;--l)i=(o=8*c.fullMessageLength[l]+i)/4294967296>>>0,r.putInt32Le(o>>>0);var p={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3};s(p,u,r);var d=z.util.createBuffer();return d.putInt32Le(p.h0),d.putInt32Le(p.h1),d.putInt32Le(p.h2),d.putInt32Le(p.h3),d},c};var n=null,r=null,a=null,o=null,i=!1;function s(e,t,n){for(var i,s,u,c,l,p,d,f=n.length();f>=64;){for(s=e.h0,u=e.h1,c=e.h2,l=e.h3,d=0;d<16;++d)t[d]=n.getInt32Le(),i=s+(l^u&(c^l))+o[d]+t[d],s=l,l=c,c=u,u+=i<<(p=a[d])|i>>>32-p;for(;d<32;++d)i=s+(c^l&(u^c))+o[d]+t[r[d]],s=l,l=c,c=u,u+=i<<(p=a[d])|i>>>32-p;for(;d<48;++d)i=s+(u^c^l)+o[d]+t[r[d]],s=l,l=c,c=u,u+=i<<(p=a[d])|i>>>32-p;for(;d<64;++d)i=s+(c^(u|~l))+o[d]+t[r[d]],s=l,l=c,c=u,u+=i<<(p=a[d])|i>>>32-p;e.h0=e.h0+s|0,e.h1=e.h1+u|0,e.h2=e.h2+c|0,e.h3=e.h3+l|0,f-=64}}})),w((function(e){var t=e.exports=z.pem=z.pem||{};function n(e){for(var t=e.name+": ",n=[],r=function(e,t){return" "+t},a=0;a<e.values.length;++a)n.push(e.values[a].replace(/^(\S+\r\n)/,r));t+=n.join(",")+"\r\n";var o=0,i=-1;for(a=0;a<t.length;++a,++o)if(o>65&&-1!==i){var s=t[i];","===s?(++i,t=t.substr(0,i)+"\r\n "+t.substr(i)):t=t.substr(0,i)+"\r\n"+s+t.substr(i+1),o=a-i-1,i=-1,++a}else" "!==t[a]&&"\t"!==t[a]&&","!==t[a]||(i=a);return t}function r(e){return e.replace(/^\s+/,"")}t.encode=function(e,t){t=t||{};var r,a="-----BEGIN "+e.type+"-----\r\n";if(e.procType&&(a+=n(r={name:"Proc-Type",values:[String(e.procType.version),e.procType.type]})),e.contentDomain&&(a+=n(r={name:"Content-Domain",values:[e.contentDomain]})),e.dekInfo&&(r={name:"DEK-Info",values:[e.dekInfo.algorithm]},e.dekInfo.parameters&&r.values.push(e.dekInfo.parameters),a+=n(r)),e.headers)for(var o=0;o<e.headers.length;++o)a+=n(e.headers[o]);return e.procType&&(a+="\r\n"),(a+=z.util.encode64(e.body,t.maxline||64)+"\r\n")+"-----END "+e.type+"-----\r\n"},t.decode=function(e){for(var t,n=[],a=/\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g,o=/([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/,i=/\r?\n/;t=a.exec(e);){var s={type:t[1],procType:null,contentDomain:null,dekInfo:null,headers:[],body:z.util.decode64(t[3])};if(n.push(s),t[2]){for(var u=t[2].split(i),c=0;t&&c<u.length;){for(var l=u[c].replace(/\s+$/,""),p=c+1;p<u.length;++p){var d=u[p];if(!/\s/.test(d[0]))break;l+=d,c=p}if(t=l.match(o)){for(var f={name:t[1],values:[]},h=t[2].split(","),m=0;m<h.length;++m)f.values.push(r(h[m]));if(s.procType)if(s.contentDomain||"Content-Domain"!==f.name)if(s.dekInfo||"DEK-Info"!==f.name)s.headers.push(f);else{if(0===f.values.length)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must have at least one subfield.');s.dekInfo={algorithm:h[0],parameters:h[1]||null}}else s.contentDomain=h[0]||"";else{if("Proc-Type"!==f.name)throw new Error('Invalid PEM formatted message. The first encapsulated header must be "Proc-Type".');if(2!==f.values.length)throw new Error('Invalid PEM formatted message. The "Proc-Type" header must have two subfields.');s.procType={version:h[0],type:h[1]}}}++c}if("ENCRYPTED"===s.procType&&!s.dekInfo)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must be present if "Proc-Type" is "ENCRYPTED".')}}if(0===n.length)throw new Error("Invalid PEM formatted message.");return n}})),z.des=z.des||{},z.des.startEncrypting=function(e,t,n,r){var a=he({key:e,output:n,decrypt:!1,mode:r||(null===t?"ECB":"CBC")});return a.start(t),a},z.des.createEncryptionCipher=function(e,t){return he({key:e,output:null,decrypt:!1,mode:t})},z.des.startDecrypting=function(e,t,n,r){var a=he({key:e,output:n,decrypt:!0,mode:r||(null===t?"ECB":"CBC")});return a.start(t),a},z.des.createDecryptionCipher=function(e,t){return he({key:e,output:null,decrypt:!0,mode:t})},z.des.Algorithm=function(e,t){var n=this;n.name=e,n.mode=new t({blockSize:8,cipher:{encrypt:function(e,t){return fe(n._keys,e,t,!1)},decrypt:function(e,t){return fe(n._keys,e,t,!0)}}}),n._init=!1},z.des.Algorithm.prototype.initialize=function(e){if(!this._init){var t=z.util.createBuffer(e.key);if(0===this.name.indexOf("3DES")&&24!==t.length())throw new Error("Invalid Triple-DES key size: "+8*t.length());this._keys=function(e){for(var t,n=[0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964],r=[0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697],a=[0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272],o=[0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144],i=[0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256],s=[0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488],u=[0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746],c=[0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568],l=[0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578],p=[0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488],d=[0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800],f=[0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744],h=[0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128],m=[0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261],g=e.length()>8?3:1,v=[],y=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],b=0,x=0;x<g;x++){var w=e.getInt32(),k=e.getInt32();w^=(t=252645135&(w>>>4^k))<<4,w^=t=65535&((k^=t)>>>-16^w),w^=(t=858993459&(w>>>2^(k^=t<<-16)))<<2,w^=t=65535&((k^=t)>>>-16^w),w^=(t=1431655765&(w>>>1^(k^=t<<-16)))<<1,w^=t=16711935&((k^=t)>>>8^w),t=(w^=(t=1431655765&(w>>>1^(k^=t<<8)))<<1)<<8|(k^=t)>>>20&240,w=k<<24|k<<8&16711680|k>>>8&65280|k>>>24&240,k=t;for(var S=0;S<y.length;++S){y[S]?(w=w<<2|w>>>26,k=k<<2|k>>>26):(w=w<<1|w>>>27,k=k<<1|k>>>27);var E=n[(w&=-15)>>>28]|r[w>>>24&15]|a[w>>>20&15]|o[w>>>16&15]|i[w>>>12&15]|s[w>>>8&15]|u[w>>>4&15],I=c[(k&=-15)>>>28]|l[k>>>24&15]|p[k>>>20&15]|d[k>>>16&15]|f[k>>>12&15]|h[k>>>8&15]|m[k>>>4&15];t=65535&(I>>>16^E),v[b++]=E^t,v[b++]=I^t<<16}}return v}(t),this._init=!0}},ae("DES-ECB",z.cipher.modes.ecb),ae("DES-CBC",z.cipher.modes.cbc),ae("DES-CFB",z.cipher.modes.cfb),ae("DES-OFB",z.cipher.modes.ofb),ae("DES-CTR",z.cipher.modes.ctr),ae("3DES-ECB",z.cipher.modes.ecb),ae("3DES-CBC",z.cipher.modes.cbc),ae("3DES-CFB",z.cipher.modes.cfb),ae("3DES-OFB",z.cipher.modes.ofb),ae("3DES-CTR",z.cipher.modes.ctr);var oe=[16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756],ie=[-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344],se=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584],ue=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],ce=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],le=[536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312],pe=[2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],de=[268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696];function fe(e,t,n,r){var a,o,i=32===e.length?3:9;a=3===i?r?[30,-2,-2]:[0,32,2]:r?[94,62,-2,32,64,2,30,-2,-2]:[0,32,2,62,30,-2,64,96,2];var s=t[0],u=t[1];s^=(o=252645135&(s>>>4^u))<<4,s^=(o=65535&(s>>>16^(u^=o)))<<16,s^=o=858993459&((u^=o)>>>2^s),s^=o=16711935&((u^=o<<2)>>>8^s),s=(s^=(o=1431655765&(s>>>1^(u^=o<<8)))<<1)<<1|s>>>31,u=(u^=o)<<1|u>>>31;for(var c=0;c<i;c+=3){for(var l=a[c+1],p=a[c+2],d=a[c];d!=l;d+=p){var f=u^e[d],h=(u>>>4|u<<28)^e[d+1];o=s,s=u,u=o^(ie[f>>>24&63]|ue[f>>>16&63]|le[f>>>8&63]|de[63&f]|oe[h>>>24&63]|se[h>>>16&63]|ce[h>>>8&63]|pe[63&h])}o=s,s=u,u=o}u=u>>>1|u<<31,u^=o=1431655765&((s=s>>>1|s<<31)>>>1^u),u^=(o=16711935&(u>>>8^(s^=o<<1)))<<8,u^=(o=858993459&(u>>>2^(s^=o)))<<2,u^=o=65535&((s^=o)>>>16^u),u^=o=252645135&((s^=o<<16)>>>4^u),s^=o<<4,n[0]=s,n[1]=u}function he(e){var t,n="DES-"+((e=e||{}).mode||"CBC").toUpperCase(),r=(t=e.decrypt?z.cipher.createDecipher(n,e.key):z.cipher.createCipher(n,e.key)).start;return t.start=function(e,n){var a=null;n instanceof z.util.ByteBuffer&&(a=n,n={}),(n=n||{}).output=a,n.iv=e,r.call(t,n)},t}var me,ge=z.pkcs5=z.pkcs5||{};z.util.isNodejs&&!z.options.usePureJavaScript&&(me=t),z.pbkdf2=ge.pbkdf2=function(e,t,n,r,a,o){if("function"==typeof a&&(o=a,a=null),z.util.isNodejs&&!z.options.usePureJavaScript&&me.pbkdf2&&(null===a||"object"!=typeof a)&&(me.pbkdf2Sync.length>4||!a||"sha1"===a))return"string"!=typeof a&&(a="sha1"),e=Buffer.from(e,"binary"),t=Buffer.from(t,"binary"),o?4===me.pbkdf2Sync.length?me.pbkdf2(e,t,n,r,(function(e,t){if(e)return o(e);o(null,t.toString("binary"))})):me.pbkdf2(e,t,n,r,a,(function(e,t){if(e)return o(e);o(null,t.toString("binary"))})):4===me.pbkdf2Sync.length?me.pbkdf2Sync(e,t,n,r).toString("binary"):me.pbkdf2Sync(e,t,n,r,a).toString("binary");if(null==a&&(a="sha1"),"string"==typeof a){if(!(a in z.md.algorithms))throw new Error("Unknown hash algorithm: "+a);a=z.md[a].create()}var i=a.digestLength;if(r>4294967295*i){var s=new Error("Derived key is too long.");if(o)return o(s);throw s}var u=Math.ceil(r/i),c=r-(u-1)*i,l=z.hmac.create();l.start(a,e);var p,d,f,h="";if(!o){for(var m=1;m<=u;++m){l.start(null,null),l.update(t),l.update(z.util.int32ToBytes(m)),p=f=l.digest().getBytes();for(var g=2;g<=n;++g)l.start(null,null),l.update(f),d=l.digest().getBytes(),p=z.util.xorBytes(p,d,i),f=d;h+=m<u?p:p.substr(0,c)}return h}function v(){if(m>u)return o(null,h);l.start(null,null),l.update(t),l.update(z.util.int32ToBytes(m)),p=f=l.digest().getBytes(),g=2,y()}function y(){if(g<=n)return l.start(null,null),l.update(f),d=l.digest().getBytes(),p=z.util.xorBytes(p,d,i),f=d,++g,z.util.setImmediate(y);h+=m<u?p:p.substr(0,c),++m,v()}m=1,v()},w((function(e){var t=e.exports=z.sha256=z.sha256||{};z.md.sha256=z.md.algorithms.sha256=t,t.create=function(){r||(n=String.fromCharCode(128),n+=z.util.fillString(String.fromCharCode(0),64),a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],r=!0);var e=null,t=z.util.createBuffer(),i=new Array(64),s={algorithm:"sha256",blockLength:64,digestLength:32,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){s.messageLength=0,s.fullMessageLength=s.messageLength64=[];for(var n=s.messageLengthSize/4,r=0;r<n;++r)s.fullMessageLength.push(0);return t=z.util.createBuffer(),e={h0:1779033703,h1:3144134277,h2:1013904242,h3:2773480762,h4:1359893119,h5:2600822924,h6:528734635,h7:1541459225},s}};return s.start(),s.update=function(n,r){"utf8"===r&&(n=z.util.encodeUtf8(n));var a=n.length;s.messageLength+=a,a=[a/4294967296>>>0,a>>>0];for(var u=s.fullMessageLength.length-1;u>=0;--u)s.fullMessageLength[u]+=a[1],a[1]=a[0]+(s.fullMessageLength[u]/4294967296>>>0),s.fullMessageLength[u]=s.fullMessageLength[u]>>>0,a[0]=a[1]/4294967296>>>0;return t.putBytes(n),o(e,i,t),(t.read>2048||0===t.length())&&t.compact(),s},s.digest=function(){var r=z.util.createBuffer();r.putBytes(t.bytes());var a,u=s.fullMessageLength[s.fullMessageLength.length-1]+s.messageLengthSize&s.blockLength-1;r.putBytes(n.substr(0,s.blockLength-u));for(var c=8*s.fullMessageLength[0],l=0;l<s.fullMessageLength.length-1;++l)c+=(a=8*s.fullMessageLength[l+1])/4294967296>>>0,r.putInt32(c>>>0),c=a>>>0;r.putInt32(c);var p={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4,h5:e.h5,h6:e.h6,h7:e.h7};o(p,i,r);var d=z.util.createBuffer();return d.putInt32(p.h0),d.putInt32(p.h1),d.putInt32(p.h2),d.putInt32(p.h3),d.putInt32(p.h4),d.putInt32(p.h5),d.putInt32(p.h6),d.putInt32(p.h7),d},s};var n=null,r=!1,a=null;function o(e,t,n){for(var r,o,i,s,u,c,l,p,d,f,h,m,g,v=n.length();v>=64;){for(u=0;u<16;++u)t[u]=n.getInt32();for(;u<64;++u)r=((r=t[u-2])>>>17|r<<15)^(r>>>19|r<<13)^r>>>10,o=((o=t[u-15])>>>7|o<<25)^(o>>>18|o<<14)^o>>>3,t[u]=r+t[u-7]+o+t[u-16]|0;for(c=e.h0,l=e.h1,p=e.h2,d=e.h3,f=e.h4,h=e.h5,m=e.h6,g=e.h7,u=0;u<64;++u)i=(c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),s=c&l|p&(c^l),r=g+((f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7))+(m^f&(h^m))+a[u]+t[u],g=m,m=h,h=f,f=d+r>>>0,d=p,p=l,l=c,c=r+(o=i+s)>>>0;e.h0=e.h0+c|0,e.h1=e.h1+l|0,e.h2=e.h2+p|0,e.h3=e.h3+d|0,e.h4=e.h4+f|0,e.h5=e.h5+h|0,e.h6=e.h6+m|0,e.h7=e.h7+g|0,v-=64}}})),w((function(e){var n=null;!z.util.isNodejs||z.options.usePureJavaScript||process.versions["node-webkit"]||(n=t),(e.exports=z.prng=z.prng||{}).create=function(e){for(var t={plugin:e,key:null,seed:null,time:null,reseeds:0,generated:0,keyBytes:""},r=e.md,a=new Array(32),o=0;o<32;++o)a[o]=r.create();function i(){if(t.pools[0].messageLength>=32)return s();var e=32-t.pools[0].messageLength<<5;t.collect(t.seedFileSync(e)),s()}function s(){t.reseeds=4294967295===t.reseeds?0:t.reseeds+1;var e=t.plugin.md.create();e.update(t.keyBytes);for(var n=1,r=0;r<32;++r)t.reseeds%n==0&&(e.update(t.pools[r].digest().getBytes()),t.pools[r].start()),n<<=1;t.keyBytes=e.digest().getBytes(),e.start(),e.update(t.keyBytes);var a=e.digest().getBytes();t.key=t.plugin.formatKey(t.keyBytes),t.seed=t.plugin.formatSeed(a),t.generated=0}function u(e){var t=null,n=z.util.globalScope,r=n.crypto||n.msCrypto;r&&r.getRandomValues&&(t=function(e){return r.getRandomValues(e)});var a=z.util.createBuffer();if(t)for(;a.length()<e;){var o=Math.max(1,Math.min(e-a.length(),65536)/4),i=new Uint32Array(Math.floor(o));try{t(i);for(var s=0;s<i.length;++s)a.putInt32(i[s])}catch(e){if(!("undefined"!=typeof QuotaExceededError&&e instanceof QuotaExceededError))throw e}}if(a.length()<e)for(var u,c,l,p=Math.floor(65536*Math.random());a.length()<e;)for(c=16807*(65535&p),c+=(32767&(u=16807*(p>>16)))<<16,p=4294967295&(c=(2147483647&(c+=u>>15))+(c>>31)),s=0;s<3;++s)l=p>>>(s<<3),l^=Math.floor(256*Math.random()),a.putByte(String.fromCharCode(255&l));return a.getBytes(e)}return t.pools=a,t.pool=0,t.generate=function(e,n){if(!n)return t.generateSync(e);var r=t.plugin.cipher,a=t.plugin.increment,o=t.plugin.formatKey,i=t.plugin.formatSeed,u=z.util.createBuffer();t.key=null,function c(l){if(l)return n(l);if(u.length()>=e)return n(null,u.getBytes(e));if(t.generated>1048575&&(t.key=null),null===t.key)return z.util.nextTick((function(){!function(e){if(t.pools[0].messageLength>=32)return s(),e();var n=32-t.pools[0].messageLength<<5;t.seedFile(n,(function(n,r){if(n)return e(n);t.collect(r),s(),e()}))}(c)}));var p=r(t.key,t.seed);t.generated+=p.length,u.putBytes(p),t.key=o(r(t.key,a(t.seed))),t.seed=i(r(t.key,t.seed)),z.util.setImmediate(c)}()},t.generateSync=function(e){var n=t.plugin.cipher,r=t.plugin.increment,a=t.plugin.formatKey,o=t.plugin.formatSeed;t.key=null;for(var s=z.util.createBuffer();s.length()<e;){t.generated>1048575&&(t.key=null),null===t.key&&i();var u=n(t.key,t.seed);t.generated+=u.length,s.putBytes(u),t.key=a(n(t.key,r(t.seed))),t.seed=o(n(t.key,t.seed))}return s.getBytes(e)},n?(t.seedFile=function(e,t){n.randomBytes(e,(function(e,n){if(e)return t(e);t(null,n.toString())}))},t.seedFileSync=function(e){return n.randomBytes(e).toString()}):(t.seedFile=function(e,t){try{t(null,u(e))}catch(e){t(e)}},t.seedFileSync=u),t.collect=function(e){for(var n=e.length,r=0;r<n;++r)t.pools[t.pool].update(e.substr(r,1)),t.pool=31===t.pool?0:t.pool+1},t.collectInt=function(e,n){for(var r="",a=0;a<n;a+=8)r+=String.fromCharCode(e>>a&255);t.collect(r)},t.registerWorker=function(e){e===self?t.seedFile=function(e,t){self.addEventListener("message",(function e(n){var r=n.data;r.forge&&r.forge.prng&&(self.removeEventListener("message",e),t(r.forge.prng.err,r.forge.prng.bytes))})),self.postMessage({forge:{prng:{needed:e}}})}:e.addEventListener("message",(function(n){var r=n.data;r.forge&&r.forge.prng&&t.seedFile(r.forge.prng.needed,(function(t,n){e.postMessage({forge:{prng:{err:t,bytes:n}}})}))}))},t}})),w((function(e){z.random&&z.random.getBytes?e.exports=z.random:function(t){var n={},r=new Array(4),a=z.util.createBuffer();function o(){var e=z.prng.create(n);return e.getBytes=function(t,n){return e.generate(t,n)},e.getBytesSync=function(t){return e.generate(t)},e}n.formatKey=function(e){var t=z.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),z.aes._expandKey(e,!1)},n.formatSeed=function(e){var t=z.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),e},n.cipher=function(e,t){return z.aes._updateBlock(e,t,r,!1),a.putInt32(r[0]),a.putInt32(r[1]),a.putInt32(r[2]),a.putInt32(r[3]),a.getBytes()},n.increment=function(e){return++e[3],e},n.md=z.md.sha256;var i=o(),s=null,u=z.util.globalScope,c=u.crypto||u.msCrypto;if(c&&c.getRandomValues&&(s=function(e){return c.getRandomValues(e)}),!z.util.isNodejs&&!s){if(i.collectInt(+new Date,32),"undefined"!=typeof navigator){var l="";for(var p in navigator)try{"string"==typeof navigator[p]&&(l+=navigator[p])}catch(e){}i.collect(l),l=null}t&&(t().mousemove((function(e){i.collectInt(e.clientX,16),i.collectInt(e.clientY,16)})),t().keypress((function(e){i.collectInt(e.charCode,8)})))}if(z.random)for(var p in i)z.random[p]=i[p];else z.random=i;z.random.createInstance=o,e.exports=z.random}("undefined"!=typeof jQuery?jQuery:null)}));var ve=[217,120,249,196,25,221,181,237,40,233,253,121,74,160,216,157,198,126,55,131,43,118,83,142,98,76,100,136,68,139,251,162,23,154,89,245,135,179,79,19,97,69,109,141,9,129,125,50,189,143,64,235,134,183,123,11,240,149,33,34,92,107,78,130,84,214,101,147,206,96,178,28,115,86,192,20,167,140,241,220,18,117,202,31,59,190,228,209,66,61,212,48,163,60,182,38,111,191,14,218,70,105,7,87,39,242,29,155,188,148,67,3,248,17,199,246,144,239,62,231,6,195,213,47,200,102,30,215,8,232,234,222,128,82,238,247,132,170,114,172,53,77,106,42,150,26,210,113,90,21,73,116,75,159,208,94,4,24,164,236,194,224,65,110,15,81,203,204,36,145,175,80,161,244,112,57,153,124,58,133,35,184,180,122,252,2,54,91,37,85,151,49,45,93,250,152,227,138,146,174,5,223,41,16,103,108,186,201,211,0,230,207,225,158,168,44,99,22,1,63,88,226,137,169,13,56,52,27,171,51,255,176,187,72,12,95,185,177,205,46,197,243,219,71,229,165,156,119,10,166,32,104,254,127,193,173],ye=[1,2,3,5],be=function(e,t){return e<<t&65535|(65535&e)>>16-t},xe=function(e,t){return(65535&e)>>t|e<<16-t&65535};z.rc2=z.rc2||{},z.rc2.expandKey=function(e,t){"string"==typeof e&&(e=z.util.createBuffer(e)),t=t||128;var n,r=e,a=e.length(),o=t,i=Math.ceil(o/8),s=255>>(7&o);for(n=a;n<128;n++)r.putByte(ve[r.at(n-1)+r.at(n-a)&255]);for(r.setAt(128-i,ve[r.at(128-i)&s]),n=127-i;n>=0;n--)r.setAt(n,ve[r.at(n+1)^r.at(n+i)]);return r};var we,ke=function(e,t,n){var r,a,o,i,s=!1,u=null,c=null,l=null,p=[];for(e=z.rc2.expandKey(e,t),o=0;o<64;o++)p.push(e.getInt16Le());n?(r=function(e){for(o=0;o<4;o++)e[o]+=p[i]+(e[(o+3)%4]&e[(o+2)%4])+(~e[(o+3)%4]&e[(o+1)%4]),e[o]=be(e[o],ye[o]),i++},a=function(e){for(o=0;o<4;o++)e[o]+=p[63&e[(o+3)%4]]}):(r=function(e){for(o=3;o>=0;o--)e[o]=xe(e[o],ye[o]),e[o]-=p[i]+(e[(o+3)%4]&e[(o+2)%4])+(~e[(o+3)%4]&e[(o+1)%4]),i--},a=function(e){for(o=3;o>=0;o--)e[o]-=p[63&e[(o+3)%4]]});var d=function(e){var t=[];for(o=0;o<4;o++){var r=u.getInt16Le();null!==l&&(n?r^=l.getInt16Le():l.putInt16Le(r)),t.push(65535&r)}i=n?0:63;for(var a=0;a<e.length;a++)for(var s=0;s<e[a][0];s++)e[a][1](t);for(o=0;o<4;o++)null!==l&&(n?l.putInt16Le(t[o]):t[o]^=l.getInt16Le()),c.putInt16Le(t[o])},f=null;return f={start:function(e,t){e&&"string"==typeof e&&(e=z.util.createBuffer(e)),s=!1,u=z.util.createBuffer(),c=t||new z.util.createBuffer,l=e,f.output=c},update:function(e){for(s||u.putBuffer(e);u.length()>=8;)d([[5,r],[1,a],[6,r],[1,a],[5,r]])},finish:function(e){var t=!0;if(n)if(e)t=e(8,u,!n);else{var r=8===u.length()?8:8-u.length();u.fillWithByte(r,r)}if(t&&(s=!0,f.update()),!n&&(t=0===u.length()))if(e)t=e(8,c,!n);else{var a=c.length(),o=c.at(a-1);o>a?t=!1:c.truncate(o)}return t}}};function Se(e,t,n){this.data=[],null!=e&&("number"==typeof e?this.fromNumber(e,t,n):null==t&&"string"!=typeof e?this.fromString(e,256):this.fromString(e,t))}function Ee(){return new Se(null)}function Ie(e,t,n,r,a,o){for(var i=16383&t,s=t>>14;--o>=0;){var u=16383&this.data[e],c=this.data[e++]>>14,l=s*u+c*i;a=((u=i*u+((16383&l)<<14)+n.data[r]+a)>>28)+(l>>14)+s*c,n.data[r++]=268435455&u}return a}z.rc2.startEncrypting=function(e,t,n){var r=z.rc2.createEncryptionCipher(e,128);return r.start(t,n),r},z.rc2.createEncryptionCipher=function(e,t){return ke(e,t,!0)},z.rc2.startDecrypting=function(e,t,n){var r=z.rc2.createDecryptionCipher(e,128);return r.start(t,n),r},z.rc2.createDecryptionCipher=function(e,t){return ke(e,t,!1)},z.jsbn=z.jsbn||{},z.jsbn.BigInteger=Se,"undefined"==typeof navigator?(Se.prototype.am=Ie,we=28):"Microsoft Internet Explorer"==navigator.appName?(Se.prototype.am=function(e,t,n,r,a,o){for(var i=32767&t,s=t>>15;--o>=0;){var u=32767&this.data[e],c=this.data[e++]>>15,l=s*u+c*i;a=((u=i*u+((32767&l)<<15)+n.data[r]+(1073741823&a))>>>30)+(l>>>15)+s*c+(a>>>30),n.data[r++]=1073741823&u}return a},we=30):"Netscape"!=navigator.appName?(Se.prototype.am=function(e,t,n,r,a,o){for(;--o>=0;){var i=t*this.data[e++]+n.data[r]+a;a=Math.floor(i/67108864),n.data[r++]=67108863&i}return a},we=26):(Se.prototype.am=Ie,we=28),Se.prototype.DB=we,Se.prototype.DM=(1<<we)-1,Se.prototype.DV=1<<we,Se.prototype.FV=Math.pow(2,52),Se.prototype.F1=52-we,Se.prototype.F2=2*we-52;var Ce,Te,_e="0123456789abcdefghijklmnopqrstuvwxyz",Ne=new Array;for(Ce="0".charCodeAt(0),Te=0;Te<=9;++Te)Ne[Ce++]=Te;for(Ce="a".charCodeAt(0),Te=10;Te<36;++Te)Ne[Ce++]=Te;for(Ce="A".charCodeAt(0),Te=10;Te<36;++Te)Ne[Ce++]=Te;function Ae(e){return _e.charAt(e)}function Re(e,t){var n=Ne[e.charCodeAt(t)];return null==n?-1:n}function Oe(e){var t=Ee();return t.fromInt(e),t}function Be(e){var t,n=1;return 0!=(t=e>>>16)&&(e=t,n+=16),0!=(t=e>>8)&&(e=t,n+=8),0!=(t=e>>4)&&(e=t,n+=4),0!=(t=e>>2)&&(e=t,n+=2),0!=(t=e>>1)&&(e=t,n+=1),n}function De(e){this.m=e}function Me(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function Fe(e,t){return e&t}function Pe(e,t){return e|t}function Le(e,t){return e^t}function Ue(e,t){return e&~t}function Ve(e){if(0==e)return-1;var t=0;return 0==(65535&e)&&(e>>=16,t+=16),0==(255&e)&&(e>>=8,t+=8),0==(15&e)&&(e>>=4,t+=4),0==(3&e)&&(e>>=2,t+=2),0==(1&e)&&++t,t}function ze(e){for(var t=0;0!=e;)e&=e-1,++t;return t}function je(){}function We(e){return e}function He(e){this.r2=Ee(),this.q3=Ee(),Se.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}De.prototype.convert=function(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e},De.prototype.revert=function(e){return e},De.prototype.reduce=function(e){e.divRemTo(this.m,null,e)},De.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n),this.reduce(n)},De.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},Me.prototype.convert=function(e){var t=Ee();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(Se.ZERO)>0&&this.m.subTo(t,t),t},Me.prototype.revert=function(e){var t=Ee();return e.copyTo(t),this.reduce(t),t},Me.prototype.reduce=function(e){for(;e.t<=this.mt2;)e.data[e.t++]=0;for(var t=0;t<this.m.t;++t){var n=32767&e.data[t],r=n*this.mpl+((n*this.mph+(e.data[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(n=t+this.m.t,e.data[n]+=this.m.am(0,r,e,t,0,this.m.t);e.data[n]>=e.DV;)e.data[n]-=e.DV,e.data[++n]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},Me.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n),this.reduce(n)},Me.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},Se.prototype.copyTo=function(e){for(var t=this.t-1;t>=0;--t)e.data[t]=this.data[t];e.t=this.t,e.s=this.s},Se.prototype.fromInt=function(e){this.t=1,this.s=e<0?-1:0,e>0?this.data[0]=e:e<-1?this.data[0]=e+this.DV:this.t=0},Se.prototype.fromString=function(e,t){var n;if(16==t)n=4;else if(8==t)n=3;else if(256==t)n=8;else if(2==t)n=1;else if(32==t)n=5;else{if(4!=t)return void this.fromRadix(e,t);n=2}this.t=0,this.s=0;for(var r=e.length,a=!1,o=0;--r>=0;){var i=8==n?255&e[r]:Re(e,r);i<0?"-"==e.charAt(r)&&(a=!0):(a=!1,0==o?this.data[this.t++]=i:o+n>this.DB?(this.data[this.t-1]|=(i&(1<<this.DB-o)-1)<<o,this.data[this.t++]=i>>this.DB-o):this.data[this.t-1]|=i<<o,(o+=n)>=this.DB&&(o-=this.DB))}8==n&&0!=(128&e[0])&&(this.s=-1,o>0&&(this.data[this.t-1]|=(1<<this.DB-o)-1<<o)),this.clamp(),a&&Se.ZERO.subTo(this,this)},Se.prototype.clamp=function(){for(var e=this.s&this.DM;this.t>0&&this.data[this.t-1]==e;)--this.t},Se.prototype.dlShiftTo=function(e,t){var n;for(n=this.t-1;n>=0;--n)t.data[n+e]=this.data[n];for(n=e-1;n>=0;--n)t.data[n]=0;t.t=this.t+e,t.s=this.s},Se.prototype.drShiftTo=function(e,t){for(var n=e;n<this.t;++n)t.data[n-e]=this.data[n];t.t=Math.max(this.t-e,0),t.s=this.s},Se.prototype.lShiftTo=function(e,t){var n,r=e%this.DB,a=this.DB-r,o=(1<<a)-1,i=Math.floor(e/this.DB),s=this.s<<r&this.DM;for(n=this.t-1;n>=0;--n)t.data[n+i+1]=this.data[n]>>a|s,s=(this.data[n]&o)<<r;for(n=i-1;n>=0;--n)t.data[n]=0;t.data[i]=s,t.t=this.t+i+1,t.s=this.s,t.clamp()},Se.prototype.rShiftTo=function(e,t){t.s=this.s;var n=Math.floor(e/this.DB);if(n>=this.t)t.t=0;else{var r=e%this.DB,a=this.DB-r,o=(1<<r)-1;t.data[0]=this.data[n]>>r;for(var i=n+1;i<this.t;++i)t.data[i-n-1]|=(this.data[i]&o)<<a,t.data[i-n]=this.data[i]>>r;r>0&&(t.data[this.t-n-1]|=(this.s&o)<<a),t.t=this.t-n,t.clamp()}},Se.prototype.subTo=function(e,t){for(var n=0,r=0,a=Math.min(e.t,this.t);n<a;)r+=this.data[n]-e.data[n],t.data[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r-=e.s;n<this.t;)r+=this.data[n],t.data[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r-=e.data[n],t.data[n++]=r&this.DM,r>>=this.DB;r-=e.s}t.s=r<0?-1:0,r<-1?t.data[n++]=this.DV+r:r>0&&(t.data[n++]=r),t.t=n,t.clamp()},Se.prototype.multiplyTo=function(e,t){var n=this.abs(),r=e.abs(),a=n.t;for(t.t=a+r.t;--a>=0;)t.data[a]=0;for(a=0;a<r.t;++a)t.data[a+n.t]=n.am(0,r.data[a],t,a,0,n.t);t.s=0,t.clamp(),this.s!=e.s&&Se.ZERO.subTo(t,t)},Se.prototype.squareTo=function(e){for(var t=this.abs(),n=e.t=2*t.t;--n>=0;)e.data[n]=0;for(n=0;n<t.t-1;++n){var r=t.am(n,t.data[n],e,2*n,0,1);(e.data[n+t.t]+=t.am(n+1,2*t.data[n],e,2*n+1,r,t.t-n-1))>=t.DV&&(e.data[n+t.t]-=t.DV,e.data[n+t.t+1]=1)}e.t>0&&(e.data[e.t-1]+=t.am(n,t.data[n],e,2*n,0,1)),e.s=0,e.clamp()},Se.prototype.divRemTo=function(e,t,n){var r=e.abs();if(!(r.t<=0)){var a=this.abs();if(a.t<r.t)return null!=t&&t.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=Ee());var o=Ee(),i=this.s,s=e.s,u=this.DB-Be(r.data[r.t-1]);u>0?(r.lShiftTo(u,o),a.lShiftTo(u,n)):(r.copyTo(o),a.copyTo(n));var c=o.t,l=o.data[c-1];if(0!=l){var p=l*(1<<this.F1)+(c>1?o.data[c-2]>>this.F2:0),d=this.FV/p,f=(1<<this.F1)/p,h=1<<this.F2,m=n.t,g=m-c,v=null==t?Ee():t;for(o.dlShiftTo(g,v),n.compareTo(v)>=0&&(n.data[n.t++]=1,n.subTo(v,n)),Se.ONE.dlShiftTo(c,v),v.subTo(o,o);o.t<c;)o.data[o.t++]=0;for(;--g>=0;){var y=n.data[--m]==l?this.DM:Math.floor(n.data[m]*d+(n.data[m-1]+h)*f);if((n.data[m]+=o.am(0,y,n,g,0,c))<y)for(o.dlShiftTo(g,v),n.subTo(v,n);n.data[m]<--y;)n.subTo(v,n)}null!=t&&(n.drShiftTo(c,t),i!=s&&Se.ZERO.subTo(t,t)),n.t=c,n.clamp(),u>0&&n.rShiftTo(u,n),i<0&&Se.ZERO.subTo(n,n)}}},Se.prototype.invDigit=function(){if(this.t<1)return 0;var e=this.data[0];if(0==(1&e))return 0;var t=3&e;return(t=(t=(t=(t=t*(2-(15&e)*t)&15)*(2-(255&e)*t)&255)*(2-((65535&e)*t&65535))&65535)*(2-e*t%this.DV)%this.DV)>0?this.DV-t:-t},Se.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},Se.prototype.exp=function(e,t){if(e>4294967295||e<1)return Se.ONE;var n=Ee(),r=Ee(),a=t.convert(this),o=Be(e)-1;for(a.copyTo(n);--o>=0;)if(t.sqrTo(n,r),(e&1<<o)>0)t.mulTo(r,a,n);else{var i=n;n=r,r=i}return t.revert(n)},Se.prototype.toString=function(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)return this.toRadix(e);t=2}var n,r=(1<<t)-1,a=!1,o="",i=this.t,s=this.DB-i*this.DB%t;if(i-- >0)for(s<this.DB&&(n=this.data[i]>>s)>0&&(a=!0,o=Ae(n));i>=0;)s<t?(n=(this.data[i]&(1<<s)-1)<<t-s,n|=this.data[--i]>>(s+=this.DB-t)):(n=this.data[i]>>(s-=t)&r,s<=0&&(s+=this.DB,--i)),n>0&&(a=!0),a&&(o+=Ae(n));return a?o:"0"},Se.prototype.negate=function(){var e=Ee();return Se.ZERO.subTo(this,e),e},Se.prototype.abs=function(){return this.s<0?this.negate():this},Se.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var n=this.t;if(0!=(t=n-e.t))return this.s<0?-t:t;for(;--n>=0;)if(0!=(t=this.data[n]-e.data[n]))return t;return 0},Se.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+Be(this.data[this.t-1]^this.s&this.DM)},Se.prototype.mod=function(e){var t=Ee();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(Se.ZERO)>0&&e.subTo(t,t),t},Se.prototype.modPowInt=function(e,t){var n;return n=e<256||t.isEven()?new De(t):new Me(t),this.exp(e,n)},Se.ZERO=Oe(0),Se.ONE=Oe(1),je.prototype.convert=We,je.prototype.revert=We,je.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n)},je.prototype.sqrTo=function(e,t){e.squareTo(t)},He.prototype.convert=function(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=Ee();return e.copyTo(t),this.reduce(t),t},He.prototype.revert=function(e){return e},He.prototype.reduce=function(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)},He.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n),this.reduce(n)},He.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)};var Ge=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509],Ke=(1<<26)/Ge[Ge.length-1];if(Se.prototype.chunkSize=function(e){return Math.floor(Math.LN2*this.DB/Math.log(e))},Se.prototype.toRadix=function(e){if(null==e&&(e=10),0==this.signum()||e<2||e>36)return"0";var t=this.chunkSize(e),n=Math.pow(e,t),r=Oe(n),a=Ee(),o=Ee(),i="";for(this.divRemTo(r,a,o);a.signum()>0;)i=(n+o.intValue()).toString(e).substr(1)+i,a.divRemTo(r,a,o);return o.intValue().toString(e)+i},Se.prototype.fromRadix=function(e,t){this.fromInt(0),null==t&&(t=10);for(var n=this.chunkSize(t),r=Math.pow(t,n),a=!1,o=0,i=0,s=0;s<e.length;++s){var u=Re(e,s);u<0?"-"==e.charAt(s)&&0==this.signum()&&(a=!0):(i=t*i+u,++o>=n&&(this.dMultiply(r),this.dAddOffset(i,0),o=0,i=0))}o>0&&(this.dMultiply(Math.pow(t,o)),this.dAddOffset(i,0)),a&&Se.ZERO.subTo(this,this)},Se.prototype.fromNumber=function(e,t,n){if("number"==typeof t)if(e<2)this.fromInt(1);else for(this.fromNumber(e,n),this.testBit(e-1)||this.bitwiseTo(Se.ONE.shiftLeft(e-1),Pe,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(Se.ONE.shiftLeft(e-1),this);else{var r=new Array,a=7&e;r.length=1+(e>>3),t.nextBytes(r),a>0?r[0]&=(1<<a)-1:r[0]=0,this.fromString(r,256)}},Se.prototype.bitwiseTo=function(e,t,n){var r,a,o=Math.min(e.t,this.t);for(r=0;r<o;++r)n.data[r]=t(this.data[r],e.data[r]);if(e.t<this.t){for(a=e.s&this.DM,r=o;r<this.t;++r)n.data[r]=t(this.data[r],a);n.t=this.t}else{for(a=this.s&this.DM,r=o;r<e.t;++r)n.data[r]=t(a,e.data[r]);n.t=e.t}n.s=t(this.s,e.s),n.clamp()},Se.prototype.changeBit=function(e,t){var n=Se.ONE.shiftLeft(e);return this.bitwiseTo(n,t,n),n},Se.prototype.addTo=function(e,t){for(var n=0,r=0,a=Math.min(e.t,this.t);n<a;)r+=this.data[n]+e.data[n],t.data[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r+=e.s;n<this.t;)r+=this.data[n],t.data[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r+=e.data[n],t.data[n++]=r&this.DM,r>>=this.DB;r+=e.s}t.s=r<0?-1:0,r>0?t.data[n++]=r:r<-1&&(t.data[n++]=this.DV+r),t.t=n,t.clamp()},Se.prototype.dMultiply=function(e){this.data[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()},Se.prototype.dAddOffset=function(e,t){if(0!=e){for(;this.t<=t;)this.data[this.t++]=0;for(this.data[t]+=e;this.data[t]>=this.DV;)this.data[t]-=this.DV,++t>=this.t&&(this.data[this.t++]=0),++this.data[t]}},Se.prototype.multiplyLowerTo=function(e,t,n){var r,a=Math.min(this.t+e.t,t);for(n.s=0,n.t=a;a>0;)n.data[--a]=0;for(r=n.t-this.t;a<r;++a)n.data[a+this.t]=this.am(0,e.data[a],n,a,0,this.t);for(r=Math.min(e.t,t);a<r;++a)this.am(0,e.data[a],n,a,0,t-a);n.clamp()},Se.prototype.multiplyUpperTo=function(e,t,n){--t;var r=n.t=this.t+e.t-t;for(n.s=0;--r>=0;)n.data[r]=0;for(r=Math.max(t-this.t,0);r<e.t;++r)n.data[this.t+r-t]=this.am(t-r,e.data[r],n,0,0,this.t+r-t);n.clamp(),n.drShiftTo(1,n)},Se.prototype.modInt=function(e){if(e<=0)return 0;var t=this.DV%e,n=this.s<0?e-1:0;if(this.t>0)if(0==t)n=this.data[0]%e;else for(var r=this.t-1;r>=0;--r)n=(t*n+this.data[r])%e;return n},Se.prototype.millerRabin=function(e){var t=this.subtract(Se.ONE),n=t.getLowestSetBit();if(n<=0)return!1;for(var r,a=t.shiftRight(n),o={nextBytes:function(e){for(var t=0;t<e.length;++t)e[t]=Math.floor(256*Math.random())}},i=0;i<e;++i){do{r=new Se(this.bitLength(),o)}while(r.compareTo(Se.ONE)<=0||r.compareTo(t)>=0);var s=r.modPow(a,this);if(0!=s.compareTo(Se.ONE)&&0!=s.compareTo(t)){for(var u=1;u++<n&&0!=s.compareTo(t);)if(0==(s=s.modPowInt(2,this)).compareTo(Se.ONE))return!1;if(0!=s.compareTo(t))return!1}}return!0},Se.prototype.clone=function(){var e=Ee();return this.copyTo(e),e},Se.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this.data[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this.data[0];if(0==this.t)return 0}return(this.data[1]&(1<<32-this.DB)-1)<<this.DB|this.data[0]},Se.prototype.byteValue=function(){return 0==this.t?this.s:this.data[0]<<24>>24},Se.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},Se.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},Se.prototype.toByteArray=function(){var e=this.t,t=new Array;t[0]=this.s;var n,r=this.DB-e*this.DB%8,a=0;if(e-- >0)for(r<this.DB&&(n=this.data[e]>>r)!=(this.s&this.DM)>>r&&(t[a++]=n|this.s<<this.DB-r);e>=0;)r<8?(n=(this.data[e]&(1<<r)-1)<<8-r,n|=this.data[--e]>>(r+=this.DB-8)):(n=this.data[e]>>(r-=8)&255,r<=0&&(r+=this.DB,--e)),0!=(128&n)&&(n|=-256),0==a&&(128&this.s)!=(128&n)&&++a,(a>0||n!=this.s)&&(t[a++]=n);return t},Se.prototype.equals=function(e){return 0==this.compareTo(e)},Se.prototype.min=function(e){return this.compareTo(e)<0?this:e},Se.prototype.max=function(e){return this.compareTo(e)>0?this:e},Se.prototype.and=function(e){var t=Ee();return this.bitwiseTo(e,Fe,t),t},Se.prototype.or=function(e){var t=Ee();return this.bitwiseTo(e,Pe,t),t},Se.prototype.xor=function(e){var t=Ee();return this.bitwiseTo(e,Le,t),t},Se.prototype.andNot=function(e){var t=Ee();return this.bitwiseTo(e,Ue,t),t},Se.prototype.not=function(){for(var e=Ee(),t=0;t<this.t;++t)e.data[t]=this.DM&~this.data[t];return e.t=this.t,e.s=~this.s,e},Se.prototype.shiftLeft=function(e){var t=Ee();return e<0?this.rShiftTo(-e,t):this.lShiftTo(e,t),t},Se.prototype.shiftRight=function(e){var t=Ee();return e<0?this.lShiftTo(-e,t):this.rShiftTo(e,t),t},Se.prototype.getLowestSetBit=function(){for(var e=0;e<this.t;++e)if(0!=this.data[e])return e*this.DB+Ve(this.data[e]);return this.s<0?this.t*this.DB:-1},Se.prototype.bitCount=function(){for(var e=0,t=this.s&this.DM,n=0;n<this.t;++n)e+=ze(this.data[n]^t);return e},Se.prototype.testBit=function(e){var t=Math.floor(e/this.DB);return t>=this.t?0!=this.s:0!=(this.data[t]&1<<e%this.DB)},Se.prototype.setBit=function(e){return this.changeBit(e,Pe)},Se.prototype.clearBit=function(e){return this.changeBit(e,Ue)},Se.prototype.flipBit=function(e){return this.changeBit(e,Le)},Se.prototype.add=function(e){var t=Ee();return this.addTo(e,t),t},Se.prototype.subtract=function(e){var t=Ee();return this.subTo(e,t),t},Se.prototype.multiply=function(e){var t=Ee();return this.multiplyTo(e,t),t},Se.prototype.divide=function(e){var t=Ee();return this.divRemTo(e,t,null),t},Se.prototype.remainder=function(e){var t=Ee();return this.divRemTo(e,null,t),t},Se.prototype.divideAndRemainder=function(e){var t=Ee(),n=Ee();return this.divRemTo(e,t,n),new Array(t,n)},Se.prototype.modPow=function(e,t){var n,r,a=e.bitLength(),o=Oe(1);if(a<=0)return o;n=a<18?1:a<48?3:a<144?4:a<768?5:6,r=a<8?new De(t):t.isEven()?new He(t):new Me(t);var i=new Array,s=3,u=n-1,c=(1<<n)-1;if(i[1]=r.convert(this),n>1){var l=Ee();for(r.sqrTo(i[1],l);s<=c;)i[s]=Ee(),r.mulTo(l,i[s-2],i[s]),s+=2}var p,d,f=e.t-1,h=!0,m=Ee();for(a=Be(e.data[f])-1;f>=0;){for(a>=u?p=e.data[f]>>a-u&c:(p=(e.data[f]&(1<<a+1)-1)<<u-a,f>0&&(p|=e.data[f-1]>>this.DB+a-u)),s=n;0==(1&p);)p>>=1,--s;if((a-=s)<0&&(a+=this.DB,--f),h)i[p].copyTo(o),h=!1;else{for(;s>1;)r.sqrTo(o,m),r.sqrTo(m,o),s-=2;s>0?r.sqrTo(o,m):(d=o,o=m,m=d),r.mulTo(m,i[p],o)}for(;f>=0&&0==(e.data[f]&1<<a);)r.sqrTo(o,m),d=o,o=m,m=d,--a<0&&(a=this.DB-1,--f)}return r.revert(o)},Se.prototype.modInverse=function(e){var t=e.isEven();if(this.isEven()&&t||0==e.signum())return Se.ZERO;for(var n=e.clone(),r=this.clone(),a=Oe(1),o=Oe(0),i=Oe(0),s=Oe(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),t?(a.isEven()&&o.isEven()||(a.addTo(this,a),o.subTo(e,o)),a.rShiftTo(1,a)):o.isEven()||o.subTo(e,o),o.rShiftTo(1,o);for(;r.isEven();)r.rShiftTo(1,r),t?(i.isEven()&&s.isEven()||(i.addTo(this,i),s.subTo(e,s)),i.rShiftTo(1,i)):s.isEven()||s.subTo(e,s),s.rShiftTo(1,s);n.compareTo(r)>=0?(n.subTo(r,n),t&&a.subTo(i,a),o.subTo(s,o)):(r.subTo(n,r),t&&i.subTo(a,i),s.subTo(o,s))}return 0!=r.compareTo(Se.ONE)?Se.ZERO:s.compareTo(e)>=0?s.subtract(e):s.signum()<0?(s.addTo(e,s),s.signum()<0?s.add(e):s):s},Se.prototype.pow=function(e){return this.exp(e,new je)},Se.prototype.gcd=function(e){var t=this.s<0?this.negate():this.clone(),n=e.s<0?e.negate():e.clone();if(t.compareTo(n)<0){var r=t;t=n,n=r}var a=t.getLowestSetBit(),o=n.getLowestSetBit();if(o<0)return t;for(a<o&&(o=a),o>0&&(t.rShiftTo(o,t),n.rShiftTo(o,n));t.signum()>0;)(a=t.getLowestSetBit())>0&&t.rShiftTo(a,t),(a=n.getLowestSetBit())>0&&n.rShiftTo(a,n),t.compareTo(n)>=0?(t.subTo(n,t),t.rShiftTo(1,t)):(n.subTo(t,n),n.rShiftTo(1,n));return o>0&&n.lShiftTo(o,n),n},Se.prototype.isProbablePrime=function(e){var t,n=this.abs();if(1==n.t&&n.data[0]<=Ge[Ge.length-1]){for(t=0;t<Ge.length;++t)if(n.data[0]==Ge[t])return!0;return!1}if(n.isEven())return!1;for(t=1;t<Ge.length;){for(var r=Ge[t],a=t+1;a<Ge.length&&r<Ke;)r*=Ge[a++];for(r=n.modInt(r);t<a;)if(r%Ge[t++]==0)return!1}return n.millerRabin(e)},w((function(e){var t=e.exports=z.sha1=z.sha1||{};z.md.sha1=z.md.algorithms.sha1=t,t.create=function(){r||(n=String.fromCharCode(128),n+=z.util.fillString(String.fromCharCode(0),64),r=!0);var e=null,t=z.util.createBuffer(),o=new Array(80),i={algorithm:"sha1",blockLength:64,digestLength:20,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){i.messageLength=0,i.fullMessageLength=i.messageLength64=[];for(var n=i.messageLengthSize/4,r=0;r<n;++r)i.fullMessageLength.push(0);return t=z.util.createBuffer(),e={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878,h4:3285377520},i}};return i.start(),i.update=function(n,r){"utf8"===r&&(n=z.util.encodeUtf8(n));var s=n.length;i.messageLength+=s,s=[s/4294967296>>>0,s>>>0];for(var u=i.fullMessageLength.length-1;u>=0;--u)i.fullMessageLength[u]+=s[1],s[1]=s[0]+(i.fullMessageLength[u]/4294967296>>>0),i.fullMessageLength[u]=i.fullMessageLength[u]>>>0,s[0]=s[1]/4294967296>>>0;return t.putBytes(n),a(e,o,t),(t.read>2048||0===t.length())&&t.compact(),i},i.digest=function(){var r=z.util.createBuffer();r.putBytes(t.bytes());var s,u=i.fullMessageLength[i.fullMessageLength.length-1]+i.messageLengthSize&i.blockLength-1;r.putBytes(n.substr(0,i.blockLength-u));for(var c=8*i.fullMessageLength[0],l=0;l<i.fullMessageLength.length-1;++l)c+=(s=8*i.fullMessageLength[l+1])/4294967296>>>0,r.putInt32(c>>>0),c=s>>>0;r.putInt32(c);var p={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4};a(p,o,r);var d=z.util.createBuffer();return d.putInt32(p.h0),d.putInt32(p.h1),d.putInt32(p.h2),d.putInt32(p.h3),d.putInt32(p.h4),d},i};var n=null,r=!1;function a(e,t,n){for(var r,a,o,i,s,u,c,l=n.length();l>=64;){for(a=e.h0,o=e.h1,i=e.h2,s=e.h3,u=e.h4,c=0;c<16;++c)r=n.getInt32(),t[c]=r,r=(a<<5|a>>>27)+(s^o&(i^s))+u+1518500249+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<20;++c)r=(r=t[c-3]^t[c-8]^t[c-14]^t[c-16])<<1|r>>>31,t[c]=r,r=(a<<5|a>>>27)+(s^o&(i^s))+u+1518500249+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<32;++c)r=(r=t[c-3]^t[c-8]^t[c-14]^t[c-16])<<1|r>>>31,t[c]=r,r=(a<<5|a>>>27)+(o^i^s)+u+1859775393+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<40;++c)r=(r=t[c-6]^t[c-16]^t[c-28]^t[c-32])<<2|r>>>30,t[c]=r,r=(a<<5|a>>>27)+(o^i^s)+u+1859775393+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<60;++c)r=(r=t[c-6]^t[c-16]^t[c-28]^t[c-32])<<2|r>>>30,t[c]=r,r=(a<<5|a>>>27)+(o&i|s&(o^i))+u+2400959708+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<80;++c)r=(r=t[c-6]^t[c-16]^t[c-28]^t[c-32])<<2|r>>>30,t[c]=r,r=(a<<5|a>>>27)+(o^i^s)+u+3395469782+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;e.h0=e.h0+a|0,e.h1=e.h1+o|0,e.h2=e.h2+i|0,e.h3=e.h3+s|0,e.h4=e.h4+u|0,l-=64}}})),w((function(e){var t=e.exports=z.pkcs1=z.pkcs1||{};function n(e,t,n){n||(n=z.md.sha1.create());for(var r="",a=Math.ceil(t/n.digestLength),o=0;o<a;++o){var i=String.fromCharCode(o>>24&255,o>>16&255,o>>8&255,255&o);n.start(),n.update(e+i),r+=n.digest().getBytes()}return r.substring(0,t)}t.encode_rsa_oaep=function(e,t,r){var a,o,i,s;"string"==typeof r?(a=r,o=arguments[3]||void 0,i=arguments[4]||void 0):r&&(a=r.label||void 0,o=r.seed||void 0,i=r.md||void 0,r.mgf1&&r.mgf1.md&&(s=r.mgf1.md)),i?i.start():i=z.md.sha1.create(),s||(s=i);var u=Math.ceil(e.n.bitLength()/8),c=u-2*i.digestLength-2;if(t.length>c)throw(h=new Error("RSAES-OAEP input message length is too long.")).length=t.length,h.maxLength=c,h;a||(a=""),i.update(a,"raw");for(var l=i.digest(),p="",d=c-t.length,f=0;f<d;f++)p+="\0";var h,m=l.getBytes()+p+""+t;if(o){if(o.length!==i.digestLength)throw(h=new Error("Invalid RSAES-OAEP seed. The seed length must match the digest length.")).seedLength=o.length,h.digestLength=i.digestLength,h}else o=z.random.getBytes(i.digestLength);var g=n(o,u-i.digestLength-1,s),v=z.util.xorBytes(m,g,m.length),y=n(v,i.digestLength,s);return"\0"+z.util.xorBytes(o,y,o.length)+v},t.decode_rsa_oaep=function(e,t,r){var a,o,i;"string"==typeof r?(a=r,o=arguments[3]||void 0):r&&(a=r.label||void 0,o=r.md||void 0,r.mgf1&&r.mgf1.md&&(i=r.mgf1.md));var s=Math.ceil(e.n.bitLength()/8);if(t.length!==s)throw(g=new Error("RSAES-OAEP encoded message length is invalid.")).length=t.length,g.expectedLength=s,g;if(void 0===o?o=z.md.sha1.create():o.start(),i||(i=o),s<2*o.digestLength+2)throw new Error("RSAES-OAEP key is too short for the hash function.");a||(a=""),o.update(a,"raw");for(var u=o.digest().getBytes(),c=t.charAt(0),l=t.substring(1,o.digestLength+1),p=t.substring(1+o.digestLength),d=n(p,o.digestLength,i),f=n(z.util.xorBytes(l,d,l.length),s-o.digestLength-1,i),h=z.util.xorBytes(p,f,p.length),m=h.substring(0,o.digestLength),g="\0"!==c,v=0;v<o.digestLength;++v)g|=u.charAt(v)!==m.charAt(v);for(var y=1,b=o.digestLength,x=o.digestLength;x<h.length;x++){var w=h.charCodeAt(x);g|=w&(y?65534:0),b+=y&=1&w^1}if(g||1!==h.charCodeAt(b))throw new Error("Invalid RSAES-OAEP padding.");return h.substring(b+1)}})),w((function(e){!function(){if(z.prime)e.exports=z.prime;else{var t=e.exports=z.prime=z.prime||{},n=z.jsbn.BigInteger,r=[6,4,2,4,2,4,6,2],a=new n(null);a.fromInt(30);var o=function(e,t){return e|t};t.generateProbablePrime=function(e,t,r){"function"==typeof t&&(r=t,t={});var a=(t=t||{}).algorithm||"PRIMEINC";"string"==typeof a&&(a={name:a}),a.options=a.options||{};var o=t.prng||z.random,u={nextBytes:function(e){for(var t=o.getBytesSync(e.length),n=0;n<e.length;++n)e[n]=t.charCodeAt(n)}};if("PRIMEINC"===a.name)return function(e,t,r,a){return"workers"in r?function(e,t,r,a){if("undefined"==typeof Worker)return i(e,t,r,a);var o=s(e,t),u=r.workers,c=r.workLoad||100,l=30*c/8,p=r.workerScript||"forge/prime.worker.js";if(-1===u)return z.util.estimateCores((function(e,t){e&&(t=2),u=t-1,d()}));function d(){u=Math.max(1,u);for(var r=[],i=0;i<u;++i)r[i]=new Worker(p);for(i=0;i<u;++i)r[i].addEventListener("message",f);var d=!1;function f(i){if(!d){var u=i.data;if(u.found){for(var p=0;p<r.length;++p)r[p].terminate();return d=!0,a(null,new n(u.prime,16))}o.bitLength()>e&&(o=s(e,t));var f=o.toString(16);i.target.postMessage({hex:f,workLoad:c}),o.dAddOffset(l,0)}}}d()}(e,t,r,a):i(e,t,r,a)}(e,u,a.options,r);throw new Error("Invalid prime generation algorithm: "+a.name)}}function i(e,t,n,a){var o=s(e,t),i=function(e){return e<=100?27:e<=150?18:e<=200?15:e<=250?12:e<=300?9:e<=350?8:e<=400?7:e<=500?6:e<=600?5:e<=800?4:e<=1250?3:2}(o.bitLength());"millerRabinTests"in n&&(i=n.millerRabinTests);var u=10;"maxBlockTime"in n&&(u=n.maxBlockTime),function e(t,n,a,o,i,u,c){var l=+new Date;do{if(t.bitLength()>n&&(t=s(n,a)),t.isProbablePrime(i))return c(null,t);t.dAddOffset(r[o++%8],0)}while(u<0||+new Date-l<u);z.util.setImmediate((function(){e(t,n,a,o,i,u,c)}))}(o,e,t,0,i,u,a)}function s(e,t){var r=new n(e,t),i=e-1;return r.testBit(i)||r.bitwiseTo(n.ONE.shiftLeft(i),o,r),r.dAddOffset(31-r.mod(a).byteValue(),0),r}}()})),void 0===qe)var qe=z.jsbn.BigInteger;var Qe=z.util.isNodejs?t:null,Xe=z.asn1,Ye=z.util;z.pki=z.pki||{},z.pki.rsa=z.rsa=z.rsa||{};var $e=z.pki,Ze=[6,4,2,4,2,4,6,2],Je={name:"PrivateKeyInfo",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"PrivateKeyInfo.version",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.privateKeyAlgorithm",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.OID,constructed:!1,capture:"privateKeyOid"}]},{name:"PrivateKeyInfo",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.OCTETSTRING,constructed:!1,capture:"privateKey"}]},et={name:"RSAPrivateKey",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPrivateKey.version",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyCoefficient"}]},tt={name:"RSAPublicKey",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPublicKey.modulus",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"publicKeyExponent"}]},nt=z.pki.rsa.publicKeyValidator={name:"SubjectPublicKeyInfo",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{name:"SubjectPublicKeyInfo.subjectPublicKey",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.BITSTRING,constructed:!1,value:[{name:"SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"rsaPublicKey"}]}]},rt=function(e){var t;if(!(e.algorithm in $e.oids)){var n=new Error("Unknown message digest algorithm.");throw n.algorithm=e.algorithm,n}t=$e.oids[e.algorithm];var r=Xe.oidToDer(t).getBytes(),a=Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[]),o=Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[]);o.value.push(Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OID,!1,r)),o.value.push(Xe.create(Xe.Class.UNIVERSAL,Xe.Type.NULL,!1,""));var i=Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OCTETSTRING,!1,e.digest().getBytes());return a.value.push(o),a.value.push(i),Xe.toDer(a).getBytes()},at=function(e,t,n){if(n)return e.modPow(t.e,t.n);if(!t.p||!t.q)return e.modPow(t.d,t.n);var r;t.dP||(t.dP=t.d.mod(t.p.subtract(qe.ONE))),t.dQ||(t.dQ=t.d.mod(t.q.subtract(qe.ONE))),t.qInv||(t.qInv=t.q.modInverse(t.p));do{r=new qe(z.util.bytesToHex(z.random.getBytes(t.n.bitLength()/8)),16)}while(r.compareTo(t.n)>=0||!r.gcd(t.n).equals(qe.ONE));for(var a=(e=e.multiply(r.modPow(t.e,t.n)).mod(t.n)).mod(t.p).modPow(t.dP,t.p),o=e.mod(t.q).modPow(t.dQ,t.q);a.compareTo(o)<0;)a=a.add(t.p);var i=a.subtract(o).multiply(t.qInv).mod(t.p).multiply(t.q).add(o);return i.multiply(r.modInverse(t.n)).mod(t.n)};function ot(e,t,n){var r=z.util.createBuffer(),a=Math.ceil(t.n.bitLength()/8);if(e.length>a-11){var o=new Error("Message is too long for PKCS#1 v1.5 padding.");throw o.length=e.length,o.max=a-11,o}r.putByte(0),r.putByte(n);var i,s=a-3-e.length;if(0===n||1===n){i=0===n?0:255;for(var u=0;u<s;++u)r.putByte(i)}else for(;s>0;){var c=0,l=z.random.getBytes(s);for(u=0;u<s;++u)0===(i=l.charCodeAt(u))?++c:r.putByte(i);s=c}return r.putByte(0),r.putBytes(e),r}function it(e,t,n,r){var a=Math.ceil(t.n.bitLength()/8),o=z.util.createBuffer(e),i=o.getByte(),s=o.getByte();if(0!==i||n&&0!==s&&1!==s||!n&&2!=s||n&&0===s&&void 0===r)throw new Error("Encryption block is invalid.");var u=0;if(0===s){u=a-3-r;for(var c=0;c<u;++c)if(0!==o.getByte())throw new Error("Encryption block is invalid.")}else if(1===s)for(u=0;o.length()>1;){if(255!==o.getByte()){--o.read;break}++u}else if(2===s)for(u=0;o.length()>1;){if(0===o.getByte()){--o.read;break}++u}if(0!==o.getByte()||u!==a-3-o.length())throw new Error("Encryption block is invalid.");return o.getBytes()}function st(e,t,n){"function"==typeof t&&(n=t,t={});var r={algorithm:{name:(t=t||{}).algorithm||"PRIMEINC",options:{workers:t.workers||2,workLoad:t.workLoad||100,workerScript:t.workerScript}}};function a(){o(e.pBits,(function(t,r){return t?n(t):(e.p=r,null!==e.q?i(t,e.q):void o(e.qBits,i))}))}function o(e,t){z.prime.generateProbablePrime(e,r,t)}function i(t,r){if(t)return n(t);if(e.q=r,e.p.compareTo(e.q)<0){var s=e.p;e.p=e.q,e.q=s}if(0!==e.p.subtract(qe.ONE).gcd(e.e).compareTo(qe.ONE))return e.p=null,void a();if(0!==e.q.subtract(qe.ONE).gcd(e.e).compareTo(qe.ONE))return e.q=null,void o(e.qBits,i);if(e.p1=e.p.subtract(qe.ONE),e.q1=e.q.subtract(qe.ONE),e.phi=e.p1.multiply(e.q1),0!==e.phi.gcd(e.e).compareTo(qe.ONE))return e.p=e.q=null,void a();if(e.n=e.p.multiply(e.q),e.n.bitLength()!==e.bits)return e.q=null,void o(e.qBits,i);var u=e.e.modInverse(e.phi);e.keys={privateKey:$e.rsa.setPrivateKey(e.n,e.e,u,e.p,e.q,u.mod(e.p1),u.mod(e.q1),e.q.modInverse(e.p)),publicKey:$e.rsa.setPublicKey(e.n,e.e)},n(null,e.keys)}"prng"in t&&(r.prng=t.prng),a()}function ut(e){var t=e.toString(16);t[0]>="8"&&(t="00"+t);var n=z.util.hexToBytes(t);return n.length>1&&(0===n.charCodeAt(0)&&0==(128&n.charCodeAt(1))||255===n.charCodeAt(0)&&128==(128&n.charCodeAt(1)))?n.substr(1):n}function ct(e){return e<=100?27:e<=150?18:e<=200?15:e<=250?12:e<=300?9:e<=350?8:e<=400?7:e<=500?6:e<=600?5:e<=800?4:e<=1250?3:2}function lt(e){return z.util.isNodejs&&"function"==typeof Qe[e]}function pt(e){return void 0!==Ye.globalScope&&"object"==typeof Ye.globalScope.crypto&&"object"==typeof Ye.globalScope.crypto.subtle&&"function"==typeof Ye.globalScope.crypto.subtle[e]}function dt(e){return void 0!==Ye.globalScope&&"object"==typeof Ye.globalScope.msCrypto&&"object"==typeof Ye.globalScope.msCrypto.subtle&&"function"==typeof Ye.globalScope.msCrypto.subtle[e]}function ft(e){for(var t=z.util.hexToBytes(e.toString(16)),n=new Uint8Array(t.length),r=0;r<t.length;++r)n[r]=t.charCodeAt(r);return n}if($e.rsa.encrypt=function(e,t,n){var r,a=n,o=Math.ceil(t.n.bitLength()/8);!1!==n&&!0!==n?(a=2===n,r=ot(e,t,n)):(r=z.util.createBuffer()).putBytes(e);for(var i=new qe(r.toHex(),16),s=at(i,t,a).toString(16),u=z.util.createBuffer(),c=o-Math.ceil(s.length/2);c>0;)u.putByte(0),--c;return u.putBytes(z.util.hexToBytes(s)),u.getBytes()},$e.rsa.decrypt=function(e,t,n,r){var a=Math.ceil(t.n.bitLength()/8);if(e.length!==a){var o=new Error("Encrypted message length is invalid.");throw o.length=e.length,o.expected=a,o}var i=new qe(z.util.createBuffer(e).toHex(),16);if(i.compareTo(t.n)>=0)throw new Error("Encrypted message is invalid.");for(var s=at(i,t,n).toString(16),u=z.util.createBuffer(),c=a-Math.ceil(s.length/2);c>0;)u.putByte(0),--c;return u.putBytes(z.util.hexToBytes(s)),!1!==r?it(u.getBytes(),t,n):u.getBytes()},$e.rsa.createKeyPairGenerationState=function(e,t,n){"string"==typeof e&&(e=parseInt(e,10)),e=e||2048;var r,a=(n=n||{}).prng||z.random,o={nextBytes:function(e){for(var t=a.getBytesSync(e.length),n=0;n<e.length;++n)e[n]=t.charCodeAt(n)}},i=n.algorithm||"PRIMEINC";if("PRIMEINC"!==i)throw new Error("Invalid key generation algorithm: "+i);return(r={algorithm:i,state:0,bits:e,rng:o,eInt:t||65537,e:new qe(null),p:null,q:null,qBits:e>>1,pBits:e-(e>>1),pqState:0,num:null,keys:null}).e.fromInt(r.eInt),r},$e.rsa.stepKeyPairGenerationState=function(e,t){"algorithm"in e||(e.algorithm="PRIMEINC");var n=new qe(null);n.fromInt(30);for(var r,a=0,o=function(e,t){return e|t},i=+new Date,s=0;null===e.keys&&(t<=0||s<t);){if(0===e.state){var u=null===e.p?e.pBits:e.qBits,c=u-1;0===e.pqState?(e.num=new qe(u,e.rng),e.num.testBit(c)||e.num.bitwiseTo(qe.ONE.shiftLeft(c),o,e.num),e.num.dAddOffset(31-e.num.mod(n).byteValue(),0),a=0,++e.pqState):1===e.pqState?e.num.bitLength()>u?e.pqState=0:e.num.isProbablePrime(ct(e.num.bitLength()))?++e.pqState:e.num.dAddOffset(Ze[a++%8],0):2===e.pqState?e.pqState=0===e.num.subtract(qe.ONE).gcd(e.e).compareTo(qe.ONE)?3:0:3===e.pqState&&(e.pqState=0,null===e.p?e.p=e.num:e.q=e.num,null!==e.p&&null!==e.q&&++e.state,e.num=null)}else if(1===e.state)e.p.compareTo(e.q)<0&&(e.num=e.p,e.p=e.q,e.q=e.num),++e.state;else if(2===e.state)e.p1=e.p.subtract(qe.ONE),e.q1=e.q.subtract(qe.ONE),e.phi=e.p1.multiply(e.q1),++e.state;else if(3===e.state)0===e.phi.gcd(e.e).compareTo(qe.ONE)?++e.state:(e.p=null,e.q=null,e.state=0);else if(4===e.state)e.n=e.p.multiply(e.q),e.n.bitLength()===e.bits?++e.state:(e.q=null,e.state=0);else if(5===e.state){var l=e.e.modInverse(e.phi);e.keys={privateKey:$e.rsa.setPrivateKey(e.n,e.e,l,e.p,e.q,l.mod(e.p1),l.mod(e.q1),e.q.modInverse(e.p)),publicKey:$e.rsa.setPublicKey(e.n,e.e)}}s+=(r=+new Date)-i,i=r}return null!==e.keys},$e.rsa.generateKeyPair=function(e,t,n,r){if(1===arguments.length?"object"==typeof e?(n=e,e=void 0):"function"==typeof e&&(r=e,e=void 0):2===arguments.length?"number"==typeof e?"function"==typeof t?(r=t,t=void 0):"number"!=typeof t&&(n=t,t=void 0):(n=e,r=t,e=void 0,t=void 0):3===arguments.length&&("number"==typeof t?"function"==typeof n&&(r=n,n=void 0):(r=n,n=t,t=void 0)),n=n||{},void 0===e&&(e=n.bits||2048),void 0===t&&(t=n.e||65537),!n.prng&&e>=256&&e<=16384&&(65537===t||3===t))if(r){if(lt("generateKeyPair"))return Qe.generateKeyPair("rsa",{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}},(function(e,t,n){if(e)return r(e);r(null,{privateKey:$e.privateKeyFromPem(n),publicKey:$e.publicKeyFromPem(t)})}));if(pt("generateKey")&&pt("exportKey"))return Ye.globalScope.crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:ft(t),hash:{name:"SHA-256"}},!0,["sign","verify"]).then((function(e){return Ye.globalScope.crypto.subtle.exportKey("pkcs8",e.privateKey)})).then(void 0,(function(e){r(e)})).then((function(e){if(e){var t=$e.privateKeyFromAsn1(Xe.fromDer(z.util.createBuffer(e)));r(null,{privateKey:t,publicKey:$e.setRsaPublicKey(t.n,t.e)})}}));if(dt("generateKey")&&dt("exportKey")){var a=Ye.globalScope.msCrypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:ft(t),hash:{name:"SHA-256"}},!0,["sign","verify"]);return a.oncomplete=function(e){var t=e.target.result,n=Ye.globalScope.msCrypto.subtle.exportKey("pkcs8",t.privateKey);n.oncomplete=function(e){var t=e.target.result,n=$e.privateKeyFromAsn1(Xe.fromDer(z.util.createBuffer(t)));r(null,{privateKey:n,publicKey:$e.setRsaPublicKey(n.n,n.e)})},n.onerror=function(e){r(e)}},void(a.onerror=function(e){r(e)})}}else if(lt("generateKeyPairSync")){var o=Qe.generateKeyPairSync("rsa",{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:$e.privateKeyFromPem(o.privateKey),publicKey:$e.publicKeyFromPem(o.publicKey)}}var i=$e.rsa.createKeyPairGenerationState(e,t,n);if(!r)return $e.rsa.stepKeyPairGenerationState(i,0),i.keys;st(i,n,r)},$e.setRsaPublicKey=$e.rsa.setPublicKey=function(e,t){var n={n:e,e:t,encrypt:function(e,t,r){if("string"==typeof t?t=t.toUpperCase():void 0===t&&(t="RSAES-PKCS1-V1_5"),"RSAES-PKCS1-V1_5"===t)t={encode:function(e,t,n){return ot(e,t,2).getBytes()}};else if("RSA-OAEP"===t||"RSAES-OAEP"===t)t={encode:function(e,t){return z.pkcs1.encode_rsa_oaep(t,e,r)}};else if(-1!==["RAW","NONE","NULL",null].indexOf(t))t={encode:function(e){return e}};else if("string"==typeof t)throw new Error('Unsupported encryption scheme: "'+t+'".');var a=t.encode(e,n,!0);return $e.rsa.encrypt(a,n,!0)},verify:function(e,t,r){"string"==typeof r?r=r.toUpperCase():void 0===r&&(r="RSASSA-PKCS1-V1_5"),"RSASSA-PKCS1-V1_5"===r?r={verify:function(e,t){return t=it(t,n,!0),e===Xe.fromDer(t).value[1].value}}:"NONE"!==r&&"NULL"!==r&&null!==r||(r={verify:function(e,t){return e===it(t,n,!0)}});var a=$e.rsa.decrypt(t,n,!0,!1);return r.verify(e,a,n.n.bitLength())}};return n},$e.setRsaPrivateKey=$e.rsa.setPrivateKey=function(e,t,n,r,a,o,i,s){var u={n:e,e:t,d:n,p:r,q:a,dP:o,dQ:i,qInv:s,decrypt:function(e,t,n){"string"==typeof t?t=t.toUpperCase():void 0===t&&(t="RSAES-PKCS1-V1_5");var r=$e.rsa.decrypt(e,u,!1,!1);if("RSAES-PKCS1-V1_5"===t)t={decode:it};else if("RSA-OAEP"===t||"RSAES-OAEP"===t)t={decode:function(e,t){return z.pkcs1.decode_rsa_oaep(t,e,n)}};else{if(-1===["RAW","NONE","NULL",null].indexOf(t))throw new Error('Unsupported encryption scheme: "'+t+'".');t={decode:function(e){return e}}}return t.decode(r,u,!1)},sign:function(e,t){var n=!1;"string"==typeof t&&(t=t.toUpperCase()),void 0===t||"RSASSA-PKCS1-V1_5"===t?(t={encode:rt},n=1):"NONE"!==t&&"NULL"!==t&&null!==t||(t={encode:function(){return e}},n=1);var r=t.encode(e,u.n.bitLength());return $e.rsa.encrypt(r,u,n)}};return u},$e.wrapRsaPrivateKey=function(e){return Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,Xe.integerToDer(0).getBytes()),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OID,!1,Xe.oidToDer($e.oids.rsaEncryption).getBytes()),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.NULL,!1,"")]),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OCTETSTRING,!1,Xe.toDer(e).getBytes())])},$e.privateKeyFromAsn1=function(e){var t,n,r,a,o,i,s,u,c={},l=[];if(Xe.validate(e,Je,c,l)&&(e=Xe.fromDer(z.util.createBuffer(c.privateKey))),c={},l=[],!Xe.validate(e,et,c,l)){var p=new Error("Cannot read private key. ASN.1 object does not contain an RSAPrivateKey.");throw p.errors=l,p}return t=z.util.createBuffer(c.privateKeyModulus).toHex(),n=z.util.createBuffer(c.privateKeyPublicExponent).toHex(),r=z.util.createBuffer(c.privateKeyPrivateExponent).toHex(),a=z.util.createBuffer(c.privateKeyPrime1).toHex(),o=z.util.createBuffer(c.privateKeyPrime2).toHex(),i=z.util.createBuffer(c.privateKeyExponent1).toHex(),s=z.util.createBuffer(c.privateKeyExponent2).toHex(),u=z.util.createBuffer(c.privateKeyCoefficient).toHex(),$e.setRsaPrivateKey(new qe(t,16),new qe(n,16),new qe(r,16),new qe(a,16),new qe(o,16),new qe(i,16),new qe(s,16),new qe(u,16))},$e.privateKeyToAsn1=$e.privateKeyToRSAPrivateKey=function(e){return Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,Xe.integerToDer(0).getBytes()),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.n)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.e)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.d)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.p)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.q)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.dP)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.dQ)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.qInv))])},$e.publicKeyFromAsn1=function(e){var t={},n=[];if(Xe.validate(e,nt,t,n)){var r,a=Xe.derToOid(t.publicKeyOid);if(a!==$e.oids.rsaEncryption)throw(r=new Error("Cannot read public key. Unknown OID.")).oid=a,r;e=t.rsaPublicKey}if(n=[],!Xe.validate(e,tt,t,n))throw(r=new Error("Cannot read public key. ASN.1 object does not contain an RSAPublicKey.")).errors=n,r;var o=z.util.createBuffer(t.publicKeyModulus).toHex(),i=z.util.createBuffer(t.publicKeyExponent).toHex();return $e.setRsaPublicKey(new qe(o,16),new qe(i,16))},$e.publicKeyToAsn1=$e.publicKeyToSubjectPublicKeyInfo=function(e){return Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OID,!1,Xe.oidToDer($e.oids.rsaEncryption).getBytes()),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.NULL,!1,"")]),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.BITSTRING,!1,[$e.publicKeyToRSAPublicKey(e)])])},$e.publicKeyToRSAPublicKey=function(e){return Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.n)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.e))])},void 0===ht)var ht=z.jsbn.BigInteger;var mt=z.asn1,gt=z.pki=z.pki||{},vt=(gt.pbe=z.pbe=z.pbe||{},gt.oids),yt={name:"EncryptedPrivateKeyInfo",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedPrivateKeyInfo.encryptionAlgorithm",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OID,constructed:!1,capture:"encryptionOid"},{name:"AlgorithmIdentifier.parameters",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,captureAsn1:"encryptionParams"}]},{name:"EncryptedPrivateKeyInfo.encryptedData",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OCTETSTRING,constructed:!1,capture:"encryptedData"}]},bt={name:"PBES2Algorithms",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc.oid",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OID,constructed:!1,capture:"kdfOid"},{name:"PBES2Algorithms.params",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.params.salt",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OCTETSTRING,constructed:!1,capture:"kdfSalt"},{name:"PBES2Algorithms.params.iterationCount",tagClass:mt.Class.UNIVERSAL,type:mt.Type.INTEGER,constructed:!1,capture:"kdfIterationCount"},{name:"PBES2Algorithms.params.keyLength",tagClass:mt.Class.UNIVERSAL,type:mt.Type.INTEGER,constructed:!1,optional:!0,capture:"keyLength"},{name:"PBES2Algorithms.params.prf",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,optional:!0,value:[{name:"PBES2Algorithms.params.prf.algorithm",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OID,constructed:!1,capture:"prfOid"}]}]}]},{name:"PBES2Algorithms.encryptionScheme",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.encryptionScheme.oid",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OID,constructed:!1,capture:"encOid"},{name:"PBES2Algorithms.encryptionScheme.iv",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OCTETSTRING,constructed:!1,capture:"encIv"}]}]},xt={name:"pkcs-12PbeParams",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"pkcs-12PbeParams.salt",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OCTETSTRING,constructed:!1,capture:"salt"},{name:"pkcs-12PbeParams.iterations",tagClass:mt.Class.UNIVERSAL,type:mt.Type.INTEGER,constructed:!1,capture:"iterations"}]};function wt(e,t){return e.start().update(t).digest().getBytes()}function kt(e){var t;if(e){if(!(t=gt.oids[mt.derToOid(e)])){var n=new Error("Unsupported PRF OID.");throw n.oid=e,n.supported=["hmacWithSHA1","hmacWithSHA224","hmacWithSHA256","hmacWithSHA384","hmacWithSHA512"],n}}else t="hmacWithSHA1";return St(t)}function St(e){var t=z.md;switch(e){case"hmacWithSHA224":t=z.md.sha512;case"hmacWithSHA1":case"hmacWithSHA256":case"hmacWithSHA384":case"hmacWithSHA512":e=e.substr(8).toLowerCase();break;default:var n=new Error("Unsupported PRF algorithm.");throw n.algorithm=e,n.supported=["hmacWithSHA1","hmacWithSHA224","hmacWithSHA256","hmacWithSHA384","hmacWithSHA512"],n}if(!t||!(e in t))throw new Error("Unknown hash algorithm: "+e);return t[e].create()}gt.encryptPrivateKeyInfo=function(e,t,n){(n=n||{}).saltSize=n.saltSize||8,n.count=n.count||2048,n.algorithm=n.algorithm||"aes128",n.prfAlgorithm=n.prfAlgorithm||"sha1";var r,a,o,i=z.random.getBytesSync(n.saltSize),s=n.count,u=mt.integerToDer(s);if(0===n.algorithm.indexOf("aes")||"des"===n.algorithm){var c,l,p;switch(n.algorithm){case"aes128":r=16,c=16,l=vt["aes128-CBC"],p=z.aes.createEncryptionCipher;break;case"aes192":r=24,c=16,l=vt["aes192-CBC"],p=z.aes.createEncryptionCipher;break;case"aes256":r=32,c=16,l=vt["aes256-CBC"],p=z.aes.createEncryptionCipher;break;case"des":r=8,c=8,l=vt.desCBC,p=z.des.createEncryptionCipher;break;default:throw(v=new Error("Cannot encrypt private key. Unknown encryption algorithm.")).algorithm=n.algorithm,v}var d="hmacWith"+n.prfAlgorithm.toUpperCase(),f=St(d),h=z.pkcs5.pbkdf2(t,i,s,r,f),m=z.random.getBytesSync(c);(y=p(h)).start(m),y.update(mt.toDer(e)),y.finish(),o=y.output.getBytes();var g=function(e,t,n,r){var a=mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OCTETSTRING,!1,e),mt.create(mt.Class.UNIVERSAL,mt.Type.INTEGER,!1,t.getBytes())]);return"hmacWithSHA1"!==r&&a.value.push(mt.create(mt.Class.UNIVERSAL,mt.Type.INTEGER,!1,z.util.hexToBytes(n.toString(16))),mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(gt.oids[r]).getBytes()),mt.create(mt.Class.UNIVERSAL,mt.Type.NULL,!1,"")])),a}(i,u,r,d);a=mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(vt.pkcs5PBES2).getBytes()),mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(vt.pkcs5PBKDF2).getBytes()),g]),mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(l).getBytes()),mt.create(mt.Class.UNIVERSAL,mt.Type.OCTETSTRING,!1,m)])])])}else{var v;if("3des"!==n.algorithm)throw(v=new Error("Cannot encrypt private key. Unknown encryption algorithm.")).algorithm=n.algorithm,v;r=24;var y,b=new z.util.ByteBuffer(i);h=gt.pbe.generatePkcs12Key(t,b,1,s,r),m=gt.pbe.generatePkcs12Key(t,b,2,s,r),(y=z.des.createEncryptionCipher(h)).start(m),y.update(mt.toDer(e)),y.finish(),o=y.output.getBytes(),a=mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(vt["pbeWithSHAAnd3-KeyTripleDES-CBC"]).getBytes()),mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OCTETSTRING,!1,i),mt.create(mt.Class.UNIVERSAL,mt.Type.INTEGER,!1,u.getBytes())])])}return mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[a,mt.create(mt.Class.UNIVERSAL,mt.Type.OCTETSTRING,!1,o)])},gt.decryptPrivateKeyInfo=function(e,t){var n=null,r={},a=[];if(!mt.validate(e,yt,r,a)){var o=new Error("Cannot read encrypted private key. ASN.1 object is not a supported EncryptedPrivateKeyInfo.");throw o.errors=a,o}var i=mt.derToOid(r.encryptionOid),s=gt.pbe.getCipher(i,r.encryptionParams,t),u=z.util.createBuffer(r.encryptedData);return s.update(u),s.finish()&&(n=mt.fromDer(s.output)),n},gt.encryptedPrivateKeyToPem=function(e,t){var n={type:"ENCRYPTED PRIVATE KEY",body:mt.toDer(e).getBytes()};return z.pem.encode(n,{maxline:t})},gt.encryptedPrivateKeyFromPem=function(e){var t=z.pem.decode(e)[0];if("ENCRYPTED PRIVATE KEY"!==t.type){var n=new Error('Could not convert encrypted private key from PEM; PEM header type is "ENCRYPTED PRIVATE KEY".');throw n.headerType=t.type,n}if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert encrypted private key from PEM; PEM is encrypted.");return mt.fromDer(t.body)},gt.encryptRsaPrivateKey=function(e,t,n){if(!(n=n||{}).legacy){var r=gt.wrapRsaPrivateKey(gt.privateKeyToAsn1(e));return r=gt.encryptPrivateKeyInfo(r,t,n),gt.encryptedPrivateKeyToPem(r)}var a,o,i,s;switch(n.algorithm){case"aes128":a="AES-128-CBC",i=16,o=z.random.getBytesSync(16),s=z.aes.createEncryptionCipher;break;case"aes192":a="AES-192-CBC",i=24,o=z.random.getBytesSync(16),s=z.aes.createEncryptionCipher;break;case"aes256":a="AES-256-CBC",i=32,o=z.random.getBytesSync(16),s=z.aes.createEncryptionCipher;break;case"3des":a="DES-EDE3-CBC",i=24,o=z.random.getBytesSync(8),s=z.des.createEncryptionCipher;break;case"des":a="DES-CBC",i=8,o=z.random.getBytesSync(8),s=z.des.createEncryptionCipher;break;default:var u=new Error('Could not encrypt RSA private key; unsupported encryption algorithm "'+n.algorithm+'".');throw u.algorithm=n.algorithm,u}var c=s(z.pbe.opensslDeriveBytes(t,o.substr(0,8),i));c.start(o),c.update(mt.toDer(gt.privateKeyToAsn1(e))),c.finish();var l={type:"RSA PRIVATE KEY",procType:{version:"4",type:"ENCRYPTED"},dekInfo:{algorithm:a,parameters:z.util.bytesToHex(o).toUpperCase()},body:c.output.getBytes()};return z.pem.encode(l)},gt.decryptRsaPrivateKey=function(e,t){var n=null,r=z.pem.decode(e)[0];if("ENCRYPTED PRIVATE KEY"!==r.type&&"PRIVATE KEY"!==r.type&&"RSA PRIVATE KEY"!==r.type)throw(i=new Error('Could not convert private key from PEM; PEM header type is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".')).headerType=i,i;if(r.procType&&"ENCRYPTED"===r.procType.type){var a,o;switch(r.dekInfo.algorithm){case"DES-CBC":a=8,o=z.des.createDecryptionCipher;break;case"DES-EDE3-CBC":a=24,o=z.des.createDecryptionCipher;break;case"AES-128-CBC":a=16,o=z.aes.createDecryptionCipher;break;case"AES-192-CBC":a=24,o=z.aes.createDecryptionCipher;break;case"AES-256-CBC":a=32,o=z.aes.createDecryptionCipher;break;case"RC2-40-CBC":a=5,o=function(e){return z.rc2.createDecryptionCipher(e,40)};break;case"RC2-64-CBC":a=8,o=function(e){return z.rc2.createDecryptionCipher(e,64)};break;case"RC2-128-CBC":a=16,o=function(e){return z.rc2.createDecryptionCipher(e,128)};break;default:var i;throw(i=new Error('Could not decrypt private key; unsupported encryption algorithm "'+r.dekInfo.algorithm+'".')).algorithm=r.dekInfo.algorithm,i}var s=z.util.hexToBytes(r.dekInfo.parameters),u=o(z.pbe.opensslDeriveBytes(t,s.substr(0,8),a));if(u.start(s),u.update(z.util.createBuffer(r.body)),!u.finish())return n;n=u.output.getBytes()}else n=r.body;return null!==(n="ENCRYPTED PRIVATE KEY"===r.type?gt.decryptPrivateKeyInfo(mt.fromDer(n),t):mt.fromDer(n))&&(n=gt.privateKeyFromAsn1(n)),n},gt.pbe.generatePkcs12Key=function(e,t,n,r,a,o){var i,s;if(null==o){if(!("sha1"in z.md))throw new Error('"sha1" hash algorithm unavailable.');o=z.md.sha1.create()}var u=o.digestLength,c=o.blockLength,l=new z.util.ByteBuffer,p=new z.util.ByteBuffer;if(null!=e){for(s=0;s<e.length;s++)p.putInt16(e.charCodeAt(s));p.putInt16(0)}var d=p.length(),f=t.length(),h=new z.util.ByteBuffer;h.fillWithByte(n,c);var m=c*Math.ceil(f/c),g=new z.util.ByteBuffer;for(s=0;s<m;s++)g.putByte(t.at(s%f));var v=c*Math.ceil(d/c),y=new z.util.ByteBuffer;for(s=0;s<v;s++)y.putByte(p.at(s%d));var b=g;b.putBuffer(y);for(var x=Math.ceil(a/u),w=1;w<=x;w++){var k=new z.util.ByteBuffer;k.putBytes(h.bytes()),k.putBytes(b.bytes());for(var S=0;S<r;S++)o.start(),o.update(k.getBytes()),k=o.digest();var E=new z.util.ByteBuffer;for(s=0;s<c;s++)E.putByte(k.at(s%u));var I=Math.ceil(f/c)+Math.ceil(d/c),C=new z.util.ByteBuffer;for(i=0;i<I;i++){var T=new z.util.ByteBuffer(b.getBytes(c)),_=511;for(s=E.length()-1;s>=0;s--)_>>=8,_+=E.at(s)+T.at(s),T.setAt(s,255&_);C.putBuffer(T)}b=C,l.putBuffer(k)}return l.truncate(l.length()-a),l},gt.pbe.getCipher=function(e,t,n){switch(e){case gt.oids.pkcs5PBES2:return gt.pbe.getCipherForPBES2(e,t,n);case gt.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:case gt.oids["pbewithSHAAnd40BitRC2-CBC"]:return gt.pbe.getCipherForPKCS12PBE(e,t,n);default:var r=new Error("Cannot read encrypted PBE data block. Unsupported OID.");throw r.oid=e,r.supportedOids=["pkcs5PBES2","pbeWithSHAAnd3-KeyTripleDES-CBC","pbewithSHAAnd40BitRC2-CBC"],r}},gt.pbe.getCipherForPBES2=function(e,t,n){var r,a={},o=[];if(!mt.validate(t,bt,a,o))throw(r=new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.")).errors=o,r;if((e=mt.derToOid(a.kdfOid))!==gt.oids.pkcs5PBKDF2)throw(r=new Error("Cannot read encrypted private key. Unsupported key derivation function OID.")).oid=e,r.supportedOids=["pkcs5PBKDF2"],r;if((e=mt.derToOid(a.encOid))!==gt.oids["aes128-CBC"]&&e!==gt.oids["aes192-CBC"]&&e!==gt.oids["aes256-CBC"]&&e!==gt.oids["des-EDE3-CBC"]&&e!==gt.oids.desCBC)throw(r=new Error("Cannot read encrypted private key. Unsupported encryption scheme OID.")).oid=e,r.supportedOids=["aes128-CBC","aes192-CBC","aes256-CBC","des-EDE3-CBC","desCBC"],r;var i,s,u=a.kdfSalt,c=z.util.createBuffer(a.kdfIterationCount);switch(c=c.getInt(c.length()<<3),gt.oids[e]){case"aes128-CBC":i=16,s=z.aes.createDecryptionCipher;break;case"aes192-CBC":i=24,s=z.aes.createDecryptionCipher;break;case"aes256-CBC":i=32,s=z.aes.createDecryptionCipher;break;case"des-EDE3-CBC":i=24,s=z.des.createDecryptionCipher;break;case"desCBC":i=8,s=z.des.createDecryptionCipher}var l=kt(a.prfOid),p=z.pkcs5.pbkdf2(n,u,c,i,l),d=a.encIv,f=s(p);return f.start(d),f},gt.pbe.getCipherForPKCS12PBE=function(e,t,n){var r={},a=[];if(!mt.validate(t,xt,r,a))throw(l=new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.")).errors=a,l;var o,i,s,u=z.util.createBuffer(r.salt),c=z.util.createBuffer(r.iterations);switch(c=c.getInt(c.length()<<3),e){case gt.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:o=24,i=8,s=z.des.startDecrypting;break;case gt.oids["pbewithSHAAnd40BitRC2-CBC"]:o=5,i=8,s=function(e,t){var n=z.rc2.createDecryptionCipher(e,40);return n.start(t,null),n};break;default:var l;throw(l=new Error("Cannot read PKCS #12 PBE data block. Unsupported OID.")).oid=e,l}var p=kt(r.prfOid),d=gt.pbe.generatePkcs12Key(n,u,1,c,o,p);return p.start(),s(d,gt.pbe.generatePkcs12Key(n,u,2,c,i,p))},gt.pbe.opensslDeriveBytes=function(e,t,n,r){if(null==r){if(!("md5"in z.md))throw new Error('"md5" hash algorithm unavailable.');r=z.md.md5.create()}null===t&&(t="");for(var a=[wt(r,e+t)],o=16,i=1;o<n;++i,o+=16)a.push(wt(r,a[i-1]+e+t));return a.join("").substr(0,n)},w((function(e){var t=z.asn1,n=e.exports=z.pkcs7asn1=z.pkcs7asn1||{};z.pkcs7=z.pkcs7||{},z.pkcs7.asn1=n;var r={name:"ContentInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"ContentInfo.ContentType",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"contentType"},{name:"ContentInfo.content",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,captureAsn1:"content"}]};n.contentInfoValidator=r;var a={name:"EncryptedContentInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedContentInfo.contentType",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"contentType"},{name:"EncryptedContentInfo.contentEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedContentInfo.contentEncryptionAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"encAlgorithm"},{name:"EncryptedContentInfo.contentEncryptionAlgorithm.parameter",tagClass:t.Class.UNIVERSAL,captureAsn1:"encParameter"}]},{name:"EncryptedContentInfo.encryptedContent",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,capture:"encryptedContent",captureAsn1:"encryptedContentAsn1"}]};n.envelopedDataValidator={name:"EnvelopedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EnvelopedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"EnvelopedData.RecipientInfos",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,captureAsn1:"recipientInfos"}].concat(a)},n.encryptedDataValidator={name:"EncryptedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"}].concat(a)};var o={name:"SignerInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1},{name:"SignerInfo.issuerAndSerialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.issuerAndSerialNumber.issuer",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"issuer"},{name:"SignerInfo.issuerAndSerialNumber.serialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"serial"}]},{name:"SignerInfo.digestAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.digestAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"digestAlgorithm"},{name:"SignerInfo.digestAlgorithm.parameter",tagClass:t.Class.UNIVERSAL,constructed:!1,captureAsn1:"digestParameter",optional:!0}]},{name:"SignerInfo.authenticatedAttributes",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,capture:"authenticatedAttributes"},{name:"SignerInfo.digestEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,capture:"signatureAlgorithm"},{name:"SignerInfo.encryptedDigest",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"signature"},{name:"SignerInfo.unauthenticatedAttributes",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0,capture:"unauthenticatedAttributes"}]};n.signedDataValidator={name:"SignedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"SignedData.DigestAlgorithms",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,captureAsn1:"digestAlgorithms"},r,{name:"SignedData.Certificates",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,optional:!0,captureAsn1:"certificates"},{name:"SignedData.CertificateRevocationLists",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,optional:!0,captureAsn1:"crls"},{name:"SignedData.SignerInfos",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,capture:"signerInfos",optional:!0,value:[o]}]},n.recipientInfoValidator={name:"RecipientInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"RecipientInfo.issuerAndSerial",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.issuerAndSerial.issuer",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"issuer"},{name:"RecipientInfo.issuerAndSerial.serialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"serial"}]},{name:"RecipientInfo.keyEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.keyEncryptionAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"encAlgorithm"},{name:"RecipientInfo.keyEncryptionAlgorithm.parameter",tagClass:t.Class.UNIVERSAL,constructed:!1,captureAsn1:"encParameter"}]},{name:"RecipientInfo.encryptedKey",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"encKey"}]}})),w((function(e){z.mgf=z.mgf||{},(e.exports=z.mgf.mgf1=z.mgf1=z.mgf1||{}).create=function(e){return{generate:function(t,n){for(var r=new z.util.ByteBuffer,a=Math.ceil(n/e.digestLength),o=0;o<a;o++){var i=new z.util.ByteBuffer;i.putInt32(o),e.start(),e.update(t+i.getBytes()),r.putBuffer(e.digest())}return r.truncate(r.length()-n),r.getBytes()}}}})),z.mgf=z.mgf||{},z.mgf.mgf1=z.mgf1,w((function(e){(e.exports=z.pss=z.pss||{}).create=function(e){3===arguments.length&&(e={md:arguments[0],mgf:arguments[1],saltLength:arguments[2]});var t,n=e.md,r=e.mgf,a=n.digestLength,o=e.salt||null;if("string"==typeof o&&(o=z.util.createBuffer(o)),"saltLength"in e)t=e.saltLength;else{if(null===o)throw new Error("Salt length not specified or specific salt not given.");t=o.length()}if(null!==o&&o.length()!==t)throw new Error("Given salt length does not match length of given salt.");var i=e.prng||z.random;return{encode:function(e,s){var u,c,l=s-1,p=Math.ceil(l/8),d=e.digest().getBytes();if(p<a+t+2)throw new Error("Message is too long to encrypt.");c=null===o?i.getBytesSync(t):o.bytes();var f=new z.util.ByteBuffer;f.fillWithByte(0,8),f.putBytes(d),f.putBytes(c),n.start(),n.update(f.getBytes());var h=n.digest().getBytes(),m=new z.util.ByteBuffer;m.fillWithByte(0,p-t-a-2),m.putByte(1),m.putBytes(c);var g=m.getBytes(),v=p-a-1,y=r.generate(h,v),b="";for(u=0;u<v;u++)b+=String.fromCharCode(g.charCodeAt(u)^y.charCodeAt(u));var x=65280>>8*p-l&255;return(b=String.fromCharCode(b.charCodeAt(0)&~x)+b.substr(1))+h+String.fromCharCode(188)},verify:function(e,o,i){var s,u=i-1,c=Math.ceil(u/8);if(o=o.substr(-c),c<a+t+2)throw new Error("Inconsistent parameters to PSS signature verification.");if(188!==o.charCodeAt(c-1))throw new Error("Encoded message does not end in 0xBC.");var l=c-a-1,p=o.substr(0,l),d=o.substr(l,a),f=65280>>8*c-u&255;if(0!=(p.charCodeAt(0)&f))throw new Error("Bits beyond keysize not zero as expected.");var h=r.generate(d,l),m="";for(s=0;s<l;s++)m+=String.fromCharCode(p.charCodeAt(s)^h.charCodeAt(s));m=String.fromCharCode(m.charCodeAt(0)&~f)+m.substr(1);var g=c-a-t-2;for(s=0;s<g;s++)if(0!==m.charCodeAt(s))throw new Error("Leftmost octets not zero as expected");if(1!==m.charCodeAt(g))throw new Error("Inconsistent PSS signature, 0x01 marker not found");var v=m.substr(-t),y=new z.util.ByteBuffer;return y.fillWithByte(0,8),y.putBytes(e),y.putBytes(v),n.start(),n.update(y.getBytes()),d===n.digest().getBytes()}}}})),w((function(e){var t=z.asn1,n=e.exports=z.pki=z.pki||{},r=n.oids,a={};a.CN=r.commonName,a.commonName="CN",a.C=r.countryName,a.countryName="C",a.L=r.localityName,a.localityName="L",a.ST=r.stateOrProvinceName,a.stateOrProvinceName="ST",a.O=r.organizationName,a.organizationName="O",a.OU=r.organizationalUnitName,a.organizationalUnitName="OU",a.E=r.emailAddress,a.emailAddress="E";var o=z.pki.rsa.publicKeyValidator,i={name:"Certificate",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"tbsCertificate",value:[{name:"Certificate.TBSCertificate.version",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.version.integer",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"certVersion"}]},{name:"Certificate.TBSCertificate.serialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"certSerialNumber"},{name:"Certificate.TBSCertificate.signature",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.signature.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"certinfoSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:t.Class.UNIVERSAL,optional:!0,captureAsn1:"certinfoSignatureParams"}]},{name:"Certificate.TBSCertificate.issuer",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"certIssuer"},{name:"Certificate.TBSCertificate.validity",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.validity.notBefore (utc)",tagClass:t.Class.UNIVERSAL,type:t.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity1UTCTime"},{name:"Certificate.TBSCertificate.validity.notBefore (generalized)",tagClass:t.Class.UNIVERSAL,type:t.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity2GeneralizedTime"},{name:"Certificate.TBSCertificate.validity.notAfter (utc)",tagClass:t.Class.UNIVERSAL,type:t.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity3UTCTime"},{name:"Certificate.TBSCertificate.validity.notAfter (generalized)",tagClass:t.Class.UNIVERSAL,type:t.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity4GeneralizedTime"}]},{name:"Certificate.TBSCertificate.subject",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"certSubject"},o,{name:"Certificate.TBSCertificate.issuerUniqueID",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.issuerUniqueID.id",tagClass:t.Class.UNIVERSAL,type:t.Type.BITSTRING,constructed:!1,captureBitStringValue:"certIssuerUniqueId"}]},{name:"Certificate.TBSCertificate.subjectUniqueID",tagClass:t.Class.CONTEXT_SPECIFIC,type:2,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.subjectUniqueID.id",tagClass:t.Class.UNIVERSAL,type:t.Type.BITSTRING,constructed:!1,captureBitStringValue:"certSubjectUniqueId"}]},{name:"Certificate.TBSCertificate.extensions",tagClass:t.Class.CONTEXT_SPECIFIC,type:3,constructed:!0,captureAsn1:"certExtensions",optional:!0}]},{name:"Certificate.signatureAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.signatureAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"certSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:t.Class.UNIVERSAL,optional:!0,captureAsn1:"certSignatureParams"}]},{name:"Certificate.signatureValue",tagClass:t.Class.UNIVERSAL,type:t.Type.BITSTRING,constructed:!1,captureBitStringValue:"certSignature"}]},s={name:"rsapss",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.hashAlgorithm",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier",tagClass:t.Class.UNIVERSAL,type:t.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"hashOid"}]}]},{name:"rsapss.maskGenAlgorithm",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier",tagClass:t.Class.UNIVERSAL,type:t.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"maskGenOid"},{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"maskGenHashOid"}]}]}]},{name:"rsapss.saltLength",tagClass:t.Class.CONTEXT_SPECIFIC,type:2,optional:!0,value:[{name:"rsapss.saltLength.saltLength",tagClass:t.Class.UNIVERSAL,type:t.Class.INTEGER,constructed:!1,capture:"saltLength"}]},{name:"rsapss.trailerField",tagClass:t.Class.CONTEXT_SPECIFIC,type:3,optional:!0,value:[{name:"rsapss.trailer.trailer",tagClass:t.Class.UNIVERSAL,type:t.Class.INTEGER,constructed:!1,capture:"trailer"}]}]},u={name:"CertificationRequestInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"certificationRequestInfo",value:[{name:"CertificationRequestInfo.integer",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"certificationRequestInfoVersion"},{name:"CertificationRequestInfo.subject",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"certificationRequestInfoSubject"},o,{name:"CertificationRequestInfo.attributes",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,capture:"certificationRequestInfoAttributes",value:[{name:"CertificationRequestInfo.attributes",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"CertificationRequestInfo.attributes.type",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1},{name:"CertificationRequestInfo.attributes.value",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0}]}]}]},c={name:"CertificationRequest",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"csr",value:[u,{name:"CertificationRequest.signatureAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"CertificationRequest.signatureAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"csrSignatureOid"},{name:"CertificationRequest.signatureAlgorithm.parameters",tagClass:t.Class.UNIVERSAL,optional:!0,captureAsn1:"csrSignatureParams"}]},{name:"CertificationRequest.signature",tagClass:t.Class.UNIVERSAL,type:t.Type.BITSTRING,constructed:!1,captureBitStringValue:"csrSignature"}]};function l(e,t){"string"==typeof t&&(t={shortName:t});for(var n,r=null,a=0;null===r&&a<e.attributes.length;++a)n=e.attributes[a],(t.type&&t.type===n.type||t.name&&t.name===n.name||t.shortName&&t.shortName===n.shortName)&&(r=n);return r}n.RDNAttributesAsArray=function(e,n){for(var o,i,s,u=[],c=0;c<e.value.length;++c){o=e.value[c];for(var l=0;l<o.value.length;++l)s={},i=o.value[l],s.type=t.derToOid(i.value[0].value),s.value=i.value[1].value,s.valueTagClass=i.value[1].type,s.type in r&&(s.name=r[s.type],s.name in a&&(s.shortName=a[s.name])),n&&(n.update(s.type),n.update(s.value)),u.push(s)}return u},n.CRIAttributesAsArray=function(e){for(var o=[],i=0;i<e.length;++i)for(var s=e[i],u=t.derToOid(s.value[0].value),c=s.value[1].value,l=0;l<c.length;++l){var p={};if(p.type=u,p.value=c[l].value,p.valueTagClass=c[l].type,p.type in r&&(p.name=r[p.type],p.name in a&&(p.shortName=a[p.name])),p.type===r.extensionRequest){p.extensions=[];for(var d=0;d<p.value.length;++d)p.extensions.push(n.certificateExtensionFromAsn1(p.value[d]))}o.push(p)}return o};var p=function(e,n,a){var o={};if(e!==r["RSASSA-PSS"])return o;a&&(o={hash:{algorithmOid:r.sha1},mgf:{algorithmOid:r.mgf1,hash:{algorithmOid:r.sha1}},saltLength:20});var i={},u=[];if(!t.validate(n,s,i,u)){var c=new Error("Cannot read RSASSA-PSS parameter block.");throw c.errors=u,c}return void 0!==i.hashOid&&(o.hash=o.hash||{},o.hash.algorithmOid=t.derToOid(i.hashOid)),void 0!==i.maskGenOid&&(o.mgf=o.mgf||{},o.mgf.algorithmOid=t.derToOid(i.maskGenOid),o.mgf.hash=o.mgf.hash||{},o.mgf.hash.algorithmOid=t.derToOid(i.maskGenHashOid)),void 0!==i.saltLength&&(o.saltLength=i.saltLength.charCodeAt(0)),o};function d(e){for(var n,r,a=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),o=e.attributes,i=0;i<o.length;++i){var s=(n=o[i]).value,u=t.Type.PRINTABLESTRING;"valueTagClass"in n&&(u=n.valueTagClass)===t.Type.UTF8&&(s=z.util.encodeUtf8(s)),r=t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.type).getBytes()),t.create(t.Class.UNIVERSAL,u,!1,s)])]),a.value.push(r)}return a}function f(e){for(var o,i=0;i<e.length;++i){if(void 0===(o=e[i]).name&&(o.type&&o.type in n.oids?o.name=n.oids[o.type]:o.shortName&&o.shortName in a&&(o.name=n.oids[a[o.shortName]])),void 0===o.type){if(!o.name||!(o.name in n.oids))throw(u=new Error("Attribute type not specified.")).attribute=o,u;o.type=n.oids[o.name]}if(void 0===o.shortName&&o.name&&o.name in a&&(o.shortName=a[o.name]),o.type===r.extensionRequest&&(o.valueConstructed=!0,o.valueTagClass=t.Type.SEQUENCE,!o.value&&o.extensions)){o.value=[];for(var s=0;s<o.extensions.length;++s)o.value.push(n.certificateExtensionToAsn1(h(o.extensions[s])))}var u;if(void 0===o.value)throw(u=new Error("Attribute value not specified.")).attribute=o,u}}function h(e,a){if(a=a||{},void 0===e.name&&e.id&&e.id in n.oids&&(e.name=n.oids[e.id]),void 0===e.id){if(!e.name||!(e.name in n.oids))throw(x=new Error("Extension ID not specified.")).extension=e,x;e.id=n.oids[e.name]}if(void 0!==e.value)return e;if("keyUsage"===e.name){var o=0,i=0,s=0;e.digitalSignature&&(i|=128,o=7),e.nonRepudiation&&(i|=64,o=6),e.keyEncipherment&&(i|=32,o=5),e.dataEncipherment&&(i|=16,o=4),e.keyAgreement&&(i|=8,o=3),e.keyCertSign&&(i|=4,o=2),e.cRLSign&&(i|=2,o=1),e.encipherOnly&&(i|=1,o=0),e.decipherOnly&&(s|=128,o=7);var u=String.fromCharCode(o);0!==s?u+=String.fromCharCode(i)+String.fromCharCode(s):0!==i&&(u+=String.fromCharCode(i)),e.value=t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,u)}else if("basicConstraints"===e.name)e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),e.cA&&e.value.value.push(t.create(t.Class.UNIVERSAL,t.Type.BOOLEAN,!1,String.fromCharCode(255))),"pathLenConstraint"in e&&e.value.value.push(t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.pathLenConstraint).getBytes()));else if("extKeyUsage"===e.name){e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]);var c=e.value.value;for(var l in e)!0===e[l]&&(l in r?c.push(t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(r[l]).getBytes())):-1!==l.indexOf(".")&&c.push(t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(l).getBytes())))}else if("nsCertType"===e.name)o=0,i=0,e.client&&(i|=128,o=7),e.server&&(i|=64,o=6),e.email&&(i|=32,o=5),e.objsign&&(i|=16,o=4),e.reserved&&(i|=8,o=3),e.sslCA&&(i|=4,o=2),e.emailCA&&(i|=2,o=1),e.objCA&&(i|=1,o=0),u=String.fromCharCode(o),0!==i&&(u+=String.fromCharCode(i)),e.value=t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,u);else if("subjectAltName"===e.name||"issuerAltName"===e.name){e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]);for(var p=0;p<e.altNames.length;++p){if(u=(v=e.altNames[p]).value,7===v.type&&v.ip){if(null===(u=z.util.bytesFromIP(v.ip)))throw(x=new Error('Extension "ip" value is not a valid IPv4 or IPv6 address.')).extension=e,x}else 8===v.type&&(u=v.oid?t.oidToDer(t.oidToDer(v.oid)):t.oidToDer(u));e.value.value.push(t.create(t.Class.CONTEXT_SPECIFIC,v.type,!1,u))}}else if("nsComment"===e.name&&a.cert){if(!/^[\x00-\x7F]*$/.test(e.comment)||e.comment.length<1||e.comment.length>128)throw new Error('Invalid "nsComment" content.');e.value=t.create(t.Class.UNIVERSAL,t.Type.IA5STRING,!1,e.comment)}else if("subjectKeyIdentifier"===e.name&&a.cert){var f=a.cert.generateSubjectKeyIdentifier();e.subjectKeyIdentifier=f.toHex(),e.value=t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,f.getBytes())}else if("authorityKeyIdentifier"===e.name&&a.cert){if(e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),c=e.value.value,e.keyIdentifier){var h=!0===e.keyIdentifier?a.cert.generateSubjectKeyIdentifier().getBytes():e.keyIdentifier;c.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!1,h))}if(e.authorityCertIssuer){var m=[t.create(t.Class.CONTEXT_SPECIFIC,4,!0,[d(!0===e.authorityCertIssuer?a.cert.issuer:e.authorityCertIssuer)])];c.push(t.create(t.Class.CONTEXT_SPECIFIC,1,!0,m))}if(e.serialNumber){var g=z.util.hexToBytes(!0===e.serialNumber?a.cert.serialNumber:e.serialNumber);c.push(t.create(t.Class.CONTEXT_SPECIFIC,2,!1,g))}}else if("cRLDistributionPoints"===e.name){e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),c=e.value.value;var v,y=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),b=t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[]);for(p=0;p<e.altNames.length;++p){if(u=(v=e.altNames[p]).value,7===v.type&&v.ip){if(null===(u=z.util.bytesFromIP(v.ip)))throw(x=new Error('Extension "ip" value is not a valid IPv4 or IPv6 address.')).extension=e,x}else 8===v.type&&(u=v.oid?t.oidToDer(t.oidToDer(v.oid)):t.oidToDer(u));b.value.push(t.create(t.Class.CONTEXT_SPECIFIC,v.type,!1,u))}y.value.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[b])),c.push(y)}var x;if(void 0===e.value)throw(x=new Error("Extension value not specified.")).extension=e,x;return e}function m(e,n){switch(e){case r["RSASSA-PSS"]:var a=[];return void 0!==n.hash.algorithmOid&&a.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.hash.algorithmOid).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")])])),void 0!==n.mgf.algorithmOid&&a.push(t.create(t.Class.CONTEXT_SPECIFIC,1,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.mgf.algorithmOid).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.mgf.hash.algorithmOid).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")])])])),void 0!==n.saltLength&&a.push(t.create(t.Class.CONTEXT_SPECIFIC,2,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(n.saltLength).getBytes())])),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,a);default:return t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")}}function g(e){var n=t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[]);if(0===e.attributes.length)return n;for(var r=e.attributes,a=0;a<r.length;++a){var o=r[a],i=o.value,s=t.Type.UTF8;"valueTagClass"in o&&(s=o.valueTagClass),s===t.Type.UTF8&&(i=z.util.encodeUtf8(i));var u=!1;"valueConstructed"in o&&(u=o.valueConstructed);var c=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(o.type).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[t.create(t.Class.UNIVERSAL,s,u,i)])]);n.value.push(c)}return n}n.certificateFromPem=function(e,r,a){var o=z.pem.decode(e)[0];if("CERTIFICATE"!==o.type&&"X509 CERTIFICATE"!==o.type&&"TRUSTED CERTIFICATE"!==o.type){var i=new Error('Could not convert certificate from PEM; PEM header type is not "CERTIFICATE", "X509 CERTIFICATE", or "TRUSTED CERTIFICATE".');throw i.headerType=o.type,i}if(o.procType&&"ENCRYPTED"===o.procType.type)throw new Error("Could not convert certificate from PEM; PEM is encrypted.");var s=t.fromDer(o.body,a);return n.certificateFromAsn1(s,r)},n.certificateToPem=function(e,r){var a={type:"CERTIFICATE",body:t.toDer(n.certificateToAsn1(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.publicKeyFromPem=function(e){var r=z.pem.decode(e)[0];if("PUBLIC KEY"!==r.type&&"RSA PUBLIC KEY"!==r.type){var a=new Error('Could not convert public key from PEM; PEM header type is not "PUBLIC KEY" or "RSA PUBLIC KEY".');throw a.headerType=r.type,a}if(r.procType&&"ENCRYPTED"===r.procType.type)throw new Error("Could not convert public key from PEM; PEM is encrypted.");var o=t.fromDer(r.body);return n.publicKeyFromAsn1(o)},n.publicKeyToPem=function(e,r){var a={type:"PUBLIC KEY",body:t.toDer(n.publicKeyToAsn1(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.publicKeyToRSAPublicKeyPem=function(e,r){var a={type:"RSA PUBLIC KEY",body:t.toDer(n.publicKeyToRSAPublicKey(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.getPublicKeyFingerprint=function(e,r){var a,o=(r=r||{}).md||z.md.sha1.create();switch(r.type||"RSAPublicKey"){case"RSAPublicKey":a=t.toDer(n.publicKeyToRSAPublicKey(e)).getBytes();break;case"SubjectPublicKeyInfo":a=t.toDer(n.publicKeyToAsn1(e)).getBytes();break;default:throw new Error('Unknown fingerprint type "'+r.type+'".')}o.start(),o.update(a);var i=o.digest();if("hex"===r.encoding){var s=i.toHex();return r.delimiter?s.match(/.{2}/g).join(r.delimiter):s}if("binary"===r.encoding)return i.getBytes();if(r.encoding)throw new Error('Unknown encoding "'+r.encoding+'".');return i},n.certificationRequestFromPem=function(e,r,a){var o=z.pem.decode(e)[0];if("CERTIFICATE REQUEST"!==o.type){var i=new Error('Could not convert certification request from PEM; PEM header type is not "CERTIFICATE REQUEST".');throw i.headerType=o.type,i}if(o.procType&&"ENCRYPTED"===o.procType.type)throw new Error("Could not convert certification request from PEM; PEM is encrypted.");var s=t.fromDer(o.body,a);return n.certificationRequestFromAsn1(s,r)},n.certificationRequestToPem=function(e,r){var a={type:"CERTIFICATE REQUEST",body:t.toDer(n.certificationRequestToAsn1(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.createCertificate=function(){var e={version:2,serialNumber:"00",signatureOid:null,signature:null,siginfo:{}};return e.siginfo.algorithmOid=null,e.validity={},e.validity.notBefore=new Date,e.validity.notAfter=new Date,e.issuer={},e.issuer.getField=function(t){return l(e.issuer,t)},e.issuer.addField=function(t){f([t]),e.issuer.attributes.push(t)},e.issuer.attributes=[],e.issuer.hash=null,e.subject={},e.subject.getField=function(t){return l(e.subject,t)},e.subject.addField=function(t){f([t]),e.subject.attributes.push(t)},e.subject.attributes=[],e.subject.hash=null,e.extensions=[],e.publicKey=null,e.md=null,e.setSubject=function(t,n){f(t),e.subject.attributes=t,delete e.subject.uniqueId,n&&(e.subject.uniqueId=n),e.subject.hash=null},e.setIssuer=function(t,n){f(t),e.issuer.attributes=t,delete e.issuer.uniqueId,n&&(e.issuer.uniqueId=n),e.issuer.hash=null},e.setExtensions=function(t){for(var n=0;n<t.length;++n)h(t[n],{cert:e});e.extensions=t},e.getExtension=function(t){"string"==typeof t&&(t={name:t});for(var n,r=null,a=0;null===r&&a<e.extensions.length;++a)n=e.extensions[a],(t.id&&n.id===t.id||t.name&&n.name===t.name)&&(r=n);return r},e.sign=function(a,o){e.md=o||z.md.sha1.create();var i=r[e.md.algorithm+"WithRSAEncryption"];if(!i){var s=new Error("Could not compute certificate digest. Unknown message digest algorithm OID.");throw s.algorithm=e.md.algorithm,s}e.signatureOid=e.siginfo.algorithmOid=i,e.tbsCertificate=n.getTBSCertificate(e);var u=t.toDer(e.tbsCertificate);e.md.update(u.getBytes()),e.signature=a.sign(e.md)},e.verify=function(a){var o=!1;if(!e.issued(a)){var i=a.issuer,s=e.subject;throw(h=new Error("The parent certificate did not issue the given child certificate; the child certificate's issuer does not match the parent's subject.")).expectedIssuer=i.attributes,h.actualIssuer=s.attributes,h}var u=a.md;if(null===u){if(a.signatureOid in r)switch(r[a.signatureOid]){case"sha1WithRSAEncryption":u=z.md.sha1.create();break;case"md5WithRSAEncryption":u=z.md.md5.create();break;case"sha256WithRSAEncryption":u=z.md.sha256.create();break;case"sha384WithRSAEncryption":u=z.md.sha384.create();break;case"sha512WithRSAEncryption":u=z.md.sha512.create();break;case"RSASSA-PSS":u=z.md.sha256.create()}if(null===u)throw(h=new Error("Could not compute certificate digest. Unknown signature OID.")).signatureOid=a.signatureOid,h;var c=a.tbsCertificate||n.getTBSCertificate(a),l=t.toDer(c);u.update(l.getBytes())}if(null!==u){var p;switch(a.signatureOid){case r.sha1WithRSAEncryption:p=void 0;break;case r["RSASSA-PSS"]:var d,f,h;if(void 0===(d=r[a.signatureParameters.mgf.hash.algorithmOid])||void 0===z.md[d])throw(h=new Error("Unsupported MGF hash function.")).oid=a.signatureParameters.mgf.hash.algorithmOid,h.name=d,h;if(void 0===(f=r[a.signatureParameters.mgf.algorithmOid])||void 0===z.mgf[f])throw(h=new Error("Unsupported MGF function.")).oid=a.signatureParameters.mgf.algorithmOid,h.name=f,h;if(f=z.mgf[f].create(z.md[d].create()),void 0===(d=r[a.signatureParameters.hash.algorithmOid])||void 0===z.md[d])throw{message:"Unsupported RSASSA-PSS hash function.",oid:a.signatureParameters.hash.algorithmOid,name:d};p=z.pss.create(z.md[d].create(),f,a.signatureParameters.saltLength)}o=e.publicKey.verify(u.digest().getBytes(),a.signature,p)}return o},e.isIssuer=function(t){var n=!1,r=e.issuer,a=t.subject;if(r.hash&&a.hash)n=r.hash===a.hash;else if(r.attributes.length===a.attributes.length){var o,i;n=!0;for(var s=0;n&&s<r.attributes.length;++s)o=r.attributes[s],i=a.attributes[s],o.type===i.type&&o.value===i.value||(n=!1)}return n},e.issued=function(t){return t.isIssuer(e)},e.generateSubjectKeyIdentifier=function(){return n.getPublicKeyFingerprint(e.publicKey,{type:"RSAPublicKey"})},e.verifySubjectKeyIdentifier=function(){for(var t=r.subjectKeyIdentifier,n=0;n<e.extensions.length;++n){var a=e.extensions[n];if(a.id===t){var o=e.generateSubjectKeyIdentifier().getBytes();return z.util.hexToBytes(a.subjectKeyIdentifier)===o}}return!1},e},n.certificateFromAsn1=function(e,a){var o={},s=[];if(!t.validate(e,i,o,s))throw(h=new Error("Cannot read X.509 certificate. ASN.1 object is not an X509v3 Certificate.")).errors=s,h;if(t.derToOid(o.publicKeyOid)!==n.oids.rsaEncryption)throw new Error("Cannot read public key. OID is not RSA.");var u=n.createCertificate();u.version=o.certVersion?o.certVersion.charCodeAt(0):0;var c=z.util.createBuffer(o.certSerialNumber);u.serialNumber=c.toHex(),u.signatureOid=z.asn1.derToOid(o.certSignatureOid),u.signatureParameters=p(u.signatureOid,o.certSignatureParams,!0),u.siginfo.algorithmOid=z.asn1.derToOid(o.certinfoSignatureOid),u.siginfo.parameters=p(u.siginfo.algorithmOid,o.certinfoSignatureParams,!1),u.signature=o.certSignature;var d=[];if(void 0!==o.certValidity1UTCTime&&d.push(t.utcTimeToDate(o.certValidity1UTCTime)),void 0!==o.certValidity2GeneralizedTime&&d.push(t.generalizedTimeToDate(o.certValidity2GeneralizedTime)),void 0!==o.certValidity3UTCTime&&d.push(t.utcTimeToDate(o.certValidity3UTCTime)),void 0!==o.certValidity4GeneralizedTime&&d.push(t.generalizedTimeToDate(o.certValidity4GeneralizedTime)),d.length>2)throw new Error("Cannot read notBefore/notAfter validity times; more than two times were provided in the certificate.");if(d.length<2)throw new Error("Cannot read notBefore/notAfter validity times; they were not provided as either UTCTime or GeneralizedTime.");if(u.validity.notBefore=d[0],u.validity.notAfter=d[1],u.tbsCertificate=o.tbsCertificate,a){var h;if(u.md=null,u.signatureOid in r)switch(r[u.signatureOid]){case"sha1WithRSAEncryption":u.md=z.md.sha1.create();break;case"md5WithRSAEncryption":u.md=z.md.md5.create();break;case"sha256WithRSAEncryption":u.md=z.md.sha256.create();break;case"sha384WithRSAEncryption":u.md=z.md.sha384.create();break;case"sha512WithRSAEncryption":u.md=z.md.sha512.create();break;case"RSASSA-PSS":u.md=z.md.sha256.create()}if(null===u.md)throw(h=new Error("Could not compute certificate digest. Unknown signature OID.")).signatureOid=u.signatureOid,h;var m=t.toDer(u.tbsCertificate);u.md.update(m.getBytes())}var g=z.md.sha1.create();u.issuer.getField=function(e){return l(u.issuer,e)},u.issuer.addField=function(e){f([e]),u.issuer.attributes.push(e)},u.issuer.attributes=n.RDNAttributesAsArray(o.certIssuer,g),o.certIssuerUniqueId&&(u.issuer.uniqueId=o.certIssuerUniqueId),u.issuer.hash=g.digest().toHex();var v=z.md.sha1.create();return u.subject.getField=function(e){return l(u.subject,e)},u.subject.addField=function(e){f([e]),u.subject.attributes.push(e)},u.subject.attributes=n.RDNAttributesAsArray(o.certSubject,v),o.certSubjectUniqueId&&(u.subject.uniqueId=o.certSubjectUniqueId),u.subject.hash=v.digest().toHex(),o.certExtensions?u.extensions=n.certificateExtensionsFromAsn1(o.certExtensions):u.extensions=[],u.publicKey=n.publicKeyFromAsn1(o.subjectPublicKeyInfo),u},n.certificateExtensionsFromAsn1=function(e){for(var t=[],r=0;r<e.value.length;++r)for(var a=e.value[r],o=0;o<a.value.length;++o)t.push(n.certificateExtensionFromAsn1(a.value[o]));return t},n.certificateExtensionFromAsn1=function(e){var n={};if(n.id=t.derToOid(e.value[0].value),n.critical=!1,e.value[1].type===t.Type.BOOLEAN?(n.critical=0!==e.value[1].value.charCodeAt(0),n.value=e.value[2].value):n.value=e.value[1].value,n.id in r)if(n.name=r[n.id],"keyUsage"===n.name){var a=0,o=0;(s=t.fromDer(n.value)).value.length>1&&(a=s.value.charCodeAt(1),o=s.value.length>2?s.value.charCodeAt(2):0),n.digitalSignature=128==(128&a),n.nonRepudiation=64==(64&a),n.keyEncipherment=32==(32&a),n.dataEncipherment=16==(16&a),n.keyAgreement=8==(8&a),n.keyCertSign=4==(4&a),n.cRLSign=2==(2&a),n.encipherOnly=1==(1&a),n.decipherOnly=128==(128&o)}else if("basicConstraints"===n.name){(s=t.fromDer(n.value)).value.length>0&&s.value[0].type===t.Type.BOOLEAN?n.cA=0!==s.value[0].value.charCodeAt(0):n.cA=!1;var i=null;s.value.length>0&&s.value[0].type===t.Type.INTEGER?i=s.value[0].value:s.value.length>1&&(i=s.value[1].value),null!==i&&(n.pathLenConstraint=t.derToInteger(i))}else if("extKeyUsage"===n.name)for(var s=t.fromDer(n.value),u=0;u<s.value.length;++u){var c=t.derToOid(s.value[u].value);c in r?n[r[c]]=!0:n[c]=!0}else if("nsCertType"===n.name)a=0,(s=t.fromDer(n.value)).value.length>1&&(a=s.value.charCodeAt(1)),n.client=128==(128&a),n.server=64==(64&a),n.email=32==(32&a),n.objsign=16==(16&a),n.reserved=8==(8&a),n.sslCA=4==(4&a),n.emailCA=2==(2&a),n.objCA=1==(1&a);else if("subjectAltName"===n.name||"issuerAltName"===n.name){var l;n.altNames=[],s=t.fromDer(n.value);for(var p=0;p<s.value.length;++p){var d={type:(l=s.value[p]).type,value:l.value};switch(n.altNames.push(d),l.type){case 1:case 2:case 6:break;case 7:d.ip=z.util.bytesToIP(l.value);break;case 8:d.oid=t.derToOid(l.value)}}}else"subjectKeyIdentifier"===n.name&&(s=t.fromDer(n.value),n.subjectKeyIdentifier=z.util.bytesToHex(s.value));return n},n.certificationRequestFromAsn1=function(e,a){var o={},i=[];if(!t.validate(e,c,o,i))throw(u=new Error("Cannot read PKCS#10 certificate request. ASN.1 object is not a PKCS#10 CertificationRequest.")).errors=i,u;if(t.derToOid(o.publicKeyOid)!==n.oids.rsaEncryption)throw new Error("Cannot read public key. OID is not RSA.");var s=n.createCertificationRequest();if(s.version=o.csrVersion?o.csrVersion.charCodeAt(0):0,s.signatureOid=z.asn1.derToOid(o.csrSignatureOid),s.signatureParameters=p(s.signatureOid,o.csrSignatureParams,!0),s.siginfo.algorithmOid=z.asn1.derToOid(o.csrSignatureOid),s.siginfo.parameters=p(s.siginfo.algorithmOid,o.csrSignatureParams,!1),s.signature=o.csrSignature,s.certificationRequestInfo=o.certificationRequestInfo,a){var u;if(s.md=null,s.signatureOid in r)switch(r[s.signatureOid]){case"sha1WithRSAEncryption":s.md=z.md.sha1.create();break;case"md5WithRSAEncryption":s.md=z.md.md5.create();break;case"sha256WithRSAEncryption":s.md=z.md.sha256.create();break;case"sha384WithRSAEncryption":s.md=z.md.sha384.create();break;case"sha512WithRSAEncryption":s.md=z.md.sha512.create();break;case"RSASSA-PSS":s.md=z.md.sha256.create()}if(null===s.md)throw(u=new Error("Could not compute certification request digest. Unknown signature OID.")).signatureOid=s.signatureOid,u;var d=t.toDer(s.certificationRequestInfo);s.md.update(d.getBytes())}var h=z.md.sha1.create();return s.subject.getField=function(e){return l(s.subject,e)},s.subject.addField=function(e){f([e]),s.subject.attributes.push(e)},s.subject.attributes=n.RDNAttributesAsArray(o.certificationRequestInfoSubject,h),s.subject.hash=h.digest().toHex(),s.publicKey=n.publicKeyFromAsn1(o.subjectPublicKeyInfo),s.getAttribute=function(e){return l(s,e)},s.addAttribute=function(e){f([e]),s.attributes.push(e)},s.attributes=n.CRIAttributesAsArray(o.certificationRequestInfoAttributes||[]),s},n.createCertificationRequest=function(){var e={version:0,signatureOid:null,signature:null,siginfo:{}};return e.siginfo.algorithmOid=null,e.subject={},e.subject.getField=function(t){return l(e.subject,t)},e.subject.addField=function(t){f([t]),e.subject.attributes.push(t)},e.subject.attributes=[],e.subject.hash=null,e.publicKey=null,e.attributes=[],e.getAttribute=function(t){return l(e,t)},e.addAttribute=function(t){f([t]),e.attributes.push(t)},e.md=null,e.setSubject=function(t){f(t),e.subject.attributes=t,e.subject.hash=null},e.setAttributes=function(t){f(t),e.attributes=t},e.sign=function(a,o){e.md=o||z.md.sha1.create();var i=r[e.md.algorithm+"WithRSAEncryption"];if(!i){var s=new Error("Could not compute certification request digest. Unknown message digest algorithm OID.");throw s.algorithm=e.md.algorithm,s}e.signatureOid=e.siginfo.algorithmOid=i,e.certificationRequestInfo=n.getCertificationRequestInfo(e);var u=t.toDer(e.certificationRequestInfo);e.md.update(u.getBytes()),e.signature=a.sign(e.md)},e.verify=function(){var a=!1,o=e.md;if(null===o){if(e.signatureOid in r)switch(r[e.signatureOid]){case"sha1WithRSAEncryption":o=z.md.sha1.create();break;case"md5WithRSAEncryption":o=z.md.md5.create();break;case"sha256WithRSAEncryption":o=z.md.sha256.create();break;case"sha384WithRSAEncryption":o=z.md.sha384.create();break;case"sha512WithRSAEncryption":o=z.md.sha512.create();break;case"RSASSA-PSS":o=z.md.sha256.create()}if(null===o)throw(p=new Error("Could not compute certification request digest. Unknown signature OID.")).signatureOid=e.signatureOid,p;var i=e.certificationRequestInfo||n.getCertificationRequestInfo(e),s=t.toDer(i);o.update(s.getBytes())}if(null!==o){var u;switch(e.signatureOid){case r.sha1WithRSAEncryption:break;case r["RSASSA-PSS"]:var c,l,p;if(void 0===(c=r[e.signatureParameters.mgf.hash.algorithmOid])||void 0===z.md[c])throw(p=new Error("Unsupported MGF hash function.")).oid=e.signatureParameters.mgf.hash.algorithmOid,p.name=c,p;if(void 0===(l=r[e.signatureParameters.mgf.algorithmOid])||void 0===z.mgf[l])throw(p=new Error("Unsupported MGF function.")).oid=e.signatureParameters.mgf.algorithmOid,p.name=l,p;if(l=z.mgf[l].create(z.md[c].create()),void 0===(c=r[e.signatureParameters.hash.algorithmOid])||void 0===z.md[c])throw(p=new Error("Unsupported RSASSA-PSS hash function.")).oid=e.signatureParameters.hash.algorithmOid,p.name=c,p;u=z.pss.create(z.md[c].create(),l,e.signatureParameters.saltLength)}a=e.publicKey.verify(o.digest().getBytes(),e.signature,u)}return a},e};var v=new Date("1950-01-01T00:00:00Z"),y=new Date("2050-01-01T00:00:00Z");function b(e){return e>=v&&e<y?t.create(t.Class.UNIVERSAL,t.Type.UTCTIME,!1,t.dateToUtcTime(e)):t.create(t.Class.UNIVERSAL,t.Type.GENERALIZEDTIME,!1,t.dateToGeneralizedTime(e))}n.getTBSCertificate=function(e){var r=b(e.validity.notBefore),a=b(e.validity.notAfter),o=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes())]),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,z.util.hexToBytes(e.serialNumber)),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.siginfo.algorithmOid).getBytes()),m(e.siginfo.algorithmOid,e.siginfo.parameters)]),d(e.issuer),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[r,a]),d(e.subject),n.publicKeyToAsn1(e.publicKey)]);return e.issuer.uniqueId&&o.value.push(t.create(t.Class.CONTEXT_SPECIFIC,1,!0,[t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,String.fromCharCode(0)+e.issuer.uniqueId)])),e.subject.uniqueId&&o.value.push(t.create(t.Class.CONTEXT_SPECIFIC,2,!0,[t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,String.fromCharCode(0)+e.subject.uniqueId)])),e.extensions.length>0&&o.value.push(n.certificateExtensionsToAsn1(e.extensions)),o},n.getCertificationRequestInfo=function(e){return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes()),d(e.subject),n.publicKeyToAsn1(e.publicKey),g(e)])},n.distinguishedNameToAsn1=function(e){return d(e)},n.certificateToAsn1=function(e){var r=e.tbsCertificate||n.getTBSCertificate(e);return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[r,t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.signatureOid).getBytes()),m(e.signatureOid,e.signatureParameters)]),t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},n.certificateExtensionsToAsn1=function(e){var r=t.create(t.Class.CONTEXT_SPECIFIC,3,!0,[]),a=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]);r.value.push(a);for(var o=0;o<e.length;++o)a.value.push(n.certificateExtensionToAsn1(e[o]));return r},n.certificateExtensionToAsn1=function(e){var n=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]);n.value.push(t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.id).getBytes())),e.critical&&n.value.push(t.create(t.Class.UNIVERSAL,t.Type.BOOLEAN,!1,String.fromCharCode(255)));var r=e.value;return"string"!=typeof e.value&&(r=t.toDer(r).getBytes()),n.value.push(t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r)),n},n.certificationRequestToAsn1=function(e){var r=e.certificationRequestInfo||n.getCertificationRequestInfo(e);return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[r,t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.signatureOid).getBytes()),m(e.signatureOid,e.signatureParameters)]),t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},n.createCaStore=function(e){var r={certs:{}};function a(e){return o(e),r.certs[e.hash]||null}function o(e){if(!e.hash){var t=z.md.sha1.create();e.attributes=n.RDNAttributesAsArray(d(e),t),e.hash=t.digest().toHex()}}if(r.getIssuer=function(e){return a(e.issuer)},r.addCertificate=function(e){if("string"==typeof e&&(e=z.pki.certificateFromPem(e)),o(e.subject),!r.hasCertificate(e))if(e.subject.hash in r.certs){var t=r.certs[e.subject.hash];z.util.isArray(t)||(t=[t]),t.push(e),r.certs[e.subject.hash]=t}else r.certs[e.subject.hash]=e},r.hasCertificate=function(e){"string"==typeof e&&(e=z.pki.certificateFromPem(e));var r=a(e.subject);if(!r)return!1;z.util.isArray(r)||(r=[r]);for(var o=t.toDer(n.certificateToAsn1(e)).getBytes(),i=0;i<r.length;++i)if(o===t.toDer(n.certificateToAsn1(r[i])).getBytes())return!0;return!1},r.listAllCertificates=function(){var e=[];for(var t in r.certs)if(r.certs.hasOwnProperty(t)){var n=r.certs[t];if(z.util.isArray(n))for(var a=0;a<n.length;++a)e.push(n[a]);else e.push(n)}return e},r.removeCertificate=function(e){var i;if("string"==typeof e&&(e=z.pki.certificateFromPem(e)),o(e.subject),!r.hasCertificate(e))return null;var s=a(e.subject);if(!z.util.isArray(s))return i=r.certs[e.subject.hash],delete r.certs[e.subject.hash],i;for(var u=t.toDer(n.certificateToAsn1(e)).getBytes(),c=0;c<s.length;++c)u===t.toDer(n.certificateToAsn1(s[c])).getBytes()&&(i=s[c],s.splice(c,1));return 0===s.length&&delete r.certs[e.subject.hash],i},e)for(var i=0;i<e.length;++i){var s=e[i];r.addCertificate(s)}return r},n.certificateError={bad_certificate:"forge.pki.BadCertificate",unsupported_certificate:"forge.pki.UnsupportedCertificate",certificate_revoked:"forge.pki.CertificateRevoked",certificate_expired:"forge.pki.CertificateExpired",certificate_unknown:"forge.pki.CertificateUnknown",unknown_ca:"forge.pki.UnknownCertificateAuthority"},n.verifyCertificateChain=function(e,t,r){"function"==typeof r&&(r={verify:r}),r=r||{};var a=(t=t.slice(0)).slice(0),o=r.validityCheckDate;void 0===o&&(o=new Date);var i=!0,s=null,u=0;do{var c=t.shift(),l=null,p=!1;if(o&&(o<c.validity.notBefore||o>c.validity.notAfter)&&(s={message:"Certificate is not valid yet or has expired.",error:n.certificateError.certificate_expired,notBefore:c.validity.notBefore,notAfter:c.validity.notAfter,now:o}),null===s){if(null===(l=t[0]||e.getIssuer(c))&&c.isIssuer(c)&&(p=!0,l=c),l){var d=l;z.util.isArray(d)||(d=[d]);for(var f=!1;!f&&d.length>0;){l=d.shift();try{f=l.verify(c)}catch(e){}}f||(s={message:"Certificate signature is invalid.",error:n.certificateError.bad_certificate})}null!==s||l&&!p||e.hasCertificate(c)||(s={message:"Certificate is not trusted.",error:n.certificateError.unknown_ca})}if(null===s&&l&&!c.isIssuer(l)&&(s={message:"Certificate issuer is invalid.",error:n.certificateError.bad_certificate}),null===s)for(var h={keyUsage:!0,basicConstraints:!0},m=0;null===s&&m<c.extensions.length;++m){var g=c.extensions[m];!g.critical||g.name in h||(s={message:"Certificate has an unsupported critical extension.",error:n.certificateError.unsupported_certificate})}if(null===s&&(!i||0===t.length&&(!l||p))){var v=c.getExtension("basicConstraints"),y=c.getExtension("keyUsage");null!==y&&(y.keyCertSign&&null!==v||(s={message:"Certificate keyUsage or basicConstraints conflict or indicate that the certificate is not a CA. If the certificate is the only one in the chain or isn't the first then the certificate must be a valid CA.",error:n.certificateError.bad_certificate})),null!==s||null===v||v.cA||(s={message:"Certificate basicConstraints indicates the certificate is not a CA.",error:n.certificateError.bad_certificate}),null===s&&null!==y&&"pathLenConstraint"in v&&u-1>v.pathLenConstraint&&(s={message:"Certificate basicConstraints pathLenConstraint violated.",error:n.certificateError.bad_certificate})}var b=null===s||s.error,x=r.verify?r.verify(b,u,a):b;if(!0!==x)throw!0===b&&(s={message:"The application rejected the certificate.",error:n.certificateError.bad_certificate}),(x||0===x)&&("object"!=typeof x||z.util.isArray(x)?"string"==typeof x&&(s.error=x):(x.message&&(s.message=x.message),x.error&&(s.error=x.error))),s;s=null,i=!1,++u}while(t.length>0);return!0}})),w((function(e){var t=z.asn1,n=z.pki,r=e.exports=z.pkcs12=z.pkcs12||{},a={name:"ContentInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"ContentInfo.contentType",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"contentType"},{name:"ContentInfo.content",tagClass:t.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:"content"}]},o={name:"PFX",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},a,{name:"PFX.macData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"mac",value:[{name:"PFX.macData.mac",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.macData.mac.digestAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.macData.mac.digestAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"macAlgorithm"},{name:"PFX.macData.mac.digestAlgorithm.parameters",tagClass:t.Class.UNIVERSAL,captureAsn1:"macAlgorithmParameters"}]},{name:"PFX.macData.mac.digest",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"macDigest"}]},{name:"PFX.macData.macSalt",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"macSalt"},{name:"PFX.macData.iterations",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,optional:!0,capture:"macIterations"}]}]},i={name:"SafeBag",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SafeBag.bagId",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"bagId"},{name:"SafeBag.bagValue",tagClass:t.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:"bagValue"},{name:"SafeBag.bagAttributes",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,optional:!0,capture:"bagAttributes"}]},s={name:"Attribute",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Attribute.attrId",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"oid"},{name:"Attribute.attrValues",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,capture:"values"}]},u={name:"CertBag",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"CertBag.certId",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"certId"},{name:"CertBag.certValue",tagClass:t.Class.CONTEXT_SPECIFIC,constructed:!0,value:[{name:"CertBag.certValue[0]",tagClass:t.Class.UNIVERSAL,type:t.Class.OCTETSTRING,constructed:!1,capture:"cert"}]}]};function c(e,t,n,r){for(var a=[],o=0;o<e.length;o++)for(var i=0;i<e[o].safeBags.length;i++){var s=e[o].safeBags[i];void 0!==r&&s.type!==r||(null!==t?void 0!==s.attributes[t]&&s.attributes[t].indexOf(n)>=0&&a.push(s):a.push(s))}return a}function l(e){if(e.composed||e.constructed){for(var t=z.util.createBuffer(),n=0;n<e.value.length;++n)t.putBytes(e.value[n].value);e.composed=e.constructed=!1,e.value=t.getBytes()}return e}function p(e,r){var a={},o=[];if(!t.validate(e,z.pkcs7.asn1.encryptedDataValidator,a,o))throw(i=new Error("Cannot read EncryptedContentInfo.")).errors=o,i;var i,s=t.derToOid(a.contentType);if(s!==n.oids.data)throw(i=new Error("PKCS#12 EncryptedContentInfo ContentType is not Data.")).oid=s,i;s=t.derToOid(a.encAlgorithm);var u=n.pbe.getCipher(s,a.encParameter,r),c=l(a.encryptedContentAsn1),p=z.util.createBuffer(c.value);if(u.update(p),!u.finish())throw new Error("Failed to decrypt PKCS#12 SafeContents.");return u.output.getBytes()}function d(e,r,a){if(!r&&0===e.length)return[];if((e=t.fromDer(e,r)).tagClass!==t.Class.UNIVERSAL||e.type!==t.Type.SEQUENCE||!0!==e.constructed)throw new Error("PKCS#12 SafeContents expected to be a SEQUENCE OF SafeBag.");for(var o=[],s=0;s<e.value.length;s++){var c=e.value[s],l={},p=[];if(!t.validate(c,i,l,p))throw(v=new Error("Cannot read SafeBag.")).errors=p,v;var d,h,m={type:t.derToOid(l.bagId),attributes:f(l.bagAttributes)};o.push(m);var g=l.bagValue.value[0];switch(m.type){case n.oids.pkcs8ShroudedKeyBag:if(null===(g=n.decryptPrivateKeyInfo(g,a)))throw new Error("Unable to decrypt PKCS#8 ShroudedKeyBag, wrong password?");case n.oids.keyBag:try{m.key=n.privateKeyFromAsn1(g)}catch(e){m.key=null,m.asn1=g}continue;case n.oids.certBag:d=u,h=function(){if(t.derToOid(l.certId)!==n.oids.x509Certificate){var e=new Error("Unsupported certificate type, only X.509 supported.");throw e.oid=t.derToOid(l.certId),e}var a=t.fromDer(l.cert,r);try{m.cert=n.certificateFromAsn1(a,!0)}catch(e){m.cert=null,m.asn1=a}};break;default:var v;throw(v=new Error("Unsupported PKCS#12 SafeBag type.")).oid=m.type,v}if(void 0!==d&&!t.validate(g,d,l,p))throw(v=new Error("Cannot read PKCS#12 "+d.name)).errors=p,v;h()}return o}function f(e){var r={};if(void 0!==e)for(var a=0;a<e.length;++a){var o={},i=[];if(!t.validate(e[a],s,o,i)){var u=new Error("Cannot read PKCS#12 BagAttribute.");throw u.errors=i,u}var c=t.derToOid(o.oid);if(void 0!==n.oids[c]){r[n.oids[c]]=[];for(var l=0;l<o.values.length;++l)r[n.oids[c]].push(o.values[l].value)}}return r}r.pkcs12FromAsn1=function(e,i,s){"string"==typeof i?(s=i,i=!0):void 0===i&&(i=!0);var u={};if(!t.validate(e,o,u,[]))throw(f=new Error("Cannot read PKCS#12 PFX. ASN.1 object is not an PKCS#12 PFX.")).errors=f,f;var f,h={version:u.version.charCodeAt(0),safeContents:[],getBags:function(e){var t,n={};return"localKeyId"in e?t=e.localKeyId:"localKeyIdHex"in e&&(t=z.util.hexToBytes(e.localKeyIdHex)),void 0===t&&!("friendlyName"in e)&&"bagType"in e&&(n[e.bagType]=c(h.safeContents,null,null,e.bagType)),void 0!==t&&(n.localKeyId=c(h.safeContents,"localKeyId",t,e.bagType)),"friendlyName"in e&&(n.friendlyName=c(h.safeContents,"friendlyName",e.friendlyName,e.bagType)),n},getBagsByFriendlyName:function(e,t){return c(h.safeContents,"friendlyName",e,t)},getBagsByLocalKeyId:function(e,t){return c(h.safeContents,"localKeyId",e,t)}};if(3!==u.version.charCodeAt(0))throw(f=new Error("PKCS#12 PFX of version other than 3 not supported.")).version=u.version.charCodeAt(0),f;if(t.derToOid(u.contentType)!==n.oids.data)throw(f=new Error("Only PKCS#12 PFX in password integrity mode supported.")).oid=t.derToOid(u.contentType),f;var m=u.content.value[0];if(m.tagClass!==t.Class.UNIVERSAL||m.type!==t.Type.OCTETSTRING)throw new Error("PKCS#12 authSafe content data is not an OCTET STRING.");if(m=l(m),u.mac){var g=null,v=0,y=t.derToOid(u.macAlgorithm);switch(y){case n.oids.sha1:g=z.md.sha1.create(),v=20;break;case n.oids.sha256:g=z.md.sha256.create(),v=32;break;case n.oids.sha384:g=z.md.sha384.create(),v=48;break;case n.oids.sha512:g=z.md.sha512.create(),v=64;break;case n.oids.md5:g=z.md.md5.create(),v=16}if(null===g)throw new Error("PKCS#12 uses unsupported MAC algorithm: "+y);var b=new z.util.ByteBuffer(u.macSalt),x="macIterations"in u?parseInt(z.util.bytesToHex(u.macIterations),16):1,w=r.generateKey(s,b,3,x,v,g),k=z.hmac.create();if(k.start(g,w),k.update(m.value),k.getMac().getBytes()!==u.macDigest)throw new Error("PKCS#12 MAC could not be verified. Invalid password?")}return function(e,r,o,i){if((r=t.fromDer(r,o)).tagClass!==t.Class.UNIVERSAL||r.type!==t.Type.SEQUENCE||!0!==r.constructed)throw new Error("PKCS#12 AuthenticatedSafe expected to be a SEQUENCE OF ContentInfo");for(var s=0;s<r.value.length;s++){var u=r.value[s],c={},f=[];if(!t.validate(u,a,c,f))throw(v=new Error("Cannot read ContentInfo.")).errors=f,v;var h={encrypted:!1},m=null,g=c.content.value[0];switch(t.derToOid(c.contentType)){case n.oids.data:if(g.tagClass!==t.Class.UNIVERSAL||g.type!==t.Type.OCTETSTRING)throw new Error("PKCS#12 SafeContents Data is not an OCTET STRING.");m=l(g).value;break;case n.oids.encryptedData:m=p(g,i),h.encrypted=!0;break;default:var v;throw(v=new Error("Unsupported PKCS#12 contentType.")).contentType=t.derToOid(c.contentType),v}h.safeBags=d(m,o,i),e.safeContents.push(h)}}(h,m.value,i,s),h},r.toPkcs12Asn1=function(e,a,o,i){(i=i||{}).saltSize=i.saltSize||8,i.count=i.count||2048,i.algorithm=i.algorithm||i.encAlgorithm||"aes128","useMac"in i||(i.useMac=!0),"localKeyId"in i||(i.localKeyId=null),"generateLocalKeyId"in i||(i.generateLocalKeyId=!0);var s,u=i.localKeyId;if(null!==u)u=z.util.hexToBytes(u);else if(i.generateLocalKeyId)if(a){var c=z.util.isArray(a)?a[0]:a;"string"==typeof c&&(c=n.certificateFromPem(c)),(C=z.md.sha1.create()).update(t.toDer(n.certificateToAsn1(c)).getBytes()),u=C.digest().getBytes()}else u=z.random.getBytes(20);var l=[];null!==u&&l.push(t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.localKeyId).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,u)])])),"friendlyName"in i&&l.push(t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.friendlyName).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[t.create(t.Class.UNIVERSAL,t.Type.BMPSTRING,!1,i.friendlyName)])])),l.length>0&&(s=t.create(t.Class.UNIVERSAL,t.Type.SET,!0,l));var p=[],d=[];null!==a&&(d=z.util.isArray(a)?a:[a]);for(var f=[],h=0;h<d.length;++h){"string"==typeof(a=d[h])&&(a=n.certificateFromPem(a));var m=0===h?s:void 0,g=n.certificateToAsn1(a),v=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.certBag).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.x509Certificate).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,t.toDer(g).getBytes())])])]),m]);f.push(v)}if(f.length>0){var y=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,f),b=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.data).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,t.toDer(y).getBytes())])]);p.push(b)}var x=null;if(null!==e){var w=n.wrapRsaPrivateKey(n.privateKeyToAsn1(e));x=null===o?t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.keyBag).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[w]),s]):t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.pkcs8ShroudedKeyBag).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[n.encryptPrivateKeyInfo(w,o,i)]),s]);var k=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[x]),S=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.data).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,t.toDer(k).getBytes())])]);p.push(S)}var E,I=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,p);if(i.useMac){var C=z.md.sha1.create(),T=new z.util.ByteBuffer(z.random.getBytes(i.saltSize)),_=i.count,N=(e=r.generateKey(o,T,3,_,20),z.hmac.create());N.start(C,e),N.update(t.toDer(I).getBytes());var A=N.getMac();E=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.sha1).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")]),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,A.getBytes())]),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,T.getBytes()),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(_).getBytes())])}return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(3).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.data).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,t.toDer(I).getBytes())])]),E])},r.generateKey=z.pbe.generatePkcs12Key})),w((function(e){var t=z.asn1,n=e.exports=z.pki=z.pki||{};n.pemToDer=function(e){var t=z.pem.decode(e)[0];if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert PEM to DER; PEM is encrypted.");return z.util.createBuffer(t.body)},n.privateKeyFromPem=function(e){var r=z.pem.decode(e)[0];if("PRIVATE KEY"!==r.type&&"RSA PRIVATE KEY"!==r.type){var a=new Error('Could not convert private key from PEM; PEM header type is not "PRIVATE KEY" or "RSA PRIVATE KEY".');throw a.headerType=r.type,a}if(r.procType&&"ENCRYPTED"===r.procType.type)throw new Error("Could not convert private key from PEM; PEM is encrypted.");var o=t.fromDer(r.body);return n.privateKeyFromAsn1(o)},n.privateKeyToPem=function(e,r){var a={type:"RSA PRIVATE KEY",body:t.toDer(n.privateKeyToAsn1(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.privateKeyInfoToPem=function(e,n){var r={type:"PRIVATE KEY",body:t.toDer(e).getBytes()};return z.pem.encode(r,{maxline:n})}}));var Et=function(e,t,n,r){var a=z.util.createBuffer(),o=e.length>>1,i=o+(1&e.length),s=e.substr(0,i),u=e.substr(o,i),c=z.util.createBuffer(),l=z.hmac.create();n=t+n;var p=Math.ceil(r/16),d=Math.ceil(r/20);l.start("MD5",s);var f=z.util.createBuffer();c.putBytes(n);for(var h=0;h<p;++h)l.start(null,null),l.update(c.getBytes()),c.putBuffer(l.digest()),l.start(null,null),l.update(c.bytes()+n),f.putBuffer(l.digest());l.start("SHA1",u);var m=z.util.createBuffer();for(c.clear(),c.putBytes(n),h=0;h<d;++h)l.start(null,null),l.update(c.getBytes()),c.putBuffer(l.digest()),l.start(null,null),l.update(c.bytes()+n),m.putBuffer(l.digest());return a.putBytes(z.util.xorBytes(f.getBytes(),m.getBytes(),r)),a},It=function(e,t,n){var r=!1;try{var a=e.deflate(t.fragment.getBytes());t.fragment=z.util.createBuffer(a),t.length=a.length,r=!0}catch(e){}return r},Ct=function(e,t,n){var r=!1;try{var a=e.inflate(t.fragment.getBytes());t.fragment=z.util.createBuffer(a),t.length=a.length,r=!0}catch(e){}return r},Tt=function(e,t){var n=0;switch(t){case 1:n=e.getByte();break;case 2:n=e.getInt16();break;case 3:n=e.getInt24();break;case 4:n=e.getInt32()}return z.util.createBuffer(e.getBytes(n))},_t=function(e,t,n){e.putInt(n.length(),t<<3),e.putBuffer(n)},Nt={Versions:{TLS_1_0:{major:3,minor:1},TLS_1_1:{major:3,minor:2},TLS_1_2:{major:3,minor:3}}};Nt.SupportedVersions=[Nt.Versions.TLS_1_1,Nt.Versions.TLS_1_0],Nt.Version=Nt.SupportedVersions[0],Nt.MaxFragment=15360,Nt.ConnectionEnd={server:0,client:1},Nt.PRFAlgorithm={tls_prf_sha256:0},Nt.BulkCipherAlgorithm={none:null,rc4:0,des3:1,aes:2},Nt.CipherType={stream:0,block:1,aead:2},Nt.MACAlgorithm={none:null,hmac_md5:0,hmac_sha1:1,hmac_sha256:2,hmac_sha384:3,hmac_sha512:4},Nt.CompressionMethod={none:0,deflate:1},Nt.ContentType={change_cipher_spec:20,alert:21,handshake:22,application_data:23,heartbeat:24},Nt.HandshakeType={hello_request:0,client_hello:1,server_hello:2,certificate:11,server_key_exchange:12,certificate_request:13,server_hello_done:14,certificate_verify:15,client_key_exchange:16,finished:20},Nt.Alert={},Nt.Alert.Level={warning:1,fatal:2},Nt.Alert.Description={close_notify:0,unexpected_message:10,bad_record_mac:20,decryption_failed:21,record_overflow:22,decompression_failure:30,handshake_failure:40,bad_certificate:42,unsupported_certificate:43,certificate_revoked:44,certificate_expired:45,certificate_unknown:46,illegal_parameter:47,unknown_ca:48,access_denied:49,decode_error:50,decrypt_error:51,export_restriction:60,protocol_version:70,insufficient_security:71,internal_error:80,user_canceled:90,no_renegotiation:100},Nt.HeartbeatMessageType={heartbeat_request:1,heartbeat_response:2},Nt.CipherSuites={},Nt.getCipherSuite=function(e){var t=null;for(var n in Nt.CipherSuites){var r=Nt.CipherSuites[n];if(r.id[0]===e.charCodeAt(0)&&r.id[1]===e.charCodeAt(1)){t=r;break}}return t},Nt.handleUnexpected=function(e,t){!e.open&&e.entity===Nt.ConnectionEnd.client||e.error(e,{message:"Unexpected message. Received TLS record out of order.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.unexpected_message}})},Nt.handleHelloRequest=function(e,t,n){!e.handshaking&&e.handshakes>0&&(Nt.queue(e,Nt.createAlert(e,{level:Nt.Alert.Level.warning,description:Nt.Alert.Description.no_renegotiation})),Nt.flush(e)),e.process()},Nt.parseHelloMessage=function(e,t,n){var r=null,a=e.entity===Nt.ConnectionEnd.client;if(n<38)e.error(e,{message:a?"Invalid ServerHello message. Message too short.":"Invalid ClientHello message. Message too short.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});else{var o=t.fragment,i=o.length();if(r={version:{major:o.getByte(),minor:o.getByte()},random:z.util.createBuffer(o.getBytes(32)),session_id:Tt(o,1),extensions:[]},a?(r.cipher_suite=o.getBytes(2),r.compression_method=o.getByte()):(r.cipher_suites=Tt(o,2),r.compression_methods=Tt(o,1)),(i=n-(i-o.length()))>0){for(var s=Tt(o,2);s.length()>0;)r.extensions.push({type:[s.getByte(),s.getByte()],data:Tt(s,2)});if(!a)for(var u=0;u<r.extensions.length;++u){var c=r.extensions[u];if(0===c.type[0]&&0===c.type[1])for(var l=Tt(c.data,2);l.length()>0&&0===l.getByte();)e.session.extensions.server_name.serverNameList.push(Tt(l,2).getBytes())}}if(e.session.version&&(r.version.major!==e.session.version.major||r.version.minor!==e.session.version.minor))return e.error(e,{message:"TLS version change is disallowed during renegotiation.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.protocol_version}});if(a)e.session.cipherSuite=Nt.getCipherSuite(r.cipher_suite);else for(var p=z.util.createBuffer(r.cipher_suites.bytes());p.length()>0&&(e.session.cipherSuite=Nt.getCipherSuite(p.getBytes(2)),null===e.session.cipherSuite););if(null===e.session.cipherSuite)return e.error(e,{message:"No cipher suites in common.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.handshake_failure},cipherSuite:z.util.bytesToHex(r.cipher_suite)});e.session.compressionMethod=a?r.compression_method:Nt.CompressionMethod.none}return r},Nt.createSecurityParameters=function(e,t){var n=e.entity===Nt.ConnectionEnd.client,r=t.random.bytes(),a=n?e.session.sp.client_random:r,o=n?r:Nt.createRandom().getBytes();e.session.sp={entity:e.entity,prf_algorithm:Nt.PRFAlgorithm.tls_prf_sha256,bulk_cipher_algorithm:null,cipher_type:null,enc_key_length:null,block_length:null,fixed_iv_length:null,record_iv_length:null,mac_algorithm:null,mac_length:null,mac_key_length:null,compression_algorithm:e.session.compressionMethod,pre_master_secret:null,master_secret:null,client_random:a,server_random:o}},Nt.handleServerHello=function(e,t,n){var r=Nt.parseHelloMessage(e,t,n);if(!e.fail){if(!(r.version.minor<=e.version.minor))return e.error(e,{message:"Incompatible TLS version.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.protocol_version}});e.version.minor=r.version.minor,e.session.version=e.version;var a=r.session_id.bytes();a.length>0&&a===e.session.id?(e.expect=Dt,e.session.resuming=!0,e.session.sp.server_random=r.random.bytes()):(e.expect=At,e.session.resuming=!1,Nt.createSecurityParameters(e,r)),e.session.id=a,e.process()}},Nt.handleClientHello=function(e,t,n){var r=Nt.parseHelloMessage(e,t,n);if(!e.fail){var a=r.session_id.bytes(),o=null;if(e.sessionCache&&(null===(o=e.sessionCache.getSession(a))?a="":(o.version.major!==r.version.major||o.version.minor>r.version.minor)&&(o=null,a="")),0===a.length&&(a=z.random.getBytes(32)),e.session.id=a,e.session.clientHelloVersion=r.version,e.session.sp={},o)e.version=e.session.version=o.version,e.session.sp=o.sp;else{for(var i,s=1;s<Nt.SupportedVersions.length&&!((i=Nt.SupportedVersions[s]).minor<=r.version.minor);++s);e.version={major:i.major,minor:i.minor},e.session.version=e.version}null!==o?(e.expect=zt,e.session.resuming=!0,e.session.sp.client_random=r.random.bytes()):(e.expect=!1!==e.verifyClient?Lt:Ut,e.session.resuming=!1,Nt.createSecurityParameters(e,r)),e.open=!0,Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createServerHello(e)})),e.session.resuming?(Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.change_cipher_spec,data:Nt.createChangeCipherSpec()})),e.state.pending=Nt.createConnectionState(e),e.state.current.write=e.state.pending.write,Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createFinished(e)}))):(Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createCertificate(e)})),e.fail||(Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createServerKeyExchange(e)})),!1!==e.verifyClient&&Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createCertificateRequest(e)})),Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createServerHelloDone(e)})))),Nt.flush(e),e.process()}},Nt.handleCertificate=function(e,t,n){if(n<3)return e.error(e,{message:"Invalid Certificate message. Message too short.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});var r,a,o=t.fragment,i={certificate_list:Tt(o,3)},s=[];try{for(;i.certificate_list.length()>0;)r=Tt(i.certificate_list,3),a=z.asn1.fromDer(r),r=z.pki.certificateFromAsn1(a,!0),s.push(r)}catch(t){return e.error(e,{message:"Could not parse certificate list.",cause:t,send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.bad_certificate}})}var u=e.entity===Nt.ConnectionEnd.client;!u&&!0!==e.verifyClient||0!==s.length?0===s.length?e.expect=u?Rt:Ut:(u?e.session.serverCertificate=s[0]:e.session.clientCertificate=s[0],Nt.verifyCertificateChain(e,s)&&(e.expect=u?Rt:Ut)):e.error(e,{message:u?"No server certificate provided.":"No client certificate provided.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}}),e.process()},Nt.handleServerKeyExchange=function(e,t,n){if(n>0)return e.error(e,{message:"Invalid key parameters. Only RSA is supported.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.unsupported_certificate}});e.expect=Ot,e.process()},Nt.handleClientKeyExchange=function(e,t,n){if(n<48)return e.error(e,{message:"Invalid key parameters. Only RSA is supported.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.unsupported_certificate}});var r=t.fragment,a={enc_pre_master_secret:Tt(r,2).getBytes()},o=null;if(e.getPrivateKey)try{o=e.getPrivateKey(e,e.session.serverCertificate),o=z.pki.privateKeyFromPem(o)}catch(t){e.error(e,{message:"Could not get private key.",cause:t,send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}})}if(null===o)return e.error(e,{message:"No private key set.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}});try{var i=e.session.sp;i.pre_master_secret=o.decrypt(a.enc_pre_master_secret);var s=e.session.clientHelloVersion;if(s.major!==i.pre_master_secret.charCodeAt(0)||s.minor!==i.pre_master_secret.charCodeAt(1))throw new Error("TLS version rollback attack detected.")}catch(e){i.pre_master_secret=z.random.getBytes(48)}e.expect=zt,null!==e.session.clientCertificate&&(e.expect=Vt),e.process()},Nt.handleCertificateRequest=function(e,t,n){if(n<3)return e.error(e,{message:"Invalid CertificateRequest. Message too short.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});var r=t.fragment,a={certificate_types:Tt(r,1),certificate_authorities:Tt(r,2)};e.session.certificateRequest=a,e.expect=Bt,e.process()},Nt.handleCertificateVerify=function(e,t,n){if(n<2)return e.error(e,{message:"Invalid CertificateVerify. Message too short.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});var r=t.fragment;r.read-=4;var a=r.bytes();r.read+=4;var o={signature:Tt(r,2).getBytes()},i=z.util.createBuffer();i.putBuffer(e.session.md5.digest()),i.putBuffer(e.session.sha1.digest()),i=i.getBytes();try{if(!e.session.clientCertificate.publicKey.verify(i,o.signature,"NONE"))throw new Error("CertificateVerify signature does not match.");e.session.md5.update(a),e.session.sha1.update(a)}catch(t){return e.error(e,{message:"Bad signature in CertificateVerify.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.handshake_failure}})}e.expect=zt,e.process()},Nt.handleServerHelloDone=function(e,t,n){if(n>0)return e.error(e,{message:"Invalid ServerHelloDone message. Invalid length.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.record_overflow}});if(null===e.serverCertificate){var r={message:"No server certificate provided. Not enough security.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.insufficient_security}},a=e.verify(e,r.alert.description,0,[]);if(!0!==a)return(a||0===a)&&("object"!=typeof a||z.util.isArray(a)?"number"==typeof a&&(r.alert.description=a):(a.message&&(r.message=a.message),a.alert&&(r.alert.description=a.alert))),e.error(e,r)}null!==e.session.certificateRequest&&(t=Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createCertificate(e)}),Nt.queue(e,t)),t=Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createClientKeyExchange(e)}),Nt.queue(e,t),e.expect=Pt;var o=function(e,t){null!==e.session.certificateRequest&&null!==e.session.clientCertificate&&Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createCertificateVerify(e,t)})),Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.change_cipher_spec,data:Nt.createChangeCipherSpec()})),e.state.pending=Nt.createConnectionState(e),e.state.current.write=e.state.pending.write,Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createFinished(e)})),e.expect=Dt,Nt.flush(e),e.process()};if(null===e.session.certificateRequest||null===e.session.clientCertificate)return o(e,null);Nt.getClientSignature(e,o)},Nt.handleChangeCipherSpec=function(e,t){if(1!==t.fragment.getByte())return e.error(e,{message:"Invalid ChangeCipherSpec message received.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});var n=e.entity===Nt.ConnectionEnd.client;(e.session.resuming&&n||!e.session.resuming&&!n)&&(e.state.pending=Nt.createConnectionState(e)),e.state.current.read=e.state.pending.read,(!e.session.resuming&&n||e.session.resuming&&!n)&&(e.state.pending=null),e.expect=n?Mt:jt,e.process()},Nt.handleFinished=function(e,t,n){var r=t.fragment;r.read-=4;var a=r.bytes();r.read+=4;var o=t.fragment.getBytes();(r=z.util.createBuffer()).putBuffer(e.session.md5.digest()),r.putBuffer(e.session.sha1.digest());var i=e.entity===Nt.ConnectionEnd.client,s=i?"server finished":"client finished",u=e.session.sp;if((r=Et(u.master_secret,s,r.getBytes(),12)).getBytes()!==o)return e.error(e,{message:"Invalid verify_data in Finished message.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.decrypt_error}});e.session.md5.update(a),e.session.sha1.update(a),(e.session.resuming&&i||!e.session.resuming&&!i)&&(Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.change_cipher_spec,data:Nt.createChangeCipherSpec()})),e.state.current.write=e.state.pending.write,e.state.pending=null,Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createFinished(e)}))),e.expect=i?Ft:Wt,e.handshaking=!1,++e.handshakes,e.peerCertificate=i?e.session.serverCertificate:e.session.clientCertificate,Nt.flush(e),e.isConnected=!0,e.connected(e),e.process()},Nt.handleAlert=function(e,t){var n,r=t.fragment,a={level:r.getByte(),description:r.getByte()};switch(a.description){case Nt.Alert.Description.close_notify:n="Connection closed.";break;case Nt.Alert.Description.unexpected_message:n="Unexpected message.";break;case Nt.Alert.Description.bad_record_mac:n="Bad record MAC.";break;case Nt.Alert.Description.decryption_failed:n="Decryption failed.";break;case Nt.Alert.Description.record_overflow:n="Record overflow.";break;case Nt.Alert.Description.decompression_failure:n="Decompression failed.";break;case Nt.Alert.Description.handshake_failure:n="Handshake failure.";break;case Nt.Alert.Description.bad_certificate:n="Bad certificate.";break;case Nt.Alert.Description.unsupported_certificate:n="Unsupported certificate.";break;case Nt.Alert.Description.certificate_revoked:n="Certificate revoked.";break;case Nt.Alert.Description.certificate_expired:n="Certificate expired.";break;case Nt.Alert.Description.certificate_unknown:n="Certificate unknown.";break;case Nt.Alert.Description.illegal_parameter:n="Illegal parameter.";break;case Nt.Alert.Description.unknown_ca:n="Unknown certificate authority.";break;case Nt.Alert.Description.access_denied:n="Access denied.";break;case Nt.Alert.Description.decode_error:n="Decode error.";break;case Nt.Alert.Description.decrypt_error:n="Decrypt error.";break;case Nt.Alert.Description.export_restriction:n="Export restriction.";break;case Nt.Alert.Description.protocol_version:n="Unsupported protocol version.";break;case Nt.Alert.Description.insufficient_security:n="Insufficient security.";break;case Nt.Alert.Description.internal_error:n="Internal error.";break;case Nt.Alert.Description.user_canceled:n="User canceled.";break;case Nt.Alert.Description.no_renegotiation:n="Renegotiation not supported.";break;default:n="Unknown error."}if(a.description===Nt.Alert.Description.close_notify)return e.close();e.error(e,{message:n,send:!1,origin:e.entity===Nt.ConnectionEnd.client?"server":"client",alert:a}),e.process()},Nt.handleHandshake=function(e,t){var n=t.fragment,r=n.getByte(),a=n.getInt24();if(a>n.length())return e.fragmented=t,t.fragment=z.util.createBuffer(),n.read-=4,e.process();e.fragmented=null,n.read-=4;var o=n.bytes(a+4);n.read+=4,r in an[e.entity][e.expect]?(e.entity!==Nt.ConnectionEnd.server||e.open||e.fail||(e.handshaking=!0,e.session={version:null,extensions:{server_name:{serverNameList:[]}},cipherSuite:null,compressionMethod:null,serverCertificate:null,clientCertificate:null,md5:z.md.md5.create(),sha1:z.md.sha1.create()}),r!==Nt.HandshakeType.hello_request&&r!==Nt.HandshakeType.certificate_verify&&r!==Nt.HandshakeType.finished&&(e.session.md5.update(o),e.session.sha1.update(o)),an[e.entity][e.expect][r](e,t,a)):Nt.handleUnexpected(e,t)},Nt.handleApplicationData=function(e,t){e.data.putBuffer(t.fragment),e.dataReady(e),e.process()},Nt.handleHeartbeat=function(e,t){var n=t.fragment,r=n.getByte(),a=n.getInt16(),o=n.getBytes(a);if(r===Nt.HeartbeatMessageType.heartbeat_request){if(e.handshaking||a>o.length)return e.process();Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.heartbeat,data:Nt.createHeartbeat(Nt.HeartbeatMessageType.heartbeat_response,o)})),Nt.flush(e)}else if(r===Nt.HeartbeatMessageType.heartbeat_response){if(o!==e.expectedHeartbeatPayload)return e.process();e.heartbeatReceived&&e.heartbeatReceived(e,z.util.createBuffer(o))}e.process()};var At=1,Rt=2,Ot=3,Bt=4,Dt=5,Mt=6,Ft=7,Pt=8,Lt=1,Ut=2,Vt=3,zt=4,jt=5,Wt=6,Ht=Nt.handleUnexpected,Gt=Nt.handleChangeCipherSpec,Kt=Nt.handleAlert,qt=Nt.handleHandshake,Qt=Nt.handleApplicationData,Xt=Nt.handleHeartbeat,Yt=[];Yt[Nt.ConnectionEnd.client]=[[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Gt,Kt,Ht,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Qt,Xt],[Ht,Kt,qt,Ht,Xt]],Yt[Nt.ConnectionEnd.server]=[[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Gt,Kt,Ht,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Qt,Xt],[Ht,Kt,qt,Ht,Xt]];var $t=Nt.handleHelloRequest,Zt=Nt.handleServerHello,Jt=Nt.handleCertificate,en=Nt.handleServerKeyExchange,tn=Nt.handleCertificateRequest,nn=Nt.handleServerHelloDone,rn=Nt.handleFinished,an=[];an[Nt.ConnectionEnd.client]=[[Ht,Ht,Zt,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Jt,en,tn,nn,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,en,tn,nn,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,tn,nn,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,nn,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,rn],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht]];var on=Nt.handleClientHello,sn=Nt.handleClientKeyExchange,un=Nt.handleCertificateVerify;an[Nt.ConnectionEnd.server]=[[Ht,on,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Jt,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,sn,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,un,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,rn],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht]],Nt.generateKeys=function(e,t){var n=Et,r=t.client_random+t.server_random;e.session.resuming||(t.master_secret=n(t.pre_master_secret,"master secret",r,48).bytes(),t.pre_master_secret=null),r=t.server_random+t.client_random;var a=2*t.mac_key_length+2*t.enc_key_length,o=e.version.major===Nt.Versions.TLS_1_0.major&&e.version.minor===Nt.Versions.TLS_1_0.minor;o&&(a+=2*t.fixed_iv_length);var i=n(t.master_secret,"key expansion",r,a),s={client_write_MAC_key:i.getBytes(t.mac_key_length),server_write_MAC_key:i.getBytes(t.mac_key_length),client_write_key:i.getBytes(t.enc_key_length),server_write_key:i.getBytes(t.enc_key_length)};return o&&(s.client_write_IV=i.getBytes(t.fixed_iv_length),s.server_write_IV=i.getBytes(t.fixed_iv_length)),s},Nt.createConnectionState=function(e){var t=e.entity===Nt.ConnectionEnd.client,n=function(){var e={sequenceNumber:[0,0],macKey:null,macLength:0,macFunction:null,cipherState:null,cipherFunction:function(e){return!0},compressionState:null,compressFunction:function(e){return!0},updateSequenceNumber:function(){4294967295===e.sequenceNumber[1]?(e.sequenceNumber[1]=0,++e.sequenceNumber[0]):++e.sequenceNumber[1]}};return e},r={read:n(),write:n()};if(r.read.update=function(e,t){return r.read.cipherFunction(t,r.read)?r.read.compressFunction(e,t,r.read)||e.error(e,{message:"Could not decompress record.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.decompression_failure}}):e.error(e,{message:"Could not decrypt record or bad MAC.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.bad_record_mac}}),!e.fail},r.write.update=function(e,t){return r.write.compressFunction(e,t,r.write)?r.write.cipherFunction(t,r.write)||e.error(e,{message:"Could not encrypt record.",send:!1,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}}):e.error(e,{message:"Could not compress record.",send:!1,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}}),!e.fail},e.session){var a=e.session.sp;switch(e.session.cipherSuite.initSecurityParameters(a),a.keys=Nt.generateKeys(e,a),r.read.macKey=t?a.keys.server_write_MAC_key:a.keys.client_write_MAC_key,r.write.macKey=t?a.keys.client_write_MAC_key:a.keys.server_write_MAC_key,e.session.cipherSuite.initConnectionState(r,e,a),a.compression_algorithm){case Nt.CompressionMethod.none:break;case Nt.CompressionMethod.deflate:r.read.compressFunction=Ct,r.write.compressFunction=It;break;default:throw new Error("Unsupported compression algorithm.")}}return r},Nt.createRandom=function(){var e=new Date,t=+e+6e4*e.getTimezoneOffset(),n=z.util.createBuffer();return n.putInt32(t),n.putBytes(z.random.getBytes(28)),n},Nt.createRecord=function(e,t){return t.data?{type:t.type,version:{major:e.version.major,minor:e.version.minor},length:t.data.length(),fragment:t.data}:null},Nt.createAlert=function(e,t){var n=z.util.createBuffer();return n.putByte(t.level),n.putByte(t.description),Nt.createRecord(e,{type:Nt.ContentType.alert,data:n})},Nt.createClientHello=function(e){e.session.clientHelloVersion={major:e.version.major,minor:e.version.minor};for(var t=z.util.createBuffer(),n=0;n<e.cipherSuites.length;++n){var r=e.cipherSuites[n];t.putByte(r.id[0]),t.putByte(r.id[1])}var a=t.length(),o=z.util.createBuffer();o.putByte(Nt.CompressionMethod.none);var i=o.length(),s=z.util.createBuffer();if(e.virtualHost){var u=z.util.createBuffer();u.putByte(0),u.putByte(0);var c=z.util.createBuffer();c.putByte(0),_t(c,2,z.util.createBuffer(e.virtualHost));var l=z.util.createBuffer();_t(l,2,c),_t(u,2,l),s.putBuffer(u)}var p=s.length();p>0&&(p+=2);var d=e.session.id,f=d.length+1+2+4+28+2+a+1+i+p,h=z.util.createBuffer();return h.putByte(Nt.HandshakeType.client_hello),h.putInt24(f),h.putByte(e.version.major),h.putByte(e.version.minor),h.putBytes(e.session.sp.client_random),_t(h,1,z.util.createBuffer(d)),_t(h,2,t),_t(h,1,o),p>0&&_t(h,2,s),h},Nt.createServerHello=function(e){var t=e.session.id,n=t.length+1+2+4+28+2+1,r=z.util.createBuffer();return r.putByte(Nt.HandshakeType.server_hello),r.putInt24(n),r.putByte(e.version.major),r.putByte(e.version.minor),r.putBytes(e.session.sp.server_random),_t(r,1,z.util.createBuffer(t)),r.putByte(e.session.cipherSuite.id[0]),r.putByte(e.session.cipherSuite.id[1]),r.putByte(e.session.compressionMethod),r},Nt.createCertificate=function(e){var t,n=e.entity===Nt.ConnectionEnd.client,r=null;e.getCertificate&&(t=n?e.session.certificateRequest:e.session.extensions.server_name.serverNameList,r=e.getCertificate(e,t));var a=z.util.createBuffer();if(null!==r)try{z.util.isArray(r)||(r=[r]);for(var o=null,i=0;i<r.length;++i){var s=z.pem.decode(r[i])[0];if("CERTIFICATE"!==s.type&&"X509 CERTIFICATE"!==s.type&&"TRUSTED CERTIFICATE"!==s.type){var u=new Error('Could not convert certificate from PEM; PEM header type is not "CERTIFICATE", "X509 CERTIFICATE", or "TRUSTED CERTIFICATE".');throw u.headerType=s.type,u}if(s.procType&&"ENCRYPTED"===s.procType.type)throw new Error("Could not convert certificate from PEM; PEM is encrypted.");var c=z.util.createBuffer(s.body);null===o&&(o=z.asn1.fromDer(c.bytes(),!1));var l=z.util.createBuffer();_t(l,3,c),a.putBuffer(l)}r=z.pki.certificateFromAsn1(o),n?e.session.clientCertificate=r:e.session.serverCertificate=r}catch(t){return e.error(e,{message:"Could not send certificate list.",cause:t,send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.bad_certificate}})}var p=3+a.length(),d=z.util.createBuffer();return d.putByte(Nt.HandshakeType.certificate),d.putInt24(p),_t(d,3,a),d},Nt.createClientKeyExchange=function(e){var t=z.util.createBuffer();t.putByte(e.session.clientHelloVersion.major),t.putByte(e.session.clientHelloVersion.minor),t.putBytes(z.random.getBytes(46));var n=e.session.sp;n.pre_master_secret=t.getBytes();var r=(t=e.session.serverCertificate.publicKey.encrypt(n.pre_master_secret)).length+2,a=z.util.createBuffer();return a.putByte(Nt.HandshakeType.client_key_exchange),a.putInt24(r),a.putInt16(t.length),a.putBytes(t),a},Nt.createServerKeyExchange=function(e){return z.util.createBuffer()},Nt.getClientSignature=function(e,t){var n=z.util.createBuffer();n.putBuffer(e.session.md5.digest()),n.putBuffer(e.session.sha1.digest()),n=n.getBytes(),e.getSignature=e.getSignature||function(e,t,n){var r=null;if(e.getPrivateKey)try{r=e.getPrivateKey(e,e.session.clientCertificate),r=z.pki.privateKeyFromPem(r)}catch(t){e.error(e,{message:"Could not get private key.",cause:t,send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}})}null===r?e.error(e,{message:"No private key set.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}}):t=r.sign(t,null),n(e,t)},e.getSignature(e,n,t)},Nt.createCertificateVerify=function(e,t){var n=t.length+2,r=z.util.createBuffer();return r.putByte(Nt.HandshakeType.certificate_verify),r.putInt24(n),r.putInt16(t.length),r.putBytes(t),r},Nt.createCertificateRequest=function(e){var t=z.util.createBuffer();t.putByte(1);var n=z.util.createBuffer();for(var r in e.caStore.certs){var a=e.caStore.certs[r],o=z.pki.distinguishedNameToAsn1(a.subject),i=z.asn1.toDer(o);n.putInt16(i.length()),n.putBuffer(i)}var s=1+t.length()+2+n.length(),u=z.util.createBuffer();return u.putByte(Nt.HandshakeType.certificate_request),u.putInt24(s),_t(u,1,t),_t(u,2,n),u},Nt.createServerHelloDone=function(e){var t=z.util.createBuffer();return t.putByte(Nt.HandshakeType.server_hello_done),t.putInt24(0),t},Nt.createChangeCipherSpec=function(){var e=z.util.createBuffer();return e.putByte(1),e},Nt.createFinished=function(e){var t=z.util.createBuffer();t.putBuffer(e.session.md5.digest()),t.putBuffer(e.session.sha1.digest());var n=e.entity===Nt.ConnectionEnd.client,r=e.session.sp,a=n?"client finished":"server finished";t=Et(r.master_secret,a,t.getBytes(),12);var o=z.util.createBuffer();return o.putByte(Nt.HandshakeType.finished),o.putInt24(t.length()),o.putBuffer(t),o},Nt.createHeartbeat=function(e,t,n){void 0===n&&(n=t.length);var r=z.util.createBuffer();r.putByte(e),r.putInt16(n),r.putBytes(t);var a=r.length(),o=Math.max(16,a-n-3);return r.putBytes(z.random.getBytes(o)),r},Nt.queue=function(e,t){if(t&&(0!==t.fragment.length()||t.type!==Nt.ContentType.handshake&&t.type!==Nt.ContentType.alert&&t.type!==Nt.ContentType.change_cipher_spec)){if(t.type===Nt.ContentType.handshake){var n=t.fragment.bytes();e.session.md5.update(n),e.session.sha1.update(n),n=null}var r;if(t.fragment.length()<=Nt.MaxFragment)r=[t];else{r=[];for(var a=t.fragment.bytes();a.length>Nt.MaxFragment;)r.push(Nt.createRecord(e,{type:t.type,data:z.util.createBuffer(a.slice(0,Nt.MaxFragment))})),a=a.slice(Nt.MaxFragment);a.length>0&&r.push(Nt.createRecord(e,{type:t.type,data:z.util.createBuffer(a)}))}for(var o=0;o<r.length&&!e.fail;++o){var i=r[o];e.state.current.write.update(e,i)&&e.records.push(i)}}},Nt.flush=function(e){for(var t=0;t<e.records.length;++t){var n=e.records[t];e.tlsData.putByte(n.type),e.tlsData.putByte(n.version.major),e.tlsData.putByte(n.version.minor),e.tlsData.putInt16(n.fragment.length()),e.tlsData.putBuffer(e.records[t].fragment)}return e.records=[],e.tlsDataReady(e)};var cn=function(e){switch(e){case!0:return!0;case z.pki.certificateError.bad_certificate:return Nt.Alert.Description.bad_certificate;case z.pki.certificateError.unsupported_certificate:return Nt.Alert.Description.unsupported_certificate;case z.pki.certificateError.certificate_revoked:return Nt.Alert.Description.certificate_revoked;case z.pki.certificateError.certificate_expired:return Nt.Alert.Description.certificate_expired;case z.pki.certificateError.certificate_unknown:return Nt.Alert.Description.certificate_unknown;case z.pki.certificateError.unknown_ca:return Nt.Alert.Description.unknown_ca;default:return Nt.Alert.Description.bad_certificate}};for(var ln in Nt.verifyCertificateChain=function(e,t){try{var n={};for(var r in e.verifyOptions)n[r]=e.verifyOptions[r];n.verify=function(t,n,r){cn(t);var a=e.verify(e,t,n,r);if(!0!==a){if("object"==typeof a&&!z.util.isArray(a)){var o=new Error("The application rejected the certificate.");throw o.send=!0,o.alert={level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.bad_certificate},a.message&&(o.message=a.message),a.alert&&(o.alert.description=a.alert),o}a!==t&&(a=function(e){switch(e){case!0:return!0;case Nt.Alert.Description.bad_certificate:return z.pki.certificateError.bad_certificate;case Nt.Alert.Description.unsupported_certificate:return z.pki.certificateError.unsupported_certificate;case Nt.Alert.Description.certificate_revoked:return z.pki.certificateError.certificate_revoked;case Nt.Alert.Description.certificate_expired:return z.pki.certificateError.certificate_expired;case Nt.Alert.Description.certificate_unknown:return z.pki.certificateError.certificate_unknown;case Nt.Alert.Description.unknown_ca:return z.pki.certificateError.unknown_ca;default:return z.pki.certificateError.bad_certificate}}(a))}return a},z.pki.verifyCertificateChain(e.caStore,t,n)}catch(t){var a=t;("object"!=typeof a||z.util.isArray(a))&&(a={send:!0,alert:{level:Nt.Alert.Level.fatal,description:cn(t)}}),"send"in a||(a.send=!0),"alert"in a||(a.alert={level:Nt.Alert.Level.fatal,description:cn(a.error)}),e.error(e,a)}return!e.fail},Nt.createSessionCache=function(e,t){var n=null;if(e&&e.getSession&&e.setSession&&e.order)n=e;else{for(var r in(n={}).cache=e||{},n.capacity=Math.max(t||100,1),n.order=[],e)n.order.length<=t?n.order.push(r):delete e[r];n.getSession=function(e){var t=null,r=null;if(e?r=z.util.bytesToHex(e):n.order.length>0&&(r=n.order[0]),null!==r&&r in n.cache)for(var a in t=n.cache[r],delete n.cache[r],n.order)if(n.order[a]===r){n.order.splice(a,1);break}return t},n.setSession=function(e,t){if(n.order.length===n.capacity){var r=n.order.shift();delete n.cache[r]}r=z.util.bytesToHex(e),n.order.push(r),n.cache[r]=t}}return n},Nt.createConnection=function(e){var t=null;t=e.caStore?z.util.isArray(e.caStore)?z.pki.createCaStore(e.caStore):e.caStore:z.pki.createCaStore();var n=e.cipherSuites||null;if(null===n)for(var r in n=[],Nt.CipherSuites)n.push(Nt.CipherSuites[r]);var a=e.server?Nt.ConnectionEnd.server:Nt.ConnectionEnd.client,o=e.sessionCache?Nt.createSessionCache(e.sessionCache):null,i={version:{major:Nt.Version.major,minor:Nt.Version.minor},entity:a,sessionId:e.sessionId,caStore:t,sessionCache:o,cipherSuites:n,connected:e.connected,virtualHost:e.virtualHost||null,verifyClient:e.verifyClient||!1,verify:e.verify||function(e,t,n,r){return t},verifyOptions:e.verifyOptions||{},getCertificate:e.getCertificate||null,getPrivateKey:e.getPrivateKey||null,getSignature:e.getSignature||null,input:z.util.createBuffer(),tlsData:z.util.createBuffer(),data:z.util.createBuffer(),tlsDataReady:e.tlsDataReady,dataReady:e.dataReady,heartbeatReceived:e.heartbeatReceived,closed:e.closed,error:function(t,n){n.origin=n.origin||(t.entity===Nt.ConnectionEnd.client?"client":"server"),n.send&&(Nt.queue(t,Nt.createAlert(t,n.alert)),Nt.flush(t));var r=!1!==n.fatal;r&&(t.fail=!0),e.error(t,n),r&&t.close(!1)},deflate:e.deflate||null,inflate:e.inflate||null,reset:function(e){i.version={major:Nt.Version.major,minor:Nt.Version.minor},i.record=null,i.session=null,i.peerCertificate=null,i.state={pending:null,current:null},i.expect=(Nt.ConnectionEnd.client,0),i.fragmented=null,i.records=[],i.open=!1,i.handshakes=0,i.handshaking=!1,i.isConnected=!1,i.fail=!(e||void 0===e),i.input.clear(),i.tlsData.clear(),i.data.clear(),i.state.current=Nt.createConnectionState(i)}};return i.reset(),i.handshake=function(e){if(i.entity!==Nt.ConnectionEnd.client)i.error(i,{message:"Cannot initiate handshake as a server.",fatal:!1});else if(i.handshaking)i.error(i,{message:"Handshake already in progress.",fatal:!1});else{i.fail&&!i.open&&0===i.handshakes&&(i.fail=!1),i.handshaking=!0;var t=null;(e=e||"").length>0&&(i.sessionCache&&(t=i.sessionCache.getSession(e)),null===t&&(e="")),0===e.length&&i.sessionCache&&null!==(t=i.sessionCache.getSession())&&(e=t.id),i.session={id:e,version:null,cipherSuite:null,compressionMethod:null,serverCertificate:null,certificateRequest:null,clientCertificate:null,sp:{},md5:z.md.md5.create(),sha1:z.md.sha1.create()},t&&(i.version=t.version,i.session.sp=t.sp),i.session.sp.client_random=Nt.createRandom().getBytes(),i.open=!0,Nt.queue(i,Nt.createRecord(i,{type:Nt.ContentType.handshake,data:Nt.createClientHello(i)})),Nt.flush(i)}},i.process=function(e){var t=0;return e&&i.input.putBytes(e),i.fail||(null!==i.record&&i.record.ready&&i.record.fragment.isEmpty()&&(i.record=null),null===i.record&&(t=function(e){var t=0,n=e.input,r=n.length();if(r<5)t=5-r;else{e.record={type:n.getByte(),version:{major:n.getByte(),minor:n.getByte()},length:n.getInt16(),fragment:z.util.createBuffer(),ready:!1};var a=e.record.version.major===e.version.major;a&&e.session&&e.session.version&&(a=e.record.version.minor===e.version.minor),a||e.error(e,{message:"Incompatible TLS version.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.protocol_version}})}return t}(i)),i.fail||null===i.record||i.record.ready||(t=function(e){var t=0,n=e.input,r=n.length();return r<e.record.length?t=e.record.length-r:(e.record.fragment.putBytes(n.getBytes(e.record.length)),n.compact(),e.state.current.read.update(e,e.record)&&(null!==e.fragmented&&(e.fragmented.type===e.record.type?(e.fragmented.fragment.putBuffer(e.record.fragment),e.record=e.fragmented):e.error(e,{message:"Invalid fragmented record.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.unexpected_message}})),e.record.ready=!0)),t}(i)),!i.fail&&null!==i.record&&i.record.ready&&function(e,t){var n=t.type-Nt.ContentType.change_cipher_spec,r=Yt[e.entity][e.expect];n in r?r[n](e,t):Nt.handleUnexpected(e,t)}(i,i.record)),t},i.prepare=function(e){return Nt.queue(i,Nt.createRecord(i,{type:Nt.ContentType.application_data,data:z.util.createBuffer(e)})),Nt.flush(i)},i.prepareHeartbeatRequest=function(e,t){return e instanceof z.util.ByteBuffer&&(e=e.bytes()),void 0===t&&(t=e.length),i.expectedHeartbeatPayload=e,Nt.queue(i,Nt.createRecord(i,{type:Nt.ContentType.heartbeat,data:Nt.createHeartbeat(Nt.HeartbeatMessageType.heartbeat_request,e,t)})),Nt.flush(i)},i.close=function(e){if(!i.fail&&i.sessionCache&&i.session){var t={id:i.session.id,version:i.session.version,sp:i.session.sp};t.sp.keys=null,i.sessionCache.setSession(t.id,t)}i.open&&(i.open=!1,i.input.clear(),(i.isConnected||i.handshaking)&&(i.isConnected=i.handshaking=!1,Nt.queue(i,Nt.createAlert(i,{level:Nt.Alert.Level.warning,description:Nt.Alert.Description.close_notify})),Nt.flush(i)),i.closed(i)),i.reset(e)},i},z.tls=z.tls||{},Nt)"function"!=typeof Nt[ln]&&(z.tls[ln]=Nt[ln]);z.tls.prf_tls1=Et,z.tls.hmac_sha1=function(e,t,n){var r=z.hmac.create();r.start("SHA1",e);var a=z.util.createBuffer();return a.putInt32(t[0]),a.putInt32(t[1]),a.putByte(n.type),a.putByte(n.version.major),a.putByte(n.version.minor),a.putInt16(n.length),a.putBytes(n.fragment.bytes()),r.update(a.getBytes()),r.digest().getBytes()},z.tls.createSessionCache=Nt.createSessionCache,z.tls.createConnection=Nt.createConnection,w((function(e){var t=e.exports=z.tls;function n(e,n,a){var o=n.entity===z.tls.ConnectionEnd.client;e.read.cipherState={init:!1,cipher:z.cipher.createDecipher("AES-CBC",o?a.keys.server_write_key:a.keys.client_write_key),iv:o?a.keys.server_write_IV:a.keys.client_write_IV},e.write.cipherState={init:!1,cipher:z.cipher.createCipher("AES-CBC",o?a.keys.client_write_key:a.keys.server_write_key),iv:o?a.keys.client_write_IV:a.keys.server_write_IV},e.read.cipherFunction=i,e.write.cipherFunction=r,e.read.macLength=e.write.macLength=a.mac_length,e.read.macFunction=e.write.macFunction=t.hmac_sha1}function r(e,n){var r,o=!1,i=n.macFunction(n.macKey,n.sequenceNumber,e);e.fragment.putBytes(i),n.updateSequenceNumber(),r=e.version.minor===t.Versions.TLS_1_0.minor?n.cipherState.init?null:n.cipherState.iv:z.random.getBytesSync(16),n.cipherState.init=!0;var s=n.cipherState.cipher;return s.start({iv:r}),e.version.minor>=t.Versions.TLS_1_1.minor&&s.output.putBytes(r),s.update(e.fragment),s.finish(a)&&(e.fragment=s.output,e.length=e.fragment.length(),o=!0),o}function a(e,t,n){if(!n){var r=e-t.length()%e;t.fillWithByte(r-1,r)}return!0}function o(e,t,n){var r=!0;if(n){for(var a=t.length(),o=t.last(),i=a-1-o;i<a-1;++i)r=r&&t.at(i)==o;r&&t.truncate(o+1)}return r}function i(e,n){var r,a=!1;r=e.version.minor===t.Versions.TLS_1_0.minor?n.cipherState.init?null:n.cipherState.iv:e.fragment.getBytes(16),n.cipherState.init=!0;var i=n.cipherState.cipher;i.start({iv:r}),i.update(e.fragment),a=i.finish(o);var s=n.macLength,u=z.random.getBytesSync(s),c=i.output.length();c>=s?(e.fragment=i.output.getBytes(c-s),u=i.output.getBytes(s)):e.fragment=i.output.getBytes(),e.fragment=z.util.createBuffer(e.fragment),e.length=e.fragment.length();var l=n.macFunction(n.macKey,n.sequenceNumber,e);return n.updateSequenceNumber(),function(e,t,n){var r=z.hmac.create();return r.start("SHA1",e),r.update(t),t=r.digest().getBytes(),r.start(null,null),r.update(n),t===(n=r.digest().getBytes())}(n.macKey,u,l)&&a}t.CipherSuites.TLS_RSA_WITH_AES_128_CBC_SHA={id:[0,47],name:"TLS_RSA_WITH_AES_128_CBC_SHA",initSecurityParameters:function(e){e.bulk_cipher_algorithm=t.BulkCipherAlgorithm.aes,e.cipher_type=t.CipherType.block,e.enc_key_length=16,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=t.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:n},t.CipherSuites.TLS_RSA_WITH_AES_256_CBC_SHA={id:[0,53],name:"TLS_RSA_WITH_AES_256_CBC_SHA",initSecurityParameters:function(e){e.bulk_cipher_algorithm=t.BulkCipherAlgorithm.aes,e.cipher_type=t.CipherType.block,e.enc_key_length=32,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=t.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:n}})),z.debug=z.debug||{},z.debug.storage={},z.debug.get=function(e,t){var n;return void 0===e?n=z.debug.storage:e in z.debug.storage&&(n=void 0===t?z.debug.storage[e]:z.debug.storage[e][t]),n},z.debug.set=function(e,t,n){e in z.debug.storage||(z.debug.storage[e]={}),z.debug.storage[e][t]=n},z.debug.clear=function(e,t){void 0===e?z.debug.storage={}:e in z.debug.storage&&(void 0===t?delete z.debug.storage[e]:delete z.debug.storage[e][t])},w((function(e){var t=e.exports=z.sha512=z.sha512||{};z.md.sha512=z.md.algorithms.sha512=t;var n=z.sha384=z.sha512.sha384=z.sha512.sha384||{};n.create=function(){return t.create("SHA-384")},z.md.sha384=z.md.algorithms.sha384=n,z.sha512.sha256=z.sha512.sha256||{create:function(){return t.create("SHA-512/256")}},z.md["sha512/256"]=z.md.algorithms["sha512/256"]=z.sha512.sha256,z.sha512.sha224=z.sha512.sha224||{create:function(){return t.create("SHA-512/224")}},z.md["sha512/224"]=z.md.algorithms["sha512/224"]=z.sha512.sha224,t.create=function(e){if(a||(r=String.fromCharCode(128),r+=z.util.fillString(String.fromCharCode(0),128),o=[[1116352408,3609767458],[1899447441,602891725],[3049323471,3964484399],[3921009573,2173295548],[961987163,4081628472],[1508970993,3053834265],[2453635748,2937671579],[2870763221,3664609560],[3624381080,2734883394],[310598401,1164996542],[607225278,1323610764],[1426881987,3590304994],[1925078388,4068182383],[2162078206,991336113],[2614888103,633803317],[3248222580,3479774868],[3835390401,2666613458],[4022224774,944711139],[264347078,2341262773],[604807628,2007800933],[770255983,1495990901],[1249150122,1856431235],[1555081692,3175218132],[1996064986,2198950837],[2554220882,3999719339],[2821834349,766784016],[2952996808,2566594879],[3210313671,3203337956],[3336571891,1034457026],[3584528711,2466948901],[113926993,3758326383],[338241895,168717936],[666307205,1188179964],[773529912,1546045734],[1294757372,1522805485],[1396182291,2643833823],[1695183700,2343527390],[1986661051,1014477480],[2177026350,1206759142],[2456956037,344077627],[2730485921,1290863460],[2820302411,3158454273],[3259730800,3505952657],[3345764771,106217008],[3516065817,3606008344],[3600352804,1432725776],[4094571909,1467031594],[275423344,851169720],[430227734,3100823752],[506948616,1363258195],[659060556,3750685593],[883997877,3785050280],[958139571,3318307427],[1322822218,3812723403],[1537002063,2003034995],[1747873779,3602036899],[1955562222,1575990012],[2024104815,1125592928],[2227730452,2716904306],[2361852424,442776044],[2428436474,593698344],[2756734187,3733110249],[3204031479,2999351573],[3329325298,3815920427],[3391569614,3928383900],[3515267271,566280711],[3940187606,3454069534],[4118630271,4000239992],[116418474,1914138554],[174292421,2731055270],[289380356,3203993006],[460393269,320620315],[685471733,587496836],[852142971,1086792851],[1017036298,365543100],[1126000580,2618297676],[1288033470,3409855158],[1501505948,4234509866],[1607167915,987167468],[1816402316,1246189591]],(i={})["SHA-512"]=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]],i["SHA-384"]=[[3418070365,3238371032],[1654270250,914150663],[2438529370,812702999],[355462360,4144912697],[1731405415,4290775857],[2394180231,1750603025],[3675008525,1694076839],[1203062813,3204075428]],i["SHA-512/256"]=[[573645204,4230739756],[2673172387,3360449730],[596883563,1867755857],[2520282905,1497426621],[2519219938,2827943907],[3193839141,1401305490],[721525244,746961066],[246885852,2177182882]],i["SHA-512/224"]=[[2352822216,424955298],[1944164710,2312950998],[502970286,855612546],[1738396948,1479516111],[258812777,2077511080],[2011393907,79989058],[1067287976,1780299464],[286451373,2446758561]],a=!0),void 0===e&&(e="SHA-512"),!(e in i))throw new Error("Invalid SHA-512 algorithm: "+e);for(var t=i[e],n=null,u=z.util.createBuffer(),c=new Array(80),l=0;l<80;++l)c[l]=new Array(2);var p=64;switch(e){case"SHA-384":p=48;break;case"SHA-512/256":p=32;break;case"SHA-512/224":p=28}var d={algorithm:e.replace("-","").toLowerCase(),blockLength:128,digestLength:p,messageLength:0,fullMessageLength:null,messageLengthSize:16,start:function(){d.messageLength=0,d.fullMessageLength=d.messageLength128=[];for(var e=d.messageLengthSize/4,r=0;r<e;++r)d.fullMessageLength.push(0);for(u=z.util.createBuffer(),n=new Array(t.length),r=0;r<t.length;++r)n[r]=t[r].slice(0);return d}};return d.start(),d.update=function(e,t){"utf8"===t&&(e=z.util.encodeUtf8(e));var r=e.length;d.messageLength+=r,r=[r/4294967296>>>0,r>>>0];for(var a=d.fullMessageLength.length-1;a>=0;--a)d.fullMessageLength[a]+=r[1],r[1]=r[0]+(d.fullMessageLength[a]/4294967296>>>0),d.fullMessageLength[a]=d.fullMessageLength[a]>>>0,r[0]=r[1]/4294967296>>>0;return u.putBytes(e),s(n,c,u),(u.read>2048||0===u.length())&&u.compact(),d},d.digest=function(){var t=z.util.createBuffer();t.putBytes(u.bytes());var a,o=d.fullMessageLength[d.fullMessageLength.length-1]+d.messageLengthSize&d.blockLength-1;t.putBytes(r.substr(0,d.blockLength-o));for(var i=8*d.fullMessageLength[0],l=0;l<d.fullMessageLength.length-1;++l)i+=(a=8*d.fullMessageLength[l+1])/4294967296>>>0,t.putInt32(i>>>0),i=a>>>0;t.putInt32(i);var p=new Array(n.length);for(l=0;l<n.length;++l)p[l]=n[l].slice(0);s(p,c,t);var f,h=z.util.createBuffer();for(f="SHA-512"===e?p.length:"SHA-384"===e?p.length-2:p.length-4,l=0;l<f;++l)h.putInt32(p[l][0]),l===f-1&&"SHA-512/224"===e||h.putInt32(p[l][1]);return h},d};var r=null,a=!1,o=null,i=null;function s(e,t,n){for(var r,a,i,s,u,c,l,p,d,f,h,m,g,v,y,b,x,w,k,S,E,I,C,T,_,N,A,R,O,B,D,M,F,P=n.length();P>=128;){for(A=0;A<16;++A)t[A][0]=n.getInt32()>>>0,t[A][1]=n.getInt32()>>>0;for(;A<80;++A)r=(((R=(B=t[A-2])[0])>>>19|(O=B[1])<<13)^(O>>>29|R<<3)^R>>>6)>>>0,a=((R<<13|O>>>19)^(O<<3|R>>>29)^(R<<26|O>>>6))>>>0,i=(((R=(M=t[A-15])[0])>>>1|(O=M[1])<<31)^(R>>>8|O<<24)^R>>>7)>>>0,s=((R<<31|O>>>1)^(R<<24|O>>>8)^(R<<25|O>>>7))>>>0,D=t[A-7],F=t[A-16],O=a+D[1]+s+F[1],t[A][0]=r+D[0]+i+F[0]+(O/4294967296>>>0)>>>0,t[A][1]=O>>>0;for(h=e[0][0],m=e[0][1],g=e[1][0],v=e[1][1],y=e[2][0],b=e[2][1],x=e[3][0],w=e[3][1],k=e[4][0],S=e[4][1],E=e[5][0],I=e[5][1],C=e[6][0],T=e[6][1],_=e[7][0],N=e[7][1],A=0;A<80;++A)l=((k>>>14|S<<18)^(k>>>18|S<<14)^(S>>>9|k<<23))>>>0,p=(C^k&(E^C))>>>0,u=((h>>>28|m<<4)^(m>>>2|h<<30)^(m>>>7|h<<25))>>>0,c=((h<<4|m>>>28)^(m<<30|h>>>2)^(m<<25|h>>>7))>>>0,d=(h&g|y&(h^g))>>>0,f=(m&v|b&(m^v))>>>0,O=N+(((k<<18|S>>>14)^(k<<14|S>>>18)^(S<<23|k>>>9))>>>0)+((T^S&(I^T))>>>0)+o[A][1]+t[A][1],r=_+l+p+o[A][0]+t[A][0]+(O/4294967296>>>0)>>>0,a=O>>>0,i=u+d+((O=c+f)/4294967296>>>0)>>>0,s=O>>>0,_=C,N=T,C=E,T=I,E=k,I=S,k=x+r+((O=w+a)/4294967296>>>0)>>>0,S=O>>>0,x=y,w=b,y=g,b=v,g=h,v=m,h=r+i+((O=a+s)/4294967296>>>0)>>>0,m=O>>>0;O=e[0][1]+m,e[0][0]=e[0][0]+h+(O/4294967296>>>0)>>>0,e[0][1]=O>>>0,O=e[1][1]+v,e[1][0]=e[1][0]+g+(O/4294967296>>>0)>>>0,e[1][1]=O>>>0,O=e[2][1]+b,e[2][0]=e[2][0]+y+(O/4294967296>>>0)>>>0,e[2][1]=O>>>0,O=e[3][1]+w,e[3][0]=e[3][0]+x+(O/4294967296>>>0)>>>0,e[3][1]=O>>>0,O=e[4][1]+S,e[4][0]=e[4][0]+k+(O/4294967296>>>0)>>>0,e[4][1]=O>>>0,O=e[5][1]+I,e[5][0]=e[5][0]+E+(O/4294967296>>>0)>>>0,e[5][1]=O>>>0,O=e[6][1]+T,e[6][0]=e[6][0]+C+(O/4294967296>>>0)>>>0,e[6][1]=O>>>0,O=e[7][1]+N,e[7][0]=e[7][0]+_+(O/4294967296>>>0)>>>0,e[7][1]=O>>>0,P-=128}}}));var pn=z.asn1,dn={privateKeyValidator:{name:"PrivateKeyInfo",tagClass:pn.Class.UNIVERSAL,type:pn.Type.SEQUENCE,constructed:!0,value:[{name:"PrivateKeyInfo.version",tagClass:pn.Class.UNIVERSAL,type:pn.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.privateKeyAlgorithm",tagClass:pn.Class.UNIVERSAL,type:pn.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:pn.Class.UNIVERSAL,type:pn.Type.OID,constructed:!1,capture:"privateKeyOid"}]},{name:"PrivateKeyInfo",tagClass:pn.Class.UNIVERSAL,type:pn.Type.OCTETSTRING,constructed:!1,capture:"privateKey"}]},publicKeyValidator:{name:"SubjectPublicKeyInfo",tagClass:pn.Class.UNIVERSAL,type:pn.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:pn.Class.UNIVERSAL,type:pn.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:pn.Class.UNIVERSAL,type:pn.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{tagClass:pn.Class.UNIVERSAL,type:pn.Type.BITSTRING,constructed:!1,composed:!0,captureBitStringValue:"ed25519PublicKey"}]}},fn=dn.publicKeyValidator,hn=dn.privateKeyValidator;if(void 0===mn)var mn=z.jsbn.BigInteger;var gn=z.util.ByteBuffer,vn="undefined"==typeof Buffer?Uint8Array:Buffer;z.pki=z.pki||{},z.pki.ed25519=z.ed25519=z.ed25519||{};var yn=z.ed25519;function bn(e){var t=e.message;if(t instanceof Uint8Array||t instanceof vn)return t;var n=e.encoding;if(void 0===t){if(!e.md)throw new TypeError('"options.message" or "options.md" not specified.');t=e.md.digest().getBytes(),n="binary"}if("string"==typeof t&&!n)throw new TypeError('"options.encoding" must be "binary" or "utf8".');if("string"==typeof t){if("undefined"!=typeof Buffer)return Buffer.from(t,n);t=new gn(t,n)}else if(!(t instanceof gn))throw new TypeError('"options.message" must be a node.js Buffer, a Uint8Array, a forge ByteBuffer, or a string with "options.encoding" specifying its encoding.');for(var r=new vn(t.length()),a=0;a<r.length;++a)r[a]=t.at(a);return r}yn.constants={},yn.constants.PUBLIC_KEY_BYTE_LENGTH=32,yn.constants.PRIVATE_KEY_BYTE_LENGTH=64,yn.constants.SEED_BYTE_LENGTH=32,yn.constants.SIGN_BYTE_LENGTH=64,yn.constants.HASH_BYTE_LENGTH=64,yn.generateKeyPair=function(e){var t=(e=e||{}).seed;if(void 0===t)t=z.random.getBytesSync(yn.constants.SEED_BYTE_LENGTH);else if("string"==typeof t){if(t.length!==yn.constants.SEED_BYTE_LENGTH)throw new TypeError('"seed" must be '+yn.constants.SEED_BYTE_LENGTH+" bytes in length.")}else if(!(t instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, Uint8Array, or a binary string.');t=bn({message:t,encoding:"binary"});for(var n=new vn(yn.constants.PUBLIC_KEY_BYTE_LENGTH),r=new vn(yn.constants.PRIVATE_KEY_BYTE_LENGTH),a=0;a<32;++a)r[a]=t[a];return function(e,t){var n,r=[Wn(),Wn(),Wn(),Wn()],a=_n(t,32);for(a[0]&=248,a[31]&=127,a[31]|=64,Un(r,a),Bn(e,r),n=0;n<32;++n)t[n+32]=e[n]}(n,r),{publicKey:n,privateKey:r}},yn.privateKeyFromAsn1=function(e){var t={},n=[];if(!z.asn1.validate(e,hn,t,n)){var r=new Error("Invalid Key.");throw r.errors=n,r}var a=z.asn1.derToOid(t.privateKeyOid),o=z.oids.EdDSA25519;if(a!==o)throw new Error('Invalid OID "'+a+'"; OID must be "'+o+'".');var i=t.privateKey;return{privateKeyBytes:bn({message:z.asn1.fromDer(i).value,encoding:"binary"})}},yn.publicKeyFromAsn1=function(e){var t={},n=[];if(!z.asn1.validate(e,fn,t,n)){var r=new Error("Invalid Key.");throw r.errors=n,r}var a=z.asn1.derToOid(t.publicKeyOid),o=z.oids.EdDSA25519;if(a!==o)throw new Error('Invalid OID "'+a+'"; OID must be "'+o+'".');var i=t.ed25519PublicKey;if(i.length!==yn.constants.PUBLIC_KEY_BYTE_LENGTH)throw new Error("Key length is invalid.");return bn({message:i,encoding:"binary"})},yn.publicKeyFromPrivateKey=function(e){var t=bn({message:(e=e||{}).privateKey,encoding:"binary"});if(t.length!==yn.constants.PRIVATE_KEY_BYTE_LENGTH)throw new TypeError('"options.privateKey" must have a byte length of '+yn.constants.PRIVATE_KEY_BYTE_LENGTH);for(var n=new vn(yn.constants.PUBLIC_KEY_BYTE_LENGTH),r=0;r<n.length;++r)n[r]=t[32+r];return n},yn.sign=function(e){var t=bn(e=e||{}),n=bn({message:e.privateKey,encoding:"binary"});if(n.length===yn.constants.SEED_BYTE_LENGTH)n=yn.generateKeyPair({seed:n}).privateKey;else if(n.length!==yn.constants.PRIVATE_KEY_BYTE_LENGTH)throw new TypeError('"options.privateKey" must have a byte length of '+yn.constants.SEED_BYTE_LENGTH+" or "+yn.constants.PRIVATE_KEY_BYTE_LENGTH);var r=new vn(yn.constants.SIGN_BYTE_LENGTH+t.length);!function(e,t,n,r){var a,o,i=new Float64Array(64),s=[Wn(),Wn(),Wn(),Wn()],u=_n(r,32);for(u[0]&=248,u[31]&=127,u[31]|=64,a=0;a<n;++a)e[64+a]=t[a];for(a=0;a<32;++a)e[32+a]=u[32+a];var c=_n(e.subarray(32),n+32);for(An(c),Un(s,c),Bn(e,s),a=32;a<64;++a)e[a]=r[a];var l=_n(e,n+64);for(An(l),a=32;a<64;++a)i[a]=0;for(a=0;a<32;++a)i[a]=c[a];for(a=0;a<32;++a)for(o=0;o<32;o++)i[a+o]+=l[a]*u[o];Nn(e.subarray(32),i)}(r,t,t.length,n);for(var a=new vn(yn.constants.SIGN_BYTE_LENGTH),o=0;o<a.length;++o)a[o]=r[o];return a},yn.verify=function(e){var t=bn(e=e||{});if(void 0===e.signature)throw new TypeError('"options.signature" must be a node.js Buffer, a Uint8Array, a forge ByteBuffer, or a binary string.');var n=bn({message:e.signature,encoding:"binary"});if(n.length!==yn.constants.SIGN_BYTE_LENGTH)throw new TypeError('"options.signature" must have a byte length of '+yn.constants.SIGN_BYTE_LENGTH);var r=bn({message:e.publicKey,encoding:"binary"});if(r.length!==yn.constants.PUBLIC_KEY_BYTE_LENGTH)throw new TypeError('"options.publicKey" must have a byte length of '+yn.constants.PUBLIC_KEY_BYTE_LENGTH);var a,o=new vn(yn.constants.SIGN_BYTE_LENGTH+t.length),i=new vn(yn.constants.SIGN_BYTE_LENGTH+t.length);for(a=0;a<yn.constants.SIGN_BYTE_LENGTH;++a)o[a]=n[a];for(a=0;a<t.length;++a)o[a+yn.constants.SIGN_BYTE_LENGTH]=t[a];return function(e,t,n,r){var a,o=new vn(32),i=[Wn(),Wn(),Wn(),Wn()],s=[Wn(),Wn(),Wn(),Wn()];if(n<64)return-1;if(function(e,t){var n=Wn(),r=Wn(),a=Wn(),o=Wn(),i=Wn(),s=Wn(),u=Wn();return Vn(e[2],wn),function(e,t){var n;for(n=0;n<16;++n)e[n]=t[2*n]+(t[2*n+1]<<8);e[15]&=32767}(e[1],t),Kn(a,e[1]),qn(o,a,kn),Gn(a,a,e[2]),Hn(o,e[2],o),Kn(i,o),Kn(s,i),qn(u,s,i),qn(n,u,a),qn(n,n,o),function(e,t){var n,r=Wn();for(n=0;n<16;++n)r[n]=t[n];for(n=250;n>=0;--n)Kn(r,r),1!==n&&qn(r,r,t);for(n=0;n<16;++n)e[n]=r[n]}(n,n),qn(n,n,a),qn(n,n,o),qn(n,n,o),qn(e[0],n,o),Kn(r,e[0]),qn(r,r,o),Mn(r,a)&&qn(e[0],e[0],Tn),Kn(r,e[0]),qn(r,r,o),Mn(r,a)?-1:(Pn(e[0])===t[31]>>7&&Gn(e[0],xn,e[0]),qn(e[3],e[0],e[1]),0)}(s,r))return-1;for(a=0;a<n;++a)e[a]=t[a];for(a=0;a<32;++a)e[a+32]=r[a];var u=_n(e,n);if(An(u),Ln(i,s,u),Un(s,t.subarray(32)),Rn(i,s),Bn(o,i),n-=64,Fn(t,0,o,0)){for(a=0;a<n;++a)e[a]=0;return-1}for(a=0;a<n;++a)e[a]=t[a+64];return n}(i,o,o.length,r)>=0};var xn=Wn(),wn=Wn([1]),kn=Wn([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),Sn=Wn([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),En=Wn([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),In=Wn([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),Cn=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]),Tn=Wn([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function _n(e,t){var n=z.md.sha512.create(),r=new gn(e);n.update(r.getBytes(t),"binary");var a=n.digest().getBytes();if("undefined"!=typeof Buffer)return Buffer.from(a,"binary");for(var o=new vn(yn.constants.HASH_BYTE_LENGTH),i=0;i<64;++i)o[i]=a.charCodeAt(i);return o}function Nn(e,t){var n,r,a,o;for(r=63;r>=32;--r){for(n=0,a=r-32,o=r-12;a<o;++a)t[a]+=n-16*t[r]*Cn[a-(r-32)],n=t[a]+128>>8,t[a]-=256*n;t[a]+=n,t[r]=0}for(n=0,a=0;a<32;++a)t[a]+=n-(t[31]>>4)*Cn[a],n=t[a]>>8,t[a]&=255;for(a=0;a<32;++a)t[a]-=n*Cn[a];for(r=0;r<32;++r)t[r+1]+=t[r]>>8,e[r]=255&t[r]}function An(e){for(var t=new Float64Array(64),n=0;n<64;++n)t[n]=e[n],e[n]=0;Nn(e,t)}function Rn(e,t){var n=Wn(),r=Wn(),a=Wn(),o=Wn(),i=Wn(),s=Wn(),u=Wn(),c=Wn(),l=Wn();Gn(n,e[1],e[0]),Gn(l,t[1],t[0]),qn(n,n,l),Hn(r,e[0],e[1]),Hn(l,t[0],t[1]),qn(r,r,l),qn(a,e[3],t[3]),qn(a,a,Sn),qn(o,e[2],t[2]),Hn(o,o,o),Gn(i,r,n),Gn(s,o,a),Hn(u,o,a),Hn(c,r,n),qn(e[0],i,s),qn(e[1],c,u),qn(e[2],u,s),qn(e[3],i,c)}function On(e,t,n){for(var r=0;r<4;++r)jn(e[r],t[r],n)}function Bn(e,t){var n=Wn(),r=Wn(),a=Wn();!function(e,t){var n,r=Wn();for(n=0;n<16;++n)r[n]=t[n];for(n=253;n>=0;--n)Kn(r,r),2!==n&&4!==n&&qn(r,r,t);for(n=0;n<16;++n)e[n]=r[n]}(a,t[2]),qn(n,t[0],a),qn(r,t[1],a),Dn(e,r),e[31]^=Pn(n)<<7}function Dn(e,t){var n,r,a,o=Wn(),i=Wn();for(n=0;n<16;++n)i[n]=t[n];for(zn(i),zn(i),zn(i),r=0;r<2;++r){for(o[0]=i[0]-65517,n=1;n<15;++n)o[n]=i[n]-65535-(o[n-1]>>16&1),o[n-1]&=65535;o[15]=i[15]-32767-(o[14]>>16&1),a=o[15]>>16&1,o[14]&=65535,jn(i,o,1-a)}for(n=0;n<16;n++)e[2*n]=255&i[n],e[2*n+1]=i[n]>>8}function Mn(e,t){var n=new vn(32),r=new vn(32);return Dn(n,e),Dn(r,t),Fn(n,0,r,0)}function Fn(e,t,n,r){return function(e,t,n,r,a){var o,i=0;for(o=0;o<a;++o)i|=e[t+o]^n[r+o];return(1&i-1>>>8)-1}(e,t,n,r,32)}function Pn(e){var t=new vn(32);return Dn(t,e),1&t[0]}function Ln(e,t,n){var r,a;for(Vn(e[0],xn),Vn(e[1],wn),Vn(e[2],wn),Vn(e[3],xn),a=255;a>=0;--a)On(e,t,r=n[a/8|0]>>(7&a)&1),Rn(t,e),Rn(e,e),On(e,t,r)}function Un(e,t){var n=[Wn(),Wn(),Wn(),Wn()];Vn(n[0],En),Vn(n[1],In),Vn(n[2],wn),qn(n[3],En,In),Ln(e,n,t)}function Vn(e,t){var n;for(n=0;n<16;n++)e[n]=0|t[n]}function zn(e){var t,n,r=1;for(t=0;t<16;++t)n=e[t]+r+65535,r=Math.floor(n/65536),e[t]=n-65536*r;e[0]+=r-1+37*(r-1)}function jn(e,t,n){for(var r,a=~(n-1),o=0;o<16;++o)r=a&(e[o]^t[o]),e[o]^=r,t[o]^=r}function Wn(e){var t,n=new Float64Array(16);if(e)for(t=0;t<e.length;++t)n[t]=e[t];return n}function Hn(e,t,n){for(var r=0;r<16;++r)e[r]=t[r]+n[r]}function Gn(e,t,n){for(var r=0;r<16;++r)e[r]=t[r]-n[r]}function Kn(e,t){qn(e,t,t)}function qn(e,t,n){var r,a,o=0,i=0,s=0,u=0,c=0,l=0,p=0,d=0,f=0,h=0,m=0,g=0,v=0,y=0,b=0,x=0,w=0,k=0,S=0,E=0,I=0,C=0,T=0,_=0,N=0,A=0,R=0,O=0,B=0,D=0,M=0,F=n[0],P=n[1],L=n[2],U=n[3],V=n[4],z=n[5],j=n[6],W=n[7],H=n[8],G=n[9],K=n[10],q=n[11],Q=n[12],X=n[13],Y=n[14],$=n[15];o+=(r=t[0])*F,i+=r*P,s+=r*L,u+=r*U,c+=r*V,l+=r*z,p+=r*j,d+=r*W,f+=r*H,h+=r*G,m+=r*K,g+=r*q,v+=r*Q,y+=r*X,b+=r*Y,x+=r*$,i+=(r=t[1])*F,s+=r*P,u+=r*L,c+=r*U,l+=r*V,p+=r*z,d+=r*j,f+=r*W,h+=r*H,m+=r*G,g+=r*K,v+=r*q,y+=r*Q,b+=r*X,x+=r*Y,w+=r*$,s+=(r=t[2])*F,u+=r*P,c+=r*L,l+=r*U,p+=r*V,d+=r*z,f+=r*j,h+=r*W,m+=r*H,g+=r*G,v+=r*K,y+=r*q,b+=r*Q,x+=r*X,w+=r*Y,k+=r*$,u+=(r=t[3])*F,c+=r*P,l+=r*L,p+=r*U,d+=r*V,f+=r*z,h+=r*j,m+=r*W,g+=r*H,v+=r*G,y+=r*K,b+=r*q,x+=r*Q,w+=r*X,k+=r*Y,S+=r*$,c+=(r=t[4])*F,l+=r*P,p+=r*L,d+=r*U,f+=r*V,h+=r*z,m+=r*j,g+=r*W,v+=r*H,y+=r*G,b+=r*K,x+=r*q,w+=r*Q,k+=r*X,S+=r*Y,E+=r*$,l+=(r=t[5])*F,p+=r*P,d+=r*L,f+=r*U,h+=r*V,m+=r*z,g+=r*j,v+=r*W,y+=r*H,b+=r*G,x+=r*K,w+=r*q,k+=r*Q,S+=r*X,E+=r*Y,I+=r*$,p+=(r=t[6])*F,d+=r*P,f+=r*L,h+=r*U,m+=r*V,g+=r*z,v+=r*j,y+=r*W,b+=r*H,x+=r*G,w+=r*K,k+=r*q,S+=r*Q,E+=r*X,I+=r*Y,C+=r*$,d+=(r=t[7])*F,f+=r*P,h+=r*L,m+=r*U,g+=r*V,v+=r*z,y+=r*j,b+=r*W,x+=r*H,w+=r*G,k+=r*K,S+=r*q,E+=r*Q,I+=r*X,C+=r*Y,T+=r*$,f+=(r=t[8])*F,h+=r*P,m+=r*L,g+=r*U,v+=r*V,y+=r*z,b+=r*j,x+=r*W,w+=r*H,k+=r*G,S+=r*K,E+=r*q,I+=r*Q,C+=r*X,T+=r*Y,_+=r*$,h+=(r=t[9])*F,m+=r*P,g+=r*L,v+=r*U,y+=r*V,b+=r*z,x+=r*j,w+=r*W,k+=r*H,S+=r*G,E+=r*K,I+=r*q,C+=r*Q,T+=r*X,_+=r*Y,N+=r*$,m+=(r=t[10])*F,g+=r*P,v+=r*L,y+=r*U,b+=r*V,x+=r*z,w+=r*j,k+=r*W,S+=r*H,E+=r*G,I+=r*K,C+=r*q,T+=r*Q,_+=r*X,N+=r*Y,A+=r*$,g+=(r=t[11])*F,v+=r*P,y+=r*L,b+=r*U,x+=r*V,w+=r*z,k+=r*j,S+=r*W,E+=r*H,I+=r*G,C+=r*K,T+=r*q,_+=r*Q,N+=r*X,A+=r*Y,R+=r*$,v+=(r=t[12])*F,y+=r*P,b+=r*L,x+=r*U,w+=r*V,k+=r*z,S+=r*j,E+=r*W,I+=r*H,C+=r*G,T+=r*K,_+=r*q,N+=r*Q,A+=r*X,R+=r*Y,O+=r*$,y+=(r=t[13])*F,b+=r*P,x+=r*L,w+=r*U,k+=r*V,S+=r*z,E+=r*j,I+=r*W,C+=r*H,T+=r*G,_+=r*K,N+=r*q,A+=r*Q,R+=r*X,O+=r*Y,B+=r*$,b+=(r=t[14])*F,x+=r*P,w+=r*L,k+=r*U,S+=r*V,E+=r*z,I+=r*j,C+=r*W,T+=r*H,_+=r*G,N+=r*K,A+=r*q,R+=r*Q,O+=r*X,B+=r*Y,D+=r*$,x+=(r=t[15])*F,i+=38*(k+=r*L),s+=38*(S+=r*U),u+=38*(E+=r*V),c+=38*(I+=r*z),l+=38*(C+=r*j),p+=38*(T+=r*W),d+=38*(_+=r*H),f+=38*(N+=r*G),h+=38*(A+=r*K),m+=38*(R+=r*q),g+=38*(O+=r*Q),v+=38*(B+=r*X),y+=38*(D+=r*Y),b+=38*(M+=r*$),o=(r=(o+=38*(w+=r*P))+(a=1)+65535)-65536*(a=Math.floor(r/65536)),i=(r=i+a+65535)-65536*(a=Math.floor(r/65536)),s=(r=s+a+65535)-65536*(a=Math.floor(r/65536)),u=(r=u+a+65535)-65536*(a=Math.floor(r/65536)),c=(r=c+a+65535)-65536*(a=Math.floor(r/65536)),l=(r=l+a+65535)-65536*(a=Math.floor(r/65536)),p=(r=p+a+65535)-65536*(a=Math.floor(r/65536)),d=(r=d+a+65535)-65536*(a=Math.floor(r/65536)),f=(r=f+a+65535)-65536*(a=Math.floor(r/65536)),h=(r=h+a+65535)-65536*(a=Math.floor(r/65536)),m=(r=m+a+65535)-65536*(a=Math.floor(r/65536)),g=(r=g+a+65535)-65536*(a=Math.floor(r/65536)),v=(r=v+a+65535)-65536*(a=Math.floor(r/65536)),y=(r=y+a+65535)-65536*(a=Math.floor(r/65536)),b=(r=b+a+65535)-65536*(a=Math.floor(r/65536)),x=(r=x+a+65535)-65536*(a=Math.floor(r/65536)),o=(r=(o+=a-1+37*(a-1))+(a=1)+65535)-65536*(a=Math.floor(r/65536)),i=(r=i+a+65535)-65536*(a=Math.floor(r/65536)),s=(r=s+a+65535)-65536*(a=Math.floor(r/65536)),u=(r=u+a+65535)-65536*(a=Math.floor(r/65536)),c=(r=c+a+65535)-65536*(a=Math.floor(r/65536)),l=(r=l+a+65535)-65536*(a=Math.floor(r/65536)),p=(r=p+a+65535)-65536*(a=Math.floor(r/65536)),d=(r=d+a+65535)-65536*(a=Math.floor(r/65536)),f=(r=f+a+65535)-65536*(a=Math.floor(r/65536)),h=(r=h+a+65535)-65536*(a=Math.floor(r/65536)),m=(r=m+a+65535)-65536*(a=Math.floor(r/65536)),g=(r=g+a+65535)-65536*(a=Math.floor(r/65536)),v=(r=v+a+65535)-65536*(a=Math.floor(r/65536)),y=(r=y+a+65535)-65536*(a=Math.floor(r/65536)),b=(r=b+a+65535)-65536*(a=Math.floor(r/65536)),x=(r=x+a+65535)-65536*(a=Math.floor(r/65536)),o+=a-1+37*(a-1),e[0]=o,e[1]=i,e[2]=s,e[3]=u,e[4]=c,e[5]=l,e[6]=p,e[7]=d,e[8]=f,e[9]=h,e[10]=m,e[11]=g,e[12]=v,e[13]=y,e[14]=b,e[15]=x}z.kem=z.kem||{};var Qn=z.jsbn.BigInteger;function Xn(e,t,n,r){e.generate=function(e,a){for(var o=new z.util.ByteBuffer,i=Math.ceil(a/r)+n,s=new z.util.ByteBuffer,u=n;u<i;++u){s.putInt32(u),t.start(),t.update(e+s.getBytes());var c=t.digest();o.putBytes(c.getBytes(r))}return o.truncate(o.length()-a),o.getBytes()}}z.kem.rsa={},z.kem.rsa.create=function(e,t){var n=(t=t||{}).prng||z.random;return{encrypt:function(t,r){var a,o=Math.ceil(t.n.bitLength()/8);do{a=new Qn(z.util.bytesToHex(n.getBytesSync(o)),16).mod(t.n)}while(a.compareTo(Qn.ONE)<=0);var i=o-(a=z.util.hexToBytes(a.toString(16))).length;return i>0&&(a=z.util.fillString(String.fromCharCode(0),i)+a),{encapsulation:t.encrypt(a,"NONE"),key:e.generate(a,r)}},decrypt:function(t,n,r){var a=t.decrypt(n,"NONE");return e.generate(a,r)}}},z.kem.kdf1=function(e,t){Xn(this,e,0,t||e.digestLength)},z.kem.kdf2=function(e,t){Xn(this,e,1,t||e.digestLength)},z.log=z.log||{},z.log.levels=["none","error","warning","info","debug","verbose","max"];var Yn={},$n=[],Zn=null;z.log.LEVEL_LOCKED=2,z.log.NO_LEVEL_CHECK=4,z.log.INTERPOLATE=8;for(var Jn=0;Jn<z.log.levels.length;++Jn){var er=z.log.levels[Jn];Yn[er]={index:Jn,name:er.toUpperCase()}}z.log.logMessage=function(e){for(var t=Yn[e.level].index,n=0;n<$n.length;++n){var r=$n[n];r.flags&z.log.NO_LEVEL_CHECK?r.f(e):t<=Yn[r.level].index&&r.f(r,e)}},z.log.prepareStandard=function(e){"standard"in e||(e.standard=Yn[e.level].name+" ["+e.category+"] "+e.message)},z.log.prepareFull=function(e){if(!("full"in e)){var t=[e.message];t=t.concat([]||e.arguments),e.full=z.util.format.apply(this,t)}},z.log.prepareStandardFull=function(e){"standardFull"in e||(z.log.prepareStandard(e),e.standardFull=e.standard)};var tr=["error","warning","info","debug","verbose"];for(Jn=0;Jn<tr.length;++Jn)!function(e){z.log[e]=function(t,n){var r=Array.prototype.slice.call(arguments).slice(2),a={timestamp:new Date,level:e,category:t,message:n,arguments:r};z.log.logMessage(a)}}(tr[Jn]);if(z.log.makeLogger=function(e){var t={flags:0,f:e};return z.log.setLevel(t,"none"),t},z.log.setLevel=function(e,t){var n=!1;if(e&&!(e.flags&z.log.LEVEL_LOCKED))for(var r=0;r<z.log.levels.length;++r)if(t==z.log.levels[r]){e.level=t,n=!0;break}return n},z.log.lock=function(e,t){void 0===t||t?e.flags|=z.log.LEVEL_LOCKED:e.flags&=~z.log.LEVEL_LOCKED},z.log.addLogger=function(e){$n.push(e)},"undefined"!=typeof console&&"log"in console){var nr;if(console.error&&console.warn&&console.info&&console.debug){var rr={error:console.error,warning:console.warn,info:console.info,debug:console.debug,verbose:console.debug},ar=function(e,t){z.log.prepareStandard(t);var n=rr[t.level],r=[t.standard];r=r.concat(t.arguments.slice()),n.apply(console,r)};nr=z.log.makeLogger(ar)}else ar=function(e,t){z.log.prepareStandardFull(t),console.log(t.standardFull)},nr=z.log.makeLogger(ar);z.log.setLevel(nr,"debug"),z.log.addLogger(nr),Zn=nr}else console={log:function(){}};if(null!==Zn){var or=z.util.getQueryVariables();"console.level"in or&&z.log.setLevel(Zn,or["console.level"].slice(-1)[0]),"console.lock"in or&&"true"==or["console.lock"].slice(-1)[0]&&z.log.lock(Zn)}z.log.consoleLogger=Zn,w((function(e){var t=z.asn1,n=e.exports=z.pkcs7=z.pkcs7||{};function r(e){var r={},a=[];if(!t.validate(e,n.asn1.recipientInfoValidator,r,a)){var o=new Error("Cannot read PKCS#7 RecipientInfo. ASN.1 object is not an PKCS#7 RecipientInfo.");throw o.errors=a,o}return{version:r.version.charCodeAt(0),issuer:z.pki.RDNAttributesAsArray(r.issuer),serialNumber:z.util.createBuffer(r.serial).toHex(),encryptedContent:{algorithm:t.derToOid(r.encAlgorithm),parameter:r.encParameter.value,content:r.encKey}}}function a(e){for(var n,r=[],a=0;a<e.length;++a)r.push((n=e[a],t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(n.version).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[z.pki.distinguishedNameToAsn1({attributes:n.issuer}),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,z.util.hexToBytes(n.serialNumber))]),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.encryptedContent.algorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")]),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,n.encryptedContent.content)])));return r}function o(e){var n=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[z.pki.distinguishedNameToAsn1({attributes:e.issuer}),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,z.util.hexToBytes(e.serialNumber))]),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.digestAlgorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")])]);if(e.authenticatedAttributesAsn1&&n.value.push(e.authenticatedAttributesAsn1),n.value.push(t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.signatureAlgorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")])),n.value.push(t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,e.signature)),e.unauthenticatedAttributes.length>0){for(var r=t.create(t.Class.CONTEXT_SPECIFIC,1,!0,[]),a=0;a<e.unauthenticatedAttributes.length;++a){var o=e.unauthenticatedAttributes[a];r.values.push(i(o))}n.value.push(r)}return n}function i(e){var n;if(e.type===z.pki.oids.contentType)n=t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.value).getBytes());else if(e.type===z.pki.oids.messageDigest)n=t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,e.value.bytes());else if(e.type===z.pki.oids.signingTime){var r=new Date("1950-01-01T00:00:00Z"),a=new Date("2050-01-01T00:00:00Z"),o=e.value;if("string"==typeof o){var i=Date.parse(o);o=isNaN(i)?13===o.length?t.utcTimeToDate(o):t.generalizedTimeToDate(o):new Date(i)}n=o>=r&&o<a?t.create(t.Class.UNIVERSAL,t.Type.UTCTIME,!1,t.dateToUtcTime(o)):t.create(t.Class.UNIVERSAL,t.Type.GENERALIZEDTIME,!1,t.dateToGeneralizedTime(o))}return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.type).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[n])])}function s(e,n,r){var a={};if(!t.validate(n,r,a,[])){var o=new Error("Cannot read PKCS#7 message. ASN.1 object is not a supported PKCS#7 message.");throw o.errors=o,o}if(t.derToOid(a.contentType)!==z.pki.oids.data)throw new Error("Unsupported PKCS#7 message. Only wrapped ContentType Data supported.");if(a.encryptedContent){var i="";if(z.util.isArray(a.encryptedContent))for(var s=0;s<a.encryptedContent.length;++s){if(a.encryptedContent[s].type!==t.Type.OCTETSTRING)throw new Error("Malformed PKCS#7 message, expecting encrypted content constructed of only OCTET STRING objects.");i+=a.encryptedContent[s].value}else i=a.encryptedContent;e.encryptedContent={algorithm:t.derToOid(a.encAlgorithm),parameter:z.util.createBuffer(a.encParameter.value),content:z.util.createBuffer(i)}}if(a.content){if(i="",z.util.isArray(a.content))for(s=0;s<a.content.length;++s){if(a.content[s].type!==t.Type.OCTETSTRING)throw new Error("Malformed PKCS#7 message, expecting content constructed of only OCTET STRING objects.");i+=a.content[s].value}else i=a.content;e.content=z.util.createBuffer(i)}return e.version=a.version.charCodeAt(0),e.rawCapture=a,a}function u(e){if(void 0===e.encryptedContent.key)throw new Error("Symmetric key not available.");if(void 0===e.content){var t;switch(e.encryptedContent.algorithm){case z.pki.oids["aes128-CBC"]:case z.pki.oids["aes192-CBC"]:case z.pki.oids["aes256-CBC"]:t=z.aes.createDecryptionCipher(e.encryptedContent.key);break;case z.pki.oids.desCBC:case z.pki.oids["des-EDE3-CBC"]:t=z.des.createDecryptionCipher(e.encryptedContent.key);break;default:throw new Error("Unsupported symmetric cipher, OID "+e.encryptedContent.algorithm)}if(t.start(e.encryptedContent.parameter),t.update(e.encryptedContent.content),!t.finish())throw new Error("Symmetric decryption failed.");e.content=t.output}}n.messageFromPem=function(e){var r=z.pem.decode(e)[0];if("PKCS7"!==r.type){var a=new Error('Could not convert PKCS#7 message from PEM; PEM header type is not "PKCS#7".');throw a.headerType=r.type,a}if(r.procType&&"ENCRYPTED"===r.procType.type)throw new Error("Could not convert PKCS#7 message from PEM; PEM is encrypted.");var o=t.fromDer(r.body);return n.messageFromAsn1(o)},n.messageToPem=function(e,n){var r={type:"PKCS7",body:t.toDer(e.toAsn1()).getBytes()};return z.pem.encode(r,{maxline:n})},n.messageFromAsn1=function(e){var r={},a=[];if(!t.validate(e,n.asn1.contentInfoValidator,r,a)){var o=new Error("Cannot read PKCS#7 message. ASN.1 object is not an PKCS#7 ContentInfo.");throw o.errors=a,o}var i,s=t.derToOid(r.contentType);switch(s){case z.pki.oids.envelopedData:i=n.createEnvelopedData();break;case z.pki.oids.encryptedData:i=n.createEncryptedData();break;case z.pki.oids.signedData:i=n.createSignedData();break;default:throw new Error("Cannot read PKCS#7 message. ContentType with OID "+s+" is not (yet) supported.")}return i.fromAsn1(r.content.value[0]),i},n.createSignedData=function(){var e=null;return e={type:z.pki.oids.signedData,version:1,certificates:[],crls:[],signers:[],digestAlgorithmIdentifiers:[],contentInfo:null,signerInfos:[],fromAsn1:function(t){if(s(e,t,n.asn1.signedDataValidator),e.certificates=[],e.crls=[],e.digestAlgorithmIdentifiers=[],e.contentInfo=null,e.signerInfos=[],e.rawCapture.certificates)for(var r=e.rawCapture.certificates.value,a=0;a<r.length;++a)e.certificates.push(z.pki.certificateFromAsn1(r[a]))},toAsn1:function(){e.contentInfo||e.sign();for(var n=[],r=0;r<e.certificates.length;++r)n.push(z.pki.certificateToAsn1(e.certificates[r]));var a=[],o=t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,e.digestAlgorithmIdentifiers),e.contentInfo])]);return n.length>0&&o.value[0].value.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!0,n)),a.length>0&&o.value[0].value.push(t.create(t.Class.CONTEXT_SPECIFIC,1,!0,a)),o.value[0].value.push(t.create(t.Class.UNIVERSAL,t.Type.SET,!0,e.signerInfos)),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.type).getBytes()),o])},addSigner:function(t){var n=t.issuer,r=t.serialNumber;if(t.certificate){var a=t.certificate;"string"==typeof a&&(a=z.pki.certificateFromPem(a)),n=a.issuer.attributes,r=a.serialNumber}var o=t.key;if(!o)throw new Error("Could not add PKCS#7 signer; no private key specified.");"string"==typeof o&&(o=z.pki.privateKeyFromPem(o));var i=t.digestAlgorithm||z.pki.oids.sha1;switch(i){case z.pki.oids.sha1:case z.pki.oids.sha256:case z.pki.oids.sha384:case z.pki.oids.sha512:case z.pki.oids.md5:break;default:throw new Error("Could not add PKCS#7 signer; unknown message digest algorithm: "+i)}var s=t.authenticatedAttributes||[];if(s.length>0){for(var u=!1,c=!1,l=0;l<s.length;++l){var p=s[l];if(u||p.type!==z.pki.oids.contentType){if(c||p.type!==z.pki.oids.messageDigest);else if(c=!0,u)break}else if(u=!0,c)break}if(!u||!c)throw new Error("Invalid signer.authenticatedAttributes. If signer.authenticatedAttributes is specified, then it must contain at least two attributes, PKCS #9 content-type and PKCS #9 message-digest.")}e.signers.push({key:o,version:1,issuer:n,serialNumber:r,digestAlgorithm:i,signatureAlgorithm:z.pki.oids.rsaEncryption,signature:null,authenticatedAttributes:s,unauthenticatedAttributes:[]})},sign:function(n){var r;n=n||{},("object"!=typeof e.content||null===e.contentInfo)&&(e.contentInfo=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(z.pki.oids.data).getBytes())]),"content"in e&&(e.content instanceof z.util.ByteBuffer?r=e.content.bytes():"string"==typeof e.content&&(r=z.util.encodeUtf8(e.content)),n.detached?e.detachedContent=t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r):e.contentInfo.value.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r)])))),0!==e.signers.length&&function(n){var r;if(!(r=e.detachedContent?e.detachedContent:(r=e.contentInfo.value[1]).value[0]))throw new Error("Could not sign PKCS#7 message; there is no content to sign.");var a=t.derToOid(e.contentInfo.value[0].value),s=t.toDer(r);for(var u in s.getByte(),t.getBerValueLength(s),s=s.getBytes(),n)n[u].start().update(s);for(var c=new Date,l=0;l<e.signers.length;++l){var p=e.signers[l];if(0===p.authenticatedAttributes.length){if(a!==z.pki.oids.data)throw new Error("Invalid signer; authenticatedAttributes must be present when the ContentInfo content type is not PKCS#7 Data.")}else{p.authenticatedAttributesAsn1=t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[]);for(var d=t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[]),f=0;f<p.authenticatedAttributes.length;++f){var h=p.authenticatedAttributes[f];h.type===z.pki.oids.messageDigest?h.value=n[p.digestAlgorithm].digest():h.type===z.pki.oids.signingTime&&(h.value||(h.value=c)),d.value.push(i(h)),p.authenticatedAttributesAsn1.value.push(i(h))}s=t.toDer(d).getBytes(),p.md.start().update(s)}p.signature=p.key.sign(p.md,"RSASSA-PKCS1-V1_5")}e.signerInfos=function(e){for(var t=[],n=0;n<e.length;++n)t.push(o(e[n]));return t}(e.signers)}(function(){for(var n={},r=0;r<e.signers.length;++r){var a=e.signers[r];(o=a.digestAlgorithm)in n||(n[o]=z.md[z.pki.oids[o]].create()),0===a.authenticatedAttributes.length?a.md=n[o]:a.md=z.md[z.pki.oids[o]].create()}for(var o in e.digestAlgorithmIdentifiers=[],n)e.digestAlgorithmIdentifiers.push(t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(o).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")]));return n}())},verify:function(){throw new Error("PKCS#7 signature verification not yet implemented.")},addCertificate:function(t){"string"==typeof t&&(t=z.pki.certificateFromPem(t)),e.certificates.push(t)},addCertificateRevokationList:function(e){throw new Error("PKCS#7 CRL support not yet implemented.")}}},n.createEncryptedData=function(){var e=null;return e={type:z.pki.oids.encryptedData,version:0,encryptedContent:{algorithm:z.pki.oids["aes256-CBC"]},fromAsn1:function(t){s(e,t,n.asn1.encryptedDataValidator)},decrypt:function(t){void 0!==t&&(e.encryptedContent.key=t),u(e)}}},n.createEnvelopedData=function(){var e=null;return e={type:z.pki.oids.envelopedData,version:0,recipients:[],encryptedContent:{algorithm:z.pki.oids["aes256-CBC"]},fromAsn1:function(t){var a=s(e,t,n.asn1.envelopedDataValidator);e.recipients=function(e){for(var t=[],n=0;n<e.length;++n)t.push(r(e[n]));return t}(a.recipientInfos.value)},toAsn1:function(){return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.type).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,a(e.recipients)),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,(n=e.encryptedContent,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(z.pki.oids.data).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.algorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,n.parameter.getBytes())]),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,n.content.getBytes())])]))])])]);var n},findRecipient:function(t){for(var n=t.issuer.attributes,r=0;r<e.recipients.length;++r){var a=e.recipients[r],o=a.issuer;if(a.serialNumber===t.serialNumber&&o.length===n.length){for(var i=!0,s=0;s<n.length;++s)if(o[s].type!==n[s].type||o[s].value!==n[s].value){i=!1;break}if(i)return a}}return null},decrypt:function(t,n){if(void 0===e.encryptedContent.key&&void 0!==t&&void 0!==n)switch(t.encryptedContent.algorithm){case z.pki.oids.rsaEncryption:case z.pki.oids.desCBC:var r=n.decrypt(t.encryptedContent.content);e.encryptedContent.key=z.util.createBuffer(r);break;default:throw new Error("Unsupported asymmetric cipher, OID "+t.encryptedContent.algorithm)}u(e)},addRecipient:function(t){e.recipients.push({version:0,issuer:t.issuer.attributes,serialNumber:t.serialNumber,encryptedContent:{algorithm:z.pki.oids.rsaEncryption,key:t.publicKey}})},encrypt:function(t,n){if(void 0===e.encryptedContent.content){var r,a,o;switch(n=n||e.encryptedContent.algorithm,t=t||e.encryptedContent.key,n){case z.pki.oids["aes128-CBC"]:r=16,a=16,o=z.aes.createEncryptionCipher;break;case z.pki.oids["aes192-CBC"]:r=24,a=16,o=z.aes.createEncryptionCipher;break;case z.pki.oids["aes256-CBC"]:r=32,a=16,o=z.aes.createEncryptionCipher;break;case z.pki.oids["des-EDE3-CBC"]:r=24,a=8,o=z.des.createEncryptionCipher;break;default:throw new Error("Unsupported symmetric cipher, OID "+n)}if(void 0===t)t=z.util.createBuffer(z.random.getBytes(r));else if(t.length()!=r)throw new Error("Symmetric key has wrong length; got "+t.length()+" bytes, expected "+r+".");e.encryptedContent.algorithm=n,e.encryptedContent.key=t,e.encryptedContent.parameter=z.util.createBuffer(z.random.getBytes(a));var i=o(t);if(i.start(e.encryptedContent.parameter.copy()),i.update(e.content),!i.finish())throw new Error("Symmetric encryption failed.");e.encryptedContent.content=i.output}for(var s=0;s<e.recipients.length;++s){var u=e.recipients[s];if(void 0===u.encryptedContent.content)switch(u.encryptedContent.algorithm){case z.pki.oids.rsaEncryption:u.encryptedContent.content=u.encryptedContent.key.encrypt(e.encryptedContent.key.data);break;default:throw new Error("Unsupported asymmetric cipher, OID "+u.encryptedContent.algorithm)}}}}}})),w((function(e){var t=e.exports=z.ssh=z.ssh||{};function n(e,t){var n=t.toString(16);n[0]>="8"&&(n="00"+n);var r=z.util.hexToBytes(n);e.putInt32(r.length),e.putBytes(r)}function r(e,t){e.putInt32(t.length),e.putString(t)}function a(){for(var e=z.md.sha1.create(),t=arguments.length,n=0;n<t;++n)e.update(arguments[n]);return e.digest()}t.privateKeyToPutty=function(e,t,o){var i=""===(t=t||"")?"none":"aes256-cbc",s="PuTTY-User-Key-File-2: ssh-rsa\r\n";s+="Encryption: "+i+"\r\n",s+="Comment: "+(o=o||"")+"\r\n";var u=z.util.createBuffer();r(u,"ssh-rsa"),n(u,e.e),n(u,e.n);var c=z.util.encode64(u.bytes(),64),l=Math.floor(c.length/66)+1;s+="Public-Lines: "+l+"\r\n",s+=c;var p,d=z.util.createBuffer();if(n(d,e.d),n(d,e.p),n(d,e.q),n(d,e.qInv),t){var f=d.length()+16-1;f-=f%16;var h=a(d.bytes());h.truncate(h.length()-f+d.length()),d.putBuffer(h);var m=z.util.createBuffer();m.putBuffer(a("\0\0\0\0",t)),m.putBuffer(a("\0\0\0",t));var g=z.aes.createEncryptionCipher(m.truncate(8),"CBC");g.start(z.util.createBuffer().fillWithByte(0,16)),g.update(d.copy()),g.finish();var v=g.output;v.truncate(16),p=z.util.encode64(v.bytes(),64)}else p=z.util.encode64(d.bytes(),64);s+="\r\nPrivate-Lines: "+(l=Math.floor(p.length/66)+1)+"\r\n",s+=p;var y=a("putty-private-key-file-mac-key",t),b=z.util.createBuffer();r(b,"ssh-rsa"),r(b,i),r(b,o),b.putInt32(u.length()),b.putBuffer(u),b.putInt32(d.length()),b.putBuffer(d);var x=z.hmac.create();return x.start("sha1",y),x.update(b.bytes()),s+"\r\nPrivate-MAC: "+x.digest().toHex()+"\r\n"},t.publicKeyToOpenSSH=function(e,t){t=t||"";var a=z.util.createBuffer();return r(a,"ssh-rsa"),n(a,e.e),n(a,e.n),"ssh-rsa "+z.util.encode64(a.bytes())+" "+t},t.privateKeyToOpenSSH=function(e,t){return t?z.pki.encryptRsaPrivateKey(e,t,{legacy:!0,algorithm:"aes128"}):z.pki.privateKeyToPem(e)},t.getPublicKeyFingerprint=function(e,t){var a=(t=t||{}).md||z.md.md5.create(),o=z.util.createBuffer();r(o,"ssh-rsa"),n(o,e.e),n(o,e.n),a.start(),a.update(o.getBytes());var i=a.digest();if("hex"===t.encoding){var s=i.toHex();return t.delimiter?s.match(/.{2}/g).join(t.delimiter):s}if("binary"===t.encoding)return i.getBytes();if(t.encoding)throw new Error('Unknown encoding "'+t.encoding+'".');return i}}));var ir="forge.task",sr={},ur=0;z.debug.set(ir,"tasks",sr);var cr={};z.debug.set(ir,"queues",cr);var lr="ready",pr="running",dr="blocked",fr="sleeping",hr="done",mr="error",gr={ready:{}};gr.ready.stop=lr,gr.ready.start=pr,gr.ready.cancel=hr,gr.ready.fail=mr,gr.running={},gr.running.stop=lr,gr.running.start=pr,gr.running.block=dr,gr.running.unblock=pr,gr.running.sleep=fr,gr.running.wakeup=pr,gr.running.cancel=hr,gr.running.fail=mr,gr.blocked={},gr.blocked.stop=dr,gr.blocked.start=dr,gr.blocked.block=dr,gr.blocked.unblock=dr,gr.blocked.sleep=dr,gr.blocked.wakeup=dr,gr.blocked.cancel=hr,gr.blocked.fail=mr,gr.sleeping={},gr.sleeping.stop=fr,gr.sleeping.start=fr,gr.sleeping.block=fr,gr.sleeping.unblock=fr,gr.sleeping.sleep=fr,gr.sleeping.wakeup=fr,gr.sleeping.cancel=hr,gr.sleeping.fail=mr,gr.done={},gr.done.stop=hr,gr.done.start=hr,gr.done.block=hr,gr.done.unblock=hr,gr.done.sleep=hr,gr.done.wakeup=hr,gr.done.cancel=hr,gr.done.fail=mr,gr.error={},gr.error.stop=mr,gr.error.start=mr,gr.error.block=mr,gr.error.unblock=mr,gr.error.sleep=mr,gr.error.wakeup=mr,gr.error.cancel=mr,gr.error.fail=mr;var vr=function(e){this.id=-1,this.name=e.name||"?",this.parent=e.parent||null,this.run=e.run,this.subtasks=[],this.error=!1,this.state=lr,this.blocks=0,this.timeoutId=null,this.swapTime=null,this.userData=null,this.id=ur++,sr[this.id]=this};vr.prototype.debug=function(e){e=e||"",z.log.debug(ir,e,"[%s][%s] task:",this.id,this.name,this,"subtasks:",this.subtasks.length,"queue:",cr)},vr.prototype.next=function(e,t){"function"==typeof e&&(t=e,e=this.name);var n=new vr({run:t,name:e,parent:this});return n.state=pr,n.type=this.type,n.successCallback=this.successCallback||null,n.failureCallback=this.failureCallback||null,this.subtasks.push(n),this},vr.prototype.parallel=function(e,t){return z.util.isArray(e)&&(t=e,e=this.name),this.next(e,(function(n){var r=n;r.block(t.length);for(var a=function(e,n){z.task.start({type:e,run:function(e){t[n](e)},success:function(e){r.unblock()},failure:function(e){r.unblock()}})},o=0;o<t.length;o++)a(e+"__parallel-"+n.id+"-"+o,o)}))},vr.prototype.stop=function(){this.state=gr[this.state].stop},vr.prototype.start=function(){this.error=!1,this.state=gr[this.state].start,this.state===pr&&(this.start=new Date,this.run(this),yr(this,0))},vr.prototype.block=function(e){e=void 0===e?1:e,this.blocks+=e,this.blocks>0&&(this.state=gr[this.state].block)},vr.prototype.unblock=function(e){return e=void 0===e?1:e,this.blocks-=e,0===this.blocks&&this.state!==hr&&(this.state=pr,yr(this,0)),this.blocks},vr.prototype.sleep=function(e){e=void 0===e?0:e,this.state=gr[this.state].sleep;var t=this;this.timeoutId=setTimeout((function(){t.timeoutId=null,t.state=pr,yr(t,0)}),e)},vr.prototype.wait=function(e){e.wait(this)},vr.prototype.wakeup=function(){this.state===fr&&(cancelTimeout(this.timeoutId),this.timeoutId=null,this.state=pr,yr(this,0))},vr.prototype.cancel=function(){this.state=gr[this.state].cancel,this.permitsNeeded=0,null!==this.timeoutId&&(cancelTimeout(this.timeoutId),this.timeoutId=null),this.subtasks=[]},vr.prototype.fail=function(e){if(this.error=!0,br(this,!0),e)e.error=this.error,e.swapTime=this.swapTime,e.userData=this.userData,yr(e,0);else{if(null!==this.parent){for(var t=this.parent;null!==t.parent;)t.error=this.error,t.swapTime=this.swapTime,t.userData=this.userData,t=t.parent;br(t,!0)}this.failureCallback&&this.failureCallback(this)}};var yr=function(e,t){var n=t>30||+new Date-e.swapTime>20,r=function(t){if(t++,e.state===pr)if(n&&(e.swapTime=+new Date),e.subtasks.length>0){var r=e.subtasks.shift();r.error=e.error,r.swapTime=e.swapTime,r.userData=e.userData,r.run(r),r.error||yr(r,t)}else br(e),e.error||null!==e.parent&&(e.parent.error=e.error,e.parent.swapTime=e.swapTime,e.parent.userData=e.userData,yr(e.parent,t))};n?setTimeout(r,0):r(t)},br=function(e,t){e.state=hr,delete sr[e.id],null===e.parent&&(e.type in cr?0===cr[e.type].length?z.log.error(ir,"[%s][%s] task queue empty [%s]",e.id,e.name,e.type):cr[e.type][0]!==e?z.log.error(ir,"[%s][%s] task not first in queue [%s]",e.id,e.name,e.type):(cr[e.type].shift(),0===cr[e.type].length?delete cr[e.type]:cr[e.type][0].start()):z.log.error(ir,"[%s][%s] task queue missing [%s]",e.id,e.name,e.type),t||(e.error&&e.failureCallback?e.failureCallback(e):!e.error&&e.successCallback&&e.successCallback(e)))};z.task=z.task||{},z.task.start=function(e){var t=new vr({run:e.run,name:e.name||"?"});t.type=e.type,t.successCallback=e.success||null,t.failureCallback=e.failure||null,t.type in cr?cr[e.type].push(t):(cr[t.type]=[t],function(e){e.error=!1,e.state=gr[e.state].start,setTimeout((function(){e.state===pr&&(e.swapTime=+new Date,e.run(e),yr(e,0))}),0)}(t))},z.task.cancel=function(e){e in cr&&(cr[e]=[cr[e][0]])},z.task.createCondition=function(){var e={tasks:{},wait:function(t){t.id in e.tasks||(t.block(),e.tasks[t.id]=t)},notify:function(){var t=e.tasks;for(var n in e.tasks={},t)t[n].unblock()}};return e};var xr=z,wr=function(){function e(e){this.secretKey=e}return e.prototype.encrypt=function(e,t){throw new Error("Method not implemented.")},e.prototype.decrypt=function(e,t){return function(e,t,n){void 0===n&&(n=xr.util.createBuffer(Uint8Array.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer));var r,a,o=xr.cipher.createDecipher("AES-CBC",t);return o.start({iv:n}),o.update(xr.util.createBuffer(xr.util.hexToBytes(e))),a=(r=o.output.data).charCodeAt(r.length-1),r.slice(0,-a)}(e,(n=this.secretKey,r=t.transactionID,""+n.slice(0,16)+r.slice(0,16)));var n,r},e}(),kr=function(){function e(e,t,n,a){void 0===n&&(n="production"),void 0===a&&(a={supportTransaction:!1,enableEncryption:!1}),this.transactionEnabled=a.supportTransaction||!1,this.encryptionEnabled=a.enableEncryption||!1;var o=F(e,t,n,{headers:a.httpHeaders});this.transactionManager=new V(o),this.encryptionService=new wr(t),this.compareFaceService=new p(o),this.clientSettingsService=new d(o),this.convertPDFService=new y(o),this.ekycPDFService=new b(o),this.readIDCardService=new r(o),this.requestVerifyIDCardService=new h(o),this.requestVerifyPortraitSerivce=new m(o),this.imagesService=new c(o),this.fileService=new l(o),this.verifyFaceLivenessService=new f(o),this.searchFaceService=new v(o),this.detectIDTamperingService=new g(o)}return e.prototype.enableTransaction=function(){this.transactionEnabled=!0},e.prototype.disableTransaction=function(){this.transactionEnabled=!1},e.prototype.enableEncryption=function(){this.encryptionEnabled=!0},e.prototype.disableEncryption=function(){this.encryptionEnabled=!1},e.prototype.compareFaces=function(e,t){return this.compareFaceService.request(e,t)},e.prototype.clientSettings=function(){return this.clientSettingsService.request()},e.prototype.uploadImage=function(e){return this.imagesService.request(e)},e.prototype.uploadFile=function(e){return this.fileService.uploadFile(e)},e.prototype.convertPDF=function(e,t){return this.convertPDFService.request(e,t)},e.prototype.ekycPDF=function(e,t){return this.ekycPDFService.request(e,t)},e.prototype.readIDCard=function(e,t){return this.readIDCardService.request(e,t)},e.prototype.requestVerifyIDCard=function(e,t){return this.requestVerifyIDCardService.request(e,t)},e.prototype.requestVerifyPortrait=function(e,t){return this.requestVerifyPortraitSerivce.request(e,t)},e.prototype.verifyFaceLiveness=function(e,t){return this.verifyFaceLivenessService.request(e,t)},e.prototype.searchFaces=function(e,t){return this.searchFaceService.request(e,t)},e.prototype.deleteFaces=function(e,t){return this.searchFaceService.deleteFaces(e,t)},e.prototype.indexFaces=function(e,t){return this.searchFaceService.indexFaces(e,t)},e.prototype.downloadFaceImage=function(e){return this.searchFaceService.downloadFaceImage(e)},e.prototype.downloadImage=function(e){return this.imagesService.download(e)},e.prototype.updateMetadata=function(e,t){return this.imagesService.updateMetadata(e,t)},e.prototype.detectIDTampering=function(e,t){return this.detectIDTamperingService.request(e,t)},o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"compareFaces",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"convertPDF",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"readIDCard",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"requestVerifyIDCard",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"requestVerifyPortrait",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"verifyFaceLiveness",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"searchFaces",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"deleteFaces",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"indexFaces",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"detectIDTampering",null),e}();e.ReadIDCard=r,e.UploadImage=c,e.UploadFile=l,e.CompareFaces=p,e.ClientSettings=d,e.VerifyFaceLiveness=f,e.RequestVerifyIDCard=h,e.RequestVerifyPortrait=m,e.DetectIDTampering=g,e.SearchFaces=v,e.ConvertPDF=y,e.EkycPDF=b,e.HttpClient=N,e.MockClient=A,e.TVAuthorizer=D,e.createHelpers=function(e,t,n){void 0===n&&(n="production");var r=new D(e,t),a=function(e){switch(e){case"testing":return"https://tv-testing.trustingsocial.com/api";case"staging":return"https://tv-staging.trustingsocial.com/api";case"production":default:return"https://vn-vision.trustingsocial.com/api"}}(n);return new N({authorizer:r,domain:a})},e.createHttpClient=F,e.SimpleTrustVisionAPI=P,e.default=kr,Object.defineProperty(e,"__esModule",{value:!0})}(r,t.default)}))),Kce=["accessKey","secretKey","apiUrl"],qce=["apiCheck","mode","accessKey","secretKey","apiUrl","onLivenessDetectionDone","onError"],Qce=tx.getUAMetadata(),Xce=function(){function e(t){var n=this,r=t.container,a=t.lang,o=void 0===a?"en":a,i=t.assetRoot,s=void 0===i?"https://unpkg.com/@tsocial/tvweb-sdk@latest/assets":i,u=t.libRoot,c=void 0===u?"":u,l=t.enableAntiDebug,p=void 0===l||l;Jm(this,e),ng(this,"checkCamera",(function(e){var t=e.frontCamera,r=void 0===t||t;return new Promise((function(e){K4.render(lv.createElement(jv.SDKSettingsProvider,{value:og({},n.commonSettings)},lv.createElement(j6,{checkCameraMode:!0,frontCamera:r,onVideoPlayed:function(){n.destroyView(),e(null)},onClose:n.destroyView,onError:function(t){n.destroyView(),e(t)}})),n.container)}))})),ng(this,"runWarmUpReadIDCard",Zm(regeneratorRuntime.mark((function e(){var t,r,a,o,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.commonSettings,r=t.tfjsWasmRoot,a=t.blazefaceRoot,o=t.opencvUrl,i=t.idCardModelUrl,e.abrupt("return",Vse({opencvUrl:o,modelUrl:i,blazefaceRoot:a,tfjsWasmRoot:r}));case 2:case"end":return e.stop()}}),e)})))),ng(this,"destroyView",(function(){K4.unmountComponentAtNode(n.container)})),Hce(r,"container is a required parameter"),this.container=r,this.lang=o,this.assetRoot=s,this.libRoot=c,this.enableAntiDebug=p,this.commonSettings={lang:this.lang,assetRoot:this.assetRoot,tfjsWasmRoot:this.libRoot?"".concat(this.libRoot,"/tfjs-backend-wasm/"):void 0,blazefaceRoot:this.libRoot?"".concat(this.libRoot,"/blaze-face-model/model.json"):void 0,opencvUrl:this.libRoot?"".concat(this.libRoot,"/opencv.js"):void 0,idCardModelUrl:this.libRoot?"".concat(this.libRoot,"/id-card-model/uint8/model.json"):void 0}}return tg(e,[{key:"readIDCard",value:function(e){var t=e.accessKey,n=e.secretKey,r=e.apiUrl,a=pg(e,Kce),o=ux.createRetryAPIClient(new Gce(t,n,r,{httpHeaders:Qce}));K4.render(lv.createElement(jv.SDKSettingsProvider,{value:og(og({},this.commonSettings),{},{apiClient:o,debug:!1,enableAntiDebug:this.enableAntiDebug})},lv.createElement(Dce,rg({onClose:this.destroyView},a))),this.container)}},{key:"livenessDetection",value:function(e){var t=e.apiCheck,n=e.mode,r=e.accessKey,a=e.secretKey,o=e.apiUrl,i=e.onLivenessDetectionDone,s=e.onError,u=pg(e,qce),c=ux.createRetryAPIClient(new Gce(r,a,o,{httpHeaders:Qce}));K4.render(lv.createElement(jv.SDKSettingsProvider,{value:og(og({},this.commonSettings),{},{apiClient:c})},lv.createElement(zce,rg({},u,{apiCheck:t,mode:n,onLivenessDetectionDone:i,onClose:this.destroyView,onError:s}))),this.container)}},{key:"compareFaces",value:function(e){var t=e.accessKey,n=e.secretKey,r=e.apiUrl,a=e.image1,o=e.image2,i=e.onSuccess,s=e.onError;ux.createRetryAPIClient(new Gce(t,n,r,{httpHeaders:Qce})).compareFaces({image1:{id:a},image2:{id:o}}).then((function(e){i(e)})).catch((function(e){s(e)}))}}]),e}();exports.APIUtils=ux,exports.Animations=Vue,exports.AntiDebugUtils=NK,exports.AssetUtils=Gv,exports.AsyncUtils=qv,exports.BASE_Z_INDEX=1e3,exports.BlurUtils=Ty,exports.Camera=j6,exports.CameraUtils=Ny,exports.CommonUtils=Ry,exports.Constants=Lv,exports.CoordinateUtils=Fy,exports.CropAreaOverlayWrapper=Q6,exports.FaceUtils=Hy,exports.GlareUtils=Jb,exports.Icons=Fce,exports.ImageUtils=Xb,exports.LivenessDetection=zce,exports.LivenessDetectionComponents=Wce,exports.LoadResourceUtils=yx,exports.MobileDetect=w6,exports.ModelUtils=_K,exports.PlacementArea=q6,exports.PredictionUtils=Qy,exports.ProgressCircle=y9,exports.ReadIDCard=Dce,exports.SDK=Xce,exports.SettingsContext=jv,exports.UserAgentUtils=tx,exports.useLivenessDetection=jce,exports.warmUpReadIdCard=Vse;
7152
+ ***************************************************************************** */function o(e,t,n,r){var a,o=arguments.length,i=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,n,i):a(t,n))||i);return o>3&&i&&Object.defineProperty(t,n,i),i}function i(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function u(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=(a=i.trys).length>0&&a[a.length-1])&&(6===o[0]||2===o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var c=function(){function e(e){this.httpClient=e}return e.prototype.uploadImage=function(e){return this.httpClient.postFormData("/v1/images",e)},e.prototype.request=function(e){var t="application/pdf"===e.file.type;return this.httpClient.postFormData(t?"/v1/files":"/v1/images",e)},e.prototype.requestWithHeaders=function(e,t){return this.httpClient.postFormData("/v1/images",e,t)},e.prototype.download=function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,this.httpClient.downloadFile("/v1/images/"+e)];case 1:return t=n.sent(),[4,URL.createObjectURL(t)];case 2:return[2,n.sent()]}}))}))},e.prototype.updateMetadata=function(e,t){return this.httpClient.patch("/v1/images/"+e,t)},e}(),l=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/files",e,t)},e.prototype.uploadFile=function(e){return this.httpClient.postFormData("/v1/files",e)},e.prototype.requestWithHeaders=function(e,t){return this.httpClient.postFormData("/v1/files",e,t)},e}(),p=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/compare_faces_sync",e,t)},e}(),d=function(){function e(e){this.httpClient=e}return e.prototype.getClientSettings=function(){return this.httpClient.get("/v1/client_settings")},e.prototype.request=function(){return this.httpClient.get("/v1/client_settings")},e}(),f=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/verify_face_liveness_sync",e,t)},e}(),h=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/verify_id_card_sanity_sync",e,t)},e}(),m=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/verify_portrait_sanity_sync",e,t)},e}(),g=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/detect_id_card_tampering_sync",e,t)},e.prototype.requestWithAuthHeaders=function(e,t){return this.httpClient.post("/v1/detect_id_card_tampering_sync",e,t)},e}(),v=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/search_faces_sync",e,t)},e.prototype.indexFaces=function(e,t){return this.httpClient.post("/v1/index_faces_sync",e,t)},e.prototype.deleteFaces=function(e,t){return this.httpClient.post("/v1/delete_faces",e,t)},e.prototype.downloadFaceImage=function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,this.httpClient.downloadFile("/v1/face_images/"+e)];case 1:return t=n.sent(),[2,URL.createObjectURL(t)]}}))}))},e}(),y=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.postFormData("/v1/convert_pdf_sync",e,t)},e}(),b=function(){function e(e){this.httpClient=e}return e.prototype.request=function(e,t){return this.httpClient.post("/v1/ekyc_pdf",e,t)},e}(),x="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==n?n:"undefined"!=typeof self?self:{};function w(e,t){return e(t={exports:{}},t.exports),t.exports}var k=w((function(e){var t,n;t=x,n=function(){function e(e){var t=[];if(0===e.length)return"";if("string"!=typeof e[0])throw new TypeError("Url must be a string. Received "+e[0]);if(e[0].match(/^[^/:]+:\/*$/)&&e.length>1){var n=e.shift();e[0]=n+e[0]}e[0].match(/^file:\/\/\//)?e[0]=e[0].replace(/^([^/:]+):\/*/,"$1:///"):e[0]=e[0].replace(/^([^/:]+):\/*/,"$1://");for(var r=0;r<e.length;r++){var a=e[r];if("string"!=typeof a)throw new TypeError("Url must be a string. Received "+a);""!==a&&(r>0&&(a=a.replace(/^[\/]+/,"")),a=r<e.length-1?a.replace(/[\/]+$/,""):a.replace(/[\/]+$/,"/"),t.push(a))}var o=t.join("/"),i=(o=o.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return i.shift()+(i.length>0?"?":"")+i.join("&")}return function(){return e("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},e.exports?e.exports=n():t.urljoin=n()}));function S(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var E=function(e,t,n,r){t=t||"&",n=n||"=";var a={};if("string"!=typeof e||0===e.length)return a;var o=/\+/g;e=e.split(t);var i=1e3;r&&"number"==typeof r.maxKeys&&(i=r.maxKeys);var s=e.length;i>0&&s>i&&(s=i);for(var u=0;u<s;++u){var c,l,p,d,f=e[u].replace(o,"%20"),h=f.indexOf(n);h>=0?(c=f.substr(0,h),l=f.substr(h+1)):(c=f,l=""),p=decodeURIComponent(c),d=decodeURIComponent(l),S(a,p)?Array.isArray(a[p])?a[p].push(d):a[p]=[a[p],d]:a[p]=d}return a},I=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},C=function(e,t,n,r){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map((function(r){var a=encodeURIComponent(I(r))+n;return Array.isArray(e[r])?e[r].map((function(e){return a+encodeURIComponent(I(e))})).join(t):a+encodeURIComponent(I(e[r]))})).join(t):r?encodeURIComponent(I(r))+n+encodeURIComponent(I(e)):""},T=w((function(e,t){t.decode=t.parse=E,t.encode=t.stringify=C})),_=(T.decode,T.parse,T.encode,T.stringify),N=function(){function e(e){this.authorizer=e.authorizer,this.domain=e.domain,this.onError=e.onError,this.configHeaders=e.headers}return e.prototype.get=function(e,t,n){var r=new URL(this.resolveUrl(e));return t&&(r.search=_(t)),this.request(r.toString(),{requestPath:e,method:"GET",headers:n})},e.prototype.post=function(e,t,n){var r=this.resolveUrl(e);return this.request(r,{requestPath:e,method:"POST",body:JSON.stringify(t),headers:a({"Content-Type":"application/json"},n)})},e.prototype.postFormData=function(e,t,n){var r,a=t instanceof FormData?t:(r=t,Object.entries(r).reduce((function(e,t){var n=t[0],r=t[1];return Array.isArray(r)?r.forEach((function(t,a){return e.append(n+"["+a+"]",r)})):!(r instanceof Object)||r instanceof File||r instanceof Date||r instanceof Blob?e.append(n,r):Object.entries(r).forEach((function(t,a){return e.append(n+"["+a+"]",r[a])})),e}),new FormData)),o=this.resolveUrl(e);return this.request(o,{requestPath:e,method:"POST",body:a,headers:n})},e.prototype.patch=function(e,t,n){var r=this.resolveUrl(e);return this.request(r,{requestPath:e,method:"PATCH",body:JSON.stringify(t),headers:a({"Content-Type":"application/json"},n)})},e.prototype.delete=function(e,t,n){var r=this.resolveUrl(e);return this.request(r,{requestPath:e,method:"DELETE",body:JSON.stringify(t),headers:a({"Content-Type":"application/json"},n)})},e.prototype.downloadFile=function(e){var t=this.resolveUrl(e);return this.request(t,{requestPath:e,method:"GET"},"blob")},e.prototype.request=function(e,t,n){return void 0===n&&(n="json"),s(this,void 0,void 0,(function(){var r,o,i,s;return u(this,(function(u){switch(u.label){case 0:return r={},o={},this.authorizer&&(r=this.authorizer.getHeaders(t)),this.configHeaders&&(o=this.configHeaders),t.headers=a(a(a({},t.headers),r),o),[4,fetch(e,t)];case 1:return i=u.sent(),[4,"blob"===n?i.blob():i.json()];case 2:if((s=u.sent()).errors&&this.onError)throw this.onError(s.errors),s;return[2,s]}}))}))},e.prototype.resolveUrl=function(e){return k(this.domain,e)},e}(),A=function(){function e(e){this.mocks=e}return e.prototype.get=function(e,t){return this.findInMocks(e,t)},e.prototype.post=function(e,t){return this.findInMocks(e)},e.prototype.postFormData=function(e,t){return this.findInMocks(e)},e.prototype.patch=function(e,t){return this.findInMocks(e)},e.prototype.delete=function(e,t){return this.findInMocks(e)},e.prototype.downloadFile=function(e){return this.findInMocks(e)},e.prototype.resolveUrl=function(e){return this.mocks.resolveUrl?this.mocks.resolveUrl(e):e},e.prototype.findInMocks=function(e,t){return s(this,void 0,void 0,(function(){return u(this,(function(n){return this.mocks[e]?"function"==typeof this.mocks[e]?[2,Promise.resolve(this.mocks[e](t))]:[2,Promise.resolve(this.mocks[e])]:[2,Promise.reject(new Error(e+" is not presented in mocks"))]}))}))},e}(),R=w((function(e,t){var n;e.exports=n=n||function(e,t){var n=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),r={},a=r.lib={},o=a.Base={extend:function(e){var t=n(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=a.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,a=e.sigBytes;if(this.clamp(),r%4)for(var o=0;o<a;o++){var i=n[o>>>2]>>>24-o%4*8&255;t[r+o>>>2]|=i<<24-(r+o)%4*8}else for(o=0;o<a;o+=4)t[r+o>>>2]=n[o>>>2];return this.sigBytes+=a,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n,r=[],a=function(t){t=t;var n=987654321,r=4294967295;return function(){var a=((n=36969*(65535&n)+(n>>16)&r)<<16)+(t=18e3*(65535&t)+(t>>16)&r)&r;return a/=4294967296,(a+=.5)*(e.random()>.5?1:-1)}},o=0;o<t;o+=4){var s=a(4294967296*(n||e.random()));n=987654071*s(),r.push(4294967296*s()|0)}return new i.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],a=0;a<n;a++){var o=t[a>>>2]>>>24-a%4*8&255;r.push((o>>>4).toString(16)),r.push((15&o).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new i.init(n,t/2)}},c=s.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],a=0;a<n;a++){var o=t[a>>>2]>>>24-a%4*8&255;r.push(String.fromCharCode(o))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new i.init(n,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=a.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,a=n.sigBytes,o=this.blockSize,s=a/(4*o),u=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*o,c=e.min(4*u,a);if(u){for(var l=0;l<u;l+=o)this._doProcessBlock(r,l);var p=r.splice(0,u);n.sigBytes-=c}return new i.init(p,c)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),d=(a.Hasher=p.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){p.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new d.HMAC.init(e,n).finalize(t)}}}),r.algo={});return r}(Math)})),O=w((function(e,t){var n,r,a;e.exports=(r=(n=a=R).lib.WordArray,n.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,r=this._map;e.clamp();for(var a=[],o=0;o<n;o+=3)for(var i=(t[o>>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;s<4&&o+.75*s<n;s++)a.push(r.charAt(i>>>6*(3-s)&63));var u=r.charAt(64);if(u)for(;a.length%4;)a.push(u);return a.join("")},parse:function(e){var t=e.length,n=this._map,a=this._reverseMap;if(!a){a=this._reverseMap=[];for(var o=0;o<n.length;o++)a[n.charCodeAt(o)]=o}var i=n.charAt(64);if(i){var s=e.indexOf(i);-1!==s&&(t=s)}return function(e,t,n){for(var a=[],o=0,i=0;i<t;i++)if(i%4){var s=n[e.charCodeAt(i-1)]<<i%4*2,u=n[e.charCodeAt(i)]>>>6-i%4*2;a[o>>>2]|=(s|u)<<24-o%4*8,o++}return r.create(a,o)}(e,t,a)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},a.enc.Base64)})),B=(w((function(e,t){var n;e.exports=(n=R,function(e){var t=n,r=t.lib,a=r.WordArray,o=r.Hasher,i=t.algo,s=[],u=[];!function(){function t(t){for(var n=e.sqrt(t),r=2;r<=n;r++)if(!(t%r))return!1;return!0}function n(e){return 4294967296*(e-(0|e))|0}for(var r=2,a=0;a<64;)t(r)&&(a<8&&(s[a]=n(e.pow(r,.5))),u[a]=n(e.pow(r,1/3)),a++),r++}();var c=[],l=i.SHA256=o.extend({_doReset:function(){this._hash=new a.init(s.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],a=n[1],o=n[2],i=n[3],s=n[4],l=n[5],p=n[6],d=n[7],f=0;f<64;f++){if(f<16)c[f]=0|e[t+f];else{var h=c[f-15],m=(h<<25|h>>>7)^(h<<14|h>>>18)^h>>>3,g=c[f-2],v=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;c[f]=m+c[f-7]+v+c[f-16]}var y=r&a^r&o^a&o,b=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),x=d+((s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25))+(s&l^~s&p)+u[f]+c[f];d=p,p=l,l=s,s=i+x|0,i=o,o=a,a=r,r=x+(b+y)|0}n[0]=n[0]+r|0,n[1]=n[1]+a|0,n[2]=n[2]+o|0,n[3]=n[3]+i|0,n[4]=n[4]+s|0,n[5]=n[5]+l|0,n[6]=n[6]+p|0,n[7]=n[7]+d|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,a=8*t.sigBytes;return n[a>>>5]|=128<<24-a%32,n[14+(a+64>>>9<<4)]=e.floor(r/4294967296),n[15+(a+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=o._createHelper(l),t.HmacSHA256=o._createHmacHelper(l)}(Math),n.SHA256)})),w((function(e,t){var n,r,a;e.exports=(r=(n=R).lib.Base,a=n.enc.Utf8,void(n.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,u=i.words,c=0;c<n;c++)s[c]^=1549556828,u[c]^=909522486;o.sigBytes=i.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,n=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(n))}})))})),w((function(e,t){e.exports=R.HmacSHA256}))),D=function(){function e(e,t){this.accessKey=e,this.keySecret=t}return e.prototype.getHeaders=function(e){var t=function(e){function t(e){return e<10?"0"+e:e}return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+"T"+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+(0===(n=e.getTimezoneOffset())?"Z":(r=n>0?"-":"+",n=Math.abs(n),r+t(Math.floor(n/60))+":"+t(n%60)));var n,r}(new Date);return{Authorization:this.generateAuthorization(e.requestPath,e.method,t),"X-TV-Timestamp":t}},e.prototype.generateAuthorization=function(e,t,n){var r=this.computeStringToSign(e,t,n),a=O.stringify(this.computeSignature(r));return this.formatAuthToken("TV",a)},e.prototype.formatAuthToken=function(e,t){return e+" "+this.accessKey+":"+t},e.prototype.computeStringToSign=function(e,t,n){return t+"\n"+e+"\n"+n},e.prototype.computeSignature=function(e){return B(e,this.keySecret)},e}();function M(e){switch(e){case"testing":return"https://tv-testing.trustingsocial.com/api";case"staging":return"https://tv-staging.trustingsocial.com/api";case"production":return"https://vn-vision.trustingsocial.com/api";default:return e}}function F(e,t,n,r){void 0===n&&(n="production");var a=(void 0===r?{}:r).headers,o=new D(e,t),i=M(n);return new N({authorizer:o,domain:i,headers:a})}var P=function(){function e(e){void 0===e&&(e="production");var t=new N({domain:M(e)});this.imagesService=new c(t),this.detectIDTamperingService=new g(t)}return e.prototype.uploadImage=function(e,t){return this.imagesService.requestWithHeaders(e,t)},e.prototype.detectTampering=function(e,t){return this.detectIDTamperingService.requestWithAuthHeaders(e,t)},e}();function L(e){var t=e.headerIndex;return function(e,n,r){var o=r.value,i=a({},r);return i.value=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return s(this,void 0,void 0,(function(){var n,r,i,s;return u(this,(function(u){switch(u.label){case 0:return this.transactionEnabled?[4,this.transactionManager.begin()]:[3,4];case 1:return n=u.sent(),r=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),a=0;for(t=0;t<n;t++)for(var o=arguments[t],i=0,s=o.length;i<s;i++,a++)r[a]=o[i];return r}(e),(i=a({},r[t]))["X-TV-Transaction"]=n,r[t]=i,[4,o.apply(this,r)];case 2:return s=u.sent(),[4,this.transactionManager.end()];case 3:return u.sent(),[2,s];case 4:return[4,o.apply(this,e)];case 5:return[2,u.sent()]}}))}))},i}}function U(e){return void 0===e&&(e={encryptedField:"data"}),function(t,n,r){var o=r.value,i=a({},r);return i.value=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return s(this,void 0,void 0,(function(){var n,r;return u(this,(function(a){switch(a.label){case 0:return[4,o.apply(this,t)];case 1:return n=a.sent(),this.encryptionEnabled&&"string"==typeof n[e.encryptedField]?(r=this.encryptionService.decrypt(n[e.encryptedField],{transactionID:this.transactionManager.currentTransactionID}),[2,JSON.parse(r)]):[2,n]}}))}))},i}}var V=function(){function e(e){this.httpClient=e,this.transactionID="",this.totalTransactions=0,this.currentTransaction=0}return Object.defineProperty(e.prototype,"currentTransactionID",{get:function(){return this.transactionID},enumerable:!0,configurable:!0}),e.prototype.begin=function(){return s(this,void 0,void 0,(function(){var e,t,n=this;return u(this,(function(r){switch(r.label){case 0:return e=this.totalTransactions++,[4,new Promise((function(t,r){var a=window.performance.now(),o=setInterval((function(){e===n.currentTransaction&&(clearInterval(o),t(!0)),window.performance.now()-a>=3e3&&(clearInterval(o),r(new Error("Transaction timeout")))}),100)}))];case 1:return r.sent(),[4,this.httpClient.post("/v1/transactions",{})];case 2:return t=r.sent().data,this.transactionID=t.id,[2,t.id]}}))}))},e.prototype.end=function(){return s(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return[4,this.httpClient.post("/v1/transactions/"+this.transactionID+"/finish")];case 1:return e=t.sent(),this.transactionID="",this.currentTransaction++,[2,e]}}))}))},e}(),z={options:{usePureJavaScript:!1}},j={},W=j,H={};j.encode=function(e,t,n){if("string"!=typeof t)throw new TypeError('"alphabet" must be a string.');if(void 0!==n&&"number"!=typeof n)throw new TypeError('"maxline" must be a number.');var r="";if(e instanceof Uint8Array){var a=0,o=t.length,i=t.charAt(0),s=[0];for(a=0;a<e.length;++a){for(var u=0,c=e[a];u<s.length;++u)c+=s[u]<<8,s[u]=c%o,c=c/o|0;for(;c>0;)s.push(c%o),c=c/o|0}for(a=0;0===e[a]&&a<e.length-1;++a)r+=i;for(a=s.length-1;a>=0;--a)r+=t[s[a]]}else r=function(e,t){var n=0,r=t.length,a=t.charAt(0),o=[0];for(n=0;n<e.length();++n){for(var i=0,s=e.at(n);i<o.length;++i)s+=o[i]<<8,o[i]=s%r,s=s/r|0;for(;s>0;)o.push(s%r),s=s/r|0}var u="";for(n=0;0===e.at(n)&&n<e.length()-1;++n)u+=a;for(n=o.length-1;n>=0;--n)u+=t[o[n]];return u}(e,t);if(n){var l=new RegExp(".{1,"+n+"}","g");r=r.match(l).join("\r\n")}return r},j.decode=function(e,t){if("string"!=typeof e)throw new TypeError('"input" must be a string.');if("string"!=typeof t)throw new TypeError('"alphabet" must be a string.');var n=H[t];if(!n){n=H[t]=[];for(var r=0;r<t.length;++r)n[t.charCodeAt(r)]=r}e=e.replace(/\s/g,"");var a=t.length,o=t.charAt(0),i=[0];for(r=0;r<e.length;r++){var s=n[e.charCodeAt(r)];if(void 0===s)return;for(var u=0,c=s;u<i.length;++u)c+=i[u]*a,i[u]=255&c,c>>=8;for(;c>0;)i.push(255&c),c>>=8}for(var l=0;e[l]===o&&l<e.length-1;++l)i.push(0);return"undefined"!=typeof Buffer?Buffer.from(i.reverse()):new Uint8Array(i.reverse())},w((function(e){var t=e.exports=z.util=z.util||{};function n(e){if(8!==e&&16!==e&&24!==e&&32!==e)throw new Error("Only 8, 16, 24, or 32 bits supported: "+e)}function r(e){if(this.data="",this.read=0,"string"==typeof e)this.data=e;else if(t.isArrayBuffer(e)||t.isArrayBufferView(e))if("undefined"!=typeof Buffer&&e instanceof Buffer)this.data=e.toString("binary");else{var n=new Uint8Array(e);try{this.data=String.fromCharCode.apply(null,n)}catch(e){for(var a=0;a<n.length;++a)this.putByte(n[a])}}else(e instanceof r||"object"==typeof e&&"string"==typeof e.data&&"number"==typeof e.read)&&(this.data=e.data,this.read=e.read);this._constructedStringLength=0}!function(){if("undefined"!=typeof process&&process.nextTick&&!process.browser)return t.nextTick=process.nextTick,void("function"==typeof setImmediate?t.setImmediate=setImmediate:t.setImmediate=t.nextTick);if("function"==typeof setImmediate)return t.setImmediate=function(){return setImmediate.apply(void 0,arguments)},void(t.nextTick=function(e){return setImmediate(e)});if(t.setImmediate=function(e){setTimeout(e,0)},"undefined"!=typeof window&&"function"==typeof window.postMessage){var e="forge.setImmediate",n=[];t.setImmediate=function(t){n.push(t),1===n.length&&window.postMessage(e,"*")},window.addEventListener("message",(function(t){if(t.source===window&&t.data===e){t.stopPropagation();var r=n.slice();n.length=0,r.forEach((function(e){e()}))}}),!0)}if("undefined"!=typeof MutationObserver){var r=Date.now(),a=!0,o=document.createElement("div");n=[],new MutationObserver((function(){var e=n.slice();n.length=0,e.forEach((function(e){e()}))})).observe(o,{attributes:!0});var i=t.setImmediate;t.setImmediate=function(e){Date.now()-r>15?(r=Date.now(),i(e)):(n.push(e),1===n.length&&o.setAttribute("a",a=!a))}}t.nextTick=t.setImmediate}(),t.isNodejs="undefined"!=typeof process&&process.versions&&process.versions.node,t.globalScope=t.isNodejs?x:"undefined"==typeof self?window:self,t.isArray=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isArrayBuffer=function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer},t.isArrayBufferView=function(e){return e&&t.isArrayBuffer(e.buffer)&&void 0!==e.byteLength},t.ByteBuffer=r,t.ByteStringBuffer=r,t.ByteStringBuffer.prototype._optimizeConstructedString=function(e){this._constructedStringLength+=e,this._constructedStringLength>4096&&(this.data.substr(0,1),this._constructedStringLength=0)},t.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read},t.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0},t.ByteStringBuffer.prototype.putByte=function(e){return this.putBytes(String.fromCharCode(e))},t.ByteStringBuffer.prototype.fillWithByte=function(e,t){e=String.fromCharCode(e);for(var n=this.data;t>0;)1&t&&(n+=e),(t>>>=1)>0&&(e+=e);return this.data=n,this._optimizeConstructedString(t),this},t.ByteStringBuffer.prototype.putBytes=function(e){return this.data+=e,this._optimizeConstructedString(e.length),this},t.ByteStringBuffer.prototype.putString=function(e){return this.putBytes(t.encodeUtf8(e))},t.ByteStringBuffer.prototype.putInt16=function(e){return this.putBytes(String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},t.ByteStringBuffer.prototype.putInt24=function(e){return this.putBytes(String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},t.ByteStringBuffer.prototype.putInt32=function(e){return this.putBytes(String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},t.ByteStringBuffer.prototype.putInt16Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255))},t.ByteStringBuffer.prototype.putInt24Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255))},t.ByteStringBuffer.prototype.putInt32Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>24&255))},t.ByteStringBuffer.prototype.putInt=function(e,t){n(t);var r="";do{t-=8,r+=String.fromCharCode(e>>t&255)}while(t>0);return this.putBytes(r)},t.ByteStringBuffer.prototype.putSignedInt=function(e,t){return e<0&&(e+=2<<t-1),this.putInt(e,t)},t.ByteStringBuffer.prototype.putBuffer=function(e){return this.putBytes(e.getBytes())},t.ByteStringBuffer.prototype.getByte=function(){return this.data.charCodeAt(this.read++)},t.ByteStringBuffer.prototype.getInt16=function(){var e=this.data.charCodeAt(this.read)<<8^this.data.charCodeAt(this.read+1);return this.read+=2,e},t.ByteStringBuffer.prototype.getInt24=function(){var e=this.data.charCodeAt(this.read)<<16^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2);return this.read+=3,e},t.ByteStringBuffer.prototype.getInt32=function(){var e=this.data.charCodeAt(this.read)<<24^this.data.charCodeAt(this.read+1)<<16^this.data.charCodeAt(this.read+2)<<8^this.data.charCodeAt(this.read+3);return this.read+=4,e},t.ByteStringBuffer.prototype.getInt16Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8;return this.read+=2,e},t.ByteStringBuffer.prototype.getInt24Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16;return this.read+=3,e},t.ByteStringBuffer.prototype.getInt32Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16^this.data.charCodeAt(this.read+3)<<24;return this.read+=4,e},t.ByteStringBuffer.prototype.getInt=function(e){n(e);var t=0;do{t=(t<<8)+this.data.charCodeAt(this.read++),e-=8}while(e>0);return t},t.ByteStringBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),n=2<<e-2;return t>=n&&(t-=n<<1),t},t.ByteStringBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t="":(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},t.ByteStringBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},t.ByteStringBuffer.prototype.at=function(e){return this.data.charCodeAt(this.read+e)},t.ByteStringBuffer.prototype.setAt=function(e,t){return this.data=this.data.substr(0,this.read+e)+String.fromCharCode(t)+this.data.substr(this.read+e+1),this},t.ByteStringBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},t.ByteStringBuffer.prototype.copy=function(){var e=t.createBuffer(this.data);return e.read=this.read,e},t.ByteStringBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},t.ByteStringBuffer.prototype.clear=function(){return this.data="",this.read=0,this},t.ByteStringBuffer.prototype.truncate=function(e){var t=Math.max(0,this.length()-e);return this.data=this.data.substr(this.read,t),this.read=0,this},t.ByteStringBuffer.prototype.toHex=function(){for(var e="",t=this.read;t<this.data.length;++t){var n=this.data.charCodeAt(t);n<16&&(e+="0"),e+=n.toString(16)}return e},t.ByteStringBuffer.prototype.toString=function(){return t.decodeUtf8(this.bytes())},t.DataBuffer=function(e,n){n=n||{},this.read=n.readOffset||0,this.growSize=n.growSize||1024;var r=t.isArrayBuffer(e),a=t.isArrayBufferView(e);if(r||a)return this.data=r?new DataView(e):new DataView(e.buffer,e.byteOffset,e.byteLength),void(this.write="writeOffset"in n?n.writeOffset:this.data.byteLength);this.data=new DataView(new ArrayBuffer(0)),this.write=0,null!=e&&this.putBytes(e),"writeOffset"in n&&(this.write=n.writeOffset)},t.DataBuffer.prototype.length=function(){return this.write-this.read},t.DataBuffer.prototype.isEmpty=function(){return this.length()<=0},t.DataBuffer.prototype.accommodate=function(e,t){if(this.length()>=e)return this;t=Math.max(t||this.growSize,e);var n=new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength),r=new Uint8Array(this.length()+t);return r.set(n),this.data=new DataView(r.buffer),this},t.DataBuffer.prototype.putByte=function(e){return this.accommodate(1),this.data.setUint8(this.write++,e),this},t.DataBuffer.prototype.fillWithByte=function(e,t){this.accommodate(t);for(var n=0;n<t;++n)this.data.setUint8(e);return this},t.DataBuffer.prototype.putBytes=function(e,n){if(t.isArrayBufferView(e)){var r=(a=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)).byteLength-a.byteOffset;return this.accommodate(r),new Uint8Array(this.data.buffer,this.write).set(a),this.write+=r,this}if(t.isArrayBuffer(e)){var a=new Uint8Array(e);return this.accommodate(a.byteLength),new Uint8Array(this.data.buffer).set(a,this.write),this.write+=a.byteLength,this}if(e instanceof t.DataBuffer||"object"==typeof e&&"number"==typeof e.read&&"number"==typeof e.write&&t.isArrayBufferView(e.data))return a=new Uint8Array(e.data.byteLength,e.read,e.length()),this.accommodate(a.byteLength),new Uint8Array(e.data.byteLength,this.write).set(a),this.write+=a.byteLength,this;if(e instanceof t.ByteStringBuffer&&(e=e.data,n="binary"),n=n||"binary","string"==typeof e){var o;if("hex"===n)return this.accommodate(Math.ceil(e.length/2)),o=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.hex.decode(e,o,this.write),this;if("base64"===n)return this.accommodate(3*Math.ceil(e.length/4)),o=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.base64.decode(e,o,this.write),this;if("utf8"===n&&(e=t.encodeUtf8(e),n="binary"),"binary"===n||"raw"===n)return this.accommodate(e.length),o=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.raw.decode(o),this;if("utf16"===n)return this.accommodate(2*e.length),o=new Uint16Array(this.data.buffer,this.write),this.write+=t.text.utf16.encode(o),this;throw new Error("Invalid encoding: "+n)}throw Error("Invalid parameter: "+e)},t.DataBuffer.prototype.putBuffer=function(e){return this.putBytes(e),e.clear(),this},t.DataBuffer.prototype.putString=function(e){return this.putBytes(e,"utf16")},t.DataBuffer.prototype.putInt16=function(e){return this.accommodate(2),this.data.setInt16(this.write,e),this.write+=2,this},t.DataBuffer.prototype.putInt24=function(e){return this.accommodate(3),this.data.setInt16(this.write,e>>8&65535),this.data.setInt8(this.write,e>>16&255),this.write+=3,this},t.DataBuffer.prototype.putInt32=function(e){return this.accommodate(4),this.data.setInt32(this.write,e),this.write+=4,this},t.DataBuffer.prototype.putInt16Le=function(e){return this.accommodate(2),this.data.setInt16(this.write,e,!0),this.write+=2,this},t.DataBuffer.prototype.putInt24Le=function(e){return this.accommodate(3),this.data.setInt8(this.write,e>>16&255),this.data.setInt16(this.write,e>>8&65535,!0),this.write+=3,this},t.DataBuffer.prototype.putInt32Le=function(e){return this.accommodate(4),this.data.setInt32(this.write,e,!0),this.write+=4,this},t.DataBuffer.prototype.putInt=function(e,t){n(t),this.accommodate(t/8);do{t-=8,this.data.setInt8(this.write++,e>>t&255)}while(t>0);return this},t.DataBuffer.prototype.putSignedInt=function(e,t){return n(t),this.accommodate(t/8),e<0&&(e+=2<<t-1),this.putInt(e,t)},t.DataBuffer.prototype.getByte=function(){return this.data.getInt8(this.read++)},t.DataBuffer.prototype.getInt16=function(){var e=this.data.getInt16(this.read);return this.read+=2,e},t.DataBuffer.prototype.getInt24=function(){var e=this.data.getInt16(this.read)<<8^this.data.getInt8(this.read+2);return this.read+=3,e},t.DataBuffer.prototype.getInt32=function(){var e=this.data.getInt32(this.read);return this.read+=4,e},t.DataBuffer.prototype.getInt16Le=function(){var e=this.data.getInt16(this.read,!0);return this.read+=2,e},t.DataBuffer.prototype.getInt24Le=function(){var e=this.data.getInt8(this.read)^this.data.getInt16(this.read+1,!0)<<8;return this.read+=3,e},t.DataBuffer.prototype.getInt32Le=function(){var e=this.data.getInt32(this.read,!0);return this.read+=4,e},t.DataBuffer.prototype.getInt=function(e){n(e);var t=0;do{t=(t<<8)+this.data.getInt8(this.read++),e-=8}while(e>0);return t},t.DataBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),n=2<<e-2;return t>=n&&(t-=n<<1),t},t.DataBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t="":(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},t.DataBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},t.DataBuffer.prototype.at=function(e){return this.data.getUint8(this.read+e)},t.DataBuffer.prototype.setAt=function(e,t){return this.data.setUint8(e,t),this},t.DataBuffer.prototype.last=function(){return this.data.getUint8(this.write-1)},t.DataBuffer.prototype.copy=function(){return new t.DataBuffer(this)},t.DataBuffer.prototype.compact=function(){if(this.read>0){var e=new Uint8Array(this.data.buffer,this.read),t=new Uint8Array(e.byteLength);t.set(e),this.data=new DataView(t),this.write-=this.read,this.read=0}return this},t.DataBuffer.prototype.clear=function(){return this.data=new DataView(new ArrayBuffer(0)),this.read=this.write=0,this},t.DataBuffer.prototype.truncate=function(e){return this.write=Math.max(0,this.length()-e),this.read=Math.min(this.read,this.write),this},t.DataBuffer.prototype.toHex=function(){for(var e="",t=this.read;t<this.data.byteLength;++t){var n=this.data.getUint8(t);n<16&&(e+="0"),e+=n.toString(16)}return e},t.DataBuffer.prototype.toString=function(e){var n=new Uint8Array(this.data,this.read,this.length());if("binary"===(e=e||"utf8")||"raw"===e)return t.binary.raw.encode(n);if("hex"===e)return t.binary.hex.encode(n);if("base64"===e)return t.binary.base64.encode(n);if("utf8"===e)return t.text.utf8.decode(n);if("utf16"===e)return t.text.utf16.decode(n);throw new Error("Invalid encoding: "+e)},t.createBuffer=function(e,n){return n=n||"raw",void 0!==e&&"utf8"===n&&(e=t.encodeUtf8(e)),new t.ByteBuffer(e)},t.fillString=function(e,t){for(var n="";t>0;)1&t&&(n+=e),(t>>>=1)>0&&(e+=e);return n},t.xorBytes=function(e,t,n){for(var r="",a="",o="",i=0,s=0;n>0;--n,++i)a=e.charCodeAt(i)^t.charCodeAt(i),s>=10&&(r+=o,o="",s=0),o+=String.fromCharCode(a),++s;return r+o},t.hexToBytes=function(e){var t="",n=0;for(!0&e.length&&(n=1,t+=String.fromCharCode(parseInt(e[0],16)));n<e.length;n+=2)t+=String.fromCharCode(parseInt(e.substr(n,2),16));return t},t.bytesToHex=function(e){return t.createBuffer(e).toHex()},t.int32ToBytes=function(e){return String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e)};var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],i="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";t.encode64=function(e,t){for(var n,r,o,i="",s="",u=0;u<e.length;)n=e.charCodeAt(u++),r=e.charCodeAt(u++),o=e.charCodeAt(u++),i+=a.charAt(n>>2),i+=a.charAt((3&n)<<4|r>>4),isNaN(r)?i+="==":(i+=a.charAt((15&r)<<2|o>>6),i+=isNaN(o)?"=":a.charAt(63&o)),t&&i.length>t&&(s+=i.substr(0,t)+"\r\n",i=i.substr(t));return s+i},t.decode64=function(e){e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var t,n,r,a,i="",s=0;s<e.length;)t=o[e.charCodeAt(s++)-43],n=o[e.charCodeAt(s++)-43],r=o[e.charCodeAt(s++)-43],a=o[e.charCodeAt(s++)-43],i+=String.fromCharCode(t<<2|n>>4),64!==r&&(i+=String.fromCharCode((15&n)<<4|r>>2),64!==a&&(i+=String.fromCharCode((3&r)<<6|a)));return i},t.encodeUtf8=function(e){return unescape(encodeURIComponent(e))},t.decodeUtf8=function(e){return decodeURIComponent(escape(e))},t.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:W.encode,decode:W.decode}},t.binary.raw.encode=function(e){return String.fromCharCode.apply(null,e)},t.binary.raw.decode=function(e,t,n){var r=t;r||(r=new Uint8Array(e.length));for(var a=n=n||0,o=0;o<e.length;++o)r[a++]=e.charCodeAt(o);return t?a-n:r},t.binary.hex.encode=t.bytesToHex,t.binary.hex.decode=function(e,t,n){var r=t;r||(r=new Uint8Array(Math.ceil(e.length/2)));var a=0,o=n=n||0;for(1&e.length&&(a=1,r[o++]=parseInt(e[0],16));a<e.length;a+=2)r[o++]=parseInt(e.substr(a,2),16);return t?o-n:r},t.binary.base64.encode=function(e,t){for(var n,r,o,i="",s="",u=0;u<e.byteLength;)n=e[u++],r=e[u++],o=e[u++],i+=a.charAt(n>>2),i+=a.charAt((3&n)<<4|r>>4),isNaN(r)?i+="==":(i+=a.charAt((15&r)<<2|o>>6),i+=isNaN(o)?"=":a.charAt(63&o)),t&&i.length>t&&(s+=i.substr(0,t)+"\r\n",i=i.substr(t));return s+i},t.binary.base64.decode=function(e,t,n){var r,a,i,s,u=t;u||(u=new Uint8Array(3*Math.ceil(e.length/4))),e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var c=0,l=n=n||0;c<e.length;)r=o[e.charCodeAt(c++)-43],a=o[e.charCodeAt(c++)-43],i=o[e.charCodeAt(c++)-43],s=o[e.charCodeAt(c++)-43],u[l++]=r<<2|a>>4,64!==i&&(u[l++]=(15&a)<<4|i>>2,64!==s&&(u[l++]=(3&i)<<6|s));return t?l-n:u.subarray(0,l)},t.binary.base58.encode=function(e,n){return t.binary.baseN.encode(e,i,n)},t.binary.base58.decode=function(e,n){return t.binary.baseN.decode(e,i,n)},t.text={utf8:{},utf16:{}},t.text.utf8.encode=function(e,n,r){e=t.encodeUtf8(e);var a=n;a||(a=new Uint8Array(e.length));for(var o=r=r||0,i=0;i<e.length;++i)a[o++]=e.charCodeAt(i);return n?o-r:a},t.text.utf8.decode=function(e){return t.decodeUtf8(String.fromCharCode.apply(null,e))},t.text.utf16.encode=function(e,t,n){var r=t;r||(r=new Uint8Array(2*e.length));for(var a=new Uint16Array(r.buffer),o=n=n||0,i=n,s=0;s<e.length;++s)a[i++]=e.charCodeAt(s),o+=2;return t?o-n:r},t.text.utf16.decode=function(e){return String.fromCharCode.apply(null,new Uint16Array(e.buffer))},t.deflate=function(e,n,r){if(n=t.decode64(e.deflate(t.encode64(n)).rval),r){var a=2;32&n.charCodeAt(1)&&(a=6),n=n.substring(a,n.length-4)}return n},t.inflate=function(e,n,r){var a=e.inflate(t.encode64(n)).rval;return null===a?null:t.decode64(a)};var s=function(e,n,r){if(!e)throw new Error("WebStorage not available.");var a;if(null===r?a=e.removeItem(n):(r=t.encode64(JSON.stringify(r)),a=e.setItem(n,r)),void 0!==a&&!0!==a.rval){var o=new Error(a.error.message);throw o.id=a.error.id,o.name=a.error.name,o}},u=function(e,n){if(!e)throw new Error("WebStorage not available.");var r=e.getItem(n);if(e.init)if(null===r.rval){if(r.error){var a=new Error(r.error.message);throw a.id=r.error.id,a.name=r.error.name,a}r=null}else r=r.rval;return null!==r&&(r=JSON.parse(t.decode64(r))),r},c=function(e,t,n,r){var a=u(e,t);null===a&&(a={}),a[n]=r,s(e,t,a)},l=function(e,t,n){var r=u(e,t);return null!==r&&(r=n in r?r[n]:null),r},p=function(e,t,n){var r=u(e,t);if(null!==r&&n in r){delete r[n];var a=!0;for(var o in r){a=!1;break}a&&(r=null),s(e,t,r)}},d=function(e,t){s(e,t,null)},f=function(e,t,n){var r,a=null;void 0===n&&(n=["web","flash"]);var o=!1,i=null;for(var s in n){r=n[s];try{if("flash"===r||"both"===r){if(null===t[0])throw new Error("Flash local storage not available.");a=e.apply(this,t),o="flash"===r}"web"!==r&&"both"!==r||(t[0]=localStorage,a=e.apply(this,t),o=!0)}catch(e){i=e}if(o)break}if(!o)throw i;return a};t.setItem=function(e,t,n,r,a){f(c,arguments,a)},t.getItem=function(e,t,n,r){return f(l,arguments,r)},t.removeItem=function(e,t,n,r){f(p,arguments,r)},t.clearItems=function(e,t,n){f(d,arguments,n)},t.parseUrl=function(e){var t=/^(https?):\/\/([^:&^\/]*):?(\d*)(.*)$/g;t.lastIndex=0;var n=t.exec(e),r=null===n?null:{full:e,scheme:n[1],host:n[2],port:n[3],path:n[4]};return r&&(r.fullHost=r.host,r.port?(80!==r.port&&"http"===r.scheme||443!==r.port&&"https"===r.scheme)&&(r.fullHost+=":"+r.port):"http"===r.scheme?r.port=80:"https"===r.scheme&&(r.port=443),r.full=r.scheme+"://"+r.fullHost),r};var h=null;t.getQueryVariables=function(e){var t,n=function(e){for(var t={},n=e.split("&"),r=0;r<n.length;r++){var a,o,i=n[r].indexOf("=");i>0?(a=n[r].substring(0,i),o=n[r].substring(i+1)):(a=n[r],o=null),a in t||(t[a]=[]),a in Object.prototype||null===o||t[a].push(unescape(o))}return t};return void 0===e?(null===h&&(h="undefined"!=typeof window&&window.location&&window.location.search?n(window.location.search.substring(1)):{}),t=h):t=n(e),t},t.parseFragment=function(e){var n=e,r="",a=e.indexOf("?");a>0&&(n=e.substring(0,a),r=e.substring(a+1));var o=n.split("/");return o.length>0&&""===o[0]&&o.shift(),{pathString:n,queryString:r,path:o,query:""===r?{}:t.getQueryVariables(r)}},t.makeRequest=function(e){var n=t.parseFragment(e),r={path:n.pathString,query:n.queryString,getPath:function(e){return void 0===e?n.path:n.path[e]},getQuery:function(e,t){var r;return void 0===e?r=n.query:(r=n.query[e])&&void 0!==t&&(r=r[t]),r},getQueryLast:function(e,t){var n=r.getQuery(e);return n?n[n.length-1]:t}};return r},t.makeLink=function(e,t,n){e=jQuery.isArray(e)?e.join("/"):e;var r=jQuery.param(t||{});return n=n||"",e+(r.length>0?"?"+r:"")+(n.length>0?"#"+n:"")},t.setPath=function(e,t,n){if("object"==typeof e&&null!==e)for(var r=0,a=t.length;r<a;){var o=t[r++];if(r==a)e[o]=n;else{var i=o in e;(!i||i&&"object"!=typeof e[o]||i&&null===e[o])&&(e[o]={}),e=e[o]}}},t.getPath=function(e,t,n){for(var r=0,a=t.length,o=!0;o&&r<a&&"object"==typeof e&&null!==e;){var i=t[r++];(o=i in e)&&(e=e[i])}return o?e:n},t.deletePath=function(e,t){if("object"==typeof e&&null!==e)for(var n=0,r=t.length;n<r;){var a=t[n++];if(n==r)delete e[a];else{if(!(a in e)||"object"!=typeof e[a]||null===e[a])break;e=e[a]}}},t.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},t.format=function(e){for(var t,n,r=/%./g,a=0,o=[],i=0;t=r.exec(e);){(n=e.substring(i,r.lastIndex-2)).length>0&&o.push(n),i=r.lastIndex;var s=t[0][1];switch(s){case"s":case"o":a<arguments.length?o.push(arguments[1+a++]):o.push("<?>");break;case"%":o.push("%");break;default:o.push("<%"+s+"?>")}}return o.push(e.substring(i)),o.join("")},t.formatNumber=function(e,t,n,r){var a=e,o=isNaN(t=Math.abs(t))?2:t,i=void 0===n?",":n,s=void 0===r?".":r,u=a<0?"-":"",c=parseInt(a=Math.abs(+a||0).toFixed(o),10)+"",l=c.length>3?c.length%3:0;return u+(l?c.substr(0,l)+s:"")+c.substr(l).replace(/(\d{3})(?=\d)/g,"$1"+s)+(o?i+Math.abs(a-c).toFixed(o).slice(2):"")},t.formatSize=function(e){return e>=1073741824?t.formatNumber(e/1073741824,2,".","")+" GiB":e>=1048576?t.formatNumber(e/1048576,2,".","")+" MiB":e>=1024?t.formatNumber(e/1024,0)+" KiB":t.formatNumber(e,0)+" bytes"},t.bytesFromIP=function(e){return-1!==e.indexOf(".")?t.bytesFromIPv4(e):-1!==e.indexOf(":")?t.bytesFromIPv6(e):null},t.bytesFromIPv4=function(e){if(4!==(e=e.split(".")).length)return null;for(var n=t.createBuffer(),r=0;r<e.length;++r){var a=parseInt(e[r],10);if(isNaN(a))return null;n.putByte(a)}return n.getBytes()},t.bytesFromIPv6=function(e){for(var n=0,r=2*(8-(e=e.split(":").filter((function(e){return 0===e.length&&++n,!0}))).length+n),a=t.createBuffer(),o=0;o<8;++o)if(e[o]&&0!==e[o].length){var i=t.hexToBytes(e[o]);i.length<2&&a.putByte(0),a.putBytes(i)}else a.fillWithByte(0,r),r=0;return a.getBytes()},t.bytesToIP=function(e){return 4===e.length?t.bytesToIPv4(e):16===e.length?t.bytesToIPv6(e):null},t.bytesToIPv4=function(e){if(4!==e.length)return null;for(var t=[],n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t.join(".")},t.bytesToIPv6=function(e){if(16!==e.length)return null;for(var n=[],r=[],a=0,o=0;o<e.length;o+=2){for(var i=t.bytesToHex(e[o]+e[o+1]);"0"===i[0]&&"0"!==i;)i=i.substr(1);if("0"===i){var s=r[r.length-1],u=n.length;s&&u===s.end+1?(s.end=u,s.end-s.start>r[a].end-r[a].start&&(a=r.length-1)):r.push({start:u,end:u})}n.push(i)}if(r.length>0){var c=r[a];c.end-c.start>0&&(n.splice(c.start,c.end-c.start+1,""),0===c.start&&n.unshift(""),7===c.end&&n.push(""))}return n.join(":")},t.estimateCores=function(e,n){if("function"==typeof e&&(n=e,e={}),e=e||{},"cores"in t&&!e.update)return n(null,t.cores);if("undefined"!=typeof navigator&&"hardwareConcurrency"in navigator&&navigator.hardwareConcurrency>0)return t.cores=navigator.hardwareConcurrency,n(null,t.cores);if("undefined"==typeof Worker)return t.cores=1,n(null,t.cores);if("undefined"==typeof Blob)return t.cores=2,n(null,t.cores);var r=URL.createObjectURL(new Blob(["(",function(){self.addEventListener("message",(function(e){var t=Date.now(),n=t+4;self.postMessage({st:t,et:n})}))}.toString(),")()"],{type:"application/javascript"}));!function e(a,o,i){if(0===o){var s=Math.floor(a.reduce((function(e,t){return e+t}),0)/a.length);return t.cores=Math.max(1,s),URL.revokeObjectURL(r),n(null,t.cores)}!function(e,t){for(var n=[],a=[],o=0;o<e;++o){var i=new Worker(r);i.addEventListener("message",(function(r){if(a.push(r.data),a.length===e){for(var o=0;o<e;++o)n[o].terminate();t(null,a)}})),n.push(i)}for(o=0;o<e;++o)n[o].postMessage(o)}(i,(function(t,n){a.push(function(e,t){for(var n=[],r=0;r<e;++r)for(var a=t[r],o=n[r]=[],i=0;i<e;++i)if(r!==i){var s=t[i];(a.st>s.st&&a.st<s.et||s.st>a.st&&s.st<a.et)&&o.push(i)}return n.reduce((function(e,t){return Math.max(e,t.length)}),0)}(i,n)),e(a,o-1,i)}))}([],5,16)}})),z.cipher=z.cipher||{},z.cipher.algorithms=z.cipher.algorithms||{},z.cipher.createCipher=function(e,t){var n=e;if("string"==typeof n&&(n=z.cipher.getAlgorithm(n))&&(n=n()),!n)throw new Error("Unsupported algorithm: "+e);return new z.cipher.BlockCipher({algorithm:n,key:t,decrypt:!1})},z.cipher.createDecipher=function(e,t){var n=e;if("string"==typeof n&&(n=z.cipher.getAlgorithm(n))&&(n=n()),!n)throw new Error("Unsupported algorithm: "+e);return new z.cipher.BlockCipher({algorithm:n,key:t,decrypt:!0})},z.cipher.registerAlgorithm=function(e,t){e=e.toUpperCase(),z.cipher.algorithms[e]=t},z.cipher.getAlgorithm=function(e){return(e=e.toUpperCase())in z.cipher.algorithms?z.cipher.algorithms[e]:null};var G=z.cipher.BlockCipher=function(e){this.algorithm=e.algorithm,this.mode=this.algorithm.mode,this.blockSize=this.mode.blockSize,this._finish=!1,this._input=null,this.output=null,this._op=e.decrypt?this.mode.decrypt:this.mode.encrypt,this._decrypt=e.decrypt,this.algorithm.initialize(e)};function K(e,t){z.cipher.registerAlgorithm(e,(function(){return new z.aes.Algorithm(e,t)}))}G.prototype.start=function(e){e=e||{};var t={};for(var n in e)t[n]=e[n];t.decrypt=this._decrypt,this._finish=!1,this._input=z.util.createBuffer(),this.output=e.output||z.util.createBuffer(),this.mode.start(t)},G.prototype.update=function(e){for(e&&this._input.putBuffer(e);!this._op.call(this.mode,this._input,this.output,this._finish)&&!this._finish;);this._input.compact()},G.prototype.finish=function(e){!e||"ECB"!==this.mode.name&&"CBC"!==this.mode.name||(this.mode.pad=function(t){return e(this.blockSize,t,!1)},this.mode.unpad=function(t){return e(this.blockSize,t,!0)});var t={};return t.decrypt=this._decrypt,t.overflow=this._input.length()%this.blockSize,!(!this._decrypt&&this.mode.pad&&!this.mode.pad(this._input,t)||(this._finish=!0,this.update(),this._decrypt&&this.mode.unpad&&!this.mode.unpad(this.output,t)||this.mode.afterFinish&&!this.mode.afterFinish(this.output,t)))},w((function(e){z.cipher=z.cipher||{};var t=e.exports=z.cipher.modes=z.cipher.modes||{};function n(e,t){if("string"==typeof e&&(e=z.util.createBuffer(e)),z.util.isArray(e)&&e.length>4){var n=e;e=z.util.createBuffer();for(var r=0;r<n.length;++r)e.putByte(n[r])}if(e.length()<t)throw new Error("Invalid IV length; got "+e.length()+" bytes and expected "+t+" bytes.");if(!z.util.isArray(e)){var a=[],o=t/4;for(r=0;r<o;++r)a.push(e.getInt32());e=a}return e}function r(e){e[e.length-1]=e[e.length-1]+1&4294967295}function a(e){return[e/4294967296|0,4294967295&e]}t.ecb=function(e){e=e||{},this.name="ECB",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},t.ecb.prototype.start=function(e){},t.ecb.prototype.encrypt=function(e,t,n){if(e.length()<this.blockSize&&!(n&&e.length()>0))return!0;for(var r=0;r<this._ints;++r)this._inBlock[r]=e.getInt32();for(this.cipher.encrypt(this._inBlock,this._outBlock),r=0;r<this._ints;++r)t.putInt32(this._outBlock[r])},t.ecb.prototype.decrypt=function(e,t,n){if(e.length()<this.blockSize&&!(n&&e.length()>0))return!0;for(var r=0;r<this._ints;++r)this._inBlock[r]=e.getInt32();for(this.cipher.decrypt(this._inBlock,this._outBlock),r=0;r<this._ints;++r)t.putInt32(this._outBlock[r])},t.ecb.prototype.pad=function(e,t){var n=e.length()===this.blockSize?this.blockSize:this.blockSize-e.length();return e.fillWithByte(n,n),!0},t.ecb.prototype.unpad=function(e,t){if(t.overflow>0)return!1;var n=e.length(),r=e.at(n-1);return!(r>this.blockSize<<2||(e.truncate(r),0))},t.cbc=function(e){e=e||{},this.name="CBC",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},t.cbc.prototype.start=function(e){if(null===e.iv){if(!this._prev)throw new Error("Invalid IV parameter.");this._iv=this._prev.slice(0)}else{if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=n(e.iv,this.blockSize),this._prev=this._iv.slice(0)}},t.cbc.prototype.encrypt=function(e,t,n){if(e.length()<this.blockSize&&!(n&&e.length()>0))return!0;for(var r=0;r<this._ints;++r)this._inBlock[r]=this._prev[r]^e.getInt32();for(this.cipher.encrypt(this._inBlock,this._outBlock),r=0;r<this._ints;++r)t.putInt32(this._outBlock[r]);this._prev=this._outBlock},t.cbc.prototype.decrypt=function(e,t,n){if(e.length()<this.blockSize&&!(n&&e.length()>0))return!0;for(var r=0;r<this._ints;++r)this._inBlock[r]=e.getInt32();for(this.cipher.decrypt(this._inBlock,this._outBlock),r=0;r<this._ints;++r)t.putInt32(this._prev[r]^this._outBlock[r]);this._prev=this._inBlock.slice(0)},t.cbc.prototype.pad=function(e,t){var n=e.length()===this.blockSize?this.blockSize:this.blockSize-e.length();return e.fillWithByte(n,n),!0},t.cbc.prototype.unpad=function(e,t){if(t.overflow>0)return!1;var n=e.length(),r=e.at(n-1);return!(r>this.blockSize<<2||(e.truncate(r),0))},t.cfb=function(e){e=e||{},this.name="CFB",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialBlock=new Array(this._ints),this._partialOutput=z.util.createBuffer(),this._partialBytes=0},t.cfb.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=n(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},t.cfb.prototype.encrypt=function(e,t,n){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var a=0;a<this._ints;++a)this._inBlock[a]=e.getInt32()^this._outBlock[a],t.putInt32(this._inBlock[a]);else{var o=(this.blockSize-r)%this.blockSize;for(o>0&&(o=this.blockSize-o),this._partialOutput.clear(),a=0;a<this._ints;++a)this._partialBlock[a]=e.getInt32()^this._outBlock[a],this._partialOutput.putInt32(this._partialBlock[a]);if(o>0)e.read-=this.blockSize;else for(a=0;a<this._ints;++a)this._inBlock[a]=this._partialBlock[a];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!n)return t.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},t.cfb.prototype.decrypt=function(e,t,n){var r=e.length();if(0===r)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var a=0;a<this._ints;++a)this._inBlock[a]=e.getInt32(),t.putInt32(this._inBlock[a]^this._outBlock[a]);else{var o=(this.blockSize-r)%this.blockSize;for(o>0&&(o=this.blockSize-o),this._partialOutput.clear(),a=0;a<this._ints;++a)this._partialBlock[a]=e.getInt32(),this._partialOutput.putInt32(this._partialBlock[a]^this._outBlock[a]);if(o>0)e.read-=this.blockSize;else for(a=0;a<this._ints;++a)this._inBlock[a]=this._partialBlock[a];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!n)return t.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},t.ofb=function(e){e=e||{},this.name="OFB",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=z.util.createBuffer(),this._partialBytes=0},t.ofb.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=n(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},t.ofb.prototype.encrypt=function(e,t,n){var r=e.length();if(0===e.length())return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&r>=this.blockSize)for(var a=0;a<this._ints;++a)t.putInt32(e.getInt32()^this._outBlock[a]),this._inBlock[a]=this._outBlock[a];else{var o=(this.blockSize-r)%this.blockSize;for(o>0&&(o=this.blockSize-o),this._partialOutput.clear(),a=0;a<this._ints;++a)this._partialOutput.putInt32(e.getInt32()^this._outBlock[a]);if(o>0)e.read-=this.blockSize;else for(a=0;a<this._ints;++a)this._inBlock[a]=this._outBlock[a];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!n)return t.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;t.putBytes(this._partialOutput.getBytes(r-this._partialBytes)),this._partialBytes=0}},t.ofb.prototype.decrypt=t.ofb.prototype.encrypt,t.ctr=function(e){e=e||{},this.name="CTR",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=z.util.createBuffer(),this._partialBytes=0},t.ctr.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=n(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},t.ctr.prototype.encrypt=function(e,t,n){var a=e.length();if(0===a)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&a>=this.blockSize)for(var o=0;o<this._ints;++o)t.putInt32(e.getInt32()^this._outBlock[o]);else{var i=(this.blockSize-a)%this.blockSize;for(i>0&&(i=this.blockSize-i),this._partialOutput.clear(),o=0;o<this._ints;++o)this._partialOutput.putInt32(e.getInt32()^this._outBlock[o]);if(i>0&&(e.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!n)return t.putBytes(this._partialOutput.getBytes(i-this._partialBytes)),this._partialBytes=i,!0;t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=0}r(this._inBlock)},t.ctr.prototype.decrypt=t.ctr.prototype.encrypt,t.gcm=function(e){e=e||{},this.name="GCM",this.cipher=e.cipher,this.blockSize=e.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints),this._partialOutput=z.util.createBuffer(),this._partialBytes=0,this._R=3774873600},t.gcm.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");var t,n=z.util.createBuffer(e.iv);if(this._cipherLength=0,t="additionalData"in e?z.util.createBuffer(e.additionalData):z.util.createBuffer(),this._tagLength="tagLength"in e?e.tagLength:128,this._tag=null,e.decrypt&&(this._tag=z.util.createBuffer(e.tag).getBytes(),this._tag.length!==this._tagLength/8))throw new Error("Authentication tag does not match tag length.");this._hashBlock=new Array(this._ints),this.tag=null,this._hashSubkey=new Array(this._ints),this.cipher.encrypt([0,0,0,0],this._hashSubkey),this.componentBits=4,this._m=this.generateHashTable(this._hashSubkey,this.componentBits);var o=n.length();if(12===o)this._j0=[n.getInt32(),n.getInt32(),n.getInt32(),1];else{for(this._j0=[0,0,0,0];n.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[n.getInt32(),n.getInt32(),n.getInt32(),n.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(a(8*o)))}this._inBlock=this._j0.slice(0),r(this._inBlock),this._partialBytes=0,t=z.util.createBuffer(t),this._aDataLength=a(8*t.length());var i=t.length()%this.blockSize;for(i&&t.fillWithByte(0,this.blockSize-i),this._s=[0,0,0,0];t.length()>0;)this._s=this.ghash(this._hashSubkey,this._s,[t.getInt32(),t.getInt32(),t.getInt32(),t.getInt32()])},t.gcm.prototype.encrypt=function(e,t,n){var a=e.length();if(0===a)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&a>=this.blockSize){for(var o=0;o<this._ints;++o)t.putInt32(this._outBlock[o]^=e.getInt32());this._cipherLength+=this.blockSize}else{var i=(this.blockSize-a)%this.blockSize;for(i>0&&(i=this.blockSize-i),this._partialOutput.clear(),o=0;o<this._ints;++o)this._partialOutput.putInt32(e.getInt32()^this._outBlock[o]);if(i<=0||n){if(n){var s=a%this.blockSize;this._cipherLength+=s,this._partialOutput.truncate(this.blockSize-s)}else this._cipherLength+=this.blockSize;for(o=0;o<this._ints;++o)this._outBlock[o]=this._partialOutput.getInt32();this._partialOutput.read-=this.blockSize}if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!n)return e.read-=this.blockSize,t.putBytes(this._partialOutput.getBytes(i-this._partialBytes)),this._partialBytes=i,!0;t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=0}this._s=this.ghash(this._hashSubkey,this._s,this._outBlock),r(this._inBlock)},t.gcm.prototype.decrypt=function(e,t,n){var a=e.length();if(a<this.blockSize&&!(n&&a>0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),r(this._inBlock),this._hashBlock[0]=e.getInt32(),this._hashBlock[1]=e.getInt32(),this._hashBlock[2]=e.getInt32(),this._hashBlock[3]=e.getInt32(),this._s=this.ghash(this._hashSubkey,this._s,this._hashBlock);for(var o=0;o<this._ints;++o)t.putInt32(this._outBlock[o]^this._hashBlock[o]);a<this.blockSize?this._cipherLength+=a%this.blockSize:this._cipherLength+=this.blockSize},t.gcm.prototype.afterFinish=function(e,t){var n=!0;t.decrypt&&t.overflow&&e.truncate(this.blockSize-t.overflow),this.tag=z.util.createBuffer();var r=this._aDataLength.concat(a(8*this._cipherLength));this._s=this.ghash(this._hashSubkey,this._s,r);var o=[];this.cipher.encrypt(this._j0,o);for(var i=0;i<this._ints;++i)this.tag.putInt32(this._s[i]^o[i]);return this.tag.truncate(this.tag.length()%(this._tagLength/8)),t.decrypt&&this.tag.bytes()!==this._tag&&(n=!1),n},t.gcm.prototype.multiply=function(e,t){for(var n=[0,0,0,0],r=t.slice(0),a=0;a<128;++a)e[a/32|0]&1<<31-a%32&&(n[0]^=r[0],n[1]^=r[1],n[2]^=r[2],n[3]^=r[3]),this.pow(r,r);return n},t.gcm.prototype.pow=function(e,t){for(var n=1&e[3],r=3;r>0;--r)t[r]=e[r]>>>1|(1&e[r-1])<<31;t[0]=e[0]>>>1,n&&(t[0]^=this._R)},t.gcm.prototype.tableMultiply=function(e){for(var t=[0,0,0,0],n=0;n<32;++n){var r=e[n/8|0]>>>4*(7-n%8)&15,a=this._m[n][r];t[0]^=a[0],t[1]^=a[1],t[2]^=a[2],t[3]^=a[3]}return t},t.gcm.prototype.ghash=function(e,t,n){return t[0]^=n[0],t[1]^=n[1],t[2]^=n[2],t[3]^=n[3],this.tableMultiply(t)},t.gcm.prototype.generateHashTable=function(e,t){for(var n=8/t,r=4*n,a=16*n,o=new Array(a),i=0;i<a;++i){var s=[0,0,0,0],u=(r-1-i%r)*t;s[i/r|0]=1<<t-1<<u,o[i]=this.generateSubHashTable(this.multiply(s,e),t)}return o},t.gcm.prototype.generateSubHashTable=function(e,t){var n=1<<t,r=n>>>1,a=new Array(n);a[r]=e.slice(0);for(var o=r>>>1;o>0;)this.pow(a[2*o],a[o]=[]),o>>=1;for(o=2;o<r;){for(var i=1;i<o;++i){var s=a[o],u=a[i];a[o+i]=[s[0]^u[0],s[1]^u[1],s[2]^u[2],s[3]^u[3]]}o*=2}for(a[0]=[0,0,0,0],o=r+1;o<n;++o){var c=a[o^r];a[o]=[e[0]^c[0],e[1]^c[1],e[2]^c[2],e[3]^c[3]]}return a}})),z.aes=z.aes||{},z.aes.startEncrypting=function(e,t,n,r){var a=re({key:e,output:n,decrypt:!1,mode:r});return a.start(t),a},z.aes.createEncryptionCipher=function(e,t){return re({key:e,output:null,decrypt:!1,mode:t})},z.aes.startDecrypting=function(e,t,n,r){var a=re({key:e,output:n,decrypt:!0,mode:r});return a.start(t),a},z.aes.createDecryptionCipher=function(e,t){return re({key:e,output:null,decrypt:!0,mode:t})},z.aes.Algorithm=function(e,t){Z||ee();var n=this;n.name=e,n.mode=new t({blockSize:16,cipher:{encrypt:function(e,t){return ne(n._w,e,t,!1)},decrypt:function(e,t){return ne(n._w,e,t,!0)}}}),n._init=!1},z.aes.Algorithm.prototype.initialize=function(e){if(!this._init){var t,n=e.key;if("string"!=typeof n||16!==n.length&&24!==n.length&&32!==n.length){if(z.util.isArray(n)&&(16===n.length||24===n.length||32===n.length)){t=n,n=z.util.createBuffer();for(var r=0;r<t.length;++r)n.putByte(t[r])}}else n=z.util.createBuffer(n);if(!z.util.isArray(n)){t=n,n=[];var a=t.length();if(16===a||24===a||32===a)for(a>>>=2,r=0;r<a;++r)n.push(t.getInt32())}if(!z.util.isArray(n)||4!==n.length&&6!==n.length&&8!==n.length)throw new Error("Invalid key parameter.");var o=this.mode.name,i=-1!==["CFB","OFB","CTR","GCM"].indexOf(o);this._w=te(n,e.decrypt&&!i),this._init=!0}},z.aes._expandKey=function(e,t){return Z||ee(),te(e,t)},z.aes._updateBlock=ne,K("AES-ECB",z.cipher.modes.ecb),K("AES-CBC",z.cipher.modes.cbc),K("AES-CFB",z.cipher.modes.cfb),K("AES-OFB",z.cipher.modes.ofb),K("AES-CTR",z.cipher.modes.ctr),K("AES-GCM",z.cipher.modes.gcm);var q,Q,X,Y,$,Z=!1,J=4;function ee(){Z=!0,X=[0,1,2,4,8,16,32,64,128,27,54];for(var e=new Array(256),t=0;t<128;++t)e[t]=t<<1,e[t+128]=t+128<<1^283;for(q=new Array(256),Q=new Array(256),Y=new Array(4),$=new Array(4),t=0;t<4;++t)Y[t]=new Array(256),$[t]=new Array(256);var n,r,a,o,i,s,u,c=0,l=0;for(t=0;t<256;++t){o=(o=l^l<<1^l<<2^l<<3^l<<4)>>8^255&o^99,q[c]=o,Q[o]=c,s=(i=e[o])<<24^o<<16^o<<8^o^i,u=((n=e[c])^(r=e[n])^(a=e[r]))<<24^(c^a)<<16^(c^r^a)<<8^c^n^a;for(var p=0;p<4;++p)Y[p][c]=s,$[p][o]=u,s=s<<24|s>>>8,u=u<<24|u>>>8;0===c?c=l=1:(c=n^e[e[e[n^a]]],l^=e[e[l]])}}function te(e,t){for(var n,r=e.slice(0),a=1,o=r.length,i=J*(o+6+1),s=o;s<i;++s)n=r[s-1],s%o==0?(n=q[n>>>16&255]<<24^q[n>>>8&255]<<16^q[255&n]<<8^q[n>>>24]^X[a]<<24,a++):o>6&&s%o==4&&(n=q[n>>>24]<<24^q[n>>>16&255]<<16^q[n>>>8&255]<<8^q[255&n]),r[s]=r[s-o]^n;if(t){for(var u,c=$[0],l=$[1],p=$[2],d=$[3],f=r.slice(0),h=(s=0,(i=r.length)-J);s<i;s+=J,h-=J)if(0===s||s===i-J)f[s]=r[h],f[s+1]=r[h+3],f[s+2]=r[h+2],f[s+3]=r[h+1];else for(var m=0;m<J;++m)u=r[h+m],f[s+(3&-m)]=c[q[u>>>24]]^l[q[u>>>16&255]]^p[q[u>>>8&255]]^d[q[255&u]];r=f}return r}function ne(e,t,n,r){var a,o,i,s,u,c,l,p,d,f,h,m,g=e.length/4-1;r?(a=$[0],o=$[1],i=$[2],s=$[3],u=Q):(a=Y[0],o=Y[1],i=Y[2],s=Y[3],u=q),c=t[0]^e[0],l=t[r?3:1]^e[1],p=t[2]^e[2],d=t[r?1:3]^e[3];for(var v=3,y=1;y<g;++y)f=a[c>>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&d]^e[++v],h=a[l>>>24]^o[p>>>16&255]^i[d>>>8&255]^s[255&c]^e[++v],m=a[p>>>24]^o[d>>>16&255]^i[c>>>8&255]^s[255&l]^e[++v],d=a[d>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^e[++v],c=f,l=h,p=m;n[0]=u[c>>>24]<<24^u[l>>>16&255]<<16^u[p>>>8&255]<<8^u[255&d]^e[++v],n[r?3:1]=u[l>>>24]<<24^u[p>>>16&255]<<16^u[d>>>8&255]<<8^u[255&c]^e[++v],n[2]=u[p>>>24]<<24^u[d>>>16&255]<<16^u[c>>>8&255]<<8^u[255&l]^e[++v],n[r?1:3]=u[d>>>24]<<24^u[c>>>16&255]<<16^u[l>>>8&255]<<8^u[255&p]^e[++v]}function re(e){var t,n="AES-"+((e=e||{}).mode||"CBC").toUpperCase(),r=(t=e.decrypt?z.cipher.createDecipher(n,e.key):z.cipher.createCipher(n,e.key)).start;return t.start=function(e,n){var a=null;n instanceof z.util.ByteBuffer&&(a=n,n={}),(n=n||{}).output=a,n.iv=e,r.call(t,n)},t}function ae(e,t){z.cipher.registerAlgorithm(e,(function(){return new z.des.Algorithm(e,t)}))}w((function(e){z.pki=z.pki||{};var t=e.exports=z.pki.oids=z.oids=z.oids||{};function n(e,n){t[e]=n,t[n]=e}function r(e,n){t[e]=n}n("1.2.840.113549.1.1.1","rsaEncryption"),n("1.2.840.113549.1.1.4","md5WithRSAEncryption"),n("1.2.840.113549.1.1.5","sha1WithRSAEncryption"),n("1.2.840.113549.1.1.7","RSAES-OAEP"),n("1.2.840.113549.1.1.8","mgf1"),n("1.2.840.113549.1.1.9","pSpecified"),n("1.2.840.113549.1.1.10","RSASSA-PSS"),n("1.2.840.113549.1.1.11","sha256WithRSAEncryption"),n("1.2.840.113549.1.1.12","sha384WithRSAEncryption"),n("1.2.840.113549.1.1.13","sha512WithRSAEncryption"),n("1.3.101.112","EdDSA25519"),n("1.2.840.10040.4.3","dsa-with-sha1"),n("1.3.14.3.2.7","desCBC"),n("1.3.14.3.2.26","sha1"),n("2.16.840.1.101.3.4.2.1","sha256"),n("2.16.840.1.101.3.4.2.2","sha384"),n("2.16.840.1.101.3.4.2.3","sha512"),n("1.2.840.113549.2.5","md5"),n("1.2.840.113549.1.7.1","data"),n("1.2.840.113549.1.7.2","signedData"),n("1.2.840.113549.1.7.3","envelopedData"),n("1.2.840.113549.1.7.4","signedAndEnvelopedData"),n("1.2.840.113549.1.7.5","digestedData"),n("1.2.840.113549.1.7.6","encryptedData"),n("1.2.840.113549.1.9.1","emailAddress"),n("1.2.840.113549.1.9.2","unstructuredName"),n("1.2.840.113549.1.9.3","contentType"),n("1.2.840.113549.1.9.4","messageDigest"),n("1.2.840.113549.1.9.5","signingTime"),n("1.2.840.113549.1.9.6","counterSignature"),n("1.2.840.113549.1.9.7","challengePassword"),n("1.2.840.113549.1.9.8","unstructuredAddress"),n("1.2.840.113549.1.9.14","extensionRequest"),n("1.2.840.113549.1.9.20","friendlyName"),n("1.2.840.113549.1.9.21","localKeyId"),n("1.2.840.113549.1.9.22.1","x509Certificate"),n("1.2.840.113549.1.12.10.1.1","keyBag"),n("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag"),n("1.2.840.113549.1.12.10.1.3","certBag"),n("1.2.840.113549.1.12.10.1.4","crlBag"),n("1.2.840.113549.1.12.10.1.5","secretBag"),n("1.2.840.113549.1.12.10.1.6","safeContentsBag"),n("1.2.840.113549.1.5.13","pkcs5PBES2"),n("1.2.840.113549.1.5.12","pkcs5PBKDF2"),n("1.2.840.113549.1.12.1.1","pbeWithSHAAnd128BitRC4"),n("1.2.840.113549.1.12.1.2","pbeWithSHAAnd40BitRC4"),n("1.2.840.113549.1.12.1.3","pbeWithSHAAnd3-KeyTripleDES-CBC"),n("1.2.840.113549.1.12.1.4","pbeWithSHAAnd2-KeyTripleDES-CBC"),n("1.2.840.113549.1.12.1.5","pbeWithSHAAnd128BitRC2-CBC"),n("1.2.840.113549.1.12.1.6","pbewithSHAAnd40BitRC2-CBC"),n("1.2.840.113549.2.7","hmacWithSHA1"),n("1.2.840.113549.2.8","hmacWithSHA224"),n("1.2.840.113549.2.9","hmacWithSHA256"),n("1.2.840.113549.2.10","hmacWithSHA384"),n("1.2.840.113549.2.11","hmacWithSHA512"),n("1.2.840.113549.3.7","des-EDE3-CBC"),n("2.16.840.1.101.3.4.1.2","aes128-CBC"),n("2.16.840.1.101.3.4.1.22","aes192-CBC"),n("2.16.840.1.101.3.4.1.42","aes256-CBC"),n("2.5.4.3","commonName"),n("2.5.4.5","serialName"),n("2.5.4.6","countryName"),n("2.5.4.7","localityName"),n("2.5.4.8","stateOrProvinceName"),n("2.5.4.9","streetAddress"),n("2.5.4.10","organizationName"),n("2.5.4.11","organizationalUnitName"),n("2.5.4.13","description"),n("2.5.4.15","businessCategory"),n("2.5.4.17","postalCode"),n("1.3.6.1.4.1.311.60.2.1.2","jurisdictionOfIncorporationStateOrProvinceName"),n("1.3.6.1.4.1.311.60.2.1.3","jurisdictionOfIncorporationCountryName"),n("2.16.840.1.113730.1.1","nsCertType"),n("2.16.840.1.113730.1.13","nsComment"),r("2.5.29.1","authorityKeyIdentifier"),r("2.5.29.2","keyAttributes"),r("2.5.29.3","certificatePolicies"),r("2.5.29.4","keyUsageRestriction"),r("2.5.29.5","policyMapping"),r("2.5.29.6","subtreesConstraint"),r("2.5.29.7","subjectAltName"),r("2.5.29.8","issuerAltName"),r("2.5.29.9","subjectDirectoryAttributes"),r("2.5.29.10","basicConstraints"),r("2.5.29.11","nameConstraints"),r("2.5.29.12","policyConstraints"),r("2.5.29.13","basicConstraints"),n("2.5.29.14","subjectKeyIdentifier"),n("2.5.29.15","keyUsage"),r("2.5.29.16","privateKeyUsagePeriod"),n("2.5.29.17","subjectAltName"),n("2.5.29.18","issuerAltName"),n("2.5.29.19","basicConstraints"),r("2.5.29.20","cRLNumber"),r("2.5.29.21","cRLReason"),r("2.5.29.22","expirationDate"),r("2.5.29.23","instructionCode"),r("2.5.29.24","invalidityDate"),r("2.5.29.25","cRLDistributionPoints"),r("2.5.29.26","issuingDistributionPoint"),r("2.5.29.27","deltaCRLIndicator"),r("2.5.29.28","issuingDistributionPoint"),r("2.5.29.29","certificateIssuer"),r("2.5.29.30","nameConstraints"),n("2.5.29.31","cRLDistributionPoints"),n("2.5.29.32","certificatePolicies"),r("2.5.29.33","policyMappings"),r("2.5.29.34","policyConstraints"),n("2.5.29.35","authorityKeyIdentifier"),r("2.5.29.36","policyConstraints"),n("2.5.29.37","extKeyUsage"),r("2.5.29.46","freshestCRL"),r("2.5.29.54","inhibitAnyPolicy"),n("1.3.6.1.4.1.11129.2.4.2","timestampList"),n("1.3.6.1.5.5.7.1.1","authorityInfoAccess"),n("1.3.6.1.5.5.7.3.1","serverAuth"),n("1.3.6.1.5.5.7.3.2","clientAuth"),n("1.3.6.1.5.5.7.3.3","codeSigning"),n("1.3.6.1.5.5.7.3.4","emailProtection"),n("1.3.6.1.5.5.7.3.8","timeStamping")})),w((function(e){var t=e.exports=z.asn1=z.asn1||{};function n(e,t,n){if(n>t){var r=new Error("Too few bytes to parse DER.");throw r.available=e.length(),r.remaining=t,r.requested=n,r}}t.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},t.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30},t.create=function(e,n,r,a,o){if(z.util.isArray(a)){for(var i=[],s=0;s<a.length;++s)void 0!==a[s]&&i.push(a[s]);a=i}var u={tagClass:e,type:n,constructed:r,composed:r||z.util.isArray(a),value:a};return o&&"bitStringContents"in o&&(u.bitStringContents=o.bitStringContents,u.original=t.copy(u)),u},t.copy=function(e,n){var r;if(z.util.isArray(e)){r=[];for(var a=0;a<e.length;++a)r.push(t.copy(e[a],n));return r}return"string"==typeof e?e:(r={tagClass:e.tagClass,type:e.type,constructed:e.constructed,composed:e.composed,value:t.copy(e.value,n)},n&&!n.excludeBitStringContents&&(r.bitStringContents=e.bitStringContents),r)},t.equals=function(e,n,r){if(z.util.isArray(e)){if(!z.util.isArray(n))return!1;if(e.length!==n.length)return!1;for(var a=0;a<e.length;++a)if(!t.equals(e[a],n[a]))return!1;return!0}if(typeof e!=typeof n)return!1;if("string"==typeof e)return e===n;var o=e.tagClass===n.tagClass&&e.type===n.type&&e.constructed===n.constructed&&e.composed===n.composed&&t.equals(e.value,n.value);return r&&r.includeBitStringContents&&(o=o&&e.bitStringContents===n.bitStringContents),o},t.getBerValueLength=function(e){var t=e.getByte();if(128!==t)return 128&t?e.getInt((127&t)<<3):t};var r=function(e,t){var r=e.getByte();if(t--,128!==r){var a;if(128&r){var o=127&r;n(e,t,o),a=e.getInt(o<<3)}else a=r;if(a<0)throw new Error("Negative length: "+a);return a}};t.fromDer=function(e,a){return void 0===a&&(a={strict:!0,decodeBitStrings:!0}),"boolean"==typeof a&&(a={strict:a,decodeBitStrings:!0}),"strict"in a||(a.strict=!0),"decodeBitStrings"in a||(a.decodeBitStrings=!0),"string"==typeof e&&(e=z.util.createBuffer(e)),function e(a,o,i,s){var u;n(a,o,2);var c=a.getByte();o--;var l=192&c,p=31&c;u=a.length();var d,f,h=r(a,o);if(o-=u-a.length(),void 0!==h&&h>o){if(s.strict){var m=new Error("Too few bytes to read ASN.1 value.");throw m.available=a.length(),m.remaining=o,m.requested=h,m}h=o}var g=32==(32&c);if(g)if(d=[],void 0===h)for(;;){if(n(a,o,2),a.bytes(2)===String.fromCharCode(0,0)){a.getBytes(2),o-=2;break}u=a.length(),d.push(e(a,o,i+1,s)),o-=u-a.length()}else for(;h>0;)u=a.length(),d.push(e(a,h,i+1,s)),o-=u-a.length(),h-=u-a.length();if(void 0===d&&l===t.Class.UNIVERSAL&&p===t.Type.BITSTRING&&(f=a.bytes(h)),void 0===d&&s.decodeBitStrings&&l===t.Class.UNIVERSAL&&p===t.Type.BITSTRING&&h>1){var v=a.read,y=o,b=0;if(p===t.Type.BITSTRING&&(n(a,o,1),b=a.getByte(),o--),0===b)try{u=a.length();var x=e(a,o,i+1,{verbose:s.verbose,strict:!0,decodeBitStrings:!0}),w=u-a.length();o-=w,p==t.Type.BITSTRING&&w++;var k=x.tagClass;w!==h||k!==t.Class.UNIVERSAL&&k!==t.Class.CONTEXT_SPECIFIC||(d=[x])}catch(e){}void 0===d&&(a.read=v,o=y)}if(void 0===d){if(void 0===h){if(s.strict)throw new Error("Non-constructed ASN.1 object of indefinite length.");h=o}if(p===t.Type.BMPSTRING)for(d="";h>0;h-=2)n(a,o,2),d+=String.fromCharCode(a.getInt16()),o-=2;else d=a.getBytes(h)}var S=void 0===f?null:{bitStringContents:f};return t.create(l,p,g,d,S)}(e,e.length(),0,a)},t.toDer=function(e){var n=z.util.createBuffer(),r=e.tagClass|e.type,a=z.util.createBuffer(),o=!1;if("bitStringContents"in e&&(o=!0,e.original&&(o=t.equals(e,e.original))),o)a.putBytes(e.bitStringContents);else if(e.composed){e.constructed?r|=32:a.putByte(0);for(var i=0;i<e.value.length;++i)void 0!==e.value[i]&&a.putBuffer(t.toDer(e.value[i]))}else if(e.type===t.Type.BMPSTRING)for(i=0;i<e.value.length;++i)a.putInt16(e.value.charCodeAt(i));else e.type===t.Type.INTEGER&&e.value.length>1&&(0===e.value.charCodeAt(0)&&0==(128&e.value.charCodeAt(1))||255===e.value.charCodeAt(0)&&128==(128&e.value.charCodeAt(1)))?a.putBytes(e.value.substr(1)):a.putBytes(e.value);if(n.putByte(r),a.length()<=127)n.putByte(127&a.length());else{var s=a.length(),u="";do{u+=String.fromCharCode(255&s),s>>>=8}while(s>0);for(n.putByte(128|u.length),i=u.length-1;i>=0;--i)n.putByte(u.charCodeAt(i))}return n.putBuffer(a),n},t.oidToDer=function(e){var t,n,r,a,o=e.split("."),i=z.util.createBuffer();i.putByte(40*parseInt(o[0],10)+parseInt(o[1],10));for(var s=2;s<o.length;++s){t=!0,n=[],r=parseInt(o[s],10);do{a=127&r,r>>>=7,t||(a|=128),n.push(a),t=!1}while(r>0);for(var u=n.length-1;u>=0;--u)i.putByte(n[u])}return i},t.derToOid=function(e){var t;"string"==typeof e&&(e=z.util.createBuffer(e));var n=e.getByte();t=Math.floor(n/40)+"."+n%40;for(var r=0;e.length()>0;)r<<=7,128&(n=e.getByte())?r+=127&n:(t+="."+(r+n),r=0);return t},t.utcTimeToDate=function(e){var t=new Date,n=parseInt(e.substr(0,2),10);n=n>=50?1900+n:2e3+n;var r=parseInt(e.substr(2,2),10)-1,a=parseInt(e.substr(4,2),10),o=parseInt(e.substr(6,2),10),i=parseInt(e.substr(8,2),10),s=0;if(e.length>11){var u=e.charAt(10),c=10;"+"!==u&&"-"!==u&&(s=parseInt(e.substr(10,2),10),c+=2)}if(t.setUTCFullYear(n,r,a),t.setUTCHours(o,i,s,0),c&&("+"===(u=e.charAt(c))||"-"===u)){var l=60*parseInt(e.substr(c+1,2),10)+parseInt(e.substr(c+4,2),10);l*=6e4,"+"===u?t.setTime(+t-l):t.setTime(+t+l)}return t},t.generalizedTimeToDate=function(e){var t=new Date,n=parseInt(e.substr(0,4),10),r=parseInt(e.substr(4,2),10)-1,a=parseInt(e.substr(6,2),10),o=parseInt(e.substr(8,2),10),i=parseInt(e.substr(10,2),10),s=parseInt(e.substr(12,2),10),u=0,c=0,l=!1;"Z"===e.charAt(e.length-1)&&(l=!0);var p=e.length-5,d=e.charAt(p);return"+"!==d&&"-"!==d||(c=60*parseInt(e.substr(p+1,2),10)+parseInt(e.substr(p+4,2),10),c*=6e4,"+"===d&&(c*=-1),l=!0),"."===e.charAt(14)&&(u=1e3*parseFloat(e.substr(14),10)),l?(t.setUTCFullYear(n,r,a),t.setUTCHours(o,i,s,u),t.setTime(+t+c)):(t.setFullYear(n,r,a),t.setHours(o,i,s,u)),t},t.dateToUtcTime=function(e){if("string"==typeof e)return e;var t="",n=[];n.push((""+e.getUTCFullYear()).substr(2)),n.push(""+(e.getUTCMonth()+1)),n.push(""+e.getUTCDate()),n.push(""+e.getUTCHours()),n.push(""+e.getUTCMinutes()),n.push(""+e.getUTCSeconds());for(var r=0;r<n.length;++r)n[r].length<2&&(t+="0"),t+=n[r];return t+"Z"},t.dateToGeneralizedTime=function(e){if("string"==typeof e)return e;var t="",n=[];n.push(""+e.getUTCFullYear()),n.push(""+(e.getUTCMonth()+1)),n.push(""+e.getUTCDate()),n.push(""+e.getUTCHours()),n.push(""+e.getUTCMinutes()),n.push(""+e.getUTCSeconds());for(var r=0;r<n.length;++r)n[r].length<2&&(t+="0"),t+=n[r];return t+"Z"},t.integerToDer=function(e){var t=z.util.createBuffer();if(e>=-128&&e<128)return t.putSignedInt(e,8);if(e>=-32768&&e<32768)return t.putSignedInt(e,16);if(e>=-8388608&&e<8388608)return t.putSignedInt(e,24);if(e>=-2147483648&&e<2147483648)return t.putSignedInt(e,32);var n=new Error("Integer too large; max is 32-bits.");throw n.integer=e,n},t.derToInteger=function(e){"string"==typeof e&&(e=z.util.createBuffer(e));var t=8*e.length();if(t>32)throw new Error("Integer too large; max is 32-bits.");return e.getSignedInt(t)},t.validate=function(e,n,r,a){var o=!1;if(e.tagClass!==n.tagClass&&void 0!==n.tagClass||e.type!==n.type&&void 0!==n.type)a&&(e.tagClass!==n.tagClass&&a.push("["+n.name+'] Expected tag class "'+n.tagClass+'", got "'+e.tagClass+'"'),e.type!==n.type&&a.push("["+n.name+'] Expected type "'+n.type+'", got "'+e.type+'"'));else if(e.constructed===n.constructed||void 0===n.constructed){if(o=!0,n.value&&z.util.isArray(n.value))for(var i=0,s=0;o&&s<n.value.length;++s)o=n.value[s].optional||!1,e.value[i]&&((o=t.validate(e.value[i],n.value[s],r,a))?++i:n.value[s].optional&&(o=!0)),!o&&a&&a.push("["+n.name+'] Tag class "'+n.tagClass+'", type "'+n.type+'" expected value length "'+n.value.length+'", got "'+e.value.length+'"');if(o&&r&&(n.capture&&(r[n.capture]=e.value),n.captureAsn1&&(r[n.captureAsn1]=e),n.captureBitStringContents&&"bitStringContents"in e&&(r[n.captureBitStringContents]=e.bitStringContents),n.captureBitStringValue&&"bitStringContents"in e))if(e.bitStringContents.length<2)r[n.captureBitStringValue]="";else{if(0!==e.bitStringContents.charCodeAt(0))throw new Error("captureBitStringValue only supported for zero unused bits");r[n.captureBitStringValue]=e.bitStringContents.slice(1)}}else a&&a.push("["+n.name+'] Expected constructed "'+n.constructed+'", got "'+e.constructed+'"');return o};var a=/[^\\u0000-\\u00ff]/;t.prettyPrint=function(e,n,r){var o="";r=r||2,(n=n||0)>0&&(o+="\n");for(var i="",s=0;s<n*r;++s)i+=" ";switch(o+=i+"Tag: ",e.tagClass){case t.Class.UNIVERSAL:o+="Universal:";break;case t.Class.APPLICATION:o+="Application:";break;case t.Class.CONTEXT_SPECIFIC:o+="Context-Specific:";break;case t.Class.PRIVATE:o+="Private:"}if(e.tagClass===t.Class.UNIVERSAL)switch(o+=e.type,e.type){case t.Type.NONE:o+=" (None)";break;case t.Type.BOOLEAN:o+=" (Boolean)";break;case t.Type.INTEGER:o+=" (Integer)";break;case t.Type.BITSTRING:o+=" (Bit string)";break;case t.Type.OCTETSTRING:o+=" (Octet string)";break;case t.Type.NULL:o+=" (Null)";break;case t.Type.OID:o+=" (Object Identifier)";break;case t.Type.ODESC:o+=" (Object Descriptor)";break;case t.Type.EXTERNAL:o+=" (External or Instance of)";break;case t.Type.REAL:o+=" (Real)";break;case t.Type.ENUMERATED:o+=" (Enumerated)";break;case t.Type.EMBEDDED:o+=" (Embedded PDV)";break;case t.Type.UTF8:o+=" (UTF8)";break;case t.Type.ROID:o+=" (Relative Object Identifier)";break;case t.Type.SEQUENCE:o+=" (Sequence)";break;case t.Type.SET:o+=" (Set)";break;case t.Type.PRINTABLESTRING:o+=" (Printable String)";break;case t.Type.IA5String:o+=" (IA5String (ASCII))";break;case t.Type.UTCTIME:o+=" (UTC time)";break;case t.Type.GENERALIZEDTIME:o+=" (Generalized time)";break;case t.Type.BMPSTRING:o+=" (BMP String)"}else o+=e.type;if(o+="\n",o+=i+"Constructed: "+e.constructed+"\n",e.composed){var u=0,c="";for(s=0;s<e.value.length;++s)void 0!==e.value[s]&&(u+=1,c+=t.prettyPrint(e.value[s],n+1,r),s+1<e.value.length&&(c+=","));o+=i+"Sub values: "+u+c}else{if(o+=i+"Value: ",e.type===t.Type.OID){var l=t.derToOid(e.value);o+=l,z.pki&&z.pki.oids&&l in z.pki.oids&&(o+=" ("+z.pki.oids[l]+") ")}if(e.type===t.Type.INTEGER)try{o+=t.derToInteger(e.value)}catch(t){o+="0x"+z.util.bytesToHex(e.value)}else if(e.type===t.Type.BITSTRING){if(e.value.length>1?o+="0x"+z.util.bytesToHex(e.value.slice(1)):o+="(none)",e.value.length>0){var p=e.value.charCodeAt(0);1==p?o+=" (1 unused bit shown)":p>1&&(o+=" ("+p+" unused bits shown)")}}else e.type===t.Type.OCTETSTRING?(a.test(e.value)||(o+="("+e.value+") "),o+="0x"+z.util.bytesToHex(e.value)):e.type===t.Type.UTF8?o+=z.util.decodeUtf8(e.value):e.type===t.Type.PRINTABLESTRING||e.type===t.Type.IA5String?o+=e.value:a.test(e.value)?o+="0x"+z.util.bytesToHex(e.value):0===e.value.length?o+="[null]":o+=e.value}return o}})),z.md=z.md||{},z.md.algorithms=z.md.algorithms||{},w((function(e){(e.exports=z.hmac=z.hmac||{}).create=function(){var e=null,t=null,n=null,r=null,a={start:function(a,o){if(null!==a)if("string"==typeof a){if(!((a=a.toLowerCase())in z.md.algorithms))throw new Error('Unknown hash algorithm "'+a+'"');t=z.md.algorithms[a].create()}else t=a;if(null===o)o=e;else{if("string"==typeof o)o=z.util.createBuffer(o);else if(z.util.isArray(o)){var i=o;o=z.util.createBuffer();for(var s=0;s<i.length;++s)o.putByte(i[s])}var u=o.length();for(u>t.blockLength&&(t.start(),t.update(o.bytes()),o=t.digest()),n=z.util.createBuffer(),r=z.util.createBuffer(),u=o.length(),s=0;s<u;++s)i=o.at(s),n.putByte(54^i),r.putByte(92^i);if(u<t.blockLength)for(i=t.blockLength-u,s=0;s<i;++s)n.putByte(54),r.putByte(92);e=o,n=n.bytes(),r=r.bytes()}t.start(),t.update(n)},update:function(e){t.update(e)},getMac:function(){var e=t.digest().bytes();return t.start(),t.update(r),t.update(e),t.digest()}};return a.digest=a.getMac,a}})),w((function(e){var t=e.exports=z.md5=z.md5||{};z.md.md5=z.md.algorithms.md5=t,t.create=function(){i||function(){n=String.fromCharCode(128),n+=z.util.fillString(String.fromCharCode(0),64),r=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12,5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2,0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9],a=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],o=new Array(64);for(var e=0;e<64;++e)o[e]=Math.floor(4294967296*Math.abs(Math.sin(e+1)));i=!0}();var e=null,t=z.util.createBuffer(),u=new Array(16),c={algorithm:"md5",blockLength:64,digestLength:16,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){c.messageLength=0,c.fullMessageLength=c.messageLength64=[];for(var n=c.messageLengthSize/4,r=0;r<n;++r)c.fullMessageLength.push(0);return t=z.util.createBuffer(),e={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878},c}};return c.start(),c.update=function(n,r){"utf8"===r&&(n=z.util.encodeUtf8(n));var a=n.length;c.messageLength+=a,a=[a/4294967296>>>0,a>>>0];for(var o=c.fullMessageLength.length-1;o>=0;--o)c.fullMessageLength[o]+=a[1],a[1]=a[0]+(c.fullMessageLength[o]/4294967296>>>0),c.fullMessageLength[o]=c.fullMessageLength[o]>>>0,a[0]=a[1]/4294967296>>>0;return t.putBytes(n),s(e,u,t),(t.read>2048||0===t.length())&&t.compact(),c},c.digest=function(){var r=z.util.createBuffer();r.putBytes(t.bytes());var a=c.fullMessageLength[c.fullMessageLength.length-1]+c.messageLengthSize&c.blockLength-1;r.putBytes(n.substr(0,c.blockLength-a));for(var o,i=0,l=c.fullMessageLength.length-1;l>=0;--l)i=(o=8*c.fullMessageLength[l]+i)/4294967296>>>0,r.putInt32Le(o>>>0);var p={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3};s(p,u,r);var d=z.util.createBuffer();return d.putInt32Le(p.h0),d.putInt32Le(p.h1),d.putInt32Le(p.h2),d.putInt32Le(p.h3),d},c};var n=null,r=null,a=null,o=null,i=!1;function s(e,t,n){for(var i,s,u,c,l,p,d,f=n.length();f>=64;){for(s=e.h0,u=e.h1,c=e.h2,l=e.h3,d=0;d<16;++d)t[d]=n.getInt32Le(),i=s+(l^u&(c^l))+o[d]+t[d],s=l,l=c,c=u,u+=i<<(p=a[d])|i>>>32-p;for(;d<32;++d)i=s+(c^l&(u^c))+o[d]+t[r[d]],s=l,l=c,c=u,u+=i<<(p=a[d])|i>>>32-p;for(;d<48;++d)i=s+(u^c^l)+o[d]+t[r[d]],s=l,l=c,c=u,u+=i<<(p=a[d])|i>>>32-p;for(;d<64;++d)i=s+(c^(u|~l))+o[d]+t[r[d]],s=l,l=c,c=u,u+=i<<(p=a[d])|i>>>32-p;e.h0=e.h0+s|0,e.h1=e.h1+u|0,e.h2=e.h2+c|0,e.h3=e.h3+l|0,f-=64}}})),w((function(e){var t=e.exports=z.pem=z.pem||{};function n(e){for(var t=e.name+": ",n=[],r=function(e,t){return" "+t},a=0;a<e.values.length;++a)n.push(e.values[a].replace(/^(\S+\r\n)/,r));t+=n.join(",")+"\r\n";var o=0,i=-1;for(a=0;a<t.length;++a,++o)if(o>65&&-1!==i){var s=t[i];","===s?(++i,t=t.substr(0,i)+"\r\n "+t.substr(i)):t=t.substr(0,i)+"\r\n"+s+t.substr(i+1),o=a-i-1,i=-1,++a}else" "!==t[a]&&"\t"!==t[a]&&","!==t[a]||(i=a);return t}function r(e){return e.replace(/^\s+/,"")}t.encode=function(e,t){t=t||{};var r,a="-----BEGIN "+e.type+"-----\r\n";if(e.procType&&(a+=n(r={name:"Proc-Type",values:[String(e.procType.version),e.procType.type]})),e.contentDomain&&(a+=n(r={name:"Content-Domain",values:[e.contentDomain]})),e.dekInfo&&(r={name:"DEK-Info",values:[e.dekInfo.algorithm]},e.dekInfo.parameters&&r.values.push(e.dekInfo.parameters),a+=n(r)),e.headers)for(var o=0;o<e.headers.length;++o)a+=n(e.headers[o]);return e.procType&&(a+="\r\n"),(a+=z.util.encode64(e.body,t.maxline||64)+"\r\n")+"-----END "+e.type+"-----\r\n"},t.decode=function(e){for(var t,n=[],a=/\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g,o=/([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/,i=/\r?\n/;t=a.exec(e);){var s={type:t[1],procType:null,contentDomain:null,dekInfo:null,headers:[],body:z.util.decode64(t[3])};if(n.push(s),t[2]){for(var u=t[2].split(i),c=0;t&&c<u.length;){for(var l=u[c].replace(/\s+$/,""),p=c+1;p<u.length;++p){var d=u[p];if(!/\s/.test(d[0]))break;l+=d,c=p}if(t=l.match(o)){for(var f={name:t[1],values:[]},h=t[2].split(","),m=0;m<h.length;++m)f.values.push(r(h[m]));if(s.procType)if(s.contentDomain||"Content-Domain"!==f.name)if(s.dekInfo||"DEK-Info"!==f.name)s.headers.push(f);else{if(0===f.values.length)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must have at least one subfield.');s.dekInfo={algorithm:h[0],parameters:h[1]||null}}else s.contentDomain=h[0]||"";else{if("Proc-Type"!==f.name)throw new Error('Invalid PEM formatted message. The first encapsulated header must be "Proc-Type".');if(2!==f.values.length)throw new Error('Invalid PEM formatted message. The "Proc-Type" header must have two subfields.');s.procType={version:h[0],type:h[1]}}}++c}if("ENCRYPTED"===s.procType&&!s.dekInfo)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must be present if "Proc-Type" is "ENCRYPTED".')}}if(0===n.length)throw new Error("Invalid PEM formatted message.");return n}})),z.des=z.des||{},z.des.startEncrypting=function(e,t,n,r){var a=he({key:e,output:n,decrypt:!1,mode:r||(null===t?"ECB":"CBC")});return a.start(t),a},z.des.createEncryptionCipher=function(e,t){return he({key:e,output:null,decrypt:!1,mode:t})},z.des.startDecrypting=function(e,t,n,r){var a=he({key:e,output:n,decrypt:!0,mode:r||(null===t?"ECB":"CBC")});return a.start(t),a},z.des.createDecryptionCipher=function(e,t){return he({key:e,output:null,decrypt:!0,mode:t})},z.des.Algorithm=function(e,t){var n=this;n.name=e,n.mode=new t({blockSize:8,cipher:{encrypt:function(e,t){return fe(n._keys,e,t,!1)},decrypt:function(e,t){return fe(n._keys,e,t,!0)}}}),n._init=!1},z.des.Algorithm.prototype.initialize=function(e){if(!this._init){var t=z.util.createBuffer(e.key);if(0===this.name.indexOf("3DES")&&24!==t.length())throw new Error("Invalid Triple-DES key size: "+8*t.length());this._keys=function(e){for(var t,n=[0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964],r=[0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697],a=[0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272],o=[0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144],i=[0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256],s=[0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488],u=[0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746],c=[0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568],l=[0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578],p=[0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488],d=[0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800],f=[0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744],h=[0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128],m=[0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261],g=e.length()>8?3:1,v=[],y=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],b=0,x=0;x<g;x++){var w=e.getInt32(),k=e.getInt32();w^=(t=252645135&(w>>>4^k))<<4,w^=t=65535&((k^=t)>>>-16^w),w^=(t=858993459&(w>>>2^(k^=t<<-16)))<<2,w^=t=65535&((k^=t)>>>-16^w),w^=(t=1431655765&(w>>>1^(k^=t<<-16)))<<1,w^=t=16711935&((k^=t)>>>8^w),t=(w^=(t=1431655765&(w>>>1^(k^=t<<8)))<<1)<<8|(k^=t)>>>20&240,w=k<<24|k<<8&16711680|k>>>8&65280|k>>>24&240,k=t;for(var S=0;S<y.length;++S){y[S]?(w=w<<2|w>>>26,k=k<<2|k>>>26):(w=w<<1|w>>>27,k=k<<1|k>>>27);var E=n[(w&=-15)>>>28]|r[w>>>24&15]|a[w>>>20&15]|o[w>>>16&15]|i[w>>>12&15]|s[w>>>8&15]|u[w>>>4&15],I=c[(k&=-15)>>>28]|l[k>>>24&15]|p[k>>>20&15]|d[k>>>16&15]|f[k>>>12&15]|h[k>>>8&15]|m[k>>>4&15];t=65535&(I>>>16^E),v[b++]=E^t,v[b++]=I^t<<16}}return v}(t),this._init=!0}},ae("DES-ECB",z.cipher.modes.ecb),ae("DES-CBC",z.cipher.modes.cbc),ae("DES-CFB",z.cipher.modes.cfb),ae("DES-OFB",z.cipher.modes.ofb),ae("DES-CTR",z.cipher.modes.ctr),ae("3DES-ECB",z.cipher.modes.ecb),ae("3DES-CBC",z.cipher.modes.cbc),ae("3DES-CFB",z.cipher.modes.cfb),ae("3DES-OFB",z.cipher.modes.ofb),ae("3DES-CTR",z.cipher.modes.ctr);var oe=[16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756],ie=[-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344],se=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584],ue=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],ce=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],le=[536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312],pe=[2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],de=[268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696];function fe(e,t,n,r){var a,o,i=32===e.length?3:9;a=3===i?r?[30,-2,-2]:[0,32,2]:r?[94,62,-2,32,64,2,30,-2,-2]:[0,32,2,62,30,-2,64,96,2];var s=t[0],u=t[1];s^=(o=252645135&(s>>>4^u))<<4,s^=(o=65535&(s>>>16^(u^=o)))<<16,s^=o=858993459&((u^=o)>>>2^s),s^=o=16711935&((u^=o<<2)>>>8^s),s=(s^=(o=1431655765&(s>>>1^(u^=o<<8)))<<1)<<1|s>>>31,u=(u^=o)<<1|u>>>31;for(var c=0;c<i;c+=3){for(var l=a[c+1],p=a[c+2],d=a[c];d!=l;d+=p){var f=u^e[d],h=(u>>>4|u<<28)^e[d+1];o=s,s=u,u=o^(ie[f>>>24&63]|ue[f>>>16&63]|le[f>>>8&63]|de[63&f]|oe[h>>>24&63]|se[h>>>16&63]|ce[h>>>8&63]|pe[63&h])}o=s,s=u,u=o}u=u>>>1|u<<31,u^=o=1431655765&((s=s>>>1|s<<31)>>>1^u),u^=(o=16711935&(u>>>8^(s^=o<<1)))<<8,u^=(o=858993459&(u>>>2^(s^=o)))<<2,u^=o=65535&((s^=o)>>>16^u),u^=o=252645135&((s^=o<<16)>>>4^u),s^=o<<4,n[0]=s,n[1]=u}function he(e){var t,n="DES-"+((e=e||{}).mode||"CBC").toUpperCase(),r=(t=e.decrypt?z.cipher.createDecipher(n,e.key):z.cipher.createCipher(n,e.key)).start;return t.start=function(e,n){var a=null;n instanceof z.util.ByteBuffer&&(a=n,n={}),(n=n||{}).output=a,n.iv=e,r.call(t,n)},t}var me,ge=z.pkcs5=z.pkcs5||{};z.util.isNodejs&&!z.options.usePureJavaScript&&(me=t),z.pbkdf2=ge.pbkdf2=function(e,t,n,r,a,o){if("function"==typeof a&&(o=a,a=null),z.util.isNodejs&&!z.options.usePureJavaScript&&me.pbkdf2&&(null===a||"object"!=typeof a)&&(me.pbkdf2Sync.length>4||!a||"sha1"===a))return"string"!=typeof a&&(a="sha1"),e=Buffer.from(e,"binary"),t=Buffer.from(t,"binary"),o?4===me.pbkdf2Sync.length?me.pbkdf2(e,t,n,r,(function(e,t){if(e)return o(e);o(null,t.toString("binary"))})):me.pbkdf2(e,t,n,r,a,(function(e,t){if(e)return o(e);o(null,t.toString("binary"))})):4===me.pbkdf2Sync.length?me.pbkdf2Sync(e,t,n,r).toString("binary"):me.pbkdf2Sync(e,t,n,r,a).toString("binary");if(null==a&&(a="sha1"),"string"==typeof a){if(!(a in z.md.algorithms))throw new Error("Unknown hash algorithm: "+a);a=z.md[a].create()}var i=a.digestLength;if(r>4294967295*i){var s=new Error("Derived key is too long.");if(o)return o(s);throw s}var u=Math.ceil(r/i),c=r-(u-1)*i,l=z.hmac.create();l.start(a,e);var p,d,f,h="";if(!o){for(var m=1;m<=u;++m){l.start(null,null),l.update(t),l.update(z.util.int32ToBytes(m)),p=f=l.digest().getBytes();for(var g=2;g<=n;++g)l.start(null,null),l.update(f),d=l.digest().getBytes(),p=z.util.xorBytes(p,d,i),f=d;h+=m<u?p:p.substr(0,c)}return h}function v(){if(m>u)return o(null,h);l.start(null,null),l.update(t),l.update(z.util.int32ToBytes(m)),p=f=l.digest().getBytes(),g=2,y()}function y(){if(g<=n)return l.start(null,null),l.update(f),d=l.digest().getBytes(),p=z.util.xorBytes(p,d,i),f=d,++g,z.util.setImmediate(y);h+=m<u?p:p.substr(0,c),++m,v()}m=1,v()},w((function(e){var t=e.exports=z.sha256=z.sha256||{};z.md.sha256=z.md.algorithms.sha256=t,t.create=function(){r||(n=String.fromCharCode(128),n+=z.util.fillString(String.fromCharCode(0),64),a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],r=!0);var e=null,t=z.util.createBuffer(),i=new Array(64),s={algorithm:"sha256",blockLength:64,digestLength:32,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){s.messageLength=0,s.fullMessageLength=s.messageLength64=[];for(var n=s.messageLengthSize/4,r=0;r<n;++r)s.fullMessageLength.push(0);return t=z.util.createBuffer(),e={h0:1779033703,h1:3144134277,h2:1013904242,h3:2773480762,h4:1359893119,h5:2600822924,h6:528734635,h7:1541459225},s}};return s.start(),s.update=function(n,r){"utf8"===r&&(n=z.util.encodeUtf8(n));var a=n.length;s.messageLength+=a,a=[a/4294967296>>>0,a>>>0];for(var u=s.fullMessageLength.length-1;u>=0;--u)s.fullMessageLength[u]+=a[1],a[1]=a[0]+(s.fullMessageLength[u]/4294967296>>>0),s.fullMessageLength[u]=s.fullMessageLength[u]>>>0,a[0]=a[1]/4294967296>>>0;return t.putBytes(n),o(e,i,t),(t.read>2048||0===t.length())&&t.compact(),s},s.digest=function(){var r=z.util.createBuffer();r.putBytes(t.bytes());var a,u=s.fullMessageLength[s.fullMessageLength.length-1]+s.messageLengthSize&s.blockLength-1;r.putBytes(n.substr(0,s.blockLength-u));for(var c=8*s.fullMessageLength[0],l=0;l<s.fullMessageLength.length-1;++l)c+=(a=8*s.fullMessageLength[l+1])/4294967296>>>0,r.putInt32(c>>>0),c=a>>>0;r.putInt32(c);var p={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4,h5:e.h5,h6:e.h6,h7:e.h7};o(p,i,r);var d=z.util.createBuffer();return d.putInt32(p.h0),d.putInt32(p.h1),d.putInt32(p.h2),d.putInt32(p.h3),d.putInt32(p.h4),d.putInt32(p.h5),d.putInt32(p.h6),d.putInt32(p.h7),d},s};var n=null,r=!1,a=null;function o(e,t,n){for(var r,o,i,s,u,c,l,p,d,f,h,m,g,v=n.length();v>=64;){for(u=0;u<16;++u)t[u]=n.getInt32();for(;u<64;++u)r=((r=t[u-2])>>>17|r<<15)^(r>>>19|r<<13)^r>>>10,o=((o=t[u-15])>>>7|o<<25)^(o>>>18|o<<14)^o>>>3,t[u]=r+t[u-7]+o+t[u-16]|0;for(c=e.h0,l=e.h1,p=e.h2,d=e.h3,f=e.h4,h=e.h5,m=e.h6,g=e.h7,u=0;u<64;++u)i=(c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),s=c&l|p&(c^l),r=g+((f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7))+(m^f&(h^m))+a[u]+t[u],g=m,m=h,h=f,f=d+r>>>0,d=p,p=l,l=c,c=r+(o=i+s)>>>0;e.h0=e.h0+c|0,e.h1=e.h1+l|0,e.h2=e.h2+p|0,e.h3=e.h3+d|0,e.h4=e.h4+f|0,e.h5=e.h5+h|0,e.h6=e.h6+m|0,e.h7=e.h7+g|0,v-=64}}})),w((function(e){var n=null;!z.util.isNodejs||z.options.usePureJavaScript||process.versions["node-webkit"]||(n=t),(e.exports=z.prng=z.prng||{}).create=function(e){for(var t={plugin:e,key:null,seed:null,time:null,reseeds:0,generated:0,keyBytes:""},r=e.md,a=new Array(32),o=0;o<32;++o)a[o]=r.create();function i(){if(t.pools[0].messageLength>=32)return s();var e=32-t.pools[0].messageLength<<5;t.collect(t.seedFileSync(e)),s()}function s(){t.reseeds=4294967295===t.reseeds?0:t.reseeds+1;var e=t.plugin.md.create();e.update(t.keyBytes);for(var n=1,r=0;r<32;++r)t.reseeds%n==0&&(e.update(t.pools[r].digest().getBytes()),t.pools[r].start()),n<<=1;t.keyBytes=e.digest().getBytes(),e.start(),e.update(t.keyBytes);var a=e.digest().getBytes();t.key=t.plugin.formatKey(t.keyBytes),t.seed=t.plugin.formatSeed(a),t.generated=0}function u(e){var t=null,n=z.util.globalScope,r=n.crypto||n.msCrypto;r&&r.getRandomValues&&(t=function(e){return r.getRandomValues(e)});var a=z.util.createBuffer();if(t)for(;a.length()<e;){var o=Math.max(1,Math.min(e-a.length(),65536)/4),i=new Uint32Array(Math.floor(o));try{t(i);for(var s=0;s<i.length;++s)a.putInt32(i[s])}catch(e){if(!("undefined"!=typeof QuotaExceededError&&e instanceof QuotaExceededError))throw e}}if(a.length()<e)for(var u,c,l,p=Math.floor(65536*Math.random());a.length()<e;)for(c=16807*(65535&p),c+=(32767&(u=16807*(p>>16)))<<16,p=4294967295&(c=(2147483647&(c+=u>>15))+(c>>31)),s=0;s<3;++s)l=p>>>(s<<3),l^=Math.floor(256*Math.random()),a.putByte(String.fromCharCode(255&l));return a.getBytes(e)}return t.pools=a,t.pool=0,t.generate=function(e,n){if(!n)return t.generateSync(e);var r=t.plugin.cipher,a=t.plugin.increment,o=t.plugin.formatKey,i=t.plugin.formatSeed,u=z.util.createBuffer();t.key=null,function c(l){if(l)return n(l);if(u.length()>=e)return n(null,u.getBytes(e));if(t.generated>1048575&&(t.key=null),null===t.key)return z.util.nextTick((function(){!function(e){if(t.pools[0].messageLength>=32)return s(),e();var n=32-t.pools[0].messageLength<<5;t.seedFile(n,(function(n,r){if(n)return e(n);t.collect(r),s(),e()}))}(c)}));var p=r(t.key,t.seed);t.generated+=p.length,u.putBytes(p),t.key=o(r(t.key,a(t.seed))),t.seed=i(r(t.key,t.seed)),z.util.setImmediate(c)}()},t.generateSync=function(e){var n=t.plugin.cipher,r=t.plugin.increment,a=t.plugin.formatKey,o=t.plugin.formatSeed;t.key=null;for(var s=z.util.createBuffer();s.length()<e;){t.generated>1048575&&(t.key=null),null===t.key&&i();var u=n(t.key,t.seed);t.generated+=u.length,s.putBytes(u),t.key=a(n(t.key,r(t.seed))),t.seed=o(n(t.key,t.seed))}return s.getBytes(e)},n?(t.seedFile=function(e,t){n.randomBytes(e,(function(e,n){if(e)return t(e);t(null,n.toString())}))},t.seedFileSync=function(e){return n.randomBytes(e).toString()}):(t.seedFile=function(e,t){try{t(null,u(e))}catch(e){t(e)}},t.seedFileSync=u),t.collect=function(e){for(var n=e.length,r=0;r<n;++r)t.pools[t.pool].update(e.substr(r,1)),t.pool=31===t.pool?0:t.pool+1},t.collectInt=function(e,n){for(var r="",a=0;a<n;a+=8)r+=String.fromCharCode(e>>a&255);t.collect(r)},t.registerWorker=function(e){e===self?t.seedFile=function(e,t){self.addEventListener("message",(function e(n){var r=n.data;r.forge&&r.forge.prng&&(self.removeEventListener("message",e),t(r.forge.prng.err,r.forge.prng.bytes))})),self.postMessage({forge:{prng:{needed:e}}})}:e.addEventListener("message",(function(n){var r=n.data;r.forge&&r.forge.prng&&t.seedFile(r.forge.prng.needed,(function(t,n){e.postMessage({forge:{prng:{err:t,bytes:n}}})}))}))},t}})),w((function(e){z.random&&z.random.getBytes?e.exports=z.random:function(t){var n={},r=new Array(4),a=z.util.createBuffer();function o(){var e=z.prng.create(n);return e.getBytes=function(t,n){return e.generate(t,n)},e.getBytesSync=function(t){return e.generate(t)},e}n.formatKey=function(e){var t=z.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),z.aes._expandKey(e,!1)},n.formatSeed=function(e){var t=z.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),e},n.cipher=function(e,t){return z.aes._updateBlock(e,t,r,!1),a.putInt32(r[0]),a.putInt32(r[1]),a.putInt32(r[2]),a.putInt32(r[3]),a.getBytes()},n.increment=function(e){return++e[3],e},n.md=z.md.sha256;var i=o(),s=null,u=z.util.globalScope,c=u.crypto||u.msCrypto;if(c&&c.getRandomValues&&(s=function(e){return c.getRandomValues(e)}),!z.util.isNodejs&&!s){if(i.collectInt(+new Date,32),"undefined"!=typeof navigator){var l="";for(var p in navigator)try{"string"==typeof navigator[p]&&(l+=navigator[p])}catch(e){}i.collect(l),l=null}t&&(t().mousemove((function(e){i.collectInt(e.clientX,16),i.collectInt(e.clientY,16)})),t().keypress((function(e){i.collectInt(e.charCode,8)})))}if(z.random)for(var p in i)z.random[p]=i[p];else z.random=i;z.random.createInstance=o,e.exports=z.random}("undefined"!=typeof jQuery?jQuery:null)}));var ve=[217,120,249,196,25,221,181,237,40,233,253,121,74,160,216,157,198,126,55,131,43,118,83,142,98,76,100,136,68,139,251,162,23,154,89,245,135,179,79,19,97,69,109,141,9,129,125,50,189,143,64,235,134,183,123,11,240,149,33,34,92,107,78,130,84,214,101,147,206,96,178,28,115,86,192,20,167,140,241,220,18,117,202,31,59,190,228,209,66,61,212,48,163,60,182,38,111,191,14,218,70,105,7,87,39,242,29,155,188,148,67,3,248,17,199,246,144,239,62,231,6,195,213,47,200,102,30,215,8,232,234,222,128,82,238,247,132,170,114,172,53,77,106,42,150,26,210,113,90,21,73,116,75,159,208,94,4,24,164,236,194,224,65,110,15,81,203,204,36,145,175,80,161,244,112,57,153,124,58,133,35,184,180,122,252,2,54,91,37,85,151,49,45,93,250,152,227,138,146,174,5,223,41,16,103,108,186,201,211,0,230,207,225,158,168,44,99,22,1,63,88,226,137,169,13,56,52,27,171,51,255,176,187,72,12,95,185,177,205,46,197,243,219,71,229,165,156,119,10,166,32,104,254,127,193,173],ye=[1,2,3,5],be=function(e,t){return e<<t&65535|(65535&e)>>16-t},xe=function(e,t){return(65535&e)>>t|e<<16-t&65535};z.rc2=z.rc2||{},z.rc2.expandKey=function(e,t){"string"==typeof e&&(e=z.util.createBuffer(e)),t=t||128;var n,r=e,a=e.length(),o=t,i=Math.ceil(o/8),s=255>>(7&o);for(n=a;n<128;n++)r.putByte(ve[r.at(n-1)+r.at(n-a)&255]);for(r.setAt(128-i,ve[r.at(128-i)&s]),n=127-i;n>=0;n--)r.setAt(n,ve[r.at(n+1)^r.at(n+i)]);return r};var we,ke=function(e,t,n){var r,a,o,i,s=!1,u=null,c=null,l=null,p=[];for(e=z.rc2.expandKey(e,t),o=0;o<64;o++)p.push(e.getInt16Le());n?(r=function(e){for(o=0;o<4;o++)e[o]+=p[i]+(e[(o+3)%4]&e[(o+2)%4])+(~e[(o+3)%4]&e[(o+1)%4]),e[o]=be(e[o],ye[o]),i++},a=function(e){for(o=0;o<4;o++)e[o]+=p[63&e[(o+3)%4]]}):(r=function(e){for(o=3;o>=0;o--)e[o]=xe(e[o],ye[o]),e[o]-=p[i]+(e[(o+3)%4]&e[(o+2)%4])+(~e[(o+3)%4]&e[(o+1)%4]),i--},a=function(e){for(o=3;o>=0;o--)e[o]-=p[63&e[(o+3)%4]]});var d=function(e){var t=[];for(o=0;o<4;o++){var r=u.getInt16Le();null!==l&&(n?r^=l.getInt16Le():l.putInt16Le(r)),t.push(65535&r)}i=n?0:63;for(var a=0;a<e.length;a++)for(var s=0;s<e[a][0];s++)e[a][1](t);for(o=0;o<4;o++)null!==l&&(n?l.putInt16Le(t[o]):t[o]^=l.getInt16Le()),c.putInt16Le(t[o])},f=null;return f={start:function(e,t){e&&"string"==typeof e&&(e=z.util.createBuffer(e)),s=!1,u=z.util.createBuffer(),c=t||new z.util.createBuffer,l=e,f.output=c},update:function(e){for(s||u.putBuffer(e);u.length()>=8;)d([[5,r],[1,a],[6,r],[1,a],[5,r]])},finish:function(e){var t=!0;if(n)if(e)t=e(8,u,!n);else{var r=8===u.length()?8:8-u.length();u.fillWithByte(r,r)}if(t&&(s=!0,f.update()),!n&&(t=0===u.length()))if(e)t=e(8,c,!n);else{var a=c.length(),o=c.at(a-1);o>a?t=!1:c.truncate(o)}return t}}};function Se(e,t,n){this.data=[],null!=e&&("number"==typeof e?this.fromNumber(e,t,n):null==t&&"string"!=typeof e?this.fromString(e,256):this.fromString(e,t))}function Ee(){return new Se(null)}function Ie(e,t,n,r,a,o){for(var i=16383&t,s=t>>14;--o>=0;){var u=16383&this.data[e],c=this.data[e++]>>14,l=s*u+c*i;a=((u=i*u+((16383&l)<<14)+n.data[r]+a)>>28)+(l>>14)+s*c,n.data[r++]=268435455&u}return a}z.rc2.startEncrypting=function(e,t,n){var r=z.rc2.createEncryptionCipher(e,128);return r.start(t,n),r},z.rc2.createEncryptionCipher=function(e,t){return ke(e,t,!0)},z.rc2.startDecrypting=function(e,t,n){var r=z.rc2.createDecryptionCipher(e,128);return r.start(t,n),r},z.rc2.createDecryptionCipher=function(e,t){return ke(e,t,!1)},z.jsbn=z.jsbn||{},z.jsbn.BigInteger=Se,"undefined"==typeof navigator?(Se.prototype.am=Ie,we=28):"Microsoft Internet Explorer"==navigator.appName?(Se.prototype.am=function(e,t,n,r,a,o){for(var i=32767&t,s=t>>15;--o>=0;){var u=32767&this.data[e],c=this.data[e++]>>15,l=s*u+c*i;a=((u=i*u+((32767&l)<<15)+n.data[r]+(1073741823&a))>>>30)+(l>>>15)+s*c+(a>>>30),n.data[r++]=1073741823&u}return a},we=30):"Netscape"!=navigator.appName?(Se.prototype.am=function(e,t,n,r,a,o){for(;--o>=0;){var i=t*this.data[e++]+n.data[r]+a;a=Math.floor(i/67108864),n.data[r++]=67108863&i}return a},we=26):(Se.prototype.am=Ie,we=28),Se.prototype.DB=we,Se.prototype.DM=(1<<we)-1,Se.prototype.DV=1<<we,Se.prototype.FV=Math.pow(2,52),Se.prototype.F1=52-we,Se.prototype.F2=2*we-52;var Ce,Te,_e="0123456789abcdefghijklmnopqrstuvwxyz",Ne=new Array;for(Ce="0".charCodeAt(0),Te=0;Te<=9;++Te)Ne[Ce++]=Te;for(Ce="a".charCodeAt(0),Te=10;Te<36;++Te)Ne[Ce++]=Te;for(Ce="A".charCodeAt(0),Te=10;Te<36;++Te)Ne[Ce++]=Te;function Ae(e){return _e.charAt(e)}function Re(e,t){var n=Ne[e.charCodeAt(t)];return null==n?-1:n}function Oe(e){var t=Ee();return t.fromInt(e),t}function Be(e){var t,n=1;return 0!=(t=e>>>16)&&(e=t,n+=16),0!=(t=e>>8)&&(e=t,n+=8),0!=(t=e>>4)&&(e=t,n+=4),0!=(t=e>>2)&&(e=t,n+=2),0!=(t=e>>1)&&(e=t,n+=1),n}function De(e){this.m=e}function Me(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function Fe(e,t){return e&t}function Pe(e,t){return e|t}function Le(e,t){return e^t}function Ue(e,t){return e&~t}function Ve(e){if(0==e)return-1;var t=0;return 0==(65535&e)&&(e>>=16,t+=16),0==(255&e)&&(e>>=8,t+=8),0==(15&e)&&(e>>=4,t+=4),0==(3&e)&&(e>>=2,t+=2),0==(1&e)&&++t,t}function ze(e){for(var t=0;0!=e;)e&=e-1,++t;return t}function je(){}function We(e){return e}function He(e){this.r2=Ee(),this.q3=Ee(),Se.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}De.prototype.convert=function(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e},De.prototype.revert=function(e){return e},De.prototype.reduce=function(e){e.divRemTo(this.m,null,e)},De.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n),this.reduce(n)},De.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},Me.prototype.convert=function(e){var t=Ee();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(Se.ZERO)>0&&this.m.subTo(t,t),t},Me.prototype.revert=function(e){var t=Ee();return e.copyTo(t),this.reduce(t),t},Me.prototype.reduce=function(e){for(;e.t<=this.mt2;)e.data[e.t++]=0;for(var t=0;t<this.m.t;++t){var n=32767&e.data[t],r=n*this.mpl+((n*this.mph+(e.data[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(n=t+this.m.t,e.data[n]+=this.m.am(0,r,e,t,0,this.m.t);e.data[n]>=e.DV;)e.data[n]-=e.DV,e.data[++n]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},Me.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n),this.reduce(n)},Me.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},Se.prototype.copyTo=function(e){for(var t=this.t-1;t>=0;--t)e.data[t]=this.data[t];e.t=this.t,e.s=this.s},Se.prototype.fromInt=function(e){this.t=1,this.s=e<0?-1:0,e>0?this.data[0]=e:e<-1?this.data[0]=e+this.DV:this.t=0},Se.prototype.fromString=function(e,t){var n;if(16==t)n=4;else if(8==t)n=3;else if(256==t)n=8;else if(2==t)n=1;else if(32==t)n=5;else{if(4!=t)return void this.fromRadix(e,t);n=2}this.t=0,this.s=0;for(var r=e.length,a=!1,o=0;--r>=0;){var i=8==n?255&e[r]:Re(e,r);i<0?"-"==e.charAt(r)&&(a=!0):(a=!1,0==o?this.data[this.t++]=i:o+n>this.DB?(this.data[this.t-1]|=(i&(1<<this.DB-o)-1)<<o,this.data[this.t++]=i>>this.DB-o):this.data[this.t-1]|=i<<o,(o+=n)>=this.DB&&(o-=this.DB))}8==n&&0!=(128&e[0])&&(this.s=-1,o>0&&(this.data[this.t-1]|=(1<<this.DB-o)-1<<o)),this.clamp(),a&&Se.ZERO.subTo(this,this)},Se.prototype.clamp=function(){for(var e=this.s&this.DM;this.t>0&&this.data[this.t-1]==e;)--this.t},Se.prototype.dlShiftTo=function(e,t){var n;for(n=this.t-1;n>=0;--n)t.data[n+e]=this.data[n];for(n=e-1;n>=0;--n)t.data[n]=0;t.t=this.t+e,t.s=this.s},Se.prototype.drShiftTo=function(e,t){for(var n=e;n<this.t;++n)t.data[n-e]=this.data[n];t.t=Math.max(this.t-e,0),t.s=this.s},Se.prototype.lShiftTo=function(e,t){var n,r=e%this.DB,a=this.DB-r,o=(1<<a)-1,i=Math.floor(e/this.DB),s=this.s<<r&this.DM;for(n=this.t-1;n>=0;--n)t.data[n+i+1]=this.data[n]>>a|s,s=(this.data[n]&o)<<r;for(n=i-1;n>=0;--n)t.data[n]=0;t.data[i]=s,t.t=this.t+i+1,t.s=this.s,t.clamp()},Se.prototype.rShiftTo=function(e,t){t.s=this.s;var n=Math.floor(e/this.DB);if(n>=this.t)t.t=0;else{var r=e%this.DB,a=this.DB-r,o=(1<<r)-1;t.data[0]=this.data[n]>>r;for(var i=n+1;i<this.t;++i)t.data[i-n-1]|=(this.data[i]&o)<<a,t.data[i-n]=this.data[i]>>r;r>0&&(t.data[this.t-n-1]|=(this.s&o)<<a),t.t=this.t-n,t.clamp()}},Se.prototype.subTo=function(e,t){for(var n=0,r=0,a=Math.min(e.t,this.t);n<a;)r+=this.data[n]-e.data[n],t.data[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r-=e.s;n<this.t;)r+=this.data[n],t.data[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r-=e.data[n],t.data[n++]=r&this.DM,r>>=this.DB;r-=e.s}t.s=r<0?-1:0,r<-1?t.data[n++]=this.DV+r:r>0&&(t.data[n++]=r),t.t=n,t.clamp()},Se.prototype.multiplyTo=function(e,t){var n=this.abs(),r=e.abs(),a=n.t;for(t.t=a+r.t;--a>=0;)t.data[a]=0;for(a=0;a<r.t;++a)t.data[a+n.t]=n.am(0,r.data[a],t,a,0,n.t);t.s=0,t.clamp(),this.s!=e.s&&Se.ZERO.subTo(t,t)},Se.prototype.squareTo=function(e){for(var t=this.abs(),n=e.t=2*t.t;--n>=0;)e.data[n]=0;for(n=0;n<t.t-1;++n){var r=t.am(n,t.data[n],e,2*n,0,1);(e.data[n+t.t]+=t.am(n+1,2*t.data[n],e,2*n+1,r,t.t-n-1))>=t.DV&&(e.data[n+t.t]-=t.DV,e.data[n+t.t+1]=1)}e.t>0&&(e.data[e.t-1]+=t.am(n,t.data[n],e,2*n,0,1)),e.s=0,e.clamp()},Se.prototype.divRemTo=function(e,t,n){var r=e.abs();if(!(r.t<=0)){var a=this.abs();if(a.t<r.t)return null!=t&&t.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=Ee());var o=Ee(),i=this.s,s=e.s,u=this.DB-Be(r.data[r.t-1]);u>0?(r.lShiftTo(u,o),a.lShiftTo(u,n)):(r.copyTo(o),a.copyTo(n));var c=o.t,l=o.data[c-1];if(0!=l){var p=l*(1<<this.F1)+(c>1?o.data[c-2]>>this.F2:0),d=this.FV/p,f=(1<<this.F1)/p,h=1<<this.F2,m=n.t,g=m-c,v=null==t?Ee():t;for(o.dlShiftTo(g,v),n.compareTo(v)>=0&&(n.data[n.t++]=1,n.subTo(v,n)),Se.ONE.dlShiftTo(c,v),v.subTo(o,o);o.t<c;)o.data[o.t++]=0;for(;--g>=0;){var y=n.data[--m]==l?this.DM:Math.floor(n.data[m]*d+(n.data[m-1]+h)*f);if((n.data[m]+=o.am(0,y,n,g,0,c))<y)for(o.dlShiftTo(g,v),n.subTo(v,n);n.data[m]<--y;)n.subTo(v,n)}null!=t&&(n.drShiftTo(c,t),i!=s&&Se.ZERO.subTo(t,t)),n.t=c,n.clamp(),u>0&&n.rShiftTo(u,n),i<0&&Se.ZERO.subTo(n,n)}}},Se.prototype.invDigit=function(){if(this.t<1)return 0;var e=this.data[0];if(0==(1&e))return 0;var t=3&e;return(t=(t=(t=(t=t*(2-(15&e)*t)&15)*(2-(255&e)*t)&255)*(2-((65535&e)*t&65535))&65535)*(2-e*t%this.DV)%this.DV)>0?this.DV-t:-t},Se.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},Se.prototype.exp=function(e,t){if(e>4294967295||e<1)return Se.ONE;var n=Ee(),r=Ee(),a=t.convert(this),o=Be(e)-1;for(a.copyTo(n);--o>=0;)if(t.sqrTo(n,r),(e&1<<o)>0)t.mulTo(r,a,n);else{var i=n;n=r,r=i}return t.revert(n)},Se.prototype.toString=function(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)return this.toRadix(e);t=2}var n,r=(1<<t)-1,a=!1,o="",i=this.t,s=this.DB-i*this.DB%t;if(i-- >0)for(s<this.DB&&(n=this.data[i]>>s)>0&&(a=!0,o=Ae(n));i>=0;)s<t?(n=(this.data[i]&(1<<s)-1)<<t-s,n|=this.data[--i]>>(s+=this.DB-t)):(n=this.data[i]>>(s-=t)&r,s<=0&&(s+=this.DB,--i)),n>0&&(a=!0),a&&(o+=Ae(n));return a?o:"0"},Se.prototype.negate=function(){var e=Ee();return Se.ZERO.subTo(this,e),e},Se.prototype.abs=function(){return this.s<0?this.negate():this},Se.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var n=this.t;if(0!=(t=n-e.t))return this.s<0?-t:t;for(;--n>=0;)if(0!=(t=this.data[n]-e.data[n]))return t;return 0},Se.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+Be(this.data[this.t-1]^this.s&this.DM)},Se.prototype.mod=function(e){var t=Ee();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(Se.ZERO)>0&&e.subTo(t,t),t},Se.prototype.modPowInt=function(e,t){var n;return n=e<256||t.isEven()?new De(t):new Me(t),this.exp(e,n)},Se.ZERO=Oe(0),Se.ONE=Oe(1),je.prototype.convert=We,je.prototype.revert=We,je.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n)},je.prototype.sqrTo=function(e,t){e.squareTo(t)},He.prototype.convert=function(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=Ee();return e.copyTo(t),this.reduce(t),t},He.prototype.revert=function(e){return e},He.prototype.reduce=function(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)},He.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n),this.reduce(n)},He.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)};var Ge=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509],Ke=(1<<26)/Ge[Ge.length-1];if(Se.prototype.chunkSize=function(e){return Math.floor(Math.LN2*this.DB/Math.log(e))},Se.prototype.toRadix=function(e){if(null==e&&(e=10),0==this.signum()||e<2||e>36)return"0";var t=this.chunkSize(e),n=Math.pow(e,t),r=Oe(n),a=Ee(),o=Ee(),i="";for(this.divRemTo(r,a,o);a.signum()>0;)i=(n+o.intValue()).toString(e).substr(1)+i,a.divRemTo(r,a,o);return o.intValue().toString(e)+i},Se.prototype.fromRadix=function(e,t){this.fromInt(0),null==t&&(t=10);for(var n=this.chunkSize(t),r=Math.pow(t,n),a=!1,o=0,i=0,s=0;s<e.length;++s){var u=Re(e,s);u<0?"-"==e.charAt(s)&&0==this.signum()&&(a=!0):(i=t*i+u,++o>=n&&(this.dMultiply(r),this.dAddOffset(i,0),o=0,i=0))}o>0&&(this.dMultiply(Math.pow(t,o)),this.dAddOffset(i,0)),a&&Se.ZERO.subTo(this,this)},Se.prototype.fromNumber=function(e,t,n){if("number"==typeof t)if(e<2)this.fromInt(1);else for(this.fromNumber(e,n),this.testBit(e-1)||this.bitwiseTo(Se.ONE.shiftLeft(e-1),Pe,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(Se.ONE.shiftLeft(e-1),this);else{var r=new Array,a=7&e;r.length=1+(e>>3),t.nextBytes(r),a>0?r[0]&=(1<<a)-1:r[0]=0,this.fromString(r,256)}},Se.prototype.bitwiseTo=function(e,t,n){var r,a,o=Math.min(e.t,this.t);for(r=0;r<o;++r)n.data[r]=t(this.data[r],e.data[r]);if(e.t<this.t){for(a=e.s&this.DM,r=o;r<this.t;++r)n.data[r]=t(this.data[r],a);n.t=this.t}else{for(a=this.s&this.DM,r=o;r<e.t;++r)n.data[r]=t(a,e.data[r]);n.t=e.t}n.s=t(this.s,e.s),n.clamp()},Se.prototype.changeBit=function(e,t){var n=Se.ONE.shiftLeft(e);return this.bitwiseTo(n,t,n),n},Se.prototype.addTo=function(e,t){for(var n=0,r=0,a=Math.min(e.t,this.t);n<a;)r+=this.data[n]+e.data[n],t.data[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r+=e.s;n<this.t;)r+=this.data[n],t.data[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r+=e.data[n],t.data[n++]=r&this.DM,r>>=this.DB;r+=e.s}t.s=r<0?-1:0,r>0?t.data[n++]=r:r<-1&&(t.data[n++]=this.DV+r),t.t=n,t.clamp()},Se.prototype.dMultiply=function(e){this.data[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()},Se.prototype.dAddOffset=function(e,t){if(0!=e){for(;this.t<=t;)this.data[this.t++]=0;for(this.data[t]+=e;this.data[t]>=this.DV;)this.data[t]-=this.DV,++t>=this.t&&(this.data[this.t++]=0),++this.data[t]}},Se.prototype.multiplyLowerTo=function(e,t,n){var r,a=Math.min(this.t+e.t,t);for(n.s=0,n.t=a;a>0;)n.data[--a]=0;for(r=n.t-this.t;a<r;++a)n.data[a+this.t]=this.am(0,e.data[a],n,a,0,this.t);for(r=Math.min(e.t,t);a<r;++a)this.am(0,e.data[a],n,a,0,t-a);n.clamp()},Se.prototype.multiplyUpperTo=function(e,t,n){--t;var r=n.t=this.t+e.t-t;for(n.s=0;--r>=0;)n.data[r]=0;for(r=Math.max(t-this.t,0);r<e.t;++r)n.data[this.t+r-t]=this.am(t-r,e.data[r],n,0,0,this.t+r-t);n.clamp(),n.drShiftTo(1,n)},Se.prototype.modInt=function(e){if(e<=0)return 0;var t=this.DV%e,n=this.s<0?e-1:0;if(this.t>0)if(0==t)n=this.data[0]%e;else for(var r=this.t-1;r>=0;--r)n=(t*n+this.data[r])%e;return n},Se.prototype.millerRabin=function(e){var t=this.subtract(Se.ONE),n=t.getLowestSetBit();if(n<=0)return!1;for(var r,a=t.shiftRight(n),o={nextBytes:function(e){for(var t=0;t<e.length;++t)e[t]=Math.floor(256*Math.random())}},i=0;i<e;++i){do{r=new Se(this.bitLength(),o)}while(r.compareTo(Se.ONE)<=0||r.compareTo(t)>=0);var s=r.modPow(a,this);if(0!=s.compareTo(Se.ONE)&&0!=s.compareTo(t)){for(var u=1;u++<n&&0!=s.compareTo(t);)if(0==(s=s.modPowInt(2,this)).compareTo(Se.ONE))return!1;if(0!=s.compareTo(t))return!1}}return!0},Se.prototype.clone=function(){var e=Ee();return this.copyTo(e),e},Se.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this.data[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this.data[0];if(0==this.t)return 0}return(this.data[1]&(1<<32-this.DB)-1)<<this.DB|this.data[0]},Se.prototype.byteValue=function(){return 0==this.t?this.s:this.data[0]<<24>>24},Se.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},Se.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},Se.prototype.toByteArray=function(){var e=this.t,t=new Array;t[0]=this.s;var n,r=this.DB-e*this.DB%8,a=0;if(e-- >0)for(r<this.DB&&(n=this.data[e]>>r)!=(this.s&this.DM)>>r&&(t[a++]=n|this.s<<this.DB-r);e>=0;)r<8?(n=(this.data[e]&(1<<r)-1)<<8-r,n|=this.data[--e]>>(r+=this.DB-8)):(n=this.data[e]>>(r-=8)&255,r<=0&&(r+=this.DB,--e)),0!=(128&n)&&(n|=-256),0==a&&(128&this.s)!=(128&n)&&++a,(a>0||n!=this.s)&&(t[a++]=n);return t},Se.prototype.equals=function(e){return 0==this.compareTo(e)},Se.prototype.min=function(e){return this.compareTo(e)<0?this:e},Se.prototype.max=function(e){return this.compareTo(e)>0?this:e},Se.prototype.and=function(e){var t=Ee();return this.bitwiseTo(e,Fe,t),t},Se.prototype.or=function(e){var t=Ee();return this.bitwiseTo(e,Pe,t),t},Se.prototype.xor=function(e){var t=Ee();return this.bitwiseTo(e,Le,t),t},Se.prototype.andNot=function(e){var t=Ee();return this.bitwiseTo(e,Ue,t),t},Se.prototype.not=function(){for(var e=Ee(),t=0;t<this.t;++t)e.data[t]=this.DM&~this.data[t];return e.t=this.t,e.s=~this.s,e},Se.prototype.shiftLeft=function(e){var t=Ee();return e<0?this.rShiftTo(-e,t):this.lShiftTo(e,t),t},Se.prototype.shiftRight=function(e){var t=Ee();return e<0?this.lShiftTo(-e,t):this.rShiftTo(e,t),t},Se.prototype.getLowestSetBit=function(){for(var e=0;e<this.t;++e)if(0!=this.data[e])return e*this.DB+Ve(this.data[e]);return this.s<0?this.t*this.DB:-1},Se.prototype.bitCount=function(){for(var e=0,t=this.s&this.DM,n=0;n<this.t;++n)e+=ze(this.data[n]^t);return e},Se.prototype.testBit=function(e){var t=Math.floor(e/this.DB);return t>=this.t?0!=this.s:0!=(this.data[t]&1<<e%this.DB)},Se.prototype.setBit=function(e){return this.changeBit(e,Pe)},Se.prototype.clearBit=function(e){return this.changeBit(e,Ue)},Se.prototype.flipBit=function(e){return this.changeBit(e,Le)},Se.prototype.add=function(e){var t=Ee();return this.addTo(e,t),t},Se.prototype.subtract=function(e){var t=Ee();return this.subTo(e,t),t},Se.prototype.multiply=function(e){var t=Ee();return this.multiplyTo(e,t),t},Se.prototype.divide=function(e){var t=Ee();return this.divRemTo(e,t,null),t},Se.prototype.remainder=function(e){var t=Ee();return this.divRemTo(e,null,t),t},Se.prototype.divideAndRemainder=function(e){var t=Ee(),n=Ee();return this.divRemTo(e,t,n),new Array(t,n)},Se.prototype.modPow=function(e,t){var n,r,a=e.bitLength(),o=Oe(1);if(a<=0)return o;n=a<18?1:a<48?3:a<144?4:a<768?5:6,r=a<8?new De(t):t.isEven()?new He(t):new Me(t);var i=new Array,s=3,u=n-1,c=(1<<n)-1;if(i[1]=r.convert(this),n>1){var l=Ee();for(r.sqrTo(i[1],l);s<=c;)i[s]=Ee(),r.mulTo(l,i[s-2],i[s]),s+=2}var p,d,f=e.t-1,h=!0,m=Ee();for(a=Be(e.data[f])-1;f>=0;){for(a>=u?p=e.data[f]>>a-u&c:(p=(e.data[f]&(1<<a+1)-1)<<u-a,f>0&&(p|=e.data[f-1]>>this.DB+a-u)),s=n;0==(1&p);)p>>=1,--s;if((a-=s)<0&&(a+=this.DB,--f),h)i[p].copyTo(o),h=!1;else{for(;s>1;)r.sqrTo(o,m),r.sqrTo(m,o),s-=2;s>0?r.sqrTo(o,m):(d=o,o=m,m=d),r.mulTo(m,i[p],o)}for(;f>=0&&0==(e.data[f]&1<<a);)r.sqrTo(o,m),d=o,o=m,m=d,--a<0&&(a=this.DB-1,--f)}return r.revert(o)},Se.prototype.modInverse=function(e){var t=e.isEven();if(this.isEven()&&t||0==e.signum())return Se.ZERO;for(var n=e.clone(),r=this.clone(),a=Oe(1),o=Oe(0),i=Oe(0),s=Oe(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),t?(a.isEven()&&o.isEven()||(a.addTo(this,a),o.subTo(e,o)),a.rShiftTo(1,a)):o.isEven()||o.subTo(e,o),o.rShiftTo(1,o);for(;r.isEven();)r.rShiftTo(1,r),t?(i.isEven()&&s.isEven()||(i.addTo(this,i),s.subTo(e,s)),i.rShiftTo(1,i)):s.isEven()||s.subTo(e,s),s.rShiftTo(1,s);n.compareTo(r)>=0?(n.subTo(r,n),t&&a.subTo(i,a),o.subTo(s,o)):(r.subTo(n,r),t&&i.subTo(a,i),s.subTo(o,s))}return 0!=r.compareTo(Se.ONE)?Se.ZERO:s.compareTo(e)>=0?s.subtract(e):s.signum()<0?(s.addTo(e,s),s.signum()<0?s.add(e):s):s},Se.prototype.pow=function(e){return this.exp(e,new je)},Se.prototype.gcd=function(e){var t=this.s<0?this.negate():this.clone(),n=e.s<0?e.negate():e.clone();if(t.compareTo(n)<0){var r=t;t=n,n=r}var a=t.getLowestSetBit(),o=n.getLowestSetBit();if(o<0)return t;for(a<o&&(o=a),o>0&&(t.rShiftTo(o,t),n.rShiftTo(o,n));t.signum()>0;)(a=t.getLowestSetBit())>0&&t.rShiftTo(a,t),(a=n.getLowestSetBit())>0&&n.rShiftTo(a,n),t.compareTo(n)>=0?(t.subTo(n,t),t.rShiftTo(1,t)):(n.subTo(t,n),n.rShiftTo(1,n));return o>0&&n.lShiftTo(o,n),n},Se.prototype.isProbablePrime=function(e){var t,n=this.abs();if(1==n.t&&n.data[0]<=Ge[Ge.length-1]){for(t=0;t<Ge.length;++t)if(n.data[0]==Ge[t])return!0;return!1}if(n.isEven())return!1;for(t=1;t<Ge.length;){for(var r=Ge[t],a=t+1;a<Ge.length&&r<Ke;)r*=Ge[a++];for(r=n.modInt(r);t<a;)if(r%Ge[t++]==0)return!1}return n.millerRabin(e)},w((function(e){var t=e.exports=z.sha1=z.sha1||{};z.md.sha1=z.md.algorithms.sha1=t,t.create=function(){r||(n=String.fromCharCode(128),n+=z.util.fillString(String.fromCharCode(0),64),r=!0);var e=null,t=z.util.createBuffer(),o=new Array(80),i={algorithm:"sha1",blockLength:64,digestLength:20,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){i.messageLength=0,i.fullMessageLength=i.messageLength64=[];for(var n=i.messageLengthSize/4,r=0;r<n;++r)i.fullMessageLength.push(0);return t=z.util.createBuffer(),e={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878,h4:3285377520},i}};return i.start(),i.update=function(n,r){"utf8"===r&&(n=z.util.encodeUtf8(n));var s=n.length;i.messageLength+=s,s=[s/4294967296>>>0,s>>>0];for(var u=i.fullMessageLength.length-1;u>=0;--u)i.fullMessageLength[u]+=s[1],s[1]=s[0]+(i.fullMessageLength[u]/4294967296>>>0),i.fullMessageLength[u]=i.fullMessageLength[u]>>>0,s[0]=s[1]/4294967296>>>0;return t.putBytes(n),a(e,o,t),(t.read>2048||0===t.length())&&t.compact(),i},i.digest=function(){var r=z.util.createBuffer();r.putBytes(t.bytes());var s,u=i.fullMessageLength[i.fullMessageLength.length-1]+i.messageLengthSize&i.blockLength-1;r.putBytes(n.substr(0,i.blockLength-u));for(var c=8*i.fullMessageLength[0],l=0;l<i.fullMessageLength.length-1;++l)c+=(s=8*i.fullMessageLength[l+1])/4294967296>>>0,r.putInt32(c>>>0),c=s>>>0;r.putInt32(c);var p={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4};a(p,o,r);var d=z.util.createBuffer();return d.putInt32(p.h0),d.putInt32(p.h1),d.putInt32(p.h2),d.putInt32(p.h3),d.putInt32(p.h4),d},i};var n=null,r=!1;function a(e,t,n){for(var r,a,o,i,s,u,c,l=n.length();l>=64;){for(a=e.h0,o=e.h1,i=e.h2,s=e.h3,u=e.h4,c=0;c<16;++c)r=n.getInt32(),t[c]=r,r=(a<<5|a>>>27)+(s^o&(i^s))+u+1518500249+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<20;++c)r=(r=t[c-3]^t[c-8]^t[c-14]^t[c-16])<<1|r>>>31,t[c]=r,r=(a<<5|a>>>27)+(s^o&(i^s))+u+1518500249+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<32;++c)r=(r=t[c-3]^t[c-8]^t[c-14]^t[c-16])<<1|r>>>31,t[c]=r,r=(a<<5|a>>>27)+(o^i^s)+u+1859775393+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<40;++c)r=(r=t[c-6]^t[c-16]^t[c-28]^t[c-32])<<2|r>>>30,t[c]=r,r=(a<<5|a>>>27)+(o^i^s)+u+1859775393+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<60;++c)r=(r=t[c-6]^t[c-16]^t[c-28]^t[c-32])<<2|r>>>30,t[c]=r,r=(a<<5|a>>>27)+(o&i|s&(o^i))+u+2400959708+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;for(;c<80;++c)r=(r=t[c-6]^t[c-16]^t[c-28]^t[c-32])<<2|r>>>30,t[c]=r,r=(a<<5|a>>>27)+(o^i^s)+u+3395469782+r,u=s,s=i,i=(o<<30|o>>>2)>>>0,o=a,a=r;e.h0=e.h0+a|0,e.h1=e.h1+o|0,e.h2=e.h2+i|0,e.h3=e.h3+s|0,e.h4=e.h4+u|0,l-=64}}})),w((function(e){var t=e.exports=z.pkcs1=z.pkcs1||{};function n(e,t,n){n||(n=z.md.sha1.create());for(var r="",a=Math.ceil(t/n.digestLength),o=0;o<a;++o){var i=String.fromCharCode(o>>24&255,o>>16&255,o>>8&255,255&o);n.start(),n.update(e+i),r+=n.digest().getBytes()}return r.substring(0,t)}t.encode_rsa_oaep=function(e,t,r){var a,o,i,s;"string"==typeof r?(a=r,o=arguments[3]||void 0,i=arguments[4]||void 0):r&&(a=r.label||void 0,o=r.seed||void 0,i=r.md||void 0,r.mgf1&&r.mgf1.md&&(s=r.mgf1.md)),i?i.start():i=z.md.sha1.create(),s||(s=i);var u=Math.ceil(e.n.bitLength()/8),c=u-2*i.digestLength-2;if(t.length>c)throw(h=new Error("RSAES-OAEP input message length is too long.")).length=t.length,h.maxLength=c,h;a||(a=""),i.update(a,"raw");for(var l=i.digest(),p="",d=c-t.length,f=0;f<d;f++)p+="\0";var h,m=l.getBytes()+p+""+t;if(o){if(o.length!==i.digestLength)throw(h=new Error("Invalid RSAES-OAEP seed. The seed length must match the digest length.")).seedLength=o.length,h.digestLength=i.digestLength,h}else o=z.random.getBytes(i.digestLength);var g=n(o,u-i.digestLength-1,s),v=z.util.xorBytes(m,g,m.length),y=n(v,i.digestLength,s);return"\0"+z.util.xorBytes(o,y,o.length)+v},t.decode_rsa_oaep=function(e,t,r){var a,o,i;"string"==typeof r?(a=r,o=arguments[3]||void 0):r&&(a=r.label||void 0,o=r.md||void 0,r.mgf1&&r.mgf1.md&&(i=r.mgf1.md));var s=Math.ceil(e.n.bitLength()/8);if(t.length!==s)throw(g=new Error("RSAES-OAEP encoded message length is invalid.")).length=t.length,g.expectedLength=s,g;if(void 0===o?o=z.md.sha1.create():o.start(),i||(i=o),s<2*o.digestLength+2)throw new Error("RSAES-OAEP key is too short for the hash function.");a||(a=""),o.update(a,"raw");for(var u=o.digest().getBytes(),c=t.charAt(0),l=t.substring(1,o.digestLength+1),p=t.substring(1+o.digestLength),d=n(p,o.digestLength,i),f=n(z.util.xorBytes(l,d,l.length),s-o.digestLength-1,i),h=z.util.xorBytes(p,f,p.length),m=h.substring(0,o.digestLength),g="\0"!==c,v=0;v<o.digestLength;++v)g|=u.charAt(v)!==m.charAt(v);for(var y=1,b=o.digestLength,x=o.digestLength;x<h.length;x++){var w=h.charCodeAt(x);g|=w&(y?65534:0),b+=y&=1&w^1}if(g||1!==h.charCodeAt(b))throw new Error("Invalid RSAES-OAEP padding.");return h.substring(b+1)}})),w((function(e){!function(){if(z.prime)e.exports=z.prime;else{var t=e.exports=z.prime=z.prime||{},n=z.jsbn.BigInteger,r=[6,4,2,4,2,4,6,2],a=new n(null);a.fromInt(30);var o=function(e,t){return e|t};t.generateProbablePrime=function(e,t,r){"function"==typeof t&&(r=t,t={});var a=(t=t||{}).algorithm||"PRIMEINC";"string"==typeof a&&(a={name:a}),a.options=a.options||{};var o=t.prng||z.random,u={nextBytes:function(e){for(var t=o.getBytesSync(e.length),n=0;n<e.length;++n)e[n]=t.charCodeAt(n)}};if("PRIMEINC"===a.name)return function(e,t,r,a){return"workers"in r?function(e,t,r,a){if("undefined"==typeof Worker)return i(e,t,r,a);var o=s(e,t),u=r.workers,c=r.workLoad||100,l=30*c/8,p=r.workerScript||"forge/prime.worker.js";if(-1===u)return z.util.estimateCores((function(e,t){e&&(t=2),u=t-1,d()}));function d(){u=Math.max(1,u);for(var r=[],i=0;i<u;++i)r[i]=new Worker(p);for(i=0;i<u;++i)r[i].addEventListener("message",f);var d=!1;function f(i){if(!d){var u=i.data;if(u.found){for(var p=0;p<r.length;++p)r[p].terminate();return d=!0,a(null,new n(u.prime,16))}o.bitLength()>e&&(o=s(e,t));var f=o.toString(16);i.target.postMessage({hex:f,workLoad:c}),o.dAddOffset(l,0)}}}d()}(e,t,r,a):i(e,t,r,a)}(e,u,a.options,r);throw new Error("Invalid prime generation algorithm: "+a.name)}}function i(e,t,n,a){var o=s(e,t),i=function(e){return e<=100?27:e<=150?18:e<=200?15:e<=250?12:e<=300?9:e<=350?8:e<=400?7:e<=500?6:e<=600?5:e<=800?4:e<=1250?3:2}(o.bitLength());"millerRabinTests"in n&&(i=n.millerRabinTests);var u=10;"maxBlockTime"in n&&(u=n.maxBlockTime),function e(t,n,a,o,i,u,c){var l=+new Date;do{if(t.bitLength()>n&&(t=s(n,a)),t.isProbablePrime(i))return c(null,t);t.dAddOffset(r[o++%8],0)}while(u<0||+new Date-l<u);z.util.setImmediate((function(){e(t,n,a,o,i,u,c)}))}(o,e,t,0,i,u,a)}function s(e,t){var r=new n(e,t),i=e-1;return r.testBit(i)||r.bitwiseTo(n.ONE.shiftLeft(i),o,r),r.dAddOffset(31-r.mod(a).byteValue(),0),r}}()})),void 0===qe)var qe=z.jsbn.BigInteger;var Qe=z.util.isNodejs?t:null,Xe=z.asn1,Ye=z.util;z.pki=z.pki||{},z.pki.rsa=z.rsa=z.rsa||{};var $e=z.pki,Ze=[6,4,2,4,2,4,6,2],Je={name:"PrivateKeyInfo",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"PrivateKeyInfo.version",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.privateKeyAlgorithm",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.OID,constructed:!1,capture:"privateKeyOid"}]},{name:"PrivateKeyInfo",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.OCTETSTRING,constructed:!1,capture:"privateKey"}]},et={name:"RSAPrivateKey",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPrivateKey.version",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"privateKeyCoefficient"}]},tt={name:"RSAPublicKey",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPublicKey.modulus",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.INTEGER,constructed:!1,capture:"publicKeyExponent"}]},nt=z.pki.rsa.publicKeyValidator={name:"SubjectPublicKeyInfo",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{name:"SubjectPublicKeyInfo.subjectPublicKey",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.BITSTRING,constructed:!1,value:[{name:"SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey",tagClass:Xe.Class.UNIVERSAL,type:Xe.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"rsaPublicKey"}]}]},rt=function(e){var t;if(!(e.algorithm in $e.oids)){var n=new Error("Unknown message digest algorithm.");throw n.algorithm=e.algorithm,n}t=$e.oids[e.algorithm];var r=Xe.oidToDer(t).getBytes(),a=Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[]),o=Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[]);o.value.push(Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OID,!1,r)),o.value.push(Xe.create(Xe.Class.UNIVERSAL,Xe.Type.NULL,!1,""));var i=Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OCTETSTRING,!1,e.digest().getBytes());return a.value.push(o),a.value.push(i),Xe.toDer(a).getBytes()},at=function(e,t,n){if(n)return e.modPow(t.e,t.n);if(!t.p||!t.q)return e.modPow(t.d,t.n);var r;t.dP||(t.dP=t.d.mod(t.p.subtract(qe.ONE))),t.dQ||(t.dQ=t.d.mod(t.q.subtract(qe.ONE))),t.qInv||(t.qInv=t.q.modInverse(t.p));do{r=new qe(z.util.bytesToHex(z.random.getBytes(t.n.bitLength()/8)),16)}while(r.compareTo(t.n)>=0||!r.gcd(t.n).equals(qe.ONE));for(var a=(e=e.multiply(r.modPow(t.e,t.n)).mod(t.n)).mod(t.p).modPow(t.dP,t.p),o=e.mod(t.q).modPow(t.dQ,t.q);a.compareTo(o)<0;)a=a.add(t.p);var i=a.subtract(o).multiply(t.qInv).mod(t.p).multiply(t.q).add(o);return i.multiply(r.modInverse(t.n)).mod(t.n)};function ot(e,t,n){var r=z.util.createBuffer(),a=Math.ceil(t.n.bitLength()/8);if(e.length>a-11){var o=new Error("Message is too long for PKCS#1 v1.5 padding.");throw o.length=e.length,o.max=a-11,o}r.putByte(0),r.putByte(n);var i,s=a-3-e.length;if(0===n||1===n){i=0===n?0:255;for(var u=0;u<s;++u)r.putByte(i)}else for(;s>0;){var c=0,l=z.random.getBytes(s);for(u=0;u<s;++u)0===(i=l.charCodeAt(u))?++c:r.putByte(i);s=c}return r.putByte(0),r.putBytes(e),r}function it(e,t,n,r){var a=Math.ceil(t.n.bitLength()/8),o=z.util.createBuffer(e),i=o.getByte(),s=o.getByte();if(0!==i||n&&0!==s&&1!==s||!n&&2!=s||n&&0===s&&void 0===r)throw new Error("Encryption block is invalid.");var u=0;if(0===s){u=a-3-r;for(var c=0;c<u;++c)if(0!==o.getByte())throw new Error("Encryption block is invalid.")}else if(1===s)for(u=0;o.length()>1;){if(255!==o.getByte()){--o.read;break}++u}else if(2===s)for(u=0;o.length()>1;){if(0===o.getByte()){--o.read;break}++u}if(0!==o.getByte()||u!==a-3-o.length())throw new Error("Encryption block is invalid.");return o.getBytes()}function st(e,t,n){"function"==typeof t&&(n=t,t={});var r={algorithm:{name:(t=t||{}).algorithm||"PRIMEINC",options:{workers:t.workers||2,workLoad:t.workLoad||100,workerScript:t.workerScript}}};function a(){o(e.pBits,(function(t,r){return t?n(t):(e.p=r,null!==e.q?i(t,e.q):void o(e.qBits,i))}))}function o(e,t){z.prime.generateProbablePrime(e,r,t)}function i(t,r){if(t)return n(t);if(e.q=r,e.p.compareTo(e.q)<0){var s=e.p;e.p=e.q,e.q=s}if(0!==e.p.subtract(qe.ONE).gcd(e.e).compareTo(qe.ONE))return e.p=null,void a();if(0!==e.q.subtract(qe.ONE).gcd(e.e).compareTo(qe.ONE))return e.q=null,void o(e.qBits,i);if(e.p1=e.p.subtract(qe.ONE),e.q1=e.q.subtract(qe.ONE),e.phi=e.p1.multiply(e.q1),0!==e.phi.gcd(e.e).compareTo(qe.ONE))return e.p=e.q=null,void a();if(e.n=e.p.multiply(e.q),e.n.bitLength()!==e.bits)return e.q=null,void o(e.qBits,i);var u=e.e.modInverse(e.phi);e.keys={privateKey:$e.rsa.setPrivateKey(e.n,e.e,u,e.p,e.q,u.mod(e.p1),u.mod(e.q1),e.q.modInverse(e.p)),publicKey:$e.rsa.setPublicKey(e.n,e.e)},n(null,e.keys)}"prng"in t&&(r.prng=t.prng),a()}function ut(e){var t=e.toString(16);t[0]>="8"&&(t="00"+t);var n=z.util.hexToBytes(t);return n.length>1&&(0===n.charCodeAt(0)&&0==(128&n.charCodeAt(1))||255===n.charCodeAt(0)&&128==(128&n.charCodeAt(1)))?n.substr(1):n}function ct(e){return e<=100?27:e<=150?18:e<=200?15:e<=250?12:e<=300?9:e<=350?8:e<=400?7:e<=500?6:e<=600?5:e<=800?4:e<=1250?3:2}function lt(e){return z.util.isNodejs&&"function"==typeof Qe[e]}function pt(e){return void 0!==Ye.globalScope&&"object"==typeof Ye.globalScope.crypto&&"object"==typeof Ye.globalScope.crypto.subtle&&"function"==typeof Ye.globalScope.crypto.subtle[e]}function dt(e){return void 0!==Ye.globalScope&&"object"==typeof Ye.globalScope.msCrypto&&"object"==typeof Ye.globalScope.msCrypto.subtle&&"function"==typeof Ye.globalScope.msCrypto.subtle[e]}function ft(e){for(var t=z.util.hexToBytes(e.toString(16)),n=new Uint8Array(t.length),r=0;r<t.length;++r)n[r]=t.charCodeAt(r);return n}if($e.rsa.encrypt=function(e,t,n){var r,a=n,o=Math.ceil(t.n.bitLength()/8);!1!==n&&!0!==n?(a=2===n,r=ot(e,t,n)):(r=z.util.createBuffer()).putBytes(e);for(var i=new qe(r.toHex(),16),s=at(i,t,a).toString(16),u=z.util.createBuffer(),c=o-Math.ceil(s.length/2);c>0;)u.putByte(0),--c;return u.putBytes(z.util.hexToBytes(s)),u.getBytes()},$e.rsa.decrypt=function(e,t,n,r){var a=Math.ceil(t.n.bitLength()/8);if(e.length!==a){var o=new Error("Encrypted message length is invalid.");throw o.length=e.length,o.expected=a,o}var i=new qe(z.util.createBuffer(e).toHex(),16);if(i.compareTo(t.n)>=0)throw new Error("Encrypted message is invalid.");for(var s=at(i,t,n).toString(16),u=z.util.createBuffer(),c=a-Math.ceil(s.length/2);c>0;)u.putByte(0),--c;return u.putBytes(z.util.hexToBytes(s)),!1!==r?it(u.getBytes(),t,n):u.getBytes()},$e.rsa.createKeyPairGenerationState=function(e,t,n){"string"==typeof e&&(e=parseInt(e,10)),e=e||2048;var r,a=(n=n||{}).prng||z.random,o={nextBytes:function(e){for(var t=a.getBytesSync(e.length),n=0;n<e.length;++n)e[n]=t.charCodeAt(n)}},i=n.algorithm||"PRIMEINC";if("PRIMEINC"!==i)throw new Error("Invalid key generation algorithm: "+i);return(r={algorithm:i,state:0,bits:e,rng:o,eInt:t||65537,e:new qe(null),p:null,q:null,qBits:e>>1,pBits:e-(e>>1),pqState:0,num:null,keys:null}).e.fromInt(r.eInt),r},$e.rsa.stepKeyPairGenerationState=function(e,t){"algorithm"in e||(e.algorithm="PRIMEINC");var n=new qe(null);n.fromInt(30);for(var r,a=0,o=function(e,t){return e|t},i=+new Date,s=0;null===e.keys&&(t<=0||s<t);){if(0===e.state){var u=null===e.p?e.pBits:e.qBits,c=u-1;0===e.pqState?(e.num=new qe(u,e.rng),e.num.testBit(c)||e.num.bitwiseTo(qe.ONE.shiftLeft(c),o,e.num),e.num.dAddOffset(31-e.num.mod(n).byteValue(),0),a=0,++e.pqState):1===e.pqState?e.num.bitLength()>u?e.pqState=0:e.num.isProbablePrime(ct(e.num.bitLength()))?++e.pqState:e.num.dAddOffset(Ze[a++%8],0):2===e.pqState?e.pqState=0===e.num.subtract(qe.ONE).gcd(e.e).compareTo(qe.ONE)?3:0:3===e.pqState&&(e.pqState=0,null===e.p?e.p=e.num:e.q=e.num,null!==e.p&&null!==e.q&&++e.state,e.num=null)}else if(1===e.state)e.p.compareTo(e.q)<0&&(e.num=e.p,e.p=e.q,e.q=e.num),++e.state;else if(2===e.state)e.p1=e.p.subtract(qe.ONE),e.q1=e.q.subtract(qe.ONE),e.phi=e.p1.multiply(e.q1),++e.state;else if(3===e.state)0===e.phi.gcd(e.e).compareTo(qe.ONE)?++e.state:(e.p=null,e.q=null,e.state=0);else if(4===e.state)e.n=e.p.multiply(e.q),e.n.bitLength()===e.bits?++e.state:(e.q=null,e.state=0);else if(5===e.state){var l=e.e.modInverse(e.phi);e.keys={privateKey:$e.rsa.setPrivateKey(e.n,e.e,l,e.p,e.q,l.mod(e.p1),l.mod(e.q1),e.q.modInverse(e.p)),publicKey:$e.rsa.setPublicKey(e.n,e.e)}}s+=(r=+new Date)-i,i=r}return null!==e.keys},$e.rsa.generateKeyPair=function(e,t,n,r){if(1===arguments.length?"object"==typeof e?(n=e,e=void 0):"function"==typeof e&&(r=e,e=void 0):2===arguments.length?"number"==typeof e?"function"==typeof t?(r=t,t=void 0):"number"!=typeof t&&(n=t,t=void 0):(n=e,r=t,e=void 0,t=void 0):3===arguments.length&&("number"==typeof t?"function"==typeof n&&(r=n,n=void 0):(r=n,n=t,t=void 0)),n=n||{},void 0===e&&(e=n.bits||2048),void 0===t&&(t=n.e||65537),!n.prng&&e>=256&&e<=16384&&(65537===t||3===t))if(r){if(lt("generateKeyPair"))return Qe.generateKeyPair("rsa",{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}},(function(e,t,n){if(e)return r(e);r(null,{privateKey:$e.privateKeyFromPem(n),publicKey:$e.publicKeyFromPem(t)})}));if(pt("generateKey")&&pt("exportKey"))return Ye.globalScope.crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:ft(t),hash:{name:"SHA-256"}},!0,["sign","verify"]).then((function(e){return Ye.globalScope.crypto.subtle.exportKey("pkcs8",e.privateKey)})).then(void 0,(function(e){r(e)})).then((function(e){if(e){var t=$e.privateKeyFromAsn1(Xe.fromDer(z.util.createBuffer(e)));r(null,{privateKey:t,publicKey:$e.setRsaPublicKey(t.n,t.e)})}}));if(dt("generateKey")&&dt("exportKey")){var a=Ye.globalScope.msCrypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:ft(t),hash:{name:"SHA-256"}},!0,["sign","verify"]);return a.oncomplete=function(e){var t=e.target.result,n=Ye.globalScope.msCrypto.subtle.exportKey("pkcs8",t.privateKey);n.oncomplete=function(e){var t=e.target.result,n=$e.privateKeyFromAsn1(Xe.fromDer(z.util.createBuffer(t)));r(null,{privateKey:n,publicKey:$e.setRsaPublicKey(n.n,n.e)})},n.onerror=function(e){r(e)}},void(a.onerror=function(e){r(e)})}}else if(lt("generateKeyPairSync")){var o=Qe.generateKeyPairSync("rsa",{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:$e.privateKeyFromPem(o.privateKey),publicKey:$e.publicKeyFromPem(o.publicKey)}}var i=$e.rsa.createKeyPairGenerationState(e,t,n);if(!r)return $e.rsa.stepKeyPairGenerationState(i,0),i.keys;st(i,n,r)},$e.setRsaPublicKey=$e.rsa.setPublicKey=function(e,t){var n={n:e,e:t,encrypt:function(e,t,r){if("string"==typeof t?t=t.toUpperCase():void 0===t&&(t="RSAES-PKCS1-V1_5"),"RSAES-PKCS1-V1_5"===t)t={encode:function(e,t,n){return ot(e,t,2).getBytes()}};else if("RSA-OAEP"===t||"RSAES-OAEP"===t)t={encode:function(e,t){return z.pkcs1.encode_rsa_oaep(t,e,r)}};else if(-1!==["RAW","NONE","NULL",null].indexOf(t))t={encode:function(e){return e}};else if("string"==typeof t)throw new Error('Unsupported encryption scheme: "'+t+'".');var a=t.encode(e,n,!0);return $e.rsa.encrypt(a,n,!0)},verify:function(e,t,r){"string"==typeof r?r=r.toUpperCase():void 0===r&&(r="RSASSA-PKCS1-V1_5"),"RSASSA-PKCS1-V1_5"===r?r={verify:function(e,t){return t=it(t,n,!0),e===Xe.fromDer(t).value[1].value}}:"NONE"!==r&&"NULL"!==r&&null!==r||(r={verify:function(e,t){return e===it(t,n,!0)}});var a=$e.rsa.decrypt(t,n,!0,!1);return r.verify(e,a,n.n.bitLength())}};return n},$e.setRsaPrivateKey=$e.rsa.setPrivateKey=function(e,t,n,r,a,o,i,s){var u={n:e,e:t,d:n,p:r,q:a,dP:o,dQ:i,qInv:s,decrypt:function(e,t,n){"string"==typeof t?t=t.toUpperCase():void 0===t&&(t="RSAES-PKCS1-V1_5");var r=$e.rsa.decrypt(e,u,!1,!1);if("RSAES-PKCS1-V1_5"===t)t={decode:it};else if("RSA-OAEP"===t||"RSAES-OAEP"===t)t={decode:function(e,t){return z.pkcs1.decode_rsa_oaep(t,e,n)}};else{if(-1===["RAW","NONE","NULL",null].indexOf(t))throw new Error('Unsupported encryption scheme: "'+t+'".');t={decode:function(e){return e}}}return t.decode(r,u,!1)},sign:function(e,t){var n=!1;"string"==typeof t&&(t=t.toUpperCase()),void 0===t||"RSASSA-PKCS1-V1_5"===t?(t={encode:rt},n=1):"NONE"!==t&&"NULL"!==t&&null!==t||(t={encode:function(){return e}},n=1);var r=t.encode(e,u.n.bitLength());return $e.rsa.encrypt(r,u,n)}};return u},$e.wrapRsaPrivateKey=function(e){return Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,Xe.integerToDer(0).getBytes()),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OID,!1,Xe.oidToDer($e.oids.rsaEncryption).getBytes()),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.NULL,!1,"")]),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OCTETSTRING,!1,Xe.toDer(e).getBytes())])},$e.privateKeyFromAsn1=function(e){var t,n,r,a,o,i,s,u,c={},l=[];if(Xe.validate(e,Je,c,l)&&(e=Xe.fromDer(z.util.createBuffer(c.privateKey))),c={},l=[],!Xe.validate(e,et,c,l)){var p=new Error("Cannot read private key. ASN.1 object does not contain an RSAPrivateKey.");throw p.errors=l,p}return t=z.util.createBuffer(c.privateKeyModulus).toHex(),n=z.util.createBuffer(c.privateKeyPublicExponent).toHex(),r=z.util.createBuffer(c.privateKeyPrivateExponent).toHex(),a=z.util.createBuffer(c.privateKeyPrime1).toHex(),o=z.util.createBuffer(c.privateKeyPrime2).toHex(),i=z.util.createBuffer(c.privateKeyExponent1).toHex(),s=z.util.createBuffer(c.privateKeyExponent2).toHex(),u=z.util.createBuffer(c.privateKeyCoefficient).toHex(),$e.setRsaPrivateKey(new qe(t,16),new qe(n,16),new qe(r,16),new qe(a,16),new qe(o,16),new qe(i,16),new qe(s,16),new qe(u,16))},$e.privateKeyToAsn1=$e.privateKeyToRSAPrivateKey=function(e){return Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,Xe.integerToDer(0).getBytes()),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.n)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.e)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.d)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.p)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.q)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.dP)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.dQ)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.qInv))])},$e.publicKeyFromAsn1=function(e){var t={},n=[];if(Xe.validate(e,nt,t,n)){var r,a=Xe.derToOid(t.publicKeyOid);if(a!==$e.oids.rsaEncryption)throw(r=new Error("Cannot read public key. Unknown OID.")).oid=a,r;e=t.rsaPublicKey}if(n=[],!Xe.validate(e,tt,t,n))throw(r=new Error("Cannot read public key. ASN.1 object does not contain an RSAPublicKey.")).errors=n,r;var o=z.util.createBuffer(t.publicKeyModulus).toHex(),i=z.util.createBuffer(t.publicKeyExponent).toHex();return $e.setRsaPublicKey(new qe(o,16),new qe(i,16))},$e.publicKeyToAsn1=$e.publicKeyToSubjectPublicKeyInfo=function(e){return Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.OID,!1,Xe.oidToDer($e.oids.rsaEncryption).getBytes()),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.NULL,!1,"")]),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.BITSTRING,!1,[$e.publicKeyToRSAPublicKey(e)])])},$e.publicKeyToRSAPublicKey=function(e){return Xe.create(Xe.Class.UNIVERSAL,Xe.Type.SEQUENCE,!0,[Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.n)),Xe.create(Xe.Class.UNIVERSAL,Xe.Type.INTEGER,!1,ut(e.e))])},void 0===ht)var ht=z.jsbn.BigInteger;var mt=z.asn1,gt=z.pki=z.pki||{},vt=(gt.pbe=z.pbe=z.pbe||{},gt.oids),yt={name:"EncryptedPrivateKeyInfo",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedPrivateKeyInfo.encryptionAlgorithm",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OID,constructed:!1,capture:"encryptionOid"},{name:"AlgorithmIdentifier.parameters",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,captureAsn1:"encryptionParams"}]},{name:"EncryptedPrivateKeyInfo.encryptedData",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OCTETSTRING,constructed:!1,capture:"encryptedData"}]},bt={name:"PBES2Algorithms",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc.oid",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OID,constructed:!1,capture:"kdfOid"},{name:"PBES2Algorithms.params",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.params.salt",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OCTETSTRING,constructed:!1,capture:"kdfSalt"},{name:"PBES2Algorithms.params.iterationCount",tagClass:mt.Class.UNIVERSAL,type:mt.Type.INTEGER,constructed:!1,capture:"kdfIterationCount"},{name:"PBES2Algorithms.params.keyLength",tagClass:mt.Class.UNIVERSAL,type:mt.Type.INTEGER,constructed:!1,optional:!0,capture:"keyLength"},{name:"PBES2Algorithms.params.prf",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,optional:!0,value:[{name:"PBES2Algorithms.params.prf.algorithm",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OID,constructed:!1,capture:"prfOid"}]}]}]},{name:"PBES2Algorithms.encryptionScheme",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.encryptionScheme.oid",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OID,constructed:!1,capture:"encOid"},{name:"PBES2Algorithms.encryptionScheme.iv",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OCTETSTRING,constructed:!1,capture:"encIv"}]}]},xt={name:"pkcs-12PbeParams",tagClass:mt.Class.UNIVERSAL,type:mt.Type.SEQUENCE,constructed:!0,value:[{name:"pkcs-12PbeParams.salt",tagClass:mt.Class.UNIVERSAL,type:mt.Type.OCTETSTRING,constructed:!1,capture:"salt"},{name:"pkcs-12PbeParams.iterations",tagClass:mt.Class.UNIVERSAL,type:mt.Type.INTEGER,constructed:!1,capture:"iterations"}]};function wt(e,t){return e.start().update(t).digest().getBytes()}function kt(e){var t;if(e){if(!(t=gt.oids[mt.derToOid(e)])){var n=new Error("Unsupported PRF OID.");throw n.oid=e,n.supported=["hmacWithSHA1","hmacWithSHA224","hmacWithSHA256","hmacWithSHA384","hmacWithSHA512"],n}}else t="hmacWithSHA1";return St(t)}function St(e){var t=z.md;switch(e){case"hmacWithSHA224":t=z.md.sha512;case"hmacWithSHA1":case"hmacWithSHA256":case"hmacWithSHA384":case"hmacWithSHA512":e=e.substr(8).toLowerCase();break;default:var n=new Error("Unsupported PRF algorithm.");throw n.algorithm=e,n.supported=["hmacWithSHA1","hmacWithSHA224","hmacWithSHA256","hmacWithSHA384","hmacWithSHA512"],n}if(!t||!(e in t))throw new Error("Unknown hash algorithm: "+e);return t[e].create()}gt.encryptPrivateKeyInfo=function(e,t,n){(n=n||{}).saltSize=n.saltSize||8,n.count=n.count||2048,n.algorithm=n.algorithm||"aes128",n.prfAlgorithm=n.prfAlgorithm||"sha1";var r,a,o,i=z.random.getBytesSync(n.saltSize),s=n.count,u=mt.integerToDer(s);if(0===n.algorithm.indexOf("aes")||"des"===n.algorithm){var c,l,p;switch(n.algorithm){case"aes128":r=16,c=16,l=vt["aes128-CBC"],p=z.aes.createEncryptionCipher;break;case"aes192":r=24,c=16,l=vt["aes192-CBC"],p=z.aes.createEncryptionCipher;break;case"aes256":r=32,c=16,l=vt["aes256-CBC"],p=z.aes.createEncryptionCipher;break;case"des":r=8,c=8,l=vt.desCBC,p=z.des.createEncryptionCipher;break;default:throw(v=new Error("Cannot encrypt private key. Unknown encryption algorithm.")).algorithm=n.algorithm,v}var d="hmacWith"+n.prfAlgorithm.toUpperCase(),f=St(d),h=z.pkcs5.pbkdf2(t,i,s,r,f),m=z.random.getBytesSync(c);(y=p(h)).start(m),y.update(mt.toDer(e)),y.finish(),o=y.output.getBytes();var g=function(e,t,n,r){var a=mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OCTETSTRING,!1,e),mt.create(mt.Class.UNIVERSAL,mt.Type.INTEGER,!1,t.getBytes())]);return"hmacWithSHA1"!==r&&a.value.push(mt.create(mt.Class.UNIVERSAL,mt.Type.INTEGER,!1,z.util.hexToBytes(n.toString(16))),mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(gt.oids[r]).getBytes()),mt.create(mt.Class.UNIVERSAL,mt.Type.NULL,!1,"")])),a}(i,u,r,d);a=mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(vt.pkcs5PBES2).getBytes()),mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(vt.pkcs5PBKDF2).getBytes()),g]),mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(l).getBytes()),mt.create(mt.Class.UNIVERSAL,mt.Type.OCTETSTRING,!1,m)])])])}else{var v;if("3des"!==n.algorithm)throw(v=new Error("Cannot encrypt private key. Unknown encryption algorithm.")).algorithm=n.algorithm,v;r=24;var y,b=new z.util.ByteBuffer(i);h=gt.pbe.generatePkcs12Key(t,b,1,s,r),m=gt.pbe.generatePkcs12Key(t,b,2,s,r),(y=z.des.createEncryptionCipher(h)).start(m),y.update(mt.toDer(e)),y.finish(),o=y.output.getBytes(),a=mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OID,!1,mt.oidToDer(vt["pbeWithSHAAnd3-KeyTripleDES-CBC"]).getBytes()),mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[mt.create(mt.Class.UNIVERSAL,mt.Type.OCTETSTRING,!1,i),mt.create(mt.Class.UNIVERSAL,mt.Type.INTEGER,!1,u.getBytes())])])}return mt.create(mt.Class.UNIVERSAL,mt.Type.SEQUENCE,!0,[a,mt.create(mt.Class.UNIVERSAL,mt.Type.OCTETSTRING,!1,o)])},gt.decryptPrivateKeyInfo=function(e,t){var n=null,r={},a=[];if(!mt.validate(e,yt,r,a)){var o=new Error("Cannot read encrypted private key. ASN.1 object is not a supported EncryptedPrivateKeyInfo.");throw o.errors=a,o}var i=mt.derToOid(r.encryptionOid),s=gt.pbe.getCipher(i,r.encryptionParams,t),u=z.util.createBuffer(r.encryptedData);return s.update(u),s.finish()&&(n=mt.fromDer(s.output)),n},gt.encryptedPrivateKeyToPem=function(e,t){var n={type:"ENCRYPTED PRIVATE KEY",body:mt.toDer(e).getBytes()};return z.pem.encode(n,{maxline:t})},gt.encryptedPrivateKeyFromPem=function(e){var t=z.pem.decode(e)[0];if("ENCRYPTED PRIVATE KEY"!==t.type){var n=new Error('Could not convert encrypted private key from PEM; PEM header type is "ENCRYPTED PRIVATE KEY".');throw n.headerType=t.type,n}if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert encrypted private key from PEM; PEM is encrypted.");return mt.fromDer(t.body)},gt.encryptRsaPrivateKey=function(e,t,n){if(!(n=n||{}).legacy){var r=gt.wrapRsaPrivateKey(gt.privateKeyToAsn1(e));return r=gt.encryptPrivateKeyInfo(r,t,n),gt.encryptedPrivateKeyToPem(r)}var a,o,i,s;switch(n.algorithm){case"aes128":a="AES-128-CBC",i=16,o=z.random.getBytesSync(16),s=z.aes.createEncryptionCipher;break;case"aes192":a="AES-192-CBC",i=24,o=z.random.getBytesSync(16),s=z.aes.createEncryptionCipher;break;case"aes256":a="AES-256-CBC",i=32,o=z.random.getBytesSync(16),s=z.aes.createEncryptionCipher;break;case"3des":a="DES-EDE3-CBC",i=24,o=z.random.getBytesSync(8),s=z.des.createEncryptionCipher;break;case"des":a="DES-CBC",i=8,o=z.random.getBytesSync(8),s=z.des.createEncryptionCipher;break;default:var u=new Error('Could not encrypt RSA private key; unsupported encryption algorithm "'+n.algorithm+'".');throw u.algorithm=n.algorithm,u}var c=s(z.pbe.opensslDeriveBytes(t,o.substr(0,8),i));c.start(o),c.update(mt.toDer(gt.privateKeyToAsn1(e))),c.finish();var l={type:"RSA PRIVATE KEY",procType:{version:"4",type:"ENCRYPTED"},dekInfo:{algorithm:a,parameters:z.util.bytesToHex(o).toUpperCase()},body:c.output.getBytes()};return z.pem.encode(l)},gt.decryptRsaPrivateKey=function(e,t){var n=null,r=z.pem.decode(e)[0];if("ENCRYPTED PRIVATE KEY"!==r.type&&"PRIVATE KEY"!==r.type&&"RSA PRIVATE KEY"!==r.type)throw(i=new Error('Could not convert private key from PEM; PEM header type is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".')).headerType=i,i;if(r.procType&&"ENCRYPTED"===r.procType.type){var a,o;switch(r.dekInfo.algorithm){case"DES-CBC":a=8,o=z.des.createDecryptionCipher;break;case"DES-EDE3-CBC":a=24,o=z.des.createDecryptionCipher;break;case"AES-128-CBC":a=16,o=z.aes.createDecryptionCipher;break;case"AES-192-CBC":a=24,o=z.aes.createDecryptionCipher;break;case"AES-256-CBC":a=32,o=z.aes.createDecryptionCipher;break;case"RC2-40-CBC":a=5,o=function(e){return z.rc2.createDecryptionCipher(e,40)};break;case"RC2-64-CBC":a=8,o=function(e){return z.rc2.createDecryptionCipher(e,64)};break;case"RC2-128-CBC":a=16,o=function(e){return z.rc2.createDecryptionCipher(e,128)};break;default:var i;throw(i=new Error('Could not decrypt private key; unsupported encryption algorithm "'+r.dekInfo.algorithm+'".')).algorithm=r.dekInfo.algorithm,i}var s=z.util.hexToBytes(r.dekInfo.parameters),u=o(z.pbe.opensslDeriveBytes(t,s.substr(0,8),a));if(u.start(s),u.update(z.util.createBuffer(r.body)),!u.finish())return n;n=u.output.getBytes()}else n=r.body;return null!==(n="ENCRYPTED PRIVATE KEY"===r.type?gt.decryptPrivateKeyInfo(mt.fromDer(n),t):mt.fromDer(n))&&(n=gt.privateKeyFromAsn1(n)),n},gt.pbe.generatePkcs12Key=function(e,t,n,r,a,o){var i,s;if(null==o){if(!("sha1"in z.md))throw new Error('"sha1" hash algorithm unavailable.');o=z.md.sha1.create()}var u=o.digestLength,c=o.blockLength,l=new z.util.ByteBuffer,p=new z.util.ByteBuffer;if(null!=e){for(s=0;s<e.length;s++)p.putInt16(e.charCodeAt(s));p.putInt16(0)}var d=p.length(),f=t.length(),h=new z.util.ByteBuffer;h.fillWithByte(n,c);var m=c*Math.ceil(f/c),g=new z.util.ByteBuffer;for(s=0;s<m;s++)g.putByte(t.at(s%f));var v=c*Math.ceil(d/c),y=new z.util.ByteBuffer;for(s=0;s<v;s++)y.putByte(p.at(s%d));var b=g;b.putBuffer(y);for(var x=Math.ceil(a/u),w=1;w<=x;w++){var k=new z.util.ByteBuffer;k.putBytes(h.bytes()),k.putBytes(b.bytes());for(var S=0;S<r;S++)o.start(),o.update(k.getBytes()),k=o.digest();var E=new z.util.ByteBuffer;for(s=0;s<c;s++)E.putByte(k.at(s%u));var I=Math.ceil(f/c)+Math.ceil(d/c),C=new z.util.ByteBuffer;for(i=0;i<I;i++){var T=new z.util.ByteBuffer(b.getBytes(c)),_=511;for(s=E.length()-1;s>=0;s--)_>>=8,_+=E.at(s)+T.at(s),T.setAt(s,255&_);C.putBuffer(T)}b=C,l.putBuffer(k)}return l.truncate(l.length()-a),l},gt.pbe.getCipher=function(e,t,n){switch(e){case gt.oids.pkcs5PBES2:return gt.pbe.getCipherForPBES2(e,t,n);case gt.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:case gt.oids["pbewithSHAAnd40BitRC2-CBC"]:return gt.pbe.getCipherForPKCS12PBE(e,t,n);default:var r=new Error("Cannot read encrypted PBE data block. Unsupported OID.");throw r.oid=e,r.supportedOids=["pkcs5PBES2","pbeWithSHAAnd3-KeyTripleDES-CBC","pbewithSHAAnd40BitRC2-CBC"],r}},gt.pbe.getCipherForPBES2=function(e,t,n){var r,a={},o=[];if(!mt.validate(t,bt,a,o))throw(r=new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.")).errors=o,r;if((e=mt.derToOid(a.kdfOid))!==gt.oids.pkcs5PBKDF2)throw(r=new Error("Cannot read encrypted private key. Unsupported key derivation function OID.")).oid=e,r.supportedOids=["pkcs5PBKDF2"],r;if((e=mt.derToOid(a.encOid))!==gt.oids["aes128-CBC"]&&e!==gt.oids["aes192-CBC"]&&e!==gt.oids["aes256-CBC"]&&e!==gt.oids["des-EDE3-CBC"]&&e!==gt.oids.desCBC)throw(r=new Error("Cannot read encrypted private key. Unsupported encryption scheme OID.")).oid=e,r.supportedOids=["aes128-CBC","aes192-CBC","aes256-CBC","des-EDE3-CBC","desCBC"],r;var i,s,u=a.kdfSalt,c=z.util.createBuffer(a.kdfIterationCount);switch(c=c.getInt(c.length()<<3),gt.oids[e]){case"aes128-CBC":i=16,s=z.aes.createDecryptionCipher;break;case"aes192-CBC":i=24,s=z.aes.createDecryptionCipher;break;case"aes256-CBC":i=32,s=z.aes.createDecryptionCipher;break;case"des-EDE3-CBC":i=24,s=z.des.createDecryptionCipher;break;case"desCBC":i=8,s=z.des.createDecryptionCipher}var l=kt(a.prfOid),p=z.pkcs5.pbkdf2(n,u,c,i,l),d=a.encIv,f=s(p);return f.start(d),f},gt.pbe.getCipherForPKCS12PBE=function(e,t,n){var r={},a=[];if(!mt.validate(t,xt,r,a))throw(l=new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.")).errors=a,l;var o,i,s,u=z.util.createBuffer(r.salt),c=z.util.createBuffer(r.iterations);switch(c=c.getInt(c.length()<<3),e){case gt.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:o=24,i=8,s=z.des.startDecrypting;break;case gt.oids["pbewithSHAAnd40BitRC2-CBC"]:o=5,i=8,s=function(e,t){var n=z.rc2.createDecryptionCipher(e,40);return n.start(t,null),n};break;default:var l;throw(l=new Error("Cannot read PKCS #12 PBE data block. Unsupported OID.")).oid=e,l}var p=kt(r.prfOid),d=gt.pbe.generatePkcs12Key(n,u,1,c,o,p);return p.start(),s(d,gt.pbe.generatePkcs12Key(n,u,2,c,i,p))},gt.pbe.opensslDeriveBytes=function(e,t,n,r){if(null==r){if(!("md5"in z.md))throw new Error('"md5" hash algorithm unavailable.');r=z.md.md5.create()}null===t&&(t="");for(var a=[wt(r,e+t)],o=16,i=1;o<n;++i,o+=16)a.push(wt(r,a[i-1]+e+t));return a.join("").substr(0,n)},w((function(e){var t=z.asn1,n=e.exports=z.pkcs7asn1=z.pkcs7asn1||{};z.pkcs7=z.pkcs7||{},z.pkcs7.asn1=n;var r={name:"ContentInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"ContentInfo.ContentType",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"contentType"},{name:"ContentInfo.content",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,captureAsn1:"content"}]};n.contentInfoValidator=r;var a={name:"EncryptedContentInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedContentInfo.contentType",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"contentType"},{name:"EncryptedContentInfo.contentEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedContentInfo.contentEncryptionAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"encAlgorithm"},{name:"EncryptedContentInfo.contentEncryptionAlgorithm.parameter",tagClass:t.Class.UNIVERSAL,captureAsn1:"encParameter"}]},{name:"EncryptedContentInfo.encryptedContent",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,capture:"encryptedContent",captureAsn1:"encryptedContentAsn1"}]};n.envelopedDataValidator={name:"EnvelopedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EnvelopedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"EnvelopedData.RecipientInfos",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,captureAsn1:"recipientInfos"}].concat(a)},n.encryptedDataValidator={name:"EncryptedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"}].concat(a)};var o={name:"SignerInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1},{name:"SignerInfo.issuerAndSerialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.issuerAndSerialNumber.issuer",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"issuer"},{name:"SignerInfo.issuerAndSerialNumber.serialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"serial"}]},{name:"SignerInfo.digestAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.digestAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"digestAlgorithm"},{name:"SignerInfo.digestAlgorithm.parameter",tagClass:t.Class.UNIVERSAL,constructed:!1,captureAsn1:"digestParameter",optional:!0}]},{name:"SignerInfo.authenticatedAttributes",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,capture:"authenticatedAttributes"},{name:"SignerInfo.digestEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,capture:"signatureAlgorithm"},{name:"SignerInfo.encryptedDigest",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"signature"},{name:"SignerInfo.unauthenticatedAttributes",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0,capture:"unauthenticatedAttributes"}]};n.signedDataValidator={name:"SignedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"SignedData.DigestAlgorithms",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,captureAsn1:"digestAlgorithms"},r,{name:"SignedData.Certificates",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,optional:!0,captureAsn1:"certificates"},{name:"SignedData.CertificateRevocationLists",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,optional:!0,captureAsn1:"crls"},{name:"SignedData.SignerInfos",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,capture:"signerInfos",optional:!0,value:[o]}]},n.recipientInfoValidator={name:"RecipientInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"RecipientInfo.issuerAndSerial",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.issuerAndSerial.issuer",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"issuer"},{name:"RecipientInfo.issuerAndSerial.serialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"serial"}]},{name:"RecipientInfo.keyEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.keyEncryptionAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"encAlgorithm"},{name:"RecipientInfo.keyEncryptionAlgorithm.parameter",tagClass:t.Class.UNIVERSAL,constructed:!1,captureAsn1:"encParameter"}]},{name:"RecipientInfo.encryptedKey",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"encKey"}]}})),w((function(e){z.mgf=z.mgf||{},(e.exports=z.mgf.mgf1=z.mgf1=z.mgf1||{}).create=function(e){return{generate:function(t,n){for(var r=new z.util.ByteBuffer,a=Math.ceil(n/e.digestLength),o=0;o<a;o++){var i=new z.util.ByteBuffer;i.putInt32(o),e.start(),e.update(t+i.getBytes()),r.putBuffer(e.digest())}return r.truncate(r.length()-n),r.getBytes()}}}})),z.mgf=z.mgf||{},z.mgf.mgf1=z.mgf1,w((function(e){(e.exports=z.pss=z.pss||{}).create=function(e){3===arguments.length&&(e={md:arguments[0],mgf:arguments[1],saltLength:arguments[2]});var t,n=e.md,r=e.mgf,a=n.digestLength,o=e.salt||null;if("string"==typeof o&&(o=z.util.createBuffer(o)),"saltLength"in e)t=e.saltLength;else{if(null===o)throw new Error("Salt length not specified or specific salt not given.");t=o.length()}if(null!==o&&o.length()!==t)throw new Error("Given salt length does not match length of given salt.");var i=e.prng||z.random;return{encode:function(e,s){var u,c,l=s-1,p=Math.ceil(l/8),d=e.digest().getBytes();if(p<a+t+2)throw new Error("Message is too long to encrypt.");c=null===o?i.getBytesSync(t):o.bytes();var f=new z.util.ByteBuffer;f.fillWithByte(0,8),f.putBytes(d),f.putBytes(c),n.start(),n.update(f.getBytes());var h=n.digest().getBytes(),m=new z.util.ByteBuffer;m.fillWithByte(0,p-t-a-2),m.putByte(1),m.putBytes(c);var g=m.getBytes(),v=p-a-1,y=r.generate(h,v),b="";for(u=0;u<v;u++)b+=String.fromCharCode(g.charCodeAt(u)^y.charCodeAt(u));var x=65280>>8*p-l&255;return(b=String.fromCharCode(b.charCodeAt(0)&~x)+b.substr(1))+h+String.fromCharCode(188)},verify:function(e,o,i){var s,u=i-1,c=Math.ceil(u/8);if(o=o.substr(-c),c<a+t+2)throw new Error("Inconsistent parameters to PSS signature verification.");if(188!==o.charCodeAt(c-1))throw new Error("Encoded message does not end in 0xBC.");var l=c-a-1,p=o.substr(0,l),d=o.substr(l,a),f=65280>>8*c-u&255;if(0!=(p.charCodeAt(0)&f))throw new Error("Bits beyond keysize not zero as expected.");var h=r.generate(d,l),m="";for(s=0;s<l;s++)m+=String.fromCharCode(p.charCodeAt(s)^h.charCodeAt(s));m=String.fromCharCode(m.charCodeAt(0)&~f)+m.substr(1);var g=c-a-t-2;for(s=0;s<g;s++)if(0!==m.charCodeAt(s))throw new Error("Leftmost octets not zero as expected");if(1!==m.charCodeAt(g))throw new Error("Inconsistent PSS signature, 0x01 marker not found");var v=m.substr(-t),y=new z.util.ByteBuffer;return y.fillWithByte(0,8),y.putBytes(e),y.putBytes(v),n.start(),n.update(y.getBytes()),d===n.digest().getBytes()}}}})),w((function(e){var t=z.asn1,n=e.exports=z.pki=z.pki||{},r=n.oids,a={};a.CN=r.commonName,a.commonName="CN",a.C=r.countryName,a.countryName="C",a.L=r.localityName,a.localityName="L",a.ST=r.stateOrProvinceName,a.stateOrProvinceName="ST",a.O=r.organizationName,a.organizationName="O",a.OU=r.organizationalUnitName,a.organizationalUnitName="OU",a.E=r.emailAddress,a.emailAddress="E";var o=z.pki.rsa.publicKeyValidator,i={name:"Certificate",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"tbsCertificate",value:[{name:"Certificate.TBSCertificate.version",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.version.integer",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"certVersion"}]},{name:"Certificate.TBSCertificate.serialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"certSerialNumber"},{name:"Certificate.TBSCertificate.signature",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.signature.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"certinfoSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:t.Class.UNIVERSAL,optional:!0,captureAsn1:"certinfoSignatureParams"}]},{name:"Certificate.TBSCertificate.issuer",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"certIssuer"},{name:"Certificate.TBSCertificate.validity",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.validity.notBefore (utc)",tagClass:t.Class.UNIVERSAL,type:t.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity1UTCTime"},{name:"Certificate.TBSCertificate.validity.notBefore (generalized)",tagClass:t.Class.UNIVERSAL,type:t.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity2GeneralizedTime"},{name:"Certificate.TBSCertificate.validity.notAfter (utc)",tagClass:t.Class.UNIVERSAL,type:t.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity3UTCTime"},{name:"Certificate.TBSCertificate.validity.notAfter (generalized)",tagClass:t.Class.UNIVERSAL,type:t.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity4GeneralizedTime"}]},{name:"Certificate.TBSCertificate.subject",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"certSubject"},o,{name:"Certificate.TBSCertificate.issuerUniqueID",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.issuerUniqueID.id",tagClass:t.Class.UNIVERSAL,type:t.Type.BITSTRING,constructed:!1,captureBitStringValue:"certIssuerUniqueId"}]},{name:"Certificate.TBSCertificate.subjectUniqueID",tagClass:t.Class.CONTEXT_SPECIFIC,type:2,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.subjectUniqueID.id",tagClass:t.Class.UNIVERSAL,type:t.Type.BITSTRING,constructed:!1,captureBitStringValue:"certSubjectUniqueId"}]},{name:"Certificate.TBSCertificate.extensions",tagClass:t.Class.CONTEXT_SPECIFIC,type:3,constructed:!0,captureAsn1:"certExtensions",optional:!0}]},{name:"Certificate.signatureAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.signatureAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"certSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:t.Class.UNIVERSAL,optional:!0,captureAsn1:"certSignatureParams"}]},{name:"Certificate.signatureValue",tagClass:t.Class.UNIVERSAL,type:t.Type.BITSTRING,constructed:!1,captureBitStringValue:"certSignature"}]},s={name:"rsapss",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.hashAlgorithm",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier",tagClass:t.Class.UNIVERSAL,type:t.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"hashOid"}]}]},{name:"rsapss.maskGenAlgorithm",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier",tagClass:t.Class.UNIVERSAL,type:t.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"maskGenOid"},{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"maskGenHashOid"}]}]}]},{name:"rsapss.saltLength",tagClass:t.Class.CONTEXT_SPECIFIC,type:2,optional:!0,value:[{name:"rsapss.saltLength.saltLength",tagClass:t.Class.UNIVERSAL,type:t.Class.INTEGER,constructed:!1,capture:"saltLength"}]},{name:"rsapss.trailerField",tagClass:t.Class.CONTEXT_SPECIFIC,type:3,optional:!0,value:[{name:"rsapss.trailer.trailer",tagClass:t.Class.UNIVERSAL,type:t.Class.INTEGER,constructed:!1,capture:"trailer"}]}]},u={name:"CertificationRequestInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"certificationRequestInfo",value:[{name:"CertificationRequestInfo.integer",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"certificationRequestInfoVersion"},{name:"CertificationRequestInfo.subject",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"certificationRequestInfoSubject"},o,{name:"CertificationRequestInfo.attributes",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,capture:"certificationRequestInfoAttributes",value:[{name:"CertificationRequestInfo.attributes",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"CertificationRequestInfo.attributes.type",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1},{name:"CertificationRequestInfo.attributes.value",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0}]}]}]},c={name:"CertificationRequest",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"csr",value:[u,{name:"CertificationRequest.signatureAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"CertificationRequest.signatureAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"csrSignatureOid"},{name:"CertificationRequest.signatureAlgorithm.parameters",tagClass:t.Class.UNIVERSAL,optional:!0,captureAsn1:"csrSignatureParams"}]},{name:"CertificationRequest.signature",tagClass:t.Class.UNIVERSAL,type:t.Type.BITSTRING,constructed:!1,captureBitStringValue:"csrSignature"}]};function l(e,t){"string"==typeof t&&(t={shortName:t});for(var n,r=null,a=0;null===r&&a<e.attributes.length;++a)n=e.attributes[a],(t.type&&t.type===n.type||t.name&&t.name===n.name||t.shortName&&t.shortName===n.shortName)&&(r=n);return r}n.RDNAttributesAsArray=function(e,n){for(var o,i,s,u=[],c=0;c<e.value.length;++c){o=e.value[c];for(var l=0;l<o.value.length;++l)s={},i=o.value[l],s.type=t.derToOid(i.value[0].value),s.value=i.value[1].value,s.valueTagClass=i.value[1].type,s.type in r&&(s.name=r[s.type],s.name in a&&(s.shortName=a[s.name])),n&&(n.update(s.type),n.update(s.value)),u.push(s)}return u},n.CRIAttributesAsArray=function(e){for(var o=[],i=0;i<e.length;++i)for(var s=e[i],u=t.derToOid(s.value[0].value),c=s.value[1].value,l=0;l<c.length;++l){var p={};if(p.type=u,p.value=c[l].value,p.valueTagClass=c[l].type,p.type in r&&(p.name=r[p.type],p.name in a&&(p.shortName=a[p.name])),p.type===r.extensionRequest){p.extensions=[];for(var d=0;d<p.value.length;++d)p.extensions.push(n.certificateExtensionFromAsn1(p.value[d]))}o.push(p)}return o};var p=function(e,n,a){var o={};if(e!==r["RSASSA-PSS"])return o;a&&(o={hash:{algorithmOid:r.sha1},mgf:{algorithmOid:r.mgf1,hash:{algorithmOid:r.sha1}},saltLength:20});var i={},u=[];if(!t.validate(n,s,i,u)){var c=new Error("Cannot read RSASSA-PSS parameter block.");throw c.errors=u,c}return void 0!==i.hashOid&&(o.hash=o.hash||{},o.hash.algorithmOid=t.derToOid(i.hashOid)),void 0!==i.maskGenOid&&(o.mgf=o.mgf||{},o.mgf.algorithmOid=t.derToOid(i.maskGenOid),o.mgf.hash=o.mgf.hash||{},o.mgf.hash.algorithmOid=t.derToOid(i.maskGenHashOid)),void 0!==i.saltLength&&(o.saltLength=i.saltLength.charCodeAt(0)),o};function d(e){for(var n,r,a=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),o=e.attributes,i=0;i<o.length;++i){var s=(n=o[i]).value,u=t.Type.PRINTABLESTRING;"valueTagClass"in n&&(u=n.valueTagClass)===t.Type.UTF8&&(s=z.util.encodeUtf8(s)),r=t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.type).getBytes()),t.create(t.Class.UNIVERSAL,u,!1,s)])]),a.value.push(r)}return a}function f(e){for(var o,i=0;i<e.length;++i){if(void 0===(o=e[i]).name&&(o.type&&o.type in n.oids?o.name=n.oids[o.type]:o.shortName&&o.shortName in a&&(o.name=n.oids[a[o.shortName]])),void 0===o.type){if(!o.name||!(o.name in n.oids))throw(u=new Error("Attribute type not specified.")).attribute=o,u;o.type=n.oids[o.name]}if(void 0===o.shortName&&o.name&&o.name in a&&(o.shortName=a[o.name]),o.type===r.extensionRequest&&(o.valueConstructed=!0,o.valueTagClass=t.Type.SEQUENCE,!o.value&&o.extensions)){o.value=[];for(var s=0;s<o.extensions.length;++s)o.value.push(n.certificateExtensionToAsn1(h(o.extensions[s])))}var u;if(void 0===o.value)throw(u=new Error("Attribute value not specified.")).attribute=o,u}}function h(e,a){if(a=a||{},void 0===e.name&&e.id&&e.id in n.oids&&(e.name=n.oids[e.id]),void 0===e.id){if(!e.name||!(e.name in n.oids))throw(x=new Error("Extension ID not specified.")).extension=e,x;e.id=n.oids[e.name]}if(void 0!==e.value)return e;if("keyUsage"===e.name){var o=0,i=0,s=0;e.digitalSignature&&(i|=128,o=7),e.nonRepudiation&&(i|=64,o=6),e.keyEncipherment&&(i|=32,o=5),e.dataEncipherment&&(i|=16,o=4),e.keyAgreement&&(i|=8,o=3),e.keyCertSign&&(i|=4,o=2),e.cRLSign&&(i|=2,o=1),e.encipherOnly&&(i|=1,o=0),e.decipherOnly&&(s|=128,o=7);var u=String.fromCharCode(o);0!==s?u+=String.fromCharCode(i)+String.fromCharCode(s):0!==i&&(u+=String.fromCharCode(i)),e.value=t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,u)}else if("basicConstraints"===e.name)e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),e.cA&&e.value.value.push(t.create(t.Class.UNIVERSAL,t.Type.BOOLEAN,!1,String.fromCharCode(255))),"pathLenConstraint"in e&&e.value.value.push(t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.pathLenConstraint).getBytes()));else if("extKeyUsage"===e.name){e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]);var c=e.value.value;for(var l in e)!0===e[l]&&(l in r?c.push(t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(r[l]).getBytes())):-1!==l.indexOf(".")&&c.push(t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(l).getBytes())))}else if("nsCertType"===e.name)o=0,i=0,e.client&&(i|=128,o=7),e.server&&(i|=64,o=6),e.email&&(i|=32,o=5),e.objsign&&(i|=16,o=4),e.reserved&&(i|=8,o=3),e.sslCA&&(i|=4,o=2),e.emailCA&&(i|=2,o=1),e.objCA&&(i|=1,o=0),u=String.fromCharCode(o),0!==i&&(u+=String.fromCharCode(i)),e.value=t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,u);else if("subjectAltName"===e.name||"issuerAltName"===e.name){e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]);for(var p=0;p<e.altNames.length;++p){if(u=(v=e.altNames[p]).value,7===v.type&&v.ip){if(null===(u=z.util.bytesFromIP(v.ip)))throw(x=new Error('Extension "ip" value is not a valid IPv4 or IPv6 address.')).extension=e,x}else 8===v.type&&(u=v.oid?t.oidToDer(t.oidToDer(v.oid)):t.oidToDer(u));e.value.value.push(t.create(t.Class.CONTEXT_SPECIFIC,v.type,!1,u))}}else if("nsComment"===e.name&&a.cert){if(!/^[\x00-\x7F]*$/.test(e.comment)||e.comment.length<1||e.comment.length>128)throw new Error('Invalid "nsComment" content.');e.value=t.create(t.Class.UNIVERSAL,t.Type.IA5STRING,!1,e.comment)}else if("subjectKeyIdentifier"===e.name&&a.cert){var f=a.cert.generateSubjectKeyIdentifier();e.subjectKeyIdentifier=f.toHex(),e.value=t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,f.getBytes())}else if("authorityKeyIdentifier"===e.name&&a.cert){if(e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),c=e.value.value,e.keyIdentifier){var h=!0===e.keyIdentifier?a.cert.generateSubjectKeyIdentifier().getBytes():e.keyIdentifier;c.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!1,h))}if(e.authorityCertIssuer){var m=[t.create(t.Class.CONTEXT_SPECIFIC,4,!0,[d(!0===e.authorityCertIssuer?a.cert.issuer:e.authorityCertIssuer)])];c.push(t.create(t.Class.CONTEXT_SPECIFIC,1,!0,m))}if(e.serialNumber){var g=z.util.hexToBytes(!0===e.serialNumber?a.cert.serialNumber:e.serialNumber);c.push(t.create(t.Class.CONTEXT_SPECIFIC,2,!1,g))}}else if("cRLDistributionPoints"===e.name){e.value=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),c=e.value.value;var v,y=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]),b=t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[]);for(p=0;p<e.altNames.length;++p){if(u=(v=e.altNames[p]).value,7===v.type&&v.ip){if(null===(u=z.util.bytesFromIP(v.ip)))throw(x=new Error('Extension "ip" value is not a valid IPv4 or IPv6 address.')).extension=e,x}else 8===v.type&&(u=v.oid?t.oidToDer(t.oidToDer(v.oid)):t.oidToDer(u));b.value.push(t.create(t.Class.CONTEXT_SPECIFIC,v.type,!1,u))}y.value.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[b])),c.push(y)}var x;if(void 0===e.value)throw(x=new Error("Extension value not specified.")).extension=e,x;return e}function m(e,n){switch(e){case r["RSASSA-PSS"]:var a=[];return void 0!==n.hash.algorithmOid&&a.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.hash.algorithmOid).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")])])),void 0!==n.mgf.algorithmOid&&a.push(t.create(t.Class.CONTEXT_SPECIFIC,1,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.mgf.algorithmOid).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.mgf.hash.algorithmOid).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")])])])),void 0!==n.saltLength&&a.push(t.create(t.Class.CONTEXT_SPECIFIC,2,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(n.saltLength).getBytes())])),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,a);default:return t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")}}function g(e){var n=t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[]);if(0===e.attributes.length)return n;for(var r=e.attributes,a=0;a<r.length;++a){var o=r[a],i=o.value,s=t.Type.UTF8;"valueTagClass"in o&&(s=o.valueTagClass),s===t.Type.UTF8&&(i=z.util.encodeUtf8(i));var u=!1;"valueConstructed"in o&&(u=o.valueConstructed);var c=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(o.type).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[t.create(t.Class.UNIVERSAL,s,u,i)])]);n.value.push(c)}return n}n.certificateFromPem=function(e,r,a){var o=z.pem.decode(e)[0];if("CERTIFICATE"!==o.type&&"X509 CERTIFICATE"!==o.type&&"TRUSTED CERTIFICATE"!==o.type){var i=new Error('Could not convert certificate from PEM; PEM header type is not "CERTIFICATE", "X509 CERTIFICATE", or "TRUSTED CERTIFICATE".');throw i.headerType=o.type,i}if(o.procType&&"ENCRYPTED"===o.procType.type)throw new Error("Could not convert certificate from PEM; PEM is encrypted.");var s=t.fromDer(o.body,a);return n.certificateFromAsn1(s,r)},n.certificateToPem=function(e,r){var a={type:"CERTIFICATE",body:t.toDer(n.certificateToAsn1(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.publicKeyFromPem=function(e){var r=z.pem.decode(e)[0];if("PUBLIC KEY"!==r.type&&"RSA PUBLIC KEY"!==r.type){var a=new Error('Could not convert public key from PEM; PEM header type is not "PUBLIC KEY" or "RSA PUBLIC KEY".');throw a.headerType=r.type,a}if(r.procType&&"ENCRYPTED"===r.procType.type)throw new Error("Could not convert public key from PEM; PEM is encrypted.");var o=t.fromDer(r.body);return n.publicKeyFromAsn1(o)},n.publicKeyToPem=function(e,r){var a={type:"PUBLIC KEY",body:t.toDer(n.publicKeyToAsn1(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.publicKeyToRSAPublicKeyPem=function(e,r){var a={type:"RSA PUBLIC KEY",body:t.toDer(n.publicKeyToRSAPublicKey(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.getPublicKeyFingerprint=function(e,r){var a,o=(r=r||{}).md||z.md.sha1.create();switch(r.type||"RSAPublicKey"){case"RSAPublicKey":a=t.toDer(n.publicKeyToRSAPublicKey(e)).getBytes();break;case"SubjectPublicKeyInfo":a=t.toDer(n.publicKeyToAsn1(e)).getBytes();break;default:throw new Error('Unknown fingerprint type "'+r.type+'".')}o.start(),o.update(a);var i=o.digest();if("hex"===r.encoding){var s=i.toHex();return r.delimiter?s.match(/.{2}/g).join(r.delimiter):s}if("binary"===r.encoding)return i.getBytes();if(r.encoding)throw new Error('Unknown encoding "'+r.encoding+'".');return i},n.certificationRequestFromPem=function(e,r,a){var o=z.pem.decode(e)[0];if("CERTIFICATE REQUEST"!==o.type){var i=new Error('Could not convert certification request from PEM; PEM header type is not "CERTIFICATE REQUEST".');throw i.headerType=o.type,i}if(o.procType&&"ENCRYPTED"===o.procType.type)throw new Error("Could not convert certification request from PEM; PEM is encrypted.");var s=t.fromDer(o.body,a);return n.certificationRequestFromAsn1(s,r)},n.certificationRequestToPem=function(e,r){var a={type:"CERTIFICATE REQUEST",body:t.toDer(n.certificationRequestToAsn1(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.createCertificate=function(){var e={version:2,serialNumber:"00",signatureOid:null,signature:null,siginfo:{}};return e.siginfo.algorithmOid=null,e.validity={},e.validity.notBefore=new Date,e.validity.notAfter=new Date,e.issuer={},e.issuer.getField=function(t){return l(e.issuer,t)},e.issuer.addField=function(t){f([t]),e.issuer.attributes.push(t)},e.issuer.attributes=[],e.issuer.hash=null,e.subject={},e.subject.getField=function(t){return l(e.subject,t)},e.subject.addField=function(t){f([t]),e.subject.attributes.push(t)},e.subject.attributes=[],e.subject.hash=null,e.extensions=[],e.publicKey=null,e.md=null,e.setSubject=function(t,n){f(t),e.subject.attributes=t,delete e.subject.uniqueId,n&&(e.subject.uniqueId=n),e.subject.hash=null},e.setIssuer=function(t,n){f(t),e.issuer.attributes=t,delete e.issuer.uniqueId,n&&(e.issuer.uniqueId=n),e.issuer.hash=null},e.setExtensions=function(t){for(var n=0;n<t.length;++n)h(t[n],{cert:e});e.extensions=t},e.getExtension=function(t){"string"==typeof t&&(t={name:t});for(var n,r=null,a=0;null===r&&a<e.extensions.length;++a)n=e.extensions[a],(t.id&&n.id===t.id||t.name&&n.name===t.name)&&(r=n);return r},e.sign=function(a,o){e.md=o||z.md.sha1.create();var i=r[e.md.algorithm+"WithRSAEncryption"];if(!i){var s=new Error("Could not compute certificate digest. Unknown message digest algorithm OID.");throw s.algorithm=e.md.algorithm,s}e.signatureOid=e.siginfo.algorithmOid=i,e.tbsCertificate=n.getTBSCertificate(e);var u=t.toDer(e.tbsCertificate);e.md.update(u.getBytes()),e.signature=a.sign(e.md)},e.verify=function(a){var o=!1;if(!e.issued(a)){var i=a.issuer,s=e.subject;throw(h=new Error("The parent certificate did not issue the given child certificate; the child certificate's issuer does not match the parent's subject.")).expectedIssuer=i.attributes,h.actualIssuer=s.attributes,h}var u=a.md;if(null===u){if(a.signatureOid in r)switch(r[a.signatureOid]){case"sha1WithRSAEncryption":u=z.md.sha1.create();break;case"md5WithRSAEncryption":u=z.md.md5.create();break;case"sha256WithRSAEncryption":u=z.md.sha256.create();break;case"sha384WithRSAEncryption":u=z.md.sha384.create();break;case"sha512WithRSAEncryption":u=z.md.sha512.create();break;case"RSASSA-PSS":u=z.md.sha256.create()}if(null===u)throw(h=new Error("Could not compute certificate digest. Unknown signature OID.")).signatureOid=a.signatureOid,h;var c=a.tbsCertificate||n.getTBSCertificate(a),l=t.toDer(c);u.update(l.getBytes())}if(null!==u){var p;switch(a.signatureOid){case r.sha1WithRSAEncryption:p=void 0;break;case r["RSASSA-PSS"]:var d,f,h;if(void 0===(d=r[a.signatureParameters.mgf.hash.algorithmOid])||void 0===z.md[d])throw(h=new Error("Unsupported MGF hash function.")).oid=a.signatureParameters.mgf.hash.algorithmOid,h.name=d,h;if(void 0===(f=r[a.signatureParameters.mgf.algorithmOid])||void 0===z.mgf[f])throw(h=new Error("Unsupported MGF function.")).oid=a.signatureParameters.mgf.algorithmOid,h.name=f,h;if(f=z.mgf[f].create(z.md[d].create()),void 0===(d=r[a.signatureParameters.hash.algorithmOid])||void 0===z.md[d])throw{message:"Unsupported RSASSA-PSS hash function.",oid:a.signatureParameters.hash.algorithmOid,name:d};p=z.pss.create(z.md[d].create(),f,a.signatureParameters.saltLength)}o=e.publicKey.verify(u.digest().getBytes(),a.signature,p)}return o},e.isIssuer=function(t){var n=!1,r=e.issuer,a=t.subject;if(r.hash&&a.hash)n=r.hash===a.hash;else if(r.attributes.length===a.attributes.length){var o,i;n=!0;for(var s=0;n&&s<r.attributes.length;++s)o=r.attributes[s],i=a.attributes[s],o.type===i.type&&o.value===i.value||(n=!1)}return n},e.issued=function(t){return t.isIssuer(e)},e.generateSubjectKeyIdentifier=function(){return n.getPublicKeyFingerprint(e.publicKey,{type:"RSAPublicKey"})},e.verifySubjectKeyIdentifier=function(){for(var t=r.subjectKeyIdentifier,n=0;n<e.extensions.length;++n){var a=e.extensions[n];if(a.id===t){var o=e.generateSubjectKeyIdentifier().getBytes();return z.util.hexToBytes(a.subjectKeyIdentifier)===o}}return!1},e},n.certificateFromAsn1=function(e,a){var o={},s=[];if(!t.validate(e,i,o,s))throw(h=new Error("Cannot read X.509 certificate. ASN.1 object is not an X509v3 Certificate.")).errors=s,h;if(t.derToOid(o.publicKeyOid)!==n.oids.rsaEncryption)throw new Error("Cannot read public key. OID is not RSA.");var u=n.createCertificate();u.version=o.certVersion?o.certVersion.charCodeAt(0):0;var c=z.util.createBuffer(o.certSerialNumber);u.serialNumber=c.toHex(),u.signatureOid=z.asn1.derToOid(o.certSignatureOid),u.signatureParameters=p(u.signatureOid,o.certSignatureParams,!0),u.siginfo.algorithmOid=z.asn1.derToOid(o.certinfoSignatureOid),u.siginfo.parameters=p(u.siginfo.algorithmOid,o.certinfoSignatureParams,!1),u.signature=o.certSignature;var d=[];if(void 0!==o.certValidity1UTCTime&&d.push(t.utcTimeToDate(o.certValidity1UTCTime)),void 0!==o.certValidity2GeneralizedTime&&d.push(t.generalizedTimeToDate(o.certValidity2GeneralizedTime)),void 0!==o.certValidity3UTCTime&&d.push(t.utcTimeToDate(o.certValidity3UTCTime)),void 0!==o.certValidity4GeneralizedTime&&d.push(t.generalizedTimeToDate(o.certValidity4GeneralizedTime)),d.length>2)throw new Error("Cannot read notBefore/notAfter validity times; more than two times were provided in the certificate.");if(d.length<2)throw new Error("Cannot read notBefore/notAfter validity times; they were not provided as either UTCTime or GeneralizedTime.");if(u.validity.notBefore=d[0],u.validity.notAfter=d[1],u.tbsCertificate=o.tbsCertificate,a){var h;if(u.md=null,u.signatureOid in r)switch(r[u.signatureOid]){case"sha1WithRSAEncryption":u.md=z.md.sha1.create();break;case"md5WithRSAEncryption":u.md=z.md.md5.create();break;case"sha256WithRSAEncryption":u.md=z.md.sha256.create();break;case"sha384WithRSAEncryption":u.md=z.md.sha384.create();break;case"sha512WithRSAEncryption":u.md=z.md.sha512.create();break;case"RSASSA-PSS":u.md=z.md.sha256.create()}if(null===u.md)throw(h=new Error("Could not compute certificate digest. Unknown signature OID.")).signatureOid=u.signatureOid,h;var m=t.toDer(u.tbsCertificate);u.md.update(m.getBytes())}var g=z.md.sha1.create();u.issuer.getField=function(e){return l(u.issuer,e)},u.issuer.addField=function(e){f([e]),u.issuer.attributes.push(e)},u.issuer.attributes=n.RDNAttributesAsArray(o.certIssuer,g),o.certIssuerUniqueId&&(u.issuer.uniqueId=o.certIssuerUniqueId),u.issuer.hash=g.digest().toHex();var v=z.md.sha1.create();return u.subject.getField=function(e){return l(u.subject,e)},u.subject.addField=function(e){f([e]),u.subject.attributes.push(e)},u.subject.attributes=n.RDNAttributesAsArray(o.certSubject,v),o.certSubjectUniqueId&&(u.subject.uniqueId=o.certSubjectUniqueId),u.subject.hash=v.digest().toHex(),o.certExtensions?u.extensions=n.certificateExtensionsFromAsn1(o.certExtensions):u.extensions=[],u.publicKey=n.publicKeyFromAsn1(o.subjectPublicKeyInfo),u},n.certificateExtensionsFromAsn1=function(e){for(var t=[],r=0;r<e.value.length;++r)for(var a=e.value[r],o=0;o<a.value.length;++o)t.push(n.certificateExtensionFromAsn1(a.value[o]));return t},n.certificateExtensionFromAsn1=function(e){var n={};if(n.id=t.derToOid(e.value[0].value),n.critical=!1,e.value[1].type===t.Type.BOOLEAN?(n.critical=0!==e.value[1].value.charCodeAt(0),n.value=e.value[2].value):n.value=e.value[1].value,n.id in r)if(n.name=r[n.id],"keyUsage"===n.name){var a=0,o=0;(s=t.fromDer(n.value)).value.length>1&&(a=s.value.charCodeAt(1),o=s.value.length>2?s.value.charCodeAt(2):0),n.digitalSignature=128==(128&a),n.nonRepudiation=64==(64&a),n.keyEncipherment=32==(32&a),n.dataEncipherment=16==(16&a),n.keyAgreement=8==(8&a),n.keyCertSign=4==(4&a),n.cRLSign=2==(2&a),n.encipherOnly=1==(1&a),n.decipherOnly=128==(128&o)}else if("basicConstraints"===n.name){(s=t.fromDer(n.value)).value.length>0&&s.value[0].type===t.Type.BOOLEAN?n.cA=0!==s.value[0].value.charCodeAt(0):n.cA=!1;var i=null;s.value.length>0&&s.value[0].type===t.Type.INTEGER?i=s.value[0].value:s.value.length>1&&(i=s.value[1].value),null!==i&&(n.pathLenConstraint=t.derToInteger(i))}else if("extKeyUsage"===n.name)for(var s=t.fromDer(n.value),u=0;u<s.value.length;++u){var c=t.derToOid(s.value[u].value);c in r?n[r[c]]=!0:n[c]=!0}else if("nsCertType"===n.name)a=0,(s=t.fromDer(n.value)).value.length>1&&(a=s.value.charCodeAt(1)),n.client=128==(128&a),n.server=64==(64&a),n.email=32==(32&a),n.objsign=16==(16&a),n.reserved=8==(8&a),n.sslCA=4==(4&a),n.emailCA=2==(2&a),n.objCA=1==(1&a);else if("subjectAltName"===n.name||"issuerAltName"===n.name){var l;n.altNames=[],s=t.fromDer(n.value);for(var p=0;p<s.value.length;++p){var d={type:(l=s.value[p]).type,value:l.value};switch(n.altNames.push(d),l.type){case 1:case 2:case 6:break;case 7:d.ip=z.util.bytesToIP(l.value);break;case 8:d.oid=t.derToOid(l.value)}}}else"subjectKeyIdentifier"===n.name&&(s=t.fromDer(n.value),n.subjectKeyIdentifier=z.util.bytesToHex(s.value));return n},n.certificationRequestFromAsn1=function(e,a){var o={},i=[];if(!t.validate(e,c,o,i))throw(u=new Error("Cannot read PKCS#10 certificate request. ASN.1 object is not a PKCS#10 CertificationRequest.")).errors=i,u;if(t.derToOid(o.publicKeyOid)!==n.oids.rsaEncryption)throw new Error("Cannot read public key. OID is not RSA.");var s=n.createCertificationRequest();if(s.version=o.csrVersion?o.csrVersion.charCodeAt(0):0,s.signatureOid=z.asn1.derToOid(o.csrSignatureOid),s.signatureParameters=p(s.signatureOid,o.csrSignatureParams,!0),s.siginfo.algorithmOid=z.asn1.derToOid(o.csrSignatureOid),s.siginfo.parameters=p(s.siginfo.algorithmOid,o.csrSignatureParams,!1),s.signature=o.csrSignature,s.certificationRequestInfo=o.certificationRequestInfo,a){var u;if(s.md=null,s.signatureOid in r)switch(r[s.signatureOid]){case"sha1WithRSAEncryption":s.md=z.md.sha1.create();break;case"md5WithRSAEncryption":s.md=z.md.md5.create();break;case"sha256WithRSAEncryption":s.md=z.md.sha256.create();break;case"sha384WithRSAEncryption":s.md=z.md.sha384.create();break;case"sha512WithRSAEncryption":s.md=z.md.sha512.create();break;case"RSASSA-PSS":s.md=z.md.sha256.create()}if(null===s.md)throw(u=new Error("Could not compute certification request digest. Unknown signature OID.")).signatureOid=s.signatureOid,u;var d=t.toDer(s.certificationRequestInfo);s.md.update(d.getBytes())}var h=z.md.sha1.create();return s.subject.getField=function(e){return l(s.subject,e)},s.subject.addField=function(e){f([e]),s.subject.attributes.push(e)},s.subject.attributes=n.RDNAttributesAsArray(o.certificationRequestInfoSubject,h),s.subject.hash=h.digest().toHex(),s.publicKey=n.publicKeyFromAsn1(o.subjectPublicKeyInfo),s.getAttribute=function(e){return l(s,e)},s.addAttribute=function(e){f([e]),s.attributes.push(e)},s.attributes=n.CRIAttributesAsArray(o.certificationRequestInfoAttributes||[]),s},n.createCertificationRequest=function(){var e={version:0,signatureOid:null,signature:null,siginfo:{}};return e.siginfo.algorithmOid=null,e.subject={},e.subject.getField=function(t){return l(e.subject,t)},e.subject.addField=function(t){f([t]),e.subject.attributes.push(t)},e.subject.attributes=[],e.subject.hash=null,e.publicKey=null,e.attributes=[],e.getAttribute=function(t){return l(e,t)},e.addAttribute=function(t){f([t]),e.attributes.push(t)},e.md=null,e.setSubject=function(t){f(t),e.subject.attributes=t,e.subject.hash=null},e.setAttributes=function(t){f(t),e.attributes=t},e.sign=function(a,o){e.md=o||z.md.sha1.create();var i=r[e.md.algorithm+"WithRSAEncryption"];if(!i){var s=new Error("Could not compute certification request digest. Unknown message digest algorithm OID.");throw s.algorithm=e.md.algorithm,s}e.signatureOid=e.siginfo.algorithmOid=i,e.certificationRequestInfo=n.getCertificationRequestInfo(e);var u=t.toDer(e.certificationRequestInfo);e.md.update(u.getBytes()),e.signature=a.sign(e.md)},e.verify=function(){var a=!1,o=e.md;if(null===o){if(e.signatureOid in r)switch(r[e.signatureOid]){case"sha1WithRSAEncryption":o=z.md.sha1.create();break;case"md5WithRSAEncryption":o=z.md.md5.create();break;case"sha256WithRSAEncryption":o=z.md.sha256.create();break;case"sha384WithRSAEncryption":o=z.md.sha384.create();break;case"sha512WithRSAEncryption":o=z.md.sha512.create();break;case"RSASSA-PSS":o=z.md.sha256.create()}if(null===o)throw(p=new Error("Could not compute certification request digest. Unknown signature OID.")).signatureOid=e.signatureOid,p;var i=e.certificationRequestInfo||n.getCertificationRequestInfo(e),s=t.toDer(i);o.update(s.getBytes())}if(null!==o){var u;switch(e.signatureOid){case r.sha1WithRSAEncryption:break;case r["RSASSA-PSS"]:var c,l,p;if(void 0===(c=r[e.signatureParameters.mgf.hash.algorithmOid])||void 0===z.md[c])throw(p=new Error("Unsupported MGF hash function.")).oid=e.signatureParameters.mgf.hash.algorithmOid,p.name=c,p;if(void 0===(l=r[e.signatureParameters.mgf.algorithmOid])||void 0===z.mgf[l])throw(p=new Error("Unsupported MGF function.")).oid=e.signatureParameters.mgf.algorithmOid,p.name=l,p;if(l=z.mgf[l].create(z.md[c].create()),void 0===(c=r[e.signatureParameters.hash.algorithmOid])||void 0===z.md[c])throw(p=new Error("Unsupported RSASSA-PSS hash function.")).oid=e.signatureParameters.hash.algorithmOid,p.name=c,p;u=z.pss.create(z.md[c].create(),l,e.signatureParameters.saltLength)}a=e.publicKey.verify(o.digest().getBytes(),e.signature,u)}return a},e};var v=new Date("1950-01-01T00:00:00Z"),y=new Date("2050-01-01T00:00:00Z");function b(e){return e>=v&&e<y?t.create(t.Class.UNIVERSAL,t.Type.UTCTIME,!1,t.dateToUtcTime(e)):t.create(t.Class.UNIVERSAL,t.Type.GENERALIZEDTIME,!1,t.dateToGeneralizedTime(e))}n.getTBSCertificate=function(e){var r=b(e.validity.notBefore),a=b(e.validity.notAfter),o=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes())]),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,z.util.hexToBytes(e.serialNumber)),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.siginfo.algorithmOid).getBytes()),m(e.siginfo.algorithmOid,e.siginfo.parameters)]),d(e.issuer),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[r,a]),d(e.subject),n.publicKeyToAsn1(e.publicKey)]);return e.issuer.uniqueId&&o.value.push(t.create(t.Class.CONTEXT_SPECIFIC,1,!0,[t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,String.fromCharCode(0)+e.issuer.uniqueId)])),e.subject.uniqueId&&o.value.push(t.create(t.Class.CONTEXT_SPECIFIC,2,!0,[t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,String.fromCharCode(0)+e.subject.uniqueId)])),e.extensions.length>0&&o.value.push(n.certificateExtensionsToAsn1(e.extensions)),o},n.getCertificationRequestInfo=function(e){return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes()),d(e.subject),n.publicKeyToAsn1(e.publicKey),g(e)])},n.distinguishedNameToAsn1=function(e){return d(e)},n.certificateToAsn1=function(e){var r=e.tbsCertificate||n.getTBSCertificate(e);return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[r,t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.signatureOid).getBytes()),m(e.signatureOid,e.signatureParameters)]),t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},n.certificateExtensionsToAsn1=function(e){var r=t.create(t.Class.CONTEXT_SPECIFIC,3,!0,[]),a=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]);r.value.push(a);for(var o=0;o<e.length;++o)a.value.push(n.certificateExtensionToAsn1(e[o]));return r},n.certificateExtensionToAsn1=function(e){var n=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[]);n.value.push(t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.id).getBytes())),e.critical&&n.value.push(t.create(t.Class.UNIVERSAL,t.Type.BOOLEAN,!1,String.fromCharCode(255)));var r=e.value;return"string"!=typeof e.value&&(r=t.toDer(r).getBytes()),n.value.push(t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r)),n},n.certificationRequestToAsn1=function(e){var r=e.certificationRequestInfo||n.getCertificationRequestInfo(e);return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[r,t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.signatureOid).getBytes()),m(e.signatureOid,e.signatureParameters)]),t.create(t.Class.UNIVERSAL,t.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},n.createCaStore=function(e){var r={certs:{}};function a(e){return o(e),r.certs[e.hash]||null}function o(e){if(!e.hash){var t=z.md.sha1.create();e.attributes=n.RDNAttributesAsArray(d(e),t),e.hash=t.digest().toHex()}}if(r.getIssuer=function(e){return a(e.issuer)},r.addCertificate=function(e){if("string"==typeof e&&(e=z.pki.certificateFromPem(e)),o(e.subject),!r.hasCertificate(e))if(e.subject.hash in r.certs){var t=r.certs[e.subject.hash];z.util.isArray(t)||(t=[t]),t.push(e),r.certs[e.subject.hash]=t}else r.certs[e.subject.hash]=e},r.hasCertificate=function(e){"string"==typeof e&&(e=z.pki.certificateFromPem(e));var r=a(e.subject);if(!r)return!1;z.util.isArray(r)||(r=[r]);for(var o=t.toDer(n.certificateToAsn1(e)).getBytes(),i=0;i<r.length;++i)if(o===t.toDer(n.certificateToAsn1(r[i])).getBytes())return!0;return!1},r.listAllCertificates=function(){var e=[];for(var t in r.certs)if(r.certs.hasOwnProperty(t)){var n=r.certs[t];if(z.util.isArray(n))for(var a=0;a<n.length;++a)e.push(n[a]);else e.push(n)}return e},r.removeCertificate=function(e){var i;if("string"==typeof e&&(e=z.pki.certificateFromPem(e)),o(e.subject),!r.hasCertificate(e))return null;var s=a(e.subject);if(!z.util.isArray(s))return i=r.certs[e.subject.hash],delete r.certs[e.subject.hash],i;for(var u=t.toDer(n.certificateToAsn1(e)).getBytes(),c=0;c<s.length;++c)u===t.toDer(n.certificateToAsn1(s[c])).getBytes()&&(i=s[c],s.splice(c,1));return 0===s.length&&delete r.certs[e.subject.hash],i},e)for(var i=0;i<e.length;++i){var s=e[i];r.addCertificate(s)}return r},n.certificateError={bad_certificate:"forge.pki.BadCertificate",unsupported_certificate:"forge.pki.UnsupportedCertificate",certificate_revoked:"forge.pki.CertificateRevoked",certificate_expired:"forge.pki.CertificateExpired",certificate_unknown:"forge.pki.CertificateUnknown",unknown_ca:"forge.pki.UnknownCertificateAuthority"},n.verifyCertificateChain=function(e,t,r){"function"==typeof r&&(r={verify:r}),r=r||{};var a=(t=t.slice(0)).slice(0),o=r.validityCheckDate;void 0===o&&(o=new Date);var i=!0,s=null,u=0;do{var c=t.shift(),l=null,p=!1;if(o&&(o<c.validity.notBefore||o>c.validity.notAfter)&&(s={message:"Certificate is not valid yet or has expired.",error:n.certificateError.certificate_expired,notBefore:c.validity.notBefore,notAfter:c.validity.notAfter,now:o}),null===s){if(null===(l=t[0]||e.getIssuer(c))&&c.isIssuer(c)&&(p=!0,l=c),l){var d=l;z.util.isArray(d)||(d=[d]);for(var f=!1;!f&&d.length>0;){l=d.shift();try{f=l.verify(c)}catch(e){}}f||(s={message:"Certificate signature is invalid.",error:n.certificateError.bad_certificate})}null!==s||l&&!p||e.hasCertificate(c)||(s={message:"Certificate is not trusted.",error:n.certificateError.unknown_ca})}if(null===s&&l&&!c.isIssuer(l)&&(s={message:"Certificate issuer is invalid.",error:n.certificateError.bad_certificate}),null===s)for(var h={keyUsage:!0,basicConstraints:!0},m=0;null===s&&m<c.extensions.length;++m){var g=c.extensions[m];!g.critical||g.name in h||(s={message:"Certificate has an unsupported critical extension.",error:n.certificateError.unsupported_certificate})}if(null===s&&(!i||0===t.length&&(!l||p))){var v=c.getExtension("basicConstraints"),y=c.getExtension("keyUsage");null!==y&&(y.keyCertSign&&null!==v||(s={message:"Certificate keyUsage or basicConstraints conflict or indicate that the certificate is not a CA. If the certificate is the only one in the chain or isn't the first then the certificate must be a valid CA.",error:n.certificateError.bad_certificate})),null!==s||null===v||v.cA||(s={message:"Certificate basicConstraints indicates the certificate is not a CA.",error:n.certificateError.bad_certificate}),null===s&&null!==y&&"pathLenConstraint"in v&&u-1>v.pathLenConstraint&&(s={message:"Certificate basicConstraints pathLenConstraint violated.",error:n.certificateError.bad_certificate})}var b=null===s||s.error,x=r.verify?r.verify(b,u,a):b;if(!0!==x)throw!0===b&&(s={message:"The application rejected the certificate.",error:n.certificateError.bad_certificate}),(x||0===x)&&("object"!=typeof x||z.util.isArray(x)?"string"==typeof x&&(s.error=x):(x.message&&(s.message=x.message),x.error&&(s.error=x.error))),s;s=null,i=!1,++u}while(t.length>0);return!0}})),w((function(e){var t=z.asn1,n=z.pki,r=e.exports=z.pkcs12=z.pkcs12||{},a={name:"ContentInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"ContentInfo.contentType",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"contentType"},{name:"ContentInfo.content",tagClass:t.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:"content"}]},o={name:"PFX",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},a,{name:"PFX.macData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"mac",value:[{name:"PFX.macData.mac",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.macData.mac.digestAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.macData.mac.digestAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"macAlgorithm"},{name:"PFX.macData.mac.digestAlgorithm.parameters",tagClass:t.Class.UNIVERSAL,captureAsn1:"macAlgorithmParameters"}]},{name:"PFX.macData.mac.digest",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"macDigest"}]},{name:"PFX.macData.macSalt",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"macSalt"},{name:"PFX.macData.iterations",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,optional:!0,capture:"macIterations"}]}]},i={name:"SafeBag",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SafeBag.bagId",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"bagId"},{name:"SafeBag.bagValue",tagClass:t.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:"bagValue"},{name:"SafeBag.bagAttributes",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,optional:!0,capture:"bagAttributes"}]},s={name:"Attribute",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"Attribute.attrId",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"oid"},{name:"Attribute.attrValues",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,capture:"values"}]},u={name:"CertBag",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"CertBag.certId",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"certId"},{name:"CertBag.certValue",tagClass:t.Class.CONTEXT_SPECIFIC,constructed:!0,value:[{name:"CertBag.certValue[0]",tagClass:t.Class.UNIVERSAL,type:t.Class.OCTETSTRING,constructed:!1,capture:"cert"}]}]};function c(e,t,n,r){for(var a=[],o=0;o<e.length;o++)for(var i=0;i<e[o].safeBags.length;i++){var s=e[o].safeBags[i];void 0!==r&&s.type!==r||(null!==t?void 0!==s.attributes[t]&&s.attributes[t].indexOf(n)>=0&&a.push(s):a.push(s))}return a}function l(e){if(e.composed||e.constructed){for(var t=z.util.createBuffer(),n=0;n<e.value.length;++n)t.putBytes(e.value[n].value);e.composed=e.constructed=!1,e.value=t.getBytes()}return e}function p(e,r){var a={},o=[];if(!t.validate(e,z.pkcs7.asn1.encryptedDataValidator,a,o))throw(i=new Error("Cannot read EncryptedContentInfo.")).errors=o,i;var i,s=t.derToOid(a.contentType);if(s!==n.oids.data)throw(i=new Error("PKCS#12 EncryptedContentInfo ContentType is not Data.")).oid=s,i;s=t.derToOid(a.encAlgorithm);var u=n.pbe.getCipher(s,a.encParameter,r),c=l(a.encryptedContentAsn1),p=z.util.createBuffer(c.value);if(u.update(p),!u.finish())throw new Error("Failed to decrypt PKCS#12 SafeContents.");return u.output.getBytes()}function d(e,r,a){if(!r&&0===e.length)return[];if((e=t.fromDer(e,r)).tagClass!==t.Class.UNIVERSAL||e.type!==t.Type.SEQUENCE||!0!==e.constructed)throw new Error("PKCS#12 SafeContents expected to be a SEQUENCE OF SafeBag.");for(var o=[],s=0;s<e.value.length;s++){var c=e.value[s],l={},p=[];if(!t.validate(c,i,l,p))throw(v=new Error("Cannot read SafeBag.")).errors=p,v;var d,h,m={type:t.derToOid(l.bagId),attributes:f(l.bagAttributes)};o.push(m);var g=l.bagValue.value[0];switch(m.type){case n.oids.pkcs8ShroudedKeyBag:if(null===(g=n.decryptPrivateKeyInfo(g,a)))throw new Error("Unable to decrypt PKCS#8 ShroudedKeyBag, wrong password?");case n.oids.keyBag:try{m.key=n.privateKeyFromAsn1(g)}catch(e){m.key=null,m.asn1=g}continue;case n.oids.certBag:d=u,h=function(){if(t.derToOid(l.certId)!==n.oids.x509Certificate){var e=new Error("Unsupported certificate type, only X.509 supported.");throw e.oid=t.derToOid(l.certId),e}var a=t.fromDer(l.cert,r);try{m.cert=n.certificateFromAsn1(a,!0)}catch(e){m.cert=null,m.asn1=a}};break;default:var v;throw(v=new Error("Unsupported PKCS#12 SafeBag type.")).oid=m.type,v}if(void 0!==d&&!t.validate(g,d,l,p))throw(v=new Error("Cannot read PKCS#12 "+d.name)).errors=p,v;h()}return o}function f(e){var r={};if(void 0!==e)for(var a=0;a<e.length;++a){var o={},i=[];if(!t.validate(e[a],s,o,i)){var u=new Error("Cannot read PKCS#12 BagAttribute.");throw u.errors=i,u}var c=t.derToOid(o.oid);if(void 0!==n.oids[c]){r[n.oids[c]]=[];for(var l=0;l<o.values.length;++l)r[n.oids[c]].push(o.values[l].value)}}return r}r.pkcs12FromAsn1=function(e,i,s){"string"==typeof i?(s=i,i=!0):void 0===i&&(i=!0);var u={};if(!t.validate(e,o,u,[]))throw(f=new Error("Cannot read PKCS#12 PFX. ASN.1 object is not an PKCS#12 PFX.")).errors=f,f;var f,h={version:u.version.charCodeAt(0),safeContents:[],getBags:function(e){var t,n={};return"localKeyId"in e?t=e.localKeyId:"localKeyIdHex"in e&&(t=z.util.hexToBytes(e.localKeyIdHex)),void 0===t&&!("friendlyName"in e)&&"bagType"in e&&(n[e.bagType]=c(h.safeContents,null,null,e.bagType)),void 0!==t&&(n.localKeyId=c(h.safeContents,"localKeyId",t,e.bagType)),"friendlyName"in e&&(n.friendlyName=c(h.safeContents,"friendlyName",e.friendlyName,e.bagType)),n},getBagsByFriendlyName:function(e,t){return c(h.safeContents,"friendlyName",e,t)},getBagsByLocalKeyId:function(e,t){return c(h.safeContents,"localKeyId",e,t)}};if(3!==u.version.charCodeAt(0))throw(f=new Error("PKCS#12 PFX of version other than 3 not supported.")).version=u.version.charCodeAt(0),f;if(t.derToOid(u.contentType)!==n.oids.data)throw(f=new Error("Only PKCS#12 PFX in password integrity mode supported.")).oid=t.derToOid(u.contentType),f;var m=u.content.value[0];if(m.tagClass!==t.Class.UNIVERSAL||m.type!==t.Type.OCTETSTRING)throw new Error("PKCS#12 authSafe content data is not an OCTET STRING.");if(m=l(m),u.mac){var g=null,v=0,y=t.derToOid(u.macAlgorithm);switch(y){case n.oids.sha1:g=z.md.sha1.create(),v=20;break;case n.oids.sha256:g=z.md.sha256.create(),v=32;break;case n.oids.sha384:g=z.md.sha384.create(),v=48;break;case n.oids.sha512:g=z.md.sha512.create(),v=64;break;case n.oids.md5:g=z.md.md5.create(),v=16}if(null===g)throw new Error("PKCS#12 uses unsupported MAC algorithm: "+y);var b=new z.util.ByteBuffer(u.macSalt),x="macIterations"in u?parseInt(z.util.bytesToHex(u.macIterations),16):1,w=r.generateKey(s,b,3,x,v,g),k=z.hmac.create();if(k.start(g,w),k.update(m.value),k.getMac().getBytes()!==u.macDigest)throw new Error("PKCS#12 MAC could not be verified. Invalid password?")}return function(e,r,o,i){if((r=t.fromDer(r,o)).tagClass!==t.Class.UNIVERSAL||r.type!==t.Type.SEQUENCE||!0!==r.constructed)throw new Error("PKCS#12 AuthenticatedSafe expected to be a SEQUENCE OF ContentInfo");for(var s=0;s<r.value.length;s++){var u=r.value[s],c={},f=[];if(!t.validate(u,a,c,f))throw(v=new Error("Cannot read ContentInfo.")).errors=f,v;var h={encrypted:!1},m=null,g=c.content.value[0];switch(t.derToOid(c.contentType)){case n.oids.data:if(g.tagClass!==t.Class.UNIVERSAL||g.type!==t.Type.OCTETSTRING)throw new Error("PKCS#12 SafeContents Data is not an OCTET STRING.");m=l(g).value;break;case n.oids.encryptedData:m=p(g,i),h.encrypted=!0;break;default:var v;throw(v=new Error("Unsupported PKCS#12 contentType.")).contentType=t.derToOid(c.contentType),v}h.safeBags=d(m,o,i),e.safeContents.push(h)}}(h,m.value,i,s),h},r.toPkcs12Asn1=function(e,a,o,i){(i=i||{}).saltSize=i.saltSize||8,i.count=i.count||2048,i.algorithm=i.algorithm||i.encAlgorithm||"aes128","useMac"in i||(i.useMac=!0),"localKeyId"in i||(i.localKeyId=null),"generateLocalKeyId"in i||(i.generateLocalKeyId=!0);var s,u=i.localKeyId;if(null!==u)u=z.util.hexToBytes(u);else if(i.generateLocalKeyId)if(a){var c=z.util.isArray(a)?a[0]:a;"string"==typeof c&&(c=n.certificateFromPem(c)),(C=z.md.sha1.create()).update(t.toDer(n.certificateToAsn1(c)).getBytes()),u=C.digest().getBytes()}else u=z.random.getBytes(20);var l=[];null!==u&&l.push(t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.localKeyId).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,u)])])),"friendlyName"in i&&l.push(t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.friendlyName).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[t.create(t.Class.UNIVERSAL,t.Type.BMPSTRING,!1,i.friendlyName)])])),l.length>0&&(s=t.create(t.Class.UNIVERSAL,t.Type.SET,!0,l));var p=[],d=[];null!==a&&(d=z.util.isArray(a)?a:[a]);for(var f=[],h=0;h<d.length;++h){"string"==typeof(a=d[h])&&(a=n.certificateFromPem(a));var m=0===h?s:void 0,g=n.certificateToAsn1(a),v=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.certBag).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.x509Certificate).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,t.toDer(g).getBytes())])])]),m]);f.push(v)}if(f.length>0){var y=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,f),b=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.data).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,t.toDer(y).getBytes())])]);p.push(b)}var x=null;if(null!==e){var w=n.wrapRsaPrivateKey(n.privateKeyToAsn1(e));x=null===o?t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.keyBag).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[w]),s]):t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.pkcs8ShroudedKeyBag).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[n.encryptPrivateKeyInfo(w,o,i)]),s]);var k=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[x]),S=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.data).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,t.toDer(k).getBytes())])]);p.push(S)}var E,I=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,p);if(i.useMac){var C=z.md.sha1.create(),T=new z.util.ByteBuffer(z.random.getBytes(i.saltSize)),_=i.count,N=(e=r.generateKey(o,T,3,_,20),z.hmac.create());N.start(C,e),N.update(t.toDer(I).getBytes());var A=N.getMac();E=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.sha1).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")]),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,A.getBytes())]),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,T.getBytes()),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(_).getBytes())])}return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(3).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.oids.data).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,t.toDer(I).getBytes())])]),E])},r.generateKey=z.pbe.generatePkcs12Key})),w((function(e){var t=z.asn1,n=e.exports=z.pki=z.pki||{};n.pemToDer=function(e){var t=z.pem.decode(e)[0];if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert PEM to DER; PEM is encrypted.");return z.util.createBuffer(t.body)},n.privateKeyFromPem=function(e){var r=z.pem.decode(e)[0];if("PRIVATE KEY"!==r.type&&"RSA PRIVATE KEY"!==r.type){var a=new Error('Could not convert private key from PEM; PEM header type is not "PRIVATE KEY" or "RSA PRIVATE KEY".');throw a.headerType=r.type,a}if(r.procType&&"ENCRYPTED"===r.procType.type)throw new Error("Could not convert private key from PEM; PEM is encrypted.");var o=t.fromDer(r.body);return n.privateKeyFromAsn1(o)},n.privateKeyToPem=function(e,r){var a={type:"RSA PRIVATE KEY",body:t.toDer(n.privateKeyToAsn1(e)).getBytes()};return z.pem.encode(a,{maxline:r})},n.privateKeyInfoToPem=function(e,n){var r={type:"PRIVATE KEY",body:t.toDer(e).getBytes()};return z.pem.encode(r,{maxline:n})}}));var Et=function(e,t,n,r){var a=z.util.createBuffer(),o=e.length>>1,i=o+(1&e.length),s=e.substr(0,i),u=e.substr(o,i),c=z.util.createBuffer(),l=z.hmac.create();n=t+n;var p=Math.ceil(r/16),d=Math.ceil(r/20);l.start("MD5",s);var f=z.util.createBuffer();c.putBytes(n);for(var h=0;h<p;++h)l.start(null,null),l.update(c.getBytes()),c.putBuffer(l.digest()),l.start(null,null),l.update(c.bytes()+n),f.putBuffer(l.digest());l.start("SHA1",u);var m=z.util.createBuffer();for(c.clear(),c.putBytes(n),h=0;h<d;++h)l.start(null,null),l.update(c.getBytes()),c.putBuffer(l.digest()),l.start(null,null),l.update(c.bytes()+n),m.putBuffer(l.digest());return a.putBytes(z.util.xorBytes(f.getBytes(),m.getBytes(),r)),a},It=function(e,t,n){var r=!1;try{var a=e.deflate(t.fragment.getBytes());t.fragment=z.util.createBuffer(a),t.length=a.length,r=!0}catch(e){}return r},Ct=function(e,t,n){var r=!1;try{var a=e.inflate(t.fragment.getBytes());t.fragment=z.util.createBuffer(a),t.length=a.length,r=!0}catch(e){}return r},Tt=function(e,t){var n=0;switch(t){case 1:n=e.getByte();break;case 2:n=e.getInt16();break;case 3:n=e.getInt24();break;case 4:n=e.getInt32()}return z.util.createBuffer(e.getBytes(n))},_t=function(e,t,n){e.putInt(n.length(),t<<3),e.putBuffer(n)},Nt={Versions:{TLS_1_0:{major:3,minor:1},TLS_1_1:{major:3,minor:2},TLS_1_2:{major:3,minor:3}}};Nt.SupportedVersions=[Nt.Versions.TLS_1_1,Nt.Versions.TLS_1_0],Nt.Version=Nt.SupportedVersions[0],Nt.MaxFragment=15360,Nt.ConnectionEnd={server:0,client:1},Nt.PRFAlgorithm={tls_prf_sha256:0},Nt.BulkCipherAlgorithm={none:null,rc4:0,des3:1,aes:2},Nt.CipherType={stream:0,block:1,aead:2},Nt.MACAlgorithm={none:null,hmac_md5:0,hmac_sha1:1,hmac_sha256:2,hmac_sha384:3,hmac_sha512:4},Nt.CompressionMethod={none:0,deflate:1},Nt.ContentType={change_cipher_spec:20,alert:21,handshake:22,application_data:23,heartbeat:24},Nt.HandshakeType={hello_request:0,client_hello:1,server_hello:2,certificate:11,server_key_exchange:12,certificate_request:13,server_hello_done:14,certificate_verify:15,client_key_exchange:16,finished:20},Nt.Alert={},Nt.Alert.Level={warning:1,fatal:2},Nt.Alert.Description={close_notify:0,unexpected_message:10,bad_record_mac:20,decryption_failed:21,record_overflow:22,decompression_failure:30,handshake_failure:40,bad_certificate:42,unsupported_certificate:43,certificate_revoked:44,certificate_expired:45,certificate_unknown:46,illegal_parameter:47,unknown_ca:48,access_denied:49,decode_error:50,decrypt_error:51,export_restriction:60,protocol_version:70,insufficient_security:71,internal_error:80,user_canceled:90,no_renegotiation:100},Nt.HeartbeatMessageType={heartbeat_request:1,heartbeat_response:2},Nt.CipherSuites={},Nt.getCipherSuite=function(e){var t=null;for(var n in Nt.CipherSuites){var r=Nt.CipherSuites[n];if(r.id[0]===e.charCodeAt(0)&&r.id[1]===e.charCodeAt(1)){t=r;break}}return t},Nt.handleUnexpected=function(e,t){!e.open&&e.entity===Nt.ConnectionEnd.client||e.error(e,{message:"Unexpected message. Received TLS record out of order.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.unexpected_message}})},Nt.handleHelloRequest=function(e,t,n){!e.handshaking&&e.handshakes>0&&(Nt.queue(e,Nt.createAlert(e,{level:Nt.Alert.Level.warning,description:Nt.Alert.Description.no_renegotiation})),Nt.flush(e)),e.process()},Nt.parseHelloMessage=function(e,t,n){var r=null,a=e.entity===Nt.ConnectionEnd.client;if(n<38)e.error(e,{message:a?"Invalid ServerHello message. Message too short.":"Invalid ClientHello message. Message too short.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});else{var o=t.fragment,i=o.length();if(r={version:{major:o.getByte(),minor:o.getByte()},random:z.util.createBuffer(o.getBytes(32)),session_id:Tt(o,1),extensions:[]},a?(r.cipher_suite=o.getBytes(2),r.compression_method=o.getByte()):(r.cipher_suites=Tt(o,2),r.compression_methods=Tt(o,1)),(i=n-(i-o.length()))>0){for(var s=Tt(o,2);s.length()>0;)r.extensions.push({type:[s.getByte(),s.getByte()],data:Tt(s,2)});if(!a)for(var u=0;u<r.extensions.length;++u){var c=r.extensions[u];if(0===c.type[0]&&0===c.type[1])for(var l=Tt(c.data,2);l.length()>0&&0===l.getByte();)e.session.extensions.server_name.serverNameList.push(Tt(l,2).getBytes())}}if(e.session.version&&(r.version.major!==e.session.version.major||r.version.minor!==e.session.version.minor))return e.error(e,{message:"TLS version change is disallowed during renegotiation.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.protocol_version}});if(a)e.session.cipherSuite=Nt.getCipherSuite(r.cipher_suite);else for(var p=z.util.createBuffer(r.cipher_suites.bytes());p.length()>0&&(e.session.cipherSuite=Nt.getCipherSuite(p.getBytes(2)),null===e.session.cipherSuite););if(null===e.session.cipherSuite)return e.error(e,{message:"No cipher suites in common.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.handshake_failure},cipherSuite:z.util.bytesToHex(r.cipher_suite)});e.session.compressionMethod=a?r.compression_method:Nt.CompressionMethod.none}return r},Nt.createSecurityParameters=function(e,t){var n=e.entity===Nt.ConnectionEnd.client,r=t.random.bytes(),a=n?e.session.sp.client_random:r,o=n?r:Nt.createRandom().getBytes();e.session.sp={entity:e.entity,prf_algorithm:Nt.PRFAlgorithm.tls_prf_sha256,bulk_cipher_algorithm:null,cipher_type:null,enc_key_length:null,block_length:null,fixed_iv_length:null,record_iv_length:null,mac_algorithm:null,mac_length:null,mac_key_length:null,compression_algorithm:e.session.compressionMethod,pre_master_secret:null,master_secret:null,client_random:a,server_random:o}},Nt.handleServerHello=function(e,t,n){var r=Nt.parseHelloMessage(e,t,n);if(!e.fail){if(!(r.version.minor<=e.version.minor))return e.error(e,{message:"Incompatible TLS version.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.protocol_version}});e.version.minor=r.version.minor,e.session.version=e.version;var a=r.session_id.bytes();a.length>0&&a===e.session.id?(e.expect=Dt,e.session.resuming=!0,e.session.sp.server_random=r.random.bytes()):(e.expect=At,e.session.resuming=!1,Nt.createSecurityParameters(e,r)),e.session.id=a,e.process()}},Nt.handleClientHello=function(e,t,n){var r=Nt.parseHelloMessage(e,t,n);if(!e.fail){var a=r.session_id.bytes(),o=null;if(e.sessionCache&&(null===(o=e.sessionCache.getSession(a))?a="":(o.version.major!==r.version.major||o.version.minor>r.version.minor)&&(o=null,a="")),0===a.length&&(a=z.random.getBytes(32)),e.session.id=a,e.session.clientHelloVersion=r.version,e.session.sp={},o)e.version=e.session.version=o.version,e.session.sp=o.sp;else{for(var i,s=1;s<Nt.SupportedVersions.length&&!((i=Nt.SupportedVersions[s]).minor<=r.version.minor);++s);e.version={major:i.major,minor:i.minor},e.session.version=e.version}null!==o?(e.expect=zt,e.session.resuming=!0,e.session.sp.client_random=r.random.bytes()):(e.expect=!1!==e.verifyClient?Lt:Ut,e.session.resuming=!1,Nt.createSecurityParameters(e,r)),e.open=!0,Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createServerHello(e)})),e.session.resuming?(Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.change_cipher_spec,data:Nt.createChangeCipherSpec()})),e.state.pending=Nt.createConnectionState(e),e.state.current.write=e.state.pending.write,Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createFinished(e)}))):(Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createCertificate(e)})),e.fail||(Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createServerKeyExchange(e)})),!1!==e.verifyClient&&Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createCertificateRequest(e)})),Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createServerHelloDone(e)})))),Nt.flush(e),e.process()}},Nt.handleCertificate=function(e,t,n){if(n<3)return e.error(e,{message:"Invalid Certificate message. Message too short.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});var r,a,o=t.fragment,i={certificate_list:Tt(o,3)},s=[];try{for(;i.certificate_list.length()>0;)r=Tt(i.certificate_list,3),a=z.asn1.fromDer(r),r=z.pki.certificateFromAsn1(a,!0),s.push(r)}catch(t){return e.error(e,{message:"Could not parse certificate list.",cause:t,send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.bad_certificate}})}var u=e.entity===Nt.ConnectionEnd.client;!u&&!0!==e.verifyClient||0!==s.length?0===s.length?e.expect=u?Rt:Ut:(u?e.session.serverCertificate=s[0]:e.session.clientCertificate=s[0],Nt.verifyCertificateChain(e,s)&&(e.expect=u?Rt:Ut)):e.error(e,{message:u?"No server certificate provided.":"No client certificate provided.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}}),e.process()},Nt.handleServerKeyExchange=function(e,t,n){if(n>0)return e.error(e,{message:"Invalid key parameters. Only RSA is supported.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.unsupported_certificate}});e.expect=Ot,e.process()},Nt.handleClientKeyExchange=function(e,t,n){if(n<48)return e.error(e,{message:"Invalid key parameters. Only RSA is supported.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.unsupported_certificate}});var r=t.fragment,a={enc_pre_master_secret:Tt(r,2).getBytes()},o=null;if(e.getPrivateKey)try{o=e.getPrivateKey(e,e.session.serverCertificate),o=z.pki.privateKeyFromPem(o)}catch(t){e.error(e,{message:"Could not get private key.",cause:t,send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}})}if(null===o)return e.error(e,{message:"No private key set.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}});try{var i=e.session.sp;i.pre_master_secret=o.decrypt(a.enc_pre_master_secret);var s=e.session.clientHelloVersion;if(s.major!==i.pre_master_secret.charCodeAt(0)||s.minor!==i.pre_master_secret.charCodeAt(1))throw new Error("TLS version rollback attack detected.")}catch(e){i.pre_master_secret=z.random.getBytes(48)}e.expect=zt,null!==e.session.clientCertificate&&(e.expect=Vt),e.process()},Nt.handleCertificateRequest=function(e,t,n){if(n<3)return e.error(e,{message:"Invalid CertificateRequest. Message too short.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});var r=t.fragment,a={certificate_types:Tt(r,1),certificate_authorities:Tt(r,2)};e.session.certificateRequest=a,e.expect=Bt,e.process()},Nt.handleCertificateVerify=function(e,t,n){if(n<2)return e.error(e,{message:"Invalid CertificateVerify. Message too short.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});var r=t.fragment;r.read-=4;var a=r.bytes();r.read+=4;var o={signature:Tt(r,2).getBytes()},i=z.util.createBuffer();i.putBuffer(e.session.md5.digest()),i.putBuffer(e.session.sha1.digest()),i=i.getBytes();try{if(!e.session.clientCertificate.publicKey.verify(i,o.signature,"NONE"))throw new Error("CertificateVerify signature does not match.");e.session.md5.update(a),e.session.sha1.update(a)}catch(t){return e.error(e,{message:"Bad signature in CertificateVerify.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.handshake_failure}})}e.expect=zt,e.process()},Nt.handleServerHelloDone=function(e,t,n){if(n>0)return e.error(e,{message:"Invalid ServerHelloDone message. Invalid length.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.record_overflow}});if(null===e.serverCertificate){var r={message:"No server certificate provided. Not enough security.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.insufficient_security}},a=e.verify(e,r.alert.description,0,[]);if(!0!==a)return(a||0===a)&&("object"!=typeof a||z.util.isArray(a)?"number"==typeof a&&(r.alert.description=a):(a.message&&(r.message=a.message),a.alert&&(r.alert.description=a.alert))),e.error(e,r)}null!==e.session.certificateRequest&&(t=Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createCertificate(e)}),Nt.queue(e,t)),t=Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createClientKeyExchange(e)}),Nt.queue(e,t),e.expect=Pt;var o=function(e,t){null!==e.session.certificateRequest&&null!==e.session.clientCertificate&&Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createCertificateVerify(e,t)})),Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.change_cipher_spec,data:Nt.createChangeCipherSpec()})),e.state.pending=Nt.createConnectionState(e),e.state.current.write=e.state.pending.write,Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createFinished(e)})),e.expect=Dt,Nt.flush(e),e.process()};if(null===e.session.certificateRequest||null===e.session.clientCertificate)return o(e,null);Nt.getClientSignature(e,o)},Nt.handleChangeCipherSpec=function(e,t){if(1!==t.fragment.getByte())return e.error(e,{message:"Invalid ChangeCipherSpec message received.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.illegal_parameter}});var n=e.entity===Nt.ConnectionEnd.client;(e.session.resuming&&n||!e.session.resuming&&!n)&&(e.state.pending=Nt.createConnectionState(e)),e.state.current.read=e.state.pending.read,(!e.session.resuming&&n||e.session.resuming&&!n)&&(e.state.pending=null),e.expect=n?Mt:jt,e.process()},Nt.handleFinished=function(e,t,n){var r=t.fragment;r.read-=4;var a=r.bytes();r.read+=4;var o=t.fragment.getBytes();(r=z.util.createBuffer()).putBuffer(e.session.md5.digest()),r.putBuffer(e.session.sha1.digest());var i=e.entity===Nt.ConnectionEnd.client,s=i?"server finished":"client finished",u=e.session.sp;if((r=Et(u.master_secret,s,r.getBytes(),12)).getBytes()!==o)return e.error(e,{message:"Invalid verify_data in Finished message.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.decrypt_error}});e.session.md5.update(a),e.session.sha1.update(a),(e.session.resuming&&i||!e.session.resuming&&!i)&&(Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.change_cipher_spec,data:Nt.createChangeCipherSpec()})),e.state.current.write=e.state.pending.write,e.state.pending=null,Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.handshake,data:Nt.createFinished(e)}))),e.expect=i?Ft:Wt,e.handshaking=!1,++e.handshakes,e.peerCertificate=i?e.session.serverCertificate:e.session.clientCertificate,Nt.flush(e),e.isConnected=!0,e.connected(e),e.process()},Nt.handleAlert=function(e,t){var n,r=t.fragment,a={level:r.getByte(),description:r.getByte()};switch(a.description){case Nt.Alert.Description.close_notify:n="Connection closed.";break;case Nt.Alert.Description.unexpected_message:n="Unexpected message.";break;case Nt.Alert.Description.bad_record_mac:n="Bad record MAC.";break;case Nt.Alert.Description.decryption_failed:n="Decryption failed.";break;case Nt.Alert.Description.record_overflow:n="Record overflow.";break;case Nt.Alert.Description.decompression_failure:n="Decompression failed.";break;case Nt.Alert.Description.handshake_failure:n="Handshake failure.";break;case Nt.Alert.Description.bad_certificate:n="Bad certificate.";break;case Nt.Alert.Description.unsupported_certificate:n="Unsupported certificate.";break;case Nt.Alert.Description.certificate_revoked:n="Certificate revoked.";break;case Nt.Alert.Description.certificate_expired:n="Certificate expired.";break;case Nt.Alert.Description.certificate_unknown:n="Certificate unknown.";break;case Nt.Alert.Description.illegal_parameter:n="Illegal parameter.";break;case Nt.Alert.Description.unknown_ca:n="Unknown certificate authority.";break;case Nt.Alert.Description.access_denied:n="Access denied.";break;case Nt.Alert.Description.decode_error:n="Decode error.";break;case Nt.Alert.Description.decrypt_error:n="Decrypt error.";break;case Nt.Alert.Description.export_restriction:n="Export restriction.";break;case Nt.Alert.Description.protocol_version:n="Unsupported protocol version.";break;case Nt.Alert.Description.insufficient_security:n="Insufficient security.";break;case Nt.Alert.Description.internal_error:n="Internal error.";break;case Nt.Alert.Description.user_canceled:n="User canceled.";break;case Nt.Alert.Description.no_renegotiation:n="Renegotiation not supported.";break;default:n="Unknown error."}if(a.description===Nt.Alert.Description.close_notify)return e.close();e.error(e,{message:n,send:!1,origin:e.entity===Nt.ConnectionEnd.client?"server":"client",alert:a}),e.process()},Nt.handleHandshake=function(e,t){var n=t.fragment,r=n.getByte(),a=n.getInt24();if(a>n.length())return e.fragmented=t,t.fragment=z.util.createBuffer(),n.read-=4,e.process();e.fragmented=null,n.read-=4;var o=n.bytes(a+4);n.read+=4,r in an[e.entity][e.expect]?(e.entity!==Nt.ConnectionEnd.server||e.open||e.fail||(e.handshaking=!0,e.session={version:null,extensions:{server_name:{serverNameList:[]}},cipherSuite:null,compressionMethod:null,serverCertificate:null,clientCertificate:null,md5:z.md.md5.create(),sha1:z.md.sha1.create()}),r!==Nt.HandshakeType.hello_request&&r!==Nt.HandshakeType.certificate_verify&&r!==Nt.HandshakeType.finished&&(e.session.md5.update(o),e.session.sha1.update(o)),an[e.entity][e.expect][r](e,t,a)):Nt.handleUnexpected(e,t)},Nt.handleApplicationData=function(e,t){e.data.putBuffer(t.fragment),e.dataReady(e),e.process()},Nt.handleHeartbeat=function(e,t){var n=t.fragment,r=n.getByte(),a=n.getInt16(),o=n.getBytes(a);if(r===Nt.HeartbeatMessageType.heartbeat_request){if(e.handshaking||a>o.length)return e.process();Nt.queue(e,Nt.createRecord(e,{type:Nt.ContentType.heartbeat,data:Nt.createHeartbeat(Nt.HeartbeatMessageType.heartbeat_response,o)})),Nt.flush(e)}else if(r===Nt.HeartbeatMessageType.heartbeat_response){if(o!==e.expectedHeartbeatPayload)return e.process();e.heartbeatReceived&&e.heartbeatReceived(e,z.util.createBuffer(o))}e.process()};var At=1,Rt=2,Ot=3,Bt=4,Dt=5,Mt=6,Ft=7,Pt=8,Lt=1,Ut=2,Vt=3,zt=4,jt=5,Wt=6,Ht=Nt.handleUnexpected,Gt=Nt.handleChangeCipherSpec,Kt=Nt.handleAlert,qt=Nt.handleHandshake,Qt=Nt.handleApplicationData,Xt=Nt.handleHeartbeat,Yt=[];Yt[Nt.ConnectionEnd.client]=[[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Gt,Kt,Ht,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Qt,Xt],[Ht,Kt,qt,Ht,Xt]],Yt[Nt.ConnectionEnd.server]=[[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Gt,Kt,Ht,Ht,Xt],[Ht,Kt,qt,Ht,Xt],[Ht,Kt,qt,Qt,Xt],[Ht,Kt,qt,Ht,Xt]];var $t=Nt.handleHelloRequest,Zt=Nt.handleServerHello,Jt=Nt.handleCertificate,en=Nt.handleServerKeyExchange,tn=Nt.handleCertificateRequest,nn=Nt.handleServerHelloDone,rn=Nt.handleFinished,an=[];an[Nt.ConnectionEnd.client]=[[Ht,Ht,Zt,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Jt,en,tn,nn,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,en,tn,nn,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,tn,nn,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,nn,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,rn],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[$t,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht]];var on=Nt.handleClientHello,sn=Nt.handleClientKeyExchange,un=Nt.handleCertificateVerify;an[Nt.ConnectionEnd.server]=[[Ht,on,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Jt,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,sn,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,un,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,rn],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht],[Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht,Ht]],Nt.generateKeys=function(e,t){var n=Et,r=t.client_random+t.server_random;e.session.resuming||(t.master_secret=n(t.pre_master_secret,"master secret",r,48).bytes(),t.pre_master_secret=null),r=t.server_random+t.client_random;var a=2*t.mac_key_length+2*t.enc_key_length,o=e.version.major===Nt.Versions.TLS_1_0.major&&e.version.minor===Nt.Versions.TLS_1_0.minor;o&&(a+=2*t.fixed_iv_length);var i=n(t.master_secret,"key expansion",r,a),s={client_write_MAC_key:i.getBytes(t.mac_key_length),server_write_MAC_key:i.getBytes(t.mac_key_length),client_write_key:i.getBytes(t.enc_key_length),server_write_key:i.getBytes(t.enc_key_length)};return o&&(s.client_write_IV=i.getBytes(t.fixed_iv_length),s.server_write_IV=i.getBytes(t.fixed_iv_length)),s},Nt.createConnectionState=function(e){var t=e.entity===Nt.ConnectionEnd.client,n=function(){var e={sequenceNumber:[0,0],macKey:null,macLength:0,macFunction:null,cipherState:null,cipherFunction:function(e){return!0},compressionState:null,compressFunction:function(e){return!0},updateSequenceNumber:function(){4294967295===e.sequenceNumber[1]?(e.sequenceNumber[1]=0,++e.sequenceNumber[0]):++e.sequenceNumber[1]}};return e},r={read:n(),write:n()};if(r.read.update=function(e,t){return r.read.cipherFunction(t,r.read)?r.read.compressFunction(e,t,r.read)||e.error(e,{message:"Could not decompress record.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.decompression_failure}}):e.error(e,{message:"Could not decrypt record or bad MAC.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.bad_record_mac}}),!e.fail},r.write.update=function(e,t){return r.write.compressFunction(e,t,r.write)?r.write.cipherFunction(t,r.write)||e.error(e,{message:"Could not encrypt record.",send:!1,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}}):e.error(e,{message:"Could not compress record.",send:!1,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}}),!e.fail},e.session){var a=e.session.sp;switch(e.session.cipherSuite.initSecurityParameters(a),a.keys=Nt.generateKeys(e,a),r.read.macKey=t?a.keys.server_write_MAC_key:a.keys.client_write_MAC_key,r.write.macKey=t?a.keys.client_write_MAC_key:a.keys.server_write_MAC_key,e.session.cipherSuite.initConnectionState(r,e,a),a.compression_algorithm){case Nt.CompressionMethod.none:break;case Nt.CompressionMethod.deflate:r.read.compressFunction=Ct,r.write.compressFunction=It;break;default:throw new Error("Unsupported compression algorithm.")}}return r},Nt.createRandom=function(){var e=new Date,t=+e+6e4*e.getTimezoneOffset(),n=z.util.createBuffer();return n.putInt32(t),n.putBytes(z.random.getBytes(28)),n},Nt.createRecord=function(e,t){return t.data?{type:t.type,version:{major:e.version.major,minor:e.version.minor},length:t.data.length(),fragment:t.data}:null},Nt.createAlert=function(e,t){var n=z.util.createBuffer();return n.putByte(t.level),n.putByte(t.description),Nt.createRecord(e,{type:Nt.ContentType.alert,data:n})},Nt.createClientHello=function(e){e.session.clientHelloVersion={major:e.version.major,minor:e.version.minor};for(var t=z.util.createBuffer(),n=0;n<e.cipherSuites.length;++n){var r=e.cipherSuites[n];t.putByte(r.id[0]),t.putByte(r.id[1])}var a=t.length(),o=z.util.createBuffer();o.putByte(Nt.CompressionMethod.none);var i=o.length(),s=z.util.createBuffer();if(e.virtualHost){var u=z.util.createBuffer();u.putByte(0),u.putByte(0);var c=z.util.createBuffer();c.putByte(0),_t(c,2,z.util.createBuffer(e.virtualHost));var l=z.util.createBuffer();_t(l,2,c),_t(u,2,l),s.putBuffer(u)}var p=s.length();p>0&&(p+=2);var d=e.session.id,f=d.length+1+2+4+28+2+a+1+i+p,h=z.util.createBuffer();return h.putByte(Nt.HandshakeType.client_hello),h.putInt24(f),h.putByte(e.version.major),h.putByte(e.version.minor),h.putBytes(e.session.sp.client_random),_t(h,1,z.util.createBuffer(d)),_t(h,2,t),_t(h,1,o),p>0&&_t(h,2,s),h},Nt.createServerHello=function(e){var t=e.session.id,n=t.length+1+2+4+28+2+1,r=z.util.createBuffer();return r.putByte(Nt.HandshakeType.server_hello),r.putInt24(n),r.putByte(e.version.major),r.putByte(e.version.minor),r.putBytes(e.session.sp.server_random),_t(r,1,z.util.createBuffer(t)),r.putByte(e.session.cipherSuite.id[0]),r.putByte(e.session.cipherSuite.id[1]),r.putByte(e.session.compressionMethod),r},Nt.createCertificate=function(e){var t,n=e.entity===Nt.ConnectionEnd.client,r=null;e.getCertificate&&(t=n?e.session.certificateRequest:e.session.extensions.server_name.serverNameList,r=e.getCertificate(e,t));var a=z.util.createBuffer();if(null!==r)try{z.util.isArray(r)||(r=[r]);for(var o=null,i=0;i<r.length;++i){var s=z.pem.decode(r[i])[0];if("CERTIFICATE"!==s.type&&"X509 CERTIFICATE"!==s.type&&"TRUSTED CERTIFICATE"!==s.type){var u=new Error('Could not convert certificate from PEM; PEM header type is not "CERTIFICATE", "X509 CERTIFICATE", or "TRUSTED CERTIFICATE".');throw u.headerType=s.type,u}if(s.procType&&"ENCRYPTED"===s.procType.type)throw new Error("Could not convert certificate from PEM; PEM is encrypted.");var c=z.util.createBuffer(s.body);null===o&&(o=z.asn1.fromDer(c.bytes(),!1));var l=z.util.createBuffer();_t(l,3,c),a.putBuffer(l)}r=z.pki.certificateFromAsn1(o),n?e.session.clientCertificate=r:e.session.serverCertificate=r}catch(t){return e.error(e,{message:"Could not send certificate list.",cause:t,send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.bad_certificate}})}var p=3+a.length(),d=z.util.createBuffer();return d.putByte(Nt.HandshakeType.certificate),d.putInt24(p),_t(d,3,a),d},Nt.createClientKeyExchange=function(e){var t=z.util.createBuffer();t.putByte(e.session.clientHelloVersion.major),t.putByte(e.session.clientHelloVersion.minor),t.putBytes(z.random.getBytes(46));var n=e.session.sp;n.pre_master_secret=t.getBytes();var r=(t=e.session.serverCertificate.publicKey.encrypt(n.pre_master_secret)).length+2,a=z.util.createBuffer();return a.putByte(Nt.HandshakeType.client_key_exchange),a.putInt24(r),a.putInt16(t.length),a.putBytes(t),a},Nt.createServerKeyExchange=function(e){return z.util.createBuffer()},Nt.getClientSignature=function(e,t){var n=z.util.createBuffer();n.putBuffer(e.session.md5.digest()),n.putBuffer(e.session.sha1.digest()),n=n.getBytes(),e.getSignature=e.getSignature||function(e,t,n){var r=null;if(e.getPrivateKey)try{r=e.getPrivateKey(e,e.session.clientCertificate),r=z.pki.privateKeyFromPem(r)}catch(t){e.error(e,{message:"Could not get private key.",cause:t,send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}})}null===r?e.error(e,{message:"No private key set.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.internal_error}}):t=r.sign(t,null),n(e,t)},e.getSignature(e,n,t)},Nt.createCertificateVerify=function(e,t){var n=t.length+2,r=z.util.createBuffer();return r.putByte(Nt.HandshakeType.certificate_verify),r.putInt24(n),r.putInt16(t.length),r.putBytes(t),r},Nt.createCertificateRequest=function(e){var t=z.util.createBuffer();t.putByte(1);var n=z.util.createBuffer();for(var r in e.caStore.certs){var a=e.caStore.certs[r],o=z.pki.distinguishedNameToAsn1(a.subject),i=z.asn1.toDer(o);n.putInt16(i.length()),n.putBuffer(i)}var s=1+t.length()+2+n.length(),u=z.util.createBuffer();return u.putByte(Nt.HandshakeType.certificate_request),u.putInt24(s),_t(u,1,t),_t(u,2,n),u},Nt.createServerHelloDone=function(e){var t=z.util.createBuffer();return t.putByte(Nt.HandshakeType.server_hello_done),t.putInt24(0),t},Nt.createChangeCipherSpec=function(){var e=z.util.createBuffer();return e.putByte(1),e},Nt.createFinished=function(e){var t=z.util.createBuffer();t.putBuffer(e.session.md5.digest()),t.putBuffer(e.session.sha1.digest());var n=e.entity===Nt.ConnectionEnd.client,r=e.session.sp,a=n?"client finished":"server finished";t=Et(r.master_secret,a,t.getBytes(),12);var o=z.util.createBuffer();return o.putByte(Nt.HandshakeType.finished),o.putInt24(t.length()),o.putBuffer(t),o},Nt.createHeartbeat=function(e,t,n){void 0===n&&(n=t.length);var r=z.util.createBuffer();r.putByte(e),r.putInt16(n),r.putBytes(t);var a=r.length(),o=Math.max(16,a-n-3);return r.putBytes(z.random.getBytes(o)),r},Nt.queue=function(e,t){if(t&&(0!==t.fragment.length()||t.type!==Nt.ContentType.handshake&&t.type!==Nt.ContentType.alert&&t.type!==Nt.ContentType.change_cipher_spec)){if(t.type===Nt.ContentType.handshake){var n=t.fragment.bytes();e.session.md5.update(n),e.session.sha1.update(n),n=null}var r;if(t.fragment.length()<=Nt.MaxFragment)r=[t];else{r=[];for(var a=t.fragment.bytes();a.length>Nt.MaxFragment;)r.push(Nt.createRecord(e,{type:t.type,data:z.util.createBuffer(a.slice(0,Nt.MaxFragment))})),a=a.slice(Nt.MaxFragment);a.length>0&&r.push(Nt.createRecord(e,{type:t.type,data:z.util.createBuffer(a)}))}for(var o=0;o<r.length&&!e.fail;++o){var i=r[o];e.state.current.write.update(e,i)&&e.records.push(i)}}},Nt.flush=function(e){for(var t=0;t<e.records.length;++t){var n=e.records[t];e.tlsData.putByte(n.type),e.tlsData.putByte(n.version.major),e.tlsData.putByte(n.version.minor),e.tlsData.putInt16(n.fragment.length()),e.tlsData.putBuffer(e.records[t].fragment)}return e.records=[],e.tlsDataReady(e)};var cn=function(e){switch(e){case!0:return!0;case z.pki.certificateError.bad_certificate:return Nt.Alert.Description.bad_certificate;case z.pki.certificateError.unsupported_certificate:return Nt.Alert.Description.unsupported_certificate;case z.pki.certificateError.certificate_revoked:return Nt.Alert.Description.certificate_revoked;case z.pki.certificateError.certificate_expired:return Nt.Alert.Description.certificate_expired;case z.pki.certificateError.certificate_unknown:return Nt.Alert.Description.certificate_unknown;case z.pki.certificateError.unknown_ca:return Nt.Alert.Description.unknown_ca;default:return Nt.Alert.Description.bad_certificate}};for(var ln in Nt.verifyCertificateChain=function(e,t){try{var n={};for(var r in e.verifyOptions)n[r]=e.verifyOptions[r];n.verify=function(t,n,r){cn(t);var a=e.verify(e,t,n,r);if(!0!==a){if("object"==typeof a&&!z.util.isArray(a)){var o=new Error("The application rejected the certificate.");throw o.send=!0,o.alert={level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.bad_certificate},a.message&&(o.message=a.message),a.alert&&(o.alert.description=a.alert),o}a!==t&&(a=function(e){switch(e){case!0:return!0;case Nt.Alert.Description.bad_certificate:return z.pki.certificateError.bad_certificate;case Nt.Alert.Description.unsupported_certificate:return z.pki.certificateError.unsupported_certificate;case Nt.Alert.Description.certificate_revoked:return z.pki.certificateError.certificate_revoked;case Nt.Alert.Description.certificate_expired:return z.pki.certificateError.certificate_expired;case Nt.Alert.Description.certificate_unknown:return z.pki.certificateError.certificate_unknown;case Nt.Alert.Description.unknown_ca:return z.pki.certificateError.unknown_ca;default:return z.pki.certificateError.bad_certificate}}(a))}return a},z.pki.verifyCertificateChain(e.caStore,t,n)}catch(t){var a=t;("object"!=typeof a||z.util.isArray(a))&&(a={send:!0,alert:{level:Nt.Alert.Level.fatal,description:cn(t)}}),"send"in a||(a.send=!0),"alert"in a||(a.alert={level:Nt.Alert.Level.fatal,description:cn(a.error)}),e.error(e,a)}return!e.fail},Nt.createSessionCache=function(e,t){var n=null;if(e&&e.getSession&&e.setSession&&e.order)n=e;else{for(var r in(n={}).cache=e||{},n.capacity=Math.max(t||100,1),n.order=[],e)n.order.length<=t?n.order.push(r):delete e[r];n.getSession=function(e){var t=null,r=null;if(e?r=z.util.bytesToHex(e):n.order.length>0&&(r=n.order[0]),null!==r&&r in n.cache)for(var a in t=n.cache[r],delete n.cache[r],n.order)if(n.order[a]===r){n.order.splice(a,1);break}return t},n.setSession=function(e,t){if(n.order.length===n.capacity){var r=n.order.shift();delete n.cache[r]}r=z.util.bytesToHex(e),n.order.push(r),n.cache[r]=t}}return n},Nt.createConnection=function(e){var t=null;t=e.caStore?z.util.isArray(e.caStore)?z.pki.createCaStore(e.caStore):e.caStore:z.pki.createCaStore();var n=e.cipherSuites||null;if(null===n)for(var r in n=[],Nt.CipherSuites)n.push(Nt.CipherSuites[r]);var a=e.server?Nt.ConnectionEnd.server:Nt.ConnectionEnd.client,o=e.sessionCache?Nt.createSessionCache(e.sessionCache):null,i={version:{major:Nt.Version.major,minor:Nt.Version.minor},entity:a,sessionId:e.sessionId,caStore:t,sessionCache:o,cipherSuites:n,connected:e.connected,virtualHost:e.virtualHost||null,verifyClient:e.verifyClient||!1,verify:e.verify||function(e,t,n,r){return t},verifyOptions:e.verifyOptions||{},getCertificate:e.getCertificate||null,getPrivateKey:e.getPrivateKey||null,getSignature:e.getSignature||null,input:z.util.createBuffer(),tlsData:z.util.createBuffer(),data:z.util.createBuffer(),tlsDataReady:e.tlsDataReady,dataReady:e.dataReady,heartbeatReceived:e.heartbeatReceived,closed:e.closed,error:function(t,n){n.origin=n.origin||(t.entity===Nt.ConnectionEnd.client?"client":"server"),n.send&&(Nt.queue(t,Nt.createAlert(t,n.alert)),Nt.flush(t));var r=!1!==n.fatal;r&&(t.fail=!0),e.error(t,n),r&&t.close(!1)},deflate:e.deflate||null,inflate:e.inflate||null,reset:function(e){i.version={major:Nt.Version.major,minor:Nt.Version.minor},i.record=null,i.session=null,i.peerCertificate=null,i.state={pending:null,current:null},i.expect=(Nt.ConnectionEnd.client,0),i.fragmented=null,i.records=[],i.open=!1,i.handshakes=0,i.handshaking=!1,i.isConnected=!1,i.fail=!(e||void 0===e),i.input.clear(),i.tlsData.clear(),i.data.clear(),i.state.current=Nt.createConnectionState(i)}};return i.reset(),i.handshake=function(e){if(i.entity!==Nt.ConnectionEnd.client)i.error(i,{message:"Cannot initiate handshake as a server.",fatal:!1});else if(i.handshaking)i.error(i,{message:"Handshake already in progress.",fatal:!1});else{i.fail&&!i.open&&0===i.handshakes&&(i.fail=!1),i.handshaking=!0;var t=null;(e=e||"").length>0&&(i.sessionCache&&(t=i.sessionCache.getSession(e)),null===t&&(e="")),0===e.length&&i.sessionCache&&null!==(t=i.sessionCache.getSession())&&(e=t.id),i.session={id:e,version:null,cipherSuite:null,compressionMethod:null,serverCertificate:null,certificateRequest:null,clientCertificate:null,sp:{},md5:z.md.md5.create(),sha1:z.md.sha1.create()},t&&(i.version=t.version,i.session.sp=t.sp),i.session.sp.client_random=Nt.createRandom().getBytes(),i.open=!0,Nt.queue(i,Nt.createRecord(i,{type:Nt.ContentType.handshake,data:Nt.createClientHello(i)})),Nt.flush(i)}},i.process=function(e){var t=0;return e&&i.input.putBytes(e),i.fail||(null!==i.record&&i.record.ready&&i.record.fragment.isEmpty()&&(i.record=null),null===i.record&&(t=function(e){var t=0,n=e.input,r=n.length();if(r<5)t=5-r;else{e.record={type:n.getByte(),version:{major:n.getByte(),minor:n.getByte()},length:n.getInt16(),fragment:z.util.createBuffer(),ready:!1};var a=e.record.version.major===e.version.major;a&&e.session&&e.session.version&&(a=e.record.version.minor===e.version.minor),a||e.error(e,{message:"Incompatible TLS version.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.protocol_version}})}return t}(i)),i.fail||null===i.record||i.record.ready||(t=function(e){var t=0,n=e.input,r=n.length();return r<e.record.length?t=e.record.length-r:(e.record.fragment.putBytes(n.getBytes(e.record.length)),n.compact(),e.state.current.read.update(e,e.record)&&(null!==e.fragmented&&(e.fragmented.type===e.record.type?(e.fragmented.fragment.putBuffer(e.record.fragment),e.record=e.fragmented):e.error(e,{message:"Invalid fragmented record.",send:!0,alert:{level:Nt.Alert.Level.fatal,description:Nt.Alert.Description.unexpected_message}})),e.record.ready=!0)),t}(i)),!i.fail&&null!==i.record&&i.record.ready&&function(e,t){var n=t.type-Nt.ContentType.change_cipher_spec,r=Yt[e.entity][e.expect];n in r?r[n](e,t):Nt.handleUnexpected(e,t)}(i,i.record)),t},i.prepare=function(e){return Nt.queue(i,Nt.createRecord(i,{type:Nt.ContentType.application_data,data:z.util.createBuffer(e)})),Nt.flush(i)},i.prepareHeartbeatRequest=function(e,t){return e instanceof z.util.ByteBuffer&&(e=e.bytes()),void 0===t&&(t=e.length),i.expectedHeartbeatPayload=e,Nt.queue(i,Nt.createRecord(i,{type:Nt.ContentType.heartbeat,data:Nt.createHeartbeat(Nt.HeartbeatMessageType.heartbeat_request,e,t)})),Nt.flush(i)},i.close=function(e){if(!i.fail&&i.sessionCache&&i.session){var t={id:i.session.id,version:i.session.version,sp:i.session.sp};t.sp.keys=null,i.sessionCache.setSession(t.id,t)}i.open&&(i.open=!1,i.input.clear(),(i.isConnected||i.handshaking)&&(i.isConnected=i.handshaking=!1,Nt.queue(i,Nt.createAlert(i,{level:Nt.Alert.Level.warning,description:Nt.Alert.Description.close_notify})),Nt.flush(i)),i.closed(i)),i.reset(e)},i},z.tls=z.tls||{},Nt)"function"!=typeof Nt[ln]&&(z.tls[ln]=Nt[ln]);z.tls.prf_tls1=Et,z.tls.hmac_sha1=function(e,t,n){var r=z.hmac.create();r.start("SHA1",e);var a=z.util.createBuffer();return a.putInt32(t[0]),a.putInt32(t[1]),a.putByte(n.type),a.putByte(n.version.major),a.putByte(n.version.minor),a.putInt16(n.length),a.putBytes(n.fragment.bytes()),r.update(a.getBytes()),r.digest().getBytes()},z.tls.createSessionCache=Nt.createSessionCache,z.tls.createConnection=Nt.createConnection,w((function(e){var t=e.exports=z.tls;function n(e,n,a){var o=n.entity===z.tls.ConnectionEnd.client;e.read.cipherState={init:!1,cipher:z.cipher.createDecipher("AES-CBC",o?a.keys.server_write_key:a.keys.client_write_key),iv:o?a.keys.server_write_IV:a.keys.client_write_IV},e.write.cipherState={init:!1,cipher:z.cipher.createCipher("AES-CBC",o?a.keys.client_write_key:a.keys.server_write_key),iv:o?a.keys.client_write_IV:a.keys.server_write_IV},e.read.cipherFunction=i,e.write.cipherFunction=r,e.read.macLength=e.write.macLength=a.mac_length,e.read.macFunction=e.write.macFunction=t.hmac_sha1}function r(e,n){var r,o=!1,i=n.macFunction(n.macKey,n.sequenceNumber,e);e.fragment.putBytes(i),n.updateSequenceNumber(),r=e.version.minor===t.Versions.TLS_1_0.minor?n.cipherState.init?null:n.cipherState.iv:z.random.getBytesSync(16),n.cipherState.init=!0;var s=n.cipherState.cipher;return s.start({iv:r}),e.version.minor>=t.Versions.TLS_1_1.minor&&s.output.putBytes(r),s.update(e.fragment),s.finish(a)&&(e.fragment=s.output,e.length=e.fragment.length(),o=!0),o}function a(e,t,n){if(!n){var r=e-t.length()%e;t.fillWithByte(r-1,r)}return!0}function o(e,t,n){var r=!0;if(n){for(var a=t.length(),o=t.last(),i=a-1-o;i<a-1;++i)r=r&&t.at(i)==o;r&&t.truncate(o+1)}return r}function i(e,n){var r,a=!1;r=e.version.minor===t.Versions.TLS_1_0.minor?n.cipherState.init?null:n.cipherState.iv:e.fragment.getBytes(16),n.cipherState.init=!0;var i=n.cipherState.cipher;i.start({iv:r}),i.update(e.fragment),a=i.finish(o);var s=n.macLength,u=z.random.getBytesSync(s),c=i.output.length();c>=s?(e.fragment=i.output.getBytes(c-s),u=i.output.getBytes(s)):e.fragment=i.output.getBytes(),e.fragment=z.util.createBuffer(e.fragment),e.length=e.fragment.length();var l=n.macFunction(n.macKey,n.sequenceNumber,e);return n.updateSequenceNumber(),function(e,t,n){var r=z.hmac.create();return r.start("SHA1",e),r.update(t),t=r.digest().getBytes(),r.start(null,null),r.update(n),t===(n=r.digest().getBytes())}(n.macKey,u,l)&&a}t.CipherSuites.TLS_RSA_WITH_AES_128_CBC_SHA={id:[0,47],name:"TLS_RSA_WITH_AES_128_CBC_SHA",initSecurityParameters:function(e){e.bulk_cipher_algorithm=t.BulkCipherAlgorithm.aes,e.cipher_type=t.CipherType.block,e.enc_key_length=16,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=t.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:n},t.CipherSuites.TLS_RSA_WITH_AES_256_CBC_SHA={id:[0,53],name:"TLS_RSA_WITH_AES_256_CBC_SHA",initSecurityParameters:function(e){e.bulk_cipher_algorithm=t.BulkCipherAlgorithm.aes,e.cipher_type=t.CipherType.block,e.enc_key_length=32,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=t.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:n}})),z.debug=z.debug||{},z.debug.storage={},z.debug.get=function(e,t){var n;return void 0===e?n=z.debug.storage:e in z.debug.storage&&(n=void 0===t?z.debug.storage[e]:z.debug.storage[e][t]),n},z.debug.set=function(e,t,n){e in z.debug.storage||(z.debug.storage[e]={}),z.debug.storage[e][t]=n},z.debug.clear=function(e,t){void 0===e?z.debug.storage={}:e in z.debug.storage&&(void 0===t?delete z.debug.storage[e]:delete z.debug.storage[e][t])},w((function(e){var t=e.exports=z.sha512=z.sha512||{};z.md.sha512=z.md.algorithms.sha512=t;var n=z.sha384=z.sha512.sha384=z.sha512.sha384||{};n.create=function(){return t.create("SHA-384")},z.md.sha384=z.md.algorithms.sha384=n,z.sha512.sha256=z.sha512.sha256||{create:function(){return t.create("SHA-512/256")}},z.md["sha512/256"]=z.md.algorithms["sha512/256"]=z.sha512.sha256,z.sha512.sha224=z.sha512.sha224||{create:function(){return t.create("SHA-512/224")}},z.md["sha512/224"]=z.md.algorithms["sha512/224"]=z.sha512.sha224,t.create=function(e){if(a||(r=String.fromCharCode(128),r+=z.util.fillString(String.fromCharCode(0),128),o=[[1116352408,3609767458],[1899447441,602891725],[3049323471,3964484399],[3921009573,2173295548],[961987163,4081628472],[1508970993,3053834265],[2453635748,2937671579],[2870763221,3664609560],[3624381080,2734883394],[310598401,1164996542],[607225278,1323610764],[1426881987,3590304994],[1925078388,4068182383],[2162078206,991336113],[2614888103,633803317],[3248222580,3479774868],[3835390401,2666613458],[4022224774,944711139],[264347078,2341262773],[604807628,2007800933],[770255983,1495990901],[1249150122,1856431235],[1555081692,3175218132],[1996064986,2198950837],[2554220882,3999719339],[2821834349,766784016],[2952996808,2566594879],[3210313671,3203337956],[3336571891,1034457026],[3584528711,2466948901],[113926993,3758326383],[338241895,168717936],[666307205,1188179964],[773529912,1546045734],[1294757372,1522805485],[1396182291,2643833823],[1695183700,2343527390],[1986661051,1014477480],[2177026350,1206759142],[2456956037,344077627],[2730485921,1290863460],[2820302411,3158454273],[3259730800,3505952657],[3345764771,106217008],[3516065817,3606008344],[3600352804,1432725776],[4094571909,1467031594],[275423344,851169720],[430227734,3100823752],[506948616,1363258195],[659060556,3750685593],[883997877,3785050280],[958139571,3318307427],[1322822218,3812723403],[1537002063,2003034995],[1747873779,3602036899],[1955562222,1575990012],[2024104815,1125592928],[2227730452,2716904306],[2361852424,442776044],[2428436474,593698344],[2756734187,3733110249],[3204031479,2999351573],[3329325298,3815920427],[3391569614,3928383900],[3515267271,566280711],[3940187606,3454069534],[4118630271,4000239992],[116418474,1914138554],[174292421,2731055270],[289380356,3203993006],[460393269,320620315],[685471733,587496836],[852142971,1086792851],[1017036298,365543100],[1126000580,2618297676],[1288033470,3409855158],[1501505948,4234509866],[1607167915,987167468],[1816402316,1246189591]],(i={})["SHA-512"]=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]],i["SHA-384"]=[[3418070365,3238371032],[1654270250,914150663],[2438529370,812702999],[355462360,4144912697],[1731405415,4290775857],[2394180231,1750603025],[3675008525,1694076839],[1203062813,3204075428]],i["SHA-512/256"]=[[573645204,4230739756],[2673172387,3360449730],[596883563,1867755857],[2520282905,1497426621],[2519219938,2827943907],[3193839141,1401305490],[721525244,746961066],[246885852,2177182882]],i["SHA-512/224"]=[[2352822216,424955298],[1944164710,2312950998],[502970286,855612546],[1738396948,1479516111],[258812777,2077511080],[2011393907,79989058],[1067287976,1780299464],[286451373,2446758561]],a=!0),void 0===e&&(e="SHA-512"),!(e in i))throw new Error("Invalid SHA-512 algorithm: "+e);for(var t=i[e],n=null,u=z.util.createBuffer(),c=new Array(80),l=0;l<80;++l)c[l]=new Array(2);var p=64;switch(e){case"SHA-384":p=48;break;case"SHA-512/256":p=32;break;case"SHA-512/224":p=28}var d={algorithm:e.replace("-","").toLowerCase(),blockLength:128,digestLength:p,messageLength:0,fullMessageLength:null,messageLengthSize:16,start:function(){d.messageLength=0,d.fullMessageLength=d.messageLength128=[];for(var e=d.messageLengthSize/4,r=0;r<e;++r)d.fullMessageLength.push(0);for(u=z.util.createBuffer(),n=new Array(t.length),r=0;r<t.length;++r)n[r]=t[r].slice(0);return d}};return d.start(),d.update=function(e,t){"utf8"===t&&(e=z.util.encodeUtf8(e));var r=e.length;d.messageLength+=r,r=[r/4294967296>>>0,r>>>0];for(var a=d.fullMessageLength.length-1;a>=0;--a)d.fullMessageLength[a]+=r[1],r[1]=r[0]+(d.fullMessageLength[a]/4294967296>>>0),d.fullMessageLength[a]=d.fullMessageLength[a]>>>0,r[0]=r[1]/4294967296>>>0;return u.putBytes(e),s(n,c,u),(u.read>2048||0===u.length())&&u.compact(),d},d.digest=function(){var t=z.util.createBuffer();t.putBytes(u.bytes());var a,o=d.fullMessageLength[d.fullMessageLength.length-1]+d.messageLengthSize&d.blockLength-1;t.putBytes(r.substr(0,d.blockLength-o));for(var i=8*d.fullMessageLength[0],l=0;l<d.fullMessageLength.length-1;++l)i+=(a=8*d.fullMessageLength[l+1])/4294967296>>>0,t.putInt32(i>>>0),i=a>>>0;t.putInt32(i);var p=new Array(n.length);for(l=0;l<n.length;++l)p[l]=n[l].slice(0);s(p,c,t);var f,h=z.util.createBuffer();for(f="SHA-512"===e?p.length:"SHA-384"===e?p.length-2:p.length-4,l=0;l<f;++l)h.putInt32(p[l][0]),l===f-1&&"SHA-512/224"===e||h.putInt32(p[l][1]);return h},d};var r=null,a=!1,o=null,i=null;function s(e,t,n){for(var r,a,i,s,u,c,l,p,d,f,h,m,g,v,y,b,x,w,k,S,E,I,C,T,_,N,A,R,O,B,D,M,F,P=n.length();P>=128;){for(A=0;A<16;++A)t[A][0]=n.getInt32()>>>0,t[A][1]=n.getInt32()>>>0;for(;A<80;++A)r=(((R=(B=t[A-2])[0])>>>19|(O=B[1])<<13)^(O>>>29|R<<3)^R>>>6)>>>0,a=((R<<13|O>>>19)^(O<<3|R>>>29)^(R<<26|O>>>6))>>>0,i=(((R=(M=t[A-15])[0])>>>1|(O=M[1])<<31)^(R>>>8|O<<24)^R>>>7)>>>0,s=((R<<31|O>>>1)^(R<<24|O>>>8)^(R<<25|O>>>7))>>>0,D=t[A-7],F=t[A-16],O=a+D[1]+s+F[1],t[A][0]=r+D[0]+i+F[0]+(O/4294967296>>>0)>>>0,t[A][1]=O>>>0;for(h=e[0][0],m=e[0][1],g=e[1][0],v=e[1][1],y=e[2][0],b=e[2][1],x=e[3][0],w=e[3][1],k=e[4][0],S=e[4][1],E=e[5][0],I=e[5][1],C=e[6][0],T=e[6][1],_=e[7][0],N=e[7][1],A=0;A<80;++A)l=((k>>>14|S<<18)^(k>>>18|S<<14)^(S>>>9|k<<23))>>>0,p=(C^k&(E^C))>>>0,u=((h>>>28|m<<4)^(m>>>2|h<<30)^(m>>>7|h<<25))>>>0,c=((h<<4|m>>>28)^(m<<30|h>>>2)^(m<<25|h>>>7))>>>0,d=(h&g|y&(h^g))>>>0,f=(m&v|b&(m^v))>>>0,O=N+(((k<<18|S>>>14)^(k<<14|S>>>18)^(S<<23|k>>>9))>>>0)+((T^S&(I^T))>>>0)+o[A][1]+t[A][1],r=_+l+p+o[A][0]+t[A][0]+(O/4294967296>>>0)>>>0,a=O>>>0,i=u+d+((O=c+f)/4294967296>>>0)>>>0,s=O>>>0,_=C,N=T,C=E,T=I,E=k,I=S,k=x+r+((O=w+a)/4294967296>>>0)>>>0,S=O>>>0,x=y,w=b,y=g,b=v,g=h,v=m,h=r+i+((O=a+s)/4294967296>>>0)>>>0,m=O>>>0;O=e[0][1]+m,e[0][0]=e[0][0]+h+(O/4294967296>>>0)>>>0,e[0][1]=O>>>0,O=e[1][1]+v,e[1][0]=e[1][0]+g+(O/4294967296>>>0)>>>0,e[1][1]=O>>>0,O=e[2][1]+b,e[2][0]=e[2][0]+y+(O/4294967296>>>0)>>>0,e[2][1]=O>>>0,O=e[3][1]+w,e[3][0]=e[3][0]+x+(O/4294967296>>>0)>>>0,e[3][1]=O>>>0,O=e[4][1]+S,e[4][0]=e[4][0]+k+(O/4294967296>>>0)>>>0,e[4][1]=O>>>0,O=e[5][1]+I,e[5][0]=e[5][0]+E+(O/4294967296>>>0)>>>0,e[5][1]=O>>>0,O=e[6][1]+T,e[6][0]=e[6][0]+C+(O/4294967296>>>0)>>>0,e[6][1]=O>>>0,O=e[7][1]+N,e[7][0]=e[7][0]+_+(O/4294967296>>>0)>>>0,e[7][1]=O>>>0,P-=128}}}));var pn=z.asn1,dn={privateKeyValidator:{name:"PrivateKeyInfo",tagClass:pn.Class.UNIVERSAL,type:pn.Type.SEQUENCE,constructed:!0,value:[{name:"PrivateKeyInfo.version",tagClass:pn.Class.UNIVERSAL,type:pn.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.privateKeyAlgorithm",tagClass:pn.Class.UNIVERSAL,type:pn.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:pn.Class.UNIVERSAL,type:pn.Type.OID,constructed:!1,capture:"privateKeyOid"}]},{name:"PrivateKeyInfo",tagClass:pn.Class.UNIVERSAL,type:pn.Type.OCTETSTRING,constructed:!1,capture:"privateKey"}]},publicKeyValidator:{name:"SubjectPublicKeyInfo",tagClass:pn.Class.UNIVERSAL,type:pn.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:pn.Class.UNIVERSAL,type:pn.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:pn.Class.UNIVERSAL,type:pn.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{tagClass:pn.Class.UNIVERSAL,type:pn.Type.BITSTRING,constructed:!1,composed:!0,captureBitStringValue:"ed25519PublicKey"}]}},fn=dn.publicKeyValidator,hn=dn.privateKeyValidator;if(void 0===mn)var mn=z.jsbn.BigInteger;var gn=z.util.ByteBuffer,vn="undefined"==typeof Buffer?Uint8Array:Buffer;z.pki=z.pki||{},z.pki.ed25519=z.ed25519=z.ed25519||{};var yn=z.ed25519;function bn(e){var t=e.message;if(t instanceof Uint8Array||t instanceof vn)return t;var n=e.encoding;if(void 0===t){if(!e.md)throw new TypeError('"options.message" or "options.md" not specified.');t=e.md.digest().getBytes(),n="binary"}if("string"==typeof t&&!n)throw new TypeError('"options.encoding" must be "binary" or "utf8".');if("string"==typeof t){if("undefined"!=typeof Buffer)return Buffer.from(t,n);t=new gn(t,n)}else if(!(t instanceof gn))throw new TypeError('"options.message" must be a node.js Buffer, a Uint8Array, a forge ByteBuffer, or a string with "options.encoding" specifying its encoding.');for(var r=new vn(t.length()),a=0;a<r.length;++a)r[a]=t.at(a);return r}yn.constants={},yn.constants.PUBLIC_KEY_BYTE_LENGTH=32,yn.constants.PRIVATE_KEY_BYTE_LENGTH=64,yn.constants.SEED_BYTE_LENGTH=32,yn.constants.SIGN_BYTE_LENGTH=64,yn.constants.HASH_BYTE_LENGTH=64,yn.generateKeyPair=function(e){var t=(e=e||{}).seed;if(void 0===t)t=z.random.getBytesSync(yn.constants.SEED_BYTE_LENGTH);else if("string"==typeof t){if(t.length!==yn.constants.SEED_BYTE_LENGTH)throw new TypeError('"seed" must be '+yn.constants.SEED_BYTE_LENGTH+" bytes in length.")}else if(!(t instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, Uint8Array, or a binary string.');t=bn({message:t,encoding:"binary"});for(var n=new vn(yn.constants.PUBLIC_KEY_BYTE_LENGTH),r=new vn(yn.constants.PRIVATE_KEY_BYTE_LENGTH),a=0;a<32;++a)r[a]=t[a];return function(e,t){var n,r=[Wn(),Wn(),Wn(),Wn()],a=_n(t,32);for(a[0]&=248,a[31]&=127,a[31]|=64,Un(r,a),Bn(e,r),n=0;n<32;++n)t[n+32]=e[n]}(n,r),{publicKey:n,privateKey:r}},yn.privateKeyFromAsn1=function(e){var t={},n=[];if(!z.asn1.validate(e,hn,t,n)){var r=new Error("Invalid Key.");throw r.errors=n,r}var a=z.asn1.derToOid(t.privateKeyOid),o=z.oids.EdDSA25519;if(a!==o)throw new Error('Invalid OID "'+a+'"; OID must be "'+o+'".');var i=t.privateKey;return{privateKeyBytes:bn({message:z.asn1.fromDer(i).value,encoding:"binary"})}},yn.publicKeyFromAsn1=function(e){var t={},n=[];if(!z.asn1.validate(e,fn,t,n)){var r=new Error("Invalid Key.");throw r.errors=n,r}var a=z.asn1.derToOid(t.publicKeyOid),o=z.oids.EdDSA25519;if(a!==o)throw new Error('Invalid OID "'+a+'"; OID must be "'+o+'".');var i=t.ed25519PublicKey;if(i.length!==yn.constants.PUBLIC_KEY_BYTE_LENGTH)throw new Error("Key length is invalid.");return bn({message:i,encoding:"binary"})},yn.publicKeyFromPrivateKey=function(e){var t=bn({message:(e=e||{}).privateKey,encoding:"binary"});if(t.length!==yn.constants.PRIVATE_KEY_BYTE_LENGTH)throw new TypeError('"options.privateKey" must have a byte length of '+yn.constants.PRIVATE_KEY_BYTE_LENGTH);for(var n=new vn(yn.constants.PUBLIC_KEY_BYTE_LENGTH),r=0;r<n.length;++r)n[r]=t[32+r];return n},yn.sign=function(e){var t=bn(e=e||{}),n=bn({message:e.privateKey,encoding:"binary"});if(n.length===yn.constants.SEED_BYTE_LENGTH)n=yn.generateKeyPair({seed:n}).privateKey;else if(n.length!==yn.constants.PRIVATE_KEY_BYTE_LENGTH)throw new TypeError('"options.privateKey" must have a byte length of '+yn.constants.SEED_BYTE_LENGTH+" or "+yn.constants.PRIVATE_KEY_BYTE_LENGTH);var r=new vn(yn.constants.SIGN_BYTE_LENGTH+t.length);!function(e,t,n,r){var a,o,i=new Float64Array(64),s=[Wn(),Wn(),Wn(),Wn()],u=_n(r,32);for(u[0]&=248,u[31]&=127,u[31]|=64,a=0;a<n;++a)e[64+a]=t[a];for(a=0;a<32;++a)e[32+a]=u[32+a];var c=_n(e.subarray(32),n+32);for(An(c),Un(s,c),Bn(e,s),a=32;a<64;++a)e[a]=r[a];var l=_n(e,n+64);for(An(l),a=32;a<64;++a)i[a]=0;for(a=0;a<32;++a)i[a]=c[a];for(a=0;a<32;++a)for(o=0;o<32;o++)i[a+o]+=l[a]*u[o];Nn(e.subarray(32),i)}(r,t,t.length,n);for(var a=new vn(yn.constants.SIGN_BYTE_LENGTH),o=0;o<a.length;++o)a[o]=r[o];return a},yn.verify=function(e){var t=bn(e=e||{});if(void 0===e.signature)throw new TypeError('"options.signature" must be a node.js Buffer, a Uint8Array, a forge ByteBuffer, or a binary string.');var n=bn({message:e.signature,encoding:"binary"});if(n.length!==yn.constants.SIGN_BYTE_LENGTH)throw new TypeError('"options.signature" must have a byte length of '+yn.constants.SIGN_BYTE_LENGTH);var r=bn({message:e.publicKey,encoding:"binary"});if(r.length!==yn.constants.PUBLIC_KEY_BYTE_LENGTH)throw new TypeError('"options.publicKey" must have a byte length of '+yn.constants.PUBLIC_KEY_BYTE_LENGTH);var a,o=new vn(yn.constants.SIGN_BYTE_LENGTH+t.length),i=new vn(yn.constants.SIGN_BYTE_LENGTH+t.length);for(a=0;a<yn.constants.SIGN_BYTE_LENGTH;++a)o[a]=n[a];for(a=0;a<t.length;++a)o[a+yn.constants.SIGN_BYTE_LENGTH]=t[a];return function(e,t,n,r){var a,o=new vn(32),i=[Wn(),Wn(),Wn(),Wn()],s=[Wn(),Wn(),Wn(),Wn()];if(n<64)return-1;if(function(e,t){var n=Wn(),r=Wn(),a=Wn(),o=Wn(),i=Wn(),s=Wn(),u=Wn();return Vn(e[2],wn),function(e,t){var n;for(n=0;n<16;++n)e[n]=t[2*n]+(t[2*n+1]<<8);e[15]&=32767}(e[1],t),Kn(a,e[1]),qn(o,a,kn),Gn(a,a,e[2]),Hn(o,e[2],o),Kn(i,o),Kn(s,i),qn(u,s,i),qn(n,u,a),qn(n,n,o),function(e,t){var n,r=Wn();for(n=0;n<16;++n)r[n]=t[n];for(n=250;n>=0;--n)Kn(r,r),1!==n&&qn(r,r,t);for(n=0;n<16;++n)e[n]=r[n]}(n,n),qn(n,n,a),qn(n,n,o),qn(n,n,o),qn(e[0],n,o),Kn(r,e[0]),qn(r,r,o),Mn(r,a)&&qn(e[0],e[0],Tn),Kn(r,e[0]),qn(r,r,o),Mn(r,a)?-1:(Pn(e[0])===t[31]>>7&&Gn(e[0],xn,e[0]),qn(e[3],e[0],e[1]),0)}(s,r))return-1;for(a=0;a<n;++a)e[a]=t[a];for(a=0;a<32;++a)e[a+32]=r[a];var u=_n(e,n);if(An(u),Ln(i,s,u),Un(s,t.subarray(32)),Rn(i,s),Bn(o,i),n-=64,Fn(t,0,o,0)){for(a=0;a<n;++a)e[a]=0;return-1}for(a=0;a<n;++a)e[a]=t[a+64];return n}(i,o,o.length,r)>=0};var xn=Wn(),wn=Wn([1]),kn=Wn([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),Sn=Wn([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),En=Wn([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),In=Wn([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),Cn=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]),Tn=Wn([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function _n(e,t){var n=z.md.sha512.create(),r=new gn(e);n.update(r.getBytes(t),"binary");var a=n.digest().getBytes();if("undefined"!=typeof Buffer)return Buffer.from(a,"binary");for(var o=new vn(yn.constants.HASH_BYTE_LENGTH),i=0;i<64;++i)o[i]=a.charCodeAt(i);return o}function Nn(e,t){var n,r,a,o;for(r=63;r>=32;--r){for(n=0,a=r-32,o=r-12;a<o;++a)t[a]+=n-16*t[r]*Cn[a-(r-32)],n=t[a]+128>>8,t[a]-=256*n;t[a]+=n,t[r]=0}for(n=0,a=0;a<32;++a)t[a]+=n-(t[31]>>4)*Cn[a],n=t[a]>>8,t[a]&=255;for(a=0;a<32;++a)t[a]-=n*Cn[a];for(r=0;r<32;++r)t[r+1]+=t[r]>>8,e[r]=255&t[r]}function An(e){for(var t=new Float64Array(64),n=0;n<64;++n)t[n]=e[n],e[n]=0;Nn(e,t)}function Rn(e,t){var n=Wn(),r=Wn(),a=Wn(),o=Wn(),i=Wn(),s=Wn(),u=Wn(),c=Wn(),l=Wn();Gn(n,e[1],e[0]),Gn(l,t[1],t[0]),qn(n,n,l),Hn(r,e[0],e[1]),Hn(l,t[0],t[1]),qn(r,r,l),qn(a,e[3],t[3]),qn(a,a,Sn),qn(o,e[2],t[2]),Hn(o,o,o),Gn(i,r,n),Gn(s,o,a),Hn(u,o,a),Hn(c,r,n),qn(e[0],i,s),qn(e[1],c,u),qn(e[2],u,s),qn(e[3],i,c)}function On(e,t,n){for(var r=0;r<4;++r)jn(e[r],t[r],n)}function Bn(e,t){var n=Wn(),r=Wn(),a=Wn();!function(e,t){var n,r=Wn();for(n=0;n<16;++n)r[n]=t[n];for(n=253;n>=0;--n)Kn(r,r),2!==n&&4!==n&&qn(r,r,t);for(n=0;n<16;++n)e[n]=r[n]}(a,t[2]),qn(n,t[0],a),qn(r,t[1],a),Dn(e,r),e[31]^=Pn(n)<<7}function Dn(e,t){var n,r,a,o=Wn(),i=Wn();for(n=0;n<16;++n)i[n]=t[n];for(zn(i),zn(i),zn(i),r=0;r<2;++r){for(o[0]=i[0]-65517,n=1;n<15;++n)o[n]=i[n]-65535-(o[n-1]>>16&1),o[n-1]&=65535;o[15]=i[15]-32767-(o[14]>>16&1),a=o[15]>>16&1,o[14]&=65535,jn(i,o,1-a)}for(n=0;n<16;n++)e[2*n]=255&i[n],e[2*n+1]=i[n]>>8}function Mn(e,t){var n=new vn(32),r=new vn(32);return Dn(n,e),Dn(r,t),Fn(n,0,r,0)}function Fn(e,t,n,r){return function(e,t,n,r,a){var o,i=0;for(o=0;o<a;++o)i|=e[t+o]^n[r+o];return(1&i-1>>>8)-1}(e,t,n,r,32)}function Pn(e){var t=new vn(32);return Dn(t,e),1&t[0]}function Ln(e,t,n){var r,a;for(Vn(e[0],xn),Vn(e[1],wn),Vn(e[2],wn),Vn(e[3],xn),a=255;a>=0;--a)On(e,t,r=n[a/8|0]>>(7&a)&1),Rn(t,e),Rn(e,e),On(e,t,r)}function Un(e,t){var n=[Wn(),Wn(),Wn(),Wn()];Vn(n[0],En),Vn(n[1],In),Vn(n[2],wn),qn(n[3],En,In),Ln(e,n,t)}function Vn(e,t){var n;for(n=0;n<16;n++)e[n]=0|t[n]}function zn(e){var t,n,r=1;for(t=0;t<16;++t)n=e[t]+r+65535,r=Math.floor(n/65536),e[t]=n-65536*r;e[0]+=r-1+37*(r-1)}function jn(e,t,n){for(var r,a=~(n-1),o=0;o<16;++o)r=a&(e[o]^t[o]),e[o]^=r,t[o]^=r}function Wn(e){var t,n=new Float64Array(16);if(e)for(t=0;t<e.length;++t)n[t]=e[t];return n}function Hn(e,t,n){for(var r=0;r<16;++r)e[r]=t[r]+n[r]}function Gn(e,t,n){for(var r=0;r<16;++r)e[r]=t[r]-n[r]}function Kn(e,t){qn(e,t,t)}function qn(e,t,n){var r,a,o=0,i=0,s=0,u=0,c=0,l=0,p=0,d=0,f=0,h=0,m=0,g=0,v=0,y=0,b=0,x=0,w=0,k=0,S=0,E=0,I=0,C=0,T=0,_=0,N=0,A=0,R=0,O=0,B=0,D=0,M=0,F=n[0],P=n[1],L=n[2],U=n[3],V=n[4],z=n[5],j=n[6],W=n[7],H=n[8],G=n[9],K=n[10],q=n[11],Q=n[12],X=n[13],Y=n[14],$=n[15];o+=(r=t[0])*F,i+=r*P,s+=r*L,u+=r*U,c+=r*V,l+=r*z,p+=r*j,d+=r*W,f+=r*H,h+=r*G,m+=r*K,g+=r*q,v+=r*Q,y+=r*X,b+=r*Y,x+=r*$,i+=(r=t[1])*F,s+=r*P,u+=r*L,c+=r*U,l+=r*V,p+=r*z,d+=r*j,f+=r*W,h+=r*H,m+=r*G,g+=r*K,v+=r*q,y+=r*Q,b+=r*X,x+=r*Y,w+=r*$,s+=(r=t[2])*F,u+=r*P,c+=r*L,l+=r*U,p+=r*V,d+=r*z,f+=r*j,h+=r*W,m+=r*H,g+=r*G,v+=r*K,y+=r*q,b+=r*Q,x+=r*X,w+=r*Y,k+=r*$,u+=(r=t[3])*F,c+=r*P,l+=r*L,p+=r*U,d+=r*V,f+=r*z,h+=r*j,m+=r*W,g+=r*H,v+=r*G,y+=r*K,b+=r*q,x+=r*Q,w+=r*X,k+=r*Y,S+=r*$,c+=(r=t[4])*F,l+=r*P,p+=r*L,d+=r*U,f+=r*V,h+=r*z,m+=r*j,g+=r*W,v+=r*H,y+=r*G,b+=r*K,x+=r*q,w+=r*Q,k+=r*X,S+=r*Y,E+=r*$,l+=(r=t[5])*F,p+=r*P,d+=r*L,f+=r*U,h+=r*V,m+=r*z,g+=r*j,v+=r*W,y+=r*H,b+=r*G,x+=r*K,w+=r*q,k+=r*Q,S+=r*X,E+=r*Y,I+=r*$,p+=(r=t[6])*F,d+=r*P,f+=r*L,h+=r*U,m+=r*V,g+=r*z,v+=r*j,y+=r*W,b+=r*H,x+=r*G,w+=r*K,k+=r*q,S+=r*Q,E+=r*X,I+=r*Y,C+=r*$,d+=(r=t[7])*F,f+=r*P,h+=r*L,m+=r*U,g+=r*V,v+=r*z,y+=r*j,b+=r*W,x+=r*H,w+=r*G,k+=r*K,S+=r*q,E+=r*Q,I+=r*X,C+=r*Y,T+=r*$,f+=(r=t[8])*F,h+=r*P,m+=r*L,g+=r*U,v+=r*V,y+=r*z,b+=r*j,x+=r*W,w+=r*H,k+=r*G,S+=r*K,E+=r*q,I+=r*Q,C+=r*X,T+=r*Y,_+=r*$,h+=(r=t[9])*F,m+=r*P,g+=r*L,v+=r*U,y+=r*V,b+=r*z,x+=r*j,w+=r*W,k+=r*H,S+=r*G,E+=r*K,I+=r*q,C+=r*Q,T+=r*X,_+=r*Y,N+=r*$,m+=(r=t[10])*F,g+=r*P,v+=r*L,y+=r*U,b+=r*V,x+=r*z,w+=r*j,k+=r*W,S+=r*H,E+=r*G,I+=r*K,C+=r*q,T+=r*Q,_+=r*X,N+=r*Y,A+=r*$,g+=(r=t[11])*F,v+=r*P,y+=r*L,b+=r*U,x+=r*V,w+=r*z,k+=r*j,S+=r*W,E+=r*H,I+=r*G,C+=r*K,T+=r*q,_+=r*Q,N+=r*X,A+=r*Y,R+=r*$,v+=(r=t[12])*F,y+=r*P,b+=r*L,x+=r*U,w+=r*V,k+=r*z,S+=r*j,E+=r*W,I+=r*H,C+=r*G,T+=r*K,_+=r*q,N+=r*Q,A+=r*X,R+=r*Y,O+=r*$,y+=(r=t[13])*F,b+=r*P,x+=r*L,w+=r*U,k+=r*V,S+=r*z,E+=r*j,I+=r*W,C+=r*H,T+=r*G,_+=r*K,N+=r*q,A+=r*Q,R+=r*X,O+=r*Y,B+=r*$,b+=(r=t[14])*F,x+=r*P,w+=r*L,k+=r*U,S+=r*V,E+=r*z,I+=r*j,C+=r*W,T+=r*H,_+=r*G,N+=r*K,A+=r*q,R+=r*Q,O+=r*X,B+=r*Y,D+=r*$,x+=(r=t[15])*F,i+=38*(k+=r*L),s+=38*(S+=r*U),u+=38*(E+=r*V),c+=38*(I+=r*z),l+=38*(C+=r*j),p+=38*(T+=r*W),d+=38*(_+=r*H),f+=38*(N+=r*G),h+=38*(A+=r*K),m+=38*(R+=r*q),g+=38*(O+=r*Q),v+=38*(B+=r*X),y+=38*(D+=r*Y),b+=38*(M+=r*$),o=(r=(o+=38*(w+=r*P))+(a=1)+65535)-65536*(a=Math.floor(r/65536)),i=(r=i+a+65535)-65536*(a=Math.floor(r/65536)),s=(r=s+a+65535)-65536*(a=Math.floor(r/65536)),u=(r=u+a+65535)-65536*(a=Math.floor(r/65536)),c=(r=c+a+65535)-65536*(a=Math.floor(r/65536)),l=(r=l+a+65535)-65536*(a=Math.floor(r/65536)),p=(r=p+a+65535)-65536*(a=Math.floor(r/65536)),d=(r=d+a+65535)-65536*(a=Math.floor(r/65536)),f=(r=f+a+65535)-65536*(a=Math.floor(r/65536)),h=(r=h+a+65535)-65536*(a=Math.floor(r/65536)),m=(r=m+a+65535)-65536*(a=Math.floor(r/65536)),g=(r=g+a+65535)-65536*(a=Math.floor(r/65536)),v=(r=v+a+65535)-65536*(a=Math.floor(r/65536)),y=(r=y+a+65535)-65536*(a=Math.floor(r/65536)),b=(r=b+a+65535)-65536*(a=Math.floor(r/65536)),x=(r=x+a+65535)-65536*(a=Math.floor(r/65536)),o=(r=(o+=a-1+37*(a-1))+(a=1)+65535)-65536*(a=Math.floor(r/65536)),i=(r=i+a+65535)-65536*(a=Math.floor(r/65536)),s=(r=s+a+65535)-65536*(a=Math.floor(r/65536)),u=(r=u+a+65535)-65536*(a=Math.floor(r/65536)),c=(r=c+a+65535)-65536*(a=Math.floor(r/65536)),l=(r=l+a+65535)-65536*(a=Math.floor(r/65536)),p=(r=p+a+65535)-65536*(a=Math.floor(r/65536)),d=(r=d+a+65535)-65536*(a=Math.floor(r/65536)),f=(r=f+a+65535)-65536*(a=Math.floor(r/65536)),h=(r=h+a+65535)-65536*(a=Math.floor(r/65536)),m=(r=m+a+65535)-65536*(a=Math.floor(r/65536)),g=(r=g+a+65535)-65536*(a=Math.floor(r/65536)),v=(r=v+a+65535)-65536*(a=Math.floor(r/65536)),y=(r=y+a+65535)-65536*(a=Math.floor(r/65536)),b=(r=b+a+65535)-65536*(a=Math.floor(r/65536)),x=(r=x+a+65535)-65536*(a=Math.floor(r/65536)),o+=a-1+37*(a-1),e[0]=o,e[1]=i,e[2]=s,e[3]=u,e[4]=c,e[5]=l,e[6]=p,e[7]=d,e[8]=f,e[9]=h,e[10]=m,e[11]=g,e[12]=v,e[13]=y,e[14]=b,e[15]=x}z.kem=z.kem||{};var Qn=z.jsbn.BigInteger;function Xn(e,t,n,r){e.generate=function(e,a){for(var o=new z.util.ByteBuffer,i=Math.ceil(a/r)+n,s=new z.util.ByteBuffer,u=n;u<i;++u){s.putInt32(u),t.start(),t.update(e+s.getBytes());var c=t.digest();o.putBytes(c.getBytes(r))}return o.truncate(o.length()-a),o.getBytes()}}z.kem.rsa={},z.kem.rsa.create=function(e,t){var n=(t=t||{}).prng||z.random;return{encrypt:function(t,r){var a,o=Math.ceil(t.n.bitLength()/8);do{a=new Qn(z.util.bytesToHex(n.getBytesSync(o)),16).mod(t.n)}while(a.compareTo(Qn.ONE)<=0);var i=o-(a=z.util.hexToBytes(a.toString(16))).length;return i>0&&(a=z.util.fillString(String.fromCharCode(0),i)+a),{encapsulation:t.encrypt(a,"NONE"),key:e.generate(a,r)}},decrypt:function(t,n,r){var a=t.decrypt(n,"NONE");return e.generate(a,r)}}},z.kem.kdf1=function(e,t){Xn(this,e,0,t||e.digestLength)},z.kem.kdf2=function(e,t){Xn(this,e,1,t||e.digestLength)},z.log=z.log||{},z.log.levels=["none","error","warning","info","debug","verbose","max"];var Yn={},$n=[],Zn=null;z.log.LEVEL_LOCKED=2,z.log.NO_LEVEL_CHECK=4,z.log.INTERPOLATE=8;for(var Jn=0;Jn<z.log.levels.length;++Jn){var er=z.log.levels[Jn];Yn[er]={index:Jn,name:er.toUpperCase()}}z.log.logMessage=function(e){for(var t=Yn[e.level].index,n=0;n<$n.length;++n){var r=$n[n];r.flags&z.log.NO_LEVEL_CHECK?r.f(e):t<=Yn[r.level].index&&r.f(r,e)}},z.log.prepareStandard=function(e){"standard"in e||(e.standard=Yn[e.level].name+" ["+e.category+"] "+e.message)},z.log.prepareFull=function(e){if(!("full"in e)){var t=[e.message];t=t.concat([]||e.arguments),e.full=z.util.format.apply(this,t)}},z.log.prepareStandardFull=function(e){"standardFull"in e||(z.log.prepareStandard(e),e.standardFull=e.standard)};var tr=["error","warning","info","debug","verbose"];for(Jn=0;Jn<tr.length;++Jn)!function(e){z.log[e]=function(t,n){var r=Array.prototype.slice.call(arguments).slice(2),a={timestamp:new Date,level:e,category:t,message:n,arguments:r};z.log.logMessage(a)}}(tr[Jn]);if(z.log.makeLogger=function(e){var t={flags:0,f:e};return z.log.setLevel(t,"none"),t},z.log.setLevel=function(e,t){var n=!1;if(e&&!(e.flags&z.log.LEVEL_LOCKED))for(var r=0;r<z.log.levels.length;++r)if(t==z.log.levels[r]){e.level=t,n=!0;break}return n},z.log.lock=function(e,t){void 0===t||t?e.flags|=z.log.LEVEL_LOCKED:e.flags&=~z.log.LEVEL_LOCKED},z.log.addLogger=function(e){$n.push(e)},"undefined"!=typeof console&&"log"in console){var nr;if(console.error&&console.warn&&console.info&&console.debug){var rr={error:console.error,warning:console.warn,info:console.info,debug:console.debug,verbose:console.debug},ar=function(e,t){z.log.prepareStandard(t);var n=rr[t.level],r=[t.standard];r=r.concat(t.arguments.slice()),n.apply(console,r)};nr=z.log.makeLogger(ar)}else ar=function(e,t){z.log.prepareStandardFull(t),console.log(t.standardFull)},nr=z.log.makeLogger(ar);z.log.setLevel(nr,"debug"),z.log.addLogger(nr),Zn=nr}else console={log:function(){}};if(null!==Zn){var or=z.util.getQueryVariables();"console.level"in or&&z.log.setLevel(Zn,or["console.level"].slice(-1)[0]),"console.lock"in or&&"true"==or["console.lock"].slice(-1)[0]&&z.log.lock(Zn)}z.log.consoleLogger=Zn,w((function(e){var t=z.asn1,n=e.exports=z.pkcs7=z.pkcs7||{};function r(e){var r={},a=[];if(!t.validate(e,n.asn1.recipientInfoValidator,r,a)){var o=new Error("Cannot read PKCS#7 RecipientInfo. ASN.1 object is not an PKCS#7 RecipientInfo.");throw o.errors=a,o}return{version:r.version.charCodeAt(0),issuer:z.pki.RDNAttributesAsArray(r.issuer),serialNumber:z.util.createBuffer(r.serial).toHex(),encryptedContent:{algorithm:t.derToOid(r.encAlgorithm),parameter:r.encParameter.value,content:r.encKey}}}function a(e){for(var n,r=[],a=0;a<e.length;++a)r.push((n=e[a],t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(n.version).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[z.pki.distinguishedNameToAsn1({attributes:n.issuer}),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,z.util.hexToBytes(n.serialNumber))]),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.encryptedContent.algorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")]),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,n.encryptedContent.content)])));return r}function o(e){var n=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[z.pki.distinguishedNameToAsn1({attributes:e.issuer}),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,z.util.hexToBytes(e.serialNumber))]),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.digestAlgorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")])]);if(e.authenticatedAttributesAsn1&&n.value.push(e.authenticatedAttributesAsn1),n.value.push(t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.signatureAlgorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")])),n.value.push(t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,e.signature)),e.unauthenticatedAttributes.length>0){for(var r=t.create(t.Class.CONTEXT_SPECIFIC,1,!0,[]),a=0;a<e.unauthenticatedAttributes.length;++a){var o=e.unauthenticatedAttributes[a];r.values.push(i(o))}n.value.push(r)}return n}function i(e){var n;if(e.type===z.pki.oids.contentType)n=t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.value).getBytes());else if(e.type===z.pki.oids.messageDigest)n=t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,e.value.bytes());else if(e.type===z.pki.oids.signingTime){var r=new Date("1950-01-01T00:00:00Z"),a=new Date("2050-01-01T00:00:00Z"),o=e.value;if("string"==typeof o){var i=Date.parse(o);o=isNaN(i)?13===o.length?t.utcTimeToDate(o):t.generalizedTimeToDate(o):new Date(i)}n=o>=r&&o<a?t.create(t.Class.UNIVERSAL,t.Type.UTCTIME,!1,t.dateToUtcTime(o)):t.create(t.Class.UNIVERSAL,t.Type.GENERALIZEDTIME,!1,t.dateToGeneralizedTime(o))}return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.type).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[n])])}function s(e,n,r){var a={};if(!t.validate(n,r,a,[])){var o=new Error("Cannot read PKCS#7 message. ASN.1 object is not a supported PKCS#7 message.");throw o.errors=o,o}if(t.derToOid(a.contentType)!==z.pki.oids.data)throw new Error("Unsupported PKCS#7 message. Only wrapped ContentType Data supported.");if(a.encryptedContent){var i="";if(z.util.isArray(a.encryptedContent))for(var s=0;s<a.encryptedContent.length;++s){if(a.encryptedContent[s].type!==t.Type.OCTETSTRING)throw new Error("Malformed PKCS#7 message, expecting encrypted content constructed of only OCTET STRING objects.");i+=a.encryptedContent[s].value}else i=a.encryptedContent;e.encryptedContent={algorithm:t.derToOid(a.encAlgorithm),parameter:z.util.createBuffer(a.encParameter.value),content:z.util.createBuffer(i)}}if(a.content){if(i="",z.util.isArray(a.content))for(s=0;s<a.content.length;++s){if(a.content[s].type!==t.Type.OCTETSTRING)throw new Error("Malformed PKCS#7 message, expecting content constructed of only OCTET STRING objects.");i+=a.content[s].value}else i=a.content;e.content=z.util.createBuffer(i)}return e.version=a.version.charCodeAt(0),e.rawCapture=a,a}function u(e){if(void 0===e.encryptedContent.key)throw new Error("Symmetric key not available.");if(void 0===e.content){var t;switch(e.encryptedContent.algorithm){case z.pki.oids["aes128-CBC"]:case z.pki.oids["aes192-CBC"]:case z.pki.oids["aes256-CBC"]:t=z.aes.createDecryptionCipher(e.encryptedContent.key);break;case z.pki.oids.desCBC:case z.pki.oids["des-EDE3-CBC"]:t=z.des.createDecryptionCipher(e.encryptedContent.key);break;default:throw new Error("Unsupported symmetric cipher, OID "+e.encryptedContent.algorithm)}if(t.start(e.encryptedContent.parameter),t.update(e.encryptedContent.content),!t.finish())throw new Error("Symmetric decryption failed.");e.content=t.output}}n.messageFromPem=function(e){var r=z.pem.decode(e)[0];if("PKCS7"!==r.type){var a=new Error('Could not convert PKCS#7 message from PEM; PEM header type is not "PKCS#7".');throw a.headerType=r.type,a}if(r.procType&&"ENCRYPTED"===r.procType.type)throw new Error("Could not convert PKCS#7 message from PEM; PEM is encrypted.");var o=t.fromDer(r.body);return n.messageFromAsn1(o)},n.messageToPem=function(e,n){var r={type:"PKCS7",body:t.toDer(e.toAsn1()).getBytes()};return z.pem.encode(r,{maxline:n})},n.messageFromAsn1=function(e){var r={},a=[];if(!t.validate(e,n.asn1.contentInfoValidator,r,a)){var o=new Error("Cannot read PKCS#7 message. ASN.1 object is not an PKCS#7 ContentInfo.");throw o.errors=a,o}var i,s=t.derToOid(r.contentType);switch(s){case z.pki.oids.envelopedData:i=n.createEnvelopedData();break;case z.pki.oids.encryptedData:i=n.createEncryptedData();break;case z.pki.oids.signedData:i=n.createSignedData();break;default:throw new Error("Cannot read PKCS#7 message. ContentType with OID "+s+" is not (yet) supported.")}return i.fromAsn1(r.content.value[0]),i},n.createSignedData=function(){var e=null;return e={type:z.pki.oids.signedData,version:1,certificates:[],crls:[],signers:[],digestAlgorithmIdentifiers:[],contentInfo:null,signerInfos:[],fromAsn1:function(t){if(s(e,t,n.asn1.signedDataValidator),e.certificates=[],e.crls=[],e.digestAlgorithmIdentifiers=[],e.contentInfo=null,e.signerInfos=[],e.rawCapture.certificates)for(var r=e.rawCapture.certificates.value,a=0;a<r.length;++a)e.certificates.push(z.pki.certificateFromAsn1(r[a]))},toAsn1:function(){e.contentInfo||e.sign();for(var n=[],r=0;r<e.certificates.length;++r)n.push(z.pki.certificateToAsn1(e.certificates[r]));var a=[],o=t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,e.digestAlgorithmIdentifiers),e.contentInfo])]);return n.length>0&&o.value[0].value.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!0,n)),a.length>0&&o.value[0].value.push(t.create(t.Class.CONTEXT_SPECIFIC,1,!0,a)),o.value[0].value.push(t.create(t.Class.UNIVERSAL,t.Type.SET,!0,e.signerInfos)),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.type).getBytes()),o])},addSigner:function(t){var n=t.issuer,r=t.serialNumber;if(t.certificate){var a=t.certificate;"string"==typeof a&&(a=z.pki.certificateFromPem(a)),n=a.issuer.attributes,r=a.serialNumber}var o=t.key;if(!o)throw new Error("Could not add PKCS#7 signer; no private key specified.");"string"==typeof o&&(o=z.pki.privateKeyFromPem(o));var i=t.digestAlgorithm||z.pki.oids.sha1;switch(i){case z.pki.oids.sha1:case z.pki.oids.sha256:case z.pki.oids.sha384:case z.pki.oids.sha512:case z.pki.oids.md5:break;default:throw new Error("Could not add PKCS#7 signer; unknown message digest algorithm: "+i)}var s=t.authenticatedAttributes||[];if(s.length>0){for(var u=!1,c=!1,l=0;l<s.length;++l){var p=s[l];if(u||p.type!==z.pki.oids.contentType){if(c||p.type!==z.pki.oids.messageDigest);else if(c=!0,u)break}else if(u=!0,c)break}if(!u||!c)throw new Error("Invalid signer.authenticatedAttributes. If signer.authenticatedAttributes is specified, then it must contain at least two attributes, PKCS #9 content-type and PKCS #9 message-digest.")}e.signers.push({key:o,version:1,issuer:n,serialNumber:r,digestAlgorithm:i,signatureAlgorithm:z.pki.oids.rsaEncryption,signature:null,authenticatedAttributes:s,unauthenticatedAttributes:[]})},sign:function(n){var r;n=n||{},("object"!=typeof e.content||null===e.contentInfo)&&(e.contentInfo=t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(z.pki.oids.data).getBytes())]),"content"in e&&(e.content instanceof z.util.ByteBuffer?r=e.content.bytes():"string"==typeof e.content&&(r=z.util.encodeUtf8(e.content)),n.detached?e.detachedContent=t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r):e.contentInfo.value.push(t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r)])))),0!==e.signers.length&&function(n){var r;if(!(r=e.detachedContent?e.detachedContent:(r=e.contentInfo.value[1]).value[0]))throw new Error("Could not sign PKCS#7 message; there is no content to sign.");var a=t.derToOid(e.contentInfo.value[0].value),s=t.toDer(r);for(var u in s.getByte(),t.getBerValueLength(s),s=s.getBytes(),n)n[u].start().update(s);for(var c=new Date,l=0;l<e.signers.length;++l){var p=e.signers[l];if(0===p.authenticatedAttributes.length){if(a!==z.pki.oids.data)throw new Error("Invalid signer; authenticatedAttributes must be present when the ContentInfo content type is not PKCS#7 Data.")}else{p.authenticatedAttributesAsn1=t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[]);for(var d=t.create(t.Class.UNIVERSAL,t.Type.SET,!0,[]),f=0;f<p.authenticatedAttributes.length;++f){var h=p.authenticatedAttributes[f];h.type===z.pki.oids.messageDigest?h.value=n[p.digestAlgorithm].digest():h.type===z.pki.oids.signingTime&&(h.value||(h.value=c)),d.value.push(i(h)),p.authenticatedAttributesAsn1.value.push(i(h))}s=t.toDer(d).getBytes(),p.md.start().update(s)}p.signature=p.key.sign(p.md,"RSASSA-PKCS1-V1_5")}e.signerInfos=function(e){for(var t=[],n=0;n<e.length;++n)t.push(o(e[n]));return t}(e.signers)}(function(){for(var n={},r=0;r<e.signers.length;++r){var a=e.signers[r];(o=a.digestAlgorithm)in n||(n[o]=z.md[z.pki.oids[o]].create()),0===a.authenticatedAttributes.length?a.md=n[o]:a.md=z.md[z.pki.oids[o]].create()}for(var o in e.digestAlgorithmIdentifiers=[],n)e.digestAlgorithmIdentifiers.push(t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(o).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")]));return n}())},verify:function(){throw new Error("PKCS#7 signature verification not yet implemented.")},addCertificate:function(t){"string"==typeof t&&(t=z.pki.certificateFromPem(t)),e.certificates.push(t)},addCertificateRevokationList:function(e){throw new Error("PKCS#7 CRL support not yet implemented.")}}},n.createEncryptedData=function(){var e=null;return e={type:z.pki.oids.encryptedData,version:0,encryptedContent:{algorithm:z.pki.oids["aes256-CBC"]},fromAsn1:function(t){s(e,t,n.asn1.encryptedDataValidator)},decrypt:function(t){void 0!==t&&(e.encryptedContent.key=t),u(e)}}},n.createEnvelopedData=function(){var e=null;return e={type:z.pki.oids.envelopedData,version:0,recipients:[],encryptedContent:{algorithm:z.pki.oids["aes256-CBC"]},fromAsn1:function(t){var a=s(e,t,n.asn1.envelopedDataValidator);e.recipients=function(e){for(var t=[],n=0;n<e.length;++n)t.push(r(e[n]));return t}(a.recipientInfos.value)},toAsn1:function(){return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.type).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,t.integerToDer(e.version).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,a(e.recipients)),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,(n=e.encryptedContent,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(z.pki.oids.data).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.algorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,n.parameter.getBytes())]),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,n.content.getBytes())])]))])])]);var n},findRecipient:function(t){for(var n=t.issuer.attributes,r=0;r<e.recipients.length;++r){var a=e.recipients[r],o=a.issuer;if(a.serialNumber===t.serialNumber&&o.length===n.length){for(var i=!0,s=0;s<n.length;++s)if(o[s].type!==n[s].type||o[s].value!==n[s].value){i=!1;break}if(i)return a}}return null},decrypt:function(t,n){if(void 0===e.encryptedContent.key&&void 0!==t&&void 0!==n)switch(t.encryptedContent.algorithm){case z.pki.oids.rsaEncryption:case z.pki.oids.desCBC:var r=n.decrypt(t.encryptedContent.content);e.encryptedContent.key=z.util.createBuffer(r);break;default:throw new Error("Unsupported asymmetric cipher, OID "+t.encryptedContent.algorithm)}u(e)},addRecipient:function(t){e.recipients.push({version:0,issuer:t.issuer.attributes,serialNumber:t.serialNumber,encryptedContent:{algorithm:z.pki.oids.rsaEncryption,key:t.publicKey}})},encrypt:function(t,n){if(void 0===e.encryptedContent.content){var r,a,o;switch(n=n||e.encryptedContent.algorithm,t=t||e.encryptedContent.key,n){case z.pki.oids["aes128-CBC"]:r=16,a=16,o=z.aes.createEncryptionCipher;break;case z.pki.oids["aes192-CBC"]:r=24,a=16,o=z.aes.createEncryptionCipher;break;case z.pki.oids["aes256-CBC"]:r=32,a=16,o=z.aes.createEncryptionCipher;break;case z.pki.oids["des-EDE3-CBC"]:r=24,a=8,o=z.des.createEncryptionCipher;break;default:throw new Error("Unsupported symmetric cipher, OID "+n)}if(void 0===t)t=z.util.createBuffer(z.random.getBytes(r));else if(t.length()!=r)throw new Error("Symmetric key has wrong length; got "+t.length()+" bytes, expected "+r+".");e.encryptedContent.algorithm=n,e.encryptedContent.key=t,e.encryptedContent.parameter=z.util.createBuffer(z.random.getBytes(a));var i=o(t);if(i.start(e.encryptedContent.parameter.copy()),i.update(e.content),!i.finish())throw new Error("Symmetric encryption failed.");e.encryptedContent.content=i.output}for(var s=0;s<e.recipients.length;++s){var u=e.recipients[s];if(void 0===u.encryptedContent.content)switch(u.encryptedContent.algorithm){case z.pki.oids.rsaEncryption:u.encryptedContent.content=u.encryptedContent.key.encrypt(e.encryptedContent.key.data);break;default:throw new Error("Unsupported asymmetric cipher, OID "+u.encryptedContent.algorithm)}}}}}})),w((function(e){var t=e.exports=z.ssh=z.ssh||{};function n(e,t){var n=t.toString(16);n[0]>="8"&&(n="00"+n);var r=z.util.hexToBytes(n);e.putInt32(r.length),e.putBytes(r)}function r(e,t){e.putInt32(t.length),e.putString(t)}function a(){for(var e=z.md.sha1.create(),t=arguments.length,n=0;n<t;++n)e.update(arguments[n]);return e.digest()}t.privateKeyToPutty=function(e,t,o){var i=""===(t=t||"")?"none":"aes256-cbc",s="PuTTY-User-Key-File-2: ssh-rsa\r\n";s+="Encryption: "+i+"\r\n",s+="Comment: "+(o=o||"")+"\r\n";var u=z.util.createBuffer();r(u,"ssh-rsa"),n(u,e.e),n(u,e.n);var c=z.util.encode64(u.bytes(),64),l=Math.floor(c.length/66)+1;s+="Public-Lines: "+l+"\r\n",s+=c;var p,d=z.util.createBuffer();if(n(d,e.d),n(d,e.p),n(d,e.q),n(d,e.qInv),t){var f=d.length()+16-1;f-=f%16;var h=a(d.bytes());h.truncate(h.length()-f+d.length()),d.putBuffer(h);var m=z.util.createBuffer();m.putBuffer(a("\0\0\0\0",t)),m.putBuffer(a("\0\0\0",t));var g=z.aes.createEncryptionCipher(m.truncate(8),"CBC");g.start(z.util.createBuffer().fillWithByte(0,16)),g.update(d.copy()),g.finish();var v=g.output;v.truncate(16),p=z.util.encode64(v.bytes(),64)}else p=z.util.encode64(d.bytes(),64);s+="\r\nPrivate-Lines: "+(l=Math.floor(p.length/66)+1)+"\r\n",s+=p;var y=a("putty-private-key-file-mac-key",t),b=z.util.createBuffer();r(b,"ssh-rsa"),r(b,i),r(b,o),b.putInt32(u.length()),b.putBuffer(u),b.putInt32(d.length()),b.putBuffer(d);var x=z.hmac.create();return x.start("sha1",y),x.update(b.bytes()),s+"\r\nPrivate-MAC: "+x.digest().toHex()+"\r\n"},t.publicKeyToOpenSSH=function(e,t){t=t||"";var a=z.util.createBuffer();return r(a,"ssh-rsa"),n(a,e.e),n(a,e.n),"ssh-rsa "+z.util.encode64(a.bytes())+" "+t},t.privateKeyToOpenSSH=function(e,t){return t?z.pki.encryptRsaPrivateKey(e,t,{legacy:!0,algorithm:"aes128"}):z.pki.privateKeyToPem(e)},t.getPublicKeyFingerprint=function(e,t){var a=(t=t||{}).md||z.md.md5.create(),o=z.util.createBuffer();r(o,"ssh-rsa"),n(o,e.e),n(o,e.n),a.start(),a.update(o.getBytes());var i=a.digest();if("hex"===t.encoding){var s=i.toHex();return t.delimiter?s.match(/.{2}/g).join(t.delimiter):s}if("binary"===t.encoding)return i.getBytes();if(t.encoding)throw new Error('Unknown encoding "'+t.encoding+'".');return i}}));var ir="forge.task",sr={},ur=0;z.debug.set(ir,"tasks",sr);var cr={};z.debug.set(ir,"queues",cr);var lr="ready",pr="running",dr="blocked",fr="sleeping",hr="done",mr="error",gr={ready:{}};gr.ready.stop=lr,gr.ready.start=pr,gr.ready.cancel=hr,gr.ready.fail=mr,gr.running={},gr.running.stop=lr,gr.running.start=pr,gr.running.block=dr,gr.running.unblock=pr,gr.running.sleep=fr,gr.running.wakeup=pr,gr.running.cancel=hr,gr.running.fail=mr,gr.blocked={},gr.blocked.stop=dr,gr.blocked.start=dr,gr.blocked.block=dr,gr.blocked.unblock=dr,gr.blocked.sleep=dr,gr.blocked.wakeup=dr,gr.blocked.cancel=hr,gr.blocked.fail=mr,gr.sleeping={},gr.sleeping.stop=fr,gr.sleeping.start=fr,gr.sleeping.block=fr,gr.sleeping.unblock=fr,gr.sleeping.sleep=fr,gr.sleeping.wakeup=fr,gr.sleeping.cancel=hr,gr.sleeping.fail=mr,gr.done={},gr.done.stop=hr,gr.done.start=hr,gr.done.block=hr,gr.done.unblock=hr,gr.done.sleep=hr,gr.done.wakeup=hr,gr.done.cancel=hr,gr.done.fail=mr,gr.error={},gr.error.stop=mr,gr.error.start=mr,gr.error.block=mr,gr.error.unblock=mr,gr.error.sleep=mr,gr.error.wakeup=mr,gr.error.cancel=mr,gr.error.fail=mr;var vr=function(e){this.id=-1,this.name=e.name||"?",this.parent=e.parent||null,this.run=e.run,this.subtasks=[],this.error=!1,this.state=lr,this.blocks=0,this.timeoutId=null,this.swapTime=null,this.userData=null,this.id=ur++,sr[this.id]=this};vr.prototype.debug=function(e){e=e||"",z.log.debug(ir,e,"[%s][%s] task:",this.id,this.name,this,"subtasks:",this.subtasks.length,"queue:",cr)},vr.prototype.next=function(e,t){"function"==typeof e&&(t=e,e=this.name);var n=new vr({run:t,name:e,parent:this});return n.state=pr,n.type=this.type,n.successCallback=this.successCallback||null,n.failureCallback=this.failureCallback||null,this.subtasks.push(n),this},vr.prototype.parallel=function(e,t){return z.util.isArray(e)&&(t=e,e=this.name),this.next(e,(function(n){var r=n;r.block(t.length);for(var a=function(e,n){z.task.start({type:e,run:function(e){t[n](e)},success:function(e){r.unblock()},failure:function(e){r.unblock()}})},o=0;o<t.length;o++)a(e+"__parallel-"+n.id+"-"+o,o)}))},vr.prototype.stop=function(){this.state=gr[this.state].stop},vr.prototype.start=function(){this.error=!1,this.state=gr[this.state].start,this.state===pr&&(this.start=new Date,this.run(this),yr(this,0))},vr.prototype.block=function(e){e=void 0===e?1:e,this.blocks+=e,this.blocks>0&&(this.state=gr[this.state].block)},vr.prototype.unblock=function(e){return e=void 0===e?1:e,this.blocks-=e,0===this.blocks&&this.state!==hr&&(this.state=pr,yr(this,0)),this.blocks},vr.prototype.sleep=function(e){e=void 0===e?0:e,this.state=gr[this.state].sleep;var t=this;this.timeoutId=setTimeout((function(){t.timeoutId=null,t.state=pr,yr(t,0)}),e)},vr.prototype.wait=function(e){e.wait(this)},vr.prototype.wakeup=function(){this.state===fr&&(cancelTimeout(this.timeoutId),this.timeoutId=null,this.state=pr,yr(this,0))},vr.prototype.cancel=function(){this.state=gr[this.state].cancel,this.permitsNeeded=0,null!==this.timeoutId&&(cancelTimeout(this.timeoutId),this.timeoutId=null),this.subtasks=[]},vr.prototype.fail=function(e){if(this.error=!0,br(this,!0),e)e.error=this.error,e.swapTime=this.swapTime,e.userData=this.userData,yr(e,0);else{if(null!==this.parent){for(var t=this.parent;null!==t.parent;)t.error=this.error,t.swapTime=this.swapTime,t.userData=this.userData,t=t.parent;br(t,!0)}this.failureCallback&&this.failureCallback(this)}};var yr=function(e,t){var n=t>30||+new Date-e.swapTime>20,r=function(t){if(t++,e.state===pr)if(n&&(e.swapTime=+new Date),e.subtasks.length>0){var r=e.subtasks.shift();r.error=e.error,r.swapTime=e.swapTime,r.userData=e.userData,r.run(r),r.error||yr(r,t)}else br(e),e.error||null!==e.parent&&(e.parent.error=e.error,e.parent.swapTime=e.swapTime,e.parent.userData=e.userData,yr(e.parent,t))};n?setTimeout(r,0):r(t)},br=function(e,t){e.state=hr,delete sr[e.id],null===e.parent&&(e.type in cr?0===cr[e.type].length?z.log.error(ir,"[%s][%s] task queue empty [%s]",e.id,e.name,e.type):cr[e.type][0]!==e?z.log.error(ir,"[%s][%s] task not first in queue [%s]",e.id,e.name,e.type):(cr[e.type].shift(),0===cr[e.type].length?delete cr[e.type]:cr[e.type][0].start()):z.log.error(ir,"[%s][%s] task queue missing [%s]",e.id,e.name,e.type),t||(e.error&&e.failureCallback?e.failureCallback(e):!e.error&&e.successCallback&&e.successCallback(e)))};z.task=z.task||{},z.task.start=function(e){var t=new vr({run:e.run,name:e.name||"?"});t.type=e.type,t.successCallback=e.success||null,t.failureCallback=e.failure||null,t.type in cr?cr[e.type].push(t):(cr[t.type]=[t],function(e){e.error=!1,e.state=gr[e.state].start,setTimeout((function(){e.state===pr&&(e.swapTime=+new Date,e.run(e),yr(e,0))}),0)}(t))},z.task.cancel=function(e){e in cr&&(cr[e]=[cr[e][0]])},z.task.createCondition=function(){var e={tasks:{},wait:function(t){t.id in e.tasks||(t.block(),e.tasks[t.id]=t)},notify:function(){var t=e.tasks;for(var n in e.tasks={},t)t[n].unblock()}};return e};var xr=z,wr=function(){function e(e){this.secretKey=e}return e.prototype.encrypt=function(e,t){throw new Error("Method not implemented.")},e.prototype.decrypt=function(e,t){return function(e,t,n){void 0===n&&(n=xr.util.createBuffer(Uint8Array.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer));var r,a,o=xr.cipher.createDecipher("AES-CBC",t);return o.start({iv:n}),o.update(xr.util.createBuffer(xr.util.hexToBytes(e))),a=(r=o.output.data).charCodeAt(r.length-1),r.slice(0,-a)}(e,(n=this.secretKey,r=t.transactionID,""+n.slice(0,16)+r.slice(0,16)));var n,r},e}(),kr=function(){function e(e,t,n,a){void 0===n&&(n="production"),void 0===a&&(a={supportTransaction:!1,enableEncryption:!1}),this.transactionEnabled=a.supportTransaction||!1,this.encryptionEnabled=a.enableEncryption||!1;var o=F(e,t,n,{headers:a.httpHeaders});this.transactionManager=new V(o),this.encryptionService=new wr(t),this.compareFaceService=new p(o),this.clientSettingsService=new d(o),this.convertPDFService=new y(o),this.ekycPDFService=new b(o),this.readIDCardService=new r(o),this.requestVerifyIDCardService=new h(o),this.requestVerifyPortraitSerivce=new m(o),this.imagesService=new c(o),this.fileService=new l(o),this.verifyFaceLivenessService=new f(o),this.searchFaceService=new v(o),this.detectIDTamperingService=new g(o)}return e.prototype.enableTransaction=function(){this.transactionEnabled=!0},e.prototype.disableTransaction=function(){this.transactionEnabled=!1},e.prototype.enableEncryption=function(){this.encryptionEnabled=!0},e.prototype.disableEncryption=function(){this.encryptionEnabled=!1},e.prototype.compareFaces=function(e,t){return this.compareFaceService.request(e,t)},e.prototype.clientSettings=function(){return this.clientSettingsService.request()},e.prototype.uploadImage=function(e){return this.imagesService.request(e)},e.prototype.uploadFile=function(e){return this.fileService.uploadFile(e)},e.prototype.convertPDF=function(e,t){return this.convertPDFService.request(e,t)},e.prototype.ekycPDF=function(e,t){return this.ekycPDFService.request(e,t)},e.prototype.readIDCard=function(e,t){return this.readIDCardService.request(e,t)},e.prototype.requestVerifyIDCard=function(e,t){return this.requestVerifyIDCardService.request(e,t)},e.prototype.requestVerifyPortrait=function(e,t){return this.requestVerifyPortraitSerivce.request(e,t)},e.prototype.verifyFaceLiveness=function(e,t){return this.verifyFaceLivenessService.request(e,t)},e.prototype.searchFaces=function(e,t){return this.searchFaceService.request(e,t)},e.prototype.deleteFaces=function(e,t){return this.searchFaceService.deleteFaces(e,t)},e.prototype.indexFaces=function(e,t){return this.searchFaceService.indexFaces(e,t)},e.prototype.downloadFaceImage=function(e){return this.searchFaceService.downloadFaceImage(e)},e.prototype.downloadImage=function(e){return this.imagesService.download(e)},e.prototype.updateMetadata=function(e,t){return this.imagesService.updateMetadata(e,t)},e.prototype.detectIDTampering=function(e,t){return this.detectIDTamperingService.request(e,t)},o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"compareFaces",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"convertPDF",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"readIDCard",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"requestVerifyIDCard",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"requestVerifyPortrait",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"verifyFaceLiveness",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"searchFaces",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"deleteFaces",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"indexFaces",null),o([L({headerIndex:1}),U(),i("design:type",Function),i("design:paramtypes",[Object,Object]),i("design:returntype",Promise)],e.prototype,"detectIDTampering",null),e}();e.ReadIDCard=r,e.UploadImage=c,e.UploadFile=l,e.CompareFaces=p,e.ClientSettings=d,e.VerifyFaceLiveness=f,e.RequestVerifyIDCard=h,e.RequestVerifyPortrait=m,e.DetectIDTampering=g,e.SearchFaces=v,e.ConvertPDF=y,e.EkycPDF=b,e.HttpClient=N,e.MockClient=A,e.TVAuthorizer=D,e.createHelpers=function(e,t,n){void 0===n&&(n="production");var r=new D(e,t),a=function(e){switch(e){case"testing":return"https://tv-testing.trustingsocial.com/api";case"staging":return"https://tv-staging.trustingsocial.com/api";case"production":default:return"https://vn-vision.trustingsocial.com/api"}}(n);return new N({authorizer:r,domain:a})},e.createHttpClient=F,e.SimpleTrustVisionAPI=P,e.default=kr,Object.defineProperty(e,"__esModule",{value:!0})}(r,t.default)}))),Kce=["accessKey","secretKey","apiUrl"],qce=["apiCheck","mode","accessKey","secretKey","apiUrl","onLivenessDetectionDone","onError"],Qce=tx.getUAMetadata(),Xce=function(){function e(t){var n=this,r=t.container,a=t.lang,o=void 0===a?"en":a,i=t.assetRoot,s=void 0===i?"https://unpkg.com/@tsocial/tvweb-sdk@latest/assets":i,u=t.libRoot,c=void 0===u?"":u,l=t.enableAntiDebug,p=void 0===l||l;Jm(this,e),ng(this,"checkCamera",(function(e){var t=e.frontCamera,r=void 0===t||t;return new Promise((function(e){K4.render(lv.createElement(jv.SDKSettingsProvider,{value:og({},n.commonSettings)},lv.createElement(j6,{checkCameraMode:!0,frontCamera:r,onVideoPlayed:function(){n.destroyView(),e(null)},onClose:n.destroyView,onError:function(t){n.destroyView(),e(t)}})),n.container)}))})),ng(this,"runWarmUpReadIDCard",Zm(regeneratorRuntime.mark((function e(){var t,r,a,o,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.commonSettings,r=t.tfjsWasmRoot,a=t.blazefaceRoot,o=t.opencvUrl,i=t.idCardModelUrl,e.abrupt("return",Vse({opencvUrl:o,modelUrl:i,blazefaceRoot:a,tfjsWasmRoot:r}));case 2:case"end":return e.stop()}}),e)})))),ng(this,"destroyView",(function(){K4.unmountComponentAtNode(n.container)})),Hce(r,"container is a required parameter"),this.container=r,this.lang=o,this.assetRoot=s,this.libRoot=c,this.enableAntiDebug=p,this.commonSettings={lang:this.lang,assetRoot:this.assetRoot,tfjsWasmRoot:this.libRoot?"".concat(this.libRoot,"/tfjs-backend-wasm/"):void 0,blazefaceRoot:this.libRoot?"".concat(this.libRoot,"/blaze-face-model/model.json"):void 0,opencvUrl:this.libRoot?"".concat(this.libRoot,"/opencv.js"):void 0,idCardModelUrl:this.libRoot?"".concat(this.libRoot,"/id-card-model/uint8/model.json"):void 0}}return tg(e,[{key:"readIDCard",value:function(e){var t=e.accessKey,n=e.secretKey,r=e.apiUrl,a=pg(e,Kce),o=ux.createRetryAPIClient(new Gce(t,n,r,{httpHeaders:Qce}));K4.render(lv.createElement(jv.SDKSettingsProvider,{value:og(og({},this.commonSettings),{},{apiClient:o,debug:!1,enableAntiDebug:this.enableAntiDebug})},lv.createElement(Dce,rg({onClose:this.destroyView},a))),this.container)}},{key:"livenessDetection",value:function(e){var t=e.apiCheck,n=e.mode,r=e.accessKey,a=e.secretKey,o=e.apiUrl,i=e.onLivenessDetectionDone,s=e.onError,u=pg(e,qce),c=ux.createRetryAPIClient(new Gce(r,a,o,{httpHeaders:Qce}));K4.render(lv.createElement(jv.SDKSettingsProvider,{value:og(og({},this.commonSettings),{},{apiClient:c})},lv.createElement(zce,rg({},u,{apiCheck:t,mode:n,onLivenessDetectionDone:i,onClose:this.destroyView,onError:s}))),this.container)}},{key:"compareFaces",value:function(e){var t=e.accessKey,n=e.secretKey,r=e.apiUrl,a=e.image1,o=e.image2,i=e.onSuccess,s=e.onError;ux.createRetryAPIClient(new Gce(t,n,r,{httpHeaders:Qce})).compareFaces({image1:{id:a},image2:{id:o}}).then((function(e){i(e)})).catch((function(e){s(e)}))}}]),e}();exports.APIUtils=ux,exports.Animations=Vue,exports.AntiDebugUtils=NK,exports.AssetUtils=Gv,exports.AsyncUtils=qv,exports.BASE_Z_INDEX=1e3,exports.BlurUtils=Ty,exports.Camera=j6,exports.CameraUtils=Ny,exports.CommonUtils=Ry,exports.Constants=Lv,exports.CoordinateUtils=Fy,exports.CropAreaOverlayWrapper=Q6,exports.FaceUtils=Hy,exports.GlareUtils=Jb,exports.Icons=Fce,exports.ImageUtils=Xb,exports.LivenessDetection=zce,exports.LivenessDetectionComponents=Wce,exports.LoadResourceUtils=yx,exports.MobileDetect=w6,exports.ModelUtils=_K,exports.OrientationMode=Pce,exports.PlacementArea=q6,exports.Popup=Zse,exports.PredictionUtils=Qy,exports.ProgressCircle=y9,exports.ReadIDCard=Dce,exports.SDK=Xce,exports.SettingsContext=jv,exports.UserAgentUtils=tx,exports.useDetectOrientation=Lce,exports.useLivenessDetection=jce,exports.warmUpReadIdCard=Vse;