9remote 0.1.42 → 0.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +2 -2
- package/dist/server.cjs +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -61,7 +61,7 @@ ${N6.default.cursorShow}`)}releaseCursor(){this.extraLinesUnderPrompt>0&&Pf(this
|
|
|
61
61
|
`:`
|
|
62
62
|
`)+t,i=n+1,n=r.indexOf(`
|
|
63
63
|
`,i)}while(n!==-1);return o+=r.slice(i),o}var{stdout:by,stderr:my}=hy,ex=Symbol("GENERATOR"),ei=Symbol("STYLER"),co=Symbol("IS_EMPTY"),yy=["ansi","ansi","ansi256","ansi16m"],ri=Object.create(null),iR=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=by?by.level:0;r.level=e.level===void 0?t:e.level};var oR=r=>{let e=(...t)=>t.join(" ");return iR(e,r),Object.setPrototypeOf(e,lo.prototype),e};function lo(r){return oR(r)}Object.setPrototypeOf(lo.prototype,Function.prototype);for(let[r,e]of Object.entries(Ze))ri[r]={get(){let t=Js(this,tx(e.open,e.close,this[ei]),this[co]);return Object.defineProperty(this,r,{value:t}),t}};ri.visible={get(){let r=Js(this,this[ei],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var rx=(r,e,t,...n)=>r==="rgb"?e==="ansi16m"?Ze[t].ansi16m(...n):e==="ansi256"?Ze[t].ansi256(Ze.rgbToAnsi256(...n)):Ze[t].ansi(Ze.rgbToAnsi(...n)):r==="hex"?rx("rgb",e,t,...Ze.hexToRgb(...n)):Ze[t][r](...n),aR=["rgb","hex","ansi256"];for(let r of aR){ri[r]={get(){let{level:t}=this;return function(...n){let i=tx(rx(r,yy[t],"color",...n),Ze.color.close,this[ei]);return Js(this,i,this[co])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);ri[e]={get(){let{level:t}=this;return function(...n){let i=tx(rx(r,yy[t],"bgColor",...n),Ze.bgColor.close,this[ei]);return Js(this,i,this[co])}}}}var uR=Object.defineProperties(()=>{},{...ri,level:{enumerable:!0,get(){return this[ex].level},set(r){this[ex].level=r}}}),tx=(r,e,t)=>{let n,i;return t===void 0?(n=r,i=e):(n=t.openAll+r,i=e+t.closeAll),{open:r,close:e,openAll:n,closeAll:i,parent:t}},Js=(r,e,t)=>{let n=(...i)=>sR(n,i.length===1?""+i[0]:i.join(" "));return Object.setPrototypeOf(n,uR),n[ex]=r,n[ei]=e,n[co]=t,n},sR=(r,e)=>{if(r.level<=0||!e)return r[co]?"":e;let t=r[ei];if(t===void 0)return e;let{openAll:n,closeAll:i}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=py(e,t.close,t.open),t=t.parent;let o=e.indexOf(`
|
|
64
|
-
`);return o!==-1&&(e=vy(e,i,n,o)),n+e+i};Object.defineProperties(lo.prototype,ri);var cR=lo(),m$=lo({level:my?my.level:0});var q=cR;var f_=O(Vy(),1),go=require("child_process"),Wt=O(require("path"),1),d_=require("url"),lc=O(require("fs"),1);var Ky=O($y(),1),cx=O(require("crypto"),1),{machineIdSync:mR}=Ky.default;async function rc(r=null){let e=r||process.env.MACHINE_ID_SALT||"9remote-salt";try{let t=mR();return cx.default.createHash("sha256").update(t+e).digest("hex").substring(0,16)}catch(t){return console.error("Error getting machine ID:",t),cx.default.randomUUID().replace(/-/g,"").substring(0,16)}}var Gy=O(require("crypto"),1),yR=process.env.API_KEY_SECRET||"9remote-api-key-secret";function _R(){let r="abcdefghijklmnopqrstuvwxyz0123456789",e="";for(let t=0;t<6;t++)e+=r.charAt(Math.floor(Math.random()*r.length));return e}function gR(r,e){return Gy.default.createHmac("sha256",yR).update(r+e).digest("hex").slice(0,8)}function xo(r){let e=_R(),t=gR(r,e);return{key:`sk-${r}-${e}-${t}`,keyId:e}}var rr=O(require("fs"),1),nc=O(require("path"),1),Hy=O(require("os"),1),tc=nc.default.join(Hy.default.homedir(),".9remote"),ho=nc.default.join(tc,"state.json"),lx=nc.default.join(tc,"keys.json");function ic(){rr.default.existsSync(tc)||rr.default.mkdirSync(tc,{recursive:!0})}function Yy(){try{return ic(),rr.default.existsSync(ho)?JSON.parse(rr.default.readFileSync(ho,"utf8")):null}catch{return null}}function zy(r){try{ic(),rr.default.writeFileSync(ho,JSON.stringify(r,null,2))}catch(e){console.error("Error saving state:",e)}}function Qy(){try{rr.default.existsSync(ho)&&rr.default.unlinkSync(ho)}catch{}}function oc(){try{return ic(),rr.default.existsSync(lx)?JSON.parse(rr.default.readFileSync(lx,"utf8")):{machineId:null,key:null,name:"Default",createdAt:null}}catch{return{machineId:null,key:null,name:"Default",createdAt:null}}}function po(r,e,t="Default"){try{ic();let n={machineId:r,key:e,name:t,createdAt:new Date().toISOString()};return rr.default.writeFileSync(lx,JSON.stringify(n,null,2)),n}catch(n){return console.error("Error saving key:",n),null}}async function fx(r,e){try{let t=await fetch(`${e}/api/temp-key/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r,expiryMinutes:30})});if(!t.ok){let n=await t.json();throw new Error(n.error||"Failed to create temp key")}return await t.json()}catch(t){return console.error("Error creating temp key:",t),null}}var Nt=require("fs"),Jy=require("url"),Xy=require("child_process"),vo=O(require("path"),1),dx=O(require("os"),1),DR=vo.default.dirname((0,Jy.fileURLToPath)(__importMetaUrl)),Pe="9remote",wR=`https://registry.npmjs.org/${Pe}/latest`,ER=3e3,SR=8e3;function OR(){return"0.1.
|
|
64
|
+
`);return o!==-1&&(e=vy(e,i,n,o)),n+e+i};Object.defineProperties(lo.prototype,ri);var cR=lo(),m$=lo({level:my?my.level:0});var q=cR;var f_=O(Vy(),1),go=require("child_process"),Wt=O(require("path"),1),d_=require("url"),lc=O(require("fs"),1);var Ky=O($y(),1),cx=O(require("crypto"),1),{machineIdSync:mR}=Ky.default;async function rc(r=null){let e=r||process.env.MACHINE_ID_SALT||"9remote-salt";try{let t=mR();return cx.default.createHash("sha256").update(t+e).digest("hex").substring(0,16)}catch(t){return console.error("Error getting machine ID:",t),cx.default.randomUUID().replace(/-/g,"").substring(0,16)}}var Gy=O(require("crypto"),1),yR=process.env.API_KEY_SECRET||"9remote-api-key-secret";function _R(){let r="abcdefghijklmnopqrstuvwxyz0123456789",e="";for(let t=0;t<6;t++)e+=r.charAt(Math.floor(Math.random()*r.length));return e}function gR(r,e){return Gy.default.createHmac("sha256",yR).update(r+e).digest("hex").slice(0,8)}function xo(r){let e=_R(),t=gR(r,e);return{key:`sk-${r}-${e}-${t}`,keyId:e}}var rr=O(require("fs"),1),nc=O(require("path"),1),Hy=O(require("os"),1),tc=nc.default.join(Hy.default.homedir(),".9remote"),ho=nc.default.join(tc,"state.json"),lx=nc.default.join(tc,"keys.json");function ic(){rr.default.existsSync(tc)||rr.default.mkdirSync(tc,{recursive:!0})}function Yy(){try{return ic(),rr.default.existsSync(ho)?JSON.parse(rr.default.readFileSync(ho,"utf8")):null}catch{return null}}function zy(r){try{ic(),rr.default.writeFileSync(ho,JSON.stringify(r,null,2))}catch(e){console.error("Error saving state:",e)}}function Qy(){try{rr.default.existsSync(ho)&&rr.default.unlinkSync(ho)}catch{}}function oc(){try{return ic(),rr.default.existsSync(lx)?JSON.parse(rr.default.readFileSync(lx,"utf8")):{machineId:null,key:null,name:"Default",createdAt:null}}catch{return{machineId:null,key:null,name:"Default",createdAt:null}}}function po(r,e,t="Default"){try{ic();let n={machineId:r,key:e,name:t,createdAt:new Date().toISOString()};return rr.default.writeFileSync(lx,JSON.stringify(n,null,2)),n}catch(n){return console.error("Error saving key:",n),null}}async function fx(r,e){try{let t=await fetch(`${e}/api/temp-key/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r,expiryMinutes:30})});if(!t.ok){let n=await t.json();throw new Error(n.error||"Failed to create temp key")}return await t.json()}catch(t){return console.error("Error creating temp key:",t),null}}var Nt=require("fs"),Jy=require("url"),Xy=require("child_process"),vo=O(require("path"),1),dx=O(require("os"),1),DR=vo.default.dirname((0,Jy.fileURLToPath)(__importMetaUrl)),Pe="9remote",wR=`https://registry.npmjs.org/${Pe}/latest`,ER=3e3,SR=8e3;function OR(){return"0.1.43"}function FR(r,e){let t=r.split(".").map(Number),n=e.split(".").map(Number);for(let i=0;i<3;i++){if(n[i]>t[i])return!0;if(n[i]<t[i])return!1}return!1}function CR(){return process.env.CODESPACES==="true"||process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN?"GitHub Codespaces":(0,Nt.existsSync)("/.dockerenv")?"Docker":null}async function Zy(r=!1){if(r)return!1;let e=OR();if(!e)return!1;let t=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],n=0,i=null,o=u=>{process.stdout.isTTY&&(process.stdout.write(`\r${t[0]} ${u}`),i=setInterval(()=>{process.stdout.write(`\r${t[n++%t.length]} ${u}`)},80))},a=()=>{i&&(clearInterval(i),i=null),process.stdout.isTTY&&process.stdout.write("\r\x1B[K")};return new Promise(u=>{let s=!1,c=x=>{s||(s=!0,a(),u(x))},l=setTimeout(()=>c(!1),SR);o("Checking for updates..."),fetch(wR,{signal:AbortSignal.timeout(ER)}).then(x=>x.json()).then(x=>{if(s)return;clearTimeout(l);let h=x.version;if(!h||!FR(e,h)){c(!1);return}a(),console.log(q.green(`\u2705 New version available: ${e} \u2192 ${h}`));let v=CR();if(v){console.log(q.yellow(` \u26A0\uFE0F ${v} detected - manual update required`)),console.log(q.gray(` Run: npm install -g ${Pe}@latest
|
|
65
65
|
`)),c(!1);return}console.log(q.yellow(`\u{1F504} Auto-updating...
|
|
66
66
|
`));let b=process.argv.slice(2).filter(A=>A!=="--skip-update").join(" "),m=process.platform,y,_;if(m==="win32"){let A=`@echo off
|
|
67
67
|
echo \u{1F4E5} Downloading update...
|
|
@@ -108,7 +108,7 @@ else
|
|
|
108
108
|
${Pe} ${b} --skip-update
|
|
109
109
|
fi
|
|
110
110
|
`;y=vo.default.join(dx.default.tmpdir(),`${Pe}-update.sh`),(0,Nt.writeFileSync)(y,A,{mode:493}),_=["sh",[y]]}(0,Xy.spawn)(_[0],_[1],{detached:!0,stdio:"inherit"}).unref(),process.exit(0)}).catch(()=>{clearTimeout(l),c(!1)})})}var pe=O(require("fs"),1),_o=O(require("path"),1),n_=O(require("https"),1),Ut=O(require("os"),1),cc=require("child_process"),yo=null,ac=null,sc=null,bo=_o.default.join(Ut.default.homedir(),".9remote","bin"),e_="cloudflared",hx=Ut.default.platform()==="win32",AR=hx?`${e_}.exe`:e_,ti=_o.default.join(bo,AR),uc=_o.default.join(Ut.default.homedir(),".9remote","cloudflared.pid"),mo=!1,xx=5,r_=6e4,ni=[],ii=null,qR="https://github.com/cloudflare/cloudflared/releases/latest/download",PR={darwin:{x64:"cloudflared-darwin-amd64.tgz",arm64:"cloudflared-darwin-amd64.tgz"},win32:{x64:"cloudflared-windows-amd64.exe"},linux:{x64:"cloudflared-linux-amd64",arm64:"cloudflared-linux-arm64"}};function TR(){let r=Ut.default.platform(),e=Ut.default.arch(),t=PR[r];if(!t)throw new Error(`Unsupported platform: ${r}`);let n=t[e];if(!n)throw new Error(`Unsupported architecture: ${e} for platform ${r}`);return`${qR}/${n}`}async function i_(r,e){return new Promise((t,n)=>{let i=pe.default.createWriteStream(e);n_.default.get(r,o=>{if([301,302].includes(o.statusCode)){i.close(),pe.default.unlinkSync(e),i_(o.headers.location,e).then(t).catch(n);return}if(o.statusCode!==200){i.close(),pe.default.unlinkSync(e),n(new Error(`Download failed with status ${o.statusCode}`));return}o.pipe(i),i.on("finish",()=>{i.close(()=>t(e))}),i.on("error",a=>{i.close(),pe.default.unlinkSync(e),n(a)})}).on("error",o=>{i.close(),pe.default.existsSync(e)&&pe.default.unlinkSync(e),n(o)})})}async function px(){if(pe.default.existsSync(bo)||pe.default.mkdirSync(bo,{recursive:!0}),pe.default.existsSync(ti))return hx||pe.default.chmodSync(ti,"755"),ti;console.log("\u{1F4E5} Downloading tunnel binary...");let r=TR(),e=r.endsWith(".tgz"),t=e?_o.default.join(bo,"cloudflared.tgz"):ti;try{return await i_(r,t),e&&(console.log("\u2705 Extracting..."),(0,cc.execSync)(`tar -xzf "${t}" -C "${bo}"`,{stdio:"pipe"}),pe.default.unlinkSync(t)),hx||pe.default.chmodSync(ti,"755"),console.log("\u2705 cloudflared ready"),ti}catch(n){throw console.error("\u274C Failed to download cloudflared:",n.message),n}}var BR=["INF Starting tunnel","INF Version","GOOS:","Settings:","Autoupdate frequency","Generated Connector","Initial protocol","ICMP proxy","Created ICMP","Starting metrics server","curve preferences","Updated to new configuration"];async function o_(r,e=null){let t=await px();e&&(ii=e),sc=r;let n=(0,cc.spawn)(t,["tunnel","run","--token",r],{detached:!1,stdio:["ignore","pipe","pipe"]});return mo=!1,console.log(`\u2705 Cloudflared spawned with PID: ${n.pid}`),await new Promise((i,o)=>{let a=0,u=!1,s=setTimeout(()=>{u||(u=!0,i(n))},9e4),c=l=>{let x=l.toString().trim();if(!BR.some(h=>x.includes(h))&&!mo&&x.includes("Registered tunnel connection")){a++,a<=4&&(process.stdout.write(`\r \u2714 Connection ${a}/4 established`),a===4&&(process.stdout.write(`
|
|
111
|
-
`),u||(u=!0,clearTimeout(s),i(n))));return}};n.stdout.on("data",c),n.stderr.on("data",c),n.on("error",l=>{u||(u=!0,clearTimeout(s),o(l))}),n.on("exit",l=>{u||(u=!0,clearTimeout(s),o(new Error(`cloudflared exited with code ${l}`)))})}),n.on("error",i=>{console.error("\u274C cloudflared error:",i)}),n.on("exit",(i,o)=>{if(console.log(`\u26A0\uFE0F Cloudflared process exited (code: ${i}, signal: ${o}, intentional: ${mo})`),mo)console.log("\u2139\uFE0F Cloudflared exit ignored (intentional shutdown)");else if(console.log("\u26A0\uFE0F Cloudflared unexpected exit detected - will restart"),ii){let a=Date.now();ni.push(a),ni=ni.filter(u=>u>a-r_),ni.length<=xx?(console.log(`\u{1F504} Restarting tunnel... (attempt ${ni.length}/${xx})`),setTimeout(()=>{console.log("\u{1F504} Executing tunnel restart..."),ii(r)},2e3)):console.log(`\u274C Too many tunnel restarts (${xx} in ${r_/1e3}s). Giving up.`)}else console.log("\u26A0\uFE0F No restart callback registered")}),pe.default.writeFileSync(uc,n.pid.toString()),jR(),n}function vx(){try{if(pe.default.existsSync(uc)){mo=!0;let r=parseInt(pe.default.readFileSync(uc,"utf8"));process.kill(r),pe.default.unlinkSync(uc),console.log("\u2705 Cloudflared killed")}}catch{}}function a_(){ni=[],ii=null,sc=null,MR()}function t_(){let r=Ut.default.networkInterfaces(),e=[];for(let[t,n]of Object.entries(r))if(n)for(let i of n)!i.internal&&i.family==="IPv4"&&e.push(`${t}:${i.address}`);return e.sort().join("|")}function jR(){yo||(ac=t_(),yo=setInterval(()=>{let r=t_();r!==ac&&(console.log("\u{1F504} Network change detected - restarting tunnel..."),ac=r,vx(),ii&&sc&&setTimeout(()=>{console.log("\u{1F504} Restarting tunnel after network change..."),ii(sc)},2e3))},5e3))}function MR(){yo&&(clearInterval(yo),yo=null),ac=null}var RR=process.argv.includes("--skip-update"),yx=Wt.default.dirname((0,d_.fileURLToPath)(__importMetaUrl)),IR=Wt.default.resolve(yx,".."),kR=Wt.default.join(yx,"server.cjs"),u_=Wt.default.join(IR,"server/index.js"),ft="https://9remote.cc",mx=2208,s_="abcdefghijklmnpqrstuvwxyz23456789",bx=10,c_=6e4,H=q.rgb(230,138,110),LR=q.rgb(200,120,95);function NR(){return"0.1.
|
|
111
|
+
`),u||(u=!0,clearTimeout(s),i(n))));return}};n.stdout.on("data",c),n.stderr.on("data",c),n.on("error",l=>{u||(u=!0,clearTimeout(s),o(l))}),n.on("exit",l=>{u||(u=!0,clearTimeout(s),o(new Error(`cloudflared exited with code ${l}`)))})}),n.on("error",i=>{console.error("\u274C cloudflared error:",i)}),n.on("exit",(i,o)=>{if(console.log(`\u26A0\uFE0F Cloudflared process exited (code: ${i}, signal: ${o}, intentional: ${mo})`),mo)console.log("\u2139\uFE0F Cloudflared exit ignored (intentional shutdown)");else if(console.log("\u26A0\uFE0F Cloudflared unexpected exit detected - will restart"),ii){let a=Date.now();ni.push(a),ni=ni.filter(u=>u>a-r_),ni.length<=xx?(console.log(`\u{1F504} Restarting tunnel... (attempt ${ni.length}/${xx})`),setTimeout(()=>{console.log("\u{1F504} Executing tunnel restart..."),ii(r)},2e3)):console.log(`\u274C Too many tunnel restarts (${xx} in ${r_/1e3}s). Giving up.`)}else console.log("\u26A0\uFE0F No restart callback registered")}),pe.default.writeFileSync(uc,n.pid.toString()),jR(),n}function vx(){try{if(pe.default.existsSync(uc)){mo=!0;let r=parseInt(pe.default.readFileSync(uc,"utf8"));process.kill(r),pe.default.unlinkSync(uc),console.log("\u2705 Cloudflared killed")}}catch{}}function a_(){ni=[],ii=null,sc=null,MR()}function t_(){let r=Ut.default.networkInterfaces(),e=[];for(let[t,n]of Object.entries(r))if(n)for(let i of n)!i.internal&&i.family==="IPv4"&&e.push(`${t}:${i.address}`);return e.sort().join("|")}function jR(){yo||(ac=t_(),yo=setInterval(()=>{let r=t_();r!==ac&&(console.log("\u{1F504} Network change detected - restarting tunnel..."),ac=r,vx(),ii&&sc&&setTimeout(()=>{console.log("\u{1F504} Restarting tunnel after network change..."),ii(sc)},2e3))},5e3))}function MR(){yo&&(clearInterval(yo),yo=null),ac=null}var RR=process.argv.includes("--skip-update"),yx=Wt.default.dirname((0,d_.fileURLToPath)(__importMetaUrl)),IR=Wt.default.resolve(yx,".."),kR=Wt.default.join(yx,"server.cjs"),u_=Wt.default.join(IR,"server/index.js"),ft="https://9remote.cc",mx=2208,s_="abcdefghijklmnpqrstuvwxyz23456789",bx=10,c_=6e4,H=q.rgb(230,138,110),LR=q.rgb(200,120,95);function NR(){return"0.1.43"}function x_(){let r=NR(),e=Math.min(44,process.stdout.columns||44);console.log(""),console.log(H("\u2554"+"\u2550".repeat(e-2)+"\u2557")),console.log(H("\u2551")+" ".repeat(e-2)+H("\u2551"));let t=`\u{1F680} 9Remote v${r}`,n=Math.floor((e-2-t.length)/2);console.log(H("\u2551")+" ".repeat(n)+H.bold(t)+" ".repeat(e-2-n-t.length)+H("\u2551"));let i="Remote terminal access from anywhere",o=Math.floor((e-2-i.length)/2);console.log(H("\u2551")+" ".repeat(o)+q.gray(i)+" ".repeat(e-2-o-i.length)+H("\u2551")),console.log(H("\u2551")+" ".repeat(e-2)+H("\u2551")),console.log(H("\u255A"+"\u2550".repeat(e-2)+"\u255D")),console.log("")}function UR(){let r="";for(let e=0;e<6;e++)r+=s_.charAt(Math.floor(Math.random()*s_.length));return r}function h_(r,e="\u{1F4F1} Scan QR to connect:"){console.log(H(`
|
|
112
112
|
${e}`)),f_.default.generate(r,{small:!0,type:"terminal",margin:0},t=>{let n=t.trim().split(`
|
|
113
113
|
`);console.log(n.join(`
|
|
114
114
|
`))})}async function p_(r,e){let t=await fx(r,ft);if(!t){console.log(q.red("\u274C Failed to create temp key"));return}let n=`${ft}/login?k=${t.tempKey}`,i=Math.min(44,process.stdout.columns||55);h_(n),console.log(q.gray(`
|
package/dist/server.cjs
CHANGED
|
@@ -22,7 +22,7 @@ Content-Length: `+s+`\r
|
|
|
22
22
|
`)+t,s=n+1,n=i.indexOf(`
|
|
23
23
|
`,s)}while(n!==-1);return r+=i.substr(s),r};Wh.exports={stringReplaceAll:_S,stringEncaseCRLFWithFirstIndex:SS}});var Xh=C((GT,Jh)=>{"use strict";var ES=/(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,Kh=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,kS=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,CS=/\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi,TS=new Map([["n",`
|
|
24
24
|
`],["r","\r"],["t"," "],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e","\x1B"],["a","\x07"]]);function Yh(i){let e=i[0]==="u",t=i[1]==="{";return e&&!t&&i.length===5||i[0]==="x"&&i.length===3?String.fromCharCode(parseInt(i.slice(1),16)):e&&t?String.fromCodePoint(parseInt(i.slice(2,-1),16)):TS.get(i)||i}function MS(i,e){let t=[],n=e.trim().split(/\s*,\s*/g),s;for(let r of n){let o=Number(r);if(!Number.isNaN(o))t.push(o);else if(s=r.match(kS))t.push(s[2].replace(CS,(a,l,p)=>l?Yh(l):p));else throw new Error(`Invalid Chalk template style argument: ${r} (in style '${i}')`)}return t}function OS(i){Kh.lastIndex=0;let e=[],t;for(;(t=Kh.exec(i))!==null;){let n=t[1];if(t[2]){let s=MS(n,t[2]);e.push([n].concat(s))}else e.push([n])}return e}function Gh(i,e){let t={};for(let s of e)for(let r of s.styles)t[r[0]]=s.inverse?null:r.slice(1);let n=i;for(let[s,r]of Object.entries(t))if(Array.isArray(r)){if(!(s in n))throw new Error(`Unknown Chalk style: ${s}`);n=r.length>0?n[s](...r):n[s]}return n}Jh.exports=(i,e)=>{let t=[],n=[],s=[];if(e.replace(ES,(r,o,a,l,p,f)=>{if(o)s.push(Yh(o));else if(l){let m=s.join("");s=[],n.push(t.length===0?m:Gh(i,t)(m)),t.push({inverse:a,styles:OS(l)})}else if(p){if(t.length===0)throw new Error("Found extraneous } in Chalk template literal");n.push(Gh(i,t)(s.join(""))),s=[],t.pop()}else s.push(f)}),n.push(s.join("")),t.length>0){let r=`Chalk template literal is missing ${t.length} closing bracket${t.length===1?"":"s"} (\`}\`)`;throw new Error(r)}return n.join("")}});var Xc=C((YT,nm)=>{"use strict";var ss=$h(),{stdout:Kc,stderr:Gc}=va(),{stringReplaceAll:AS,stringEncaseCRLFWithFirstIndex:RS}=Vh(),{isArray:Pr}=Array,Qh=["ansi","ansi","ansi256","ansi16m"],gn=Object.create(null),PS=(i,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=Kc?Kc.level:0;i.level=e.level===void 0?t:e.level},Yc=class{constructor(e){return em(e)}},em=i=>{let e={};return PS(e,i),e.template=(...t)=>im(e.template,...t),Object.setPrototypeOf(e,Br.prototype),Object.setPrototypeOf(e.template,e),e.template.constructor=()=>{throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.")},e.template.Instance=Yc,e.template};function Br(i){return em(i)}for(let[i,e]of Object.entries(ss))gn[i]={get(){let t=jr(this,Jc(e.open,e.close,this._styler),this._isEmpty);return Object.defineProperty(this,i,{value:t}),t}};gn.visible={get(){let i=jr(this,this._styler,!0);return Object.defineProperty(this,"visible",{value:i}),i}};var tm=["rgb","hex","keyword","hsl","hsv","hwb","ansi","ansi256"];for(let i of tm)gn[i]={get(){let{level:e}=this;return function(...t){let n=Jc(ss.color[Qh[e]][i](...t),ss.color.close,this._styler);return jr(this,n,this._isEmpty)}}};for(let i of tm){let e="bg"+i[0].toUpperCase()+i.slice(1);gn[e]={get(){let{level:t}=this;return function(...n){let s=Jc(ss.bgColor[Qh[t]][i](...n),ss.bgColor.close,this._styler);return jr(this,s,this._isEmpty)}}}}var BS=Object.defineProperties(()=>{},{...gn,level:{enumerable:!0,get(){return this._generator.level},set(i){this._generator.level=i}}}),Jc=(i,e,t)=>{let n,s;return t===void 0?(n=i,s=e):(n=t.openAll+i,s=e+t.closeAll),{open:i,close:e,openAll:n,closeAll:s,parent:t}},jr=(i,e,t)=>{let n=(...s)=>Pr(s[0])&&Pr(s[0].raw)?Zh(n,im(n,...s)):Zh(n,s.length===1?""+s[0]:s.join(" "));return Object.setPrototypeOf(n,BS),n._generator=i,n._styler=e,n._isEmpty=t,n},Zh=(i,e)=>{if(i.level<=0||!e)return i._isEmpty?"":e;let t=i._styler;if(t===void 0)return e;let{openAll:n,closeAll:s}=t;if(e.indexOf("\x1B")!==-1)for(;t!==void 0;)e=AS(e,t.close,t.open),t=t.parent;let r=e.indexOf(`
|
|
25
|
-
`);return r!==-1&&(e=RS(e,s,n,r)),n+e+s},Vc,im=(i,...e)=>{let[t]=e;if(!Pr(t)||!Pr(t.raw))return e.join(" ");let n=e.slice(1),s=[t.raw[0]];for(let r=1;r<t.length;r++)s.push(String(n[r-1]).replace(/[{}\\]/g,"\\$&"),String(t.raw[r]));return Vc===void 0&&(Vc=Xh()),Vc(i,s.join(""))};Object.defineProperties(Br.prototype,gn);var Nr=Br();Nr.supportsColor=Kc;Nr.stderr=Br({level:Gc?Gc.level:0});Nr.stderr.supportsColor=Gc;nm.exports=Nr});var Ve,xn=bi(()=>{Ve={webrtc:{enableWebRTC:!0,enableTurn:!1},robotSettings:{mouseDelay:2,keyboardDelay:2},throttling:{mouseThrottle:8,keyThrottle:25,typeTextThrottle:100,maxTextLength:1e3},resourceManagement:{inactiveTimeout:12e4,memoryCheckInterval:6e4,memoryWarningThreshold:1e3,maxTimersPerClient:100,maxChunkTimersPerClient:50},streaming:{activeInterval:80,idleInterval:400,idleThreshold:3,actionCaptureDelay:50,chunkSize:32,chunkDelay:5}}});var om={};wi(om,{TileManager:()=>Zc});var Dr,yn,qr,rm,FS,US,Zc,am=bi(()=>{Dr=L(require("sharp"),1),yn=L(require("fs"),1),qr=L(require("path"),1),rm=require("url"),FS=(0,rm.fileURLToPath)(__importMetaUrl),US=qr.default.dirname(FS),Zc=class{constructor(e){this.robot=e,this.tileSize=100,this.lastTileChecksums=new Map,this.screenWidth=0,this.screenHeight=0,this.tilesPerRow=0,this.tilesPerColumn=0,this.totalTiles=0,this.frameCount=0,this.tempDir=qr.default.join(US,"../../temp"),this.compressionQuality=1,this.changeThreshold=1,this.scaleFactor=.99,this.scaledWidth=0,this.scaledHeight=0,this.isProcessing=!1,this.sharedScreenCache=null,this.lastCaptureTime=0,this.CACHE_TTL=100,this.dpiScale=1,this.captureWidth=0,this.captureHeight=0,yn.default.existsSync(this.tempDir)||yn.default.mkdirSync(this.tempDir,{recursive:!0}),this.initializeScreenDimensions()}initializeScreenDimensions(){try{let{width:e,height:t}=this.robot.getScreenSize();this.screenWidth=e,this.screenHeight=t,this.detectDpiScale(),this.scaledWidth=Math.floor(e*this.scaleFactor),this.scaledHeight=Math.floor(t*this.scaleFactor),this.tilesPerRow=Math.ceil(this.scaledWidth/this.tileSize),this.tilesPerColumn=Math.ceil(this.scaledHeight/this.tileSize),this.totalTiles=this.tilesPerRow*this.tilesPerColumn;let n=100;if(this.totalTiles>n){let s=Math.ceil(Math.sqrt(this.scaledWidth*this.scaledHeight/n));this.tileSize=Math.max(s,120),this.tilesPerRow=Math.ceil(this.scaledWidth/this.tileSize),this.tilesPerColumn=Math.ceil(this.scaledHeight/this.tileSize),this.totalTiles=this.tilesPerRow*this.tilesPerColumn}console.log(`\u{1F5A5}\uFE0F TileManager: ${e}x${t} (DPI ${this.dpiScale}x) -> ${this.totalTiles} tiles`)}catch(e){console.error("Screen dimensions error:",e),this.screenWidth=1920,this.screenHeight=1080,this.dpiScale=1,this.captureWidth=1920,this.captureHeight=1080,this.scaledWidth=1728,this.scaledHeight=972,this.tileSize=120,this.tilesPerRow=Math.ceil(this.scaledWidth/this.tileSize),this.tilesPerColumn=Math.ceil(this.scaledHeight/this.tileSize),this.totalTiles=this.tilesPerRow*this.tilesPerColumn}}detectDpiScale(){let e=Math.min(100,this.screenWidth),t=Math.min(100,this.screenHeight),n=this.robot.screen.capture(0,0,e,t),r=n.byteWidth/n.bytesPerPixel/e;r>=1.9&&r<=2.1?this.dpiScale=2:this.dpiScale=1,this.captureWidth=Math.floor(this.screenWidth*this.dpiScale),this.captureHeight=Math.floor(this.screenHeight*this.dpiScale)}async captureFullScreen(){let e=this.robot.screen.capture(0,0,this.captureWidth,this.captureHeight),t=Buffer.from(e.image),n=new Uint32Array(t.buffer,t.byteOffset,t.length>>2);for(let p=0;p<n.length;p++){let f=n[p];n[p]=f&4278255360|(f&16711680)>>16|(f&255)<<16}let s=e.byteWidth/e.bytesPerPixel,r=e.height,o=t,a=s,l=r;if(this.dpiScale>1||this.scaleFactor<1){let p=Math.floor(this.screenWidth*this.scaleFactor),f=Math.floor(this.screenHeight*this.scaleFactor);o=await(0,Dr.default)(t,{raw:{width:s,height:r,channels:e.bytesPerPixel}}).resize(p,f,{kernel:Dr.default.kernel.nearest,fit:"fill"}).raw().toBuffer(),a=p,l=f}return{buffer:o,width:a,height:l,channels:e.bytesPerPixel}}async getSharedScreenCapture(){let e=Date.now();return this.sharedScreenCache&&e-this.lastCaptureTime<this.CACHE_TTL?this.sharedScreenCache:(this.sharedScreenCache=await this.captureFullScreen(),this.lastCaptureTime=e,this.sharedScreenCache)}clearScreenCache(){}async detectChangedTiles(){return(await this.detectChangedTilesWithHashes()).tiles}async detectChangedTilesWithHashes(){if(this.isProcessing)return{tiles:[],currentHashes:Array.from(this.lastTileChecksums.values())};this.isProcessing=!0;try{let e=await this.getSharedScreenCapture(),t=[],n=[],s=new Map;this.frameCount++;for(let a=0;a<this.totalTiles;a++){let l=this.calculateTileChecksumDirect(e,a);s.set(a,l)}let r=Array.from(s.values());if(this.lastTileChecksums.size===0){let a=[];for(let p=0;p<this.totalTiles;p++)this.lastTileChecksums.set(p,s.get(p)),a.push(this.processTileAsync(e,p));let l=await Promise.all(a);return t.push(...l),{tiles:t,currentHashes:r}}for(let a=0;a<this.totalTiles;a++){let l=s.get(a),p=this.lastTileChecksums.get(a);l!==p&&(n.push(a),this.lastTileChecksums.set(a,l))}if(n.length/this.totalTiles>this.changeThreshold){let a=[];for(let p=0;p<this.totalTiles;p++)a.push(this.processTileAsync(e,p));let l=await Promise.all(a);t.push(...l.map(p=>({...p,fullRefresh:!0})))}else if(n.length>0){let a=n.map(p=>this.processTileAsync(e,p)),l=await Promise.all(a);t.push(...l)}return{tiles:t,currentHashes:r}}finally{this.isProcessing=!1}}async processTileAsync(e,t,n=null){let s=n||this.extractTile(e,t),r=await this.compressTileImage(s.buffer,s.width,s.height),{row:o,col:a}=this.getTilePosition(t);return{type:"tile-update",tileIndex:t,x:a*this.tileSize,y:o*this.tileSize,width:s.width,height:s.height,imageBuffer:r,timestamp:Date.now(),frameCount:this.frameCount}}calculateTileChecksum(e){let t=0;for(let n=0;n<e.length;n+=64)t+=e[n]||0,t^=e[n+1]||0,t+=(e[n+2]||0)<<1,t^=(e[n+3]||0)<<2;return t>>>0}calculateTileChecksumDirect(e,t){let{row:n,col:s}=this.getTilePosition(t),r=s*this.tileSize,o=n*this.tileSize,a=Math.min(r+this.tileSize,e.width),l=Math.min(o+this.tileSize,e.height),p=a-r,f=l-o,m=e.channels,_=e.width*m,E=0,k=16;for(let T=0;T<f;T+=4){let M=(o+T)*_+r*m;for(let O=0;O<p;O+=k){let A=M+O*m;E+=e.buffer[A]||0,E^=e.buffer[A+1]||0,E+=(e.buffer[A+2]||0)<<1,E^=(e.buffer[A+3]||0)<<2}}return E>>>0}getTilePosition(e){return{row:Math.floor(e/this.tilesPerRow),col:e%this.tilesPerRow}}extractTile(e,t){let{row:n,col:s}=this.getTilePosition(t),r=s*this.tileSize,o=n*this.tileSize,a=Math.min(r+this.tileSize,e.width),l=Math.min(o+this.tileSize,e.height),p=a-r,f=l-o,m=e.channels,_=p*m,E=Buffer.alloc(p*f*m);for(let k=0;k<f;k++){let T=((o+k)*e.width+r)*m,M=k*_;e.buffer.copy(E,M,T,T+_)}return{buffer:E,width:p,height:f,channels:m,tileIndex:t,x:r,y:o}}async compressTileImage(e,t,n){return(0,Dr.default)(e,{raw:{width:t,height:n,channels:4}}).jpeg({quality:85}).toBuffer()}async getScreenDimensions(){try{let e=await this.captureFullScreen();this.scaledWidth=e.width,this.scaledHeight=e.height,this.tilesPerRow=Math.ceil(e.width/this.tileSize),this.tilesPerColumn=Math.ceil(e.height/this.tileSize),this.totalTiles=this.tilesPerRow*this.tilesPerColumn}catch(e){console.error("Error getting dimensions:",e)}return{width:this.scaledWidth,height:this.scaledHeight,tileWidth:this.tileSize,tileHeight:this.tileSize,tileCount:this.totalTiles,scaleFactor:this.scaleFactor,originalWidth:this.screenWidth,originalHeight:this.screenHeight}}async compareClientTileHashes(e){if(this.isProcessing)return{tiles:[],currentHashes:[],changedIndices:[]};this.isProcessing=!0;try{let t=await this.getSharedScreenCapture(),n=[],s=[];this.frameCount++;let r=new Map;for(let a=0;a<this.totalTiles;a++){let l=this.calculateTileChecksumDirect(t,a);r.set(a,l),this.lastTileChecksums.set(a,l)}if(!e||e.length===0){let a=[];for(let p=0;p<this.totalTiles;p++)a.push(this.processTileAsync(t,p));let l=await Promise.all(a);return n.push(...l),{tiles:n,currentHashes:Array.from(r.values())}}for(let a=0;a<this.totalTiles;a++)e[a]!==r.get(a)&&s.push(a);if(s.length/this.totalTiles>this.changeThreshold){let a=[];for(let p=0;p<this.totalTiles;p++)a.push(this.processTileAsync(t,p));let l=await Promise.all(a);n.push(...l.map(p=>({...p,fullRefresh:!0})))}else if(s.length>0){let a=s.map(p=>this.processTileAsync(t,p)),l=await Promise.all(a);n.push(...l)}return{tiles:n,currentHashes:Array.from(r.values()),changedIndices:s}}finally{this.isProcessing=!1}}clearMemory(){this.sharedScreenCache=null,this.lastCaptureTime=0,this.lastTileChecksums.clear()}reset(){this.lastTileChecksums.clear(),this.frameCount=0}cleanup(){try{yn.default.existsSync(this.tempDir)&&yn.default.readdirSync(this.tempDir).forEach(t=>yn.default.unlinkSync(qr.default.join(this.tempDir,t)))}catch(e){console.warn("Cleanup error:",e)}}}});var cm={};wi(cm,{ResourceManager:()=>Qc});var Qc,lm=bi(()=>{xn();Qc=class{constructor(){this.activeClients=new Map,this.activeTimers=new Map,this.chunkTimers=new Map,this.memoryCheckInterval=null}startResourceMonitoring(){this.memoryCheckInterval=setInterval(()=>{let e=process.memoryUsage(),t=Math.round(e.heapUsed/1024/1024);t>Ve.resourceManagement.memoryWarningThreshold&&(console.warn(`\u26A0\uFE0F High memory: ${t}MB`),this.cleanupInactiveClients())},Ve.resourceManagement.memoryCheckInterval)}stopResourceMonitoring(){this.memoryCheckInterval&&(clearInterval(this.memoryCheckInterval),this.memoryCheckInterval=null)}addClient(e,t){this.activeClients.set(e,{...t,lastActivity:Date.now()})}getClient(e){return this.activeClients.get(e)}updateClientActivity(e){let t=this.activeClients.get(e);t&&(t.lastActivity=Date.now())}cleanupInactiveClients(){let e=Date.now(),t=Ve.resourceManagement.inactiveTimeout;for(let[n,s]of this.activeClients.entries())e-s.lastActivity>t&&(console.log(`\u{1F9F9} Cleaning inactive client: ${n}`),this.cleanupClientResources(n,s),this.activeClients.delete(n))}cleanupClientResources(e,t){try{t.isStreaming=!1,t?.streamingTimeout&&(clearTimeout(t.streamingTimeout),t.streamingTimeout=null),t?.screenInterval&&(clearInterval(t.screenInterval),t.screenInterval=null);let n=this.activeTimers.get(e);n&&(n.forEach(r=>clearTimeout(r)),this.activeTimers.delete(e));let s=this.chunkTimers.get(e);s&&(s.forEach(r=>clearTimeout(r)),this.chunkTimers.delete(e)),t?.tileManager&&(t.tileManager.clearMemory(),t.tileManager.cleanup(),t.tileManager.reset())}catch(n){console.error(`Error cleaning up ${e}:`,n.message)}}getStreamingConfig(){return Ve.streaming}removeClient(e){let t=this.activeClients.get(e);t&&(this.cleanupClientResources(e,t),this.activeClients.delete(e))}getChunkTimers(e){return this.chunkTimers.has(e)||this.chunkTimers.set(e,new Set),this.chunkTimers.get(e)}cleanupAll(){this.stopResourceMonitoring();for(let[e,t]of this.activeClients.entries())this.cleanupClientResources(e,t);this.activeClients.clear(),this.activeTimers.clear(),this.chunkTimers.clear()}}});var um={};wi(um,{ScreenUpdateHelper:()=>el});var el,pm=bi(()=>{xn();el=class{constructor(e){this.resourceManager=e}async sendTilesInChunks(e,t,n,s=!1){if(!t||t.length===0)return;let r=Ve.streaming.chunkSize,o=[];for(let l=0;l<t.length;l+=r)o.push(t.slice(l,l+r));let a=this.resourceManager.getChunkTimers(e.id);for(let l=0;l<o.length;l++){let p=o[l],f=l===o.length-1,m=setTimeout(()=>{a.delete(m),e.connected&&e.emit("tiles-data",{tiles:p,timestamp:n,forceRefresh:!1,userAction:s,chunkInfo:{chunkIndex:l,totalChunks:o.length,isLastChunk:f}})},l*Ve.streaming.chunkDelay);a.add(m)}}}});var dm={};wi(dm,{MouseHandler:()=>tl});var tl,fm=bi(()=>{xn();tl=class{constructor(e,t){this.robot=e,this.resourceManager=t,this.lastMouseMove=0}setupMouseHandlers(e,t){let n=this.robot;e.on("mouse-move",t(s=>{let r=Date.now();if(!(r-this.lastMouseMove<Ve.throttling.mouseThrottle)){this.lastMouseMove=r;try{let o=n.getScreenSize(),a=Math.round(s.x/100*o.width),l=Math.round(s.y/100*o.height),p=Math.max(0,Math.min(o.width-1,a)),f=Math.max(0,Math.min(o.height-1,l));n.moveMouse(p,f),this.resourceManager.updateClientActivity(e.id)}catch(o){console.error("Mouse move error:",o.message)}}})),e.on("mouse-click",t(async s=>{try{let r=this.resourceManager.getClient(e.id);if(!r)return;let o=n.getScreenSize(),a=Math.round(s.x/100*o.width),l=Math.round(s.y/100*o.height),p=Math.max(0,Math.min(o.width-1,a)),f=Math.max(0,Math.min(o.height-1,l));n.moveMouse(p,f),n.mouseClick(s.button||"left",s.double||!1),r.idleFrameCount=0,this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Mouse click error:",r.message)}})),e.on("mouse-press",t(async s=>{try{if(!this.resourceManager.getClient(e.id))return;let o=n.getScreenSize(),a=Math.round(s.x/100*o.width),l=Math.round(s.y/100*o.height),p=Math.max(0,Math.min(o.width-1,a)),f=Math.max(0,Math.min(o.height-1,l));n.moveMouse(p,f),n.mouseToggle("down",s.button||"left"),this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Mouse press error:",r.message)}})),e.on("mouse-release",t(async s=>{try{if(!this.resourceManager.getClient(e.id))return;let o=n.getScreenSize(),a=Math.round(s.x/100*o.width),l=Math.round(s.y/100*o.height),p=Math.max(0,Math.min(o.width-1,a)),f=Math.max(0,Math.min(o.height-1,l));n.moveMouse(p,f),n.mouseToggle("up",s.button||"left"),this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Mouse release error:",r.message)}})),e.on("scroll",t(async s=>{try{let{direction:r,amount:o=60,horizontal:a=!1}=s,l=this.resourceManager.getClient(e.id);if(!l)return;let p=0,f=0;a||r==="left"||r==="right"?p=r==="right"?o:-o:f=r==="down"?-o:o,n.scrollMouse(p,f),l.idleFrameCount=0,this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Scroll error:",r.message)}})),e.on("mouse-drag-select",t(s=>{try{let{startX:r,startY:o,endX:a,endY:l}=s,p=n.getScreenSize(),f=Math.round(r/100*p.width),m=Math.round(o/100*p.height),_=Math.round(a/100*p.width),E=Math.round(l/100*p.height),k=Math.max(0,Math.min(p.width-1,f)),T=Math.max(0,Math.min(p.height-1,m)),M=Math.max(0,Math.min(p.width-1,_)),O=Math.max(0,Math.min(p.height-1,E));n.moveMouse(k,T),n.mouseToggle("down","left"),n.dragMouse(M,O),n.mouseToggle("up","left"),this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Drag selection error:",r.message)}}))}}});var hm={};wi(hm,{KeyboardHandler:()=>il});var il,mm=bi(()=>{xn();il=class{constructor(e,t){this.robot=e,this.resourceManager=t,this.lastKeyPress=0,this.lastTypeText=0}setupKeyboardHandlers(e,t){let n=this.robot;e.on("key-press",t(s=>{let r=Date.now();if(!(r-this.lastKeyPress<Ve.throttling.keyThrottle)){this.lastKeyPress=r;try{if(!s.key||typeof s.key!="string")return;let o=this.resourceManager.getClient(e.id),a=s.key;if(a.length===1){n.keyTap(a,s.modifier||[]);for(let l of s.modifier||[])n.keyToggle(l,"up")}else switch(a.toLowerCase()){case"enter":case"return":n.keyTap("enter");break;case"space":n.keyTap(" ");break;case"backspace":n.keyTap("backspace");break;case"tab":n.keyTap("tab");break;case"escape":n.keyTap("escape");break;default:n.keyTap(a,s.modifier||[])}o&&(o.idleFrameCount=0),this.resourceManager.updateClientActivity(e.id)}catch(o){console.error("Key press error:",o.message)}}})),e.on("type-text",t(s=>{let r=Date.now();if(!(r-this.lastTypeText<Ve.throttling.typeTextThrottle)){this.lastTypeText=r;try{if(!s.text||typeof s.text!="string")return;let o=s.text;o.length>Ve.throttling.maxTextLength&&(o=o.substring(0,Ve.throttling.maxTextLength));let a=o.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),l=this.resourceManager.getClient(e.id);setTimeout(()=>{try{n.typeString(a),this.resourceManager.updateClientActivity(e.id),l&&(l.idleFrameCount=0,l.tileManager&&l.tileManager.clearScreenCache())}catch(p){console.error("Robot typeString error:",p.message)}},10)}catch(o){console.error("Type text error:",o.message)}}}))}}});var vm={};wi(vm,{ScreenHandler:()=>nl});function HS(i){let e=Buffer.alloc(20);return e.writeUInt32LE(i.tileIndex,0),e.writeUInt32LE(i.x,4),e.writeUInt32LE(i.y,8),e.writeUInt32LE(i.width,12),e.writeUInt32LE(i.height,16),Buffer.concat([e,i.imageBuffer])}var nl,gm=bi(()=>{nl=class{constructor(e,t,n=null){this.resourceManager=e,this.screenUpdateHelper=t,this.webrtcManager=n}_sendTiles(e,t){if(this.webrtcManager?.isReady(e.id)&&t.tiles?.length>0){let n=!0;for(let s of t.tiles){let r=HS(s);if(!this.webrtcManager.sendTile(e.id,r)){n=!1;break}}if(n)return}e.emit("tiles-data",t)}setupScreenHandlers(e,t){e.on("request-screen",t(async()=>{let n=this.resourceManager.getClient(e.id);if(n)try{let s=await n.tileManager.detectChangedTiles();s.length>0&&this._sendTiles(e,{tiles:s,timestamp:Date.now()}),this.resourceManager.updateClientActivity(e.id)}catch(s){console.error("Tile capture error:",s),e.emit("screen-error",{error:s.message})}})),e.on("request-screen-with-hashes",t(async n=>{let s=this.resourceManager.getClient(e.id);if(s)try{let r=n.tileHashes||[],o=await s.tileManager.compareClientTileHashes(r);o?.tiles?.length>0?this._sendTiles(e,{tiles:o.tiles,timestamp:Date.now(),currentHashes:o.currentHashes,changedIndices:o.changedIndices}):e.emit("tiles-data",{tiles:[],timestamp:Date.now(),currentHashes:o.currentHashes,changedIndices:[]}),this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Tile capture with hashes error:",r),e.emit("screen-error",{error:r.message})}})),e.on("start-streaming",t(()=>{let n=this.resourceManager.getClient(e.id);if(!n)return;n.streamingTimeout&&(clearTimeout(n.streamingTimeout),n.streamingTimeout=null),console.log("\u{1F680} Remote streaming started"),n.idleFrameCount=0,n.isStreaming=!0;let s=async()=>{if(!e.connected||!n.isStreaming){n.streamingTimeout=null;return}try{let r=performance.now(),o=await n.tileManager.detectChangedTilesWithHashes();o.tiles.length>0&&e.connected?(this._sendTiles(e,{tiles:o.tiles,timestamp:Date.now(),currentHashes:o.currentHashes}),n.idleFrameCount=0):n.idleFrameCount++;let{activeInterval:l,idleInterval:p,idleThreshold:f}=this.resourceManager.getStreamingConfig(),m=n.idleFrameCount>=f?p:l,_=Math.max(0,m-(performance.now()-r));n.streamingTimeout=setTimeout(s,_)}catch(r){console.error("Auto streaming error:",r),n.streamingTimeout=setTimeout(s,200)}};s()})),e.on("stop-streaming",()=>{let n=this.resourceManager.getClient(e.id);n&&(n.isStreaming=!1,n.streamingTimeout&&(clearTimeout(n.streamingTimeout),n.streamingTimeout=null),console.log("\u23F9\uFE0F Remote streaming stopped"))}),e.on("get-screen-dimensions",t(async()=>{let n=this.resourceManager.getClient(e.id);if(n)try{let s=await n.tileManager.getScreenDimensions();e.emit("screen-dimensions",s)}catch(s){console.error("Get dimensions error:",s),e.emit("screen-error",{error:s.message})}})),e.on("boost-stream",t(()=>{let n=this.resourceManager.getClient(e.id);n&&(n.idleFrameCount=0)}))}}});var ll=C((qm,cl)=>{(function(i,e){"use strict";function t(b,c){if(!b)throw new Error(c||"Assertion failed")}function n(b,c){b.super_=c;var d=function(){};d.prototype=c.prototype,b.prototype=new d,b.prototype.constructor=b}function s(b,c,d){if(s.isBN(b))return b;this.negative=0,this.words=null,this.length=0,this.red=null,b!==null&&((c==="le"||c==="be")&&(d=c,c=10),this._init(b||0,c||10,d||"be"))}typeof i=="object"?i.exports=s:e.BN=s,s.BN=s,s.wordSize=26;var r;try{typeof window<"u"&&typeof window.Buffer<"u"?r=window.Buffer:r=require("buffer").Buffer}catch{}s.isBN=function(c){return c instanceof s?!0:c!==null&&typeof c=="object"&&c.constructor.wordSize===s.wordSize&&Array.isArray(c.words)},s.max=function(c,d){return c.cmp(d)>0?c:d},s.min=function(c,d){return c.cmp(d)<0?c:d},s.prototype._init=function(c,d,h){if(typeof c=="number")return this._initNumber(c,d,h);if(typeof c=="object")return this._initArray(c,d,h);d==="hex"&&(d=16),t(d===(d|0)&&d>=2&&d<=36),c=c.toString().replace(/\s+/g,"");var v=0;c[0]==="-"&&(v++,this.negative=1),v<c.length&&(d===16?this._parseHex(c,v,h):(this._parseBase(c,d,v),h==="le"&&this._initArray(this.toArray(),d,h)))},s.prototype._initNumber=function(c,d,h){c<0&&(this.negative=1,c=-c),c<67108864?(this.words=[c&67108863],this.length=1):c<4503599627370496?(this.words=[c&67108863,c/67108864&67108863],this.length=2):(t(c<9007199254740992),this.words=[c&67108863,c/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),d,h)},s.prototype._initArray=function(c,d,h){if(t(typeof c.length=="number"),c.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(c.length/3),this.words=new Array(this.length);for(var v=0;v<this.length;v++)this.words[v]=0;var y,w,S=0;if(h==="be")for(v=c.length-1,y=0;v>=0;v-=3)w=c[v]|c[v-1]<<8|c[v-2]<<16,this.words[y]|=w<<S&67108863,this.words[y+1]=w>>>26-S&67108863,S+=24,S>=26&&(S-=26,y++);else if(h==="le")for(v=0,y=0;v<c.length;v+=3)w=c[v]|c[v+1]<<8|c[v+2]<<16,this.words[y]|=w<<S&67108863,this.words[y+1]=w>>>26-S&67108863,S+=24,S>=26&&(S-=26,y++);return this.strip()};function o(b,c){var d=b.charCodeAt(c);return d>=65&&d<=70?d-55:d>=97&&d<=102?d-87:d-48&15}function a(b,c,d){var h=o(b,d);return d-1>=c&&(h|=o(b,d-1)<<4),h}s.prototype._parseHex=function(c,d,h){this.length=Math.ceil((c.length-d)/6),this.words=new Array(this.length);for(var v=0;v<this.length;v++)this.words[v]=0;var y=0,w=0,S;if(h==="be")for(v=c.length-1;v>=d;v-=2)S=a(c,d,v)<<y,this.words[w]|=S&67108863,y>=18?(y-=18,w+=1,this.words[w]|=S>>>26):y+=8;else{var g=c.length-d;for(v=g%2===0?d+1:d;v<c.length;v+=2)S=a(c,d,v)<<y,this.words[w]|=S&67108863,y>=18?(y-=18,w+=1,this.words[w]|=S>>>26):y+=8}this.strip()};function l(b,c,d,h){for(var v=0,y=Math.min(b.length,d),w=c;w<y;w++){var S=b.charCodeAt(w)-48;v*=h,S>=49?v+=S-49+10:S>=17?v+=S-17+10:v+=S}return v}s.prototype._parseBase=function(c,d,h){this.words=[0],this.length=1;for(var v=0,y=1;y<=67108863;y*=d)v++;v--,y=y/d|0;for(var w=c.length-h,S=w%v,g=Math.min(w,w-S)+h,u=0,x=h;x<g;x+=v)u=l(c,x,x+v,d),this.imuln(y),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(S!==0){var P=1;for(u=l(c,x,c.length,d),x=0;x<S;x++)P*=d;this.imuln(P),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this.strip()},s.prototype.copy=function(c){c.words=new Array(this.length);for(var d=0;d<this.length;d++)c.words[d]=this.words[d];c.length=this.length,c.negative=this.negative,c.red=this.red},s.prototype.clone=function(){var c=new s(null);return this.copy(c),c},s.prototype._expand=function(c){for(;this.length<c;)this.words[this.length++]=0;return this},s.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},s.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},s.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var p=["","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"],f=[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],m=[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];s.prototype.toString=function(c,d){c=c||10,d=d|0||1;var h;if(c===16||c==="hex"){h="";for(var v=0,y=0,w=0;w<this.length;w++){var S=this.words[w],g=((S<<v|y)&16777215).toString(16);y=S>>>24-v&16777215,v+=2,v>=26&&(v-=26,w--),y!==0||w!==this.length-1?h=p[6-g.length]+g+h:h=g+h}for(y!==0&&(h=y.toString(16)+h);h.length%d!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(c===(c|0)&&c>=2&&c<=36){var u=f[c],x=m[c];h="";var P=this.clone();for(P.negative=0;!P.isZero();){var B=P.modn(x).toString(c);P=P.idivn(x),P.isZero()?h=B+h:h=p[u-B.length]+B+h}for(this.isZero()&&(h="0"+h);h.length%d!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}t(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var c=this.words[0];return this.length===2?c+=this.words[1]*67108864:this.length===3&&this.words[2]===1?c+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-c:c},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(c,d){return t(typeof r<"u"),this.toArrayLike(r,c,d)},s.prototype.toArray=function(c,d){return this.toArrayLike(Array,c,d)},s.prototype.toArrayLike=function(c,d,h){var v=this.byteLength(),y=h||Math.max(1,v);t(v<=y,"byte array longer than desired length"),t(y>0,"Requested array length <= 0"),this.strip();var w=d==="le",S=new c(y),g,u,x=this.clone();if(w){for(u=0;!x.isZero();u++)g=x.andln(255),x.iushrn(8),S[u]=g;for(;u<y;u++)S[u]=0}else{for(u=0;u<y-v;u++)S[u]=0;for(u=0;!x.isZero();u++)g=x.andln(255),x.iushrn(8),S[y-u-1]=g}return S},Math.clz32?s.prototype._countBits=function(c){return 32-Math.clz32(c)}:s.prototype._countBits=function(c){var d=c,h=0;return d>=4096&&(h+=13,d>>>=13),d>=64&&(h+=7,d>>>=7),d>=8&&(h+=4,d>>>=4),d>=2&&(h+=2,d>>>=2),h+d},s.prototype._zeroBits=function(c){if(c===0)return 26;var d=c,h=0;return(d&8191)===0&&(h+=13,d>>>=13),(d&127)===0&&(h+=7,d>>>=7),(d&15)===0&&(h+=4,d>>>=4),(d&3)===0&&(h+=2,d>>>=2),(d&1)===0&&h++,h},s.prototype.bitLength=function(){var c=this.words[this.length-1],d=this._countBits(c);return(this.length-1)*26+d};function _(b){for(var c=new Array(b.bitLength()),d=0;d<c.length;d++){var h=d/26|0,v=d%26;c[d]=(b.words[h]&1<<v)>>>v}return c}s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var c=0,d=0;d<this.length;d++){var h=this._zeroBits(this.words[d]);if(c+=h,h!==26)break}return c},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(c){return this.negative!==0?this.abs().inotn(c).iaddn(1):this.clone()},s.prototype.fromTwos=function(c){return this.testn(c-1)?this.notn(c).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return this.negative!==0},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(c){for(;this.length<c.length;)this.words[this.length++]=0;for(var d=0;d<c.length;d++)this.words[d]=this.words[d]|c.words[d];return this.strip()},s.prototype.ior=function(c){return t((this.negative|c.negative)===0),this.iuor(c)},s.prototype.or=function(c){return this.length>c.length?this.clone().ior(c):c.clone().ior(this)},s.prototype.uor=function(c){return this.length>c.length?this.clone().iuor(c):c.clone().iuor(this)},s.prototype.iuand=function(c){var d;this.length>c.length?d=c:d=this;for(var h=0;h<d.length;h++)this.words[h]=this.words[h]&c.words[h];return this.length=d.length,this.strip()},s.prototype.iand=function(c){return t((this.negative|c.negative)===0),this.iuand(c)},s.prototype.and=function(c){return this.length>c.length?this.clone().iand(c):c.clone().iand(this)},s.prototype.uand=function(c){return this.length>c.length?this.clone().iuand(c):c.clone().iuand(this)},s.prototype.iuxor=function(c){var d,h;this.length>c.length?(d=this,h=c):(d=c,h=this);for(var v=0;v<h.length;v++)this.words[v]=d.words[v]^h.words[v];if(this!==d)for(;v<d.length;v++)this.words[v]=d.words[v];return this.length=d.length,this.strip()},s.prototype.ixor=function(c){return t((this.negative|c.negative)===0),this.iuxor(c)},s.prototype.xor=function(c){return this.length>c.length?this.clone().ixor(c):c.clone().ixor(this)},s.prototype.uxor=function(c){return this.length>c.length?this.clone().iuxor(c):c.clone().iuxor(this)},s.prototype.inotn=function(c){t(typeof c=="number"&&c>=0);var d=Math.ceil(c/26)|0,h=c%26;this._expand(d),h>0&&d--;for(var v=0;v<d;v++)this.words[v]=~this.words[v]&67108863;return h>0&&(this.words[v]=~this.words[v]&67108863>>26-h),this.strip()},s.prototype.notn=function(c){return this.clone().inotn(c)},s.prototype.setn=function(c,d){t(typeof c=="number"&&c>=0);var h=c/26|0,v=c%26;return this._expand(h+1),d?this.words[h]=this.words[h]|1<<v:this.words[h]=this.words[h]&~(1<<v),this.strip()},s.prototype.iadd=function(c){var d;if(this.negative!==0&&c.negative===0)return this.negative=0,d=this.isub(c),this.negative^=1,this._normSign();if(this.negative===0&&c.negative!==0)return c.negative=0,d=this.isub(c),c.negative=1,d._normSign();var h,v;this.length>c.length?(h=this,v=c):(h=c,v=this);for(var y=0,w=0;w<v.length;w++)d=(h.words[w]|0)+(v.words[w]|0)+y,this.words[w]=d&67108863,y=d>>>26;for(;y!==0&&w<h.length;w++)d=(h.words[w]|0)+y,this.words[w]=d&67108863,y=d>>>26;if(this.length=h.length,y!==0)this.words[this.length]=y,this.length++;else if(h!==this)for(;w<h.length;w++)this.words[w]=h.words[w];return this},s.prototype.add=function(c){var d;return c.negative!==0&&this.negative===0?(c.negative=0,d=this.sub(c),c.negative^=1,d):c.negative===0&&this.negative!==0?(this.negative=0,d=c.sub(this),this.negative=1,d):this.length>c.length?this.clone().iadd(c):c.clone().iadd(this)},s.prototype.isub=function(c){if(c.negative!==0){c.negative=0;var d=this.iadd(c);return c.negative=1,d._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(c),this.negative=1,this._normSign();var h=this.cmp(c);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var v,y;h>0?(v=this,y=c):(v=c,y=this);for(var w=0,S=0;S<y.length;S++)d=(v.words[S]|0)-(y.words[S]|0)+w,w=d>>26,this.words[S]=d&67108863;for(;w!==0&&S<v.length;S++)d=(v.words[S]|0)+w,w=d>>26,this.words[S]=d&67108863;if(w===0&&S<v.length&&v!==this)for(;S<v.length;S++)this.words[S]=v.words[S];return this.length=Math.max(this.length,S),v!==this&&(this.negative=1),this.strip()},s.prototype.sub=function(c){return this.clone().isub(c)};function E(b,c,d){d.negative=c.negative^b.negative;var h=b.length+c.length|0;d.length=h,h=h-1|0;var v=b.words[0]|0,y=c.words[0]|0,w=v*y,S=w&67108863,g=w/67108864|0;d.words[0]=S;for(var u=1;u<h;u++){for(var x=g>>>26,P=g&67108863,B=Math.min(u,c.length-1),j=Math.max(0,u-b.length+1);j<=B;j++){var D=u-j|0;v=b.words[D]|0,y=c.words[j]|0,w=v*y+P,x+=w/67108864|0,P=w&67108863}d.words[u]=P|0,g=x|0}return g!==0?d.words[u]=g|0:d.length--,d.strip()}var k=function(c,d,h){var v=c.words,y=d.words,w=h.words,S=0,g,u,x,P=v[0]|0,B=P&8191,j=P>>>13,D=v[1]|0,$=D&8191,Y=D>>>13,ri=v[2]|0,J=ri&8191,Z=ri>>>13,gu=v[3]|0,ae=gu&8191,ce=gu>>>13,xu=v[4]|0,le=xu&8191,ue=xu>>>13,yu=v[5]|0,pe=yu&8191,de=yu>>>13,bu=v[6]|0,fe=bu&8191,he=bu>>>13,wu=v[7]|0,me=wu&8191,ve=wu>>>13,_u=v[8]|0,ge=_u&8191,xe=_u>>>13,Su=v[9]|0,ye=Su&8191,be=Su>>>13,Eu=y[0]|0,we=Eu&8191,_e=Eu>>>13,ku=y[1]|0,Se=ku&8191,Ee=ku>>>13,Cu=y[2]|0,ke=Cu&8191,Ce=Cu>>>13,Tu=y[3]|0,Te=Tu&8191,Me=Tu>>>13,Mu=y[4]|0,Oe=Mu&8191,Ae=Mu>>>13,Ou=y[5]|0,Re=Ou&8191,Pe=Ou>>>13,Au=y[6]|0,Be=Au&8191,je=Au>>>13,Ru=y[7]|0,Ne=Ru&8191,Ie=Ru>>>13,Pu=y[8]|0,De=Pu&8191,qe=Pu>>>13,Bu=y[9]|0,Le=Bu&8191,Fe=Bu>>>13;h.negative=c.negative^d.negative,h.length=19,g=Math.imul(B,we),u=Math.imul(B,_e),u=u+Math.imul(j,we)|0,x=Math.imul(j,_e);var Bo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Bo>>>26)|0,Bo&=67108863,g=Math.imul($,we),u=Math.imul($,_e),u=u+Math.imul(Y,we)|0,x=Math.imul(Y,_e),g=g+Math.imul(B,Se)|0,u=u+Math.imul(B,Ee)|0,u=u+Math.imul(j,Se)|0,x=x+Math.imul(j,Ee)|0;var jo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(jo>>>26)|0,jo&=67108863,g=Math.imul(J,we),u=Math.imul(J,_e),u=u+Math.imul(Z,we)|0,x=Math.imul(Z,_e),g=g+Math.imul($,Se)|0,u=u+Math.imul($,Ee)|0,u=u+Math.imul(Y,Se)|0,x=x+Math.imul(Y,Ee)|0,g=g+Math.imul(B,ke)|0,u=u+Math.imul(B,Ce)|0,u=u+Math.imul(j,ke)|0,x=x+Math.imul(j,Ce)|0;var No=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(No>>>26)|0,No&=67108863,g=Math.imul(ae,we),u=Math.imul(ae,_e),u=u+Math.imul(ce,we)|0,x=Math.imul(ce,_e),g=g+Math.imul(J,Se)|0,u=u+Math.imul(J,Ee)|0,u=u+Math.imul(Z,Se)|0,x=x+Math.imul(Z,Ee)|0,g=g+Math.imul($,ke)|0,u=u+Math.imul($,Ce)|0,u=u+Math.imul(Y,ke)|0,x=x+Math.imul(Y,Ce)|0,g=g+Math.imul(B,Te)|0,u=u+Math.imul(B,Me)|0,u=u+Math.imul(j,Te)|0,x=x+Math.imul(j,Me)|0;var Io=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Io>>>26)|0,Io&=67108863,g=Math.imul(le,we),u=Math.imul(le,_e),u=u+Math.imul(ue,we)|0,x=Math.imul(ue,_e),g=g+Math.imul(ae,Se)|0,u=u+Math.imul(ae,Ee)|0,u=u+Math.imul(ce,Se)|0,x=x+Math.imul(ce,Ee)|0,g=g+Math.imul(J,ke)|0,u=u+Math.imul(J,Ce)|0,u=u+Math.imul(Z,ke)|0,x=x+Math.imul(Z,Ce)|0,g=g+Math.imul($,Te)|0,u=u+Math.imul($,Me)|0,u=u+Math.imul(Y,Te)|0,x=x+Math.imul(Y,Me)|0,g=g+Math.imul(B,Oe)|0,u=u+Math.imul(B,Ae)|0,u=u+Math.imul(j,Oe)|0,x=x+Math.imul(j,Ae)|0;var Do=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Do>>>26)|0,Do&=67108863,g=Math.imul(pe,we),u=Math.imul(pe,_e),u=u+Math.imul(de,we)|0,x=Math.imul(de,_e),g=g+Math.imul(le,Se)|0,u=u+Math.imul(le,Ee)|0,u=u+Math.imul(ue,Se)|0,x=x+Math.imul(ue,Ee)|0,g=g+Math.imul(ae,ke)|0,u=u+Math.imul(ae,Ce)|0,u=u+Math.imul(ce,ke)|0,x=x+Math.imul(ce,Ce)|0,g=g+Math.imul(J,Te)|0,u=u+Math.imul(J,Me)|0,u=u+Math.imul(Z,Te)|0,x=x+Math.imul(Z,Me)|0,g=g+Math.imul($,Oe)|0,u=u+Math.imul($,Ae)|0,u=u+Math.imul(Y,Oe)|0,x=x+Math.imul(Y,Ae)|0,g=g+Math.imul(B,Re)|0,u=u+Math.imul(B,Pe)|0,u=u+Math.imul(j,Re)|0,x=x+Math.imul(j,Pe)|0;var qo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(qo>>>26)|0,qo&=67108863,g=Math.imul(fe,we),u=Math.imul(fe,_e),u=u+Math.imul(he,we)|0,x=Math.imul(he,_e),g=g+Math.imul(pe,Se)|0,u=u+Math.imul(pe,Ee)|0,u=u+Math.imul(de,Se)|0,x=x+Math.imul(de,Ee)|0,g=g+Math.imul(le,ke)|0,u=u+Math.imul(le,Ce)|0,u=u+Math.imul(ue,ke)|0,x=x+Math.imul(ue,Ce)|0,g=g+Math.imul(ae,Te)|0,u=u+Math.imul(ae,Me)|0,u=u+Math.imul(ce,Te)|0,x=x+Math.imul(ce,Me)|0,g=g+Math.imul(J,Oe)|0,u=u+Math.imul(J,Ae)|0,u=u+Math.imul(Z,Oe)|0,x=x+Math.imul(Z,Ae)|0,g=g+Math.imul($,Re)|0,u=u+Math.imul($,Pe)|0,u=u+Math.imul(Y,Re)|0,x=x+Math.imul(Y,Pe)|0,g=g+Math.imul(B,Be)|0,u=u+Math.imul(B,je)|0,u=u+Math.imul(j,Be)|0,x=x+Math.imul(j,je)|0;var Lo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Lo>>>26)|0,Lo&=67108863,g=Math.imul(me,we),u=Math.imul(me,_e),u=u+Math.imul(ve,we)|0,x=Math.imul(ve,_e),g=g+Math.imul(fe,Se)|0,u=u+Math.imul(fe,Ee)|0,u=u+Math.imul(he,Se)|0,x=x+Math.imul(he,Ee)|0,g=g+Math.imul(pe,ke)|0,u=u+Math.imul(pe,Ce)|0,u=u+Math.imul(de,ke)|0,x=x+Math.imul(de,Ce)|0,g=g+Math.imul(le,Te)|0,u=u+Math.imul(le,Me)|0,u=u+Math.imul(ue,Te)|0,x=x+Math.imul(ue,Me)|0,g=g+Math.imul(ae,Oe)|0,u=u+Math.imul(ae,Ae)|0,u=u+Math.imul(ce,Oe)|0,x=x+Math.imul(ce,Ae)|0,g=g+Math.imul(J,Re)|0,u=u+Math.imul(J,Pe)|0,u=u+Math.imul(Z,Re)|0,x=x+Math.imul(Z,Pe)|0,g=g+Math.imul($,Be)|0,u=u+Math.imul($,je)|0,u=u+Math.imul(Y,Be)|0,x=x+Math.imul(Y,je)|0,g=g+Math.imul(B,Ne)|0,u=u+Math.imul(B,Ie)|0,u=u+Math.imul(j,Ne)|0,x=x+Math.imul(j,Ie)|0;var Fo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Fo>>>26)|0,Fo&=67108863,g=Math.imul(ge,we),u=Math.imul(ge,_e),u=u+Math.imul(xe,we)|0,x=Math.imul(xe,_e),g=g+Math.imul(me,Se)|0,u=u+Math.imul(me,Ee)|0,u=u+Math.imul(ve,Se)|0,x=x+Math.imul(ve,Ee)|0,g=g+Math.imul(fe,ke)|0,u=u+Math.imul(fe,Ce)|0,u=u+Math.imul(he,ke)|0,x=x+Math.imul(he,Ce)|0,g=g+Math.imul(pe,Te)|0,u=u+Math.imul(pe,Me)|0,u=u+Math.imul(de,Te)|0,x=x+Math.imul(de,Me)|0,g=g+Math.imul(le,Oe)|0,u=u+Math.imul(le,Ae)|0,u=u+Math.imul(ue,Oe)|0,x=x+Math.imul(ue,Ae)|0,g=g+Math.imul(ae,Re)|0,u=u+Math.imul(ae,Pe)|0,u=u+Math.imul(ce,Re)|0,x=x+Math.imul(ce,Pe)|0,g=g+Math.imul(J,Be)|0,u=u+Math.imul(J,je)|0,u=u+Math.imul(Z,Be)|0,x=x+Math.imul(Z,je)|0,g=g+Math.imul($,Ne)|0,u=u+Math.imul($,Ie)|0,u=u+Math.imul(Y,Ne)|0,x=x+Math.imul(Y,Ie)|0,g=g+Math.imul(B,De)|0,u=u+Math.imul(B,qe)|0,u=u+Math.imul(j,De)|0,x=x+Math.imul(j,qe)|0;var Uo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Uo>>>26)|0,Uo&=67108863,g=Math.imul(ye,we),u=Math.imul(ye,_e),u=u+Math.imul(be,we)|0,x=Math.imul(be,_e),g=g+Math.imul(ge,Se)|0,u=u+Math.imul(ge,Ee)|0,u=u+Math.imul(xe,Se)|0,x=x+Math.imul(xe,Ee)|0,g=g+Math.imul(me,ke)|0,u=u+Math.imul(me,Ce)|0,u=u+Math.imul(ve,ke)|0,x=x+Math.imul(ve,Ce)|0,g=g+Math.imul(fe,Te)|0,u=u+Math.imul(fe,Me)|0,u=u+Math.imul(he,Te)|0,x=x+Math.imul(he,Me)|0,g=g+Math.imul(pe,Oe)|0,u=u+Math.imul(pe,Ae)|0,u=u+Math.imul(de,Oe)|0,x=x+Math.imul(de,Ae)|0,g=g+Math.imul(le,Re)|0,u=u+Math.imul(le,Pe)|0,u=u+Math.imul(ue,Re)|0,x=x+Math.imul(ue,Pe)|0,g=g+Math.imul(ae,Be)|0,u=u+Math.imul(ae,je)|0,u=u+Math.imul(ce,Be)|0,x=x+Math.imul(ce,je)|0,g=g+Math.imul(J,Ne)|0,u=u+Math.imul(J,Ie)|0,u=u+Math.imul(Z,Ne)|0,x=x+Math.imul(Z,Ie)|0,g=g+Math.imul($,De)|0,u=u+Math.imul($,qe)|0,u=u+Math.imul(Y,De)|0,x=x+Math.imul(Y,qe)|0,g=g+Math.imul(B,Le)|0,u=u+Math.imul(B,Fe)|0,u=u+Math.imul(j,Le)|0,x=x+Math.imul(j,Fe)|0;var Ho=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Ho>>>26)|0,Ho&=67108863,g=Math.imul(ye,Se),u=Math.imul(ye,Ee),u=u+Math.imul(be,Se)|0,x=Math.imul(be,Ee),g=g+Math.imul(ge,ke)|0,u=u+Math.imul(ge,Ce)|0,u=u+Math.imul(xe,ke)|0,x=x+Math.imul(xe,Ce)|0,g=g+Math.imul(me,Te)|0,u=u+Math.imul(me,Me)|0,u=u+Math.imul(ve,Te)|0,x=x+Math.imul(ve,Me)|0,g=g+Math.imul(fe,Oe)|0,u=u+Math.imul(fe,Ae)|0,u=u+Math.imul(he,Oe)|0,x=x+Math.imul(he,Ae)|0,g=g+Math.imul(pe,Re)|0,u=u+Math.imul(pe,Pe)|0,u=u+Math.imul(de,Re)|0,x=x+Math.imul(de,Pe)|0,g=g+Math.imul(le,Be)|0,u=u+Math.imul(le,je)|0,u=u+Math.imul(ue,Be)|0,x=x+Math.imul(ue,je)|0,g=g+Math.imul(ae,Ne)|0,u=u+Math.imul(ae,Ie)|0,u=u+Math.imul(ce,Ne)|0,x=x+Math.imul(ce,Ie)|0,g=g+Math.imul(J,De)|0,u=u+Math.imul(J,qe)|0,u=u+Math.imul(Z,De)|0,x=x+Math.imul(Z,qe)|0,g=g+Math.imul($,Le)|0,u=u+Math.imul($,Fe)|0,u=u+Math.imul(Y,Le)|0,x=x+Math.imul(Y,Fe)|0;var zo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(zo>>>26)|0,zo&=67108863,g=Math.imul(ye,ke),u=Math.imul(ye,Ce),u=u+Math.imul(be,ke)|0,x=Math.imul(be,Ce),g=g+Math.imul(ge,Te)|0,u=u+Math.imul(ge,Me)|0,u=u+Math.imul(xe,Te)|0,x=x+Math.imul(xe,Me)|0,g=g+Math.imul(me,Oe)|0,u=u+Math.imul(me,Ae)|0,u=u+Math.imul(ve,Oe)|0,x=x+Math.imul(ve,Ae)|0,g=g+Math.imul(fe,Re)|0,u=u+Math.imul(fe,Pe)|0,u=u+Math.imul(he,Re)|0,x=x+Math.imul(he,Pe)|0,g=g+Math.imul(pe,Be)|0,u=u+Math.imul(pe,je)|0,u=u+Math.imul(de,Be)|0,x=x+Math.imul(de,je)|0,g=g+Math.imul(le,Ne)|0,u=u+Math.imul(le,Ie)|0,u=u+Math.imul(ue,Ne)|0,x=x+Math.imul(ue,Ie)|0,g=g+Math.imul(ae,De)|0,u=u+Math.imul(ae,qe)|0,u=u+Math.imul(ce,De)|0,x=x+Math.imul(ce,qe)|0,g=g+Math.imul(J,Le)|0,u=u+Math.imul(J,Fe)|0,u=u+Math.imul(Z,Le)|0,x=x+Math.imul(Z,Fe)|0;var $o=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+($o>>>26)|0,$o&=67108863,g=Math.imul(ye,Te),u=Math.imul(ye,Me),u=u+Math.imul(be,Te)|0,x=Math.imul(be,Me),g=g+Math.imul(ge,Oe)|0,u=u+Math.imul(ge,Ae)|0,u=u+Math.imul(xe,Oe)|0,x=x+Math.imul(xe,Ae)|0,g=g+Math.imul(me,Re)|0,u=u+Math.imul(me,Pe)|0,u=u+Math.imul(ve,Re)|0,x=x+Math.imul(ve,Pe)|0,g=g+Math.imul(fe,Be)|0,u=u+Math.imul(fe,je)|0,u=u+Math.imul(he,Be)|0,x=x+Math.imul(he,je)|0,g=g+Math.imul(pe,Ne)|0,u=u+Math.imul(pe,Ie)|0,u=u+Math.imul(de,Ne)|0,x=x+Math.imul(de,Ie)|0,g=g+Math.imul(le,De)|0,u=u+Math.imul(le,qe)|0,u=u+Math.imul(ue,De)|0,x=x+Math.imul(ue,qe)|0,g=g+Math.imul(ae,Le)|0,u=u+Math.imul(ae,Fe)|0,u=u+Math.imul(ce,Le)|0,x=x+Math.imul(ce,Fe)|0;var Wo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Wo>>>26)|0,Wo&=67108863,g=Math.imul(ye,Oe),u=Math.imul(ye,Ae),u=u+Math.imul(be,Oe)|0,x=Math.imul(be,Ae),g=g+Math.imul(ge,Re)|0,u=u+Math.imul(ge,Pe)|0,u=u+Math.imul(xe,Re)|0,x=x+Math.imul(xe,Pe)|0,g=g+Math.imul(me,Be)|0,u=u+Math.imul(me,je)|0,u=u+Math.imul(ve,Be)|0,x=x+Math.imul(ve,je)|0,g=g+Math.imul(fe,Ne)|0,u=u+Math.imul(fe,Ie)|0,u=u+Math.imul(he,Ne)|0,x=x+Math.imul(he,Ie)|0,g=g+Math.imul(pe,De)|0,u=u+Math.imul(pe,qe)|0,u=u+Math.imul(de,De)|0,x=x+Math.imul(de,qe)|0,g=g+Math.imul(le,Le)|0,u=u+Math.imul(le,Fe)|0,u=u+Math.imul(ue,Le)|0,x=x+Math.imul(ue,Fe)|0;var Vo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Vo>>>26)|0,Vo&=67108863,g=Math.imul(ye,Re),u=Math.imul(ye,Pe),u=u+Math.imul(be,Re)|0,x=Math.imul(be,Pe),g=g+Math.imul(ge,Be)|0,u=u+Math.imul(ge,je)|0,u=u+Math.imul(xe,Be)|0,x=x+Math.imul(xe,je)|0,g=g+Math.imul(me,Ne)|0,u=u+Math.imul(me,Ie)|0,u=u+Math.imul(ve,Ne)|0,x=x+Math.imul(ve,Ie)|0,g=g+Math.imul(fe,De)|0,u=u+Math.imul(fe,qe)|0,u=u+Math.imul(he,De)|0,x=x+Math.imul(he,qe)|0,g=g+Math.imul(pe,Le)|0,u=u+Math.imul(pe,Fe)|0,u=u+Math.imul(de,Le)|0,x=x+Math.imul(de,Fe)|0;var Ko=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Ko>>>26)|0,Ko&=67108863,g=Math.imul(ye,Be),u=Math.imul(ye,je),u=u+Math.imul(be,Be)|0,x=Math.imul(be,je),g=g+Math.imul(ge,Ne)|0,u=u+Math.imul(ge,Ie)|0,u=u+Math.imul(xe,Ne)|0,x=x+Math.imul(xe,Ie)|0,g=g+Math.imul(me,De)|0,u=u+Math.imul(me,qe)|0,u=u+Math.imul(ve,De)|0,x=x+Math.imul(ve,qe)|0,g=g+Math.imul(fe,Le)|0,u=u+Math.imul(fe,Fe)|0,u=u+Math.imul(he,Le)|0,x=x+Math.imul(he,Fe)|0;var Go=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Go>>>26)|0,Go&=67108863,g=Math.imul(ye,Ne),u=Math.imul(ye,Ie),u=u+Math.imul(be,Ne)|0,x=Math.imul(be,Ie),g=g+Math.imul(ge,De)|0,u=u+Math.imul(ge,qe)|0,u=u+Math.imul(xe,De)|0,x=x+Math.imul(xe,qe)|0,g=g+Math.imul(me,Le)|0,u=u+Math.imul(me,Fe)|0,u=u+Math.imul(ve,Le)|0,x=x+Math.imul(ve,Fe)|0;var Yo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Yo>>>26)|0,Yo&=67108863,g=Math.imul(ye,De),u=Math.imul(ye,qe),u=u+Math.imul(be,De)|0,x=Math.imul(be,qe),g=g+Math.imul(ge,Le)|0,u=u+Math.imul(ge,Fe)|0,u=u+Math.imul(xe,Le)|0,x=x+Math.imul(xe,Fe)|0;var Jo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Jo>>>26)|0,Jo&=67108863,g=Math.imul(ye,Le),u=Math.imul(ye,Fe),u=u+Math.imul(be,Le)|0,x=Math.imul(be,Fe);var Xo=(S+g|0)+((u&8191)<<13)|0;return S=(x+(u>>>13)|0)+(Xo>>>26)|0,Xo&=67108863,w[0]=Bo,w[1]=jo,w[2]=No,w[3]=Io,w[4]=Do,w[5]=qo,w[6]=Lo,w[7]=Fo,w[8]=Uo,w[9]=Ho,w[10]=zo,w[11]=$o,w[12]=Wo,w[13]=Vo,w[14]=Ko,w[15]=Go,w[16]=Yo,w[17]=Jo,w[18]=Xo,S!==0&&(w[19]=S,h.length++),h};Math.imul||(k=E);function T(b,c,d){d.negative=c.negative^b.negative,d.length=b.length+c.length;for(var h=0,v=0,y=0;y<d.length-1;y++){var w=v;v=0;for(var S=h&67108863,g=Math.min(y,c.length-1),u=Math.max(0,y-b.length+1);u<=g;u++){var x=y-u,P=b.words[x]|0,B=c.words[u]|0,j=P*B,D=j&67108863;w=w+(j/67108864|0)|0,D=D+S|0,S=D&67108863,w=w+(D>>>26)|0,v+=w>>>26,w&=67108863}d.words[y]=S,h=w,w=v}return h!==0?d.words[y]=h:d.length--,d.strip()}function M(b,c,d){var h=new O;return h.mulp(b,c,d)}s.prototype.mulTo=function(c,d){var h,v=this.length+c.length;return this.length===10&&c.length===10?h=k(this,c,d):v<63?h=E(this,c,d):v<1024?h=T(this,c,d):h=M(this,c,d),h};function O(b,c){this.x=b,this.y=c}O.prototype.makeRBT=function(c){for(var d=new Array(c),h=s.prototype._countBits(c)-1,v=0;v<c;v++)d[v]=this.revBin(v,h,c);return d},O.prototype.revBin=function(c,d,h){if(c===0||c===h-1)return c;for(var v=0,y=0;y<d;y++)v|=(c&1)<<d-y-1,c>>=1;return v},O.prototype.permute=function(c,d,h,v,y,w){for(var S=0;S<w;S++)v[S]=d[c[S]],y[S]=h[c[S]]},O.prototype.transform=function(c,d,h,v,y,w){this.permute(w,c,d,h,v,y);for(var S=1;S<y;S<<=1)for(var g=S<<1,u=Math.cos(2*Math.PI/g),x=Math.sin(2*Math.PI/g),P=0;P<y;P+=g)for(var B=u,j=x,D=0;D<S;D++){var $=h[P+D],Y=v[P+D],ri=h[P+D+S],J=v[P+D+S],Z=B*ri-j*J;J=B*J+j*ri,ri=Z,h[P+D]=$+ri,v[P+D]=Y+J,h[P+D+S]=$-ri,v[P+D+S]=Y-J,D!==g&&(Z=u*B-x*j,j=u*j+x*B,B=Z)}},O.prototype.guessLen13b=function(c,d){var h=Math.max(d,c)|1,v=h&1,y=0;for(h=h/2|0;h;h=h>>>1)y++;return 1<<y+1+v},O.prototype.conjugate=function(c,d,h){if(!(h<=1))for(var v=0;v<h/2;v++){var y=c[v];c[v]=c[h-v-1],c[h-v-1]=y,y=d[v],d[v]=-d[h-v-1],d[h-v-1]=-y}},O.prototype.normalize13b=function(c,d){for(var h=0,v=0;v<d/2;v++){var y=Math.round(c[2*v+1]/d)*8192+Math.round(c[2*v]/d)+h;c[v]=y&67108863,y<67108864?h=0:h=y/67108864|0}return c},O.prototype.convert13b=function(c,d,h,v){for(var y=0,w=0;w<d;w++)y=y+(c[w]|0),h[2*w]=y&8191,y=y>>>13,h[2*w+1]=y&8191,y=y>>>13;for(w=2*d;w<v;++w)h[w]=0;t(y===0),t((y&-8192)===0)},O.prototype.stub=function(c){for(var d=new Array(c),h=0;h<c;h++)d[h]=0;return d},O.prototype.mulp=function(c,d,h){var v=2*this.guessLen13b(c.length,d.length),y=this.makeRBT(v),w=this.stub(v),S=new Array(v),g=new Array(v),u=new Array(v),x=new Array(v),P=new Array(v),B=new Array(v),j=h.words;j.length=v,this.convert13b(c.words,c.length,S,v),this.convert13b(d.words,d.length,x,v),this.transform(S,w,g,u,v,y),this.transform(x,w,P,B,v,y);for(var D=0;D<v;D++){var $=g[D]*P[D]-u[D]*B[D];u[D]=g[D]*B[D]+u[D]*P[D],g[D]=$}return this.conjugate(g,u,v),this.transform(g,u,j,w,v,y),this.conjugate(j,w,v),this.normalize13b(j,v),h.negative=c.negative^d.negative,h.length=c.length+d.length,h.strip()},s.prototype.mul=function(c){var d=new s(null);return d.words=new Array(this.length+c.length),this.mulTo(c,d)},s.prototype.mulf=function(c){var d=new s(null);return d.words=new Array(this.length+c.length),M(this,c,d)},s.prototype.imul=function(c){return this.clone().mulTo(c,this)},s.prototype.imuln=function(c){t(typeof c=="number"),t(c<67108864);for(var d=0,h=0;h<this.length;h++){var v=(this.words[h]|0)*c,y=(v&67108863)+(d&67108863);d>>=26,d+=v/67108864|0,d+=y>>>26,this.words[h]=y&67108863}return d!==0&&(this.words[h]=d,this.length++),this.length=c===0?1:this.length,this},s.prototype.muln=function(c){return this.clone().imuln(c)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(c){var d=_(c);if(d.length===0)return new s(1);for(var h=this,v=0;v<d.length&&d[v]===0;v++,h=h.sqr());if(++v<d.length)for(var y=h.sqr();v<d.length;v++,y=y.sqr())d[v]!==0&&(h=h.mul(y));return h},s.prototype.iushln=function(c){t(typeof c=="number"&&c>=0);var d=c%26,h=(c-d)/26,v=67108863>>>26-d<<26-d,y;if(d!==0){var w=0;for(y=0;y<this.length;y++){var S=this.words[y]&v,g=(this.words[y]|0)-S<<d;this.words[y]=g|w,w=S>>>26-d}w&&(this.words[y]=w,this.length++)}if(h!==0){for(y=this.length-1;y>=0;y--)this.words[y+h]=this.words[y];for(y=0;y<h;y++)this.words[y]=0;this.length+=h}return this.strip()},s.prototype.ishln=function(c){return t(this.negative===0),this.iushln(c)},s.prototype.iushrn=function(c,d,h){t(typeof c=="number"&&c>=0);var v;d?v=(d-d%26)/26:v=0;var y=c%26,w=Math.min((c-y)/26,this.length),S=67108863^67108863>>>y<<y,g=h;if(v-=w,v=Math.max(0,v),g){for(var u=0;u<w;u++)g.words[u]=this.words[u];g.length=w}if(w!==0)if(this.length>w)for(this.length-=w,u=0;u<this.length;u++)this.words[u]=this.words[u+w];else this.words[0]=0,this.length=1;var x=0;for(u=this.length-1;u>=0&&(x!==0||u>=v);u--){var P=this.words[u]|0;this.words[u]=x<<26-y|P>>>y,x=P&S}return g&&x!==0&&(g.words[g.length++]=x),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},s.prototype.ishrn=function(c,d,h){return t(this.negative===0),this.iushrn(c,d,h)},s.prototype.shln=function(c){return this.clone().ishln(c)},s.prototype.ushln=function(c){return this.clone().iushln(c)},s.prototype.shrn=function(c){return this.clone().ishrn(c)},s.prototype.ushrn=function(c){return this.clone().iushrn(c)},s.prototype.testn=function(c){t(typeof c=="number"&&c>=0);var d=c%26,h=(c-d)/26,v=1<<d;if(this.length<=h)return!1;var y=this.words[h];return!!(y&v)},s.prototype.imaskn=function(c){t(typeof c=="number"&&c>=0);var d=c%26,h=(c-d)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(d!==0&&h++,this.length=Math.min(h,this.length),d!==0){var v=67108863^67108863>>>d<<d;this.words[this.length-1]&=v}return this.length===0&&(this.words[0]=0,this.length=1),this.strip()},s.prototype.maskn=function(c){return this.clone().imaskn(c)},s.prototype.iaddn=function(c){return t(typeof c=="number"),t(c<67108864),c<0?this.isubn(-c):this.negative!==0?this.length===1&&(this.words[0]|0)<c?(this.words[0]=c-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(c),this.negative=1,this):this._iaddn(c)},s.prototype._iaddn=function(c){this.words[0]+=c;for(var d=0;d<this.length&&this.words[d]>=67108864;d++)this.words[d]-=67108864,d===this.length-1?this.words[d+1]=1:this.words[d+1]++;return this.length=Math.max(this.length,d+1),this},s.prototype.isubn=function(c){if(t(typeof c=="number"),t(c<67108864),c<0)return this.iaddn(-c);if(this.negative!==0)return this.negative=0,this.iaddn(c),this.negative=1,this;if(this.words[0]-=c,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var d=0;d<this.length&&this.words[d]<0;d++)this.words[d]+=67108864,this.words[d+1]-=1;return this.strip()},s.prototype.addn=function(c){return this.clone().iaddn(c)},s.prototype.subn=function(c){return this.clone().isubn(c)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(c,d,h){var v=c.length+h,y;this._expand(v);var w,S=0;for(y=0;y<c.length;y++){w=(this.words[y+h]|0)+S;var g=(c.words[y]|0)*d;w-=g&67108863,S=(w>>26)-(g/67108864|0),this.words[y+h]=w&67108863}for(;y<this.length-h;y++)w=(this.words[y+h]|0)+S,S=w>>26,this.words[y+h]=w&67108863;if(S===0)return this.strip();for(t(S===-1),S=0,y=0;y<this.length;y++)w=-(this.words[y]|0)+S,S=w>>26,this.words[y]=w&67108863;return this.negative=1,this.strip()},s.prototype._wordDiv=function(c,d){var h=this.length-c.length,v=this.clone(),y=c,w=y.words[y.length-1]|0,S=this._countBits(w);h=26-S,h!==0&&(y=y.ushln(h),v.iushln(h),w=y.words[y.length-1]|0);var g=v.length-y.length,u;if(d!=="mod"){u=new s(null),u.length=g+1,u.words=new Array(u.length);for(var x=0;x<u.length;x++)u.words[x]=0}var P=v.clone()._ishlnsubmul(y,1,g);P.negative===0&&(v=P,u&&(u.words[g]=1));for(var B=g-1;B>=0;B--){var j=(v.words[y.length+B]|0)*67108864+(v.words[y.length+B-1]|0);for(j=Math.min(j/w|0,67108863),v._ishlnsubmul(y,j,B);v.negative!==0;)j--,v.negative=0,v._ishlnsubmul(y,1,B),v.isZero()||(v.negative^=1);u&&(u.words[B]=j)}return u&&u.strip(),v.strip(),d!=="div"&&h!==0&&v.iushrn(h),{div:u||null,mod:v}},s.prototype.divmod=function(c,d,h){if(t(!c.isZero()),this.isZero())return{div:new s(0),mod:new s(0)};var v,y,w;return this.negative!==0&&c.negative===0?(w=this.neg().divmod(c,d),d!=="mod"&&(v=w.div.neg()),d!=="div"&&(y=w.mod.neg(),h&&y.negative!==0&&y.iadd(c)),{div:v,mod:y}):this.negative===0&&c.negative!==0?(w=this.divmod(c.neg(),d),d!=="mod"&&(v=w.div.neg()),{div:v,mod:w.mod}):(this.negative&c.negative)!==0?(w=this.neg().divmod(c.neg(),d),d!=="div"&&(y=w.mod.neg(),h&&y.negative!==0&&y.isub(c)),{div:w.div,mod:y}):c.length>this.length||this.cmp(c)<0?{div:new s(0),mod:this}:c.length===1?d==="div"?{div:this.divn(c.words[0]),mod:null}:d==="mod"?{div:null,mod:new s(this.modn(c.words[0]))}:{div:this.divn(c.words[0]),mod:new s(this.modn(c.words[0]))}:this._wordDiv(c,d)},s.prototype.div=function(c){return this.divmod(c,"div",!1).div},s.prototype.mod=function(c){return this.divmod(c,"mod",!1).mod},s.prototype.umod=function(c){return this.divmod(c,"mod",!0).mod},s.prototype.divRound=function(c){var d=this.divmod(c);if(d.mod.isZero())return d.div;var h=d.div.negative!==0?d.mod.isub(c):d.mod,v=c.ushrn(1),y=c.andln(1),w=h.cmp(v);return w<0||y===1&&w===0?d.div:d.div.negative!==0?d.div.isubn(1):d.div.iaddn(1)},s.prototype.modn=function(c){t(c<=67108863);for(var d=(1<<26)%c,h=0,v=this.length-1;v>=0;v--)h=(d*h+(this.words[v]|0))%c;return h},s.prototype.idivn=function(c){t(c<=67108863);for(var d=0,h=this.length-1;h>=0;h--){var v=(this.words[h]|0)+d*67108864;this.words[h]=v/c|0,d=v%c}return this.strip()},s.prototype.divn=function(c){return this.clone().idivn(c)},s.prototype.egcd=function(c){t(c.negative===0),t(!c.isZero());var d=this,h=c.clone();d.negative!==0?d=d.umod(c):d=d.clone();for(var v=new s(1),y=new s(0),w=new s(0),S=new s(1),g=0;d.isEven()&&h.isEven();)d.iushrn(1),h.iushrn(1),++g;for(var u=h.clone(),x=d.clone();!d.isZero();){for(var P=0,B=1;(d.words[0]&B)===0&&P<26;++P,B<<=1);if(P>0)for(d.iushrn(P);P-- >0;)(v.isOdd()||y.isOdd())&&(v.iadd(u),y.isub(x)),v.iushrn(1),y.iushrn(1);for(var j=0,D=1;(h.words[0]&D)===0&&j<26;++j,D<<=1);if(j>0)for(h.iushrn(j);j-- >0;)(w.isOdd()||S.isOdd())&&(w.iadd(u),S.isub(x)),w.iushrn(1),S.iushrn(1);d.cmp(h)>=0?(d.isub(h),v.isub(w),y.isub(S)):(h.isub(d),w.isub(v),S.isub(y))}return{a:w,b:S,gcd:h.iushln(g)}},s.prototype._invmp=function(c){t(c.negative===0),t(!c.isZero());var d=this,h=c.clone();d.negative!==0?d=d.umod(c):d=d.clone();for(var v=new s(1),y=new s(0),w=h.clone();d.cmpn(1)>0&&h.cmpn(1)>0;){for(var S=0,g=1;(d.words[0]&g)===0&&S<26;++S,g<<=1);if(S>0)for(d.iushrn(S);S-- >0;)v.isOdd()&&v.iadd(w),v.iushrn(1);for(var u=0,x=1;(h.words[0]&x)===0&&u<26;++u,x<<=1);if(u>0)for(h.iushrn(u);u-- >0;)y.isOdd()&&y.iadd(w),y.iushrn(1);d.cmp(h)>=0?(d.isub(h),v.isub(y)):(h.isub(d),y.isub(v))}var P;return d.cmpn(1)===0?P=v:P=y,P.cmpn(0)<0&&P.iadd(c),P},s.prototype.gcd=function(c){if(this.isZero())return c.abs();if(c.isZero())return this.abs();var d=this.clone(),h=c.clone();d.negative=0,h.negative=0;for(var v=0;d.isEven()&&h.isEven();v++)d.iushrn(1),h.iushrn(1);do{for(;d.isEven();)d.iushrn(1);for(;h.isEven();)h.iushrn(1);var y=d.cmp(h);if(y<0){var w=d;d=h,h=w}else if(y===0||h.cmpn(1)===0)break;d.isub(h)}while(!0);return h.iushln(v)},s.prototype.invm=function(c){return this.egcd(c).a.umod(c)},s.prototype.isEven=function(){return(this.words[0]&1)===0},s.prototype.isOdd=function(){return(this.words[0]&1)===1},s.prototype.andln=function(c){return this.words[0]&c},s.prototype.bincn=function(c){t(typeof c=="number");var d=c%26,h=(c-d)/26,v=1<<d;if(this.length<=h)return this._expand(h+1),this.words[h]|=v,this;for(var y=v,w=h;y!==0&&w<this.length;w++){var S=this.words[w]|0;S+=y,y=S>>>26,S&=67108863,this.words[w]=S}return y!==0&&(this.words[w]=y,this.length++),this},s.prototype.isZero=function(){return this.length===1&&this.words[0]===0},s.prototype.cmpn=function(c){var d=c<0;if(this.negative!==0&&!d)return-1;if(this.negative===0&&d)return 1;this.strip();var h;if(this.length>1)h=1;else{d&&(c=-c),t(c<=67108863,"Number is too big");var v=this.words[0]|0;h=v===c?0:v<c?-1:1}return this.negative!==0?-h|0:h},s.prototype.cmp=function(c){if(this.negative!==0&&c.negative===0)return-1;if(this.negative===0&&c.negative!==0)return 1;var d=this.ucmp(c);return this.negative!==0?-d|0:d},s.prototype.ucmp=function(c){if(this.length>c.length)return 1;if(this.length<c.length)return-1;for(var d=0,h=this.length-1;h>=0;h--){var v=this.words[h]|0,y=c.words[h]|0;if(v!==y){v<y?d=-1:v>y&&(d=1);break}}return d},s.prototype.gtn=function(c){return this.cmpn(c)===1},s.prototype.gt=function(c){return this.cmp(c)===1},s.prototype.gten=function(c){return this.cmpn(c)>=0},s.prototype.gte=function(c){return this.cmp(c)>=0},s.prototype.ltn=function(c){return this.cmpn(c)===-1},s.prototype.lt=function(c){return this.cmp(c)===-1},s.prototype.lten=function(c){return this.cmpn(c)<=0},s.prototype.lte=function(c){return this.cmp(c)<=0},s.prototype.eqn=function(c){return this.cmpn(c)===0},s.prototype.eq=function(c){return this.cmp(c)===0},s.red=function(c){return new H(c)},s.prototype.toRed=function(c){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),c.convertTo(this)._forceRed(c)},s.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(c){return this.red=c,this},s.prototype.forceRed=function(c){return t(!this.red,"Already a number in reduction context"),this._forceRed(c)},s.prototype.redAdd=function(c){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,c)},s.prototype.redIAdd=function(c){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,c)},s.prototype.redSub=function(c){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,c)},s.prototype.redISub=function(c){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,c)},s.prototype.redShl=function(c){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,c)},s.prototype.redMul=function(c){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,c),this.red.mul(this,c)},s.prototype.redIMul=function(c){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,c),this.red.imul(this,c)},s.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(c){return t(this.red&&!c.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,c)};var A={k256:null,p224:null,p192:null,p25519:null};function I(b,c){this.name=b,this.p=new s(c,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}I.prototype._tmp=function(){var c=new s(null);return c.words=new Array(Math.ceil(this.n/13)),c},I.prototype.ireduce=function(c){var d=c,h;do this.split(d,this.tmp),d=this.imulK(d),d=d.iadd(this.tmp),h=d.bitLength();while(h>this.n);var v=h<this.n?-1:d.ucmp(this.p);return v===0?(d.words[0]=0,d.length=1):v>0?d.isub(this.p):d.strip!==void 0?d.strip():d._strip(),d},I.prototype.split=function(c,d){c.iushrn(this.n,0,d)},I.prototype.imulK=function(c){return c.imul(this.k)};function U(){I.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(U,I),U.prototype.split=function(c,d){for(var h=4194303,v=Math.min(c.length,9),y=0;y<v;y++)d.words[y]=c.words[y];if(d.length=v,c.length<=9){c.words[0]=0,c.length=1;return}var w=c.words[9];for(d.words[d.length++]=w&h,y=10;y<c.length;y++){var S=c.words[y]|0;c.words[y-10]=(S&h)<<4|w>>>22,w=S}w>>>=22,c.words[y-10]=w,w===0&&c.length>10?c.length-=10:c.length-=9},U.prototype.imulK=function(c){c.words[c.length]=0,c.words[c.length+1]=0,c.length+=2;for(var d=0,h=0;h<c.length;h++){var v=c.words[h]|0;d+=v*977,c.words[h]=d&67108863,d=v*64+(d/67108864|0)}return c.words[c.length-1]===0&&(c.length--,c.words[c.length-1]===0&&c.length--),c};function ee(){I.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(ee,I);function z(){I.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(z,I);function ne(){I.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(ne,I),ne.prototype.imulK=function(c){for(var d=0,h=0;h<c.length;h++){var v=(c.words[h]|0)*19+d,y=v&67108863;v>>>=26,c.words[h]=y,d=v}return d!==0&&(c.words[c.length++]=d),c},s._prime=function(c){if(A[c])return A[c];var d;if(c==="k256")d=new U;else if(c==="p224")d=new ee;else if(c==="p192")d=new z;else if(c==="p25519")d=new ne;else throw new Error("Unknown prime "+c);return A[c]=d,d};function H(b){if(typeof b=="string"){var c=s._prime(b);this.m=c.p,this.prime=c}else t(b.gtn(1),"modulus must be greater than 1"),this.m=b,this.prime=null}H.prototype._verify1=function(c){t(c.negative===0,"red works only with positives"),t(c.red,"red works only with red numbers")},H.prototype._verify2=function(c,d){t((c.negative|d.negative)===0,"red works only with positives"),t(c.red&&c.red===d.red,"red works only with red numbers")},H.prototype.imod=function(c){return this.prime?this.prime.ireduce(c)._forceRed(this):c.umod(this.m)._forceRed(this)},H.prototype.neg=function(c){return c.isZero()?c.clone():this.m.sub(c)._forceRed(this)},H.prototype.add=function(c,d){this._verify2(c,d);var h=c.add(d);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},H.prototype.iadd=function(c,d){this._verify2(c,d);var h=c.iadd(d);return h.cmp(this.m)>=0&&h.isub(this.m),h},H.prototype.sub=function(c,d){this._verify2(c,d);var h=c.sub(d);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},H.prototype.isub=function(c,d){this._verify2(c,d);var h=c.isub(d);return h.cmpn(0)<0&&h.iadd(this.m),h},H.prototype.shl=function(c,d){return this._verify1(c),this.imod(c.ushln(d))},H.prototype.imul=function(c,d){return this._verify2(c,d),this.imod(c.imul(d))},H.prototype.mul=function(c,d){return this._verify2(c,d),this.imod(c.mul(d))},H.prototype.isqr=function(c){return this.imul(c,c.clone())},H.prototype.sqr=function(c){return this.mul(c,c)},H.prototype.sqrt=function(c){if(c.isZero())return c.clone();var d=this.m.andln(3);if(t(d%2===1),d===3){var h=this.m.add(new s(1)).iushrn(2);return this.pow(c,h)}for(var v=this.m.subn(1),y=0;!v.isZero()&&v.andln(1)===0;)y++,v.iushrn(1);t(!v.isZero());var w=new s(1).toRed(this),S=w.redNeg(),g=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new s(2*u*u).toRed(this);this.pow(u,g).cmp(S)!==0;)u.redIAdd(S);for(var x=this.pow(u,v),P=this.pow(c,v.addn(1).iushrn(1)),B=this.pow(c,v),j=y;B.cmp(w)!==0;){for(var D=B,$=0;D.cmp(w)!==0;$++)D=D.redSqr();t($<j);var Y=this.pow(x,new s(1).iushln(j-$-1));P=P.redMul(Y),x=Y.redSqr(),B=B.redMul(x),j=$}return P},H.prototype.invm=function(c){var d=c._invmp(this.m);return d.negative!==0?(d.negative=0,this.imod(d).redNeg()):this.imod(d)},H.prototype.pow=function(c,d){if(d.isZero())return new s(1).toRed(this);if(d.cmpn(1)===0)return c.clone();var h=4,v=new Array(1<<h);v[0]=new s(1).toRed(this),v[1]=c;for(var y=2;y<v.length;y++)v[y]=this.mul(v[y-1],c);var w=v[0],S=0,g=0,u=d.bitLength()%26;for(u===0&&(u=26),y=d.length-1;y>=0;y--){for(var x=d.words[y],P=u-1;P>=0;P--){var B=x>>P&1;if(w!==v[0]&&(w=this.sqr(w)),B===0&&S===0){g=0;continue}S<<=1,S|=B,g++,!(g!==h&&(y!==0||P!==0))&&(w=this.mul(w,v[S]),g=0,S=0)}u=26}return w},H.prototype.convertTo=function(c){var d=c.umod(this.m);return d===c?d.clone():d},H.prototype.convertFrom=function(c){var d=c.clone();return d.red=null,d},s.mont=function(c){return new oe(c)};function oe(b){H.call(this,b),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new s(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)}n(oe,H),oe.prototype.convertTo=function(c){return this.imod(c.ushln(this.shift))},oe.prototype.convertFrom=function(c){var d=this.imod(c.mul(this.rinv));return d.red=null,d},oe.prototype.imul=function(c,d){if(c.isZero()||d.isZero())return c.words[0]=0,c.length=1,c;var h=c.imul(d),v=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=h.isub(v).iushrn(this.shift),w=y;return y.cmp(this.m)>=0?w=y.isub(this.m):y.cmpn(0)<0&&(w=y.iadd(this.m)),w._forceRed(this)},oe.prototype.mul=function(c,d){if(c.isZero()||d.isZero())return new s(0)._forceRed(this);var h=c.mul(d),v=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=h.isub(v).iushrn(this.shift),w=y;return y.cmp(this.m)>=0?w=y.isub(this.m):y.cmpn(0)<0&&(w=y.iadd(this.m)),w._forceRed(this)},oe.prototype.invm=function(c){var d=this.imod(c._invmp(this.m).mul(this.r2));return d._forceRed(this)}})(typeof cl>"u"||cl,qm)});var Lm=C((oM,ul)=>{typeof Object.create=="function"?ul.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:ul.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}});var vi=C((aM,dl)=>{try{if(pl=require("util"),typeof pl.inherits!="function")throw"";dl.exports=pl.inherits}catch{dl.exports=Lm()}var pl});var Jr=C((cM,Fm)=>{"use strict";var Yr=require("buffer"),kn=Yr.Buffer,_t={},St;for(St in Yr)Yr.hasOwnProperty(St)&&(St==="SlowBuffer"||St==="Buffer"||(_t[St]=Yr[St]));var Cn=_t.Buffer={};for(St in kn)kn.hasOwnProperty(St)&&(St==="allocUnsafe"||St==="allocUnsafeSlow"||(Cn[St]=kn[St]));_t.Buffer.prototype=kn.prototype;(!Cn.from||Cn.from===Uint8Array.from)&&(Cn.from=function(i,e,t){if(typeof i=="number")throw new TypeError('The "value" argument must not be of type number. Received type '+typeof i);if(i&&typeof i.length>"u")throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i);return kn(i,e,t)});Cn.alloc||(Cn.alloc=function(i,e,t){if(typeof i!="number")throw new TypeError('The "size" argument must be of type number. Received type '+typeof i);if(i<0||i>=2*(1<<30))throw new RangeError('The value "'+i+'" is invalid for option "size"');var n=kn(i);return!e||e.length===0?n.fill(0):typeof t=="string"?n.fill(e,t):n.fill(e),n});if(!_t.kStringMaxLength)try{_t.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}_t.constants||(_t.constants={MAX_LENGTH:_t.kMaxLength},_t.kStringMaxLength&&(_t.constants.MAX_STRING_LENGTH=_t.kStringMaxLength));Fm.exports=_t});var Xr=C(Um=>{"use strict";var rE=vi();function Et(i){this._reporterState={obj:null,path:[],options:i||{},errors:[]}}Um.Reporter=Et;Et.prototype.isError=function(e){return e instanceof Tn};Et.prototype.save=function(){let e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}};Et.prototype.restore=function(e){let t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)};Et.prototype.enterKey=function(e){return this._reporterState.path.push(e)};Et.prototype.exitKey=function(e){let t=this._reporterState;t.path=t.path.slice(0,e-1)};Et.prototype.leaveKey=function(e,t,n){let s=this._reporterState;this.exitKey(e),s.obj!==null&&(s.obj[t]=n)};Et.prototype.path=function(){return this._reporterState.path.join("/")};Et.prototype.enterObject=function(){let e=this._reporterState,t=e.obj;return e.obj={},t};Et.prototype.leaveObject=function(e){let t=this._reporterState,n=t.obj;return t.obj=e,n};Et.prototype.error=function(e){let t,n=this._reporterState,s=e instanceof Tn;if(s?t=e:t=new Tn(n.path.map(function(r){return"["+JSON.stringify(r)+"]"}).join(""),e.message||e,e.stack),!n.options.partial)throw t;return s||n.errors.push(t),t};Et.prototype.wrapResult=function(e){let t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e};function Tn(i,e){this.path=i,this.rethrow(e)}rE(Tn,Error);Tn.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,Tn),!this.stack)try{throw new Error(this.message)}catch(t){this.stack=t.stack}return this}});var An=C(fl=>{"use strict";var oE=vi(),Zr=Xr().Reporter,Mn=Jr().Buffer;function kt(i,e){if(Zr.call(this,e),!Mn.isBuffer(i)){this.error("Input not Buffer");return}this.base=i,this.offset=0,this.length=i.length}oE(kt,Zr);fl.DecoderBuffer=kt;kt.isDecoderBuffer=function(e){return e instanceof kt?!0:typeof e=="object"&&Mn.isBuffer(e.base)&&e.constructor.name==="DecoderBuffer"&&typeof e.offset=="number"&&typeof e.length=="number"&&typeof e.save=="function"&&typeof e.restore=="function"&&typeof e.isEmpty=="function"&&typeof e.readUInt8=="function"&&typeof e.skip=="function"&&typeof e.raw=="function"};kt.prototype.save=function(){return{offset:this.offset,reporter:Zr.prototype.save.call(this)}};kt.prototype.restore=function(e){let t=new kt(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,Zr.prototype.restore.call(this,e.reporter),t};kt.prototype.isEmpty=function(){return this.offset===this.length};kt.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")};kt.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");let n=new kt(this.base);return n._reporterState=this._reporterState,n.offset=this.offset,n.length=this.offset+e,this.offset+=e,n};kt.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)};function On(i,e){if(Array.isArray(i))this.length=0,this.value=i.map(function(t){return On.isEncoderBuffer(t)||(t=new On(t,e)),this.length+=t.length,t},this);else if(typeof i=="number"){if(!(0<=i&&i<=255))return e.error("non-byte EncoderBuffer value");this.value=i,this.length=1}else if(typeof i=="string")this.value=i,this.length=Mn.byteLength(i);else if(Mn.isBuffer(i))this.value=i,this.length=i.length;else return e.error("Unsupported type: "+typeof i)}fl.EncoderBuffer=On;On.isEncoderBuffer=function(e){return e instanceof On?!0:typeof e=="object"&&e.constructor.name==="EncoderBuffer"&&typeof e.length=="number"&&typeof e.join=="function"};On.prototype.join=function(e,t){return e||(e=Mn.alloc(this.length)),t||(t=0),this.length===0||(Array.isArray(this.value)?this.value.forEach(function(n){n.join(e,t),t+=n.length}):(typeof this.value=="number"?e[t]=this.value:typeof this.value=="string"?e.write(this.value,t):Mn.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e}});var $m=C((pM,zm)=>{zm.exports=Hm;function Hm(i,e){if(!i)throw new Error(e||"Assertion failed")}Hm.equal=function(e,t,n){if(e!=t)throw new Error(n||"Assertion failed: "+e+" != "+t)}});var Qr=C((dM,Vm)=>{"use strict";var aE=Xr().Reporter,cE=An().EncoderBuffer,lE=An().DecoderBuffer,et=$m(),Wm=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],uE=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(Wm),pE=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];function K(i,e,t){let n={};this._baseState=n,n.name=t,n.enc=i,n.parent=e||null,n.children=null,n.tag=null,n.args=null,n.reverseArgs=null,n.choice=null,n.optional=!1,n.any=!1,n.obj=!1,n.use=null,n.useDecoder=null,n.key=null,n.default=null,n.explicit=null,n.implicit=null,n.contains=null,n.parent||(n.children=[],this._wrap())}Vm.exports=K;var dE=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];K.prototype.clone=function(){let e=this._baseState,t={};dE.forEach(function(s){t[s]=e[s]});let n=new this.constructor(t.parent);return n._baseState=t,n};K.prototype._wrap=function(){let e=this._baseState;uE.forEach(function(t){this[t]=function(){let s=new this.constructor(this);return e.children.push(s),s[t].apply(s,arguments)}},this)};K.prototype._init=function(e){let t=this._baseState;et(t.parent===null),e.call(this),t.children=t.children.filter(function(n){return n._baseState.parent===this},this),et.equal(t.children.length,1,"Root node can have only one child")};K.prototype._useArgs=function(e){let t=this._baseState,n=e.filter(function(s){return s instanceof this.constructor},this);e=e.filter(function(s){return!(s instanceof this.constructor)},this),n.length!==0&&(et(t.children===null),t.children=n,n.forEach(function(s){s._baseState.parent=this},this)),e.length!==0&&(et(t.args===null),t.args=e,t.reverseArgs=e.map(function(s){if(typeof s!="object"||s.constructor!==Object)return s;let r={};return Object.keys(s).forEach(function(o){o==(o|0)&&(o|=0);let a=s[o];r[a]=o}),r}))};pE.forEach(function(i){K.prototype[i]=function(){let t=this._baseState;throw new Error(i+" not implemented for encoding: "+t.enc)}});Wm.forEach(function(i){K.prototype[i]=function(){let t=this._baseState,n=Array.prototype.slice.call(arguments);return et(t.tag===null),t.tag=i,this._useArgs(n),this}});K.prototype.use=function(e){et(e);let t=this._baseState;return et(t.use===null),t.use=e,this};K.prototype.optional=function(){let e=this._baseState;return e.optional=!0,this};K.prototype.def=function(e){let t=this._baseState;return et(t.default===null),t.default=e,t.optional=!0,this};K.prototype.explicit=function(e){let t=this._baseState;return et(t.explicit===null&&t.implicit===null),t.explicit=e,this};K.prototype.implicit=function(e){let t=this._baseState;return et(t.explicit===null&&t.implicit===null),t.implicit=e,this};K.prototype.obj=function(){let e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,t.length!==0&&this._useArgs(t),this};K.prototype.key=function(e){let t=this._baseState;return et(t.key===null),t.key=e,this};K.prototype.any=function(){let e=this._baseState;return e.any=!0,this};K.prototype.choice=function(e){let t=this._baseState;return et(t.choice===null),t.choice=e,this._useArgs(Object.keys(e).map(function(n){return e[n]})),this};K.prototype.contains=function(e){let t=this._baseState;return et(t.use===null),t.contains=e,this};K.prototype._decode=function(e,t){let n=this._baseState;if(n.parent===null)return e.wrapResult(n.children[0]._decode(e,t));let s=n.default,r=!0,o=null;if(n.key!==null&&(o=e.enterKey(n.key)),n.optional){let l=null;if(n.explicit!==null?l=n.explicit:n.implicit!==null?l=n.implicit:n.tag!==null&&(l=n.tag),l===null&&!n.any){let p=e.save();try{n.choice===null?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),r=!0}catch{r=!1}e.restore(p)}else if(r=this._peekTag(e,l,n.any),e.isError(r))return r}let a;if(n.obj&&r&&(a=e.enterObject()),r){if(n.explicit!==null){let p=this._decodeTag(e,n.explicit);if(e.isError(p))return p;e=p}let l=e.offset;if(n.use===null&&n.choice===null){let p;n.any&&(p=e.save());let f=this._decodeTag(e,n.implicit!==null?n.implicit:n.tag,n.any);if(e.isError(f))return f;n.any?s=e.raw(p):e=f}if(t&&t.track&&n.tag!==null&&t.track(e.path(),l,e.length,"tagged"),t&&t.track&&n.tag!==null&&t.track(e.path(),e.offset,e.length,"content"),n.any||(n.choice===null?s=this._decodeGeneric(n.tag,e,t):s=this._decodeChoice(e,t)),e.isError(s))return s;if(!n.any&&n.choice===null&&n.children!==null&&n.children.forEach(function(f){f._decode(e,t)}),n.contains&&(n.tag==="octstr"||n.tag==="bitstr")){let p=new lE(s);s=this._getUse(n.contains,e._reporterState.obj)._decode(p,t)}}return n.obj&&r&&(s=e.leaveObject(a)),n.key!==null&&(s!==null||r===!0)?e.leaveKey(o,n.key,s):o!==null&&e.exitKey(o),s};K.prototype._decodeGeneric=function(e,t,n){let s=this._baseState;return e==="seq"||e==="set"?null:e==="seqof"||e==="setof"?this._decodeList(t,e,s.args[0],n):/str$/.test(e)?this._decodeStr(t,e,n):e==="objid"&&s.args?this._decodeObjid(t,s.args[0],s.args[1],n):e==="objid"?this._decodeObjid(t,null,null,n):e==="gentime"||e==="utctime"?this._decodeTime(t,e,n):e==="null_"?this._decodeNull(t,n):e==="bool"?this._decodeBool(t,n):e==="objDesc"?this._decodeStr(t,e,n):e==="int"||e==="enum"?this._decodeInt(t,s.args&&s.args[0],n):s.use!==null?this._getUse(s.use,t._reporterState.obj)._decode(t,n):t.error("unknown tag: "+e)};K.prototype._getUse=function(e,t){let n=this._baseState;return n.useDecoder=this._use(e,t),et(n.useDecoder._baseState.parent===null),n.useDecoder=n.useDecoder._baseState.children[0],n.implicit!==n.useDecoder._baseState.implicit&&(n.useDecoder=n.useDecoder.clone(),n.useDecoder._baseState.implicit=n.implicit),n.useDecoder};K.prototype._decodeChoice=function(e,t){let n=this._baseState,s=null,r=!1;return Object.keys(n.choice).some(function(o){let a=e.save(),l=n.choice[o];try{let p=l._decode(e,t);if(e.isError(p))return!1;s={type:o,value:p},r=!0}catch{return e.restore(a),!1}return!0},this),r?s:e.error("Choice not matched")};K.prototype._createEncoderBuffer=function(e){return new cE(e,this.reporter)};K.prototype._encode=function(e,t,n){let s=this._baseState;if(s.default!==null&&s.default===e)return;let r=this._encodeValue(e,t,n);if(r!==void 0&&!this._skipDefault(r,t,n))return r};K.prototype._encodeValue=function(e,t,n){let s=this._baseState;if(s.parent===null)return s.children[0]._encode(e,t||new aE);let r=null;if(this.reporter=t,s.optional&&e===void 0)if(s.default!==null)e=s.default;else return;let o=null,a=!1;if(s.any)r=this._createEncoderBuffer(e);else if(s.choice)r=this._encodeChoice(e,t);else if(s.contains)o=this._getUse(s.contains,n)._encode(e,t),a=!0;else if(s.children)o=s.children.map(function(l){if(l._baseState.tag==="null_")return l._encode(null,t,e);if(l._baseState.key===null)return t.error("Child should have a key");let p=t.enterKey(l._baseState.key);if(typeof e!="object")return t.error("Child expected, but input is not object");let f=l._encode(e[l._baseState.key],t,e);return t.leaveKey(p),f},this).filter(function(l){return l}),o=this._createEncoderBuffer(o);else if(s.tag==="seqof"||s.tag==="setof"){if(!(s.args&&s.args.length===1))return t.error("Too many args for : "+s.tag);if(!Array.isArray(e))return t.error("seqof/setof, but data is not Array");let l=this.clone();l._baseState.implicit=null,o=this._createEncoderBuffer(e.map(function(p){let f=this._baseState;return this._getUse(f.args[0],e)._encode(p,t)},l))}else s.use!==null?r=this._getUse(s.use,n)._encode(e,t):(o=this._encodePrimitive(s.tag,e),a=!0);if(!s.any&&s.choice===null){let l=s.implicit!==null?s.implicit:s.tag,p=s.implicit===null?"universal":"context";l===null?s.use===null&&t.error("Tag could be omitted only for .use()"):s.use===null&&(r=this._encodeComposite(l,a,p,o))}return s.explicit!==null&&(r=this._encodeComposite(s.explicit,!1,"context",r)),r};K.prototype._encodeChoice=function(e,t){let n=this._baseState,s=n.choice[e.type];return s||et(!1,e.type+" not found in "+JSON.stringify(Object.keys(n.choice))),s._encode(e.value,t)};K.prototype._encodePrimitive=function(e,t){let n=this._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if(e==="objid"&&n.args)return this._encodeObjid(t,n.reverseArgs[0],n.args[1]);if(e==="objid")return this._encodeObjid(t,null,null);if(e==="gentime"||e==="utctime")return this._encodeTime(t,e);if(e==="null_")return this._encodeNull();if(e==="int"||e==="enum")return this._encodeInt(t,n.args&&n.reverseArgs[0]);if(e==="bool")return this._encodeBool(t);if(e==="objDesc")return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)};K.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)};K.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)}});var eo=C(ji=>{"use strict";function Km(i){let e={};return Object.keys(i).forEach(function(t){(t|0)==t&&(t=t|0);let n=i[t];e[n]=t}),e}ji.tagClass={0:"universal",1:"application",2:"context",3:"private"};ji.tagClassByName=Km(ji.tagClass);ji.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"};ji.tagByName=Km(ji.tag)});var ml=C((hM,Jm)=>{"use strict";var fE=vi(),ni=Jr().Buffer,Gm=Qr(),hl=eo();function Ym(i){this.enc="der",this.name=i.name,this.entity=i,this.tree=new jt,this.tree._init(i.body)}Jm.exports=Ym;Ym.prototype.encode=function(e,t){return this.tree._encode(e,t).join()};function jt(i){Gm.call(this,"der",i)}fE(jt,Gm);jt.prototype._encodeComposite=function(e,t,n,s){let r=hE(e,t,n,this.reporter);if(s.length<128){let l=ni.alloc(2);return l[0]=r,l[1]=s.length,this._createEncoderBuffer([l,s])}let o=1;for(let l=s.length;l>=256;l>>=8)o++;let a=ni.alloc(2+o);a[0]=r,a[1]=128|o;for(let l=1+o,p=s.length;p>0;l--,p>>=8)a[l]=p&255;return this._createEncoderBuffer([a,s])};jt.prototype._encodeStr=function(e,t){if(t==="bitstr")return this._createEncoderBuffer([e.unused|0,e.data]);if(t==="bmpstr"){let n=ni.alloc(e.length*2);for(let s=0;s<e.length;s++)n.writeUInt16BE(e.charCodeAt(s),s*2);return this._createEncoderBuffer(n)}else return t==="numstr"?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):t==="printstr"?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(t)?this._createEncoderBuffer(e):t==="objDesc"?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")};jt.prototype._encodeObjid=function(e,t,n){if(typeof e=="string"){if(!t)return this.reporter.error("string objid given, but no values map found");if(!t.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=t[e].split(/[\s.]+/g);for(let a=0;a<e.length;a++)e[a]|=0}else if(Array.isArray(e)){e=e.slice();for(let a=0;a<e.length;a++)e[a]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!n){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,e[0]*40+e[1])}let s=0;for(let a=0;a<e.length;a++){let l=e[a];for(s++;l>=128;l>>=7)s++}let r=ni.alloc(s),o=r.length-1;for(let a=e.length-1;a>=0;a--){let l=e[a];for(r[o--]=l&127;(l>>=7)>0;)r[o--]=128|l&127}return this._createEncoderBuffer(r)};function Ct(i){return i<10?"0"+i:i}jt.prototype._encodeTime=function(e,t){let n,s=new Date(e);return t==="gentime"?n=[Ct(s.getUTCFullYear()),Ct(s.getUTCMonth()+1),Ct(s.getUTCDate()),Ct(s.getUTCHours()),Ct(s.getUTCMinutes()),Ct(s.getUTCSeconds()),"Z"].join(""):t==="utctime"?n=[Ct(s.getUTCFullYear()%100),Ct(s.getUTCMonth()+1),Ct(s.getUTCDate()),Ct(s.getUTCHours()),Ct(s.getUTCMinutes()),Ct(s.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(n,"octstr")};jt.prototype._encodeNull=function(){return this._createEncoderBuffer("")};jt.prototype._encodeInt=function(e,t){if(typeof e=="string"){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if(typeof e!="number"&&!ni.isBuffer(e)){let r=e.toArray();!e.sign&&r[0]&128&&r.unshift(0),e=ni.from(r)}if(ni.isBuffer(e)){let r=e.length;e.length===0&&r++;let o=ni.alloc(r);return e.copy(o),e.length===0&&(o[0]=0),this._createEncoderBuffer(o)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let n=1;for(let r=e;r>=256;r>>=8)n++;let s=new Array(n);for(let r=s.length-1;r>=0;r--)s[r]=e&255,e>>=8;return s[0]&128&&s.unshift(0),this._createEncoderBuffer(ni.from(s))};jt.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)};jt.prototype._use=function(e,t){return typeof e=="function"&&(e=e(t)),e._getEncoder("der").tree};jt.prototype._skipDefault=function(e,t,n){let s=this._baseState,r;if(s.default===null)return!1;let o=e.join();if(s.defaultBuffer===void 0&&(s.defaultBuffer=this._encodeValue(s.default,t,n).join()),o.length!==s.defaultBuffer.length)return!1;for(r=0;r<o.length;r++)if(o[r]!==s.defaultBuffer[r])return!1;return!0};function hE(i,e,t,n){let s;if(i==="seqof"?i="seq":i==="setof"&&(i="set"),hl.tagByName.hasOwnProperty(i))s=hl.tagByName[i];else if(typeof i=="number"&&(i|0)===i)s=i;else return n.error("Unknown tag: "+i);return s>=31?n.error("Multi-octet tag encoding unsupported"):(e||(s|=32),s|=hl.tagClassByName[t||"universal"]<<6,s)}});var Zm=C((mM,Xm)=>{"use strict";var mE=vi(),vl=ml();function gl(i){vl.call(this,i),this.enc="pem"}mE(gl,vl);Xm.exports=gl;gl.prototype.encode=function(e,t){let s=vl.prototype.encode.call(this,e).toString("base64"),r=["-----BEGIN "+t.label+"-----"];for(let o=0;o<s.length;o+=64)r.push(s.slice(o,o+64));return r.push("-----END "+t.label+"-----"),r.join(`
|
|
25
|
+
`);return r!==-1&&(e=RS(e,s,n,r)),n+e+s},Vc,im=(i,...e)=>{let[t]=e;if(!Pr(t)||!Pr(t.raw))return e.join(" ");let n=e.slice(1),s=[t.raw[0]];for(let r=1;r<t.length;r++)s.push(String(n[r-1]).replace(/[{}\\]/g,"\\$&"),String(t.raw[r]));return Vc===void 0&&(Vc=Xh()),Vc(i,s.join(""))};Object.defineProperties(Br.prototype,gn);var Nr=Br();Nr.supportsColor=Kc;Nr.stderr=Br({level:Gc?Gc.level:0});Nr.stderr.supportsColor=Gc;nm.exports=Nr});var Ve,xn=bi(()=>{Ve={webrtc:{enableWebRTC:!0,enableTurn:!1},robotSettings:{mouseDelay:2,keyboardDelay:2},throttling:{mouseThrottle:8,keyThrottle:25,typeTextThrottle:100,maxTextLength:1e3},resourceManagement:{inactiveTimeout:12e4,memoryCheckInterval:6e4,memoryWarningThreshold:1e3,maxTimersPerClient:100,maxChunkTimersPerClient:50},streaming:{activeInterval:80,idleInterval:400,idleThreshold:3,actionCaptureDelay:50,chunkSize:32,chunkDelay:5}}});var om={};wi(om,{TileManager:()=>Zc});var Dr,yn,qr,rm,FS,US,Zc,am=bi(()=>{Dr=L(require("sharp"),1),yn=L(require("fs"),1),qr=L(require("path"),1),rm=require("url"),FS=(0,rm.fileURLToPath)(__importMetaUrl),US=qr.default.dirname(FS),Zc=class{constructor(e){this.robot=e,this.tileSize=100,this.lastTileChecksums=new Map,this.screenWidth=0,this.screenHeight=0,this.tilesPerRow=0,this.tilesPerColumn=0,this.totalTiles=0,this.frameCount=0,this.tempDir=qr.default.join(US,"../../temp"),this.compressionQuality=1,this.changeThreshold=1,this.scaleFactor=.99,this.scaledWidth=0,this.scaledHeight=0,this.isProcessing=!1,this.sharedScreenCache=null,this.lastCaptureTime=0,this.CACHE_TTL=100,this.dpiScale=1,this.captureWidth=0,this.captureHeight=0,yn.default.existsSync(this.tempDir)||yn.default.mkdirSync(this.tempDir,{recursive:!0}),this.initializeScreenDimensions()}initializeScreenDimensions(){try{let{width:e,height:t}=this.robot.getScreenSize();this.screenWidth=e,this.screenHeight=t,this.detectDpiScale(),this.scaledWidth=Math.floor(e*this.scaleFactor),this.scaledHeight=Math.floor(t*this.scaleFactor),this.tilesPerRow=Math.ceil(this.scaledWidth/this.tileSize),this.tilesPerColumn=Math.ceil(this.scaledHeight/this.tileSize),this.totalTiles=this.tilesPerRow*this.tilesPerColumn;let n=100;if(this.totalTiles>n){let s=Math.ceil(Math.sqrt(this.scaledWidth*this.scaledHeight/n));this.tileSize=Math.max(s,120),this.tilesPerRow=Math.ceil(this.scaledWidth/this.tileSize),this.tilesPerColumn=Math.ceil(this.scaledHeight/this.tileSize),this.totalTiles=this.tilesPerRow*this.tilesPerColumn}console.log(`\u{1F5A5}\uFE0F TileManager: ${e}x${t} (DPI ${this.dpiScale}x) -> ${this.totalTiles} tiles`)}catch(e){console.error("Screen dimensions error:",e),this.screenWidth=1920,this.screenHeight=1080,this.dpiScale=1,this.captureWidth=1920,this.captureHeight=1080,this.scaledWidth=1728,this.scaledHeight=972,this.tileSize=120,this.tilesPerRow=Math.ceil(this.scaledWidth/this.tileSize),this.tilesPerColumn=Math.ceil(this.scaledHeight/this.tileSize),this.totalTiles=this.tilesPerRow*this.tilesPerColumn}}detectDpiScale(){if(process.platform==="darwin"){let e=this.robot.screen.capture(0,0,1,1);this.dpiScale=e.byteWidth/e.bytesPerPixel}else{let e=Math.min(this.screenWidth*2,4096),t=Math.min(this.screenHeight*2,4096),n=this.robot.screen.capture(0,0,e,t),s=n.byteWidth/n.bytesPerPixel;s>this.screenWidth?this.dpiScale=s/this.screenWidth:this.dpiScale=1}this.captureWidth=Math.floor(this.screenWidth*this.dpiScale),this.captureHeight=Math.floor(this.screenHeight*this.dpiScale)}async captureFullScreen(){let e=this.robot.screen.capture(0,0,this.captureWidth,this.captureHeight),t=Buffer.from(e.image),n=new Uint32Array(t.buffer,t.byteOffset,t.length>>2);for(let p=0;p<n.length;p++){let f=n[p];n[p]=f&4278255360|(f&16711680)>>16|(f&255)<<16}let s=e.byteWidth/e.bytesPerPixel,r=e.height,o=t,a=s,l=r;if(this.dpiScale>1||this.scaleFactor<1){let p=Math.floor(this.screenWidth*this.scaleFactor),f=Math.floor(this.screenHeight*this.scaleFactor);o=await(0,Dr.default)(t,{raw:{width:s,height:r,channels:e.bytesPerPixel}}).resize(p,f,{kernel:Dr.default.kernel.nearest,fit:"fill"}).raw().toBuffer(),a=p,l=f}return{buffer:o,width:a,height:l,channels:e.bytesPerPixel}}async getSharedScreenCapture(){let e=Date.now();return this.sharedScreenCache&&e-this.lastCaptureTime<this.CACHE_TTL?this.sharedScreenCache:(this.sharedScreenCache=await this.captureFullScreen(),this.lastCaptureTime=e,this.sharedScreenCache)}clearScreenCache(){}async detectChangedTiles(){return(await this.detectChangedTilesWithHashes()).tiles}async detectChangedTilesWithHashes(){if(this.isProcessing)return{tiles:[],currentHashes:Array.from(this.lastTileChecksums.values())};this.isProcessing=!0;try{let e=await this.getSharedScreenCapture(),t=[],n=[],s=new Map;this.frameCount++;for(let a=0;a<this.totalTiles;a++){let l=this.calculateTileChecksumDirect(e,a);s.set(a,l)}let r=Array.from(s.values());if(this.lastTileChecksums.size===0){let a=[];for(let p=0;p<this.totalTiles;p++)this.lastTileChecksums.set(p,s.get(p)),a.push(this.processTileAsync(e,p));let l=await Promise.all(a);return t.push(...l),{tiles:t,currentHashes:r}}for(let a=0;a<this.totalTiles;a++){let l=s.get(a),p=this.lastTileChecksums.get(a);l!==p&&(n.push(a),this.lastTileChecksums.set(a,l))}if(n.length/this.totalTiles>this.changeThreshold){let a=[];for(let p=0;p<this.totalTiles;p++)a.push(this.processTileAsync(e,p));let l=await Promise.all(a);t.push(...l.map(p=>({...p,fullRefresh:!0})))}else if(n.length>0){let a=n.map(p=>this.processTileAsync(e,p)),l=await Promise.all(a);t.push(...l)}return{tiles:t,currentHashes:r}}finally{this.isProcessing=!1}}async processTileAsync(e,t,n=null){let s=n||this.extractTile(e,t),r=await this.compressTileImage(s.buffer,s.width,s.height),{row:o,col:a}=this.getTilePosition(t);return{type:"tile-update",tileIndex:t,x:a*this.tileSize,y:o*this.tileSize,width:s.width,height:s.height,imageBuffer:r,timestamp:Date.now(),frameCount:this.frameCount}}calculateTileChecksum(e){let t=0;for(let n=0;n<e.length;n+=64)t+=e[n]||0,t^=e[n+1]||0,t+=(e[n+2]||0)<<1,t^=(e[n+3]||0)<<2;return t>>>0}calculateTileChecksumDirect(e,t){let{row:n,col:s}=this.getTilePosition(t),r=s*this.tileSize,o=n*this.tileSize,a=Math.min(r+this.tileSize,e.width),l=Math.min(o+this.tileSize,e.height),p=a-r,f=l-o,m=e.channels,_=e.width*m,E=0,k=16;for(let T=0;T<f;T+=4){let M=(o+T)*_+r*m;for(let O=0;O<p;O+=k){let A=M+O*m;E+=e.buffer[A]||0,E^=e.buffer[A+1]||0,E+=(e.buffer[A+2]||0)<<1,E^=(e.buffer[A+3]||0)<<2}}return E>>>0}getTilePosition(e){return{row:Math.floor(e/this.tilesPerRow),col:e%this.tilesPerRow}}extractTile(e,t){let{row:n,col:s}=this.getTilePosition(t),r=s*this.tileSize,o=n*this.tileSize,a=Math.min(r+this.tileSize,e.width),l=Math.min(o+this.tileSize,e.height),p=a-r,f=l-o,m=e.channels,_=p*m,E=Buffer.alloc(p*f*m);for(let k=0;k<f;k++){let T=((o+k)*e.width+r)*m,M=k*_;e.buffer.copy(E,M,T,T+_)}return{buffer:E,width:p,height:f,channels:m,tileIndex:t,x:r,y:o}}async compressTileImage(e,t,n){return(0,Dr.default)(e,{raw:{width:t,height:n,channels:4}}).jpeg({quality:85}).toBuffer()}async getScreenDimensions(){try{let e=await this.captureFullScreen();this.scaledWidth=e.width,this.scaledHeight=e.height,this.tilesPerRow=Math.ceil(e.width/this.tileSize),this.tilesPerColumn=Math.ceil(e.height/this.tileSize),this.totalTiles=this.tilesPerRow*this.tilesPerColumn}catch(e){console.error("Error getting dimensions:",e)}return{width:this.scaledWidth,height:this.scaledHeight,tileWidth:this.tileSize,tileHeight:this.tileSize,tileCount:this.totalTiles,scaleFactor:this.scaleFactor,originalWidth:this.screenWidth,originalHeight:this.screenHeight}}async compareClientTileHashes(e){if(this.isProcessing)return{tiles:[],currentHashes:[],changedIndices:[]};this.isProcessing=!0;try{let t=await this.getSharedScreenCapture(),n=[],s=[];this.frameCount++;let r=new Map;for(let a=0;a<this.totalTiles;a++){let l=this.calculateTileChecksumDirect(t,a);r.set(a,l),this.lastTileChecksums.set(a,l)}if(!e||e.length===0){let a=[];for(let p=0;p<this.totalTiles;p++)a.push(this.processTileAsync(t,p));let l=await Promise.all(a);return n.push(...l),{tiles:n,currentHashes:Array.from(r.values())}}for(let a=0;a<this.totalTiles;a++)e[a]!==r.get(a)&&s.push(a);if(s.length/this.totalTiles>this.changeThreshold){let a=[];for(let p=0;p<this.totalTiles;p++)a.push(this.processTileAsync(t,p));let l=await Promise.all(a);n.push(...l.map(p=>({...p,fullRefresh:!0})))}else if(s.length>0){let a=s.map(p=>this.processTileAsync(t,p)),l=await Promise.all(a);n.push(...l)}return{tiles:n,currentHashes:Array.from(r.values()),changedIndices:s}}finally{this.isProcessing=!1}}clearMemory(){this.sharedScreenCache=null,this.lastCaptureTime=0,this.lastTileChecksums.clear()}reset(){this.lastTileChecksums.clear(),this.frameCount=0}cleanup(){try{yn.default.existsSync(this.tempDir)&&yn.default.readdirSync(this.tempDir).forEach(t=>yn.default.unlinkSync(qr.default.join(this.tempDir,t)))}catch(e){console.warn("Cleanup error:",e)}}}});var cm={};wi(cm,{ResourceManager:()=>Qc});var Qc,lm=bi(()=>{xn();Qc=class{constructor(){this.activeClients=new Map,this.activeTimers=new Map,this.chunkTimers=new Map,this.memoryCheckInterval=null}startResourceMonitoring(){this.memoryCheckInterval=setInterval(()=>{let e=process.memoryUsage(),t=Math.round(e.heapUsed/1024/1024);t>Ve.resourceManagement.memoryWarningThreshold&&(console.warn(`\u26A0\uFE0F High memory: ${t}MB`),this.cleanupInactiveClients())},Ve.resourceManagement.memoryCheckInterval)}stopResourceMonitoring(){this.memoryCheckInterval&&(clearInterval(this.memoryCheckInterval),this.memoryCheckInterval=null)}addClient(e,t){this.activeClients.set(e,{...t,lastActivity:Date.now()})}getClient(e){return this.activeClients.get(e)}updateClientActivity(e){let t=this.activeClients.get(e);t&&(t.lastActivity=Date.now())}cleanupInactiveClients(){let e=Date.now(),t=Ve.resourceManagement.inactiveTimeout;for(let[n,s]of this.activeClients.entries())e-s.lastActivity>t&&(console.log(`\u{1F9F9} Cleaning inactive client: ${n}`),this.cleanupClientResources(n,s),this.activeClients.delete(n))}cleanupClientResources(e,t){try{t.isStreaming=!1,t?.streamingTimeout&&(clearTimeout(t.streamingTimeout),t.streamingTimeout=null),t?.screenInterval&&(clearInterval(t.screenInterval),t.screenInterval=null);let n=this.activeTimers.get(e);n&&(n.forEach(r=>clearTimeout(r)),this.activeTimers.delete(e));let s=this.chunkTimers.get(e);s&&(s.forEach(r=>clearTimeout(r)),this.chunkTimers.delete(e)),t?.tileManager&&(t.tileManager.clearMemory(),t.tileManager.cleanup(),t.tileManager.reset())}catch(n){console.error(`Error cleaning up ${e}:`,n.message)}}getStreamingConfig(){return Ve.streaming}removeClient(e){let t=this.activeClients.get(e);t&&(this.cleanupClientResources(e,t),this.activeClients.delete(e))}getChunkTimers(e){return this.chunkTimers.has(e)||this.chunkTimers.set(e,new Set),this.chunkTimers.get(e)}cleanupAll(){this.stopResourceMonitoring();for(let[e,t]of this.activeClients.entries())this.cleanupClientResources(e,t);this.activeClients.clear(),this.activeTimers.clear(),this.chunkTimers.clear()}}});var um={};wi(um,{ScreenUpdateHelper:()=>el});var el,pm=bi(()=>{xn();el=class{constructor(e){this.resourceManager=e}async sendTilesInChunks(e,t,n,s=!1){if(!t||t.length===0)return;let r=Ve.streaming.chunkSize,o=[];for(let l=0;l<t.length;l+=r)o.push(t.slice(l,l+r));let a=this.resourceManager.getChunkTimers(e.id);for(let l=0;l<o.length;l++){let p=o[l],f=l===o.length-1,m=setTimeout(()=>{a.delete(m),e.connected&&e.emit("tiles-data",{tiles:p,timestamp:n,forceRefresh:!1,userAction:s,chunkInfo:{chunkIndex:l,totalChunks:o.length,isLastChunk:f}})},l*Ve.streaming.chunkDelay);a.add(m)}}}});var dm={};wi(dm,{MouseHandler:()=>tl});var tl,fm=bi(()=>{xn();tl=class{constructor(e,t){this.robot=e,this.resourceManager=t,this.lastMouseMove=0}setupMouseHandlers(e,t){let n=this.robot;e.on("mouse-move",t(s=>{let r=Date.now();if(!(r-this.lastMouseMove<Ve.throttling.mouseThrottle)){this.lastMouseMove=r;try{let o=n.getScreenSize(),a=Math.round(s.x/100*o.width),l=Math.round(s.y/100*o.height),p=Math.max(0,Math.min(o.width-1,a)),f=Math.max(0,Math.min(o.height-1,l));n.moveMouse(p,f),this.resourceManager.updateClientActivity(e.id)}catch(o){console.error("Mouse move error:",o.message)}}})),e.on("mouse-click",t(async s=>{try{let r=this.resourceManager.getClient(e.id);if(!r)return;let o=n.getScreenSize(),a=Math.round(s.x/100*o.width),l=Math.round(s.y/100*o.height),p=Math.max(0,Math.min(o.width-1,a)),f=Math.max(0,Math.min(o.height-1,l));n.moveMouse(p,f),n.mouseClick(s.button||"left",s.double||!1),r.idleFrameCount=0,this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Mouse click error:",r.message)}})),e.on("mouse-press",t(async s=>{try{if(!this.resourceManager.getClient(e.id))return;let o=n.getScreenSize(),a=Math.round(s.x/100*o.width),l=Math.round(s.y/100*o.height),p=Math.max(0,Math.min(o.width-1,a)),f=Math.max(0,Math.min(o.height-1,l));n.moveMouse(p,f),n.mouseToggle("down",s.button||"left"),this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Mouse press error:",r.message)}})),e.on("mouse-release",t(async s=>{try{if(!this.resourceManager.getClient(e.id))return;let o=n.getScreenSize(),a=Math.round(s.x/100*o.width),l=Math.round(s.y/100*o.height),p=Math.max(0,Math.min(o.width-1,a)),f=Math.max(0,Math.min(o.height-1,l));n.moveMouse(p,f),n.mouseToggle("up",s.button||"left"),this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Mouse release error:",r.message)}})),e.on("scroll",t(async s=>{try{let{direction:r,amount:o=60,horizontal:a=!1}=s,l=this.resourceManager.getClient(e.id);if(!l)return;let p=0,f=0;a||r==="left"||r==="right"?p=r==="right"?o:-o:f=r==="down"?-o:o,n.scrollMouse(p,f),l.idleFrameCount=0,this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Scroll error:",r.message)}})),e.on("mouse-drag-select",t(s=>{try{let{startX:r,startY:o,endX:a,endY:l}=s,p=n.getScreenSize(),f=Math.round(r/100*p.width),m=Math.round(o/100*p.height),_=Math.round(a/100*p.width),E=Math.round(l/100*p.height),k=Math.max(0,Math.min(p.width-1,f)),T=Math.max(0,Math.min(p.height-1,m)),M=Math.max(0,Math.min(p.width-1,_)),O=Math.max(0,Math.min(p.height-1,E));n.moveMouse(k,T),n.mouseToggle("down","left"),n.dragMouse(M,O),n.mouseToggle("up","left"),this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Drag selection error:",r.message)}}))}}});var hm={};wi(hm,{KeyboardHandler:()=>il});var il,mm=bi(()=>{xn();il=class{constructor(e,t){this.robot=e,this.resourceManager=t,this.lastKeyPress=0,this.lastTypeText=0}setupKeyboardHandlers(e,t){let n=this.robot;e.on("key-press",t(s=>{let r=Date.now();if(!(r-this.lastKeyPress<Ve.throttling.keyThrottle)){this.lastKeyPress=r;try{if(!s.key||typeof s.key!="string")return;let o=this.resourceManager.getClient(e.id),a=s.key;if(a.length===1){n.keyTap(a,s.modifier||[]);for(let l of s.modifier||[])n.keyToggle(l,"up")}else switch(a.toLowerCase()){case"enter":case"return":n.keyTap("enter");break;case"space":n.keyTap(" ");break;case"backspace":n.keyTap("backspace");break;case"tab":n.keyTap("tab");break;case"escape":n.keyTap("escape");break;default:n.keyTap(a,s.modifier||[])}o&&(o.idleFrameCount=0),this.resourceManager.updateClientActivity(e.id)}catch(o){console.error("Key press error:",o.message)}}})),e.on("type-text",t(s=>{let r=Date.now();if(!(r-this.lastTypeText<Ve.throttling.typeTextThrottle)){this.lastTypeText=r;try{if(!s.text||typeof s.text!="string")return;let o=s.text;o.length>Ve.throttling.maxTextLength&&(o=o.substring(0,Ve.throttling.maxTextLength));let a=o.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),l=this.resourceManager.getClient(e.id);setTimeout(()=>{try{n.typeString(a),this.resourceManager.updateClientActivity(e.id),l&&(l.idleFrameCount=0,l.tileManager&&l.tileManager.clearScreenCache())}catch(p){console.error("Robot typeString error:",p.message)}},10)}catch(o){console.error("Type text error:",o.message)}}}))}}});var vm={};wi(vm,{ScreenHandler:()=>nl});function HS(i){let e=Buffer.alloc(20);return e.writeUInt32LE(i.tileIndex,0),e.writeUInt32LE(i.x,4),e.writeUInt32LE(i.y,8),e.writeUInt32LE(i.width,12),e.writeUInt32LE(i.height,16),Buffer.concat([e,i.imageBuffer])}var nl,gm=bi(()=>{nl=class{constructor(e,t,n=null){this.resourceManager=e,this.screenUpdateHelper=t,this.webrtcManager=n}_sendTiles(e,t){if(this.webrtcManager?.isReady(e.id)&&t.tiles?.length>0){let n=!0;for(let s of t.tiles){let r=HS(s);if(!this.webrtcManager.sendTile(e.id,r)){n=!1;break}}if(n)return}e.emit("tiles-data",t)}setupScreenHandlers(e,t){e.on("request-screen",t(async()=>{let n=this.resourceManager.getClient(e.id);if(n)try{let s=await n.tileManager.detectChangedTiles();s.length>0&&this._sendTiles(e,{tiles:s,timestamp:Date.now()}),this.resourceManager.updateClientActivity(e.id)}catch(s){console.error("Tile capture error:",s),e.emit("screen-error",{error:s.message})}})),e.on("request-screen-with-hashes",t(async n=>{let s=this.resourceManager.getClient(e.id);if(s)try{let r=n.tileHashes||[],o=await s.tileManager.compareClientTileHashes(r);o?.tiles?.length>0?this._sendTiles(e,{tiles:o.tiles,timestamp:Date.now(),currentHashes:o.currentHashes,changedIndices:o.changedIndices}):e.emit("tiles-data",{tiles:[],timestamp:Date.now(),currentHashes:o.currentHashes,changedIndices:[]}),this.resourceManager.updateClientActivity(e.id)}catch(r){console.error("Tile capture with hashes error:",r),e.emit("screen-error",{error:r.message})}})),e.on("start-streaming",t(()=>{let n=this.resourceManager.getClient(e.id);if(!n)return;n.streamingTimeout&&(clearTimeout(n.streamingTimeout),n.streamingTimeout=null),console.log("\u{1F680} Remote streaming started"),n.idleFrameCount=0,n.isStreaming=!0;let s=async()=>{if(!e.connected||!n.isStreaming){n.streamingTimeout=null;return}try{let r=performance.now(),o=await n.tileManager.detectChangedTilesWithHashes();o.tiles.length>0&&e.connected?(this._sendTiles(e,{tiles:o.tiles,timestamp:Date.now(),currentHashes:o.currentHashes}),n.idleFrameCount=0):n.idleFrameCount++;let{activeInterval:l,idleInterval:p,idleThreshold:f}=this.resourceManager.getStreamingConfig(),m=n.idleFrameCount>=f?p:l,_=Math.max(0,m-(performance.now()-r));n.streamingTimeout=setTimeout(s,_)}catch(r){console.error("Auto streaming error:",r),n.streamingTimeout=setTimeout(s,200)}};s()})),e.on("stop-streaming",()=>{let n=this.resourceManager.getClient(e.id);n&&(n.isStreaming=!1,n.streamingTimeout&&(clearTimeout(n.streamingTimeout),n.streamingTimeout=null),console.log("\u23F9\uFE0F Remote streaming stopped"))}),e.on("get-screen-dimensions",t(async()=>{let n=this.resourceManager.getClient(e.id);if(n)try{let s=await n.tileManager.getScreenDimensions();e.emit("screen-dimensions",s)}catch(s){console.error("Get dimensions error:",s),e.emit("screen-error",{error:s.message})}})),e.on("boost-stream",t(()=>{let n=this.resourceManager.getClient(e.id);n&&(n.idleFrameCount=0)}))}}});var ll=C((qm,cl)=>{(function(i,e){"use strict";function t(b,c){if(!b)throw new Error(c||"Assertion failed")}function n(b,c){b.super_=c;var d=function(){};d.prototype=c.prototype,b.prototype=new d,b.prototype.constructor=b}function s(b,c,d){if(s.isBN(b))return b;this.negative=0,this.words=null,this.length=0,this.red=null,b!==null&&((c==="le"||c==="be")&&(d=c,c=10),this._init(b||0,c||10,d||"be"))}typeof i=="object"?i.exports=s:e.BN=s,s.BN=s,s.wordSize=26;var r;try{typeof window<"u"&&typeof window.Buffer<"u"?r=window.Buffer:r=require("buffer").Buffer}catch{}s.isBN=function(c){return c instanceof s?!0:c!==null&&typeof c=="object"&&c.constructor.wordSize===s.wordSize&&Array.isArray(c.words)},s.max=function(c,d){return c.cmp(d)>0?c:d},s.min=function(c,d){return c.cmp(d)<0?c:d},s.prototype._init=function(c,d,h){if(typeof c=="number")return this._initNumber(c,d,h);if(typeof c=="object")return this._initArray(c,d,h);d==="hex"&&(d=16),t(d===(d|0)&&d>=2&&d<=36),c=c.toString().replace(/\s+/g,"");var v=0;c[0]==="-"&&(v++,this.negative=1),v<c.length&&(d===16?this._parseHex(c,v,h):(this._parseBase(c,d,v),h==="le"&&this._initArray(this.toArray(),d,h)))},s.prototype._initNumber=function(c,d,h){c<0&&(this.negative=1,c=-c),c<67108864?(this.words=[c&67108863],this.length=1):c<4503599627370496?(this.words=[c&67108863,c/67108864&67108863],this.length=2):(t(c<9007199254740992),this.words=[c&67108863,c/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),d,h)},s.prototype._initArray=function(c,d,h){if(t(typeof c.length=="number"),c.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(c.length/3),this.words=new Array(this.length);for(var v=0;v<this.length;v++)this.words[v]=0;var y,w,S=0;if(h==="be")for(v=c.length-1,y=0;v>=0;v-=3)w=c[v]|c[v-1]<<8|c[v-2]<<16,this.words[y]|=w<<S&67108863,this.words[y+1]=w>>>26-S&67108863,S+=24,S>=26&&(S-=26,y++);else if(h==="le")for(v=0,y=0;v<c.length;v+=3)w=c[v]|c[v+1]<<8|c[v+2]<<16,this.words[y]|=w<<S&67108863,this.words[y+1]=w>>>26-S&67108863,S+=24,S>=26&&(S-=26,y++);return this.strip()};function o(b,c){var d=b.charCodeAt(c);return d>=65&&d<=70?d-55:d>=97&&d<=102?d-87:d-48&15}function a(b,c,d){var h=o(b,d);return d-1>=c&&(h|=o(b,d-1)<<4),h}s.prototype._parseHex=function(c,d,h){this.length=Math.ceil((c.length-d)/6),this.words=new Array(this.length);for(var v=0;v<this.length;v++)this.words[v]=0;var y=0,w=0,S;if(h==="be")for(v=c.length-1;v>=d;v-=2)S=a(c,d,v)<<y,this.words[w]|=S&67108863,y>=18?(y-=18,w+=1,this.words[w]|=S>>>26):y+=8;else{var g=c.length-d;for(v=g%2===0?d+1:d;v<c.length;v+=2)S=a(c,d,v)<<y,this.words[w]|=S&67108863,y>=18?(y-=18,w+=1,this.words[w]|=S>>>26):y+=8}this.strip()};function l(b,c,d,h){for(var v=0,y=Math.min(b.length,d),w=c;w<y;w++){var S=b.charCodeAt(w)-48;v*=h,S>=49?v+=S-49+10:S>=17?v+=S-17+10:v+=S}return v}s.prototype._parseBase=function(c,d,h){this.words=[0],this.length=1;for(var v=0,y=1;y<=67108863;y*=d)v++;v--,y=y/d|0;for(var w=c.length-h,S=w%v,g=Math.min(w,w-S)+h,u=0,x=h;x<g;x+=v)u=l(c,x,x+v,d),this.imuln(y),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(S!==0){var P=1;for(u=l(c,x,c.length,d),x=0;x<S;x++)P*=d;this.imuln(P),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this.strip()},s.prototype.copy=function(c){c.words=new Array(this.length);for(var d=0;d<this.length;d++)c.words[d]=this.words[d];c.length=this.length,c.negative=this.negative,c.red=this.red},s.prototype.clone=function(){var c=new s(null);return this.copy(c),c},s.prototype._expand=function(c){for(;this.length<c;)this.words[this.length++]=0;return this},s.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},s.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},s.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var p=["","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"],f=[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],m=[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];s.prototype.toString=function(c,d){c=c||10,d=d|0||1;var h;if(c===16||c==="hex"){h="";for(var v=0,y=0,w=0;w<this.length;w++){var S=this.words[w],g=((S<<v|y)&16777215).toString(16);y=S>>>24-v&16777215,v+=2,v>=26&&(v-=26,w--),y!==0||w!==this.length-1?h=p[6-g.length]+g+h:h=g+h}for(y!==0&&(h=y.toString(16)+h);h.length%d!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(c===(c|0)&&c>=2&&c<=36){var u=f[c],x=m[c];h="";var P=this.clone();for(P.negative=0;!P.isZero();){var B=P.modn(x).toString(c);P=P.idivn(x),P.isZero()?h=B+h:h=p[u-B.length]+B+h}for(this.isZero()&&(h="0"+h);h.length%d!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}t(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var c=this.words[0];return this.length===2?c+=this.words[1]*67108864:this.length===3&&this.words[2]===1?c+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-c:c},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(c,d){return t(typeof r<"u"),this.toArrayLike(r,c,d)},s.prototype.toArray=function(c,d){return this.toArrayLike(Array,c,d)},s.prototype.toArrayLike=function(c,d,h){var v=this.byteLength(),y=h||Math.max(1,v);t(v<=y,"byte array longer than desired length"),t(y>0,"Requested array length <= 0"),this.strip();var w=d==="le",S=new c(y),g,u,x=this.clone();if(w){for(u=0;!x.isZero();u++)g=x.andln(255),x.iushrn(8),S[u]=g;for(;u<y;u++)S[u]=0}else{for(u=0;u<y-v;u++)S[u]=0;for(u=0;!x.isZero();u++)g=x.andln(255),x.iushrn(8),S[y-u-1]=g}return S},Math.clz32?s.prototype._countBits=function(c){return 32-Math.clz32(c)}:s.prototype._countBits=function(c){var d=c,h=0;return d>=4096&&(h+=13,d>>>=13),d>=64&&(h+=7,d>>>=7),d>=8&&(h+=4,d>>>=4),d>=2&&(h+=2,d>>>=2),h+d},s.prototype._zeroBits=function(c){if(c===0)return 26;var d=c,h=0;return(d&8191)===0&&(h+=13,d>>>=13),(d&127)===0&&(h+=7,d>>>=7),(d&15)===0&&(h+=4,d>>>=4),(d&3)===0&&(h+=2,d>>>=2),(d&1)===0&&h++,h},s.prototype.bitLength=function(){var c=this.words[this.length-1],d=this._countBits(c);return(this.length-1)*26+d};function _(b){for(var c=new Array(b.bitLength()),d=0;d<c.length;d++){var h=d/26|0,v=d%26;c[d]=(b.words[h]&1<<v)>>>v}return c}s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var c=0,d=0;d<this.length;d++){var h=this._zeroBits(this.words[d]);if(c+=h,h!==26)break}return c},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(c){return this.negative!==0?this.abs().inotn(c).iaddn(1):this.clone()},s.prototype.fromTwos=function(c){return this.testn(c-1)?this.notn(c).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return this.negative!==0},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(c){for(;this.length<c.length;)this.words[this.length++]=0;for(var d=0;d<c.length;d++)this.words[d]=this.words[d]|c.words[d];return this.strip()},s.prototype.ior=function(c){return t((this.negative|c.negative)===0),this.iuor(c)},s.prototype.or=function(c){return this.length>c.length?this.clone().ior(c):c.clone().ior(this)},s.prototype.uor=function(c){return this.length>c.length?this.clone().iuor(c):c.clone().iuor(this)},s.prototype.iuand=function(c){var d;this.length>c.length?d=c:d=this;for(var h=0;h<d.length;h++)this.words[h]=this.words[h]&c.words[h];return this.length=d.length,this.strip()},s.prototype.iand=function(c){return t((this.negative|c.negative)===0),this.iuand(c)},s.prototype.and=function(c){return this.length>c.length?this.clone().iand(c):c.clone().iand(this)},s.prototype.uand=function(c){return this.length>c.length?this.clone().iuand(c):c.clone().iuand(this)},s.prototype.iuxor=function(c){var d,h;this.length>c.length?(d=this,h=c):(d=c,h=this);for(var v=0;v<h.length;v++)this.words[v]=d.words[v]^h.words[v];if(this!==d)for(;v<d.length;v++)this.words[v]=d.words[v];return this.length=d.length,this.strip()},s.prototype.ixor=function(c){return t((this.negative|c.negative)===0),this.iuxor(c)},s.prototype.xor=function(c){return this.length>c.length?this.clone().ixor(c):c.clone().ixor(this)},s.prototype.uxor=function(c){return this.length>c.length?this.clone().iuxor(c):c.clone().iuxor(this)},s.prototype.inotn=function(c){t(typeof c=="number"&&c>=0);var d=Math.ceil(c/26)|0,h=c%26;this._expand(d),h>0&&d--;for(var v=0;v<d;v++)this.words[v]=~this.words[v]&67108863;return h>0&&(this.words[v]=~this.words[v]&67108863>>26-h),this.strip()},s.prototype.notn=function(c){return this.clone().inotn(c)},s.prototype.setn=function(c,d){t(typeof c=="number"&&c>=0);var h=c/26|0,v=c%26;return this._expand(h+1),d?this.words[h]=this.words[h]|1<<v:this.words[h]=this.words[h]&~(1<<v),this.strip()},s.prototype.iadd=function(c){var d;if(this.negative!==0&&c.negative===0)return this.negative=0,d=this.isub(c),this.negative^=1,this._normSign();if(this.negative===0&&c.negative!==0)return c.negative=0,d=this.isub(c),c.negative=1,d._normSign();var h,v;this.length>c.length?(h=this,v=c):(h=c,v=this);for(var y=0,w=0;w<v.length;w++)d=(h.words[w]|0)+(v.words[w]|0)+y,this.words[w]=d&67108863,y=d>>>26;for(;y!==0&&w<h.length;w++)d=(h.words[w]|0)+y,this.words[w]=d&67108863,y=d>>>26;if(this.length=h.length,y!==0)this.words[this.length]=y,this.length++;else if(h!==this)for(;w<h.length;w++)this.words[w]=h.words[w];return this},s.prototype.add=function(c){var d;return c.negative!==0&&this.negative===0?(c.negative=0,d=this.sub(c),c.negative^=1,d):c.negative===0&&this.negative!==0?(this.negative=0,d=c.sub(this),this.negative=1,d):this.length>c.length?this.clone().iadd(c):c.clone().iadd(this)},s.prototype.isub=function(c){if(c.negative!==0){c.negative=0;var d=this.iadd(c);return c.negative=1,d._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(c),this.negative=1,this._normSign();var h=this.cmp(c);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var v,y;h>0?(v=this,y=c):(v=c,y=this);for(var w=0,S=0;S<y.length;S++)d=(v.words[S]|0)-(y.words[S]|0)+w,w=d>>26,this.words[S]=d&67108863;for(;w!==0&&S<v.length;S++)d=(v.words[S]|0)+w,w=d>>26,this.words[S]=d&67108863;if(w===0&&S<v.length&&v!==this)for(;S<v.length;S++)this.words[S]=v.words[S];return this.length=Math.max(this.length,S),v!==this&&(this.negative=1),this.strip()},s.prototype.sub=function(c){return this.clone().isub(c)};function E(b,c,d){d.negative=c.negative^b.negative;var h=b.length+c.length|0;d.length=h,h=h-1|0;var v=b.words[0]|0,y=c.words[0]|0,w=v*y,S=w&67108863,g=w/67108864|0;d.words[0]=S;for(var u=1;u<h;u++){for(var x=g>>>26,P=g&67108863,B=Math.min(u,c.length-1),j=Math.max(0,u-b.length+1);j<=B;j++){var D=u-j|0;v=b.words[D]|0,y=c.words[j]|0,w=v*y+P,x+=w/67108864|0,P=w&67108863}d.words[u]=P|0,g=x|0}return g!==0?d.words[u]=g|0:d.length--,d.strip()}var k=function(c,d,h){var v=c.words,y=d.words,w=h.words,S=0,g,u,x,P=v[0]|0,B=P&8191,j=P>>>13,D=v[1]|0,$=D&8191,Y=D>>>13,ri=v[2]|0,J=ri&8191,Z=ri>>>13,gu=v[3]|0,ae=gu&8191,ce=gu>>>13,xu=v[4]|0,le=xu&8191,ue=xu>>>13,yu=v[5]|0,pe=yu&8191,de=yu>>>13,bu=v[6]|0,fe=bu&8191,he=bu>>>13,wu=v[7]|0,me=wu&8191,ve=wu>>>13,_u=v[8]|0,ge=_u&8191,xe=_u>>>13,Su=v[9]|0,ye=Su&8191,be=Su>>>13,Eu=y[0]|0,we=Eu&8191,_e=Eu>>>13,ku=y[1]|0,Se=ku&8191,Ee=ku>>>13,Cu=y[2]|0,ke=Cu&8191,Ce=Cu>>>13,Tu=y[3]|0,Te=Tu&8191,Me=Tu>>>13,Mu=y[4]|0,Oe=Mu&8191,Ae=Mu>>>13,Ou=y[5]|0,Re=Ou&8191,Pe=Ou>>>13,Au=y[6]|0,Be=Au&8191,je=Au>>>13,Ru=y[7]|0,Ne=Ru&8191,Ie=Ru>>>13,Pu=y[8]|0,De=Pu&8191,qe=Pu>>>13,Bu=y[9]|0,Le=Bu&8191,Fe=Bu>>>13;h.negative=c.negative^d.negative,h.length=19,g=Math.imul(B,we),u=Math.imul(B,_e),u=u+Math.imul(j,we)|0,x=Math.imul(j,_e);var Bo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Bo>>>26)|0,Bo&=67108863,g=Math.imul($,we),u=Math.imul($,_e),u=u+Math.imul(Y,we)|0,x=Math.imul(Y,_e),g=g+Math.imul(B,Se)|0,u=u+Math.imul(B,Ee)|0,u=u+Math.imul(j,Se)|0,x=x+Math.imul(j,Ee)|0;var jo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(jo>>>26)|0,jo&=67108863,g=Math.imul(J,we),u=Math.imul(J,_e),u=u+Math.imul(Z,we)|0,x=Math.imul(Z,_e),g=g+Math.imul($,Se)|0,u=u+Math.imul($,Ee)|0,u=u+Math.imul(Y,Se)|0,x=x+Math.imul(Y,Ee)|0,g=g+Math.imul(B,ke)|0,u=u+Math.imul(B,Ce)|0,u=u+Math.imul(j,ke)|0,x=x+Math.imul(j,Ce)|0;var No=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(No>>>26)|0,No&=67108863,g=Math.imul(ae,we),u=Math.imul(ae,_e),u=u+Math.imul(ce,we)|0,x=Math.imul(ce,_e),g=g+Math.imul(J,Se)|0,u=u+Math.imul(J,Ee)|0,u=u+Math.imul(Z,Se)|0,x=x+Math.imul(Z,Ee)|0,g=g+Math.imul($,ke)|0,u=u+Math.imul($,Ce)|0,u=u+Math.imul(Y,ke)|0,x=x+Math.imul(Y,Ce)|0,g=g+Math.imul(B,Te)|0,u=u+Math.imul(B,Me)|0,u=u+Math.imul(j,Te)|0,x=x+Math.imul(j,Me)|0;var Io=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Io>>>26)|0,Io&=67108863,g=Math.imul(le,we),u=Math.imul(le,_e),u=u+Math.imul(ue,we)|0,x=Math.imul(ue,_e),g=g+Math.imul(ae,Se)|0,u=u+Math.imul(ae,Ee)|0,u=u+Math.imul(ce,Se)|0,x=x+Math.imul(ce,Ee)|0,g=g+Math.imul(J,ke)|0,u=u+Math.imul(J,Ce)|0,u=u+Math.imul(Z,ke)|0,x=x+Math.imul(Z,Ce)|0,g=g+Math.imul($,Te)|0,u=u+Math.imul($,Me)|0,u=u+Math.imul(Y,Te)|0,x=x+Math.imul(Y,Me)|0,g=g+Math.imul(B,Oe)|0,u=u+Math.imul(B,Ae)|0,u=u+Math.imul(j,Oe)|0,x=x+Math.imul(j,Ae)|0;var Do=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Do>>>26)|0,Do&=67108863,g=Math.imul(pe,we),u=Math.imul(pe,_e),u=u+Math.imul(de,we)|0,x=Math.imul(de,_e),g=g+Math.imul(le,Se)|0,u=u+Math.imul(le,Ee)|0,u=u+Math.imul(ue,Se)|0,x=x+Math.imul(ue,Ee)|0,g=g+Math.imul(ae,ke)|0,u=u+Math.imul(ae,Ce)|0,u=u+Math.imul(ce,ke)|0,x=x+Math.imul(ce,Ce)|0,g=g+Math.imul(J,Te)|0,u=u+Math.imul(J,Me)|0,u=u+Math.imul(Z,Te)|0,x=x+Math.imul(Z,Me)|0,g=g+Math.imul($,Oe)|0,u=u+Math.imul($,Ae)|0,u=u+Math.imul(Y,Oe)|0,x=x+Math.imul(Y,Ae)|0,g=g+Math.imul(B,Re)|0,u=u+Math.imul(B,Pe)|0,u=u+Math.imul(j,Re)|0,x=x+Math.imul(j,Pe)|0;var qo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(qo>>>26)|0,qo&=67108863,g=Math.imul(fe,we),u=Math.imul(fe,_e),u=u+Math.imul(he,we)|0,x=Math.imul(he,_e),g=g+Math.imul(pe,Se)|0,u=u+Math.imul(pe,Ee)|0,u=u+Math.imul(de,Se)|0,x=x+Math.imul(de,Ee)|0,g=g+Math.imul(le,ke)|0,u=u+Math.imul(le,Ce)|0,u=u+Math.imul(ue,ke)|0,x=x+Math.imul(ue,Ce)|0,g=g+Math.imul(ae,Te)|0,u=u+Math.imul(ae,Me)|0,u=u+Math.imul(ce,Te)|0,x=x+Math.imul(ce,Me)|0,g=g+Math.imul(J,Oe)|0,u=u+Math.imul(J,Ae)|0,u=u+Math.imul(Z,Oe)|0,x=x+Math.imul(Z,Ae)|0,g=g+Math.imul($,Re)|0,u=u+Math.imul($,Pe)|0,u=u+Math.imul(Y,Re)|0,x=x+Math.imul(Y,Pe)|0,g=g+Math.imul(B,Be)|0,u=u+Math.imul(B,je)|0,u=u+Math.imul(j,Be)|0,x=x+Math.imul(j,je)|0;var Lo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Lo>>>26)|0,Lo&=67108863,g=Math.imul(me,we),u=Math.imul(me,_e),u=u+Math.imul(ve,we)|0,x=Math.imul(ve,_e),g=g+Math.imul(fe,Se)|0,u=u+Math.imul(fe,Ee)|0,u=u+Math.imul(he,Se)|0,x=x+Math.imul(he,Ee)|0,g=g+Math.imul(pe,ke)|0,u=u+Math.imul(pe,Ce)|0,u=u+Math.imul(de,ke)|0,x=x+Math.imul(de,Ce)|0,g=g+Math.imul(le,Te)|0,u=u+Math.imul(le,Me)|0,u=u+Math.imul(ue,Te)|0,x=x+Math.imul(ue,Me)|0,g=g+Math.imul(ae,Oe)|0,u=u+Math.imul(ae,Ae)|0,u=u+Math.imul(ce,Oe)|0,x=x+Math.imul(ce,Ae)|0,g=g+Math.imul(J,Re)|0,u=u+Math.imul(J,Pe)|0,u=u+Math.imul(Z,Re)|0,x=x+Math.imul(Z,Pe)|0,g=g+Math.imul($,Be)|0,u=u+Math.imul($,je)|0,u=u+Math.imul(Y,Be)|0,x=x+Math.imul(Y,je)|0,g=g+Math.imul(B,Ne)|0,u=u+Math.imul(B,Ie)|0,u=u+Math.imul(j,Ne)|0,x=x+Math.imul(j,Ie)|0;var Fo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Fo>>>26)|0,Fo&=67108863,g=Math.imul(ge,we),u=Math.imul(ge,_e),u=u+Math.imul(xe,we)|0,x=Math.imul(xe,_e),g=g+Math.imul(me,Se)|0,u=u+Math.imul(me,Ee)|0,u=u+Math.imul(ve,Se)|0,x=x+Math.imul(ve,Ee)|0,g=g+Math.imul(fe,ke)|0,u=u+Math.imul(fe,Ce)|0,u=u+Math.imul(he,ke)|0,x=x+Math.imul(he,Ce)|0,g=g+Math.imul(pe,Te)|0,u=u+Math.imul(pe,Me)|0,u=u+Math.imul(de,Te)|0,x=x+Math.imul(de,Me)|0,g=g+Math.imul(le,Oe)|0,u=u+Math.imul(le,Ae)|0,u=u+Math.imul(ue,Oe)|0,x=x+Math.imul(ue,Ae)|0,g=g+Math.imul(ae,Re)|0,u=u+Math.imul(ae,Pe)|0,u=u+Math.imul(ce,Re)|0,x=x+Math.imul(ce,Pe)|0,g=g+Math.imul(J,Be)|0,u=u+Math.imul(J,je)|0,u=u+Math.imul(Z,Be)|0,x=x+Math.imul(Z,je)|0,g=g+Math.imul($,Ne)|0,u=u+Math.imul($,Ie)|0,u=u+Math.imul(Y,Ne)|0,x=x+Math.imul(Y,Ie)|0,g=g+Math.imul(B,De)|0,u=u+Math.imul(B,qe)|0,u=u+Math.imul(j,De)|0,x=x+Math.imul(j,qe)|0;var Uo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Uo>>>26)|0,Uo&=67108863,g=Math.imul(ye,we),u=Math.imul(ye,_e),u=u+Math.imul(be,we)|0,x=Math.imul(be,_e),g=g+Math.imul(ge,Se)|0,u=u+Math.imul(ge,Ee)|0,u=u+Math.imul(xe,Se)|0,x=x+Math.imul(xe,Ee)|0,g=g+Math.imul(me,ke)|0,u=u+Math.imul(me,Ce)|0,u=u+Math.imul(ve,ke)|0,x=x+Math.imul(ve,Ce)|0,g=g+Math.imul(fe,Te)|0,u=u+Math.imul(fe,Me)|0,u=u+Math.imul(he,Te)|0,x=x+Math.imul(he,Me)|0,g=g+Math.imul(pe,Oe)|0,u=u+Math.imul(pe,Ae)|0,u=u+Math.imul(de,Oe)|0,x=x+Math.imul(de,Ae)|0,g=g+Math.imul(le,Re)|0,u=u+Math.imul(le,Pe)|0,u=u+Math.imul(ue,Re)|0,x=x+Math.imul(ue,Pe)|0,g=g+Math.imul(ae,Be)|0,u=u+Math.imul(ae,je)|0,u=u+Math.imul(ce,Be)|0,x=x+Math.imul(ce,je)|0,g=g+Math.imul(J,Ne)|0,u=u+Math.imul(J,Ie)|0,u=u+Math.imul(Z,Ne)|0,x=x+Math.imul(Z,Ie)|0,g=g+Math.imul($,De)|0,u=u+Math.imul($,qe)|0,u=u+Math.imul(Y,De)|0,x=x+Math.imul(Y,qe)|0,g=g+Math.imul(B,Le)|0,u=u+Math.imul(B,Fe)|0,u=u+Math.imul(j,Le)|0,x=x+Math.imul(j,Fe)|0;var Ho=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Ho>>>26)|0,Ho&=67108863,g=Math.imul(ye,Se),u=Math.imul(ye,Ee),u=u+Math.imul(be,Se)|0,x=Math.imul(be,Ee),g=g+Math.imul(ge,ke)|0,u=u+Math.imul(ge,Ce)|0,u=u+Math.imul(xe,ke)|0,x=x+Math.imul(xe,Ce)|0,g=g+Math.imul(me,Te)|0,u=u+Math.imul(me,Me)|0,u=u+Math.imul(ve,Te)|0,x=x+Math.imul(ve,Me)|0,g=g+Math.imul(fe,Oe)|0,u=u+Math.imul(fe,Ae)|0,u=u+Math.imul(he,Oe)|0,x=x+Math.imul(he,Ae)|0,g=g+Math.imul(pe,Re)|0,u=u+Math.imul(pe,Pe)|0,u=u+Math.imul(de,Re)|0,x=x+Math.imul(de,Pe)|0,g=g+Math.imul(le,Be)|0,u=u+Math.imul(le,je)|0,u=u+Math.imul(ue,Be)|0,x=x+Math.imul(ue,je)|0,g=g+Math.imul(ae,Ne)|0,u=u+Math.imul(ae,Ie)|0,u=u+Math.imul(ce,Ne)|0,x=x+Math.imul(ce,Ie)|0,g=g+Math.imul(J,De)|0,u=u+Math.imul(J,qe)|0,u=u+Math.imul(Z,De)|0,x=x+Math.imul(Z,qe)|0,g=g+Math.imul($,Le)|0,u=u+Math.imul($,Fe)|0,u=u+Math.imul(Y,Le)|0,x=x+Math.imul(Y,Fe)|0;var zo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(zo>>>26)|0,zo&=67108863,g=Math.imul(ye,ke),u=Math.imul(ye,Ce),u=u+Math.imul(be,ke)|0,x=Math.imul(be,Ce),g=g+Math.imul(ge,Te)|0,u=u+Math.imul(ge,Me)|0,u=u+Math.imul(xe,Te)|0,x=x+Math.imul(xe,Me)|0,g=g+Math.imul(me,Oe)|0,u=u+Math.imul(me,Ae)|0,u=u+Math.imul(ve,Oe)|0,x=x+Math.imul(ve,Ae)|0,g=g+Math.imul(fe,Re)|0,u=u+Math.imul(fe,Pe)|0,u=u+Math.imul(he,Re)|0,x=x+Math.imul(he,Pe)|0,g=g+Math.imul(pe,Be)|0,u=u+Math.imul(pe,je)|0,u=u+Math.imul(de,Be)|0,x=x+Math.imul(de,je)|0,g=g+Math.imul(le,Ne)|0,u=u+Math.imul(le,Ie)|0,u=u+Math.imul(ue,Ne)|0,x=x+Math.imul(ue,Ie)|0,g=g+Math.imul(ae,De)|0,u=u+Math.imul(ae,qe)|0,u=u+Math.imul(ce,De)|0,x=x+Math.imul(ce,qe)|0,g=g+Math.imul(J,Le)|0,u=u+Math.imul(J,Fe)|0,u=u+Math.imul(Z,Le)|0,x=x+Math.imul(Z,Fe)|0;var $o=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+($o>>>26)|0,$o&=67108863,g=Math.imul(ye,Te),u=Math.imul(ye,Me),u=u+Math.imul(be,Te)|0,x=Math.imul(be,Me),g=g+Math.imul(ge,Oe)|0,u=u+Math.imul(ge,Ae)|0,u=u+Math.imul(xe,Oe)|0,x=x+Math.imul(xe,Ae)|0,g=g+Math.imul(me,Re)|0,u=u+Math.imul(me,Pe)|0,u=u+Math.imul(ve,Re)|0,x=x+Math.imul(ve,Pe)|0,g=g+Math.imul(fe,Be)|0,u=u+Math.imul(fe,je)|0,u=u+Math.imul(he,Be)|0,x=x+Math.imul(he,je)|0,g=g+Math.imul(pe,Ne)|0,u=u+Math.imul(pe,Ie)|0,u=u+Math.imul(de,Ne)|0,x=x+Math.imul(de,Ie)|0,g=g+Math.imul(le,De)|0,u=u+Math.imul(le,qe)|0,u=u+Math.imul(ue,De)|0,x=x+Math.imul(ue,qe)|0,g=g+Math.imul(ae,Le)|0,u=u+Math.imul(ae,Fe)|0,u=u+Math.imul(ce,Le)|0,x=x+Math.imul(ce,Fe)|0;var Wo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Wo>>>26)|0,Wo&=67108863,g=Math.imul(ye,Oe),u=Math.imul(ye,Ae),u=u+Math.imul(be,Oe)|0,x=Math.imul(be,Ae),g=g+Math.imul(ge,Re)|0,u=u+Math.imul(ge,Pe)|0,u=u+Math.imul(xe,Re)|0,x=x+Math.imul(xe,Pe)|0,g=g+Math.imul(me,Be)|0,u=u+Math.imul(me,je)|0,u=u+Math.imul(ve,Be)|0,x=x+Math.imul(ve,je)|0,g=g+Math.imul(fe,Ne)|0,u=u+Math.imul(fe,Ie)|0,u=u+Math.imul(he,Ne)|0,x=x+Math.imul(he,Ie)|0,g=g+Math.imul(pe,De)|0,u=u+Math.imul(pe,qe)|0,u=u+Math.imul(de,De)|0,x=x+Math.imul(de,qe)|0,g=g+Math.imul(le,Le)|0,u=u+Math.imul(le,Fe)|0,u=u+Math.imul(ue,Le)|0,x=x+Math.imul(ue,Fe)|0;var Vo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Vo>>>26)|0,Vo&=67108863,g=Math.imul(ye,Re),u=Math.imul(ye,Pe),u=u+Math.imul(be,Re)|0,x=Math.imul(be,Pe),g=g+Math.imul(ge,Be)|0,u=u+Math.imul(ge,je)|0,u=u+Math.imul(xe,Be)|0,x=x+Math.imul(xe,je)|0,g=g+Math.imul(me,Ne)|0,u=u+Math.imul(me,Ie)|0,u=u+Math.imul(ve,Ne)|0,x=x+Math.imul(ve,Ie)|0,g=g+Math.imul(fe,De)|0,u=u+Math.imul(fe,qe)|0,u=u+Math.imul(he,De)|0,x=x+Math.imul(he,qe)|0,g=g+Math.imul(pe,Le)|0,u=u+Math.imul(pe,Fe)|0,u=u+Math.imul(de,Le)|0,x=x+Math.imul(de,Fe)|0;var Ko=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Ko>>>26)|0,Ko&=67108863,g=Math.imul(ye,Be),u=Math.imul(ye,je),u=u+Math.imul(be,Be)|0,x=Math.imul(be,je),g=g+Math.imul(ge,Ne)|0,u=u+Math.imul(ge,Ie)|0,u=u+Math.imul(xe,Ne)|0,x=x+Math.imul(xe,Ie)|0,g=g+Math.imul(me,De)|0,u=u+Math.imul(me,qe)|0,u=u+Math.imul(ve,De)|0,x=x+Math.imul(ve,qe)|0,g=g+Math.imul(fe,Le)|0,u=u+Math.imul(fe,Fe)|0,u=u+Math.imul(he,Le)|0,x=x+Math.imul(he,Fe)|0;var Go=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Go>>>26)|0,Go&=67108863,g=Math.imul(ye,Ne),u=Math.imul(ye,Ie),u=u+Math.imul(be,Ne)|0,x=Math.imul(be,Ie),g=g+Math.imul(ge,De)|0,u=u+Math.imul(ge,qe)|0,u=u+Math.imul(xe,De)|0,x=x+Math.imul(xe,qe)|0,g=g+Math.imul(me,Le)|0,u=u+Math.imul(me,Fe)|0,u=u+Math.imul(ve,Le)|0,x=x+Math.imul(ve,Fe)|0;var Yo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Yo>>>26)|0,Yo&=67108863,g=Math.imul(ye,De),u=Math.imul(ye,qe),u=u+Math.imul(be,De)|0,x=Math.imul(be,qe),g=g+Math.imul(ge,Le)|0,u=u+Math.imul(ge,Fe)|0,u=u+Math.imul(xe,Le)|0,x=x+Math.imul(xe,Fe)|0;var Jo=(S+g|0)+((u&8191)<<13)|0;S=(x+(u>>>13)|0)+(Jo>>>26)|0,Jo&=67108863,g=Math.imul(ye,Le),u=Math.imul(ye,Fe),u=u+Math.imul(be,Le)|0,x=Math.imul(be,Fe);var Xo=(S+g|0)+((u&8191)<<13)|0;return S=(x+(u>>>13)|0)+(Xo>>>26)|0,Xo&=67108863,w[0]=Bo,w[1]=jo,w[2]=No,w[3]=Io,w[4]=Do,w[5]=qo,w[6]=Lo,w[7]=Fo,w[8]=Uo,w[9]=Ho,w[10]=zo,w[11]=$o,w[12]=Wo,w[13]=Vo,w[14]=Ko,w[15]=Go,w[16]=Yo,w[17]=Jo,w[18]=Xo,S!==0&&(w[19]=S,h.length++),h};Math.imul||(k=E);function T(b,c,d){d.negative=c.negative^b.negative,d.length=b.length+c.length;for(var h=0,v=0,y=0;y<d.length-1;y++){var w=v;v=0;for(var S=h&67108863,g=Math.min(y,c.length-1),u=Math.max(0,y-b.length+1);u<=g;u++){var x=y-u,P=b.words[x]|0,B=c.words[u]|0,j=P*B,D=j&67108863;w=w+(j/67108864|0)|0,D=D+S|0,S=D&67108863,w=w+(D>>>26)|0,v+=w>>>26,w&=67108863}d.words[y]=S,h=w,w=v}return h!==0?d.words[y]=h:d.length--,d.strip()}function M(b,c,d){var h=new O;return h.mulp(b,c,d)}s.prototype.mulTo=function(c,d){var h,v=this.length+c.length;return this.length===10&&c.length===10?h=k(this,c,d):v<63?h=E(this,c,d):v<1024?h=T(this,c,d):h=M(this,c,d),h};function O(b,c){this.x=b,this.y=c}O.prototype.makeRBT=function(c){for(var d=new Array(c),h=s.prototype._countBits(c)-1,v=0;v<c;v++)d[v]=this.revBin(v,h,c);return d},O.prototype.revBin=function(c,d,h){if(c===0||c===h-1)return c;for(var v=0,y=0;y<d;y++)v|=(c&1)<<d-y-1,c>>=1;return v},O.prototype.permute=function(c,d,h,v,y,w){for(var S=0;S<w;S++)v[S]=d[c[S]],y[S]=h[c[S]]},O.prototype.transform=function(c,d,h,v,y,w){this.permute(w,c,d,h,v,y);for(var S=1;S<y;S<<=1)for(var g=S<<1,u=Math.cos(2*Math.PI/g),x=Math.sin(2*Math.PI/g),P=0;P<y;P+=g)for(var B=u,j=x,D=0;D<S;D++){var $=h[P+D],Y=v[P+D],ri=h[P+D+S],J=v[P+D+S],Z=B*ri-j*J;J=B*J+j*ri,ri=Z,h[P+D]=$+ri,v[P+D]=Y+J,h[P+D+S]=$-ri,v[P+D+S]=Y-J,D!==g&&(Z=u*B-x*j,j=u*j+x*B,B=Z)}},O.prototype.guessLen13b=function(c,d){var h=Math.max(d,c)|1,v=h&1,y=0;for(h=h/2|0;h;h=h>>>1)y++;return 1<<y+1+v},O.prototype.conjugate=function(c,d,h){if(!(h<=1))for(var v=0;v<h/2;v++){var y=c[v];c[v]=c[h-v-1],c[h-v-1]=y,y=d[v],d[v]=-d[h-v-1],d[h-v-1]=-y}},O.prototype.normalize13b=function(c,d){for(var h=0,v=0;v<d/2;v++){var y=Math.round(c[2*v+1]/d)*8192+Math.round(c[2*v]/d)+h;c[v]=y&67108863,y<67108864?h=0:h=y/67108864|0}return c},O.prototype.convert13b=function(c,d,h,v){for(var y=0,w=0;w<d;w++)y=y+(c[w]|0),h[2*w]=y&8191,y=y>>>13,h[2*w+1]=y&8191,y=y>>>13;for(w=2*d;w<v;++w)h[w]=0;t(y===0),t((y&-8192)===0)},O.prototype.stub=function(c){for(var d=new Array(c),h=0;h<c;h++)d[h]=0;return d},O.prototype.mulp=function(c,d,h){var v=2*this.guessLen13b(c.length,d.length),y=this.makeRBT(v),w=this.stub(v),S=new Array(v),g=new Array(v),u=new Array(v),x=new Array(v),P=new Array(v),B=new Array(v),j=h.words;j.length=v,this.convert13b(c.words,c.length,S,v),this.convert13b(d.words,d.length,x,v),this.transform(S,w,g,u,v,y),this.transform(x,w,P,B,v,y);for(var D=0;D<v;D++){var $=g[D]*P[D]-u[D]*B[D];u[D]=g[D]*B[D]+u[D]*P[D],g[D]=$}return this.conjugate(g,u,v),this.transform(g,u,j,w,v,y),this.conjugate(j,w,v),this.normalize13b(j,v),h.negative=c.negative^d.negative,h.length=c.length+d.length,h.strip()},s.prototype.mul=function(c){var d=new s(null);return d.words=new Array(this.length+c.length),this.mulTo(c,d)},s.prototype.mulf=function(c){var d=new s(null);return d.words=new Array(this.length+c.length),M(this,c,d)},s.prototype.imul=function(c){return this.clone().mulTo(c,this)},s.prototype.imuln=function(c){t(typeof c=="number"),t(c<67108864);for(var d=0,h=0;h<this.length;h++){var v=(this.words[h]|0)*c,y=(v&67108863)+(d&67108863);d>>=26,d+=v/67108864|0,d+=y>>>26,this.words[h]=y&67108863}return d!==0&&(this.words[h]=d,this.length++),this.length=c===0?1:this.length,this},s.prototype.muln=function(c){return this.clone().imuln(c)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(c){var d=_(c);if(d.length===0)return new s(1);for(var h=this,v=0;v<d.length&&d[v]===0;v++,h=h.sqr());if(++v<d.length)for(var y=h.sqr();v<d.length;v++,y=y.sqr())d[v]!==0&&(h=h.mul(y));return h},s.prototype.iushln=function(c){t(typeof c=="number"&&c>=0);var d=c%26,h=(c-d)/26,v=67108863>>>26-d<<26-d,y;if(d!==0){var w=0;for(y=0;y<this.length;y++){var S=this.words[y]&v,g=(this.words[y]|0)-S<<d;this.words[y]=g|w,w=S>>>26-d}w&&(this.words[y]=w,this.length++)}if(h!==0){for(y=this.length-1;y>=0;y--)this.words[y+h]=this.words[y];for(y=0;y<h;y++)this.words[y]=0;this.length+=h}return this.strip()},s.prototype.ishln=function(c){return t(this.negative===0),this.iushln(c)},s.prototype.iushrn=function(c,d,h){t(typeof c=="number"&&c>=0);var v;d?v=(d-d%26)/26:v=0;var y=c%26,w=Math.min((c-y)/26,this.length),S=67108863^67108863>>>y<<y,g=h;if(v-=w,v=Math.max(0,v),g){for(var u=0;u<w;u++)g.words[u]=this.words[u];g.length=w}if(w!==0)if(this.length>w)for(this.length-=w,u=0;u<this.length;u++)this.words[u]=this.words[u+w];else this.words[0]=0,this.length=1;var x=0;for(u=this.length-1;u>=0&&(x!==0||u>=v);u--){var P=this.words[u]|0;this.words[u]=x<<26-y|P>>>y,x=P&S}return g&&x!==0&&(g.words[g.length++]=x),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},s.prototype.ishrn=function(c,d,h){return t(this.negative===0),this.iushrn(c,d,h)},s.prototype.shln=function(c){return this.clone().ishln(c)},s.prototype.ushln=function(c){return this.clone().iushln(c)},s.prototype.shrn=function(c){return this.clone().ishrn(c)},s.prototype.ushrn=function(c){return this.clone().iushrn(c)},s.prototype.testn=function(c){t(typeof c=="number"&&c>=0);var d=c%26,h=(c-d)/26,v=1<<d;if(this.length<=h)return!1;var y=this.words[h];return!!(y&v)},s.prototype.imaskn=function(c){t(typeof c=="number"&&c>=0);var d=c%26,h=(c-d)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(d!==0&&h++,this.length=Math.min(h,this.length),d!==0){var v=67108863^67108863>>>d<<d;this.words[this.length-1]&=v}return this.length===0&&(this.words[0]=0,this.length=1),this.strip()},s.prototype.maskn=function(c){return this.clone().imaskn(c)},s.prototype.iaddn=function(c){return t(typeof c=="number"),t(c<67108864),c<0?this.isubn(-c):this.negative!==0?this.length===1&&(this.words[0]|0)<c?(this.words[0]=c-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(c),this.negative=1,this):this._iaddn(c)},s.prototype._iaddn=function(c){this.words[0]+=c;for(var d=0;d<this.length&&this.words[d]>=67108864;d++)this.words[d]-=67108864,d===this.length-1?this.words[d+1]=1:this.words[d+1]++;return this.length=Math.max(this.length,d+1),this},s.prototype.isubn=function(c){if(t(typeof c=="number"),t(c<67108864),c<0)return this.iaddn(-c);if(this.negative!==0)return this.negative=0,this.iaddn(c),this.negative=1,this;if(this.words[0]-=c,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var d=0;d<this.length&&this.words[d]<0;d++)this.words[d]+=67108864,this.words[d+1]-=1;return this.strip()},s.prototype.addn=function(c){return this.clone().iaddn(c)},s.prototype.subn=function(c){return this.clone().isubn(c)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(c,d,h){var v=c.length+h,y;this._expand(v);var w,S=0;for(y=0;y<c.length;y++){w=(this.words[y+h]|0)+S;var g=(c.words[y]|0)*d;w-=g&67108863,S=(w>>26)-(g/67108864|0),this.words[y+h]=w&67108863}for(;y<this.length-h;y++)w=(this.words[y+h]|0)+S,S=w>>26,this.words[y+h]=w&67108863;if(S===0)return this.strip();for(t(S===-1),S=0,y=0;y<this.length;y++)w=-(this.words[y]|0)+S,S=w>>26,this.words[y]=w&67108863;return this.negative=1,this.strip()},s.prototype._wordDiv=function(c,d){var h=this.length-c.length,v=this.clone(),y=c,w=y.words[y.length-1]|0,S=this._countBits(w);h=26-S,h!==0&&(y=y.ushln(h),v.iushln(h),w=y.words[y.length-1]|0);var g=v.length-y.length,u;if(d!=="mod"){u=new s(null),u.length=g+1,u.words=new Array(u.length);for(var x=0;x<u.length;x++)u.words[x]=0}var P=v.clone()._ishlnsubmul(y,1,g);P.negative===0&&(v=P,u&&(u.words[g]=1));for(var B=g-1;B>=0;B--){var j=(v.words[y.length+B]|0)*67108864+(v.words[y.length+B-1]|0);for(j=Math.min(j/w|0,67108863),v._ishlnsubmul(y,j,B);v.negative!==0;)j--,v.negative=0,v._ishlnsubmul(y,1,B),v.isZero()||(v.negative^=1);u&&(u.words[B]=j)}return u&&u.strip(),v.strip(),d!=="div"&&h!==0&&v.iushrn(h),{div:u||null,mod:v}},s.prototype.divmod=function(c,d,h){if(t(!c.isZero()),this.isZero())return{div:new s(0),mod:new s(0)};var v,y,w;return this.negative!==0&&c.negative===0?(w=this.neg().divmod(c,d),d!=="mod"&&(v=w.div.neg()),d!=="div"&&(y=w.mod.neg(),h&&y.negative!==0&&y.iadd(c)),{div:v,mod:y}):this.negative===0&&c.negative!==0?(w=this.divmod(c.neg(),d),d!=="mod"&&(v=w.div.neg()),{div:v,mod:w.mod}):(this.negative&c.negative)!==0?(w=this.neg().divmod(c.neg(),d),d!=="div"&&(y=w.mod.neg(),h&&y.negative!==0&&y.isub(c)),{div:w.div,mod:y}):c.length>this.length||this.cmp(c)<0?{div:new s(0),mod:this}:c.length===1?d==="div"?{div:this.divn(c.words[0]),mod:null}:d==="mod"?{div:null,mod:new s(this.modn(c.words[0]))}:{div:this.divn(c.words[0]),mod:new s(this.modn(c.words[0]))}:this._wordDiv(c,d)},s.prototype.div=function(c){return this.divmod(c,"div",!1).div},s.prototype.mod=function(c){return this.divmod(c,"mod",!1).mod},s.prototype.umod=function(c){return this.divmod(c,"mod",!0).mod},s.prototype.divRound=function(c){var d=this.divmod(c);if(d.mod.isZero())return d.div;var h=d.div.negative!==0?d.mod.isub(c):d.mod,v=c.ushrn(1),y=c.andln(1),w=h.cmp(v);return w<0||y===1&&w===0?d.div:d.div.negative!==0?d.div.isubn(1):d.div.iaddn(1)},s.prototype.modn=function(c){t(c<=67108863);for(var d=(1<<26)%c,h=0,v=this.length-1;v>=0;v--)h=(d*h+(this.words[v]|0))%c;return h},s.prototype.idivn=function(c){t(c<=67108863);for(var d=0,h=this.length-1;h>=0;h--){var v=(this.words[h]|0)+d*67108864;this.words[h]=v/c|0,d=v%c}return this.strip()},s.prototype.divn=function(c){return this.clone().idivn(c)},s.prototype.egcd=function(c){t(c.negative===0),t(!c.isZero());var d=this,h=c.clone();d.negative!==0?d=d.umod(c):d=d.clone();for(var v=new s(1),y=new s(0),w=new s(0),S=new s(1),g=0;d.isEven()&&h.isEven();)d.iushrn(1),h.iushrn(1),++g;for(var u=h.clone(),x=d.clone();!d.isZero();){for(var P=0,B=1;(d.words[0]&B)===0&&P<26;++P,B<<=1);if(P>0)for(d.iushrn(P);P-- >0;)(v.isOdd()||y.isOdd())&&(v.iadd(u),y.isub(x)),v.iushrn(1),y.iushrn(1);for(var j=0,D=1;(h.words[0]&D)===0&&j<26;++j,D<<=1);if(j>0)for(h.iushrn(j);j-- >0;)(w.isOdd()||S.isOdd())&&(w.iadd(u),S.isub(x)),w.iushrn(1),S.iushrn(1);d.cmp(h)>=0?(d.isub(h),v.isub(w),y.isub(S)):(h.isub(d),w.isub(v),S.isub(y))}return{a:w,b:S,gcd:h.iushln(g)}},s.prototype._invmp=function(c){t(c.negative===0),t(!c.isZero());var d=this,h=c.clone();d.negative!==0?d=d.umod(c):d=d.clone();for(var v=new s(1),y=new s(0),w=h.clone();d.cmpn(1)>0&&h.cmpn(1)>0;){for(var S=0,g=1;(d.words[0]&g)===0&&S<26;++S,g<<=1);if(S>0)for(d.iushrn(S);S-- >0;)v.isOdd()&&v.iadd(w),v.iushrn(1);for(var u=0,x=1;(h.words[0]&x)===0&&u<26;++u,x<<=1);if(u>0)for(h.iushrn(u);u-- >0;)y.isOdd()&&y.iadd(w),y.iushrn(1);d.cmp(h)>=0?(d.isub(h),v.isub(y)):(h.isub(d),y.isub(v))}var P;return d.cmpn(1)===0?P=v:P=y,P.cmpn(0)<0&&P.iadd(c),P},s.prototype.gcd=function(c){if(this.isZero())return c.abs();if(c.isZero())return this.abs();var d=this.clone(),h=c.clone();d.negative=0,h.negative=0;for(var v=0;d.isEven()&&h.isEven();v++)d.iushrn(1),h.iushrn(1);do{for(;d.isEven();)d.iushrn(1);for(;h.isEven();)h.iushrn(1);var y=d.cmp(h);if(y<0){var w=d;d=h,h=w}else if(y===0||h.cmpn(1)===0)break;d.isub(h)}while(!0);return h.iushln(v)},s.prototype.invm=function(c){return this.egcd(c).a.umod(c)},s.prototype.isEven=function(){return(this.words[0]&1)===0},s.prototype.isOdd=function(){return(this.words[0]&1)===1},s.prototype.andln=function(c){return this.words[0]&c},s.prototype.bincn=function(c){t(typeof c=="number");var d=c%26,h=(c-d)/26,v=1<<d;if(this.length<=h)return this._expand(h+1),this.words[h]|=v,this;for(var y=v,w=h;y!==0&&w<this.length;w++){var S=this.words[w]|0;S+=y,y=S>>>26,S&=67108863,this.words[w]=S}return y!==0&&(this.words[w]=y,this.length++),this},s.prototype.isZero=function(){return this.length===1&&this.words[0]===0},s.prototype.cmpn=function(c){var d=c<0;if(this.negative!==0&&!d)return-1;if(this.negative===0&&d)return 1;this.strip();var h;if(this.length>1)h=1;else{d&&(c=-c),t(c<=67108863,"Number is too big");var v=this.words[0]|0;h=v===c?0:v<c?-1:1}return this.negative!==0?-h|0:h},s.prototype.cmp=function(c){if(this.negative!==0&&c.negative===0)return-1;if(this.negative===0&&c.negative!==0)return 1;var d=this.ucmp(c);return this.negative!==0?-d|0:d},s.prototype.ucmp=function(c){if(this.length>c.length)return 1;if(this.length<c.length)return-1;for(var d=0,h=this.length-1;h>=0;h--){var v=this.words[h]|0,y=c.words[h]|0;if(v!==y){v<y?d=-1:v>y&&(d=1);break}}return d},s.prototype.gtn=function(c){return this.cmpn(c)===1},s.prototype.gt=function(c){return this.cmp(c)===1},s.prototype.gten=function(c){return this.cmpn(c)>=0},s.prototype.gte=function(c){return this.cmp(c)>=0},s.prototype.ltn=function(c){return this.cmpn(c)===-1},s.prototype.lt=function(c){return this.cmp(c)===-1},s.prototype.lten=function(c){return this.cmpn(c)<=0},s.prototype.lte=function(c){return this.cmp(c)<=0},s.prototype.eqn=function(c){return this.cmpn(c)===0},s.prototype.eq=function(c){return this.cmp(c)===0},s.red=function(c){return new H(c)},s.prototype.toRed=function(c){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),c.convertTo(this)._forceRed(c)},s.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(c){return this.red=c,this},s.prototype.forceRed=function(c){return t(!this.red,"Already a number in reduction context"),this._forceRed(c)},s.prototype.redAdd=function(c){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,c)},s.prototype.redIAdd=function(c){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,c)},s.prototype.redSub=function(c){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,c)},s.prototype.redISub=function(c){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,c)},s.prototype.redShl=function(c){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,c)},s.prototype.redMul=function(c){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,c),this.red.mul(this,c)},s.prototype.redIMul=function(c){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,c),this.red.imul(this,c)},s.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(c){return t(this.red&&!c.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,c)};var A={k256:null,p224:null,p192:null,p25519:null};function I(b,c){this.name=b,this.p=new s(c,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}I.prototype._tmp=function(){var c=new s(null);return c.words=new Array(Math.ceil(this.n/13)),c},I.prototype.ireduce=function(c){var d=c,h;do this.split(d,this.tmp),d=this.imulK(d),d=d.iadd(this.tmp),h=d.bitLength();while(h>this.n);var v=h<this.n?-1:d.ucmp(this.p);return v===0?(d.words[0]=0,d.length=1):v>0?d.isub(this.p):d.strip!==void 0?d.strip():d._strip(),d},I.prototype.split=function(c,d){c.iushrn(this.n,0,d)},I.prototype.imulK=function(c){return c.imul(this.k)};function U(){I.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(U,I),U.prototype.split=function(c,d){for(var h=4194303,v=Math.min(c.length,9),y=0;y<v;y++)d.words[y]=c.words[y];if(d.length=v,c.length<=9){c.words[0]=0,c.length=1;return}var w=c.words[9];for(d.words[d.length++]=w&h,y=10;y<c.length;y++){var S=c.words[y]|0;c.words[y-10]=(S&h)<<4|w>>>22,w=S}w>>>=22,c.words[y-10]=w,w===0&&c.length>10?c.length-=10:c.length-=9},U.prototype.imulK=function(c){c.words[c.length]=0,c.words[c.length+1]=0,c.length+=2;for(var d=0,h=0;h<c.length;h++){var v=c.words[h]|0;d+=v*977,c.words[h]=d&67108863,d=v*64+(d/67108864|0)}return c.words[c.length-1]===0&&(c.length--,c.words[c.length-1]===0&&c.length--),c};function ee(){I.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(ee,I);function z(){I.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(z,I);function ne(){I.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(ne,I),ne.prototype.imulK=function(c){for(var d=0,h=0;h<c.length;h++){var v=(c.words[h]|0)*19+d,y=v&67108863;v>>>=26,c.words[h]=y,d=v}return d!==0&&(c.words[c.length++]=d),c},s._prime=function(c){if(A[c])return A[c];var d;if(c==="k256")d=new U;else if(c==="p224")d=new ee;else if(c==="p192")d=new z;else if(c==="p25519")d=new ne;else throw new Error("Unknown prime "+c);return A[c]=d,d};function H(b){if(typeof b=="string"){var c=s._prime(b);this.m=c.p,this.prime=c}else t(b.gtn(1),"modulus must be greater than 1"),this.m=b,this.prime=null}H.prototype._verify1=function(c){t(c.negative===0,"red works only with positives"),t(c.red,"red works only with red numbers")},H.prototype._verify2=function(c,d){t((c.negative|d.negative)===0,"red works only with positives"),t(c.red&&c.red===d.red,"red works only with red numbers")},H.prototype.imod=function(c){return this.prime?this.prime.ireduce(c)._forceRed(this):c.umod(this.m)._forceRed(this)},H.prototype.neg=function(c){return c.isZero()?c.clone():this.m.sub(c)._forceRed(this)},H.prototype.add=function(c,d){this._verify2(c,d);var h=c.add(d);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},H.prototype.iadd=function(c,d){this._verify2(c,d);var h=c.iadd(d);return h.cmp(this.m)>=0&&h.isub(this.m),h},H.prototype.sub=function(c,d){this._verify2(c,d);var h=c.sub(d);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},H.prototype.isub=function(c,d){this._verify2(c,d);var h=c.isub(d);return h.cmpn(0)<0&&h.iadd(this.m),h},H.prototype.shl=function(c,d){return this._verify1(c),this.imod(c.ushln(d))},H.prototype.imul=function(c,d){return this._verify2(c,d),this.imod(c.imul(d))},H.prototype.mul=function(c,d){return this._verify2(c,d),this.imod(c.mul(d))},H.prototype.isqr=function(c){return this.imul(c,c.clone())},H.prototype.sqr=function(c){return this.mul(c,c)},H.prototype.sqrt=function(c){if(c.isZero())return c.clone();var d=this.m.andln(3);if(t(d%2===1),d===3){var h=this.m.add(new s(1)).iushrn(2);return this.pow(c,h)}for(var v=this.m.subn(1),y=0;!v.isZero()&&v.andln(1)===0;)y++,v.iushrn(1);t(!v.isZero());var w=new s(1).toRed(this),S=w.redNeg(),g=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new s(2*u*u).toRed(this);this.pow(u,g).cmp(S)!==0;)u.redIAdd(S);for(var x=this.pow(u,v),P=this.pow(c,v.addn(1).iushrn(1)),B=this.pow(c,v),j=y;B.cmp(w)!==0;){for(var D=B,$=0;D.cmp(w)!==0;$++)D=D.redSqr();t($<j);var Y=this.pow(x,new s(1).iushln(j-$-1));P=P.redMul(Y),x=Y.redSqr(),B=B.redMul(x),j=$}return P},H.prototype.invm=function(c){var d=c._invmp(this.m);return d.negative!==0?(d.negative=0,this.imod(d).redNeg()):this.imod(d)},H.prototype.pow=function(c,d){if(d.isZero())return new s(1).toRed(this);if(d.cmpn(1)===0)return c.clone();var h=4,v=new Array(1<<h);v[0]=new s(1).toRed(this),v[1]=c;for(var y=2;y<v.length;y++)v[y]=this.mul(v[y-1],c);var w=v[0],S=0,g=0,u=d.bitLength()%26;for(u===0&&(u=26),y=d.length-1;y>=0;y--){for(var x=d.words[y],P=u-1;P>=0;P--){var B=x>>P&1;if(w!==v[0]&&(w=this.sqr(w)),B===0&&S===0){g=0;continue}S<<=1,S|=B,g++,!(g!==h&&(y!==0||P!==0))&&(w=this.mul(w,v[S]),g=0,S=0)}u=26}return w},H.prototype.convertTo=function(c){var d=c.umod(this.m);return d===c?d.clone():d},H.prototype.convertFrom=function(c){var d=c.clone();return d.red=null,d},s.mont=function(c){return new oe(c)};function oe(b){H.call(this,b),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new s(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)}n(oe,H),oe.prototype.convertTo=function(c){return this.imod(c.ushln(this.shift))},oe.prototype.convertFrom=function(c){var d=this.imod(c.mul(this.rinv));return d.red=null,d},oe.prototype.imul=function(c,d){if(c.isZero()||d.isZero())return c.words[0]=0,c.length=1,c;var h=c.imul(d),v=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=h.isub(v).iushrn(this.shift),w=y;return y.cmp(this.m)>=0?w=y.isub(this.m):y.cmpn(0)<0&&(w=y.iadd(this.m)),w._forceRed(this)},oe.prototype.mul=function(c,d){if(c.isZero()||d.isZero())return new s(0)._forceRed(this);var h=c.mul(d),v=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=h.isub(v).iushrn(this.shift),w=y;return y.cmp(this.m)>=0?w=y.isub(this.m):y.cmpn(0)<0&&(w=y.iadd(this.m)),w._forceRed(this)},oe.prototype.invm=function(c){var d=this.imod(c._invmp(this.m).mul(this.r2));return d._forceRed(this)}})(typeof cl>"u"||cl,qm)});var Lm=C((oM,ul)=>{typeof Object.create=="function"?ul.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:ul.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}});var vi=C((aM,dl)=>{try{if(pl=require("util"),typeof pl.inherits!="function")throw"";dl.exports=pl.inherits}catch{dl.exports=Lm()}var pl});var Jr=C((cM,Fm)=>{"use strict";var Yr=require("buffer"),kn=Yr.Buffer,_t={},St;for(St in Yr)Yr.hasOwnProperty(St)&&(St==="SlowBuffer"||St==="Buffer"||(_t[St]=Yr[St]));var Cn=_t.Buffer={};for(St in kn)kn.hasOwnProperty(St)&&(St==="allocUnsafe"||St==="allocUnsafeSlow"||(Cn[St]=kn[St]));_t.Buffer.prototype=kn.prototype;(!Cn.from||Cn.from===Uint8Array.from)&&(Cn.from=function(i,e,t){if(typeof i=="number")throw new TypeError('The "value" argument must not be of type number. Received type '+typeof i);if(i&&typeof i.length>"u")throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i);return kn(i,e,t)});Cn.alloc||(Cn.alloc=function(i,e,t){if(typeof i!="number")throw new TypeError('The "size" argument must be of type number. Received type '+typeof i);if(i<0||i>=2*(1<<30))throw new RangeError('The value "'+i+'" is invalid for option "size"');var n=kn(i);return!e||e.length===0?n.fill(0):typeof t=="string"?n.fill(e,t):n.fill(e),n});if(!_t.kStringMaxLength)try{_t.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}_t.constants||(_t.constants={MAX_LENGTH:_t.kMaxLength},_t.kStringMaxLength&&(_t.constants.MAX_STRING_LENGTH=_t.kStringMaxLength));Fm.exports=_t});var Xr=C(Um=>{"use strict";var rE=vi();function Et(i){this._reporterState={obj:null,path:[],options:i||{},errors:[]}}Um.Reporter=Et;Et.prototype.isError=function(e){return e instanceof Tn};Et.prototype.save=function(){let e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}};Et.prototype.restore=function(e){let t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)};Et.prototype.enterKey=function(e){return this._reporterState.path.push(e)};Et.prototype.exitKey=function(e){let t=this._reporterState;t.path=t.path.slice(0,e-1)};Et.prototype.leaveKey=function(e,t,n){let s=this._reporterState;this.exitKey(e),s.obj!==null&&(s.obj[t]=n)};Et.prototype.path=function(){return this._reporterState.path.join("/")};Et.prototype.enterObject=function(){let e=this._reporterState,t=e.obj;return e.obj={},t};Et.prototype.leaveObject=function(e){let t=this._reporterState,n=t.obj;return t.obj=e,n};Et.prototype.error=function(e){let t,n=this._reporterState,s=e instanceof Tn;if(s?t=e:t=new Tn(n.path.map(function(r){return"["+JSON.stringify(r)+"]"}).join(""),e.message||e,e.stack),!n.options.partial)throw t;return s||n.errors.push(t),t};Et.prototype.wrapResult=function(e){let t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e};function Tn(i,e){this.path=i,this.rethrow(e)}rE(Tn,Error);Tn.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,Tn),!this.stack)try{throw new Error(this.message)}catch(t){this.stack=t.stack}return this}});var An=C(fl=>{"use strict";var oE=vi(),Zr=Xr().Reporter,Mn=Jr().Buffer;function kt(i,e){if(Zr.call(this,e),!Mn.isBuffer(i)){this.error("Input not Buffer");return}this.base=i,this.offset=0,this.length=i.length}oE(kt,Zr);fl.DecoderBuffer=kt;kt.isDecoderBuffer=function(e){return e instanceof kt?!0:typeof e=="object"&&Mn.isBuffer(e.base)&&e.constructor.name==="DecoderBuffer"&&typeof e.offset=="number"&&typeof e.length=="number"&&typeof e.save=="function"&&typeof e.restore=="function"&&typeof e.isEmpty=="function"&&typeof e.readUInt8=="function"&&typeof e.skip=="function"&&typeof e.raw=="function"};kt.prototype.save=function(){return{offset:this.offset,reporter:Zr.prototype.save.call(this)}};kt.prototype.restore=function(e){let t=new kt(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,Zr.prototype.restore.call(this,e.reporter),t};kt.prototype.isEmpty=function(){return this.offset===this.length};kt.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")};kt.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");let n=new kt(this.base);return n._reporterState=this._reporterState,n.offset=this.offset,n.length=this.offset+e,this.offset+=e,n};kt.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)};function On(i,e){if(Array.isArray(i))this.length=0,this.value=i.map(function(t){return On.isEncoderBuffer(t)||(t=new On(t,e)),this.length+=t.length,t},this);else if(typeof i=="number"){if(!(0<=i&&i<=255))return e.error("non-byte EncoderBuffer value");this.value=i,this.length=1}else if(typeof i=="string")this.value=i,this.length=Mn.byteLength(i);else if(Mn.isBuffer(i))this.value=i,this.length=i.length;else return e.error("Unsupported type: "+typeof i)}fl.EncoderBuffer=On;On.isEncoderBuffer=function(e){return e instanceof On?!0:typeof e=="object"&&e.constructor.name==="EncoderBuffer"&&typeof e.length=="number"&&typeof e.join=="function"};On.prototype.join=function(e,t){return e||(e=Mn.alloc(this.length)),t||(t=0),this.length===0||(Array.isArray(this.value)?this.value.forEach(function(n){n.join(e,t),t+=n.length}):(typeof this.value=="number"?e[t]=this.value:typeof this.value=="string"?e.write(this.value,t):Mn.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e}});var $m=C((pM,zm)=>{zm.exports=Hm;function Hm(i,e){if(!i)throw new Error(e||"Assertion failed")}Hm.equal=function(e,t,n){if(e!=t)throw new Error(n||"Assertion failed: "+e+" != "+t)}});var Qr=C((dM,Vm)=>{"use strict";var aE=Xr().Reporter,cE=An().EncoderBuffer,lE=An().DecoderBuffer,et=$m(),Wm=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],uE=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(Wm),pE=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];function K(i,e,t){let n={};this._baseState=n,n.name=t,n.enc=i,n.parent=e||null,n.children=null,n.tag=null,n.args=null,n.reverseArgs=null,n.choice=null,n.optional=!1,n.any=!1,n.obj=!1,n.use=null,n.useDecoder=null,n.key=null,n.default=null,n.explicit=null,n.implicit=null,n.contains=null,n.parent||(n.children=[],this._wrap())}Vm.exports=K;var dE=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];K.prototype.clone=function(){let e=this._baseState,t={};dE.forEach(function(s){t[s]=e[s]});let n=new this.constructor(t.parent);return n._baseState=t,n};K.prototype._wrap=function(){let e=this._baseState;uE.forEach(function(t){this[t]=function(){let s=new this.constructor(this);return e.children.push(s),s[t].apply(s,arguments)}},this)};K.prototype._init=function(e){let t=this._baseState;et(t.parent===null),e.call(this),t.children=t.children.filter(function(n){return n._baseState.parent===this},this),et.equal(t.children.length,1,"Root node can have only one child")};K.prototype._useArgs=function(e){let t=this._baseState,n=e.filter(function(s){return s instanceof this.constructor},this);e=e.filter(function(s){return!(s instanceof this.constructor)},this),n.length!==0&&(et(t.children===null),t.children=n,n.forEach(function(s){s._baseState.parent=this},this)),e.length!==0&&(et(t.args===null),t.args=e,t.reverseArgs=e.map(function(s){if(typeof s!="object"||s.constructor!==Object)return s;let r={};return Object.keys(s).forEach(function(o){o==(o|0)&&(o|=0);let a=s[o];r[a]=o}),r}))};pE.forEach(function(i){K.prototype[i]=function(){let t=this._baseState;throw new Error(i+" not implemented for encoding: "+t.enc)}});Wm.forEach(function(i){K.prototype[i]=function(){let t=this._baseState,n=Array.prototype.slice.call(arguments);return et(t.tag===null),t.tag=i,this._useArgs(n),this}});K.prototype.use=function(e){et(e);let t=this._baseState;return et(t.use===null),t.use=e,this};K.prototype.optional=function(){let e=this._baseState;return e.optional=!0,this};K.prototype.def=function(e){let t=this._baseState;return et(t.default===null),t.default=e,t.optional=!0,this};K.prototype.explicit=function(e){let t=this._baseState;return et(t.explicit===null&&t.implicit===null),t.explicit=e,this};K.prototype.implicit=function(e){let t=this._baseState;return et(t.explicit===null&&t.implicit===null),t.implicit=e,this};K.prototype.obj=function(){let e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,t.length!==0&&this._useArgs(t),this};K.prototype.key=function(e){let t=this._baseState;return et(t.key===null),t.key=e,this};K.prototype.any=function(){let e=this._baseState;return e.any=!0,this};K.prototype.choice=function(e){let t=this._baseState;return et(t.choice===null),t.choice=e,this._useArgs(Object.keys(e).map(function(n){return e[n]})),this};K.prototype.contains=function(e){let t=this._baseState;return et(t.use===null),t.contains=e,this};K.prototype._decode=function(e,t){let n=this._baseState;if(n.parent===null)return e.wrapResult(n.children[0]._decode(e,t));let s=n.default,r=!0,o=null;if(n.key!==null&&(o=e.enterKey(n.key)),n.optional){let l=null;if(n.explicit!==null?l=n.explicit:n.implicit!==null?l=n.implicit:n.tag!==null&&(l=n.tag),l===null&&!n.any){let p=e.save();try{n.choice===null?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),r=!0}catch{r=!1}e.restore(p)}else if(r=this._peekTag(e,l,n.any),e.isError(r))return r}let a;if(n.obj&&r&&(a=e.enterObject()),r){if(n.explicit!==null){let p=this._decodeTag(e,n.explicit);if(e.isError(p))return p;e=p}let l=e.offset;if(n.use===null&&n.choice===null){let p;n.any&&(p=e.save());let f=this._decodeTag(e,n.implicit!==null?n.implicit:n.tag,n.any);if(e.isError(f))return f;n.any?s=e.raw(p):e=f}if(t&&t.track&&n.tag!==null&&t.track(e.path(),l,e.length,"tagged"),t&&t.track&&n.tag!==null&&t.track(e.path(),e.offset,e.length,"content"),n.any||(n.choice===null?s=this._decodeGeneric(n.tag,e,t):s=this._decodeChoice(e,t)),e.isError(s))return s;if(!n.any&&n.choice===null&&n.children!==null&&n.children.forEach(function(f){f._decode(e,t)}),n.contains&&(n.tag==="octstr"||n.tag==="bitstr")){let p=new lE(s);s=this._getUse(n.contains,e._reporterState.obj)._decode(p,t)}}return n.obj&&r&&(s=e.leaveObject(a)),n.key!==null&&(s!==null||r===!0)?e.leaveKey(o,n.key,s):o!==null&&e.exitKey(o),s};K.prototype._decodeGeneric=function(e,t,n){let s=this._baseState;return e==="seq"||e==="set"?null:e==="seqof"||e==="setof"?this._decodeList(t,e,s.args[0],n):/str$/.test(e)?this._decodeStr(t,e,n):e==="objid"&&s.args?this._decodeObjid(t,s.args[0],s.args[1],n):e==="objid"?this._decodeObjid(t,null,null,n):e==="gentime"||e==="utctime"?this._decodeTime(t,e,n):e==="null_"?this._decodeNull(t,n):e==="bool"?this._decodeBool(t,n):e==="objDesc"?this._decodeStr(t,e,n):e==="int"||e==="enum"?this._decodeInt(t,s.args&&s.args[0],n):s.use!==null?this._getUse(s.use,t._reporterState.obj)._decode(t,n):t.error("unknown tag: "+e)};K.prototype._getUse=function(e,t){let n=this._baseState;return n.useDecoder=this._use(e,t),et(n.useDecoder._baseState.parent===null),n.useDecoder=n.useDecoder._baseState.children[0],n.implicit!==n.useDecoder._baseState.implicit&&(n.useDecoder=n.useDecoder.clone(),n.useDecoder._baseState.implicit=n.implicit),n.useDecoder};K.prototype._decodeChoice=function(e,t){let n=this._baseState,s=null,r=!1;return Object.keys(n.choice).some(function(o){let a=e.save(),l=n.choice[o];try{let p=l._decode(e,t);if(e.isError(p))return!1;s={type:o,value:p},r=!0}catch{return e.restore(a),!1}return!0},this),r?s:e.error("Choice not matched")};K.prototype._createEncoderBuffer=function(e){return new cE(e,this.reporter)};K.prototype._encode=function(e,t,n){let s=this._baseState;if(s.default!==null&&s.default===e)return;let r=this._encodeValue(e,t,n);if(r!==void 0&&!this._skipDefault(r,t,n))return r};K.prototype._encodeValue=function(e,t,n){let s=this._baseState;if(s.parent===null)return s.children[0]._encode(e,t||new aE);let r=null;if(this.reporter=t,s.optional&&e===void 0)if(s.default!==null)e=s.default;else return;let o=null,a=!1;if(s.any)r=this._createEncoderBuffer(e);else if(s.choice)r=this._encodeChoice(e,t);else if(s.contains)o=this._getUse(s.contains,n)._encode(e,t),a=!0;else if(s.children)o=s.children.map(function(l){if(l._baseState.tag==="null_")return l._encode(null,t,e);if(l._baseState.key===null)return t.error("Child should have a key");let p=t.enterKey(l._baseState.key);if(typeof e!="object")return t.error("Child expected, but input is not object");let f=l._encode(e[l._baseState.key],t,e);return t.leaveKey(p),f},this).filter(function(l){return l}),o=this._createEncoderBuffer(o);else if(s.tag==="seqof"||s.tag==="setof"){if(!(s.args&&s.args.length===1))return t.error("Too many args for : "+s.tag);if(!Array.isArray(e))return t.error("seqof/setof, but data is not Array");let l=this.clone();l._baseState.implicit=null,o=this._createEncoderBuffer(e.map(function(p){let f=this._baseState;return this._getUse(f.args[0],e)._encode(p,t)},l))}else s.use!==null?r=this._getUse(s.use,n)._encode(e,t):(o=this._encodePrimitive(s.tag,e),a=!0);if(!s.any&&s.choice===null){let l=s.implicit!==null?s.implicit:s.tag,p=s.implicit===null?"universal":"context";l===null?s.use===null&&t.error("Tag could be omitted only for .use()"):s.use===null&&(r=this._encodeComposite(l,a,p,o))}return s.explicit!==null&&(r=this._encodeComposite(s.explicit,!1,"context",r)),r};K.prototype._encodeChoice=function(e,t){let n=this._baseState,s=n.choice[e.type];return s||et(!1,e.type+" not found in "+JSON.stringify(Object.keys(n.choice))),s._encode(e.value,t)};K.prototype._encodePrimitive=function(e,t){let n=this._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if(e==="objid"&&n.args)return this._encodeObjid(t,n.reverseArgs[0],n.args[1]);if(e==="objid")return this._encodeObjid(t,null,null);if(e==="gentime"||e==="utctime")return this._encodeTime(t,e);if(e==="null_")return this._encodeNull();if(e==="int"||e==="enum")return this._encodeInt(t,n.args&&n.reverseArgs[0]);if(e==="bool")return this._encodeBool(t);if(e==="objDesc")return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)};K.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)};K.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)}});var eo=C(ji=>{"use strict";function Km(i){let e={};return Object.keys(i).forEach(function(t){(t|0)==t&&(t=t|0);let n=i[t];e[n]=t}),e}ji.tagClass={0:"universal",1:"application",2:"context",3:"private"};ji.tagClassByName=Km(ji.tagClass);ji.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"};ji.tagByName=Km(ji.tag)});var ml=C((hM,Jm)=>{"use strict";var fE=vi(),ni=Jr().Buffer,Gm=Qr(),hl=eo();function Ym(i){this.enc="der",this.name=i.name,this.entity=i,this.tree=new jt,this.tree._init(i.body)}Jm.exports=Ym;Ym.prototype.encode=function(e,t){return this.tree._encode(e,t).join()};function jt(i){Gm.call(this,"der",i)}fE(jt,Gm);jt.prototype._encodeComposite=function(e,t,n,s){let r=hE(e,t,n,this.reporter);if(s.length<128){let l=ni.alloc(2);return l[0]=r,l[1]=s.length,this._createEncoderBuffer([l,s])}let o=1;for(let l=s.length;l>=256;l>>=8)o++;let a=ni.alloc(2+o);a[0]=r,a[1]=128|o;for(let l=1+o,p=s.length;p>0;l--,p>>=8)a[l]=p&255;return this._createEncoderBuffer([a,s])};jt.prototype._encodeStr=function(e,t){if(t==="bitstr")return this._createEncoderBuffer([e.unused|0,e.data]);if(t==="bmpstr"){let n=ni.alloc(e.length*2);for(let s=0;s<e.length;s++)n.writeUInt16BE(e.charCodeAt(s),s*2);return this._createEncoderBuffer(n)}else return t==="numstr"?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):t==="printstr"?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(t)?this._createEncoderBuffer(e):t==="objDesc"?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")};jt.prototype._encodeObjid=function(e,t,n){if(typeof e=="string"){if(!t)return this.reporter.error("string objid given, but no values map found");if(!t.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=t[e].split(/[\s.]+/g);for(let a=0;a<e.length;a++)e[a]|=0}else if(Array.isArray(e)){e=e.slice();for(let a=0;a<e.length;a++)e[a]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!n){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,e[0]*40+e[1])}let s=0;for(let a=0;a<e.length;a++){let l=e[a];for(s++;l>=128;l>>=7)s++}let r=ni.alloc(s),o=r.length-1;for(let a=e.length-1;a>=0;a--){let l=e[a];for(r[o--]=l&127;(l>>=7)>0;)r[o--]=128|l&127}return this._createEncoderBuffer(r)};function Ct(i){return i<10?"0"+i:i}jt.prototype._encodeTime=function(e,t){let n,s=new Date(e);return t==="gentime"?n=[Ct(s.getUTCFullYear()),Ct(s.getUTCMonth()+1),Ct(s.getUTCDate()),Ct(s.getUTCHours()),Ct(s.getUTCMinutes()),Ct(s.getUTCSeconds()),"Z"].join(""):t==="utctime"?n=[Ct(s.getUTCFullYear()%100),Ct(s.getUTCMonth()+1),Ct(s.getUTCDate()),Ct(s.getUTCHours()),Ct(s.getUTCMinutes()),Ct(s.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(n,"octstr")};jt.prototype._encodeNull=function(){return this._createEncoderBuffer("")};jt.prototype._encodeInt=function(e,t){if(typeof e=="string"){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if(typeof e!="number"&&!ni.isBuffer(e)){let r=e.toArray();!e.sign&&r[0]&128&&r.unshift(0),e=ni.from(r)}if(ni.isBuffer(e)){let r=e.length;e.length===0&&r++;let o=ni.alloc(r);return e.copy(o),e.length===0&&(o[0]=0),this._createEncoderBuffer(o)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let n=1;for(let r=e;r>=256;r>>=8)n++;let s=new Array(n);for(let r=s.length-1;r>=0;r--)s[r]=e&255,e>>=8;return s[0]&128&&s.unshift(0),this._createEncoderBuffer(ni.from(s))};jt.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)};jt.prototype._use=function(e,t){return typeof e=="function"&&(e=e(t)),e._getEncoder("der").tree};jt.prototype._skipDefault=function(e,t,n){let s=this._baseState,r;if(s.default===null)return!1;let o=e.join();if(s.defaultBuffer===void 0&&(s.defaultBuffer=this._encodeValue(s.default,t,n).join()),o.length!==s.defaultBuffer.length)return!1;for(r=0;r<o.length;r++)if(o[r]!==s.defaultBuffer[r])return!1;return!0};function hE(i,e,t,n){let s;if(i==="seqof"?i="seq":i==="setof"&&(i="set"),hl.tagByName.hasOwnProperty(i))s=hl.tagByName[i];else if(typeof i=="number"&&(i|0)===i)s=i;else return n.error("Unknown tag: "+i);return s>=31?n.error("Multi-octet tag encoding unsupported"):(e||(s|=32),s|=hl.tagClassByName[t||"universal"]<<6,s)}});var Zm=C((mM,Xm)=>{"use strict";var mE=vi(),vl=ml();function gl(i){vl.call(this,i),this.enc="pem"}mE(gl,vl);Xm.exports=gl;gl.prototype.encode=function(e,t){let s=vl.prototype.encode.call(this,e).toString("base64"),r=["-----BEGIN "+t.label+"-----"];for(let o=0;o<s.length;o+=64)r.push(s.slice(o,o+64));return r.push("-----END "+t.label+"-----"),r.join(`
|
|
26
26
|
`)}});var xl=C(ev=>{"use strict";var Qm=ev;Qm.der=ml();Qm.pem=Zm()});var bl=C((gM,ov)=>{"use strict";var vE=vi(),gE=ll(),tv=An().DecoderBuffer,nv=Qr(),iv=eo();function sv(i){this.enc="der",this.name=i.name,this.entity=i,this.tree=new dt,this.tree._init(i.body)}ov.exports=sv;sv.prototype.decode=function(e,t){return tv.isDecoderBuffer(e)||(e=new tv(e,t)),this.tree._decode(e,t)};function dt(i){nv.call(this,"der",i)}vE(dt,nv);dt.prototype._peekTag=function(e,t,n){if(e.isEmpty())return!1;let s=e.save(),r=yl(e,'Failed to peek tag: "'+t+'"');return e.isError(r)?r:(e.restore(s),r.tag===t||r.tagStr===t||r.tagStr+"of"===t||n)};dt.prototype._decodeTag=function(e,t,n){let s=yl(e,'Failed to decode tag of "'+t+'"');if(e.isError(s))return s;let r=rv(e,s.primitive,'Failed to get length of "'+t+'"');if(e.isError(r))return r;if(!n&&s.tag!==t&&s.tagStr!==t&&s.tagStr+"of"!==t)return e.error('Failed to match tag: "'+t+'"');if(s.primitive||r!==null)return e.skip(r,'Failed to match body of: "'+t+'"');let o=e.save(),a=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(a)?a:(r=e.offset-o.offset,e.restore(o),e.skip(r,'Failed to match body of: "'+t+'"'))};dt.prototype._skipUntilEnd=function(e,t){for(;;){let n=yl(e,t);if(e.isError(n))return n;let s=rv(e,n.primitive,t);if(e.isError(s))return s;let r;if(n.primitive||s!==null?r=e.skip(s):r=this._skipUntilEnd(e,t),e.isError(r))return r;if(n.tagStr==="end")break}};dt.prototype._decodeList=function(e,t,n,s){let r=[];for(;!e.isEmpty();){let o=this._peekTag(e,"end");if(e.isError(o))return o;let a=n.decode(e,"der",s);if(e.isError(a)&&o)break;r.push(a)}return r};dt.prototype._decodeStr=function(e,t){if(t==="bitstr"){let n=e.readUInt8();return e.isError(n)?n:{unused:n,data:e.raw()}}else if(t==="bmpstr"){let n=e.raw();if(n.length%2===1)return e.error("Decoding of string type: bmpstr length mismatch");let s="";for(let r=0;r<n.length/2;r++)s+=String.fromCharCode(n.readUInt16BE(r*2));return s}else if(t==="numstr"){let n=e.raw().toString("ascii");return this._isNumstr(n)?n:e.error("Decoding of string type: numstr unsupported characters")}else{if(t==="octstr")return e.raw();if(t==="objDesc")return e.raw();if(t==="printstr"){let n=e.raw().toString("ascii");return this._isPrintstr(n)?n:e.error("Decoding of string type: printstr unsupported characters")}else return/str$/.test(t)?e.raw().toString():e.error("Decoding of string type: "+t+" unsupported")}};dt.prototype._decodeObjid=function(e,t,n){let s,r=[],o=0,a=0;for(;!e.isEmpty();)a=e.readUInt8(),o<<=7,o|=a&127,(a&128)===0&&(r.push(o),o=0);a&128&&r.push(o);let l=r[0]/40|0,p=r[0]%40;if(n?s=r:s=[l,p].concat(r.slice(1)),t){let f=t[s.join(" ")];f===void 0&&(f=t[s.join(".")]),f!==void 0&&(s=f)}return s};dt.prototype._decodeTime=function(e,t){let n=e.raw().toString(),s,r,o,a,l,p;if(t==="gentime")s=n.slice(0,4)|0,r=n.slice(4,6)|0,o=n.slice(6,8)|0,a=n.slice(8,10)|0,l=n.slice(10,12)|0,p=n.slice(12,14)|0;else if(t==="utctime")s=n.slice(0,2)|0,r=n.slice(2,4)|0,o=n.slice(4,6)|0,a=n.slice(6,8)|0,l=n.slice(8,10)|0,p=n.slice(10,12)|0,s<70?s=2e3+s:s=1900+s;else return e.error("Decoding "+t+" time is not supported yet");return Date.UTC(s,r-1,o,a,l,p,0)};dt.prototype._decodeNull=function(){return null};dt.prototype._decodeBool=function(e){let t=e.readUInt8();return e.isError(t)?t:t!==0};dt.prototype._decodeInt=function(e,t){let n=e.raw(),s=new gE(n);return t&&(s=t[s.toString(10)]||s),s};dt.prototype._use=function(e,t){return typeof e=="function"&&(e=e(t)),e._getDecoder("der").tree};function yl(i,e){let t=i.readUInt8(e);if(i.isError(t))return t;let n=iv.tagClass[t>>6],s=(t&32)===0;if((t&31)===31){let o=t;for(t=0;(o&128)===128;){if(o=i.readUInt8(e),i.isError(o))return o;t<<=7,t|=o&127}}else t&=31;let r=iv.tag[t];return{cls:n,primitive:s,tag:t,tagStr:r}}function rv(i,e,t){let n=i.readUInt8(t);if(i.isError(n))return n;if(!e&&n===128)return null;if((n&128)===0)return n;let s=n&127;if(s>4)return i.error("length octect is too long");n=0;for(let r=0;r<s;r++){n<<=8;let o=i.readUInt8(t);if(i.isError(o))return o;n|=o}return n}});var cv=C((xM,av)=>{"use strict";var xE=vi(),yE=Jr().Buffer,wl=bl();function _l(i){wl.call(this,i),this.enc="pem"}xE(_l,wl);av.exports=_l;_l.prototype.decode=function(e,t){let n=e.toString().split(/[\r\n]+/g),s=t.label.toUpperCase(),r=/^-----(BEGIN|END) ([^-]+)-----$/,o=-1,a=-1;for(let f=0;f<n.length;f++){let m=n[f].match(r);if(m!==null&&m[2]===s)if(o===-1){if(m[1]!=="BEGIN")break;o=f}else{if(m[1]!=="END")break;a=f;break}}if(o===-1||a===-1)throw new Error("PEM section not found for: "+s);let l=n.slice(o+1,a).join("");l.replace(/[^a-z0-9+/=]+/gi,"");let p=yE.from(l,"base64");return wl.prototype.decode.call(this,p,t)}});var Sl=C(uv=>{"use strict";var lv=uv;lv.der=bl();lv.pem=cv()});var dv=C(pv=>{"use strict";var bE=xl(),wE=Sl(),_E=vi(),SE=pv;SE.define=function(e,t){return new Rn(e,t)};function Rn(i,e){this.name=i,this.body=e,this.decoders={},this.encoders={}}Rn.prototype._createNamed=function(e){let t=this.name;function n(s){this._initNamed(s,t)}return _E(n,e),n.prototype._initNamed=function(r,o){e.call(this,r,o)},new n(this)};Rn.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(wE[e])),this.decoders[e]};Rn.prototype.decode=function(e,t,n){return this._getDecoder(t).decode(e,n)};Rn.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(bE[e])),this.encoders[e]};Rn.prototype.encode=function(e,t,n){return this._getEncoder(t).encode(e,n)}});var hv=C(fv=>{"use strict";var to=fv;to.Reporter=Xr().Reporter;to.DecoderBuffer=An().DecoderBuffer;to.EncoderBuffer=An().EncoderBuffer;to.Node=Qr()});var gv=C(vv=>{"use strict";var mv=vv;mv._reverse=function(e){let t={};return Object.keys(e).forEach(function(n){(n|0)==n&&(n=n|0);let s=e[n];t[s]=n}),t};mv.der=eo()});var yv=C(xv=>{"use strict";var Pn=xv;Pn.bignum=ll();Pn.define=dv().define;Pn.base=hv();Pn.constants=gv();Pn.decoders=Sl();Pn.encoders=xl()});var Bn=C((El,wv)=>{var io=require("buffer"),Ht=io.Buffer;function bv(i,e){for(var t in i)e[t]=i[t]}Ht.from&&Ht.alloc&&Ht.allocUnsafe&&Ht.allocUnsafeSlow?wv.exports=io:(bv(io,El),El.Buffer=Ni);function Ni(i,e,t){return Ht(i,e,t)}Ni.prototype=Object.create(Ht.prototype);bv(Ht,Ni);Ni.from=function(i,e,t){if(typeof i=="number")throw new TypeError("Argument must not be a number");return Ht(i,e,t)};Ni.alloc=function(i,e,t){if(typeof i!="number")throw new TypeError("Argument must be a number");var n=Ht(i);return e!==void 0?typeof t=="string"?n.fill(e,t):n.fill(e):n.fill(0),n};Ni.allocUnsafe=function(i){if(typeof i!="number")throw new TypeError("Argument must be a number");return Ht(i)};Ni.allocUnsafeSlow=function(i){if(typeof i!="number")throw new TypeError("Argument must be a number");return io.SlowBuffer(i)}});var kl=C((EM,_v)=>{var no=Bn().Buffer,EE=require("stream"),kE=require("util");function so(i){if(this.buffer=null,this.writable=!0,this.readable=!0,!i)return this.buffer=no.alloc(0),this;if(typeof i.pipe=="function")return this.buffer=no.alloc(0),i.pipe(this),this;if(i.length||typeof i=="object")return this.buffer=i,this.writable=!1,process.nextTick(function(){this.emit("end",i),this.readable=!1,this.emit("close")}.bind(this)),this;throw new TypeError("Unexpected data type ("+typeof i+")")}kE.inherits(so,EE);so.prototype.write=function(e){this.buffer=no.concat([this.buffer,no.from(e)]),this.emit("data",e)};so.prototype.end=function(e){e&&this.write(e),this.emit("end",e),this.emit("close"),this.writable=!1,this.readable=!1};_v.exports=so});var Ev=C((kM,Sv)=>{"use strict";function Cl(i){var e=(i/8|0)+(i%8===0?0:1);return e}var CE={ES256:Cl(256),ES384:Cl(384),ES512:Cl(521)};function TE(i){var e=CE[i];if(e)return e;throw new Error('Unknown algorithm "'+i+'"')}Sv.exports=TE});var Rv=C((CM,Av)=>{"use strict";var ro=Bn().Buffer,Cv=Ev(),oo=128,Tv=0,ME=32,OE=16,AE=2,Mv=OE|ME|Tv<<6,ao=AE|Tv<<6;function RE(i){return i.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Ov(i){if(ro.isBuffer(i))return i;if(typeof i=="string")return ro.from(i,"base64");throw new TypeError("ECDSA signature must be a Base64 string or a Buffer")}function PE(i,e){i=Ov(i);var t=Cv(e),n=t+1,s=i.length,r=0;if(i[r++]!==Mv)throw new Error('Could not find expected "seq"');var o=i[r++];if(o===(oo|1)&&(o=i[r++]),s-r<o)throw new Error('"seq" specified length of "'+o+'", only "'+(s-r)+'" remaining');if(i[r++]!==ao)throw new Error('Could not find expected "int" for "r"');var a=i[r++];if(s-r-2<a)throw new Error('"r" specified length of "'+a+'", only "'+(s-r-2)+'" available');if(n<a)throw new Error('"r" specified length of "'+a+'", max of "'+n+'" is acceptable');var l=r;if(r+=a,i[r++]!==ao)throw new Error('Could not find expected "int" for "s"');var p=i[r++];if(s-r!==p)throw new Error('"s" specified length of "'+p+'", expected "'+(s-r)+'"');if(n<p)throw new Error('"s" specified length of "'+p+'", max of "'+n+'" is acceptable');var f=r;if(r+=p,r!==s)throw new Error('Expected to consume entire buffer, but "'+(s-r)+'" bytes remain');var m=t-a,_=t-p,E=ro.allocUnsafe(m+a+_+p);for(r=0;r<m;++r)E[r]=0;i.copy(E,r,l+Math.max(-m,0),l+a),r=t;for(var k=r;r<k+_;++r)E[r]=0;return i.copy(E,r,f+Math.max(-_,0),f+p),E=E.toString("base64"),E=RE(E),E}function kv(i,e,t){for(var n=0;e+n<t&&i[e+n]===0;)++n;var s=i[e+n]>=oo;return s&&--n,n}function BE(i,e){i=Ov(i);var t=Cv(e),n=i.length;if(n!==t*2)throw new TypeError('"'+e+'" signatures must be "'+t*2+'" bytes, saw "'+n+'"');var s=kv(i,0,t),r=kv(i,t,i.length),o=t-s,a=t-r,l=2+o+1+1+a,p=l<oo,f=ro.allocUnsafe((p?2:3)+l),m=0;return f[m++]=Mv,p?f[m++]=l:(f[m++]=oo|1,f[m++]=l&255),f[m++]=ao,f[m++]=o,s<0?(f[m++]=0,m+=i.copy(f,m,0,t)):m+=i.copy(f,m,s,t),f[m++]=ao,f[m++]=a,r<0?(f[m++]=0,i.copy(f,m,t)):i.copy(f,m,t+r),f}Av.exports={derToJose:PE,joseToDer:BE}});var Bv=C((TM,Pv)=>{"use strict";var as=require("buffer").Buffer,Tl=require("buffer").SlowBuffer;Pv.exports=co;function co(i,e){if(!as.isBuffer(i)||!as.isBuffer(e)||i.length!==e.length)return!1;for(var t=0,n=0;n<i.length;n++)t|=i[n]^e[n];return t===0}co.install=function(){as.prototype.equal=Tl.prototype.equal=function(e){return co(this,e)}};var jE=as.prototype.equal,NE=Tl.prototype.equal;co.restore=function(){as.prototype.equal=jE,Tl.prototype.equal=NE}});var Rl=C((MM,Hv)=>{var Nn=Bn().Buffer,Tt=require("crypto"),Nv=Rv(),jv=require("util"),IE=`"%s" is not a valid algorithm.
|
|
27
27
|
Supported algorithms are:
|
|
28
28
|
"HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512" and "none".`,cs="secret must be a string or buffer",jn="key must be a string or a buffer",DE="key must be a string, a buffer or an object",Ol=typeof Tt.createPublicKey=="function";Ol&&(jn+=" or a KeyObject",cs+="or a KeyObject");function Iv(i){if(!Nn.isBuffer(i)&&typeof i!="string"&&(!Ol||typeof i!="object"||typeof i.type!="string"||typeof i.asymmetricKeyType!="string"||typeof i.export!="function"))throw Nt(jn)}function Dv(i){if(!Nn.isBuffer(i)&&typeof i!="string"&&typeof i!="object")throw Nt(DE)}function qE(i){if(!Nn.isBuffer(i)){if(typeof i=="string")return i;if(!Ol||typeof i!="object"||i.type!=="secret"||typeof i.export!="function")throw Nt(cs)}}function Al(i){return i.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function qv(i){i=i.toString();var e=4-i.length%4;if(e!==4)for(var t=0;t<e;++t)i+="=";return i.replace(/\-/g,"+").replace(/_/g,"/")}function Nt(i){var e=[].slice.call(arguments,1),t=jv.format.bind(jv,i).apply(null,e);return new TypeError(t)}function LE(i){return Nn.isBuffer(i)||typeof i=="string"}function ls(i){return LE(i)||(i=JSON.stringify(i)),i}function Lv(i){return function(t,n){qE(n),t=ls(t);var s=Tt.createHmac("sha"+i,n),r=(s.update(t),s.digest("base64"));return Al(r)}}var Ml,FE="timingSafeEqual"in Tt?function(e,t){return e.byteLength!==t.byteLength?!1:Tt.timingSafeEqual(e,t)}:function(e,t){return Ml||(Ml=Bv()),Ml(e,t)};function UE(i){return function(t,n,s){var r=Lv(i)(t,s);return FE(Nn.from(n),Nn.from(r))}}function Fv(i){return function(t,n){Dv(n),t=ls(t);var s=Tt.createSign("RSA-SHA"+i),r=(s.update(t),s.sign(n,"base64"));return Al(r)}}function Uv(i){return function(t,n,s){Iv(s),t=ls(t),n=qv(n);var r=Tt.createVerify("RSA-SHA"+i);return r.update(t),r.verify(s,n,"base64")}}function HE(i){return function(t,n){Dv(n),t=ls(t);var s=Tt.createSign("RSA-SHA"+i),r=(s.update(t),s.sign({key:n,padding:Tt.constants.RSA_PKCS1_PSS_PADDING,saltLength:Tt.constants.RSA_PSS_SALTLEN_DIGEST},"base64"));return Al(r)}}function zE(i){return function(t,n,s){Iv(s),t=ls(t),n=qv(n);var r=Tt.createVerify("RSA-SHA"+i);return r.update(t),r.verify({key:s,padding:Tt.constants.RSA_PKCS1_PSS_PADDING,saltLength:Tt.constants.RSA_PSS_SALTLEN_DIGEST},n,"base64")}}function $E(i){var e=Fv(i);return function(){var n=e.apply(null,arguments);return n=Nv.derToJose(n,"ES"+i),n}}function WE(i){var e=Uv(i);return function(n,s,r){s=Nv.joseToDer(s,"ES"+i).toString("base64");var o=e(n,s,r);return o}}function VE(){return function(){return""}}function KE(){return function(e,t){return t===""}}Hv.exports=function(e){var t={hs:Lv,rs:Fv,ps:HE,es:$E,none:VE},n={hs:UE,rs:Uv,ps:zE,es:WE,none:KE},s=e.match(/^(RS|PS|ES|HS)(256|384|512)$|^(none)$/);if(!s)throw Nt(IE,e);var r=(s[1]||s[3]).toLowerCase(),o=s[2];return{sign:t[r](o),verify:n[r](o)}}});var Pl=C((OM,zv)=>{var GE=require("buffer").Buffer;zv.exports=function(e){return typeof e=="string"?e:typeof e=="number"||GE.isBuffer(e)?e.toString():JSON.stringify(e)}});var Yv=C((AM,Gv)=>{var YE=Bn().Buffer,$v=kl(),JE=Rl(),XE=require("stream"),Wv=Pl(),Bl=require("util");function Vv(i,e){return YE.from(i,e).toString("base64").replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function ZE(i,e,t){t=t||"utf8";var n=Vv(Wv(i),"binary"),s=Vv(Wv(e),t);return Bl.format("%s.%s",n,s)}function Kv(i){var e=i.header,t=i.payload,n=i.secret||i.privateKey,s=i.encoding,r=JE(e.alg),o=ZE(e,t,s),a=r.sign(o,n);return Bl.format("%s.%s",o,a)}function lo(i){var e=i.secret;if(e=e??i.privateKey,e=e??i.key,/^hs/i.test(i.header.alg)===!0&&e==null)throw new TypeError("secret must be a string or buffer or a KeyObject");var t=new $v(e);this.readable=!0,this.header=i.header,this.encoding=i.encoding,this.secret=this.privateKey=this.key=t,this.payload=new $v(i.payload),this.secret.once("close",function(){!this.payload.writable&&this.readable&&this.sign()}.bind(this)),this.payload.once("close",function(){!this.secret.writable&&this.readable&&this.sign()}.bind(this))}Bl.inherits(lo,XE);lo.prototype.sign=function(){try{var e=Kv({header:this.header,payload:this.payload.buffer,secret:this.secret.buffer,encoding:this.encoding});return this.emit("done",e),this.emit("data",e),this.emit("end"),this.readable=!1,e}catch(t){this.readable=!1,this.emit("error",t),this.emit("close")}};lo.sign=Kv;Gv.exports=lo});var rg=C((RM,sg)=>{var Xv=Bn().Buffer,Jv=kl(),QE=Rl(),ek=require("stream"),Zv=Pl(),tk=require("util"),ik=/^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)?$/;function nk(i){return Object.prototype.toString.call(i)==="[object Object]"}function sk(i){if(nk(i))return i;try{return JSON.parse(i)}catch{return}}function Qv(i){var e=i.split(".",1)[0];return sk(Xv.from(e,"base64").toString("binary"))}function rk(i){return i.split(".",2).join(".")}function eg(i){return i.split(".")[2]}function ok(i,e){e=e||"utf8";var t=i.split(".")[1];return Xv.from(t,"base64").toString(e)}function tg(i){return ik.test(i)&&!!Qv(i)}function ig(i,e,t){if(!e){var n=new Error("Missing algorithm parameter for jws.verify");throw n.code="MISSING_ALGORITHM",n}i=Zv(i);var s=eg(i),r=rk(i),o=QE(e);return o.verify(r,s,t)}function ng(i,e){if(e=e||{},i=Zv(i),!tg(i))return null;var t=Qv(i);if(!t)return null;var n=ok(i);return(t.typ==="JWT"||e.json)&&(n=JSON.parse(n,e.encoding)),{header:t,payload:n,signature:eg(i)}}function In(i){i=i||{};var e=i.secret;if(e=e??i.publicKey,e=e??i.key,/^hs/i.test(i.algorithm)===!0&&e==null)throw new TypeError("secret must be a string or buffer or a KeyObject");var t=new Jv(e);this.readable=!0,this.algorithm=i.algorithm,this.encoding=i.encoding,this.secret=this.publicKey=this.key=t,this.signature=new Jv(i.signature),this.secret.once("close",function(){!this.signature.writable&&this.readable&&this.verify()}.bind(this)),this.signature.once("close",function(){!this.secret.writable&&this.readable&&this.verify()}.bind(this))}tk.inherits(In,ek);In.prototype.verify=function(){try{var e=ig(this.signature.buffer,this.algorithm,this.key.buffer),t=ng(this.signature.buffer,this.encoding);return this.emit("done",e,t),this.emit("data",e),this.emit("end"),this.readable=!1,e}catch(n){this.readable=!1,this.emit("error",n),this.emit("close")}};In.decode=ng;In.isValid=tg;In.verify=ig;sg.exports=In});var ag=C(gi=>{var og=Yv(),uo=rg(),ak=["HS256","HS384","HS512","RS256","RS384","RS512","PS256","PS384","PS512","ES256","ES384","ES512"];gi.ALGORITHMS=ak;gi.sign=og.sign;gi.verify=uo.verify;gi.decode=uo.decode;gi.isValid=uo.isValid;gi.createSign=function(e){return new og(e)};gi.createVerify=function(e){return new uo(e)}});var po=C((BM,cg)=>{"use strict";var jl={};jl.supportedContentEncodings={AES_GCM:"aesgcm",AES_128_GCM:"aes128gcm"};jl.supportedUrgency={VERY_LOW:"very-low",LOW:"low",NORMAL:"normal",HIGH:"high"};cg.exports=jl});var Nl=C((jM,lg)=>{"use strict";function ck(i){return/^[A-Za-z0-9\-_]+$/.test(i)}lg.exports={validate:ck}});var Dl=C((NM,gg)=>{"use strict";var lk=require("crypto"),uk=yv(),pk=ag(),{URL:pg}=require("url"),ug=po(),dg=Nl(),dk=720*60,fk=1440*60,hk=uk.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").explicit(0).objid().optional(),this.key("publicKey").explicit(1).bitstr().optional())});function mk(i){return hk.encode({version:1,privateKey:i,parameters:[1,2,840,10045,3,1,7]},"pem",{label:"EC PRIVATE KEY"})}function vk(){let i=lk.createECDH("prime256v1");i.generateKeys();let e=i.getPublicKey(),t=i.getPrivateKey();if(t.length<32){let n=Buffer.alloc(32-t.length);n.fill(0),t=Buffer.concat([n,t])}if(e.length<65){let n=Buffer.alloc(65-e.length);n.fill(0),e=Buffer.concat([n,e])}return{publicKey:e.toString("base64url"),privateKey:t.toString("base64url")}}function fg(i){if(!i)throw new Error("No subject set in vapidDetails.subject.");if(typeof i!="string"||i.length===0)throw new Error("The subject value must be a string containing an https: URL or mailto: address. "+i);let e=null;try{e=new pg(i)}catch{throw new Error("Vapid subject is not a valid URL. "+i)}if(!["https:","mailto:"].includes(e.protocol))throw new Error("Vapid subject is not an https: or mailto: URL. "+i);e.hostname==="localhost"&&console.warn("Vapid subject points to a localhost web URI, which is unsupported by Apple's push notification server and will result in a BadJwtToken error when sending notifications.")}function hg(i){if(!i)throw new Error("No key set vapidDetails.publicKey");if(typeof i!="string")throw new Error("Vapid public key is must be a URL safe Base 64 encoded string.");if(!dg.validate(i))throw new Error('Vapid public key must be a URL safe Base 64 (without "=")');if(i=Buffer.from(i,"base64url"),i.length!==65)throw new Error("Vapid public key should be 65 bytes long when decoded.")}function mg(i){if(!i)throw new Error("No key set in vapidDetails.privateKey");if(typeof i!="string")throw new Error("Vapid private key must be a URL safe Base 64 encoded string.");if(!dg.validate(i))throw new Error('Vapid private key must be a URL safe Base 64 (without "=")');if(i=Buffer.from(i,"base64url"),i.length!==32)throw new Error("Vapid private key should be 32 bytes long when decoded.")}function Il(i){let e=new Date;return e.setSeconds(e.getSeconds()+i),Math.floor(e.getTime()/1e3)}function vg(i){if(!Number.isInteger(i))throw new Error("`expiration` value must be a number");if(i<0)throw new Error("`expiration` must be a positive integer");let e=Il(fk);if(i>=e)throw new Error("`expiration` value is greater than maximum of 24 hours")}function gk(i,e,t,n,s,r){if(!i)throw new Error("No audience could be generated for VAPID.");if(typeof i!="string"||i.length===0)throw new Error("The audience value must be a string containing the origin of a push service. "+i);try{new pg(i)}catch{throw new Error("VAPID audience is not a url. "+i)}fg(e),hg(t),mg(n),n=Buffer.from(n,"base64url"),r?vg(r):r=Il(dk);let o={typ:"JWT",alg:"ES256"},a={aud:i,exp:r,sub:e},l=pk.sign({header:o,payload:a,privateKey:mk(n)});if(s===ug.supportedContentEncodings.AES_128_GCM)return{Authorization:"vapid t="+l+", k="+t};if(s===ug.supportedContentEncodings.AES_GCM)return{Authorization:"WebPush "+l,"Crypto-Key":"p256ecdsa="+t};throw new Error("Unsupported encoding type specified.")}gg.exports={generateVAPIDKeys:vk,getFutureExpirationTimestamp:Il,getVapidHeaders:gk,validateSubject:fg,validatePublicKey:hg,validatePrivateKey:mg,validateExpiration:vg}});var Mg=C((IM,Tg)=>{"use strict";var ho=require("crypto"),yg="aes-128-gcm",mo={aes128gcm:1,aesgcm:2},Ii=16,zt=16,xk=12,bg=32,us="encrypt",ps="decrypt",G;process.env.ECE_KEYLOG==="1"?G=function(i,e){return console.warn(i+" ["+e.length+"]: "+e.toString("base64url")),e}:G=function(i,e){return e};function fo(i){return typeof i=="string"?Buffer.from(i,"base64url"):i}function wg(i,e){var t=ho.createHmac("sha256",i);return t.update(e),t.digest()}function _g(i,e){return G("salt",i),G("ikm",e),G("extract",wg(i,e))}function ql(i,e,t){G("prk",i),G("info",e);var n=Buffer.alloc(0),s=Buffer.alloc(0);e=Buffer.from(e,"ascii");for(var r=0,o=Buffer.alloc(1);n.length<t;)o.writeUIntBE(++r,0,1),s=wg(i,Buffer.concat([s,e,o])),n=Buffer.concat([n,s]);return G("expand",n.slice(0,t))}function Sg(i,e,t,n){return ql(_g(i,e),t,n)}function Ll(i,e){var t=Buffer.concat([Buffer.from("Content-Encoding: "+i+"\0","ascii"),e]);return G("info "+i,t),t}function xg(i){var e=Buffer.concat([Buffer.alloc(2),i]);return e.writeUIntBE(i.length,0,2),e}function yk(i,e){var t=i.privateKey,n,s;if(e===us)n=t.getPublicKey(),s=i.dh;else if(e===ps)n=i.dh,s=t.getPublicKey();else throw new Error("Unknown mode only "+us+" and "+ps+" supported");return{secret:t.computeSecret(i.dh),context:Buffer.concat([Buffer.from(i.keylabel,"ascii"),Buffer.from([0]),xg(s),xg(n)])}}function bk(i,e){var t={secret:null,context:Buffer.alloc(0)};if(i.key){if(t.secret=i.key,t.secret.length!==zt)throw new Error("An explicit key must be "+zt+" bytes")}else i.dh?t=yk(i,e):typeof i.keyid!==void 0&&(t.secret=i.keymap[i.keyid]);if(!t.secret)throw new Error("Unable to determine key");return G("secret",t.secret),G("context",t.context),i.authSecret&&(t.secret=Sg(i.authSecret,t.secret,Ll("auth",Buffer.alloc(0)),bg),G("authsecret",t.secret)),t}function wk(i,e){if(!i.authSecret)throw new Error("No authentication secret for webpush");G("authsecret",i.authSecret);var t,n,s;if(e===us)n=i.privateKey.getPublicKey(),t=s=i.dh;else if(e===ps)t=n=i.keyid,s=i.privateKey.getPublicKey();else throw new Error("Unknown mode only "+us+" and "+ps+" supported");return G("remote pubkey",t),G("sender pubkey",n),G("receiver pubkey",s),G("secret dh",Sg(i.authSecret,i.privateKey.computeSecret(t),Buffer.concat([Buffer.from("WebPush: info\0"),s,n]),bg))}function _k(i,e,t){if(t&&!Rk(t))throw new Error("Callback is not a function");if(i.key){if(i.key.length!==zt)throw new Error("An explicit key must be "+zt+" bytes");return G("secret key",i.key)}if(!i.privateKey){if(t)var n=t(i.keyid);else var n=i.keymap&&i.keymap[i.keyid];if(!n)throw new Error('No saved key (keyid: "'+i.keyid+'")');return n}return wk(i,e)}function Eg(i,e,t){if(!i.salt)throw new Error("must include a salt parameter for "+i.version);var n,s,r;if(i.version==="aesgcm"){var o=bk(i,e,t);n=Ll("aesgcm",o.context),s=Ll("nonce",o.context),r=o.secret}else if(i.version==="aes128gcm")n=Buffer.from("Content-Encoding: aes128gcm\0"),s=Buffer.from("Content-Encoding: nonce\0"),r=_k(i,e,t);else throw new Error("Unable to set context for mode "+i.version);var a=_g(i.salt,r),l={key:ql(a,n,zt),nonce:ql(a,s,xk)};return G("key",l.key),G("nonce base",l.nonce),l}function kg(i){var e={};e.version=i.version||"aes128gcm",e.rs=parseInt(i.rs,10),isNaN(e.rs)&&(e.rs=4096);var t=mo[e.version];if(e.version==="aes128gcm"&&(t+=Ii),e.rs<=t)throw new Error("The rs parameter has to be greater than "+t);if(i.salt&&(e.salt=fo(i.salt),e.salt.length!==zt))throw new Error("The salt parameter must be "+zt+" bytes");return e.keyid=i.keyid,i.key?e.key=fo(i.key):(e.privateKey=i.privateKey,e.privateKey||(e.keymap=i.keymap),e.version!=="aes128gcm"&&(e.keylabel=i.keylabel||"P-256"),i.dh&&(e.dh=fo(i.dh))),i.authSecret&&(e.authSecret=fo(i.authSecret)),e}function Cg(i,e){var t=Buffer.from(i),n=t.readUIntBE(t.length-6,6),s=((n^e)&16777215)+((n/16777216^e/16777216)&16777215)*16777216;return t.writeUIntBE(s,t.length-6,6),G("nonce"+e,t),t}function Sk(i,e){var t=i.readUIntBE(20,1);return e.salt=i.slice(0,zt),e.rs=i.readUIntBE(zt,4),e.keyid=i.slice(21,21+t),21+t}function Ek(i,e){var t=mo[e],n=i.readUIntBE(0,t);if(n+t>i.length)throw new Error("padding exceeds block size");G("padding",i.slice(0,t+n));var s=Buffer.alloc(n);if(s.fill(0),s.compare(i.slice(t,t+n))!==0)throw new Error("invalid padding");return i.slice(t+n)}function kk(i,e){for(var t=i.length-1;t>=0;){if(i[t]){if(e){if(i[t]!==2)throw new Error("last record needs to start padding with a 2")}else if(i[t]!==1)throw new Error("last record needs to start padding with a 2");return i.slice(0,t)}--t}throw new Error("all zero plaintext")}function Ck(i,e,t,n,s){G("decrypt",t);var r=Cg(i.nonce,e),o=ho.createDecipheriv(yg,i.key,r);o.setAuthTag(t.slice(t.length-Ii));var a=o.update(t.slice(0,t.length-Ii));return a=Buffer.concat([a,o.final()]),G("decrypted",a),n.version!=="aes128gcm"?Ek(a,n.version):kk(a,s)}function Tk(i,e,t){var n=kg(e);if(n.version==="aes128gcm"){var s=Sk(i,n);i=i.slice(s)}var r=Eg(n,ps,t),o=0,a=Buffer.alloc(0),l=n.rs;n.version!=="aes128gcm"&&(l+=Ii);for(var p=0;o<i.length;++p){var f=o+l;if(n.version!=="aes128gcm"&&f===i.length)throw new Error("Truncated payload");if(f=Math.min(f,i.length),f-o<=Ii)throw new Error("Invalid block: too small at "+p);var m=Ck(r,p,i.slice(o,f),n,f>=i.length);a=Buffer.concat([a,m]),o=f}return a}function Mk(i,e,t,n,s,r){G("encrypt",t),n=n||0;var o=Cg(i.nonce,e),a=ho.createCipheriv(yg,i.key,o),l=[],p=mo[s.version],f=Buffer.alloc(n+p);if(f.fill(0),s.version!=="aes128gcm"){if(f.writeUIntBE(n,0,p),G("padding",f),l.push(a.update(f)),l.push(a.update(t)),!r&&f.length+t.length<s.rs)throw new Error("Unable to pad to record size")}else l.push(a.update(t)),f.writeUIntBE(r?2:1,0,1),G("padding",f),l.push(a.update(f));a.final();var m=a.getAuthTag();if(m.length!==Ii)throw new Error("invalid tag generated");return l.push(m),G("encrypted",Buffer.concat(l))}function Ok(i){var e=Buffer.alloc(5),t=Buffer.from(i.keyid||[]);if(t.length>255)throw new Error("keyid is too large");return e.writeUIntBE(i.rs,0,4),e.writeUIntBE(t.length,4,1),Buffer.concat([i.salt,e,t])}function Ak(i,e,t){if(!Buffer.isBuffer(i))throw new Error("buffer argument must be a Buffer");var n=kg(e);n.salt||(n.salt=ho.randomBytes(zt));var s;n.version==="aes128gcm"?(n.privateKey&&!n.keyid&&(n.keyid=n.privateKey.getPublicKey()),s=Ok(n)):s=Buffer.alloc(0);var r=Eg(n,us,t),o=0,a=mo[n.version],l=a;n.version==="aes128gcm"&&(l+=Ii);for(var p=isNaN(parseInt(e.pad,10))?0:parseInt(e.pad,10),f=0,m=!1;!m;){var _=Math.min(n.rs-l-1,p);n.version!=="aes128gcm"&&(_=Math.min((1<<a*8)-1,_)),p>0&&_===0&&++_,p-=_;var E=o+n.rs-l-_;n.version!=="aes128gcm"?m=E>i.length:m=E>=i.length,m=m&&p<=0;var k=Mk(r,f,i.slice(o,E),_,n,m);s=Buffer.concat([s,k]),o=E,++f}return s}function Rk(i){return typeof i=="function"}Tg.exports={decrypt:Tk,encrypt:Ak}});var Fl=C((DM,Ag)=>{"use strict";var Og=require("crypto"),Pk=Mg(),Bk=function(i,e,t,n){if(!i)throw new Error("No user public key provided for encryption.");if(typeof i!="string")throw new Error("The subscription p256dh value must be a string.");if(Buffer.from(i,"base64url").length!==65)throw new Error("The subscription p256dh value should be 65 bytes long.");if(!e)throw new Error("No user auth provided for encryption.");if(typeof e!="string")throw new Error("The subscription auth key must be a string.");if(Buffer.from(e,"base64url").length<16)throw new Error("The subscription auth key should be at least 16 bytes long");if(typeof t!="string"&&!Buffer.isBuffer(t))throw new Error("Payload must be either a string or a Node Buffer.");(typeof t=="string"||t instanceof String)&&(t=Buffer.from(t));let s=Og.createECDH("prime256v1"),r=s.generateKeys(),o=Og.randomBytes(16).toString("base64url"),a=Pk.encrypt(t,{version:n,dh:i,privateKey:s,salt:o,authSecret:e});return{localPublicKey:r,salt:o,cipherText:a}};Ag.exports={encrypt:Bk}});var Ul=C((qM,Pg)=>{"use strict";function Rg(i,e,t,n,s){Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.message=i,this.statusCode=e,this.headers=t,this.body=n,this.endpoint=s}require("util").inherits(Rg,Error);Pg.exports=Rg});var Ng=C(rt=>{"use strict";var jk=rt&&rt.__createBinding||(Object.create?(function(i,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(i,n,s)}):(function(i,e,t,n){n===void 0&&(n=t),i[n]=e[t]})),Nk=rt&&rt.__setModuleDefault||(Object.create?(function(i,e){Object.defineProperty(i,"default",{enumerable:!0,value:e})}):function(i,e){i.default=e}),Bg=rt&&rt.__importStar||function(i){if(i&&i.__esModule)return i;var e={};if(i!=null)for(var t in i)t!=="default"&&Object.prototype.hasOwnProperty.call(i,t)&&jk(e,i,t);return Nk(e,i),e};Object.defineProperty(rt,"__esModule",{value:!0});rt.req=rt.json=rt.toBuffer=void 0;var Ik=Bg(require("http")),Dk=Bg(require("https"));async function jg(i){let e=0,t=[];for await(let n of i)e+=n.length,t.push(n);return Buffer.concat(t,e)}rt.toBuffer=jg;async function qk(i){let t=(await jg(i)).toString("utf8");try{return JSON.parse(t)}catch(n){let s=n;throw s.message+=` (input: ${t})`,s}}rt.json=qk;function Lk(i,e={}){let n=((typeof i=="string"?i:i.href).startsWith("https:")?Dk:Ik).request(i,e),s=new Promise((r,o)=>{n.once("response",r).once("error",o).end()});return n.then=s.then.bind(s),n}rt.req=Lk});var Lg=C(ft=>{"use strict";var Dg=ft&&ft.__createBinding||(Object.create?(function(i,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(i,n,s)}):(function(i,e,t,n){n===void 0&&(n=t),i[n]=e[t]})),Fk=ft&&ft.__setModuleDefault||(Object.create?(function(i,e){Object.defineProperty(i,"default",{enumerable:!0,value:e})}):function(i,e){i.default=e}),qg=ft&&ft.__importStar||function(i){if(i&&i.__esModule)return i;var e={};if(i!=null)for(var t in i)t!=="default"&&Object.prototype.hasOwnProperty.call(i,t)&&Dg(e,i,t);return Fk(e,i),e},Uk=ft&&ft.__exportStar||function(i,e){for(var t in i)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Dg(e,i,t)};Object.defineProperty(ft,"__esModule",{value:!0});ft.Agent=void 0;var Hk=qg(require("net")),Ig=qg(require("http")),zk=require("https");Uk(Ng(),ft);var $t=Symbol("AgentBaseInternalState"),Hl=class extends Ig.Agent{constructor(e){super(e),this[$t]={}}isSecureEndpoint(e){if(e){if(typeof e.secureEndpoint=="boolean")return e.secureEndpoint;if(typeof e.protocol=="string")return e.protocol==="https:"}let{stack:t}=new Error;return typeof t!="string"?!1:t.split(`
|