@voxepay/checkout 0.3.0 → 0.3.2
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.
- package/dist/index.cjs.js +320 -28072
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +320 -28072
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/encryption.d.ts +6 -0
- package/dist/voxepay-checkout.min.js +1 -1
- package/dist/voxepay-checkout.min.js.map +1 -1
- package/package.json +2 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var VoxePay=function(e,t){"use strict";const r=[{name:"Visa",code:"visa",pattern:/^4/,lengths:[13,16,19],cvvLength:3},{name:"Mastercard",code:"mastercard",pattern:/^(5[1-5]|2[2-7])/,lengths:[16],cvvLength:3},{name:"Verve",code:"verve",pattern:/^(506[0-9]|507[0-9]|6500)/,lengths:[16,18,19],cvvLength:3},{name:"American Express",code:"amex",pattern:/^3[47]/,lengths:[15],cvvLength:4},{name:"Discover",code:"discover",pattern:/^(6011|65|64[4-9])/,lengths:[16,19],cvvLength:3}];function a(e){const t=e.replace(/\s/g,"");for(const e of r)if(e.pattern.test(t))return e;return null}function n(e){const t=e.replace(/\s/g,"");if(!/^\d+$/.test(t))return!1;let r=0,a=!1;for(let e=t.length-1;e>=0;e--){let n=parseInt(t[e],10);a&&(n*=2,n>9&&(n-=9)),r+=n,a=!a}return r%10==0}function i(e){const t=e.replace(/\s/g,"");if(!t)return{valid:!1,error:"Card number is required"};if(!/^\d+$/.test(t))return{valid:!1,error:"Invalid card number"};const r=a(t);return r?r.lengths.includes(t.length)?n(t)?{valid:!0}:{valid:!1,error:"Invalid card number"}:{valid:!1,error:"Invalid card number length"}:{valid:!1,error:"Unsupported card type"}}function s(e){const t=e.replace(/\s/g,"");if(!t)return{valid:!1,error:"Expiry date is required"};const r=t.match(/^(\d{2})\/(\d{2})$/);if(!r)return{valid:!1,error:"Invalid format (MM/YY)"};const a=parseInt(r[1],10),n=parseInt(r[2],10)+2e3;if(a<1||a>12)return{valid:!1,error:"Invalid month"};const i=new Date,s=i.getFullYear(),o=i.getMonth()+1;return n<s||n===s&&a<o?{valid:!1,error:"Card has expired"}:n>s+20?{valid:!1,error:"Invalid expiry year"}:{valid:!0}}function o(e,t){const r=e.replace(/\s/g,"");if(!r)return{valid:!1,error:"CVV is required"};if(!/^\d+$/.test(r))return{valid:!1,error:"Invalid CVV"};const n=t?a(t):null,i=(null==n?void 0:n.cvvLength)||3;return r.length!==i&&3!==r.length&&4!==r.length?{valid:!1,error:`CVV must be ${i} digits`}:{valid:!0}}function c(e){return(e.replace(/\D/g,"").match(/.{1,4}/g)||[]).join(" ").slice(0,23)}function l(e){const t=e.replace(/\D/g,"");if(0===t.length)return"";if(1===t.length)return parseInt(t)>1?`0${t}`:t;if(2===t.length){const e=parseInt(t);return e>12?"12":0===e?"01":t}return`${t.slice(0,2)}/${t.slice(2,4)}`}function u(e){return e.replace(/\D/g,"").slice(0,4)}function p(e,t){return new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:2}).format(e/100)}var d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function h(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var f={options:{usePureJavaScript:!1}},y={},g=y,v={};y.encode=function(e,t,r){if("string"!=typeof t)throw new TypeError('"alphabet" must be a string.');if(void 0!==r&&"number"!=typeof r)throw new TypeError('"maxline" must be a number.');var a="";if(e instanceof Uint8Array){var n=0,i=t.length,s=t.charAt(0),o=[0];for(n=0;n<e.length;++n){for(var c=0,l=e[n];c<o.length;++c)l+=o[c]<<8,o[c]=l%i,l=l/i|0;for(;l>0;)o.push(l%i),l=l/i|0}for(n=0;0===e[n]&&n<e.length-1;++n)a+=s;for(n=o.length-1;n>=0;--n)a+=t[o[n]]}else a=function(e,t){var r=0,a=t.length,n=t.charAt(0),i=[0];for(r=0;r<e.length();++r){for(var s=0,o=e.at(r);s<i.length;++s)o+=i[s]<<8,i[s]=o%a,o=o/a|0;for(;o>0;)i.push(o%a),o=o/a|0}var c="";for(r=0;0===e.at(r)&&r<e.length()-1;++r)c+=n;for(r=i.length-1;r>=0;--r)c+=t[i[r]];return c}(e,t);if(r){var u=new RegExp(".{1,"+r+"}","g");a=a.match(u).join("\r\n")}return a},y.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 r=v[t];if(!r){r=v[t]=[];for(var a=0;a<t.length;++a)r[t.charCodeAt(a)]=a}e=e.replace(/\s/g,"");var n=t.length,i=t.charAt(0),s=[0];for(a=0;a<e.length;a++){var o=r[e.charCodeAt(a)];if(void 0===o)return;for(var c=0,l=o;c<s.length;++c)l+=s[c]*n,s[c]=255&l,l>>=8;for(;l>0;)s.push(255&l),l>>=8}for(var u=0;e[u]===i&&u<e.length-1;++u)s.push(0);return"undefined"!=typeof Buffer?Buffer.from(s.reverse()):new Uint8Array(s.reverse())};var m=f,C=g,E=m.util=m.util||{};function S(e){if(8!==e&&16!==e&&24!==e&&32!==e)throw new Error("Only 8, 16, 24, or 32 bits supported: "+e)}function b(e){if(this.data="",this.read=0,"string"==typeof e)this.data=e;else if(E.isArrayBuffer(e)||E.isArrayBufferView(e))if("undefined"!=typeof Buffer&&e instanceof Buffer)this.data=e.toString("binary");else{var t=new Uint8Array(e);try{this.data=String.fromCharCode.apply(null,t)}catch(e){for(var r=0;r<t.length;++r)this.putByte(t[r])}}else(e instanceof b||"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 E.nextTick=process.nextTick,void("function"==typeof setImmediate?E.setImmediate=setImmediate:E.setImmediate=E.nextTick);if("function"==typeof setImmediate)return E.setImmediate=function(){return setImmediate.apply(void 0,arguments)},void(E.nextTick=function(e){return setImmediate(e)});if(E.setImmediate=function(e){setTimeout(e,0)},"undefined"!=typeof window&&"function"==typeof window.postMessage){var e="forge.setImmediate",t=[];function s(r){if(r.source===window&&r.data===e){r.stopPropagation();var a=t.slice();t.length=0,a.forEach(function(e){e()})}}E.setImmediate=function(r){t.push(r),1===t.length&&window.postMessage(e,"*")},window.addEventListener("message",s,!0)}if("undefined"!=typeof MutationObserver){var r=Date.now(),a=!0,n=document.createElement("div");t=[];new MutationObserver(function(){var e=t.slice();t.length=0,e.forEach(function(e){e()})}).observe(n,{attributes:!0});var i=E.setImmediate;E.setImmediate=function(e){Date.now()-r>15?(r=Date.now(),i(e)):(t.push(e),1===t.length&&n.setAttribute("a",a=!a))}}E.nextTick=E.setImmediate}(),E.isNodejs="undefined"!=typeof process&&process.versions&&process.versions.node,E.globalScope=E.isNodejs?d:"undefined"==typeof self?window:self,E.isArray=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},E.isArrayBuffer=function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer},E.isArrayBufferView=function(e){return e&&E.isArrayBuffer(e.buffer)&&void 0!==e.byteLength},E.ByteBuffer=b,E.ByteStringBuffer=b;E.ByteStringBuffer.prototype._optimizeConstructedString=function(e){this._constructedStringLength+=e,this._constructedStringLength>4096&&(this.data.substr(0,1),this._constructedStringLength=0)},E.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read},E.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0},E.ByteStringBuffer.prototype.putByte=function(e){return this.putBytes(String.fromCharCode(e))},E.ByteStringBuffer.prototype.fillWithByte=function(e,t){e=String.fromCharCode(e);for(var r=this.data;t>0;)1&t&&(r+=e),(t>>>=1)>0&&(e+=e);return this.data=r,this._optimizeConstructedString(t),this},E.ByteStringBuffer.prototype.putBytes=function(e){return this.data+=e,this._optimizeConstructedString(e.length),this},E.ByteStringBuffer.prototype.putString=function(e){return this.putBytes(E.encodeUtf8(e))},E.ByteStringBuffer.prototype.putInt16=function(e){return this.putBytes(String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},E.ByteStringBuffer.prototype.putInt24=function(e){return this.putBytes(String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e))},E.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))},E.ByteStringBuffer.prototype.putInt16Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255))},E.ByteStringBuffer.prototype.putInt24Le=function(e){return this.putBytes(String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255))},E.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))},E.ByteStringBuffer.prototype.putInt=function(e,t){S(t);var r="";do{t-=8,r+=String.fromCharCode(e>>t&255)}while(t>0);return this.putBytes(r)},E.ByteStringBuffer.prototype.putSignedInt=function(e,t){return e<0&&(e+=2<<t-1),this.putInt(e,t)},E.ByteStringBuffer.prototype.putBuffer=function(e){return this.putBytes(e.getBytes())},E.ByteStringBuffer.prototype.getByte=function(){return this.data.charCodeAt(this.read++)},E.ByteStringBuffer.prototype.getInt16=function(){var e=this.data.charCodeAt(this.read)<<8^this.data.charCodeAt(this.read+1);return this.read+=2,e},E.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},E.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},E.ByteStringBuffer.prototype.getInt16Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8;return this.read+=2,e},E.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},E.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},E.ByteStringBuffer.prototype.getInt=function(e){S(e);var t=0;do{t=(t<<8)+this.data.charCodeAt(this.read++),e-=8}while(e>0);return t},E.ByteStringBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),r=2<<e-2;return t>=r&&(t-=r<<1),t},E.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},E.ByteStringBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},E.ByteStringBuffer.prototype.at=function(e){return this.data.charCodeAt(this.read+e)},E.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},E.ByteStringBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},E.ByteStringBuffer.prototype.copy=function(){var e=E.createBuffer(this.data);return e.read=this.read,e},E.ByteStringBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},E.ByteStringBuffer.prototype.clear=function(){return this.data="",this.read=0,this},E.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},E.ByteStringBuffer.prototype.toHex=function(){for(var e="",t=this.read;t<this.data.length;++t){var r=this.data.charCodeAt(t);r<16&&(e+="0"),e+=r.toString(16)}return e},E.ByteStringBuffer.prototype.toString=function(){return E.decodeUtf8(this.bytes())},E.DataBuffer=function(e,t){t=t||{},this.read=t.readOffset||0,this.growSize=t.growSize||1024;var r=E.isArrayBuffer(e),a=E.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 t?t.writeOffset:this.data.byteLength);this.data=new DataView(new ArrayBuffer(0)),this.write=0,null!=e&&this.putBytes(e),"writeOffset"in t&&(this.write=t.writeOffset)},E.DataBuffer.prototype.length=function(){return this.write-this.read},E.DataBuffer.prototype.isEmpty=function(){return this.length()<=0},E.DataBuffer.prototype.accommodate=function(e,t){if(this.length()>=e)return this;t=Math.max(t||this.growSize,e);var r=new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength),a=new Uint8Array(this.length()+t);return a.set(r),this.data=new DataView(a.buffer),this},E.DataBuffer.prototype.putByte=function(e){return this.accommodate(1),this.data.setUint8(this.write++,e),this},E.DataBuffer.prototype.fillWithByte=function(e,t){this.accommodate(t);for(var r=0;r<t;++r)this.data.setUint8(e);return this},E.DataBuffer.prototype.putBytes=function(e,t){if(E.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(E.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 E.DataBuffer||"object"==typeof e&&"number"==typeof e.read&&"number"==typeof e.write&&E.isArrayBufferView(e.data)){a=new Uint8Array(e.data.byteLength,e.read,e.length());return this.accommodate(a.byteLength),new Uint8Array(e.data.byteLength,this.write).set(a),this.write+=a.byteLength,this}if(e instanceof E.ByteStringBuffer&&(e=e.data,t="binary"),t=t||"binary","string"==typeof e){var n;if("hex"===t)return this.accommodate(Math.ceil(e.length/2)),n=new Uint8Array(this.data.buffer,this.write),this.write+=E.binary.hex.decode(e,n,this.write),this;if("base64"===t)return this.accommodate(3*Math.ceil(e.length/4)),n=new Uint8Array(this.data.buffer,this.write),this.write+=E.binary.base64.decode(e,n,this.write),this;if("utf8"===t&&(e=E.encodeUtf8(e),t="binary"),"binary"===t||"raw"===t)return this.accommodate(e.length),n=new Uint8Array(this.data.buffer,this.write),this.write+=E.binary.raw.decode(n),this;if("utf16"===t)return this.accommodate(2*e.length),n=new Uint16Array(this.data.buffer,this.write),this.write+=E.text.utf16.encode(n),this;throw new Error("Invalid encoding: "+t)}throw Error("Invalid parameter: "+e)},E.DataBuffer.prototype.putBuffer=function(e){return this.putBytes(e),e.clear(),this},E.DataBuffer.prototype.putString=function(e){return this.putBytes(e,"utf16")},E.DataBuffer.prototype.putInt16=function(e){return this.accommodate(2),this.data.setInt16(this.write,e),this.write+=2,this},E.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},E.DataBuffer.prototype.putInt32=function(e){return this.accommodate(4),this.data.setInt32(this.write,e),this.write+=4,this},E.DataBuffer.prototype.putInt16Le=function(e){return this.accommodate(2),this.data.setInt16(this.write,e,!0),this.write+=2,this},E.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},E.DataBuffer.prototype.putInt32Le=function(e){return this.accommodate(4),this.data.setInt32(this.write,e,!0),this.write+=4,this},E.DataBuffer.prototype.putInt=function(e,t){S(t),this.accommodate(t/8);do{t-=8,this.data.setInt8(this.write++,e>>t&255)}while(t>0);return this},E.DataBuffer.prototype.putSignedInt=function(e,t){return S(t),this.accommodate(t/8),e<0&&(e+=2<<t-1),this.putInt(e,t)},E.DataBuffer.prototype.getByte=function(){return this.data.getInt8(this.read++)},E.DataBuffer.prototype.getInt16=function(){var e=this.data.getInt16(this.read);return this.read+=2,e},E.DataBuffer.prototype.getInt24=function(){var e=this.data.getInt16(this.read)<<8^this.data.getInt8(this.read+2);return this.read+=3,e},E.DataBuffer.prototype.getInt32=function(){var e=this.data.getInt32(this.read);return this.read+=4,e},E.DataBuffer.prototype.getInt16Le=function(){var e=this.data.getInt16(this.read,!0);return this.read+=2,e},E.DataBuffer.prototype.getInt24Le=function(){var e=this.data.getInt8(this.read)^this.data.getInt16(this.read+1,!0)<<8;return this.read+=3,e},E.DataBuffer.prototype.getInt32Le=function(){var e=this.data.getInt32(this.read,!0);return this.read+=4,e},E.DataBuffer.prototype.getInt=function(e){S(e);var t=0;do{t=(t<<8)+this.data.getInt8(this.read++),e-=8}while(e>0);return t},E.DataBuffer.prototype.getSignedInt=function(e){var t=this.getInt(e),r=2<<e-2;return t>=r&&(t-=r<<1),t},E.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},E.DataBuffer.prototype.bytes=function(e){return void 0===e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},E.DataBuffer.prototype.at=function(e){return this.data.getUint8(this.read+e)},E.DataBuffer.prototype.setAt=function(e,t){return this.data.setUint8(e,t),this},E.DataBuffer.prototype.last=function(){return this.data.getUint8(this.write-1)},E.DataBuffer.prototype.copy=function(){return new E.DataBuffer(this)},E.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},E.DataBuffer.prototype.clear=function(){return this.data=new DataView(new ArrayBuffer(0)),this.read=this.write=0,this},E.DataBuffer.prototype.truncate=function(e){return this.write=Math.max(0,this.length()-e),this.read=Math.min(this.read,this.write),this},E.DataBuffer.prototype.toHex=function(){for(var e="",t=this.read;t<this.data.byteLength;++t){var r=this.data.getUint8(t);r<16&&(e+="0"),e+=r.toString(16)}return e},E.DataBuffer.prototype.toString=function(e){var t=new Uint8Array(this.data,this.read,this.length());if("binary"===(e=e||"utf8")||"raw"===e)return E.binary.raw.encode(t);if("hex"===e)return E.binary.hex.encode(t);if("base64"===e)return E.binary.base64.encode(t);if("utf8"===e)return E.text.utf8.decode(t);if("utf16"===e)return E.text.utf16.decode(t);throw new Error("Invalid encoding: "+e)},E.createBuffer=function(e,t){return t=t||"raw",void 0!==e&&"utf8"===t&&(e=E.encodeUtf8(e)),new E.ByteBuffer(e)},E.fillString=function(e,t){for(var r="";t>0;)1&t&&(r+=e),(t>>>=1)>0&&(e+=e);return r},E.xorBytes=function(e,t,r){for(var a="",n="",i="",s=0,o=0;r>0;--r,++s)n=e.charCodeAt(s)^t.charCodeAt(s),o>=10&&(a+=i,i="",o=0),i+=String.fromCharCode(n),++o;return a+=i},E.hexToBytes=function(e){var t="",r=0;for(!0&e.length&&(r=1,t+=String.fromCharCode(parseInt(e[0],16)));r<e.length;r+=2)t+=String.fromCharCode(parseInt(e.substr(r,2),16));return t},E.bytesToHex=function(e){return E.createBuffer(e).toHex()},E.int32ToBytes=function(e){return String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e)};var T="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",I=[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],A="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";E.encode64=function(e,t){for(var r,a,n,i="",s="",o=0;o<e.length;)r=e.charCodeAt(o++),a=e.charCodeAt(o++),n=e.charCodeAt(o++),i+=T.charAt(r>>2),i+=T.charAt((3&r)<<4|a>>4),isNaN(a)?i+="==":(i+=T.charAt((15&a)<<2|n>>6),i+=isNaN(n)?"=":T.charAt(63&n)),t&&i.length>t&&(s+=i.substr(0,t)+"\r\n",i=i.substr(t));return s+=i},E.decode64=function(e){e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var t,r,a,n,i="",s=0;s<e.length;)t=I[e.charCodeAt(s++)-43],r=I[e.charCodeAt(s++)-43],a=I[e.charCodeAt(s++)-43],n=I[e.charCodeAt(s++)-43],i+=String.fromCharCode(t<<2|r>>4),64!==a&&(i+=String.fromCharCode((15&r)<<4|a>>2),64!==n&&(i+=String.fromCharCode((3&a)<<6|n)));return i},E.encodeUtf8=function(e){return unescape(encodeURIComponent(e))},E.decodeUtf8=function(e){return decodeURIComponent(escape(e))},E.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:C.encode,decode:C.decode}},E.binary.raw.encode=function(e){return String.fromCharCode.apply(null,e)},E.binary.raw.decode=function(e,t,r){var a=t;a||(a=new Uint8Array(e.length));for(var n=r=r||0,i=0;i<e.length;++i)a[n++]=e.charCodeAt(i);return t?n-r:a},E.binary.hex.encode=E.bytesToHex,E.binary.hex.decode=function(e,t,r){var a=t;a||(a=new Uint8Array(Math.ceil(e.length/2)));var n=0,i=r=r||0;for(1&e.length&&(n=1,a[i++]=parseInt(e[0],16));n<e.length;n+=2)a[i++]=parseInt(e.substr(n,2),16);return t?i-r:a},E.binary.base64.encode=function(e,t){for(var r,a,n,i="",s="",o=0;o<e.byteLength;)r=e[o++],a=e[o++],n=e[o++],i+=T.charAt(r>>2),i+=T.charAt((3&r)<<4|a>>4),isNaN(a)?i+="==":(i+=T.charAt((15&a)<<2|n>>6),i+=isNaN(n)?"=":T.charAt(63&n)),t&&i.length>t&&(s+=i.substr(0,t)+"\r\n",i=i.substr(t));return s+=i},E.binary.base64.decode=function(e,t,r){var a,n,i,s,o=t;o||(o=new Uint8Array(3*Math.ceil(e.length/4))),e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var c=0,l=r=r||0;c<e.length;)a=I[e.charCodeAt(c++)-43],n=I[e.charCodeAt(c++)-43],i=I[e.charCodeAt(c++)-43],s=I[e.charCodeAt(c++)-43],o[l++]=a<<2|n>>4,64!==i&&(o[l++]=(15&n)<<4|i>>2,64!==s&&(o[l++]=(3&i)<<6|s));return t?l-r:o.subarray(0,l)},E.binary.base58.encode=function(e,t){return E.binary.baseN.encode(e,A,t)},E.binary.base58.decode=function(e,t){return E.binary.baseN.decode(e,A,t)},E.text={utf8:{},utf16:{}},E.text.utf8.encode=function(e,t,r){e=E.encodeUtf8(e);var a=t;a||(a=new Uint8Array(e.length));for(var n=r=r||0,i=0;i<e.length;++i)a[n++]=e.charCodeAt(i);return t?n-r:a},E.text.utf8.decode=function(e){return E.decodeUtf8(String.fromCharCode.apply(null,e))},E.text.utf16.encode=function(e,t,r){var a=t;a||(a=new Uint8Array(2*e.length));for(var n=new Uint16Array(a.buffer),i=r=r||0,s=r,o=0;o<e.length;++o)n[s++]=e.charCodeAt(o),i+=2;return t?i-r:a},E.text.utf16.decode=function(e){return String.fromCharCode.apply(null,new Uint16Array(e.buffer))},E.deflate=function(e,t,r){if(t=E.decode64(e.deflate(E.encode64(t)).rval),r){var a=2;32&t.charCodeAt(1)&&(a=6),t=t.substring(a,t.length-4)}return t},E.inflate=function(e,t,r){var a=e.inflate(E.encode64(t)).rval;return null===a?null:E.decode64(a)};var B=function(e,t,r){if(!e)throw new Error("WebStorage not available.");var a;if(null===r?a=e.removeItem(t):(r=E.encode64(JSON.stringify(r)),a=e.setItem(t,r)),void 0!==a&&!0!==a.rval){var n=new Error(a.error.message);throw n.id=a.error.id,n.name=a.error.name,n}},x=function(e,t){if(!e)throw new Error("WebStorage not available.");var r=e.getItem(t);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(E.decode64(r))),r},w=function(e,t,r,a){var n=x(e,t);null===n&&(n={}),n[r]=a,B(e,t,n)},N=function(e,t,r){var a=x(e,t);return null!==a&&(a=r in a?a[r]:null),a},k=function(e,t,r){var a=x(e,t);if(null!==a&&r in a){delete a[r];var n=!0;for(var i in a){n=!1;break}n&&(a=null),B(e,t,a)}},R=function(e,t){B(e,t,null)},L=function(e,t,r){var a,n=null;void 0===r&&(r=["web","flash"]);var i=!1,s=null;for(var o in r){a=r[o];try{if("flash"===a||"both"===a){if(null===t[0])throw new Error("Flash local storage not available.");n=e.apply(this,t),i="flash"===a}"web"!==a&&"both"!==a||(t[0]=localStorage,n=e.apply(this,t),i=!0)}catch(e){s=e}if(i)break}if(!i)throw s;return n};E.setItem=function(e,t,r,a,n){L(w,arguments,n)},E.getItem=function(e,t,r,a){return L(N,arguments,a)},E.removeItem=function(e,t,r,a){L(k,arguments,a)},E.clearItems=function(e,t,r){L(R,arguments,r)},E.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},E.format=function(e){for(var t,r,a=/%./g,n=0,i=[],s=0;t=a.exec(e);){(r=e.substring(s,a.lastIndex-2)).length>0&&i.push(r),s=a.lastIndex;var o=t[0][1];switch(o){case"s":case"o":n<arguments.length?i.push(arguments[1+n++]):i.push("<?>");break;case"%":i.push("%");break;default:i.push("<%"+o+"?>")}}return i.push(e.substring(s)),i.join("")},E.formatNumber=function(e,t,r,a){var n=e,i=isNaN(t=Math.abs(t))?2:t,s=void 0===r?",":r,o=void 0===a?".":a,c=n<0?"-":"",l=parseInt(n=Math.abs(+n||0).toFixed(i),10)+"",u=l.length>3?l.length%3:0;return c+(u?l.substr(0,u)+o:"")+l.substr(u).replace(/(\d{3})(?=\d)/g,"$1"+o)+(i?s+Math.abs(n-l).toFixed(i).slice(2):"")},E.formatSize=function(e){return e=e>=1073741824?E.formatNumber(e/1073741824,2,".","")+" GiB":e>=1048576?E.formatNumber(e/1048576,2,".","")+" MiB":e>=1024?E.formatNumber(e/1024,0)+" KiB":E.formatNumber(e,0)+" bytes"},E.bytesFromIP=function(e){return-1!==e.indexOf(".")?E.bytesFromIPv4(e):-1!==e.indexOf(":")?E.bytesFromIPv6(e):null},E.bytesFromIPv4=function(e){if(4!==(e=e.split(".")).length)return null;for(var t=E.createBuffer(),r=0;r<e.length;++r){var a=parseInt(e[r],10);if(isNaN(a))return null;t.putByte(a)}return t.getBytes()},E.bytesFromIPv6=function(e){for(var t=0,r=2*(8-(e=e.split(":").filter(function(e){return 0===e.length&&++t,!0})).length+t),a=E.createBuffer(),n=0;n<8;++n)if(e[n]&&0!==e[n].length){var i=E.hexToBytes(e[n]);i.length<2&&a.putByte(0),a.putBytes(i)}else a.fillWithByte(0,r),r=0;return a.getBytes()},E.bytesToIP=function(e){return 4===e.length?E.bytesToIPv4(e):16===e.length?E.bytesToIPv6(e):null},E.bytesToIPv4=function(e){if(4!==e.length)return null;for(var t=[],r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t.join(".")},E.bytesToIPv6=function(e){if(16!==e.length)return null;for(var t=[],r=[],a=0,n=0;n<e.length;n+=2){for(var i=E.bytesToHex(e[n]+e[n+1]);"0"===i[0]&&"0"!==i;)i=i.substr(1);if("0"===i){var s=r[r.length-1],o=t.length;s&&o===s.end+1?(s.end=o,s.end-s.start>r[a].end-r[a].start&&(a=r.length-1)):r.push({start:o,end:o})}t.push(i)}if(r.length>0){var c=r[a];c.end-c.start>0&&(t.splice(c.start,c.end-c.start+1,""),0===c.start&&t.unshift(""),7===c.end&&t.push(""))}return t.join(":")},E.estimateCores=function(e,t){if("function"==typeof e&&(t=e,e={}),e=e||{},"cores"in E&&!e.update)return t(null,E.cores);if("undefined"!=typeof navigator&&"hardwareConcurrency"in navigator&&navigator.hardwareConcurrency>0)return E.cores=navigator.hardwareConcurrency,t(null,E.cores);if("undefined"==typeof Worker)return E.cores=1,t(null,E.cores);if("undefined"==typeof Blob)return E.cores=2,t(null,E.cores);var r=URL.createObjectURL(new Blob(["(",function(){self.addEventListener("message",function(e){var t=Date.now(),r=t+4;self.postMessage({st:t,et:r})})}.toString(),")()"],{type:"application/javascript"}));!function e(a,n,i){if(0===n){var s=Math.floor(a.reduce(function(e,t){return e+t},0)/a.length);return E.cores=Math.max(1,s),URL.revokeObjectURL(r),t(null,E.cores)}!function(e,t){for(var a=[],n=[],i=0;i<e;++i){var s=new Worker(r);s.addEventListener("message",function(r){if(n.push(r.data),n.length===e){for(var i=0;i<e;++i)a[i].terminate();t(null,n)}}),a.push(s)}for(i=0;i<e;++i)a[i].postMessage(i)}(i,function(t,r){a.push(function(e,t){for(var r=[],a=0;a<e;++a)for(var n=t[a],i=r[a]=[],s=0;s<e;++s)if(a!==s){var o=t[s];(n.st>o.st&&n.st<o.et||o.st>n.st&&o.st<n.et)&&i.push(s)}return r.reduce(function(e,t){return Math.max(e,t.length)},0)}(i,r)),e(a,n-1,i)})}([],5,16)};var _=f;_.cipher=_.cipher||{},_.cipher.algorithms=_.cipher.algorithms||{},_.cipher.createCipher=function(e,t){var r=e;if("string"==typeof r&&(r=_.cipher.getAlgorithm(r))&&(r=r()),!r)throw new Error("Unsupported algorithm: "+e);return new _.cipher.BlockCipher({algorithm:r,key:t,decrypt:!1})},_.cipher.createDecipher=function(e,t){var r=e;if("string"==typeof r&&(r=_.cipher.getAlgorithm(r))&&(r=r()),!r)throw new Error("Unsupported algorithm: "+e);return new _.cipher.BlockCipher({algorithm:r,key:t,decrypt:!0})},_.cipher.registerAlgorithm=function(e,t){e=e.toUpperCase(),_.cipher.algorithms[e]=t},_.cipher.getAlgorithm=function(e){return(e=e.toUpperCase())in _.cipher.algorithms?_.cipher.algorithms[e]:null};var D=_.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)};D.prototype.start=function(e){e=e||{};var t={};for(var r in e)t[r]=e[r];t.decrypt=this._decrypt,this._finish=!1,this._input=_.util.createBuffer(),this.output=e.output||_.util.createBuffer(),this.mode.start(t)},D.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()},D.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)))};var U=f;U.cipher=U.cipher||{};var P=U.cipher.modes=U.cipher.modes||{};function V(e,t){if("string"==typeof e&&(e=U.util.createBuffer(e)),U.util.isArray(e)&&e.length>4){var r=e;e=U.util.createBuffer();for(var a=0;a<r.length;++a)e.putByte(r[a])}if(e.length()<t)throw new Error("Invalid IV length; got "+e.length()+" bytes and expected "+t+" bytes.");if(!U.util.isArray(e)){var n=[],i=t/4;for(a=0;a<i;++a)n.push(e.getInt32());e=n}return e}function O(e){e[e.length-1]=e[e.length-1]+1&4294967295}function K(e){return[e/4294967296|0,4294967295&e]}P.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)},P.ecb.prototype.start=function(e){},P.ecb.prototype.encrypt=function(e,t,r){if(e.length()<this.blockSize&&!(r&&e.length()>0))return!0;for(var a=0;a<this._ints;++a)this._inBlock[a]=e.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(a=0;a<this._ints;++a)t.putInt32(this._outBlock[a])},P.ecb.prototype.decrypt=function(e,t,r){if(e.length()<this.blockSize&&!(r&&e.length()>0))return!0;for(var a=0;a<this._ints;++a)this._inBlock[a]=e.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(a=0;a<this._ints;++a)t.putInt32(this._outBlock[a])},P.ecb.prototype.pad=function(e,t){var r=e.length()===this.blockSize?this.blockSize:this.blockSize-e.length();return e.fillWithByte(r,r),!0},P.ecb.prototype.unpad=function(e,t){if(t.overflow>0)return!1;var r=e.length(),a=e.at(r-1);return!(a>this.blockSize<<2)&&(e.truncate(a),!0)},P.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)},P.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=V(e.iv,this.blockSize),this._prev=this._iv.slice(0)}},P.cbc.prototype.encrypt=function(e,t,r){if(e.length()<this.blockSize&&!(r&&e.length()>0))return!0;for(var a=0;a<this._ints;++a)this._inBlock[a]=this._prev[a]^e.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(a=0;a<this._ints;++a)t.putInt32(this._outBlock[a]);this._prev=this._outBlock},P.cbc.prototype.decrypt=function(e,t,r){if(e.length()<this.blockSize&&!(r&&e.length()>0))return!0;for(var a=0;a<this._ints;++a)this._inBlock[a]=e.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(a=0;a<this._ints;++a)t.putInt32(this._prev[a]^this._outBlock[a]);this._prev=this._inBlock.slice(0)},P.cbc.prototype.pad=function(e,t){var r=e.length()===this.blockSize?this.blockSize:this.blockSize-e.length();return e.fillWithByte(r,r),!0},P.cbc.prototype.unpad=function(e,t){if(t.overflow>0)return!1;var r=e.length(),a=e.at(r-1);return!(a>this.blockSize<<2)&&(e.truncate(a),!0)},P.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=U.util.createBuffer(),this._partialBytes=0},P.cfb.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=V(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},P.cfb.prototype.encrypt=function(e,t,r){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 n=0;n<this._ints;++n)this._inBlock[n]=e.getInt32()^this._outBlock[n],t.putInt32(this._inBlock[n]);else{var i=(this.blockSize-a)%this.blockSize;i>0&&(i=this.blockSize-i),this._partialOutput.clear();for(n=0;n<this._ints;++n)this._partialBlock[n]=e.getInt32()^this._outBlock[n],this._partialOutput.putInt32(this._partialBlock[n]);if(i>0)e.read-=this.blockSize;else for(n=0;n<this._ints;++n)this._inBlock[n]=this._partialBlock[n];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!r)return t.putBytes(this._partialOutput.getBytes(i-this._partialBytes)),this._partialBytes=i,!0;t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=0}},P.cfb.prototype.decrypt=function(e,t,r){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 n=0;n<this._ints;++n)this._inBlock[n]=e.getInt32(),t.putInt32(this._inBlock[n]^this._outBlock[n]);else{var i=(this.blockSize-a)%this.blockSize;i>0&&(i=this.blockSize-i),this._partialOutput.clear();for(n=0;n<this._ints;++n)this._partialBlock[n]=e.getInt32(),this._partialOutput.putInt32(this._partialBlock[n]^this._outBlock[n]);if(i>0)e.read-=this.blockSize;else for(n=0;n<this._ints;++n)this._inBlock[n]=this._partialBlock[n];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!r)return t.putBytes(this._partialOutput.getBytes(i-this._partialBytes)),this._partialBytes=i,!0;t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=0}},P.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=U.util.createBuffer(),this._partialBytes=0},P.ofb.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=V(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},P.ofb.prototype.encrypt=function(e,t,r){var a=e.length();if(0===e.length())return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),0===this._partialBytes&&a>=this.blockSize)for(var n=0;n<this._ints;++n)t.putInt32(e.getInt32()^this._outBlock[n]),this._inBlock[n]=this._outBlock[n];else{var i=(this.blockSize-a)%this.blockSize;i>0&&(i=this.blockSize-i),this._partialOutput.clear();for(n=0;n<this._ints;++n)this._partialOutput.putInt32(e.getInt32()^this._outBlock[n]);if(i>0)e.read-=this.blockSize;else for(n=0;n<this._ints;++n)this._inBlock[n]=this._outBlock[n];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!r)return t.putBytes(this._partialOutput.getBytes(i-this._partialBytes)),this._partialBytes=i,!0;t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=0}},P.ofb.prototype.decrypt=P.ofb.prototype.encrypt,P.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=U.util.createBuffer(),this._partialBytes=0},P.ctr.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");this._iv=V(e.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},P.ctr.prototype.encrypt=function(e,t,r){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 n=0;n<this._ints;++n)t.putInt32(e.getInt32()^this._outBlock[n]);else{var i=(this.blockSize-a)%this.blockSize;i>0&&(i=this.blockSize-i),this._partialOutput.clear();for(n=0;n<this._ints;++n)this._partialOutput.putInt32(e.getInt32()^this._outBlock[n]);if(i>0&&(e.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!r)return t.putBytes(this._partialOutput.getBytes(i-this._partialBytes)),this._partialBytes=i,!0;t.putBytes(this._partialOutput.getBytes(a-this._partialBytes)),this._partialBytes=0}O(this._inBlock)},P.ctr.prototype.decrypt=P.ctr.prototype.encrypt,P.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=U.util.createBuffer(),this._partialBytes=0,this._R=3774873600},P.gcm.prototype.start=function(e){if(!("iv"in e))throw new Error("Invalid IV parameter.");var t,r=U.util.createBuffer(e.iv);if(this._cipherLength=0,t="additionalData"in e?U.util.createBuffer(e.additionalData):U.util.createBuffer(),this._tagLength="tagLength"in e?e.tagLength:128,this._tag=null,e.decrypt&&(this._tag=U.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 a=r.length();if(12===a)this._j0=[r.getInt32(),r.getInt32(),r.getInt32(),1];else{for(this._j0=[0,0,0,0];r.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[r.getInt32(),r.getInt32(),r.getInt32(),r.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(K(8*a)))}this._inBlock=this._j0.slice(0),O(this._inBlock),this._partialBytes=0,t=U.util.createBuffer(t),this._aDataLength=K(8*t.length());var n=t.length()%this.blockSize;for(n&&t.fillWithByte(0,this.blockSize-n),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()])},P.gcm.prototype.encrypt=function(e,t,r){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 n=0;n<this._ints;++n)t.putInt32(this._outBlock[n]^=e.getInt32());this._cipherLength+=this.blockSize}else{var i=(this.blockSize-a)%this.blockSize;i>0&&(i=this.blockSize-i),this._partialOutput.clear();for(n=0;n<this._ints;++n)this._partialOutput.putInt32(e.getInt32()^this._outBlock[n]);if(i<=0||r){if(r){var s=a%this.blockSize;this._cipherLength+=s,this._partialOutput.truncate(this.blockSize-s)}else this._cipherLength+=this.blockSize;for(n=0;n<this._ints;++n)this._outBlock[n]=this._partialOutput.getInt32();this._partialOutput.read-=this.blockSize}if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),i>0&&!r)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),O(this._inBlock)},P.gcm.prototype.decrypt=function(e,t,r){var a=e.length();if(a<this.blockSize&&!(r&&a>0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),O(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 n=0;n<this._ints;++n)t.putInt32(this._outBlock[n]^this._hashBlock[n]);a<this.blockSize?this._cipherLength+=a%this.blockSize:this._cipherLength+=this.blockSize},P.gcm.prototype.afterFinish=function(e,t){var r=!0;t.decrypt&&t.overflow&&e.truncate(this.blockSize-t.overflow),this.tag=U.util.createBuffer();var a=this._aDataLength.concat(K(8*this._cipherLength));this._s=this.ghash(this._hashSubkey,this._s,a);var n=[];this.cipher.encrypt(this._j0,n);for(var i=0;i<this._ints;++i)this.tag.putInt32(this._s[i]^n[i]);return this.tag.truncate(this.tag.length()%(this._tagLength/8)),t.decrypt&&this.tag.bytes()!==this._tag&&(r=!1),r},P.gcm.prototype.multiply=function(e,t){for(var r=[0,0,0,0],a=t.slice(0),n=0;n<128;++n){e[n/32|0]&1<<31-n%32&&(r[0]^=a[0],r[1]^=a[1],r[2]^=a[2],r[3]^=a[3]),this.pow(a,a)}return r},P.gcm.prototype.pow=function(e,t){for(var r=1&e[3],a=3;a>0;--a)t[a]=e[a]>>>1|(1&e[a-1])<<31;t[0]=e[0]>>>1,r&&(t[0]^=this._R)},P.gcm.prototype.tableMultiply=function(e){for(var t=[0,0,0,0],r=0;r<32;++r){var a=e[r/8|0]>>>4*(7-r%8)&15,n=this._m[r][a];t[0]^=n[0],t[1]^=n[1],t[2]^=n[2],t[3]^=n[3]}return t},P.gcm.prototype.ghash=function(e,t,r){return t[0]^=r[0],t[1]^=r[1],t[2]^=r[2],t[3]^=r[3],this.tableMultiply(t)},P.gcm.prototype.generateHashTable=function(e,t){for(var r=8/t,a=4*r,n=16*r,i=new Array(n),s=0;s<n;++s){var o=[0,0,0,0],c=(a-1-s%a)*t;o[s/a|0]=1<<t-1<<c,i[s]=this.generateSubHashTable(this.multiply(o,e),t)}return i},P.gcm.prototype.generateSubHashTable=function(e,t){var r=1<<t,a=r>>>1,n=new Array(r);n[a]=e.slice(0);for(var i=a>>>1;i>0;)this.pow(n[2*i],n[i]=[]),i>>=1;for(i=2;i<a;){for(var s=1;s<i;++s){var o=n[i],c=n[s];n[i+s]=[o[0]^c[0],o[1]^c[1],o[2]^c[2],o[3]^c[3]]}i*=2}for(n[0]=[0,0,0,0],i=a+1;i<r;++i){var l=n[i^a];n[i]=[e[0]^l[0],e[1]^l[1],e[2]^l[2],e[3]^l[3]]}return n};var M=f;function F(e,t){M.cipher.registerAlgorithm(e,function(){return new M.aes.Algorithm(e,t)})}M.aes=M.aes||{},M.aes.startEncrypting=function(e,t,r,a){var n=Z({key:e,output:r,decrypt:!1,mode:a});return n.start(t),n},M.aes.createEncryptionCipher=function(e,t){return Z({key:e,output:null,decrypt:!1,mode:t})},M.aes.startDecrypting=function(e,t,r,a){var n=Z({key:e,output:r,decrypt:!0,mode:a});return n.start(t),n},M.aes.createDecryptionCipher=function(e,t){return Z({key:e,output:null,decrypt:!0,mode:t})},M.aes.Algorithm=function(e,t){Q||X();var r=this;r.name=e,r.mode=new t({blockSize:16,cipher:{encrypt:function(e,t){return $(r._w,e,t,!1)},decrypt:function(e,t){return $(r._w,e,t,!0)}}}),r._init=!1},M.aes.Algorithm.prototype.initialize=function(e){if(!this._init){var t,r=e.key;if("string"!=typeof r||16!==r.length&&24!==r.length&&32!==r.length){if(M.util.isArray(r)&&(16===r.length||24===r.length||32===r.length)){t=r,r=M.util.createBuffer();for(var a=0;a<t.length;++a)r.putByte(t[a])}}else r=M.util.createBuffer(r);if(!M.util.isArray(r)){t=r,r=[];var n=t.length();if(16===n||24===n||32===n){n>>>=2;for(a=0;a<n;++a)r.push(t.getInt32())}}if(!M.util.isArray(r)||4!==r.length&&6!==r.length&&8!==r.length)throw new Error("Invalid key parameter.");var i=this.mode.name,s=-1!==["CFB","OFB","CTR","GCM"].indexOf(i);this._w=W(r,e.decrypt&&!s),this._init=!0}},M.aes._expandKey=function(e,t){return Q||X(),W(e,t)},M.aes._updateBlock=$,F("AES-ECB",M.cipher.modes.ecb),F("AES-CBC",M.cipher.modes.cbc),F("AES-CFB",M.cipher.modes.cfb),F("AES-OFB",M.cipher.modes.ofb),F("AES-CTR",M.cipher.modes.ctr),F("AES-GCM",M.cipher.modes.gcm);var q,j,H,G,z,Q=!1,Y=4;function X(){Q=!0,H=[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;q=new Array(256),j=new Array(256),G=new Array(4),z=new Array(4);for(t=0;t<4;++t)G[t]=new Array(256),z[t]=new Array(256);var r,a,n,i,s,o,c,l=0,u=0;for(t=0;t<256;++t){i=(i=u^u<<1^u<<2^u<<3^u<<4)>>8^255&i^99,q[l]=i,j[i]=l,o=(s=e[i])<<24^i<<16^i<<8^i^s,c=((r=e[l])^(a=e[r])^(n=e[a]))<<24^(l^n)<<16^(l^a^n)<<8^l^r^n;for(var p=0;p<4;++p)G[p][l]=o,z[p][i]=c,o=o<<24|o>>>8,c=c<<24|c>>>8;0===l?l=u=1:(l=r^e[e[e[r^n]]],u^=e[e[u]])}}function W(e,t){for(var r,a=e.slice(0),n=1,i=a.length,s=Y*(i+6+1),o=i;o<s;++o)r=a[o-1],o%i===0?(r=q[r>>>16&255]<<24^q[r>>>8&255]<<16^q[255&r]<<8^q[r>>>24]^H[n]<<24,n++):i>6&&o%i===4&&(r=q[r>>>24]<<24^q[r>>>16&255]<<16^q[r>>>8&255]<<8^q[255&r]),a[o]=a[o-i]^r;if(t){for(var c,l=z[0],u=z[1],p=z[2],d=z[3],h=a.slice(0),f=(o=0,(s=a.length)-Y);o<s;o+=Y,f-=Y)if(0===o||o===s-Y)h[o]=a[f],h[o+1]=a[f+3],h[o+2]=a[f+2],h[o+3]=a[f+1];else for(var y=0;y<Y;++y)c=a[f+y],h[o+(3&-y)]=l[q[c>>>24]]^u[q[c>>>16&255]]^p[q[c>>>8&255]]^d[q[255&c]];a=h}return a}function $(e,t,r,a){var n,i,s,o,c,l,u,p,d,h,f,y,g=e.length/4-1;a?(n=z[0],i=z[1],s=z[2],o=z[3],c=j):(n=G[0],i=G[1],s=G[2],o=G[3],c=q),l=t[0]^e[0],u=t[a?3:1]^e[1],p=t[2]^e[2],d=t[a?1:3]^e[3];for(var v=3,m=1;m<g;++m)h=n[l>>>24]^i[u>>>16&255]^s[p>>>8&255]^o[255&d]^e[++v],f=n[u>>>24]^i[p>>>16&255]^s[d>>>8&255]^o[255&l]^e[++v],y=n[p>>>24]^i[d>>>16&255]^s[l>>>8&255]^o[255&u]^e[++v],d=n[d>>>24]^i[l>>>16&255]^s[u>>>8&255]^o[255&p]^e[++v],l=h,u=f,p=y;r[0]=c[l>>>24]<<24^c[u>>>16&255]<<16^c[p>>>8&255]<<8^c[255&d]^e[++v],r[a?3:1]=c[u>>>24]<<24^c[p>>>16&255]<<16^c[d>>>8&255]<<8^c[255&l]^e[++v],r[2]=c[p>>>24]<<24^c[d>>>16&255]<<16^c[l>>>8&255]<<8^c[255&u]^e[++v],r[a?1:3]=c[d>>>24]<<24^c[l>>>16&255]<<16^c[u>>>8&255]<<8^c[255&p]^e[++v]}function Z(e){var t,r="AES-"+((e=e||{}).mode||"CBC").toUpperCase(),a=(t=e.decrypt?M.cipher.createDecipher(r,e.key):M.cipher.createCipher(r,e.key)).start;return t.start=function(e,r){var n=null;r instanceof M.util.ByteBuffer&&(n=r,r={}),(r=r||{}).output=n,r.iv=e,a.call(t,r)},t}var J=f;J.pki=J.pki||{};var ee=J.pki.oids=J.oids=J.oids||{};function te(e,t){ee[e]=t,ee[t]=e}function re(e,t){ee[e]=t}te("1.2.840.113549.1.1.1","rsaEncryption"),te("1.2.840.113549.1.1.4","md5WithRSAEncryption"),te("1.2.840.113549.1.1.5","sha1WithRSAEncryption"),te("1.2.840.113549.1.1.7","RSAES-OAEP"),te("1.2.840.113549.1.1.8","mgf1"),te("1.2.840.113549.1.1.9","pSpecified"),te("1.2.840.113549.1.1.10","RSASSA-PSS"),te("1.2.840.113549.1.1.11","sha256WithRSAEncryption"),te("1.2.840.113549.1.1.12","sha384WithRSAEncryption"),te("1.2.840.113549.1.1.13","sha512WithRSAEncryption"),te("1.3.101.112","EdDSA25519"),te("1.2.840.10040.4.3","dsa-with-sha1"),te("1.3.14.3.2.7","desCBC"),te("1.3.14.3.2.26","sha1"),te("1.3.14.3.2.29","sha1WithRSASignature"),te("2.16.840.1.101.3.4.2.1","sha256"),te("2.16.840.1.101.3.4.2.2","sha384"),te("2.16.840.1.101.3.4.2.3","sha512"),te("2.16.840.1.101.3.4.2.4","sha224"),te("2.16.840.1.101.3.4.2.5","sha512-224"),te("2.16.840.1.101.3.4.2.6","sha512-256"),te("1.2.840.113549.2.2","md2"),te("1.2.840.113549.2.5","md5"),te("1.2.840.113549.1.7.1","data"),te("1.2.840.113549.1.7.2","signedData"),te("1.2.840.113549.1.7.3","envelopedData"),te("1.2.840.113549.1.7.4","signedAndEnvelopedData"),te("1.2.840.113549.1.7.5","digestedData"),te("1.2.840.113549.1.7.6","encryptedData"),te("1.2.840.113549.1.9.1","emailAddress"),te("1.2.840.113549.1.9.2","unstructuredName"),te("1.2.840.113549.1.9.3","contentType"),te("1.2.840.113549.1.9.4","messageDigest"),te("1.2.840.113549.1.9.5","signingTime"),te("1.2.840.113549.1.9.6","counterSignature"),te("1.2.840.113549.1.9.7","challengePassword"),te("1.2.840.113549.1.9.8","unstructuredAddress"),te("1.2.840.113549.1.9.14","extensionRequest"),te("1.2.840.113549.1.9.20","friendlyName"),te("1.2.840.113549.1.9.21","localKeyId"),te("1.2.840.113549.1.9.22.1","x509Certificate"),te("1.2.840.113549.1.12.10.1.1","keyBag"),te("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag"),te("1.2.840.113549.1.12.10.1.3","certBag"),te("1.2.840.113549.1.12.10.1.4","crlBag"),te("1.2.840.113549.1.12.10.1.5","secretBag"),te("1.2.840.113549.1.12.10.1.6","safeContentsBag"),te("1.2.840.113549.1.5.13","pkcs5PBES2"),te("1.2.840.113549.1.5.12","pkcs5PBKDF2"),te("1.2.840.113549.1.12.1.1","pbeWithSHAAnd128BitRC4"),te("1.2.840.113549.1.12.1.2","pbeWithSHAAnd40BitRC4"),te("1.2.840.113549.1.12.1.3","pbeWithSHAAnd3-KeyTripleDES-CBC"),te("1.2.840.113549.1.12.1.4","pbeWithSHAAnd2-KeyTripleDES-CBC"),te("1.2.840.113549.1.12.1.5","pbeWithSHAAnd128BitRC2-CBC"),te("1.2.840.113549.1.12.1.6","pbewithSHAAnd40BitRC2-CBC"),te("1.2.840.113549.2.7","hmacWithSHA1"),te("1.2.840.113549.2.8","hmacWithSHA224"),te("1.2.840.113549.2.9","hmacWithSHA256"),te("1.2.840.113549.2.10","hmacWithSHA384"),te("1.2.840.113549.2.11","hmacWithSHA512"),te("1.2.840.113549.3.7","des-EDE3-CBC"),te("2.16.840.1.101.3.4.1.2","aes128-CBC"),te("2.16.840.1.101.3.4.1.22","aes192-CBC"),te("2.16.840.1.101.3.4.1.42","aes256-CBC"),te("2.5.4.3","commonName"),te("2.5.4.4","surname"),te("2.5.4.5","serialNumber"),te("2.5.4.6","countryName"),te("2.5.4.7","localityName"),te("2.5.4.8","stateOrProvinceName"),te("2.5.4.9","streetAddress"),te("2.5.4.10","organizationName"),te("2.5.4.11","organizationalUnitName"),te("2.5.4.12","title"),te("2.5.4.13","description"),te("2.5.4.15","businessCategory"),te("2.5.4.17","postalCode"),te("2.5.4.42","givenName"),te("1.3.6.1.4.1.311.60.2.1.2","jurisdictionOfIncorporationStateOrProvinceName"),te("1.3.6.1.4.1.311.60.2.1.3","jurisdictionOfIncorporationCountryName"),te("2.16.840.1.113730.1.1","nsCertType"),te("2.16.840.1.113730.1.13","nsComment"),re("2.5.29.1","authorityKeyIdentifier"),re("2.5.29.2","keyAttributes"),re("2.5.29.3","certificatePolicies"),re("2.5.29.4","keyUsageRestriction"),re("2.5.29.5","policyMapping"),re("2.5.29.6","subtreesConstraint"),re("2.5.29.7","subjectAltName"),re("2.5.29.8","issuerAltName"),re("2.5.29.9","subjectDirectoryAttributes"),re("2.5.29.10","basicConstraints"),re("2.5.29.11","nameConstraints"),re("2.5.29.12","policyConstraints"),re("2.5.29.13","basicConstraints"),te("2.5.29.14","subjectKeyIdentifier"),te("2.5.29.15","keyUsage"),re("2.5.29.16","privateKeyUsagePeriod"),te("2.5.29.17","subjectAltName"),te("2.5.29.18","issuerAltName"),te("2.5.29.19","basicConstraints"),re("2.5.29.20","cRLNumber"),re("2.5.29.21","cRLReason"),re("2.5.29.22","expirationDate"),re("2.5.29.23","instructionCode"),re("2.5.29.24","invalidityDate"),re("2.5.29.25","cRLDistributionPoints"),re("2.5.29.26","issuingDistributionPoint"),re("2.5.29.27","deltaCRLIndicator"),re("2.5.29.28","issuingDistributionPoint"),re("2.5.29.29","certificateIssuer"),re("2.5.29.30","nameConstraints"),te("2.5.29.31","cRLDistributionPoints"),te("2.5.29.32","certificatePolicies"),re("2.5.29.33","policyMappings"),re("2.5.29.34","policyConstraints"),te("2.5.29.35","authorityKeyIdentifier"),re("2.5.29.36","policyConstraints"),te("2.5.29.37","extKeyUsage"),re("2.5.29.46","freshestCRL"),re("2.5.29.54","inhibitAnyPolicy"),te("1.3.6.1.4.1.11129.2.4.2","timestampList"),te("1.3.6.1.5.5.7.1.1","authorityInfoAccess"),te("1.3.6.1.5.5.7.3.1","serverAuth"),te("1.3.6.1.5.5.7.3.2","clientAuth"),te("1.3.6.1.5.5.7.3.3","codeSigning"),te("1.3.6.1.5.5.7.3.4","emailProtection"),te("1.3.6.1.5.5.7.3.8","timeStamping");var ae=f,ne=ae.asn1=ae.asn1||{};function ie(e,t,r){if(r>t){var a=new Error("Too few bytes to parse DER.");throw a.available=e.length(),a.remaining=t,a.requested=r,a}}ne.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},ne.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},ne.maxDepth=256,ne.create=function(e,t,r,a,n){if(ae.util.isArray(a)){for(var i=[],s=0;s<a.length;++s)void 0!==a[s]&&i.push(a[s]);a=i}var o={tagClass:e,type:t,constructed:r,composed:r||ae.util.isArray(a),value:a};return n&&"bitStringContents"in n&&(o.bitStringContents=n.bitStringContents,o.original=ne.copy(o)),o},ne.copy=function(e,t){var r;if(ae.util.isArray(e)){r=[];for(var a=0;a<e.length;++a)r.push(ne.copy(e[a],t));return r}return"string"==typeof e?e:(r={tagClass:e.tagClass,type:e.type,constructed:e.constructed,composed:e.composed,value:ne.copy(e.value,t)},t&&!t.excludeBitStringContents&&(r.bitStringContents=e.bitStringContents),r)},ne.equals=function(e,t,r){if(ae.util.isArray(e)){if(!ae.util.isArray(t))return!1;if(e.length!==t.length)return!1;for(var a=0;a<e.length;++a)if(!ne.equals(e[a],t[a]))return!1;return!0}if(typeof e!=typeof t)return!1;if("string"==typeof e)return e===t;var n=e.tagClass===t.tagClass&&e.type===t.type&&e.constructed===t.constructed&&e.composed===t.composed&&ne.equals(e.value,t.value);return r&&r.includeBitStringContents&&(n=n&&e.bitStringContents===t.bitStringContents),n},ne.getBerValueLength=function(e){var t=e.getByte();if(128!==t)return 128&t?e.getInt((127&t)<<3):t};function se(e,t,r,a){if(r>=a.maxDepth)throw new Error("ASN.1 parsing error: Max depth exceeded.");var n;ie(e,t,2);var i=e.getByte();t--;var s=192&i,o=31&i;n=e.length();var c,l,u=function(e,t){var r=e.getByte();if(t--,128!==r){var a;if(128&r){var n=127&r;ie(e,t,n),a=e.getInt(n<<3)}else a=r;if(a<0)throw new Error("Negative length: "+a);return a}}(e,t);if(t-=n-e.length(),void 0!==u&&u>t){if(a.strict){var p=new Error("Too few bytes to read ASN.1 value.");throw p.available=e.length(),p.remaining=t,p.requested=u,p}u=t}var d=!(32&~i);if(d)if(c=[],void 0===u)for(;;){if(ie(e,t,2),e.bytes(2)===String.fromCharCode(0,0)){e.getBytes(2),t-=2;break}n=e.length(),c.push(se(e,t,r+1,a)),t-=n-e.length()}else for(;u>0;)n=e.length(),c.push(se(e,u,r+1,a)),t-=n-e.length(),u-=n-e.length();if(void 0===c&&s===ne.Class.UNIVERSAL&&o===ne.Type.BITSTRING&&(l=e.bytes(u)),void 0===c&&a.decodeBitStrings&&s===ne.Class.UNIVERSAL&&o===ne.Type.BITSTRING&&u>1){var h=e.read,f=t,y=0;if(o===ne.Type.BITSTRING&&(ie(e,t,1),y=e.getByte(),t--),0===y)try{n=e.length();var g=se(e,t,r+1,{strict:!0,decodeBitStrings:!0}),v=n-e.length();t-=v,o==ne.Type.BITSTRING&&v++;var m=g.tagClass;v!==u||m!==ne.Class.UNIVERSAL&&m!==ne.Class.CONTEXT_SPECIFIC||(c=[g])}catch(e){}void 0===c&&(e.read=h,t=f)}if(void 0===c){if(void 0===u){if(a.strict)throw new Error("Non-constructed ASN.1 object of indefinite length.");u=t}if(o===ne.Type.BMPSTRING)for(c="";u>0;u-=2)ie(e,t,2),c+=String.fromCharCode(e.getInt16()),t-=2;else c=e.getBytes(u),t-=u}var C=void 0===l?null:{bitStringContents:l};return ne.create(s,o,d,c,C)}ne.fromDer=function(e,t){void 0===t&&(t={strict:!0,parseAllBytes:!0,decodeBitStrings:!0}),"boolean"==typeof t&&(t={strict:t,parseAllBytes:!0,decodeBitStrings:!0}),"strict"in t||(t.strict=!0),"parseAllBytes"in t||(t.parseAllBytes=!0),"decodeBitStrings"in t||(t.decodeBitStrings=!0),"maxDepth"in t||(t.maxDepth=ne.maxDepth),"string"==typeof e&&(e=ae.util.createBuffer(e));var r=e.length(),a=se(e,e.length(),0,t);if(t.parseAllBytes&&0!==e.length()){var n=new Error("Unparsed DER bytes remain after ASN.1 parsing.");throw n.byteCount=r,n.remaining=e.length(),n}return a},ne.toDer=function(e){var t=ae.util.createBuffer(),r=e.tagClass|e.type,a=ae.util.createBuffer(),n=!1;if("bitStringContents"in e&&(n=!0,e.original&&(n=ne.equals(e,e.original))),n)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(ne.toDer(e.value[i]))}else if(e.type===ne.Type.BMPSTRING)for(i=0;i<e.value.length;++i)a.putInt16(e.value.charCodeAt(i));else!(e.type===ne.Type.INTEGER&&e.value.length>1)||(0!==e.value.charCodeAt(0)||128&e.value.charCodeAt(1))&&(255!==e.value.charCodeAt(0)||128&~e.value.charCodeAt(1))?a.putBytes(e.value):a.putBytes(e.value.substr(1));if(t.putByte(r),a.length()<=127)t.putByte(127&a.length());else{var s=a.length(),o="";do{o+=String.fromCharCode(255&s),s>>>=8}while(s>0);t.putByte(128|o.length);for(i=o.length-1;i>=0;--i)t.putByte(o.charCodeAt(i))}return t.putBuffer(a),t},ne.oidToDer=function(e){var t,r,a,n,i=e.split("."),s=ae.util.createBuffer();s.putByte(40*parseInt(i[0],10)+parseInt(i[1],10));for(var o=2;o<i.length;++o){if(t=!0,r=[],(a=parseInt(i[o],10))>4294967295)throw new Error("OID value too large; max is 32-bits.");do{n=127&a,a>>>=7,t||(n|=128),r.push(n),t=!1}while(a>0);for(var c=r.length-1;c>=0;--c)s.putByte(r[c])}return s},ne.derToOid=function(e){var t;"string"==typeof e&&(e=ae.util.createBuffer(e));var r=e.getByte();t=Math.floor(r/40)+"."+r%40;for(var a=0;e.length()>0;){if(a>70368744177663)throw new Error("OID value too large; max is 53-bits.");a*=128,128&(r=e.getByte())?a+=127&r:(t+="."+(a+r),a=0)}return t},ne.utcTimeToDate=function(e){var t=new Date,r=parseInt(e.substr(0,2),10);r=r>=50?1900+r:2e3+r;var a=parseInt(e.substr(2,2),10)-1,n=parseInt(e.substr(4,2),10),i=parseInt(e.substr(6,2),10),s=parseInt(e.substr(8,2),10),o=0;if(e.length>11){var c=e.charAt(10),l=10;"+"!==c&&"-"!==c&&(o=parseInt(e.substr(10,2),10),l+=2)}if(t.setUTCFullYear(r,a,n),t.setUTCHours(i,s,o,0),l&&("+"===(c=e.charAt(l))||"-"===c)){var u=60*parseInt(e.substr(l+1,2),10)+parseInt(e.substr(l+4,2),10);u*=6e4,"+"===c?t.setTime(+t-u):t.setTime(+t+u)}return t},ne.generalizedTimeToDate=function(e){var t=new Date,r=parseInt(e.substr(0,4),10),a=parseInt(e.substr(4,2),10)-1,n=parseInt(e.substr(6,2),10),i=parseInt(e.substr(8,2),10),s=parseInt(e.substr(10,2),10),o=parseInt(e.substr(12,2),10),c=0,l=0,u=!1;"Z"===e.charAt(e.length-1)&&(u=!0);var p=e.length-5,d=e.charAt(p);"+"!==d&&"-"!==d||(l=60*parseInt(e.substr(p+1,2),10)+parseInt(e.substr(p+4,2),10),l*=6e4,"+"===d&&(l*=-1),u=!0);return"."===e.charAt(14)&&(c=1e3*parseFloat(e.substr(14),10)),u?(t.setUTCFullYear(r,a,n),t.setUTCHours(i,s,o,c),t.setTime(+t+l)):(t.setFullYear(r,a,n),t.setHours(i,s,o,c)),t},ne.dateToUtcTime=function(e){if("string"==typeof e)return e;var t="",r=[];r.push((""+e.getUTCFullYear()).substr(2)),r.push(""+(e.getUTCMonth()+1)),r.push(""+e.getUTCDate()),r.push(""+e.getUTCHours()),r.push(""+e.getUTCMinutes()),r.push(""+e.getUTCSeconds());for(var a=0;a<r.length;++a)r[a].length<2&&(t+="0"),t+=r[a];return t+="Z"},ne.dateToGeneralizedTime=function(e){if("string"==typeof e)return e;var t="",r=[];r.push(""+e.getUTCFullYear()),r.push(""+(e.getUTCMonth()+1)),r.push(""+e.getUTCDate()),r.push(""+e.getUTCHours()),r.push(""+e.getUTCMinutes()),r.push(""+e.getUTCSeconds());for(var a=0;a<r.length;++a)r[a].length<2&&(t+="0"),t+=r[a];return t+="Z"},ne.integerToDer=function(e){var t=ae.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 r=new Error("Integer too large; max is 32-bits.");throw r.integer=e,r},ne.derToInteger=function(e){"string"==typeof e&&(e=ae.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)},ne.validate=function(e,t,r,a){var n=!1;if(e.tagClass!==t.tagClass&&void 0!==t.tagClass||e.type!==t.type&&void 0!==t.type)a&&(e.tagClass!==t.tagClass&&a.push("["+t.name+'] Expected tag class "'+t.tagClass+'", got "'+e.tagClass+'"'),e.type!==t.type&&a.push("["+t.name+'] Expected type "'+t.type+'", got "'+e.type+'"'));else if(e.constructed===t.constructed||void 0===t.constructed){if(n=!0,t.value&&ae.util.isArray(t.value))for(var i=0,s=0;n&&s<t.value.length;++s){var o=t.value[s];n=!!o.optional;var c=e.value[i];if(c){if(void 0!==o.tagClass&&void 0!==o.type&&(c.tagClass!==o.tagClass||c.type!==o.type)){if(o.optional){n=!0;continue}n=!1,a&&a.push("["+t.name+"] Tag mismatch. Expected ("+o.tagClass+","+o.type+"), got ("+c.tagClass+","+c.type+")");break}if(ne.validate(c,o,r,a))++i,n=!0;else{if(!o.optional){n=!1;break}n=!0}}else o.optional||(n=!1,a&&a.push("["+t.name+'] Missing required element. Expected tag class "'+o.tagClass+'", type "'+o.type+'"'))}if(n&&r&&(t.capture&&(r[t.capture]=e.value),t.captureAsn1&&(r[t.captureAsn1]=e),t.captureBitStringContents&&"bitStringContents"in e&&(r[t.captureBitStringContents]=e.bitStringContents),t.captureBitStringValue&&"bitStringContents"in e))if(e.bitStringContents.length<2)r[t.captureBitStringValue]="";else{if(0!==e.bitStringContents.charCodeAt(0))throw new Error("captureBitStringValue only supported for zero unused bits");r[t.captureBitStringValue]=e.bitStringContents.slice(1)}}else a&&a.push("["+t.name+'] Expected constructed "'+t.constructed+'", got "'+e.constructed+'"');return n};var oe=/[^\\u0000-\\u00ff]/;ne.prettyPrint=function(e,t,r){var a="";r=r||2,(t=t||0)>0&&(a+="\n");for(var n="",i=0;i<t*r;++i)n+=" ";switch(a+=n+"Tag: ",e.tagClass){case ne.Class.UNIVERSAL:a+="Universal:";break;case ne.Class.APPLICATION:a+="Application:";break;case ne.Class.CONTEXT_SPECIFIC:a+="Context-Specific:";break;case ne.Class.PRIVATE:a+="Private:"}if(e.tagClass===ne.Class.UNIVERSAL)switch(a+=e.type,e.type){case ne.Type.NONE:a+=" (None)";break;case ne.Type.BOOLEAN:a+=" (Boolean)";break;case ne.Type.INTEGER:a+=" (Integer)";break;case ne.Type.BITSTRING:a+=" (Bit string)";break;case ne.Type.OCTETSTRING:a+=" (Octet string)";break;case ne.Type.NULL:a+=" (Null)";break;case ne.Type.OID:a+=" (Object Identifier)";break;case ne.Type.ODESC:a+=" (Object Descriptor)";break;case ne.Type.EXTERNAL:a+=" (External or Instance of)";break;case ne.Type.REAL:a+=" (Real)";break;case ne.Type.ENUMERATED:a+=" (Enumerated)";break;case ne.Type.EMBEDDED:a+=" (Embedded PDV)";break;case ne.Type.UTF8:a+=" (UTF8)";break;case ne.Type.ROID:a+=" (Relative Object Identifier)";break;case ne.Type.SEQUENCE:a+=" (Sequence)";break;case ne.Type.SET:a+=" (Set)";break;case ne.Type.PRINTABLESTRING:a+=" (Printable String)";break;case ne.Type.IA5String:a+=" (IA5String (ASCII))";break;case ne.Type.UTCTIME:a+=" (UTC time)";break;case ne.Type.GENERALIZEDTIME:a+=" (Generalized time)";break;case ne.Type.BMPSTRING:a+=" (BMP String)"}else a+=e.type;if(a+="\n",a+=n+"Constructed: "+e.constructed+"\n",e.composed){var s=0,o="";for(i=0;i<e.value.length;++i)void 0!==e.value[i]&&(s+=1,o+=ne.prettyPrint(e.value[i],t+1,r),i+1<e.value.length&&(o+=","));a+=n+"Sub values: "+s+o}else{if(a+=n+"Value: ",e.type===ne.Type.OID){var c=ne.derToOid(e.value);a+=c,ae.pki&&ae.pki.oids&&c in ae.pki.oids&&(a+=" ("+ae.pki.oids[c]+") ")}if(e.type===ne.Type.INTEGER)try{a+=ne.derToInteger(e.value)}catch(t){a+="0x"+ae.util.bytesToHex(e.value)}else if(e.type===ne.Type.BITSTRING){if(e.value.length>1?a+="0x"+ae.util.bytesToHex(e.value.slice(1)):a+="(none)",e.value.length>0){var l=e.value.charCodeAt(0);1==l?a+=" (1 unused bit shown)":l>1&&(a+=" ("+l+" unused bits shown)")}}else if(e.type===ne.Type.OCTETSTRING)oe.test(e.value)||(a+="("+e.value+") "),a+="0x"+ae.util.bytesToHex(e.value);else if(e.type===ne.Type.UTF8)try{a+=ae.util.decodeUtf8(e.value)}catch(t){if("URI malformed"!==t.message)throw t;a+="0x"+ae.util.bytesToHex(e.value)+" (malformed UTF8)"}else e.type===ne.Type.PRINTABLESTRING||e.type===ne.Type.IA5String?a+=e.value:oe.test(e.value)?a+="0x"+ae.util.bytesToHex(e.value):0===e.value.length?a+="[null]":a+=e.value}return a};var ce=f;ce.md=ce.md||{},ce.md.algorithms=ce.md.algorithms||{};var le=f;(le.hmac=le.hmac||{}).create=function(){var e=null,t=null,r=null,a=null,n={start:function(n,i){if(null!==n)if("string"==typeof n){if(!((n=n.toLowerCase())in le.md.algorithms))throw new Error('Unknown hash algorithm "'+n+'"');t=le.md.algorithms[n].create()}else t=n;if(null===i)i=e;else{if("string"==typeof i)i=le.util.createBuffer(i);else if(le.util.isArray(i)){var s=i;i=le.util.createBuffer();for(var o=0;o<s.length;++o)i.putByte(s[o])}var c=i.length();c>t.blockLength&&(t.start(),t.update(i.bytes()),i=t.digest()),r=le.util.createBuffer(),a=le.util.createBuffer(),c=i.length();for(o=0;o<c;++o){s=i.at(o);r.putByte(54^s),a.putByte(92^s)}if(c<t.blockLength)for(s=t.blockLength-c,o=0;o<s;++o)r.putByte(54),a.putByte(92);e=i,r=r.bytes(),a=a.bytes()}t.start(),t.update(r)},update:function(e){t.update(e)},getMac:function(){var e=t.digest().bytes();return t.start(),t.update(a),t.update(e),t.digest()}};return n.digest=n.getMac,n};var ue=f,pe=ue.md5=ue.md5||{};ue.md.md5=ue.md.algorithms.md5=pe,pe.create=function(){ge||function(){de=String.fromCharCode(128),de+=ue.util.fillString(String.fromCharCode(0),64),he=[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],fe=[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],ye=new Array(64);for(var e=0;e<64;++e)ye[e]=Math.floor(4294967296*Math.abs(Math.sin(e+1)));ge=!0}();var e=null,t=ue.util.createBuffer(),r=new Array(16),a={algorithm:"md5",blockLength:64,digestLength:16,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){a.messageLength=0,a.fullMessageLength=a.messageLength64=[];for(var r=a.messageLengthSize/4,n=0;n<r;++n)a.fullMessageLength.push(0);return t=ue.util.createBuffer(),e={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878},a}};return a.start(),a.update=function(n,i){"utf8"===i&&(n=ue.util.encodeUtf8(n));var s=n.length;a.messageLength+=s,s=[s/4294967296>>>0,s>>>0];for(var o=a.fullMessageLength.length-1;o>=0;--o)a.fullMessageLength[o]+=s[1],s[1]=s[0]+(a.fullMessageLength[o]/4294967296>>>0),a.fullMessageLength[o]=a.fullMessageLength[o]>>>0,s[0]=s[1]/4294967296>>>0;return t.putBytes(n),ve(e,r,t),(t.read>2048||0===t.length())&&t.compact(),a},a.digest=function(){var n=ue.util.createBuffer();n.putBytes(t.bytes());var i=a.fullMessageLength[a.fullMessageLength.length-1]+a.messageLengthSize&a.blockLength-1;n.putBytes(de.substr(0,a.blockLength-i));for(var s,o=0,c=a.fullMessageLength.length-1;c>=0;--c)o=(s=8*a.fullMessageLength[c]+o)/4294967296>>>0,n.putInt32Le(s>>>0);var l={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3};ve(l,r,n);var u=ue.util.createBuffer();return u.putInt32Le(l.h0),u.putInt32Le(l.h1),u.putInt32Le(l.h2),u.putInt32Le(l.h3),u},a};var de=null,he=null,fe=null,ye=null,ge=!1;function ve(e,t,r){for(var a,n,i,s,o,c,l,u=r.length();u>=64;){for(n=e.h0,i=e.h1,s=e.h2,o=e.h3,l=0;l<16;++l)t[l]=r.getInt32Le(),a=n+(o^i&(s^o))+ye[l]+t[l],n=o,o=s,s=i,i+=a<<(c=fe[l])|a>>>32-c;for(;l<32;++l)a=n+(s^o&(i^s))+ye[l]+t[he[l]],n=o,o=s,s=i,i+=a<<(c=fe[l])|a>>>32-c;for(;l<48;++l)a=n+(i^s^o)+ye[l]+t[he[l]],n=o,o=s,s=i,i+=a<<(c=fe[l])|a>>>32-c;for(;l<64;++l)a=n+(s^(i|~o))+ye[l]+t[he[l]],n=o,o=s,s=i,i+=a<<(c=fe[l])|a>>>32-c;e.h0=e.h0+n|0,e.h1=e.h1+i|0,e.h2=e.h2+s|0,e.h3=e.h3+o|0,u-=64}}var me=f,Ce=me.pem=me.pem||{};function Ee(e){for(var t=e.name+": ",r=[],a=function(e,t){return" "+t},n=0;n<e.values.length;++n)r.push(e.values[n].replace(/^(\S+\r\n)/,a));t+=r.join(",")+"\r\n";var i=0,s=-1;for(n=0;n<t.length;++n,++i)if(i>65&&-1!==s){var o=t[s];","===o?(++s,t=t.substr(0,s)+"\r\n "+t.substr(s)):t=t.substr(0,s)+"\r\n"+o+t.substr(s+1),i=n-s-1,s=-1,++n}else" "!==t[n]&&"\t"!==t[n]&&","!==t[n]||(s=n);return t}function Se(e){return e.replace(/^\s+/,"")}Ce.encode=function(e,t){t=t||{};var r,a="-----BEGIN "+e.type+"-----\r\n";if(e.procType&&(a+=Ee(r={name:"Proc-Type",values:[String(e.procType.version),e.procType.type]})),e.contentDomain&&(a+=Ee(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+=Ee(r)),e.headers)for(var n=0;n<e.headers.length;++n)a+=Ee(e.headers[n]);return e.procType&&(a+="\r\n"),a+=me.util.encode64(e.body,t.maxline||64)+"\r\n",a+="-----END "+e.type+"-----\r\n"},Ce.decode=function(e){for(var t,r=[],a=/\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g,n=/([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/,i=/\r?\n/;t=a.exec(e);){var s=t[1];"NEW CERTIFICATE REQUEST"===s&&(s="CERTIFICATE REQUEST");var o={type:s,procType:null,contentDomain:null,dekInfo:null,headers:[],body:me.util.decode64(t[3])};if(r.push(o),t[2]){for(var c=t[2].split(i),l=0;t&&l<c.length;){for(var u=c[l].replace(/\s+$/,""),p=l+1;p<c.length;++p){var d=c[p];if(!/\s/.test(d[0]))break;u+=d,l=p}if(t=u.match(n)){for(var h={name:t[1],values:[]},f=t[2].split(","),y=0;y<f.length;++y)h.values.push(Se(f[y]));if(o.procType)if(o.contentDomain||"Content-Domain"!==h.name)if(o.dekInfo||"DEK-Info"!==h.name)o.headers.push(h);else{if(0===h.values.length)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must have at least one subfield.');o.dekInfo={algorithm:f[0],parameters:f[1]||null}}else o.contentDomain=f[0]||"";else{if("Proc-Type"!==h.name)throw new Error('Invalid PEM formatted message. The first encapsulated header must be "Proc-Type".');if(2!==h.values.length)throw new Error('Invalid PEM formatted message. The "Proc-Type" header must have two subfields.');o.procType={version:f[0],type:f[1]}}}++l}if("ENCRYPTED"===o.procType&&!o.dekInfo)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must be present if "Proc-Type" is "ENCRYPTED".')}}if(0===r.length)throw new Error("Invalid PEM formatted message.");return r};var be=f;function Te(e,t){be.cipher.registerAlgorithm(e,function(){return new be.des.Algorithm(e,t)})}be.des=be.des||{},be.des.startEncrypting=function(e,t,r,a){var n=_e({key:e,output:r,decrypt:!1,mode:a||(null===t?"ECB":"CBC")});return n.start(t),n},be.des.createEncryptionCipher=function(e,t){return _e({key:e,output:null,decrypt:!1,mode:t})},be.des.startDecrypting=function(e,t,r,a){var n=_e({key:e,output:r,decrypt:!0,mode:a||(null===t?"ECB":"CBC")});return n.start(t),n},be.des.createDecryptionCipher=function(e,t){return _e({key:e,output:null,decrypt:!0,mode:t})},be.des.Algorithm=function(e,t){var r=this;r.name=e,r.mode=new t({blockSize:8,cipher:{encrypt:function(e,t){return Le(r._keys,e,t,!1)},decrypt:function(e,t){return Le(r._keys,e,t,!0)}}}),r._init=!1},be.des.Algorithm.prototype.initialize=function(e){if(!this._init){var t=be.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,r=[0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964],a=[0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697],n=[0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272],i=[0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144],s=[0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256],o=[0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488],c=[0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746],l=[0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568],u=[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],h=[0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744],f=[0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128],y=[0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261],g=e.length()>8?3:1,v=[],m=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],C=0,E=0;E<g;E++){var S=e.getInt32(),b=e.getInt32();S^=(t=252645135&(S>>>4^b))<<4,S^=t=65535&((b^=t)>>>-16^S),S^=(t=858993459&(S>>>2^(b^=t<<-16)))<<2,S^=t=65535&((b^=t)>>>-16^S),S^=(t=1431655765&(S>>>1^(b^=t<<-16)))<<1,S^=t=16711935&((b^=t)>>>8^S),t=(S^=(t=1431655765&(S>>>1^(b^=t<<8)))<<1)<<8|(b^=t)>>>20&240,S=b<<24|b<<8&16711680|b>>>8&65280|b>>>24&240,b=t;for(var T=0;T<m.length;++T){m[T]?(S=S<<2|S>>>26,b=b<<2|b>>>26):(S=S<<1|S>>>27,b=b<<1|b>>>27),b&=-15;var I=r[(S&=-15)>>>28]|a[S>>>24&15]|n[S>>>20&15]|i[S>>>16&15]|s[S>>>12&15]|o[S>>>8&15]|c[S>>>4&15],A=l[b>>>28]|u[b>>>24&15]|p[b>>>20&15]|d[b>>>16&15]|h[b>>>12&15]|f[b>>>8&15]|y[b>>>4&15];t=65535&(A>>>16^I),v[C++]=I^t,v[C++]=A^t<<16}}return v}(t),this._init=!0}},Te("DES-ECB",be.cipher.modes.ecb),Te("DES-CBC",be.cipher.modes.cbc),Te("DES-CFB",be.cipher.modes.cfb),Te("DES-OFB",be.cipher.modes.ofb),Te("DES-CTR",be.cipher.modes.ctr),Te("3DES-ECB",be.cipher.modes.ecb),Te("3DES-CBC",be.cipher.modes.cbc),Te("3DES-CFB",be.cipher.modes.cfb),Te("3DES-OFB",be.cipher.modes.ofb),Te("3DES-CTR",be.cipher.modes.ctr);var Ie=[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],Ae=[-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],Be=[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],xe=[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],we=[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],Ne=[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],ke=[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],Re=[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 Le(e,t,r,a){var n,i,s=32===e.length?3:9;n=3===s?a?[30,-2,-2]:[0,32,2]:a?[94,62,-2,32,64,2,30,-2,-2]:[0,32,2,62,30,-2,64,96,2];var o=t[0],c=t[1];o^=(i=252645135&(o>>>4^c))<<4,o^=(i=65535&(o>>>16^(c^=i)))<<16,o^=i=858993459&((c^=i)>>>2^o),o^=i=16711935&((c^=i<<2)>>>8^o),o=(o^=(i=1431655765&(o>>>1^(c^=i<<8)))<<1)<<1|o>>>31,c=(c^=i)<<1|c>>>31;for(var l=0;l<s;l+=3){for(var u=n[l+1],p=n[l+2],d=n[l];d!=u;d+=p){var h=c^e[d],f=(c>>>4|c<<28)^e[d+1];i=o,o=c,c=i^(Ae[h>>>24&63]|xe[h>>>16&63]|Ne[h>>>8&63]|Re[63&h]|Ie[f>>>24&63]|Be[f>>>16&63]|we[f>>>8&63]|ke[63&f])}i=o,o=c,c=i}c=c>>>1|c<<31,c^=i=1431655765&((o=o>>>1|o<<31)>>>1^c),c^=(i=16711935&(c>>>8^(o^=i<<1)))<<8,c^=(i=858993459&(c>>>2^(o^=i)))<<2,c^=i=65535&((o^=i)>>>16^c),c^=i=252645135&((o^=i<<16)>>>4^c),o^=i<<4,r[0]=o,r[1]=c}function _e(e){var t,r="DES-"+((e=e||{}).mode||"CBC").toUpperCase(),a=(t=e.decrypt?be.cipher.createDecipher(r,e.key):be.cipher.createCipher(r,e.key)).start;return t.start=function(e,r){var n=null;r instanceof be.util.ByteBuffer&&(n=r,r={}),(r=r||{}).output=n,r.iv=e,a.call(t,r)},t}var De,Ue=f,Pe=Ue.pkcs5=Ue.pkcs5||{};Ue.util.isNodejs&&!Ue.options.usePureJavaScript&&(De=t),Ue.pbkdf2=Pe.pbkdf2=function(e,t,r,a,n,i){if("function"==typeof n&&(i=n,n=null),Ue.util.isNodejs&&!Ue.options.usePureJavaScript&&De.pbkdf2&&(null===n||"object"!=typeof n)&&(De.pbkdf2Sync.length>4||!n||"sha1"===n))return"string"!=typeof n&&(n="sha1"),e=Buffer.from(e,"binary"),t=Buffer.from(t,"binary"),i?4===De.pbkdf2Sync.length?De.pbkdf2(e,t,r,a,function(e,t){if(e)return i(e);i(null,t.toString("binary"))}):De.pbkdf2(e,t,r,a,n,function(e,t){if(e)return i(e);i(null,t.toString("binary"))}):4===De.pbkdf2Sync.length?De.pbkdf2Sync(e,t,r,a).toString("binary"):De.pbkdf2Sync(e,t,r,a,n).toString("binary");if(null==n&&(n="sha1"),"string"==typeof n){if(!(n in Ue.md.algorithms))throw new Error("Unknown hash algorithm: "+n);n=Ue.md[n].create()}var s=n.digestLength;if(a>4294967295*s){var o=new Error("Derived key is too long.");if(i)return i(o);throw o}var c=Math.ceil(a/s),l=a-(c-1)*s,u=Ue.hmac.create();u.start(n,e);var p,d,h,f="";if(!i){for(var y=1;y<=c;++y){u.start(null,null),u.update(t),u.update(Ue.util.int32ToBytes(y)),p=h=u.digest().getBytes();for(var g=2;g<=r;++g)u.start(null,null),u.update(h),d=u.digest().getBytes(),p=Ue.util.xorBytes(p,d,s),h=d;f+=y<c?p:p.substr(0,l)}return f}y=1;function v(){if(y>c)return i(null,f);u.start(null,null),u.update(t),u.update(Ue.util.int32ToBytes(y)),p=h=u.digest().getBytes(),g=2,m()}function m(){if(g<=r)return u.start(null,null),u.update(h),d=u.digest().getBytes(),p=Ue.util.xorBytes(p,d,s),h=d,++g,Ue.util.setImmediate(m);f+=y<c?p:p.substr(0,l),++y,v()}v()};var Ve=f,Oe=Ve.sha256=Ve.sha256||{};Ve.md.sha256=Ve.md.algorithms.sha256=Oe,Oe.create=function(){Me||(Ke=String.fromCharCode(128),Ke+=Ve.util.fillString(String.fromCharCode(0),64),Fe=[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],Me=!0);var e=null,t=Ve.util.createBuffer(),r=new Array(64),a={algorithm:"sha256",blockLength:64,digestLength:32,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){a.messageLength=0,a.fullMessageLength=a.messageLength64=[];for(var r=a.messageLengthSize/4,n=0;n<r;++n)a.fullMessageLength.push(0);return t=Ve.util.createBuffer(),e={h0:1779033703,h1:3144134277,h2:1013904242,h3:2773480762,h4:1359893119,h5:2600822924,h6:528734635,h7:1541459225},a}};return a.start(),a.update=function(n,i){"utf8"===i&&(n=Ve.util.encodeUtf8(n));var s=n.length;a.messageLength+=s,s=[s/4294967296>>>0,s>>>0];for(var o=a.fullMessageLength.length-1;o>=0;--o)a.fullMessageLength[o]+=s[1],s[1]=s[0]+(a.fullMessageLength[o]/4294967296>>>0),a.fullMessageLength[o]=a.fullMessageLength[o]>>>0,s[0]=s[1]/4294967296>>>0;return t.putBytes(n),qe(e,r,t),(t.read>2048||0===t.length())&&t.compact(),a},a.digest=function(){var n=Ve.util.createBuffer();n.putBytes(t.bytes());var i,s=a.fullMessageLength[a.fullMessageLength.length-1]+a.messageLengthSize&a.blockLength-1;n.putBytes(Ke.substr(0,a.blockLength-s));for(var o=8*a.fullMessageLength[0],c=0;c<a.fullMessageLength.length-1;++c)o+=(i=8*a.fullMessageLength[c+1])/4294967296>>>0,n.putInt32(o>>>0),o=i>>>0;n.putInt32(o);var l={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4,h5:e.h5,h6:e.h6,h7:e.h7};qe(l,r,n);var u=Ve.util.createBuffer();return u.putInt32(l.h0),u.putInt32(l.h1),u.putInt32(l.h2),u.putInt32(l.h3),u.putInt32(l.h4),u.putInt32(l.h5),u.putInt32(l.h6),u.putInt32(l.h7),u},a};var Ke=null,Me=!1,Fe=null;function qe(e,t,r){for(var a,n,i,s,o,c,l,u,p,d,h,f,y,g=r.length();g>=64;){for(o=0;o<16;++o)t[o]=r.getInt32();for(;o<64;++o)a=((a=t[o-2])>>>17|a<<15)^(a>>>19|a<<13)^a>>>10,n=((n=t[o-15])>>>7|n<<25)^(n>>>18|n<<14)^n>>>3,t[o]=a+t[o-7]+n+t[o-16]|0;for(c=e.h0,l=e.h1,u=e.h2,p=e.h3,d=e.h4,h=e.h5,f=e.h6,y=e.h7,o=0;o<64;++o)i=(c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),s=c&l|u&(c^l),a=y+((d>>>6|d<<26)^(d>>>11|d<<21)^(d>>>25|d<<7))+(f^d&(h^f))+Fe[o]+t[o],y=f,f=h,h=d,d=p+a>>>0,p=u,u=l,l=c,c=a+(n=i+s)>>>0;e.h0=e.h0+c|0,e.h1=e.h1+l|0,e.h2=e.h2+u|0,e.h3=e.h3+p|0,e.h4=e.h4+d|0,e.h5=e.h5+h|0,e.h6=e.h6+f|0,e.h7=e.h7+y|0,g-=64}}var je=f,He=null;!je.util.isNodejs||je.options.usePureJavaScript||process.versions["node-webkit"]||(He=t),(je.prng=je.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),n=0;n<32;++n)a[n]=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 r=1,a=0;a<32;++a)t.reseeds%r===0&&(e.update(t.pools[a].digest().getBytes()),t.pools[a].start()),r<<=1;t.keyBytes=e.digest().getBytes(),e.start(),e.update(t.keyBytes);var n=e.digest().getBytes();t.key=t.plugin.formatKey(t.keyBytes),t.seed=t.plugin.formatSeed(n),t.generated=0}function o(e){var t=null,r=je.util.globalScope,a=r.crypto||r.msCrypto;a&&a.getRandomValues&&(t=function(e){return a.getRandomValues(e)});var n=je.util.createBuffer();if(t)for(;n.length()<e;){var i=Math.max(1,Math.min(e-n.length(),65536)/4),s=new Uint32Array(Math.floor(i));try{t(s);for(var o=0;o<s.length;++o)n.putInt32(s[o])}catch(e){if(!("undefined"!=typeof QuotaExceededError&&e instanceof QuotaExceededError))throw e}}if(n.length()<e)for(var c,l,u,p=Math.floor(65536*Math.random());n.length()<e;){l=16807*(65535&p),l+=(32767&(c=16807*(p>>16)))<<16,p=4294967295&(l=(2147483647&(l+=c>>15))+(l>>31));for(o=0;o<3;++o)u=p>>>(o<<3),u^=Math.floor(256*Math.random()),n.putByte(255&u)}return n.getBytes(e)}return t.pools=a,t.pool=0,t.generate=function(e,r){if(!r)return t.generateSync(e);var a=t.plugin.cipher,n=t.plugin.increment,i=t.plugin.formatKey,o=t.plugin.formatSeed,c=je.util.createBuffer();t.key=null,function l(u){if(u)return r(u);if(c.length()>=e)return r(null,c.getBytes(e));t.generated>1048575&&(t.key=null);if(null===t.key)return je.util.nextTick(function(){!function(e){if(t.pools[0].messageLength>=32)return s(),e();var r=32-t.pools[0].messageLength<<5;t.seedFile(r,function(r,a){if(r)return e(r);t.collect(a),s(),e()})}(l)});var p=a(t.key,t.seed);t.generated+=p.length,c.putBytes(p),t.key=i(a(t.key,n(t.seed))),t.seed=o(a(t.key,t.seed)),je.util.setImmediate(l)}()},t.generateSync=function(e){var r=t.plugin.cipher,a=t.plugin.increment,n=t.plugin.formatKey,s=t.plugin.formatSeed;t.key=null;for(var o=je.util.createBuffer();o.length()<e;){t.generated>1048575&&(t.key=null),null===t.key&&i();var c=r(t.key,t.seed);t.generated+=c.length,o.putBytes(c),t.key=n(r(t.key,a(t.seed))),t.seed=s(r(t.key,t.seed))}return o.getBytes(e)},He?(t.seedFile=function(e,t){He.randomBytes(e,function(e,r){if(e)return t(e);t(null,r.toString())})},t.seedFileSync=function(e){return He.randomBytes(e).toString()}):(t.seedFile=function(e,t){try{t(null,o(e))}catch(e){t(e)}},t.seedFileSync=o),t.collect=function(e){for(var r=e.length,a=0;a<r;++a)t.pools[t.pool].update(e.substr(a,1)),t.pool=31===t.pool?0:t.pool+1},t.collectInt=function(e,r){for(var a="",n=0;n<r;n+=8)a+=String.fromCharCode(e>>n&255);t.collect(a)},t.registerWorker=function(e){if(e===self)t.seedFile=function(e,t){self.addEventListener("message",function e(r){var a=r.data;a.forge&&a.forge.prng&&(self.removeEventListener("message",e),t(a.forge.prng.err,a.forge.prng.bytes))}),self.postMessage({forge:{prng:{needed:e}}})};else{e.addEventListener("message",function(r){var a=r.data;a.forge&&a.forge.prng&&t.seedFile(a.forge.prng.needed,function(t,r){e.postMessage({forge:{prng:{err:t,bytes:r}}})})})}},t};var Ge=f;Ge.random&&Ge.random.getBytes?Ge.random:function(e){var t={},r=new Array(4),a=Ge.util.createBuffer();function n(){var e=Ge.prng.create(t);return e.getBytes=function(t,r){return e.generate(t,r)},e.getBytesSync=function(t){return e.generate(t)},e}t.formatKey=function(e){var t=Ge.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),Ge.aes._expandKey(e,!1)},t.formatSeed=function(e){var t=Ge.util.createBuffer(e);return(e=new Array(4))[0]=t.getInt32(),e[1]=t.getInt32(),e[2]=t.getInt32(),e[3]=t.getInt32(),e},t.cipher=function(e,t){return Ge.aes._updateBlock(e,t,r,!1),a.putInt32(r[0]),a.putInt32(r[1]),a.putInt32(r[2]),a.putInt32(r[3]),a.getBytes()},t.increment=function(e){return++e[3],e},t.md=Ge.md.sha256;var i=n(),s=null,o=Ge.util.globalScope,c=o.crypto||o.msCrypto;if(c&&c.getRandomValues&&(s=function(e){return c.getRandomValues(e)}),Ge.options.usePureJavaScript||!Ge.util.isNodejs&&!s){if(i.collectInt(+new Date,32),"undefined"!=typeof navigator){var l="";for(var u in navigator)try{"string"==typeof navigator[u]&&(l+=navigator[u])}catch(e){}i.collect(l),l=null}e&&(e().mousemove(function(e){i.collectInt(e.clientX,16),i.collectInt(e.clientY,16)}),e().keypress(function(e){i.collectInt(e.charCode,8)}))}if(Ge.random)for(var u in i)Ge.random[u]=i[u];else Ge.random=i;Ge.random.createInstance=n,Ge.random}("undefined"!=typeof jQuery?jQuery:null);var ze=f,Qe=[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],Xe=function(e,t){return e<<t&65535|(65535&e)>>16-t},We=function(e,t){return(65535&e)>>t|e<<16-t&65535};ze.rc2=ze.rc2||{},ze.rc2.expandKey=function(e,t){"string"==typeof e&&(e=ze.util.createBuffer(e)),t=t||128;var r,a=e,n=e.length(),i=t,s=Math.ceil(i/8),o=255>>(7&i);for(r=n;r<128;r++)a.putByte(Qe[a.at(r-1)+a.at(r-n)&255]);for(a.setAt(128-s,Qe[a.at(128-s)&o]),r=127-s;r>=0;r--)a.setAt(r,Qe[a.at(r+1)^a.at(r+s)]);return a};var $e=function(e,t,r){var a,n,i,s,o=!1,c=null,l=null,u=null,p=[];for(e=ze.rc2.expandKey(e,t),i=0;i<64;i++)p.push(e.getInt16Le());r?(a=function(e){for(i=0;i<4;i++)e[i]+=p[s]+(e[(i+3)%4]&e[(i+2)%4])+(~e[(i+3)%4]&e[(i+1)%4]),e[i]=Xe(e[i],Ye[i]),s++},n=function(e){for(i=0;i<4;i++)e[i]+=p[63&e[(i+3)%4]]}):(a=function(e){for(i=3;i>=0;i--)e[i]=We(e[i],Ye[i]),e[i]-=p[s]+(e[(i+3)%4]&e[(i+2)%4])+(~e[(i+3)%4]&e[(i+1)%4]),s--},n=function(e){for(i=3;i>=0;i--)e[i]-=p[63&e[(i+3)%4]]});var d=function(e){var t=[];for(i=0;i<4;i++){var a=c.getInt16Le();null!==u&&(r?a^=u.getInt16Le():u.putInt16Le(a)),t.push(65535&a)}s=r?0:63;for(var n=0;n<e.length;n++)for(var o=0;o<e[n][0];o++)e[n][1](t);for(i=0;i<4;i++)null!==u&&(r?u.putInt16Le(t[i]):t[i]^=u.getInt16Le()),l.putInt16Le(t[i])},h=null;return h={start:function(e,t){e&&"string"==typeof e&&(e=ze.util.createBuffer(e)),o=!1,c=ze.util.createBuffer(),l=t||new ze.util.createBuffer,u=e,h.output=l},update:function(e){for(o||c.putBuffer(e);c.length()>=8;)d([[5,a],[1,n],[6,a],[1,n],[5,a]])},finish:function(e){var t=!0;if(r)if(e)t=e(8,c,!r);else{var a=8===c.length()?8:8-c.length();c.fillWithByte(a,a)}if(t&&(o=!0,h.update()),!r&&(t=0===c.length()))if(e)t=e(8,l,!r);else{var n=l.length(),i=l.at(n-1);i>n?t=!1:l.truncate(i)}return t}}};ze.rc2.startEncrypting=function(e,t,r){var a=ze.rc2.createEncryptionCipher(e,128);return a.start(t,r),a},ze.rc2.createEncryptionCipher=function(e,t){return $e(e,t,!0)},ze.rc2.startDecrypting=function(e,t,r){var a=ze.rc2.createDecryptionCipher(e,128);return a.start(t,r),a},ze.rc2.createDecryptionCipher=function(e,t){return $e(e,t,!1)};var Ze,Je=f;function et(e,t,r){this.data=[],null!=e&&("number"==typeof e?this.fromNumber(e,t,r):null==t&&"string"!=typeof e?this.fromString(e,256):this.fromString(e,t))}function tt(){return new et(null)}function rt(e,t,r,a,n,i){for(var s=16383&t,o=t>>14;--i>=0;){var c=16383&this.data[e],l=this.data[e++]>>14,u=o*c+l*s;n=((c=s*c+((16383&u)<<14)+r.data[a]+n)>>28)+(u>>14)+o*l,r.data[a++]=268435455&c}return n}Je.jsbn=Je.jsbn||{},Je.jsbn.BigInteger=et,"undefined"==typeof navigator?(et.prototype.am=rt,Ze=28):"Microsoft Internet Explorer"==navigator.appName?(et.prototype.am=function(e,t,r,a,n,i){for(var s=32767&t,o=t>>15;--i>=0;){var c=32767&this.data[e],l=this.data[e++]>>15,u=o*c+l*s;n=((c=s*c+((32767&u)<<15)+r.data[a]+(1073741823&n))>>>30)+(u>>>15)+o*l+(n>>>30),r.data[a++]=1073741823&c}return n},Ze=30):"Netscape"!=navigator.appName?(et.prototype.am=function(e,t,r,a,n,i){for(;--i>=0;){var s=t*this.data[e++]+r.data[a]+n;n=Math.floor(s/67108864),r.data[a++]=67108863&s}return n},Ze=26):(et.prototype.am=rt,Ze=28),et.prototype.DB=Ze,et.prototype.DM=(1<<Ze)-1,et.prototype.DV=1<<Ze;et.prototype.FV=Math.pow(2,52),et.prototype.F1=52-Ze,et.prototype.F2=2*Ze-52;var at,nt,it=new Array;for(at="0".charCodeAt(0),nt=0;nt<=9;++nt)it[at++]=nt;for(at="a".charCodeAt(0),nt=10;nt<36;++nt)it[at++]=nt;for(at="A".charCodeAt(0),nt=10;nt<36;++nt)it[at++]=nt;function st(e){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(e)}function ot(e,t){var r=it[e.charCodeAt(t)];return null==r?-1:r}function ct(e){var t=tt();return t.fromInt(e),t}function lt(e){var t,r=1;return 0!=(t=e>>>16)&&(e=t,r+=16),0!=(t=e>>8)&&(e=t,r+=8),0!=(t=e>>4)&&(e=t,r+=4),0!=(t=e>>2)&&(e=t,r+=2),0!=(t=e>>1)&&(e=t,r+=1),r}function ut(e){this.m=e}function pt(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 dt(e,t){return e&t}function ht(e,t){return e|t}function ft(e,t){return e^t}function yt(e,t){return e&~t}function gt(e){if(0==e)return-1;var t=0;return 65535&e||(e>>=16,t+=16),255&e||(e>>=8,t+=8),15&e||(e>>=4,t+=4),3&e||(e>>=2,t+=2),1&e||++t,t}function vt(e){for(var t=0;0!=e;)e&=e-1,++t;return t}function mt(){}function Ct(e){return e}function Et(e){this.r2=tt(),this.q3=tt(),et.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}ut.prototype.convert=function(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e},ut.prototype.revert=function(e){return e},ut.prototype.reduce=function(e){e.divRemTo(this.m,null,e)},ut.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r),this.reduce(r)},ut.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},pt.prototype.convert=function(e){var t=tt();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(et.ZERO)>0&&this.m.subTo(t,t),t},pt.prototype.revert=function(e){var t=tt();return e.copyTo(t),this.reduce(t),t},pt.prototype.reduce=function(e){for(;e.t<=this.mt2;)e.data[e.t++]=0;for(var t=0;t<this.m.t;++t){var r=32767&e.data[t],a=r*this.mpl+((r*this.mph+(e.data[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(r=t+this.m.t,e.data[r]+=this.m.am(0,a,e,t,0,this.m.t);e.data[r]>=e.DV;)e.data[r]-=e.DV,e.data[++r]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},pt.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r),this.reduce(r)},pt.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},et.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},et.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},et.prototype.fromString=function(e,t){var r;if(16==t)r=4;else if(8==t)r=3;else if(256==t)r=8;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)return void this.fromRadix(e,t);r=2}this.t=0,this.s=0;for(var a=e.length,n=!1,i=0;--a>=0;){var s=8==r?255&e[a]:ot(e,a);s<0?"-"==e.charAt(a)&&(n=!0):(n=!1,0==i?this.data[this.t++]=s:i+r>this.DB?(this.data[this.t-1]|=(s&(1<<this.DB-i)-1)<<i,this.data[this.t++]=s>>this.DB-i):this.data[this.t-1]|=s<<i,(i+=r)>=this.DB&&(i-=this.DB))}8==r&&128&e[0]&&(this.s=-1,i>0&&(this.data[this.t-1]|=(1<<this.DB-i)-1<<i)),this.clamp(),n&&et.ZERO.subTo(this,this)},et.prototype.clamp=function(){for(var e=this.s&this.DM;this.t>0&&this.data[this.t-1]==e;)--this.t},et.prototype.dlShiftTo=function(e,t){var r;for(r=this.t-1;r>=0;--r)t.data[r+e]=this.data[r];for(r=e-1;r>=0;--r)t.data[r]=0;t.t=this.t+e,t.s=this.s},et.prototype.drShiftTo=function(e,t){for(var r=e;r<this.t;++r)t.data[r-e]=this.data[r];t.t=Math.max(this.t-e,0),t.s=this.s},et.prototype.lShiftTo=function(e,t){var r,a=e%this.DB,n=this.DB-a,i=(1<<n)-1,s=Math.floor(e/this.DB),o=this.s<<a&this.DM;for(r=this.t-1;r>=0;--r)t.data[r+s+1]=this.data[r]>>n|o,o=(this.data[r]&i)<<a;for(r=s-1;r>=0;--r)t.data[r]=0;t.data[s]=o,t.t=this.t+s+1,t.s=this.s,t.clamp()},et.prototype.rShiftTo=function(e,t){t.s=this.s;var r=Math.floor(e/this.DB);if(r>=this.t)t.t=0;else{var a=e%this.DB,n=this.DB-a,i=(1<<a)-1;t.data[0]=this.data[r]>>a;for(var s=r+1;s<this.t;++s)t.data[s-r-1]|=(this.data[s]&i)<<n,t.data[s-r]=this.data[s]>>a;a>0&&(t.data[this.t-r-1]|=(this.s&i)<<n),t.t=this.t-r,t.clamp()}},et.prototype.subTo=function(e,t){for(var r=0,a=0,n=Math.min(e.t,this.t);r<n;)a+=this.data[r]-e.data[r],t.data[r++]=a&this.DM,a>>=this.DB;if(e.t<this.t){for(a-=e.s;r<this.t;)a+=this.data[r],t.data[r++]=a&this.DM,a>>=this.DB;a+=this.s}else{for(a+=this.s;r<e.t;)a-=e.data[r],t.data[r++]=a&this.DM,a>>=this.DB;a-=e.s}t.s=a<0?-1:0,a<-1?t.data[r++]=this.DV+a:a>0&&(t.data[r++]=a),t.t=r,t.clamp()},et.prototype.multiplyTo=function(e,t){var r=this.abs(),a=e.abs(),n=r.t;for(t.t=n+a.t;--n>=0;)t.data[n]=0;for(n=0;n<a.t;++n)t.data[n+r.t]=r.am(0,a.data[n],t,n,0,r.t);t.s=0,t.clamp(),this.s!=e.s&&et.ZERO.subTo(t,t)},et.prototype.squareTo=function(e){for(var t=this.abs(),r=e.t=2*t.t;--r>=0;)e.data[r]=0;for(r=0;r<t.t-1;++r){var a=t.am(r,t.data[r],e,2*r,0,1);(e.data[r+t.t]+=t.am(r+1,2*t.data[r],e,2*r+1,a,t.t-r-1))>=t.DV&&(e.data[r+t.t]-=t.DV,e.data[r+t.t+1]=1)}e.t>0&&(e.data[e.t-1]+=t.am(r,t.data[r],e,2*r,0,1)),e.s=0,e.clamp()},et.prototype.divRemTo=function(e,t,r){var a=e.abs();if(!(a.t<=0)){var n=this.abs();if(n.t<a.t)return null!=t&&t.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=tt());var i=tt(),s=this.s,o=e.s,c=this.DB-lt(a.data[a.t-1]);c>0?(a.lShiftTo(c,i),n.lShiftTo(c,r)):(a.copyTo(i),n.copyTo(r));var l=i.t,u=i.data[l-1];if(0!=u){var p=u*(1<<this.F1)+(l>1?i.data[l-2]>>this.F2:0),d=this.FV/p,h=(1<<this.F1)/p,f=1<<this.F2,y=r.t,g=y-l,v=null==t?tt():t;for(i.dlShiftTo(g,v),r.compareTo(v)>=0&&(r.data[r.t++]=1,r.subTo(v,r)),et.ONE.dlShiftTo(l,v),v.subTo(i,i);i.t<l;)i.data[i.t++]=0;for(;--g>=0;){var m=r.data[--y]==u?this.DM:Math.floor(r.data[y]*d+(r.data[y-1]+f)*h);if((r.data[y]+=i.am(0,m,r,g,0,l))<m)for(i.dlShiftTo(g,v),r.subTo(v,r);r.data[y]<--m;)r.subTo(v,r)}null!=t&&(r.drShiftTo(l,t),s!=o&&et.ZERO.subTo(t,t)),r.t=l,r.clamp(),c>0&&r.rShiftTo(c,r),s<0&&et.ZERO.subTo(r,r)}}},et.prototype.invDigit=function(){if(this.t<1)return 0;var e=this.data[0];if(!(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},et.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},et.prototype.exp=function(e,t){if(e>4294967295||e<1)return et.ONE;var r=tt(),a=tt(),n=t.convert(this),i=lt(e)-1;for(n.copyTo(r);--i>=0;)if(t.sqrTo(r,a),(e&1<<i)>0)t.mulTo(a,n,r);else{var s=r;r=a,a=s}return t.revert(r)},et.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 r,a=(1<<t)-1,n=!1,i="",s=this.t,o=this.DB-s*this.DB%t;if(s-- >0)for(o<this.DB&&(r=this.data[s]>>o)>0&&(n=!0,i=st(r));s>=0;)o<t?(r=(this.data[s]&(1<<o)-1)<<t-o,r|=this.data[--s]>>(o+=this.DB-t)):(r=this.data[s]>>(o-=t)&a,o<=0&&(o+=this.DB,--s)),r>0&&(n=!0),n&&(i+=st(r));return n?i:"0"},et.prototype.negate=function(){var e=tt();return et.ZERO.subTo(this,e),e},et.prototype.abs=function(){return this.s<0?this.negate():this},et.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var r=this.t;if(0!=(t=r-e.t))return this.s<0?-t:t;for(;--r>=0;)if(0!=(t=this.data[r]-e.data[r]))return t;return 0},et.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+lt(this.data[this.t-1]^this.s&this.DM)},et.prototype.mod=function(e){var t=tt();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(et.ZERO)>0&&e.subTo(t,t),t},et.prototype.modPowInt=function(e,t){var r;return r=e<256||t.isEven()?new ut(t):new pt(t),this.exp(e,r)},et.ZERO=ct(0),et.ONE=ct(1),mt.prototype.convert=Ct,mt.prototype.revert=Ct,mt.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r)},mt.prototype.sqrTo=function(e,t){e.squareTo(t)},Et.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=tt();return e.copyTo(t),this.reduce(t),t},Et.prototype.revert=function(e){return e},Et.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)},Et.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r),this.reduce(r)},Et.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)};var St=[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],bt=(1<<26)/St[St.length-1];et.prototype.chunkSize=function(e){return Math.floor(Math.LN2*this.DB/Math.log(e))},et.prototype.toRadix=function(e){if(null==e&&(e=10),0==this.signum()||e<2||e>36)return"0";var t=this.chunkSize(e),r=Math.pow(e,t),a=ct(r),n=tt(),i=tt(),s="";for(this.divRemTo(a,n,i);n.signum()>0;)s=(r+i.intValue()).toString(e).substr(1)+s,n.divRemTo(a,n,i);return i.intValue().toString(e)+s},et.prototype.fromRadix=function(e,t){this.fromInt(0),null==t&&(t=10);for(var r=this.chunkSize(t),a=Math.pow(t,r),n=!1,i=0,s=0,o=0;o<e.length;++o){var c=ot(e,o);c<0?"-"==e.charAt(o)&&0==this.signum()&&(n=!0):(s=t*s+c,++i>=r&&(this.dMultiply(a),this.dAddOffset(s,0),i=0,s=0))}i>0&&(this.dMultiply(Math.pow(t,i)),this.dAddOffset(s,0)),n&&et.ZERO.subTo(this,this)},et.prototype.fromNumber=function(e,t,r){if("number"==typeof t)if(e<2)this.fromInt(1);else for(this.fromNumber(e,r),this.testBit(e-1)||this.bitwiseTo(et.ONE.shiftLeft(e-1),ht,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(et.ONE.shiftLeft(e-1),this);else{var a=new Array,n=7&e;a.length=1+(e>>3),t.nextBytes(a),n>0?a[0]&=(1<<n)-1:a[0]=0,this.fromString(a,256)}},et.prototype.bitwiseTo=function(e,t,r){var a,n,i=Math.min(e.t,this.t);for(a=0;a<i;++a)r.data[a]=t(this.data[a],e.data[a]);if(e.t<this.t){for(n=e.s&this.DM,a=i;a<this.t;++a)r.data[a]=t(this.data[a],n);r.t=this.t}else{for(n=this.s&this.DM,a=i;a<e.t;++a)r.data[a]=t(n,e.data[a]);r.t=e.t}r.s=t(this.s,e.s),r.clamp()},et.prototype.changeBit=function(e,t){var r=et.ONE.shiftLeft(e);return this.bitwiseTo(r,t,r),r},et.prototype.addTo=function(e,t){for(var r=0,a=0,n=Math.min(e.t,this.t);r<n;)a+=this.data[r]+e.data[r],t.data[r++]=a&this.DM,a>>=this.DB;if(e.t<this.t){for(a+=e.s;r<this.t;)a+=this.data[r],t.data[r++]=a&this.DM,a>>=this.DB;a+=this.s}else{for(a+=this.s;r<e.t;)a+=e.data[r],t.data[r++]=a&this.DM,a>>=this.DB;a+=e.s}t.s=a<0?-1:0,a>0?t.data[r++]=a:a<-1&&(t.data[r++]=this.DV+a),t.t=r,t.clamp()},et.prototype.dMultiply=function(e){this.data[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()},et.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]}},et.prototype.multiplyLowerTo=function(e,t,r){var a,n=Math.min(this.t+e.t,t);for(r.s=0,r.t=n;n>0;)r.data[--n]=0;for(a=r.t-this.t;n<a;++n)r.data[n+this.t]=this.am(0,e.data[n],r,n,0,this.t);for(a=Math.min(e.t,t);n<a;++n)this.am(0,e.data[n],r,n,0,t-n);r.clamp()},et.prototype.multiplyUpperTo=function(e,t,r){--t;var a=r.t=this.t+e.t-t;for(r.s=0;--a>=0;)r.data[a]=0;for(a=Math.max(t-this.t,0);a<e.t;++a)r.data[this.t+a-t]=this.am(t-a,e.data[a],r,0,0,this.t+a-t);r.clamp(),r.drShiftTo(1,r)},et.prototype.modInt=function(e){if(e<=0)return 0;var t=this.DV%e,r=this.s<0?e-1:0;if(this.t>0)if(0==t)r=this.data[0]%e;else for(var a=this.t-1;a>=0;--a)r=(t*r+this.data[a])%e;return r},et.prototype.millerRabin=function(e){var t=this.subtract(et.ONE),r=t.getLowestSetBit();if(r<=0)return!1;for(var a,n=t.shiftRight(r),i={nextBytes:function(e){for(var t=0;t<e.length;++t)e[t]=Math.floor(256*Math.random())}},s=0;s<e;++s){do{a=new et(this.bitLength(),i)}while(a.compareTo(et.ONE)<=0||a.compareTo(t)>=0);var o=a.modPow(n,this);if(0!=o.compareTo(et.ONE)&&0!=o.compareTo(t)){for(var c=1;c++<r&&0!=o.compareTo(t);)if(0==(o=o.modPowInt(2,this)).compareTo(et.ONE))return!1;if(0!=o.compareTo(t))return!1}}return!0},et.prototype.clone=function(){var e=tt();return this.copyTo(e),e},et.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]},et.prototype.byteValue=function(){return 0==this.t?this.s:this.data[0]<<24>>24},et.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},et.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},et.prototype.toByteArray=function(){var e=this.t,t=new Array;t[0]=this.s;var r,a=this.DB-e*this.DB%8,n=0;if(e-- >0)for(a<this.DB&&(r=this.data[e]>>a)!=(this.s&this.DM)>>a&&(t[n++]=r|this.s<<this.DB-a);e>=0;)a<8?(r=(this.data[e]&(1<<a)-1)<<8-a,r|=this.data[--e]>>(a+=this.DB-8)):(r=this.data[e]>>(a-=8)&255,a<=0&&(a+=this.DB,--e)),128&r&&(r|=-256),0==n&&(128&this.s)!=(128&r)&&++n,(n>0||r!=this.s)&&(t[n++]=r);return t},et.prototype.equals=function(e){return 0==this.compareTo(e)},et.prototype.min=function(e){return this.compareTo(e)<0?this:e},et.prototype.max=function(e){return this.compareTo(e)>0?this:e},et.prototype.and=function(e){var t=tt();return this.bitwiseTo(e,dt,t),t},et.prototype.or=function(e){var t=tt();return this.bitwiseTo(e,ht,t),t},et.prototype.xor=function(e){var t=tt();return this.bitwiseTo(e,ft,t),t},et.prototype.andNot=function(e){var t=tt();return this.bitwiseTo(e,yt,t),t},et.prototype.not=function(){for(var e=tt(),t=0;t<this.t;++t)e.data[t]=this.DM&~this.data[t];return e.t=this.t,e.s=~this.s,e},et.prototype.shiftLeft=function(e){var t=tt();return e<0?this.rShiftTo(-e,t):this.lShiftTo(e,t),t},et.prototype.shiftRight=function(e){var t=tt();return e<0?this.lShiftTo(-e,t):this.rShiftTo(e,t),t},et.prototype.getLowestSetBit=function(){for(var e=0;e<this.t;++e)if(0!=this.data[e])return e*this.DB+gt(this.data[e]);return this.s<0?this.t*this.DB:-1},et.prototype.bitCount=function(){for(var e=0,t=this.s&this.DM,r=0;r<this.t;++r)e+=vt(this.data[r]^t);return e},et.prototype.testBit=function(e){var t=Math.floor(e/this.DB);return t>=this.t?0!=this.s:!!(this.data[t]&1<<e%this.DB)},et.prototype.setBit=function(e){return this.changeBit(e,ht)},et.prototype.clearBit=function(e){return this.changeBit(e,yt)},et.prototype.flipBit=function(e){return this.changeBit(e,ft)},et.prototype.add=function(e){var t=tt();return this.addTo(e,t),t},et.prototype.subtract=function(e){var t=tt();return this.subTo(e,t),t},et.prototype.multiply=function(e){var t=tt();return this.multiplyTo(e,t),t},et.prototype.divide=function(e){var t=tt();return this.divRemTo(e,t,null),t},et.prototype.remainder=function(e){var t=tt();return this.divRemTo(e,null,t),t},et.prototype.divideAndRemainder=function(e){var t=tt(),r=tt();return this.divRemTo(e,t,r),new Array(t,r)},et.prototype.modPow=function(e,t){var r,a,n=e.bitLength(),i=ct(1);if(n<=0)return i;r=n<18?1:n<48?3:n<144?4:n<768?5:6,a=n<8?new ut(t):t.isEven()?new Et(t):new pt(t);var s=new Array,o=3,c=r-1,l=(1<<r)-1;if(s[1]=a.convert(this),r>1){var u=tt();for(a.sqrTo(s[1],u);o<=l;)s[o]=tt(),a.mulTo(u,s[o-2],s[o]),o+=2}var p,d,h=e.t-1,f=!0,y=tt();for(n=lt(e.data[h])-1;h>=0;){for(n>=c?p=e.data[h]>>n-c&l:(p=(e.data[h]&(1<<n+1)-1)<<c-n,h>0&&(p|=e.data[h-1]>>this.DB+n-c)),o=r;!(1&p);)p>>=1,--o;if((n-=o)<0&&(n+=this.DB,--h),f)s[p].copyTo(i),f=!1;else{for(;o>1;)a.sqrTo(i,y),a.sqrTo(y,i),o-=2;o>0?a.sqrTo(i,y):(d=i,i=y,y=d),a.mulTo(y,s[p],i)}for(;h>=0&&!(e.data[h]&1<<n);)a.sqrTo(i,y),d=i,i=y,y=d,--n<0&&(n=this.DB-1,--h)}return a.revert(i)},et.prototype.modInverse=function(e){var t=e.isEven();if(this.isEven()&&t||0==e.signum())return et.ZERO;for(var r=e.clone(),a=this.clone(),n=ct(1),i=ct(0),s=ct(0),o=ct(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),t?(n.isEven()&&i.isEven()||(n.addTo(this,n),i.subTo(e,i)),n.rShiftTo(1,n)):i.isEven()||i.subTo(e,i),i.rShiftTo(1,i);for(;a.isEven();)a.rShiftTo(1,a),t?(s.isEven()&&o.isEven()||(s.addTo(this,s),o.subTo(e,o)),s.rShiftTo(1,s)):o.isEven()||o.subTo(e,o),o.rShiftTo(1,o);r.compareTo(a)>=0?(r.subTo(a,r),t&&n.subTo(s,n),i.subTo(o,i)):(a.subTo(r,a),t&&s.subTo(n,s),o.subTo(i,o))}return 0!=a.compareTo(et.ONE)?et.ZERO:o.compareTo(e)>=0?o.subtract(e):o.signum()<0?(o.addTo(e,o),o.signum()<0?o.add(e):o):o},et.prototype.pow=function(e){return this.exp(e,new mt)},et.prototype.gcd=function(e){var t=this.s<0?this.negate():this.clone(),r=e.s<0?e.negate():e.clone();if(t.compareTo(r)<0){var a=t;t=r,r=a}var n=t.getLowestSetBit(),i=r.getLowestSetBit();if(i<0)return t;for(n<i&&(i=n),i>0&&(t.rShiftTo(i,t),r.rShiftTo(i,r));t.signum()>0;)(n=t.getLowestSetBit())>0&&t.rShiftTo(n,t),(n=r.getLowestSetBit())>0&&r.rShiftTo(n,r),t.compareTo(r)>=0?(t.subTo(r,t),t.rShiftTo(1,t)):(r.subTo(t,r),r.rShiftTo(1,r));return i>0&&r.lShiftTo(i,r),r},et.prototype.isProbablePrime=function(e){var t,r=this.abs();if(1==r.t&&r.data[0]<=St[St.length-1]){for(t=0;t<St.length;++t)if(r.data[0]==St[t])return!0;return!1}if(r.isEven())return!1;for(t=1;t<St.length;){for(var a=St[t],n=t+1;n<St.length&&a<bt;)a*=St[n++];for(a=r.modInt(a);t<n;)if(a%St[t++]==0)return!1}return r.millerRabin(e)};var Tt=f,It=Tt.sha1=Tt.sha1||{};Tt.md.sha1=Tt.md.algorithms.sha1=It,It.create=function(){Bt||(At=String.fromCharCode(128),At+=Tt.util.fillString(String.fromCharCode(0),64),Bt=!0);var e=null,t=Tt.util.createBuffer(),r=new Array(80),a={algorithm:"sha1",blockLength:64,digestLength:20,messageLength:0,fullMessageLength:null,messageLengthSize:8,start:function(){a.messageLength=0,a.fullMessageLength=a.messageLength64=[];for(var r=a.messageLengthSize/4,n=0;n<r;++n)a.fullMessageLength.push(0);return t=Tt.util.createBuffer(),e={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878,h4:3285377520},a}};return a.start(),a.update=function(n,i){"utf8"===i&&(n=Tt.util.encodeUtf8(n));var s=n.length;a.messageLength+=s,s=[s/4294967296>>>0,s>>>0];for(var o=a.fullMessageLength.length-1;o>=0;--o)a.fullMessageLength[o]+=s[1],s[1]=s[0]+(a.fullMessageLength[o]/4294967296>>>0),a.fullMessageLength[o]=a.fullMessageLength[o]>>>0,s[0]=s[1]/4294967296>>>0;return t.putBytes(n),xt(e,r,t),(t.read>2048||0===t.length())&&t.compact(),a},a.digest=function(){var n=Tt.util.createBuffer();n.putBytes(t.bytes());var i,s=a.fullMessageLength[a.fullMessageLength.length-1]+a.messageLengthSize&a.blockLength-1;n.putBytes(At.substr(0,a.blockLength-s));for(var o=8*a.fullMessageLength[0],c=0;c<a.fullMessageLength.length-1;++c)o+=(i=8*a.fullMessageLength[c+1])/4294967296>>>0,n.putInt32(o>>>0),o=i>>>0;n.putInt32(o);var l={h0:e.h0,h1:e.h1,h2:e.h2,h3:e.h3,h4:e.h4};xt(l,r,n);var u=Tt.util.createBuffer();return u.putInt32(l.h0),u.putInt32(l.h1),u.putInt32(l.h2),u.putInt32(l.h3),u.putInt32(l.h4),u},a};var At=null,Bt=!1;function xt(e,t,r){for(var a,n,i,s,o,c,l,u=r.length();u>=64;){for(n=e.h0,i=e.h1,s=e.h2,o=e.h3,c=e.h4,l=0;l<16;++l)a=r.getInt32(),t[l]=a,a=(n<<5|n>>>27)+(o^i&(s^o))+c+1518500249+a,c=o,o=s,s=(i<<30|i>>>2)>>>0,i=n,n=a;for(;l<20;++l)a=(a=t[l-3]^t[l-8]^t[l-14]^t[l-16])<<1|a>>>31,t[l]=a,a=(n<<5|n>>>27)+(o^i&(s^o))+c+1518500249+a,c=o,o=s,s=(i<<30|i>>>2)>>>0,i=n,n=a;for(;l<32;++l)a=(a=t[l-3]^t[l-8]^t[l-14]^t[l-16])<<1|a>>>31,t[l]=a,a=(n<<5|n>>>27)+(i^s^o)+c+1859775393+a,c=o,o=s,s=(i<<30|i>>>2)>>>0,i=n,n=a;for(;l<40;++l)a=(a=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|a>>>30,t[l]=a,a=(n<<5|n>>>27)+(i^s^o)+c+1859775393+a,c=o,o=s,s=(i<<30|i>>>2)>>>0,i=n,n=a;for(;l<60;++l)a=(a=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|a>>>30,t[l]=a,a=(n<<5|n>>>27)+(i&s|o&(i^s))+c+2400959708+a,c=o,o=s,s=(i<<30|i>>>2)>>>0,i=n,n=a;for(;l<80;++l)a=(a=t[l-6]^t[l-16]^t[l-28]^t[l-32])<<2|a>>>30,t[l]=a,a=(n<<5|n>>>27)+(i^s^o)+c+3395469782+a,c=o,o=s,s=(i<<30|i>>>2)>>>0,i=n,n=a;e.h0=e.h0+n|0,e.h1=e.h1+i|0,e.h2=e.h2+s|0,e.h3=e.h3+o|0,e.h4=e.h4+c|0,u-=64}}var wt=f,Nt=wt.pkcs1=wt.pkcs1||{};function kt(e,t,r){r||(r=wt.md.sha1.create());for(var a="",n=Math.ceil(t/r.digestLength),i=0;i<n;++i){var s=String.fromCharCode(i>>24&255,i>>16&255,i>>8&255,255&i);r.start(),r.update(e+s),a+=r.digest().getBytes()}return a.substring(0,t)}Nt.encode_rsa_oaep=function(e,t,r){var a,n,i,s;"string"==typeof r?(a=r,n=arguments[3]||void 0,i=arguments[4]||void 0):r&&(a=r.label||void 0,n=r.seed||void 0,i=r.md||void 0,r.mgf1&&r.mgf1.md&&(s=r.mgf1.md)),i?i.start():i=wt.md.sha1.create(),s||(s=i);var o=Math.ceil(e.n.bitLength()/8),c=o-2*i.digestLength-2;if(t.length>c)throw(f=new Error("RSAES-OAEP input message length is too long.")).length=t.length,f.maxLength=c,f;a||(a=""),i.update(a,"raw");for(var l=i.digest(),u="",p=c-t.length,d=0;d<p;d++)u+="\0";var h=l.getBytes()+u+""+t;if(n){if(n.length!==i.digestLength){var f;throw(f=new Error("Invalid RSAES-OAEP seed. The seed length must match the digest length.")).seedLength=n.length,f.digestLength=i.digestLength,f}}else n=wt.random.getBytes(i.digestLength);var y=kt(n,o-i.digestLength-1,s),g=wt.util.xorBytes(h,y,h.length),v=kt(g,i.digestLength,s);return"\0"+wt.util.xorBytes(n,v,n.length)+g},Nt.decode_rsa_oaep=function(e,t,r){var a,n,i;"string"==typeof r?(a=r,n=arguments[3]||void 0):r&&(a=r.label||void 0,n=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(y=new Error("RSAES-OAEP encoded message length is invalid.")).length=t.length,y.expectedLength=s,y;if(void 0===n?n=wt.md.sha1.create():n.start(),i||(i=n),s<2*n.digestLength+2)throw new Error("RSAES-OAEP key is too short for the hash function.");a||(a=""),n.update(a,"raw");for(var o=n.digest().getBytes(),c=t.charAt(0),l=t.substring(1,n.digestLength+1),u=t.substring(1+n.digestLength),p=kt(u,n.digestLength,i),d=kt(wt.util.xorBytes(l,p,l.length),s-n.digestLength-1,i),h=wt.util.xorBytes(u,d,u.length),f=h.substring(0,n.digestLength),y="\0"!==c,g=0;g<n.digestLength;++g)y|=o.charAt(g)!==f.charAt(g);for(var v=1,m=n.digestLength,C=n.digestLength;C<h.length;C++){var E=h.charCodeAt(C);y|=E&(v?65534:0),m+=v&=1&E^1}if(y||1!==h.charCodeAt(m))throw new Error("Invalid RSAES-OAEP padding.");return h.substring(m+1)};var Rt=f;!function(){if(Rt.prime)Rt.prime;else{var e=Rt.prime=Rt.prime||{},t=Rt.jsbn.BigInteger,r=[6,4,2,4,2,4,6,2],a=new t(null);a.fromInt(30);var n=function(e,t){return e|t};e.generateProbablePrime=function(e,r,a){"function"==typeof r&&(a=r,r={});var n=(r=r||{}).algorithm||"PRIMEINC";"string"==typeof n&&(n={name:n}),n.options=n.options||{};var s=r.prng||Rt.random,c={nextBytes:function(e){for(var t=s.getBytesSync(e.length),r=0;r<e.length;++r)e[r]=t.charCodeAt(r)}};if("PRIMEINC"===n.name)return function(e,r,a,n){if("workers"in a)return function(e,r,a,n){if("undefined"==typeof Worker)return i(e,r,a,n);var s=o(e,r),c=a.workers,l=a.workLoad||100,u=30*l/8,p=a.workerScript||"forge/prime.worker.js";if(-1===c)return Rt.util.estimateCores(function(e,t){e&&(t=2),c=t-1,d()});function d(){c=Math.max(1,c);for(var a=[],i=0;i<c;++i)a[i]=new Worker(p);for(i=0;i<c;++i)a[i].addEventListener("message",h);var d=!1;function h(i){if(!d){var c=i.data;if(c.found){for(var p=0;p<a.length;++p)a[p].terminate();return d=!0,n(null,new t(c.prime,16))}s.bitLength()>e&&(s=o(e,r));var h=s.toString(16);i.target.postMessage({hex:h,workLoad:l}),s.dAddOffset(u,0)}}}d()}(e,r,a,n);return i(e,r,a,n)}(e,c,n.options,a);throw new Error("Invalid prime generation algorithm: "+n.name)}}function i(e,t,r,a){var n=o(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}(n.bitLength());"millerRabinTests"in r&&(i=r.millerRabinTests);var c=10;"maxBlockTime"in r&&(c=r.maxBlockTime),s(n,e,t,0,i,c,a)}function s(e,t,a,n,i,c,l){var u=+new Date;do{if(e.bitLength()>t&&(e=o(t,a)),e.isProbablePrime(i))return l(null,e);e.dAddOffset(r[n++%8],0)}while(c<0||+new Date-u<c);Rt.util.setImmediate(function(){s(e,t,a,n,i,c,l)})}function o(e,r){var i=new t(e,r),s=e-1;return i.testBit(s)||i.bitwiseTo(t.ONE.shiftLeft(s),n,i),i.dAddOffset(31-i.mod(a).byteValue(),0),i}}();var Lt=f;if(void 0===_t)var _t=Lt.jsbn.BigInteger;var Dt=Lt.util.isNodejs?t:null,Ut=Lt.asn1,Pt=Lt.util;Lt.pki=Lt.pki||{},Lt.pki.rsa=Lt.rsa=Lt.rsa||{};var Vt=Lt.pki,Ot=[6,4,2,4,2,4,6,2],Kt={name:"PrivateKeyInfo",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,value:[{name:"PrivateKeyInfo.version",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.privateKeyAlgorithm",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.OID,constructed:!1,capture:"privateKeyOid"}]},{name:"PrivateKeyInfo",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.OCTETSTRING,constructed:!1,capture:"privateKey"}]},Mt={name:"RSAPrivateKey",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPrivateKey.version",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"privateKeyCoefficient"}]},Ft={name:"RSAPublicKey",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPublicKey.modulus",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.INTEGER,constructed:!1,capture:"publicKeyExponent"}]},qt=Lt.pki.rsa.publicKeyValidator={name:"SubjectPublicKeyInfo",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{name:"SubjectPublicKeyInfo.subjectPublicKey",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.BITSTRING,constructed:!1,value:[{name:"SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"rsaPublicKey"}]}]},jt={name:"DigestInfo",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,value:[{name:"DigestInfo.DigestAlgorithm",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.SEQUENCE,constructed:!0,value:[{name:"DigestInfo.DigestAlgorithm.algorithmIdentifier",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.OID,constructed:!1,capture:"algorithmIdentifier"},{name:"DigestInfo.DigestAlgorithm.parameters",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.NULL,capture:"parameters",optional:!0,constructed:!1}]},{name:"DigestInfo.digest",tagClass:Ut.Class.UNIVERSAL,type:Ut.Type.OCTETSTRING,constructed:!1,capture:"digest"}]},Ht=function(e){var t;if(!(e.algorithm in Vt.oids)){var r=new Error("Unknown message digest algorithm.");throw r.algorithm=e.algorithm,r}t=Vt.oids[e.algorithm];var a=Ut.oidToDer(t).getBytes(),n=Ut.create(Ut.Class.UNIVERSAL,Ut.Type.SEQUENCE,!0,[]),i=Ut.create(Ut.Class.UNIVERSAL,Ut.Type.SEQUENCE,!0,[]);i.value.push(Ut.create(Ut.Class.UNIVERSAL,Ut.Type.OID,!1,a)),i.value.push(Ut.create(Ut.Class.UNIVERSAL,Ut.Type.NULL,!1,""));var s=Ut.create(Ut.Class.UNIVERSAL,Ut.Type.OCTETSTRING,!1,e.digest().getBytes());return n.value.push(i),n.value.push(s),Ut.toDer(n).getBytes()},Gt=function(e,t,r){if(r)return e.modPow(t.e,t.n);if(!t.p||!t.q)return e.modPow(t.d,t.n);var a;t.dP||(t.dP=t.d.mod(t.p.subtract(_t.ONE))),t.dQ||(t.dQ=t.d.mod(t.q.subtract(_t.ONE))),t.qInv||(t.qInv=t.q.modInverse(t.p));do{a=new _t(Lt.util.bytesToHex(Lt.random.getBytes(t.n.bitLength()/8)),16)}while(a.compareTo(t.n)>=0||!a.gcd(t.n).equals(_t.ONE));for(var n=(e=e.multiply(a.modPow(t.e,t.n)).mod(t.n)).mod(t.p).modPow(t.dP,t.p),i=e.mod(t.q).modPow(t.dQ,t.q);n.compareTo(i)<0;)n=n.add(t.p);var s=n.subtract(i).multiply(t.qInv).mod(t.p).multiply(t.q).add(i);return s=s.multiply(a.modInverse(t.n)).mod(t.n)};function zt(e,t,r){var a=Lt.util.createBuffer(),n=Math.ceil(t.n.bitLength()/8);if(e.length>n-11){var i=new Error("Message is too long for PKCS#1 v1.5 padding.");throw i.length=e.length,i.max=n-11,i}a.putByte(0),a.putByte(r);var s,o=n-3-e.length;if(0===r||1===r){s=0===r?0:255;for(var c=0;c<o;++c)a.putByte(s)}else for(;o>0;){var l=0,u=Lt.random.getBytes(o);for(c=0;c<o;++c)0===(s=u.charCodeAt(c))?++l:a.putByte(s);o=l}return a.putByte(0),a.putBytes(e),a}function Qt(e,t,r,a){var n=Math.ceil(t.n.bitLength()/8),i=Lt.util.createBuffer(e),s=i.getByte(),o=i.getByte();if(0!==s||r&&0!==o&&1!==o||!r&&2!=o||r&&0===o&&void 0===a)throw new Error("Encryption block is invalid.");var c=0;if(0===o){c=n-3-a;for(var l=0;l<c;++l)if(0!==i.getByte())throw new Error("Encryption block is invalid.")}else if(1===o)for(c=0;i.length()>1;){if(255!==i.getByte()){--i.read;break}++c}else if(2===o)for(c=0;i.length()>1;){if(0===i.getByte()){--i.read;break}++c}if(0!==i.getByte()||c!==n-3-i.length())throw new Error("Encryption block is invalid.");return i.getBytes()}function Yt(e){var t=e.toString(16);t[0]>="8"&&(t="00"+t);var r=Lt.util.hexToBytes(t);return!(r.length>1)||(0!==r.charCodeAt(0)||128&r.charCodeAt(1))&&(255!==r.charCodeAt(0)||128&~r.charCodeAt(1))?r:r.substr(1)}function Xt(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 Wt(e){return Lt.util.isNodejs&&"function"==typeof Dt[e]}function $t(e){return void 0!==Pt.globalScope&&"object"==typeof Pt.globalScope.crypto&&"object"==typeof Pt.globalScope.crypto.subtle&&"function"==typeof Pt.globalScope.crypto.subtle[e]}function Zt(e){return void 0!==Pt.globalScope&&"object"==typeof Pt.globalScope.msCrypto&&"object"==typeof Pt.globalScope.msCrypto.subtle&&"function"==typeof Pt.globalScope.msCrypto.subtle[e]}function Jt(e){for(var t=Lt.util.hexToBytes(e.toString(16)),r=new Uint8Array(t.length),a=0;a<t.length;++a)r[a]=t.charCodeAt(a);return r}Vt.rsa.encrypt=function(e,t,r){var a,n=r,i=Math.ceil(t.n.bitLength()/8);!1!==r&&!0!==r?(n=2===r,a=zt(e,t,r)):(a=Lt.util.createBuffer()).putBytes(e);for(var s=new _t(a.toHex(),16),o=Gt(s,t,n).toString(16),c=Lt.util.createBuffer(),l=i-Math.ceil(o.length/2);l>0;)c.putByte(0),--l;return c.putBytes(Lt.util.hexToBytes(o)),c.getBytes()},Vt.rsa.decrypt=function(e,t,r,a){var n=Math.ceil(t.n.bitLength()/8);if(e.length!==n){var i=new Error("Encrypted message length is invalid.");throw i.length=e.length,i.expected=n,i}var s=new _t(Lt.util.createBuffer(e).toHex(),16);if(s.compareTo(t.n)>=0)throw new Error("Encrypted message is invalid.");for(var o=Gt(s,t,r).toString(16),c=Lt.util.createBuffer(),l=n-Math.ceil(o.length/2);l>0;)c.putByte(0),--l;return c.putBytes(Lt.util.hexToBytes(o)),!1!==a?Qt(c.getBytes(),t,r):c.getBytes()},Vt.rsa.createKeyPairGenerationState=function(e,t,r){"string"==typeof e&&(e=parseInt(e,10)),e=e||2048;var a,n=(r=r||{}).prng||Lt.random,i={nextBytes:function(e){for(var t=n.getBytesSync(e.length),r=0;r<e.length;++r)e[r]=t.charCodeAt(r)}},s=r.algorithm||"PRIMEINC";if("PRIMEINC"!==s)throw new Error("Invalid key generation algorithm: "+s);return(a={algorithm:s,state:0,bits:e,rng:i,eInt:t||65537,e:new _t(null),p:null,q:null,qBits:e>>1,pBits:e-(e>>1),pqState:0,num:null,keys:null}).e.fromInt(a.eInt),a},Vt.rsa.stepKeyPairGenerationState=function(e,t){"algorithm"in e||(e.algorithm="PRIMEINC");var r=new _t(null);r.fromInt(30);for(var a,n=0,i=function(e,t){return e|t},s=+new Date,o=0;null===e.keys&&(t<=0||o<t);){if(0===e.state){var c=null===e.p?e.pBits:e.qBits,l=c-1;0===e.pqState?(e.num=new _t(c,e.rng),e.num.testBit(l)||e.num.bitwiseTo(_t.ONE.shiftLeft(l),i,e.num),e.num.dAddOffset(31-e.num.mod(r).byteValue(),0),n=0,++e.pqState):1===e.pqState?e.num.bitLength()>c?e.pqState=0:e.num.isProbablePrime(Xt(e.num.bitLength()))?++e.pqState:e.num.dAddOffset(Ot[n++%8],0):2===e.pqState?e.pqState=0===e.num.subtract(_t.ONE).gcd(e.e).compareTo(_t.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(_t.ONE),e.q1=e.q.subtract(_t.ONE),e.phi=e.p1.multiply(e.q1),++e.state;else if(3===e.state)0===e.phi.gcd(e.e).compareTo(_t.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 u=e.e.modInverse(e.phi);e.keys={privateKey:Vt.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:Vt.rsa.setPublicKey(e.n,e.e)}}o+=(a=+new Date)-s,s=a}return null!==e.keys},Vt.rsa.generateKeyPair=function(e,t,r,a){if(1===arguments.length?"object"==typeof e?(r=e,e=void 0):"function"==typeof e&&(a=e,e=void 0):2===arguments.length?"number"==typeof e?"function"==typeof t?(a=t,t=void 0):"number"!=typeof t&&(r=t,t=void 0):(r=e,a=t,e=void 0,t=void 0):3===arguments.length&&("number"==typeof t?"function"==typeof r&&(a=r,r=void 0):(a=r,r=t,t=void 0)),r=r||{},void 0===e&&(e=r.bits||2048),void 0===t&&(t=r.e||65537),!Lt.options.usePureJavaScript&&!r.prng&&e>=256&&e<=16384&&(65537===t||3===t))if(a){if(Wt("generateKeyPair"))return Dt.generateKeyPair("rsa",{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}},function(e,t,r){if(e)return a(e);a(null,{privateKey:Vt.privateKeyFromPem(r),publicKey:Vt.publicKeyFromPem(t)})});if($t("generateKey")&&$t("exportKey"))return Pt.globalScope.crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:Jt(t),hash:{name:"SHA-256"}},!0,["sign","verify"]).then(function(e){return Pt.globalScope.crypto.subtle.exportKey("pkcs8",e.privateKey)}).then(void 0,function(e){a(e)}).then(function(e){if(e){var t=Vt.privateKeyFromAsn1(Ut.fromDer(Lt.util.createBuffer(e)));a(null,{privateKey:t,publicKey:Vt.setRsaPublicKey(t.n,t.e)})}});if(Zt("generateKey")&&Zt("exportKey")){var n=Pt.globalScope.msCrypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:Jt(t),hash:{name:"SHA-256"}},!0,["sign","verify"]);return n.oncomplete=function(e){var t=e.target.result,r=Pt.globalScope.msCrypto.subtle.exportKey("pkcs8",t.privateKey);r.oncomplete=function(e){var t=e.target.result,r=Vt.privateKeyFromAsn1(Ut.fromDer(Lt.util.createBuffer(t)));a(null,{privateKey:r,publicKey:Vt.setRsaPublicKey(r.n,r.e)})},r.onerror=function(e){a(e)}},void(n.onerror=function(e){a(e)})}}else if(Wt("generateKeyPairSync")){var i=Dt.generateKeyPairSync("rsa",{modulusLength:e,publicExponent:t,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:Vt.privateKeyFromPem(i.privateKey),publicKey:Vt.publicKeyFromPem(i.publicKey)}}var s=Vt.rsa.createKeyPairGenerationState(e,t,r);if(!a)return Vt.rsa.stepKeyPairGenerationState(s,0),s.keys;!function(e,t,r){"function"==typeof t&&(r=t,t={});t=t||{};var a={algorithm:{name:t.algorithm||"PRIMEINC",options:{workers:t.workers||2,workLoad:t.workLoad||100,workerScript:t.workerScript}}};"prng"in t&&(a.prng=t.prng);function n(){i(e.pBits,function(t,a){return t?r(t):(e.p=a,null!==e.q?s(t,e.q):void i(e.qBits,s))})}function i(e,t){Lt.prime.generateProbablePrime(e,a,t)}function s(t,a){if(t)return r(t);if(e.q=a,e.p.compareTo(e.q)<0){var o=e.p;e.p=e.q,e.q=o}if(0!==e.p.subtract(_t.ONE).gcd(e.e).compareTo(_t.ONE))return e.p=null,void n();if(0!==e.q.subtract(_t.ONE).gcd(e.e).compareTo(_t.ONE))return e.q=null,void i(e.qBits,s);if(e.p1=e.p.subtract(_t.ONE),e.q1=e.q.subtract(_t.ONE),e.phi=e.p1.multiply(e.q1),0!==e.phi.gcd(e.e).compareTo(_t.ONE))return e.p=e.q=null,void n();if(e.n=e.p.multiply(e.q),e.n.bitLength()!==e.bits)return e.q=null,void i(e.qBits,s);var c=e.e.modInverse(e.phi);e.keys={privateKey:Vt.rsa.setPrivateKey(e.n,e.e,c,e.p,e.q,c.mod(e.p1),c.mod(e.q1),e.q.modInverse(e.p)),publicKey:Vt.rsa.setPublicKey(e.n,e.e)},r(null,e.keys)}n()}(s,r,a)},Vt.setRsaPublicKey=Vt.rsa.setPublicKey=function(e,t){var r={n:e,e:t,encrypt:function(e,t,a){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,r){return zt(e,t,2).getBytes()}};else if("RSA-OAEP"===t||"RSAES-OAEP"===t)t={encode:function(e,t){return Lt.pkcs1.encode_rsa_oaep(t,e,a)}};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 n=t.encode(e,r,!0);return Vt.rsa.encrypt(n,r,!0)},verify:function(e,t,a,n){"string"==typeof a?a=a.toUpperCase():void 0===a&&(a="RSASSA-PKCS1-V1_5"),void 0===n&&(n={_parseAllDigestBytes:!0}),"_parseAllDigestBytes"in n||(n._parseAllDigestBytes=!0),"RSASSA-PKCS1-V1_5"===a?a={verify:function(e,t){t=Qt(t,r,!0);var a=Ut.fromDer(t,{parseAllBytes:n._parseAllDigestBytes}),i={},s=[];if(!Ut.validate(a,jt,i,s))throw(o=new Error("ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value.")).errors=s,o;var o,c=Ut.derToOid(i.algorithmIdentifier);if(c!==Lt.oids.md2&&c!==Lt.oids.md5&&c!==Lt.oids.sha1&&c!==Lt.oids.sha224&&c!==Lt.oids.sha256&&c!==Lt.oids.sha384&&c!==Lt.oids.sha512&&c!==Lt.oids["sha512-224"]&&c!==Lt.oids["sha512-256"])throw(o=new Error("Unknown RSASSA-PKCS1-v1_5 DigestAlgorithm identifier.")).oid=c,o;if((c===Lt.oids.md2||c===Lt.oids.md5)&&!("parameters"in i))throw new Error("ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value. Missing algorithm identifier NULL parameters.");return e===i.digest}}:"NONE"!==a&&"NULL"!==a&&null!==a||(a={verify:function(e,t){return e===(t=Qt(t,r,!0))}});var i=Vt.rsa.decrypt(t,r,!0,!1);return a.verify(e,i,r.n.bitLength())}};return r},Vt.setRsaPrivateKey=Vt.rsa.setPrivateKey=function(e,t,r,a,n,i,s,o){var c={n:e,e:t,d:r,p:a,q:n,dP:i,dQ:s,qInv:o,decrypt:function(e,t,r){"string"==typeof t?t=t.toUpperCase():void 0===t&&(t="RSAES-PKCS1-V1_5");var a=Vt.rsa.decrypt(e,c,!1,!1);if("RSAES-PKCS1-V1_5"===t)t={decode:Qt};else if("RSA-OAEP"===t||"RSAES-OAEP"===t)t={decode:function(e,t){return Lt.pkcs1.decode_rsa_oaep(t,e,r)}};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(a,c,!1)},sign:function(e,t){var r=!1;"string"==typeof t&&(t=t.toUpperCase()),void 0===t||"RSASSA-PKCS1-V1_5"===t?(t={encode:Ht},r=1):"NONE"!==t&&"NULL"!==t&&null!==t||(t={encode:function(){return e}},r=1);var a=t.encode(e,c.n.bitLength());return Vt.rsa.encrypt(a,c,r)}};return c},Vt.wrapRsaPrivateKey=function(e){return Ut.create(Ut.Class.UNIVERSAL,Ut.Type.SEQUENCE,!0,[Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Ut.integerToDer(0).getBytes()),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.SEQUENCE,!0,[Ut.create(Ut.Class.UNIVERSAL,Ut.Type.OID,!1,Ut.oidToDer(Vt.oids.rsaEncryption).getBytes()),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.NULL,!1,"")]),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.OCTETSTRING,!1,Ut.toDer(e).getBytes())])},Vt.privateKeyFromAsn1=function(e){var t,r,a,n,i,s,o,c,l={},u=[];if(Ut.validate(e,Kt,l,u)&&(e=Ut.fromDer(Lt.util.createBuffer(l.privateKey))),l={},u=[],!Ut.validate(e,Mt,l,u)){var p=new Error("Cannot read private key. ASN.1 object does not contain an RSAPrivateKey.");throw p.errors=u,p}return t=Lt.util.createBuffer(l.privateKeyModulus).toHex(),r=Lt.util.createBuffer(l.privateKeyPublicExponent).toHex(),a=Lt.util.createBuffer(l.privateKeyPrivateExponent).toHex(),n=Lt.util.createBuffer(l.privateKeyPrime1).toHex(),i=Lt.util.createBuffer(l.privateKeyPrime2).toHex(),s=Lt.util.createBuffer(l.privateKeyExponent1).toHex(),o=Lt.util.createBuffer(l.privateKeyExponent2).toHex(),c=Lt.util.createBuffer(l.privateKeyCoefficient).toHex(),Vt.setRsaPrivateKey(new _t(t,16),new _t(r,16),new _t(a,16),new _t(n,16),new _t(i,16),new _t(s,16),new _t(o,16),new _t(c,16))},Vt.privateKeyToAsn1=Vt.privateKeyToRSAPrivateKey=function(e){return Ut.create(Ut.Class.UNIVERSAL,Ut.Type.SEQUENCE,!0,[Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Ut.integerToDer(0).getBytes()),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.n)),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.e)),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.d)),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.p)),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.q)),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.dP)),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.dQ)),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.qInv))])},Vt.publicKeyFromAsn1=function(e){var t={},r=[];if(Ut.validate(e,qt,t,r)){var a,n=Ut.derToOid(t.publicKeyOid);if(n!==Vt.oids.rsaEncryption)throw(a=new Error("Cannot read public key. Unknown OID.")).oid=n,a;e=t.rsaPublicKey}if(r=[],!Ut.validate(e,Ft,t,r))throw(a=new Error("Cannot read public key. ASN.1 object does not contain an RSAPublicKey.")).errors=r,a;var i=Lt.util.createBuffer(t.publicKeyModulus).toHex(),s=Lt.util.createBuffer(t.publicKeyExponent).toHex();return Vt.setRsaPublicKey(new _t(i,16),new _t(s,16))},Vt.publicKeyToAsn1=Vt.publicKeyToSubjectPublicKeyInfo=function(e){return Ut.create(Ut.Class.UNIVERSAL,Ut.Type.SEQUENCE,!0,[Ut.create(Ut.Class.UNIVERSAL,Ut.Type.SEQUENCE,!0,[Ut.create(Ut.Class.UNIVERSAL,Ut.Type.OID,!1,Ut.oidToDer(Vt.oids.rsaEncryption).getBytes()),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.NULL,!1,"")]),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.BITSTRING,!1,[Vt.publicKeyToRSAPublicKey(e)])])},Vt.publicKeyToRSAPublicKey=function(e){return Ut.create(Ut.Class.UNIVERSAL,Ut.Type.SEQUENCE,!0,[Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.n)),Ut.create(Ut.Class.UNIVERSAL,Ut.Type.INTEGER,!1,Yt(e.e))])};var er=f;if(void 0===tr)var tr=er.jsbn.BigInteger;var rr=er.asn1,ar=er.pki=er.pki||{};ar.pbe=er.pbe=er.pbe||{};var nr=ar.oids,ir={name:"EncryptedPrivateKeyInfo",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedPrivateKeyInfo.encryptionAlgorithm",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:rr.Class.UNIVERSAL,type:rr.Type.OID,constructed:!1,capture:"encryptionOid"},{name:"AlgorithmIdentifier.parameters",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,captureAsn1:"encryptionParams"}]},{name:"EncryptedPrivateKeyInfo.encryptedData",tagClass:rr.Class.UNIVERSAL,type:rr.Type.OCTETSTRING,constructed:!1,capture:"encryptedData"}]},sr={name:"PBES2Algorithms",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc.oid",tagClass:rr.Class.UNIVERSAL,type:rr.Type.OID,constructed:!1,capture:"kdfOid"},{name:"PBES2Algorithms.params",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.params.salt",tagClass:rr.Class.UNIVERSAL,type:rr.Type.OCTETSTRING,constructed:!1,capture:"kdfSalt"},{name:"PBES2Algorithms.params.iterationCount",tagClass:rr.Class.UNIVERSAL,type:rr.Type.INTEGER,constructed:!1,capture:"kdfIterationCount"},{name:"PBES2Algorithms.params.keyLength",tagClass:rr.Class.UNIVERSAL,type:rr.Type.INTEGER,constructed:!1,optional:!0,capture:"keyLength"},{name:"PBES2Algorithms.params.prf",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,optional:!0,value:[{name:"PBES2Algorithms.params.prf.algorithm",tagClass:rr.Class.UNIVERSAL,type:rr.Type.OID,constructed:!1,capture:"prfOid"}]}]}]},{name:"PBES2Algorithms.encryptionScheme",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.encryptionScheme.oid",tagClass:rr.Class.UNIVERSAL,type:rr.Type.OID,constructed:!1,capture:"encOid"},{name:"PBES2Algorithms.encryptionScheme.iv",tagClass:rr.Class.UNIVERSAL,type:rr.Type.OCTETSTRING,constructed:!1,capture:"encIv"}]}]},or={name:"pkcs-12PbeParams",tagClass:rr.Class.UNIVERSAL,type:rr.Type.SEQUENCE,constructed:!0,value:[{name:"pkcs-12PbeParams.salt",tagClass:rr.Class.UNIVERSAL,type:rr.Type.OCTETSTRING,constructed:!1,capture:"salt"},{name:"pkcs-12PbeParams.iterations",tagClass:rr.Class.UNIVERSAL,type:rr.Type.INTEGER,constructed:!1,capture:"iterations"}]};function cr(e,t){return e.start().update(t).digest().getBytes()}function lr(e){var t;if(e){if(!(t=ar.oids[rr.derToOid(e)])){var r=new Error("Unsupported PRF OID.");throw r.oid=e,r.supported=["hmacWithSHA1","hmacWithSHA224","hmacWithSHA256","hmacWithSHA384","hmacWithSHA512"],r}}else t="hmacWithSHA1";return ur(t)}function ur(e){var t=er.md;switch(e){case"hmacWithSHA224":t=er.md.sha512;case"hmacWithSHA1":case"hmacWithSHA256":case"hmacWithSHA384":case"hmacWithSHA512":e=e.substr(8).toLowerCase();break;default:var r=new Error("Unsupported PRF algorithm.");throw r.algorithm=e,r.supported=["hmacWithSHA1","hmacWithSHA224","hmacWithSHA256","hmacWithSHA384","hmacWithSHA512"],r}if(!t||!(e in t))throw new Error("Unknown hash algorithm: "+e);return t[e].create()}ar.encryptPrivateKeyInfo=function(e,t,r){(r=r||{}).saltSize=r.saltSize||8,r.count=r.count||2048,r.algorithm=r.algorithm||"aes128",r.prfAlgorithm=r.prfAlgorithm||"sha1";var a,n,i,s=er.random.getBytesSync(r.saltSize),o=r.count,c=rr.integerToDer(o);if(0===r.algorithm.indexOf("aes")||"des"===r.algorithm){var l,u,p;switch(r.algorithm){case"aes128":a=16,l=16,u=nr["aes128-CBC"],p=er.aes.createEncryptionCipher;break;case"aes192":a=24,l=16,u=nr["aes192-CBC"],p=er.aes.createEncryptionCipher;break;case"aes256":a=32,l=16,u=nr["aes256-CBC"],p=er.aes.createEncryptionCipher;break;case"des":a=8,l=8,u=nr.desCBC,p=er.des.createEncryptionCipher;break;default:throw(v=new Error("Cannot encrypt private key. Unknown encryption algorithm.")).algorithm=r.algorithm,v}var d="hmacWith"+r.prfAlgorithm.toUpperCase(),h=ur(d),f=er.pkcs5.pbkdf2(t,s,o,a,h),y=er.random.getBytesSync(l);(m=p(f)).start(y),m.update(rr.toDer(e)),m.finish(),i=m.output.getBytes();var g=function(e,t,r,a){var n=rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[rr.create(rr.Class.UNIVERSAL,rr.Type.OCTETSTRING,!1,e),rr.create(rr.Class.UNIVERSAL,rr.Type.INTEGER,!1,t.getBytes())]);"hmacWithSHA1"!==a&&n.value.push(rr.create(rr.Class.UNIVERSAL,rr.Type.INTEGER,!1,er.util.hexToBytes(r.toString(16))),rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[rr.create(rr.Class.UNIVERSAL,rr.Type.OID,!1,rr.oidToDer(ar.oids[a]).getBytes()),rr.create(rr.Class.UNIVERSAL,rr.Type.NULL,!1,"")]));return n}(s,c,a,d);n=rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[rr.create(rr.Class.UNIVERSAL,rr.Type.OID,!1,rr.oidToDer(nr.pkcs5PBES2).getBytes()),rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[rr.create(rr.Class.UNIVERSAL,rr.Type.OID,!1,rr.oidToDer(nr.pkcs5PBKDF2).getBytes()),g]),rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[rr.create(rr.Class.UNIVERSAL,rr.Type.OID,!1,rr.oidToDer(u).getBytes()),rr.create(rr.Class.UNIVERSAL,rr.Type.OCTETSTRING,!1,y)])])])}else{var v;if("3des"!==r.algorithm)throw(v=new Error("Cannot encrypt private key. Unknown encryption algorithm.")).algorithm=r.algorithm,v;a=24;var m,C=new er.util.ByteBuffer(s);f=ar.pbe.generatePkcs12Key(t,C,1,o,a),y=ar.pbe.generatePkcs12Key(t,C,2,o,a);(m=er.des.createEncryptionCipher(f)).start(y),m.update(rr.toDer(e)),m.finish(),i=m.output.getBytes(),n=rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[rr.create(rr.Class.UNIVERSAL,rr.Type.OID,!1,rr.oidToDer(nr["pbeWithSHAAnd3-KeyTripleDES-CBC"]).getBytes()),rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[rr.create(rr.Class.UNIVERSAL,rr.Type.OCTETSTRING,!1,s),rr.create(rr.Class.UNIVERSAL,rr.Type.INTEGER,!1,c.getBytes())])])}return rr.create(rr.Class.UNIVERSAL,rr.Type.SEQUENCE,!0,[n,rr.create(rr.Class.UNIVERSAL,rr.Type.OCTETSTRING,!1,i)])},ar.decryptPrivateKeyInfo=function(e,t){var r=null,a={},n=[];if(!rr.validate(e,ir,a,n)){var i=new Error("Cannot read encrypted private key. ASN.1 object is not a supported EncryptedPrivateKeyInfo.");throw i.errors=n,i}var s=rr.derToOid(a.encryptionOid),o=ar.pbe.getCipher(s,a.encryptionParams,t),c=er.util.createBuffer(a.encryptedData);return o.update(c),o.finish()&&(r=rr.fromDer(o.output)),r},ar.encryptedPrivateKeyToPem=function(e,t){var r={type:"ENCRYPTED PRIVATE KEY",body:rr.toDer(e).getBytes()};return er.pem.encode(r,{maxline:t})},ar.encryptedPrivateKeyFromPem=function(e){var t=er.pem.decode(e)[0];if("ENCRYPTED PRIVATE KEY"!==t.type){var r=new Error('Could not convert encrypted private key from PEM; PEM header type is "ENCRYPTED PRIVATE KEY".');throw r.headerType=t.type,r}if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert encrypted private key from PEM; PEM is encrypted.");return rr.fromDer(t.body)},ar.encryptRsaPrivateKey=function(e,t,r){if(!(r=r||{}).legacy){var a=ar.wrapRsaPrivateKey(ar.privateKeyToAsn1(e));return a=ar.encryptPrivateKeyInfo(a,t,r),ar.encryptedPrivateKeyToPem(a)}var n,i,s,o;switch(r.algorithm){case"aes128":n="AES-128-CBC",s=16,i=er.random.getBytesSync(16),o=er.aes.createEncryptionCipher;break;case"aes192":n="AES-192-CBC",s=24,i=er.random.getBytesSync(16),o=er.aes.createEncryptionCipher;break;case"aes256":n="AES-256-CBC",s=32,i=er.random.getBytesSync(16),o=er.aes.createEncryptionCipher;break;case"3des":n="DES-EDE3-CBC",s=24,i=er.random.getBytesSync(8),o=er.des.createEncryptionCipher;break;case"des":n="DES-CBC",s=8,i=er.random.getBytesSync(8),o=er.des.createEncryptionCipher;break;default:var c=new Error('Could not encrypt RSA private key; unsupported encryption algorithm "'+r.algorithm+'".');throw c.algorithm=r.algorithm,c}var l=o(er.pbe.opensslDeriveBytes(t,i.substr(0,8),s));l.start(i),l.update(rr.toDer(ar.privateKeyToAsn1(e))),l.finish();var u={type:"RSA PRIVATE KEY",procType:{version:"4",type:"ENCRYPTED"},dekInfo:{algorithm:n,parameters:er.util.bytesToHex(i).toUpperCase()},body:l.output.getBytes()};return er.pem.encode(u)},ar.decryptRsaPrivateKey=function(e,t){var r=null,a=er.pem.decode(e)[0];if("ENCRYPTED PRIVATE KEY"!==a.type&&"PRIVATE KEY"!==a.type&&"RSA PRIVATE KEY"!==a.type)throw(s=new Error('Could not convert private key from PEM; PEM header type is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".')).headerType=s,s;if(a.procType&&"ENCRYPTED"===a.procType.type){var n,i;switch(a.dekInfo.algorithm){case"DES-CBC":n=8,i=er.des.createDecryptionCipher;break;case"DES-EDE3-CBC":n=24,i=er.des.createDecryptionCipher;break;case"AES-128-CBC":n=16,i=er.aes.createDecryptionCipher;break;case"AES-192-CBC":n=24,i=er.aes.createDecryptionCipher;break;case"AES-256-CBC":n=32,i=er.aes.createDecryptionCipher;break;case"RC2-40-CBC":n=5,i=function(e){return er.rc2.createDecryptionCipher(e,40)};break;case"RC2-64-CBC":n=8,i=function(e){return er.rc2.createDecryptionCipher(e,64)};break;case"RC2-128-CBC":n=16,i=function(e){return er.rc2.createDecryptionCipher(e,128)};break;default:var s;throw(s=new Error('Could not decrypt private key; unsupported encryption algorithm "'+a.dekInfo.algorithm+'".')).algorithm=a.dekInfo.algorithm,s}var o=er.util.hexToBytes(a.dekInfo.parameters),c=i(er.pbe.opensslDeriveBytes(t,o.substr(0,8),n));if(c.start(o),c.update(er.util.createBuffer(a.body)),!c.finish())return r;r=c.output.getBytes()}else r=a.body;return null!==(r="ENCRYPTED PRIVATE KEY"===a.type?ar.decryptPrivateKeyInfo(rr.fromDer(r),t):rr.fromDer(r))&&(r=ar.privateKeyFromAsn1(r)),r},ar.pbe.generatePkcs12Key=function(e,t,r,a,n,i){var s,o;if(null==i){if(!("sha1"in er.md))throw new Error('"sha1" hash algorithm unavailable.');i=er.md.sha1.create()}var c=i.digestLength,l=i.blockLength,u=new er.util.ByteBuffer,p=new er.util.ByteBuffer;if(null!=e){for(o=0;o<e.length;o++)p.putInt16(e.charCodeAt(o));p.putInt16(0)}var d=p.length(),h=t.length(),f=new er.util.ByteBuffer;f.fillWithByte(r,l);var y=l*Math.ceil(h/l),g=new er.util.ByteBuffer;for(o=0;o<y;o++)g.putByte(t.at(o%h));var v=l*Math.ceil(d/l),m=new er.util.ByteBuffer;for(o=0;o<v;o++)m.putByte(p.at(o%d));var C=g;C.putBuffer(m);for(var E=Math.ceil(n/c),S=1;S<=E;S++){var b=new er.util.ByteBuffer;b.putBytes(f.bytes()),b.putBytes(C.bytes());for(var T=0;T<a;T++)i.start(),i.update(b.getBytes()),b=i.digest();var I=new er.util.ByteBuffer;for(o=0;o<l;o++)I.putByte(b.at(o%c));var A=Math.ceil(h/l)+Math.ceil(d/l),B=new er.util.ByteBuffer;for(s=0;s<A;s++){var x=new er.util.ByteBuffer(C.getBytes(l)),w=511;for(o=I.length()-1;o>=0;o--)w>>=8,w+=I.at(o)+x.at(o),x.setAt(o,255&w);B.putBuffer(x)}C=B,u.putBuffer(b)}return u.truncate(u.length()-n),u},ar.pbe.getCipher=function(e,t,r){switch(e){case ar.oids.pkcs5PBES2:return ar.pbe.getCipherForPBES2(e,t,r);case ar.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:case ar.oids["pbewithSHAAnd40BitRC2-CBC"]:return ar.pbe.getCipherForPKCS12PBE(e,t,r);default:var a=new Error("Cannot read encrypted PBE data block. Unsupported OID.");throw a.oid=e,a.supportedOids=["pkcs5PBES2","pbeWithSHAAnd3-KeyTripleDES-CBC","pbewithSHAAnd40BitRC2-CBC"],a}},ar.pbe.getCipherForPBES2=function(e,t,r){var a,n={},i=[];if(!rr.validate(t,sr,n,i))throw(a=new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.")).errors=i,a;if((e=rr.derToOid(n.kdfOid))!==ar.oids.pkcs5PBKDF2)throw(a=new Error("Cannot read encrypted private key. Unsupported key derivation function OID.")).oid=e,a.supportedOids=["pkcs5PBKDF2"],a;if((e=rr.derToOid(n.encOid))!==ar.oids["aes128-CBC"]&&e!==ar.oids["aes192-CBC"]&&e!==ar.oids["aes256-CBC"]&&e!==ar.oids["des-EDE3-CBC"]&&e!==ar.oids.desCBC)throw(a=new Error("Cannot read encrypted private key. Unsupported encryption scheme OID.")).oid=e,a.supportedOids=["aes128-CBC","aes192-CBC","aes256-CBC","des-EDE3-CBC","desCBC"],a;var s,o,c=n.kdfSalt,l=er.util.createBuffer(n.kdfIterationCount);switch(l=l.getInt(l.length()<<3),ar.oids[e]){case"aes128-CBC":s=16,o=er.aes.createDecryptionCipher;break;case"aes192-CBC":s=24,o=er.aes.createDecryptionCipher;break;case"aes256-CBC":s=32,o=er.aes.createDecryptionCipher;break;case"des-EDE3-CBC":s=24,o=er.des.createDecryptionCipher;break;case"desCBC":s=8,o=er.des.createDecryptionCipher}var u=lr(n.prfOid),p=er.pkcs5.pbkdf2(r,c,l,s,u),d=n.encIv,h=o(p);return h.start(d),h},ar.pbe.getCipherForPKCS12PBE=function(e,t,r){var a={},n=[];if(!rr.validate(t,or,a,n))throw(u=new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.")).errors=n,u;var i,s,o,c=er.util.createBuffer(a.salt),l=er.util.createBuffer(a.iterations);switch(l=l.getInt(l.length()<<3),e){case ar.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:i=24,s=8,o=er.des.startDecrypting;break;case ar.oids["pbewithSHAAnd40BitRC2-CBC"]:i=5,s=8,o=function(e,t){var r=er.rc2.createDecryptionCipher(e,40);return r.start(t,null),r};break;default:var u;throw(u=new Error("Cannot read PKCS #12 PBE data block. Unsupported OID.")).oid=e,u}var p=lr(a.prfOid),d=ar.pbe.generatePkcs12Key(r,c,1,l,i,p);return p.start(),o(d,ar.pbe.generatePkcs12Key(r,c,2,l,s,p))},ar.pbe.opensslDeriveBytes=function(e,t,r,a){if(null==a){if(!("md5"in er.md))throw new Error('"md5" hash algorithm unavailable.');a=er.md.md5.create()}null===t&&(t="");for(var n=[cr(a,e+t)],i=16,s=1;i<r;++s,i+=16)n.push(cr(a,n[s-1]+e+t));return n.join("").substr(0,r)};var pr=f,dr=pr.asn1,hr=pr.pkcs7asn1=pr.pkcs7asn1||{};pr.pkcs7=pr.pkcs7||{},pr.pkcs7.asn1=hr;var fr={name:"ContentInfo",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"ContentInfo.ContentType",tagClass:dr.Class.UNIVERSAL,type:dr.Type.OID,constructed:!1,capture:"contentType"},{name:"ContentInfo.content",tagClass:dr.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,captureAsn1:"content"}]};hr.contentInfoValidator=fr;var yr={name:"EncryptedContentInfo",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedContentInfo.contentType",tagClass:dr.Class.UNIVERSAL,type:dr.Type.OID,constructed:!1,capture:"contentType"},{name:"EncryptedContentInfo.contentEncryptionAlgorithm",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedContentInfo.contentEncryptionAlgorithm.algorithm",tagClass:dr.Class.UNIVERSAL,type:dr.Type.OID,constructed:!1,capture:"encAlgorithm"},{name:"EncryptedContentInfo.contentEncryptionAlgorithm.parameter",tagClass:dr.Class.UNIVERSAL,captureAsn1:"encParameter"}]},{name:"EncryptedContentInfo.encryptedContent",tagClass:dr.Class.CONTEXT_SPECIFIC,type:0,capture:"encryptedContent",captureAsn1:"encryptedContentAsn1"}]};hr.envelopedDataValidator={name:"EnvelopedData",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"EnvelopedData.Version",tagClass:dr.Class.UNIVERSAL,type:dr.Type.INTEGER,constructed:!1,capture:"version"},{name:"EnvelopedData.RecipientInfos",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SET,constructed:!0,captureAsn1:"recipientInfos"}].concat(yr)},hr.encryptedDataValidator={name:"EncryptedData",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedData.Version",tagClass:dr.Class.UNIVERSAL,type:dr.Type.INTEGER,constructed:!1,capture:"version"}].concat(yr)};var gr={name:"SignerInfo",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.version",tagClass:dr.Class.UNIVERSAL,type:dr.Type.INTEGER,constructed:!1},{name:"SignerInfo.issuerAndSerialNumber",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.issuerAndSerialNumber.issuer",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,captureAsn1:"issuer"},{name:"SignerInfo.issuerAndSerialNumber.serialNumber",tagClass:dr.Class.UNIVERSAL,type:dr.Type.INTEGER,constructed:!1,capture:"serial"}]},{name:"SignerInfo.digestAlgorithm",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.digestAlgorithm.algorithm",tagClass:dr.Class.UNIVERSAL,type:dr.Type.OID,constructed:!1,capture:"digestAlgorithm"},{name:"SignerInfo.digestAlgorithm.parameter",tagClass:dr.Class.UNIVERSAL,constructed:!1,captureAsn1:"digestParameter",optional:!0}]},{name:"SignerInfo.authenticatedAttributes",tagClass:dr.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,capture:"authenticatedAttributes"},{name:"SignerInfo.digestEncryptionAlgorithm",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,capture:"signatureAlgorithm"},{name:"SignerInfo.encryptedDigest",tagClass:dr.Class.UNIVERSAL,type:dr.Type.OCTETSTRING,constructed:!1,capture:"signature"},{name:"SignerInfo.unauthenticatedAttributes",tagClass:dr.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0,capture:"unauthenticatedAttributes"}]};hr.signedDataValidator={name:"SignedData",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"SignedData.Version",tagClass:dr.Class.UNIVERSAL,type:dr.Type.INTEGER,constructed:!1,capture:"version"},{name:"SignedData.DigestAlgorithms",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SET,constructed:!0,captureAsn1:"digestAlgorithms"},fr,{name:"SignedData.Certificates",tagClass:dr.Class.CONTEXT_SPECIFIC,type:0,optional:!0,captureAsn1:"certificates"},{name:"SignedData.CertificateRevocationLists",tagClass:dr.Class.CONTEXT_SPECIFIC,type:1,optional:!0,captureAsn1:"crls"},{name:"SignedData.SignerInfos",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SET,capture:"signerInfos",optional:!0,value:[gr]}]},hr.recipientInfoValidator={name:"RecipientInfo",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.version",tagClass:dr.Class.UNIVERSAL,type:dr.Type.INTEGER,constructed:!1,capture:"version"},{name:"RecipientInfo.issuerAndSerial",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.issuerAndSerial.issuer",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,captureAsn1:"issuer"},{name:"RecipientInfo.issuerAndSerial.serialNumber",tagClass:dr.Class.UNIVERSAL,type:dr.Type.INTEGER,constructed:!1,capture:"serial"}]},{name:"RecipientInfo.keyEncryptionAlgorithm",tagClass:dr.Class.UNIVERSAL,type:dr.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.keyEncryptionAlgorithm.algorithm",tagClass:dr.Class.UNIVERSAL,type:dr.Type.OID,constructed:!1,capture:"encAlgorithm"},{name:"RecipientInfo.keyEncryptionAlgorithm.parameter",tagClass:dr.Class.UNIVERSAL,constructed:!1,captureAsn1:"encParameter",optional:!0}]},{name:"RecipientInfo.encryptedKey",tagClass:dr.Class.UNIVERSAL,type:dr.Type.OCTETSTRING,constructed:!1,capture:"encKey"}]};var vr=f;vr.mgf=vr.mgf||{},(vr.mgf.mgf1=vr.mgf1=vr.mgf1||{}).create=function(e){var t={generate:function(t,r){for(var a=new vr.util.ByteBuffer,n=Math.ceil(r/e.digestLength),i=0;i<n;i++){var s=new vr.util.ByteBuffer;s.putInt32(i),e.start(),e.update(t+s.getBytes()),a.putBuffer(e.digest())}return a.truncate(a.length()-r),a.getBytes()}};return t};var mr=f;mr.mgf=mr.mgf||{},mr.mgf.mgf1=mr.mgf1;var Cr=f;(Cr.pss=Cr.pss||{}).create=function(e){3===arguments.length&&(e={md:arguments[0],mgf:arguments[1],saltLength:arguments[2]});var t,r=e.md,a=e.mgf,n=r.digestLength,i=e.salt||null;if("string"==typeof i&&(i=Cr.util.createBuffer(i)),"saltLength"in e)t=e.saltLength;else{if(null===i)throw new Error("Salt length not specified or specific salt not given.");t=i.length()}if(null!==i&&i.length()!==t)throw new Error("Given salt length does not match length of given salt.");var s=e.prng||Cr.random,o={encode:function(e,o){var c,l,u=o-1,p=Math.ceil(u/8),d=e.digest().getBytes();if(p<n+t+2)throw new Error("Message is too long to encrypt.");l=null===i?s.getBytesSync(t):i.bytes();var h=new Cr.util.ByteBuffer;h.fillWithByte(0,8),h.putBytes(d),h.putBytes(l),r.start(),r.update(h.getBytes());var f=r.digest().getBytes(),y=new Cr.util.ByteBuffer;y.fillWithByte(0,p-t-n-2),y.putByte(1),y.putBytes(l);var g=y.getBytes(),v=p-n-1,m=a.generate(f,v),C="";for(c=0;c<v;c++)C+=String.fromCharCode(g.charCodeAt(c)^m.charCodeAt(c));var E=65280>>8*p-u&255;return(C=String.fromCharCode(C.charCodeAt(0)&~E)+C.substr(1))+f+String.fromCharCode(188)},verify:function(e,i,s){var o,c=s-1,l=Math.ceil(c/8);if(i=i.substr(-l),l<n+t+2)throw new Error("Inconsistent parameters to PSS signature verification.");if(188!==i.charCodeAt(l-1))throw new Error("Encoded message does not end in 0xBC.");var u=l-n-1,p=i.substr(0,u),d=i.substr(u,n),h=65280>>8*l-c&255;if(0!==(p.charCodeAt(0)&h))throw new Error("Bits beyond keysize not zero as expected.");var f=a.generate(d,u),y="";for(o=0;o<u;o++)y+=String.fromCharCode(p.charCodeAt(o)^f.charCodeAt(o));y=String.fromCharCode(y.charCodeAt(0)&~h)+y.substr(1);var g=l-n-t-2;for(o=0;o<g;o++)if(0!==y.charCodeAt(o))throw new Error("Leftmost octets not zero as expected");if(1!==y.charCodeAt(g))throw new Error("Inconsistent PSS signature, 0x01 marker not found");var v=y.substr(-t),m=new Cr.util.ByteBuffer;return m.fillWithByte(0,8),m.putBytes(e),m.putBytes(v),r.start(),r.update(m.getBytes()),d===r.digest().getBytes()}};return o};var Er=f,Sr=Er.asn1,br=Er.pki=Er.pki||{},Tr=br.oids,Ir={};Ir.CN=Tr.commonName,Ir.commonName="CN",Ir.C=Tr.countryName,Ir.countryName="C",Ir.L=Tr.localityName,Ir.localityName="L",Ir.ST=Tr.stateOrProvinceName,Ir.stateOrProvinceName="ST",Ir.O=Tr.organizationName,Ir.organizationName="O",Ir.OU=Tr.organizationalUnitName,Ir.organizationalUnitName="OU",Ir.E=Tr.emailAddress,Ir.emailAddress="E";var Ar=Er.pki.rsa.publicKeyValidator,Br={name:"Certificate",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,captureAsn1:"tbsCertificate",value:[{name:"Certificate.TBSCertificate.version",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.version.integer",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.INTEGER,constructed:!1,capture:"certVersion"}]},{name:"Certificate.TBSCertificate.serialNumber",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.INTEGER,constructed:!1,capture:"certSerialNumber"},{name:"Certificate.TBSCertificate.signature",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.signature.algorithm",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.OID,constructed:!1,capture:"certinfoSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:Sr.Class.UNIVERSAL,optional:!0,captureAsn1:"certinfoSignatureParams"}]},{name:"Certificate.TBSCertificate.issuer",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,captureAsn1:"certIssuer"},{name:"Certificate.TBSCertificate.validity",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.validity.notBefore (utc)",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity1UTCTime"},{name:"Certificate.TBSCertificate.validity.notBefore (generalized)",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity2GeneralizedTime"},{name:"Certificate.TBSCertificate.validity.notAfter (utc)",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity3UTCTime"},{name:"Certificate.TBSCertificate.validity.notAfter (generalized)",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity4GeneralizedTime"}]},{name:"Certificate.TBSCertificate.subject",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,captureAsn1:"certSubject"},Ar,{name:"Certificate.TBSCertificate.issuerUniqueID",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.issuerUniqueID.id",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.BITSTRING,constructed:!1,captureBitStringValue:"certIssuerUniqueId"}]},{name:"Certificate.TBSCertificate.subjectUniqueID",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:2,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.subjectUniqueID.id",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.BITSTRING,constructed:!1,captureBitStringValue:"certSubjectUniqueId"}]},{name:"Certificate.TBSCertificate.extensions",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:3,constructed:!0,captureAsn1:"certExtensions",optional:!0}]},{name:"Certificate.signatureAlgorithm",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.signatureAlgorithm.algorithm",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.OID,constructed:!1,capture:"certSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:Sr.Class.UNIVERSAL,optional:!0,captureAsn1:"certSignatureParams"}]},{name:"Certificate.signatureValue",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.BITSTRING,constructed:!1,captureBitStringValue:"certSignature"}]},xr={name:"rsapss",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.hashAlgorithm",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier",tagClass:Sr.Class.UNIVERSAL,type:Sr.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier.algorithm",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.OID,constructed:!1,capture:"hashOid"}]}]},{name:"rsapss.maskGenAlgorithm",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier",tagClass:Sr.Class.UNIVERSAL,type:Sr.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.algorithm",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.OID,constructed:!1,capture:"maskGenOid"},{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params.algorithm",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.OID,constructed:!1,capture:"maskGenHashOid"}]}]}]},{name:"rsapss.saltLength",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:2,optional:!0,value:[{name:"rsapss.saltLength.saltLength",tagClass:Sr.Class.UNIVERSAL,type:Sr.Class.INTEGER,constructed:!1,capture:"saltLength"}]},{name:"rsapss.trailerField",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:3,optional:!0,value:[{name:"rsapss.trailer.trailer",tagClass:Sr.Class.UNIVERSAL,type:Sr.Class.INTEGER,constructed:!1,capture:"trailer"}]}]},wr={name:"CertificationRequestInfo",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,captureAsn1:"certificationRequestInfo",value:[{name:"CertificationRequestInfo.integer",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.INTEGER,constructed:!1,capture:"certificationRequestInfoVersion"},{name:"CertificationRequestInfo.subject",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,captureAsn1:"certificationRequestInfoSubject"},Ar,{name:"CertificationRequestInfo.attributes",tagClass:Sr.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,capture:"certificationRequestInfoAttributes",value:[{name:"CertificationRequestInfo.attributes",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,value:[{name:"CertificationRequestInfo.attributes.type",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.OID,constructed:!1},{name:"CertificationRequestInfo.attributes.value",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SET,constructed:!0}]}]}]},Nr={name:"CertificationRequest",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,captureAsn1:"csr",value:[wr,{name:"CertificationRequest.signatureAlgorithm",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.SEQUENCE,constructed:!0,value:[{name:"CertificationRequest.signatureAlgorithm.algorithm",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.OID,constructed:!1,capture:"csrSignatureOid"},{name:"CertificationRequest.signatureAlgorithm.parameters",tagClass:Sr.Class.UNIVERSAL,optional:!0,captureAsn1:"csrSignatureParams"}]},{name:"CertificationRequest.signature",tagClass:Sr.Class.UNIVERSAL,type:Sr.Type.BITSTRING,constructed:!1,captureBitStringValue:"csrSignature"}]};function kr(e,t){"string"==typeof t&&(t={shortName:t});for(var r,a=null,n=0;null===a&&n<e.attributes.length;++n)r=e.attributes[n],(t.type&&t.type===r.type||t.name&&t.name===r.name||t.shortName&&t.shortName===r.shortName)&&(a=r);return a}br.RDNAttributesAsArray=function(e,t){for(var r,a,n,i=[],s=0;s<e.value.length;++s){r=e.value[s];for(var o=0;o<r.value.length;++o)n={},a=r.value[o],n.type=Sr.derToOid(a.value[0].value),n.value=a.value[1].value,n.valueTagClass=a.value[1].type,n.type in Tr&&(n.name=Tr[n.type],n.name in Ir&&(n.shortName=Ir[n.name])),t&&(t.update(n.type),t.update(n.value)),i.push(n)}return i},br.CRIAttributesAsArray=function(e){for(var t=[],r=0;r<e.length;++r)for(var a=e[r],n=Sr.derToOid(a.value[0].value),i=a.value[1].value,s=0;s<i.length;++s){var o={};if(o.type=n,o.value=i[s].value,o.valueTagClass=i[s].type,o.type in Tr&&(o.name=Tr[o.type],o.name in Ir&&(o.shortName=Ir[o.name])),o.type===Tr.extensionRequest){o.extensions=[];for(var c=0;c<o.value.length;++c)o.extensions.push(br.certificateExtensionFromAsn1(o.value[c]))}t.push(o)}return t};var Rr=function(e,t,r){var a={};if(e!==Tr["RSASSA-PSS"])return a;r&&(a={hash:{algorithmOid:Tr.sha1},mgf:{algorithmOid:Tr.mgf1,hash:{algorithmOid:Tr.sha1}},saltLength:20});var n={},i=[];if(!Sr.validate(t,xr,n,i)){var s=new Error("Cannot read RSASSA-PSS parameter block.");throw s.errors=i,s}return void 0!==n.hashOid&&(a.hash=a.hash||{},a.hash.algorithmOid=Sr.derToOid(n.hashOid)),void 0!==n.maskGenOid&&(a.mgf=a.mgf||{},a.mgf.algorithmOid=Sr.derToOid(n.maskGenOid),a.mgf.hash=a.mgf.hash||{},a.mgf.hash.algorithmOid=Sr.derToOid(n.maskGenHashOid)),void 0!==n.saltLength&&(a.saltLength=n.saltLength.charCodeAt(0)),a},Lr=function(e){switch(Tr[e.signatureOid]){case"sha1WithRSAEncryption":case"sha1WithRSASignature":return Er.md.sha1.create();case"md5WithRSAEncryption":return Er.md.md5.create();case"sha256WithRSAEncryption":case"RSASSA-PSS":return Er.md.sha256.create();case"sha384WithRSAEncryption":return Er.md.sha384.create();case"sha512WithRSAEncryption":return Er.md.sha512.create();default:var t=new Error("Could not compute "+e.type+" digest. Unknown signature OID.");throw t.signatureOid=e.signatureOid,t}},_r=function(e){var t,r=e.certificate;switch(r.signatureOid){case Tr.sha1WithRSAEncryption:case Tr.sha1WithRSASignature:break;case Tr["RSASSA-PSS"]:var a,n,i;if(void 0===(a=Tr[r.signatureParameters.mgf.hash.algorithmOid])||void 0===Er.md[a])throw(i=new Error("Unsupported MGF hash function.")).oid=r.signatureParameters.mgf.hash.algorithmOid,i.name=a,i;if(void 0===(n=Tr[r.signatureParameters.mgf.algorithmOid])||void 0===Er.mgf[n])throw(i=new Error("Unsupported MGF function.")).oid=r.signatureParameters.mgf.algorithmOid,i.name=n,i;if(n=Er.mgf[n].create(Er.md[a].create()),void 0===(a=Tr[r.signatureParameters.hash.algorithmOid])||void 0===Er.md[a])throw(i=new Error("Unsupported RSASSA-PSS hash function.")).oid=r.signatureParameters.hash.algorithmOid,i.name=a,i;t=Er.pss.create(Er.md[a].create(),n,r.signatureParameters.saltLength)}return r.publicKey.verify(e.md.digest().getBytes(),e.signature,t)};function Dr(e){for(var t,r,a=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]),n=e.attributes,i=0;i<n.length;++i){var s=(t=n[i]).value,o=Sr.Type.PRINTABLESTRING;"valueTagClass"in t&&(o=t.valueTagClass)===Sr.Type.UTF8&&(s=Er.util.encodeUtf8(s)),r=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SET,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(t.type).getBytes()),Sr.create(Sr.Class.UNIVERSAL,o,!1,s)])]),a.value.push(r)}return a}function Ur(e){for(var t,r=0;r<e.length;++r){if(void 0===(t=e[r]).name&&(t.type&&t.type in br.oids?t.name=br.oids[t.type]:t.shortName&&t.shortName in Ir&&(t.name=br.oids[Ir[t.shortName]])),void 0===t.type){if(!t.name||!(t.name in br.oids))throw(n=new Error("Attribute type not specified.")).attribute=t,n;t.type=br.oids[t.name]}if(void 0===t.shortName&&t.name&&t.name in Ir&&(t.shortName=Ir[t.name]),t.type===Tr.extensionRequest&&(t.valueConstructed=!0,t.valueTagClass=Sr.Type.SEQUENCE,!t.value&&t.extensions)){t.value=[];for(var a=0;a<t.extensions.length;++a)t.value.push(br.certificateExtensionToAsn1(Pr(t.extensions[a])))}var n;if(void 0===t.value)throw(n=new Error("Attribute value not specified.")).attribute=t,n}}function Pr(e,t){if(t=t||{},void 0===e.name&&e.id&&e.id in br.oids&&(e.name=br.oids[e.id]),void 0===e.id){if(!e.name||!(e.name in br.oids))throw(g=new Error("Extension ID not specified.")).extension=e,g;e.id=br.oids[e.name]}if(void 0!==e.value)return e;if("keyUsage"===e.name){var r=0,a=0,n=0;e.digitalSignature&&(a|=128,r=7),e.nonRepudiation&&(a|=64,r=6),e.keyEncipherment&&(a|=32,r=5),e.dataEncipherment&&(a|=16,r=4),e.keyAgreement&&(a|=8,r=3),e.keyCertSign&&(a|=4,r=2),e.cRLSign&&(a|=2,r=1),e.encipherOnly&&(a|=1,r=0),e.decipherOnly&&(n|=128,r=7);var i=String.fromCharCode(r);0!==n?i+=String.fromCharCode(a)+String.fromCharCode(n):0!==a&&(i+=String.fromCharCode(a)),e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.BITSTRING,!1,i)}else if("basicConstraints"===e.name)e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]),e.cA&&e.value.value.push(Sr.create(Sr.Class.UNIVERSAL,Sr.Type.BOOLEAN,!1,String.fromCharCode(255))),"pathLenConstraint"in e&&e.value.value.push(Sr.create(Sr.Class.UNIVERSAL,Sr.Type.INTEGER,!1,Sr.integerToDer(e.pathLenConstraint).getBytes()));else if("extKeyUsage"===e.name){e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]);var s=e.value.value;for(var o in e)!0===e[o]&&(o in Tr?s.push(Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(Tr[o]).getBytes())):-1!==o.indexOf(".")&&s.push(Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(o).getBytes())))}else if("nsCertType"===e.name){r=0,a=0;e.client&&(a|=128,r=7),e.server&&(a|=64,r=6),e.email&&(a|=32,r=5),e.objsign&&(a|=16,r=4),e.reserved&&(a|=8,r=3),e.sslCA&&(a|=4,r=2),e.emailCA&&(a|=2,r=1),e.objCA&&(a|=1,r=0);i=String.fromCharCode(r);0!==a&&(i+=String.fromCharCode(a)),e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.BITSTRING,!1,i)}else if("subjectAltName"===e.name||"issuerAltName"===e.name){e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]);for(var c=0;c<e.altNames.length;++c){i=(h=e.altNames[c]).value;if(7===h.type&&h.ip){if(null===(i=Er.util.bytesFromIP(h.ip)))throw(g=new Error('Extension "ip" value is not a valid IPv4 or IPv6 address.')).extension=e,g}else 8===h.type&&(i=h.oid?Sr.oidToDer(Sr.oidToDer(h.oid)):Sr.oidToDer(i));e.value.value.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,h.type,!1,i))}}else if("nsComment"===e.name&&t.cert){if(!/^[\x00-\x7F]*$/.test(e.comment)||e.comment.length<1||e.comment.length>128)throw new Error('Invalid "nsComment" content.');e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.IA5STRING,!1,e.comment)}else if("subjectKeyIdentifier"===e.name&&t.cert){var l=t.cert.generateSubjectKeyIdentifier();e.subjectKeyIdentifier=l.toHex(),e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OCTETSTRING,!1,l.getBytes())}else if("authorityKeyIdentifier"===e.name&&t.cert){e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]);s=e.value.value;if(e.keyIdentifier){var u=!0===e.keyIdentifier?t.cert.generateSubjectKeyIdentifier().getBytes():e.keyIdentifier;s.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,0,!1,u))}if(e.authorityCertIssuer){var p=[Sr.create(Sr.Class.CONTEXT_SPECIFIC,4,!0,[Dr(!0===e.authorityCertIssuer?t.cert.issuer:e.authorityCertIssuer)])];s.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,1,!0,p))}if(e.serialNumber){var d=Er.util.hexToBytes(!0===e.serialNumber?t.cert.serialNumber:e.serialNumber);s.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,2,!1,d))}}else if("cRLDistributionPoints"===e.name){e.value=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]);s=e.value.value;var h,f=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]),y=Sr.create(Sr.Class.CONTEXT_SPECIFIC,0,!0,[]);for(c=0;c<e.altNames.length;++c){i=(h=e.altNames[c]).value;if(7===h.type&&h.ip){if(null===(i=Er.util.bytesFromIP(h.ip)))throw(g=new Error('Extension "ip" value is not a valid IPv4 or IPv6 address.')).extension=e,g}else 8===h.type&&(i=h.oid?Sr.oidToDer(Sr.oidToDer(h.oid)):Sr.oidToDer(i));y.value.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,h.type,!1,i))}f.value.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,0,!0,[y])),s.push(f)}var g;if(void 0===e.value)throw(g=new Error("Extension value not specified.")).extension=e,g;return e}function Vr(e,t){if(e===Tr["RSASSA-PSS"]){var r=[];return void 0!==t.hash.algorithmOid&&r.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,0,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(t.hash.algorithmOid).getBytes()),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.NULL,!1,"")])])),void 0!==t.mgf.algorithmOid&&r.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,1,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(t.mgf.algorithmOid).getBytes()),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(t.mgf.hash.algorithmOid).getBytes()),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.NULL,!1,"")])])])),void 0!==t.saltLength&&r.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,2,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.INTEGER,!1,Sr.integerToDer(t.saltLength).getBytes())])),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,r)}return Sr.create(Sr.Class.UNIVERSAL,Sr.Type.NULL,!1,"")}function Or(e){var t=Sr.create(Sr.Class.CONTEXT_SPECIFIC,0,!0,[]);if(0===e.attributes.length)return t;for(var r=e.attributes,a=0;a<r.length;++a){var n=r[a],i=n.value,s=Sr.Type.UTF8;"valueTagClass"in n&&(s=n.valueTagClass),s===Sr.Type.UTF8&&(i=Er.util.encodeUtf8(i));var o=!1;"valueConstructed"in n&&(o=n.valueConstructed);var c=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(n.type).getBytes()),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SET,!0,[Sr.create(Sr.Class.UNIVERSAL,s,o,i)])]);t.value.push(c)}return t}br.certificateFromPem=function(e,t,r){var a=Er.pem.decode(e)[0];if("CERTIFICATE"!==a.type&&"X509 CERTIFICATE"!==a.type&&"TRUSTED CERTIFICATE"!==a.type){var n=new Error('Could not convert certificate from PEM; PEM header type is not "CERTIFICATE", "X509 CERTIFICATE", or "TRUSTED CERTIFICATE".');throw n.headerType=a.type,n}if(a.procType&&"ENCRYPTED"===a.procType.type)throw new Error("Could not convert certificate from PEM; PEM is encrypted.");var i=Sr.fromDer(a.body,r);return br.certificateFromAsn1(i,t)},br.certificateToPem=function(e,t){var r={type:"CERTIFICATE",body:Sr.toDer(br.certificateToAsn1(e)).getBytes()};return Er.pem.encode(r,{maxline:t})},br.publicKeyFromPem=function(e){var t=Er.pem.decode(e)[0];if("PUBLIC KEY"!==t.type&&"RSA PUBLIC KEY"!==t.type){var r=new Error('Could not convert public key from PEM; PEM header type is not "PUBLIC KEY" or "RSA PUBLIC KEY".');throw r.headerType=t.type,r}if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert public key from PEM; PEM is encrypted.");var a=Sr.fromDer(t.body);return br.publicKeyFromAsn1(a)},br.publicKeyToPem=function(e,t){var r={type:"PUBLIC KEY",body:Sr.toDer(br.publicKeyToAsn1(e)).getBytes()};return Er.pem.encode(r,{maxline:t})},br.publicKeyToRSAPublicKeyPem=function(e,t){var r={type:"RSA PUBLIC KEY",body:Sr.toDer(br.publicKeyToRSAPublicKey(e)).getBytes()};return Er.pem.encode(r,{maxline:t})},br.getPublicKeyFingerprint=function(e,t){var r,a=(t=t||{}).md||Er.md.sha1.create();switch(t.type||"RSAPublicKey"){case"RSAPublicKey":r=Sr.toDer(br.publicKeyToRSAPublicKey(e)).getBytes();break;case"SubjectPublicKeyInfo":r=Sr.toDer(br.publicKeyToAsn1(e)).getBytes();break;default:throw new Error('Unknown fingerprint type "'+t.type+'".')}a.start(),a.update(r);var n=a.digest();if("hex"===t.encoding){var i=n.toHex();return t.delimiter?i.match(/.{2}/g).join(t.delimiter):i}if("binary"===t.encoding)return n.getBytes();if(t.encoding)throw new Error('Unknown encoding "'+t.encoding+'".');return n},br.certificationRequestFromPem=function(e,t,r){var a=Er.pem.decode(e)[0];if("CERTIFICATE REQUEST"!==a.type){var n=new Error('Could not convert certification request from PEM; PEM header type is not "CERTIFICATE REQUEST".');throw n.headerType=a.type,n}if(a.procType&&"ENCRYPTED"===a.procType.type)throw new Error("Could not convert certification request from PEM; PEM is encrypted.");var i=Sr.fromDer(a.body,r);return br.certificationRequestFromAsn1(i,t)},br.certificationRequestToPem=function(e,t){var r={type:"CERTIFICATE REQUEST",body:Sr.toDer(br.certificationRequestToAsn1(e)).getBytes()};return Er.pem.encode(r,{maxline:t})},br.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 kr(e.issuer,t)},e.issuer.addField=function(t){Ur([t]),e.issuer.attributes.push(t)},e.issuer.attributes=[],e.issuer.hash=null,e.subject={},e.subject.getField=function(t){return kr(e.subject,t)},e.subject.addField=function(t){Ur([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,r){Ur(t),e.subject.attributes=t,delete e.subject.uniqueId,r&&(e.subject.uniqueId=r),e.subject.hash=null},e.setIssuer=function(t,r){Ur(t),e.issuer.attributes=t,delete e.issuer.uniqueId,r&&(e.issuer.uniqueId=r),e.issuer.hash=null},e.setExtensions=function(t){for(var r=0;r<t.length;++r)Pr(t[r],{cert:e});e.extensions=t},e.getExtension=function(t){"string"==typeof t&&(t={name:t});for(var r,a=null,n=0;null===a&&n<e.extensions.length;++n)r=e.extensions[n],(t.id&&r.id===t.id||t.name&&r.name===t.name)&&(a=r);return a},e.sign=function(t,r){e.md=r||Er.md.sha1.create();var a=Tr[e.md.algorithm+"WithRSAEncryption"];if(!a){var n=new Error("Could not compute certificate digest. Unknown message digest algorithm OID.");throw n.algorithm=e.md.algorithm,n}e.signatureOid=e.siginfo.algorithmOid=a,e.tbsCertificate=br.getTBSCertificate(e);var i=Sr.toDer(e.tbsCertificate);e.md.update(i.getBytes()),e.signature=t.sign(e.md)},e.verify=function(t){var r=!1;if(!e.issued(t)){var a=t.issuer,n=e.subject,i=new Error("The parent certificate did not issue the given child certificate; the child certificate's issuer does not match the parent's subject.");throw i.expectedIssuer=n.attributes,i.actualIssuer=a.attributes,i}var s=t.md;if(null===s){s=Lr({signatureOid:t.signatureOid,type:"certificate"});var o=t.tbsCertificate||br.getTBSCertificate(t),c=Sr.toDer(o);s.update(c.getBytes())}return null!==s&&(r=_r({certificate:e,md:s,signature:t.signature})),r},e.isIssuer=function(t){var r=!1,a=e.issuer,n=t.subject;if(a.hash&&n.hash)r=a.hash===n.hash;else if(a.attributes.length===n.attributes.length){var i,s;r=!0;for(var o=0;r&&o<a.attributes.length;++o)i=a.attributes[o],s=n.attributes[o],i.type===s.type&&i.value===s.value||(r=!1)}return r},e.issued=function(t){return t.isIssuer(e)},e.generateSubjectKeyIdentifier=function(){return br.getPublicKeyFingerprint(e.publicKey,{type:"RSAPublicKey"})},e.verifySubjectKeyIdentifier=function(){for(var t=Tr.subjectKeyIdentifier,r=0;r<e.extensions.length;++r){var a=e.extensions[r];if(a.id===t){var n=e.generateSubjectKeyIdentifier().getBytes();return Er.util.hexToBytes(a.subjectKeyIdentifier)===n}}return!1},e},br.certificateFromAsn1=function(e,t){var r={},a=[];if(!Sr.validate(e,Br,r,a)){var n=new Error("Cannot read X.509 certificate. ASN.1 object is not an X509v3 Certificate.");throw n.errors=a,n}if(Sr.derToOid(r.publicKeyOid)!==br.oids.rsaEncryption)throw new Error("Cannot read public key. OID is not RSA.");var i=br.createCertificate();i.version=r.certVersion?r.certVersion.charCodeAt(0):0;var s=Er.util.createBuffer(r.certSerialNumber);i.serialNumber=s.toHex(),i.signatureOid=Er.asn1.derToOid(r.certSignatureOid),i.signatureParameters=Rr(i.signatureOid,r.certSignatureParams,!0),i.siginfo.algorithmOid=Er.asn1.derToOid(r.certinfoSignatureOid),i.siginfo.parameters=Rr(i.siginfo.algorithmOid,r.certinfoSignatureParams,!1),i.signature=r.certSignature;var o=[];if(void 0!==r.certValidity1UTCTime&&o.push(Sr.utcTimeToDate(r.certValidity1UTCTime)),void 0!==r.certValidity2GeneralizedTime&&o.push(Sr.generalizedTimeToDate(r.certValidity2GeneralizedTime)),void 0!==r.certValidity3UTCTime&&o.push(Sr.utcTimeToDate(r.certValidity3UTCTime)),void 0!==r.certValidity4GeneralizedTime&&o.push(Sr.generalizedTimeToDate(r.certValidity4GeneralizedTime)),o.length>2)throw new Error("Cannot read notBefore/notAfter validity times; more than two times were provided in the certificate.");if(o.length<2)throw new Error("Cannot read notBefore/notAfter validity times; they were not provided as either UTCTime or GeneralizedTime.");if(i.validity.notBefore=o[0],i.validity.notAfter=o[1],i.tbsCertificate=r.tbsCertificate,t){i.md=Lr({signatureOid:i.signatureOid,type:"certificate"});var c=Sr.toDer(i.tbsCertificate);i.md.update(c.getBytes())}var l=Er.md.sha1.create(),u=Sr.toDer(r.certIssuer);l.update(u.getBytes()),i.issuer.getField=function(e){return kr(i.issuer,e)},i.issuer.addField=function(e){Ur([e]),i.issuer.attributes.push(e)},i.issuer.attributes=br.RDNAttributesAsArray(r.certIssuer),r.certIssuerUniqueId&&(i.issuer.uniqueId=r.certIssuerUniqueId),i.issuer.hash=l.digest().toHex();var p=Er.md.sha1.create(),d=Sr.toDer(r.certSubject);return p.update(d.getBytes()),i.subject.getField=function(e){return kr(i.subject,e)},i.subject.addField=function(e){Ur([e]),i.subject.attributes.push(e)},i.subject.attributes=br.RDNAttributesAsArray(r.certSubject),r.certSubjectUniqueId&&(i.subject.uniqueId=r.certSubjectUniqueId),i.subject.hash=p.digest().toHex(),r.certExtensions?i.extensions=br.certificateExtensionsFromAsn1(r.certExtensions):i.extensions=[],i.publicKey=br.publicKeyFromAsn1(r.subjectPublicKeyInfo),i},br.certificateExtensionsFromAsn1=function(e){for(var t=[],r=0;r<e.value.length;++r)for(var a=e.value[r],n=0;n<a.value.length;++n)t.push(br.certificateExtensionFromAsn1(a.value[n]));return t},br.certificateExtensionFromAsn1=function(e){var t={};if(t.id=Sr.derToOid(e.value[0].value),t.critical=!1,e.value[1].type===Sr.Type.BOOLEAN?(t.critical=0!==e.value[1].value.charCodeAt(0),t.value=e.value[2].value):t.value=e.value[1].value,t.id in Tr)if(t.name=Tr[t.id],"keyUsage"===t.name){var r=0,a=0;(i=Sr.fromDer(t.value)).value.length>1&&(r=i.value.charCodeAt(1),a=i.value.length>2?i.value.charCodeAt(2):0),t.digitalSignature=!(128&~r),t.nonRepudiation=!(64&~r),t.keyEncipherment=!(32&~r),t.dataEncipherment=!(16&~r),t.keyAgreement=!(8&~r),t.keyCertSign=!(4&~r),t.cRLSign=!(2&~r),t.encipherOnly=!(1&~r),t.decipherOnly=!(128&~a)}else if("basicConstraints"===t.name){(i=Sr.fromDer(t.value)).value.length>0&&i.value[0].type===Sr.Type.BOOLEAN?t.cA=0!==i.value[0].value.charCodeAt(0):t.cA=!1;var n=null;i.value.length>0&&i.value[0].type===Sr.Type.INTEGER?n=i.value[0].value:i.value.length>1&&(n=i.value[1].value),null!==n&&(t.pathLenConstraint=Sr.derToInteger(n))}else if("extKeyUsage"===t.name)for(var i=Sr.fromDer(t.value),s=0;s<i.value.length;++s){var o=Sr.derToOid(i.value[s].value);o in Tr?t[Tr[o]]=!0:t[o]=!0}else if("nsCertType"===t.name){r=0;(i=Sr.fromDer(t.value)).value.length>1&&(r=i.value.charCodeAt(1)),t.client=!(128&~r),t.server=!(64&~r),t.email=!(32&~r),t.objsign=!(16&~r),t.reserved=!(8&~r),t.sslCA=!(4&~r),t.emailCA=!(2&~r),t.objCA=!(1&~r)}else if("subjectAltName"===t.name||"issuerAltName"===t.name){var c;t.altNames=[];i=Sr.fromDer(t.value);for(var l=0;l<i.value.length;++l){var u={type:(c=i.value[l]).type,value:c.value};switch(t.altNames.push(u),c.type){case 1:case 2:case 6:break;case 7:u.ip=Er.util.bytesToIP(c.value);break;case 8:u.oid=Sr.derToOid(c.value)}}}else if("subjectKeyIdentifier"===t.name){i=Sr.fromDer(t.value);t.subjectKeyIdentifier=Er.util.bytesToHex(i.value)}return t},br.certificationRequestFromAsn1=function(e,t){var r={},a=[];if(!Sr.validate(e,Nr,r,a)){var n=new Error("Cannot read PKCS#10 certificate request. ASN.1 object is not a PKCS#10 CertificationRequest.");throw n.errors=a,n}if(Sr.derToOid(r.publicKeyOid)!==br.oids.rsaEncryption)throw new Error("Cannot read public key. OID is not RSA.");var i=br.createCertificationRequest();if(i.version=r.csrVersion?r.csrVersion.charCodeAt(0):0,i.signatureOid=Er.asn1.derToOid(r.csrSignatureOid),i.signatureParameters=Rr(i.signatureOid,r.csrSignatureParams,!0),i.siginfo.algorithmOid=Er.asn1.derToOid(r.csrSignatureOid),i.siginfo.parameters=Rr(i.siginfo.algorithmOid,r.csrSignatureParams,!1),i.signature=r.csrSignature,i.certificationRequestInfo=r.certificationRequestInfo,t){i.md=Lr({signatureOid:i.signatureOid,type:"certification request"});var s=Sr.toDer(i.certificationRequestInfo);i.md.update(s.getBytes())}var o=Er.md.sha1.create();return i.subject.getField=function(e){return kr(i.subject,e)},i.subject.addField=function(e){Ur([e]),i.subject.attributes.push(e)},i.subject.attributes=br.RDNAttributesAsArray(r.certificationRequestInfoSubject,o),i.subject.hash=o.digest().toHex(),i.publicKey=br.publicKeyFromAsn1(r.subjectPublicKeyInfo),i.getAttribute=function(e){return kr(i,e)},i.addAttribute=function(e){Ur([e]),i.attributes.push(e)},i.attributes=br.CRIAttributesAsArray(r.certificationRequestInfoAttributes||[]),i},br.createCertificationRequest=function(){var e={version:0,signatureOid:null,signature:null,siginfo:{}};return e.siginfo.algorithmOid=null,e.subject={},e.subject.getField=function(t){return kr(e.subject,t)},e.subject.addField=function(t){Ur([t]),e.subject.attributes.push(t)},e.subject.attributes=[],e.subject.hash=null,e.publicKey=null,e.attributes=[],e.getAttribute=function(t){return kr(e,t)},e.addAttribute=function(t){Ur([t]),e.attributes.push(t)},e.md=null,e.setSubject=function(t){Ur(t),e.subject.attributes=t,e.subject.hash=null},e.setAttributes=function(t){Ur(t),e.attributes=t},e.sign=function(t,r){e.md=r||Er.md.sha1.create();var a=Tr[e.md.algorithm+"WithRSAEncryption"];if(!a){var n=new Error("Could not compute certification request digest. Unknown message digest algorithm OID.");throw n.algorithm=e.md.algorithm,n}e.signatureOid=e.siginfo.algorithmOid=a,e.certificationRequestInfo=br.getCertificationRequestInfo(e);var i=Sr.toDer(e.certificationRequestInfo);e.md.update(i.getBytes()),e.signature=t.sign(e.md)},e.verify=function(){var t=!1,r=e.md;if(null===r){r=Lr({signatureOid:e.signatureOid,type:"certification request"});var a=e.certificationRequestInfo||br.getCertificationRequestInfo(e),n=Sr.toDer(a);r.update(n.getBytes())}return null!==r&&(t=_r({certificate:e,md:r,signature:e.signature})),t},e};var Kr=new Date("1950-01-01T00:00:00Z"),Mr=new Date("2050-01-01T00:00:00Z");function Fr(e){return e>=Kr&&e<Mr?Sr.create(Sr.Class.UNIVERSAL,Sr.Type.UTCTIME,!1,Sr.dateToUtcTime(e)):Sr.create(Sr.Class.UNIVERSAL,Sr.Type.GENERALIZEDTIME,!1,Sr.dateToGeneralizedTime(e))}br.getTBSCertificate=function(e){var t=Fr(e.validity.notBefore),r=Fr(e.validity.notAfter),a=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.CONTEXT_SPECIFIC,0,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.INTEGER,!1,Sr.integerToDer(e.version).getBytes())]),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.INTEGER,!1,Er.util.hexToBytes(e.serialNumber)),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(e.siginfo.algorithmOid).getBytes()),Vr(e.siginfo.algorithmOid,e.siginfo.parameters)]),Dr(e.issuer),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[t,r]),Dr(e.subject),br.publicKeyToAsn1(e.publicKey)]);return e.issuer.uniqueId&&a.value.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,1,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.BITSTRING,!1,String.fromCharCode(0)+e.issuer.uniqueId)])),e.subject.uniqueId&&a.value.push(Sr.create(Sr.Class.CONTEXT_SPECIFIC,2,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.BITSTRING,!1,String.fromCharCode(0)+e.subject.uniqueId)])),e.extensions.length>0&&a.value.push(br.certificateExtensionsToAsn1(e.extensions)),a},br.getCertificationRequestInfo=function(e){return Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.INTEGER,!1,Sr.integerToDer(e.version).getBytes()),Dr(e.subject),br.publicKeyToAsn1(e.publicKey),Or(e)])},br.distinguishedNameToAsn1=function(e){return Dr(e)},br.certificateToAsn1=function(e){var t=e.tbsCertificate||br.getTBSCertificate(e);return Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[t,Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(e.signatureOid).getBytes()),Vr(e.signatureOid,e.signatureParameters)]),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},br.certificateExtensionsToAsn1=function(e){var t=Sr.create(Sr.Class.CONTEXT_SPECIFIC,3,!0,[]),r=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]);t.value.push(r);for(var a=0;a<e.length;++a)r.value.push(br.certificateExtensionToAsn1(e[a]));return t},br.certificateExtensionToAsn1=function(e){var t=Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[]);t.value.push(Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(e.id).getBytes())),e.critical&&t.value.push(Sr.create(Sr.Class.UNIVERSAL,Sr.Type.BOOLEAN,!1,String.fromCharCode(255)));var r=e.value;return"string"!=typeof e.value&&(r=Sr.toDer(r).getBytes()),t.value.push(Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OCTETSTRING,!1,r)),t},br.certificationRequestToAsn1=function(e){var t=e.certificationRequestInfo||br.getCertificationRequestInfo(e);return Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[t,Sr.create(Sr.Class.UNIVERSAL,Sr.Type.SEQUENCE,!0,[Sr.create(Sr.Class.UNIVERSAL,Sr.Type.OID,!1,Sr.oidToDer(e.signatureOid).getBytes()),Vr(e.signatureOid,e.signatureParameters)]),Sr.create(Sr.Class.UNIVERSAL,Sr.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},br.createCaStore=function(e){var t={certs:{}};function r(e){return a(e),t.certs[e.hash]||null}function a(e){if(!e.hash){var t=Er.md.sha1.create();e.attributes=br.RDNAttributesAsArray(Dr(e),t),e.hash=t.digest().toHex()}}if(t.getIssuer=function(e){return r(e.issuer)},t.addCertificate=function(e){if("string"==typeof e&&(e=Er.pki.certificateFromPem(e)),a(e.subject),!t.hasCertificate(e))if(e.subject.hash in t.certs){var r=t.certs[e.subject.hash];Er.util.isArray(r)||(r=[r]),r.push(e),t.certs[e.subject.hash]=r}else t.certs[e.subject.hash]=e},t.hasCertificate=function(e){"string"==typeof e&&(e=Er.pki.certificateFromPem(e));var t=r(e.subject);if(!t)return!1;Er.util.isArray(t)||(t=[t]);for(var a=Sr.toDer(br.certificateToAsn1(e)).getBytes(),n=0;n<t.length;++n){if(a===Sr.toDer(br.certificateToAsn1(t[n])).getBytes())return!0}return!1},t.listAllCertificates=function(){var e=[];for(var r in t.certs)if(t.certs.hasOwnProperty(r)){var a=t.certs[r];if(Er.util.isArray(a))for(var n=0;n<a.length;++n)e.push(a[n]);else e.push(a)}return e},t.removeCertificate=function(e){var n;if("string"==typeof e&&(e=Er.pki.certificateFromPem(e)),a(e.subject),!t.hasCertificate(e))return null;var i=r(e.subject);if(!Er.util.isArray(i))return n=t.certs[e.subject.hash],delete t.certs[e.subject.hash],n;for(var s=Sr.toDer(br.certificateToAsn1(e)).getBytes(),o=0;o<i.length;++o){s===Sr.toDer(br.certificateToAsn1(i[o])).getBytes()&&(n=i[o],i.splice(o,1))}return 0===i.length&&delete t.certs[e.subject.hash],n},e)for(var n=0;n<e.length;++n){var i=e[n];t.addCertificate(i)}return t},br.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"},br.verifyCertificateChain=function(e,t,r){"function"==typeof r&&(r={verify:r}),r=r||{};var a=(t=t.slice(0)).slice(0),n=r.validityCheckDate;void 0===n&&(n=new Date);var i=!0,s=null,o=0;do{var c=t.shift(),l=null,u=!1;if(n&&(n<c.validity.notBefore||n>c.validity.notAfter)&&(s={message:"Certificate is not valid yet or has expired.",error:br.certificateError.certificate_expired,notBefore:c.validity.notBefore,notAfter:c.validity.notAfter,now:n}),null===s){if(null===(l=t[0]||e.getIssuer(c))&&c.isIssuer(c)&&(u=!0,l=c),l){var p=l;Er.util.isArray(p)||(p=[p]);for(var d=!1;!d&&p.length>0;){l=p.shift();try{d=l.verify(c)}catch(e){}}d||(s={message:"Certificate signature is invalid.",error:br.certificateError.bad_certificate})}null!==s||l&&!u||e.hasCertificate(c)||(s={message:"Certificate is not trusted.",error:br.certificateError.unknown_ca})}if(null===s&&l&&!c.isIssuer(l)&&(s={message:"Certificate issuer is invalid.",error:br.certificateError.bad_certificate}),null===s)for(var h={keyUsage:!0,basicConstraints:!0},f=0;null===s&&f<c.extensions.length;++f){var y=c.extensions[f];y.critical&&!(y.name in h)&&(s={message:"Certificate has an unsupported critical extension.",error:br.certificateError.unsupported_certificate})}if(null===s&&(!i||0===t.length&&(!l||u))){var g=c.getExtension("basicConstraints"),v=c.getExtension("keyUsage");if(null!==v&&(v.keyCertSign&&null!==g||(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:br.certificateError.bad_certificate})),null!==s||null===g||g.cA||(s={message:"Certificate basicConstraints indicates the certificate is not a CA.",error:br.certificateError.bad_certificate}),null===s&&null!==v&&"pathLenConstraint"in g)o-1>g.pathLenConstraint&&(s={message:"Certificate basicConstraints pathLenConstraint violated.",error:br.certificateError.bad_certificate})}var m=null===s||s.error,C=r.verify?r.verify(m,o,a):m;if(!0!==C)throw!0===m&&(s={message:"The application rejected the certificate.",error:br.certificateError.bad_certificate}),(C||0===C)&&("object"!=typeof C||Er.util.isArray(C)?"string"==typeof C&&(s.error=C):(C.message&&(s.message=C.message),C.error&&(s.error=C.error))),s;s=null,i=!1,++o}while(t.length>0);return!0};var qr=f,jr=qr.asn1,Hr=qr.pki,Gr=qr.pkcs12=qr.pkcs12||{},zr={name:"ContentInfo",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SEQUENCE,constructed:!0,value:[{name:"ContentInfo.contentType",tagClass:jr.Class.UNIVERSAL,type:jr.Type.OID,constructed:!1,capture:"contentType"},{name:"ContentInfo.content",tagClass:jr.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:"content"}]},Qr={name:"PFX",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.version",tagClass:jr.Class.UNIVERSAL,type:jr.Type.INTEGER,constructed:!1,capture:"version"},zr,{name:"PFX.macData",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"mac",value:[{name:"PFX.macData.mac",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.macData.mac.digestAlgorithm",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.macData.mac.digestAlgorithm.algorithm",tagClass:jr.Class.UNIVERSAL,type:jr.Type.OID,constructed:!1,capture:"macAlgorithm"},{name:"PFX.macData.mac.digestAlgorithm.parameters",optional:!0,tagClass:jr.Class.UNIVERSAL,captureAsn1:"macAlgorithmParameters"}]},{name:"PFX.macData.mac.digest",tagClass:jr.Class.UNIVERSAL,type:jr.Type.OCTETSTRING,constructed:!1,capture:"macDigest"}]},{name:"PFX.macData.macSalt",tagClass:jr.Class.UNIVERSAL,type:jr.Type.OCTETSTRING,constructed:!1,capture:"macSalt"},{name:"PFX.macData.iterations",tagClass:jr.Class.UNIVERSAL,type:jr.Type.INTEGER,constructed:!1,optional:!0,capture:"macIterations"}]}]},Yr={name:"SafeBag",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SEQUENCE,constructed:!0,value:[{name:"SafeBag.bagId",tagClass:jr.Class.UNIVERSAL,type:jr.Type.OID,constructed:!1,capture:"bagId"},{name:"SafeBag.bagValue",tagClass:jr.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:"bagValue"},{name:"SafeBag.bagAttributes",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SET,constructed:!0,optional:!0,capture:"bagAttributes"}]},Xr={name:"Attribute",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SEQUENCE,constructed:!0,value:[{name:"Attribute.attrId",tagClass:jr.Class.UNIVERSAL,type:jr.Type.OID,constructed:!1,capture:"oid"},{name:"Attribute.attrValues",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SET,constructed:!0,capture:"values"}]},Wr={name:"CertBag",tagClass:jr.Class.UNIVERSAL,type:jr.Type.SEQUENCE,constructed:!0,value:[{name:"CertBag.certId",tagClass:jr.Class.UNIVERSAL,type:jr.Type.OID,constructed:!1,capture:"certId"},{name:"CertBag.certValue",tagClass:jr.Class.CONTEXT_SPECIFIC,constructed:!0,value:[{name:"CertBag.certValue[0]",tagClass:jr.Class.UNIVERSAL,type:jr.Class.OCTETSTRING,constructed:!1,capture:"cert"}]}]};function $r(e,t,r,a){for(var n=[],i=0;i<e.length;i++)for(var s=0;s<e[i].safeBags.length;s++){var o=e[i].safeBags[s];void 0!==a&&o.type!==a||(null!==t?void 0!==o.attributes[t]&&o.attributes[t].indexOf(r)>=0&&n.push(o):n.push(o))}return n}function Zr(e){if(e.composed||e.constructed){for(var t=qr.util.createBuffer(),r=0;r<e.value.length;++r)t.putBytes(e.value[r].value);e.composed=e.constructed=!1,e.value=t.getBytes()}return e}function Jr(e,t){var r={},a=[];if(!jr.validate(e,qr.pkcs7.asn1.encryptedDataValidator,r,a))throw(n=new Error("Cannot read EncryptedContentInfo.")).errors=a,n;var n,i=jr.derToOid(r.contentType);if(i!==Hr.oids.data)throw(n=new Error("PKCS#12 EncryptedContentInfo ContentType is not Data.")).oid=i,n;i=jr.derToOid(r.encAlgorithm);var s=Hr.pbe.getCipher(i,r.encParameter,t),o=Zr(r.encryptedContentAsn1),c=qr.util.createBuffer(o.value);if(s.update(c),!s.finish())throw new Error("Failed to decrypt PKCS#12 SafeContents.");return s.output.getBytes()}function ea(e,t,r){if(!t&&0===e.length)return[];if((e=jr.fromDer(e,t)).tagClass!==jr.Class.UNIVERSAL||e.type!==jr.Type.SEQUENCE||!0!==e.constructed)throw new Error("PKCS#12 SafeContents expected to be a SEQUENCE OF SafeBag.");for(var a=[],n=0;n<e.value.length;n++){var i=e.value[n],s={},o=[];if(!jr.validate(i,Yr,s,o))throw(d=new Error("Cannot read SafeBag.")).errors=o,d;var c,l,u={type:jr.derToOid(s.bagId),attributes:ta(s.bagAttributes)};a.push(u);var p=s.bagValue.value[0];switch(u.type){case Hr.oids.pkcs8ShroudedKeyBag:if(null===(p=Hr.decryptPrivateKeyInfo(p,r)))throw new Error("Unable to decrypt PKCS#8 ShroudedKeyBag, wrong password?");case Hr.oids.keyBag:try{u.key=Hr.privateKeyFromAsn1(p)}catch(e){u.key=null,u.asn1=p}continue;case Hr.oids.certBag:c=Wr,l=function(){if(jr.derToOid(s.certId)!==Hr.oids.x509Certificate){var e=new Error("Unsupported certificate type, only X.509 supported.");throw e.oid=jr.derToOid(s.certId),e}var r=jr.fromDer(s.cert,t);try{u.cert=Hr.certificateFromAsn1(r,!0)}catch(e){u.cert=null,u.asn1=r}};break;default:var d;throw(d=new Error("Unsupported PKCS#12 SafeBag type.")).oid=u.type,d}if(void 0!==c&&!jr.validate(p,c,s,o))throw(d=new Error("Cannot read PKCS#12 "+c.name)).errors=o,d;l()}return a}function ta(e){var t={};if(void 0!==e)for(var r=0;r<e.length;++r){var a={},n=[];if(!jr.validate(e[r],Xr,a,n)){var i=new Error("Cannot read PKCS#12 BagAttribute.");throw i.errors=n,i}var s=jr.derToOid(a.oid);if(void 0!==Hr.oids[s]){t[Hr.oids[s]]=[];for(var o=0;o<a.values.length;++o)t[Hr.oids[s]].push(a.values[o].value)}}return t}Gr.pkcs12FromAsn1=function(e,t,r){"string"==typeof t?(r=t,t=!0):void 0===t&&(t=!0);var a={};if(!jr.validate(e,Qr,a,[]))throw(n=new Error("Cannot read PKCS#12 PFX. ASN.1 object is not an PKCS#12 PFX.")).errors=n,n;var n,i={version:a.version.charCodeAt(0),safeContents:[],getBags:function(e){var t,r={};return"localKeyId"in e?t=e.localKeyId:"localKeyIdHex"in e&&(t=qr.util.hexToBytes(e.localKeyIdHex)),void 0===t&&!("friendlyName"in e)&&"bagType"in e&&(r[e.bagType]=$r(i.safeContents,null,null,e.bagType)),void 0!==t&&(r.localKeyId=$r(i.safeContents,"localKeyId",t,e.bagType)),"friendlyName"in e&&(r.friendlyName=$r(i.safeContents,"friendlyName",e.friendlyName,e.bagType)),r},getBagsByFriendlyName:function(e,t){return $r(i.safeContents,"friendlyName",e,t)},getBagsByLocalKeyId:function(e,t){return $r(i.safeContents,"localKeyId",e,t)}};if(3!==a.version.charCodeAt(0))throw(n=new Error("PKCS#12 PFX of version other than 3 not supported.")).version=a.version.charCodeAt(0),n;if(jr.derToOid(a.contentType)!==Hr.oids.data)throw(n=new Error("Only PKCS#12 PFX in password integrity mode supported.")).oid=jr.derToOid(a.contentType),n;var s=a.content.value[0];if(s.tagClass!==jr.Class.UNIVERSAL||s.type!==jr.Type.OCTETSTRING)throw new Error("PKCS#12 authSafe content data is not an OCTET STRING.");if(s=Zr(s),a.mac){var o=null,c=0,l=jr.derToOid(a.macAlgorithm);switch(l){case Hr.oids.sha1:o=qr.md.sha1.create(),c=20;break;case Hr.oids.sha256:o=qr.md.sha256.create(),c=32;break;case Hr.oids.sha384:o=qr.md.sha384.create(),c=48;break;case Hr.oids.sha512:o=qr.md.sha512.create(),c=64;break;case Hr.oids.md5:o=qr.md.md5.create(),c=16}if(null===o)throw new Error("PKCS#12 uses unsupported MAC algorithm: "+l);var u=new qr.util.ByteBuffer(a.macSalt),p="macIterations"in a?parseInt(qr.util.bytesToHex(a.macIterations),16):1,d=Gr.generateKey(r,u,3,p,c,o),h=qr.hmac.create();if(h.start(o,d),h.update(s.value),h.getMac().getBytes()!==a.macDigest)throw new Error("PKCS#12 MAC could not be verified. Invalid password?")}else if(Array.isArray(e.value)&&e.value.length>2)throw new Error("Invalid PKCS#12. macData field present but MAC was not validated.");return function(e,t,r,a){if(t=jr.fromDer(t,r),t.tagClass!==jr.Class.UNIVERSAL||t.type!==jr.Type.SEQUENCE||!0!==t.constructed)throw new Error("PKCS#12 AuthenticatedSafe expected to be a SEQUENCE OF ContentInfo");for(var n=0;n<t.value.length;n++){var i=t.value[n],s={},o=[];if(!jr.validate(i,zr,s,o))throw(p=new Error("Cannot read ContentInfo.")).errors=o,p;var c={encrypted:!1},l=null,u=s.content.value[0];switch(jr.derToOid(s.contentType)){case Hr.oids.data:if(u.tagClass!==jr.Class.UNIVERSAL||u.type!==jr.Type.OCTETSTRING)throw new Error("PKCS#12 SafeContents Data is not an OCTET STRING.");l=Zr(u).value;break;case Hr.oids.encryptedData:l=Jr(u,a),c.encrypted=!0;break;default:var p;throw(p=new Error("Unsupported PKCS#12 contentType.")).contentType=jr.derToOid(s.contentType),p}c.safeBags=ea(l,r,a),e.safeContents.push(c)}}(i,s.value,t,r),i},Gr.toPkcs12Asn1=function(e,t,r,a){(a=a||{}).saltSize=a.saltSize||8,a.count=a.count||2048,a.algorithm=a.algorithm||a.encAlgorithm||"aes128","useMac"in a||(a.useMac=!0),"localKeyId"in a||(a.localKeyId=null),"generateLocalKeyId"in a||(a.generateLocalKeyId=!0);var n,i=a.localKeyId;if(null!==i)i=qr.util.hexToBytes(i);else if(a.generateLocalKeyId)if(t){var s=qr.util.isArray(t)?t[0]:t;"string"==typeof s&&(s=Hr.certificateFromPem(s)),(T=qr.md.sha1.create()).update(jr.toDer(Hr.certificateToAsn1(s)).getBytes()),i=T.digest().getBytes()}else i=qr.random.getBytes(20);var o=[];null!==i&&o.push(jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.localKeyId).getBytes()),jr.create(jr.Class.UNIVERSAL,jr.Type.SET,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OCTETSTRING,!1,i)])])),"friendlyName"in a&&o.push(jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.friendlyName).getBytes()),jr.create(jr.Class.UNIVERSAL,jr.Type.SET,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.BMPSTRING,!1,a.friendlyName)])])),o.length>0&&(n=jr.create(jr.Class.UNIVERSAL,jr.Type.SET,!0,o));var c=[],l=[];null!==t&&(l=qr.util.isArray(t)?t:[t]);for(var u=[],p=0;p<l.length;++p){"string"==typeof(t=l[p])&&(t=Hr.certificateFromPem(t));var d=0===p?n:void 0,h=Hr.certificateToAsn1(t),f=jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.certBag).getBytes()),jr.create(jr.Class.CONTEXT_SPECIFIC,0,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.x509Certificate).getBytes()),jr.create(jr.Class.CONTEXT_SPECIFIC,0,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OCTETSTRING,!1,jr.toDer(h).getBytes())])])]),d]);u.push(f)}if(u.length>0){var y=jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,u),g=jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.data).getBytes()),jr.create(jr.Class.CONTEXT_SPECIFIC,0,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OCTETSTRING,!1,jr.toDer(y).getBytes())])]);c.push(g)}var v=null;if(null!==e){var m=Hr.wrapRsaPrivateKey(Hr.privateKeyToAsn1(e));v=null===r?jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.keyBag).getBytes()),jr.create(jr.Class.CONTEXT_SPECIFIC,0,!0,[m]),n]):jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.pkcs8ShroudedKeyBag).getBytes()),jr.create(jr.Class.CONTEXT_SPECIFIC,0,!0,[Hr.encryptPrivateKeyInfo(m,r,a)]),n]);var C=jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[v]),E=jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.data).getBytes()),jr.create(jr.Class.CONTEXT_SPECIFIC,0,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OCTETSTRING,!1,jr.toDer(C).getBytes())])]);c.push(E)}var S,b=jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,c);if(a.useMac){var T=qr.md.sha1.create(),I=new qr.util.ByteBuffer(qr.random.getBytes(a.saltSize)),A=a.count,B=(e=Gr.generateKey(r,I,3,A,20),qr.hmac.create());B.start(T,e),B.update(jr.toDer(b).getBytes());var x=B.getMac();S=jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.sha1).getBytes()),jr.create(jr.Class.UNIVERSAL,jr.Type.NULL,!1,"")]),jr.create(jr.Class.UNIVERSAL,jr.Type.OCTETSTRING,!1,x.getBytes())]),jr.create(jr.Class.UNIVERSAL,jr.Type.OCTETSTRING,!1,I.getBytes()),jr.create(jr.Class.UNIVERSAL,jr.Type.INTEGER,!1,jr.integerToDer(A).getBytes())])}return jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.INTEGER,!1,jr.integerToDer(3).getBytes()),jr.create(jr.Class.UNIVERSAL,jr.Type.SEQUENCE,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OID,!1,jr.oidToDer(Hr.oids.data).getBytes()),jr.create(jr.Class.CONTEXT_SPECIFIC,0,!0,[jr.create(jr.Class.UNIVERSAL,jr.Type.OCTETSTRING,!1,jr.toDer(b).getBytes())])]),S])},Gr.generateKey=qr.pbe.generatePkcs12Key;var ra=f,aa=ra.asn1,na=ra.pki=ra.pki||{};na.pemToDer=function(e){var t=ra.pem.decode(e)[0];if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert PEM to DER; PEM is encrypted.");return ra.util.createBuffer(t.body)},na.privateKeyFromPem=function(e){var t=ra.pem.decode(e)[0];if("PRIVATE KEY"!==t.type&&"RSA PRIVATE KEY"!==t.type){var r=new Error('Could not convert private key from PEM; PEM header type is not "PRIVATE KEY" or "RSA PRIVATE KEY".');throw r.headerType=t.type,r}if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert private key from PEM; PEM is encrypted.");var a=aa.fromDer(t.body);return na.privateKeyFromAsn1(a)},na.privateKeyToPem=function(e,t){var r={type:"RSA PRIVATE KEY",body:aa.toDer(na.privateKeyToAsn1(e)).getBytes()};return ra.pem.encode(r,{maxline:t})},na.privateKeyInfoToPem=function(e,t){var r={type:"PRIVATE KEY",body:aa.toDer(e).getBytes()};return ra.pem.encode(r,{maxline:t})};var ia=f,sa=function(e,t,r,a){var n=ia.util.createBuffer(),i=e.length>>1,s=i+(1&e.length),o=e.substr(0,s),c=e.substr(i,s),l=ia.util.createBuffer(),u=ia.hmac.create();r=t+r;var p=Math.ceil(a/16),d=Math.ceil(a/20);u.start("MD5",o);var h=ia.util.createBuffer();l.putBytes(r);for(var f=0;f<p;++f)u.start(null,null),u.update(l.getBytes()),l.putBuffer(u.digest()),u.start(null,null),u.update(l.bytes()+r),h.putBuffer(u.digest());u.start("SHA1",c);var y=ia.util.createBuffer();l.clear(),l.putBytes(r);for(f=0;f<d;++f)u.start(null,null),u.update(l.getBytes()),l.putBuffer(u.digest()),u.start(null,null),u.update(l.bytes()+r),y.putBuffer(u.digest());return n.putBytes(ia.util.xorBytes(h.getBytes(),y.getBytes(),a)),n},oa=function(e,t,r){var a=!1;try{var n=e.deflate(t.fragment.getBytes());t.fragment=ia.util.createBuffer(n),t.length=n.length,a=!0}catch(e){}return a},ca=function(e,t,r){var a=!1;try{var n=e.inflate(t.fragment.getBytes());t.fragment=ia.util.createBuffer(n),t.length=n.length,a=!0}catch(e){}return a},la=function(e,t){var r=0;switch(t){case 1:r=e.getByte();break;case 2:r=e.getInt16();break;case 3:r=e.getInt24();break;case 4:r=e.getInt32()}return ia.util.createBuffer(e.getBytes(r))},ua=function(e,t,r){e.putInt(r.length(),t<<3),e.putBuffer(r)},pa={Versions:{TLS_1_0:{major:3,minor:1},TLS_1_1:{major:3,minor:2},TLS_1_2:{major:3,minor:3}}};pa.SupportedVersions=[pa.Versions.TLS_1_1,pa.Versions.TLS_1_0],pa.Version=pa.SupportedVersions[0],pa.MaxFragment=15360,pa.ConnectionEnd={server:0,client:1},pa.PRFAlgorithm={tls_prf_sha256:0},pa.BulkCipherAlgorithm={none:null,rc4:0,des3:1,aes:2},pa.CipherType={stream:0,block:1,aead:2},pa.MACAlgorithm={none:null,hmac_md5:0,hmac_sha1:1,hmac_sha256:2,hmac_sha384:3,hmac_sha512:4},pa.CompressionMethod={none:0,deflate:1},pa.ContentType={change_cipher_spec:20,alert:21,handshake:22,application_data:23,heartbeat:24},pa.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},pa.Alert={},pa.Alert.Level={warning:1,fatal:2},pa.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},pa.HeartbeatMessageType={heartbeat_request:1,heartbeat_response:2},pa.CipherSuites={},pa.getCipherSuite=function(e){var t=null;for(var r in pa.CipherSuites){var a=pa.CipherSuites[r];if(a.id[0]===e.charCodeAt(0)&&a.id[1]===e.charCodeAt(1)){t=a;break}}return t},pa.handleUnexpected=function(e,t){!e.open&&e.entity===pa.ConnectionEnd.client||e.error(e,{message:"Unexpected message. Received TLS record out of order.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.unexpected_message}})},pa.handleHelloRequest=function(e,t,r){!e.handshaking&&e.handshakes>0&&(pa.queue(e,pa.createAlert(e,{level:pa.Alert.Level.warning,description:pa.Alert.Description.no_renegotiation})),pa.flush(e)),e.process()},pa.parseHelloMessage=function(e,t,r){var a=null,n=e.entity===pa.ConnectionEnd.client;if(r<38)e.error(e,{message:n?"Invalid ServerHello message. Message too short.":"Invalid ClientHello message. Message too short.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.illegal_parameter}});else{var i=t.fragment,s=i.length();if(a={version:{major:i.getByte(),minor:i.getByte()},random:ia.util.createBuffer(i.getBytes(32)),session_id:la(i,1),extensions:[]},n?(a.cipher_suite=i.getBytes(2),a.compression_method=i.getByte()):(a.cipher_suites=la(i,2),a.compression_methods=la(i,1)),(s=r-(s-i.length()))>0){for(var o=la(i,2);o.length()>0;)a.extensions.push({type:[o.getByte(),o.getByte()],data:la(o,2)});if(!n)for(var c=0;c<a.extensions.length;++c){var l=a.extensions[c];if(0===l.type[0]&&0===l.type[1])for(var u=la(l.data,2);u.length()>0;){if(0!==u.getByte())break;e.session.extensions.server_name.serverNameList.push(la(u,2).getBytes())}}}if(e.session.version&&(a.version.major!==e.session.version.major||a.version.minor!==e.session.version.minor))return e.error(e,{message:"TLS version change is disallowed during renegotiation.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.protocol_version}});if(n)e.session.cipherSuite=pa.getCipherSuite(a.cipher_suite);else for(var p=ia.util.createBuffer(a.cipher_suites.bytes());p.length()>0&&(e.session.cipherSuite=pa.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:pa.Alert.Level.fatal,description:pa.Alert.Description.handshake_failure},cipherSuite:ia.util.bytesToHex(a.cipher_suite)});e.session.compressionMethod=n?a.compression_method:pa.CompressionMethod.none}return a},pa.createSecurityParameters=function(e,t){var r=e.entity===pa.ConnectionEnd.client,a=t.random.bytes(),n=r?e.session.sp.client_random:a,i=r?a:pa.createRandom().getBytes();e.session.sp={entity:e.entity,prf_algorithm:pa.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:n,server_random:i}},pa.handleServerHello=function(e,t,r){var a=pa.parseHelloMessage(e,t,r);if(!e.fail){if(!(a.version.minor<=e.version.minor))return e.error(e,{message:"Incompatible TLS version.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.protocol_version}});e.version.minor=a.version.minor,e.session.version=e.version;var n=a.session_id.bytes();n.length>0&&n===e.session.id?(e.expect=ga,e.session.resuming=!0,e.session.sp.server_random=a.random.bytes()):(e.expect=da,e.session.resuming=!1,pa.createSecurityParameters(e,a)),e.session.id=n,e.process()}},pa.handleClientHello=function(e,t,r){var a=pa.parseHelloMessage(e,t,r);if(!e.fail){var n=a.session_id.bytes(),i=null;if(e.sessionCache&&(null===(i=e.sessionCache.getSession(n))?n="":(i.version.major!==a.version.major||i.version.minor>a.version.minor)&&(i=null,n="")),0===n.length&&(n=ia.random.getBytes(32)),e.session.id=n,e.session.clientHelloVersion=a.version,e.session.sp={},i)e.version=e.session.version=i.version,e.session.sp=i.sp;else{for(var s,o=1;o<pa.SupportedVersions.length&&!((s=pa.SupportedVersions[o]).minor<=a.version.minor);++o);e.version={major:s.major,minor:s.minor},e.session.version=e.version}null!==i?(e.expect=Ta,e.session.resuming=!0,e.session.sp.client_random=a.random.bytes()):(e.expect=!1!==e.verifyClient?Ea:Sa,e.session.resuming=!1,pa.createSecurityParameters(e,a)),e.open=!0,pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createServerHello(e)})),e.session.resuming?(pa.queue(e,pa.createRecord(e,{type:pa.ContentType.change_cipher_spec,data:pa.createChangeCipherSpec()})),e.state.pending=pa.createConnectionState(e),e.state.current.write=e.state.pending.write,pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createFinished(e)}))):(pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createCertificate(e)})),e.fail||(pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createServerKeyExchange(e)})),!1!==e.verifyClient&&pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createCertificateRequest(e)})),pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createServerHelloDone(e)})))),pa.flush(e),e.process()}},pa.handleCertificate=function(e,t,r){if(r<3)return e.error(e,{message:"Invalid Certificate message. Message too short.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.illegal_parameter}});var a,n,i=t.fragment,s={certificate_list:la(i,3)},o=[];try{for(;s.certificate_list.length()>0;)a=la(s.certificate_list,3),n=ia.asn1.fromDer(a),a=ia.pki.certificateFromAsn1(n,!0),o.push(a)}catch(t){return e.error(e,{message:"Could not parse certificate list.",cause:t,send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.bad_certificate}})}var c=e.entity===pa.ConnectionEnd.client;!c&&!0!==e.verifyClient||0!==o.length?0===o.length?e.expect=c?ha:Sa:(c?e.session.serverCertificate=o[0]:e.session.clientCertificate=o[0],pa.verifyCertificateChain(e,o)&&(e.expect=c?ha:Sa)):e.error(e,{message:c?"No server certificate provided.":"No client certificate provided.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.illegal_parameter}}),e.process()},pa.handleServerKeyExchange=function(e,t,r){if(r>0)return e.error(e,{message:"Invalid key parameters. Only RSA is supported.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.unsupported_certificate}});e.expect=fa,e.process()},pa.handleClientKeyExchange=function(e,t,r){if(r<48)return e.error(e,{message:"Invalid key parameters. Only RSA is supported.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.unsupported_certificate}});var a=t.fragment,n={enc_pre_master_secret:la(a,2).getBytes()},i=null;if(e.getPrivateKey)try{i=e.getPrivateKey(e,e.session.serverCertificate),i=ia.pki.privateKeyFromPem(i)}catch(t){e.error(e,{message:"Could not get private key.",cause:t,send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.internal_error}})}if(null===i)return e.error(e,{message:"No private key set.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.internal_error}});try{var s=e.session.sp;s.pre_master_secret=i.decrypt(n.enc_pre_master_secret);var o=e.session.clientHelloVersion;if(o.major!==s.pre_master_secret.charCodeAt(0)||o.minor!==s.pre_master_secret.charCodeAt(1))throw new Error("TLS version rollback attack detected.")}catch(e){s.pre_master_secret=ia.random.getBytes(48)}e.expect=Ta,null!==e.session.clientCertificate&&(e.expect=ba),e.process()},pa.handleCertificateRequest=function(e,t,r){if(r<3)return e.error(e,{message:"Invalid CertificateRequest. Message too short.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.illegal_parameter}});var a=t.fragment,n={certificate_types:la(a,1),certificate_authorities:la(a,2)};e.session.certificateRequest=n,e.expect=ya,e.process()},pa.handleCertificateVerify=function(e,t,r){if(r<2)return e.error(e,{message:"Invalid CertificateVerify. Message too short.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.illegal_parameter}});var a=t.fragment;a.read-=4;var n=a.bytes();a.read+=4;var i={signature:la(a,2).getBytes()},s=ia.util.createBuffer();s.putBuffer(e.session.md5.digest()),s.putBuffer(e.session.sha1.digest()),s=s.getBytes();try{if(!e.session.clientCertificate.publicKey.verify(s,i.signature,"NONE"))throw new Error("CertificateVerify signature does not match.");e.session.md5.update(n),e.session.sha1.update(n)}catch(t){return e.error(e,{message:"Bad signature in CertificateVerify.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.handshake_failure}})}e.expect=Ta,e.process()},pa.handleServerHelloDone=function(e,t,r){if(r>0)return e.error(e,{message:"Invalid ServerHelloDone message. Invalid length.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.record_overflow}});if(null===e.serverCertificate){var a={message:"No server certificate provided. Not enough security.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.insufficient_security}},n=e.verify(e,a.alert.description,0,[]);if(!0!==n)return(n||0===n)&&("object"!=typeof n||ia.util.isArray(n)?"number"==typeof n&&(a.alert.description=n):(n.message&&(a.message=n.message),n.alert&&(a.alert.description=n.alert))),e.error(e,a)}null!==e.session.certificateRequest&&(t=pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createCertificate(e)}),pa.queue(e,t)),t=pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createClientKeyExchange(e)}),pa.queue(e,t),e.expect=Ca;var i=function(e,t){null!==e.session.certificateRequest&&null!==e.session.clientCertificate&&pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createCertificateVerify(e,t)})),pa.queue(e,pa.createRecord(e,{type:pa.ContentType.change_cipher_spec,data:pa.createChangeCipherSpec()})),e.state.pending=pa.createConnectionState(e),e.state.current.write=e.state.pending.write,pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createFinished(e)})),e.expect=ga,pa.flush(e),e.process()};if(null===e.session.certificateRequest||null===e.session.clientCertificate)return i(e,null);pa.getClientSignature(e,i)},pa.handleChangeCipherSpec=function(e,t){if(1!==t.fragment.getByte())return e.error(e,{message:"Invalid ChangeCipherSpec message received.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.illegal_parameter}});var r=e.entity===pa.ConnectionEnd.client;(e.session.resuming&&r||!e.session.resuming&&!r)&&(e.state.pending=pa.createConnectionState(e)),e.state.current.read=e.state.pending.read,(!e.session.resuming&&r||e.session.resuming&&!r)&&(e.state.pending=null),e.expect=r?va:Ia,e.process()},pa.handleFinished=function(e,t,r){var a=t.fragment;a.read-=4;var n=a.bytes();a.read+=4;var i=t.fragment.getBytes();(a=ia.util.createBuffer()).putBuffer(e.session.md5.digest()),a.putBuffer(e.session.sha1.digest());var s=e.entity===pa.ConnectionEnd.client,o=s?"server finished":"client finished",c=e.session.sp;if((a=sa(c.master_secret,o,a.getBytes(),12)).getBytes()!==i)return e.error(e,{message:"Invalid verify_data in Finished message.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.decrypt_error}});e.session.md5.update(n),e.session.sha1.update(n),(e.session.resuming&&s||!e.session.resuming&&!s)&&(pa.queue(e,pa.createRecord(e,{type:pa.ContentType.change_cipher_spec,data:pa.createChangeCipherSpec()})),e.state.current.write=e.state.pending.write,e.state.pending=null,pa.queue(e,pa.createRecord(e,{type:pa.ContentType.handshake,data:pa.createFinished(e)}))),e.expect=s?ma:Aa,e.handshaking=!1,++e.handshakes,e.peerCertificate=s?e.session.serverCertificate:e.session.clientCertificate,pa.flush(e),e.isConnected=!0,e.connected(e),e.process()},pa.handleAlert=function(e,t){var r,a=t.fragment,n={level:a.getByte(),description:a.getByte()};switch(n.description){case pa.Alert.Description.close_notify:r="Connection closed.";break;case pa.Alert.Description.unexpected_message:r="Unexpected message.";break;case pa.Alert.Description.bad_record_mac:r="Bad record MAC.";break;case pa.Alert.Description.decryption_failed:r="Decryption failed.";break;case pa.Alert.Description.record_overflow:r="Record overflow.";break;case pa.Alert.Description.decompression_failure:r="Decompression failed.";break;case pa.Alert.Description.handshake_failure:r="Handshake failure.";break;case pa.Alert.Description.bad_certificate:r="Bad certificate.";break;case pa.Alert.Description.unsupported_certificate:r="Unsupported certificate.";break;case pa.Alert.Description.certificate_revoked:r="Certificate revoked.";break;case pa.Alert.Description.certificate_expired:r="Certificate expired.";break;case pa.Alert.Description.certificate_unknown:r="Certificate unknown.";break;case pa.Alert.Description.illegal_parameter:r="Illegal parameter.";break;case pa.Alert.Description.unknown_ca:r="Unknown certificate authority.";break;case pa.Alert.Description.access_denied:r="Access denied.";break;case pa.Alert.Description.decode_error:r="Decode error.";break;case pa.Alert.Description.decrypt_error:r="Decrypt error.";break;case pa.Alert.Description.export_restriction:r="Export restriction.";break;case pa.Alert.Description.protocol_version:r="Unsupported protocol version.";break;case pa.Alert.Description.insufficient_security:r="Insufficient security.";break;case pa.Alert.Description.internal_error:r="Internal error.";break;case pa.Alert.Description.user_canceled:r="User canceled.";break;case pa.Alert.Description.no_renegotiation:r="Renegotiation not supported.";break;default:r="Unknown error."}if(n.description===pa.Alert.Description.close_notify)return e.close();e.error(e,{message:r,send:!1,origin:e.entity===pa.ConnectionEnd.client?"server":"client",alert:n}),e.process()},pa.handleHandshake=function(e,t){var r=t.fragment,a=r.getByte(),n=r.getInt24();if(n>r.length())return e.fragmented=t,t.fragment=ia.util.createBuffer(),r.read-=4,e.process();e.fragmented=null,r.read-=4;var i=r.bytes(n+4);r.read+=4,a in Ma[e.entity][e.expect]?(e.entity!==pa.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:ia.md.md5.create(),sha1:ia.md.sha1.create()}),a!==pa.HandshakeType.hello_request&&a!==pa.HandshakeType.certificate_verify&&a!==pa.HandshakeType.finished&&(e.session.md5.update(i),e.session.sha1.update(i)),Ma[e.entity][e.expect][a](e,t,n)):pa.handleUnexpected(e,t)},pa.handleApplicationData=function(e,t){e.data.putBuffer(t.fragment),e.dataReady(e),e.process()},pa.handleHeartbeat=function(e,t){var r=t.fragment,a=r.getByte(),n=r.getInt16(),i=r.getBytes(n);if(a===pa.HeartbeatMessageType.heartbeat_request){if(e.handshaking||n>i.length)return e.process();pa.queue(e,pa.createRecord(e,{type:pa.ContentType.heartbeat,data:pa.createHeartbeat(pa.HeartbeatMessageType.heartbeat_response,i)})),pa.flush(e)}else if(a===pa.HeartbeatMessageType.heartbeat_response){if(i!==e.expectedHeartbeatPayload)return e.process();e.heartbeatReceived&&e.heartbeatReceived(e,ia.util.createBuffer(i))}e.process()};var da=1,ha=2,fa=3,ya=4,ga=5,va=6,ma=7,Ca=8,Ea=1,Sa=2,ba=3,Ta=4,Ia=5,Aa=6,Ba=pa.handleUnexpected,xa=pa.handleChangeCipherSpec,wa=pa.handleAlert,Na=pa.handleHandshake,ka=pa.handleApplicationData,Ra=pa.handleHeartbeat,La=[];La[pa.ConnectionEnd.client]=[[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,Ba,Ra],[xa,wa,Ba,Ba,Ra],[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,ka,Ra],[Ba,wa,Na,Ba,Ra]],La[pa.ConnectionEnd.server]=[[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,Ba,Ra],[xa,wa,Ba,Ba,Ra],[Ba,wa,Na,Ba,Ra],[Ba,wa,Na,ka,Ra],[Ba,wa,Na,Ba,Ra]];var _a=pa.handleHelloRequest,Da=pa.handleServerHello,Ua=pa.handleCertificate,Pa=pa.handleServerKeyExchange,Va=pa.handleCertificateRequest,Oa=pa.handleServerHelloDone,Ka=pa.handleFinished,Ma=[];Ma[pa.ConnectionEnd.client]=[[Ba,Ba,Da,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba],[_a,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ua,Pa,Va,Oa,Ba,Ba,Ba,Ba,Ba,Ba],[_a,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Pa,Va,Oa,Ba,Ba,Ba,Ba,Ba,Ba],[_a,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Va,Oa,Ba,Ba,Ba,Ba,Ba,Ba],[_a,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Oa,Ba,Ba,Ba,Ba,Ba,Ba],[_a,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba],[_a,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ka],[_a,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba],[_a,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba]];var Fa=pa.handleClientHello,qa=pa.handleClientKeyExchange,ja=pa.handleCertificateVerify;Ma[pa.ConnectionEnd.server]=[[Ba,Fa,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba],[Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ua,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba],[Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,qa,Ba,Ba,Ba,Ba],[Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,ja,Ba,Ba,Ba,Ba,Ba],[Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba],[Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ka],[Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba],[Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba,Ba]],pa.generateKeys=function(e,t){var r=sa,a=t.client_random+t.server_random;e.session.resuming||(t.master_secret=r(t.pre_master_secret,"master secret",a,48).bytes(),t.pre_master_secret=null),a=t.server_random+t.client_random;var n=2*t.mac_key_length+2*t.enc_key_length,i=e.version.major===pa.Versions.TLS_1_0.major&&e.version.minor===pa.Versions.TLS_1_0.minor;i&&(n+=2*t.fixed_iv_length);var s=r(t.master_secret,"key expansion",a,n),o={client_write_MAC_key:s.getBytes(t.mac_key_length),server_write_MAC_key:s.getBytes(t.mac_key_length),client_write_key:s.getBytes(t.enc_key_length),server_write_key:s.getBytes(t.enc_key_length)};return i&&(o.client_write_IV=s.getBytes(t.fixed_iv_length),o.server_write_IV=s.getBytes(t.fixed_iv_length)),o},pa.createConnectionState=function(e){var t=e.entity===pa.ConnectionEnd.client,r=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},a={read:r(),write:r()};if(a.read.update=function(e,t){return a.read.cipherFunction(t,a.read)?a.read.compressFunction(e,t,a.read)||e.error(e,{message:"Could not decompress record.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.decompression_failure}}):e.error(e,{message:"Could not decrypt record or bad MAC.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.bad_record_mac}}),!e.fail},a.write.update=function(e,t){return a.write.compressFunction(e,t,a.write)?a.write.cipherFunction(t,a.write)||e.error(e,{message:"Could not encrypt record.",send:!1,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.internal_error}}):e.error(e,{message:"Could not compress record.",send:!1,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.internal_error}}),!e.fail},e.session){var n=e.session.sp;switch(e.session.cipherSuite.initSecurityParameters(n),n.keys=pa.generateKeys(e,n),a.read.macKey=t?n.keys.server_write_MAC_key:n.keys.client_write_MAC_key,a.write.macKey=t?n.keys.client_write_MAC_key:n.keys.server_write_MAC_key,e.session.cipherSuite.initConnectionState(a,e,n),n.compression_algorithm){case pa.CompressionMethod.none:break;case pa.CompressionMethod.deflate:a.read.compressFunction=ca,a.write.compressFunction=oa;break;default:throw new Error("Unsupported compression algorithm.")}}return a},pa.createRandom=function(){var e=new Date,t=+e+6e4*e.getTimezoneOffset(),r=ia.util.createBuffer();return r.putInt32(t),r.putBytes(ia.random.getBytes(28)),r},pa.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},pa.createAlert=function(e,t){var r=ia.util.createBuffer();return r.putByte(t.level),r.putByte(t.description),pa.createRecord(e,{type:pa.ContentType.alert,data:r})},pa.createClientHello=function(e){e.session.clientHelloVersion={major:e.version.major,minor:e.version.minor};for(var t=ia.util.createBuffer(),r=0;r<e.cipherSuites.length;++r){var a=e.cipherSuites[r];t.putByte(a.id[0]),t.putByte(a.id[1])}var n=t.length(),i=ia.util.createBuffer();i.putByte(pa.CompressionMethod.none);var s=i.length(),o=ia.util.createBuffer();if(e.virtualHost){var c=ia.util.createBuffer();c.putByte(0),c.putByte(0);var l=ia.util.createBuffer();l.putByte(0),ua(l,2,ia.util.createBuffer(e.virtualHost));var u=ia.util.createBuffer();ua(u,2,l),ua(c,2,u),o.putBuffer(c)}var p=o.length();p>0&&(p+=2);var d=e.session.id,h=d.length+1+2+4+28+2+n+1+s+p,f=ia.util.createBuffer();return f.putByte(pa.HandshakeType.client_hello),f.putInt24(h),f.putByte(e.version.major),f.putByte(e.version.minor),f.putBytes(e.session.sp.client_random),ua(f,1,ia.util.createBuffer(d)),ua(f,2,t),ua(f,1,i),p>0&&ua(f,2,o),f},pa.createServerHello=function(e){var t=e.session.id,r=t.length+1+2+4+28+2+1,a=ia.util.createBuffer();return a.putByte(pa.HandshakeType.server_hello),a.putInt24(r),a.putByte(e.version.major),a.putByte(e.version.minor),a.putBytes(e.session.sp.server_random),ua(a,1,ia.util.createBuffer(t)),a.putByte(e.session.cipherSuite.id[0]),a.putByte(e.session.cipherSuite.id[1]),a.putByte(e.session.compressionMethod),a},pa.createCertificate=function(e){var t,r=e.entity===pa.ConnectionEnd.client,a=null;e.getCertificate&&(t=r?e.session.certificateRequest:e.session.extensions.server_name.serverNameList,a=e.getCertificate(e,t));var n=ia.util.createBuffer();if(null!==a)try{ia.util.isArray(a)||(a=[a]);for(var i=null,s=0;s<a.length;++s){var o=ia.pem.decode(a[s])[0];if("CERTIFICATE"!==o.type&&"X509 CERTIFICATE"!==o.type&&"TRUSTED CERTIFICATE"!==o.type){var c=new Error('Could not convert certificate from PEM; PEM header type is not "CERTIFICATE", "X509 CERTIFICATE", or "TRUSTED CERTIFICATE".');throw c.headerType=o.type,c}if(o.procType&&"ENCRYPTED"===o.procType.type)throw new Error("Could not convert certificate from PEM; PEM is encrypted.");var l=ia.util.createBuffer(o.body);null===i&&(i=ia.asn1.fromDer(l.bytes(),!1));var u=ia.util.createBuffer();ua(u,3,l),n.putBuffer(u)}a=ia.pki.certificateFromAsn1(i),r?e.session.clientCertificate=a:e.session.serverCertificate=a}catch(t){return e.error(e,{message:"Could not send certificate list.",cause:t,send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.bad_certificate}})}var p=3+n.length(),d=ia.util.createBuffer();return d.putByte(pa.HandshakeType.certificate),d.putInt24(p),ua(d,3,n),d},pa.createClientKeyExchange=function(e){var t=ia.util.createBuffer();t.putByte(e.session.clientHelloVersion.major),t.putByte(e.session.clientHelloVersion.minor),t.putBytes(ia.random.getBytes(46));var r=e.session.sp;r.pre_master_secret=t.getBytes();var a=(t=e.session.serverCertificate.publicKey.encrypt(r.pre_master_secret)).length+2,n=ia.util.createBuffer();return n.putByte(pa.HandshakeType.client_key_exchange),n.putInt24(a),n.putInt16(t.length),n.putBytes(t),n},pa.createServerKeyExchange=function(e){return ia.util.createBuffer()},pa.getClientSignature=function(e,t){var r=ia.util.createBuffer();r.putBuffer(e.session.md5.digest()),r.putBuffer(e.session.sha1.digest()),r=r.getBytes(),e.getSignature=e.getSignature||function(e,t,r){var a=null;if(e.getPrivateKey)try{a=e.getPrivateKey(e,e.session.clientCertificate),a=ia.pki.privateKeyFromPem(a)}catch(t){e.error(e,{message:"Could not get private key.",cause:t,send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.internal_error}})}null===a?e.error(e,{message:"No private key set.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.internal_error}}):t=a.sign(t,null),r(e,t)},e.getSignature(e,r,t)},pa.createCertificateVerify=function(e,t){var r=t.length+2,a=ia.util.createBuffer();return a.putByte(pa.HandshakeType.certificate_verify),a.putInt24(r),a.putInt16(t.length),a.putBytes(t),a},pa.createCertificateRequest=function(e){var t=ia.util.createBuffer();t.putByte(1);var r=ia.util.createBuffer();for(var a in e.caStore.certs){var n=e.caStore.certs[a],i=ia.pki.distinguishedNameToAsn1(n.subject),s=ia.asn1.toDer(i);r.putInt16(s.length()),r.putBuffer(s)}var o=1+t.length()+2+r.length(),c=ia.util.createBuffer();return c.putByte(pa.HandshakeType.certificate_request),c.putInt24(o),ua(c,1,t),ua(c,2,r),c},pa.createServerHelloDone=function(e){var t=ia.util.createBuffer();return t.putByte(pa.HandshakeType.server_hello_done),t.putInt24(0),t},pa.createChangeCipherSpec=function(){var e=ia.util.createBuffer();return e.putByte(1),e},pa.createFinished=function(e){var t=ia.util.createBuffer();t.putBuffer(e.session.md5.digest()),t.putBuffer(e.session.sha1.digest());var r=e.entity===pa.ConnectionEnd.client,a=e.session.sp,n=r?"client finished":"server finished";t=sa(a.master_secret,n,t.getBytes(),12);var i=ia.util.createBuffer();return i.putByte(pa.HandshakeType.finished),i.putInt24(t.length()),i.putBuffer(t),i},pa.createHeartbeat=function(e,t,r){void 0===r&&(r=t.length);var a=ia.util.createBuffer();a.putByte(e),a.putInt16(r),a.putBytes(t);var n=a.length(),i=Math.max(16,n-r-3);return a.putBytes(ia.random.getBytes(i)),a},pa.queue=function(e,t){if(t&&(0!==t.fragment.length()||t.type!==pa.ContentType.handshake&&t.type!==pa.ContentType.alert&&t.type!==pa.ContentType.change_cipher_spec)){if(t.type===pa.ContentType.handshake){var r=t.fragment.bytes();e.session.md5.update(r),e.session.sha1.update(r),r=null}var a;if(t.fragment.length()<=pa.MaxFragment)a=[t];else{a=[];for(var n=t.fragment.bytes();n.length>pa.MaxFragment;)a.push(pa.createRecord(e,{type:t.type,data:ia.util.createBuffer(n.slice(0,pa.MaxFragment))})),n=n.slice(pa.MaxFragment);n.length>0&&a.push(pa.createRecord(e,{type:t.type,data:ia.util.createBuffer(n)}))}for(var i=0;i<a.length&&!e.fail;++i){var s=a[i];e.state.current.write.update(e,s)&&e.records.push(s)}}},pa.flush=function(e){for(var t=0;t<e.records.length;++t){var r=e.records[t];e.tlsData.putByte(r.type),e.tlsData.putByte(r.version.major),e.tlsData.putByte(r.version.minor),e.tlsData.putInt16(r.fragment.length()),e.tlsData.putBuffer(e.records[t].fragment)}return e.records=[],e.tlsDataReady(e)};var Ha=function(e){switch(e){case!0:return!0;case ia.pki.certificateError.bad_certificate:return pa.Alert.Description.bad_certificate;case ia.pki.certificateError.unsupported_certificate:return pa.Alert.Description.unsupported_certificate;case ia.pki.certificateError.certificate_revoked:return pa.Alert.Description.certificate_revoked;case ia.pki.certificateError.certificate_expired:return pa.Alert.Description.certificate_expired;case ia.pki.certificateError.certificate_unknown:return pa.Alert.Description.certificate_unknown;case ia.pki.certificateError.unknown_ca:return pa.Alert.Description.unknown_ca;default:return pa.Alert.Description.bad_certificate}};for(var Ga in pa.verifyCertificateChain=function(e,t){try{var r={};for(var a in e.verifyOptions)r[a]=e.verifyOptions[a];r.verify=function(t,r,a){Ha(t);var n=e.verify(e,t,r,a);if(!0!==n){if("object"==typeof n&&!ia.util.isArray(n)){var i=new Error("The application rejected the certificate.");throw i.send=!0,i.alert={level:pa.Alert.Level.fatal,description:pa.Alert.Description.bad_certificate},n.message&&(i.message=n.message),n.alert&&(i.alert.description=n.alert),i}n!==t&&(n=function(e){switch(e){case!0:return!0;case pa.Alert.Description.bad_certificate:return ia.pki.certificateError.bad_certificate;case pa.Alert.Description.unsupported_certificate:return ia.pki.certificateError.unsupported_certificate;case pa.Alert.Description.certificate_revoked:return ia.pki.certificateError.certificate_revoked;case pa.Alert.Description.certificate_expired:return ia.pki.certificateError.certificate_expired;case pa.Alert.Description.certificate_unknown:return ia.pki.certificateError.certificate_unknown;case pa.Alert.Description.unknown_ca:return ia.pki.certificateError.unknown_ca;default:return ia.pki.certificateError.bad_certificate}}(n))}return n},ia.pki.verifyCertificateChain(e.caStore,t,r)}catch(t){var n=t;("object"!=typeof n||ia.util.isArray(n))&&(n={send:!0,alert:{level:pa.Alert.Level.fatal,description:Ha(t)}}),"send"in n||(n.send=!0),"alert"in n||(n.alert={level:pa.Alert.Level.fatal,description:Ha(n.error)}),e.error(e,n)}return!e.fail},pa.createSessionCache=function(e,t){var r=null;if(e&&e.getSession&&e.setSession&&e.order)r=e;else{for(var a in(r={}).cache=e||{},r.capacity=Math.max(t||100,1),r.order=[],e)r.order.length<=t?r.order.push(a):delete e[a];r.getSession=function(e){var t=null,a=null;if(e?a=ia.util.bytesToHex(e):r.order.length>0&&(a=r.order[0]),null!==a&&a in r.cache)for(var n in t=r.cache[a],delete r.cache[a],r.order)if(r.order[n]===a){r.order.splice(n,1);break}return t},r.setSession=function(e,t){if(r.order.length===r.capacity){var a=r.order.shift();delete r.cache[a]}a=ia.util.bytesToHex(e);r.order.push(a),r.cache[a]=t}}return r},pa.createConnection=function(e){var t=null;t=e.caStore?ia.util.isArray(e.caStore)?ia.pki.createCaStore(e.caStore):e.caStore:ia.pki.createCaStore();var r=e.cipherSuites||null;if(null===r)for(var a in r=[],pa.CipherSuites)r.push(pa.CipherSuites[a]);var n=e.server?pa.ConnectionEnd.server:pa.ConnectionEnd.client,i=e.sessionCache?pa.createSessionCache(e.sessionCache):null,s={version:{major:pa.Version.major,minor:pa.Version.minor},entity:n,sessionId:e.sessionId,caStore:t,sessionCache:i,cipherSuites:r,connected:e.connected,virtualHost:e.virtualHost||null,verifyClient:e.verifyClient||!1,verify:e.verify||function(e,t,r,a){return t},verifyOptions:e.verifyOptions||{},getCertificate:e.getCertificate||null,getPrivateKey:e.getPrivateKey||null,getSignature:e.getSignature||null,input:ia.util.createBuffer(),tlsData:ia.util.createBuffer(),data:ia.util.createBuffer(),tlsDataReady:e.tlsDataReady,dataReady:e.dataReady,heartbeatReceived:e.heartbeatReceived,closed:e.closed,error:function(t,r){r.origin=r.origin||(t.entity===pa.ConnectionEnd.client?"client":"server"),r.send&&(pa.queue(t,pa.createAlert(t,r.alert)),pa.flush(t));var a=!1!==r.fatal;a&&(t.fail=!0),e.error(t,r),a&&t.close(!1)},deflate:e.deflate||null,inflate:e.inflate||null,reset:function(e){s.version={major:pa.Version.major,minor:pa.Version.minor},s.record=null,s.session=null,s.peerCertificate=null,s.state={pending:null,current:null},s.expect=(s.entity,pa.ConnectionEnd.client,0),s.fragmented=null,s.records=[],s.open=!1,s.handshakes=0,s.handshaking=!1,s.isConnected=!1,s.fail=!(e||void 0===e),s.input.clear(),s.tlsData.clear(),s.data.clear(),s.state.current=pa.createConnectionState(s)}};s.reset();return s.handshake=function(e){if(s.entity!==pa.ConnectionEnd.client)s.error(s,{message:"Cannot initiate handshake as a server.",fatal:!1});else if(s.handshaking)s.error(s,{message:"Handshake already in progress.",fatal:!1});else{s.fail&&!s.open&&0===s.handshakes&&(s.fail=!1),s.handshaking=!0;var t=null;(e=e||"").length>0&&(s.sessionCache&&(t=s.sessionCache.getSession(e)),null===t&&(e="")),0===e.length&&s.sessionCache&&null!==(t=s.sessionCache.getSession())&&(e=t.id),s.session={id:e,version:null,cipherSuite:null,compressionMethod:null,serverCertificate:null,certificateRequest:null,clientCertificate:null,sp:{},md5:ia.md.md5.create(),sha1:ia.md.sha1.create()},t&&(s.version=t.version,s.session.sp=t.sp),s.session.sp.client_random=pa.createRandom().getBytes(),s.open=!0,pa.queue(s,pa.createRecord(s,{type:pa.ContentType.handshake,data:pa.createClientHello(s)})),pa.flush(s)}},s.process=function(e){var t=0;return e&&s.input.putBytes(e),s.fail||(null!==s.record&&s.record.ready&&s.record.fragment.isEmpty()&&(s.record=null),null===s.record&&(t=function(e){var t=0,r=e.input,a=r.length();if(a<5)t=5-a;else{e.record={type:r.getByte(),version:{major:r.getByte(),minor:r.getByte()},length:r.getInt16(),fragment:ia.util.createBuffer(),ready:!1};var n=e.record.version.major===e.version.major;n&&e.session&&e.session.version&&(n=e.record.version.minor===e.version.minor),n||e.error(e,{message:"Incompatible TLS version.",send:!0,alert:{level:pa.Alert.Level.fatal,description:pa.Alert.Description.protocol_version}})}return t}(s)),s.fail||null===s.record||s.record.ready||(t=function(e){var t=0,r=e.input,a=r.length();return a<e.record.length?t=e.record.length-a:(e.record.fragment.putBytes(r.getBytes(e.record.length)),r.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:pa.Alert.Level.fatal,description:pa.Alert.Description.unexpected_message}})),e.record.ready=!0)),t}(s)),!s.fail&&null!==s.record&&s.record.ready&&function(e,t){var r=t.type-pa.ContentType.change_cipher_spec,a=La[e.entity][e.expect];r in a?a[r](e,t):pa.handleUnexpected(e,t)}(s,s.record)),t},s.prepare=function(e){return pa.queue(s,pa.createRecord(s,{type:pa.ContentType.application_data,data:ia.util.createBuffer(e)})),pa.flush(s)},s.prepareHeartbeatRequest=function(e,t){return e instanceof ia.util.ByteBuffer&&(e=e.bytes()),void 0===t&&(t=e.length),s.expectedHeartbeatPayload=e,pa.queue(s,pa.createRecord(s,{type:pa.ContentType.heartbeat,data:pa.createHeartbeat(pa.HeartbeatMessageType.heartbeat_request,e,t)})),pa.flush(s)},s.close=function(e){if(!s.fail&&s.sessionCache&&s.session){var t={id:s.session.id,version:s.session.version,sp:s.session.sp};t.sp.keys=null,s.sessionCache.setSession(t.id,t)}s.open&&(s.open=!1,s.input.clear(),(s.isConnected||s.handshaking)&&(s.isConnected=s.handshaking=!1,pa.queue(s,pa.createAlert(s,{level:pa.Alert.Level.warning,description:pa.Alert.Description.close_notify})),pa.flush(s)),s.closed(s)),s.reset(e)},s},ia.tls=ia.tls||{},pa)"function"!=typeof pa[Ga]&&(ia.tls[Ga]=pa[Ga]);ia.tls.prf_tls1=sa,ia.tls.hmac_sha1=function(e,t,r){var a=ia.hmac.create();a.start("SHA1",e);var n=ia.util.createBuffer();return n.putInt32(t[0]),n.putInt32(t[1]),n.putByte(r.type),n.putByte(r.version.major),n.putByte(r.version.minor),n.putInt16(r.length),n.putBytes(r.fragment.bytes()),a.update(n.getBytes()),a.digest().getBytes()},ia.tls.createSessionCache=pa.createSessionCache,ia.tls.createConnection=pa.createConnection;var za=f,Qa=za.tls;function Ya(e,t,r){var a=t.entity===za.tls.ConnectionEnd.client;e.read.cipherState={init:!1,cipher:za.cipher.createDecipher("AES-CBC",a?r.keys.server_write_key:r.keys.client_write_key),iv:a?r.keys.server_write_IV:r.keys.client_write_IV},e.write.cipherState={init:!1,cipher:za.cipher.createCipher("AES-CBC",a?r.keys.client_write_key:r.keys.server_write_key),iv:a?r.keys.client_write_IV:r.keys.server_write_IV},e.read.cipherFunction=Za,e.write.cipherFunction=Xa,e.read.macLength=e.write.macLength=r.mac_length,e.read.macFunction=e.write.macFunction=Qa.hmac_sha1}function Xa(e,t){var r,a=!1,n=t.macFunction(t.macKey,t.sequenceNumber,e);e.fragment.putBytes(n),t.updateSequenceNumber(),r=e.version.minor===Qa.Versions.TLS_1_0.minor?t.cipherState.init?null:t.cipherState.iv:za.random.getBytesSync(16),t.cipherState.init=!0;var i=t.cipherState.cipher;return i.start({iv:r}),e.version.minor>=Qa.Versions.TLS_1_1.minor&&i.output.putBytes(r),i.update(e.fragment),i.finish(Wa)&&(e.fragment=i.output,e.length=e.fragment.length(),a=!0),a}function Wa(e,t,r){if(!r){var a=e-t.length()%e;t.fillWithByte(a-1,a)}return!0}function $a(e,t,r){var a=!0;if(r){for(var n=t.length(),i=t.last(),s=n-1-i;s<n-1;++s)a=a&&t.at(s)==i;a&&t.truncate(i+1)}return a}function Za(e,t){var r,a=!1;r=e.version.minor===Qa.Versions.TLS_1_0.minor?t.cipherState.init?null:t.cipherState.iv:e.fragment.getBytes(16),t.cipherState.init=!0;var n=t.cipherState.cipher;n.start({iv:r}),n.update(e.fragment),a=n.finish($a);var i=t.macLength,s=za.random.getBytesSync(i),o=n.output.length();o>=i?(e.fragment=n.output.getBytes(o-i),s=n.output.getBytes(i)):e.fragment=n.output.getBytes(),e.fragment=za.util.createBuffer(e.fragment),e.length=e.fragment.length();var c=t.macFunction(t.macKey,t.sequenceNumber,e);return t.updateSequenceNumber(),a=function(e,t,r){var a=za.hmac.create();return a.start("SHA1",e),a.update(t),t=a.digest().getBytes(),a.start(null,null),a.update(r),r=a.digest().getBytes(),t===r}(t.macKey,s,c)&&a,a}Qa.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=Qa.BulkCipherAlgorithm.aes,e.cipher_type=Qa.CipherType.block,e.enc_key_length=16,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=Qa.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:Ya},Qa.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=Qa.BulkCipherAlgorithm.aes,e.cipher_type=Qa.CipherType.block,e.enc_key_length=32,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=Qa.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:Ya};var Ja=f,en=Ja.sha512=Ja.sha512||{};Ja.md.sha512=Ja.md.algorithms.sha512=en;var tn=Ja.sha384=Ja.sha512.sha384=Ja.sha512.sha384||{};tn.create=function(){return en.create("SHA-384")},Ja.md.sha384=Ja.md.algorithms.sha384=tn,Ja.sha512.sha256=Ja.sha512.sha256||{create:function(){return en.create("SHA-512/256")}},Ja.md["sha512/256"]=Ja.md.algorithms["sha512/256"]=Ja.sha512.sha256,Ja.sha512.sha224=Ja.sha512.sha224||{create:function(){return en.create("SHA-512/224")}},Ja.md["sha512/224"]=Ja.md.algorithms["sha512/224"]=Ja.sha512.sha224,en.create=function(e){if(an||(rn=String.fromCharCode(128),rn+=Ja.util.fillString(String.fromCharCode(0),128),nn=[[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]],(sn={})["SHA-512"]=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]],sn["SHA-384"]=[[3418070365,3238371032],[1654270250,914150663],[2438529370,812702999],[355462360,4144912697],[1731405415,4290775857],[2394180231,1750603025],[3675008525,1694076839],[1203062813,3204075428]],sn["SHA-512/256"]=[[573645204,4230739756],[2673172387,3360449730],[596883563,1867755857],[2520282905,1497426621],[2519219938,2827943907],[3193839141,1401305490],[721525244,746961066],[246885852,2177182882]],sn["SHA-512/224"]=[[2352822216,424955298],[1944164710,2312950998],[502970286,855612546],[1738396948,1479516111],[258812777,2077511080],[2011393907,79989058],[1067287976,1780299464],[286451373,2446758561]],an=!0),void 0===e&&(e="SHA-512"),!(e in sn))throw new Error("Invalid SHA-512 algorithm: "+e);for(var t=sn[e],r=null,a=Ja.util.createBuffer(),n=new Array(80),i=0;i<80;++i)n[i]=new Array(2);var s=64;switch(e){case"SHA-384":s=48;break;case"SHA-512/256":s=32;break;case"SHA-512/224":s=28}var o={algorithm:e.replace("-","").toLowerCase(),blockLength:128,digestLength:s,messageLength:0,fullMessageLength:null,messageLengthSize:16,start:function(){o.messageLength=0,o.fullMessageLength=o.messageLength128=[];for(var e=o.messageLengthSize/4,n=0;n<e;++n)o.fullMessageLength.push(0);a=Ja.util.createBuffer(),r=new Array(t.length);for(n=0;n<t.length;++n)r[n]=t[n].slice(0);return o}};return o.start(),o.update=function(e,t){"utf8"===t&&(e=Ja.util.encodeUtf8(e));var i=e.length;o.messageLength+=i,i=[i/4294967296>>>0,i>>>0];for(var s=o.fullMessageLength.length-1;s>=0;--s)o.fullMessageLength[s]+=i[1],i[1]=i[0]+(o.fullMessageLength[s]/4294967296>>>0),o.fullMessageLength[s]=o.fullMessageLength[s]>>>0,i[0]=i[1]/4294967296>>>0;return a.putBytes(e),on(r,n,a),(a.read>2048||0===a.length())&&a.compact(),o},o.digest=function(){var t=Ja.util.createBuffer();t.putBytes(a.bytes());var i,s=o.fullMessageLength[o.fullMessageLength.length-1]+o.messageLengthSize&o.blockLength-1;t.putBytes(rn.substr(0,o.blockLength-s));for(var c=8*o.fullMessageLength[0],l=0;l<o.fullMessageLength.length-1;++l)c+=(i=8*o.fullMessageLength[l+1])/4294967296>>>0,t.putInt32(c>>>0),c=i>>>0;t.putInt32(c);var u=new Array(r.length);for(l=0;l<r.length;++l)u[l]=r[l].slice(0);on(u,n,t);var p,d=Ja.util.createBuffer();p="SHA-512"===e?u.length:"SHA-384"===e?u.length-2:u.length-4;for(l=0;l<p;++l)d.putInt32(u[l][0]),l===p-1&&"SHA-512/224"===e||d.putInt32(u[l][1]);return d},o};var rn=null,an=!1,nn=null,sn=null;function on(e,t,r){for(var a,n,i,s,o,c,l,u,p,d,h,f,y,g,v,m,C,E,S,b,T,I,A,B,x,w,N,k,R,L,_,D,U,P=r.length();P>=128;){for(N=0;N<16;++N)t[N][0]=r.getInt32()>>>0,t[N][1]=r.getInt32()>>>0;for(;N<80;++N)a=(((k=(L=t[N-2])[0])>>>19|(R=L[1])<<13)^(R>>>29|k<<3)^k>>>6)>>>0,n=((k<<13|R>>>19)^(R<<3|k>>>29)^(k<<26|R>>>6))>>>0,i=(((k=(D=t[N-15])[0])>>>1|(R=D[1])<<31)^(k>>>8|R<<24)^k>>>7)>>>0,s=((k<<31|R>>>1)^(k<<24|R>>>8)^(k<<25|R>>>7))>>>0,_=t[N-7],U=t[N-16],R=n+_[1]+s+U[1],t[N][0]=a+_[0]+i+U[0]+(R/4294967296>>>0)>>>0,t[N][1]=R>>>0;for(h=e[0][0],f=e[0][1],y=e[1][0],g=e[1][1],v=e[2][0],m=e[2][1],C=e[3][0],E=e[3][1],S=e[4][0],b=e[4][1],T=e[5][0],I=e[5][1],A=e[6][0],B=e[6][1],x=e[7][0],w=e[7][1],N=0;N<80;++N)l=((S>>>14|b<<18)^(S>>>18|b<<14)^(b>>>9|S<<23))>>>0,u=(A^S&(T^A))>>>0,o=((h>>>28|f<<4)^(f>>>2|h<<30)^(f>>>7|h<<25))>>>0,c=((h<<4|f>>>28)^(f<<30|h>>>2)^(f<<25|h>>>7))>>>0,p=(h&y|v&(h^y))>>>0,d=(f&g|m&(f^g))>>>0,R=w+(((S<<18|b>>>14)^(S<<14|b>>>18)^(b<<23|S>>>9))>>>0)+((B^b&(I^B))>>>0)+nn[N][1]+t[N][1],a=x+l+u+nn[N][0]+t[N][0]+(R/4294967296>>>0)>>>0,n=R>>>0,i=o+p+((R=c+d)/4294967296>>>0)>>>0,s=R>>>0,x=A,w=B,A=T,B=I,T=S,I=b,S=C+a+((R=E+n)/4294967296>>>0)>>>0,b=R>>>0,C=v,E=m,v=y,m=g,y=h,g=f,h=a+i+((R=n+s)/4294967296>>>0)>>>0,f=R>>>0;R=e[0][1]+f,e[0][0]=e[0][0]+h+(R/4294967296>>>0)>>>0,e[0][1]=R>>>0,R=e[1][1]+g,e[1][0]=e[1][0]+y+(R/4294967296>>>0)>>>0,e[1][1]=R>>>0,R=e[2][1]+m,e[2][0]=e[2][0]+v+(R/4294967296>>>0)>>>0,e[2][1]=R>>>0,R=e[3][1]+E,e[3][0]=e[3][0]+C+(R/4294967296>>>0)>>>0,e[3][1]=R>>>0,R=e[4][1]+b,e[4][0]=e[4][0]+S+(R/4294967296>>>0)>>>0,e[4][1]=R>>>0,R=e[5][1]+I,e[5][0]=e[5][0]+T+(R/4294967296>>>0)>>>0,e[5][1]=R>>>0,R=e[6][1]+B,e[6][0]=e[6][0]+A+(R/4294967296>>>0)>>>0,e[6][1]=R>>>0,R=e[7][1]+w,e[7][0]=e[7][0]+x+(R/4294967296>>>0)>>>0,e[7][1]=R>>>0,P-=128}}var cn={},ln=f.asn1;cn.privateKeyValidator={name:"PrivateKeyInfo",tagClass:ln.Class.UNIVERSAL,type:ln.Type.SEQUENCE,constructed:!0,value:[{name:"PrivateKeyInfo.version",tagClass:ln.Class.UNIVERSAL,type:ln.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.privateKeyAlgorithm",tagClass:ln.Class.UNIVERSAL,type:ln.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:ln.Class.UNIVERSAL,type:ln.Type.OID,constructed:!1,capture:"privateKeyOid"}]},{name:"PrivateKeyInfo",tagClass:ln.Class.UNIVERSAL,type:ln.Type.OCTETSTRING,constructed:!1,capture:"privateKey"}]},cn.publicKeyValidator={name:"SubjectPublicKeyInfo",tagClass:ln.Class.UNIVERSAL,type:ln.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:ln.Class.UNIVERSAL,type:ln.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:ln.Class.UNIVERSAL,type:ln.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{tagClass:ln.Class.UNIVERSAL,type:ln.Type.BITSTRING,constructed:!1,composed:!0,captureBitStringValue:"ed25519PublicKey"}]};var un=f,pn=cn,dn=pn.publicKeyValidator,hn=pn.privateKeyValidator;if(void 0===fn)var fn=un.jsbn.BigInteger;var yn=un.util.ByteBuffer,gn="undefined"==typeof Buffer?Uint8Array:Buffer;un.pki=un.pki||{},un.pki.ed25519=un.ed25519=un.ed25519||{};var vn=un.ed25519;function mn(e){var t=e.message;if(t instanceof Uint8Array||t instanceof gn)return t;var r=e.encoding;if(void 0===t){if(!e.md)throw new TypeError('"options.message" or "options.md" not specified.');t=e.md.digest().getBytes(),r="binary"}if("string"==typeof t&&!r)throw new TypeError('"options.encoding" must be "binary" or "utf8".');if("string"==typeof t){if("undefined"!=typeof Buffer)return Buffer.from(t,r);t=new yn(t,r)}else if(!(t instanceof yn))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 a=new gn(t.length()),n=0;n<a.length;++n)a[n]=t.at(n);return a}vn.constants={},vn.constants.PUBLIC_KEY_BYTE_LENGTH=32,vn.constants.PRIVATE_KEY_BYTE_LENGTH=64,vn.constants.SEED_BYTE_LENGTH=32,vn.constants.SIGN_BYTE_LENGTH=64,vn.constants.HASH_BYTE_LENGTH=64,vn.generateKeyPair=function(e){var t=(e=e||{}).seed;if(void 0===t)t=un.random.getBytesSync(vn.constants.SEED_BYTE_LENGTH);else if("string"==typeof t){if(t.length!==vn.constants.SEED_BYTE_LENGTH)throw new TypeError('"seed" must be '+vn.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=mn({message:t,encoding:"binary"});for(var r=new gn(vn.constants.PUBLIC_KEY_BYTE_LENGTH),a=new gn(vn.constants.PRIVATE_KEY_BYTE_LENGTH),n=0;n<32;++n)a[n]=t[n];return function(e,t){var r,a=[qn(),qn(),qn(),qn()],n=xn(t,32);for(n[0]&=248,n[31]&=127,n[31]|=64,On(a,n),Ln(e,a),r=0;r<32;++r)t[r+32]=e[r]}(r,a),{publicKey:r,privateKey:a}},vn.privateKeyFromAsn1=function(e){var t={},r=[];if(!un.asn1.validate(e,hn,t,r)){var a=new Error("Invalid Key.");throw a.errors=r,a}var n=un.asn1.derToOid(t.privateKeyOid),i=un.oids.EdDSA25519;if(n!==i)throw new Error('Invalid OID "'+n+'"; OID must be "'+i+'".');var s=t.privateKey;return{privateKeyBytes:mn({message:un.asn1.fromDer(s).value,encoding:"binary"})}},vn.publicKeyFromAsn1=function(e){var t={},r=[];if(!un.asn1.validate(e,dn,t,r)){var a=new Error("Invalid Key.");throw a.errors=r,a}var n=un.asn1.derToOid(t.publicKeyOid),i=un.oids.EdDSA25519;if(n!==i)throw new Error('Invalid OID "'+n+'"; OID must be "'+i+'".');var s=t.ed25519PublicKey;if(s.length!==vn.constants.PUBLIC_KEY_BYTE_LENGTH)throw new Error("Key length is invalid.");return mn({message:s,encoding:"binary"})},vn.publicKeyFromPrivateKey=function(e){var t=mn({message:(e=e||{}).privateKey,encoding:"binary"});if(t.length!==vn.constants.PRIVATE_KEY_BYTE_LENGTH)throw new TypeError('"options.privateKey" must have a byte length of '+vn.constants.PRIVATE_KEY_BYTE_LENGTH);for(var r=new gn(vn.constants.PUBLIC_KEY_BYTE_LENGTH),a=0;a<r.length;++a)r[a]=t[32+a];return r},vn.sign=function(e){var t=mn(e=e||{}),r=mn({message:e.privateKey,encoding:"binary"});if(r.length===vn.constants.SEED_BYTE_LENGTH)r=vn.generateKeyPair({seed:r}).privateKey;else if(r.length!==vn.constants.PRIVATE_KEY_BYTE_LENGTH)throw new TypeError('"options.privateKey" must have a byte length of '+vn.constants.SEED_BYTE_LENGTH+" or "+vn.constants.PRIVATE_KEY_BYTE_LENGTH);var a=new gn(vn.constants.SIGN_BYTE_LENGTH+t.length);!function(e,t,r,a){var n,i,s=new Float64Array(64),o=[qn(),qn(),qn(),qn()],c=xn(a,32);c[0]&=248,c[31]&=127,c[31]|=64;var l=r+64;for(n=0;n<r;++n)e[64+n]=t[n];for(n=0;n<32;++n)e[32+n]=c[32+n];var u=xn(e.subarray(32),r+32);for(Nn(u),On(o,u),Ln(e,o),n=32;n<64;++n)e[n]=a[n];var p=xn(e,r+64);for(Nn(p),n=32;n<64;++n)s[n]=0;for(n=0;n<32;++n)s[n]=u[n];for(n=0;n<32;++n)for(i=0;i<32;i++)s[n+i]+=p[n]*c[i];wn(e.subarray(32),s)}(a,t,t.length,r);for(var n=new gn(vn.constants.SIGN_BYTE_LENGTH),i=0;i<n.length;++i)n[i]=a[i];return n},vn.verify=function(e){var t=mn(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 r=mn({message:e.signature,encoding:"binary"});if(r.length!==vn.constants.SIGN_BYTE_LENGTH)throw new TypeError('"options.signature" must have a byte length of '+vn.constants.SIGN_BYTE_LENGTH);var a=mn({message:e.publicKey,encoding:"binary"});if(a.length!==vn.constants.PUBLIC_KEY_BYTE_LENGTH)throw new TypeError('"options.publicKey" must have a byte length of '+vn.constants.PUBLIC_KEY_BYTE_LENGTH);var n,i=new gn(vn.constants.SIGN_BYTE_LENGTH+t.length),s=new gn(vn.constants.SIGN_BYTE_LENGTH+t.length);for(n=0;n<vn.constants.SIGN_BYTE_LENGTH;++n)i[n]=r[n];for(n=0;n<t.length;++n)i[n+vn.constants.SIGN_BYTE_LENGTH]=t[n];return function(e,t,r,a){var n,i=new gn(32),s=[qn(),qn(),qn(),qn()],o=[qn(),qn(),qn(),qn()];if(r<64)return-1;if(function(e,t){var r=qn(),a=qn(),n=qn(),i=qn(),s=qn(),o=qn(),c=qn();Kn(e[2],En),function(e,t){var r;for(r=0;r<16;++r)e[r]=t[2*r]+(t[2*r+1]<<8);e[15]&=32767}(e[1],t),Gn(n,e[1]),zn(i,n,Sn),Hn(n,n,e[2]),jn(i,e[2],i),Gn(s,i),Gn(o,s),zn(c,o,s),zn(r,c,n),zn(r,r,i),function(e,t){var r,a=qn();for(r=0;r<16;++r)a[r]=t[r];for(r=250;r>=0;--r)Gn(a,a),1!==r&&zn(a,a,t);for(r=0;r<16;++r)e[r]=a[r]}(r,r),zn(r,r,n),zn(r,r,i),zn(r,r,i),zn(e[0],r,i),Gn(a,e[0]),zn(a,a,i),Dn(a,n)&&zn(e[0],e[0],Bn);if(Gn(a,e[0]),zn(a,a,i),Dn(a,n))return-1;Pn(e[0])===t[31]>>7&&Hn(e[0],Cn,e[0]);return zn(e[3],e[0],e[1]),0}(o,a))return-1;for(n=0;n<r;++n)e[n]=t[n];for(n=0;n<32;++n)e[n+32]=a[n];var c=xn(e,r);if(Nn(c),Vn(s,o,c),On(o,t.subarray(32)),kn(s,o),Ln(i,s),r-=64,Un(t,0,i,0)){for(n=0;n<r;++n)e[n]=0;return-1}for(n=0;n<r;++n)e[n]=t[n+64];return r}(s,i,i.length,a)>=0};var Cn=qn(),En=qn([1]),Sn=qn([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),bn=qn([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),Tn=qn([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),In=qn([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),An=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]),Bn=qn([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function xn(e,t){var r=un.md.sha512.create(),a=new yn(e);r.update(a.getBytes(t),"binary");var n=r.digest().getBytes();if("undefined"!=typeof Buffer)return Buffer.from(n,"binary");for(var i=new gn(vn.constants.HASH_BYTE_LENGTH),s=0;s<64;++s)i[s]=n.charCodeAt(s);return i}function wn(e,t){var r,a,n,i;for(a=63;a>=32;--a){for(r=0,n=a-32,i=a-12;n<i;++n)t[n]+=r-16*t[a]*An[n-(a-32)],r=t[n]+128>>8,t[n]-=256*r;t[n]+=r,t[a]=0}for(r=0,n=0;n<32;++n)t[n]+=r-(t[31]>>4)*An[n],r=t[n]>>8,t[n]&=255;for(n=0;n<32;++n)t[n]-=r*An[n];for(a=0;a<32;++a)t[a+1]+=t[a]>>8,e[a]=255&t[a]}function Nn(e){for(var t=new Float64Array(64),r=0;r<64;++r)t[r]=e[r],e[r]=0;wn(e,t)}function kn(e,t){var r=qn(),a=qn(),n=qn(),i=qn(),s=qn(),o=qn(),c=qn(),l=qn(),u=qn();Hn(r,e[1],e[0]),Hn(u,t[1],t[0]),zn(r,r,u),jn(a,e[0],e[1]),jn(u,t[0],t[1]),zn(a,a,u),zn(n,e[3],t[3]),zn(n,n,bn),zn(i,e[2],t[2]),jn(i,i,i),Hn(s,a,r),Hn(o,i,n),jn(c,i,n),jn(l,a,r),zn(e[0],s,o),zn(e[1],l,c),zn(e[2],c,o),zn(e[3],s,l)}function Rn(e,t,r){for(var a=0;a<4;++a)Fn(e[a],t[a],r)}function Ln(e,t){var r=qn(),a=qn(),n=qn();!function(e,t){var r,a=qn();for(r=0;r<16;++r)a[r]=t[r];for(r=253;r>=0;--r)Gn(a,a),2!==r&&4!==r&&zn(a,a,t);for(r=0;r<16;++r)e[r]=a[r]}(n,t[2]),zn(r,t[0],n),zn(a,t[1],n),_n(e,a),e[31]^=Pn(r)<<7}function _n(e,t){var r,a,n,i=qn(),s=qn();for(r=0;r<16;++r)s[r]=t[r];for(Mn(s),Mn(s),Mn(s),a=0;a<2;++a){for(i[0]=s[0]-65517,r=1;r<15;++r)i[r]=s[r]-65535-(i[r-1]>>16&1),i[r-1]&=65535;i[15]=s[15]-32767-(i[14]>>16&1),n=i[15]>>16&1,i[14]&=65535,Fn(s,i,1-n)}for(r=0;r<16;r++)e[2*r]=255&s[r],e[2*r+1]=s[r]>>8}function Dn(e,t){var r=new gn(32),a=new gn(32);return _n(r,e),_n(a,t),Un(r,0,a,0)}function Un(e,t,r,a){return function(e,t,r,a,n){var i,s=0;for(i=0;i<n;++i)s|=e[t+i]^r[a+i];return(1&s-1>>>8)-1}(e,t,r,a,32)}function Pn(e){var t=new gn(32);return _n(t,e),1&t[0]}function Vn(e,t,r){var a,n;for(Kn(e[0],Cn),Kn(e[1],En),Kn(e[2],En),Kn(e[3],Cn),n=255;n>=0;--n)Rn(e,t,a=r[n/8|0]>>(7&n)&1),kn(t,e),kn(e,e),Rn(e,t,a)}function On(e,t){var r=[qn(),qn(),qn(),qn()];Kn(r[0],Tn),Kn(r[1],In),Kn(r[2],En),zn(r[3],Tn,In),Vn(e,r,t)}function Kn(e,t){var r;for(r=0;r<16;r++)e[r]=0|t[r]}function Mn(e){var t,r,a=1;for(t=0;t<16;++t)r=e[t]+a+65535,a=Math.floor(r/65536),e[t]=r-65536*a;e[0]+=a-1+37*(a-1)}function Fn(e,t,r){for(var a,n=~(r-1),i=0;i<16;++i)a=n&(e[i]^t[i]),e[i]^=a,t[i]^=a}function qn(e){var t,r=new Float64Array(16);if(e)for(t=0;t<e.length;++t)r[t]=e[t];return r}function jn(e,t,r){for(var a=0;a<16;++a)e[a]=t[a]+r[a]}function Hn(e,t,r){for(var a=0;a<16;++a)e[a]=t[a]-r[a]}function Gn(e,t){zn(e,t,t)}function zn(e,t,r){var a,n,i=0,s=0,o=0,c=0,l=0,u=0,p=0,d=0,h=0,f=0,y=0,g=0,v=0,m=0,C=0,E=0,S=0,b=0,T=0,I=0,A=0,B=0,x=0,w=0,N=0,k=0,R=0,L=0,_=0,D=0,U=0,P=r[0],V=r[1],O=r[2],K=r[3],M=r[4],F=r[5],q=r[6],j=r[7],H=r[8],G=r[9],z=r[10],Q=r[11],Y=r[12],X=r[13],W=r[14],$=r[15];i+=(a=t[0])*P,s+=a*V,o+=a*O,c+=a*K,l+=a*M,u+=a*F,p+=a*q,d+=a*j,h+=a*H,f+=a*G,y+=a*z,g+=a*Q,v+=a*Y,m+=a*X,C+=a*W,E+=a*$,s+=(a=t[1])*P,o+=a*V,c+=a*O,l+=a*K,u+=a*M,p+=a*F,d+=a*q,h+=a*j,f+=a*H,y+=a*G,g+=a*z,v+=a*Q,m+=a*Y,C+=a*X,E+=a*W,S+=a*$,o+=(a=t[2])*P,c+=a*V,l+=a*O,u+=a*K,p+=a*M,d+=a*F,h+=a*q,f+=a*j,y+=a*H,g+=a*G,v+=a*z,m+=a*Q,C+=a*Y,E+=a*X,S+=a*W,b+=a*$,c+=(a=t[3])*P,l+=a*V,u+=a*O,p+=a*K,d+=a*M,h+=a*F,f+=a*q,y+=a*j,g+=a*H,v+=a*G,m+=a*z,C+=a*Q,E+=a*Y,S+=a*X,b+=a*W,T+=a*$,l+=(a=t[4])*P,u+=a*V,p+=a*O,d+=a*K,h+=a*M,f+=a*F,y+=a*q,g+=a*j,v+=a*H,m+=a*G,C+=a*z,E+=a*Q,S+=a*Y,b+=a*X,T+=a*W,I+=a*$,u+=(a=t[5])*P,p+=a*V,d+=a*O,h+=a*K,f+=a*M,y+=a*F,g+=a*q,v+=a*j,m+=a*H,C+=a*G,E+=a*z,S+=a*Q,b+=a*Y,T+=a*X,I+=a*W,A+=a*$,p+=(a=t[6])*P,d+=a*V,h+=a*O,f+=a*K,y+=a*M,g+=a*F,v+=a*q,m+=a*j,C+=a*H,E+=a*G,S+=a*z,b+=a*Q,T+=a*Y,I+=a*X,A+=a*W,B+=a*$,d+=(a=t[7])*P,h+=a*V,f+=a*O,y+=a*K,g+=a*M,v+=a*F,m+=a*q,C+=a*j,E+=a*H,S+=a*G,b+=a*z,T+=a*Q,I+=a*Y,A+=a*X,B+=a*W,x+=a*$,h+=(a=t[8])*P,f+=a*V,y+=a*O,g+=a*K,v+=a*M,m+=a*F,C+=a*q,E+=a*j,S+=a*H,b+=a*G,T+=a*z,I+=a*Q,A+=a*Y,B+=a*X,x+=a*W,w+=a*$,f+=(a=t[9])*P,y+=a*V,g+=a*O,v+=a*K,m+=a*M,C+=a*F,E+=a*q,S+=a*j,b+=a*H,T+=a*G,I+=a*z,A+=a*Q,B+=a*Y,x+=a*X,w+=a*W,N+=a*$,y+=(a=t[10])*P,g+=a*V,v+=a*O,m+=a*K,C+=a*M,E+=a*F,S+=a*q,b+=a*j,T+=a*H,I+=a*G,A+=a*z,B+=a*Q,x+=a*Y,w+=a*X,N+=a*W,k+=a*$,g+=(a=t[11])*P,v+=a*V,m+=a*O,C+=a*K,E+=a*M,S+=a*F,b+=a*q,T+=a*j,I+=a*H,A+=a*G,B+=a*z,x+=a*Q,w+=a*Y,N+=a*X,k+=a*W,R+=a*$,v+=(a=t[12])*P,m+=a*V,C+=a*O,E+=a*K,S+=a*M,b+=a*F,T+=a*q,I+=a*j,A+=a*H,B+=a*G,x+=a*z,w+=a*Q,N+=a*Y,k+=a*X,R+=a*W,L+=a*$,m+=(a=t[13])*P,C+=a*V,E+=a*O,S+=a*K,b+=a*M,T+=a*F,I+=a*q,A+=a*j,B+=a*H,x+=a*G,w+=a*z,N+=a*Q,k+=a*Y,R+=a*X,L+=a*W,_+=a*$,C+=(a=t[14])*P,E+=a*V,S+=a*O,b+=a*K,T+=a*M,I+=a*F,A+=a*q,B+=a*j,x+=a*H,w+=a*G,N+=a*z,k+=a*Q,R+=a*Y,L+=a*X,_+=a*W,D+=a*$,E+=(a=t[15])*P,s+=38*(b+=a*O),o+=38*(T+=a*K),c+=38*(I+=a*M),l+=38*(A+=a*F),u+=38*(B+=a*q),p+=38*(x+=a*j),d+=38*(w+=a*H),h+=38*(N+=a*G),f+=38*(k+=a*z),y+=38*(R+=a*Q),g+=38*(L+=a*Y),v+=38*(_+=a*X),m+=38*(D+=a*W),C+=38*(U+=a*$),i=(a=(i+=38*(S+=a*V))+(n=1)+65535)-65536*(n=Math.floor(a/65536)),s=(a=s+n+65535)-65536*(n=Math.floor(a/65536)),o=(a=o+n+65535)-65536*(n=Math.floor(a/65536)),c=(a=c+n+65535)-65536*(n=Math.floor(a/65536)),l=(a=l+n+65535)-65536*(n=Math.floor(a/65536)),u=(a=u+n+65535)-65536*(n=Math.floor(a/65536)),p=(a=p+n+65535)-65536*(n=Math.floor(a/65536)),d=(a=d+n+65535)-65536*(n=Math.floor(a/65536)),h=(a=h+n+65535)-65536*(n=Math.floor(a/65536)),f=(a=f+n+65535)-65536*(n=Math.floor(a/65536)),y=(a=y+n+65535)-65536*(n=Math.floor(a/65536)),g=(a=g+n+65535)-65536*(n=Math.floor(a/65536)),v=(a=v+n+65535)-65536*(n=Math.floor(a/65536)),m=(a=m+n+65535)-65536*(n=Math.floor(a/65536)),C=(a=C+n+65535)-65536*(n=Math.floor(a/65536)),E=(a=E+n+65535)-65536*(n=Math.floor(a/65536)),i=(a=(i+=n-1+37*(n-1))+(n=1)+65535)-65536*(n=Math.floor(a/65536)),s=(a=s+n+65535)-65536*(n=Math.floor(a/65536)),o=(a=o+n+65535)-65536*(n=Math.floor(a/65536)),c=(a=c+n+65535)-65536*(n=Math.floor(a/65536)),l=(a=l+n+65535)-65536*(n=Math.floor(a/65536)),u=(a=u+n+65535)-65536*(n=Math.floor(a/65536)),p=(a=p+n+65535)-65536*(n=Math.floor(a/65536)),d=(a=d+n+65535)-65536*(n=Math.floor(a/65536)),h=(a=h+n+65535)-65536*(n=Math.floor(a/65536)),f=(a=f+n+65535)-65536*(n=Math.floor(a/65536)),y=(a=y+n+65535)-65536*(n=Math.floor(a/65536)),g=(a=g+n+65535)-65536*(n=Math.floor(a/65536)),v=(a=v+n+65535)-65536*(n=Math.floor(a/65536)),m=(a=m+n+65535)-65536*(n=Math.floor(a/65536)),C=(a=C+n+65535)-65536*(n=Math.floor(a/65536)),E=(a=E+n+65535)-65536*(n=Math.floor(a/65536)),i+=n-1+37*(n-1),e[0]=i,e[1]=s,e[2]=o,e[3]=c,e[4]=l,e[5]=u,e[6]=p,e[7]=d,e[8]=h,e[9]=f,e[10]=y,e[11]=g,e[12]=v,e[13]=m,e[14]=C,e[15]=E}var Qn=f;Qn.kem=Qn.kem||{};var Yn=Qn.jsbn.BigInteger;function Xn(e,t,r,a){e.generate=function(e,n){for(var i=new Qn.util.ByteBuffer,s=Math.ceil(n/a)+r,o=new Qn.util.ByteBuffer,c=r;c<s;++c){o.putInt32(c),t.start(),t.update(e+o.getBytes());var l=t.digest();i.putBytes(l.getBytes(a))}return i.truncate(i.length()-n),i.getBytes()}}Qn.kem.rsa={},Qn.kem.rsa.create=function(e,t){var r=(t=t||{}).prng||Qn.random,a={encrypt:function(t,a){var n,i=Math.ceil(t.n.bitLength()/8);do{n=new Yn(Qn.util.bytesToHex(r.getBytesSync(i)),16).mod(t.n)}while(n.compareTo(Yn.ONE)<=0);var s=i-(n=Qn.util.hexToBytes(n.toString(16))).length;return s>0&&(n=Qn.util.fillString(String.fromCharCode(0),s)+n),{encapsulation:t.encrypt(n,"NONE"),key:e.generate(n,a)}},decrypt:function(t,r,a){var n=t.decrypt(r,"NONE");return e.generate(n,a)}};return a},Qn.kem.kdf1=function(e,t){Xn(this,e,0,t||e.digestLength)},Qn.kem.kdf2=function(e,t){Xn(this,e,1,t||e.digestLength)};var Wn=f;Wn.log=Wn.log||{},Wn.log.levels=["none","error","warning","info","debug","verbose","max"];var $n={},Zn=[],Jn=null;Wn.log.LEVEL_LOCKED=2,Wn.log.NO_LEVEL_CHECK=4,Wn.log.INTERPOLATE=8;for(var ei=0;ei<Wn.log.levels.length;++ei){var ti=Wn.log.levels[ei];$n[ti]={index:ei,name:ti.toUpperCase()}}Wn.log.logMessage=function(e){for(var t=$n[e.level].index,r=0;r<Zn.length;++r){var a=Zn[r];if(a.flags&Wn.log.NO_LEVEL_CHECK)a.f(e);else t<=$n[a.level].index&&a.f(a,e)}},Wn.log.prepareStandard=function(e){"standard"in e||(e.standard=$n[e.level].name+" ["+e.category+"] "+e.message)},Wn.log.prepareFull=function(e){if(!("full"in e)){var t=[e.message];t=t.concat([]||e.arguments),e.full=Wn.util.format.apply(this,t)}},Wn.log.prepareStandardFull=function(e){"standardFull"in e||(Wn.log.prepareStandard(e),e.standardFull=e.standard)};var ri=["error","warning","info","debug","verbose"];for(ei=0;ei<ri.length;++ei)(function(e){Wn.log[e]=function(t,r){var a=Array.prototype.slice.call(arguments).slice(2),n={timestamp:new Date,level:e,category:t,message:r,arguments:a};Wn.log.logMessage(n)}})(ri[ei]);if(Wn.log.makeLogger=function(e){var t={flags:0,f:e};return Wn.log.setLevel(t,"none"),t},Wn.log.setLevel=function(e,t){var r=!1;if(e&&!(e.flags&Wn.log.LEVEL_LOCKED))for(var a=0;a<Wn.log.levels.length;++a){if(t==Wn.log.levels[a]){e.level=t,r=!0;break}}return r},Wn.log.lock=function(e,t){void 0===t||t?e.flags|=Wn.log.LEVEL_LOCKED:e.flags&=~Wn.log.LEVEL_LOCKED},Wn.log.addLogger=function(e){Zn.push(e)},"undefined"!=typeof console&&"log"in console){var ai;if(console.error&&console.warn&&console.info&&console.debug){var ni={error:console.error,warning:console.warn,info:console.info,debug:console.debug,verbose:console.debug},ii=function(e,t){Wn.log.prepareStandard(t);var r=ni[t.level],a=[t.standard];a=a.concat(t.arguments.slice()),r.apply(console,a)};ai=Wn.log.makeLogger(ii)}else{ii=function(e,t){Wn.log.prepareStandardFull(t),console.log(t.standardFull)};ai=Wn.log.makeLogger(ii)}Wn.log.setLevel(ai,"debug"),Wn.log.addLogger(ai),Jn=ai}else console={log:function(){}};if(null!==Jn&&"undefined"!=typeof window&&window.location){var si=new URL(window.location.href).searchParams;if(si.has("console.level")&&Wn.log.setLevel(Jn,si.get("console.level").slice(-1)[0]),si.has("console.lock"))"true"==si.get("console.lock").slice(-1)[0]&&Wn.log.lock(Jn)}Wn.log.consoleLogger=Jn;var oi=f,ci=oi.asn1,li=oi.pkcs7=oi.pkcs7||{};function ui(e){var t={},r=[];if(!ci.validate(e,li.asn1.recipientInfoValidator,t,r)){var a=new Error("Cannot read PKCS#7 RecipientInfo. ASN.1 object is not an PKCS#7 RecipientInfo.");throw a.errors=r,a}return{version:t.version.charCodeAt(0),issuer:oi.pki.RDNAttributesAsArray(t.issuer),serialNumber:oi.util.createBuffer(t.serial).toHex(),encryptedContent:{algorithm:ci.derToOid(t.encAlgorithm),parameter:t.encParameter?t.encParameter.value:void 0,content:t.encKey}}}function pi(e){return ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.INTEGER,!1,ci.integerToDer(e.version).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[oi.pki.distinguishedNameToAsn1({attributes:e.issuer}),ci.create(ci.Class.UNIVERSAL,ci.Type.INTEGER,!1,oi.util.hexToBytes(e.serialNumber))]),ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(e.encryptedContent.algorithm).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.NULL,!1,"")]),ci.create(ci.Class.UNIVERSAL,ci.Type.OCTETSTRING,!1,e.encryptedContent.content)])}function di(e){for(var t=[],r=0;r<e.length;++r)t.push(pi(e[r]));return t}function hi(e){var t=ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.INTEGER,!1,ci.integerToDer(e.version).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[oi.pki.distinguishedNameToAsn1({attributes:e.issuer}),ci.create(ci.Class.UNIVERSAL,ci.Type.INTEGER,!1,oi.util.hexToBytes(e.serialNumber))]),ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(e.digestAlgorithm).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.NULL,!1,"")])]);if(e.authenticatedAttributesAsn1&&t.value.push(e.authenticatedAttributesAsn1),t.value.push(ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(e.signatureAlgorithm).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.NULL,!1,"")])),t.value.push(ci.create(ci.Class.UNIVERSAL,ci.Type.OCTETSTRING,!1,e.signature)),e.unauthenticatedAttributes.length>0){for(var r=ci.create(ci.Class.CONTEXT_SPECIFIC,1,!0,[]),a=0;a<e.unauthenticatedAttributes.length;++a){var n=e.unauthenticatedAttributes[a];r.values.push(fi(n))}t.value.push(r)}return t}function fi(e){var t;if(e.type===oi.pki.oids.contentType)t=ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(e.value).getBytes());else if(e.type===oi.pki.oids.messageDigest)t=ci.create(ci.Class.UNIVERSAL,ci.Type.OCTETSTRING,!1,e.value.bytes());else if(e.type===oi.pki.oids.signingTime){var r=new Date("1950-01-01T00:00:00Z"),a=new Date("2050-01-01T00:00:00Z"),n=e.value;if("string"==typeof n){var i=Date.parse(n);n=isNaN(i)?13===n.length?ci.utcTimeToDate(n):ci.generalizedTimeToDate(n):new Date(i)}t=n>=r&&n<a?ci.create(ci.Class.UNIVERSAL,ci.Type.UTCTIME,!1,ci.dateToUtcTime(n)):ci.create(ci.Class.UNIVERSAL,ci.Type.GENERALIZEDTIME,!1,ci.dateToGeneralizedTime(n))}return ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(e.type).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.SET,!0,[t])])}function yi(e,t,r){var a={};if(!ci.validate(t,r,a,[])){var n=new Error("Cannot read PKCS#7 message. ASN.1 object is not a supported PKCS#7 message.");throw n.errors=n,n}if(ci.derToOid(a.contentType)!==oi.pki.oids.data)throw new Error("Unsupported PKCS#7 message. Only wrapped ContentType Data supported.");if(a.encryptedContent){var i="";if(oi.util.isArray(a.encryptedContent))for(var s=0;s<a.encryptedContent.length;++s){if(a.encryptedContent[s].type!==ci.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:ci.derToOid(a.encAlgorithm),parameter:oi.util.createBuffer(a.encParameter.value),content:oi.util.createBuffer(i)}}if(a.content){i="";if(oi.util.isArray(a.content))for(s=0;s<a.content.length;++s){if(a.content[s].type!==ci.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=oi.util.createBuffer(i)}return e.version=a.version.charCodeAt(0),e.rawCapture=a,a}function gi(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 oi.pki.oids["aes128-CBC"]:case oi.pki.oids["aes192-CBC"]:case oi.pki.oids["aes256-CBC"]:t=oi.aes.createDecryptionCipher(e.encryptedContent.key);break;case oi.pki.oids.desCBC:case oi.pki.oids["des-EDE3-CBC"]:t=oi.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}}li.messageFromPem=function(e){var t=oi.pem.decode(e)[0];if("PKCS7"!==t.type){var r=new Error('Could not convert PKCS#7 message from PEM; PEM header type is not "PKCS#7".');throw r.headerType=t.type,r}if(t.procType&&"ENCRYPTED"===t.procType.type)throw new Error("Could not convert PKCS#7 message from PEM; PEM is encrypted.");var a=ci.fromDer(t.body);return li.messageFromAsn1(a)},li.messageToPem=function(e,t){var r={type:"PKCS7",body:ci.toDer(e.toAsn1()).getBytes()};return oi.pem.encode(r,{maxline:t})},li.messageFromAsn1=function(e){var t={},r=[];if(!ci.validate(e,li.asn1.contentInfoValidator,t,r)){var a=new Error("Cannot read PKCS#7 message. ASN.1 object is not an PKCS#7 ContentInfo.");throw a.errors=r,a}var n,i=ci.derToOid(t.contentType);switch(i){case oi.pki.oids.envelopedData:n=li.createEnvelopedData();break;case oi.pki.oids.encryptedData:n=li.createEncryptedData();break;case oi.pki.oids.signedData:n=li.createSignedData();break;default:throw new Error("Cannot read PKCS#7 message. ContentType with OID "+i+" is not (yet) supported.")}return n.fromAsn1(t.content.value[0]),n},li.createSignedData=function(){var e=null;return e={type:oi.pki.oids.signedData,version:1,certificates:[],crls:[],signers:[],digestAlgorithmIdentifiers:[],contentInfo:null,signerInfos:[],fromAsn1:function(t){if(yi(e,t,li.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(oi.pki.certificateFromAsn1(r[a]))},toAsn1:function(){e.contentInfo||e.sign();for(var t=[],r=0;r<e.certificates.length;++r)t.push(oi.pki.certificateToAsn1(e.certificates[r]));var a=[],n=ci.create(ci.Class.CONTEXT_SPECIFIC,0,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.INTEGER,!1,ci.integerToDer(e.version).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.SET,!0,e.digestAlgorithmIdentifiers),e.contentInfo])]);return t.length>0&&n.value[0].value.push(ci.create(ci.Class.CONTEXT_SPECIFIC,0,!0,t)),a.length>0&&n.value[0].value.push(ci.create(ci.Class.CONTEXT_SPECIFIC,1,!0,a)),n.value[0].value.push(ci.create(ci.Class.UNIVERSAL,ci.Type.SET,!0,e.signerInfos)),ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(e.type).getBytes()),n])},addSigner:function(t){var r=t.issuer,a=t.serialNumber;if(t.certificate){var n=t.certificate;"string"==typeof n&&(n=oi.pki.certificateFromPem(n)),r=n.issuer.attributes,a=n.serialNumber}var i=t.key;if(!i)throw new Error("Could not add PKCS#7 signer; no private key specified.");"string"==typeof i&&(i=oi.pki.privateKeyFromPem(i));var s=t.digestAlgorithm||oi.pki.oids.sha1;switch(s){case oi.pki.oids.sha1:case oi.pki.oids.sha256:case oi.pki.oids.sha384:case oi.pki.oids.sha512:case oi.pki.oids.md5:break;default:throw new Error("Could not add PKCS#7 signer; unknown message digest algorithm: "+s)}var o=t.authenticatedAttributes||[];if(o.length>0){for(var c=!1,l=!1,u=0;u<o.length;++u){var p=o[u];if(c||p.type!==oi.pki.oids.contentType){if(l||p.type!==oi.pki.oids.messageDigest);else if(l=!0,c)break}else if(c=!0,l)break}if(!c||!l)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:i,version:1,issuer:r,serialNumber:a,digestAlgorithm:s,signatureAlgorithm:oi.pki.oids.rsaEncryption,signature:null,authenticatedAttributes:o,unauthenticatedAttributes:[]})},sign:function(t){var r;(t=t||{},"object"!=typeof e.content||null===e.contentInfo)&&(e.contentInfo=ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(oi.pki.oids.data).getBytes())]),"content"in e&&(e.content instanceof oi.util.ByteBuffer?r=e.content.bytes():"string"==typeof e.content&&(r=oi.util.encodeUtf8(e.content)),t.detached?e.detachedContent=ci.create(ci.Class.UNIVERSAL,ci.Type.OCTETSTRING,!1,r):e.contentInfo.value.push(ci.create(ci.Class.CONTEXT_SPECIFIC,0,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OCTETSTRING,!1,r)]))));if(0!==e.signers.length){var a=function(){for(var t={},r=0;r<e.signers.length;++r){var a=e.signers[r];(n=a.digestAlgorithm)in t||(t[n]=oi.md[oi.pki.oids[n]].create()),0===a.authenticatedAttributes.length?a.md=t[n]:a.md=oi.md[oi.pki.oids[n]].create()}for(var n in e.digestAlgorithmIdentifiers=[],t)e.digestAlgorithmIdentifiers.push(ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(n).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.NULL,!1,"")]));return t}();!function(t){var r;r=e.detachedContent?e.detachedContent:(r=e.contentInfo.value[1]).value[0];if(!r)throw new Error("Could not sign PKCS#7 message; there is no content to sign.");var a=ci.derToOid(e.contentInfo.value[0].value),n=ci.toDer(r);for(var i in n.getByte(),ci.getBerValueLength(n),n=n.getBytes(),t)t[i].start().update(n);for(var s=new Date,o=0;o<e.signers.length;++o){var c=e.signers[o];if(0===c.authenticatedAttributes.length){if(a!==oi.pki.oids.data)throw new Error("Invalid signer; authenticatedAttributes must be present when the ContentInfo content type is not PKCS#7 Data.")}else{c.authenticatedAttributesAsn1=ci.create(ci.Class.CONTEXT_SPECIFIC,0,!0,[]);for(var l=ci.create(ci.Class.UNIVERSAL,ci.Type.SET,!0,[]),u=0;u<c.authenticatedAttributes.length;++u){var p=c.authenticatedAttributes[u];p.type===oi.pki.oids.messageDigest?p.value=t[c.digestAlgorithm].digest():p.type===oi.pki.oids.signingTime&&(p.value||(p.value=s)),l.value.push(fi(p)),c.authenticatedAttributesAsn1.value.push(fi(p))}n=ci.toDer(l).getBytes(),c.md.start().update(n)}c.signature=c.key.sign(c.md,"RSASSA-PKCS1-V1_5")}e.signerInfos=function(e){for(var t=[],r=0;r<e.length;++r)t.push(hi(e[r]));return t}(e.signers)}(a)}},verify:function(){throw new Error("PKCS#7 signature verification not yet implemented.")},addCertificate:function(t){"string"==typeof t&&(t=oi.pki.certificateFromPem(t)),e.certificates.push(t)},addCertificateRevokationList:function(e){throw new Error("PKCS#7 CRL support not yet implemented.")}},e},li.createEncryptedData=function(){var e=null;return e={type:oi.pki.oids.encryptedData,version:0,encryptedContent:{algorithm:oi.pki.oids["aes256-CBC"]},fromAsn1:function(t){yi(e,t,li.asn1.encryptedDataValidator)},decrypt:function(t){void 0!==t&&(e.encryptedContent.key=t),gi(e)}},e},li.createEnvelopedData=function(){var e=null;return e={type:oi.pki.oids.envelopedData,version:0,recipients:[],encryptedContent:{algorithm:oi.pki.oids["aes256-CBC"]},fromAsn1:function(t){var r=yi(e,t,li.asn1.envelopedDataValidator);e.recipients=function(e){for(var t=[],r=0;r<e.length;++r)t.push(ui(e[r]));return t}(r.recipientInfos.value)},toAsn1:function(){return ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(e.type).getBytes()),ci.create(ci.Class.CONTEXT_SPECIFIC,0,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.INTEGER,!1,ci.integerToDer(e.version).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.SET,!0,di(e.recipients)),ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,(t=e.encryptedContent,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(oi.pki.oids.data).getBytes()),ci.create(ci.Class.UNIVERSAL,ci.Type.SEQUENCE,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OID,!1,ci.oidToDer(t.algorithm).getBytes()),t.parameter?ci.create(ci.Class.UNIVERSAL,ci.Type.OCTETSTRING,!1,t.parameter.getBytes()):void 0]),ci.create(ci.Class.CONTEXT_SPECIFIC,0,!0,[ci.create(ci.Class.UNIVERSAL,ci.Type.OCTETSTRING,!1,t.content.getBytes())])]))])])]);var t},findRecipient:function(t){for(var r=t.issuer.attributes,a=0;a<e.recipients.length;++a){var n=e.recipients[a],i=n.issuer;if(n.serialNumber===t.serialNumber&&i.length===r.length){for(var s=!0,o=0;o<r.length;++o)if(i[o].type!==r[o].type||i[o].value!==r[o].value){s=!1;break}if(s)return n}}return null},decrypt:function(t,r){if(void 0===e.encryptedContent.key&&void 0!==t&&void 0!==r)switch(t.encryptedContent.algorithm){case oi.pki.oids.rsaEncryption:case oi.pki.oids.desCBC:var a=r.decrypt(t.encryptedContent.content);e.encryptedContent.key=oi.util.createBuffer(a);break;default:throw new Error("Unsupported asymmetric cipher, OID "+t.encryptedContent.algorithm)}gi(e)},addRecipient:function(t){e.recipients.push({version:0,issuer:t.issuer.attributes,serialNumber:t.serialNumber,encryptedContent:{algorithm:oi.pki.oids.rsaEncryption,key:t.publicKey}})},encrypt:function(t,r){if(void 0===e.encryptedContent.content){var a,n,i;switch(r=r||e.encryptedContent.algorithm,t=t||e.encryptedContent.key,r){case oi.pki.oids["aes128-CBC"]:a=16,n=16,i=oi.aes.createEncryptionCipher;break;case oi.pki.oids["aes192-CBC"]:a=24,n=16,i=oi.aes.createEncryptionCipher;break;case oi.pki.oids["aes256-CBC"]:a=32,n=16,i=oi.aes.createEncryptionCipher;break;case oi.pki.oids["des-EDE3-CBC"]:a=24,n=8,i=oi.des.createEncryptionCipher;break;default:throw new Error("Unsupported symmetric cipher, OID "+r)}if(void 0===t)t=oi.util.createBuffer(oi.random.getBytes(a));else if(t.length()!=a)throw new Error("Symmetric key has wrong length; got "+t.length()+" bytes, expected "+a+".");e.encryptedContent.algorithm=r,e.encryptedContent.key=t,e.encryptedContent.parameter=oi.util.createBuffer(oi.random.getBytes(n));var s=i(t);if(s.start(e.encryptedContent.parameter.copy()),s.update(e.content),!s.finish())throw new Error("Symmetric encryption failed.");e.encryptedContent.content=s.output}for(var o=0;o<e.recipients.length;++o){var c=e.recipients[o];if(void 0===c.encryptedContent.content){if(c.encryptedContent.algorithm!==oi.pki.oids.rsaEncryption)throw new Error("Unsupported asymmetric cipher, OID "+c.encryptedContent.algorithm);c.encryptedContent.content=c.encryptedContent.key.encrypt(e.encryptedContent.key.data)}}}},e};var vi=f,mi=vi.ssh=vi.ssh||{};function Ci(e,t){var r=t.toString(16);r[0]>="8"&&(r="00"+r);var a=vi.util.hexToBytes(r);e.putInt32(a.length),e.putBytes(a)}function Ei(e,t){e.putInt32(t.length),e.putString(t)}function Si(){for(var e=vi.md.sha1.create(),t=arguments.length,r=0;r<t;++r)e.update(arguments[r]);return e.digest()}mi.privateKeyToPutty=function(e,t,r){var a="ssh-rsa",n=""===(t=t||"")?"none":"aes256-cbc",i="PuTTY-User-Key-File-2: "+a+"\r\n";i+="Encryption: "+n+"\r\n",i+="Comment: "+(r=r||"")+"\r\n";var s=vi.util.createBuffer();Ei(s,a),Ci(s,e.e),Ci(s,e.n);var o=vi.util.encode64(s.bytes(),64),c=Math.floor(o.length/66)+1;i+="Public-Lines: "+c+"\r\n",i+=o;var l,u=vi.util.createBuffer();if(Ci(u,e.d),Ci(u,e.p),Ci(u,e.q),Ci(u,e.qInv),t){var p=u.length()+16-1;p-=p%16;var d=Si(u.bytes());d.truncate(d.length()-p+u.length()),u.putBuffer(d);var h=vi.util.createBuffer();h.putBuffer(Si("\0\0\0\0",t)),h.putBuffer(Si("\0\0\0",t));var f=vi.aes.createEncryptionCipher(h.truncate(8),"CBC");f.start(vi.util.createBuffer().fillWithByte(0,16)),f.update(u.copy()),f.finish();var y=f.output;y.truncate(16),l=vi.util.encode64(y.bytes(),64)}else l=vi.util.encode64(u.bytes(),64);i+="\r\nPrivate-Lines: "+(c=Math.floor(l.length/66)+1)+"\r\n",i+=l;var g=Si("putty-private-key-file-mac-key",t),v=vi.util.createBuffer();Ei(v,a),Ei(v,n),Ei(v,r),v.putInt32(s.length()),v.putBuffer(s),v.putInt32(u.length()),v.putBuffer(u);var m=vi.hmac.create();return m.start("sha1",g),m.update(v.bytes()),i+="\r\nPrivate-MAC: "+m.digest().toHex()+"\r\n"},mi.publicKeyToOpenSSH=function(e,t){var r="ssh-rsa";t=t||"";var a=vi.util.createBuffer();return Ei(a,r),Ci(a,e.e),Ci(a,e.n),r+" "+vi.util.encode64(a.bytes())+" "+t},mi.privateKeyToOpenSSH=function(e,t){return t?vi.pki.encryptRsaPrivateKey(e,t,{legacy:!0,algorithm:"aes128"}):vi.pki.privateKeyToPem(e)},mi.getPublicKeyFingerprint=function(e,t){var r=(t=t||{}).md||vi.md.md5.create(),a=vi.util.createBuffer();Ei(a,"ssh-rsa"),Ci(a,e.e),Ci(a,e.n),r.start(),r.update(a.getBytes());var n=r.digest();if("hex"===t.encoding){var i=n.toHex();return t.delimiter?i.match(/.{2}/g).join(t.delimiter):i}if("binary"===t.encoding)return n.getBytes();if(t.encoding)throw new Error('Unknown encoding "'+t.encoding+'".');return n};var bi=h(f);const Ti="009c7b3ba621a26c4b02f48cfc07ef6ee0aed8e12b4bd11c5cc0abf80d5206be69e1891e60fc88e2d565e2fabe4d0cf630e318a6c721c3ded718d0c530cdf050387ad0a30a336899bbda877d0ec7c7c3ffe693988bfae0ffbab71b25468c7814924f022cb5fda36e0d2c30a7161fa1c6fb5fbd7d05adbef7e68d48f8b6c5f511827c4b1c5ed15b6f20555affc4d0857ef7ab2b5c18ba22bea5d3a79bd1834badb5878d8c7a4b19da20c1f62340b1f7fbf01d2f2e97c9714a9df376ac0ea58072b2b77aeb7872b54a89667519de44d0fc73540beeaec4cb778a45eebfbefe2d817a8a8319b2bc6d9fa714f5289ec7c0dbc43496d71cf2a642cb679b0fc4072fd2cf",Ii="010001",Ai=async({version:e,pan:t,pin:r,expiryDate:a,cvv:n})=>{try{const i=`${e}Z${t}Z${r}Z${a}Z${n}`,s=bi.util.hexToBytes((e=>{let t="";for(let r=0;r<e.length;r++)t+=e.charCodeAt(r).toString(16).padStart(2,"0");return t})(i)),o=bi.pki.rsa,c=new bi.jsbn.BigInteger(Ti,16),l=new bi.jsbn.BigInteger(Ii,16),u=o.setPublicKey(c,l),p=bi.util.createBuffer();p.putBytes(s);const d=u.encrypt(p.getBytes());return bi.util.encode64(d)}catch(e){throw console.error("[VoxePay] Encryption error:",e),new Error("Failed to encrypt card data")}},Bi=e=>{const t=e.replace(/\s|\//g,"");if(4!==t.length)return"";const r=t.substring(0,2);return`${t.substring(2,4)}${r}`},xi=e=>e.replace(/\s/g,"");class wi{constructor(e,t){this.apiKey=e,this.baseUrl=t||"https://devpay.voxepay.app"}async request(e,t){const r=`${this.baseUrl}${e}`,a=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.apiKey,Accept:"application/json"},body:JSON.stringify(t)}),n=await a.json();if(!a.ok){const e=(null==n?void 0:n.message)||(null==n?void 0:n.error)||`Request failed with status ${a.status}`,t=new Error(e);throw t.code=(null==n?void 0:n.code)||`HTTP_${a.status}`,t.status=a.status,t.data=n,t}return n}async initiatePayment(e){return this.request("/api/v1/payments/initiate",e)}async validateOTP(e){return this.request("/api/v1/payments/validate-otp",e)}async resendOTP(e){await this.request("/api/v1/payments/resend-otp",e)}}const Ni='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />\n </svg>',ki='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />\n </svg>',Ri='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">\n <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />\n </svg>',Li='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" />\n </svg>',_i='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />\n </svg>',Di='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M3 21h18M3 10h18M5 6l7-3 7 3M4 10v11M20 10v11M8 14v3M12 14v3M16 14v3" />\n </svg>',Ui='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />\n </svg>',Pi='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />\n </svg>',Vi={visa:"VISA",mastercard:"MC",amex:"AMEX",verve:"VERVE",discover:"DISC"};class Oi{constructor(e){this.container=null,this.overlay=null,this.apiClient=null,this.handleEscape=e=>{"Escape"===e.key&&(this.close(),document.removeEventListener("keydown",this.handleEscape))},this.options=e;const t=e.paymentMethods||["card","bank_transfer"];e._sdkConfig&&(this.apiClient=new wi(e._sdkConfig.apiKey,e._sdkConfig.baseUrl)),this.state={cardNumber:"",expiry:"",cvv:"",otp:"",errors:{},isProcessing:!1,isSuccess:!1,isOtpStep:!1,otpTimer:60,canResendOtp:!1,otpTimerInterval:null,paymentMethod:t[0],transferTimer:0,transferTimerInterval:null,bankTransferDetails:e.bankTransferDetails||null,paymentId:null,transactionId:null,transactionRef:null,eciFlag:null}}open(){this.injectStyles(),this.render(),this.attachEventListeners(),requestAnimationFrame(()=>{var e;null===(e=this.overlay)||void 0===e||e.classList.add("voxepay-visible")})}close(){var e;this.stopTransferTimer(),null===(e=this.overlay)||void 0===e||e.classList.remove("voxepay-visible"),setTimeout(()=>{var e,t,r;null===(e=this.container)||void 0===e||e.remove(),this.container=null,this.overlay=null,null===(r=(t=this.options).onClose)||void 0===r||r.call(t)},300)}injectStyles(){if(document.getElementById("voxepay-checkout-styles"))return;const e=document.createElement("style");e.id="voxepay-checkout-styles",e.textContent=this.getStyles(),document.head.appendChild(e)}render(){this.container=document.createElement("div"),this.container.className="voxepay-checkout",this.container.innerHTML=this.getModalHTML(),document.body.appendChild(this.container),this.overlay=this.container.querySelector(".voxepay-overlay")}getPaymentMethods(){return this.options.paymentMethods||["card","bank_transfer"]}getModalHTML(){const e=p(this.options.amount,this.options.currency),t=this.getPaymentMethods(),r=t.length>1,a="card"===this.state.paymentMethod;return`\n <div class="voxepay-overlay">\n <div class="voxepay-modal" role="dialog" aria-modal="true" aria-labelledby="voxepay-title">\n <div class="voxepay-header">\n <div class="voxepay-header-left">\n <div class="voxepay-logo">V</div>\n <div>\n <div class="voxepay-amount" id="voxepay-title">Pay ${e}</div>\n ${this.options.description?`<div style="font-size: 0.875rem; color: var(--voxepay-text-muted);">${this.options.description}</div>`:""}\n </div>\n </div>\n <button class="voxepay-close" aria-label="Close" data-action="close">\n ${Ni}\n </button>\n </div>\n\n ${r?`\n <div class="voxepay-method-tabs">\n ${t.includes("card")?`\n <button class="voxepay-method-tab ${a?"active":""}" data-method="card">\n ${Ui} <span>Card</span>\n </button>`:""}\n ${t.includes("bank_transfer")?`\n <button class="voxepay-method-tab ${a?"":"active"}" data-method="bank_transfer">\n ${Di} <span>Bank Transfer</span>\n </button>`:""}\n </div>`:""}\n \n <div class="voxepay-body" id="voxepay-form-container">\n ${a?this.getCardFormHTML(e):this.getBankTransferHTML(e)}\n </div>\n \n <div class="voxepay-footer">\n <div class="voxepay-powered-by">\n ${ki}\n <span>Secured by <strong>VoxePay</strong></span>\n </div>\n </div>\n </div>\n </div>\n `}getCardFormHTML(e){return`\n <form id="voxepay-payment-form" novalidate>\n <div class="voxepay-form-group">\n <label class="voxepay-label">\n <span class="voxepay-label-icon">💳</span>\n Card Number\n </label>\n <div class="voxepay-card-input-wrapper">\n <input type="text" class="voxepay-input" id="voxepay-card-number" name="cardNumber"\n placeholder="1234 5678 9012 3456" autocomplete="cc-number" inputmode="numeric" />\n <div class="voxepay-card-brand" id="voxepay-card-brand"></div>\n </div>\n <div class="voxepay-error-message" id="voxepay-card-error" style="display: none;"></div>\n </div>\n \n <div class="voxepay-row">\n <div class="voxepay-form-group">\n <label class="voxepay-label"><span class="voxepay-label-icon">📅</span> Expiry</label>\n <input type="text" class="voxepay-input" id="voxepay-expiry" name="expiry"\n placeholder="MM/YY" autocomplete="cc-exp" inputmode="numeric" maxlength="5" />\n <div class="voxepay-error-message" id="voxepay-expiry-error" style="display: none;"></div>\n </div>\n <div class="voxepay-form-group">\n <label class="voxepay-label"><span class="voxepay-label-icon">🔒</span> CVV</label>\n <input type="text" class="voxepay-input" id="voxepay-cvv" name="cvv"\n placeholder="•••" autocomplete="cc-csc" inputmode="numeric" maxlength="4" />\n <div class="voxepay-error-message" id="voxepay-cvv-error" style="display: none;"></div>\n </div>\n </div>\n \n <button type="submit" class="voxepay-submit-btn" id="voxepay-submit">\n <span>Pay Now ${e}</span>\n </button>\n </form>\n `}getBankTransferHTML(e){const t=this.state.bankTransferDetails;return t?`\n <div class="voxepay-transfer-view">\n <div class="voxepay-transfer-instruction">\n <p>Transfer <strong>${e}</strong> to the account below</p>\n </div>\n\n <div class="voxepay-transfer-details">\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Account Number</span>\n <div class="voxepay-transfer-value-row">\n <span class="voxepay-transfer-value voxepay-transfer-account" id="voxepay-account-number">${t.accountNumber}</span>\n <button class="voxepay-copy-btn" id="voxepay-copy-btn" data-copy="${t.accountNumber}" title="Copy">\n ${_i}\n </button>\n </div>\n </div>\n\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Bank Name</span>\n <span class="voxepay-transfer-value">${t.bankName}</span>\n </div>\n\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Account Name</span>\n <span class="voxepay-transfer-value">${t.accountName}</span>\n </div>\n\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Amount</span>\n <span class="voxepay-transfer-value voxepay-transfer-amount">${e}</span>\n </div>\n\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Reference</span>\n <span class="voxepay-transfer-value" style="font-family: monospace; letter-spacing: 1px;">${t.reference}</span>\n </div>\n </div>\n\n <div class="voxepay-transfer-timer" id="voxepay-transfer-timer">\n ${Pi}\n <span>Account expires in <strong id="voxepay-transfer-countdown">${this.formatCountdown(t.expiresIn)}</strong></span>\n </div>\n\n <button type="button" class="voxepay-submit-btn" id="voxepay-transfer-confirm">\n <span>I've sent the money</span>\n </button>\n </div>\n `:'\n <div class="voxepay-transfer-view">\n <div class="voxepay-transfer-loading">\n <div class="voxepay-spinner"></div>\n <p style="margin-top: 16px; color: var(--voxepay-text-muted);">Generating account details...</p>\n </div>\n </div>\n '}formatCountdown(e){const t=Math.floor(e/60),r=e%60;return`${String(t).padStart(2,"0")}:${String(r).padStart(2,"0")}`}renderSuccessView(){var e;const t=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-form-container");if(!t)return;const r=p(this.options.amount,this.options.currency);t.innerHTML=`\n <div class="voxepay-success-view">\n <div class="voxepay-success-icon">\n ${Ri}\n </div>\n <h2 class="voxepay-success-title">Payment Successful!</h2>\n <p class="voxepay-success-message">Your payment of ${r} has been processed.</p>\n <button class="voxepay-success-btn" data-action="close">Done</button>\n </div>\n `;const a=t.querySelector('[data-action="close"]');null==a||a.addEventListener("click",()=>this.close())}renderOTPView(){var e;const t=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-form-container");if(!t)return;this.state.isOtpStep=!0,this.state.otpTimer=60,this.state.canResendOtp=!1;const r=this.options.customerEmail?`****${this.options.customerEmail.slice(-4)}`:"****1234";t.innerHTML=`\n <div class="voxepay-otp-view">\n <div class="voxepay-otp-header">\n <div class="voxepay-otp-icon">📱</div>\n <h3 class="voxepay-otp-title">Verify Your Payment</h3>\n <p class="voxepay-otp-subtitle">We've sent a 6-digit code to ${r}</p>\n </div>\n \n <div class="voxepay-otp-inputs-container">\n <div class="voxepay-otp-inputs" id="voxepay-otp-inputs">\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="0" inputmode="numeric" autocomplete="one-time-code" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="1" inputmode="numeric" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="2" inputmode="numeric" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="3" inputmode="numeric" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="4" inputmode="numeric" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="5" inputmode="numeric" />\n </div>\n <div class="voxepay-error-message" id="voxepay-otp-error" style="display: none;"></div>\n </div>\n\n <div class="voxepay-otp-timer" id="voxepay-otp-timer">\n Resend code in <span id="voxepay-timer-count">60</span>s\n </div>\n \n <button class="voxepay-resend-btn" id="voxepay-resend-otp" disabled>\n Resend OTP\n </button>\n \n <button type="button" class="voxepay-submit-btn" id="voxepay-verify-otp">\n <span>🔐 Verify & Pay</span>\n </button>\n \n <button class="voxepay-back-btn" id="voxepay-back-to-card">\n ← Back to card details\n </button>\n </div>\n `,this.attachOTPEventListeners(),this.startOTPTimer()}attachOTPEventListeners(){var e,t,r,a,n;const i=null===(e=this.container)||void 0===e?void 0:e.querySelectorAll(".voxepay-otp-digit");null==i||i.forEach((e,t)=>{e.addEventListener("input",e=>this.handleOTPInput(e,t)),e.addEventListener("keydown",e=>this.handleOTPKeydown(e,t)),e.addEventListener("paste",e=>this.handleOTPPaste(e))});const s=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-verify-otp");null==s||s.addEventListener("click",()=>this.handleOTPSubmit());const o=null===(r=this.container)||void 0===r?void 0:r.querySelector("#voxepay-resend-otp");null==o||o.addEventListener("click",()=>this.handleResendOTP());const c=null===(a=this.container)||void 0===a?void 0:a.querySelector("#voxepay-back-to-card");null==c||c.addEventListener("click",()=>this.handleBackToCard()),null===(n=null==i?void 0:i[0])||void 0===n||n.focus()}handleOTPInput(e,t){var r;const a=e.target,n=a.value.replace(/\D/g,"");if(a.value=n,n&&t<5){const e=null===(r=this.container)||void 0===r?void 0:r.querySelector(`[data-index="${t+1}"]`);null==e||e.focus()}this.updateOTPState(),this.clearError("otp")}handleOTPKeydown(e,t){var r;const a=e.target;if("Backspace"===e.key&&!a.value&&t>0){const e=null===(r=this.container)||void 0===r?void 0:r.querySelector(`[data-index="${t-1}"]`);null==e||e.focus()}}handleOTPPaste(e){var t,r;e.preventDefault();const a=null===(t=e.clipboardData)||void 0===t?void 0:t.getData("text").replace(/\D/g,"").slice(0,6);if(a){const e=null===(r=this.container)||void 0===r?void 0:r.querySelectorAll(".voxepay-otp-digit");a.split("").forEach((t,r)=>{e[r]&&(e[r].value=t)}),this.updateOTPState()}}updateOTPState(){var e;const t=null===(e=this.container)||void 0===e?void 0:e.querySelectorAll(".voxepay-otp-digit");let r="";null==t||t.forEach(e=>r+=e.value),this.state.otp=r}startOTPTimer(){var e,t,r;const a=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-timer-count"),n=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-otp-timer"),i=null===(r=this.container)||void 0===r?void 0:r.querySelector("#voxepay-resend-otp");this.state.otpTimerInterval=window.setInterval(()=>{this.state.otpTimer--,a&&(a.textContent=String(this.state.otpTimer)),this.state.otpTimer<=0&&(this.state.otpTimerInterval&&clearInterval(this.state.otpTimerInterval),this.state.canResendOtp=!0,n&&(n.style.display="none"),i&&(i.disabled=!1))},1e3)}async handleOTPSubmit(){if(6===this.state.otp.length){this.setOTPProcessing(!0);try{await this.verifyOTP(),this.state.otpTimerInterval&&clearInterval(this.state.otpTimerInterval);const e=await this.processPayment();this.state.isSuccess=!0,this.renderSuccessView(),this.options.onSuccess(e)}catch(e){this.setOTPProcessing(!1);const t=e;this.showError("otp",t.message||"Invalid OTP. Please try again.")}}else this.showError("otp","Please enter the complete 6-digit code")}setOTPProcessing(e){var t;const r=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-verify-otp");r&&(r.disabled=e,r.innerHTML=e?'<div class="voxepay-spinner"></div><span>Verifying...</span>':"<span>🔐 Verify & Pay</span>")}async verifyOTP(){if(!this.apiClient||!this.options._sdkConfig)throw{code:"SDK_ERROR",message:"SDK not properly initialized",recoverable:!1};if(6!==this.state.otp.length)throw{code:"INVALID_OTP",message:"Please enter the complete 6-digit code",recoverable:!0};if(!this.state.paymentId||!this.state.transactionId)throw{code:"MISSING_PAYMENT_DATA",message:"Payment session expired. Please try again.",recoverable:!1};await this.apiClient.validateOTP({paymentId:this.state.paymentId,otp:this.state.otp,transactionId:this.state.transactionId,eciFlag:this.state.eciFlag||void 0,organizationId:this.options._sdkConfig.organizationId})}async handleResendOTP(){var e,t,r,a;const n=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-otp-timer"),i=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-resend-otp");if(this.apiClient&&this.options._sdkConfig&&this.state.transactionRef)try{i&&(i.disabled=!0),await this.apiClient.resendOTP({transactionRef:this.state.transactionRef,organizationId:this.options._sdkConfig.organizationId})}catch(e){console.error("[VoxePay] Failed to resend OTP:",e)}this.state.otpTimer=60,this.state.canResendOtp=!1,n&&(n.style.display="block"),i&&(i.disabled=!0);const s=null===(r=this.container)||void 0===r?void 0:r.querySelectorAll(".voxepay-otp-digit");null==s||s.forEach(e=>e.value=""),this.state.otp="",this.startOTPTimer(),null===(a=null==s?void 0:s[0])||void 0===a||a.focus()}handleBackToCard(){var e;if(this.state.otpTimerInterval&&clearInterval(this.state.otpTimerInterval),this.state.isOtpStep=!1,this.state.otp="",this.container){this.container.innerHTML=this.getModalHTML(),this.overlay=this.container.querySelector(".voxepay-overlay"),null===(e=this.overlay)||void 0===e||e.classList.add("voxepay-visible"),this.attachEventListeners();const t=this.container.querySelector("#voxepay-card-number"),r=this.container.querySelector("#voxepay-expiry"),a=this.container.querySelector("#voxepay-cvv");t&&(t.value=c(this.state.cardNumber)),r&&(r.value=this.state.expiry),a&&(a.value=this.state.cvv)}}attachEventListeners(){var e,t,r,a,n,i,s;const o=null===(e=this.container)||void 0===e?void 0:e.querySelector('[data-action="close"]');null==o||o.addEventListener("click",()=>this.close()),null===(t=this.overlay)||void 0===t||t.addEventListener("click",e=>{e.target===this.overlay&&this.close()}),document.addEventListener("keydown",this.handleEscape);const c=null===(r=this.container)||void 0===r?void 0:r.querySelectorAll(".voxepay-method-tab");if(null==c||c.forEach(e=>{e.addEventListener("click",()=>{const t=e.dataset.method;t&&t!==this.state.paymentMethod&&this.switchPaymentMethod(t)})}),"card"===this.state.paymentMethod){const e=null===(a=this.container)||void 0===a?void 0:a.querySelector("#voxepay-card-number");null==e||e.addEventListener("input",e=>this.handleCardInput(e)),null==e||e.addEventListener("blur",()=>this.validateField("cardNumber"));const t=null===(n=this.container)||void 0===n?void 0:n.querySelector("#voxepay-expiry");null==t||t.addEventListener("input",e=>this.handleExpiryInput(e)),null==t||t.addEventListener("blur",()=>this.validateField("expiry"));const r=null===(i=this.container)||void 0===i?void 0:i.querySelector("#voxepay-cvv");null==r||r.addEventListener("input",e=>this.handleCVVInput(e)),null==r||r.addEventListener("blur",()=>this.validateField("cvv"));const o=null===(s=this.container)||void 0===s?void 0:s.querySelector("#voxepay-payment-form");null==o||o.addEventListener("submit",e=>this.handleSubmit(e))}"bank_transfer"===this.state.paymentMethod&&(this.attachBankTransferListeners(),this.state.bankTransferDetails?this.startTransferTimer():this.loadBankTransferDetails())}attachBankTransferListeners(){var e,t;const r=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-copy-btn");null==r||r.addEventListener("click",()=>{const e=r.dataset.copy||"";this.copyToClipboard(e)});const a=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-transfer-confirm");null==a||a.addEventListener("click",()=>this.handleTransferConfirm())}switchPaymentMethod(e){var t;if(this.stopTransferTimer(),this.state.paymentMethod=e,this.container&&(this.container.innerHTML=this.getModalHTML(),this.overlay=this.container.querySelector(".voxepay-overlay"),null===(t=this.overlay)||void 0===t||t.classList.add("voxepay-visible"),this.attachEventListeners(),"card"===e&&this.state.cardNumber)){const e=this.container.querySelector("#voxepay-card-number"),t=this.container.querySelector("#voxepay-expiry"),r=this.container.querySelector("#voxepay-cvv");e&&(e.value=c(this.state.cardNumber)),t&&(t.value=this.state.expiry),r&&(r.value=this.state.cvv)}}async loadBankTransferDetails(){var e;try{let t;this.options.onBankTransferRequested?t=await this.options.onBankTransferRequested():(await new Promise(e=>setTimeout(e,1500)),t={accountNumber:"0123456789",bankName:"VoxePay Bank",accountName:"VoxePay Collections",reference:`VP-${Date.now().toString(36).toUpperCase()}`,expiresIn:1800}),this.state.bankTransferDetails=t;const r=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-form-container");if(r){const e=p(this.options.amount,this.options.currency);r.innerHTML=this.getBankTransferHTML(e),this.attachBankTransferListeners(),this.startTransferTimer()}}catch(e){this.options.onError({code:"BANK_TRANSFER_INIT_FAILED",message:"Could not generate bank transfer details. Please try again.",recoverable:!0})}}async copyToClipboard(e){var t;try{await navigator.clipboard.writeText(e);const r=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-copy-btn");r&&(r.innerHTML=`${Ri}`,r.classList.add("voxepay-copied"),setTimeout(()=>{r.innerHTML=`${_i}`,r.classList.remove("voxepay-copied")},2e3))}catch(t){const r=document.createElement("textarea");r.value=e,r.style.position="fixed",r.style.opacity="0",document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r)}}async handleTransferConfirm(){var e,t;const r=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-transfer-confirm");r&&(r.disabled=!0,r.innerHTML='<div class="voxepay-spinner"></div><span>Confirming transfer...</span>'),this.stopTransferTimer();try{await new Promise(e=>setTimeout(e,3e3));const e={id:`pay_transfer_${Date.now()}`,status:"pending",amount:this.options.amount,currency:this.options.currency,timestamp:(new Date).toISOString(),reference:null===(t=this.state.bankTransferDetails)||void 0===t?void 0:t.reference,paymentMethod:"bank_transfer"};this.state.isSuccess=!0,this.renderSuccessView(),this.options.onSuccess(e)}catch(e){r&&(r.disabled=!1,r.innerHTML="<span>I've sent the money</span>");const t=e;this.options.onError(t)}}startTransferTimer(){this.state.bankTransferDetails&&(this.state.transferTimer=this.state.bankTransferDetails.expiresIn,this.state.transferTimerInterval=window.setInterval(()=>{var e,t,r;this.state.transferTimer--;const a=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-transfer-countdown");if(a&&(a.textContent=this.formatCountdown(this.state.transferTimer)),this.state.transferTimer<=0){this.stopTransferTimer();const e=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-transfer-timer");e&&(e.innerHTML=`${Pi} <span style="color: var(--voxepay-error);">Account expired. Please try again.</span>`);const a=null===(r=this.container)||void 0===r?void 0:r.querySelector("#voxepay-transfer-confirm");a&&(a.disabled=!0)}},1e3))}stopTransferTimer(){this.state.transferTimerInterval&&(clearInterval(this.state.transferTimerInterval),this.state.transferTimerInterval=null)}handleCardInput(e){var t;const r=e.target,n=c(r.value);r.value=n,this.state.cardNumber=n.replace(/\s/g,"");const i=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-card-brand"),s=a(this.state.cardNumber);i&&(i.textContent=s&&Vi[s.code]||"",i.style.opacity=s?"1":"0"),this.clearError("cardNumber")}handleExpiryInput(e){const t=e.target,r=l(t.value);t.value=r,this.state.expiry=r,this.clearError("expiry")}handleCVVInput(e){const t=e.target,r=u(t.value);t.value=r,this.state.cvv=r,this.clearError("cvv")}validateField(e){let t;switch(e){case"cardNumber":t=i(this.state.cardNumber);break;case"expiry":t=s(this.state.expiry);break;case"cvv":t=o(this.state.cvv,this.state.cardNumber);break;default:return!0}return t.valid?(this.clearError(e),!0):(this.showError(e,t.error||"Invalid"),!1)}showError(e,t){var r,a;const n=null===(r=this.container)||void 0===r?void 0:r.querySelector(`#voxepay-${"cardNumber"===e?"card":e}-error`),i=null===(a=this.container)||void 0===a?void 0:a.querySelector(`#voxepay-${"cardNumber"===e?"card-number":e}`);n&&(n.innerHTML=`${Li} ${t}`,n.style.display="flex"),null==i||i.classList.add("voxepay-error")}clearError(e){var t,r;const a=null===(t=this.container)||void 0===t?void 0:t.querySelector(`#voxepay-${"cardNumber"===e?"card":e}-error`),n=null===(r=this.container)||void 0===r?void 0:r.querySelector(`#voxepay-${"cardNumber"===e?"card-number":e}`);a&&(a.style.display="none"),null==n||n.classList.remove("voxepay-error")}async handleSubmit(e){e.preventDefault();const t=this.validateField("cardNumber"),r=this.validateField("expiry"),a=this.validateField("cvv");if(t&&r&&a)if(this.apiClient&&this.options._sdkConfig){this.setProcessing(!0);try{const e=xi(this.state.cardNumber),t=Bi(this.state.expiry),r=await Ai({version:"1",pan:e,pin:"",expiryDate:t,cvv:this.state.cvv}),a=`VP-${Date.now().toString(36).toUpperCase()}-${Math.random().toString(36).substring(2,8).toUpperCase()}`,n=await this.apiClient.initiatePayment({organizationId:this.options._sdkConfig.organizationId,transactionRef:a,customerEmail:this.options.customerEmail,customerPhone:this.options.customerPhone,amount:this.options.amount/100,currency:this.options.currency,paymentMethod:"CARD",authData:r,narration:this.options.description});this.state.paymentId=n.paymentId,this.state.transactionId=n.transactionId,this.state.transactionRef=n.transactionRef||a,this.state.eciFlag=n.eciFlag||null,this.setProcessing(!1),this.renderOTPView()}catch(e){this.setProcessing(!1);const t=(null==e?void 0:e.message)||"Payment failed. Please try again.";this.options.onError({code:(null==e?void 0:e.code)||"PAYMENT_INITIATE_FAILED",message:t,recoverable:!0,details:null==e?void 0:e.data}),this.showError("cardNumber",t)}}else this.showError("cardNumber","SDK not properly initialized. Missing API key or organization ID.")}setProcessing(e){var t;this.state.isProcessing=e;const r=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-submit");r&&(r.disabled=e,r.innerHTML=e?'<div class="voxepay-spinner"></div><span>Processing...</span>':`<span>Pay Now ${p(this.options.amount,this.options.currency)}</span>`)}async processPayment(){return{id:this.state.paymentId||`pay_${Date.now()}`,status:"success",amount:this.options.amount,currency:this.options.currency,timestamp:(new Date).toISOString(),reference:this.state.transactionRef||void 0,paymentMethod:"card"}}getStyles(){return"\n :root {\n /* VoxePay Blue Color Palette */\n --voxepay-primary: #0061FF;\n --voxepay-primary-hover: #0056E0;\n --voxepay-secondary: #0047CC;\n --voxepay-accent: #60A5FA;\n --voxepay-glow: rgba(0, 97, 255, 0.35);\n --voxepay-success: #10B981;\n --voxepay-success-bg: rgba(16, 185, 129, 0.1);\n --voxepay-error: #EF4444;\n \n /* Dark Mode (Default) */\n --voxepay-bg: #0C0C1D;\n --voxepay-surface: rgba(255, 255, 255, 0.04);\n --voxepay-surface-hover: rgba(255, 255, 255, 0.08);\n --voxepay-border: rgba(255, 255, 255, 0.08);\n --voxepay-text: #FFFFFF;\n --voxepay-text-muted: #B4B4C7;\n --voxepay-text-subtle: #6B7280;\n --voxepay-input-bg: rgba(255, 255, 255, 0.06);\n \n /* Effects */\n --voxepay-backdrop-blur: blur(24px);\n --voxepay-border-radius: 12px;\n --voxepay-border-radius-lg: 16px;\n --voxepay-border-radius-xl: 24px;\n --voxepay-glow-shadow: 0 0 60px var(--voxepay-glow);\n --voxepay-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.6);\n --voxepay-transition-fast: 150ms ease;\n --voxepay-transition: 300ms cubic-bezier(0.4, 0, 0.2, 1);\n }\n \n /* Light Mode */\n html.voxepay-light {\n --voxepay-primary: #0061FF;\n --voxepay-primary-hover: #0056E0;\n --voxepay-secondary: #0047CC;\n --voxepay-glow: rgba(0, 97, 255, 0.2);\n \n --voxepay-bg: #FFFFFF;\n --voxepay-surface: #F8FAFC;\n --voxepay-surface-hover: #F1F5F9;\n --voxepay-border: #E2E8F0;\n --voxepay-text: #0F172A;\n --voxepay-text-muted: #475569;\n --voxepay-text-subtle: #94A3B8;\n --voxepay-input-bg: #F8FAFC;\n \n --voxepay-glow-shadow: 0 0 40px rgba(0, 97, 255, 0.12);\n --voxepay-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);\n }\n \n .voxepay-checkout * { box-sizing: border-box; margin: 0; padding: 0; }\n .voxepay-checkout { font-family: 'DM Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 1rem; color: var(--voxepay-text); line-height: 1.5; -webkit-font-smoothing: antialiased; }\n \n .voxepay-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); backdrop-filter: var(--voxepay-backdrop-blur); -webkit-backdrop-filter: var(--voxepay-backdrop-blur); display: flex; align-items: center; justify-content: center; z-index: 999999; opacity: 0; visibility: hidden; transition: opacity var(--voxepay-transition), visibility var(--voxepay-transition); }\n html.voxepay-light .voxepay-overlay { background: rgba(15, 23, 42, 0.4); }\n .voxepay-overlay.voxepay-visible { opacity: 1; visibility: visible; }\n \n .voxepay-modal { background: var(--voxepay-bg); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius-xl); width: 100%; max-width: 420px; max-height: 90vh; overflow: hidden; box-shadow: var(--voxepay-shadow), var(--voxepay-glow-shadow); transform: scale(0.95) translateY(20px); opacity: 0; transition: transform var(--voxepay-transition), opacity var(--voxepay-transition); }\n .voxepay-overlay.voxepay-visible .voxepay-modal { transform: scale(1) translateY(0); opacity: 1; }\n \n .voxepay-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }\n .voxepay-header-left { display: flex; align-items: center; gap: 12px; }\n .voxepay-logo { width: 36px; height: 36px; border-radius: var(--voxepay-border-radius); background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.25rem; color: white; box-shadow: 0 4px 12px rgba(0, 97, 255, 0.3); }\n .voxepay-amount { font-size: 1.25rem; font-weight: 600; }\n .voxepay-close { width: 36px; height: 36px; border: none; background: var(--voxepay-surface-hover); border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--voxepay-text-muted); transition: all var(--voxepay-transition-fast); }\n .voxepay-close:hover { background: var(--voxepay-border); color: var(--voxepay-text); transform: rotate(90deg); }\n .voxepay-close svg { width: 18px; height: 18px; }\n \n .voxepay-body { padding: 24px; background: var(--voxepay-bg); }\n .voxepay-form-group { margin-bottom: 20px; }\n .voxepay-label { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; font-weight: 500; color: var(--voxepay-text-muted); margin-bottom: 8px; }\n .voxepay-label-icon { font-size: 1rem; }\n \n .voxepay-input { width: 100%; padding: 14px 16px; background: var(--voxepay-input-bg); border: 1.5px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text); font-size: 1rem; font-family: inherit; outline: none; transition: border-color var(--voxepay-transition-fast), box-shadow var(--voxepay-transition-fast), background var(--voxepay-transition-fast); }\n .voxepay-input::placeholder { color: var(--voxepay-text-subtle); }\n .voxepay-input:hover { border-color: var(--voxepay-text-subtle); }\n .voxepay-input:focus { border-color: var(--voxepay-primary); box-shadow: 0 0 0 4px var(--voxepay-glow); background: var(--voxepay-bg); }\n .voxepay-input.voxepay-error { border-color: var(--voxepay-error); box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15); }\n \n .voxepay-card-input-wrapper { position: relative; }\n .voxepay-card-brand { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); padding: 4px 8px; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); border-radius: 6px; font-size: 0.7rem; font-weight: 700; color: white; opacity: 0; transition: opacity var(--voxepay-transition-fast); letter-spacing: 0.5px; }\n .voxepay-card-input-wrapper .voxepay-input { padding-right: 70px; }\n \n .voxepay-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }\n \n .voxepay-error-message { display: flex; align-items: center; gap: 6px; font-size: 0.813rem; color: var(--voxepay-error); margin-top: 8px; animation: voxepay-shake 0.4s ease; }\n .voxepay-error-message svg { width: 16px; height: 16px; flex-shrink: 0; }\n @keyframes voxepay-shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }\n \n .voxepay-submit-btn { width: 100%; padding: 16px 24px; background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); border: none; border-radius: var(--voxepay-border-radius); color: white; font-size: 1.063rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: all var(--voxepay-transition-fast); position: relative; overflow: hidden; box-shadow: 0 4px 15px rgba(0, 97, 255, 0.35); }\n .voxepay-submit-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(0, 97, 255, 0.45); }\n .voxepay-submit-btn:active:not(:disabled) { transform: translateY(0); }\n .voxepay-submit-btn:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; }\n .voxepay-submit-btn span { position: relative; z-index: 1; }\n \n .voxepay-spinner { width: 20px; height: 20px; border: 2.5px solid rgba(255, 255, 255, 0.3); border-top-color: white; border-radius: 50%; animation: voxepay-spin 0.8s linear infinite; }\n @keyframes voxepay-spin { to { transform: rotate(360deg); } }\n \n .voxepay-footer { text-align: center; padding: 16px 24px 20px; border-top: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }\n .voxepay-powered-by { font-size: 0.75rem; color: var(--voxepay-text-subtle); display: flex; align-items: center; justify-content: center; gap: 6px; }\n .voxepay-powered-by svg { width: 14px; height: 14px; color: var(--voxepay-primary); }\n .voxepay-powered-by strong { color: var(--voxepay-primary); font-weight: 600; }\n \n .voxepay-success-view { text-align: center; padding: 40px 24px; }\n .voxepay-success-icon { width: 80px; height: 80px; margin: 0 auto 24px; background: linear-gradient(135deg, var(--voxepay-success), #059669); border-radius: 50%; display: flex; align-items: center; justify-content: center; animation: voxepay-success-pop 0.5s ease; box-shadow: 0 8px 25px rgba(16, 185, 129, 0.35); }\n @keyframes voxepay-success-pop { 0% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }\n .voxepay-success-icon svg { width: 40px; height: 40px; color: white; }\n .voxepay-success-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; color: var(--voxepay-text); }\n .voxepay-success-message { font-size: 1rem; color: var(--voxepay-text-muted); margin-bottom: 24px; }\n .voxepay-success-btn { padding: 12px 32px; background: var(--voxepay-surface); border: 1.5px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text); font-size: 1rem; font-weight: 500; cursor: pointer; transition: all var(--voxepay-transition-fast); }\n .voxepay-success-btn:hover { background: var(--voxepay-surface-hover); border-color: var(--voxepay-primary); color: var(--voxepay-primary); }\n \n /* OTP View */\n .voxepay-otp-view { text-align: center; padding: 24px 16px; }\n .voxepay-otp-header { margin-bottom: 24px; }\n .voxepay-otp-icon { font-size: 3rem; margin-bottom: 12px; }\n .voxepay-otp-title { font-size: 1.25rem; font-weight: 700; color: var(--voxepay-text); margin-bottom: 8px; }\n .voxepay-otp-subtitle { font-size: 0.875rem; color: var(--voxepay-text-muted); }\n \n .voxepay-otp-inputs-container { margin-bottom: 16px; }\n .voxepay-otp-inputs { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }\n .voxepay-otp-digit { width: 48px; height: 56px; text-align: center; font-size: 1.5rem; font-weight: 700; border: 2px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); background: var(--voxepay-input-bg); color: var(--voxepay-text); outline: none; transition: all var(--voxepay-transition-fast); }\n .voxepay-otp-digit:focus { border-color: var(--voxepay-primary); box-shadow: 0 0 0 4px var(--voxepay-glow); }\n \n .voxepay-otp-timer { font-size: 0.875rem; color: var(--voxepay-text-muted); margin-bottom: 12px; }\n .voxepay-otp-timer span { font-weight: 700; color: var(--voxepay-primary); }\n \n .voxepay-resend-btn { padding: 8px 16px; background: transparent; border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text-muted); font-size: 0.875rem; cursor: pointer; margin-bottom: 16px; transition: all var(--voxepay-transition-fast); }\n .voxepay-resend-btn:hover:not(:disabled) { border-color: var(--voxepay-primary); color: var(--voxepay-primary); }\n .voxepay-resend-btn:disabled { opacity: 0.5; cursor: not-allowed; }\n \n .voxepay-back-btn { display: block; width: 100%; padding: 12px; background: transparent; border: none; color: var(--voxepay-text-muted); font-size: 0.875rem; cursor: pointer; margin-top: 12px; transition: color var(--voxepay-transition-fast); }\n .voxepay-back-btn:hover { color: var(--voxepay-primary); }\n\n /* Payment Method Tabs */\n .voxepay-method-tabs { display: flex; border-bottom: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }\n .voxepay-method-tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 12px; border: none; background: transparent; color: var(--voxepay-text-muted); font-size: 0.813rem; font-weight: 500; font-family: inherit; cursor: pointer; transition: all var(--voxepay-transition-fast); border-bottom: 2px solid transparent; white-space: nowrap; }\n .voxepay-method-tab svg { width: 16px; height: 16px; flex-shrink: 0; }\n .voxepay-method-tab:hover { color: var(--voxepay-text); background: var(--voxepay-surface-hover); }\n .voxepay-method-tab.active { color: var(--voxepay-primary); border-bottom-color: var(--voxepay-primary); background: var(--voxepay-bg); }\n\n /* Bank Transfer View */\n .voxepay-transfer-view { padding: 4px 0; }\n .voxepay-transfer-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 0; }\n .voxepay-transfer-instruction { text-align: center; margin-bottom: 20px; font-size: 0.938rem; color: var(--voxepay-text-muted); }\n .voxepay-transfer-instruction strong { color: var(--voxepay-text); font-size: 1.063rem; }\n .voxepay-transfer-details { background: var(--voxepay-surface); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); overflow: hidden; margin-bottom: 16px; }\n .voxepay-transfer-detail { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--voxepay-border); }\n .voxepay-transfer-detail:last-child { border-bottom: none; }\n .voxepay-transfer-label { font-size: 0.813rem; color: var(--voxepay-text-muted); font-weight: 500; }\n .voxepay-transfer-value { font-size: 0.938rem; font-weight: 600; color: var(--voxepay-text); }\n .voxepay-transfer-value-row { display: flex; align-items: center; gap: 8px; }\n .voxepay-transfer-account { font-size: 1.125rem; font-weight: 700; color: var(--voxepay-primary); letter-spacing: 1.5px; font-family: 'DM Sans', monospace; }\n .voxepay-transfer-amount { color: var(--voxepay-primary); }\n\n /* Copy Button */\n .voxepay-copy-btn { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid var(--voxepay-border); border-radius: 8px; background: var(--voxepay-surface-hover); color: var(--voxepay-text-muted); cursor: pointer; transition: all var(--voxepay-transition-fast); flex-shrink: 0; }\n .voxepay-copy-btn svg { width: 16px; height: 16px; }\n .voxepay-copy-btn:hover { border-color: var(--voxepay-primary); color: var(--voxepay-primary); background: rgba(0, 97, 255, 0.1); }\n .voxepay-copy-btn.voxepay-copied { border-color: var(--voxepay-success); color: var(--voxepay-success); background: var(--voxepay-success-bg); }\n\n /* Transfer Timer */\n .voxepay-transfer-timer { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; background: var(--voxepay-surface); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); margin-bottom: 16px; font-size: 0.875rem; color: var(--voxepay-text-muted); }\n .voxepay-transfer-timer svg { width: 16px; height: 16px; color: var(--voxepay-primary); flex-shrink: 0; }\n .voxepay-transfer-timer strong { color: var(--voxepay-primary); font-weight: 700; font-family: monospace; font-size: 0.938rem; }\n \n @media (max-width: 480px) { .voxepay-modal { max-width: 100%; max-height: 100%; border-radius: 0; height: 100%; } .voxepay-body { padding: 20px; } .voxepay-otp-digit { width: 42px; height: 50px; font-size: 1.25rem; } .voxepay-transfer-detail { flex-direction: column; align-items: flex-start; gap: 4px; } }\n "}}class Ki{constructor(){this.config=null,this.currentModal=null,this.initialized=!1}init(e){e.apiKey?e.organizationId?(this.config={theme:"dark",locale:"en-US",...e},this.initialized=!0,"auto"===e.theme?this.applyAutoTheme():"light"===e.theme&&document.documentElement.classList.add("voxepay-light"),e.customStyles&&this.applyCustomStyles(e.customStyles),console.log("[VoxePay] Initialized successfully")):console.error("[VoxePay] Organization ID is required. Find it in your VoxePay dashboard."):console.error("[VoxePay] API key is required. Get your API key from the VoxePay dashboard: Settings > API Keys")}checkout(e){return this.initialized?!e.amount||e.amount<=0?(console.error("[VoxePay] Invalid amount"),void e.onError({code:"INVALID_AMOUNT",message:"Payment amount must be greater than 0",recoverable:!1})):e.currency?(this.closeModal(),this.currentModal=new Oi({...e,_sdkConfig:{apiKey:this.config.apiKey,organizationId:this.config.organizationId,baseUrl:this.config.baseUrl},onClose:()=>{var t;this.currentModal=null,null===(t=e.onClose)||void 0===t||t.call(e)}}),void this.currentModal.open()):(console.error("[VoxePay] Currency is required"),void e.onError({code:"INVALID_CURRENCY",message:"Currency code is required",recoverable:!1})):(console.error("[VoxePay] Not initialized. Call VoxePay.init() first."),void e.onError({code:"NOT_INITIALIZED",message:"VoxePay SDK not initialized. Call VoxePay.init() first.",recoverable:!1}))}closeModal(){this.currentModal&&(this.currentModal.close(),this.currentModal=null)}setTheme(e){document.documentElement.classList.remove("voxepay-light"),"light"===e?document.documentElement.classList.add("voxepay-light"):"auto"===e&&this.applyAutoTheme(),this.config&&(this.config.theme=e)}applyAutoTheme(){window.matchMedia("(prefers-color-scheme: dark)").matches||document.documentElement.classList.add("voxepay-light"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{var t;"auto"===(null===(t=this.config)||void 0===t?void 0:t.theme)&&document.documentElement.classList.toggle("voxepay-light",!e.matches)})}applyCustomStyles(e){const t=document.documentElement;for(const[r,a]of Object.entries(e))a&&t.style.setProperty(r,a)}get version(){return"0.3.0"}get isInitialized(){return this.initialized}}const Mi=new Ki;return"undefined"!=typeof window&&(window.VoxePay=Mi),e.VoxePay=Mi,e.VoxePaySDK=Ki,e.cleanPan=xi,e.default=Mi,e.detectCardBrand=a,e.formatAmount=p,e.formatCVV=u,e.formatCardNumber=c,e.formatExpiry=l,e.formatExpiryForApi=Bi,e.generateAuthData=Ai,e.getCurrencySymbol=function(e){return{NGN:"₦",USD:"$",EUR:"€",GBP:"£",GHS:"₵",KES:"KSh",ZAR:"R"}[e.toUpperCase()]||e},e.luhnCheck=n,e.validateCVV=o,e.validateCardNumber=i,e.validateExpiry=s,Object.defineProperty(e,"__esModule",{value:!0}),e}({},require$$4);
|
|
1
|
+
var VoxePay=function(e){"use strict";const t=[{name:"Visa",code:"visa",pattern:/^4/,lengths:[13,16,19],cvvLength:3},{name:"Mastercard",code:"mastercard",pattern:/^(5[1-5]|2[2-7])/,lengths:[16],cvvLength:3},{name:"Verve",code:"verve",pattern:/^(506[0-9]|507[0-9]|6500)/,lengths:[16,18,19],cvvLength:3},{name:"American Express",code:"amex",pattern:/^3[47]/,lengths:[15],cvvLength:4},{name:"Discover",code:"discover",pattern:/^(6011|65|64[4-9])/,lengths:[16,19],cvvLength:3}];function a(e){const a=e.replace(/\s/g,"");for(const e of t)if(e.pattern.test(a))return e;return null}function n(e){const t=e.replace(/\s/g,"");if(!/^\d+$/.test(t))return!1;let a=0,n=!1;for(let e=t.length-1;e>=0;e--){let o=parseInt(t[e],10);n&&(o*=2,o>9&&(o-=9)),a+=o,n=!n}return a%10==0}function o(e){const t=e.replace(/\s/g,"");if(!t)return{valid:!1,error:"Card number is required"};if(!/^\d+$/.test(t))return{valid:!1,error:"Invalid card number"};const o=a(t);return o?o.lengths.includes(t.length)?n(t)?{valid:!0}:{valid:!1,error:"Invalid card number"}:{valid:!1,error:"Invalid card number length"}:{valid:!1,error:"Unsupported card type"}}function r(e){const t=e.replace(/\s/g,"");if(!t)return{valid:!1,error:"Expiry date is required"};const a=t.match(/^(\d{2})\/(\d{2})$/);if(!a)return{valid:!1,error:"Invalid format (MM/YY)"};const n=parseInt(a[1],10),o=parseInt(a[2],10)+2e3;if(n<1||n>12)return{valid:!1,error:"Invalid month"};const r=new Date,i=r.getFullYear(),s=r.getMonth()+1;return o<i||o===i&&n<s?{valid:!1,error:"Card has expired"}:o>i+20?{valid:!1,error:"Invalid expiry year"}:{valid:!0}}function i(e,t){const n=e.replace(/\s/g,"");if(!n)return{valid:!1,error:"CVV is required"};if(!/^\d+$/.test(n))return{valid:!1,error:"Invalid CVV"};const o=t?a(t):null,r=(null==o?void 0:o.cvvLength)||3;return n.length!==r&&3!==n.length&&4!==n.length?{valid:!1,error:`CVV must be ${r} digits`}:{valid:!0}}function s(e){return(e.replace(/\D/g,"").match(/.{1,4}/g)||[]).join(" ").slice(0,23)}function l(e){const t=e.replace(/\D/g,"");if(0===t.length)return"";if(1===t.length)return parseInt(t)>1?`0${t}`:t;if(2===t.length){const e=parseInt(t);return e>12?"12":0===e?"01":t}return`${t.slice(0,2)}/${t.slice(2,4)}`}function d(e){return e.replace(/\D/g,"").slice(0,4)}function p(e,t){return new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:2}).format(e/100)}const c=e=>{const t=[];for(let a=0;a<e.length;a+=2)t.push(parseInt(e.substring(a,a+2),16));return t};class v{constructor(){this.data=[],this.sign=0}static fromHex(e){const t=new v;if(0===e.length)return t;t.sign=1;let a=0,n=0;for(let o=e.length-1;o>=0;o--){n|=parseInt(e[o],16)<<a,a+=4,a>=v.BITS&&(t.data.push(n&v.BASE-1),n>>>=v.BITS,a-=v.BITS)}return(n>0||a>0)&&t.data.push(n),t.trim(),t}static fromBytes(e){const t=e.map(e=>e.toString(16).padStart(2,"0")).join("");return v.fromHex(t)}trim(){for(;this.data.length>0&&0===this.data[this.data.length-1];)this.data.pop();0===this.data.length&&(this.sign=0)}isZero(){return 0===this.data.length}bitLength(){if(0===this.data.length)return 0;const e=this.data[this.data.length-1];let t=(this.data.length-1)*v.BITS,a=e;for(;a>0;)t++,a>>>=1;return t}toBytes(e){let t="";for(let e=this.data.length-1;e>=0;e--){const a=this.data[e].toString(16);if(e===this.data.length-1)t+=a;else{const e=Math.ceil(v.BITS/4);t+=a.padStart(e,"0")}}t.length%2!=0&&(t="0"+t);const a=c(t);if(e&&a.length<e){return new Array(e-a.length).fill(0).concat(a)}return a}clone(){const e=new v;return e.data=this.data.slice(),e.sign=this.sign,e}compareAbs(e){if(this.data.length!==e.data.length)return this.data.length>e.data.length?1:-1;for(let t=this.data.length-1;t>=0;t--)if(this.data[t]!==e.data[t])return this.data[t]>e.data[t]?1:-1;return 0}multiply(e){if(this.isZero()||e.isZero())return new v;const t=new v;t.data=new Array(this.data.length+e.data.length).fill(0),t.sign=1;for(let a=0;a<this.data.length;a++){let n=0;for(let o=0;o<e.data.length;o++){const r=this.data[a]*e.data[o]+t.data[a+o]+n;t.data[a+o]=r&v.BASE-1,n=Math.floor(r/v.BASE)}n>0&&(t.data[a+e.data.length]+=n)}return t.trim(),t}modPow(e,t){if(t.isZero())throw new Error("Division by zero");let a=v.fromHex("1"),n=this.mod(t);const o=e.bitLength();for(let r=0;r<o;r++){const o=Math.floor(r/v.BITS),i=r%v.BITS;o<e.data.length&&e.data[o]&1<<i&&(a=a.multiply(n).mod(t)),n=n.multiply(n).mod(t)}return a}mod(e){return this.divmod(e).remainder}divmod(e){if(e.isZero())throw new Error("Division by zero");if(this.isZero())return{quotient:new v,remainder:new v};const t=this.compareAbs(e);if(t<0)return{quotient:new v,remainder:this.clone()};if(0===t){return{quotient:v.fromHex("1"),remainder:new v}}const a=new v;a.data=new Array(this.data.length).fill(0),a.sign=1;let n=new v;for(let t=this.bitLength()-1;t>=0;t--){n=n.shiftLeft(1);const o=Math.floor(t/v.BITS),r=t%v.BITS;if(o<this.data.length&&this.data[o]&1<<r&&(0===n.data.length&&n.data.push(0),n.data[0]|=1,n.sign=1),n.compareAbs(e)>=0){n=n.subtract(e);const o=Math.floor(t/v.BITS),r=t%v.BITS;for(;a.data.length<=o;)a.data.push(0);a.data[o]|=1<<r}}return a.trim(),n.trim(),{quotient:a,remainder:n}}shiftLeft(e){if(this.isZero()||0===e)return this.clone();const t=Math.floor(e/v.BITS),a=e%v.BITS,n=new v;n.sign=this.sign,n.data=new Array(this.data.length+t+1).fill(0);for(let e=0;e<this.data.length;e++)n.data[e+t]|=this.data[e]<<a&v.BASE-1,a>0&&(n.data[e+t+1]|=this.data[e]>>>v.BITS-a);return n.trim(),n}subtract(e){const t=new v;t.sign=1,t.data=new Array(Math.max(this.data.length,e.data.length)).fill(0);let a=0;for(let n=0;n<t.data.length;n++){let o=(this.data[n]||0)-(e.data[n]||0)-a;o<0?(o+=v.BASE,a=1):a=0,t.data[n]=o}return t.trim(),t}}v.BASE=67108864,v.BITS=26;const y="009c7b3ba621a26c4b02f48cfc07ef6ee0aed8e12b4bd11c5cc0abf80d5206be69e1891e60fc88e2d565e2fabe4d0cf630e318a6c721c3ded718d0c530cdf050387ad0a30a336899bbda877d0ec7c7c3ffe693988bfae0ffbab71b25468c7814924f022cb5fda36e0d2c30a7161fa1c6fb5fbd7d05adbef7e68d48f8b6c5f511827c4b1c5ed15b6f20555affc4d0857ef7ab2b5c18ba22bea5d3a79bd1834badb5878d8c7a4b19da20c1f62340b1f7fbf01d2f2e97c9714a9df376ac0ea58072b2b77aeb7872b54a89667519de44d0fc73540beeaec4cb778a45eebfbefe2d817a8a8319b2bc6d9fa714f5289ec7c0dbc43496d71cf2a642cb679b0fc4072fd2cf",u="010001",h=async({version:e,pan:t,pin:a,expiryDate:n,cvv:o})=>{try{const i=c((e=>{let t="";for(let a=0;a<e.length;a++)t+=e.charCodeAt(a).toString(16).padStart(2,"0");return t})(`${e}Z${t}Z${a}Z${n}Z${o}`)),s=v.fromHex(y),l=v.fromHex(u),d=Math.ceil(s.bitLength()/8),p=((e,t)=>{if(e.length>t-11)throw new Error("Message too long for RSA encryption");const a=t-e.length-3,n=new Array(t);n[0]=0,n[1]=2;for(let e=0;e<a;e++){let t=0;if("undefined"!=typeof crypto&&crypto.getRandomValues){const e=new Uint8Array(1);for(;0===t;)crypto.getRandomValues(e),t=e[0]}else for(;0===t;)t=Math.floor(255*Math.random())+1;n[2+e]=t}n[2+a]=0;for(let t=0;t<e.length;t++)n[3+a+t]=e[t];return n})(i,d),h=v.fromBytes(p),x=h.modPow(l,s).toBytes(d);return r=x,"undefined"!=typeof btoa?btoa(String.fromCharCode(...r)):Buffer.from(r).toString("base64")}catch(e){throw console.error("[VoxePay] Encryption error:",e),new Error("Failed to encrypt card data")}var r},x=e=>{const t=e.replace(/\s|\//g,"");if(4!==t.length)return"";const a=t.substring(0,2);return`${t.substring(2,4)}${a}`},m=e=>e.replace(/\s/g,"");class f{constructor(e,t){this.apiKey=e,this.baseUrl=t||"https://devpay.voxepay.app"}async request(e,t){const a=`${this.baseUrl}${e}`,n=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.apiKey,Accept:"application/json"},body:JSON.stringify(t)}),o=await n.json();if(!n.ok){const e=(null==o?void 0:o.message)||(null==o?void 0:o.error)||`Request failed with status ${n.status}`,t=new Error(e);throw t.code=(null==o?void 0:o.code)||`HTTP_${n.status}`,t.status=n.status,t.data=o,t}return o}async initiatePayment(e){return this.request("/api/v1/payments/initiate",e)}async validateOTP(e){return this.request("/api/v1/payments/validate-otp",e)}async resendOTP(e){await this.request("/api/v1/payments/resend-otp",e)}}const g='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />\n </svg>',b='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />\n </svg>',w='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">\n <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />\n </svg>',T='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" />\n </svg>',k='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />\n </svg>',S='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M3 21h18M3 10h18M5 6l7-3 7 3M4 10v11M20 10v11M8 14v3M12 14v3M16 14v3" />\n </svg>',I='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />\n </svg>',P='<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">\n <path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />\n </svg>',E={visa:"VISA",mastercard:"MC",amex:"AMEX",verve:"VERVE",discover:"DISC"};class M{constructor(e){this.container=null,this.overlay=null,this.apiClient=null,this.handleEscape=e=>{"Escape"===e.key&&(this.close(),document.removeEventListener("keydown",this.handleEscape))},this.options=e;const t=e.paymentMethods||["card","bank_transfer"];e._sdkConfig&&(this.apiClient=new f(e._sdkConfig.apiKey,e._sdkConfig.baseUrl)),this.state={cardNumber:"",expiry:"",cvv:"",otp:"",errors:{},isProcessing:!1,isSuccess:!1,isOtpStep:!1,otpTimer:60,canResendOtp:!1,otpTimerInterval:null,paymentMethod:t[0],transferTimer:0,transferTimerInterval:null,bankTransferDetails:e.bankTransferDetails||null,paymentId:null,transactionId:null,transactionRef:null,eciFlag:null}}open(){this.injectStyles(),this.render(),this.attachEventListeners(),requestAnimationFrame(()=>{var e;null===(e=this.overlay)||void 0===e||e.classList.add("voxepay-visible")})}close(){var e;this.stopTransferTimer(),null===(e=this.overlay)||void 0===e||e.classList.remove("voxepay-visible"),setTimeout(()=>{var e,t,a;null===(e=this.container)||void 0===e||e.remove(),this.container=null,this.overlay=null,null===(a=(t=this.options).onClose)||void 0===a||a.call(t)},300)}injectStyles(){if(document.getElementById("voxepay-checkout-styles"))return;const e=document.createElement("style");e.id="voxepay-checkout-styles",e.textContent=this.getStyles(),document.head.appendChild(e)}render(){this.container=document.createElement("div"),this.container.className="voxepay-checkout",this.container.innerHTML=this.getModalHTML(),document.body.appendChild(this.container),this.overlay=this.container.querySelector(".voxepay-overlay")}getPaymentMethods(){return this.options.paymentMethods||["card","bank_transfer"]}getModalHTML(){const e=p(this.options.amount,this.options.currency),t=this.getPaymentMethods(),a=t.length>1,n="card"===this.state.paymentMethod;return`\n <div class="voxepay-overlay">\n <div class="voxepay-modal" role="dialog" aria-modal="true" aria-labelledby="voxepay-title">\n <div class="voxepay-header">\n <div class="voxepay-header-left">\n <div class="voxepay-logo">V</div>\n <div>\n <div class="voxepay-amount" id="voxepay-title">Pay ${e}</div>\n ${this.options.description?`<div style="font-size: 0.875rem; color: var(--voxepay-text-muted);">${this.options.description}</div>`:""}\n </div>\n </div>\n <button class="voxepay-close" aria-label="Close" data-action="close">\n ${g}\n </button>\n </div>\n\n ${a?`\n <div class="voxepay-method-tabs">\n ${t.includes("card")?`\n <button class="voxepay-method-tab ${n?"active":""}" data-method="card">\n ${I} <span>Card</span>\n </button>`:""}\n ${t.includes("bank_transfer")?`\n <button class="voxepay-method-tab ${n?"":"active"}" data-method="bank_transfer">\n ${S} <span>Bank Transfer</span>\n </button>`:""}\n </div>`:""}\n \n <div class="voxepay-body" id="voxepay-form-container">\n ${n?this.getCardFormHTML(e):this.getBankTransferHTML(e)}\n </div>\n \n <div class="voxepay-footer">\n <div class="voxepay-powered-by">\n ${b}\n <span>Secured by <strong>VoxePay</strong></span>\n </div>\n </div>\n </div>\n </div>\n `}getCardFormHTML(e){return`\n <form id="voxepay-payment-form" novalidate>\n <div class="voxepay-form-group">\n <label class="voxepay-label">\n <span class="voxepay-label-icon">💳</span>\n Card Number\n </label>\n <div class="voxepay-card-input-wrapper">\n <input type="text" class="voxepay-input" id="voxepay-card-number" name="cardNumber"\n placeholder="1234 5678 9012 3456" autocomplete="cc-number" inputmode="numeric" />\n <div class="voxepay-card-brand" id="voxepay-card-brand"></div>\n </div>\n <div class="voxepay-error-message" id="voxepay-card-error" style="display: none;"></div>\n </div>\n \n <div class="voxepay-row">\n <div class="voxepay-form-group">\n <label class="voxepay-label"><span class="voxepay-label-icon">📅</span> Expiry</label>\n <input type="text" class="voxepay-input" id="voxepay-expiry" name="expiry"\n placeholder="MM/YY" autocomplete="cc-exp" inputmode="numeric" maxlength="5" />\n <div class="voxepay-error-message" id="voxepay-expiry-error" style="display: none;"></div>\n </div>\n <div class="voxepay-form-group">\n <label class="voxepay-label"><span class="voxepay-label-icon">🔒</span> CVV</label>\n <input type="text" class="voxepay-input" id="voxepay-cvv" name="cvv"\n placeholder="•••" autocomplete="cc-csc" inputmode="numeric" maxlength="4" />\n <div class="voxepay-error-message" id="voxepay-cvv-error" style="display: none;"></div>\n </div>\n </div>\n \n <button type="submit" class="voxepay-submit-btn" id="voxepay-submit">\n <span>Pay Now ${e}</span>\n </button>\n </form>\n `}getBankTransferHTML(e){const t=this.state.bankTransferDetails;return t?`\n <div class="voxepay-transfer-view">\n <div class="voxepay-transfer-instruction">\n <p>Transfer <strong>${e}</strong> to the account below</p>\n </div>\n\n <div class="voxepay-transfer-details">\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Account Number</span>\n <div class="voxepay-transfer-value-row">\n <span class="voxepay-transfer-value voxepay-transfer-account" id="voxepay-account-number">${t.accountNumber}</span>\n <button class="voxepay-copy-btn" id="voxepay-copy-btn" data-copy="${t.accountNumber}" title="Copy">\n ${k}\n </button>\n </div>\n </div>\n\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Bank Name</span>\n <span class="voxepay-transfer-value">${t.bankName}</span>\n </div>\n\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Account Name</span>\n <span class="voxepay-transfer-value">${t.accountName}</span>\n </div>\n\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Amount</span>\n <span class="voxepay-transfer-value voxepay-transfer-amount">${e}</span>\n </div>\n\n <div class="voxepay-transfer-detail">\n <span class="voxepay-transfer-label">Reference</span>\n <span class="voxepay-transfer-value" style="font-family: monospace; letter-spacing: 1px;">${t.reference}</span>\n </div>\n </div>\n\n <div class="voxepay-transfer-timer" id="voxepay-transfer-timer">\n ${P}\n <span>Account expires in <strong id="voxepay-transfer-countdown">${this.formatCountdown(t.expiresIn)}</strong></span>\n </div>\n\n <button type="button" class="voxepay-submit-btn" id="voxepay-transfer-confirm">\n <span>I've sent the money</span>\n </button>\n </div>\n `:'\n <div class="voxepay-transfer-view">\n <div class="voxepay-transfer-loading">\n <div class="voxepay-spinner"></div>\n <p style="margin-top: 16px; color: var(--voxepay-text-muted);">Generating account details...</p>\n </div>\n </div>\n '}formatCountdown(e){const t=Math.floor(e/60),a=e%60;return`${String(t).padStart(2,"0")}:${String(a).padStart(2,"0")}`}renderSuccessView(){var e;const t=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-form-container");if(!t)return;const a=p(this.options.amount,this.options.currency);t.innerHTML=`\n <div class="voxepay-success-view">\n <div class="voxepay-success-icon">\n ${w}\n </div>\n <h2 class="voxepay-success-title">Payment Successful!</h2>\n <p class="voxepay-success-message">Your payment of ${a} has been processed.</p>\n <button class="voxepay-success-btn" data-action="close">Done</button>\n </div>\n `;const n=t.querySelector('[data-action="close"]');null==n||n.addEventListener("click",()=>this.close())}renderOTPView(){var e;const t=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-form-container");if(!t)return;this.state.isOtpStep=!0,this.state.otpTimer=60,this.state.canResendOtp=!1;const a=this.options.customerEmail?`****${this.options.customerEmail.slice(-4)}`:"****1234";t.innerHTML=`\n <div class="voxepay-otp-view">\n <div class="voxepay-otp-header">\n <div class="voxepay-otp-icon">📱</div>\n <h3 class="voxepay-otp-title">Verify Your Payment</h3>\n <p class="voxepay-otp-subtitle">We've sent a 6-digit code to ${a}</p>\n </div>\n \n <div class="voxepay-otp-inputs-container">\n <div class="voxepay-otp-inputs" id="voxepay-otp-inputs">\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="0" inputmode="numeric" autocomplete="one-time-code" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="1" inputmode="numeric" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="2" inputmode="numeric" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="3" inputmode="numeric" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="4" inputmode="numeric" />\n <input type="text" maxlength="1" class="voxepay-otp-digit" data-index="5" inputmode="numeric" />\n </div>\n <div class="voxepay-error-message" id="voxepay-otp-error" style="display: none;"></div>\n </div>\n\n <div class="voxepay-otp-timer" id="voxepay-otp-timer">\n Resend code in <span id="voxepay-timer-count">60</span>s\n </div>\n \n <button class="voxepay-resend-btn" id="voxepay-resend-otp" disabled>\n Resend OTP\n </button>\n \n <button type="button" class="voxepay-submit-btn" id="voxepay-verify-otp">\n <span>🔐 Verify & Pay</span>\n </button>\n \n <button class="voxepay-back-btn" id="voxepay-back-to-card">\n ← Back to card details\n </button>\n </div>\n `,this.attachOTPEventListeners(),this.startOTPTimer()}attachOTPEventListeners(){var e,t,a,n,o;const r=null===(e=this.container)||void 0===e?void 0:e.querySelectorAll(".voxepay-otp-digit");null==r||r.forEach((e,t)=>{e.addEventListener("input",e=>this.handleOTPInput(e,t)),e.addEventListener("keydown",e=>this.handleOTPKeydown(e,t)),e.addEventListener("paste",e=>this.handleOTPPaste(e))});const i=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-verify-otp");null==i||i.addEventListener("click",()=>this.handleOTPSubmit());const s=null===(a=this.container)||void 0===a?void 0:a.querySelector("#voxepay-resend-otp");null==s||s.addEventListener("click",()=>this.handleResendOTP());const l=null===(n=this.container)||void 0===n?void 0:n.querySelector("#voxepay-back-to-card");null==l||l.addEventListener("click",()=>this.handleBackToCard()),null===(o=null==r?void 0:r[0])||void 0===o||o.focus()}handleOTPInput(e,t){var a;const n=e.target,o=n.value.replace(/\D/g,"");if(n.value=o,o&&t<5){const e=null===(a=this.container)||void 0===a?void 0:a.querySelector(`[data-index="${t+1}"]`);null==e||e.focus()}this.updateOTPState(),this.clearError("otp")}handleOTPKeydown(e,t){var a;const n=e.target;if("Backspace"===e.key&&!n.value&&t>0){const e=null===(a=this.container)||void 0===a?void 0:a.querySelector(`[data-index="${t-1}"]`);null==e||e.focus()}}handleOTPPaste(e){var t,a;e.preventDefault();const n=null===(t=e.clipboardData)||void 0===t?void 0:t.getData("text").replace(/\D/g,"").slice(0,6);if(n){const e=null===(a=this.container)||void 0===a?void 0:a.querySelectorAll(".voxepay-otp-digit");n.split("").forEach((t,a)=>{e[a]&&(e[a].value=t)}),this.updateOTPState()}}updateOTPState(){var e;const t=null===(e=this.container)||void 0===e?void 0:e.querySelectorAll(".voxepay-otp-digit");let a="";null==t||t.forEach(e=>a+=e.value),this.state.otp=a}startOTPTimer(){var e,t,a;const n=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-timer-count"),o=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-otp-timer"),r=null===(a=this.container)||void 0===a?void 0:a.querySelector("#voxepay-resend-otp");this.state.otpTimerInterval=window.setInterval(()=>{this.state.otpTimer--,n&&(n.textContent=String(this.state.otpTimer)),this.state.otpTimer<=0&&(this.state.otpTimerInterval&&clearInterval(this.state.otpTimerInterval),this.state.canResendOtp=!0,o&&(o.style.display="none"),r&&(r.disabled=!1))},1e3)}async handleOTPSubmit(){if(6===this.state.otp.length){this.setOTPProcessing(!0);try{await this.verifyOTP(),this.state.otpTimerInterval&&clearInterval(this.state.otpTimerInterval);const e=await this.processPayment();this.state.isSuccess=!0,this.renderSuccessView(),this.options.onSuccess(e)}catch(e){this.setOTPProcessing(!1);const t=e;this.showError("otp",t.message||"Invalid OTP. Please try again.")}}else this.showError("otp","Please enter the complete 6-digit code")}setOTPProcessing(e){var t;const a=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-verify-otp");a&&(a.disabled=e,a.innerHTML=e?'<div class="voxepay-spinner"></div><span>Verifying...</span>':"<span>🔐 Verify & Pay</span>")}async verifyOTP(){if(!this.apiClient||!this.options._sdkConfig)throw{code:"SDK_ERROR",message:"SDK not properly initialized",recoverable:!1};if(6!==this.state.otp.length)throw{code:"INVALID_OTP",message:"Please enter the complete 6-digit code",recoverable:!0};if(!this.state.paymentId||!this.state.transactionId)throw{code:"MISSING_PAYMENT_DATA",message:"Payment session expired. Please try again.",recoverable:!1};await this.apiClient.validateOTP({paymentId:this.state.paymentId,otp:this.state.otp,transactionId:this.state.transactionId,eciFlag:this.state.eciFlag||void 0,organizationId:this.options._sdkConfig.organizationId})}async handleResendOTP(){var e,t,a,n;const o=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-otp-timer"),r=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-resend-otp");if(this.apiClient&&this.options._sdkConfig&&this.state.transactionRef)try{r&&(r.disabled=!0),await this.apiClient.resendOTP({transactionRef:this.state.transactionRef,organizationId:this.options._sdkConfig.organizationId})}catch(e){console.error("[VoxePay] Failed to resend OTP:",e)}this.state.otpTimer=60,this.state.canResendOtp=!1,o&&(o.style.display="block"),r&&(r.disabled=!0);const i=null===(a=this.container)||void 0===a?void 0:a.querySelectorAll(".voxepay-otp-digit");null==i||i.forEach(e=>e.value=""),this.state.otp="",this.startOTPTimer(),null===(n=null==i?void 0:i[0])||void 0===n||n.focus()}handleBackToCard(){var e;if(this.state.otpTimerInterval&&clearInterval(this.state.otpTimerInterval),this.state.isOtpStep=!1,this.state.otp="",this.container){this.container.innerHTML=this.getModalHTML(),this.overlay=this.container.querySelector(".voxepay-overlay"),null===(e=this.overlay)||void 0===e||e.classList.add("voxepay-visible"),this.attachEventListeners();const t=this.container.querySelector("#voxepay-card-number"),a=this.container.querySelector("#voxepay-expiry"),n=this.container.querySelector("#voxepay-cvv");t&&(t.value=s(this.state.cardNumber)),a&&(a.value=this.state.expiry),n&&(n.value=this.state.cvv)}}attachEventListeners(){var e,t,a,n,o,r,i;const s=null===(e=this.container)||void 0===e?void 0:e.querySelector('[data-action="close"]');null==s||s.addEventListener("click",()=>this.close()),null===(t=this.overlay)||void 0===t||t.addEventListener("click",e=>{e.target===this.overlay&&this.close()}),document.addEventListener("keydown",this.handleEscape);const l=null===(a=this.container)||void 0===a?void 0:a.querySelectorAll(".voxepay-method-tab");if(null==l||l.forEach(e=>{e.addEventListener("click",()=>{const t=e.dataset.method;t&&t!==this.state.paymentMethod&&this.switchPaymentMethod(t)})}),"card"===this.state.paymentMethod){const e=null===(n=this.container)||void 0===n?void 0:n.querySelector("#voxepay-card-number");null==e||e.addEventListener("input",e=>this.handleCardInput(e)),null==e||e.addEventListener("blur",()=>this.validateField("cardNumber"));const t=null===(o=this.container)||void 0===o?void 0:o.querySelector("#voxepay-expiry");null==t||t.addEventListener("input",e=>this.handleExpiryInput(e)),null==t||t.addEventListener("blur",()=>this.validateField("expiry"));const a=null===(r=this.container)||void 0===r?void 0:r.querySelector("#voxepay-cvv");null==a||a.addEventListener("input",e=>this.handleCVVInput(e)),null==a||a.addEventListener("blur",()=>this.validateField("cvv"));const s=null===(i=this.container)||void 0===i?void 0:i.querySelector("#voxepay-payment-form");null==s||s.addEventListener("submit",e=>this.handleSubmit(e))}"bank_transfer"===this.state.paymentMethod&&(this.attachBankTransferListeners(),this.state.bankTransferDetails?this.startTransferTimer():this.loadBankTransferDetails())}attachBankTransferListeners(){var e,t;const a=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-copy-btn");null==a||a.addEventListener("click",()=>{const e=a.dataset.copy||"";this.copyToClipboard(e)});const n=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-transfer-confirm");null==n||n.addEventListener("click",()=>this.handleTransferConfirm())}switchPaymentMethod(e){var t;if(this.stopTransferTimer(),this.state.paymentMethod=e,this.container&&(this.container.innerHTML=this.getModalHTML(),this.overlay=this.container.querySelector(".voxepay-overlay"),null===(t=this.overlay)||void 0===t||t.classList.add("voxepay-visible"),this.attachEventListeners(),"card"===e&&this.state.cardNumber)){const e=this.container.querySelector("#voxepay-card-number"),t=this.container.querySelector("#voxepay-expiry"),a=this.container.querySelector("#voxepay-cvv");e&&(e.value=s(this.state.cardNumber)),t&&(t.value=this.state.expiry),a&&(a.value=this.state.cvv)}}async loadBankTransferDetails(){var e;try{let t;this.options.onBankTransferRequested?t=await this.options.onBankTransferRequested():(await new Promise(e=>setTimeout(e,1500)),t={accountNumber:"0123456789",bankName:"VoxePay Bank",accountName:"VoxePay Collections",reference:`VP-${Date.now().toString(36).toUpperCase()}`,expiresIn:1800}),this.state.bankTransferDetails=t;const a=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-form-container");if(a){const e=p(this.options.amount,this.options.currency);a.innerHTML=this.getBankTransferHTML(e),this.attachBankTransferListeners(),this.startTransferTimer()}}catch(e){this.options.onError({code:"BANK_TRANSFER_INIT_FAILED",message:"Could not generate bank transfer details. Please try again.",recoverable:!0})}}async copyToClipboard(e){var t;try{await navigator.clipboard.writeText(e);const a=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-copy-btn");a&&(a.innerHTML=`${w}`,a.classList.add("voxepay-copied"),setTimeout(()=>{a.innerHTML=`${k}`,a.classList.remove("voxepay-copied")},2e3))}catch(t){const a=document.createElement("textarea");a.value=e,a.style.position="fixed",a.style.opacity="0",document.body.appendChild(a),a.select(),document.execCommand("copy"),document.body.removeChild(a)}}async handleTransferConfirm(){var e,t;const a=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-transfer-confirm");a&&(a.disabled=!0,a.innerHTML='<div class="voxepay-spinner"></div><span>Confirming transfer...</span>'),this.stopTransferTimer();try{await new Promise(e=>setTimeout(e,3e3));const e={id:`pay_transfer_${Date.now()}`,status:"pending",amount:this.options.amount,currency:this.options.currency,timestamp:(new Date).toISOString(),reference:null===(t=this.state.bankTransferDetails)||void 0===t?void 0:t.reference,paymentMethod:"bank_transfer"};this.state.isSuccess=!0,this.renderSuccessView(),this.options.onSuccess(e)}catch(e){a&&(a.disabled=!1,a.innerHTML="<span>I've sent the money</span>");const t=e;this.options.onError(t)}}startTransferTimer(){this.state.bankTransferDetails&&(this.state.transferTimer=this.state.bankTransferDetails.expiresIn,this.state.transferTimerInterval=window.setInterval(()=>{var e,t,a;this.state.transferTimer--;const n=null===(e=this.container)||void 0===e?void 0:e.querySelector("#voxepay-transfer-countdown");if(n&&(n.textContent=this.formatCountdown(this.state.transferTimer)),this.state.transferTimer<=0){this.stopTransferTimer();const e=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-transfer-timer");e&&(e.innerHTML=`${P} <span style="color: var(--voxepay-error);">Account expired. Please try again.</span>`);const n=null===(a=this.container)||void 0===a?void 0:a.querySelector("#voxepay-transfer-confirm");n&&(n.disabled=!0)}},1e3))}stopTransferTimer(){this.state.transferTimerInterval&&(clearInterval(this.state.transferTimerInterval),this.state.transferTimerInterval=null)}handleCardInput(e){var t;const n=e.target,o=s(n.value);n.value=o,this.state.cardNumber=o.replace(/\s/g,"");const r=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-card-brand"),i=a(this.state.cardNumber);r&&(r.textContent=i&&E[i.code]||"",r.style.opacity=i?"1":"0"),this.clearError("cardNumber")}handleExpiryInput(e){const t=e.target,a=l(t.value);t.value=a,this.state.expiry=a,this.clearError("expiry")}handleCVVInput(e){const t=e.target,a=d(t.value);t.value=a,this.state.cvv=a,this.clearError("cvv")}validateField(e){let t;switch(e){case"cardNumber":t=o(this.state.cardNumber);break;case"expiry":t=r(this.state.expiry);break;case"cvv":t=i(this.state.cvv,this.state.cardNumber);break;default:return!0}return t.valid?(this.clearError(e),!0):(this.showError(e,t.error||"Invalid"),!1)}showError(e,t){var a,n;const o=null===(a=this.container)||void 0===a?void 0:a.querySelector(`#voxepay-${"cardNumber"===e?"card":e}-error`),r=null===(n=this.container)||void 0===n?void 0:n.querySelector(`#voxepay-${"cardNumber"===e?"card-number":e}`);o&&(o.innerHTML=`${T} ${t}`,o.style.display="flex"),null==r||r.classList.add("voxepay-error")}clearError(e){var t,a;const n=null===(t=this.container)||void 0===t?void 0:t.querySelector(`#voxepay-${"cardNumber"===e?"card":e}-error`),o=null===(a=this.container)||void 0===a?void 0:a.querySelector(`#voxepay-${"cardNumber"===e?"card-number":e}`);n&&(n.style.display="none"),null==o||o.classList.remove("voxepay-error")}async handleSubmit(e){e.preventDefault();const t=this.validateField("cardNumber"),a=this.validateField("expiry"),n=this.validateField("cvv");if(t&&a&&n)if(this.apiClient&&this.options._sdkConfig){this.setProcessing(!0);try{const e=m(this.state.cardNumber),t=x(this.state.expiry),a=await h({version:"1",pan:e,pin:"",expiryDate:t,cvv:this.state.cvv}),n=`VP-${Date.now().toString(36).toUpperCase()}-${Math.random().toString(36).substring(2,8).toUpperCase()}`,o=await this.apiClient.initiatePayment({organizationId:this.options._sdkConfig.organizationId,transactionRef:n,customerEmail:this.options.customerEmail,customerPhone:this.options.customerPhone,amount:this.options.amount/100,currency:this.options.currency,paymentMethod:"CARD",authData:a,narration:this.options.description});this.state.paymentId=o.paymentId,this.state.transactionId=o.transactionId,this.state.transactionRef=o.transactionRef||n,this.state.eciFlag=o.eciFlag||null,this.setProcessing(!1),this.renderOTPView()}catch(e){this.setProcessing(!1);const t=(null==e?void 0:e.message)||"Payment failed. Please try again.";this.options.onError({code:(null==e?void 0:e.code)||"PAYMENT_INITIATE_FAILED",message:t,recoverable:!0,details:null==e?void 0:e.data}),this.showError("cardNumber",t)}}else this.showError("cardNumber","SDK not properly initialized. Missing API key or organization ID.")}setProcessing(e){var t;this.state.isProcessing=e;const a=null===(t=this.container)||void 0===t?void 0:t.querySelector("#voxepay-submit");a&&(a.disabled=e,a.innerHTML=e?'<div class="voxepay-spinner"></div><span>Processing...</span>':`<span>Pay Now ${p(this.options.amount,this.options.currency)}</span>`)}async processPayment(){return{id:this.state.paymentId||`pay_${Date.now()}`,status:"success",amount:this.options.amount,currency:this.options.currency,timestamp:(new Date).toISOString(),reference:this.state.transactionRef||void 0,paymentMethod:"card"}}getStyles(){return"\n :root {\n /* VoxePay Blue Color Palette */\n --voxepay-primary: #0061FF;\n --voxepay-primary-hover: #0056E0;\n --voxepay-secondary: #0047CC;\n --voxepay-accent: #60A5FA;\n --voxepay-glow: rgba(0, 97, 255, 0.35);\n --voxepay-success: #10B981;\n --voxepay-success-bg: rgba(16, 185, 129, 0.1);\n --voxepay-error: #EF4444;\n \n /* Dark Mode (Default) */\n --voxepay-bg: #0C0C1D;\n --voxepay-surface: rgba(255, 255, 255, 0.04);\n --voxepay-surface-hover: rgba(255, 255, 255, 0.08);\n --voxepay-border: rgba(255, 255, 255, 0.08);\n --voxepay-text: #FFFFFF;\n --voxepay-text-muted: #B4B4C7;\n --voxepay-text-subtle: #6B7280;\n --voxepay-input-bg: rgba(255, 255, 255, 0.06);\n \n /* Effects */\n --voxepay-backdrop-blur: blur(24px);\n --voxepay-border-radius: 12px;\n --voxepay-border-radius-lg: 16px;\n --voxepay-border-radius-xl: 24px;\n --voxepay-glow-shadow: 0 0 60px var(--voxepay-glow);\n --voxepay-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.6);\n --voxepay-transition-fast: 150ms ease;\n --voxepay-transition: 300ms cubic-bezier(0.4, 0, 0.2, 1);\n }\n \n /* Light Mode */\n html.voxepay-light {\n --voxepay-primary: #0061FF;\n --voxepay-primary-hover: #0056E0;\n --voxepay-secondary: #0047CC;\n --voxepay-glow: rgba(0, 97, 255, 0.2);\n \n --voxepay-bg: #FFFFFF;\n --voxepay-surface: #F8FAFC;\n --voxepay-surface-hover: #F1F5F9;\n --voxepay-border: #E2E8F0;\n --voxepay-text: #0F172A;\n --voxepay-text-muted: #475569;\n --voxepay-text-subtle: #94A3B8;\n --voxepay-input-bg: #F8FAFC;\n \n --voxepay-glow-shadow: 0 0 40px rgba(0, 97, 255, 0.12);\n --voxepay-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);\n }\n \n .voxepay-checkout * { box-sizing: border-box; margin: 0; padding: 0; }\n .voxepay-checkout { font-family: 'DM Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 1rem; color: var(--voxepay-text); line-height: 1.5; -webkit-font-smoothing: antialiased; }\n \n .voxepay-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); backdrop-filter: var(--voxepay-backdrop-blur); -webkit-backdrop-filter: var(--voxepay-backdrop-blur); display: flex; align-items: center; justify-content: center; z-index: 999999; opacity: 0; visibility: hidden; transition: opacity var(--voxepay-transition), visibility var(--voxepay-transition); }\n html.voxepay-light .voxepay-overlay { background: rgba(15, 23, 42, 0.4); }\n .voxepay-overlay.voxepay-visible { opacity: 1; visibility: visible; }\n \n .voxepay-modal { background: var(--voxepay-bg); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius-xl); width: 100%; max-width: 420px; max-height: 90vh; overflow: hidden; box-shadow: var(--voxepay-shadow), var(--voxepay-glow-shadow); transform: scale(0.95) translateY(20px); opacity: 0; transition: transform var(--voxepay-transition), opacity var(--voxepay-transition); }\n .voxepay-overlay.voxepay-visible .voxepay-modal { transform: scale(1) translateY(0); opacity: 1; }\n \n .voxepay-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }\n .voxepay-header-left { display: flex; align-items: center; gap: 12px; }\n .voxepay-logo { width: 36px; height: 36px; border-radius: var(--voxepay-border-radius); background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.25rem; color: white; box-shadow: 0 4px 12px rgba(0, 97, 255, 0.3); }\n .voxepay-amount { font-size: 1.25rem; font-weight: 600; }\n .voxepay-close { width: 36px; height: 36px; border: none; background: var(--voxepay-surface-hover); border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--voxepay-text-muted); transition: all var(--voxepay-transition-fast); }\n .voxepay-close:hover { background: var(--voxepay-border); color: var(--voxepay-text); transform: rotate(90deg); }\n .voxepay-close svg { width: 18px; height: 18px; }\n \n .voxepay-body { padding: 24px; background: var(--voxepay-bg); }\n .voxepay-form-group { margin-bottom: 20px; }\n .voxepay-label { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; font-weight: 500; color: var(--voxepay-text-muted); margin-bottom: 8px; }\n .voxepay-label-icon { font-size: 1rem; }\n \n .voxepay-input { width: 100%; padding: 14px 16px; background: var(--voxepay-input-bg); border: 1.5px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text); font-size: 1rem; font-family: inherit; outline: none; transition: border-color var(--voxepay-transition-fast), box-shadow var(--voxepay-transition-fast), background var(--voxepay-transition-fast); }\n .voxepay-input::placeholder { color: var(--voxepay-text-subtle); }\n .voxepay-input:hover { border-color: var(--voxepay-text-subtle); }\n .voxepay-input:focus { border-color: var(--voxepay-primary); box-shadow: 0 0 0 4px var(--voxepay-glow); background: var(--voxepay-bg); }\n .voxepay-input.voxepay-error { border-color: var(--voxepay-error); box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15); }\n \n .voxepay-card-input-wrapper { position: relative; }\n .voxepay-card-brand { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); padding: 4px 8px; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); border-radius: 6px; font-size: 0.7rem; font-weight: 700; color: white; opacity: 0; transition: opacity var(--voxepay-transition-fast); letter-spacing: 0.5px; }\n .voxepay-card-input-wrapper .voxepay-input { padding-right: 70px; }\n \n .voxepay-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }\n \n .voxepay-error-message { display: flex; align-items: center; gap: 6px; font-size: 0.813rem; color: var(--voxepay-error); margin-top: 8px; animation: voxepay-shake 0.4s ease; }\n .voxepay-error-message svg { width: 16px; height: 16px; flex-shrink: 0; }\n @keyframes voxepay-shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }\n \n .voxepay-submit-btn { width: 100%; padding: 16px 24px; background: linear-gradient(135deg, var(--voxepay-primary), var(--voxepay-secondary)); border: none; border-radius: var(--voxepay-border-radius); color: white; font-size: 1.063rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: all var(--voxepay-transition-fast); position: relative; overflow: hidden; box-shadow: 0 4px 15px rgba(0, 97, 255, 0.35); }\n .voxepay-submit-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(0, 97, 255, 0.45); }\n .voxepay-submit-btn:active:not(:disabled) { transform: translateY(0); }\n .voxepay-submit-btn:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; }\n .voxepay-submit-btn span { position: relative; z-index: 1; }\n \n .voxepay-spinner { width: 20px; height: 20px; border: 2.5px solid rgba(255, 255, 255, 0.3); border-top-color: white; border-radius: 50%; animation: voxepay-spin 0.8s linear infinite; }\n @keyframes voxepay-spin { to { transform: rotate(360deg); } }\n \n .voxepay-footer { text-align: center; padding: 16px 24px 20px; border-top: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }\n .voxepay-powered-by { font-size: 0.75rem; color: var(--voxepay-text-subtle); display: flex; align-items: center; justify-content: center; gap: 6px; }\n .voxepay-powered-by svg { width: 14px; height: 14px; color: var(--voxepay-primary); }\n .voxepay-powered-by strong { color: var(--voxepay-primary); font-weight: 600; }\n \n .voxepay-success-view { text-align: center; padding: 40px 24px; }\n .voxepay-success-icon { width: 80px; height: 80px; margin: 0 auto 24px; background: linear-gradient(135deg, var(--voxepay-success), #059669); border-radius: 50%; display: flex; align-items: center; justify-content: center; animation: voxepay-success-pop 0.5s ease; box-shadow: 0 8px 25px rgba(16, 185, 129, 0.35); }\n @keyframes voxepay-success-pop { 0% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }\n .voxepay-success-icon svg { width: 40px; height: 40px; color: white; }\n .voxepay-success-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; color: var(--voxepay-text); }\n .voxepay-success-message { font-size: 1rem; color: var(--voxepay-text-muted); margin-bottom: 24px; }\n .voxepay-success-btn { padding: 12px 32px; background: var(--voxepay-surface); border: 1.5px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text); font-size: 1rem; font-weight: 500; cursor: pointer; transition: all var(--voxepay-transition-fast); }\n .voxepay-success-btn:hover { background: var(--voxepay-surface-hover); border-color: var(--voxepay-primary); color: var(--voxepay-primary); }\n \n /* OTP View */\n .voxepay-otp-view { text-align: center; padding: 24px 16px; }\n .voxepay-otp-header { margin-bottom: 24px; }\n .voxepay-otp-icon { font-size: 3rem; margin-bottom: 12px; }\n .voxepay-otp-title { font-size: 1.25rem; font-weight: 700; color: var(--voxepay-text); margin-bottom: 8px; }\n .voxepay-otp-subtitle { font-size: 0.875rem; color: var(--voxepay-text-muted); }\n \n .voxepay-otp-inputs-container { margin-bottom: 16px; }\n .voxepay-otp-inputs { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }\n .voxepay-otp-digit { width: 48px; height: 56px; text-align: center; font-size: 1.5rem; font-weight: 700; border: 2px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); background: var(--voxepay-input-bg); color: var(--voxepay-text); outline: none; transition: all var(--voxepay-transition-fast); }\n .voxepay-otp-digit:focus { border-color: var(--voxepay-primary); box-shadow: 0 0 0 4px var(--voxepay-glow); }\n \n .voxepay-otp-timer { font-size: 0.875rem; color: var(--voxepay-text-muted); margin-bottom: 12px; }\n .voxepay-otp-timer span { font-weight: 700; color: var(--voxepay-primary); }\n \n .voxepay-resend-btn { padding: 8px 16px; background: transparent; border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); color: var(--voxepay-text-muted); font-size: 0.875rem; cursor: pointer; margin-bottom: 16px; transition: all var(--voxepay-transition-fast); }\n .voxepay-resend-btn:hover:not(:disabled) { border-color: var(--voxepay-primary); color: var(--voxepay-primary); }\n .voxepay-resend-btn:disabled { opacity: 0.5; cursor: not-allowed; }\n \n .voxepay-back-btn { display: block; width: 100%; padding: 12px; background: transparent; border: none; color: var(--voxepay-text-muted); font-size: 0.875rem; cursor: pointer; margin-top: 12px; transition: color var(--voxepay-transition-fast); }\n .voxepay-back-btn:hover { color: var(--voxepay-primary); }\n\n /* Payment Method Tabs */\n .voxepay-method-tabs { display: flex; border-bottom: 1px solid var(--voxepay-border); background: var(--voxepay-surface); }\n .voxepay-method-tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 12px; border: none; background: transparent; color: var(--voxepay-text-muted); font-size: 0.813rem; font-weight: 500; font-family: inherit; cursor: pointer; transition: all var(--voxepay-transition-fast); border-bottom: 2px solid transparent; white-space: nowrap; }\n .voxepay-method-tab svg { width: 16px; height: 16px; flex-shrink: 0; }\n .voxepay-method-tab:hover { color: var(--voxepay-text); background: var(--voxepay-surface-hover); }\n .voxepay-method-tab.active { color: var(--voxepay-primary); border-bottom-color: var(--voxepay-primary); background: var(--voxepay-bg); }\n\n /* Bank Transfer View */\n .voxepay-transfer-view { padding: 4px 0; }\n .voxepay-transfer-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 0; }\n .voxepay-transfer-instruction { text-align: center; margin-bottom: 20px; font-size: 0.938rem; color: var(--voxepay-text-muted); }\n .voxepay-transfer-instruction strong { color: var(--voxepay-text); font-size: 1.063rem; }\n .voxepay-transfer-details { background: var(--voxepay-surface); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); overflow: hidden; margin-bottom: 16px; }\n .voxepay-transfer-detail { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--voxepay-border); }\n .voxepay-transfer-detail:last-child { border-bottom: none; }\n .voxepay-transfer-label { font-size: 0.813rem; color: var(--voxepay-text-muted); font-weight: 500; }\n .voxepay-transfer-value { font-size: 0.938rem; font-weight: 600; color: var(--voxepay-text); }\n .voxepay-transfer-value-row { display: flex; align-items: center; gap: 8px; }\n .voxepay-transfer-account { font-size: 1.125rem; font-weight: 700; color: var(--voxepay-primary); letter-spacing: 1.5px; font-family: 'DM Sans', monospace; }\n .voxepay-transfer-amount { color: var(--voxepay-primary); }\n\n /* Copy Button */\n .voxepay-copy-btn { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid var(--voxepay-border); border-radius: 8px; background: var(--voxepay-surface-hover); color: var(--voxepay-text-muted); cursor: pointer; transition: all var(--voxepay-transition-fast); flex-shrink: 0; }\n .voxepay-copy-btn svg { width: 16px; height: 16px; }\n .voxepay-copy-btn:hover { border-color: var(--voxepay-primary); color: var(--voxepay-primary); background: rgba(0, 97, 255, 0.1); }\n .voxepay-copy-btn.voxepay-copied { border-color: var(--voxepay-success); color: var(--voxepay-success); background: var(--voxepay-success-bg); }\n\n /* Transfer Timer */\n .voxepay-transfer-timer { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; background: var(--voxepay-surface); border: 1px solid var(--voxepay-border); border-radius: var(--voxepay-border-radius); margin-bottom: 16px; font-size: 0.875rem; color: var(--voxepay-text-muted); }\n .voxepay-transfer-timer svg { width: 16px; height: 16px; color: var(--voxepay-primary); flex-shrink: 0; }\n .voxepay-transfer-timer strong { color: var(--voxepay-primary); font-weight: 700; font-family: monospace; font-size: 0.938rem; }\n \n @media (max-width: 480px) { .voxepay-modal { max-width: 100%; max-height: 100%; border-radius: 0; height: 100%; } .voxepay-body { padding: 20px; } .voxepay-otp-digit { width: 42px; height: 50px; font-size: 1.25rem; } .voxepay-transfer-detail { flex-direction: column; align-items: flex-start; gap: 4px; } }\n "}}class C{constructor(){this.config=null,this.currentModal=null,this.initialized=!1}init(e){e.apiKey?e.organizationId?(this.config={theme:"dark",locale:"en-US",...e},this.initialized=!0,"auto"===e.theme?this.applyAutoTheme():"light"===e.theme&&document.documentElement.classList.add("voxepay-light"),e.customStyles&&this.applyCustomStyles(e.customStyles),console.log("[VoxePay] Initialized successfully")):console.error("[VoxePay] Organization ID is required. Find it in your VoxePay dashboard."):console.error("[VoxePay] API key is required. Get your API key from the VoxePay dashboard: Settings > API Keys")}checkout(e){return this.initialized?!e.amount||e.amount<=0?(console.error("[VoxePay] Invalid amount"),void e.onError({code:"INVALID_AMOUNT",message:"Payment amount must be greater than 0",recoverable:!1})):e.currency?(this.closeModal(),this.currentModal=new M({...e,_sdkConfig:{apiKey:this.config.apiKey,organizationId:this.config.organizationId,baseUrl:this.config.baseUrl},onClose:()=>{var t;this.currentModal=null,null===(t=e.onClose)||void 0===t||t.call(e)}}),void this.currentModal.open()):(console.error("[VoxePay] Currency is required"),void e.onError({code:"INVALID_CURRENCY",message:"Currency code is required",recoverable:!1})):(console.error("[VoxePay] Not initialized. Call VoxePay.init() first."),void e.onError({code:"NOT_INITIALIZED",message:"VoxePay SDK not initialized. Call VoxePay.init() first.",recoverable:!1}))}closeModal(){this.currentModal&&(this.currentModal.close(),this.currentModal=null)}setTheme(e){document.documentElement.classList.remove("voxepay-light"),"light"===e?document.documentElement.classList.add("voxepay-light"):"auto"===e&&this.applyAutoTheme(),this.config&&(this.config.theme=e)}applyAutoTheme(){window.matchMedia("(prefers-color-scheme: dark)").matches||document.documentElement.classList.add("voxepay-light"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{var t;"auto"===(null===(t=this.config)||void 0===t?void 0:t.theme)&&document.documentElement.classList.toggle("voxepay-light",!e.matches)})}applyCustomStyles(e){const t=document.documentElement;for(const[a,n]of Object.entries(e))n&&t.style.setProperty(a,n)}get version(){return"0.3.0"}get isInitialized(){return this.initialized}}const L=new C;return"undefined"!=typeof window&&(window.VoxePay=L),e.VoxePay=L,e.VoxePaySDK=C,e.cleanPan=m,e.default=L,e.detectCardBrand=a,e.formatAmount=p,e.formatCVV=d,e.formatCardNumber=s,e.formatExpiry=l,e.formatExpiryForApi=x,e.generateAuthData=h,e.getCurrencySymbol=function(e){return{NGN:"₦",USD:"$",EUR:"€",GBP:"£",GHS:"₵",KES:"KSh",ZAR:"R"}[e.toUpperCase()]||e},e.luhnCheck=n,e.validateCVV=i,e.validateCardNumber=o,e.validateExpiry=r,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
|
2
2
|
//# sourceMappingURL=voxepay-checkout.min.js.map
|