/*! OpenPGP.js v5.8.0 - 2023-08-14 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */ "undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;import{c as e,m as f,i as d,u as t,b as a,d as c,_ as r,e as b,f as i,g as n,r as s}from"./openpgp.min.mjs";import o from"./bn.min.mjs";var h,u=e((function(e,f){var d=f;function t(e){return 1===e.length?"0"+e:e}function a(e){for(var f="",d=0;d>8,r=255&a;c?d.push(c,r):d.push(r)}return d},d.zero2=t,d.toHex=a,d.encode=function(e,f){return"hex"===f?a(e):e}})),p=e((function(e,d){var t=d;t.assert=f,t.toArray=u.toArray,t.zero2=u.zero2,t.toHex=u.toHex,t.encode=u.encode,t.getNAF=function(e,f){for(var d=[],t=1<=0;){var c;if(a.isOdd()){var r=a.andln(t-1);c=r>(t>>1)-1?(t>>1)-r:r,a.isubn(c)}else c=0;d.push(c);for(var b=0!==a.cmpn(0)&&0===a.andln(t-1)?f+1:1,i=1;i0||f.cmpn(-a)>0;){var c,r,b,i=e.andln(3)+t&3,n=f.andln(3)+a&3;if(3===i&&(i=-1),3===n&&(n=-1),0==(1&i))c=0;else c=3!==(b=e.andln(7)+t&7)&&5!==b||2!==n?i:-i;if(d[0].push(c),0==(1&n))r=0;else r=3!==(b=f.andln(7)+a&7)&&5!==b||2!==i?n:-n;d[1].push(r),2*t===c+1&&(t=1-t),2*a===r+1&&(a=1-a),e.iushrn(1),f.iushrn(1)}return d},t.cachedProperty=function(e,f,d){var t="_"+f;e.prototype[f]=function(){return void 0!==this[t]?this[t]:this[t]=d.call(this)}},t.parseBytes=function(e){return"string"==typeof e?t.toArray(e,"hex"):e},t.intFromLE=function(e){return new o(e,"hex","le")}})),l=function(e){return h||(h=new y(null)),h.generate(e)};function y(e){this.rand=e}var v=y;if(y.prototype.generate=function(e){return this._rand(e)},y.prototype._rand=function(e){if(this.rand.getBytes)return this.rand.getBytes(e);for(var f=new Uint8Array(e),d=0;d0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var I=w;function E(e,f){this.curve=e,this.type=f,this.precomputed=null}w.prototype.point=function(){throw Error("Not implemented")},w.prototype.validate=function(){throw Error("Not implemented")},w.prototype._fixedNafMul=function(e,f){S(e.precomputed);var d=e._getDoubles(),t=A(f,1),a=(1<=r;f--)b=(b<<1)+t[f];c.push(b)}for(var i=this.jpoint(null,null,null),n=this.jpoint(null,null,null),s=a;s>0;s--){for(r=0;r=0;b--){for(f=0;b>=0&&0===c[b];b--)f++;if(b>=0&&f++,r=r.dblp(f),b<0)break;var i=c[b];S(0!==i),r="affine"===e.type?i>0?r.mixedAdd(a[i-1>>1]):r.mixedAdd(a[-i-1>>1].neg()):i>0?r.add(a[i-1>>1]):r.add(a[-i-1>>1].neg())}return"affine"===e.type?r.toP():r},w.prototype._wnafMulAdd=function(e,f,d,t,a){for(var c=this._wnafT1,r=this._wnafT2,b=this._wnafT3,i=0,n=0;n=1;n-=2){var o=n-1,h=n;if(1===c[o]&&1===c[h]){var u=[f[o],null,null,f[h]];0===f[o].y.cmp(f[h].y)?(u[1]=f[o].add(f[h]),u[2]=f[o].toJ().mixedAdd(f[h].neg())):0===f[o].y.cmp(f[h].y.redNeg())?(u[1]=f[o].toJ().mixedAdd(f[h]),u[2]=f[o].add(f[h].neg())):(u[1]=f[o].toJ().mixedAdd(f[h]),u[2]=f[o].toJ().mixedAdd(f[h].neg()));var p=[-3,-1,-5,-7,0,7,5,1,3],l=g(d[o],d[h]);i=Math.max(l[0].length,i),b[o]=Array(i),b[h]=Array(i);for(var y=0;y=0;n--){for(var I=0;n>=0;){var E=!0;for(y=0;y=0&&I++,S=S.dblp(I),n<0)break;for(y=0;y0?x=r[y][M-1>>1]:M<0&&(x=r[y][-M-1>>1].neg()),S="affine"===x.type?S.mixedAdd(x):S.add(x))}}for(n=0;n=Math.ceil((e.bitLength()+1)/f.step)},E.prototype._getDoubles=function(e,f){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var d=[this],t=this,a=0;a=0&&(c=f,r=d),t.negative&&(t=t.neg(),a=a.neg()),c.negative&&(c=c.neg(),r=r.neg()),[{a:t,b:a},{a:c,b:r}]},M.prototype._endoSplit=function(e){var f=this.endo.basis,d=f[0],t=f[1],a=t.b.mul(e).divRound(this.n),c=d.b.neg().mul(e).divRound(this.n),r=a.mul(d.a),b=c.mul(t.a),i=a.mul(d.b),n=c.mul(t.b);return{k1:e.sub(r).sub(b),k2:i.add(n).neg()}},M.prototype.pointFromX=function(e,f){(e=new o(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),t=d.redSqrt();if(0!==t.redSqr().redSub(d).cmp(this.zero))throw Error("invalid point");var a=t.fromRed().isOdd();return(f&&!a||!f&&a)&&(t=t.redNeg()),this.point(e,t)},M.prototype.validate=function(e){if(e.inf)return!0;var f=e.x,d=e.y,t=this.a.redMul(f),a=f.redSqr().redMul(f).redIAdd(t).redIAdd(this.b);return 0===d.redSqr().redISub(a).cmpn(0)},M.prototype._endoWnafMulAdd=function(e,f,d){for(var t=this._endoWnafT1,a=this._endoWnafT2,c=0;c":""},C.prototype.isInfinity=function(){return this.inf},C.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 f=this.y.redSub(e.y);0!==f.cmpn(0)&&(f=f.redMul(this.x.redSub(e.x).redInvm()));var d=f.redSqr().redISub(this.x).redISub(e.x),t=f.redMul(this.x.redSub(d)).redISub(this.y);return this.curve.point(d,t)},C.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 f=this.curve.a,d=this.x.redSqr(),t=e.redInvm(),a=d.redAdd(d).redIAdd(d).redIAdd(f).redMul(t),c=a.redSqr().redISub(this.x.redAdd(this.x)),r=a.redMul(this.x.redSub(c)).redISub(this.y);return this.curve.point(c,r)},C.prototype.getX=function(){return this.x.fromRed()},C.prototype.getY=function(){return this.y.fromRed()},C.prototype.mul=function(e){return e=new o(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)},C.prototype.mulAdd=function(e,f,d){var t=[this,f],a=[e,d];return this.curve.endo?this.curve._endoWnafMulAdd(t,a):this.curve._wnafMulAdd(1,t,a,2)},C.prototype.jmulAdd=function(e,f,d){var t=[this,f],a=[e,d];return this.curve.endo?this.curve._endoWnafMulAdd(t,a,!0):this.curve._wnafMulAdd(1,t,a,2,!0)},C.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))},C.prototype.neg=function(e){if(this.inf)return this;var f=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var d=this.precomputed,t=function(e){return e.neg()};f.precomputed={naf:d.naf&&{wnd:d.naf.wnd,points:d.naf.points.map(t)},doubles:d.doubles&&{step:d.doubles.step,points:d.doubles.points.map(t)}}}return f},C.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},d(_,I.BasePoint),M.prototype.jpoint=function(e,f,d){return new _(this,e,f,d)},_.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),f=e.redSqr(),d=this.x.redMul(f),t=this.y.redMul(f).redMul(e);return this.curve.point(d,t)},_.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},_.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var f=e.z.redSqr(),d=this.z.redSqr(),t=this.x.redMul(f),a=e.x.redMul(d),c=this.y.redMul(f.redMul(e.z)),r=e.y.redMul(d.redMul(this.z)),b=t.redSub(a),i=c.redSub(r);if(0===b.cmpn(0))return 0!==i.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var n=b.redSqr(),s=n.redMul(b),o=t.redMul(n),h=i.redSqr().redIAdd(s).redISub(o).redISub(o),u=i.redMul(o.redISub(h)).redISub(c.redMul(s)),p=this.z.redMul(e.z).redMul(b);return this.curve.jpoint(h,u,p)},_.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var f=this.z.redSqr(),d=this.x,t=e.x.redMul(f),a=this.y,c=e.y.redMul(f).redMul(this.z),r=d.redSub(t),b=a.redSub(c);if(0===r.cmpn(0))return 0!==b.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var i=r.redSqr(),n=i.redMul(r),s=d.redMul(i),o=b.redSqr().redIAdd(n).redISub(s).redISub(s),h=b.redMul(s.redISub(o)).redISub(a.redMul(n)),u=this.z.redMul(r);return this.curve.jpoint(o,h,u)},_.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 f=this,d=0;d=0)return!1;if(d.redIAdd(a),0===this.x.cmp(d))return!0}},_.prototype.inspect=function(){return this.isInfinity()?"":""},_.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},d(D,I);var F=D;function z(e,f,d){I.BasePoint.call(this,e,"projective"),null===f&&null===d?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new o(f,16),this.z=new o(d,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}D.prototype.validate=function(e){var f=e.normalize().x,d=f.redSqr(),t=d.redMul(f).redAdd(d.redMul(this.a)).redAdd(f);return 0===t.redSqrt().redSqr().cmp(t)},d(z,I.BasePoint),D.prototype.decodePoint=function(e,f){if(33===(e=p.toArray(e,f)).length&&64===e[0]&&(e=e.slice(1,33).reverse()),32!==e.length)throw Error("Unknown point compression format");return this.point(e,1)},D.prototype.point=function(e,f){return new z(this,e,f)},D.prototype.pointFromJSON=function(e){return z.fromJSON(this,e)},z.prototype.precompute=function(){},z.prototype._encode=function(e){var f=this.curve.p.byteLength();return e?[64].concat(this.getX().toArray("le",f)):this.getX().toArray("be",f)},z.fromJSON=function(e,f){return new z(e,f[0],f[1]||e.one)},z.prototype.inspect=function(){return this.isInfinity()?"":""},z.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},z.prototype.dbl=function(){var e=this.x.redAdd(this.z).redSqr(),f=this.x.redSub(this.z).redSqr(),d=e.redSub(f),t=e.redMul(f),a=d.redMul(f.redAdd(this.curve.a24.redMul(d)));return this.curve.point(t,a)},z.prototype.add=function(){throw Error("Not supported on Montgomery curve")},z.prototype.diffAdd=function(e,f){var d=this.x.redAdd(this.z),t=this.x.redSub(this.z),a=e.x.redAdd(e.z),c=e.x.redSub(e.z).redMul(d),r=a.redMul(t),b=f.z.redMul(c.redAdd(r).redSqr()),i=f.x.redMul(c.redISub(r).redSqr());return this.curve.point(b,i)},z.prototype.mul=function(e){for(var f=(e=new o(e,16)).clone(),d=this,t=this.curve.point(null,null),a=[];0!==f.cmpn(0);f.iushrn(1))a.push(f.andln(1));for(var c=a.length-1;c>=0;c--)0===a[c]?(d=d.diffAdd(t,this),t=t.dbl()):(t=d.diffAdd(t,this),d=d.dbl());return t},z.prototype.mulAdd=function(){throw Error("Not supported on Montgomery curve")},z.prototype.jumlAdd=function(){throw Error("Not supported on Montgomery curve")},z.prototype.eq=function(e){return 0===this.getX().cmp(e.getX())},z.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},z.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var q=p.assert;function R(e){this.twisted=1!=(0|e.a),this.mOneA=this.twisted&&-1==(0|e.a),this.extended=this.mOneA,I.call(this,"edwards",e),this.a=new o(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new o(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new o(e.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),q(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|e.c)}d(R,I);var P=R;function N(e,f,d,t,a){I.BasePoint.call(this,e,"projective"),null===f&&null===d&&null===t?(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 o(f,16),this.y=new o(d,16),this.z=t?new o(t,16):this.curve.one,this.t=a&&new o(a,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()))))}R.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)},R.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)},R.prototype.jpoint=function(e,f,d,t){return this.point(e,f,d,t)},R.prototype.pointFromX=function(e,f){(e=new o(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr(),t=this.c2.redSub(this.a.redMul(d)),a=this.one.redSub(this.c2.redMul(this.d).redMul(d)),c=t.redMul(a.redInvm()),r=c.redSqrt();if(0!==r.redSqr().redSub(c).cmp(this.zero))throw Error("invalid point");var b=r.fromRed().isOdd();return(f&&!b||!f&&b)&&(r=r.redNeg()),this.point(e,r)},R.prototype.pointFromY=function(e,f){(e=new o(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr(),t=d.redSub(this.c2),a=d.redMul(this.d).redMul(this.c2).redSub(this.a),c=t.redMul(a.redInvm());if(0===c.cmp(this.zero)){if(f)throw Error("invalid point");return this.point(this.zero,e)}var r=c.redSqrt();if(0!==r.redSqr().redSub(c).cmp(this.zero))throw Error("invalid point");return r.fromRed().isOdd()!==f&&(r=r.redNeg()),this.point(r,e)},R.prototype.validate=function(e){if(e.isInfinity())return!0;e.normalize();var f=e.x.redSqr(),d=e.y.redSqr(),t=f.redMul(this.a).redAdd(d),a=this.c2.redMul(this.one.redAdd(this.d.redMul(f).redMul(d)));return 0===t.cmp(a)},d(N,I.BasePoint),R.prototype.pointFromJSON=function(e){return N.fromJSON(this,e)},R.prototype.point=function(e,f,d,t){return new N(this,e,f,d,t)},N.fromJSON=function(e,f){return new N(e,f[0],f[1],f[2])},N.prototype.inspect=function(){return this.isInfinity()?"":""},N.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&(0===this.y.cmp(this.z)||this.zOne&&0===this.y.cmp(this.curve.c))},N.prototype._extDbl=function(){var e=this.x.redSqr(),f=this.y.redSqr(),d=this.z.redSqr();d=d.redIAdd(d);var t=this.curve._mulA(e),a=this.x.redAdd(this.y).redSqr().redISub(e).redISub(f),c=t.redAdd(f),r=c.redSub(d),b=t.redSub(f),i=a.redMul(r),n=c.redMul(b),s=a.redMul(b),o=r.redMul(c);return this.curve.point(i,n,o,s)},N.prototype._projDbl=function(){var e,f,d,t=this.x.redAdd(this.y).redSqr(),a=this.x.redSqr(),c=this.y.redSqr();if(this.curve.twisted){var r=(n=this.curve._mulA(a)).redAdd(c);if(this.zOne)e=t.redSub(a).redSub(c).redMul(r.redSub(this.curve.two)),f=r.redMul(n.redSub(c)),d=r.redSqr().redSub(r).redSub(r);else{var b=this.z.redSqr(),i=r.redSub(b).redISub(b);e=t.redSub(a).redISub(c).redMul(i),f=r.redMul(n.redSub(c)),d=r.redMul(i)}}else{var n=a.redAdd(c);b=this.curve._mulC(this.z).redSqr(),i=n.redSub(b).redSub(b);e=this.curve._mulC(t.redISub(n)).redMul(i),f=this.curve._mulC(n).redMul(a.redISub(c)),d=n.redMul(i)}return this.curve.point(e,f,d)},N.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},N.prototype._extAdd=function(e){var f=this.y.redSub(this.x).redMul(e.y.redSub(e.x)),d=this.y.redAdd(this.x).redMul(e.y.redAdd(e.x)),t=this.t.redMul(this.curve.dd).redMul(e.t),a=this.z.redMul(e.z.redAdd(e.z)),c=d.redSub(f),r=a.redSub(t),b=a.redAdd(t),i=d.redAdd(f),n=c.redMul(r),s=b.redMul(i),o=c.redMul(i),h=r.redMul(b);return this.curve.point(n,s,h,o)},N.prototype._projAdd=function(e){var f,d,t=this.z.redMul(e.z),a=t.redSqr(),c=this.x.redMul(e.x),r=this.y.redMul(e.y),b=this.curve.d.redMul(c).redMul(r),i=a.redSub(b),n=a.redAdd(b),s=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(c).redISub(r),o=t.redMul(i).redMul(s);return this.curve.twisted?(f=t.redMul(n).redMul(r.redSub(this.curve._mulA(c))),d=i.redMul(n)):(f=t.redMul(n).redMul(r.redSub(c)),d=this.curve._mulC(i).redMul(n)),this.curve.point(o,f,d)},N.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},N.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},N.prototype.mulAdd=function(e,f,d){return this.curve._wnafMulAdd(1,[this,f],[e,d],2,!1)},N.prototype.jmulAdd=function(e,f,d){return this.curve._wnafMulAdd(1,[this,f],[e,d],2,!0)},N.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},N.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},N.prototype.getX=function(){return this.normalize(),this.x.fromRed()},N.prototype.getY=function(){return this.normalize(),this.y.fromRed()},N.prototype.eq=function(e){return this===e||0===this.getX().cmp(e.getX())&&0===this.getY().cmp(e.getY())},N.prototype.eqXToP=function(e){var f=e.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(f))return!0;for(var d=e.clone(),t=this.curve.redN.redMul(this.z);;){if(d.iadd(this.curve.n),d.cmp(this.curve.p)>=0)return!1;if(f.redIAdd(t),0===this.x.cmp(f))return!0}},N.prototype.toP=N.prototype.normalize,N.prototype.mixedAdd=N.prototype.add;var k=e((function(e,f){var d=f;d.base=I,d.short=B,d.mont=F,d.edwards=P})),j=t.rotl32,O=t.sum32,L=t.sum32_5,T=a.ft_1,J=c.BlockHash,X=[1518500249,1859775393,2400959708,3395469782];function V(){if(!(this instanceof V))return new V;J.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=Array(80)}t.inherits(V,J);var K=V;V.blockSize=512,V.outSize=160,V.hmacStrength=80,V.padLength=64,V.prototype._update=function(e,f){for(var d=this.W,t=0;t<16;t++)d[t]=e[f+t];for(;tthis.blockSize&&(e=(new this.Hash).update(e).digest()),f(e.length<=this.blockSize);for(var d=e.length;d=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(d,t,a)}var $=Z;Z.prototype._init=function(e,f,d){var t=e.concat(f).concat(d);this.K=Array(this.outLen/8),this.V=Array(this.outLen/8);for(var a=0;a=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(e.concat(t||[])),this._reseed=1},Z.prototype.generate=function(e,f,d,t){if(this._reseed>this.reseedInterval)throw Error("Reseed is required");"string"!=typeof f&&(t=d,d=f,f=null),d&&(d=u.toArray(d,t||"hex"),this._update(d));for(var a=[];a.length"};var te=p.assert;function ae(e,f){if(e instanceof ae)return e;this._importDER(e,f)||(te(e.r&&e.s,"Signature without r or s"),this.r=new o(e.r,16),this.s=new o(e.s,16),void 0===e.recoveryParam?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}var ce=ae;function re(){this.place=0}function be(e,f){var d=e[f.place++];if(!(128&d))return d;for(var t=15&d,a=0,c=0,r=f.place;c>>3);for(e.push(128|d);--d;)e.push(f>>>(d<<3)&255);e.push(f)}}ae.prototype._importDER=function(e,f){e=p.toArray(e,f);var d=new re;if(48!==e[d.place++])return!1;if(be(e,d)+d.place!==e.length)return!1;if(2!==e[d.place++])return!1;var t=be(e,d),a=e.slice(d.place,t+d.place);if(d.place+=t,2!==e[d.place++])return!1;var c=be(e,d);if(e.length!==c+d.place)return!1;var r=e.slice(d.place,c+d.place);return 0===a[0]&&128&a[1]&&(a=a.slice(1)),0===r[0]&&128&r[1]&&(r=r.slice(1)),this.r=new o(a),this.s=new o(r),this.recoveryParam=null,!0},ae.prototype.toDER=function(e){var f=this.r.toArray(),d=this.s.toArray();for(128&f[0]&&(f=[0].concat(f)),128&d[0]&&(d=[0].concat(d)),f=ie(f),d=ie(d);!(d[0]||128&d[1]);)d=d.slice(1);var t=[2];ne(t,f.length),(t=t.concat(f)).push(2),ne(t,d.length);var a=t.concat(d),c=[48];return ne(c,a.length),c=c.concat(a),p.encode(c,e)};var se=p.assert;function oe(e){if(!(this instanceof oe))return new oe(e);"string"==typeof e&&(se(Q.hasOwnProperty(e),"Unknown curve "+e),e=Q[e]),e instanceof Q.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 he=oe;oe.prototype.keyPair=function(e){return new de(this,e)},oe.prototype.keyFromPrivate=function(e,f){return de.fromPrivate(this,e,f)},oe.prototype.keyFromPublic=function(e,f){return de.fromPublic(this,e,f)},oe.prototype.genKeyPair=function(e){e||(e={});var f=new $({hash:this.hash,pers:e.pers,persEnc:e.persEnc||"utf8",entropy:e.entropy||l(this.hash.hmacStrength),entropyEnc:e.entropy&&e.entropyEnc||"utf8",nonce:this.n.toArray()});if("mont"===this.curve.type){var d=new o(f.generate(32));return this.keyFromPrivate(d)}for(var t=this.n.byteLength(),a=this.n.sub(new o(2));;){if(!((d=new o(f.generate(t))).cmp(a)>0))return d.iaddn(1),this.keyFromPrivate(d)}},oe.prototype._truncateToN=function(e,f,d){var t=(d=d||8*e.byteLength())-this.n.bitLength();return t>0&&(e=e.ushrn(t)),!f&&e.cmp(this.n)>=0?e.sub(this.n):e},oe.prototype.truncateMsg=function(e){var f;return e instanceof Uint8Array?(f=8*e.byteLength,e=this._truncateToN(new o(e,16),!1,f)):"string"==typeof e?(f=4*e.length,e=this._truncateToN(new o(e,16),!1,f)):e=this._truncateToN(new o(e,16)),e},oe.prototype.sign=function(e,f,d,t){"object"==typeof d&&(t=d,d=null),t||(t={}),f=this.keyFromPrivate(f,d),e=this.truncateMsg(e);for(var a=this.n.byteLength(),c=f.getPrivate().toArray("be",a),r=e.toArray("be",a),b=new $({hash:this.hash,entropy:c,nonce:r,pers:t.pers,persEnc:t.persEnc||"utf8"}),i=this.n.sub(new o(1)),n=0;;n++){var s=t.k?t.k(n):new o(b.generate(this.n.byteLength()));if(!((s=this._truncateToN(s,!0)).cmpn(1)<=0||s.cmp(i)>=0)){var h=this.g.mul(s);if(!h.isInfinity()){var u=h.getX(),p=u.umod(this.n);if(0!==p.cmpn(0)){var l=s.invm(this.n).mul(p.mul(f.getPrivate()).iadd(e));if(0!==(l=l.umod(this.n)).cmpn(0)){var y=(h.getY().isOdd()?1:0)|(0!==u.cmp(p)?2:0);return t.canonical&&l.cmp(this.nh)>0&&(l=this.n.sub(l),y^=1),new ce({r:p,s:l,recoveryParam:y})}}}}}},oe.prototype.verify=function(e,f,d,t){return d=this.keyFromPublic(d,t),f=new ce(f,"hex"),this._verify(this.truncateMsg(e),f,d)||this._verify(this._truncateToN(new o(e,16)),f,d)},oe.prototype._verify=function(e,f,d){var t=f.r,a=f.s;if(t.cmpn(1)<0||t.cmp(this.n)>=0)return!1;if(a.cmpn(1)<0||a.cmp(this.n)>=0)return!1;var c,r=a.invm(this.n),b=r.mul(e).umod(this.n),i=r.mul(t).umod(this.n);return this.curve._maxwellTrick?!(c=this.g.jmulAdd(b,d.getPublic(),i)).isInfinity()&&c.eqXToP(t):!(c=this.g.mulAdd(b,d.getPublic(),i)).isInfinity()&&0===c.getX().umod(this.n).cmp(t)},oe.prototype.recoverPubKey=function(e,f,d,t){se((3&d)===d,"The recovery param is more than two bits"),f=new ce(f,t);var a=this.n,c=new o(e),r=f.r,b=f.s,i=1&d,n=d>>1;if(r.cmp(this.curve.p.umod(this.curve.n))>=0&&n)throw Error("Unable to find sencond key candinate");r=n?this.curve.pointFromX(r.add(this.curve.n),i):this.curve.pointFromX(r,i);var s=f.r.invm(a),h=a.sub(c).mul(s).umod(a),u=b.mul(s).umod(a);return this.g.mulAdd(h,r,u)},oe.prototype.getKeyRecoveryParam=function(e,f,d,t){if(null!==(f=new ce(f,t)).recoveryParam)return f.recoveryParam;for(var a=0;a<4;a++){var c;try{c=this.recoverPubKey(e,f,a)}catch(e){continue}if(c.eq(d))return a}throw Error("Unable to find valid recovery factor")};var ue=p.assert,pe=p.parseBytes,le=p.cachedProperty;function ye(e,f){if(this.eddsa=e,f.hasOwnProperty("secret")&&(this._secret=pe(f.secret)),e.isPoint(f.pub))this._pub=f.pub;else if(this._pubBytes=pe(f.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")}ye.fromPublic=function(e,f){return f instanceof ye?f:new ye(e,{pub:f})},ye.fromSecret=function(e,f){return f instanceof ye?f:new ye(e,{secret:f})},ye.prototype.secret=function(){return this._secret},le(ye,"pubBytes",(function(){return this.eddsa.encodePoint(this.pub())})),le(ye,"pub",(function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())})),le(ye,"privBytes",(function(){var e=this.eddsa,f=this.hash(),d=e.encodingLength-1,t=f.slice(0,e.encodingLength);return t[0]&=248,t[d]&=127,t[d]|=64,t})),le(ye,"priv",(function(){return this.eddsa.decodeInt(this.privBytes())})),le(ye,"hash",(function(){return this.eddsa.hash().update(this.secret()).digest()})),le(ye,"messagePrefix",(function(){return this.hash().slice(this.eddsa.encodingLength)})),ye.prototype.sign=function(e){return ue(this._secret,"KeyPair can only verify"),this.eddsa.sign(e,this)},ye.prototype.verify=function(e,f){return this.eddsa.verify(e,f,this)},ye.prototype.getSecret=function(e){return ue(this._secret,"KeyPair is public only"),p.encode(this.secret(),e)},ye.prototype.getPublic=function(e,f){return p.encode((f?[64]:[]).concat(this.pubBytes()),e)};var ve=ye,me=p.assert,Ae=p.cachedProperty,ge=p.parseBytes;function Se(e,f){this.eddsa=e,"object"!=typeof f&&(f=ge(f)),Array.isArray(f)&&(f={R:f.slice(0,e.encodingLength),S:f.slice(e.encodingLength)}),me(f.R&&f.S,"Signature without R or S"),e.isPoint(f.R)&&(this._R=f.R),f.S instanceof o&&(this._S=f.S),this._Rencoded=Array.isArray(f.R)?f.R:f.Rencoded,this._Sencoded=Array.isArray(f.S)?f.S:f.Sencoded}Ae(Se,"S",(function(){return this.eddsa.decodeInt(this.Sencoded())})),Ae(Se,"R",(function(){return this.eddsa.decodePoint(this.Rencoded())})),Ae(Se,"Rencoded",(function(){return this.eddsa.encodePoint(this.R())})),Ae(Se,"Sencoded",(function(){return this.eddsa.encodeInt(this.S())})),Se.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())},Se.prototype.toHex=function(){return p.encode(this.toBytes(),"hex").toUpperCase()};var we=Se,Ie=p.assert,Ee=p.parseBytes;function xe(e){if(Ie("ed25519"===e,"only tested with ed25519 so far"),!(this instanceof xe))return new xe(e);e=Q[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=Y.sha512}var Me=xe;xe.prototype.sign=function(e,f){e=Ee(e);var d=this.keyFromSecret(f),t=this.hashInt(d.messagePrefix(),e),a=this.g.mul(t),c=this.encodePoint(a),r=this.hashInt(c,d.pubBytes(),e).mul(d.priv()),b=t.add(r).umod(this.curve.n);return this.makeSignature({R:a,S:b,Rencoded:c})},xe.prototype.verify=function(e,f,d){e=Ee(e),f=this.makeSignature(f);var t=this.keyFromPublic(d),a=this.hashInt(f.Rencoded(),t.pubBytes(),e),c=this.g.mul(f.S());return f.R().add(t.pub().mul(a)).eq(c)},xe.prototype.hashInt=function(){for(var e=this.hash(),f=0;f