>>=26,t.words[r]=n,e=i}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(g[t])return g[t];var e;if("k256"===t)e=new v;else if("p224"===t)e=new w;else if("p192"===t)e=new M;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new _}return g[t]=e,e},S.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},S.prototype._verify2=function(t,e){i(0===(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},S.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},S.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},S.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},S.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},S.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},S.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},S.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},S.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},S.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},S.prototype.isqr=function(t){return this.imul(t,t.clone())},S.prototype.sqr=function(t){return this.mul(t,t)},S.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new o(1)).iushrn(2);return this.pow(t,r)}for(var n=this.m.subn(1),a=0;!n.isZero()&&0===n.andln(1);)a++,n.iushrn(1);i(!n.isZero());var s=new o(1).toRed(this),h=s.redNeg(),u=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new o(2*f*f).toRed(this);0!==this.pow(f,u).cmp(h);)f.redIAdd(h);for(var l=this.pow(f,n),c=this.pow(t,n.addn(1).iushrn(1)),d=this.pow(t,n),p=a;0!==d.cmp(s);){for(var m=d,b=0;0!==m.cmp(s);b++)m=m.redSqr();i(b=0;i--){for(var u=e.words[i],f=h-1;f>=0;f--){var l=u>>f&1;n!==r[0]&&(n=this.sqr(n)),0!==l||0!==a?(a<<=1,a|=l,(4===++s||0===i&&0===f)&&(n=this.mul(n,r[a]),s=0,a=0)):s=0}h=26}return n},S.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},S.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new k(t)},n(k,S),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},k.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),o=n;return n.cmp(this.m)>=0?o=n.isub(this.m):n.cmpn(0)<0&&(o=n.iadd(this.m)),o._forceRed(this)},k.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var r=t.mul(e),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.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t=r.nmd(t),this)},7475(t,e,r){"use strict";r.d(e,{default:()=>O}),t=r.hmd(t);var i,n=r(8287).Buffer;function o(t){var e="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(a())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,e);var n=new(t.bind.apply(t,i));return r&&s(n,r.prototype),n}(t,arguments,h(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)},o(t)}function a(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(a=function(){return!!t})()}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function h(t){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},h(t)}function u(t){return function(t){if(Array.isArray(t))return d(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var i,n,o,a,s=[],h=!0,u=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;h=!1}else for(;!(h=(i=o.call(r)).done)&&(s.push(i.value),s.length!==e);h=!0);}catch(t){u=!0,n=t}finally{try{if(!h&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw n}}return s}}(t,e)||c(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=c(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0,n=function(){};return{s:n,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function c(t,e){if(t){if("string"==typeof t)return d(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(t,e):void 0}}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=Array(e);r3?(n=p===i)&&(h=o[(s=o[4])?5:(s=3,3)],o[4]=o[5]=t):o[0]<=d&&((n=r<2&&di||i>p)&&(o[4]=r,o[5]=i,c.n=p,s=0))}if(n||r>1)return a;throw l=!0,i}return function(n,f,p){if(u>1)throw TypeError("Generator is already running");for(l&&1===f&&d(f,p),s=f,h=p;(e=s<2?t:h)||!l;){o||(s?s<3?(s>1&&(c.n=-1),d(s,h)):c.n=h:c.v=h);try{if(u=2,o){if(s||(n="next"),e=o[n]){if(!(e=e.call(o,h)))throw TypeError("iterator result is not an object");if(!e.done)return e;h=e.value,s<2&&(s=0)}else 1===s&&(e=o.return)&&e.call(o),s<2&&(h=TypeError("The iterator does not provide a '"+n+"' method"),s=1);o=t}else if((e=(l=c.n<0)?h:r.call(i,c))!==a)break}catch(e){o=t,s=1,h=e}finally{u=1}}return{value:e,done:l}}}(r,n,o),!0),u}var a={};function s(){}function h(){}function u(){}e=Object.getPrototypeOf;var f=[][i]?e(e([][i]())):(b(e={},i,function(){return this}),e),l=u.prototype=s.prototype=Object.create(f);function c(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,b(t,n,"GeneratorFunction")),t.prototype=Object.create(l),t}return h.prototype=u,b(l,"constructor",u),b(u,"constructor",h),h.displayName="GeneratorFunction",b(u,n,"GeneratorFunction"),b(l),b(l,n,"Generator"),b(l,i,function(){return this}),b(l,"toString",function(){return"[object Generator]"}),(m=function(){return{w:o,m:c}})()}function b(t,e,r,i){var n=Object.defineProperty;try{n({},"",{})}catch(t){n=0}b=function(t,e,r,i){function o(e,r){b(t,e,function(t){return this._invoke(e,r,t)})}e?n?n(t,e,{value:r,enumerable:!i,configurable:!i,writable:!i}):t[e]=r:(o("next",0),o("throw",1),o("return",2))},b(t,e,r,i)}function g(t,e,r,i,n,o,a){try{var s=t[o](a),h=s.value}catch(t){return void r(t)}s.done?e(h):Promise.resolve(h).then(i,n)}function y(t){return function(){var e=this,r=arguments;return new Promise(function(i,n){var o=t.apply(e,r);function a(t){g(o,i,n,a,s,"next",t)}function s(t){g(o,i,n,a,s,"throw",t)}a(void 0)})}}function v(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function w(t,e){for(var r=0;r=300&&t.statusCode<400&&t.headers.location)i(t.headers.location,e).then(o).catch(a);else{var r=[];t.on("data",function(t){return r.push(t)}),t.on("end",function(){var e=n.concat(r);o({ok:t.statusCode>=200&&t.statusCode<300,status:t.statusCode,arrayBuffer:function(){var t=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);return Promise.resolve(t)}})})}});u.on("error",a),u.end()})},console.log("[RtcTorrent] bundle v25 loaded");var E=function(){return M(function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(v(this,t),this.options=S({trackerUrl:e.trackerUrl||"",announceInterval:e.announceInterval||3e4,rtcInterval:e.rtcInterval||1e4,maxPeers:e.maxPeers||50,iceServers:e.iceServers||[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"}]},e),this.pieces=new Map,this.downloaded=0,this.requestedPieces=new Set,this.torrents=new Map,this.connections=new Map,this.announcer=null,this.webRtcManager=null,this.bencoder=null,this.isBrowser="undefined"!=typeof window,this.isFileApiAvailable=this.isBrowser&&"undefined"!=typeof File,!this.isBrowser){try{this.fs=r(1603)}catch(t){}try{this.path=r(7975)}catch(t){}}},[{key:"getRTCPeerConnection",value:function(){if("undefined"!=typeof RTCPeerConnection)return RTCPeerConnection;for(var t="undefined"!=typeof require?require:r(6589),e=0,i=["wrtc","@roamhq/wrtc","node-webrtc"];e1&&void 0!==B[1]?B[1]:{},t.n=1,this.initBencoder();case 1:if(i=t.v,o=0,a=[],s=[],!Array.isArray(e)){t.n=11;break}h=l(e),t.p=2,h.s();case 3:if((u=h.n()).done){t.n=8;break}if(f=u.value,this.isBrowser||!this.fs){t.n=4;break}c="string"==typeof f?f:f.path,d="string"==typeof f?this.path.basename(c):f.name||this.path.basename(c),p=this.fs.statSync(c),o+=p.size,a.push({length:p.size,path:[d]}),s.push(this.fs.readFileSync(c)),t.n=7;break;case 4:if(!(this.isBrowser&&this.isFileApiAvailable&&f instanceof File)){t.n=6;break}return o+=f.size,a.push({length:f.size,path:[f.name]}),t.n=5,f.arrayBuffer();case 5:b=t.v,s.push(n.from(b)),t.n=7;break;case 6:o+=f.size||0,a.push({length:f.size||0,path:[f.name||"file"]});case 7:t.n=3;break;case 8:t.n=10;break;case 9:t.p=9,T=t.v,h.e(T);case 10:return t.p=10,h.f(),t.f(10);case 11:g=16384,o>8388608&&(g=32768),o>67108864&&(g=65536),y=s.length>0?n.concat(s):n.alloc(o),v=Math.ceil(o/g),w=new Uint8Array(20*v),M=0;case 12:if(!(M1?(S.files=a,delete S.length):1===a.length&&(S.length=a[0].length),k={info:S,announce:this.options.trackerUrl,"creation date":Math.floor(Date.now()/1e3),"created by":"Torrust-Actix v4.2",_originalFiles:s,_pieceLength:g},A=i.encode(k.info),t.n=16,this.sha1Hex(A);case 16:return E=t.v,x={info:k.info,announce:k.announce,"creation date":k["creation date"],"created by":k["created by"]},r.webseedUrls&&(R=Array.isArray(r.webseedUrls)?r.webseedUrls:[r.webseedUrls],x["url-list"]=1===R.length?R[0]:R),t.a(2,{torrent:k,magnetUri:this.createMagnetURI(k,E),infoHash:E,encodedTorrent:i.encode(x)})}},t,this,[[2,9,10,11]])})),function(t){return w.apply(this,arguments)})},{key:"sha1Hex",value:function(t){if(this.isBrowser)return this.sha1Browser(t);try{return r(1565).createHash("sha1").update(t).digest("hex")}catch(t){return"0".repeat(40)}}},{key:"sha1Browser",value:(g=y(m().m(function t(e){var r;return m().w(function(t){for(;;)switch(t.n){case 0:return"string"==typeof e&&(e=(new TextEncoder).encode(e)),t.n=1,crypto.subtle.digest("SHA-1",e);case 1:return r=t.v,t.a(2,Array.from(new Uint8Array(r)).map(function(t){return t.toString(16).padStart(2,"0")}).join(""))}},t)})),function(t){return g.apply(this,arguments)})},{key:"sha1Buffer",value:(b=y(m().m(function t(e){var i;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isBrowser){t.n=2;break}return t.n=1,crypto.subtle.digest("SHA-1",e);case 1:return i=t.v,t.a(2,new Uint8Array(i));case 2:return t.p=2,t.a(2,r(1565).createHash("sha1").update(e).digest());case 3:return t.p=3,t.v,t.a(2,new Uint8Array(20).fill(66))}},t,this,[[2,3]])})),function(t){return b.apply(this,arguments)})},{key:"createMagnetURI",value:function(t,e){var r,i=Array.isArray(t.announce)?t.announce:[t.announce],n=["xt=urn:btih:".concat(e)];return null!==(r=t.info)&&void 0!==r&&r.name&&n.push("dn=".concat(encodeURIComponent(t.info.name))),i.forEach(function(t){return t&&n.push("tr=".concat(encodeURIComponent(t)))}),"magnet:?".concat(n.join("&"))}},{key:"calculateInfoHash",value:(d=y(m().m(function t(e){var r;return m().w(function(t){for(;;)switch(t.n){case 0:return r=this.createMinimalBencoder(),t.n=1,this.sha1Hex(r.encode(e));case 1:return t.a(2,t.v)}},t,this)})),function(t){return d.apply(this,arguments)})},{key:"download",value:(c=y(m().m(function t(e){var r,i,o,a,s;return m().w(function(t){for(;;)switch(t.n){case 0:if(r=e,"string"!=typeof e){t.n=5;break}if(!e.startsWith("magnet:")){t.n=2;break}return t.n=1,this.parseMagnet(e);case 1:a=t.v,t.n=4;break;case 2:return t.n=3,this.fetchTorrentFile(e);case 3:a=t.v;case 4:r=a,t.n=7;break;case 5:if(!(n.isBuffer(e)||e instanceof Uint8Array)){t.n=7;break}return t.n=6,this.parseTorrentFile(e);case 6:r=t.v;case 7:if(s=r.infoHash){t.n=9;break}return t.n=8,this.calculateInfoHash(r.info);case 8:s=t.v;case 9:if(i=s,!this.torrents.has(i)){t.n=10;break}throw new Error("Torrent already exists");case 10:return o=new x(this,r,this.options),this.torrents.set(i,o),t.n=11,o.start();case 11:return t.a(2,t.v)}},t,this)})),function(t){return c.apply(this,arguments)})},{key:"seed",value:(u=y(m().m(function t(e){var r,i,o,a,s,h,u,f,c,d,p,b,g,y,v=this,w=arguments;return m().w(function(t){for(;;)switch(t.n){case 0:if(i=w.length>1&&void 0!==w[1]?w[1]:null,"string"!=typeof e){t.n=5;break}if(!e.startsWith("magnet:")){t.n=2;break}return t.n=1,this.parseMagnet(e);case 1:g=t.v,t.n=4;break;case 2:return t.n=3,this.fetchTorrentFile(e);case 3:g=t.v;case 4:o=g,t.n=8;break;case 5:if(!(n.isBuffer(e)||e instanceof Uint8Array)){t.n=7;break}return t.n=6,this.parseTorrentFile(e);case 6:o=t.v,t.n=8;break;case 7:o=e;case 8:if(!o.info&&null!==(r=o.torrent)&&void 0!==r&&r.info&&(o=S(S({},o),{},{info:o.torrent.info})),null!==i&&!this.isBrowser&&this.fs&&(a=i.map(function(t){var e="string"==typeof t?t:t.path;return v.fs.existsSync(e)?{path:e,size:v.fs.statSync(e).size}:null}).filter(Boolean),a.length>0&&(o.torrent||(o.torrent={}),o.torrent._filePaths=a,o.torrent._pieceLength=(null===(s=o.info)||void 0===s?void 0:s["piece length"])||262144)),null!==i&&this.isBrowser&&this.isFileApiAvailable){h=[],u=l(i);try{for(u.s();!(f=u.n()).done;)(c=f.value)instanceof File&&h.push({file:c,size:c.size})}catch(t){u.e(t)}finally{u.f()}h.length>0&&(o.torrent||(o.torrent={}),o.torrent._fileObjects=h,o.torrent._pieceLength=(null===(d=o.info)||void 0===d?void 0:d["piece length"])||262144)}if(y=o.infoHash){t.n=10;break}return t.n=9,this.calculateInfoHash(o.info);case 9:y=t.v;case 10:if(p=y,!this.torrents.has(p)){t.n=11;break}throw new Error("Torrent already exists");case 11:return b=new x(this,o,this.options),this.torrents.set(p,b),t.n=12,b.seed();case 12:return t.a(2,t.v)}},t,this)})),function(t){return u.apply(this,arguments)})},{key:"parseTorrentFile",value:(h=y(m().m(function t(e){var r,i,o,a,s,h,u,f,l;return m().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.initBencoder();case 1:if(r=t.v,!n.isBuffer(e)){t.n=2;break}i=e,t.n=4;break;case 2:if(!(e instanceof Uint8Array)){t.n=3;break}i=n.from(e),t.n=4;break;case 3:throw new Error("Invalid torrent data type");case 4:return o=r.decode(i),a=o.info,s=r.encode(a),t.n=5,this.sha1Hex(s);case 5:return h=t.v,u=n.isBuffer(null==a?void 0:a.name)?a.name.toString():(null==a?void 0:a.name)||"Unknown",f=o["url-list"],l=f?Array.isArray(f)?f.map(function(t){return n.isBuffer(t)?t.toString():String(t)}):[n.isBuffer(f)?f.toString():String(f)]:[],t.a(2,{info:a,announce:o.announce,announceList:o["announce-list"],infoHash:h,name:u,webseeds:l})}},t,this)})),function(t){return h.apply(this,arguments)})},{key:"fetchTorrentFile",value:(s=y(m().m(function t(e){var r,o,a;return m().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,i(e);case 1:if((r=t.v).ok){t.n=2;break}throw new Error("Failed to fetch torrent: ".concat(r.status));case 2:return o=this,a=n,t.n=3,r.arrayBuffer();case 3:return t.a(2,o.parseTorrentFile.call(o,a.from.call(a,t.v)))}},t,this)})),function(t){return s.apply(this,arguments)})},{key:"parseMagnet",value:(a=y(m().m(function t(e){var r,i,n;return m().w(function(t){for(;;)switch(t.n){case 0:if("magnet:"===(r=new URL(e)).protocol){t.n=1;break}throw new Error("Invalid magnet URI");case 1:return i=Object.fromEntries(r.searchParams),n=(i.xt||"").replace("urn:btih:","").toLowerCase(),t.a(2,{infoHash:n,announce:i.tr?Array.isArray(i.tr)?i.tr:[i.tr]:[this.options.trackerUrl],name:i.dn?decodeURIComponent(i.dn):"Unknown"})}},t,this)})),function(t){return a.apply(this,arguments)})},{key:"start",value:(o=y(m().m(function t(){return m().w(function(t){for(;;)switch(t.n){case 0:this.webRtcManager=new T(this.options),this.announcer=new B(this.options),console.log("RtcTorrent client started");case 1:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"stop",value:(e=y(m().m(function t(){var e,r,i,n,o;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:e=l(this.torrents),t.p=1,e.s();case 2:if((r=e.n()).done){t.n=4;break}return i=f(r.value,2),n=i[1],t.n=3,n.stop();case 3:t.n=2;break;case 4:t.n=6;break;case 5:t.p=5,o=t.v,e.e(o);case 6:return t.p=6,e.f(),t.f(6);case 7:if(!this.webRtcManager){t.n=8;break}return t.n=8,this.webRtcManager.close();case 8:console.log("RtcTorrent client stopped");case 9:return t.a(2)}},t,this,[[1,5,6,7]])})),function(){return e.apply(this,arguments)})},{key:"streamVideo",value:(t=y(m().m(function t(e){var r,i,n,o=arguments;return m().w(function(t){for(;;)switch(t.n){case 0:if(r=o.length>1&&void 0!==o[1]?o[1]:0,i=o.length>2?o[2]:void 0,n=this.torrents.get(e)){t.n=1;break}throw new Error("Torrent ".concat(e," not found"));case 1:return t.a(2,n.streamVideo(r,i))}},t,this)})),function(e){return t.apply(this,arguments)})}]);var t,e,o,a,s,h,u,c,d,b,g,w,_}(),x=function(){return M(function t(e,r,i){var o;v(this,t),this.client=e,this.data=r,this.options=i,this.peers=new Map,this.pieces=new Map,this.downloaded=0,this.uploaded=0,this.active=!1,this.isSeeder=!1,this.signalChannel=null,this.pieceLength=(null===(o=r.info)||void 0===o?void 0:o["piece length"])||262144,this.totalSize=this.calculateTotalSize(r),this.files=this.extractFiles(r),this.pieceCount=Math.ceil(this.totalSize/this.pieceLength)||0,this._peerIdBytes=this._generatePeerIdBytes(),this._peerIdHex=n.from(this._peerIdBytes).toString("hex"),this._localPc=null,this._localSdp=null,this.mediaSource=null,this.sourceBuffer=null,this.requestedPieces=new Set,this._downloadCompleted=!1,this._sendQueue=Promise.resolve(),this._fdCache=new Map,this._peerStats=new Map,this._pieceChunks=new Map,this.webseeds=r.webseeds||[],this._webseedFetching=new Set,this._trackers=this._buildTrackerList(r),this._ignoredTrackers=new Set},[{key:"calculateTotalSize",value:function(t){var e,r;return null!==(e=t.info)&&void 0!==e&&e.length?t.info.length:Array.isArray(null===(r=t.info)||void 0===r?void 0:r.files)?t.info.files.reduce(function(t,e){return t+(e.length||0)},0):0}},{key:"extractFiles",value:function(t){var e,r,i;if(null!==(e=t.info)&&void 0!==e&&e.length&&null!==(r=t.info)&&void 0!==r&&r.name)return[{name:n.isBuffer(t.info.name)?t.info.name.toString():t.info.name,length:t.info.length,offset:0}];if(Array.isArray(null===(i=t.info)||void 0===i?void 0:i.files)){var o=0;return t.info.files.map(function(t){var e={name:Array.isArray(t.path)?t.path.map(function(t){return n.isBuffer(t)?t.toString():t}).join("/"):n.isBuffer(t.path)?t.path.toString():t.path,length:t.length,offset:o};return o+=t.length,e})}return[]}},{key:"_generatePeerIdBytes",value:function(){for(var t="-RT1000-",e=0;e<12;e++)t+=Math.floor(10*Math.random()).toString();return n.from(t,"ascii")}},{key:"_webseedPieceRanges",value:function(t){var e,r,i=t*this.pieceLength,o=Math.min(i+this.pieceLength,this.totalSize);if(this.files.length<=1)return[{url:this.webseeds[0],start:i,end:o-1,offset:0}];var a,s=this.webseeds[0].endsWith("/")?this.webseeds[0]:this.webseeds[0]+"/",h=n.isBuffer(null===(e=this.data.info)||void 0===e?void 0:e.name)?this.data.info.name.toString():(null===(r=this.data.info)||void 0===r?void 0:r.name)||"",u=[],f=l(this.files);try{for(f.s();!(a=f.n()).done;){var c=a.value,d=c.offset+c.length,p=Math.max(i,c.offset),m=Math.min(o,d);if(!(p>=m)){var b=s+encodeURIComponent(h)+"/"+c.name.split("/").map(encodeURIComponent).join("/");u.push({url:b,start:p-c.offset,end:m-c.offset-1,offset:p-i,length:m-p})}}}catch(t){f.e(t)}finally{f.f()}return u}},{key:"_fetchPieceFromWebseed",value:(C=y(m().m(function t(e){var r,n,o,a,s,h,u,f,c,d,p,b;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.webseeds.length&&!this._webseedFetching.has(e)){t.n=1;break}return t.a(2);case 1:this._webseedFetching.add(e),t.p=2,r=this._webseedPieceRanges(e),n=Math.min(this.pieceLength,this.totalSize-e*this.pieceLength),o=new Uint8Array(n),a=l(r),t.p=3,a.s();case 4:if((s=a.n()).done){t.n=9;break}return h=s.value,t.n=5,i(h.url,{headers:{Range:"bytes=".concat(h.start,"-").concat(h.end)}});case 5:if((u=t.v).ok||206===u.status){t.n=6;break}throw new Error("HTTP ".concat(u.status," from webseed"));case 6:return t.n=7,u.arrayBuffer();case 7:f=t.v,c=new Uint8Array(f),this.files.length<=1?o.set(c.slice(0,n)):o.set(c.slice(0,h.length),h.offset);case 8:t.n=4;break;case 9:t.n=11;break;case 10:t.p=10,p=t.v,a.e(p);case 11:return t.p=11,a.f(),t.f(11);case 12:return t.n=13,this._verifyPiece(e,o);case 13:if(t.v){t.n=14;break}return console.warn("[Webseed] Piece ".concat(e," hash mismatch — discarding")),t.a(2);case 14:this.pieces.has(e)||(this.pieces.set(e,o),this.requestedPieces.delete(e),d=Math.min(o.length,this.totalSize-this.downloaded),this.downloaded+=d,console.log("[Webseed] Piece ".concat(e," OK (").concat(o.length," B) — ")+"".concat(this.pieces.size,"/").concat(this.pieceCount," pieces")),"function"==typeof this.onPieceReceived&&this.onPieceReceived(e,o),this.updateProgress(),this._downloadCompleted||this._requestMissingPieces()),t.n=16;break;case 15:t.p=15,b=t.v,console.warn("[Webseed] Failed to fetch piece ".concat(e,":"),b.message);case 16:return t.p=16,this._webseedFetching.delete(e),t.f(16);case 17:return t.a(2)}},t,this,[[3,10,11,12],[2,15,16,17]])})),function(t){return C.apply(this,arguments)})},{key:"_buildTrackerList",value:function(t){var e=new Set,r=function(t){var r=n.isBuffer(t)?t.toString():"string"==typeof t?t:null;r&&e.add(r)};if(t.announce){var i=t.announce;Array.isArray(i)?i.forEach(r):r(i)}var o=t.announceList;if(Array.isArray(o)){var a,s=l(o);try{for(s.s();!(a=s.n()).done;){var h=a.value;Array.isArray(h)?h.forEach(r):r(h)}}catch(t){s.e(t)}finally{s.f()}}0===e.size&&this.client.options.trackerUrl&&e.add(this.client.options.trackerUrl);var f,c=u(e),d=c.filter(function(t){return/^https?:\/\//i.test(t)}),p=l(c.filter(function(t){return!/^https?:\/\//i.test(t)}));try{for(p.s();!(f=p.n()).done;){var m=f.value;console.log("[RtcTorrent] Skipping unsupported tracker protocol (not HTTP/HTTPS): ".concat(m))}}catch(t){p.e(t)}finally{p.f()}return 0===d.length&&console.warn("[RtcTorrent] No HTTP/HTTPS trackers found — WebRTC signaling will not work"),d}},{key:"urlEncodeBytes",value:function(t){for(var e="",r=0;r0&&this.downloaded>=this.totalSize,0===(r=this._trackers.filter(function(t){return!A._ignoredTrackers.has(t)})).length&&this._trackers.length>0&&console.warn("[RtcTorrent] All trackers are on the ignore list — no WebRTC signaling possible"),i=l(r),t.p=2,i.s();case 3:if((n=i.n()).done){t.n=26;break}if(o=n.value,t.p=4,h=void 0,!e){t.n=14;break}return t.n=5,this.getOrCreateSdpOffer();case 5:return f=t.v,t.n=6,this.announce({event:"started",numwant:50},{rtctorrent:!0,rtcoffer:f},o);case 6:if(h=t.v,null===(u=h)||void 0===u||null===(u=u.rtc_answers)||void 0===u||!u.length){t.n=13;break}c=l(h.rtc_answers),t.p=7,c.s();case 8:if((d=c.n()).done){t.n=10;break}return p=d.value,t.n=9,this.handleAnswerFromTracker(p);case 9:t.n=8;break;case 10:t.n=12;break;case 11:t.p=11,w=t.v,c.e(w);case 12:return t.p=12,c.f(),t.f(12);case 13:t.n=23;break;case 14:return t.n=15,this.announce({event:"started",numwant:50},{rtctorrent:!0,rtcrequest:!0},o);case 15:if(h=t.v,null===(b=h)||void 0===b||null===(b=b.rtc_peers)||void 0===b||!b.length){t.n=22;break}g=l(h.rtc_peers),t.p=16,g.s();case 17:if((y=g.n()).done){t.n=19;break}if(v=y.value,this.peers.has(v.peer_id)){t.n=18;break}return t.n=18,this.connectToWebRTCPeer(v,o);case 18:t.n=17;break;case 19:t.n=21;break;case 20:t.p=20,M=t.v,g.e(M);case 21:return t.p=21,g.f(),t.f(21);case 22:this.isSeeder||this._requestMissingPieces();case 23:null!==(a=h)&&void 0!==a&&a.rtc_interval&&(this.client.options.rtcInterval=h.rtc_interval),null!==(s=h)&&void 0!==s&&s.rtcNotSupported&&(this._ignoredTrackers.add(o),console.warn("[RtcTorrent] Tracker does not support WebRTC signaling: ".concat(o)+" — added to temporary ignore list (will retry on restart)")),t.n=25;break;case 24:t.p=24,_=t.v,console.error("[RtcTorrent] Announce to ".concat(o," failed:"),_.message);case 25:t.n=3;break;case 26:t.n=28;break;case 27:t.p=27,S=t.v,i.e(S);case 28:return t.p=28,i.f(),t.f(28);case 29:t.n=31;break;case 30:t.p=30,k=t.v,console.error("RtcTorrent announce error:",k);case 31:return t.p=31,this.active&&setTimeout(function(){return A.announceLoop()},this.client.options.rtcInterval),t.f(31);case 32:return t.a(2)}},t,this,[[16,20,21,22],[7,11,12,13],[4,24],[2,27,28,29],[1,30,31,32]])})),function(){return P.apply(this,arguments)})},{key:"_requestMissingPieces",value:function(){var t=Math.max(0,64-this.requestedPieces.size);if(0!==t)for(var e=0,r=0;r0&&void 0!==c[0]?c[0]:{},r=c.length>1&&void 0!==c[1]?c[1]:null,n=(c.length>2&&void 0!==c[2]?c[2]:null)||this.client.options.trackerUrl,o=this.hexToUint8Array(this.data.infoHash),a=Math.max(0,this.totalSize-this.downloaded),s=["info_hash="+this.urlEncodeBytes(o),"peer_id="+this.urlEncodeBytes(this._peerIdBytes),"port=6881","uploaded="+this.uploaded,"downloaded="+this.downloaded,"left="+a,"compact=1"],e.event&&s.push("event="+e.event),e.numwant&&s.push("numwant="+e.numwant),r&&(s.push("rtctorrent=1"),r.rtcoffer&&s.push("rtcoffer="+encodeURIComponent(r.rtcoffer)),r.rtcrequest&&s.push("rtcrequest=1"),r.rtcanswer&&s.push("rtcanswer="+encodeURIComponent(r.rtcanswer)),r.rtcanswerfor&&s.push("rtcanswerfor="+encodeURIComponent(r.rtcanswerfor))),h="".concat(n,"?").concat(s.join("&")),t.p=1,t.n=2,i(h);case 2:if((u=t.v).ok){t.n=3;break}throw new Error("Tracker returned ".concat(u.status));case 3:return t.n=4,u.arrayBuffer();case 4:return f=t.v,t.a(2,this.parseBencodedResponse(new Uint8Array(f)));case 5:throw t.p=5,l=t.v,console.error("Announce failed:",l.message),l;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return O.apply(this,arguments)})},{key:"parseBencodedResponse",value:function(t){try{var e;try{e=r(4179)}catch(t){e=null}if(!e)return console.warn("bencode library not available – tracker response may not be fully parsed"),{};var i=e.decode(n.from(t)),o=function(t){return n.isBuffer(t)?t.toString():null!=t?String(t):null},a=function(t){return null!=t?Number(t):void 0},s={};return i.interval&&(s.interval=a(i.interval)),i["rtc interval"]&&(s.rtc_interval=1e3*a(i["rtc interval"])),null!=i.complete&&(s.complete=a(i.complete)),null!=i.incomplete&&(s.incomplete=a(i.incomplete)),Array.isArray(i.rtc_peers)&&(s.rtc_peers=i.rtc_peers.map(function(t){return{peer_id:n.isBuffer(t.peer_id)?t.peer_id.toString("hex"):o(t.peer_id),sdp_offer:o(t.sdp_offer)}}).filter(function(t){return t.peer_id&&t.sdp_offer})),Array.isArray(i.rtc_answers)&&(s.rtc_answers=i.rtc_answers.map(function(t){return{peer_id:n.isBuffer(t.peer_id)?t.peer_id.toString("hex"):o(t.peer_id),sdp_answer:o(t.sdp_answer)}}).filter(function(t){return t.peer_id&&t.sdp_answer})),i["failure reason"]?(s.failure_reason=o(i["failure reason"]),console.error("Tracker failure:",s.failure_reason),s.failure_reason.toLowerCase().includes("rtctorrent")&&(s.rtcNotSupported=!0)):void 0===i.rtc_peers&&void 0===i.rtc_answers&&(s.rtcNotSupported=!0),s}catch(t){return console.error("Error parsing bencoded response:",t.message),{}}}},{key:"getOrCreateSdpOffer",value:(B=y(m().m(function t(){var e,r,i,n,o;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this._localSdp||!this._localPc||"closed"===this._localPc.signalingState||"connected"===this._localPc.connectionState){t.n=1;break}return t.a(2,this._localSdp);case 1:if(e=this.client.getRTCPeerConnection()){t.n=2;break}return console.warn('RTCPeerConnection not available. In Node.js, install "wrtc" or "@roamhq/wrtc" for WebRTC support.'),t.a(2,null);case 2:return t.p=2,r=new e({iceServers:this.client.options.iceServers}),i=r.createDataChannel("torrent",{ordered:!1,maxRetransmits:3}),this._setupDataChannelSeeder(i),t.n=3,r.createOffer({offerToReceiveAudio:!1,offerToReceiveVideo:!1});case 3:return n=t.v,t.n=4,r.setLocalDescription(n);case 4:return t.n=5,this._waitForIceGathering(r);case 5:return this._localPc=r,this._localSdp=r.localDescription.sdp,console.log("[Seeder] SDP offer created (".concat(this._localSdp.length," bytes)")),t.a(2,this._localSdp);case 6:return t.p=6,o=t.v,console.error("Failed to create SDP offer:",o),t.a(2,null)}},t,this,[[2,6]])})),function(){return B.apply(this,arguments)})},{key:"_waitForIceGathering",value:function(t){return new Promise(function(e){"complete"!==t.iceGatheringState?(t.onicegatheringstatechange=function(){"complete"===t.iceGatheringState&&e()},setTimeout(e,5e3)):e()})}},{key:"_setupDataChannelSeeder",value:function(t){var e=this;t.onopen=function(){console.log("[Seeder] Data channel opened")},t.onerror=function(t){return console.error("[Seeder] Data channel error:",t)},t.onclose=function(){return console.log("[Seeder] Data channel closed")},t.onmessage=function(r){return e.handleMessage(r.data,null,t)}}},{key:"connectToWebRTCPeer",value:(T=y(m().m(function t(e){var r,i,n,o,a,s,h,u=this,f=arguments;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(r=f.length>1&&void 0!==f[1]?f[1]:null,null!=e&&e.sdp_offer){t.n=1;break}return console.warn("connectToWebRTCPeer: peerInfo.sdp_offer missing"),t.a(2);case 1:if(i=this.client.getRTCPeerConnection()){t.n=2;break}return console.warn("RTCPeerConnection not available – skipping peer connection"),t.a(2);case 2:return t.p=2,(n=new i({iceServers:this.client.options.iceServers})).ondatachannel=function(t){var r=t.channel;u.setupDataChannel(r,e);var i=u.peers.get(e.peer_id);i&&(i.channel=r),"open"===r.readyState&&(u.requestedPieces.clear(),u._requestMissingPieces())},t.n=3,n.setRemoteDescription({type:"offer",sdp:e.sdp_offer});case 3:return t.n=4,n.createAnswer();case 4:return o=t.v,t.n=5,n.setLocalDescription(o);case 5:return t.n=6,this._waitForIceGathering(n);case 6:return a=n.localDescription.sdp,this.peers.set(e.peer_id,{connection:n,channel:null,info:e,connected:!1}),s=r||this._trackers.find(function(t){return!u._ignoredTrackers.has(t)})||this.client.options.trackerUrl,t.n=7,this.announce({event:"started",numwant:0},{rtctorrent:!0,rtcanswer:a,rtcanswerfor:e.peer_id},s);case 7:console.log("[Leecher] Sent SDP answer to seeder ".concat(e.peer_id)),t.n=9;break;case 8:t.p=8,h=t.v,console.error("Error connecting to WebRTC peer:",h);case 9:return t.a(2)}},t,this,[[2,8]])})),function(t){return T.apply(this,arguments)})},{key:"handleAnswerFromTracker",value:(x=y(m().m(function t(e){var r;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this._localPc&&null!=e&&e.sdp_answer){t.n=1;break}return t.a(2);case 1:if(t.p=1,"have-local-offer"===this._localPc.signalingState){t.n=2;break}return console.warn("[Seeder] Cannot apply answer: signalingState =",this._localPc.signalingState),t.a(2);case 2:return t.n=3,this._localPc.setRemoteDescription({type:"answer",sdp:e.sdp_answer});case 3:console.log("[Seeder] WebRTC connection established with leecher ".concat(e.peer_id)),this.peers.set(e.peer_id,{connection:this._localPc,channel:null,info:{peer_id:e.peer_id},connected:!1}),this._localPc=null,this._localSdp=null,t.n=5;break;case 4:t.p=4,r=t.v,console.error("[Seeder] Error applying SDP answer:",r);case 5:return t.a(2)}},t,this,[[1,4]])})),function(t){return x.apply(this,arguments)})},{key:"setupDataChannel",value:function(t,e){var r=this;t.binaryType="arraybuffer",t.onopen=function(){console.log("[Leecher] Data channel opened with peer",null==e?void 0:e.peer_id),null!=e&&e.peer_id&&r.peers.has(e.peer_id)&&(r.peers.get(e.peer_id).connected=!0),r.requestedPieces.clear(),r._requestMissingPieces()},t.onclose=function(){return console.log("[Leecher] Data channel closed")},t.onerror=function(t){return console.error("[Leecher] Data channel error:",t)},t.onmessage=function(i){return r.handleMessage(i.data,e,t)}}},{key:"handleMessage",value:function(t,e,r){try{var i;if(t instanceof ArrayBuffer)i=new DataView(t);else{if(!ArrayBuffer.isView(t))return;i=new DataView(t.buffer,t.byteOffset,t.byteLength)}var n=i.getUint8(0);if(1===n){var o=i.getUint32(1,!1);this.handlePieceRequest(o,r)}else if(2===n){var a=i.getUint32(1,!1),s=t instanceof ArrayBuffer?new Uint8Array(t,5):t.subarray(5);this.handlePieceData(a,s,e)}else if(4===n){if(i.byteLength<13)return;var h=i.getUint32(1,!1),u=i.getUint32(5,!1),f=i.getUint32(9,!1),l=t instanceof ArrayBuffer?new Uint8Array(t,13):t.subarray(13);this._handlePieceChunk(h,u,f,l,e)}}catch(t){console.error("Error handling message:",t)}}},{key:"_handlePieceChunk",value:function(t,e,r,i,n){this._pieceChunks.has(t)||this._pieceChunks.set(t,{total:e,buf:new Uint8Array(e),received:0});var o=this._pieceChunks.get(t);o.buf.set(i,r),o.received+=i.length,o.received>=o.total&&(this._pieceChunks.delete(t),this.handlePieceData(t,o.buf,n))}},{key:"handlePieceRequest",value:function(t,e){var r=this;e._sendQueue||(e._sendQueue=Promise.resolve()),e._sendQueue=e._sendQueue.then(function(){return r._servePiece(t,e)})}},{key:"_servePiece",value:(E=y(m().m(function t(e,r){var i,n,o,a,s,h,u,f,l,c;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(r&&"open"===r.readyState){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,this._readPieceAsync(e);case 2:if((i=t.v)&&0!==i.length){t.n=3;break}return t.a(2);case 3:if(n=16384,!(i.length<=65531)){t.n=6;break}if(!(r.bufferedAmount>524288)){t.n=4;break}return t.n=4,this._waitForSendBuffer(r);case 4:if("open"===r.readyState){t.n=5;break}return t.a(2);case 5:(o=new Uint8Array(5+i.length))[0]=2,new DataView(o.buffer).setUint32(1,e,!1),o.set(i,5),r.send(o.buffer),t.n=12;break;case 6:a=i.length,(s=new DataView(new ArrayBuffer(13))).setUint8(0,4),s.setUint32(1,e,!1),s.setUint32(5,a,!1),h=0;case 7:if(!(h524288)){t.n=9;break}return t.n=9,this._waitForSendBuffer(r);case 9:if("open"===r.readyState){t.n=10;break}return t.a(2);case 10:u=Math.min(h+n,a),f=i.subarray(h,u),l=new Uint8Array(13+f.length),s.setUint32(9,h,!1),l.set(new Uint8Array(s.buffer),0),l.set(f,13),r.send(l.buffer);case 11:h+=n,t.n=7;break;case 12:console.log("[Seeder] Sent piece ".concat(e," (").concat(i.length," bytes)")),t.n=14;break;case 13:t.p=13,c=t.v,console.error("[Seeder] Error serving piece:",c);case 14:return t.a(2)}},t,this,[[1,13]])})),function(t,e){return E.apply(this,arguments)})},{key:"_waitForSendBuffer",value:function(t){return new Promise(function(e){if("open"===t.readyState){t.bufferedAmountLowThreshold=65536,t.addEventListener("bufferedamountlow",e,{once:!0});var r=function(){"open"!==t.readyState||t.bufferedAmount<=65536?e():setTimeout(r,10)};setTimeout(r,10)}else e()})}},{key:"_evaluatePeerSpeed",value:function(t,e){var r;if(!e.blacklisted){var i=null!==(r=this.client.options.slowPeerThresholdMs)&&void 0!==r?r:8e3;if(!(e.responseTimes.length<5)){var n=e.responseTimes.slice(-5),o=n.reduce(function(t,e){return t+e},0)/n.length;o>i&&this._blacklistPeer(t,"avg response ".concat(o.toFixed(0)," ms > ").concat(i," ms"))}}}},{key:"_blacklistPeer",value:function(t,e){var r=this._peerStats.get(t);if(r&&!r.blacklisted){r.blacklisted=!0,console.warn("[Leecher] Peer ".concat(String(t).slice(0,16),"… blacklisted — ").concat(e));var i,n=l(r.pendingRequests);try{for(n.s();!(i=n.n()).done;){var o=f(i.value,1)[0];this.requestedPieces.delete(o)}}catch(t){n.e(t)}finally{n.f()}r.pendingRequests.clear(),this._requestMissingPieces()}}},{key:"_startPeerSpeedCheck",value:function(){var t,e,r=this,i=null!==(t=this.client.options.peerRequestTimeoutMs)&&void 0!==t?t:3e4,n=null!==(e=this.client.options.maxPeerTimeouts)&&void 0!==e?e:3,o=function(){if(r.active){var t,e=Date.now(),a=l(r._peerStats);try{for(a.s();!(t=a.n()).done;){var s=f(t.value,2),h=s[0],u=s[1];if(!u.blacklisted){var c,d=0,p=l(u.pendingRequests);try{for(p.s();!(c=p.n()).done;){var m=f(c.value,2),b=m[0];e-m[1]>i&&(u.pendingRequests.delete(b),r.requestedPieces.delete(b),d++)}}catch(t){p.e(t)}finally{p.f()}d>0&&r._requestMissingPieces(),d>=n&&r._blacklistPeer(h,"".concat(d," requests timed out (>").concat(i/1e3," s)"))}}}catch(t){a.e(t)}finally{a.f()}setTimeout(o,1e4)}};setTimeout(o,1e4)}},{key:"_readPiece",value:function(t){var e,r,i,o=(null===(e=this.data.torrent)||void 0===e?void 0:e._pieceLength)||this.pieceLength,a=t*o,s=Math.min(a+o,this.totalSize);if(a>=this.totalSize)return null;var h=null===(r=this.data.torrent)||void 0===r?void 0:r._filePaths;if(h&&this.client.fs)return this._readRangeFromDisk(h,a,s);var u=null===(i=this.data.torrent)||void 0===i?void 0:i._originalFiles;if(u){var f=n.concat(u);return f.slice(a,Math.min(s,f.length))}return null}},{key:"_readRangeFromDisk",value:function(t,e,r){var i,o=this.client.fs,a=n.alloc(r-e),s=0,h=0,u=l(t);try{for(u.s();!(i=u.n()).done;){var f=i.value,c=h+f.size;if(c<=e)h=c;else{if(h>=r)break;var d=Math.max(e,h)-h,p=Math.min(r,c)-h-d,m=this._fdCache.get(f.path);void 0===m&&(m=o.openSync(f.path,"r"),this._fdCache.set(f.path,m)),o.readSync(m,a,s,p,d),s+=p,h=c}}}catch(t){u.e(t)}finally{u.f()}return a}},{key:"_readPieceAsync",value:(A=y(m().m(function t(e){var r,i,n,o,a,s;return m().w(function(t){for(;;)switch(t.n){case 0:if(n=(null===(r=this.data.torrent)||void 0===r?void 0:r._pieceLength)||this.pieceLength,o=e*n,a=Math.min(o+n,this.totalSize),!(o>=this.totalSize)){t.n=1;break}return t.a(2,null);case 1:if(!(s=null===(i=this.data.torrent)||void 0===i?void 0:i._fileObjects)){t.n=3;break}return t.n=2,this._readRangeFromFileObjects(s,o,a);case 2:return t.a(2,t.v);case 3:return t.a(2,this._readPiece(e))}},t,this)})),function(t){return A.apply(this,arguments)})},{key:"_readRangeFromFileObjects",value:(k=y(m().m(function t(e,r,i){var n,o,a,s,h,u,f,c,d,p,b,g;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:n=new Uint8Array(i-r),o=0,a=0,s=l(e),t.p=1,s.s();case 2:if((h=s.n()).done){t.n=7;break}if(u=h.value,!((f=a+u.size)<=r)){t.n=3;break}return a=f,t.a(3,6);case 3:if(!(a>=i)){t.n=4;break}return t.a(3,7);case 4:return c=Math.max(r,a)-a,d=Math.min(i,f)-a,p=d-c,t.n=5,u.file.slice(c,d).arrayBuffer();case 5:b=t.v,n.set(new Uint8Array(b),o),o+=p,a=f;case 6:t.n=2;break;case 7:t.n=9;break;case 8:t.p=8,g=t.v,s.e(g);case 9:return t.p=9,s.f(),t.f(9);case 10:return t.a(2,n)}},t,null,[[1,8,9,10]])})),function(t,e,r){return k.apply(this,arguments)})},{key:"handlePieceData",value:function(t,e,r){var i=this;this.pieces.has(t)||this._verifyPiece(t,e).then(function(n){if(!n)return console.warn("[Leecher] Piece ".concat(t," hash mismatch — discarding, will re-request")),void i.requestedPieces.delete(t);var o=null==r?void 0:r.peer_id;if(o){var a=i._peerStats.get(o);if(a){var s=a.pendingRequests.get(t);void 0!==s&&(a.responseTimes.push(Date.now()-s),a.responseTimes.length>10&&a.responseTimes.shift(),a.pendingRequests.delete(t),i._evaluatePeerSpeed(o,a))}}i.pieces.set(t,e),i.requestedPieces.delete(t);var h=Math.min(e.length,i.totalSize-i.downloaded);i.downloaded+=h,console.log("[Leecher] Piece ".concat(t," OK (").concat(e.length," B) — ")+"".concat(i.pieces.size,"/").concat(i.pieceCount," pieces")),"function"==typeof i.onPieceReceived&&i.onPieceReceived(t,e),i.updateProgress(),i._downloadCompleted||i._requestMissingPieces()})}},{key:"_verifyPiece",value:(S=y(m().m(function t(e,i){var o,a,s,h,u,f,l,c,d,p;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(a=null===(o=this.data.info)||void 0===o?void 0:o.pieces){t.n=1;break}return t.a(2,!0);case 1:if((s=a.slice(20*e,20*e+20))&&!(s.length<20)){t.n=2;break}return t.a(2,!0);case 2:if(t.p=2,"undefined"==typeof window||null===(u=window.crypto)||void 0===u||!u.subtle){t.n=4;break}return f=i instanceof Uint8Array?i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength):i,t.n=3,window.crypto.subtle.digest("SHA-1",f);case 3:l=t.v,h=new Uint8Array(l),t.n=5;break;case 4:c=r(1565).createHash("sha1").update(i instanceof n?i:n.from(i)).digest(),h=new Uint8Array(c);case 5:t.n=7;break;case 6:return t.p=6,p=t.v,console.warn("[RtcTorrent] SHA-1 verify failed:",p.message),t.a(2,!0);case 7:d=0;case 8:if(!(d<20)){t.n=10;break}if(h[d]===(n.isBuffer(s),s[d])){t.n=9;break}return t.a(2,!1);case 9:d++,t.n=8;break;case 10:return t.a(2,!0)}},t,this,[[2,6]])})),function(t,e){return S.apply(this,arguments)})},{key:"handleOffer",value:(_=y(m().m(function t(e){var r,i,n,o=this;return m().w(function(t){for(;;)switch(t.n){case 0:if(r=this.client.getRTCPeerConnection()){t.n=1;break}return t.a(2);case 1:return(i=new r({iceServers:this.client.options.iceServers})).ondatachannel=function(t){return o.setupDataChannel(t.channel,null)},t.n=2,i.setRemoteDescription({type:"offer",sdp:e});case 2:return t.n=3,i.createAnswer();case 3:return n=t.v,t.n=4,i.setLocalDescription(n);case 4:this.signalChannel.sendAnswer(n.sdp),this.peers.set("incoming_".concat(Date.now()),{connection:i,channel:null,info:{},connected:!1});case 5:return t.a(2)}},t,this)})),function(t){return _.apply(this,arguments)})},{key:"handleAnswer",value:(w=y(m().m(function t(e){var r,i,n,o,a,s,h;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:r=l(this.peers),t.p=1,r.s();case 2:if((i=r.n()).done){t.n=7;break}if(o=f(i.value,2),(a=o[1]).connected||"have-local-offer"!==(null===(n=a.connection)||void 0===n?void 0:n.signalingState)){t.n=6;break}return t.p=3,t.n=4,a.connection.setRemoteDescription({type:"answer",sdp:e});case 4:return a.connected=!0,t.a(3,7);case 5:t.p=5,s=t.v,console.error("Error setting remote answer:",s);case 6:t.n=2;break;case 7:t.n=9;break;case 8:t.p=8,h=t.v,r.e(h);case 9:return t.p=9,r.f(),t.f(9);case 10:return t.a(2)}},t,this,[[3,5],[1,8,9,10]])})),function(t){return w.apply(this,arguments)})},{key:"requestPieceFromPeers",value:(g=y(m().m(function t(e){var r,i,n,o,a,s,h,u,c,d,p,b,g;return m().w(function(t){for(;;)switch(t.n){case 0:(r=new Uint8Array(5))[0]=1,new DataView(r.buffer).setUint32(1,e,!1),i=[],n=l(this.peers);try{for(n.s();!(o=n.n()).done;)h=f(o.value,2),u=h[0],c=h[1],"open"!==(null===(a=c.channel)||void 0===a?void 0:a.readyState)||null!==(s=this._peerStats.get(u))&&void 0!==s&&s.blacklisted||i.push({peer:c,peerId:u})}catch(t){n.e(t)}finally{n.f()}if(d=!1,i.length>0){p=i[e%i.length],b=p.peer,g=p.peerId;try{b.channel.send(r.buffer),d=!0,this._peerStats.has(g)||this._peerStats.set(g,{pendingRequests:new Map,responseTimes:[],blacklisted:!1}),this._peerStats.get(g).pendingRequests.set(e,Date.now())}catch(t){}}d||(this.webseeds.length?this._fetchPieceFromWebseed(e):console.log("[Leecher] No open channel to request piece ".concat(e)));case 1:return t.a(2)}},t,this)})),function(t){return g.apply(this,arguments)})},{key:"updateProgress",value:function(){!this._downloadCompleted&&this.pieceCount>0&&this.pieces.size>=this.pieceCount&&(this._downloadCompleted=!0,this.onDownloadComplete())}},{key:"onDownloadComplete",value:function(){console.log("[Leecher] Download complete!")}},{key:"streamVideo",value:(b=y(m().m(function t(){var e,r,i,n,o,a,s,h,u,f,l,c=arguments;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(r=c.length>0&&void 0!==c[0]?c[0]:0,n=c.length>2&&void 0!==c[2]?c[2]:{},i=c.length>1?c[1]:void 0){t.n=1;break}throw new Error("videoElement is required");case 1:if(o=this.files[r]){t.n=2;break}throw new Error("File at index ".concat(r," not found"));case 2:if("undefined"!=typeof window){t.n=3;break}throw new Error("streamVideo is browser-only");case 3:return a=Math.floor(o.offset/this.pieceLength),t.n=4,this._waitForPiece(a);case 4:if(null===(e=navigator.serviceWorker)||void 0===e||!e.controller){t.n=8;break}return t.p=5,console.log("[RtcTorrent] Service Worker active — seamless SW stream"),t.n=6,this._streamWithSW(o,i,n);case 6:return t.a(2);case 7:t.p=7,f=t.v,console.warn("[RtcTorrent] SW streaming failed, falling back:",f.message);case 8:if(!((s=this._getFaststartMoovEnd(this.pieces.get(a)))>0)){t.n=10;break}return console.log("[RtcTorrent] Faststart MP4 — blob rebuild streaming"),this._moovEndByte=s,t.n=9,this._streamFaststart(o,i,n);case 9:return t.a(2);case 10:if(!((h=n.mimeType||this._detectMimeType(this.pieces.get(a)))&&window.MediaSource&&MediaSource.isTypeSupported(h))){t.n=14;break}return t.p=11,t.n=12,this._streamWithMSE(o,i,h);case 12:return t.a(2);case 13:t.p=13,l=t.v,console.warn("[RtcTorrent] MSE streaming failed, falling back to Blob URL:",l.message),null!==(u=i.src)&&void 0!==u&&u.startsWith("blob:")&&URL.revokeObjectURL(i.src);case 14:return t.n=15,this._playAsBlob(o,i,n.onProgress);case 15:return t.a(2)}},t,this,[[11,13],[5,7]])})),function(){return b.apply(this,arguments)})},{key:"_streamWithSW",value:(p=y(m().m(function t(e,r){var i,n,o,a,s,h,u,f,l,c,d,p,b,g,y,v,w,M,_,S,k,A=this,E=arguments;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(i=(E.length>2&&void 0!==E[2]?E[2]:{}).onProgress,n=navigator.serviceWorker.controller){t.n=1;break}throw new Error("No active Service Worker controller");case 1:o="".concat((this.data.infoHash||"x").slice(0,8),"-").concat(Date.now()),a=this._getMimeForFile(e)||"video/mp4",s="__rtc_stream__/".concat(o,"?mime=").concat(encodeURIComponent(a),"&size=").concat(e.length),h=Math.floor(e.offset/this.pieceLength),u=Math.ceil((e.offset+e.length)/this.pieceLength),f=e.offset%this.pieceLength,l=u-h,r.src=s,r.play().catch(function(t){return console.warn("[RtcTorrent] SW autoplay blocked (click play):",t.message)}),c=0,d=h;case 2:if(!(d>>0;if(r<16)return null;var i=new Set(["iso5","iso6","cmfc","cmff","dash"]),n=String.fromCharCode(e[8],e[9],e[10],e[11]);if(i.has(n))return'video/mp4; codecs="avc1.42E01E,mp4a.40.2"';for(var o=Math.min(r,e.length),a=16;a+4<=o;a+=4){var s=String.fromCharCode(e[a],e[a+1],e[a+2],e[a+3]);if(i.has(s))return'video/mp4; codecs="avc1.42E01E,mp4a.40.2"'}return null}},{key:"_getFaststartMoovEnd",value:function(t){if(!t||t.length<16)return 0;var e=t instanceof Uint8Array?t:new Uint8Array(t);if("ftyp"!==String.fromCharCode(e[4],e[5],e[6],e[7]))return 0;var r=(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;if(r<8||r+8>e.length)return 0;for(var i=r;i+8<=e.length;){var n=(e[i]<<24|e[i+1]<<16|e[i+2]<<8|e[i+3])>>>0,o=String.fromCharCode(e[i+4],e[i+5],e[i+6],e[i+7]);if(n<8)return 0;if("moov"===o)return i+n;if("mdat"===o)return 0;i+=n}return 0}},{key:"_streamFaststart",value:(d=y(m().m(function t(e,r){var i,n,o,a,s,h,f,l,c,d,p,b,g,v,w,M,_,S,k,A,E,x,R,T,B,O,P,I,j=this,L=arguments;return m().w(function(t){for(;;)switch(t.n){case 0:n=(i=L.length>2&&void 0!==L[2]?L[2]:{}).onProgress,o=i.initialExtra,a=void 0===o?50:o,s=200,h=5e3,f=2e3,l=Math.floor(e.offset/this.pieceLength),c=Math.ceil((e.offset+e.length)/this.pieceLength),d=c-l,p=this._moovEndByte||0,b=Math.max(l,Math.floor((e.offset+p-1)/this.pieceLength)),g=Math.min(b+a,c-1),v=g-l+1,console.log("[RtcTorrent] faststart stream: moovEndByte=".concat(p)+" moovEndPiece=".concat(b," initialEndPiece=").concat(g)+" totalPieces=".concat(d)),w=l;case 1:if(!(w<=g)){t.n=4;break}return t.n=2,this._waitForPiece(w);case 2:"function"==typeof n&&n(Math.floor((w-l+1)/v*100));case 3:w++,t.n=1;break;case 4:return M=null,_=-1,S=!1,k=-1,A=!1,E=0,x=function(){for(var t=_>=l?_:l-1;t+1=c||j.pieces.has(t)||(j.requestedPieces.delete(t),j.requestPieceFromPeers(t),j.requestedPieces.add(t))},T=function(){var t=y(m().m(function t(i){var n,o,a,s,u,f,d,p,b,g,y,v,w,x;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!(i<=_)){t.n=1;break}return t.a(2);case 1:if(!S){t.n=2;break}return k=Math.max(k,i),t.a(2);case 2:S=!0,t.p=3,n=[],o=e.offset%j.pieceLength,a=0,s=l;case 4:if(!(s<=i)){t.n=7;break}if(u=j.pieces.get(s)){t.n=5;break}return t.a(3,7);case 5:f=u instanceof Uint8Array?u:new Uint8Array(u),d=s===l?o:0,p=f.length,s===c-1&&(p=d+(e.length-a)),n.push(f.slice(d,p)),a+=p-d,_=s;case 6:s++,t.n=4;break;case 7:if(0!==n.length){t.n=8;break}return t.a(2);case 8:return b=isNaN(r.currentTime)?0:r.currentTime,g=!r.paused||r.readyState<3||r.ended,M&&URL.revokeObjectURL(M),y=j._getMimeForFile(e)||"video/mp4",v=new Blob(n,{type:y}),M=URL.createObjectURL(v),r.src=M,r.load(),t.n=9,new Promise(function(t){var e=function(){r.removeEventListener("loadedmetadata",e);var i=Math.min(b,r.duration||0);i>.5&&(r.currentTime=i),t()};r.addEventListener("loadedmetadata",e,{once:!0}),setTimeout(t,2e3)});case 9:A&&!g||(A=!0,r.play().catch(function(t){console.warn("[RtcTorrent] Faststart autoplay blocked (click play):",t.message)})),E=Date.now(),console.log("[RtcTorrent] blob extended to piece ".concat(_,"/").concat(c-1)+" (".concat((v.size/1024/1024).toFixed(1)," MB)"));case 10:return t.p=10,S=!1,k>_&&(w=k,k=-1,x=Math.max(0,h-(Date.now()-E)),setTimeout(function(){return T(w)},x)),t.f(10);case 11:return t.a(2)}},t,null,[[3,,10,11]])}));return function(e){return t.apply(this,arguments)}}(),B=this.onPieceReceived,O=function(t){clearInterval(t),r.removeEventListener("waiting",P),r.removeEventListener("ended",P),j.onPieceReceived=B},t.n=5,T(g);case 5:P=function(){var t=x();t>_?Date.now()-E>=h&&T(t).catch(function(){}):R(_+1)},r.addEventListener("waiting",P),r.addEventListener("ended",P),this.onPieceReceived=function(t,e){B&&B.call(j,t,e)},I=setInterval(y(m().m(function t(){var e,r,i;return m().w(function(t){for(;;)switch(t.n){case 0:if(e=x(),"function"==typeof n&&(r=u(j.pieces.keys()).filter(function(t){return t>=l&&t=c-1)){t.n=2;break}return O(I),t.n=1,T(c-1);case 1:return console.log("[RtcTorrent] faststart stream complete — full blob playing"),t.a(2);case 2:if(e<=_&&(i=_+1)_+s&&Date.now()-E>=h)){t.n=3;break}return t.n=3,T(e);case 3:return t.a(2)}},t)})),f);case 6:return t.a(2)}},t,this)})),function(t,e){return d.apply(this,arguments)})},{key:"_streamWithMSEProgressive",value:(c=y(m().m(function t(e,r){var i,n,o,a,s,h,u,f,l,c,d,p,b,g,v,w,M,_,S,k,A,E,x,R,T=arguments;return m().w(function(t){for(;;)switch(t.n){case 0:if(i=(T.length>2&&void 0!==T[2]?T[2]:{}).onProgress,n=['video/mp4; codecs="avc1.64001E,mp4a.40.2"','video/mp4; codecs="avc1.42E01E,mp4a.40.2"','video/mp4; codecs="avc1.64001E"',"video/mp4"].find(function(t){return MediaSource.isTypeSupported(t)})){t.n=1;break}throw new Error("MSE: no supported MP4 MIME type found");case 1:return o=Math.floor(e.offset/this.pieceLength),a=Math.ceil((e.offset+e.length)/this.pieceLength),s=e.offset%this.pieceLength,h=a-o,u=524288,f=new MediaSource,l=URL.createObjectURL(f),r.src=l,t.n=2,new Promise(function(t,e){f.addEventListener("sourceopen",t,{once:!0}),setTimeout(function(){return e(new Error("sourceopen timeout"))},1e4)});case 2:URL.revokeObjectURL(l),c=f.addSourceBuffer(n),d=function(){return new Promise(function(t,e){c.addEventListener("updateend",t,{once:!0}),c.addEventListener("error",e,{once:!0})})},p=function(){var t=y(m().m(function t(e){var i,n;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,c.appendBuffer(e),t.n=1,d();case 1:t.n=5;break;case 2:if(t.p=2,"QuotaExceededError"===(n=t.v).name){t.n=3;break}throw n;case 3:return i=Math.max(0,r.currentTime-5),c.remove(0,i),t.n=4,d();case 4:return c.appendBuffer(e),t.n=5,d();case 5:return t.a(2)}},t,null,[[0,2]])}));return function(e){return t.apply(this,arguments)}}(),b=!1,r.addEventListener("loadedmetadata",function(){b=!0},{once:!0}),g=[],v=0,w=0,M=function(){var t=y(m().m(function t(){var e,r,i,n,o;return m().w(function(t){for(;;)switch(t.n){case 0:if(g.length){t.n=1;break}return t.a(2);case 1:if(1===g.length)e=g[0];else for(e=new Uint8Array(v),r=0,i=0,n=g;i=u||R)){t.n=7;break}return t.n=7,M();case 7:"function"==typeof i&&i(Math.floor((_-o+1)/h*100));case 8:_++,t.n=3;break;case 9:"open"===f.readyState&&f.endOfStream();case 10:return t.a(2)}},t,this)})),function(t,e){return c.apply(this,arguments)})},{key:"_waitForPiece",value:(h=y(m().m(function t(e){var r,i;return m().w(function(t){for(;;)switch(t.n){case 0:r=3e3,i=0;case 1:if(this.pieces.has(e)){t.n=3;break}return(!this.requestedPieces.has(e)||i>=r)&&(this.requestedPieces.delete(e),this.requestPieceFromPeers(e),this.requestedPieces.add(e),i=0),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:i+=100,t.n=1;break;case 3:return t.a(2)}},t,this)})),function(t){return h.apply(this,arguments)})},{key:"_streamWithMSE",value:(s=y(m().m(function t(e,r,i){var n,o,a,s=this;return m().w(function(t){for(;;)switch(t.n){case 0:return n=Math.floor(e.offset/this.pieceLength),o=Math.ceil((e.offset+e.length)/this.pieceLength),a=new MediaSource,this.mediaSource=a,r.src=URL.createObjectURL(a),t.n=1,new Promise(function(t,e){a.addEventListener("sourceopen",y(m().m(function r(){var h,u,f;return m().w(function(r){for(;;)switch(r.p=r.n){case 0:return r.p=0,h=a.addSourceBuffer(i),s.sourceBuffer=h,u=s.pieces.get(n),r.n=1,s._appendToSourceBuffer(h,u);case 1:t(),r.n=3;break;case 2:return r.p=2,f=r.v,e(f),r.a(2);case 3:return r.n=4,y(m().m(function t(){var e,r;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:t.p=0,e=n+1;case 1:if(!(e0&&void 0!==l[0]?l[0]:0)?this.files[e]:e){t.n=1;break}throw new Error("File not found");case 1:i=Math.floor(r.offset/this.pieceLength),n=Math.ceil((r.offset+r.length)/this.pieceLength),o=r.offset%this.pieceLength,a=[],s=i;case 2:if(!(s0&&void 0!==h[0]?h[0]:0,r=this.files[e]){t.n=1;break}throw new Error("File at index ".concat(e," not found"));case 1:i=Math.floor(r.offset/this.pieceLength),n=Math.ceil((r.offset+r.length)/this.pieceLength),o=i;case 2:if(!(o fallback:",s.message);case 9:o=URL.createObjectURL(e),a=Object.assign(document.createElement("a"),{href:o,download:r}),document.body.appendChild(a),a.click(),document.body.removeChild(a),setTimeout(function(){return URL.revokeObjectURL(o)},3e4);case 10:return t.a(2)}},t,null,[[2,7]])})),function(e,r){return t.apply(this,arguments)})},{key:"isPlayable",value:function(t){var e;if("undefined"==typeof window)return!1;var r={mp4:"video/mp4",m4v:"video/mp4",mov:"video/quicktime",webm:"video/webm",ogv:"video/ogg",mp3:"audio/mpeg",m4a:"audio/mp4",ogg:"audio/ogg",wav:"audio/wav",flac:"audio/flac",aac:"audio/aac",opus:"audio/ogg; codecs=opus"}[((null===(e=(t||"").split("/").pop())||void 0===e?void 0:e.split(".").pop())||"").toLowerCase()];if(!r)return!1;var i=r.startsWith("audio/")?"audio":"video";return""!==document.createElement(i).canPlayType(r)}}]);var t,e,o,a,s,h,c,d,p,b,g,w,_,S,k,A,E,x,T,B,O,P,I,j,L,C}(),R=function(t){function e(t,r){var i,n,o,s;return v(this,e),(n=this,o=e,o=h(o),i=function(t,e){if(e&&("object"==p(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(n,a()?Reflect.construct(o,s||[],h(n).constructor):o.apply(n,s))).trackerUrl=t,i.infoHash=r,i}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&s(t,e)}(e,t),M(e,[{key:"_urlEncodeBytes",value:function(t){for(var e="",r=0;r0&&void 0!==arguments[0]?arguments[0]:{},i=new(function(){if(void 0!==globalThis.RTCPeerConnection)return globalThis.RTCPeerConnection;for(var t="undefined"!=typeof require?require:r(6589),e=0,i=["wrtc","@roamhq/wrtc","node-webrtc"];e0?a-4:a;for(r=0;r>16&255,u[f++]=e>>8&255,u[f++]=255&e;return 2===h&&(e=i[t.charCodeAt(r)]<<2|i[t.charCodeAt(r+1)]>>4,u[f++]=255&e),1===h&&(e=i[t.charCodeAt(r)]<<10|i[t.charCodeAt(r+1)]<<4|i[t.charCodeAt(r+2)]>>2,u[f++]=e>>8&255,u[f++]=255&e),u},e.fromByteArray=function(t){for(var e,i=t.length,n=i%3,o=[],a=16383,s=0,h=i-n;sh?h:s+a));return 1===n?(e=t[i-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===n&&(e=(t[i-2]<<8)+t[i-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),o.join("")};for(var r=[],i=[],n="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0;a<64;++a)r[a]=o[a],i[o.charCodeAt(a)]=a;function s(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function h(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function u(t,e,r){for(var i,n=[],o=e;o=48)i=10*i+(r-48);else if(o!==e||43!==r){if(o!==e||45!==r){if(46===r)break;throw new Error("not a number: buffer["+o+"] = "+r)}n=-1}}return i*n}function o(t,e,r,n){return null==t||0===t.length?null:("number"!=typeof e&&null==n&&(n=e,e=void 0),"number"!=typeof r&&null==n&&(n=r,r=void 0),o.position=0,o.encoding=n||null,o.data=i.isBuffer(t)?t.slice(e,r):i.from(t),o.bytes=o.data.length,o.next())}o.bytes=0,o.position=0,o.data=null,o.encoding=null,o.next=function(){switch(o.data[o.position]){case 100:return o.dictionary();case 108:return o.list();case 105:return o.integer();default:return o.buffer()}},o.find=function(t){let e=o.position;const r=o.data.length,i=o.data;for(;e=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void i(!1,"Invalid character in "+t)}function h(t,e,r){var i=s(t,r);return r-1>=e&&(i|=s(t,r-1)<<4),i}function u(t,e,r,n){for(var o=0,a=0,s=Math.min(t.length,r),h=e;h=49?u-49+10:u>=17?u-17+10:u,i(u>=0&&a0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n=0;n-=3)a=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[o]|=a<>>26-s&67108863,(s+=24)>=26&&(s-=26,o++);else if("le"===r)for(n=0,o=0;n>>26-s&67108863,(s+=24)>=26&&(s-=26,o++);return this._strip()},o.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i=e;i-=2)n=h(t,e,i)<=18?(o-=18,a+=1,this.words[a]|=n>>>26):o+=8;else for(i=(t.length-e)%2==0?e+1:e;i=18?(o-=18,a+=1,this.words[a]|=n>>>26):o+=8;this._strip()},o.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=e)i++;i--,n=n/e|0;for(var o=t.length-r,a=o%i,s=Math.min(o,o-a)+r,h=0,f=r;f1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?""}var c=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],d=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],p=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function m(t,e,r){r.negative=e.negative^t.negative;var i=t.length+e.length|0;r.length=i,i=i-1|0;var n=0|t.words[0],o=0|e.words[0],a=n*o,s=67108863&a,h=a/67108864|0;r.words[0]=s;for(var u=1;u>>26,l=67108863&h,c=Math.min(u,e.length-1),d=Math.max(0,u-t.length+1);d<=c;d++){var p=u-d|0;f+=(a=(n=0|t.words[p])*(o=0|e.words[d])+l)/67108864|0,l=67108863&a}r.words[u]=0|l,h=0|f}return 0!==h?r.words[u]=0|h:r.length--,r._strip()}o.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,o=0,a=0;a>>24-n&16777215,(n+=2)>=26&&(n-=26,a--),r=0!==o||a!==this.length-1?c[6-h.length]+h+r:h+r}for(0!==o&&(r=o.toString(16)+r);r.length%e!==0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var u=d[t],f=p[t];r="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modrn(f).toString(t);r=(l=l.idivn(f)).isZero()?m+r:c[u-m.length]+m+r}for(this.isZero()&&(r="0"+r);r.length%e!==0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16,2)},a&&(o.prototype.toBuffer=function(t,e){return this.toArrayLike(a,t,e)}),o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,r){this._strip();var n=this.byteLength(),o=r||Math.max(1,n);i(n<=o,"byte array longer than desired length"),i(o>0,"Requested array length <= 0");var a=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](a,n),a},o.prototype._toArrayLikeLE=function(t,e){for(var r=0,i=0,n=0,o=0;n>8&255),r>16&255),6===o?(r>24&255),i=0,o=0):(i=a>>>24,o+=2)}if(r=0&&(t[r--]=a>>8&255),r>=0&&(t[r--]=a>>16&255),6===o?(r>=0&&(t[r--]=a>>24&255),i=0,o=0):(i=a>>>24,o+=2)}if(r>=0)for(t[r--]=i;r>=0;)t[r--]=0},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 8191&e||(r+=13,e>>>=13),127&e||(r+=7,e>>>=7),15&e||(r+=4,e>>>=4),3&e||(r+=2,e>>>=2),1&e||r++,r},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;et.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;rt.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var i=0;it.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n0&&(this.words[n]=~this.words[n]&67108863>>26-r),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<t.length?(r=this,i=t):(r=t,i=this);for(var n=0,o=0;o>>26;for(;0!==n&&o>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;ot.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,i,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=t):(r=t,i=this);for(var o=0,a=0;a>26,this.words[a]=67108863&e;for(;0!==o&&a>26,this.words[a]=67108863&e;if(0===o&&a>>13,d=0|a[1],p=8191&d,m=d>>>13,b=0|a[2],g=8191&b,y=b>>>13,v=0|a[3],w=8191&v,M=v>>>13,_=0|a[4],S=8191&_,k=_>>>13,A=0|a[5],E=8191&A,x=A>>>13,R=0|a[6],T=8191&R,B=R>>>13,O=0|a[7],P=8191&O,I=O>>>13,j=0|a[8],L=8191&j,C=j>>>13,N=0|a[9],q=8191&N,U=N>>>13,D=0|s[0],F=8191&D,z=D>>>13,H=0|s[1],W=8191&H,Z=H>>>13,K=0|s[2],V=8191&K,G=K>>>13,X=0|s[3],Y=8191&X,J=X>>>13,$=0|s[4],Q=8191&$,tt=$>>>13,et=0|s[5],rt=8191&et,it=et>>>13,nt=0|s[6],ot=8191&nt,at=nt>>>13,st=0|s[7],ht=8191&st,ut=st>>>13,ft=0|s[8],lt=8191&ft,ct=ft>>>13,dt=0|s[9],pt=8191&dt,mt=dt>>>13;r.negative=t.negative^e.negative,r.length=19;var bt=(u+(i=Math.imul(l,F))|0)+((8191&(n=(n=Math.imul(l,z))+Math.imul(c,F)|0))<<13)|0;u=((o=Math.imul(c,z))+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,i=Math.imul(p,F),n=(n=Math.imul(p,z))+Math.imul(m,F)|0,o=Math.imul(m,z);var gt=(u+(i=i+Math.imul(l,W)|0)|0)+((8191&(n=(n=n+Math.imul(l,Z)|0)+Math.imul(c,W)|0))<<13)|0;u=((o=o+Math.imul(c,Z)|0)+(n>>>13)|0)+(gt>>>26)|0,gt&=67108863,i=Math.imul(g,F),n=(n=Math.imul(g,z))+Math.imul(y,F)|0,o=Math.imul(y,z),i=i+Math.imul(p,W)|0,n=(n=n+Math.imul(p,Z)|0)+Math.imul(m,W)|0,o=o+Math.imul(m,Z)|0;var yt=(u+(i=i+Math.imul(l,V)|0)|0)+((8191&(n=(n=n+Math.imul(l,G)|0)+Math.imul(c,V)|0))<<13)|0;u=((o=o+Math.imul(c,G)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,i=Math.imul(w,F),n=(n=Math.imul(w,z))+Math.imul(M,F)|0,o=Math.imul(M,z),i=i+Math.imul(g,W)|0,n=(n=n+Math.imul(g,Z)|0)+Math.imul(y,W)|0,o=o+Math.imul(y,Z)|0,i=i+Math.imul(p,V)|0,n=(n=n+Math.imul(p,G)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,G)|0;var vt=(u+(i=i+Math.imul(l,Y)|0)|0)+((8191&(n=(n=n+Math.imul(l,J)|0)+Math.imul(c,Y)|0))<<13)|0;u=((o=o+Math.imul(c,J)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,i=Math.imul(S,F),n=(n=Math.imul(S,z))+Math.imul(k,F)|0,o=Math.imul(k,z),i=i+Math.imul(w,W)|0,n=(n=n+Math.imul(w,Z)|0)+Math.imul(M,W)|0,o=o+Math.imul(M,Z)|0,i=i+Math.imul(g,V)|0,n=(n=n+Math.imul(g,G)|0)+Math.imul(y,V)|0,o=o+Math.imul(y,G)|0,i=i+Math.imul(p,Y)|0,n=(n=n+Math.imul(p,J)|0)+Math.imul(m,Y)|0,o=o+Math.imul(m,J)|0;var wt=(u+(i=i+Math.imul(l,Q)|0)|0)+((8191&(n=(n=n+Math.imul(l,tt)|0)+Math.imul(c,Q)|0))<<13)|0;u=((o=o+Math.imul(c,tt)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(E,F),n=(n=Math.imul(E,z))+Math.imul(x,F)|0,o=Math.imul(x,z),i=i+Math.imul(S,W)|0,n=(n=n+Math.imul(S,Z)|0)+Math.imul(k,W)|0,o=o+Math.imul(k,Z)|0,i=i+Math.imul(w,V)|0,n=(n=n+Math.imul(w,G)|0)+Math.imul(M,V)|0,o=o+Math.imul(M,G)|0,i=i+Math.imul(g,Y)|0,n=(n=n+Math.imul(g,J)|0)+Math.imul(y,Y)|0,o=o+Math.imul(y,J)|0,i=i+Math.imul(p,Q)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,tt)|0;var Mt=(u+(i=i+Math.imul(l,rt)|0)|0)+((8191&(n=(n=n+Math.imul(l,it)|0)+Math.imul(c,rt)|0))<<13)|0;u=((o=o+Math.imul(c,it)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(T,F),n=(n=Math.imul(T,z))+Math.imul(B,F)|0,o=Math.imul(B,z),i=i+Math.imul(E,W)|0,n=(n=n+Math.imul(E,Z)|0)+Math.imul(x,W)|0,o=o+Math.imul(x,Z)|0,i=i+Math.imul(S,V)|0,n=(n=n+Math.imul(S,G)|0)+Math.imul(k,V)|0,o=o+Math.imul(k,G)|0,i=i+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,J)|0)+Math.imul(M,Y)|0,o=o+Math.imul(M,J)|0,i=i+Math.imul(g,Q)|0,n=(n=n+Math.imul(g,tt)|0)+Math.imul(y,Q)|0,o=o+Math.imul(y,tt)|0,i=i+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,it)|0)+Math.imul(m,rt)|0,o=o+Math.imul(m,it)|0;var _t=(u+(i=i+Math.imul(l,ot)|0)|0)+((8191&(n=(n=n+Math.imul(l,at)|0)+Math.imul(c,ot)|0))<<13)|0;u=((o=o+Math.imul(c,at)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(P,F),n=(n=Math.imul(P,z))+Math.imul(I,F)|0,o=Math.imul(I,z),i=i+Math.imul(T,W)|0,n=(n=n+Math.imul(T,Z)|0)+Math.imul(B,W)|0,o=o+Math.imul(B,Z)|0,i=i+Math.imul(E,V)|0,n=(n=n+Math.imul(E,G)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,G)|0,i=i+Math.imul(S,Y)|0,n=(n=n+Math.imul(S,J)|0)+Math.imul(k,Y)|0,o=o+Math.imul(k,J)|0,i=i+Math.imul(w,Q)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(M,Q)|0,o=o+Math.imul(M,tt)|0,i=i+Math.imul(g,rt)|0,n=(n=n+Math.imul(g,it)|0)+Math.imul(y,rt)|0,o=o+Math.imul(y,it)|0,i=i+Math.imul(p,ot)|0,n=(n=n+Math.imul(p,at)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,at)|0;var St=(u+(i=i+Math.imul(l,ht)|0)|0)+((8191&(n=(n=n+Math.imul(l,ut)|0)+Math.imul(c,ht)|0))<<13)|0;u=((o=o+Math.imul(c,ut)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(L,F),n=(n=Math.imul(L,z))+Math.imul(C,F)|0,o=Math.imul(C,z),i=i+Math.imul(P,W)|0,n=(n=n+Math.imul(P,Z)|0)+Math.imul(I,W)|0,o=o+Math.imul(I,Z)|0,i=i+Math.imul(T,V)|0,n=(n=n+Math.imul(T,G)|0)+Math.imul(B,V)|0,o=o+Math.imul(B,G)|0,i=i+Math.imul(E,Y)|0,n=(n=n+Math.imul(E,J)|0)+Math.imul(x,Y)|0,o=o+Math.imul(x,J)|0,i=i+Math.imul(S,Q)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(k,Q)|0,o=o+Math.imul(k,tt)|0,i=i+Math.imul(w,rt)|0,n=(n=n+Math.imul(w,it)|0)+Math.imul(M,rt)|0,o=o+Math.imul(M,it)|0,i=i+Math.imul(g,ot)|0,n=(n=n+Math.imul(g,at)|0)+Math.imul(y,ot)|0,o=o+Math.imul(y,at)|0,i=i+Math.imul(p,ht)|0,n=(n=n+Math.imul(p,ut)|0)+Math.imul(m,ht)|0,o=o+Math.imul(m,ut)|0;var kt=(u+(i=i+Math.imul(l,lt)|0)|0)+((8191&(n=(n=n+Math.imul(l,ct)|0)+Math.imul(c,lt)|0))<<13)|0;u=((o=o+Math.imul(c,ct)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,i=Math.imul(q,F),n=(n=Math.imul(q,z))+Math.imul(U,F)|0,o=Math.imul(U,z),i=i+Math.imul(L,W)|0,n=(n=n+Math.imul(L,Z)|0)+Math.imul(C,W)|0,o=o+Math.imul(C,Z)|0,i=i+Math.imul(P,V)|0,n=(n=n+Math.imul(P,G)|0)+Math.imul(I,V)|0,o=o+Math.imul(I,G)|0,i=i+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,J)|0)+Math.imul(B,Y)|0,o=o+Math.imul(B,J)|0,i=i+Math.imul(E,Q)|0,n=(n=n+Math.imul(E,tt)|0)+Math.imul(x,Q)|0,o=o+Math.imul(x,tt)|0,i=i+Math.imul(S,rt)|0,n=(n=n+Math.imul(S,it)|0)+Math.imul(k,rt)|0,o=o+Math.imul(k,it)|0,i=i+Math.imul(w,ot)|0,n=(n=n+Math.imul(w,at)|0)+Math.imul(M,ot)|0,o=o+Math.imul(M,at)|0,i=i+Math.imul(g,ht)|0,n=(n=n+Math.imul(g,ut)|0)+Math.imul(y,ht)|0,o=o+Math.imul(y,ut)|0,i=i+Math.imul(p,lt)|0,n=(n=n+Math.imul(p,ct)|0)+Math.imul(m,lt)|0,o=o+Math.imul(m,ct)|0;var At=(u+(i=i+Math.imul(l,pt)|0)|0)+((8191&(n=(n=n+Math.imul(l,mt)|0)+Math.imul(c,pt)|0))<<13)|0;u=((o=o+Math.imul(c,mt)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,i=Math.imul(q,W),n=(n=Math.imul(q,Z))+Math.imul(U,W)|0,o=Math.imul(U,Z),i=i+Math.imul(L,V)|0,n=(n=n+Math.imul(L,G)|0)+Math.imul(C,V)|0,o=o+Math.imul(C,G)|0,i=i+Math.imul(P,Y)|0,n=(n=n+Math.imul(P,J)|0)+Math.imul(I,Y)|0,o=o+Math.imul(I,J)|0,i=i+Math.imul(T,Q)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(B,Q)|0,o=o+Math.imul(B,tt)|0,i=i+Math.imul(E,rt)|0,n=(n=n+Math.imul(E,it)|0)+Math.imul(x,rt)|0,o=o+Math.imul(x,it)|0,i=i+Math.imul(S,ot)|0,n=(n=n+Math.imul(S,at)|0)+Math.imul(k,ot)|0,o=o+Math.imul(k,at)|0,i=i+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ut)|0)+Math.imul(M,ht)|0,o=o+Math.imul(M,ut)|0,i=i+Math.imul(g,lt)|0,n=(n=n+Math.imul(g,ct)|0)+Math.imul(y,lt)|0,o=o+Math.imul(y,ct)|0;var Et=(u+(i=i+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;u=((o=o+Math.imul(m,mt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,i=Math.imul(q,V),n=(n=Math.imul(q,G))+Math.imul(U,V)|0,o=Math.imul(U,G),i=i+Math.imul(L,Y)|0,n=(n=n+Math.imul(L,J)|0)+Math.imul(C,Y)|0,o=o+Math.imul(C,J)|0,i=i+Math.imul(P,Q)|0,n=(n=n+Math.imul(P,tt)|0)+Math.imul(I,Q)|0,o=o+Math.imul(I,tt)|0,i=i+Math.imul(T,rt)|0,n=(n=n+Math.imul(T,it)|0)+Math.imul(B,rt)|0,o=o+Math.imul(B,it)|0,i=i+Math.imul(E,ot)|0,n=(n=n+Math.imul(E,at)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,at)|0,i=i+Math.imul(S,ht)|0,n=(n=n+Math.imul(S,ut)|0)+Math.imul(k,ht)|0,o=o+Math.imul(k,ut)|0,i=i+Math.imul(w,lt)|0,n=(n=n+Math.imul(w,ct)|0)+Math.imul(M,lt)|0,o=o+Math.imul(M,ct)|0;var xt=(u+(i=i+Math.imul(g,pt)|0)|0)+((8191&(n=(n=n+Math.imul(g,mt)|0)+Math.imul(y,pt)|0))<<13)|0;u=((o=o+Math.imul(y,mt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,i=Math.imul(q,Y),n=(n=Math.imul(q,J))+Math.imul(U,Y)|0,o=Math.imul(U,J),i=i+Math.imul(L,Q)|0,n=(n=n+Math.imul(L,tt)|0)+Math.imul(C,Q)|0,o=o+Math.imul(C,tt)|0,i=i+Math.imul(P,rt)|0,n=(n=n+Math.imul(P,it)|0)+Math.imul(I,rt)|0,o=o+Math.imul(I,it)|0,i=i+Math.imul(T,ot)|0,n=(n=n+Math.imul(T,at)|0)+Math.imul(B,ot)|0,o=o+Math.imul(B,at)|0,i=i+Math.imul(E,ht)|0,n=(n=n+Math.imul(E,ut)|0)+Math.imul(x,ht)|0,o=o+Math.imul(x,ut)|0,i=i+Math.imul(S,lt)|0,n=(n=n+Math.imul(S,ct)|0)+Math.imul(k,lt)|0,o=o+Math.imul(k,ct)|0;var Rt=(u+(i=i+Math.imul(w,pt)|0)|0)+((8191&(n=(n=n+Math.imul(w,mt)|0)+Math.imul(M,pt)|0))<<13)|0;u=((o=o+Math.imul(M,mt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,i=Math.imul(q,Q),n=(n=Math.imul(q,tt))+Math.imul(U,Q)|0,o=Math.imul(U,tt),i=i+Math.imul(L,rt)|0,n=(n=n+Math.imul(L,it)|0)+Math.imul(C,rt)|0,o=o+Math.imul(C,it)|0,i=i+Math.imul(P,ot)|0,n=(n=n+Math.imul(P,at)|0)+Math.imul(I,ot)|0,o=o+Math.imul(I,at)|0,i=i+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ut)|0)+Math.imul(B,ht)|0,o=o+Math.imul(B,ut)|0,i=i+Math.imul(E,lt)|0,n=(n=n+Math.imul(E,ct)|0)+Math.imul(x,lt)|0,o=o+Math.imul(x,ct)|0;var Tt=(u+(i=i+Math.imul(S,pt)|0)|0)+((8191&(n=(n=n+Math.imul(S,mt)|0)+Math.imul(k,pt)|0))<<13)|0;u=((o=o+Math.imul(k,mt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,i=Math.imul(q,rt),n=(n=Math.imul(q,it))+Math.imul(U,rt)|0,o=Math.imul(U,it),i=i+Math.imul(L,ot)|0,n=(n=n+Math.imul(L,at)|0)+Math.imul(C,ot)|0,o=o+Math.imul(C,at)|0,i=i+Math.imul(P,ht)|0,n=(n=n+Math.imul(P,ut)|0)+Math.imul(I,ht)|0,o=o+Math.imul(I,ut)|0,i=i+Math.imul(T,lt)|0,n=(n=n+Math.imul(T,ct)|0)+Math.imul(B,lt)|0,o=o+Math.imul(B,ct)|0;var Bt=(u+(i=i+Math.imul(E,pt)|0)|0)+((8191&(n=(n=n+Math.imul(E,mt)|0)+Math.imul(x,pt)|0))<<13)|0;u=((o=o+Math.imul(x,mt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,i=Math.imul(q,ot),n=(n=Math.imul(q,at))+Math.imul(U,ot)|0,o=Math.imul(U,at),i=i+Math.imul(L,ht)|0,n=(n=n+Math.imul(L,ut)|0)+Math.imul(C,ht)|0,o=o+Math.imul(C,ut)|0,i=i+Math.imul(P,lt)|0,n=(n=n+Math.imul(P,ct)|0)+Math.imul(I,lt)|0,o=o+Math.imul(I,ct)|0;var Ot=(u+(i=i+Math.imul(T,pt)|0)|0)+((8191&(n=(n=n+Math.imul(T,mt)|0)+Math.imul(B,pt)|0))<<13)|0;u=((o=o+Math.imul(B,mt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,i=Math.imul(q,ht),n=(n=Math.imul(q,ut))+Math.imul(U,ht)|0,o=Math.imul(U,ut),i=i+Math.imul(L,lt)|0,n=(n=n+Math.imul(L,ct)|0)+Math.imul(C,lt)|0,o=o+Math.imul(C,ct)|0;var Pt=(u+(i=i+Math.imul(P,pt)|0)|0)+((8191&(n=(n=n+Math.imul(P,mt)|0)+Math.imul(I,pt)|0))<<13)|0;u=((o=o+Math.imul(I,mt)|0)+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,i=Math.imul(q,lt),n=(n=Math.imul(q,ct))+Math.imul(U,lt)|0,o=Math.imul(U,ct);var It=(u+(i=i+Math.imul(L,pt)|0)|0)+((8191&(n=(n=n+Math.imul(L,mt)|0)+Math.imul(C,pt)|0))<<13)|0;u=((o=o+Math.imul(C,mt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863;var jt=(u+(i=Math.imul(q,pt))|0)+((8191&(n=(n=Math.imul(q,mt))+Math.imul(U,pt)|0))<<13)|0;return u=((o=Math.imul(U,mt))+(n>>>13)|0)+(jt>>>26)|0,jt&=67108863,h[0]=bt,h[1]=gt,h[2]=yt,h[3]=vt,h[4]=wt,h[5]=Mt,h[6]=_t,h[7]=St,h[8]=kt,h[9]=At,h[10]=Et,h[11]=xt,h[12]=Rt,h[13]=Tt,h[14]=Bt,h[15]=Ot,h[16]=Pt,h[17]=It,h[18]=jt,0!==u&&(h[19]=u,r.length++),r};function g(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var i=0,n=0,o=0;o>>26)|0)>>>26,a&=67108863}r.words[o]=s,i=a,a=n}return 0!==i?r.words[o]=i:r.length--,r._strip()}function y(t,e,r){return g(t,e,r)}function v(t,e){this.x=t,this.y=e}Math.imul||(b=m),o.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?b(this,t,e):r<63?m(this,t,e):r<1024?g(this,t,e):y(this,t,e)},v.prototype.makeRBT=function(t){for(var e=new Array(t),r=o.prototype._countBits(t)-1,i=0;i>=1;return i},v.prototype.permute=function(t,e,r,i,n,o){for(var a=0;a>>=1)n++;return 1<>>=13,r[2*a+1]=8191&o,o>>>=13;for(a=2*e;a>=26,r+=o/67108864|0,r+=a>>>26,this.words[n]=67108863&a}return 0!==r&&(this.words[n]=r,this.length++),this.length=0===t?1:this.length,e?this.ineg():this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r>>n&1}return e}(t);if(0===e.length)return new o(1);for(var r=this,i=0;i=0);var e,r=t%26,n=(t-r)/26,o=67108863>>>26-r<<26-r;if(0!==r){var a=0;for(e=0;e>>26-r}a&&(this.words[e]=a,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e=0),n=e?(e-e%26)/26:0;var o=t%26,a=Math.min((t-o)/26,this.length),s=67108863^67108863>>>o<a)for(this.length-=a,u=0;u=0&&(0!==f||u>=n);u--){var l=0|this.words[u];this.words[u]=f<<26-o|l>>>o,f=l&s}return h&&0!==f&&(h.words[h.length++]=f),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,n=1<=0);var e=t%26,r=(t-e)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var n=67108863^67108863>>>e<=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},o.prototype.isubn=function(t){if(i("number"==typeof t),i(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e>26)-(h/67108864|0),this.words[n+r]=67108863&o}for(;n>26,this.words[n+r]=67108863&o;if(0===s)return this._strip();for(i(-1===s),s=0,n=0;n>26,this.words[n]=67108863&o;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,e){var r=(this.length,t.length),i=this.clone(),n=t,a=0|n.words[n.length-1];0!=(r=26-this._countBits(a))&&(n=n.ushln(r),i.iushln(r),a=0|n.words[n.length-1]);var s,h=i.length-n.length;if("mod"!==e){(s=new o(null)).length=h+1,s.words=new Array(s.length);for(var u=0;u=0;l--){var c=67108864*(0|i.words[n.length+l])+(0|i.words[n.length+l-1]);for(c=Math.min(c/a|0,67108863),i._ishlnsubmul(n,c,l);0!==i.negative;)c--,i.negative=0,i._ishlnsubmul(n,1,l),i.isZero()||(i.negative^=1);s&&(s.words[l]=c)}return s&&s._strip(),i._strip(),"div"!==e&&0!==r&&i.iushrn(r),{div:s||null,mod:i}},o.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(s=this.neg().divmod(t,e),"mod"!==e&&(n=s.div.neg()),"div"!==e&&(a=s.mod.neg(),r&&0!==a.negative&&a.iadd(t)),{div:n,mod:a}):0===this.negative&&0!==t.negative?(s=this.divmod(t.neg(),e),"mod"!==e&&(n=s.div.neg()),{div:n,mod:s.mod}):0!==(this.negative&t.negative)?(s=this.neg().divmod(t.neg(),e),"div"!==e&&(a=s.mod.neg(),r&&0!==a.negative&&a.isub(t)),{div:s.div,mod:a}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,e);var n,a,s},o.prototype.div=function(t){return this.divmod(t,"div",!1).div},o.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},o.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,i=t.ushrn(1),n=t.andln(1),o=r.cmp(i);return o<0||1===n&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modrn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var r=(1<<26)%t,n=0,o=this.length-1;o>=0;o--)n=(r*n+(0|this.words[o]))%t;return e?-n:n},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var r=0,n=this.length-1;n>=0;n--){var o=(0|this.words[n])+67108864*r;this.words[n]=o/t|0,r=o%t}return this._strip(),e?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n=new o(1),a=new o(0),s=new o(0),h=new o(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var f=r.clone(),l=e.clone();!e.isZero();){for(var c=0,d=1;0===(e.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(e.iushrn(c);c-- >0;)(n.isOdd()||a.isOdd())&&(n.iadd(f),a.isub(l)),n.iushrn(1),a.iushrn(1);for(var p=0,m=1;0===(r.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(s.isOdd()||h.isOdd())&&(s.iadd(f),h.isub(l)),s.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),n.isub(s),a.isub(h)):(r.isub(e),s.isub(n),h.isub(a))}return{a:s,b:h,gcd:r.iushln(u)}},o.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n,a=new o(1),s=new o(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,f=1;0===(e.words[0]&f)&&u<26;++u,f<<=1);if(u>0)for(e.iushrn(u);u-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);for(var l=0,c=1;0===(r.words[0]&c)&&l<26;++l,c<<=1);if(l>0)for(r.iushrn(l);l-- >0;)s.isOdd()&&s.iadd(h),s.iushrn(1);e.cmp(r)>=0?(e.isub(r),a.isub(s)):(r.isub(e),s.isub(a))}return(n=0===e.cmpn(1)?a:s).cmpn(0)<0&&n.iadd(t),n},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var i=0;e.isEven()&&r.isEven();i++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=e.cmp(r);if(n<0){var o=e;e=r,r=o}else if(0===n||0===r.cmpn(1))break;e.isub(r)}return r.iushln(i)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return!(1&this.words[0])},o.prototype.isOdd=function(){return!(1&~this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<>>26,s&=67108863,this.words[a]=s}return 0!==o&&(this.words[a]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:nt.length)return 1;if(this.length=0;r--){var i=0|this.words[r],n=0|t.words[r];if(i!==n){in&&(e=1);break}}return e},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return-1===this.cmpn(t)},o.prototype.lt=function(t){return-1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new E(t)},o.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var w={k256:null,p224:null,p192:null,p25519:null};function M(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function _(){M.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function S(){M.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function k(){M.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){M.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function E(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function x(t){E.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}M.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},M.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var i=e0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},M.prototype.split=function(t,e){t.iushrn(this.n,0,e)},M.prototype.imulK=function(t){return t.imul(this.k)},n(_,M),_.prototype.split=function(t,e){for(var r=4194303,i=Math.min(t.length,9),n=0;n>>22,o=a}o>>>=22,t.words[n-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},_.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r>>=26,t.words[r]=n,e=i}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(w[t])return w[t];var e;if("k256"===t)e=new _;else if("p224"===t)e=new S;else if("p192"===t)e=new k;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new A}return w[t]=e,e},E.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},E.prototype._verify2=function(t,e){i(0===(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},E.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(f(t,t.umod(this.m)._forceRed(this)),t)},E.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},E.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},E.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},E.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},E.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},E.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},E.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},E.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},E.prototype.isqr=function(t){return this.imul(t,t.clone())},E.prototype.sqr=function(t){return this.mul(t,t)},E.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new o(1)).iushrn(2);return this.pow(t,r)}for(var n=this.m.subn(1),a=0;!n.isZero()&&0===n.andln(1);)a++,n.iushrn(1);i(!n.isZero());var s=new o(1).toRed(this),h=s.redNeg(),u=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new o(2*f*f).toRed(this);0!==this.pow(f,u).cmp(h);)f.redIAdd(h);for(var l=this.pow(f,n),c=this.pow(t,n.addn(1).iushrn(1)),d=this.pow(t,n),p=a;0!==d.cmp(s);){for(var m=d,b=0;0!==m.cmp(s);b++)m=m.redSqr();i(b=0;i--){for(var u=e.words[i],f=h-1;f>=0;f--){var l=u>>f&1;n!==r[0]&&(n=this.sqr(n)),0!==l||0!==a?(a<<=1,a|=l,(4===++s||0===i&&0===f)&&(n=this.mul(n,r[a]),s=0,a=0)):s=0}h=26}return n},E.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},E.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new x(t)},n(x,E),x.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},x.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},x.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),o=n;return n.cmp(this.m)>=0?o=n.isub(this.m):n.cmpn(0)<0&&(o=n.iadd(this.m)),o._forceRed(this)},x.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var r=t.mul(e),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)},x.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t=r.nmd(t),this)},5037(t,e,r){var i;function n(t){this.rand=t}if(t.exports=function(t){return i||(i=new n(null)),i.generate(t)},t.exports.Rand=n,n.prototype.generate=function(t){return this._rand(t)},n.prototype._rand=function(t){if(this.rand.getBytes)return this.rand.getBytes(t);for(var e=new Uint8Array(t),r=0;r>>24]^f[p>>>16&255]^l[m>>>8&255]^c[255&b]^e[g++],a=u[p>>>24]^f[m>>>16&255]^l[b>>>8&255]^c[255&d]^e[g++],s=u[m>>>24]^f[b>>>16&255]^l[d>>>8&255]^c[255&p]^e[g++],h=u[b>>>24]^f[d>>>16&255]^l[p>>>8&255]^c[255&m]^e[g++],d=o,p=a,m=s,b=h;return o=(i[d>>>24]<<24|i[p>>>16&255]<<16|i[m>>>8&255]<<8|i[255&b])^e[g++],a=(i[p>>>24]<<24|i[m>>>16&255]<<16|i[b>>>8&255]<<8|i[255&d])^e[g++],s=(i[m>>>24]<<24|i[b>>>16&255]<<16|i[d>>>8&255]<<8|i[255&p])^e[g++],h=(i[b>>>24]<<24|i[d>>>16&255]<<16|i[p>>>8&255]<<8|i[255&m])^e[g++],[o>>>=0,a>>>=0,s>>>=0,h>>>=0]}var s=[0,1,2,4,8,16,32,64,128,27,54],h=function(){for(var t=new Array(256),e=0;e<256;e++)t[e]=e<128?e<<1:e<<1^283;for(var r=[],i=[],n=[[],[],[],[]],o=[[],[],[],[]],a=0,s=0,h=0;h<256;++h){var u=s^s<<1^s<<2^s<<3^s<<4;u=u>>>8^255&u^99,r[a]=u,i[u]=a;var f=t[a],l=t[f],c=t[l],d=257*t[u]^16843008*u;n[0][a]=d<<24|d>>>8,n[1][a]=d<<16|d>>>16,n[2][a]=d<<8|d>>>24,n[3][a]=d,d=16843009*c^65537*l^257*f^16843008*a,o[0][u]=d<<24|d>>>8,o[1][u]=d<<16|d>>>16,o[2][u]=d<<8|d>>>24,o[3][u]=d,0===a?a=s=1:(a=f^t[t[t[c^f]]],s^=t[t[s]])}return{SBOX:r,INV_SBOX:i,SUB_MIX:n,INV_SUB_MIX:o}}();function u(t){this._key=n(t),this._reset()}u.blockSize=16,u.keySize=32,u.prototype.blockSize=u.blockSize,u.prototype.keySize=u.keySize,u.prototype._reset=function(){for(var t=this._key,e=t.length,r=e+6,i=4*(r+1),n=[],o=0;o>>24,a=h.SBOX[a>>>24]<<24|h.SBOX[a>>>16&255]<<16|h.SBOX[a>>>8&255]<<8|h.SBOX[255&a],a^=s[o/e|0]<<24):e>6&&o%e===4&&(a=h.SBOX[a>>>24]<<24|h.SBOX[a>>>16&255]<<16|h.SBOX[a>>>8&255]<<8|h.SBOX[255&a]),n[o]=n[o-e]^a}for(var u=[],f=0;f>>24]]^h.INV_SUB_MIX[1][h.SBOX[c>>>16&255]]^h.INV_SUB_MIX[2][h.SBOX[c>>>8&255]]^h.INV_SUB_MIX[3][h.SBOX[255&c]]}this._nRounds=r,this._keySchedule=n,this._invKeySchedule=u},u.prototype.encryptBlockRaw=function(t){return a(t=n(t),this._keySchedule,h.SUB_MIX,h.SBOX,this._nRounds)},u.prototype.encryptBlock=function(t){var e=this.encryptBlockRaw(t),r=i.allocUnsafe(16);return r.writeUInt32BE(e[0],0),r.writeUInt32BE(e[1],4),r.writeUInt32BE(e[2],8),r.writeUInt32BE(e[3],12),r},u.prototype.decryptBlock=function(t){var e=(t=n(t))[1];t[1]=t[3],t[3]=e;var r=a(t,this._invKeySchedule,h.INV_SUB_MIX,h.INV_SBOX,this._nRounds),o=i.allocUnsafe(16);return o.writeUInt32BE(r[0],0),o.writeUInt32BE(r[3],4),o.writeUInt32BE(r[2],8),o.writeUInt32BE(r[1],12),o},u.prototype.scrub=function(){o(this._keySchedule),o(this._invKeySchedule),o(this._key)},t.exports.AES=u},2356(t,e,r){var i=r(462),n=r(2861).Buffer,o=r(6168),a=r(6698),s=r(5892),h=r(295),u=r(5122);function f(t,e,r,a){o.call(this);var h=n.alloc(4,0);this._cipher=new i.AES(e);var f=this._cipher.encryptBlock(h);this._ghash=new s(f),r=function(t,e,r){if(12===e.length)return t._finID=n.concat([e,n.from([0,0,0,1])]),n.concat([e,n.from([0,0,0,2])]);var i=new s(r),o=e.length,a=o%16;i.update(e),a&&(a=16-a,i.update(n.alloc(a,0))),i.update(n.alloc(8,0));var h=8*o,f=n.alloc(8);f.writeUIntBE(h,0,8),i.update(f),t._finID=i.state;var l=n.from(t._finID);return u(l),l}(this,r,f),this._prev=n.from(r),this._cache=n.allocUnsafe(0),this._secCache=n.allocUnsafe(0),this._decrypt=a,this._alen=0,this._len=0,this._mode=t,this._authTag=null,this._called=!1}a(f,o),f.prototype._update=function(t){if(!this._called&&this._alen){var e=16-this._alen%16;e<16&&(e=n.alloc(e,0),this._ghash.update(e))}this._called=!0;var r=this._mode.encrypt(this,t);return this._decrypt?this._ghash.update(t):this._ghash.update(r),this._len+=t.length,r},f.prototype._final=function(){if(this._decrypt&&!this._authTag)throw new Error("Unsupported state or unable to authenticate data");var t=h(this._ghash.final(8*this._alen,8*this._len),this._cipher.encryptBlock(this._finID));if(this._decrypt&&function(t,e){var r=0;t.length!==e.length&&r++;for(var i=Math.min(t.length,e.length),n=0;n16)throw new Error("unable to decrypt data");for(var r=-1;++r16)return e=this.cache.slice(0,16),this.cache=this.cache.slice(16),e}else if(this.cache.length>=16)return e=this.cache.slice(0,16),this.cache=this.cache.slice(16),e;return null},l.prototype.flush=function(){if(this.cache.length)return this.cache},e.createDecipher=function(t,e){var r=o[t.toLowerCase()];if(!r)throw new TypeError("invalid suite type");var i=u(e,!1,r.key,r.iv);return c(t,i.key,i.iv)},e.createDecipheriv=c},5799(t,e,r){var i=r(530),n=r(2356),o=r(2861).Buffer,a=r(650),s=r(6168),h=r(462),u=r(8078);function f(t,e,r){s.call(this),this._cache=new c,this._cipher=new h.AES(e),this._prev=o.from(r),this._mode=t,this._autopadding=!0}r(6698)(f,s),f.prototype._update=function(t){var e,r;this._cache.add(t);for(var i=[];e=this._cache.get();)r=this._mode.encrypt(this,e),i.push(r);return o.concat(i)};var l=o.alloc(16,16);function c(){this.cache=o.allocUnsafe(0)}function d(t,e,r){var s=i[t.toLowerCase()];if(!s)throw new TypeError("invalid suite type");if("string"==typeof e&&(e=o.from(e)),e.length!==s.key/8)throw new TypeError("invalid key length "+e.length);if("string"==typeof r&&(r=o.from(r)),"GCM"!==s.mode&&r.length!==s.iv)throw new TypeError("invalid iv length "+r.length);return"stream"===s.type?new a(s.module,e,r):"auth"===s.type?new n(s.module,e,r):new f(s.module,e,r)}f.prototype._final=function(){var t=this._cache.flush();if(this._autopadding)return t=this._mode.encrypt(this,t),this._cipher.scrub(),t;if(!t.equals(l))throw this._cipher.scrub(),new Error("data not multiple of block length")},f.prototype.setAutoPadding=function(t){return this._autopadding=!!t,this},c.prototype.add=function(t){this.cache=o.concat([this.cache,t])},c.prototype.get=function(){if(this.cache.length>15){var t=this.cache.slice(0,16);return this.cache=this.cache.slice(16),t}return null},c.prototype.flush=function(){for(var t=16-this.cache.length,e=o.allocUnsafe(t),r=-1;++r>>0,0),e.writeUInt32BE(t[1]>>>0,4),e.writeUInt32BE(t[2]>>>0,8),e.writeUInt32BE(t[3]>>>0,12),e}function a(t){this.h=t,this.state=i.alloc(16,0),this.cache=i.allocUnsafe(0)}a.prototype.ghash=function(t){for(var e=-1;++e0;e--)i[e]=i[e]>>>1|(1&i[e-1])<<31;i[0]=i[0]>>>1,r&&(i[0]=i[0]^225<<24)}this.state=o(n)},a.prototype.update=function(t){var e;for(this.cache=i.concat([this.cache,t]);this.cache.length>=16;)e=this.cache.slice(0,16),this.cache=this.cache.slice(16),this.ghash(e)},a.prototype.final=function(t,e){return this.cache.length&&this.ghash(i.concat([this.cache,n],16)),this.ghash(o([0,t,0,e])),this.state},t.exports=a},5122(t){t.exports=function(t){for(var e,r=t.length;r--;){if(255!==(e=t.readUInt8(r))){e++,t.writeUInt8(e,r);break}t.writeUInt8(0,r)}}},2884(t,e,r){var i=r(295);e.encrypt=function(t,e){var r=i(e,t._prev);return t._prev=t._cipher.encryptBlock(r),t._prev},e.decrypt=function(t,e){var r=t._prev;t._prev=e;var n=t._cipher.decryptBlock(e);return i(n,r)}},6383(t,e,r){var i=r(2861).Buffer,n=r(295);function o(t,e,r){var o=e.length,a=n(e,t._cache);return t._cache=t._cache.slice(o),t._prev=i.concat([t._prev,r?e:a]),a}e.encrypt=function(t,e,r){for(var n,a=i.allocUnsafe(0);e.length;){if(0===t._cache.length&&(t._cache=t._cipher.encryptBlock(t._prev),t._prev=i.allocUnsafe(0)),!(t._cache.length<=e.length)){a=i.concat([a,o(t,e,r)]);break}n=t._cache.length,a=i.concat([a,o(t,e.slice(0,n),r)]),e=e.slice(n)}return a}},5264(t,e,r){var i=r(2861).Buffer;function n(t,e,r){for(var i,n,a=-1,s=0;++a<8;)i=e&1<<7-a?128:0,s+=(128&(n=t._cipher.encryptBlock(t._prev)[0]^i))>>a%8,t._prev=o(t._prev,r?i:n);return s}function o(t,e){var r=t.length,n=-1,o=i.allocUnsafe(t.length);for(t=i.concat([t,i.from([e])]);++n>7;return o}e.encrypt=function(t,e,r){for(var o=e.length,a=i.allocUnsafe(o),s=-1;++s=0||!e.umod(t.prime1)||!e.umod(t.prime2));return e}function s(t,e){var r=function(t){var e=a(t);return{blinder:e.toRed(i.mont(t.modulus)).redPow(new i(t.publicExponent)).fromRed(),unblinder:e.invm(t.modulus)}}(e),n=e.modulus.byteLength(),s=new i(t).mul(r.blinder).umod(e.modulus),h=s.toRed(i.mont(e.prime1)),u=s.toRed(i.mont(e.prime2)),f=e.coefficient,l=e.prime1,c=e.prime2,d=h.redPow(e.exponent1).fromRed(),p=u.redPow(e.exponent2).fromRed(),m=d.isub(p).imul(f).umod(l).imul(c);return p.iadd(m).imul(r.unblinder).umod(e.modulus).toArrayLike(o,"be",n)}s.getr=a,t.exports=s},5715(t,e,r){"use strict";t.exports=r(2951)},20(t,e,r){"use strict";var i=r(2861).Buffer,n=r(7108),o=r(8399),a=r(6698),s=r(5359),h=r(4847),u=r(2951);function f(t){o.Writable.call(this);var e=u[t];if(!e)throw new Error("Unknown message digest");this._hashType=e.hash,this._hash=n(e.hash),this._tag=e.id,this._signType=e.sign}function l(t){o.Writable.call(this);var e=u[t];if(!e)throw new Error("Unknown message digest");this._hash=n(e.hash),this._tag=e.id,this._signType=e.sign}function c(t){return new f(t)}function d(t){return new l(t)}Object.keys(u).forEach(function(t){u[t].id=i.from(u[t].id,"hex"),u[t.toLowerCase()]=u[t]}),a(f,o.Writable),f.prototype._write=function(t,e,r){this._hash.update(t),r()},f.prototype.update=function(t,e){return this._hash.update("string"==typeof t?i.from(t,e):t),this},f.prototype.sign=function(t,e){this.end();var r=this._hash.digest(),i=s(r,t,this._hashType,this._signType,this._tag);return e?i.toString(e):i},a(l,o.Writable),l.prototype._write=function(t,e,r){this._hash.update(t),r()},l.prototype.update=function(t,e){return this._hash.update("string"==typeof t?i.from(t,e):t),this},l.prototype.verify=function(t,e,r){var n="string"==typeof e?i.from(e,r):e;this.end();var o=this._hash.digest();return h(n,o,t,this._signType,this._tag)},t.exports={Sign:c,Verify:d,createSign:c,createVerify:d}},5359(t,e,r){"use strict";var i=r(2861).Buffer,n=r(3507),o=r(7332),a=r(6729).ec,s=r(9404),h=r(8170),u=r(4589);function f(t,e,r,o){if((t=i.from(t.toArray())).length0&&r.ishrn(i),r}function c(t,e,r){var o,a;do{for(o=i.alloc(0);8*o.length=0)throw new Error("invalid sig")}t.exports=function(t,e,r,u,f){var l=a(r);if("ec"===l.type){if("ecdsa"!==u&&"ecdsa/rsa"!==u)throw new Error("wrong public key type");return function(t,e,r){var i=s[r.data.algorithm.curve.join(".")];if(!i)throw new Error("unknown curve "+r.data.algorithm.curve.join("."));var n=new o(i),a=r.data.subjectPrivateKey.data;return n.verify(e,t,a)}(t,e,l)}if("dsa"===l.type){if("dsa"!==u)throw new Error("wrong public key type");return function(t,e,r){var i=r.data.p,o=r.data.q,s=r.data.g,u=r.data.pub_key,f=a.signature.decode(t,"der"),l=f.s,c=f.r;h(l,o),h(c,o);var d=n.mont(i),p=l.invm(o);return 0===s.toRed(d).redPow(new n(e).mul(p).mod(o)).fromRed().mul(u.toRed(d).redPow(c.mul(p).mod(o)).fromRed()).mod(i).mod(o).cmp(c)}(t,e,l)}if("rsa"!==u&&"ecdsa/rsa"!==u)throw new Error("wrong public key type");e=i.concat([f,e]);for(var c=l.modulus.byteLength(),d=[1],p=0;e.length+d.length+2a)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,h.prototype),e}function h(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return l(t)}return u(t,e,r)}function u(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!h.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=0|m(t,e),i=s(r),n=i.write(t,e);return n!==r&&(i=i.slice(0,n)),i}(t,e);if(ArrayBuffer.isView(t))return function(t){if(F(t,Uint8Array)){var e=new Uint8Array(t);return d(e.buffer,e.byteOffset,e.byteLength)}return c(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(F(t,ArrayBuffer)||t&&F(t.buffer,ArrayBuffer))return d(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(F(t,SharedArrayBuffer)||t&&F(t.buffer,SharedArrayBuffer)))return d(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var i=t.valueOf&&t.valueOf();if(null!=i&&i!==t)return h.from(i,e,r);var n=function(t){if(h.isBuffer(t)){var e=0|p(t.length),r=s(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||z(t.length)?s(0):c(t):"Buffer"===t.type&&Array.isArray(t.data)?c(t.data):void 0}(t);if(n)return n;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return h.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function f(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function l(t){return f(t),s(t<0?0:0|p(t))}function c(t){for(var e=t.length<0?0:0|p(t.length),r=s(e),i=0;i=a)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a.toString(16)+" bytes");return 0|t}function m(t,e){if(h.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||F(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,i=arguments.length>2&&!0===arguments[2];if(!i&&0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return q(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return U(t).length;default:if(n)return i?-1:q(t).length;e=(""+e).toLowerCase(),n=!0}}function b(t,e,r){var i=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return B(this,e,r);case"utf8":case"utf-8":return E(this,e,r);case"ascii":return R(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return A(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,r);default:if(i)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),i=!0}}function g(t,e,r){var i=t[e];t[e]=t[r],t[r]=i}function y(t,e,r,i,n){if(0===t.length)return-1;if("string"==typeof r?(i=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),z(r=+r)&&(r=n?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(n)return-1;r=t.length-1}else if(r<0){if(!n)return-1;r=0}if("string"==typeof e&&(e=h.from(e,i)),h.isBuffer(e))return 0===e.length?-1:v(t,e,r,i,n);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):v(t,[e],r,i,n);throw new TypeError("val must be string, number or Buffer")}function v(t,e,r,i,n){var o,a=1,s=t.length,h=e.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(t.length<2||e.length<2)return-1;a=2,s/=2,h/=2,r/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(n){var f=-1;for(o=r;os&&(r=s-h),o=r;o>=0;o--){for(var l=!0,c=0;cn&&(i=n):i=n;var o=e.length;i>o/2&&(i=o/2);for(var a=0;a