UNPKG

pouchdb-crypto

Version:

encrypted pouchdb/couchdb database

2 lines 361 kB
!function e(t,r,n){function i(o,s){if(!r[o]){if(!t[o]){var f="function"==typeof require&&require;if(!s&&f)return f(o,!0);if(a)return a(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var h=r[o]={exports:{}};t[o][0].call(h.exports,function(e){var r=t[o][1][e];return i(r?r:e)},h,h.exports,e,t,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,t,r){"use strict";var n=e("chacha"),i=e("pouchdb-promise");r.encrypt=function(e,t,r,a){return new i(function(i){var o={},s=n.createCipher(t,r);s.setAAD(a),o.data=s.update(e).toString("hex"),s.final(),o.tag=s.getAuthTag().toString("hex"),i(o)})},r.decrypt=function(e,t,r,a,o){return new i(function(i){var s=n.createDecipher(t,r);s.setAAD(a),s.setAuthTag(o);var f=s.update(e).toString();s.final(),i(f)})}},{chacha:50,"pouchdb-promise":124}],2:[function(e,t,r){(function(t){"use strict";var n=e("native-crypto/encrypt"),i=e("native-crypto/decrypt");r.encrypt=function(e,t,r,i){return n(t,r,e,i).then(function(e){return{tag:e.slice(-16).toString("hex"),data:e.slice(0,-16).toString("hex")}})},r.decrypt=function(e,r,n,a,o){var s=t.concat([e,o]);return i(r,n,s,a).then(function(e){return e.toString()})}}).call(this,e("buffer").Buffer)},{buffer:47,"native-crypto/decrypt":112,"native-crypto/encrypt":113}],3:[function(e,t,r){var n=r;n.bignum=e("bn.js"),n.define=e("./asn1/api").define,n.base=e("./asn1/base"),n.constants=e("./asn1/constants"),n.decoders=e("./asn1/decoders"),n.encoders=e("./asn1/encoders")},{"./asn1/api":4,"./asn1/base":6,"./asn1/constants":10,"./asn1/decoders":12,"./asn1/encoders":15,"bn.js":18}],4:[function(e,t,r){function n(e,t){this.name=e,this.body=t,this.decoders={},this.encoders={}}var i=e("../asn1"),a=e("inherits"),o=r;o.define=function(e,t){return new n(e,t)},n.prototype._createNamed=function(t){var r;try{r=e("vm").runInThisContext("(function "+this.name+"(entity) {\n this._initNamed(entity);\n})")}catch(e){r=function(e){this._initNamed(e)}}return a(r,t),r.prototype._initNamed=function(e){t.call(this,e)},new r(this)},n.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(i.decoders[e])),this.decoders[e]},n.prototype.decode=function(e,t,r){return this._getDecoder(t).decode(e,r)},n.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(i.encoders[e])),this.encoders[e]},n.prototype.encode=function(e,t,r){return this._getEncoder(t).encode(e,r)}},{"../asn1":3,inherits:105,vm:171}],5:[function(e,t,r){function n(e,t){return o.call(this,t),s.isBuffer(e)?(this.base=e,this.offset=0,void(this.length=e.length)):void this.error("Input not Buffer")}function i(e,t){if(Array.isArray(e))this.length=0,this.value=e.map(function(e){return e instanceof i||(e=new i(e,t)),this.length+=e.length,e},this);else if("number"==typeof e){if(!(0<=e&&e<=255))return t.error("non-byte EncoderBuffer value");this.value=e,this.length=1}else if("string"==typeof e)this.value=e,this.length=s.byteLength(e);else{if(!s.isBuffer(e))return t.error("Unsupported type: "+typeof e);this.value=e,this.length=e.length}}var a=e("inherits"),o=e("../base").Reporter,s=e("buffer").Buffer;a(n,o),r.DecoderBuffer=n,n.prototype.save=function(){return{offset:this.offset,reporter:o.prototype.save.call(this)}},n.prototype.restore=function(e){var t=new n(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,o.prototype.restore.call(this,e.reporter),t},n.prototype.isEmpty=function(){return this.offset===this.length},n.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},n.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");var r=new n(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+e,this.offset+=e,r},n.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},r.EncoderBuffer=i,i.prototype.join=function(e,t){return e||(e=new s(this.length)),t||(t=0),0===this.length?e:(Array.isArray(this.value)?this.value.forEach(function(r){r.join(e,t),t+=r.length}):("number"==typeof this.value?e[t]=this.value:"string"==typeof this.value?e.write(this.value,t):s.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length),e)}},{"../base":6,buffer:47,inherits:105}],6:[function(e,t,r){var n=r;n.Reporter=e("./reporter").Reporter,n.DecoderBuffer=e("./buffer").DecoderBuffer,n.EncoderBuffer=e("./buffer").EncoderBuffer,n.Node=e("./node")},{"./buffer":5,"./node":7,"./reporter":8}],7:[function(e,t,r){function n(e,t){var r={};this._baseState=r,r.enc=e,r.parent=t||null,r.children=null,r.tag=null,r.args=null,r.reverseArgs=null,r.choice=null,r.optional=!1,r.any=!1,r.obj=!1,r.use=null,r.useDecoder=null,r.key=null,r.default=null,r.explicit=null,r.implicit=null,r.contains=null,r.parent||(r.children=[],this._wrap())}var i=e("../base").Reporter,a=e("../base").EncoderBuffer,o=e("../base").DecoderBuffer,s=e("minimalistic-assert"),f=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],c=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(f),h=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];t.exports=n;var u=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];n.prototype.clone=function(){var e=this._baseState,t={};u.forEach(function(r){t[r]=e[r]});var r=new this.constructor(t.parent);return r._baseState=t,r},n.prototype._wrap=function(){var e=this._baseState;c.forEach(function(t){this[t]=function(){var r=new this.constructor(this);return e.children.push(r),r[t].apply(r,arguments)}},this)},n.prototype._init=function(e){var t=this._baseState;s(null===t.parent),e.call(this),t.children=t.children.filter(function(e){return e._baseState.parent===this},this),s.equal(t.children.length,1,"Root node can have only one child")},n.prototype._useArgs=function(e){var t=this._baseState,r=e.filter(function(e){return e instanceof this.constructor},this);e=e.filter(function(e){return!(e instanceof this.constructor)},this),0!==r.length&&(s(null===t.children),t.children=r,r.forEach(function(e){e._baseState.parent=this},this)),0!==e.length&&(s(null===t.args),t.args=e,t.reverseArgs=e.map(function(e){if("object"!=typeof e||e.constructor!==Object)return e;var t={};return Object.keys(e).forEach(function(r){r==(0|r)&&(r|=0);var n=e[r];t[n]=r}),t}))},h.forEach(function(e){n.prototype[e]=function(){var t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}}),f.forEach(function(e){n.prototype[e]=function(){var t=this._baseState,r=Array.prototype.slice.call(arguments);return s(null===t.tag),t.tag=e,this._useArgs(r),this}}),n.prototype.use=function(e){s(e);var t=this._baseState;return s(null===t.use),t.use=e,this},n.prototype.optional=function(){var e=this._baseState;return e.optional=!0,this},n.prototype.def=function(e){var t=this._baseState;return s(null===t.default),t.default=e,t.optional=!0,this},n.prototype.explicit=function(e){var t=this._baseState;return s(null===t.explicit&&null===t.implicit),t.explicit=e,this},n.prototype.implicit=function(e){var t=this._baseState;return s(null===t.explicit&&null===t.implicit),t.implicit=e,this},n.prototype.obj=function(){var e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},n.prototype.key=function(e){var t=this._baseState;return s(null===t.key),t.key=e,this},n.prototype.any=function(){var e=this._baseState;return e.any=!0,this},n.prototype.choice=function(e){var t=this._baseState;return s(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map(function(t){return e[t]})),this},n.prototype.contains=function(e){var t=this._baseState;return s(null===t.use),t.contains=e,this},n.prototype._decode=function(e,t){var r=this._baseState;if(null===r.parent)return e.wrapResult(r.children[0]._decode(e,t));var n=r.default,i=!0,a=null;if(null!==r.key&&(a=e.enterKey(r.key)),r.optional){var s=null;if(null!==r.explicit?s=r.explicit:null!==r.implicit?s=r.implicit:null!==r.tag&&(s=r.tag),null!==s||r.any){if(i=this._peekTag(e,s,r.any),e.isError(i))return i}else{var f=e.save();try{null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t),i=!0}catch(e){i=!1}e.restore(f)}}var c;if(r.obj&&i&&(c=e.enterObject()),i){if(null!==r.explicit){var h=this._decodeTag(e,r.explicit);if(e.isError(h))return h;e=h}var u=e.offset;if(null===r.use&&null===r.choice){if(r.any)var f=e.save();var d=this._decodeTag(e,null!==r.implicit?r.implicit:r.tag,r.any);if(e.isError(d))return d;r.any?n=e.raw(f):e=d}if(t&&t.track&&null!==r.tag&&t.track(e.path(),u,e.length,"tagged"),t&&t.track&&null!==r.tag&&t.track(e.path(),e.offset,e.length,"content"),n=r.any?n:null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t),e.isError(n))return n;if(r.any||null!==r.choice||null===r.children||r.children.forEach(function(r){r._decode(e,t)}),r.contains&&("octstr"===r.tag||"bitstr"===r.tag)){var l=new o(n);n=this._getUse(r.contains,e._reporterState.obj)._decode(l,t)}}return r.obj&&i&&(n=e.leaveObject(c)),null===r.key||null===n&&i!==!0?null!==a&&e.exitKey(a):e.leaveKey(a,r.key,n),n},n.prototype._decodeGeneric=function(e,t,r){var n=this._baseState;return"seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,n.args[0],r):/str$/.test(e)?this._decodeStr(t,e,r):"objid"===e&&n.args?this._decodeObjid(t,n.args[0],n.args[1],r):"objid"===e?this._decodeObjid(t,null,null,r):"gentime"===e||"utctime"===e?this._decodeTime(t,e,r):"null_"===e?this._decodeNull(t,r):"bool"===e?this._decodeBool(t,r):"objDesc"===e?this._decodeStr(t,e,r):"int"===e||"enum"===e?this._decodeInt(t,n.args&&n.args[0],r):null!==n.use?this._getUse(n.use,t._reporterState.obj)._decode(t,r):t.error("unknown tag: "+e)},n.prototype._getUse=function(e,t){var r=this._baseState;return r.useDecoder=this._use(e,t),s(null===r.useDecoder._baseState.parent),r.useDecoder=r.useDecoder._baseState.children[0],r.implicit!==r.useDecoder._baseState.implicit&&(r.useDecoder=r.useDecoder.clone(),r.useDecoder._baseState.implicit=r.implicit),r.useDecoder},n.prototype._decodeChoice=function(e,t){var r=this._baseState,n=null,i=!1;return Object.keys(r.choice).some(function(a){var o=e.save(),s=r.choice[a];try{var f=s._decode(e,t);if(e.isError(f))return!1;n={type:a,value:f},i=!0}catch(t){return e.restore(o),!1}return!0},this),i?n:e.error("Choice not matched")},n.prototype._createEncoderBuffer=function(e){return new a(e,this.reporter)},n.prototype._encode=function(e,t,r){var n=this._baseState;if(null===n.default||n.default!==e){var i=this._encodeValue(e,t,r);if(void 0!==i&&!this._skipDefault(i,t,r))return i}},n.prototype._encodeValue=function(e,t,r){var n=this._baseState;if(null===n.parent)return n.children[0]._encode(e,t||new i);var a=null;if(this.reporter=t,n.optional&&void 0===e){if(null===n.default)return;e=n.default}var o=null,s=!1;if(n.any)a=this._createEncoderBuffer(e);else if(n.choice)a=this._encodeChoice(e,t);else if(n.contains)o=this._getUse(n.contains,r)._encode(e,t),s=!0;else if(n.children)o=n.children.map(function(r){if("null_"===r._baseState.tag)return r._encode(null,t,e);if(null===r._baseState.key)return t.error("Child should have a key");var n=t.enterKey(r._baseState.key);if("object"!=typeof e)return t.error("Child expected, but input is not object");var i=r._encode(e[r._baseState.key],t,e);return t.leaveKey(n),i},this).filter(function(e){return e}),o=this._createEncoderBuffer(o);else if("seqof"===n.tag||"setof"===n.tag){if(!n.args||1!==n.args.length)return t.error("Too many args for : "+n.tag);if(!Array.isArray(e))return t.error("seqof/setof, but data is not Array");var f=this.clone();f._baseState.implicit=null,o=this._createEncoderBuffer(e.map(function(r){var n=this._baseState;return this._getUse(n.args[0],e)._encode(r,t)},f))}else null!==n.use?a=this._getUse(n.use,r)._encode(e,t):(o=this._encodePrimitive(n.tag,e),s=!0);var a;if(!n.any&&null===n.choice){var c=null!==n.implicit?n.implicit:n.tag,h=null===n.implicit?"universal":"context";null===c?null===n.use&&t.error("Tag could be ommited only for .use()"):null===n.use&&(a=this._encodeComposite(c,s,h,o))}return null!==n.explicit&&(a=this._encodeComposite(n.explicit,!1,"context",a)),a},n.prototype._encodeChoice=function(e,t){var r=this._baseState,n=r.choice[e.type];return n||s(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),n._encode(e.value,t)},n.prototype._encodePrimitive=function(e,t){var r=this._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if("objid"===e&&r.args)return this._encodeObjid(t,r.reverseArgs[0],r.args[1]);if("objid"===e)return this._encodeObjid(t,null,null);if("gentime"===e||"utctime"===e)return this._encodeTime(t,e);if("null_"===e)return this._encodeNull();if("int"===e||"enum"===e)return this._encodeInt(t,r.args&&r.reverseArgs[0]);if("bool"===e)return this._encodeBool(t);if("objDesc"===e)return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)},n.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},n.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(e)}},{"../base":6,"minimalistic-assert":110}],8:[function(e,t,r){function n(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function i(e,t){this.path=e,this.rethrow(t)}var a=e("inherits");r.Reporter=n,n.prototype.isError=function(e){return e instanceof i},n.prototype.save=function(){var e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},n.prototype.restore=function(e){var t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},n.prototype.enterKey=function(e){return this._reporterState.path.push(e)},n.prototype.exitKey=function(e){var t=this._reporterState;t.path=t.path.slice(0,e-1)},n.prototype.leaveKey=function(e,t,r){var n=this._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r)},n.prototype.path=function(){return this._reporterState.path.join("/")},n.prototype.enterObject=function(){var e=this._reporterState,t=e.obj;return e.obj={},t},n.prototype.leaveObject=function(e){var t=this._reporterState,r=t.obj;return t.obj=e,r},n.prototype.error=function(e){var t,r=this._reporterState,n=e instanceof i;if(t=n?e:new i(r.path.map(function(e){return"["+JSON.stringify(e)+"]"}).join(""),e.message||e,e.stack),!r.options.partial)throw t;return n||r.errors.push(t),t},n.prototype.wrapResult=function(e){var t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},a(i,Error),i.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,i),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this}},{inherits:105}],9:[function(e,t,r){var n=e("../constants");r.tagClass={0:"universal",1:"application",2:"context",3:"private"},r.tagClassByName=n._reverse(r.tagClass),r.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},r.tagByName=n._reverse(r.tag)},{"../constants":10}],10:[function(e,t,r){var n=r;n._reverse=function(e){var t={};return Object.keys(e).forEach(function(r){(0|r)==r&&(r|=0);var n=e[r];t[n]=r}),t},n.der=e("./der")},{"./der":9}],11:[function(e,t,r){function n(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new i,this.tree._init(e.body)}function i(e){c.Node.call(this,"der",e)}function a(e,t){var r=e.readUInt8(t);if(e.isError(r))return r;var n=u.tagClass[r>>6],i=0===(32&r);if(31===(31&r)){var a=r;for(r=0;128===(128&a);){if(a=e.readUInt8(t),e.isError(a))return a;r<<=7,r|=127&a}}else r&=31;var o=u.tag[r];return{cls:n,primitive:i,tag:r,tagStr:o}}function o(e,t,r){var n=e.readUInt8(r);if(e.isError(n))return n;if(!t&&128===n)return null;if(0===(128&n))return n;var i=127&n;if(i>=4)return e.error("length octect is too long");n=0;for(var a=0;a<i;a++){n<<=8;var o=e.readUInt8(r);if(e.isError(o))return o;n|=o}return n}var s=e("inherits"),f=e("../../asn1"),c=f.base,h=f.bignum,u=f.constants.der;t.exports=n,n.prototype.decode=function(e,t){return e instanceof c.DecoderBuffer||(e=new c.DecoderBuffer(e,t)),this.tree._decode(e,t)},s(i,c.Node),i.prototype._peekTag=function(e,t,r){if(e.isEmpty())return!1;var n=e.save(),i=a(e,'Failed to peek tag: "'+t+'"');return e.isError(i)?i:(e.restore(n),i.tag===t||i.tagStr===t||i.tagStr+"of"===t||r)},i.prototype._decodeTag=function(e,t,r){var n=a(e,'Failed to decode tag of "'+t+'"');if(e.isError(n))return n;var i=o(e,n.primitive,'Failed to get length of "'+t+'"');if(e.isError(i))return i;if(!r&&n.tag!==t&&n.tagStr!==t&&n.tagStr+"of"!==t)return e.error('Failed to match tag: "'+t+'"');if(n.primitive||null!==i)return e.skip(i,'Failed to match body of: "'+t+'"');var s=e.save(),f=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(f)?f:(i=e.offset-s.offset,e.restore(s),e.skip(i,'Failed to match body of: "'+t+'"'))},i.prototype._skipUntilEnd=function(e,t){for(;;){var r=a(e,t);if(e.isError(r))return r;var n=o(e,r.primitive,t);if(e.isError(n))return n;var i;if(i=r.primitive||null!==n?e.skip(n):this._skipUntilEnd(e,t),e.isError(i))return i;if("end"===r.tagStr)break}},i.prototype._decodeList=function(e,t,r,n){for(var i=[];!e.isEmpty();){var a=this._peekTag(e,"end");if(e.isError(a))return a;var o=r.decode(e,"der",n);if(e.isError(o)&&a)break;i.push(o)}return i},i.prototype._decodeStr=function(e,t){if("bitstr"===t){var r=e.readUInt8();return e.isError(r)?r:{unused:r,data:e.raw()}}if("bmpstr"===t){var n=e.raw();if(n.length%2===1)return e.error("Decoding of string type: bmpstr length mismatch");for(var i="",a=0;a<n.length/2;a++)i+=String.fromCharCode(n.readUInt16BE(2*a));return i}if("numstr"===t){var o=e.raw().toString("ascii");return this._isNumstr(o)?o:e.error("Decoding of string type: numstr unsupported characters")}if("octstr"===t)return e.raw();if("objDesc"===t)return e.raw();if("printstr"===t){var s=e.raw().toString("ascii");return this._isPrintstr(s)?s:e.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(t)?e.raw().toString():e.error("Decoding of string type: "+t+" unsupported")},i.prototype._decodeObjid=function(e,t,r){for(var n,i=[],a=0;!e.isEmpty();){var o=e.readUInt8();a<<=7,a|=127&o,0===(128&o)&&(i.push(a),a=0)}128&o&&i.push(a);var s=i[0]/40|0,f=i[0]%40;if(n=r?i:[s,f].concat(i.slice(1)),t){var c=t[n.join(" ")];void 0===c&&(c=t[n.join(".")]),void 0!==c&&(n=c)}return n},i.prototype._decodeTime=function(e,t){var r=e.raw().toString();if("gentime"===t)var n=0|r.slice(0,4),i=0|r.slice(4,6),a=0|r.slice(6,8),o=0|r.slice(8,10),s=0|r.slice(10,12),f=0|r.slice(12,14);else{if("utctime"!==t)return e.error("Decoding "+t+" time is not supported yet");var n=0|r.slice(0,2),i=0|r.slice(2,4),a=0|r.slice(4,6),o=0|r.slice(6,8),s=0|r.slice(8,10),f=0|r.slice(10,12);n=n<70?2e3+n:1900+n}return Date.UTC(n,i-1,a,o,s,f,0)},i.prototype._decodeNull=function(e){return null},i.prototype._decodeBool=function(e){var t=e.readUInt8();return e.isError(t)?t:0!==t},i.prototype._decodeInt=function(e,t){var r=e.raw(),n=new h(r);return t&&(n=t[n.toString(10)]||n),n},i.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree}},{"../../asn1":3,inherits:105}],12:[function(e,t,r){var n=r;n.der=e("./der"),n.pem=e("./pem")},{"./der":11,"./pem":13}],13:[function(e,t,r){function n(e){o.call(this,e),this.enc="pem"}var i=e("inherits"),a=e("buffer").Buffer,o=e("./der");i(n,o),t.exports=n,n.prototype.decode=function(e,t){for(var r=e.toString().split(/[\r\n]+/g),n=t.label.toUpperCase(),i=/^-----(BEGIN|END) ([^-]+)-----$/,s=-1,f=-1,c=0;c<r.length;c++){var h=r[c].match(i);if(null!==h&&h[2]===n){if(s!==-1){if("END"!==h[1])break;f=c;break}if("BEGIN"!==h[1])break;s=c}}if(s===-1||f===-1)throw new Error("PEM section not found for: "+n);var u=r.slice(s+1,f).join("");u.replace(/[^a-z0-9\+\/=]+/gi,"");var d=new a(u,"base64");return o.prototype.decode.call(this,d,t)}},{"./der":11,buffer:47,inherits:105}],14:[function(e,t,r){function n(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new i,this.tree._init(e.body)}function i(e){h.Node.call(this,"der",e)}function a(e){return e<10?"0"+e:e}function o(e,t,r,n){var i;if("seqof"===e?e="seq":"setof"===e&&(e="set"),u.tagByName.hasOwnProperty(e))i=u.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return n.error("Unknown tag: "+e);i=e}return i>=31?n.error("Multi-octet tag encoding unsupported"):(t||(i|=32),i|=u.tagClassByName[r||"universal"]<<6)}var s=e("inherits"),f=e("buffer").Buffer,c=e("../../asn1"),h=c.base,u=c.constants.der;t.exports=n,n.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},s(i,h.Node),i.prototype._encodeComposite=function(e,t,r,n){var i=o(e,t,r,this.reporter);if(n.length<128){var a=new f(2);return a[0]=i,a[1]=n.length,this._createEncoderBuffer([a,n])}for(var s=1,c=n.length;c>=256;c>>=8)s++;var a=new f(2+s);a[0]=i,a[1]=128|s;for(var c=1+s,h=n.length;h>0;c--,h>>=8)a[c]=255&h;return this._createEncoderBuffer([a,n])},i.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){for(var r=new f(2*e.length),n=0;n<e.length;n++)r.writeUInt16BE(e.charCodeAt(n),2*n);return this._createEncoderBuffer(r)}return"numstr"===t?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===t?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(t)?this._createEncoderBuffer(e):"objDesc"===t?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")},i.prototype._encodeObjid=function(e,t,r){if("string"==typeof e){if(!t)return this.reporter.error("string objid given, but no values map found");if(!t.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=t[e].split(/[\s\.]+/g);for(var n=0;n<e.length;n++)e[n]|=0}else if(Array.isArray(e)){e=e.slice();for(var n=0;n<e.length;n++)e[n]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!r){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}for(var i=0,n=0;n<e.length;n++){var a=e[n];for(i++;a>=128;a>>=7)i++}for(var o=new f(i),s=o.length-1,n=e.length-1;n>=0;n--){var a=e[n];for(o[s--]=127&a;(a>>=7)>0;)o[s--]=128|127&a}return this._createEncoderBuffer(o)},i.prototype._encodeTime=function(e,t){var r,n=new Date(e);return"gentime"===t?r=[a(n.getFullYear()),a(n.getUTCMonth()+1),a(n.getUTCDate()),a(n.getUTCHours()),a(n.getUTCMinutes()),a(n.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[a(n.getFullYear()%100),a(n.getUTCMonth()+1),a(n.getUTCDate()),a(n.getUTCHours()),a(n.getUTCMinutes()),a(n.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},i.prototype._encodeNull=function(){return this._createEncoderBuffer("")},i.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if("number"!=typeof e&&!f.isBuffer(e)){var r=e.toArray();!e.sign&&128&r[0]&&r.unshift(0),e=new f(r)}if(f.isBuffer(e)){var n=e.length;0===e.length&&n++;var i=new f(n);return e.copy(i),0===e.length&&(i[0]=0),this._createEncoderBuffer(i)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);for(var n=1,a=e;a>=256;a>>=8)n++;for(var i=new Array(n),a=i.length-1;a>=0;a--)i[a]=255&e,e>>=8;return 128&i[0]&&i.unshift(0),this._createEncoderBuffer(new f(i))},i.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},i.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},i.prototype._skipDefault=function(e,t,r){var n,i=this._baseState;if(null===i.default)return!1;var a=e.join();if(void 0===i.defaultBuffer&&(i.defaultBuffer=this._encodeValue(i.default,t,r).join()),a.length!==i.defaultBuffer.length)return!1;for(n=0;n<a.length;n++)if(a[n]!==i.defaultBuffer[n])return!1;return!0}},{"../../asn1":3,buffer:47,inherits:105}],15:[function(e,t,r){var n=r;n.der=e("./der"),n.pem=e("./pem")},{"./der":14,"./pem":16}],16:[function(e,t,r){function n(e){a.call(this,e),this.enc="pem"}var i=e("inherits"),a=e("./der");i(n,a),t.exports=n,n.prototype.encode=function(e,t){for(var r=a.prototype.encode.call(this,e),n=r.toString("base64"),i=["-----BEGIN "+t.label+"-----"],o=0;o<n.length;o+=64)i.push(n.slice(o,o+64));return i.push("-----END "+t.label+"-----"),i.join("\n")}},{"./der":14,inherits:105}],17:[function(e,t,r){"use strict";function n(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function i(e){return 3*e.length/4-n(e)}function a(e){var t,r,i,a,o,s,f=e.length;o=n(e),s=new u(3*f/4-o),i=o>0?f-4:f;var c=0;for(t=0,r=0;t<i;t+=4,r+=3)a=h[e.charCodeAt(t)]<<18|h[e.charCodeAt(t+1)]<<12|h[e.charCodeAt(t+2)]<<6|h[e.charCodeAt(t+3)],s[c++]=a>>16&255,s[c++]=a>>8&255,s[c++]=255&a;return 2===o?(a=h[e.charCodeAt(t)]<<2|h[e.charCodeAt(t+1)]>>4,s[c++]=255&a):1===o&&(a=h[e.charCodeAt(t)]<<10|h[e.charCodeAt(t+1)]<<4|h[e.charCodeAt(t+2)]>>2,s[c++]=a>>8&255,s[c++]=255&a),s}function o(e){return c[e>>18&63]+c[e>>12&63]+c[e>>6&63]+c[63&e]}function s(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16)+(e[a+1]<<8)+e[a+2],i.push(o(n));return i.join("")}function f(e){for(var t,r=e.length,n=r%3,i="",a=[],o=16383,f=0,h=r-n;f<h;f+=o)a.push(s(e,f,f+o>h?h:f+o));return 1===n?(t=e[r-1],i+=c[t>>2],i+=c[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=c[t>>10],i+=c[t>>4&63],i+=c[t<<2&63],i+="="),a.push(i),a.join("")}r.byteLength=i,r.toByteArray=a,r.fromByteArray=f;for(var c=[],h=[],u="undefined"!=typeof Uint8Array?Uint8Array:Array,d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,p=d.length;l<p;++l)c[l]=d[l],h[d.charCodeAt(l)]=l;h["-".charCodeAt(0)]=62,h["_".charCodeAt(0)]=63},{}],18:[function(e,t,r){!function(t,r){"use strict";function n(e,t){if(!e)throw new Error(t||"Assertion failed")}function i(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}function a(e,t,r){return a.isBN(e)?e:(this.negative=0,this.words=null,this.length=0,this.red=null,void(null!==e&&("le"!==t&&"be"!==t||(r=t,t=10),this._init(e||0,t||10,r||"be"))))}function o(e,t,r){for(var n=0,i=Math.min(e.length,r),a=t;a<i;a++){var o=e.charCodeAt(a)-48;n<<=4,n|=o>=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o}return n}function s(e,t,r,n){for(var i=0,a=Math.min(e.length,r),o=t;o<a;o++){var s=e.charCodeAt(o)-48;i*=n,i+=s>=49?s-49+10:s>=17?s-17+10:s}return i}function f(e){for(var t=new Array(e.bitLength()),r=0;r<t.length;r++){var n=r/26|0,i=r%26;t[r]=(e.words[n]&1<<i)>>>i}return t}function c(e,t,r){r.negative=t.negative^e.negative;var n=e.length+t.length|0;r.length=n,n=n-1|0;var i=0|e.words[0],a=0|t.words[0],o=i*a,s=67108863&o,f=o/67108864|0;r.words[0]=s;for(var c=1;c<n;c++){for(var h=f>>>26,u=67108863&f,d=Math.min(c,t.length-1),l=Math.max(0,c-e.length+1);l<=d;l++){var p=c-l|0;i=0|e.words[p],a=0|t.words[l],o=i*a+u,h+=o/67108864|0,u=67108863&o}r.words[c]=0|u,f=0|h}return 0!==f?r.words[c]=0|f:r.length--,r.strip()}function h(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,i=0,a=0;a<r.length-1;a++){var o=i;i=0;for(var s=67108863&n,f=Math.min(a,t.length-1),c=Math.max(0,a-e.length+1);c<=f;c++){var h=a-c,u=0|e.words[h],d=0|t.words[c],l=u*d,p=67108863&l;o=o+(l/67108864|0)|0,p=p+s|0,s=67108863&p,o=o+(p>>>26)|0,i+=o>>>26,o&=67108863}r.words[a]=s,n=o,o=i}return 0!==n?r.words[a]=n:r.length--,r.strip()}function u(e,t,r){var n=new d;return n.mulp(e,t,r)}function d(e,t){this.x=e,this.y=t}function l(e,t){this.name=e,this.p=new a(t,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function p(){l.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function b(){l.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function v(){l.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function g(){l.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function y(e){if("string"==typeof e){var t=a._prime(e);this.m=t.p,this.prime=t}else n(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function m(e){y.call(this,e),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}"object"==typeof t?t.exports=a:r.BN=a,a.BN=a,a.wordSize=26;var w;try{w=e("buffer").Buffer}catch(e){}a.isBN=function(e){return e instanceof a||null!==e&&"object"==typeof e&&e.constructor.wordSize===a.wordSize&&Array.isArray(e.words)},a.max=function(e,t){return e.cmp(t)>0?e:t},a.min=function(e,t){return e.cmp(t)<0?e:t},a.prototype._init=function(e,t,r){if("number"==typeof e)return this._initNumber(e,t,r);if("object"==typeof e)return this._initArray(e,t,r);"hex"===t&&(t=16),n(t===(0|t)&&t>=2&&t<=36),e=e.toString().replace(/\s+/g,"");var i=0;"-"===e[0]&&i++,16===t?this._parseHex(e,i):this._parseBase(e,t,i),"-"===e[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),t,r)},a.prototype._initNumber=function(e,t,r){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),t,r)},a.prototype._initArray=function(e,t,r){if(n("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var a,o,s=0;if("be"===r)for(i=e.length-1,a=0;i>=0;i-=3)o=e[i]|e[i-1]<<8|e[i-2]<<16,this.words[a]|=o<<s&67108863,this.words[a+1]=o>>>26-s&67108863,s+=24,s>=26&&(s-=26,a++);else if("le"===r)for(i=0,a=0;i<e.length;i+=3)o=e[i]|e[i+1]<<8|e[i+2]<<16,this.words[a]|=o<<s&67108863,this.words[a+1]=o>>>26-s&67108863,s+=24,s>=26&&(s-=26,a++);return this.strip()},a.prototype._parseHex=function(e,t){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var n,i,a=0;for(r=e.length-6,n=0;r>=t;r-=6)i=o(e,r,r+6),this.words[n]|=i<<a&67108863,this.words[n+1]|=i>>>26-a&4194303,a+=24,a>=26&&(a-=26,n++);r+6!==t&&(i=o(e,t,r+6),this.words[n]|=i<<a&67108863,this.words[n+1]|=i>>>26-a&4194303),this.strip()},a.prototype._parseBase=function(e,t,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=t)n++;n--,i=i/t|0;for(var a=e.length-r,o=a%n,f=Math.min(a,a-o)+r,c=0,h=r;h<f;h+=n)c=s(e,h,h+n,t), this.imuln(i),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==o){var u=1;for(c=s(e,h,e.length,t),h=0;h<o;h++)u*=t;this.imuln(u),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}},a.prototype.copy=function(e){e.words=new Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red},a.prototype.clone=function(){var e=new a(null);return this.copy(e),e},a.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},a.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},a.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},a.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var _=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],S=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],M=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];a.prototype.toString=function(e,t){e=e||10,t=0|t||1;var r;if(16===e||"hex"===e){r="";for(var i=0,a=0,o=0;o<this.length;o++){var s=this.words[o],f=(16777215&(s<<i|a)).toString(16);a=s>>>24-i&16777215,r=0!==a||o!==this.length-1?_[6-f.length]+f+r:f+r,i+=2,i>=26&&(i-=26,o--)}for(0!==a&&(r=a.toString(16)+r);r.length%t!==0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(e===(0|e)&&e>=2&&e<=36){var c=S[e],h=M[e];r="";var u=this.clone();for(u.negative=0;!u.isZero();){var d=u.modn(h).toString(e);u=u.idivn(h),r=u.isZero()?d+r:_[c-d.length]+d+r}for(this.isZero()&&(r="0"+r);r.length%t!==0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!1,"Base should be between 2 and 36")},a.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},a.prototype.toJSON=function(){return this.toString(16)},a.prototype.toBuffer=function(e,t){return n("undefined"!=typeof w),this.toArrayLike(w,e,t)},a.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},a.prototype.toArrayLike=function(e,t,r){var i=this.byteLength(),a=r||Math.max(1,i);n(i<=a,"byte array longer than desired length"),n(a>0,"Requested array length <= 0"),this.strip();var o,s,f="le"===t,c=new e(a),h=this.clone();if(f){for(s=0;!h.isZero();s++)o=h.andln(255),h.iushrn(8),c[s]=o;for(;s<a;s++)c[s]=0}else{for(s=0;s<a-i;s++)c[s]=0;for(s=0;!h.isZero();s++)o=h.andln(255),h.iushrn(8),c[a-s-1]=o}return c},Math.clz32?a.prototype._countBits=function(e){return 32-Math.clz32(e)}:a.prototype._countBits=function(e){var t=e,r=0;return t>=4096&&(r+=13,t>>>=13),t>=64&&(r+=7,t>>>=7),t>=8&&(r+=4,t>>>=4),t>=2&&(r+=2,t>>>=2),r+t},a.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,r=0;return 0===(8191&t)&&(r+=13,t>>>=13),0===(127&t)&&(r+=7,t>>>=7),0===(15&t)&&(r+=4,t>>>=4),0===(3&t)&&(r+=2,t>>>=2),0===(1&t)&&r++,r},a.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;t<this.length;t++){var r=this._zeroBits(this.words[t]);if(e+=r,26!==r)break}return e},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(e){return 0!==this.negative?this.abs().inotn(e).iaddn(1):this.clone()},a.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return 0!==this.negative},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]=this.words[t]|e.words[t];return this.strip()},a.prototype.ior=function(e){return n(0===(this.negative|e.negative)),this.iuor(e)},a.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},a.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},a.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]&e.words[r];return this.length=t.length,this.strip()},a.prototype.iand=function(e){return n(0===(this.negative|e.negative)),this.iuand(e)},a.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},a.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},a.prototype.iuxor=function(e){var t,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var n=0;n<r.length;n++)this.words[n]=t.words[n]^r.words[n];if(this!==t)for(;n<t.length;n++)this.words[n]=t.words[n];return this.length=t.length,this.strip()},a.prototype.ixor=function(e){return n(0===(this.negative|e.negative)),this.iuxor(e)},a.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},a.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},a.prototype.inotn=function(e){n("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),r=e%26;this._expand(t),r>0&&t--;for(var i=0;i<t;i++)this.words[i]=67108863&~this.words[i];return r>0&&(this.words[i]=~this.words[i]&67108863>>26-r),this.strip()},a.prototype.notn=function(e){return this.clone().inotn(e)},a.prototype.setn=function(e,t){n("number"==typeof e&&e>=0);var r=e/26|0,i=e%26;return this._expand(r+1),t?this.words[r]=this.words[r]|1<<i:this.words[r]=this.words[r]&~(1<<i),this.strip()},a.prototype.iadd=function(e){var t;if(0!==this.negative&&0===e.negative)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(0===this.negative&&0!==e.negative)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();var r,n;this.length>e.length?(r=this,n=e):(r=e,n=this);for(var i=0,a=0;a<n.length;a++)t=(0|r.words[a])+(0|n.words[a])+i,this.words[a]=67108863&t,i=t>>>26;for(;0!==i&&a<r.length;a++)t=(0|r.words[a])+i,this.words[a]=67108863&t,i=t>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;a<r.length;a++)this.words[a]=r.words[a];return this},a.prototype.add=function(e){var t;return 0!==e.negative&&0===this.negative?(e.negative=0,t=this.sub(e),e.negative^=1,t):0===e.negative&&0!==this.negative?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},a.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var r=this.cmp(e);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;var n,i;r>0?(n=this,i=e):(n=e,i=this);for(var a=0,o=0;o<i.length;o++)t=(0|n.words[o])-(0|i.words[o])+a,a=t>>26,this.words[o]=67108863&t;for(;0!==a&&o<n.length;o++)t=(0|n.words[o])+a,a=t>>26,this.words[o]=67108863&t;if(0===a&&o<n.length&&n!==this)for(;o<n.length;o++)this.words[o]=n.words[o];return this.length=Math.max(this.length,o),n!==this&&(this.negative=1),this.strip()},a.prototype.sub=function(e){return this.clone().isub(e)};var A=function(e,t,r){var n,i,a,o=e.words,s=t.words,f=r.words,c=0,h=0|o[0],u=8191&h,d=h>>>13,l=0|o[1],p=8191&l,b=l>>>13,v=0|o[2],g=8191&v,y=v>>>13,m=0|o[3],w=8191&m,_=m>>>13,S=0|o[4],M=8191&S,A=S>>>13,E=0|o[5],k=8191&E,x=E>>>13,B=0|o[6],I=8191&B,R=B>>>13,j=0|o[7],P=8191&j,C=j>>>13,T=0|o[8],L=8191&T,D=T>>>13,O=0|o[9],q=8191&O,U=O>>>13,z=0|s[0],N=8191&z,K=z>>>13,F=0|s[1],H=8191&F,W=F>>>13,Y=0|s[2],X=8191&Y,V=Y>>>13,G=0|s[3],J=8191&G,Z=G>>>13,$=0|s[4],Q=8191&$,ee=$>>>13,te=0|s[5],re=8191&te,ne=te>>>13,ie=0|s[6],ae=8191&ie,oe=ie>>>13,se=0|s[7],fe=8191&se,ce=se>>>13,he=0|s[8],ue=8191&he,de=he>>>13,le=0|s[9],pe=8191&le,be=le>>>13;r.negative=e.negative^t.negative,r.length=19,n=Math.imul(u,N),i=Math.imul(u,K),i=i+Math.imul(d,N)|0,a=Math.imul(d,K);var ve=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(p,N),i=Math.imul(p,K),i=i+Math.imul(b,N)|0,a=Math.imul(b,K),n=n+Math.imul(u,H)|0,i=i+Math.imul(u,W)|0,i=i+Math.imul(d,H)|0,a=a+Math.imul(d,W)|0;var ge=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(g,N),i=Math.imul(g,K),i=i+Math.imul(y,N)|0,a=Math.imul(y,K),n=n+Math.imul(p,H)|0,i=i+Math.imul(p,W)|0,i=i+Math.imul(b,H)|0,a=a+Math.imul(b,W)|0,n=n+Math.imul(u,X)|0,i=i+Math.imul(u,V)|0,i=i+Math.imul(d,X)|0,a=a+Math.imul(d,V)|0;var ye=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(w,N),i=Math.imul(w,K),i=i+Math.imul(_,N)|0,a=Math.imul(_,K),n=n+Math.imul(g,H)|0,i=i+Math.imul(g,W)|0,i=i+Math.imul(y,H)|0,a=a+Math.imul(y,W)|0,n=n+Math.imul(p,X)|0,i=i+Math.imul(p,V)|0,i=i+Math.imul(b,X)|0,a=a+Math.imul(b,V)|0,n=n+Math.imul(u,J)|0,i=i+Math.imul(u,Z)|0,i=i+Math.imul(d,J)|0,a=a+Math.imul(d,Z)|0;var me=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(me>>>26)|0,me&=67108863,n=Math.imul(M,N),i=Math.imul(M,K),i=i+Math.imul(A,N)|0,a=Math.imul(A,K),n=n+Math.imul(w,H)|0,i=i+Math.imul(w,W)|0,i=i+Math.imul(_,H)|0,a=a+Math.imul(_,W)|0,n=n+Math.imul(g,X)|0,i=i+Math.imul(g,V)|0,i=i+Math.imul(y,X)|0,a=a+Math.imul(y,V)|0,n=n+Math.imul(p,J)|0,i=i+Math.imul(p,Z)|0,i=i+Math.imul(b,J)|0,a=a+Math.imul(b,Z)|0,n=n+Math.imul(u,Q)|0,i=i+Math.imul(u,ee)|0,i=i+Math.imul(d,Q)|0,a=a+Math.imul(d,ee)|0;var we=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(k,N),i=Math.imul(k,K),i=i+Math.imul(x,N)|0,a=Math.imul(x,K),n=n+Math.imul(M,H)|0,i=i+Math.imul(M,W)|0,i=i+Math.imul(A,H)|0,a=a+Math.imul(A,W)|0,n=n+Math.imul(w,X)|0,i=i+Math.imul(w,V)|0,i=i+Math.imul(_,X)|0,a=a+Math.imul(_,V)|0,n=n+Math.imul(g,J)|0,i=i+Math.imul(g,Z)|0,i=i+Math.imul(y,J)|0,a=a+Math.imul(y,Z)|0,n=n+Math.imul(p,Q)|0,i=i+Math.imul(p,ee)|0,i=i+Math.imul(b,Q)|0,a=a+Math.imul(b,ee)|0,n=n+Math.imul(u,re)|0,i=i+Math.imul(u,ne)|0,i=i+Math.imul(d,re)|0,a=a+Math.imul(d,ne)|0;var _e=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(I,N),i=Math.imul(I,K),i=i+Math.imul(R,N)|0,a=Math.imul(R,K),n=n+Math.imul(k,H)|0,i=i+Math.imul(k,W)|0,i=i+Math.imul(x,H)|0,a=a+Math.imul(x,W)|0,n=n+Math.imul(M,X)|0,i=i+Math.imul(M,V)|0,i=i+Math.imul(A,X)|0,a=a+Math.imul(A,V)|0,n=n+Math.imul(w,J)|0,i=i+Math.imul(w,Z)|0,i=i+Math.imul(_,J)|0,a=a+Math.imul(_,Z)|0,n=n+Math.imul(g,Q)|0,i=i+Math.imul(g,ee)|0,i=i+Math.imul(y,Q)|0,a=a+Math.imul(y,ee)|0,n=n+Math.imul(p,re)|0,i=i+Math.imul(p,ne)|0,i=i+Math.imul(b,re)|0,a=a+Math.imul(b,ne)|0,n=n+Math.imul(u,ae)|0,i=i+Math.imul(u,oe)|0,i=i+Math.imul(d,ae)|0,a=a+Math.imul(d,oe)|0;var Se=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(P,N),i=Math.imul(P,K),i=i+Math.imul(C,N)|0,a=Math.imul(C,K),n=n+Math.imul(I,H)|0,i=i+Math.imul(I,W)|0,i=i+Math.imul(R,H)|0,a=a+Math.imul(R,W)|0,n=n+Math.imul(k,X)|0,i=i+Math.imul(k,V)|0,i=i+Math.imul(x,X)|0,a=a+Math.imul(x,V)|0,n=n+Math.imul(M,J)|0,i=i+Math.imul(M,Z)|0,i=i+Math.imul(A,J)|0,a=a+Math.imul(A,Z)|0,n=n+Math.imul(w,Q)|0,i=i+Math.imul(w,ee)|0,i=i+Math.imul(_,Q)|0,a=a+Math.imul(_,ee)|0,n=n+Math.imul(g,re)|0,i=i+Math.imul(g,ne)|0,i=i+Math.imul(y,re)|0,a=a+Math.imul(y,ne)|0,n=n+Math.imul(p,ae)|0,i=i+Math.imul(p,oe)|0,i=i+Math.imul(b,ae)|0,a=a+Math.imul(b,oe)|0,n=n+Math.imul(u,fe)|0,i=i+Math.imul(u,ce)|0,i=i+Math.imul(d,fe)|0,a=a+Math.imul(d,ce)|0;var Me=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(L,N),i=Math.imul(L,K),i=i+Math.imul(D,N)|0,a=Math.imul(D,K),n=n+Math.imul(P,H)|0,i=i+Math.imul(P,W)|0,i=i+Math.imul(C,H)|0,a=a+Math.imul(C,W)|0,n=n+Math.imul(I,X)|0,i=i+Math.imul(I,V)|0,i=i+Math.imul(R,X)|0,a=a+Math.imul(R,V)|0,n=n+Math.imul(k,J)|0,i=i+Math.imul(k,Z)|0,i=i+Math.imul(x,J)|0,a=a+Math.imul(x,Z)|0,n=n+Math.imul(M,Q)|0,i=i+Math.imul(M,ee)|0,i=i+Math.imul(A,Q)|0,a=a+Math.imul(A,ee)|0,n=n+Math.imul(w,re)|0,i=i+Math.imul(w,ne)|0,i=i+Math.imul(_,re)|0,a=a+Math.imul(_,ne)|0,n=n+Math.imul(g,ae)|0,i=i+Math.imul(g,oe)|0,i=i+Math.imul(y,ae)|0,a=a+Math.imul(y,oe)|0,n=n+Math.imul(p,fe)|0,i=i+Math.imul(p,ce)|0,i=i+Math.imul(b,fe)|0,a=a+Math.imul(b,ce)|0,n=n+Math.imul(u,ue)|0,i=i+Math.imul(u,de)|0,i=i+Math.imul(d,ue)|0,a=a+Math.imul(d,de)|0;var Ae=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(q,N),i=Math.imul(q,K),i=i+Math.imul(U,N)|0,a=Math.imul(U,K),n=n+Math.imul(L,H)|0,i=i+Math.imul(L,W)|0,i=i+Math.imul(D,H)|0,a=a+Math.imul(D,W)|0,n=n+Math.imul(P,X)|0,i=i+Math.imul(P,V)|0,i=i+Math.imul(C,X)|0,a=a+Math.imul(C,V)|0,n=n+Math.imul(I,J)|0,i=i+Math.imul(I,Z)|0,i=i+Math.imul(R,J)|0,a=a+Math.imul(R,Z)|0,n=n+Math.imul(k,Q)|0,i=i+Math.imul(k,ee)|0,i=i+Math.imul(x,Q)|0,a=a+Math.imul(x,ee)|0,n=n+Math.imul(M,re)|0,i=i+Math.imul(M,ne)|0,i=i+Math.imul(A,re)|0,a=a+Math.imul(A,ne)|0,n=n+Math.imul(w,ae)|0,i=i+Math.imul(w,oe)|0,i=i+Math.imul(_,ae)|0,a=a+Math.imul(_,oe)|0,n=n+Math.imul(g,fe)|0,i=i+Math.imul(g,ce)|0,i=i+Math.imul(y,fe)|0,a=a+Math.imul(y,ce)|0,n=n+Math.imul(p,ue)|0,i=i+Math.imul(p,de)|0,i=i+Math.imul(b,ue)|0,a=a+Math.imul(b,de)|0,n=n+Math.imul(u,pe)|0,i=i+Math.imul(u,be)|0,i=i+Math.imul(d,pe)|0,a=a+Math.imul(d,be)|0;var Ee=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(q,H),i=Math.imul(q,W),i=i+Math.imul(U,H)|0,a=Math.imul(U,W),n=n+Math.imul(L,X)|0,i=i+Math.imul(L,V)|0,i=i+Math.imul(D,X)|0,a=a+Math.imul(D,V)|0,n=n+Math.imul(P,J)|0,i=i+Math.imul(P,Z)|0,i=i+Math.imul(C,J)|0,a=a+Math.imul(C,Z)|0,n=n+Math.imul(I,Q)|0,i=i+Math.imul(I,ee)|0,i=i+Math.imul(R,Q)|0,a=a+Math.imul(R,ee)|0,n=n+Math.imul(k,re)|0,i=i+Math.imul(k,ne)|0,i=i+Math.imul(x,re)|0,a=a+Math.imul(x,ne)|0,n=n+Math.imul(M,ae)|0,i=i+Math.imul(M,oe)|0,i=i+Math.imul(A,ae)|0,a=a+Math.imul(A,oe)|0,n=n+Math.imul(w,fe)|0,i=i+Math.imul(w,ce)|0,i=i+Math.imul(_,fe)|0,a=a+Math.imul(_,ce)|0,n=n+Math.imul(g,ue)|0,i=i+Math.imul(g,de)|0,i=i+Math.imul(y,ue)|0,a=a+Math.imul(y,de)|0,n=n+Math.imul(p,pe)|0,i=i+Math.imul(p,be)|0,i=i+Math.imul(b,pe)|0,a=a+Math.imul(b,be)|0;var ke=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(q,X),i=Math.imul(q,V),i=i+Math.imul(U,X)|0,a=Math.imul(U,V),n=n+Math.imul(L,J)|0,i=i+Math.imul(L,Z)|0,i=i+Math.imul(D,J)|0,a=a+Math.imul(D,Z)|0,n=n+Math.imul(P,Q)|0,i=i+Math.imul(P,ee)|0,i=i+Math.imul(C,Q)|0,a=a+Math.imul(C,ee)|0,n=n+Math.imul(I,re)|0,i=i+Math.imul(I,ne)|0,i=i+Math.imul(R,re)|0,a=a+Math.imul(R,ne)|0,n=n+Math.imul(k,ae)|0,i=i+Math.imul(k,oe)|0,i=i+Math.imul(x,ae)|0,a=a+Math.imul(x,oe)|0,n=n+Math.imul(M,fe)|0,i=i+Math.imul(M,ce)|0,i=i+Math.imul(A,fe)|0,a=a+Math.imul(A,ce)|0,n=n+Math.imul(w,ue)|0,i=i+Math.imul(w,de)|0,i=i+Math.imul(_,ue)|0,a=a+Math.imul(_,de)|0,n=n+Math.imul(g,pe)|0,i=i+Math.imul(g,be)|0,i=i+Math.imul(y,pe)|0,a=a+Math.imul(y,be)|0;var xe=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(q,J),i=Math.imul(q,Z),i=i+Math.imul(U,J)|0,a=Math.imul(U,Z),n=n+Math.imul(L,Q)|0,i=i+Math.imul(L,ee)|0,i=i+Math.imul(D,Q)|0,a=a+Math.imul(D,ee)|0,n=n+Math.imul(P,re)|0,i=i+Math.imul(P,ne)|0,i=i+Math.imul(C,re)|0,a=a+Math.imul(C,ne)|0,n=n+Math.imul(I,ae)|0,i=i+Math.imul(I,oe)|0,i=i+Math.imul(R,ae)|0,a=a+Math.imul(R,oe)|0,n=n+Math.imul(k,fe)|0,i=i+Math.imul(k,ce)|0,i=i+Math.imul(x,fe)|0,a=a+Math.imul(x,ce)|0,n=n+Math.imul(M,ue)|0,i=i+Math.imul(M,de)|0,i=i+Math.imul(A,ue)|0,a=a+Math.imul(A,de)|0,n=n+Math.imul(w,pe)|0,i=i+Math.imul(w,be)|0,i=i+Math.imul(_,pe)|0,a=a+Math.imul(_,be)|0;var Be=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(Be>>>26)|0,Be&=67108863,n=Math.imul(q,Q),i=Math.imul(q,ee),i=i+Math.imul(U,Q)|0,a=Math.imul(U,ee),n=n+Math.imul(L,re)|0,i=i+Math.imul(L,ne)|0,i=i+Math.imul(D,re)|0,a=a+Math.imul(D,ne)|0,n=n+Math.imul(P,ae)|0,i=i+Math.imul(P,oe)|0,i=i+Math.imul(C,ae)|0,a=a+Math.imul(C,oe)|0,n=n+Math.imul(I,fe)|0,i=i+Math.imul(I,ce)|0,i=i+Math.imul(R,fe)|0,a=a+Math.imul(R,ce)|0,n=n+Math.imul(k,ue)|0,i=i+Math.imul(k,de)|0,i=i+Math.imul(x,ue)|0,a=a+Math.imul(x,de)|0,n=n+Math.imul(M,pe)|0,i=i+Math.imul(M,be)|0,i=i+Math.imul(A,pe)|0,a=a+Math.imul(A,be)|0;var Ie=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(q,re),i=Math.imul(q,ne),i=i+Math.imul(U,re)|0,a=Math.imul(U,ne),n=n+Math.imul(L,ae)|0,i=i+Math.imul(L,oe)|0,i=i+Math.imul(D,ae)|0,a=a+Math.imul(D,oe)|0,n=n+Math.imul(P,fe)|0,i=i+Math.imul(P,ce)|0,i=i+Math.imul(C,fe)|0,a=a+Math.imul(C,ce)|0,n=n+Math.imul(I,ue)|0,i=i+Math.imul(I,de)|0,i=i+Math.imul(R,ue)|0,a=a+Math.imul(R,de)|0,n=n+Math.imul(k,pe)|0,i=i+Math.imul(k,be)|0,i=i+Math.imul(x,pe)|0,a=a+Math.imul(x,be)|0;var Re=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(Re>>>26)|0,Re&=67108863,n=Math.imul(q,ae),i=Math.imul(q,oe),i=i+Math.imul(U,ae)|0,a=Math.imul(U,oe),n=n+Math.imul(L,fe)|0,i=i+Math.imul(L,ce)|0,i=i+Math.imul(D,fe)|0,a=a+Math.imul(D,ce)|0,n=n+Math.imul(P,ue)|0,i=i+Math.imul(P,de)|0,i=i+Math.imul(C,ue)|0,a=a+Math.imul(C,de)|0,n=n+Math.imul(I,pe)|0,i=i+Math.imul(I,be)|0,i=i+Math.imul(R,pe)|0,a=a+Math.imul(R,be)|0;var je=(c+n|0)+((8191&i)<<13)|0;c=(a+(i>>>13)|0)+(je>>>26)|0,je&=67108863,n=Math.imul(q,fe),i=Math.imul(q,ce),i=i+Math.imul(U,fe)|0,a=Math.imul(U,ce),n=n+Math.imul(L,ue)|0,i=i+Math.imul(L,de)|0,i=i+Math.imul(D,ue)|0,a=a+Math.imul(D,de)|0,n=n+Math.imul(P,pe)|0,i=i+Math.imul(P,be)|0,i=i+Math.imul(C,pe)|0,a=a+Math.imul(C,be)|0;var Pe=(c+n|0)+((8191&