flagmint-js-sdk 1.2.21 → 1.2.22
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/README.md +20 -12
- package/dist/flagmint.cjs.js +1 -1
- package/dist/flagmint.es.js +8 -8
- package/dist/flagmint.umd.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ await client.updateContext({
|
|
|
60
60
|
| `persistContext` | `boolean` | `false` | Persist evaluation context across sessions. | |
|
|
61
61
|
| `cacheAdapter` | `CacheAdapter<C>` | Sync `cacheHelper` | Custom cache implementation (see examples). |
|
|
62
62
|
| `transportMode` | `'auto' \| 'websocket' \| 'long-polling'` | `'auto'` | How to fetch flags: prefer WebSocket, or use long-polling transport. |
|
|
63
|
-
| `onError` | `(error: Error) => void` | — | Callback for transport or initialization errors.
|
|
63
|
+
| `onError` | `(error: Error) => void` | — | Callback for transport or initialization errors. Called when operating in degraded mode with cached flags. |
|
|
64
64
|
| `previewMode` | `boolean` | `false` | Evaluate using `rawFlags` only, bypassing remote fetch. |
|
|
65
65
|
| `rawFlags` | `Record<string, FlagValue>` | — | Local-only flag definitions used when `previewMode: true`. |
|
|
66
66
|
| `deferInitialization` | `boolean` | `false` | If `true`, client initialization is deferred until you call `ready()`. |
|
|
@@ -327,31 +327,39 @@ const client = new FlagClient({
|
|
|
327
327
|
});
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
-
**Important:
|
|
330
|
+
**Important: Offline Fallback & Cache Behavior**
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
- ✅ Cached flags ARE loaded and accessible via `getFlag()`
|
|
334
|
-
- ⚠️ `onError` callback is called with the connection error
|
|
335
|
-
- ❌ `ready()` promise still **rejects** with the error
|
|
332
|
+
The SDK gracefully handles connection failures using cached flags as a fallback:
|
|
336
333
|
|
|
337
|
-
|
|
334
|
+
**When the server is unreachable:**
|
|
335
|
+
|
|
336
|
+
| Scenario | `ready()` Promise | Behavior |
|
|
337
|
+
|----------|-------------------|----------|
|
|
338
|
+
| ✅ Cached flags available | Resolves | Operates in degraded mode with cached flags |
|
|
339
|
+
| ❌ No cached flags | Rejects | Initialization fails |
|
|
340
|
+
| ✅ Connected successfully | Resolves | Normal operation with live updates |
|
|
341
|
+
|
|
342
|
+
**Degraded Mode:** When `ready()` resolves but the connection failed, the `onError` callback is triggered to notify you:
|
|
338
343
|
|
|
339
344
|
```ts
|
|
340
345
|
const client = new FlagClient({
|
|
341
346
|
apiKey: '...',
|
|
342
347
|
enableOfflineCache: true,
|
|
343
348
|
onError: (error) => {
|
|
344
|
-
|
|
349
|
+
// Called when operating in degraded mode with cached flags
|
|
350
|
+
console.warn('⚠️ Degraded mode - using cached flags:', error.message);
|
|
351
|
+
// Optionally report to monitoring service
|
|
345
352
|
}
|
|
346
353
|
});
|
|
347
354
|
|
|
348
355
|
try {
|
|
349
356
|
await client.ready();
|
|
350
|
-
|
|
357
|
+
// ✅ Resolves successfully even if server is down (when cached flags exist)
|
|
358
|
+
console.log('Client ready');
|
|
359
|
+
const feature = client.getFlag('my_feature', false); // Always works
|
|
351
360
|
} catch (error) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const feature = client.getFlag('my_feature', false); // Works!
|
|
361
|
+
// ❌ Only throws if NO cached flags AND server is unreachable
|
|
362
|
+
console.error('Completely offline:', error);
|
|
355
363
|
}
|
|
356
364
|
```
|
|
357
365
|
|
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
|
`)},Gf}var oh;function s2(){return oh||(oh=1,function(a){var n=a;n.der=zo(),n.pem=h2()}(Yf)),Yf}var uh;function sn(){return uh||(uh=1,function(a){var n=a;n.bignum=t2,n.define=e2().define,n.base=zi(),n.constants=Uo(),n.decoders=a2(),n.encoders=s2()}(Lf)),Lf}var nr=sn(),lh=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())}),j0=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(j0),this.key("subjectPublicKey").bitstr())}),l2=nr.define("RelativeDistinguishedName",function(){this.setof(o2)}),d2=nr.define("RDNSequence",function(){this.seqof(l2)}),dh=nr.define("Name",function(){this.choice({rdnSequence:this.use(d2)})}),c2=nr.define("Validity",function(){this.seq().obj(this.key("notBefore").use(lh),this.key("notAfter").use(lh))}),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(j0),this.key("issuer").use(dh),this.key("validity").use(c2),this.key("subject").use(dh),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(j0),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 Ko=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(Ko),this.key("subjectPublicKey").bitstr())});ir.PublicKey=w2;var M2=fr.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").use(Ko),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=Yn,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,M=[],x=T2.createDecipheriv(g,B,y);M.push(x.update(S)),M.push(x.final()),m=gn.concat(M)}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=On,g0=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),M=[];return M.push(B.update(g)),M.push(B.final()),g0.concat(M)}function Ho(a){var n;typeof a=="object"&&!g0.isBuffer(a)&&(n=a.passphrase,a=a.key),typeof a=="string"&&(a=g0.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)}}Ho.signature=Pe.signature;var uf=Ho;const Zo={"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 ch;function $2(){if(ch)return Pi.exports;ch=1;var a=zt.Buffer,n=Qh,o=H0,s=G0().ec,m=K0,f=uf,g=Zo,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 M(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 M(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 Xf,vh;function L2(){if(vh)return Xf;vh=1;var a=zt.Buffer,n=K0,o=G0().ec,s=uf,m=Zo;function f(B,M,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,M,D)}else if(D.type==="dsa"){if(I!=="dsa")throw new Error("wrong public key type");return y(B,M,D)}if(I!=="rsa"&&I!=="ecdsa/rsa")throw new Error("wrong public key type");M=a.concat([k,M]);for(var U=D.modulus.byteLength(),W=[1],z=0;M.length+W.length+2<U;)W.push(255),z+=1;W.push(0);for(var $=-1;++$<M.length;)W.push(M[$]);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,M,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(M,B,D)}function y(B,M,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(M).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,M){if(B.cmpn(0)<=0)throw new Error("invalid sig");if(B.cmp(M)>=0)throw new Error("invalid sig")}return Xf=f,Xf}var jf,ph;function U2(){if(ph)return jf;ph=1;var a=zt.Buffer,n=Qi,o=Dv,s=Gt,m=$2(),f=L2(),g=ts;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 M(x){return new S(x)}return jf={Sign:B,Verify:M,createSign:B,createVerify:M},jf}var 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=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 M=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],x=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],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=M[6-u.length]+u+i:i=u+i}for(d!==0&&(i=d.toString(16)+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var e=x[t],l=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=M[e-_.length]+_+i}for(this.isZero()&&(i="0"+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}s(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&s(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(t,r){return s(typeof g!="undefined"),this.toArrayLike(g,t,r)},f.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},f.prototype.toArrayLike=function(t,r,i){var 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,Dt=h[5]|0,et=Dt&8191,pt=Dt>>>13,Pt=h[6]|0,j=Pt&8191,dt=Pt>>>13,qt=h[7]|0,Q=qt&8191,ct=qt>>>13,Ut=h[8]|0,E=Ut&8191,w=Ut>>>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 Nt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Nt>>>26)|0,Nt&=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 $t=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+($t>>>26)|0,$t&=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(w,L)|0,l=Math.imul(w,X),u=u+Math.imul(Q,G)|0,e=e+Math.imul(Q,rt)|0,e=e+Math.imul(ct,G)|0,l=l+Math.imul(ct,rt)|0,u=u+Math.imul(j,it)|0,e=e+Math.imul(j,gt)|0,e=e+Math.imul(dt,it)|0,l=l+Math.imul(dt,gt)|0,u=u+Math.imul(et,nt)|0,e=e+Math.imul(et,bt)|0,e=e+Math.imul(pt,nt)|0,l=l+Math.imul(pt,bt)|0,u=u+Math.imul(tt,ft)|0,e=e+Math.imul(tt,yt)|0,e=e+Math.imul(vt,ft)|0,l=l+Math.imul(vt,yt)|0,u=u+Math.imul(Z,at)|0,e=e+Math.imul(Z,wt)|0,e=e+Math.imul(J,at)|0,l=l+Math.imul(J,wt)|0,u=u+Math.imul(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(w,G)|0,l=l+Math.imul(w,rt)|0,u=u+Math.imul(Q,it)|0,e=e+Math.imul(Q,gt)|0,e=e+Math.imul(ct,it)|0,l=l+Math.imul(ct,gt)|0,u=u+Math.imul(j,nt)|0,e=e+Math.imul(j,bt)|0,e=e+Math.imul(dt,nt)|0,l=l+Math.imul(dt,bt)|0,u=u+Math.imul(et,ft)|0,e=e+Math.imul(et,yt)|0,e=e+Math.imul(pt,ft)|0,l=l+Math.imul(pt,yt)|0,u=u+Math.imul(tt,at)|0,e=e+Math.imul(tt,wt)|0,e=e+Math.imul(vt,at)|0,l=l+Math.imul(vt,wt)|0,u=u+Math.imul(Z,ht)|0,e=e+Math.imul(Z,Mt)|0,e=e+Math.imul(J,ht)|0,l=l+Math.imul(J,Mt)|0,u=u+Math.imul(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(w,it)|0,l=l+Math.imul(w,gt)|0,u=u+Math.imul(Q,nt)|0,e=e+Math.imul(Q,bt)|0,e=e+Math.imul(ct,nt)|0,l=l+Math.imul(ct,bt)|0,u=u+Math.imul(j,ft)|0,e=e+Math.imul(j,yt)|0,e=e+Math.imul(dt,ft)|0,l=l+Math.imul(dt,yt)|0,u=u+Math.imul(et,at)|0,e=e+Math.imul(et,wt)|0,e=e+Math.imul(pt,at)|0,l=l+Math.imul(pt,wt)|0,u=u+Math.imul(tt,ht)|0,e=e+Math.imul(tt,Mt)|0,e=e+Math.imul(vt,ht)|0,l=l+Math.imul(vt,Mt)|0,u=u+Math.imul(Z,st)|0,e=e+Math.imul(Z,xt)|0,e=e+Math.imul(J,st)|0,l=l+Math.imul(J,xt)|0,u=u+Math.imul(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(w,nt)|0,l=l+Math.imul(w,bt)|0,u=u+Math.imul(Q,ft)|0,e=e+Math.imul(Q,yt)|0,e=e+Math.imul(ct,ft)|0,l=l+Math.imul(ct,yt)|0,u=u+Math.imul(j,at)|0,e=e+Math.imul(j,wt)|0,e=e+Math.imul(dt,at)|0,l=l+Math.imul(dt,wt)|0,u=u+Math.imul(et,ht)|0,e=e+Math.imul(et,Mt)|0,e=e+Math.imul(pt,ht)|0,l=l+Math.imul(pt,Mt)|0,u=u+Math.imul(tt,st)|0,e=e+Math.imul(tt,xt)|0,e=e+Math.imul(vt,st)|0,l=l+Math.imul(vt,xt)|0,u=u+Math.imul(Z,ot)|0,e=e+Math.imul(Z,_t)|0,e=e+Math.imul(J,ot)|0,l=l+Math.imul(J,_t)|0,u=u+Math.imul(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(w,ft)|0,l=l+Math.imul(w,yt)|0,u=u+Math.imul(Q,at)|0,e=e+Math.imul(Q,wt)|0,e=e+Math.imul(ct,at)|0,l=l+Math.imul(ct,wt)|0,u=u+Math.imul(j,ht)|0,e=e+Math.imul(j,Mt)|0,e=e+Math.imul(dt,ht)|0,l=l+Math.imul(dt,Mt)|0,u=u+Math.imul(et,st)|0,e=e+Math.imul(et,xt)|0,e=e+Math.imul(pt,st)|0,l=l+Math.imul(pt,xt)|0,u=u+Math.imul(tt,ot)|0,e=e+Math.imul(tt,_t)|0,e=e+Math.imul(vt,ot)|0,l=l+Math.imul(vt,_t)|0,u=u+Math.imul(Z,ut)|0,e=e+Math.imul(Z,St)|0,e=e+Math.imul(J,ut)|0,l=l+Math.imul(J,St)|0;var 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(w,at)|0,l=l+Math.imul(w,wt)|0,u=u+Math.imul(Q,ht)|0,e=e+Math.imul(Q,Mt)|0,e=e+Math.imul(ct,ht)|0,l=l+Math.imul(ct,Mt)|0,u=u+Math.imul(j,st)|0,e=e+Math.imul(j,xt)|0,e=e+Math.imul(dt,st)|0,l=l+Math.imul(dt,xt)|0,u=u+Math.imul(et,ot)|0,e=e+Math.imul(et,_t)|0,e=e+Math.imul(pt,ot)|0,l=l+Math.imul(pt,_t)|0,u=u+Math.imul(tt,ut)|0,e=e+Math.imul(tt,St)|0,e=e+Math.imul(vt,ut)|0,l=l+Math.imul(vt,St)|0;var 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(w,ht)|0,l=l+Math.imul(w,Mt)|0,u=u+Math.imul(Q,st)|0,e=e+Math.imul(Q,xt)|0,e=e+Math.imul(ct,st)|0,l=l+Math.imul(ct,xt)|0,u=u+Math.imul(j,ot)|0,e=e+Math.imul(j,_t)|0,e=e+Math.imul(dt,ot)|0,l=l+Math.imul(dt,_t)|0,u=u+Math.imul(et,ut)|0,e=e+Math.imul(et,St)|0,e=e+Math.imul(pt,ut)|0,l=l+Math.imul(pt,St)|0;var 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(w,st)|0,l=l+Math.imul(w,xt)|0,u=u+Math.imul(Q,ot)|0,e=e+Math.imul(Q,_t)|0,e=e+Math.imul(ct,ot)|0,l=l+Math.imul(ct,_t)|0,u=u+Math.imul(j,ut)|0,e=e+Math.imul(j,St)|0,e=e+Math.imul(dt,ut)|0,l=l+Math.imul(dt,St)|0;var 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(w,ot)|0,l=l+Math.imul(w,_t)|0,u=u+Math.imul(Q,ut)|0,e=e+Math.imul(Q,St)|0,e=e+Math.imul(ct,ut)|0,l=l+Math.imul(ct,St)|0;var 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(w,ut)|0,l=l+Math.imul(w,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]=Nt,c[1]=$t,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)})(Q0);var O2=Q0.exports,Qf,mh;function z2(){if(mh)return Qf;mh=1;var a=G0(),n=O2;Qf=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 Qf}var Wo={},K2=Qi,b0=zt.Buffer,Vo=function(a,n){for(var o=b0.alloc(0),s=0,m;o.length<n;)m=H2(s++),o=b0.concat([o,K2("sha1").update(a).update(m).digest()]);return o.slice(0,n)};function H2(a){var n=b0.allocUnsafe(4);return n.writeUInt32BE(a,0),n}var Yo=function(n,o){for(var s=n.length,m=-1;++m<s;)n[m]^=o[m];return n},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 M=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],x=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],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=M[6-u.length]+u+i:i=u+i}for(d!==0&&(i=d.toString(16)+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var e=x[t],l=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=M[e-_.length]+_+i}for(this.isZero()&&(i="0"+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}s(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&s(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(t,r){return s(typeof g!="undefined"),this.toArrayLike(g,t,r)},f.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},f.prototype.toArrayLike=function(t,r,i){var 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,Dt=h[5]|0,et=Dt&8191,pt=Dt>>>13,Pt=h[6]|0,j=Pt&8191,dt=Pt>>>13,qt=h[7]|0,Q=qt&8191,ct=qt>>>13,Ut=h[8]|0,E=Ut&8191,w=Ut>>>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 Nt=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+(Nt>>>26)|0,Nt&=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 $t=(v+u|0)+((e&8191)<<13)|0;v=(l+(e>>>13)|0)+($t>>>26)|0,$t&=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(w,L)|0,l=Math.imul(w,X),u=u+Math.imul(Q,G)|0,e=e+Math.imul(Q,rt)|0,e=e+Math.imul(ct,G)|0,l=l+Math.imul(ct,rt)|0,u=u+Math.imul(j,it)|0,e=e+Math.imul(j,gt)|0,e=e+Math.imul(dt,it)|0,l=l+Math.imul(dt,gt)|0,u=u+Math.imul(et,nt)|0,e=e+Math.imul(et,bt)|0,e=e+Math.imul(pt,nt)|0,l=l+Math.imul(pt,bt)|0,u=u+Math.imul(tt,ft)|0,e=e+Math.imul(tt,yt)|0,e=e+Math.imul(vt,ft)|0,l=l+Math.imul(vt,yt)|0,u=u+Math.imul(Z,at)|0,e=e+Math.imul(Z,wt)|0,e=e+Math.imul(J,at)|0,l=l+Math.imul(J,wt)|0,u=u+Math.imul(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(w,G)|0,l=l+Math.imul(w,rt)|0,u=u+Math.imul(Q,it)|0,e=e+Math.imul(Q,gt)|0,e=e+Math.imul(ct,it)|0,l=l+Math.imul(ct,gt)|0,u=u+Math.imul(j,nt)|0,e=e+Math.imul(j,bt)|0,e=e+Math.imul(dt,nt)|0,l=l+Math.imul(dt,bt)|0,u=u+Math.imul(et,ft)|0,e=e+Math.imul(et,yt)|0,e=e+Math.imul(pt,ft)|0,l=l+Math.imul(pt,yt)|0,u=u+Math.imul(tt,at)|0,e=e+Math.imul(tt,wt)|0,e=e+Math.imul(vt,at)|0,l=l+Math.imul(vt,wt)|0,u=u+Math.imul(Z,ht)|0,e=e+Math.imul(Z,Mt)|0,e=e+Math.imul(J,ht)|0,l=l+Math.imul(J,Mt)|0,u=u+Math.imul(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(w,it)|0,l=l+Math.imul(w,gt)|0,u=u+Math.imul(Q,nt)|0,e=e+Math.imul(Q,bt)|0,e=e+Math.imul(ct,nt)|0,l=l+Math.imul(ct,bt)|0,u=u+Math.imul(j,ft)|0,e=e+Math.imul(j,yt)|0,e=e+Math.imul(dt,ft)|0,l=l+Math.imul(dt,yt)|0,u=u+Math.imul(et,at)|0,e=e+Math.imul(et,wt)|0,e=e+Math.imul(pt,at)|0,l=l+Math.imul(pt,wt)|0,u=u+Math.imul(tt,ht)|0,e=e+Math.imul(tt,Mt)|0,e=e+Math.imul(vt,ht)|0,l=l+Math.imul(vt,Mt)|0,u=u+Math.imul(Z,st)|0,e=e+Math.imul(Z,xt)|0,e=e+Math.imul(J,st)|0,l=l+Math.imul(J,xt)|0,u=u+Math.imul(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(w,nt)|0,l=l+Math.imul(w,bt)|0,u=u+Math.imul(Q,ft)|0,e=e+Math.imul(Q,yt)|0,e=e+Math.imul(ct,ft)|0,l=l+Math.imul(ct,yt)|0,u=u+Math.imul(j,at)|0,e=e+Math.imul(j,wt)|0,e=e+Math.imul(dt,at)|0,l=l+Math.imul(dt,wt)|0,u=u+Math.imul(et,ht)|0,e=e+Math.imul(et,Mt)|0,e=e+Math.imul(pt,ht)|0,l=l+Math.imul(pt,Mt)|0,u=u+Math.imul(tt,st)|0,e=e+Math.imul(tt,xt)|0,e=e+Math.imul(vt,st)|0,l=l+Math.imul(vt,xt)|0,u=u+Math.imul(Z,ot)|0,e=e+Math.imul(Z,_t)|0,e=e+Math.imul(J,ot)|0,l=l+Math.imul(J,_t)|0,u=u+Math.imul(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(w,ft)|0,l=l+Math.imul(w,yt)|0,u=u+Math.imul(Q,at)|0,e=e+Math.imul(Q,wt)|0,e=e+Math.imul(ct,at)|0,l=l+Math.imul(ct,wt)|0,u=u+Math.imul(j,ht)|0,e=e+Math.imul(j,Mt)|0,e=e+Math.imul(dt,ht)|0,l=l+Math.imul(dt,Mt)|0,u=u+Math.imul(et,st)|0,e=e+Math.imul(et,xt)|0,e=e+Math.imul(pt,st)|0,l=l+Math.imul(pt,xt)|0,u=u+Math.imul(tt,ot)|0,e=e+Math.imul(tt,_t)|0,e=e+Math.imul(vt,ot)|0,l=l+Math.imul(vt,_t)|0,u=u+Math.imul(Z,ut)|0,e=e+Math.imul(Z,St)|0,e=e+Math.imul(J,ut)|0,l=l+Math.imul(J,St)|0;var 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(w,at)|0,l=l+Math.imul(w,wt)|0,u=u+Math.imul(Q,ht)|0,e=e+Math.imul(Q,Mt)|0,e=e+Math.imul(ct,ht)|0,l=l+Math.imul(ct,Mt)|0,u=u+Math.imul(j,st)|0,e=e+Math.imul(j,xt)|0,e=e+Math.imul(dt,st)|0,l=l+Math.imul(dt,xt)|0,u=u+Math.imul(et,ot)|0,e=e+Math.imul(et,_t)|0,e=e+Math.imul(pt,ot)|0,l=l+Math.imul(pt,_t)|0,u=u+Math.imul(tt,ut)|0,e=e+Math.imul(tt,St)|0,e=e+Math.imul(vt,ut)|0,l=l+Math.imul(vt,St)|0;var 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(w,ht)|0,l=l+Math.imul(w,Mt)|0,u=u+Math.imul(Q,st)|0,e=e+Math.imul(Q,xt)|0,e=e+Math.imul(ct,st)|0,l=l+Math.imul(ct,xt)|0,u=u+Math.imul(j,ot)|0,e=e+Math.imul(j,_t)|0,e=e+Math.imul(dt,ot)|0,l=l+Math.imul(dt,_t)|0,u=u+Math.imul(et,ut)|0,e=e+Math.imul(et,St)|0,e=e+Math.imul(pt,ut)|0,l=l+Math.imul(pt,St)|0;var 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(w,st)|0,l=l+Math.imul(w,xt)|0,u=u+Math.imul(Q,ot)|0,e=e+Math.imul(Q,_t)|0,e=e+Math.imul(ct,ot)|0,l=l+Math.imul(ct,_t)|0,u=u+Math.imul(j,ut)|0,e=e+Math.imul(j,St)|0,e=e+Math.imul(dt,ut)|0,l=l+Math.imul(dt,St)|0;var 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(w,ot)|0,l=l+Math.imul(w,_t)|0,u=u+Math.imul(Q,ut)|0,e=e+Math.imul(Q,St)|0,e=e+Math.imul(ct,ut)|0,l=l+Math.imul(ct,St)|0;var 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(w,ut)|0,l=l+Math.imul(w,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]=Nt,c[1]=$t,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 ea=ta.exports,gh=ea,Z2=zt.Buffer;function W2(a,n){return Z2.from(a.toRed(gh.mont(n.modulus)).redPow(new gh(n.publicExponent)).fromRed().toArray())}var Jo=W2,V2=uf,y0=yi,Y2=Qi,bh=Vo,yh=Yo,ra=ea,J2=Jo,G2=H0,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 ra(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=y0(f),M=yh(Qe.concat([m,y,Qe.alloc(1,1),n],S),bh(B,S)),x=yh(B,bh(M,f));return new ra(Qe.concat([Qe.alloc(1),x,M],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 ra(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=y0(a*2),m=0,f;o<a;)m===s.length&&(s=y0(a*2),m=0),f=s[m++],f&&(n[o++]=f);return n}var eg=uf,wh=Vo,Mh=Yo,xh=ea,rg=H0,ig=Qi,ng=Jo,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 xh(o).cmp(f.modulus)>=0)throw new Error("decryption error");var y;s?y=ng(new xh(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=Mh(f,wh(g,m)),S=Mh(g,wh(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)}})(Wo);var Ui={};function _h(){throw new Error(`secure random number generation not supported by this browser
|
|
16
16
|
use chrome, FireFox or Internet Explorer 11`)}var Go=zt,Sh=yi,Xo=Go.Buffer,jo=Go.kMaxLength,w0=Xt.crypto||Xt.msCrypto,Qo=Math.pow(2,32)-1;function tu(a,n){if(typeof a!="number"||a!==a)throw new TypeError("offset must be a number");if(a>Qo||a<0)throw new TypeError("offset must be a uint32");if(a>jo||a>n)throw new RangeError("offset out of range")}function eu(a,n,o){if(typeof a!="number"||a!==a)throw new TypeError("size must be a number");if(a>Qo||a<0)throw new TypeError("size must be a uint32");if(a+n>o||a>jo)throw new RangeError("buffer too small")}w0&&w0.getRandomValues||!we.browser?(Ui.randomFill=og,Ui.randomFillSync=ug):(Ui.randomFill=_h,Ui.randomFillSync=_h);function og(a,n,o,s){if(!Xo.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 tu(n,a.length),eu(o,n,a.length),ru(a,n,o,s)}function ru(a,n,o,s){if(we.browser){var m=a.buffer,f=new Uint8Array(m,n,o);if(w0.getRandomValues(f),s){we.nextTick(function(){s(null,a)});return}return a}if(s){Sh(o,function(y,S){if(y)return s(y);S.copy(a,n),s(null,a)});return}var g=Sh(o);return g.copy(a,n),a}function ug(a,n,o){if(typeof n=="undefined"&&(n=0),!Xo.isBuffer(a)&&!(a instanceof Xt.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');return tu(n,a.length),o===void 0&&(o=a.length-n),eu(o,n,a.length),ru(a,n,o)}var Ah;function iu(){if(Ah)return Lt;Ah=1,Lt.randomBytes=Lt.rng=Lt.pseudoRandomBytes=Lt.prng=yi,Lt.createHash=Lt.Hash=Qi,Lt.createHmac=Lt.Hmac=Qh;var a=tc,n=Object.keys(a),o=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(n);Lt.getHashes=function(){return o};var s=On;Lt.pbkdf2=s.pbkdf2,Lt.pbkdf2Sync=s.pbkdf2Sync;var m=tr;Lt.Cipher=m.Cipher,Lt.createCipher=m.createCipher,Lt.Cipheriv=m.Cipheriv,Lt.createCipheriv=m.createCipheriv,Lt.Decipher=m.Decipher,Lt.createDecipher=m.createDecipher,Lt.Decipheriv=m.Decipheriv,Lt.createDecipheriv=m.createDecipheriv,Lt.getCiphers=m.getCiphers,Lt.listCiphers=m.listCiphers;var f=uv();Lt.DiffieHellmanGroup=f.DiffieHellmanGroup,Lt.createDiffieHellmanGroup=f.createDiffieHellmanGroup,Lt.getDiffieHellman=f.getDiffieHellman,Lt.createDiffieHellman=f.createDiffieHellman,Lt.DiffieHellman=f.DiffieHellman;var g=U2();Lt.createSign=g.createSign,Lt.Sign=g.Sign,Lt.createVerify=g.createVerify,Lt.Verify=g.Verify,Lt.createECDH=z2();var y=Wo;Lt.publicEncrypt=y.publicEncrypt,Lt.privateEncrypt=y.privateEncrypt,Lt.publicDecrypt=y.publicDecrypt,Lt.privateDecrypt=y.privateDecrypt;var S=Ui;return Lt.randomFill=S.randomFill,Lt.randomFillSync=S.randomFillSync,Lt.createCredentials=function(){throw new Error(`sorry, createCredentials is not implemented yet
|
|
17
17
|
we accept pull requests
|
|
18
|
-
https://github.com/browserify/crypto-browserify`)},Lt.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6},Lt}var lg=iu();const dg=wu(lg);function ia(a){const n=dg.createHash("sha256").update(a).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function nu(a,n){if(!n||n.length===0)return null;const o=ia(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 M0(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:ia(`${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:nu(`${s}.${y}`,S)}default:return null}}function fu(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?Rh(B,n):!1}else return Ih(y,n)}))return null;if(a.rollout){if(a.rollout.strategy==="percentage")return M0(a.rollout,n)&&(m=a.value)!=null?m:null;{const y=M0(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 au(a){return`flagmint_${a}_flags`}function hu(a){return`flagmint_${a}_context`}function su(a,n){try{const o=on.getItem(au(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}}function ou(a,n){try{on.setItem(au(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}}function uu(a){try{const n=on.getItem(hu(a));return n?JSON.parse(n):null}catch(n){return null}}function lu(a,n){try{on.setItem(hu(a),JSON.stringify(n))}catch(o){}}const vg=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:uu,loadCachedFlags:su,saveCachedContext:lu,saveCachedFlags:ou,setCacheStorage:cg},Symbol.toStringTag,{value:"Module"})),pg=24*60*60*1e3;function du(){switch(typeof process!="undefined"?process.env.NEXT_PUBLIC_NODE_ENV||process.env.NODE_ENV:"development"){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:"http://localhost:3000/evaluator/evaluate",ws:"ws://localhost:3000/ws/sdk"}}}const mg=du().rest,gg=du().ws;class bg{constructor(n){var o,s,m,f,g,y,S;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=n.restEndpoint)!=null?m:mg,this.wsEndpoint=(f=n.wsEndpoint)!=null?f:gg,this.cacheAdapter=(g=n.cacheAdapter)!=null?g:{loadFlags:su,saveFlags:ou,loadContext:uu,saveContext:lu},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.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&&Ot.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((B,M)=>{this.resolveReady=B,this.rejectReady=M}),this.deferInitialization?(Ot.log("[FlagClient] Initialization deferred. Call ready() to initialize."),this.initializationOptions=n):this.initialize(n)}initialize(n){return Ie(this,null,function*(){var o;if(Ot.log("[FlagClient] Initialization started with options:",n),this.isInitialized){Ot.log("[FlagClient] Already initialized, skipping.");return}try{if(this.persistContext){const
|
|
18
|
+
https://github.com/browserify/crypto-browserify`)},Lt.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6},Lt}var lg=iu();const dg=wu(lg);function ia(a){const n=dg.createHash("sha256").update(a).digest("hex");return parseInt(n.slice(0,8),16)%1e4/100}function nu(a,n){if(!n||n.length===0)return null;const o=ia(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 M0(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:ia(`${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:nu(`${s}.${y}`,S)}default:return null}}function fu(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?Rh(B,n):!1}else return Ih(y,n)}))return null;if(a.rollout){if(a.rollout.strategy==="percentage")return M0(a.rollout,n)&&(m=a.value)!=null?m:null;{const y=M0(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 au(a){return`flagmint_${a}_flags`}function hu(a){return`flagmint_${a}_context`}function su(a,n){try{const o=on.getItem(au(a));if(!o)return null;const s=JSON.parse(o);return Date.now()-s.ts>n?null:s.data}catch(o){return null}}function ou(a,n){try{on.setItem(au(a),JSON.stringify({ts:Date.now(),data:n}))}catch(o){}}function uu(a){try{const n=on.getItem(hu(a));return n?JSON.parse(n):null}catch(n){return null}}function lu(a,n){try{on.setItem(hu(a),JSON.stringify(n))}catch(o){}}const vg=Object.freeze(Object.defineProperty({__proto__:null,loadCachedContext:uu,loadCachedFlags:su,saveCachedContext:lu,saveCachedFlags:ou,setCacheStorage:cg},Symbol.toStringTag,{value:"Module"})),pg=24*60*60*1e3;function du(){switch(typeof process!="undefined"?process.env.NEXT_PUBLIC_NODE_ENV||process.env.NODE_ENV:"development"){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:"http://localhost:3000/evaluator/evaluate",ws:"ws://localhost:3000/ws/sdk"}}}const mg=du().rest,gg=du().ws;class bg{constructor(n){var o,s,m,f,g,y,S;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=n.restEndpoint)!=null?m:mg,this.wsEndpoint=(f=n.wsEndpoint)!=null?f:gg,this.cacheAdapter=(g=n.cacheAdapter)!=null?g:{loadFlags:su,saveFlags:ou,loadContext:uu,saveContext:lu},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.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&&Ot.error("[FlagClient] No raw flags provided for preview mode. Defaulting to remote fetch.");this.readyPromise=new Promise((B,M)=>{this.resolveReady=B,this.rejectReady=M}),this.deferInitialization?(Ot.log("[FlagClient] Initialization deferred. Call ready() to initialize."),this.initializationOptions=n):this.initialize(n)}initialize(n){return Ie(this,null,function*(){var o,s;if(Ot.log("[FlagClient] Initialization started with options:",n),this.isInitialized){Ot.log("[FlagClient] Already initialized, skipping.");return}try{if(this.persistContext){const m=yield Promise.resolve(this.cacheAdapter.loadContext(this.apiKey));m&&(this.context=m)}if(this.enableOfflineCache){const m=yield Promise.resolve(this.cacheAdapter.loadFlags(this.apiKey,this.cacheTTL));m&&(this.flags=m,this.notifySubscribers())}yield this.setupTransport(n),this.isInitialized=!0,this.resolveReady()}catch(m){const f=m instanceof Error?m:new Error(String(m));Ot.error("[FlagClient] Initialization failed:",f),Object.keys(this.flags).length>0?(Ot.warn("[FlagClient] Transport connection failed. Serving cached flags in degraded mode."),this.isInitialized=!0,this.resolveReady(),(o=this.onError)==null||o.call(this,f)):(Ot.error("[FlagClient] No cached flags available. Initialization failed."),(s=this.onError)==null||s.call(this,f),this.rejectReady(f))}})}setupTransport(n){return Ie(this,null,function*(){var g;Ot.log("[FlagClient] setupTransport() started");const o=(g=n.transportMode)!=null?g:"auto",s=()=>Ie(this,null,function*(){Ot.log("[FlagClient] Initializing WebSocket transport...");const y=new kh(this.wsEndpoint,this.apiKey);return yield y.init(),Ot.log("[FlagClient] WebSocket transport initialized"),y}),m=()=>{const y=new Eh(this.restEndpoint,this.apiKey,this.context,{pollIntervalMs:12e5,maxBackoffMs:6e4,backoffMultiplier:2});return y.onFlagsUpdated(S=>{Ot.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){Ot.warn("[FlagClient] WebSocket failed, falling back to long polling"),this.transport=m()}typeof this.transport.onFlagsUpdated=="function"&&this.transport.onFlagsUpdated(y=>{Ot.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){Ot.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);Ot.log("[FlagClient] Flags updated after context change:",s),this.updateFlags(s)}catch(s){Ot.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*(){Ot.log("[FlagClient] 🔍 ready() START"),this.deferInitialization&&!this.isInitialized&&this.initializationOptions&&(Ot.log("[FlagClient] 🔍 About to initialize..."),yield this.initialize(this.initializationOptions),Ot.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=fu(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()):Ot.log("[FlagClient] 📥 Not resolving:",{resolved:s,flagsLength:Object.keys(g).length})}),Ot.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=Eh;exports.WebSocketTransport=kh;exports.asyncCache=Sg;exports.evaluateFlagValue=fu;exports.evaluateRollout=M0;exports.hashToPercentage=ia;exports.isInSegment=Rh;exports.pickVariant=nu;exports.syncCache=vg;
|
package/dist/flagmint.es.js
CHANGED
|
@@ -20324,28 +20324,28 @@ class Ag {
|
|
|
20324
20324
|
*/
|
|
20325
20325
|
initialize(n) {
|
|
20326
20326
|
return Ie(this, null, function* () {
|
|
20327
|
-
var o;
|
|
20327
|
+
var o, s;
|
|
20328
20328
|
if (Ot.log("[FlagClient] Initialization started with options:", n), this.isInitialized) {
|
|
20329
20329
|
Ot.log("[FlagClient] Already initialized, skipping.");
|
|
20330
20330
|
return;
|
|
20331
20331
|
}
|
|
20332
20332
|
try {
|
|
20333
20333
|
if (this.persistContext) {
|
|
20334
|
-
const
|
|
20334
|
+
const m = yield Promise.resolve(
|
|
20335
20335
|
this.cacheAdapter.loadContext(this.apiKey)
|
|
20336
20336
|
);
|
|
20337
|
-
|
|
20337
|
+
m && (this.context = m);
|
|
20338
20338
|
}
|
|
20339
20339
|
if (this.enableOfflineCache) {
|
|
20340
|
-
const
|
|
20340
|
+
const m = yield Promise.resolve(
|
|
20341
20341
|
this.cacheAdapter.loadFlags(this.apiKey, this.cacheTTL)
|
|
20342
20342
|
);
|
|
20343
|
-
|
|
20343
|
+
m && (this.flags = m, this.notifySubscribers());
|
|
20344
20344
|
}
|
|
20345
20345
|
yield this.setupTransport(n), this.isInitialized = !0, this.resolveReady();
|
|
20346
|
-
} catch (
|
|
20347
|
-
const
|
|
20348
|
-
Ot.error("[FlagClient] Initialization failed:",
|
|
20346
|
+
} catch (m) {
|
|
20347
|
+
const f = m instanceof Error ? m : new Error(String(m));
|
|
20348
|
+
Ot.error("[FlagClient] Initialization failed:", f), Object.keys(this.flags).length > 0 ? (Ot.warn("[FlagClient] Transport connection failed. Serving cached flags in degraded mode."), this.isInitialized = !0, this.resolveReady(), (o = this.onError) == null || o.call(this, f)) : (Ot.error("[FlagClient] No cached flags available. Initialization failed."), (s = this.onError) == null || s.call(this, f), this.rejectReady(f));
|
|
20349
20349
|
}
|
|
20350
20350
|
});
|
|
20351
20351
|
}
|