flagmint-js-sdk 1.2.25 → 1.2.26
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.
- package/dist/flagmint.cjs.js +1 -1
- package/dist/flagmint.es.js +14 -16
- package/dist/flagmint.umd.js +1 -1
- package/package.json +1 -1
package/dist/flagmint.cjs.js
CHANGED
|
@@ -15,4 +15,4 @@ Use Chrome, Firefox or Internet Explorer 11`)}var hl=zt.Buffer,_n=Xt.crypto||Xt.
|
|
|
15
15
|
`)},Xf}var uh;function s2(){return uh||(uh=1,function(a){var n=a;n.der=Ko(),n.pem=h2()}(Jf)),Jf}var lh;function sn(){return lh||(lh=1,function(a){var n=a;n.bignum=t2,n.define=e2().define,n.base=zi(),n.constants=Oo(),n.decoders=a2(),n.encoders=s2()}(Uf)),Uf}var nr=sn(),dh=nr.define("Time",function(){this.choice({utcTime:this.utctime(),generalTime:this.gentime()})}),o2=nr.define("AttributeTypeValue",function(){this.seq().obj(this.key("type").objid(),this.key("value").any())}),Q0=nr.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional(),this.key("curve").objid().optional())}),u2=nr.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(Q0),this.key("subjectPublicKey").bitstr())}),l2=nr.define("RelativeDistinguishedName",function(){this.setof(o2)}),d2=nr.define("RDNSequence",function(){this.seqof(l2)}),ch=nr.define("Name",function(){this.choice({rdnSequence:this.use(d2)})}),c2=nr.define("Validity",function(){this.seq().obj(this.key("notBefore").use(dh),this.key("notAfter").use(dh))}),v2=nr.define("Extension",function(){this.seq().obj(this.key("extnID").objid(),this.key("critical").bool().def(!1),this.key("extnValue").octstr())}),p2=nr.define("TBSCertificate",function(){this.seq().obj(this.key("version").explicit(0).int().optional(),this.key("serialNumber").int(),this.key("signature").use(Q0),this.key("issuer").use(ch),this.key("validity").use(c2),this.key("subject").use(ch),this.key("subjectPublicKeyInfo").use(u2),this.key("issuerUniqueID").implicit(1).bitstr().optional(),this.key("subjectUniqueID").implicit(2).bitstr().optional(),this.key("extensions").explicit(3).seqof(v2).optional())}),m2=nr.define("X509Certificate",function(){this.seq().obj(this.key("tbsCertificate").use(p2),this.key("signatureAlgorithm").use(Q0),this.key("signatureValue").bitstr())}),g2=m2,fr=sn();ir.certificate=g2;var b2=fr.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())});ir.RSAPrivateKey=b2;var y2=fr.define("RSAPublicKey",function(){this.seq().obj(this.key("modulus").int(),this.key("publicExponent").int())});ir.RSAPublicKey=y2;var Ho=fr.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())}),w2=fr.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(Ho),this.key("subjectPublicKey").bitstr())});ir.PublicKey=w2;var M2=fr.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").use(Ho),this.key("subjectPrivateKey").octstr())});ir.PrivateKey=M2;var x2=fr.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())});ir.EncryptedPrivateKey=x2;var _2=fr.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())});ir.DSAPrivateKey=_2;ir.DSAparam=fr.define("DSAparam",function(){this.int()});var S2=fr.define("ECParameters",function(){this.choice({namedCurve:this.objid()})}),A2=fr.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").optional().explicit(0).use(S2),this.key("publicKey").optional().explicit(1).bitstr())});ir.ECPrivateKey=A2;ir.signature=fr.define("signature",function(){this.seq().obj(this.key("r").int(),this.key("s").int())});const B2={"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 E2=/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,k2=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m,I2=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m,R2=Jn,T2=Oe,gn=zt.Buffer,C2=function(a,n){var o=a.toString(),s=o.match(E2),m;if(s){var g="aes"+s[1],y=gn.from(s[2],"hex"),S=gn.from(s[3].replace(/[\r\n]/g,""),"base64"),B=R2(n,y.slice(0,8),parseInt(s[1],10)).key,w=[],x=T2.createDecipheriv(g,B,y);w.push(x.update(S)),w.push(x.final()),m=gn.concat(w)}else{var f=o.match(I2);m=gn.from(f[2].replace(/[\r\n]/g,""),"base64")}var I=o.match(k2)[1];return{tag:I,data:m}},Pe=ir,F2=B2,q2=C2,P2=Oe,D2=zn,b0=zt.Buffer;function N2(a,n){var o=a.algorithm.decrypt.kde.kdeparams.salt,s=parseInt(a.algorithm.decrypt.kde.kdeparams.iters.toString(),10),m=F2[a.algorithm.decrypt.cipher.algo.join(".")],f=a.algorithm.decrypt.cipher.iv,g=a.subjectPrivateKey,y=parseInt(m.split("-")[1],10)/8,S=D2.pbkdf2Sync(n,o,s,y,"sha1"),B=P2.createDecipheriv(m,S,f),w=[];return w.push(B.update(g)),w.push(B.final()),b0.concat(w)}function Zo(a){var n;typeof a=="object"&&!b0.isBuffer(a)&&(n=a.passphrase,a=a.key),typeof a=="string"&&(a=b0.from(a));var o=q2(a,n),s=o.tag,m=o.data,f,g;switch(s){case"CERTIFICATE":g=Pe.certificate.decode(m,"der").tbsCertificate.subjectPublicKeyInfo;case"PUBLIC KEY":switch(g||(g=Pe.PublicKey.decode(m,"der")),f=g.algorithm.algorithm.join("."),f){case"1.2.840.113549.1.1.1":return Pe.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=Pe.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=Pe.EncryptedPrivateKey.decode(m,"der"),m=N2(m,n);case"PRIVATE KEY":switch(g=Pe.PrivateKey.decode(m,"der"),f=g.algorithm.algorithm.join("."),f){case"1.2.840.113549.1.1.1":return Pe.RSAPrivateKey.decode(g.subjectPrivateKey,"der");case"1.2.840.10045.2.1":return{curve:g.algorithm.curve,privateKey:Pe.ECPrivateKey.decode(g.subjectPrivateKey,"der").privateKey};case"1.2.840.10040.4.1":return g.algorithm.params.priv_key=Pe.DSAparam.decode(g.subjectPrivateKey,"der"),{type:"dsa",params:g.algorithm.params};default:throw new Error("unknown key id "+f)}case"RSA PUBLIC KEY":return Pe.RSAPublicKey.decode(m,"der");case"RSA PRIVATE KEY":return Pe.RSAPrivateKey.decode(m,"der");case"DSA PRIVATE KEY":return{type:"dsa",params:Pe.DSAPrivateKey.decode(m,"der")};case"EC PRIVATE KEY":return m=Pe.ECPrivateKey.decode(m,"der"),{curve:m.parameters.value,privateKey:m.privateKey};default:throw new Error("unknown key type "+s)}}Zo.signature=Pe.signature;var lf=Zo;const Wo={"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 vh;function $2(){if(vh)return Pi.exports;vh=1;var a=zt.Buffer,n=ts,o=Z0,s=X0().ec,m=H0,f=lf,g=Wo,y=1;function S(z,$,lt,H,At){var Bt=f($);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 w(z,Bt,lt)}if(H!=="rsa"&&H!=="ecdsa/rsa")throw new Error("wrong private key type");if($.padding!==void 0&&$.padding!==y)throw new Error("illegal or unsupported padding mode");z=a.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 It=o(Et,Bt);return It}function B(z,$){var lt=g[$.curve.join(".")];if(!lt)throw new Error("unknown curve "+$.curve.join("."));var H=new s(lt),At=H.keyFromPrivate($.privateKey),Bt=At.sign(z);return a.from(Bt.toDER())}function w(z,$,lt){for(var H=$.params.priv_key,At=$.params.p,Bt=$.params.q,Ct=$.params.g,Et=new m(0),Y,It=k(z,Bt).mod(Bt),p=!1,t=I(H,Bt,z,lt);p===!1;)Y=U(Bt,t,lt),Et=W(Ct,Y,At,Bt),p=Y.invm(Bt).imul(It.add(H.mul(Et))).mod(Bt),p.cmpn(0)===0&&(p=!1,Et=new m(0));return x(Et,p)}function x(z,$){z=z.toArray(),$=$.toArray(),z[0]&128&&(z=[0].concat(z)),$[0]&128&&($=[0].concat($));var lt=z.length+$.length+4,H=[48,lt,2,z.length];return H=H.concat(z,[2,$.length],$),a.from(H)}function I(z,$,lt,H){if(z=a.from(z.toArray()),z.length<$.byteLength()){var At=a.alloc($.byteLength()-z.length);z=a.concat([At,z])}var Bt=lt.length,Ct=D(lt,$),Et=a.alloc(Bt);Et.fill(1);var Y=a.alloc(Bt);return Y=n(H,Y).update(Et).update(a.from([0])).update(z).update(Ct).digest(),Et=n(H,Y).update(Et).digest(),Y=n(H,Y).update(Et).update(a.from([1])).update(z).update(Ct).digest(),Et=n(H,Y).update(Et).digest(),{k:Y,v:Et}}function k(z,$){var lt=new m(z),H=(z.length<<3)-$.bitLength();return H>0&<.ishrn(H),lt}function D(z,$){z=k(z,$),z=z.mod($);var lt=a.from(z.toArray());if(lt.length<$.byteLength()){var H=a.alloc($.byteLength()-lt.length);lt=a.concat([H,lt])}return lt}function U(z,$,lt){var H,At;do{for(H=a.alloc(0);H.length*8<z.bitLength();)$.v=n(lt,$.k).update($.v).digest(),H=a.concat([H,$.v]);At=k(H,z),$.k=n(lt,$.k).update($.v).update(a.from([0])).digest(),$.v=n(lt,$.k).update($.v).digest()}while(At.cmp(z)!==-1);return At}function W(z,$,lt,H){return z.toRed(m.mont(lt)).redPow($).fromRed().mod(H)}return Pi.exports=S,Pi.exports.getKey=I,Pi.exports.makeKey=U,Pi.exports}var jf,ph;function L2(){if(ph)return jf;ph=1;var a=zt.Buffer,n=H0,o=X0().ec,s=lf,m=Wo;function f(B,w,x,I,k){var D=s(x);if(D.type==="ec"){if(I!=="ecdsa"&&I!=="ecdsa/rsa")throw new Error("wrong public key type");return g(B,w,D)}else if(D.type==="dsa"){if(I!=="dsa")throw new Error("wrong public key type");return y(B,w,D)}if(I!=="rsa"&&I!=="ecdsa/rsa")throw new Error("wrong public key type");w=a.concat([k,w]);for(var U=D.modulus.byteLength(),W=[1],z=0;w.length+W.length+2<U;)W.push(255),z+=1;W.push(0);for(var $=-1;++$<w.length;)W.push(w[$]);W=a.from(W);var lt=n.mont(D.modulus);B=new n(B).toRed(lt),B=B.redPow(new n(D.publicExponent)),B=a.from(B.fromRed().toArray());var H=z<8?1:0;for(U=Math.min(B.length,W.length),B.length!==W.length&&(H=1),$=-1;++$<U;)H|=B[$]^W[$];return H===0}function g(B,w,x){var I=m[x.data.algorithm.curve.join(".")];if(!I)throw new Error("unknown curve "+x.data.algorithm.curve.join("."));var k=new o(I),D=x.data.subjectPrivateKey.data;return k.verify(w,B,D)}function y(B,w,x){var I=x.data.p,k=x.data.q,D=x.data.g,U=x.data.pub_key,W=s.signature.decode(B,"der"),z=W.s,$=W.r;S(z,k),S($,k);var lt=n.mont(I),H=z.invm(k),At=D.toRed(lt).redPow(new n(w).mul(H).mod(k)).fromRed().mul(U.toRed(lt).redPow($.mul(H).mod(k)).fromRed()).mod(I).mod(k);return At.cmp($)===0}function S(B,w){if(B.cmpn(0)<=0)throw new Error("invalid sig");if(B.cmp(w)>=0)throw new Error("invalid sig")}return jf=f,jf}var Qf,mh;function U2(){if(mh)return Qf;mh=1;var a=zt.Buffer,n=Qi,o=Dv,s=Gt,m=$2(),f=L2(),g=es;Object.keys(g).forEach(function(x){g[x].id=a.from(g[x].id,"hex"),g[x.toLowerCase()]=g[x]});function y(x){o.Writable.call(this);var I=g[x];if(!I)throw new Error("Unknown message digest");this._hashType=I.hash,this._hash=n(I.hash),this._tag=I.id,this._signType=I.sign}s(y,o.Writable),y.prototype._write=function(I,k,D){this._hash.update(I),D()},y.prototype.update=function(I,k){return this._hash.update(typeof I=="string"?a.from(I,k):I),this},y.prototype.sign=function(I,k){this.end();var D=this._hash.digest(),U=m(D,I,this._hashType,this._signType,this._tag);return k?U.toString(k):U};function S(x){o.Writable.call(this);var I=g[x];if(!I)throw new Error("Unknown message digest");this._hash=n(I.hash),this._tag=I.id,this._signType=I.sign}s(S,o.Writable),S.prototype._write=function(I,k,D){this._hash.update(I),D()},S.prototype.update=function(I,k){return this._hash.update(typeof I=="string"?a.from(I,k):I),this},S.prototype.verify=function(I,k,D){var U=typeof k=="string"?a.from(k,D):k;this.end();var W=this._hash.digest();return f(U,W,I,this._signType,this._tag)};function B(x){return new y(x)}function w(x){return new S(x)}return Qf={Sign:B,Verify:w,createSign:B,createVerify:w},Qf}var ta={exports:{}};ta.exports;(function(a){(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=Ne.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 h=0;t[0]==="-"&&(h++,this.negative=1),h<t.length&&(r===16?this._parseHex(t,h,i):(this._parseBase(t,r,h),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 h=0;h<this.length;h++)this.words[h]=0;var d,c,v=0;if(i==="be")for(h=t.length-1,d=0;h>=0;h-=3)c=t[h]|t[h-1]<<8|t[h-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(h=0,d=0;h<t.length;h+=3)c=t[h]|t[h+1]<<8|t[h+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 h=0;h<this.length;h++)this.words[h]=0;var d=0,c=0,v;if(i==="be")for(h=t.length-1;h>=r;h-=2)v=S(t,r,h)<<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(h=u%2===0?r+1:r;h<t.length;h+=2)v=S(t,r,h)<<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 h=0,d=Math.min(p.length,r),c=t;c<d;c++){var v=p.charCodeAt(c)-48;h*=i,v>=49?h+=v-49+10:v>=17?h+=v-17+10:h+=v}return h}f.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var h=0,d=1;d<=67108863;d*=r)h++;h--,d=d/r|0;for(var c=t.length-i,v=c%h,u=Math.min(c,c-v)+i,e=0,l=i;l<u;l+=h)e=B(t,l,l+h,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 w=["","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],I=[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 h=0,d=0,c=0;c<this.length;c++){var v=this.words[c],u=((v<<h|d)&16777215).toString(16);d=v>>>24-h&16777215,h+=2,h>=26&&(h-=26,c--),d!==0||c!==this.length-1?i=w[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=I[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=w[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 h=this.byteLength(),d=i||Math.max(1,h);s(h<=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-h;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 k(p){for(var t=new Array(p.bitLength()),r=0;r<t.length;r++){var i=r/26|0,h=r%26;t[r]=(p.words[i]&1<<h)>>>h}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 h=0;h<i.length;h++)this.words[h]=r.words[h]^i.words[h];if(this!==r)for(;h<r.length;h++)this.words[h]=r.words[h];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 h=0;h<r;h++)this.words[h]=~this.words[h]&67108863;return i>0&&(this.words[h]=~this.words[h]&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,h=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<h:this.words[i]=this.words[i]&~(1<<h),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,h;this.length>t.length?(i=this,h=t):(i=t,h=this);for(var d=0,c=0;c<h.length;c++)r=(i.words[c]|0)+(h.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 h,d;i>0?(h=this,d=t):(h=t,d=this);for(var c=0,v=0;v<d.length;v++)r=(h.words[v]|0)-(d.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;for(;c!==0&&v<h.length;v++)r=(h.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;if(c===0&&v<h.length&&h!==this)for(;v<h.length;v++)this.words[v]=h.words[v];return this.length=Math.max(this.length,v),h!==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 h=p.words[0]|0,d=t.words[0]|0,c=h*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 q=e-C|0;h=p.words[q]|0,d=t.words[C]|0,c=h*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 U=function(t,r,i){var h=t.words,d=r.words,c=i.words,v=0,u,e,l,b=h[0]|0,_=b&8191,C=b>>>13,q=h[1]|0,O=q&8191,R=q>>>13,P=h[2]|0,N=P&8191,K=P>>>13,kt=h[3]|0,Z=kt&8191,J=kt>>>13,Ft=h[4]|0,tt=Ft&8191,vt=Ft>>>13,Nt=h[5]|0,et=Nt&8191,pt=Nt>>>13,Dt=h[6]|0,j=Dt&8191,dt=Dt>>>13,Pt=h[7]|0,Q=Pt&8191,ct=Pt>>>13,Ot=h[8]|0,E=Ot&8191,M=Ot>>>13,A=h[9]|0,T=A&8191,F=A>>>13,V=d[0]|0,L=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,Kt=d[3]|0,nt=Kt&8191,bt=Kt>>>13,Ht=d[4]|0,ft=Ht&8191,yt=Ht>>>13,Zt=d[5]|0,at=Zt&8191,wt=Zt>>>13,Wt=d[6]|0,ht=Wt&8191,Mt=Wt>>>13,Vt=d[7]|0,st=Vt&8191,xt=Vt>>>13,Yt=d[8]|0,ot=Yt&8191,_t=Yt>>>13,Jt=d[9]|0,ut=Jt&8191,St=Jt>>>13;i.negative=t.negative^r.negative,i.length=19,u=Math.imul(_,L),e=Math.imul(_,X),e=e+Math.imul(C,L)|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,L),e=Math.imul(O,X),e=e+Math.imul(R,L)|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 Lt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,u=Math.imul(N,L),e=Math.imul(N,X),e=e+Math.imul(K,L)|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 Qt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,u=Math.imul(Z,L),e=Math.imul(Z,X),e=e+Math.imul(J,L)|0,l=Math.imul(J,X),u=u+Math.imul(N,G)|0,e=e+Math.imul(N,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 te=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(te>>>26)|0,te&=67108863,u=Math.imul(tt,L),e=Math.imul(tt,X),e=e+Math.imul(vt,L)|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(N,it)|0,e=e+Math.imul(N,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 ee=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,u=Math.imul(et,L),e=Math.imul(et,X),e=e+Math.imul(pt,L)|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(N,nt)|0,e=e+Math.imul(N,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 re=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(re>>>26)|0,re&=67108863,u=Math.imul(j,L),e=Math.imul(j,X),e=e+Math.imul(dt,L)|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(N,ft)|0,e=e+Math.imul(N,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 ie=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,u=Math.imul(Q,L),e=Math.imul(Q,X),e=e+Math.imul(ct,L)|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(N,at)|0,e=e+Math.imul(N,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 ne=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,u=Math.imul(E,L),e=Math.imul(E,X),e=e+Math.imul(M,L)|0,l=Math.imul(M,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(N,ht)|0,e=e+Math.imul(N,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 fe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(fe>>>26)|0,fe&=67108863,u=Math.imul(T,L),e=Math.imul(T,X),e=e+Math.imul(F,L)|0,l=Math.imul(F,X),u=u+Math.imul(E,G)|0,e=e+Math.imul(E,rt)|0,e=e+Math.imul(M,G)|0,l=l+Math.imul(M,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(N,st)|0,e=e+Math.imul(N,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 ae=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,u=Math.imul(T,G),e=Math.imul(T,rt),e=e+Math.imul(F,G)|0,l=Math.imul(F,rt),u=u+Math.imul(E,it)|0,e=e+Math.imul(E,gt)|0,e=e+Math.imul(M,it)|0,l=l+Math.imul(M,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(N,ot)|0,e=e+Math.imul(N,_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 he=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(he>>>26)|0,he&=67108863,u=Math.imul(T,it),e=Math.imul(T,gt),e=e+Math.imul(F,it)|0,l=Math.imul(F,gt),u=u+Math.imul(E,nt)|0,e=e+Math.imul(E,bt)|0,e=e+Math.imul(M,nt)|0,l=l+Math.imul(M,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(N,ut)|0,e=e+Math.imul(N,St)|0,e=e+Math.imul(K,ut)|0,l=l+Math.imul(K,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,nt),e=Math.imul(T,bt),e=e+Math.imul(F,nt)|0,l=Math.imul(F,bt),u=u+Math.imul(E,ft)|0,e=e+Math.imul(E,yt)|0,e=e+Math.imul(M,ft)|0,l=l+Math.imul(M,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 oe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(oe>>>26)|0,oe&=67108863,u=Math.imul(T,ft),e=Math.imul(T,yt),e=e+Math.imul(F,ft)|0,l=Math.imul(F,yt),u=u+Math.imul(E,at)|0,e=e+Math.imul(E,wt)|0,e=e+Math.imul(M,at)|0,l=l+Math.imul(M,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 ue=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ue>>>26)|0,ue&=67108863,u=Math.imul(T,at),e=Math.imul(T,wt),e=e+Math.imul(F,at)|0,l=Math.imul(F,wt),u=u+Math.imul(E,ht)|0,e=e+Math.imul(E,Mt)|0,e=e+Math.imul(M,ht)|0,l=l+Math.imul(M,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 le=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(le>>>26)|0,le&=67108863,u=Math.imul(T,ht),e=Math.imul(T,Mt),e=e+Math.imul(F,ht)|0,l=Math.imul(F,Mt),u=u+Math.imul(E,st)|0,e=e+Math.imul(E,xt)|0,e=e+Math.imul(M,st)|0,l=l+Math.imul(M,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 de=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(de>>>26)|0,de&=67108863,u=Math.imul(T,st),e=Math.imul(T,xt),e=e+Math.imul(F,st)|0,l=Math.imul(F,xt),u=u+Math.imul(E,ot)|0,e=e+Math.imul(E,_t)|0,e=e+Math.imul(M,ot)|0,l=l+Math.imul(M,_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 ce=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ce>>>26)|0,ce&=67108863,u=Math.imul(T,ot),e=Math.imul(T,_t),e=e+Math.imul(F,ot)|0,l=Math.imul(F,_t),u=u+Math.imul(E,ut)|0,e=e+Math.imul(E,St)|0,e=e+Math.imul(M,ut)|0,l=l+Math.imul(M,St)|0;var ve=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,u=Math.imul(T,ut),e=Math.imul(T,St),e=e+Math.imul(F,ut)|0,l=Math.imul(F,St);var pe=(v+u|0)+((e&8191)<<13)|0;return v=(l+(e>>>13)|0)+(pe>>>26)|0,pe&=67108863,c[0]=$t,c[1]=Lt,c[2]=Qt,c[3]=te,c[4]=ee,c[5]=re,c[6]=ie,c[7]=ne,c[8]=fe,c[9]=ae,c[10]=he,c[11]=se,c[12]=oe,c[13]=ue,c[14]=le,c[15]=de,c[16]=ce,c[17]=ve,c[18]=pe,v!==0&&(c[19]=v,i.length++),i};Math.imul||(U=D);function W(p,t,r){r.negative=t.negative^p.negative,r.length=p.length+t.length;for(var i=0,h=0,d=0;d<r.length-1;d++){var c=h;h=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*_,q=C&67108863;c=c+(C/67108864|0)|0,q=q+v|0,v=q&67108863,c=c+(q>>>26)|0,h+=c>>>26,c&=67108863}r.words[d]=v,i=c,c=h}return i!==0?r.words[d]=i:r.length--,r.strip()}function z(p,t,r){var i=new $;return i.mulp(p,t,r)}f.prototype.mulTo=function(t,r){var i,h=this.length+t.length;return this.length===10&&t.length===10?i=U(this,t,r):h<63?i=D(this,t,r):h<1024?i=W(this,t,r):i=z(this,t,r),i};function $(p,t){this.x=p,this.y=t}$.prototype.makeRBT=function(t){for(var r=new Array(t),i=f.prototype._countBits(t)-1,h=0;h<t;h++)r[h]=this.revBin(h,i,t);return r},$.prototype.revBin=function(t,r,i){if(t===0||t===i-1)return t;for(var h=0,d=0;d<r;d++)h|=(t&1)<<r-d-1,t>>=1;return h},$.prototype.permute=function(t,r,i,h,d,c){for(var v=0;v<c;v++)h[v]=r[t[v]],d[v]=i[t[v]]},$.prototype.transform=function(t,r,i,h,d,c){this.permute(c,t,r,i,h,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,q=0;q<v;q++){var O=i[b+q],R=h[b+q],P=i[b+q+v],N=h[b+q+v],K=_*P-C*N;N=_*N+C*P,P=K,i[b+q]=O+P,h[b+q]=R+N,i[b+q+v]=O-P,h[b+q+v]=R-N,q!==u&&(K=e*_-l*C,C=e*C+l*_,_=K)}},$.prototype.guessLen13b=function(t,r){var i=Math.max(r,t)|1,h=i&1,d=0;for(i=i/2|0;i;i=i>>>1)d++;return 1<<d+1+h},$.prototype.conjugate=function(t,r,i){if(!(i<=1))for(var h=0;h<i/2;h++){var d=t[h];t[h]=t[i-h-1],t[i-h-1]=d,d=r[h],r[h]=-r[i-h-1],r[i-h-1]=-d}},$.prototype.normalize13b=function(t,r){for(var i=0,h=0;h<r/2;h++){var d=Math.round(t[2*h+1]/r)*8192+Math.round(t[2*h]/r)+i;t[h]=d&67108863,d<67108864?i=0:i=d/67108864|0}return t},$.prototype.convert13b=function(t,r,i,h){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<h;++c)i[c]=0;s(d===0),s((d&-8192)===0)},$.prototype.stub=function(t){for(var r=new Array(t),i=0;i<t;i++)r[i]=0;return r},$.prototype.mulp=function(t,r,i){var h=2*this.guessLen13b(t.length,r.length),d=this.makeRBT(h),c=this.stub(h),v=new Array(h),u=new Array(h),e=new Array(h),l=new Array(h),b=new Array(h),_=new Array(h),C=i.words;C.length=h,this.convert13b(t.words,t.length,v,h),this.convert13b(r.words,r.length,l,h),this.transform(v,c,u,e,h,d),this.transform(l,c,b,_,h,d);for(var q=0;q<h;q++){var O=u[q]*b[q]-e[q]*_[q];e[q]=u[q]*_[q]+e[q]*b[q],u[q]=O}return this.conjugate(u,e,h),this.transform(u,e,C,c,h,d),this.conjugate(C,c,h),this.normalize13b(C,h),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 h=(this.words[i]|0)*t,d=(h&67108863)+(r&67108863);r>>=26,r+=h/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=k(t);if(r.length===0)return new f(1);for(var i=this,h=0;h<r.length&&r[h]===0;h++,i=i.sqr());if(++h<r.length)for(var d=i.sqr();h<r.length;h++,d=d.sqr())r[h]!==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,h=67108863>>>26-r<<26-r,d;if(r!==0){var c=0;for(d=0;d<this.length;d++){var v=this.words[d]&h,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 h;r?h=(r-r%26)/26:h=0;var d=t%26,c=Math.min((t-d)/26,this.length),v=67108863^67108863>>>d<<d,u=i;if(h-=c,h=Math.max(0,h),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>=h);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,h=1<<r;if(this.length<=i)return!1;var d=this.words[i];return!!(d&h)},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 h=67108863^67108863>>>r<<r;this.words[this.length-1]&=h}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 h=t.length+i,d;this._expand(h);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,h=this.clone(),d=t,c=d.words[d.length-1]|0,v=this._countBits(c);i=26-v,i!==0&&(d=d.ushln(i),h.iushln(i),c=d.words[d.length-1]|0);var u=h.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=h.clone()._ishlnsubmul(d,1,u);b.negative===0&&(h=b,e&&(e.words[u]=1));for(var _=u-1;_>=0;_--){var C=(h.words[d.length+_]|0)*67108864+(h.words[d.length+_-1]|0);for(C=Math.min(C/c|0,67108863),h._ishlnsubmul(d,C,_);h.negative!==0;)C--,h.negative=0,h._ishlnsubmul(d,1,_),h.isZero()||(h.negative^=1);e&&(e.words[_]=C)}return e&&e.strip(),h.strip(),r!=="div"&&i!==0&&h.iushrn(i),{div:e||null,mod:h}},f.prototype.divmod=function(t,r,i){if(s(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var h,d,c;return this.negative!==0&&t.negative===0?(c=this.neg().divmod(t,r),r!=="mod"&&(h=c.div.neg()),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.iadd(t)),{div:h,mod:d}):this.negative===0&&t.negative!==0?(c=this.divmod(t.neg(),r),r!=="mod"&&(h=c.div.neg()),{div:h,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,h=t.ushrn(1),d=t.andln(1),c=i.cmp(h);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,h=this.length-1;h>=0;h--)i=(r*i+(this.words[h]|0))%t;return i},f.prototype.idivn=function(t){s(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var h=(this.words[i]|0)+r*67108864;this.words[i]=h/t|0,r=h%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 h=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;)(h.isOdd()||d.isOdd())&&(h.iadd(e),d.isub(l)),h.iushrn(1),d.iushrn(1);for(var C=0,q=1;!(i.words[0]&q)&&C<26;++C,q<<=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),h.isub(c),d.isub(v)):(i.isub(r),c.isub(h),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 h=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;)h.isOdd()&&h.iadd(c),h.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),h.isub(d)):(i.isub(r),d.isub(h))}var b;return r.cmpn(1)===0?b=h: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 h=0;r.isEven()&&i.isEven();h++)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(h)},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,h=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=h,this;for(var d=h,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 h=this.words[0]|0;i=h===t?0:h<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 h=this.words[i]|0,d=t.words[i]|0;if(h!==d){h<d?r=-1:h>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 h=i<this.n?-1:r.ucmp(this.p);return h===0?(r.words[0]=0,r.length=1):h>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,h=Math.min(t.length,9),d=0;d<h;d++)r.words[d]=t.words[d];if(r.length=h,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 h=t.words[i]|0;r+=h*977,t.words[i]=r&67108863,r=h*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 h=(t.words[i]|0)*19+r,d=h&67108863;h>>>=26,t.words[i]=d,r=h}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 h=this.m.subn(1),d=0;!h.isZero()&&h.andln(1)===0;)d++,h.iushrn(1);s(!h.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,h),b=this.pow(t,h.addn(1).iushrn(1)),_=this.pow(t,h),C=d;_.cmp(c)!==0;){for(var q=_,O=0;q.cmp(c)!==0;O++)q=q.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,h=new Array(1<<i);h[0]=new f(1).toRed(this),h[1]=t;for(var d=2;d<h.length;d++)h[d]=this.mul(h[d-1],t);var c=h[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!==h[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,h[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 It(t)};function It(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(It,Y),It.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},It.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},It.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),h=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(h).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)},It.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var i=t.mul(r),h=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(h).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)},It.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(a,Xt)})(ta);var O2=ta.exports,t0,gh;function z2(){if(gh)return t0;gh=1;var a=X0(),n=O2;t0=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 a.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 t0}var Vo={},K2=Qi,y0=zt.Buffer,Yo=function(a,n){for(var o=y0.alloc(0),s=0,m;o.length<n;)m=H2(s++),o=y0.concat([o,K2("sha1").update(a).update(m).digest()]);return o.slice(0,n)};function H2(a){var n=y0.allocUnsafe(4);return n.writeUInt32BE(a,0),n}var Jo=function(n,o){for(var s=n.length,m=-1;++m<s;)n[m]^=o[m];return n},ea={exports:{}};ea.exports;(function(a){(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=Ne.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 h=0;t[0]==="-"&&(h++,this.negative=1),h<t.length&&(r===16?this._parseHex(t,h,i):(this._parseBase(t,r,h),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 h=0;h<this.length;h++)this.words[h]=0;var d,c,v=0;if(i==="be")for(h=t.length-1,d=0;h>=0;h-=3)c=t[h]|t[h-1]<<8|t[h-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(h=0,d=0;h<t.length;h+=3)c=t[h]|t[h+1]<<8|t[h+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 h=0;h<this.length;h++)this.words[h]=0;var d=0,c=0,v;if(i==="be")for(h=t.length-1;h>=r;h-=2)v=S(t,r,h)<<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(h=u%2===0?r+1:r;h<t.length;h+=2)v=S(t,r,h)<<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 h=0,d=Math.min(p.length,r),c=t;c<d;c++){var v=p.charCodeAt(c)-48;h*=i,v>=49?h+=v-49+10:v>=17?h+=v-17+10:h+=v}return h}f.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var h=0,d=1;d<=67108863;d*=r)h++;h--,d=d/r|0;for(var c=t.length-i,v=c%h,u=Math.min(c,c-v)+i,e=0,l=i;l<u;l+=h)e=B(t,l,l+h,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 w=["","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],I=[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 h=0,d=0,c=0;c<this.length;c++){var v=this.words[c],u=((v<<h|d)&16777215).toString(16);d=v>>>24-h&16777215,h+=2,h>=26&&(h-=26,c--),d!==0||c!==this.length-1?i=w[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=I[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=w[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 h=this.byteLength(),d=i||Math.max(1,h);s(h<=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-h;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 k(p){for(var t=new Array(p.bitLength()),r=0;r<t.length;r++){var i=r/26|0,h=r%26;t[r]=(p.words[i]&1<<h)>>>h}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 h=0;h<i.length;h++)this.words[h]=r.words[h]^i.words[h];if(this!==r)for(;h<r.length;h++)this.words[h]=r.words[h];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 h=0;h<r;h++)this.words[h]=~this.words[h]&67108863;return i>0&&(this.words[h]=~this.words[h]&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,h=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<h:this.words[i]=this.words[i]&~(1<<h),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,h;this.length>t.length?(i=this,h=t):(i=t,h=this);for(var d=0,c=0;c<h.length;c++)r=(i.words[c]|0)+(h.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 h,d;i>0?(h=this,d=t):(h=t,d=this);for(var c=0,v=0;v<d.length;v++)r=(h.words[v]|0)-(d.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;for(;c!==0&&v<h.length;v++)r=(h.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;if(c===0&&v<h.length&&h!==this)for(;v<h.length;v++)this.words[v]=h.words[v];return this.length=Math.max(this.length,v),h!==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 h=p.words[0]|0,d=t.words[0]|0,c=h*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 q=e-C|0;h=p.words[q]|0,d=t.words[C]|0,c=h*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 U=function(t,r,i){var h=t.words,d=r.words,c=i.words,v=0,u,e,l,b=h[0]|0,_=b&8191,C=b>>>13,q=h[1]|0,O=q&8191,R=q>>>13,P=h[2]|0,N=P&8191,K=P>>>13,kt=h[3]|0,Z=kt&8191,J=kt>>>13,Ft=h[4]|0,tt=Ft&8191,vt=Ft>>>13,Nt=h[5]|0,et=Nt&8191,pt=Nt>>>13,Dt=h[6]|0,j=Dt&8191,dt=Dt>>>13,Pt=h[7]|0,Q=Pt&8191,ct=Pt>>>13,Ot=h[8]|0,E=Ot&8191,M=Ot>>>13,A=h[9]|0,T=A&8191,F=A>>>13,V=d[0]|0,L=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,Kt=d[3]|0,nt=Kt&8191,bt=Kt>>>13,Ht=d[4]|0,ft=Ht&8191,yt=Ht>>>13,Zt=d[5]|0,at=Zt&8191,wt=Zt>>>13,Wt=d[6]|0,ht=Wt&8191,Mt=Wt>>>13,Vt=d[7]|0,st=Vt&8191,xt=Vt>>>13,Yt=d[8]|0,ot=Yt&8191,_t=Yt>>>13,Jt=d[9]|0,ut=Jt&8191,St=Jt>>>13;i.negative=t.negative^r.negative,i.length=19,u=Math.imul(_,L),e=Math.imul(_,X),e=e+Math.imul(C,L)|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,L),e=Math.imul(O,X),e=e+Math.imul(R,L)|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 Lt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,u=Math.imul(N,L),e=Math.imul(N,X),e=e+Math.imul(K,L)|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 Qt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,u=Math.imul(Z,L),e=Math.imul(Z,X),e=e+Math.imul(J,L)|0,l=Math.imul(J,X),u=u+Math.imul(N,G)|0,e=e+Math.imul(N,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 te=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(te>>>26)|0,te&=67108863,u=Math.imul(tt,L),e=Math.imul(tt,X),e=e+Math.imul(vt,L)|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(N,it)|0,e=e+Math.imul(N,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 ee=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,u=Math.imul(et,L),e=Math.imul(et,X),e=e+Math.imul(pt,L)|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(N,nt)|0,e=e+Math.imul(N,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 re=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(re>>>26)|0,re&=67108863,u=Math.imul(j,L),e=Math.imul(j,X),e=e+Math.imul(dt,L)|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(N,ft)|0,e=e+Math.imul(N,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 ie=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,u=Math.imul(Q,L),e=Math.imul(Q,X),e=e+Math.imul(ct,L)|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(N,at)|0,e=e+Math.imul(N,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 ne=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,u=Math.imul(E,L),e=Math.imul(E,X),e=e+Math.imul(M,L)|0,l=Math.imul(M,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(N,ht)|0,e=e+Math.imul(N,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 fe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(fe>>>26)|0,fe&=67108863,u=Math.imul(T,L),e=Math.imul(T,X),e=e+Math.imul(F,L)|0,l=Math.imul(F,X),u=u+Math.imul(E,G)|0,e=e+Math.imul(E,rt)|0,e=e+Math.imul(M,G)|0,l=l+Math.imul(M,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(N,st)|0,e=e+Math.imul(N,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 ae=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,u=Math.imul(T,G),e=Math.imul(T,rt),e=e+Math.imul(F,G)|0,l=Math.imul(F,rt),u=u+Math.imul(E,it)|0,e=e+Math.imul(E,gt)|0,e=e+Math.imul(M,it)|0,l=l+Math.imul(M,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(N,ot)|0,e=e+Math.imul(N,_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 he=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(he>>>26)|0,he&=67108863,u=Math.imul(T,it),e=Math.imul(T,gt),e=e+Math.imul(F,it)|0,l=Math.imul(F,gt),u=u+Math.imul(E,nt)|0,e=e+Math.imul(E,bt)|0,e=e+Math.imul(M,nt)|0,l=l+Math.imul(M,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(N,ut)|0,e=e+Math.imul(N,St)|0,e=e+Math.imul(K,ut)|0,l=l+Math.imul(K,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,nt),e=Math.imul(T,bt),e=e+Math.imul(F,nt)|0,l=Math.imul(F,bt),u=u+Math.imul(E,ft)|0,e=e+Math.imul(E,yt)|0,e=e+Math.imul(M,ft)|0,l=l+Math.imul(M,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 oe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(oe>>>26)|0,oe&=67108863,u=Math.imul(T,ft),e=Math.imul(T,yt),e=e+Math.imul(F,ft)|0,l=Math.imul(F,yt),u=u+Math.imul(E,at)|0,e=e+Math.imul(E,wt)|0,e=e+Math.imul(M,at)|0,l=l+Math.imul(M,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 ue=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ue>>>26)|0,ue&=67108863,u=Math.imul(T,at),e=Math.imul(T,wt),e=e+Math.imul(F,at)|0,l=Math.imul(F,wt),u=u+Math.imul(E,ht)|0,e=e+Math.imul(E,Mt)|0,e=e+Math.imul(M,ht)|0,l=l+Math.imul(M,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 le=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(le>>>26)|0,le&=67108863,u=Math.imul(T,ht),e=Math.imul(T,Mt),e=e+Math.imul(F,ht)|0,l=Math.imul(F,Mt),u=u+Math.imul(E,st)|0,e=e+Math.imul(E,xt)|0,e=e+Math.imul(M,st)|0,l=l+Math.imul(M,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 de=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(de>>>26)|0,de&=67108863,u=Math.imul(T,st),e=Math.imul(T,xt),e=e+Math.imul(F,st)|0,l=Math.imul(F,xt),u=u+Math.imul(E,ot)|0,e=e+Math.imul(E,_t)|0,e=e+Math.imul(M,ot)|0,l=l+Math.imul(M,_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 ce=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ce>>>26)|0,ce&=67108863,u=Math.imul(T,ot),e=Math.imul(T,_t),e=e+Math.imul(F,ot)|0,l=Math.imul(F,_t),u=u+Math.imul(E,ut)|0,e=e+Math.imul(E,St)|0,e=e+Math.imul(M,ut)|0,l=l+Math.imul(M,St)|0;var ve=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,u=Math.imul(T,ut),e=Math.imul(T,St),e=e+Math.imul(F,ut)|0,l=Math.imul(F,St);var pe=(v+u|0)+((e&8191)<<13)|0;return v=(l+(e>>>13)|0)+(pe>>>26)|0,pe&=67108863,c[0]=$t,c[1]=Lt,c[2]=Qt,c[3]=te,c[4]=ee,c[5]=re,c[6]=ie,c[7]=ne,c[8]=fe,c[9]=ae,c[10]=he,c[11]=se,c[12]=oe,c[13]=ue,c[14]=le,c[15]=de,c[16]=ce,c[17]=ve,c[18]=pe,v!==0&&(c[19]=v,i.length++),i};Math.imul||(U=D);function W(p,t,r){r.negative=t.negative^p.negative,r.length=p.length+t.length;for(var i=0,h=0,d=0;d<r.length-1;d++){var c=h;h=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*_,q=C&67108863;c=c+(C/67108864|0)|0,q=q+v|0,v=q&67108863,c=c+(q>>>26)|0,h+=c>>>26,c&=67108863}r.words[d]=v,i=c,c=h}return i!==0?r.words[d]=i:r.length--,r.strip()}function z(p,t,r){var i=new $;return i.mulp(p,t,r)}f.prototype.mulTo=function(t,r){var i,h=this.length+t.length;return this.length===10&&t.length===10?i=U(this,t,r):h<63?i=D(this,t,r):h<1024?i=W(this,t,r):i=z(this,t,r),i};function $(p,t){this.x=p,this.y=t}$.prototype.makeRBT=function(t){for(var r=new Array(t),i=f.prototype._countBits(t)-1,h=0;h<t;h++)r[h]=this.revBin(h,i,t);return r},$.prototype.revBin=function(t,r,i){if(t===0||t===i-1)return t;for(var h=0,d=0;d<r;d++)h|=(t&1)<<r-d-1,t>>=1;return h},$.prototype.permute=function(t,r,i,h,d,c){for(var v=0;v<c;v++)h[v]=r[t[v]],d[v]=i[t[v]]},$.prototype.transform=function(t,r,i,h,d,c){this.permute(c,t,r,i,h,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,q=0;q<v;q++){var O=i[b+q],R=h[b+q],P=i[b+q+v],N=h[b+q+v],K=_*P-C*N;N=_*N+C*P,P=K,i[b+q]=O+P,h[b+q]=R+N,i[b+q+v]=O-P,h[b+q+v]=R-N,q!==u&&(K=e*_-l*C,C=e*C+l*_,_=K)}},$.prototype.guessLen13b=function(t,r){var i=Math.max(r,t)|1,h=i&1,d=0;for(i=i/2|0;i;i=i>>>1)d++;return 1<<d+1+h},$.prototype.conjugate=function(t,r,i){if(!(i<=1))for(var h=0;h<i/2;h++){var d=t[h];t[h]=t[i-h-1],t[i-h-1]=d,d=r[h],r[h]=-r[i-h-1],r[i-h-1]=-d}},$.prototype.normalize13b=function(t,r){for(var i=0,h=0;h<r/2;h++){var d=Math.round(t[2*h+1]/r)*8192+Math.round(t[2*h]/r)+i;t[h]=d&67108863,d<67108864?i=0:i=d/67108864|0}return t},$.prototype.convert13b=function(t,r,i,h){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<h;++c)i[c]=0;s(d===0),s((d&-8192)===0)},$.prototype.stub=function(t){for(var r=new Array(t),i=0;i<t;i++)r[i]=0;return r},$.prototype.mulp=function(t,r,i){var h=2*this.guessLen13b(t.length,r.length),d=this.makeRBT(h),c=this.stub(h),v=new Array(h),u=new Array(h),e=new Array(h),l=new Array(h),b=new Array(h),_=new Array(h),C=i.words;C.length=h,this.convert13b(t.words,t.length,v,h),this.convert13b(r.words,r.length,l,h),this.transform(v,c,u,e,h,d),this.transform(l,c,b,_,h,d);for(var q=0;q<h;q++){var O=u[q]*b[q]-e[q]*_[q];e[q]=u[q]*_[q]+e[q]*b[q],u[q]=O}return this.conjugate(u,e,h),this.transform(u,e,C,c,h,d),this.conjugate(C,c,h),this.normalize13b(C,h),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 h=(this.words[i]|0)*t,d=(h&67108863)+(r&67108863);r>>=26,r+=h/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=k(t);if(r.length===0)return new f(1);for(var i=this,h=0;h<r.length&&r[h]===0;h++,i=i.sqr());if(++h<r.length)for(var d=i.sqr();h<r.length;h++,d=d.sqr())r[h]!==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,h=67108863>>>26-r<<26-r,d;if(r!==0){var c=0;for(d=0;d<this.length;d++){var v=this.words[d]&h,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 h;r?h=(r-r%26)/26:h=0;var d=t%26,c=Math.min((t-d)/26,this.length),v=67108863^67108863>>>d<<d,u=i;if(h-=c,h=Math.max(0,h),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>=h);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,h=1<<r;if(this.length<=i)return!1;var d=this.words[i];return!!(d&h)},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 h=67108863^67108863>>>r<<r;this.words[this.length-1]&=h}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 h=t.length+i,d;this._expand(h);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,h=this.clone(),d=t,c=d.words[d.length-1]|0,v=this._countBits(c);i=26-v,i!==0&&(d=d.ushln(i),h.iushln(i),c=d.words[d.length-1]|0);var u=h.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=h.clone()._ishlnsubmul(d,1,u);b.negative===0&&(h=b,e&&(e.words[u]=1));for(var _=u-1;_>=0;_--){var C=(h.words[d.length+_]|0)*67108864+(h.words[d.length+_-1]|0);for(C=Math.min(C/c|0,67108863),h._ishlnsubmul(d,C,_);h.negative!==0;)C--,h.negative=0,h._ishlnsubmul(d,1,_),h.isZero()||(h.negative^=1);e&&(e.words[_]=C)}return e&&e.strip(),h.strip(),r!=="div"&&i!==0&&h.iushrn(i),{div:e||null,mod:h}},f.prototype.divmod=function(t,r,i){if(s(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var h,d,c;return this.negative!==0&&t.negative===0?(c=this.neg().divmod(t,r),r!=="mod"&&(h=c.div.neg()),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.iadd(t)),{div:h,mod:d}):this.negative===0&&t.negative!==0?(c=this.divmod(t.neg(),r),r!=="mod"&&(h=c.div.neg()),{div:h,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,h=t.ushrn(1),d=t.andln(1),c=i.cmp(h);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,h=this.length-1;h>=0;h--)i=(r*i+(this.words[h]|0))%t;return i},f.prototype.idivn=function(t){s(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var h=(this.words[i]|0)+r*67108864;this.words[i]=h/t|0,r=h%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 h=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;)(h.isOdd()||d.isOdd())&&(h.iadd(e),d.isub(l)),h.iushrn(1),d.iushrn(1);for(var C=0,q=1;!(i.words[0]&q)&&C<26;++C,q<<=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),h.isub(c),d.isub(v)):(i.isub(r),c.isub(h),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 h=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;)h.isOdd()&&h.iadd(c),h.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),h.isub(d)):(i.isub(r),d.isub(h))}var b;return r.cmpn(1)===0?b=h: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 h=0;r.isEven()&&i.isEven();h++)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(h)},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,h=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=h,this;for(var d=h,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 h=this.words[0]|0;i=h===t?0:h<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 h=this.words[i]|0,d=t.words[i]|0;if(h!==d){h<d?r=-1:h>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 h=i<this.n?-1:r.ucmp(this.p);return h===0?(r.words[0]=0,r.length=1):h>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,h=Math.min(t.length,9),d=0;d<h;d++)r.words[d]=t.words[d];if(r.length=h,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 h=t.words[i]|0;r+=h*977,t.words[i]=r&67108863,r=h*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 h=(t.words[i]|0)*19+r,d=h&67108863;h>>>=26,t.words[i]=d,r=h}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 h=this.m.subn(1),d=0;!h.isZero()&&h.andln(1)===0;)d++,h.iushrn(1);s(!h.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,h),b=this.pow(t,h.addn(1).iushrn(1)),_=this.pow(t,h),C=d;_.cmp(c)!==0;){for(var q=_,O=0;q.cmp(c)!==0;O++)q=q.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,h=new Array(1<<i);h[0]=new f(1).toRed(this),h[1]=t;for(var d=2;d<h.length;d++)h[d]=this.mul(h[d-1],t);var c=h[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!==h[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,h[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 It(t)};function It(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(It,Y),It.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},It.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},It.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),h=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(h).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)},It.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var i=t.mul(r),h=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(h).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)},It.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(a,Xt)})(ea);var ra=ea.exports,bh=ra,Z2=zt.Buffer;function W2(a,n){return Z2.from(a.toRed(bh.mont(n.modulus)).redPow(new bh(n.publicExponent)).fromRed().toArray())}var Go=W2,V2=lf,w0=yi,Y2=Qi,yh=Yo,wh=Jo,ia=ra,J2=Go,G2=Z0,Qe=zt.Buffer,X2=function(n,o,s){var m;n.padding?m=n.padding:s?m=1:m=4;var f=V2(n),g;if(m===4)g=j2(f,o);else if(m===1)g=Q2(f,o,s);else if(m===3){if(g=new ia(o),g.cmp(f.modulus)>=0)throw new Error("data too long for modulus")}else throw new Error("unknown padding");return s?G2(g,f):J2(g,f)};function j2(a,n){var o=a.modulus.byteLength(),s=n.length,m=Y2("sha1").update(Qe.alloc(0)).digest(),f=m.length,g=2*f;if(s>o-g-2)throw new Error("message too long");var y=Qe.alloc(o-s-g-2),S=o-f-1,B=w0(f),w=wh(Qe.concat([m,y,Qe.alloc(1,1),n],S),yh(B,S)),x=wh(B,yh(w,f));return new ia(Qe.concat([Qe.alloc(1),x,w],o))}function Q2(a,n,o){var s=n.length,m=a.modulus.byteLength();if(s>m-11)throw new Error("message too long");var f;return o?f=Qe.alloc(m-s-3,255):f=tg(m-s-3),new ia(Qe.concat([Qe.from([0,o?1:2]),f,Qe.alloc(1),n],m))}function tg(a){for(var n=Qe.allocUnsafe(a),o=0,s=w0(a*2),m=0,f;o<a;)m===s.length&&(s=w0(a*2),m=0),f=s[m++],f&&(n[o++]=f);return n}var eg=lf,Mh=Yo,xh=Jo,_h=ra,rg=Z0,ig=Qi,ng=Go,Vi=zt.Buffer,fg=function(n,o,s){var m;n.padding?m=n.padding:s?m=1:m=4;var f=eg(n),g=f.modulus.byteLength();if(o.length>g||new _h(o).cmp(f.modulus)>=0)throw new Error("decryption error");var y;s?y=ng(new _h(o),f):y=rg(o,f);var S=Vi.alloc(g-y.length);if(y=Vi.concat([S,y],g),m===4)return ag(f,y);if(m===1)return hg(f,y,s);if(m===3)return y;throw new Error("unknown padding")};function ag(a,n){var o=a.modulus.byteLength(),s=ig("sha1").update(Vi.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=xh(f,Mh(g,m)),S=xh(g,Mh(y,o-m-1));if(sg(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 hg(a,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 sg(a,n){a=Vi.from(a),n=Vi.from(n);var o=0,s=a.length;a.length!==n.length&&(o++,s=Math.min(a.length,n.length));for(var m=-1;++m<s;)o+=a[m]^n[m];return o}(function(a){a.publicEncrypt=X2,a.privateDecrypt=fg,a.privateEncrypt=function(o,s){return a.publicEncrypt(o,s,!0)},a.publicDecrypt=function(o,s){return a.privateDecrypt(o,s,!0)}})(Vo);var Ui={};function Sh(){throw new Error(`secure random number generation not supported by this browser
|
|
16
16
|
use chrome, FireFox or Internet Explorer 11`)}var Xo=zt,Ah=yi,jo=Xo.Buffer,Qo=Xo.kMaxLength,M0=Xt.crypto||Xt.msCrypto,tu=Math.pow(2,32)-1;function eu(a,n){if(typeof a!="number"||a!==a)throw new TypeError("offset must be a number");if(a>tu||a<0)throw new TypeError("offset must be a uint32");if(a>Qo||a>n)throw new RangeError("offset out of range")}function ru(a,n,o){if(typeof a!="number"||a!==a)throw new TypeError("size must be a number");if(a>tu||a<0)throw new TypeError("size must be a uint32");if(a+n>o||a>Qo)throw new RangeError("buffer too small")}M0&&M0.getRandomValues||!we.browser?(Ui.randomFill=og,Ui.randomFillSync=ug):(Ui.randomFill=Sh,Ui.randomFillSync=Sh);function og(a,n,o,s){if(!jo.isBuffer(a)&&!(a instanceof Xt.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');if(typeof n=="function")s=n,n=0,o=a.length;else if(typeof o=="function")s=o,o=a.length-n;else if(typeof s!="function")throw new TypeError('"cb" argument must be a function');return eu(n,a.length),ru(o,n,a.length),iu(a,n,o,s)}function iu(a,n,o,s){if(we.browser){var m=a.buffer,f=new Uint8Array(m,n,o);if(M0.getRandomValues(f),s){we.nextTick(function(){s(null,a)});return}return a}if(s){Ah(o,function(y,S){if(y)return s(y);S.copy(a,n),s(null,a)});return}var g=Ah(o);return g.copy(a,n),a}function ug(a,n,o){if(typeof n=="undefined"&&(n=0),!jo.isBuffer(a)&&!(a instanceof Xt.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');return eu(n,a.length),o===void 0&&(o=a.length-n),ru(o,n,a.length),iu(a,n,o)}var Bh;function nu(){if(Bh)return Ut;Bh=1,Ut.randomBytes=Ut.rng=Ut.pseudoRandomBytes=Ut.prng=yi,Ut.createHash=Ut.Hash=Qi,Ut.createHmac=Ut.Hmac=ts;var a=tc,n=Object.keys(a),o=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(n);Ut.getHashes=function(){return o};var s=zn;Ut.pbkdf2=s.pbkdf2,Ut.pbkdf2Sync=s.pbkdf2Sync;var m=tr;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=uv();Ut.DiffieHellmanGroup=f.DiffieHellmanGroup,Ut.createDiffieHellmanGroup=f.createDiffieHellmanGroup,Ut.getDiffieHellman=f.getDiffieHellman,Ut.createDiffieHellman=f.createDiffieHellman,Ut.DiffieHellman=f.DiffieHellman;var g=U2();Ut.createSign=g.createSign,Ut.Sign=g.Sign,Ut.createVerify=g.createVerify,Ut.Verify=g.Verify,Ut.createECDH=z2();var y=Vo;Ut.publicEncrypt=y.publicEncrypt,Ut.privateEncrypt=y.privateEncrypt,Ut.publicDecrypt=y.publicDecrypt,Ut.privateDecrypt=y.privateDecrypt;var S=Ui;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 lg=nu();const dg=wu(lg);function na(a){const n=dg.createHash("sha256").update(a).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function fu(a,n){if(!n||n.length===0)return null;const o=na(a);let s=0,m=0;for(const g of n)m+=g.weight;const f=m>0?o*m/100:o;for(const g of n)if(s+=g.weight,f<s)return g.value;return n[n.length-1].value}function x0(a,n){var m,f,g;const o=n,s=((m=o.user)==null?void 0:m.key)||((f=o.organization)==null?void 0:f.key)||o.user_id||o.id||((g=o.user)==null?void 0:g.email)||o.email;if(!a||typeof a!="object"||!s||!("strategy"in a))return null;switch(a.strategy){case"percentage":{if(!("percentage"in a)||!("salt"in a))return null;const{percentage:y,salt:S}=a;return typeof y!="number"||y<0||y>100?null:na(`${s}.${S}`)<y?!0:null}case"variant":{if(!("variants"in a)||!("salt"in a))return null;const{salt:y,variants:S}=a;return!Array.isArray(S)||S.length===0?null:fu(`${s}.${y}`,S)}default:return null}}function au(a,n){var m,f,g;if(!(a.targeting_rules||[]).every(y=>{var S;if(y.type==="segment"){const B=(S=a.segmentsById)==null?void 0:S[y.segment_id];return B?Th(B,n):!1}else return Rh(y,n)}))return null;if(a.rollout){if(a.rollout.strategy==="percentage")return x0(a.rollout,n)&&(m=a.value)!=null?m:null;{const y=x0(a.rollout,n);return(f=y!=null?y:a.value)!=null?f:null}}return(g=a.value)!=null?g:null}let on={getItem:a=>typeof localStorage!="undefined"?localStorage.getItem(a):null,setItem:(a,n)=>{typeof localStorage!="undefined"&&localStorage.setItem(a,n)}};function cg(a){on=a}function hu(a){return`flagmint_${a}_flags`}function su(a){return`flagmint_${a}_context`}function ou(a,n){try{const o=on.getItem(hu(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}}function uu(a,n){try{on.setItem(hu(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}}function lu(a){try{const n=on.getItem(su(a));return n?JSON.parse(n):null}catch(n){return null}}function du(a,n){try{on.setItem(su(a),JSON.stringify(n))}catch(o){}}const vg=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:lu,loadCachedFlags:ou,saveCachedContext:du,saveCachedFlags:uu,setCacheStorage:cg},Symbol.toStringTag,{value:"Module"})),pg=24*60*60*1e3;function Cn(a){const n=a||(typeof process!="undefined"?process.env.NEXT_PUBLIC_NODE_ENV||process.env.NODE_ENV:"production");switch(n==null?void 0:n.toLowerCase()){case"production":return{rest:"https://api.flagmint.com/evaluator/evaluate",ws:"wss://api.flagmint.com/ws/sdk"};case"staging":return{rest:"https://staging-api.flagmint.com/evaluator/evaluate",ws:"wss://staging-api.flagmint.com/ws/sdk"};case"development":default:return{rest:"https://api.flagmint.com/evaluator/evaluate",ws:"wss://api.flagmint.com/ws/sdk"}}}const mg=Cn().rest,gg=Cn().ws;class bg{constructor(n){var o,s,m,f,g,y,S,B;if(this.flags={},this.refreshIntervalId=null,this.rawFlags={},this.isInitialized=!1,this.subscribers=new Set,this.apiKey=n.apiKey,this.enableOfflineCache=(o=n.enableOfflineCache)!=null?o:!0,this.persistContext=(s=n.persistContext)!=null?s:!1,this.cacheTTL=pg,this.onError=n.onError,this.restEndpoint=(m=Cn(n.env).rest)!=null?m:mg,this.wsEndpoint=(f=Cn(n.env).ws)!=null?f:gg,this.cacheAdapter=(g=n.cacheAdapter)!=null?g:{loadFlags:ou,saveFlags:uu,loadContext:lu,saveContext:du},this.context=n.context||{},this.rawFlags=(y=n.rawFlags)!=null?y:{},this.previewMode=n.previewMode||!1,this.deferInitialization=(S=n.deferInitialization)!=null?S:!1,this.env=n.env,this.enableFlagmint=(B=n.enableFlagmint)!=null?B:!0,qt.setup({debugLog:n.debugLog}),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=()=>{},this.isInitialized=!0;return}else this.previewMode&&!this.rawFlags&&qt.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((w,x)=>{this.resolveReady=w,this.rejectReady=x}),this.enableFlagmint?this.deferInitialization?(qt.log("[FlagClient] Initialization deferred. Call ready() to initialize."),this.initializationOptions=n):this.initialize(n):qt.log("[FlagClient] Flagmint connection disabled. Skipping initialization.")}initialize(n){return Ie(this,null,function*(){var o;if(qt.log("[FlagClient] Initialization started"),this.isInitialized){qt.log("[FlagClient] Already initialized, skipping.");return}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,this.notifySubscribers())}yield this.setupTransport(n),this.isInitialized=!0,this.resolveReady()}catch(s){const m=s instanceof Error?s:new Error(String(s));qt.error("[FlagClient] Initialization failed:",m),Object.keys(this.flags).length>0?qt.warn("[FlagClient] Transport connection failed. Serving cached flags in degraded mode."):qt.warn("[FlagClient] Transport connection failed. No cached flags — getFlag() will return fallback values."),(o=this.onError)==null||o.call(this,m),this.isInitialized=!0,this.resolveReady()}})}setupTransport(n){return Ie(this,null,function*(){var g;qt.log("[FlagClient] setupTransport() started");const o=(g=n.transportMode)!=null?g:"auto",s=()=>Ie(this,null,function*(){qt.log("[FlagClient] Initializing WebSocket transport...");const y=new Ih(this.wsEndpoint,this.apiKey);return yield y.init(),qt.log("[FlagClient] WebSocket transport initialized"),y}),m=()=>{const y=new kh(this.restEndpoint,this.apiKey,this.context,{pollIntervalMs:12e5,maxBackoffMs:6e4,backoffMultiplier:2});return y.onFlagsUpdated(S=>{qt.log("[FlagClient] Flags updated via long polling:",S),this.updateFlags(S)}),y.init(),y};if(o==="websocket")this.transport=yield s();else if(o==="long-polling")this.transport=m();else try{this.transport=yield s()}catch(y){const S=y.code;if(S==="ERR_AUTH"||S==="ERR_RATE_LIMITED")throw y;qt.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(y=>{qt.log("[FlagClient] Flags updated via transport:",y),this.updateFlags(y)});const f=yield this.transport.fetchFlags(this.context);this.updateFlags(f)})}updateFlags(n){this.flags=n,this.enableOfflineCache&&Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,n)),this.notifySubscribers()}notifySubscribers(){this.subscribers.forEach(n=>{try{n(this.flags)}catch(o){qt.error("[FlagClient] Error in subscriber callback:",o)}})}subscribe(n){return this.subscribers.add(n),n(this.flags),()=>{this.subscribers.delete(n)}}getFlags(){return ni({},this.flags)}getFlag(n,o){var s;return(s=this.flags[n])!=null?s:o}updateContext(n){return Ie(this,null,function*(){var o;if(this.context=ni(ni({},this.context),n),this.initializationOptions&&(this.initializationOptions.context=this.context),this.persistContext&&(yield Promise.resolve(this.cacheAdapter.saveContext(this.apiKey,this.context))),this.transport&&typeof this.transport.fetchFlags=="function")try{const s=yield this.transport.fetchFlags(this.context);qt.log("[FlagClient] Flags updated after context change:",s),this.updateFlags(s)}catch(s){qt.error("[FlagClient] Error updating flags after context change:",s),(o=this.onError)==null||o.call(this,s)}})}destroy(){this.refreshIntervalId&&clearInterval(this.refreshIntervalId),this.subscribers.clear(),this.transport&&this.transport.destroy()}ready(n=3e3){return Ie(this,null,function*(){qt.log("[FlagClient] 🔍 ready() START"),this.deferInitialization&&!this.isInitialized&&this.initializationOptions&&(qt.log("[FlagClient] 🔍 About to initialize..."),yield this.initialize(this.initializationOptions),qt.log("[FlagClient] 🔍 Initialize complete")),Object.keys(this.flags).length===0&&(yield this.waitForFlags(n)),yield this.readyPromise})}evaluateLocally(n,o){const s={};for(const m in n){const f=au(n[m],o);f!==null&&(s[m]=f)}return s}waitForFlags(n){return new Promise(o=>{let s=!1,m;const f=setTimeout(()=>{s||(s=!0,m&&m(),o())},n);m=this.subscribe(g=>{!s&&Object.keys(g).length>0?(s=!0,clearTimeout(f),m&&m(),o()):qt.log("[FlagClient] 📥 Not resolving:",{resolved:s,flagsLength:Object.keys(g).length})}),qt.log("[FlagClient] 🔍 Subscribe callback registered")})}}function cu(a){return`flagmint_${a}_flags`}function vu(a){return`flagmint_${a}_context`}let Rr=null;function yg(a){Rr=a}function wg(a,n){return Ie(this,null,function*(){if(!Rr)throw new Error("Async storage not set");try{const o=yield Rr.getItem(cu(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}})}function Mg(a,n){return Ie(this,null,function*(){if(!Rr)throw new Error("Async storage not set");try{yield Rr.setItem(cu(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}})}function xg(a){return Ie(this,null,function*(){if(!Rr)throw new Error("Async storage not set");try{const n=yield Rr.getItem(vu(a));return n?JSON.parse(n):null}catch(n){return null}})}function _g(a,n){return Ie(this,null,function*(){if(!Rr)throw new Error("Async storage not set");try{yield Rr.setItem(vu(a),JSON.stringify(n))}catch(o){}})}const Sg=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:xg,loadCachedFlags:wg,saveCachedContext:_g,saveCachedFlags:Mg,setAsyncCacheStorage:yg},Symbol.toStringTag,{value:"Module"}));typeof globalThis.Buffer=="undefined"&&(globalThis.Buffer=br.Buffer);exports.FlagClient=bg;exports.LongPollingTransport=kh;exports.WebSocketTransport=Ih;exports.asyncCache=Sg;exports.evaluateFlagValue=au;exports.evaluateRollout=x0;exports.hashToPercentage=na;exports.isInSegment=Th;exports.pickVariant=fu;exports.syncCache=vg;
|
|
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 lg=nu();const dg=wu(lg);function na(a){const n=dg.createHash("sha256").update(a).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function fu(a,n){if(!n||n.length===0)return null;const o=na(a);let s=0,m=0;for(const g of n)m+=g.weight;const f=m>0?o*m/100:o;for(const g of n)if(s+=g.weight,f<s)return g.value;return n[n.length-1].value}function x0(a,n){var m,f,g;const o=n,s=((m=o.user)==null?void 0:m.key)||((f=o.organization)==null?void 0:f.key)||o.user_id||o.id||((g=o.user)==null?void 0:g.email)||o.email;if(!a||typeof a!="object"||!s||!("strategy"in a))return null;switch(a.strategy){case"percentage":{if(!("percentage"in a)||!("salt"in a))return null;const{percentage:y,salt:S}=a;return typeof y!="number"||y<0||y>100?null:na(`${s}.${S}`)<y?!0:null}case"variant":{if(!("variants"in a)||!("salt"in a))return null;const{salt:y,variants:S}=a;return!Array.isArray(S)||S.length===0?null:fu(`${s}.${y}`,S)}default:return null}}function au(a,n){var m,f,g;if(!(a.targeting_rules||[]).every(y=>{var S;if(y.type==="segment"){const B=(S=a.segmentsById)==null?void 0:S[y.segment_id];return B?Th(B,n):!1}else return Rh(y,n)}))return null;if(a.rollout){if(a.rollout.strategy==="percentage")return x0(a.rollout,n)&&(m=a.value)!=null?m:null;{const y=x0(a.rollout,n);return(f=y!=null?y:a.value)!=null?f:null}}return(g=a.value)!=null?g:null}let on={getItem:a=>typeof localStorage!="undefined"?localStorage.getItem(a):null,setItem:(a,n)=>{typeof localStorage!="undefined"&&localStorage.setItem(a,n)}};function cg(a){on=a}function hu(a){return`flagmint_${a}_flags`}function su(a){return`flagmint_${a}_context`}function ou(a,n){try{const o=on.getItem(hu(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}}function uu(a,n){try{on.setItem(hu(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}}function lu(a){try{const n=on.getItem(su(a));return n?JSON.parse(n):null}catch(n){return null}}function du(a,n){try{on.setItem(su(a),JSON.stringify(n))}catch(o){}}const vg=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:lu,loadCachedFlags:ou,saveCachedContext:du,saveCachedFlags:uu,setCacheStorage:cg},Symbol.toStringTag,{value:"Module"})),pg=24*60*60*1e3;function Cn(a){const n=a||(typeof process!="undefined"?process.env.NEXT_PUBLIC_NODE_ENV||process.env.NODE_ENV:"production");switch(n==null?void 0:n.toLowerCase()){case"production":return{rest:"https://api.flagmint.com/evaluator/evaluate",ws:"wss://api.flagmint.com/ws/sdk"};case"staging":return{rest:"https://staging-api.flagmint.com/evaluator/evaluate",ws:"wss://staging-api.flagmint.com/ws/sdk"};case"development":default:return{rest:"https://api.flagmint.com/evaluator/evaluate",ws:"wss://api.flagmint.com/ws/sdk"}}}const mg=Cn().rest,gg=Cn().ws;class bg{constructor(n){var o,s,m,f,g,y,S,B;if(this.flags={},this.refreshIntervalId=null,this.rawFlags={},this.isInitialized=!1,this.subscribers=new Set,this.apiKey=n.apiKey,this.enableOfflineCache=(o=n.enableOfflineCache)!=null?o:!0,this.persistContext=(s=n.persistContext)!=null?s:!1,this.cacheTTL=pg,this.onError=n.onError,this.restEndpoint=(m=Cn(n.env).rest)!=null?m:mg,this.wsEndpoint=(f=Cn(n.env).ws)!=null?f:gg,this.cacheAdapter=(g=n.cacheAdapter)!=null?g:{loadFlags:ou,saveFlags:uu,loadContext:lu,saveContext:du},this.context=n.context||{},this.rawFlags=(y=n.rawFlags)!=null?y:{},this.previewMode=n.previewMode||!1,this.deferInitialization=(S=n.deferInitialization)!=null?S:!1,this.env=n.env,this.enableFlagmint=(B=n.enableFlagmint)!=null?B:!0,qt.setup({debugLog:n.debugLog}),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=()=>{},this.isInitialized=!0;return}else this.previewMode&&!this.rawFlags&&qt.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((w,x)=>{this.resolveReady=w,this.rejectReady=x}),this.enableFlagmint?this.deferInitialization?(qt.log("[FlagClient] Initialization deferred. Call ready() to initialize."),this.initializationOptions=n):this.initialize(n):qt.log("[FlagClient] Flagmint connection disabled. Skipping initialization.")}initialize(n){return Ie(this,null,function*(){var o;if(qt.log("[FlagClient] Initialization started"),this.isInitialized){qt.log("[FlagClient] Already initialized, skipping.");return}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,this.notifySubscribers())}yield this.setupTransport(n),this.isInitialized=!0,this.resolveReady()}catch(s){const m=s instanceof Error?s:new Error(String(s));qt.error("[FlagClient] Initialization failed:",m),Object.keys(this.flags).length>0?qt.warn("[FlagClient] Transport connection failed. Serving cached flags in degraded mode."):qt.warn("[FlagClient] Transport connection failed. No cached flags — getFlag() will return fallback values."),(o=this.onError)==null||o.call(this,m),this.isInitialized=!0,this.resolveReady()}})}setupTransport(n){return Ie(this,null,function*(){var f;qt.log("[FlagClient] setupTransport() started");const o=(f=n.transportMode)!=null?f:"auto",s=()=>Ie(this,null,function*(){qt.log("[FlagClient] Initializing WebSocket transport...");const g=new Ih(this.wsEndpoint,this.apiKey);return yield g.init(),qt.log("[FlagClient] WebSocket transport initialized"),g}),m=()=>{const g=new kh(this.restEndpoint,this.apiKey,this.context,{pollIntervalMs:12e5,maxBackoffMs:6e4,backoffMultiplier:2});return g.onFlagsUpdated(y=>{qt.log("[FlagClient] Flags updated via long polling:",y),this.updateFlags(y)}),g.init(),g};if(o==="websocket")this.transport=yield s();else if(o==="long-polling")this.transport=m();else try{this.transport=yield s()}catch(g){const y=g.code;if(y==="ERR_AUTH"||y==="ERR_RATE_LIMITED")throw g;qt.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(g=>{qt.log("[FlagClient] Flags updated via transport:",g),this.updateFlags(g)})})}updateFlags(n){this.flags=n,this.enableOfflineCache&&Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,n)),this.notifySubscribers()}notifySubscribers(){this.subscribers.forEach(n=>{try{n(this.flags)}catch(o){qt.error("[FlagClient] Error in subscriber callback:",o)}})}subscribe(n){return this.subscribers.add(n),n(this.flags),()=>{this.subscribers.delete(n)}}getFlags(){return ni({},this.flags)}getFlag(n,o){var s;return(s=this.flags[n])!=null?s:o}updateContext(n){return Ie(this,null,function*(){var o;if(this.context=ni(ni({},this.context),n),this.initializationOptions&&(this.initializationOptions.context=this.context),this.persistContext&&(yield Promise.resolve(this.cacheAdapter.saveContext(this.apiKey,this.context))),this.transport&&typeof this.transport.fetchFlags=="function")try{const s=yield this.transport.fetchFlags(this.context);qt.log("[FlagClient] Flags updated after context change:",s),this.updateFlags(s)}catch(s){qt.error("[FlagClient] Error updating flags after context change:",s),(o=this.onError)==null||o.call(this,s)}})}destroy(){this.refreshIntervalId&&clearInterval(this.refreshIntervalId),this.subscribers.clear(),this.transport&&this.transport.destroy()}ready(n=3e3){return Ie(this,null,function*(){qt.log("[FlagClient] 🔍 ready() START"),this.deferInitialization&&!this.isInitialized&&this.initializationOptions&&(qt.log("[FlagClient] 🔍 About to initialize..."),yield this.initialize(this.initializationOptions),qt.log("[FlagClient] 🔍 Initialize complete")),Object.keys(this.flags).length===0&&(yield this.waitForFlags(n)),yield this.readyPromise})}evaluateLocally(n,o){const s={};for(const m in n){const f=au(n[m],o);f!==null&&(s[m]=f)}return s}waitForFlags(n){return new Promise(o=>{let s=!1,m;const f=setTimeout(()=>{s||(s=!0,m&&m(),o())},n);m=this.subscribe(g=>{!s&&Object.keys(g).length>0?(s=!0,clearTimeout(f),m&&m(),o()):qt.log("[FlagClient] 📥 Not resolving:",{resolved:s,flagsLength:Object.keys(g).length})}),qt.log("[FlagClient] 🔍 Subscribe callback registered")})}}function cu(a){return`flagmint_${a}_flags`}function vu(a){return`flagmint_${a}_context`}let Rr=null;function yg(a){Rr=a}function wg(a,n){return Ie(this,null,function*(){if(!Rr)throw new Error("Async storage not set");try{const o=yield Rr.getItem(cu(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}})}function Mg(a,n){return Ie(this,null,function*(){if(!Rr)throw new Error("Async storage not set");try{yield Rr.setItem(cu(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}})}function xg(a){return Ie(this,null,function*(){if(!Rr)throw new Error("Async storage not set");try{const n=yield Rr.getItem(vu(a));return n?JSON.parse(n):null}catch(n){return null}})}function _g(a,n){return Ie(this,null,function*(){if(!Rr)throw new Error("Async storage not set");try{yield Rr.setItem(vu(a),JSON.stringify(n))}catch(o){}})}const Sg=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:xg,loadCachedFlags:wg,saveCachedContext:_g,saveCachedFlags:Mg,setAsyncCacheStorage:yg},Symbol.toStringTag,{value:"Module"}));typeof globalThis.Buffer=="undefined"&&(globalThis.Buffer=br.Buffer);exports.FlagClient=bg;exports.LongPollingTransport=kh;exports.WebSocketTransport=Ih;exports.asyncCache=Sg;exports.evaluateFlagValue=au;exports.evaluateRollout=x0;exports.hashToPercentage=na;exports.isInSegment=Th;exports.pickVariant=fu;exports.syncCache=vg;
|
package/dist/flagmint.es.js
CHANGED
|
@@ -20365,23 +20365,23 @@ class Ag {
|
|
|
20365
20365
|
*/
|
|
20366
20366
|
setupTransport(n) {
|
|
20367
20367
|
return Ie(this, null, function* () {
|
|
20368
|
-
var
|
|
20368
|
+
var f;
|
|
20369
20369
|
qt.log("[FlagClient] setupTransport() started");
|
|
20370
|
-
const o = (
|
|
20370
|
+
const o = (f = n.transportMode) != null ? f : "auto", s = () => Ie(this, null, function* () {
|
|
20371
20371
|
qt.log("[FlagClient] Initializing WebSocket transport...");
|
|
20372
|
-
const
|
|
20373
|
-
return yield
|
|
20372
|
+
const g = new ku(this.wsEndpoint, this.apiKey);
|
|
20373
|
+
return yield g.init(), qt.log("[FlagClient] WebSocket transport initialized"), g;
|
|
20374
20374
|
}), m = () => {
|
|
20375
|
-
const
|
|
20375
|
+
const g = new Eu(this.restEndpoint, this.apiKey, this.context, {
|
|
20376
20376
|
pollIntervalMs: 12e5,
|
|
20377
20377
|
maxBackoffMs: 6e4,
|
|
20378
20378
|
// 1min max backoff
|
|
20379
20379
|
backoffMultiplier: 2
|
|
20380
20380
|
// Double each time
|
|
20381
20381
|
});
|
|
20382
|
-
return
|
|
20383
|
-
qt.log("[FlagClient] Flags updated via long polling:",
|
|
20384
|
-
}),
|
|
20382
|
+
return g.onFlagsUpdated((y) => {
|
|
20383
|
+
qt.log("[FlagClient] Flags updated via long polling:", y), this.updateFlags(y);
|
|
20384
|
+
}), g.init(), g;
|
|
20385
20385
|
};
|
|
20386
20386
|
if (o === "websocket")
|
|
20387
20387
|
this.transport = yield s();
|
|
@@ -20390,17 +20390,15 @@ class Ag {
|
|
|
20390
20390
|
else
|
|
20391
20391
|
try {
|
|
20392
20392
|
this.transport = yield s();
|
|
20393
|
-
} catch (
|
|
20394
|
-
const
|
|
20395
|
-
if (
|
|
20396
|
-
throw
|
|
20393
|
+
} catch (g) {
|
|
20394
|
+
const y = g.code;
|
|
20395
|
+
if (y === "ERR_AUTH" || y === "ERR_RATE_LIMITED")
|
|
20396
|
+
throw g;
|
|
20397
20397
|
qt.warn("[FlagClient] WebSocket failed, falling back to long polling"), this.transport = m();
|
|
20398
20398
|
}
|
|
20399
|
-
typeof this.transport.onFlagsUpdated == "function" && this.transport.onFlagsUpdated((
|
|
20400
|
-
qt.log("[FlagClient] Flags updated via transport:",
|
|
20399
|
+
typeof this.transport.onFlagsUpdated == "function" && this.transport.onFlagsUpdated((g) => {
|
|
20400
|
+
qt.log("[FlagClient] Flags updated via transport:", g), this.updateFlags(g);
|
|
20401
20401
|
});
|
|
20402
|
-
const f = yield this.transport.fetchFlags(this.context);
|
|
20403
|
-
this.updateFlags(f);
|
|
20404
20402
|
});
|
|
20405
20403
|
}
|
|
20406
20404
|
/**
|
package/dist/flagmint.umd.js
CHANGED
|
@@ -15,4 +15,4 @@ Use Chrome, Firefox or Internet Explorer 11`)}var il=Kt.Buffer,mn=Ct.crypto||Ct.
|
|
|
15
15
|
`)},Z0}var Io;function wm(){return Io||(Io=1,function(a){var n=a;n.der=Eo(),n.pem=ym()}(K0)),K0}var Ro;function ln(){return Ro||(Ro=1,function(a){var n=a;n.bignum=dm,n.define=cm().define,n.base=un(),n.constants=Mo(),n.decoders=bm(),n.encoders=wm()}(F0)),F0}var hr=ln(),To=hr.define("Time",function(){this.choice({utcTime:this.utctime(),generalTime:this.gentime()})}),Mm=hr.define("AttributeTypeValue",function(){this.seq().obj(this.key("type").objid(),this.key("value").any())}),W0=hr.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional(),this.key("curve").objid().optional())}),xm=hr.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(W0),this.key("subjectPublicKey").bitstr())}),_m=hr.define("RelativeDistinguishedName",function(){this.setof(Mm)}),Sm=hr.define("RDNSequence",function(){this.seqof(_m)}),Co=hr.define("Name",function(){this.choice({rdnSequence:this.use(Sm)})}),Am=hr.define("Validity",function(){this.seq().obj(this.key("notBefore").use(To),this.key("notAfter").use(To))}),Bm=hr.define("Extension",function(){this.seq().obj(this.key("extnID").objid(),this.key("critical").bool().def(!1),this.key("extnValue").octstr())}),Em=hr.define("TBSCertificate",function(){this.seq().obj(this.key("version").explicit(0).int().optional(),this.key("serialNumber").int(),this.key("signature").use(W0),this.key("issuer").use(Co),this.key("validity").use(Am),this.key("subject").use(Co),this.key("subjectPublicKeyInfo").use(xm),this.key("issuerUniqueID").implicit(1).bitstr().optional(),this.key("subjectUniqueID").implicit(2).bitstr().optional(),this.key("extensions").explicit(3).seqof(Bm).optional())}),km=hr.define("X509Certificate",function(){this.seq().obj(this.key("tbsCertificate").use(Em),this.key("signatureAlgorithm").use(W0),this.key("signatureValue").bitstr())}),Im=km,sr=ln();ar.certificate=Im;var Rm=sr.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())});ar.RSAPrivateKey=Rm;var Tm=sr.define("RSAPublicKey",function(){this.seq().obj(this.key("modulus").int(),this.key("publicExponent").int())});ar.RSAPublicKey=Tm;var Fo=sr.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())}),Cm=sr.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(Fo),this.key("subjectPublicKey").bitstr())});ar.PublicKey=Cm;var Fm=sr.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").use(Fo),this.key("subjectPrivateKey").octstr())});ar.PrivateKey=Fm;var qm=sr.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())});ar.EncryptedPrivateKey=qm;var Pm=sr.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())});ar.DSAPrivateKey=Pm,ar.DSAparam=sr.define("DSAparam",function(){this.int()});var Dm=sr.define("ECParameters",function(){this.choice({namedCurve:this.objid()})}),Nm=sr.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").optional().explicit(0).use(Dm),this.key("publicKey").optional().explicit(1).bitstr())});ar.ECPrivateKey=Nm,ar.signature=sr.define("signature",function(){this.seq().obj(this.key("r").int(),this.key("s").int())});const $m={"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 Lm=/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,Um=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m,Om=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m,zm=Kn,Km=We,cf=Kt.Buffer,Hm=function(a,n){var o=a.toString(),s=o.match(Lm),m;if(s){var g="aes"+s[1],y=cf.from(s[2],"hex"),S=cf.from(s[3].replace(/[\r\n]/g,""),"base64"),B=zm(n,y.slice(0,8),parseInt(s[1],10)).key,w=[],x=Km.createDecipheriv(g,B,y);w.push(x.update(S)),w.push(x.final()),m=cf.concat(w)}else{var f=o.match(Om);m=cf.from(f[2].replace(/[\r\n]/g,""),"base64")}var I=o.match(Um)[1];return{tag:I,data:m}},Ke=ar,Zm=$m,Wm=Hm,Vm=We,Ym=Bn,V0=Kt.Buffer;function Jm(a,n){var o=a.algorithm.decrypt.kde.kdeparams.salt,s=parseInt(a.algorithm.decrypt.kde.kdeparams.iters.toString(),10),m=Zm[a.algorithm.decrypt.cipher.algo.join(".")],f=a.algorithm.decrypt.cipher.iv,g=a.subjectPrivateKey,y=parseInt(m.split("-")[1],10)/8,S=Ym.pbkdf2Sync(n,o,s,y,"sha1"),B=Vm.createDecipheriv(m,S,f),w=[];return w.push(B.update(g)),w.push(B.final()),V0.concat(w)}function qo(a){var n;typeof a=="object"&&!V0.isBuffer(a)&&(n=a.passphrase,a=a.key),typeof a=="string"&&(a=V0.from(a));var o=Wm(a,n),s=o.tag,m=o.data,f,g;switch(s){case"CERTIFICATE":g=Ke.certificate.decode(m,"der").tbsCertificate.subjectPublicKeyInfo;case"PUBLIC KEY":switch(g||(g=Ke.PublicKey.decode(m,"der")),f=g.algorithm.algorithm.join("."),f){case"1.2.840.113549.1.1.1":return Ke.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=Ke.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=Ke.EncryptedPrivateKey.decode(m,"der"),m=Jm(m,n);case"PRIVATE KEY":switch(g=Ke.PrivateKey.decode(m,"der"),f=g.algorithm.algorithm.join("."),f){case"1.2.840.113549.1.1.1":return Ke.RSAPrivateKey.decode(g.subjectPrivateKey,"der");case"1.2.840.10045.2.1":return{curve:g.algorithm.curve,privateKey:Ke.ECPrivateKey.decode(g.subjectPrivateKey,"der").privateKey};case"1.2.840.10040.4.1":return g.algorithm.params.priv_key=Ke.DSAparam.decode(g.subjectPrivateKey,"der"),{type:"dsa",params:g.algorithm.params};default:throw new Error("unknown key id "+f)}case"RSA PUBLIC KEY":return Ke.RSAPublicKey.decode(m,"der");case"RSA PRIVATE KEY":return Ke.RSAPrivateKey.decode(m,"der");case"DSA PRIVATE KEY":return{type:"dsa",params:Ke.DSAPrivateKey.decode(m,"der")};case"EC PRIVATE KEY":return m=Ke.ECPrivateKey.decode(m,"der"),{curve:m.parameters.value,privateKey:m.privateKey};default:throw new Error("unknown key type "+s)}}qo.signature=Ke.signature;var vf=qo;const Po={"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 Do;function Gm(){if(Do)return fn.exports;Do=1;var a=Kt.Buffer,n=Va,o=p0,s=C0().ec,m=v0,f=vf,g=Po,y=1;function S(z,$,lt,H,At){var Bt=f($);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 w(z,Bt,lt)}if(H!=="rsa"&&H!=="ecdsa/rsa")throw new Error("wrong private key type");if($.padding!==void 0&&$.padding!==y)throw new Error("illegal or unsupported padding mode");z=a.concat([At,z]);for(var Ft=Bt.modulus.byteLength(),Et=[0,1];z.length+Et.length+1<Ft;)Et.push(255);Et.push(0);for(var Y=-1;++Y<z.length;)Et.push(z[Y]);var It=o(Et,Bt);return It}function B(z,$){var lt=g[$.curve.join(".")];if(!lt)throw new Error("unknown curve "+$.curve.join("."));var H=new s(lt),At=H.keyFromPrivate($.privateKey),Bt=At.sign(z);return a.from(Bt.toDER())}function w(z,$,lt){for(var H=$.params.priv_key,At=$.params.p,Bt=$.params.q,Ft=$.params.g,Et=new m(0),Y,It=k(z,Bt).mod(Bt),p=!1,t=I(H,Bt,z,lt);p===!1;)Y=U(Bt,t,lt),Et=W(Ft,Y,At,Bt),p=Y.invm(Bt).imul(It.add(H.mul(Et))).mod(Bt),p.cmpn(0)===0&&(p=!1,Et=new m(0));return x(Et,p)}function x(z,$){z=z.toArray(),$=$.toArray(),z[0]&128&&(z=[0].concat(z)),$[0]&128&&($=[0].concat($));var lt=z.length+$.length+4,H=[48,lt,2,z.length];return H=H.concat(z,[2,$.length],$),a.from(H)}function I(z,$,lt,H){if(z=a.from(z.toArray()),z.length<$.byteLength()){var At=a.alloc($.byteLength()-z.length);z=a.concat([At,z])}var Bt=lt.length,Ft=D(lt,$),Et=a.alloc(Bt);Et.fill(1);var Y=a.alloc(Bt);return Y=n(H,Y).update(Et).update(a.from([0])).update(z).update(Ft).digest(),Et=n(H,Y).update(Et).digest(),Y=n(H,Y).update(Et).update(a.from([1])).update(z).update(Ft).digest(),Et=n(H,Y).update(Et).digest(),{k:Y,v:Et}}function k(z,$){var lt=new m(z),H=(z.length<<3)-$.bitLength();return H>0&<.ishrn(H),lt}function D(z,$){z=k(z,$),z=z.mod($);var lt=a.from(z.toArray());if(lt.length<$.byteLength()){var H=a.alloc($.byteLength()-lt.length);lt=a.concat([H,lt])}return lt}function U(z,$,lt){var H,At;do{for(H=a.alloc(0);H.length*8<z.bitLength();)$.v=n(lt,$.k).update($.v).digest(),H=a.concat([H,$.v]);At=k(H,z),$.k=n(lt,$.k).update($.v).update(a.from([0])).digest(),$.v=n(lt,$.k).update($.v).digest()}while(At.cmp(z)!==-1);return At}function W(z,$,lt,H){return z.toRed(m.mont(lt)).redPow($).fromRed().mod(H)}return fn.exports=S,fn.exports.getKey=I,fn.exports.makeKey=U,fn.exports}var Y0,No;function Xm(){if(No)return Y0;No=1;var a=Kt.Buffer,n=v0,o=C0().ec,s=vf,m=Po;function f(B,w,x,I,k){var D=s(x);if(D.type==="ec"){if(I!=="ecdsa"&&I!=="ecdsa/rsa")throw new Error("wrong public key type");return g(B,w,D)}else if(D.type==="dsa"){if(I!=="dsa")throw new Error("wrong public key type");return y(B,w,D)}if(I!=="rsa"&&I!=="ecdsa/rsa")throw new Error("wrong public key type");w=a.concat([k,w]);for(var U=D.modulus.byteLength(),W=[1],z=0;w.length+W.length+2<U;)W.push(255),z+=1;W.push(0);for(var $=-1;++$<w.length;)W.push(w[$]);W=a.from(W);var lt=n.mont(D.modulus);B=new n(B).toRed(lt),B=B.redPow(new n(D.publicExponent)),B=a.from(B.fromRed().toArray());var H=z<8?1:0;for(U=Math.min(B.length,W.length),B.length!==W.length&&(H=1),$=-1;++$<U;)H|=B[$]^W[$];return H===0}function g(B,w,x){var I=m[x.data.algorithm.curve.join(".")];if(!I)throw new Error("unknown curve "+x.data.algorithm.curve.join("."));var k=new o(I),D=x.data.subjectPrivateKey.data;return k.verify(w,B,D)}function y(B,w,x){var I=x.data.p,k=x.data.q,D=x.data.g,U=x.data.pub_key,W=s.signature.decode(B,"der"),z=W.s,$=W.r;S(z,k),S($,k);var lt=n.mont(I),H=z.invm(k),At=D.toRed(lt).redPow(new n(w).mul(H).mod(k)).fromRed().mul(U.toRed(lt).redPow($.mul(H).mod(k)).fromRed()).mod(I).mod(k);return At.cmp($)===0}function S(B,w){if(B.cmpn(0)<=0)throw new Error("invalid sig");if(B.cmp(w)>=0)throw new Error("invalid sig")}return Y0=f,Y0}var J0,$o;function jm(){if($o)return J0;$o=1;var a=Kt.Buffer,n=Wi,o=sv,s=Ht,m=Gm(),f=Xm(),g=Ya;Object.keys(g).forEach(function(x){g[x].id=a.from(g[x].id,"hex"),g[x.toLowerCase()]=g[x]});function y(x){o.Writable.call(this);var I=g[x];if(!I)throw new Error("Unknown message digest");this._hashType=I.hash,this._hash=n(I.hash),this._tag=I.id,this._signType=I.sign}s(y,o.Writable),y.prototype._write=function(I,k,D){this._hash.update(I),D()},y.prototype.update=function(I,k){return this._hash.update(typeof I=="string"?a.from(I,k):I),this},y.prototype.sign=function(I,k){this.end();var D=this._hash.digest(),U=m(D,I,this._hashType,this._signType,this._tag);return k?U.toString(k):U};function S(x){o.Writable.call(this);var I=g[x];if(!I)throw new Error("Unknown message digest");this._hash=n(I.hash),this._tag=I.id,this._signType=I.sign}s(S,o.Writable),S.prototype._write=function(I,k,D){this._hash.update(I),D()},S.prototype.update=function(I,k){return this._hash.update(typeof I=="string"?a.from(I,k):I),this},S.prototype.verify=function(I,k,D){var U=typeof k=="string"?a.from(k,D):k;this.end();var W=this._hash.digest();return f(U,W,I,this._signType,this._tag)};function B(x){return new y(x)}function w(x){return new S(x)}return J0={Sign:B,Verify:w,createSign:B,createVerify:w},J0}var G0={exports:{}};G0.exports,function(a){(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=$e.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 h=0;t[0]==="-"&&(h++,this.negative=1),h<t.length&&(r===16?this._parseHex(t,h,i):(this._parseBase(t,r,h),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 h=0;h<this.length;h++)this.words[h]=0;var d,c,v=0;if(i==="be")for(h=t.length-1,d=0;h>=0;h-=3)c=t[h]|t[h-1]<<8|t[h-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(h=0,d=0;h<t.length;h+=3)c=t[h]|t[h+1]<<8|t[h+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 h=0;h<this.length;h++)this.words[h]=0;var d=0,c=0,v;if(i==="be")for(h=t.length-1;h>=r;h-=2)v=S(t,r,h)<<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(h=u%2===0?r+1:r;h<t.length;h+=2)v=S(t,r,h)<<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 h=0,d=Math.min(p.length,r),c=t;c<d;c++){var v=p.charCodeAt(c)-48;h*=i,v>=49?h+=v-49+10:v>=17?h+=v-17+10:h+=v}return h}f.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var h=0,d=1;d<=67108863;d*=r)h++;h--,d=d/r|0;for(var c=t.length-i,v=c%h,u=Math.min(c,c-v)+i,e=0,l=i;l<u;l+=h)e=B(t,l,l+h,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 w=["","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],I=[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 h=0,d=0,c=0;c<this.length;c++){var v=this.words[c],u=((v<<h|d)&16777215).toString(16);d=v>>>24-h&16777215,h+=2,h>=26&&(h-=26,c--),d!==0||c!==this.length-1?i=w[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=I[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=w[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 h=this.byteLength(),d=i||Math.max(1,h);s(h<=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-h;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 k(p){for(var t=new Array(p.bitLength()),r=0;r<t.length;r++){var i=r/26|0,h=r%26;t[r]=(p.words[i]&1<<h)>>>h}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 h=0;h<i.length;h++)this.words[h]=r.words[h]^i.words[h];if(this!==r)for(;h<r.length;h++)this.words[h]=r.words[h];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 h=0;h<r;h++)this.words[h]=~this.words[h]&67108863;return i>0&&(this.words[h]=~this.words[h]&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,h=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<h:this.words[i]=this.words[i]&~(1<<h),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,h;this.length>t.length?(i=this,h=t):(i=t,h=this);for(var d=0,c=0;c<h.length;c++)r=(i.words[c]|0)+(h.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 h,d;i>0?(h=this,d=t):(h=t,d=this);for(var c=0,v=0;v<d.length;v++)r=(h.words[v]|0)-(d.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;for(;c!==0&&v<h.length;v++)r=(h.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;if(c===0&&v<h.length&&h!==this)for(;v<h.length;v++)this.words[v]=h.words[v];return this.length=Math.max(this.length,v),h!==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 h=p.words[0]|0,d=t.words[0]|0,c=h*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 q=e-C|0;h=p.words[q]|0,d=t.words[C]|0,c=h*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 U=function(t,r,i){var h=t.words,d=r.words,c=i.words,v=0,u,e,l,b=h[0]|0,_=b&8191,C=b>>>13,q=h[1]|0,O=q&8191,R=q>>>13,P=h[2]|0,N=P&8191,K=P>>>13,kt=h[3]|0,Z=kt&8191,J=kt>>>13,Pt=h[4]|0,tt=Pt&8191,vt=Pt>>>13,$t=h[5]|0,et=$t&8191,pt=$t>>>13,Nt=h[6]|0,j=Nt&8191,dt=Nt>>>13,Dt=h[7]|0,Q=Dt&8191,ct=Dt>>>13,zt=h[8]|0,E=zt&8191,M=zt>>>13,A=h[9]|0,T=A&8191,F=A>>>13,V=d[0]|0,L=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,Wt=d[4]|0,ft=Wt&8191,yt=Wt>>>13,Vt=d[5]|0,at=Vt&8191,wt=Vt>>>13,Yt=d[6]|0,ht=Yt&8191,Mt=Yt>>>13,Jt=d[7]|0,st=Jt&8191,xt=Jt>>>13,Gt=d[8]|0,ot=Gt&8191,_t=Gt>>>13,Xt=d[9]|0,ut=Xt&8191,St=Xt>>>13;i.negative=t.negative^r.negative,i.length=19,u=Math.imul(_,L),e=Math.imul(_,X),e=e+Math.imul(C,L)|0,l=Math.imul(C,X);var Lt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,u=Math.imul(O,L),e=Math.imul(O,X),e=e+Math.imul(R,L)|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 Ut=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,u=Math.imul(N,L),e=Math.imul(N,X),e=e+Math.imul(K,L)|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 te=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(te>>>26)|0,te&=67108863,u=Math.imul(Z,L),e=Math.imul(Z,X),e=e+Math.imul(J,L)|0,l=Math.imul(J,X),u=u+Math.imul(N,G)|0,e=e+Math.imul(N,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 ee=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,u=Math.imul(tt,L),e=Math.imul(tt,X),e=e+Math.imul(vt,L)|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(N,it)|0,e=e+Math.imul(N,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 re=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(re>>>26)|0,re&=67108863,u=Math.imul(et,L),e=Math.imul(et,X),e=e+Math.imul(pt,L)|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(N,nt)|0,e=e+Math.imul(N,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 ie=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,u=Math.imul(j,L),e=Math.imul(j,X),e=e+Math.imul(dt,L)|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(N,ft)|0,e=e+Math.imul(N,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 ne=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,u=Math.imul(Q,L),e=Math.imul(Q,X),e=e+Math.imul(ct,L)|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(N,at)|0,e=e+Math.imul(N,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 fe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(fe>>>26)|0,fe&=67108863,u=Math.imul(E,L),e=Math.imul(E,X),e=e+Math.imul(M,L)|0,l=Math.imul(M,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(N,ht)|0,e=e+Math.imul(N,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 ae=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,u=Math.imul(T,L),e=Math.imul(T,X),e=e+Math.imul(F,L)|0,l=Math.imul(F,X),u=u+Math.imul(E,G)|0,e=e+Math.imul(E,rt)|0,e=e+Math.imul(M,G)|0,l=l+Math.imul(M,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(N,st)|0,e=e+Math.imul(N,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 he=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(he>>>26)|0,he&=67108863,u=Math.imul(T,G),e=Math.imul(T,rt),e=e+Math.imul(F,G)|0,l=Math.imul(F,rt),u=u+Math.imul(E,it)|0,e=e+Math.imul(E,gt)|0,e=e+Math.imul(M,it)|0,l=l+Math.imul(M,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(N,ot)|0,e=e+Math.imul(N,_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 se=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(se>>>26)|0,se&=67108863,u=Math.imul(T,it),e=Math.imul(T,gt),e=e+Math.imul(F,it)|0,l=Math.imul(F,gt),u=u+Math.imul(E,nt)|0,e=e+Math.imul(E,bt)|0,e=e+Math.imul(M,nt)|0,l=l+Math.imul(M,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(N,ut)|0,e=e+Math.imul(N,St)|0,e=e+Math.imul(K,ut)|0,l=l+Math.imul(K,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,nt),e=Math.imul(T,bt),e=e+Math.imul(F,nt)|0,l=Math.imul(F,bt),u=u+Math.imul(E,ft)|0,e=e+Math.imul(E,yt)|0,e=e+Math.imul(M,ft)|0,l=l+Math.imul(M,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 ue=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ue>>>26)|0,ue&=67108863,u=Math.imul(T,ft),e=Math.imul(T,yt),e=e+Math.imul(F,ft)|0,l=Math.imul(F,yt),u=u+Math.imul(E,at)|0,e=e+Math.imul(E,wt)|0,e=e+Math.imul(M,at)|0,l=l+Math.imul(M,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 le=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(le>>>26)|0,le&=67108863,u=Math.imul(T,at),e=Math.imul(T,wt),e=e+Math.imul(F,at)|0,l=Math.imul(F,wt),u=u+Math.imul(E,ht)|0,e=e+Math.imul(E,Mt)|0,e=e+Math.imul(M,ht)|0,l=l+Math.imul(M,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 de=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(de>>>26)|0,de&=67108863,u=Math.imul(T,ht),e=Math.imul(T,Mt),e=e+Math.imul(F,ht)|0,l=Math.imul(F,Mt),u=u+Math.imul(E,st)|0,e=e+Math.imul(E,xt)|0,e=e+Math.imul(M,st)|0,l=l+Math.imul(M,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 ce=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ce>>>26)|0,ce&=67108863,u=Math.imul(T,st),e=Math.imul(T,xt),e=e+Math.imul(F,st)|0,l=Math.imul(F,xt),u=u+Math.imul(E,ot)|0,e=e+Math.imul(E,_t)|0,e=e+Math.imul(M,ot)|0,l=l+Math.imul(M,_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 ve=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,u=Math.imul(T,ot),e=Math.imul(T,_t),e=e+Math.imul(F,ot)|0,l=Math.imul(F,_t),u=u+Math.imul(E,ut)|0,e=e+Math.imul(E,St)|0,e=e+Math.imul(M,ut)|0,l=l+Math.imul(M,St)|0;var pe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(pe>>>26)|0,pe&=67108863,u=Math.imul(T,ut),e=Math.imul(T,St),e=e+Math.imul(F,ut)|0,l=Math.imul(F,St);var me=(v+u|0)+((e&8191)<<13)|0;return v=(l+(e>>>13)|0)+(me>>>26)|0,me&=67108863,c[0]=Lt,c[1]=Ut,c[2]=te,c[3]=ee,c[4]=re,c[5]=ie,c[6]=ne,c[7]=fe,c[8]=ae,c[9]=he,c[10]=se,c[11]=oe,c[12]=ue,c[13]=le,c[14]=de,c[15]=ce,c[16]=ve,c[17]=pe,c[18]=me,v!==0&&(c[19]=v,i.length++),i};Math.imul||(U=D);function W(p,t,r){r.negative=t.negative^p.negative,r.length=p.length+t.length;for(var i=0,h=0,d=0;d<r.length-1;d++){var c=h;h=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*_,q=C&67108863;c=c+(C/67108864|0)|0,q=q+v|0,v=q&67108863,c=c+(q>>>26)|0,h+=c>>>26,c&=67108863}r.words[d]=v,i=c,c=h}return i!==0?r.words[d]=i:r.length--,r.strip()}function z(p,t,r){var i=new $;return i.mulp(p,t,r)}f.prototype.mulTo=function(t,r){var i,h=this.length+t.length;return this.length===10&&t.length===10?i=U(this,t,r):h<63?i=D(this,t,r):h<1024?i=W(this,t,r):i=z(this,t,r),i};function $(p,t){this.x=p,this.y=t}$.prototype.makeRBT=function(t){for(var r=new Array(t),i=f.prototype._countBits(t)-1,h=0;h<t;h++)r[h]=this.revBin(h,i,t);return r},$.prototype.revBin=function(t,r,i){if(t===0||t===i-1)return t;for(var h=0,d=0;d<r;d++)h|=(t&1)<<r-d-1,t>>=1;return h},$.prototype.permute=function(t,r,i,h,d,c){for(var v=0;v<c;v++)h[v]=r[t[v]],d[v]=i[t[v]]},$.prototype.transform=function(t,r,i,h,d,c){this.permute(c,t,r,i,h,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,q=0;q<v;q++){var O=i[b+q],R=h[b+q],P=i[b+q+v],N=h[b+q+v],K=_*P-C*N;N=_*N+C*P,P=K,i[b+q]=O+P,h[b+q]=R+N,i[b+q+v]=O-P,h[b+q+v]=R-N,q!==u&&(K=e*_-l*C,C=e*C+l*_,_=K)}},$.prototype.guessLen13b=function(t,r){var i=Math.max(r,t)|1,h=i&1,d=0;for(i=i/2|0;i;i=i>>>1)d++;return 1<<d+1+h},$.prototype.conjugate=function(t,r,i){if(!(i<=1))for(var h=0;h<i/2;h++){var d=t[h];t[h]=t[i-h-1],t[i-h-1]=d,d=r[h],r[h]=-r[i-h-1],r[i-h-1]=-d}},$.prototype.normalize13b=function(t,r){for(var i=0,h=0;h<r/2;h++){var d=Math.round(t[2*h+1]/r)*8192+Math.round(t[2*h]/r)+i;t[h]=d&67108863,d<67108864?i=0:i=d/67108864|0}return t},$.prototype.convert13b=function(t,r,i,h){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<h;++c)i[c]=0;s(d===0),s((d&-8192)===0)},$.prototype.stub=function(t){for(var r=new Array(t),i=0;i<t;i++)r[i]=0;return r},$.prototype.mulp=function(t,r,i){var h=2*this.guessLen13b(t.length,r.length),d=this.makeRBT(h),c=this.stub(h),v=new Array(h),u=new Array(h),e=new Array(h),l=new Array(h),b=new Array(h),_=new Array(h),C=i.words;C.length=h,this.convert13b(t.words,t.length,v,h),this.convert13b(r.words,r.length,l,h),this.transform(v,c,u,e,h,d),this.transform(l,c,b,_,h,d);for(var q=0;q<h;q++){var O=u[q]*b[q]-e[q]*_[q];e[q]=u[q]*_[q]+e[q]*b[q],u[q]=O}return this.conjugate(u,e,h),this.transform(u,e,C,c,h,d),this.conjugate(C,c,h),this.normalize13b(C,h),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 h=(this.words[i]|0)*t,d=(h&67108863)+(r&67108863);r>>=26,r+=h/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=k(t);if(r.length===0)return new f(1);for(var i=this,h=0;h<r.length&&r[h]===0;h++,i=i.sqr());if(++h<r.length)for(var d=i.sqr();h<r.length;h++,d=d.sqr())r[h]!==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,h=67108863>>>26-r<<26-r,d;if(r!==0){var c=0;for(d=0;d<this.length;d++){var v=this.words[d]&h,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 h;r?h=(r-r%26)/26:h=0;var d=t%26,c=Math.min((t-d)/26,this.length),v=67108863^67108863>>>d<<d,u=i;if(h-=c,h=Math.max(0,h),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>=h);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,h=1<<r;if(this.length<=i)return!1;var d=this.words[i];return!!(d&h)},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 h=67108863^67108863>>>r<<r;this.words[this.length-1]&=h}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 h=t.length+i,d;this._expand(h);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,h=this.clone(),d=t,c=d.words[d.length-1]|0,v=this._countBits(c);i=26-v,i!==0&&(d=d.ushln(i),h.iushln(i),c=d.words[d.length-1]|0);var u=h.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=h.clone()._ishlnsubmul(d,1,u);b.negative===0&&(h=b,e&&(e.words[u]=1));for(var _=u-1;_>=0;_--){var C=(h.words[d.length+_]|0)*67108864+(h.words[d.length+_-1]|0);for(C=Math.min(C/c|0,67108863),h._ishlnsubmul(d,C,_);h.negative!==0;)C--,h.negative=0,h._ishlnsubmul(d,1,_),h.isZero()||(h.negative^=1);e&&(e.words[_]=C)}return e&&e.strip(),h.strip(),r!=="div"&&i!==0&&h.iushrn(i),{div:e||null,mod:h}},f.prototype.divmod=function(t,r,i){if(s(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var h,d,c;return this.negative!==0&&t.negative===0?(c=this.neg().divmod(t,r),r!=="mod"&&(h=c.div.neg()),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.iadd(t)),{div:h,mod:d}):this.negative===0&&t.negative!==0?(c=this.divmod(t.neg(),r),r!=="mod"&&(h=c.div.neg()),{div:h,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,h=t.ushrn(1),d=t.andln(1),c=i.cmp(h);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,h=this.length-1;h>=0;h--)i=(r*i+(this.words[h]|0))%t;return i},f.prototype.idivn=function(t){s(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var h=(this.words[i]|0)+r*67108864;this.words[i]=h/t|0,r=h%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 h=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;)(h.isOdd()||d.isOdd())&&(h.iadd(e),d.isub(l)),h.iushrn(1),d.iushrn(1);for(var C=0,q=1;!(i.words[0]&q)&&C<26;++C,q<<=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),h.isub(c),d.isub(v)):(i.isub(r),c.isub(h),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 h=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;)h.isOdd()&&h.iadd(c),h.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),h.isub(d)):(i.isub(r),d.isub(h))}var b;return r.cmpn(1)===0?b=h: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 h=0;r.isEven()&&i.isEven();h++)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(h)},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,h=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=h,this;for(var d=h,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 h=this.words[0]|0;i=h===t?0:h<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 h=this.words[i]|0,d=t.words[i]|0;if(h!==d){h<d?r=-1:h>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 h=i<this.n?-1:r.ucmp(this.p);return h===0?(r.words[0]=0,r.length=1):h>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,h=Math.min(t.length,9),d=0;d<h;d++)r.words[d]=t.words[d];if(r.length=h,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 h=t.words[i]|0;r+=h*977,t.words[i]=r&67108863,r=h*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 Ft(){H.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}m(Ft,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 h=(t.words[i]|0)*19+r,d=h&67108863;h>>>=26,t.words[i]=d,r=h}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 Ft;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 h=this.m.subn(1),d=0;!h.isZero()&&h.andln(1)===0;)d++,h.iushrn(1);s(!h.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,h),b=this.pow(t,h.addn(1).iushrn(1)),_=this.pow(t,h),C=d;_.cmp(c)!==0;){for(var q=_,O=0;q.cmp(c)!==0;O++)q=q.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,h=new Array(1<<i);h[0]=new f(1).toRed(this),h[1]=t;for(var d=2;d<h.length;d++)h[d]=this.mul(h[d-1],t);var c=h[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!==h[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,h[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 It(t)};function It(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(It,Y),It.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},It.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},It.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),h=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(h).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)},It.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var i=t.mul(r),h=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(h).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)},It.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(a,Ct)}(G0);var Qm=G0.exports,X0,Lo;function t2(){if(Lo)return X0;Lo=1;var a=C0(),n=Qm;X0=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 a.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 X0}var Uo={},e2=Wi,j0=Kt.Buffer,Oo=function(a,n){for(var o=j0.alloc(0),s=0,m;o.length<n;)m=r2(s++),o=j0.concat([o,e2("sha1").update(a).update(m).digest()]);return o.slice(0,n)};function r2(a){var n=j0.allocUnsafe(4);return n.writeUInt32BE(a,0),n}var zo=function(n,o){for(var s=n.length,m=-1;++m<s;)n[m]^=o[m];return n},Q0={exports:{}};Q0.exports,function(a){(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=$e.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 h=0;t[0]==="-"&&(h++,this.negative=1),h<t.length&&(r===16?this._parseHex(t,h,i):(this._parseBase(t,r,h),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 h=0;h<this.length;h++)this.words[h]=0;var d,c,v=0;if(i==="be")for(h=t.length-1,d=0;h>=0;h-=3)c=t[h]|t[h-1]<<8|t[h-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(h=0,d=0;h<t.length;h+=3)c=t[h]|t[h+1]<<8|t[h+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 h=0;h<this.length;h++)this.words[h]=0;var d=0,c=0,v;if(i==="be")for(h=t.length-1;h>=r;h-=2)v=S(t,r,h)<<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(h=u%2===0?r+1:r;h<t.length;h+=2)v=S(t,r,h)<<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 h=0,d=Math.min(p.length,r),c=t;c<d;c++){var v=p.charCodeAt(c)-48;h*=i,v>=49?h+=v-49+10:v>=17?h+=v-17+10:h+=v}return h}f.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var h=0,d=1;d<=67108863;d*=r)h++;h--,d=d/r|0;for(var c=t.length-i,v=c%h,u=Math.min(c,c-v)+i,e=0,l=i;l<u;l+=h)e=B(t,l,l+h,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 w=["","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],I=[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 h=0,d=0,c=0;c<this.length;c++){var v=this.words[c],u=((v<<h|d)&16777215).toString(16);d=v>>>24-h&16777215,h+=2,h>=26&&(h-=26,c--),d!==0||c!==this.length-1?i=w[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=I[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=w[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 h=this.byteLength(),d=i||Math.max(1,h);s(h<=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-h;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 k(p){for(var t=new Array(p.bitLength()),r=0;r<t.length;r++){var i=r/26|0,h=r%26;t[r]=(p.words[i]&1<<h)>>>h}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 h=0;h<i.length;h++)this.words[h]=r.words[h]^i.words[h];if(this!==r)for(;h<r.length;h++)this.words[h]=r.words[h];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 h=0;h<r;h++)this.words[h]=~this.words[h]&67108863;return i>0&&(this.words[h]=~this.words[h]&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,h=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<h:this.words[i]=this.words[i]&~(1<<h),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,h;this.length>t.length?(i=this,h=t):(i=t,h=this);for(var d=0,c=0;c<h.length;c++)r=(i.words[c]|0)+(h.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 h,d;i>0?(h=this,d=t):(h=t,d=this);for(var c=0,v=0;v<d.length;v++)r=(h.words[v]|0)-(d.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;for(;c!==0&&v<h.length;v++)r=(h.words[v]|0)+c,c=r>>26,this.words[v]=r&67108863;if(c===0&&v<h.length&&h!==this)for(;v<h.length;v++)this.words[v]=h.words[v];return this.length=Math.max(this.length,v),h!==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 h=p.words[0]|0,d=t.words[0]|0,c=h*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 q=e-C|0;h=p.words[q]|0,d=t.words[C]|0,c=h*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 U=function(t,r,i){var h=t.words,d=r.words,c=i.words,v=0,u,e,l,b=h[0]|0,_=b&8191,C=b>>>13,q=h[1]|0,O=q&8191,R=q>>>13,P=h[2]|0,N=P&8191,K=P>>>13,kt=h[3]|0,Z=kt&8191,J=kt>>>13,Pt=h[4]|0,tt=Pt&8191,vt=Pt>>>13,$t=h[5]|0,et=$t&8191,pt=$t>>>13,Nt=h[6]|0,j=Nt&8191,dt=Nt>>>13,Dt=h[7]|0,Q=Dt&8191,ct=Dt>>>13,zt=h[8]|0,E=zt&8191,M=zt>>>13,A=h[9]|0,T=A&8191,F=A>>>13,V=d[0]|0,L=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,Wt=d[4]|0,ft=Wt&8191,yt=Wt>>>13,Vt=d[5]|0,at=Vt&8191,wt=Vt>>>13,Yt=d[6]|0,ht=Yt&8191,Mt=Yt>>>13,Jt=d[7]|0,st=Jt&8191,xt=Jt>>>13,Gt=d[8]|0,ot=Gt&8191,_t=Gt>>>13,Xt=d[9]|0,ut=Xt&8191,St=Xt>>>13;i.negative=t.negative^r.negative,i.length=19,u=Math.imul(_,L),e=Math.imul(_,X),e=e+Math.imul(C,L)|0,l=Math.imul(C,X);var Lt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,u=Math.imul(O,L),e=Math.imul(O,X),e=e+Math.imul(R,L)|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 Ut=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,u=Math.imul(N,L),e=Math.imul(N,X),e=e+Math.imul(K,L)|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 te=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(te>>>26)|0,te&=67108863,u=Math.imul(Z,L),e=Math.imul(Z,X),e=e+Math.imul(J,L)|0,l=Math.imul(J,X),u=u+Math.imul(N,G)|0,e=e+Math.imul(N,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 ee=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ee>>>26)|0,ee&=67108863,u=Math.imul(tt,L),e=Math.imul(tt,X),e=e+Math.imul(vt,L)|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(N,it)|0,e=e+Math.imul(N,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 re=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(re>>>26)|0,re&=67108863,u=Math.imul(et,L),e=Math.imul(et,X),e=e+Math.imul(pt,L)|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(N,nt)|0,e=e+Math.imul(N,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 ie=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ie>>>26)|0,ie&=67108863,u=Math.imul(j,L),e=Math.imul(j,X),e=e+Math.imul(dt,L)|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(N,ft)|0,e=e+Math.imul(N,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 ne=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ne>>>26)|0,ne&=67108863,u=Math.imul(Q,L),e=Math.imul(Q,X),e=e+Math.imul(ct,L)|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(N,at)|0,e=e+Math.imul(N,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 fe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(fe>>>26)|0,fe&=67108863,u=Math.imul(E,L),e=Math.imul(E,X),e=e+Math.imul(M,L)|0,l=Math.imul(M,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(N,ht)|0,e=e+Math.imul(N,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 ae=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ae>>>26)|0,ae&=67108863,u=Math.imul(T,L),e=Math.imul(T,X),e=e+Math.imul(F,L)|0,l=Math.imul(F,X),u=u+Math.imul(E,G)|0,e=e+Math.imul(E,rt)|0,e=e+Math.imul(M,G)|0,l=l+Math.imul(M,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(N,st)|0,e=e+Math.imul(N,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 he=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(he>>>26)|0,he&=67108863,u=Math.imul(T,G),e=Math.imul(T,rt),e=e+Math.imul(F,G)|0,l=Math.imul(F,rt),u=u+Math.imul(E,it)|0,e=e+Math.imul(E,gt)|0,e=e+Math.imul(M,it)|0,l=l+Math.imul(M,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(N,ot)|0,e=e+Math.imul(N,_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 se=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(se>>>26)|0,se&=67108863,u=Math.imul(T,it),e=Math.imul(T,gt),e=e+Math.imul(F,it)|0,l=Math.imul(F,gt),u=u+Math.imul(E,nt)|0,e=e+Math.imul(E,bt)|0,e=e+Math.imul(M,nt)|0,l=l+Math.imul(M,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(N,ut)|0,e=e+Math.imul(N,St)|0,e=e+Math.imul(K,ut)|0,l=l+Math.imul(K,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,nt),e=Math.imul(T,bt),e=e+Math.imul(F,nt)|0,l=Math.imul(F,bt),u=u+Math.imul(E,ft)|0,e=e+Math.imul(E,yt)|0,e=e+Math.imul(M,ft)|0,l=l+Math.imul(M,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 ue=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ue>>>26)|0,ue&=67108863,u=Math.imul(T,ft),e=Math.imul(T,yt),e=e+Math.imul(F,ft)|0,l=Math.imul(F,yt),u=u+Math.imul(E,at)|0,e=e+Math.imul(E,wt)|0,e=e+Math.imul(M,at)|0,l=l+Math.imul(M,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 le=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(le>>>26)|0,le&=67108863,u=Math.imul(T,at),e=Math.imul(T,wt),e=e+Math.imul(F,at)|0,l=Math.imul(F,wt),u=u+Math.imul(E,ht)|0,e=e+Math.imul(E,Mt)|0,e=e+Math.imul(M,ht)|0,l=l+Math.imul(M,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 de=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(de>>>26)|0,de&=67108863,u=Math.imul(T,ht),e=Math.imul(T,Mt),e=e+Math.imul(F,ht)|0,l=Math.imul(F,Mt),u=u+Math.imul(E,st)|0,e=e+Math.imul(E,xt)|0,e=e+Math.imul(M,st)|0,l=l+Math.imul(M,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 ce=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ce>>>26)|0,ce&=67108863,u=Math.imul(T,st),e=Math.imul(T,xt),e=e+Math.imul(F,st)|0,l=Math.imul(F,xt),u=u+Math.imul(E,ot)|0,e=e+Math.imul(E,_t)|0,e=e+Math.imul(M,ot)|0,l=l+Math.imul(M,_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 ve=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,u=Math.imul(T,ot),e=Math.imul(T,_t),e=e+Math.imul(F,ot)|0,l=Math.imul(F,_t),u=u+Math.imul(E,ut)|0,e=e+Math.imul(E,St)|0,e=e+Math.imul(M,ut)|0,l=l+Math.imul(M,St)|0;var pe=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(pe>>>26)|0,pe&=67108863,u=Math.imul(T,ut),e=Math.imul(T,St),e=e+Math.imul(F,ut)|0,l=Math.imul(F,St);var me=(v+u|0)+((e&8191)<<13)|0;return v=(l+(e>>>13)|0)+(me>>>26)|0,me&=67108863,c[0]=Lt,c[1]=Ut,c[2]=te,c[3]=ee,c[4]=re,c[5]=ie,c[6]=ne,c[7]=fe,c[8]=ae,c[9]=he,c[10]=se,c[11]=oe,c[12]=ue,c[13]=le,c[14]=de,c[15]=ce,c[16]=ve,c[17]=pe,c[18]=me,v!==0&&(c[19]=v,i.length++),i};Math.imul||(U=D);function W(p,t,r){r.negative=t.negative^p.negative,r.length=p.length+t.length;for(var i=0,h=0,d=0;d<r.length-1;d++){var c=h;h=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*_,q=C&67108863;c=c+(C/67108864|0)|0,q=q+v|0,v=q&67108863,c=c+(q>>>26)|0,h+=c>>>26,c&=67108863}r.words[d]=v,i=c,c=h}return i!==0?r.words[d]=i:r.length--,r.strip()}function z(p,t,r){var i=new $;return i.mulp(p,t,r)}f.prototype.mulTo=function(t,r){var i,h=this.length+t.length;return this.length===10&&t.length===10?i=U(this,t,r):h<63?i=D(this,t,r):h<1024?i=W(this,t,r):i=z(this,t,r),i};function $(p,t){this.x=p,this.y=t}$.prototype.makeRBT=function(t){for(var r=new Array(t),i=f.prototype._countBits(t)-1,h=0;h<t;h++)r[h]=this.revBin(h,i,t);return r},$.prototype.revBin=function(t,r,i){if(t===0||t===i-1)return t;for(var h=0,d=0;d<r;d++)h|=(t&1)<<r-d-1,t>>=1;return h},$.prototype.permute=function(t,r,i,h,d,c){for(var v=0;v<c;v++)h[v]=r[t[v]],d[v]=i[t[v]]},$.prototype.transform=function(t,r,i,h,d,c){this.permute(c,t,r,i,h,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,q=0;q<v;q++){var O=i[b+q],R=h[b+q],P=i[b+q+v],N=h[b+q+v],K=_*P-C*N;N=_*N+C*P,P=K,i[b+q]=O+P,h[b+q]=R+N,i[b+q+v]=O-P,h[b+q+v]=R-N,q!==u&&(K=e*_-l*C,C=e*C+l*_,_=K)}},$.prototype.guessLen13b=function(t,r){var i=Math.max(r,t)|1,h=i&1,d=0;for(i=i/2|0;i;i=i>>>1)d++;return 1<<d+1+h},$.prototype.conjugate=function(t,r,i){if(!(i<=1))for(var h=0;h<i/2;h++){var d=t[h];t[h]=t[i-h-1],t[i-h-1]=d,d=r[h],r[h]=-r[i-h-1],r[i-h-1]=-d}},$.prototype.normalize13b=function(t,r){for(var i=0,h=0;h<r/2;h++){var d=Math.round(t[2*h+1]/r)*8192+Math.round(t[2*h]/r)+i;t[h]=d&67108863,d<67108864?i=0:i=d/67108864|0}return t},$.prototype.convert13b=function(t,r,i,h){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<h;++c)i[c]=0;s(d===0),s((d&-8192)===0)},$.prototype.stub=function(t){for(var r=new Array(t),i=0;i<t;i++)r[i]=0;return r},$.prototype.mulp=function(t,r,i){var h=2*this.guessLen13b(t.length,r.length),d=this.makeRBT(h),c=this.stub(h),v=new Array(h),u=new Array(h),e=new Array(h),l=new Array(h),b=new Array(h),_=new Array(h),C=i.words;C.length=h,this.convert13b(t.words,t.length,v,h),this.convert13b(r.words,r.length,l,h),this.transform(v,c,u,e,h,d),this.transform(l,c,b,_,h,d);for(var q=0;q<h;q++){var O=u[q]*b[q]-e[q]*_[q];e[q]=u[q]*_[q]+e[q]*b[q],u[q]=O}return this.conjugate(u,e,h),this.transform(u,e,C,c,h,d),this.conjugate(C,c,h),this.normalize13b(C,h),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 h=(this.words[i]|0)*t,d=(h&67108863)+(r&67108863);r>>=26,r+=h/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=k(t);if(r.length===0)return new f(1);for(var i=this,h=0;h<r.length&&r[h]===0;h++,i=i.sqr());if(++h<r.length)for(var d=i.sqr();h<r.length;h++,d=d.sqr())r[h]!==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,h=67108863>>>26-r<<26-r,d;if(r!==0){var c=0;for(d=0;d<this.length;d++){var v=this.words[d]&h,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 h;r?h=(r-r%26)/26:h=0;var d=t%26,c=Math.min((t-d)/26,this.length),v=67108863^67108863>>>d<<d,u=i;if(h-=c,h=Math.max(0,h),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>=h);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,h=1<<r;if(this.length<=i)return!1;var d=this.words[i];return!!(d&h)},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 h=67108863^67108863>>>r<<r;this.words[this.length-1]&=h}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 h=t.length+i,d;this._expand(h);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,h=this.clone(),d=t,c=d.words[d.length-1]|0,v=this._countBits(c);i=26-v,i!==0&&(d=d.ushln(i),h.iushln(i),c=d.words[d.length-1]|0);var u=h.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=h.clone()._ishlnsubmul(d,1,u);b.negative===0&&(h=b,e&&(e.words[u]=1));for(var _=u-1;_>=0;_--){var C=(h.words[d.length+_]|0)*67108864+(h.words[d.length+_-1]|0);for(C=Math.min(C/c|0,67108863),h._ishlnsubmul(d,C,_);h.negative!==0;)C--,h.negative=0,h._ishlnsubmul(d,1,_),h.isZero()||(h.negative^=1);e&&(e.words[_]=C)}return e&&e.strip(),h.strip(),r!=="div"&&i!==0&&h.iushrn(i),{div:e||null,mod:h}},f.prototype.divmod=function(t,r,i){if(s(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var h,d,c;return this.negative!==0&&t.negative===0?(c=this.neg().divmod(t,r),r!=="mod"&&(h=c.div.neg()),r!=="div"&&(d=c.mod.neg(),i&&d.negative!==0&&d.iadd(t)),{div:h,mod:d}):this.negative===0&&t.negative!==0?(c=this.divmod(t.neg(),r),r!=="mod"&&(h=c.div.neg()),{div:h,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,h=t.ushrn(1),d=t.andln(1),c=i.cmp(h);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,h=this.length-1;h>=0;h--)i=(r*i+(this.words[h]|0))%t;return i},f.prototype.idivn=function(t){s(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var h=(this.words[i]|0)+r*67108864;this.words[i]=h/t|0,r=h%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 h=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;)(h.isOdd()||d.isOdd())&&(h.iadd(e),d.isub(l)),h.iushrn(1),d.iushrn(1);for(var C=0,q=1;!(i.words[0]&q)&&C<26;++C,q<<=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),h.isub(c),d.isub(v)):(i.isub(r),c.isub(h),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 h=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;)h.isOdd()&&h.iadd(c),h.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),h.isub(d)):(i.isub(r),d.isub(h))}var b;return r.cmpn(1)===0?b=h: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 h=0;r.isEven()&&i.isEven();h++)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(h)},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,h=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=h,this;for(var d=h,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 h=this.words[0]|0;i=h===t?0:h<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 h=this.words[i]|0,d=t.words[i]|0;if(h!==d){h<d?r=-1:h>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 h=i<this.n?-1:r.ucmp(this.p);return h===0?(r.words[0]=0,r.length=1):h>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,h=Math.min(t.length,9),d=0;d<h;d++)r.words[d]=t.words[d];if(r.length=h,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 h=t.words[i]|0;r+=h*977,t.words[i]=r&67108863,r=h*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 Ft(){H.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}m(Ft,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 h=(t.words[i]|0)*19+r,d=h&67108863;h>>>=26,t.words[i]=d,r=h}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 Ft;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 h=this.m.subn(1),d=0;!h.isZero()&&h.andln(1)===0;)d++,h.iushrn(1);s(!h.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,h),b=this.pow(t,h.addn(1).iushrn(1)),_=this.pow(t,h),C=d;_.cmp(c)!==0;){for(var q=_,O=0;q.cmp(c)!==0;O++)q=q.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,h=new Array(1<<i);h[0]=new f(1).toRed(this),h[1]=t;for(var d=2;d<h.length;d++)h[d]=this.mul(h[d-1],t);var c=h[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!==h[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,h[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 It(t)};function It(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(It,Y),It.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},It.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},It.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),h=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(h).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)},It.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var i=t.mul(r),h=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),d=i.isub(h).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)},It.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(a,Ct)}(Q0);var ta=Q0.exports,Ko=ta,i2=Kt.Buffer;function n2(a,n){return i2.from(a.toRed(Ko.mont(n.modulus)).redPow(new Ko(n.publicExponent)).fromRed().toArray())}var Ho=n2,f2=vf,ea=di,a2=Wi,Zo=Oo,Wo=zo,ra=ta,h2=Ho,s2=p0,or=Kt.Buffer,o2=function(n,o,s){var m;n.padding?m=n.padding:s?m=1:m=4;var f=f2(n),g;if(m===4)g=u2(f,o);else if(m===1)g=l2(f,o,s);else if(m===3){if(g=new ra(o),g.cmp(f.modulus)>=0)throw new Error("data too long for modulus")}else throw new Error("unknown padding");return s?s2(g,f):h2(g,f)};function u2(a,n){var o=a.modulus.byteLength(),s=n.length,m=a2("sha1").update(or.alloc(0)).digest(),f=m.length,g=2*f;if(s>o-g-2)throw new Error("message too long");var y=or.alloc(o-s-g-2),S=o-f-1,B=ea(f),w=Wo(or.concat([m,y,or.alloc(1,1),n],S),Zo(B,S)),x=Wo(B,Zo(w,f));return new ra(or.concat([or.alloc(1),x,w],o))}function l2(a,n,o){var s=n.length,m=a.modulus.byteLength();if(s>m-11)throw new Error("message too long");var f;return o?f=or.alloc(m-s-3,255):f=d2(m-s-3),new ra(or.concat([or.from([0,o?1:2]),f,or.alloc(1),n],m))}function d2(a){for(var n=or.allocUnsafe(a),o=0,s=ea(a*2),m=0,f;o<a;)m===s.length&&(s=ea(a*2),m=0),f=s[m++],f&&(n[o++]=f);return n}var c2=vf,Vo=Oo,Yo=zo,Jo=ta,v2=p0,p2=Wi,m2=Ho,dn=Kt.Buffer,g2=function(n,o,s){var m;n.padding?m=n.padding:s?m=1:m=4;var f=c2(n),g=f.modulus.byteLength();if(o.length>g||new Jo(o).cmp(f.modulus)>=0)throw new Error("decryption error");var y;s?y=m2(new Jo(o),f):y=v2(o,f);var S=dn.alloc(g-y.length);if(y=dn.concat([S,y],g),m===4)return b2(f,y);if(m===1)return y2(f,y,s);if(m===3)return y;throw new Error("unknown padding")};function b2(a,n){var o=a.modulus.byteLength(),s=p2("sha1").update(dn.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=Yo(f,Vo(g,m)),S=Yo(g,Vo(y,o-m-1));if(w2(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 y2(a,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 w2(a,n){a=dn.from(a),n=dn.from(n);var o=0,s=a.length;a.length!==n.length&&(o++,s=Math.min(a.length,n.length));for(var m=-1;++m<s;)o+=a[m]^n[m];return o}(function(a){a.publicEncrypt=o2,a.privateDecrypt=g2,a.privateEncrypt=function(o,s){return a.publicEncrypt(o,s,!0)},a.publicDecrypt=function(o,s){return a.privateDecrypt(o,s,!0)}})(Uo);var cn={};function Go(){throw new Error(`secure random number generation not supported by this browser
|
|
16
16
|
use chrome, FireFox or Internet Explorer 11`)}var Xo=Kt,jo=di,Qo=Xo.Buffer,tu=Xo.kMaxLength,ia=Ct.crypto||Ct.msCrypto,eu=Math.pow(2,32)-1;function ru(a,n){if(typeof a!="number"||a!==a)throw new TypeError("offset must be a number");if(a>eu||a<0)throw new TypeError("offset must be a uint32");if(a>tu||a>n)throw new RangeError("offset out of range")}function iu(a,n,o){if(typeof a!="number"||a!==a)throw new TypeError("size must be a number");if(a>eu||a<0)throw new TypeError("size must be a uint32");if(a+n>o||a>tu)throw new RangeError("buffer too small")}ia&&ia.getRandomValues||!we.browser?(cn.randomFill=M2,cn.randomFillSync=x2):(cn.randomFill=Go,cn.randomFillSync=Go);function M2(a,n,o,s){if(!Qo.isBuffer(a)&&!(a instanceof Ct.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');if(typeof n=="function")s=n,n=0,o=a.length;else if(typeof o=="function")s=o,o=a.length-n;else if(typeof s!="function")throw new TypeError('"cb" argument must be a function');return ru(n,a.length),iu(o,n,a.length),nu(a,n,o,s)}function nu(a,n,o,s){if(we.browser){var m=a.buffer,f=new Uint8Array(m,n,o);if(ia.getRandomValues(f),s){we.nextTick(function(){s(null,a)});return}return a}if(s){jo(o,function(y,S){if(y)return s(y);S.copy(a,n),s(null,a)});return}var g=jo(o);return g.copy(a,n),a}function x2(a,n,o){if(typeof n=="undefined"&&(n=0),!Qo.isBuffer(a)&&!(a instanceof Ct.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');return ru(n,a.length),o===void 0&&(o=a.length-n),iu(o,n,a.length),nu(a,n,o)}var fu;function au(){if(fu)return Ot;fu=1,Ot.randomBytes=Ot.rng=Ot.pseudoRandomBytes=Ot.prng=di,Ot.createHash=Ot.Hash=Wi,Ot.createHmac=Ot.Hmac=Va;var a=Nd,n=Object.keys(a),o=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(n);Ot.getHashes=function(){return o};var s=Bn;Ot.pbkdf2=s.pbkdf2,Ot.pbkdf2Sync=s.pbkdf2Sync;var m=ir;Ot.Cipher=m.Cipher,Ot.createCipher=m.createCipher,Ot.Cipheriv=m.Cipheriv,Ot.createCipheriv=m.createCipheriv,Ot.Decipher=m.Decipher,Ot.createDecipher=m.createDecipher,Ot.Decipheriv=m.Decipheriv,Ot.createDecipheriv=m.createDecipheriv,Ot.getCiphers=m.getCiphers,Ot.listCiphers=m.listCiphers;var f=D1();Ot.DiffieHellmanGroup=f.DiffieHellmanGroup,Ot.createDiffieHellmanGroup=f.createDiffieHellmanGroup,Ot.getDiffieHellman=f.getDiffieHellman,Ot.createDiffieHellman=f.createDiffieHellman,Ot.DiffieHellman=f.DiffieHellman;var g=jm();Ot.createSign=g.createSign,Ot.Sign=g.Sign,Ot.createVerify=g.createVerify,Ot.Verify=g.Verify,Ot.createECDH=t2();var y=Uo;Ot.publicEncrypt=y.publicEncrypt,Ot.privateEncrypt=y.privateEncrypt,Ot.publicDecrypt=y.publicDecrypt,Ot.privateDecrypt=y.privateDecrypt;var S=cn;return Ot.randomFill=S.randomFill,Ot.randomFillSync=S.randomFillSync,Ot.createCredentials=function(){throw new Error(`sorry, createCredentials is not implemented yet
|
|
17
17
|
we accept pull requests
|
|
18
|
-
https://github.com/browserify/crypto-browserify`)},Ot.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},Ot}var _2=au();const S2=Ie(_2);function na(a){const n=S2.createHash("sha256").update(a).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function hu(a,n){if(!n||n.length===0)return null;const o=na(a);let s=0,m=0;for(const g of n)m+=g.weight;const f=m>0?o*m/100:o;for(const g of n)if(s+=g.weight,f<s)return g.value;return n[n.length-1].value}function fa(a,n){var m,f,g;const o=n,s=((m=o.user)==null?void 0:m.key)||((f=o.organization)==null?void 0:f.key)||o.user_id||o.id||((g=o.user)==null?void 0:g.email)||o.email;if(!a||typeof a!="object"||!s||!("strategy"in a))return null;switch(a.strategy){case"percentage":{if(!("percentage"in a)||!("salt"in a))return null;const{percentage:y,salt:S}=a;return typeof y!="number"||y<0||y>100?null:na(`${s}.${S}`)<y?!0:null}case"variant":{if(!("variants"in a)||!("salt"in a))return null;const{salt:y,variants:S}=a;return!Array.isArray(S)||S.length===0?null:hu(`${s}.${y}`,S)}default:return null}}function su(a,n){var m,f,g;if(!(a.targeting_rules||[]).every(y=>{var S;if(y.type==="segment"){const B=(S=a.segmentsById)==null?void 0:S[y.segment_id];return B?ca(B,n):!1}else return da(y,n)}))return null;if(a.rollout){if(a.rollout.strategy==="percentage")return fa(a.rollout,n)&&(m=a.value)!=null?m:null;{const y=fa(a.rollout,n);return(f=y!=null?y:a.value)!=null?f:null}}return(g=a.value)!=null?g:null}let vn={getItem:a=>typeof localStorage!="undefined"?localStorage.getItem(a):null,setItem:(a,n)=>{typeof localStorage!="undefined"&&localStorage.setItem(a,n)}};function A2(a){vn=a}function ou(a){return`flagmint_${a}_flags`}function uu(a){return`flagmint_${a}_context`}function lu(a,n){try{const o=vn.getItem(ou(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}}function du(a,n){try{vn.setItem(ou(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}}function cu(a){try{const n=vn.getItem(uu(a));return n?JSON.parse(n):null}catch(n){return null}}function vu(a,n){try{vn.setItem(uu(a),JSON.stringify(n))}catch(o){}}const B2=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:cu,loadCachedFlags:lu,saveCachedContext:vu,saveCachedFlags:du,setCacheStorage:A2},Symbol.toStringTag,{value:"Module"})),E2=24*60*60*1e3;function pf(a){const n=a||(typeof process!="undefined"?process.env.NEXT_PUBLIC_NODE_ENV||process.env.NODE_ENV:"production");switch(n==null?void 0:n.toLowerCase()){case"production":return{rest:"https://api.flagmint.com/evaluator/evaluate",ws:"wss://api.flagmint.com/ws/sdk"};case"staging":return{rest:"https://staging-api.flagmint.com/evaluator/evaluate",ws:"wss://staging-api.flagmint.com/ws/sdk"};case"development":default:return{rest:"https://api.flagmint.com/evaluator/evaluate",ws:"wss://api.flagmint.com/ws/sdk"}}}const k2=pf().rest,I2=pf().ws;class R2{constructor(n){var o,s,m,f,g,y,S,B;if(this.flags={},this.refreshIntervalId=null,this.rawFlags={},this.isInitialized=!1,this.subscribers=new Set,this.apiKey=n.apiKey,this.enableOfflineCache=(o=n.enableOfflineCache)!=null?o:!0,this.persistContext=(s=n.persistContext)!=null?s:!1,this.cacheTTL=E2,this.onError=n.onError,this.restEndpoint=(m=pf(n.env).rest)!=null?m:k2,this.wsEndpoint=(f=pf(n.env).ws)!=null?f:I2,this.cacheAdapter=(g=n.cacheAdapter)!=null?g:{loadFlags:lu,saveFlags:du,loadContext:cu,saveContext:vu},this.context=n.context||{},this.rawFlags=(y=n.rawFlags)!=null?y:{},this.previewMode=n.previewMode||!1,this.deferInitialization=(S=n.deferInitialization)!=null?S:!1,this.env=n.env,this.enableFlagmint=(B=n.enableFlagmint)!=null?B:!0,qt.setup({debugLog:n.debugLog}),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=()=>{},this.isInitialized=!0;return}else this.previewMode&&!this.rawFlags&&qt.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((w,x)=>{this.resolveReady=w,this.rejectReady=x}),this.enableFlagmint?this.deferInitialization?(qt.log("[FlagClient] Initialization deferred. Call ready() to initialize."),this.initializationOptions=n):this.initialize(n):qt.log("[FlagClient] Flagmint connection disabled. Skipping initialization.")}initialize(n){return Ne(this,null,function*(){var o;if(qt.log("[FlagClient] Initialization started"),this.isInitialized){qt.log("[FlagClient] Already initialized, skipping.");return}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,this.notifySubscribers())}yield this.setupTransport(n),this.isInitialized=!0,this.resolveReady()}catch(s){const m=s instanceof Error?s:new Error(String(s));qt.error("[FlagClient] Initialization failed:",m),Object.keys(this.flags).length>0?qt.warn("[FlagClient] Transport connection failed. Serving cached flags in degraded mode."):qt.warn("[FlagClient] Transport connection failed. No cached flags — getFlag() will return fallback values."),(o=this.onError)==null||o.call(this,m),this.isInitialized=!0,this.resolveReady()}})}setupTransport(n){return Ne(this,null,function*(){var g;qt.log("[FlagClient] setupTransport() started");const o=(g=n.transportMode)!=null?g:"auto",s=()=>Ne(this,null,function*(){qt.log("[FlagClient] Initializing WebSocket transport...");const y=new la(this.wsEndpoint,this.apiKey);return yield y.init(),qt.log("[FlagClient] WebSocket transport initialized"),y}),m=()=>{const y=new ua(this.restEndpoint,this.apiKey,this.context,{pollIntervalMs:12e5,maxBackoffMs:6e4,backoffMultiplier:2});return y.onFlagsUpdated(S=>{qt.log("[FlagClient] Flags updated via long polling:",S),this.updateFlags(S)}),y.init(),y};if(o==="websocket")this.transport=yield s();else if(o==="long-polling")this.transport=m();else try{this.transport=yield s()}catch(y){const S=y.code;if(S==="ERR_AUTH"||S==="ERR_RATE_LIMITED")throw y;qt.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(y=>{qt.log("[FlagClient] Flags updated via transport:",y),this.updateFlags(y)});const f=yield this.transport.fetchFlags(this.context);this.updateFlags(f)})}updateFlags(n){this.flags=n,this.enableOfflineCache&&Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,n)),this.notifySubscribers()}notifySubscribers(){this.subscribers.forEach(n=>{try{n(this.flags)}catch(o){qt.error("[FlagClient] Error in subscriber callback:",o)}})}subscribe(n){return this.subscribers.add(n),n(this.flags),()=>{this.subscribers.delete(n)}}getFlags(){return Ci({},this.flags)}getFlag(n,o){var s;return(s=this.flags[n])!=null?s:o}updateContext(n){return Ne(this,null,function*(){var o;if(this.context=Ci(Ci({},this.context),n),this.initializationOptions&&(this.initializationOptions.context=this.context),this.persistContext&&(yield Promise.resolve(this.cacheAdapter.saveContext(this.apiKey,this.context))),this.transport&&typeof this.transport.fetchFlags=="function")try{const s=yield this.transport.fetchFlags(this.context);qt.log("[FlagClient] Flags updated after context change:",s),this.updateFlags(s)}catch(s){qt.error("[FlagClient] Error updating flags after context change:",s),(o=this.onError)==null||o.call(this,s)}})}destroy(){this.refreshIntervalId&&clearInterval(this.refreshIntervalId),this.subscribers.clear(),this.transport&&this.transport.destroy()}ready(n=3e3){return Ne(this,null,function*(){qt.log("[FlagClient] 🔍 ready() START"),this.deferInitialization&&!this.isInitialized&&this.initializationOptions&&(qt.log("[FlagClient] 🔍 About to initialize..."),yield this.initialize(this.initializationOptions),qt.log("[FlagClient] 🔍 Initialize complete")),Object.keys(this.flags).length===0&&(yield this.waitForFlags(n)),yield this.readyPromise})}evaluateLocally(n,o){const s={};for(const m in n){const f=su(n[m],o);f!==null&&(s[m]=f)}return s}waitForFlags(n){return new Promise(o=>{let s=!1,m;const f=setTimeout(()=>{s||(s=!0,m&&m(),o())},n);m=this.subscribe(g=>{!s&&Object.keys(g).length>0?(s=!0,clearTimeout(f),m&&m(),o()):qt.log("[FlagClient] 📥 Not resolving:",{resolved:s,flagsLength:Object.keys(g).length})}),qt.log("[FlagClient] 🔍 Subscribe callback registered")})}}function pu(a){return`flagmint_${a}_flags`}function mu(a){return`flagmint_${a}_context`}let qr=null;function T2(a){qr=a}function C2(a,n){return Ne(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{const o=yield qr.getItem(pu(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}})}function F2(a,n){return Ne(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{yield qr.setItem(pu(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}})}function q2(a){return Ne(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{const n=yield qr.getItem(mu(a));return n?JSON.parse(n):null}catch(n){return null}})}function P2(a,n){return Ne(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{yield qr.setItem(mu(a),JSON.stringify(n))}catch(o){}})}const D2=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:q2,loadCachedFlags:C2,saveCachedContext:P2,saveCachedFlags:F2,setAsyncCacheStorage:T2},Symbol.toStringTag,{value:"Module"}));typeof globalThis.Buffer=="undefined"&&(globalThis.Buffer=He.Buffer),Qt.FlagClient=R2,Qt.LongPollingTransport=ua,Qt.WebSocketTransport=la,Qt.asyncCache=D2,Qt.evaluateFlagValue=su,Qt.evaluateRollout=fa,Qt.hashToPercentage=na,Qt.isInSegment=ca,Qt.pickVariant=hu,Qt.syncCache=B2,Object.defineProperty(Qt,Symbol.toStringTag,{value:"Module"})});
|
|
18
|
+
https://github.com/browserify/crypto-browserify`)},Ot.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},Ot}var _2=au();const S2=Ie(_2);function na(a){const n=S2.createHash("sha256").update(a).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function hu(a,n){if(!n||n.length===0)return null;const o=na(a);let s=0,m=0;for(const g of n)m+=g.weight;const f=m>0?o*m/100:o;for(const g of n)if(s+=g.weight,f<s)return g.value;return n[n.length-1].value}function fa(a,n){var m,f,g;const o=n,s=((m=o.user)==null?void 0:m.key)||((f=o.organization)==null?void 0:f.key)||o.user_id||o.id||((g=o.user)==null?void 0:g.email)||o.email;if(!a||typeof a!="object"||!s||!("strategy"in a))return null;switch(a.strategy){case"percentage":{if(!("percentage"in a)||!("salt"in a))return null;const{percentage:y,salt:S}=a;return typeof y!="number"||y<0||y>100?null:na(`${s}.${S}`)<y?!0:null}case"variant":{if(!("variants"in a)||!("salt"in a))return null;const{salt:y,variants:S}=a;return!Array.isArray(S)||S.length===0?null:hu(`${s}.${y}`,S)}default:return null}}function su(a,n){var m,f,g;if(!(a.targeting_rules||[]).every(y=>{var S;if(y.type==="segment"){const B=(S=a.segmentsById)==null?void 0:S[y.segment_id];return B?ca(B,n):!1}else return da(y,n)}))return null;if(a.rollout){if(a.rollout.strategy==="percentage")return fa(a.rollout,n)&&(m=a.value)!=null?m:null;{const y=fa(a.rollout,n);return(f=y!=null?y:a.value)!=null?f:null}}return(g=a.value)!=null?g:null}let vn={getItem:a=>typeof localStorage!="undefined"?localStorage.getItem(a):null,setItem:(a,n)=>{typeof localStorage!="undefined"&&localStorage.setItem(a,n)}};function A2(a){vn=a}function ou(a){return`flagmint_${a}_flags`}function uu(a){return`flagmint_${a}_context`}function lu(a,n){try{const o=vn.getItem(ou(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}}function du(a,n){try{vn.setItem(ou(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}}function cu(a){try{const n=vn.getItem(uu(a));return n?JSON.parse(n):null}catch(n){return null}}function vu(a,n){try{vn.setItem(uu(a),JSON.stringify(n))}catch(o){}}const B2=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:cu,loadCachedFlags:lu,saveCachedContext:vu,saveCachedFlags:du,setCacheStorage:A2},Symbol.toStringTag,{value:"Module"})),E2=24*60*60*1e3;function pf(a){const n=a||(typeof process!="undefined"?process.env.NEXT_PUBLIC_NODE_ENV||process.env.NODE_ENV:"production");switch(n==null?void 0:n.toLowerCase()){case"production":return{rest:"https://api.flagmint.com/evaluator/evaluate",ws:"wss://api.flagmint.com/ws/sdk"};case"staging":return{rest:"https://staging-api.flagmint.com/evaluator/evaluate",ws:"wss://staging-api.flagmint.com/ws/sdk"};case"development":default:return{rest:"https://api.flagmint.com/evaluator/evaluate",ws:"wss://api.flagmint.com/ws/sdk"}}}const k2=pf().rest,I2=pf().ws;class R2{constructor(n){var o,s,m,f,g,y,S,B;if(this.flags={},this.refreshIntervalId=null,this.rawFlags={},this.isInitialized=!1,this.subscribers=new Set,this.apiKey=n.apiKey,this.enableOfflineCache=(o=n.enableOfflineCache)!=null?o:!0,this.persistContext=(s=n.persistContext)!=null?s:!1,this.cacheTTL=E2,this.onError=n.onError,this.restEndpoint=(m=pf(n.env).rest)!=null?m:k2,this.wsEndpoint=(f=pf(n.env).ws)!=null?f:I2,this.cacheAdapter=(g=n.cacheAdapter)!=null?g:{loadFlags:lu,saveFlags:du,loadContext:cu,saveContext:vu},this.context=n.context||{},this.rawFlags=(y=n.rawFlags)!=null?y:{},this.previewMode=n.previewMode||!1,this.deferInitialization=(S=n.deferInitialization)!=null?S:!1,this.env=n.env,this.enableFlagmint=(B=n.enableFlagmint)!=null?B:!0,qt.setup({debugLog:n.debugLog}),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=()=>{},this.isInitialized=!0;return}else this.previewMode&&!this.rawFlags&&qt.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((w,x)=>{this.resolveReady=w,this.rejectReady=x}),this.enableFlagmint?this.deferInitialization?(qt.log("[FlagClient] Initialization deferred. Call ready() to initialize."),this.initializationOptions=n):this.initialize(n):qt.log("[FlagClient] Flagmint connection disabled. Skipping initialization.")}initialize(n){return Ne(this,null,function*(){var o;if(qt.log("[FlagClient] Initialization started"),this.isInitialized){qt.log("[FlagClient] Already initialized, skipping.");return}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,this.notifySubscribers())}yield this.setupTransport(n),this.isInitialized=!0,this.resolveReady()}catch(s){const m=s instanceof Error?s:new Error(String(s));qt.error("[FlagClient] Initialization failed:",m),Object.keys(this.flags).length>0?qt.warn("[FlagClient] Transport connection failed. Serving cached flags in degraded mode."):qt.warn("[FlagClient] Transport connection failed. No cached flags — getFlag() will return fallback values."),(o=this.onError)==null||o.call(this,m),this.isInitialized=!0,this.resolveReady()}})}setupTransport(n){return Ne(this,null,function*(){var f;qt.log("[FlagClient] setupTransport() started");const o=(f=n.transportMode)!=null?f:"auto",s=()=>Ne(this,null,function*(){qt.log("[FlagClient] Initializing WebSocket transport...");const g=new la(this.wsEndpoint,this.apiKey);return yield g.init(),qt.log("[FlagClient] WebSocket transport initialized"),g}),m=()=>{const g=new ua(this.restEndpoint,this.apiKey,this.context,{pollIntervalMs:12e5,maxBackoffMs:6e4,backoffMultiplier:2});return g.onFlagsUpdated(y=>{qt.log("[FlagClient] Flags updated via long polling:",y),this.updateFlags(y)}),g.init(),g};if(o==="websocket")this.transport=yield s();else if(o==="long-polling")this.transport=m();else try{this.transport=yield s()}catch(g){const y=g.code;if(y==="ERR_AUTH"||y==="ERR_RATE_LIMITED")throw g;qt.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(g=>{qt.log("[FlagClient] Flags updated via transport:",g),this.updateFlags(g)})})}updateFlags(n){this.flags=n,this.enableOfflineCache&&Promise.resolve(this.cacheAdapter.saveFlags(this.apiKey,n)),this.notifySubscribers()}notifySubscribers(){this.subscribers.forEach(n=>{try{n(this.flags)}catch(o){qt.error("[FlagClient] Error in subscriber callback:",o)}})}subscribe(n){return this.subscribers.add(n),n(this.flags),()=>{this.subscribers.delete(n)}}getFlags(){return Ci({},this.flags)}getFlag(n,o){var s;return(s=this.flags[n])!=null?s:o}updateContext(n){return Ne(this,null,function*(){var o;if(this.context=Ci(Ci({},this.context),n),this.initializationOptions&&(this.initializationOptions.context=this.context),this.persistContext&&(yield Promise.resolve(this.cacheAdapter.saveContext(this.apiKey,this.context))),this.transport&&typeof this.transport.fetchFlags=="function")try{const s=yield this.transport.fetchFlags(this.context);qt.log("[FlagClient] Flags updated after context change:",s),this.updateFlags(s)}catch(s){qt.error("[FlagClient] Error updating flags after context change:",s),(o=this.onError)==null||o.call(this,s)}})}destroy(){this.refreshIntervalId&&clearInterval(this.refreshIntervalId),this.subscribers.clear(),this.transport&&this.transport.destroy()}ready(n=3e3){return Ne(this,null,function*(){qt.log("[FlagClient] 🔍 ready() START"),this.deferInitialization&&!this.isInitialized&&this.initializationOptions&&(qt.log("[FlagClient] 🔍 About to initialize..."),yield this.initialize(this.initializationOptions),qt.log("[FlagClient] 🔍 Initialize complete")),Object.keys(this.flags).length===0&&(yield this.waitForFlags(n)),yield this.readyPromise})}evaluateLocally(n,o){const s={};for(const m in n){const f=su(n[m],o);f!==null&&(s[m]=f)}return s}waitForFlags(n){return new Promise(o=>{let s=!1,m;const f=setTimeout(()=>{s||(s=!0,m&&m(),o())},n);m=this.subscribe(g=>{!s&&Object.keys(g).length>0?(s=!0,clearTimeout(f),m&&m(),o()):qt.log("[FlagClient] 📥 Not resolving:",{resolved:s,flagsLength:Object.keys(g).length})}),qt.log("[FlagClient] 🔍 Subscribe callback registered")})}}function pu(a){return`flagmint_${a}_flags`}function mu(a){return`flagmint_${a}_context`}let qr=null;function T2(a){qr=a}function C2(a,n){return Ne(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{const o=yield qr.getItem(pu(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}})}function F2(a,n){return Ne(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{yield qr.setItem(pu(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}})}function q2(a){return Ne(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{const n=yield qr.getItem(mu(a));return n?JSON.parse(n):null}catch(n){return null}})}function P2(a,n){return Ne(this,null,function*(){if(!qr)throw new Error("Async storage not set");try{yield qr.setItem(mu(a),JSON.stringify(n))}catch(o){}})}const D2=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:q2,loadCachedFlags:C2,saveCachedContext:P2,saveCachedFlags:F2,setAsyncCacheStorage:T2},Symbol.toStringTag,{value:"Module"}));typeof globalThis.Buffer=="undefined"&&(globalThis.Buffer=He.Buffer),Qt.FlagClient=R2,Qt.LongPollingTransport=ua,Qt.WebSocketTransport=la,Qt.asyncCache=D2,Qt.evaluateFlagValue=su,Qt.evaluateRollout=fa,Qt.hashToPercentage=na,Qt.isInSegment=ca,Qt.pickVariant=hu,Qt.syncCache=B2,Object.defineProperty(Qt,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED