>>=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,it)})),Mp=/*#__PURE__*/Object.freeze({__proto__:null,default:xp,__moduleExports:xp});class Cp{constructor(e){if(void 0===e)throw Error("Invalid BigInteger input");this.value=new xp(e)}clone(){const e=new Cp(null);return this.value.copy(e.value),e}iinc(){return this.value.iadd(new xp(1)),this}inc(){return this.clone().iinc()}idec(){return this.value.isub(new xp(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()?xp.red(t.value):xp.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 Cp(this.value.invm(e.value))}gcd(e){return new Cp(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 xp(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 Kp,Dp=/*#__PURE__*/Object.freeze({__proto__:null,default:Cp}),Rp=nt((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}})),Up=nt((function(e,t){var r=t;r.assert=tt,r.toArray=Rp.toArray,r.zero2=Rp.zero2,r.toHex=Rp.toHex,r.encode=Rp.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 xp(e,"hex","le")}})),Ip=function(e){return Kp||(Kp=new Bp(null)),Kp.generate(e)};function Bp(e){this.rand=e}var Tp=Bp;if(Bp.prototype.generate=function(e){return this._rand(e)},Bp.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 jp=Np;function Lp(e,t){this.curve=e,this.type=t,this.precomputed=null}Np.prototype.point=function(){throw Error("Not implemented")},Np.prototype.validate=function(){throw Error("Not implemented")},Np.prototype._fixedNafMul=function(e,t){Op(e.precomputed);var r=e._getDoubles(),i=qp(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];Op(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},Np.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=Fp(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)},Lp.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}]},Hp.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()}},Hp.prototype.pointFromX=function(e,t){(e=new xp(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)},Hp.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)},Hp.prototype._endoWnafMulAdd=function(e,t,r){for(var i=this._endoWnafT1,n=this._endoWnafT2,a=0;a":""},Vp.prototype.isInfinity=function(){return this.inf},Vp.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)},Vp.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)},Vp.prototype.getX=function(){return this.x.fromRed()},Vp.prototype.getY=function(){return this.y.fromRed()},Vp.prototype.mul=function(e){return e=new xp(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)},Vp.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)},Vp.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)},Vp.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))},Vp.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},Vp.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},st($p,jp.BasePoint),Hp.prototype.jpoint=function(e,t,r){return new $p(this,e,t,r)},$p.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)},$p.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},$p.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)},$p.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)},$p.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}},$p.prototype.inspect=function(){return this.isInfinity()?"":""},$p.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},st(Zp,jp);var Yp=Zp;function Xp(e,t,r){jp.BasePoint.call(this,e,"projective"),null===t&&null===r?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new xp(t,16),this.z=new xp(r,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}Zp.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)},st(Xp,jp.BasePoint),Zp.prototype.decodePoint=function(e,t){if(33===(e=Up.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)},Zp.prototype.point=function(e,t){return new Xp(this,e,t)},Zp.prototype.pointFromJSON=function(e){return Xp.fromJSON(this,e)},Xp.prototype.precompute=function(){},Xp.prototype._encode=function(e){var t=this.curve.p.byteLength();return e?[64].concat(this.getX().toArray("le",t)):this.getX().toArray("be",t)},Xp.fromJSON=function(e,t){return new Xp(e,t[0],t[1]||e.one)},Xp.prototype.inspect=function(){return this.isInfinity()?"":""},Xp.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},Xp.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)},Xp.prototype.add=function(){throw Error("Not supported on Montgomery curve")},Xp.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)},Xp.prototype.mul=function(e){for(var t=(e=new xp(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},Xp.prototype.mulAdd=function(){throw Error("Not supported on Montgomery curve")},Xp.prototype.jumlAdd=function(){throw Error("Not supported on Montgomery curve")},Xp.prototype.eq=function(e){return 0===this.getX().cmp(e.getX())},Xp.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},Xp.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var Qp=Up.assert;function Jp(e){this.twisted=1!=(0|e.a),this.mOneA=this.twisted&&-1==(0|e.a),this.extended=this.mOneA,jp.call(this,"edwards",e),this.a=new xp(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new xp(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new xp(e.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),Qp(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|e.c)}st(Jp,jp);var ey=Jp;function ty(e,t,r,i,n){jp.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 xp(t,16),this.y=new xp(r,16),this.z=i?new xp(i,16):this.curve.one,this.t=n&&new xp(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()))))}Jp.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)},Jp.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)},Jp.prototype.jpoint=function(e,t,r,i){return this.point(e,t,r,i)},Jp.prototype.pointFromX=function(e,t){(e=new xp(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)},Jp.prototype.pointFromY=function(e,t){(e=new xp(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)},Jp.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)},st(ty,jp.BasePoint),Jp.prototype.pointFromJSON=function(e){return ty.fromJSON(this,e)},Jp.prototype.point=function(e,t,r,i){return new ty(this,e,t,r,i)},ty.fromJSON=function(e,t){return new ty(e,t[0],t[1],t[2])},ty.prototype.inspect=function(){return this.isInfinity()?"":""},ty.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&(0===this.y.cmp(this.z)||this.zOne&&0===this.y.cmp(this.curve.c))},ty.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)},ty.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)},ty.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},ty.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)},ty.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)},ty.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},ty.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},ty.prototype.mulAdd=function(e,t,r){return this.curve._wnafMulAdd(1,[this,t],[e,r],2,!1)},ty.prototype.jmulAdd=function(e,t,r){return this.curve._wnafMulAdd(1,[this,t],[e,r],2,!0)},ty.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},ty.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},ty.prototype.getX=function(){return this.normalize(),this.x.fromRed()},ty.prototype.getY=function(){return this.normalize(),this.y.fromRed()},ty.prototype.eq=function(e){return this===e||0===this.getX().cmp(e.getX())&&0===this.getY().cmp(e.getY())},ty.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}},ty.prototype.toP=ty.prototype.normalize,ty.prototype.mixedAdd=ty.prototype.add;var ry=nt((function(e,t){var r=t;r.base=jp,r.short=Gp,r.mont=Yp,r.edwards=ey})),iy=yt.rotl32,ny=yt.sum32,ay=yt.sum32_5,sy=St.ft_1,oy=gt.BlockHash,cy=[1518500249,1859775393,2400959708,3395469782];function uy(){if(!(this instanceof uy))return new uy;oy.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=Array(80)}yt.inherits(uy,oy);var hy=uy;uy.blockSize=512,uy.outSize=160,uy.hmacStrength=80,uy.padLength=64,uy.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()),tt(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 gy=my;my.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},my.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=Rp.toArray(r,i||"hex"),this._update(r));for(var n=[];n.length"};var ky=Up.assert;function Ay(e,t){if(e instanceof Ay)return e;this._importDER(e,t)||(ky(e.r&&e.s,"Signature without r or s"),this.r=new xp(e.r,16),this.s=new xp(e.s,16),void 0===e.recoveryParam?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}var Sy=Ay;function Ey(){this.place=0}function Py(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)}}Ay.prototype._importDER=function(e,t){e=Up.toArray(e,t);var r=new Ey;if(48!==e[r.place++])return!1;if(Py(e,r)+r.place!==e.length)return!1;if(2!==e[r.place++])return!1;var i=Py(e,r),n=e.slice(r.place,i+r.place);if(r.place+=i,2!==e[r.place++])return!1;var a=Py(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 xp(n),this.s=new xp(s),this.recoveryParam=null,!0},Ay.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=xy(t),r=xy(r);!(r[0]||128&r[1]);)r=r.slice(1);var i=[2];My(i,t.length),(i=i.concat(t)).push(2),My(i,r.length);var n=i.concat(r),a=[48];return My(a,n.length),a=a.concat(n),Up.encode(a,e)};var Cy=Up.assert;function Ky(e){if(!(this instanceof Ky))return new Ky(e);"string"==typeof e&&(Cy(by.hasOwnProperty(e),"Unknown curve "+e),e=by[e]),e instanceof by.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 Dy=Ky;Ky.prototype.keyPair=function(e){return new _y(this,e)},Ky.prototype.keyFromPrivate=function(e,t){return _y.fromPrivate(this,e,t)},Ky.prototype.keyFromPublic=function(e,t){return _y.fromPublic(this,e,t)},Ky.prototype.genKeyPair=function(e){e||(e={});var t=new gy({hash:this.hash,pers:e.pers,persEnc:e.persEnc||"utf8",entropy:e.entropy||Ip(this.hash.hmacStrength),entropyEnc:e.entropy&&e.entropyEnc||"utf8",nonce:this.n.toArray()});if("mont"===this.curve.type){var r=new xp(t.generate(32));return this.keyFromPrivate(r)}for(var i=this.n.byteLength(),n=this.n.sub(new xp(2));;){if(!((r=new xp(t.generate(i))).cmp(n)>0))return r.iaddn(1),this.keyFromPrivate(r)}},Ky.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},Ky.prototype.truncateMsg=function(e){var t;return e instanceof Uint8Array?(t=8*e.byteLength,e=this._truncateToN(new xp(e,16),!1,t)):"string"==typeof e?(t=4*e.length,e=this._truncateToN(new xp(e,16),!1,t)):e=this._truncateToN(new xp(e,16)),e},Ky.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 gy({hash:this.hash,entropy:a,nonce:s,pers:i.pers,persEnc:i.persEnc||"utf8"}),c=this.n.sub(new xp(1)),u=0;;u++){var h=i.k?i.k(u):new xp(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 Sy({r:l,s:p,recoveryParam:y})}}}}}},Ky.prototype.verify=function(e,t,r,i){return r=this.keyFromPublic(r,i),t=new Sy(t,"hex"),this._verify(this.truncateMsg(e),t,r)||this._verify(this._truncateToN(new xp(e,16)),t,r)},Ky.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)},Ky.prototype.recoverPubKey=function(e,t,r,i){Cy((3&r)===r,"The recovery param is more than two bits"),t=new Sy(t,i);var n=this.n,a=new xp(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)},Ky.prototype.getKeyRecoveryParam=function(e,t,r,i){if(null!==(t=new Sy(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 Ry=Up.assert,Uy=Up.parseBytes,Iy=Up.cachedProperty;function By(e,t){if(this.eddsa=e,t.hasOwnProperty("secret")&&(this._secret=Uy(t.secret)),e.isPoint(t.pub))this._pub=t.pub;else if(this._pubBytes=Uy(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")}By.fromPublic=function(e,t){return t instanceof By?t:new By(e,{pub:t})},By.fromSecret=function(e,t){return t instanceof By?t:new By(e,{secret:t})},By.prototype.secret=function(){return this._secret},Iy(By,"pubBytes",(function(){return this.eddsa.encodePoint(this.pub())})),Iy(By,"pub",(function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())})),Iy(By,"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})),Iy(By,"priv",(function(){return this.eddsa.decodeInt(this.privBytes())})),Iy(By,"hash",(function(){return this.eddsa.hash().update(this.secret()).digest()})),Iy(By,"messagePrefix",(function(){return this.hash().slice(this.eddsa.encodingLength)})),By.prototype.sign=function(e){return Ry(this._secret,"KeyPair can only verify"),this.eddsa.sign(e,this)},By.prototype.verify=function(e,t){return this.eddsa.verify(e,t,this)},By.prototype.getSecret=function(e){return Ry(this._secret,"KeyPair is public only"),Up.encode(this.secret(),e)},By.prototype.getPublic=function(e,t){return Up.encode((t?[64]:[]).concat(this.pubBytes()),e)};var Ty=By,zy=Up.assert,qy=Up.cachedProperty,Fy=Up.parseBytes;function Oy(e,t){this.eddsa=e,"object"!=typeof t&&(t=Fy(t)),Array.isArray(t)&&(t={R:t.slice(0,e.encodingLength),S:t.slice(e.encodingLength)}),zy(t.R&&t.S,"Signature without R or S"),e.isPoint(t.R)&&(this._R=t.R),t.S instanceof xp&&(this._S=t.S),this._Rencoded=Array.isArray(t.R)?t.R:t.Rencoded,this._Sencoded=Array.isArray(t.S)?t.S:t.Sencoded}qy(Oy,"S",(function(){return this.eddsa.decodeInt(this.Sencoded())})),qy(Oy,"R",(function(){return this.eddsa.decodePoint(this.Rencoded())})),qy(Oy,"Rencoded",(function(){return this.eddsa.encodePoint(this.R())})),qy(Oy,"Sencoded",(function(){return this.eddsa.encodeInt(this.S())})),Oy.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())},Oy.prototype.toHex=function(){return Up.encode(this.toBytes(),"hex").toUpperCase()};var Ny=Oy,jy=Up.assert,Ly=Up.parseBytes;function Wy(e){if(jy("ed25519"===e,"only tested with ed25519 so far"),!(this instanceof Wy))return new Wy(e);e=by[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=py.sha512}var Hy=Wy;Wy.prototype.sign=function(e,t){e=Ly(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})},Wy.prototype.verify=function(e,t,r){e=Ly(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)},Wy.prototype.hashInt=function(){for(var e=this.hash(),t=0;t0)throw Error("Unknown option: "+r.join(", "));return new ph(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&&!Z.isString(e)&&!Z.isStream(e))throw Error("createMessage: options.text must be a string or stream");if(t&&!Z.isUint8Array(t)&&!Z.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=Z.isStream(s);c&&(await P(),s=M(s));const u=new Qc(i);void 0!==e?u.setText(s,ne.write(ne.literal,n)):u.setBytes(s,ne.write(ne.literal,n)),void 0!==r&&u.setFilename(r);const h=new au;h.push(u);const d=new hh(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(wh(u={...ae,...u}),yh(e),n=vh(n),t=vh(t),r=vh(r),i=vh(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(),kh(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=K([d.data,H((async()=>{await Z.anyPromise(d.signatures.map((e=>e.verified)))}))])}return d.data=await _h(d.data,e.fromStream,s),d}catch(e){throw Z.wrapError("Error decrypting message",e)}},e.decryptKey=async function({privateKey:e,passphrase:t,config:r,...i}){wh(r={...ae,...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=Z.isArray(t)?t:[t];try{return await Promise.all(a.getKeys().map((e=>Z.anyPromise(s.map((t=>e.keyPacket.decrypt(t))))))),await a.validate(r),a}catch(e){throw a.clearPrivateParams(),Z.wrapError("Error decrypting private key",e)}},e.decryptSessionKeys=async function({message:e,decryptionKeys:t,passwords:r,date:i=new Date,config:n,...a}){if(wh(n={...ae,...n}),yh(e),t=vh(t),r=vh(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 Z.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=[],signatureNotations:l=[],config:p,...y}){if(wh(p={...ae,...p}),yh(e),mh(a),t=vh(t),r=vh(r),i=vh(i),c=vh(c),u=vh(u),d=vh(d),f=vh(f),l=vh(l),y.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(y.publicKeys)throw Error("The `publicKeys` option has been removed from openpgp.encrypt, pass `encryptionKeys` instead");if(y.privateKeys)throw Error("The `privateKeys` option has been removed from openpgp.encrypt, pass `signingKeys` instead");if(void 0!==y.armor)throw Error("The `armor` option has been removed from openpgp.encrypt, pass `format` instead.");const b=Object.keys(y);if(b.length>0)throw Error("Unknown option: "+b.join(", "));r||(r=[]);const m=e.fromStream;try{if((r.length||s)&&(e=await e.sign(r,s,c,h,d,l,p)),e=e.compress(await Ou("compression",t,h,f,p),p),e=await e.encrypt(t,i,n,o,u,h,f,p),"object"===a)return e;const y="armored"===a;return _h(y?e.armor(p):e.write(),m,y?"utf8":"binary")}catch(e){throw Z.wrapError("Error encrypting message",e)}},e.encryptKey=async function({privateKey:e,passphrase:t,config:r,...i}){wh(r={...ae,...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=Z.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(),Z.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(wh(h={...ae,...h}),function(e,t){if(!Z.isUint8Array(e))throw Error("Parameter ["+(t||"data")+"] must be of type Uint8Array")}(e),function(e,t){if(!Z.isString(e))throw Error("Parameter ["+(t||"data")+"] must be of type String")}(t,"algorithm"),mh(a),i=vh(i),n=vh(n),o=vh(o),u=vh(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(", "));if(!(i&&0!==i.length||n&&0!==n.length))throw Error("No encryption keys or passwords provided.");try{return Ah(await hh.encryptSessionKey(e,t,r,i,n,s,o,c,u,h),a,h)}catch(e){throw Z.wrapError("Error encrypting session key",e)}},e.enums=ne,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}){wh(u={...ae,...u}),e=vh(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&&iHu(e.subkeys[r],e)));let r=[Bu(e,t)];r=r.concat(e.subkeys.map((e=>Iu(e,t))));const i=await Promise.all(r),n=await sh(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})=>Zu(e,u))),{privateKey:Ah(e,c,u),publicKey:Ah(e.toPublic(),c,u),revocationCertificate:t}}catch(e){throw Z.wrapError("Error generating keypair",e)}},e.generateSessionKey=async function({encryptionKeys:e,date:t=new Date,encryptionUserIDs:r=[],config:i,...n}){if(wh(i={...ae,...i}),e=vh(e),r=vh(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 hh.generateSessionKey(e,t,r,i)}catch(e){throw Z.wrapError("Error generating session key",e)}},e.readCleartextMessage=async function({cleartextMessage:e,config:t,...r}){if(t={...ae,...t},!e)throw Error("readCleartextMessage: must pass options object containing `cleartextMessage`");if(!Z.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 le(e);if(n.type!==ne.armor.signed)throw Error("No cleartext signed message.");const a=await au.fromBinary(n.data,lh,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 le(e,r);if(t!==ne.armor.publicKey&&t!==ne.armor.privateKey)throw Error("Armored text not of type key");a=i}else a=t;return ah(await au.fromBinary(a,nh,r))},e.readKeys=async function({armoredKeys:e,binaryKeys:t,config:r,...i}){r={...ae,...r};let n=e||t;if(!n)throw Error("readKeys: must pass options object containing `armoredKeys` or `binaryKeys`");if(e&&!Z.isString(e))throw Error("readKeys: options.armoredKeys must be a string");if(t&&!Z.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 le(e,r);if(t!==ne.armor.publicKey&&t!==ne.armor.privateKey)throw Error("Armored text not of type key");n=i}const s=[],o=await au.fromBinary(n,nh,r),c=o.indexOfTag(ne.packet.publicKey,ne.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=Z.isStream(n);if(s&&(await P(),n=M(n)),e){const{type:e,data:t}=await le(n,r);if(e!==ne.armor.message)throw Error("Armored text not of type message");n=t}const o=await au.fromBinary(n,oh,r),c=new hh(o);return c.fromStream=s,c},e.readPrivateKey=async function({armoredKey:e,binaryKey:t,config:r,...i}){if(r={...ae,...r},!e&&!t)throw Error("readPrivateKey: must pass options object containing `armoredKey` or `binaryKey`");if(e&&!Z.isString(e))throw Error("readPrivateKey: options.armoredKey must be a string");if(t&&!Z.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 le(e,r);if(t!==ne.armor.privateKey)throw Error("Armored text not of type private key");a=i}else a=t;const s=await au.fromBinary(a,nh,r);return new ih(s)},e.readPrivateKeys=async function({armoredKeys:e,binaryKeys:t,config:r}){r={...ae,...r};let i=e||t;if(!i)throw Error("readPrivateKeys: must pass options object containing `armoredKeys` or `binaryKeys`");if(e&&!Z.isString(e))throw Error("readPrivateKeys: options.armoredKeys must be a string");if(t&&!Z.isUint8Array(t))throw Error("readPrivateKeys: options.binaryKeys must be a Uint8Array");if(e){const{type:t,data:n}=await le(e,r);if(t!==ne.armor.privateKey)throw Error("Armored text not of type private key");i=n}const n=[],a=await au.fromBinary(i,nh,r),s=a.indexOfTag(ne.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 le(n,r);if(e!==ne.armor.signature)throw Error("Armored text not of type signature");n=t}const s=await au.fromBinary(n,Ru,r);return new Uu(s)},e.reformatKey=async function({privateKey:e,userIDs:t=[],passphrase:r,keyExpirationTime:i=0,date:n,format:a="armored",config:s,...o}){wh(s={...ae,...s}),t=vh(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 Tu(e.bindingSignatures,i,ne.signature.subkeyBinding,n,null,t).catch((()=>({})));return{sign:a.keyFlags&&a.keyFlags[0]&ne.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 sh(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=Z.isString(e.passphrase)?e.passphrase:t.passphrase,e.date=e.date||t.date,e}}(u,s);return{privateKey:Ah(e,a,s),publicKey:Ah(e.toPublic(),a,s),revocationCertificate:t}}catch(e){throw Z.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}){wh(a={...ae,...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:Ah(s,n,a),publicKey:Ah(s.toPublic(),n,a)}:{privateKey:null,publicKey:Ah(s,n,a)}}catch(e){throw Z.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=[],signatureNotations:o=[],config:c,...u}){if(wh(c={...ae,...c}),bh(e),mh(r),t=vh(t),n=vh(n),s=vh(s),o=vh(o),u.privateKeys)throw Error("The `privateKeys` option has been removed from openpgp.sign, pass `signingKeys` instead");if(void 0!==u.armor)throw Error("The `armor` option has been removed from openpgp.sign, pass `format` instead.");const h=Object.keys(u);if(h.length>0)throw Error("Unknown option: "+h.join(", "));if(e instanceof ph&&"binary"===r)throw Error("Cannot return signed cleartext message in binary format");if(e instanceof ph&&i)throw Error("Cannot detach-sign a cleartext message");if(!t||0===t.length)throw Error("No signing keys provided");try{let u;if(u=i?await e.signDetached(t,void 0,n,a,s,o,c):await e.sign(t,void 0,n,a,s,o,c),"object"===r)return u;const h="armored"===r;return u=h?u.armor(c):u.write(),i&&(u=z(e.packets.write(),(async(e,t)=>{await Promise.all([U(u,t),L(e).catch((()=>{}))])}))),_h(u,e.fromStream,h?"utf8":"binary")}catch(e){throw Z.wrapError("Error signing message",e)}},e.unarmor=le,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(wh(s={...ae,...s}),bh(e),t=vh(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 ph&&"binary"===i)throw Error("Can't return cleartext message data as binary");if(e instanceof ph&&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&&kh(o,e),r){if(0===o.signatures.length)throw Error("Message is not signed");o.data=K([o.data,H((async()=>{await Z.anyPromise(o.signatures.map((e=>e.verified)))}))])}return o.data=await _h(o.data,e.fromStream,i),o}catch(e){throw Z.wrapError("Error verifying signed message",e)}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
-//# sourceMappingURL=openpgp.min.js.map
diff --git a/main.js b/main.js
index e58f622..f948dfe 100644
--- a/main.js
+++ b/main.js
@@ -11,8 +11,6 @@ var defaultsettings =
titlebydefault: false,
linksinnewtab: true,
colors: true,
- password: "",
- sync: false,
tagsinlists: true,
uselinkpopup: true,
downloadextension: ".md"
@@ -31,7 +29,6 @@ var workerid = null;
var backup = "";
var settings = null;
var tags = null;
-var pending = {};
var commands = [
{
@@ -195,14 +192,6 @@ var commands = [
hint: "Insert text in todo",
action: promptinserttodo
},
-{
- hint: "Edit pgp keys",
- action: editpgpkeys
-},
-{
- hint: "Decrypt note",
- action: decryptnote
-},
{
hint: "Replace",
shortcut: "ctrl+h",
@@ -314,56 +303,6 @@ function seteditorcontent(content)
resize();
}
-function encryptstring(str)
-{
- var key = localStorage.getItem("pgpkeys").split("-----BEGIN PGP PRIVATE KEY BLOCK-----")[0];
- var publicKey = null;
- return openpgp.readKey({ armoredKey: key })
- .then(res =>
- {
- publicKey = res;
- return openpgp.createMessage({ text: str });
- })
- .then(message =>
- {
- return openpgp.encrypt({
- message: message,
- encryptionKeys: publicKey });
- });
-}
-
-function decryptstring(str)
-{
- if (!str.startsWith("-----BEGIN PGP MESSAGE-----"))
- {
- // console.log(str + ": string is not encrypted");
- return Promise.resolve(str);
- }
-
- var key = localStorage.getItem("pgpkeys").split("-----END PGP PUBLIC KEY BLOCK-----")[1];
- var privateKey = null;
- return openpgp.readKey({ armoredKey: key })
- .then(res =>
- {
- privateKey = res;
- return openpgp.readMessage({ armoredMessage: str })
- })
- .then(message =>
- {
- return openpgp.decrypt({
- message: message,
- decryptionKeys: privateKey });
- })
- .then(decrypted =>
- {
- const chunks = [];
- for (const chunk of decrypted.data) {
- chunks.push(chunk);
- }
- return chunks.join('');
- })
-}
-
function getrangecontent(range)
{
return md.value.substring(range.start, range.end);
@@ -377,44 +316,12 @@ function currentrange()
};
}
-function pushitem(key, value)
-{
- unsavedmark.hidden = false;
- pending[key] = true;
- var name = metadata && metadata[key] ? metadata[key].title : key;
-
- queryremote({action: "push", name: key, data: value})
- .then( () =>
- {
- console.log("'" + name + "' pushed to server");
- delete pending[key];
- })
- .catch( err =>
- {
- console.error("error while pushing '" + name + "': " + err);
- showtemporaryinfo(msg);
- setTimeout( () =>
- {
- serialize(key, value);
- }, settings.savedelay);
- })
- .finally( () =>
- {
- unsavedmark.hidden = Object.keys(pending) == 0;
- });
-}
-
function serialize(key, value)
{
localStorage.setItem(key, value);
var name = metadata && metadata[key] ? metadata[key].title : key;
console.log("'" + name + "' serialized locally");
-
- if (settings.sync)
- {
- pushitem(key, value);
- }
}
function createsubnote()
@@ -510,8 +417,6 @@ function showinfo()
var tags = gettags(md.value);
showtemporaryinfo(
[
- "sync: " + (settings.sync ? "en" : "dis") + "abled",
- "pending: " + Object.keys(pending).join(),
"title: " + title.value,
"line count: " + md.value.split("\n").length,
"word count: " + getwords(),
@@ -903,21 +808,6 @@ function changesetting()
});
}
-function decryptnote()
-{
- decryptstring(md.value)
- .then(decrypted =>
- {
- seteditorcontent(decrypted);
- resize();
- });
-}
-
-function editpgpkeys()
-{
- bind("pgpkeys", localStorage.getItem("pgpkeys") || "");
-}
-
function showtemporaryinfo(info)
{
alert(info);
@@ -1338,102 +1228,6 @@ function migratelegacystorage()
}
}
-function pushall()
-{
- var index = JSON.parse(localStorage.getItem("index"));
- var list = [queryremote({action: "push", name: "index", data: localStorage.getItem("index")})];
- Object.keys(index).forEach(guid =>
- {
- list.push(queryremote({action: "push", name: guid, data: localStorage.getItem(guid)}));
- });
-
- return Promise.all(list);
-}
-
-function fetchandserialize(guid)
-{
- var name = (metadata && metadata[guid]) ? metadata[guid] : guid;
- console.log("fetching '" + name + "'");
- return queryremote({action: "fetch", name: guid})
- .then(content =>
- {
- localStorage.setItem(guid, content);
- console.log("'" + name + "' fetched and serialized");
- });
-}
-
-function fetch()
-{
- return new Promise(function(resolve)
- {
- if (settings.sync)
- {
- var pgpkeys = localStorage.getItem("pgpkeys");
- if (!pgpkeys)
- {
- loadstorage();
- editpgpkeys();
- showtemporaryinfo("Pgp key empty or invalid. Enter PGP keys and refresh.");
- }
- else
- {
- queryremote({action: "fetch", name: "index"})
- .then(filecontent =>
- {
- if (!filecontent)
- {
- if (confirm("No remote index found. Init remote now?"))
- {
- pushall().then(resolve);
- }
- else
- {
- resolve();
- }
- }
- else
- {
- var localindex = JSON.parse(localStorage.getItem("index"));
- var remoteindex = JSON.parse(filecontent);
-
- var list = [];
- Object.keys(remoteindex).forEach(guid =>
- {
- if (!localindex[guid] || localindex[guid].lastchanged < remoteindex[guid].lastchanged)
- {
- list.push(fetchandserialize(guid));
- }
- });
-
- Promise.all(list).then( () =>
- {
- localStorage.setItem("index", JSON.stringify(remoteindex));
- resolve();
- });
- }
- })
- .catch(err =>
- {
- if (err == "error: authent")
- {
- settings.password = prompt("Password: ", settings.password);
- savesettings();
- init();
- }
- else
- {
- showtemporaryinfo(err);
- }
- });
- }
- }
- else
- {
- resolve();
- }
- });
-}
-
function init()
{
migratelegacystorage();
@@ -1445,94 +1239,19 @@ function init()
initsnippets();
- fetch()
- .then( () =>
- {
- loadstorage();
+ loadstorage();
- if (issplit())
+ if (issplit())
+ {
+ if (settings.defaultpreviewinsplit && name == "right")
{
- if (settings.defaultpreviewinsplit && name == "right")
- {
- togglepreview();
- }
- else if (name == "left")
- {
- md.focus();
- }
+ togglepreview();
}
- });
-}
-
-function encryptdata(params)
-{
- if (params.data)
- {
- return encryptstring(params.data)
- .then(encrypted =>
+ else if (name == "left")
{
- params.data = encrypted;
- return Promise.resolve(params);
- });
+ md.focus();
+ }
}
- else
- {
- return Promise.resolve(params);
- }
-}
-
-function queryremote(params)
-{
- return encryptdata(params)
- .then(encparams =>
- {
- return new Promise ( (resolve, reject) =>
- {
- encparams.password = settings.password;
-
- var paramlist = [];
- for (var i in encparams)
- {
- paramlist.push(i + "=" + encodeURIComponent(encparams[i]));
- }
-
- var xhr = new XMLHttpRequest();
- xhr.open("POST", "handler.php");
- xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
-
- xhr.onerror = function()
- {
- reject("XMLHttpRequest error");
- }
-
- xhr.onload = function()
- {
- if (xhr.status !== 200)
- {
- reject("Http status " + xhr.status);
- }
- else
- {
- decryptstring(xhr.responseText)
- .then(decrypted =>
- {
- if (decrypted.startsWith("error: "))
- {
- reject(decrypted);
- }
- else
- {
- resolve(decrypted);
- }
- });
- }
- }
-
- var paramstring = paramlist.join("&");
- console.log("http '" + encparams.action + "' request length: " + formatsize(paramstring.length));
- xhr.send(paramstring);
- });
- });
}
function getlinesrange()
@@ -1741,7 +1460,7 @@ function commandpalette()
return {
prefix: "setting ",
text: s,
- suffix: s == "password" ? null : [settings[s]]
+ suffix: [settings[s]]
};
})))
.then(selected =>
@@ -1935,12 +1654,7 @@ function flush()
savesettings();
loadsettings();
}
- else if (title.value == "pgpkeys")
- {
- localStorage.setItem("pgpkeys", md.value);
- }
-
- unsavedmark.hidden = Object.keys(pending).length == 0;
+ unsavedmark.hidden = true;
}
function escapeHtml(unsafe) {
@@ -2243,7 +1957,6 @@ function showhelp()
help.push("## Libs");
help.push("[Showdown](https://showdownjs.com/)");
help.push("[vis-network](https://visjs.org/)");
- help.push("[openpgpjs](https://openpgpjs.org/)");
help.push("[jszip](https://stuk.github.io/jszip/)");
help.push("[FileSaver](http://eligrey.com)");
diff --git a/readme.md b/readme.md
index 46755be..51014f9 100644
--- a/readme.md
+++ b/readme.md
@@ -2,41 +2,21 @@
## Getting started
-Launch index.html from your web server or try https://notes.ouvaton.org.
+Call index.html or try https://notes.ouvaton.org.
Your notes are stored in your browser local storage.
+You can import a folder of markdown files.
+
## Usage
* command palette: ctrl+shift+p
* notes list: ctrl+p
-## Sync feature
-
-To sync your notes in the cloud:
-
-* put the source files on your php server
-* browse index.html
-* paste your public and private PGP keys as a single file (passphrase is not supported)
-* refresh the page
-
-Your data is always encrypted before reaching the server.
-
-To protect your data file access by a password, edit settings.php and change `$password` variable. The password is sent from browser to server through a post http query, encrypted with ssl if enabled. It is stored unencrypted in your browser local storage and in the settings.php file on server side.
-
-## Cli tool
-
-```
-cd cli
-python3 app.py
-```
-
-Requires python3, curl, gnupg and a text editor.
-
## Web clipper
Add `clipper\clipper.js` as bookmarklet on your web browser bookmark toolbar. Click to add current URL to a note named *todo*.
## Export your data
-You can download your notes in a single json data file, or as flat markdown files in a zip archive.
+You can download your notes as flat markdown files in a zip archive.
diff --git a/settingssample.php b/settingssample.php
deleted file mode 100644
index bb1c1a8..0000000
--- a/settingssample.php
+++ /dev/null
@@ -1,4 +0,0 @@
-
\ No newline at end of file