"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var buffer=_interopDefault(require("buffer")),stream=_interopDefault(require("stream")),util=_interopDefault(require("util")),crypto=_interopDefault(require("crypto"));function createCommonjsModule(e,r){return e(r={exports:{}},r.exports),r.exports}var safeBuffer=createCommonjsModule((function(e,r){var t=buffer.Buffer;function n(e,r){for(var t in e)r[t]=e[t]}function o(e,r,n){return t(e,r,n)}t.from&&t.alloc&&t.allocUnsafe&&t.allocUnsafeSlow?e.exports=buffer:(n(buffer,r),r.Buffer=o),o.prototype=Object.create(t.prototype),n(t,o),o.from=function(e,r,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return t(e,r,n)},o.alloc=function(e,r,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var o=t(e);return void 0!==r?"string"==typeof n?o.fill(r,n):o.fill(r):o.fill(0),o},o.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return t(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return buffer.SlowBuffer(e)}})),safeBuffer_1=safeBuffer.Buffer,Buffer$1=safeBuffer.Buffer;function DataStream(e){if(this.buffer=null,this.writable=!0,this.readable=!0,!e)return this.buffer=Buffer$1.alloc(0),this;if("function"==typeof e.pipe)return this.buffer=Buffer$1.alloc(0),e.pipe(this),this;if(e.length||"object"==typeof e)return this.buffer=e,this.writable=!1,process.nextTick(function(){this.emit("end",e),this.readable=!1,this.emit("close")}.bind(this)),this;throw new TypeError("Unexpected data type ("+typeof e+")")}util.inherits(DataStream,stream),DataStream.prototype.write=function(e){this.buffer=Buffer$1.concat([this.buffer,Buffer$1.from(e)]),this.emit("data",e)},DataStream.prototype.end=function(e){e&&this.write(e),this.emit("end",e),this.emit("close"),this.writable=!1,this.readable=!1};var dataStream=DataStream,Buffer$2=buffer.Buffer,SlowBuffer=buffer.SlowBuffer,bufferEqualConstantTime=bufferEq;function bufferEq(e,r){if(!Buffer$2.isBuffer(e)||!Buffer$2.isBuffer(r))return!1;if(e.length!==r.length)return!1;for(var t=0,n=0;n=MAX_OCTET&&--n,n}function joseToDer(e,r){e=signatureAsBuffer(e);var t=paramBytesForAlg_1(r),n=e.length;if(n!==2*t)throw new TypeError('"'+r+'" signatures must be "'+2*t+'" bytes, saw "'+n+'"');var o=countPadding(e,0,t),i=countPadding(e,t,e.length),s=t-o,a=t-i,u=2+s+1+1+a,c=u0)return parse(e);if("number"===t&&isFinite(e))return r.long?fmtLong(e):fmtShort(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function parse(e){if(!((e=String(e)).length>100)){var r=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(r){var t=parseFloat(r[1]);switch((r[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return t*y;case"weeks":case"week":case"w":return t*w;case"days":case"day":case"d":return t*d;case"hours":case"hour":case"hrs":case"hr":case"h":return t*h;case"minutes":case"minute":case"mins":case"min":case"m":return t*m;case"seconds":case"second":case"secs":case"sec":case"s":return t*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function fmtShort(e){var r=Math.abs(e);return r>=d?Math.round(e/d)+"d":r>=h?Math.round(e/h)+"h":r>=m?Math.round(e/m)+"m":r>=s?Math.round(e/s)+"s":e+"ms"}function fmtLong(e){var r=Math.abs(e);return r>=d?plural(e,r,d,"day"):r>=h?plural(e,r,h,"hour"):r>=m?plural(e,r,m,"minute"):r>=s?plural(e,r,s,"second"):e+" ms"}function plural(e,r,t,n){var o=r>=1.5*t;return Math.round(e/t)+" "+n+(o?"s":"")}var timespan=function(e,r){var t=r||Math.floor(Date.now()/1e3);if("string"==typeof e){var n=ms(e);if(void 0===n)return;return Math.floor(t+n/1e3)}return"number"==typeof e?t+e:void 0},semver=createCommonjsModule((function(e,r){var t;r=e.exports=Y,t="object"==typeof process&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?function(){var e=Array.prototype.slice.call(arguments,0);e.unshift("SEMVER"),console.log.apply(console,e)}:function(){},r.SEMVER_SPEC_VERSION="2.0.0";var n=Number.MAX_SAFE_INTEGER||9007199254740991,o=r.re=[],i=r.safeRe=[],s=r.src=[],a=0,u=[["\\s",1],["\\d",256],["[a-zA-Z0-9-]",250]];function c(e){for(var r=0;r)?=?)";var I=a++;s[I]=s[l]+"|x|X|\\*";var $=a++;s[$]=s[f]+"|x|X|\\*";var A=a++;s[A]="[v=\\s]*("+s[$]+")(?:\\.("+s[$]+")(?:\\.("+s[$]+")(?:"+s[g]+")?"+s[S]+"?)?)?";var N=a++;s[N]="[v=\\s]*("+s[I]+")(?:\\.("+s[I]+")(?:\\.("+s[I]+")(?:"+s[y]+")?"+s[S]+"?)?)?";var B=a++;s[B]="^"+s[T]+"\\s*"+s[A]+"$";var O=a++;s[O]="^"+s[T]+"\\s*"+s[N]+"$";var k=a++;s[k]="(?:^|[^\\d])(\\d{1,16})(?:\\.(\\d{1,16}))?(?:\\.(\\d{1,16}))?(?:$|[^\\d])";var P=a++;s[P]="(?:~>?)";var R=a++;s[R]="(\\s*)"+s[P]+"\\s+",o[R]=new RegExp(s[R],"g"),i[R]=new RegExp(c(s[R]),"g");var x=a++;s[x]="^"+s[P]+s[A]+"$";var V=a++;s[V]="^"+s[P]+s[N]+"$";var L=a++;s[L]="(?:\\^)";var D=a++;s[D]="(\\s*)"+s[L]+"\\s+",o[D]=new RegExp(s[D],"g"),i[D]=new RegExp(c(s[D]),"g");var G=a++;s[G]="^"+s[L]+s[A]+"$";var M=a++;s[M]="^"+s[L]+s[N]+"$";var J=a++;s[J]="^"+s[T]+"\\s*("+_+")$|^$";var F=a++;s[F]="^"+s[T]+"\\s*("+w+")$|^$";var K=a++;s[K]="(\\s*)"+s[T]+"\\s*("+_+"|"+s[A]+")",o[K]=new RegExp(s[K],"g"),i[K]=new RegExp(c(s[K]),"g");var C=a++;s[C]="^\\s*("+s[A]+")\\s+-\\s+("+s[A]+")\\s*$";var W=a++;s[W]="^\\s*("+s[N]+")\\s+-\\s+("+s[N]+")\\s*$";var H=a++;s[H]="(<|>)?=?\\s*\\*";for(var q=0;q<35;q++)t(q,s[q]),o[q]||(o[q]=new RegExp(s[q]),i[q]=new RegExp(c(s[q])));function U(e,r){if(r&&"object"==typeof r||(r={loose:!!r,includePrerelease:!1}),e instanceof Y)return e;if("string"!=typeof e)return null;if(e.length>256)return null;if(!(r.loose?i[j]:i[E]).test(e))return null;try{return new Y(e,r)}catch(e){return null}}function Y(e,r){if(r&&"object"==typeof r||(r={loose:!!r,includePrerelease:!1}),e instanceof Y){if(e.loose===r.loose)return e;e=e.version}else if("string"!=typeof e)throw new TypeError("Invalid Version: "+e);if(e.length>256)throw new TypeError("version is longer than 256 characters");if(!(this instanceof Y))return new Y(e,r);t("SemVer",e,r),this.options=r,this.loose=!!r.loose;var o=e.trim().match(r.loose?i[j]:i[E]);if(!o)throw new TypeError("Invalid Version: "+e);if(this.raw=e,this.major=+o[1],this.minor=+o[2],this.patch=+o[3],this.major>n||this.major<0)throw new TypeError("Invalid major version");if(this.minor>n||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>n||this.patch<0)throw new TypeError("Invalid patch version");o[4]?this.prerelease=o[4].split(".").map((function(e){if(/^[0-9]+$/.test(e)){var r=+e;if(r>=0&&r=0;)"number"==typeof this.prerelease[t]&&(this.prerelease[t]++,t=-2);-1===t&&this.prerelease.push(0)}r&&(this.prerelease[0]===r?isNaN(this.prerelease[1])&&(this.prerelease=[r,0]):this.prerelease=[r,0]);break;default:throw new Error("invalid increment argument: "+e)}return this.format(),this.raw=this.version,this},r.inc=function(e,r,t,n){"string"==typeof t&&(n=t,t=void 0);try{return new Y(e,t).inc(r,n).version}catch(e){return null}},r.diff=function(e,r){if(re(e,r))return null;var t=U(e),n=U(r),o="";if(t.prerelease.length||n.prerelease.length){o="pre";var i="prerelease"}for(var s in t)if(("major"===s||"minor"===s||"patch"===s)&&t[s]!==n[s])return o+s;return i},r.compareIdentifiers=z;var X=/^[0-9]+$/;function z(e,r){var t=X.test(e),n=X.test(r);return t&&n&&(e=+e,r=+r),e===r?0:t&&!n?-1:n&&!t?1:e0}function ee(e,r,t){return Z(e,r,t)<0}function re(e,r,t){return 0===Z(e,r,t)}function te(e,r,t){return 0!==Z(e,r,t)}function ne(e,r,t){return Z(e,r,t)>=0}function oe(e,r,t){return Z(e,r,t)<=0}function ie(e,r,t,n){switch(r){case"===":return"object"==typeof e&&(e=e.version),"object"==typeof t&&(t=t.version),e===t;case"!==":return"object"==typeof e&&(e=e.version),"object"==typeof t&&(t=t.version),e!==t;case"":case"=":case"==":return re(e,t,n);case"!=":return te(e,t,n);case">":return Q(e,t,n);case">=":return ne(e,t,n);case"<":return ee(e,t,n);case"<=":return oe(e,t,n);default:throw new TypeError("Invalid operator: "+r)}}function se(e,r){if(r&&"object"==typeof r||(r={loose:!!r,includePrerelease:!1}),e instanceof se){if(e.loose===!!r.loose)return e;e=e.value}if(!(this instanceof se))return new se(e,r);e=e.trim().split(/\s+/).join(" "),t("comparator",e,r),this.options=r,this.loose=!!r.loose,this.parse(e),this.semver===ae?this.value="":this.value=this.operator+this.semver.version,t("comp",this)}r.rcompareIdentifiers=function(e,r){return z(r,e)},r.major=function(e,r){return new Y(e,r).major},r.minor=function(e,r){return new Y(e,r).minor},r.patch=function(e,r){return new Y(e,r).patch},r.compare=Z,r.compareLoose=function(e,r){return Z(e,r,!0)},r.rcompare=function(e,r,t){return Z(r,e,t)},r.sort=function(e,t){return e.sort((function(e,n){return r.compare(e,n,t)}))},r.rsort=function(e,t){return e.sort((function(e,n){return r.rcompare(e,n,t)}))},r.gt=Q,r.lt=ee,r.eq=re,r.neq=te,r.gte=ne,r.lte=oe,r.cmp=ie,r.Comparator=se;var ae={};function ue(e,r){if(r&&"object"==typeof r||(r={loose:!!r,includePrerelease:!1}),e instanceof ue)return e.loose===!!r.loose&&e.includePrerelease===!!r.includePrerelease?e:new ue(e.raw,r);if(e instanceof se)return new ue(e.value,r);if(!(this instanceof ue))return new ue(e,r);if(this.options=r,this.loose=!!r.loose,this.includePrerelease=!!r.includePrerelease,this.raw=e.trim().split(/\s+/).join(" "),this.set=this.raw.split("||").map((function(e){return this.parseRange(e.trim())}),this).filter((function(e){return e.length})),!this.set.length)throw new TypeError("Invalid SemVer Range: "+this.raw);this.format()}function ce(e){return!e||"x"===e.toLowerCase()||"*"===e}function fe(e,r,t,n,o,i,s,a,u,c,f,l,p){return((r=ce(t)?"":ce(n)?">="+t+".0.0":ce(o)?">="+t+"."+n+".0":">="+r)+" "+(a=ce(u)?"":ce(c)?"<"+(+u+1)+".0.0":ce(f)?"<"+u+"."+(+c+1)+".0":l?"<="+u+"."+c+"."+f+"-"+l:"<="+a)).trim()}function le(e,r,n){for(var o=0;o0){var i=e[o].semver;if(i.major===r.major&&i.minor===r.minor&&i.patch===r.patch)return!0}return!1}return!0}function pe(e,r,t){try{r=new ue(r,t)}catch(e){return!1}return r.test(e)}function me(e,r,t,n){var o,i,s,a,u;switch(e=new Y(e,n),r=new ue(r,n),t){case">":o=Q,i=oe,s=ee,a=">",u=">=";break;case"<":o=ee,i=ne,s=Q,a="<",u="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(pe(e,r,n))return!1;for(var c=0;c=0.0.0")),l=l||e,p=p||e,o(e.semver,l.semver,n)?l=e:s(e.semver,p.semver,n)&&(p=e)})),l.operator===a||l.operator===u)return!1;if((!p.operator||p.operator===a)&&i(e,p.semver))return!1;if(p.operator===u&&s(e,p.semver))return!1}return!0}se.prototype.parse=function(e){var r=this.options.loose?i[J]:i[F],t=e.match(r);if(!t)throw new TypeError("Invalid comparator: "+e);this.operator=t[1],"="===this.operator&&(this.operator=""),t[2]?this.semver=new Y(t[2],this.options.loose):this.semver=ae},se.prototype.toString=function(){return this.value},se.prototype.test=function(e){return t("Comparator.test",e,this.options.loose),this.semver===ae||("string"==typeof e&&(e=new Y(e,this.options)),ie(e,this.operator,this.semver,this.options))},se.prototype.intersects=function(e,r){if(!(e instanceof se))throw new TypeError("a Comparator is required");var t;if(r&&"object"==typeof r||(r={loose:!!r,includePrerelease:!1}),""===this.operator)return t=new ue(e.value,r),pe(this.value,t,r);if(""===e.operator)return t=new ue(this.value,r),pe(e.semver,t,r);var n=!(">="!==this.operator&&">"!==this.operator||">="!==e.operator&&">"!==e.operator),o=!("<="!==this.operator&&"<"!==this.operator||"<="!==e.operator&&"<"!==e.operator),i=this.semver.version===e.semver.version,s=!(">="!==this.operator&&"<="!==this.operator||">="!==e.operator&&"<="!==e.operator),a=ie(this.semver,"<",e.semver,r)&&(">="===this.operator||">"===this.operator)&&("<="===e.operator||"<"===e.operator),u=ie(this.semver,">",e.semver,r)&&("<="===this.operator||"<"===this.operator)&&(">="===e.operator||">"===e.operator);return n||o||i&&s||a||u},r.Range=ue,ue.prototype.format=function(){return this.range=this.set.map((function(e){return e.join(" ").trim()})).join("||").trim(),this.range},ue.prototype.toString=function(){return this.range},ue.prototype.parseRange=function(e){var r=this.options.loose,n=r?i[W]:i[C];e=e.replace(n,fe),t("hyphen replace",e),e=e.replace(i[K],"$1$2$3"),t("comparator trim",e,i[K]),e=(e=e.replace(i[R],"$1~")).replace(i[D],"$1^");var o=r?i[J]:i[F],s=e.split(" ").map((function(e){return function(e,r){return t("comp",e,r),e=function(e,r){return e.trim().split(/\s+/).map((function(e){return function(e,r){t("caret",e,r);var n=r.loose?i[M]:i[G];return e.replace(n,(function(r,n,o,i,s){var a;return t("caret",e,r,n,o,i,s),ce(n)?a="":ce(o)?a=">="+n+".0.0 <"+(+n+1)+".0.0":ce(i)?a="0"===n?">="+n+"."+o+".0 <"+n+"."+(+o+1)+".0":">="+n+"."+o+".0 <"+(+n+1)+".0.0":s?(t("replaceCaret pr",s),a="0"===n?"0"===o?">="+n+"."+o+"."+i+"-"+s+" <"+n+"."+o+"."+(+i+1):">="+n+"."+o+"."+i+"-"+s+" <"+n+"."+(+o+1)+".0":">="+n+"."+o+"."+i+"-"+s+" <"+(+n+1)+".0.0"):(t("no pr"),a="0"===n?"0"===o?">="+n+"."+o+"."+i+" <"+n+"."+o+"."+(+i+1):">="+n+"."+o+"."+i+" <"+n+"."+(+o+1)+".0":">="+n+"."+o+"."+i+" <"+(+n+1)+".0.0"),t("caret return",a),a}))}(e,r)})).join(" ")}(e,r),t("caret",e),e=function(e,r){return e.trim().split(/\s+/).map((function(e){return function(e,r){var n=r.loose?i[V]:i[x];return e.replace(n,(function(r,n,o,i,s){var a;return t("tilde",e,r,n,o,i,s),ce(n)?a="":ce(o)?a=">="+n+".0.0 <"+(+n+1)+".0.0":ce(i)?a=">="+n+"."+o+".0 <"+n+"."+(+o+1)+".0":s?(t("replaceTilde pr",s),a=">="+n+"."+o+"."+i+"-"+s+" <"+n+"."+(+o+1)+".0"):a=">="+n+"."+o+"."+i+" <"+n+"."+(+o+1)+".0",t("tilde return",a),a}))}(e,r)})).join(" ")}(e,r),t("tildes",e),e=function(e,r){return t("replaceXRanges",e,r),e.split(/\s+/).map((function(e){return function(e,r){e=e.trim();var n=r.loose?i[O]:i[B];return e.replace(n,(function(r,n,o,i,s,a){t("xRange",e,r,n,o,i,s,a);var u=ce(o),c=u||ce(i),f=c||ce(s);return"="===n&&f&&(n=""),u?r=">"===n||"<"===n?"<0.0.0":"*":n&&f?(c&&(i=0),s=0,">"===n?(n=">=",c?(o=+o+1,i=0,s=0):(i=+i+1,s=0)):"<="===n&&(n="<",c?o=+o+1:i=+i+1),r=n+o+"."+i+"."+s):c?r=">="+o+".0.0 <"+(+o+1)+".0.0":f&&(r=">="+o+"."+i+".0 <"+o+"."+(+i+1)+".0"),t("xRange return",r),r}))}(e,r)})).join(" ")}(e,r),t("xrange",e),e=function(e,r){return t("replaceStars",e,r),e.trim().replace(i[H],"")}(e,r),t("stars",e),e}(e,this.options)}),this).join(" ").split(/\s+/);return this.options.loose&&(s=s.filter((function(e){return!!e.match(o)}))),s=s.map((function(e){return new se(e,this.options)}),this)},ue.prototype.intersects=function(e,r){if(!(e instanceof ue))throw new TypeError("a Range is required");return this.set.some((function(t){return t.every((function(t){return e.set.some((function(e){return e.every((function(e){return t.intersects(e,r)}))}))}))}))},r.toComparators=function(e,r){return new ue(e,r).set.map((function(e){return e.map((function(e){return e.value})).join(" ").trim().split(" ")}))},ue.prototype.test=function(e){if(!e)return!1;"string"==typeof e&&(e=new Y(e,this.options));for(var r=0;r":0===r.prerelease.length?r.patch++:r.prerelease.push(0),r.raw=r.format();case"":case">=":t&&!Q(t,r)||(t=r);break;case"<":case"<=":break;default:throw new Error("Unexpected operation: "+e.operator)}}))}if(t&&e.test(t))return t;return null},r.validRange=function(e,r){try{return new ue(e,r).range||"*"}catch(e){return null}},r.ltr=function(e,r,t){return me(e,r,"<",t)},r.gtr=function(e,r,t){return me(e,r,">",t)},r.outside=me,r.prerelease=function(e,r){var t=U(e,r);return t&&t.prerelease.length?t.prerelease:null},r.intersects=function(e,r,t){return e=new ue(e,t),r=new ue(r,t),e.intersects(r)},r.coerce=function(e){if(e instanceof Y)return e;if("string"!=typeof e)return null;var r=e.match(i[k]);if(null==r)return null;return U(r[1]+"."+(r[2]||"0")+"."+(r[3]||"0"))}})),semver_1=semver.SEMVER_SPEC_VERSION,semver_2=semver.re,semver_3=semver.safeRe,semver_4=semver.src,semver_5=semver.parse,semver_6=semver.valid,semver_7=semver.clean,semver_8=semver.SemVer,semver_9=semver.inc,semver_10=semver.diff,semver_11=semver.compareIdentifiers,semver_12=semver.rcompareIdentifiers,semver_13=semver.major,semver_14=semver.minor,semver_15=semver.patch,semver_16=semver.compare,semver_17=semver.compareLoose,semver_18=semver.rcompare,semver_19=semver.sort,semver_20=semver.rsort,semver_21=semver.gt,semver_22=semver.lt,semver_23=semver.eq,semver_24=semver.neq,semver_25=semver.gte,semver_26=semver.lte,semver_27=semver.cmp,semver_28=semver.Comparator,semver_29=semver.Range,semver_30=semver.toComparators,semver_31=semver.satisfies,semver_32=semver.maxSatisfying,semver_33=semver.minSatisfying,semver_34=semver.minVersion,semver_35=semver.validRange,semver_36=semver.ltr,semver_37=semver.gtr,semver_38=semver.outside,semver_39=semver.prerelease,semver_40=semver.intersects,semver_41=semver.coerce,psSupported=semver.satisfies(process.version,"^6.12.0 || >=8.0.0"),PUB_KEY_ALGS=["RS256","RS384","RS512","ES256","ES384","ES512"],RSA_KEY_ALGS=["RS256","RS384","RS512"],HS_ALGS=["HS256","HS384","HS512"];psSupported&&(PUB_KEY_ALGS.splice(3,0,"PS256","PS384","PS512"),RSA_KEY_ALGS.splice(3,0,"PS256","PS384","PS512"));var verify$1=function(e,r,t,n){var o;if("function"!=typeof t||n||(n=t,t={}),t||(t={}),t=Object.assign({},t),o=n||function(e,r){if(e)throw e;return r},t.clockTimestamp&&"number"!=typeof t.clockTimestamp)return o(new JsonWebTokenError_1("clockTimestamp must be a number"));if(void 0!==t.nonce&&("string"!=typeof t.nonce||""===t.nonce.trim()))return o(new JsonWebTokenError_1("nonce must be a non-empty string"));var i=t.clockTimestamp||Math.floor(Date.now()/1e3);if(!e)return o(new JsonWebTokenError_1("jwt must be provided"));if("string"!=typeof e)return o(new JsonWebTokenError_1("jwt must be a string"));var s,a=e.split(".");if(3!==a.length)return o(new JsonWebTokenError_1("jwt malformed"));try{s=decode$1(e,{complete:!0})}catch(e){return o(e)}if(!s)return o(new JsonWebTokenError_1("invalid token"));var u,c=s.header;if("function"==typeof r){if(!n)return o(new JsonWebTokenError_1("verify must be called asynchronous if secret or public key is provided as a callback"));u=r}else u=function(e,t){return t(null,r)};return u(c,(function(r,n){if(r)return o(new JsonWebTokenError_1("error in secret or public key callback: "+r.message));var u,f=""!==a[2].trim();if(!f&&n)return o(new JsonWebTokenError_1("jwt signature is required"));if(f&&!n)return o(new JsonWebTokenError_1("secret or public key must be provided"));if(f||t.algorithms||(t.algorithms=["none"]),t.algorithms||(t.algorithms=~n.toString().indexOf("BEGIN CERTIFICATE")||~n.toString().indexOf("BEGIN PUBLIC KEY")?PUB_KEY_ALGS:~n.toString().indexOf("BEGIN RSA PUBLIC KEY")?RSA_KEY_ALGS:HS_ALGS),!~t.algorithms.indexOf(s.header.alg))return o(new JsonWebTokenError_1("invalid algorithm"));try{u=jws.verify(e,s.header.alg,n)}catch(e){return o(e)}if(!u)return o(new JsonWebTokenError_1("invalid signature"));var l=s.payload;if(void 0!==l.nbf&&!t.ignoreNotBefore){if("number"!=typeof l.nbf)return o(new JsonWebTokenError_1("invalid nbf value"));if(l.nbf>i+(t.clockTolerance||0))return o(new NotBeforeError_1("jwt not active",new Date(1e3*l.nbf)))}if(void 0!==l.exp&&!t.ignoreExpiration){if("number"!=typeof l.exp)return o(new JsonWebTokenError_1("invalid exp value"));if(i>=l.exp+(t.clockTolerance||0))return o(new TokenExpiredError_1("jwt expired",new Date(1e3*l.exp)))}if(t.audience){var p=Array.isArray(t.audience)?t.audience:[t.audience];if(!(Array.isArray(l.aud)?l.aud:[l.aud]).some((function(e){return p.some((function(r){return r instanceof RegExp?r.test(e):r===e}))})))return o(new JsonWebTokenError_1("jwt audience invalid. expected: "+p.join(" or ")))}if(t.issuer&&("string"==typeof t.issuer&&l.iss!==t.issuer||Array.isArray(t.issuer)&&-1===t.issuer.indexOf(l.iss)))return o(new JsonWebTokenError_1("jwt issuer invalid. expected: "+t.issuer));if(t.subject&&l.sub!==t.subject)return o(new JsonWebTokenError_1("jwt subject invalid. expected: "+t.subject));if(t.jwtid&&l.jti!==t.jwtid)return o(new JsonWebTokenError_1("jwt jwtid invalid. expected: "+t.jwtid));if(t.nonce&&l.nonce!==t.nonce)return o(new JsonWebTokenError_1("jwt nonce invalid. expected: "+t.nonce));if(t.maxAge){if("number"!=typeof l.iat)return o(new JsonWebTokenError_1("iat required when maxAge is specified"));var m=timespan(t.maxAge,l.iat);if(void 0===m)return o(new JsonWebTokenError_1('"maxAge" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'));if(i>=m+(t.clockTolerance||0))return o(new TokenExpiredError_1("maxAge exceeded",new Date(1e3*m)))}if(!0===t.complete){var h=s.signature;return o(null,{header:c,payload:l,signature:h})}return o(null,l)}))},INFINITY=1/0,MAX_SAFE_INTEGER=9007199254740991,MAX_INTEGER=17976931348623157e292,NAN=NaN,argsTag="[object Arguments]",funcTag="[object Function]",genTag="[object GeneratorFunction]",stringTag="[object String]",symbolTag="[object Symbol]",reTrim=/^\s+|\s+$/g,reIsBadHex=/^[-+]0x[0-9a-f]+$/i,reIsBinary=/^0b[01]+$/i,reIsOctal=/^0o[0-7]+$/i,reIsUint=/^(?:0|[1-9]\d*)$/,freeParseInt=parseInt;function arrayMap(e,r){for(var t=-1,n=e?e.length:0,o=Array(n);++t-1&&e%1==0&&e-1:!!o&&baseIndexOf(e,r,t)>-1}function isArguments(e){return isArrayLikeObject(e)&&hasOwnProperty.call(e,"callee")&&(!propertyIsEnumerable.call(e,"callee")||objectToString.call(e)==argsTag)}var isArray=Array.isArray;function isArrayLike(e){return null!=e&&isLength(e.length)&&!isFunction(e)}function isArrayLikeObject(e){return isObjectLike(e)&&isArrayLike(e)}function isFunction(e){var r=isObject$1(e)?objectToString.call(e):"";return r==funcTag||r==genTag}function isLength(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=MAX_SAFE_INTEGER}function isObject$1(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}function isObjectLike(e){return!!e&&"object"==typeof e}function isString(e){return"string"==typeof e||!isArray(e)&&isObjectLike(e)&&objectToString.call(e)==stringTag}function isSymbol(e){return"symbol"==typeof e||isObjectLike(e)&&objectToString.call(e)==symbolTag}function toFinite(e){return e?(e=toNumber(e))===INFINITY||e===-INFINITY?(e<0?-1:1)*MAX_INTEGER:e==e?e:0:0===e?e:0}function toInteger(e){var r=toFinite(e),t=r%1;return r==r?t?r-t:r:0}function toNumber(e){if("number"==typeof e)return e;if(isSymbol(e))return NAN;if(isObject$1(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=isObject$1(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(reTrim,"");var t=reIsBinary.test(e);return t||reIsOctal.test(e)?freeParseInt(e.slice(2),t?2:8):reIsBadHex.test(e)?NAN:+e}function keys(e){return isArrayLike(e)?arrayLikeKeys(e):baseKeys(e)}function values(e){return e?baseValues(e,keys(e)):[]}var lodash_includes=includes,boolTag="[object Boolean]",objectProto$1=Object.prototype,objectToString$1=objectProto$1.toString;function isBoolean(e){return!0===e||!1===e||isObjectLike$1(e)&&objectToString$1.call(e)==boolTag}function isObjectLike$1(e){return!!e&&"object"==typeof e}var lodash_isboolean=isBoolean,INFINITY$1=1/0,MAX_INTEGER$1=17976931348623157e292,NAN$1=NaN,symbolTag$1="[object Symbol]",reTrim$1=/^\s+|\s+$/g,reIsBadHex$1=/^[-+]0x[0-9a-f]+$/i,reIsBinary$1=/^0b[01]+$/i,reIsOctal$1=/^0o[0-7]+$/i,freeParseInt$1=parseInt,objectProto$2=Object.prototype,objectToString$2=objectProto$2.toString;function isInteger(e){return"number"==typeof e&&e==toInteger$1(e)}function isObject$2(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}function isObjectLike$2(e){return!!e&&"object"==typeof e}function isSymbol$1(e){return"symbol"==typeof e||isObjectLike$2(e)&&objectToString$2.call(e)==symbolTag$1}function toFinite$1(e){return e?(e=toNumber$1(e))===INFINITY$1||e===-INFINITY$1?(e<0?-1:1)*MAX_INTEGER$1:e==e?e:0:0===e?e:0}function toInteger$1(e){var r=toFinite$1(e),t=r%1;return r==r?t?r-t:r:0}function toNumber$1(e){if("number"==typeof e)return e;if(isSymbol$1(e))return NAN$1;if(isObject$2(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=isObject$2(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(reTrim$1,"");var t=reIsBinary$1.test(e);return t||reIsOctal$1.test(e)?freeParseInt$1(e.slice(2),t?2:8):reIsBadHex$1.test(e)?NAN$1:+e}var lodash_isinteger=isInteger,numberTag="[object Number]",objectProto$3=Object.prototype,objectToString$3=objectProto$3.toString;function isObjectLike$3(e){return!!e&&"object"==typeof e}function isNumber(e){return"number"==typeof e||isObjectLike$3(e)&&objectToString$3.call(e)==numberTag}var lodash_isnumber=isNumber,objectTag="[object Object]";function isHostObject(e){var r=!1;if(null!=e&&"function"!=typeof e.toString)try{r=!!(e+"")}catch(e){}return r}function overArg$1(e,r){return function(t){return e(r(t))}}var funcProto=Function.prototype,objectProto$4=Object.prototype,funcToString=funcProto.toString,hasOwnProperty$1=objectProto$4.hasOwnProperty,objectCtorString=funcToString.call(Object),objectToString$4=objectProto$4.toString,getPrototype=overArg$1(Object.getPrototypeOf,Object);function isObjectLike$4(e){return!!e&&"object"==typeof e}function isPlainObject(e){if(!isObjectLike$4(e)||objectToString$4.call(e)!=objectTag||isHostObject(e))return!1;var r=getPrototype(e);if(null===r)return!0;var t=hasOwnProperty$1.call(r,"constructor")&&r.constructor;return"function"==typeof t&&t instanceof t&&funcToString.call(t)==objectCtorString}var lodash_isplainobject=isPlainObject,stringTag$1="[object String]",objectProto$5=Object.prototype,objectToString$5=objectProto$5.toString,isArray$1=Array.isArray;function isObjectLike$5(e){return!!e&&"object"==typeof e}function isString$1(e){return"string"==typeof e||!isArray$1(e)&&isObjectLike$5(e)&&objectToString$5.call(e)==stringTag$1}var lodash_isstring=isString$1,FUNC_ERROR_TEXT="Expected a function",INFINITY$2=1/0,MAX_INTEGER$2=17976931348623157e292,NAN$2=NaN,symbolTag$2="[object Symbol]",reTrim$2=/^\s+|\s+$/g,reIsBadHex$2=/^[-+]0x[0-9a-f]+$/i,reIsBinary$2=/^0b[01]+$/i,reIsOctal$2=/^0o[0-7]+$/i,freeParseInt$2=parseInt,objectProto$6=Object.prototype,objectToString$6=objectProto$6.toString;function before(e,r){var t;if("function"!=typeof r)throw new TypeError(FUNC_ERROR_TEXT);return e=toInteger$2(e),function(){return--e>0&&(t=r.apply(this,arguments)),e<=1&&(r=void 0),t}}function once(e){return before(2,e)}function isObject$3(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}function isObjectLike$6(e){return!!e&&"object"==typeof e}function isSymbol$2(e){return"symbol"==typeof e||isObjectLike$6(e)&&objectToString$6.call(e)==symbolTag$2}function toFinite$2(e){return e?(e=toNumber$2(e))===INFINITY$2||e===-INFINITY$2?(e<0?-1:1)*MAX_INTEGER$2:e==e?e:0:0===e?e:0}function toInteger$2(e){var r=toFinite$2(e),t=r%1;return r==r?t?r-t:r:0}function toNumber$2(e){if("number"==typeof e)return e;if(isSymbol$2(e))return NAN$2;if(isObject$3(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=isObject$3(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(reTrim$2,"");var t=reIsBinary$2.test(e);return t||reIsOctal$2.test(e)?freeParseInt$2(e.slice(2),t?2:8):reIsBadHex$2.test(e)?NAN$2:+e}var lodash_once=once,SUPPORTED_ALGS=["RS256","RS384","RS512","ES256","ES384","ES512","HS256","HS384","HS512","none"];psSupported&&SUPPORTED_ALGS.splice(3,0,"PS256","PS384","PS512");var sign_options_schema={expiresIn:{isValid:function(e){return lodash_isinteger(e)||lodash_isstring(e)&&e},message:'"expiresIn" should be a number of seconds or string representing a timespan'},notBefore:{isValid:function(e){return lodash_isinteger(e)||lodash_isstring(e)&&e},message:'"notBefore" should be a number of seconds or string representing a timespan'},audience:{isValid:function(e){return lodash_isstring(e)||Array.isArray(e)},message:'"audience" must be a string or array'},algorithm:{isValid:lodash_includes.bind(null,SUPPORTED_ALGS),message:'"algorithm" must be a valid string enum value'},header:{isValid:lodash_isplainobject,message:'"header" must be an object'},encoding:{isValid:lodash_isstring,message:'"encoding" must be a string'},issuer:{isValid:lodash_isstring,message:'"issuer" must be a string'},subject:{isValid:lodash_isstring,message:'"subject" must be a string'},jwtid:{isValid:lodash_isstring,message:'"jwtid" must be a string'},noTimestamp:{isValid:lodash_isboolean,message:'"noTimestamp" must be a boolean'},keyid:{isValid:lodash_isstring,message:'"keyid" must be a string'},mutatePayload:{isValid:lodash_isboolean,message:'"mutatePayload" must be a boolean'}},registered_claims_schema={iat:{isValid:lodash_isnumber,message:'"iat" should be a number of seconds'},exp:{isValid:lodash_isnumber,message:'"exp" should be a number of seconds'},nbf:{isValid:lodash_isnumber,message:'"nbf" should be a number of seconds'}};function validate(e,r,t,n){if(!lodash_isplainobject(t))throw new Error('Expected "'+n+'" to be a plain object.');Object.keys(t).forEach((function(o){var i=e[o];if(i){if(!i.isValid(t[o]))throw new Error(i.message)}else if(!r)throw new Error('"'+o+'" is not allowed in "'+n+'"')}))}function validateOptions(e){return validate(sign_options_schema,!1,e,"options")}function validatePayload(e){return validate(registered_claims_schema,!0,e,"payload")}var options_to_payload={audience:"aud",issuer:"iss",subject:"sub",jwtid:"jti"},options_for_objects=["expiresIn","notBefore","noTimestamp","audience","issuer","subject","jwtid"],sign$1=function(e,r,t,n){"function"==typeof t?(n=t,t={}):t=t||{};var o="object"==typeof e&&!Buffer.isBuffer(e),i=Object.assign({alg:t.algorithm||"HS256",typ:o?"JWT":void 0,kid:t.keyid},t.header);function s(e){if(n)return n(e);throw e}if(!r&&"none"!==t.algorithm)return s(new Error("secretOrPrivateKey must have a value"));if(void 0===e)return s(new Error("payload is required"));if(o){try{validatePayload(e)}catch(e){return s(e)}t.mutatePayload||(e=Object.assign({},e))}else{var a=options_for_objects.filter((function(e){return void 0!==t[e]}));if(a.length>0)return s(new Error("invalid "+a.join(",")+" option for "+typeof e+" payload"))}if(void 0!==e.exp&&void 0!==t.expiresIn)return s(new Error('Bad "options.expiresIn" option the payload already has an "exp" property.'));if(void 0!==e.nbf&&void 0!==t.notBefore)return s(new Error('Bad "options.notBefore" option the payload already has an "nbf" property.'));try{validateOptions(t)}catch(e){return s(e)}var u=e.iat||Math.floor(Date.now()/1e3);if(t.noTimestamp?delete e.iat:o&&(e.iat=u),void 0!==t.notBefore){try{e.nbf=timespan(t.notBefore,u)}catch(e){return s(e)}if(void 0===e.nbf)return s(new Error('"notBefore" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'))}if(void 0!==t.expiresIn&&"object"==typeof e){try{e.exp=timespan(t.expiresIn,u)}catch(e){return s(e)}if(void 0===e.exp)return s(new Error('"expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'))}Object.keys(options_to_payload).forEach((function(r){var n=options_to_payload[r];if(void 0!==t[r]){if(void 0!==e[n])return s(new Error('Bad "options.'+r+'" option. The payload already has an "'+n+'" property.'));e[n]=t[r]}}));var c=t.encoding||"utf8";if("function"!=typeof n)return jws.sign({header:i,payload:e,secret:r,encoding:c});n=n&&lodash_once(n),jws.createSign({header:i,privateKey:r,payload:e,encoding:c}).once("error",n).once("done",(function(e){n(null,e)}))},jsonwebtoken={decode:decode$1,verify:verify$1,sign:sign$1,JsonWebTokenError:JsonWebTokenError_1,NotBeforeError:NotBeforeError_1,TokenExpiredError:TokenExpiredError_1},src=jsonwebtoken;module.exports=src;