@danidoble/webserial
Version:
WebSerial API wrapper
15 lines • 153 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("./kernel-9JeWIxgz.cjs");var di="0123456789abcdefghijklmnopqrstuvwxyz";function G(n){return di.charAt(n)}function _i(n,t){return n&t}function St(n,t){return n|t}function le(n,t){return n^t}function fe(n,t){return n&~t}function gi(n){if(n==0)return-1;var t=0;return(n&65535)==0&&(n>>=16,t+=16),(n&255)==0&&(n>>=8,t+=8),(n&15)==0&&(n>>=4,t+=4),(n&3)==0&&(n>>=2,t+=2),(n&1)==0&&++t,t}function mi(n){for(var t=0;n!=0;)n&=n-1,++t;return t}var ht="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ke="=";function yt(n){var t,e,i="";for(t=0;t+3<=n.length;t+=3)e=parseInt(n.substring(t,t+3),16),i+=ht.charAt(e>>6)+ht.charAt(e&63);for(t+1==n.length?(e=parseInt(n.substring(t,t+1),16),i+=ht.charAt(e<<2)):t+2==n.length&&(e=parseInt(n.substring(t,t+2),16),i+=ht.charAt(e>>2)+ht.charAt((e&3)<<4));(i.length&3)>0;)i+=ke;return i}function pe(n){var t="",e,i=0,r=0;for(e=0;e<n.length&&n.charAt(e)!=ke;++e){var s=ht.indexOf(n.charAt(e));s<0||(i==0?(t+=G(s>>2),r=s&3,i=1):i==1?(t+=G(r<<2|s>>4),r=s&15,i=2):i==2?(t+=G(r),t+=G(s>>2),r=s&3,i=3):(t+=G(r<<2|s>>4),t+=G(s&15),i=0))}return i==1&&(t+=G(r<<2)),t}var ct,yi={decode:function(n){var t;if(ct===void 0){var e="0123456789ABCDEF",i=` \f
\r \u2028\u2029`;for(ct={},t=0;t<16;++t)ct[e.charAt(t)]=t;for(e=e.toLowerCase(),t=10;t<16;++t)ct[e.charAt(t)]=t;for(t=0;t<i.length;++t)ct[i.charAt(t)]=-1}var r=[],s=0,a=0;for(t=0;t<n.length;++t){var o=n.charAt(t);if(o=="=")break;if(o=ct[o],o!=-1){if(o===void 0)throw new Error("Illegal character at offset "+t);s|=o,++a>=2?(r[r.length]=s,s=0,a=0):s<<=4}}if(a)throw new Error("Hex encoding incomplete: 4 bits missing");return r}},et,Jt={decode:function(n){var t;if(et===void 0){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=`= \f
\r \u2028\u2029`;for(et=Object.create(null),t=0;t<64;++t)et[e.charAt(t)]=t;for(et["-"]=62,et._=63,t=0;t<i.length;++t)et[i.charAt(t)]=-1}var r=[],s=0,a=0;for(t=0;t<n.length;++t){var o=n.charAt(t);if(o=="=")break;if(o=et[o],o!=-1){if(o===void 0)throw new Error("Illegal character at offset "+t);s|=o,++a>=4?(r[r.length]=s>>16,r[r.length]=s>>8&255,r[r.length]=s&255,s=0,a=0):s<<=6}}switch(a){case 1:throw new Error("Base64 encoding incomplete: at least 2 bits missing");case 2:r[r.length]=s>>10;break;case 3:r[r.length]=s>>16,r[r.length]=s>>8&255;break}return r},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(n){var t=Jt.re.exec(n);if(t)if(t[1])n=t[1];else if(t[2])n=t[2];else throw new Error("RegExp out of sync");return Jt.decode(n)}},ut=1e13,mt=function(){function n(t){this.buf=[+t||0]}return n.prototype.mulAdd=function(t,e){var i=this.buf,r=i.length,s,a;for(s=0;s<r;++s)a=i[s]*t+e,a<ut?e=0:(e=0|a/ut,a-=e*ut),i[s]=a;e>0&&(i[s]=e)},n.prototype.sub=function(t){var e=this.buf,i=e.length,r,s;for(r=0;r<i;++r)s=e[r]-t,s<0?(s+=ut,t=1):t=0,e[r]=s;for(;e[e.length-1]===0;)e.pop()},n.prototype.toString=function(t){if((t||10)!=10)throw new Error("only base 10 is supported");for(var e=this.buf,i=e[e.length-1].toString(),r=e.length-2;r>=0;--r)i+=(ut+e[r]).toString().substring(1);return i},n.prototype.valueOf=function(){for(var t=this.buf,e=0,i=t.length-1;i>=0;--i)e=e*ut+t[i];return e},n.prototype.simplify=function(){var t=this.buf;return t.length==1?t[0]:this},n}(),Fe="…",bi=/^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,Pi=/^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;function lt(n,t){return n.length>t&&(n=n.substring(0,t)+Fe),n}var Ht=function(){function n(t,e){this.hexDigits="0123456789ABCDEF",t instanceof n?(this.enc=t.enc,this.pos=t.pos):(this.enc=t,this.pos=e)}return n.prototype.get=function(t){if(t===void 0&&(t=this.pos++),t>=this.enc.length)throw new Error("Requesting byte offset ".concat(t," on a stream of length ").concat(this.enc.length));return typeof this.enc=="string"?this.enc.charCodeAt(t):this.enc[t]},n.prototype.hexByte=function(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(t&15)},n.prototype.hexDump=function(t,e,i){for(var r="",s=t;s<e;++s)if(r+=this.hexByte(this.get(s)),i!==!0)switch(s&15){case 7:r+=" ";break;case 15:r+=`
`;break;default:r+=" "}return r},n.prototype.isASCII=function(t,e){for(var i=t;i<e;++i){var r=this.get(i);if(r<32||r>176)return!1}return!0},n.prototype.parseStringISO=function(t,e){for(var i="",r=t;r<e;++r)i+=String.fromCharCode(this.get(r));return i},n.prototype.parseStringUTF=function(t,e){for(var i="",r=t;r<e;){var s=this.get(r++);s<128?i+=String.fromCharCode(s):s>191&&s<224?i+=String.fromCharCode((s&31)<<6|this.get(r++)&63):i+=String.fromCharCode((s&15)<<12|(this.get(r++)&63)<<6|this.get(r++)&63)}return i},n.prototype.parseStringBMP=function(t,e){for(var i="",r,s,a=t;a<e;)r=this.get(a++),s=this.get(a++),i+=String.fromCharCode(r<<8|s);return i},n.prototype.parseTime=function(t,e,i){var r=this.parseStringISO(t,e),s=(i?bi:Pi).exec(r);return s?(i&&(s[1]=+s[1],s[1]+=+s[1]<70?2e3:1900),r=s[1]+"-"+s[2]+"-"+s[3]+" "+s[4],s[5]&&(r+=":"+s[5],s[6]&&(r+=":"+s[6],s[7]&&(r+="."+s[7]))),s[8]&&(r+=" UTC",s[8]!="Z"&&(r+=s[8],s[9]&&(r+=":"+s[9]))),r):"Unrecognized time: "+r},n.prototype.parseInteger=function(t,e){for(var i=this.get(t),r=i>127,s=r?255:0,a,o="";i==s&&++t<e;)i=this.get(t);if(a=e-t,a===0)return r?-1:0;if(a>4){for(o=i,a<<=3;((+o^s)&128)==0;)o=+o<<1,--a;o="("+a+` bit)
`}r&&(i=i-256);for(var c=new mt(i),h=t+1;h<e;++h)c.mulAdd(256,this.get(h));return o+c.toString()},n.prototype.parseBitString=function(t,e,i){for(var r=this.get(t),s=(e-t-1<<3)-r,a="("+s+` bit)
`,o="",c=t+1;c<e;++c){for(var h=this.get(c),u=c==e-1?r:0,f=7;f>=u;--f)o+=h>>f&1?"1":"0";if(o.length>i)return a+lt(o,i)}return a+o},n.prototype.parseOctetString=function(t,e,i){if(this.isASCII(t,e))return lt(this.parseStringISO(t,e),i);var r=e-t,s="("+r+` byte)
`;i/=2,r>i&&(e=t+i);for(var a=t;a<e;++a)s+=this.hexByte(this.get(a));return r>i&&(s+=Fe),s},n.prototype.parseOID=function(t,e,i){for(var r="",s=new mt,a=0,o=t;o<e;++o){var c=this.get(o);if(s.mulAdd(128,c&127),a+=7,!(c&128)){if(r==="")if(s=s.simplify(),s instanceof mt)s.sub(80),r="2."+s.toString();else{var h=s<80?s<40?0:1:2;r=h+"."+(s-h*40)}else r+="."+s.toString();if(r.length>i)return lt(r,i);s=new mt,a=0}}return a>0&&(r+=".incomplete"),r},n}(),vi=function(){function n(t,e,i,r,s){if(!(r instanceof de))throw new Error("Invalid tag value.");this.stream=t,this.header=e,this.length=i,this.tag=r,this.sub=s}return n.prototype.typeName=function(){switch(this.tag.tagClass){case 0:switch(this.tag.tagNumber){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString"}return"Universal_"+this.tag.tagNumber.toString();case 1:return"Application_"+this.tag.tagNumber.toString();case 2:return"["+this.tag.tagNumber.toString()+"]";case 3:return"Private_"+this.tag.tagNumber.toString()}},n.prototype.content=function(t){if(this.tag===void 0)return null;t===void 0&&(t=1/0);var e=this.posContent(),i=Math.abs(this.length);if(!this.tag.isUniversal())return this.sub!==null?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+i,t);switch(this.tag.tagNumber){case 1:return this.stream.get(e)===0?"false":"true";case 2:return this.stream.parseInteger(e,e+i);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(e,e+i,t);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+i,t);case 6:return this.stream.parseOID(e,e+i,t);case 16:case 17:return this.sub!==null?"("+this.sub.length+" elem)":"(no elem)";case 12:return lt(this.stream.parseStringUTF(e,e+i),t);case 18:case 19:case 20:case 21:case 22:case 26:return lt(this.stream.parseStringISO(e,e+i),t);case 30:return lt(this.stream.parseStringBMP(e,e+i),t);case 23:case 24:return this.stream.parseTime(e,e+i,this.tag.tagNumber==23)}return null},n.prototype.toString=function(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(this.sub===null?"null":this.sub.length)+"]"},n.prototype.toPrettyString=function(t){t===void 0&&(t="");var e=t+this.typeName()+" @"+this.stream.pos;if(this.length>=0&&(e+="+"),e+=this.length,this.tag.tagConstructed?e+=" (constructed)":this.tag.isUniversal()&&(this.tag.tagNumber==3||this.tag.tagNumber==4)&&this.sub!==null&&(e+=" (encapsulates)"),e+=`
`,this.sub!==null){t+=" ";for(var i=0,r=this.sub.length;i<r;++i)e+=this.sub[i].toPrettyString(t)}return e},n.prototype.posStart=function(){return this.stream.pos},n.prototype.posContent=function(){return this.stream.pos+this.header},n.prototype.posEnd=function(){return this.stream.pos+this.header+Math.abs(this.length)},n.prototype.toHexString=function(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)},n.decodeLength=function(t){var e=t.get(),i=e&127;if(i==e)return i;if(i>6)throw new Error("Length over 48 bits not supported at position "+(t.pos-1));if(i===0)return null;e=0;for(var r=0;r<i;++r)e=e*256+t.get();return e},n.prototype.getHexStringValue=function(){var t=this.toHexString(),e=this.header*2,i=this.length*2;return t.substring(e,e+i)},n.decode=function(t){var e;t instanceof Ht?e=t:e=new Ht(t,0);var i=new Ht(e),r=new de(e),s=n.decodeLength(e),a=e.pos,o=a-i.pos,c=null,h=function(){var f=[];if(s!==null){for(var _=a+s;e.pos<_;)f[f.length]=n.decode(e);if(e.pos!=_)throw new Error("Content size is not correct for container starting at offset "+a)}else try{for(;;){var y=n.decode(e);if(y.tag.isEOC())break;f[f.length]=y}s=a-e.pos}catch(d){throw new Error("Exception while decoding undefined length content: "+d)}return f};if(r.tagConstructed)c=h();else if(r.isUniversal()&&(r.tagNumber==3||r.tagNumber==4))try{if(r.tagNumber==3&&e.get()!=0)throw new Error("BIT STRINGs with unused bits cannot encapsulate.");c=h();for(var u=0;u<c.length;++u)if(c[u].tag.isEOC())throw new Error("EOC is not supposed to be actual content.")}catch{c=null}if(c===null){if(s===null)throw new Error("We can't skip over an invalid tag with undefined length at offset "+a);e.pos=a+Math.abs(s)}return new n(i,o,s,r,c)},n}(),de=function(){function n(t){var e=t.get();if(this.tagClass=e>>6,this.tagConstructed=(e&32)!==0,this.tagNumber=e&31,this.tagNumber==31){var i=new mt;do e=t.get(),i.mulAdd(128,e&127);while(e&128);this.tagNumber=i.simplify()}}return n.prototype.isUniversal=function(){return this.tagClass===0},n.prototype.isEOC=function(){return this.tagClass===0&&this.tagNumber===0},n}(),Y,Ei=0xdeadbeefcafe,_e=(Ei&16777215)==15715070,x=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],wi=(1<<26)/x[x.length-1],P=function(){function n(t,e,i){t!=null&&(typeof t=="number"?this.fromNumber(t,e,i):e==null&&typeof t!="string"?this.fromString(t,256):this.fromString(t,e))}return n.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(t==16)e=4;else if(t==8)e=3;else if(t==2)e=1;else if(t==32)e=5;else if(t==4)e=2;else return this.toRadix(t);var i=(1<<e)-1,r,s=!1,a="",o=this.t,c=this.DB-o*this.DB%e;if(o-- >0)for(c<this.DB&&(r=this[o]>>c)>0&&(s=!0,a=G(r));o>=0;)c<e?(r=(this[o]&(1<<c)-1)<<e-c,r|=this[--o]>>(c+=this.DB-e)):(r=this[o]>>(c-=e)&i,c<=0&&(c+=this.DB,--o)),r>0&&(s=!0),s&&(a+=G(r));return s?a:"0"},n.prototype.negate=function(){var t=E();return n.ZERO.subTo(this,t),t},n.prototype.abs=function(){return this.s<0?this.negate():this},n.prototype.compareTo=function(t){var e=this.s-t.s;if(e!=0)return e;var i=this.t;if(e=i-t.t,e!=0)return this.s<0?-e:e;for(;--i>=0;)if((e=this[i]-t[i])!=0)return e;return 0},n.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+Tt(this[this.t-1]^this.s&this.DM)},n.prototype.mod=function(t){var e=E();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(n.ZERO)>0&&t.subTo(e,e),e},n.prototype.modPowInt=function(t,e){var i;return t<256||e.isEven()?i=new ge(e):i=new me(e),this.exp(t,i)},n.prototype.clone=function(){var t=E();return this.copyTo(t),t},n.prototype.intValue=function(){if(this.s<0){if(this.t==1)return this[0]-this.DV;if(this.t==0)return-1}else{if(this.t==1)return this[0];if(this.t==0)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]},n.prototype.byteValue=function(){return this.t==0?this.s:this[0]<<24>>24},n.prototype.shortValue=function(){return this.t==0?this.s:this[0]<<16>>16},n.prototype.signum=function(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1},n.prototype.toByteArray=function(){var t=this.t,e=[];e[0]=this.s;var i=this.DB-t*this.DB%8,r,s=0;if(t-- >0)for(i<this.DB&&(r=this[t]>>i)!=(this.s&this.DM)>>i&&(e[s++]=r|this.s<<this.DB-i);t>=0;)i<8?(r=(this[t]&(1<<i)-1)<<8-i,r|=this[--t]>>(i+=this.DB-8)):(r=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),(r&128)!=0&&(r|=-256),s==0&&(this.s&128)!=(r&128)&&++s,(s>0||r!=this.s)&&(e[s++]=r);return e},n.prototype.equals=function(t){return this.compareTo(t)==0},n.prototype.min=function(t){return this.compareTo(t)<0?this:t},n.prototype.max=function(t){return this.compareTo(t)>0?this:t},n.prototype.and=function(t){var e=E();return this.bitwiseTo(t,_i,e),e},n.prototype.or=function(t){var e=E();return this.bitwiseTo(t,St,e),e},n.prototype.xor=function(t){var e=E();return this.bitwiseTo(t,le,e),e},n.prototype.andNot=function(t){var e=E();return this.bitwiseTo(t,fe,e),e},n.prototype.not=function(){for(var t=E(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t},n.prototype.shiftLeft=function(t){var e=E();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e},n.prototype.shiftRight=function(t){var e=E();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e},n.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(this[t]!=0)return t*this.DB+gi(this[t]);return this.s<0?this.t*this.DB:-1},n.prototype.bitCount=function(){for(var t=0,e=this.s&this.DM,i=0;i<this.t;++i)t+=mi(this[i]^e);return t},n.prototype.testBit=function(t){var e=Math.floor(t/this.DB);return e>=this.t?this.s!=0:(this[e]&1<<t%this.DB)!=0},n.prototype.setBit=function(t){return this.changeBit(t,St)},n.prototype.clearBit=function(t){return this.changeBit(t,fe)},n.prototype.flipBit=function(t){return this.changeBit(t,le)},n.prototype.add=function(t){var e=E();return this.addTo(t,e),e},n.prototype.subtract=function(t){var e=E();return this.subTo(t,e),e},n.prototype.multiply=function(t){var e=E();return this.multiplyTo(t,e),e},n.prototype.divide=function(t){var e=E();return this.divRemTo(t,e,null),e},n.prototype.remainder=function(t){var e=E();return this.divRemTo(t,null,e),e},n.prototype.divideAndRemainder=function(t){var e=E(),i=E();return this.divRemTo(t,e,i),[e,i]},n.prototype.modPow=function(t,e){var i=t.bitLength(),r,s=Q(1),a;if(i<=0)return s;i<18?r=1:i<48?r=3:i<144?r=4:i<768?r=5:r=6,i<8?a=new ge(e):e.isEven()?a=new Ti(e):a=new me(e);var o=[],c=3,h=r-1,u=(1<<r)-1;if(o[1]=a.convert(this),r>1){var f=E();for(a.sqrTo(o[1],f);c<=u;)o[c]=E(),a.mulTo(f,o[c-2],o[c]),c+=2}var _=t.t-1,y,d=!0,m=E(),g;for(i=Tt(t[_])-1;_>=0;){for(i>=h?y=t[_]>>i-h&u:(y=(t[_]&(1<<i+1)-1)<<h-i,_>0&&(y|=t[_-1]>>this.DB+i-h)),c=r;(y&1)==0;)y>>=1,--c;if((i-=c)<0&&(i+=this.DB,--_),d)o[y].copyTo(s),d=!1;else{for(;c>1;)a.sqrTo(s,m),a.sqrTo(m,s),c-=2;c>0?a.sqrTo(s,m):(g=s,s=m,m=g),a.mulTo(m,o[y],s)}for(;_>=0&&(t[_]&1<<i)==0;)a.sqrTo(s,m),g=s,s=m,m=g,--i<0&&(i=this.DB-1,--_)}return a.revert(s)},n.prototype.modInverse=function(t){var e=t.isEven();if(this.isEven()&&e||t.signum()==0)return n.ZERO;for(var i=t.clone(),r=this.clone(),s=Q(1),a=Q(0),o=Q(0),c=Q(1);i.signum()!=0;){for(;i.isEven();)i.rShiftTo(1,i),e?((!s.isEven()||!a.isEven())&&(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);for(;r.isEven();)r.rShiftTo(1,r),e?((!o.isEven()||!c.isEven())&&(o.addTo(this,o),c.subTo(t,c)),o.rShiftTo(1,o)):c.isEven()||c.subTo(t,c),c.rShiftTo(1,c);i.compareTo(r)>=0?(i.subTo(r,i),e&&s.subTo(o,s),a.subTo(c,a)):(r.subTo(i,r),e&&o.subTo(s,o),c.subTo(a,c))}if(r.compareTo(n.ONE)!=0)return n.ZERO;if(c.compareTo(t)>=0)return c.subtract(t);if(c.signum()<0)c.addTo(t,c);else return c;return c.signum()<0?c.add(t):c},n.prototype.pow=function(t){return this.exp(t,new Si)},n.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var r=e;e=i,i=r}var s=e.getLowestSetBit(),a=i.getLowestSetBit();if(a<0)return e;for(s<a&&(a=s),a>0&&(e.rShiftTo(a,e),i.rShiftTo(a,i));e.signum()>0;)(s=e.getLowestSetBit())>0&&e.rShiftTo(s,e),(s=i.getLowestSetBit())>0&&i.rShiftTo(s,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return a>0&&i.lShiftTo(a,i),i},n.prototype.isProbablePrime=function(t){var e,i=this.abs();if(i.t==1&&i[0]<=x[x.length-1]){for(e=0;e<x.length;++e)if(i[0]==x[e])return!0;return!1}if(i.isEven())return!1;for(e=1;e<x.length;){for(var r=x[e],s=e+1;s<x.length&&r<wi;)r*=x[s++];for(r=i.modInt(r);e<s;)if(r%x[e++]==0)return!1}return i.millerRabin(t)},n.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},n.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},n.prototype.fromString=function(t,e){var i;if(e==16)i=4;else if(e==8)i=3;else if(e==256)i=8;else if(e==2)i=1;else if(e==32)i=5;else if(e==4)i=2;else{this.fromRadix(t,e);return}this.t=0,this.s=0;for(var r=t.length,s=!1,a=0;--r>=0;){var o=i==8?+t[r]&255:be(t,r);if(o<0){t.charAt(r)=="-"&&(s=!0);continue}s=!1,a==0?this[this.t++]=o:a+i>this.DB?(this[this.t-1]|=(o&(1<<this.DB-a)-1)<<a,this[this.t++]=o>>this.DB-a):this[this.t-1]|=o<<a,a+=i,a>=this.DB&&(a-=this.DB)}i==8&&(+t[0]&128)!=0&&(this.s=-1,a>0&&(this[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),s&&n.ZERO.subTo(this,this)},n.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},n.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},n.prototype.drShiftTo=function(t,e){for(var i=t;i<this.t;++i)e[i-t]=this[i];e.t=Math.max(this.t-t,0),e.s=this.s},n.prototype.lShiftTo=function(t,e){for(var i=t%this.DB,r=this.DB-i,s=(1<<r)-1,a=Math.floor(t/this.DB),o=this.s<<i&this.DM,c=this.t-1;c>=0;--c)e[c+a+1]=this[c]>>r|o,o=(this[c]&s)<<i;for(var c=a-1;c>=0;--c)e[c]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},n.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t){e.t=0;return}var r=t%this.DB,s=this.DB-r,a=(1<<r)-1;e[0]=this[i]>>r;for(var o=i+1;o<this.t;++o)e[o-i-1]|=(this[o]&a)<<s,e[o-i]=this[o]>>r;r>0&&(e[this.t-i-1]|=(this.s&a)<<s),e.t=this.t-i,e.clamp()},n.prototype.subTo=function(t,e){for(var i=0,r=0,s=Math.min(t.t,this.t);i<s;)r+=this[i]-t[i],e[i++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;i<this.t;)r+=this[i],e[i++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;i<t.t;)r-=t[i],e[i++]=r&this.DM,r>>=this.DB;r-=t.s}e.s=r<0?-1:0,r<-1?e[i++]=this.DV+r:r>0&&(e[i++]=r),e.t=i,e.clamp()},n.prototype.multiplyTo=function(t,e){var i=this.abs(),r=t.abs(),s=i.t;for(e.t=s+r.t;--s>=0;)e[s]=0;for(s=0;s<r.t;++s)e[s+i.t]=i.am(0,r[s],e,s,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&n.ZERO.subTo(e,e)},n.prototype.squareTo=function(t){for(var e=this.abs(),i=t.t=2*e.t;--i>=0;)t[i]=0;for(i=0;i<e.t-1;++i){var r=e.am(i,e[i],t,2*i,0,1);(t[i+e.t]+=e.am(i+1,2*e[i],t,2*i+1,r,e.t-i-1))>=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},n.prototype.divRemTo=function(t,e,i){var r=t.abs();if(!(r.t<=0)){var s=this.abs();if(s.t<r.t){e?.fromInt(0),i!=null&&this.copyTo(i);return}i==null&&(i=E());var a=E(),o=this.s,c=t.s,h=this.DB-Tt(r[r.t-1]);h>0?(r.lShiftTo(h,a),s.lShiftTo(h,i)):(r.copyTo(a),s.copyTo(i));var u=a.t,f=a[u-1];if(f!=0){var _=f*(1<<this.F1)+(u>1?a[u-2]>>this.F2:0),y=this.FV/_,d=(1<<this.F1)/_,m=1<<this.F2,g=i.t,w=g-u,A=e??E();for(a.dlShiftTo(w,A),i.compareTo(A)>=0&&(i[i.t++]=1,i.subTo(A,i)),n.ONE.dlShiftTo(u,A),A.subTo(a,a);a.t<u;)a[a.t++]=0;for(;--w>=0;){var T=i[--g]==f?this.DM:Math.floor(i[g]*y+(i[g-1]+m)*d);if((i[g]+=a.am(0,T,i,w,0,u))<T)for(a.dlShiftTo(w,A),i.subTo(A,i);i[g]<--T;)i.subTo(A,i)}e!=null&&(i.drShiftTo(u,e),o!=c&&n.ZERO.subTo(e,e)),i.t=u,i.clamp(),h>0&&i.rShiftTo(h,i),o<0&&n.ZERO.subTo(i,i)}}},n.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if((t&1)==0)return 0;var e=t&3;return e=e*(2-(t&15)*e)&15,e=e*(2-(t&255)*e)&255,e=e*(2-((t&65535)*e&65535))&65535,e=e*(2-t*e%this.DV)%this.DV,e>0?this.DV-e:-e},n.prototype.isEven=function(){return(this.t>0?this[0]&1:this.s)==0},n.prototype.exp=function(t,e){if(t>4294967295||t<1)return n.ONE;var i=E(),r=E(),s=e.convert(this),a=Tt(t)-1;for(s.copyTo(i);--a>=0;)if(e.sqrTo(i,r),(t&1<<a)>0)e.mulTo(r,s,i);else{var o=i;i=r,r=o}return e.revert(i)},n.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},n.prototype.toRadix=function(t){if(t==null&&(t=10),this.signum()==0||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),r=Q(i),s=E(),a=E(),o="";for(this.divRemTo(r,s,a);s.signum()>0;)o=(i+a.intValue()).toString(t).substring(1)+o,s.divRemTo(r,s,a);return a.intValue().toString(t)+o},n.prototype.fromRadix=function(t,e){this.fromInt(0),e==null&&(e=10);for(var i=this.chunkSize(e),r=Math.pow(e,i),s=!1,a=0,o=0,c=0;c<t.length;++c){var h=be(t,c);if(h<0){t.charAt(c)=="-"&&this.signum()==0&&(s=!0);continue}o=e*o+h,++a>=i&&(this.dMultiply(r),this.dAddOffset(o,0),a=0,o=0)}a>0&&(this.dMultiply(Math.pow(e,a)),this.dAddOffset(o,0)),s&&n.ZERO.subTo(this,this)},n.prototype.fromNumber=function(t,e,i){if(typeof e=="number")if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(n.ONE.shiftLeft(t-1),St,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(n.ONE.shiftLeft(t-1),this);else{var r=[],s=t&7;r.length=(t>>3)+1,e.nextBytes(r),s>0?r[0]&=(1<<s)-1:r[0]=0,this.fromString(r,256)}},n.prototype.bitwiseTo=function(t,e,i){var r,s,a=Math.min(t.t,this.t);for(r=0;r<a;++r)i[r]=e(this[r],t[r]);if(t.t<this.t){for(s=t.s&this.DM,r=a;r<this.t;++r)i[r]=e(this[r],s);i.t=this.t}else{for(s=this.s&this.DM,r=a;r<t.t;++r)i[r]=e(s,t[r]);i.t=t.t}i.s=e(this.s,t.s),i.clamp()},n.prototype.changeBit=function(t,e){var i=n.ONE.shiftLeft(t);return this.bitwiseTo(i,e,i),i},n.prototype.addTo=function(t,e){for(var i=0,r=0,s=Math.min(t.t,this.t);i<s;)r+=this[i]+t[i],e[i++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r+=t.s;i<this.t;)r+=this[i],e[i++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;i<t.t;)r+=t[i],e[i++]=r&this.DM,r>>=this.DB;r+=t.s}e.s=r<0?-1:0,r>0?e[i++]=r:r<-1&&(e[i++]=this.DV+r),e.t=i,e.clamp()},n.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},n.prototype.dAddOffset=function(t,e){if(t!=0){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},n.prototype.multiplyLowerTo=function(t,e,i){var r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(var s=i.t-this.t;r<s;++r)i[r+this.t]=this.am(0,t[r],i,r,0,this.t);for(var s=Math.min(t.t,e);r<s;++r)this.am(0,t[r],i,r,0,e-r);i.clamp()},n.prototype.multiplyUpperTo=function(t,e,i){--e;var r=i.t=this.t+t.t-e;for(i.s=0;--r>=0;)i[r]=0;for(r=Math.max(e-this.t,0);r<t.t;++r)i[this.t+r-e]=this.am(e-r,t[r],i,0,0,this.t+r-e);i.clamp(),i.drShiftTo(1,i)},n.prototype.modInt=function(t){if(t<=0)return 0;var e=this.DV%t,i=this.s<0?t-1:0;if(this.t>0)if(e==0)i=this[0]%t;else for(var r=this.t-1;r>=0;--r)i=(e*i+this[r])%t;return i},n.prototype.millerRabin=function(t){var e=this.subtract(n.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var r=e.shiftRight(i);t=t+1>>1,t>x.length&&(t=x.length);for(var s=E(),a=0;a<t;++a){s.fromInt(x[Math.floor(Math.random()*x.length)]);var o=s.modPow(r,this);if(o.compareTo(n.ONE)!=0&&o.compareTo(e)!=0){for(var c=1;c++<i&&o.compareTo(e)!=0;)if(o=o.modPowInt(2,this),o.compareTo(n.ONE)==0)return!1;if(o.compareTo(e)!=0)return!1}}return!0},n.prototype.square=function(){var t=E();return this.squareTo(t),t},n.prototype.gcda=function(t,e){var i=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(i.compareTo(r)<0){var s=i;i=r,r=s}var a=i.getLowestSetBit(),o=r.getLowestSetBit();if(o<0){e(i);return}a<o&&(o=a),o>0&&(i.rShiftTo(o,i),r.rShiftTo(o,r));var c=function(){(a=i.getLowestSetBit())>0&&i.rShiftTo(a,i),(a=r.getLowestSetBit())>0&&r.rShiftTo(a,r),i.compareTo(r)>=0?(i.subTo(r,i),i.rShiftTo(1,i)):(r.subTo(i,r),r.rShiftTo(1,r)),i.signum()>0?setTimeout(c,0):(o>0&&r.lShiftTo(o,r),setTimeout(function(){e(r)},0))};setTimeout(c,10)},n.prototype.fromNumberAsync=function(t,e,i,r){if(typeof e=="number")if(t<2)this.fromInt(1);else{this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(n.ONE.shiftLeft(t-1),St,this),this.isEven()&&this.dAddOffset(1,0);var s=this,a=function(){s.dAddOffset(2,0),s.bitLength()>t&&s.subTo(n.ONE.shiftLeft(t-1),s),s.isProbablePrime(e)?setTimeout(function(){r()},0):setTimeout(a,0)};setTimeout(a,0)}else{var o=[],c=t&7;o.length=(t>>3)+1,e.nextBytes(o),c>0?o[0]&=(1<<c)-1:o[0]=0,this.fromString(o,256)}},n}(),Si=function(){function n(){}return n.prototype.convert=function(t){return t},n.prototype.revert=function(t){return t},n.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},n.prototype.sqrTo=function(t,e){t.squareTo(e)},n}(),ge=function(){function n(t){this.m=t}return n.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},n.prototype.revert=function(t){return t},n.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},n.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},n.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},n}(),me=function(){function n(t){this.m=t,this.mp=t.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}return n.prototype.convert=function(t){var e=E();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(P.ZERO)>0&&this.m.subTo(e,e),e},n.prototype.revert=function(t){var e=E();return t.copyTo(e),this.reduce(e),e},n.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var i=t[e]&32767,r=i*this.mpl+((i*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(i=e+this.m.t,t[i]+=this.m.am(0,r,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},n.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},n.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},n}(),Ti=function(){function n(t){this.m=t,this.r2=E(),this.q3=E(),P.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t)}return n.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=E();return t.copyTo(e),this.reduce(e),e},n.prototype.revert=function(t){return t},n.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},n.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},n.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},n}();function E(){return new P(null)}function C(n,t){return new P(n,t)}var ye=typeof navigator<"u";ye&&_e&&navigator.appName=="Microsoft Internet Explorer"?(P.prototype.am=function(t,e,i,r,s,a){for(var o=e&32767,c=e>>15;--a>=0;){var h=this[t]&32767,u=this[t++]>>15,f=c*h+u*o;h=o*h+((f&32767)<<15)+i[r]+(s&1073741823),s=(h>>>30)+(f>>>15)+c*u+(s>>>30),i[r++]=h&1073741823}return s},Y=30):ye&&_e&&navigator.appName!="Netscape"?(P.prototype.am=function(t,e,i,r,s,a){for(;--a>=0;){var o=e*this[t++]+i[r]+s;s=Math.floor(o/67108864),i[r++]=o&67108863}return s},Y=26):(P.prototype.am=function(t,e,i,r,s,a){for(var o=e&16383,c=e>>14;--a>=0;){var h=this[t]&16383,u=this[t++]>>14,f=c*h+u*o;h=o*h+((f&16383)<<14)+i[r]+s,s=(h>>28)+(f>>14)+c*u,i[r++]=h&268435455}return s},Y=28);P.prototype.DB=Y;P.prototype.DM=(1<<Y)-1;P.prototype.DV=1<<Y;var ne=52;P.prototype.FV=Math.pow(2,ne);P.prototype.F1=ne-Y;P.prototype.F2=2*Y-ne;var Lt=[],pt,F;pt=48;for(F=0;F<=9;++F)Lt[pt++]=F;pt=97;for(F=10;F<36;++F)Lt[pt++]=F;pt=65;for(F=10;F<36;++F)Lt[pt++]=F;function be(n,t){var e=Lt[n.charCodeAt(t)];return e??-1}function Q(n){var t=E();return t.fromInt(n),t}function Tt(n){var t=1,e;return(e=n>>>16)!=0&&(n=e,t+=16),(e=n>>8)!=0&&(n=e,t+=8),(e=n>>4)!=0&&(n=e,t+=4),(e=n>>2)!=0&&(n=e,t+=2),(e=n>>1)!=0&&(n=e,t+=1),t}P.ZERO=Q(0);P.ONE=Q(1);var Ai=function(){function n(){this.i=0,this.j=0,this.S=[]}return n.prototype.init=function(t){var e,i,r;for(e=0;e<256;++e)this.S[e]=e;for(i=0,e=0;e<256;++e)i=i+this.S[e]+t[e%t.length]&255,r=this.S[e],this.S[e]=this.S[i],this.S[i]=r;this.i=0,this.j=0},n.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]},n}();function Ci(){return new Ai}var je=256,At,Z=null,j;if(Z==null){Z=[],j=0;var Ct=void 0;if(typeof window<"u"&&self.crypto&&self.crypto.getRandomValues){var Wt=new Uint32Array(256);for(self.crypto.getRandomValues(Wt),Ct=0;Ct<Wt.length;++Ct)Z[j++]=Wt[Ct]&255}var Rt=0,Ot=function(n){if(Rt=Rt||0,Rt>=256||j>=je){self.removeEventListener?self.removeEventListener("mousemove",Ot,!1):self.detachEvent&&self.detachEvent("onmousemove",Ot);return}try{var t=n.x+n.y;Z[j++]=t&255,Rt+=1}catch{}};typeof window<"u"&&(self.addEventListener?self.addEventListener("mousemove",Ot,!1):self.attachEvent&&self.attachEvent("onmousemove",Ot))}function Ri(){if(At==null){for(At=Ci();j<je;){var n=Math.floor(65536*Math.random());Z[j++]=n&255}for(At.init(Z),j=0;j<Z.length;++j)Z[j]=0;j=0}return At.next()}var Vt=function(){function n(){}return n.prototype.nextBytes=function(t){for(var e=0;e<t.length;++e)t[e]=Ri()},n}();function Qt(n){return Di(Mi(Oi(n),n.length*8))}function Pe(n){for(var t="0123456789abcdef",e="",i=0;i<n.length;i++){var r=n.charCodeAt(i);e+=t.charAt(r>>>4&15)+t.charAt(r&15)}return e}function Oi(n){for(var t=Array(n.length>>2),e=0;e<t.length;e++)t[e]=0;for(var e=0;e<n.length*8;e+=8)t[e>>5]|=(n.charCodeAt(e/8)&255)<<24-e%32;return t}function Di(n){for(var t="",e=0;e<n.length*32;e+=8)t+=String.fromCharCode(n[e>>5]>>>24-e%32&255);return t}function X(n,t){return n>>>t|n<<32-t}function qe(n,t){return n>>>t}function Ii(n,t,e){return n&t^~n&e}function Bi(n,t,e){return n&t^n&e^t&e}function Ni(n){return X(n,2)^X(n,13)^X(n,22)}function xi(n){return X(n,6)^X(n,11)^X(n,25)}function Vi(n){return X(n,7)^X(n,18)^qe(n,3)}function Ui(n){return X(n,17)^X(n,19)^qe(n,10)}var Li=new Array(1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998);function Mi(n,t){var e=new Array(1779033703,-1150833019,1013904242,-1521486534,1359893119,-1694144372,528734635,1541459225),i=new Array(64),r,s,a,o,c,h,u,f,_,y,d,m;for(n[t>>5]|=128<<24-t%32,n[(t+64>>9<<4)+15]=t,_=0;_<n.length;_+=16){for(r=e[0],s=e[1],a=e[2],o=e[3],c=e[4],h=e[5],u=e[6],f=e[7],y=0;y<64;y++)y<16?i[y]=n[y+_]:i[y]=I(I(I(Ui(i[y-2]),i[y-7]),Vi(i[y-15])),i[y-16]),d=I(I(I(I(f,xi(c)),Ii(c,h,u)),Li[y]),i[y]),m=I(Ni(r),Bi(r,s,a)),f=u,u=h,h=c,c=I(o,d),o=a,a=s,s=r,r=I(d,m);e[0]=I(r,e[0]),e[1]=I(s,e[1]),e[2]=I(a,e[2]),e[3]=I(o,e[3]),e[4]=I(c,e[4]),e[5]=I(h,e[5]),e[6]=I(u,e[6]),e[7]=I(f,e[7])}return e}function I(n,t){var e=(n&65535)+(t&65535),i=(n>>16)+(t>>16)+(e>>16);return i<<16|e&65535}function ki(n,t){if(t<n.length+22)return console.error("Message too long for RSA"),null;for(var e=t-n.length-6,i="",r=0;r<e;r+=2)i+="ff";var s="0001"+i+"00"+n;return C(s,16)}function Fi(n,t){if(t<n.length+11)return console.error("Message too long for RSA"),null;for(var e=[],i=n.length-1;i>=0&&t>0;){var r=n.charCodeAt(i--);r<128?e[--t]=r:r>127&&r<2048?(e[--t]=r&63|128,e[--t]=r>>6|192):(e[--t]=r&63|128,e[--t]=r>>6&63|128,e[--t]=r>>12|224)}e[--t]=0;for(var s=new Vt,a=[];t>2;){for(a[0]=0;a[0]==0;)s.nextBytes(a);e[--t]=a[0]}return e[--t]=2,e[--t]=0,new P(e)}function ve(n,t,e){for(var i="",r=0;i.length<t;)i+=e(String.fromCharCode.apply(String,n.concat([(r&4278190080)>>24,(r&16711680)>>16,(r&65280)>>8,r&255]))),r+=1;return i}var ji=32;function qi(n,t){var e=ji,i=Qt;if(n.length+2*e+2>t)throw"Message too long for RSA";var r="",s;for(s=0;s<t-n.length-2*e-2;s+=1)r+="\0";var a=i("")+r+""+n,o=new Array(e);new Vt().nextBytes(o);var c=ve(o,a.length,i),h=[];for(s=0;s<a.length;s+=1)h[s]=a.charCodeAt(s)^c.charCodeAt(s);var u=ve(h,o.length,i),f=[0];for(s=0;s<o.length;s+=1)f[s+1]=o[s]^u.charCodeAt(s);return new P(f.concat(h))}var Ki=function(){function n(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}return n.prototype.doPublic=function(t){return t.modPowInt(this.e,this.n)},n.prototype.doPrivate=function(t){if(this.p==null||this.q==null)return t.modPow(this.d,this.n);for(var e=t.mod(this.p).modPow(this.dmp1,this.p),i=t.mod(this.q).modPow(this.dmq1,this.q);e.compareTo(i)<0;)e=e.add(this.p);return e.subtract(i).multiply(this.coeff).mod(this.p).multiply(this.q).add(i)},n.prototype.setPublic=function(t,e){t!=null&&e!=null&&t.length>0&&e.length>0?(this.n=C(t,16),this.e=parseInt(e,16)):console.error("Invalid RSA public key")},n.prototype.encrypt=function(t,e){typeof e>"u"&&(e=Fi);var i=this.n.bitLength()+7>>3,r=e(t,i);if(r==null)return null;var s=this.doPublic(r);if(s==null)return null;for(var a=s.toString(16),o=a.length,c=0;c<i*2-o;c++)a="0"+a;return a},n.prototype.setPrivate=function(t,e,i){t!=null&&e!=null&&t.length>0&&e.length>0?(this.n=C(t,16),this.e=parseInt(e,16),this.d=C(i,16)):console.error("Invalid RSA private key")},n.prototype.setPrivateEx=function(t,e,i,r,s,a,o,c){t!=null&&e!=null&&t.length>0&&e.length>0?(this.n=C(t,16),this.e=parseInt(e,16),this.d=C(i,16),this.p=C(r,16),this.q=C(s,16),this.dmp1=C(a,16),this.dmq1=C(o,16),this.coeff=C(c,16)):console.error("Invalid RSA private key")},n.prototype.generate=function(t,e){var i=new Vt,r=t>>1;this.e=parseInt(e,16);for(var s=new P(e,16);;){for(;this.p=new P(t-r,1,i),!(this.p.subtract(P.ONE).gcd(s).compareTo(P.ONE)==0&&this.p.isProbablePrime(10)););for(;this.q=new P(r,1,i),!(this.q.subtract(P.ONE).gcd(s).compareTo(P.ONE)==0&&this.q.isProbablePrime(10)););if(this.p.compareTo(this.q)<=0){var a=this.p;this.p=this.q,this.q=a}var o=this.p.subtract(P.ONE),c=this.q.subtract(P.ONE),h=o.multiply(c);if(h.gcd(s).compareTo(P.ONE)==0){this.n=this.p.multiply(this.q),this.d=s.modInverse(h),this.dmp1=this.d.mod(o),this.dmq1=this.d.mod(c),this.coeff=this.q.modInverse(this.p);break}}},n.prototype.decrypt=function(t){var e=C(t,16),i=this.doPrivate(e);return i==null?null:Hi(i,this.n.bitLength()+7>>3)},n.prototype.generateAsync=function(t,e,i){var r=new Vt,s=t>>1;this.e=parseInt(e,16);var a=new P(e,16),o=this,c=function(){var h=function(){if(o.p.compareTo(o.q)<=0){var _=o.p;o.p=o.q,o.q=_}var y=o.p.subtract(P.ONE),d=o.q.subtract(P.ONE),m=y.multiply(d);m.gcd(a).compareTo(P.ONE)==0?(o.n=o.p.multiply(o.q),o.d=a.modInverse(m),o.dmp1=o.d.mod(y),o.dmq1=o.d.mod(d),o.coeff=o.q.modInverse(o.p),setTimeout(function(){i()},0)):setTimeout(c,0)},u=function(){o.q=E(),o.q.fromNumberAsync(s,1,r,function(){o.q.subtract(P.ONE).gcda(a,function(_){_.compareTo(P.ONE)==0&&o.q.isProbablePrime(10)?setTimeout(h,0):setTimeout(u,0)})})},f=function(){o.p=E(),o.p.fromNumberAsync(t-s,1,r,function(){o.p.subtract(P.ONE).gcda(a,function(_){_.compareTo(P.ONE)==0&&o.p.isProbablePrime(10)?setTimeout(u,0):setTimeout(f,0)})})};setTimeout(f,0)};setTimeout(c,0)},n.prototype.sign=function(t,e,i){var r=Wi(i),s=r+e(t).toString(),a=this.n.bitLength()/4,o=ki(s,a);if(o==null)return null;var c=this.doPrivate(o);if(c==null)return null;for(var h=c.toString(16),u=h.length,f=0;f<a-u;f++)h="0"+h;return h},n.prototype.verify=function(t,e,i){var r=C(e,16),s=this.doPublic(r);if(s==null)return null;var a=s.toString(16).replace(/^1f+00/,""),o=Xi(a);return o==i(t).toString()},n}();function Hi(n,t){for(var e=n.toByteArray(),i=0;i<e.length&&e[i]==0;)++i;if(e.length-i!=t-1||e[i]!=2)return null;for(++i;e[i]!=0;)if(++i>=e.length)return null;for(var r="";++i<e.length;){var s=e[i]&255;s<128?r+=String.fromCharCode(s):s>191&&s<224?(r+=String.fromCharCode((s&31)<<6|e[i+1]&63),++i):(r+=String.fromCharCode((s&15)<<12|(e[i+1]&63)<<6|e[i+2]&63),i+=2)}return r}var It={md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",ripemd160:"3021300906052b2403020105000414"};function Wi(n){return It[n]||""}function Xi(n){for(var t in It)if(It.hasOwnProperty(t)){var e=It[t],i=e.length;if(n.substring(0,i)==e)return n.substring(i)}return n}function R(n,t,e){if(!t||!n)throw new Error("extend failed, please check that all dependencies are included.");var i=function(){};i.prototype=t.prototype,n.prototype=new i,n.prototype.constructor=n,n.superclass=t.prototype,t.prototype.constructor==Object.prototype.constructor&&(t.prototype.constructor=t)}/**
* @fileOverview
* @name asn1-1.0.js
* @author Kenji Urushima kenji.urushima@gmail.com
* @version asn1 1.0.13 (2017-Jun-02)
* @since jsrsasign 2.1
* @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
*/var p={};(typeof p.asn1>"u"||!p.asn1)&&(p.asn1={});p.asn1.ASN1Util=new function(){this.integerToByteHex=function(n){var t=n.toString(16);return t.length%2==1&&(t="0"+t),t},this.bigIntToMinTwosComplementsHex=function(n){var t=n.toString(16);if(t.substring(0,1)!="-")t.length%2==1?t="0"+t:t.match(/^[0-7]/)||(t="00"+t);else{var e=t.substring(1),i=e.length;i%2==1?i+=1:t.match(/^[0-7]/)||(i+=2);for(var r="",s=0;s<i;s++)r+="f";var a=new P(r,16),o=a.xor(n).add(P.ONE);t=o.toString(16).replace(/^-/,"")}return t},this.getPEMStringFromHex=function(n,t){return hextopem(n,t)},this.newObject=function(n){var t=p,e=t.asn1,i=e.DERBoolean,r=e.DERInteger,s=e.DERBitString,a=e.DEROctetString,o=e.DERNull,c=e.DERObjectIdentifier,h=e.DEREnumerated,u=e.DERUTF8String,f=e.DERNumericString,_=e.DERPrintableString,y=e.DERTeletexString,d=e.DERIA5String,m=e.DERUTCTime,g=e.DERGeneralizedTime,w=e.DERSequence,A=e.DERSet,T=e.DERTaggedObject,O=e.ASN1Util.newObject,V=Object.keys(n);if(V.length!=1)throw"key of param shall be only one.";var b=V[0];if(":bool:int:bitstr:octstr:null:oid:enum:utf8str:numstr:prnstr:telstr:ia5str:utctime:gentime:seq:set:tag:".indexOf(":"+b+":")==-1)throw"undefined key: "+b;if(b=="bool")return new i(n[b]);if(b=="int")return new r(n[b]);if(b=="bitstr")return new s(n[b]);if(b=="octstr")return new a(n[b]);if(b=="null")return new o(n[b]);if(b=="oid")return new c(n[b]);if(b=="enum")return new h(n[b]);if(b=="utf8str")return new u(n[b]);if(b=="numstr")return new f(n[b]);if(b=="prnstr")return new _(n[b]);if(b=="telstr")return new y(n[b]);if(b=="ia5str")return new d(n[b]);if(b=="utctime")return new m(n[b]);if(b=="gentime")return new g(n[b]);if(b=="seq"){for(var D=n[b],z=[],k=0;k<D.length;k++){var st=O(D[k]);z.push(st)}return new w({array:z})}if(b=="set"){for(var D=n[b],z=[],k=0;k<D.length;k++){var st=O(D[k]);z.push(st)}return new A({array:z})}if(b=="tag"){var U=n[b];if(Object.prototype.toString.call(U)==="[object Array]"&&U.length==3){var at=O(U[2]);return new T({tag:U[0],explicit:U[1],obj:at})}else{var K={};if(U.explicit!==void 0&&(K.explicit=U.explicit),U.tag!==void 0&&(K.tag=U.tag),U.obj===void 0)throw"obj shall be specified for 'tag'.";return K.obj=O(U.obj),new T(K)}}},this.jsonToASN1HEX=function(n){var t=this.newObject(n);return t.getEncodedHex()}};p.asn1.ASN1Util.oidHexToInt=function(n){for(var r="",t=parseInt(n.substring(0,2),16),e=Math.floor(t/40),i=t%40,r=e+"."+i,s="",a=2;a<n.length;a+=2){var o=parseInt(n.substring(a,a+2),16),c=("00000000"+o.toString(2)).slice(-8);if(s=s+c.substring(1,8),c.substring(0,1)=="0"){var h=new P(s,2);r=r+"."+h.toString(10),s=""}}return r};p.asn1.ASN1Util.oidIntToHex=function(n){var t=function(o){var c=o.toString(16);return c.length==1&&(c="0"+c),c},e=function(o){var c="",h=new P(o,10),u=h.toString(2),f=7-u.length%7;f==7&&(f=0);for(var _="",y=0;y<f;y++)_+="0";u=_+u;for(var y=0;y<u.length-1;y+=7){var d=u.substring(y,y+7);y!=u.length-7&&(d="1"+d),c+=t(parseInt(d,2))}return c};if(!n.match(/^[0-9.]+$/))throw"malformed oid string: "+n;var i="",r=n.split("."),s=parseInt(r[0])*40+parseInt(r[1]);i+=t(s),r.splice(0,2);for(var a=0;a<r.length;a++)i+=e(r[a]);return i};p.asn1.ASN1Object=function(){var n="";this.getLengthHexFromValue=function(){if(typeof this.hV>"u"||this.hV==null)throw"this.hV is null or undefined.";if(this.hV.length%2==1)throw"value hex must be even length: n="+n.length+",v="+this.hV;var t=this.hV.length/2,e=t.toString(16);if(e.length%2==1&&(e="0"+e),t<128)return e;var i=e.length/2;if(i>15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);var r=128+i;return r.toString(16)+e},this.getEncodedHex=function(){return(this.hTLV==null||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}};p.asn1.DERAbstractString=function(n){p.asn1.DERAbstractString.superclass.constructor.call(this),this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=stohex(this.s)},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},typeof n<"u"&&(typeof n=="string"?this.setString(n):typeof n.str<"u"?this.setString(n.str):typeof n.hex<"u"&&this.setStringHex(n.hex))};R(p.asn1.DERAbstractString,p.asn1.ASN1Object);p.asn1.DERAbstractTime=function(n){p.asn1.DERAbstractTime.superclass.constructor.call(this),this.localDateToUTC=function(t){utc=t.getTime()+t.getTimezoneOffset()*6e4;var e=new Date(utc);return e},this.formatDate=function(t,e,i){var r=this.zeroPadding,s=this.localDateToUTC(t),a=String(s.getFullYear());e=="utc"&&(a=a.substring(2,4));var o=r(String(s.getMonth()+1),2),c=r(String(s.getDate()),2),h=r(String(s.getHours()),2),u=r(String(s.getMinutes()),2),f=r(String(s.getSeconds()),2),_=a+o+c+h+u+f;if(i===!0){var y=s.getMilliseconds();if(y!=0){var d=r(String(y),3);d=d.replace(/[0]+$/,""),_=_+"."+d}}return _+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=stohex(t)},this.setByDateValue=function(t,e,i,r,s,a){var o=new Date(Date.UTC(t,e-1,i,r,s,a,0));this.setByDate(o)},this.getFreshValueHex=function(){return this.hV}};R(p.asn1.DERAbstractTime,p.asn1.ASN1Object);p.asn1.DERAbstractStructured=function(n){p.asn1.DERAbstractString.superclass.constructor.call(this),this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,typeof n<"u"&&typeof n.array<"u"&&(this.asn1Array=n.array)};R(p.asn1.DERAbstractStructured,p.asn1.ASN1Object);p.asn1.DERBoolean=function(){p.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"};R(p.asn1.DERBoolean,p.asn1.ASN1Object);p.asn1.DERInteger=function(n){p.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=p.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new P(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},typeof n<"u"&&(typeof n.bigint<"u"?this.setByBigInteger(n.bigint):typeof n.int<"u"?this.setByInteger(n.int):typeof n=="number"?this.setByInteger(n):typeof n.hex<"u"&&this.setValueHex(n.hex))};R(p.asn1.DERInteger,p.asn1.ASN1Object);p.asn1.DERBitString=function(n){if(n!==void 0&&typeof n.obj<"u"){var t=p.asn1.ASN1Util.newObject(n.obj);n.hex="00"+t.getEncodedHex()}p.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(e){this.hTLV=null,this.isModified=!0,this.hV=e},this.setUnusedBitsAndHexValue=function(e,i){if(e<0||7<e)throw"unused bits shall be from 0 to 7: u = "+e;var r="0"+e;this.hTLV=null,this.isModified=!0,this.hV=r+i},this.setByBinaryString=function(e){e=e.replace(/0+$/,"");var i=8-e.length%8;i==8&&(i=0);for(var r=0;r<=i;r++)e+="0";for(var s="",r=0;r<e.length-1;r+=8){var a=e.substring(r,r+8),o=parseInt(a,2).toString(16);o.length==1&&(o="0"+o),s+=o}this.hTLV=null,this.isModified=!0,this.hV="0"+i+s},this.setByBooleanArray=function(e){for(var i="",r=0;r<e.length;r++)e[r]==!0?i+="1":i+="0";this.setByBinaryString(i)},this.newFalseArray=function(e){for(var i=new Array(e),r=0;r<e;r++)i[r]=!1;return i},this.getFreshValueHex=function(){return this.hV},typeof n<"u"&&(typeof n=="string"&&n.toLowerCase().match(/^[0-9a-f]+$/)?this.setHexValueIncludingUnusedBits(n):typeof n.hex<"u"?this.setHexValueIncludingUnusedBits(n.hex):typeof n.bin<"u"?this.setByBinaryString(n.bin):typeof n.array<"u"&&this.setByBooleanArray(n.array))};R(p.asn1.DERBitString,p.asn1.ASN1Object);p.asn1.DEROctetString=function(n){if(n!==void 0&&typeof n.obj<"u"){var t=p.asn1.ASN1Util.newObject(n.obj);n.hex=t.getEncodedHex()}p.asn1.DEROctetString.superclass.constructor.call(this,n),this.hT="04"};R(p.asn1.DEROctetString,p.asn1.DERAbstractString);p.asn1.DERNull=function(){p.asn1.DERNull.superclass.constructor.call(this),this.hT="05",this.hTLV="0500"};R(p.asn1.DERNull,p.asn1.ASN1Object);p.asn1.DERObjectIdentifier=function(n){var t=function(i){var r=i.toString(16);return r.length==1&&(r="0"+r),r},e=function(i){var r="",s=new P(i,10),a=s.toString(2),o=7-a.length%7;o==7&&(o=0);for(var c="",h=0;h<o;h++)c+="0";a=c+a;for(var h=0;h<a.length-1;h+=7){var u=a.substring(h,h+7);h!=a.length-7&&(u="1"+u),r+=t(parseInt(u,2))}return r};p.asn1.DERObjectIdentifier.superclass.constructor.call(this),this.hT="06",this.setValueHex=function(i){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=i},this.setValueOidString=function(i){if(!i.match(/^[0-9.]+$/))throw"malformed oid string: "+i;var r="",s=i.split("."),a=parseInt(s[0])*40+parseInt(s[1]);r+=t(a),s.splice(0,2);for(var o=0;o<s.length;o++)r+=e(s[o]);this.hTLV=null,this.isModified=!0,this.s=null,this.hV=r},this.setValueName=function(i){var r=p.asn1.x509.OID.name2oid(i);if(r!=="")this.setValueOidString(r);else throw"DERObjectIdentifier oidName undefined: "+i},this.getFreshValueHex=function(){return this.hV},n!==void 0&&(typeof n=="string"?n.match(/^[0-2].[0-9.]+$/)?this.setValueOidString(n):this.setValueName(n):n.oid!==void 0?this.setValueOidString(n.oid):n.hex!==void 0?this.setValueHex(n.hex):n.name!==void 0&&this.setValueName(n.name))};R(p.asn1.DERObjectIdentifier,p.asn1.ASN1Object);p.asn1.DEREnumerated=function(n){p.asn1.DEREnumerated.superclass.constructor.call(this),this.hT="0a",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=p.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new P(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},typeof n<"u"&&(typeof n.int<"u"?this.setByInteger(n.int):typeof n=="number"?this.setByInteger(n):typeof n.hex<"u"&&this.setValueHex(n.hex))};R(p.asn1.DEREnumerated,p.asn1.ASN1Object);p.asn1.DERUTF8String=function(n){p.asn1.DERUTF8String.superclass.constructor.call(this,n),this.hT="0c"};R(p.asn1.DERUTF8String,p.asn1.DERAbstractString);p.asn1.DERNumericString=function(n){p.asn1.DERNumericString.superclass.constructor.call(this,n),this.hT="12"};R(p.asn1.DERNumericString,p.asn1.DERAbstractString);p.asn1.DERPrintableString=function(n){p.asn1.DERPrintableString.superclass.constructor.call(this,n),this.hT="13"};R(p.asn1.DERPrintableString,p.asn1.DERAbstractString);p.asn1.DERTeletexString=function(n){p.asn1.DER