>>=26,e.words[r]=n,t=i}return 0!==t&&(e.words[e.length++]=t),e},n._prime=function(e){if(y[e])return y[e];var t;if("k256"===e)t=new m;else if("p224"===e)t=new g;else if("p192"===e)t=new w;else{if("p25519"!==e)throw Error("Unknown prime "+e);t=new v}return y[e]=t,t},_.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},_.prototype._verify2=function(e,t){r(0==(e.negative|t.negative),"red works only with positives"),r(e.red&&e.red===t.red,"red works only with red numbers")},_.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):e.umod(this.m)._forceRed(this)},_.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},_.prototype.add=function(e,t){this._verify2(e,t);var r=e.add(t);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},_.prototype.iadd=function(e,t){this._verify2(e,t);var r=e.iadd(t);return r.cmp(this.m)>=0&&r.isub(this.m),r},_.prototype.sub=function(e,t){this._verify2(e,t);var r=e.sub(t);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},_.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},_.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},_.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},_.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},_.prototype.isqr=function(e){return this.imul(e,e.clone())},_.prototype.sqr=function(e){return this.mul(e,e)},_.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(r(t%2==1),3===t){var i=this.m.add(new n(1)).iushrn(2);return this.pow(e,i)}for(var a=this.m.subn(1),s=0;!a.isZero()&&0===a.andln(1);)s++,a.iushrn(1);r(!a.isZero());var o=new n(1).toRed(this),c=o.redNeg(),u=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new n(2*h*h).toRed(this);0!==this.pow(h,u).cmp(c);)h.redIAdd(c);for(var d=this.pow(h,a),f=this.pow(e,a.addn(1).iushrn(1)),l=this.pow(e,a),p=s;0!==l.cmp(o);){for(var y=l,b=0;0!==y.cmp(o);b++)y=y.redSqr();r(b=0;i--){for(var u=t.words[i],h=c-1;h>=0;h--){var d=u>>h&1;a!==r[0]&&(a=this.sqr(a)),0!==d||0!==s?(s<<=1,s|=d,(4===++o||0===i&&0===h)&&(a=this.mul(a,r[s]),o=0,s=0)):o=0}c=26}return a},_.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},_.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},n.mont=function(e){return new k(e)},i(k,_),k.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},k.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},k.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),a=n;return n.cmp(this.m)>=0?a=n.isub(this.m):n.cmpn(0)<0&&(a=n.iadd(this.m)),a._forceRed(this)},k.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new n(0)._forceRed(this);var r=e.mul(t),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),a=r.isub(i).iushrn(this.shift),s=a;return a.cmp(this.m)>=0?s=a.isub(this.m):a.cmpn(0)<0&&(s=a.iadd(this.m)),s._forceRed(this)},k.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(e,et)})),Rf=/*#__PURE__*/Object.freeze({__proto__:null,default:Df,__moduleExports:Df});class If{constructor(e){if(void 0===e)throw Error("Invalid BigInteger input");this.value=new Df(e)}clone(){const e=new If(null);return this.value.copy(e.value),e}iinc(){return this.value.iadd(new Df(1)),this}inc(){return this.clone().iinc()}idec(){return this.value.isub(new Df(1)),this}dec(){return this.clone().idec()}iadd(e){return this.value.iadd(e.value),this}add(e){return this.clone().iadd(e)}isub(e){return this.value.isub(e.value),this}sub(e){return this.clone().isub(e)}imul(e){return this.value.imul(e.value),this}mul(e){return this.clone().imul(e)}imod(e){return this.value=this.value.umod(e.value),this}mod(e){return this.clone().imod(e)}modExp(e,t){const r=t.isEven()?Df.red(t.value):Df.mont(t.value),i=this.clone();return i.value=i.value.toRed(r).redPow(e.value).fromRed(),i}modInv(e){if(!this.gcd(e).isOne())throw Error("Inverse does not exist");return new If(this.value.invm(e.value))}gcd(e){return new If(this.value.gcd(e.value))}ileftShift(e){return this.value.ishln(e.value.toNumber()),this}leftShift(e){return this.clone().ileftShift(e)}irightShift(e){return this.value.ishrn(e.value.toNumber()),this}rightShift(e){return this.clone().irightShift(e)}equal(e){return this.value.eq(e.value)}lt(e){return this.value.lt(e.value)}lte(e){return this.value.lte(e.value)}gt(e){return this.value.gt(e.value)}gte(e){return this.value.gte(e.value)}isZero(){return this.value.isZero()}isOne(){return this.value.eq(new Df(1))}isNegative(){return this.value.isNeg()}isEven(){return this.value.isEven()}abs(){const e=this.clone();return e.value=e.value.abs(),e}toString(){return this.value.toString()}toNumber(){return this.value.toNumber()}getBit(e){return this.value.testn(e)?1:0}bitLength(){return this.value.bitLength()}byteLength(){return this.value.byteLength()}toUint8Array(e="be",t){return this.value.toArrayLike(Uint8Array,e,t)}}var Uf,Bf=/*#__PURE__*/Object.freeze({__proto__:null,default:If}),Tf=tt((function(e,t){var r=t;function i(e){return 1===e.length?"0"+e:e}function n(e){for(var t="",r=0;r>8,s=255&n;a?r.push(a,s):r.push(s)}return r},r.zero2=i,r.toHex=n,r.encode=function(e,t){return"hex"===t?n(e):e}})),zf=tt((function(e,t){var r=t;r.assert=Qe,r.toArray=Tf.toArray,r.zero2=Tf.zero2,r.toHex=Tf.toHex,r.encode=Tf.encode,r.getNAF=function(e,t){for(var r=[],i=1<=0;){var a;if(n.isOdd()){var s=n.andln(i-1);a=s>(i>>1)-1?(i>>1)-s:s,n.isubn(a)}else a=0;r.push(a);for(var o=0!==n.cmpn(0)&&0===n.andln(i-1)?t+1:1,c=1;c0||t.cmpn(-n)>0;){var a,s,o,c=e.andln(3)+i&3,u=t.andln(3)+n&3;if(3===c&&(c=-1),3===u&&(u=-1),0==(1&c))a=0;else a=3!==(o=e.andln(7)+i&7)&&5!==o||2!==u?c:-c;if(r[0].push(a),0==(1&u))s=0;else s=3!==(o=t.andln(7)+n&7)&&5!==o||2!==c?u:-u;r[1].push(s),2*i===a+1&&(i=1-i),2*n===s+1&&(n=1-n),e.iushrn(1),t.iushrn(1)}return r},r.cachedProperty=function(e,t,r){var i="_"+t;e.prototype[t]=function(){return void 0!==this[i]?this[i]:this[i]=r.call(this)}},r.parseBytes=function(e){return"string"==typeof e?r.toArray(e,"hex"):e},r.intFromLE=function(e){return new Df(e,"hex","le")}})),qf=function(e){return Uf||(Uf=new Of(null)),Uf.generate(e)};function Of(e){this.rand=e}var Ff=Of;if(Of.prototype.generate=function(e){return this._rand(e)},Of.prototype._rand=function(e){if(this.rand.getBytes)return this.rand.getBytes(e);for(var t=new Uint8Array(e),r=0;r0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var Gf=Hf;function Vf(e,t){this.curve=e,this.type=t,this.precomputed=null}Hf.prototype.point=function(){throw Error("Not implemented")},Hf.prototype.validate=function(){throw Error("Not implemented")},Hf.prototype._fixedNafMul=function(e,t){Wf(e.precomputed);var r=e._getDoubles(),i=Lf(t,1),n=(1<=s;t--)o=(o<<1)+i[t];a.push(o)}for(var c=this.jpoint(null,null,null),u=this.jpoint(null,null,null),h=n;h>0;h--){for(s=0;s=0;o--){for(t=0;o>=0&&0===a[o];o--)t++;if(o>=0&&t++,s=s.dblp(t),o<0)break;var c=a[o];Wf(0!==c),s="affine"===e.type?c>0?s.mixedAdd(n[c-1>>1]):s.mixedAdd(n[-c-1>>1].neg()):c>0?s.add(n[c-1>>1]):s.add(n[-c-1>>1].neg())}return"affine"===e.type?s.toP():s},Hf.prototype._wnafMulAdd=function(e,t,r,i,n){for(var a=this._wnafT1,s=this._wnafT2,o=this._wnafT3,c=0,u=0;u=1;u-=2){var d=u-1,f=u;if(1===a[d]&&1===a[f]){var l=[t[d],null,null,t[f]];0===t[d].y.cmp(t[f].y)?(l[1]=t[d].add(t[f]),l[2]=t[d].toJ().mixedAdd(t[f].neg())):0===t[d].y.cmp(t[f].y.redNeg())?(l[1]=t[d].toJ().mixedAdd(t[f]),l[2]=t[d].add(t[f].neg())):(l[1]=t[d].toJ().mixedAdd(t[f]),l[2]=t[d].toJ().mixedAdd(t[f].neg()));var p=[-3,-1,-5,-7,0,7,5,1,3],y=jf(r[d],r[f]);c=Math.max(y[0].length,c),o[d]=Array(c),o[f]=Array(c);for(var b=0;b=0;u--){for(var _=0;u>=0;){var k=!0;for(b=0;b=0&&_++,w=w.dblp(_),u<0)break;for(b=0;b0?A=s[b][S-1>>1]:S<0&&(A=s[b][-S-1>>1].neg()),w="affine"===A.type?w.mixedAdd(A):w.add(A))}}for(u=0;u=Math.ceil((e.bitLength()+1)/t.step)},Vf.prototype._getDoubles=function(e,t){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],i=this,n=0;n=0&&(a=t,s=r),i.negative&&(i=i.neg(),n=n.neg()),a.negative&&(a=a.neg(),s=s.neg()),[{a:i,b:n},{a,b:s}]},Zf.prototype._endoSplit=function(e){var t=this.endo.basis,r=t[0],i=t[1],n=i.b.mul(e).divRound(this.n),a=r.b.neg().mul(e).divRound(this.n),s=n.mul(r.a),o=a.mul(i.a),c=n.mul(r.b),u=a.mul(i.b);return{k1:e.sub(s).sub(o),k2:c.add(u).neg()}},Zf.prototype.pointFromX=function(e,t){(e=new Df(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),i=r.redSqrt();if(0!==i.redSqr().redSub(r).cmp(this.zero))throw Error("invalid point");var n=i.fromRed().isOdd();return(t&&!n||!t&&n)&&(i=i.redNeg()),this.point(e,i)},Zf.prototype.validate=function(e){if(e.inf)return!0;var t=e.x,r=e.y,i=this.a.redMul(t),n=t.redSqr().redMul(t).redIAdd(i).redIAdd(this.b);return 0===r.redSqr().redISub(n).cmpn(0)},Zf.prototype._endoWnafMulAdd=function(e,t,r){for(var i=this._endoWnafT1,n=this._endoWnafT2,a=0;a":""},Xf.prototype.isInfinity=function(){return this.inf},Xf.prototype.add=function(e){if(this.inf)return e;if(e.inf)return this;if(this.eq(e))return this.dbl();if(this.neg().eq(e))return this.curve.point(null,null);if(0===this.x.cmp(e.x))return this.curve.point(null,null);var t=this.y.redSub(e.y);0!==t.cmpn(0)&&(t=t.redMul(this.x.redSub(e.x).redInvm()));var r=t.redSqr().redISub(this.x).redISub(e.x),i=t.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,i)},Xf.prototype.dbl=function(){if(this.inf)return this;var e=this.y.redAdd(this.y);if(0===e.cmpn(0))return this.curve.point(null,null);var t=this.curve.a,r=this.x.redSqr(),i=e.redInvm(),n=r.redAdd(r).redIAdd(r).redIAdd(t).redMul(i),a=n.redSqr().redISub(this.x.redAdd(this.x)),s=n.redMul(this.x.redSub(a)).redISub(this.y);return this.curve.point(a,s)},Xf.prototype.getX=function(){return this.x.fromRed()},Xf.prototype.getY=function(){return this.y.fromRed()},Xf.prototype.mul=function(e){return e=new Df(e,16),this.isInfinity()?this:this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve.endo?this.curve._endoWnafMulAdd([this],[e]):this.curve._wnafMul(this,e)},Xf.prototype.mulAdd=function(e,t,r){var i=[this,t],n=[e,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n):this.curve._wnafMulAdd(1,i,n,2)},Xf.prototype.jmulAdd=function(e,t,r){var i=[this,t],n=[e,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n,!0):this.curve._wnafMulAdd(1,i,n,2,!0)},Xf.prototype.eq=function(e){return this===e||this.inf===e.inf&&(this.inf||0===this.x.cmp(e.x)&&0===this.y.cmp(e.y))},Xf.prototype.neg=function(e){if(this.inf)return this;var t=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var r=this.precomputed,i=function(e){return e.neg()};t.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(i)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(i)}}}return t},Xf.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},rt(Qf,Gf.BasePoint),Zf.prototype.jpoint=function(e,t,r){return new Qf(this,e,t,r)},Qf.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),t=e.redSqr(),r=this.x.redMul(t),i=this.y.redMul(t).redMul(e);return this.curve.point(r,i)},Qf.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},Qf.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var t=e.z.redSqr(),r=this.z.redSqr(),i=this.x.redMul(t),n=e.x.redMul(r),a=this.y.redMul(t.redMul(e.z)),s=e.y.redMul(r.redMul(this.z)),o=i.redSub(n),c=a.redSub(s);if(0===o.cmpn(0))return 0!==c.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var u=o.redSqr(),h=u.redMul(o),d=i.redMul(u),f=c.redSqr().redIAdd(h).redISub(d).redISub(d),l=c.redMul(d.redISub(f)).redISub(a.redMul(h)),p=this.z.redMul(e.z).redMul(o);return this.curve.jpoint(f,l,p)},Qf.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var t=this.z.redSqr(),r=this.x,i=e.x.redMul(t),n=this.y,a=e.y.redMul(t).redMul(this.z),s=r.redSub(i),o=n.redSub(a);if(0===s.cmpn(0))return 0!==o.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var c=s.redSqr(),u=c.redMul(s),h=r.redMul(c),d=o.redSqr().redIAdd(u).redISub(h).redISub(h),f=o.redMul(h.redISub(d)).redISub(n.redMul(u)),l=this.z.redMul(s);return this.curve.jpoint(d,f,l)},Qf.prototype.dblp=function(e){if(0===e)return this;if(this.isInfinity())return this;if(!e)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var t=this,r=0;r=0)return!1;if(r.redIAdd(n),0===this.x.cmp(r))return!0}},Qf.prototype.inspect=function(){return this.isInfinity()?"":""},Qf.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},rt(Jf,Gf);var el=Jf;function tl(e,t,r){Gf.BasePoint.call(this,e,"projective"),null===t&&null===r?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new Df(t,16),this.z=new Df(r,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}Jf.prototype.validate=function(e){var t=e.normalize().x,r=t.redSqr(),i=r.redMul(t).redAdd(r.redMul(this.a)).redAdd(t);return 0===i.redSqrt().redSqr().cmp(i)},rt(tl,Gf.BasePoint),Jf.prototype.decodePoint=function(e,t){if(33===(e=zf.toArray(e,t)).length&&64===e[0]&&(e=e.slice(1,33).reverse()),32!==e.length)throw Error("Unknown point compression format");return this.point(e,1)},Jf.prototype.point=function(e,t){return new tl(this,e,t)},Jf.prototype.pointFromJSON=function(e){return tl.fromJSON(this,e)},tl.prototype.precompute=function(){},tl.prototype._encode=function(e){var t=this.curve.p.byteLength();return e?[64].concat(this.getX().toArray("le",t)):this.getX().toArray("be",t)},tl.fromJSON=function(e,t){return new tl(e,t[0],t[1]||e.one)},tl.prototype.inspect=function(){return this.isInfinity()?"":""},tl.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},tl.prototype.dbl=function(){var e=this.x.redAdd(this.z).redSqr(),t=this.x.redSub(this.z).redSqr(),r=e.redSub(t),i=e.redMul(t),n=r.redMul(t.redAdd(this.curve.a24.redMul(r)));return this.curve.point(i,n)},tl.prototype.add=function(){throw Error("Not supported on Montgomery curve")},tl.prototype.diffAdd=function(e,t){var r=this.x.redAdd(this.z),i=this.x.redSub(this.z),n=e.x.redAdd(e.z),a=e.x.redSub(e.z).redMul(r),s=n.redMul(i),o=t.z.redMul(a.redAdd(s).redSqr()),c=t.x.redMul(a.redISub(s).redSqr());return this.curve.point(o,c)},tl.prototype.mul=function(e){for(var t=(e=new Df(e,16)).clone(),r=this,i=this.curve.point(null,null),n=[];0!==t.cmpn(0);t.iushrn(1))n.push(t.andln(1));for(var a=n.length-1;a>=0;a--)0===n[a]?(r=r.diffAdd(i,this),i=i.dbl()):(i=r.diffAdd(i,this),r=r.dbl());return i},tl.prototype.mulAdd=function(){throw Error("Not supported on Montgomery curve")},tl.prototype.jumlAdd=function(){throw Error("Not supported on Montgomery curve")},tl.prototype.eq=function(e){return 0===this.getX().cmp(e.getX())},tl.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},tl.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var rl=zf.assert;function il(e){this.twisted=1!=(0|e.a),this.mOneA=this.twisted&&-1==(0|e.a),this.extended=this.mOneA,Gf.call(this,"edwards",e),this.a=new Df(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new Df(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new Df(e.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),rl(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|e.c)}rt(il,Gf);var nl=il;function al(e,t,r,i,n){Gf.BasePoint.call(this,e,"projective"),null===t&&null===r&&null===i?(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 Df(t,16),this.y=new Df(r,16),this.z=i?new Df(i,16):this.curve.one,this.t=n&&new Df(n,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()))))}il.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)},il.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)},il.prototype.jpoint=function(e,t,r,i){return this.point(e,t,r,i)},il.prototype.pointFromX=function(e,t){(e=new Df(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr(),i=this.c2.redSub(this.a.redMul(r)),n=this.one.redSub(this.c2.redMul(this.d).redMul(r)),a=i.redMul(n.redInvm()),s=a.redSqrt();if(0!==s.redSqr().redSub(a).cmp(this.zero))throw Error("invalid point");var o=s.fromRed().isOdd();return(t&&!o||!t&&o)&&(s=s.redNeg()),this.point(e,s)},il.prototype.pointFromY=function(e,t){(e=new Df(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr(),i=r.redSub(this.c2),n=r.redMul(this.d).redMul(this.c2).redSub(this.a),a=i.redMul(n.redInvm());if(0===a.cmp(this.zero)){if(t)throw Error("invalid point");return this.point(this.zero,e)}var s=a.redSqrt();if(0!==s.redSqr().redSub(a).cmp(this.zero))throw Error("invalid point");return s.fromRed().isOdd()!==t&&(s=s.redNeg()),this.point(s,e)},il.prototype.validate=function(e){if(e.isInfinity())return!0;e.normalize();var t=e.x.redSqr(),r=e.y.redSqr(),i=t.redMul(this.a).redAdd(r),n=this.c2.redMul(this.one.redAdd(this.d.redMul(t).redMul(r)));return 0===i.cmp(n)},rt(al,Gf.BasePoint),il.prototype.pointFromJSON=function(e){return al.fromJSON(this,e)},il.prototype.point=function(e,t,r,i){return new al(this,e,t,r,i)},al.fromJSON=function(e,t){return new al(e,t[0],t[1],t[2])},al.prototype.inspect=function(){return this.isInfinity()?"":""},al.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&(0===this.y.cmp(this.z)||this.zOne&&0===this.y.cmp(this.curve.c))},al.prototype._extDbl=function(){var e=this.x.redSqr(),t=this.y.redSqr(),r=this.z.redSqr();r=r.redIAdd(r);var i=this.curve._mulA(e),n=this.x.redAdd(this.y).redSqr().redISub(e).redISub(t),a=i.redAdd(t),s=a.redSub(r),o=i.redSub(t),c=n.redMul(s),u=a.redMul(o),h=n.redMul(o),d=s.redMul(a);return this.curve.point(c,u,d,h)},al.prototype._projDbl=function(){var e,t,r,i=this.x.redAdd(this.y).redSqr(),n=this.x.redSqr(),a=this.y.redSqr();if(this.curve.twisted){var s=(u=this.curve._mulA(n)).redAdd(a);if(this.zOne)e=i.redSub(n).redSub(a).redMul(s.redSub(this.curve.two)),t=s.redMul(u.redSub(a)),r=s.redSqr().redSub(s).redSub(s);else{var o=this.z.redSqr(),c=s.redSub(o).redISub(o);e=i.redSub(n).redISub(a).redMul(c),t=s.redMul(u.redSub(a)),r=s.redMul(c)}}else{var u=n.redAdd(a);o=this.curve._mulC(this.z).redSqr(),c=u.redSub(o).redSub(o);e=this.curve._mulC(i.redISub(u)).redMul(c),t=this.curve._mulC(u).redMul(n.redISub(a)),r=u.redMul(c)}return this.curve.point(e,t,r)},al.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},al.prototype._extAdd=function(e){var t=this.y.redSub(this.x).redMul(e.y.redSub(e.x)),r=this.y.redAdd(this.x).redMul(e.y.redAdd(e.x)),i=this.t.redMul(this.curve.dd).redMul(e.t),n=this.z.redMul(e.z.redAdd(e.z)),a=r.redSub(t),s=n.redSub(i),o=n.redAdd(i),c=r.redAdd(t),u=a.redMul(s),h=o.redMul(c),d=a.redMul(c),f=s.redMul(o);return this.curve.point(u,h,f,d)},al.prototype._projAdd=function(e){var t,r,i=this.z.redMul(e.z),n=i.redSqr(),a=this.x.redMul(e.x),s=this.y.redMul(e.y),o=this.curve.d.redMul(a).redMul(s),c=n.redSub(o),u=n.redAdd(o),h=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(a).redISub(s),d=i.redMul(c).redMul(h);return this.curve.twisted?(t=i.redMul(u).redMul(s.redSub(this.curve._mulA(a))),r=c.redMul(u)):(t=i.redMul(u).redMul(s.redSub(a)),r=this.curve._mulC(c).redMul(u)),this.curve.point(d,t,r)},al.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},al.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},al.prototype.mulAdd=function(e,t,r){return this.curve._wnafMulAdd(1,[this,t],[e,r],2,!1)},al.prototype.jmulAdd=function(e,t,r){return this.curve._wnafMulAdd(1,[this,t],[e,r],2,!0)},al.prototype.normalize=function(){if(this.zOne)return this;var e=this.z.redInvm();return this.x=this.x.redMul(e),this.y=this.y.redMul(e),this.t&&(this.t=this.t.redMul(e)),this.z=this.curve.one,this.zOne=!0,this},al.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},al.prototype.getX=function(){return this.normalize(),this.x.fromRed()},al.prototype.getY=function(){return this.normalize(),this.y.fromRed()},al.prototype.eq=function(e){return this===e||0===this.getX().cmp(e.getX())&&0===this.getY().cmp(e.getY())},al.prototype.eqXToP=function(e){var t=e.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(t))return!0;for(var r=e.clone(),i=this.curve.redN.redMul(this.z);;){if(r.iadd(this.curve.n),r.cmp(this.curve.p)>=0)return!1;if(t.redIAdd(i),0===this.x.cmp(t))return!0}},al.prototype.toP=al.prototype.normalize,al.prototype.mixedAdd=al.prototype.add;var sl=tt((function(e,t){var r=t;r.base=Gf,r.short=Yf,r.mont=el,r.edwards=nl})),ol=st.rotl32,cl=st.sum32,ul=st.sum32_5,hl=pt.ft_1,dl=ut.BlockHash,fl=[1518500249,1859775393,2400959708,3395469782];function ll(){if(!(this instanceof ll))return new ll;dl.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=Array(80)}st.inherits(ll,dl);var pl=ll;ll.blockSize=512,ll.outSize=160,ll.hmacStrength=80,ll.padLength=64,ll.prototype._update=function(e,t){for(var r=this.W,i=0;i<16;i++)r[i]=e[t+i];for(;ithis.blockSize&&(e=(new this.Hash).update(e).digest()),Qe(e.length<=this.blockSize);for(var t=e.length;t=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(t,r,i)}var kl=_l;_l.prototype._init=function(e,t,r){var i=e.concat(t).concat(r);this.K=Array(this.outLen/8),this.V=Array(this.outLen/8);for(var n=0;n=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(e.concat(r||[])),this._reseed=1},_l.prototype.generate=function(e,t,r,i){if(this._reseed>this.reseedInterval)throw Error("Reseed is required");"string"!=typeof t&&(i=r,r=t,t=null),r&&(r=Tf.toArray(r,i||"hex"),this._update(r));for(var n=[];n.length"};var Pl=zf.assert;function xl(e,t){if(e instanceof xl)return e;this._importDER(e,t)||(Pl(e.r&&e.s,"Signature without r or s"),this.r=new Df(e.r,16),this.s=new Df(e.s,16),void 0===e.recoveryParam?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}var Ml=xl;function Cl(){this.place=0}function Kl(e,t){var r=e[t.place++];if(!(128&r))return r;for(var i=15&r,n=0,a=0,s=t.place;a>>3);for(e.push(128|r);--r;)e.push(t>>>(r<<3)&255);e.push(t)}}xl.prototype._importDER=function(e,t){e=zf.toArray(e,t);var r=new Cl;if(48!==e[r.place++])return!1;if(Kl(e,r)+r.place!==e.length)return!1;if(2!==e[r.place++])return!1;var i=Kl(e,r),n=e.slice(r.place,i+r.place);if(r.place+=i,2!==e[r.place++])return!1;var a=Kl(e,r);if(e.length!==a+r.place)return!1;var s=e.slice(r.place,a+r.place);return 0===n[0]&&128&n[1]&&(n=n.slice(1)),0===s[0]&&128&s[1]&&(s=s.slice(1)),this.r=new Df(n),this.s=new Df(s),this.recoveryParam=null,!0},xl.prototype.toDER=function(e){var t=this.r.toArray(),r=this.s.toArray();for(128&t[0]&&(t=[0].concat(t)),128&r[0]&&(r=[0].concat(r)),t=Dl(t),r=Dl(r);!(r[0]||128&r[1]);)r=r.slice(1);var i=[2];Rl(i,t.length),(i=i.concat(t)).push(2),Rl(i,r.length);var n=i.concat(r),a=[48];return Rl(a,n.length),a=a.concat(n),zf.encode(a,e)};var Il=zf.assert;function Ul(e){if(!(this instanceof Ul))return new Ul(e);"string"==typeof e&&(Il(vl.hasOwnProperty(e),"Unknown curve "+e),e=vl[e]),e instanceof vl.PresetCurve&&(e={curve:e}),this.curve=e.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=e.curve.g,this.g.precompute(e.curve.n.bitLength()+1),this.hash=e.hash||e.curve.hash}var Bl=Ul;Ul.prototype.keyPair=function(e){return new El(this,e)},Ul.prototype.keyFromPrivate=function(e,t){return El.fromPrivate(this,e,t)},Ul.prototype.keyFromPublic=function(e,t){return El.fromPublic(this,e,t)},Ul.prototype.genKeyPair=function(e){e||(e={});var t=new kl({hash:this.hash,pers:e.pers,persEnc:e.persEnc||"utf8",entropy:e.entropy||qf(this.hash.hmacStrength),entropyEnc:e.entropy&&e.entropyEnc||"utf8",nonce:this.n.toArray()});if("mont"===this.curve.type){var r=new Df(t.generate(32));return this.keyFromPrivate(r)}for(var i=this.n.byteLength(),n=this.n.sub(new Df(2));;){if(!((r=new Df(t.generate(i))).cmp(n)>0))return r.iaddn(1),this.keyFromPrivate(r)}},Ul.prototype._truncateToN=function(e,t,r){var i=(r=r||8*e.byteLength())-this.n.bitLength();return i>0&&(e=e.ushrn(i)),!t&&e.cmp(this.n)>=0?e.sub(this.n):e},Ul.prototype.truncateMsg=function(e){var t;return e instanceof Uint8Array?(t=8*e.byteLength,e=this._truncateToN(new Df(e,16),!1,t)):"string"==typeof e?(t=4*e.length,e=this._truncateToN(new Df(e,16),!1,t)):e=this._truncateToN(new Df(e,16)),e},Ul.prototype.sign=function(e,t,r,i){"object"==typeof r&&(i=r,r=null),i||(i={}),t=this.keyFromPrivate(t,r),e=this.truncateMsg(e);for(var n=this.n.byteLength(),a=t.getPrivate().toArray("be",n),s=e.toArray("be",n),o=new kl({hash:this.hash,entropy:a,nonce:s,pers:i.pers,persEnc:i.persEnc||"utf8"}),c=this.n.sub(new Df(1)),u=0;;u++){var h=i.k?i.k(u):new Df(o.generate(this.n.byteLength()));if(!((h=this._truncateToN(h,!0)).cmpn(1)<=0||h.cmp(c)>=0)){var d=this.g.mul(h);if(!d.isInfinity()){var f=d.getX(),l=f.umod(this.n);if(0!==l.cmpn(0)){var p=h.invm(this.n).mul(l.mul(t.getPrivate()).iadd(e));if(0!==(p=p.umod(this.n)).cmpn(0)){var y=(d.getY().isOdd()?1:0)|(0!==f.cmp(l)?2:0);return i.canonical&&p.cmp(this.nh)>0&&(p=this.n.sub(p),y^=1),new Ml({r:l,s:p,recoveryParam:y})}}}}}},Ul.prototype.verify=function(e,t,r,i){return r=this.keyFromPublic(r,i),t=new Ml(t,"hex"),this._verify(this.truncateMsg(e),t,r)||this._verify(this._truncateToN(new Df(e,16)),t,r)},Ul.prototype._verify=function(e,t,r){var i=t.r,n=t.s;if(i.cmpn(1)<0||i.cmp(this.n)>=0)return!1;if(n.cmpn(1)<0||n.cmp(this.n)>=0)return!1;var a,s=n.invm(this.n),o=s.mul(e).umod(this.n),c=s.mul(i).umod(this.n);return this.curve._maxwellTrick?!(a=this.g.jmulAdd(o,r.getPublic(),c)).isInfinity()&&a.eqXToP(i):!(a=this.g.mulAdd(o,r.getPublic(),c)).isInfinity()&&0===a.getX().umod(this.n).cmp(i)},Ul.prototype.recoverPubKey=function(e,t,r,i){Il((3&r)===r,"The recovery param is more than two bits"),t=new Ml(t,i);var n=this.n,a=new Df(e),s=t.r,o=t.s,c=1&r,u=r>>1;if(s.cmp(this.curve.p.umod(this.curve.n))>=0&&u)throw Error("Unable to find sencond key candinate");s=u?this.curve.pointFromX(s.add(this.curve.n),c):this.curve.pointFromX(s,c);var h=t.r.invm(n),d=n.sub(a).mul(h).umod(n),f=o.mul(h).umod(n);return this.g.mulAdd(d,s,f)},Ul.prototype.getKeyRecoveryParam=function(e,t,r,i){if(null!==(t=new Ml(t,i)).recoveryParam)return t.recoveryParam;for(var n=0;n<4;n++){var a;try{a=this.recoverPubKey(e,t,n)}catch(e){continue}if(a.eq(r))return n}throw Error("Unable to find valid recovery factor")};var Tl=zf.assert,zl=zf.parseBytes,ql=zf.cachedProperty;function Ol(e,t){if(this.eddsa=e,t.hasOwnProperty("secret")&&(this._secret=zl(t.secret)),e.isPoint(t.pub))this._pub=t.pub;else if(this._pubBytes=zl(t.pub),this._pubBytes&&33===this._pubBytes.length&&64===this._pubBytes[0]&&(this._pubBytes=this._pubBytes.slice(1,33)),this._pubBytes&&32!==this._pubBytes.length)throw Error("Unknown point compression format")}Ol.fromPublic=function(e,t){return t instanceof Ol?t:new Ol(e,{pub:t})},Ol.fromSecret=function(e,t){return t instanceof Ol?t:new Ol(e,{secret:t})},Ol.prototype.secret=function(){return this._secret},ql(Ol,"pubBytes",(function(){return this.eddsa.encodePoint(this.pub())})),ql(Ol,"pub",(function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())})),ql(Ol,"privBytes",(function(){var e=this.eddsa,t=this.hash(),r=e.encodingLength-1,i=t.slice(0,e.encodingLength);return i[0]&=248,i[r]&=127,i[r]|=64,i})),ql(Ol,"priv",(function(){return this.eddsa.decodeInt(this.privBytes())})),ql(Ol,"hash",(function(){return this.eddsa.hash().update(this.secret()).digest()})),ql(Ol,"messagePrefix",(function(){return this.hash().slice(this.eddsa.encodingLength)})),Ol.prototype.sign=function(e){return Tl(this._secret,"KeyPair can only verify"),this.eddsa.sign(e,this)},Ol.prototype.verify=function(e,t){return this.eddsa.verify(e,t,this)},Ol.prototype.getSecret=function(e){return Tl(this._secret,"KeyPair is public only"),zf.encode(this.secret(),e)},Ol.prototype.getPublic=function(e,t){return zf.encode((t?[64]:[]).concat(this.pubBytes()),e)};var Fl=Ol,Nl=zf.assert,Ll=zf.cachedProperty,jl=zf.parseBytes;function Wl(e,t){this.eddsa=e,"object"!=typeof t&&(t=jl(t)),Array.isArray(t)&&(t={R:t.slice(0,e.encodingLength),S:t.slice(e.encodingLength)}),Nl(t.R&&t.S,"Signature without R or S"),e.isPoint(t.R)&&(this._R=t.R),t.S instanceof Df&&(this._S=t.S),this._Rencoded=Array.isArray(t.R)?t.R:t.Rencoded,this._Sencoded=Array.isArray(t.S)?t.S:t.Sencoded}Ll(Wl,"S",(function(){return this.eddsa.decodeInt(this.Sencoded())})),Ll(Wl,"R",(function(){return this.eddsa.decodePoint(this.Rencoded())})),Ll(Wl,"Rencoded",(function(){return this.eddsa.encodePoint(this.R())})),Ll(Wl,"Sencoded",(function(){return this.eddsa.encodeInt(this.S())})),Wl.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())},Wl.prototype.toHex=function(){return zf.encode(this.toBytes(),"hex").toUpperCase()};var Hl=Wl,Gl=zf.assert,Vl=zf.parseBytes;function $l(e){if(Gl("ed25519"===e,"only tested with ed25519 so far"),!(this instanceof $l))return new $l(e);e=vl[e].curve;this.curve=e,this.g=e.g,this.g.precompute(e.n.bitLength()+1),this.pointClass=e.point().constructor,this.encodingLength=Math.ceil(e.n.bitLength()/8),this.hash=gl.sha512}var Zl=$l;$l.prototype.sign=function(e,t){e=Vl(e);var r=this.keyFromSecret(t),i=this.hashInt(r.messagePrefix(),e),n=this.g.mul(i),a=this.encodePoint(n),s=this.hashInt(a,r.pubBytes(),e).mul(r.priv()),o=i.add(s).umod(this.curve.n);return this.makeSignature({R:n,S:o,Rencoded:a})},$l.prototype.verify=function(e,t,r){e=Vl(e),t=this.makeSignature(t);var i=this.keyFromPublic(r),n=this.hashInt(t.Rencoded(),i.pubBytes(),e),a=this.g.mul(t.S());return t.R().add(i.pub().mul(n)).eq(a)},$l.prototype.hashInt=function(){for(var e=this.hash(),t=0;t0)throw Error("Unknown option: "+r.join(", "));return new gc(e)},e.createMessage=async function({text:e,binary:t,filename:r,date:i=new Date,format:n=(void 0!==e?"utf8":"binary"),...a}){let s=void 0!==e?e:t;if(void 0===s)throw Error("createMessage: must pass options object containing `text` or `binary`");if(e&&!V.isString(e)&&!V.isStream(e))throw Error("createMessage: options.text must be a string or stream");if(t&&!V.isUint8Array(t)&&!V.isStream(t))throw Error("createMessage: options.binary must be a Uint8Array or stream");const o=Object.keys(a);if(o.length>0)throw Error("Unknown option: "+o.join(", "));const c=V.isStream(s);c&&(await E(),s=x(s));const u=new Zs(i);void 0!==e?u.setText(s,n):u.setBytes(s,n),void 0!==r&&u.setFilename(r);const h=new ho;h.push(u);const d=new pc(h);return d.fromStream=c,d},e.decrypt=async function({message:e,decryptionKeys:t,passwords:r,sessionKeys:i,verificationKeys:n,expectSigned:a=!1,format:s="utf8",signature:o=null,date:c=new Date,config:u,...h}){if(Ac(u={...ie,...u}),wc(e),n=Sc(n),t=Sc(t),r=Sc(r),i=Sc(i),h.privateKeys)throw Error("The `privateKeys` option has been removed from openpgp.decrypt, pass `decryptionKeys` instead");if(h.publicKeys)throw Error("The `publicKeys` option has been removed from openpgp.decrypt, pass `verificationKeys` instead");const d=Object.keys(h);if(d.length>0)throw Error("Unknown option: "+d.join(", "));try{const h=await e.decrypt(t,r,i,c,u);n||(n=[]);const d={};if(d.signatures=o?await h.verifyDetached(o,n,c,u):await h.verify(n,c,u),d.data="binary"===s?h.getLiteralData():h.getText(),d.filename=h.getFilename(),Pc(d,e),a){if(0===n.length)throw Error("Verification keys are required to verify message signatures");if(0===d.signatures.length)throw Error("Message is not signed");d.data=C([d.data,W((async()=>{await V.anyPromise(d.signatures.map((e=>e.verified)))}))])}return d.data=await Ec(d.data,e.fromStream,s),d}catch(e){throw V.wrapError("Error decrypting message",e)}},e.decryptKey=async function({privateKey:e,passphrase:t,config:r,...i}){Ac(r={...ie,...r});const n=Object.keys(i);if(n.length>0)throw Error("Unknown option: "+n.join(", "));if(!e.isPrivate())throw Error("Cannot decrypt a public key");const a=e.clone(!0),s=V.isArray(t)?t:[t];try{return await Promise.all(a.getKeys().map((e=>V.anyPromise(s.map((t=>e.keyPacket.decrypt(t))))))),await a.validate(r),a}catch(e){throw a.clearPrivateParams(),V.wrapError("Error decrypting private key",e)}},e.decryptSessionKeys=async function({message:e,decryptionKeys:t,passwords:r,date:i=new Date,config:n,...a}){if(Ac(n={...ie,...n}),wc(e),t=Sc(t),r=Sc(r),a.privateKeys)throw Error("The `privateKeys` option has been removed from openpgp.decryptSessionKeys, pass `decryptionKeys` instead");const s=Object.keys(a);if(s.length>0)throw Error("Unknown option: "+s.join(", "));try{return await e.decryptSessionKeys(t,r,i,n)}catch(e){throw V.wrapError("Error decrypting session keys",e)}},e.encrypt=async function({message:e,encryptionKeys:t,signingKeys:r,passwords:i,sessionKey:n,format:a="armored",signature:s=null,wildcard:o=!1,signingKeyIDs:c=[],encryptionKeyIDs:u=[],date:h=new Date,signingUserIDs:d=[],encryptionUserIDs:f=[],config:l,...p}){if(Ac(l={...ie,...l}),wc(e),_c(a),t=Sc(t),r=Sc(r),i=Sc(i),c=Sc(c),u=Sc(u),d=Sc(d),f=Sc(f),p.detached)throw Error("The `detached` option has been removed from openpgp.encrypt, separately call openpgp.sign instead. Don't forget to remove the `privateKeys` option as well.");if(p.publicKeys)throw Error("The `publicKeys` option has been removed from openpgp.encrypt, pass `encryptionKeys` instead");if(p.privateKeys)throw Error("The `privateKeys` option has been removed from openpgp.encrypt, pass `signingKeys` instead");if(void 0!==p.armor)throw Error("The `armor` option has been removed from openpgp.encrypt, pass `format` instead.");const y=Object.keys(p);if(y.length>0)throw Error("Unknown option: "+y.join(", "));r||(r=[]);const b=e.fromStream;try{if((r.length||s)&&(e=await e.sign(r,s,c,h,d,l)),e=e.compress(await Go("compression",t,h,f,l),l),e=await e.encrypt(t,i,n,o,u,h,f,l),"object"===a)return e;const p="armored"===a;return Ec(p?e.armor(l):e.write(),b,p?"utf8":"binary")}catch(e){throw V.wrapError("Error encrypting message",e)}},e.encryptKey=async function({privateKey:e,passphrase:t,config:r,...i}){Ac(r={...ie,...r});const n=Object.keys(i);if(n.length>0)throw Error("Unknown option: "+n.join(", "));if(!e.isPrivate())throw Error("Cannot encrypt a public key");const a=e.clone(!0),s=a.getKeys(),o=V.isArray(t)?t:Array(s.length).fill(t);if(o.length!==s.length)throw Error("Invalid number of passphrases given for key encryption");try{return await Promise.all(s.map((async(e,t)=>{const{keyPacket:i}=e;await i.encrypt(o[t],r),i.clearPrivateParams()}))),a}catch(e){throw a.clearPrivateParams(),V.wrapError("Error encrypting private key",e)}},e.encryptSessionKey=async function({data:e,algorithm:t,aeadAlgorithm:r,encryptionKeys:i,passwords:n,format:a="armored",wildcard:s=!1,encryptionKeyIDs:o=[],date:c=new Date,encryptionUserIDs:u=[],config:h,...d}){if(Ac(h={...ie,...h}),function(e,t){if(!V.isUint8Array(e))throw Error("Parameter ["+(t||"data")+"] must be of type Uint8Array")}(e),function(e,t){if(!V.isString(e))throw Error("Parameter ["+(t||"data")+"] must be of type String")}(t,"algorithm"),_c(a),i=Sc(i),n=Sc(n),o=Sc(o),u=Sc(u),d.publicKeys)throw Error("The `publicKeys` option has been removed from openpgp.encryptSessionKey, pass `encryptionKeys` instead");const f=Object.keys(d);if(f.length>0)throw Error("Unknown option: "+f.join(", "));try{return xc(await pc.encryptSessionKey(e,t,r,i,n,s,o,c,u,h),a,h)}catch(e){throw V.wrapError("Error encrypting session key",e)}},e.enums=re,e.generateKey=async function({userIDs:e=[],passphrase:t="",type:r="ecc",rsaBits:i=4096,curve:n="curve25519",keyExpirationTime:a=0,date:s=new Date,subkeys:o=[{}],format:c="armored",config:u,...h}){Ac(u={...ie,...u}),e=Sc(e);const d=Object.keys(h);if(d.length>0)throw Error("Unknown option: "+d.join(", "));if(0===e.length)throw Error("UserIDs are required for key generation");if("rsa"===r&&iXo(e.subkeys[r],e)));let r=[No(e,t)];r=r.concat(e.subkeys.map((e=>Fo(e,t))));const i=await Promise.all(r),n=await hc(i[0],i.slice(1),e,t),a=await n.getRevocationCertificate(e.date,t);return n.revocationSignatures=[],{key:n,revocationCertificate:a}}(f,u);return e.getKeys().forEach((({keyPacket:e})=>tc(e,u))),{privateKey:xc(e,c,u),publicKey:xc(e.toPublic(),c,u),revocationCertificate:t}}catch(e){throw V.wrapError("Error generating keypair",e)}},e.generateSessionKey=async function({encryptionKeys:e,date:t=new Date,encryptionUserIDs:r=[],config:i,...n}){if(Ac(i={...ie,...i}),e=Sc(e),r=Sc(r),n.publicKeys)throw Error("The `publicKeys` option has been removed from openpgp.generateSessionKey, pass `encryptionKeys` instead");const a=Object.keys(n);if(a.length>0)throw Error("Unknown option: "+a.join(", "));try{return await pc.generateSessionKey(e,t,r,i)}catch(e){throw V.wrapError("Error generating session key",e)}},e.readCleartextMessage=async function({cleartextMessage:e,config:t,...r}){if(t={...ie,...t},!e)throw Error("readCleartextMessage: must pass options object containing `cleartextMessage`");if(!V.isString(e))throw Error("readCleartextMessage: options.cleartextMessage must be a string");const i=Object.keys(r);if(i.length>0)throw Error("Unknown option: "+i.join(", "));const n=await de(e);if(n.type!==re.armor.signed)throw Error("No cleartext signed message.");const a=await ho.fromBinary(n.data,mc,t);!function(e,t){const r=function(e){const r=e=>t=>e.hashAlgorithm===t;for(let i=0;i0)throw Error("Unknown option: "+n.join(", "));let a;if(e){const{type:t,data:i}=await de(e,r);if(t!==re.armor.publicKey&&t!==re.armor.privateKey)throw Error("Armored text not of type key");a=i}else a=t;return sc(await ho.fromBinary(a,uc,r))},e.readKeys=async function({armoredKeys:e,binaryKeys:t,config:r,...i}){r={...ie,...r};let n=e||t;if(!n)throw Error("readKeys: must pass options object containing `armoredKeys` or `binaryKeys`");if(e&&!V.isString(e))throw Error("readKeys: options.armoredKeys must be a string");if(t&&!V.isUint8Array(t))throw Error("readKeys: options.binaryKeys must be a Uint8Array");const a=Object.keys(i);if(a.length>0)throw Error("Unknown option: "+a.join(", "));if(e){const{type:t,data:i}=await de(e,r);if(t!==re.armor.publicKey&&t!==re.armor.privateKey)throw Error("Armored text not of type key");n=i}const s=[],o=await ho.fromBinary(n,uc,r),c=o.indexOfTag(re.packet.publicKey,re.packet.secretKey);if(0===c.length)throw Error("No key packet found");for(let e=0;e0)throw Error("Unknown option: "+a.join(", "));const s=V.isStream(n);if(s&&(await E(),n=x(n)),e){const{type:e,data:t}=await de(n,r);if(e!==re.armor.message)throw Error("Armored text not of type message");n=t}const o=await ho.fromBinary(n,dc,r),c=new pc(o);return c.fromStream=s,c},e.readPrivateKey=async function({armoredKey:e,binaryKey:t,config:r,...i}){if(r={...ie,...r},!e&&!t)throw Error("readPrivateKey: must pass options object containing `armoredKey` or `binaryKey`");if(e&&!V.isString(e))throw Error("readPrivateKey: options.armoredKey must be a string");if(t&&!V.isUint8Array(t))throw Error("readPrivateKey: options.binaryKey must be a Uint8Array");const n=Object.keys(i);if(n.length>0)throw Error("Unknown option: "+n.join(", "));let a;if(e){const{type:t,data:i}=await de(e,r);if(t!==re.armor.privateKey)throw Error("Armored text not of type private key");a=i}else a=t;const s=await ho.fromBinary(a,uc,r);return new cc(s)},e.readPrivateKeys=async function({armoredKeys:e,binaryKeys:t,config:r}){r={...ie,...r};let i=e||t;if(!i)throw Error("readPrivateKeys: must pass options object containing `armoredKeys` or `binaryKeys`");if(e&&!V.isString(e))throw Error("readPrivateKeys: options.armoredKeys must be a string");if(t&&!V.isUint8Array(t))throw Error("readPrivateKeys: options.binaryKeys must be a Uint8Array");if(e){const{type:t,data:n}=await de(e,r);if(t!==re.armor.privateKey)throw Error("Armored text not of type private key");i=n}const n=[],a=await ho.fromBinary(i,uc,r),s=a.indexOfTag(re.packet.secretKey);if(0===s.length)throw Error("No secret key packet found");for(let e=0;e0)throw Error("Unknown option: "+a.join(", "));if(e){const{type:e,data:t}=await de(n,r);if(e!==re.armor.signature)throw Error("Armored text not of type signature");n=t}const s=await ho.fromBinary(n,qo,r);return new Oo(s)},e.reformatKey=async function({privateKey:e,userIDs:t=[],passphrase:r="",keyExpirationTime:i=0,date:n,format:a="armored",config:s,...o}){Ac(s={...ie,...s}),t=Sc(t);const c=Object.keys(o);if(c.length>0)throw Error("Unknown option: "+c.join(", "));if(0===t.length)throw Error("UserIDs are required for key reformat");const u={privateKey:e,userIDs:t,passphrase:r,keyExpirationTime:i,date:n};try{const{key:e,revocationCertificate:t}=await async function(e,t){e=o(e);const{privateKey:r}=e;if(!r.isPrivate())throw Error("Cannot reformat a public key");if(r.keyPacket.isDummy())throw Error("Cannot reformat a gnu-dummy primary key");if(!r.getKeys().every((({keyPacket:e})=>e.isDecrypted())))throw Error("Key is not decrypted");const i=r.keyPacket;e.subkeys||(e.subkeys=await Promise.all(r.subkeys.map((async e=>{const r=e.keyPacket,n={key:i,bind:r},a=await Lo(e.bindingSignatures,i,re.signature.subkeyBinding,n,null,t).catch((()=>({})));return{sign:a.keyFlags&&a.keyFlags[0]&re.keyFlags.signData}}))));const n=r.subkeys.map((e=>e.keyPacket));if(e.subkeys.length!==n.length)throw Error("Number of subkey options does not match number of subkeys");e.subkeys=e.subkeys.map((t=>o(t,e)));const a=await hc(i,n,e,t),s=await a.getRevocationCertificate(e.date,t);return a.revocationSignatures=[],{key:a,revocationCertificate:s};function o(e,t={}){return e.keyExpirationTime=e.keyExpirationTime||t.keyExpirationTime,e.passphrase=V.isString(e.passphrase)?e.passphrase:t.passphrase,e.date=e.date||t.date,e}}(u,s);return{privateKey:xc(e,a,s),publicKey:xc(e.toPublic(),a,s),revocationCertificate:t}}catch(e){throw V.wrapError("Error reformatting keypair",e)}},e.revokeKey=async function({key:e,revocationCertificate:t,reasonForRevocation:r,date:i=new Date,format:n="armored",config:a,...s}){Ac(a={...ie,...a});const o=Object.keys(s);if(o.length>0)throw Error("Unknown option: "+o.join(", "));try{const s=t?await e.applyRevocationCertificate(t,i,a):await e.revoke(r,i,a);return s.isPrivate()?{privateKey:xc(s,n,a),publicKey:xc(s.toPublic(),n,a)}:{privateKey:null,publicKey:xc(s,n,a)}}catch(e){throw V.wrapError("Error revoking key",e)}},e.sign=async function({message:e,signingKeys:t,format:r="armored",detached:i=!1,signingKeyIDs:n=[],date:a=new Date,signingUserIDs:s=[],config:o,...c}){if(Ac(o={...ie,...o}),vc(e),_c(r),t=Sc(t),n=Sc(n),s=Sc(s),c.privateKeys)throw Error("The `privateKeys` option has been removed from openpgp.sign, pass `signingKeys` instead");if(void 0!==c.armor)throw Error("The `armor` option has been removed from openpgp.sign, pass `format` instead.");const u=Object.keys(c);if(u.length>0)throw Error("Unknown option: "+u.join(", "));if(e instanceof gc&&"binary"===r)throw Error("Cannot return signed cleartext message in binary format");if(e instanceof gc&&i)throw Error("Cannot detach-sign a cleartext message");if(!t||0===t.length)throw Error("No signing keys provided");try{let c;if(c=i?await e.signDetached(t,void 0,n,a,s,o):await e.sign(t,void 0,n,a,s,o),"object"===r)return c;const u="armored"===r;return c=u?c.armor(o):c.write(),i&&(c=T(e.packets.write(),(async(e,t)=>{await Promise.all([R(c,t),L(e).catch((()=>{}))])}))),Ec(c,e.fromStream,u?"utf8":"binary")}catch(e){throw V.wrapError("Error signing message",e)}},e.unarmor=de,e.verify=async function({message:e,verificationKeys:t,expectSigned:r=!1,format:i="utf8",signature:n=null,date:a=new Date,config:s,...o}){if(Ac(s={...ie,...s}),vc(e),t=Sc(t),o.publicKeys)throw Error("The `publicKeys` option has been removed from openpgp.verify, pass `verificationKeys` instead");const c=Object.keys(o);if(c.length>0)throw Error("Unknown option: "+c.join(", "));if(e instanceof gc&&"binary"===i)throw Error("Can't return cleartext message data as binary");if(e instanceof gc&&n)throw Error("Can't verify detached cleartext signature");try{const o={};if(o.signatures=n?await e.verifyDetached(n,t,a,s):await e.verify(t,a,s),o.data="binary"===i?e.getLiteralData():e.getText(),e.fromStream&&Pc(o,e),r){if(0===o.signatures.length)throw Error("Message is not signed");o.data=C([o.data,W((async()=>{await V.anyPromise(o.signatures.map((e=>e.verified)))}))])}return o.data=await Ec(o.data,e.fromStream,i),o}catch(e){throw V.wrapError("Error verifying signed message",e)}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
//# sourceMappingURL=openpgp.min.js.map