UNPKG

hash-anything

Version:

Hash any Javascript primitive or object

1 lines 385 kB
!function(){return function t(e,r,i){function n(o,a){if(!r[o]){if(!e[o]){var f="function"==typeof require&&require;if(!a&&f)return f(o,!0);if(s)return s(o,!0);var h=new Error("Cannot find module '"+o+"'");throw h.code="MODULE_NOT_FOUND",h}var u=r[o]={exports:{}};e[o][0].call(u.exports,function(t){return n(e[o][1][t]||t)},u,u.exports,t,e,r,i)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o<i.length;o++)n(i[o]);return n}}()({1:[function(t,e,r){"use strict";const i=t("buffer").Buffer,n=t("crypto"),s=n.getHashes(),o=n.createHash,a=Object.freeze({Array:1,Boolean:2,Date:3,Function:4,Null:5,Number:6,Object:7,RegExp:8,String:9,Undefined:10,NaN:11,PositiveInfinity:12,NegativeInfinity:13,Int8Array:14,Uint8Array:15,Uint8ClampedArray:16,Int16Array:17,Uint16Array:18,Int32Array:19,Uint32Array:20,Float32Array:21,Float64Array:22,Symbol:23,BigInt:24,Map:25,Set:26,GeneratorFunction:27,AsyncFunction:28});class f{constructor(t){if(!(this instanceof f))throw new Error("new must be used when calling Hash()");if(!t)throw new Error("algorithm is required.");switch(this._buffer=i.alloc(128),this._index=0,typeof t){case"string":t=t.toLowerCase();for(const e of s)if(e.toLowerCase()===t)return void(this._algorithm=e);throw new Error("unrecognized hash algorithm: "+t);case"function":this._hashFunction=t;break;default:throw new Error("unrecognized hash algorithm")}}getValue(){const t=this._buffer.slice(0,this._index);if(this._hashFunction)return this._hashFunction(t);const e=o(this._algorithm);return e.update(t),e.digest("hex")}hash(t){return this._add(t),this}clear(){return this._index=0,this}_resizeBuffer(){const t=i.alloc(2*this._buffer.length);this._buffer.copy(t),this._buffer=t}_writeInt8(t){this._index+1>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeUInt8(t,this._index++)}_writeUInt8(t){this._index+1>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeUInt8(t,this._index++)}_writeInt16LE(t){this._index+2>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeUInt16LE(t,this._index),this._index+=2}_writeUInt16LE(t){this._index+2>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeUInt16LE(t,this._index),this._index+=2}_writeInt32LE(t){this._index+4>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeUInt32LE(t,this._index),this._index+=4}_writeUInt32LE(t){this._index+4>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeUInt32LE(t,this._index),this._index+=4}_writeUInt64LE(t){this._index+8>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeUInt32LE(t<<32>>>0,this._index),this._index+=4,this._buffer.writeUInt32LE(t>>>0,this._index),this._index+=4}_writeFloatLE(t){this._index+4>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeFloatLE(t,this._index),this._index+=8}_writeDoubleLE(t){this._index+8>=this._buffer.length&&this._resizeBuffer(),this._buffer.writeDoubleLE(t,this._index),this._index+=8}_writeString(t){for(;this._index+t.length>=this._buffer.length;)this._resizeBuffer();this._buffer.write(t,this._index),this._index+=t.length}_writeBigInt(t){for(;this._index+8>=this._buffer.length;)this._resizeBuffer();this._buffer.writeBigUInt64LE(t,this._index),this._index+=8}_add(t){switch(Object.prototype.toString.call(t)){case"[object Array]":return void this._addArray(t);case"[object Boolean]":return void this._addBoolean(t);case"[object Date]":return void this._addDate(t);case"[object Function]":return void this._addFunction(t);case"[object Null]":return void this._addNull();case"[object Number]":return void this._addNumber(t);case"[object Object]":return void this._addObject(t);case"[object RegExp]":return void this._addRegExp(t);case"[object String]":return void this._addString(t);case"[object Undefined]":return void this._addUndefined();case"[object Int8Array]":return void this._addInt8Array(t);case"[object Uint8Array]":return void this._addUint8Array(t);case"[object Uint8ClampedArray]":return void this._addUint8ClampedArray(t);case"[object Int16Array]":return void this._addInt16Array(t);case"[object Uint16Array]":return void this._addUint16Array(t);case"[object Int32Array]":return void this._addInt32Array(t);case"[object Uint32Array]":return void this._addUint32Array(t);case"[object Float32Array]":return void this._addFloat32Array(t);case"[object Float64Array]":return void this._addFloat64Array(t);case"[object Symbol]":return void this._addSymbol(t);case"[object BigInt]":return void this._addBigInt(t);case"[object Map]":return void this._addMap(t);case"[object Set]":return void this._addSet(t);case"[object GeneratorFunction]":return void this._addGeneratorFunction(t);case"[object AsyncFunction]":return void this._addAsyncFunction(t);case"[object WeakMap]":throw new TypeError("WeakMap can not be hashed.");case"[object WeakSet]":throw new TypeError("WeakSet can not be hashed.");case"[object Promise]":throw new TypeError("Promise can not be hashed.");case"[object Generator]":throw new TypeError("Generator can not be hashed.");case"[object DataView]":throw new TypeError("DataView can not be hashed.");case"[object Proxy]":throw new TypeError("Proxy can not be hashed.");default:return void this._addObject(t)}}_addArray(t){this._writeUInt8(a.Array);const e=t.length;for(let r=0;r<e;r++)this._addNumber(r),this._add(t[r])}_addInt8Array(t){this._writeUInt8(a.Int8Array);for(let e=0;e<t.length;e++)this._writeInt8(t[e])}_addUint8Array(t){this._writeUInt8(a.Uint8Array);for(let e=0;e<t.length;e++)this._writeUInt8(t[e])}_addUint8ClampedArray(t){this._writeUInt8(a.Uint8ClampedArray);for(let e=0;e<t.length;e++)this._writeUInt8(t[e])}_addInt16Array(t){this._writeUInt8(a.Int16Array);for(let e=0;e<t.length;e++)this._writeInt16LE(t[e])}_addUint16Array(t){this._writeUInt8(a.Uint16Array);for(let e=0;e<t.length;e++)this._writeUInt16LE(t[e])}_addInt32Array(t){this._writeUInt8(a.Int32Array);for(let e=0;e<t.length;e++)this._writeInt32LE(t[e])}_addUint32Array(t){this._writeUInt8(a.Uint32Array);for(let e=0;e<t.length;e++)this._writeUInt32LE(t[e])}_addFloat32Array(t){this._writeUInt8(a.Float32Array);for(let e=0;e<t.length;e++)this._writeFloatLE(t[e])}_addFloat64Array(t){this._writeUInt8(a.Float64Array);for(let e=0;e<t.length;e++)this._writeDoubleLE(t[e])}_addBoolean(t){this._writeUInt8(a.Boolean),this._writeUInt8(t?15:255)}_addDate(t){this._writeUInt8(a.Date),this._writeUInt64LE(+t)}_addFunction(t){this._writeUInt8(a.Function),this._writeString(t.toString());const e=Object.getPrototypeOf(t);e&&e!==Object.prototype&&this._addObject(e)}_addGeneratorFunction(t){this._writeUInt8(a.GeneratorFunction),this._writeString(t.toString());const e=Object.getPrototypeOf(t);e&&e!==Object.prototype&&this._addObject(e)}_addAsyncFunction(t){this._writeUInt8(a.AsyncFunction),this._writeString(t.toString());const e=Object.getPrototypeOf(t);e&&e!==Object.prototype&&this._addObject(e)}_addNull(){this._writeUInt8(a.Null)}_addNumber(t){if(isFinite(t))Math.floor(t)===t?(this._writeUInt8(a.Number),this._writeUInt64LE(t)):(this._writeUInt8(a.Number),this._writeDoubleLE(t));else if(isNaN(t))this._writeUInt8(a.NaN);else if(t===Number.POSITIVE_INFINITY)this._writeUInt8(a.PositiveInfinity);else{if(t!==Number.NEGATIVE_INFINITY)throw new Error("unhandled infinite number");this._writeUInt8(a.NegativeInfinity)}}_addObject(t){this._writeUInt8(a.Object);for(let e in t)if(t.hasOwnProperty(e)){if(this.includeFunc&&!this.includeFunc(t,e))continue;this._addString(e),this._add(t[e])}const e=Object.getPrototypeOf(t);e&&e!==Object.prototype&&this._addObject(e)}_addRegExp(t){this._writeUInt8(a.RegExp),this._writeString(t.toString())}_addString(t){this._writeUInt8(a.String),this._writeString(t)}_addUndefined(){this._writeUInt8(a.Undefined)}_addSymbol(t){this._writeUInt8(a.Symbol),this._writeString(t.description)}_addBigInt(t){this._writeUInt8(a.BigInt),this._writeBigInt(t)}_addMap(t){this._writeUInt8(a.Map);for(let[e,r]of t)this._add(e),this._add(r)}_addSet(t){this._writeUInt8(a.Set);for(let e of t)this._add(e)}}e.exports={Hash:f,sha1:function(t){const e=new f("sha1");return e.hash(t),e.getValue()},md5:function(t){const e=new f("md5");return e.hash(t),e.getValue()},sha256:function(t){const e=new f("sha256");return e.hash(t),e.getValue()},sha512:function(t){const e=new f("sha512");return e.hash(t),e.getValue()}}},{buffer:64,crypto:72}],2:[function(t,e,r){"use strict";const i=r;i.bignum=t("bn.js"),i.define=t("./asn1/api").define,i.base=t("./asn1/base"),i.constants=t("./asn1/constants"),i.decoders=t("./asn1/decoders"),i.encoders=t("./asn1/encoders")},{"./asn1/api":3,"./asn1/base":5,"./asn1/constants":9,"./asn1/decoders":11,"./asn1/encoders":14,"bn.js":16}],3:[function(t,e,r){"use strict";const i=t("./encoders"),n=t("./decoders"),s=t("inherits");function o(t,e){this.name=t,this.body=e,this.decoders={},this.encoders={}}r.define=function(t,e){return new o(t,e)},o.prototype._createNamed=function(t){const e=this.name;function r(t){this._initNamed(t,e)}return s(r,t),r.prototype._initNamed=function(e,r){t.call(this,e,r)},new r(this)},o.prototype._getDecoder=function(t){return t=t||"der",this.decoders.hasOwnProperty(t)||(this.decoders[t]=this._createNamed(n[t])),this.decoders[t]},o.prototype.decode=function(t,e,r){return this._getDecoder(e).decode(t,r)},o.prototype._getEncoder=function(t){return t=t||"der",this.encoders.hasOwnProperty(t)||(this.encoders[t]=this._createNamed(i[t])),this.encoders[t]},o.prototype.encode=function(t,e,r){return this._getEncoder(e).encode(t,r)}},{"./decoders":11,"./encoders":14,inherits:133}],4:[function(t,e,r){"use strict";const i=t("inherits"),n=t("../base/reporter").Reporter,s=t("safer-buffer").Buffer;function o(t,e){n.call(this,e),s.isBuffer(t)?(this.base=t,this.offset=0,this.length=t.length):this.error("Input not Buffer")}function a(t,e){if(Array.isArray(t))this.length=0,this.value=t.map(function(t){return a.isEncoderBuffer(t)||(t=new a(t,e)),this.length+=t.length,t},this);else if("number"==typeof t){if(!(0<=t&&t<=255))return e.error("non-byte EncoderBuffer value");this.value=t,this.length=1}else if("string"==typeof t)this.value=t,this.length=s.byteLength(t);else{if(!s.isBuffer(t))return e.error("Unsupported type: "+typeof t);this.value=t,this.length=t.length}}i(o,n),r.DecoderBuffer=o,o.isDecoderBuffer=function(t){if(t instanceof o)return!0;return"object"==typeof t&&s.isBuffer(t.base)&&"DecoderBuffer"===t.constructor.name&&"number"==typeof t.offset&&"number"==typeof t.length&&"function"==typeof t.save&&"function"==typeof t.restore&&"function"==typeof t.isEmpty&&"function"==typeof t.readUInt8&&"function"==typeof t.skip&&"function"==typeof t.raw},o.prototype.save=function(){return{offset:this.offset,reporter:n.prototype.save.call(this)}},o.prototype.restore=function(t){const e=new o(this.base);return e.offset=t.offset,e.length=this.offset,this.offset=t.offset,n.prototype.restore.call(this,t.reporter),e},o.prototype.isEmpty=function(){return this.offset===this.length},o.prototype.readUInt8=function(t){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(t||"DecoderBuffer overrun")},o.prototype.skip=function(t,e){if(!(this.offset+t<=this.length))return this.error(e||"DecoderBuffer overrun");const r=new o(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+t,this.offset+=t,r},o.prototype.raw=function(t){return this.base.slice(t?t.offset:this.offset,this.length)},r.EncoderBuffer=a,a.isEncoderBuffer=function(t){if(t instanceof a)return!0;return"object"==typeof t&&"EncoderBuffer"===t.constructor.name&&"number"==typeof t.length&&"function"==typeof t.join},a.prototype.join=function(t,e){return t||(t=s.alloc(this.length)),e||(e=0),0===this.length?t:(Array.isArray(this.value)?this.value.forEach(function(r){r.join(t,e),e+=r.length}):("number"==typeof this.value?t[e]=this.value:"string"==typeof this.value?t.write(this.value,e):s.isBuffer(this.value)&&this.value.copy(t,e),e+=this.length),t)}},{"../base/reporter":7,inherits:133,"safer-buffer":162}],5:[function(t,e,r){"use strict";const i=r;i.Reporter=t("./reporter").Reporter,i.DecoderBuffer=t("./buffer").DecoderBuffer,i.EncoderBuffer=t("./buffer").EncoderBuffer,i.Node=t("./node")},{"./buffer":4,"./node":6,"./reporter":7}],6:[function(t,e,r){"use strict";const i=t("../base/reporter").Reporter,n=t("../base/buffer").EncoderBuffer,s=t("../base/buffer").DecoderBuffer,o=t("minimalistic-assert"),a=["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(a);function h(t,e,r){const i={};this._baseState=i,i.name=r,i.enc=t,i.parent=e||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())}e.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 t=this._baseState,e={};u.forEach(function(r){e[r]=t[r]});const r=new this.constructor(e.parent);return r._baseState=e,r},h.prototype._wrap=function(){const t=this._baseState;f.forEach(function(e){this[e]=function(){const r=new this.constructor(this);return t.children.push(r),r[e].apply(r,arguments)}},this)},h.prototype._init=function(t){const e=this._baseState;o(null===e.parent),t.call(this),e.children=e.children.filter(function(t){return t._baseState.parent===this},this),o.equal(e.children.length,1,"Root node can have only one child")},h.prototype._useArgs=function(t){const e=this._baseState,r=t.filter(function(t){return t instanceof this.constructor},this);t=t.filter(function(t){return!(t instanceof this.constructor)},this),0!==r.length&&(o(null===e.children),e.children=r,r.forEach(function(t){t._baseState.parent=this},this)),0!==t.length&&(o(null===e.args),e.args=t,e.reverseArgs=t.map(function(t){if("object"!=typeof t||t.constructor!==Object)return t;const e={};return Object.keys(t).forEach(function(r){r==(0|r)&&(r|=0);const i=t[r];e[i]=r}),e}))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach(function(t){h.prototype[t]=function(){const e=this._baseState;throw new Error(t+" not implemented for encoding: "+e.enc)}}),a.forEach(function(t){h.prototype[t]=function(){const e=this._baseState,r=Array.prototype.slice.call(arguments);return o(null===e.tag),e.tag=t,this._useArgs(r),this}}),h.prototype.use=function(t){o(t);const e=this._baseState;return o(null===e.use),e.use=t,this},h.prototype.optional=function(){return this._baseState.optional=!0,this},h.prototype.def=function(t){const e=this._baseState;return o(null===e.default),e.default=t,e.optional=!0,this},h.prototype.explicit=function(t){const e=this._baseState;return o(null===e.explicit&&null===e.implicit),e.explicit=t,this},h.prototype.implicit=function(t){const e=this._baseState;return o(null===e.explicit&&null===e.implicit),e.implicit=t,this},h.prototype.obj=function(){const t=this._baseState,e=Array.prototype.slice.call(arguments);return t.obj=!0,0!==e.length&&this._useArgs(e),this},h.prototype.key=function(t){const e=this._baseState;return o(null===e.key),e.key=t,this},h.prototype.any=function(){return this._baseState.any=!0,this},h.prototype.choice=function(t){const e=this._baseState;return o(null===e.choice),e.choice=t,this._useArgs(Object.keys(t).map(function(e){return t[e]})),this},h.prototype.contains=function(t){const e=this._baseState;return o(null===e.use),e.contains=t,this},h.prototype._decode=function(t,e){const r=this._baseState;if(null===r.parent)return t.wrapResult(r.children[0]._decode(t,e));let i,n=r.default,o=!0,a=null;if(null!==r.key&&(a=t.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(o=this._peekTag(t,i,r.any),t.isError(o))return o}else{const i=t.save();try{null===r.choice?this._decodeGeneric(r.tag,t,e):this._decodeChoice(t,e),o=!0}catch(t){o=!1}t.restore(i)}}if(r.obj&&o&&(i=t.enterObject()),o){if(null!==r.explicit){const e=this._decodeTag(t,r.explicit);if(t.isError(e))return e;t=e}const i=t.offset;if(null===r.use&&null===r.choice){let e;r.any&&(e=t.save());const i=this._decodeTag(t,null!==r.implicit?r.implicit:r.tag,r.any);if(t.isError(i))return i;r.any?n=t.raw(e):t=i}if(e&&e.track&&null!==r.tag&&e.track(t.path(),i,t.length,"tagged"),e&&e.track&&null!==r.tag&&e.track(t.path(),t.offset,t.length,"content"),r.any||(n=null===r.choice?this._decodeGeneric(r.tag,t,e):this._decodeChoice(t,e)),t.isError(n))return n;if(r.any||null!==r.choice||null===r.children||r.children.forEach(function(r){r._decode(t,e)}),r.contains&&("octstr"===r.tag||"bitstr"===r.tag)){const i=new s(n);n=this._getUse(r.contains,t._reporterState.obj)._decode(i,e)}}return r.obj&&o&&(n=t.leaveObject(i)),null===r.key||null===n&&!0!==o?null!==a&&t.exitKey(a):t.leaveKey(a,r.key,n),n},h.prototype._decodeGeneric=function(t,e,r){const i=this._baseState;return"seq"===t||"set"===t?null:"seqof"===t||"setof"===t?this._decodeList(e,t,i.args[0],r):/str$/.test(t)?this._decodeStr(e,t,r):"objid"===t&&i.args?this._decodeObjid(e,i.args[0],i.args[1],r):"objid"===t?this._decodeObjid(e,null,null,r):"gentime"===t||"utctime"===t?this._decodeTime(e,t,r):"null_"===t?this._decodeNull(e,r):"bool"===t?this._decodeBool(e,r):"objDesc"===t?this._decodeStr(e,t,r):"int"===t||"enum"===t?this._decodeInt(e,i.args&&i.args[0],r):null!==i.use?this._getUse(i.use,e._reporterState.obj)._decode(e,r):e.error("unknown tag: "+t)},h.prototype._getUse=function(t,e){const r=this._baseState;return r.useDecoder=this._use(t,e),o(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(t,e){const r=this._baseState;let i=null,n=!1;return Object.keys(r.choice).some(function(s){const o=t.save(),a=r.choice[s];try{const r=a._decode(t,e);if(t.isError(r))return!1;i={type:s,value:r},n=!0}catch(e){return t.restore(o),!1}return!0},this),n?i:t.error("Choice not matched")},h.prototype._createEncoderBuffer=function(t){return new n(t,this.reporter)},h.prototype._encode=function(t,e,r){const i=this._baseState;if(null!==i.default&&i.default===t)return;const n=this._encodeValue(t,e,r);return void 0===n||this._skipDefault(n,e,r)?void 0:n},h.prototype._encodeValue=function(t,e,r){const n=this._baseState;if(null===n.parent)return n.children[0]._encode(t,e||new i);let s=null;if(this.reporter=e,n.optional&&void 0===t){if(null===n.default)return;t=n.default}let o=null,a=!1;if(n.any)s=this._createEncoderBuffer(t);else if(n.choice)s=this._encodeChoice(t,e);else if(n.contains)o=this._getUse(n.contains,r)._encode(t,e),a=!0;else if(n.children)o=n.children.map(function(r){if("null_"===r._baseState.tag)return r._encode(null,e,t);if(null===r._baseState.key)return e.error("Child should have a key");const i=e.enterKey(r._baseState.key);if("object"!=typeof t)return e.error("Child expected, but input is not object");const n=r._encode(t[r._baseState.key],e,t);return e.leaveKey(i),n},this).filter(function(t){return t}),o=this._createEncoderBuffer(o);else if("seqof"===n.tag||"setof"===n.tag){if(!n.args||1!==n.args.length)return e.error("Too many args for : "+n.tag);if(!Array.isArray(t))return e.error("seqof/setof, but data is not Array");const r=this.clone();r._baseState.implicit=null,o=this._createEncoderBuffer(t.map(function(r){const i=this._baseState;return this._getUse(i.args[0],t)._encode(r,e)},r))}else null!==n.use?s=this._getUse(n.use,r)._encode(t,e):(o=this._encodePrimitive(n.tag,t),a=!0);if(!n.any&&null===n.choice){const t=null!==n.implicit?n.implicit:n.tag,r=null===n.implicit?"universal":"context";null===t?null===n.use&&e.error("Tag could be omitted only for .use()"):null===n.use&&(s=this._encodeComposite(t,a,r,o))}return null!==n.explicit&&(s=this._encodeComposite(n.explicit,!1,"context",s)),s},h.prototype._encodeChoice=function(t,e){const r=this._baseState,i=r.choice[t.type];return i||o(!1,t.type+" not found in "+JSON.stringify(Object.keys(r.choice))),i._encode(t.value,e)},h.prototype._encodePrimitive=function(t,e){const r=this._baseState;if(/str$/.test(t))return this._encodeStr(e,t);if("objid"===t&&r.args)return this._encodeObjid(e,r.reverseArgs[0],r.args[1]);if("objid"===t)return this._encodeObjid(e,null,null);if("gentime"===t||"utctime"===t)return this._encodeTime(e,t);if("null_"===t)return this._encodeNull();if("int"===t||"enum"===t)return this._encodeInt(e,r.args&&r.reverseArgs[0]);if("bool"===t)return this._encodeBool(e);if("objDesc"===t)return this._encodeStr(e,t);throw new Error("Unsupported tag: "+t)},h.prototype._isNumstr=function(t){return/^[0-9 ]*$/.test(t)},h.prototype._isPrintstr=function(t){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(t)}},{"../base/buffer":4,"../base/reporter":7,"minimalistic-assert":137}],7:[function(t,e,r){"use strict";const i=t("inherits");function n(t){this._reporterState={obj:null,path:[],options:t||{},errors:[]}}function s(t,e){this.path=t,this.rethrow(e)}r.Reporter=n,n.prototype.isError=function(t){return t instanceof s},n.prototype.save=function(){const t=this._reporterState;return{obj:t.obj,pathLen:t.path.length}},n.prototype.restore=function(t){const e=this._reporterState;e.obj=t.obj,e.path=e.path.slice(0,t.pathLen)},n.prototype.enterKey=function(t){return this._reporterState.path.push(t)},n.prototype.exitKey=function(t){const e=this._reporterState;e.path=e.path.slice(0,t-1)},n.prototype.leaveKey=function(t,e,r){const i=this._reporterState;this.exitKey(t),null!==i.obj&&(i.obj[e]=r)},n.prototype.path=function(){return this._reporterState.path.join("/")},n.prototype.enterObject=function(){const t=this._reporterState,e=t.obj;return t.obj={},e},n.prototype.leaveObject=function(t){const e=this._reporterState,r=e.obj;return e.obj=t,r},n.prototype.error=function(t){let e;const r=this._reporterState,i=t instanceof s;if(e=i?t:new s(r.path.map(function(t){return"["+JSON.stringify(t)+"]"}).join(""),t.message||t,t.stack),!r.options.partial)throw e;return i||r.errors.push(e),e},n.prototype.wrapResult=function(t){const e=this._reporterState;return e.options.partial?{result:this.isError(t)?null:t,errors:e.errors}:t},i(s,Error),s.prototype.rethrow=function(t){if(this.message=t+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,s),!this.stack)try{throw new Error(this.message)}catch(t){this.stack=t.stack}return this}},{inherits:133}],8:[function(t,e,r){"use strict";function i(t){const e={};return Object.keys(t).forEach(function(r){(0|r)==r&&(r|=0);const i=t[r];e[i]=r}),e}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(t,e,r){"use strict";const i=r;i._reverse=function(t){const e={};return Object.keys(t).forEach(function(r){(0|r)==r&&(r|=0);const i=t[r];e[i]=r}),e},i.der=t("./der")},{"./der":8}],10:[function(t,e,r){"use strict";const i=t("inherits"),n=t("bn.js"),s=t("../base/buffer").DecoderBuffer,o=t("../base/node"),a=t("../constants/der");function f(t){this.enc="der",this.name=t.name,this.entity=t,this.tree=new h,this.tree._init(t.body)}function h(t){o.call(this,"der",t)}function u(t,e){let r=t.readUInt8(e);if(t.isError(r))return r;const i=a.tagClass[r>>6],n=0==(32&r);if(31==(31&r)){let i=r;for(r=0;128==(128&i);){if(i=t.readUInt8(e),t.isError(i))return i;r<<=7,r|=127&i}}else r&=31;return{cls:i,primitive:n,tag:r,tagStr:a.tag[r]}}function c(t,e,r){let i=t.readUInt8(r);if(t.isError(i))return i;if(!e&&128===i)return null;if(0==(128&i))return i;const n=127&i;if(n>4)return t.error("length octect is too long");i=0;for(let e=0;e<n;e++){i<<=8;const e=t.readUInt8(r);if(t.isError(e))return e;i|=e}return i}e.exports=f,f.prototype.decode=function(t,e){return s.isDecoderBuffer(t)||(t=new s(t,e)),this.tree._decode(t,e)},i(h,o),h.prototype._peekTag=function(t,e,r){if(t.isEmpty())return!1;const i=t.save(),n=u(t,'Failed to peek tag: "'+e+'"');return t.isError(n)?n:(t.restore(i),n.tag===e||n.tagStr===e||n.tagStr+"of"===e||r)},h.prototype._decodeTag=function(t,e,r){const i=u(t,'Failed to decode tag of "'+e+'"');if(t.isError(i))return i;let n=c(t,i.primitive,'Failed to get length of "'+e+'"');if(t.isError(n))return n;if(!r&&i.tag!==e&&i.tagStr!==e&&i.tagStr+"of"!==e)return t.error('Failed to match tag: "'+e+'"');if(i.primitive||null!==n)return t.skip(n,'Failed to match body of: "'+e+'"');const s=t.save(),o=this._skipUntilEnd(t,'Failed to skip indefinite length body: "'+this.tag+'"');return t.isError(o)?o:(n=t.offset-s.offset,t.restore(s),t.skip(n,'Failed to match body of: "'+e+'"'))},h.prototype._skipUntilEnd=function(t,e){for(;;){const r=u(t,e);if(t.isError(r))return r;const i=c(t,r.primitive,e);if(t.isError(i))return i;let n;if(n=r.primitive||null!==i?t.skip(i):this._skipUntilEnd(t,e),t.isError(n))return n;if("end"===r.tagStr)break}},h.prototype._decodeList=function(t,e,r,i){const n=[];for(;!t.isEmpty();){const e=this._peekTag(t,"end");if(t.isError(e))return e;const s=r.decode(t,"der",i);if(t.isError(s)&&e)break;n.push(s)}return n},h.prototype._decodeStr=function(t,e){if("bitstr"===e){const e=t.readUInt8();return t.isError(e)?e:{unused:e,data:t.raw()}}if("bmpstr"===e){const e=t.raw();if(e.length%2==1)return t.error("Decoding of string type: bmpstr length mismatch");let r="";for(let t=0;t<e.length/2;t++)r+=String.fromCharCode(e.readUInt16BE(2*t));return r}if("numstr"===e){const e=t.raw().toString("ascii");return this._isNumstr(e)?e:t.error("Decoding of string type: numstr unsupported characters")}if("octstr"===e)return t.raw();if("objDesc"===e)return t.raw();if("printstr"===e){const e=t.raw().toString("ascii");return this._isPrintstr(e)?e:t.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(e)?t.raw().toString():t.error("Decoding of string type: "+e+" unsupported")},h.prototype._decodeObjid=function(t,e,r){let i;const n=[];let s=0,o=0;for(;!t.isEmpty();)s<<=7,s|=127&(o=t.readUInt8()),0==(128&o)&&(n.push(s),s=0);128&o&&n.push(s);const a=n[0]/40|0,f=n[0]%40;if(i=r?n:[a,f].concat(n.slice(1)),e){let t=e[i.join(" ")];void 0===t&&(t=e[i.join(".")]),void 0!==t&&(i=t)}return i},h.prototype._decodeTime=function(t,e){const r=t.raw().toString();let i,n,s,o,a,f;if("gentime"===e)i=0|r.slice(0,4),n=0|r.slice(4,6),s=0|r.slice(6,8),o=0|r.slice(8,10),a=0|r.slice(10,12),f=0|r.slice(12,14);else{if("utctime"!==e)return t.error("Decoding "+e+" time is not supported yet");i=0|r.slice(0,2),n=0|r.slice(2,4),s=0|r.slice(4,6),o=0|r.slice(6,8),a=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,o,a,f,0)},h.prototype._decodeNull=function(){return null},h.prototype._decodeBool=function(t){const e=t.readUInt8();return t.isError(e)?e:0!==e},h.prototype._decodeInt=function(t,e){const r=t.raw();let i=new n(r);return e&&(i=e[i.toString(10)]||i),i},h.prototype._use=function(t,e){return"function"==typeof t&&(t=t(e)),t._getDecoder("der").tree}},{"../base/buffer":4,"../base/node":6,"../constants/der":8,"bn.js":16,inherits:133}],11:[function(t,e,r){"use strict";const i=r;i.der=t("./der"),i.pem=t("./pem")},{"./der":10,"./pem":12}],12:[function(t,e,r){"use strict";const i=t("inherits"),n=t("safer-buffer").Buffer,s=t("./der");function o(t){s.call(this,t),this.enc="pem"}i(o,s),e.exports=o,o.prototype.decode=function(t,e){const r=t.toString().split(/[\r\n]+/g),i=e.label.toUpperCase(),o=/^-----(BEGIN|END) ([^-]+)-----$/;let a=-1,f=-1;for(let t=0;t<r.length;t++){const e=r[t].match(o);if(null!==e&&e[2]===i){if(-1!==a){if("END"!==e[1])break;f=t;break}if("BEGIN"!==e[1])break;a=t}}if(-1===a||-1===f)throw new Error("PEM section not found for: "+i);const h=r.slice(a+1,f).join("");h.replace(/[^a-z0-9+/=]+/gi,"");const u=n.from(h,"base64");return s.prototype.decode.call(this,u,e)}},{"./der":10,inherits:133,"safer-buffer":162}],13:[function(t,e,r){"use strict";const i=t("inherits"),n=t("safer-buffer").Buffer,s=t("../base/node"),o=t("../constants/der");function a(t){this.enc="der",this.name=t.name,this.entity=t,this.tree=new f,this.tree._init(t.body)}function f(t){s.call(this,"der",t)}function h(t){return t<10?"0"+t:t}e.exports=a,a.prototype.encode=function(t,e){return this.tree._encode(t,e).join()},i(f,s),f.prototype._encodeComposite=function(t,e,r,i){const s=function(t,e,r,i){let n;"seqof"===t?t="seq":"setof"===t&&(t="set");if(o.tagByName.hasOwnProperty(t))n=o.tagByName[t];else{if("number"!=typeof t||(0|t)!==t)return i.error("Unknown tag: "+t);n=t}if(n>=31)return i.error("Multi-octet tag encoding unsupported");e||(n|=32);return n|=o.tagClassByName[r||"universal"]<<6}(t,e,r,this.reporter);if(i.length<128){const t=n.alloc(2);return t[0]=s,t[1]=i.length,this._createEncoderBuffer([t,i])}let a=1;for(let t=i.length;t>=256;t>>=8)a++;const f=n.alloc(2+a);f[0]=s,f[1]=128|a;for(let t=1+a,e=i.length;e>0;t--,e>>=8)f[t]=255&e;return this._createEncoderBuffer([f,i])},f.prototype._encodeStr=function(t,e){if("bitstr"===e)return this._createEncoderBuffer([0|t.unused,t.data]);if("bmpstr"===e){const e=n.alloc(2*t.length);for(let r=0;r<t.length;r++)e.writeUInt16BE(t.charCodeAt(r),2*r);return this._createEncoderBuffer(e)}return"numstr"===e?this._isNumstr(t)?this._createEncoderBuffer(t):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===e?this._isPrintstr(t)?this._createEncoderBuffer(t):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(e)?this._createEncoderBuffer(t):"objDesc"===e?this._createEncoderBuffer(t):this.reporter.error("Encoding of string type: "+e+" unsupported")},f.prototype._encodeObjid=function(t,e,r){if("string"==typeof t){if(!e)return this.reporter.error("string objid given, but no values map found");if(!e.hasOwnProperty(t))return this.reporter.error("objid not found in values map");t=e[t].split(/[\s.]+/g);for(let e=0;e<t.length;e++)t[e]|=0}else if(Array.isArray(t)){t=t.slice();for(let e=0;e<t.length;e++)t[e]|=0}if(!Array.isArray(t))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(t));if(!r){if(t[1]>=40)return this.reporter.error("Second objid identifier OOB");t.splice(0,2,40*t[0]+t[1])}let i=0;for(let e=0;e<t.length;e++){let r=t[e];for(i++;r>=128;r>>=7)i++}const s=n.alloc(i);let o=s.length-1;for(let e=t.length-1;e>=0;e--){let r=t[e];for(s[o--]=127&r;(r>>=7)>0;)s[o--]=128|127&r}return this._createEncoderBuffer(s)},f.prototype._encodeTime=function(t,e){let r;const i=new Date(t);return"gentime"===e?r=[h(i.getUTCFullYear()),h(i.getUTCMonth()+1),h(i.getUTCDate()),h(i.getUTCHours()),h(i.getUTCMinutes()),h(i.getUTCSeconds()),"Z"].join(""):"utctime"===e?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 "+e+" time is not supported yet"),this._encodeStr(r,"octstr")},f.prototype._encodeNull=function(){return this._createEncoderBuffer("")},f.prototype._encodeInt=function(t,e){if("string"==typeof t){if(!e)return this.reporter.error("String int or enum given, but no values map");if(!e.hasOwnProperty(t))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(t));t=e[t]}if("number"!=typeof t&&!n.isBuffer(t)){const e=t.toArray();!t.sign&&128&e[0]&&e.unshift(0),t=n.from(e)}if(n.isBuffer(t)){let e=t.length;0===t.length&&e++;const r=n.alloc(e);return t.copy(r),0===t.length&&(r[0]=0),this._createEncoderBuffer(r)}if(t<128)return this._createEncoderBuffer(t);if(t<256)return this._createEncoderBuffer([0,t]);let r=1;for(let e=t;e>=256;e>>=8)r++;const i=new Array(r);for(let e=i.length-1;e>=0;e--)i[e]=255&t,t>>=8;return 128&i[0]&&i.unshift(0),this._createEncoderBuffer(n.from(i))},f.prototype._encodeBool=function(t){return this._createEncoderBuffer(t?255:0)},f.prototype._use=function(t,e){return"function"==typeof t&&(t=t(e)),t._getEncoder("der").tree},f.prototype._skipDefault=function(t,e,r){const i=this._baseState;let n;if(null===i.default)return!1;const s=t.join();if(void 0===i.defaultBuffer&&(i.defaultBuffer=this._encodeValue(i.default,e,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:133,"safer-buffer":162}],14:[function(t,e,r){"use strict";const i=r;i.der=t("./der"),i.pem=t("./pem")},{"./der":13,"./pem":15}],15:[function(t,e,r){"use strict";const i=t("inherits"),n=t("./der");function s(t){n.call(this,t),this.enc="pem"}i(s,n),e.exports=s,s.prototype.encode=function(t,e){const r=n.prototype.encode.call(this,t).toString("base64"),i=["-----BEGIN "+e.label+"-----"];for(let t=0;t<r.length;t+=64)i.push(r.slice(t,t+64));return i.push("-----END "+e.label+"-----"),i.join("\n")}},{"./der":13,inherits:133}],16:[function(t,e,r){!function(e,r){"use strict";function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function s(t,e,r){if(s.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var o;"object"==typeof e?e.exports=s:r.BN=s,s.BN=s,s.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:t("buffer").Buffer}catch(t){}function a(t,e){var r=t.charCodeAt(e);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function f(t,e,r){var i=a(t,r);return r-1>=e&&(i|=a(t,r-1)<<4),i}function h(t,e,r,i){for(var n=0,s=Math.min(t.length,r),o=e;o<s;o++){var a=t.charCodeAt(o)-48;n*=i,n+=a>=49?a-49+10:a>=17?a-17+10:a}return n}s.isBN=function(t){return t instanceof s||null!==t&&"object"==typeof t&&t.constructor.wordSize===s.wordSize&&Array.isArray(t.words)},s.max=function(t,e){return t.cmp(e)>0?t:e},s.min=function(t,e){return t.cmp(e)<0?t:e},s.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n<t.length&&(16===e?this._parseHex(t,n,r):(this._parseBase(t,e,n),"le"===r&&this._initArray(this.toArray(),e,r)))},s.prototype._initNumber=function(t,e,r){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},s.prototype._initArray=function(t,e,r){if(i("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var s,o,a=0;if("be"===r)for(n=t.length-1,s=0;n>=0;n-=3)o=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=o<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n<t.length;n+=3)o=t[n]|t[n+1]<<8|t[n+2]<<16,this.words[s]|=o<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this.strip()},s.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var n,s=0,o=0;if("be"===r)for(i=t.length-1;i>=e;i-=2)n=f(t,e,i)<<s,this.words[o]|=67108863&n,s>=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;else for(i=(t.length-e)%2==0?e+1:e;i<t.length;i+=2)n=f(t,e,i)<<s,this.words[o]|=67108863&n,s>=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;this.strip()},s.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=e)i++;i--,n=n/e|0;for(var s=t.length-r,o=s%i,a=Math.min(s,s-o)+r,f=0,u=r;u<a;u+=i)f=h(t,u,u+i,e),this.imuln(n),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f);if(0!==o){var c=1;for(f=h(t,u,t.length,e),u=0;u<o;u++)c*=e;this.imuln(c),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f)}this.strip()},s.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},s.prototype.clone=function(){var t=new s(null);return this.copy(t),t},s.prototype._expand=function(t){for(;this.length<t;)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(t,e,r){r.negative=e.negative^t.negative;var i=t.length+e.length|0;r.length=i,i=i-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=67108863&o,f=o/67108864|0;r.words[0]=a;for(var h=1;h<i;h++){for(var u=f>>>26,c=67108863&f,d=Math.min(h,e.length-1),l=Math.max(0,h-t.length+1);l<=d;l++){var p=h-l|0;u+=(o=(n=0|t.words[p])*(s=0|e.words[l])+c)/67108864|0,c=67108863&o}r.words[h]=0|c,f=0|u}return 0!==f?r.words[h]=0|f:r.length--,r.strip()}s.prototype.toString=function(t,e){var r;if(t=t||10,e=0|e||1,16===t||"hex"===t){r="";for(var n=0,s=0,o=0;o<this.length;o++){var a=this.words[o],f=(16777215&(a<<n|s)).toString(16);r=0!==(s=a>>>24-n&16777215)||o!==this.length-1?u[6-f.length]+f+r:f+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var h=c[t],l=d[t];r="";var p=this.clone();for(p.negative=0;!p.isZero();){var b=p.modn(l).toString(t);r=(p=p.idivn(l)).isZero()?b+r:u[h-b.length]+b+r}for(this.isZero()&&(r="0"+r);r.length%e!=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 t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(t,e){return i(void 0!==o),this.toArrayLike(o,t,e)},s.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},s.prototype.toArrayLike=function(t,e,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 o,a,f="le"===e,h=new t(s),u=this.clone();if(f){for(a=0;!u.isZero();a++)o=u.andln(255),u.iushrn(8),h[a]=o;for(;a<s;a++)h[a]=0}else{for(a=0;a<s-n;a++)h[a]=0;for(a=0;!u.isZero();a++)o=u.andln(255),u.iushrn(8),h[s-a-1]=o}return h},Math.clz32?s.prototype._countBits=function(t){return 32-Math.clz32(t)}:s.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},s.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},s.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)break}return t},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},s.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).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(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this.strip()},s.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},s.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},s.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},s.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this.strip()},s.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},s.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},s.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},s.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var i=0;i<r.length;i++)this.words[i]=e.words[i]^r.words[i];if(this!==e)for(;i<e.length;i++)this.words[i]=e.words[i];return this.length=e.length,this.strip()},s.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},s.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},s.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},s.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n<e;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(t){return this.clone().inotn(t)},s.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<n:this.words[r]&~(1<<n),this.strip()},s.prototype.iadd=function(t){var e,r,i;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(r=this,i=t):(r=t,i=this);for(var n=0,s=0;s<i.length;s++)e=(0|r.words[s])+(0|i.words[s])+n,this.words[s]=67108863&e,n=e>>>26;for(;0!==n&&s<r.length;s++)e=(0|r.words[s])+n,this.words[s]=67108863&e,n=e>>>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(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},s.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,i,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=t):(r=t,i=this);for(var s=0,o=0;o<i.length;o++)s=(e=(0|r.words[o])-(0|i.words[o])+s)>>26,this.words[o]=67108863&e;for(;0!==s&&o<r.length;o++)s=(e=(0|r.words[o])+s)>>26,this.words[o]=67108863&e;if(0===s&&o<r.length&&r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=Math.max(this.length,o),r!==this&&(this.negative=1),this.strip()},s.prototype.sub=function(t){return this.clone().isub(t)};var p=function(t,e,r){var i,n,s,o=t.words,a=e.words,f=r.words,h=0,u=0|o[0],c=8191&u,d=u>>>13,l=0|o[1],p=8191&l,b=l>>>13,m=0|o[2],y=8191&m,g=m>>>13,v=0|o[3],_=8191&v,w=v>>>13,M=0|o[4],S=8191&M,E=M>>>13,A=0|o[5],k=8191&A,x=A>>>13,I=0|o[6],B=8191&I,R=I>>>13,j=0|o[7],T=8191&j,L=j>>>13,P=0|o[8],C=8191&P,U=P>>>13,O=0|o[9],N=8191&O,D=O>>>13,q=0|a[0],z=8191&q,F=q>>>13,K=0|a[1],H=8191&K,V=K>>>13,W=0|a[2],Z=8191&W,G=W>>>13,X=0|a[3],Y=8191&X,J=X>>>13,$=0|a[4],Q=8191&$,tt=$>>>13,et=0|a[5],rt=8191&et,it=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ft=8191&at,ht=at>>>13,ut=0|a[8],ct=8191&ut,dt=ut>>>13,lt=0|a[9],pt=8191&lt,bt=lt>>>13;r.negative=t.negative^e.negative,r.length=19;var mt=(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)+(mt>>>26)|0,mt&=67108863,i=Math.imul(p,z),n=(n=Math.imul(p,F))+Math.imul(b,z)|0,s=Math.imul(b,F);var yt=(h+(i=i+Math.imul(c,H)|0)|0)+((8191&(n=(n=n+Math.imul(c,V)|0)+Math.imul(d,H)|0))<<13)|0;h=((s=s+Math.imul(d,V)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=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,V)|0)+Math.imul(b,H)|0,s=s+Math.imul(b,V)|0;var gt=(h+(i=i+Math.imul(c,Z)|0)|0)+((8191&(n=(n=n+Math.imul(c,G)|0)+Math.imul(d,Z)|0))<<13)|0;h=((s=s+Math.imul(d,G)|0)+(n>>>13)|0)+(gt>>>26)|0,gt&=67108863,i=Math.imul(_,z),n=(n=Math.imul(_,F))+Math.imul(w,z)|0,s=Math.imul(w,F),i=i+Math.imul(y,H)|0,n=(n=n+Math.imul(y,V)|0)+Math.imul(g,H)|0,s=s+Math.imul(g,V)|0,i=i+Math.imul(p,Z)|0,n=(n=n+Math.imul(p,G)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,G)|0;var vt=(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)+(vt>>>26)|0,vt&=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(_,H)|0,n=(n=n+Math.imul(_,V)|0)+Math.imul(w,H)|0,s=s+Math.imul(w,V)|0,i=i+Math.imul(y,Z)|0,n=(n=n+Math.imul(y,G)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,G)|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 _t=(h+(i=i+Math.imul(c,Q)|0)|0)+((8191&(n=(n=n+Math.imul(c,tt)|0)+Math.imul(d,Q)|0))<<13)|0;h=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(k,z),n=(n=Math.imul(k,F))+Math.imul(x,z)|0,s=Math.imul(x,F),i=i+Math.imul(S,H)|0,n=(n=n+Math.imul(S,V)|0)+Math.imul(E,H)|0,s=s+Math.imul(E,V)|0,i=i+Math.imul(_,Z)|0,n=(n=n+Math.imul(_,G)|0)+Math.imul(w,Z)|0,s=s+Math.imul(w,G)|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,tt)|0)+Math.imul(b,Q)|0,s=s+Math.imul(b,tt)|0;var wt=(h+(i=i+Math.imul(c,rt)|0)|0)+((8191&(n=(n=n+Math.imul(c,it)|0)+Math.imul(d,rt)|0))<<13)|0;h=((s=s+Math.imul(d,it)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(B,z),n=(n=Math.imul(B,F))+Math.imul(R,z)|0,s=Math.imul(R,F),i=i+Math.imul(k,H)|0,n=(n=n+Math.imul(k,V)|0)+Math.imul(x,H)|0,s=s+Math.imul(x,V)|0,i=i+Math.imul(S,Z)|0,n=(n=n+Math.imul(S,G)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,G)|0,i=i+Math.imul(_,Y)|0,n=(n=n+Math.imul(_,J)|0)+Math.imul(w,Y)|0,s=s+Math.imul(w,J)|0,i=i+Math.imul(y,Q)|0,n=(n=n+Math.imul(y,tt)|0)+Math.imul(g,Q)|0,s=s+Math.imul(g,tt)|0,i=i+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,it)|0)+Math.imul(b,rt)|0,s=s+Math.imul(b,it)|0;var Mt=(h+(i=i+Math.imul(c,st)|0)|0)+((8191&(n=(n=n+Math.imul(c,ot)|0)+Math.imul(d,st)|0))<<13)|0;h=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(T,z),n=(n=Math.imul(T,F))+Math.imul(L,z)|0,s=Math.imul(L,F),i=i+Math.imul(B,H)|0,n=(n=n+Math.imul(B,V)|0)+Math.imul(R,H)|0,s=s+Math.imul(R,V)|0,i=i+Math.imul(k,Z)|0,n=(n=n+Math.imul(k,G)|0)+Math.imul(x,Z)|0,s=s+Math.imul(x,G)|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(_,Q)|0,n=(n=n+Math.imul(_,tt)|0)+Math.imul(w,Q)|0,s=s+Math.imul(w,tt)|0,i=i+Math.imul(y,rt)|0,n=(n=n+Math.imul(y,it)|0)+Math.imul(g,rt)|0,s=s+Math.imul(g,it)|0,i=i+Math.imul(p,st)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ot)|0;var St=(h+(i=i+Math.imul(c,ft)|0)|0)+((8191&(n=(n=n+Math.imul(c,ht)|0)+Math.imul(d,ft)|0))<<13)|0;h=((s=s+Math.imul(d,ht)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(C,z),n=(n=Math.imul(C,F))+Math.imul(U,z)|0,s=Math.imul(U,F),i=i+Math.imul(T,H)|0,n=(n=n+Math.imul(T,V)|0)+Math.imul(L,H)|0,s=s+Math.imul(L,V)|0,i=i+Math.imul(B,Z)|0,n=(n=n+Math.imul(B,G)|0)+Math.imul(R,Z)|0,s=s+Math.imul(R,G)|0,i=i+Math.imul(k,Y)|0,n=(n=n+Math.imul(k,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,tt)|0)+Math.imul(E,Q)|0,s=s+Math.imul(E,tt)|0,i=i+Math.imul(_,rt)|0,n=(n=n+Math.imul(_,it)|0)+Math.imul(w,rt)|0,s=s+Math.imul(w,it)|0,i=i+Math.imul(y,st)|0,n=(n=n+Math.imul(y,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0,i=i+Math.imul(p,ft)|0,n=(n=n+Math.imul(p,ht)|0)+Math.imul(b,ft)|0,s=s+Math.imul(b,ht)|0;var Et=(h+(i=i+Ma