>>=26,t.words[r]=i,e=n}return 0!==e&&(t.words[t.length++]=e),t},i._prime=function(t){if(y[t])return y[t];var e;if("k256"===t)e=new _;else if("p224"===t)e=new A;else if("p192"===t)e=new M;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new E}return y[t]=e,e},S.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},S.prototype._verify2=function(t,e){r(0==(t.negative|e.negative),"red works only with positives"),r(t.red&&t.red===e.red,"red works only with red numbers")},S.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(u(t,t.umod(this.m)._forceRed(this)),t)},S.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},S.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},S.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},S.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},S.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},S.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},S.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},S.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},S.prototype.isqr=function(t){return this.imul(t,t.clone())},S.prototype.sqr=function(t){return this.mul(t,t)},S.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(r(e%2==1),3===e){var n=this.m.add(new i(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),a=0;!o.isZero()&&0===o.andln(1);)a++,o.iushrn(1);r(!o.isZero());var s=new i(1).toRed(this),f=s.redNeg(),u=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new i(2*h*h).toRed(this);0!==this.pow(h,u).cmp(f);)h.redIAdd(f);for(var c=this.pow(h,o),d=this.pow(t,o.addn(1).iushrn(1)),l=this.pow(t,o),p=a;0!==l.cmp(s);){for(var m=l,b=0;0!==m.cmp(s);b++)m=m.redSqr();r(b=0;n--){for(var u=e.words[n],h=f-1;h>=0;h--){var c=u>>h&1;o!==r[0]&&(o=this.sqr(o)),0!==c||0!==a?(a<<=1,a|=c,(4===++s||0===n&&0===h)&&(o=this.mul(o,r[a]),s=0,a=0)):s=0}f=26}return o},S.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},S.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},i.mont=function(t){return new k(t)},n(k,S),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},k.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},k.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new i(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),a=o;return o.cmp(this.m)>=0?a=o.isub(this.m):o.cmpn(0)<0&&(a=o.iadd(this.m)),a._forceRed(this)},k.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(void 0===t||t,this),t.exports}.call({})}var Rb,xb,Cb,Ib,Db=!1;function Pb(t){var e,r=t.modulus.byteLength();do{e=new Cb(Ib(r))}while(e.cmp(t.modulus)>=0||!e.umod(t.prime1)||!e.umod(t.prime2));return e}function Ob(t,e){var r=function(t){var e=Pb(t);return{blinder:e.toRed(Cb.mont(t.modulus)).redPow(new Cb(t.publicExponent)).fromRed(),unblinder:e.invm(t.modulus)}}(e),n=e.modulus.byteLength(),i=new Cb(t).mul(r.blinder).umod(e.modulus),o=i.toRed(Cb.mont(e.prime1)),a=i.toRed(Cb.mont(e.prime2)),s=e.coefficient,f=e.prime1,u=e.prime2,h=o.redPow(e.exponent1).fromRed(),c=a.redPow(e.exponent2).fromRed(),d=h.isub(c).imul(s).umod(f).imul(u);return c.iadd(d).imul(r.unblinder).umod(e.modulus).toArrayLike(xb,"be",n)}function Lb(){Rb={},xb=Ke().Buffer,Bb||(Bb=!0,Tb()),Cb=kb,Ib=yr(),Ob.getr=Pb,Rb=Ob}function Ub(){return Db||(Db=!0,Lb()),Rb}var jb,Nb=!1;function zb(){return Nb||(Nb=!0,jb={},jb=JSON.parse('{"name":"elliptic","version":"6.5.4","description":"EC cryptography","main":"lib/elliptic.js","files":["lib"],"scripts":{"lint":"eslint lib test","lint:fix":"npm run lint -- --fix","unit":"istanbul test _mocha --reporter=spec test/index.js","test":"npm run lint && npm run unit","version":"grunt dist && git add dist/"},"repository":{"type":"git","url":"git@github.com:indutny/elliptic"},"keywords":["EC","Elliptic","curve","Cryptography"],"author":"Fedor Indutny ","license":"MIT","bugs":{"url":"https://github.com/indutny/elliptic/issues"},"homepage":"https://github.com/indutny/elliptic","devDependencies":{"brfs":"^2.0.2","coveralls":"^3.1.0","eslint":"^7.6.0","grunt":"^1.2.1","grunt-browserify":"^5.3.0","grunt-cli":"^1.3.2","grunt-contrib-connect":"^3.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^5.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-saucelabs":"^9.0.1","istanbul":"^0.4.5","mocha":"^8.0.1"},"dependencies":{"bn.js":"^4.11.9","brorand":"^1.1.0","hash.js":"^1.0.0","hmac-drbg":"^1.0.1","inherits":"^2.0.4","minimalistic-assert":"^1.0.1","minimalistic-crypto-utils":"^1.0.1"}}')),jb}var Fb,qb,Wb=!1;function Hb(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"!=typeof t){for(var n=0;n>8,a=255&i;o?r.push(o,a):r.push(a)}return r}function Gb(t){return 1===t.length?"0"+t:t}function Yb(t){for(var e="",r=0;r(i>>1)-1?(i>>1)-f:f,o.isubn(s)):s=0,n[a]=s,o.iushrn(1)}return n}function tg(t,e){var r=[[],[]];t=t.clone(),e=e.clone();for(var n,i=0,o=0;t.cmpn(-i)>0||e.cmpn(-o)>0;){var a,s,f=t.andln(3)+i&3,u=e.andln(3)+o&3;3===f&&(f=-1),3===u&&(u=-1),a=0==(1&f)?0:3!==(n=t.andln(7)+i&7)&&5!==n||2!==u?f:-f,r[0].push(a),s=0==(1&u)?0:3!==(n=e.andln(7)+o&7)&&5!==n||2!==f?u:-u,r[1].push(s),2*i===a+1&&(i=1-i),2*o===s+1&&(o=1-o),t.iushrn(1),e.iushrn(1)}return r}function eg(t,e,r){var n="_"+e;t.prototype[e]=function(){return void 0!==this[n]?this[n]:this[n]=r.call(this)}}function rg(t){return"string"==typeof t?Zb.toArray(t,"hex"):t}function ng(t){return new $b(t,"hex","le")}function ig(){return Jb||(Jb=!0,Zb=Vb={},$b=lm(),Xb=tc(),Kb(),Zb.assert=Xb,Zb.toArray=Kb().toArray,Zb.zero2=Kb().zero2,Zb.toHex=Kb().toHex,Zb.encode=Kb().encode,Zb.getNAF=Qb,Zb.getJSF=tg,Zb.cachedProperty=eg,Zb.parseBytes=rg,Zb.intFromLE=ng),Vb}var og,ag,sg,fg,ug,hg=!1;function cg(t,e){this.type=t,this.p=new ag(e.p,16),this.red=e.prime?ag.red(e.prime):ag.mont(this.p),this.zero=new ag(0).toRed(this.red),this.one=new ag(1).toRed(this.red),this.two=new ag(2).toRed(this.red),this.n=e.n&&new ag(e.n,16),this.g=e.g&&this.pointFromJSON(e.g,e.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4),this._bitLength=this.n?this.n.bitLength():0;var r=this.n&&this.p.div(this.n);!r||r.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}function dg(t,e){this.curve=t,this.type=e,this.precomputed=null}function lg(){return hg||(hg=!0,og={},ag=lm(),ig(),sg=ig().getNAF,fg=ig().getJSF,ug=ig().assert,og=cg,cg.prototype.point=function(){throw new Error("Not implemented")},cg.prototype.validate=function(){throw new Error("Not implemented")},cg.prototype._fixedNafMul=function(t,e){ug(t.precomputed);var r=t._getDoubles(),n=sg(e,1,this._bitLength),i=(1<=o;f--)a=(a<<1)+n[f];s.push(a)}for(var u=this.jpoint(null,null,null),h=this.jpoint(null,null,null),c=i;c>0;c--){for(o=0;o=0;s--){for(var f=0;s>=0&&0===o[s];s--)f++;if(s>=0&&f++,a=a.dblp(f),s<0)break;var u=o[s];ug(0!==u),a="affine"===t.type?u>0?a.mixedAdd(i[u-1>>1]):a.mixedAdd(i[-u-1>>1].neg()):u>0?a.add(i[u-1>>1]):a.add(i[-u-1>>1].neg())}return"affine"===t.type?a.toP():a},cg.prototype._wnafMulAdd=function(t,e,r,n,i){var o,a,s,f=this._wnafT1,u=this._wnafT2,h=this._wnafT3,c=0;for(o=0;o=1;o-=2){var l=o-1,p=o;if(1===f[l]&&1===f[p]){var m=[e[l],null,null,e[p]];0===e[l].y.cmp(e[p].y)?(m[1]=e[l].add(e[p]),m[2]=e[l].toJ().mixedAdd(e[p].neg())):0===e[l].y.cmp(e[p].y.redNeg())?(m[1]=e[l].toJ().mixedAdd(e[p]),m[2]=e[l].add(e[p].neg())):(m[1]=e[l].toJ().mixedAdd(e[p]),m[2]=e[l].toJ().mixedAdd(e[p].neg()));var b=[-3,-1,-5,-7,0,7,5,1,3],g=fg(r[l],r[p]);for(c=Math.max(g[0].length,c),h[l]=new Array(c),h[p]=new Array(c),a=0;a=0;o--){for(var A=0;o>=0;){var M=!0;for(a=0;a=0&&A++,w=w.dblp(A),o<0)break;for(a=0;a0?s=u[a][E-1>>1]:E<0&&(s=u[a][-E-1>>1].neg()),w="affine"===s.type?w.mixedAdd(s):w.add(s))}}for(o=0;o=Math.ceil((t.bitLength()+1)/e.step)},dg.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],n=this,i=0;i=0&&(o=e,a=r),n.negative&&(n=n.neg(),i=i.neg()),o.negative&&(o=o.neg(),a=a.neg()),[{a:n,b:i},{a:o,b:a}]},wg.prototype._endoSplit=function(t){var e=this.endo.basis,r=e[0],n=e[1],i=n.b.mul(t).divRound(this.n),o=r.b.neg().mul(t).divRound(this.n),a=i.mul(r.a),s=o.mul(n.a),f=i.mul(r.b),u=o.mul(n.b);return{k1:t.sub(a).sub(s),k2:f.add(u).neg()}},wg.prototype.pointFromX=function(t,e){(t=new mg(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),n=r.redSqrt();if(0!==n.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var i=n.fromRed().isOdd();return(e&&!i||!e&&i)&&(n=n.redNeg()),this.point(t,n)},wg.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,r=t.y,n=this.a.redMul(e),i=e.redSqr().redMul(e).redIAdd(n).redIAdd(this.b);return 0===r.redSqr().redISub(i).cmpn(0)},wg.prototype._endoWnafMulAdd=function(t,e,r){for(var n=this._endoWnafT1,i=this._endoWnafT2,o=0;o":""},_g.prototype.isInfinity=function(){return this.inf},_g.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var r=e.redSqr().redISub(this.x).redISub(t.x),n=e.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,n)},_g.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,r=this.x.redSqr(),n=t.redInvm(),i=r.redAdd(r).redIAdd(r).redIAdd(e).redMul(n),o=i.redSqr().redISub(this.x.redAdd(this.x)),a=i.redMul(this.x.redSub(o)).redISub(this.y);return this.curve.point(o,a)},_g.prototype.getX=function(){return this.x.fromRed()},_g.prototype.getY=function(){return this.y.fromRed()},_g.prototype.mul=function(t){return t=new mg(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},_g.prototype.mulAdd=function(t,e,r){var n=[this,e],i=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i):this.curve._wnafMulAdd(1,n,i,2)},_g.prototype.jmulAdd=function(t,e,r){var n=[this,e],i=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i,!0):this.curve._wnafMulAdd(1,n,i,2,!0)},_g.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},_g.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var r=this.precomputed,n=function(t){return t.neg()};e.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(n)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(n)}}}return e},_g.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},bg(Ag,gg.BasePoint),wg.prototype.jpoint=function(t,e,r){return new Ag(this,t,e,r)},Ag.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),r=this.x.redMul(e),n=this.y.redMul(e).redMul(t);return this.curve.point(r,n)},Ag.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},Ag.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),r=this.z.redSqr(),n=this.x.redMul(e),i=t.x.redMul(r),o=this.y.redMul(e.redMul(t.z)),a=t.y.redMul(r.redMul(this.z)),s=n.redSub(i),f=o.redSub(a);if(0===s.cmpn(0))return 0!==f.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var u=s.redSqr(),h=u.redMul(s),c=n.redMul(u),d=f.redSqr().redIAdd(h).redISub(c).redISub(c),l=f.redMul(c.redISub(d)).redISub(o.redMul(h)),p=this.z.redMul(t.z).redMul(s);return this.curve.jpoint(d,l,p)},Ag.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),r=this.x,n=t.x.redMul(e),i=this.y,o=t.y.redMul(e).redMul(this.z),a=r.redSub(n),s=i.redSub(o);if(0===a.cmpn(0))return 0!==s.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var f=a.redSqr(),u=f.redMul(a),h=r.redMul(f),c=s.redSqr().redIAdd(u).redISub(h).redISub(h),d=s.redMul(h.redISub(c)).redISub(i.redMul(u)),l=this.z.redMul(a);return this.curve.jpoint(c,d,l)},Ag.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var e;if(this.curve.zeroA||this.curve.threeA){var r=this;for(e=0;e=0)return!1;if(r.redIAdd(i),0===this.x.cmp(r))return!0}},Ag.prototype.inspect=function(){return this.isInfinity()?"":""},Ag.prototype.isInfinity=function(){return 0===this.z.cmpn(0)}),pg}var Eg,Sg,kg,Bg,Tg=!1;function Rg(t){Bg.call(this,"mont",t),this.a=new Sg(t.a,16).toRed(this.red),this.b=new Sg(t.b,16).toRed(this.red),this.i4=new Sg(4).toRed(this.red).redInvm(),this.two=new Sg(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}function xg(t,e,r){Bg.BasePoint.call(this,t,"projective"),null===e&&null===r?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new Sg(e,16),this.z=new Sg(r,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}function Cg(){return Tg||(Tg=!0,Eg={},Sg=lm(),kg=Ar(),Bg=lg(),ig(),kg(Rg,Bg),Eg=Rg,Rg.prototype.validate=function(t){var e=t.normalize().x,r=e.redSqr(),n=r.redMul(e).redAdd(r.redMul(this.a)).redAdd(e);return 0===n.redSqrt().redSqr().cmp(n)},kg(xg,Bg.BasePoint),Rg.prototype.decodePoint=function(t,e){return this.point(ig().toArray(t,e),1)},Rg.prototype.point=function(t,e){return new xg(this,t,e)},Rg.prototype.pointFromJSON=function(t){return xg.fromJSON(this,t)},xg.prototype.precompute=function(){},xg.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},xg.fromJSON=function(t,e){return new xg(t,e[0],e[1]||t.one)},xg.prototype.inspect=function(){return this.isInfinity()?"":""},xg.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},xg.prototype.dbl=function(){var t=this.x.redAdd(this.z).redSqr(),e=this.x.redSub(this.z).redSqr(),r=t.redSub(e),n=t.redMul(e),i=r.redMul(e.redAdd(this.curve.a24.redMul(r)));return this.curve.point(n,i)},xg.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},xg.prototype.diffAdd=function(t,e){var r=this.x.redAdd(this.z),n=this.x.redSub(this.z),i=t.x.redAdd(t.z),o=t.x.redSub(t.z).redMul(r),a=i.redMul(n),s=e.z.redMul(o.redAdd(a).redSqr()),f=e.x.redMul(o.redISub(a).redSqr());return this.curve.point(s,f)},xg.prototype.mul=function(t){for(var e=t.clone(),r=this,n=this.curve.point(null,null),i=[];0!==e.cmpn(0);e.iushrn(1))i.push(e.andln(1));for(var o=i.length-1;o>=0;o--)0===i[o]?(r=r.diffAdd(n,this),n=n.dbl()):(n=r.diffAdd(n,this),r=r.dbl());return n},xg.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")},xg.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")},xg.prototype.eq=function(t){return 0===this.getX().cmp(t.getX())},xg.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},xg.prototype.getX=function(){return this.normalize(),this.x.fromRed()}),Eg}var Ig,Dg,Pg,Og,Lg,Ug=!1;function jg(t){this.twisted=1!=(0|t.a),this.mOneA=this.twisted&&-1==(0|t.a),this.extended=this.mOneA,Og.call(this,"edwards",t),this.a=new Dg(t.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new Dg(t.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new Dg(t.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),Lg(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|t.c)}function Ng(t,e,r,n,i){Og.BasePoint.call(this,t,"projective"),null===e&&null===r&&null===n?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new Dg(e,16),this.y=new Dg(r,16),this.z=n?new Dg(n,16):this.curve.one,this.t=i&&new Dg(i,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))))}function zg(){return Ug||(Ug=!0,Ig={},ig(),Dg=lm(),Pg=Ar(),Og=lg(),Lg=ig().assert,Pg(jg,Og),Ig=jg,jg.prototype._mulA=function(t){return this.mOneA?t.redNeg():this.a.redMul(t)},jg.prototype._mulC=function(t){return this.oneC?t:this.c.redMul(t)},jg.prototype.jpoint=function(t,e,r,n){return this.point(t,e,r,n)},jg.prototype.pointFromX=function(t,e){(t=new Dg(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr(),n=this.c2.redSub(this.a.redMul(r)),i=this.one.redSub(this.c2.redMul(this.d).redMul(r)),o=n.redMul(i.redInvm()),a=o.redSqrt();if(0!==a.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");var s=a.fromRed().isOdd();return(e&&!s||!e&&s)&&(a=a.redNeg()),this.point(t,a)},jg.prototype.pointFromY=function(t,e){(t=new Dg(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr(),n=r.redSub(this.c2),i=r.redMul(this.d).redMul(this.c2).redSub(this.a),o=n.redMul(i.redInvm());if(0===o.cmp(this.zero)){if(e)throw new Error("invalid point");return this.point(this.zero,t)}var a=o.redSqrt();if(0!==a.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");return a.fromRed().isOdd()!==e&&(a=a.redNeg()),this.point(a,t)},jg.prototype.validate=function(t){if(t.isInfinity())return!0;t.normalize();var e=t.x.redSqr(),r=t.y.redSqr(),n=e.redMul(this.a).redAdd(r),i=this.c2.redMul(this.one.redAdd(this.d.redMul(e).redMul(r)));return 0===n.cmp(i)},Pg(Ng,Og.BasePoint),jg.prototype.pointFromJSON=function(t){return Ng.fromJSON(this,t)},jg.prototype.point=function(t,e,r,n){return new Ng(this,t,e,r,n)},Ng.fromJSON=function(t,e){return new Ng(t,e[0],e[1],e[2])},Ng.prototype.inspect=function(){return this.isInfinity()?"":""},Ng.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&(0===this.y.cmp(this.z)||this.zOne&&0===this.y.cmp(this.curve.c))},Ng.prototype._extDbl=function(){var t=this.x.redSqr(),e=this.y.redSqr(),r=this.z.redSqr();r=r.redIAdd(r);var n=this.curve._mulA(t),i=this.x.redAdd(this.y).redSqr().redISub(t).redISub(e),o=n.redAdd(e),a=o.redSub(r),s=n.redSub(e),f=i.redMul(a),u=o.redMul(s),h=i.redMul(s),c=a.redMul(o);return this.curve.point(f,u,c,h)},Ng.prototype._projDbl=function(){var t,e,r,n,i,o,a=this.x.redAdd(this.y).redSqr(),s=this.x.redSqr(),f=this.y.redSqr();if(this.curve.twisted){var u=(n=this.curve._mulA(s)).redAdd(f);this.zOne?(t=a.redSub(s).redSub(f).redMul(u.redSub(this.curve.two)),e=u.redMul(n.redSub(f)),r=u.redSqr().redSub(u).redSub(u)):(i=this.z.redSqr(),o=u.redSub(i).redISub(i),t=a.redSub(s).redISub(f).redMul(o),e=u.redMul(n.redSub(f)),r=u.redMul(o))}else n=s.redAdd(f),i=this.curve._mulC(this.z).redSqr(),o=n.redSub(i).redSub(i),t=this.curve._mulC(a.redISub(n)).redMul(o),e=this.curve._mulC(n).redMul(s.redISub(f)),r=n.redMul(o);return this.curve.point(t,e,r)},Ng.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},Ng.prototype._extAdd=function(t){var e=this.y.redSub(this.x).redMul(t.y.redSub(t.x)),r=this.y.redAdd(this.x).redMul(t.y.redAdd(t.x)),n=this.t.redMul(this.curve.dd).redMul(t.t),i=this.z.redMul(t.z.redAdd(t.z)),o=r.redSub(e),a=i.redSub(n),s=i.redAdd(n),f=r.redAdd(e),u=o.redMul(a),h=s.redMul(f),c=o.redMul(f),d=a.redMul(s);return this.curve.point(u,h,d,c)},Ng.prototype._projAdd=function(t){var e,r,n=this.z.redMul(t.z),i=n.redSqr(),o=this.x.redMul(t.x),a=this.y.redMul(t.y),s=this.curve.d.redMul(o).redMul(a),f=i.redSub(s),u=i.redAdd(s),h=this.x.redAdd(this.y).redMul(t.x.redAdd(t.y)).redISub(o).redISub(a),c=n.redMul(f).redMul(h);return this.curve.twisted?(e=n.redMul(u).redMul(a.redSub(this.curve._mulA(o))),r=f.redMul(u)):(e=n.redMul(u).redMul(a.redSub(o)),r=this.curve._mulC(f).redMul(u)),this.curve.point(c,e,r)},Ng.prototype.add=function(t){return this.isInfinity()?t:t.isInfinity()?this:this.curve.extended?this._extAdd(t):this._projAdd(t)},Ng.prototype.mul=function(t){return this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve._wnafMul(this,t)},Ng.prototype.mulAdd=function(t,e,r){return this.curve._wnafMulAdd(1,[this,e],[t,r],2,!1)},Ng.prototype.jmulAdd=function(t,e,r){return this.curve._wnafMulAdd(1,[this,e],[t,r],2,!0)},Ng.prototype.normalize=function(){if(this.zOne)return this;var t=this.z.redInvm();return this.x=this.x.redMul(t),this.y=this.y.redMul(t),this.t&&(this.t=this.t.redMul(t)),this.z=this.curve.one,this.zOne=!0,this},Ng.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},Ng.prototype.getX=function(){return this.normalize(),this.x.fromRed()},Ng.prototype.getY=function(){return this.normalize(),this.y.fromRed()},Ng.prototype.eq=function(t){return this===t||0===this.getX().cmp(t.getX())&&0===this.getY().cmp(t.getY())},Ng.prototype.eqXToP=function(t){var e=t.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(e))return!0;for(var r=t.clone(),n=this.curve.redN.redMul(this.z);;){if(r.iadd(this.curve.n),r.cmp(this.curve.p)>=0)return!1;if(e.redIAdd(n),0===this.x.cmp(e))return!0}},Ng.prototype.toP=Ng.prototype.normalize,Ng.prototype.mixedAdd=Ng.prototype.add),Ig}var Fg,qg,Wg=!1;function Hg(){return Wg||(Wg=!0,(qg=Fg={}).base=lg(),qg.short=Mg(),qg.mont=Cg(),qg.edwards=zg()),Fg}var Gg,Yg,Kg,Vg,Zg,$g,Xg,Jg,Qg,tv,ev,rv,nv,iv,ov,av,sv,fv,uv,hv,cv,dv,lv,pv,mv,bv,gv,vv,yv,wv=!1;function _v(t,e){return 55296==(64512&t.charCodeAt(e))&&(!(e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1)))}function Av(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),i=0;i>6|192,r[n++]=63&o|128):_v(t,i)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++i)),r[n++]=o>>18|240,r[n++]=o>>12&63|128,r[n++]=o>>6&63|128,r[n++]=63&o|128):(r[n++]=o>>12|224,r[n++]=o>>6&63|128,r[n++]=63&o|128)}else for(i=0;i>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function Sv(t,e){for(var r="",n=0;n>>0}return o}function Rv(t,e){for(var r=new Array(4*t.length),n=0,i=0;n>>24,r[i+1]=o>>>16&255,r[i+2]=o>>>8&255,r[i+3]=255&o):(r[i+3]=o>>>24,r[i+2]=o>>>16&255,r[i+1]=o>>>8&255,r[i]=255&o)}return r}function xv(t,e){return t>>>e|t<<32-e}function Cv(t,e){return t<>>32-e}function Iv(t,e){return t+e>>>0}function Dv(t,e,r){return t+e+r>>>0}function Pv(t,e,r,n){return t+e+r+n>>>0}function Ov(t,e,r,n,i){return t+e+r+n+i>>>0}function Lv(t,e,r,n){var i=t[e],o=n+t[e+1]>>>0,a=(o>>0,t[e+1]=o}function Uv(t,e,r,n){return(e+n>>>0>>0}function jv(t,e,r,n){return e+n>>>0}function Nv(t,e,r,n,i,o,a,s){var f=0,u=e;return f+=(u=u+n>>>0)>>0)>>0)>>0}function zv(t,e,r,n,i,o,a,s){return e+n+o+s>>>0}function Fv(t,e,r,n,i,o,a,s,f,u){var h=0,c=e;return h+=(c=c+n>>>0)>>0)