flagmint-js-sdk 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,4 +15,4 @@ Use Chrome, Firefox or Internet Explorer 11`)}var ju=Ot.Buffer,wn=Gt.crypto||Gt.
15
15
  `)},Vf}var nh;function Q2(){return nh||(nh=1,function(h){var n=h;n.der=Do(),n.pem=j2()}(Zf)),Zf}var fh;function fn(){return fh||(fh=1,function(h){var n=h;n.bignum=Z2,n.define=W2().define,n.base=Ui(),n.constants=Fo(),n.decoders=X2(),n.encoders=Q2()}(Df)),Df}var ir=fn(),ah=ir.define("Time",function(){this.choice({utcTime:this.utctime(),generalTime:this.gentime()})}),tm=ir.define("AttributeTypeValue",function(){this.seq().obj(this.key("type").objid(),this.key("value").any())}),V0=ir.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional(),this.key("curve").objid().optional())}),em=ir.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(V0),this.key("subjectPublicKey").bitstr())}),rm=ir.define("RelativeDistinguishedName",function(){this.setof(tm)}),im=ir.define("RDNSequence",function(){this.seqof(rm)}),hh=ir.define("Name",function(){this.choice({rdnSequence:this.use(im)})}),nm=ir.define("Validity",function(){this.seq().obj(this.key("notBefore").use(ah),this.key("notAfter").use(ah))}),fm=ir.define("Extension",function(){this.seq().obj(this.key("extnID").objid(),this.key("critical").bool().def(!1),this.key("extnValue").octstr())}),am=ir.define("TBSCertificate",function(){this.seq().obj(this.key("version").explicit(0).int().optional(),this.key("serialNumber").int(),this.key("signature").use(V0),this.key("issuer").use(hh),this.key("validity").use(nm),this.key("subject").use(hh),this.key("subjectPublicKeyInfo").use(em),this.key("issuerUniqueID").implicit(1).bitstr().optional(),this.key("subjectUniqueID").implicit(2).bitstr().optional(),this.key("extensions").explicit(3).seqof(fm).optional())}),hm=ir.define("X509Certificate",function(){this.seq().obj(this.key("tbsCertificate").use(am),this.key("signatureAlgorithm").use(V0),this.key("signatureValue").bitstr())}),sm=hm,nr=fn();rr.certificate=sm;var om=nr.define("RSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("modulus").int(),this.key("publicExponent").int(),this.key("privateExponent").int(),this.key("prime1").int(),this.key("prime2").int(),this.key("exponent1").int(),this.key("exponent2").int(),this.key("coefficient").int())});rr.RSAPrivateKey=om;var um=nr.define("RSAPublicKey",function(){this.seq().obj(this.key("modulus").int(),this.key("publicExponent").int())});rr.RSAPublicKey=um;var $o=nr.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("none").null_().optional(),this.key("curve").objid().optional(),this.key("params").seq().obj(this.key("p").int(),this.key("q").int(),this.key("g").int()).optional())}),lm=nr.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use($o),this.key("subjectPublicKey").bitstr())});rr.PublicKey=lm;var dm=nr.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").use($o),this.key("subjectPrivateKey").octstr())});rr.PrivateKey=dm;var cm=nr.define("EncryptedPrivateKeyInfo",function(){this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(),this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(),this.key("kdeparams").seq().obj(this.key("salt").octstr(),this.key("iters").int())),this.key("cipher").seq().obj(this.key("algo").objid(),this.key("iv").octstr()))),this.key("subjectPrivateKey").octstr())});rr.EncryptedPrivateKey=cm;var vm=nr.define("DSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("p").int(),this.key("q").int(),this.key("g").int(),this.key("pub_key").int(),this.key("priv_key").int())});rr.DSAPrivateKey=vm;rr.DSAparam=nr.define("DSAparam",function(){this.int()});var pm=nr.define("ECParameters",function(){this.choice({namedCurve:this.objid()})}),mm=nr.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").optional().explicit(0).use(pm),this.key("publicKey").optional().explicit(1).bitstr())});rr.ECPrivateKey=mm;rr.signature=nr.define("signature",function(){this.seq().obj(this.key("r").int(),this.key("s").int())});const gm={"2.16.840.1.101.3.4.1.1":"aes-128-ecb","2.16.840.1.101.3.4.1.2":"aes-128-cbc","2.16.840.1.101.3.4.1.3":"aes-128-ofb","2.16.840.1.101.3.4.1.4":"aes-128-cfb","2.16.840.1.101.3.4.1.21":"aes-192-ecb","2.16.840.1.101.3.4.1.22":"aes-192-cbc","2.16.840.1.101.3.4.1.23":"aes-192-ofb","2.16.840.1.101.3.4.1.24":"aes-192-cfb","2.16.840.1.101.3.4.1.41":"aes-256-ecb","2.16.840.1.101.3.4.1.42":"aes-256-cbc","2.16.840.1.101.3.4.1.43":"aes-256-ofb","2.16.840.1.101.3.4.1.44":"aes-256-cfb"};var bm=/Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m,ym=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m,wm=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m,Mm=Zn,xm=Le,vn=Ot.Buffer,_m=function(h,n){var o=h.toString(),s=o.match(bm),m;if(s){var g="aes"+s[1],y=vn.from(s[2],"hex"),S=vn.from(s[3].replace(/[\r\n]/g,""),"base64"),B=Mm(n,y.slice(0,8),parseInt(s[1],10)).key,M=[],x=xm.createDecipheriv(g,B,y);M.push(x.update(S)),M.push(x.final()),m=vn.concat(M)}else{var f=o.match(wm);m=vn.from(f[2].replace(/[\r\n]/g,""),"base64")}var k=o.match(ym)[1];return{tag:k,data:m}},qe=rr,Sm=gm,Am=_m,Bm=Le,Em=Nn,c0=Ot.Buffer;function Im(h,n){var o=h.algorithm.decrypt.kde.kdeparams.salt,s=parseInt(h.algorithm.decrypt.kde.kdeparams.iters.toString(),10),m=Sm[h.algorithm.decrypt.cipher.algo.join(".")],f=h.algorithm.decrypt.cipher.iv,g=h.subjectPrivateKey,y=parseInt(m.split("-")[1],10)/8,S=Em.pbkdf2Sync(n,o,s,y,"sha1"),B=Bm.createDecipheriv(m,S,f),M=[];return M.push(B.update(g)),M.push(B.final()),c0.concat(M)}function No(h){var n;typeof h=="object"&&!c0.isBuffer(h)&&(n=h.passphrase,h=h.key),typeof h=="string"&&(h=c0.from(h));var o=Am(h,n),s=o.tag,m=o.data,f,g;switch(s){case"CERTIFICATE":g=qe.certificate.decode(m,"der").tbsCertificate.subjectPublicKeyInfo;case"PUBLIC KEY":switch(g||(g=qe.PublicKey.decode(m,"der")),f=g.algorithm.algorithm.join("."),f){case"1.2.840.113549.1.1.1":return qe.RSAPublicKey.decode(g.subjectPublicKey.data,"der");case"1.2.840.10045.2.1":return g.subjectPrivateKey=g.subjectPublicKey,{type:"ec",data:g};case"1.2.840.10040.4.1":return g.algorithm.params.pub_key=qe.DSAparam.decode(g.subjectPublicKey.data,"der"),{type:"dsa",data:g.algorithm.params};default:throw new Error("unknown key id "+f)}case"ENCRYPTED PRIVATE KEY":m=qe.EncryptedPrivateKey.decode(m,"der"),m=Im(m,n);case"PRIVATE KEY":switch(g=qe.PrivateKey.decode(m,"der"),f=g.algorithm.algorithm.join("."),f){case"1.2.840.113549.1.1.1":return qe.RSAPrivateKey.decode(g.subjectPrivateKey,"der");case"1.2.840.10045.2.1":return{curve:g.algorithm.curve,privateKey:qe.ECPrivateKey.decode(g.subjectPrivateKey,"der").privateKey};case"1.2.840.10040.4.1":return g.algorithm.params.priv_key=qe.DSAparam.decode(g.subjectPrivateKey,"der"),{type:"dsa",params:g.algorithm.params};default:throw new Error("unknown key id "+f)}case"RSA PUBLIC KEY":return qe.RSAPublicKey.decode(m,"der");case"RSA PRIVATE KEY":return qe.RSAPrivateKey.decode(m,"der");case"DSA PRIVATE KEY":return{type:"dsa",params:qe.DSAPrivateKey.decode(m,"der")};case"EC PRIVATE KEY":return m=qe.ECPrivateKey.decode(m,"der"),{curve:m.parameters.value,privateKey:m.privateKey};default:throw new Error("unknown key type "+s)}}No.signature=qe.signature;var hf=No;const Uo={"1.3.132.0.10":"secp256k1","1.3.132.0.33":"p224","1.2.840.10045.3.1.1":"p192","1.2.840.10045.3.1.7":"p256","1.3.132.0.34":"p384","1.3.132.0.35":"p521"};var sh;function km(){if(sh)return Ci.exports;sh=1;var h=Ot.Buffer,n=Vh,o=U0,s=Z0().ec,m=N0,f=hf,g=Uo,y=1;function S(z,N,lt,H,At){var Bt=f(N);if(Bt.curve){if(H!=="ecdsa"&&H!=="ecdsa/rsa")throw new Error("wrong private key type");return B(z,Bt)}else if(Bt.type==="dsa"){if(H!=="dsa")throw new Error("wrong private key type");return M(z,Bt,lt)}if(H!=="rsa"&&H!=="ecdsa/rsa")throw new Error("wrong private key type");if(N.padding!==void 0&&N.padding!==y)throw new Error("illegal or unsupported padding mode");z=h.concat([At,z]);for(var Ct=Bt.modulus.byteLength(),Et=[0,1];z.length+Et.length+1<Ct;)Et.push(255);Et.push(0);for(var Y=-1;++Y<z.length;)Et.push(z[Y]);var kt=o(Et,Bt);return kt}function B(z,N){var lt=g[N.curve.join(".")];if(!lt)throw new Error("unknown curve "+N.curve.join("."));var H=new s(lt),At=H.keyFromPrivate(N.privateKey),Bt=At.sign(z);return h.from(Bt.toDER())}function M(z,N,lt){for(var H=N.params.priv_key,At=N.params.p,Bt=N.params.q,Ct=N.params.g,Et=new m(0),Y,kt=I(z,Bt).mod(Bt),p=!1,t=k(H,Bt,z,lt);p===!1;)Y=L(Bt,t,lt),Et=W(Ct,Y,At,Bt),p=Y.invm(Bt).imul(kt.add(H.mul(Et))).mod(Bt),p.cmpn(0)===0&&(p=!1,Et=new m(0));return x(Et,p)}function x(z,N){z=z.toArray(),N=N.toArray(),z[0]&128&&(z=[0].concat(z)),N[0]&128&&(N=[0].concat(N));var lt=z.length+N.length+4,H=[48,lt,2,z.length];return H=H.concat(z,[2,N.length],N),h.from(H)}function k(z,N,lt,H){if(z=h.from(z.toArray()),z.length<N.byteLength()){var At=h.alloc(N.byteLength()-z.length);z=h.concat([At,z])}var Bt=lt.length,Ct=D(lt,N),Et=h.alloc(Bt);Et.fill(1);var Y=h.alloc(Bt);return Y=n(H,Y).update(Et).update(h.from([0])).update(z).update(Ct).digest(),Et=n(H,Y).update(Et).digest(),Y=n(H,Y).update(Et).update(h.from([1])).update(z).update(Ct).digest(),Et=n(H,Y).update(Et).digest(),{k:Y,v:Et}}function I(z,N){var lt=new m(z),H=(z.length<<3)-N.bitLength();return H>0&&lt.ishrn(H),lt}function D(z,N){z=I(z,N),z=z.mod(N);var lt=h.from(z.toArray());if(lt.length<N.byteLength()){var H=h.alloc(N.byteLength()-lt.length);lt=h.concat([H,lt])}return lt}function L(z,N,lt){var H,At;do{for(H=h.alloc(0);H.length*8<z.bitLength();)N.v=n(lt,N.k).update(N.v).digest(),H=h.concat([H,N.v]);At=I(H,z),N.k=n(lt,N.k).update(N.v).update(h.from([0])).digest(),N.v=n(lt,N.k).update(N.v).digest()}while(At.cmp(z)!==-1);return At}function W(z,N,lt,H){return z.toRed(m.mont(lt)).redPow(N).fromRed().mod(H)}return Ci.exports=S,Ci.exports.getKey=k,Ci.exports.makeKey=L,Ci.exports}var Yf,oh;function Rm(){if(oh)return Yf;oh=1;var h=Ot.Buffer,n=N0,o=Z0().ec,s=hf,m=Uo;function f(B,M,x,k,I){var D=s(x);if(D.type==="ec"){if(k!=="ecdsa"&&k!=="ecdsa/rsa")throw new Error("wrong public key type");return g(B,M,D)}else if(D.type==="dsa"){if(k!=="dsa")throw new Error("wrong public key type");return y(B,M,D)}if(k!=="rsa"&&k!=="ecdsa/rsa")throw new Error("wrong public key type");M=h.concat([I,M]);for(var L=D.modulus.byteLength(),W=[1],z=0;M.length+W.length+2<L;)W.push(255),z+=1;W.push(0);for(var N=-1;++N<M.length;)W.push(M[N]);W=h.from(W);var lt=n.mont(D.modulus);B=new n(B).toRed(lt),B=B.redPow(new n(D.publicExponent)),B=h.from(B.fromRed().toArray());var H=z<8?1:0;for(L=Math.min(B.length,W.length),B.length!==W.length&&(H=1),N=-1;++N<L;)H|=B[N]^W[N];return H===0}function g(B,M,x){var k=m[x.data.algorithm.curve.join(".")];if(!k)throw new Error("unknown curve "+x.data.algorithm.curve.join("."));var I=new o(k),D=x.data.subjectPrivateKey.data;return I.verify(M,B,D)}function y(B,M,x){var k=x.data.p,I=x.data.q,D=x.data.g,L=x.data.pub_key,W=s.signature.decode(B,"der"),z=W.s,N=W.r;S(z,I),S(N,I);var lt=n.mont(k),H=z.invm(I),At=D.toRed(lt).redPow(new n(M).mul(H).mod(I)).fromRed().mul(L.toRed(lt).redPow(N.mul(H).mod(I)).fromRed()).mod(k).mod(I);return At.cmp(N)===0}function S(B,M){if(B.cmpn(0)<=0)throw new Error("invalid sig");if(B.cmp(M)>=0)throw new Error("invalid sig")}return Yf=f,Yf}var Jf,uh;function Tm(){if(uh)return Jf;uh=1;var h=Ot.Buffer,n=Gi,o=Ev,s=Jt,m=km(),f=Rm(),g=Yh;Object.keys(g).forEach(function(x){g[x].id=h.from(g[x].id,"hex"),g[x.toLowerCase()]=g[x]});function y(x){o.Writable.call(this);var k=g[x];if(!k)throw new Error("Unknown message digest");this._hashType=k.hash,this._hash=n(k.hash),this._tag=k.id,this._signType=k.sign}s(y,o.Writable),y.prototype._write=function(k,I,D){this._hash.update(k),D()},y.prototype.update=function(k,I){return this._hash.update(typeof k=="string"?h.from(k,I):k),this},y.prototype.sign=function(k,I){this.end();var D=this._hash.digest(),L=m(D,k,this._hashType,this._signType,this._tag);return I?L.toString(I):L};function S(x){o.Writable.call(this);var k=g[x];if(!k)throw new Error("Unknown message digest");this._hash=n(k.hash),this._tag=k.id,this._signType=k.sign}s(S,o.Writable),S.prototype._write=function(k,I,D){this._hash.update(k),D()},S.prototype.update=function(k,I){return this._hash.update(typeof k=="string"?h.from(k,I):k),this},S.prototype.verify=function(k,I,D){var L=typeof I=="string"?h.from(I,D):I;this.end();var W=this._hash.digest();return f(L,W,k,this._signType,this._tag)};function B(x){return new y(x)}function M(x){return new S(x)}return Jf={Sign:B,Verify:M,createSign:B,createVerify:M},Jf}var Y0={exports:{}};Y0.exports;(function(h){(function(n,o){function s(p,t){if(!p)throw new Error(t||"Assertion failed")}function m(p,t){p.super_=t;var r=function(){};r.prototype=t.prototype,p.prototype=new r,p.prototype.constructor=p}function f(p,t,r){if(f.isBN(p))return p;this.negative=0,this.words=null,this.length=0,this.red=null,p!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(p||0,t||10,r||"be"))}typeof n=="object"?n.exports=f:o.BN=f,f.BN=f,f.wordSize=26;var g;try{typeof window!="undefined"&&typeof window.Buffer!="undefined"?g=window.Buffer:g=Pe.Buffer}catch(p){}f.isBN=function(t){return t instanceof f?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===f.wordSize&&Array.isArray(t.words)},f.max=function(t,r){return t.cmp(r)>0?t:r},f.min=function(t,r){return t.cmp(r)<0?t:r},f.prototype._init=function(t,r,i){if(typeof t=="number")return this._initNumber(t,r,i);if(typeof t=="object")return this._initArray(t,r,i);r==="hex"&&(r=16),s(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var a=0;t[0]==="-"&&(a++,this.negative=1),a<t.length&&(r===16?this._parseHex(t,a,i):(this._parseBase(t,r,a),i==="le"&&this._initArray(this.toArray(),r,i)))},f.prototype._initNumber=function(t,r,i){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(s(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),i==="le"&&this._initArray(this.toArray(),r,i)},f.prototype._initArray=function(t,r,i){if(s(typeof t.length=="number"),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 a=0;a<this.length;a++)this.words[a]=0;var d,c,v=0;if(i==="be")for(a=t.length-1,d=0;a>=0;a-=3)c=t[a]|t[a-1]<<8|t[a-2]<<16,this.words[d]|=c<<v&67108863,this.words[d+1]=c>>>26-v&67108863,v+=24,v>=26&&(v-=26,d++);else if(i==="le")for(a=0,d=0;a<t.length;a+=3)c=t[a]|t[a+1]<<8|t[a+2]<<16,this.words[d]|=c<<v&67108863,this.words[d+1]=c>>>26-v&67108863,v+=24,v>=26&&(v-=26,d++);return this.strip()};function y(p,t){var r=p.charCodeAt(t);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function S(p,t,r){var i=y(p,r);return r-1>=t&&(i|=y(p,r-1)<<4),i}f.prototype._parseHex=function(t,r,i){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var a=0;a<this.length;a++)this.words[a]=0;var d=0,c=0,v;if(i==="be")for(a=t.length-1;a>=r;a-=2)v=S(t,r,a)<<d,this.words[c]|=v&67108863,d>=18?(d-=18,c+=1,this.words[c]|=v>>>26):d+=8;else{var u=t.length-r;for(a=u%2===0?r+1:r;a<t.length;a+=2)v=S(t,r,a)<<d,this.words[c]|=v&67108863,d>=18?(d-=18,c+=1,this.words[c]|=v>>>26):d+=8}this.strip()};function B(p,t,r,i){for(var a=0,d=Math.min(p.length,r),c=t;c<d;c++){var v=p.charCodeAt(c)-48;a*=i,v>=49?a+=v-49+10:v>=17?a+=v-17+10:a+=v}return a}f.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var a=0,d=1;d<=67108863;d*=r)a++;a--,d=d/r|0;for(var c=t.length-i,v=c%a,u=Math.min(c,c-v)+i,e=0,l=i;l<u;l+=a)e=B(t,l,l+a,r),this.imuln(d),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);if(v!==0){var b=1;for(e=B(t,l,t.length,r),l=0;l<v;l++)b*=r;this.imuln(b),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e)}this.strip()},f.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red},f.prototype.clone=function(){var t=new f(null);return this.copy(t),t},f.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},f.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},f.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},f.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var M=["","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"],x=[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],k=[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];f.prototype.toString=function(t,r){t=t||10,r=r|0||1;var i;if(t===16||t==="hex"){i="";for(var a=0,d=0,c=0;c<this.length;c++){var v=this.words[c],u=((v<<a|d)&16777215).toString(16);d=v>>>24-a&16777215,a+=2,a>=26&&(a-=26,c--),d!==0||c!==this.length-1?i=M[6-u.length]+u+i:i=u+i}for(d!==0&&(i=d.toString(16)+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var e=x[t],l=k[t];i="";var b=this.clone();for(b.negative=0;!b.isZero();){var _=b.modn(l).toString(t);b=b.idivn(l),b.isZero()?i=_+i:i=M[e-_.length]+_+i}for(this.isZero()&&(i="0"+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}s(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&s(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(t,r){return s(typeof g!="undefined"),this.toArrayLike(g,t,r)},f.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},f.prototype.toArrayLike=function(t,r,i){var a=this.byteLength(),d=i||Math.max(1,a);s(a<=d,"byte array longer than desired length"),s(d>0,"Requested array length <= 0"),this.strip();var c=r==="le",v=new t(d),u,e,l=this.clone();if(c){for(e=0;!l.isZero();e++)u=l.andln(255),l.iushrn(8),v[e]=u;for(;e<d;e++)v[e]=0}else{for(e=0;e<d-a;e++)v[e]=0;for(e=0;!l.isZero();e++)u=l.andln(255),l.iushrn(8),v[d-e-1]=u}return v},Math.clz32?f.prototype._countBits=function(t){return 32-Math.clz32(t)}:f.prototype._countBits=function(t){var r=t,i=0;return r>=4096&&(i+=13,r>>>=13),r>=64&&(i+=7,r>>>=7),r>=8&&(i+=4,r>>>=4),r>=2&&(i+=2,r>>>=2),i+r},f.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,i=0;return r&8191||(i+=13,r>>>=13),r&127||(i+=7,r>>>=7),r&15||(i+=4,r>>>=4),r&3||(i+=2,r>>>=2),r&1||i++,i},f.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return(this.length-1)*26+r};function I(p){for(var t=new Array(p.bitLength()),r=0;r<t.length;r++){var i=r/26|0,a=r%26;t[r]=(p.words[i]&1<<a)>>>a}return t}f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var i=this._zeroBits(this.words[r]);if(t+=i,i!==26)break}return t},f.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},f.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},f.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},f.prototype.isNeg=function(){return this.negative!==0},f.prototype.neg=function(){return this.clone().ineg()},f.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},f.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this.strip()},f.prototype.ior=function(t){return s((this.negative|t.negative)===0),this.iuor(t)},f.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},f.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},f.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var i=0;i<r.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=r.length,this.strip()},f.prototype.iand=function(t){return s((this.negative|t.negative)===0),this.iuand(t)},f.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},f.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},f.prototype.iuxor=function(t){var r,i;this.length>t.length?(r=this,i=t):(r=t,i=this);for(var a=0;a<i.length;a++)this.words[a]=r.words[a]^i.words[a];if(this!==r)for(;a<r.length;a++)this.words[a]=r.words[a];return this.length=r.length,this.strip()},f.prototype.ixor=function(t){return s((this.negative|t.negative)===0),this.iuxor(t)},f.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},f.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},f.prototype.inotn=function(t){s(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,i=t%26;this._expand(r),i>0&&r--;for(var a=0;a<r;a++)this.words[a]=~this.words[a]&67108863;return i>0&&(this.words[a]=~this.words[a]&67108863>>26-i),this.strip()},f.prototype.notn=function(t){return this.clone().inotn(t)},f.prototype.setn=function(t,r){s(typeof t=="number"&&t>=0);var i=t/26|0,a=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<a:this.words[i]=this.words[i]&~(1<<a),this.strip()},f.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var i,a;this.length>t.length?(i=this,a=t):(i=t,a=this);for(var d=0,c=0;c<a.length;c++)r=(i.words[c]|0)+(a.words[c]|0)+d,this.words[c]=r&67108863,d=r>>>26;for(;d!==0&&c<i.length;c++)r=(i.words[c]|0)+d,this.words[c]=r&67108863,d=r>>>26;if(this.length=i.length,d!==0)this.words[this.length]=d,this.length++;else if(i!==this)for(;c<i.length;c++)this.words[c]=i.words[c];return this},f.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},f.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i=this.cmp(t);if(i===0)return this.negative=0,this.length=1,this.words[0]=0,this;var a,d;i>0?(a=this,d=t):(a=t,d=this);for(var c=0,v=0;v<d.length;v++)r=(a.words[v]|0)-(d.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;for(;c!==0&&v<a.length;v++)r=(a.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;if(c===0&&v<a.length&&a!==this)for(;v<a.length;v++)this.words[v]=a.words[v];return this.length=Math.max(this.length,v),a!==this&&(this.negative=1),this.strip()},f.prototype.sub=function(t){return this.clone().isub(t)};function D(p,t,r){r.negative=t.negative^p.negative;var i=p.length+t.length|0;r.length=i,i=i-1|0;var a=p.words[0]|0,d=t.words[0]|0,c=a*d,v=c&67108863,u=c/67108864|0;r.words[0]=v;for(var e=1;e<i;e++){for(var l=u>>>26,b=u&67108863,_=Math.min(e,t.length-1),C=Math.max(0,e-p.length+1);C<=_;C++){var F=e-C|0;a=p.words[F]|0,d=t.words[C]|0,c=a*d+b,l+=c/67108864|0,b=c&67108863}r.words[e]=b|0,u=l|0}return u!==0?r.words[e]=u|0:r.length--,r.strip()}var L=function(t,r,i){var a=t.words,d=r.words,c=i.words,v=0,u,e,l,b=a[0]|0,_=b&8191,C=b>>>13,F=a[1]|0,O=F&8191,R=F>>>13,P=a[2]|0,$=P&8191,K=P>>>13,It=a[3]|0,Z=It&8191,J=It>>>13,qt=a[4]|0,tt=qt&8191,vt=qt>>>13,Dt=a[5]|0,et=Dt&8191,pt=Dt>>>13,Pt=a[6]|0,j=Pt&8191,dt=Pt>>>13,Ft=a[7]|0,Q=Ft&8191,ct=Ft>>>13,Lt=a[8]|0,E=Lt&8191,w=Lt>>>13,A=a[9]|0,T=A&8191,q=A>>>13,V=d[0]|0,U=V&8191,X=V>>>13,Tt=d[1]|0,G=Tt&8191,rt=Tt>>>13,Rt=d[2]|0,it=Rt&8191,gt=Rt>>>13,zt=d[3]|0,nt=zt&8191,bt=zt>>>13,Kt=d[4]|0,ft=Kt&8191,yt=Kt>>>13,Ht=d[5]|0,at=Ht&8191,wt=Ht>>>13,Zt=d[6]|0,ht=Zt&8191,Mt=Zt>>>13,Wt=d[7]|0,st=Wt&8191,xt=Wt>>>13,Vt=d[8]|0,ot=Vt&8191,_t=Vt>>>13,Yt=d[9]|0,ut=Yt&8191,St=Yt>>>13;i.negative=t.negative^r.negative,i.length=19,u=Math.imul(_,U),e=Math.imul(_,X),e=e+Math.imul(C,U)|0,l=Math.imul(C,X);var $t=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+($t>>>26)|0,$t&=67108863,u=Math.imul(O,U),e=Math.imul(O,X),e=e+Math.imul(R,U)|0,l=Math.imul(R,X),u=u+Math.imul(_,G)|0,e=e+Math.imul(_,rt)|0,e=e+Math.imul(C,G)|0,l=l+Math.imul(C,rt)|0;var Nt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,u=Math.imul($,U),e=Math.imul($,X),e=e+Math.imul(K,U)|0,l=Math.imul(K,X),u=u+Math.imul(O,G)|0,e=e+Math.imul(O,rt)|0,e=e+Math.imul(R,G)|0,l=l+Math.imul(R,rt)|0,u=u+Math.imul(_,it)|0,e=e+Math.imul(_,gt)|0,e=e+Math.imul(C,it)|0,l=l+Math.imul(C,gt)|0;var jt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(jt>>>26)|0,jt&=67108863,u=Math.imul(Z,U),e=Math.imul(Z,X),e=e+Math.imul(J,U)|0,l=Math.imul(J,X),u=u+Math.imul($,G)|0,e=e+Math.imul($,rt)|0,e=e+Math.imul(K,G)|0,l=l+Math.imul(K,rt)|0,u=u+Math.imul(O,it)|0,e=e+Math.imul(O,gt)|0,e=e+Math.imul(R,it)|0,l=l+Math.imul(R,gt)|0,u=u+Math.imul(_,nt)|0,e=e+Math.imul(_,bt)|0,e=e+Math.imul(C,nt)|0,l=l+Math.imul(C,bt)|0;var Qt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,u=Math.imul(tt,U),e=Math.imul(tt,X),e=e+Math.imul(vt,U)|0,l=Math.imul(vt,X),u=u+Math.imul(Z,G)|0,e=e+Math.imul(Z,rt)|0,e=e+Math.imul(J,G)|0,l=l+Math.imul(J,rt)|0,u=u+Math.imul($,it)|0,e=e+Math.imul($,gt)|0,e=e+Math.imul(K,it)|0,l=l+Math.imul(K,gt)|0,u=u+Math.imul(O,nt)|0,e=e+Math.imul(O,bt)|0,e=e+Math.imul(R,nt)|0,l=l+Math.imul(R,bt)|0,u=u+Math.imul(_,ft)|0,e=e+Math.imul(_,yt)|0,e=e+Math.imul(C,ft)|0,l=l+Math.imul(C,yt)|0;var te=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(te>>>26)|0,te&=67108863,u=Math.imul(et,U),e=Math.imul(et,X),e=e+Math.imul(pt,U)|0,l=Math.imul(pt,X),u=u+Math.imul(tt,G)|0,e=e+Math.imul(tt,rt)|0,e=e+Math.imul(vt,G)|0,l=l+Math.imul(vt,rt)|0,u=u+Math.imul(Z,it)|0,e=e+Math.imul(Z,gt)|0,e=e+Math.imul(J,it)|0,l=l+Math.imul(J,gt)|0,u=u+Math.imul($,nt)|0,e=e+Math.imul($,bt)|0,e=e+Math.imul(K,nt)|0,l=l+Math.imul(K,bt)|0,u=u+Math.imul(O,ft)|0,e=e+Math.imul(O,yt)|0,e=e+Math.imul(R,ft)|0,l=l+Math.imul(R,yt)|0,u=u+Math.imul(_,at)|0,e=e+Math.imul(_,wt)|0,e=e+Math.imul(C,at)|0,l=l+Math.imul(C,wt)|0;var ee=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,u=Math.imul(j,U),e=Math.imul(j,X),e=e+Math.imul(dt,U)|0,l=Math.imul(dt,X),u=u+Math.imul(et,G)|0,e=e+Math.imul(et,rt)|0,e=e+Math.imul(pt,G)|0,l=l+Math.imul(pt,rt)|0,u=u+Math.imul(tt,it)|0,e=e+Math.imul(tt,gt)|0,e=e+Math.imul(vt,it)|0,l=l+Math.imul(vt,gt)|0,u=u+Math.imul(Z,nt)|0,e=e+Math.imul(Z,bt)|0,e=e+Math.imul(J,nt)|0,l=l+Math.imul(J,bt)|0,u=u+Math.imul($,ft)|0,e=e+Math.imul($,yt)|0,e=e+Math.imul(K,ft)|0,l=l+Math.imul(K,yt)|0,u=u+Math.imul(O,at)|0,e=e+Math.imul(O,wt)|0,e=e+Math.imul(R,at)|0,l=l+Math.imul(R,wt)|0,u=u+Math.imul(_,ht)|0,e=e+Math.imul(_,Mt)|0,e=e+Math.imul(C,ht)|0,l=l+Math.imul(C,Mt)|0;var re=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(re>>>26)|0,re&=67108863,u=Math.imul(Q,U),e=Math.imul(Q,X),e=e+Math.imul(ct,U)|0,l=Math.imul(ct,X),u=u+Math.imul(j,G)|0,e=e+Math.imul(j,rt)|0,e=e+Math.imul(dt,G)|0,l=l+Math.imul(dt,rt)|0,u=u+Math.imul(et,it)|0,e=e+Math.imul(et,gt)|0,e=e+Math.imul(pt,it)|0,l=l+Math.imul(pt,gt)|0,u=u+Math.imul(tt,nt)|0,e=e+Math.imul(tt,bt)|0,e=e+Math.imul(vt,nt)|0,l=l+Math.imul(vt,bt)|0,u=u+Math.imul(Z,ft)|0,e=e+Math.imul(Z,yt)|0,e=e+Math.imul(J,ft)|0,l=l+Math.imul(J,yt)|0,u=u+Math.imul($,at)|0,e=e+Math.imul($,wt)|0,e=e+Math.imul(K,at)|0,l=l+Math.imul(K,wt)|0,u=u+Math.imul(O,ht)|0,e=e+Math.imul(O,Mt)|0,e=e+Math.imul(R,ht)|0,l=l+Math.imul(R,Mt)|0,u=u+Math.imul(_,st)|0,e=e+Math.imul(_,xt)|0,e=e+Math.imul(C,st)|0,l=l+Math.imul(C,xt)|0;var ie=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,u=Math.imul(E,U),e=Math.imul(E,X),e=e+Math.imul(w,U)|0,l=Math.imul(w,X),u=u+Math.imul(Q,G)|0,e=e+Math.imul(Q,rt)|0,e=e+Math.imul(ct,G)|0,l=l+Math.imul(ct,rt)|0,u=u+Math.imul(j,it)|0,e=e+Math.imul(j,gt)|0,e=e+Math.imul(dt,it)|0,l=l+Math.imul(dt,gt)|0,u=u+Math.imul(et,nt)|0,e=e+Math.imul(et,bt)|0,e=e+Math.imul(pt,nt)|0,l=l+Math.imul(pt,bt)|0,u=u+Math.imul(tt,ft)|0,e=e+Math.imul(tt,yt)|0,e=e+Math.imul(vt,ft)|0,l=l+Math.imul(vt,yt)|0,u=u+Math.imul(Z,at)|0,e=e+Math.imul(Z,wt)|0,e=e+Math.imul(J,at)|0,l=l+Math.imul(J,wt)|0,u=u+Math.imul($,ht)|0,e=e+Math.imul($,Mt)|0,e=e+Math.imul(K,ht)|0,l=l+Math.imul(K,Mt)|0,u=u+Math.imul(O,st)|0,e=e+Math.imul(O,xt)|0,e=e+Math.imul(R,st)|0,l=l+Math.imul(R,xt)|0,u=u+Math.imul(_,ot)|0,e=e+Math.imul(_,_t)|0,e=e+Math.imul(C,ot)|0,l=l+Math.imul(C,_t)|0;var ne=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,u=Math.imul(T,U),e=Math.imul(T,X),e=e+Math.imul(q,U)|0,l=Math.imul(q,X),u=u+Math.imul(E,G)|0,e=e+Math.imul(E,rt)|0,e=e+Math.imul(w,G)|0,l=l+Math.imul(w,rt)|0,u=u+Math.imul(Q,it)|0,e=e+Math.imul(Q,gt)|0,e=e+Math.imul(ct,it)|0,l=l+Math.imul(ct,gt)|0,u=u+Math.imul(j,nt)|0,e=e+Math.imul(j,bt)|0,e=e+Math.imul(dt,nt)|0,l=l+Math.imul(dt,bt)|0,u=u+Math.imul(et,ft)|0,e=e+Math.imul(et,yt)|0,e=e+Math.imul(pt,ft)|0,l=l+Math.imul(pt,yt)|0,u=u+Math.imul(tt,at)|0,e=e+Math.imul(tt,wt)|0,e=e+Math.imul(vt,at)|0,l=l+Math.imul(vt,wt)|0,u=u+Math.imul(Z,ht)|0,e=e+Math.imul(Z,Mt)|0,e=e+Math.imul(J,ht)|0,l=l+Math.imul(J,Mt)|0,u=u+Math.imul($,st)|0,e=e+Math.imul($,xt)|0,e=e+Math.imul(K,st)|0,l=l+Math.imul(K,xt)|0,u=u+Math.imul(O,ot)|0,e=e+Math.imul(O,_t)|0,e=e+Math.imul(R,ot)|0,l=l+Math.imul(R,_t)|0,u=u+Math.imul(_,ut)|0,e=e+Math.imul(_,St)|0,e=e+Math.imul(C,ut)|0,l=l+Math.imul(C,St)|0;var fe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(fe>>>26)|0,fe&=67108863,u=Math.imul(T,G),e=Math.imul(T,rt),e=e+Math.imul(q,G)|0,l=Math.imul(q,rt),u=u+Math.imul(E,it)|0,e=e+Math.imul(E,gt)|0,e=e+Math.imul(w,it)|0,l=l+Math.imul(w,gt)|0,u=u+Math.imul(Q,nt)|0,e=e+Math.imul(Q,bt)|0,e=e+Math.imul(ct,nt)|0,l=l+Math.imul(ct,bt)|0,u=u+Math.imul(j,ft)|0,e=e+Math.imul(j,yt)|0,e=e+Math.imul(dt,ft)|0,l=l+Math.imul(dt,yt)|0,u=u+Math.imul(et,at)|0,e=e+Math.imul(et,wt)|0,e=e+Math.imul(pt,at)|0,l=l+Math.imul(pt,wt)|0,u=u+Math.imul(tt,ht)|0,e=e+Math.imul(tt,Mt)|0,e=e+Math.imul(vt,ht)|0,l=l+Math.imul(vt,Mt)|0,u=u+Math.imul(Z,st)|0,e=e+Math.imul(Z,xt)|0,e=e+Math.imul(J,st)|0,l=l+Math.imul(J,xt)|0,u=u+Math.imul($,ot)|0,e=e+Math.imul($,_t)|0,e=e+Math.imul(K,ot)|0,l=l+Math.imul(K,_t)|0,u=u+Math.imul(O,ut)|0,e=e+Math.imul(O,St)|0,e=e+Math.imul(R,ut)|0,l=l+Math.imul(R,St)|0;var ae=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,u=Math.imul(T,it),e=Math.imul(T,gt),e=e+Math.imul(q,it)|0,l=Math.imul(q,gt),u=u+Math.imul(E,nt)|0,e=e+Math.imul(E,bt)|0,e=e+Math.imul(w,nt)|0,l=l+Math.imul(w,bt)|0,u=u+Math.imul(Q,ft)|0,e=e+Math.imul(Q,yt)|0,e=e+Math.imul(ct,ft)|0,l=l+Math.imul(ct,yt)|0,u=u+Math.imul(j,at)|0,e=e+Math.imul(j,wt)|0,e=e+Math.imul(dt,at)|0,l=l+Math.imul(dt,wt)|0,u=u+Math.imul(et,ht)|0,e=e+Math.imul(et,Mt)|0,e=e+Math.imul(pt,ht)|0,l=l+Math.imul(pt,Mt)|0,u=u+Math.imul(tt,st)|0,e=e+Math.imul(tt,xt)|0,e=e+Math.imul(vt,st)|0,l=l+Math.imul(vt,xt)|0,u=u+Math.imul(Z,ot)|0,e=e+Math.imul(Z,_t)|0,e=e+Math.imul(J,ot)|0,l=l+Math.imul(J,_t)|0,u=u+Math.imul($,ut)|0,e=e+Math.imul($,St)|0,e=e+Math.imul(K,ut)|0,l=l+Math.imul(K,St)|0;var he=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(he>>>26)|0,he&=67108863,u=Math.imul(T,nt),e=Math.imul(T,bt),e=e+Math.imul(q,nt)|0,l=Math.imul(q,bt),u=u+Math.imul(E,ft)|0,e=e+Math.imul(E,yt)|0,e=e+Math.imul(w,ft)|0,l=l+Math.imul(w,yt)|0,u=u+Math.imul(Q,at)|0,e=e+Math.imul(Q,wt)|0,e=e+Math.imul(ct,at)|0,l=l+Math.imul(ct,wt)|0,u=u+Math.imul(j,ht)|0,e=e+Math.imul(j,Mt)|0,e=e+Math.imul(dt,ht)|0,l=l+Math.imul(dt,Mt)|0,u=u+Math.imul(et,st)|0,e=e+Math.imul(et,xt)|0,e=e+Math.imul(pt,st)|0,l=l+Math.imul(pt,xt)|0,u=u+Math.imul(tt,ot)|0,e=e+Math.imul(tt,_t)|0,e=e+Math.imul(vt,ot)|0,l=l+Math.imul(vt,_t)|0,u=u+Math.imul(Z,ut)|0,e=e+Math.imul(Z,St)|0,e=e+Math.imul(J,ut)|0,l=l+Math.imul(J,St)|0;var se=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(se>>>26)|0,se&=67108863,u=Math.imul(T,ft),e=Math.imul(T,yt),e=e+Math.imul(q,ft)|0,l=Math.imul(q,yt),u=u+Math.imul(E,at)|0,e=e+Math.imul(E,wt)|0,e=e+Math.imul(w,at)|0,l=l+Math.imul(w,wt)|0,u=u+Math.imul(Q,ht)|0,e=e+Math.imul(Q,Mt)|0,e=e+Math.imul(ct,ht)|0,l=l+Math.imul(ct,Mt)|0,u=u+Math.imul(j,st)|0,e=e+Math.imul(j,xt)|0,e=e+Math.imul(dt,st)|0,l=l+Math.imul(dt,xt)|0,u=u+Math.imul(et,ot)|0,e=e+Math.imul(et,_t)|0,e=e+Math.imul(pt,ot)|0,l=l+Math.imul(pt,_t)|0,u=u+Math.imul(tt,ut)|0,e=e+Math.imul(tt,St)|0,e=e+Math.imul(vt,ut)|0,l=l+Math.imul(vt,St)|0;var oe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(oe>>>26)|0,oe&=67108863,u=Math.imul(T,at),e=Math.imul(T,wt),e=e+Math.imul(q,at)|0,l=Math.imul(q,wt),u=u+Math.imul(E,ht)|0,e=e+Math.imul(E,Mt)|0,e=e+Math.imul(w,ht)|0,l=l+Math.imul(w,Mt)|0,u=u+Math.imul(Q,st)|0,e=e+Math.imul(Q,xt)|0,e=e+Math.imul(ct,st)|0,l=l+Math.imul(ct,xt)|0,u=u+Math.imul(j,ot)|0,e=e+Math.imul(j,_t)|0,e=e+Math.imul(dt,ot)|0,l=l+Math.imul(dt,_t)|0,u=u+Math.imul(et,ut)|0,e=e+Math.imul(et,St)|0,e=e+Math.imul(pt,ut)|0,l=l+Math.imul(pt,St)|0;var ue=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ue>>>26)|0,ue&=67108863,u=Math.imul(T,ht),e=Math.imul(T,Mt),e=e+Math.imul(q,ht)|0,l=Math.imul(q,Mt),u=u+Math.imul(E,st)|0,e=e+Math.imul(E,xt)|0,e=e+Math.imul(w,st)|0,l=l+Math.imul(w,xt)|0,u=u+Math.imul(Q,ot)|0,e=e+Math.imul(Q,_t)|0,e=e+Math.imul(ct,ot)|0,l=l+Math.imul(ct,_t)|0,u=u+Math.imul(j,ut)|0,e=e+Math.imul(j,St)|0,e=e+Math.imul(dt,ut)|0,l=l+Math.imul(dt,St)|0;var le=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(le>>>26)|0,le&=67108863,u=Math.imul(T,st),e=Math.imul(T,xt),e=e+Math.imul(q,st)|0,l=Math.imul(q,xt),u=u+Math.imul(E,ot)|0,e=e+Math.imul(E,_t)|0,e=e+Math.imul(w,ot)|0,l=l+Math.imul(w,_t)|0,u=u+Math.imul(Q,ut)|0,e=e+Math.imul(Q,St)|0,e=e+Math.imul(ct,ut)|0,l=l+Math.imul(ct,St)|0;var de=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(de>>>26)|0,de&=67108863,u=Math.imul(T,ot),e=Math.imul(T,_t),e=e+Math.imul(q,ot)|0,l=Math.imul(q,_t),u=u+Math.imul(E,ut)|0,e=e+Math.imul(E,St)|0,e=e+Math.imul(w,ut)|0,l=l+Math.imul(w,St)|0;var ce=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ce>>>26)|0,ce&=67108863,u=Math.imul(T,ut),e=Math.imul(T,St),e=e+Math.imul(q,ut)|0,l=Math.imul(q,St);var ve=(v+u|0)+((e&8191)<<13)|0;return v=(l+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,c[0]=$t,c[1]=Nt,c[2]=jt,c[3]=Qt,c[4]=te,c[5]=ee,c[6]=re,c[7]=ie,c[8]=ne,c[9]=fe,c[10]=ae,c[11]=he,c[12]=se,c[13]=oe,c[14]=ue,c[15]=le,c[16]=de,c[17]=ce,c[18]=ve,v!==0&&(c[19]=v,i.length++),i};Math.imul||(L=D);function W(p,t,r){r.negative=t.negative^p.negative,r.length=p.length+t.length;for(var i=0,a=0,d=0;d<r.length-1;d++){var c=a;a=0;for(var v=i&67108863,u=Math.min(d,t.length-1),e=Math.max(0,d-p.length+1);e<=u;e++){var l=d-e,b=p.words[l]|0,_=t.words[e]|0,C=b*_,F=C&67108863;c=c+(C/67108864|0)|0,F=F+v|0,v=F&67108863,c=c+(F>>>26)|0,a+=c>>>26,c&=67108863}r.words[d]=v,i=c,c=a}return i!==0?r.words[d]=i:r.length--,r.strip()}function z(p,t,r){var i=new N;return i.mulp(p,t,r)}f.prototype.mulTo=function(t,r){var i,a=this.length+t.length;return this.length===10&&t.length===10?i=L(this,t,r):a<63?i=D(this,t,r):a<1024?i=W(this,t,r):i=z(this,t,r),i};function N(p,t){this.x=p,this.y=t}N.prototype.makeRBT=function(t){for(var r=new Array(t),i=f.prototype._countBits(t)-1,a=0;a<t;a++)r[a]=this.revBin(a,i,t);return r},N.prototype.revBin=function(t,r,i){if(t===0||t===i-1)return t;for(var a=0,d=0;d<r;d++)a|=(t&1)<<r-d-1,t>>=1;return a},N.prototype.permute=function(t,r,i,a,d,c){for(var v=0;v<c;v++)a[v]=r[t[v]],d[v]=i[t[v]]},N.prototype.transform=function(t,r,i,a,d,c){this.permute(c,t,r,i,a,d);for(var v=1;v<d;v<<=1)for(var u=v<<1,e=Math.cos(2*Math.PI/u),l=Math.sin(2*Math.PI/u),b=0;b<d;b+=u)for(var _=e,C=l,F=0;F<v;F++){var O=i[b+F],R=a[b+F],P=i[b+F+v],$=a[b+F+v],K=_*P-C*$;$=_*$+C*P,P=K,i[b+F]=O+P,a[b+F]=R+$,i[b+F+v]=O-P,a[b+F+v]=R-$,F!==u&&(K=e*_-l*C,C=e*C+l*_,_=K)}},N.prototype.guessLen13b=function(t,r){var i=Math.max(r,t)|1,a=i&1,d=0;for(i=i/2|0;i;i=i>>>1)d++;return 1<<d+1+a},N.prototype.conjugate=function(t,r,i){if(!(i<=1))for(var a=0;a<i/2;a++){var d=t[a];t[a]=t[i-a-1],t[i-a-1]=d,d=r[a],r[a]=-r[i-a-1],r[i-a-1]=-d}},N.prototype.normalize13b=function(t,r){for(var i=0,a=0;a<r/2;a++){var d=Math.round(t[2*a+1]/r)*8192+Math.round(t[2*a]/r)+i;t[a]=d&67108863,d<67108864?i=0:i=d/67108864|0}return t},N.prototype.convert13b=function(t,r,i,a){for(var d=0,c=0;c<r;c++)d=d+(t[c]|0),i[2*c]=d&8191,d=d>>>13,i[2*c+1]=d&8191,d=d>>>13;for(c=2*r;c<a;++c)i[c]=0;s(d===0),s((d&-8192)===0)},N.prototype.stub=function(t){for(var r=new Array(t),i=0;i<t;i++)r[i]=0;return r},N.prototype.mulp=function(t,r,i){var a=2*this.guessLen13b(t.length,r.length),d=this.makeRBT(a),c=this.stub(a),v=new Array(a),u=new Array(a),e=new Array(a),l=new Array(a),b=new Array(a),_=new Array(a),C=i.words;C.length=a,this.convert13b(t.words,t.length,v,a),this.convert13b(r.words,r.length,l,a),this.transform(v,c,u,e,a,d),this.transform(l,c,b,_,a,d);for(var F=0;F<a;F++){var O=u[F]*b[F]-e[F]*_[F];e[F]=u[F]*_[F]+e[F]*b[F],u[F]=O}return this.conjugate(u,e,a),this.transform(u,e,C,c,a,d),this.conjugate(C,c,a),this.normalize13b(C,a),i.negative=t.negative^r.negative,i.length=t.length+r.length,i.strip()},f.prototype.mul=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},f.prototype.mulf=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),z(this,t,r)},f.prototype.imul=function(t){return this.clone().mulTo(t,this)},f.prototype.imuln=function(t){s(typeof t=="number"),s(t<67108864);for(var r=0,i=0;i<this.length;i++){var a=(this.words[i]|0)*t,d=(a&67108863)+(r&67108863);r>>=26,r+=a/67108864|0,r+=d>>>26,this.words[i]=d&67108863}return r!==0&&(this.words[i]=r,this.length++),this.length=t===0?1:this.length,this},f.prototype.muln=function(t){return this.clone().imuln(t)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(t){var r=I(t);if(r.length===0)return new f(1);for(var i=this,a=0;a<r.length&&r[a]===0;a++,i=i.sqr());if(++a<r.length)for(var d=i.sqr();a<r.length;a++,d=d.sqr())r[a]!==0&&(i=i.mul(d));return i},f.prototype.iushln=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,a=67108863>>>26-r<<26-r,d;if(r!==0){var c=0;for(d=0;d<this.length;d++){var v=this.words[d]&a,u=(this.words[d]|0)-v<<r;this.words[d]=u|c,c=v>>>26-r}c&&(this.words[d]=c,this.length++)}if(i!==0){for(d=this.length-1;d>=0;d--)this.words[d+i]=this.words[d];for(d=0;d<i;d++)this.words[d]=0;this.length+=i}return this.strip()},f.prototype.ishln=function(t){return s(this.negative===0),this.iushln(t)},f.prototype.iushrn=function(t,r,i){s(typeof t=="number"&&t>=0);var a;r?a=(r-r%26)/26:a=0;var d=t%26,c=Math.min((t-d)/26,this.length),v=67108863^67108863>>>d<<d,u=i;if(a-=c,a=Math.max(0,a),u){for(var e=0;e<c;e++)u.words[e]=this.words[e];u.length=c}if(c!==0)if(this.length>c)for(this.length-=c,e=0;e<this.length;e++)this.words[e]=this.words[e+c];else this.words[0]=0,this.length=1;var l=0;for(e=this.length-1;e>=0&&(l!==0||e>=a);e--){var b=this.words[e]|0;this.words[e]=l<<26-d|b>>>d,l=b&v}return u&&l!==0&&(u.words[u.length++]=l),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},f.prototype.ishrn=function(t,r,i){return s(this.negative===0),this.iushrn(t,r,i)},f.prototype.shln=function(t){return this.clone().ishln(t)},f.prototype.ushln=function(t){return this.clone().iushln(t)},f.prototype.shrn=function(t){return this.clone().ishrn(t)},f.prototype.ushrn=function(t){return this.clone().iushrn(t)},f.prototype.testn=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,a=1<<r;if(this.length<=i)return!1;var d=this.words[i];return!!(d&a)},f.prototype.imaskn=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26;if(s(this.negative===0,"imaskn works only with positive numbers"),this.length<=i)return this;if(r!==0&&i++,this.length=Math.min(i,this.length),r!==0){var a=67108863^67108863>>>r<<r;this.words[this.length-1]&=a}return this.strip()},f.prototype.maskn=function(t){return this.clone().imaskn(t)},f.prototype.iaddn=function(t){return s(typeof t=="number"),s(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},f.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},f.prototype.isubn=function(t){if(s(typeof t=="number"),s(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this.strip()},f.prototype.addn=function(t){return this.clone().iaddn(t)},f.prototype.subn=function(t){return this.clone().isubn(t)},f.prototype.iabs=function(){return this.negative=0,this},f.prototype.abs=function(){return this.clone().iabs()},f.prototype._ishlnsubmul=function(t,r,i){var a=t.length+i,d;this._expand(a);var c,v=0;for(d=0;d<t.length;d++){c=(this.words[d+i]|0)+v;var u=(t.words[d]|0)*r;c-=u&67108863,v=(c>>26)-(u/67108864|0),this.words[d+i]=c&67108863}for(;d<this.length-i;d++)c=(this.words[d+i]|0)+v,v=c>>26,this.words[d+i]=c&67108863;if(v===0)return this.strip();for(s(v===-1),v=0,d=0;d<this.length;d++)c=-(this.words[d]|0)+v,v=c>>26,this.words[d]=c&67108863;return this.negative=1,this.strip()},f.prototype._wordDiv=function(t,r){var i=this.length-t.length,a=this.clone(),d=t,c=d.words[d.length-1]|0,v=this._countBits(c);i=26-v,i!==0&&(d=d.ushln(i),a.iushln(i),c=d.words[d.length-1]|0);var u=a.length-d.length,e;if(r!=="mod"){e=new f(null),e.length=u+1,e.words=new Array(e.length);for(var l=0;l<e.length;l++)e.words[l]=0}var b=a.clone()._ishlnsubmul(d,1,u);b.negative===0&&(a=b,e&&(e.words[u]=1));for(var _=u-1;_>=0;_--){var C=(a.words[d.length+_]|0)*67108864+(a.words[d.length+_-1]|0);for(C=Math.min(C/c|0,67108863),a._ishlnsubmul(d,C,_);a.negative!==0;)C--,a.negative=0,a._ishlnsubmul(d,1,_),a.isZero()||(a.negative^=1);e&&(e.words[_]=C)}return e&&e.strip(),a.strip(),r!=="div"&&i!==0&&a.iushrn(i),{div:e||null,mod:a}},f.prototype.divmod=function(t,r,i){if(s(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var a,d,c;return this.negative!==0&&t.negative===0?(c=this.neg().divmod(t,r),r!=="mod"&&(a=c.div.neg()),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.iadd(t)),{div:a,mod:d}):this.negative===0&&t.negative!==0?(c=this.divmod(t.neg(),r),r!=="mod"&&(a=c.div.neg()),{div:a,mod:c.mod}):this.negative&t.negative?(c=this.neg().divmod(t.neg(),r),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.isub(t)),{div:c.div,mod:d}):t.length>this.length||this.cmp(t)<0?{div:new f(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new f(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new f(this.modn(t.words[0]))}:this._wordDiv(t,r)},f.prototype.div=function(t){return this.divmod(t,"div",!1).div},f.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},f.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},f.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var i=r.div.negative!==0?r.mod.isub(t):r.mod,a=t.ushrn(1),d=t.andln(1),c=i.cmp(a);return c<0||d===1&&c===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},f.prototype.modn=function(t){s(t<=67108863);for(var r=(1<<26)%t,i=0,a=this.length-1;a>=0;a--)i=(r*i+(this.words[a]|0))%t;return i},f.prototype.idivn=function(t){s(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var a=(this.words[i]|0)+r*67108864;this.words[i]=a/t|0,r=a%t}return this.strip()},f.prototype.divn=function(t){return this.clone().idivn(t)},f.prototype.egcd=function(t){s(t.negative===0),s(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var a=new f(1),d=new f(0),c=new f(0),v=new f(1),u=0;r.isEven()&&i.isEven();)r.iushrn(1),i.iushrn(1),++u;for(var e=i.clone(),l=r.clone();!r.isZero();){for(var b=0,_=1;!(r.words[0]&_)&&b<26;++b,_<<=1);if(b>0)for(r.iushrn(b);b-- >0;)(a.isOdd()||d.isOdd())&&(a.iadd(e),d.isub(l)),a.iushrn(1),d.iushrn(1);for(var C=0,F=1;!(i.words[0]&F)&&C<26;++C,F<<=1);if(C>0)for(i.iushrn(C);C-- >0;)(c.isOdd()||v.isOdd())&&(c.iadd(e),v.isub(l)),c.iushrn(1),v.iushrn(1);r.cmp(i)>=0?(r.isub(i),a.isub(c),d.isub(v)):(i.isub(r),c.isub(a),v.isub(d))}return{a:c,b:v,gcd:i.iushln(u)}},f.prototype._invmp=function(t){s(t.negative===0),s(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var a=new f(1),d=new f(0),c=i.clone();r.cmpn(1)>0&&i.cmpn(1)>0;){for(var v=0,u=1;!(r.words[0]&u)&&v<26;++v,u<<=1);if(v>0)for(r.iushrn(v);v-- >0;)a.isOdd()&&a.iadd(c),a.iushrn(1);for(var e=0,l=1;!(i.words[0]&l)&&e<26;++e,l<<=1);if(e>0)for(i.iushrn(e);e-- >0;)d.isOdd()&&d.iadd(c),d.iushrn(1);r.cmp(i)>=0?(r.isub(i),a.isub(d)):(i.isub(r),d.isub(a))}var b;return r.cmpn(1)===0?b=a:b=d,b.cmpn(0)<0&&b.iadd(t),b},f.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),i=t.clone();r.negative=0,i.negative=0;for(var a=0;r.isEven()&&i.isEven();a++)r.iushrn(1),i.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;i.isEven();)i.iushrn(1);var d=r.cmp(i);if(d<0){var c=r;r=i,i=c}else if(d===0||i.cmpn(1)===0)break;r.isub(i)}while(!0);return i.iushln(a)},f.prototype.invm=function(t){return this.egcd(t).a.umod(t)},f.prototype.isEven=function(){return(this.words[0]&1)===0},f.prototype.isOdd=function(){return(this.words[0]&1)===1},f.prototype.andln=function(t){return this.words[0]&t},f.prototype.bincn=function(t){s(typeof t=="number");var r=t%26,i=(t-r)/26,a=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=a,this;for(var d=a,c=i;d!==0&&c<this.length;c++){var v=this.words[c]|0;v+=d,d=v>>>26,v&=67108863,this.words[c]=v}return d!==0&&(this.words[c]=d,this.length++),this},f.prototype.isZero=function(){return this.length===1&&this.words[0]===0},f.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return-1;if(this.negative===0&&r)return 1;this.strip();var i;if(this.length>1)i=1;else{r&&(t=-t),s(t<=67108863,"Number is too big");var a=this.words[0]|0;i=a===t?0:a<t?-1:1}return this.negative!==0?-i|0:i},f.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return-1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},f.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var r=0,i=this.length-1;i>=0;i--){var a=this.words[i]|0,d=t.words[i]|0;if(a!==d){a<d?r=-1:a>d&&(r=1);break}}return r},f.prototype.gtn=function(t){return this.cmpn(t)===1},f.prototype.gt=function(t){return this.cmp(t)===1},f.prototype.gten=function(t){return this.cmpn(t)>=0},f.prototype.gte=function(t){return this.cmp(t)>=0},f.prototype.ltn=function(t){return this.cmpn(t)===-1},f.prototype.lt=function(t){return this.cmp(t)===-1},f.prototype.lten=function(t){return this.cmpn(t)<=0},f.prototype.lte=function(t){return this.cmp(t)<=0},f.prototype.eqn=function(t){return this.cmpn(t)===0},f.prototype.eq=function(t){return this.cmp(t)===0},f.red=function(t){return new Y(t)},f.prototype.toRed=function(t){return s(!this.red,"Already a number in reduction context"),s(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},f.prototype.fromRed=function(){return s(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(t){return this.red=t,this},f.prototype.forceRed=function(t){return s(!this.red,"Already a number in reduction context"),this._forceRed(t)},f.prototype.redAdd=function(t){return s(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},f.prototype.redIAdd=function(t){return s(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},f.prototype.redSub=function(t){return s(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},f.prototype.redISub=function(t){return s(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},f.prototype.redShl=function(t){return s(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},f.prototype.redMul=function(t){return s(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},f.prototype.redIMul=function(t){return s(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},f.prototype.redSqr=function(){return s(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return s(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return s(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return s(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return s(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(t){return s(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var lt={k256:null,p224:null,p192:null,p25519:null};function H(p,t){this.name=p,this.p=new f(t,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}H.prototype._tmp=function(){var t=new f(null);return t.words=new Array(Math.ceil(this.n/13)),t},H.prototype.ireduce=function(t){var r=t,i;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),i=r.bitLength();while(i>this.n);var a=i<this.n?-1:r.ucmp(this.p);return a===0?(r.words[0]=0,r.length=1):a>0?r.isub(this.p):r.strip!==void 0?r.strip():r._strip(),r},H.prototype.split=function(t,r){t.iushrn(this.n,0,r)},H.prototype.imulK=function(t){return t.imul(this.k)};function At(){H.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}m(At,H),At.prototype.split=function(t,r){for(var i=4194303,a=Math.min(t.length,9),d=0;d<a;d++)r.words[d]=t.words[d];if(r.length=a,t.length<=9){t.words[0]=0,t.length=1;return}var c=t.words[9];for(r.words[r.length++]=c&i,d=10;d<t.length;d++){var v=t.words[d]|0;t.words[d-10]=(v&i)<<4|c>>>22,c=v}c>>>=22,t.words[d-10]=c,c===0&&t.length>10?t.length-=10:t.length-=9},At.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,i=0;i<t.length;i++){var a=t.words[i]|0;r+=a*977,t.words[i]=r&67108863,r=a*64+(r/67108864|0)}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function Bt(){H.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}m(Bt,H);function Ct(){H.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}m(Ct,H);function Et(){H.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}m(Et,H),Et.prototype.imulK=function(t){for(var r=0,i=0;i<t.length;i++){var a=(t.words[i]|0)*19+r,d=a&67108863;a>>>=26,t.words[i]=d,r=a}return r!==0&&(t.words[t.length++]=r),t},f._prime=function(t){if(lt[t])return lt[t];var r;if(t==="k256")r=new At;else if(t==="p224")r=new Bt;else if(t==="p192")r=new Ct;else if(t==="p25519")r=new Et;else throw new Error("Unknown prime "+t);return lt[t]=r,r};function Y(p){if(typeof p=="string"){var t=f._prime(p);this.m=t.p,this.prime=t}else s(p.gtn(1),"modulus must be greater than 1"),this.m=p,this.prime=null}Y.prototype._verify1=function(t){s(t.negative===0,"red works only with positives"),s(t.red,"red works only with red numbers")},Y.prototype._verify2=function(t,r){s((t.negative|r.negative)===0,"red works only with positives"),s(t.red&&t.red===r.red,"red works only with red numbers")},Y.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},Y.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},Y.prototype.add=function(t,r){this._verify2(t,r);var i=t.add(r);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},Y.prototype.iadd=function(t,r){this._verify2(t,r);var i=t.iadd(r);return i.cmp(this.m)>=0&&i.isub(this.m),i},Y.prototype.sub=function(t,r){this._verify2(t,r);var i=t.sub(r);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},Y.prototype.isub=function(t,r){this._verify2(t,r);var i=t.isub(r);return i.cmpn(0)<0&&i.iadd(this.m),i},Y.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},Y.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},Y.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},Y.prototype.isqr=function(t){return this.imul(t,t.clone())},Y.prototype.sqr=function(t){return this.mul(t,t)},Y.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(s(r%2===1),r===3){var i=this.m.add(new f(1)).iushrn(2);return this.pow(t,i)}for(var a=this.m.subn(1),d=0;!a.isZero()&&a.andln(1)===0;)d++,a.iushrn(1);s(!a.isZero());var c=new f(1).toRed(this),v=c.redNeg(),u=this.m.subn(1).iushrn(1),e=this.m.bitLength();for(e=new f(2*e*e).toRed(this);this.pow(e,u).cmp(v)!==0;)e.redIAdd(v);for(var l=this.pow(e,a),b=this.pow(t,a.addn(1).iushrn(1)),_=this.pow(t,a),C=d;_.cmp(c)!==0;){for(var F=_,O=0;F.cmp(c)!==0;O++)F=F.redSqr();s(O<C);var R=this.pow(l,new f(1).iushln(C-O-1));b=b.redMul(R),l=R.redSqr(),_=_.redMul(l),C=O}return b},Y.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},Y.prototype.pow=function(t,r){if(r.isZero())return new f(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var i=4,a=new Array(1<<i);a[0]=new f(1).toRed(this),a[1]=t;for(var d=2;d<a.length;d++)a[d]=this.mul(a[d-1],t);var c=a[0],v=0,u=0,e=r.bitLength()%26;for(e===0&&(e=26),d=r.length-1;d>=0;d--){for(var l=r.words[d],b=e-1;b>=0;b--){var _=l>>b&1;if(c!==a[0]&&(c=this.sqr(c)),_===0&&v===0){u=0;continue}v<<=1,v|=_,u++,!(u!==i&&(d!==0||b!==0))&&(c=this.mul(c,a[v]),u=0,v=0)}e=26}return c},Y.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},Y.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},f.mont=function(t){return new kt(t)};function kt(p){Y.call(this,p),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}m(kt,Y),kt.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},kt.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},kt.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),a=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(a).iushrn(this.shift),c=d;return d.cmp(this.m)>=0?c=d.isub(this.m):d.cmpn(0)<0&&(c=d.iadd(this.m)),c._forceRed(this)},kt.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var i=t.mul(r),a=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(a).iushrn(this.shift),c=d;return d.cmp(this.m)>=0?c=d.isub(this.m):d.cmpn(0)<0&&(c=d.iadd(this.m)),c._forceRed(this)},kt.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(h,Gt)})(Y0);var Cm=Y0.exports,Gf,lh;function qm(){if(lh)return Gf;lh=1;var h=Z0(),n=Cm;Gf=function(g){return new s(g)};var o={secp256k1:{name:"secp256k1",byteLength:32},secp224r1:{name:"p224",byteLength:28},prime256v1:{name:"p256",byteLength:32},prime192v1:{name:"p192",byteLength:24},ed25519:{name:"ed25519",byteLength:32},secp384r1:{name:"p384",byteLength:48},secp521r1:{name:"p521",byteLength:66}};o.p224=o.secp224r1,o.p256=o.secp256r1=o.prime256v1,o.p192=o.secp192r1=o.prime192v1,o.p384=o.secp384r1,o.p521=o.secp521r1;function s(f){this.curveType=o[f],this.curveType||(this.curveType={name:f}),this.curve=new h.ec(this.curveType.name),this.keys=void 0}s.prototype.generateKeys=function(f,g){return this.keys=this.curve.genKeyPair(),this.getPublicKey(f,g)},s.prototype.computeSecret=function(f,g,y){g=g||"utf8",mt.isBuffer(f)||(f=new mt(f,g));var S=this.curve.keyFromPublic(f).getPublic(),B=S.mul(this.keys.getPrivate()).getX();return m(B,y,this.curveType.byteLength)},s.prototype.getPublicKey=function(f,g){var y=this.keys.getPublic(g==="compressed",!0);return g==="hybrid"&&(y[y.length-1]%2?y[0]=7:y[0]=6),m(y,f)},s.prototype.getPrivateKey=function(f){return m(this.keys.getPrivate(),f)},s.prototype.setPublicKey=function(f,g){return g=g||"utf8",mt.isBuffer(f)||(f=new mt(f,g)),this.keys._importPublic(f),this},s.prototype.setPrivateKey=function(f,g){g=g||"utf8",mt.isBuffer(f)||(f=new mt(f,g));var y=new n(f);return y=y.toString(16),this.keys=this.curve.genKeyPair(),this.keys._importPrivate(y),this};function m(f,g,y){Array.isArray(f)||(f=f.toArray());var S=new mt(f);if(y&&S.length<y){var B=new mt(y-S.length);B.fill(0),S=mt.concat([B,S])}return g?S.toString(g):S}return Gf}var Lo={},Fm=Gi,v0=Ot.Buffer,Oo=function(h,n){for(var o=v0.alloc(0),s=0,m;o.length<n;)m=Pm(s++),o=v0.concat([o,Fm("sha1").update(h).update(m).digest()]);return o.slice(0,n)};function Pm(h){var n=v0.allocUnsafe(4);return n.writeUInt32BE(h,0),n}var zo=function(n,o){for(var s=n.length,m=-1;++m<s;)n[m]^=o[m];return n},J0={exports:{}};J0.exports;(function(h){(function(n,o){function s(p,t){if(!p)throw new Error(t||"Assertion failed")}function m(p,t){p.super_=t;var r=function(){};r.prototype=t.prototype,p.prototype=new r,p.prototype.constructor=p}function f(p,t,r){if(f.isBN(p))return p;this.negative=0,this.words=null,this.length=0,this.red=null,p!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(p||0,t||10,r||"be"))}typeof n=="object"?n.exports=f:o.BN=f,f.BN=f,f.wordSize=26;var g;try{typeof window!="undefined"&&typeof window.Buffer!="undefined"?g=window.Buffer:g=Pe.Buffer}catch(p){}f.isBN=function(t){return t instanceof f?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===f.wordSize&&Array.isArray(t.words)},f.max=function(t,r){return t.cmp(r)>0?t:r},f.min=function(t,r){return t.cmp(r)<0?t:r},f.prototype._init=function(t,r,i){if(typeof t=="number")return this._initNumber(t,r,i);if(typeof t=="object")return this._initArray(t,r,i);r==="hex"&&(r=16),s(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var a=0;t[0]==="-"&&(a++,this.negative=1),a<t.length&&(r===16?this._parseHex(t,a,i):(this._parseBase(t,r,a),i==="le"&&this._initArray(this.toArray(),r,i)))},f.prototype._initNumber=function(t,r,i){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(s(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),i==="le"&&this._initArray(this.toArray(),r,i)},f.prototype._initArray=function(t,r,i){if(s(typeof t.length=="number"),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 a=0;a<this.length;a++)this.words[a]=0;var d,c,v=0;if(i==="be")for(a=t.length-1,d=0;a>=0;a-=3)c=t[a]|t[a-1]<<8|t[a-2]<<16,this.words[d]|=c<<v&67108863,this.words[d+1]=c>>>26-v&67108863,v+=24,v>=26&&(v-=26,d++);else if(i==="le")for(a=0,d=0;a<t.length;a+=3)c=t[a]|t[a+1]<<8|t[a+2]<<16,this.words[d]|=c<<v&67108863,this.words[d+1]=c>>>26-v&67108863,v+=24,v>=26&&(v-=26,d++);return this.strip()};function y(p,t){var r=p.charCodeAt(t);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function S(p,t,r){var i=y(p,r);return r-1>=t&&(i|=y(p,r-1)<<4),i}f.prototype._parseHex=function(t,r,i){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var a=0;a<this.length;a++)this.words[a]=0;var d=0,c=0,v;if(i==="be")for(a=t.length-1;a>=r;a-=2)v=S(t,r,a)<<d,this.words[c]|=v&67108863,d>=18?(d-=18,c+=1,this.words[c]|=v>>>26):d+=8;else{var u=t.length-r;for(a=u%2===0?r+1:r;a<t.length;a+=2)v=S(t,r,a)<<d,this.words[c]|=v&67108863,d>=18?(d-=18,c+=1,this.words[c]|=v>>>26):d+=8}this.strip()};function B(p,t,r,i){for(var a=0,d=Math.min(p.length,r),c=t;c<d;c++){var v=p.charCodeAt(c)-48;a*=i,v>=49?a+=v-49+10:v>=17?a+=v-17+10:a+=v}return a}f.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var a=0,d=1;d<=67108863;d*=r)a++;a--,d=d/r|0;for(var c=t.length-i,v=c%a,u=Math.min(c,c-v)+i,e=0,l=i;l<u;l+=a)e=B(t,l,l+a,r),this.imuln(d),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);if(v!==0){var b=1;for(e=B(t,l,t.length,r),l=0;l<v;l++)b*=r;this.imuln(b),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e)}this.strip()},f.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red},f.prototype.clone=function(){var t=new f(null);return this.copy(t),t},f.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},f.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},f.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},f.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var M=["","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"],x=[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],k=[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];f.prototype.toString=function(t,r){t=t||10,r=r|0||1;var i;if(t===16||t==="hex"){i="";for(var a=0,d=0,c=0;c<this.length;c++){var v=this.words[c],u=((v<<a|d)&16777215).toString(16);d=v>>>24-a&16777215,a+=2,a>=26&&(a-=26,c--),d!==0||c!==this.length-1?i=M[6-u.length]+u+i:i=u+i}for(d!==0&&(i=d.toString(16)+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var e=x[t],l=k[t];i="";var b=this.clone();for(b.negative=0;!b.isZero();){var _=b.modn(l).toString(t);b=b.idivn(l),b.isZero()?i=_+i:i=M[e-_.length]+_+i}for(this.isZero()&&(i="0"+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}s(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&s(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(t,r){return s(typeof g!="undefined"),this.toArrayLike(g,t,r)},f.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},f.prototype.toArrayLike=function(t,r,i){var a=this.byteLength(),d=i||Math.max(1,a);s(a<=d,"byte array longer than desired length"),s(d>0,"Requested array length <= 0"),this.strip();var c=r==="le",v=new t(d),u,e,l=this.clone();if(c){for(e=0;!l.isZero();e++)u=l.andln(255),l.iushrn(8),v[e]=u;for(;e<d;e++)v[e]=0}else{for(e=0;e<d-a;e++)v[e]=0;for(e=0;!l.isZero();e++)u=l.andln(255),l.iushrn(8),v[d-e-1]=u}return v},Math.clz32?f.prototype._countBits=function(t){return 32-Math.clz32(t)}:f.prototype._countBits=function(t){var r=t,i=0;return r>=4096&&(i+=13,r>>>=13),r>=64&&(i+=7,r>>>=7),r>=8&&(i+=4,r>>>=4),r>=2&&(i+=2,r>>>=2),i+r},f.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,i=0;return r&8191||(i+=13,r>>>=13),r&127||(i+=7,r>>>=7),r&15||(i+=4,r>>>=4),r&3||(i+=2,r>>>=2),r&1||i++,i},f.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return(this.length-1)*26+r};function I(p){for(var t=new Array(p.bitLength()),r=0;r<t.length;r++){var i=r/26|0,a=r%26;t[r]=(p.words[i]&1<<a)>>>a}return t}f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var i=this._zeroBits(this.words[r]);if(t+=i,i!==26)break}return t},f.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},f.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},f.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},f.prototype.isNeg=function(){return this.negative!==0},f.prototype.neg=function(){return this.clone().ineg()},f.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},f.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this.strip()},f.prototype.ior=function(t){return s((this.negative|t.negative)===0),this.iuor(t)},f.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},f.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},f.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var i=0;i<r.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=r.length,this.strip()},f.prototype.iand=function(t){return s((this.negative|t.negative)===0),this.iuand(t)},f.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},f.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},f.prototype.iuxor=function(t){var r,i;this.length>t.length?(r=this,i=t):(r=t,i=this);for(var a=0;a<i.length;a++)this.words[a]=r.words[a]^i.words[a];if(this!==r)for(;a<r.length;a++)this.words[a]=r.words[a];return this.length=r.length,this.strip()},f.prototype.ixor=function(t){return s((this.negative|t.negative)===0),this.iuxor(t)},f.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},f.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},f.prototype.inotn=function(t){s(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,i=t%26;this._expand(r),i>0&&r--;for(var a=0;a<r;a++)this.words[a]=~this.words[a]&67108863;return i>0&&(this.words[a]=~this.words[a]&67108863>>26-i),this.strip()},f.prototype.notn=function(t){return this.clone().inotn(t)},f.prototype.setn=function(t,r){s(typeof t=="number"&&t>=0);var i=t/26|0,a=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<a:this.words[i]=this.words[i]&~(1<<a),this.strip()},f.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var i,a;this.length>t.length?(i=this,a=t):(i=t,a=this);for(var d=0,c=0;c<a.length;c++)r=(i.words[c]|0)+(a.words[c]|0)+d,this.words[c]=r&67108863,d=r>>>26;for(;d!==0&&c<i.length;c++)r=(i.words[c]|0)+d,this.words[c]=r&67108863,d=r>>>26;if(this.length=i.length,d!==0)this.words[this.length]=d,this.length++;else if(i!==this)for(;c<i.length;c++)this.words[c]=i.words[c];return this},f.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},f.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i=this.cmp(t);if(i===0)return this.negative=0,this.length=1,this.words[0]=0,this;var a,d;i>0?(a=this,d=t):(a=t,d=this);for(var c=0,v=0;v<d.length;v++)r=(a.words[v]|0)-(d.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;for(;c!==0&&v<a.length;v++)r=(a.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;if(c===0&&v<a.length&&a!==this)for(;v<a.length;v++)this.words[v]=a.words[v];return this.length=Math.max(this.length,v),a!==this&&(this.negative=1),this.strip()},f.prototype.sub=function(t){return this.clone().isub(t)};function D(p,t,r){r.negative=t.negative^p.negative;var i=p.length+t.length|0;r.length=i,i=i-1|0;var a=p.words[0]|0,d=t.words[0]|0,c=a*d,v=c&67108863,u=c/67108864|0;r.words[0]=v;for(var e=1;e<i;e++){for(var l=u>>>26,b=u&67108863,_=Math.min(e,t.length-1),C=Math.max(0,e-p.length+1);C<=_;C++){var F=e-C|0;a=p.words[F]|0,d=t.words[C]|0,c=a*d+b,l+=c/67108864|0,b=c&67108863}r.words[e]=b|0,u=l|0}return u!==0?r.words[e]=u|0:r.length--,r.strip()}var L=function(t,r,i){var a=t.words,d=r.words,c=i.words,v=0,u,e,l,b=a[0]|0,_=b&8191,C=b>>>13,F=a[1]|0,O=F&8191,R=F>>>13,P=a[2]|0,$=P&8191,K=P>>>13,It=a[3]|0,Z=It&8191,J=It>>>13,qt=a[4]|0,tt=qt&8191,vt=qt>>>13,Dt=a[5]|0,et=Dt&8191,pt=Dt>>>13,Pt=a[6]|0,j=Pt&8191,dt=Pt>>>13,Ft=a[7]|0,Q=Ft&8191,ct=Ft>>>13,Lt=a[8]|0,E=Lt&8191,w=Lt>>>13,A=a[9]|0,T=A&8191,q=A>>>13,V=d[0]|0,U=V&8191,X=V>>>13,Tt=d[1]|0,G=Tt&8191,rt=Tt>>>13,Rt=d[2]|0,it=Rt&8191,gt=Rt>>>13,zt=d[3]|0,nt=zt&8191,bt=zt>>>13,Kt=d[4]|0,ft=Kt&8191,yt=Kt>>>13,Ht=d[5]|0,at=Ht&8191,wt=Ht>>>13,Zt=d[6]|0,ht=Zt&8191,Mt=Zt>>>13,Wt=d[7]|0,st=Wt&8191,xt=Wt>>>13,Vt=d[8]|0,ot=Vt&8191,_t=Vt>>>13,Yt=d[9]|0,ut=Yt&8191,St=Yt>>>13;i.negative=t.negative^r.negative,i.length=19,u=Math.imul(_,U),e=Math.imul(_,X),e=e+Math.imul(C,U)|0,l=Math.imul(C,X);var $t=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+($t>>>26)|0,$t&=67108863,u=Math.imul(O,U),e=Math.imul(O,X),e=e+Math.imul(R,U)|0,l=Math.imul(R,X),u=u+Math.imul(_,G)|0,e=e+Math.imul(_,rt)|0,e=e+Math.imul(C,G)|0,l=l+Math.imul(C,rt)|0;var Nt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,u=Math.imul($,U),e=Math.imul($,X),e=e+Math.imul(K,U)|0,l=Math.imul(K,X),u=u+Math.imul(O,G)|0,e=e+Math.imul(O,rt)|0,e=e+Math.imul(R,G)|0,l=l+Math.imul(R,rt)|0,u=u+Math.imul(_,it)|0,e=e+Math.imul(_,gt)|0,e=e+Math.imul(C,it)|0,l=l+Math.imul(C,gt)|0;var jt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(jt>>>26)|0,jt&=67108863,u=Math.imul(Z,U),e=Math.imul(Z,X),e=e+Math.imul(J,U)|0,l=Math.imul(J,X),u=u+Math.imul($,G)|0,e=e+Math.imul($,rt)|0,e=e+Math.imul(K,G)|0,l=l+Math.imul(K,rt)|0,u=u+Math.imul(O,it)|0,e=e+Math.imul(O,gt)|0,e=e+Math.imul(R,it)|0,l=l+Math.imul(R,gt)|0,u=u+Math.imul(_,nt)|0,e=e+Math.imul(_,bt)|0,e=e+Math.imul(C,nt)|0,l=l+Math.imul(C,bt)|0;var Qt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,u=Math.imul(tt,U),e=Math.imul(tt,X),e=e+Math.imul(vt,U)|0,l=Math.imul(vt,X),u=u+Math.imul(Z,G)|0,e=e+Math.imul(Z,rt)|0,e=e+Math.imul(J,G)|0,l=l+Math.imul(J,rt)|0,u=u+Math.imul($,it)|0,e=e+Math.imul($,gt)|0,e=e+Math.imul(K,it)|0,l=l+Math.imul(K,gt)|0,u=u+Math.imul(O,nt)|0,e=e+Math.imul(O,bt)|0,e=e+Math.imul(R,nt)|0,l=l+Math.imul(R,bt)|0,u=u+Math.imul(_,ft)|0,e=e+Math.imul(_,yt)|0,e=e+Math.imul(C,ft)|0,l=l+Math.imul(C,yt)|0;var te=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(te>>>26)|0,te&=67108863,u=Math.imul(et,U),e=Math.imul(et,X),e=e+Math.imul(pt,U)|0,l=Math.imul(pt,X),u=u+Math.imul(tt,G)|0,e=e+Math.imul(tt,rt)|0,e=e+Math.imul(vt,G)|0,l=l+Math.imul(vt,rt)|0,u=u+Math.imul(Z,it)|0,e=e+Math.imul(Z,gt)|0,e=e+Math.imul(J,it)|0,l=l+Math.imul(J,gt)|0,u=u+Math.imul($,nt)|0,e=e+Math.imul($,bt)|0,e=e+Math.imul(K,nt)|0,l=l+Math.imul(K,bt)|0,u=u+Math.imul(O,ft)|0,e=e+Math.imul(O,yt)|0,e=e+Math.imul(R,ft)|0,l=l+Math.imul(R,yt)|0,u=u+Math.imul(_,at)|0,e=e+Math.imul(_,wt)|0,e=e+Math.imul(C,at)|0,l=l+Math.imul(C,wt)|0;var ee=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,u=Math.imul(j,U),e=Math.imul(j,X),e=e+Math.imul(dt,U)|0,l=Math.imul(dt,X),u=u+Math.imul(et,G)|0,e=e+Math.imul(et,rt)|0,e=e+Math.imul(pt,G)|0,l=l+Math.imul(pt,rt)|0,u=u+Math.imul(tt,it)|0,e=e+Math.imul(tt,gt)|0,e=e+Math.imul(vt,it)|0,l=l+Math.imul(vt,gt)|0,u=u+Math.imul(Z,nt)|0,e=e+Math.imul(Z,bt)|0,e=e+Math.imul(J,nt)|0,l=l+Math.imul(J,bt)|0,u=u+Math.imul($,ft)|0,e=e+Math.imul($,yt)|0,e=e+Math.imul(K,ft)|0,l=l+Math.imul(K,yt)|0,u=u+Math.imul(O,at)|0,e=e+Math.imul(O,wt)|0,e=e+Math.imul(R,at)|0,l=l+Math.imul(R,wt)|0,u=u+Math.imul(_,ht)|0,e=e+Math.imul(_,Mt)|0,e=e+Math.imul(C,ht)|0,l=l+Math.imul(C,Mt)|0;var re=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(re>>>26)|0,re&=67108863,u=Math.imul(Q,U),e=Math.imul(Q,X),e=e+Math.imul(ct,U)|0,l=Math.imul(ct,X),u=u+Math.imul(j,G)|0,e=e+Math.imul(j,rt)|0,e=e+Math.imul(dt,G)|0,l=l+Math.imul(dt,rt)|0,u=u+Math.imul(et,it)|0,e=e+Math.imul(et,gt)|0,e=e+Math.imul(pt,it)|0,l=l+Math.imul(pt,gt)|0,u=u+Math.imul(tt,nt)|0,e=e+Math.imul(tt,bt)|0,e=e+Math.imul(vt,nt)|0,l=l+Math.imul(vt,bt)|0,u=u+Math.imul(Z,ft)|0,e=e+Math.imul(Z,yt)|0,e=e+Math.imul(J,ft)|0,l=l+Math.imul(J,yt)|0,u=u+Math.imul($,at)|0,e=e+Math.imul($,wt)|0,e=e+Math.imul(K,at)|0,l=l+Math.imul(K,wt)|0,u=u+Math.imul(O,ht)|0,e=e+Math.imul(O,Mt)|0,e=e+Math.imul(R,ht)|0,l=l+Math.imul(R,Mt)|0,u=u+Math.imul(_,st)|0,e=e+Math.imul(_,xt)|0,e=e+Math.imul(C,st)|0,l=l+Math.imul(C,xt)|0;var ie=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,u=Math.imul(E,U),e=Math.imul(E,X),e=e+Math.imul(w,U)|0,l=Math.imul(w,X),u=u+Math.imul(Q,G)|0,e=e+Math.imul(Q,rt)|0,e=e+Math.imul(ct,G)|0,l=l+Math.imul(ct,rt)|0,u=u+Math.imul(j,it)|0,e=e+Math.imul(j,gt)|0,e=e+Math.imul(dt,it)|0,l=l+Math.imul(dt,gt)|0,u=u+Math.imul(et,nt)|0,e=e+Math.imul(et,bt)|0,e=e+Math.imul(pt,nt)|0,l=l+Math.imul(pt,bt)|0,u=u+Math.imul(tt,ft)|0,e=e+Math.imul(tt,yt)|0,e=e+Math.imul(vt,ft)|0,l=l+Math.imul(vt,yt)|0,u=u+Math.imul(Z,at)|0,e=e+Math.imul(Z,wt)|0,e=e+Math.imul(J,at)|0,l=l+Math.imul(J,wt)|0,u=u+Math.imul($,ht)|0,e=e+Math.imul($,Mt)|0,e=e+Math.imul(K,ht)|0,l=l+Math.imul(K,Mt)|0,u=u+Math.imul(O,st)|0,e=e+Math.imul(O,xt)|0,e=e+Math.imul(R,st)|0,l=l+Math.imul(R,xt)|0,u=u+Math.imul(_,ot)|0,e=e+Math.imul(_,_t)|0,e=e+Math.imul(C,ot)|0,l=l+Math.imul(C,_t)|0;var ne=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,u=Math.imul(T,U),e=Math.imul(T,X),e=e+Math.imul(q,U)|0,l=Math.imul(q,X),u=u+Math.imul(E,G)|0,e=e+Math.imul(E,rt)|0,e=e+Math.imul(w,G)|0,l=l+Math.imul(w,rt)|0,u=u+Math.imul(Q,it)|0,e=e+Math.imul(Q,gt)|0,e=e+Math.imul(ct,it)|0,l=l+Math.imul(ct,gt)|0,u=u+Math.imul(j,nt)|0,e=e+Math.imul(j,bt)|0,e=e+Math.imul(dt,nt)|0,l=l+Math.imul(dt,bt)|0,u=u+Math.imul(et,ft)|0,e=e+Math.imul(et,yt)|0,e=e+Math.imul(pt,ft)|0,l=l+Math.imul(pt,yt)|0,u=u+Math.imul(tt,at)|0,e=e+Math.imul(tt,wt)|0,e=e+Math.imul(vt,at)|0,l=l+Math.imul(vt,wt)|0,u=u+Math.imul(Z,ht)|0,e=e+Math.imul(Z,Mt)|0,e=e+Math.imul(J,ht)|0,l=l+Math.imul(J,Mt)|0,u=u+Math.imul($,st)|0,e=e+Math.imul($,xt)|0,e=e+Math.imul(K,st)|0,l=l+Math.imul(K,xt)|0,u=u+Math.imul(O,ot)|0,e=e+Math.imul(O,_t)|0,e=e+Math.imul(R,ot)|0,l=l+Math.imul(R,_t)|0,u=u+Math.imul(_,ut)|0,e=e+Math.imul(_,St)|0,e=e+Math.imul(C,ut)|0,l=l+Math.imul(C,St)|0;var fe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(fe>>>26)|0,fe&=67108863,u=Math.imul(T,G),e=Math.imul(T,rt),e=e+Math.imul(q,G)|0,l=Math.imul(q,rt),u=u+Math.imul(E,it)|0,e=e+Math.imul(E,gt)|0,e=e+Math.imul(w,it)|0,l=l+Math.imul(w,gt)|0,u=u+Math.imul(Q,nt)|0,e=e+Math.imul(Q,bt)|0,e=e+Math.imul(ct,nt)|0,l=l+Math.imul(ct,bt)|0,u=u+Math.imul(j,ft)|0,e=e+Math.imul(j,yt)|0,e=e+Math.imul(dt,ft)|0,l=l+Math.imul(dt,yt)|0,u=u+Math.imul(et,at)|0,e=e+Math.imul(et,wt)|0,e=e+Math.imul(pt,at)|0,l=l+Math.imul(pt,wt)|0,u=u+Math.imul(tt,ht)|0,e=e+Math.imul(tt,Mt)|0,e=e+Math.imul(vt,ht)|0,l=l+Math.imul(vt,Mt)|0,u=u+Math.imul(Z,st)|0,e=e+Math.imul(Z,xt)|0,e=e+Math.imul(J,st)|0,l=l+Math.imul(J,xt)|0,u=u+Math.imul($,ot)|0,e=e+Math.imul($,_t)|0,e=e+Math.imul(K,ot)|0,l=l+Math.imul(K,_t)|0,u=u+Math.imul(O,ut)|0,e=e+Math.imul(O,St)|0,e=e+Math.imul(R,ut)|0,l=l+Math.imul(R,St)|0;var ae=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,u=Math.imul(T,it),e=Math.imul(T,gt),e=e+Math.imul(q,it)|0,l=Math.imul(q,gt),u=u+Math.imul(E,nt)|0,e=e+Math.imul(E,bt)|0,e=e+Math.imul(w,nt)|0,l=l+Math.imul(w,bt)|0,u=u+Math.imul(Q,ft)|0,e=e+Math.imul(Q,yt)|0,e=e+Math.imul(ct,ft)|0,l=l+Math.imul(ct,yt)|0,u=u+Math.imul(j,at)|0,e=e+Math.imul(j,wt)|0,e=e+Math.imul(dt,at)|0,l=l+Math.imul(dt,wt)|0,u=u+Math.imul(et,ht)|0,e=e+Math.imul(et,Mt)|0,e=e+Math.imul(pt,ht)|0,l=l+Math.imul(pt,Mt)|0,u=u+Math.imul(tt,st)|0,e=e+Math.imul(tt,xt)|0,e=e+Math.imul(vt,st)|0,l=l+Math.imul(vt,xt)|0,u=u+Math.imul(Z,ot)|0,e=e+Math.imul(Z,_t)|0,e=e+Math.imul(J,ot)|0,l=l+Math.imul(J,_t)|0,u=u+Math.imul($,ut)|0,e=e+Math.imul($,St)|0,e=e+Math.imul(K,ut)|0,l=l+Math.imul(K,St)|0;var he=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(he>>>26)|0,he&=67108863,u=Math.imul(T,nt),e=Math.imul(T,bt),e=e+Math.imul(q,nt)|0,l=Math.imul(q,bt),u=u+Math.imul(E,ft)|0,e=e+Math.imul(E,yt)|0,e=e+Math.imul(w,ft)|0,l=l+Math.imul(w,yt)|0,u=u+Math.imul(Q,at)|0,e=e+Math.imul(Q,wt)|0,e=e+Math.imul(ct,at)|0,l=l+Math.imul(ct,wt)|0,u=u+Math.imul(j,ht)|0,e=e+Math.imul(j,Mt)|0,e=e+Math.imul(dt,ht)|0,l=l+Math.imul(dt,Mt)|0,u=u+Math.imul(et,st)|0,e=e+Math.imul(et,xt)|0,e=e+Math.imul(pt,st)|0,l=l+Math.imul(pt,xt)|0,u=u+Math.imul(tt,ot)|0,e=e+Math.imul(tt,_t)|0,e=e+Math.imul(vt,ot)|0,l=l+Math.imul(vt,_t)|0,u=u+Math.imul(Z,ut)|0,e=e+Math.imul(Z,St)|0,e=e+Math.imul(J,ut)|0,l=l+Math.imul(J,St)|0;var se=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(se>>>26)|0,se&=67108863,u=Math.imul(T,ft),e=Math.imul(T,yt),e=e+Math.imul(q,ft)|0,l=Math.imul(q,yt),u=u+Math.imul(E,at)|0,e=e+Math.imul(E,wt)|0,e=e+Math.imul(w,at)|0,l=l+Math.imul(w,wt)|0,u=u+Math.imul(Q,ht)|0,e=e+Math.imul(Q,Mt)|0,e=e+Math.imul(ct,ht)|0,l=l+Math.imul(ct,Mt)|0,u=u+Math.imul(j,st)|0,e=e+Math.imul(j,xt)|0,e=e+Math.imul(dt,st)|0,l=l+Math.imul(dt,xt)|0,u=u+Math.imul(et,ot)|0,e=e+Math.imul(et,_t)|0,e=e+Math.imul(pt,ot)|0,l=l+Math.imul(pt,_t)|0,u=u+Math.imul(tt,ut)|0,e=e+Math.imul(tt,St)|0,e=e+Math.imul(vt,ut)|0,l=l+Math.imul(vt,St)|0;var oe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(oe>>>26)|0,oe&=67108863,u=Math.imul(T,at),e=Math.imul(T,wt),e=e+Math.imul(q,at)|0,l=Math.imul(q,wt),u=u+Math.imul(E,ht)|0,e=e+Math.imul(E,Mt)|0,e=e+Math.imul(w,ht)|0,l=l+Math.imul(w,Mt)|0,u=u+Math.imul(Q,st)|0,e=e+Math.imul(Q,xt)|0,e=e+Math.imul(ct,st)|0,l=l+Math.imul(ct,xt)|0,u=u+Math.imul(j,ot)|0,e=e+Math.imul(j,_t)|0,e=e+Math.imul(dt,ot)|0,l=l+Math.imul(dt,_t)|0,u=u+Math.imul(et,ut)|0,e=e+Math.imul(et,St)|0,e=e+Math.imul(pt,ut)|0,l=l+Math.imul(pt,St)|0;var ue=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ue>>>26)|0,ue&=67108863,u=Math.imul(T,ht),e=Math.imul(T,Mt),e=e+Math.imul(q,ht)|0,l=Math.imul(q,Mt),u=u+Math.imul(E,st)|0,e=e+Math.imul(E,xt)|0,e=e+Math.imul(w,st)|0,l=l+Math.imul(w,xt)|0,u=u+Math.imul(Q,ot)|0,e=e+Math.imul(Q,_t)|0,e=e+Math.imul(ct,ot)|0,l=l+Math.imul(ct,_t)|0,u=u+Math.imul(j,ut)|0,e=e+Math.imul(j,St)|0,e=e+Math.imul(dt,ut)|0,l=l+Math.imul(dt,St)|0;var le=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(le>>>26)|0,le&=67108863,u=Math.imul(T,st),e=Math.imul(T,xt),e=e+Math.imul(q,st)|0,l=Math.imul(q,xt),u=u+Math.imul(E,ot)|0,e=e+Math.imul(E,_t)|0,e=e+Math.imul(w,ot)|0,l=l+Math.imul(w,_t)|0,u=u+Math.imul(Q,ut)|0,e=e+Math.imul(Q,St)|0,e=e+Math.imul(ct,ut)|0,l=l+Math.imul(ct,St)|0;var de=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(de>>>26)|0,de&=67108863,u=Math.imul(T,ot),e=Math.imul(T,_t),e=e+Math.imul(q,ot)|0,l=Math.imul(q,_t),u=u+Math.imul(E,ut)|0,e=e+Math.imul(E,St)|0,e=e+Math.imul(w,ut)|0,l=l+Math.imul(w,St)|0;var ce=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ce>>>26)|0,ce&=67108863,u=Math.imul(T,ut),e=Math.imul(T,St),e=e+Math.imul(q,ut)|0,l=Math.imul(q,St);var ve=(v+u|0)+((e&8191)<<13)|0;return v=(l+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,c[0]=$t,c[1]=Nt,c[2]=jt,c[3]=Qt,c[4]=te,c[5]=ee,c[6]=re,c[7]=ie,c[8]=ne,c[9]=fe,c[10]=ae,c[11]=he,c[12]=se,c[13]=oe,c[14]=ue,c[15]=le,c[16]=de,c[17]=ce,c[18]=ve,v!==0&&(c[19]=v,i.length++),i};Math.imul||(L=D);function W(p,t,r){r.negative=t.negative^p.negative,r.length=p.length+t.length;for(var i=0,a=0,d=0;d<r.length-1;d++){var c=a;a=0;for(var v=i&67108863,u=Math.min(d,t.length-1),e=Math.max(0,d-p.length+1);e<=u;e++){var l=d-e,b=p.words[l]|0,_=t.words[e]|0,C=b*_,F=C&67108863;c=c+(C/67108864|0)|0,F=F+v|0,v=F&67108863,c=c+(F>>>26)|0,a+=c>>>26,c&=67108863}r.words[d]=v,i=c,c=a}return i!==0?r.words[d]=i:r.length--,r.strip()}function z(p,t,r){var i=new N;return i.mulp(p,t,r)}f.prototype.mulTo=function(t,r){var i,a=this.length+t.length;return this.length===10&&t.length===10?i=L(this,t,r):a<63?i=D(this,t,r):a<1024?i=W(this,t,r):i=z(this,t,r),i};function N(p,t){this.x=p,this.y=t}N.prototype.makeRBT=function(t){for(var r=new Array(t),i=f.prototype._countBits(t)-1,a=0;a<t;a++)r[a]=this.revBin(a,i,t);return r},N.prototype.revBin=function(t,r,i){if(t===0||t===i-1)return t;for(var a=0,d=0;d<r;d++)a|=(t&1)<<r-d-1,t>>=1;return a},N.prototype.permute=function(t,r,i,a,d,c){for(var v=0;v<c;v++)a[v]=r[t[v]],d[v]=i[t[v]]},N.prototype.transform=function(t,r,i,a,d,c){this.permute(c,t,r,i,a,d);for(var v=1;v<d;v<<=1)for(var u=v<<1,e=Math.cos(2*Math.PI/u),l=Math.sin(2*Math.PI/u),b=0;b<d;b+=u)for(var _=e,C=l,F=0;F<v;F++){var O=i[b+F],R=a[b+F],P=i[b+F+v],$=a[b+F+v],K=_*P-C*$;$=_*$+C*P,P=K,i[b+F]=O+P,a[b+F]=R+$,i[b+F+v]=O-P,a[b+F+v]=R-$,F!==u&&(K=e*_-l*C,C=e*C+l*_,_=K)}},N.prototype.guessLen13b=function(t,r){var i=Math.max(r,t)|1,a=i&1,d=0;for(i=i/2|0;i;i=i>>>1)d++;return 1<<d+1+a},N.prototype.conjugate=function(t,r,i){if(!(i<=1))for(var a=0;a<i/2;a++){var d=t[a];t[a]=t[i-a-1],t[i-a-1]=d,d=r[a],r[a]=-r[i-a-1],r[i-a-1]=-d}},N.prototype.normalize13b=function(t,r){for(var i=0,a=0;a<r/2;a++){var d=Math.round(t[2*a+1]/r)*8192+Math.round(t[2*a]/r)+i;t[a]=d&67108863,d<67108864?i=0:i=d/67108864|0}return t},N.prototype.convert13b=function(t,r,i,a){for(var d=0,c=0;c<r;c++)d=d+(t[c]|0),i[2*c]=d&8191,d=d>>>13,i[2*c+1]=d&8191,d=d>>>13;for(c=2*r;c<a;++c)i[c]=0;s(d===0),s((d&-8192)===0)},N.prototype.stub=function(t){for(var r=new Array(t),i=0;i<t;i++)r[i]=0;return r},N.prototype.mulp=function(t,r,i){var a=2*this.guessLen13b(t.length,r.length),d=this.makeRBT(a),c=this.stub(a),v=new Array(a),u=new Array(a),e=new Array(a),l=new Array(a),b=new Array(a),_=new Array(a),C=i.words;C.length=a,this.convert13b(t.words,t.length,v,a),this.convert13b(r.words,r.length,l,a),this.transform(v,c,u,e,a,d),this.transform(l,c,b,_,a,d);for(var F=0;F<a;F++){var O=u[F]*b[F]-e[F]*_[F];e[F]=u[F]*_[F]+e[F]*b[F],u[F]=O}return this.conjugate(u,e,a),this.transform(u,e,C,c,a,d),this.conjugate(C,c,a),this.normalize13b(C,a),i.negative=t.negative^r.negative,i.length=t.length+r.length,i.strip()},f.prototype.mul=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},f.prototype.mulf=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),z(this,t,r)},f.prototype.imul=function(t){return this.clone().mulTo(t,this)},f.prototype.imuln=function(t){s(typeof t=="number"),s(t<67108864);for(var r=0,i=0;i<this.length;i++){var a=(this.words[i]|0)*t,d=(a&67108863)+(r&67108863);r>>=26,r+=a/67108864|0,r+=d>>>26,this.words[i]=d&67108863}return r!==0&&(this.words[i]=r,this.length++),this.length=t===0?1:this.length,this},f.prototype.muln=function(t){return this.clone().imuln(t)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(t){var r=I(t);if(r.length===0)return new f(1);for(var i=this,a=0;a<r.length&&r[a]===0;a++,i=i.sqr());if(++a<r.length)for(var d=i.sqr();a<r.length;a++,d=d.sqr())r[a]!==0&&(i=i.mul(d));return i},f.prototype.iushln=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,a=67108863>>>26-r<<26-r,d;if(r!==0){var c=0;for(d=0;d<this.length;d++){var v=this.words[d]&a,u=(this.words[d]|0)-v<<r;this.words[d]=u|c,c=v>>>26-r}c&&(this.words[d]=c,this.length++)}if(i!==0){for(d=this.length-1;d>=0;d--)this.words[d+i]=this.words[d];for(d=0;d<i;d++)this.words[d]=0;this.length+=i}return this.strip()},f.prototype.ishln=function(t){return s(this.negative===0),this.iushln(t)},f.prototype.iushrn=function(t,r,i){s(typeof t=="number"&&t>=0);var a;r?a=(r-r%26)/26:a=0;var d=t%26,c=Math.min((t-d)/26,this.length),v=67108863^67108863>>>d<<d,u=i;if(a-=c,a=Math.max(0,a),u){for(var e=0;e<c;e++)u.words[e]=this.words[e];u.length=c}if(c!==0)if(this.length>c)for(this.length-=c,e=0;e<this.length;e++)this.words[e]=this.words[e+c];else this.words[0]=0,this.length=1;var l=0;for(e=this.length-1;e>=0&&(l!==0||e>=a);e--){var b=this.words[e]|0;this.words[e]=l<<26-d|b>>>d,l=b&v}return u&&l!==0&&(u.words[u.length++]=l),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},f.prototype.ishrn=function(t,r,i){return s(this.negative===0),this.iushrn(t,r,i)},f.prototype.shln=function(t){return this.clone().ishln(t)},f.prototype.ushln=function(t){return this.clone().iushln(t)},f.prototype.shrn=function(t){return this.clone().ishrn(t)},f.prototype.ushrn=function(t){return this.clone().iushrn(t)},f.prototype.testn=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,a=1<<r;if(this.length<=i)return!1;var d=this.words[i];return!!(d&a)},f.prototype.imaskn=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26;if(s(this.negative===0,"imaskn works only with positive numbers"),this.length<=i)return this;if(r!==0&&i++,this.length=Math.min(i,this.length),r!==0){var a=67108863^67108863>>>r<<r;this.words[this.length-1]&=a}return this.strip()},f.prototype.maskn=function(t){return this.clone().imaskn(t)},f.prototype.iaddn=function(t){return s(typeof t=="number"),s(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},f.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},f.prototype.isubn=function(t){if(s(typeof t=="number"),s(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this.strip()},f.prototype.addn=function(t){return this.clone().iaddn(t)},f.prototype.subn=function(t){return this.clone().isubn(t)},f.prototype.iabs=function(){return this.negative=0,this},f.prototype.abs=function(){return this.clone().iabs()},f.prototype._ishlnsubmul=function(t,r,i){var a=t.length+i,d;this._expand(a);var c,v=0;for(d=0;d<t.length;d++){c=(this.words[d+i]|0)+v;var u=(t.words[d]|0)*r;c-=u&67108863,v=(c>>26)-(u/67108864|0),this.words[d+i]=c&67108863}for(;d<this.length-i;d++)c=(this.words[d+i]|0)+v,v=c>>26,this.words[d+i]=c&67108863;if(v===0)return this.strip();for(s(v===-1),v=0,d=0;d<this.length;d++)c=-(this.words[d]|0)+v,v=c>>26,this.words[d]=c&67108863;return this.negative=1,this.strip()},f.prototype._wordDiv=function(t,r){var i=this.length-t.length,a=this.clone(),d=t,c=d.words[d.length-1]|0,v=this._countBits(c);i=26-v,i!==0&&(d=d.ushln(i),a.iushln(i),c=d.words[d.length-1]|0);var u=a.length-d.length,e;if(r!=="mod"){e=new f(null),e.length=u+1,e.words=new Array(e.length);for(var l=0;l<e.length;l++)e.words[l]=0}var b=a.clone()._ishlnsubmul(d,1,u);b.negative===0&&(a=b,e&&(e.words[u]=1));for(var _=u-1;_>=0;_--){var C=(a.words[d.length+_]|0)*67108864+(a.words[d.length+_-1]|0);for(C=Math.min(C/c|0,67108863),a._ishlnsubmul(d,C,_);a.negative!==0;)C--,a.negative=0,a._ishlnsubmul(d,1,_),a.isZero()||(a.negative^=1);e&&(e.words[_]=C)}return e&&e.strip(),a.strip(),r!=="div"&&i!==0&&a.iushrn(i),{div:e||null,mod:a}},f.prototype.divmod=function(t,r,i){if(s(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var a,d,c;return this.negative!==0&&t.negative===0?(c=this.neg().divmod(t,r),r!=="mod"&&(a=c.div.neg()),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.iadd(t)),{div:a,mod:d}):this.negative===0&&t.negative!==0?(c=this.divmod(t.neg(),r),r!=="mod"&&(a=c.div.neg()),{div:a,mod:c.mod}):this.negative&t.negative?(c=this.neg().divmod(t.neg(),r),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.isub(t)),{div:c.div,mod:d}):t.length>this.length||this.cmp(t)<0?{div:new f(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new f(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new f(this.modn(t.words[0]))}:this._wordDiv(t,r)},f.prototype.div=function(t){return this.divmod(t,"div",!1).div},f.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},f.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},f.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var i=r.div.negative!==0?r.mod.isub(t):r.mod,a=t.ushrn(1),d=t.andln(1),c=i.cmp(a);return c<0||d===1&&c===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},f.prototype.modn=function(t){s(t<=67108863);for(var r=(1<<26)%t,i=0,a=this.length-1;a>=0;a--)i=(r*i+(this.words[a]|0))%t;return i},f.prototype.idivn=function(t){s(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var a=(this.words[i]|0)+r*67108864;this.words[i]=a/t|0,r=a%t}return this.strip()},f.prototype.divn=function(t){return this.clone().idivn(t)},f.prototype.egcd=function(t){s(t.negative===0),s(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var a=new f(1),d=new f(0),c=new f(0),v=new f(1),u=0;r.isEven()&&i.isEven();)r.iushrn(1),i.iushrn(1),++u;for(var e=i.clone(),l=r.clone();!r.isZero();){for(var b=0,_=1;!(r.words[0]&_)&&b<26;++b,_<<=1);if(b>0)for(r.iushrn(b);b-- >0;)(a.isOdd()||d.isOdd())&&(a.iadd(e),d.isub(l)),a.iushrn(1),d.iushrn(1);for(var C=0,F=1;!(i.words[0]&F)&&C<26;++C,F<<=1);if(C>0)for(i.iushrn(C);C-- >0;)(c.isOdd()||v.isOdd())&&(c.iadd(e),v.isub(l)),c.iushrn(1),v.iushrn(1);r.cmp(i)>=0?(r.isub(i),a.isub(c),d.isub(v)):(i.isub(r),c.isub(a),v.isub(d))}return{a:c,b:v,gcd:i.iushln(u)}},f.prototype._invmp=function(t){s(t.negative===0),s(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var a=new f(1),d=new f(0),c=i.clone();r.cmpn(1)>0&&i.cmpn(1)>0;){for(var v=0,u=1;!(r.words[0]&u)&&v<26;++v,u<<=1);if(v>0)for(r.iushrn(v);v-- >0;)a.isOdd()&&a.iadd(c),a.iushrn(1);for(var e=0,l=1;!(i.words[0]&l)&&e<26;++e,l<<=1);if(e>0)for(i.iushrn(e);e-- >0;)d.isOdd()&&d.iadd(c),d.iushrn(1);r.cmp(i)>=0?(r.isub(i),a.isub(d)):(i.isub(r),d.isub(a))}var b;return r.cmpn(1)===0?b=a:b=d,b.cmpn(0)<0&&b.iadd(t),b},f.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),i=t.clone();r.negative=0,i.negative=0;for(var a=0;r.isEven()&&i.isEven();a++)r.iushrn(1),i.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;i.isEven();)i.iushrn(1);var d=r.cmp(i);if(d<0){var c=r;r=i,i=c}else if(d===0||i.cmpn(1)===0)break;r.isub(i)}while(!0);return i.iushln(a)},f.prototype.invm=function(t){return this.egcd(t).a.umod(t)},f.prototype.isEven=function(){return(this.words[0]&1)===0},f.prototype.isOdd=function(){return(this.words[0]&1)===1},f.prototype.andln=function(t){return this.words[0]&t},f.prototype.bincn=function(t){s(typeof t=="number");var r=t%26,i=(t-r)/26,a=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=a,this;for(var d=a,c=i;d!==0&&c<this.length;c++){var v=this.words[c]|0;v+=d,d=v>>>26,v&=67108863,this.words[c]=v}return d!==0&&(this.words[c]=d,this.length++),this},f.prototype.isZero=function(){return this.length===1&&this.words[0]===0},f.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return-1;if(this.negative===0&&r)return 1;this.strip();var i;if(this.length>1)i=1;else{r&&(t=-t),s(t<=67108863,"Number is too big");var a=this.words[0]|0;i=a===t?0:a<t?-1:1}return this.negative!==0?-i|0:i},f.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return-1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},f.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var r=0,i=this.length-1;i>=0;i--){var a=this.words[i]|0,d=t.words[i]|0;if(a!==d){a<d?r=-1:a>d&&(r=1);break}}return r},f.prototype.gtn=function(t){return this.cmpn(t)===1},f.prototype.gt=function(t){return this.cmp(t)===1},f.prototype.gten=function(t){return this.cmpn(t)>=0},f.prototype.gte=function(t){return this.cmp(t)>=0},f.prototype.ltn=function(t){return this.cmpn(t)===-1},f.prototype.lt=function(t){return this.cmp(t)===-1},f.prototype.lten=function(t){return this.cmpn(t)<=0},f.prototype.lte=function(t){return this.cmp(t)<=0},f.prototype.eqn=function(t){return this.cmpn(t)===0},f.prototype.eq=function(t){return this.cmp(t)===0},f.red=function(t){return new Y(t)},f.prototype.toRed=function(t){return s(!this.red,"Already a number in reduction context"),s(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},f.prototype.fromRed=function(){return s(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(t){return this.red=t,this},f.prototype.forceRed=function(t){return s(!this.red,"Already a number in reduction context"),this._forceRed(t)},f.prototype.redAdd=function(t){return s(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},f.prototype.redIAdd=function(t){return s(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},f.prototype.redSub=function(t){return s(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},f.prototype.redISub=function(t){return s(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},f.prototype.redShl=function(t){return s(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},f.prototype.redMul=function(t){return s(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},f.prototype.redIMul=function(t){return s(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},f.prototype.redSqr=function(){return s(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return s(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return s(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return s(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return s(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(t){return s(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var lt={k256:null,p224:null,p192:null,p25519:null};function H(p,t){this.name=p,this.p=new f(t,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}H.prototype._tmp=function(){var t=new f(null);return t.words=new Array(Math.ceil(this.n/13)),t},H.prototype.ireduce=function(t){var r=t,i;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),i=r.bitLength();while(i>this.n);var a=i<this.n?-1:r.ucmp(this.p);return a===0?(r.words[0]=0,r.length=1):a>0?r.isub(this.p):r.strip!==void 0?r.strip():r._strip(),r},H.prototype.split=function(t,r){t.iushrn(this.n,0,r)},H.prototype.imulK=function(t){return t.imul(this.k)};function At(){H.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}m(At,H),At.prototype.split=function(t,r){for(var i=4194303,a=Math.min(t.length,9),d=0;d<a;d++)r.words[d]=t.words[d];if(r.length=a,t.length<=9){t.words[0]=0,t.length=1;return}var c=t.words[9];for(r.words[r.length++]=c&i,d=10;d<t.length;d++){var v=t.words[d]|0;t.words[d-10]=(v&i)<<4|c>>>22,c=v}c>>>=22,t.words[d-10]=c,c===0&&t.length>10?t.length-=10:t.length-=9},At.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,i=0;i<t.length;i++){var a=t.words[i]|0;r+=a*977,t.words[i]=r&67108863,r=a*64+(r/67108864|0)}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function Bt(){H.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}m(Bt,H);function Ct(){H.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}m(Ct,H);function Et(){H.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}m(Et,H),Et.prototype.imulK=function(t){for(var r=0,i=0;i<t.length;i++){var a=(t.words[i]|0)*19+r,d=a&67108863;a>>>=26,t.words[i]=d,r=a}return r!==0&&(t.words[t.length++]=r),t},f._prime=function(t){if(lt[t])return lt[t];var r;if(t==="k256")r=new At;else if(t==="p224")r=new Bt;else if(t==="p192")r=new Ct;else if(t==="p25519")r=new Et;else throw new Error("Unknown prime "+t);return lt[t]=r,r};function Y(p){if(typeof p=="string"){var t=f._prime(p);this.m=t.p,this.prime=t}else s(p.gtn(1),"modulus must be greater than 1"),this.m=p,this.prime=null}Y.prototype._verify1=function(t){s(t.negative===0,"red works only with positives"),s(t.red,"red works only with red numbers")},Y.prototype._verify2=function(t,r){s((t.negative|r.negative)===0,"red works only with positives"),s(t.red&&t.red===r.red,"red works only with red numbers")},Y.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},Y.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},Y.prototype.add=function(t,r){this._verify2(t,r);var i=t.add(r);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},Y.prototype.iadd=function(t,r){this._verify2(t,r);var i=t.iadd(r);return i.cmp(this.m)>=0&&i.isub(this.m),i},Y.prototype.sub=function(t,r){this._verify2(t,r);var i=t.sub(r);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},Y.prototype.isub=function(t,r){this._verify2(t,r);var i=t.isub(r);return i.cmpn(0)<0&&i.iadd(this.m),i},Y.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},Y.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},Y.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},Y.prototype.isqr=function(t){return this.imul(t,t.clone())},Y.prototype.sqr=function(t){return this.mul(t,t)},Y.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(s(r%2===1),r===3){var i=this.m.add(new f(1)).iushrn(2);return this.pow(t,i)}for(var a=this.m.subn(1),d=0;!a.isZero()&&a.andln(1)===0;)d++,a.iushrn(1);s(!a.isZero());var c=new f(1).toRed(this),v=c.redNeg(),u=this.m.subn(1).iushrn(1),e=this.m.bitLength();for(e=new f(2*e*e).toRed(this);this.pow(e,u).cmp(v)!==0;)e.redIAdd(v);for(var l=this.pow(e,a),b=this.pow(t,a.addn(1).iushrn(1)),_=this.pow(t,a),C=d;_.cmp(c)!==0;){for(var F=_,O=0;F.cmp(c)!==0;O++)F=F.redSqr();s(O<C);var R=this.pow(l,new f(1).iushln(C-O-1));b=b.redMul(R),l=R.redSqr(),_=_.redMul(l),C=O}return b},Y.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},Y.prototype.pow=function(t,r){if(r.isZero())return new f(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var i=4,a=new Array(1<<i);a[0]=new f(1).toRed(this),a[1]=t;for(var d=2;d<a.length;d++)a[d]=this.mul(a[d-1],t);var c=a[0],v=0,u=0,e=r.bitLength()%26;for(e===0&&(e=26),d=r.length-1;d>=0;d--){for(var l=r.words[d],b=e-1;b>=0;b--){var _=l>>b&1;if(c!==a[0]&&(c=this.sqr(c)),_===0&&v===0){u=0;continue}v<<=1,v|=_,u++,!(u!==i&&(d!==0||b!==0))&&(c=this.mul(c,a[v]),u=0,v=0)}e=26}return c},Y.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},Y.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},f.mont=function(t){return new kt(t)};function kt(p){Y.call(this,p),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}m(kt,Y),kt.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},kt.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},kt.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),a=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(a).iushrn(this.shift),c=d;return d.cmp(this.m)>=0?c=d.isub(this.m):d.cmpn(0)<0&&(c=d.iadd(this.m)),c._forceRed(this)},kt.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var i=t.mul(r),a=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(a).iushrn(this.shift),c=d;return d.cmp(this.m)>=0?c=d.isub(this.m):d.cmpn(0)<0&&(c=d.iadd(this.m)),c._forceRed(this)},kt.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(h,Gt)})(J0);var G0=J0.exports,dh=G0,Dm=Ot.Buffer;function $m(h,n){return Dm.from(h.toRed(dh.mont(n.modulus)).redPow(new dh(n.publicExponent)).fromRed().toArray())}var Ko=$m,Nm=hf,p0=gi,Um=Gi,ch=Oo,vh=zo,X0=G0,Lm=Ko,Om=U0,je=Ot.Buffer,zm=function(n,o,s){var m;n.padding?m=n.padding:s?m=1:m=4;var f=Nm(n),g;if(m===4)g=Km(f,o);else if(m===1)g=Hm(f,o,s);else if(m===3){if(g=new X0(o),g.cmp(f.modulus)>=0)throw new Error("data too long for modulus")}else throw new Error("unknown padding");return s?Om(g,f):Lm(g,f)};function Km(h,n){var o=h.modulus.byteLength(),s=n.length,m=Um("sha1").update(je.alloc(0)).digest(),f=m.length,g=2*f;if(s>o-g-2)throw new Error("message too long");var y=je.alloc(o-s-g-2),S=o-f-1,B=p0(f),M=vh(je.concat([m,y,je.alloc(1,1),n],S),ch(B,S)),x=vh(B,ch(M,f));return new X0(je.concat([je.alloc(1),x,M],o))}function Hm(h,n,o){var s=n.length,m=h.modulus.byteLength();if(s>m-11)throw new Error("message too long");var f;return o?f=je.alloc(m-s-3,255):f=Zm(m-s-3),new X0(je.concat([je.from([0,o?1:2]),f,je.alloc(1),n],m))}function Zm(h){for(var n=je.allocUnsafe(h),o=0,s=p0(h*2),m=0,f;o<h;)m===s.length&&(s=p0(h*2),m=0),f=s[m++],f&&(n[o++]=f);return n}var Wm=hf,ph=Oo,mh=zo,gh=G0,Vm=U0,Ym=Gi,Jm=Ko,Hi=Ot.Buffer,Gm=function(n,o,s){var m;n.padding?m=n.padding:s?m=1:m=4;var f=Wm(n),g=f.modulus.byteLength();if(o.length>g||new gh(o).cmp(f.modulus)>=0)throw new Error("decryption error");var y;s?y=Jm(new gh(o),f):y=Vm(o,f);var S=Hi.alloc(g-y.length);if(y=Hi.concat([S,y],g),m===4)return Xm(f,y);if(m===1)return jm(f,y,s);if(m===3)return y;throw new Error("unknown padding")};function Xm(h,n){var o=h.modulus.byteLength(),s=Ym("sha1").update(Hi.alloc(0)).digest(),m=s.length;if(n[0]!==0)throw new Error("decryption error");var f=n.slice(1,m+1),g=n.slice(m+1),y=mh(f,ph(g,m)),S=mh(g,ph(y,o-m-1));if(Qm(s,S.slice(0,m)))throw new Error("decryption error");for(var B=m;S[B]===0;)B++;if(S[B++]!==1)throw new Error("decryption error");return S.slice(B)}function jm(h,n,o){for(var s=n.slice(0,2),m=2,f=0;n[m++]!==0;)if(m>=n.length){f++;break}var g=n.slice(2,m-1);if((s.toString("hex")!=="0002"&&!o||s.toString("hex")!=="0001"&&o)&&f++,g.length<8&&f++,f)throw new Error("decryption error");return n.slice(m)}function Qm(h,n){h=Hi.from(h),n=Hi.from(n);var o=0,s=h.length;h.length!==n.length&&(o++,s=Math.min(h.length,n.length));for(var m=-1;++m<s;)o+=h[m]^n[m];return o}(function(h){h.publicEncrypt=zm,h.privateDecrypt=Gm,h.privateEncrypt=function(o,s){return h.publicEncrypt(o,s,!0)},h.publicDecrypt=function(o,s){return h.privateDecrypt(o,s,!0)}})(Lo);var $i={};function bh(){throw new Error(`secure random number generation not supported by this browser
16
16
  use chrome, FireFox or Internet Explorer 11`)}var Ho=Ot,yh=gi,Zo=Ho.Buffer,Wo=Ho.kMaxLength,m0=Gt.crypto||Gt.msCrypto,Vo=Math.pow(2,32)-1;function Yo(h,n){if(typeof h!="number"||h!==h)throw new TypeError("offset must be a number");if(h>Vo||h<0)throw new TypeError("offset must be a uint32");if(h>Wo||h>n)throw new RangeError("offset out of range")}function Jo(h,n,o){if(typeof h!="number"||h!==h)throw new TypeError("size must be a number");if(h>Vo||h<0)throw new TypeError("size must be a uint32");if(h+n>o||h>Wo)throw new RangeError("buffer too small")}m0&&m0.getRandomValues||!ye.browser?($i.randomFill=t3,$i.randomFillSync=e3):($i.randomFill=bh,$i.randomFillSync=bh);function t3(h,n,o,s){if(!Zo.isBuffer(h)&&!(h instanceof Gt.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');if(typeof n=="function")s=n,n=0,o=h.length;else if(typeof o=="function")s=o,o=h.length-n;else if(typeof s!="function")throw new TypeError('"cb" argument must be a function');return Yo(n,h.length),Jo(o,n,h.length),Go(h,n,o,s)}function Go(h,n,o,s){if(ye.browser){var m=h.buffer,f=new Uint8Array(m,n,o);if(m0.getRandomValues(f),s){ye.nextTick(function(){s(null,h)});return}return h}if(s){yh(o,function(y,S){if(y)return s(y);S.copy(h,n),s(null,h)});return}var g=yh(o);return g.copy(h,n),h}function e3(h,n,o){if(typeof n=="undefined"&&(n=0),!Zo.isBuffer(h)&&!(h instanceof Gt.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');return Yo(n,h.length),o===void 0&&(o=h.length-n),Jo(o,n,h.length),Go(h,n,o)}var wh;function Xo(){if(wh)return Ut;wh=1,Ut.randomBytes=Ut.rng=Ut.pseudoRandomBytes=Ut.prng=gi,Ut.createHash=Ut.Hash=Gi,Ut.createHmac=Ut.Hmac=Vh;var h=Zd,n=Object.keys(h),o=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(n);Ut.getHashes=function(){return o};var s=Nn;Ut.pbkdf2=s.pbkdf2,Ut.pbkdf2Sync=s.pbkdf2Sync;var m=Qe;Ut.Cipher=m.Cipher,Ut.createCipher=m.createCipher,Ut.Cipheriv=m.Cipheriv,Ut.createCipheriv=m.createCipheriv,Ut.Decipher=m.Decipher,Ut.createDecipher=m.createDecipher,Ut.Decipheriv=m.Decipheriv,Ut.createDecipheriv=m.createDecipheriv,Ut.getCiphers=m.getCiphers,Ut.listCiphers=m.listCiphers;var f=ev();Ut.DiffieHellmanGroup=f.DiffieHellmanGroup,Ut.createDiffieHellmanGroup=f.createDiffieHellmanGroup,Ut.getDiffieHellman=f.getDiffieHellman,Ut.createDiffieHellman=f.createDiffieHellman,Ut.DiffieHellman=f.DiffieHellman;var g=Tm();Ut.createSign=g.createSign,Ut.Sign=g.Sign,Ut.createVerify=g.createVerify,Ut.Verify=g.Verify,Ut.createECDH=qm();var y=Lo;Ut.publicEncrypt=y.publicEncrypt,Ut.privateEncrypt=y.privateEncrypt,Ut.publicDecrypt=y.publicDecrypt,Ut.privateDecrypt=y.privateDecrypt;var S=$i;return Ut.randomFill=S.randomFill,Ut.randomFillSync=S.randomFillSync,Ut.createCredentials=function(){throw new Error(`sorry, createCredentials is not implemented yet
17
17
  we accept pull requests
18
- https://github.com/browserify/crypto-browserify`)},Ut.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6},Ut}var r3=Xo();const i3=du(r3);function j0(h){const n=i3.createHash("sha256").update(h).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function jo(h,n){const o=j0(h);let s=0;for(const m of n.variants)if(s+=m.weight,o<s)return m.value;return null}function Qo(h,n){const o=n.user_id||n.id||n.email;if(!h||typeof h!="object"||!o)return null;switch(h.strategy){case"percentage":{if(!("percentage"in h)||!("salt"in h))return null;const{percentage:s,salt:m}=h;return j0(`${o}.${m}`)<s?!0:null}case"variant":{if(!("variants"in h))return null;const{salt:s,variants:m}=h;return jo(`${o}.${s}`,m)}default:return null}}function tu(h,n){var f;if(!(h.targeting_rules||[]).every(g=>{var y;if(g.type==="segment"){const S=(y=h.segmentsById)==null?void 0:y[g.segment_id];return S?xu(S,n):!1}else return Sh(g,n)}))return null;const m=h.rollout?Qo(h.rollout,n):null;return(f=m!=null?m:h.value)!=null?f:null}let an={getItem:h=>typeof localStorage!="undefined"?localStorage.getItem(h):null,setItem:(h,n)=>{typeof localStorage!="undefined"&&localStorage.setItem(h,n)}};function n3(h){an=h}function eu(h){return`flagmint_${h}_flags`}function ru(h){return`flagmint_${h}_context`}function iu(h,n){try{const o=an.getItem(eu(h));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}}function nu(h,n){try{an.setItem(eu(h),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}}function fu(h){try{const n=an.getItem(ru(h));return n?JSON.parse(n):null}catch(n){return null}}function au(h,n){try{an.setItem(ru(h),JSON.stringify(n))}catch(o){}}const f3=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:fu,loadCachedFlags:iu,saveCachedContext:au,saveCachedFlags:nu,setCacheStorage:n3},Symbol.toStringTag,{value:"Module"})),a3=24*60*60*1e3,h3="http://localhost:3000/evaluator/evaluate",s3="wss://api.flagmint.io/flags/ws";class o3{constructor(n){var o,s,m,f;if(this.flags={},this.refreshIntervalId=null,this.rawFlags={},this.apiKey=n.apiKey,this.enableOfflineCache=(o=n.enableOfflineCache)!=null?o:!0,this.persistContext=(s=n.persistContext)!=null?s:!1,this.cacheTTL=a3,this.onError=n.onError,this.cacheAdapter=(m=n.cacheAdapter)!=null?m:{loadFlags:iu,saveFlags:nu,loadContext:fu,saveContext:au},this.context=n.context||{},this.rawFlags=(f=n.rawFlags)!=null?f:{},this.previewMode=n.previewMode||!1,this.previewMode&&this.rawFlags&&Object.keys(this.rawFlags).length>0){this.flags=this.evaluateLocally(this.rawFlags,this.context),this.readyPromise=Promise.resolve(),this.resolveReady=()=>{},this.rejectReady=()=>{};return}else this.previewMode&&!this.rawFlags&&console.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((g,y)=>{this.resolveReady=g,this.rejectReady=y}),this.initialize(n)}initialize(n){return Ue(this,null,function*(){var o;try{if(this.persistContext){const s=yield Promise.resolve(this.cacheAdapter.loadContext(this.apiKey));s&&(this.context=s)}if(this.enableOfflineCache){const s=yield Promise.resolve(this.cacheAdapter.loadFlags(this.apiKey,this.cacheTTL));s&&(this.flags=s)}yield this.setupTransport(n),this.resolveReady()}catch(s){this.rejectReady(s),(o=this.onError)==null||o.call(this,s)}})}setupTransport(n){return Ue(this,null,function*(){var f;const o=(f=n.transportMode)!=null?f:"auto",s=()=>Ue(this,null,function*(){console.log("[FlagClient] Initializing WebSocket transport...");const g=new _h(s3,this.apiKey);return yield g.init(),console.log("[FlagClient] WebSocket transport initialized"),g}),m=()=>{console.log("[FlagClient] Using long polling transport...");const g=new xh(h3,this.apiKey,this.context,{pollIntervalMs:1e4});return g.init(y=>{console.log("[FlagClient] LongPolling update received:",y),this.flags=y,this.enableOfflineCache&&Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,y))}),g};try{if(o==="websocket")this.transport=yield s();else if(o==="long-polling")this.transport=m();else try{this.transport=yield s()}catch(y){console.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}const g=yield this.transport.fetchFlags(this.context);this.flags=g,this.enableOfflineCache&&(yield Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,g))),typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(y=>{this.flags=y,this.enableOfflineCache&&this.cacheAdapter.saveFlags(this.apiKey,y)}),this.resolveReady()}catch(g){throw console.error("[FlagClient] setupTransport error:",g),this.rejectReady(g),this.onError&&this.onError(g instanceof Error?g:new Error(String(g))),g}})}getFlag(n,o){var s;return(s=this.flags[n])!=null?s:o}updateContext(n){this.context=uf(uf({},this.context),n),this.persistContext&&this.cacheAdapter.saveContext(this.apiKey,this.context)}destroy(){this.refreshIntervalId&&clearInterval(this.refreshIntervalId),this.transport.destroy()}ready(){return Ue(this,null,function*(){return this.readyPromise})}evaluateLocally(n,o){const s={};for(const m in n){const f=tu(n[m],o);f!==null&&(s[m]=f)}return s}}function hu(h){return`flagmint_${h}_flags`}function su(h){return`flagmint_${h}_context`}let kr=null;function u3(h){kr=h}function l3(h,n){return Ue(this,null,function*(){if(!kr)throw new Error("Async storage not set");try{const o=yield kr.getItem(hu(h));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}})}function d3(h,n){return Ue(this,null,function*(){if(!kr)throw new Error("Async storage not set");try{yield kr.setItem(hu(h),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}})}function c3(h){return Ue(this,null,function*(){if(!kr)throw new Error("Async storage not set");try{const n=yield kr.getItem(su(h));return n?JSON.parse(n):null}catch(n){return null}})}function v3(h,n){return Ue(this,null,function*(){if(!kr)throw new Error("Async storage not set");try{yield kr.setItem(su(h),JSON.stringify(n))}catch(o){}})}const p3=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:c3,loadCachedFlags:l3,saveCachedContext:v3,saveCachedFlags:d3,setAsyncCacheStorage:u3},Symbol.toStringTag,{value:"Module"}));typeof globalThis.Buffer=="undefined"&&(globalThis.Buffer=gr.Buffer);exports.FlagClient=o3;exports.LongPollingTransport=xh;exports.WebSocketTransport=_h;exports.asyncCache=p3;exports.evaluateFlagValue=tu;exports.evaluateRollout=Qo;exports.hashToPercentage=j0;exports.pickVariant=jo;exports.syncCache=f3;
18
+ https://github.com/browserify/crypto-browserify`)},Ut.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6},Ut}var r3=Xo();const i3=du(r3);function j0(h){const n=i3.createHash("sha256").update(h).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function jo(h,n){const o=j0(h);let s=0;for(const m of n.variants)if(s+=m.weight,o<s)return m.value;return null}function Qo(h,n){const o=n.user_id||n.id||n.email;if(!h||typeof h!="object"||!o)return null;switch(h.strategy){case"percentage":{if(!("percentage"in h)||!("salt"in h))return null;const{percentage:s,salt:m}=h;return j0(`${o}.${m}`)<s?!0:null}case"variant":{if(!("variants"in h))return null;const{salt:s,variants:m}=h;return jo(`${o}.${s}`,m)}default:return null}}function tu(h,n){var f;if(!(h.targeting_rules||[]).every(g=>{var y;if(g.type==="segment"){const S=(y=h.segmentsById)==null?void 0:y[g.segment_id];return S?xu(S,n):!1}else return Sh(g,n)}))return null;const m=h.rollout?Qo(h.rollout,n):null;return(f=m!=null?m:h.value)!=null?f:null}let an={getItem:h=>typeof localStorage!="undefined"?localStorage.getItem(h):null,setItem:(h,n)=>{typeof localStorage!="undefined"&&localStorage.setItem(h,n)}};function n3(h){an=h}function eu(h){return`flagmint_${h}_flags`}function ru(h){return`flagmint_${h}_context`}function iu(h,n){try{const o=an.getItem(eu(h));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}}function nu(h,n){try{an.setItem(eu(h),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}}function fu(h){try{const n=an.getItem(ru(h));return n?JSON.parse(n):null}catch(n){return null}}function au(h,n){try{an.setItem(ru(h),JSON.stringify(n))}catch(o){}}const f3=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:fu,loadCachedFlags:iu,saveCachedContext:au,saveCachedFlags:nu,setCacheStorage:n3},Symbol.toStringTag,{value:"Module"})),a3=24*60*60*1e3,h3="http://localhost:3000/evaluator/evaluate",s3="wss://api.flagmint.io/flags/ws";class o3{constructor(n){var o,s,m,f;if(this.flags={},this.refreshIntervalId=null,this.rawFlags={},this.apiKey=n.apiKey,this.enableOfflineCache=(o=n.enableOfflineCache)!=null?o:!0,this.persistContext=(s=n.persistContext)!=null?s:!1,this.cacheTTL=a3,this.onError=n.onError,this.cacheAdapter=(m=n.cacheAdapter)!=null?m:{loadFlags:iu,saveFlags:nu,loadContext:fu,saveContext:au},this.context=n.context||{},this.rawFlags=(f=n.rawFlags)!=null?f:{},this.previewMode=n.previewMode||!1,this.previewMode&&this.rawFlags&&Object.keys(this.rawFlags).length>0){this.flags=this.rawFlags,this.flags=this.evaluateLocally(this.rawFlags,this.context),this.readyPromise=Promise.resolve(),this.resolveReady=()=>{},this.rejectReady=()=>{};return}else this.previewMode&&!this.rawFlags&&console.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((g,y)=>{this.resolveReady=g,this.rejectReady=y}),this.initialize(n)}initialize(n){return Ue(this,null,function*(){var o;try{if(this.persistContext){const s=yield Promise.resolve(this.cacheAdapter.loadContext(this.apiKey));s&&(this.context=s)}if(this.enableOfflineCache){const s=yield Promise.resolve(this.cacheAdapter.loadFlags(this.apiKey,this.cacheTTL));s&&(this.flags=s)}yield this.setupTransport(n),this.resolveReady()}catch(s){this.rejectReady(s),(o=this.onError)==null||o.call(this,s)}})}setupTransport(n){return Ue(this,null,function*(){var f;const o=(f=n.transportMode)!=null?f:"auto",s=()=>Ue(this,null,function*(){console.log("[FlagClient] Initializing WebSocket transport...");const g=new _h(s3,this.apiKey);return yield g.init(),console.log("[FlagClient] WebSocket transport initialized"),g}),m=()=>{console.log("[FlagClient] Using long polling transport...");const g=new xh(h3,this.apiKey,this.context,{pollIntervalMs:2e4});return g.init(y=>{console.log("[FlagClient] LongPolling update received:",y),this.flags=y,this.enableOfflineCache&&Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,y))}),g};try{if(o==="websocket")this.transport=yield s();else if(o==="long-polling")this.transport=m();else try{this.transport=yield s()}catch(g){console.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}this.flags=yield this.transport.fetchFlags(this.context),this.enableOfflineCache&&(yield Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,this.flags))),typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(g=>{this.flags=g,this.enableOfflineCache&&this.cacheAdapter.saveFlags(this.apiKey,g)}),this.resolveReady()}catch(g){throw console.error("[FlagClient] setupTransport error:",g),this.rejectReady(g),this.onError&&this.onError(g instanceof Error?g:new Error(String(g))),g}})}getFlag(n,o){var s;return(s=this.flags[n])!=null?s:o}updateContext(n){this.context=uf(uf({},this.context),n),this.persistContext&&this.cacheAdapter.saveContext(this.apiKey,this.context)}destroy(){this.refreshIntervalId&&clearInterval(this.refreshIntervalId),this.transport.destroy()}ready(){return Ue(this,null,function*(){return this.readyPromise})}evaluateLocally(n,o){const s={};console.log("[FlagClient] Evaluating flags locally with context:",n,o);for(const m in n){const f=tu(n[m],o);f!==null&&(s[m]=f)}return s}}function hu(h){return`flagmint_${h}_flags`}function su(h){return`flagmint_${h}_context`}let kr=null;function u3(h){kr=h}function l3(h,n){return Ue(this,null,function*(){if(!kr)throw new Error("Async storage not set");try{const o=yield kr.getItem(hu(h));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}})}function d3(h,n){return Ue(this,null,function*(){if(!kr)throw new Error("Async storage not set");try{yield kr.setItem(hu(h),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}})}function c3(h){return Ue(this,null,function*(){if(!kr)throw new Error("Async storage not set");try{const n=yield kr.getItem(su(h));return n?JSON.parse(n):null}catch(n){return null}})}function v3(h,n){return Ue(this,null,function*(){if(!kr)throw new Error("Async storage not set");try{yield kr.setItem(su(h),JSON.stringify(n))}catch(o){}})}const p3=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:c3,loadCachedFlags:l3,saveCachedContext:v3,saveCachedFlags:d3,setAsyncCacheStorage:u3},Symbol.toStringTag,{value:"Module"}));typeof globalThis.Buffer=="undefined"&&(globalThis.Buffer=gr.Buffer);exports.FlagClient=o3;exports.LongPollingTransport=xh;exports.WebSocketTransport=_h;exports.asyncCache=p3;exports.evaluateFlagValue=tu;exports.evaluateRollout=Qo;exports.hashToPercentage=j0;exports.pickVariant=jo;exports.syncCache=f3;
@@ -20136,7 +20136,7 @@ class m3 {
20136
20136
  loadContext: tu,
20137
20137
  saveContext: eu
20138
20138
  }, this.context = n.context || {}, this.rawFlags = (f = n.rawFlags) != null ? f : {}, this.previewMode = n.previewMode || !1, this.previewMode && this.rawFlags && Object.keys(this.rawFlags).length > 0) {
20139
- this.flags = this.evaluateLocally(this.rawFlags, this.context), this.readyPromise = Promise.resolve(), this.resolveReady = () => {
20139
+ this.flags = this.rawFlags, this.flags = this.evaluateLocally(this.rawFlags, this.context), this.readyPromise = Promise.resolve(), this.resolveReady = () => {
20140
20140
  }, this.rejectReady = () => {
20141
20141
  };
20142
20142
  return;
@@ -20190,7 +20190,7 @@ class m3 {
20190
20190
  }), m = () => {
20191
20191
  console.log("[FlagClient] Using long polling transport...");
20192
20192
  const g = new gu(a3, this.apiKey, this.context, {
20193
- pollIntervalMs: 1e4
20193
+ pollIntervalMs: 2e4
20194
20194
  // Default polling interval
20195
20195
  });
20196
20196
  return g.init((y) => {
@@ -20207,37 +20207,66 @@ class m3 {
20207
20207
  else
20208
20208
  try {
20209
20209
  this.transport = yield s();
20210
- } catch (y) {
20210
+ } catch (g) {
20211
20211
  console.warn("[FlagClient] WebSocket failed, falling back to long polling"), this.transport = m();
20212
20212
  }
20213
- const g = yield this.transport.fetchFlags(this.context);
20214
- this.flags = g, this.enableOfflineCache && (yield Promise.resolve(
20215
- this.cacheAdapter.saveFlags(this.apiKey, g)
20216
- )), typeof this.transport.onFlagsUpdated == "function" && this.transport.onFlagsUpdated((y) => {
20217
- this.flags = y, this.enableOfflineCache && this.cacheAdapter.saveFlags(this.apiKey, y);
20213
+ this.flags = yield this.transport.fetchFlags(this.context), this.enableOfflineCache && (yield Promise.resolve(
20214
+ this.cacheAdapter.saveFlags(this.apiKey, this.flags)
20215
+ )), typeof this.transport.onFlagsUpdated == "function" && this.transport.onFlagsUpdated((g) => {
20216
+ this.flags = g, this.enableOfflineCache && this.cacheAdapter.saveFlags(this.apiKey, g);
20218
20217
  }), this.resolveReady();
20219
20218
  } catch (g) {
20220
20219
  throw console.error("[FlagClient] setupTransport error:", g), this.rejectReady(g), this.onError && this.onError(g instanceof Error ? g : new Error(String(g))), g;
20221
20220
  }
20222
20221
  });
20223
20222
  }
20223
+ /**
20224
+ * Gets the value of a feature flag by its key, with an optional fallback value.
20225
+ * @param key
20226
+ * @param fallback
20227
+ * @returns The value of the feature flag, or the fallback value if the flag is not set.
20228
+ * @template K - The key of the feature flag.
20229
+ * @template T - The type of the feature flags.
20230
+ */
20224
20231
  getFlag(n, o) {
20225
20232
  var s;
20226
20233
  return (s = this.flags[n]) != null ? s : o;
20227
20234
  }
20235
+ /**
20236
+ * Updates the client context and optionally persists it to cache.
20237
+ * @param context - The new context to set.
20238
+ * @returns void
20239
+ */
20228
20240
  updateContext(n) {
20229
20241
  this.context = uf(uf({}, this.context), n), this.persistContext && this.cacheAdapter.saveContext(this.apiKey, this.context);
20230
20242
  }
20243
+ /**
20244
+ * Destroys the client, clearing the refresh interval and transport.
20245
+ * @returns void
20246
+ */
20231
20247
  destroy() {
20232
20248
  this.refreshIntervalId && clearInterval(this.refreshIntervalId), this.transport.destroy();
20233
20249
  }
20250
+ /**
20251
+ * Returns a promise that resolves when the client is ready.
20252
+ * This is useful for ensuring that the client is fully initialized before using it.
20253
+ * */
20234
20254
  ready() {
20235
20255
  return Ue(this, null, function* () {
20236
20256
  return this.readyPromise;
20237
20257
  });
20238
20258
  }
20259
+ /**
20260
+ * Evaluates flags locally based on the provided context.
20261
+ * This method is used when preview mode is enabled and raw flags are provided.
20262
+ * It evaluates each flag value against the context and returns a record of evaluated flags.
20263
+ * @param flags
20264
+ * @param context
20265
+ * @returns
20266
+ */
20239
20267
  evaluateLocally(n, o) {
20240
20268
  const s = {};
20269
+ console.log("[FlagClient] Evaluating flags locally with context:", n, o);
20241
20270
  for (const m in n) {
20242
20271
  const f = i3(n[m], o);
20243
20272
  f !== null && (s[m] = f);
@@ -15,4 +15,4 @@ Use Chrome, Firefox or Internet Explorer 11`)}var Gu=zt.Buffer,cn=qt.crypto||qt.
15
15
  `)},L0}var xo;function c2(){return xo||(xo=1,function(h){var n=h;n.der=wo(),n.pem=d2()}(N0)),N0}var _o;function sn(){return _o||(_o=1,function(h){var n=h;n.bignum=f2,n.define=a2().define,n.base=hn(),n.constants=vo(),n.decoders=l2(),n.encoders=c2()}(I0)),I0}var ar=sn(),So=ar.define("Time",function(){this.choice({utcTime:this.utctime(),generalTime:this.gentime()})}),v2=ar.define("AttributeTypeValue",function(){this.seq().obj(this.key("type").objid(),this.key("value").any())}),O0=ar.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional(),this.key("curve").objid().optional())}),p2=ar.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(O0),this.key("subjectPublicKey").bitstr())}),m2=ar.define("RelativeDistinguishedName",function(){this.setof(v2)}),g2=ar.define("RDNSequence",function(){this.seqof(m2)}),Ao=ar.define("Name",function(){this.choice({rdnSequence:this.use(g2)})}),b2=ar.define("Validity",function(){this.seq().obj(this.key("notBefore").use(So),this.key("notAfter").use(So))}),y2=ar.define("Extension",function(){this.seq().obj(this.key("extnID").objid(),this.key("critical").bool().def(!1),this.key("extnValue").octstr())}),w2=ar.define("TBSCertificate",function(){this.seq().obj(this.key("version").explicit(0).int().optional(),this.key("serialNumber").int(),this.key("signature").use(O0),this.key("issuer").use(Ao),this.key("validity").use(b2),this.key("subject").use(Ao),this.key("subjectPublicKeyInfo").use(p2),this.key("issuerUniqueID").implicit(1).bitstr().optional(),this.key("subjectUniqueID").implicit(2).bitstr().optional(),this.key("extensions").explicit(3).seqof(y2).optional())}),M2=ar.define("X509Certificate",function(){this.seq().obj(this.key("tbsCertificate").use(w2),this.key("signatureAlgorithm").use(O0),this.key("signatureValue").bitstr())}),x2=M2,hr=sn();fr.certificate=x2;var _2=hr.define("RSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("modulus").int(),this.key("publicExponent").int(),this.key("privateExponent").int(),this.key("prime1").int(),this.key("prime2").int(),this.key("exponent1").int(),this.key("exponent2").int(),this.key("coefficient").int())});fr.RSAPrivateKey=_2;var S2=hr.define("RSAPublicKey",function(){this.seq().obj(this.key("modulus").int(),this.key("publicExponent").int())});fr.RSAPublicKey=S2;var Bo=hr.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("none").null_().optional(),this.key("curve").objid().optional(),this.key("params").seq().obj(this.key("p").int(),this.key("q").int(),this.key("g").int()).optional())}),A2=hr.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(Bo),this.key("subjectPublicKey").bitstr())});fr.PublicKey=A2;var B2=hr.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").use(Bo),this.key("subjectPrivateKey").octstr())});fr.PrivateKey=B2;var E2=hr.define("EncryptedPrivateKeyInfo",function(){this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(),this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(),this.key("kdeparams").seq().obj(this.key("salt").octstr(),this.key("iters").int())),this.key("cipher").seq().obj(this.key("algo").objid(),this.key("iv").octstr()))),this.key("subjectPrivateKey").octstr())});fr.EncryptedPrivateKey=E2;var I2=hr.define("DSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("p").int(),this.key("q").int(),this.key("g").int(),this.key("pub_key").int(),this.key("priv_key").int())});fr.DSAPrivateKey=I2,fr.DSAparam=hr.define("DSAparam",function(){this.int()});var k2=hr.define("ECParameters",function(){this.choice({namedCurve:this.objid()})}),R2=hr.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").optional().explicit(0).use(k2),this.key("publicKey").optional().explicit(1).bitstr())});fr.ECPrivateKey=R2,fr.signature=hr.define("signature",function(){this.seq().obj(this.key("r").int(),this.key("s").int())});const T2={"2.16.840.1.101.3.4.1.1":"aes-128-ecb","2.16.840.1.101.3.4.1.2":"aes-128-cbc","2.16.840.1.101.3.4.1.3":"aes-128-ofb","2.16.840.1.101.3.4.1.4":"aes-128-cfb","2.16.840.1.101.3.4.1.21":"aes-192-ecb","2.16.840.1.101.3.4.1.22":"aes-192-cbc","2.16.840.1.101.3.4.1.23":"aes-192-ofb","2.16.840.1.101.3.4.1.24":"aes-192-cfb","2.16.840.1.101.3.4.1.41":"aes-256-ecb","2.16.840.1.101.3.4.1.42":"aes-256-cbc","2.16.840.1.101.3.4.1.43":"aes-256-ofb","2.16.840.1.101.3.4.1.44":"aes-256-cfb"};var C2=/Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m,q2=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m,F2=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m,P2=Ln,D2=He,uf=zt.Buffer,$2=function(h,n){var u=h.toString(),s=u.match(C2),m;if(s){var g="aes"+s[1],y=uf.from(s[2],"hex"),S=uf.from(s[3].replace(/[\r\n]/g,""),"base64"),E=P2(n,y.slice(0,8),parseInt(s[1],10)).key,M=[],x=D2.createDecipheriv(g,E,y);M.push(x.update(S)),M.push(x.final()),m=uf.concat(M)}else{var f=u.match(F2);m=uf.from(f[2].replace(/[\r\n]/g,""),"base64")}var k=u.match(q2)[1];return{tag:k,data:m}},Oe=fr,N2=T2,U2=$2,L2=He,O2=_n,z0=zt.Buffer;function z2(h,n){var u=h.algorithm.decrypt.kde.kdeparams.salt,s=parseInt(h.algorithm.decrypt.kde.kdeparams.iters.toString(),10),m=N2[h.algorithm.decrypt.cipher.algo.join(".")],f=h.algorithm.decrypt.cipher.iv,g=h.subjectPrivateKey,y=parseInt(m.split("-")[1],10)/8,S=O2.pbkdf2Sync(n,u,s,y,"sha1"),E=L2.createDecipheriv(m,S,f),M=[];return M.push(E.update(g)),M.push(E.final()),z0.concat(M)}function Eo(h){var n;typeof h=="object"&&!z0.isBuffer(h)&&(n=h.passphrase,h=h.key),typeof h=="string"&&(h=z0.from(h));var u=U2(h,n),s=u.tag,m=u.data,f,g;switch(s){case"CERTIFICATE":g=Oe.certificate.decode(m,"der").tbsCertificate.subjectPublicKeyInfo;case"PUBLIC KEY":switch(g||(g=Oe.PublicKey.decode(m,"der")),f=g.algorithm.algorithm.join("."),f){case"1.2.840.113549.1.1.1":return Oe.RSAPublicKey.decode(g.subjectPublicKey.data,"der");case"1.2.840.10045.2.1":return g.subjectPrivateKey=g.subjectPublicKey,{type:"ec",data:g};case"1.2.840.10040.4.1":return g.algorithm.params.pub_key=Oe.DSAparam.decode(g.subjectPublicKey.data,"der"),{type:"dsa",data:g.algorithm.params};default:throw new Error("unknown key id "+f)}case"ENCRYPTED PRIVATE KEY":m=Oe.EncryptedPrivateKey.decode(m,"der"),m=z2(m,n);case"PRIVATE KEY":switch(g=Oe.PrivateKey.decode(m,"der"),f=g.algorithm.algorithm.join("."),f){case"1.2.840.113549.1.1.1":return Oe.RSAPrivateKey.decode(g.subjectPrivateKey,"der");case"1.2.840.10045.2.1":return{curve:g.algorithm.curve,privateKey:Oe.ECPrivateKey.decode(g.subjectPrivateKey,"der").privateKey};case"1.2.840.10040.4.1":return g.algorithm.params.priv_key=Oe.DSAparam.decode(g.subjectPrivateKey,"der"),{type:"dsa",params:g.algorithm.params};default:throw new Error("unknown key id "+f)}case"RSA PUBLIC KEY":return Oe.RSAPublicKey.decode(m,"der");case"RSA PRIVATE KEY":return Oe.RSAPrivateKey.decode(m,"der");case"DSA PRIVATE KEY":return{type:"dsa",params:Oe.DSAPrivateKey.decode(m,"der")};case"EC PRIVATE KEY":return m=Oe.ECPrivateKey.decode(m,"der"),{curve:m.parameters.value,privateKey:m.privateKey};default:throw new Error("unknown key type "+s)}}Eo.signature=Oe.signature;var lf=Eo;const Io={"1.3.132.0.10":"secp256k1","1.3.132.0.33":"p224","1.2.840.10045.3.1.1":"p192","1.2.840.10045.3.1.7":"p256","1.3.132.0.34":"p384","1.3.132.0.35":"p521"};var ko;function K2(){if(ko)return en.exports;ko=1;var h=zt.Buffer,n=La,u=u0,s=E0().ec,m=o0,f=lf,g=Io,y=1;function S(z,N,lt,H,At){var Bt=f(N);if(Bt.curve){if(H!=="ecdsa"&&H!=="ecdsa/rsa")throw new Error("wrong private key type");return E(z,Bt)}else if(Bt.type==="dsa"){if(H!=="dsa")throw new Error("wrong private key type");return M(z,Bt,lt)}if(H!=="rsa"&&H!=="ecdsa/rsa")throw new Error("wrong private key type");if(N.padding!==void 0&&N.padding!==y)throw new Error("illegal or unsupported padding mode");z=h.concat([At,z]);for(var Ct=Bt.modulus.byteLength(),Et=[0,1];z.length+Et.length+1<Ct;)Et.push(255);Et.push(0);for(var Y=-1;++Y<z.length;)Et.push(z[Y]);var kt=u(Et,Bt);return kt}function E(z,N){var lt=g[N.curve.join(".")];if(!lt)throw new Error("unknown curve "+N.curve.join("."));var H=new s(lt),At=H.keyFromPrivate(N.privateKey),Bt=At.sign(z);return h.from(Bt.toDER())}function M(z,N,lt){for(var H=N.params.priv_key,At=N.params.p,Bt=N.params.q,Ct=N.params.g,Et=new m(0),Y,kt=I(z,Bt).mod(Bt),p=!1,t=k(H,Bt,z,lt);p===!1;)Y=L(Bt,t,lt),Et=W(Ct,Y,At,Bt),p=Y.invm(Bt).imul(kt.add(H.mul(Et))).mod(Bt),p.cmpn(0)===0&&(p=!1,Et=new m(0));return x(Et,p)}function x(z,N){z=z.toArray(),N=N.toArray(),z[0]&128&&(z=[0].concat(z)),N[0]&128&&(N=[0].concat(N));var lt=z.length+N.length+4,H=[48,lt,2,z.length];return H=H.concat(z,[2,N.length],N),h.from(H)}function k(z,N,lt,H){if(z=h.from(z.toArray()),z.length<N.byteLength()){var At=h.alloc(N.byteLength()-z.length);z=h.concat([At,z])}var Bt=lt.length,Ct=D(lt,N),Et=h.alloc(Bt);Et.fill(1);var Y=h.alloc(Bt);return Y=n(H,Y).update(Et).update(h.from([0])).update(z).update(Ct).digest(),Et=n(H,Y).update(Et).digest(),Y=n(H,Y).update(Et).update(h.from([1])).update(z).update(Ct).digest(),Et=n(H,Y).update(Et).digest(),{k:Y,v:Et}}function I(z,N){var lt=new m(z),H=(z.length<<3)-N.bitLength();return H>0&&lt.ishrn(H),lt}function D(z,N){z=I(z,N),z=z.mod(N);var lt=h.from(z.toArray());if(lt.length<N.byteLength()){var H=h.alloc(N.byteLength()-lt.length);lt=h.concat([H,lt])}return lt}function L(z,N,lt){var H,At;do{for(H=h.alloc(0);H.length*8<z.bitLength();)N.v=n(lt,N.k).update(N.v).digest(),H=h.concat([H,N.v]);At=I(H,z),N.k=n(lt,N.k).update(N.v).update(h.from([0])).digest(),N.v=n(lt,N.k).update(N.v).digest()}while(At.cmp(z)!==-1);return At}function W(z,N,lt,H){return z.toRed(m.mont(lt)).redPow(N).fromRed().mod(H)}return en.exports=S,en.exports.getKey=k,en.exports.makeKey=L,en.exports}var K0,Ro;function H2(){if(Ro)return K0;Ro=1;var h=zt.Buffer,n=o0,u=E0().ec,s=lf,m=Io;function f(E,M,x,k,I){var D=s(x);if(D.type==="ec"){if(k!=="ecdsa"&&k!=="ecdsa/rsa")throw new Error("wrong public key type");return g(E,M,D)}else if(D.type==="dsa"){if(k!=="dsa")throw new Error("wrong public key type");return y(E,M,D)}if(k!=="rsa"&&k!=="ecdsa/rsa")throw new Error("wrong public key type");M=h.concat([I,M]);for(var L=D.modulus.byteLength(),W=[1],z=0;M.length+W.length+2<L;)W.push(255),z+=1;W.push(0);for(var N=-1;++N<M.length;)W.push(M[N]);W=h.from(W);var lt=n.mont(D.modulus);E=new n(E).toRed(lt),E=E.redPow(new n(D.publicExponent)),E=h.from(E.fromRed().toArray());var H=z<8?1:0;for(L=Math.min(E.length,W.length),E.length!==W.length&&(H=1),N=-1;++N<L;)H|=E[N]^W[N];return H===0}function g(E,M,x){var k=m[x.data.algorithm.curve.join(".")];if(!k)throw new Error("unknown curve "+x.data.algorithm.curve.join("."));var I=new u(k),D=x.data.subjectPrivateKey.data;return I.verify(M,E,D)}function y(E,M,x){var k=x.data.p,I=x.data.q,D=x.data.g,L=x.data.pub_key,W=s.signature.decode(E,"der"),z=W.s,N=W.r;S(z,I),S(N,I);var lt=n.mont(k),H=z.invm(I),At=D.toRed(lt).redPow(new n(M).mul(H).mod(I)).fromRed().mul(L.toRed(lt).redPow(N.mul(H).mod(I)).fromRed()).mod(k).mod(I);return At.cmp(N)===0}function S(E,M){if(E.cmpn(0)<=0)throw new Error("invalid sig");if(E.cmp(M)>=0)throw new Error("invalid sig")}return K0=f,K0}var H0,To;function Z2(){if(To)return H0;To=1;var h=zt.Buffer,n=Ki,u=ev,s=Kt,m=K2(),f=H2(),g=Oa;Object.keys(g).forEach(function(x){g[x].id=h.from(g[x].id,"hex"),g[x.toLowerCase()]=g[x]});function y(x){u.Writable.call(this);var k=g[x];if(!k)throw new Error("Unknown message digest");this._hashType=k.hash,this._hash=n(k.hash),this._tag=k.id,this._signType=k.sign}s(y,u.Writable),y.prototype._write=function(k,I,D){this._hash.update(k),D()},y.prototype.update=function(k,I){return this._hash.update(typeof k=="string"?h.from(k,I):k),this},y.prototype.sign=function(k,I){this.end();var D=this._hash.digest(),L=m(D,k,this._hashType,this._signType,this._tag);return I?L.toString(I):L};function S(x){u.Writable.call(this);var k=g[x];if(!k)throw new Error("Unknown message digest");this._hash=n(k.hash),this._tag=k.id,this._signType=k.sign}s(S,u.Writable),S.prototype._write=function(k,I,D){this._hash.update(k),D()},S.prototype.update=function(k,I){return this._hash.update(typeof k=="string"?h.from(k,I):k),this},S.prototype.verify=function(k,I,D){var L=typeof I=="string"?h.from(I,D):I;this.end();var W=this._hash.digest();return f(L,W,k,this._signType,this._tag)};function E(x){return new y(x)}function M(x){return new S(x)}return H0={Sign:E,Verify:M,createSign:E,createVerify:M},H0}var Z0={exports:{}};Z0.exports,function(h){(function(n,u){function s(p,t){if(!p)throw new Error(t||"Assertion failed")}function m(p,t){p.super_=t;var r=function(){};r.prototype=t.prototype,p.prototype=new r,p.prototype.constructor=p}function f(p,t,r){if(f.isBN(p))return p;this.negative=0,this.words=null,this.length=0,this.red=null,p!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(p||0,t||10,r||"be"))}typeof n=="object"?n.exports=f:u.BN=f,f.BN=f,f.wordSize=26;var g;try{typeof window!="undefined"&&typeof window.Buffer!="undefined"?g=window.Buffer:g=De.Buffer}catch(p){}f.isBN=function(t){return t instanceof f?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===f.wordSize&&Array.isArray(t.words)},f.max=function(t,r){return t.cmp(r)>0?t:r},f.min=function(t,r){return t.cmp(r)<0?t:r},f.prototype._init=function(t,r,i){if(typeof t=="number")return this._initNumber(t,r,i);if(typeof t=="object")return this._initArray(t,r,i);r==="hex"&&(r=16),s(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var a=0;t[0]==="-"&&(a++,this.negative=1),a<t.length&&(r===16?this._parseHex(t,a,i):(this._parseBase(t,r,a),i==="le"&&this._initArray(this.toArray(),r,i)))},f.prototype._initNumber=function(t,r,i){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(s(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),i==="le"&&this._initArray(this.toArray(),r,i)},f.prototype._initArray=function(t,r,i){if(s(typeof t.length=="number"),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 a=0;a<this.length;a++)this.words[a]=0;var d,c,v=0;if(i==="be")for(a=t.length-1,d=0;a>=0;a-=3)c=t[a]|t[a-1]<<8|t[a-2]<<16,this.words[d]|=c<<v&67108863,this.words[d+1]=c>>>26-v&67108863,v+=24,v>=26&&(v-=26,d++);else if(i==="le")for(a=0,d=0;a<t.length;a+=3)c=t[a]|t[a+1]<<8|t[a+2]<<16,this.words[d]|=c<<v&67108863,this.words[d+1]=c>>>26-v&67108863,v+=24,v>=26&&(v-=26,d++);return this.strip()};function y(p,t){var r=p.charCodeAt(t);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function S(p,t,r){var i=y(p,r);return r-1>=t&&(i|=y(p,r-1)<<4),i}f.prototype._parseHex=function(t,r,i){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var a=0;a<this.length;a++)this.words[a]=0;var d=0,c=0,v;if(i==="be")for(a=t.length-1;a>=r;a-=2)v=S(t,r,a)<<d,this.words[c]|=v&67108863,d>=18?(d-=18,c+=1,this.words[c]|=v>>>26):d+=8;else{var o=t.length-r;for(a=o%2===0?r+1:r;a<t.length;a+=2)v=S(t,r,a)<<d,this.words[c]|=v&67108863,d>=18?(d-=18,c+=1,this.words[c]|=v>>>26):d+=8}this.strip()};function E(p,t,r,i){for(var a=0,d=Math.min(p.length,r),c=t;c<d;c++){var v=p.charCodeAt(c)-48;a*=i,v>=49?a+=v-49+10:v>=17?a+=v-17+10:a+=v}return a}f.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var a=0,d=1;d<=67108863;d*=r)a++;a--,d=d/r|0;for(var c=t.length-i,v=c%a,o=Math.min(c,c-v)+i,e=0,l=i;l<o;l+=a)e=E(t,l,l+a,r),this.imuln(d),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);if(v!==0){var b=1;for(e=E(t,l,t.length,r),l=0;l<v;l++)b*=r;this.imuln(b),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e)}this.strip()},f.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red},f.prototype.clone=function(){var t=new f(null);return this.copy(t),t},f.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},f.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},f.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},f.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var M=["","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"],x=[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],k=[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];f.prototype.toString=function(t,r){t=t||10,r=r|0||1;var i;if(t===16||t==="hex"){i="";for(var a=0,d=0,c=0;c<this.length;c++){var v=this.words[c],o=((v<<a|d)&16777215).toString(16);d=v>>>24-a&16777215,a+=2,a>=26&&(a-=26,c--),d!==0||c!==this.length-1?i=M[6-o.length]+o+i:i=o+i}for(d!==0&&(i=d.toString(16)+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var e=x[t],l=k[t];i="";var b=this.clone();for(b.negative=0;!b.isZero();){var _=b.modn(l).toString(t);b=b.idivn(l),b.isZero()?i=_+i:i=M[e-_.length]+_+i}for(this.isZero()&&(i="0"+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}s(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&s(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(t,r){return s(typeof g!="undefined"),this.toArrayLike(g,t,r)},f.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},f.prototype.toArrayLike=function(t,r,i){var a=this.byteLength(),d=i||Math.max(1,a);s(a<=d,"byte array longer than desired length"),s(d>0,"Requested array length <= 0"),this.strip();var c=r==="le",v=new t(d),o,e,l=this.clone();if(c){for(e=0;!l.isZero();e++)o=l.andln(255),l.iushrn(8),v[e]=o;for(;e<d;e++)v[e]=0}else{for(e=0;e<d-a;e++)v[e]=0;for(e=0;!l.isZero();e++)o=l.andln(255),l.iushrn(8),v[d-e-1]=o}return v},Math.clz32?f.prototype._countBits=function(t){return 32-Math.clz32(t)}:f.prototype._countBits=function(t){var r=t,i=0;return r>=4096&&(i+=13,r>>>=13),r>=64&&(i+=7,r>>>=7),r>=8&&(i+=4,r>>>=4),r>=2&&(i+=2,r>>>=2),i+r},f.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,i=0;return r&8191||(i+=13,r>>>=13),r&127||(i+=7,r>>>=7),r&15||(i+=4,r>>>=4),r&3||(i+=2,r>>>=2),r&1||i++,i},f.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return(this.length-1)*26+r};function I(p){for(var t=new Array(p.bitLength()),r=0;r<t.length;r++){var i=r/26|0,a=r%26;t[r]=(p.words[i]&1<<a)>>>a}return t}f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var i=this._zeroBits(this.words[r]);if(t+=i,i!==26)break}return t},f.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},f.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},f.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},f.prototype.isNeg=function(){return this.negative!==0},f.prototype.neg=function(){return this.clone().ineg()},f.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},f.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this.strip()},f.prototype.ior=function(t){return s((this.negative|t.negative)===0),this.iuor(t)},f.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},f.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},f.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var i=0;i<r.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=r.length,this.strip()},f.prototype.iand=function(t){return s((this.negative|t.negative)===0),this.iuand(t)},f.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},f.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},f.prototype.iuxor=function(t){var r,i;this.length>t.length?(r=this,i=t):(r=t,i=this);for(var a=0;a<i.length;a++)this.words[a]=r.words[a]^i.words[a];if(this!==r)for(;a<r.length;a++)this.words[a]=r.words[a];return this.length=r.length,this.strip()},f.prototype.ixor=function(t){return s((this.negative|t.negative)===0),this.iuxor(t)},f.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},f.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},f.prototype.inotn=function(t){s(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,i=t%26;this._expand(r),i>0&&r--;for(var a=0;a<r;a++)this.words[a]=~this.words[a]&67108863;return i>0&&(this.words[a]=~this.words[a]&67108863>>26-i),this.strip()},f.prototype.notn=function(t){return this.clone().inotn(t)},f.prototype.setn=function(t,r){s(typeof t=="number"&&t>=0);var i=t/26|0,a=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<a:this.words[i]=this.words[i]&~(1<<a),this.strip()},f.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var i,a;this.length>t.length?(i=this,a=t):(i=t,a=this);for(var d=0,c=0;c<a.length;c++)r=(i.words[c]|0)+(a.words[c]|0)+d,this.words[c]=r&67108863,d=r>>>26;for(;d!==0&&c<i.length;c++)r=(i.words[c]|0)+d,this.words[c]=r&67108863,d=r>>>26;if(this.length=i.length,d!==0)this.words[this.length]=d,this.length++;else if(i!==this)for(;c<i.length;c++)this.words[c]=i.words[c];return this},f.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},f.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i=this.cmp(t);if(i===0)return this.negative=0,this.length=1,this.words[0]=0,this;var a,d;i>0?(a=this,d=t):(a=t,d=this);for(var c=0,v=0;v<d.length;v++)r=(a.words[v]|0)-(d.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;for(;c!==0&&v<a.length;v++)r=(a.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;if(c===0&&v<a.length&&a!==this)for(;v<a.length;v++)this.words[v]=a.words[v];return this.length=Math.max(this.length,v),a!==this&&(this.negative=1),this.strip()},f.prototype.sub=function(t){return this.clone().isub(t)};function D(p,t,r){r.negative=t.negative^p.negative;var i=p.length+t.length|0;r.length=i,i=i-1|0;var a=p.words[0]|0,d=t.words[0]|0,c=a*d,v=c&67108863,o=c/67108864|0;r.words[0]=v;for(var e=1;e<i;e++){for(var l=o>>>26,b=o&67108863,_=Math.min(e,t.length-1),C=Math.max(0,e-p.length+1);C<=_;C++){var F=e-C|0;a=p.words[F]|0,d=t.words[C]|0,c=a*d+b,l+=c/67108864|0,b=c&67108863}r.words[e]=b|0,o=l|0}return o!==0?r.words[e]=o|0:r.length--,r.strip()}var L=function(t,r,i){var a=t.words,d=r.words,c=i.words,v=0,o,e,l,b=a[0]|0,_=b&8191,C=b>>>13,F=a[1]|0,O=F&8191,R=F>>>13,P=a[2]|0,$=P&8191,K=P>>>13,It=a[3]|0,Z=It&8191,J=It>>>13,Ft=a[4]|0,tt=Ft&8191,vt=Ft>>>13,$t=a[5]|0,et=$t&8191,pt=$t>>>13,Dt=a[6]|0,j=Dt&8191,dt=Dt>>>13,Pt=a[7]|0,Q=Pt&8191,ct=Pt>>>13,Ot=a[8]|0,B=Ot&8191,w=Ot>>>13,A=a[9]|0,T=A&8191,q=A>>>13,V=d[0]|0,U=V&8191,X=V>>>13,Tt=d[1]|0,G=Tt&8191,rt=Tt>>>13,Rt=d[2]|0,it=Rt&8191,gt=Rt>>>13,Ht=d[3]|0,nt=Ht&8191,bt=Ht>>>13,Zt=d[4]|0,ft=Zt&8191,yt=Zt>>>13,Wt=d[5]|0,at=Wt&8191,wt=Wt>>>13,Vt=d[6]|0,ht=Vt&8191,Mt=Vt>>>13,Yt=d[7]|0,st=Yt&8191,xt=Yt>>>13,Jt=d[8]|0,ot=Jt&8191,_t=Jt>>>13,Gt=d[9]|0,ut=Gt&8191,St=Gt>>>13;i.negative=t.negative^r.negative,i.length=19,o=Math.imul(_,U),e=Math.imul(_,X),e=e+Math.imul(C,U)|0,l=Math.imul(C,X);var Nt=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,o=Math.imul(O,U),e=Math.imul(O,X),e=e+Math.imul(R,U)|0,l=Math.imul(R,X),o=o+Math.imul(_,G)|0,e=e+Math.imul(_,rt)|0,e=e+Math.imul(C,G)|0,l=l+Math.imul(C,rt)|0;var Ut=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,o=Math.imul($,U),e=Math.imul($,X),e=e+Math.imul(K,U)|0,l=Math.imul(K,X),o=o+Math.imul(O,G)|0,e=e+Math.imul(O,rt)|0,e=e+Math.imul(R,G)|0,l=l+Math.imul(R,rt)|0,o=o+Math.imul(_,it)|0,e=e+Math.imul(_,gt)|0,e=e+Math.imul(C,it)|0,l=l+Math.imul(C,gt)|0;var jt=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(jt>>>26)|0,jt&=67108863,o=Math.imul(Z,U),e=Math.imul(Z,X),e=e+Math.imul(J,U)|0,l=Math.imul(J,X),o=o+Math.imul($,G)|0,e=e+Math.imul($,rt)|0,e=e+Math.imul(K,G)|0,l=l+Math.imul(K,rt)|0,o=o+Math.imul(O,it)|0,e=e+Math.imul(O,gt)|0,e=e+Math.imul(R,it)|0,l=l+Math.imul(R,gt)|0,o=o+Math.imul(_,nt)|0,e=e+Math.imul(_,bt)|0,e=e+Math.imul(C,nt)|0,l=l+Math.imul(C,bt)|0;var Qt=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,o=Math.imul(tt,U),e=Math.imul(tt,X),e=e+Math.imul(vt,U)|0,l=Math.imul(vt,X),o=o+Math.imul(Z,G)|0,e=e+Math.imul(Z,rt)|0,e=e+Math.imul(J,G)|0,l=l+Math.imul(J,rt)|0,o=o+Math.imul($,it)|0,e=e+Math.imul($,gt)|0,e=e+Math.imul(K,it)|0,l=l+Math.imul(K,gt)|0,o=o+Math.imul(O,nt)|0,e=e+Math.imul(O,bt)|0,e=e+Math.imul(R,nt)|0,l=l+Math.imul(R,bt)|0,o=o+Math.imul(_,ft)|0,e=e+Math.imul(_,yt)|0,e=e+Math.imul(C,ft)|0,l=l+Math.imul(C,yt)|0;var te=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(te>>>26)|0,te&=67108863,o=Math.imul(et,U),e=Math.imul(et,X),e=e+Math.imul(pt,U)|0,l=Math.imul(pt,X),o=o+Math.imul(tt,G)|0,e=e+Math.imul(tt,rt)|0,e=e+Math.imul(vt,G)|0,l=l+Math.imul(vt,rt)|0,o=o+Math.imul(Z,it)|0,e=e+Math.imul(Z,gt)|0,e=e+Math.imul(J,it)|0,l=l+Math.imul(J,gt)|0,o=o+Math.imul($,nt)|0,e=e+Math.imul($,bt)|0,e=e+Math.imul(K,nt)|0,l=l+Math.imul(K,bt)|0,o=o+Math.imul(O,ft)|0,e=e+Math.imul(O,yt)|0,e=e+Math.imul(R,ft)|0,l=l+Math.imul(R,yt)|0,o=o+Math.imul(_,at)|0,e=e+Math.imul(_,wt)|0,e=e+Math.imul(C,at)|0,l=l+Math.imul(C,wt)|0;var ee=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,o=Math.imul(j,U),e=Math.imul(j,X),e=e+Math.imul(dt,U)|0,l=Math.imul(dt,X),o=o+Math.imul(et,G)|0,e=e+Math.imul(et,rt)|0,e=e+Math.imul(pt,G)|0,l=l+Math.imul(pt,rt)|0,o=o+Math.imul(tt,it)|0,e=e+Math.imul(tt,gt)|0,e=e+Math.imul(vt,it)|0,l=l+Math.imul(vt,gt)|0,o=o+Math.imul(Z,nt)|0,e=e+Math.imul(Z,bt)|0,e=e+Math.imul(J,nt)|0,l=l+Math.imul(J,bt)|0,o=o+Math.imul($,ft)|0,e=e+Math.imul($,yt)|0,e=e+Math.imul(K,ft)|0,l=l+Math.imul(K,yt)|0,o=o+Math.imul(O,at)|0,e=e+Math.imul(O,wt)|0,e=e+Math.imul(R,at)|0,l=l+Math.imul(R,wt)|0,o=o+Math.imul(_,ht)|0,e=e+Math.imul(_,Mt)|0,e=e+Math.imul(C,ht)|0,l=l+Math.imul(C,Mt)|0;var re=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(re>>>26)|0,re&=67108863,o=Math.imul(Q,U),e=Math.imul(Q,X),e=e+Math.imul(ct,U)|0,l=Math.imul(ct,X),o=o+Math.imul(j,G)|0,e=e+Math.imul(j,rt)|0,e=e+Math.imul(dt,G)|0,l=l+Math.imul(dt,rt)|0,o=o+Math.imul(et,it)|0,e=e+Math.imul(et,gt)|0,e=e+Math.imul(pt,it)|0,l=l+Math.imul(pt,gt)|0,o=o+Math.imul(tt,nt)|0,e=e+Math.imul(tt,bt)|0,e=e+Math.imul(vt,nt)|0,l=l+Math.imul(vt,bt)|0,o=o+Math.imul(Z,ft)|0,e=e+Math.imul(Z,yt)|0,e=e+Math.imul(J,ft)|0,l=l+Math.imul(J,yt)|0,o=o+Math.imul($,at)|0,e=e+Math.imul($,wt)|0,e=e+Math.imul(K,at)|0,l=l+Math.imul(K,wt)|0,o=o+Math.imul(O,ht)|0,e=e+Math.imul(O,Mt)|0,e=e+Math.imul(R,ht)|0,l=l+Math.imul(R,Mt)|0,o=o+Math.imul(_,st)|0,e=e+Math.imul(_,xt)|0,e=e+Math.imul(C,st)|0,l=l+Math.imul(C,xt)|0;var ie=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,o=Math.imul(B,U),e=Math.imul(B,X),e=e+Math.imul(w,U)|0,l=Math.imul(w,X),o=o+Math.imul(Q,G)|0,e=e+Math.imul(Q,rt)|0,e=e+Math.imul(ct,G)|0,l=l+Math.imul(ct,rt)|0,o=o+Math.imul(j,it)|0,e=e+Math.imul(j,gt)|0,e=e+Math.imul(dt,it)|0,l=l+Math.imul(dt,gt)|0,o=o+Math.imul(et,nt)|0,e=e+Math.imul(et,bt)|0,e=e+Math.imul(pt,nt)|0,l=l+Math.imul(pt,bt)|0,o=o+Math.imul(tt,ft)|0,e=e+Math.imul(tt,yt)|0,e=e+Math.imul(vt,ft)|0,l=l+Math.imul(vt,yt)|0,o=o+Math.imul(Z,at)|0,e=e+Math.imul(Z,wt)|0,e=e+Math.imul(J,at)|0,l=l+Math.imul(J,wt)|0,o=o+Math.imul($,ht)|0,e=e+Math.imul($,Mt)|0,e=e+Math.imul(K,ht)|0,l=l+Math.imul(K,Mt)|0,o=o+Math.imul(O,st)|0,e=e+Math.imul(O,xt)|0,e=e+Math.imul(R,st)|0,l=l+Math.imul(R,xt)|0,o=o+Math.imul(_,ot)|0,e=e+Math.imul(_,_t)|0,e=e+Math.imul(C,ot)|0,l=l+Math.imul(C,_t)|0;var ne=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,o=Math.imul(T,U),e=Math.imul(T,X),e=e+Math.imul(q,U)|0,l=Math.imul(q,X),o=o+Math.imul(B,G)|0,e=e+Math.imul(B,rt)|0,e=e+Math.imul(w,G)|0,l=l+Math.imul(w,rt)|0,o=o+Math.imul(Q,it)|0,e=e+Math.imul(Q,gt)|0,e=e+Math.imul(ct,it)|0,l=l+Math.imul(ct,gt)|0,o=o+Math.imul(j,nt)|0,e=e+Math.imul(j,bt)|0,e=e+Math.imul(dt,nt)|0,l=l+Math.imul(dt,bt)|0,o=o+Math.imul(et,ft)|0,e=e+Math.imul(et,yt)|0,e=e+Math.imul(pt,ft)|0,l=l+Math.imul(pt,yt)|0,o=o+Math.imul(tt,at)|0,e=e+Math.imul(tt,wt)|0,e=e+Math.imul(vt,at)|0,l=l+Math.imul(vt,wt)|0,o=o+Math.imul(Z,ht)|0,e=e+Math.imul(Z,Mt)|0,e=e+Math.imul(J,ht)|0,l=l+Math.imul(J,Mt)|0,o=o+Math.imul($,st)|0,e=e+Math.imul($,xt)|0,e=e+Math.imul(K,st)|0,l=l+Math.imul(K,xt)|0,o=o+Math.imul(O,ot)|0,e=e+Math.imul(O,_t)|0,e=e+Math.imul(R,ot)|0,l=l+Math.imul(R,_t)|0,o=o+Math.imul(_,ut)|0,e=e+Math.imul(_,St)|0,e=e+Math.imul(C,ut)|0,l=l+Math.imul(C,St)|0;var fe=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(fe>>>26)|0,fe&=67108863,o=Math.imul(T,G),e=Math.imul(T,rt),e=e+Math.imul(q,G)|0,l=Math.imul(q,rt),o=o+Math.imul(B,it)|0,e=e+Math.imul(B,gt)|0,e=e+Math.imul(w,it)|0,l=l+Math.imul(w,gt)|0,o=o+Math.imul(Q,nt)|0,e=e+Math.imul(Q,bt)|0,e=e+Math.imul(ct,nt)|0,l=l+Math.imul(ct,bt)|0,o=o+Math.imul(j,ft)|0,e=e+Math.imul(j,yt)|0,e=e+Math.imul(dt,ft)|0,l=l+Math.imul(dt,yt)|0,o=o+Math.imul(et,at)|0,e=e+Math.imul(et,wt)|0,e=e+Math.imul(pt,at)|0,l=l+Math.imul(pt,wt)|0,o=o+Math.imul(tt,ht)|0,e=e+Math.imul(tt,Mt)|0,e=e+Math.imul(vt,ht)|0,l=l+Math.imul(vt,Mt)|0,o=o+Math.imul(Z,st)|0,e=e+Math.imul(Z,xt)|0,e=e+Math.imul(J,st)|0,l=l+Math.imul(J,xt)|0,o=o+Math.imul($,ot)|0,e=e+Math.imul($,_t)|0,e=e+Math.imul(K,ot)|0,l=l+Math.imul(K,_t)|0,o=o+Math.imul(O,ut)|0,e=e+Math.imul(O,St)|0,e=e+Math.imul(R,ut)|0,l=l+Math.imul(R,St)|0;var ae=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,o=Math.imul(T,it),e=Math.imul(T,gt),e=e+Math.imul(q,it)|0,l=Math.imul(q,gt),o=o+Math.imul(B,nt)|0,e=e+Math.imul(B,bt)|0,e=e+Math.imul(w,nt)|0,l=l+Math.imul(w,bt)|0,o=o+Math.imul(Q,ft)|0,e=e+Math.imul(Q,yt)|0,e=e+Math.imul(ct,ft)|0,l=l+Math.imul(ct,yt)|0,o=o+Math.imul(j,at)|0,e=e+Math.imul(j,wt)|0,e=e+Math.imul(dt,at)|0,l=l+Math.imul(dt,wt)|0,o=o+Math.imul(et,ht)|0,e=e+Math.imul(et,Mt)|0,e=e+Math.imul(pt,ht)|0,l=l+Math.imul(pt,Mt)|0,o=o+Math.imul(tt,st)|0,e=e+Math.imul(tt,xt)|0,e=e+Math.imul(vt,st)|0,l=l+Math.imul(vt,xt)|0,o=o+Math.imul(Z,ot)|0,e=e+Math.imul(Z,_t)|0,e=e+Math.imul(J,ot)|0,l=l+Math.imul(J,_t)|0,o=o+Math.imul($,ut)|0,e=e+Math.imul($,St)|0,e=e+Math.imul(K,ut)|0,l=l+Math.imul(K,St)|0;var he=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(he>>>26)|0,he&=67108863,o=Math.imul(T,nt),e=Math.imul(T,bt),e=e+Math.imul(q,nt)|0,l=Math.imul(q,bt),o=o+Math.imul(B,ft)|0,e=e+Math.imul(B,yt)|0,e=e+Math.imul(w,ft)|0,l=l+Math.imul(w,yt)|0,o=o+Math.imul(Q,at)|0,e=e+Math.imul(Q,wt)|0,e=e+Math.imul(ct,at)|0,l=l+Math.imul(ct,wt)|0,o=o+Math.imul(j,ht)|0,e=e+Math.imul(j,Mt)|0,e=e+Math.imul(dt,ht)|0,l=l+Math.imul(dt,Mt)|0,o=o+Math.imul(et,st)|0,e=e+Math.imul(et,xt)|0,e=e+Math.imul(pt,st)|0,l=l+Math.imul(pt,xt)|0,o=o+Math.imul(tt,ot)|0,e=e+Math.imul(tt,_t)|0,e=e+Math.imul(vt,ot)|0,l=l+Math.imul(vt,_t)|0,o=o+Math.imul(Z,ut)|0,e=e+Math.imul(Z,St)|0,e=e+Math.imul(J,ut)|0,l=l+Math.imul(J,St)|0;var se=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(se>>>26)|0,se&=67108863,o=Math.imul(T,ft),e=Math.imul(T,yt),e=e+Math.imul(q,ft)|0,l=Math.imul(q,yt),o=o+Math.imul(B,at)|0,e=e+Math.imul(B,wt)|0,e=e+Math.imul(w,at)|0,l=l+Math.imul(w,wt)|0,o=o+Math.imul(Q,ht)|0,e=e+Math.imul(Q,Mt)|0,e=e+Math.imul(ct,ht)|0,l=l+Math.imul(ct,Mt)|0,o=o+Math.imul(j,st)|0,e=e+Math.imul(j,xt)|0,e=e+Math.imul(dt,st)|0,l=l+Math.imul(dt,xt)|0,o=o+Math.imul(et,ot)|0,e=e+Math.imul(et,_t)|0,e=e+Math.imul(pt,ot)|0,l=l+Math.imul(pt,_t)|0,o=o+Math.imul(tt,ut)|0,e=e+Math.imul(tt,St)|0,e=e+Math.imul(vt,ut)|0,l=l+Math.imul(vt,St)|0;var oe=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(oe>>>26)|0,oe&=67108863,o=Math.imul(T,at),e=Math.imul(T,wt),e=e+Math.imul(q,at)|0,l=Math.imul(q,wt),o=o+Math.imul(B,ht)|0,e=e+Math.imul(B,Mt)|0,e=e+Math.imul(w,ht)|0,l=l+Math.imul(w,Mt)|0,o=o+Math.imul(Q,st)|0,e=e+Math.imul(Q,xt)|0,e=e+Math.imul(ct,st)|0,l=l+Math.imul(ct,xt)|0,o=o+Math.imul(j,ot)|0,e=e+Math.imul(j,_t)|0,e=e+Math.imul(dt,ot)|0,l=l+Math.imul(dt,_t)|0,o=o+Math.imul(et,ut)|0,e=e+Math.imul(et,St)|0,e=e+Math.imul(pt,ut)|0,l=l+Math.imul(pt,St)|0;var ue=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ue>>>26)|0,ue&=67108863,o=Math.imul(T,ht),e=Math.imul(T,Mt),e=e+Math.imul(q,ht)|0,l=Math.imul(q,Mt),o=o+Math.imul(B,st)|0,e=e+Math.imul(B,xt)|0,e=e+Math.imul(w,st)|0,l=l+Math.imul(w,xt)|0,o=o+Math.imul(Q,ot)|0,e=e+Math.imul(Q,_t)|0,e=e+Math.imul(ct,ot)|0,l=l+Math.imul(ct,_t)|0,o=o+Math.imul(j,ut)|0,e=e+Math.imul(j,St)|0,e=e+Math.imul(dt,ut)|0,l=l+Math.imul(dt,St)|0;var le=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(le>>>26)|0,le&=67108863,o=Math.imul(T,st),e=Math.imul(T,xt),e=e+Math.imul(q,st)|0,l=Math.imul(q,xt),o=o+Math.imul(B,ot)|0,e=e+Math.imul(B,_t)|0,e=e+Math.imul(w,ot)|0,l=l+Math.imul(w,_t)|0,o=o+Math.imul(Q,ut)|0,e=e+Math.imul(Q,St)|0,e=e+Math.imul(ct,ut)|0,l=l+Math.imul(ct,St)|0;var de=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(de>>>26)|0,de&=67108863,o=Math.imul(T,ot),e=Math.imul(T,_t),e=e+Math.imul(q,ot)|0,l=Math.imul(q,_t),o=o+Math.imul(B,ut)|0,e=e+Math.imul(B,St)|0,e=e+Math.imul(w,ut)|0,l=l+Math.imul(w,St)|0;var ce=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ce>>>26)|0,ce&=67108863,o=Math.imul(T,ut),e=Math.imul(T,St),e=e+Math.imul(q,ut)|0,l=Math.imul(q,St);var ve=(v+o|0)+((e&8191)<<13)|0;return v=(l+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,c[0]=Nt,c[1]=Ut,c[2]=jt,c[3]=Qt,c[4]=te,c[5]=ee,c[6]=re,c[7]=ie,c[8]=ne,c[9]=fe,c[10]=ae,c[11]=he,c[12]=se,c[13]=oe,c[14]=ue,c[15]=le,c[16]=de,c[17]=ce,c[18]=ve,v!==0&&(c[19]=v,i.length++),i};Math.imul||(L=D);function W(p,t,r){r.negative=t.negative^p.negative,r.length=p.length+t.length;for(var i=0,a=0,d=0;d<r.length-1;d++){var c=a;a=0;for(var v=i&67108863,o=Math.min(d,t.length-1),e=Math.max(0,d-p.length+1);e<=o;e++){var l=d-e,b=p.words[l]|0,_=t.words[e]|0,C=b*_,F=C&67108863;c=c+(C/67108864|0)|0,F=F+v|0,v=F&67108863,c=c+(F>>>26)|0,a+=c>>>26,c&=67108863}r.words[d]=v,i=c,c=a}return i!==0?r.words[d]=i:r.length--,r.strip()}function z(p,t,r){var i=new N;return i.mulp(p,t,r)}f.prototype.mulTo=function(t,r){var i,a=this.length+t.length;return this.length===10&&t.length===10?i=L(this,t,r):a<63?i=D(this,t,r):a<1024?i=W(this,t,r):i=z(this,t,r),i};function N(p,t){this.x=p,this.y=t}N.prototype.makeRBT=function(t){for(var r=new Array(t),i=f.prototype._countBits(t)-1,a=0;a<t;a++)r[a]=this.revBin(a,i,t);return r},N.prototype.revBin=function(t,r,i){if(t===0||t===i-1)return t;for(var a=0,d=0;d<r;d++)a|=(t&1)<<r-d-1,t>>=1;return a},N.prototype.permute=function(t,r,i,a,d,c){for(var v=0;v<c;v++)a[v]=r[t[v]],d[v]=i[t[v]]},N.prototype.transform=function(t,r,i,a,d,c){this.permute(c,t,r,i,a,d);for(var v=1;v<d;v<<=1)for(var o=v<<1,e=Math.cos(2*Math.PI/o),l=Math.sin(2*Math.PI/o),b=0;b<d;b+=o)for(var _=e,C=l,F=0;F<v;F++){var O=i[b+F],R=a[b+F],P=i[b+F+v],$=a[b+F+v],K=_*P-C*$;$=_*$+C*P,P=K,i[b+F]=O+P,a[b+F]=R+$,i[b+F+v]=O-P,a[b+F+v]=R-$,F!==o&&(K=e*_-l*C,C=e*C+l*_,_=K)}},N.prototype.guessLen13b=function(t,r){var i=Math.max(r,t)|1,a=i&1,d=0;for(i=i/2|0;i;i=i>>>1)d++;return 1<<d+1+a},N.prototype.conjugate=function(t,r,i){if(!(i<=1))for(var a=0;a<i/2;a++){var d=t[a];t[a]=t[i-a-1],t[i-a-1]=d,d=r[a],r[a]=-r[i-a-1],r[i-a-1]=-d}},N.prototype.normalize13b=function(t,r){for(var i=0,a=0;a<r/2;a++){var d=Math.round(t[2*a+1]/r)*8192+Math.round(t[2*a]/r)+i;t[a]=d&67108863,d<67108864?i=0:i=d/67108864|0}return t},N.prototype.convert13b=function(t,r,i,a){for(var d=0,c=0;c<r;c++)d=d+(t[c]|0),i[2*c]=d&8191,d=d>>>13,i[2*c+1]=d&8191,d=d>>>13;for(c=2*r;c<a;++c)i[c]=0;s(d===0),s((d&-8192)===0)},N.prototype.stub=function(t){for(var r=new Array(t),i=0;i<t;i++)r[i]=0;return r},N.prototype.mulp=function(t,r,i){var a=2*this.guessLen13b(t.length,r.length),d=this.makeRBT(a),c=this.stub(a),v=new Array(a),o=new Array(a),e=new Array(a),l=new Array(a),b=new Array(a),_=new Array(a),C=i.words;C.length=a,this.convert13b(t.words,t.length,v,a),this.convert13b(r.words,r.length,l,a),this.transform(v,c,o,e,a,d),this.transform(l,c,b,_,a,d);for(var F=0;F<a;F++){var O=o[F]*b[F]-e[F]*_[F];e[F]=o[F]*_[F]+e[F]*b[F],o[F]=O}return this.conjugate(o,e,a),this.transform(o,e,C,c,a,d),this.conjugate(C,c,a),this.normalize13b(C,a),i.negative=t.negative^r.negative,i.length=t.length+r.length,i.strip()},f.prototype.mul=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},f.prototype.mulf=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),z(this,t,r)},f.prototype.imul=function(t){return this.clone().mulTo(t,this)},f.prototype.imuln=function(t){s(typeof t=="number"),s(t<67108864);for(var r=0,i=0;i<this.length;i++){var a=(this.words[i]|0)*t,d=(a&67108863)+(r&67108863);r>>=26,r+=a/67108864|0,r+=d>>>26,this.words[i]=d&67108863}return r!==0&&(this.words[i]=r,this.length++),this.length=t===0?1:this.length,this},f.prototype.muln=function(t){return this.clone().imuln(t)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(t){var r=I(t);if(r.length===0)return new f(1);for(var i=this,a=0;a<r.length&&r[a]===0;a++,i=i.sqr());if(++a<r.length)for(var d=i.sqr();a<r.length;a++,d=d.sqr())r[a]!==0&&(i=i.mul(d));return i},f.prototype.iushln=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,a=67108863>>>26-r<<26-r,d;if(r!==0){var c=0;for(d=0;d<this.length;d++){var v=this.words[d]&a,o=(this.words[d]|0)-v<<r;this.words[d]=o|c,c=v>>>26-r}c&&(this.words[d]=c,this.length++)}if(i!==0){for(d=this.length-1;d>=0;d--)this.words[d+i]=this.words[d];for(d=0;d<i;d++)this.words[d]=0;this.length+=i}return this.strip()},f.prototype.ishln=function(t){return s(this.negative===0),this.iushln(t)},f.prototype.iushrn=function(t,r,i){s(typeof t=="number"&&t>=0);var a;r?a=(r-r%26)/26:a=0;var d=t%26,c=Math.min((t-d)/26,this.length),v=67108863^67108863>>>d<<d,o=i;if(a-=c,a=Math.max(0,a),o){for(var e=0;e<c;e++)o.words[e]=this.words[e];o.length=c}if(c!==0)if(this.length>c)for(this.length-=c,e=0;e<this.length;e++)this.words[e]=this.words[e+c];else this.words[0]=0,this.length=1;var l=0;for(e=this.length-1;e>=0&&(l!==0||e>=a);e--){var b=this.words[e]|0;this.words[e]=l<<26-d|b>>>d,l=b&v}return o&&l!==0&&(o.words[o.length++]=l),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},f.prototype.ishrn=function(t,r,i){return s(this.negative===0),this.iushrn(t,r,i)},f.prototype.shln=function(t){return this.clone().ishln(t)},f.prototype.ushln=function(t){return this.clone().iushln(t)},f.prototype.shrn=function(t){return this.clone().ishrn(t)},f.prototype.ushrn=function(t){return this.clone().iushrn(t)},f.prototype.testn=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,a=1<<r;if(this.length<=i)return!1;var d=this.words[i];return!!(d&a)},f.prototype.imaskn=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26;if(s(this.negative===0,"imaskn works only with positive numbers"),this.length<=i)return this;if(r!==0&&i++,this.length=Math.min(i,this.length),r!==0){var a=67108863^67108863>>>r<<r;this.words[this.length-1]&=a}return this.strip()},f.prototype.maskn=function(t){return this.clone().imaskn(t)},f.prototype.iaddn=function(t){return s(typeof t=="number"),s(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},f.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},f.prototype.isubn=function(t){if(s(typeof t=="number"),s(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this.strip()},f.prototype.addn=function(t){return this.clone().iaddn(t)},f.prototype.subn=function(t){return this.clone().isubn(t)},f.prototype.iabs=function(){return this.negative=0,this},f.prototype.abs=function(){return this.clone().iabs()},f.prototype._ishlnsubmul=function(t,r,i){var a=t.length+i,d;this._expand(a);var c,v=0;for(d=0;d<t.length;d++){c=(this.words[d+i]|0)+v;var o=(t.words[d]|0)*r;c-=o&67108863,v=(c>>26)-(o/67108864|0),this.words[d+i]=c&67108863}for(;d<this.length-i;d++)c=(this.words[d+i]|0)+v,v=c>>26,this.words[d+i]=c&67108863;if(v===0)return this.strip();for(s(v===-1),v=0,d=0;d<this.length;d++)c=-(this.words[d]|0)+v,v=c>>26,this.words[d]=c&67108863;return this.negative=1,this.strip()},f.prototype._wordDiv=function(t,r){var i=this.length-t.length,a=this.clone(),d=t,c=d.words[d.length-1]|0,v=this._countBits(c);i=26-v,i!==0&&(d=d.ushln(i),a.iushln(i),c=d.words[d.length-1]|0);var o=a.length-d.length,e;if(r!=="mod"){e=new f(null),e.length=o+1,e.words=new Array(e.length);for(var l=0;l<e.length;l++)e.words[l]=0}var b=a.clone()._ishlnsubmul(d,1,o);b.negative===0&&(a=b,e&&(e.words[o]=1));for(var _=o-1;_>=0;_--){var C=(a.words[d.length+_]|0)*67108864+(a.words[d.length+_-1]|0);for(C=Math.min(C/c|0,67108863),a._ishlnsubmul(d,C,_);a.negative!==0;)C--,a.negative=0,a._ishlnsubmul(d,1,_),a.isZero()||(a.negative^=1);e&&(e.words[_]=C)}return e&&e.strip(),a.strip(),r!=="div"&&i!==0&&a.iushrn(i),{div:e||null,mod:a}},f.prototype.divmod=function(t,r,i){if(s(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var a,d,c;return this.negative!==0&&t.negative===0?(c=this.neg().divmod(t,r),r!=="mod"&&(a=c.div.neg()),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.iadd(t)),{div:a,mod:d}):this.negative===0&&t.negative!==0?(c=this.divmod(t.neg(),r),r!=="mod"&&(a=c.div.neg()),{div:a,mod:c.mod}):this.negative&t.negative?(c=this.neg().divmod(t.neg(),r),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.isub(t)),{div:c.div,mod:d}):t.length>this.length||this.cmp(t)<0?{div:new f(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new f(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new f(this.modn(t.words[0]))}:this._wordDiv(t,r)},f.prototype.div=function(t){return this.divmod(t,"div",!1).div},f.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},f.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},f.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var i=r.div.negative!==0?r.mod.isub(t):r.mod,a=t.ushrn(1),d=t.andln(1),c=i.cmp(a);return c<0||d===1&&c===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},f.prototype.modn=function(t){s(t<=67108863);for(var r=(1<<26)%t,i=0,a=this.length-1;a>=0;a--)i=(r*i+(this.words[a]|0))%t;return i},f.prototype.idivn=function(t){s(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var a=(this.words[i]|0)+r*67108864;this.words[i]=a/t|0,r=a%t}return this.strip()},f.prototype.divn=function(t){return this.clone().idivn(t)},f.prototype.egcd=function(t){s(t.negative===0),s(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var a=new f(1),d=new f(0),c=new f(0),v=new f(1),o=0;r.isEven()&&i.isEven();)r.iushrn(1),i.iushrn(1),++o;for(var e=i.clone(),l=r.clone();!r.isZero();){for(var b=0,_=1;!(r.words[0]&_)&&b<26;++b,_<<=1);if(b>0)for(r.iushrn(b);b-- >0;)(a.isOdd()||d.isOdd())&&(a.iadd(e),d.isub(l)),a.iushrn(1),d.iushrn(1);for(var C=0,F=1;!(i.words[0]&F)&&C<26;++C,F<<=1);if(C>0)for(i.iushrn(C);C-- >0;)(c.isOdd()||v.isOdd())&&(c.iadd(e),v.isub(l)),c.iushrn(1),v.iushrn(1);r.cmp(i)>=0?(r.isub(i),a.isub(c),d.isub(v)):(i.isub(r),c.isub(a),v.isub(d))}return{a:c,b:v,gcd:i.iushln(o)}},f.prototype._invmp=function(t){s(t.negative===0),s(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var a=new f(1),d=new f(0),c=i.clone();r.cmpn(1)>0&&i.cmpn(1)>0;){for(var v=0,o=1;!(r.words[0]&o)&&v<26;++v,o<<=1);if(v>0)for(r.iushrn(v);v-- >0;)a.isOdd()&&a.iadd(c),a.iushrn(1);for(var e=0,l=1;!(i.words[0]&l)&&e<26;++e,l<<=1);if(e>0)for(i.iushrn(e);e-- >0;)d.isOdd()&&d.iadd(c),d.iushrn(1);r.cmp(i)>=0?(r.isub(i),a.isub(d)):(i.isub(r),d.isub(a))}var b;return r.cmpn(1)===0?b=a:b=d,b.cmpn(0)<0&&b.iadd(t),b},f.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),i=t.clone();r.negative=0,i.negative=0;for(var a=0;r.isEven()&&i.isEven();a++)r.iushrn(1),i.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;i.isEven();)i.iushrn(1);var d=r.cmp(i);if(d<0){var c=r;r=i,i=c}else if(d===0||i.cmpn(1)===0)break;r.isub(i)}while(!0);return i.iushln(a)},f.prototype.invm=function(t){return this.egcd(t).a.umod(t)},f.prototype.isEven=function(){return(this.words[0]&1)===0},f.prototype.isOdd=function(){return(this.words[0]&1)===1},f.prototype.andln=function(t){return this.words[0]&t},f.prototype.bincn=function(t){s(typeof t=="number");var r=t%26,i=(t-r)/26,a=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=a,this;for(var d=a,c=i;d!==0&&c<this.length;c++){var v=this.words[c]|0;v+=d,d=v>>>26,v&=67108863,this.words[c]=v}return d!==0&&(this.words[c]=d,this.length++),this},f.prototype.isZero=function(){return this.length===1&&this.words[0]===0},f.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return-1;if(this.negative===0&&r)return 1;this.strip();var i;if(this.length>1)i=1;else{r&&(t=-t),s(t<=67108863,"Number is too big");var a=this.words[0]|0;i=a===t?0:a<t?-1:1}return this.negative!==0?-i|0:i},f.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return-1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},f.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var r=0,i=this.length-1;i>=0;i--){var a=this.words[i]|0,d=t.words[i]|0;if(a!==d){a<d?r=-1:a>d&&(r=1);break}}return r},f.prototype.gtn=function(t){return this.cmpn(t)===1},f.prototype.gt=function(t){return this.cmp(t)===1},f.prototype.gten=function(t){return this.cmpn(t)>=0},f.prototype.gte=function(t){return this.cmp(t)>=0},f.prototype.ltn=function(t){return this.cmpn(t)===-1},f.prototype.lt=function(t){return this.cmp(t)===-1},f.prototype.lten=function(t){return this.cmpn(t)<=0},f.prototype.lte=function(t){return this.cmp(t)<=0},f.prototype.eqn=function(t){return this.cmpn(t)===0},f.prototype.eq=function(t){return this.cmp(t)===0},f.red=function(t){return new Y(t)},f.prototype.toRed=function(t){return s(!this.red,"Already a number in reduction context"),s(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},f.prototype.fromRed=function(){return s(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(t){return this.red=t,this},f.prototype.forceRed=function(t){return s(!this.red,"Already a number in reduction context"),this._forceRed(t)},f.prototype.redAdd=function(t){return s(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},f.prototype.redIAdd=function(t){return s(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},f.prototype.redSub=function(t){return s(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},f.prototype.redISub=function(t){return s(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},f.prototype.redShl=function(t){return s(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},f.prototype.redMul=function(t){return s(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},f.prototype.redIMul=function(t){return s(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},f.prototype.redSqr=function(){return s(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return s(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return s(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return s(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return s(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(t){return s(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var lt={k256:null,p224:null,p192:null,p25519:null};function H(p,t){this.name=p,this.p=new f(t,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}H.prototype._tmp=function(){var t=new f(null);return t.words=new Array(Math.ceil(this.n/13)),t},H.prototype.ireduce=function(t){var r=t,i;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),i=r.bitLength();while(i>this.n);var a=i<this.n?-1:r.ucmp(this.p);return a===0?(r.words[0]=0,r.length=1):a>0?r.isub(this.p):r.strip!==void 0?r.strip():r._strip(),r},H.prototype.split=function(t,r){t.iushrn(this.n,0,r)},H.prototype.imulK=function(t){return t.imul(this.k)};function At(){H.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}m(At,H),At.prototype.split=function(t,r){for(var i=4194303,a=Math.min(t.length,9),d=0;d<a;d++)r.words[d]=t.words[d];if(r.length=a,t.length<=9){t.words[0]=0,t.length=1;return}var c=t.words[9];for(r.words[r.length++]=c&i,d=10;d<t.length;d++){var v=t.words[d]|0;t.words[d-10]=(v&i)<<4|c>>>22,c=v}c>>>=22,t.words[d-10]=c,c===0&&t.length>10?t.length-=10:t.length-=9},At.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,i=0;i<t.length;i++){var a=t.words[i]|0;r+=a*977,t.words[i]=r&67108863,r=a*64+(r/67108864|0)}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function Bt(){H.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}m(Bt,H);function Ct(){H.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}m(Ct,H);function Et(){H.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}m(Et,H),Et.prototype.imulK=function(t){for(var r=0,i=0;i<t.length;i++){var a=(t.words[i]|0)*19+r,d=a&67108863;a>>>=26,t.words[i]=d,r=a}return r!==0&&(t.words[t.length++]=r),t},f._prime=function(t){if(lt[t])return lt[t];var r;if(t==="k256")r=new At;else if(t==="p224")r=new Bt;else if(t==="p192")r=new Ct;else if(t==="p25519")r=new Et;else throw new Error("Unknown prime "+t);return lt[t]=r,r};function Y(p){if(typeof p=="string"){var t=f._prime(p);this.m=t.p,this.prime=t}else s(p.gtn(1),"modulus must be greater than 1"),this.m=p,this.prime=null}Y.prototype._verify1=function(t){s(t.negative===0,"red works only with positives"),s(t.red,"red works only with red numbers")},Y.prototype._verify2=function(t,r){s((t.negative|r.negative)===0,"red works only with positives"),s(t.red&&t.red===r.red,"red works only with red numbers")},Y.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},Y.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},Y.prototype.add=function(t,r){this._verify2(t,r);var i=t.add(r);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},Y.prototype.iadd=function(t,r){this._verify2(t,r);var i=t.iadd(r);return i.cmp(this.m)>=0&&i.isub(this.m),i},Y.prototype.sub=function(t,r){this._verify2(t,r);var i=t.sub(r);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},Y.prototype.isub=function(t,r){this._verify2(t,r);var i=t.isub(r);return i.cmpn(0)<0&&i.iadd(this.m),i},Y.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},Y.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},Y.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},Y.prototype.isqr=function(t){return this.imul(t,t.clone())},Y.prototype.sqr=function(t){return this.mul(t,t)},Y.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(s(r%2===1),r===3){var i=this.m.add(new f(1)).iushrn(2);return this.pow(t,i)}for(var a=this.m.subn(1),d=0;!a.isZero()&&a.andln(1)===0;)d++,a.iushrn(1);s(!a.isZero());var c=new f(1).toRed(this),v=c.redNeg(),o=this.m.subn(1).iushrn(1),e=this.m.bitLength();for(e=new f(2*e*e).toRed(this);this.pow(e,o).cmp(v)!==0;)e.redIAdd(v);for(var l=this.pow(e,a),b=this.pow(t,a.addn(1).iushrn(1)),_=this.pow(t,a),C=d;_.cmp(c)!==0;){for(var F=_,O=0;F.cmp(c)!==0;O++)F=F.redSqr();s(O<C);var R=this.pow(l,new f(1).iushln(C-O-1));b=b.redMul(R),l=R.redSqr(),_=_.redMul(l),C=O}return b},Y.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},Y.prototype.pow=function(t,r){if(r.isZero())return new f(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var i=4,a=new Array(1<<i);a[0]=new f(1).toRed(this),a[1]=t;for(var d=2;d<a.length;d++)a[d]=this.mul(a[d-1],t);var c=a[0],v=0,o=0,e=r.bitLength()%26;for(e===0&&(e=26),d=r.length-1;d>=0;d--){for(var l=r.words[d],b=e-1;b>=0;b--){var _=l>>b&1;if(c!==a[0]&&(c=this.sqr(c)),_===0&&v===0){o=0;continue}v<<=1,v|=_,o++,!(o!==i&&(d!==0||b!==0))&&(c=this.mul(c,a[v]),o=0,v=0)}e=26}return c},Y.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},Y.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},f.mont=function(t){return new kt(t)};function kt(p){Y.call(this,p),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}m(kt,Y),kt.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},kt.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},kt.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),a=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(a).iushrn(this.shift),c=d;return d.cmp(this.m)>=0?c=d.isub(this.m):d.cmpn(0)<0&&(c=d.iadd(this.m)),c._forceRed(this)},kt.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var i=t.mul(r),a=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(a).iushrn(this.shift),c=d;return d.cmp(this.m)>=0?c=d.isub(this.m):d.cmpn(0)<0&&(c=d.iadd(this.m)),c._forceRed(this)},kt.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(h,qt)}(Z0);var W2=Z0.exports,W0,Co;function V2(){if(Co)return W0;Co=1;var h=E0(),n=W2;W0=function(g){return new s(g)};var u={secp256k1:{name:"secp256k1",byteLength:32},secp224r1:{name:"p224",byteLength:28},prime256v1:{name:"p256",byteLength:32},prime192v1:{name:"p192",byteLength:24},ed25519:{name:"ed25519",byteLength:32},secp384r1:{name:"p384",byteLength:48},secp521r1:{name:"p521",byteLength:66}};u.p224=u.secp224r1,u.p256=u.secp256r1=u.prime256v1,u.p192=u.secp192r1=u.prime192v1,u.p384=u.secp384r1,u.p521=u.secp521r1;function s(f){this.curveType=u[f],this.curveType||(this.curveType={name:f}),this.curve=new h.ec(this.curveType.name),this.keys=void 0}s.prototype.generateKeys=function(f,g){return this.keys=this.curve.genKeyPair(),this.getPublicKey(f,g)},s.prototype.computeSecret=function(f,g,y){g=g||"utf8",mt.isBuffer(f)||(f=new mt(f,g));var S=this.curve.keyFromPublic(f).getPublic(),E=S.mul(this.keys.getPrivate()).getX();return m(E,y,this.curveType.byteLength)},s.prototype.getPublicKey=function(f,g){var y=this.keys.getPublic(g==="compressed",!0);return g==="hybrid"&&(y[y.length-1]%2?y[0]=7:y[0]=6),m(y,f)},s.prototype.getPrivateKey=function(f){return m(this.keys.getPrivate(),f)},s.prototype.setPublicKey=function(f,g){return g=g||"utf8",mt.isBuffer(f)||(f=new mt(f,g)),this.keys._importPublic(f),this},s.prototype.setPrivateKey=function(f,g){g=g||"utf8",mt.isBuffer(f)||(f=new mt(f,g));var y=new n(f);return y=y.toString(16),this.keys=this.curve.genKeyPair(),this.keys._importPrivate(y),this};function m(f,g,y){Array.isArray(f)||(f=f.toArray());var S=new mt(f);if(y&&S.length<y){var E=new mt(y-S.length);E.fill(0),S=mt.concat([E,S])}return g?S.toString(g):S}return W0}var qo={},Y2=Ki,V0=zt.Buffer,Fo=function(h,n){for(var u=V0.alloc(0),s=0,m;u.length<n;)m=J2(s++),u=V0.concat([u,Y2("sha1").update(h).update(m).digest()]);return u.slice(0,n)};function J2(h){var n=V0.allocUnsafe(4);return n.writeUInt32BE(h,0),n}var Po=function(n,u){for(var s=n.length,m=-1;++m<s;)n[m]^=u[m];return n},Y0={exports:{}};Y0.exports,function(h){(function(n,u){function s(p,t){if(!p)throw new Error(t||"Assertion failed")}function m(p,t){p.super_=t;var r=function(){};r.prototype=t.prototype,p.prototype=new r,p.prototype.constructor=p}function f(p,t,r){if(f.isBN(p))return p;this.negative=0,this.words=null,this.length=0,this.red=null,p!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(p||0,t||10,r||"be"))}typeof n=="object"?n.exports=f:u.BN=f,f.BN=f,f.wordSize=26;var g;try{typeof window!="undefined"&&typeof window.Buffer!="undefined"?g=window.Buffer:g=De.Buffer}catch(p){}f.isBN=function(t){return t instanceof f?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===f.wordSize&&Array.isArray(t.words)},f.max=function(t,r){return t.cmp(r)>0?t:r},f.min=function(t,r){return t.cmp(r)<0?t:r},f.prototype._init=function(t,r,i){if(typeof t=="number")return this._initNumber(t,r,i);if(typeof t=="object")return this._initArray(t,r,i);r==="hex"&&(r=16),s(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var a=0;t[0]==="-"&&(a++,this.negative=1),a<t.length&&(r===16?this._parseHex(t,a,i):(this._parseBase(t,r,a),i==="le"&&this._initArray(this.toArray(),r,i)))},f.prototype._initNumber=function(t,r,i){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(s(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),i==="le"&&this._initArray(this.toArray(),r,i)},f.prototype._initArray=function(t,r,i){if(s(typeof t.length=="number"),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 a=0;a<this.length;a++)this.words[a]=0;var d,c,v=0;if(i==="be")for(a=t.length-1,d=0;a>=0;a-=3)c=t[a]|t[a-1]<<8|t[a-2]<<16,this.words[d]|=c<<v&67108863,this.words[d+1]=c>>>26-v&67108863,v+=24,v>=26&&(v-=26,d++);else if(i==="le")for(a=0,d=0;a<t.length;a+=3)c=t[a]|t[a+1]<<8|t[a+2]<<16,this.words[d]|=c<<v&67108863,this.words[d+1]=c>>>26-v&67108863,v+=24,v>=26&&(v-=26,d++);return this.strip()};function y(p,t){var r=p.charCodeAt(t);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function S(p,t,r){var i=y(p,r);return r-1>=t&&(i|=y(p,r-1)<<4),i}f.prototype._parseHex=function(t,r,i){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var a=0;a<this.length;a++)this.words[a]=0;var d=0,c=0,v;if(i==="be")for(a=t.length-1;a>=r;a-=2)v=S(t,r,a)<<d,this.words[c]|=v&67108863,d>=18?(d-=18,c+=1,this.words[c]|=v>>>26):d+=8;else{var o=t.length-r;for(a=o%2===0?r+1:r;a<t.length;a+=2)v=S(t,r,a)<<d,this.words[c]|=v&67108863,d>=18?(d-=18,c+=1,this.words[c]|=v>>>26):d+=8}this.strip()};function E(p,t,r,i){for(var a=0,d=Math.min(p.length,r),c=t;c<d;c++){var v=p.charCodeAt(c)-48;a*=i,v>=49?a+=v-49+10:v>=17?a+=v-17+10:a+=v}return a}f.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var a=0,d=1;d<=67108863;d*=r)a++;a--,d=d/r|0;for(var c=t.length-i,v=c%a,o=Math.min(c,c-v)+i,e=0,l=i;l<o;l+=a)e=E(t,l,l+a,r),this.imuln(d),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);if(v!==0){var b=1;for(e=E(t,l,t.length,r),l=0;l<v;l++)b*=r;this.imuln(b),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e)}this.strip()},f.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red},f.prototype.clone=function(){var t=new f(null);return this.copy(t),t},f.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},f.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},f.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},f.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var M=["","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"],x=[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],k=[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];f.prototype.toString=function(t,r){t=t||10,r=r|0||1;var i;if(t===16||t==="hex"){i="";for(var a=0,d=0,c=0;c<this.length;c++){var v=this.words[c],o=((v<<a|d)&16777215).toString(16);d=v>>>24-a&16777215,a+=2,a>=26&&(a-=26,c--),d!==0||c!==this.length-1?i=M[6-o.length]+o+i:i=o+i}for(d!==0&&(i=d.toString(16)+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var e=x[t],l=k[t];i="";var b=this.clone();for(b.negative=0;!b.isZero();){var _=b.modn(l).toString(t);b=b.idivn(l),b.isZero()?i=_+i:i=M[e-_.length]+_+i}for(this.isZero()&&(i="0"+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}s(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&s(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(t,r){return s(typeof g!="undefined"),this.toArrayLike(g,t,r)},f.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},f.prototype.toArrayLike=function(t,r,i){var a=this.byteLength(),d=i||Math.max(1,a);s(a<=d,"byte array longer than desired length"),s(d>0,"Requested array length <= 0"),this.strip();var c=r==="le",v=new t(d),o,e,l=this.clone();if(c){for(e=0;!l.isZero();e++)o=l.andln(255),l.iushrn(8),v[e]=o;for(;e<d;e++)v[e]=0}else{for(e=0;e<d-a;e++)v[e]=0;for(e=0;!l.isZero();e++)o=l.andln(255),l.iushrn(8),v[d-e-1]=o}return v},Math.clz32?f.prototype._countBits=function(t){return 32-Math.clz32(t)}:f.prototype._countBits=function(t){var r=t,i=0;return r>=4096&&(i+=13,r>>>=13),r>=64&&(i+=7,r>>>=7),r>=8&&(i+=4,r>>>=4),r>=2&&(i+=2,r>>>=2),i+r},f.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,i=0;return r&8191||(i+=13,r>>>=13),r&127||(i+=7,r>>>=7),r&15||(i+=4,r>>>=4),r&3||(i+=2,r>>>=2),r&1||i++,i},f.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return(this.length-1)*26+r};function I(p){for(var t=new Array(p.bitLength()),r=0;r<t.length;r++){var i=r/26|0,a=r%26;t[r]=(p.words[i]&1<<a)>>>a}return t}f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var i=this._zeroBits(this.words[r]);if(t+=i,i!==26)break}return t},f.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},f.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},f.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},f.prototype.isNeg=function(){return this.negative!==0},f.prototype.neg=function(){return this.clone().ineg()},f.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},f.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this.strip()},f.prototype.ior=function(t){return s((this.negative|t.negative)===0),this.iuor(t)},f.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},f.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},f.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var i=0;i<r.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=r.length,this.strip()},f.prototype.iand=function(t){return s((this.negative|t.negative)===0),this.iuand(t)},f.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},f.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},f.prototype.iuxor=function(t){var r,i;this.length>t.length?(r=this,i=t):(r=t,i=this);for(var a=0;a<i.length;a++)this.words[a]=r.words[a]^i.words[a];if(this!==r)for(;a<r.length;a++)this.words[a]=r.words[a];return this.length=r.length,this.strip()},f.prototype.ixor=function(t){return s((this.negative|t.negative)===0),this.iuxor(t)},f.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},f.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},f.prototype.inotn=function(t){s(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,i=t%26;this._expand(r),i>0&&r--;for(var a=0;a<r;a++)this.words[a]=~this.words[a]&67108863;return i>0&&(this.words[a]=~this.words[a]&67108863>>26-i),this.strip()},f.prototype.notn=function(t){return this.clone().inotn(t)},f.prototype.setn=function(t,r){s(typeof t=="number"&&t>=0);var i=t/26|0,a=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<a:this.words[i]=this.words[i]&~(1<<a),this.strip()},f.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var i,a;this.length>t.length?(i=this,a=t):(i=t,a=this);for(var d=0,c=0;c<a.length;c++)r=(i.words[c]|0)+(a.words[c]|0)+d,this.words[c]=r&67108863,d=r>>>26;for(;d!==0&&c<i.length;c++)r=(i.words[c]|0)+d,this.words[c]=r&67108863,d=r>>>26;if(this.length=i.length,d!==0)this.words[this.length]=d,this.length++;else if(i!==this)for(;c<i.length;c++)this.words[c]=i.words[c];return this},f.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},f.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i=this.cmp(t);if(i===0)return this.negative=0,this.length=1,this.words[0]=0,this;var a,d;i>0?(a=this,d=t):(a=t,d=this);for(var c=0,v=0;v<d.length;v++)r=(a.words[v]|0)-(d.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;for(;c!==0&&v<a.length;v++)r=(a.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;if(c===0&&v<a.length&&a!==this)for(;v<a.length;v++)this.words[v]=a.words[v];return this.length=Math.max(this.length,v),a!==this&&(this.negative=1),this.strip()},f.prototype.sub=function(t){return this.clone().isub(t)};function D(p,t,r){r.negative=t.negative^p.negative;var i=p.length+t.length|0;r.length=i,i=i-1|0;var a=p.words[0]|0,d=t.words[0]|0,c=a*d,v=c&67108863,o=c/67108864|0;r.words[0]=v;for(var e=1;e<i;e++){for(var l=o>>>26,b=o&67108863,_=Math.min(e,t.length-1),C=Math.max(0,e-p.length+1);C<=_;C++){var F=e-C|0;a=p.words[F]|0,d=t.words[C]|0,c=a*d+b,l+=c/67108864|0,b=c&67108863}r.words[e]=b|0,o=l|0}return o!==0?r.words[e]=o|0:r.length--,r.strip()}var L=function(t,r,i){var a=t.words,d=r.words,c=i.words,v=0,o,e,l,b=a[0]|0,_=b&8191,C=b>>>13,F=a[1]|0,O=F&8191,R=F>>>13,P=a[2]|0,$=P&8191,K=P>>>13,It=a[3]|0,Z=It&8191,J=It>>>13,Ft=a[4]|0,tt=Ft&8191,vt=Ft>>>13,$t=a[5]|0,et=$t&8191,pt=$t>>>13,Dt=a[6]|0,j=Dt&8191,dt=Dt>>>13,Pt=a[7]|0,Q=Pt&8191,ct=Pt>>>13,Ot=a[8]|0,B=Ot&8191,w=Ot>>>13,A=a[9]|0,T=A&8191,q=A>>>13,V=d[0]|0,U=V&8191,X=V>>>13,Tt=d[1]|0,G=Tt&8191,rt=Tt>>>13,Rt=d[2]|0,it=Rt&8191,gt=Rt>>>13,Ht=d[3]|0,nt=Ht&8191,bt=Ht>>>13,Zt=d[4]|0,ft=Zt&8191,yt=Zt>>>13,Wt=d[5]|0,at=Wt&8191,wt=Wt>>>13,Vt=d[6]|0,ht=Vt&8191,Mt=Vt>>>13,Yt=d[7]|0,st=Yt&8191,xt=Yt>>>13,Jt=d[8]|0,ot=Jt&8191,_t=Jt>>>13,Gt=d[9]|0,ut=Gt&8191,St=Gt>>>13;i.negative=t.negative^r.negative,i.length=19,o=Math.imul(_,U),e=Math.imul(_,X),e=e+Math.imul(C,U)|0,l=Math.imul(C,X);var Nt=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,o=Math.imul(O,U),e=Math.imul(O,X),e=e+Math.imul(R,U)|0,l=Math.imul(R,X),o=o+Math.imul(_,G)|0,e=e+Math.imul(_,rt)|0,e=e+Math.imul(C,G)|0,l=l+Math.imul(C,rt)|0;var Ut=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,o=Math.imul($,U),e=Math.imul($,X),e=e+Math.imul(K,U)|0,l=Math.imul(K,X),o=o+Math.imul(O,G)|0,e=e+Math.imul(O,rt)|0,e=e+Math.imul(R,G)|0,l=l+Math.imul(R,rt)|0,o=o+Math.imul(_,it)|0,e=e+Math.imul(_,gt)|0,e=e+Math.imul(C,it)|0,l=l+Math.imul(C,gt)|0;var jt=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(jt>>>26)|0,jt&=67108863,o=Math.imul(Z,U),e=Math.imul(Z,X),e=e+Math.imul(J,U)|0,l=Math.imul(J,X),o=o+Math.imul($,G)|0,e=e+Math.imul($,rt)|0,e=e+Math.imul(K,G)|0,l=l+Math.imul(K,rt)|0,o=o+Math.imul(O,it)|0,e=e+Math.imul(O,gt)|0,e=e+Math.imul(R,it)|0,l=l+Math.imul(R,gt)|0,o=o+Math.imul(_,nt)|0,e=e+Math.imul(_,bt)|0,e=e+Math.imul(C,nt)|0,l=l+Math.imul(C,bt)|0;var Qt=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,o=Math.imul(tt,U),e=Math.imul(tt,X),e=e+Math.imul(vt,U)|0,l=Math.imul(vt,X),o=o+Math.imul(Z,G)|0,e=e+Math.imul(Z,rt)|0,e=e+Math.imul(J,G)|0,l=l+Math.imul(J,rt)|0,o=o+Math.imul($,it)|0,e=e+Math.imul($,gt)|0,e=e+Math.imul(K,it)|0,l=l+Math.imul(K,gt)|0,o=o+Math.imul(O,nt)|0,e=e+Math.imul(O,bt)|0,e=e+Math.imul(R,nt)|0,l=l+Math.imul(R,bt)|0,o=o+Math.imul(_,ft)|0,e=e+Math.imul(_,yt)|0,e=e+Math.imul(C,ft)|0,l=l+Math.imul(C,yt)|0;var te=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(te>>>26)|0,te&=67108863,o=Math.imul(et,U),e=Math.imul(et,X),e=e+Math.imul(pt,U)|0,l=Math.imul(pt,X),o=o+Math.imul(tt,G)|0,e=e+Math.imul(tt,rt)|0,e=e+Math.imul(vt,G)|0,l=l+Math.imul(vt,rt)|0,o=o+Math.imul(Z,it)|0,e=e+Math.imul(Z,gt)|0,e=e+Math.imul(J,it)|0,l=l+Math.imul(J,gt)|0,o=o+Math.imul($,nt)|0,e=e+Math.imul($,bt)|0,e=e+Math.imul(K,nt)|0,l=l+Math.imul(K,bt)|0,o=o+Math.imul(O,ft)|0,e=e+Math.imul(O,yt)|0,e=e+Math.imul(R,ft)|0,l=l+Math.imul(R,yt)|0,o=o+Math.imul(_,at)|0,e=e+Math.imul(_,wt)|0,e=e+Math.imul(C,at)|0,l=l+Math.imul(C,wt)|0;var ee=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,o=Math.imul(j,U),e=Math.imul(j,X),e=e+Math.imul(dt,U)|0,l=Math.imul(dt,X),o=o+Math.imul(et,G)|0,e=e+Math.imul(et,rt)|0,e=e+Math.imul(pt,G)|0,l=l+Math.imul(pt,rt)|0,o=o+Math.imul(tt,it)|0,e=e+Math.imul(tt,gt)|0,e=e+Math.imul(vt,it)|0,l=l+Math.imul(vt,gt)|0,o=o+Math.imul(Z,nt)|0,e=e+Math.imul(Z,bt)|0,e=e+Math.imul(J,nt)|0,l=l+Math.imul(J,bt)|0,o=o+Math.imul($,ft)|0,e=e+Math.imul($,yt)|0,e=e+Math.imul(K,ft)|0,l=l+Math.imul(K,yt)|0,o=o+Math.imul(O,at)|0,e=e+Math.imul(O,wt)|0,e=e+Math.imul(R,at)|0,l=l+Math.imul(R,wt)|0,o=o+Math.imul(_,ht)|0,e=e+Math.imul(_,Mt)|0,e=e+Math.imul(C,ht)|0,l=l+Math.imul(C,Mt)|0;var re=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(re>>>26)|0,re&=67108863,o=Math.imul(Q,U),e=Math.imul(Q,X),e=e+Math.imul(ct,U)|0,l=Math.imul(ct,X),o=o+Math.imul(j,G)|0,e=e+Math.imul(j,rt)|0,e=e+Math.imul(dt,G)|0,l=l+Math.imul(dt,rt)|0,o=o+Math.imul(et,it)|0,e=e+Math.imul(et,gt)|0,e=e+Math.imul(pt,it)|0,l=l+Math.imul(pt,gt)|0,o=o+Math.imul(tt,nt)|0,e=e+Math.imul(tt,bt)|0,e=e+Math.imul(vt,nt)|0,l=l+Math.imul(vt,bt)|0,o=o+Math.imul(Z,ft)|0,e=e+Math.imul(Z,yt)|0,e=e+Math.imul(J,ft)|0,l=l+Math.imul(J,yt)|0,o=o+Math.imul($,at)|0,e=e+Math.imul($,wt)|0,e=e+Math.imul(K,at)|0,l=l+Math.imul(K,wt)|0,o=o+Math.imul(O,ht)|0,e=e+Math.imul(O,Mt)|0,e=e+Math.imul(R,ht)|0,l=l+Math.imul(R,Mt)|0,o=o+Math.imul(_,st)|0,e=e+Math.imul(_,xt)|0,e=e+Math.imul(C,st)|0,l=l+Math.imul(C,xt)|0;var ie=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,o=Math.imul(B,U),e=Math.imul(B,X),e=e+Math.imul(w,U)|0,l=Math.imul(w,X),o=o+Math.imul(Q,G)|0,e=e+Math.imul(Q,rt)|0,e=e+Math.imul(ct,G)|0,l=l+Math.imul(ct,rt)|0,o=o+Math.imul(j,it)|0,e=e+Math.imul(j,gt)|0,e=e+Math.imul(dt,it)|0,l=l+Math.imul(dt,gt)|0,o=o+Math.imul(et,nt)|0,e=e+Math.imul(et,bt)|0,e=e+Math.imul(pt,nt)|0,l=l+Math.imul(pt,bt)|0,o=o+Math.imul(tt,ft)|0,e=e+Math.imul(tt,yt)|0,e=e+Math.imul(vt,ft)|0,l=l+Math.imul(vt,yt)|0,o=o+Math.imul(Z,at)|0,e=e+Math.imul(Z,wt)|0,e=e+Math.imul(J,at)|0,l=l+Math.imul(J,wt)|0,o=o+Math.imul($,ht)|0,e=e+Math.imul($,Mt)|0,e=e+Math.imul(K,ht)|0,l=l+Math.imul(K,Mt)|0,o=o+Math.imul(O,st)|0,e=e+Math.imul(O,xt)|0,e=e+Math.imul(R,st)|0,l=l+Math.imul(R,xt)|0,o=o+Math.imul(_,ot)|0,e=e+Math.imul(_,_t)|0,e=e+Math.imul(C,ot)|0,l=l+Math.imul(C,_t)|0;var ne=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,o=Math.imul(T,U),e=Math.imul(T,X),e=e+Math.imul(q,U)|0,l=Math.imul(q,X),o=o+Math.imul(B,G)|0,e=e+Math.imul(B,rt)|0,e=e+Math.imul(w,G)|0,l=l+Math.imul(w,rt)|0,o=o+Math.imul(Q,it)|0,e=e+Math.imul(Q,gt)|0,e=e+Math.imul(ct,it)|0,l=l+Math.imul(ct,gt)|0,o=o+Math.imul(j,nt)|0,e=e+Math.imul(j,bt)|0,e=e+Math.imul(dt,nt)|0,l=l+Math.imul(dt,bt)|0,o=o+Math.imul(et,ft)|0,e=e+Math.imul(et,yt)|0,e=e+Math.imul(pt,ft)|0,l=l+Math.imul(pt,yt)|0,o=o+Math.imul(tt,at)|0,e=e+Math.imul(tt,wt)|0,e=e+Math.imul(vt,at)|0,l=l+Math.imul(vt,wt)|0,o=o+Math.imul(Z,ht)|0,e=e+Math.imul(Z,Mt)|0,e=e+Math.imul(J,ht)|0,l=l+Math.imul(J,Mt)|0,o=o+Math.imul($,st)|0,e=e+Math.imul($,xt)|0,e=e+Math.imul(K,st)|0,l=l+Math.imul(K,xt)|0,o=o+Math.imul(O,ot)|0,e=e+Math.imul(O,_t)|0,e=e+Math.imul(R,ot)|0,l=l+Math.imul(R,_t)|0,o=o+Math.imul(_,ut)|0,e=e+Math.imul(_,St)|0,e=e+Math.imul(C,ut)|0,l=l+Math.imul(C,St)|0;var fe=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(fe>>>26)|0,fe&=67108863,o=Math.imul(T,G),e=Math.imul(T,rt),e=e+Math.imul(q,G)|0,l=Math.imul(q,rt),o=o+Math.imul(B,it)|0,e=e+Math.imul(B,gt)|0,e=e+Math.imul(w,it)|0,l=l+Math.imul(w,gt)|0,o=o+Math.imul(Q,nt)|0,e=e+Math.imul(Q,bt)|0,e=e+Math.imul(ct,nt)|0,l=l+Math.imul(ct,bt)|0,o=o+Math.imul(j,ft)|0,e=e+Math.imul(j,yt)|0,e=e+Math.imul(dt,ft)|0,l=l+Math.imul(dt,yt)|0,o=o+Math.imul(et,at)|0,e=e+Math.imul(et,wt)|0,e=e+Math.imul(pt,at)|0,l=l+Math.imul(pt,wt)|0,o=o+Math.imul(tt,ht)|0,e=e+Math.imul(tt,Mt)|0,e=e+Math.imul(vt,ht)|0,l=l+Math.imul(vt,Mt)|0,o=o+Math.imul(Z,st)|0,e=e+Math.imul(Z,xt)|0,e=e+Math.imul(J,st)|0,l=l+Math.imul(J,xt)|0,o=o+Math.imul($,ot)|0,e=e+Math.imul($,_t)|0,e=e+Math.imul(K,ot)|0,l=l+Math.imul(K,_t)|0,o=o+Math.imul(O,ut)|0,e=e+Math.imul(O,St)|0,e=e+Math.imul(R,ut)|0,l=l+Math.imul(R,St)|0;var ae=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,o=Math.imul(T,it),e=Math.imul(T,gt),e=e+Math.imul(q,it)|0,l=Math.imul(q,gt),o=o+Math.imul(B,nt)|0,e=e+Math.imul(B,bt)|0,e=e+Math.imul(w,nt)|0,l=l+Math.imul(w,bt)|0,o=o+Math.imul(Q,ft)|0,e=e+Math.imul(Q,yt)|0,e=e+Math.imul(ct,ft)|0,l=l+Math.imul(ct,yt)|0,o=o+Math.imul(j,at)|0,e=e+Math.imul(j,wt)|0,e=e+Math.imul(dt,at)|0,l=l+Math.imul(dt,wt)|0,o=o+Math.imul(et,ht)|0,e=e+Math.imul(et,Mt)|0,e=e+Math.imul(pt,ht)|0,l=l+Math.imul(pt,Mt)|0,o=o+Math.imul(tt,st)|0,e=e+Math.imul(tt,xt)|0,e=e+Math.imul(vt,st)|0,l=l+Math.imul(vt,xt)|0,o=o+Math.imul(Z,ot)|0,e=e+Math.imul(Z,_t)|0,e=e+Math.imul(J,ot)|0,l=l+Math.imul(J,_t)|0,o=o+Math.imul($,ut)|0,e=e+Math.imul($,St)|0,e=e+Math.imul(K,ut)|0,l=l+Math.imul(K,St)|0;var he=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(he>>>26)|0,he&=67108863,o=Math.imul(T,nt),e=Math.imul(T,bt),e=e+Math.imul(q,nt)|0,l=Math.imul(q,bt),o=o+Math.imul(B,ft)|0,e=e+Math.imul(B,yt)|0,e=e+Math.imul(w,ft)|0,l=l+Math.imul(w,yt)|0,o=o+Math.imul(Q,at)|0,e=e+Math.imul(Q,wt)|0,e=e+Math.imul(ct,at)|0,l=l+Math.imul(ct,wt)|0,o=o+Math.imul(j,ht)|0,e=e+Math.imul(j,Mt)|0,e=e+Math.imul(dt,ht)|0,l=l+Math.imul(dt,Mt)|0,o=o+Math.imul(et,st)|0,e=e+Math.imul(et,xt)|0,e=e+Math.imul(pt,st)|0,l=l+Math.imul(pt,xt)|0,o=o+Math.imul(tt,ot)|0,e=e+Math.imul(tt,_t)|0,e=e+Math.imul(vt,ot)|0,l=l+Math.imul(vt,_t)|0,o=o+Math.imul(Z,ut)|0,e=e+Math.imul(Z,St)|0,e=e+Math.imul(J,ut)|0,l=l+Math.imul(J,St)|0;var se=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(se>>>26)|0,se&=67108863,o=Math.imul(T,ft),e=Math.imul(T,yt),e=e+Math.imul(q,ft)|0,l=Math.imul(q,yt),o=o+Math.imul(B,at)|0,e=e+Math.imul(B,wt)|0,e=e+Math.imul(w,at)|0,l=l+Math.imul(w,wt)|0,o=o+Math.imul(Q,ht)|0,e=e+Math.imul(Q,Mt)|0,e=e+Math.imul(ct,ht)|0,l=l+Math.imul(ct,Mt)|0,o=o+Math.imul(j,st)|0,e=e+Math.imul(j,xt)|0,e=e+Math.imul(dt,st)|0,l=l+Math.imul(dt,xt)|0,o=o+Math.imul(et,ot)|0,e=e+Math.imul(et,_t)|0,e=e+Math.imul(pt,ot)|0,l=l+Math.imul(pt,_t)|0,o=o+Math.imul(tt,ut)|0,e=e+Math.imul(tt,St)|0,e=e+Math.imul(vt,ut)|0,l=l+Math.imul(vt,St)|0;var oe=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(oe>>>26)|0,oe&=67108863,o=Math.imul(T,at),e=Math.imul(T,wt),e=e+Math.imul(q,at)|0,l=Math.imul(q,wt),o=o+Math.imul(B,ht)|0,e=e+Math.imul(B,Mt)|0,e=e+Math.imul(w,ht)|0,l=l+Math.imul(w,Mt)|0,o=o+Math.imul(Q,st)|0,e=e+Math.imul(Q,xt)|0,e=e+Math.imul(ct,st)|0,l=l+Math.imul(ct,xt)|0,o=o+Math.imul(j,ot)|0,e=e+Math.imul(j,_t)|0,e=e+Math.imul(dt,ot)|0,l=l+Math.imul(dt,_t)|0,o=o+Math.imul(et,ut)|0,e=e+Math.imul(et,St)|0,e=e+Math.imul(pt,ut)|0,l=l+Math.imul(pt,St)|0;var ue=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ue>>>26)|0,ue&=67108863,o=Math.imul(T,ht),e=Math.imul(T,Mt),e=e+Math.imul(q,ht)|0,l=Math.imul(q,Mt),o=o+Math.imul(B,st)|0,e=e+Math.imul(B,xt)|0,e=e+Math.imul(w,st)|0,l=l+Math.imul(w,xt)|0,o=o+Math.imul(Q,ot)|0,e=e+Math.imul(Q,_t)|0,e=e+Math.imul(ct,ot)|0,l=l+Math.imul(ct,_t)|0,o=o+Math.imul(j,ut)|0,e=e+Math.imul(j,St)|0,e=e+Math.imul(dt,ut)|0,l=l+Math.imul(dt,St)|0;var le=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(le>>>26)|0,le&=67108863,o=Math.imul(T,st),e=Math.imul(T,xt),e=e+Math.imul(q,st)|0,l=Math.imul(q,xt),o=o+Math.imul(B,ot)|0,e=e+Math.imul(B,_t)|0,e=e+Math.imul(w,ot)|0,l=l+Math.imul(w,_t)|0,o=o+Math.imul(Q,ut)|0,e=e+Math.imul(Q,St)|0,e=e+Math.imul(ct,ut)|0,l=l+Math.imul(ct,St)|0;var de=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(de>>>26)|0,de&=67108863,o=Math.imul(T,ot),e=Math.imul(T,_t),e=e+Math.imul(q,ot)|0,l=Math.imul(q,_t),o=o+Math.imul(B,ut)|0,e=e+Math.imul(B,St)|0,e=e+Math.imul(w,ut)|0,l=l+Math.imul(w,St)|0;var ce=(v+o|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ce>>>26)|0,ce&=67108863,o=Math.imul(T,ut),e=Math.imul(T,St),e=e+Math.imul(q,ut)|0,l=Math.imul(q,St);var ve=(v+o|0)+((e&8191)<<13)|0;return v=(l+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,c[0]=Nt,c[1]=Ut,c[2]=jt,c[3]=Qt,c[4]=te,c[5]=ee,c[6]=re,c[7]=ie,c[8]=ne,c[9]=fe,c[10]=ae,c[11]=he,c[12]=se,c[13]=oe,c[14]=ue,c[15]=le,c[16]=de,c[17]=ce,c[18]=ve,v!==0&&(c[19]=v,i.length++),i};Math.imul||(L=D);function W(p,t,r){r.negative=t.negative^p.negative,r.length=p.length+t.length;for(var i=0,a=0,d=0;d<r.length-1;d++){var c=a;a=0;for(var v=i&67108863,o=Math.min(d,t.length-1),e=Math.max(0,d-p.length+1);e<=o;e++){var l=d-e,b=p.words[l]|0,_=t.words[e]|0,C=b*_,F=C&67108863;c=c+(C/67108864|0)|0,F=F+v|0,v=F&67108863,c=c+(F>>>26)|0,a+=c>>>26,c&=67108863}r.words[d]=v,i=c,c=a}return i!==0?r.words[d]=i:r.length--,r.strip()}function z(p,t,r){var i=new N;return i.mulp(p,t,r)}f.prototype.mulTo=function(t,r){var i,a=this.length+t.length;return this.length===10&&t.length===10?i=L(this,t,r):a<63?i=D(this,t,r):a<1024?i=W(this,t,r):i=z(this,t,r),i};function N(p,t){this.x=p,this.y=t}N.prototype.makeRBT=function(t){for(var r=new Array(t),i=f.prototype._countBits(t)-1,a=0;a<t;a++)r[a]=this.revBin(a,i,t);return r},N.prototype.revBin=function(t,r,i){if(t===0||t===i-1)return t;for(var a=0,d=0;d<r;d++)a|=(t&1)<<r-d-1,t>>=1;return a},N.prototype.permute=function(t,r,i,a,d,c){for(var v=0;v<c;v++)a[v]=r[t[v]],d[v]=i[t[v]]},N.prototype.transform=function(t,r,i,a,d,c){this.permute(c,t,r,i,a,d);for(var v=1;v<d;v<<=1)for(var o=v<<1,e=Math.cos(2*Math.PI/o),l=Math.sin(2*Math.PI/o),b=0;b<d;b+=o)for(var _=e,C=l,F=0;F<v;F++){var O=i[b+F],R=a[b+F],P=i[b+F+v],$=a[b+F+v],K=_*P-C*$;$=_*$+C*P,P=K,i[b+F]=O+P,a[b+F]=R+$,i[b+F+v]=O-P,a[b+F+v]=R-$,F!==o&&(K=e*_-l*C,C=e*C+l*_,_=K)}},N.prototype.guessLen13b=function(t,r){var i=Math.max(r,t)|1,a=i&1,d=0;for(i=i/2|0;i;i=i>>>1)d++;return 1<<d+1+a},N.prototype.conjugate=function(t,r,i){if(!(i<=1))for(var a=0;a<i/2;a++){var d=t[a];t[a]=t[i-a-1],t[i-a-1]=d,d=r[a],r[a]=-r[i-a-1],r[i-a-1]=-d}},N.prototype.normalize13b=function(t,r){for(var i=0,a=0;a<r/2;a++){var d=Math.round(t[2*a+1]/r)*8192+Math.round(t[2*a]/r)+i;t[a]=d&67108863,d<67108864?i=0:i=d/67108864|0}return t},N.prototype.convert13b=function(t,r,i,a){for(var d=0,c=0;c<r;c++)d=d+(t[c]|0),i[2*c]=d&8191,d=d>>>13,i[2*c+1]=d&8191,d=d>>>13;for(c=2*r;c<a;++c)i[c]=0;s(d===0),s((d&-8192)===0)},N.prototype.stub=function(t){for(var r=new Array(t),i=0;i<t;i++)r[i]=0;return r},N.prototype.mulp=function(t,r,i){var a=2*this.guessLen13b(t.length,r.length),d=this.makeRBT(a),c=this.stub(a),v=new Array(a),o=new Array(a),e=new Array(a),l=new Array(a),b=new Array(a),_=new Array(a),C=i.words;C.length=a,this.convert13b(t.words,t.length,v,a),this.convert13b(r.words,r.length,l,a),this.transform(v,c,o,e,a,d),this.transform(l,c,b,_,a,d);for(var F=0;F<a;F++){var O=o[F]*b[F]-e[F]*_[F];e[F]=o[F]*_[F]+e[F]*b[F],o[F]=O}return this.conjugate(o,e,a),this.transform(o,e,C,c,a,d),this.conjugate(C,c,a),this.normalize13b(C,a),i.negative=t.negative^r.negative,i.length=t.length+r.length,i.strip()},f.prototype.mul=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},f.prototype.mulf=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),z(this,t,r)},f.prototype.imul=function(t){return this.clone().mulTo(t,this)},f.prototype.imuln=function(t){s(typeof t=="number"),s(t<67108864);for(var r=0,i=0;i<this.length;i++){var a=(this.words[i]|0)*t,d=(a&67108863)+(r&67108863);r>>=26,r+=a/67108864|0,r+=d>>>26,this.words[i]=d&67108863}return r!==0&&(this.words[i]=r,this.length++),this.length=t===0?1:this.length,this},f.prototype.muln=function(t){return this.clone().imuln(t)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(t){var r=I(t);if(r.length===0)return new f(1);for(var i=this,a=0;a<r.length&&r[a]===0;a++,i=i.sqr());if(++a<r.length)for(var d=i.sqr();a<r.length;a++,d=d.sqr())r[a]!==0&&(i=i.mul(d));return i},f.prototype.iushln=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,a=67108863>>>26-r<<26-r,d;if(r!==0){var c=0;for(d=0;d<this.length;d++){var v=this.words[d]&a,o=(this.words[d]|0)-v<<r;this.words[d]=o|c,c=v>>>26-r}c&&(this.words[d]=c,this.length++)}if(i!==0){for(d=this.length-1;d>=0;d--)this.words[d+i]=this.words[d];for(d=0;d<i;d++)this.words[d]=0;this.length+=i}return this.strip()},f.prototype.ishln=function(t){return s(this.negative===0),this.iushln(t)},f.prototype.iushrn=function(t,r,i){s(typeof t=="number"&&t>=0);var a;r?a=(r-r%26)/26:a=0;var d=t%26,c=Math.min((t-d)/26,this.length),v=67108863^67108863>>>d<<d,o=i;if(a-=c,a=Math.max(0,a),o){for(var e=0;e<c;e++)o.words[e]=this.words[e];o.length=c}if(c!==0)if(this.length>c)for(this.length-=c,e=0;e<this.length;e++)this.words[e]=this.words[e+c];else this.words[0]=0,this.length=1;var l=0;for(e=this.length-1;e>=0&&(l!==0||e>=a);e--){var b=this.words[e]|0;this.words[e]=l<<26-d|b>>>d,l=b&v}return o&&l!==0&&(o.words[o.length++]=l),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},f.prototype.ishrn=function(t,r,i){return s(this.negative===0),this.iushrn(t,r,i)},f.prototype.shln=function(t){return this.clone().ishln(t)},f.prototype.ushln=function(t){return this.clone().iushln(t)},f.prototype.shrn=function(t){return this.clone().ishrn(t)},f.prototype.ushrn=function(t){return this.clone().iushrn(t)},f.prototype.testn=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,a=1<<r;if(this.length<=i)return!1;var d=this.words[i];return!!(d&a)},f.prototype.imaskn=function(t){s(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26;if(s(this.negative===0,"imaskn works only with positive numbers"),this.length<=i)return this;if(r!==0&&i++,this.length=Math.min(i,this.length),r!==0){var a=67108863^67108863>>>r<<r;this.words[this.length-1]&=a}return this.strip()},f.prototype.maskn=function(t){return this.clone().imaskn(t)},f.prototype.iaddn=function(t){return s(typeof t=="number"),s(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},f.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},f.prototype.isubn=function(t){if(s(typeof t=="number"),s(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this.strip()},f.prototype.addn=function(t){return this.clone().iaddn(t)},f.prototype.subn=function(t){return this.clone().isubn(t)},f.prototype.iabs=function(){return this.negative=0,this},f.prototype.abs=function(){return this.clone().iabs()},f.prototype._ishlnsubmul=function(t,r,i){var a=t.length+i,d;this._expand(a);var c,v=0;for(d=0;d<t.length;d++){c=(this.words[d+i]|0)+v;var o=(t.words[d]|0)*r;c-=o&67108863,v=(c>>26)-(o/67108864|0),this.words[d+i]=c&67108863}for(;d<this.length-i;d++)c=(this.words[d+i]|0)+v,v=c>>26,this.words[d+i]=c&67108863;if(v===0)return this.strip();for(s(v===-1),v=0,d=0;d<this.length;d++)c=-(this.words[d]|0)+v,v=c>>26,this.words[d]=c&67108863;return this.negative=1,this.strip()},f.prototype._wordDiv=function(t,r){var i=this.length-t.length,a=this.clone(),d=t,c=d.words[d.length-1]|0,v=this._countBits(c);i=26-v,i!==0&&(d=d.ushln(i),a.iushln(i),c=d.words[d.length-1]|0);var o=a.length-d.length,e;if(r!=="mod"){e=new f(null),e.length=o+1,e.words=new Array(e.length);for(var l=0;l<e.length;l++)e.words[l]=0}var b=a.clone()._ishlnsubmul(d,1,o);b.negative===0&&(a=b,e&&(e.words[o]=1));for(var _=o-1;_>=0;_--){var C=(a.words[d.length+_]|0)*67108864+(a.words[d.length+_-1]|0);for(C=Math.min(C/c|0,67108863),a._ishlnsubmul(d,C,_);a.negative!==0;)C--,a.negative=0,a._ishlnsubmul(d,1,_),a.isZero()||(a.negative^=1);e&&(e.words[_]=C)}return e&&e.strip(),a.strip(),r!=="div"&&i!==0&&a.iushrn(i),{div:e||null,mod:a}},f.prototype.divmod=function(t,r,i){if(s(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var a,d,c;return this.negative!==0&&t.negative===0?(c=this.neg().divmod(t,r),r!=="mod"&&(a=c.div.neg()),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.iadd(t)),{div:a,mod:d}):this.negative===0&&t.negative!==0?(c=this.divmod(t.neg(),r),r!=="mod"&&(a=c.div.neg()),{div:a,mod:c.mod}):this.negative&t.negative?(c=this.neg().divmod(t.neg(),r),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.isub(t)),{div:c.div,mod:d}):t.length>this.length||this.cmp(t)<0?{div:new f(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new f(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new f(this.modn(t.words[0]))}:this._wordDiv(t,r)},f.prototype.div=function(t){return this.divmod(t,"div",!1).div},f.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},f.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},f.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var i=r.div.negative!==0?r.mod.isub(t):r.mod,a=t.ushrn(1),d=t.andln(1),c=i.cmp(a);return c<0||d===1&&c===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},f.prototype.modn=function(t){s(t<=67108863);for(var r=(1<<26)%t,i=0,a=this.length-1;a>=0;a--)i=(r*i+(this.words[a]|0))%t;return i},f.prototype.idivn=function(t){s(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var a=(this.words[i]|0)+r*67108864;this.words[i]=a/t|0,r=a%t}return this.strip()},f.prototype.divn=function(t){return this.clone().idivn(t)},f.prototype.egcd=function(t){s(t.negative===0),s(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var a=new f(1),d=new f(0),c=new f(0),v=new f(1),o=0;r.isEven()&&i.isEven();)r.iushrn(1),i.iushrn(1),++o;for(var e=i.clone(),l=r.clone();!r.isZero();){for(var b=0,_=1;!(r.words[0]&_)&&b<26;++b,_<<=1);if(b>0)for(r.iushrn(b);b-- >0;)(a.isOdd()||d.isOdd())&&(a.iadd(e),d.isub(l)),a.iushrn(1),d.iushrn(1);for(var C=0,F=1;!(i.words[0]&F)&&C<26;++C,F<<=1);if(C>0)for(i.iushrn(C);C-- >0;)(c.isOdd()||v.isOdd())&&(c.iadd(e),v.isub(l)),c.iushrn(1),v.iushrn(1);r.cmp(i)>=0?(r.isub(i),a.isub(c),d.isub(v)):(i.isub(r),c.isub(a),v.isub(d))}return{a:c,b:v,gcd:i.iushln(o)}},f.prototype._invmp=function(t){s(t.negative===0),s(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var a=new f(1),d=new f(0),c=i.clone();r.cmpn(1)>0&&i.cmpn(1)>0;){for(var v=0,o=1;!(r.words[0]&o)&&v<26;++v,o<<=1);if(v>0)for(r.iushrn(v);v-- >0;)a.isOdd()&&a.iadd(c),a.iushrn(1);for(var e=0,l=1;!(i.words[0]&l)&&e<26;++e,l<<=1);if(e>0)for(i.iushrn(e);e-- >0;)d.isOdd()&&d.iadd(c),d.iushrn(1);r.cmp(i)>=0?(r.isub(i),a.isub(d)):(i.isub(r),d.isub(a))}var b;return r.cmpn(1)===0?b=a:b=d,b.cmpn(0)<0&&b.iadd(t),b},f.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),i=t.clone();r.negative=0,i.negative=0;for(var a=0;r.isEven()&&i.isEven();a++)r.iushrn(1),i.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;i.isEven();)i.iushrn(1);var d=r.cmp(i);if(d<0){var c=r;r=i,i=c}else if(d===0||i.cmpn(1)===0)break;r.isub(i)}while(!0);return i.iushln(a)},f.prototype.invm=function(t){return this.egcd(t).a.umod(t)},f.prototype.isEven=function(){return(this.words[0]&1)===0},f.prototype.isOdd=function(){return(this.words[0]&1)===1},f.prototype.andln=function(t){return this.words[0]&t},f.prototype.bincn=function(t){s(typeof t=="number");var r=t%26,i=(t-r)/26,a=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=a,this;for(var d=a,c=i;d!==0&&c<this.length;c++){var v=this.words[c]|0;v+=d,d=v>>>26,v&=67108863,this.words[c]=v}return d!==0&&(this.words[c]=d,this.length++),this},f.prototype.isZero=function(){return this.length===1&&this.words[0]===0},f.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return-1;if(this.negative===0&&r)return 1;this.strip();var i;if(this.length>1)i=1;else{r&&(t=-t),s(t<=67108863,"Number is too big");var a=this.words[0]|0;i=a===t?0:a<t?-1:1}return this.negative!==0?-i|0:i},f.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return-1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},f.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var r=0,i=this.length-1;i>=0;i--){var a=this.words[i]|0,d=t.words[i]|0;if(a!==d){a<d?r=-1:a>d&&(r=1);break}}return r},f.prototype.gtn=function(t){return this.cmpn(t)===1},f.prototype.gt=function(t){return this.cmp(t)===1},f.prototype.gten=function(t){return this.cmpn(t)>=0},f.prototype.gte=function(t){return this.cmp(t)>=0},f.prototype.ltn=function(t){return this.cmpn(t)===-1},f.prototype.lt=function(t){return this.cmp(t)===-1},f.prototype.lten=function(t){return this.cmpn(t)<=0},f.prototype.lte=function(t){return this.cmp(t)<=0},f.prototype.eqn=function(t){return this.cmpn(t)===0},f.prototype.eq=function(t){return this.cmp(t)===0},f.red=function(t){return new Y(t)},f.prototype.toRed=function(t){return s(!this.red,"Already a number in reduction context"),s(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},f.prototype.fromRed=function(){return s(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(t){return this.red=t,this},f.prototype.forceRed=function(t){return s(!this.red,"Already a number in reduction context"),this._forceRed(t)},f.prototype.redAdd=function(t){return s(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},f.prototype.redIAdd=function(t){return s(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},f.prototype.redSub=function(t){return s(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},f.prototype.redISub=function(t){return s(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},f.prototype.redShl=function(t){return s(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},f.prototype.redMul=function(t){return s(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},f.prototype.redIMul=function(t){return s(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},f.prototype.redSqr=function(){return s(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return s(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return s(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return s(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return s(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(t){return s(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var lt={k256:null,p224:null,p192:null,p25519:null};function H(p,t){this.name=p,this.p=new f(t,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}H.prototype._tmp=function(){var t=new f(null);return t.words=new Array(Math.ceil(this.n/13)),t},H.prototype.ireduce=function(t){var r=t,i;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),i=r.bitLength();while(i>this.n);var a=i<this.n?-1:r.ucmp(this.p);return a===0?(r.words[0]=0,r.length=1):a>0?r.isub(this.p):r.strip!==void 0?r.strip():r._strip(),r},H.prototype.split=function(t,r){t.iushrn(this.n,0,r)},H.prototype.imulK=function(t){return t.imul(this.k)};function At(){H.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}m(At,H),At.prototype.split=function(t,r){for(var i=4194303,a=Math.min(t.length,9),d=0;d<a;d++)r.words[d]=t.words[d];if(r.length=a,t.length<=9){t.words[0]=0,t.length=1;return}var c=t.words[9];for(r.words[r.length++]=c&i,d=10;d<t.length;d++){var v=t.words[d]|0;t.words[d-10]=(v&i)<<4|c>>>22,c=v}c>>>=22,t.words[d-10]=c,c===0&&t.length>10?t.length-=10:t.length-=9},At.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,i=0;i<t.length;i++){var a=t.words[i]|0;r+=a*977,t.words[i]=r&67108863,r=a*64+(r/67108864|0)}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function Bt(){H.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}m(Bt,H);function Ct(){H.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}m(Ct,H);function Et(){H.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}m(Et,H),Et.prototype.imulK=function(t){for(var r=0,i=0;i<t.length;i++){var a=(t.words[i]|0)*19+r,d=a&67108863;a>>>=26,t.words[i]=d,r=a}return r!==0&&(t.words[t.length++]=r),t},f._prime=function(t){if(lt[t])return lt[t];var r;if(t==="k256")r=new At;else if(t==="p224")r=new Bt;else if(t==="p192")r=new Ct;else if(t==="p25519")r=new Et;else throw new Error("Unknown prime "+t);return lt[t]=r,r};function Y(p){if(typeof p=="string"){var t=f._prime(p);this.m=t.p,this.prime=t}else s(p.gtn(1),"modulus must be greater than 1"),this.m=p,this.prime=null}Y.prototype._verify1=function(t){s(t.negative===0,"red works only with positives"),s(t.red,"red works only with red numbers")},Y.prototype._verify2=function(t,r){s((t.negative|r.negative)===0,"red works only with positives"),s(t.red&&t.red===r.red,"red works only with red numbers")},Y.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},Y.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},Y.prototype.add=function(t,r){this._verify2(t,r);var i=t.add(r);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},Y.prototype.iadd=function(t,r){this._verify2(t,r);var i=t.iadd(r);return i.cmp(this.m)>=0&&i.isub(this.m),i},Y.prototype.sub=function(t,r){this._verify2(t,r);var i=t.sub(r);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},Y.prototype.isub=function(t,r){this._verify2(t,r);var i=t.isub(r);return i.cmpn(0)<0&&i.iadd(this.m),i},Y.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},Y.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},Y.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},Y.prototype.isqr=function(t){return this.imul(t,t.clone())},Y.prototype.sqr=function(t){return this.mul(t,t)},Y.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(s(r%2===1),r===3){var i=this.m.add(new f(1)).iushrn(2);return this.pow(t,i)}for(var a=this.m.subn(1),d=0;!a.isZero()&&a.andln(1)===0;)d++,a.iushrn(1);s(!a.isZero());var c=new f(1).toRed(this),v=c.redNeg(),o=this.m.subn(1).iushrn(1),e=this.m.bitLength();for(e=new f(2*e*e).toRed(this);this.pow(e,o).cmp(v)!==0;)e.redIAdd(v);for(var l=this.pow(e,a),b=this.pow(t,a.addn(1).iushrn(1)),_=this.pow(t,a),C=d;_.cmp(c)!==0;){for(var F=_,O=0;F.cmp(c)!==0;O++)F=F.redSqr();s(O<C);var R=this.pow(l,new f(1).iushln(C-O-1));b=b.redMul(R),l=R.redSqr(),_=_.redMul(l),C=O}return b},Y.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},Y.prototype.pow=function(t,r){if(r.isZero())return new f(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var i=4,a=new Array(1<<i);a[0]=new f(1).toRed(this),a[1]=t;for(var d=2;d<a.length;d++)a[d]=this.mul(a[d-1],t);var c=a[0],v=0,o=0,e=r.bitLength()%26;for(e===0&&(e=26),d=r.length-1;d>=0;d--){for(var l=r.words[d],b=e-1;b>=0;b--){var _=l>>b&1;if(c!==a[0]&&(c=this.sqr(c)),_===0&&v===0){o=0;continue}v<<=1,v|=_,o++,!(o!==i&&(d!==0||b!==0))&&(c=this.mul(c,a[v]),o=0,v=0)}e=26}return c},Y.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},Y.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},f.mont=function(t){return new kt(t)};function kt(p){Y.call(this,p),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}m(kt,Y),kt.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},kt.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},kt.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),a=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(a).iushrn(this.shift),c=d;return d.cmp(this.m)>=0?c=d.isub(this.m):d.cmpn(0)<0&&(c=d.iadd(this.m)),c._forceRed(this)},kt.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var i=t.mul(r),a=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(a).iushrn(this.shift),c=d;return d.cmp(this.m)>=0?c=d.isub(this.m):d.cmpn(0)<0&&(c=d.iadd(this.m)),c._forceRed(this)},kt.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(h,qt)}(Y0);var J0=Y0.exports,Do=J0,G2=zt.Buffer;function X2(h,n){return G2.from(h.toRed(Do.mont(n.modulus)).redPow(new Do(n.publicExponent)).fromRed().toArray())}var $o=X2,j2=lf,G0=li,Q2=Ki,No=Fo,Uo=Po,X0=J0,tm=$o,em=u0,sr=zt.Buffer,rm=function(n,u,s){var m;n.padding?m=n.padding:s?m=1:m=4;var f=j2(n),g;if(m===4)g=im(f,u);else if(m===1)g=nm(f,u,s);else if(m===3){if(g=new X0(u),g.cmp(f.modulus)>=0)throw new Error("data too long for modulus")}else throw new Error("unknown padding");return s?em(g,f):tm(g,f)};function im(h,n){var u=h.modulus.byteLength(),s=n.length,m=Q2("sha1").update(sr.alloc(0)).digest(),f=m.length,g=2*f;if(s>u-g-2)throw new Error("message too long");var y=sr.alloc(u-s-g-2),S=u-f-1,E=G0(f),M=Uo(sr.concat([m,y,sr.alloc(1,1),n],S),No(E,S)),x=Uo(E,No(M,f));return new X0(sr.concat([sr.alloc(1),x,M],u))}function nm(h,n,u){var s=n.length,m=h.modulus.byteLength();if(s>m-11)throw new Error("message too long");var f;return u?f=sr.alloc(m-s-3,255):f=fm(m-s-3),new X0(sr.concat([sr.from([0,u?1:2]),f,sr.alloc(1),n],m))}function fm(h){for(var n=sr.allocUnsafe(h),u=0,s=G0(h*2),m=0,f;u<h;)m===s.length&&(s=G0(h*2),m=0),f=s[m++],f&&(n[u++]=f);return n}var am=lf,Lo=Fo,Oo=Po,zo=J0,hm=u0,sm=Ki,om=$o,on=zt.Buffer,um=function(n,u,s){var m;n.padding?m=n.padding:s?m=1:m=4;var f=am(n),g=f.modulus.byteLength();if(u.length>g||new zo(u).cmp(f.modulus)>=0)throw new Error("decryption error");var y;s?y=om(new zo(u),f):y=hm(u,f);var S=on.alloc(g-y.length);if(y=on.concat([S,y],g),m===4)return lm(f,y);if(m===1)return dm(f,y,s);if(m===3)return y;throw new Error("unknown padding")};function lm(h,n){var u=h.modulus.byteLength(),s=sm("sha1").update(on.alloc(0)).digest(),m=s.length;if(n[0]!==0)throw new Error("decryption error");var f=n.slice(1,m+1),g=n.slice(m+1),y=Oo(f,Lo(g,m)),S=Oo(g,Lo(y,u-m-1));if(cm(s,S.slice(0,m)))throw new Error("decryption error");for(var E=m;S[E]===0;)E++;if(S[E++]!==1)throw new Error("decryption error");return S.slice(E)}function dm(h,n,u){for(var s=n.slice(0,2),m=2,f=0;n[m++]!==0;)if(m>=n.length){f++;break}var g=n.slice(2,m-1);if((s.toString("hex")!=="0002"&&!u||s.toString("hex")!=="0001"&&u)&&f++,g.length<8&&f++,f)throw new Error("decryption error");return n.slice(m)}function cm(h,n){h=on.from(h),n=on.from(n);var u=0,s=h.length;h.length!==n.length&&(u++,s=Math.min(h.length,n.length));for(var m=-1;++m<s;)u+=h[m]^n[m];return u}(function(h){h.publicEncrypt=rm,h.privateDecrypt=um,h.privateEncrypt=function(u,s){return h.publicEncrypt(u,s,!0)},h.publicDecrypt=function(u,s){return h.privateDecrypt(u,s,!0)}})(qo);var un={};function Ko(){throw new Error(`secure random number generation not supported by this browser
16
16
  use chrome, FireFox or Internet Explorer 11`)}var Ho=zt,Zo=li,Wo=Ho.Buffer,Vo=Ho.kMaxLength,j0=qt.crypto||qt.msCrypto,Yo=Math.pow(2,32)-1;function Jo(h,n){if(typeof h!="number"||h!==h)throw new TypeError("offset must be a number");if(h>Yo||h<0)throw new TypeError("offset must be a uint32");if(h>Vo||h>n)throw new RangeError("offset out of range")}function Go(h,n,u){if(typeof h!="number"||h!==h)throw new TypeError("size must be a number");if(h>Yo||h<0)throw new TypeError("size must be a uint32");if(h+n>u||h>Vo)throw new RangeError("buffer too small")}j0&&j0.getRandomValues||!ye.browser?(un.randomFill=vm,un.randomFillSync=pm):(un.randomFill=Ko,un.randomFillSync=Ko);function vm(h,n,u,s){if(!Wo.isBuffer(h)&&!(h instanceof qt.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');if(typeof n=="function")s=n,n=0,u=h.length;else if(typeof u=="function")s=u,u=h.length-n;else if(typeof s!="function")throw new TypeError('"cb" argument must be a function');return Jo(n,h.length),Go(u,n,h.length),Xo(h,n,u,s)}function Xo(h,n,u,s){if(ye.browser){var m=h.buffer,f=new Uint8Array(m,n,u);if(j0.getRandomValues(f),s){ye.nextTick(function(){s(null,h)});return}return h}if(s){Zo(u,function(y,S){if(y)return s(y);S.copy(h,n),s(null,h)});return}var g=Zo(u);return g.copy(h,n),h}function pm(h,n,u){if(typeof n=="undefined"&&(n=0),!Wo.isBuffer(h)&&!(h instanceof qt.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');return Jo(n,h.length),u===void 0&&(u=h.length-n),Go(u,n,h.length),Xo(h,n,u)}var jo;function Qo(){if(jo)return Lt;jo=1,Lt.randomBytes=Lt.rng=Lt.pseudoRandomBytes=Lt.prng=li,Lt.createHash=Lt.Hash=Ki,Lt.createHmac=Lt.Hmac=La;var h=Rd,n=Object.keys(h),u=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(n);Lt.getHashes=function(){return u};var s=_n;Lt.pbkdf2=s.pbkdf2,Lt.pbkdf2Sync=s.pbkdf2Sync;var m=rr;Lt.Cipher=m.Cipher,Lt.createCipher=m.createCipher,Lt.Cipheriv=m.Cipheriv,Lt.createCipheriv=m.createCipheriv,Lt.Decipher=m.Decipher,Lt.createDecipher=m.createDecipher,Lt.Decipheriv=m.Decipheriv,Lt.createDecipheriv=m.createDecipheriv,Lt.getCiphers=m.getCiphers,Lt.listCiphers=m.listCiphers;var f=k1();Lt.DiffieHellmanGroup=f.DiffieHellmanGroup,Lt.createDiffieHellmanGroup=f.createDiffieHellmanGroup,Lt.getDiffieHellman=f.getDiffieHellman,Lt.createDiffieHellman=f.createDiffieHellman,Lt.DiffieHellman=f.DiffieHellman;var g=Z2();Lt.createSign=g.createSign,Lt.Sign=g.Sign,Lt.createVerify=g.createVerify,Lt.Verify=g.Verify,Lt.createECDH=V2();var y=qo;Lt.publicEncrypt=y.publicEncrypt,Lt.privateEncrypt=y.privateEncrypt,Lt.publicDecrypt=y.publicDecrypt,Lt.privateDecrypt=y.privateDecrypt;var S=un;return Lt.randomFill=S.randomFill,Lt.randomFillSync=S.randomFillSync,Lt.createCredentials=function(){throw new Error(`sorry, createCredentials is not implemented yet
17
17
  we accept pull requests
18
- https://github.com/browserify/crypto-browserify`)},Lt.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6},Lt}var mm=Qo();const gm=Ie(mm);function Q0(h){const n=gm.createHash("sha256").update(h).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function tu(h,n){const u=Q0(h);let s=0;for(const m of n.variants)if(s+=m.weight,u<s)return m.value;return null}function eu(h,n){const u=n.user_id||n.id||n.email;if(!h||typeof h!="object"||!u)return null;switch(h.strategy){case"percentage":{if(!("percentage"in h)||!("salt"in h))return null;const{percentage:s,salt:m}=h;return Q0(`${u}.${m}`)<s?!0:null}case"variant":{if(!("variants"in h))return null;const{salt:s,variants:m}=h;return tu(`${u}.${s}`,m)}default:return null}}function ru(h,n){var f;if(!(h.targeting_rules||[]).every(g=>{var y;if(g.type==="segment"){const S=(y=h.segmentsById)==null?void 0:y[g.segment_id];return S?wu(S,n):!1}else return aa(g,n)}))return null;const m=h.rollout?eu(h.rollout,n):null;return(f=m!=null?m:h.value)!=null?f:null}let ln={getItem:h=>typeof localStorage!="undefined"?localStorage.getItem(h):null,setItem:(h,n)=>{typeof localStorage!="undefined"&&localStorage.setItem(h,n)}};function bm(h){ln=h}function iu(h){return`flagmint_${h}_flags`}function nu(h){return`flagmint_${h}_context`}function fu(h,n){try{const u=ln.getItem(iu(h));if(!u)return null;const s=JSON.parse(u);return Date.now()-s.ts>n?null:s.data}catch(u){return null}}function au(h,n){try{ln.setItem(iu(h),JSON.stringify({ts:Date.now(),data:n}))}catch(u){}}function hu(h){try{const n=ln.getItem(nu(h));return n?JSON.parse(n):null}catch(n){return null}}function su(h,n){try{ln.setItem(nu(h),JSON.stringify(n))}catch(u){}}const ym=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:hu,loadCachedFlags:fu,saveCachedContext:su,saveCachedFlags:au,setCacheStorage:bm},Symbol.toStringTag,{value:"Module"})),wm=24*60*60*1e3,Mm="http://localhost:3000/evaluator/evaluate",xm="wss://api.flagmint.io/flags/ws";class _m{constructor(n){var u,s,m,f;if(this.flags={},this.refreshIntervalId=null,this.rawFlags={},this.apiKey=n.apiKey,this.enableOfflineCache=(u=n.enableOfflineCache)!=null?u:!0,this.persistContext=(s=n.persistContext)!=null?s:!1,this.cacheTTL=wm,this.onError=n.onError,this.cacheAdapter=(m=n.cacheAdapter)!=null?m:{loadFlags:fu,saveFlags:au,loadContext:hu,saveContext:su},this.context=n.context||{},this.rawFlags=(f=n.rawFlags)!=null?f:{},this.previewMode=n.previewMode||!1,this.previewMode&&this.rawFlags&&Object.keys(this.rawFlags).length>0){this.flags=this.evaluateLocally(this.rawFlags,this.context),this.readyPromise=Promise.resolve(),this.resolveReady=()=>{},this.rejectReady=()=>{};return}else this.previewMode&&!this.rawFlags&&console.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((g,y)=>{this.resolveReady=g,this.rejectReady=y}),this.initialize(n)}initialize(n){return We(this,null,function*(){var u;try{if(this.persistContext){const s=yield Promise.resolve(this.cacheAdapter.loadContext(this.apiKey));s&&(this.context=s)}if(this.enableOfflineCache){const s=yield Promise.resolve(this.cacheAdapter.loadFlags(this.apiKey,this.cacheTTL));s&&(this.flags=s)}yield this.setupTransport(n),this.resolveReady()}catch(s){this.rejectReady(s),(u=this.onError)==null||u.call(this,s)}})}setupTransport(n){return We(this,null,function*(){var f;const u=(f=n.transportMode)!=null?f:"auto",s=()=>We(this,null,function*(){console.log("[FlagClient] Initializing WebSocket transport...");const g=new fa(xm,this.apiKey);return yield g.init(),console.log("[FlagClient] WebSocket transport initialized"),g}),m=()=>{console.log("[FlagClient] Using long polling transport...");const g=new na(Mm,this.apiKey,this.context,{pollIntervalMs:1e4});return g.init(y=>{console.log("[FlagClient] LongPolling update received:",y),this.flags=y,this.enableOfflineCache&&Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,y))}),g};try{if(u==="websocket")this.transport=yield s();else if(u==="long-polling")this.transport=m();else try{this.transport=yield s()}catch(y){console.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}const g=yield this.transport.fetchFlags(this.context);this.flags=g,this.enableOfflineCache&&(yield Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,g))),typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(y=>{this.flags=y,this.enableOfflineCache&&this.cacheAdapter.saveFlags(this.apiKey,y)}),this.resolveReady()}catch(g){throw console.error("[FlagClient] setupTransport error:",g),this.rejectReady(g),this.onError&&this.onError(g instanceof Error?g:new Error(String(g))),g}})}getFlag(n,u){var s;return(s=this.flags[n])!=null?s:u}updateContext(n){this.context=ra(ra({},this.context),n),this.persistContext&&this.cacheAdapter.saveContext(this.apiKey,this.context)}destroy(){this.refreshIntervalId&&clearInterval(this.refreshIntervalId),this.transport.destroy()}ready(){return We(this,null,function*(){return this.readyPromise})}evaluateLocally(n,u){const s={};for(const m in n){const f=ru(n[m],u);f!==null&&(s[m]=f)}return s}}function ou(h){return`flagmint_${h}_flags`}function uu(h){return`flagmint_${h}_context`}let qr=null;function Sm(h){qr=h}function Am(h,n){return We(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{const u=yield qr.getItem(ou(h));if(!u)return null;const s=JSON.parse(u);return Date.now()-s.ts>n?null:s.data}catch(u){return null}})}function Bm(h,n){return We(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{yield qr.setItem(ou(h),JSON.stringify({ts:Date.now(),data:n}))}catch(u){}})}function Em(h){return We(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{const n=yield qr.getItem(uu(h));return n?JSON.parse(n):null}catch(n){return null}})}function Im(h,n){return We(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{yield qr.setItem(uu(h),JSON.stringify(n))}catch(u){}})}const km=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:Em,loadCachedFlags:Am,saveCachedContext:Im,saveCachedFlags:Bm,setAsyncCacheStorage:Sm},Symbol.toStringTag,{value:"Module"}));typeof globalThis.Buffer=="undefined"&&(globalThis.Buffer=ze.Buffer),ge.FlagClient=_m,ge.LongPollingTransport=na,ge.WebSocketTransport=fa,ge.asyncCache=km,ge.evaluateFlagValue=ru,ge.evaluateRollout=eu,ge.hashToPercentage=Q0,ge.pickVariant=tu,ge.syncCache=ym,Object.defineProperty(ge,Symbol.toStringTag,{value:"Module"})});
18
+ https://github.com/browserify/crypto-browserify`)},Lt.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6},Lt}var mm=Qo();const gm=Ie(mm);function Q0(h){const n=gm.createHash("sha256").update(h).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function tu(h,n){const u=Q0(h);let s=0;for(const m of n.variants)if(s+=m.weight,u<s)return m.value;return null}function eu(h,n){const u=n.user_id||n.id||n.email;if(!h||typeof h!="object"||!u)return null;switch(h.strategy){case"percentage":{if(!("percentage"in h)||!("salt"in h))return null;const{percentage:s,salt:m}=h;return Q0(`${u}.${m}`)<s?!0:null}case"variant":{if(!("variants"in h))return null;const{salt:s,variants:m}=h;return tu(`${u}.${s}`,m)}default:return null}}function ru(h,n){var f;if(!(h.targeting_rules||[]).every(g=>{var y;if(g.type==="segment"){const S=(y=h.segmentsById)==null?void 0:y[g.segment_id];return S?wu(S,n):!1}else return aa(g,n)}))return null;const m=h.rollout?eu(h.rollout,n):null;return(f=m!=null?m:h.value)!=null?f:null}let ln={getItem:h=>typeof localStorage!="undefined"?localStorage.getItem(h):null,setItem:(h,n)=>{typeof localStorage!="undefined"&&localStorage.setItem(h,n)}};function bm(h){ln=h}function iu(h){return`flagmint_${h}_flags`}function nu(h){return`flagmint_${h}_context`}function fu(h,n){try{const u=ln.getItem(iu(h));if(!u)return null;const s=JSON.parse(u);return Date.now()-s.ts>n?null:s.data}catch(u){return null}}function au(h,n){try{ln.setItem(iu(h),JSON.stringify({ts:Date.now(),data:n}))}catch(u){}}function hu(h){try{const n=ln.getItem(nu(h));return n?JSON.parse(n):null}catch(n){return null}}function su(h,n){try{ln.setItem(nu(h),JSON.stringify(n))}catch(u){}}const ym=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:hu,loadCachedFlags:fu,saveCachedContext:su,saveCachedFlags:au,setCacheStorage:bm},Symbol.toStringTag,{value:"Module"})),wm=24*60*60*1e3,Mm="http://localhost:3000/evaluator/evaluate",xm="wss://api.flagmint.io/flags/ws";class _m{constructor(n){var u,s,m,f;if(this.flags={},this.refreshIntervalId=null,this.rawFlags={},this.apiKey=n.apiKey,this.enableOfflineCache=(u=n.enableOfflineCache)!=null?u:!0,this.persistContext=(s=n.persistContext)!=null?s:!1,this.cacheTTL=wm,this.onError=n.onError,this.cacheAdapter=(m=n.cacheAdapter)!=null?m:{loadFlags:fu,saveFlags:au,loadContext:hu,saveContext:su},this.context=n.context||{},this.rawFlags=(f=n.rawFlags)!=null?f:{},this.previewMode=n.previewMode||!1,this.previewMode&&this.rawFlags&&Object.keys(this.rawFlags).length>0){this.flags=this.rawFlags,this.flags=this.evaluateLocally(this.rawFlags,this.context),this.readyPromise=Promise.resolve(),this.resolveReady=()=>{},this.rejectReady=()=>{};return}else this.previewMode&&!this.rawFlags&&console.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((g,y)=>{this.resolveReady=g,this.rejectReady=y}),this.initialize(n)}initialize(n){return We(this,null,function*(){var u;try{if(this.persistContext){const s=yield Promise.resolve(this.cacheAdapter.loadContext(this.apiKey));s&&(this.context=s)}if(this.enableOfflineCache){const s=yield Promise.resolve(this.cacheAdapter.loadFlags(this.apiKey,this.cacheTTL));s&&(this.flags=s)}yield this.setupTransport(n),this.resolveReady()}catch(s){this.rejectReady(s),(u=this.onError)==null||u.call(this,s)}})}setupTransport(n){return We(this,null,function*(){var f;const u=(f=n.transportMode)!=null?f:"auto",s=()=>We(this,null,function*(){console.log("[FlagClient] Initializing WebSocket transport...");const g=new fa(xm,this.apiKey);return yield g.init(),console.log("[FlagClient] WebSocket transport initialized"),g}),m=()=>{console.log("[FlagClient] Using long polling transport...");const g=new na(Mm,this.apiKey,this.context,{pollIntervalMs:2e4});return g.init(y=>{console.log("[FlagClient] LongPolling update received:",y),this.flags=y,this.enableOfflineCache&&Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,y))}),g};try{if(u==="websocket")this.transport=yield s();else if(u==="long-polling")this.transport=m();else try{this.transport=yield s()}catch(g){console.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}this.flags=yield this.transport.fetchFlags(this.context),this.enableOfflineCache&&(yield Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,this.flags))),typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(g=>{this.flags=g,this.enableOfflineCache&&this.cacheAdapter.saveFlags(this.apiKey,g)}),this.resolveReady()}catch(g){throw console.error("[FlagClient] setupTransport error:",g),this.rejectReady(g),this.onError&&this.onError(g instanceof Error?g:new Error(String(g))),g}})}getFlag(n,u){var s;return(s=this.flags[n])!=null?s:u}updateContext(n){this.context=ra(ra({},this.context),n),this.persistContext&&this.cacheAdapter.saveContext(this.apiKey,this.context)}destroy(){this.refreshIntervalId&&clearInterval(this.refreshIntervalId),this.transport.destroy()}ready(){return We(this,null,function*(){return this.readyPromise})}evaluateLocally(n,u){const s={};console.log("[FlagClient] Evaluating flags locally with context:",n,u);for(const m in n){const f=ru(n[m],u);f!==null&&(s[m]=f)}return s}}function ou(h){return`flagmint_${h}_flags`}function uu(h){return`flagmint_${h}_context`}let qr=null;function Sm(h){qr=h}function Am(h,n){return We(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{const u=yield qr.getItem(ou(h));if(!u)return null;const s=JSON.parse(u);return Date.now()-s.ts>n?null:s.data}catch(u){return null}})}function Bm(h,n){return We(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{yield qr.setItem(ou(h),JSON.stringify({ts:Date.now(),data:n}))}catch(u){}})}function Em(h){return We(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{const n=yield qr.getItem(uu(h));return n?JSON.parse(n):null}catch(n){return null}})}function Im(h,n){return We(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{yield qr.setItem(uu(h),JSON.stringify(n))}catch(u){}})}const km=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:Em,loadCachedFlags:Am,saveCachedContext:Im,saveCachedFlags:Bm,setAsyncCacheStorage:Sm},Symbol.toStringTag,{value:"Module"}));typeof globalThis.Buffer=="undefined"&&(globalThis.Buffer=ze.Buffer),ge.FlagClient=_m,ge.LongPollingTransport=na,ge.WebSocketTransport=fa,ge.asyncCache=km,ge.evaluateFlagValue=ru,ge.evaluateRollout=eu,ge.hashToPercentage=Q0,ge.pickVariant=tu,ge.syncCache=ym,Object.defineProperty(ge,Symbol.toStringTag,{value:"Module"})});
@@ -15,6 +15,12 @@ export interface FlagClientOptions<C extends Record<string, any> = Record<string
15
15
  deferInitialization?: boolean;
16
16
  cacheAdapter?: CacheAdapter<C>;
17
17
  }
18
+ /**
19
+ * FlagClient is the main class for interacting with the Flagmint feature flag service.
20
+ * It handles fetching flags, evaluating them against a context, and managing offline caching.
21
+ * @template T - The type of feature flags.
22
+ * @template C - The type of context used for evaluating flags.
23
+ */
18
24
  export declare class FlagClient<T = unknown, C extends Record<string, any> = Record<string, any>> {
19
25
  private apiKey;
20
26
  private context;
@@ -50,10 +56,39 @@ export declare class FlagClient<T = unknown, C extends Record<string, any> = Rec
50
56
  * @param options - The options for the transport setup.
51
57
  */
52
58
  private setupTransport;
59
+ /**
60
+ * Gets the value of a feature flag by its key, with an optional fallback value.
61
+ * @param key
62
+ * @param fallback
63
+ * @returns The value of the feature flag, or the fallback value if the flag is not set.
64
+ * @template K - The key of the feature flag.
65
+ * @template T - The type of the feature flags.
66
+ */
53
67
  getFlag<K extends keyof FeatureFlags<T>>(key: K, fallback?: FeatureFlags<T>[K]): FeatureFlags<T>[K];
68
+ /**
69
+ * Updates the client context and optionally persists it to cache.
70
+ * @param context - The new context to set.
71
+ * @returns void
72
+ */
54
73
  updateContext(context: C): void;
74
+ /**
75
+ * Destroys the client, clearing the refresh interval and transport.
76
+ * @returns void
77
+ */
55
78
  destroy(): void;
79
+ /**
80
+ * Returns a promise that resolves when the client is ready.
81
+ * This is useful for ensuring that the client is fully initialized before using it.
82
+ * */
56
83
  ready(): Promise<void>;
84
+ /**
85
+ * Evaluates flags locally based on the provided context.
86
+ * This method is used when preview mode is enabled and raw flags are provided.
87
+ * It evaluates each flag value against the context and returns a record of evaluated flags.
88
+ * @param flags
89
+ * @param context
90
+ * @returns
91
+ */
57
92
  private evaluateLocally;
58
93
  }
59
94
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagmint-js-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Framework-agnostic JavaScript SDK for managing feature flags in Flagmint applications.",
5
5
  "author": "Flagmint Team",
6
6
  "license": "MIT",