UNPKG

happn-util-crypto

Version:
2 lines 413 kB
/**HAPPN CRYPTO UTILS**/ !function e(t,r,i){function n(a,o){if(!r[a]){if(!t[a]){var f="function"==typeof require&&require;if(!o&&f)return f(a,!0);if(s)return s(a,!0);var h=new Error("Cannot find module '"+a+"'");throw h.code="MODULE_NOT_FOUND",h}var u=r[a]={exports:{}};t[a][0].call(u.exports,(function(e){return n(t[a][1][e]||e)}),u,u.exports,e,t,r,i)}return r[a].exports}for(var s="function"==typeof require&&require,a=0;a<i.length;a++)n(i[a]);return n}({1:[function(e,t,r){(function(r){(function(){!function(){const i=e("crypto-browserify"),n=e("crypto"),s=e("randombytes"),a=e("buffer").Buffer,o=e("uuid");let f=!1;function h(t){t||(t={}),this.sign_algorithm=t.sign_algorithm||"RSA-SHA256",this.keypair_algorithm=t.keypair_algorithm||"rsa",this.keypair_length=t.keypair_length||2048,this.randomBytes=s,this.symmetricEncrypt=function(e,t,r){r||(r="aes-256-ctr");var n=i.createCipher(r,t);return n.update(e,"utf8","hex")+n.final("hex")},this.symmetricDecrypt=function(e,t,r){r||(r="aes-256-ctr");var n=i.createDecipher(r,t);return n.update(e,"hex","utf8")+n.final("utf8")},this.symmetricEncryptObject=function(e,t,r){return this.symmetricEncrypt(JSON.stringify(e),t,r)},this.symmetricDecryptObject=function(e,t,r){return JSON.parse(this.symmetricDecrypt(e,t,r))},this.symmetricEncryptiv=function(e,t,r,n){if(!r)throw new Error("an iv is reuired for this operation");n||(n="aes-256-ctr");var s=i.createCipheriv(n,t,r);return s.update(e,"utf8","hex")+s.final("hex")},this.symmetricDecryptiv=function(e,t,r,n){if(!r)throw new Error("an iv is reuired for this operation");n||(n="aes-256-ctr");var s=i.createDecipheriv(n,t,r);return s.update(e,"hex","utf8")+s.final("utf8")},this.symmetricEncryptObjectiv=function(e,t,r,i){return this.symmetricEncryptiv(JSON.stringify(e),t,r,i)},this.symmetricDecryptObjectiv=function(e,t,r,i){return JSON.parse(this.symmetricDecryptiv(e,t,r,i))},this.asymmetricEncrypt=function(e,t){return a.isBuffer(t)||(t=a.from(t)),i.privateEncrypt(e,t)},this.asymmetricDecrypt=function(e,t){return a.isBuffer(t)||(t=a.from(t)),i.publicDecrypt(e,t).toString()},this.sign=function(e,t,r){r||(r="base64"),"string"==typeof e&&(e=a.from(e,r));const n=i.createSign(this.sign_algorithm);return n.update(e),n.end(),n.sign(t).toString("base64")},this.verify=function(e,t,r,n){n||(n="base64"),"string"==typeof e&&(e=a.from(e,n)),"string"==typeof t&&(t=a.from(t,n));const s=i.createVerify(this.sign_algorithm);return s.update(e),s.end(),s.verify(r,t)},this.createKeyPair=function(){return n.generateKeyPairSync(this.keypair_algorithm,{modulusLength:this.keypair_length,publicKeyEncoding:{format:"pem",type:"pkcs1"},privateKeyEncoding:{format:"pem",type:"pkcs1"}})},this.createHashFromString=function(e,t,r){return t||(t="base64"),r||(r="sha256"),i.createHash(r).update(e).digest(t)},this.generateNonce=function(e){return e||(e=o.v4().toString()+o.v4().toString()),this.createHashFromString(e)},this.attacheMiddleware=function(t,i){var n=e("fs");i||(i="/happn_util_crypto"),t.use(i,(function(t,i){if(i.setHeader("Content-Type","application/javascript"),this.cached)return i.end(this.cached);var s=e("path"),a=this;n.readFile(s.resolve(r,"../build/lib/crypto.js"),(function(e,t){a.cached=t.toString(),i.end(a.cached)}))}))}}"undefined"!=typeof window&&"undefined"!=typeof document&&(f=!0),void 0!==t&&(t.exports=h),f&&(window.Crypto=h)}()}).call(this)}).call(this,"/lib")},{buffer:65,crypto:74,"crypto-browserify":74,fs:63,path:147,randombytes:163,uuid:195}],2:[function(e,t,r){"use strict";const i=r;i.bignum=e("bn.js"),i.define=e("./asn1/api").define,i.base=e("./asn1/base"),i.constants=e("./asn1/constants"),i.decoders=e("./asn1/decoders"),i.encoders=e("./asn1/encoders")},{"./asn1/api":3,"./asn1/base":5,"./asn1/constants":9,"./asn1/decoders":11,"./asn1/encoders":14,"bn.js":16}],3:[function(e,t,r){"use strict";const i=e("./encoders"),n=e("./decoders"),s=e("inherits");function a(e,t){this.name=e,this.body=t,this.decoders={},this.encoders={}}r.define=function(e,t){return new a(e,t)},a.prototype._createNamed=function(e){const t=this.name;function r(e){this._initNamed(e,t)}return s(r,e),r.prototype._initNamed=function(t,r){e.call(this,t,r)},new r(this)},a.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(n[e])),this.decoders[e]},a.prototype.decode=function(e,t,r){return this._getDecoder(t).decode(e,r)},a.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(i[e])),this.encoders[e]},a.prototype.encode=function(e,t,r){return this._getEncoder(t).encode(e,r)}},{"./decoders":11,"./encoders":14,inherits:135}],4:[function(e,t,r){"use strict";const i=e("inherits"),n=e("../base/reporter").Reporter,s=e("safer-buffer").Buffer;function a(e,t){n.call(this,t),s.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function o(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return o.isEncoderBuffer(e)||(e=new o(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}}i(a,n),r.DecoderBuffer=a,a.isDecoderBuffer=function(e){if(e instanceof a)return!0;return"object"==typeof e&&s.isBuffer(e.base)&&"DecoderBuffer"===e.constructor.name&&"number"==typeof e.offset&&"number"==typeof e.length&&"function"==typeof e.save&&"function"==typeof e.restore&&"function"==typeof e.isEmpty&&"function"==typeof e.readUInt8&&"function"==typeof e.skip&&"function"==typeof e.raw},a.prototype.save=function(){return{offset:this.offset,reporter:n.prototype.save.call(this)}},a.prototype.restore=function(e){const t=new a(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,n.prototype.restore.call(this,e.reporter),t},a.prototype.isEmpty=function(){return this.offset===this.length},a.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},a.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const r=new a(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+e,this.offset+=e,r},a.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},r.EncoderBuffer=o,o.isEncoderBuffer=function(e){if(e instanceof o)return!0;return"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},o.prototype.join=function(e,t){return e||(e=s.alloc(this.length)),t||(t=0),0===this.length||(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/reporter":7,inherits:135,"safer-buffer":182}],5:[function(e,t,r){"use strict";const i=r;i.Reporter=e("./reporter").Reporter,i.DecoderBuffer=e("./buffer").DecoderBuffer,i.EncoderBuffer=e("./buffer").EncoderBuffer,i.Node=e("./node")},{"./buffer":4,"./node":6,"./reporter":7}],6:[function(e,t,r){"use strict";const i=e("../base/reporter").Reporter,n=e("../base/buffer").EncoderBuffer,s=e("../base/buffer").DecoderBuffer,a=e("minimalistic-assert"),o=["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"],f=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(o);function h(e,t,r){const i={};this._baseState=i,i.name=r,i.enc=e,i.parent=t||null,i.children=null,i.tag=null,i.args=null,i.reverseArgs=null,i.choice=null,i.optional=!1,i.any=!1,i.obj=!1,i.use=null,i.useDecoder=null,i.key=null,i.default=null,i.explicit=null,i.implicit=null,i.contains=null,i.parent||(i.children=[],this._wrap())}t.exports=h;const u=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];h.prototype.clone=function(){const e=this._baseState,t={};u.forEach((function(r){t[r]=e[r]}));const r=new this.constructor(t.parent);return r._baseState=t,r},h.prototype._wrap=function(){const e=this._baseState;f.forEach((function(t){this[t]=function(){const r=new this.constructor(this);return e.children.push(r),r[t].apply(r,arguments)}}),this)},h.prototype._init=function(e){const t=this._baseState;a(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),a.equal(t.children.length,1,"Root node can have only one child")},h.prototype._useArgs=function(e){const 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&&(a(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(a(null===t.args),t.args=e,t.reverseArgs=e.map((function(e){if("object"!=typeof e||e.constructor!==Object)return e;const t={};return Object.keys(e).forEach((function(r){r==(0|r)&&(r|=0);const i=e[r];t[i]=r})),t})))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(e){h.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),o.forEach((function(e){h.prototype[e]=function(){const t=this._baseState,r=Array.prototype.slice.call(arguments);return a(null===t.tag),t.tag=e,this._useArgs(r),this}})),h.prototype.use=function(e){a(e);const t=this._baseState;return a(null===t.use),t.use=e,this},h.prototype.optional=function(){return this._baseState.optional=!0,this},h.prototype.def=function(e){const t=this._baseState;return a(null===t.default),t.default=e,t.optional=!0,this},h.prototype.explicit=function(e){const t=this._baseState;return a(null===t.explicit&&null===t.implicit),t.explicit=e,this},h.prototype.implicit=function(e){const t=this._baseState;return a(null===t.explicit&&null===t.implicit),t.implicit=e,this},h.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},h.prototype.key=function(e){const t=this._baseState;return a(null===t.key),t.key=e,this},h.prototype.any=function(){return this._baseState.any=!0,this},h.prototype.choice=function(e){const t=this._baseState;return a(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},h.prototype.contains=function(e){const t=this._baseState;return a(null===t.use),t.contains=e,this},h.prototype._decode=function(e,t){const r=this._baseState;if(null===r.parent)return e.wrapResult(r.children[0]._decode(e,t));let i,n=r.default,a=!0,o=null;if(null!==r.key&&(o=e.enterKey(r.key)),r.optional){let i=null;if(null!==r.explicit?i=r.explicit:null!==r.implicit?i=r.implicit:null!==r.tag&&(i=r.tag),null!==i||r.any){if(a=this._peekTag(e,i,r.any),e.isError(a))return a}else{const i=e.save();try{null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t),a=!0}catch(e){a=!1}e.restore(i)}}if(r.obj&&a&&(i=e.enterObject()),a){if(null!==r.explicit){const t=this._decodeTag(e,r.explicit);if(e.isError(t))return t;e=t}const i=e.offset;if(null===r.use&&null===r.choice){let t;r.any&&(t=e.save());const i=this._decodeTag(e,null!==r.implicit?r.implicit:r.tag,r.any);if(e.isError(i))return i;r.any?n=e.raw(t):e=i}if(t&&t.track&&null!==r.tag&&t.track(e.path(),i,e.length,"tagged"),t&&t.track&&null!==r.tag&&t.track(e.path(),e.offset,e.length,"content"),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)){const i=new s(n);n=this._getUse(r.contains,e._reporterState.obj)._decode(i,t)}}return r.obj&&a&&(n=e.leaveObject(i)),null===r.key||null===n&&!0!==a?null!==o&&e.exitKey(o):e.leaveKey(o,r.key,n),n},h.prototype._decodeGeneric=function(e,t,r){const i=this._baseState;return"seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,i.args[0],r):/str$/.test(e)?this._decodeStr(t,e,r):"objid"===e&&i.args?this._decodeObjid(t,i.args[0],i.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,i.args&&i.args[0],r):null!==i.use?this._getUse(i.use,t._reporterState.obj)._decode(t,r):t.error("unknown tag: "+e)},h.prototype._getUse=function(e,t){const r=this._baseState;return r.useDecoder=this._use(e,t),a(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},h.prototype._decodeChoice=function(e,t){const r=this._baseState;let i=null,n=!1;return Object.keys(r.choice).some((function(s){const a=e.save(),o=r.choice[s];try{const r=o._decode(e,t);if(e.isError(r))return!1;i={type:s,value:r},n=!0}catch(t){return e.restore(a),!1}return!0}),this),n?i:e.error("Choice not matched")},h.prototype._createEncoderBuffer=function(e){return new n(e,this.reporter)},h.prototype._encode=function(e,t,r){const i=this._baseState;if(null!==i.default&&i.default===e)return;const n=this._encodeValue(e,t,r);return void 0===n||this._skipDefault(n,t,r)?void 0:n},h.prototype._encodeValue=function(e,t,r){const n=this._baseState;if(null===n.parent)return n.children[0]._encode(e,t||new i);let s=null;if(this.reporter=t,n.optional&&void 0===e){if(null===n.default)return;e=n.default}let a=null,o=!1;if(n.any)s=this._createEncoderBuffer(e);else if(n.choice)s=this._encodeChoice(e,t);else if(n.contains)a=this._getUse(n.contains,r)._encode(e,t),o=!0;else if(n.children)a=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");const i=t.enterKey(r._baseState.key);if("object"!=typeof e)return t.error("Child expected, but input is not object");const n=r._encode(e[r._baseState.key],t,e);return t.leaveKey(i),n}),this).filter((function(e){return e})),a=this._createEncoderBuffer(a);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");const r=this.clone();r._baseState.implicit=null,a=this._createEncoderBuffer(e.map((function(r){const i=this._baseState;return this._getUse(i.args[0],e)._encode(r,t)}),r))}else null!==n.use?s=this._getUse(n.use,r)._encode(e,t):(a=this._encodePrimitive(n.tag,e),o=!0);if(!n.any&&null===n.choice){const e=null!==n.implicit?n.implicit:n.tag,r=null===n.implicit?"universal":"context";null===e?null===n.use&&t.error("Tag could be omitted only for .use()"):null===n.use&&(s=this._encodeComposite(e,o,r,a))}return null!==n.explicit&&(s=this._encodeComposite(n.explicit,!1,"context",s)),s},h.prototype._encodeChoice=function(e,t){const r=this._baseState,i=r.choice[e.type];return i||a(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),i._encode(e.value,t)},h.prototype._encodePrimitive=function(e,t){const 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)},h.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},h.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)}},{"../base/buffer":4,"../base/reporter":7,"minimalistic-assert":140}],7:[function(e,t,r){"use strict";const i=e("inherits");function n(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function s(e,t){this.path=e,this.rethrow(t)}r.Reporter=n,n.prototype.isError=function(e){return e instanceof s},n.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},n.prototype.restore=function(e){const 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){const t=this._reporterState;t.path=t.path.slice(0,e-1)},n.prototype.leaveKey=function(e,t,r){const i=this._reporterState;this.exitKey(e),null!==i.obj&&(i.obj[t]=r)},n.prototype.path=function(){return this._reporterState.path.join("/")},n.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},n.prototype.leaveObject=function(e){const t=this._reporterState,r=t.obj;return t.obj=e,r},n.prototype.error=function(e){let t;const r=this._reporterState,i=e instanceof s;if(t=i?e:new s(r.path.map((function(e){return"["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!r.options.partial)throw t;return i||r.errors.push(t),t},n.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},i(s,Error),s.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,s),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this}},{inherits:135}],8:[function(e,t,r){"use strict";function i(e){const t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);const i=e[r];t[i]=r})),t}r.tagClass={0:"universal",1:"application",2:"context",3:"private"},r.tagClassByName=i(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=i(r.tag)},{}],9:[function(e,t,r){"use strict";const i=r;i._reverse=function(e){const t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);const i=e[r];t[i]=r})),t},i.der=e("./der")},{"./der":8}],10:[function(e,t,r){"use strict";const i=e("inherits"),n=e("bn.js"),s=e("../base/buffer").DecoderBuffer,a=e("../base/node"),o=e("../constants/der");function f(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new h,this.tree._init(e.body)}function h(e){a.call(this,"der",e)}function u(e,t){let r=e.readUInt8(t);if(e.isError(r))return r;const i=o.tagClass[r>>6],n=0==(32&r);if(31==(31&r)){let i=r;for(r=0;128==(128&i);){if(i=e.readUInt8(t),e.isError(i))return i;r<<=7,r|=127&i}}else r&=31;return{cls:i,primitive:n,tag:r,tagStr:o.tag[r]}}function c(e,t,r){let i=e.readUInt8(r);if(e.isError(i))return i;if(!t&&128===i)return null;if(0==(128&i))return i;const n=127&i;if(n>4)return e.error("length octect is too long");i=0;for(let t=0;t<n;t++){i<<=8;const t=e.readUInt8(r);if(e.isError(t))return t;i|=t}return i}t.exports=f,f.prototype.decode=function(e,t){return s.isDecoderBuffer(e)||(e=new s(e,t)),this.tree._decode(e,t)},i(h,a),h.prototype._peekTag=function(e,t,r){if(e.isEmpty())return!1;const i=e.save(),n=u(e,'Failed to peek tag: "'+t+'"');return e.isError(n)?n:(e.restore(i),n.tag===t||n.tagStr===t||n.tagStr+"of"===t||r)},h.prototype._decodeTag=function(e,t,r){const i=u(e,'Failed to decode tag of "'+t+'"');if(e.isError(i))return i;let n=c(e,i.primitive,'Failed to get length of "'+t+'"');if(e.isError(n))return n;if(!r&&i.tag!==t&&i.tagStr!==t&&i.tagStr+"of"!==t)return e.error('Failed to match tag: "'+t+'"');if(i.primitive||null!==n)return e.skip(n,'Failed to match body of: "'+t+'"');const s=e.save(),a=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(a)?a:(n=e.offset-s.offset,e.restore(s),e.skip(n,'Failed to match body of: "'+t+'"'))},h.prototype._skipUntilEnd=function(e,t){for(;;){const r=u(e,t);if(e.isError(r))return r;const i=c(e,r.primitive,t);if(e.isError(i))return i;let n;if(n=r.primitive||null!==i?e.skip(i):this._skipUntilEnd(e,t),e.isError(n))return n;if("end"===r.tagStr)break}},h.prototype._decodeList=function(e,t,r,i){const n=[];for(;!e.isEmpty();){const t=this._peekTag(e,"end");if(e.isError(t))return t;const s=r.decode(e,"der",i);if(e.isError(s)&&t)break;n.push(s)}return n},h.prototype._decodeStr=function(e,t){if("bitstr"===t){const t=e.readUInt8();return e.isError(t)?t:{unused:t,data:e.raw()}}if("bmpstr"===t){const t=e.raw();if(t.length%2==1)return e.error("Decoding of string type: bmpstr length mismatch");let r="";for(let e=0;e<t.length/2;e++)r+=String.fromCharCode(t.readUInt16BE(2*e));return r}if("numstr"===t){const t=e.raw().toString("ascii");return this._isNumstr(t)?t:e.error("Decoding of string type: numstr unsupported characters")}if("octstr"===t)return e.raw();if("objDesc"===t)return e.raw();if("printstr"===t){const t=e.raw().toString("ascii");return this._isPrintstr(t)?t:e.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(t)?e.raw().toString():e.error("Decoding of string type: "+t+" unsupported")},h.prototype._decodeObjid=function(e,t,r){let i;const n=[];let s=0,a=0;for(;!e.isEmpty();)a=e.readUInt8(),s<<=7,s|=127&a,0==(128&a)&&(n.push(s),s=0);128&a&&n.push(s);const o=n[0]/40|0,f=n[0]%40;if(i=r?n:[o,f].concat(n.slice(1)),t){let e=t[i.join(" ")];void 0===e&&(e=t[i.join(".")]),void 0!==e&&(i=e)}return i},h.prototype._decodeTime=function(e,t){const r=e.raw().toString();let i,n,s,a,o,f;if("gentime"===t)i=0|r.slice(0,4),n=0|r.slice(4,6),s=0|r.slice(6,8),a=0|r.slice(8,10),o=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");i=0|r.slice(0,2),n=0|r.slice(2,4),s=0|r.slice(4,6),a=0|r.slice(6,8),o=0|r.slice(8,10),f=0|r.slice(10,12),i=i<70?2e3+i:1900+i}return Date.UTC(i,n-1,s,a,o,f,0)},h.prototype._decodeNull=function(){return null},h.prototype._decodeBool=function(e){const t=e.readUInt8();return e.isError(t)?t:0!==t},h.prototype._decodeInt=function(e,t){const r=e.raw();let i=new n(r);return t&&(i=t[i.toString(10)]||i),i},h.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree}},{"../base/buffer":4,"../base/node":6,"../constants/der":8,"bn.js":16,inherits:135}],11:[function(e,t,r){"use strict";const i=r;i.der=e("./der"),i.pem=e("./pem")},{"./der":10,"./pem":12}],12:[function(e,t,r){"use strict";const i=e("inherits"),n=e("safer-buffer").Buffer,s=e("./der");function a(e){s.call(this,e),this.enc="pem"}i(a,s),t.exports=a,a.prototype.decode=function(e,t){const r=e.toString().split(/[\r\n]+/g),i=t.label.toUpperCase(),a=/^-----(BEGIN|END) ([^-]+)-----$/;let o=-1,f=-1;for(let e=0;e<r.length;e++){const t=r[e].match(a);if(null!==t&&t[2]===i){if(-1!==o){if("END"!==t[1])break;f=e;break}if("BEGIN"!==t[1])break;o=e}}if(-1===o||-1===f)throw new Error("PEM section not found for: "+i);const h=r.slice(o+1,f).join("");h.replace(/[^a-z0-9+/=]+/gi,"");const u=n.from(h,"base64");return s.prototype.decode.call(this,u,t)}},{"./der":10,inherits:135,"safer-buffer":182}],13:[function(e,t,r){"use strict";const i=e("inherits"),n=e("safer-buffer").Buffer,s=e("../base/node"),a=e("../constants/der");function o(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new f,this.tree._init(e.body)}function f(e){s.call(this,"der",e)}function h(e){return e<10?"0"+e:e}t.exports=o,o.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},i(f,s),f.prototype._encodeComposite=function(e,t,r,i){const s=function(e,t,r,i){let n;"seqof"===e?e="seq":"setof"===e&&(e="set");if(a.tagByName.hasOwnProperty(e))n=a.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return i.error("Unknown tag: "+e);n=e}if(n>=31)return i.error("Multi-octet tag encoding unsupported");t||(n|=32);return n|=a.tagClassByName[r||"universal"]<<6,n}(e,t,r,this.reporter);if(i.length<128){const e=n.alloc(2);return e[0]=s,e[1]=i.length,this._createEncoderBuffer([e,i])}let o=1;for(let e=i.length;e>=256;e>>=8)o++;const f=n.alloc(2+o);f[0]=s,f[1]=128|o;for(let e=1+o,t=i.length;t>0;e--,t>>=8)f[e]=255&t;return this._createEncoderBuffer([f,i])},f.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){const t=n.alloc(2*e.length);for(let r=0;r<e.length;r++)t.writeUInt16BE(e.charCodeAt(r),2*r);return this._createEncoderBuffer(t)}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)||"objDesc"===t?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")},f.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(let t=0;t<e.length;t++)e[t]|=0}else if(Array.isArray(e)){e=e.slice();for(let t=0;t<e.length;t++)e[t]|=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])}let i=0;for(let t=0;t<e.length;t++){let r=e[t];for(i++;r>=128;r>>=7)i++}const s=n.alloc(i);let a=s.length-1;for(let t=e.length-1;t>=0;t--){let r=e[t];for(s[a--]=127&r;(r>>=7)>0;)s[a--]=128|127&r}return this._createEncoderBuffer(s)},f.prototype._encodeTime=function(e,t){let r;const i=new Date(e);return"gentime"===t?r=[h(i.getUTCFullYear()),h(i.getUTCMonth()+1),h(i.getUTCDate()),h(i.getUTCHours()),h(i.getUTCMinutes()),h(i.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[h(i.getUTCFullYear()%100),h(i.getUTCMonth()+1),h(i.getUTCDate()),h(i.getUTCHours()),h(i.getUTCMinutes()),h(i.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},f.prototype._encodeNull=function(){return this._createEncoderBuffer("")},f.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&&!n.isBuffer(e)){const t=e.toArray();!e.sign&&128&t[0]&&t.unshift(0),e=n.from(t)}if(n.isBuffer(e)){let t=e.length;0===e.length&&t++;const r=n.alloc(t);return e.copy(r),0===e.length&&(r[0]=0),this._createEncoderBuffer(r)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let r=1;for(let t=e;t>=256;t>>=8)r++;const i=new Array(r);for(let t=i.length-1;t>=0;t--)i[t]=255&e,e>>=8;return 128&i[0]&&i.unshift(0),this._createEncoderBuffer(n.from(i))},f.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},f.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},f.prototype._skipDefault=function(e,t,r){const i=this._baseState;let n;if(null===i.default)return!1;const s=e.join();if(void 0===i.defaultBuffer&&(i.defaultBuffer=this._encodeValue(i.default,t,r).join()),s.length!==i.defaultBuffer.length)return!1;for(n=0;n<s.length;n++)if(s[n]!==i.defaultBuffer[n])return!1;return!0}},{"../base/node":6,"../constants/der":8,inherits:135,"safer-buffer":182}],14:[function(e,t,r){"use strict";const i=r;i.der=e("./der"),i.pem=e("./pem")},{"./der":13,"./pem":15}],15:[function(e,t,r){"use strict";const i=e("inherits"),n=e("./der");function s(e){n.call(this,e),this.enc="pem"}i(s,n),t.exports=s,s.prototype.encode=function(e,t){const r=n.prototype.encode.call(this,e).toString("base64"),i=["-----BEGIN "+t.label+"-----"];for(let e=0;e<r.length;e+=64)i.push(r.slice(e,e+64));return i.push("-----END "+t.label+"-----"),i.join("\n")}},{"./der":13,inherits:135}],16:[function(e,t,r){!function(t,r){"use strict";function i(e,t){if(!e)throw new Error(t||"Assertion failed")}function n(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}function s(e,t,r){if(s.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(r=t,t=10),this._init(e||0,t||10,r||"be"))}var a;"object"==typeof t?t.exports=s:r.BN=s,s.BN=s,s.wordSize=26;try{a="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:e("buffer").Buffer}catch(e){}function o(e,t){var r=e.charCodeAt(t);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function f(e,t,r){var i=o(e,r);return r-1>=t&&(i|=o(e,r-1)<<4),i}function h(e,t,r,i){for(var n=0,s=Math.min(e.length,r),a=t;a<s;a++){var o=e.charCodeAt(a)-48;n*=i,n+=o>=49?o-49+10:o>=17?o-17+10:o}return n}s.isBN=function(e){return e instanceof s||null!==e&&"object"==typeof e&&e.constructor.wordSize===s.wordSize&&Array.isArray(e.words)},s.max=function(e,t){return e.cmp(t)>0?e:t},s.min=function(e,t){return e.cmp(t)<0?e:t},s.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),i(t===(0|t)&&t>=2&&t<=36);var n=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n<e.length&&(16===t?this._parseHex(e,n,r):(this._parseBase(e,t,n),"le"===r&&this._initArray(this.toArray(),t,r)))},s.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):(i(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),t,r)},s.prototype._initArray=function(e,t,r){if(i("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 n=0;n<this.length;n++)this.words[n]=0;var s,a,o=0;if("be"===r)for(n=e.length-1,s=0;n>=0;n-=3)a=e[n]|e[n-1]<<8|e[n-2]<<16,this.words[s]|=a<<o&67108863,this.words[s+1]=a>>>26-o&67108863,(o+=24)>=26&&(o-=26,s++);else if("le"===r)for(n=0,s=0;n<e.length;n+=3)a=e[n]|e[n+1]<<8|e[n+2]<<16,this.words[s]|=a<<o&67108863,this.words[s+1]=a>>>26-o&67108863,(o+=24)>=26&&(o-=26,s++);return this.strip()},s.prototype._parseHex=function(e,t,r){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var n,s=0,a=0;if("be"===r)for(i=e.length-1;i>=t;i-=2)n=f(e,t,i)<<s,this.words[a]|=67108863&n,s>=18?(s-=18,a+=1,this.words[a]|=n>>>26):s+=8;else for(i=(e.length-t)%2==0?t+1:t;i<e.length;i+=2)n=f(e,t,i)<<s,this.words[a]|=67108863&n,s>=18?(s-=18,a+=1,this.words[a]|=n>>>26):s+=8;this.strip()},s.prototype._parseBase=function(e,t,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=t)i++;i--,n=n/t|0;for(var s=e.length-r,a=s%i,o=Math.min(s,s-a)+r,f=0,u=r;u<o;u+=i)f=h(e,u,u+i,t),this.imuln(n),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f);if(0!==a){var c=1;for(f=h(e,u,e.length,t),u=0;u<a;u++)c*=t;this.imuln(c),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f)}this.strip()},s.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},s.prototype.clone=function(){var e=new s(null);return this.copy(e),e},s.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},s.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},s.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var u=["","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"],c=[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],d=[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];function l(e,t,r){r.negative=t.negative^e.negative;var i=e.length+t.length|0;r.length=i,i=i-1|0;var n=0|e.words[0],s=0|t.words[0],a=n*s,o=67108863&a,f=a/67108864|0;r.words[0]=o;for(var h=1;h<i;h++){for(var u=f>>>26,c=67108863&f,d=Math.min(h,t.length-1),l=Math.max(0,h-e.length+1);l<=d;l++){var p=h-l|0;u+=(a=(n=0|e.words[p])*(s=0|t.words[l])+c)/67108864|0,c=67108863&a}r.words[h]=0|c,f=0|u}return 0!==f?r.words[h]=0|f:r.length--,r.strip()}s.prototype.toString=function(e,t){var r;if(t=0|t||1,16===(e=e||10)||"hex"===e){r="";for(var n=0,s=0,a=0;a<this.length;a++){var o=this.words[a],f=(16777215&(o<<n|s)).toString(16);r=0!==(s=o>>>24-n&16777215)||a!==this.length-1?u[6-f.length]+f+r:f+r,(n+=2)>=26&&(n-=26,a--)}for(0!==s&&(r=s.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 h=c[e],l=d[e];r="";var p=this.clone();for(p.negative=0;!p.isZero();){var b=p.modn(l).toString(e);r=(p=p.idivn(l)).isZero()?b+r:u[h-b.length]+b+r}for(this.isZero()&&(r="0"+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},s.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&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(e,t){return i(void 0!==a),this.toArrayLike(a,e,t)},s.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},s.prototype.toArrayLike=function(e,t,r){var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0"),this.strip();var a,o,f="le"===t,h=new e(s),u=this.clone();if(f){for(o=0;!u.isZero();o++)a=u.andln(255),u.iushrn(8),h[o]=a;for(;o<s;o++)h[o]=0}else{for(o=0;o<s-n;o++)h[o]=0;for(o=0;!u.isZero();o++)a=u.andln(255),u.iushrn(8),h[s-o-1]=a}return h},Math.clz32?s.prototype._countBits=function(e){return 32-Math.clz32(e)}:s.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},s.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},s.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},s.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},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(e){return 0!==this.negative?this.abs().inotn(e).iaddn(1):this.clone()},s.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return 0!==this.negative},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.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()},s.prototype.ior=function(e){return i(0==(this.negative|e.negative)),this.iuor(e)},s.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},s.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},s.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()},s.prototype.iand=function(e){return i(0==(this.negative|e.negative)),this.iuand(e)},s.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},s.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},s.prototype.iuxor=function(e){var t,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var i=0;i<r.length;i++)this.words[i]=t.words[i]^r.words[i];if(this!==t)for(;i<t.length;i++)this.words[i]=t.words[i];return this.length=t.length,this.strip()},s.prototype.ixor=function(e){return i(0==(this.negative|e.negative)),this.iuxor(e)},s.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},s.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},s.prototype.inotn=function(e){i("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),r=e%26;this._expand(t),r>0&&t--;for(var n=0;n<t;n++)this.words[n]=67108863&~this.words[n];return r>0&&(this.words[n]=~this.words[n]&67108863>>26-r),this.strip()},s.prototype.notn=function(e){return this.clone().inotn(e)},s.prototype.setn=function(e,t){i("number"==typeof e&&e>=0);var r=e/26|0,n=e%26;return this._expand(r+1),this.words[r]=t?this.words[r]|1<<n:this.words[r]&~(1<<n),this.strip()},s.prototype.iadd=function(e){var t,r,i;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();this.length>e.length?(r=this,i=e):(r=e,i=this);for(var n=0,s=0;s<i.length;s++)t=(0|r.words[s])+(0|i.words[s])+n,this.words[s]=67108863&t,n=t>>>26;for(;0!==n&&s<r.length;s++)t=(0|r.words[s])+n,this.words[s]=67108863&t,n=t>>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this},s.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)},s.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,i,n=this.cmp(e);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=e):(r=e,i=this);for(var s=0,a=0;a<i.length;a++)s=(t=(0|r.words[a])-(0|i.words[a])+s)>>26,this.words[a]=67108863&t;for(;0!==s&&a<r.length;a++)s=(t=(0|r.words[a])+s)>>26,this.words[a]=67108863&t;if(0===s&&a<r.length&&r!==this)for(;a<r.length;a++)this.words[a]=r.words[a];return this.length=Math.max(this.length,a),r!==this&&(this.negative=1),this.strip()},s.prototype.sub=function(e){return this.clone().isub(e)};var p=function(e,t,r){var i,n,s,a=e.words,o=t.words,f=r.words,h=0,u=0|a[0],c=8191&u,d=u>>>13,l=0|a[1],p=8191&l,b=l>>>13,m=0|a[2],y=8191&m,g=m>>>13,v=0|a[3],w=8191&v,_=v>>>13,M=0|a[4],S=8191&M,E=M>>>13,k=0|a[5],A=8191&k,x=k>>>13,B=0|a[6],R=8191&B,I=B>>>13,j=0|a[7],T=8191&j,C=j>>>13,P=0|a[8],L=8191&P,O=P>>>13,D=0|a[9],q=8191&D,N=D>>>13,U=0|o[0],z=8191&U,F=U>>>13,K=0|o[1],H=8191&K,W=K>>>13,V=0|o[2],Z=8191&V,X=V>>>13,G=0|o[3],Y=8191&G,J=G>>>13,$=0|o[4],Q=8191&$,ee=$>>>13,te=0|o[5],re=8191&te,ie=te>>>13,ne=0|o[6],se=8191&ne,ae=ne>>>13,oe=0|o[7],fe=8191&oe,he=oe>>>13,ue=0|o[8],ce=8191&ue,de=ue>>>13,le=0|o[9],pe=8191&le,be=le>>>13;r.negative=e.negative^t.negative,r.length=19;var me=(h+(i=Math.imul(c,z))|0)+((8191&(n=(n=Math.imul(c,F))+Math.imul(d,z)|0))<<13)|0;h=((s=Math.imul(d,F))+(n>>>13)|0)+(me>>>26)|0,me&=67108863,i=Math.imul(p,z),n=(n=Math.imul(p,F))+Math.imul(b,z)|0,s=Math.imul(b,F);var ye=(h+(i=i+Math.imul(c,H)|0)|0)+((8191&(n=(n=n+Math.imul(c,W)|0)+Math.imul(d,H)|0))<<13)|0;h=((s=s+Math.imul(d,W)|0)+(n>>>13)|0)+(ye>>>26)|0,ye&=67108863,i=Math.imul(y,z),n=(n=Math.imul(y,F))+Math.imul(g,z)|0,s=Math.imul(g,F),i=i+Math.imul(p,H)|0,n=(n=n+Math.imul(p,W)|0)+Math.imul(b,H)|0,s=s+Math.imul(b,W)|0;var ge=(h+(i=i+Math.imul(c,Z)|0)|0)+((8191&(n=(n=n+Math.imul(c,X)|0)+Math.imul(d,Z)|0))<<13)|0;h=((s=s+Math.imul(d,X)|0)+(n>>>13)|0)+(ge>>>26)|0,ge&=67108863,i=Math.imul(w,z),n=(n=Math.imul(w,F))+Math.imul(_,z)|0,s=Math.imul(_,F),i=i+Math.imul(y,H)|0,n=(n=n+Math.imul(y,W)|0)+Math.imul(g,H)|0,s=s+Math.imul(g,W)|0,i=i+Math.imul(p,Z)|0,n=(n=n+Math.imul(p,X)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,X)|0;var ve=(h+(i=i+Math.imul(c,Y)|0)|0)+((8191&(n=(n=n+Math.imul(c,J)|0)+Math.imul(d,Y)|0))<<13)|0;h=((s=s+Math.imul(d,J)|0)+(n>>>13)|0)+(ve>>>26)|0,ve&=67108863,i=Math.imul(S,z),n=(n=Math.imul(S,F))+Math.imul(E,z)|0,s=Math.imul(E,F),i=i+Math.imul(w,H)|0,n=(n=n+Math.imul(w,W)|0)+Math.imul(_,H)|0,s=s+Math.imul(_,W)|0,i=i+Math.imul(y,Z)|0,n=(n=n+Math.imul(y,X)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,X)|0,i=i+Math.imul(p,Y)|0,n=(n=n+Math.imul(p,J)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,J)|0;var we=(h+(i=i+Math.imul(c,Q)|0)|0)+((8191&(n=(n=n+Math.imul(c,ee)|0)+Math.imul(d,Q)|0))<<13)|0;h=((s=s+Math.imul(d,ee)|0)+(n>>>13)|0)+(we>>>26)|0,we&=67108863,i=Math.imul(A,z),n=(n=Math.imul(A,F))+Math.imul(x,z)|0,s=Math.imul(x,F),i=i+Math.imul(S,H)|0,n=(n=n+Math.imul(S,W)|0)+Math.imul(E,H)|0,s=s+Math.imul(E,W)|0,i=i+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,X)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,X)|0,i=i+Math.imul(y,Y)|0,n=(n=n+Math.imul(y,J)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,J)|0,i=i+Math.imul(p,Q)|0,n=(n=n+Math.imul(p,ee)|0)+Math.imul(b,Q)|0,s=s+Math.imul(b,ee)|0;var _e=(h+(i=i+Math.imul(c,re)|0)|0)+((8191&(n=(n=n+Math.imul(c,ie)|0)+Math.imul(d,re)|0))<<13)|0;h=((s=s+Math.imul(d,ie)|0)+(n>>>13)|0)+(_e>>>26)|0,_e&=67108863,i=Math.imul(R,z),n=(n=Math.imul(R,F))+Math.imul(I,z)|0,s=Math.imul(I,F),i=i+Math.imul(A,H)|0,n=(n=n+Math.imul(A,W)|0)+Math.imul(x,H)|0,s=s+Math.imul(x,W)|0,i=i+Math.imul(S,Z)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,X)|0,i=i+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,J)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,J)|0,i=i+Math.imul(y,Q)|0,n=(n=n+Math.imul(y,ee)|0)+Math.imul(g,Q)|0,s=s+Math.imul(g,ee)|0,i=i+Math.imul(p,re)|0,n=(n=n+Math.imul(p,ie)|0)+Math.imul(b,re)|0,s=s+Math.imul(b,ie)|0;var Me=(h+(i=i+Math.imul(c,se)|0)|0)+((8191&(n=(n=n+Math.imul(c,ae)|0)+Math.imul(d,se)|0))<<13)|0;h=((s=s+Math.imul(d,ae)|0)+(n>>>13)|0)+(Me>>>26)|0,Me&=67108863,i=Math.imul(T,z),n=(n=Math.imul(T,F))+Math.imul(C,z)|0,s=Math.imul(C,F),i=i+Math.imul(R,H)|0,n=(n=n+Math.imul(R,W)|0)+Math.imul(I,H)|0,s=s+Math.imul(I,W)|0,i=i+Math.imul(A,Z)|0,n=(n=n+Math.imul(A,X)|0)+Math.imul(x,Z)|0,s=s+Math.imul(x,X)|0,i=i+Math.imul(S,Y)|0,n=(n=n+Math.imul(S,J)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,J)|0,i=i+Math.imul(w,Q)|0,n=(n=n+Math.imul(w,ee)|0)+Math.imul(_,Q)|0,s=s+Math.imul(_,ee)|0,i=i+Math.imul(y,re)|0,n=(n=n+Math.imul(y,ie)|0)+Math.imul(g,re)|0,s=s+Math.imul(g,ie)|0,i=i+Math.imul(p,se)|0,n=(n=n+Math.imul(p,ae)|0)+Math.imul(b,se)|0,s=s+Math.imul(b,ae)|0;var Se=(h+(i=i+Math.imul(c,fe)|0)|0)+((8191&(n=(n=n+Math.imul(c,he)|0)+Math.imul(d,fe)|0))<<13)|0;h=((s=s+Math.imul(d,he)|0)+(n>>>13)|0)+(Se>>>26)|0,Se&=67108863,i=Math.imul(L,z),n=(n=Math.imul(L,F))+Math.imul(O,z)|0,s=Math.imul(O,F),i=i+Math.imul(T,H)|0,n=(n=n+Math.imul(T,W)|0)+Math.imul(C,H)|0,s=s+Math.imul(C,W)|0,i=i+Math.imul(R,Z)|0,n=(n=n+Math.imul(R,X)|0)+Math.imul(I,Z)|0,s=s+Math.imul(I,X)|0,i=i+Math.imul(A,Y)|0,n=(n=n+Math.imul(A,J)|0)+Math.imul(x,Y)|0,s=s+Math.imul(x,J)|0,i=i+Math.imul(S,Q)|0,n=(n=n+Math.imul(S,ee)|0)+Math.imul(E,Q)|0,s=s+Math.imul(E,ee)|0,i=i+Math.imul(w,re)|0,n=(n=n+Math.imul(w,ie)|0)+Math.imul(_,re)|0,s=s+Math.imul(_,ie)|0,i=i+Math.imul(y,se)|0,n=(n=n+Math.imul(y,ae)|0)+Math.imul(g,se)|0,s=s+Math.imul(g,ae)|0,i=i+Math.imul(p,fe)|0,n=(n=n+Math.imul(p,he)|0)+Math.imul(b,fe)|0,s=s+Math.imul(b,he)|0;var Ee=(h+(i=i+Math.imul(c,ce)|0)|0)+((8191&(n=(n=n+Math.imul(c,de)|0)+Math.imul(d,ce)|0))<<13)|0;h=((s=s+Math.imul(d,de)|0)+(n>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,i=Math.imul(q,z),n=(n=Math.imul(q,F))+Math.imul(N,z)|0,s=Math.imul(N,F),i=i+Math.imul(L,H)|0,n=(n=n+Math.imul(L,W)|0)+Math.imul(O,H)|0,s=s+Math.imul(O,W)|0,i=i+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,X)|0)+Math.imul(C,Z)|0,s=s+Math.imul(C,X)|0,i=i+Math.imul(R,Y)|0,n=(n=n+Math.imul(R,J)|0)+Math.imul(I,Y)|0,s=s+Math.imul(I,J)|0,i=i+Math.imul(A,Q)|0,n=(n=n+Math.imul(A,ee)|0)+Math.imul(x,Q)|0,s=s+Math.imul(x,ee)|0,i=i+Math.imul(S,re)|0,n=(n=n+Math.imul(S,ie)|0)+Math.imul(E,re)|0,s=s+Math.imul(E,ie)|0,i=i+Math.imul(w,se)|0,n=(n=n+Math.imul(w,ae)|0)+Math.imul(_,se)|0,s=s+Math.imul(_,ae)|0,i=i+Math.imul(y,fe)|0,n=(n=n+Math.imul(y,he)|0)+Math.imul(g,fe)|0,s=s+Math.imul(g,he)|0,i=i+Math.imul(p,ce)|0,n=(n=n+Math.imul(p,de)|0)+Math.imul(b,ce)|0,s=s+Math.imul(b,de)|0;var ke=(h+(i=i+Math.imul(c,pe)|0)|0)+((8191&(n=(n=n+Math.imul(c,be)|0)+Math.imul(d,pe)|0))<<13)|0;h=((s=s+Math.imul(d,be)|0)+(n>>>13)|0)+(ke>>>26)|0,ke&=67108863,i=Math.imul(q,H),n=(n=Math.imul(q,W))+Math.imul(N,H)|0,s=Math.imul(N,W),i=i+Math.imul(L,Z)|0,n=(n=n+Math.imul(L,X)|0)+Math.imul(O,Z)|0,s=s+Math.imul(O,X)|0,i=i+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,J)|0)+Math.imul(C,Y)|0,s=s+Math.imul(C,J)|0,i=i+Math.imul(R,Q)|0,n=(n=n+Math.imul(R,ee)|0)+Math.imul(I,Q)|0,s=s+Math.imul(I,ee)|0,i=i+Math.imul(A,re)|0,n=(n=n+Math.imul(A,ie)|0)+Math.imul(x,re)|0,s=s+Math.imul(x,ie)|0,i=i+Math.imul(S,se)|0,n=(n=n+Math.imul(S,ae)|0)+Math.imul(E,se)|0,s=s+Math.imul(E,ae)|0,i=i+Math.imul(w,fe)|0,n=(n=n+Math.imul(w,he)|0)+Math.imul(_,fe)|0,s=s+Math.imul(_,he)|0,i=i+Math.imul(y,ce)|0,n=(n=n+Math.imul(y,de)|0)+Math.imul(g,ce)|0,s=s+Math.imul(g,de)|0;var Ae=(h+(i=i+Math.imul(p,pe)|0)|0)+((8191&(n=(n=n+Math.imul(p,be)|0)+Math.imul(b,pe)|0))<<13)|0;h=((s=s+Math.imul(b,be)|0)+(n>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,i=Math.imul(q,Z),n=(n=Math.imul(q,X))+Math.imul(N,Z)|0,s=Math.imul(N,X),i=i+Math.imul(L,Y)|0,n=(n=n+Math.imul(L,J)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,J)|0,i=i+Math.imul(T,Q)|0,n=(n=n+Math.imul(T,ee)|0)+Math.imul(C,Q)|0,s=s+Math.imul(C,ee)|0,i=i+Math.imul(R,re)|0,n=(n=n+Math.imul(R,ie)|0)+Math.imul(I,re)|0,s=s+Math.imul(I,ie)|0,i=i+Math.imul(A,se)|0,n=(n=n+Math.imul(A,ae)|0)+Math.imul(x,se)|0,s=s+Math.imul(x,ae)|0,i=i+Math.imul(S,fe)|0,n=(n=n+Math.imul(S,he)|0)+Math.imul(E,fe)|0,s=s+Math.imul(E,he)|0,i=i+Math.imul(w,ce)|0,n=(n=n+Math.imul(w,de)|0)+Math.imul(_,ce)|0,s=s+Math.imul(_,de)|0;var xe=(h+(i=i+Math.imul(y,pe)|0)|0)+((8191&(n=(n=n+Math.imul(y,be)|0)+Math.imul(g,pe)|0))<<13)|0;h=((s=s+Math.imul(g,be)|0)+(n>>>13)|0)+(xe>>>26)|0,xe&=67108863,i=Math.imul(q,Y),n=(n=Math.imul(q,J))+Math.imul(N,Y)|0,s=Math.imul(N,J),i=i+Math.imul(L,Q)|0,n=(n=n+Math.imul(L,ee)|0)+Math.imul(O,Q)|0,s=s+Math.imul(O,ee)|0,i=i+Math.imul(T,re)|0,n=(n=n+Math.imul(T,ie)|0)+Math.imul(C,re)|0,s=s+Math.imul(C,ie)|0,i=i+Math.imul(R,se)|0,n=(n=n+Math.imul(R,ae)|0)+Math.imul(I,se)|0,s=s+Math.imul(I,ae)|0,i=i+Math.imul(A,fe)|0,n=(n=n+Math.imul(A,he)|0)+Math.imul(x,fe)|0,s=s+Math.imul(x,he)|0,i=i+Math.imul(S,ce)|0,n=(n=n+Math.imul(S,de)|0)+Math.imul(E,ce)|0,s=s+Math.imul(E,de)|0;var Be=(h+(i=i+Math.imul(w,pe)|0)|0)+((8191&(n=(n=n+Math.imul(w,be)|0)+Math.imul(_,pe)|0))<<13)|0;h=((s=s+Math.imul(_,be)|0)+(n>>>13)|0)+(Be>>>26)|0,Be&=67108863,i=Math.imul(q,Q),n=(n=Math.imul(q,ee))+Math.imul(N,Q)|0,s=Math.imul(N,ee),i=i+Math.imul(L,re)|0,n=(n=n+Math.imul(L,ie)|0)+Math.imul(O,re)|0,s=s+Math.imul(O,ie)|0,i=i+Math.imul(T,se)|0,n=(n=n+Math.imul(T,ae)|0)+Math.imul(C,se)|0,s=s+Math.imul(C,ae)|0,i=i+Math.imul(R,fe)|0,n=(n=n+Math.imul(R,he)|0)+Math.imul(I,fe)|0,s=s+Math.imul(I,he)|0,i=i+Math.imul(A,ce)|0,n=(n=n+Math.imul(A,de)|0)+Math.imul(x,ce)|0,s=s+Math.imul(x,de)|0;var Re=(h+(i=i+Math.imul(S,pe)|0)|0)+((8191&(n=(n=n+Math.imul(S,be)|0)+Math.imul(E,pe)|0))<<13)|0;h=((s=s+Math.imul(E,be)|0)+(n>>>13)|0)+(Re>>>26)|0,Re&=67108863,i=Math.imul(q,re),n=(n=Math.imul(q,ie))+Math.imul(N,re)|0,s=Math.imul(N,ie),i=i+Math.imul(L,se)|0,n=(n=n+Math.imul(L,ae)|0)+Math.imul(O,se)|0,s=s+Math.imul(O,ae)|0,i=i+Math.imul(T,fe)|0,n=(n=n+Math.imul(T,he)|0)+Math.imul(C,fe)|0,s=s+Math.imul(C,he)|0,i=i+Math.imul(R,ce)|0,n=(n=n+Math.imul(R,de)|0)+Math.imul(I,ce)|0,s=s+Math.imul(I,de)|0;var Ie=(h+(i=i+Math.imul(A,pe)|0)|0)+((8191&(n=(n=n+Math.imul(A,be)|0)+Math.imul(x,pe)|0))<<13)|0;h=((s=s+Math.imul(x,be)|0)+(n>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,i=Math.imul(q,se),n=(n=Math.imul(q,ae))+Math.imul(N,se)|0,s=Math.imul(N,ae),i=i+Math.imul(L,fe)|0,n=(n=n+Math.imul(L,he)|0)+Math.imul(O,fe)|0,s=s+Math.imul(O,he)|0,i=i+Math.imul(T,ce)|0,n=(n=n+Math.imul(T,de)|0)+Math.imul(C,ce)|0,s=s+Math.imul(C,de)|0;var je=(h+(i=i+Math.imul(R,pe)|0)|0)+((8191&(n=(n=n+Math.imul(R,be)|0)+Math.imul(I,pe)|0))<<13)|0;h=((s=s+Math.imul(I,be)|0)+(n>>