typescript-virtual-container 1.2.7 → 1.2.9

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.
Files changed (130) hide show
  1. package/README.md +457 -42
  2. package/dist/SSHMimic/executor.js +3 -5
  3. package/dist/VirtualFileSystem/binaryPack.d.ts +49 -0
  4. package/dist/VirtualFileSystem/binaryPack.d.ts.map +1 -0
  5. package/dist/VirtualFileSystem/binaryPack.js +193 -0
  6. package/dist/VirtualFileSystem/index.d.ts +7 -5
  7. package/dist/VirtualFileSystem/index.d.ts.map +1 -1
  8. package/dist/VirtualFileSystem/index.js +20 -9
  9. package/dist/VirtualPackageManager/index.d.ts +202 -0
  10. package/dist/VirtualPackageManager/index.d.ts.map +1 -0
  11. package/dist/VirtualPackageManager/index.js +676 -0
  12. package/dist/VirtualShell/index.d.ts +87 -12
  13. package/dist/VirtualShell/index.d.ts.map +1 -1
  14. package/dist/VirtualShell/index.js +83 -12
  15. package/dist/VirtualUserManager/index.d.ts +52 -20
  16. package/dist/VirtualUserManager/index.d.ts.map +1 -1
  17. package/dist/VirtualUserManager/index.js +54 -20
  18. package/dist/commands/alias.d.ts +4 -0
  19. package/dist/commands/alias.d.ts.map +1 -0
  20. package/dist/commands/alias.js +58 -0
  21. package/dist/commands/apt.d.ts +4 -0
  22. package/dist/commands/apt.d.ts.map +1 -0
  23. package/dist/commands/apt.js +182 -0
  24. package/dist/commands/cat.d.ts.map +1 -1
  25. package/dist/commands/cat.js +27 -8
  26. package/dist/commands/chmod.d.ts.map +1 -1
  27. package/dist/commands/chmod.js +52 -3
  28. package/dist/commands/command-helpers.d.ts +78 -4
  29. package/dist/commands/command-helpers.d.ts.map +1 -1
  30. package/dist/commands/command-helpers.js +78 -4
  31. package/dist/commands/curl.d.ts.map +1 -1
  32. package/dist/commands/curl.js +81 -29
  33. package/dist/commands/dpkg.d.ts +4 -0
  34. package/dist/commands/dpkg.d.ts.map +1 -0
  35. package/dist/commands/dpkg.js +144 -0
  36. package/dist/commands/echo.d.ts.map +1 -1
  37. package/dist/commands/echo.js +24 -12
  38. package/dist/commands/free.d.ts +3 -0
  39. package/dist/commands/free.d.ts.map +1 -0
  40. package/dist/commands/free.js +38 -0
  41. package/dist/commands/helpers.d.ts +3 -0
  42. package/dist/commands/helpers.d.ts.map +1 -1
  43. package/dist/commands/helpers.js +3 -0
  44. package/dist/commands/history.d.ts +3 -0
  45. package/dist/commands/history.d.ts.map +1 -0
  46. package/dist/commands/history.js +21 -0
  47. package/dist/commands/index.d.ts +8 -1
  48. package/dist/commands/index.d.ts.map +1 -1
  49. package/dist/commands/index.js +120 -11
  50. package/dist/commands/ls.d.ts.map +1 -1
  51. package/dist/commands/ls.js +4 -3
  52. package/dist/commands/lsb-release.d.ts +3 -0
  53. package/dist/commands/lsb-release.d.ts.map +1 -0
  54. package/dist/commands/lsb-release.js +50 -0
  55. package/dist/commands/man.d.ts +3 -0
  56. package/dist/commands/man.d.ts.map +1 -0
  57. package/dist/commands/man.js +155 -0
  58. package/dist/commands/neofetch.d.ts.map +1 -1
  59. package/dist/commands/neofetch.js +5 -0
  60. package/dist/commands/ping.d.ts.map +1 -1
  61. package/dist/commands/ping.js +5 -2
  62. package/dist/commands/ps.d.ts.map +1 -1
  63. package/dist/commands/ps.js +27 -6
  64. package/dist/commands/sh.d.ts.map +1 -1
  65. package/dist/commands/sh.js +29 -11
  66. package/dist/commands/source.d.ts +3 -0
  67. package/dist/commands/source.d.ts.map +1 -0
  68. package/dist/commands/source.js +31 -0
  69. package/dist/commands/test.d.ts +3 -0
  70. package/dist/commands/test.d.ts.map +1 -0
  71. package/dist/commands/test.js +92 -0
  72. package/dist/commands/type.d.ts +3 -0
  73. package/dist/commands/type.d.ts.map +1 -0
  74. package/dist/commands/type.js +34 -0
  75. package/dist/commands/uptime.d.ts +3 -0
  76. package/dist/commands/uptime.d.ts.map +1 -0
  77. package/dist/commands/uptime.js +40 -0
  78. package/dist/commands/wget.d.ts.map +1 -1
  79. package/dist/commands/wget.js +71 -100
  80. package/dist/commands/which.d.ts +3 -0
  81. package/dist/commands/which.d.ts.map +1 -0
  82. package/dist/commands/which.js +32 -0
  83. package/dist/index.d.ts +5 -2
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -1
  86. package/dist/modules/linuxRootfs.d.ts +24 -0
  87. package/dist/modules/linuxRootfs.d.ts.map +1 -0
  88. package/dist/modules/linuxRootfs.js +297 -0
  89. package/dist/modules/neofetch.d.ts.map +1 -1
  90. package/dist/modules/neofetch.js +1 -0
  91. package/dist/standalone.js +4 -1
  92. package/package.json +2 -1
  93. package/src/SSHMimic/executor.ts +3 -5
  94. package/src/VirtualFileSystem/binaryPack.ts +219 -0
  95. package/src/VirtualFileSystem/index.ts +21 -11
  96. package/src/VirtualPackageManager/index.ts +820 -0
  97. package/src/VirtualShell/index.ts +104 -13
  98. package/src/VirtualUserManager/index.ts +55 -20
  99. package/src/commands/alias.ts +60 -0
  100. package/src/commands/apt.ts +198 -0
  101. package/src/commands/cat.ts +32 -8
  102. package/src/commands/chmod.ts +48 -3
  103. package/src/commands/command-helpers.ts +78 -4
  104. package/src/commands/curl.ts +78 -37
  105. package/src/commands/dpkg.ts +158 -0
  106. package/src/commands/echo.ts +30 -14
  107. package/src/commands/free.ts +40 -0
  108. package/src/commands/helpers.ts +8 -0
  109. package/src/commands/history.ts +29 -0
  110. package/src/commands/index.ts +116 -11
  111. package/src/commands/ls.ts +5 -4
  112. package/src/commands/lsb-release.ts +52 -0
  113. package/src/commands/man.ts +166 -0
  114. package/src/commands/neofetch.ts +5 -0
  115. package/src/commands/ping.ts +5 -2
  116. package/src/commands/ps.ts +28 -6
  117. package/src/commands/sh.ts +33 -11
  118. package/src/commands/source.ts +35 -0
  119. package/src/commands/test.ts +100 -0
  120. package/src/commands/type.ts +40 -0
  121. package/src/commands/uptime.ts +46 -0
  122. package/src/commands/wget.ts +70 -123
  123. package/src/commands/which.ts +34 -0
  124. package/src/index.ts +10 -0
  125. package/src/modules/linuxRootfs.ts +439 -0
  126. package/src/modules/neofetch.ts +1 -0
  127. package/src/standalone.ts +4 -1
  128. package/standalone.js +418 -103
  129. package/standalone.js.map +4 -4
  130. package/tests/new-features.test.ts +626 -0
package/standalone.js CHANGED
@@ -1,104 +1,419 @@
1
- "use strict";var Dd=Object.create;var Ts=Object.defineProperty;var Hd=Object.getOwnPropertyDescriptor;var Md=Object.getOwnPropertyNames;var Fd=Object.getPrototypeOf,Qd=Object.prototype.hasOwnProperty;var de=(n,t)=>()=>(n&&(t=n(n=0)),t);var ot=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),qa=(n,t)=>{for(var e in t)Ts(n,e,{get:t[e],enumerable:!0})},$d=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Md(t))!Qd.call(n,i)&&i!==e&&Ts(n,i,{get:()=>t[i],enumerable:!(r=Hd(t,i))||r.enumerable});return n};var Xt=(n,t,e)=>(e=n!=null?Dd(Fd(n)):{},$d(t||!n||!n.__esModule?Ts(e,"default",{value:n,enumerable:!0}):e,n));var Ya,Va=de(()=>{"use strict";Ya={name:"adduser",description:"Add a new user",category:"users",params:["<username> <password>"],run:async({authUser:n,shell:t,args:e})=>{if(n!=="root")return{stderr:"adduser: permission denied",exitCode:1};let[r,i]=e;return!r||!i?{stderr:"adduser: usage: adduser <username> <password>",exitCode:1}:(await t.users.addUser(r,i),{stdout:`adduser: user '${r}' created`,exitCode:0})}}});function ja(n){return Array.isArray(n)?n:[n]}function Ci(n,t){if(n===t)return{matched:!0,inlineValue:null};let e=`${t}=`;return n.startsWith(e)?{matched:!0,inlineValue:n.slice(e.length)}:{matched:!1,inlineValue:null}}function qd(n,t={}){let e=new Set(t.flags??[]),r=new Set(t.flagsWithValue??[]),i=[],s=!1;for(let o=0;o<n.length;o+=1){let a=n[o];if(s){i.push(a);continue}if(a==="--"){s=!0;continue}let c=!1;for(let f of e){let{matched:u}=Ci(a,f);if(u){c=!0;break}}if(!c){for(let f of r){let u=Ci(a,f);if(u.matched){c=!0,u.inlineValue===null&&o+1<n.length&&(o+=1);break}}c||i.push(a)}}return i}function Ne(n,t){let e=ja(t);for(let r of n)for(let i of e)if(Ci(r,i).matched)return!0;return!1}function $t(n,t){let e=ja(t);for(let r=0;r<n.length;r+=1){let i=n[r];for(let s of e){let o=Ci(i,s);if(!o.matched)continue;if(o.inlineValue!==null)return o.inlineValue;let a=n[r+1];return a!==void 0&&a!=="--"?a:!0}}}function Mt(n,t,e={}){return qd(n,e)[t]}function hr(n,t={}){let e=new Set,r=new Map,i=[],s=new Set(t.flags??[]),o=new Set(t.flagsWithValue??[]),a=!1;for(let c=0;c<n.length;c+=1){let f=n[c];if(a){i.push(f);continue}if(f==="--"){a=!0;continue}if(s.has(f)){e.add(f);continue}if(o.has(f)){let h=n[c+1];h&&!h.startsWith("-")?(r.set(f,h),c+=1):r.set(f,"");continue}let u=Array.from(o).find(h=>f.startsWith(`${h}=`));if(u){r.set(u,f.slice(u.length+1));continue}i.push(f)}return{flags:e,flagsWithValues:r,positionals:i}}var it=de(()=>{"use strict"});var za,Xa=de(()=>{"use strict";it();za={name:"awk",description:"Pattern scanning and processing language (minimal)",category:"text",params:["[-F <sep>] '<program>' [file]"],run:({args:n,stdin:t})=>{let e=$t(n,["-F"])??" ",r=n.find(c=>!c.startsWith("-")&&c!==e);if(!r)return{stderr:"awk: no program",exitCode:1};let i=r.match(/^\{?\s*print\s+([^}]+)\s*\}?$/);if(!i)return{stderr:`awk: unsupported program: ${r}`,exitCode:1};let s=i[1].split(/\s*,\s*/).map(c=>c.trim());return{stdout:(t??"").split(`
2
- `).filter(Boolean).map(c=>{let f=c.split(e===" "?/\s+/:e);return s.map(u=>{if(u==="$0")return c;let h=parseInt(u.replace("$",""),10);return Number.isNaN(h)?u.replace(/"/g,""):f[h-1]??""}).join(e===" "?" ":e)}).join(`
3
- `),exitCode:0}}}});var Ja,Za=de(()=>{"use strict";it();Ja={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=Ne(n,["-d","--decode"]),r=t??"";if(e)try{return{stdout:Buffer.from(r.trim(),"base64").toString("utf8"),exitCode:0}}catch{return{stderr:"base64: invalid input",exitCode:1}}return{stdout:Buffer.from(r).toString("base64"),exitCode:0}}}});function Rr(n){return n.replace(/\r\n/g,`
4
- `).replace(/\r/g,`
5
- `).replace(/\t/g," ").split(`
6
- `).map(t=>t.replace(/^[ \u00A0]{8,}/," ").replace(/[ \u00A0]{3,}/g," ")).join(`
7
- `).replace(/\n{3,}/g,`
8
-
9
- `).trimEnd()}function le(n,t){return!t||t.trim()===""?n:t.startsWith("/")?dr.posix.normalize(t):dr.posix.normalize(dr.posix.join(n,t))}function Gd(n){let t=n.startsWith("/")?dr.posix.normalize(n):dr.posix.normalize(`/${n}`);return Kd.some(e=>t===e||t.startsWith(`${e}/`))}function De(n,t,e){if(n!=="root"&&Gd(t))throw new Error(`${e}: permission denied: ${t}`)}function tc(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function Bi(n,t){return new Promise(e=>{let r;try{r=(0,ec.spawn)(n,t,{stdio:["ignore","pipe","pipe"]})}catch(c){e({stdout:"",stderr:`${n}: ${c instanceof Error?c.message:String(c)}`,exitCode:1});return}let i="",s="",o=r.stdout,a=r.stderr;if(!o||!a){e({stdout:"",stderr:`${n}: failed to capture process output`,exitCode:1});return}o.setEncoding("utf8"),a.setEncoding("utf8"),o.on("data",c=>{i+=c}),a.on("data",c=>{s+=c}),r.on("error",c=>{let f=c instanceof Error&&"code"in c?String(c.code??""):"";e({stdout:"",stderr:`${n}: ${c.message}`,exitCode:f==="ENOENT"?127:1})}),r.on("close",c=>{e({stdout:i,stderr:s,exitCode:c??1})})})}function Yd(n,t){let e=Array.from({length:n.length+1},()=>Array(t.length+1).fill(0));for(let r=0;r<=n.length;r+=1)e[r][0]=r;for(let r=0;r<=t.length;r+=1)e[0][r]=r;for(let r=1;r<=n.length;r+=1)for(let i=1;i<=t.length;i+=1){let s=n[r-1]===t[i-1]?0:1;e[r][i]=Math.min(e[r-1][i]+1,e[r][i-1]+1,e[r-1][i-1]+s)}return e[n.length][t.length]}function rc(n,t,e){let r=le(t,e);if(n.exists(r))return r;let i=dr.posix.dirname(r),s=dr.posix.basename(r),o=n.list(i),a=o.filter(f=>f.toLowerCase()===s.toLowerCase());if(a.length===1)return dr.posix.join(i,a[0]);let c=o.filter(f=>Yd(f.toLowerCase(),s.toLowerCase())<=1);return c.length===1?dr.posix.join(i,c[0]):r}function nc(n,t,e){return t.map(r=>{let i=le(n,r);return e(i).type==="directory"?`${r}/`:r}).join(" ")}var ec,dr,Kd,ct=de(()=>{"use strict";ec=require("node:child_process"),dr=Xt(require("node:path"),1),Kd=["/virtual-env-js/.auth"]});var ic,sc=de(()=>{"use strict";it();ct();ic={name:"cat",description:"Concatenate and print files",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=Mt(r,0);if(!i)return{stderr:"cat: missing file operand",exitCode:1};let s=rc(t.vfs,e,i);return De(n,s,"cat"),{stdout:t.vfs.readFile(s),exitCode:0}}}});var oc,ac=de(()=>{"use strict";ct();oc={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r,mode:i})=>{let s=le(e,r[0]??"/virtual-env-js");return De(n,s,"cd"),t.vfs.stat(s).type!=="directory"?{stderr:`cd: not a directory: ${s}`,exitCode:1}:i==="exec"?{exitCode:0}:{nextCwd:s,exitCode:0}}}});var cc,fc=de(()=>{"use strict";ct();cc={name:"chmod",description:"Change file permissions",category:"files",params:["<mode> <file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let[i,s]=r;if(!i||!s)return{stderr:"chmod: missing operand",exitCode:1};let o=le(e,s);try{if(De(n,o,"chmod"),!t.vfs.exists(o))return{stderr:`chmod: ${s}: No such file or directory`,exitCode:1};let a=parseInt(i,8);return Number.isNaN(a)?{stderr:`chmod: invalid mode: ${i}`,exitCode:1}:(t.vfs.chmod(o,a),{exitCode:0})}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}}});var uc,lc=de(()=>{"use strict";uc={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})}});var hc,dc=de(()=>{"use strict";it();ct();hc={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=Ne(r,["-r","-R","--recursive"]),s=r.filter(u=>!u.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let c=le(e,o),f=le(e,a);try{if(De(n,c,"cp"),De(n,f,"cp"),!t.vfs.exists(c))return{stderr:`cp: ${o}: No such file or directory`,exitCode:1};if(t.vfs.stat(c).type==="directory"){if(!i)return{stderr:`cp: ${o}: is a directory (use -r)`,exitCode:1};let h=(g,_)=>{t.vfs.mkdir(_,493);for(let y of t.vfs.list(g)){let x=`${g}/${y}`,I=`${_}/${y}`;if(t.vfs.stat(x).type==="directory")h(x,I);else{let $=t.vfs.readFileRaw(x);t.writeFileAsUser(n,I,$)}}},d=t.vfs.exists(f)&&t.vfs.stat(f).type==="directory"?`${f}/${o.split("/").pop()}`:f;h(c,d)}else{let h=t.vfs.exists(f)&&t.vfs.stat(f).type==="directory"?`${f}/${o.split("/").pop()}`:f,d=t.vfs.readFileRaw(c);t.writeFileAsUser(n,h,d)}return{exitCode:0}}catch(u){return{stderr:`cp: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}}});var pc,gc=de(()=>{"use strict";it();ct();pc={name:"curl",description:"HTTP client",category:"network",params:["[-o file] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:i,positionals:s}=hr(e,{flagsWithValue:["-o","--output"]}),o=i.get("-o")||i.get("--output")||null;if(!s[0])return{stderr:"curl: missing URL",exitCode:1};let c=o?[...s,"-o","-"]:s,f=await Bi("curl",c);if(f.exitCode!==0)return{stderr:Rr(f.stderr||`curl: exited with code ${f.exitCode}`),exitCode:f.exitCode};if(o){let u=le(t,o);return De(n,u,"curl"),r.writeFileAsUser(n,u,f.stdout),{stderr:f.stderr?Rr(f.stderr):void 0,exitCode:0}}return{stdout:f.stdout,stderr:f.stderr?Rr(f.stderr):void 0,exitCode:0}}}});var mc,Ac=de(()=>{"use strict";it();mc={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=$t(n,["-d"])??" ",i=($t(n,["-f"])??"1").split(",").map(a=>{let[c,f]=a.split("-").map(Number);return f!==void 0?{from:(c??1)-1,to:f-1}:{from:(c??1)-1,to:(c??1)-1}});return{stdout:(t??"").split(`
10
- `).map(a=>{let c=a.split(e),f=[];for(let u of i)for(let h=u.from;h<=Math.min(u.to,c.length-1);h++)f.push(c[h]??"");return f.join(e)}).join(`
11
- `),exitCode:0}}}});var Ec,_c=de(()=>{"use strict";Ec={name:"date",description:"Print current date and time",category:"system",params:["[+format]"],run:({args:n})=>{let t=new Date,e=n[0];return e?.startsWith("+")?{stdout:e.slice(1).replace("%Y",String(t.getFullYear())).replace("%m",String(t.getMonth()+1).padStart(2,"0")).replace("%d",String(t.getDate()).padStart(2,"0")).replace("%H",String(t.getHours()).padStart(2,"0")).replace("%M",String(t.getMinutes()).padStart(2,"0")).replace("%S",String(t.getSeconds()).padStart(2,"0")).replace("%s",String(Math.floor(t.getTime()/1e3))),exitCode:0}:{stdout:t.toString(),exitCode:0}}}});var yc,bc=de(()=>{"use strict";yc={name:"deluser",description:"Delete a user",category:"users",params:["<username>"],run:async({authUser:n,args:t,shell:e})=>{if(n!=="root")return{stderr:"deluser: permission denied",exitCode:1};let[r]=t;return r?(await e.users.deleteUser(r),{stdout:`deluser: user '${r}' deleted`,exitCode:0}):{stderr:"deluser: usage: deluser <username>",exitCode:1}}}});var xc,Sc=de(()=>{"use strict";xc={name:"df",description:"Report filesystem disk space usage",category:"system",params:["[-h]"],run:({shell:n})=>{let e=(n.vfs.getUsageBytes()/1024).toFixed(0),r="1048576",i=String(Number(r)-Number(e)),s=Math.round(Number(e)/Number(r)*100),o="Filesystem 1K-blocks Used Available Use% Mounted on",a=`virtual-fs ${r.padStart(9)} ${e.padStart(7)} ${i.padStart(9)} ${s}% /`;return{stdout:`${o}
12
- ${a}`,exitCode:0}}}});var wc,Ic=de(()=>{"use strict";ct();wc={name:"diff",description:"Compare files line by line",category:"text",params:["<file1> <file2>"],run:({shell:n,cwd:t,args:e})=>{let[r,i]=e;if(!r||!i)return{stderr:"diff: missing operand",exitCode:1};let s=le(t,r),o=le(t,i),a,c;try{a=n.vfs.readFile(s).split(`
13
- `)}catch{return{stderr:`diff: ${r}: No such file or directory`,exitCode:2}}try{c=n.vfs.readFile(o).split(`
14
- `)}catch{return{stderr:`diff: ${i}: No such file or directory`,exitCode:2}}let f=[],u=Math.max(a.length,c.length);for(let h=0;h<u;h++){let d=a[h],g=c[h];d!==g&&(d!==void 0&&f.push(`< ${d}`),g!==void 0&&f.push(`> ${g}`))}return{stdout:f.join(`
15
- `),exitCode:f.length>0?1:0}}}});var Cc,Bc=de(()=>{"use strict";it();ct();Cc={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=Ne(e,["-h"]),i=Ne(e,["-s"]),s=e.find(u=>!u.startsWith("-"))??".",o=le(t,s),a=u=>r?`${(u/1024).toFixed(1)}K`:String(Math.ceil(u/1024));if(!n.vfs.exists(o))return{stderr:`du: ${s}: No such file or directory`,exitCode:1};if(i||n.vfs.stat(o).type==="file")return{stdout:`${a(n.vfs.getUsageBytes(o))} ${s}`,exitCode:0};let c=[],f=(u,h)=>{let d=0;for(let g of n.vfs.list(u)){let _=`${u}/${g}`,y=`${h}/${g}`,x=n.vfs.stat(_);x.type==="directory"?d+=f(_,y):(d+=x.size,i||c.push(`${a(x.size)} ${y}`))}return c.push(`${a(d)} ${h}`),d};return f(o,s),{stdout:c.join(`
16
- `),exitCode:0}}}});function vi(n){return Ls.USER=n,Ls.HOME=`/home/${n}`,{...Ls}}var Ls,vc,ki=de(()=>{"use strict";Ls={PATH:"/usr/local/bin:/usr/bin:/bin",HOME:"/home/user",SHELL:"/bin/sh",TERM:"xterm-256color",USER:"user"};vc={name:"set",description:"Display or set shell variables",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0)return{stdout:Object.entries(t.vars).map(([r,i])=>`${r}=${i}`).join(`
17
- `),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("=");t.vars[e.slice(0,r)]=e.slice(r+1)}return{exitCode:0}}}});function Vd(n,t){return n.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g,(e,r)=>t[r]??"")}var kc,Rc=de(()=>{"use strict";it();ki();kc={name:"echo",description:"Display text",category:"shell",params:["[options] [text...]"],run:({args:n,authUser:t,stdin:e})=>{let{flags:r,positionals:i}=hr(n,{flags:["-n"]}),s=!r.has("-n"),o=i.length>0?i.join(" "):e??"",a=vi(t),c=Vd(o,a);return{stdout:s?c:c.trimEnd(),exitCode:0}}}});var Nc,Pc=de(()=>{"use strict";Nc={name:"env",description:"Print environment variables",category:"shell",params:[],run:({env:n,authUser:t})=>{let e={...n.vars,USER:t,HOME:`/home/${t}`};return{stdout:Object.entries(e).map(([r,i])=>`${r}=${i}`).join(`
18
- `),exitCode:0}}}});var Tc,Lc=de(()=>{"use strict";Tc={name:"exit",aliases:["bye"],params:[],run:()=>({closeSession:!0,exitCode:0})}});var Uc,Oc=de(()=>{"use strict";Uc={name:"export",description:"Set shell environment variable",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0)return{stdout:Object.entries(t.vars).map(([r,i])=>`declare -x ${r}="${i}"`).join(`
19
- `),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("="),i=e.slice(0,r),s=e.slice(r+1);t.vars[i]=s}return{exitCode:0}}}});var Dc,Hc=de(()=>{"use strict";it();ct();Dc={name:"find",description:"Search for files",category:"files",params:["[path] [-name <pattern>] [-type f|d]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=$t(r,["-name"]),s=$t(r,["-type"]),a=r.filter(d=>!d.startsWith("-")&&d!==i&&d!==s)[0]??".",c=le(e,a);try{if(De(n,c,"find"),!t.vfs.exists(c))return{stderr:`find: ${a}: No such file or directory`,exitCode:1}}catch(d){return{stderr:`find: ${d instanceof Error?d.message:String(d)}`,exitCode:1}}let f=i?new RegExp(`^${i.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,u=[],h=(d,g)=>{let _=t.vfs.stat(d),y=!s||s==="f"&&_.type==="file"||s==="d"&&_.type==="directory",x=!f||f.test(d.split("/").pop()??"");if(y&&x&&u.push(g),_.type==="directory")for(let I of t.vfs.list(d)){let O=`${d}/${I}`,$=`${g}/${I}`;h(O,$)}};return h(c,a),{stdout:u.join(`
20
- `),exitCode:0}}}});var Mc,Fc=de(()=>{"use strict";it();ct();Mc={name:"grep",description:"Search text patterns",category:"text",params:["[-i] [-v] [-n] [-r] <pattern> [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let{flags:s,positionals:o}=hr(r,{flags:["-i","-v","-n","-r"]}),a=s.has("-i"),c=s.has("-v"),f=s.has("-n"),u=s.has("-r"),h=o[0],d=o.slice(1);if(!h)return{stderr:"grep: no pattern specified",exitCode:1};let g;try{let I=a?"mi":"m";g=new RegExp(h,I)}catch{return{stderr:`grep: invalid regex: ${h}`,exitCode:1}}let _=(I,O="")=>{let $=I.split(`
21
- `),L=[];for(let j=0;j<$.length;j++){let J=$[j]??"",z=g.test(J);if(c?!z:z){let w=f?`${j+1}:`:"";L.push(`${O}${w}${J}`)}}return L},y=I=>{if(!t.vfs.exists(I))return[];if(t.vfs.stat(I).type==="file")return[I];if(!u)return[];let $=[],L=j=>{for(let J of t.vfs.list(j)){let z=`${j}/${J}`;t.vfs.stat(z).type==="file"?$.push(z):L(z)}};return L(I),$},x=[];if(d.length===0){if(!i)return{stdout:"",exitCode:1};x.push(..._(i))}else{let I=d.flatMap(O=>{let $=le(e,O);return y($).map(L=>({file:O,path:L}))});for(let{file:O,path:$}of I)try{De(n,$,"grep");let L=t.vfs.readFile($),j=I.length>1?`${O}:`:"";x.push(..._(L,j))}catch{return{stderr:`grep: ${O}: No such file or directory`,exitCode:1}}}return{stdout:x.length>0?x.join(`
22
- `):"",exitCode:x.length>0?0:1}}}});var Qc,$c=de(()=>{"use strict";Qc={name:"groups",description:"Print group memberships",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n;return{stdout:t.users.isSudoer(r)?`${r} sudo root`:r,exitCode:0}}}});var Wc,qc,Kc=de(()=>{"use strict";ct();Wc={name:"gzip",description:"Compress files",category:"archive",params:["<file>"],run:({shell:n,cwd:t,args:e})=>{let r=e[0];if(!r)return{stderr:"gzip: no file specified",exitCode:1};let i=le(t,r);try{return n.vfs.compressFile(i),{exitCode:0}}catch{return{stderr:`gzip: ${r}: No such file or directory`,exitCode:1}}}},qc={name:"gunzip",description:"Decompress files",category:"archive",params:["<file>"],aliases:["zcat"],run:({shell:n,cwd:t,args:e})=>{let r=e[0];if(!r)return{stderr:"gunzip: no file specified",exitCode:1};let i=le(t,r);try{return n.vfs.decompressFile(i),{exitCode:0}}catch{return{stderr:`gunzip: ${r}: No such file or directory`,exitCode:1}}}}});var Gc,Yc=de(()=>{"use strict";it();ct();Gc={name:"head",description:"Output first lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=$t(r,["-n"]),o=typeof s=="string"?parseInt(s,10):10,a=r.filter(u=>!u.startsWith("-")&&u!==s),c=u=>u.split(`
23
- `).slice(0,o).join(`
24
- `);if(a.length===0)return{stdout:c(i??""),exitCode:0};let f=[];for(let u of a){let h=le(e,u);try{De(n,h,"head"),f.push(c(t.vfs.readFile(h)))}catch{return{stderr:`head: ${u}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
25
- `),exitCode:0}}}});function jc(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function zc(n){return{name:"help",description:"Display this help message",category:"shell",params:["[command]"],run:({args:t})=>{let e=Jc();if(t[0]){let o=e.find(f=>f.name===t[0]||f.aliases?.includes(t[0]));if(!o)return{stderr:`help: no help for '${t[0]}'`,exitCode:1};let a=o.aliases?.length?` aliases: ${o.aliases.join(", ")}
26
- `:"",c=o.params.map(f=>` ${o.name} ${f}`).join(`
27
- `);return{stdout:[`\x1B[1m${o.name}\x1B[0m \u2014 ${o.description??"no description"}`,a,"Usage:",c||` ${o.name}`].filter(Boolean).join(`
28
- `),exitCode:0}}let r={};for(let o of e){let a=o.category??"misc";r[a]||(r[a]=[]),r[a].push(o)}let i=[];i.push("\x1B[1mAvailable commands\x1B[0m"),i.push("");let s=[...Vc.filter(o=>r[o]),...Object.keys(r).filter(o=>!Vc.includes(o))];for(let o of s){let a=r[o];if(!a||a.length===0)continue;i.push(`\x1B[33m${jd[o]??o}\x1B[0m`);let c=[...a].sort((f,u)=>f.name.localeCompare(u.name));for(let f=0;f<c.length;f+=2){let u=c[f],h=c[f+1],d=` \x1B[36m${jc(u.name,14)}\x1B[0m ${u.description??""}`,g=h?` \x1B[36m${jc(h.name,14)}\x1B[0m ${h.description??""}`:"";i.push(g?`${d.padEnd(44)}${g}`:d)}i.push("")}return i.push("Type \x1B[1mhelp <command>\x1B[0m for usage details."),{stdout:i.join(`
29
- `),exitCode:0}}}}var Vc,jd,Xc=de(()=>{"use strict";pr();Vc=["navigation","files","text","archive","system","network","shell","users","misc"],jd={navigation:"Navigation",files:"Files & Filesystem",text:"Text Processing",archive:"Archive & Compression",system:"System",network:"Network",shell:"Shell",users:"Users & Permissions",misc:"Miscellaneous"}});var Zc,ef=de(()=>{"use strict";Zc={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})}});var tf,rf=de(()=>{"use strict";tf={name:"htop",description:"System monitor",category:"system",params:[],run:({mode:n})=>n==="exec"?{stderr:"htop: interactive terminal required",exitCode:1}:{openHtop:!0,exitCode:0}}});var nf,sf=de(()=>{"use strict";nf={name:"id",description:"Print user identity",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n,i=r==="root"?0:1e3,s=i,a=t.users.isSudoer(r)?`${s}(${r}),0(root)`:`${s}(${r})`;return{stdout:`uid=${i}(${r}) gid=${s}(${r}) groups=${a}`,exitCode:0}}}});var of,af=de(()=>{"use strict";of={name:"kill",description:"Send signal to process",category:"system",params:["[-9] <pid>"],run:({args:n})=>n.find(e=>!e.startsWith("-"))?{stdout:"",exitCode:0}:{stderr:"kill: no pid specified",exitCode:1}}});var cf,ff=de(()=>{"use strict";it();ct();cf={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=Ne(r,["-s","--symbolic"]),s=r.filter(u=>!u.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let c=le(e,a),f=i?o:le(e,o);try{if(De(n,c,"ln"),i)t.vfs.symlink(f,c);else{let u=le(e,o);if(De(n,u,"ln"),!t.vfs.exists(u))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let h=t.vfs.readFile(u);t.writeFileAsUser(n,c,h)}return{exitCode:0}}catch(u){return{stderr:`ln: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}}});function zd(n,t){let e=t?"d":"-",i=[[256,"r"],[128,"w"],[64,"x"],[32,"r"],[16,"w"],[8,"x"],[4,"r"],[2,"w"],[1,"x"]].map(([s,o])=>n&s?o:"-").join("");return`${e}${i}`}function Xd(n){return n.toISOString().replace("T"," ").slice(0,16)}var uf,lf=de(()=>{"use strict";it();ct();uf={name:"ls",description:"List directory contents",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=Ne(r,["-l","--long"]),s=Mt(r,0,{flags:["-l","--long"]}),o=le(e,s??e);De(n,o,"ls");let a=t.vfs.list(o).filter(f=>!f.startsWith("."));return{stdout:i?a.map(f=>{let u=le(o,f),h=t.vfs.stat(u),d=h.type==="file"?h.size:h.childrenCount;return`${zd(h.mode,h.type==="directory")} 1 ${d} ${Xd(h.updatedAt)} ${f}${h.type==="directory"?"/":""}`}).join(`
30
- `):nc(o,a,f=>t.vfs.stat(f)),exitCode:0}}}});var hf,df=de(()=>{"use strict";it();ct();hf={name:"mkdir",description:"Make directories",category:"files",params:["<dir>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"mkdir: missing operand",exitCode:1};for(let i=0;i<r.length;i++){let s=Mt(r,i);if(!s)return{stderr:"mkdir: missing operand",exitCode:1};let o=le(e,s);De(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}}});var pf,gf=de(()=>{"use strict";ct();pf={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=r.filter(f=>!f.startsWith("-")),[s,o]=i;if(!s||!o)return{stderr:"mv: missing operand",exitCode:1};let a=le(e,s),c=le(e,o);try{if(De(n,a,"mv"),De(n,c,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${s}: No such file or directory`,exitCode:1};let f=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${s.split("/").pop()}`:c;return t.vfs.move(a,f),{exitCode:0}}catch(f){return{stderr:`mv: ${f instanceof Error?f.message:String(f)}`,exitCode:1}}}}});var mf,Af,Ef=de(()=>{"use strict";mf=Xt(require("node:path"),1);ct();Af={name:"nano",description:"Text editor",category:"shell",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=r[0];if(!i)return{stderr:"nano: missing file operand",exitCode:1};let s=le(e,i);De(n,s,"nano");let o=t.vfs.exists(s)?t.vfs.readFile(s):"",a=mf.posix.basename(s)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:s,tempPath:c,initialContent:o},exitCode:0}}}});function Jd(n){let t=Math.max(1,Math.floor(n/60)),e=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60,s=[];return e>0&&s.push(`${e} day${e>1?"s":""}`),r>0&&s.push(`${r} hour${r>1?"s":""}`),(i>0||s.length===0)&&s.push(`${i} min${i>1?"s":""}`),s.join(", ")}function _f(n){return`\x1B[${n}m \x1B[0m`}function Zd(){let n=[40,41,42,43,44,45,46,47].map(_f).join(""),t=[100,101,102,103,104,105,106,107].map(_f).join("");return[n,t]}function yf(n,t,e){if(n.trim().length===0)return n;let r={r:255,g:255,b:255},i={r:168,g:85,b:247},s=e<=1?0:t/(e-1),o=Math.round(r.r+(i.r-r.r)*s),a=Math.round(r.g+(i.g-r.g)*s),c=Math.round(r.b+(i.b-r.b)*s);return`\x1B[38;2;${o};${a};${c}m${n}\x1B[0m`}function ep(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?bf(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return bf(e)+r}function bf(n){let t=new RegExp("\x1B\\[[\\d;]*m","g"),e=n.replace(t,"");if(e.trim().length===0)return n;let r={r:255,g:255,b:255},i={r:168,g:85,b:247},s="";for(let o=0;o<e.length;o+=1){let a=e.length<=1?0:o/(e.length-1),c=Math.round(r.r+(i.r-r.r)*a),f=Math.round(r.g+(i.g-r.g)*a),u=Math.round(r.b+(i.b-r.b)*a);s+=`\x1B[38;2;${c};${f};${u}m${e[o]}\x1B[0m`}return s}function xf(n){return Math.max(0,Math.round(n/(1024*1024)))}function Sf(){try{let n=(0,br.readFileSync)("/etc/os-release","utf8");for(let t of n.split(`
31
- `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function wf(n){try{let t=(0,br.readFileSync)(n,"utf8").split(`
32
- `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function tp(n){let t=wf("/sys/devices/virtual/dmi/id/sys_vendor"),e=wf("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function rp(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if((0,br.existsSync)(t))try{return(0,br.readFileSync)(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function np(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if((0,br.existsSync)(t))try{return(0,br.readdirSync)(t,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}}function ip(){let n=rp(),t=np();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function sp(){let n=Nt.cpus();if(n.length===0)return"unknown";let t=n[0];if(!t)return"unknown";let e=(t.speed/1e3).toFixed(2);return`${t.model} (${n.length}) @ ${e}GHz`}function op(n){return!n||n.trim().length===0?"unknown":If.posix.basename(n.trim())}function ap(n){let t=Nt.totalmem(),e=Nt.freemem(),r=Math.max(0,t-e),i=n.shellProps,s=process.uptime();return n.uptimeSeconds===void 0&&(n.uptimeSeconds=Math.round(s)),{user:n.user,host:n.host,osName:i?.os??n.osName??`${Sf()??Nt.type()} ${Nt.arch()}`,kernel:i?.kernel??n.kernel??Nt.release(),uptimeSeconds:n.uptimeSeconds??Nt.uptime(),packages:n.packages??ip(),shell:op(n.shell),shellProps:n.shellProps??{kernel:n.kernel??Nt.release(),os:n.osName??`${Sf()??Nt.type()} ${Nt.arch()}`,arch:Nt.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??sp(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??xf(r),memoryTotalMiB:n.memoryTotalMiB??xf(t)}}function Cf(n){let t=ap(n),e=Jd(t.uptimeSeconds),r=Zd(),i=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],s=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${tp(t.host)}`,`Kernel: ${t.kernel}`,`Uptime: ${e}`,`Shell: ${t.shell}`,`Resolution: ${t.resolution}`,`Terminal: ${t.terminal}`,`CPU: ${t.cpu}`,`GPU: ${t.gpu}`,`Memory: ${t.memoryUsedMiB}MiB / ${t.memoryTotalMiB}MiB`,"",r[0],r[1]],o=Math.max(i.length,s.length),a=[];for(let c=0;c<o;c+=1){let f=i[c]??"",u=s[c]??"";if(u.length>0){let h=yf(f.padEnd(31," "),c,i.length),d=ep(u);a.push(`${h} ${d}`);continue}a.push(yf(f,c,i.length))}return a.join(`
33
- `)}var br,Nt,If,Bf=de(()=>{"use strict";br=require("node:fs"),Nt=Xt(require("node:os"),1),If=Xt(require("node:path"),1)});var vf,kf=de(()=>{"use strict";Bf();it();ki();vf={name:"neofetch",description:"System info display",category:"misc",params:["[--off]"],run:({args:n,authUser:t,hostname:e,shell:r})=>{let i=vi(t);return Ne(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:Ne(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:Cf({user:t,host:e,shell:i.SHELL,shellProps:r.properties,terminal:i.TERM}),exitCode:0}}}});var Rf,Nf=de(()=>{"use strict";Rf={name:"passwd",description:"Change user password",category:"users",params:["<username> <password>"],run:async({authUser:n,args:t,shell:e})=>{let[r,i]=t;return!r||!i?{stderr:"passwd: usage: passwd <username> <password>",exitCode:1}:n!=="root"&&n!==r?{stderr:"passwd: permission denied",exitCode:1}:(await e.users.setPassword(r,i),{stdout:`passwd: password updated for '${r}'`,exitCode:0})}}});var Pf,Tf=de(()=>{"use strict";Pf={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:n})=>{let t=n.find(i=>!i.startsWith("-"))??"localhost",e=4,r=[`PING ${t}: 56 data bytes`];for(let i=0;i<e;i++){let s=(Math.random()*10+1).toFixed(3);r.push(`64 bytes from ${t}: icmp_seq=${i} ttl=64 time=${s} ms`)}return r.push(`--- ${t} ping statistics ---`),r.push(`${e} packets transmitted, ${e} received, 0% packet loss`),{stdout:r.join(`
34
- `),exitCode:0}}}});var Lf,Uf=de(()=>{"use strict";Lf={name:"ps",description:"Report process status",category:"system",params:["[-a] [-u] [-x]"],run:({authUser:n,shell:t})=>{let e=t.users.listActiveSessions(),r=[" PID TTY TIME CMD"],i=1e3;for(let s of e)r.push(`${String(i).padStart(5)} ${s.tty.padEnd(12)} 00:00:00 ${s.username===n?"bash":`bash (${s.username})`}`),i++;return r.push(`${String(i).padStart(5)} pts/0 00:00:00 ps`),{stdout:r.join(`
35
- `),exitCode:0}}}});var Of,Df=de(()=>{"use strict";Of={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})}});var Hf,Mf=de(()=>{"use strict";it();ct();Hf={name:"rm",description:"Remove files or directories",category:"files",params:["[-r|-rf] <path>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"rm: missing operand",exitCode:1};let i=Ne(r,["-r","-rf","-fr"]),s=[];for(let o=0;;o+=1){let a=Mt(r,o,{flags:["-r","-rf","-fr"]});if(!a)break;s.push(a)}if(s.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of s){let a=le(e,o);De(n,a,"rm"),t.vfs.remove(a,{recursive:i})}return{exitCode:0}}}});var Ff,Qf=de(()=>{"use strict";it();ct();Ff={name:"sed",description:"Stream editor for filtering and transforming text",category:"text",params:["-e <expr> [file]","s/pattern/replace/[g]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=Ne(r,["-i"]),o=$t(r,["-e"])??r.find(x=>!x.startsWith("-")),a=r.filter(x=>!x.startsWith("-")&&x!==o).pop();if(!o)return{stderr:"sed: no expression",exitCode:1};let c=i??"";if(a){let x=le(e,a);try{c=t.vfs.readFile(x)}catch{return{stderr:`sed: ${a}: No such file or directory`,exitCode:1}}}let f=o.match(/^s([^a-zA-Z0-9])(.+?)\1(.*?)\1([gi]*)$/);if(!f)return{stderr:`sed: unrecognized command: ${o}`,exitCode:1};let[,,u,h,d]=f,g=(d??"").includes("i")?"gi":(d??"").includes("g")?"g":"",_;try{_=new RegExp(u,g||"")}catch{return{stderr:`sed: invalid regex: ${u}`,exitCode:1}}let y=((d??"").includes("g")||g.includes("g"),c.replace(_,h??""));if(s&&a){let x=le(e,a);return t.writeFileAsUser(n,x,y),{exitCode:0}}return{stdout:y,exitCode:0}}}});function Os(n,t,e){return n.replace(/\$\?/g,String(e)).replace(/\$\{([^}:]+):-([^}]*)\}/g,(r,i,s)=>t[i]??s).replace(/\$\{([^}]+)\}/g,(r,i)=>t[i]??"").replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g,(r,i)=>t[i]??"").replace(/^~(\/|$)/,`${t.HOME??"/home/user"}$1`)}function Vr(n){let t=[],e=0;for(;e<n.length;){let r=n[e].trim();if(!r||r.startsWith("#")){e++;continue}if(r.startsWith("if ")||r==="if"){let i=r.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),s=[],o=[],a=[],c="then",f="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let u=n[e].trim();u.startsWith("elif ")?(c="elif",f=u.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),o.push({cond:f,body:[]})):u==="else"?c="else":u!=="then"&&(c==="then"?s.push(u):c==="elif"&&o.length>0?o[o.length-1].body.push(u):a.push(u)),e++}t.push({type:"if",cond:i,then:s,elif:o,else_:a})}else if(r.startsWith("for ")){let i=r.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(i){let s=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let o=n[e].trim();o!=="do"&&s.push(o),e++}t.push({type:"for",var:i[1],list:i[2],body:s})}else t.push({type:"cmd",line:r})}else if(r.startsWith("while ")){let i=r.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),s=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let o=n[e].trim();o!=="do"&&s.push(o),e++}t.push({type:"while",cond:i,body:s})}else t.push({type:"cmd",line:r});e++}return t}async function Us(n,t){let e=Os(n,t.env.vars,t.env.lastExitCode),r=e.match(/^\[?\s*(.+?)\s*\]?$/);if(r){let s=r[1],o=s.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,f,u]=o,h=le(t.cwd,u);if(f==="f")return t.shell.vfs.exists(h)&&t.shell.vfs.stat(h).type==="file";if(f==="d")return t.shell.vfs.exists(h)&&t.shell.vfs.stat(h).type==="directory";if(f==="e")return t.shell.vfs.exists(h);if(f==="z")return(u??"").length===0;if(f==="n")return(u??"").length>0}let a=s.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,f,u,h]=a;if(u==="=="||u==="=")return f===h;if(u==="!=")return f!==h}let c=s.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,f,u,h]=c,d=Number(f),g=Number(h);if(u==="-eq")return d===g;if(u==="-ne")return d!==g;if(u==="-lt")return d<g;if(u==="-le")return d<=g;if(u==="-gt")return d>g;if(u==="-ge")return d>=g}}return((await kt(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function jr(n,t){let e={exitCode:0},r="";for(let i of n)if(i.type==="cmd"){let s=Os(i.line,t.env.vars,t.env.lastExitCode),o=await kt(s,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env);if(t.env.lastExitCode=o.exitCode??0,o.stdout&&(r+=`${o.stdout}
36
- `),o.stderr)return{...o,stdout:r.trim()};e=o}else if(i.type==="if"){let s=!1;if(await Us(i.cond,t)){let o=await jr(Vr(i.then),t);o.stdout&&(r+=`${o.stdout}
37
- `),s=!0}else{for(let o of i.elif)if(await Us(o.cond,t)){let a=await jr(Vr(o.body),t);a.stdout&&(r+=`${a.stdout}
38
- `),s=!0;break}if(!s&&i.else_.length>0){let o=await jr(Vr(i.else_),t);o.stdout&&(r+=`${o.stdout}
39
- `)}}}else if(i.type==="for"){let o=Os(i.list,t.env.vars,t.env.lastExitCode).trim().split(/\s+/);for(let a of o){t.env.vars[i.var]=a;let c=await jr(Vr(i.body),t);if(c.stdout&&(r+=`${c.stdout}
40
- `),c.closeSession)return c}}else if(i.type==="while"){let s=0;for(;s<1e3&&await Us(i.cond,t);){let o=await jr(Vr(i.body),t);if(o.stdout&&(r+=`${o.stdout}
41
- `),o.closeSession)return o;s++}}return{...e,stdout:r.trim()||e.stdout}}var $f,Wf=de(()=>{"use strict";it();ct();pr();$f={name:"sh",aliases:["bash"],description:"Execute shell script or command",category:"shell",params:["-c <script>","[<file>]"],run:async n=>{let{args:t,authUser:e,shell:r,cwd:i}=n;if(Ne(t,"-c")){let o=Mt(t,1)??"";if(!o)return{stderr:"sh: -c requires a script",exitCode:1};let a=o.split(/[;\n]/).map(f=>f.trim()).filter(f=>f&&!f.startsWith("#")),c=Vr(a);return jr(c,n)}let s=t[0];if(s){let o=le(i,s);if(!r.vfs.exists(o))return{stderr:`sh: ${s}: No such file or directory`,exitCode:1};let c=r.vfs.readFile(o).split(`
42
- `).map(u=>u.trim()).filter(u=>u&&!u.startsWith("#")),f=Vr(c);return jr(f,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}}});var qf,Kf=de(()=>{"use strict";qf={name:"sleep",description:"Delay execution",category:"system",params:["<seconds>"],run:async({args:n})=>{let t=parseFloat(n[0]??"1");return Number.isNaN(t)||t<0?{stderr:"sleep: invalid time",exitCode:1}:(await new Promise(e=>setTimeout(e,t*1e3)),{exitCode:0})}}});var Gf,Yf=de(()=>{"use strict";it();ct();Gf={name:"sort",description:"Sort lines of text",category:"text",params:["[-r] [-n] [-u] [-k <col>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=Ne(r,["-r"]),o=Ne(r,["-n"]),a=Ne(r,["-u"]),c=r.filter(_=>!_.startsWith("-")),h=[...(c.length>0?c.map(_=>{try{return De(n,le(e,_),"sort"),t.vfs.readFile(le(e,_))}catch{return""}}).join(`
43
- `):i??"").split(`
44
- `).filter(Boolean)].sort((_,y)=>o?Number(_)-Number(y):_.localeCompare(y)),d=s?h.reverse():h;return{stdout:(a?[...new Set(d)]:d).join(`
45
- `),exitCode:0}}}});var Vf,jf=de(()=>{"use strict";it();Vf={name:"su",description:"Switch user",category:"users",params:["- <username>"],run:({authUser:n,shell:t,args:e})=>{let r=t.users,i=Mt(e,0,{flags:["-"]});return i?!r.isSudoer(n)&&n!=="root"?{stderr:"su: permission denied",exitCode:1}:!r.verifyPassword(i,Mt(e,1)??"")&&n!=="root"?{stderr:"su: authentication failure",exitCode:1}:{switchUser:i,nextCwd:`/home/${i}`,exitCode:0}:{stderr:"su: missing username",exitCode:1}}}});function cp(n){let{flags:t,flagsWithValues:e,positionals:r}=hr(n,{flags:["-i","-S"],flagsWithValue:["-u","--user"]}),i=t.has("-i"),s=e.get("-u")||e.get("--user")||"root",o=r.length>0?r.join(" "):null;return{targetUser:s,loginShell:i,commandLine:o}}var zf,Xf=de(()=>{"use strict";it();pr();zf={name:"sudo",description:"Execute as superuser",category:"users",params:["<command...>"],run:async({authUser:n,hostname:t,mode:e,cwd:r,shell:i,args:s})=>{let{targetUser:o,loginShell:a,commandLine:c}=cp(s);if(n!=="root"&&!i.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let f=o||"root",u=`[sudo] password for ${n}: `;return n==="root"?!c&&a?{switchUser:f,nextCwd:`/home/${f}`,exitCode:0}:c?kt(c,f,t,e,a?`/home/${f}`:r,i):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:n,targetUser:f,commandLine:c,loginShell:a,prompt:u},exitCode:0}}}});var Jf,Zf=de(()=>{"use strict";it();ct();Jf={name:"tail",description:"Output last lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=$t(r,["-n"]),o=typeof s=="string"?parseInt(s,10):10,a=r.filter(u=>!u.startsWith("-")&&u!==s),c=u=>{let h=u.split(`
46
- `);return h.slice(Math.max(0,h.length-o)).join(`
47
- `)};if(a.length===0)return{stdout:c(i??""),exitCode:0};let f=[];for(let u of a){let h=le(e,u);try{De(n,h,"tail"),f.push(c(t.vfs.readFile(h)))}catch{return{stderr:`tail: ${u}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
48
- `),exitCode:0}}}});var eu,tu=de(()=>{"use strict";it();ct();eu={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=Ne(r,["-c"]),s=Ne(r,["-x"]),o=Ne(r,["-t"]),a=r.findIndex(u=>u.includes("f")),c=a!==-1?r[a+1]:r.find(u=>u.endsWith(".tar")||u.endsWith(".tar.gz")||u.endsWith(".tgz"));if(!c)return{stderr:"tar: no archive specified",exitCode:1};let f=le(e,c);if(i){let u=r.filter(d=>!d.startsWith("-")&&d!==c),h={};for(let d of u){let g=le(e,d);try{if(t.vfs.stat(g).type==="file")h[d]=t.vfs.readFile(g);else{let y=(x,I)=>{for(let O of t.vfs.list(x)){let $=`${x}/${O}`,L=`${I}/${O}`;t.vfs.stat($).type==="file"?h[L]=t.vfs.readFile($):y($,L)}};y(g,d)}}catch{return{stderr:`tar: ${d}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,f,JSON.stringify(h)),{exitCode:0}}if(o||s){let u;try{u=JSON.parse(t.vfs.readFile(f))}catch{return{stderr:`tar: ${c}: cannot open archive`,exitCode:1}}if(o)return{stdout:Object.keys(u).join(`
49
- `),exitCode:0};for(let[h,d]of Object.entries(u))t.writeFileAsUser(n,le(e,h),d);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}}});var ru,nu=de(()=>{"use strict";it();ct();ru={name:"tee",description:"Read stdin, write to stdout and files",category:"text",params:["[-a] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=Ne(r,["-a"]),o=r.filter(c=>!c.startsWith("-")),a=i??"";for(let c of o){let f=le(e,c);if(s){let u=(()=>{try{return t.vfs.readFile(f)}catch{return""}})();t.writeFileAsUser(n,f,u+a)}else t.writeFileAsUser(n,f,a)}return{stdout:a,exitCode:0}}}});var iu,su=de(()=>{"use strict";ct();iu={name:"touch",description:"Create or update files",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"touch: missing file operand",exitCode:1};for(let i of r){let s=le(e,i);De(n,s,"touch"),t.vfs.exists(s)||t.writeFileAsUser(n,s,"")}return{exitCode:0}}}});var ou,au=de(()=>{"use strict";it();ou={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=Ne(n,["-d"]),r=n.filter(a=>!a.startsWith("-")),i=r[0]??"",s=r[1]??"",o=t??"";if(e)for(let a of i)o=o.split(a).join("");else if(s)for(let a=0;a<i.length;a++)o=o.split(i[a]).join(s[a]??s[s.length-1]??"");return{stdout:o,exitCode:0}}}});var cu,fu=de(()=>{"use strict";it();ct();cu={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=le(e,Mt(r,0)??e);return De(n,i,"tree"),{stdout:t.vfs.tree(i),exitCode:0}}}});var uu,lu=de(()=>{"use strict";it();uu={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=Ne(t,["-a"]),r="Linux",i=n.properties?.kernel??"5.15.0",s=n.properties?.arch??"x86_64",o=n.hostname;return e?{stdout:`${r} ${o} ${i} #1 SMP ${s} GNU/Linux`,exitCode:0}:Ne(t,["-r"])?{stdout:i,exitCode:0}:Ne(t,["-m"])?{stdout:s,exitCode:0}:{stdout:r,exitCode:0}}}});var hu,du=de(()=>{"use strict";it();hu={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=Ne(n,["-c"]),r=Ne(n,["-d"]),i=Ne(n,["-u"]),s=(t??"").split(`
50
- `),o=[],a=0;for(;a<s.length;){let c=a;for(;c<s.length&&s[c]===s[a];)c++;let f=c-a,u=s[a];if(r&&f===1){a=c;continue}if(i&&f>1){a=c;continue}o.push(e?`${String(f).padStart(4)} ${u}`:u),a=c}return{stdout:o.join(`
51
- `),exitCode:0}}}});var pu,gu=de(()=>{"use strict";pu={name:"unset",description:"Remove shell variable",category:"shell",params:["<VAR>"],run:({args:n,env:t})=>{for(let e of n)delete t.vars[e];return{exitCode:0}}}});var mu,Au=de(()=>{"use strict";it();ct();mu={name:"wc",description:"Count words/lines/bytes",category:"text",params:["[-l] [-w] [-c] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=Ne(r,["-l"]),o=Ne(r,["-w"]),a=Ne(r,["-c"]),c=!s&&!o&&!a,f=r.filter(d=>!d.startsWith("-")),u=(d,g)=>{let _=d.split(`
52
- `).length-(d.endsWith(`
53
- `)?1:0),y=d.trim().split(/\s+/).filter(Boolean).length,x=Buffer.byteLength(d,"utf8"),I=[];return(c||s)&&I.push(String(_).padStart(7)),(c||o)&&I.push(String(y).padStart(7)),(c||a)&&I.push(String(x).padStart(7)),g&&I.push(` ${g}`),I.join("")};if(f.length===0)return{stdout:u(i??"",""),exitCode:0};let h=[];for(let d of f){let g=le(e,d);try{De(n,g,"wc");let _=t.vfs.readFile(g);h.push(u(_,d))}catch{return{stderr:`wc: ${d}: No such file or directory`,exitCode:1}}}return{stdout:h.join(`
54
- `),exitCode:0}}}});function fp(n){return new Promise(t=>{let e;try{e=(0,Eu.spawn)("wget",n,{stdio:["ignore","pipe","pipe"]})}catch(a){t({stdout:"",stderr:`wget: ${a instanceof Error?a.message:String(a)}`,exitCode:1});return}let r="",i="",s=e.stdout,o=e.stderr;if(!s||!o){t({stdout:"",stderr:"wget: failed to capture process output",exitCode:1});return}s.setEncoding("utf8"),o.setEncoding("utf8"),s.on("data",a=>{r+=a}),o.on("data",a=>{i+=a}),e.on("error",a=>{let c=a instanceof Error&&"code"in a?String(a.code??""):"";t({stdout:"",stderr:`wget: ${a.message}`,exitCode:c==="ENOENT"?127:1})}),e.on("close",a=>{t({stdout:r,stderr:i,exitCode:a??1})})})}var Eu,hn,_u,Ds,yu,bu=de(()=>{"use strict";Eu=require("node:child_process"),hn=require("node:fs/promises"),_u=require("node:os"),Ds=require("node:path");it();ct();yu={name:"wget",description:"File downloader",category:"network",params:["[url]"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:i,positionals:s}=hr(e,{flagsWithValue:["-o","-O","--output","--output-document"]}),o=i.get("-o")||i.get("-O")||i.get("--output")||i.get("--output-document")||null,a=s[0];if(!a)return{stderr:"wget: missing URL",exitCode:1};if(Ne(e,["-h","--help","-V","--version"])){let h=await fp(e);return{stdout:Rr(h.stdout),stderr:h.stderr?Rr(h.stderr):void 0,exitCode:h.exitCode}}let f=await(0,hn.mkdtemp)((0,Ds.join)((0,_u.tmpdir)(),"virtual-env-js-wget-")),u=(0,Ds.join)(f,"download");try{let h=[...s,"-O",u],d=await Bi("wget",h);if(d.exitCode!==0)return{stderr:Rr(d.stderr||`wget: exited with code ${d.exitCode}`),exitCode:d.exitCode};let g=await(0,hn.readFile)(u,"utf8"),_=le(t,o||tc(a));return De(n,_,"wget"),r.writeFileAsUser(n,_,g),{stdout:`saved ${_}`,exitCode:0}}finally{await(0,hn.rm)(f,{recursive:!0,force:!0})}}}});function Ri(n){let t=n.toLocaleString("en-US",{weekday:"short"}),e=n.toLocaleString("en-US",{month:"short"}),r=n.getDate().toString().padStart(2,"0"),i=n.getHours().toString().padStart(2,"0"),s=n.getMinutes().toString().padStart(2,"0"),o=n.getSeconds().toString().padStart(2,"0"),a=n.getFullYear();return`${t} ${e} ${r} ${i}:${s}:${o} ${a}`}var Hs=de(()=>{"use strict"});var xu,Su=de(()=>{"use strict";Hs();xu={name:"who",description:"Show active sessions",category:"system",params:[],run:({shell:n})=>({stdout:n.users.listActiveSessions().map(e=>{let r=new Date(e.startedAt),i=Number.isNaN(r.getTime())?e.startedAt:Ri(r);return`${e.username} ${e.tty} ${i} (${e.remoteAddress||"unknown"})`}).join(`
55
- `),exitCode:0})}});var wu,Iu=de(()=>{"use strict";wu={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})}});var Cu,Bu=de(()=>{"use strict";pr();Cu={name:"xargs",description:"Build and execute command lines from stdin",category:"text",params:["[command] [args...]"],run:async({authUser:n,hostname:t,mode:e,cwd:r,args:i,stdin:s,shell:o,env:a})=>{let c=i[0]??"echo",f=i.slice(1),u=(s??"").trim().split(/\s+/).filter(Boolean);if(u.length===0)return{exitCode:0};let h=[c,...f,...u].join(" ");return kt(h,n,t,e,r,o,void 0,a)}}});var ku={};qa(ku,{expandGlob:()=>dp,expandToken:()=>hp,parseScript:()=>up,parseShellPipeline:()=>lp});function up(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:gp(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function lp(n){let t=n.trim();if(!t)return{commands:[],isValid:!0};try{return{commands:vu(t),isValid:!0}}catch(e){return{commands:[],isValid:!1,error:e.message}}}function hp(n,t,e,r=0){return n=n.replace(/^~(\/|$)/,`/home/${e}$1`),n=n.replace(/\$\?/g,String(r)),n=n.replace(/\$\$/g,"1"),n=n.replace(/\$#/g,"0"),n=n.replace(/\$\{([^}:]+):-([^}]*)\}/g,(i,s,o)=>t[s]??o),n=n.replace(/\$\{([^}:]+):\+([^}]*)\}/g,(i,s,o)=>t[s]?o:""),n=n.replace(/\$\{([^}]+)\}/g,(i,s)=>t[s]??""),n=n.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g,(i,s)=>t[s]??""),n}function dp(n,t){if(!/[*?[]/.test(n))return[n];let e=pp(n),r=t.filter(i=>e.test(i));return r.length>0?r.sort():[n]}function pp(n){let t="^";for(let e=0;e<n.length;e++){let r=n[e];if(r==="*")t+=".*";else if(r==="?")t+=".";else if(r==="["){let i=n.indexOf("]",e+1);i===-1?t+="\\[":(t+=`[${n.slice(e+1,i)}]`,e=i)}else t+=r.replace(/[.+^${}()|[\]\\]/g,"\\$&")}return new RegExp(`${t}$`)}function gp(n){let t=mp(n),e=[];for(let r of t){let s={pipeline:{commands:vu(r.text.trim()),isValid:!0}};r.op&&(s.op=r.op),e.push(s)}return e}function mp(n){let t=[],e="",r=0,i=!1,s="",o=0,a=c=>{e.trim()&&t.push({text:e,op:c}),e=""};for(;o<n.length;){let c=n[o],f=n.slice(o,o+2);if((c==='"'||c==="'")&&!i){i=!0,s=c,e+=c,o++;continue}if(i&&c===s){i=!1,e+=c,o++;continue}if(i){e+=c,o++;continue}if(c==="("){r++,e+=c,o++;continue}if(c===")"){r--,e+=c,o++;continue}if(r>0){e+=c,o++;continue}if(f==="&&"){a("&&"),o+=2;continue}if(f==="||"){a("||"),o+=2;continue}if(c===";"){a(";"),o++;continue}e+=c,o++}return a(),t}function vu(n){return Ap(n).map(Ep)}function Ap(n){let t=[],e="",r=!1,i="";for(let o=0;o<n.length;o++){let a=n[o];if((a==='"'||a==="'")&&!r){r=!0,i=a,e+=a;continue}if(r&&a===i){r=!1,e+=a;continue}if(r){e+=a;continue}if(a==="|"&&n[o+1]!=="|"){if(!e.trim())throw new Error("Syntax error near unexpected token '|'");t.push(e.trim()),e=""}else e+=a}let s=e.trim();if(!s&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return s&&t.push(s),t}function Ep(n){let t=_p(n);if(t.length===0)return{name:"",args:[]};let e=[],r,i,s=!1,o=0;for(;o<t.length;){let c=t[o];if(c==="<"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after <");r=t[o],o++}else if(c===">>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >>");i=t[o],s=!0,o++}else if(c===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");i=t[o],s=!1,o++}else e.push(c),o++}return{name:(e[0]??"").toLowerCase(),args:e.slice(1),inputFile:r,outputFile:i,appendOutput:s}}function _p(n){let t=[],e="",r=!1,i="",s=0;for(;s<n.length;){let o=n[s],a=n[s+1];if((o==='"'||o==="'")&&!r){r=!0,i=o,s++;continue}if(r&&o===i){r=!1,i="",s++;continue}if(r){e+=o,s++;continue}if(o===" "){e&&(t.push(e),e=""),s++;continue}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),s+=2):(t.push(o),s++);continue}e+=o,s++}return e&&t.push(e),t}var Ru=de(()=>{"use strict"});var Nu={};qa(Nu,{executePipeline:()=>Ms,executeScript:()=>yp,executeStatements:()=>bp});async function yp(n,t,e,r,i,s,o){if(!n.isValid)return{stderr:n.error||"Syntax error",exitCode:1};let a={exitCode:0};for(let c of n.statements)if(a=await Ms(c.pipeline,t,e,r,i,s,o),o.lastExitCode=a.exitCode??0,a.closeSession||a.switchUser||a.nextCwd)break;return a}async function bp(n,t,e,r,i,s,o){let a={exitCode:0},c=0;for(;c<n.length;){let f=n[c];if(a=await Ms(f.pipeline,t,e,r,i,s,o),o.lastExitCode=a.exitCode??0,a.closeSession||a.switchUser)return a;let u=f.op;if(!(!u||u===";")){if(u==="&&"){if((a.exitCode??0)!==0)for(;c<n.length&&n[c]?.op==="&&";)c++}else if(u==="||"&&(a.exitCode??0)===0)for(;c<n.length&&n[c]?.op==="||";)c++}c++}return a}async function Ms(n,t,e,r,i,s,o){if(!n.isValid)return{stderr:n.error||"Syntax error",exitCode:1};if(n.commands.length===0)return{exitCode:0};let a=o??{vars:{},lastExitCode:0};return n.commands.length===1?xp(n.commands[0],t,e,r,i,s,a):Sp(n.commands,t,e,r,i,s,a)}async function xp(n,t,e,r,i,s,o){let a;if(n.inputFile){let u=le(i,n.inputFile);try{a=s.vfs.readFile(u)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let c=[n.name,...n.args].join(" "),f=await kt(c,t,e,r,i,s,a,o);if(n.outputFile){let u=le(i,n.outputFile),h=f.stdout||"";try{if(n.appendOutput){let d=(()=>{try{return s.vfs.readFile(u)}catch{return""}})();s.writeFileAsUser(t,u,d+h)}else s.writeFileAsUser(t,u,h);return{...f,stdout:""}}catch{return{...f,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return f}async function Sp(n,t,e,r,i,s,o){let a="",c=0;for(let f=0;f<n.length;f++){let u=n[f];if(f===0&&u.inputFile){let g=le(i,u.inputFile);try{a=s.vfs.readFile(g)}catch{return{stderr:`${u.inputFile}: No such file or directory`,exitCode:1}}}let h=[u.name,...u.args].join(" "),d=await kt(h,t,e,r,i,s,a,o);if(c=d.exitCode??0,f===n.length-1&&u.outputFile){let g=le(i,u.outputFile),_=d.stdout||"";try{if(u.appendOutput){let y=(()=>{try{return s.vfs.readFile(g)}catch{return""}})();s.writeFileAsUser(t,g,y+_)}else s.writeFileAsUser(t,g,_);a=""}catch{return{stderr:`Failed to write to ${u.outputFile}`,exitCode:1}}}else a=d.stdout||"";if(d.stderr&&c!==0)return{stderr:d.stderr,exitCode:c};if(d.closeSession||d.switchUser)return d}return{stdout:a,exitCode:c}}var Pu=de(()=>{"use strict";pr();ct()});function Fs(){Wn.clear();for(let n of Qs()){Wn.set(n.name,n);for(let t of n.aliases??[])Wn.set(t,n)}Ni=Array.from(Wn.keys()).sort()}function Qs(){return[...wp,...Tu,Ip]}function Lu(n){let t={...n,name:n.name.trim().toLowerCase(),aliases:n.aliases?.map(r=>r.trim().toLowerCase())};if([t.name,...t.aliases??[]].some(r=>r.length===0||/\s/.test(r)))throw new Error("Command names must be non-empty and contain no spaces");Tu.push(t),Fs()}function Uu(n,t,e){return{name:n,params:t,run:e}}function Ou(){return Ni||Fs(),Ni}function Jc(){return Qs()}function Cp(n){return Ni||Fs(),Wn.get(n.toLowerCase())}function Bp(n){let t=[],e="",r=!1,i="";for(let s=0;s<n.length;s++){let o=n[s]||"",a=s>0?n[s-1]:"";if((o==='"'||o==="'")&&a!=="\\"){if(!r){r=!0,i=o;continue}if(o===i){r=!1,i="";continue}}if(/\s/.test(o)&&!r){e.length>0&&(t.push(e),e="");continue}e+=o}return e.length>0&&t.push(e),t}function vp(n){let t=Bp(n.trim());return{commandName:t[0]?.toLowerCase()??"",args:t.slice(1)}}function qn(n,t){return{vars:{PATH:"/usr/local/bin:/usr/bin:/bin",HOME:`/home/${n}`,USER:n,LOGNAME:n,SHELL:"/bin/sh",TERM:"xterm-256color",HOSTNAME:t,PS1:"\\u@\\h:\\w\\$ "},lastExitCode:0}}async function kt(n,t,e,r,i,s,o,a){let c=n.trim();if(c.length===0)return{exitCode:0};let f=a??qn(t,e);if(/(?<![|&])[|](?![|])/.test(c)||c.includes(">")||c.includes("<")||c.includes("&&")||c.includes("||")||c.includes(";")){let{parseScript:g}=await Promise.resolve().then(()=>(Ru(),ku)),{executeStatements:_}=await Promise.resolve().then(()=>(Pu(),Nu)),y=g(c);if(!y.isValid)return{stderr:y.error||"Syntax error",exitCode:1};try{return await _(y.statements,t,e,r,i,s,f)}catch(x){return{stderr:x instanceof Error?x.message:"Execution failed",exitCode:1}}}let{commandName:u,args:h}=vp(c),d=Cp(u);if(!d)return{stderr:`${u}: command not found`,exitCode:127};try{return await d.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:c,mode:r,args:h,stdin:o,cwd:i,shell:s,env:f})}catch(g){return{stderr:g instanceof Error?g.message:"Command failed",exitCode:1}}}var wp,Tu,Wn,Ni,Ip,pr=de(()=>{"use strict";Va();Xa();Za();sc();ac();fc();lc();dc();gc();Ac();_c();bc();Sc();Ic();Bc();Rc();Pc();Lc();Oc();Hc();Fc();$c();Kc();Yc();Xc();ef();rf();sf();af();ff();lf();df();gf();Ef();kf();Nf();Tf();Uf();Df();Mf();Qf();ki();Wf();Kf();Yf();jf();Xf();Zf();tu();nu();su();au();fu();lu();du();gu();Au();bu();Su();Iu();Bu();wp=[Of,oc,uf,cu,ic,iu,Hf,hf,hc,pf,cf,cc,Dc,Mc,Ff,za,Gf,hu,mu,Gc,Jf,mc,ou,ru,Cu,wc,eu,Wc,qc,Ja,wu,xu,Zc,nf,Qc,uu,Lf,of,xc,Cc,Ec,qf,Pf,kc,Nc,Uc,vc,pu,$f,uc,Tc,Af,tf,pc,yu,Ya,Rf,yc,zf,Vf,vf],Tu=[],Wn=new Map,Ni=null,Ip=zc(()=>Qs().map(n=>n.name))});var Pi=ot((pb,Du)=>{Du.exports={newInvalidAsn1Error:function(n){var t=new Error;return t.name="InvalidAsn1Error",t.message=n||"",t}}});var Ti=ot((gb,Hu)=>{Hu.exports={EOC:0,Boolean:1,Integer:2,BitString:3,OctetString:4,Null:5,OID:6,ObjectDescriptor:7,External:8,Real:9,Enumeration:10,PDV:11,Utf8String:12,RelativeOID:13,Sequence:16,Set:17,NumericString:18,PrintableString:19,T61String:20,VideotexString:21,IA5String:22,UTCTime:23,GeneralizedTime:24,GraphicString:25,VisibleString:26,GeneralString:28,UniversalString:29,CharacterString:30,BMPString:31,Constructor:32,Context:128}});var $s=ot((mb,Mu)=>{"use strict";var Li=require("buffer"),dn=Li.Buffer,rr={},nr;for(nr in Li)Li.hasOwnProperty(nr)&&(nr==="SlowBuffer"||nr==="Buffer"||(rr[nr]=Li[nr]));var pn=rr.Buffer={};for(nr in dn)dn.hasOwnProperty(nr)&&(nr==="allocUnsafe"||nr==="allocUnsafeSlow"||(pn[nr]=dn[nr]));rr.Buffer.prototype=dn.prototype;(!pn.from||pn.from===Uint8Array.from)&&(pn.from=function(n,t,e){if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type '+typeof n);if(n&&typeof n.length>"u")throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);return dn(n,t,e)});pn.alloc||(pn.alloc=function(n,t,e){if(typeof n!="number")throw new TypeError('The "size" argument must be of type number. Received type '+typeof n);if(n<0||n>=2*(1<<30))throw new RangeError('The value "'+n+'" is invalid for option "size"');var r=dn(n);return!t||t.length===0?r.fill(0):typeof e=="string"?r.fill(t,e):r.fill(t),r});if(!rr.kStringMaxLength)try{rr.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}rr.constants||(rr.constants={MAX_LENGTH:rr.kMaxLength},rr.kStringMaxLength&&(rr.constants.MAX_STRING_LENGTH=rr.kStringMaxLength));Mu.exports=rr});var $u=ot((Ab,Qu)=>{var kp=require("assert"),Fu=$s().Buffer,Kn=Ti(),Rp=Pi(),gn=Rp.newInvalidAsn1Error;function Wt(n){if(!n||!Fu.isBuffer(n))throw new TypeError("data must be a node Buffer");this._buf=n,this._size=n.length,this._len=0,this._offset=0}Object.defineProperty(Wt.prototype,"length",{enumerable:!0,get:function(){return this._len}});Object.defineProperty(Wt.prototype,"offset",{enumerable:!0,get:function(){return this._offset}});Object.defineProperty(Wt.prototype,"remain",{get:function(){return this._size-this._offset}});Object.defineProperty(Wt.prototype,"buffer",{get:function(){return this._buf.slice(this._offset)}});Wt.prototype.readByte=function(n){if(this._size-this._offset<1)return null;var t=this._buf[this._offset]&255;return n||(this._offset+=1),t};Wt.prototype.peek=function(){return this.readByte(!0)};Wt.prototype.readLength=function(n){if(n===void 0&&(n=this._offset),n>=this._size)return null;var t=this._buf[n++]&255;if(t===null)return null;if((t&128)===128){if(t&=127,t===0)throw gn("Indefinite length not supported");if(t>4)throw gn("encoding too long");if(this._size-n<t)return null;this._len=0;for(var e=0;e<t;e++)this._len=(this._len<<8)+(this._buf[n++]&255)}else this._len=t;return n};Wt.prototype.readSequence=function(n){var t=this.peek();if(t===null)return null;if(n!==void 0&&n!==t)throw gn("Expected 0x"+n.toString(16)+": got 0x"+t.toString(16));var e=this.readLength(this._offset+1);return e===null?null:(this._offset=e,t)};Wt.prototype.readInt=function(){return this._readTag(Kn.Integer)};Wt.prototype.readBoolean=function(){return this._readTag(Kn.Boolean)!==0};Wt.prototype.readEnumeration=function(){return this._readTag(Kn.Enumeration)};Wt.prototype.readString=function(n,t){n||(n=Kn.OctetString);var e=this.peek();if(e===null)return null;if(e!==n)throw gn("Expected 0x"+n.toString(16)+": got 0x"+e.toString(16));var r=this.readLength(this._offset+1);if(r===null||this.length>this._size-r)return null;if(this._offset=r,this.length===0)return t?Fu.alloc(0):"";var i=this._buf.slice(this._offset,this._offset+this.length);return this._offset+=this.length,t?i:i.toString("utf8")};Wt.prototype.readOID=function(n){n||(n=Kn.OID);var t=this.readString(n,!0);if(t===null)return null;for(var e=[],r=0,i=0;i<t.length;i++){var s=t[i]&255;r<<=7,r+=s&127,(s&128)===0&&(e.push(r),r=0)}return r=e.shift(),e.unshift(r%40),e.unshift(r/40>>0),e.join(".")};Wt.prototype._readTag=function(n){kp.ok(n!==void 0);var t=this.peek();if(t===null)return null;if(t!==n)throw gn("Expected 0x"+n.toString(16)+": got 0x"+t.toString(16));var e=this.readLength(this._offset+1);if(e===null)return null;if(this.length>4)throw gn("Integer too long: "+this.length);if(this.length>this._size-e)return null;this._offset=e;for(var r=this._buf[this._offset],i=0,s=0;s<this.length;s++)i<<=8,i|=this._buf[this._offset++]&255;return(r&128)===128&&s!==4&&(i-=1<<s*8),i>>0};Qu.exports=Wt});var qu=ot((Eb,Wu)=>{var Nr=require("assert"),Ui=$s().Buffer,Pr=Ti(),Np=Pi(),Oi=Np.newInvalidAsn1Error,Pp={size:1024,growthFactor:8};function Tp(n,t){Nr.ok(n),Nr.equal(typeof n,"object"),Nr.ok(t),Nr.equal(typeof t,"object");var e=Object.getOwnPropertyNames(n);return e.forEach(function(r){if(!t[r]){var i=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(t,r,i)}}),t}function Ft(n){n=Tp(Pp,n||{}),this._buf=Ui.alloc(n.size||1024),this._size=this._buf.length,this._offset=0,this._options=n,this._seq=[]}Object.defineProperty(Ft.prototype,"buffer",{get:function(){if(this._seq.length)throw Oi(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});Ft.prototype.writeByte=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=n};Ft.prototype.writeInt=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Pr.Integer);for(var e=4;((n&4286578688)===0||(n&4286578688)===-8388608)&&e>1;)e--,n<<=8;if(e>4)throw Oi("BER ints cannot be > 0xffffffff");for(this._ensure(2+e),this._buf[this._offset++]=t,this._buf[this._offset++]=e;e-- >0;)this._buf[this._offset++]=(n&4278190080)>>>24,n<<=8};Ft.prototype.writeNull=function(){this.writeByte(Pr.Null),this.writeByte(0)};Ft.prototype.writeEnumeration=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Pr.Enumeration),this.writeInt(n,t)};Ft.prototype.writeBoolean=function(n,t){if(typeof n!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Pr.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=n?255:0};Ft.prototype.writeString=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string (was: "+typeof n+")");typeof t!="number"&&(t=Pr.OctetString);var e=Ui.byteLength(n);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(n,this._offset),this._offset+=e)};Ft.prototype.writeBuffer=function(n,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!Ui.isBuffer(n))throw new TypeError("argument must be a buffer");this.writeByte(t),this.writeLength(n.length),this._ensure(n.length),n.copy(this._buf,this._offset,0,n.length),this._offset+=n.length};Ft.prototype.writeStringArray=function(n){if(!n instanceof Array)throw new TypeError("argument must be an Array[String]");var t=this;n.forEach(function(e){t.writeString(e)})};Ft.prototype.writeOID=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Pr.OID),!/^([0-9]+\.){3,}[0-9]+$/.test(n))throw new Error("argument is not a valid OID string");function e(o,a){a<128?o.push(a):a<16384?(o.push(a>>>7|128),o.push(a&127)):a<2097152?(o.push(a>>>14|128),o.push((a>>>7|128)&255),o.push(a&127)):a<268435456?(o.push(a>>>21|128),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127)):(o.push((a>>>28|128)&255),o.push((a>>>21|128)&255),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127))}var r=n.split("."),i=[];i.push(parseInt(r[0],10)*40+parseInt(r[1],10)),r.slice(2).forEach(function(o){e(i,parseInt(o,10))});var s=this;this._ensure(2+i.length),this.writeByte(t),this.writeLength(i.length),i.forEach(function(o){s.writeByte(o)})};Ft.prototype.writeLength=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");if(this._ensure(4),n<=127)this._buf[this._offset++]=n;else if(n<=255)this._buf[this._offset++]=129,this._buf[this._offset++]=n;else if(n<=65535)this._buf[this._offset++]=130,this._buf[this._offset++]=n>>8,this._buf[this._offset++]=n;else if(n<=16777215)this._buf[this._offset++]=131,this._buf[this._offset++]=n>>16,this._buf[this._offset++]=n>>8,this._buf[this._offset++]=n;else throw Oi("Length too long (> 4 bytes)")};Ft.prototype.startSequence=function(n){typeof n!="number"&&(n=Pr.Sequence|Pr.Constructor),this.writeByte(n),this._seq.push(this._offset),this._ensure(3),this._offset+=3};Ft.prototype.endSequence=function(){var n=this._seq.pop(),t=n+3,e=this._offset-t;if(e<=127)this._shift(t,e,-2),this._buf[n]=e;else if(e<=255)this._shift(t,e,-1),this._buf[n]=129,this._buf[n+1]=e;else if(e<=65535)this._buf[n]=130,this._buf[n+1]=e>>8,this._buf[n+2]=e;else if(e<=16777215)this._shift(t,e,1),this._buf[n]=131,this._buf[n+1]=e>>16,this._buf[n+2]=e>>8,this._buf[n+3]=e;else throw Oi("Sequence too long")};Ft.prototype._shift=function(n,t,e){Nr.ok(n!==void 0),Nr.ok(t!==void 0),Nr.ok(e),this._buf.copy(this._buf,n+e,n,n+t),this._offset+=e};Ft.prototype._ensure=function(n){if(Nr.ok(n),this._size-this._offset<n){var t=this._size*this._options.growthFactor;t-this._offset<n&&(t+=n);var e=Ui.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};Wu.exports=Ft});var Ku=ot((_b,Mi)=>{var Ws=Pi(),qs=Ti(),Lp=$u(),Up=qu();Mi.exports={Reader:Lp,Writer:Up};for(Di in qs)qs.hasOwnProperty(Di)&&(Mi.exports[Di]=qs[Di]);var Di;for(Hi in Ws)Ws.hasOwnProperty(Hi)&&(Mi.exports[Hi]=Ws[Hi]);var Hi});var Gn=ot((yb,Gu)=>{var Ks=Ku();Gu.exports={Ber:Ks,BerReader:Ks.Reader,BerWriter:Ks.Writer}});var Yu=ot((bb,Fi)=>{(function(n){"use strict";var t=function(p){var A,m=new Float64Array(16);if(p)for(A=0;A<p.length;A++)m[A]=p[A];return m},e=function(){throw new Error("no PRNG")},r=new Uint8Array(16),i=new Uint8Array(32);i[0]=9;var s=t(),o=t([1]),a=t([56129,1]),c=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),f=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),u=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),h=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),d=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function g(p,A,m,l){p[A]=m>>24&255,p[A+1]=m>>16&255,p[A+2]=m>>8&255,p[A+3]=m&255,p[A+4]=l>>24&255,p[A+5]=l>>16&255,p[A+6]=l>>8&255,p[A+7]=l&255}function _(p,A,m,l,E){var k,P=0;for(k=0;k<E;k++)P|=p[A+k]^m[l+k];return(1&P-1>>>8)-1}function y(p,A,m,l){return _(p,A,m,l,16)}function x(p,A,m,l){return _(p,A,m,l,32)}function I(p,A,m,l){for(var E=l[0]&255|(l[1]&255)<<8|(l[2]&255)<<16|(l[3]&255)<<24,k=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,P=m[4]&255|(m[5]&255)<<8|(m[6]&255)<<16|(m[7]&255)<<24,Y=m[8]&255|(m[9]&255)<<8|(m[10]&255)<<16|(m[11]&255)<<24,ie=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,ge=l[4]&255|(l[5]&255)<<8|(l[6]&255)<<16|(l[7]&255)<<24,ue=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,et=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,pe=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Re=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Pe=l[8]&255|(l[9]&255)<<8|(l[10]&255)<<16|(l[11]&255)<<24,Me=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,Oe=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,Te=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Ue=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,Le=l[12]&255|(l[13]&255)<<8|(l[14]&255)<<16|(l[15]&255)<<24,me=E,_e=k,he=P,Ae=Y,Ee=ie,fe=ge,H=ue,M=et,X=pe,K=Re,V=Pe,ne=Me,we=Oe,Fe=Te,$e=Ue,Qe=Le,b,qe=0;qe<20;qe+=2)b=me+we|0,Ee^=b<<7|b>>>25,b=Ee+me|0,X^=b<<9|b>>>23,b=X+Ee|0,we^=b<<13|b>>>19,b=we+X|0,me^=b<<18|b>>>14,b=fe+_e|0,K^=b<<7|b>>>25,b=K+fe|0,Fe^=b<<9|b>>>23,b=Fe+K|0,_e^=b<<13|b>>>19,b=_e+Fe|0,fe^=b<<18|b>>>14,b=V+H|0,$e^=b<<7|b>>>25,b=$e+V|0,he^=b<<9|b>>>23,b=he+$e|0,H^=b<<13|b>>>19,b=H+he|0,V^=b<<18|b>>>14,b=Qe+ne|0,Ae^=b<<7|b>>>25,b=Ae+Qe|0,M^=b<<9|b>>>23,b=M+Ae|0,ne^=b<<13|b>>>19,b=ne+M|0,Qe^=b<<18|b>>>14,b=me+Ae|0,_e^=b<<7|b>>>25,b=_e+me|0,he^=b<<9|b>>>23,b=he+_e|0,Ae^=b<<13|b>>>19,b=Ae+he|0,me^=b<<18|b>>>14,b=fe+Ee|0,H^=b<<7|b>>>25,b=H+fe|0,M^=b<<9|b>>>23,b=M+H|0,Ee^=b<<13|b>>>19,b=Ee+M|0,fe^=b<<18|b>>>14,b=V+K|0,ne^=b<<7|b>>>25,b=ne+V|0,X^=b<<9|b>>>23,b=X+ne|0,K^=b<<13|b>>>19,b=K+X|0,V^=b<<18|b>>>14,b=Qe+$e|0,we^=b<<7|b>>>25,b=we+Qe|0,Fe^=b<<9|b>>>23,b=Fe+we|0,$e^=b<<13|b>>>19,b=$e+Fe|0,Qe^=b<<18|b>>>14;me=me+E|0,_e=_e+k|0,he=he+P|0,Ae=Ae+Y|0,Ee=Ee+ie|0,fe=fe+ge|0,H=H+ue|0,M=M+et|0,X=X+pe|0,K=K+Re|0,V=V+Pe|0,ne=ne+Me|0,we=we+Oe|0,Fe=Fe+Te|0,$e=$e+Ue|0,Qe=Qe+Le|0,p[0]=me>>>0&255,p[1]=me>>>8&255,p[2]=me>>>16&255,p[3]=me>>>24&255,p[4]=_e>>>0&255,p[5]=_e>>>8&255,p[6]=_e>>>16&255,p[7]=_e>>>24&255,p[8]=he>>>0&255,p[9]=he>>>8&255,p[10]=he>>>16&255,p[11]=he>>>24&255,p[12]=Ae>>>0&255,p[13]=Ae>>>8&255,p[14]=Ae>>>16&255,p[15]=Ae>>>24&255,p[16]=Ee>>>0&255,p[17]=Ee>>>8&255,p[18]=Ee>>>16&255,p[19]=Ee>>>24&255,p[20]=fe>>>0&255,p[21]=fe>>>8&255,p[22]=fe>>>16&255,p[23]=fe>>>24&255,p[24]=H>>>0&255,p[25]=H>>>8&255,p[26]=H>>>16&255,p[27]=H>>>24&255,p[28]=M>>>0&255,p[29]=M>>>8&255,p[30]=M>>>16&255,p[31]=M>>>24&255,p[32]=X>>>0&255,p[33]=X>>>8&255,p[34]=X>>>16&255,p[35]=X>>>24&255,p[36]=K>>>0&255,p[37]=K>>>8&255,p[38]=K>>>16&255,p[39]=K>>>24&255,p[40]=V>>>0&255,p[41]=V>>>8&255,p[42]=V>>>16&255,p[43]=V>>>24&255,p[44]=ne>>>0&255,p[45]=ne>>>8&255,p[46]=ne>>>16&255,p[47]=ne>>>24&255,p[48]=we>>>0&255,p[49]=we>>>8&255,p[50]=we>>>16&255,p[51]=we>>>24&255,p[52]=Fe>>>0&255,p[53]=Fe>>>8&255,p[54]=Fe>>>16&255,p[55]=Fe>>>24&255,p[56]=$e>>>0&255,p[57]=$e>>>8&255,p[58]=$e>>>16&255,p[59]=$e>>>24&255,p[60]=Qe>>>0&255,p[61]=Qe>>>8&255,p[62]=Qe>>>16&255,p[63]=Qe>>>24&255}function O(p,A,m,l){for(var E=l[0]&255|(l[1]&255)<<8|(l[2]&255)<<16|(l[3]&255)<<24,k=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,P=m[4]&255|(m[5]&255)<<8|(m[6]&255)<<16|(m[7]&255)<<24,Y=m[8]&255|(m[9]&255)<<8|(m[10]&255)<<16|(m[11]&255)<<24,ie=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,ge=l[4]&255|(l[5]&255)<<8|(l[6]&255)<<16|(l[7]&255)<<24,ue=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,et=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,pe=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Re=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Pe=l[8]&255|(l[9]&255)<<8|(l[10]&255)<<16|(l[11]&255)<<24,Me=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,Oe=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,Te=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Ue=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,Le=l[12]&255|(l[13]&255)<<8|(l[14]&255)<<16|(l[15]&255)<<24,me=E,_e=k,he=P,Ae=Y,Ee=ie,fe=ge,H=ue,M=et,X=pe,K=Re,V=Pe,ne=Me,we=Oe,Fe=Te,$e=Ue,Qe=Le,b,qe=0;qe<20;qe+=2)b=me+we|0,Ee^=b<<7|b>>>25,b=Ee+me|0,X^=b<<9|b>>>23,b=X+Ee|0,we^=b<<13|b>>>19,b=we+X|0,me^=b<<18|b>>>14,b=fe+_e|0,K^=b<<7|b>>>25,b=K+fe|0,Fe^=b<<9|b>>>23,b=Fe+K|0,_e^=b<<13|b>>>19,b=_e+Fe|0,fe^=b<<18|b>>>14,b=V+H|0,$e^=b<<7|b>>>25,b=$e+V|0,he^=b<<9|b>>>23,b=he+$e|0,H^=b<<13|b>>>19,b=H+he|0,V^=b<<18|b>>>14,b=Qe+ne|0,Ae^=b<<7|b>>>25,b=Ae+Qe|0,M^=b<<9|b>>>23,b=M+Ae|0,ne^=b<<13|b>>>19,b=ne+M|0,Qe^=b<<18|b>>>14,b=me+Ae|0,_e^=b<<7|b>>>25,b=_e+me|0,he^=b<<9|b>>>23,b=he+_e|0,Ae^=b<<13|b>>>19,b=Ae+he|0,me^=b<<18|b>>>14,b=fe+Ee|0,H^=b<<7|b>>>25,b=H+fe|0,M^=b<<9|b>>>23,b=M+H|0,Ee^=b<<13|b>>>19,b=Ee+M|0,fe^=b<<18|b>>>14,b=V+K|0,ne^=b<<7|b>>>25,b=ne+V|0,X^=b<<9|b>>>23,b=X+ne|0,K^=b<<13|b>>>19,b=K+X|0,V^=b<<18|b>>>14,b=Qe+$e|0,we^=b<<7|b>>>25,b=we+Qe|0,Fe^=b<<9|b>>>23,b=Fe+we|0,$e^=b<<13|b>>>19,b=$e+Fe|0,Qe^=b<<18|b>>>14;p[0]=me>>>0&255,p[1]=me>>>8&255,p[2]=me>>>16&255,p[3]=me>>>24&255,p[4]=fe>>>0&255,p[5]=fe>>>8&255,p[6]=fe>>>16&255,p[7]=fe>>>24&255,p[8]=V>>>0&255,p[9]=V>>>8&255,p[10]=V>>>16&255,p[11]=V>>>24&255,p[12]=Qe>>>0&255,p[13]=Qe>>>8&255,p[14]=Qe>>>16&255,p[15]=Qe>>>24&255,p[16]=H>>>0&255,p[17]=H>>>8&255,p[18]=H>>>16&255,p[19]=H>>>24&255,p[20]=M>>>0&255,p[21]=M>>>8&255,p[22]=M>>>16&255,p[23]=M>>>24&255,p[24]=X>>>0&255,p[25]=X>>>8&255,p[26]=X>>>16&255,p[27]=X>>>24&255,p[28]=K>>>0&255,p[29]=K>>>8&255,p[30]=K>>>16&255,p[31]=K>>>24&255}function $(p,A,m,l){I(p,A,m,l)}function L(p,A,m,l){O(p,A,m,l)}var j=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function J(p,A,m,l,E,k,P){var Y=new Uint8Array(16),ie=new Uint8Array(64),ge,ue;for(ue=0;ue<16;ue++)Y[ue]=0;for(ue=0;ue<8;ue++)Y[ue]=k[ue];for(;E>=64;){for($(ie,Y,P,j),ue=0;ue<64;ue++)p[A+ue]=m[l+ue]^ie[ue];for(ge=1,ue=8;ue<16;ue++)ge=ge+(Y[ue]&255)|0,Y[ue]=ge&255,ge>>>=8;E-=64,A+=64,l+=64}if(E>0)for($(ie,Y,P,j),ue=0;ue<E;ue++)p[A+ue]=m[l+ue]^ie[ue];return 0}function z(p,A,m,l,E){var k=new Uint8Array(16),P=new Uint8Array(64),Y,ie;for(ie=0;ie<16;ie++)k[ie]=0;for(ie=0;ie<8;ie++)k[ie]=l[ie];for(;m>=64;){for($(P,k,E,j),ie=0;ie<64;ie++)p[A+ie]=P[ie];for(Y=1,ie=8;ie<16;ie++)Y=Y+(k[ie]&255)|0,k[ie]=Y&255,Y>>>=8;m-=64,A+=64}if(m>0)for($(P,k,E,j),ie=0;ie<m;ie++)p[A+ie]=P[ie];return 0}function S(p,A,m,l,E){var k=new Uint8Array(32);L(k,l,E,j);for(var P=new Uint8Array(8),Y=0;Y<8;Y++)P[Y]=l[Y+16];return z(p,A,m,P,k)}function w(p,A,m,l,E,k,P){var Y=new Uint8Array(32);L(Y,k,P,j);for(var ie=new Uint8Array(8),ge=0;ge<8;ge++)ie[ge]=k[ge+16];return J(p,A,m,l,E,ie,Y)}var U=function(p){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var A,m,l,E,k,P,Y,ie;A=p[0]&255|(p[1]&255)<<8,this.r[0]=A&8191,m=p[2]&255|(p[3]&255)<<8,this.r[1]=(A>>>13|m<<3)&8191,l=p[4]&255|(p[5]&255)<<8,this.r[2]=(m>>>10|l<<6)&7939,E=p[6]&255|(p[7]&255)<<8,this.r[3]=(l>>>7|E<<9)&8191,k=p[8]&255|(p[9]&255)<<8,this.r[4]=(E>>>4|k<<12)&255,this.r[5]=k>>>1&8190,P=p[10]&255|(p[11]&255)<<8,this.r[6]=(k>>>14|P<<2)&8191,Y=p[12]&255|(p[13]&255)<<8,this.r[7]=(P>>>11|Y<<5)&8065,ie=p[14]&255|(p[15]&255)<<8,this.r[8]=(Y>>>8|ie<<8)&8191,this.r[9]=ie>>>5&127,this.pad[0]=p[16]&255|(p[17]&255)<<8,this.pad[1]=p[18]&255|(p[19]&255)<<8,this.pad[2]=p[20]&255|(p[21]&255)<<8,this.pad[3]=p[22]&255|(p[23]&255)<<8,this.pad[4]=p[24]&255|(p[25]&255)<<8,this.pad[5]=p[26]&255|(p[27]&255)<<8,this.pad[6]=p[28]&255|(p[29]&255)<<8,this.pad[7]=p[30]&255|(p[31]&255)<<8};U.prototype.blocks=function(p,A,m){for(var l=this.fin?0:2048,E,k,P,Y,ie,ge,ue,et,pe,Re,Pe,Me,Oe,Te,Ue,Le,me,_e,he,Ae=this.h[0],Ee=this.h[1],fe=this.h[2],H=this.h[3],M=this.h[4],X=this.h[5],K=this.h[6],V=this.h[7],ne=this.h[8],we=this.h[9],Fe=this.r[0],$e=this.r[1],Qe=this.r[2],b=this.r[3],qe=this.r[4],tt=this.r[5],rt=this.r[6],We=this.r[7],Xe=this.r[8],Je=this.r[9];m>=16;)E=p[A+0]&255|(p[A+1]&255)<<8,Ae+=E&8191,k=p[A+2]&255|(p[A+3]&255)<<8,Ee+=(E>>>13|k<<3)&8191,P=p[A+4]&255|(p[A+5]&255)<<8,fe+=(k>>>10|P<<6)&8191,Y=p[A+6]&255|(p[A+7]&255)<<8,H+=(P>>>7|Y<<9)&8191,ie=p[A+8]&255|(p[A+9]&255)<<8,M+=(Y>>>4|ie<<12)&8191,X+=ie>>>1&8191,ge=p[A+10]&255|(p[A+11]&255)<<8,K+=(ie>>>14|ge<<2)&8191,ue=p[A+12]&255|(p[A+13]&255)<<8,V+=(ge>>>11|ue<<5)&8191,et=p[A+14]&255|(p[A+15]&255)<<8,ne+=(ue>>>8|et<<8)&8191,we+=et>>>5|l,pe=0,Re=pe,Re+=Ae*Fe,Re+=Ee*(5*Je),Re+=fe*(5*Xe),Re+=H*(5*We),Re+=M*(5*rt),pe=Re>>>13,Re&=8191,Re+=X*(5*tt),Re+=K*(5*qe),Re+=V*(5*b),Re+=ne*(5*Qe),Re+=we*(5*$e),pe+=Re>>>13,Re&=8191,Pe=pe,Pe+=Ae*$e,Pe+=Ee*Fe,Pe+=fe*(5*Je),Pe+=H*(5*Xe),Pe+=M*(5*We),pe=Pe>>>13,Pe&=8191,Pe+=X*(5*rt),Pe+=K*(5*tt),Pe+=V*(5*qe),Pe+=ne*(5*b),Pe+=we*(5*Qe),pe+=Pe>>>13,Pe&=8191,Me=pe,Me+=Ae*Qe,Me+=Ee*$e,Me+=fe*Fe,Me+=H*(5*Je),Me+=M*(5*Xe),pe=Me>>>13,Me&=8191,Me+=X*(5*We),Me+=K*(5*rt),Me+=V*(5*tt),Me+=ne*(5*qe),Me+=we*(5*b),pe+=Me>>>13,Me&=8191,Oe=pe,Oe+=Ae*b,Oe+=Ee*Qe,Oe+=fe*$e,Oe+=H*Fe,Oe+=M*(5*Je),pe=Oe>>>13,Oe&=8191,Oe+=X*(5*Xe),Oe+=K*(5*We),Oe+=V*(5*rt),Oe+=ne*(5*tt),Oe+=we*(5*qe),pe+=Oe>>>13,Oe&=8191,Te=pe,Te+=Ae*qe,Te+=Ee*b,Te+=fe*Qe,Te+=H*$e,Te+=M*Fe,pe=Te>>>13,Te&=8191,Te+=X*(5*Je),Te+=K*(5*Xe),Te+=V*(5*We),Te+=ne*(5*rt),Te+=we*(5*tt),pe+=Te>>>13,Te&=8191,Ue=pe,Ue+=Ae*tt,Ue+=Ee*qe,Ue+=fe*b,Ue+=H*Qe,Ue+=M*$e,pe=Ue>>>13,Ue&=8191,Ue+=X*Fe,Ue+=K*(5*Je),Ue+=V*(5*Xe),Ue+=ne*(5*We),Ue+=we*(5*rt),pe+=Ue>>>13,Ue&=8191,Le=pe,Le+=Ae*rt,Le+=Ee*tt,Le+=fe*qe,Le+=H*b,Le+=M*Qe,pe=Le>>>13,Le&=8191,Le+=X*$e,Le+=K*Fe,Le+=V*(5*Je),Le+=ne*(5*Xe),Le+=we*(5*We),pe+=Le>>>13,Le&=8191,me=pe,me+=Ae*We,me+=Ee*rt,me+=fe*tt,me+=H*qe,me+=M*b,pe=me>>>13,me&=8191,me+=X*Qe,me+=K*$e,me+=V*Fe,me+=ne*(5*Je),me+=we*(5*Xe),pe+=me>>>13,me&=8191,_e=pe,_e+=Ae*Xe,_e+=Ee*We,_e+=fe*rt,_e+=H*tt,_e+=M*qe,pe=_e>>>13,_e&=8191,_e+=X*b,_e+=K*Qe,_e+=V*$e,_e+=ne*Fe,_e+=we*(5*Je),pe+=_e>>>13,_e&=8191,he=pe,he+=Ae*Je,he+=Ee*Xe,he+=fe*We,he+=H*rt,he+=M*tt,pe=he>>>13,he&=8191,he+=X*qe,he+=K*b,he+=V*Qe,he+=ne*$e,he+=we*Fe,pe+=he>>>13,he&=8191,pe=(pe<<2)+pe|0,pe=pe+Re|0,Re=pe&8191,pe=pe>>>13,Pe+=pe,Ae=Re,Ee=Pe,fe=Me,H=Oe,M=Te,X=Ue,K=Le,V=me,ne=_e,we=he,A+=16,m-=16;this.h[0]=Ae,this.h[1]=Ee,this.h[2]=fe,this.h[3]=H,this.h[4]=M,this.h[5]=X,this.h[6]=K,this.h[7]=V,this.h[8]=ne,this.h[9]=we},U.prototype.finish=function(p,A){var m=new Uint16Array(10),l,E,k,P;if(this.leftover){for(P=this.leftover,this.buffer[P++]=1;P<16;P++)this.buffer[P]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(l=this.h[1]>>>13,this.h[1]&=8191,P=2;P<10;P++)this.h[P]+=l,l=this.h[P]>>>13,this.h[P]&=8191;for(this.h[0]+=l*5,l=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=l,l=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=l,m[0]=this.h[0]+5,l=m[0]>>>13,m[0]&=8191,P=1;P<10;P++)m[P]=this.h[P]+l,l=m[P]>>>13,m[P]&=8191;for(m[9]-=8192,E=(l^1)-1,P=0;P<10;P++)m[P]&=E;for(E=~E,P=0;P<10;P++)this.h[P]=this.h[P]&E|m[P];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,k=this.h[0]+this.pad[0],this.h[0]=k&65535,P=1;P<8;P++)k=(this.h[P]+this.pad[P]|0)+(k>>>16)|0,this.h[P]=k&65535;p[A+0]=this.h[0]>>>0&255,p[A+1]=this.h[0]>>>8&255,p[A+2]=this.h[1]>>>0&255,p[A+3]=this.h[1]>>>8&255,p[A+4]=this.h[2]>>>0&255,p[A+5]=this.h[2]>>>8&255,p[A+6]=this.h[3]>>>0&255,p[A+7]=this.h[3]>>>8&255,p[A+8]=this.h[4]>>>0&255,p[A+9]=this.h[4]>>>8&255,p[A+10]=this.h[5]>>>0&255,p[A+11]=this.h[5]>>>8&255,p[A+12]=this.h[6]>>>0&255,p[A+13]=this.h[6]>>>8&255,p[A+14]=this.h[7]>>>0&255,p[A+15]=this.h[7]>>>8&255},U.prototype.update=function(p,A,m){var l,E;if(this.leftover){for(E=16-this.leftover,E>m&&(E=m),l=0;l<E;l++)this.buffer[this.leftover+l]=p[A+l];if(m-=E,A+=E,this.leftover+=E,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(m>=16&&(E=m-m%16,this.blocks(p,A,E),A+=E,m-=E),m){for(l=0;l<m;l++)this.buffer[this.leftover+l]=p[A+l];this.leftover+=m}};function W(p,A,m,l,E,k){var P=new U(k);return P.update(m,l,E),P.finish(p,A),0}function Q(p,A,m,l,E,k){var P=new Uint8Array(16);return W(P,0,m,l,E,k),y(p,A,P,0)}function oe(p,A,m,l,E){var k;if(m<32)return-1;for(w(p,0,A,0,m,l,E),W(p,16,p,32,m-32,p),k=0;k<16;k++)p[k]=0;return 0}function te(p,A,m,l,E){var k,P=new Uint8Array(32);if(m<32||(S(P,0,32,l,E),Q(A,16,A,32,m-32,P)!==0))return-1;for(w(p,0,A,0,m,l,E),k=0;k<32;k++)p[k]=0;return 0}function Z(p,A){var m;for(m=0;m<16;m++)p[m]=A[m]|0}function re(p){var A,m,l=1;for(A=0;A<16;A++)m=p[A]+l+65535,l=Math.floor(m/65536),p[A]=m-l*65536;p[0]+=l-1+37*(l-1)}function ae(p,A,m){for(var l,E=~(m-1),k=0;k<16;k++)l=E&(p[k]^A[k]),p[k]^=l,A[k]^=l}function T(p,A){var m,l,E,k=t(),P=t();for(m=0;m<16;m++)P[m]=A[m];for(re(P),re(P),re(P),l=0;l<2;l++){for(k[0]=P[0]-65517,m=1;m<15;m++)k[m]=P[m]-65535-(k[m-1]>>16&1),k[m-1]&=65535;k[15]=P[15]-32767-(k[14]>>16&1),E=k[15]>>16&1,k[14]&=65535,ae(P,k,1-E)}for(m=0;m<16;m++)p[2*m]=P[m]&255,p[2*m+1]=P[m]>>8}function C(p,A){var m=new Uint8Array(32),l=new Uint8Array(32);return T(m,p),T(l,A),x(m,0,l,0)}function v(p){var A=new Uint8Array(32);return T(A,p),A[0]&1}function D(p,A){var m;for(m=0;m<16;m++)p[m]=A[2*m]+(A[2*m+1]<<8);p[15]&=32767}function G(p,A,m){for(var l=0;l<16;l++)p[l]=A[l]+m[l]}function se(p,A,m){for(var l=0;l<16;l++)p[l]=A[l]-m[l]}function ee(p,A,m){var l,E,k=0,P=0,Y=0,ie=0,ge=0,ue=0,et=0,pe=0,Re=0,Pe=0,Me=0,Oe=0,Te=0,Ue=0,Le=0,me=0,_e=0,he=0,Ae=0,Ee=0,fe=0,H=0,M=0,X=0,K=0,V=0,ne=0,we=0,Fe=0,$e=0,Qe=0,b=m[0],qe=m[1],tt=m[2],rt=m[3],We=m[4],Xe=m[5],Je=m[6],St=m[7],at=m[8],yt=m[9],bt=m[10],xt=m[11],vt=m[12],Ot=m[13],Dt=m[14],Ht=m[15];l=A[0],k+=l*b,P+=l*qe,Y+=l*tt,ie+=l*rt,ge+=l*We,ue+=l*Xe,et+=l*Je,pe+=l*St,Re+=l*at,Pe+=l*yt,Me+=l*bt,Oe+=l*xt,Te+=l*vt,Ue+=l*Ot,Le+=l*Dt,me+=l*Ht,l=A[1],P+=l*b,Y+=l*qe,ie+=l*tt,ge+=l*rt,ue+=l*We,et+=l*Xe,pe+=l*Je,Re+=l*St,Pe+=l*at,Me+=l*yt,Oe+=l*bt,Te+=l*xt,Ue+=l*vt,Le+=l*Ot,me+=l*Dt,_e+=l*Ht,l=A[2],Y+=l*b,ie+=l*qe,ge+=l*tt,ue+=l*rt,et+=l*We,pe+=l*Xe,Re+=l*Je,Pe+=l*St,Me+=l*at,Oe+=l*yt,Te+=l*bt,Ue+=l*xt,Le+=l*vt,me+=l*Ot,_e+=l*Dt,he+=l*Ht,l=A[3],ie+=l*b,ge+=l*qe,ue+=l*tt,et+=l*rt,pe+=l*We,Re+=l*Xe,Pe+=l*Je,Me+=l*St,Oe+=l*at,Te+=l*yt,Ue+=l*bt,Le+=l*xt,me+=l*vt,_e+=l*Ot,he+=l*Dt,Ae+=l*Ht,l=A[4],ge+=l*b,ue+=l*qe,et+=l*tt,pe+=l*rt,Re+=l*We,Pe+=l*Xe,Me+=l*Je,Oe+=l*St,Te+=l*at,Ue+=l*yt,Le+=l*bt,me+=l*xt,_e+=l*vt,he+=l*Ot,Ae+=l*Dt,Ee+=l*Ht,l=A[5],ue+=l*b,et+=l*qe,pe+=l*tt,Re+=l*rt,Pe+=l*We,Me+=l*Xe,Oe+=l*Je,Te+=l*St,Ue+=l*at,Le+=l*yt,me+=l*bt,_e+=l*xt,he+=l*vt,Ae+=l*Ot,Ee+=l*Dt,fe+=l*Ht,l=A[6],et+=l*b,pe+=l*qe,Re+=l*tt,Pe+=l*rt,Me+=l*We,Oe+=l*Xe,Te+=l*Je,Ue+=l*St,Le+=l*at,me+=l*yt,_e+=l*bt,he+=l*xt,Ae+=l*vt,Ee+=l*Ot,fe+=l*Dt,H+=l*Ht,l=A[7],pe+=l*b,Re+=l*qe,Pe+=l*tt,Me+=l*rt,Oe+=l*We,Te+=l*Xe,Ue+=l*Je,Le+=l*St,me+=l*at,_e+=l*yt,he+=l*bt,Ae+=l*xt,Ee+=l*vt,fe+=l*Ot,H+=l*Dt,M+=l*Ht,l=A[8],Re+=l*b,Pe+=l*qe,Me+=l*tt,Oe+=l*rt,Te+=l*We,Ue+=l*Xe,Le+=l*Je,me+=l*St,_e+=l*at,he+=l*yt,Ae+=l*bt,Ee+=l*xt,fe+=l*vt,H+=l*Ot,M+=l*Dt,X+=l*Ht,l=A[9],Pe+=l*b,Me+=l*qe,Oe+=l*tt,Te+=l*rt,Ue+=l*We,Le+=l*Xe,me+=l*Je,_e+=l*St,he+=l*at,Ae+=l*yt,Ee+=l*bt,fe+=l*xt,H+=l*vt,M+=l*Ot,X+=l*Dt,K+=l*Ht,l=A[10],Me+=l*b,Oe+=l*qe,Te+=l*tt,Ue+=l*rt,Le+=l*We,me+=l*Xe,_e+=l*Je,he+=l*St,Ae+=l*at,Ee+=l*yt,fe+=l*bt,H+=l*xt,M+=l*vt,X+=l*Ot,K+=l*Dt,V+=l*Ht,l=A[11],Oe+=l*b,Te+=l*qe,Ue+=l*tt,Le+=l*rt,me+=l*We,_e+=l*Xe,he+=l*Je,Ae+=l*St,Ee+=l*at,fe+=l*yt,H+=l*bt,M+=l*xt,X+=l*vt,K+=l*Ot,V+=l*Dt,ne+=l*Ht,l=A[12],Te+=l*b,Ue+=l*qe,Le+=l*tt,me+=l*rt,_e+=l*We,he+=l*Xe,Ae+=l*Je,Ee+=l*St,fe+=l*at,H+=l*yt,M+=l*bt,X+=l*xt,K+=l*vt,V+=l*Ot,ne+=l*Dt,we+=l*Ht,l=A[13],Ue+=l*b,Le+=l*qe,me+=l*tt,_e+=l*rt,he+=l*We,Ae+=l*Xe,Ee+=l*Je,fe+=l*St,H+=l*at,M+=l*yt,X+=l*bt,K+=l*xt,V+=l*vt,ne+=l*Ot,we+=l*Dt,Fe+=l*Ht,l=A[14],Le+=l*b,me+=l*qe,_e+=l*tt,he+=l*rt,Ae+=l*We,Ee+=l*Xe,fe+=l*Je,H+=l*St,M+=l*at,X+=l*yt,K+=l*bt,V+=l*xt,ne+=l*vt,we+=l*Ot,Fe+=l*Dt,$e+=l*Ht,l=A[15],me+=l*b,_e+=l*qe,he+=l*tt,Ae+=l*rt,Ee+=l*We,fe+=l*Xe,H+=l*Je,M+=l*St,X+=l*at,K+=l*yt,V+=l*bt,ne+=l*xt,we+=l*vt,Fe+=l*Ot,$e+=l*Dt,Qe+=l*Ht,k+=38*_e,P+=38*he,Y+=38*Ae,ie+=38*Ee,ge+=38*fe,ue+=38*H,et+=38*M,pe+=38*X,Re+=38*K,Pe+=38*V,Me+=38*ne,Oe+=38*we,Te+=38*Fe,Ue+=38*$e,Le+=38*Qe,E=1,l=k+E+65535,E=Math.floor(l/65536),k=l-E*65536,l=P+E+65535,E=Math.floor(l/65536),P=l-E*65536,l=Y+E+65535,E=Math.floor(l/65536),Y=l-E*65536,l=ie+E+65535,E=Math.floor(l/65536),ie=l-E*65536,l=ge+E+65535,E=Math.floor(l/65536),ge=l-E*65536,l=ue+E+65535,E=Math.floor(l/65536),ue=l-E*65536,l=et+E+65535,E=Math.floor(l/65536),et=l-E*65536,l=pe+E+65535,E=Math.floor(l/65536),pe=l-E*65536,l=Re+E+65535,E=Math.floor(l/65536),Re=l-E*65536,l=Pe+E+65535,E=Math.floor(l/65536),Pe=l-E*65536,l=Me+E+65535,E=Math.floor(l/65536),Me=l-E*65536,l=Oe+E+65535,E=Math.floor(l/65536),Oe=l-E*65536,l=Te+E+65535,E=Math.floor(l/65536),Te=l-E*65536,l=Ue+E+65535,E=Math.floor(l/65536),Ue=l-E*65536,l=Le+E+65535,E=Math.floor(l/65536),Le=l-E*65536,l=me+E+65535,E=Math.floor(l/65536),me=l-E*65536,k+=E-1+37*(E-1),E=1,l=k+E+65535,E=Math.floor(l/65536),k=l-E*65536,l=P+E+65535,E=Math.floor(l/65536),P=l-E*65536,l=Y+E+65535,E=Math.floor(l/65536),Y=l-E*65536,l=ie+E+65535,E=Math.floor(l/65536),ie=l-E*65536,l=ge+E+65535,E=Math.floor(l/65536),ge=l-E*65536,l=ue+E+65535,E=Math.floor(l/65536),ue=l-E*65536,l=et+E+65535,E=Math.floor(l/65536),et=l-E*65536,l=pe+E+65535,E=Math.floor(l/65536),pe=l-E*65536,l=Re+E+65535,E=Math.floor(l/65536),Re=l-E*65536,l=Pe+E+65535,E=Math.floor(l/65536),Pe=l-E*65536,l=Me+E+65535,E=Math.floor(l/65536),Me=l-E*65536,l=Oe+E+65535,E=Math.floor(l/65536),Oe=l-E*65536,l=Te+E+65535,E=Math.floor(l/65536),Te=l-E*65536,l=Ue+E+65535,E=Math.floor(l/65536),Ue=l-E*65536,l=Le+E+65535,E=Math.floor(l/65536),Le=l-E*65536,l=me+E+65535,E=Math.floor(l/65536),me=l-E*65536,k+=E-1+37*(E-1),p[0]=k,p[1]=P,p[2]=Y,p[3]=ie,p[4]=ge,p[5]=ue,p[6]=et,p[7]=pe,p[8]=Re,p[9]=Pe,p[10]=Me,p[11]=Oe,p[12]=Te,p[13]=Ue,p[14]=Le,p[15]=me}function Ve(p,A){ee(p,A,A)}function mt(p,A){var m=t(),l;for(l=0;l<16;l++)m[l]=A[l];for(l=253;l>=0;l--)Ve(m,m),l!==2&&l!==4&&ee(m,m,A);for(l=0;l<16;l++)p[l]=m[l]}function ur(p,A){var m=t(),l;for(l=0;l<16;l++)m[l]=A[l];for(l=250;l>=0;l--)Ve(m,m),l!==1&&ee(m,m,A);for(l=0;l<16;l++)p[l]=m[l]}function nn(p,A,m){var l=new Uint8Array(32),E=new Float64Array(80),k,P,Y=t(),ie=t(),ge=t(),ue=t(),et=t(),pe=t();for(P=0;P<31;P++)l[P]=A[P];for(l[31]=A[31]&127|64,l[0]&=248,D(E,m),P=0;P<16;P++)ie[P]=E[P],ue[P]=Y[P]=ge[P]=0;for(Y[0]=ue[0]=1,P=254;P>=0;--P)k=l[P>>>3]>>>(P&7)&1,ae(Y,ie,k),ae(ge,ue,k),G(et,Y,ge),se(Y,Y,ge),G(ge,ie,ue),se(ie,ie,ue),Ve(ue,et),Ve(pe,Y),ee(Y,ge,Y),ee(ge,ie,et),G(et,Y,ge),se(Y,Y,ge),Ve(ie,Y),se(ge,ue,pe),ee(Y,ge,a),G(Y,Y,ue),ee(ge,ge,Y),ee(Y,ue,pe),ee(ue,ie,E),Ve(ie,et),ae(Y,ie,k),ae(ge,ue,k);for(P=0;P<16;P++)E[P+16]=Y[P],E[P+32]=ge[P],E[P+48]=ie[P],E[P+64]=ue[P];var Re=E.subarray(32),Pe=E.subarray(16);return mt(Re,Re),ee(Pe,Pe,Re),T(p,Pe),0}function sn(p,A){return nn(p,A,i)}function _r(p,A){return e(A,32),sn(p,A)}function on(p,A,m){var l=new Uint8Array(32);return nn(l,m,A),L(p,r,l,j)}var Hn=oe,wi=te;function Mn(p,A,m,l,E,k){var P=new Uint8Array(32);return on(P,E,k),Hn(p,A,m,l,P)}function an(p,A,m,l,E,k){var P=new Uint8Array(32);return on(P,E,k),wi(p,A,m,l,P)}var cn=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function q(p,A,m,l){for(var E=new Int32Array(16),k=new Int32Array(16),P,Y,ie,ge,ue,et,pe,Re,Pe,Me,Oe,Te,Ue,Le,me,_e,he,Ae,Ee,fe,H,M,X,K,V,ne,we=p[0],Fe=p[1],$e=p[2],Qe=p[3],b=p[4],qe=p[5],tt=p[6],rt=p[7],We=A[0],Xe=A[1],Je=A[2],St=A[3],at=A[4],yt=A[5],bt=A[6],xt=A[7],vt=0;l>=128;){for(Ee=0;Ee<16;Ee++)fe=8*Ee+vt,E[Ee]=m[fe+0]<<24|m[fe+1]<<16|m[fe+2]<<8|m[fe+3],k[Ee]=m[fe+4]<<24|m[fe+5]<<16|m[fe+6]<<8|m[fe+7];for(Ee=0;Ee<80;Ee++)if(P=we,Y=Fe,ie=$e,ge=Qe,ue=b,et=qe,pe=tt,Re=rt,Pe=We,Me=Xe,Oe=Je,Te=St,Ue=at,Le=yt,me=bt,_e=xt,H=rt,M=xt,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=(b>>>14|at<<18)^(b>>>18|at<<14)^(at>>>9|b<<23),M=(at>>>14|b<<18)^(at>>>18|b<<14)^(b>>>9|at<<23),X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,H=b&qe^~b&tt,M=at&yt^~at&bt,X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,H=cn[Ee*2],M=cn[Ee*2+1],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,H=E[Ee%16],M=k[Ee%16],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,he=V&65535|ne<<16,Ae=X&65535|K<<16,H=he,M=Ae,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=(we>>>28|We<<4)^(We>>>2|we<<30)^(We>>>7|we<<25),M=(We>>>28|we<<4)^(we>>>2|We<<30)^(we>>>7|We<<25),X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,H=we&Fe^we&$e^Fe&$e,M=We&Xe^We&Je^Xe&Je,X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,Re=V&65535|ne<<16,_e=X&65535|K<<16,H=ge,M=Te,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=he,M=Ae,X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,ge=V&65535|ne<<16,Te=X&65535|K<<16,Fe=P,$e=Y,Qe=ie,b=ge,qe=ue,tt=et,rt=pe,we=Re,Xe=Pe,Je=Me,St=Oe,at=Te,yt=Ue,bt=Le,xt=me,We=_e,Ee%16===15)for(fe=0;fe<16;fe++)H=E[fe],M=k[fe],X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=E[(fe+9)%16],M=k[(fe+9)%16],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,he=E[(fe+1)%16],Ae=k[(fe+1)%16],H=(he>>>1|Ae<<31)^(he>>>8|Ae<<24)^he>>>7,M=(Ae>>>1|he<<31)^(Ae>>>8|he<<24)^(Ae>>>7|he<<25),X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,he=E[(fe+14)%16],Ae=k[(fe+14)%16],H=(he>>>19|Ae<<13)^(Ae>>>29|he<<3)^he>>>6,M=(Ae>>>19|he<<13)^(he>>>29|Ae<<3)^(Ae>>>6|he<<26),X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,E[fe]=V&65535|ne<<16,k[fe]=X&65535|K<<16;H=we,M=We,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=p[0],M=A[0],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,p[0]=we=V&65535|ne<<16,A[0]=We=X&65535|K<<16,H=Fe,M=Xe,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=p[1],M=A[1],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,p[1]=Fe=V&65535|ne<<16,A[1]=Xe=X&65535|K<<16,H=$e,M=Je,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=p[2],M=A[2],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,p[2]=$e=V&65535|ne<<16,A[2]=Je=X&65535|K<<16,H=Qe,M=St,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=p[3],M=A[3],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,p[3]=Qe=V&65535|ne<<16,A[3]=St=X&65535|K<<16,H=b,M=at,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=p[4],M=A[4],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,p[4]=b=V&65535|ne<<16,A[4]=at=X&65535|K<<16,H=qe,M=yt,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=p[5],M=A[5],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,p[5]=qe=V&65535|ne<<16,A[5]=yt=X&65535|K<<16,H=tt,M=bt,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=p[6],M=A[6],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,p[6]=tt=V&65535|ne<<16,A[6]=bt=X&65535|K<<16,H=rt,M=xt,X=M&65535,K=M>>>16,V=H&65535,ne=H>>>16,H=p[7],M=A[7],X+=M&65535,K+=M>>>16,V+=H&65535,ne+=H>>>16,K+=X>>>16,V+=K>>>16,ne+=V>>>16,p[7]=rt=V&65535|ne<<16,A[7]=xt=X&65535|K<<16,vt+=128,l-=128}return l}function ce(p,A,m){var l=new Int32Array(8),E=new Int32Array(8),k=new Uint8Array(256),P,Y=m;for(l[0]=1779033703,l[1]=3144134277,l[2]=1013904242,l[3]=2773480762,l[4]=1359893119,l[5]=2600822924,l[6]=528734635,l[7]=1541459225,E[0]=4089235720,E[1]=2227873595,E[2]=4271175723,E[3]=1595750129,E[4]=2917565137,E[5]=725511199,E[6]=4215389547,E[7]=327033209,q(l,E,A,m),m%=128,P=0;P<m;P++)k[P]=A[Y-m+P];for(k[m]=128,m=256-128*(m<112?1:0),k[m-9]=0,g(k,m-8,Y/536870912|0,Y<<3),q(l,E,k,m),P=0;P<8;P++)g(p,8*P,l[P],E[P]);return 0}function ye(p,A){var m=t(),l=t(),E=t(),k=t(),P=t(),Y=t(),ie=t(),ge=t(),ue=t();se(m,p[1],p[0]),se(ue,A[1],A[0]),ee(m,m,ue),G(l,p[0],p[1]),G(ue,A[0],A[1]),ee(l,l,ue),ee(E,p[3],A[3]),ee(E,E,f),ee(k,p[2],A[2]),G(k,k,k),se(P,l,m),se(Y,k,E),G(ie,k,E),G(ge,l,m),ee(p[0],P,Y),ee(p[1],ge,ie),ee(p[2],ie,Y),ee(p[3],P,ge)}function ke(p,A,m){var l;for(l=0;l<4;l++)ae(p[l],A[l],m)}function je(p,A){var m=t(),l=t(),E=t();mt(E,A[2]),ee(m,A[0],E),ee(l,A[1],E),T(p,l),p[31]^=v(m)<<7}function It(p,A,m){var l,E;for(Z(p[0],s),Z(p[1],o),Z(p[2],o),Z(p[3],s),E=255;E>=0;--E)l=m[E/8|0]>>(E&7)&1,ke(p,A,l),ye(A,p),ye(p,p),ke(p,A,l)}function lr(p,A){var m=[t(),t(),t(),t()];Z(m[0],u),Z(m[1],h),Z(m[2],o),ee(m[3],u,h),It(p,m,A)}function jt(p,A,m){var l=new Uint8Array(64),E=[t(),t(),t(),t()],k;for(m||e(A,32),ce(l,A,32),l[0]&=248,l[31]&=127,l[31]|=64,lr(E,l),je(p,E),k=0;k<32;k++)A[k+32]=p[k];return 0}var fn=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function st(p,A){var m,l,E,k;for(l=63;l>=32;--l){for(m=0,E=l-32,k=l-12;E<k;++E)A[E]+=m-16*A[l]*fn[E-(l-32)],m=A[E]+128>>8,A[E]-=m*256;A[E]+=m,A[l]=0}for(m=0,E=0;E<32;E++)A[E]+=m-(A[31]>>4)*fn[E],m=A[E]>>8,A[E]&=255;for(E=0;E<32;E++)A[E]-=m*fn[E];for(l=0;l<32;l++)A[l+1]+=A[l]>>8,p[l]=A[l]&255}function Rt(p){var A=new Float64Array(64),m;for(m=0;m<64;m++)A[m]=p[m];for(m=0;m<64;m++)p[m]=0;st(p,A)}function Bt(p,A,m,l){var E=new Uint8Array(64),k=new Uint8Array(64),P=new Uint8Array(64),Y,ie,ge=new Float64Array(64),ue=[t(),t(),t(),t()];ce(E,l,32),E[0]&=248,E[31]&=127,E[31]|=64;var et=m+64;for(Y=0;Y<m;Y++)p[64+Y]=A[Y];for(Y=0;Y<32;Y++)p[32+Y]=E[32+Y];for(ce(P,p.subarray(32),m+32),Rt(P),lr(ue,P),je(p,ue),Y=32;Y<64;Y++)p[Y]=l[Y];for(ce(k,p,m+64),Rt(k),Y=0;Y<64;Y++)ge[Y]=0;for(Y=0;Y<32;Y++)ge[Y]=P[Y];for(Y=0;Y<32;Y++)for(ie=0;ie<32;ie++)ge[Y+ie]+=k[Y]*E[ie];return st(p.subarray(32),ge),et}function Et(p,A){var m=t(),l=t(),E=t(),k=t(),P=t(),Y=t(),ie=t();return Z(p[2],o),D(p[1],A),Ve(E,p[1]),ee(k,E,c),se(E,E,p[2]),G(k,p[2],k),Ve(P,k),Ve(Y,P),ee(ie,Y,P),ee(m,ie,E),ee(m,m,k),ur(m,m),ee(m,m,E),ee(m,m,k),ee(m,m,k),ee(p[0],m,k),Ve(l,p[0]),ee(l,l,k),C(l,E)&&ee(p[0],p[0],d),Ve(l,p[0]),ee(l,l,k),C(l,E)?-1:(v(p[0])===A[31]>>7&&se(p[0],s,p[0]),ee(p[3],p[0],p[1]),0)}function lt(p,A,m,l){var E,k,P=new Uint8Array(32),Y=new Uint8Array(64),ie=[t(),t(),t(),t()],ge=[t(),t(),t(),t()];if(k=-1,m<64||Et(ge,l))return-1;for(E=0;E<m;E++)p[E]=A[E];for(E=0;E<32;E++)p[E+32]=l[E];if(ce(Y,p,m),Rt(Y),It(ie,ge,Y),lr(ge,A.subarray(32)),ye(ie,ge),je(P,ie),m-=64,x(A,0,P,0)){for(E=0;E<m;E++)p[E]=0;return-1}for(E=0;E<m;E++)p[E]=A[E+64];return k=m,k}var er=32,_t=24,Gr=32,un=16,Fn=32,Ii=32,Qn=32,$n=32,Rs=32,Qa=_t,Ld=Gr,Ud=un,yr=64,Yr=32,ln=64,Ns=32,Ps=64;n.lowlevel={crypto_core_hsalsa20:L,crypto_stream_xor:w,crypto_stream:S,crypto_stream_salsa20_xor:J,crypto_stream_salsa20:z,crypto_onetimeauth:W,crypto_onetimeauth_verify:Q,crypto_verify_16:y,crypto_verify_32:x,crypto_secretbox:oe,crypto_secretbox_open:te,crypto_scalarmult:nn,crypto_scalarmult_base:sn,crypto_box_beforenm:on,crypto_box_afternm:Hn,crypto_box:Mn,crypto_box_open:an,crypto_box_keypair:_r,crypto_hash:ce,crypto_sign:Bt,crypto_sign_keypair:jt,crypto_sign_open:lt,crypto_secretbox_KEYBYTES:er,crypto_secretbox_NONCEBYTES:_t,crypto_secretbox_ZEROBYTES:Gr,crypto_secretbox_BOXZEROBYTES:un,crypto_scalarmult_BYTES:Fn,crypto_scalarmult_SCALARBYTES:Ii,crypto_box_PUBLICKEYBYTES:Qn,crypto_box_SECRETKEYBYTES:$n,crypto_box_BEFORENMBYTES:Rs,crypto_box_NONCEBYTES:Qa,crypto_box_ZEROBYTES:Ld,crypto_box_BOXZEROBYTES:Ud,crypto_sign_BYTES:yr,crypto_sign_PUBLICKEYBYTES:Yr,crypto_sign_SECRETKEYBYTES:ln,crypto_sign_SEEDBYTES:Ns,crypto_hash_BYTES:Ps};function $a(p,A){if(p.length!==er)throw new Error("bad key size");if(A.length!==_t)throw new Error("bad nonce size")}function Od(p,A){if(p.length!==Qn)throw new Error("bad public key size");if(A.length!==$n)throw new Error("bad secret key size")}function zt(){var p,A;for(A=0;A<arguments.length;A++)if((p=Object.prototype.toString.call(arguments[A]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+p+", use Uint8Array")}function Wa(p){for(var A=0;A<p.length;A++)p[A]=0}n.util||(n.util={},n.util.decodeUTF8=n.util.encodeUTF8=n.util.encodeBase64=n.util.decodeBase64=function(){throw new Error("nacl.util moved into separate package: https://github.com/dchest/tweetnacl-util-js")}),n.randomBytes=function(p){var A=new Uint8Array(p);return e(A,p),A},n.secretbox=function(p,A,m){zt(p,A,m),$a(m,A);for(var l=new Uint8Array(Gr+p.length),E=new Uint8Array(l.length),k=0;k<p.length;k++)l[k+Gr]=p[k];return oe(E,l,l.length,A,m),E.subarray(un)},n.secretbox.open=function(p,A,m){zt(p,A,m),$a(m,A);for(var l=new Uint8Array(un+p.length),E=new Uint8Array(l.length),k=0;k<p.length;k++)l[k+un]=p[k];return l.length<32||te(E,l,l.length,A,m)!==0?!1:E.subarray(Gr)},n.secretbox.keyLength=er,n.secretbox.nonceLength=_t,n.secretbox.overheadLength=un,n.scalarMult=function(p,A){if(zt(p,A),p.length!==Ii)throw new Error("bad n size");if(A.length!==Fn)throw new Error("bad p size");var m=new Uint8Array(Fn);return nn(m,p,A),m},n.scalarMult.base=function(p){if(zt(p),p.length!==Ii)throw new Error("bad n size");var A=new Uint8Array(Fn);return sn(A,p),A},n.scalarMult.scalarLength=Ii,n.scalarMult.groupElementLength=Fn,n.box=function(p,A,m,l){var E=n.box.before(m,l);return n.secretbox(p,A,E)},n.box.before=function(p,A){zt(p,A),Od(p,A);var m=new Uint8Array(Rs);return on(m,p,A),m},n.box.after=n.secretbox,n.box.open=function(p,A,m,l){var E=n.box.before(m,l);return n.secretbox.open(p,A,E)},n.box.open.after=n.secretbox.open,n.box.keyPair=function(){var p=new Uint8Array(Qn),A=new Uint8Array($n);return _r(p,A),{publicKey:p,secretKey:A}},n.box.keyPair.fromSecretKey=function(p){if(zt(p),p.length!==$n)throw new Error("bad secret key size");var A=new Uint8Array(Qn);return sn(A,p),{publicKey:A,secretKey:new Uint8Array(p)}},n.box.publicKeyLength=Qn,n.box.secretKeyLength=$n,n.box.sharedKeyLength=Rs,n.box.nonceLength=Qa,n.box.overheadLength=n.secretbox.overheadLength,n.sign=function(p,A){if(zt(p,A),A.length!==ln)throw new Error("bad secret key size");var m=new Uint8Array(yr+p.length);return Bt(m,p,p.length,A),m},n.sign.open=function(p,A){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(zt(p,A),A.length!==Yr)throw new Error("bad public key size");var m=new Uint8Array(p.length),l=lt(m,p,p.length,A);if(l<0)return null;for(var E=new Uint8Array(l),k=0;k<E.length;k++)E[k]=m[k];return E},n.sign.detached=function(p,A){for(var m=n.sign(p,A),l=new Uint8Array(yr),E=0;E<l.length;E++)l[E]=m[E];return l},n.sign.detached.verify=function(p,A,m){if(zt(p,A,m),A.length!==yr)throw new Error("bad signature size");if(m.length!==Yr)throw new Error("bad public key size");var l=new Uint8Array(yr+p.length),E=new Uint8Array(yr+p.length),k;for(k=0;k<yr;k++)l[k]=A[k];for(k=0;k<p.length;k++)l[k+yr]=p[k];return lt(E,l,l.length,m)>=0},n.sign.keyPair=function(){var p=new Uint8Array(Yr),A=new Uint8Array(ln);return jt(p,A),{publicKey:p,secretKey:A}},n.sign.keyPair.fromSecretKey=function(p){if(zt(p),p.length!==ln)throw new Error("bad secret key size");for(var A=new Uint8Array(Yr),m=0;m<A.length;m++)A[m]=p[32+m];return{publicKey:A,secretKey:new Uint8Array(p)}},n.sign.keyPair.fromSeed=function(p){if(zt(p),p.length!==Ns)throw new Error("bad seed size");for(var A=new Uint8Array(Yr),m=new Uint8Array(ln),l=0;l<32;l++)m[l]=p[l];return jt(A,m,!0),{publicKey:A,secretKey:m}},n.sign.publicKeyLength=Yr,n.sign.secretKeyLength=ln,n.sign.seedLength=Ns,n.sign.signatureLength=yr,n.hash=function(p){zt(p);var A=new Uint8Array(Ps);return ce(A,p,p.length),A},n.hash.hashLength=Ps,n.verify=function(p,A){return zt(p,A),p.length===0||A.length===0||p.length!==A.length?!1:_(p,0,A,0,p.length)===0},n.setPRNG=function(p){e=p},(function(){var p=typeof self<"u"?self.crypto||self.msCrypto:null;if(p&&p.getRandomValues){var A=65536;n.setPRNG(function(m,l){var E,k=new Uint8Array(l);for(E=0;E<l;E+=A)p.getRandomValues(k.subarray(E,E+Math.min(l-E,A)));for(E=0;E<l;E++)m[E]=k[E];Wa(k)})}else typeof require<"u"&&(p=require("crypto"),p&&p.randomBytes&&n.setPRNG(function(m,l){var E,k=p.randomBytes(l);for(E=0;E<l;E++)m[E]=k[E];Wa(k)}))})()})(typeof Fi<"u"&&Fi.exports?Fi.exports:self.nacl=self.nacl||{})});var js=ot((xb,Vu)=>{"use strict";var Gs=Yu().lowlevel.crypto_hash,xr=0,Xr=function(){this.S=[new Uint32Array([3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946]),new Uint32Array([1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055]),new Uint32Array([3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504]),new Uint32Array([976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462])],this.P=new Uint32Array([608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731])};function $i(n,t,e){return(n[0][t[e+3]]+n[1][t[e+2]]^n[2][t[e+1]])+n[3][t[e]]}Xr.prototype.encipher=function(n,t){t===void 0&&(t=new Uint8Array(n.buffer),n.byteOffset!==0&&(t=t.subarray(n.byteOffset))),n[0]^=this.P[0];for(var e=1;e<16;e+=2)n[1]^=$i(this.S,t,0)^this.P[e],n[0]^=$i(this.S,t,4)^this.P[e+1];var r=n[0];n[0]=n[1]^this.P[17],n[1]=r};Xr.prototype.decipher=function(n){var t=new Uint8Array(n.buffer);n.byteOffset!==0&&(t=t.subarray(n.byteOffset)),n[0]^=this.P[17];for(var e=16;e>0;e-=2)n[1]^=$i(this.S,t,0)^this.P[e],n[0]^=$i(this.S,t,4)^this.P[e-1];var r=n[0];n[0]=n[1]^this.P[0],n[1]=r};function zr(n,t){var e,r=0;for(e=0;e<4;e++,xr++)xr>=t&&(xr=0),r=r<<8|n[xr];return r}Xr.prototype.expand0state=function(n,t){var e=new Uint32Array(2),r,i,s=new Uint8Array(e.buffer);for(r=0,xr=0;r<18;r++)this.P[r]^=zr(n,t);for(xr=0,r=0;r<18;r+=2)this.encipher(e,s),this.P[r]=e[0],this.P[r+1]=e[1];for(r=0;r<4;r++)for(i=0;i<256;i+=2)this.encipher(e,s),this.S[r][i]=e[0],this.S[r][i+1]=e[1]};Xr.prototype.expandstate=function(n,t,e,r){var i=new Uint32Array(2),s,o;for(s=0,xr=0;s<18;s++)this.P[s]^=zr(e,r);for(s=0,xr=0;s<18;s+=2)i[0]^=zr(n,t),i[1]^=zr(n,t),this.encipher(i),this.P[s]=i[0],this.P[s+1]=i[1];for(s=0;s<4;s++)for(o=0;o<256;o+=2)i[0]^=zr(n,t),i[1]^=zr(n,t),this.encipher(i),this.S[s][o]=i[0],this.S[s][o+1]=i[1];xr=0};Xr.prototype.enc=function(n,t){for(var e=0;e<t;e++)this.encipher(n.subarray(e*2))};Xr.prototype.dec=function(n,t){for(var e=0;e<t;e++)this.decipher(n.subarray(e*2))};var Qi=8,Ys=32;function Vs(n,t,e){var r=new Xr,i=new Uint32Array(Qi),s,o=new Uint8Array([79,120,121,99,104,114,111,109,97,116,105,99,66,108,111,119,102,105,115,104,83,119,97,116,68,121,110,97,109,105,116,101]);for(r.expandstate(t,64,n,64),s=0;s<64;s++)r.expand0state(t,64),r.expand0state(n,64);for(s=0;s<Qi;s++)i[s]=zr(o,o.byteLength);for(s=0;s<64;s++)r.enc(i,i.byteLength/8);for(s=0;s<Qi;s++)e[4*s+3]=i[s]>>>24,e[4*s+2]=i[s]>>>16,e[4*s+1]=i[s]>>>8,e[4*s+0]=i[s]}function Op(n,t,e,r,i,s,o){var a=new Uint8Array(64),c=new Uint8Array(64),f=new Uint8Array(Ys),u=new Uint8Array(Ys),h=new Uint8Array(r+4),d,g,_,y,x,I,O=s;if(o<1||t===0||r===0||s===0||s>f.byteLength*f.byteLength||r>1<<20)return-1;for(y=Math.floor((s+f.byteLength-1)/f.byteLength),_=Math.floor((s+y-1)/y),d=0;d<r;d++)h[d]=e[d];for(Gs(a,n,t),I=1;s>0;I++){for(h[r+0]=I>>>24,h[r+1]=I>>>16,h[r+2]=I>>>8,h[r+3]=I,Gs(c,h,r+4),Vs(a,c,u),d=f.byteLength;d--;)f[d]=u[d];for(d=1;d<o;d++)for(Gs(c,u,u.byteLength),Vs(a,c,u),g=0;g<f.byteLength;g++)f[g]^=u[g];for(_=Math.min(_,s),d=0;d<_&&(x=d*y+(I-1),!(x>=O));d++)i[x]=f[d];s-=d}return 0}Vu.exports={BLOCKS:Qi,HASHSIZE:Ys,hash:Vs,pbkdf:Op}});var wr=ot((Sb,qi)=>{"use strict";var Sr=require("crypto"),An;try{An=require("cpu-features")()}catch{}var{bindingAvailable:ju,CIPHER_INFO:Dp,MAC_INFO:Hp}=Lr(),zu=(()=>{if(typeof Sr.sign=="function"&&typeof Sr.verify=="function"){let n=`-----BEGIN PRIVATE KEY-----\r
1
+ "use strict";var jd=Object.create;var Va=Object.defineProperty;var zd=Object.getOwnPropertyDescriptor;var Xd=Object.getOwnPropertyNames;var Jd=Object.getPrototypeOf,Zd=Object.prototype.hasOwnProperty;var ot=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var eh=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Xd(t))!Zd.call(r,i)&&i!==e&&Va(r,i,{get:()=>t[i],enumerable:!(n=zd(t,i))||n.enumerable});return r};var $t=(r,t,e)=>(e=r!=null?jd(Jd(r)):{},eh(t||!r||!r.__esModule?Va(e,"default",{value:r,enumerable:!0}):e,r));var Ni=ot((_y,Hf)=>{Hf.exports={newInvalidAsn1Error:function(r){var t=new Error;return t.name="InvalidAsn1Error",t.message=r||"",t}}});var Pi=ot((by,Qf)=>{Qf.exports={EOC:0,Boolean:1,Integer:2,BitString:3,OctetString:4,Null:5,OID:6,ObjectDescriptor:7,External:8,Real:9,Enumeration:10,PDV:11,Utf8String:12,RelativeOID:13,Sequence:16,Set:17,NumericString:18,PrintableString:19,T61String:20,VideotexString:21,IA5String:22,UTCTime:23,GeneralizedTime:24,GraphicString:25,VisibleString:26,GeneralString:28,UniversalString:29,CharacterString:30,BMPString:31,Constructor:32,Context:128}});var Ms=ot((yy,Wf)=>{"use strict";var Ti=require("buffer"),un=Ti.Buffer,rr={},nr;for(nr in Ti)Ti.hasOwnProperty(nr)&&(nr==="SlowBuffer"||nr==="Buffer"||(rr[nr]=Ti[nr]));var dn=rr.Buffer={};for(nr in un)un.hasOwnProperty(nr)&&(nr==="allocUnsafe"||nr==="allocUnsafeSlow"||(dn[nr]=un[nr]));rr.Buffer.prototype=un.prototype;(!dn.from||dn.from===Uint8Array.from)&&(dn.from=function(r,t,e){if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type '+typeof r);if(r&&typeof r.length>"u")throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);return un(r,t,e)});dn.alloc||(dn.alloc=function(r,t,e){if(typeof r!="number")throw new TypeError('The "size" argument must be of type number. Received type '+typeof r);if(r<0||r>=2*(1<<30))throw new RangeError('The value "'+r+'" is invalid for option "size"');var n=un(r);return!t||t.length===0?n.fill(0):typeof e=="string"?n.fill(t,e):n.fill(t),n});if(!rr.kStringMaxLength)try{rr.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}rr.constants||(rr.constants={MAX_LENGTH:rr.kMaxLength},rr.kStringMaxLength&&(rr.constants.MAX_STRING_LENGTH=rr.kStringMaxLength));Wf.exports=rr});var Vf=ot((xy,Kf)=>{var Mh=require("assert"),qf=Ms().Buffer,qn=Pi(),Fh=Ni(),hn=Fh.newInvalidAsn1Error;function Wt(r){if(!r||!qf.isBuffer(r))throw new TypeError("data must be a node Buffer");this._buf=r,this._size=r.length,this._len=0,this._offset=0}Object.defineProperty(Wt.prototype,"length",{enumerable:!0,get:function(){return this._len}});Object.defineProperty(Wt.prototype,"offset",{enumerable:!0,get:function(){return this._offset}});Object.defineProperty(Wt.prototype,"remain",{get:function(){return this._size-this._offset}});Object.defineProperty(Wt.prototype,"buffer",{get:function(){return this._buf.slice(this._offset)}});Wt.prototype.readByte=function(r){if(this._size-this._offset<1)return null;var t=this._buf[this._offset]&255;return r||(this._offset+=1),t};Wt.prototype.peek=function(){return this.readByte(!0)};Wt.prototype.readLength=function(r){if(r===void 0&&(r=this._offset),r>=this._size)return null;var t=this._buf[r++]&255;if(t===null)return null;if((t&128)===128){if(t&=127,t===0)throw hn("Indefinite length not supported");if(t>4)throw hn("encoding too long");if(this._size-r<t)return null;this._len=0;for(var e=0;e<t;e++)this._len=(this._len<<8)+(this._buf[r++]&255)}else this._len=t;return r};Wt.prototype.readSequence=function(r){var t=this.peek();if(t===null)return null;if(r!==void 0&&r!==t)throw hn("Expected 0x"+r.toString(16)+": got 0x"+t.toString(16));var e=this.readLength(this._offset+1);return e===null?null:(this._offset=e,t)};Wt.prototype.readInt=function(){return this._readTag(qn.Integer)};Wt.prototype.readBoolean=function(){return this._readTag(qn.Boolean)!==0};Wt.prototype.readEnumeration=function(){return this._readTag(qn.Enumeration)};Wt.prototype.readString=function(r,t){r||(r=qn.OctetString);var e=this.peek();if(e===null)return null;if(e!==r)throw hn("Expected 0x"+r.toString(16)+": got 0x"+e.toString(16));var n=this.readLength(this._offset+1);if(n===null||this.length>this._size-n)return null;if(this._offset=n,this.length===0)return t?qf.alloc(0):"";var i=this._buf.slice(this._offset,this._offset+this.length);return this._offset+=this.length,t?i:i.toString("utf8")};Wt.prototype.readOID=function(r){r||(r=qn.OID);var t=this.readString(r,!0);if(t===null)return null;for(var e=[],n=0,i=0;i<t.length;i++){var s=t[i]&255;n<<=7,n+=s&127,(s&128)===0&&(e.push(n),n=0)}return n=e.shift(),e.unshift(n%40),e.unshift(n/40>>0),e.join(".")};Wt.prototype._readTag=function(r){Mh.ok(r!==void 0);var t=this.peek();if(t===null)return null;if(t!==r)throw hn("Expected 0x"+r.toString(16)+": got 0x"+t.toString(16));var e=this.readLength(this._offset+1);if(e===null)return null;if(this.length>4)throw hn("Integer too long: "+this.length);if(this.length>this._size-e)return null;this._offset=e;for(var n=this._buf[this._offset],i=0,s=0;s<this.length;s++)i<<=8,i|=this._buf[this._offset++]&255;return(n&128)===128&&s!==4&&(i-=1<<s*8),i>>0};Kf.exports=Wt});var Yf=ot((Sy,Gf)=>{var kr=require("assert"),Li=Ms().Buffer,Br=Pi(),$h=Ni(),Ui=$h.newInvalidAsn1Error,Hh={size:1024,growthFactor:8};function Qh(r,t){kr.ok(r),kr.equal(typeof r,"object"),kr.ok(t),kr.equal(typeof t,"object");var e=Object.getOwnPropertyNames(r);return e.forEach(function(n){if(!t[n]){var i=Object.getOwnPropertyDescriptor(r,n);Object.defineProperty(t,n,i)}}),t}function Mt(r){r=Qh(Hh,r||{}),this._buf=Li.alloc(r.size||1024),this._size=this._buf.length,this._offset=0,this._options=r,this._seq=[]}Object.defineProperty(Mt.prototype,"buffer",{get:function(){if(this._seq.length)throw Ui(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});Mt.prototype.writeByte=function(r){if(typeof r!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=r};Mt.prototype.writeInt=function(r,t){if(typeof r!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Br.Integer);for(var e=4;((r&4286578688)===0||(r&4286578688)===-8388608)&&e>1;)e--,r<<=8;if(e>4)throw Ui("BER ints cannot be > 0xffffffff");for(this._ensure(2+e),this._buf[this._offset++]=t,this._buf[this._offset++]=e;e-- >0;)this._buf[this._offset++]=(r&4278190080)>>>24,r<<=8};Mt.prototype.writeNull=function(){this.writeByte(Br.Null),this.writeByte(0)};Mt.prototype.writeEnumeration=function(r,t){if(typeof r!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Br.Enumeration),this.writeInt(r,t)};Mt.prototype.writeBoolean=function(r,t){if(typeof r!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Br.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=r?255:0};Mt.prototype.writeString=function(r,t){if(typeof r!="string")throw new TypeError("argument must be a string (was: "+typeof r+")");typeof t!="number"&&(t=Br.OctetString);var e=Li.byteLength(r);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(r,this._offset),this._offset+=e)};Mt.prototype.writeBuffer=function(r,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!Li.isBuffer(r))throw new TypeError("argument must be a buffer");this.writeByte(t),this.writeLength(r.length),this._ensure(r.length),r.copy(this._buf,this._offset,0,r.length),this._offset+=r.length};Mt.prototype.writeStringArray=function(r){if(!r instanceof Array)throw new TypeError("argument must be an Array[String]");var t=this;r.forEach(function(e){t.writeString(e)})};Mt.prototype.writeOID=function(r,t){if(typeof r!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Br.OID),!/^([0-9]+\.){3,}[0-9]+$/.test(r))throw new Error("argument is not a valid OID string");function e(o,a){a<128?o.push(a):a<16384?(o.push(a>>>7|128),o.push(a&127)):a<2097152?(o.push(a>>>14|128),o.push((a>>>7|128)&255),o.push(a&127)):a<268435456?(o.push(a>>>21|128),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127)):(o.push((a>>>28|128)&255),o.push((a>>>21|128)&255),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127))}var n=r.split("."),i=[];i.push(parseInt(n[0],10)*40+parseInt(n[1],10)),n.slice(2).forEach(function(o){e(i,parseInt(o,10))});var s=this;this._ensure(2+i.length),this.writeByte(t),this.writeLength(i.length),i.forEach(function(o){s.writeByte(o)})};Mt.prototype.writeLength=function(r){if(typeof r!="number")throw new TypeError("argument must be a Number");if(this._ensure(4),r<=127)this._buf[this._offset++]=r;else if(r<=255)this._buf[this._offset++]=129,this._buf[this._offset++]=r;else if(r<=65535)this._buf[this._offset++]=130,this._buf[this._offset++]=r>>8,this._buf[this._offset++]=r;else if(r<=16777215)this._buf[this._offset++]=131,this._buf[this._offset++]=r>>16,this._buf[this._offset++]=r>>8,this._buf[this._offset++]=r;else throw Ui("Length too long (> 4 bytes)")};Mt.prototype.startSequence=function(r){typeof r!="number"&&(r=Br.Sequence|Br.Constructor),this.writeByte(r),this._seq.push(this._offset),this._ensure(3),this._offset+=3};Mt.prototype.endSequence=function(){var r=this._seq.pop(),t=r+3,e=this._offset-t;if(e<=127)this._shift(t,e,-2),this._buf[r]=e;else if(e<=255)this._shift(t,e,-1),this._buf[r]=129,this._buf[r+1]=e;else if(e<=65535)this._buf[r]=130,this._buf[r+1]=e>>8,this._buf[r+2]=e;else if(e<=16777215)this._shift(t,e,1),this._buf[r]=131,this._buf[r+1]=e>>16,this._buf[r+2]=e>>8,this._buf[r+3]=e;else throw Ui("Sequence too long")};Mt.prototype._shift=function(r,t,e){kr.ok(r!==void 0),kr.ok(t!==void 0),kr.ok(e),this._buf.copy(this._buf,r+e,r,r+t),this._offset+=e};Mt.prototype._ensure=function(r){if(kr.ok(r),this._size-this._offset<r){var t=this._size*this._options.growthFactor;t-this._offset<r&&(t+=r);var e=Li.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};Gf.exports=Mt});var jf=ot((wy,Mi)=>{var Fs=Ni(),$s=Pi(),Wh=Vf(),qh=Yf();Mi.exports={Reader:Wh,Writer:qh};for(Di in $s)$s.hasOwnProperty(Di)&&(Mi.exports[Di]=$s[Di]);var Di;for(Oi in Fs)Fs.hasOwnProperty(Oi)&&(Mi.exports[Oi]=Fs[Oi]);var Oi});var Kn=ot((Iy,zf)=>{var Hs=jf();zf.exports={Ber:Hs,BerReader:Hs.Reader,BerWriter:Hs.Writer}});var Xf=ot((Cy,Fi)=>{(function(r){"use strict";var t=function(p){var A,m=new Float64Array(16);if(p)for(A=0;A<p.length;A++)m[A]=p[A];return m},e=function(){throw new Error("no PRNG")},n=new Uint8Array(16),i=new Uint8Array(32);i[0]=9;var s=t(),o=t([1]),a=t([56129,1]),c=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),f=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),l=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),u=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),h=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function g(p,A,m,d){p[A]=m>>24&255,p[A+1]=m>>16&255,p[A+2]=m>>8&255,p[A+3]=m&255,p[A+4]=d>>24&255,p[A+5]=d>>16&255,p[A+6]=d>>8&255,p[A+7]=d&255}function b(p,A,m,d,E){var B,L=0;for(B=0;B<E;B++)L|=p[A+B]^m[d+B];return(1&L-1>>>8)-1}function _(p,A,m,d){return b(p,A,m,d,16)}function x(p,A,m,d){return b(p,A,m,d,32)}function S(p,A,m,d){for(var E=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,B=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,L=m[4]&255|(m[5]&255)<<8|(m[6]&255)<<16|(m[7]&255)<<24,j=m[8]&255|(m[9]&255)<<8|(m[10]&255)<<16|(m[11]&255)<<24,ie=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,ge=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,de=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,et=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,pe=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Ne=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Pe=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Fe=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,De=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,Te=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Ue=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,Le=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,me=E,_e=B,he=L,Ae=j,Ee=ie,le=ge,F=de,$=et,J=pe,V=Ne,z=Pe,ne=Fe,Ie=De,$e=Te,Qe=Ue,He=Le,y,qe=0;qe<20;qe+=2)y=me+Ie|0,Ee^=y<<7|y>>>25,y=Ee+me|0,J^=y<<9|y>>>23,y=J+Ee|0,Ie^=y<<13|y>>>19,y=Ie+J|0,me^=y<<18|y>>>14,y=le+_e|0,V^=y<<7|y>>>25,y=V+le|0,$e^=y<<9|y>>>23,y=$e+V|0,_e^=y<<13|y>>>19,y=_e+$e|0,le^=y<<18|y>>>14,y=z+F|0,Qe^=y<<7|y>>>25,y=Qe+z|0,he^=y<<9|y>>>23,y=he+Qe|0,F^=y<<13|y>>>19,y=F+he|0,z^=y<<18|y>>>14,y=He+ne|0,Ae^=y<<7|y>>>25,y=Ae+He|0,$^=y<<9|y>>>23,y=$+Ae|0,ne^=y<<13|y>>>19,y=ne+$|0,He^=y<<18|y>>>14,y=me+Ae|0,_e^=y<<7|y>>>25,y=_e+me|0,he^=y<<9|y>>>23,y=he+_e|0,Ae^=y<<13|y>>>19,y=Ae+he|0,me^=y<<18|y>>>14,y=le+Ee|0,F^=y<<7|y>>>25,y=F+le|0,$^=y<<9|y>>>23,y=$+F|0,Ee^=y<<13|y>>>19,y=Ee+$|0,le^=y<<18|y>>>14,y=z+V|0,ne^=y<<7|y>>>25,y=ne+z|0,J^=y<<9|y>>>23,y=J+ne|0,V^=y<<13|y>>>19,y=V+J|0,z^=y<<18|y>>>14,y=He+Qe|0,Ie^=y<<7|y>>>25,y=Ie+He|0,$e^=y<<9|y>>>23,y=$e+Ie|0,Qe^=y<<13|y>>>19,y=Qe+$e|0,He^=y<<18|y>>>14;me=me+E|0,_e=_e+B|0,he=he+L|0,Ae=Ae+j|0,Ee=Ee+ie|0,le=le+ge|0,F=F+de|0,$=$+et|0,J=J+pe|0,V=V+Ne|0,z=z+Pe|0,ne=ne+Fe|0,Ie=Ie+De|0,$e=$e+Te|0,Qe=Qe+Ue|0,He=He+Le|0,p[0]=me>>>0&255,p[1]=me>>>8&255,p[2]=me>>>16&255,p[3]=me>>>24&255,p[4]=_e>>>0&255,p[5]=_e>>>8&255,p[6]=_e>>>16&255,p[7]=_e>>>24&255,p[8]=he>>>0&255,p[9]=he>>>8&255,p[10]=he>>>16&255,p[11]=he>>>24&255,p[12]=Ae>>>0&255,p[13]=Ae>>>8&255,p[14]=Ae>>>16&255,p[15]=Ae>>>24&255,p[16]=Ee>>>0&255,p[17]=Ee>>>8&255,p[18]=Ee>>>16&255,p[19]=Ee>>>24&255,p[20]=le>>>0&255,p[21]=le>>>8&255,p[22]=le>>>16&255,p[23]=le>>>24&255,p[24]=F>>>0&255,p[25]=F>>>8&255,p[26]=F>>>16&255,p[27]=F>>>24&255,p[28]=$>>>0&255,p[29]=$>>>8&255,p[30]=$>>>16&255,p[31]=$>>>24&255,p[32]=J>>>0&255,p[33]=J>>>8&255,p[34]=J>>>16&255,p[35]=J>>>24&255,p[36]=V>>>0&255,p[37]=V>>>8&255,p[38]=V>>>16&255,p[39]=V>>>24&255,p[40]=z>>>0&255,p[41]=z>>>8&255,p[42]=z>>>16&255,p[43]=z>>>24&255,p[44]=ne>>>0&255,p[45]=ne>>>8&255,p[46]=ne>>>16&255,p[47]=ne>>>24&255,p[48]=Ie>>>0&255,p[49]=Ie>>>8&255,p[50]=Ie>>>16&255,p[51]=Ie>>>24&255,p[52]=$e>>>0&255,p[53]=$e>>>8&255,p[54]=$e>>>16&255,p[55]=$e>>>24&255,p[56]=Qe>>>0&255,p[57]=Qe>>>8&255,p[58]=Qe>>>16&255,p[59]=Qe>>>24&255,p[60]=He>>>0&255,p[61]=He>>>8&255,p[62]=He>>>16&255,p[63]=He>>>24&255}function N(p,A,m,d){for(var E=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,B=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,L=m[4]&255|(m[5]&255)<<8|(m[6]&255)<<16|(m[7]&255)<<24,j=m[8]&255|(m[9]&255)<<8|(m[10]&255)<<16|(m[11]&255)<<24,ie=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,ge=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,de=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,et=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,pe=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Ne=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Pe=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Fe=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,De=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,Te=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Ue=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,Le=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,me=E,_e=B,he=L,Ae=j,Ee=ie,le=ge,F=de,$=et,J=pe,V=Ne,z=Pe,ne=Fe,Ie=De,$e=Te,Qe=Ue,He=Le,y,qe=0;qe<20;qe+=2)y=me+Ie|0,Ee^=y<<7|y>>>25,y=Ee+me|0,J^=y<<9|y>>>23,y=J+Ee|0,Ie^=y<<13|y>>>19,y=Ie+J|0,me^=y<<18|y>>>14,y=le+_e|0,V^=y<<7|y>>>25,y=V+le|0,$e^=y<<9|y>>>23,y=$e+V|0,_e^=y<<13|y>>>19,y=_e+$e|0,le^=y<<18|y>>>14,y=z+F|0,Qe^=y<<7|y>>>25,y=Qe+z|0,he^=y<<9|y>>>23,y=he+Qe|0,F^=y<<13|y>>>19,y=F+he|0,z^=y<<18|y>>>14,y=He+ne|0,Ae^=y<<7|y>>>25,y=Ae+He|0,$^=y<<9|y>>>23,y=$+Ae|0,ne^=y<<13|y>>>19,y=ne+$|0,He^=y<<18|y>>>14,y=me+Ae|0,_e^=y<<7|y>>>25,y=_e+me|0,he^=y<<9|y>>>23,y=he+_e|0,Ae^=y<<13|y>>>19,y=Ae+he|0,me^=y<<18|y>>>14,y=le+Ee|0,F^=y<<7|y>>>25,y=F+le|0,$^=y<<9|y>>>23,y=$+F|0,Ee^=y<<13|y>>>19,y=Ee+$|0,le^=y<<18|y>>>14,y=z+V|0,ne^=y<<7|y>>>25,y=ne+z|0,J^=y<<9|y>>>23,y=J+ne|0,V^=y<<13|y>>>19,y=V+J|0,z^=y<<18|y>>>14,y=He+Qe|0,Ie^=y<<7|y>>>25,y=Ie+He|0,$e^=y<<9|y>>>23,y=$e+Ie|0,Qe^=y<<13|y>>>19,y=Qe+$e|0,He^=y<<18|y>>>14;p[0]=me>>>0&255,p[1]=me>>>8&255,p[2]=me>>>16&255,p[3]=me>>>24&255,p[4]=le>>>0&255,p[5]=le>>>8&255,p[6]=le>>>16&255,p[7]=le>>>24&255,p[8]=z>>>0&255,p[9]=z>>>8&255,p[10]=z>>>16&255,p[11]=z>>>24&255,p[12]=He>>>0&255,p[13]=He>>>8&255,p[14]=He>>>16&255,p[15]=He>>>24&255,p[16]=F>>>0&255,p[17]=F>>>8&255,p[18]=F>>>16&255,p[19]=F>>>24&255,p[20]=$>>>0&255,p[21]=$>>>8&255,p[22]=$>>>16&255,p[23]=$>>>24&255,p[24]=J>>>0&255,p[25]=J>>>8&255,p[26]=J>>>16&255,p[27]=J>>>24&255,p[28]=V>>>0&255,p[29]=V>>>8&255,p[30]=V>>>16&255,p[31]=V>>>24&255}function O(p,A,m,d){S(p,A,m,d)}function P(p,A,m,d){N(p,A,m,d)}var W=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function X(p,A,m,d,E,B,L){var j=new Uint8Array(16),ie=new Uint8Array(64),ge,de;for(de=0;de<16;de++)j[de]=0;for(de=0;de<8;de++)j[de]=B[de];for(;E>=64;){for(O(ie,j,L,W),de=0;de<64;de++)p[A+de]=m[d+de]^ie[de];for(ge=1,de=8;de<16;de++)ge=ge+(j[de]&255)|0,j[de]=ge&255,ge>>>=8;E-=64,A+=64,d+=64}if(E>0)for(O(ie,j,L,W),de=0;de<E;de++)p[A+de]=m[d+de]^ie[de];return 0}function G(p,A,m,d,E){var B=new Uint8Array(16),L=new Uint8Array(64),j,ie;for(ie=0;ie<16;ie++)B[ie]=0;for(ie=0;ie<8;ie++)B[ie]=d[ie];for(;m>=64;){for(O(L,B,E,W),ie=0;ie<64;ie++)p[A+ie]=L[ie];for(j=1,ie=8;ie<16;ie++)j=j+(B[ie]&255)|0,B[ie]=j&255,j>>>=8;m-=64,A+=64}if(m>0)for(O(L,B,E,W),ie=0;ie<m;ie++)p[A+ie]=L[ie];return 0}function w(p,A,m,d,E){var B=new Uint8Array(32);P(B,d,E,W);for(var L=new Uint8Array(8),j=0;j<8;j++)L[j]=d[j+16];return G(p,A,m,L,B)}function I(p,A,m,d,E,B,L){var j=new Uint8Array(32);P(j,B,L,W);for(var ie=new Uint8Array(8),ge=0;ge<8;ge++)ie[ge]=B[ge+16];return X(p,A,m,d,E,ie,j)}var D=function(p){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var A,m,d,E,B,L,j,ie;A=p[0]&255|(p[1]&255)<<8,this.r[0]=A&8191,m=p[2]&255|(p[3]&255)<<8,this.r[1]=(A>>>13|m<<3)&8191,d=p[4]&255|(p[5]&255)<<8,this.r[2]=(m>>>10|d<<6)&7939,E=p[6]&255|(p[7]&255)<<8,this.r[3]=(d>>>7|E<<9)&8191,B=p[8]&255|(p[9]&255)<<8,this.r[4]=(E>>>4|B<<12)&255,this.r[5]=B>>>1&8190,L=p[10]&255|(p[11]&255)<<8,this.r[6]=(B>>>14|L<<2)&8191,j=p[12]&255|(p[13]&255)<<8,this.r[7]=(L>>>11|j<<5)&8065,ie=p[14]&255|(p[15]&255)<<8,this.r[8]=(j>>>8|ie<<8)&8191,this.r[9]=ie>>>5&127,this.pad[0]=p[16]&255|(p[17]&255)<<8,this.pad[1]=p[18]&255|(p[19]&255)<<8,this.pad[2]=p[20]&255|(p[21]&255)<<8,this.pad[3]=p[22]&255|(p[23]&255)<<8,this.pad[4]=p[24]&255|(p[25]&255)<<8,this.pad[5]=p[26]&255|(p[27]&255)<<8,this.pad[6]=p[28]&255|(p[29]&255)<<8,this.pad[7]=p[30]&255|(p[31]&255)<<8};D.prototype.blocks=function(p,A,m){for(var d=this.fin?0:2048,E,B,L,j,ie,ge,de,et,pe,Ne,Pe,Fe,De,Te,Ue,Le,me,_e,he,Ae=this.h[0],Ee=this.h[1],le=this.h[2],F=this.h[3],$=this.h[4],J=this.h[5],V=this.h[6],z=this.h[7],ne=this.h[8],Ie=this.h[9],$e=this.r[0],Qe=this.r[1],He=this.r[2],y=this.r[3],qe=this.r[4],tt=this.r[5],rt=this.r[6],We=this.r[7],Xe=this.r[8],Je=this.r[9];m>=16;)E=p[A+0]&255|(p[A+1]&255)<<8,Ae+=E&8191,B=p[A+2]&255|(p[A+3]&255)<<8,Ee+=(E>>>13|B<<3)&8191,L=p[A+4]&255|(p[A+5]&255)<<8,le+=(B>>>10|L<<6)&8191,j=p[A+6]&255|(p[A+7]&255)<<8,F+=(L>>>7|j<<9)&8191,ie=p[A+8]&255|(p[A+9]&255)<<8,$+=(j>>>4|ie<<12)&8191,J+=ie>>>1&8191,ge=p[A+10]&255|(p[A+11]&255)<<8,V+=(ie>>>14|ge<<2)&8191,de=p[A+12]&255|(p[A+13]&255)<<8,z+=(ge>>>11|de<<5)&8191,et=p[A+14]&255|(p[A+15]&255)<<8,ne+=(de>>>8|et<<8)&8191,Ie+=et>>>5|d,pe=0,Ne=pe,Ne+=Ae*$e,Ne+=Ee*(5*Je),Ne+=le*(5*Xe),Ne+=F*(5*We),Ne+=$*(5*rt),pe=Ne>>>13,Ne&=8191,Ne+=J*(5*tt),Ne+=V*(5*qe),Ne+=z*(5*y),Ne+=ne*(5*He),Ne+=Ie*(5*Qe),pe+=Ne>>>13,Ne&=8191,Pe=pe,Pe+=Ae*Qe,Pe+=Ee*$e,Pe+=le*(5*Je),Pe+=F*(5*Xe),Pe+=$*(5*We),pe=Pe>>>13,Pe&=8191,Pe+=J*(5*rt),Pe+=V*(5*tt),Pe+=z*(5*qe),Pe+=ne*(5*y),Pe+=Ie*(5*He),pe+=Pe>>>13,Pe&=8191,Fe=pe,Fe+=Ae*He,Fe+=Ee*Qe,Fe+=le*$e,Fe+=F*(5*Je),Fe+=$*(5*Xe),pe=Fe>>>13,Fe&=8191,Fe+=J*(5*We),Fe+=V*(5*rt),Fe+=z*(5*tt),Fe+=ne*(5*qe),Fe+=Ie*(5*y),pe+=Fe>>>13,Fe&=8191,De=pe,De+=Ae*y,De+=Ee*He,De+=le*Qe,De+=F*$e,De+=$*(5*Je),pe=De>>>13,De&=8191,De+=J*(5*Xe),De+=V*(5*We),De+=z*(5*rt),De+=ne*(5*tt),De+=Ie*(5*qe),pe+=De>>>13,De&=8191,Te=pe,Te+=Ae*qe,Te+=Ee*y,Te+=le*He,Te+=F*Qe,Te+=$*$e,pe=Te>>>13,Te&=8191,Te+=J*(5*Je),Te+=V*(5*Xe),Te+=z*(5*We),Te+=ne*(5*rt),Te+=Ie*(5*tt),pe+=Te>>>13,Te&=8191,Ue=pe,Ue+=Ae*tt,Ue+=Ee*qe,Ue+=le*y,Ue+=F*He,Ue+=$*Qe,pe=Ue>>>13,Ue&=8191,Ue+=J*$e,Ue+=V*(5*Je),Ue+=z*(5*Xe),Ue+=ne*(5*We),Ue+=Ie*(5*rt),pe+=Ue>>>13,Ue&=8191,Le=pe,Le+=Ae*rt,Le+=Ee*tt,Le+=le*qe,Le+=F*y,Le+=$*He,pe=Le>>>13,Le&=8191,Le+=J*Qe,Le+=V*$e,Le+=z*(5*Je),Le+=ne*(5*Xe),Le+=Ie*(5*We),pe+=Le>>>13,Le&=8191,me=pe,me+=Ae*We,me+=Ee*rt,me+=le*tt,me+=F*qe,me+=$*y,pe=me>>>13,me&=8191,me+=J*He,me+=V*Qe,me+=z*$e,me+=ne*(5*Je),me+=Ie*(5*Xe),pe+=me>>>13,me&=8191,_e=pe,_e+=Ae*Xe,_e+=Ee*We,_e+=le*rt,_e+=F*tt,_e+=$*qe,pe=_e>>>13,_e&=8191,_e+=J*y,_e+=V*He,_e+=z*Qe,_e+=ne*$e,_e+=Ie*(5*Je),pe+=_e>>>13,_e&=8191,he=pe,he+=Ae*Je,he+=Ee*Xe,he+=le*We,he+=F*rt,he+=$*tt,pe=he>>>13,he&=8191,he+=J*qe,he+=V*y,he+=z*He,he+=ne*Qe,he+=Ie*$e,pe+=he>>>13,he&=8191,pe=(pe<<2)+pe|0,pe=pe+Ne|0,Ne=pe&8191,pe=pe>>>13,Pe+=pe,Ae=Ne,Ee=Pe,le=Fe,F=De,$=Te,J=Ue,V=Le,z=me,ne=_e,Ie=he,A+=16,m-=16;this.h[0]=Ae,this.h[1]=Ee,this.h[2]=le,this.h[3]=F,this.h[4]=$,this.h[5]=J,this.h[6]=V,this.h[7]=z,this.h[8]=ne,this.h[9]=Ie},D.prototype.finish=function(p,A){var m=new Uint16Array(10),d,E,B,L;if(this.leftover){for(L=this.leftover,this.buffer[L++]=1;L<16;L++)this.buffer[L]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(d=this.h[1]>>>13,this.h[1]&=8191,L=2;L<10;L++)this.h[L]+=d,d=this.h[L]>>>13,this.h[L]&=8191;for(this.h[0]+=d*5,d=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=d,d=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=d,m[0]=this.h[0]+5,d=m[0]>>>13,m[0]&=8191,L=1;L<10;L++)m[L]=this.h[L]+d,d=m[L]>>>13,m[L]&=8191;for(m[9]-=8192,E=(d^1)-1,L=0;L<10;L++)m[L]&=E;for(E=~E,L=0;L<10;L++)this.h[L]=this.h[L]&E|m[L];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,B=this.h[0]+this.pad[0],this.h[0]=B&65535,L=1;L<8;L++)B=(this.h[L]+this.pad[L]|0)+(B>>>16)|0,this.h[L]=B&65535;p[A+0]=this.h[0]>>>0&255,p[A+1]=this.h[0]>>>8&255,p[A+2]=this.h[1]>>>0&255,p[A+3]=this.h[1]>>>8&255,p[A+4]=this.h[2]>>>0&255,p[A+5]=this.h[2]>>>8&255,p[A+6]=this.h[3]>>>0&255,p[A+7]=this.h[3]>>>8&255,p[A+8]=this.h[4]>>>0&255,p[A+9]=this.h[4]>>>8&255,p[A+10]=this.h[5]>>>0&255,p[A+11]=this.h[5]>>>8&255,p[A+12]=this.h[6]>>>0&255,p[A+13]=this.h[6]>>>8&255,p[A+14]=this.h[7]>>>0&255,p[A+15]=this.h[7]>>>8&255},D.prototype.update=function(p,A,m){var d,E;if(this.leftover){for(E=16-this.leftover,E>m&&(E=m),d=0;d<E;d++)this.buffer[this.leftover+d]=p[A+d];if(m-=E,A+=E,this.leftover+=E,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(m>=16&&(E=m-m%16,this.blocks(p,A,E),A+=E,m-=E),m){for(d=0;d<m;d++)this.buffer[this.leftover+d]=p[A+d];this.leftover+=m}};function q(p,A,m,d,E,B){var L=new D(B);return L.update(m,d,E),L.finish(p,A),0}function Q(p,A,m,d,E,B){var L=new Uint8Array(16);return q(L,0,m,d,E,B),_(p,A,L,0)}function ae(p,A,m,d,E){var B;if(m<32)return-1;for(I(p,0,A,0,m,d,E),q(p,16,p,32,m-32,p),B=0;B<16;B++)p[B]=0;return 0}function te(p,A,m,d,E){var B,L=new Uint8Array(32);if(m<32||(w(L,0,32,d,E),Q(A,16,A,32,m-32,L)!==0))return-1;for(I(p,0,A,0,m,d,E),B=0;B<32;B++)p[B]=0;return 0}function Z(p,A){var m;for(m=0;m<16;m++)p[m]=A[m]|0}function re(p){var A,m,d=1;for(A=0;A<16;A++)m=p[A]+d+65535,d=Math.floor(m/65536),p[A]=m-d*65536;p[0]+=d-1+37*(d-1)}function ce(p,A,m){for(var d,E=~(m-1),B=0;B<16;B++)d=E&(p[B]^A[B]),p[B]^=d,A[B]^=d}function U(p,A){var m,d,E,B=t(),L=t();for(m=0;m<16;m++)L[m]=A[m];for(re(L),re(L),re(L),d=0;d<2;d++){for(B[0]=L[0]-65517,m=1;m<15;m++)B[m]=L[m]-65535-(B[m-1]>>16&1),B[m-1]&=65535;B[15]=L[15]-32767-(B[14]>>16&1),E=B[15]>>16&1,B[14]&=65535,ce(L,B,1-E)}for(m=0;m<16;m++)p[2*m]=L[m]&255,p[2*m+1]=L[m]>>8}function C(p,A){var m=new Uint8Array(32),d=new Uint8Array(32);return U(m,p),U(d,A),x(m,0,d,0)}function k(p){var A=new Uint8Array(32);return U(A,p),A[0]&1}function M(p,A){var m;for(m=0;m<16;m++)p[m]=A[2*m]+(A[2*m+1]<<8);p[15]&=32767}function Y(p,A,m){for(var d=0;d<16;d++)p[d]=A[d]+m[d]}function oe(p,A,m){for(var d=0;d<16;d++)p[d]=A[d]-m[d]}function ee(p,A,m){var d,E,B=0,L=0,j=0,ie=0,ge=0,de=0,et=0,pe=0,Ne=0,Pe=0,Fe=0,De=0,Te=0,Ue=0,Le=0,me=0,_e=0,he=0,Ae=0,Ee=0,le=0,F=0,$=0,J=0,V=0,z=0,ne=0,Ie=0,$e=0,Qe=0,He=0,y=m[0],qe=m[1],tt=m[2],rt=m[3],We=m[4],Xe=m[5],Je=m[6],xt=m[7],at=m[8],_t=m[9],bt=m[10],yt=m[11],kt=m[12],Ut=m[13],Dt=m[14],Ot=m[15];d=A[0],B+=d*y,L+=d*qe,j+=d*tt,ie+=d*rt,ge+=d*We,de+=d*Xe,et+=d*Je,pe+=d*xt,Ne+=d*at,Pe+=d*_t,Fe+=d*bt,De+=d*yt,Te+=d*kt,Ue+=d*Ut,Le+=d*Dt,me+=d*Ot,d=A[1],L+=d*y,j+=d*qe,ie+=d*tt,ge+=d*rt,de+=d*We,et+=d*Xe,pe+=d*Je,Ne+=d*xt,Pe+=d*at,Fe+=d*_t,De+=d*bt,Te+=d*yt,Ue+=d*kt,Le+=d*Ut,me+=d*Dt,_e+=d*Ot,d=A[2],j+=d*y,ie+=d*qe,ge+=d*tt,de+=d*rt,et+=d*We,pe+=d*Xe,Ne+=d*Je,Pe+=d*xt,Fe+=d*at,De+=d*_t,Te+=d*bt,Ue+=d*yt,Le+=d*kt,me+=d*Ut,_e+=d*Dt,he+=d*Ot,d=A[3],ie+=d*y,ge+=d*qe,de+=d*tt,et+=d*rt,pe+=d*We,Ne+=d*Xe,Pe+=d*Je,Fe+=d*xt,De+=d*at,Te+=d*_t,Ue+=d*bt,Le+=d*yt,me+=d*kt,_e+=d*Ut,he+=d*Dt,Ae+=d*Ot,d=A[4],ge+=d*y,de+=d*qe,et+=d*tt,pe+=d*rt,Ne+=d*We,Pe+=d*Xe,Fe+=d*Je,De+=d*xt,Te+=d*at,Ue+=d*_t,Le+=d*bt,me+=d*yt,_e+=d*kt,he+=d*Ut,Ae+=d*Dt,Ee+=d*Ot,d=A[5],de+=d*y,et+=d*qe,pe+=d*tt,Ne+=d*rt,Pe+=d*We,Fe+=d*Xe,De+=d*Je,Te+=d*xt,Ue+=d*at,Le+=d*_t,me+=d*bt,_e+=d*yt,he+=d*kt,Ae+=d*Ut,Ee+=d*Dt,le+=d*Ot,d=A[6],et+=d*y,pe+=d*qe,Ne+=d*tt,Pe+=d*rt,Fe+=d*We,De+=d*Xe,Te+=d*Je,Ue+=d*xt,Le+=d*at,me+=d*_t,_e+=d*bt,he+=d*yt,Ae+=d*kt,Ee+=d*Ut,le+=d*Dt,F+=d*Ot,d=A[7],pe+=d*y,Ne+=d*qe,Pe+=d*tt,Fe+=d*rt,De+=d*We,Te+=d*Xe,Ue+=d*Je,Le+=d*xt,me+=d*at,_e+=d*_t,he+=d*bt,Ae+=d*yt,Ee+=d*kt,le+=d*Ut,F+=d*Dt,$+=d*Ot,d=A[8],Ne+=d*y,Pe+=d*qe,Fe+=d*tt,De+=d*rt,Te+=d*We,Ue+=d*Xe,Le+=d*Je,me+=d*xt,_e+=d*at,he+=d*_t,Ae+=d*bt,Ee+=d*yt,le+=d*kt,F+=d*Ut,$+=d*Dt,J+=d*Ot,d=A[9],Pe+=d*y,Fe+=d*qe,De+=d*tt,Te+=d*rt,Ue+=d*We,Le+=d*Xe,me+=d*Je,_e+=d*xt,he+=d*at,Ae+=d*_t,Ee+=d*bt,le+=d*yt,F+=d*kt,$+=d*Ut,J+=d*Dt,V+=d*Ot,d=A[10],Fe+=d*y,De+=d*qe,Te+=d*tt,Ue+=d*rt,Le+=d*We,me+=d*Xe,_e+=d*Je,he+=d*xt,Ae+=d*at,Ee+=d*_t,le+=d*bt,F+=d*yt,$+=d*kt,J+=d*Ut,V+=d*Dt,z+=d*Ot,d=A[11],De+=d*y,Te+=d*qe,Ue+=d*tt,Le+=d*rt,me+=d*We,_e+=d*Xe,he+=d*Je,Ae+=d*xt,Ee+=d*at,le+=d*_t,F+=d*bt,$+=d*yt,J+=d*kt,V+=d*Ut,z+=d*Dt,ne+=d*Ot,d=A[12],Te+=d*y,Ue+=d*qe,Le+=d*tt,me+=d*rt,_e+=d*We,he+=d*Xe,Ae+=d*Je,Ee+=d*xt,le+=d*at,F+=d*_t,$+=d*bt,J+=d*yt,V+=d*kt,z+=d*Ut,ne+=d*Dt,Ie+=d*Ot,d=A[13],Ue+=d*y,Le+=d*qe,me+=d*tt,_e+=d*rt,he+=d*We,Ae+=d*Xe,Ee+=d*Je,le+=d*xt,F+=d*at,$+=d*_t,J+=d*bt,V+=d*yt,z+=d*kt,ne+=d*Ut,Ie+=d*Dt,$e+=d*Ot,d=A[14],Le+=d*y,me+=d*qe,_e+=d*tt,he+=d*rt,Ae+=d*We,Ee+=d*Xe,le+=d*Je,F+=d*xt,$+=d*at,J+=d*_t,V+=d*bt,z+=d*yt,ne+=d*kt,Ie+=d*Ut,$e+=d*Dt,Qe+=d*Ot,d=A[15],me+=d*y,_e+=d*qe,he+=d*tt,Ae+=d*rt,Ee+=d*We,le+=d*Xe,F+=d*Je,$+=d*xt,J+=d*at,V+=d*_t,z+=d*bt,ne+=d*yt,Ie+=d*kt,$e+=d*Ut,Qe+=d*Dt,He+=d*Ot,B+=38*_e,L+=38*he,j+=38*Ae,ie+=38*Ee,ge+=38*le,de+=38*F,et+=38*$,pe+=38*J,Ne+=38*V,Pe+=38*z,Fe+=38*ne,De+=38*Ie,Te+=38*$e,Ue+=38*Qe,Le+=38*He,E=1,d=B+E+65535,E=Math.floor(d/65536),B=d-E*65536,d=L+E+65535,E=Math.floor(d/65536),L=d-E*65536,d=j+E+65535,E=Math.floor(d/65536),j=d-E*65536,d=ie+E+65535,E=Math.floor(d/65536),ie=d-E*65536,d=ge+E+65535,E=Math.floor(d/65536),ge=d-E*65536,d=de+E+65535,E=Math.floor(d/65536),de=d-E*65536,d=et+E+65535,E=Math.floor(d/65536),et=d-E*65536,d=pe+E+65535,E=Math.floor(d/65536),pe=d-E*65536,d=Ne+E+65535,E=Math.floor(d/65536),Ne=d-E*65536,d=Pe+E+65535,E=Math.floor(d/65536),Pe=d-E*65536,d=Fe+E+65535,E=Math.floor(d/65536),Fe=d-E*65536,d=De+E+65535,E=Math.floor(d/65536),De=d-E*65536,d=Te+E+65535,E=Math.floor(d/65536),Te=d-E*65536,d=Ue+E+65535,E=Math.floor(d/65536),Ue=d-E*65536,d=Le+E+65535,E=Math.floor(d/65536),Le=d-E*65536,d=me+E+65535,E=Math.floor(d/65536),me=d-E*65536,B+=E-1+37*(E-1),E=1,d=B+E+65535,E=Math.floor(d/65536),B=d-E*65536,d=L+E+65535,E=Math.floor(d/65536),L=d-E*65536,d=j+E+65535,E=Math.floor(d/65536),j=d-E*65536,d=ie+E+65535,E=Math.floor(d/65536),ie=d-E*65536,d=ge+E+65535,E=Math.floor(d/65536),ge=d-E*65536,d=de+E+65535,E=Math.floor(d/65536),de=d-E*65536,d=et+E+65535,E=Math.floor(d/65536),et=d-E*65536,d=pe+E+65535,E=Math.floor(d/65536),pe=d-E*65536,d=Ne+E+65535,E=Math.floor(d/65536),Ne=d-E*65536,d=Pe+E+65535,E=Math.floor(d/65536),Pe=d-E*65536,d=Fe+E+65535,E=Math.floor(d/65536),Fe=d-E*65536,d=De+E+65535,E=Math.floor(d/65536),De=d-E*65536,d=Te+E+65535,E=Math.floor(d/65536),Te=d-E*65536,d=Ue+E+65535,E=Math.floor(d/65536),Ue=d-E*65536,d=Le+E+65535,E=Math.floor(d/65536),Le=d-E*65536,d=me+E+65535,E=Math.floor(d/65536),me=d-E*65536,B+=E-1+37*(E-1),p[0]=B,p[1]=L,p[2]=j,p[3]=ie,p[4]=ge,p[5]=de,p[6]=et,p[7]=pe,p[8]=Ne,p[9]=Pe,p[10]=Fe,p[11]=De,p[12]=Te,p[13]=Ue,p[14]=Le,p[15]=me}function Ye(p,A){ee(p,A,A)}function gt(p,A){var m=t(),d;for(d=0;d<16;d++)m[d]=A[d];for(d=253;d>=0;d--)Ye(m,m),d!==2&&d!==4&&ee(m,m,A);for(d=0;d<16;d++)p[d]=m[d]}function lr(p,A){var m=t(),d;for(d=0;d<16;d++)m[d]=A[d];for(d=250;d>=0;d--)Ye(m,m),d!==1&&ee(m,m,A);for(d=0;d<16;d++)p[d]=m[d]}function en(p,A,m){var d=new Uint8Array(32),E=new Float64Array(80),B,L,j=t(),ie=t(),ge=t(),de=t(),et=t(),pe=t();for(L=0;L<31;L++)d[L]=A[L];for(d[31]=A[31]&127|64,d[0]&=248,M(E,m),L=0;L<16;L++)ie[L]=E[L],de[L]=j[L]=ge[L]=0;for(j[0]=de[0]=1,L=254;L>=0;--L)B=d[L>>>3]>>>(L&7)&1,ce(j,ie,B),ce(ge,de,B),Y(et,j,ge),oe(j,j,ge),Y(ge,ie,de),oe(ie,ie,de),Ye(de,et),Ye(pe,j),ee(j,ge,j),ee(ge,ie,et),Y(et,j,ge),oe(j,j,ge),Ye(ie,j),oe(ge,de,pe),ee(j,ge,a),Y(j,j,de),ee(ge,ge,j),ee(j,de,pe),ee(de,ie,E),Ye(ie,et),ce(j,ie,B),ce(ge,de,B);for(L=0;L<16;L++)E[L+16]=j[L],E[L+32]=ge[L],E[L+48]=ie[L],E[L+64]=de[L];var Ne=E.subarray(32),Pe=E.subarray(16);return gt(Ne,Ne),ee(Pe,Pe,Ne),U(p,Pe),0}function tn(p,A){return en(p,A,i)}function Ar(p,A){return e(A,32),tn(p,A)}function rn(p,A,m){var d=new Uint8Array(32);return en(d,m,A),P(p,n,d,W)}var On=ae,wi=te;function Mn(p,A,m,d,E,B){var L=new Uint8Array(32);return rn(L,E,B),On(p,A,m,d,L)}function nn(p,A,m,d,E,B){var L=new Uint8Array(32);return rn(L,E,B),wi(p,A,m,d,L)}var sn=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function K(p,A,m,d){for(var E=new Int32Array(16),B=new Int32Array(16),L,j,ie,ge,de,et,pe,Ne,Pe,Fe,De,Te,Ue,Le,me,_e,he,Ae,Ee,le,F,$,J,V,z,ne,Ie=p[0],$e=p[1],Qe=p[2],He=p[3],y=p[4],qe=p[5],tt=p[6],rt=p[7],We=A[0],Xe=A[1],Je=A[2],xt=A[3],at=A[4],_t=A[5],bt=A[6],yt=A[7],kt=0;d>=128;){for(Ee=0;Ee<16;Ee++)le=8*Ee+kt,E[Ee]=m[le+0]<<24|m[le+1]<<16|m[le+2]<<8|m[le+3],B[Ee]=m[le+4]<<24|m[le+5]<<16|m[le+6]<<8|m[le+7];for(Ee=0;Ee<80;Ee++)if(L=Ie,j=$e,ie=Qe,ge=He,de=y,et=qe,pe=tt,Ne=rt,Pe=We,Fe=Xe,De=Je,Te=xt,Ue=at,Le=_t,me=bt,_e=yt,F=rt,$=yt,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=(y>>>14|at<<18)^(y>>>18|at<<14)^(at>>>9|y<<23),$=(at>>>14|y<<18)^(at>>>18|y<<14)^(y>>>9|at<<23),J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,F=y&qe^~y&tt,$=at&_t^~at&bt,J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,F=sn[Ee*2],$=sn[Ee*2+1],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,F=E[Ee%16],$=B[Ee%16],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,he=z&65535|ne<<16,Ae=J&65535|V<<16,F=he,$=Ae,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=(Ie>>>28|We<<4)^(We>>>2|Ie<<30)^(We>>>7|Ie<<25),$=(We>>>28|Ie<<4)^(Ie>>>2|We<<30)^(Ie>>>7|We<<25),J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,F=Ie&$e^Ie&Qe^$e&Qe,$=We&Xe^We&Je^Xe&Je,J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,Ne=z&65535|ne<<16,_e=J&65535|V<<16,F=ge,$=Te,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=he,$=Ae,J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,ge=z&65535|ne<<16,Te=J&65535|V<<16,$e=L,Qe=j,He=ie,y=ge,qe=de,tt=et,rt=pe,Ie=Ne,Xe=Pe,Je=Fe,xt=De,at=Te,_t=Ue,bt=Le,yt=me,We=_e,Ee%16===15)for(le=0;le<16;le++)F=E[le],$=B[le],J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=E[(le+9)%16],$=B[(le+9)%16],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,he=E[(le+1)%16],Ae=B[(le+1)%16],F=(he>>>1|Ae<<31)^(he>>>8|Ae<<24)^he>>>7,$=(Ae>>>1|he<<31)^(Ae>>>8|he<<24)^(Ae>>>7|he<<25),J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,he=E[(le+14)%16],Ae=B[(le+14)%16],F=(he>>>19|Ae<<13)^(Ae>>>29|he<<3)^he>>>6,$=(Ae>>>19|he<<13)^(he>>>29|Ae<<3)^(Ae>>>6|he<<26),J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,E[le]=z&65535|ne<<16,B[le]=J&65535|V<<16;F=Ie,$=We,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=p[0],$=A[0],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,p[0]=Ie=z&65535|ne<<16,A[0]=We=J&65535|V<<16,F=$e,$=Xe,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=p[1],$=A[1],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,p[1]=$e=z&65535|ne<<16,A[1]=Xe=J&65535|V<<16,F=Qe,$=Je,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=p[2],$=A[2],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,p[2]=Qe=z&65535|ne<<16,A[2]=Je=J&65535|V<<16,F=He,$=xt,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=p[3],$=A[3],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,p[3]=He=z&65535|ne<<16,A[3]=xt=J&65535|V<<16,F=y,$=at,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=p[4],$=A[4],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,p[4]=y=z&65535|ne<<16,A[4]=at=J&65535|V<<16,F=qe,$=_t,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=p[5],$=A[5],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,p[5]=qe=z&65535|ne<<16,A[5]=_t=J&65535|V<<16,F=tt,$=bt,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=p[6],$=A[6],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,p[6]=tt=z&65535|ne<<16,A[6]=bt=J&65535|V<<16,F=rt,$=yt,J=$&65535,V=$>>>16,z=F&65535,ne=F>>>16,F=p[7],$=A[7],J+=$&65535,V+=$>>>16,z+=F&65535,ne+=F>>>16,V+=J>>>16,z+=V>>>16,ne+=z>>>16,p[7]=rt=z&65535|ne<<16,A[7]=yt=J&65535|V<<16,kt+=128,d-=128}return d}function fe(p,A,m){var d=new Int32Array(8),E=new Int32Array(8),B=new Uint8Array(256),L,j=m;for(d[0]=1779033703,d[1]=3144134277,d[2]=1013904242,d[3]=2773480762,d[4]=1359893119,d[5]=2600822924,d[6]=528734635,d[7]=1541459225,E[0]=4089235720,E[1]=2227873595,E[2]=4271175723,E[3]=1595750129,E[4]=2917565137,E[5]=725511199,E[6]=4215389547,E[7]=327033209,K(d,E,A,m),m%=128,L=0;L<m;L++)B[L]=A[j-m+L];for(B[m]=128,m=256-128*(m<112?1:0),B[m-9]=0,g(B,m-8,j/536870912|0,j<<3),K(d,E,B,m),L=0;L<8;L++)g(p,8*L,d[L],E[L]);return 0}function be(p,A){var m=t(),d=t(),E=t(),B=t(),L=t(),j=t(),ie=t(),ge=t(),de=t();oe(m,p[1],p[0]),oe(de,A[1],A[0]),ee(m,m,de),Y(d,p[0],p[1]),Y(de,A[0],A[1]),ee(d,d,de),ee(E,p[3],A[3]),ee(E,E,f),ee(B,p[2],A[2]),Y(B,B,B),oe(L,d,m),oe(j,B,E),Y(ie,B,E),Y(ge,d,m),ee(p[0],L,j),ee(p[1],ge,ie),ee(p[2],ie,j),ee(p[3],L,ge)}function Re(p,A,m){var d;for(d=0;d<4;d++)ce(p[d],A[d],m)}function je(p,A){var m=t(),d=t(),E=t();gt(E,A[2]),ee(m,A[0],E),ee(d,A[1],E),U(p,d),p[31]^=k(m)<<7}function It(p,A,m){var d,E;for(Z(p[0],s),Z(p[1],o),Z(p[2],o),Z(p[3],s),E=255;E>=0;--E)d=m[E/8|0]>>(E&7)&1,Re(p,A,d),be(A,p),be(p,p),Re(p,A,d)}function ur(p,A){var m=[t(),t(),t(),t()];Z(m[0],l),Z(m[1],u),Z(m[2],o),ee(m[3],l,u),It(p,m,A)}function jt(p,A,m){var d=new Uint8Array(64),E=[t(),t(),t(),t()],B;for(m||e(A,32),fe(d,A,32),d[0]&=248,d[31]&=127,d[31]|=64,ur(E,d),je(p,E),B=0;B<32;B++)A[B+32]=p[B];return 0}var on=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function st(p,A){var m,d,E,B;for(d=63;d>=32;--d){for(m=0,E=d-32,B=d-12;E<B;++E)A[E]+=m-16*A[d]*on[E-(d-32)],m=A[E]+128>>8,A[E]-=m*256;A[E]+=m,A[d]=0}for(m=0,E=0;E<32;E++)A[E]+=m-(A[31]>>4)*on[E],m=A[E]>>8,A[E]&=255;for(E=0;E<32;E++)A[E]-=m*on[E];for(d=0;d<32;d++)A[d+1]+=A[d]>>8,p[d]=A[d]&255}function Bt(p){var A=new Float64Array(64),m;for(m=0;m<64;m++)A[m]=p[m];for(m=0;m<64;m++)p[m]=0;st(p,A)}function vt(p,A,m,d){var E=new Uint8Array(64),B=new Uint8Array(64),L=new Uint8Array(64),j,ie,ge=new Float64Array(64),de=[t(),t(),t(),t()];fe(E,d,32),E[0]&=248,E[31]&=127,E[31]|=64;var et=m+64;for(j=0;j<m;j++)p[64+j]=A[j];for(j=0;j<32;j++)p[32+j]=E[32+j];for(fe(L,p.subarray(32),m+32),Bt(L),ur(de,L),je(p,de),j=32;j<64;j++)p[j]=d[j];for(fe(B,p,m+64),Bt(B),j=0;j<64;j++)ge[j]=0;for(j=0;j<32;j++)ge[j]=L[j];for(j=0;j<32;j++)for(ie=0;ie<32;ie++)ge[j+ie]+=B[j]*E[ie];return st(p.subarray(32),ge),et}function At(p,A){var m=t(),d=t(),E=t(),B=t(),L=t(),j=t(),ie=t();return Z(p[2],o),M(p[1],A),Ye(E,p[1]),ee(B,E,c),oe(E,E,p[2]),Y(B,p[2],B),Ye(L,B),Ye(j,L),ee(ie,j,L),ee(m,ie,E),ee(m,m,B),lr(m,m),ee(m,m,E),ee(m,m,B),ee(m,m,B),ee(p[0],m,B),Ye(d,p[0]),ee(d,d,B),C(d,E)&&ee(p[0],p[0],h),Ye(d,p[0]),ee(d,d,B),C(d,E)?-1:(k(p[0])===A[31]>>7&&oe(p[0],s,p[0]),ee(p[3],p[0],p[1]),0)}function lt(p,A,m,d){var E,B,L=new Uint8Array(32),j=new Uint8Array(64),ie=[t(),t(),t(),t()],ge=[t(),t(),t(),t()];if(B=-1,m<64||At(ge,d))return-1;for(E=0;E<m;E++)p[E]=A[E];for(E=0;E<32;E++)p[E+32]=d[E];if(fe(j,p,m),Bt(j),It(ie,ge,j),ur(ge,A.subarray(32)),be(ie,ge),je(L,ie),m-=64,x(A,0,L,0)){for(E=0;E<m;E++)p[E]=0;return-1}for(E=0;E<m;E++)p[E]=A[E+64];return B=m,B}var Zt=32,Et=24,Wr=32,an=16,Fn=32,Ii=32,$n=32,Hn=32,Bs=32,Wa=Et,Vd=Wr,Gd=an,Er=64,qr=32,cn=64,Rs=32,Ns=64;r.lowlevel={crypto_core_hsalsa20:P,crypto_stream_xor:I,crypto_stream:w,crypto_stream_salsa20_xor:X,crypto_stream_salsa20:G,crypto_onetimeauth:q,crypto_onetimeauth_verify:Q,crypto_verify_16:_,crypto_verify_32:x,crypto_secretbox:ae,crypto_secretbox_open:te,crypto_scalarmult:en,crypto_scalarmult_base:tn,crypto_box_beforenm:rn,crypto_box_afternm:On,crypto_box:Mn,crypto_box_open:nn,crypto_box_keypair:Ar,crypto_hash:fe,crypto_sign:vt,crypto_sign_keypair:jt,crypto_sign_open:lt,crypto_secretbox_KEYBYTES:Zt,crypto_secretbox_NONCEBYTES:Et,crypto_secretbox_ZEROBYTES:Wr,crypto_secretbox_BOXZEROBYTES:an,crypto_scalarmult_BYTES:Fn,crypto_scalarmult_SCALARBYTES:Ii,crypto_box_PUBLICKEYBYTES:$n,crypto_box_SECRETKEYBYTES:Hn,crypto_box_BEFORENMBYTES:Bs,crypto_box_NONCEBYTES:Wa,crypto_box_ZEROBYTES:Vd,crypto_box_BOXZEROBYTES:Gd,crypto_sign_BYTES:Er,crypto_sign_PUBLICKEYBYTES:qr,crypto_sign_SECRETKEYBYTES:cn,crypto_sign_SEEDBYTES:Rs,crypto_hash_BYTES:Ns};function qa(p,A){if(p.length!==Zt)throw new Error("bad key size");if(A.length!==Et)throw new Error("bad nonce size")}function Yd(p,A){if(p.length!==$n)throw new Error("bad public key size");if(A.length!==Hn)throw new Error("bad secret key size")}function zt(){var p,A;for(A=0;A<arguments.length;A++)if((p=Object.prototype.toString.call(arguments[A]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+p+", use Uint8Array")}function Ka(p){for(var A=0;A<p.length;A++)p[A]=0}r.util||(r.util={},r.util.decodeUTF8=r.util.encodeUTF8=r.util.encodeBase64=r.util.decodeBase64=function(){throw new Error("nacl.util moved into separate package: https://github.com/dchest/tweetnacl-util-js")}),r.randomBytes=function(p){var A=new Uint8Array(p);return e(A,p),A},r.secretbox=function(p,A,m){zt(p,A,m),qa(m,A);for(var d=new Uint8Array(Wr+p.length),E=new Uint8Array(d.length),B=0;B<p.length;B++)d[B+Wr]=p[B];return ae(E,d,d.length,A,m),E.subarray(an)},r.secretbox.open=function(p,A,m){zt(p,A,m),qa(m,A);for(var d=new Uint8Array(an+p.length),E=new Uint8Array(d.length),B=0;B<p.length;B++)d[B+an]=p[B];return d.length<32||te(E,d,d.length,A,m)!==0?!1:E.subarray(Wr)},r.secretbox.keyLength=Zt,r.secretbox.nonceLength=Et,r.secretbox.overheadLength=an,r.scalarMult=function(p,A){if(zt(p,A),p.length!==Ii)throw new Error("bad n size");if(A.length!==Fn)throw new Error("bad p size");var m=new Uint8Array(Fn);return en(m,p,A),m},r.scalarMult.base=function(p){if(zt(p),p.length!==Ii)throw new Error("bad n size");var A=new Uint8Array(Fn);return tn(A,p),A},r.scalarMult.scalarLength=Ii,r.scalarMult.groupElementLength=Fn,r.box=function(p,A,m,d){var E=r.box.before(m,d);return r.secretbox(p,A,E)},r.box.before=function(p,A){zt(p,A),Yd(p,A);var m=new Uint8Array(Bs);return rn(m,p,A),m},r.box.after=r.secretbox,r.box.open=function(p,A,m,d){var E=r.box.before(m,d);return r.secretbox.open(p,A,E)},r.box.open.after=r.secretbox.open,r.box.keyPair=function(){var p=new Uint8Array($n),A=new Uint8Array(Hn);return Ar(p,A),{publicKey:p,secretKey:A}},r.box.keyPair.fromSecretKey=function(p){if(zt(p),p.length!==Hn)throw new Error("bad secret key size");var A=new Uint8Array($n);return tn(A,p),{publicKey:A,secretKey:new Uint8Array(p)}},r.box.publicKeyLength=$n,r.box.secretKeyLength=Hn,r.box.sharedKeyLength=Bs,r.box.nonceLength=Wa,r.box.overheadLength=r.secretbox.overheadLength,r.sign=function(p,A){if(zt(p,A),A.length!==cn)throw new Error("bad secret key size");var m=new Uint8Array(Er+p.length);return vt(m,p,p.length,A),m},r.sign.open=function(p,A){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(zt(p,A),A.length!==qr)throw new Error("bad public key size");var m=new Uint8Array(p.length),d=lt(m,p,p.length,A);if(d<0)return null;for(var E=new Uint8Array(d),B=0;B<E.length;B++)E[B]=m[B];return E},r.sign.detached=function(p,A){for(var m=r.sign(p,A),d=new Uint8Array(Er),E=0;E<d.length;E++)d[E]=m[E];return d},r.sign.detached.verify=function(p,A,m){if(zt(p,A,m),A.length!==Er)throw new Error("bad signature size");if(m.length!==qr)throw new Error("bad public key size");var d=new Uint8Array(Er+p.length),E=new Uint8Array(Er+p.length),B;for(B=0;B<Er;B++)d[B]=A[B];for(B=0;B<p.length;B++)d[B+Er]=p[B];return lt(E,d,d.length,m)>=0},r.sign.keyPair=function(){var p=new Uint8Array(qr),A=new Uint8Array(cn);return jt(p,A),{publicKey:p,secretKey:A}},r.sign.keyPair.fromSecretKey=function(p){if(zt(p),p.length!==cn)throw new Error("bad secret key size");for(var A=new Uint8Array(qr),m=0;m<A.length;m++)A[m]=p[32+m];return{publicKey:A,secretKey:new Uint8Array(p)}},r.sign.keyPair.fromSeed=function(p){if(zt(p),p.length!==Rs)throw new Error("bad seed size");for(var A=new Uint8Array(qr),m=new Uint8Array(cn),d=0;d<32;d++)m[d]=p[d];return jt(A,m,!0),{publicKey:A,secretKey:m}},r.sign.publicKeyLength=qr,r.sign.secretKeyLength=cn,r.sign.seedLength=Rs,r.sign.signatureLength=Er,r.hash=function(p){zt(p);var A=new Uint8Array(Ns);return fe(A,p,p.length),A},r.hash.hashLength=Ns,r.verify=function(p,A){return zt(p,A),p.length===0||A.length===0||p.length!==A.length?!1:b(p,0,A,0,p.length)===0},r.setPRNG=function(p){e=p},(function(){var p=typeof self<"u"?self.crypto||self.msCrypto:null;if(p&&p.getRandomValues){var A=65536;r.setPRNG(function(m,d){var E,B=new Uint8Array(d);for(E=0;E<d;E+=A)p.getRandomValues(B.subarray(E,E+Math.min(d-E,A)));for(E=0;E<d;E++)m[E]=B[E];Ka(B)})}else typeof require<"u"&&(p=require("crypto"),p&&p.randomBytes&&r.setPRNG(function(m,d){var E,B=p.randomBytes(d);for(E=0;E<d;E++)m[E]=B[E];Ka(B)}))})()})(typeof Fi<"u"&&Fi.exports?Fi.exports:self.nacl=self.nacl||{})});var Ks=ot((vy,Jf)=>{"use strict";var Qs=Xf().lowlevel.crypto_hash,br=0,Yr=function(){this.S=[new Uint32Array([3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946]),new Uint32Array([1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055]),new Uint32Array([3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504]),new Uint32Array([976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462])],this.P=new Uint32Array([608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731])};function Hi(r,t,e){return(r[0][t[e+3]]+r[1][t[e+2]]^r[2][t[e+1]])+r[3][t[e]]}Yr.prototype.encipher=function(r,t){t===void 0&&(t=new Uint8Array(r.buffer),r.byteOffset!==0&&(t=t.subarray(r.byteOffset))),r[0]^=this.P[0];for(var e=1;e<16;e+=2)r[1]^=Hi(this.S,t,0)^this.P[e],r[0]^=Hi(this.S,t,4)^this.P[e+1];var n=r[0];r[0]=r[1]^this.P[17],r[1]=n};Yr.prototype.decipher=function(r){var t=new Uint8Array(r.buffer);r.byteOffset!==0&&(t=t.subarray(r.byteOffset)),r[0]^=this.P[17];for(var e=16;e>0;e-=2)r[1]^=Hi(this.S,t,0)^this.P[e],r[0]^=Hi(this.S,t,4)^this.P[e-1];var n=r[0];r[0]=r[1]^this.P[0],r[1]=n};function Gr(r,t){var e,n=0;for(e=0;e<4;e++,br++)br>=t&&(br=0),n=n<<8|r[br];return n}Yr.prototype.expand0state=function(r,t){var e=new Uint32Array(2),n,i,s=new Uint8Array(e.buffer);for(n=0,br=0;n<18;n++)this.P[n]^=Gr(r,t);for(br=0,n=0;n<18;n+=2)this.encipher(e,s),this.P[n]=e[0],this.P[n+1]=e[1];for(n=0;n<4;n++)for(i=0;i<256;i+=2)this.encipher(e,s),this.S[n][i]=e[0],this.S[n][i+1]=e[1]};Yr.prototype.expandstate=function(r,t,e,n){var i=new Uint32Array(2),s,o;for(s=0,br=0;s<18;s++)this.P[s]^=Gr(e,n);for(s=0,br=0;s<18;s+=2)i[0]^=Gr(r,t),i[1]^=Gr(r,t),this.encipher(i),this.P[s]=i[0],this.P[s+1]=i[1];for(s=0;s<4;s++)for(o=0;o<256;o+=2)i[0]^=Gr(r,t),i[1]^=Gr(r,t),this.encipher(i),this.S[s][o]=i[0],this.S[s][o+1]=i[1];br=0};Yr.prototype.enc=function(r,t){for(var e=0;e<t;e++)this.encipher(r.subarray(e*2))};Yr.prototype.dec=function(r,t){for(var e=0;e<t;e++)this.decipher(r.subarray(e*2))};var $i=8,Ws=32;function qs(r,t,e){var n=new Yr,i=new Uint32Array($i),s,o=new Uint8Array([79,120,121,99,104,114,111,109,97,116,105,99,66,108,111,119,102,105,115,104,83,119,97,116,68,121,110,97,109,105,116,101]);for(n.expandstate(t,64,r,64),s=0;s<64;s++)n.expand0state(t,64),n.expand0state(r,64);for(s=0;s<$i;s++)i[s]=Gr(o,o.byteLength);for(s=0;s<64;s++)n.enc(i,i.byteLength/8);for(s=0;s<$i;s++)e[4*s+3]=i[s]>>>24,e[4*s+2]=i[s]>>>16,e[4*s+1]=i[s]>>>8,e[4*s+0]=i[s]}function Kh(r,t,e,n,i,s,o){var a=new Uint8Array(64),c=new Uint8Array(64),f=new Uint8Array(Ws),l=new Uint8Array(Ws),u=new Uint8Array(n+4),h,g,b,_,x,S,N=s;if(o<1||t===0||n===0||s===0||s>f.byteLength*f.byteLength||n>1<<20)return-1;for(_=Math.floor((s+f.byteLength-1)/f.byteLength),b=Math.floor((s+_-1)/_),h=0;h<n;h++)u[h]=e[h];for(Qs(a,r,t),S=1;s>0;S++){for(u[n+0]=S>>>24,u[n+1]=S>>>16,u[n+2]=S>>>8,u[n+3]=S,Qs(c,u,n+4),qs(a,c,l),h=f.byteLength;h--;)f[h]=l[h];for(h=1;h<o;h++)for(Qs(c,l,l.byteLength),qs(a,c,l),g=0;g<f.byteLength;g++)f[g]^=l[g];for(b=Math.min(b,s),h=0;h<b&&(x=h*_+(S-1),!(x>=N));h++)i[x]=f[h];s-=h}return 0}Jf.exports={BLOCKS:$i,HASHSIZE:Ws,hash:qs,pbkdf:Kh}});var xr=ot((ky,Wi)=>{"use strict";var yr=require("crypto"),gn;try{gn=require("cpu-features")()}catch{}var{bindingAvailable:Zf,CIPHER_INFO:Vh,MAC_INFO:Gh}=Nr(),el=(()=>{if(typeof yr.sign=="function"&&typeof yr.verify=="function"){let r=`-----BEGIN PRIVATE KEY-----\r
56
2
  MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
57
- -----END PRIVATE KEY-----`,t=Buffer.from("a"),e,r;try{e=Sr.sign(null,t,n),r=Sr.verify(null,t,n,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&r===!0}return!1})(),Xu=typeof Sr.diffieHellman=="function"&&typeof Sr.generateKeyPairSync=="function"&&typeof Sr.createPublicKey=="function",Wi=["ecdh-sha2-nistp256","ecdh-sha2-nistp384","ecdh-sha2-nistp521","diffie-hellman-group-exchange-sha256","diffie-hellman-group14-sha256","diffie-hellman-group15-sha512","diffie-hellman-group16-sha512","diffie-hellman-group17-sha512","diffie-hellman-group18-sha512"];Xu&&(Wi.unshift("curve25519-sha256"),Wi.unshift("curve25519-sha256@libssh.org"));var Mp=Wi.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),zs=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];zu&&zs.unshift("ssh-ed25519");var Fp=zs.concat(["ssh-dss"]),Ju=(()=>{let n=Sr.getCiphers();return t=>n.includes(Dp[t].sslName)})(),Tr=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];An&&An.flags&&!An.flags.aes?ju?Tr.unshift("chacha20-poly1305@openssh.com"):Tr.push("chacha20-poly1305@openssh.com"):ju&&An&&An.arch==="x86"?Tr.splice(4,0,"chacha20-poly1305@openssh.com"):Tr.push("chacha20-poly1305@openssh.com");Tr=Tr.filter(Ju);var Qp=Tr.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(Ju)),Zu=(()=>{let n=Sr.getHashes();return t=>n.includes(Hp[t].sslName)})(),el=["hmac-sha2-256-etm@openssh.com","hmac-sha2-512-etm@openssh.com","hmac-sha1-etm@openssh.com","hmac-sha2-256","hmac-sha2-512","hmac-sha1"].filter(Zu),$p=el.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(Zu)),tl=["none","zlib@openssh.com","zlib"],Wp=tl.concat([]),mn={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};qi.exports={MESSAGE:{DISCONNECT:1,IGNORE:2,UNIMPLEMENTED:3,DEBUG:4,SERVICE_REQUEST:5,SERVICE_ACCEPT:6,EXT_INFO:7,KEXINIT:20,NEWKEYS:21,KEXDH_INIT:30,KEXDH_REPLY:31,KEXDH_GEX_GROUP:31,KEXDH_GEX_INIT:32,KEXDH_GEX_REPLY:33,KEXDH_GEX_REQUEST:34,KEXECDH_INIT:30,KEXECDH_REPLY:31,USERAUTH_REQUEST:50,USERAUTH_FAILURE:51,USERAUTH_SUCCESS:52,USERAUTH_BANNER:53,USERAUTH_PASSWD_CHANGEREQ:60,USERAUTH_PK_OK:60,USERAUTH_INFO_REQUEST:60,USERAUTH_INFO_RESPONSE:61,GLOBAL_REQUEST:80,REQUEST_SUCCESS:81,REQUEST_FAILURE:82,CHANNEL_OPEN:90,CHANNEL_OPEN_CONFIRMATION:91,CHANNEL_OPEN_FAILURE:92,CHANNEL_WINDOW_ADJUST:93,CHANNEL_DATA:94,CHANNEL_EXTENDED_DATA:95,CHANNEL_EOF:96,CHANNEL_CLOSE:97,CHANNEL_REQUEST:98,CHANNEL_SUCCESS:99,CHANNEL_FAILURE:100},DISCONNECT_REASON:{HOST_NOT_ALLOWED_TO_CONNECT:1,PROTOCOL_ERROR:2,KEY_EXCHANGE_FAILED:3,RESERVED:4,MAC_ERROR:5,COMPRESSION_ERROR:6,SERVICE_NOT_AVAILABLE:7,PROTOCOL_VERSION_NOT_SUPPORTED:8,HOST_KEY_NOT_VERIFIABLE:9,CONNECTION_LOST:10,BY_APPLICATION:11,TOO_MANY_CONNECTIONS:12,AUTH_CANCELED_BY_USER:13,NO_MORE_AUTH_METHODS_AVAILABLE:14,ILLEGAL_USER_NAME:15},DISCONNECT_REASON_STR:void 0,CHANNEL_OPEN_FAILURE:{ADMINISTRATIVELY_PROHIBITED:1,CONNECT_FAILED:2,UNKNOWN_CHANNEL_TYPE:3,RESOURCE_SHORTAGE:4},TERMINAL_MODE:{TTY_OP_END:0,VINTR:1,VQUIT:2,VERASE:3,VKILL:4,VEOF:5,VEOL:6,VEOL2:7,VSTART:8,VSTOP:9,VSUSP:10,VDSUSP:11,VREPRINT:12,VWERASE:13,VLNEXT:14,VFLUSH:15,VSWTCH:16,VSTATUS:17,VDISCARD:18,IGNPAR:30,PARMRK:31,INPCK:32,ISTRIP:33,INLCR:34,IGNCR:35,ICRNL:36,IUCLC:37,IXON:38,IXANY:39,IXOFF:40,IMAXBEL:41,ISIG:50,ICANON:51,XCASE:52,ECHO:53,ECHOE:54,ECHOK:55,ECHONL:56,NOFLSH:57,TOSTOP:58,IEXTEN:59,ECHOCTL:60,ECHOKE:61,PENDIN:62,OPOST:70,OLCUC:71,ONLCR:72,OCRNL:73,ONOCR:74,ONLRET:75,CS7:90,CS8:91,PARENB:92,PARODD:93,TTY_OP_ISPEED:128,TTY_OP_OSPEED:129},CHANNEL_EXTENDED_DATATYPE:{STDERR:1},SIGNALS:["ABRT","ALRM","FPE","HUP","ILL","INT","QUIT","SEGV","TERM","USR1","USR2","KILL","PIPE"].reduce((n,t)=>({...n,[t]:1}),{}),COMPAT:mn,COMPAT_CHECKS:[["Cisco-1.25",mn.BAD_DHGEX],[/^Cisco-1[.]/,mn.BUG_DHGEX_LARGE],[/^[0-9.]+$/,mn.OLD_EXIT],[/^OpenSSH_5[.][0-9]+/,mn.DYN_RPORT_BUG],[/^OpenSSH_7[.]4/,mn.IMPLY_RSA_SHA2_SIGALGS]],DEFAULT_KEX:Wi,SUPPORTED_KEX:Mp,DEFAULT_SERVER_HOST_KEY:zs,SUPPORTED_SERVER_HOST_KEY:Fp,DEFAULT_CIPHER:Tr,SUPPORTED_CIPHER:Qp,DEFAULT_MAC:el,SUPPORTED_MAC:$p,DEFAULT_COMPRESSION:tl,SUPPORTED_COMPRESSION:Wp,curve25519Supported:Xu,eddsaSupported:zu};qi.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(qi.exports.DISCONNECT_REASON)).reduce((n,[t,e])=>({...n,[e]:t}),{})});var or=ot((wb,sl)=>{"use strict";var ir=Gn().Ber,Ki,il=Buffer[Symbol.species],qp=Object.getPrototypeOf(Uint8Array.prototype).fill;function rl(n,t){return n[t++]*16777216+n[t++]*65536+n[t++]*256+n[t]}function Yn(n,t,e,r,i){i||(i=0),r>n.length&&(r=n.length);let s=r-e,o=t.length-i;return s>o&&(s=o),t.set(new Uint8Array(n.buffer,n.byteOffset+e,s),i),s}function Vn(n,t,e){return e===void 0&&(e=n.length),new il(n.buffer,n.byteOffset+t,e-t)}function Js(){let n=0,t,e={init:(r,i)=>{t=r,n=typeof i=="number"?i:0},pos:()=>n,length:()=>t?t.length:0,avail:()=>t&&n<t.length?t.length-n:0,clear:()=>{t=void 0},readUInt32BE:()=>{if(!(!t||n+3>=t.length))return t[n++]*16777216+t[n++]*65536+t[n++]*256+t[n++]},readUInt64BE:r=>{if(!(!t||n+7>=t.length))switch(r){case"always":return BigInt(`0x${t.hexSlice(n,n+=8)}`);case"maybe":if(t[n]>31)return BigInt(`0x${t.hexSlice(n,n+=8)}`);default:return t[n++]*72057594037927940+t[n++]*281474976710656+t[n++]*1099511627776+t[n++]*4294967296+t[n++]*16777216+t[n++]*65536+t[n++]*256+t[n++]}},skip:r=>{t&&r>0&&(n+=r)},skipString:()=>{let r=e.readUInt32BE();if(r!==void 0)return n+=r,n<=t.length?r:void 0},readByte:()=>{if(t&&n<t.length)return t[n++]},readBool:()=>{if(t&&n<t.length)return!!t[n++]},readList:()=>{let r=e.readString(!0);if(r!==void 0)return r?r.split(","):[]},readString:(r,i)=>{typeof r=="number"&&(i=r,r=void 0);let s=e.readUInt32BE();if(s!==void 0&&!(t.length-n<s||typeof i=="number"&&s>i))return r?Buffer.isBuffer(r)?Yn(t,r,n,n+=s):t.utf8Slice(n,n+=s):Vn(t,n,n+=s)},readRaw:r=>{if(t){if(typeof r!="number")return Vn(t,n,n+=t.length-n);if(t.length-n>=r)return Vn(t,n,n+=r)}}};return e}function nl(n,t,e){let r=new Error(n);return typeof t=="boolean"?(e=t,r.level="protocol"):r.level=t||"protocol",r.fatal=!!e,r}function Xs(n,t,e){return n[e++]=t>>>24,n[e++]=t>>>16,n[e++]=t>>>8,n[e++]=t,e}var Gi=Js();sl.exports={bufferCopy:Yn,bufferSlice:Vn,FastBuffer:il,bufferFill:(n,t,e,r)=>qp.call(n,t,e,r),makeError:nl,doFatalError:(n,t,e,r)=>{let i;return Ki===void 0&&({DISCONNECT_REASON:Ki}=wr()),t instanceof Error?(i=t,typeof e!="number"?r=Ki.PROTOCOL_ERROR:r=e):i=nl(t,e,!0),typeof r!="number"&&(r=Ki.PROTOCOL_ERROR),n.disconnect(r),n._destruct(),n._onError(i),1/0},readUInt32BE:rl,writeUInt32BE:Xs,writeUInt32LE:(n,t,e)=>(n[e++]=t,n[e++]=t>>>8,n[e++]=t>>>16,n[e++]=t>>>24,e),makeBufferParser:Js,bufferParser:Js(),readString:(n,t,e,r)=>{typeof e=="number"&&(r=e,e=void 0),t===void 0&&(t=0);let i=n.length-t;if(t<0||t>=n.length||i<4)return;let s=rl(n,t);if(i<4+s||typeof r=="number"&&s>r)return;t+=4;let o=t+s;return n._pos=o,e?Buffer.isBuffer(e)?Yn(n,e,t,o):n.utf8Slice(t,o):Vn(n,t,o)},sigSSHToASN1:(n,t)=>{switch(t){case"ssh-dss":{if(n.length>40)return n;let e=new ir.Writer;e.startSequence();let r=n.slice(0,20),i=n.slice(20);if(r[0]&128){let s=Buffer.allocUnsafe(21);s[0]=0,r.copy(s,1),r=s}else r[0]===0&&!(r[1]&128)&&(r=r.slice(1));if(i[0]&128){let s=Buffer.allocUnsafe(21);s[0]=0,i.copy(s,1),i=s}else i[0]===0&&!(i[1]&128)&&(i=i.slice(1));return e.writeBuffer(r,ir.Integer),e.writeBuffer(i,ir.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{Gi.init(n,0);let e=Gi.readString(),r=Gi.readString();if(Gi.clear(),e===void 0||r===void 0)return;let i=new ir.Writer;return i.startSequence(),i.writeBuffer(e,ir.Integer),i.writeBuffer(r,ir.Integer),i.endSequence(),i.buffer}default:return n}},convertSignature:(n,t)=>{switch(t){case"ssh-dss":{if(n.length<=40)return n;let e=new ir.Reader(n);e.readSequence();let r=e.readString(ir.Integer,!0),i=e.readString(ir.Integer,!0),s=0,o=0;if(r.length<20){let c=Buffer.allocUnsafe(20);c.set(r,1),r=c,r[0]=0}if(i.length<20){let c=Buffer.allocUnsafe(20);c.set(i,1),i=c,i[0]=0}r.length>20&&r[0]===0&&(s=1),i.length>20&&i[0]===0&&(o=1);let a=Buffer.allocUnsafe(r.length-s+(i.length-o));return Yn(r,a,s,r.length,0),Yn(i,a,o,i.length,r.length-s),a}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{if(n[0]===0)return n;let e=new ir.Reader(n);e.readSequence();let r=e.readString(ir.Integer,!0),i=e.readString(ir.Integer,!0);if(r===null||i===null)return;let s=Buffer.allocUnsafe(4+r.length+4+i.length);return Xs(s,r.length,0),s.set(r,4),Xs(s,i.length,4+r.length),s.set(i,8+r.length),s}}return n},sendPacket:(n,t,e)=>!e&&n._kexinit!==void 0?(n._queue===void 0&&(n._queue=[]),n._queue.push(t),n._debug&&n._debug("Outbound: ... packet queued"),!1):(n._cipher.encrypt(t),!0)}});var ol=ot((Yi,eo)=>{var Zs=(function(){var n=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename<"u"&&(n=n||__filename),(function(t){t=t||{};var e;e||(e=typeof t<"u"?t:{});var r,i;e.ready=new Promise(function(q,ce){r=q,i=ce});var s={},o;for(o in e)e.hasOwnProperty(o)&&(s[o]=e[o]);var a=typeof window=="object",c=typeof importScripts=="function",f=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",u="",h,d,g,_,y;f?(u=c?require("path").dirname(u)+"/":__dirname+"/",h=function(q,ce){var ye=_r(q);return ye?ce?ye:ye.toString():(_||(_=require("fs")),y||(y=require("path")),q=y.normalize(q),_.readFileSync(q,ce?null:"utf8"))},g=function(q){return q=h(q,!0),q.buffer||(q=new Uint8Array(q)),j(q.buffer),q},d=function(q,ce,ye){var ke=_r(q);ke&&ce(ke),_||(_=require("fs")),y||(y=require("path")),q=y.normalize(q),_.readFile(q,function(je,It){je?ye(je):ce(It.buffer)})},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),e.inspect=function(){return"[Emscripten Module object]"}):(a||c)&&(c?u=self.location.href:typeof document<"u"&&document.currentScript&&(u=document.currentScript.src),n&&(u=n),u.indexOf("blob:")!==0?u=u.substr(0,u.lastIndexOf("/")+1):u="",h=function(q){try{var ce=new XMLHttpRequest;return ce.open("GET",q,!1),ce.send(null),ce.responseText}catch(je){if(q=_r(q)){ce=[];for(var ye=0;ye<q.length;ye++){var ke=q[ye];255<ke&&(nn&&j(!1,"Character code "+ke+" ("+String.fromCharCode(ke)+") at offset "+ye+" not in 0x00-0xFF."),ke&=255),ce.push(String.fromCharCode(ke))}return ce.join("")}throw je}},c&&(g=function(q){try{var ce=new XMLHttpRequest;return ce.open("GET",q,!1),ce.responseType="arraybuffer",ce.send(null),new Uint8Array(ce.response)}catch(ye){if(q=_r(q))return q;throw ye}}),d=function(q,ce,ye){var ke=new XMLHttpRequest;ke.open("GET",q,!0),ke.responseType="arraybuffer",ke.onload=function(){if(ke.status==200||ke.status==0&&ke.response)ce(ke.response);else{var je=_r(q);je?ce(je.buffer):ye()}},ke.onerror=ye,ke.send(null)}),e.print||console.log.bind(console);var x=e.printErr||console.warn.bind(console);for(o in s)s.hasOwnProperty(o)&&(e[o]=s[o]);s=null;var I;e.wasmBinary&&(I=e.wasmBinary);var O=e.noExitRuntime||!0;typeof WebAssembly!="object"&&D("no native wasm support detected");var $,L=!1;function j(q,ce){q||D("Assertion failed: "+ce)}function J(q){var ce=e["_"+q];return j(ce,"Cannot call unknown function "+q+", make sure it is exported"),ce}function z(q,ce,ye,ke){var je={string:function(st){var Rt=0;if(st!=null&&st!==0){var Bt=(st.length<<2)+1;Rt=Mn(Bt);var Et=Rt,lt=W;if(0<Bt){Bt=Et+Bt-1;for(var er=0;er<st.length;++er){var _t=st.charCodeAt(er);if(55296<=_t&&57343>=_t){var Gr=st.charCodeAt(++er);_t=65536+((_t&1023)<<10)|Gr&1023}if(127>=_t){if(Et>=Bt)break;lt[Et++]=_t}else{if(2047>=_t){if(Et+1>=Bt)break;lt[Et++]=192|_t>>6}else{if(65535>=_t){if(Et+2>=Bt)break;lt[Et++]=224|_t>>12}else{if(Et+3>=Bt)break;lt[Et++]=240|_t>>18,lt[Et++]=128|_t>>12&63}lt[Et++]=128|_t>>6&63}lt[Et++]=128|_t&63}}lt[Et]=0}}return Rt},array:function(st){var Rt=Mn(st.length);return U.set(st,Rt),Rt}},It=J(q),lr=[];if(q=0,ke)for(var jt=0;jt<ke.length;jt++){var fn=je[ye[jt]];fn?(q===0&&(q=Hn()),lr[jt]=fn(ke[jt])):lr[jt]=ke[jt]}return ye=It.apply(null,lr),ye=(function(st){if(ce==="string")if(st){for(var Rt=W,Bt=st+NaN,Et=st;Rt[Et]&&!(Et>=Bt);)++Et;if(16<Et-st&&Rt.subarray&&S)st=S.decode(Rt.subarray(st,Et));else{for(Bt="";st<Et;){var lt=Rt[st++];if(lt&128){var er=Rt[st++]&63;if((lt&224)==192)Bt+=String.fromCharCode((lt&31)<<6|er);else{var _t=Rt[st++]&63;lt=(lt&240)==224?(lt&15)<<12|er<<6|_t:(lt&7)<<18|er<<12|_t<<6|Rt[st++]&63,65536>lt?Bt+=String.fromCharCode(lt):(lt-=65536,Bt+=String.fromCharCode(55296|lt>>10,56320|lt&1023))}}else Bt+=String.fromCharCode(lt)}st=Bt}}else st="";else st=ce==="boolean"?!!st:st;return st})(ye),q!==0&&wi(q),ye}var S=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,w,U,W;function Q(){var q=$.buffer;w=q,e.HEAP8=U=new Int8Array(q),e.HEAP16=new Int16Array(q),e.HEAP32=new Int32Array(q),e.HEAPU8=W=new Uint8Array(q),e.HEAPU16=new Uint16Array(q),e.HEAPU32=new Uint32Array(q),e.HEAPF32=new Float32Array(q),e.HEAPF64=new Float64Array(q)}var oe,te=[],Z=[],re=[];function ae(){var q=e.preRun.shift();te.unshift(q)}var T=0,C=null,v=null;e.preloadedImages={},e.preloadedAudios={};function D(q){throw e.onAbort&&e.onAbort(q),x(q),L=!0,q=new WebAssembly.RuntimeError("abort("+q+"). Build with -s ASSERTIONS=1 for more info."),i(q),q}var G="data:application/octet-stream;base64,",se;if(se="data:application/octet-stream;base64,AGFzbQEAAAABIAZgAX8Bf2ADf39/AGABfwBgAABgAAF/YAZ/f39/f38AAgcBAWEBYQAAAwsKAAEDAQAAAgQFAgQFAXABAQEFBwEBgAKAgAIGCQF/AUGAjMACCwclCQFiAgABYwADAWQACQFlAAgBZgAHAWcABgFoAAUBaQAKAWoBAAqGTQpPAQJ/QYAIKAIAIgEgAEEDakF8cSICaiEAAkAgAkEAIAAgAU0bDQAgAD8AQRB0SwRAIAAQAEUNAQtBgAggADYCACABDwtBhAhBMDYCAEF/C4wFAg5+Cn8gACgCJCEUIAAoAiAhFSAAKAIcIREgACgCGCESIAAoAhQhEyACQRBPBEAgAC0ATEVBGHQhFyAAKAIEIhZBBWytIQ8gACgCCCIYQQVsrSENIAAoAgwiGUEFbK0hCyAAKAIQIhpBBWytIQkgADUCACEIIBqtIRAgGa0hDiAYrSEMIBatIQoDQCASIAEtAAMiEiABLQAEQQh0ciABLQAFQRB0ciABLQAGIhZBGHRyQQJ2Qf///x9xaq0iAyAOfiABLwAAIAEtAAJBEHRyIBNqIBJBGHRBgICAGHFqrSIEIBB+fCARIAEtAAdBCHQgFnIgAS0ACEEQdHIgAS0ACSIRQRh0ckEEdkH///8fcWqtIgUgDH58IAEtAApBCHQgEXIgAS0AC0EQdHIgAS0ADEEYdHJBBnYgFWqtIgYgCn58IBQgF2ogAS8ADSABLQAPQRB0cmqtIgcgCH58IAMgDH4gBCAOfnwgBSAKfnwgBiAIfnwgByAJfnwgAyAKfiAEIAx+fCAFIAh+fCAGIAl+fCAHIAt+fCADIAh+IAQgCn58IAUgCX58IAYgC358IAcgDX58IAMgCX4gBCAIfnwgBSALfnwgBiANfnwgByAPfnwiA0IaiEL/////D4N8IgRCGohC/////w+DfCIFQhqIQv////8Pg3wiBkIaiEL/////D4N8IgdCGoinQQVsIAOnQf///x9xaiITQRp2IASnQf///x9xaiESIAWnQf///x9xIREgBqdB////H3EhFSAHp0H///8fcSEUIBNB////H3EhEyABQRBqIQEgAkEQayICQQ9LDQALCyAAIBQ2AiQgACAVNgIgIAAgETYCHCAAIBI2AhggACATNgIUCwMAAQu2BAEGfwJAIAAoAjgiBARAIABBPGohBQJAIAJBECAEayIDIAIgA0kbIgZFDQAgBkEDcSEHAkAgBkEBa0EDSQRAQQAhAwwBCyAGQXxxIQhBACEDA0AgBSADIARqaiABIANqLQAAOgAAIAUgA0EBciIEIAAoAjhqaiABIARqLQAAOgAAIAUgA0ECciIEIAAoAjhqaiABIARqLQAAOgAAIAUgA0EDciIEIAAoAjhqaiABIARqLQAAOgAAIANBBGohAyAAKAI4IQQgCEEEayIIDQALCyAHRQ0AA0AgBSADIARqaiABIANqLQAAOgAAIANBAWohAyAAKAI4IQQgB0EBayIHDQALCyAAIAQgBmoiAzYCOCADQRBJDQEgACAFQRAQAiAAQQA2AjggAiAGayECIAEgBmohAQsgAkEQTwRAIAAgASACQXBxIgMQAiACQQ9xIQIgASADaiEBCyACRQ0AIAJBA3EhBCAAQTxqIQVBACEDIAJBAWtBA08EQCACQXxxIQcDQCAFIAAoAjggA2pqIAEgA2otAAA6AAAgBSADQQFyIgYgACgCOGpqIAEgBmotAAA6AAAgBSADQQJyIgYgACgCOGpqIAEgBmotAAA6AAAgBSADQQNyIgYgACgCOGpqIAEgBmotAAA6AAAgA0EEaiEDIAdBBGsiBw0ACwsgBARAA0AgBSAAKAI4IANqaiABIANqLQAAOgAAIANBAWohAyAEQQFrIgQNAAsLIAAgACgCOCACajYCOAsLoS0BDH8jAEEQayIMJAACQAJAAkACQAJAAkACQAJAAkACQAJAAkAgAEH0AU0EQEGICCgCACIFQRAgAEELakF4cSAAQQtJGyIIQQN2IgJ2IgFBA3EEQCABQX9zQQFxIAJqIgNBA3QiAUG4CGooAgAiBEEIaiEAAkAgBCgCCCICIAFBsAhqIgFGBEBBiAggBUF+IAN3cTYCAAwBCyACIAE2AgwgASACNgIICyAEIANBA3QiAUEDcjYCBCABIARqIgEgASgCBEEBcjYCBAwNCyAIQZAIKAIAIgpNDQEgAQRAAkBBAiACdCIAQQAgAGtyIAEgAnRxIgBBACAAa3FBAWsiACAAQQx2QRBxIgJ2IgFBBXZBCHEiACACciABIAB2IgFBAnZBBHEiAHIgASAAdiIBQQF2QQJxIgByIAEgAHYiAUEBdkEBcSIAciABIAB2aiIDQQN0IgBBuAhqKAIAIgQoAggiASAAQbAIaiIARgRAQYgIIAVBfiADd3EiBTYCAAwBCyABIAA2AgwgACABNgIICyAEQQhqIQAgBCAIQQNyNgIEIAQgCGoiAiADQQN0IgEgCGsiA0EBcjYCBCABIARqIAM2AgAgCgRAIApBA3YiAUEDdEGwCGohB0GcCCgCACEEAn8gBUEBIAF0IgFxRQRAQYgIIAEgBXI2AgAgBwwBCyAHKAIICyEBIAcgBDYCCCABIAQ2AgwgBCAHNgIMIAQgATYCCAtBnAggAjYCAEGQCCADNgIADA0LQYwIKAIAIgZFDQEgBkEAIAZrcUEBayIAIABBDHZBEHEiAnYiAUEFdkEIcSIAIAJyIAEgAHYiAUECdkEEcSIAciABIAB2IgFBAXZBAnEiAHIgASAAdiIBQQF2QQFxIgByIAEgAHZqQQJ0QbgKaigCACIBKAIEQXhxIAhrIQMgASECA0ACQCACKAIQIgBFBEAgAigCFCIARQ0BCyAAKAIEQXhxIAhrIgIgAyACIANJIgIbIQMgACABIAIbIQEgACECDAELCyABIAhqIgkgAU0NAiABKAIYIQsgASABKAIMIgRHBEAgASgCCCIAQZgIKAIASRogACAENgIMIAQgADYCCAwMCyABQRRqIgIoAgAiAEUEQCABKAIQIgBFDQQgAUEQaiECCwNAIAIhByAAIgRBFGoiAigCACIADQAgBEEQaiECIAQoAhAiAA0ACyAHQQA2AgAMCwtBfyEIIABBv39LDQAgAEELaiIAQXhxIQhBjAgoAgAiCUUNAEEAIAhrIQMCQAJAAkACf0EAIAhBgAJJDQAaQR8gCEH///8HSw0AGiAAQQh2IgAgAEGA/j9qQRB2QQhxIgJ0IgAgAEGA4B9qQRB2QQRxIgF0IgAgAEGAgA9qQRB2QQJxIgB0QQ92IAEgAnIgAHJrIgBBAXQgCCAAQRVqdkEBcXJBHGoLIgVBAnRBuApqKAIAIgJFBEBBACEADAELQQAhACAIQQBBGSAFQQF2ayAFQR9GG3QhAQNAAkAgAigCBEF4cSAIayIHIANPDQAgAiEEIAciAw0AQQAhAyACIQAMAwsgACACKAIUIgcgByACIAFBHXZBBHFqKAIQIgJGGyAAIAcbIQAgAUEBdCEBIAINAAsLIAAgBHJFBEBBACEEQQIgBXQiAEEAIABrciAJcSIARQ0DIABBACAAa3FBAWsiACAAQQx2QRBxIgJ2IgFBBXZBCHEiACACciABIAB2IgFBAnZBBHEiAHIgASAAdiIBQQF2QQJxIgByIAEgAHYiAUEBdkEBcSIAciABIAB2akECdEG4CmooAgAhAAsgAEUNAQsDQCAAKAIEQXhxIAhrIgEgA0khAiABIAMgAhshAyAAIAQgAhshBCAAKAIQIgEEfyABBSAAKAIUCyIADQALCyAERQ0AIANBkAgoAgAgCGtPDQAgBCAIaiIGIARNDQEgBCgCGCEFIAQgBCgCDCIBRwRAIAQoAggiAEGYCCgCAEkaIAAgATYCDCABIAA2AggMCgsgBEEUaiICKAIAIgBFBEAgBCgCECIARQ0EIARBEGohAgsDQCACIQcgACIBQRRqIgIoAgAiAA0AIAFBEGohAiABKAIQIgANAAsgB0EANgIADAkLIAhBkAgoAgAiAk0EQEGcCCgCACEDAkAgAiAIayIBQRBPBEBBkAggATYCAEGcCCADIAhqIgA2AgAgACABQQFyNgIEIAIgA2ogATYCACADIAhBA3I2AgQMAQtBnAhBADYCAEGQCEEANgIAIAMgAkEDcjYCBCACIANqIgAgACgCBEEBcjYCBAsgA0EIaiEADAsLIAhBlAgoAgAiBkkEQEGUCCAGIAhrIgE2AgBBoAhBoAgoAgAiAiAIaiIANgIAIAAgAUEBcjYCBCACIAhBA3I2AgQgAkEIaiEADAsLQQAhACAIQS9qIgkCf0HgCygCAARAQegLKAIADAELQewLQn83AgBB5AtCgKCAgICABDcCAEHgCyAMQQxqQXBxQdiq1aoFczYCAEH0C0EANgIAQcQLQQA2AgBBgCALIgFqIgVBACABayIHcSICIAhNDQpBwAsoAgAiBARAQbgLKAIAIgMgAmoiASADTQ0LIAEgBEsNCwtBxAstAABBBHENBQJAAkBBoAgoAgAiAwRAQcgLIQADQCADIAAoAgAiAU8EQCABIAAoAgRqIANLDQMLIAAoAggiAA0ACwtBABABIgFBf0YNBiACIQVB5AsoAgAiA0EBayIAIAFxBEAgAiABayAAIAFqQQAgA2txaiEFCyAFIAhNDQYgBUH+////B0sNBkHACygCACIEBEBBuAsoAgAiAyAFaiIAIANNDQcgACAESw0HCyAFEAEiACABRw0BDAgLIAUgBmsgB3EiBUH+////B0sNBSAFEAEiASAAKAIAIAAoAgRqRg0EIAEhAAsCQCAAQX9GDQAgCEEwaiAFTQ0AQegLKAIAIgEgCSAFa2pBACABa3EiAUH+////B0sEQCAAIQEMCAsgARABQX9HBEAgASAFaiEFIAAhAQwIC0EAIAVrEAEaDAULIAAiAUF/Rw0GDAQLAAtBACEEDAcLQQAhAQwFCyABQX9HDQILQcQLQcQLKAIAQQRyNgIACyACQf7///8HSw0BIAIQASEBQQAQASEAIAFBf0YNASAAQX9GDQEgACABTQ0BIAAgAWsiBSAIQShqTQ0BC0G4C0G4CygCACAFaiIANgIAQbwLKAIAIABJBEBBvAsgADYCAAsCQAJAAkBBoAgoAgAiBwRAQcgLIQADQCABIAAoAgAiAyAAKAIEIgJqRg0CIAAoAggiAA0ACwwCC0GYCCgCACIAQQAgACABTRtFBEBBmAggATYCAAtBACEAQcwLIAU2AgBByAsgATYCAEGoCEF/NgIAQawIQeALKAIANgIAQdQLQQA2AgADQCAAQQN0IgNBuAhqIANBsAhqIgI2AgAgA0G8CGogAjYCACAAQQFqIgBBIEcNAAtBlAggBUEoayIDQXggAWtBB3FBACABQQhqQQdxGyIAayICNgIAQaAIIAAgAWoiADYCACAAIAJBAXI2AgQgASADakEoNgIEQaQIQfALKAIANgIADAILIAAtAAxBCHENACADIAdLDQAgASAHTQ0AIAAgAiAFajYCBEGgCCAHQXggB2tBB3FBACAHQQhqQQdxGyIAaiICNgIAQZQIQZQIKAIAIAVqIgEgAGsiADYCACACIABBAXI2AgQgASAHakEoNgIEQaQIQfALKAIANgIADAELQZgIKAIAIAFLBEBBmAggATYCAAsgASAFaiECQcgLIQACQAJAAkACQAJAAkADQCACIAAoAgBHBEAgACgCCCIADQEMAgsLIAAtAAxBCHFFDQELQcgLIQADQCAHIAAoAgAiAk8EQCACIAAoAgRqIgQgB0sNAwsgACgCCCEADAALAAsgACABNgIAIAAgACgCBCAFajYCBCABQXggAWtBB3FBACABQQhqQQdxG2oiCSAIQQNyNgIEIAJBeCACa0EHcUEAIAJBCGpBB3EbaiIFIAggCWoiBmshAiAFIAdGBEBBoAggBjYCAEGUCEGUCCgCACACaiIANgIAIAYgAEEBcjYCBAwDCyAFQZwIKAIARgRAQZwIIAY2AgBBkAhBkAgoAgAgAmoiADYCACAGIABBAXI2AgQgACAGaiAANgIADAMLIAUoAgQiAEEDcUEBRgRAIABBeHEhBwJAIABB/wFNBEAgBSgCCCIDIABBA3YiAEEDdEGwCGpGGiADIAUoAgwiAUYEQEGICEGICCgCAEF+IAB3cTYCAAwCCyADIAE2AgwgASADNgIIDAELIAUoAhghCAJAIAUgBSgCDCIBRwRAIAUoAggiACABNgIMIAEgADYCCAwBCwJAIAVBFGoiACgCACIDDQAgBUEQaiIAKAIAIgMNAEEAIQEMAQsDQCAAIQQgAyIBQRRqIgAoAgAiAw0AIAFBEGohACABKAIQIgMNAAsgBEEANgIACyAIRQ0AAkAgBSAFKAIcIgNBAnRBuApqIgAoAgBGBEAgACABNgIAIAENAUGMCEGMCCgCAEF+IAN3cTYCAAwCCyAIQRBBFCAIKAIQIAVGG2ogATYCACABRQ0BCyABIAg2AhggBSgCECIABEAgASAANgIQIAAgATYCGAsgBSgCFCIARQ0AIAEgADYCFCAAIAE2AhgLIAUgB2ohBSACIAdqIQILIAUgBSgCBEF+cTYCBCAGIAJBAXI2AgQgAiAGaiACNgIAIAJB/wFNBEAgAkEDdiIAQQN0QbAIaiECAn9BiAgoAgAiAUEBIAB0IgBxRQRAQYgIIAAgAXI2AgAgAgwBCyACKAIICyEAIAIgBjYCCCAAIAY2AgwgBiACNgIMIAYgADYCCAwDC0EfIQAgAkH///8HTQRAIAJBCHYiACAAQYD+P2pBEHZBCHEiA3QiACAAQYDgH2pBEHZBBHEiAXQiACAAQYCAD2pBEHZBAnEiAHRBD3YgASADciAAcmsiAEEBdCACIABBFWp2QQFxckEcaiEACyAGIAA2AhwgBkIANwIQIABBAnRBuApqIQQCQEGMCCgCACIDQQEgAHQiAXFFBEBBjAggASADcjYCACAEIAY2AgAgBiAENgIYDAELIAJBAEEZIABBAXZrIABBH0YbdCEAIAQoAgAhAQNAIAEiAygCBEF4cSACRg0DIABBHXYhASAAQQF0IQAgAyABQQRxaiIEKAIQIgENAAsgBCAGNgIQIAYgAzYCGAsgBiAGNgIMIAYgBjYCCAwCC0GUCCAFQShrIgNBeCABa0EHcUEAIAFBCGpBB3EbIgBrIgI2AgBBoAggACABaiIANgIAIAAgAkEBcjYCBCABIANqQSg2AgRBpAhB8AsoAgA2AgAgByAEQScgBGtBB3FBACAEQSdrQQdxG2pBL2siACAAIAdBEGpJGyICQRs2AgQgAkHQCykCADcCECACQcgLKQIANwIIQdALIAJBCGo2AgBBzAsgBTYCAEHICyABNgIAQdQLQQA2AgAgAkEYaiEAA0AgAEEHNgIEIABBCGohASAAQQRqIQAgASAESQ0ACyACIAdGDQMgAiACKAIEQX5xNgIEIAcgAiAHayIEQQFyNgIEIAIgBDYCACAEQf8BTQRAIARBA3YiAEEDdEGwCGohAgJ/QYgIKAIAIgFBASAAdCIAcUUEQEGICCAAIAFyNgIAIAIMAQsgAigCCAshACACIAc2AgggACAHNgIMIAcgAjYCDCAHIAA2AggMBAtBHyEAIAdCADcCECAEQf///wdNBEAgBEEIdiIAIABBgP4/akEQdkEIcSICdCIAIABBgOAfakEQdkEEcSIBdCIAIABBgIAPakEQdkECcSIAdEEPdiABIAJyIAByayIAQQF0IAQgAEEVanZBAXFyQRxqIQALIAcgADYCHCAAQQJ0QbgKaiEDAkBBjAgoAgAiAkEBIAB0IgFxRQRAQYwIIAEgAnI2AgAgAyAHNgIAIAcgAzYCGAwBCyAEQQBBGSAAQQF2ayAAQR9GG3QhACADKAIAIQEDQCABIgIoAgRBeHEgBEYNBCAAQR12IQEgAEEBdCEAIAIgAUEEcWoiAygCECIBDQALIAMgBzYCECAHIAI2AhgLIAcgBzYCDCAHIAc2AggMAwsgAygCCCIAIAY2AgwgAyAGNgIIIAZBADYCGCAGIAM2AgwgBiAANgIICyAJQQhqIQAMBQsgAigCCCIAIAc2AgwgAiAHNgIIIAdBADYCGCAHIAI2AgwgByAANgIIC0GUCCgCACIAIAhNDQBBlAggACAIayIBNgIAQaAIQaAIKAIAIgIgCGoiADYCACAAIAFBAXI2AgQgAiAIQQNyNgIEIAJBCGohAAwDC0GECEEwNgIAQQAhAAwCCwJAIAVFDQACQCAEKAIcIgJBAnRBuApqIgAoAgAgBEYEQCAAIAE2AgAgAQ0BQYwIIAlBfiACd3EiCTYCAAwCCyAFQRBBFCAFKAIQIARGG2ogATYCACABRQ0BCyABIAU2AhggBCgCECIABEAgASAANgIQIAAgATYCGAsgBCgCFCIARQ0AIAEgADYCFCAAIAE2AhgLAkAgA0EPTQRAIAQgAyAIaiIAQQNyNgIEIAAgBGoiACAAKAIEQQFyNgIEDAELIAQgCEEDcjYCBCAGIANBAXI2AgQgAyAGaiADNgIAIANB/wFNBEAgA0EDdiIAQQN0QbAIaiECAn9BiAgoAgAiAUEBIAB0IgBxRQRAQYgIIAAgAXI2AgAgAgwBCyACKAIICyEAIAIgBjYCCCAAIAY2AgwgBiACNgIMIAYgADYCCAwBC0EfIQAgA0H///8HTQRAIANBCHYiACAAQYD+P2pBEHZBCHEiAnQiACAAQYDgH2pBEHZBBHEiAXQiACAAQYCAD2pBEHZBAnEiAHRBD3YgASACciAAcmsiAEEBdCADIABBFWp2QQFxckEcaiEACyAGIAA2AhwgBkIANwIQIABBAnRBuApqIQICQAJAIAlBASAAdCIBcUUEQEGMCCABIAlyNgIAIAIgBjYCACAGIAI2AhgMAQsgA0EAQRkgAEEBdmsgAEEfRht0IQAgAigCACEIA0AgCCIBKAIEQXhxIANGDQIgAEEddiECIABBAXQhACABIAJBBHFqIgIoAhAiCA0ACyACIAY2AhAgBiABNgIYCyAGIAY2AgwgBiAGNgIIDAELIAEoAggiACAGNgIMIAEgBjYCCCAGQQA2AhggBiABNgIMIAYgADYCCAsgBEEIaiEADAELAkAgC0UNAAJAIAEoAhwiAkECdEG4CmoiACgCACABRgRAIAAgBDYCACAEDQFBjAggBkF+IAJ3cTYCAAwCCyALQRBBFCALKAIQIAFGG2ogBDYCACAERQ0BCyAEIAs2AhggASgCECIABEAgBCAANgIQIAAgBDYCGAsgASgCFCIARQ0AIAQgADYCFCAAIAQ2AhgLAkAgA0EPTQRAIAEgAyAIaiIAQQNyNgIEIAAgAWoiACAAKAIEQQFyNgIEDAELIAEgCEEDcjYCBCAJIANBAXI2AgQgAyAJaiADNgIAIAoEQCAKQQN2IgBBA3RBsAhqIQRBnAgoAgAhAgJ/QQEgAHQiACAFcUUEQEGICCAAIAVyNgIAIAQMAQsgBCgCCAshACAEIAI2AgggACACNgIMIAIgBDYCDCACIAA2AggLQZwIIAk2AgBBkAggAzYCAAsgAUEIaiEACyAMQRBqJAAgAAsQACMAIABrQXBxIgAkACAACwYAIAAkAAsEACMAC4AJAgh/BH4jAEGQAWsiBiQAIAYgBS0AA0EYdEGAgIAYcSAFLwAAIAUtAAJBEHRycjYCACAGIAUoAANBAnZBg/7/H3E2AgQgBiAFKAAGQQR2Qf+B/x9xNgIIIAYgBSgACUEGdkH//8AfcTYCDCAFLwANIQggBS0ADyEJIAZCADcCFCAGQgA3AhwgBkEANgIkIAYgCCAJQRB0QYCAPHFyNgIQIAYgBSgAEDYCKCAGIAUoABQ2AiwgBiAFKAAYNgIwIAUoABwhBSAGQQA6AEwgBkEANgI4IAYgBTYCNCAGIAEgAhAEIAQEQCAGIAMgBBAECyAGKAI4IgEEQCAGQTxqIgIgAWpBAToAACABQQFqQQ9NBEAgASAGakE9aiEEAkBBDyABayIDRQ0AIAMgBGoiAUEBa0EAOgAAIARBADoAACADQQNJDQAgAUECa0EAOgAAIARBADoAASABQQNrQQA6AAAgBEEAOgACIANBB0kNACABQQRrQQA6AAAgBEEAOgADIANBCUkNACAEQQAgBGtBA3EiAWoiBEEANgIAIAQgAyABa0F8cSIBaiIDQQRrQQA2AgAgAUEJSQ0AIARBADYCCCAEQQA2AgQgA0EIa0EANgIAIANBDGtBADYCACABQRlJDQAgBEEANgIYIARBADYCFCAEQQA2AhAgBEEANgIMIANBEGtBADYCACADQRRrQQA2AgAgA0EYa0EANgIAIANBHGtBADYCACABIARBBHFBGHIiAWsiA0EgSQ0AIAEgBGohAQNAIAFCADcDGCABQgA3AxAgAUIANwMIIAFCADcDACABQSBqIQEgA0EgayIDQR9LDQALCwsgBkEBOgBMIAYgAkEQEAILIAY1AjQhECAGNQIwIREgBjUCLCEOIAAgBjUCKCAGKAIkIAYoAiAgBigCHCAGKAIYIgNBGnZqIgJBGnZqIgFBGnZqIgtBgICAYHIgAUH///8fcSINIAJB////H3EiCCAGKAIUIAtBGnZBBWxqIgFB////H3EiCUEFaiIFQRp2IANB////H3EgAUEadmoiA2oiAUEadmoiAkEadmoiBEEadmoiDEEfdSIHIANxIAEgDEEfdkEBayIDQf///x9xIgpxciIBQRp0IAUgCnEgByAJcXJyrXwiDzwAACAAIA9CGIg8AAMgACAPQhCIPAACIAAgD0IIiDwAASAAIA4gByAIcSACIApxciICQRR0IAFBBnZyrXwgD0IgiHwiDjwABCAAIA5CGIg8AAcgACAOQhCIPAAGIAAgDkIIiDwABSAAIBEgByANcSAEIApxciIBQQ50IAJBDHZyrXwgDkIgiHwiDjwACCAAIA5CGIg8AAsgACAOQhCIPAAKIAAgDkIIiDwACSAAIBAgAyAMcSAHIAtxckEIdCABQRJ2cq18IA5CIIh8Ig48AAwgACAOQhiIPAAPIAAgDkIQiDwADiAAIA5CCIg8AA0gBkIANwIwIAZCADcCKCAGQgA3AiAgBkIANwIYIAZCADcCECAGQgA3AgggBkIANwIAIAZBkAFqJAALpwwBB38CQCAARQ0AIABBCGsiAyAAQQRrKAIAIgFBeHEiAGohBQJAIAFBAXENACABQQNxRQ0BIAMgAygCACIBayIDQZgIKAIASQ0BIAAgAWohACADQZwIKAIARwRAIAFB/wFNBEAgAygCCCICIAFBA3YiBEEDdEGwCGpGGiACIAMoAgwiAUYEQEGICEGICCgCAEF+IAR3cTYCAAwDCyACIAE2AgwgASACNgIIDAILIAMoAhghBgJAIAMgAygCDCIBRwRAIAMoAggiAiABNgIMIAEgAjYCCAwBCwJAIANBFGoiAigCACIEDQAgA0EQaiICKAIAIgQNAEEAIQEMAQsDQCACIQcgBCIBQRRqIgIoAgAiBA0AIAFBEGohAiABKAIQIgQNAAsgB0EANgIACyAGRQ0BAkAgAyADKAIcIgJBAnRBuApqIgQoAgBGBEAgBCABNgIAIAENAUGMCEGMCCgCAEF+IAJ3cTYCAAwDCyAGQRBBFCAGKAIQIANGG2ogATYCACABRQ0CCyABIAY2AhggAygCECICBEAgASACNgIQIAIgATYCGAsgAygCFCICRQ0BIAEgAjYCFCACIAE2AhgMAQsgBSgCBCIBQQNxQQNHDQBBkAggADYCACAFIAFBfnE2AgQgAyAAQQFyNgIEIAAgA2ogADYCAA8LIAMgBU8NACAFKAIEIgFBAXFFDQACQCABQQJxRQRAIAVBoAgoAgBGBEBBoAggAzYCAEGUCEGUCCgCACAAaiIANgIAIAMgAEEBcjYCBCADQZwIKAIARw0DQZAIQQA2AgBBnAhBADYCAA8LIAVBnAgoAgBGBEBBnAggAzYCAEGQCEGQCCgCACAAaiIANgIAIAMgAEEBcjYCBCAAIANqIAA2AgAPCyABQXhxIABqIQACQCABQf8BTQRAIAUoAggiAiABQQN2IgRBA3RBsAhqRhogAiAFKAIMIgFGBEBBiAhBiAgoAgBBfiAEd3E2AgAMAgsgAiABNgIMIAEgAjYCCAwBCyAFKAIYIQYCQCAFIAUoAgwiAUcEQCAFKAIIIgJBmAgoAgBJGiACIAE2AgwgASACNgIIDAELAkAgBUEUaiICKAIAIgQNACAFQRBqIgIoAgAiBA0AQQAhAQwBCwNAIAIhByAEIgFBFGoiAigCACIEDQAgAUEQaiECIAEoAhAiBA0ACyAHQQA2AgALIAZFDQACQCAFIAUoAhwiAkECdEG4CmoiBCgCAEYEQCAEIAE2AgAgAQ0BQYwIQYwIKAIAQX4gAndxNgIADAILIAZBEEEUIAYoAhAgBUYbaiABNgIAIAFFDQELIAEgBjYCGCAFKAIQIgIEQCABIAI2AhAgAiABNgIYCyAFKAIUIgJFDQAgASACNgIUIAIgATYCGAsgAyAAQQFyNgIEIAAgA2ogADYCACADQZwIKAIARw0BQZAIIAA2AgAPCyAFIAFBfnE2AgQgAyAAQQFyNgIEIAAgA2ogADYCAAsgAEH/AU0EQCAAQQN2IgFBA3RBsAhqIQACf0GICCgCACICQQEgAXQiAXFFBEBBiAggASACcjYCACAADAELIAAoAggLIQIgACADNgIIIAIgAzYCDCADIAA2AgwgAyACNgIIDwtBHyECIANCADcCECAAQf///wdNBEAgAEEIdiIBIAFBgP4/akEQdkEIcSIBdCICIAJBgOAfakEQdkEEcSICdCIEIARBgIAPakEQdkECcSIEdEEPdiABIAJyIARyayIBQQF0IAAgAUEVanZBAXFyQRxqIQILIAMgAjYCHCACQQJ0QbgKaiEBAkACQAJAQYwIKAIAIgRBASACdCIHcUUEQEGMCCAEIAdyNgIAIAEgAzYCACADIAE2AhgMAQsgAEEAQRkgAkEBdmsgAkEfRht0IQIgASgCACEBA0AgASIEKAIEQXhxIABGDQIgAkEddiEBIAJBAXQhAiAEIAFBBHFqIgdBEGooAgAiAQ0ACyAHIAM2AhAgAyAENgIYCyADIAM2AgwgAyADNgIIDAELIAQoAggiACADNgIMIAQgAzYCCCADQQA2AhggAyAENgIMIAMgADYCCAtBqAhBqAgoAgBBAWsiAEF/IAAbNgIACwsLCQEAQYEICwIGUA==",!se.startsWith(G)){var ee=se;se=e.locateFile?e.locateFile(ee,u):u+ee}function Ve(){var q=se;try{if(q==se&&I)return new Uint8Array(I);var ce=_r(q);if(ce)return ce;if(g)return g(q);throw"both async and sync fetching of the wasm failed"}catch(ye){D(ye)}}function mt(){if(!I&&(a||c)){if(typeof fetch=="function"&&!se.startsWith("file://"))return fetch(se,{credentials:"same-origin"}).then(function(q){if(!q.ok)throw"failed to load wasm binary file at '"+se+"'";return q.arrayBuffer()}).catch(function(){return Ve()});if(d)return new Promise(function(q,ce){d(se,function(ye){q(new Uint8Array(ye))},ce)})}return Promise.resolve().then(function(){return Ve()})}function ur(q){for(;0<q.length;){var ce=q.shift();if(typeof ce=="function")ce(e);else{var ye=ce.m;typeof ye=="number"?ce.l===void 0?oe.get(ye)():oe.get(ye)(ce.l):ye(ce.l===void 0?null:ce.l)}}}var nn=!1,sn=typeof atob=="function"?atob:function(q){var ce="",ye=0;q=q.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var ke="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(q.charAt(ye++)),je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(q.charAt(ye++)),It="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(q.charAt(ye++)),lr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(q.charAt(ye++));ke=ke<<2|je>>4,je=(je&15)<<4|It>>2;var jt=(It&3)<<6|lr;ce+=String.fromCharCode(ke),It!==64&&(ce+=String.fromCharCode(je)),lr!==64&&(ce+=String.fromCharCode(jt))}while(ye<q.length);return ce};function _r(q){if(q.startsWith(G)){if(q=q.slice(G.length),typeof f=="boolean"&&f){var ce=Buffer.from(q,"base64");ce=new Uint8Array(ce.buffer,ce.byteOffset,ce.byteLength)}else try{var ye=sn(q),ke=new Uint8Array(ye.length);for(q=0;q<ye.length;++q)ke[q]=ye.charCodeAt(q);ce=ke}catch{throw Error("Converting base64 string to bytes failed.")}return ce}}var on={a:function(q){var ce=W.length;if(q>>>=0,2147483648<q)return!1;for(var ye=1;4>=ye;ye*=2){var ke=ce*(1+.2/ye);ke=Math.min(ke,q+100663296),ke=Math.max(q,ke),0<ke%65536&&(ke+=65536-ke%65536);e:{try{$.grow(Math.min(2147483648,ke)-w.byteLength+65535>>>16),Q();var je=1;break e}catch{}je=void 0}if(je)return!0}return!1}};(function(){function q(je){e.asm=je.exports,$=e.asm.b,Q(),oe=e.asm.j,Z.unshift(e.asm.c),T--,e.monitorRunDependencies&&e.monitorRunDependencies(T),T==0&&(C!==null&&(clearInterval(C),C=null),v&&(je=v,v=null,je()))}function ce(je){q(je.instance)}function ye(je){return mt().then(function(It){return WebAssembly.instantiate(It,ke)}).then(je,function(It){x("failed to asynchronously prepare wasm: "+It),D(It)})}var ke={a:on};if(T++,e.monitorRunDependencies&&e.monitorRunDependencies(T),e.instantiateWasm)try{return e.instantiateWasm(ke,q)}catch(je){return x("Module.instantiateWasm callback failed with error: "+je),!1}return(function(){return I||typeof WebAssembly.instantiateStreaming!="function"||se.startsWith(G)||se.startsWith("file://")||typeof fetch!="function"?ye(ce):fetch(se,{credentials:"same-origin"}).then(function(je){return WebAssembly.instantiateStreaming(je,ke).then(ce,function(It){return x("wasm streaming compile failed: "+It),x("falling back to ArrayBuffer instantiation"),ye(ce)})})})().catch(i),{}})(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.c).apply(null,arguments)},e._poly1305_auth=function(){return(e._poly1305_auth=e.asm.d).apply(null,arguments)};var Hn=e.stackSave=function(){return(Hn=e.stackSave=e.asm.e).apply(null,arguments)},wi=e.stackRestore=function(){return(wi=e.stackRestore=e.asm.f).apply(null,arguments)},Mn=e.stackAlloc=function(){return(Mn=e.stackAlloc=e.asm.g).apply(null,arguments)};e._malloc=function(){return(e._malloc=e.asm.h).apply(null,arguments)},e._free=function(){return(e._free=e.asm.i).apply(null,arguments)},e.cwrap=function(q,ce,ye,ke){ye=ye||[];var je=ye.every(function(It){return It==="number"});return ce!=="string"&&je&&!ke?J(q):function(){return z(q,ce,ye,arguments)}};var an;v=function q(){an||cn(),an||(v=q)};function cn(){function q(){if(!an&&(an=!0,e.calledRun=!0,!L)){if(ur(Z),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var ce=e.postRun.shift();re.unshift(ce)}ur(re)}}if(!(0<T)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)ae();ur(te),0<T||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),q()},1)):q())}}if(e.run=cn,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return cn(),t.ready})})();typeof Yi=="object"&&typeof eo=="object"?eo.exports=Zs:typeof define=="function"&&define.amd?define([],function(){return Zs}):typeof Yi=="object"&&(Yi.createPoly1305=Zs)});var Lr=ot((Ib,ll)=>{"use strict";var{createCipheriv:_n,createDecipheriv:Vi,createHmac:to,randomFillSync:Jr,timingSafeEqual:ro}=require("crypto"),{readUInt32BE:zn,writeUInt32BE:Jt}=or(),Ur=Buffer[Symbol.species],al=2**32-1,cl=Buffer.alloc(0),En=Buffer.alloc(4),ji=new Map,Zr=35e3,no,_o,yo,bo,xo,So,wo;try{no=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:_o,ChaChaPolyCipher:yo,GenericCipher:bo,AESGCMDecipher:xo,ChaChaPolyDecipher:So,GenericDecipher:wo}=no}catch{}var Lt=1,Kp=(()=>{function n(t,e,r,i,s,o,a){return{sslName:t,blockLen:e,keyLen:r,ivLen:i!==0||a&Lt?i:e,authLen:s,discardLen:o,stream:!!(a&Lt)}}return{"chacha20-poly1305@openssh.com":n("chacha20",8,64,0,16,0,Lt),"aes128-gcm":n("aes-128-gcm",16,16,12,16,0,Lt),"aes256-gcm":n("aes-256-gcm",16,32,12,16,0,Lt),"aes128-gcm@openssh.com":n("aes-128-gcm",16,16,12,16,0,Lt),"aes256-gcm@openssh.com":n("aes-256-gcm",16,32,12,16,0,Lt),"aes128-cbc":n("aes-128-cbc",16,16,0,0,0,0),"aes192-cbc":n("aes-192-cbc",16,24,0,0,0,0),"aes256-cbc":n("aes-256-cbc",16,32,0,0,0,0),"rijndael-cbc@lysator.liu.se":n("aes-256-cbc",16,32,0,0,0,0),"3des-cbc":n("des-ede3-cbc",8,24,0,0,0,0),"blowfish-cbc":n("bf-cbc",8,16,0,0,0,0),"idea-cbc":n("idea-cbc",8,16,0,0,0,0),"cast128-cbc":n("cast-cbc",8,16,0,0,0,0),"aes128-ctr":n("aes-128-ctr",16,16,16,0,0,Lt),"aes192-ctr":n("aes-192-ctr",16,24,16,0,0,Lt),"aes256-ctr":n("aes-256-ctr",16,32,16,0,0,Lt),"3des-ctr":n("des-ede3",8,24,8,0,0,Lt),"blowfish-ctr":n("bf-ecb",8,16,8,0,0,Lt),"cast128-ctr":n("cast5-ecb",8,16,8,0,0,Lt),arcfour:n("rc4",8,16,0,0,1536,Lt),arcfour128:n("rc4",8,16,0,0,1536,Lt),arcfour256:n("rc4",8,32,0,0,1536,Lt),arcfour512:n("rc4",8,64,0,0,1536,Lt)}})(),Gp=(()=>{function n(t,e,r,i){return{sslName:t,len:e,actualLen:r,isETM:i}}return{"hmac-md5":n("md5",16,16,!1),"hmac-md5-96":n("md5",16,12,!1),"hmac-ripemd160":n("ripemd160",20,20,!1),"hmac-sha1":n("sha1",20,20,!1),"hmac-sha1-etm@openssh.com":n("sha1",20,20,!0),"hmac-sha1-96":n("sha1",20,12,!1),"hmac-sha2-256":n("sha256",32,32,!1),"hmac-sha2-256-etm@openssh.com":n("sha256",32,32,!0),"hmac-sha2-256-96":n("sha256",32,12,!1),"hmac-sha2-512":n("sha512",64,64,!1),"hmac-sha2-512-etm@openssh.com":n("sha512",64,64,!0),"hmac-sha2-512-96":n("sha512",64,12,!1)}})(),io=class{constructor(t,e){this.outSeqno=t,this._onWrite=e,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=8-(e&7);r<4&&(r+=8),e+=r;let i=Buffer.allocUnsafe(e);return Jt(i,e-4,0),i[4]=r,Jr(i,5+t,r),i}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},fl=Buffer.alloc(32),Kt=Buffer.alloc(16),jn,Xn,Io,so=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encKeyMain=e.cipherKey.slice(0,32),this._encKeyPktLen=e.cipherKey.slice(32),this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=8-(e-4&7);r<4&&(r+=8),e+=r;let i=Buffer.allocUnsafe(e);return Jt(i,e-4,0),i[4]=r,Jr(i,5+t,r),i}encrypt(t){if(this._dead)return;Kt[0]=0,Jt(Kt,this.outSeqno,12);let e=_n("chacha20",this._encKeyMain,Kt).update(fl),r=_n("chacha20",this._encKeyPktLen,Kt).update(t.slice(0,4));this._onWrite(r),Kt[0]=1;let i=_n("chacha20",this._encKeyMain,Kt).update(t.slice(4));this._onWrite(i),Io(Xn,r,r.length,i,i.length,e);let s=Buffer.allocUnsafe(16);s.set(new Uint8Array(jn.HEAPU8.buffer,Xn,16),0),this._onWrite(s),this.outSeqno=this.outSeqno+1>>>0}},oo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new yo(e.cipherKey),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,r=8-(e-4&7);r<4&&(r+=8),e+=r;let i=Buffer.allocUnsafe(e+16);return Jt(i,e-4,0),i[4]=r,Jr(i,5+t,r),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},ao=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encSSLName=e.cipherInfo.sslName,this._encKey=e.cipherKey,this._encIV=e.cipherIV,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=16-(e-4&15);r<4&&(r+=16),e+=r;let i=Buffer.allocUnsafe(e);return Jt(i,e-4,0),i[4]=r,Jr(i,5+t,r),i}encrypt(t){if(this._dead)return;let e=_n(this._encSSLName,this._encKey,this._encIV);e.setAutoPadding(!1);let r=t.slice(0,4);e.setAAD(r),this._onWrite(r);let i=e.update(t.slice(4));this._onWrite(i);let s=e.final();s.length&&this._onWrite(s);let o=e.getAuthTag();this._onWrite(o),ul(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},co=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new _o(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,r=16-(e-4&15);r<4&&(r+=16),e+=r;let i=Buffer.allocUnsafe(e+16);return Jt(i,e-4,0),i[4]=r,Jr(i,5+t,r),i}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},fo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=_n(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._aadLen=this._macETM?4:0,this._dead=!1;let r=e.cipherInfo.discardLen;if(r){let i=ji.get(r);i===void 0&&(i=Buffer.alloc(r),ji.set(r,i)),this._cipherInstance.update(i)}}free(){this._dead=!0}allocPacket(t){let e=this._encBlockLen,r=5+t,i=e-(r-this._aadLen&e-1);i<4&&(i+=e),r+=i;let s=Buffer.allocUnsafe(r);return Jt(s,r-4,0),s[4]=i,Jr(s,5+t,i),s}encrypt(t){if(this._dead)return;let e;if(this._macETM){let i=new Uint8Array(t.buffer,t.byteOffset,4),s=this._cipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+4,t.length-4));this._onWrite(i),this._onWrite(s),e=to(this._macSSLName,this._macKey),Jt(En,this.outSeqno,0),e.update(En),e.update(i),e.update(s)}else{let i=this._cipherInstance.update(t);this._onWrite(i),e=to(this._macSSLName,this._macKey),Jt(En,this.outSeqno,0),e.update(En),e.update(t)}let r=e.digest();r.length>this._macActualLen&&(r=r.slice(0,this._macActualLen)),this._onWrite(r),this.outSeqno=this.outSeqno+1>>>0}},uo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._macLen=e.macInfo.len,this._macActualLen=e.macInfo.actualLen,this._aadLen=e.macInfo.isETM?4:0,this._instance=new bo(e.cipherInfo.sslName,e.cipherKey,e.cipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=this._encBlockLen,r=5+t,i=e-(r-this._aadLen&e-1);i<4&&(i+=e),r+=i;let s=Buffer.allocUnsafe(r+this._macLen);return Jt(s,r-4,0),s[4]=i,Jr(s,5+t,i),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new Ur(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},lo=class{constructor(t,e){this.inSeqno=t,this._onPayload=e,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len>Zr||this._len<8||(4+this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._packetPos<this._len){let s=Math.min(this._len-this._packetPos,r-e),o;if(e!==0||s!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),e+=s,this._packetPos+=s,this._packetPos<this._len)return}let i=this._packet?new Ur(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):cl;this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},ho=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decKeyMain=e.decipherKey.slice(0,32),this._decKeyPktLen=e.decipherKey.slice(32),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._calcMac=Buffer.allocUnsafe(16),this._macPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenPos<4){let a=Math.min(4-this._lenPos,r-e);for(;a--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;Kt[0]=0,Jt(Kt,this.inSeqno,12);let c=Vi("chacha20",this._decKeyPktLen,Kt).update(this._lenBuf);if(this._len=zn(c,0),this._len>Zr||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length")}if(this._pktLen<this._len){if(e>=r)return;let a=Math.min(this._len-this._pktLen,r-e),c;if(e!==0||a!==r?c=new Uint8Array(t.buffer,t.byteOffset+e,a):c=t,a===this._len?this._packet=c:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(c,this._pktLen)),e+=a,this._pktLen+=a,this._pktLen<this._len||e>=r)return}{let a=Math.min(16-this._macPos,r-e);if(e!==0||a!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,a),this._macPos):this._mac.set(t,this._macPos),e+=a,this._macPos+=a,this._macPos<16)return}Kt[0]=0,Jt(Kt,this.inSeqno,12);let i=_n("chacha20",this._decKeyMain,Kt).update(fl);if(Io(Xn,this._lenBuf,4,this._packet,this._packet.length,i),this._calcMac.set(new Uint8Array(jn.HEAPU8.buffer,Xn,16),0),!ro(this._calcMac,this._mac))throw new Error("Invalid MAC");Kt[0]=1;let s=Vi("chacha20",this._decKeyMain,Kt).update(this._packet),o=new Ur(s.buffer,s.byteOffset+1,s.length-s[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let a=this._onPayload(o);if(a!==void 0)return a===!1?e:a}}}},po=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new So(e.decipherKey),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._macPos=0}free(){this._instance.free()}decrypt(t,e,r){for(;e<r;){if(this._lenPos<4){let s=Math.min(4-this._lenPos,r-e);for(;s--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;if(this._len=this._instance.decryptLen(this._lenBuf,this.inSeqno),this._len>Zr||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._pktLen<this._len){let s=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||s!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=r)return}{let s=Math.min(16-this._macPos,r-e);if(e!==0||s!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._macPos):this._mac.set(t,this._macPos),e+=s,this._macPos+=s,this._macPos<16)return}this._instance.decrypt(this._packet,this._mac,this.inSeqno);let i=new Ur(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},go=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=null,this._decipherSSLName=e.decipherInfo.sslName,this._decipherKey=e.decipherKey,this._decipherIV=e.decipherIV,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>Zr||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=Vi(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(Yp(this._len))}if(this._pktLen<this._len){if(e>=r)return;let s=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||s!==r?o=this._decipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+e,s)):o=this._decipherInstance.update(t),o.length&&(s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),this._packetPos+=o.length),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=r)return}{let s=Math.min(16-this._tagPos,r-e);if(e!==0||s!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._tagPos):this._tag.set(t,this._tagPos),e+=s,this._tagPos+=s,this._tagPos<16)return}{this._decipherInstance.setAuthTag(this._tag);let s=this._decipherInstance.final();s.length&&(this._packet?this._packet.set(s,this._packetPos):this._packet=s)}let i=this._packet?new Ur(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):cl;this.inSeqno=this.inSeqno+1>>>0,ul(this._decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tagPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},mo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new xo(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>Zr||this._len<16||(this._len&15)!==0)throw new Error(`Bad packet length: ${this._len}`)}if(this._pktLen<this._len){if(e>=r)return;let s=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||s!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=r)return}{let s=Math.min(16-this._tagPos,r-e);if(e!==0||s!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._tagPos):this._tag.set(t,this._tagPos),e+=s,this._tagPos+=s,this._tagPos<16)return}this._instance.decrypt(this._packet,this._len,this._tag);let i=new Ur(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tagPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},Ao=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=Vi(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._decipherInstance.setAutoPadding(!1),this._block=Buffer.allocUnsafe(e.macInfo.isETM?4:e.decipherInfo.blockLen),this._blockSize=e.decipherInfo.blockLen,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._macInstance=null;let r=e.decipherInfo.discardLen;if(r){let i=ji.get(r);i===void 0&&(i=Buffer.alloc(r),ji.set(r,i)),this._decipherInstance.update(i)}}free(){}decrypt(t,e,r){for(;e<r;){if(this._blockPos<this._block.length){let o=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||o!==r||o<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._blockPos):this._block.set(t,this._blockPos),e+=o,this._blockPos+=o,this._blockPos<this._block.length)return;let a,c;if(this._macETM?this._len=c=zn(this._block,0):(a=this._decipherInstance.update(this._block),this._len=zn(a,0),c=4+this._len-this._blockSize),this._len>Zr||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=to(this._macSSLName,this._macKey),Jt(En,this.inSeqno,0),this._macInstance.update(En),this._macETM?this._macInstance.update(this._block):(this._macInstance.update(new Uint8Array(a.buffer,a.byteOffset,4)),this._pktLen=a.length-4,this._packetPos=this._pktLen,this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(a.buffer,a.byteOffset+4,this._packetPos),0)),e>=r)return}if(this._pktLen<this._len){let o=Math.min(this._len-this._pktLen,r-e),a;e!==0||o!==r?a=new Uint8Array(t.buffer,t.byteOffset+e,o):a=t,this._macETM&&this._macInstance.update(a);let c=this._decipherInstance.update(a);if(c.length&&(o===this._len?this._packet=c:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(c,this._packetPos)),this._packetPos+=c.length),e+=o,this._pktLen+=o,this._pktLen<this._len||e>=r)return}{let o=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||o!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._macPos):this._mac.set(t,this._macPos),e+=o,this._macPos+=o,this._macPos<this._macActualLen)return}this._macETM||this._macInstance.update(this._packet);let i=this._macInstance.digest();if(this._macActualLen<i.length&&(i=new Uint8Array(i.buffer,i.byteOffset,this._macActualLen)),!Vp(i,this._mac))throw new Error("Invalid MAC");let s=new Ur(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._macPos=0,this._macInstance=null;{let o=this._onPayload(s);if(o!==void 0)return o===!1?e:o}}}},Eo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new wo(e.decipherInfo.sslName,e.decipherKey,e.decipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM,e.macInfo.actualLen),this._block=Buffer.allocUnsafe(e.macInfo.isETM||e.decipherInfo.stream?4:e.decipherInfo.blockLen),this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM}free(){this._instance.free()}decrypt(t,e,r){for(;e<r;){if(this._blockPos<this._block.length){let s=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||s!==r||s<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._blockPos):this._block.set(t,this._blockPos),e+=s,this._blockPos+=s,this._blockPos<this._block.length)return;let o;if(this._macETM?this._len=o=zn(this._block,0):(this._instance.decryptBlock(this._block),this._len=zn(this._block,0),o=4+this._len-this._block.length),this._len>Zr||this._len<5||(o&this._block.length-1)!==0)throw new Error("Bad packet length");if(this._macETM||(this._pktLen=this._block.length-4,this._pktLen&&(this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(this._block.buffer,this._block.byteOffset+4,this._pktLen),0))),e>=r)return}if(this._pktLen<this._len){let s=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||s!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=r)return}{let s=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||s!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._macPos):this._mac.set(t,this._macPos),e+=s,this._macPos+=s,this._macPos<this._macActualLen)return}this._instance.decrypt(this._packet,this.inSeqno,this._block,this._mac);let i=new Ur(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._macPos=0,this._macInstance=null;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}};function ul(n){++n[11]>>>8&&++n[10]>>>8&&++n[9]>>>8&&++n[8]>>>8&&++n[7]>>>8&&++n[6]>>>8&&++n[5]>>>8&&++n[4]>>>8}var Yp=(()=>{let n=Buffer.alloc(4);return t=>(n[0]=t>>>24,n[1]=t>>>16,n[2]=t>>>8,n[3]=t,n)})();function Vp(n,t){return n.length!==t.length?(ro(n,n),!1):ro(n,t)}function jp(n){if(typeof n!="object"||n===null)throw new Error("Invalid config");if(typeof n.outbound!="object"||n.outbound===null)throw new Error("Invalid outbound");let t=n.outbound;if(typeof t.onWrite!="function")throw new Error("Invalid outbound.onWrite");if(typeof t.cipherInfo!="object"||t.cipherInfo===null)throw new Error("Invalid outbound.cipherInfo");if(!Buffer.isBuffer(t.cipherKey)||t.cipherKey.length!==t.cipherInfo.keyLen)throw new Error("Invalid outbound.cipherKey");if(t.cipherInfo.ivLen&&(!Buffer.isBuffer(t.cipherIV)||t.cipherIV.length!==t.cipherInfo.ivLen))throw new Error("Invalid outbound.cipherIV");if(typeof t.seqno!="number"||t.seqno<0||t.seqno>al)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return _o&&!e?new co(n):new ao(n);case"chacha20":return yo&&!e?new oo(n):new so(n);default:{if(typeof t.macInfo!="object"||t.macInfo===null)throw new Error("Invalid outbound.macInfo");if(!Buffer.isBuffer(t.macKey)||t.macKey.length!==t.macInfo.len)throw new Error("Invalid outbound.macKey");return bo&&!e?new uo(n):new fo(n)}}}function zp(n){if(typeof n!="object"||n===null)throw new Error("Invalid config");if(typeof n.inbound!="object"||n.inbound===null)throw new Error("Invalid inbound");let t=n.inbound;if(typeof t.onPayload!="function")throw new Error("Invalid inbound.onPayload");if(typeof t.decipherInfo!="object"||t.decipherInfo===null)throw new Error("Invalid inbound.decipherInfo");if(!Buffer.isBuffer(t.decipherKey)||t.decipherKey.length!==t.decipherInfo.keyLen)throw new Error("Invalid inbound.decipherKey");if(t.decipherInfo.ivLen&&(!Buffer.isBuffer(t.decipherIV)||t.decipherIV.length!==t.decipherInfo.ivLen))throw new Error("Invalid inbound.decipherIV");if(typeof t.seqno!="number"||t.seqno<0||t.seqno>al)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return xo&&!e?new mo(n):new go(n);case"chacha20":return So&&!e?new po(n):new ho(n);default:{if(typeof t.macInfo!="object"||t.macInfo===null)throw new Error("Invalid inbound.macInfo");if(!Buffer.isBuffer(t.macKey)||t.macKey.length!==t.macInfo.len)throw new Error("Invalid inbound.macKey");return wo&&!e?new Eo(n):new Ao(n)}}}ll.exports={CIPHER_INFO:Kp,MAC_INFO:Gp,bindingAvailable:!!no,init:new Promise(async(n,t)=>{try{jn=await ol()(),Xn=jn._malloc(16),Io=jn.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}n()}),NullCipher:io,createCipher:jp,NullDecipher:lo,createDecipher:zp}});var Dr=ot((Cb,bl)=>{"use strict";var{createDecipheriv:Bo,createECDH:Xp,createHash:Zn,createHmac:Jp,createSign:Zp,createVerify:eg,getCiphers:tg,sign:hl,verify:dl}=require("crypto"),rg=tg(),{Ber:Be}=Gn(),ng=js().pbkdf,{CIPHER_INFO:ei}=Lr(),{eddsaSupported:vo,SUPPORTED_CIPHER:ig}=wr(),{bufferSlice:en,makeBufferParser:sg,readString:Ie,readUInt32BE:Jn,writeUInt32BE:Pt}=or(),Ir=Symbol("Hash Algorithm"),ar=Symbol("Private key PEM"),gr=Symbol("Public key PEM"),Or=Symbol("Public key SSH"),yn=Symbol("Decrypted Key"),Co=Object.create(null);{let n=Object.keys(ei);for(let t=0;t<n.length;++t){let e=ei[n[t]].sslName;!e||Co[e]||(Co[e]=ei[n[t]])}}var zi=sg();function cr(n,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
3
+ -----END PRIVATE KEY-----`,t=Buffer.from("a"),e,n;try{e=yr.sign(null,t,r),n=yr.verify(null,t,r,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&n===!0}return!1})(),tl=typeof yr.diffieHellman=="function"&&typeof yr.generateKeyPairSync=="function"&&typeof yr.createPublicKey=="function",Qi=["ecdh-sha2-nistp256","ecdh-sha2-nistp384","ecdh-sha2-nistp521","diffie-hellman-group-exchange-sha256","diffie-hellman-group14-sha256","diffie-hellman-group15-sha512","diffie-hellman-group16-sha512","diffie-hellman-group17-sha512","diffie-hellman-group18-sha512"];tl&&(Qi.unshift("curve25519-sha256"),Qi.unshift("curve25519-sha256@libssh.org"));var Yh=Qi.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),Vs=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];el&&Vs.unshift("ssh-ed25519");var jh=Vs.concat(["ssh-dss"]),rl=(()=>{let r=yr.getCiphers();return t=>r.includes(Vh[t].sslName)})(),Rr=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];gn&&gn.flags&&!gn.flags.aes?Zf?Rr.unshift("chacha20-poly1305@openssh.com"):Rr.push("chacha20-poly1305@openssh.com"):Zf&&gn&&gn.arch==="x86"?Rr.splice(4,0,"chacha20-poly1305@openssh.com"):Rr.push("chacha20-poly1305@openssh.com");Rr=Rr.filter(rl);var zh=Rr.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(rl)),nl=(()=>{let r=yr.getHashes();return t=>r.includes(Gh[t].sslName)})(),il=["hmac-sha2-256-etm@openssh.com","hmac-sha2-512-etm@openssh.com","hmac-sha1-etm@openssh.com","hmac-sha2-256","hmac-sha2-512","hmac-sha1"].filter(nl),Xh=il.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(nl)),sl=["none","zlib@openssh.com","zlib"],Jh=sl.concat([]),pn={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};Wi.exports={MESSAGE:{DISCONNECT:1,IGNORE:2,UNIMPLEMENTED:3,DEBUG:4,SERVICE_REQUEST:5,SERVICE_ACCEPT:6,EXT_INFO:7,KEXINIT:20,NEWKEYS:21,KEXDH_INIT:30,KEXDH_REPLY:31,KEXDH_GEX_GROUP:31,KEXDH_GEX_INIT:32,KEXDH_GEX_REPLY:33,KEXDH_GEX_REQUEST:34,KEXECDH_INIT:30,KEXECDH_REPLY:31,USERAUTH_REQUEST:50,USERAUTH_FAILURE:51,USERAUTH_SUCCESS:52,USERAUTH_BANNER:53,USERAUTH_PASSWD_CHANGEREQ:60,USERAUTH_PK_OK:60,USERAUTH_INFO_REQUEST:60,USERAUTH_INFO_RESPONSE:61,GLOBAL_REQUEST:80,REQUEST_SUCCESS:81,REQUEST_FAILURE:82,CHANNEL_OPEN:90,CHANNEL_OPEN_CONFIRMATION:91,CHANNEL_OPEN_FAILURE:92,CHANNEL_WINDOW_ADJUST:93,CHANNEL_DATA:94,CHANNEL_EXTENDED_DATA:95,CHANNEL_EOF:96,CHANNEL_CLOSE:97,CHANNEL_REQUEST:98,CHANNEL_SUCCESS:99,CHANNEL_FAILURE:100},DISCONNECT_REASON:{HOST_NOT_ALLOWED_TO_CONNECT:1,PROTOCOL_ERROR:2,KEY_EXCHANGE_FAILED:3,RESERVED:4,MAC_ERROR:5,COMPRESSION_ERROR:6,SERVICE_NOT_AVAILABLE:7,PROTOCOL_VERSION_NOT_SUPPORTED:8,HOST_KEY_NOT_VERIFIABLE:9,CONNECTION_LOST:10,BY_APPLICATION:11,TOO_MANY_CONNECTIONS:12,AUTH_CANCELED_BY_USER:13,NO_MORE_AUTH_METHODS_AVAILABLE:14,ILLEGAL_USER_NAME:15},DISCONNECT_REASON_STR:void 0,CHANNEL_OPEN_FAILURE:{ADMINISTRATIVELY_PROHIBITED:1,CONNECT_FAILED:2,UNKNOWN_CHANNEL_TYPE:3,RESOURCE_SHORTAGE:4},TERMINAL_MODE:{TTY_OP_END:0,VINTR:1,VQUIT:2,VERASE:3,VKILL:4,VEOF:5,VEOL:6,VEOL2:7,VSTART:8,VSTOP:9,VSUSP:10,VDSUSP:11,VREPRINT:12,VWERASE:13,VLNEXT:14,VFLUSH:15,VSWTCH:16,VSTATUS:17,VDISCARD:18,IGNPAR:30,PARMRK:31,INPCK:32,ISTRIP:33,INLCR:34,IGNCR:35,ICRNL:36,IUCLC:37,IXON:38,IXANY:39,IXOFF:40,IMAXBEL:41,ISIG:50,ICANON:51,XCASE:52,ECHO:53,ECHOE:54,ECHOK:55,ECHONL:56,NOFLSH:57,TOSTOP:58,IEXTEN:59,ECHOCTL:60,ECHOKE:61,PENDIN:62,OPOST:70,OLCUC:71,ONLCR:72,OCRNL:73,ONOCR:74,ONLRET:75,CS7:90,CS8:91,PARENB:92,PARODD:93,TTY_OP_ISPEED:128,TTY_OP_OSPEED:129},CHANNEL_EXTENDED_DATATYPE:{STDERR:1},SIGNALS:["ABRT","ALRM","FPE","HUP","ILL","INT","QUIT","SEGV","TERM","USR1","USR2","KILL","PIPE"].reduce((r,t)=>({...r,[t]:1}),{}),COMPAT:pn,COMPAT_CHECKS:[["Cisco-1.25",pn.BAD_DHGEX],[/^Cisco-1[.]/,pn.BUG_DHGEX_LARGE],[/^[0-9.]+$/,pn.OLD_EXIT],[/^OpenSSH_5[.][0-9]+/,pn.DYN_RPORT_BUG],[/^OpenSSH_7[.]4/,pn.IMPLY_RSA_SHA2_SIGALGS]],DEFAULT_KEX:Qi,SUPPORTED_KEX:Yh,DEFAULT_SERVER_HOST_KEY:Vs,SUPPORTED_SERVER_HOST_KEY:jh,DEFAULT_CIPHER:Rr,SUPPORTED_CIPHER:zh,DEFAULT_MAC:il,SUPPORTED_MAC:Xh,DEFAULT_COMPRESSION:sl,SUPPORTED_COMPRESSION:Jh,curve25519Supported:tl,eddsaSupported:el};Wi.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(Wi.exports.DISCONNECT_REASON)).reduce((r,[t,e])=>({...r,[e]:t}),{})});var or=ot((By,fl)=>{"use strict";var ir=Kn().Ber,qi,cl=Buffer[Symbol.species],Zh=Object.getPrototypeOf(Uint8Array.prototype).fill;function ol(r,t){return r[t++]*16777216+r[t++]*65536+r[t++]*256+r[t]}function Vn(r,t,e,n,i){i||(i=0),n>r.length&&(n=r.length);let s=n-e,o=t.length-i;return s>o&&(s=o),t.set(new Uint8Array(r.buffer,r.byteOffset+e,s),i),s}function Gn(r,t,e){return e===void 0&&(e=r.length),new cl(r.buffer,r.byteOffset+t,e-t)}function Ys(){let r=0,t,e={init:(n,i)=>{t=n,r=typeof i=="number"?i:0},pos:()=>r,length:()=>t?t.length:0,avail:()=>t&&r<t.length?t.length-r:0,clear:()=>{t=void 0},readUInt32BE:()=>{if(!(!t||r+3>=t.length))return t[r++]*16777216+t[r++]*65536+t[r++]*256+t[r++]},readUInt64BE:n=>{if(!(!t||r+7>=t.length))switch(n){case"always":return BigInt(`0x${t.hexSlice(r,r+=8)}`);case"maybe":if(t[r]>31)return BigInt(`0x${t.hexSlice(r,r+=8)}`);default:return t[r++]*72057594037927940+t[r++]*281474976710656+t[r++]*1099511627776+t[r++]*4294967296+t[r++]*16777216+t[r++]*65536+t[r++]*256+t[r++]}},skip:n=>{t&&n>0&&(r+=n)},skipString:()=>{let n=e.readUInt32BE();if(n!==void 0)return r+=n,r<=t.length?n:void 0},readByte:()=>{if(t&&r<t.length)return t[r++]},readBool:()=>{if(t&&r<t.length)return!!t[r++]},readList:()=>{let n=e.readString(!0);if(n!==void 0)return n?n.split(","):[]},readString:(n,i)=>{typeof n=="number"&&(i=n,n=void 0);let s=e.readUInt32BE();if(s!==void 0&&!(t.length-r<s||typeof i=="number"&&s>i))return n?Buffer.isBuffer(n)?Vn(t,n,r,r+=s):t.utf8Slice(r,r+=s):Gn(t,r,r+=s)},readRaw:n=>{if(t){if(typeof n!="number")return Gn(t,r,r+=t.length-r);if(t.length-r>=n)return Gn(t,r,r+=n)}}};return e}function al(r,t,e){let n=new Error(r);return typeof t=="boolean"?(e=t,n.level="protocol"):n.level=t||"protocol",n.fatal=!!e,n}function Gs(r,t,e){return r[e++]=t>>>24,r[e++]=t>>>16,r[e++]=t>>>8,r[e++]=t,e}var Ki=Ys();fl.exports={bufferCopy:Vn,bufferSlice:Gn,FastBuffer:cl,bufferFill:(r,t,e,n)=>Zh.call(r,t,e,n),makeError:al,doFatalError:(r,t,e,n)=>{let i;return qi===void 0&&({DISCONNECT_REASON:qi}=xr()),t instanceof Error?(i=t,typeof e!="number"?n=qi.PROTOCOL_ERROR:n=e):i=al(t,e,!0),typeof n!="number"&&(n=qi.PROTOCOL_ERROR),r.disconnect(n),r._destruct(),r._onError(i),1/0},readUInt32BE:ol,writeUInt32BE:Gs,writeUInt32LE:(r,t,e)=>(r[e++]=t,r[e++]=t>>>8,r[e++]=t>>>16,r[e++]=t>>>24,e),makeBufferParser:Ys,bufferParser:Ys(),readString:(r,t,e,n)=>{typeof e=="number"&&(n=e,e=void 0),t===void 0&&(t=0);let i=r.length-t;if(t<0||t>=r.length||i<4)return;let s=ol(r,t);if(i<4+s||typeof n=="number"&&s>n)return;t+=4;let o=t+s;return r._pos=o,e?Buffer.isBuffer(e)?Vn(r,e,t,o):r.utf8Slice(t,o):Gn(r,t,o)},sigSSHToASN1:(r,t)=>{switch(t){case"ssh-dss":{if(r.length>40)return r;let e=new ir.Writer;e.startSequence();let n=r.slice(0,20),i=r.slice(20);if(n[0]&128){let s=Buffer.allocUnsafe(21);s[0]=0,n.copy(s,1),n=s}else n[0]===0&&!(n[1]&128)&&(n=n.slice(1));if(i[0]&128){let s=Buffer.allocUnsafe(21);s[0]=0,i.copy(s,1),i=s}else i[0]===0&&!(i[1]&128)&&(i=i.slice(1));return e.writeBuffer(n,ir.Integer),e.writeBuffer(i,ir.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{Ki.init(r,0);let e=Ki.readString(),n=Ki.readString();if(Ki.clear(),e===void 0||n===void 0)return;let i=new ir.Writer;return i.startSequence(),i.writeBuffer(e,ir.Integer),i.writeBuffer(n,ir.Integer),i.endSequence(),i.buffer}default:return r}},convertSignature:(r,t)=>{switch(t){case"ssh-dss":{if(r.length<=40)return r;let e=new ir.Reader(r);e.readSequence();let n=e.readString(ir.Integer,!0),i=e.readString(ir.Integer,!0),s=0,o=0;if(n.length<20){let c=Buffer.allocUnsafe(20);c.set(n,1),n=c,n[0]=0}if(i.length<20){let c=Buffer.allocUnsafe(20);c.set(i,1),i=c,i[0]=0}n.length>20&&n[0]===0&&(s=1),i.length>20&&i[0]===0&&(o=1);let a=Buffer.allocUnsafe(n.length-s+(i.length-o));return Vn(n,a,s,n.length,0),Vn(i,a,o,i.length,n.length-s),a}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{if(r[0]===0)return r;let e=new ir.Reader(r);e.readSequence();let n=e.readString(ir.Integer,!0),i=e.readString(ir.Integer,!0);if(n===null||i===null)return;let s=Buffer.allocUnsafe(4+n.length+4+i.length);return Gs(s,n.length,0),s.set(n,4),Gs(s,i.length,4+n.length),s.set(i,8+n.length),s}}return r},sendPacket:(r,t,e)=>!e&&r._kexinit!==void 0?(r._queue===void 0&&(r._queue=[]),r._queue.push(t),r._debug&&r._debug("Outbound: ... packet queued"),!1):(r._cipher.encrypt(t),!0)}});var ll=ot((Vi,zs)=>{var js=(function(){var r=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename<"u"&&(r=r||__filename),(function(t){t=t||{};var e;e||(e=typeof t<"u"?t:{});var n,i;e.ready=new Promise(function(K,fe){n=K,i=fe});var s={},o;for(o in e)e.hasOwnProperty(o)&&(s[o]=e[o]);var a=typeof window=="object",c=typeof importScripts=="function",f=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",l="",u,h,g,b,_;f?(l=c?require("path").dirname(l)+"/":__dirname+"/",u=function(K,fe){var be=Ar(K);return be?fe?be:be.toString():(b||(b=require("fs")),_||(_=require("path")),K=_.normalize(K),b.readFileSync(K,fe?null:"utf8"))},g=function(K){return K=u(K,!0),K.buffer||(K=new Uint8Array(K)),W(K.buffer),K},h=function(K,fe,be){var Re=Ar(K);Re&&fe(Re),b||(b=require("fs")),_||(_=require("path")),K=_.normalize(K),b.readFile(K,function(je,It){je?be(je):fe(It.buffer)})},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),e.inspect=function(){return"[Emscripten Module object]"}):(a||c)&&(c?l=self.location.href:typeof document<"u"&&document.currentScript&&(l=document.currentScript.src),r&&(l=r),l.indexOf("blob:")!==0?l=l.substr(0,l.lastIndexOf("/")+1):l="",u=function(K){try{var fe=new XMLHttpRequest;return fe.open("GET",K,!1),fe.send(null),fe.responseText}catch(je){if(K=Ar(K)){fe=[];for(var be=0;be<K.length;be++){var Re=K[be];255<Re&&(en&&W(!1,"Character code "+Re+" ("+String.fromCharCode(Re)+") at offset "+be+" not in 0x00-0xFF."),Re&=255),fe.push(String.fromCharCode(Re))}return fe.join("")}throw je}},c&&(g=function(K){try{var fe=new XMLHttpRequest;return fe.open("GET",K,!1),fe.responseType="arraybuffer",fe.send(null),new Uint8Array(fe.response)}catch(be){if(K=Ar(K))return K;throw be}}),h=function(K,fe,be){var Re=new XMLHttpRequest;Re.open("GET",K,!0),Re.responseType="arraybuffer",Re.onload=function(){if(Re.status==200||Re.status==0&&Re.response)fe(Re.response);else{var je=Ar(K);je?fe(je.buffer):be()}},Re.onerror=be,Re.send(null)}),e.print||console.log.bind(console);var x=e.printErr||console.warn.bind(console);for(o in s)s.hasOwnProperty(o)&&(e[o]=s[o]);s=null;var S;e.wasmBinary&&(S=e.wasmBinary);var N=e.noExitRuntime||!0;typeof WebAssembly!="object"&&M("no native wasm support detected");var O,P=!1;function W(K,fe){K||M("Assertion failed: "+fe)}function X(K){var fe=e["_"+K];return W(fe,"Cannot call unknown function "+K+", make sure it is exported"),fe}function G(K,fe,be,Re){var je={string:function(st){var Bt=0;if(st!=null&&st!==0){var vt=(st.length<<2)+1;Bt=Mn(vt);var At=Bt,lt=q;if(0<vt){vt=At+vt-1;for(var Zt=0;Zt<st.length;++Zt){var Et=st.charCodeAt(Zt);if(55296<=Et&&57343>=Et){var Wr=st.charCodeAt(++Zt);Et=65536+((Et&1023)<<10)|Wr&1023}if(127>=Et){if(At>=vt)break;lt[At++]=Et}else{if(2047>=Et){if(At+1>=vt)break;lt[At++]=192|Et>>6}else{if(65535>=Et){if(At+2>=vt)break;lt[At++]=224|Et>>12}else{if(At+3>=vt)break;lt[At++]=240|Et>>18,lt[At++]=128|Et>>12&63}lt[At++]=128|Et>>6&63}lt[At++]=128|Et&63}}lt[At]=0}}return Bt},array:function(st){var Bt=Mn(st.length);return D.set(st,Bt),Bt}},It=X(K),ur=[];if(K=0,Re)for(var jt=0;jt<Re.length;jt++){var on=je[be[jt]];on?(K===0&&(K=On()),ur[jt]=on(Re[jt])):ur[jt]=Re[jt]}return be=It.apply(null,ur),be=(function(st){if(fe==="string")if(st){for(var Bt=q,vt=st+NaN,At=st;Bt[At]&&!(At>=vt);)++At;if(16<At-st&&Bt.subarray&&w)st=w.decode(Bt.subarray(st,At));else{for(vt="";st<At;){var lt=Bt[st++];if(lt&128){var Zt=Bt[st++]&63;if((lt&224)==192)vt+=String.fromCharCode((lt&31)<<6|Zt);else{var Et=Bt[st++]&63;lt=(lt&240)==224?(lt&15)<<12|Zt<<6|Et:(lt&7)<<18|Zt<<12|Et<<6|Bt[st++]&63,65536>lt?vt+=String.fromCharCode(lt):(lt-=65536,vt+=String.fromCharCode(55296|lt>>10,56320|lt&1023))}}else vt+=String.fromCharCode(lt)}st=vt}}else st="";else st=fe==="boolean"?!!st:st;return st})(be),K!==0&&wi(K),be}var w=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,I,D,q;function Q(){var K=O.buffer;I=K,e.HEAP8=D=new Int8Array(K),e.HEAP16=new Int16Array(K),e.HEAP32=new Int32Array(K),e.HEAPU8=q=new Uint8Array(K),e.HEAPU16=new Uint16Array(K),e.HEAPU32=new Uint32Array(K),e.HEAPF32=new Float32Array(K),e.HEAPF64=new Float64Array(K)}var ae,te=[],Z=[],re=[];function ce(){var K=e.preRun.shift();te.unshift(K)}var U=0,C=null,k=null;e.preloadedImages={},e.preloadedAudios={};function M(K){throw e.onAbort&&e.onAbort(K),x(K),P=!0,K=new WebAssembly.RuntimeError("abort("+K+"). Build with -s ASSERTIONS=1 for more info."),i(K),K}var Y="data:application/octet-stream;base64,",oe;if(oe="data:application/octet-stream;base64,AGFzbQEAAAABIAZgAX8Bf2ADf39/AGABfwBgAABgAAF/YAZ/f39/f38AAgcBAWEBYQAAAwsKAAEDAQAAAgQFAgQFAXABAQEFBwEBgAKAgAIGCQF/AUGAjMACCwclCQFiAgABYwADAWQACQFlAAgBZgAHAWcABgFoAAUBaQAKAWoBAAqGTQpPAQJ/QYAIKAIAIgEgAEEDakF8cSICaiEAAkAgAkEAIAAgAU0bDQAgAD8AQRB0SwRAIAAQAEUNAQtBgAggADYCACABDwtBhAhBMDYCAEF/C4wFAg5+Cn8gACgCJCEUIAAoAiAhFSAAKAIcIREgACgCGCESIAAoAhQhEyACQRBPBEAgAC0ATEVBGHQhFyAAKAIEIhZBBWytIQ8gACgCCCIYQQVsrSENIAAoAgwiGUEFbK0hCyAAKAIQIhpBBWytIQkgADUCACEIIBqtIRAgGa0hDiAYrSEMIBatIQoDQCASIAEtAAMiEiABLQAEQQh0ciABLQAFQRB0ciABLQAGIhZBGHRyQQJ2Qf///x9xaq0iAyAOfiABLwAAIAEtAAJBEHRyIBNqIBJBGHRBgICAGHFqrSIEIBB+fCARIAEtAAdBCHQgFnIgAS0ACEEQdHIgAS0ACSIRQRh0ckEEdkH///8fcWqtIgUgDH58IAEtAApBCHQgEXIgAS0AC0EQdHIgAS0ADEEYdHJBBnYgFWqtIgYgCn58IBQgF2ogAS8ADSABLQAPQRB0cmqtIgcgCH58IAMgDH4gBCAOfnwgBSAKfnwgBiAIfnwgByAJfnwgAyAKfiAEIAx+fCAFIAh+fCAGIAl+fCAHIAt+fCADIAh+IAQgCn58IAUgCX58IAYgC358IAcgDX58IAMgCX4gBCAIfnwgBSALfnwgBiANfnwgByAPfnwiA0IaiEL/////D4N8IgRCGohC/////w+DfCIFQhqIQv////8Pg3wiBkIaiEL/////D4N8IgdCGoinQQVsIAOnQf///x9xaiITQRp2IASnQf///x9xaiESIAWnQf///x9xIREgBqdB////H3EhFSAHp0H///8fcSEUIBNB////H3EhEyABQRBqIQEgAkEQayICQQ9LDQALCyAAIBQ2AiQgACAVNgIgIAAgETYCHCAAIBI2AhggACATNgIUCwMAAQu2BAEGfwJAIAAoAjgiBARAIABBPGohBQJAIAJBECAEayIDIAIgA0kbIgZFDQAgBkEDcSEHAkAgBkEBa0EDSQRAQQAhAwwBCyAGQXxxIQhBACEDA0AgBSADIARqaiABIANqLQAAOgAAIAUgA0EBciIEIAAoAjhqaiABIARqLQAAOgAAIAUgA0ECciIEIAAoAjhqaiABIARqLQAAOgAAIAUgA0EDciIEIAAoAjhqaiABIARqLQAAOgAAIANBBGohAyAAKAI4IQQgCEEEayIIDQALCyAHRQ0AA0AgBSADIARqaiABIANqLQAAOgAAIANBAWohAyAAKAI4IQQgB0EBayIHDQALCyAAIAQgBmoiAzYCOCADQRBJDQEgACAFQRAQAiAAQQA2AjggAiAGayECIAEgBmohAQsgAkEQTwRAIAAgASACQXBxIgMQAiACQQ9xIQIgASADaiEBCyACRQ0AIAJBA3EhBCAAQTxqIQVBACEDIAJBAWtBA08EQCACQXxxIQcDQCAFIAAoAjggA2pqIAEgA2otAAA6AAAgBSADQQFyIgYgACgCOGpqIAEgBmotAAA6AAAgBSADQQJyIgYgACgCOGpqIAEgBmotAAA6AAAgBSADQQNyIgYgACgCOGpqIAEgBmotAAA6AAAgA0EEaiEDIAdBBGsiBw0ACwsgBARAA0AgBSAAKAI4IANqaiABIANqLQAAOgAAIANBAWohAyAEQQFrIgQNAAsLIAAgACgCOCACajYCOAsLoS0BDH8jAEEQayIMJAACQAJAAkACQAJAAkACQAJAAkACQAJAAkAgAEH0AU0EQEGICCgCACIFQRAgAEELakF4cSAAQQtJGyIIQQN2IgJ2IgFBA3EEQCABQX9zQQFxIAJqIgNBA3QiAUG4CGooAgAiBEEIaiEAAkAgBCgCCCICIAFBsAhqIgFGBEBBiAggBUF+IAN3cTYCAAwBCyACIAE2AgwgASACNgIICyAEIANBA3QiAUEDcjYCBCABIARqIgEgASgCBEEBcjYCBAwNCyAIQZAIKAIAIgpNDQEgAQRAAkBBAiACdCIAQQAgAGtyIAEgAnRxIgBBACAAa3FBAWsiACAAQQx2QRBxIgJ2IgFBBXZBCHEiACACciABIAB2IgFBAnZBBHEiAHIgASAAdiIBQQF2QQJxIgByIAEgAHYiAUEBdkEBcSIAciABIAB2aiIDQQN0IgBBuAhqKAIAIgQoAggiASAAQbAIaiIARgRAQYgIIAVBfiADd3EiBTYCAAwBCyABIAA2AgwgACABNgIICyAEQQhqIQAgBCAIQQNyNgIEIAQgCGoiAiADQQN0IgEgCGsiA0EBcjYCBCABIARqIAM2AgAgCgRAIApBA3YiAUEDdEGwCGohB0GcCCgCACEEAn8gBUEBIAF0IgFxRQRAQYgIIAEgBXI2AgAgBwwBCyAHKAIICyEBIAcgBDYCCCABIAQ2AgwgBCAHNgIMIAQgATYCCAtBnAggAjYCAEGQCCADNgIADA0LQYwIKAIAIgZFDQEgBkEAIAZrcUEBayIAIABBDHZBEHEiAnYiAUEFdkEIcSIAIAJyIAEgAHYiAUECdkEEcSIAciABIAB2IgFBAXZBAnEiAHIgASAAdiIBQQF2QQFxIgByIAEgAHZqQQJ0QbgKaigCACIBKAIEQXhxIAhrIQMgASECA0ACQCACKAIQIgBFBEAgAigCFCIARQ0BCyAAKAIEQXhxIAhrIgIgAyACIANJIgIbIQMgACABIAIbIQEgACECDAELCyABIAhqIgkgAU0NAiABKAIYIQsgASABKAIMIgRHBEAgASgCCCIAQZgIKAIASRogACAENgIMIAQgADYCCAwMCyABQRRqIgIoAgAiAEUEQCABKAIQIgBFDQQgAUEQaiECCwNAIAIhByAAIgRBFGoiAigCACIADQAgBEEQaiECIAQoAhAiAA0ACyAHQQA2AgAMCwtBfyEIIABBv39LDQAgAEELaiIAQXhxIQhBjAgoAgAiCUUNAEEAIAhrIQMCQAJAAkACf0EAIAhBgAJJDQAaQR8gCEH///8HSw0AGiAAQQh2IgAgAEGA/j9qQRB2QQhxIgJ0IgAgAEGA4B9qQRB2QQRxIgF0IgAgAEGAgA9qQRB2QQJxIgB0QQ92IAEgAnIgAHJrIgBBAXQgCCAAQRVqdkEBcXJBHGoLIgVBAnRBuApqKAIAIgJFBEBBACEADAELQQAhACAIQQBBGSAFQQF2ayAFQR9GG3QhAQNAAkAgAigCBEF4cSAIayIHIANPDQAgAiEEIAciAw0AQQAhAyACIQAMAwsgACACKAIUIgcgByACIAFBHXZBBHFqKAIQIgJGGyAAIAcbIQAgAUEBdCEBIAINAAsLIAAgBHJFBEBBACEEQQIgBXQiAEEAIABrciAJcSIARQ0DIABBACAAa3FBAWsiACAAQQx2QRBxIgJ2IgFBBXZBCHEiACACciABIAB2IgFBAnZBBHEiAHIgASAAdiIBQQF2QQJxIgByIAEgAHYiAUEBdkEBcSIAciABIAB2akECdEG4CmooAgAhAAsgAEUNAQsDQCAAKAIEQXhxIAhrIgEgA0khAiABIAMgAhshAyAAIAQgAhshBCAAKAIQIgEEfyABBSAAKAIUCyIADQALCyAERQ0AIANBkAgoAgAgCGtPDQAgBCAIaiIGIARNDQEgBCgCGCEFIAQgBCgCDCIBRwRAIAQoAggiAEGYCCgCAEkaIAAgATYCDCABIAA2AggMCgsgBEEUaiICKAIAIgBFBEAgBCgCECIARQ0EIARBEGohAgsDQCACIQcgACIBQRRqIgIoAgAiAA0AIAFBEGohAiABKAIQIgANAAsgB0EANgIADAkLIAhBkAgoAgAiAk0EQEGcCCgCACEDAkAgAiAIayIBQRBPBEBBkAggATYCAEGcCCADIAhqIgA2AgAgACABQQFyNgIEIAIgA2ogATYCACADIAhBA3I2AgQMAQtBnAhBADYCAEGQCEEANgIAIAMgAkEDcjYCBCACIANqIgAgACgCBEEBcjYCBAsgA0EIaiEADAsLIAhBlAgoAgAiBkkEQEGUCCAGIAhrIgE2AgBBoAhBoAgoAgAiAiAIaiIANgIAIAAgAUEBcjYCBCACIAhBA3I2AgQgAkEIaiEADAsLQQAhACAIQS9qIgkCf0HgCygCAARAQegLKAIADAELQewLQn83AgBB5AtCgKCAgICABDcCAEHgCyAMQQxqQXBxQdiq1aoFczYCAEH0C0EANgIAQcQLQQA2AgBBgCALIgFqIgVBACABayIHcSICIAhNDQpBwAsoAgAiBARAQbgLKAIAIgMgAmoiASADTQ0LIAEgBEsNCwtBxAstAABBBHENBQJAAkBBoAgoAgAiAwRAQcgLIQADQCADIAAoAgAiAU8EQCABIAAoAgRqIANLDQMLIAAoAggiAA0ACwtBABABIgFBf0YNBiACIQVB5AsoAgAiA0EBayIAIAFxBEAgAiABayAAIAFqQQAgA2txaiEFCyAFIAhNDQYgBUH+////B0sNBkHACygCACIEBEBBuAsoAgAiAyAFaiIAIANNDQcgACAESw0HCyAFEAEiACABRw0BDAgLIAUgBmsgB3EiBUH+////B0sNBSAFEAEiASAAKAIAIAAoAgRqRg0EIAEhAAsCQCAAQX9GDQAgCEEwaiAFTQ0AQegLKAIAIgEgCSAFa2pBACABa3EiAUH+////B0sEQCAAIQEMCAsgARABQX9HBEAgASAFaiEFIAAhAQwIC0EAIAVrEAEaDAULIAAiAUF/Rw0GDAQLAAtBACEEDAcLQQAhAQwFCyABQX9HDQILQcQLQcQLKAIAQQRyNgIACyACQf7///8HSw0BIAIQASEBQQAQASEAIAFBf0YNASAAQX9GDQEgACABTQ0BIAAgAWsiBSAIQShqTQ0BC0G4C0G4CygCACAFaiIANgIAQbwLKAIAIABJBEBBvAsgADYCAAsCQAJAAkBBoAgoAgAiBwRAQcgLIQADQCABIAAoAgAiAyAAKAIEIgJqRg0CIAAoAggiAA0ACwwCC0GYCCgCACIAQQAgACABTRtFBEBBmAggATYCAAtBACEAQcwLIAU2AgBByAsgATYCAEGoCEF/NgIAQawIQeALKAIANgIAQdQLQQA2AgADQCAAQQN0IgNBuAhqIANBsAhqIgI2AgAgA0G8CGogAjYCACAAQQFqIgBBIEcNAAtBlAggBUEoayIDQXggAWtBB3FBACABQQhqQQdxGyIAayICNgIAQaAIIAAgAWoiADYCACAAIAJBAXI2AgQgASADakEoNgIEQaQIQfALKAIANgIADAILIAAtAAxBCHENACADIAdLDQAgASAHTQ0AIAAgAiAFajYCBEGgCCAHQXggB2tBB3FBACAHQQhqQQdxGyIAaiICNgIAQZQIQZQIKAIAIAVqIgEgAGsiADYCACACIABBAXI2AgQgASAHakEoNgIEQaQIQfALKAIANgIADAELQZgIKAIAIAFLBEBBmAggATYCAAsgASAFaiECQcgLIQACQAJAAkACQAJAAkADQCACIAAoAgBHBEAgACgCCCIADQEMAgsLIAAtAAxBCHFFDQELQcgLIQADQCAHIAAoAgAiAk8EQCACIAAoAgRqIgQgB0sNAwsgACgCCCEADAALAAsgACABNgIAIAAgACgCBCAFajYCBCABQXggAWtBB3FBACABQQhqQQdxG2oiCSAIQQNyNgIEIAJBeCACa0EHcUEAIAJBCGpBB3EbaiIFIAggCWoiBmshAiAFIAdGBEBBoAggBjYCAEGUCEGUCCgCACACaiIANgIAIAYgAEEBcjYCBAwDCyAFQZwIKAIARgRAQZwIIAY2AgBBkAhBkAgoAgAgAmoiADYCACAGIABBAXI2AgQgACAGaiAANgIADAMLIAUoAgQiAEEDcUEBRgRAIABBeHEhBwJAIABB/wFNBEAgBSgCCCIDIABBA3YiAEEDdEGwCGpGGiADIAUoAgwiAUYEQEGICEGICCgCAEF+IAB3cTYCAAwCCyADIAE2AgwgASADNgIIDAELIAUoAhghCAJAIAUgBSgCDCIBRwRAIAUoAggiACABNgIMIAEgADYCCAwBCwJAIAVBFGoiACgCACIDDQAgBUEQaiIAKAIAIgMNAEEAIQEMAQsDQCAAIQQgAyIBQRRqIgAoAgAiAw0AIAFBEGohACABKAIQIgMNAAsgBEEANgIACyAIRQ0AAkAgBSAFKAIcIgNBAnRBuApqIgAoAgBGBEAgACABNgIAIAENAUGMCEGMCCgCAEF+IAN3cTYCAAwCCyAIQRBBFCAIKAIQIAVGG2ogATYCACABRQ0BCyABIAg2AhggBSgCECIABEAgASAANgIQIAAgATYCGAsgBSgCFCIARQ0AIAEgADYCFCAAIAE2AhgLIAUgB2ohBSACIAdqIQILIAUgBSgCBEF+cTYCBCAGIAJBAXI2AgQgAiAGaiACNgIAIAJB/wFNBEAgAkEDdiIAQQN0QbAIaiECAn9BiAgoAgAiAUEBIAB0IgBxRQRAQYgIIAAgAXI2AgAgAgwBCyACKAIICyEAIAIgBjYCCCAAIAY2AgwgBiACNgIMIAYgADYCCAwDC0EfIQAgAkH///8HTQRAIAJBCHYiACAAQYD+P2pBEHZBCHEiA3QiACAAQYDgH2pBEHZBBHEiAXQiACAAQYCAD2pBEHZBAnEiAHRBD3YgASADciAAcmsiAEEBdCACIABBFWp2QQFxckEcaiEACyAGIAA2AhwgBkIANwIQIABBAnRBuApqIQQCQEGMCCgCACIDQQEgAHQiAXFFBEBBjAggASADcjYCACAEIAY2AgAgBiAENgIYDAELIAJBAEEZIABBAXZrIABBH0YbdCEAIAQoAgAhAQNAIAEiAygCBEF4cSACRg0DIABBHXYhASAAQQF0IQAgAyABQQRxaiIEKAIQIgENAAsgBCAGNgIQIAYgAzYCGAsgBiAGNgIMIAYgBjYCCAwCC0GUCCAFQShrIgNBeCABa0EHcUEAIAFBCGpBB3EbIgBrIgI2AgBBoAggACABaiIANgIAIAAgAkEBcjYCBCABIANqQSg2AgRBpAhB8AsoAgA2AgAgByAEQScgBGtBB3FBACAEQSdrQQdxG2pBL2siACAAIAdBEGpJGyICQRs2AgQgAkHQCykCADcCECACQcgLKQIANwIIQdALIAJBCGo2AgBBzAsgBTYCAEHICyABNgIAQdQLQQA2AgAgAkEYaiEAA0AgAEEHNgIEIABBCGohASAAQQRqIQAgASAESQ0ACyACIAdGDQMgAiACKAIEQX5xNgIEIAcgAiAHayIEQQFyNgIEIAIgBDYCACAEQf8BTQRAIARBA3YiAEEDdEGwCGohAgJ/QYgIKAIAIgFBASAAdCIAcUUEQEGICCAAIAFyNgIAIAIMAQsgAigCCAshACACIAc2AgggACAHNgIMIAcgAjYCDCAHIAA2AggMBAtBHyEAIAdCADcCECAEQf///wdNBEAgBEEIdiIAIABBgP4/akEQdkEIcSICdCIAIABBgOAfakEQdkEEcSIBdCIAIABBgIAPakEQdkECcSIAdEEPdiABIAJyIAByayIAQQF0IAQgAEEVanZBAXFyQRxqIQALIAcgADYCHCAAQQJ0QbgKaiEDAkBBjAgoAgAiAkEBIAB0IgFxRQRAQYwIIAEgAnI2AgAgAyAHNgIAIAcgAzYCGAwBCyAEQQBBGSAAQQF2ayAAQR9GG3QhACADKAIAIQEDQCABIgIoAgRBeHEgBEYNBCAAQR12IQEgAEEBdCEAIAIgAUEEcWoiAygCECIBDQALIAMgBzYCECAHIAI2AhgLIAcgBzYCDCAHIAc2AggMAwsgAygCCCIAIAY2AgwgAyAGNgIIIAZBADYCGCAGIAM2AgwgBiAANgIICyAJQQhqIQAMBQsgAigCCCIAIAc2AgwgAiAHNgIIIAdBADYCGCAHIAI2AgwgByAANgIIC0GUCCgCACIAIAhNDQBBlAggACAIayIBNgIAQaAIQaAIKAIAIgIgCGoiADYCACAAIAFBAXI2AgQgAiAIQQNyNgIEIAJBCGohAAwDC0GECEEwNgIAQQAhAAwCCwJAIAVFDQACQCAEKAIcIgJBAnRBuApqIgAoAgAgBEYEQCAAIAE2AgAgAQ0BQYwIIAlBfiACd3EiCTYCAAwCCyAFQRBBFCAFKAIQIARGG2ogATYCACABRQ0BCyABIAU2AhggBCgCECIABEAgASAANgIQIAAgATYCGAsgBCgCFCIARQ0AIAEgADYCFCAAIAE2AhgLAkAgA0EPTQRAIAQgAyAIaiIAQQNyNgIEIAAgBGoiACAAKAIEQQFyNgIEDAELIAQgCEEDcjYCBCAGIANBAXI2AgQgAyAGaiADNgIAIANB/wFNBEAgA0EDdiIAQQN0QbAIaiECAn9BiAgoAgAiAUEBIAB0IgBxRQRAQYgIIAAgAXI2AgAgAgwBCyACKAIICyEAIAIgBjYCCCAAIAY2AgwgBiACNgIMIAYgADYCCAwBC0EfIQAgA0H///8HTQRAIANBCHYiACAAQYD+P2pBEHZBCHEiAnQiACAAQYDgH2pBEHZBBHEiAXQiACAAQYCAD2pBEHZBAnEiAHRBD3YgASACciAAcmsiAEEBdCADIABBFWp2QQFxckEcaiEACyAGIAA2AhwgBkIANwIQIABBAnRBuApqIQICQAJAIAlBASAAdCIBcUUEQEGMCCABIAlyNgIAIAIgBjYCACAGIAI2AhgMAQsgA0EAQRkgAEEBdmsgAEEfRht0IQAgAigCACEIA0AgCCIBKAIEQXhxIANGDQIgAEEddiECIABBAXQhACABIAJBBHFqIgIoAhAiCA0ACyACIAY2AhAgBiABNgIYCyAGIAY2AgwgBiAGNgIIDAELIAEoAggiACAGNgIMIAEgBjYCCCAGQQA2AhggBiABNgIMIAYgADYCCAsgBEEIaiEADAELAkAgC0UNAAJAIAEoAhwiAkECdEG4CmoiACgCACABRgRAIAAgBDYCACAEDQFBjAggBkF+IAJ3cTYCAAwCCyALQRBBFCALKAIQIAFGG2ogBDYCACAERQ0BCyAEIAs2AhggASgCECIABEAgBCAANgIQIAAgBDYCGAsgASgCFCIARQ0AIAQgADYCFCAAIAQ2AhgLAkAgA0EPTQRAIAEgAyAIaiIAQQNyNgIEIAAgAWoiACAAKAIEQQFyNgIEDAELIAEgCEEDcjYCBCAJIANBAXI2AgQgAyAJaiADNgIAIAoEQCAKQQN2IgBBA3RBsAhqIQRBnAgoAgAhAgJ/QQEgAHQiACAFcUUEQEGICCAAIAVyNgIAIAQMAQsgBCgCCAshACAEIAI2AgggACACNgIMIAIgBDYCDCACIAA2AggLQZwIIAk2AgBBkAggAzYCAAsgAUEIaiEACyAMQRBqJAAgAAsQACMAIABrQXBxIgAkACAACwYAIAAkAAsEACMAC4AJAgh/BH4jAEGQAWsiBiQAIAYgBS0AA0EYdEGAgIAYcSAFLwAAIAUtAAJBEHRycjYCACAGIAUoAANBAnZBg/7/H3E2AgQgBiAFKAAGQQR2Qf+B/x9xNgIIIAYgBSgACUEGdkH//8AfcTYCDCAFLwANIQggBS0ADyEJIAZCADcCFCAGQgA3AhwgBkEANgIkIAYgCCAJQRB0QYCAPHFyNgIQIAYgBSgAEDYCKCAGIAUoABQ2AiwgBiAFKAAYNgIwIAUoABwhBSAGQQA6AEwgBkEANgI4IAYgBTYCNCAGIAEgAhAEIAQEQCAGIAMgBBAECyAGKAI4IgEEQCAGQTxqIgIgAWpBAToAACABQQFqQQ9NBEAgASAGakE9aiEEAkBBDyABayIDRQ0AIAMgBGoiAUEBa0EAOgAAIARBADoAACADQQNJDQAgAUECa0EAOgAAIARBADoAASABQQNrQQA6AAAgBEEAOgACIANBB0kNACABQQRrQQA6AAAgBEEAOgADIANBCUkNACAEQQAgBGtBA3EiAWoiBEEANgIAIAQgAyABa0F8cSIBaiIDQQRrQQA2AgAgAUEJSQ0AIARBADYCCCAEQQA2AgQgA0EIa0EANgIAIANBDGtBADYCACABQRlJDQAgBEEANgIYIARBADYCFCAEQQA2AhAgBEEANgIMIANBEGtBADYCACADQRRrQQA2AgAgA0EYa0EANgIAIANBHGtBADYCACABIARBBHFBGHIiAWsiA0EgSQ0AIAEgBGohAQNAIAFCADcDGCABQgA3AxAgAUIANwMIIAFCADcDACABQSBqIQEgA0EgayIDQR9LDQALCwsgBkEBOgBMIAYgAkEQEAILIAY1AjQhECAGNQIwIREgBjUCLCEOIAAgBjUCKCAGKAIkIAYoAiAgBigCHCAGKAIYIgNBGnZqIgJBGnZqIgFBGnZqIgtBgICAYHIgAUH///8fcSINIAJB////H3EiCCAGKAIUIAtBGnZBBWxqIgFB////H3EiCUEFaiIFQRp2IANB////H3EgAUEadmoiA2oiAUEadmoiAkEadmoiBEEadmoiDEEfdSIHIANxIAEgDEEfdkEBayIDQf///x9xIgpxciIBQRp0IAUgCnEgByAJcXJyrXwiDzwAACAAIA9CGIg8AAMgACAPQhCIPAACIAAgD0IIiDwAASAAIA4gByAIcSACIApxciICQRR0IAFBBnZyrXwgD0IgiHwiDjwABCAAIA5CGIg8AAcgACAOQhCIPAAGIAAgDkIIiDwABSAAIBEgByANcSAEIApxciIBQQ50IAJBDHZyrXwgDkIgiHwiDjwACCAAIA5CGIg8AAsgACAOQhCIPAAKIAAgDkIIiDwACSAAIBAgAyAMcSAHIAtxckEIdCABQRJ2cq18IA5CIIh8Ig48AAwgACAOQhiIPAAPIAAgDkIQiDwADiAAIA5CCIg8AA0gBkIANwIwIAZCADcCKCAGQgA3AiAgBkIANwIYIAZCADcCECAGQgA3AgggBkIANwIAIAZBkAFqJAALpwwBB38CQCAARQ0AIABBCGsiAyAAQQRrKAIAIgFBeHEiAGohBQJAIAFBAXENACABQQNxRQ0BIAMgAygCACIBayIDQZgIKAIASQ0BIAAgAWohACADQZwIKAIARwRAIAFB/wFNBEAgAygCCCICIAFBA3YiBEEDdEGwCGpGGiACIAMoAgwiAUYEQEGICEGICCgCAEF+IAR3cTYCAAwDCyACIAE2AgwgASACNgIIDAILIAMoAhghBgJAIAMgAygCDCIBRwRAIAMoAggiAiABNgIMIAEgAjYCCAwBCwJAIANBFGoiAigCACIEDQAgA0EQaiICKAIAIgQNAEEAIQEMAQsDQCACIQcgBCIBQRRqIgIoAgAiBA0AIAFBEGohAiABKAIQIgQNAAsgB0EANgIACyAGRQ0BAkAgAyADKAIcIgJBAnRBuApqIgQoAgBGBEAgBCABNgIAIAENAUGMCEGMCCgCAEF+IAJ3cTYCAAwDCyAGQRBBFCAGKAIQIANGG2ogATYCACABRQ0CCyABIAY2AhggAygCECICBEAgASACNgIQIAIgATYCGAsgAygCFCICRQ0BIAEgAjYCFCACIAE2AhgMAQsgBSgCBCIBQQNxQQNHDQBBkAggADYCACAFIAFBfnE2AgQgAyAAQQFyNgIEIAAgA2ogADYCAA8LIAMgBU8NACAFKAIEIgFBAXFFDQACQCABQQJxRQRAIAVBoAgoAgBGBEBBoAggAzYCAEGUCEGUCCgCACAAaiIANgIAIAMgAEEBcjYCBCADQZwIKAIARw0DQZAIQQA2AgBBnAhBADYCAA8LIAVBnAgoAgBGBEBBnAggAzYCAEGQCEGQCCgCACAAaiIANgIAIAMgAEEBcjYCBCAAIANqIAA2AgAPCyABQXhxIABqIQACQCABQf8BTQRAIAUoAggiAiABQQN2IgRBA3RBsAhqRhogAiAFKAIMIgFGBEBBiAhBiAgoAgBBfiAEd3E2AgAMAgsgAiABNgIMIAEgAjYCCAwBCyAFKAIYIQYCQCAFIAUoAgwiAUcEQCAFKAIIIgJBmAgoAgBJGiACIAE2AgwgASACNgIIDAELAkAgBUEUaiICKAIAIgQNACAFQRBqIgIoAgAiBA0AQQAhAQwBCwNAIAIhByAEIgFBFGoiAigCACIEDQAgAUEQaiECIAEoAhAiBA0ACyAHQQA2AgALIAZFDQACQCAFIAUoAhwiAkECdEG4CmoiBCgCAEYEQCAEIAE2AgAgAQ0BQYwIQYwIKAIAQX4gAndxNgIADAILIAZBEEEUIAYoAhAgBUYbaiABNgIAIAFFDQELIAEgBjYCGCAFKAIQIgIEQCABIAI2AhAgAiABNgIYCyAFKAIUIgJFDQAgASACNgIUIAIgATYCGAsgAyAAQQFyNgIEIAAgA2ogADYCACADQZwIKAIARw0BQZAIIAA2AgAPCyAFIAFBfnE2AgQgAyAAQQFyNgIEIAAgA2ogADYCAAsgAEH/AU0EQCAAQQN2IgFBA3RBsAhqIQACf0GICCgCACICQQEgAXQiAXFFBEBBiAggASACcjYCACAADAELIAAoAggLIQIgACADNgIIIAIgAzYCDCADIAA2AgwgAyACNgIIDwtBHyECIANCADcCECAAQf///wdNBEAgAEEIdiIBIAFBgP4/akEQdkEIcSIBdCICIAJBgOAfakEQdkEEcSICdCIEIARBgIAPakEQdkECcSIEdEEPdiABIAJyIARyayIBQQF0IAAgAUEVanZBAXFyQRxqIQILIAMgAjYCHCACQQJ0QbgKaiEBAkACQAJAQYwIKAIAIgRBASACdCIHcUUEQEGMCCAEIAdyNgIAIAEgAzYCACADIAE2AhgMAQsgAEEAQRkgAkEBdmsgAkEfRht0IQIgASgCACEBA0AgASIEKAIEQXhxIABGDQIgAkEddiEBIAJBAXQhAiAEIAFBBHFqIgdBEGooAgAiAQ0ACyAHIAM2AhAgAyAENgIYCyADIAM2AgwgAyADNgIIDAELIAQoAggiACADNgIMIAQgAzYCCCADQQA2AhggAyAENgIMIAMgADYCCAtBqAhBqAgoAgBBAWsiAEF/IAAbNgIACwsLCQEAQYEICwIGUA==",!oe.startsWith(Y)){var ee=oe;oe=e.locateFile?e.locateFile(ee,l):l+ee}function Ye(){var K=oe;try{if(K==oe&&S)return new Uint8Array(S);var fe=Ar(K);if(fe)return fe;if(g)return g(K);throw"both async and sync fetching of the wasm failed"}catch(be){M(be)}}function gt(){if(!S&&(a||c)){if(typeof fetch=="function"&&!oe.startsWith("file://"))return fetch(oe,{credentials:"same-origin"}).then(function(K){if(!K.ok)throw"failed to load wasm binary file at '"+oe+"'";return K.arrayBuffer()}).catch(function(){return Ye()});if(h)return new Promise(function(K,fe){h(oe,function(be){K(new Uint8Array(be))},fe)})}return Promise.resolve().then(function(){return Ye()})}function lr(K){for(;0<K.length;){var fe=K.shift();if(typeof fe=="function")fe(e);else{var be=fe.m;typeof be=="number"?fe.l===void 0?ae.get(be)():ae.get(be)(fe.l):be(fe.l===void 0?null:fe.l)}}}var en=!1,tn=typeof atob=="function"?atob:function(K){var fe="",be=0;K=K.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var Re="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(K.charAt(be++)),je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(K.charAt(be++)),It="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(K.charAt(be++)),ur="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(K.charAt(be++));Re=Re<<2|je>>4,je=(je&15)<<4|It>>2;var jt=(It&3)<<6|ur;fe+=String.fromCharCode(Re),It!==64&&(fe+=String.fromCharCode(je)),ur!==64&&(fe+=String.fromCharCode(jt))}while(be<K.length);return fe};function Ar(K){if(K.startsWith(Y)){if(K=K.slice(Y.length),typeof f=="boolean"&&f){var fe=Buffer.from(K,"base64");fe=new Uint8Array(fe.buffer,fe.byteOffset,fe.byteLength)}else try{var be=tn(K),Re=new Uint8Array(be.length);for(K=0;K<be.length;++K)Re[K]=be.charCodeAt(K);fe=Re}catch{throw Error("Converting base64 string to bytes failed.")}return fe}}var rn={a:function(K){var fe=q.length;if(K>>>=0,2147483648<K)return!1;for(var be=1;4>=be;be*=2){var Re=fe*(1+.2/be);Re=Math.min(Re,K+100663296),Re=Math.max(K,Re),0<Re%65536&&(Re+=65536-Re%65536);e:{try{O.grow(Math.min(2147483648,Re)-I.byteLength+65535>>>16),Q();var je=1;break e}catch{}je=void 0}if(je)return!0}return!1}};(function(){function K(je){e.asm=je.exports,O=e.asm.b,Q(),ae=e.asm.j,Z.unshift(e.asm.c),U--,e.monitorRunDependencies&&e.monitorRunDependencies(U),U==0&&(C!==null&&(clearInterval(C),C=null),k&&(je=k,k=null,je()))}function fe(je){K(je.instance)}function be(je){return gt().then(function(It){return WebAssembly.instantiate(It,Re)}).then(je,function(It){x("failed to asynchronously prepare wasm: "+It),M(It)})}var Re={a:rn};if(U++,e.monitorRunDependencies&&e.monitorRunDependencies(U),e.instantiateWasm)try{return e.instantiateWasm(Re,K)}catch(je){return x("Module.instantiateWasm callback failed with error: "+je),!1}return(function(){return S||typeof WebAssembly.instantiateStreaming!="function"||oe.startsWith(Y)||oe.startsWith("file://")||typeof fetch!="function"?be(fe):fetch(oe,{credentials:"same-origin"}).then(function(je){return WebAssembly.instantiateStreaming(je,Re).then(fe,function(It){return x("wasm streaming compile failed: "+It),x("falling back to ArrayBuffer instantiation"),be(fe)})})})().catch(i),{}})(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.c).apply(null,arguments)},e._poly1305_auth=function(){return(e._poly1305_auth=e.asm.d).apply(null,arguments)};var On=e.stackSave=function(){return(On=e.stackSave=e.asm.e).apply(null,arguments)},wi=e.stackRestore=function(){return(wi=e.stackRestore=e.asm.f).apply(null,arguments)},Mn=e.stackAlloc=function(){return(Mn=e.stackAlloc=e.asm.g).apply(null,arguments)};e._malloc=function(){return(e._malloc=e.asm.h).apply(null,arguments)},e._free=function(){return(e._free=e.asm.i).apply(null,arguments)},e.cwrap=function(K,fe,be,Re){be=be||[];var je=be.every(function(It){return It==="number"});return fe!=="string"&&je&&!Re?X(K):function(){return G(K,fe,be,arguments)}};var nn;k=function K(){nn||sn(),nn||(k=K)};function sn(){function K(){if(!nn&&(nn=!0,e.calledRun=!0,!P)){if(lr(Z),n(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var fe=e.postRun.shift();re.unshift(fe)}lr(re)}}if(!(0<U)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)ce();lr(te),0<U||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),K()},1)):K())}}if(e.run=sn,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return sn(),t.ready})})();typeof Vi=="object"&&typeof zs=="object"?zs.exports=js:typeof define=="function"&&define.amd?define([],function(){return js}):typeof Vi=="object"&&(Vi.createPoly1305=js)});var Nr=ot((Ry,gl)=>{"use strict";var{createCipheriv:An,createDecipheriv:Gi,createHmac:Xs,randomFillSync:jr,timingSafeEqual:Js}=require("crypto"),{readUInt32BE:jn,writeUInt32BE:Xt}=or(),Pr=Buffer[Symbol.species],ul=2**32-1,dl=Buffer.alloc(0),mn=Buffer.alloc(4),Yi=new Map,zr=35e3,Zs,go,mo,Ao,Eo,_o,bo;try{Zs=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:go,ChaChaPolyCipher:mo,GenericCipher:Ao,AESGCMDecipher:Eo,ChaChaPolyDecipher:_o,GenericDecipher:bo}=Zs}catch{}var Tt=1,ep=(()=>{function r(t,e,n,i,s,o,a){return{sslName:t,blockLen:e,keyLen:n,ivLen:i!==0||a&Tt?i:e,authLen:s,discardLen:o,stream:!!(a&Tt)}}return{"chacha20-poly1305@openssh.com":r("chacha20",8,64,0,16,0,Tt),"aes128-gcm":r("aes-128-gcm",16,16,12,16,0,Tt),"aes256-gcm":r("aes-256-gcm",16,32,12,16,0,Tt),"aes128-gcm@openssh.com":r("aes-128-gcm",16,16,12,16,0,Tt),"aes256-gcm@openssh.com":r("aes-256-gcm",16,32,12,16,0,Tt),"aes128-cbc":r("aes-128-cbc",16,16,0,0,0,0),"aes192-cbc":r("aes-192-cbc",16,24,0,0,0,0),"aes256-cbc":r("aes-256-cbc",16,32,0,0,0,0),"rijndael-cbc@lysator.liu.se":r("aes-256-cbc",16,32,0,0,0,0),"3des-cbc":r("des-ede3-cbc",8,24,0,0,0,0),"blowfish-cbc":r("bf-cbc",8,16,0,0,0,0),"idea-cbc":r("idea-cbc",8,16,0,0,0,0),"cast128-cbc":r("cast-cbc",8,16,0,0,0,0),"aes128-ctr":r("aes-128-ctr",16,16,16,0,0,Tt),"aes192-ctr":r("aes-192-ctr",16,24,16,0,0,Tt),"aes256-ctr":r("aes-256-ctr",16,32,16,0,0,Tt),"3des-ctr":r("des-ede3",8,24,8,0,0,Tt),"blowfish-ctr":r("bf-ecb",8,16,8,0,0,Tt),"cast128-ctr":r("cast5-ecb",8,16,8,0,0,Tt),arcfour:r("rc4",8,16,0,0,1536,Tt),arcfour128:r("rc4",8,16,0,0,1536,Tt),arcfour256:r("rc4",8,32,0,0,1536,Tt),arcfour512:r("rc4",8,64,0,0,1536,Tt)}})(),tp=(()=>{function r(t,e,n,i){return{sslName:t,len:e,actualLen:n,isETM:i}}return{"hmac-md5":r("md5",16,16,!1),"hmac-md5-96":r("md5",16,12,!1),"hmac-ripemd160":r("ripemd160",20,20,!1),"hmac-sha1":r("sha1",20,20,!1),"hmac-sha1-etm@openssh.com":r("sha1",20,20,!0),"hmac-sha1-96":r("sha1",20,12,!1),"hmac-sha2-256":r("sha256",32,32,!1),"hmac-sha2-256-etm@openssh.com":r("sha256",32,32,!0),"hmac-sha2-256-96":r("sha256",32,12,!1),"hmac-sha2-512":r("sha512",64,64,!1),"hmac-sha2-512-etm@openssh.com":r("sha512",64,64,!0),"hmac-sha2-512-96":r("sha512",64,12,!1)}})(),eo=class{constructor(t,e){this.outSeqno=t,this._onWrite=e,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,n=8-(e&7);n<4&&(n+=8),e+=n;let i=Buffer.allocUnsafe(e);return Xt(i,e-4,0),i[4]=n,jr(i,5+t,n),i}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},hl=Buffer.alloc(32),Kt=Buffer.alloc(16),Yn,zn,yo,to=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encKeyMain=e.cipherKey.slice(0,32),this._encKeyPktLen=e.cipherKey.slice(32),this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,n=8-(e-4&7);n<4&&(n+=8),e+=n;let i=Buffer.allocUnsafe(e);return Xt(i,e-4,0),i[4]=n,jr(i,5+t,n),i}encrypt(t){if(this._dead)return;Kt[0]=0,Xt(Kt,this.outSeqno,12);let e=An("chacha20",this._encKeyMain,Kt).update(hl),n=An("chacha20",this._encKeyPktLen,Kt).update(t.slice(0,4));this._onWrite(n),Kt[0]=1;let i=An("chacha20",this._encKeyMain,Kt).update(t.slice(4));this._onWrite(i),yo(zn,n,n.length,i,i.length,e);let s=Buffer.allocUnsafe(16);s.set(new Uint8Array(Yn.HEAPU8.buffer,zn,16),0),this._onWrite(s),this.outSeqno=this.outSeqno+1>>>0}},ro=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new mo(e.cipherKey),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,n=8-(e-4&7);n<4&&(n+=8),e+=n;let i=Buffer.allocUnsafe(e+16);return Xt(i,e-4,0),i[4]=n,jr(i,5+t,n),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},no=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encSSLName=e.cipherInfo.sslName,this._encKey=e.cipherKey,this._encIV=e.cipherIV,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,n=16-(e-4&15);n<4&&(n+=16),e+=n;let i=Buffer.allocUnsafe(e);return Xt(i,e-4,0),i[4]=n,jr(i,5+t,n),i}encrypt(t){if(this._dead)return;let e=An(this._encSSLName,this._encKey,this._encIV);e.setAutoPadding(!1);let n=t.slice(0,4);e.setAAD(n),this._onWrite(n);let i=e.update(t.slice(4));this._onWrite(i);let s=e.final();s.length&&this._onWrite(s);let o=e.getAuthTag();this._onWrite(o),pl(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},io=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new go(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,n=16-(e-4&15);n<4&&(n+=16),e+=n;let i=Buffer.allocUnsafe(e+16);return Xt(i,e-4,0),i[4]=n,jr(i,5+t,n),i}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},so=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=An(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._aadLen=this._macETM?4:0,this._dead=!1;let n=e.cipherInfo.discardLen;if(n){let i=Yi.get(n);i===void 0&&(i=Buffer.alloc(n),Yi.set(n,i)),this._cipherInstance.update(i)}}free(){this._dead=!0}allocPacket(t){let e=this._encBlockLen,n=5+t,i=e-(n-this._aadLen&e-1);i<4&&(i+=e),n+=i;let s=Buffer.allocUnsafe(n);return Xt(s,n-4,0),s[4]=i,jr(s,5+t,i),s}encrypt(t){if(this._dead)return;let e;if(this._macETM){let i=new Uint8Array(t.buffer,t.byteOffset,4),s=this._cipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+4,t.length-4));this._onWrite(i),this._onWrite(s),e=Xs(this._macSSLName,this._macKey),Xt(mn,this.outSeqno,0),e.update(mn),e.update(i),e.update(s)}else{let i=this._cipherInstance.update(t);this._onWrite(i),e=Xs(this._macSSLName,this._macKey),Xt(mn,this.outSeqno,0),e.update(mn),e.update(t)}let n=e.digest();n.length>this._macActualLen&&(n=n.slice(0,this._macActualLen)),this._onWrite(n),this.outSeqno=this.outSeqno+1>>>0}},oo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._macLen=e.macInfo.len,this._macActualLen=e.macInfo.actualLen,this._aadLen=e.macInfo.isETM?4:0,this._instance=new Ao(e.cipherInfo.sslName,e.cipherKey,e.cipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=this._encBlockLen,n=5+t,i=e-(n-this._aadLen&e-1);i<4&&(i+=e),n+=i;let s=Buffer.allocUnsafe(n+this._macLen);return Xt(s,n-4,0),s[4]=i,jr(s,5+t,i),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new Pr(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},ao=class{constructor(t,e){this.inSeqno=t,this._onPayload=e,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0}free(){}decrypt(t,e,n){for(;e<n;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,n-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len>zr||this._len<8||(4+this._len&7)!==0)throw new Error("Bad packet length");if(e>=n)return}if(this._packetPos<this._len){let s=Math.min(this._len-this._packetPos,n-e),o;if(e!==0||s!==n?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),e+=s,this._packetPos+=s,this._packetPos<this._len)return}let i=this._packet?new Pr(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):dl;this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},co=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decKeyMain=e.decipherKey.slice(0,32),this._decKeyPktLen=e.decipherKey.slice(32),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._calcMac=Buffer.allocUnsafe(16),this._macPos=0}free(){}decrypt(t,e,n){for(;e<n;){if(this._lenPos<4){let a=Math.min(4-this._lenPos,n-e);for(;a--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;Kt[0]=0,Xt(Kt,this.inSeqno,12);let c=Gi("chacha20",this._decKeyPktLen,Kt).update(this._lenBuf);if(this._len=jn(c,0),this._len>zr||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length")}if(this._pktLen<this._len){if(e>=n)return;let a=Math.min(this._len-this._pktLen,n-e),c;if(e!==0||a!==n?c=new Uint8Array(t.buffer,t.byteOffset+e,a):c=t,a===this._len?this._packet=c:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(c,this._pktLen)),e+=a,this._pktLen+=a,this._pktLen<this._len||e>=n)return}{let a=Math.min(16-this._macPos,n-e);if(e!==0||a!==n?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,a),this._macPos):this._mac.set(t,this._macPos),e+=a,this._macPos+=a,this._macPos<16)return}Kt[0]=0,Xt(Kt,this.inSeqno,12);let i=An("chacha20",this._decKeyMain,Kt).update(hl);if(yo(zn,this._lenBuf,4,this._packet,this._packet.length,i),this._calcMac.set(new Uint8Array(Yn.HEAPU8.buffer,zn,16),0),!Js(this._calcMac,this._mac))throw new Error("Invalid MAC");Kt[0]=1;let s=Gi("chacha20",this._decKeyMain,Kt).update(this._packet),o=new Pr(s.buffer,s.byteOffset+1,s.length-s[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let a=this._onPayload(o);if(a!==void 0)return a===!1?e:a}}}},fo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new _o(e.decipherKey),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._macPos=0}free(){this._instance.free()}decrypt(t,e,n){for(;e<n;){if(this._lenPos<4){let s=Math.min(4-this._lenPos,n-e);for(;s--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;if(this._len=this._instance.decryptLen(this._lenBuf,this.inSeqno),this._len>zr||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length");if(e>=n)return}if(this._pktLen<this._len){let s=Math.min(this._len-this._pktLen,n-e),o;if(e!==0||s!==n?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=n)return}{let s=Math.min(16-this._macPos,n-e);if(e!==0||s!==n?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._macPos):this._mac.set(t,this._macPos),e+=s,this._macPos+=s,this._macPos<16)return}this._instance.decrypt(this._packet,this._mac,this.inSeqno);let i=new Pr(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},lo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=null,this._decipherSSLName=e.decipherInfo.sslName,this._decipherKey=e.decipherKey,this._decipherIV=e.decipherIV,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,n){for(;e<n;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,n-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>zr||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=Gi(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(rp(this._len))}if(this._pktLen<this._len){if(e>=n)return;let s=Math.min(this._len-this._pktLen,n-e),o;if(e!==0||s!==n?o=this._decipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+e,s)):o=this._decipherInstance.update(t),o.length&&(s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),this._packetPos+=o.length),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=n)return}{let s=Math.min(16-this._tagPos,n-e);if(e!==0||s!==n?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._tagPos):this._tag.set(t,this._tagPos),e+=s,this._tagPos+=s,this._tagPos<16)return}{this._decipherInstance.setAuthTag(this._tag);let s=this._decipherInstance.final();s.length&&(this._packet?this._packet.set(s,this._packetPos):this._packet=s)}let i=this._packet?new Pr(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):dl;this.inSeqno=this.inSeqno+1>>>0,pl(this._decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tagPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},uo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Eo(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,n){for(;e<n;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,n-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>zr||this._len<16||(this._len&15)!==0)throw new Error(`Bad packet length: ${this._len}`)}if(this._pktLen<this._len){if(e>=n)return;let s=Math.min(this._len-this._pktLen,n-e),o;if(e!==0||s!==n?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=n)return}{let s=Math.min(16-this._tagPos,n-e);if(e!==0||s!==n?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._tagPos):this._tag.set(t,this._tagPos),e+=s,this._tagPos+=s,this._tagPos<16)return}this._instance.decrypt(this._packet,this._len,this._tag);let i=new Pr(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tagPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},ho=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=Gi(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._decipherInstance.setAutoPadding(!1),this._block=Buffer.allocUnsafe(e.macInfo.isETM?4:e.decipherInfo.blockLen),this._blockSize=e.decipherInfo.blockLen,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._macInstance=null;let n=e.decipherInfo.discardLen;if(n){let i=Yi.get(n);i===void 0&&(i=Buffer.alloc(n),Yi.set(n,i)),this._decipherInstance.update(i)}}free(){}decrypt(t,e,n){for(;e<n;){if(this._blockPos<this._block.length){let o=Math.min(this._block.length-this._blockPos,n-e);if(e!==0||o!==n||o<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._blockPos):this._block.set(t,this._blockPos),e+=o,this._blockPos+=o,this._blockPos<this._block.length)return;let a,c;if(this._macETM?this._len=c=jn(this._block,0):(a=this._decipherInstance.update(this._block),this._len=jn(a,0),c=4+this._len-this._blockSize),this._len>zr||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=Xs(this._macSSLName,this._macKey),Xt(mn,this.inSeqno,0),this._macInstance.update(mn),this._macETM?this._macInstance.update(this._block):(this._macInstance.update(new Uint8Array(a.buffer,a.byteOffset,4)),this._pktLen=a.length-4,this._packetPos=this._pktLen,this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(a.buffer,a.byteOffset+4,this._packetPos),0)),e>=n)return}if(this._pktLen<this._len){let o=Math.min(this._len-this._pktLen,n-e),a;e!==0||o!==n?a=new Uint8Array(t.buffer,t.byteOffset+e,o):a=t,this._macETM&&this._macInstance.update(a);let c=this._decipherInstance.update(a);if(c.length&&(o===this._len?this._packet=c:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(c,this._packetPos)),this._packetPos+=c.length),e+=o,this._pktLen+=o,this._pktLen<this._len||e>=n)return}{let o=Math.min(this._macActualLen-this._macPos,n-e);if(e!==0||o!==n?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._macPos):this._mac.set(t,this._macPos),e+=o,this._macPos+=o,this._macPos<this._macActualLen)return}this._macETM||this._macInstance.update(this._packet);let i=this._macInstance.digest();if(this._macActualLen<i.length&&(i=new Uint8Array(i.buffer,i.byteOffset,this._macActualLen)),!np(i,this._mac))throw new Error("Invalid MAC");let s=new Pr(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._macPos=0,this._macInstance=null;{let o=this._onPayload(s);if(o!==void 0)return o===!1?e:o}}}},po=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new bo(e.decipherInfo.sslName,e.decipherKey,e.decipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM,e.macInfo.actualLen),this._block=Buffer.allocUnsafe(e.macInfo.isETM||e.decipherInfo.stream?4:e.decipherInfo.blockLen),this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM}free(){this._instance.free()}decrypt(t,e,n){for(;e<n;){if(this._blockPos<this._block.length){let s=Math.min(this._block.length-this._blockPos,n-e);if(e!==0||s!==n||s<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._blockPos):this._block.set(t,this._blockPos),e+=s,this._blockPos+=s,this._blockPos<this._block.length)return;let o;if(this._macETM?this._len=o=jn(this._block,0):(this._instance.decryptBlock(this._block),this._len=jn(this._block,0),o=4+this._len-this._block.length),this._len>zr||this._len<5||(o&this._block.length-1)!==0)throw new Error("Bad packet length");if(this._macETM||(this._pktLen=this._block.length-4,this._pktLen&&(this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(this._block.buffer,this._block.byteOffset+4,this._pktLen),0))),e>=n)return}if(this._pktLen<this._len){let s=Math.min(this._len-this._pktLen,n-e),o;if(e!==0||s!==n?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=n)return}{let s=Math.min(this._macActualLen-this._macPos,n-e);if(e!==0||s!==n?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._macPos):this._mac.set(t,this._macPos),e+=s,this._macPos+=s,this._macPos<this._macActualLen)return}this._instance.decrypt(this._packet,this.inSeqno,this._block,this._mac);let i=new Pr(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._macPos=0,this._macInstance=null;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}};function pl(r){++r[11]>>>8&&++r[10]>>>8&&++r[9]>>>8&&++r[8]>>>8&&++r[7]>>>8&&++r[6]>>>8&&++r[5]>>>8&&++r[4]>>>8}var rp=(()=>{let r=Buffer.alloc(4);return t=>(r[0]=t>>>24,r[1]=t>>>16,r[2]=t>>>8,r[3]=t,r)})();function np(r,t){return r.length!==t.length?(Js(r,r),!1):Js(r,t)}function ip(r){if(typeof r!="object"||r===null)throw new Error("Invalid config");if(typeof r.outbound!="object"||r.outbound===null)throw new Error("Invalid outbound");let t=r.outbound;if(typeof t.onWrite!="function")throw new Error("Invalid outbound.onWrite");if(typeof t.cipherInfo!="object"||t.cipherInfo===null)throw new Error("Invalid outbound.cipherInfo");if(!Buffer.isBuffer(t.cipherKey)||t.cipherKey.length!==t.cipherInfo.keyLen)throw new Error("Invalid outbound.cipherKey");if(t.cipherInfo.ivLen&&(!Buffer.isBuffer(t.cipherIV)||t.cipherIV.length!==t.cipherInfo.ivLen))throw new Error("Invalid outbound.cipherIV");if(typeof t.seqno!="number"||t.seqno<0||t.seqno>ul)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return go&&!e?new io(r):new no(r);case"chacha20":return mo&&!e?new ro(r):new to(r);default:{if(typeof t.macInfo!="object"||t.macInfo===null)throw new Error("Invalid outbound.macInfo");if(!Buffer.isBuffer(t.macKey)||t.macKey.length!==t.macInfo.len)throw new Error("Invalid outbound.macKey");return Ao&&!e?new oo(r):new so(r)}}}function sp(r){if(typeof r!="object"||r===null)throw new Error("Invalid config");if(typeof r.inbound!="object"||r.inbound===null)throw new Error("Invalid inbound");let t=r.inbound;if(typeof t.onPayload!="function")throw new Error("Invalid inbound.onPayload");if(typeof t.decipherInfo!="object"||t.decipherInfo===null)throw new Error("Invalid inbound.decipherInfo");if(!Buffer.isBuffer(t.decipherKey)||t.decipherKey.length!==t.decipherInfo.keyLen)throw new Error("Invalid inbound.decipherKey");if(t.decipherInfo.ivLen&&(!Buffer.isBuffer(t.decipherIV)||t.decipherIV.length!==t.decipherInfo.ivLen))throw new Error("Invalid inbound.decipherIV");if(typeof t.seqno!="number"||t.seqno<0||t.seqno>ul)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return Eo&&!e?new uo(r):new lo(r);case"chacha20":return _o&&!e?new fo(r):new co(r);default:{if(typeof t.macInfo!="object"||t.macInfo===null)throw new Error("Invalid inbound.macInfo");if(!Buffer.isBuffer(t.macKey)||t.macKey.length!==t.macInfo.len)throw new Error("Invalid inbound.macKey");return bo&&!e?new po(r):new ho(r)}}}gl.exports={CIPHER_INFO:ep,MAC_INFO:tp,bindingAvailable:!!Zs,init:new Promise(async(r,t)=>{try{Yn=await ll()(),zn=Yn._malloc(16),yo=Yn.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}r()}),NullCipher:eo,createCipher:ip,NullDecipher:ao,createDecipher:sp}});var Lr=ot((Ny,Il)=>{"use strict";var{createDecipheriv:So,createECDH:op,createHash:Jn,createHmac:ap,createSign:cp,createVerify:fp,getCiphers:lp,sign:ml,verify:Al}=require("crypto"),up=lp(),{Ber:ke}=Kn(),dp=Ks().pbkdf,{CIPHER_INFO:Zn}=Nr(),{eddsaSupported:wo,SUPPORTED_CIPHER:hp}=xr(),{bufferSlice:Xr,makeBufferParser:pp,readString:Ce,readUInt32BE:Xn,writeUInt32BE:Nt}=or(),Sr=Symbol("Hash Algorithm"),ar=Symbol("Private key PEM"),hr=Symbol("Public key PEM"),Tr=Symbol("Public key SSH"),En=Symbol("Decrypted Key"),xo=Object.create(null);{let r=Object.keys(Zn);for(let t=0;t<r.length;++t){let e=Zn[r[t]].sslName;!e||xo[e]||(xo[e]=Zn[r[t]])}}var ji=pp();function cr(r,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
58
4
  `);return t.length&63&&(e+=`
59
- `),`-----BEGIN ${n} KEY-----
60
- ${e}-----END ${n} KEY-----`}function ti(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return e.set(n,0),e.set(t,n.length),e}function ko(n,t){let e=n.length,r=n._pos||0;for(let i=0;i<t;++i){let s=e-r;if(r>=e||s<4)return!1;let o=Jn(n,r);if(s<4+o)return!1;r+=4+o}return n._pos=r,!0}function ri(n,t){let e=new Be.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.113549.1.1.1"),e.writeNull(),e.endSequence(),e.startSequence(Be.BitString),e.writeByte(0),e.startSequence(),e.writeBuffer(n,Be.Integer),e.writeBuffer(t,Be.Integer),e.endSequence(),e.endSequence(),e.endSequence(),cr("PUBLIC",e.buffer)}function ni(n,t){let e=Buffer.allocUnsafe(15+t.length+4+n.length);Pt(e,7,0),e.utf8Write("ssh-rsa",4,7);let r=11;return Pt(e,t.length,r),e.set(t,r+=4),Pt(e,n.length,r+=t.length),e.set(n,r+4),e}var pl=(()=>{function n(r,i,s,o,a,c,f,u){let h=new Be.Writer;return h.startSequence(),h.writeInt(0,Be.Integer),h.writeBuffer(r,Be.Integer),h.writeBuffer(i,Be.Integer),h.writeBuffer(s,Be.Integer),h.writeBuffer(o,Be.Integer),h.writeBuffer(a,Be.Integer),h.writeBuffer(c,Be.Integer),h.writeBuffer(f,Be.Integer),h.writeBuffer(u,Be.Integer),h.endSequence(),h.buffer}function t(r){return BigInt(`0x${r.hexSlice(0,r.length)}`)}function e(r){let i=r.toString(16);if((i.length&1)!==0)i=`0${i}`;else{let s=i.charCodeAt(0);(s===56||s===57||s>=97&&s<=102)&&(i=`00${i}`)}return Buffer.from(i,"hex")}return function(i,s,o,a,c,f){let u=t(o),h=e(u%(t(c)-1n)),d=e(u%(t(f)-1n));return cr("RSA PRIVATE",n(i,s,o,c,f,h,d,a))}})();function ii(n,t,e,r){let i=new Be.Writer;return i.startSequence(),i.startSequence(),i.writeOID("1.2.840.10040.4.1"),i.startSequence(),i.writeBuffer(n,Be.Integer),i.writeBuffer(t,Be.Integer),i.writeBuffer(e,Be.Integer),i.endSequence(),i.endSequence(),i.startSequence(Be.BitString),i.writeByte(0),i.writeBuffer(r,Be.Integer),i.endSequence(),i.endSequence(),cr("PUBLIC",i.buffer)}function si(n,t,e,r){let i=Buffer.allocUnsafe(15+n.length+4+t.length+4+e.length+4+r.length);Pt(i,7,0),i.utf8Write("ssh-dss",4,7);let s=11;return Pt(i,n.length,s),i.set(n,s+=4),Pt(i,t.length,s+=n.length),i.set(t,s+=4),Pt(i,e.length,s+=t.length),i.set(e,s+=4),Pt(i,r.length,s+=e.length),i.set(r,s+4),i}function gl(n,t,e,r,i){let s=new Be.Writer;return s.startSequence(),s.writeInt(0,Be.Integer),s.writeBuffer(n,Be.Integer),s.writeBuffer(t,Be.Integer),s.writeBuffer(e,Be.Integer),s.writeBuffer(r,Be.Integer),s.writeBuffer(i,Be.Integer),s.endSequence(),cr("DSA PRIVATE",s.buffer)}function ml(n){let t=new Be.Writer;return t.startSequence(),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Be.BitString),t.writeByte(0),t._ensure(n.length),t._buf.set(n,t._offset),t._offset+=n.length,t.endSequence(),t.endSequence(),cr("PUBLIC",t.buffer)}function Al(n){let t=Buffer.allocUnsafe(19+n.length);return Pt(t,11,0),t.utf8Write("ssh-ed25519",4,11),Pt(t,n.length,15),t.set(n,19),t}function og(n){let t=new Be.Writer;return t.startSequence(),t.writeInt(0,Be.Integer),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Be.OctetString),t.writeBuffer(n,Be.OctetString),t.endSequence(),t.endSequence(),cr("PRIVATE",t.buffer)}function Ro(n,t){let e=new Be.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.10045.2.1"),e.writeOID(n),e.endSequence(),e.startSequence(Be.BitString),e.writeByte(0),e._ensure(t.length),e._buf.set(t,e._offset),e._offset+=t.length,e.endSequence(),e.endSequence(),cr("PUBLIC",e.buffer)}function No(n,t){let e;switch(n){case"1.2.840.10045.3.1.7":e="nistp256";break;case"1.3.132.0.34":e="nistp384";break;case"1.3.132.0.35":e="nistp521";break;default:return}let r=Buffer.allocUnsafe(39+t.length);return Pt(r,19,0),r.utf8Write(`ecdsa-sha2-${e}`,4,19),Pt(r,8,23),r.utf8Write(e,27,8),Pt(r,t.length,35),r.set(t,39),r}function ag(n,t,e){let r=new Be.Writer;return r.startSequence(),r.writeInt(1,Be.Integer),r.writeBuffer(e,Be.OctetString),r.startSequence(160),r.writeOID(n),r.endSequence(),r.startSequence(161),r.startSequence(Be.BitString),r.writeByte(0),r._ensure(t.length),r._buf.set(t,r._offset),r._offset+=t.length,r.endSequence(),r.endSequence(),r.endSequence(),cr("EC PRIVATE",r.buffer)}function cg(n,t){let e=Xp(n);return e.setPrivateKey(t),e.getPublicKey()}var oi={sign:typeof hl=="function"?function(t,e){let r=this[ar];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Ir]);try{return hl(e,t,r)}catch(i){return i}}:function(t,e){let r=this[ar];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Ir]);let i=Zp(e);i.update(t);try{return i.sign(r)}catch(s){return s}},verify:typeof dl=="function"?function(t,e,r){let i=this[gr];if(i===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Ir]);try{return dl(r,t,i,e)}catch(s){return s}}:function(t,e,r){let i=this[gr];if(i===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Ir]);let s=eg(r);s.update(t);try{return s.verify(i,e)}catch(o){return o}},isPrivateKey:function(){return this[ar]!==null},getPrivatePEM:function(){return this[ar]},getPublicPEM:function(){return this[gr]},getPublicSSH:function(){return this[Or]},equals:function(t){let e=yl(t);return e instanceof Error?!1:this.type===e.type&&this[ar]===e[ar]&&this[gr]===e[gr]&&this[Or].equals(e[Or])}};function Xi(n,t,e,r,i,s,o){this.type=n,this.comment=t,this[ar]=e,this[gr]=r,this[Or]=i,this[Ir]=s,this[yn]=o}Xi.prototype=oi;{let t=function(e,r,i){let s=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=Jn(e,0),a=Jn(e,4);if(o!==a)return i?new Error("OpenSSH key integrity check failed -- bad passphrase?"):new Error("OpenSSH key integrity check failed");e._pos=8;let c,f;for(c=0;c<r;++c){let h,d,g,_,y=Ie(e,e._pos,!0);if(y===void 0)return new Error("Malformed OpenSSH private key");switch(y){case"ssh-rsa":{let I=Ie(e,e._pos);if(I===void 0)return new Error("Malformed OpenSSH private key");let O=Ie(e,e._pos);if(O===void 0)return new Error("Malformed OpenSSH private key");let $=Ie(e,e._pos);if($===void 0)return new Error("Malformed OpenSSH private key");let L=Ie(e,e._pos);if(L===void 0)return new Error("Malformed OpenSSH private key");let j=Ie(e,e._pos);if(j===void 0)return new Error("Malformed OpenSSH private key");let J=Ie(e,e._pos);if(J===void 0)return new Error("Malformed OpenSSH private key");g=ri(I,O),_=ni(I,O),d=pl(I,O,$,L,j,J),h="sha1";break}case"ssh-dss":{let I=Ie(e,e._pos);if(I===void 0)return new Error("Malformed OpenSSH private key");let O=Ie(e,e._pos);if(O===void 0)return new Error("Malformed OpenSSH private key");let $=Ie(e,e._pos);if($===void 0)return new Error("Malformed OpenSSH private key");let L=Ie(e,e._pos);if(L===void 0)return new Error("Malformed OpenSSH private key");let j=Ie(e,e._pos);if(j===void 0)return new Error("Malformed OpenSSH private key");g=ii(I,O,$,L),_=si(I,O,$,L),d=gl(I,O,$,L,j),h="sha1";break}case"ssh-ed25519":{if(!vo)return new Error(`Unsupported OpenSSH private key type: ${y}`);let I=Ie(e,e._pos);if(I===void 0||I.length!==32)return new Error("Malformed OpenSSH private key");let O=Ie(e,e._pos);if(O===void 0||O.length!==64)return new Error("Malformed OpenSSH private key");g=ml(I),_=Al(I),d=og(en(O,0,32)),h=null;break}case"ecdsa-sha2-nistp256":h="sha256",f="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":h===void 0&&(h="sha384",f="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(h===void 0&&(h="sha512",f="1.3.132.0.35"),!ko(e,1))return new Error("Malformed OpenSSH private key");let I=Ie(e,e._pos);if(I===void 0)return new Error("Malformed OpenSSH private key");let O=Ie(e,e._pos);if(O===void 0)return new Error("Malformed OpenSSH private key");g=Ro(f,I),_=No(f,I),d=ag(f,I,O);break}default:return new Error(`Unsupported OpenSSH private key type: ${y}`)}let x=Ie(e,e._pos,!0);if(x===void 0)return new Error("Malformed OpenSSH private key");s.push(new Xi(y,x,d,g,_,h,i))}let u=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++u%255)return new Error("Malformed OpenSSH private key");return s},n=/^-----BEGIN OPENSSH PRIVATE KEY-----(?:\r\n|\n)([\s\S]+)(?:\r\n|\n)-----END OPENSSH PRIVATE KEY-----$/;Xi.parse=(e,r)=>{let i=n.exec(e);if(i===null)return null;let s,o=Buffer.from(i[1],"base64");if(o.length<31)return new Error("Malformed OpenSSH private key");let a=o.utf8Slice(0,15);if(a!=="openssh-key-v1\0")return new Error(`Unsupported OpenSSH key magic: ${a}`);let c=Ie(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&ig.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let f=Ie(o,o._pos,!0);if(f===void 0)return new Error("Malformed OpenSSH private key");if(f!=="none"){if(c==="none")return new Error("Malformed OpenSSH private key");if(f!=="bcrypt")return new Error(`Unsupported kdf name for OpenSSH key: ${f}`);if(!r)return new Error("Encrypted private OpenSSH key detected, but no passphrase given")}else if(c!=="none")return new Error("Malformed OpenSSH private key");let u,h,d;c!=="none"&&(u=ei[c]);let g=Ie(o,o._pos);if(g===void 0)return new Error("Malformed OpenSSH private key");if(g.length)switch(f){case"none":return new Error("Malformed OpenSSH private key");case"bcrypt":{let y=Ie(g,0);if(y===void 0||g._pos+4>g.length)return new Error("Malformed OpenSSH private key");let x=Jn(g,g._pos),I=Buffer.allocUnsafe(u.keyLen+u.ivLen);if(ng(r,r.length,y,y.length,I,I.length,x)!==0)return new Error("Failed to generate information to decrypt key");h=en(I,0,u.keyLen),d=en(I,u.keyLen,I.length);break}}else if(f!=="none")return new Error("Malformed OpenSSH private key");if(o._pos+3>=o.length)return new Error("Malformed OpenSSH private key");let _=Jn(o,o._pos);if(o._pos+=4,_>0){for(let x=0;x<_;++x){let I=Ie(o,o._pos);if(I===void 0)return new Error("Malformed OpenSSH private key");if(Ie(I,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let y=Ie(o,o._pos);if(y===void 0)return new Error("Malformed OpenSSH private key");if(h!==void 0){if(y.length<u.blockLen||y.length%u.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let x={authTagLength:u.authLen},I=Bo(u.sslName,h,d,x);if(I.setAutoPadding(!1),u.authLen>0){if(o.length-o._pos<u.authLen)return new Error("Malformed OpenSSH private key");I.setAuthTag(en(o,o._pos,o._pos+=u.authLen))}y=ti(I.update(y),I.final())}catch(x){return x}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");s=t(y,_,h!==void 0)}else s=[];return s instanceof Error?s:s[0]}}function Ji(n,t,e,r,i,s,o){this.type=n,this.comment=t,this[ar]=e,this[gr]=r,this[Or]=i,this[Ir]=s,this[yn]=o}Ji.prototype=oi;{let n=/^-----BEGIN (RSA|DSA|EC) PRIVATE KEY-----(?:\r\n|\n)((?:[^:]+:\s*[\S].*(?:\r\n|\n))*)([\s\S]+)(?:\r\n|\n)-----END (RSA|DSA|EC) PRIVATE KEY-----$/;Ji.parse=(t,e)=>{let r=n.exec(t);if(r===null)return null;let i=Buffer.from(r[3],"base64"),s=r[2],o=!1;if(s!==void 0){s=s.split(/\r\n|\n/g);for(let _=0;_<s.length;++_){let y=s[_],x=y.indexOf(":");if(y.slice(0,x)==="DEK-Info"){let I=y.slice(x+2);if(x=I.indexOf(","),x===-1)continue;let O=I.slice(0,x).toLowerCase();if(rg.indexOf(O)===-1)return new Error(`Cipher (${O}) not supported for encrypted OpenSSH private key`);let $=Co[O];if(!$)return new Error(`Cipher (${O}) not supported for encrypted OpenSSH private key`);let L=Buffer.from(I.slice(x+1),"hex");if(L.length!==$.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let j=en(L,0,8),J=Zn("md5").update(e).update(j).digest();for(;J.length<$.keyLen;)J=ti(J,Zn("md5").update(J).update(e).update(j).digest());J.length>$.keyLen&&(J=en(J,0,$.keyLen));try{let z=Bo(O,J,L);z.setAutoPadding(!1),i=ti(z.update(i),z.final()),o=!0}catch(z){return z}}}}let a,c,f,u,h,d,g="Malformed OpenSSH private key";switch(o&&(g+=". Bad passphrase?"),r[1]){case"RSA":a="ssh-rsa",c=cr("RSA PRIVATE",i);try{d=new Be.Reader(i),d.readSequence(),d.readInt();let _=d.readString(Be.Integer,!0);if(_===null)return new Error(g);let y=d.readString(Be.Integer,!0);if(y===null)return new Error(g);f=ri(_,y),u=ni(_,y)}catch{return new Error(g)}h="sha1";break;case"DSA":a="ssh-dss",c=cr("DSA PRIVATE",i);try{d=new Be.Reader(i),d.readSequence(),d.readInt();let _=d.readString(Be.Integer,!0);if(_===null)return new Error(g);let y=d.readString(Be.Integer,!0);if(y===null)return new Error(g);let x=d.readString(Be.Integer,!0);if(x===null)return new Error(g);let I=d.readString(Be.Integer,!0);if(I===null)return new Error(g);f=ii(_,y,x,I),u=si(_,y,x,I)}catch{return new Error(g)}h="sha1";break;case"EC":{let _,y,x;try{d=new Be.Reader(i),d.readSequence(),d.readInt(),y=d.readString(Be.OctetString,!0),d.readByte();let O=d.readLength();if(O!==null){if(d._offset=O,x=d.readOID(),x===null)return new Error(g);switch(x){case"1.2.840.10045.3.1.7":_="prime256v1",a="ecdsa-sha2-nistp256",h="sha256";break;case"1.3.132.0.34":_="secp384r1",a="ecdsa-sha2-nistp384",h="sha384";break;case"1.3.132.0.35":_="secp521r1",a="ecdsa-sha2-nistp521",h="sha512";break;default:return new Error(`Unsupported private key EC OID: ${x}`)}}else return new Error(g)}catch{return new Error(g)}c=cr("EC PRIVATE",i);let I=cg(_,y);f=Ro(x,I),u=No(x,I);break}}return new Ji(a,"",c,f,u,h,o)}}function Zi(n,t,e,r,i,s,o){this.type=n,this.comment=t,this[ar]=e,this[gr]=r,this[Or]=i,this[Ir]=s,this[yn]=o}Zi.prototype=oi;{let n=Buffer.alloc(0),t=Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),e=Buffer.from([0,0,0,0]),r=Buffer.from([0,0,0,1]),i=/^PuTTY-User-Key-File-2: (ssh-(?:rsa|dss))\r?\nEncryption: (aes256-cbc|none)\r?\nComment: ([^\r\n]*)\r?\nPublic-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-MAC: ([^\r\n]+)/;Zi.parse=(s,o)=>{let a=i.exec(s);if(a===null)return null;let c=a[2],f=c!=="none";if(f&&!o)return new Error("Encrypted PPK private key detected, but no passphrase given");let u=Buffer.from(a[5],"base64");if(f){let U=ei[c],W=ti(Zn("sha1").update(e).update(o).digest(),Zn("sha1").update(r).update(o).digest());W.length>U.keyLen&&(W=en(W,0,U.keyLen));try{let Q=Bo(U.sslName,W,t);Q.setAutoPadding(!1),u=ti(Q.update(u),Q.final())}catch(Q){return Q}}let h=a[1],d=a[3],g=Buffer.from(a[4],"base64"),_=a[6],y=h.length,x=c.length,I=Buffer.byteLength(d),O=g.length,$=u.length,L=Buffer.allocUnsafe(4+y+4+x+4+I+4+O+4+$),j=0;if(Pt(L,y,j),L.utf8Write(h,j+=4,y),Pt(L,x,j+=y),L.utf8Write(c,j+=4,x),Pt(L,I,j+=x),L.utf8Write(d,j+=4,I),Pt(L,O,j+=I),L.set(g,j+=4),Pt(L,$,j+=O),L.set(u,j+4),o||(o=n),Jp("sha1",Zn("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(L).digest("hex")!==_)return f?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let z,S,w;switch(g._pos=0,ko(g,1),h){case"ssh-rsa":{let U=Ie(g,g._pos);if(U===void 0)return new Error("Malformed PPK public key");let W=Ie(g,g._pos);if(W===void 0)return new Error("Malformed PPK public key");let Q=Ie(u,0);if(Q===void 0)return new Error("Malformed PPK private key");let oe=Ie(u,u._pos);if(oe===void 0)return new Error("Malformed PPK private key");let te=Ie(u,u._pos);if(te===void 0)return new Error("Malformed PPK private key");let Z=Ie(u,u._pos);if(Z===void 0)return new Error("Malformed PPK private key");z=ri(W,U),S=ni(W,U),w=pl(W,U,Q,Z,oe,te);break}case"ssh-dss":{let U=Ie(g,g._pos);if(U===void 0)return new Error("Malformed PPK public key");let W=Ie(g,g._pos);if(W===void 0)return new Error("Malformed PPK public key");let Q=Ie(g,g._pos);if(Q===void 0)return new Error("Malformed PPK public key");let oe=Ie(g,g._pos);if(oe===void 0)return new Error("Malformed PPK public key");let te=Ie(u,0);if(te===void 0)return new Error("Malformed PPK private key");z=ii(U,W,Q,oe),S=si(U,W,Q,oe),w=gl(U,W,Q,oe,te);break}}return new Zi(h,d,w,z,S,"sha1",f)}}function ts(n,t,e,r,i){this.type=n,this.comment=t,this[ar]=null,this[gr]=e,this[Or]=r,this[Ir]=i,this[yn]=!1}ts.prototype=oi;{let n;vo?n=/^(((?:ssh-(?:rsa|dss|ed25519))|ecdsa-sha2-nistp(?:256|384|521))(?:-cert-v0[01]@openssh.com)?) ([A-Z0-9a-z/+=]+)(?:$|\s+([\S].*)?)$/:n=/^(((?:ssh-(?:rsa|dss))|ecdsa-sha2-nistp(?:256|384|521))(?:-cert-v0[01]@openssh.com)?) ([A-Z0-9a-z/+=]+)(?:$|\s+([\S].*)?)$/,ts.parse=t=>{let e=n.exec(t);if(e===null)return null;let r=e[1],i=e[2],s=Buffer.from(e[3],"base64"),o=e[4]||"",a=Ie(s,s._pos,!0);return a===void 0||a.indexOf(i)!==0?new Error("Malformed OpenSSH public key"):Po(s,i,o,r)}}function es(n,t,e,r,i){this.type=n,this.comment=t,this[ar]=null,this[gr]=e,this[Or]=r,this[Ir]=i,this[yn]=!1}es.prototype=oi;{let n=/^---- BEGIN SSH2 PUBLIC KEY ----(?:\r?\n)((?:.{0,72}\r?\n)+)---- END SSH2 PUBLIC KEY ----$/,t=/^[A-Z0-9a-z/+=\r\n]+$/,e=/^([\x21-\x39\x3B-\x7E]{1,64}): ((?:[^\\]*\\\r?\n)*[^\r\n]+)\r?\n/gm,r=/\\\r?\n/g;es.parse=i=>{let s=n.exec(i);if(s===null)return null;let o=s[1],a=0,c="";for(;s=e.exec(o);){let g=s[1],_=s[2].replace(r,"");if(_.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,g.toLowerCase()==="comment"&&(c=_,c.length>1&&c.charCodeAt(0)===34&&c.charCodeAt(c.length-1)===34&&(c=c.slice(1,-1)))}let f=o.slice(a);if(!t.test(f))return new Error("Malformed RFC4716 public key");f=Buffer.from(f,"base64");let u=Ie(f,0,!0);if(u===void 0)return new Error("Malformed RFC4716 public key");let h=null,d=null;switch(u){case"ssh-rsa":{let g=Ie(f,f._pos);if(g===void 0)return new Error("Malformed RFC4716 public key");let _=Ie(f,f._pos);if(_===void 0)return new Error("Malformed RFC4716 public key");h=ri(_,g),d=ni(_,g);break}case"ssh-dss":{let g=Ie(f,f._pos);if(g===void 0)return new Error("Malformed RFC4716 public key");let _=Ie(f,f._pos);if(_===void 0)return new Error("Malformed RFC4716 public key");let y=Ie(f,f._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");let x=Ie(f,f._pos);if(x===void 0)return new Error("Malformed RFC4716 public key");h=ii(g,_,y,x),d=si(g,_,y,x);break}default:return new Error("Malformed RFC4716 public key")}return new es(u,c,h,d,"sha1")}}function Po(n,t,e,r){if(!El(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let i,s,o=null,a=null;switch(t){case"ssh-rsa":{let c=Ie(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=Ie(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");o=ri(f,c),a=ni(f,c),i="sha1";break}case"ssh-dss":{let c=Ie(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=Ie(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");let u=Ie(n,n._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");let h=Ie(n,n._pos);if(h===void 0)return new Error("Malformed OpenSSH public key");o=ii(c,f,u,h),a=si(c,f,u,h),i="sha1";break}case"ssh-ed25519":{let c=Ie(n,n._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=ml(c),a=Al(c),i=null;break}case"ecdsa-sha2-nistp256":i="sha256",s="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":i===void 0&&(i="sha384",s="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(i===void 0&&(i="sha512",s="1.3.132.0.35"),!ko(n,1))return new Error("Malformed OpenSSH public key");let c=Ie(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=Ro(s,c),a=No(s,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new ts(r,e,o,a,i)}function El(n){switch(n){case"ssh-rsa":case"ssh-dss":case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":return!0;case"ssh-ed25519":if(vo)return!0;default:return!1}}function _l(n){return n?typeof n[yn]=="boolean":!1}function yl(n,t){if(_l(n))return n;let e;if(Buffer.isBuffer(n))e=n,n=n.utf8Slice(0,n.length).trim();else if(typeof n=="string")n=n.trim();else return new Error("Key data must be a Buffer or string");if(t!=null){if(typeof t=="string")t=Buffer.from(t);else if(!Buffer.isBuffer(t))return new Error("Passphrase must be a string or Buffer when supplied")}let r;if((r=Xi.parse(n,t))!==null||(r=Ji.parse(n,t))!==null||(r=Zi.parse(n,t))!==null||(r=ts.parse(n))!==null||(r=es.parse(n))!==null)return r;if(e){zi.init(e,0);let i=zi.readString(!0);i!==void 0&&(n=zi.readRaw(),n!==void 0&&(r=Po(n,i,"",i),r instanceof Error&&(r=null))),zi.clear()}return r||new Error("Unsupported key format")}bl.exports={isParsedKey:_l,isSupportedKeyType:El,parseDERKey:(n,t)=>Po(n,t,"",t),parseKey:yl}});var Ho=ot((Rb,Nl)=>{"use strict";var{Socket:Il}=require("net"),{Duplex:Cl}=require("stream"),{resolve:fg}=require("path"),{readFile:xl}=require("fs"),{execFile:ug,spawn:lg}=require("child_process"),{isParsedKey:Sl,parseKey:ai}=Dr(),{makeBufferParser:hg,readUInt32BE:Do,writeUInt32BE:Gt,writeUInt32LE:wl}=or();function ci(n){let t=!1;return(...e)=>{t||(t=!0,n(...e))}}function dg(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return n.copy(e,0),t.copy(e,n.length),e}function Lo(){}var pg=Buffer.alloc(0),At=hg(),fi=class{getIdentities(t){t(new Error("Missing getIdentities() implementation"))}sign(t,e,r,i){typeof r=="function"&&(i=r),i(new Error("Missing sign() implementation"))}},xn=class extends fi{constructor(t){super(),this.socketPath=t}getStream(t){t=ci(t);let e=new Il;e.on("connect",()=>{t(null,e)}),e.on("close",r).on("end",r).on("error",r),e.connect(this.socketPath);function r(){try{e.destroy()}catch{}t(new Error("Failed to connect to agent"))}}getIdentities(t){t=ci(t),this.getStream((e,r)=>{function i(o){if(r)try{r.destroy()}catch{}o||(o=new Error("Failed to retrieve identities from agent")),t(o)}if(e)return i(e);let s=new Uo(!0);s.on("error",i),s.pipe(r).pipe(s),r.on("close",i).on("end",i).on("error",i),s.getIdentities((o,a)=>{if(o)return i(o);try{r.destroy()}catch{}t(null,a)})})}sign(t,e,r,i){typeof r=="function"?(i=r,r=void 0):(typeof r!="object"||r===null)&&(r=void 0),i=ci(i),this.getStream((s,o)=>{function a(f){if(o)try{o.destroy()}catch{}f||(f=new Error("Failed to sign data with agent")),i(f)}if(s)return a(s);let c=new Uo(!0);c.on("error",a),c.pipe(o).pipe(c),o.on("close",a).on("end",a).on("error",a),c.sign(t,e,r,(f,u)=>{if(f)return a(f);try{o.destroy()}catch{}i(null,u)})})}},Bl=(()=>{let o=fg(__dirname,"..","util/pagent.exe"),a={10:new Error("Invalid pagent.exe arguments"),11:new Error("Pageant is not running"),12:new Error("pagent.exe could not create an mmap"),13:new Error("pagent.exe could not set mode for stdin"),14:new Error("pagent.exe could not set mode for stdout"),15:new Error("pagent.exe did not get expected input payload")};function c(u){u.buffer=null,u.proc&&(u.proc.kill(),u.proc=void 0)}class f extends Cl{constructor(){super(),this.proc=void 0,this.buffer=null}_read(h){}_write(h,d,g){if(this.buffer===null)this.buffer=h;else{let I=Buffer.allocUnsafe(this.buffer.length+h.length);this.buffer.copy(I,0),h.copy(I,this.buffer.length),this.buffer=I}if(this.buffer.length<4)return g();let _=Do(this.buffer,0);if(this.buffer.length-4<_)return g();if(h=this.buffer.slice(0,4+_),this.buffer.length>4+_)return g(new Error("Unexpected multiple agent requests"));this.buffer=null;let y,x=this.proc=lg(o,[h.length]);x.stdout.on("data",I=>{this.push(I)}),x.on("error",I=>{y=I,g(y)}),x.on("close",I=>{if(this.proc=void 0,!y){if(y=a[I])return g(y);g()}}),x.stdin.end(h)}_final(h){c(this),h()}_destroy(h,d){c(this),d()}}return class extends xn{getStream(h){h(null,new f)}}})(),vl=(()=>{let n=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends xn{getStream(e){e=ci(e);let r=this.socketPath,i=!1;xl(r,function s(o,a){if(o){if(i)return e(new Error("Invalid cygwin unix socket path"));ug("cygpath",["-w",r],(J,z,S)=>{if(J||z.length===0)return e(new Error("Invalid cygwin unix socket path"));i=!0,r=z.toString().replace(/[\r\n]/g,""),xl(r,s)});return}let c=n.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let f,u=0,h=!1,d=[],g,_=Buffer.alloc(12),y=parseInt(c[1],10),x=c[2].replace(/-/g,""),I=Buffer.allocUnsafe(16);for(let J=0,z=0;z<32;++J,z+=2)I[J]=parseInt(x.substring(z,z+2),16);for(let J=0;J<16;J+=4)wl(I,Do(I,J),J);j();function O(){u=0,f="secret",g.write(I)}function $(J){if(u+=J.length,f==="secret"){u===16&&(u=0,f="creds",g.write(_));return}if(f==="creds"&&(h||d.push(J),u===12)){if(g.removeListener("connect",O),g.removeListener("data",$),g.removeListener("error",L),g.removeListener("end",L),g.removeListener("close",L),h)return e(null,g);h=!0,_=Buffer.concat(d),wl(_,process.pid,0),g.on("error",()=>{}),g.destroy(),j()}}function L(){e(new Error("Problem negotiating cygwin unix socket security"))}function j(){g=new Il,g.on("connect",O),g.on("data",$),g.on("error",L),g.on("end",L),g.on("close",L),g.connect(y)}})}}})(),gg=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function kl(n){return process.platform==="win32"&&!gg.test(n)?n==="pageant"?new Bl:new vl(n):new xn(n)}var Uo=(()=>{function f(S){let w;for(;S[O].length;){let U=S[O][0][h];if(U===void 0)break;S[O].shift(),w=S.push(U)}return w}let u=Symbol("Inbound Request Type"),h=Symbol("Inbound Request Response"),d=Symbol("Inbound Request Context");class g{constructor(w,U){this[u]=w,this[h]=void 0,this[d]=U}hasResponded(){return this[h]!==void 0}getType(){return this[u]}getContext(){return this[d]}}function _(S,w,U){return w[h]=U,f(S)}function y(S){if(S[L]=null,S[$]===0){let w=S[O];if(w&&w.length){S[O]=[];for(let U of w)U.cb(new Error("No reply from server"))}}try{S.end()}catch{}setImmediate(()=>{S[z]||S.emit("end"),S[J]||S.emit("close")})}function x(){this[J]=!0}function I(){this[z]=!0}let O=Symbol("Requests"),$=Symbol("Agent Protocol Role"),L=Symbol("Agent Protocol Buffer"),j=Symbol("Agent Protocol Current Message Length"),J=Symbol("Agent Protocol Closed"),z=Symbol("Agent Protocol Ended");return class extends Cl{constructor(w){super({autoDestroy:!0,emitClose:!1}),this[$]=w?0:1,this[O]=[],this[L]=null,this[j]=-1,this.once("end",I),this.once("close",x)}_read(w){}_write(w,U,W){this[L]===null?this[L]=w:this[L]=dg(this[L],w);let Q=this[L],oe=Q.length,te=0;for(;te<oe&&!(oe<5||(this[j]===-1&&(this[j]=Do(Q,te)),oe<4+this[j]));){let Z=Q[te+=4];if(++te,this[$]===0){if(this[O].length===0)return W(new Error("Received unexpected message from server"));let re=this[O].shift();switch(Z){case 5:re.cb(new Error("Agent responded with failure"));break;case 12:{if(re.type!==11)return W(new Error("Agent responded with wrong message type"));At.init(Q,te);let ae=At.readUInt32BE();if(ae===void 0)return At.clear(),W(new Error("Malformed agent response"));let T=[];for(let C=0;C<ae;++C){let v=At.readString();if(v===void 0)return At.clear(),W(new Error("Malformed agent response"));let D=At.readString(!0);if(D===void 0)return At.clear(),W(new Error("Malformed agent response"));v=ai(v),!(v instanceof Error)&&(v.comment=v.comment||D,T.push(v))}te=At.pos(),At.clear(),re.cb(null,T);break}case 14:{if(re.type!==13)return W(new Error("Agent responded with wrong message type"));At.init(Q,te);let ae=At.readString();if(te=At.pos(),At.clear(),ae===void 0)return W(new Error("Malformed agent response"));if(At.init(ae,0),At.readString(!0),ae=At.readString(),At.clear(),ae===void 0)return W(new Error("Malformed OpenSSH signature format"));re.cb(null,ae);break}default:return W(new Error("Agent responded with unsupported message type"))}}else switch(Z){case 11:{let re=new g(Z);this[O].push(re),this.emit("identities",re);break}case 13:{At.init(Q,te);let re=At.readString(),ae=At.readString(),T=At.readUInt32BE();if(te=At.pos(),At.clear(),T===void 0){let G=new g(Z);return this[O].push(G),this.failureReply(G)}if(re=ai(re),re instanceof Error){let G=new g(Z);return this[O].push(G),this.failureReply(G)}let C={hash:void 0},v;re.type==="ssh-rsa"&&(T&2?(v="rsa-sha2-256",C.hash="sha256"):T&4&&(v="rsa-sha2-512",C.hash="sha512")),v===void 0&&(v=re.type);let D=new g(Z,v);this[O].push(D),this.emit("sign",D,re,ae,C);break}default:{let re=new g(Z);this[O].push(re),this.failureReply(re)}}if(this[j]=-1,te===oe){this[L]=null;break}else this[L]=Q=Q.slice(te),oe=Q.length,te=0}W()}_destroy(w,U){y(this),U()}_final(w){y(this),w()}sign(w,U,W,Q){if(this[$]!==0)throw new Error("Client-only method called with server role");typeof W=="function"?(Q=W,W=void 0):(typeof W!="object"||W===null)&&(W=void 0);let oe=0;if(w=ai(w),w instanceof Error)throw new Error("Invalid public key argument");if(w.type==="ssh-rsa"&&W)switch(W.hash){case"sha256":oe=2;break;case"sha512":oe=4;break}w=w.getPublicSSH();let te=13,Z=w.length,re=U.length,ae=0,T=Buffer.allocUnsafe(9+Z+4+re+4);return Gt(T,T.length-4,ae),T[ae+=4]=te,Gt(T,Z,++ae),w.copy(T,ae+=4),Gt(T,re,ae+=Z),U.copy(T,ae+=4),Gt(T,oe,ae+=re),typeof Q!="function"&&(Q=Lo),this[O].push({type:te,cb:Q}),this.push(T)}getIdentities(w){if(this[$]!==0)throw new Error("Client-only method called with server role");let U=11,W=0,Q=Buffer.allocUnsafe(5);return Gt(Q,Q.length-4,W),Q[W+=4]=U,typeof w!="function"&&(w=Lo),this[O].push({type:U,cb:w}),this.push(Q)}failureReply(w){if(this[$]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;let U=0,W=Buffer.allocUnsafe(5);return Gt(W,W.length-4,U),W[U+=4]=5,_(this,w,W)}getIdentitiesReply(w,U){if(this[$]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;if(w.getType()!==11)throw new Error("Invalid response to request");if(!Array.isArray(U))throw new Error("Keys argument must be an array");let W=4,Q=[];for(let Z=0;Z<U.length;++Z){let re=U[Z];if(typeof re!="object"||re===null)throw new Error(`Invalid key entry: ${re}`);let ae,T;if(Sl(re))ae=re;else if(Sl(re.pubKey))ae=re.pubKey;else if(typeof re.pubKey!="object"||re.pubKey===null||({pubKey:ae,comment:T}=re.pubKey,ae=ai(ae),ae instanceof Error))continue;T=ae.comment||T,ae=ae.getPublicSSH(),W+=4+ae.length,T&&typeof T=="string"?T=Buffer.from(T):Buffer.isBuffer(T)||(T=pg),W+=4+T.length,Q.push({pubKey:ae,comment:T})}let oe=0,te=Buffer.allocUnsafe(5+W);Gt(te,te.length-4,oe),te[oe+=4]=12,Gt(te,Q.length,++oe),oe+=4;for(let Z=0;Z<Q.length;++Z){let{pubKey:re,comment:ae}=Q[Z];Gt(te,re.length,oe),re.copy(te,oe+=4),Gt(te,ae.length,oe+=re.length),oe+=4,ae.length&&(ae.copy(te,oe),oe+=ae.length)}return _(this,w,te)}signReply(w,U){if(this[$]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;if(w.getType()!==13)throw new Error("Invalid response to request");if(!Buffer.isBuffer(U))throw new Error("Signature argument must be a Buffer");if(U.length===0)throw new Error("Signature argument must be non-empty");let W=0,Q=w.getContext(),oe=Buffer.byteLength(Q),te=Buffer.allocUnsafe(13+oe+4+U.length);return Gt(te,te.length-4,W),te[W+=4]=14,Gt(te,4+oe+4+U.length,++W),Gt(te,oe,W+=4),te.utf8Write(Q,W+=4,oe),Gt(te,U.length,W+=oe),U.copy(te,W+=4),_(this,w,te)}}})(),To=Symbol("Agent"),fr=Symbol("Agent Keys"),Cr=Symbol("Agent Keys Index"),bn=Symbol("Agent Init Callbacks"),Oo=class{constructor(t){if(typeof t=="string")t=kl(t);else if(!Rl(t))throw new Error("Invalid agent argument");this[To]=t,this[fr]=null,this[Cr]=-1,this[bn]=null}init(t){if(typeof t!="function"&&(t=Lo),this[fr]===null)if(this[bn]===null){this[bn]=[t];let e=(...r)=>{process.nextTick(()=>{let i=this[bn];this[bn]=null;for(let s of i)s(...r)})};this[To].getIdentities(ci((r,i)=>{if(r)return e(r);if(!Array.isArray(i))return e(new Error("Agent implementation failed to provide keys"));let s=[];for(let o of i)o=ai(o),!(o instanceof Error)&&s.push(o);this[fr]=s,this[Cr]=-1,e()}))}else this[bn].push(t);else process.nextTick(t)}nextKey(){return this[fr]===null||++this[Cr]>=this[fr].length?!1:this[fr][this[Cr]]}currentKey(){return this[fr]===null||this[Cr]>=this[fr].length?null:this[fr][this[Cr]]}pos(){return this[fr]===null||this[Cr]>=this[fr].length?-1:this[Cr]}reset(){this[Cr]=-1}sign(...t){this[To].sign(...t)}};function Rl(n){return n instanceof fi}Nl.exports={AgentContext:Oo,AgentProtocol:Uo,BaseAgent:fi,createAgent:kl,CygwinAgent:vl,isAgent:Rl,OpenSSHAgent:xn,PageantAgent:Bl}});var qo=ot((Nb,Pl)=>{"use strict";var{kMaxLength:mg}=require("buffer"),{createInflate:Ag,constants:{DEFLATE:Eg,INFLATE:_g,Z_DEFAULT_CHUNK:yg,Z_DEFAULT_COMPRESSION:bg,Z_DEFAULT_MEMLEVEL:xg,Z_DEFAULT_STRATEGY:Sg,Z_DEFAULT_WINDOWBITS:wg,Z_PARTIAL_FLUSH:Ig}}=require("zlib"),Cg=Ag()._handle.constructor;function Bg(){throw new Error("Should not get here")}function vg(n,t,e){let r=this._owner,i=new Error(n);i.errno=t,i.code=e,r._err=i}function Wo(n){n._handle&&(n._handle.close(),n._handle=null)}var rs=class{constructor(t){let e=wg,r=bg,i=xg,s=Sg,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=yg,this._maxOutputLength=mg,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new Cg(t),this._handle._owner=this,this._handle.onerror=vg,this._handle.init(e,r,i,s,this._writeState,Bg,o)}writeSync(t,e){let r=this._handle;if(!r)throw new Error("Invalid Zlib instance");let i=t.length,s=this._chunkSize-this._outOffset,o=0,a,c,f,u=0,h=this._writeState,d=this._outBuffer,g=this._outOffset,_=this._chunkSize;for(;;){if(r.writeSync(Ig,t,o,i,d,g,s),this._err)throw this._err;a=h[0],c=h[1];let x=i-c,I=s-a;if(I>0){let O=g===0&&I===d.length?d:d.slice(g,g+I);if(g+=I,f?f.push===void 0?f=[f,O]:f.push(O):f=O,u+=O.byteLength,u>this._maxOutputLength)throw Wo(this),new Error(`Output length exceeded maximum of ${this._maxOutputLength}`)}else if(I!==0)throw new Error("have should not go down");if((a===0||g>=_)&&(s=_,g=0,d=Buffer.allocUnsafe(_)),a===0)o+=x,i=c;else break}if(this._outBuffer=d,this._outOffset=g,u===0&&(f=Buffer.alloc(0)),e)return f.totalLen=u,f;if(f.push===void 0)return f;let y=Buffer.allocUnsafe(u);for(let x=0,I=0;x<f.length;++x){let O=f[x];y.set(O,I),I+=O.length}return y}},Mo=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new rs(Eg)}cleanup(){this._zlib&&Wo(this._zlib)}alloc(t,e){return Buffer.allocUnsafe(t)}finalize(t,e){if(this._protocol._kexinit===void 0||e){let r=this._zlib.writeSync(t,!0),i=this._protocol._cipher.allocPacket(r.totalLen);if(r.push===void 0)i.set(r,5);else for(let s=0,o=5;s<r.length;++s){let a=r[s];i.set(a,o),o+=a.length}return i}return t}},Fo=class{constructor(t){this.allocStart=5,this.allocStartKEX=5,this._protocol=t}cleanup(){}alloc(t,e){return this._protocol._kexinit===void 0||e?this._protocol._cipher.allocPacket(t):Buffer.allocUnsafe(t)}finalize(t,e){return t}},Qo=class{constructor(){this._zlib=new rs(_g)}cleanup(){this._zlib&&Wo(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},$o=class{cleanup(){}read(t){return t}};Pl.exports={PacketReader:$o,PacketWriter:Fo,ZlibPacketReader:Qo,ZlibPacketWriter:Mo}});var Dl=ot((Pb,Ol)=>{"use strict";var{bufferSlice:Ko,bufferParser:R,doFatalError:ht,sigSSHToASN1:Tl,writeUInt32BE:Ll}=or(),{CHANNEL_OPEN_FAILURE:kg,COMPAT:Rg,MESSAGE:dt,TERMINAL_MODE:Ul}=wr(),{parseKey:Ng}=Dr(),Pg=Array.from(Object.entries(Ul)).reduce((n,[t,e])=>({...n,[t]:e}),{});Ol.exports={[dt.DISCONNECT]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE(),r=R.readString(!0),i=R.readString();if(R.clear(),i===void 0)return ht(n,"Inbound: Malformed DISCONNECT packet");n._debug&&n._debug(`Inbound: Received DISCONNECT (${e}, "${r}")`);let s=n._handlers.DISCONNECT;s&&s(n,e,r)},[dt.IGNORE]:(n,t)=>{n._debug&&n._debug("Inbound: Received IGNORE")},[dt.UNIMPLEMENTED]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ht(n,"Inbound: Malformed UNIMPLEMENTED packet");n._debug&&n._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[dt.DEBUG]:(n,t)=>{R.init(t,1);let e=R.readBool(),r=R.readString(!0),i=R.readString();if(R.clear(),i===void 0)return ht(n,"Inbound: Malformed DEBUG packet");n._debug&&n._debug("Inbound: Received DEBUG");let s=n._handlers.DEBUG;s&&s(n,e,r)},[dt.SERVICE_REQUEST]:(n,t)=>{R.init(t,1);let e=R.readString(!0);if(R.clear(),e===void 0)return ht(n,"Inbound: Malformed SERVICE_REQUEST packet");n._debug&&n._debug(`Inbound: Received SERVICE_REQUEST (${e})`);let r=n._handlers.SERVICE_REQUEST;r&&r(n,e)},[dt.SERVICE_ACCEPT]:(n,t)=>{R.init(t,1);let e=R.readString(!0);if(R.clear(),e===void 0)return ht(n,"Inbound: Malformed SERVICE_ACCEPT packet");n._debug&&n._debug(`Inbound: Received SERVICE_ACCEPT (${e})`);let r=n._handlers.SERVICE_ACCEPT;r&&r(n,e)},[dt.EXT_INFO]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE(),r;if(e!==void 0){r=[];for(let s=0;s<e;++s){let o=R.readString(!0),a=R.readString();if(a!==void 0)if(o==="server-sig-algs"){let c=a.latin1Slice(0,a.length).split(",");r.push({name:o,algs:c});continue}else continue;r=void 0;break}}if(R.clear(),r===void 0)return ht(n,"Inbound: Malformed EXT_INFO packet");n._debug&&n._debug("Inbound: Received EXT_INFO");let i=n._handlers.EXT_INFO;i&&i(n,r)},[dt.USERAUTH_REQUEST]:(n,t)=>{R.init(t,1);let e=R.readString(!0),r=R.readString(!0),i=R.readString(!0),s,o;switch(i){case"none":s=null;break;case"password":{let c=R.readBool();if(c!==void 0&&(s=R.readString(!0),s!==void 0&&c)){let f=R.readString(!0);f!==void 0?s={oldPassword:s,newPassword:f}:s=void 0}break}case"publickey":{let c=R.readBool();if(c!==void 0){let f=R.readString(!0),u=f,h=R.readString(),d;switch(f){case"rsa-sha2-256":u="ssh-rsa",d="sha256";break;case"rsa-sha2-512":u="ssh-rsa",d="sha512";break}if(c){let g=R.pos(),_=R.readString();if(_!==void 0&&(_.length>4+f.length+4&&_.utf8Slice(4,4+f.length)===f&&(_=Ko(_,4+f.length+4)),_=Tl(_,u),_)){let y=n._kex.sessionID,x=Buffer.allocUnsafe(4+y.length+g);Ll(x,y.length,0),x.set(y,4),x.set(new Uint8Array(t.buffer,t.byteOffset,g),4+y.length),s={keyAlgo:u,key:h,signature:_,blob:x,hashAlgo:d}}}else s={keyAlgo:u,key:h,hashAlgo:d},o="publickey -- check"}break}case"hostbased":{let c=R.readString(!0),f=c,u=R.readString(),h=R.readString(!0),d=R.readString(!0),g;switch(c){case"rsa-sha2-256":f="ssh-rsa",g="sha256";break;case"rsa-sha2-512":f="ssh-rsa",g="sha512";break}let _=R.pos(),y=R.readString();if(y!==void 0&&(y.length>4+c.length+4&&y.utf8Slice(4,4+c.length)===c&&(y=Ko(y,4+c.length+4)),y=Tl(y,f),y!==void 0)){let x=n._kex.sessionID,I=Buffer.allocUnsafe(4+x.length+_);Ll(I,x.length,0),I.set(x,4),I.set(new Uint8Array(t.buffer,t.byteOffset,_),4+x.length),s={keyAlgo:f,key:u,signature:y,blob:I,localHostname:h,localUsername:d,hashAlgo:g}}break}case"keyboard-interactive":R.skipString(),s=R.readList();break;default:i!==void 0&&(s=R.readRaw())}if(R.clear(),s===void 0)return ht(n,"Inbound: Malformed USERAUTH_REQUEST packet");o===void 0&&(o=i),n._authsQueue.push(i),n._debug&&n._debug(`Inbound: Received USERAUTH_REQUEST (${o})`);let a=n._handlers.USERAUTH_REQUEST;a&&a(n,e,r,i,s)},[dt.USERAUTH_FAILURE]:(n,t)=>{R.init(t,1);let e=R.readList(),r=R.readBool();if(R.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_FAILURE packet");n._debug&&n._debug(`Inbound: Received USERAUTH_FAILURE (${e})`),n._authsQueue.shift();let i=n._handlers.USERAUTH_FAILURE;i&&i(n,e,r)},[dt.USERAUTH_SUCCESS]:(n,t)=>{n._debug&&n._debug("Inbound: Received USERAUTH_SUCCESS"),n._authsQueue.shift();let e=n._handlers.USERAUTH_SUCCESS;e&&e(n)},[dt.USERAUTH_BANNER]:(n,t)=>{R.init(t,1);let e=R.readString(!0),r=R.readString();if(R.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_BANNER packet");n._debug&&n._debug("Inbound: Received USERAUTH_BANNER");let i=n._handlers.USERAUTH_BANNER;i&&i(n,e)},60:(n,t)=>{if(!n._authsQueue.length){n._debug&&n._debug("Inbound: Received payload type 60 without auth");return}switch(n._authsQueue[0]){case"password":{R.init(t,1);let e=R.readString(!0),r=R.readString();if(R.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_PASSWD_CHANGEREQ packet");n._debug&&n._debug("Inbound: Received USERAUTH_PASSWD_CHANGEREQ");let i=n._handlers.USERAUTH_PASSWD_CHANGEREQ;i&&i(n,e);break}case"publickey":{R.init(t,1);let e=R.readString(!0),r=R.readString();if(R.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_PK_OK packet");n._debug&&n._debug("Inbound: Received USERAUTH_PK_OK"),n._authsQueue.shift();let i=n._handlers.USERAUTH_PK_OK;i&&i(n,e,r);break}case"keyboard-interactive":{R.init(t,1);let e=R.readString(!0),r=R.readString(!0);R.readString();let i=R.readUInt32BE(),s;if(i!==void 0){s=new Array(i);let a;for(a=0;a<i;++a){let c=R.readString(!0),f=R.readBool();if(f===void 0)break;s[a]={prompt:c,echo:f}}a!==i&&(s=void 0)}if(R.clear(),s===void 0)return ht(n,"Inbound: Malformed USERAUTH_INFO_REQUEST packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_REQUEST");let o=n._handlers.USERAUTH_INFO_REQUEST;o&&o(n,e,r,s);break}default:n._debug&&n._debug("Inbound: Received unexpected payload type 60")}},61:(n,t)=>{if(!n._authsQueue.length){n._debug&&n._debug("Inbound: Received payload type 61 without auth");return}if(n._authsQueue[0]!=="keyboard-interactive")return ht(n,"Inbound: Received unexpected payload type 61");R.init(t,1);let e=R.readUInt32BE(),r;if(e!==void 0){r=new Array(e);let s;for(s=0;s<e;++s){let o=R.readString(!0);if(o===void 0)break;r[s]=o}s!==e&&(r=void 0)}if(R.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_INFO_RESPONSE packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_RESPONSE");let i=n._handlers.USERAUTH_INFO_RESPONSE;i&&i(n,r)},[dt.GLOBAL_REQUEST]:(n,t)=>{R.init(t,1);let e=R.readString(!0),r=R.readBool(),i;if(r!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=R.readString(!0),a=R.readUInt32BE();a!==void 0&&(i={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=R.readString(!0);o!==void 0&&(i={socketPath:o});break}case"no-more-sessions@openssh.com":i=null;break;case"hostkeys-00@openssh.com":{for(i=[];R.avail()>0;){let o=R.readString();if(o===void 0){i=void 0;break}let a=Ng(o);a instanceof Error||i.push(a)}break}default:i=R.readRaw()}if(R.clear(),i===void 0)return ht(n,"Inbound: Malformed GLOBAL_REQUEST packet");n._debug&&n._debug(`Inbound: GLOBAL_REQUEST (${e})`);let s=n._handlers.GLOBAL_REQUEST;s?s(n,e,r,i):n.requestFailure()},[dt.REQUEST_SUCCESS]:(n,t)=>{let e=t.length>1?Ko(t,1):null;n._debug&&n._debug("Inbound: REQUEST_SUCCESS");let r=n._handlers.REQUEST_SUCCESS;r&&r(n,e)},[dt.REQUEST_FAILURE]:(n,t)=>{n._debug&&n._debug("Inbound: Received REQUEST_FAILURE");let e=n._handlers.REQUEST_FAILURE;e&&e(n)},[dt.CHANNEL_OPEN]:(n,t)=>{R.init(t,1);let e=R.readString(!0),r=R.readUInt32BE(),i=R.readUInt32BE(),s=R.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=R.readString(!0),f=R.readUInt32BE(),u=R.readString(!0),h=R.readUInt32BE();h!==void 0&&(o={type:e,sender:r,window:i,packetSize:s,data:{destIP:c,destPort:f,srcIP:u,srcPort:h}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=R.readString(!0);c!==void 0&&(o={type:e,sender:r,window:i,packetSize:s,data:{socketPath:c}});break}case"x11":{let c=R.readString(!0),f=R.readUInt32BE();f!==void 0&&(o={type:e,sender:r,window:i,packetSize:s,data:{srcIP:c,srcPort:f}});break}default:o={type:e,sender:r,window:i,packetSize:s,data:{}}}if(R.clear(),o===void 0)return ht(n,"Inbound: Malformed CHANNEL_OPEN packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN (s:${r}, ${e})`);let a=n._handlers.CHANNEL_OPEN;a?a(n,o):n.channelOpenFail(o.sender,kg.ADMINISTRATIVELY_PROHIBITED,"","")},[dt.CHANNEL_OPEN_CONFIRMATION]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE(),r=R.readUInt32BE(),i=R.readUInt32BE(),s=R.readUInt32BE(),o=R.avail()?R.readRaw():void 0;if(R.clear(),s===void 0)return ht(n,"Inbound: Malformed CHANNEL_OPEN_CONFIRMATION packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN_CONFIRMATION (r:${e}, s:${r})`);let a=n._handlers.CHANNEL_OPEN_CONFIRMATION;a&&a(n,{recipient:e,sender:r,window:i,packetSize:s,data:o})},[dt.CHANNEL_OPEN_FAILURE]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE(),r=R.readUInt32BE(),i=R.readString(!0),s=R.readString();if(R.clear(),s===void 0)return ht(n,"Inbound: Malformed CHANNEL_OPEN_FAILURE packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN_FAILURE (r:${e})`);let o=n._handlers.CHANNEL_OPEN_FAILURE;o&&o(n,e,r,i)},[dt.CHANNEL_WINDOW_ADJUST]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE(),r=R.readUInt32BE();if(R.clear(),r===void 0)return ht(n,"Inbound: Malformed CHANNEL_WINDOW_ADJUST packet");n._debug&&n._debug(`Inbound: CHANNEL_WINDOW_ADJUST (r:${e}, ${r})`);let i=n._handlers.CHANNEL_WINDOW_ADJUST;i&&i(n,e,r)},[dt.CHANNEL_DATA]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE(),r=R.readString();if(R.clear(),r===void 0)return ht(n,"Inbound: Malformed CHANNEL_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_DATA (r:${e}, ${r.length})`);let i=n._handlers.CHANNEL_DATA;i&&i(n,e,r)},[dt.CHANNEL_EXTENDED_DATA]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE(),r=R.readUInt32BE(),i=R.readString();if(R.clear(),i===void 0)return ht(n,"Inbound: Malformed CHANNEL_EXTENDED_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_EXTENDED_DATA (r:${e}, ${i.length})`);let s=n._handlers.CHANNEL_EXTENDED_DATA;s&&s(n,e,i,r)},[dt.CHANNEL_EOF]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ht(n,"Inbound: Malformed CHANNEL_EOF packet");n._debug&&n._debug(`Inbound: CHANNEL_EOF (r:${e})`);let r=n._handlers.CHANNEL_EOF;r&&r(n,e)},[dt.CHANNEL_CLOSE]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ht(n,"Inbound: Malformed CHANNEL_CLOSE packet");n._debug&&n._debug(`Inbound: CHANNEL_CLOSE (r:${e})`);let r=n._handlers.CHANNEL_CLOSE;r&&r(n,e)},[dt.CHANNEL_REQUEST]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE(),r=R.readString(!0),i=R.readBool(),s;if(i!==void 0)switch(r){case"exit-status":s=R.readUInt32BE(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"exit-signal":{let a,c;if(n._compatFlags&Rg.OLD_EXIT){let u=R.readUInt32BE();switch(u){case 1:a="HUP";break;case 2:a="INT";break;case 3:a="QUIT";break;case 6:a="ABRT";break;case 9:a="KILL";break;case 14:a="ALRM";break;case 15:a="TERM";break;default:u!==void 0&&(a=`UNKNOWN (${u})`)}c=!1}else a=R.readString(!0),c=R.readBool(),c===void 0&&(a=void 0);let f=R.readString(!0);R.skipString()!==void 0&&(s={signal:a,coreDumped:c,errorMessage:f}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a})`);break}case"pty-req":{let a=R.readString(!0),c=R.readUInt32BE(),f=R.readUInt32BE(),u=R.readUInt32BE(),h=R.readUInt32BE(),d=R.readString();if(d!==void 0){R.init(d,1);let g={};for(;R.avail();){let _=R.readByte();if(_===Ul.TTY_OP_END)break;let y=Pg[_],x=R.readUInt32BE();if(_===void 0||y===void 0||x===void 0){g=void 0;break}g[y]=x}g!==void 0&&(s={term:a,cols:c,rows:f,width:u,height:h,modes:g})}n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"window-change":{let a=R.readUInt32BE(),c=R.readUInt32BE(),f=R.readUInt32BE(),u=R.readUInt32BE();u!==void 0&&(s={cols:a,rows:c,width:f,height:u}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"x11-req":{let a=R.readBool(),c=R.readString(!0),f=R.readString(),u=R.readUInt32BE();u!==void 0&&(s={single:a,protocol:c,cookie:f,screen:u}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"env":{let a=R.readString(!0),c=R.readString(!0);c!==void 0&&(s={name:a,value:c}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a}=${c})`);break}case"shell":s=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;case"exec":s=R.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"subsystem":s=R.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"signal":s=R.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"xon-xoff":s=R.readBool(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"auth-agent-req@openssh.com":s=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;default:s=R.avail()?R.readRaw():null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`)}if(R.clear(),s===void 0)return ht(n,"Inbound: Malformed CHANNEL_REQUEST packet");let o=n._handlers.CHANNEL_REQUEST;o&&o(n,e,r,i,s)},[dt.CHANNEL_SUCCESS]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ht(n,"Inbound: Malformed CHANNEL_SUCCESS packet");n._debug&&n._debug(`Inbound: CHANNEL_SUCCESS (r:${e})`);let r=n._handlers.CHANNEL_SUCCESS;r&&r(n,e)},[dt.CHANNEL_FAILURE]:(n,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ht(n,"Inbound: Malformed CHANNEL_FAILURE packet");n._debug&&n._debug(`Inbound: CHANNEL_FAILURE (r:${e})`);let r=n._handlers.CHANNEL_FAILURE;r&&r(n,e)}}});var ns=ot((Tb,Hl)=>{"use strict";var Go=new Array(256);[is().HANDLERS,Dl()].forEach(n=>{for(let[t,e]of Object.entries(n))t=+t,isFinite(t)&&t>=0&&t<Go.length&&(Go[t]=e)});Hl.exports=Go});var is=ot((Ub,Vl)=>{"use strict";var{createDiffieHellman:Tg,createDiffieHellmanGroup:Lg,createECDH:Ug,createHash:Vo,createPublicKey:Og,diffieHellman:Dg,generateKeyPairSync:Hg,randomFillSync:Mg}=require("crypto"),{Ber:Ml}=Gn(),{COMPAT:jo,curve25519Supported:Fg,DEFAULT_KEX:Fl,DEFAULT_SERVER_HOST_KEY:Ql,DEFAULT_CIPHER:ss,DEFAULT_MAC:os,DEFAULT_COMPRESSION:as,DISCONNECT_REASON:Ge,MESSAGE:ut}=wr(),{CIPHER_INFO:In,createCipher:Qg,createDecipher:$g,MAC_INFO:$l}=Lr(),{parseDERKey:Wg}=Dr(),{bufferFill:qg,bufferParser:Ke,convertSignature:Kg,doFatalError:Ye,FastBuffer:Gg,sigSSHToASN1:Yg,writeUInt32BE:Tt}=or(),{PacketReader:Wl,PacketWriter:ql,ZlibPacketReader:cs,ZlibPacketWriter:fs}=qo(),Sn,Vg=2048,jg=8192,zg=Buffer.alloc(0);function Kl(n){let t;if(n._compatFlags&jo.BAD_DHGEX){let e=n._offer.lists.kex,r=e.array,i=!1;for(let s=0;s<r.length;++s)r[s].includes("group-exchange")&&(i||(i=!0,r=r.slice()),r.splice(s--,1));if(i){let s=17+n._offer.totalSize+1+4,o=Buffer.from(r.join(","));s-=e.buffer.length-o.length;let a=n._offer.lists.all,c=new Uint8Array(a.buffer,a.byteOffset+4+e.buffer.length,a.length-(4+e.buffer.length));t=Buffer.allocUnsafe(s),Tt(t,o.length,17),t.set(o,21),t.set(c,21+o.length)}}t===void 0&&(t=Buffer.allocUnsafe(17+n._offer.totalSize+1+4),n._offer.copyAllTo(t,17)),n._debug&&n._debug("Outbound: Sending KEXINIT"),t[0]=ut.KEXINIT,Mg(t,1,16),qg(t,0,t.length-5),n._kexinit=t,n._packetRW.write.allocStart=0;{let e=n._packetRW.write.allocStartKEX,r=n._packetRW.write.alloc(t.length,!0);r.set(t,e),n._cipher.encrypt(n._packetRW.write.finalize(r,!0))}}function Gl(n,t){let e={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0}};if(Ke.init(t,17),(e.kex=Ke.readList())===void 0||(e.serverHostKey=Ke.readList())===void 0||(e.cs.cipher=Ke.readList())===void 0||(e.sc.cipher=Ke.readList())===void 0||(e.cs.mac=Ke.readList())===void 0||(e.sc.mac=Ke.readList())===void 0||(e.cs.compress=Ke.readList())===void 0||(e.sc.compress=Ke.readList())===void 0||(e.cs.lang=Ke.readList())===void 0||(e.sc.lang=Ke.readList())===void 0)return Ke.clear(),Ye(n,"Received malformed KEXINIT","handshake",Ge.KEY_EXCHANGE_FAILED);let r=Ke.pos(),i=r<t.length&&t[r]===1;Ke.clear();let s=n._offer,o=e,a=s.lists.kex.array;if(n._compatFlags&jo.BAD_DHGEX){let L=!1;for(let j=0;j<a.length;++j)a[j].indexOf("group-exchange")!==-1&&(L||(L=!0,a=a.slice()),a.splice(j--,1))}let c,f,u,h=n._debug;h&&h("Inbound: Handshake in progress"),h&&h(`Handshake: (local) KEX method: ${a}`),h&&h(`Handshake: (remote) KEX method: ${o.kex}`);let d;if(n._server?(f=a,c=o.kex,d=c.indexOf("ext-info-c")!==-1):(f=o.kex,c=a,d=f.indexOf("ext-info-s")!==-1),n._strictMode===void 0&&(n._server?n._strictMode=c.indexOf("kex-strict-c-v00@openssh.com")!==-1:n._strictMode=f.indexOf("kex-strict-s-v00@openssh.com")!==-1,n._strictMode&&(h&&h("Handshake: strict KEX mode enabled"),n._decipher.inSeqno!==1)))return h&&h("Handshake: KEXINIT not first packet in strict KEX mode"),Ye(n,"Handshake failed: KEXINIT not first packet in strict KEX mode","handshake",Ge.KEY_EXCHANGE_FAILED);for(u=0;u<c.length&&f.indexOf(c[u])===-1;++u);if(u===c.length)return h&&h("Handshake: no matching key exchange algorithm"),Ye(n,"Handshake failed: no matching key exchange algorithm","handshake",Ge.KEY_EXCHANGE_FAILED);e.kex=c[u],h&&h(`Handshake: KEX algorithm: ${c[u]}`),i&&(!o.kex.length||c[u]!==o.kex[0])&&(n._skipNextInboundPacket=!0);let g=s.lists.serverHostKey.array;for(h&&h(`Handshake: (local) Host key format: ${g}`),h&&h(`Handshake: (remote) Host key format: ${o.serverHostKey}`),n._server?(f=g,c=o.serverHostKey):(f=o.serverHostKey,c=g),u=0;u<c.length&&f.indexOf(c[u])===-1;++u);if(u===c.length)return h&&h("Handshake: No matching host key format"),Ye(n,"Handshake failed: no matching host key format","handshake",Ge.KEY_EXCHANGE_FAILED);e.serverHostKey=c[u],h&&h(`Handshake: Host key format: ${c[u]}`);let _=s.lists.cs.cipher.array;for(h&&h(`Handshake: (local) C->S cipher: ${_}`),h&&h(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),n._server?(f=_,c=o.cs.cipher):(f=o.cs.cipher,c=_),u=0;u<c.length&&f.indexOf(c[u])===-1;++u);if(u===c.length)return h&&h("Handshake: No matching C->S cipher"),Ye(n,"Handshake failed: no matching C->S cipher","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.cipher=c[u],h&&h(`Handshake: C->S Cipher: ${c[u]}`);let y=s.lists.sc.cipher.array;for(h&&h(`Handshake: (local) S->C cipher: ${y}`),h&&h(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),n._server?(f=y,c=o.sc.cipher):(f=o.sc.cipher,c=y),u=0;u<c.length&&f.indexOf(c[u])===-1;++u);if(u===c.length)return h&&h("Handshake: No matching S->C cipher"),Ye(n,"Handshake failed: no matching S->C cipher","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.cipher=c[u],h&&h(`Handshake: S->C cipher: ${c[u]}`);let x=s.lists.cs.mac.array;if(h&&h(`Handshake: (local) C->S MAC: ${x}`),h&&h(`Handshake: (remote) C->S MAC: ${o.cs.mac}`),In[e.cs.cipher].authLen>0)e.cs.mac="",h&&h("Handshake: C->S MAC: <implicit>");else{for(n._server?(f=x,c=o.cs.mac):(f=o.cs.mac,c=x),u=0;u<c.length&&f.indexOf(c[u])===-1;++u);if(u===c.length)return h&&h("Handshake: No matching C->S MAC"),Ye(n,"Handshake failed: no matching C->S MAC","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.mac=c[u],h&&h(`Handshake: C->S MAC: ${c[u]}`)}let I=s.lists.sc.mac.array;if(h&&h(`Handshake: (local) S->C MAC: ${I}`),h&&h(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),In[e.sc.cipher].authLen>0)e.sc.mac="",h&&h("Handshake: S->C MAC: <implicit>");else{for(n._server?(f=I,c=o.sc.mac):(f=o.sc.mac,c=I),u=0;u<c.length&&f.indexOf(c[u])===-1;++u);if(u===c.length)return h&&h("Handshake: No matching S->C MAC"),Ye(n,"Handshake failed: no matching S->C MAC","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.mac=c[u],h&&h(`Handshake: S->C MAC: ${c[u]}`)}let O=s.lists.cs.compress.array;for(h&&h(`Handshake: (local) C->S compression: ${O}`),h&&h(`Handshake: (remote) C->S compression: ${o.cs.compress}`),n._server?(f=O,c=o.cs.compress):(f=o.cs.compress,c=O),u=0;u<c.length&&f.indexOf(c[u])===-1;++u);if(u===c.length)return h&&h("Handshake: No matching C->S compression"),Ye(n,"Handshake failed: no matching C->S compression","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.compress=c[u],h&&h(`Handshake: C->S compression: ${c[u]}`);let $=s.lists.sc.compress.array;for(h&&h(`Handshake: (local) S->C compression: ${$}`),h&&h(`Handshake: (remote) S->C compression: ${o.sc.compress}`),n._server?(f=$,c=o.sc.compress):(f=o.sc.compress,c=$),u=0;u<c.length&&f.indexOf(c[u])===-1;++u);if(u===c.length)return h&&h("Handshake: No matching S->C compression"),Ye(n,"Handshake failed: no matching S->C compression","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.compress=c[u],h&&h(`Handshake: S->C compression: ${c[u]}`),e.cs.lang="",e.sc.lang="",n._kex&&(n._kexinit||Kl(n),n._decipher._onPayload=Yl.bind(n,{firstPacket:!1})),n._kex=Xg(e,n,t),n._kex.remoteExtInfoEnabled=d,n._kex.start()}var Xg=(()=>{function n(o){let a=0,c=o.length;for(;o[a]===0;)++a,--c;let f;return o[a]&128?(f=Buffer.allocUnsafe(1+c),f[0]=0,o.copy(f,1,a),o=f):c!==o.length&&(f=Buffer.allocUnsafe(c),o.copy(f,0,a),o=f),o}class t{constructor(a,c,f){this._protocol=c,this.sessionID=c._kex?c._kex.sessionID:void 0,this.negotiated=a,this.remoteExtInfoEnabled=!1,this._step=1,this._public=null,this._dh=null,this._sentNEWKEYS=!1,this._receivedNEWKEYS=!1,this._finished=!1,this._hostVerified=!1,this._kexinit=c._kexinit,this._remoteKexinit=f,this._identRaw=c._identRaw,this._remoteIdentRaw=c._remoteIdentRaw,this._hostKey=void 0,this._dhData=void 0,this._sig=void 0}finish(a){if(this._finished)return!1;this._finished=!0;let c=this._protocol._server,f=this.negotiated,u=this.convertPublicKey(this._dhData),h=this.computeSecret(this._dhData);if(h instanceof Error)return h.message=`Error while computing DH secret (${this.type}): ${h.message}`,h.level="handshake",Ye(this._protocol,h,Ge.KEY_EXCHANGE_FAILED);let d=Vo(this.hashName);mr(d,c?this._remoteIdentRaw:this._identRaw),mr(d,c?this._identRaw:this._remoteIdentRaw),mr(d,c?this._remoteKexinit:this._kexinit),mr(d,c?this._kexinit:this._remoteKexinit);let g=c?this._hostKey.getPublicSSH():this._hostKey;if(mr(d,g),this.type==="groupex"){let $=this.getDHParams(),L=Buffer.allocUnsafe(4);Tt(L,this._minBits,0),d.update(L),Tt(L,this._prefBits,0),d.update(L),Tt(L,this._maxBits,0),d.update(L),mr(d,$.prime),mr(d,$.generator)}mr(d,c?u:this.getPublicKey());let _=c?this.getPublicKey():u;mr(d,_),mr(d,h);let y=d.digest();if(c){let $;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":$="sha256";break;case"rsa-sha2-512":$="sha512";break}this._protocol._debug&&this._protocol._debug("Generating signature ...");let L=this._hostKey.sign(y,$);if(L instanceof Error)return Ye(this._protocol,`Handshake failed: signature generation failed for ${this._hostKey.type} host key: ${L.message}`,"handshake",Ge.KEY_EXCHANGE_FAILED);if(L=Kg(L,this._hostKey.type),L===!1)return Ye(this._protocol,`Handshake failed: signature conversion failed for ${this._hostKey.type} host key`,"handshake",Ge.KEY_EXCHANGE_FAILED);let j=this.negotiated.serverHostKey,J=Buffer.byteLength(j),z=4+J+4+L.length,S=this._protocol._packetRW.write.allocStartKEX,w=this._protocol._packetRW.write.alloc(5+g.length+4+_.length+4+z,!0);if(w[S]=ut.KEXDH_REPLY,Tt(w,g.length,++S),w.set(g,S+=4),Tt(w,_.length,S+=g.length),w.set(_,S+=4),Tt(w,z,S+=_.length),Tt(w,J,S+=4),w.utf8Write(j,S+=4,J),Tt(w,L.length,S+=J),w.set(L,S+=4),this._protocol._debug){let U;switch(this.type){case"group":U="KEXDH_REPLY";break;case"groupex":U="KEXDH_GEX_REPLY";break;default:U="KEXECDH_REPLY"}this._protocol._debug(`Outbound: Sending ${U}`)}this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(w,!0))}else{Ke.init(this._sig,0);let $=Ke.readString(!0);if(!$)return Ye(this._protocol,"Malformed packet while reading signature","handshake",Ge.KEY_EXCHANGE_FAILED);if($!==f.serverHostKey)return Ye(this._protocol,`Wrong signature type: ${$}, expected: ${f.serverHostKey}`,"handshake",Ge.KEY_EXCHANGE_FAILED);let L=Ke.readString();if(Ke.clear(),L===void 0)return Ye(this._protocol,"Malformed packet while reading signature","handshake",Ge.KEY_EXCHANGE_FAILED);if(!(L=Yg(L,$)))return Ye(this._protocol,"Malformed signature","handshake",Ge.KEY_EXCHANGE_FAILED);let j;{Ke.init(this._hostKey,0);let S=Ke.readString(!0),w=this._hostKey.slice(Ke.pos());if(Ke.clear(),j=Wg(w,S),j instanceof Error)return j.level="handshake",Ye(this._protocol,j,Ge.KEY_EXCHANGE_FAILED)}let J;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":J="sha256";break;case"rsa-sha2-512":J="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let z=j.verify(y,L,J);if(z!==!0)return z instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${z.stack}`):this._protocol._debug&&this._protocol._debug("Signature verification failed"),Ye(this._protocol,"Handshake failed: signature verification failed","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Verified signature")}(c||!a)&&us(this);let x,I,O=$=>{if(x)return us(this),x.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=Qg(x),this._protocol._packetRW.write=I,x=void 0,I=void 0,this._protocol._onHandshakeComplete(f),!1;this.sessionID||(this.sessionID=y);{let re=Buffer.allocUnsafe(4+h.length);Tt(re,h.length,0),re.set(h,4),h=re}let L=In[f.cs.cipher],j=In[f.sc.cipher],J=wn(L.ivLen,this.hashName,h,y,this.sessionID,"A"),z=wn(j.ivLen,this.hashName,h,y,this.sessionID,"B"),S=wn(L.keyLen,this.hashName,h,y,this.sessionID,"C"),w=wn(j.keyLen,this.hashName,h,y,this.sessionID,"D"),U,W;L.authLen||(U=$l[f.cs.mac],W=wn(U.len,this.hashName,h,y,this.sessionID,"E"));let Q,oe;j.authLen||(Q=$l[f.sc.mac],oe=wn(Q.len,this.hashName,h,y,this.sessionID,"F"));let te={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?L:j,decipherIV:c?J:z,decipherKey:c?S:w,macInfo:c?U:Q,macKey:c?W:oe},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?j:L,cipherIV:c?z:J,cipherKey:c?w:S,macInfo:c?Q:U,macKey:c?oe:W}};this._protocol._decipher.free(),x=te,this._protocol._decipher=$g(te);let Z={read:void 0,write:void 0};switch(f.cs.compress){case"zlib":c?Z.read=new cs:Z.write=new fs(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Z.read=new cs:Z.write=new fs(this._protocol);break}default:c?Z.read=new Wl:Z.write=new ql(this._protocol)}switch(f.sc.compress){case"zlib":c?Z.write=new fs(this._protocol):Z.read=new cs;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Z.write=new fs(this._protocol):Z.read=new cs;break}default:c?Z.write=new ql(this._protocol):Z.read=new Wl}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=Z.read,I=Z.write,this._public=null,this._dh=null,this._kexinit=this._protocol._kexinit=void 0,this._remoteKexinit=void 0,this._identRaw=void 0,this._remoteIdentRaw=void 0,this._hostKey=void 0,this._dhData=void 0,this._sig=void 0,$?!1:O()};if((c||a)&&(this.finish=O),!c)return O(a)}start(){if(!this._protocol._server){if(this._protocol._debug){let u;this.type==="group"?u="KEXDH_INIT":u="KEXECDH_INIT",this._protocol._debug(`Outbound: Sending ${u}`)}let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,f=this._protocol._packetRW.write.alloc(5+a.length,!0);f[c]=ut.KEXDH_INIT,Tt(f,a.length,++c),f.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(f,!0))}}getPublicKey(){this.generateKeys();let a=this._public;if(a)return this.convertPublicKey(a)}convertPublicKey(a){let c,f=0,u=a.length;for(;a[f]===0;)++f,--u;return a[f]&128?(c=Buffer.allocUnsafe(1+u),c[0]=0,a.copy(c,1,f),c):(u!==a.length&&(c=Buffer.allocUnsafe(u),a.copy(c,0,f),a=c),a)}computeSecret(a){this.generateKeys();try{return n(this._dh.computeSecret(a))}catch(c){return c}}parse(a){let c=a[0];switch(this._step){case 1:if(this._protocol._server){if(c!==ut.KEXDH_INIT)return Ye(this._protocol,`Received packet ${c} instead of ${ut.KEXDH_INIT}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Init"),Ke.init(a,1);let f=Ke.readString();if(Ke.clear(),f===void 0)return Ye(this._protocol,"Received malformed KEX*_INIT","handshake",Ge.KEY_EXCHANGE_FAILED);this._dhData=f;let u=this._protocol._hostKeys[this.negotiated.serverHostKey];Array.isArray(u)&&(u=u[0]),this._hostKey=u,this.finish()}else{if(c!==ut.KEXDH_REPLY)return Ye(this._protocol,`Received packet ${c} instead of ${ut.KEXDH_REPLY}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ke.init(a,1);let f,u,h;if((f=Ke.readString())===void 0||(u=Ke.readString())===void 0||(h=Ke.readString())===void 0)return Ke.clear(),Ye(this._protocol,"Received malformed KEX*_REPLY","handshake",Ge.KEY_EXCHANGE_FAILED);Ke.clear(),Ke.init(f,0);let d=Ke.readString(!0);if(Ke.clear(),d===void 0)return Ye(this._protocol,"Received malformed host public key","handshake",Ge.KEY_EXCHANGE_FAILED);if(d!==this.negotiated.serverHostKey)switch(this.negotiated.serverHostKey){case"rsa-sha2-256":case"rsa-sha2-512":if(d==="ssh-rsa")break;default:return Ye(this._protocol,"Host key does not match negotiated type","handshake",Ge.KEY_EXCHANGE_FAILED)}this._hostKey=f,this._dhData=u,this._sig=h;let g=!1,_;if(this._protocol._hostVerifier===void 0?(_=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):_=this._protocol._hostVerifier(f,y=>{if(!g){if(g=!0,y===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ye(this._protocol,"Host denied (verification failed)","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,this._receivedNEWKEYS?this.finish():us(this)}}),_===void 0){++this._step;return}if(g=!0,_===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ye(this._protocol,"Host denied (verification failed)","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,us(this)}++this._step;break;case 2:return c!==ut.NEWKEYS?Ye(this._protocol,`Received packet ${c} instead of ${ut.NEWKEYS}`,"handshake",Ge.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Inbound: NEWKEYS"),this._receivedNEWKEYS=!0,this._protocol._strictMode&&(this._protocol._decipher.inSeqno=0),++this._step,this.finish(!this._protocol._server&&!this._hostVerified));default:return Ye(this._protocol,`Received unexpected packet ${c} after NEWKEYS`,"handshake",Ge.KEY_EXCHANGE_FAILED)}}}class e extends t{constructor(a,...c){super(...c),this.type="25519",this.hashName=a,this._keys=null}generateKeys(){this._keys||(this._keys=Hg("x25519"))}getPublicKey(){return this.generateKeys(),this._keys.publicKey.export({type:"spki",format:"der"}).slice(-32)}convertPublicKey(a){let c,f=0,u=a.length;for(;a[f]===0;)++f,--u;return a.length===32||u!==a.length&&(c=Buffer.allocUnsafe(u),a.copy(c,0,f),a=c),a}computeSecret(a){this.generateKeys();try{let c=new Ml.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(Ml.BitString),c.writeByte(0),c._ensure(a.length),a.copy(c._buf,c._offset,0,a.length),c._offset+=a.length,c.endSequence(),c.endSequence(),n(Dg({privateKey:this._keys.privateKey,publicKey:Og({key:c.buffer,type:"spki",format:"der"})}))}catch(c){return c}}}class r extends t{constructor(a,c,...f){super(...f),this.type="ecdh",this.curveName=a,this.hashName=c}generateKeys(){this._dh||(this._dh=Ug(this.curveName),this._public=this._dh.generateKeys())}}class i extends t{constructor(a,...c){super(...c),this.type="groupex",this.hashName=a,this._prime=null,this._generator=null,this._minBits=Vg,this._prefBits=Jg(this.negotiated),this._protocol._compatFlags&jo.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=jg}start(){if(this._protocol._server)return;this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_REQUEST");let a=this._protocol._packetRW.write.allocStartKEX,c=this._protocol._packetRW.write.alloc(13,!0);c[a]=ut.KEXDH_GEX_REQUEST,Tt(c,this._minBits,++a),Tt(c,this._prefBits,a+=4),Tt(c,this._maxBits,a+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(c,!0))}generateKeys(){!this._dh&&this._prime&&this._generator&&(this._dh=Tg(this._prime,this._generator),this._public=this._dh.generateKeys())}setDHParams(a,c){if(!Buffer.isBuffer(a))throw new Error("Invalid prime value");if(!Buffer.isBuffer(c))throw new Error("Invalid generator value");this._prime=a,this._generator=c}getDHParams(){if(this._dh)return{prime:n(this._dh.getPrime()),generator:n(this._dh.getGenerator())}}parse(a){let c=a[0];switch(this._step){case 1:{if(this._protocol._server)return c!==ut.KEXDH_GEX_REQUEST?Ye(this._protocol,`Received packet ${c} instead of `+ut.KEXDH_GEX_REQUEST,"handshake",Ge.KEY_EXCHANGE_FAILED):Ye(this._protocol,"Group exchange not implemented for server","handshake",Ge.KEY_EXCHANGE_FAILED);if(c!==ut.KEXDH_GEX_GROUP)return Ye(this._protocol,`Received packet ${c} instead of ${ut.KEXDH_GEX_GROUP}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ke.init(a,1);let f,u;if((f=Ke.readString())===void 0||(u=Ke.readString())===void 0)return Ke.clear(),Ye(this._protocol,"Received malformed KEXDH_GEX_GROUP","handshake",Ge.KEY_EXCHANGE_FAILED);Ke.clear(),this.setDHParams(f,u),this.generateKeys();let h=this.getPublicKey();this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_INIT");let d=this._protocol._packetRW.write.allocStartKEX,g=this._protocol._packetRW.write.alloc(5+h.length,!0);g[d]=ut.KEXDH_GEX_INIT,Tt(g,h.length,++d),g.set(h,d+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(g,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==ut.KEXDH_GEX_INIT?Ye(this._protocol,`Received packet ${c} instead of ${ut.KEXDH_GEX_INIT}`,"handshake",Ge.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Received DH GEX Init"),Ye(this._protocol,"Group exchange not implemented for server","handshake",Ge.KEY_EXCHANGE_FAILED));if(c!==ut.KEXDH_GEX_REPLY)return Ye(this._protocol,`Received packet ${c} instead of ${ut.KEXDH_GEX_REPLY}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=ut.KEXDH_REPLY,this.parse=t.prototype.parse,this.parse(a)}}}class s extends t{constructor(a,c,...f){super(...f),this.type="group",this.groupName=a,this.hashName=c}start(){if(!this._protocol._server){this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_INIT");let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,f=this._protocol._packetRW.write.alloc(5+a.length,!0);f[c]=ut.KEXDH_INIT,Tt(f,a.length,++c),f.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(f,!0))}}generateKeys(){this._dh||(this._dh=Lg(this.groupName),this._public=this._dh.generateKeys())}getDHParams(){if(this._dh)return{prime:n(this._dh.getPrime()),generator:n(this._dh.getGenerator())}}}return(o,...a)=>{if(typeof o!="object"||o===null)throw new Error("Invalid negotiated argument");let c=o.kex;if(typeof c=="string"){switch(a=[o,...a],c){case"curve25519-sha256":case"curve25519-sha256@libssh.org":if(!Fg)break;return new e("sha256",...a);case"ecdh-sha2-nistp256":return new r("prime256v1","sha256",...a);case"ecdh-sha2-nistp384":return new r("secp384r1","sha384",...a);case"ecdh-sha2-nistp521":return new r("secp521r1","sha512",...a);case"diffie-hellman-group1-sha1":return new s("modp2","sha1",...a);case"diffie-hellman-group14-sha1":return new s("modp14","sha1",...a);case"diffie-hellman-group14-sha256":return new s("modp14","sha256",...a);case"diffie-hellman-group15-sha512":return new s("modp15","sha512",...a);case"diffie-hellman-group16-sha512":return new s("modp16","sha512",...a);case"diffie-hellman-group17-sha512":return new s("modp17","sha512",...a);case"diffie-hellman-group18-sha512":return new s("modp18","sha512",...a);case"diffie-hellman-group-exchange-sha1":return new i("sha1",...a);case"diffie-hellman-group-exchange-sha256":return new i("sha256",...a)}throw new Error(`Unsupported key exchange algorithm: ${c}`)}throw new Error(`Invalid key exchange type: ${c}`)}})(),Yo=(()=>{let n=["kex","serverHostKey",["cs","cipher"],["sc","cipher"],["cs","mac"],["sc","mac"],["cs","compress"],["sc","compress"],["cs","lang"],["sc","lang"]];return class{constructor(e){if(typeof e!="object"||e===null)throw new TypeError("Argument must be an object");let r={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},all:void 0},i=0;for(let a of n){let c,f,u,h;if(typeof a=="string")c=r,f=e[a],u=h=a;else{let g=a[0];c=r[g],h=a[1],f=e[g][h],u=`${g}.${h}`}let d={array:void 0,buffer:void 0};if(Buffer.isBuffer(f))d.array=(""+f).split(","),d.buffer=f,i+=4+f.length;else{if(typeof f=="string"&&(f=f.split(",")),Array.isArray(f))d.array=f,d.buffer=Buffer.from(f.join(","));else throw new TypeError(`Invalid \`${u}\` type: ${typeof f}`);i+=4+d.buffer.length}c[h]=d}let s=Buffer.allocUnsafe(i);r.all=s;let o=0;for(let a of n){let c;typeof a=="string"?c=r[a].buffer:c=r[a[0]][a[1]].buffer,o=Tt(s,c.length,o),s.set(c,o),o+=c.length}this.totalSize=i,this.lists=r}copyAllTo(e,r){let i=this.lists.all;if(typeof r!="number")throw new TypeError(`Invalid offset value: ${typeof r}`);if(e.length-r<i.length)throw new Error("Insufficient space to copy list");return e.set(i,r),i.length}}})(),mr=(()=>{let n=Buffer.allocUnsafe(4);return(t,e)=>{Tt(n,e.length,0),t.update(n),t.update(e)}})();function wn(n,t,e,r,i,s){let o;if(n){let a=Vo(t).update(e).update(r).update(s).update(i).digest();for(;a.length<n;){let c=Vo(t).update(e).update(r).update(a).digest(),f=Buffer.allocUnsafe(a.length+c.length);f.set(a,0),f.set(c,a.length),a=f}a.length===n?o=a:o=new Gg(a.buffer,a.byteOffset,n)}else o=zg;return o}function Yl(n,t){if(t.length===0){this._debug&&this._debug("Inbound: Skipping empty packet payload");return}if(this._skipNextInboundPacket){this._skipNextInboundPacket=!1;return}t=this._packetRW.read.read(t);let e=t[0];if(!this._strictMode)switch(e){case ut.IGNORE:case ut.UNIMPLEMENTED:case ut.DEBUG:return Sn||(Sn=ns()),Sn[e](this,t)}switch(e){case ut.DISCONNECT:return Sn||(Sn=ns()),Sn[e](this,t);case ut.KEXINIT:return n.firstPacket?(n.firstPacket=!1,Gl(this,t)):Ye(this,"Received extra KEXINIT during handshake","handshake",Ge.KEY_EXCHANGE_FAILED);default:if(e<20||e>49)return Ye(this,`Received unexpected packet type ${e}`,"handshake",Ge.KEY_EXCHANGE_FAILED)}return this._kex.parse(t)}function Jg(n){let t=In[n.cs.cipher],e=In[n.sc.cipher],r=Math.max(0,t.sslName==="des-ede3-cbc"?14:t.keyLen,t.blockLen,t.ivLen,e.sslName==="des-ede3-cbc"?14:e.keyLen,e.blockLen,e.ivLen)*8;return r<=112?2048:r<=128?3072:r<=192?7680:8192}function us(n){if(!n._sentNEWKEYS){n._protocol._debug&&n._protocol._debug("Outbound: Sending NEWKEYS");let t=n._protocol._packetRW.write.allocStartKEX,e=n._protocol._packetRW.write.alloc(1,!0);e[t]=ut.NEWKEYS,n._protocol._cipher.encrypt(n._protocol._packetRW.write.finalize(e,!0)),n._sentNEWKEYS=!0,n._protocol._strictMode&&(n._protocol._cipher.outSeqno=0)}}Vl.exports={KexInit:Yo,kexinit:Kl,onKEXPayload:Yl,DEFAULT_KEXINIT_CLIENT:new Yo({kex:Fl.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:Ql,cs:{cipher:ss,mac:os,compress:as,lang:[]},sc:{cipher:ss,mac:os,compress:as,lang:[]}}),DEFAULT_KEXINIT_SERVER:new Yo({kex:Fl.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:Ql,cs:{cipher:ss,mac:os,compress:as,lang:[]},sc:{cipher:ss,mac:os,compress:as,lang:[]}}),HANDLERS:{[ut.KEXINIT]:Gl}}});var jl=ot((Ob,Zg)=>{Zg.exports={name:"ssh2",version:"1.17.0",author:"Brian White <mscdex@mscdex.net>",description:"SSH2 client and server modules written in pure JavaScript for node.js",main:"./lib/index.js",engines:{node:">=10.16.0"},dependencies:{asn1:"^0.2.6","bcrypt-pbkdf":"^1.0.2"},devDependencies:{"@mscdex/eslint-config":"^1.1.0",eslint:"^7.32.0"},optionalDependencies:{"cpu-features":"~0.0.10",nan:"^2.23.0"},scripts:{install:"node install.js",rebuild:"node install.js",test:"node test/test.js",lint:"eslint --cache --report-unused-disable-directives --ext=.js .eslintrc.js examples lib test","lint:fix":"npm run lint -- --fix"},keywords:["ssh","ssh2","sftp","secure","shell","exec","remote","client"],licenses:[{type:"MIT",url:"http://github.com/mscdex/ssh2/raw/master/LICENSE"}],repository:{type:"git",url:"http://github.com/mscdex/ssh2.git"}}});var Zo=ot((Db,ch)=>{"use strict";var{inspect:th}=require("util"),{bindingAvailable:e0,NullCipher:t0,NullDecipher:r0}=Lr(),{COMPAT_CHECKS:n0,DISCONNECT_REASON:rh,eddsaSupported:i0,MESSAGE:be,SIGNALS:zl,TERMINAL_MODE:Xo}=wr(),{DEFAULT_KEXINIT_CLIENT:s0,DEFAULT_KEXINIT_SERVER:o0,KexInit:Xl,kexinit:nh,onKEXPayload:a0}=is(),{parseKey:Jl}=Dr(),c0=ns(),{bufferCopy:ls,bufferFill:f0,bufferSlice:ih,convertSignature:Zl,sendPacket:xe,writeUInt32BE:B}=or(),{PacketReader:u0,PacketWriter:l0,ZlibPacketReader:sh,ZlibPacketWriter:oh}=qo(),h0=jl().version,d0=new Map(Object.values(rh).map(n=>[n,1])),ah=Buffer.from(`SSH-2.0-ssh2js${h0}`),p0=Buffer.from(`${ah}\r
61
- `),g0=8192,m0=1024,eh=Buffer.from([be.GLOBAL_REQUEST,0,0,0,21,107,101,101,112,97,108,105,118,101,64,111,112,101,110,115,115,104,46,99,111,109,1]),A0=Buffer.from([Xo.TTY_OP_END]);function zo(){}var Jo=class{constructor(t){let e=t.onWrite;if(typeof e!="function")throw new Error("Missing onWrite function");this._onWrite=g=>{e(g)};let r=t.onError;if(typeof r!="function")throw new Error("Missing onError function");this._onError=g=>{r(g)};let i=t.debug;this._debug=typeof i=="function"?g=>{i(g)}:void 0;let s=t.onHeader;this._onHeader=typeof s=="function"?(...g)=>{s(...g)}:zo;let o=t.onPacket;this._onPacket=typeof o=="function"?()=>{o()}:zo;let a=t.onHandshakeComplete;typeof a!="function"&&(a=zo);let c;this._onHandshakeComplete=(...g)=>{this._debug&&this._debug("Handshake completed"),c===void 0?c=!0:c=!1;let _=this._queue;if(_){this._queue=void 0,this._debug&&this._debug(`Draining outbound queue (${_.length}) ...`);for(let y=0;y<_.length;++y){let x=_[y],I=this._packetRW.write.finalize(x);if(I===x){let O=this._cipher.allocPacket(x.length);O.set(x,5),I=O}xe(this,I)}this._debug&&this._debug("... finished draining outbound queue")}c&&this._server&&this._kex.remoteExtInfoEnabled&&w0(this),a(...g)},this._queue=void 0;let f=t.messageHandlers;typeof f=="object"&&f!==null?this._handlers=f:this._handlers={},this._onPayload=b0.bind(this),this._server=!!t.server,this._banner=void 0;let u;if(this._server){if(typeof t.hostKeys!="object"||t.hostKeys===null)throw new Error("Missing server host key(s)");this._hostKeys=t.hostKeys,typeof t.greeting=="string"&&t.greeting.length&&(u=t.greeting.slice(-2)===`\r
5
+ `),`-----BEGIN ${r} KEY-----
6
+ ${e}-----END ${r} KEY-----`}function ei(r,t){let e=Buffer.allocUnsafe(r.length+t.length);return e.set(r,0),e.set(t,r.length),e}function Io(r,t){let e=r.length,n=r._pos||0;for(let i=0;i<t;++i){let s=e-n;if(n>=e||s<4)return!1;let o=Xn(r,n);if(s<4+o)return!1;n+=4+o}return r._pos=n,!0}function ti(r,t){let e=new ke.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.113549.1.1.1"),e.writeNull(),e.endSequence(),e.startSequence(ke.BitString),e.writeByte(0),e.startSequence(),e.writeBuffer(r,ke.Integer),e.writeBuffer(t,ke.Integer),e.endSequence(),e.endSequence(),e.endSequence(),cr("PUBLIC",e.buffer)}function ri(r,t){let e=Buffer.allocUnsafe(15+t.length+4+r.length);Nt(e,7,0),e.utf8Write("ssh-rsa",4,7);let n=11;return Nt(e,t.length,n),e.set(t,n+=4),Nt(e,r.length,n+=t.length),e.set(r,n+4),e}var El=(()=>{function r(n,i,s,o,a,c,f,l){let u=new ke.Writer;return u.startSequence(),u.writeInt(0,ke.Integer),u.writeBuffer(n,ke.Integer),u.writeBuffer(i,ke.Integer),u.writeBuffer(s,ke.Integer),u.writeBuffer(o,ke.Integer),u.writeBuffer(a,ke.Integer),u.writeBuffer(c,ke.Integer),u.writeBuffer(f,ke.Integer),u.writeBuffer(l,ke.Integer),u.endSequence(),u.buffer}function t(n){return BigInt(`0x${n.hexSlice(0,n.length)}`)}function e(n){let i=n.toString(16);if((i.length&1)!==0)i=`0${i}`;else{let s=i.charCodeAt(0);(s===56||s===57||s>=97&&s<=102)&&(i=`00${i}`)}return Buffer.from(i,"hex")}return function(i,s,o,a,c,f){let l=t(o),u=e(l%(t(c)-1n)),h=e(l%(t(f)-1n));return cr("RSA PRIVATE",r(i,s,o,c,f,u,h,a))}})();function ni(r,t,e,n){let i=new ke.Writer;return i.startSequence(),i.startSequence(),i.writeOID("1.2.840.10040.4.1"),i.startSequence(),i.writeBuffer(r,ke.Integer),i.writeBuffer(t,ke.Integer),i.writeBuffer(e,ke.Integer),i.endSequence(),i.endSequence(),i.startSequence(ke.BitString),i.writeByte(0),i.writeBuffer(n,ke.Integer),i.endSequence(),i.endSequence(),cr("PUBLIC",i.buffer)}function ii(r,t,e,n){let i=Buffer.allocUnsafe(15+r.length+4+t.length+4+e.length+4+n.length);Nt(i,7,0),i.utf8Write("ssh-dss",4,7);let s=11;return Nt(i,r.length,s),i.set(r,s+=4),Nt(i,t.length,s+=r.length),i.set(t,s+=4),Nt(i,e.length,s+=t.length),i.set(e,s+=4),Nt(i,n.length,s+=e.length),i.set(n,s+4),i}function _l(r,t,e,n,i){let s=new ke.Writer;return s.startSequence(),s.writeInt(0,ke.Integer),s.writeBuffer(r,ke.Integer),s.writeBuffer(t,ke.Integer),s.writeBuffer(e,ke.Integer),s.writeBuffer(n,ke.Integer),s.writeBuffer(i,ke.Integer),s.endSequence(),cr("DSA PRIVATE",s.buffer)}function bl(r){let t=new ke.Writer;return t.startSequence(),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(ke.BitString),t.writeByte(0),t._ensure(r.length),t._buf.set(r,t._offset),t._offset+=r.length,t.endSequence(),t.endSequence(),cr("PUBLIC",t.buffer)}function yl(r){let t=Buffer.allocUnsafe(19+r.length);return Nt(t,11,0),t.utf8Write("ssh-ed25519",4,11),Nt(t,r.length,15),t.set(r,19),t}function gp(r){let t=new ke.Writer;return t.startSequence(),t.writeInt(0,ke.Integer),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(ke.OctetString),t.writeBuffer(r,ke.OctetString),t.endSequence(),t.endSequence(),cr("PRIVATE",t.buffer)}function Co(r,t){let e=new ke.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.10045.2.1"),e.writeOID(r),e.endSequence(),e.startSequence(ke.BitString),e.writeByte(0),e._ensure(t.length),e._buf.set(t,e._offset),e._offset+=t.length,e.endSequence(),e.endSequence(),cr("PUBLIC",e.buffer)}function vo(r,t){let e;switch(r){case"1.2.840.10045.3.1.7":e="nistp256";break;case"1.3.132.0.34":e="nistp384";break;case"1.3.132.0.35":e="nistp521";break;default:return}let n=Buffer.allocUnsafe(39+t.length);return Nt(n,19,0),n.utf8Write(`ecdsa-sha2-${e}`,4,19),Nt(n,8,23),n.utf8Write(e,27,8),Nt(n,t.length,35),n.set(t,39),n}function mp(r,t,e){let n=new ke.Writer;return n.startSequence(),n.writeInt(1,ke.Integer),n.writeBuffer(e,ke.OctetString),n.startSequence(160),n.writeOID(r),n.endSequence(),n.startSequence(161),n.startSequence(ke.BitString),n.writeByte(0),n._ensure(t.length),n._buf.set(t,n._offset),n._offset+=t.length,n.endSequence(),n.endSequence(),n.endSequence(),cr("EC PRIVATE",n.buffer)}function Ap(r,t){let e=op(r);return e.setPrivateKey(t),e.getPublicKey()}var si={sign:typeof ml=="function"?function(t,e){let n=this[ar];if(n===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Sr]);try{return ml(e,t,n)}catch(i){return i}}:function(t,e){let n=this[ar];if(n===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Sr]);let i=cp(e);i.update(t);try{return i.sign(n)}catch(s){return s}},verify:typeof Al=="function"?function(t,e,n){let i=this[hr];if(i===null)return new Error("No public key available");(!n||typeof n!="string")&&(n=this[Sr]);try{return Al(n,t,i,e)}catch(s){return s}}:function(t,e,n){let i=this[hr];if(i===null)return new Error("No public key available");(!n||typeof n!="string")&&(n=this[Sr]);let s=fp(n);s.update(t);try{return s.verify(i,e)}catch(o){return o}},isPrivateKey:function(){return this[ar]!==null},getPrivatePEM:function(){return this[ar]},getPublicPEM:function(){return this[hr]},getPublicSSH:function(){return this[Tr]},equals:function(t){let e=wl(t);return e instanceof Error?!1:this.type===e.type&&this[ar]===e[ar]&&this[hr]===e[hr]&&this[Tr].equals(e[Tr])}};function zi(r,t,e,n,i,s,o){this.type=r,this.comment=t,this[ar]=e,this[hr]=n,this[Tr]=i,this[Sr]=s,this[En]=o}zi.prototype=si;{let t=function(e,n,i){let s=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=Xn(e,0),a=Xn(e,4);if(o!==a)return i?new Error("OpenSSH key integrity check failed -- bad passphrase?"):new Error("OpenSSH key integrity check failed");e._pos=8;let c,f;for(c=0;c<n;++c){let u,h,g,b,_=Ce(e,e._pos,!0);if(_===void 0)return new Error("Malformed OpenSSH private key");switch(_){case"ssh-rsa":{let S=Ce(e,e._pos);if(S===void 0)return new Error("Malformed OpenSSH private key");let N=Ce(e,e._pos);if(N===void 0)return new Error("Malformed OpenSSH private key");let O=Ce(e,e._pos);if(O===void 0)return new Error("Malformed OpenSSH private key");let P=Ce(e,e._pos);if(P===void 0)return new Error("Malformed OpenSSH private key");let W=Ce(e,e._pos);if(W===void 0)return new Error("Malformed OpenSSH private key");let X=Ce(e,e._pos);if(X===void 0)return new Error("Malformed OpenSSH private key");g=ti(S,N),b=ri(S,N),h=El(S,N,O,P,W,X),u="sha1";break}case"ssh-dss":{let S=Ce(e,e._pos);if(S===void 0)return new Error("Malformed OpenSSH private key");let N=Ce(e,e._pos);if(N===void 0)return new Error("Malformed OpenSSH private key");let O=Ce(e,e._pos);if(O===void 0)return new Error("Malformed OpenSSH private key");let P=Ce(e,e._pos);if(P===void 0)return new Error("Malformed OpenSSH private key");let W=Ce(e,e._pos);if(W===void 0)return new Error("Malformed OpenSSH private key");g=ni(S,N,O,P),b=ii(S,N,O,P),h=_l(S,N,O,P,W),u="sha1";break}case"ssh-ed25519":{if(!wo)return new Error(`Unsupported OpenSSH private key type: ${_}`);let S=Ce(e,e._pos);if(S===void 0||S.length!==32)return new Error("Malformed OpenSSH private key");let N=Ce(e,e._pos);if(N===void 0||N.length!==64)return new Error("Malformed OpenSSH private key");g=bl(S),b=yl(S),h=gp(Xr(N,0,32)),u=null;break}case"ecdsa-sha2-nistp256":u="sha256",f="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":u===void 0&&(u="sha384",f="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(u===void 0&&(u="sha512",f="1.3.132.0.35"),!Io(e,1))return new Error("Malformed OpenSSH private key");let S=Ce(e,e._pos);if(S===void 0)return new Error("Malformed OpenSSH private key");let N=Ce(e,e._pos);if(N===void 0)return new Error("Malformed OpenSSH private key");g=Co(f,S),b=vo(f,S),h=mp(f,S,N);break}default:return new Error(`Unsupported OpenSSH private key type: ${_}`)}let x=Ce(e,e._pos,!0);if(x===void 0)return new Error("Malformed OpenSSH private key");s.push(new zi(_,x,h,g,b,u,i))}let l=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++l%255)return new Error("Malformed OpenSSH private key");return s},r=/^-----BEGIN OPENSSH PRIVATE KEY-----(?:\r\n|\n)([\s\S]+)(?:\r\n|\n)-----END OPENSSH PRIVATE KEY-----$/;zi.parse=(e,n)=>{let i=r.exec(e);if(i===null)return null;let s,o=Buffer.from(i[1],"base64");if(o.length<31)return new Error("Malformed OpenSSH private key");let a=o.utf8Slice(0,15);if(a!=="openssh-key-v1\0")return new Error(`Unsupported OpenSSH key magic: ${a}`);let c=Ce(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&hp.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let f=Ce(o,o._pos,!0);if(f===void 0)return new Error("Malformed OpenSSH private key");if(f!=="none"){if(c==="none")return new Error("Malformed OpenSSH private key");if(f!=="bcrypt")return new Error(`Unsupported kdf name for OpenSSH key: ${f}`);if(!n)return new Error("Encrypted private OpenSSH key detected, but no passphrase given")}else if(c!=="none")return new Error("Malformed OpenSSH private key");let l,u,h;c!=="none"&&(l=Zn[c]);let g=Ce(o,o._pos);if(g===void 0)return new Error("Malformed OpenSSH private key");if(g.length)switch(f){case"none":return new Error("Malformed OpenSSH private key");case"bcrypt":{let _=Ce(g,0);if(_===void 0||g._pos+4>g.length)return new Error("Malformed OpenSSH private key");let x=Xn(g,g._pos),S=Buffer.allocUnsafe(l.keyLen+l.ivLen);if(dp(n,n.length,_,_.length,S,S.length,x)!==0)return new Error("Failed to generate information to decrypt key");u=Xr(S,0,l.keyLen),h=Xr(S,l.keyLen,S.length);break}}else if(f!=="none")return new Error("Malformed OpenSSH private key");if(o._pos+3>=o.length)return new Error("Malformed OpenSSH private key");let b=Xn(o,o._pos);if(o._pos+=4,b>0){for(let x=0;x<b;++x){let S=Ce(o,o._pos);if(S===void 0)return new Error("Malformed OpenSSH private key");if(Ce(S,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let _=Ce(o,o._pos);if(_===void 0)return new Error("Malformed OpenSSH private key");if(u!==void 0){if(_.length<l.blockLen||_.length%l.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let x={authTagLength:l.authLen},S=So(l.sslName,u,h,x);if(S.setAutoPadding(!1),l.authLen>0){if(o.length-o._pos<l.authLen)return new Error("Malformed OpenSSH private key");S.setAuthTag(Xr(o,o._pos,o._pos+=l.authLen))}_=ei(S.update(_),S.final())}catch(x){return x}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");s=t(_,b,u!==void 0)}else s=[];return s instanceof Error?s:s[0]}}function Xi(r,t,e,n,i,s,o){this.type=r,this.comment=t,this[ar]=e,this[hr]=n,this[Tr]=i,this[Sr]=s,this[En]=o}Xi.prototype=si;{let r=/^-----BEGIN (RSA|DSA|EC) PRIVATE KEY-----(?:\r\n|\n)((?:[^:]+:\s*[\S].*(?:\r\n|\n))*)([\s\S]+)(?:\r\n|\n)-----END (RSA|DSA|EC) PRIVATE KEY-----$/;Xi.parse=(t,e)=>{let n=r.exec(t);if(n===null)return null;let i=Buffer.from(n[3],"base64"),s=n[2],o=!1;if(s!==void 0){s=s.split(/\r\n|\n/g);for(let b=0;b<s.length;++b){let _=s[b],x=_.indexOf(":");if(_.slice(0,x)==="DEK-Info"){let S=_.slice(x+2);if(x=S.indexOf(","),x===-1)continue;let N=S.slice(0,x).toLowerCase();if(up.indexOf(N)===-1)return new Error(`Cipher (${N}) not supported for encrypted OpenSSH private key`);let O=xo[N];if(!O)return new Error(`Cipher (${N}) not supported for encrypted OpenSSH private key`);let P=Buffer.from(S.slice(x+1),"hex");if(P.length!==O.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let W=Xr(P,0,8),X=Jn("md5").update(e).update(W).digest();for(;X.length<O.keyLen;)X=ei(X,Jn("md5").update(X).update(e).update(W).digest());X.length>O.keyLen&&(X=Xr(X,0,O.keyLen));try{let G=So(N,X,P);G.setAutoPadding(!1),i=ei(G.update(i),G.final()),o=!0}catch(G){return G}}}}let a,c,f,l,u,h,g="Malformed OpenSSH private key";switch(o&&(g+=". Bad passphrase?"),n[1]){case"RSA":a="ssh-rsa",c=cr("RSA PRIVATE",i);try{h=new ke.Reader(i),h.readSequence(),h.readInt();let b=h.readString(ke.Integer,!0);if(b===null)return new Error(g);let _=h.readString(ke.Integer,!0);if(_===null)return new Error(g);f=ti(b,_),l=ri(b,_)}catch{return new Error(g)}u="sha1";break;case"DSA":a="ssh-dss",c=cr("DSA PRIVATE",i);try{h=new ke.Reader(i),h.readSequence(),h.readInt();let b=h.readString(ke.Integer,!0);if(b===null)return new Error(g);let _=h.readString(ke.Integer,!0);if(_===null)return new Error(g);let x=h.readString(ke.Integer,!0);if(x===null)return new Error(g);let S=h.readString(ke.Integer,!0);if(S===null)return new Error(g);f=ni(b,_,x,S),l=ii(b,_,x,S)}catch{return new Error(g)}u="sha1";break;case"EC":{let b,_,x;try{h=new ke.Reader(i),h.readSequence(),h.readInt(),_=h.readString(ke.OctetString,!0),h.readByte();let N=h.readLength();if(N!==null){if(h._offset=N,x=h.readOID(),x===null)return new Error(g);switch(x){case"1.2.840.10045.3.1.7":b="prime256v1",a="ecdsa-sha2-nistp256",u="sha256";break;case"1.3.132.0.34":b="secp384r1",a="ecdsa-sha2-nistp384",u="sha384";break;case"1.3.132.0.35":b="secp521r1",a="ecdsa-sha2-nistp521",u="sha512";break;default:return new Error(`Unsupported private key EC OID: ${x}`)}}else return new Error(g)}catch{return new Error(g)}c=cr("EC PRIVATE",i);let S=Ap(b,_);f=Co(x,S),l=vo(x,S);break}}return new Xi(a,"",c,f,l,u,o)}}function Ji(r,t,e,n,i,s,o){this.type=r,this.comment=t,this[ar]=e,this[hr]=n,this[Tr]=i,this[Sr]=s,this[En]=o}Ji.prototype=si;{let r=Buffer.alloc(0),t=Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),e=Buffer.from([0,0,0,0]),n=Buffer.from([0,0,0,1]),i=/^PuTTY-User-Key-File-2: (ssh-(?:rsa|dss))\r?\nEncryption: (aes256-cbc|none)\r?\nComment: ([^\r\n]*)\r?\nPublic-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-MAC: ([^\r\n]+)/;Ji.parse=(s,o)=>{let a=i.exec(s);if(a===null)return null;let c=a[2],f=c!=="none";if(f&&!o)return new Error("Encrypted PPK private key detected, but no passphrase given");let l=Buffer.from(a[5],"base64");if(f){let D=Zn[c],q=ei(Jn("sha1").update(e).update(o).digest(),Jn("sha1").update(n).update(o).digest());q.length>D.keyLen&&(q=Xr(q,0,D.keyLen));try{let Q=So(D.sslName,q,t);Q.setAutoPadding(!1),l=ei(Q.update(l),Q.final())}catch(Q){return Q}}let u=a[1],h=a[3],g=Buffer.from(a[4],"base64"),b=a[6],_=u.length,x=c.length,S=Buffer.byteLength(h),N=g.length,O=l.length,P=Buffer.allocUnsafe(4+_+4+x+4+S+4+N+4+O),W=0;if(Nt(P,_,W),P.utf8Write(u,W+=4,_),Nt(P,x,W+=_),P.utf8Write(c,W+=4,x),Nt(P,S,W+=x),P.utf8Write(h,W+=4,S),Nt(P,N,W+=S),P.set(g,W+=4),Nt(P,O,W+=N),P.set(l,W+4),o||(o=r),ap("sha1",Jn("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(P).digest("hex")!==b)return f?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let G,w,I;switch(g._pos=0,Io(g,1),u){case"ssh-rsa":{let D=Ce(g,g._pos);if(D===void 0)return new Error("Malformed PPK public key");let q=Ce(g,g._pos);if(q===void 0)return new Error("Malformed PPK public key");let Q=Ce(l,0);if(Q===void 0)return new Error("Malformed PPK private key");let ae=Ce(l,l._pos);if(ae===void 0)return new Error("Malformed PPK private key");let te=Ce(l,l._pos);if(te===void 0)return new Error("Malformed PPK private key");let Z=Ce(l,l._pos);if(Z===void 0)return new Error("Malformed PPK private key");G=ti(q,D),w=ri(q,D),I=El(q,D,Q,Z,ae,te);break}case"ssh-dss":{let D=Ce(g,g._pos);if(D===void 0)return new Error("Malformed PPK public key");let q=Ce(g,g._pos);if(q===void 0)return new Error("Malformed PPK public key");let Q=Ce(g,g._pos);if(Q===void 0)return new Error("Malformed PPK public key");let ae=Ce(g,g._pos);if(ae===void 0)return new Error("Malformed PPK public key");let te=Ce(l,0);if(te===void 0)return new Error("Malformed PPK private key");G=ni(D,q,Q,ae),w=ii(D,q,Q,ae),I=_l(D,q,Q,ae,te);break}}return new Ji(u,h,I,G,w,"sha1",f)}}function es(r,t,e,n,i){this.type=r,this.comment=t,this[ar]=null,this[hr]=e,this[Tr]=n,this[Sr]=i,this[En]=!1}es.prototype=si;{let r;wo?r=/^(((?:ssh-(?:rsa|dss|ed25519))|ecdsa-sha2-nistp(?:256|384|521))(?:-cert-v0[01]@openssh.com)?) ([A-Z0-9a-z/+=]+)(?:$|\s+([\S].*)?)$/:r=/^(((?:ssh-(?:rsa|dss))|ecdsa-sha2-nistp(?:256|384|521))(?:-cert-v0[01]@openssh.com)?) ([A-Z0-9a-z/+=]+)(?:$|\s+([\S].*)?)$/,es.parse=t=>{let e=r.exec(t);if(e===null)return null;let n=e[1],i=e[2],s=Buffer.from(e[3],"base64"),o=e[4]||"",a=Ce(s,s._pos,!0);return a===void 0||a.indexOf(i)!==0?new Error("Malformed OpenSSH public key"):ko(s,i,o,n)}}function Zi(r,t,e,n,i){this.type=r,this.comment=t,this[ar]=null,this[hr]=e,this[Tr]=n,this[Sr]=i,this[En]=!1}Zi.prototype=si;{let r=/^---- BEGIN SSH2 PUBLIC KEY ----(?:\r?\n)((?:.{0,72}\r?\n)+)---- END SSH2 PUBLIC KEY ----$/,t=/^[A-Z0-9a-z/+=\r\n]+$/,e=/^([\x21-\x39\x3B-\x7E]{1,64}): ((?:[^\\]*\\\r?\n)*[^\r\n]+)\r?\n/gm,n=/\\\r?\n/g;Zi.parse=i=>{let s=r.exec(i);if(s===null)return null;let o=s[1],a=0,c="";for(;s=e.exec(o);){let g=s[1],b=s[2].replace(n,"");if(b.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,g.toLowerCase()==="comment"&&(c=b,c.length>1&&c.charCodeAt(0)===34&&c.charCodeAt(c.length-1)===34&&(c=c.slice(1,-1)))}let f=o.slice(a);if(!t.test(f))return new Error("Malformed RFC4716 public key");f=Buffer.from(f,"base64");let l=Ce(f,0,!0);if(l===void 0)return new Error("Malformed RFC4716 public key");let u=null,h=null;switch(l){case"ssh-rsa":{let g=Ce(f,f._pos);if(g===void 0)return new Error("Malformed RFC4716 public key");let b=Ce(f,f._pos);if(b===void 0)return new Error("Malformed RFC4716 public key");u=ti(b,g),h=ri(b,g);break}case"ssh-dss":{let g=Ce(f,f._pos);if(g===void 0)return new Error("Malformed RFC4716 public key");let b=Ce(f,f._pos);if(b===void 0)return new Error("Malformed RFC4716 public key");let _=Ce(f,f._pos);if(_===void 0)return new Error("Malformed RFC4716 public key");let x=Ce(f,f._pos);if(x===void 0)return new Error("Malformed RFC4716 public key");u=ni(g,b,_,x),h=ii(g,b,_,x);break}default:return new Error("Malformed RFC4716 public key")}return new Zi(l,c,u,h,"sha1")}}function ko(r,t,e,n){if(!xl(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let i,s,o=null,a=null;switch(t){case"ssh-rsa":{let c=Ce(r,r._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=Ce(r,r._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");o=ti(f,c),a=ri(f,c),i="sha1";break}case"ssh-dss":{let c=Ce(r,r._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=Ce(r,r._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");let l=Ce(r,r._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");let u=Ce(r,r._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");o=ni(c,f,l,u),a=ii(c,f,l,u),i="sha1";break}case"ssh-ed25519":{let c=Ce(r,r._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=bl(c),a=yl(c),i=null;break}case"ecdsa-sha2-nistp256":i="sha256",s="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":i===void 0&&(i="sha384",s="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(i===void 0&&(i="sha512",s="1.3.132.0.35"),!Io(r,1))return new Error("Malformed OpenSSH public key");let c=Ce(r,r._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=Co(s,c),a=vo(s,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new es(n,e,o,a,i)}function xl(r){switch(r){case"ssh-rsa":case"ssh-dss":case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":return!0;case"ssh-ed25519":if(wo)return!0;default:return!1}}function Sl(r){return r?typeof r[En]=="boolean":!1}function wl(r,t){if(Sl(r))return r;let e;if(Buffer.isBuffer(r))e=r,r=r.utf8Slice(0,r.length).trim();else if(typeof r=="string")r=r.trim();else return new Error("Key data must be a Buffer or string");if(t!=null){if(typeof t=="string")t=Buffer.from(t);else if(!Buffer.isBuffer(t))return new Error("Passphrase must be a string or Buffer when supplied")}let n;if((n=zi.parse(r,t))!==null||(n=Xi.parse(r,t))!==null||(n=Ji.parse(r,t))!==null||(n=es.parse(r))!==null||(n=Zi.parse(r))!==null)return n;if(e){ji.init(e,0);let i=ji.readString(!0);i!==void 0&&(r=ji.readRaw(),r!==void 0&&(n=ko(r,i,"",i),n instanceof Error&&(n=null))),ji.clear()}return n||new Error("Unsupported key format")}Il.exports={isParsedKey:Sl,isSupportedKeyType:xl,parseDERKey:(r,t)=>ko(r,t,"",t),parseKey:wl}});var Lo=ot((Uy,Ul)=>{"use strict";var{Socket:Bl}=require("net"),{Duplex:Rl}=require("stream"),{resolve:Ep}=require("path"),{readFile:Cl}=require("fs"),{execFile:_p,spawn:bp}=require("child_process"),{isParsedKey:vl,parseKey:oi}=Lr(),{makeBufferParser:yp,readUInt32BE:To,writeUInt32BE:Vt,writeUInt32LE:kl}=or();function ai(r){let t=!1;return(...e)=>{t||(t=!0,r(...e))}}function xp(r,t){let e=Buffer.allocUnsafe(r.length+t.length);return r.copy(e,0),t.copy(e,r.length),e}function Ro(){}var Sp=Buffer.alloc(0),mt=yp(),ci=class{getIdentities(t){t(new Error("Missing getIdentities() implementation"))}sign(t,e,n,i){typeof n=="function"&&(i=n),i(new Error("Missing sign() implementation"))}},bn=class extends ci{constructor(t){super(),this.socketPath=t}getStream(t){t=ai(t);let e=new Bl;e.on("connect",()=>{t(null,e)}),e.on("close",n).on("end",n).on("error",n),e.connect(this.socketPath);function n(){try{e.destroy()}catch{}t(new Error("Failed to connect to agent"))}}getIdentities(t){t=ai(t),this.getStream((e,n)=>{function i(o){if(n)try{n.destroy()}catch{}o||(o=new Error("Failed to retrieve identities from agent")),t(o)}if(e)return i(e);let s=new No(!0);s.on("error",i),s.pipe(n).pipe(s),n.on("close",i).on("end",i).on("error",i),s.getIdentities((o,a)=>{if(o)return i(o);try{n.destroy()}catch{}t(null,a)})})}sign(t,e,n,i){typeof n=="function"?(i=n,n=void 0):(typeof n!="object"||n===null)&&(n=void 0),i=ai(i),this.getStream((s,o)=>{function a(f){if(o)try{o.destroy()}catch{}f||(f=new Error("Failed to sign data with agent")),i(f)}if(s)return a(s);let c=new No(!0);c.on("error",a),c.pipe(o).pipe(c),o.on("close",a).on("end",a).on("error",a),c.sign(t,e,n,(f,l)=>{if(f)return a(f);try{o.destroy()}catch{}i(null,l)})})}},Nl=(()=>{let o=Ep(__dirname,"..","util/pagent.exe"),a={10:new Error("Invalid pagent.exe arguments"),11:new Error("Pageant is not running"),12:new Error("pagent.exe could not create an mmap"),13:new Error("pagent.exe could not set mode for stdin"),14:new Error("pagent.exe could not set mode for stdout"),15:new Error("pagent.exe did not get expected input payload")};function c(l){l.buffer=null,l.proc&&(l.proc.kill(),l.proc=void 0)}class f extends Rl{constructor(){super(),this.proc=void 0,this.buffer=null}_read(u){}_write(u,h,g){if(this.buffer===null)this.buffer=u;else{let S=Buffer.allocUnsafe(this.buffer.length+u.length);this.buffer.copy(S,0),u.copy(S,this.buffer.length),this.buffer=S}if(this.buffer.length<4)return g();let b=To(this.buffer,0);if(this.buffer.length-4<b)return g();if(u=this.buffer.slice(0,4+b),this.buffer.length>4+b)return g(new Error("Unexpected multiple agent requests"));this.buffer=null;let _,x=this.proc=bp(o,[u.length]);x.stdout.on("data",S=>{this.push(S)}),x.on("error",S=>{_=S,g(_)}),x.on("close",S=>{if(this.proc=void 0,!_){if(_=a[S])return g(_);g()}}),x.stdin.end(u)}_final(u){c(this),u()}_destroy(u,h){c(this),h()}}return class extends bn{getStream(u){u(null,new f)}}})(),Pl=(()=>{let r=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends bn{getStream(e){e=ai(e);let n=this.socketPath,i=!1;Cl(n,function s(o,a){if(o){if(i)return e(new Error("Invalid cygwin unix socket path"));_p("cygpath",["-w",n],(X,G,w)=>{if(X||G.length===0)return e(new Error("Invalid cygwin unix socket path"));i=!0,n=G.toString().replace(/[\r\n]/g,""),Cl(n,s)});return}let c=r.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let f,l=0,u=!1,h=[],g,b=Buffer.alloc(12),_=parseInt(c[1],10),x=c[2].replace(/-/g,""),S=Buffer.allocUnsafe(16);for(let X=0,G=0;G<32;++X,G+=2)S[X]=parseInt(x.substring(G,G+2),16);for(let X=0;X<16;X+=4)kl(S,To(S,X),X);W();function N(){l=0,f="secret",g.write(S)}function O(X){if(l+=X.length,f==="secret"){l===16&&(l=0,f="creds",g.write(b));return}if(f==="creds"&&(u||h.push(X),l===12)){if(g.removeListener("connect",N),g.removeListener("data",O),g.removeListener("error",P),g.removeListener("end",P),g.removeListener("close",P),u)return e(null,g);u=!0,b=Buffer.concat(h),kl(b,process.pid,0),g.on("error",()=>{}),g.destroy(),W()}}function P(){e(new Error("Problem negotiating cygwin unix socket security"))}function W(){g=new Bl,g.on("connect",N),g.on("data",O),g.on("error",P),g.on("end",P),g.on("close",P),g.connect(_)}})}}})(),wp=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function Tl(r){return process.platform==="win32"&&!wp.test(r)?r==="pageant"?new Nl:new Pl(r):new bn(r)}var No=(()=>{function f(w){let I;for(;w[N].length;){let D=w[N][0][u];if(D===void 0)break;w[N].shift(),I=w.push(D)}return I}let l=Symbol("Inbound Request Type"),u=Symbol("Inbound Request Response"),h=Symbol("Inbound Request Context");class g{constructor(I,D){this[l]=I,this[u]=void 0,this[h]=D}hasResponded(){return this[u]!==void 0}getType(){return this[l]}getContext(){return this[h]}}function b(w,I,D){return I[u]=D,f(w)}function _(w){if(w[P]=null,w[O]===0){let I=w[N];if(I&&I.length){w[N]=[];for(let D of I)D.cb(new Error("No reply from server"))}}try{w.end()}catch{}setImmediate(()=>{w[G]||w.emit("end"),w[X]||w.emit("close")})}function x(){this[X]=!0}function S(){this[G]=!0}let N=Symbol("Requests"),O=Symbol("Agent Protocol Role"),P=Symbol("Agent Protocol Buffer"),W=Symbol("Agent Protocol Current Message Length"),X=Symbol("Agent Protocol Closed"),G=Symbol("Agent Protocol Ended");return class extends Rl{constructor(I){super({autoDestroy:!0,emitClose:!1}),this[O]=I?0:1,this[N]=[],this[P]=null,this[W]=-1,this.once("end",S),this.once("close",x)}_read(I){}_write(I,D,q){this[P]===null?this[P]=I:this[P]=xp(this[P],I);let Q=this[P],ae=Q.length,te=0;for(;te<ae&&!(ae<5||(this[W]===-1&&(this[W]=To(Q,te)),ae<4+this[W]));){let Z=Q[te+=4];if(++te,this[O]===0){if(this[N].length===0)return q(new Error("Received unexpected message from server"));let re=this[N].shift();switch(Z){case 5:re.cb(new Error("Agent responded with failure"));break;case 12:{if(re.type!==11)return q(new Error("Agent responded with wrong message type"));mt.init(Q,te);let ce=mt.readUInt32BE();if(ce===void 0)return mt.clear(),q(new Error("Malformed agent response"));let U=[];for(let C=0;C<ce;++C){let k=mt.readString();if(k===void 0)return mt.clear(),q(new Error("Malformed agent response"));let M=mt.readString(!0);if(M===void 0)return mt.clear(),q(new Error("Malformed agent response"));k=oi(k),!(k instanceof Error)&&(k.comment=k.comment||M,U.push(k))}te=mt.pos(),mt.clear(),re.cb(null,U);break}case 14:{if(re.type!==13)return q(new Error("Agent responded with wrong message type"));mt.init(Q,te);let ce=mt.readString();if(te=mt.pos(),mt.clear(),ce===void 0)return q(new Error("Malformed agent response"));if(mt.init(ce,0),mt.readString(!0),ce=mt.readString(),mt.clear(),ce===void 0)return q(new Error("Malformed OpenSSH signature format"));re.cb(null,ce);break}default:return q(new Error("Agent responded with unsupported message type"))}}else switch(Z){case 11:{let re=new g(Z);this[N].push(re),this.emit("identities",re);break}case 13:{mt.init(Q,te);let re=mt.readString(),ce=mt.readString(),U=mt.readUInt32BE();if(te=mt.pos(),mt.clear(),U===void 0){let Y=new g(Z);return this[N].push(Y),this.failureReply(Y)}if(re=oi(re),re instanceof Error){let Y=new g(Z);return this[N].push(Y),this.failureReply(Y)}let C={hash:void 0},k;re.type==="ssh-rsa"&&(U&2?(k="rsa-sha2-256",C.hash="sha256"):U&4&&(k="rsa-sha2-512",C.hash="sha512")),k===void 0&&(k=re.type);let M=new g(Z,k);this[N].push(M),this.emit("sign",M,re,ce,C);break}default:{let re=new g(Z);this[N].push(re),this.failureReply(re)}}if(this[W]=-1,te===ae){this[P]=null;break}else this[P]=Q=Q.slice(te),ae=Q.length,te=0}q()}_destroy(I,D){_(this),D()}_final(I){_(this),I()}sign(I,D,q,Q){if(this[O]!==0)throw new Error("Client-only method called with server role");typeof q=="function"?(Q=q,q=void 0):(typeof q!="object"||q===null)&&(q=void 0);let ae=0;if(I=oi(I),I instanceof Error)throw new Error("Invalid public key argument");if(I.type==="ssh-rsa"&&q)switch(q.hash){case"sha256":ae=2;break;case"sha512":ae=4;break}I=I.getPublicSSH();let te=13,Z=I.length,re=D.length,ce=0,U=Buffer.allocUnsafe(9+Z+4+re+4);return Vt(U,U.length-4,ce),U[ce+=4]=te,Vt(U,Z,++ce),I.copy(U,ce+=4),Vt(U,re,ce+=Z),D.copy(U,ce+=4),Vt(U,ae,ce+=re),typeof Q!="function"&&(Q=Ro),this[N].push({type:te,cb:Q}),this.push(U)}getIdentities(I){if(this[O]!==0)throw new Error("Client-only method called with server role");let D=11,q=0,Q=Buffer.allocUnsafe(5);return Vt(Q,Q.length-4,q),Q[q+=4]=D,typeof I!="function"&&(I=Ro),this[N].push({type:D,cb:I}),this.push(Q)}failureReply(I){if(this[O]!==1)throw new Error("Server-only method called with client role");if(!(I instanceof g))throw new Error("Wrong request argument");if(I.hasResponded())return!0;let D=0,q=Buffer.allocUnsafe(5);return Vt(q,q.length-4,D),q[D+=4]=5,b(this,I,q)}getIdentitiesReply(I,D){if(this[O]!==1)throw new Error("Server-only method called with client role");if(!(I instanceof g))throw new Error("Wrong request argument");if(I.hasResponded())return!0;if(I.getType()!==11)throw new Error("Invalid response to request");if(!Array.isArray(D))throw new Error("Keys argument must be an array");let q=4,Q=[];for(let Z=0;Z<D.length;++Z){let re=D[Z];if(typeof re!="object"||re===null)throw new Error(`Invalid key entry: ${re}`);let ce,U;if(vl(re))ce=re;else if(vl(re.pubKey))ce=re.pubKey;else if(typeof re.pubKey!="object"||re.pubKey===null||({pubKey:ce,comment:U}=re.pubKey,ce=oi(ce),ce instanceof Error))continue;U=ce.comment||U,ce=ce.getPublicSSH(),q+=4+ce.length,U&&typeof U=="string"?U=Buffer.from(U):Buffer.isBuffer(U)||(U=Sp),q+=4+U.length,Q.push({pubKey:ce,comment:U})}let ae=0,te=Buffer.allocUnsafe(5+q);Vt(te,te.length-4,ae),te[ae+=4]=12,Vt(te,Q.length,++ae),ae+=4;for(let Z=0;Z<Q.length;++Z){let{pubKey:re,comment:ce}=Q[Z];Vt(te,re.length,ae),re.copy(te,ae+=4),Vt(te,ce.length,ae+=re.length),ae+=4,ce.length&&(ce.copy(te,ae),ae+=ce.length)}return b(this,I,te)}signReply(I,D){if(this[O]!==1)throw new Error("Server-only method called with client role");if(!(I instanceof g))throw new Error("Wrong request argument");if(I.hasResponded())return!0;if(I.getType()!==13)throw new Error("Invalid response to request");if(!Buffer.isBuffer(D))throw new Error("Signature argument must be a Buffer");if(D.length===0)throw new Error("Signature argument must be non-empty");let q=0,Q=I.getContext(),ae=Buffer.byteLength(Q),te=Buffer.allocUnsafe(13+ae+4+D.length);return Vt(te,te.length-4,q),te[q+=4]=14,Vt(te,4+ae+4+D.length,++q),Vt(te,ae,q+=4),te.utf8Write(Q,q+=4,ae),Vt(te,D.length,q+=ae),D.copy(te,q+=4),b(this,I,te)}}})(),Bo=Symbol("Agent"),fr=Symbol("Agent Keys"),wr=Symbol("Agent Keys Index"),_n=Symbol("Agent Init Callbacks"),Po=class{constructor(t){if(typeof t=="string")t=Tl(t);else if(!Ll(t))throw new Error("Invalid agent argument");this[Bo]=t,this[fr]=null,this[wr]=-1,this[_n]=null}init(t){if(typeof t!="function"&&(t=Ro),this[fr]===null)if(this[_n]===null){this[_n]=[t];let e=(...n)=>{process.nextTick(()=>{let i=this[_n];this[_n]=null;for(let s of i)s(...n)})};this[Bo].getIdentities(ai((n,i)=>{if(n)return e(n);if(!Array.isArray(i))return e(new Error("Agent implementation failed to provide keys"));let s=[];for(let o of i)o=oi(o),!(o instanceof Error)&&s.push(o);this[fr]=s,this[wr]=-1,e()}))}else this[_n].push(t);else process.nextTick(t)}nextKey(){return this[fr]===null||++this[wr]>=this[fr].length?!1:this[fr][this[wr]]}currentKey(){return this[fr]===null||this[wr]>=this[fr].length?null:this[fr][this[wr]]}pos(){return this[fr]===null||this[wr]>=this[fr].length?-1:this[wr]}reset(){this[wr]=-1}sign(...t){this[Bo].sign(...t)}};function Ll(r){return r instanceof ci}Ul.exports={AgentContext:Po,AgentProtocol:No,BaseAgent:ci,createAgent:Tl,CygwinAgent:Pl,isAgent:Ll,OpenSSHAgent:bn,PageantAgent:Nl}});var $o=ot((Dy,Dl)=>{"use strict";var{kMaxLength:Ip}=require("buffer"),{createInflate:Cp,constants:{DEFLATE:vp,INFLATE:kp,Z_DEFAULT_CHUNK:Bp,Z_DEFAULT_COMPRESSION:Rp,Z_DEFAULT_MEMLEVEL:Np,Z_DEFAULT_STRATEGY:Pp,Z_DEFAULT_WINDOWBITS:Tp,Z_PARTIAL_FLUSH:Lp}}=require("zlib"),Up=Cp()._handle.constructor;function Dp(){throw new Error("Should not get here")}function Op(r,t,e){let n=this._owner,i=new Error(r);i.errno=t,i.code=e,n._err=i}function Fo(r){r._handle&&(r._handle.close(),r._handle=null)}var ts=class{constructor(t){let e=Tp,n=Rp,i=Np,s=Pp,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=Bp,this._maxOutputLength=Ip,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new Up(t),this._handle._owner=this,this._handle.onerror=Op,this._handle.init(e,n,i,s,this._writeState,Dp,o)}writeSync(t,e){let n=this._handle;if(!n)throw new Error("Invalid Zlib instance");let i=t.length,s=this._chunkSize-this._outOffset,o=0,a,c,f,l=0,u=this._writeState,h=this._outBuffer,g=this._outOffset,b=this._chunkSize;for(;;){if(n.writeSync(Lp,t,o,i,h,g,s),this._err)throw this._err;a=u[0],c=u[1];let x=i-c,S=s-a;if(S>0){let N=g===0&&S===h.length?h:h.slice(g,g+S);if(g+=S,f?f.push===void 0?f=[f,N]:f.push(N):f=N,l+=N.byteLength,l>this._maxOutputLength)throw Fo(this),new Error(`Output length exceeded maximum of ${this._maxOutputLength}`)}else if(S!==0)throw new Error("have should not go down");if((a===0||g>=b)&&(s=b,g=0,h=Buffer.allocUnsafe(b)),a===0)o+=x,i=c;else break}if(this._outBuffer=h,this._outOffset=g,l===0&&(f=Buffer.alloc(0)),e)return f.totalLen=l,f;if(f.push===void 0)return f;let _=Buffer.allocUnsafe(l);for(let x=0,S=0;x<f.length;++x){let N=f[x];_.set(N,S),S+=N.length}return _}},Uo=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new ts(vp)}cleanup(){this._zlib&&Fo(this._zlib)}alloc(t,e){return Buffer.allocUnsafe(t)}finalize(t,e){if(this._protocol._kexinit===void 0||e){let n=this._zlib.writeSync(t,!0),i=this._protocol._cipher.allocPacket(n.totalLen);if(n.push===void 0)i.set(n,5);else for(let s=0,o=5;s<n.length;++s){let a=n[s];i.set(a,o),o+=a.length}return i}return t}},Do=class{constructor(t){this.allocStart=5,this.allocStartKEX=5,this._protocol=t}cleanup(){}alloc(t,e){return this._protocol._kexinit===void 0||e?this._protocol._cipher.allocPacket(t):Buffer.allocUnsafe(t)}finalize(t,e){return t}},Oo=class{constructor(){this._zlib=new ts(kp)}cleanup(){this._zlib&&Fo(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},Mo=class{cleanup(){}read(t){return t}};Dl.exports={PacketReader:Mo,PacketWriter:Do,ZlibPacketReader:Oo,ZlibPacketWriter:Uo}});var Hl=ot((Oy,$l)=>{"use strict";var{bufferSlice:Ho,bufferParser:R,doFatalError:ut,sigSSHToASN1:Ol,writeUInt32BE:Ml}=or(),{CHANNEL_OPEN_FAILURE:Mp,COMPAT:Fp,MESSAGE:dt,TERMINAL_MODE:Fl}=xr(),{parseKey:$p}=Lr(),Hp=Array.from(Object.entries(Fl)).reduce((r,[t,e])=>({...r,[t]:e}),{});$l.exports={[dt.DISCONNECT]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE(),n=R.readString(!0),i=R.readString();if(R.clear(),i===void 0)return ut(r,"Inbound: Malformed DISCONNECT packet");r._debug&&r._debug(`Inbound: Received DISCONNECT (${e}, "${n}")`);let s=r._handlers.DISCONNECT;s&&s(r,e,n)},[dt.IGNORE]:(r,t)=>{r._debug&&r._debug("Inbound: Received IGNORE")},[dt.UNIMPLEMENTED]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ut(r,"Inbound: Malformed UNIMPLEMENTED packet");r._debug&&r._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[dt.DEBUG]:(r,t)=>{R.init(t,1);let e=R.readBool(),n=R.readString(!0),i=R.readString();if(R.clear(),i===void 0)return ut(r,"Inbound: Malformed DEBUG packet");r._debug&&r._debug("Inbound: Received DEBUG");let s=r._handlers.DEBUG;s&&s(r,e,n)},[dt.SERVICE_REQUEST]:(r,t)=>{R.init(t,1);let e=R.readString(!0);if(R.clear(),e===void 0)return ut(r,"Inbound: Malformed SERVICE_REQUEST packet");r._debug&&r._debug(`Inbound: Received SERVICE_REQUEST (${e})`);let n=r._handlers.SERVICE_REQUEST;n&&n(r,e)},[dt.SERVICE_ACCEPT]:(r,t)=>{R.init(t,1);let e=R.readString(!0);if(R.clear(),e===void 0)return ut(r,"Inbound: Malformed SERVICE_ACCEPT packet");r._debug&&r._debug(`Inbound: Received SERVICE_ACCEPT (${e})`);let n=r._handlers.SERVICE_ACCEPT;n&&n(r,e)},[dt.EXT_INFO]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE(),n;if(e!==void 0){n=[];for(let s=0;s<e;++s){let o=R.readString(!0),a=R.readString();if(a!==void 0)if(o==="server-sig-algs"){let c=a.latin1Slice(0,a.length).split(",");n.push({name:o,algs:c});continue}else continue;n=void 0;break}}if(R.clear(),n===void 0)return ut(r,"Inbound: Malformed EXT_INFO packet");r._debug&&r._debug("Inbound: Received EXT_INFO");let i=r._handlers.EXT_INFO;i&&i(r,n)},[dt.USERAUTH_REQUEST]:(r,t)=>{R.init(t,1);let e=R.readString(!0),n=R.readString(!0),i=R.readString(!0),s,o;switch(i){case"none":s=null;break;case"password":{let c=R.readBool();if(c!==void 0&&(s=R.readString(!0),s!==void 0&&c)){let f=R.readString(!0);f!==void 0?s={oldPassword:s,newPassword:f}:s=void 0}break}case"publickey":{let c=R.readBool();if(c!==void 0){let f=R.readString(!0),l=f,u=R.readString(),h;switch(f){case"rsa-sha2-256":l="ssh-rsa",h="sha256";break;case"rsa-sha2-512":l="ssh-rsa",h="sha512";break}if(c){let g=R.pos(),b=R.readString();if(b!==void 0&&(b.length>4+f.length+4&&b.utf8Slice(4,4+f.length)===f&&(b=Ho(b,4+f.length+4)),b=Ol(b,l),b)){let _=r._kex.sessionID,x=Buffer.allocUnsafe(4+_.length+g);Ml(x,_.length,0),x.set(_,4),x.set(new Uint8Array(t.buffer,t.byteOffset,g),4+_.length),s={keyAlgo:l,key:u,signature:b,blob:x,hashAlgo:h}}}else s={keyAlgo:l,key:u,hashAlgo:h},o="publickey -- check"}break}case"hostbased":{let c=R.readString(!0),f=c,l=R.readString(),u=R.readString(!0),h=R.readString(!0),g;switch(c){case"rsa-sha2-256":f="ssh-rsa",g="sha256";break;case"rsa-sha2-512":f="ssh-rsa",g="sha512";break}let b=R.pos(),_=R.readString();if(_!==void 0&&(_.length>4+c.length+4&&_.utf8Slice(4,4+c.length)===c&&(_=Ho(_,4+c.length+4)),_=Ol(_,f),_!==void 0)){let x=r._kex.sessionID,S=Buffer.allocUnsafe(4+x.length+b);Ml(S,x.length,0),S.set(x,4),S.set(new Uint8Array(t.buffer,t.byteOffset,b),4+x.length),s={keyAlgo:f,key:l,signature:_,blob:S,localHostname:u,localUsername:h,hashAlgo:g}}break}case"keyboard-interactive":R.skipString(),s=R.readList();break;default:i!==void 0&&(s=R.readRaw())}if(R.clear(),s===void 0)return ut(r,"Inbound: Malformed USERAUTH_REQUEST packet");o===void 0&&(o=i),r._authsQueue.push(i),r._debug&&r._debug(`Inbound: Received USERAUTH_REQUEST (${o})`);let a=r._handlers.USERAUTH_REQUEST;a&&a(r,e,n,i,s)},[dt.USERAUTH_FAILURE]:(r,t)=>{R.init(t,1);let e=R.readList(),n=R.readBool();if(R.clear(),n===void 0)return ut(r,"Inbound: Malformed USERAUTH_FAILURE packet");r._debug&&r._debug(`Inbound: Received USERAUTH_FAILURE (${e})`),r._authsQueue.shift();let i=r._handlers.USERAUTH_FAILURE;i&&i(r,e,n)},[dt.USERAUTH_SUCCESS]:(r,t)=>{r._debug&&r._debug("Inbound: Received USERAUTH_SUCCESS"),r._authsQueue.shift();let e=r._handlers.USERAUTH_SUCCESS;e&&e(r)},[dt.USERAUTH_BANNER]:(r,t)=>{R.init(t,1);let e=R.readString(!0),n=R.readString();if(R.clear(),n===void 0)return ut(r,"Inbound: Malformed USERAUTH_BANNER packet");r._debug&&r._debug("Inbound: Received USERAUTH_BANNER");let i=r._handlers.USERAUTH_BANNER;i&&i(r,e)},60:(r,t)=>{if(!r._authsQueue.length){r._debug&&r._debug("Inbound: Received payload type 60 without auth");return}switch(r._authsQueue[0]){case"password":{R.init(t,1);let e=R.readString(!0),n=R.readString();if(R.clear(),n===void 0)return ut(r,"Inbound: Malformed USERAUTH_PASSWD_CHANGEREQ packet");r._debug&&r._debug("Inbound: Received USERAUTH_PASSWD_CHANGEREQ");let i=r._handlers.USERAUTH_PASSWD_CHANGEREQ;i&&i(r,e);break}case"publickey":{R.init(t,1);let e=R.readString(!0),n=R.readString();if(R.clear(),n===void 0)return ut(r,"Inbound: Malformed USERAUTH_PK_OK packet");r._debug&&r._debug("Inbound: Received USERAUTH_PK_OK"),r._authsQueue.shift();let i=r._handlers.USERAUTH_PK_OK;i&&i(r,e,n);break}case"keyboard-interactive":{R.init(t,1);let e=R.readString(!0),n=R.readString(!0);R.readString();let i=R.readUInt32BE(),s;if(i!==void 0){s=new Array(i);let a;for(a=0;a<i;++a){let c=R.readString(!0),f=R.readBool();if(f===void 0)break;s[a]={prompt:c,echo:f}}a!==i&&(s=void 0)}if(R.clear(),s===void 0)return ut(r,"Inbound: Malformed USERAUTH_INFO_REQUEST packet");r._debug&&r._debug("Inbound: Received USERAUTH_INFO_REQUEST");let o=r._handlers.USERAUTH_INFO_REQUEST;o&&o(r,e,n,s);break}default:r._debug&&r._debug("Inbound: Received unexpected payload type 60")}},61:(r,t)=>{if(!r._authsQueue.length){r._debug&&r._debug("Inbound: Received payload type 61 without auth");return}if(r._authsQueue[0]!=="keyboard-interactive")return ut(r,"Inbound: Received unexpected payload type 61");R.init(t,1);let e=R.readUInt32BE(),n;if(e!==void 0){n=new Array(e);let s;for(s=0;s<e;++s){let o=R.readString(!0);if(o===void 0)break;n[s]=o}s!==e&&(n=void 0)}if(R.clear(),n===void 0)return ut(r,"Inbound: Malformed USERAUTH_INFO_RESPONSE packet");r._debug&&r._debug("Inbound: Received USERAUTH_INFO_RESPONSE");let i=r._handlers.USERAUTH_INFO_RESPONSE;i&&i(r,n)},[dt.GLOBAL_REQUEST]:(r,t)=>{R.init(t,1);let e=R.readString(!0),n=R.readBool(),i;if(n!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=R.readString(!0),a=R.readUInt32BE();a!==void 0&&(i={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=R.readString(!0);o!==void 0&&(i={socketPath:o});break}case"no-more-sessions@openssh.com":i=null;break;case"hostkeys-00@openssh.com":{for(i=[];R.avail()>0;){let o=R.readString();if(o===void 0){i=void 0;break}let a=$p(o);a instanceof Error||i.push(a)}break}default:i=R.readRaw()}if(R.clear(),i===void 0)return ut(r,"Inbound: Malformed GLOBAL_REQUEST packet");r._debug&&r._debug(`Inbound: GLOBAL_REQUEST (${e})`);let s=r._handlers.GLOBAL_REQUEST;s?s(r,e,n,i):r.requestFailure()},[dt.REQUEST_SUCCESS]:(r,t)=>{let e=t.length>1?Ho(t,1):null;r._debug&&r._debug("Inbound: REQUEST_SUCCESS");let n=r._handlers.REQUEST_SUCCESS;n&&n(r,e)},[dt.REQUEST_FAILURE]:(r,t)=>{r._debug&&r._debug("Inbound: Received REQUEST_FAILURE");let e=r._handlers.REQUEST_FAILURE;e&&e(r)},[dt.CHANNEL_OPEN]:(r,t)=>{R.init(t,1);let e=R.readString(!0),n=R.readUInt32BE(),i=R.readUInt32BE(),s=R.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=R.readString(!0),f=R.readUInt32BE(),l=R.readString(!0),u=R.readUInt32BE();u!==void 0&&(o={type:e,sender:n,window:i,packetSize:s,data:{destIP:c,destPort:f,srcIP:l,srcPort:u}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=R.readString(!0);c!==void 0&&(o={type:e,sender:n,window:i,packetSize:s,data:{socketPath:c}});break}case"x11":{let c=R.readString(!0),f=R.readUInt32BE();f!==void 0&&(o={type:e,sender:n,window:i,packetSize:s,data:{srcIP:c,srcPort:f}});break}default:o={type:e,sender:n,window:i,packetSize:s,data:{}}}if(R.clear(),o===void 0)return ut(r,"Inbound: Malformed CHANNEL_OPEN packet");r._debug&&r._debug(`Inbound: CHANNEL_OPEN (s:${n}, ${e})`);let a=r._handlers.CHANNEL_OPEN;a?a(r,o):r.channelOpenFail(o.sender,Mp.ADMINISTRATIVELY_PROHIBITED,"","")},[dt.CHANNEL_OPEN_CONFIRMATION]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE(),n=R.readUInt32BE(),i=R.readUInt32BE(),s=R.readUInt32BE(),o=R.avail()?R.readRaw():void 0;if(R.clear(),s===void 0)return ut(r,"Inbound: Malformed CHANNEL_OPEN_CONFIRMATION packet");r._debug&&r._debug(`Inbound: CHANNEL_OPEN_CONFIRMATION (r:${e}, s:${n})`);let a=r._handlers.CHANNEL_OPEN_CONFIRMATION;a&&a(r,{recipient:e,sender:n,window:i,packetSize:s,data:o})},[dt.CHANNEL_OPEN_FAILURE]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE(),n=R.readUInt32BE(),i=R.readString(!0),s=R.readString();if(R.clear(),s===void 0)return ut(r,"Inbound: Malformed CHANNEL_OPEN_FAILURE packet");r._debug&&r._debug(`Inbound: CHANNEL_OPEN_FAILURE (r:${e})`);let o=r._handlers.CHANNEL_OPEN_FAILURE;o&&o(r,e,n,i)},[dt.CHANNEL_WINDOW_ADJUST]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE(),n=R.readUInt32BE();if(R.clear(),n===void 0)return ut(r,"Inbound: Malformed CHANNEL_WINDOW_ADJUST packet");r._debug&&r._debug(`Inbound: CHANNEL_WINDOW_ADJUST (r:${e}, ${n})`);let i=r._handlers.CHANNEL_WINDOW_ADJUST;i&&i(r,e,n)},[dt.CHANNEL_DATA]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE(),n=R.readString();if(R.clear(),n===void 0)return ut(r,"Inbound: Malformed CHANNEL_DATA packet");r._debug&&r._debug(`Inbound: CHANNEL_DATA (r:${e}, ${n.length})`);let i=r._handlers.CHANNEL_DATA;i&&i(r,e,n)},[dt.CHANNEL_EXTENDED_DATA]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE(),n=R.readUInt32BE(),i=R.readString();if(R.clear(),i===void 0)return ut(r,"Inbound: Malformed CHANNEL_EXTENDED_DATA packet");r._debug&&r._debug(`Inbound: CHANNEL_EXTENDED_DATA (r:${e}, ${i.length})`);let s=r._handlers.CHANNEL_EXTENDED_DATA;s&&s(r,e,i,n)},[dt.CHANNEL_EOF]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ut(r,"Inbound: Malformed CHANNEL_EOF packet");r._debug&&r._debug(`Inbound: CHANNEL_EOF (r:${e})`);let n=r._handlers.CHANNEL_EOF;n&&n(r,e)},[dt.CHANNEL_CLOSE]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ut(r,"Inbound: Malformed CHANNEL_CLOSE packet");r._debug&&r._debug(`Inbound: CHANNEL_CLOSE (r:${e})`);let n=r._handlers.CHANNEL_CLOSE;n&&n(r,e)},[dt.CHANNEL_REQUEST]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE(),n=R.readString(!0),i=R.readBool(),s;if(i!==void 0)switch(n){case"exit-status":s=R.readUInt32BE(),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n}: ${s})`);break;case"exit-signal":{let a,c;if(r._compatFlags&Fp.OLD_EXIT){let l=R.readUInt32BE();switch(l){case 1:a="HUP";break;case 2:a="INT";break;case 3:a="QUIT";break;case 6:a="ABRT";break;case 9:a="KILL";break;case 14:a="ALRM";break;case 15:a="TERM";break;default:l!==void 0&&(a=`UNKNOWN (${l})`)}c=!1}else a=R.readString(!0),c=R.readBool(),c===void 0&&(a=void 0);let f=R.readString(!0);R.skipString()!==void 0&&(s={signal:a,coreDumped:c,errorMessage:f}),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n}: ${a})`);break}case"pty-req":{let a=R.readString(!0),c=R.readUInt32BE(),f=R.readUInt32BE(),l=R.readUInt32BE(),u=R.readUInt32BE(),h=R.readString();if(h!==void 0){R.init(h,1);let g={};for(;R.avail();){let b=R.readByte();if(b===Fl.TTY_OP_END)break;let _=Hp[b],x=R.readUInt32BE();if(b===void 0||_===void 0||x===void 0){g=void 0;break}g[_]=x}g!==void 0&&(s={term:a,cols:c,rows:f,width:l,height:u,modes:g})}r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n})`);break}case"window-change":{let a=R.readUInt32BE(),c=R.readUInt32BE(),f=R.readUInt32BE(),l=R.readUInt32BE();l!==void 0&&(s={cols:a,rows:c,width:f,height:l}),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n})`);break}case"x11-req":{let a=R.readBool(),c=R.readString(!0),f=R.readString(),l=R.readUInt32BE();l!==void 0&&(s={single:a,protocol:c,cookie:f,screen:l}),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n})`);break}case"env":{let a=R.readString(!0),c=R.readString(!0);c!==void 0&&(s={name:a,value:c}),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n}: ${a}=${c})`);break}case"shell":s=null,r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n})`);break;case"exec":s=R.readString(!0),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n}: ${s})`);break;case"subsystem":s=R.readString(!0),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n}: ${s})`);break;case"signal":s=R.readString(!0),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n}: ${s})`);break;case"xon-xoff":s=R.readBool(),r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n}: ${s})`);break;case"auth-agent-req@openssh.com":s=null,r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n})`);break;default:s=R.avail()?R.readRaw():null,r._debug&&r._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${n})`)}if(R.clear(),s===void 0)return ut(r,"Inbound: Malformed CHANNEL_REQUEST packet");let o=r._handlers.CHANNEL_REQUEST;o&&o(r,e,n,i,s)},[dt.CHANNEL_SUCCESS]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ut(r,"Inbound: Malformed CHANNEL_SUCCESS packet");r._debug&&r._debug(`Inbound: CHANNEL_SUCCESS (r:${e})`);let n=r._handlers.CHANNEL_SUCCESS;n&&n(r,e)},[dt.CHANNEL_FAILURE]:(r,t)=>{R.init(t,1);let e=R.readUInt32BE();if(R.clear(),e===void 0)return ut(r,"Inbound: Malformed CHANNEL_FAILURE packet");r._debug&&r._debug(`Inbound: CHANNEL_FAILURE (r:${e})`);let n=r._handlers.CHANNEL_FAILURE;n&&n(r,e)}}});var rs=ot((My,Ql)=>{"use strict";var Qo=new Array(256);[ns().HANDLERS,Hl()].forEach(r=>{for(let[t,e]of Object.entries(r))t=+t,isFinite(t)&&t>=0&&t<Qo.length&&(Qo[t]=e)});Ql.exports=Qo});var ns=ot(($y,Jl)=>{"use strict";var{createDiffieHellman:Qp,createDiffieHellmanGroup:Wp,createECDH:qp,createHash:qo,createPublicKey:Kp,diffieHellman:Vp,generateKeyPairSync:Gp,randomFillSync:Yp}=require("crypto"),{Ber:Wl}=Kn(),{COMPAT:Ko,curve25519Supported:jp,DEFAULT_KEX:ql,DEFAULT_SERVER_HOST_KEY:Kl,DEFAULT_CIPHER:is,DEFAULT_MAC:ss,DEFAULT_COMPRESSION:os,DISCONNECT_REASON:Ve,MESSAGE:ft}=xr(),{CIPHER_INFO:Sn,createCipher:zp,createDecipher:Xp,MAC_INFO:Vl}=Nr(),{parseDERKey:Jp}=Lr(),{bufferFill:Zp,bufferParser:Ke,convertSignature:eg,doFatalError:Ge,FastBuffer:tg,sigSSHToASN1:rg,writeUInt32BE:Pt}=or(),{PacketReader:Gl,PacketWriter:Yl,ZlibPacketReader:as,ZlibPacketWriter:cs}=$o(),yn,ng=2048,ig=8192,sg=Buffer.alloc(0);function jl(r){let t;if(r._compatFlags&Ko.BAD_DHGEX){let e=r._offer.lists.kex,n=e.array,i=!1;for(let s=0;s<n.length;++s)n[s].includes("group-exchange")&&(i||(i=!0,n=n.slice()),n.splice(s--,1));if(i){let s=17+r._offer.totalSize+1+4,o=Buffer.from(n.join(","));s-=e.buffer.length-o.length;let a=r._offer.lists.all,c=new Uint8Array(a.buffer,a.byteOffset+4+e.buffer.length,a.length-(4+e.buffer.length));t=Buffer.allocUnsafe(s),Pt(t,o.length,17),t.set(o,21),t.set(c,21+o.length)}}t===void 0&&(t=Buffer.allocUnsafe(17+r._offer.totalSize+1+4),r._offer.copyAllTo(t,17)),r._debug&&r._debug("Outbound: Sending KEXINIT"),t[0]=ft.KEXINIT,Yp(t,1,16),Zp(t,0,t.length-5),r._kexinit=t,r._packetRW.write.allocStart=0;{let e=r._packetRW.write.allocStartKEX,n=r._packetRW.write.alloc(t.length,!0);n.set(t,e),r._cipher.encrypt(r._packetRW.write.finalize(n,!0))}}function zl(r,t){let e={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0}};if(Ke.init(t,17),(e.kex=Ke.readList())===void 0||(e.serverHostKey=Ke.readList())===void 0||(e.cs.cipher=Ke.readList())===void 0||(e.sc.cipher=Ke.readList())===void 0||(e.cs.mac=Ke.readList())===void 0||(e.sc.mac=Ke.readList())===void 0||(e.cs.compress=Ke.readList())===void 0||(e.sc.compress=Ke.readList())===void 0||(e.cs.lang=Ke.readList())===void 0||(e.sc.lang=Ke.readList())===void 0)return Ke.clear(),Ge(r,"Received malformed KEXINIT","handshake",Ve.KEY_EXCHANGE_FAILED);let n=Ke.pos(),i=n<t.length&&t[n]===1;Ke.clear();let s=r._offer,o=e,a=s.lists.kex.array;if(r._compatFlags&Ko.BAD_DHGEX){let P=!1;for(let W=0;W<a.length;++W)a[W].indexOf("group-exchange")!==-1&&(P||(P=!0,a=a.slice()),a.splice(W--,1))}let c,f,l,u=r._debug;u&&u("Inbound: Handshake in progress"),u&&u(`Handshake: (local) KEX method: ${a}`),u&&u(`Handshake: (remote) KEX method: ${o.kex}`);let h;if(r._server?(f=a,c=o.kex,h=c.indexOf("ext-info-c")!==-1):(f=o.kex,c=a,h=f.indexOf("ext-info-s")!==-1),r._strictMode===void 0&&(r._server?r._strictMode=c.indexOf("kex-strict-c-v00@openssh.com")!==-1:r._strictMode=f.indexOf("kex-strict-s-v00@openssh.com")!==-1,r._strictMode&&(u&&u("Handshake: strict KEX mode enabled"),r._decipher.inSeqno!==1)))return u&&u("Handshake: KEXINIT not first packet in strict KEX mode"),Ge(r,"Handshake failed: KEXINIT not first packet in strict KEX mode","handshake",Ve.KEY_EXCHANGE_FAILED);for(l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: no matching key exchange algorithm"),Ge(r,"Handshake failed: no matching key exchange algorithm","handshake",Ve.KEY_EXCHANGE_FAILED);e.kex=c[l],u&&u(`Handshake: KEX algorithm: ${c[l]}`),i&&(!o.kex.length||c[l]!==o.kex[0])&&(r._skipNextInboundPacket=!0);let g=s.lists.serverHostKey.array;for(u&&u(`Handshake: (local) Host key format: ${g}`),u&&u(`Handshake: (remote) Host key format: ${o.serverHostKey}`),r._server?(f=g,c=o.serverHostKey):(f=o.serverHostKey,c=g),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching host key format"),Ge(r,"Handshake failed: no matching host key format","handshake",Ve.KEY_EXCHANGE_FAILED);e.serverHostKey=c[l],u&&u(`Handshake: Host key format: ${c[l]}`);let b=s.lists.cs.cipher.array;for(u&&u(`Handshake: (local) C->S cipher: ${b}`),u&&u(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),r._server?(f=b,c=o.cs.cipher):(f=o.cs.cipher,c=b),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S cipher"),Ge(r,"Handshake failed: no matching C->S cipher","handshake",Ve.KEY_EXCHANGE_FAILED);e.cs.cipher=c[l],u&&u(`Handshake: C->S Cipher: ${c[l]}`);let _=s.lists.sc.cipher.array;for(u&&u(`Handshake: (local) S->C cipher: ${_}`),u&&u(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),r._server?(f=_,c=o.sc.cipher):(f=o.sc.cipher,c=_),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C cipher"),Ge(r,"Handshake failed: no matching S->C cipher","handshake",Ve.KEY_EXCHANGE_FAILED);e.sc.cipher=c[l],u&&u(`Handshake: S->C cipher: ${c[l]}`);let x=s.lists.cs.mac.array;if(u&&u(`Handshake: (local) C->S MAC: ${x}`),u&&u(`Handshake: (remote) C->S MAC: ${o.cs.mac}`),Sn[e.cs.cipher].authLen>0)e.cs.mac="",u&&u("Handshake: C->S MAC: <implicit>");else{for(r._server?(f=x,c=o.cs.mac):(f=o.cs.mac,c=x),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S MAC"),Ge(r,"Handshake failed: no matching C->S MAC","handshake",Ve.KEY_EXCHANGE_FAILED);e.cs.mac=c[l],u&&u(`Handshake: C->S MAC: ${c[l]}`)}let S=s.lists.sc.mac.array;if(u&&u(`Handshake: (local) S->C MAC: ${S}`),u&&u(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),Sn[e.sc.cipher].authLen>0)e.sc.mac="",u&&u("Handshake: S->C MAC: <implicit>");else{for(r._server?(f=S,c=o.sc.mac):(f=o.sc.mac,c=S),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C MAC"),Ge(r,"Handshake failed: no matching S->C MAC","handshake",Ve.KEY_EXCHANGE_FAILED);e.sc.mac=c[l],u&&u(`Handshake: S->C MAC: ${c[l]}`)}let N=s.lists.cs.compress.array;for(u&&u(`Handshake: (local) C->S compression: ${N}`),u&&u(`Handshake: (remote) C->S compression: ${o.cs.compress}`),r._server?(f=N,c=o.cs.compress):(f=o.cs.compress,c=N),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S compression"),Ge(r,"Handshake failed: no matching C->S compression","handshake",Ve.KEY_EXCHANGE_FAILED);e.cs.compress=c[l],u&&u(`Handshake: C->S compression: ${c[l]}`);let O=s.lists.sc.compress.array;for(u&&u(`Handshake: (local) S->C compression: ${O}`),u&&u(`Handshake: (remote) S->C compression: ${o.sc.compress}`),r._server?(f=O,c=o.sc.compress):(f=o.sc.compress,c=O),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C compression"),Ge(r,"Handshake failed: no matching S->C compression","handshake",Ve.KEY_EXCHANGE_FAILED);e.sc.compress=c[l],u&&u(`Handshake: S->C compression: ${c[l]}`),e.cs.lang="",e.sc.lang="",r._kex&&(r._kexinit||jl(r),r._decipher._onPayload=Xl.bind(r,{firstPacket:!1})),r._kex=og(e,r,t),r._kex.remoteExtInfoEnabled=h,r._kex.start()}var og=(()=>{function r(o){let a=0,c=o.length;for(;o[a]===0;)++a,--c;let f;return o[a]&128?(f=Buffer.allocUnsafe(1+c),f[0]=0,o.copy(f,1,a),o=f):c!==o.length&&(f=Buffer.allocUnsafe(c),o.copy(f,0,a),o=f),o}class t{constructor(a,c,f){this._protocol=c,this.sessionID=c._kex?c._kex.sessionID:void 0,this.negotiated=a,this.remoteExtInfoEnabled=!1,this._step=1,this._public=null,this._dh=null,this._sentNEWKEYS=!1,this._receivedNEWKEYS=!1,this._finished=!1,this._hostVerified=!1,this._kexinit=c._kexinit,this._remoteKexinit=f,this._identRaw=c._identRaw,this._remoteIdentRaw=c._remoteIdentRaw,this._hostKey=void 0,this._dhData=void 0,this._sig=void 0}finish(a){if(this._finished)return!1;this._finished=!0;let c=this._protocol._server,f=this.negotiated,l=this.convertPublicKey(this._dhData),u=this.computeSecret(this._dhData);if(u instanceof Error)return u.message=`Error while computing DH secret (${this.type}): ${u.message}`,u.level="handshake",Ge(this._protocol,u,Ve.KEY_EXCHANGE_FAILED);let h=qo(this.hashName);pr(h,c?this._remoteIdentRaw:this._identRaw),pr(h,c?this._identRaw:this._remoteIdentRaw),pr(h,c?this._remoteKexinit:this._kexinit),pr(h,c?this._kexinit:this._remoteKexinit);let g=c?this._hostKey.getPublicSSH():this._hostKey;if(pr(h,g),this.type==="groupex"){let O=this.getDHParams(),P=Buffer.allocUnsafe(4);Pt(P,this._minBits,0),h.update(P),Pt(P,this._prefBits,0),h.update(P),Pt(P,this._maxBits,0),h.update(P),pr(h,O.prime),pr(h,O.generator)}pr(h,c?l:this.getPublicKey());let b=c?this.getPublicKey():l;pr(h,b),pr(h,u);let _=h.digest();if(c){let O;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":O="sha256";break;case"rsa-sha2-512":O="sha512";break}this._protocol._debug&&this._protocol._debug("Generating signature ...");let P=this._hostKey.sign(_,O);if(P instanceof Error)return Ge(this._protocol,`Handshake failed: signature generation failed for ${this._hostKey.type} host key: ${P.message}`,"handshake",Ve.KEY_EXCHANGE_FAILED);if(P=eg(P,this._hostKey.type),P===!1)return Ge(this._protocol,`Handshake failed: signature conversion failed for ${this._hostKey.type} host key`,"handshake",Ve.KEY_EXCHANGE_FAILED);let W=this.negotiated.serverHostKey,X=Buffer.byteLength(W),G=4+X+4+P.length,w=this._protocol._packetRW.write.allocStartKEX,I=this._protocol._packetRW.write.alloc(5+g.length+4+b.length+4+G,!0);if(I[w]=ft.KEXDH_REPLY,Pt(I,g.length,++w),I.set(g,w+=4),Pt(I,b.length,w+=g.length),I.set(b,w+=4),Pt(I,G,w+=b.length),Pt(I,X,w+=4),I.utf8Write(W,w+=4,X),Pt(I,P.length,w+=X),I.set(P,w+=4),this._protocol._debug){let D;switch(this.type){case"group":D="KEXDH_REPLY";break;case"groupex":D="KEXDH_GEX_REPLY";break;default:D="KEXECDH_REPLY"}this._protocol._debug(`Outbound: Sending ${D}`)}this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(I,!0))}else{Ke.init(this._sig,0);let O=Ke.readString(!0);if(!O)return Ge(this._protocol,"Malformed packet while reading signature","handshake",Ve.KEY_EXCHANGE_FAILED);if(O!==f.serverHostKey)return Ge(this._protocol,`Wrong signature type: ${O}, expected: ${f.serverHostKey}`,"handshake",Ve.KEY_EXCHANGE_FAILED);let P=Ke.readString();if(Ke.clear(),P===void 0)return Ge(this._protocol,"Malformed packet while reading signature","handshake",Ve.KEY_EXCHANGE_FAILED);if(!(P=rg(P,O)))return Ge(this._protocol,"Malformed signature","handshake",Ve.KEY_EXCHANGE_FAILED);let W;{Ke.init(this._hostKey,0);let w=Ke.readString(!0),I=this._hostKey.slice(Ke.pos());if(Ke.clear(),W=Jp(I,w),W instanceof Error)return W.level="handshake",Ge(this._protocol,W,Ve.KEY_EXCHANGE_FAILED)}let X;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":X="sha256";break;case"rsa-sha2-512":X="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let G=W.verify(_,P,X);if(G!==!0)return G instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${G.stack}`):this._protocol._debug&&this._protocol._debug("Signature verification failed"),Ge(this._protocol,"Handshake failed: signature verification failed","handshake",Ve.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Verified signature")}(c||!a)&&fs(this);let x,S,N=O=>{if(x)return fs(this),x.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=zp(x),this._protocol._packetRW.write=S,x=void 0,S=void 0,this._protocol._onHandshakeComplete(f),!1;this.sessionID||(this.sessionID=_);{let re=Buffer.allocUnsafe(4+u.length);Pt(re,u.length,0),re.set(u,4),u=re}let P=Sn[f.cs.cipher],W=Sn[f.sc.cipher],X=xn(P.ivLen,this.hashName,u,_,this.sessionID,"A"),G=xn(W.ivLen,this.hashName,u,_,this.sessionID,"B"),w=xn(P.keyLen,this.hashName,u,_,this.sessionID,"C"),I=xn(W.keyLen,this.hashName,u,_,this.sessionID,"D"),D,q;P.authLen||(D=Vl[f.cs.mac],q=xn(D.len,this.hashName,u,_,this.sessionID,"E"));let Q,ae;W.authLen||(Q=Vl[f.sc.mac],ae=xn(Q.len,this.hashName,u,_,this.sessionID,"F"));let te={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?P:W,decipherIV:c?X:G,decipherKey:c?w:I,macInfo:c?D:Q,macKey:c?q:ae},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?W:P,cipherIV:c?G:X,cipherKey:c?I:w,macInfo:c?Q:D,macKey:c?ae:q}};this._protocol._decipher.free(),x=te,this._protocol._decipher=Xp(te);let Z={read:void 0,write:void 0};switch(f.cs.compress){case"zlib":c?Z.read=new as:Z.write=new cs(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Z.read=new as:Z.write=new cs(this._protocol);break}default:c?Z.read=new Gl:Z.write=new Yl(this._protocol)}switch(f.sc.compress){case"zlib":c?Z.write=new cs(this._protocol):Z.read=new as;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Z.write=new cs(this._protocol):Z.read=new as;break}default:c?Z.write=new Yl(this._protocol):Z.read=new Gl}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=Z.read,S=Z.write,this._public=null,this._dh=null,this._kexinit=this._protocol._kexinit=void 0,this._remoteKexinit=void 0,this._identRaw=void 0,this._remoteIdentRaw=void 0,this._hostKey=void 0,this._dhData=void 0,this._sig=void 0,O?!1:N()};if((c||a)&&(this.finish=N),!c)return N(a)}start(){if(!this._protocol._server){if(this._protocol._debug){let l;this.type==="group"?l="KEXDH_INIT":l="KEXECDH_INIT",this._protocol._debug(`Outbound: Sending ${l}`)}let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,f=this._protocol._packetRW.write.alloc(5+a.length,!0);f[c]=ft.KEXDH_INIT,Pt(f,a.length,++c),f.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(f,!0))}}getPublicKey(){this.generateKeys();let a=this._public;if(a)return this.convertPublicKey(a)}convertPublicKey(a){let c,f=0,l=a.length;for(;a[f]===0;)++f,--l;return a[f]&128?(c=Buffer.allocUnsafe(1+l),c[0]=0,a.copy(c,1,f),c):(l!==a.length&&(c=Buffer.allocUnsafe(l),a.copy(c,0,f),a=c),a)}computeSecret(a){this.generateKeys();try{return r(this._dh.computeSecret(a))}catch(c){return c}}parse(a){let c=a[0];switch(this._step){case 1:if(this._protocol._server){if(c!==ft.KEXDH_INIT)return Ge(this._protocol,`Received packet ${c} instead of ${ft.KEXDH_INIT}`,"handshake",Ve.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Init"),Ke.init(a,1);let f=Ke.readString();if(Ke.clear(),f===void 0)return Ge(this._protocol,"Received malformed KEX*_INIT","handshake",Ve.KEY_EXCHANGE_FAILED);this._dhData=f;let l=this._protocol._hostKeys[this.negotiated.serverHostKey];Array.isArray(l)&&(l=l[0]),this._hostKey=l,this.finish()}else{if(c!==ft.KEXDH_REPLY)return Ge(this._protocol,`Received packet ${c} instead of ${ft.KEXDH_REPLY}`,"handshake",Ve.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ke.init(a,1);let f,l,u;if((f=Ke.readString())===void 0||(l=Ke.readString())===void 0||(u=Ke.readString())===void 0)return Ke.clear(),Ge(this._protocol,"Received malformed KEX*_REPLY","handshake",Ve.KEY_EXCHANGE_FAILED);Ke.clear(),Ke.init(f,0);let h=Ke.readString(!0);if(Ke.clear(),h===void 0)return Ge(this._protocol,"Received malformed host public key","handshake",Ve.KEY_EXCHANGE_FAILED);if(h!==this.negotiated.serverHostKey)switch(this.negotiated.serverHostKey){case"rsa-sha2-256":case"rsa-sha2-512":if(h==="ssh-rsa")break;default:return Ge(this._protocol,"Host key does not match negotiated type","handshake",Ve.KEY_EXCHANGE_FAILED)}this._hostKey=f,this._dhData=l,this._sig=u;let g=!1,b;if(this._protocol._hostVerifier===void 0?(b=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):b=this._protocol._hostVerifier(f,_=>{if(!g){if(g=!0,_===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ge(this._protocol,"Host denied (verification failed)","handshake",Ve.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,this._receivedNEWKEYS?this.finish():fs(this)}}),b===void 0){++this._step;return}if(g=!0,b===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ge(this._protocol,"Host denied (verification failed)","handshake",Ve.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,fs(this)}++this._step;break;case 2:return c!==ft.NEWKEYS?Ge(this._protocol,`Received packet ${c} instead of ${ft.NEWKEYS}`,"handshake",Ve.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Inbound: NEWKEYS"),this._receivedNEWKEYS=!0,this._protocol._strictMode&&(this._protocol._decipher.inSeqno=0),++this._step,this.finish(!this._protocol._server&&!this._hostVerified));default:return Ge(this._protocol,`Received unexpected packet ${c} after NEWKEYS`,"handshake",Ve.KEY_EXCHANGE_FAILED)}}}class e extends t{constructor(a,...c){super(...c),this.type="25519",this.hashName=a,this._keys=null}generateKeys(){this._keys||(this._keys=Gp("x25519"))}getPublicKey(){return this.generateKeys(),this._keys.publicKey.export({type:"spki",format:"der"}).slice(-32)}convertPublicKey(a){let c,f=0,l=a.length;for(;a[f]===0;)++f,--l;return a.length===32||l!==a.length&&(c=Buffer.allocUnsafe(l),a.copy(c,0,f),a=c),a}computeSecret(a){this.generateKeys();try{let c=new Wl.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(Wl.BitString),c.writeByte(0),c._ensure(a.length),a.copy(c._buf,c._offset,0,a.length),c._offset+=a.length,c.endSequence(),c.endSequence(),r(Vp({privateKey:this._keys.privateKey,publicKey:Kp({key:c.buffer,type:"spki",format:"der"})}))}catch(c){return c}}}class n extends t{constructor(a,c,...f){super(...f),this.type="ecdh",this.curveName=a,this.hashName=c}generateKeys(){this._dh||(this._dh=qp(this.curveName),this._public=this._dh.generateKeys())}}class i extends t{constructor(a,...c){super(...c),this.type="groupex",this.hashName=a,this._prime=null,this._generator=null,this._minBits=ng,this._prefBits=ag(this.negotiated),this._protocol._compatFlags&Ko.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=ig}start(){if(this._protocol._server)return;this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_REQUEST");let a=this._protocol._packetRW.write.allocStartKEX,c=this._protocol._packetRW.write.alloc(13,!0);c[a]=ft.KEXDH_GEX_REQUEST,Pt(c,this._minBits,++a),Pt(c,this._prefBits,a+=4),Pt(c,this._maxBits,a+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(c,!0))}generateKeys(){!this._dh&&this._prime&&this._generator&&(this._dh=Qp(this._prime,this._generator),this._public=this._dh.generateKeys())}setDHParams(a,c){if(!Buffer.isBuffer(a))throw new Error("Invalid prime value");if(!Buffer.isBuffer(c))throw new Error("Invalid generator value");this._prime=a,this._generator=c}getDHParams(){if(this._dh)return{prime:r(this._dh.getPrime()),generator:r(this._dh.getGenerator())}}parse(a){let c=a[0];switch(this._step){case 1:{if(this._protocol._server)return c!==ft.KEXDH_GEX_REQUEST?Ge(this._protocol,`Received packet ${c} instead of `+ft.KEXDH_GEX_REQUEST,"handshake",Ve.KEY_EXCHANGE_FAILED):Ge(this._protocol,"Group exchange not implemented for server","handshake",Ve.KEY_EXCHANGE_FAILED);if(c!==ft.KEXDH_GEX_GROUP)return Ge(this._protocol,`Received packet ${c} instead of ${ft.KEXDH_GEX_GROUP}`,"handshake",Ve.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ke.init(a,1);let f,l;if((f=Ke.readString())===void 0||(l=Ke.readString())===void 0)return Ke.clear(),Ge(this._protocol,"Received malformed KEXDH_GEX_GROUP","handshake",Ve.KEY_EXCHANGE_FAILED);Ke.clear(),this.setDHParams(f,l),this.generateKeys();let u=this.getPublicKey();this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_INIT");let h=this._protocol._packetRW.write.allocStartKEX,g=this._protocol._packetRW.write.alloc(5+u.length,!0);g[h]=ft.KEXDH_GEX_INIT,Pt(g,u.length,++h),g.set(u,h+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(g,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==ft.KEXDH_GEX_INIT?Ge(this._protocol,`Received packet ${c} instead of ${ft.KEXDH_GEX_INIT}`,"handshake",Ve.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Received DH GEX Init"),Ge(this._protocol,"Group exchange not implemented for server","handshake",Ve.KEY_EXCHANGE_FAILED));if(c!==ft.KEXDH_GEX_REPLY)return Ge(this._protocol,`Received packet ${c} instead of ${ft.KEXDH_GEX_REPLY}`,"handshake",Ve.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=ft.KEXDH_REPLY,this.parse=t.prototype.parse,this.parse(a)}}}class s extends t{constructor(a,c,...f){super(...f),this.type="group",this.groupName=a,this.hashName=c}start(){if(!this._protocol._server){this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_INIT");let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,f=this._protocol._packetRW.write.alloc(5+a.length,!0);f[c]=ft.KEXDH_INIT,Pt(f,a.length,++c),f.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(f,!0))}}generateKeys(){this._dh||(this._dh=Wp(this.groupName),this._public=this._dh.generateKeys())}getDHParams(){if(this._dh)return{prime:r(this._dh.getPrime()),generator:r(this._dh.getGenerator())}}}return(o,...a)=>{if(typeof o!="object"||o===null)throw new Error("Invalid negotiated argument");let c=o.kex;if(typeof c=="string"){switch(a=[o,...a],c){case"curve25519-sha256":case"curve25519-sha256@libssh.org":if(!jp)break;return new e("sha256",...a);case"ecdh-sha2-nistp256":return new n("prime256v1","sha256",...a);case"ecdh-sha2-nistp384":return new n("secp384r1","sha384",...a);case"ecdh-sha2-nistp521":return new n("secp521r1","sha512",...a);case"diffie-hellman-group1-sha1":return new s("modp2","sha1",...a);case"diffie-hellman-group14-sha1":return new s("modp14","sha1",...a);case"diffie-hellman-group14-sha256":return new s("modp14","sha256",...a);case"diffie-hellman-group15-sha512":return new s("modp15","sha512",...a);case"diffie-hellman-group16-sha512":return new s("modp16","sha512",...a);case"diffie-hellman-group17-sha512":return new s("modp17","sha512",...a);case"diffie-hellman-group18-sha512":return new s("modp18","sha512",...a);case"diffie-hellman-group-exchange-sha1":return new i("sha1",...a);case"diffie-hellman-group-exchange-sha256":return new i("sha256",...a)}throw new Error(`Unsupported key exchange algorithm: ${c}`)}throw new Error(`Invalid key exchange type: ${c}`)}})(),Wo=(()=>{let r=["kex","serverHostKey",["cs","cipher"],["sc","cipher"],["cs","mac"],["sc","mac"],["cs","compress"],["sc","compress"],["cs","lang"],["sc","lang"]];return class{constructor(e){if(typeof e!="object"||e===null)throw new TypeError("Argument must be an object");let n={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},all:void 0},i=0;for(let a of r){let c,f,l,u;if(typeof a=="string")c=n,f=e[a],l=u=a;else{let g=a[0];c=n[g],u=a[1],f=e[g][u],l=`${g}.${u}`}let h={array:void 0,buffer:void 0};if(Buffer.isBuffer(f))h.array=(""+f).split(","),h.buffer=f,i+=4+f.length;else{if(typeof f=="string"&&(f=f.split(",")),Array.isArray(f))h.array=f,h.buffer=Buffer.from(f.join(","));else throw new TypeError(`Invalid \`${l}\` type: ${typeof f}`);i+=4+h.buffer.length}c[u]=h}let s=Buffer.allocUnsafe(i);n.all=s;let o=0;for(let a of r){let c;typeof a=="string"?c=n[a].buffer:c=n[a[0]][a[1]].buffer,o=Pt(s,c.length,o),s.set(c,o),o+=c.length}this.totalSize=i,this.lists=n}copyAllTo(e,n){let i=this.lists.all;if(typeof n!="number")throw new TypeError(`Invalid offset value: ${typeof n}`);if(e.length-n<i.length)throw new Error("Insufficient space to copy list");return e.set(i,n),i.length}}})(),pr=(()=>{let r=Buffer.allocUnsafe(4);return(t,e)=>{Pt(r,e.length,0),t.update(r),t.update(e)}})();function xn(r,t,e,n,i,s){let o;if(r){let a=qo(t).update(e).update(n).update(s).update(i).digest();for(;a.length<r;){let c=qo(t).update(e).update(n).update(a).digest(),f=Buffer.allocUnsafe(a.length+c.length);f.set(a,0),f.set(c,a.length),a=f}a.length===r?o=a:o=new tg(a.buffer,a.byteOffset,r)}else o=sg;return o}function Xl(r,t){if(t.length===0){this._debug&&this._debug("Inbound: Skipping empty packet payload");return}if(this._skipNextInboundPacket){this._skipNextInboundPacket=!1;return}t=this._packetRW.read.read(t);let e=t[0];if(!this._strictMode)switch(e){case ft.IGNORE:case ft.UNIMPLEMENTED:case ft.DEBUG:return yn||(yn=rs()),yn[e](this,t)}switch(e){case ft.DISCONNECT:return yn||(yn=rs()),yn[e](this,t);case ft.KEXINIT:return r.firstPacket?(r.firstPacket=!1,zl(this,t)):Ge(this,"Received extra KEXINIT during handshake","handshake",Ve.KEY_EXCHANGE_FAILED);default:if(e<20||e>49)return Ge(this,`Received unexpected packet type ${e}`,"handshake",Ve.KEY_EXCHANGE_FAILED)}return this._kex.parse(t)}function ag(r){let t=Sn[r.cs.cipher],e=Sn[r.sc.cipher],n=Math.max(0,t.sslName==="des-ede3-cbc"?14:t.keyLen,t.blockLen,t.ivLen,e.sslName==="des-ede3-cbc"?14:e.keyLen,e.blockLen,e.ivLen)*8;return n<=112?2048:n<=128?3072:n<=192?7680:8192}function fs(r){if(!r._sentNEWKEYS){r._protocol._debug&&r._protocol._debug("Outbound: Sending NEWKEYS");let t=r._protocol._packetRW.write.allocStartKEX,e=r._protocol._packetRW.write.alloc(1,!0);e[t]=ft.NEWKEYS,r._protocol._cipher.encrypt(r._protocol._packetRW.write.finalize(e,!0)),r._sentNEWKEYS=!0,r._protocol._strictMode&&(r._protocol._cipher.outSeqno=0)}}Jl.exports={KexInit:Wo,kexinit:jl,onKEXPayload:Xl,DEFAULT_KEXINIT_CLIENT:new Wo({kex:ql.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:Kl,cs:{cipher:is,mac:ss,compress:os,lang:[]},sc:{cipher:is,mac:ss,compress:os,lang:[]}}),DEFAULT_KEXINIT_SERVER:new Wo({kex:ql.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:Kl,cs:{cipher:is,mac:ss,compress:os,lang:[]},sc:{cipher:is,mac:ss,compress:os,lang:[]}}),HANDLERS:{[ft.KEXINIT]:zl}}});var Zl=ot((Hy,cg)=>{cg.exports={name:"ssh2",version:"1.17.0",author:"Brian White <mscdex@mscdex.net>",description:"SSH2 client and server modules written in pure JavaScript for node.js",main:"./lib/index.js",engines:{node:">=10.16.0"},dependencies:{asn1:"^0.2.6","bcrypt-pbkdf":"^1.0.2"},devDependencies:{"@mscdex/eslint-config":"^1.1.0",eslint:"^7.32.0"},optionalDependencies:{"cpu-features":"~0.0.10",nan:"^2.23.0"},scripts:{install:"node install.js",rebuild:"node install.js",test:"node test/test.js",lint:"eslint --cache --report-unused-disable-directives --ext=.js .eslintrc.js examples lib test","lint:fix":"npm run lint -- --fix"},keywords:["ssh","ssh2","sftp","secure","shell","exec","remote","client"],licenses:[{type:"MIT",url:"http://github.com/mscdex/ssh2/raw/master/LICENSE"}],repository:{type:"git",url:"http://github.com/mscdex/ssh2.git"}}});var jo=ot((Qy,du)=>{"use strict";var{inspect:su}=require("util"),{bindingAvailable:fg,NullCipher:lg,NullDecipher:ug}=Nr(),{COMPAT_CHECKS:dg,DISCONNECT_REASON:ou,eddsaSupported:hg,MESSAGE:ye,SIGNALS:eu,TERMINAL_MODE:Go}=xr(),{DEFAULT_KEXINIT_CLIENT:pg,DEFAULT_KEXINIT_SERVER:gg,KexInit:tu,kexinit:au,onKEXPayload:mg}=ns(),{parseKey:ru}=Lr(),Ag=rs(),{bufferCopy:ls,bufferFill:Eg,bufferSlice:cu,convertSignature:nu,sendPacket:xe,writeUInt32BE:v}=or(),{PacketReader:_g,PacketWriter:bg,ZlibPacketReader:fu,ZlibPacketWriter:lu}=$o(),yg=Zl().version,xg=new Map(Object.values(ou).map(r=>[r,1])),uu=Buffer.from(`SSH-2.0-ssh2js${yg}`),Sg=Buffer.from(`${uu}\r
7
+ `),wg=8192,Ig=1024,iu=Buffer.from([ye.GLOBAL_REQUEST,0,0,0,21,107,101,101,112,97,108,105,118,101,64,111,112,101,110,115,115,104,46,99,111,109,1]),Cg=Buffer.from([Go.TTY_OP_END]);function Vo(){}var Yo=class{constructor(t){let e=t.onWrite;if(typeof e!="function")throw new Error("Missing onWrite function");this._onWrite=g=>{e(g)};let n=t.onError;if(typeof n!="function")throw new Error("Missing onError function");this._onError=g=>{n(g)};let i=t.debug;this._debug=typeof i=="function"?g=>{i(g)}:void 0;let s=t.onHeader;this._onHeader=typeof s=="function"?(...g)=>{s(...g)}:Vo;let o=t.onPacket;this._onPacket=typeof o=="function"?()=>{o()}:Vo;let a=t.onHandshakeComplete;typeof a!="function"&&(a=Vo);let c;this._onHandshakeComplete=(...g)=>{this._debug&&this._debug("Handshake completed"),c===void 0?c=!0:c=!1;let b=this._queue;if(b){this._queue=void 0,this._debug&&this._debug(`Draining outbound queue (${b.length}) ...`);for(let _=0;_<b.length;++_){let x=b[_],S=this._packetRW.write.finalize(x);if(S===x){let N=this._cipher.allocPacket(x.length);N.set(x,5),S=N}xe(this,S)}this._debug&&this._debug("... finished draining outbound queue")}c&&this._server&&this._kex.remoteExtInfoEnabled&&Tg(this),a(...g)},this._queue=void 0;let f=t.messageHandlers;typeof f=="object"&&f!==null?this._handlers=f:this._handlers={},this._onPayload=Rg.bind(this),this._server=!!t.server,this._banner=void 0;let l;if(this._server){if(typeof t.hostKeys!="object"||t.hostKeys===null)throw new Error("Missing server host key(s)");this._hostKeys=t.hostKeys,typeof t.greeting=="string"&&t.greeting.length&&(l=t.greeting.slice(-2)===`\r
62
8
  `?t.greeting:`${t.greeting}\r
63
9
  `),typeof t.banner=="string"&&t.banner.length&&(this._banner=t.banner.slice(-2)===`\r
64
10
  `?t.banner:`${t.banner}\r
65
- `)}else this._hostKeys=void 0;let h=t.offer;typeof h!="object"||h===null?h=this._server?o0:s0:h.constructor!==Xl&&(this._server?h.kex=h.kex.concat(["kex-strict-s-v00@openssh.com"]):h.kex=h.kex.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),h=new Xl(h)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=h,this._cipher=new t0(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new u0,write:new l0(this)},this._hostVerifier=!this._server&&typeof t.hostVerifier=="function"?t.hostVerifier:void 0,this._parse=_0,this._buffer=void 0,this._authsQueue=[],this._authenticated=!1,this._remoteIdentRaw=void 0;let d;if(typeof t.ident=="string")this._identRaw=Buffer.from(`SSH-2.0-${t.ident}`),d=Buffer.allocUnsafe(this._identRaw.length+2),d.set(this._identRaw,0),d[d.length-2]=13,d[d.length-1]=10;else if(Buffer.isBuffer(t.ident)){let g=Buffer.allocUnsafe(8+t.ident.length);g.latin1Write("SSH-2.0-",0,8),g.set(t.ident,8),this._identRaw=g,d=Buffer.allocUnsafe(g.length+2),d.set(g,0),d[d.length-2]=13,d[d.length-1]=10}else this._identRaw=ah,d=p0;this._compatFlags=0,this._debug&&(e0?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${th(this._identRaw.toString())}`),this.start=()=>{this.start=void 0,u&&this._onWrite(u),this._onWrite(d)}}_destruct(t){this._packetRW.read.cleanup(),this._packetRW.write.cleanup(),this._cipher&&this._cipher.free(),this._decipher&&this._decipher.free(),(typeof t!="string"||t.length===0)&&(t="fatal error"),this.parse=()=>{throw new Error(`Instance unusable after ${t}`)},this._onWrite=()=>{throw new Error(`Instance unusable after ${t}`)},this._destruct=void 0}cleanup(){this._destruct&&this._destruct()}parse(t,e,r){for(;e<r;)e=this._parse(t,e,r)}disconnect(t){let r=this._packetRW.write.allocStartKEX,i=this._packetRW.write.alloc(13,!0),s=r+13;d0.has(t)||(t=rh.PROTOCOL_ERROR),i[r]=be.DISCONNECT,B(i,t,++r),i.fill(0,r+=4,s),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),xe(this,this._packetRW.write.finalize(i,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(eh.length);e.set(eh,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),xe(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],nh(this)):this._debug&&this._debug("Outbound: Ignoring rekey during handshake")}requestSuccess(t){let e=this._packetRW.write.allocStart,r;Buffer.isBuffer(t)?(r=this._packetRW.write.alloc(1+t.length),r[e]=be.REQUEST_SUCCESS,r.set(t,++e)):(r=this._packetRW.write.alloc(1),r[e]=be.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),xe(this,this._packetRW.write.finalize(r))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=be.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),xe(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=be.CHANNEL_SUCCESS,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),xe(this,this._packetRW.write.finalize(r))}channelFailure(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=be.CHANNEL_FAILURE,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),xe(this,this._packetRW.write.finalize(r))}channelEOF(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=be.CHANNEL_EOF,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),xe(this,this._packetRW.write.finalize(r))}channelClose(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=be.CHANNEL_CLOSE,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),xe(this,this._packetRW.write.finalize(r))}channelWindowAdjust(t,e){let r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(9);i[r]=be.CHANNEL_WINDOW_ADJUST,B(i,t,++r),B(i,e,r+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),xe(this,this._packetRW.write.finalize(i))}channelData(t,e){let r=Buffer.isBuffer(e),i=r?e.length:Buffer.byteLength(e),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(9+i);o[s]=be.CHANNEL_DATA,B(o,t,++s),B(o,i,s+=4),r?o.set(e,s+=4):o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_DATA (r:${t}, ${i})`),xe(this,this._packetRW.write.finalize(o))}channelExtData(t,e,r){let i=Buffer.isBuffer(e),s=i?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(13+s);a[o]=be.CHANNEL_EXTENDED_DATA,B(a,t,++o),B(a,r,o+=4),B(a,s,o+=4),i?a.set(e,o+=4):a.utf8Write(e,o+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_EXTENDED_DATA (r:${t})`),xe(this,this._packetRW.write.finalize(a))}channelOpenConfirm(t,e,r,i){let s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(17);o[s]=be.CHANNEL_OPEN_CONFIRMATION,B(o,t,++s),B(o,e,s+=4),B(o,r,s+=4),B(o,i,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),xe(this,this._packetRW.write.finalize(o))}channelOpenFail(t,e,r){typeof r!="string"&&(r="");let i=Buffer.byteLength(r),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(13+i+4);o[s]=be.CHANNEL_OPEN_FAILURE,B(o,t,++s),B(o,e,s+=4),B(o,i,s+=4),s+=4,i&&(o.utf8Write(r,s,i),s+=i),B(o,0,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),xe(this,this._packetRW.write.finalize(o))}service(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);i[r]=be.SERVICE_REQUEST,B(i,e,++r),i.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),xe(this,this._packetRW.write.finalize(i))}authPassword(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=Buffer.byteLength(e),o=r?Buffer.byteLength(r):0,a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+i+4+14+4+8+1+4+s+(r?4+o:0));c[a]=be.USERAUTH_REQUEST,B(c,i,++a),c.utf8Write(t,a+=4,i),B(c,14,a+=i),c.utf8Write("ssh-connection",a+=4,14),B(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=r?1:0,B(c,s,++a),Buffer.isBuffer(e)?ls(e,c,0,s,a+=4):c.utf8Write(e,a+=4,s),r?(B(c,o,a+=s),Buffer.isBuffer(r)?ls(r,c,0,o,a+=4):c.utf8Write(r,a+=4,o),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (changed password)")):this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (password)"),this._authsQueue.push("password"),xe(this,this._packetRW.write.finalize(c))}authPK(t,e,r,i){if(this._server)throw new Error("Client-only method called in server mode");if(e=Jl(e),e instanceof Error)throw new Error("Invalid key");let s=e.type;e=e.getPublicSSH(),typeof r=="function"&&(i=r,r=void 0),r||(r=s);let o=Buffer.byteLength(t),a=Buffer.byteLength(r),c=e.length,f=this._kex.sessionID,u=f.length,h=(i?4+u:0)+1+4+o+4+14+4+9+1+4+a+4+c,d,g;if(i?(d=Buffer.allocUnsafe(h),g=0,B(d,u,g),d.set(f,g+=4),g+=u):(d=this._packetRW.write.alloc(h),g=this._packetRW.write.allocStart),d[g]=be.USERAUTH_REQUEST,B(d,o,++g),d.utf8Write(t,g+=4,o),B(d,14,g+=o),d.utf8Write("ssh-connection",g+=4,14),B(d,9,g+=14),d.utf8Write("publickey",g+=4,9),d[g+=9]=i?1:0,B(d,a,++g),d.utf8Write(r,g+=4,a),B(d,c,g+=a),d.set(e,g+=4),!i){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),xe(this,this._packetRW.write.finalize(d));return}i(d,_=>{if(_=Zl(_,s),_===!1)throw new Error("Error while converting handshake signature");let y=_.length;g=this._packetRW.write.allocStart,d=this._packetRW.write.alloc(5+o+4+14+4+9+1+4+a+4+c+4+4+a+4+y),d[g]=be.USERAUTH_REQUEST,B(d,o,++g),d.utf8Write(t,g+=4,o),B(d,14,g+=o),d.utf8Write("ssh-connection",g+=4,14),B(d,9,g+=14),d.utf8Write("publickey",g+=4,9),d[g+=9]=1,B(d,a,++g),d.utf8Write(r,g+=4,a),B(d,c,g+=a),d.set(e,g+=4),B(d,4+a+4+y,g+=c),B(d,a,g+=4),d.utf8Write(r,g+=4,a),B(d,y,g+=a),d.set(_,g+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),xe(this,this._packetRW.write.finalize(d))})}authHostbased(t,e,r,i,s,o){if(this._server)throw new Error("Client-only method called in server mode");if(e=Jl(e),e instanceof Error)throw new Error("Invalid key");let a=e.type;e=e.getPublicSSH(),typeof s=="function"&&(o=s,s=void 0),s||(s=a);let c=Buffer.byteLength(t),f=Buffer.byteLength(s),u=e.length,h=this._kex.sessionID,d=h.length,g=Buffer.byteLength(r),_=Buffer.byteLength(i),y=Buffer.allocUnsafe(4+d+1+4+c+4+14+4+9+4+f+4+u+4+g+4+_),x=0;B(y,d,x),y.set(h,x+=4),y[x+=d]=be.USERAUTH_REQUEST,B(y,c,++x),y.utf8Write(t,x+=4,c),B(y,14,x+=c),y.utf8Write("ssh-connection",x+=4,14),B(y,9,x+=14),y.utf8Write("hostbased",x+=4,9),B(y,f,x+=9),y.utf8Write(s,x+=4,f),B(y,u,x+=f),y.set(e,x+=4),B(y,g,x+=u),y.utf8Write(r,x+=4,g),B(y,_,x+=g),y.utf8Write(i,x+=4,_),o(y,I=>{if(I=Zl(I,a),!I)throw new Error("Error while converting handshake signature");let O=I.length,$=y.length-d-4;x=this._packetRW.write.allocStart;let L=this._packetRW.write.alloc($+4+4+f+4+O);ls(y,L,4+d,y.length,x),B(L,4+f+4+O,x+=$),B(L,f,x+=4),L.utf8Write(s,x+=4,f),B(L,O,x+=f),L.set(I,x+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),xe(this,this._packetRW.write.finalize(L))})}authKeyboard(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e+4+14+4+20+4+4);i[r]=be.USERAUTH_REQUEST,B(i,e,++r),i.utf8Write(t,r+=4,e),B(i,14,r+=e),i.utf8Write("ssh-connection",r+=4,14),B(i,20,r+=14),i.utf8Write("keyboard-interactive",r+=4,20),B(i,0,r+=20),B(i,0,r+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),xe(this,this._packetRW.write.finalize(i))}authNone(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e+4+14+4+4);i[r]=be.USERAUTH_REQUEST,B(i,e,++r),i.utf8Write(t,r+=4,e),B(i,14,r+=e),i.utf8Write("ssh-connection",r+=4,14),B(i,4,r+=14),i.utf8Write("none",r+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),xe(this,this._packetRW.write.finalize(i))}authInfoRes(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,r;if(t){r=new Array(t.length);for(let o=0;o<t.length;++o){let a=Buffer.byteLength(t[o]);r[o]=a,e+=4+a}}let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e);if(s[i]=be.USERAUTH_INFO_RESPONSE,t){B(s,t.length,++i),i+=4;for(let o=0;o<t.length;++o){let a=r[o];B(s,a,i),i+=4,a&&(s.utf8Write(t[o],i,a),i+=a)}}else B(s,0,++i);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),xe(this,this._packetRW.write.finalize(s))}tcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+i+4);o[s]=be.GLOBAL_REQUEST,B(o,13,++s),o.utf8Write("tcpip-forward",s+=4,13),o[s+=13]=r===void 0||r===!0?1:0,B(o,i,++s),o.utf8Write(t,s+=4,i),B(o,e,s+=i),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),xe(this,this._packetRW.write.finalize(o))}cancelTcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(30+i+4);o[s]=be.GLOBAL_REQUEST,B(o,20,++s),o.utf8Write("cancel-tcpip-forward",s+=4,20),o[s+=20]=r===void 0||r===!0?1:0,B(o,i,++s),o.utf8Write(t,s+=4,i),B(o,e,s+=i),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),xe(this,this._packetRW.write.finalize(o))}openssh_streamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(41+r);s[i]=be.GLOBAL_REQUEST,B(s,31,++i),s.utf8Write("streamlocal-forward@openssh.com",i+=4,31),s[i+=31]=e===void 0||e===!0?1:0,B(s,r,++i),s.utf8Write(t,i+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),xe(this,this._packetRW.write.finalize(s))}openssh_cancelStreamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(48+r);s[i]=be.GLOBAL_REQUEST,B(s,38,++i),s.utf8Write("cancel-streamlocal-forward@openssh.com",i+=4,38),s[i+=38]=e===void 0||e===!0?1:0,B(s,r,++i),s.utf8Write(t,i+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),xe(this,this._packetRW.write.finalize(s))}directTcpip(t,e,r,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(i.srcIP),o=Buffer.byteLength(i.dstIP),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(33+s+4+4+o+4);c[a]=be.CHANNEL_OPEN,B(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),B(c,t,a+=12),B(c,e,a+=4),B(c,r,a+=4),B(c,o,a+=4),c.utf8Write(i.dstIP,a+=4,o),B(c,i.dstPort,a+=o),B(c,s,a+=4),c.utf8Write(i.srcIP,a+=4,s),B(c,i.srcPort,a+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),xe(this,this._packetRW.write.finalize(c))}openssh_directStreamLocal(t,e,r,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(i.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(51+s+4+4);a[o]=be.CHANNEL_OPEN,B(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),B(a,t,o+=30),B(a,e,o+=4),B(a,r,o+=4),B(a,s,o+=4),a.utf8Write(i.socketPath,o+=4,s),f0(a,0,o+=s,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),xe(this,this._packetRW.write.finalize(a))}openssh_noMoreSessions(t){if(this._server)throw new Error("Client-only method called in server mode");let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(34);r[e]=be.GLOBAL_REQUEST,B(r,28,++e),r.utf8Write("no-more-sessions@openssh.com",e+=4,28),r[e+=28]=t===void 0||t===!0?1:0,this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (no-more-sessions@openssh.com)"),xe(this,this._packetRW.write.finalize(r))}session(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(24);s[i]=be.CHANNEL_OPEN,B(s,7,++i),s.utf8Write("session",i+=4,7),B(s,t,i+=7),B(s,e,i+=4),B(s,r,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),xe(this,this._packetRW.write.finalize(s))}windowChange(t,e,r,i,s){if(this._server)throw new Error("Client-only method called in server mode");let o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(39);a[o]=be.CHANNEL_REQUEST,B(a,t,++o),B(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,B(a,r,++o),B(a,e,o+=4),B(a,s,o+=4),B(a,i,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),xe(this,this._packetRW.write.finalize(a))}pty(t,e,r,i,s,o,a,c){if(this._server)throw new Error("Client-only method called in server mode");(!o||!o.length)&&(o="vt100"),a&&!Buffer.isBuffer(a)&&!Array.isArray(a)&&typeof a=="object"&&a!==null&&(a=S0(a)),(!a||!a.length)&&(a=A0);let f=o.length,u=a.length,h=this._packetRW.write.allocStart,d=this._packetRW.write.alloc(21+f+4+4+4+4+4+u);if(d[h]=be.CHANNEL_REQUEST,B(d,t,++h),B(d,7,h+=4),d.utf8Write("pty-req",h+=4,7),d[h+=7]=c===void 0||c===!0?1:0,B(d,f,++h),d.utf8Write(o,h+=4,f),B(d,r,h+=f),B(d,e,h+=4),B(d,s,h+=4),B(d,i,h+=4),B(d,u,h+=4),h+=4,Array.isArray(a))for(let g=0;g<u;++g)d[h++]=a[g];else Buffer.isBuffer(a)&&d.set(a,h);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),xe(this,this._packetRW.write.finalize(d))}shell(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(15);i[r]=be.CHANNEL_REQUEST,B(i,t,++r),B(i,5,r+=4),i.utf8Write("shell",r+=4,5),i[r+=5]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, shell)`),xe(this,this._packetRW.write.finalize(i))}exec(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.isBuffer(e),s=i?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(18+s);a[o]=be.CHANNEL_REQUEST,B(a,t,++o),B(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=r===void 0||r===!0?1:0,B(a,s,++o),i?a.set(e,o+=4):a.utf8Write(e,o+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exec: ${e})`),xe(this,this._packetRW.write.finalize(a))}signal(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=e;if(e=e.toUpperCase(),e.slice(0,3)==="SIG"&&(e=e.slice(3)),zl[e]!==1)throw new Error(`Invalid signal: ${r}`);let i=e.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(20+i);o[s]=be.CHANNEL_REQUEST,B(o,t,++s),B(o,6,s+=4),o.utf8Write("signal",s+=4,6),o[s+=6]=0,B(o,i,++s),o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),xe(this,this._packetRW.write.finalize(o))}env(t,e,r,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),o=Buffer.isBuffer(r),a=o?r.length:Buffer.byteLength(r),c=this._packetRW.write.allocStart,f=this._packetRW.write.alloc(17+s+4+a);f[c]=be.CHANNEL_REQUEST,B(f,t,++c),B(f,3,c+=4),f.utf8Write("env",c+=4,3),f[c+=3]=i===void 0||i===!0?1:0,B(f,s,++c),f.utf8Write(e,c+=4,s),B(f,a,c+=s),o?f.set(r,c+=4):f.utf8Write(r,c+=4,a),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, env: ${e}=${r})`),xe(this,this._packetRW.write.finalize(f))}x11Forward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=e.protocol,s=e.cookie,o=Buffer.isBuffer(i),a=o?i.length:Buffer.byteLength(i),c=Buffer.isBuffer(s),f=c?s.length:Buffer.byteLength(s),u=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(22+a+4+f+4);h[u]=be.CHANNEL_REQUEST,B(h,t,++u),B(h,7,u+=4),h.utf8Write("x11-req",u+=4,7),h[u+=7]=r===void 0||r===!0?1:0,h[++u]=e.single?1:0,B(h,a,++u),o?h.set(i,u+=4):h.utf8Write(i,u+=4,a),B(h,f,u+=a),c?h.set(s,u+=4):h.latin1Write(s,u+=4,f),B(h,e.screen||0,u+=f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),xe(this,this._packetRW.write.finalize(h))}subsystem(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+i);o[s]=be.CHANNEL_REQUEST,B(o,t,++s),B(o,9,s+=4),o.utf8Write("subsystem",s+=4,9),o[s+=9]=r===void 0||r===!0?1:0,B(o,i,++s),o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),xe(this,this._packetRW.write.finalize(o))}openssh_agentForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(36);i[r]=be.CHANNEL_REQUEST,B(i,t,++r),B(i,26,r+=4),i.utf8Write("auth-agent-req@openssh.com",r+=4,26),i[r+=26]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, auth-agent-req@openssh.com)`),xe(this,this._packetRW.write.finalize(i))}openssh_hostKeysProve(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,r=[];for(let o of t){let a=o.getPublicSSH();e+=4+a.length,r.push(a)}let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(35+e);s[i]=be.GLOBAL_REQUEST,B(s,29,++i),s.utf8Write("hostkeys-prove-00@openssh.com",i+=4,29),s[i+=29]=1,++i;for(let o of r)B(s,o.length,i),ls(o,s,0,o.length,i+=4),i+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),xe(this,this._packetRW.write.finalize(s))}serviceAccept(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);if(i[r]=be.SERVICE_ACCEPT,B(i,e,++r),i.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),xe(this,this._packetRW.write.finalize(i)),this._server&&this._banner&&t==="ssh-userauth"){let s=this._banner;this._banner=void 0;let o=Buffer.byteLength(s);r=this._packetRW.write.allocStart;let a=this._packetRW.write.alloc(5+o+4);a[r]=be.USERAUTH_BANNER,B(a,o,++r),a.utf8Write(s,r+=4,o),B(a,0,r+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),xe(this,this._packetRW.write.finalize(a))}}forwardedTcpip(t,e,r,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.boundAddr),o=Buffer.byteLength(i.remoteAddr),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(36+s+4+4+o+4);c[a]=be.CHANNEL_OPEN,B(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),B(c,t,a+=15),B(c,e,a+=4),B(c,r,a+=4),B(c,s,a+=4),c.utf8Write(i.boundAddr,a+=4,s),B(c,i.boundPort,a+=s),B(c,o,a+=4),c.utf8Write(i.remoteAddr,a+=4,o),B(c,i.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),xe(this,this._packetRW.write.finalize(c))}x11(t,e,r,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.originAddr),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(24+s+4);a[o]=be.CHANNEL_OPEN,B(a,3,++o),a.utf8Write("x11",o+=4,3),B(a,t,o+=3),B(a,e,o+=4),B(a,r,o+=4),B(a,s,o+=4),a.utf8Write(i.originAddr,o+=4,s),B(a,i.originPort,o+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),xe(this,this._packetRW.write.finalize(a))}openssh_authAgent(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(39);s[i]=be.CHANNEL_OPEN,B(s,22,++i),s.utf8Write("auth-agent@openssh.com",i+=4,22),B(s,t,i+=22),B(s,e,i+=4),B(s,r,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),xe(this,this._packetRW.write.finalize(s))}openssh_forwardedStreamLocal(t,e,r,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(54+s+4);a[o]=be.CHANNEL_OPEN,B(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),B(a,t,o+=33),B(a,e,o+=4),B(a,r,o+=4),B(a,s,o+=4),a.utf8Write(i.socketPath,o+=4,s),B(a,0,o+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),xe(this,this._packetRW.write.finalize(a))}exitStatus(t,e){if(!this._server)throw new Error("Server-only method called in client mode");let r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(25);i[r]=be.CHANNEL_REQUEST,B(i,t,++r),B(i,11,r+=4),i.utf8Write("exit-status",r+=4,11),i[r+=11]=0,B(i,e,++r),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),xe(this,this._packetRW.write.finalize(i))}exitSignal(t,e,r,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=e;if(typeof s!="string"||!s)throw new Error(`Invalid signal: ${s}`);let o=e.toUpperCase();if(o.slice(0,3)==="SIG"&&(o=o.slice(3)),zl[o]!==1)throw new Error(`Invalid signal: ${s}`);let a=Buffer.byteLength(o),c=i?Buffer.byteLength(i):0,f=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(25+a+1+4+c+4);u[f]=be.CHANNEL_REQUEST,B(u,t,++f),B(u,11,f+=4),u.utf8Write("exit-signal",f+=4,11),u[f+=11]=0,B(u,a,++f),u.utf8Write(o,f+=4,a),u[f+=a]=r?1:0,B(u,c,++f),f+=4,c&&(u.utf8Write(i,f,c),f+=c),B(u,0,f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),xe(this,this._packetRW.write.finalize(u))}authFailure(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let r;if(typeof t=="boolean"&&(e=t,t=void 0),t){r=[];for(let a=0;a<t.length;++a)t[a].toLowerCase()!=="none"&&r.push(t[a]);r=r.join(",")}else r="";let i=r.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+i+1);o[s]=be.USERAUTH_FAILURE,B(o,i,++s),o.utf8Write(r,s+=4,i),o[s+=i]=e===!0?1:0,this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_FAILURE"),xe(this,this._packetRW.write.finalize(o))}authSuccess(){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=be.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),xe(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new sh),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new oh(this))}authPKOK(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0||this._authsQueue[0]!=="publickey")throw new Error('"publickey" auth not in progress');let r=Buffer.byteLength(t),i=e.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+r+4+i);o[s]=be.USERAUTH_PK_OK,B(o,r,++s),o.utf8Write(t,s+=4,r),B(o,i,s+=r),o.set(e,s+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),xe(this,this._packetRW.write.finalize(o))}authPasswdChg(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e+4);i[r]=be.USERAUTH_PASSWD_CHANGEREQ,B(i,e,++r),i.utf8Write(t,r+=4,e),B(i,0,r+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),xe(this,this._packetRW.write.finalize(i))}authInfoReq(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let i=0,s=t?Buffer.byteLength(t):0,o=e?Buffer.byteLength(e):0;for(let f=0;f<r.length;++f)i+=4+Buffer.byteLength(r[f].prompt)+1;let a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+s+4+o+4+4+i);c[a]=be.USERAUTH_INFO_REQUEST,B(c,s,++a),a+=4,t&&(c.utf8Write(t,a,s),a+=s),B(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),B(c,0,a),B(c,r.length,a+=4),a+=4;for(let f=0;f<r.length;++f){let u=r[f],h=Buffer.byteLength(u.prompt);B(c,h,a),a+=4,h&&(c.utf8Write(u.prompt,a,h),a+=h),c[a++]=u.echo?1:0}this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_REQUEST"),xe(this,this._packetRW.write.finalize(c))}},E0=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function _0(n,t,e){let r,i;this._buffer?(r=Buffer.allocUnsafe(this._buffer.length+(e-t)),r.set(this._buffer,0),t===0?r.set(n,this._buffer.length):r.set(new Uint8Array(n.buffer,n.byteOffset+t,e-t),this._buffer.length),i=this._buffer.length,t=0):(r=n,i=0);let s=t,o=t,a=t,c=!1,f=0,u=0;for(;t<r.length;++t){let h=r[t];if(h===13){c=!0;continue}if(h===10){if(a>o&&a-o>4&&r[o]===83&&r[o+1]===83&&r[o+2]===72&&r[o+3]===45){let d=r.latin1Slice(s,a+1),g=o===s?d:d.slice(o-s),_=E0.exec(g);if(!_)throw new Error("Invalid identification string");let y={greeting:o===s?"":d.slice(0,o-s),identRaw:g,versions:{protocol:_[1],software:_[2]},comments:_[3]};return this._remoteIdentRaw=Buffer.from(g),this._debug&&this._debug(`Remote ident: ${th(g)}`),this._compatFlags=x0(y),this._buffer=void 0,this._decipher=new r0(0,a0.bind(this,{firstPacket:!0})),this._parse=y0,this._onHeader(y),this._destruct?(nh(this),t+1-i):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++u>m0)throw new Error("Max greeting lines exceeded");c=!1,o=t+1,f=0}else{if(c)throw new Error("Invalid header: expected newline");if(++f>=g0)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=ih(r,s)),t-i}function y0(n,t,e){return this._decipher.decrypt(n,t,e)}function b0(n){if(this._onPacket(),n.length===0){this._debug&&this._debug("Inbound: Skipping empty packet payload");return}n=this._packetRW.read.read(n);let t=n[0];t===be.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new oh(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new sh));let e=c0[t];if(e===void 0){this._debug&&this._debug(`Inbound: Unsupported message type: ${t}`);return}return e(this,n)}function x0(n){let t=n.versions.software,e=0;for(let r of n0)typeof r[0]=="string"?t===r[0]&&(e|=r[1]):r[0].test(t)&&(e|=r[1]);return e}function S0(n){let t=Object.keys(n),e=Buffer.allocUnsafe(5*t.length+1),r=0;for(let i=0;i<t.length;++i){let s=t[i];if(s==="TTY_OP_END")continue;let o=Xo[s];if(o===void 0)continue;let a=n[s];typeof a=="number"&&isFinite(a)&&(e[r++]=o,e[r++]=a>>>24,e[r++]=a>>>16,e[r++]=a>>>8,e[r++]=a)}return e[r++]=Xo.TTY_OP_END,r<e.length?ih(e,0,r):e}function w0(n){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";i0&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),r=n._packetRW.write.allocStart,i=n._packetRW.write.alloc(28+e);i[r]=be.EXT_INFO,B(i,1,++r),B(i,15,r+=4),i.utf8Write("server-sig-algs",r+=4,15),B(i,e,r+=15),i.utf8Write(t,r+=4,e),n._debug&&n._debug("Outbound: Sending EXT_INFO"),xe(n,n._packetRW.write.finalize(i))}ch.exports=Jo});var ph=ot(ui=>{"use strict";var hs=require("assert"),{inspect:I0}=require("util");function fh(n){let t="",e=n.length,r=n[0]==="-"?1:0;for(;e>=r+4;e-=3)t=`_${n.slice(e-3,e)}${t}`;return`${n.slice(0,e)}${t}`}function uh(n,t){if(hs(typeof t=="string","`thing` has to be of type string"),Array.isArray(n)){let e=n.length;return hs(e>0,"At least one expected value needs to be specified"),n=n.map(r=>String(r)),e>2?`one of ${t} ${n.slice(0,e-1).join(", ")}, or `+n[e-1]:e===2?`one of ${t} ${n[0]} or ${n[1]}`:`of ${t} ${n[0]}`}return`of ${t} ${String(n)}`}ui.ERR_INTERNAL_ASSERTION=class hh extends Error{constructor(t){super(),Error.captureStackTrace(this,hh);let e=`This is caused by either a bug in ssh2 or incorrect usage of ssh2 internals.
11
+ `)}else this._hostKeys=void 0;let u=t.offer;typeof u!="object"||u===null?u=this._server?gg:pg:u.constructor!==tu&&(this._server?u.kex=u.kex.concat(["kex-strict-s-v00@openssh.com"]):u.kex=u.kex.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),u=new tu(u)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=u,this._cipher=new lg(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new _g,write:new bg(this)},this._hostVerifier=!this._server&&typeof t.hostVerifier=="function"?t.hostVerifier:void 0,this._parse=kg,this._buffer=void 0,this._authsQueue=[],this._authenticated=!1,this._remoteIdentRaw=void 0;let h;if(typeof t.ident=="string")this._identRaw=Buffer.from(`SSH-2.0-${t.ident}`),h=Buffer.allocUnsafe(this._identRaw.length+2),h.set(this._identRaw,0),h[h.length-2]=13,h[h.length-1]=10;else if(Buffer.isBuffer(t.ident)){let g=Buffer.allocUnsafe(8+t.ident.length);g.latin1Write("SSH-2.0-",0,8),g.set(t.ident,8),this._identRaw=g,h=Buffer.allocUnsafe(g.length+2),h.set(g,0),h[h.length-2]=13,h[h.length-1]=10}else this._identRaw=uu,h=Sg;this._compatFlags=0,this._debug&&(fg?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${su(this._identRaw.toString())}`),this.start=()=>{this.start=void 0,l&&this._onWrite(l),this._onWrite(h)}}_destruct(t){this._packetRW.read.cleanup(),this._packetRW.write.cleanup(),this._cipher&&this._cipher.free(),this._decipher&&this._decipher.free(),(typeof t!="string"||t.length===0)&&(t="fatal error"),this.parse=()=>{throw new Error(`Instance unusable after ${t}`)},this._onWrite=()=>{throw new Error(`Instance unusable after ${t}`)},this._destruct=void 0}cleanup(){this._destruct&&this._destruct()}parse(t,e,n){for(;e<n;)e=this._parse(t,e,n)}disconnect(t){let n=this._packetRW.write.allocStartKEX,i=this._packetRW.write.alloc(13,!0),s=n+13;xg.has(t)||(t=ou.PROTOCOL_ERROR),i[n]=ye.DISCONNECT,v(i,t,++n),i.fill(0,n+=4,s),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),xe(this,this._packetRW.write.finalize(i,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(iu.length);e.set(iu,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),xe(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],au(this)):this._debug&&this._debug("Outbound: Ignoring rekey during handshake")}requestSuccess(t){let e=this._packetRW.write.allocStart,n;Buffer.isBuffer(t)?(n=this._packetRW.write.alloc(1+t.length),n[e]=ye.REQUEST_SUCCESS,n.set(t,++e)):(n=this._packetRW.write.alloc(1),n[e]=ye.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),xe(this,this._packetRW.write.finalize(n))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=ye.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),xe(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,n=this._packetRW.write.alloc(5);n[e]=ye.CHANNEL_SUCCESS,v(n,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),xe(this,this._packetRW.write.finalize(n))}channelFailure(t){let e=this._packetRW.write.allocStart,n=this._packetRW.write.alloc(5);n[e]=ye.CHANNEL_FAILURE,v(n,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),xe(this,this._packetRW.write.finalize(n))}channelEOF(t){let e=this._packetRW.write.allocStart,n=this._packetRW.write.alloc(5);n[e]=ye.CHANNEL_EOF,v(n,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),xe(this,this._packetRW.write.finalize(n))}channelClose(t){let e=this._packetRW.write.allocStart,n=this._packetRW.write.alloc(5);n[e]=ye.CHANNEL_CLOSE,v(n,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),xe(this,this._packetRW.write.finalize(n))}channelWindowAdjust(t,e){let n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(9);i[n]=ye.CHANNEL_WINDOW_ADJUST,v(i,t,++n),v(i,e,n+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),xe(this,this._packetRW.write.finalize(i))}channelData(t,e){let n=Buffer.isBuffer(e),i=n?e.length:Buffer.byteLength(e),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(9+i);o[s]=ye.CHANNEL_DATA,v(o,t,++s),v(o,i,s+=4),n?o.set(e,s+=4):o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_DATA (r:${t}, ${i})`),xe(this,this._packetRW.write.finalize(o))}channelExtData(t,e,n){let i=Buffer.isBuffer(e),s=i?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(13+s);a[o]=ye.CHANNEL_EXTENDED_DATA,v(a,t,++o),v(a,n,o+=4),v(a,s,o+=4),i?a.set(e,o+=4):a.utf8Write(e,o+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_EXTENDED_DATA (r:${t})`),xe(this,this._packetRW.write.finalize(a))}channelOpenConfirm(t,e,n,i){let s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(17);o[s]=ye.CHANNEL_OPEN_CONFIRMATION,v(o,t,++s),v(o,e,s+=4),v(o,n,s+=4),v(o,i,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),xe(this,this._packetRW.write.finalize(o))}channelOpenFail(t,e,n){typeof n!="string"&&(n="");let i=Buffer.byteLength(n),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(13+i+4);o[s]=ye.CHANNEL_OPEN_FAILURE,v(o,t,++s),v(o,e,s+=4),v(o,i,s+=4),s+=4,i&&(o.utf8Write(n,s,i),s+=i),v(o,0,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),xe(this,this._packetRW.write.finalize(o))}service(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);i[n]=ye.SERVICE_REQUEST,v(i,e,++n),i.utf8Write(t,n+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),xe(this,this._packetRW.write.finalize(i))}authPassword(t,e,n){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=Buffer.byteLength(e),o=n?Buffer.byteLength(n):0,a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+i+4+14+4+8+1+4+s+(n?4+o:0));c[a]=ye.USERAUTH_REQUEST,v(c,i,++a),c.utf8Write(t,a+=4,i),v(c,14,a+=i),c.utf8Write("ssh-connection",a+=4,14),v(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=n?1:0,v(c,s,++a),Buffer.isBuffer(e)?ls(e,c,0,s,a+=4):c.utf8Write(e,a+=4,s),n?(v(c,o,a+=s),Buffer.isBuffer(n)?ls(n,c,0,o,a+=4):c.utf8Write(n,a+=4,o),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (changed password)")):this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (password)"),this._authsQueue.push("password"),xe(this,this._packetRW.write.finalize(c))}authPK(t,e,n,i){if(this._server)throw new Error("Client-only method called in server mode");if(e=ru(e),e instanceof Error)throw new Error("Invalid key");let s=e.type;e=e.getPublicSSH(),typeof n=="function"&&(i=n,n=void 0),n||(n=s);let o=Buffer.byteLength(t),a=Buffer.byteLength(n),c=e.length,f=this._kex.sessionID,l=f.length,u=(i?4+l:0)+1+4+o+4+14+4+9+1+4+a+4+c,h,g;if(i?(h=Buffer.allocUnsafe(u),g=0,v(h,l,g),h.set(f,g+=4),g+=l):(h=this._packetRW.write.alloc(u),g=this._packetRW.write.allocStart),h[g]=ye.USERAUTH_REQUEST,v(h,o,++g),h.utf8Write(t,g+=4,o),v(h,14,g+=o),h.utf8Write("ssh-connection",g+=4,14),v(h,9,g+=14),h.utf8Write("publickey",g+=4,9),h[g+=9]=i?1:0,v(h,a,++g),h.utf8Write(n,g+=4,a),v(h,c,g+=a),h.set(e,g+=4),!i){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),xe(this,this._packetRW.write.finalize(h));return}i(h,b=>{if(b=nu(b,s),b===!1)throw new Error("Error while converting handshake signature");let _=b.length;g=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(5+o+4+14+4+9+1+4+a+4+c+4+4+a+4+_),h[g]=ye.USERAUTH_REQUEST,v(h,o,++g),h.utf8Write(t,g+=4,o),v(h,14,g+=o),h.utf8Write("ssh-connection",g+=4,14),v(h,9,g+=14),h.utf8Write("publickey",g+=4,9),h[g+=9]=1,v(h,a,++g),h.utf8Write(n,g+=4,a),v(h,c,g+=a),h.set(e,g+=4),v(h,4+a+4+_,g+=c),v(h,a,g+=4),h.utf8Write(n,g+=4,a),v(h,_,g+=a),h.set(b,g+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),xe(this,this._packetRW.write.finalize(h))})}authHostbased(t,e,n,i,s,o){if(this._server)throw new Error("Client-only method called in server mode");if(e=ru(e),e instanceof Error)throw new Error("Invalid key");let a=e.type;e=e.getPublicSSH(),typeof s=="function"&&(o=s,s=void 0),s||(s=a);let c=Buffer.byteLength(t),f=Buffer.byteLength(s),l=e.length,u=this._kex.sessionID,h=u.length,g=Buffer.byteLength(n),b=Buffer.byteLength(i),_=Buffer.allocUnsafe(4+h+1+4+c+4+14+4+9+4+f+4+l+4+g+4+b),x=0;v(_,h,x),_.set(u,x+=4),_[x+=h]=ye.USERAUTH_REQUEST,v(_,c,++x),_.utf8Write(t,x+=4,c),v(_,14,x+=c),_.utf8Write("ssh-connection",x+=4,14),v(_,9,x+=14),_.utf8Write("hostbased",x+=4,9),v(_,f,x+=9),_.utf8Write(s,x+=4,f),v(_,l,x+=f),_.set(e,x+=4),v(_,g,x+=l),_.utf8Write(n,x+=4,g),v(_,b,x+=g),_.utf8Write(i,x+=4,b),o(_,S=>{if(S=nu(S,a),!S)throw new Error("Error while converting handshake signature");let N=S.length,O=_.length-h-4;x=this._packetRW.write.allocStart;let P=this._packetRW.write.alloc(O+4+4+f+4+N);ls(_,P,4+h,_.length,x),v(P,4+f+4+N,x+=O),v(P,f,x+=4),P.utf8Write(s,x+=4,f),v(P,N,x+=f),P.set(S,x+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),xe(this,this._packetRW.write.finalize(P))})}authKeyboard(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e+4+14+4+20+4+4);i[n]=ye.USERAUTH_REQUEST,v(i,e,++n),i.utf8Write(t,n+=4,e),v(i,14,n+=e),i.utf8Write("ssh-connection",n+=4,14),v(i,20,n+=14),i.utf8Write("keyboard-interactive",n+=4,20),v(i,0,n+=20),v(i,0,n+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),xe(this,this._packetRW.write.finalize(i))}authNone(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e+4+14+4+4);i[n]=ye.USERAUTH_REQUEST,v(i,e,++n),i.utf8Write(t,n+=4,e),v(i,14,n+=e),i.utf8Write("ssh-connection",n+=4,14),v(i,4,n+=14),i.utf8Write("none",n+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),xe(this,this._packetRW.write.finalize(i))}authInfoRes(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,n;if(t){n=new Array(t.length);for(let o=0;o<t.length;++o){let a=Buffer.byteLength(t[o]);n[o]=a,e+=4+a}}let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e);if(s[i]=ye.USERAUTH_INFO_RESPONSE,t){v(s,t.length,++i),i+=4;for(let o=0;o<t.length;++o){let a=n[o];v(s,a,i),i+=4,a&&(s.utf8Write(t[o],i,a),i+=a)}}else v(s,0,++i);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),xe(this,this._packetRW.write.finalize(s))}tcpipForward(t,e,n){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+i+4);o[s]=ye.GLOBAL_REQUEST,v(o,13,++s),o.utf8Write("tcpip-forward",s+=4,13),o[s+=13]=n===void 0||n===!0?1:0,v(o,i,++s),o.utf8Write(t,s+=4,i),v(o,e,s+=i),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),xe(this,this._packetRW.write.finalize(o))}cancelTcpipForward(t,e,n){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(30+i+4);o[s]=ye.GLOBAL_REQUEST,v(o,20,++s),o.utf8Write("cancel-tcpip-forward",s+=4,20),o[s+=20]=n===void 0||n===!0?1:0,v(o,i,++s),o.utf8Write(t,s+=4,i),v(o,e,s+=i),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),xe(this,this._packetRW.write.finalize(o))}openssh_streamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(41+n);s[i]=ye.GLOBAL_REQUEST,v(s,31,++i),s.utf8Write("streamlocal-forward@openssh.com",i+=4,31),s[i+=31]=e===void 0||e===!0?1:0,v(s,n,++i),s.utf8Write(t,i+=4,n),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),xe(this,this._packetRW.write.finalize(s))}openssh_cancelStreamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(48+n);s[i]=ye.GLOBAL_REQUEST,v(s,38,++i),s.utf8Write("cancel-streamlocal-forward@openssh.com",i+=4,38),s[i+=38]=e===void 0||e===!0?1:0,v(s,n,++i),s.utf8Write(t,i+=4,n),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),xe(this,this._packetRW.write.finalize(s))}directTcpip(t,e,n,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(i.srcIP),o=Buffer.byteLength(i.dstIP),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(33+s+4+4+o+4);c[a]=ye.CHANNEL_OPEN,v(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),v(c,t,a+=12),v(c,e,a+=4),v(c,n,a+=4),v(c,o,a+=4),c.utf8Write(i.dstIP,a+=4,o),v(c,i.dstPort,a+=o),v(c,s,a+=4),c.utf8Write(i.srcIP,a+=4,s),v(c,i.srcPort,a+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),xe(this,this._packetRW.write.finalize(c))}openssh_directStreamLocal(t,e,n,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(i.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(51+s+4+4);a[o]=ye.CHANNEL_OPEN,v(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),v(a,t,o+=30),v(a,e,o+=4),v(a,n,o+=4),v(a,s,o+=4),a.utf8Write(i.socketPath,o+=4,s),Eg(a,0,o+=s,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),xe(this,this._packetRW.write.finalize(a))}openssh_noMoreSessions(t){if(this._server)throw new Error("Client-only method called in server mode");let e=this._packetRW.write.allocStart,n=this._packetRW.write.alloc(34);n[e]=ye.GLOBAL_REQUEST,v(n,28,++e),n.utf8Write("no-more-sessions@openssh.com",e+=4,28),n[e+=28]=t===void 0||t===!0?1:0,this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (no-more-sessions@openssh.com)"),xe(this,this._packetRW.write.finalize(n))}session(t,e,n){if(this._server)throw new Error("Client-only method called in server mode");let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(24);s[i]=ye.CHANNEL_OPEN,v(s,7,++i),s.utf8Write("session",i+=4,7),v(s,t,i+=7),v(s,e,i+=4),v(s,n,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),xe(this,this._packetRW.write.finalize(s))}windowChange(t,e,n,i,s){if(this._server)throw new Error("Client-only method called in server mode");let o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(39);a[o]=ye.CHANNEL_REQUEST,v(a,t,++o),v(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,v(a,n,++o),v(a,e,o+=4),v(a,s,o+=4),v(a,i,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),xe(this,this._packetRW.write.finalize(a))}pty(t,e,n,i,s,o,a,c){if(this._server)throw new Error("Client-only method called in server mode");(!o||!o.length)&&(o="vt100"),a&&!Buffer.isBuffer(a)&&!Array.isArray(a)&&typeof a=="object"&&a!==null&&(a=Pg(a)),(!a||!a.length)&&(a=Cg);let f=o.length,l=a.length,u=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(21+f+4+4+4+4+4+l);if(h[u]=ye.CHANNEL_REQUEST,v(h,t,++u),v(h,7,u+=4),h.utf8Write("pty-req",u+=4,7),h[u+=7]=c===void 0||c===!0?1:0,v(h,f,++u),h.utf8Write(o,u+=4,f),v(h,n,u+=f),v(h,e,u+=4),v(h,s,u+=4),v(h,i,u+=4),v(h,l,u+=4),u+=4,Array.isArray(a))for(let g=0;g<l;++g)h[u++]=a[g];else Buffer.isBuffer(a)&&h.set(a,u);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),xe(this,this._packetRW.write.finalize(h))}shell(t,e){if(this._server)throw new Error("Client-only method called in server mode");let n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(15);i[n]=ye.CHANNEL_REQUEST,v(i,t,++n),v(i,5,n+=4),i.utf8Write("shell",n+=4,5),i[n+=5]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, shell)`),xe(this,this._packetRW.write.finalize(i))}exec(t,e,n){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.isBuffer(e),s=i?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(18+s);a[o]=ye.CHANNEL_REQUEST,v(a,t,++o),v(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=n===void 0||n===!0?1:0,v(a,s,++o),i?a.set(e,o+=4):a.utf8Write(e,o+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exec: ${e})`),xe(this,this._packetRW.write.finalize(a))}signal(t,e){if(this._server)throw new Error("Client-only method called in server mode");let n=e;if(e=e.toUpperCase(),e.slice(0,3)==="SIG"&&(e=e.slice(3)),eu[e]!==1)throw new Error(`Invalid signal: ${n}`);let i=e.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(20+i);o[s]=ye.CHANNEL_REQUEST,v(o,t,++s),v(o,6,s+=4),o.utf8Write("signal",s+=4,6),o[s+=6]=0,v(o,i,++s),o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),xe(this,this._packetRW.write.finalize(o))}env(t,e,n,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),o=Buffer.isBuffer(n),a=o?n.length:Buffer.byteLength(n),c=this._packetRW.write.allocStart,f=this._packetRW.write.alloc(17+s+4+a);f[c]=ye.CHANNEL_REQUEST,v(f,t,++c),v(f,3,c+=4),f.utf8Write("env",c+=4,3),f[c+=3]=i===void 0||i===!0?1:0,v(f,s,++c),f.utf8Write(e,c+=4,s),v(f,a,c+=s),o?f.set(n,c+=4):f.utf8Write(n,c+=4,a),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, env: ${e}=${n})`),xe(this,this._packetRW.write.finalize(f))}x11Forward(t,e,n){if(this._server)throw new Error("Client-only method called in server mode");let i=e.protocol,s=e.cookie,o=Buffer.isBuffer(i),a=o?i.length:Buffer.byteLength(i),c=Buffer.isBuffer(s),f=c?s.length:Buffer.byteLength(s),l=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(22+a+4+f+4);u[l]=ye.CHANNEL_REQUEST,v(u,t,++l),v(u,7,l+=4),u.utf8Write("x11-req",l+=4,7),u[l+=7]=n===void 0||n===!0?1:0,u[++l]=e.single?1:0,v(u,a,++l),o?u.set(i,l+=4):u.utf8Write(i,l+=4,a),v(u,f,l+=a),c?u.set(s,l+=4):u.latin1Write(s,l+=4,f),v(u,e.screen||0,l+=f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),xe(this,this._packetRW.write.finalize(u))}subsystem(t,e,n){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+i);o[s]=ye.CHANNEL_REQUEST,v(o,t,++s),v(o,9,s+=4),o.utf8Write("subsystem",s+=4,9),o[s+=9]=n===void 0||n===!0?1:0,v(o,i,++s),o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),xe(this,this._packetRW.write.finalize(o))}openssh_agentForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(36);i[n]=ye.CHANNEL_REQUEST,v(i,t,++n),v(i,26,n+=4),i.utf8Write("auth-agent-req@openssh.com",n+=4,26),i[n+=26]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, auth-agent-req@openssh.com)`),xe(this,this._packetRW.write.finalize(i))}openssh_hostKeysProve(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,n=[];for(let o of t){let a=o.getPublicSSH();e+=4+a.length,n.push(a)}let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(35+e);s[i]=ye.GLOBAL_REQUEST,v(s,29,++i),s.utf8Write("hostkeys-prove-00@openssh.com",i+=4,29),s[i+=29]=1,++i;for(let o of n)v(s,o.length,i),ls(o,s,0,o.length,i+=4),i+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),xe(this,this._packetRW.write.finalize(s))}serviceAccept(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);if(i[n]=ye.SERVICE_ACCEPT,v(i,e,++n),i.utf8Write(t,n+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),xe(this,this._packetRW.write.finalize(i)),this._server&&this._banner&&t==="ssh-userauth"){let s=this._banner;this._banner=void 0;let o=Buffer.byteLength(s);n=this._packetRW.write.allocStart;let a=this._packetRW.write.alloc(5+o+4);a[n]=ye.USERAUTH_BANNER,v(a,o,++n),a.utf8Write(s,n+=4,o),v(a,0,n+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),xe(this,this._packetRW.write.finalize(a))}}forwardedTcpip(t,e,n,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.boundAddr),o=Buffer.byteLength(i.remoteAddr),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(36+s+4+4+o+4);c[a]=ye.CHANNEL_OPEN,v(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),v(c,t,a+=15),v(c,e,a+=4),v(c,n,a+=4),v(c,s,a+=4),c.utf8Write(i.boundAddr,a+=4,s),v(c,i.boundPort,a+=s),v(c,o,a+=4),c.utf8Write(i.remoteAddr,a+=4,o),v(c,i.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),xe(this,this._packetRW.write.finalize(c))}x11(t,e,n,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.originAddr),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(24+s+4);a[o]=ye.CHANNEL_OPEN,v(a,3,++o),a.utf8Write("x11",o+=4,3),v(a,t,o+=3),v(a,e,o+=4),v(a,n,o+=4),v(a,s,o+=4),a.utf8Write(i.originAddr,o+=4,s),v(a,i.originPort,o+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),xe(this,this._packetRW.write.finalize(a))}openssh_authAgent(t,e,n){if(!this._server)throw new Error("Server-only method called in client mode");let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(39);s[i]=ye.CHANNEL_OPEN,v(s,22,++i),s.utf8Write("auth-agent@openssh.com",i+=4,22),v(s,t,i+=22),v(s,e,i+=4),v(s,n,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),xe(this,this._packetRW.write.finalize(s))}openssh_forwardedStreamLocal(t,e,n,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(54+s+4);a[o]=ye.CHANNEL_OPEN,v(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),v(a,t,o+=33),v(a,e,o+=4),v(a,n,o+=4),v(a,s,o+=4),a.utf8Write(i.socketPath,o+=4,s),v(a,0,o+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),xe(this,this._packetRW.write.finalize(a))}exitStatus(t,e){if(!this._server)throw new Error("Server-only method called in client mode");let n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(25);i[n]=ye.CHANNEL_REQUEST,v(i,t,++n),v(i,11,n+=4),i.utf8Write("exit-status",n+=4,11),i[n+=11]=0,v(i,e,++n),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),xe(this,this._packetRW.write.finalize(i))}exitSignal(t,e,n,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=e;if(typeof s!="string"||!s)throw new Error(`Invalid signal: ${s}`);let o=e.toUpperCase();if(o.slice(0,3)==="SIG"&&(o=o.slice(3)),eu[o]!==1)throw new Error(`Invalid signal: ${s}`);let a=Buffer.byteLength(o),c=i?Buffer.byteLength(i):0,f=this._packetRW.write.allocStart,l=this._packetRW.write.alloc(25+a+1+4+c+4);l[f]=ye.CHANNEL_REQUEST,v(l,t,++f),v(l,11,f+=4),l.utf8Write("exit-signal",f+=4,11),l[f+=11]=0,v(l,a,++f),l.utf8Write(o,f+=4,a),l[f+=a]=n?1:0,v(l,c,++f),f+=4,c&&(l.utf8Write(i,f,c),f+=c),v(l,0,f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),xe(this,this._packetRW.write.finalize(l))}authFailure(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let n;if(typeof t=="boolean"&&(e=t,t=void 0),t){n=[];for(let a=0;a<t.length;++a)t[a].toLowerCase()!=="none"&&n.push(t[a]);n=n.join(",")}else n="";let i=n.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+i+1);o[s]=ye.USERAUTH_FAILURE,v(o,i,++s),o.utf8Write(n,s+=4,i),o[s+=i]=e===!0?1:0,this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_FAILURE"),xe(this,this._packetRW.write.finalize(o))}authSuccess(){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=ye.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),xe(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new fu),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new lu(this))}authPKOK(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0||this._authsQueue[0]!=="publickey")throw new Error('"publickey" auth not in progress');let n=Buffer.byteLength(t),i=e.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+n+4+i);o[s]=ye.USERAUTH_PK_OK,v(o,n,++s),o.utf8Write(t,s+=4,n),v(o,i,s+=n),o.set(e,s+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),xe(this,this._packetRW.write.finalize(o))}authPasswdChg(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),n=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e+4);i[n]=ye.USERAUTH_PASSWD_CHANGEREQ,v(i,e,++n),i.utf8Write(t,n+=4,e),v(i,0,n+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),xe(this,this._packetRW.write.finalize(i))}authInfoReq(t,e,n){if(!this._server)throw new Error("Server-only method called in client mode");let i=0,s=t?Buffer.byteLength(t):0,o=e?Buffer.byteLength(e):0;for(let f=0;f<n.length;++f)i+=4+Buffer.byteLength(n[f].prompt)+1;let a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+s+4+o+4+4+i);c[a]=ye.USERAUTH_INFO_REQUEST,v(c,s,++a),a+=4,t&&(c.utf8Write(t,a,s),a+=s),v(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),v(c,0,a),v(c,n.length,a+=4),a+=4;for(let f=0;f<n.length;++f){let l=n[f],u=Buffer.byteLength(l.prompt);v(c,u,a),a+=4,u&&(c.utf8Write(l.prompt,a,u),a+=u),c[a++]=l.echo?1:0}this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_REQUEST"),xe(this,this._packetRW.write.finalize(c))}},vg=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function kg(r,t,e){let n,i;this._buffer?(n=Buffer.allocUnsafe(this._buffer.length+(e-t)),n.set(this._buffer,0),t===0?n.set(r,this._buffer.length):n.set(new Uint8Array(r.buffer,r.byteOffset+t,e-t),this._buffer.length),i=this._buffer.length,t=0):(n=r,i=0);let s=t,o=t,a=t,c=!1,f=0,l=0;for(;t<n.length;++t){let u=n[t];if(u===13){c=!0;continue}if(u===10){if(a>o&&a-o>4&&n[o]===83&&n[o+1]===83&&n[o+2]===72&&n[o+3]===45){let h=n.latin1Slice(s,a+1),g=o===s?h:h.slice(o-s),b=vg.exec(g);if(!b)throw new Error("Invalid identification string");let _={greeting:o===s?"":h.slice(0,o-s),identRaw:g,versions:{protocol:b[1],software:b[2]},comments:b[3]};return this._remoteIdentRaw=Buffer.from(g),this._debug&&this._debug(`Remote ident: ${su(g)}`),this._compatFlags=Ng(_),this._buffer=void 0,this._decipher=new ug(0,mg.bind(this,{firstPacket:!0})),this._parse=Bg,this._onHeader(_),this._destruct?(au(this),t+1-i):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++l>Ig)throw new Error("Max greeting lines exceeded");c=!1,o=t+1,f=0}else{if(c)throw new Error("Invalid header: expected newline");if(++f>=wg)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=cu(n,s)),t-i}function Bg(r,t,e){return this._decipher.decrypt(r,t,e)}function Rg(r){if(this._onPacket(),r.length===0){this._debug&&this._debug("Inbound: Skipping empty packet payload");return}r=this._packetRW.read.read(r);let t=r[0];t===ye.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new lu(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new fu));let e=Ag[t];if(e===void 0){this._debug&&this._debug(`Inbound: Unsupported message type: ${t}`);return}return e(this,r)}function Ng(r){let t=r.versions.software,e=0;for(let n of dg)typeof n[0]=="string"?t===n[0]&&(e|=n[1]):n[0].test(t)&&(e|=n[1]);return e}function Pg(r){let t=Object.keys(r),e=Buffer.allocUnsafe(5*t.length+1),n=0;for(let i=0;i<t.length;++i){let s=t[i];if(s==="TTY_OP_END")continue;let o=Go[s];if(o===void 0)continue;let a=r[s];typeof a=="number"&&isFinite(a)&&(e[n++]=o,e[n++]=a>>>24,e[n++]=a>>>16,e[n++]=a>>>8,e[n++]=a)}return e[n++]=Go.TTY_OP_END,n<e.length?cu(e,0,n):e}function Tg(r){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";hg&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),n=r._packetRW.write.allocStart,i=r._packetRW.write.alloc(28+e);i[n]=ye.EXT_INFO,v(i,1,++n),v(i,15,n+=4),i.utf8Write("server-sig-algs",n+=4,15),v(i,e,n+=15),i.utf8Write(t,n+=4,e),r._debug&&r._debug("Outbound: Sending EXT_INFO"),xe(r,r._packetRW.write.finalize(i))}du.exports=Yo});var Eu=ot(fi=>{"use strict";var us=require("assert"),{inspect:Lg}=require("util");function hu(r){let t="",e=r.length,n=r[0]==="-"?1:0;for(;e>=n+4;e-=3)t=`_${r.slice(e-3,e)}${t}`;return`${r.slice(0,e)}${t}`}function pu(r,t){if(us(typeof t=="string","`thing` has to be of type string"),Array.isArray(r)){let e=r.length;return us(e>0,"At least one expected value needs to be specified"),r=r.map(n=>String(n)),e>2?`one of ${t} ${r.slice(0,e-1).join(", ")}, or `+r[e-1]:e===2?`one of ${t} ${r[0]} or ${r[1]}`:`of ${t} ${r[0]}`}return`of ${t} ${String(r)}`}fi.ERR_INTERNAL_ASSERTION=class mu extends Error{constructor(t){super(),Error.captureStackTrace(this,mu);let e=`This is caused by either a bug in ssh2 or incorrect usage of ssh2 internals.
66
12
  Please open an issue with this stack trace at https://github.com/mscdex/ssh2/issues
67
13
  `;this.message=t===void 0?e:`${t}
68
- ${e}`}};var C0=2**32,lh=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();ui.ERR_OUT_OF_RANGE=class dh extends RangeError{constructor(t,e,r,i){super(),Error.captureStackTrace(this,dh),hs(e,'Missing "range" argument');let s=i?t:`The value of "${t}" is out of range.`,o;Number.isInteger(r)&&Math.abs(r)>C0?o=fh(String(r)):typeof r=="bigint"?(o=String(r),(r>lh||r<-lh)&&(o=fh(o)),o+="n"):o=I0(r),s+=` It must be ${e}. Received ${o}`,this.message=s}};var ds=class n extends TypeError{constructor(t,e,r){super(),Error.captureStackTrace(this,n),hs(typeof t=="string","'name' must be a string");let i;typeof e=="string"&&e.startsWith("not ")?(i="must not be",e=e.replace(/^not /,"")):i="must be";let s;if(t.endsWith(" argument"))s=`The ${t} ${i} ${uh(e,"type")}`;else{let o=t.includes(".")?"property":"argument";s=`The "${t}" ${o} ${i} ${uh(e,"type")}`}s+=`. Received type ${typeof r}`,this.message=s}};ui.ERR_INVALID_ARG_TYPE=ds;ui.validateNumber=function(t,e){if(typeof t!="number")throw new ds(e,"number",t)}});var li=ot((Mb,Bh)=>{"use strict";var B0=require("events"),Mr=require("fs"),{constants:Yt}=Mr,{Readable:yh,Writable:ca}=require("stream"),{inherits:bh,types:{isDate:ra}}=require("util"),v0=Buffer[Symbol.species],{bufferCopy:Hr,bufferSlice:vn,makeBufferParser:k0,writeUInt32BE:F}=or(),Br={SIZE:1,UIDGID:2,PERMISSIONS:4,ACMODTIME:8,EXTENDED:2147483648},ve=Buffer.alloc(28),Ze={OK:0,EOF:1,NO_SUCH_FILE:2,PERMISSION_DENIED:3,FAILURE:4,BAD_MESSAGE:5,NO_CONNECTION:6,CONNECTION_LOST:7,OP_UNSUPPORTED:8},R0=new Map(Object.values(Ze).map(n=>[n,1])),N0={[Ze.OK]:"No error",[Ze.EOF]:"End of file",[Ze.NO_SUCH_FILE]:"No such file or directory",[Ze.PERMISSION_DENIED]:"Permission denied",[Ze.FAILURE]:"Failure",[Ze.BAD_MESSAGE]:"Bad message",[Ze.NO_CONNECTION]:"No connection",[Ze.CONNECTION_LOST]:"Connection lost",[Ze.OP_UNSUPPORTED]:"Operation unsupported"},Ce={INIT:1,OPEN:3,CLOSE:4,READ:5,WRITE:6,LSTAT:7,FSTAT:8,SETSTAT:9,FSETSTAT:10,OPENDIR:11,READDIR:12,REMOVE:13,MKDIR:14,RMDIR:15,REALPATH:16,STAT:17,RENAME:18,READLINK:19,SYMLINK:20,EXTENDED:200},Vt={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},Se={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},gh=2*1024,ft=2**32-1,P0=Buffer.from([0,0,0,5,Ce.INIT,0,0,0,3]),T0=Buffer.from([0,0,0,5,Vt.VERSION,0,0,0,3]),L0=/^SSH-2.0-(?:OpenSSH|dropbear)/,ea=256*1024,N=k0(),U0={readable:!1,writable:!1,push:n=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function xh(){}var na=class extends B0{constructor(t,e,r){super(),(typeof r!="object"||!r)&&(r={});let i=t._protocol._remoteIdentRaw;this.server=!!r.server,this._debug=typeof r.debug=="function"?r.debug:void 0,this._isOpenSSH=i&&L0.test(i),this._version=-1,this._extensions={},this._biOpt=r.biOpt,this._pktLenBytes=0,this._pktLen=0,this._pktPos=0,this._pktType=0,this._pktData=void 0,this._writeReqid=-1,this._requests={},this._maxInPktLen=ea,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?ea:34e3)-gh,this._maxWriteLen=(this._isOpenSSH?ea:34e3)-gh,this.maxOpenHandles=void 0,this._client=t,this._protocol=t._protocol,this._callbacks=[],this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this._waitWindow=!1,this._chunkcb=void 0,this._buffer=[],this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this.stderr=U0,this.readable=!0}push(t){if(t===null){if(Ch(this),!this.readable)return;this.readable=!1,this.emit("end");return}let e=0;for(;e<t.length;){if(this._pktLenBytes<4){let o=Math.min(4-this._pktLenBytes,t.length-e);for(this._pktLenBytes+=o;o--;)this._pktLen=(this._pktLen<<8)+t[e++];if(this._pktLenBytes<4)return;if(this._pktLen===0)return nt(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return nt(this,`Packet length ${this._pktLen} exceeds max length of ${a}`)}if(e>=t.length)return}if(this._pktPos<this._pktLen){let o=Math.min(this._pktLen-this._pktPos,t.length-e);if(e!==0||o!==t.length?o===this._pktLen?this._pkt=new v0(t.buffer,t.byteOffset+e,o):(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._pktPos)):o===this._pktLen?this._pkt=t:(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(t,this._pktPos)),e+=o,this._pktPos+=o,this._pktPos<this._pktLen)return}let r=this._pkt[0],i=this._pkt;this._pktLen=0,this._pktLenBytes=0,this._pkt=void 0,this._pktPos=0;let s=this.server?F0[r]:M0[r];if(!s)return nt(this,`Unknown packet type ${r}`);if(this._version===-1){if(this.server){if(r!==Ce.INIT)return nt(this,`Expected INIT packet, got ${r}`)}else if(r!==Vt.VERSION)return nt(this,`Expected VERSION packet, got ${r}`)}if(s(this,i)===!1)return}}end(){this.destroy()}destroy(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._protocol.channelClose(this.outgoing.id))}_init(){this._init=xh,this.server||ze(this,P0)}createReadStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new vr(this,t,e)}createWriteStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new sr(this,t,e)}open(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");typeof r=="function"&&(i=r,r=void 0);let s=typeof e=="number"?e:wh(e);if(s===null)throw new Error(`Unknown flags string: ${e}`);let o=0,a=0;(typeof r=="string"||typeof r=="number")&&(r={mode:r}),typeof r=="object"&&r!==null&&(r=tn(r),o=r.flags,a=r.nb);let c=Buffer.byteLength(t),f=9,u=Buffer.allocUnsafe(13+c+4+4+a);F(u,u.length-4,0),u[4]=Ce.OPEN;let h=this._writeReqid=this._writeReqid+1&ft;F(u,h,5),F(u,c,f),u.utf8Write(t,f+=4,c),F(u,s,f+=c),F(u,o,f+=4),a&&(f+=4,a===ve.length?u.set(ve,f):Hr(ve,u,0,a,f),f+=a),this._requests[h]={cb:i};let d=ze(this,u);this._debug&&this._debug(`SFTP: Outbound: ${d?"Buffered":"Sending"} OPEN`)}close(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let r=t.length,i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.CLOSE;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.set(t,i+=4),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} CLOSE`)}read(t,e,r,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(r>=e.length)throw new Error("offset is out of bounds");if(r+i>e.length)throw new Error("length extends beyond buffer");if(s===null)throw new Error("null position currently unsupported");Sh(this,t,e,r,i,s,o)}readData(t,e,r,i,s,o){this.read(t,e,r,i,s,o)}write(t,e,r,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(r>e.length)throw new Error("offset is out of bounds");if(r+i>e.length)throw new Error("length extends beyond buffer");if(s===null)throw new Error("null position currently unsupported");if(!i){o&&process.nextTick(o,void 0,0);return}let a=this._maxWriteLen,c=Math.max(i-a,0),f=s;c&&(i=a);let u=t.length,h=9,d=Buffer.allocUnsafe(13+u+8+4+i);F(d,d.length-4,0),d[4]=Ce.WRITE;let g=this._writeReqid=this._writeReqid+1&ft;F(d,g,5),F(d,u,h),d.set(t,h+=4),h+=u;for(let y=7;y>=0;--y)d[h+y]=s&255,s/=256;F(d,i,h+=8),Hr(e,d,r,r+i,h+=4),this._requests[g]={cb:y=>{y?typeof o=="function"&&o(y):c?this.write(t,e,r+i,c,f+i,o):typeof o=="function"&&o(void 0,r+i)}};let _=ze(this,d);if(this._debug){let y=_?"Sent":"Buffered";this._debug(`SFTP: Outbound: ${y} WRITE (id:${g})`)}}writeData(t,e,r,i,s,o){this.write(t,e,r,i,s,o)}fastGet(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");mh(this,Mr,t,e,r,i)}fastPut(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");mh(Mr,this,t,e,r,i)}readFile(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof r=="function"?i=r:typeof e=="function"&&(i=e,e=void 0),typeof e=="string")e={encoding:e,flag:"r"};else if(!e)e={encoding:null,flag:"r"};else if(typeof e!="object")throw new TypeError("Bad arguments");let s=e.encoding;if(s&&!Buffer.isEncoding(s))throw new Error(`Unknown encoding: ${s}`);let o,a,c,f=0,u,h=0,d=e.flag||"r",g=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(u,a,0,8192,h,_)):this.read(u,a,f,o-f,h,_)},_=(x,I)=>{let O;if(x){if(O=x.code===Ze.EOF,!O)return this.close(u,()=>i&&i(x))}else O=!1;if(O||o===0&&I===0)return y();h+=I,f+=I,o!==0?f===o?y():g():(c.push(vn(a,0,I)),g())};_._wantEOFError=!0;let y=()=>{this.close(u,x=>(o===0?a=Buffer.concat(c,f):f<o&&(a=vn(a,0,f)),s&&(a=a.toString(s)),i&&i(x,a)))};this.open(t,d,438,(x,I)=>{if(x)return i&&i(x);u=I;let O=($,L)=>{if($){this.stat(t,(j,J)=>{if(j)return this.close(u,()=>{i&&i($)});O(null,J)});return}if(o=L.size||0,o===0)return c=[],g();a=Buffer.allocUnsafe(o),g()};this.fstat(u,O)})}writeFile(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof i=="function"?s=i:typeof r=="function"&&(s=r,r=void 0),typeof r=="string")r={encoding:r,mode:438,flag:"w"};else if(!r)r={encoding:"utf8",mode:438,flag:"w"};else if(typeof r!="object")throw new TypeError("Bad arguments");if(r.encoding&&!Buffer.isEncoding(r.encoding))throw new Error(`Unknown encoding: ${r.encoding}`);let o=r.flag||"w";this.open(t,o,r.mode,(a,c)=>{if(a)s&&s(a);else{let f=Buffer.isBuffer(e)?e:Buffer.from(""+e,r.encoding||"utf8"),u=/a/.test(o)?null:0;if(u===null){let h=(d,g)=>{if(d){this.stat(t,(_,y)=>{if(_)return this.close(c,()=>{s&&s(d)});h(null,y)});return}ia(this,c,f,0,f.length,g.size,s)};this.fstat(c,h);return}ia(this,c,f,0,f.length,u,s)}})}appendFile(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof i=="function"?s=i:typeof r=="function"&&(s=r,r=void 0),typeof r=="string")r={encoding:r,mode:438,flag:"a"};else if(!r)r={encoding:"utf8",mode:438,flag:"a"};else if(typeof r!="object")throw new TypeError("Bad arguments");r.flag||(r=Object.assign({flag:"a"},r)),this.writeFile(t,e,r,s)}exists(t,e){if(this.server)throw new Error("Client-only method called in server mode");this.stat(t,r=>{e&&e(!r)})}unlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.REMOVE;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REMOVE`)}rename(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=Buffer.byteLength(e),o=9,a=Buffer.allocUnsafe(13+i+4+s);F(a,a.length-4,0),a[4]=Ce.RENAME;let c=this._writeReqid=this._writeReqid+1&ft;F(a,c,5),F(a,i,o),a.utf8Write(t,o+=4,i),F(a,s,o+=i),a.utf8Write(e,o+=4,s),this._requests[c]={cb:r};let f=ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} RENAME`)}mkdir(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=0,s=0;typeof e=="function"&&(r=e,e=void 0),typeof e=="object"&&e!==null&&(e=tn(e),i=e.flags,s=e.nb);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+s);F(c,c.length-4,0),c[4]=Ce.MKDIR;let f=this._writeReqid=this._writeReqid+1&ft;F(c,f,5),F(c,o,a),c.utf8Write(t,a+=4,o),F(c,i,a+=o),s&&(a+=4,s===ve.length?c.set(ve,a):Hr(ve,c,0,s,a),a+=s),this._requests[f]={cb:r};let u=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"Buffered":"Sending"} MKDIR`)}rmdir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.RMDIR;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} RMDIR`)}readdir(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");typeof e=="function"&&(r=e,e={}),(typeof e!="object"||e===null)&&(e={});let i=!(e&&e.full);if(!Buffer.isBuffer(t)&&typeof t!="string")throw new Error("missing directory handle or path");if(typeof t=="string"){let u=[],h=0,d=(g,_)=>{if(g)return r(g);this.readdir(_,e,(y,x)=>{let I=y&&y.code===Ze.EOF;if(y&&!I)return this.close(_,()=>r(y));if(I)return this.close(_,O=>{if(O)return r(O);r(void 0,u)});for(let O=0;O<x.length;++O,++h)u[h]=x[O];d(void 0,_)})};return this.opendir(t,d)}let s=t.length,o=9,a=Buffer.allocUnsafe(13+s);F(a,a.length-4,0),a[4]=Ce.READDIR;let c=this._writeReqid=this._writeReqid+1&ft;F(a,c,5),F(a,s,o),a.set(t,o+=4),this._requests[c]={cb:i?(u,h)=>{if(typeof r=="function"){if(u)return r(u);for(let d=h.length-1;d>=0;--d)(h[d].filename==="."||h[d].filename==="..")&&h.splice(d,1);r(void 0,h)}}:r};let f=ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} READDIR`)}fstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let r=t.length,i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.FSTAT;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.set(t,i+=4),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} FSTAT`)}stat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.STAT;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STAT`)}lstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.LSTAT;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} LSTAT`)}opendir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.OPENDIR;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} OPENDIR`)}setstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=0,s=0;typeof e=="object"&&e!==null?(e=tn(e),i=e.flags,s=e.nb):typeof e=="function"&&(r=e);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+s);F(c,c.length-4,0),c[4]=Ce.SETSTAT;let f=this._writeReqid=this._writeReqid+1&ft;F(c,f,5),F(c,o,a),c.utf8Write(t,a+=4,o),F(c,i,a+=o),s&&(a+=4,s===ve.length?c.set(ve,a):Hr(ve,c,0,s,a),a+=s),this._requests[f]={cb:r};let u=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"Buffered":"Sending"} SETSTAT`)}fsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let i=0,s=0;typeof e=="object"&&e!==null?(e=tn(e),i=e.flags,s=e.nb):typeof e=="function"&&(r=e);let o=t.length,a=9,c=Buffer.allocUnsafe(13+o+4+s);F(c,c.length-4,0),c[4]=Ce.FSETSTAT;let f=this._writeReqid=this._writeReqid+1&ft;F(c,f,5),F(c,o,a),c.set(t,a+=4),F(c,i,a+=o),s&&(a+=4,s===ve.length?c.set(ve,a):Hr(ve,c,0,s,a),a+=s),this._requests[f]={cb:r};let u=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"Buffered":"Sending"} FSETSTAT`)}futimes(t,e,r,i){return this.fsetstat(t,{atime:Cn(e),mtime:Cn(r)},i)}utimes(t,e,r,i){return this.setstat(t,{atime:Cn(e),mtime:Cn(r)},i)}fchown(t,e,r,i){return this.fsetstat(t,{uid:e,gid:r},i)}chown(t,e,r,i){return this.setstat(t,{uid:e,gid:r},i)}fchmod(t,e,r){return this.fsetstat(t,{mode:e},r)}chmod(t,e,r){return this.setstat(t,{mode:e},r)}readlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.READLINK;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:(c,f)=>{if(typeof e=="function"){if(c)return e(c);if(!f||!f.length)return e(new Error("Response missing link info"));e(void 0,f[0].filename)}}};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} READLINK`)}symlink(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),s=Buffer.byteLength(t),o=9,a=Buffer.allocUnsafe(13+i+4+s);F(a,a.length-4,0),a[4]=Ce.SYMLINK;let c=this._writeReqid=this._writeReqid+1&ft;F(a,c,5),this._isOpenSSH?(F(a,s,o),a.utf8Write(t,o+=4,s),F(a,i,o+=s),a.utf8Write(e,o+=4,i)):(F(a,i,o),a.utf8Write(e,o+=4,i),F(a,s,o+=i),a.utf8Write(t,o+=4,s)),this._requests[c]={cb:r};let f=ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} SYMLINK`)}realpath(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Ce.REALPATH;let o=this._writeReqid=this._writeReqid+1&ft;F(s,o,5),F(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:(c,f)=>{if(typeof e=="function"){if(c)return e(c);if(!f||!f.length)return e(new Error("Response missing path info"));e(void 0,f[0].filename)}}};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REALPATH`)}ext_openssh_rename(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=this._extensions["posix-rename@openssh.com"];if(!i||i!=="1")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(41+s+4+o);F(c,c.length-4,0),c[4]=Ce.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ft;F(c,f,5),F(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),F(c,s,a+=24),c.utf8Write(t,a+=4,s),F(c,o,a+=s),c.utf8Write(e,a+=4,o),this._requests[f]={cb:r};let u=ze(this,c);if(this._debug){let h=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} posix-rename@openssh.com`)}}ext_openssh_statvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=this._extensions["statvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),s=9,o=Buffer.allocUnsafe(36+i);F(o,o.length-4,0),o[4]=Ce.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;F(o,a,5),F(o,19,s),o.utf8Write("statvfs@openssh.com",s+=4,19),F(o,i,s+=19),o.utf8Write(t,s+=4,i),this._requests[a]={extended:"statvfs@openssh.com",cb:e};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} statvfs@openssh.com`)}}ext_openssh_fstatvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=this._extensions["fstatvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let i=t.length,s=9,o=Buffer.allocUnsafe(37+i);F(o,o.length-4,0),o[4]=Ce.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;F(o,a,5),F(o,20,s),o.utf8Write("fstatvfs@openssh.com",s+=4,20),F(o,i,s+=20),o.set(t,s+=4),this._requests[a]={extended:"fstatvfs@openssh.com",cb:e};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} fstatvfs@openssh.com`)}}ext_openssh_hardlink(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["hardlink@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(37+s+4+o);F(c,c.length-4,0),c[4]=Ce.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ft;F(c,f,5),F(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),F(c,s,a+=20),c.utf8Write(t,a+=4,s),F(c,o,a+=s),c.utf8Write(e,a+=4,o),this._requests[f]={cb:r};let u=ze(this,c);if(this._debug){let h=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} hardlink@openssh.com`)}}ext_openssh_fsync(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["fsync@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let i=t.length,s=9,o=Buffer.allocUnsafe(34+i);F(o,o.length-4,0),o[4]=Ce.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;F(o,a,5),F(o,17,s),o.utf8Write("fsync@openssh.com",s+=4,17),F(o,i,s+=17),o.set(t,s+=4),this._requests[a]={cb:e};let c=ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${c?"Buffered":"Sending"} fsync@openssh.com`)}ext_openssh_lsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["lsetstat@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let s=0,o=0;typeof e=="object"&&e!==null?(e=tn(e),s=e.flags,o=e.nb):typeof e=="function"&&(r=e);let a=Buffer.byteLength(t),c=9,f=Buffer.allocUnsafe(37+a+4+o);F(f,f.length-4,0),f[4]=Ce.EXTENDED;let u=this._writeReqid=this._writeReqid+1&ft;F(f,u,5),F(f,20,c),f.utf8Write("lsetstat@openssh.com",c+=4,20),F(f,a,c+=20),f.utf8Write(t,c+=4,a),F(f,s,c+=a),o&&(c+=4,o===ve.length?f.set(ve,c):Hr(ve,f,0,o,c),c+=o),this._requests[u]={cb:r};let h=ze(this,f);if(this._debug){let d=h?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${d} lsetstat@openssh.com`)}}ext_openssh_expandPath(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["expand-path@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),s=9,o=Buffer.allocUnsafe(40+i);F(o,o.length-4,0),o[4]=Ce.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;F(o,a,5),F(o,23,s),o.utf8Write("expand-path@openssh.com",s+=4,23),F(o,i,s+=20),o.utf8Write(t,s+=4,i),this._requests[a]={cb:(f,u)=>{if(typeof e=="function"){if(f)return e(f);if(!u||!u.length)return e(new Error("Response missing expanded path"));e(void 0,u[0].filename)}}};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} expand-path@openssh.com`)}}ext_copy_data(t,e,r,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["copy-data"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("Source handle is not a Buffer");if(!Buffer.isBuffer(i))throw new Error("Destination handle is not a Buffer");let c=0,f=Buffer.allocUnsafe(26+t.length+8+8+4+i.length+8);F(f,f.length-4,c),c+=4,f[c]=Ce.EXTENDED,++c;let u=this._writeReqid=this._writeReqid+1&ft;F(f,u,c),c+=4,F(f,9,c),c+=4,f.utf8Write("copy-data",c,9),c+=9,F(f,t.length,c),c+=4,f.set(t,c),c+=t.length;for(let d=7;d>=0;--d)f[c+d]=e&255,e/=256;c+=8;for(let d=7;d>=0;--d)f[c+d]=r&255,r/=256;c+=8,F(f,i.length,c),c+=4,f.set(i,c),c+=i.length;for(let d=7;d>=0;--d)f[c+d]=s&255,s/=256;this._requests[u]={cb:o};let h=ze(this,f);if(this._debug){let d=h?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${d} copy-data`)}}ext_home_dir(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["home-directory"]!=="1")throw new Error("Server does not support this extended request");if(typeof t!="string")throw new TypeError("username is not a string");let i=0,s=Buffer.byteLength(t),o=Buffer.allocUnsafe(31+s);F(o,o.length-4,i),i+=4,o[i]=Ce.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&ft;F(o,a,i),i+=4,F(o,14,i),i+=4,o.utf8Write("home-directory",i,14),i+=14,F(o,s,i),i+=4,o.utf8Write(t,i,s),i+=s,this._requests[a]={cb:(f,u)=>{if(typeof e=="function"){if(f)return e(f);if(!u||!u.length)return e(new Error("Response missing home directory"));e(void 0,u[0].filename)}}};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} home-directory`)}}ext_users_groups(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["users-groups-by-id@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Array.isArray(t))throw new TypeError("uids is not an array");for(let f of t)if(!Number.isInteger(f)||f<0||f>2**32-1)throw new Error("uid values must all be 32-bit unsigned integers");if(!Array.isArray(e))throw new TypeError("gids is not an array");for(let f of e)if(!Number.isInteger(f)||f<0||f>2**32-1)throw new Error("gid values must all be 32-bit unsigned integers");let s=0,o=Buffer.allocUnsafe(47+4*t.length+4+4*e.length);F(o,o.length-4,s),s+=4,o[s]=Ce.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&ft;F(o,a,s),s+=4,F(o,30,s),s+=4,o.utf8Write("users-groups-by-id@openssh.com",s,30),s+=30,F(o,4*t.length,s),s+=4;for(let f of t)F(o,f,s),s+=4;F(o,4*e.length,s),s+=4;for(let f of e)F(o,f,s),s+=4;this._requests[a]={extended:"users-groups-by-id@openssh.com",cb:r};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} users-groups-by-id@openssh.com`)}}handle(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(!Buffer.isBuffer(e))throw new Error("handle is not a Buffer");let r=e.length;if(r>256)throw new Error("handle too large (> 256 bytes)");let i=9,s=Buffer.allocUnsafe(13+r);F(s,s.length-4,0),s[4]=Vt.HANDLE,F(s,t,5),F(s,r,i),r&&s.set(e,i+=4);let o=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${o?"Buffered":"Sending"} HANDLE`)}status(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");if(!R0.has(e))throw new Error(`Bad status code: ${e}`);r||(r="");let i=Buffer.byteLength(r),s=9,o=Buffer.allocUnsafe(17+i+4);F(o,o.length-4,0),o[4]=Vt.STATUS,F(o,t,5),F(o,e,s),F(o,i,s+=4),s+=4,i&&(o.utf8Write(r,s,i),s+=i),F(o,0,s);let a=ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STATUS`)}data(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");let i=Buffer.isBuffer(e);if(!i&&typeof e!="string")throw new Error("data is not a Buffer or string");let s;!i&&!r&&(r=void 0,s=!0);let o=i?e.length:Buffer.byteLength(e,r),a=9,c=Buffer.allocUnsafe(13+o);F(c,c.length-4,0),c[4]=Vt.DATA,F(c,t,5),F(c,o,a),o&&(i?c.set(e,a+=4):s?c.utf8Write(e,a+=4,o):c.write(e,a+=4,o,r));let f=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} DATA`)}name(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(!Array.isArray(e)){if(typeof e!="object"||e===null)throw new Error("names is not an object or array");e=[e]}let r=e.length,i=0,s,o=[];for(let u=0;u<r;++u){let h=e[u],d=!h||!h.filename||typeof h.filename!="string"?"":h.filename;i+=4+Buffer.byteLength(d);let g=!h||!h.longname||typeof h.longname!="string"?"":h.longname;if(i+=4+Buffer.byteLength(g),typeof h.attrs=="object"&&h.attrs!==null){if(s=tn(h.attrs),i+=4+s.nb,s.nb){let _;s.nb===ve.length?_=new Uint8Array(ve):(_=new Uint8Array(s.nb),Hr(ve,_,0,s.nb,0)),s.bytes=_}o.push(s)}else i+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+i);F(c,c.length-4,0),c[4]=Vt.NAME,F(c,t,5),F(c,r,a),a+=4;for(let u=0;u<r;++u){let h=e[u];{let g=!h||!h.filename||typeof h.filename!="string"?"":h.filename,_=Buffer.byteLength(g);F(c,_,a),a+=4,_&&(c.utf8Write(g,a,_),a+=_)}{let g=!h||!h.longname||typeof h.longname!="string"?"":h.longname,_=Buffer.byteLength(g);F(c,_,a),a+=4,_&&(c.utf8Write(g,a,_),a+=_)}let d=o[u];d?(F(c,d.flags,a),a+=4,d.flags&&d.bytes&&(c.set(d.bytes,a),a+=d.nb)):(F(c,0,a),a+=4)}let f=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} NAME`)}attrs(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(typeof e!="object"||e===null)throw new Error("attrs is not an object");e=tn(e);let r=e.flags,i=e.nb,s=9,o=Buffer.allocUnsafe(13+i);F(o,o.length-4,0),o[4]=Vt.ATTRS,F(o,t,5),F(o,r,s),i&&(s+=4,i===ve.length?o.set(ve,s):Hr(ve,o,0,i,s),s+=i);let a=ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function O0(n){try{return Buffer.allocUnsafe(n)}catch(t){return t}}function Sh(n,t,e,r,i,s,o,a){let c=n._maxReadLen,f=Math.max(i-c,0);f&&(i=c);let u=t.length,h=9,d=s,g=Buffer.allocUnsafe(13+u+8+4);F(g,g.length-4,0),g[4]=Ce.READ;let _=n._writeReqid=n._writeReqid+1&ft;F(g,_,5),F(g,u,h),g.set(t,h+=4),h+=u;for(let I=7;I>=0;--I)g[h+I]=d&255,d/=256;F(g,i,h+=8),typeof o!="function"&&(o=xh);let y=a||{nb:0,position:s,off:r,origOff:r,len:void 0,overflow:void 0,cb:(I,O,$)=>{let L=y.len,j=y.overflow;if(I){if(o._wantEOFError||I.code!==Ze.EOF)return o(I)}else{if($>L)return o(new Error("Received more data than requested"));if($===L&&j){y.nb+=$,y.position+=$,y.off+=$,Sh(n,t,e,y.off,j,y.position,o,y);return}}$=$||0,y.origOff===0&&e.length===y.nb?O=e:O=vn(e,y.origOff,y.origOff+y.nb+$),o(void 0,y.nb+$,O,y.position)},buffer:void 0};y.len=i,y.overflow=f,y.buffer=vn(e,r,r+i),n._requests[_]=y;let x=ze(n,g);n._debug&&n._debug(`SFTP: Outbound: ${x?"Buffered":"Sending"} READ`)}function mh(n,t,e,r,i,s){let o=64,a=32768,c,f,u;typeof i=="function"?s=i:typeof i=="object"&&i!==null&&(typeof i.concurrency=="number"&&i.concurrency>0&&!isNaN(i.concurrency)&&(o=i.concurrency),typeof i.chunkSize=="number"&&i.chunkSize>0&&!isNaN(i.chunkSize)&&(a=i.chunkSize),typeof i.fileSize=="number"&&i.fileSize>0&&!isNaN(i.fileSize)&&(u=i.fileSize),typeof i.step=="function"&&(c=i.step),(typeof i.mode=="string"||typeof i.mode=="number")&&(f=fa(i.mode)));let h,d=0,g=0,_=!1,y,x,I,O=a*o;function $(L){if(_)return;_=!0;let j=0,J;y||x?(J=()=>{--j===0&&s(L)},y&&(n===Mr||n.outgoing.state==="open")&&++j,x&&(t===Mr||t.outgoing.state==="open")&&++j,y&&(n===Mr||n.outgoing.state==="open")&&n.close(y,J),x&&(t===Mr||t.outgoing.state==="open")&&t.close(x,J)):s(L)}n.open(e,"r",(L,j)=>{if(L)return $(L);y=j,u===void 0?n.fstat(y,J):J(null,{size:u});function J(z,S){if(z){if(n!==Mr){n.stat(e,(w,U)=>{if(w)return $(z);J(null,U)});return}return $(z)}h=S.size,t.open(r,"w",(w,U)=>{if(w)return $(w);if(x=U,h<=0)return $();for(;O>h;){if(o===1){O=h;break}O-=a,--o}if(I=O0(O),I instanceof Error)return $(I);f!==void 0?t.fchmod(x,f,function Z(re){if(re){t.chmod(r,f,ae=>Z());return}te()}):te();function W(Z,re,ae,T,C,v){if(Z)return $(Z);C=C||0,t.write(x,I,C,re,T,D);function D(G){if(G)return $(G);if(g+=re,c&&c(g,re,h),re<v)return oe(C,T+re,v-re);if(g===h){t.close(x,ee=>{if(x=void 0,ee)return $(ee);n.close(y,Ve=>{if(y=void 0,Ve)return $(Ve);s()})});return}if(d>=h)return;let se=d+a>h?h-d:a;oe(C,d,se),d+=se}}function Q(Z,re,ae){return(T,C,v)=>{W(T,C,v,re,Z,ae)}}function oe(Z,re,ae){n.read(y,I,Z,ae,re,Q(Z,re,ae))}function te(){let Z=0,re=0;for(;d<h&&Z<o;){let ae=d+a>h?h-d:a;oe(re,d,ae),re+=ae,d+=ae,++Z}}})}})}function ia(n,t,e,r,i,s,o){let a=typeof o=="function"?o:void 0;n.write(t,e,r,i,s,(c,f)=>{if(c)return n.close(t,()=>{a&&a(c)});f===i?n.close(t,a):(r+=f,i-=f,s+=f,ia(n,t,e,r,i,s,a))})}var gs=class{constructor(t){this.mode=t&&t.mode,this.uid=t&&t.uid,this.gid=t&&t.gid,this.size=t&&t.size,this.atime=t&&t.atime,this.mtime=t&&t.mtime,this.extended=t&&t.extended}isDirectory(){return(this.mode&Yt.S_IFMT)===Yt.S_IFDIR}isFile(){return(this.mode&Yt.S_IFMT)===Yt.S_IFREG}isBlockDevice(){return(this.mode&Yt.S_IFMT)===Yt.S_IFBLK}isCharacterDevice(){return(this.mode&Yt.S_IFMT)===Yt.S_IFCHR}isSymbolicLink(){return(this.mode&Yt.S_IFMT)===Yt.S_IFLNK}isFIFO(){return(this.mode&Yt.S_IFMT)===Yt.S_IFIFO}isSocket(){return(this.mode&Yt.S_IFMT)===Yt.S_IFSOCK}};function tn(n){let t=0,e=0;if(typeof n=="object"&&n!==null){if(typeof n.size=="number"){t|=Br.SIZE;let r=n.size;ve[e++]=r/72057594037927940,ve[e++]=r/281474976710656,ve[e++]=r/1099511627776,ve[e++]=r/4294967296,ve[e++]=r/16777216,ve[e++]=r/65536,ve[e++]=r/256,ve[e++]=r}if(typeof n.uid=="number"&&typeof n.gid=="number"){t|=Br.UIDGID;let r=n.uid,i=n.gid;ve[e++]=r>>>24,ve[e++]=r>>>16,ve[e++]=r>>>8,ve[e++]=r,ve[e++]=i>>>24,ve[e++]=i>>>16,ve[e++]=i>>>8,ve[e++]=i}if(typeof n.mode=="number"||typeof n.mode=="string"){let r=fa(n.mode);t|=Br.PERMISSIONS,ve[e++]=r>>>24,ve[e++]=r>>>16,ve[e++]=r>>>8,ve[e++]=r}if((typeof n.atime=="number"||ra(n.atime))&&(typeof n.mtime=="number"||ra(n.mtime))){let r=Cn(n.atime),i=Cn(n.mtime);t|=Br.ACMODTIME,ve[e++]=r>>>24,ve[e++]=r>>>16,ve[e++]=r>>>8,ve[e++]=r,ve[e++]=i>>>24,ve[e++]=i>>>16,ve[e++]=i>>>8,ve[e++]=i}}return{flags:t,nb:e}}function Cn(n){if(typeof n=="number"&&n===n)return n;if(ra(n))return parseInt(n.getTime()/1e3,10);throw new Error(`Cannot parse time: ${n}`)}function fa(n){if(typeof n=="number"&&n===n)return n;if(typeof n=="string")return fa(parseInt(n,8));throw new Error(`Cannot parse mode: ${n}`)}var sa={r:Se.READ,"r+":Se.READ|Se.WRITE,w:Se.TRUNC|Se.CREAT|Se.WRITE,wx:Se.TRUNC|Se.CREAT|Se.WRITE|Se.EXCL,xw:Se.TRUNC|Se.CREAT|Se.WRITE|Se.EXCL,"w+":Se.TRUNC|Se.CREAT|Se.READ|Se.WRITE,"wx+":Se.TRUNC|Se.CREAT|Se.READ|Se.WRITE|Se.EXCL,"xw+":Se.TRUNC|Se.CREAT|Se.READ|Se.WRITE|Se.EXCL,a:Se.APPEND|Se.CREAT|Se.WRITE,ax:Se.APPEND|Se.CREAT|Se.WRITE|Se.EXCL,xa:Se.APPEND|Se.CREAT|Se.WRITE|Se.EXCL,"a+":Se.APPEND|Se.CREAT|Se.READ|Se.WRITE,"ax+":Se.APPEND|Se.CREAT|Se.READ|Se.WRITE|Se.EXCL,"xa+":Se.APPEND|Se.CREAT|Se.READ|Se.WRITE|Se.EXCL};function wh(n){let t=sa[n];return t!==void 0?t:null}var D0=(()=>{let n=Object.keys(sa);return t=>{for(let e=0;e<n.length;++e){let r=n[e];if(sa[r]===t)return r}return null}})();function Bn(n){let t=N.readUInt32BE();if(t===void 0)return;let e=new gs;if(t&Br.SIZE){let r=N.readUInt64BE(n);if(r===void 0)return;e.size=r}if(t&Br.UIDGID){let r=N.readUInt32BE(),i=N.readUInt32BE();if(i===void 0)return;e.uid=r,e.gid=i}if(t&Br.PERMISSIONS){let r=N.readUInt32BE();if(r===void 0)return;e.mode=r}if(t&Br.ACMODTIME){let r=N.readUInt32BE(),i=N.readUInt32BE();if(i===void 0)return;e.atime=r,e.mtime=i}if(t&Br.EXTENDED){let r=N.readUInt32BE();if(r===void 0)return;let i={};for(let s=0;s<r;++s){let o=N.readString(!0),a=N.readString();if(a===void 0)return;i[o]=a}e.extended=i}return e}function ze(n,t){let e=Ih(n,t);return e!==void 0?(n._buffer.push(e),!1):!0}function Ih(n,t){let e=n.outgoing;if(e.state!=="open")return;if(e.window===0)return n._waitWindow=!0,n._chunkcb=Ah,t;let r,i=t.length,s=0;for(;i-s>0&&e.window>0;){let o=Math.min(i-s,e.window,e.packetSize);e.window-=o,e.window===0&&(n._waitWindow=!0,n._chunkcb=Ah),s===0&&o===i?n._protocol.channelData(n.outgoing.id,t):n._protocol.channelData(n.outgoing.id,vn(t,s,s+o)),s+=o}return i-s>0&&(s>0?r=vn(t,s,i):r=t),r}function Ah(){this._chunkcb=void 0;let n=this._buffer,t=0;for(;t<n.length;){let e=n[t],r=Ih(this,e);if(r!==void 0){r!==e&&(n[t]=r),t>0&&(this._buffer=n.slice(t));return}++t}t>0&&(this._buffer=[])}function nt(n,t,e){let r=new Error(t);return r.level="sftp-protocol",!e&&n._debug&&n._debug(`SFTP: Inbound: ${t}`),n.emit("error",r),n.destroy(),Ch(n),!1}function Ch(n){let t=Object.keys(n._requests);if(t.length===0)return;let e=n._requests;n._requests={};let r=new Error("No response from server");for(let i=0;i<t.length;++i){let s=e[t[i]];typeof s.cb=="function"&&s.cb(r)}}function H0(n,t){let e=9,r=Buffer.allocUnsafe(31);F(r,r.length-4,0),r[4]=Ce.EXTENDED;let i=n._writeReqid=n._writeReqid+1&ft;F(r,i,5),F(r,18,e),r.utf8Write("limits@openssh.com",e+=4,18),n._requests[i]={extended:"limits@openssh.com",cb:t};let s=ze(n,r);if(n._debug){let o=s?"Buffered":"Sending";n._debug(`SFTP: Outbound: ${o} limits@openssh.com`)}}var M0={[Vt.VERSION]:(n,t)=>{if(n._version!==-1)return nt(n,"Duplicate VERSION packet");let e={};N.init(t,1);let r=N.readUInt32BE();for(;N.avail();){let i=N.readString(!0),s=N.readString(!0);if(s===void 0){r=void 0;break}e[i]=s}if(N.clear(),r===void 0)return nt(n,"Malformed VERSION packet");if(n._debug){let i=Object.keys(e);i.length?n._debug(`SFTP: Inbound: Received VERSION (v${r}, exts:${i})`):n._debug(`SFTP: Inbound: Received VERSION (v${r})`)}if(n._version=r,n._extensions=e,e["limits@openssh.com"]==="1")return H0(n,(i,s)=>{i||(s.maxPktLen>0&&(n._maxOutPktLen=s.maxPktLen),s.maxReadLen>0&&(n._maxReadLen=s.maxReadLen),s.maxWriteLen>0&&(n._maxWriteLen=s.maxWriteLen),n.maxOpenHandles=s.maxOpenHandles>0?s.maxOpenHandles:1/0),n.emit("ready")});n.emit("ready")},[Vt.STATUS]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readUInt32BE(),i=N.readString(!0);if(N.clear(),n._debug){let o=JSON.stringify(i);n._debug(`SFTP: Inbound: Received STATUS (id:${e}, ${r}, ${o})`)}let s=n._requests[e];if(delete n._requests[e],s&&typeof s.cb=="function"){if(r===Ze.OK){s.cb();return}let o=new Error(i||N0[r]||"Unknown status");o.code=r,s.cb(o)}},[Vt.HANDLE]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString();if(N.clear(),r===void 0)return e!==void 0&&delete n._requests[e],nt(n,"Malformed HANDLE packet");n._debug&&n._debug(`SFTP: Inbound: Received HANDLE (id:${e})`);let i=n._requests[e];delete n._requests[e],i&&typeof i.cb=="function"&&i.cb(void 0,r)},[Vt.DATA]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r;if(e!==void 0&&(r=n._requests[e],delete n._requests[e]),r&&typeof r.cb=="function")if(r.buffer){let i=N.readString(r.buffer);if(N.clear(),i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i})`),r.cb(void 0,r.buffer,i);return}}else{let i=N.readString();if(N.clear(),i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i.length})`),r.cb(void 0,i);return}}else{let i=N.skipString();if(N.clear(),i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i})`);return}}return nt(n,"Malformed DATA packet")},[Vt.NAME]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let i=N.readUInt32BE();if(i!==void 0){let s=[];for(let o=0;o<i;++o){let a=N.readString(!0),c=N.readString(!0),f=Bn(n._biOpt);if(f===void 0){s=void 0;break}s.push({filename:a,longname:c,attrs:f})}if(s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received NAME (id:${e}, ${s.length})`),N.clear(),r&&typeof r.cb=="function"&&r.cb(void 0,s);return}}return N.clear(),nt(n,"Malformed NAME packet")},[Vt.ATTRS]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let i=Bn(n._biOpt);if(N.clear(),i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received ATTRS (id:${e})`),r&&typeof r.cb=="function"&&r.cb(void 0,i);return}return nt(n,"Malformed ATTRS packet")},[Vt.EXTENDED]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE();if(e!==void 0){let r=n._requests[e];if(r)switch(delete n._requests[e],r.extended){case"statvfs@openssh.com":case"fstatvfs@openssh.com":{let i=n._biOpt,s={f_bsize:N.readUInt64BE(i),f_frsize:N.readUInt64BE(i),f_blocks:N.readUInt64BE(i),f_bfree:N.readUInt64BE(i),f_bavail:N.readUInt64BE(i),f_files:N.readUInt64BE(i),f_ffree:N.readUInt64BE(i),f_favail:N.readUInt64BE(i),f_sid:N.readUInt64BE(i),f_flag:N.readUInt64BE(i),f_namemax:N.readUInt64BE(i)};if(s.f_namemax===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),N.clear(),typeof r.cb=="function"&&r.cb(void 0,s);return}case"limits@openssh.com":{let i={maxPktLen:N.readUInt64BE(),maxReadLen:N.readUInt64BE(),maxWriteLen:N.readUInt64BE(),maxOpenHandles:N.readUInt64BE()};if(i.maxOpenHandles===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),N.clear(),typeof r.cb=="function"&&r.cb(void 0,i);return}case"users-groups-by-id@openssh.com":{let i=N.readUInt32BE();if(i===void 0)break;let s=new Array(i);for(let c=0;c<s.length;++c)s[c]=N.readString(!0);let o=N.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=N.readString(!0);if(a.length>0&&a[a.length-1]===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),N.clear(),typeof r.cb=="function"&&r.cb(void 0,s,a);return}default:n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),N.clear(),typeof r.cb=="function"&&r.cb();return}else{n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),N.clear();return}}return N.clear(),nt(n,"Malformed EXTENDED_REPLY packet")}},F0={[Ce.INIT]:(n,t)=>{if(n._version!==-1)return nt(n,"Duplicate INIT packet");let e={};N.init(t,1);let r=N.readUInt32BE();for(;N.avail();){let i=N.readString(!0),s=N.readString(!0);if(s===void 0){r=void 0;break}e[i]=s}if(N.clear(),r===void 0)return nt(n,"Malformed INIT packet");if(n._debug){let i=Object.keys(e);i.length?n._debug(`SFTP: Inbound: Received INIT (v${r}, exts:${i})`):n._debug(`SFTP: Inbound: Received INIT (v${r})`)}ze(n,T0),n._version=r,n._extensions=e,n.emit("ready")},[Ce.OPEN]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0),i=N.readUInt32BE(),s=Bn(n._biOpt);if(N.clear(),s===void 0)return nt(n,"Malformed OPEN packet");n._debug&&n._debug(`SFTP: Inbound: Received OPEN (id:${e})`),n.emit("OPEN",e,r,i,s)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.CLOSE]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString();if(N.clear(),r===void 0||r.length>256)return nt(n,"Malformed CLOSE packet");n._debug&&n._debug(`SFTP: Inbound: Received CLOSE (id:${e})`),n.emit("CLOSE",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.READ]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(),i=N.readUInt64BE(n._biOpt),s=N.readUInt32BE();if(N.clear(),s===void 0||r.length>256)return nt(n,"Malformed READ packet");n._debug&&n._debug(`SFTP: Inbound: Received READ (id:${e})`),n.emit("READ",e,r,i,s)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.WRITE]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(),i=N.readUInt64BE(n._biOpt),s=N.readString();if(N.clear(),s===void 0||r.length>256)return nt(n,"Malformed WRITE packet");n._debug&&n._debug(`SFTP: Inbound: Received WRITE (id:${e})`),n.emit("WRITE",e,r,i,s)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.LSTAT]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0);if(N.clear(),r===void 0)return nt(n,"Malformed LSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received LSTAT (id:${e})`),n.emit("LSTAT",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.FSTAT]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString();if(N.clear(),r===void 0||r.length>256)return nt(n,"Malformed FSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSTAT (id:${e})`),n.emit("FSTAT",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.SETSTAT]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0),i=Bn(n._biOpt);if(N.clear(),i===void 0)return nt(n,"Malformed SETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received SETSTAT (id:${e})`),n.emit("SETSTAT",e,r,i)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.FSETSTAT]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(),i=Bn(n._biOpt);if(N.clear(),i===void 0||r.length>256)return nt(n,"Malformed FSETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSETSTAT (id:${e})`),n.emit("FSETSTAT",e,r,i)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.OPENDIR]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0);if(N.clear(),r===void 0)return nt(n,"Malformed OPENDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received OPENDIR (id:${e})`),n.emit("OPENDIR",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.READDIR]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString();if(N.clear(),r===void 0||r.length>256)return nt(n,"Malformed READDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received READDIR (id:${e})`),n.emit("READDIR",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.REMOVE]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0);if(N.clear(),r===void 0)return nt(n,"Malformed REMOVE packet");n._debug&&n._debug(`SFTP: Inbound: Received REMOVE (id:${e})`),n.emit("REMOVE",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.MKDIR]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0),i=Bn(n._biOpt);if(N.clear(),i===void 0)return nt(n,"Malformed MKDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received MKDIR (id:${e})`),n.emit("MKDIR",e,r,i)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.RMDIR]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0);if(N.clear(),r===void 0)return nt(n,"Malformed RMDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received RMDIR (id:${e})`),n.emit("RMDIR",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.REALPATH]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0);if(N.clear(),r===void 0)return nt(n,"Malformed REALPATH packet");n._debug&&n._debug(`SFTP: Inbound: Received REALPATH (id:${e})`),n.emit("REALPATH",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.STAT]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0);if(N.clear(),r===void 0)return nt(n,"Malformed STAT packet");n._debug&&n._debug(`SFTP: Inbound: Received STAT (id:${e})`),n.emit("STAT",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.RENAME]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0),i=N.readString(!0);if(N.clear(),i===void 0)return nt(n,"Malformed RENAME packet");n._debug&&n._debug(`SFTP: Inbound: Received RENAME (id:${e})`),n.emit("RENAME",e,r,i)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.READLINK]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0);if(N.clear(),r===void 0)return nt(n,"Malformed READLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received READLINK (id:${e})`),n.emit("READLINK",e,r)||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.SYMLINK]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0),i=N.readString(!0);if(N.clear(),i===void 0)return nt(n,"Malformed SYMLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received SYMLINK (id:${e})`);let s;n._isOpenSSH?s=n.emit("SYMLINK",e,i,r):s=n.emit("SYMLINK",e,r,i),s||n.status(e,Ze.OP_UNSUPPORTED)},[Ce.EXTENDED]:(n,t)=>{N.init(t,1);let e=N.readUInt32BE(),r=N.readString(!0);if(r===void 0)return N.clear(),nt(n,"Malformed EXTENDED packet");let i;N.avail()&&(i=N.readRaw()),N.clear(),n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED (id:${e})`),n.emit("EXTENDED",e,r,i)||n.status(e,Ze.OP_UNSUPPORTED)}},{ERR_INVALID_ARG_TYPE:Q0,ERR_OUT_OF_RANGE:ps,validateNumber:$0}=ph(),Eh=128,qt,oa=[];function W0(n){oa.length>0?qt=oa.pop():qt=Buffer.allocUnsafe(n),qt.used=0}function aa(n,t){if(!Number.isSafeInteger(n))throw $0(n,t),Number.isInteger(n)?new ps(t,">= 0 and <= 2 ** 53 - 1",n):new ps(t,"an integer",n);if(n<0)throw new ps(t,">= 0 and <= 2 ** 53 - 1",n)}function ta(n){return n+7&-8}function vr(n,t,e){if(e===void 0)e={};else if(typeof e=="string")e={encoding:e};else{if(e===null||typeof e!="object")throw new TypeError('"options" argument must be a string or an object');e=Object.create(e)}if(e.highWaterMark===void 0&&(e.highWaterMark=64*1024),e.emitClose=!1,e.autoDestroy=!1,yh.call(this,e),this.path=t,this.flags=e.flags===void 0?"r":e.flags,this.mode=e.mode===void 0?438:e.mode,this.start=e.start,this.end=e.end,this.autoClose=e.autoClose===void 0?!0:e.autoClose,this.pos=0,this.bytesRead=0,this.isClosed=!1,this.handle=e.handle===void 0?null:e.handle,this.sftp=n,this._opening=!1,this.start!==void 0&&(aa(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(aa(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new ps("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}bh(vr,yh);vr.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(n,t)=>{if(this._opening=!1,n){this.emit("error",n),this.autoClose&&this.destroy();return}this.handle=t,this.emit("open",t),this.emit("ready"),this.read()}))};vr.prototype._read=function(n){if(!Buffer.isBuffer(this.handle))return this.once("open",()=>this._read(n));if(this.destroyed)return;(!qt||qt.length-qt.used<Eh)&&W0(this.readableHighWaterMark||this._readableState.highWaterMark);let t=qt,e=Math.min(qt.length-qt.used,n),r=qt.used;if(this.end!==void 0&&(e=Math.min(this.end-this.pos+1,e)),e<=0)return this.push(null);this.sftp.read(this.handle,qt,qt.used,e,this.pos,(i,s)=>{if(i){this.emit("error",i),this.autoClose&&this.destroy();return}let o=null;if(r+e===t.used&&t===qt)t.used=ta(t.used+s-e);else{let a=r+e&-8,c=ta(r+s);a-c>=Eh&&oa.push(t.slice(c,a))}s>0&&(this.bytesRead+=s,o=t.slice(r,r+s)),this.pos+=s,this.push(o)}),qt.used=ta(qt.used+e)};vr.prototype._destroy=function(n,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",_h.bind(null,this,t,n));return}_h(this,t,n),this.handle=null,this._opening=!1};function _h(n,t,e){if(!n.handle)return r();n.sftp.close(n.handle,r);function r(i){i=i||e,t(i),n.isClosed=!0,i||n.emit("close")}}vr.prototype.close=function(n){this.destroy(null,n)};Object.defineProperty(vr.prototype,"pending",{get(){return this.handle===null},configurable:!0});function sr(n,t,e){if(e===void 0)e={};else if(typeof e=="string")e={encoding:e};else{if(e===null||typeof e!="object")throw new TypeError('"options" argument must be a string or an object');e=Object.create(e)}e.emitClose=!1,e.autoDestroy=!1,ca.call(this,e),this.path=t,this.flags=e.flags===void 0?"w":e.flags,this.mode=e.mode===void 0?438:e.mode,this.start=e.start,this.autoClose=e.autoClose===void 0?!0:e.autoClose,this.pos=0,this.bytesWritten=0,this.isClosed=!1,this.handle=e.handle===void 0?null:e.handle,this.sftp=n,this._opening=!1,this.start!==void 0&&(aa(this.start,"start"),this.pos=this.start),e.encoding&&this.setDefaultEncoding(e.encoding),this.on("finish",function(){this._writableState.finalCalled||this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}bh(sr,ca);sr.prototype._final=function(n){this.autoClose&&this.destroy(),n()};sr.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(n,t)=>{if(this._opening=!1,n){this.emit("error",n),this.autoClose&&this.destroy();return}this.handle=t;let e=r=>{if(r){this.sftp.chmod(this.path,this.mode,i=>e());return}if(this.flags[0]==="a"){let i=(s,o)=>{if(s){this.sftp.stat(this.path,(a,c)=>{if(a){this.destroy(),this.emit("error",s);return}i(null,c)});return}this.pos=o.size,this.emit("open",t),this.emit("ready")};this.sftp.fstat(t,i);return}this.emit("open",t),this.emit("ready")};this.sftp.fchmod(t,this.mode,e)}))};sr.prototype._write=function(n,t,e){if(!Buffer.isBuffer(n)){let r=new Q0("data","Buffer",n);return this.emit("error",r)}if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._write(n,t,e)});this.sftp.write(this.handle,n,0,n.length,this.pos,(r,i)=>{if(r)return this.autoClose&&this.destroy(),e(r);this.bytesWritten+=i,e()}),this.pos+=n.length};sr.prototype._writev=function(n,t){if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._writev(n,t)});let e=this.sftp,r=this.handle,i=n.length,s=(o,a)=>{if(o)return this.destroy(),t(o);this.bytesWritten+=a,--i===0&&t()};for(let o=0;o<n.length;++o){let a=n[o].chunk;e.write(r,a,0,a.length,this.pos,s),this.pos+=a.length}};typeof ca.prototype.destroy!="function"&&(sr.prototype.destroy=vr.prototype.destroy);sr.prototype._destroy=vr.prototype._destroy;sr.prototype.close=function(n){if(n){if(this.isClosed){process.nextTick(n);return}this.on("close",n)}this.autoClose||this.on("finish",this.destroy.bind(this)),this.end()};sr.prototype.destroySoon=sr.prototype.end;Object.defineProperty(sr.prototype,"pending",{get(){return this.handle===null},configurable:!0});Bh.exports={flagsToString:D0,OPEN_MODE:Se,SFTP:na,Stats:gs,STATUS_CODE:Ze,stringToFlags:wh}});var ga=ot((Fb,Nh)=>{"use strict";var{Duplex:q0,Readable:K0,Writable:G0}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:vh}}=wr(),{bufferSlice:ms}=or(),Y0=32*1024,hi=2*1024*1024,da=hi/2,ua=class extends K0{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=da&&pa(this._channel))}},la=class extends G0{constructor(t){super({highWaterMark:hi}),this._channel=t}_write(t,e,r){let i=this._channel,s=i._client._protocol,o=i.outgoing,a=o.packetSize,c=o.id,f=o.window,u=t.length,h=0;if(o.state==="open"){for(;u-h>0&&f>0;){let d=u-h;d>f&&(d=f),d>a&&(d=a),h===0&&d===u?s.channelExtData(c,t,vh):s.channelExtData(c,ms(t,h,h+d),vh),h+=d,f-=d}if(o.window=f,u-h>0){f===0&&(i._waitWindow=!0),h>0?i._chunkErr=ms(t,h,u):i._chunkErr=t,i._chunkcbErr=r;return}r()}}},ha=class extends q0{constructor(t,e,r){let i={highWaterMark:hi,allowHalfOpen:!r||r&&r.allowHalfOpen!==!1,emitClose:!1};super(i),this.allowHalfOpen=i.allowHalfOpen;let s=!!(r&&r.server);this.server=s,this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this._callbacks=[],this._client=t,this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this.stdin=this.stdout=this,s?this.stderr=new la(this):this.stderr=new ua(this,i),this._waitWindow=!1,this._waitChanDrain=!1,this._chunk=void 0,this._chunkcb=void 0,this._chunkErr=void 0,this._chunkcbErr=void 0,this.on("finish",kh).on("prefinish",kh),this.on("end",Rh).on("close",Rh)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=da&&pa(this))}_write(t,e,r){let i=this._client._protocol,s=this.outgoing,o=s.packetSize,a=s.id,c=s.window,f=t.length,u=0;if(s.state==="open"){for(;f-u>0&&c>0;){let h=f-u;h>c&&(h=c),h>o&&(h=o),u===0&&h===f?i.channelData(a,t):i.channelData(a,ms(t,u,u+h)),u+=h,c-=h}if(s.window=c,f-u>0){c===0&&(this._waitWindow=!0),u>0?this._chunk=ms(t,u,f):this._chunk=t,this._chunkcb=r;return}r()}}eof(){this.outgoing.state==="open"&&(this.outgoing.state="eof",this._client._protocol.channelEOF(this.outgoing.id))}close(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._client._protocol.channelClose(this.outgoing.id))}destroy(){return this.end(),this.close(),this}setWindow(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&(this.subtype==="shell"||this.subtype==="exec")&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.windowChange(this.outgoing.id,t,e,r,i)}signal(t){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.signal(this.outgoing.id,t)}exit(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&(typeof t=="number"?this._client._protocol.exitStatus(this.outgoing.id,t):this._client._protocol.exitSignal(this.outgoing.id,t,e,r))}};function kh(){this.eof(),(this.server||!this.allowHalfOpen)&&this.close(),this.writable=!1}function Rh(){this.readable=!1}function pa(n){if(n.outgoing.state==="closed")return;let t=hi-n.incoming.window;t<=0||(n.incoming.window+=t,n._client._protocol.channelWindowAdjust(n.outgoing.id,t))}Nh.exports={Channel:ha,MAX_WINDOW:hi,PACKET_SIZE:Y0,windowAdjust:pa,WINDOW_THRESHOLD:da}});var Ea=ot((Qb,Lh)=>{"use strict";var{SFTP:V0}=li(),di=2**32-1;function Ph(n,t,e,r){if(n._chanMgr.remove(t),typeof r!="function")return;let i;e instanceof Error?i=e:typeof e=="object"&&e!==null?(i=new Error(`(SSH) Channel open failure: ${e.description}`),i.reason=e.reason):(i=new Error("(SSH) Channel open failure: server closed channel unexpectedly"),i.reason=""),r(i)}function Th(n,t,e,r,i){if(typeof e=="function"){Ph(n,t,r,e);return}if(typeof e!="object"||e===null||e.incoming&&e.incoming.state==="closed"||(n._chanMgr.remove(t),e.server&&e.constructor.name==="Session"))return;e.incoming.state="closed",e.readable&&e.push(null),e.server?e.stderr.writable&&e.stderr.end():e.stderr.readable&&e.stderr.push(null),e.constructor!==V0&&(e.outgoing.state==="open"||e.outgoing.state==="eof")&&!i&&e.close(),e.outgoing.state==="closing"&&(e.outgoing.state="closed");let s=e._readableState,o=e._writableState;o&&!o.ending&&!o.finished&&!i&&e.end();let a=e._callbacks;e._callbacks=[];for(let c=0;c<a.length;++c)a[c](!0);if(e.server)!e.readable||e.destroyed||s&&s.endEmitted?e.emit("close"):e.once("end",()=>e.emit("close"));else{let c;switch(e.type){case"direct-streamlocal@openssh.com":case"direct-tcpip":c=()=>e.emit("close");break;default:{let u=e._exit;c=()=>{u.code===null?e.emit("close",u.code,u.signal,u.dump,u.desc):e.emit("close",u.code)}}}!e.readable||e.destroyed||s&&s.endEmitted?c():e.once("end",c);let f=e.stderr._readableState;!e.stderr.readable||e.stderr.destroyed||f&&f.endEmitted?e.stderr.emit("close"):e.stderr.once("end",()=>e.stderr.emit("close"))}}var Aa=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<di)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let r=this._channels;for(let i=0;i<di;++i)if(r[i]===void 0){e=i;break}}return e===void 0?-1:(this._channels[e]=t||!0,++this._count,e)}update(t,e){if(typeof t!="number"||t<0||t>=di||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);e&&this._channels[t]&&(this._channels[t]=e)}get(t){if(typeof t!="number"||t<0||t>=di||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=di||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);this._channels[t]&&(delete this._channels[t],this._count&&--this._count)}cleanup(t){let e=this._channels;this._channels={},this._cur=-1,this._count=0;let r=Object.keys(e),i=this._client;for(let s=0;s<r.length;++s){let o=+r[s],a=e[o];Th(i,o,a._channel||a,t,!0)}}},ma=(()=>{let n=Object.prototype.toString;return t=>n.call(t)==="[object RegExp]"})();function j0(n,t,e){if(Array.isArray(n)&&n.length>0){for(let r=0;r<n.length;++r)if(e.indexOf(n[r])===-1)throw new Error(`Unsupported algorithm: ${n[r]}`);return n}if(typeof n=="object"&&n!==null){let r=Object.keys(n),i=t;for(let s=0;s<r.length;++s){let o=r[s],a=n[o];switch(o){case"append":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let f=a[c];if(typeof f=="string"){if(!f||i.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);i===t&&(i=i.slice()),i.push(f)}else if(ma(f))for(let u=0;u<e.length;++u){let h=e[u];if(f.test(h)){if(i.indexOf(h)!==-1)continue;i===t&&(i=i.slice()),i.push(h)}}}break;case"prepend":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=a.length;c>=0;--c){let f=a[c];if(typeof f=="string"){if(!f||i.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);i===t&&(i=i.slice()),i.unshift(f)}else if(ma(f))for(let u=e.length;u>=0;--u){let h=e[u];if(f.test(h)){if(i.indexOf(h)!==-1)continue;i===t&&(i=i.slice()),i.unshift(h)}}}break;case"remove":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let f=a[c];if(typeof f=="string"){if(!f)continue;let u=i.indexOf(f);if(u===-1)continue;i===t&&(i=i.slice()),i.splice(u,1)}else if(ma(f))for(let u=0;u<i.length;++u)f.test(i[u])&&(i===t&&(i=i.slice()),i.splice(u,1),--u)}break}}return i}return t}Lh.exports={ChannelManager:Aa,generateAlgorithmList:j0,onChannelOpenFailure:Ph,onCHANNEL_CLOSE:Th,isWritable:n=>n&&n.writable&&n._readableState&&n._readableState.ended===!1}});var Ia=ot(($b,ed)=>{"use strict";var{createHash:z0,getHashes:X0,randomFillSync:J0}=require("crypto"),{Socket:Z0}=require("net"),{lookup:em}=require("dns"),tm=require("events"),rm=X0(),{COMPAT:Xh,CHANNEL_EXTENDED_DATATYPE:{STDERR:nm},CHANNEL_OPEN_FAILURE:pi,DEFAULT_CIPHER:Uh,DEFAULT_COMPRESSION:Oh,DEFAULT_KEX:Dh,DEFAULT_MAC:Hh,DEFAULT_SERVER_HOST_KEY:Mh,DISCONNECT_REASON:Fh,DISCONNECT_REASON_BY_VALUE:im,SUPPORTED_CIPHER:sm,SUPPORTED_COMPRESSION:om,SUPPORTED_KEX:am,SUPPORTED_MAC:cm,SUPPORTED_SERVER_HOST_KEY:fm}=wr(),{init:um}=Lr(),lm=Zo(),{parseKey:_s}=Dr(),{SFTP:hm}=li(),{bufferCopy:Qh,makeBufferParser:Jh,makeError:dm,readUInt32BE:pm,sigSSHToASN1:gm,writeUInt32BE:_a}=or(),{AgentContext:$h,createAgent:Wh,isAgent:qh}=Ho(),{Channel:Zh,MAX_WINDOW:ys,PACKET_SIZE:bs,windowAdjust:Kh,WINDOW_THRESHOLD:Gh}=ga(),{ChannelManager:mm,generateAlgorithmList:gi,isWritable:Ct,onChannelOpenFailure:Am,onCHANNEL_CLOSE:Em}=Ea(),As=Jh(),Es=Jh(),mi=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,Sa=n=>{},wa=class extends tm{constructor(){super(),this.config={host:void 0,port:void 0,localAddress:void 0,localPort:void 0,forceIPv4:void 0,forceIPv6:void 0,keepaliveCountMax:void 0,keepaliveInterval:void 0,readyTimeout:void 0,ident:void 0,username:void 0,password:void 0,privateKey:void 0,tryKeyboard:void 0,agent:void 0,allowAgentFwd:void 0,authHandler:void 0,hostHashAlgo:void 0,hostHashCb:void 0,strictVendor:void 0,debug:void 0},this._agent=void 0,this._readyTimeout=void 0,this._chanMgr=void 0,this._callbacks=void 0,this._forwarding=void 0,this._forwardingUnix=void 0,this._acceptX11=void 0,this._agentFwdEnabled=void 0,this._remoteVer=void 0,this._protocol=void 0,this._sock=void 0,this._resetKA=void 0}connect(t){if(this._sock&&Ct(this._sock))return this.once("close",()=>{this.connect(t)}),this.end(),this;this.config.host=t.hostname||t.host||"localhost",this.config.port=t.port||22,this.config.localAddress=typeof t.localAddress=="string"?t.localAddress:void 0,this.config.localPort=typeof t.localPort=="string"||typeof t.localPort=="number"?t.localPort:void 0,this.config.forceIPv4=t.forceIPv4||!1,this.config.forceIPv6=t.forceIPv6||!1,this.config.keepaliveCountMax=typeof t.keepaliveCountMax=="number"&&t.keepaliveCountMax>=0?t.keepaliveCountMax:3,this.config.keepaliveInterval=typeof t.keepaliveInterval=="number"&&t.keepaliveInterval>0?t.keepaliveInterval:0,this.config.readyTimeout=typeof t.readyTimeout=="number"&&t.readyTimeout>=0?t.readyTimeout:2e4,this.config.ident=typeof t.ident=="string"||Buffer.isBuffer(t.ident)?t.ident:void 0;let e={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:[]},sc:void 0},r=!0;if(typeof t.algorithms=="object"&&t.algorithms!==null&&(e.kex=gi(t.algorithms.kex,Dh,am),e.kex!==Dh&&(r=!1),e.serverHostKey=gi(t.algorithms.serverHostKey,Mh,fm),e.serverHostKey!==Mh&&(r=!1),e.cs.cipher=gi(t.algorithms.cipher,Uh,sm),e.cs.cipher!==Uh&&(r=!1),e.cs.mac=gi(t.algorithms.hmac,Hh,cm),e.cs.mac!==Hh&&(r=!1),e.cs.compress=gi(t.algorithms.compress,Oh,om),e.cs.compress!==Oh&&(r=!1),r||(e.sc=e.cs)),typeof t.username=="string")this.config.username=t.username;else if(typeof t.user=="string")this.config.username=t.user;else throw new Error("Invalid username");this.config.password=typeof t.password=="string"?t.password:void 0,this.config.privateKey=typeof t.privateKey=="string"||Buffer.isBuffer(t.privateKey)?t.privateKey:void 0,this.config.localHostname=typeof t.localHostname=="string"?t.localHostname:void 0,this.config.localUsername=typeof t.localUsername=="string"?t.localUsername:void 0,this.config.tryKeyboard=t.tryKeyboard===!0,typeof t.agent=="string"&&t.agent.length?this.config.agent=Wh(t.agent):qh(t.agent)?this.config.agent=t.agent:this.config.agent=void 0,this.config.allowAgentFwd=t.agentForward===!0&&this.config.agent!==void 0;let i=this.config.authHandler=typeof t.authHandler=="function"||Array.isArray(t.authHandler)?t.authHandler:void 0;this.config.strictVendor=typeof t.strictVendor=="boolean"?t.strictVendor:!0;let s=this.config.debug=typeof t.debug=="function"?t.debug:void 0;if(t.agentForward===!0&&!this.config.allowAgentFwd)throw new Error("You must set a valid agent path to allow agent forwarding");let o=this._callbacks=[];this._chanMgr=new mm(this),this._forwarding={},this._forwardingUnix={},this._acceptX11=0,this._agentFwdEnabled=!1,this._agent=this.config.agent?this.config.agent:void 0,this._remoteVer=void 0;let a;if(this.config.privateKey){if(a=_s(this.config.privateKey,t.passphrase),a instanceof Error)throw new Error(`Cannot parse privateKey: ${a.message}`);if(Array.isArray(a)&&(a=a[0]),a.getPrivatePEM()===null)throw new Error("privateKey value does not contain a (valid) private key")}let c;if(typeof t.hostVerifier=="function"){let T=t.hostVerifier,C;rm.indexOf(t.hostHash)!==-1&&(C=t.hostHash),c=(v,D)=>{C&&(v=z0(C).update(v).digest("hex"));let G=T(v,D);G!==void 0&&D(G)}}let f=this._sock=t.sock||new Z0,u=!1,h=!1;this._protocol&&this._protocol.cleanup();let d=s?(T,C,v)=>{s(`Debug output from server: ${JSON.stringify(v)}`)}:void 0,g,_=this._protocol=new lm({ident:this.config.ident,offer:r?void 0:e,onWrite:T=>{Ct(f)&&f.write(T)},onError:T=>{T.level==="handshake"&&clearTimeout(this._readyTimeout),_._destruct||f.removeAllListeners("data"),this.emit("error",T);try{f.end()}catch{}},onHeader:T=>{h=!0,this._remoteVer=T.versions.software,T.greeting&&this.emit("greeting",T.greeting)},onHandshakeComplete:T=>{this.emit("handshake",T),u||(u=!0,_.service("ssh-userauth"))},debug:s,hostVerifier:c,messageHandlers:{DEBUG:d,DISCONNECT:(T,C,v)=>{if(C!==Fh.BY_APPLICATION){v||(v=im[C],v===void 0&&(v=`Unexpected disconnection reason: ${C}`));let D=new Error(v);D.code=C,this.emit("error",D)}f.end()},SERVICE_ACCEPT:(T,C)=>{C==="ssh-userauth"&&Z()},EXT_INFO:(T,C)=>{if(g===void 0){for(let v of C)if(v.name==="server-sig-algs"){g=v.algs;return}g=null}},USERAUTH_BANNER:(T,C)=>{this.emit("banner",C)},USERAUTH_SUCCESS:T=>{L(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:(T,C,v)=>{if(S.keyAlgos){let D=S.keyAlgos[0][0];if(s&&s(`Client: ${S.type} (${D}) auth failed`),S.keyAlgos.shift(),S.keyAlgos.length){let[G,se]=S.keyAlgos[0];switch(S.type){case"agent":_.authPK(S.username,S.agentCtx.currentKey(),G);return;case"publickey":_.authPK(S.username,S.key,G);return;case"hostbased":_.authHostbased(S.username,S.key,S.localHostname,S.localUsername,G,(ee,Ve)=>{let mt=S.key.sign(ee,se);if(mt instanceof Error)return mt.message=`Error while signing with key: ${mt.message}`,mt.level="client-authentication",this.emit("error",mt),Z();Ve(mt)});return}}else S.keyAlgos=void 0}if(S.type==="agent"){let D=S.agentCtx.pos();return s&&s(`Client: Agent key #${D+1} failed`),re()}s&&s(`Client: ${S.type} auth failed`),w=v,U=C,Z()},USERAUTH_PASSWD_CHANGEREQ:(T,C)=>{S.type==="password"&&this.emit("change password",C,v=>{_.authPassword(this.config.username,this.config.password,v)})},USERAUTH_PK_OK:T=>{let C,v;if(S.keyAlgos&&([C,v]=S.keyAlgos[0]),S.type==="agent"){let D=S.agentCtx.currentKey();_.authPK(S.username,D,C,(G,se)=>{let ee={hash:v};S.agentCtx.sign(D,G,ee,(Ve,mt)=>{if(Ve)Ve.level="agent",this.emit("error",Ve);else return se(mt);re()})})}else S.type==="publickey"&&_.authPK(S.username,S.key,C,(D,G)=>{let se=S.key.sign(D,v);if(se instanceof Error)return se.message=`Error signing data with key: ${se.message}`,se.level="client-authentication",this.emit("error",se),Z();G(se)})},USERAUTH_INFO_REQUEST:(T,C,v,D)=>{if(S.type==="keyboard-interactive"){if((Array.isArray(D)?D.length:0)===0){s&&s("Client: Sending automatic USERAUTH_INFO_RESPONSE"),_.authInfoRes();return}S.prompt(C,v,"",D,se=>{_.authInfoRes(se)})}},REQUEST_SUCCESS:(T,C)=>{o.length&&o.shift()(!1,C)},REQUEST_FAILURE:T=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:(T,C,v,D)=>{C==="hostkeys-00@openssh.com"?(Sm(this,D,(G,se)=>{G||this.emit("hostkeys",se)}),v&&_.requestSuccess()):v&&_.requestFailure()},CHANNEL_OPEN:(T,C)=>{bm(this,C)},CHANNEL_OPEN_CONFIRMATION:(T,C)=>{let v=this._chanMgr.get(C.recipient);if(typeof v!="function")return;let D=v.type==="sftp",se={type:D?"session":v.type,incoming:{id:C.recipient,window:ys,packetSize:bs,state:"open"},outgoing:{id:C.sender,window:C.window,packetSize:C.packetSize,state:"open"}},ee=D?new hm(this,se,{debug:s}):new Zh(this,se);this._chanMgr.update(C.recipient,ee),v(void 0,ee)},CHANNEL_OPEN_FAILURE:(T,C,v,D)=>{let G=this._chanMgr.get(C);if(typeof G!="function")return;Am(this,C,{reason:v,description:D},G)},CHANNEL_DATA:(T,C,v)=>{let D=this._chanMgr.get(C);if(!(typeof D!="object"||D===null)&&D.incoming.window!==0){if(D.incoming.window-=v.length,D.push(v)===!1){D._waitChanDrain=!0;return}D.incoming.window<=Gh&&Kh(D)}},CHANNEL_EXTENDED_DATA:(T,C,v,D)=>{if(D!==nm)return;let G=this._chanMgr.get(C);if(!(typeof G!="object"||G===null)&&G.incoming.window!==0){if(G.incoming.window-=v.length,!G.stderr.push(v)){G._waitChanDrain=!0;return}G.incoming.window<=Gh&&Kh(G)}},CHANNEL_WINDOW_ADJUST:(T,C,v)=>{let D=this._chanMgr.get(C);typeof D!="object"||D===null||(D.outgoing.window+=v,D._waitWindow&&(D._waitWindow=!1,D._chunk?D._write(D._chunk,null,D._chunkcb):D._chunkcb?D._chunkcb():D._chunkErr?D.stderr._write(D._chunkErr,null,D._chunkcbErr):D._chunkcbErr&&D._chunkcbErr()))},CHANNEL_SUCCESS:(T,C)=>{let v=this._chanMgr.get(C);typeof v!="object"||v===null||(this._resetKA(),v._callbacks.length&&v._callbacks.shift()(!1))},CHANNEL_FAILURE:(T,C)=>{let v=this._chanMgr.get(C);typeof v!="object"||v===null||(this._resetKA(),v._callbacks.length&&v._callbacks.shift()(!0))},CHANNEL_REQUEST:(T,C,v,D,G)=>{let se=this._chanMgr.get(C);if(typeof se!="object"||se===null)return;let ee=se._exit;if(ee.code===void 0){switch(v){case"exit-status":se.emit("exit",ee.code=G);return;case"exit-signal":se.emit("exit",ee.code=null,ee.signal=`SIG${G.signal}`,ee.dump=G.coreDumped,ee.desc=G.errorMessage);return}D&&T.channelFailure(se.outgoing.id)}},CHANNEL_EOF:(T,C)=>{let v=this._chanMgr.get(C);typeof v!="object"||v===null||v.incoming.state==="open"&&(v.incoming.state="eof",v.readable&&v.push(null),v.stderr.readable&&v.stderr.push(null))},CHANNEL_CLOSE:(T,C)=>{Em(this,C,this._chanMgr.get(C))}}});f.pause();let y=this.config.keepaliveInterval,x=this.config.keepaliveCountMax,I=0,O,$=()=>{if(++I>x){if(clearInterval(O),f.readable){let T=new Error("Keepalive timeout");T.level="client-timeout",this.emit("error",T),f.destroy()}return}Ct(f)?(o.push(L),_.ping()):clearInterval(O)};function L(){y>0&&(I=0,clearInterval(O),Ct(f)&&(O=setInterval($,y)))}this._resetKA=L;let j=(()=>{let T=!1;return()=>{if(!T&&(T=!0,z&&!h)){let C=dm("Connection lost before handshake","protocol",!0);this.emit("error",C)}}})(),J=(()=>{let T=!1;return()=>{T||(T=!0,z=!0,s&&s("Socket connected"),this.emit("connect"),um.then(()=>{_.start(),f.on("data",C=>{try{_.parse(C,0,C.length)}catch(v){this.emit("error",v);try{Ct(f)&&f.end()}catch{}}}),f.stderr&&typeof f.stderr.resume=="function"&&f.stderr.resume(),f.resume()}).catch(C=>{this.emit("error",C);try{Ct(f)&&f.end()}catch{}}))}})(),z=!1;f.on("connect",J).on("timeout",()=>{this.emit("timeout")}).on("error",T=>{s&&s(`Socket error: ${T.message}`),clearTimeout(this._readyTimeout),T.level="client-socket",this.emit("error",T)}).on("end",()=>{s&&s("Socket ended"),j(),_.cleanup(),clearTimeout(this._readyTimeout),clearInterval(O),this.emit("end")}).on("close",()=>{s&&s("Socket closed"),j(),_.cleanup(),clearTimeout(this._readyTimeout),clearInterval(O),this.emit("close");let T=o;o=this._callbacks=[];let C=new Error("No response from server");for(let v=0;v<T.length;++v)T[v](C);this._chanMgr.cleanup(C)});let S,w=null,U=null,W=["none"];this.config.password!==void 0&&W.push("password"),a!==void 0&&W.push("publickey"),this._agent!==void 0&&W.push("agent"),this.config.tryKeyboard&&W.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&W.push("hostbased"),Array.isArray(i)?i=zh(i):typeof i!="function"&&(i=zh(W));let Q=!1,oe=T=>{if(!Q){if(Q=!0,T===!1){let C=new Error("All configured authentication methods failed");C.level="client-authentication",this.emit("error",C),this.end();return}if(typeof T=="string"){let C=T;if(W.indexOf(C)===-1)return te(`Authentication method not allowed: ${C}`);let v=this.config.username;switch(C){case"password":T={type:C,username:v,password:this.config.password};break;case"publickey":T={type:C,username:v,key:a};break;case"hostbased":T={type:C,username:v,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":T={type:C,username:v,agentCtx:new $h(this._agent)};break;case"keyboard-interactive":T={type:C,username:v,prompt:(...D)=>this.emit("keyboard-interactive",...D)};break;case"none":T={type:C,username:v};break;default:return te(`Skipping unsupported authentication method: ${T}`)}}else{if(typeof T!="object"||T===null)return te(`Skipping invalid authentication attempt: ${T}`);{let C=T.username;if(typeof C!="string")return te(`Skipping invalid authentication attempt: ${T}`);let v=T.type;switch(v){case"password":{let{password:D}=T;if(typeof D!="string"&&!Buffer.isBuffer(D))return te("Skipping invalid password auth attempt");T={type:v,username:C,password:D};break}case"publickey":{let D=_s(T.key,T.passphrase);if(D instanceof Error)return te("Skipping invalid key auth attempt");if(!D.isPrivateKey())return te("Skipping non-private key");T={type:v,username:C,key:D};break}case"hostbased":{let{localHostname:D,localUsername:G}=T,se=_s(T.key,T.passphrase);if(se instanceof Error||typeof D!="string"||typeof G!="string")return te("Skipping invalid hostbased auth attempt");if(!se.isPrivateKey())return te("Skipping non-private key");T={type:v,username:C,key:se,localHostname:D,localUsername:G};break}case"agent":{let D=T.agent;if(typeof D=="string"&&D.length)D=Wh(D);else if(!qh(D))return te(`Skipping invalid agent: ${T.agent}`);T={type:v,username:C,agentCtx:new $h(D)};break}case"keyboard-interactive":{let{prompt:D}=T;if(typeof D!="function")return te("Skipping invalid keyboard-interactive auth attempt");T={type:v,username:C,prompt:D};break}case"none":T={type:v,username:C};break;default:return te(`Skipping unsupported authentication method: ${T}`)}}}S=T;try{let C=S.username;switch(S.type){case"password":_.authPassword(C,S.password);break;case"publickey":{let v;if(S.keyAlgos=xa(this,S.key,g),S.keyAlgos)if(S.keyAlgos.length)v=S.keyAlgos[0][0];else return te("Skipping key authentication (no mutual hash algorithm)");_.authPK(C,S.key,v);break}case"hostbased":{let v,D;if(S.keyAlgos=xa(this,S.key,g),S.keyAlgos)if(S.keyAlgos.length)[v,D]=S.keyAlgos[0];else return te("Skipping hostbased authentication (no mutual hash algorithm)");_.authHostbased(C,S.key,S.localHostname,S.localUsername,v,(G,se)=>{let ee=S.key.sign(G,D);if(ee instanceof Error)return ee.message=`Error while signing with key: ${ee.message}`,ee.level="client-authentication",this.emit("error",ee),Z();se(ee)});break}case"agent":S.agentCtx.init(v=>{if(v)return v.level="agent",this.emit("error",v),Z();re()});break;case"keyboard-interactive":_.authKeyboard(C);break;case"none":_.authNone(C);break}}finally{Q=!1}}};function te(T){s&&s(T),process.nextTick(Z)}function Z(){Q=!1;let T=i(U,w,oe);Q||T===void 0||oe(T)}let re=()=>{if(S.type==="agent"){let T=S.agentCtx.nextKey();if(T===!1)s&&s("Agent: No more keys left to try"),s&&s("Client: agent auth failed"),Z();else{let C=S.agentCtx.pos(),v;if(S.keyAlgos=xa(this,T,g),S.keyAlgos)if(S.keyAlgos.length)v=S.keyAlgos[0][0];else{s&&s(`Agent: Skipping key #${C+1} (no mutual hash algorithm)`),re();return}s&&s(`Agent: Trying key #${C+1}`),_.authPK(S.username,T,v)}}},ae=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let T=new Error("Timed out while waiting for handshake");T.level="client-timeout",this.emit("error",T),f.destroy()},this.config.readyTimeout))};if(t.sock)ae(),typeof f.connecting=="boolean"&&f.connecting||J();else{let T=this.config.host,C=this.config.forceIPv4,v=this.config.forceIPv6;s&&s(`Client: Trying ${T} on port ${this.config.port} ...`);let D=()=>{ae(),f.connect({host:T,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),f.setMaxListeners(0),f.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!C&&!v||C&&v?D():em(T,C?4:6,(G,se,ee)=>{if(G){let Ve=C?"IPv4":"IPv6",mt=new Error(`Error while looking up ${Ve} address for '${T}': ${G}`);clearTimeout(this._readyTimeout),mt.level="client-dns",this.emit("error",mt),this.emit("close");return}T=se,D()})}return this}end(){return this._sock&&Ct(this._sock)&&(this._protocol.disconnect(Fh.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&Ct(this._sock)&&this._sock.destroy(),this}exec(t,e,r){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");typeof e=="function"&&(r=e,e={});let i={allowHalfOpen:e.allowHalfOpen!==!1};return kn(this,"session",i,(s,o)=>{if(s){r(s);return}let a=[];function c(f){if(f){o.close(),r(f);return}a.length&&a.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&a.push(()=>jh(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&ya(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>Vh(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>Yh(o,e.x11,c))),a.push(()=>ym(o,t,e,r)),a.shift()()}),this}shell(t,e,r){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");return typeof t=="function"?(r=t,t=e=void 0):typeof e=="function"&&(r=e,e=void 0),t&&(t.x11!==void 0||t.env!==void 0)&&(e=t,t=void 0),kn(this,"session",(i,s)=>{if(i){r(i);return}let o=[];function a(c){if(c){s.close(),r(c);return}o.length&&o.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&o.push(()=>jh(s,a)),t!==!1&&o.push(()=>Vh(s,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&ya(s,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>Yh(s,e.x11,a))),o.push(()=>_m(s,r)),o.shift()()}),this}subsys(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");return kn(this,"session",(r,i)=>{if(r){e(r);return}ba(i,t,(s,o)=>{if(s){e(s);return}e(void 0,o)})}),this}forwardIn(t,e,r){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let i=typeof r=="function";return i&&this._callbacks.push((s,o)=>{if(s){r(s!==!0?s:new Error(`Unable to bind to ${t}:${e}`));return}let a=e;e===0&&o&&o.length>=4&&(a=pm(o,0),this._protocol._compatFlags&Xh.DYN_RPORT_BUG||(e=a)),this._forwarding[`${t}:${e}`]=a,r(void 0,a)}),this._protocol.tcpipForward(t,e,i),this}unforwardIn(t,e,r){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let i=typeof r=="function";return i&&this._callbacks.push(s=>{if(s){r(s!==!0?s:new Error(`Unable to unbind from ${t}:${e}`));return}delete this._forwarding[`${t}:${e}`],r()}),this._protocol.cancelTcpipForward(t,e,i),this}forwardOut(t,e,r,i,s){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:r,dstPort:i};return typeof s!="function"&&(s=Sa),kn(this,"direct-tcpip",o,s),this}openssh_noMoreSessions(t){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let e=typeof t=="function";return!this.config.strictVendor||this.config.strictVendor&&mi.test(this._remoteVer)?(e&&this._callbacks.push(r=>{if(r){t(r!==!0?r:new Error("Unable to disable future sessions"));return}t()}),this._protocol.openssh_noMoreSessions(e),this):e?(process.nextTick(t,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardInStreamLocal(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&mi.test(this._remoteVer)?(r&&this._callbacks.push(i=>{if(i){e(i!==!0?i:new Error(`Unable to bind to ${t}`));return}this._forwardingUnix[t]=!0,e()}),this._protocol.openssh_streamLocalForward(t,r),this):r?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_unforwardInStreamLocal(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&mi.test(this._remoteVer)?(r&&this._callbacks.push(i=>{if(i){e(i!==!0?i:new Error(`Unable to unbind from ${t}`));return}delete this._forwardingUnix[t],e()}),this._protocol.openssh_cancelStreamLocalForward(t,r),this):r?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardOutStreamLocal(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=Sa),!this.config.strictVendor||this.config.strictVendor&&mi.test(this._remoteVer)?(kn(this,"direct-streamlocal@openssh.com",{socketPath:t},e),this):(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this)}sftp(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");return typeof t=="function"&&(e=t,t=void 0),kn(this,"sftp",(r,i)=>{if(r){e(r);return}let s=(o,a)=>{if(o){e(o);return}function c(){i.removeListener("ready",f),i.removeListener("error",u),i.removeListener("exit",h),i.removeListener("close",h)}function f(){c(),e(void 0,i)}function u(d){c(),e(d)}function h(d,g){c();let _;typeof d=="number"?_=`Received exit code ${d} while establishing SFTP session`:g!==void 0?_=`Received signal ${g} while establishing SFTP session`:_="Received unexpected SFTP session termination";let y=new Error(_);y.code=d,y.signal=g,e(y)}i.on("ready",f).on("error",u).on("exit",h).on("close",h),i._init()};typeof t=="object"&&t!==null?ya(i,t,o=>{if(o){e(o);return}ba(i,"sftp",s)}):ba(i,"sftp",s)}),this}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function kn(n,t,e,r){let i=ys,s=bs;typeof e=="function"&&(r=e,e={});let o=(c,f)=>{r(c,f)};o.type=t;let a=n._chanMgr.add(o);if(a===-1){r(new Error("No free channels available"));return}switch(t){case"session":case"sftp":n._protocol.session(a,i,s);break;case"direct-tcpip":n._protocol.directTcpip(a,i,s,e);break;case"direct-streamlocal@openssh.com":n._protocol.openssh_directStreamLocal(a,i,s,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function Yh(n,t,e){let r={single:!1,protocol:"MIT-MAGIC-COOKIE-1",cookie:void 0,screen:0};typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.single=="boolean"&&(r.single=t.single),typeof t.screen=="number"&&(r.screen=t.screen),typeof t.protocol=="string"&&(r.protocol=t.protocol),typeof t.cookie=="string"?r.cookie=t.cookie:Buffer.isBuffer(t.cookie)&&(r.cookie=t.cookie.hexSlice(0,t.cookie.length))),r.cookie===void 0&&(r.cookie=xm());let i=typeof e=="function";if(n.outgoing.state!=="open"){i&&e(new Error("Channel is not open"));return}i&&n._callbacks.push(s=>{if(s){e(s!==!0?s:new Error("Unable to request X11"));return}n._hasX11=!0,++n._client._acceptX11,n.once("close",()=>{n._client._acceptX11&&--n._client._acceptX11}),e()}),n._client._protocol.x11Forward(n.outgoing.id,r,i)}function Vh(n,t,e){let r=24,i=80,s=640,o=480,a="vt100",c=null;typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.rows=="number"&&(r=t.rows),typeof t.cols=="number"&&(i=t.cols),typeof t.width=="number"&&(s=t.width),typeof t.height=="number"&&(o=t.height),typeof t.term=="string"&&(a=t.term),typeof t.modes=="object"&&(c=t.modes));let f=typeof e=="function";if(n.outgoing.state!=="open"){f&&e(new Error("Channel is not open"));return}f&&n._callbacks.push(u=>{if(u){e(u!==!0?u:new Error("Unable to request a pseudo-terminal"));return}e()}),n._client._protocol.pty(n.outgoing.id,r,i,o,s,a,c,f)}function jh(n,t){let e=typeof t=="function";if(n.outgoing.state!=="open"){e&&t(new Error("Channel is not open"));return}if(n._client._agentFwdEnabled){e&&t(!1);return}n._client._agentFwdEnabled=!0,n._callbacks.push(r=>{if(r){n._client._agentFwdEnabled=!1,e&&t(r!==!0?r:new Error("Unable to request agent forwarding"));return}e&&t()}),n._client._protocol.openssh_agentForward(n.outgoing.id,!0)}function _m(n,t){if(n.outgoing.state!=="open"){t(new Error("Channel is not open"));return}n._callbacks.push(e=>{if(e){t(e!==!0?e:new Error("Unable to open shell"));return}n.subtype="shell",t(void 0,n)}),n._client._protocol.shell(n.outgoing.id,!0)}function ym(n,t,e,r){if(n.outgoing.state!=="open"){r(new Error("Channel is not open"));return}n._callbacks.push(i=>{if(i){r(i!==!0?i:new Error("Unable to exec"));return}n.subtype="exec",n.allowHalfOpen=e.allowHalfOpen!==!1,r(void 0,n)}),n._client._protocol.exec(n.outgoing.id,t,!0)}function ya(n,t,e){let r=typeof e=="function";if(n.outgoing.state!=="open"){r&&e(new Error("Channel is not open"));return}r&&n._callbacks.push(s=>{if(s){e(s!==!0?s:new Error("Unable to set environment"));return}e()});let i=Object.keys(t||{});for(let s=0;s<i.length;++s){let o=i[s],a=t[o];n._client._protocol.env(n.outgoing.id,o,a,r)}}function ba(n,t,e){if(n.outgoing.state!=="open"){e(new Error("Channel is not open"));return}n._callbacks.push(r=>{if(r){e(r!==!0?r:new Error(`Unable to start subsystem: ${t}`));return}n.subtype="subsystem",e(void 0,n)}),n._client._protocol.subsystem(n.outgoing.id,t,!0)}function bm(n,t){let e=-1,r,i=()=>{let c={type:t.type,incoming:{id:e,window:ys,packetSize:bs,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},f=new Zh(n,c);return n._chanMgr.update(e,f),n._protocol.channelOpenConfirm(t.sender,e,ys,bs),f},s=()=>{r===void 0&&(e===-1?r=pi.RESOURCE_SHORTAGE:r=pi.CONNECT_FAILED),e!==-1&&n._chanMgr.remove(e),n._protocol.channelOpenFail(t.sender,r,"")},o=()=>(e=n._chanMgr.add(),e===-1&&(r=pi.RESOURCE_SHORTAGE,n.config.debug&&n.config.debug("Client: Automatic rejection of incoming channel open: no channels available")),e!==-1),a=t.data;switch(t.type){case"forwarded-tcpip":{let c=n._forwarding[`${a.destIP}:${a.destPort}`];if(c!==void 0&&o()){a.destPort===0&&(a.destPort=c),n.emit("tcp connection",a,i,s);return}break}case"forwarded-streamlocal@openssh.com":if(n._forwardingUnix[a.socketPath]!==void 0&&o()){n.emit("unix connection",a,i,s);return}break;case"auth-agent@openssh.com":if(n._agentFwdEnabled&&typeof n._agent.getStream=="function"&&o()){n._agent.getStream((c,f)=>{if(c)return s();let u=i();u.pipe(f).pipe(u)});return}break;case"x11":if(n._acceptX11!==0&&o()){n.emit("x11",a,i,s);return}break;default:r=pi.UNKNOWN_CHANNEL_TYPE,n.config.debug&&n.config.debug(`Client: Automatic rejection of unsupported incoming channel open type: ${t.type}`)}r===void 0&&(r=pi.ADMINISTRATIVELY_PROHIBITED,n.config.debug&&n.config.debug("Client: Automatic rejection of unexpected incoming channel open for: "+t.type)),s()}var xm=(()=>{let n=Buffer.allocUnsafe(16);return()=>(J0(n,0,16),n.hexSlice(0,16))})();function zh(n){if(!Array.isArray(n))throw new Error("authList must be an array");let t=0;return(e,r,i)=>t===n.length?!1:n[t++]}function Sm(n,t,e){if(!n._sock||!Ct(n._sock))return;if(typeof e!="function"&&(e=Sa),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let r=[];for(let i of t){let s=_s(i);if(s instanceof Error)throw s;r.push(s)}if(!n.config.strictVendor||n.config.strictVendor&&mi.test(n._remoteVer)){n._callbacks.push((i,s)=>{if(i){e(i!==!0?i:new Error("Server failed to prove supplied keys"));return}let o=[],a=0;for(As.init(s,0);As.avail()&&a!==r.length;){let c=r[a++],f=c.getPublicSSH(),u=As.readString();Es.init(u,0);let h=Es.readString(!0),d=Es.readString(),g;if(h!==c.type)if(c.type==="ssh-rsa")switch(h){case"rsa-sha2-256":g="sha256";break;case"rsa-sha2-512":g="sha512";break;default:continue}else continue;let _=n._protocol._kex.sessionID,y=Buffer.allocUnsafe(37+_.length+4+f.length),x=0;_a(y,29,x),y.utf8Write("hostkeys-prove-00@openssh.com",x+=4,29),_a(y,_.length,x+=29),Qh(_,y,0,_.length,x+=4),_a(y,f.length,x+=_.length),Qh(f,y,0,f.length,x+=4),(d=gm(d,h))&&c.verify(y,d,g)===!0&&o.push(c)}Es.clear(),As.clear(),e(null,o)}),n._protocol.openssh_hostKeysProve(r);return}process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version"))}function xa(n,t,e){switch(t.type){case"ssh-rsa":if(n._protocol._compatFlags&Xh.IMPLY_RSA_SHA2_SIGALGS&&(Array.isArray(e)?e=["rsa-sha2-256","rsa-sha2-512",...e]:e=["rsa-sha2-256","rsa-sha2-512"]),Array.isArray(e)){if(e.indexOf("rsa-sha2-256")!==-1)return[["rsa-sha2-256","sha256"]];if(e.indexOf("rsa-sha2-512")!==-1)return[["rsa-sha2-512","sha512"]];if(e.indexOf("ssh-rsa")===-1)return[]}return[["ssh-rsa","sha1"]]}}ed.exports=wa});var rd=ot(td=>{"use strict";var{Agent:Ba}=require("http"),{Agent:wm}=require("https"),{connect:Im}=require("tls"),Ca;for(let n of[Ba,wm]){class t extends n{constructor(r,i){super(i),this._connectCfg=r,this._defaultSrcIP=i&&i.srcIP||"localhost"}createConnection(r,i){let s=r&&r.localAddress||this._defaultSrcIP,o=r&&r.localPort||0,a=r.host,c=r.port;Ca===void 0&&(Ca=Ia());let f=new Ca,u=!1;f.on("ready",()=>{f.forwardOut(s,o,a,c,(h,d)=>{if(u=!0,h)return f.end(),i(h);d.once("close",()=>f.end()),i(null,Cm(d,n,r))})}).on("error",i).on("close",()=>{u||i(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}td[n===Ba?"SSHTTPAgent":"SSHTTPSAgent"]=t}function Ai(){}function Cm(n,t,e){if(t===Ba)return n.setKeepAlive=Ai,n.setNoDelay=Ai,n.setTimeout=Ai,n.ref=Ai,n.unref=Ai,n.destroySoon=n.destroy,n;e.socket=n;let r=Im(e),i=(()=>{let s=!1;return()=>{s||(s=!0,n.isPaused()&&n.resume())}})();return r.on("end",i).on("close",i),r}});var id=ot((qb,Na)=>{"use strict";var{Server:Bm}=require("net"),_i=require("events"),{listenerCount:Qt}=_i,{CHANNEL_OPEN_FAILURE:Rn,DEFAULT_CIPHER:vm,DEFAULT_COMPRESSION:km,DEFAULT_KEX:Rm,DEFAULT_MAC:Nm,DEFAULT_SERVER_HOST_KEY:Pm,DISCONNECT_REASON:Nn,DISCONNECT_REASON_BY_VALUE:Tm,SUPPORTED_CIPHER:Lm,SUPPORTED_COMPRESSION:Um,SUPPORTED_KEX:Om,SUPPORTED_MAC:Dm,SUPPORTED_SERVER_HOST_KEY:Hm}=wr(),{init:Mm}=Lr(),{KexInit:Fm}=is(),{parseKey:nd}=Dr(),Qm=Zo(),{SFTP:$m}=li(),{writeUInt32BE:Wm}=or(),{Channel:Pn,MAX_WINDOW:Fr,PACKET_SIZE:Qr,windowAdjust:qm,WINDOW_THRESHOLD:Km}=ga(),{ChannelManager:Gm,generateAlgorithmList:Ei,isWritable:xs,onChannelOpenFailure:Ym,onCHANNEL_CLOSE:Vm}=Ea(),jm=10,$r=class extends _i{constructor(t,e,r,i,s){super(),this.username=this.user=e,this.service=r,this.method=i,this._initialResponse=!1,this._finalResponse=!1,this._multistep=!1,this._cbfinal=(o,a,c)=>{this._finalResponse||(this._finalResponse=!0,s(this,o,a,c))},this._protocol=t}accept(){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!0)}reject(t,e){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!1,t,e)}},Ss=class extends $r{constructor(t,e,r,i,s,o){super(t,e,r,i,o),this._multistep=!0,this._cb=void 0,this._onInfoResponse=a=>{let c=this._cb;c&&(this._cb=void 0,c(a))},this.submethods=s,this.on("abort",()=>{this._cb&&this._cb(new Error("Authentication request aborted"))})}prompt(t,e,r,i){Array.isArray(t)||(t=[t]),typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"?(i=r,r=void 0):typeof i!="function"&&(i=void 0);for(let s=0;s<t.length;++s)typeof t[s]=="string"&&(t[s]={prompt:t[s],echo:!0});this._cb=i,this._initialResponse=!0,this._protocol.authInfoReq(e,r,t)}},ka=class extends $r{constructor(t,e,r,i,s,o){super(t,e,r,i,o),this.key={algo:s.keyAlgo,data:s.key},this.hashAlgo=s.hashAlgo,this.signature=s.signature,this.blob=s.blob}accept(){this.signature?$r.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},Ra=class extends $r{constructor(t,e,r,i,s,o){super(t,e,r,i,o),this.key={algo:s.keyAlgo,data:s.key},this.hashAlgo=s.hashAlgo,this.signature=s.signature,this.blob=s.blob,this.localHostname=s.localHostname,this.localUsername=s.localUsername}},ws=class extends $r{constructor(t,e,r,i,s,o){super(t,e,r,i,o),this.password=s,this._changeCb=void 0}requestChange(t,e){if(this._changeCb)throw new Error("Change request already in progress");if(typeof t!="string")throw new Error("prompt argument must be a string");if(typeof e!="function")throw new Error("Callback argument must be a function");this._changeCb=e,this._protocol.authPasswdChg(t)}},Ar=class extends _i{constructor(t,e,r){super(),this.type="session",this.subtype=void 0,this.server=!0,this._ending=!1,this._channel=void 0,this._chanInfo={type:"session",incoming:{id:r,window:Fr,packetSize:Qr,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},Zt=class extends _i{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new Error("Missing configuration object");let r=Object.create(null),i=[],s=t.hostKeys;if(!Array.isArray(s))throw new Error("hostKeys must be an array");let o=typeof t.algorithms=="object"&&t.algorithms!==null?t.algorithms:{},a=Ei(o.serverHostKey,Pm,Hm);for(let d=0;d<s.length;++d){let g;if(Buffer.isBuffer(s[d])||typeof s[d]=="string"?g=nd(s[d]):g=nd(s[d].key,s[d].passphrase),g instanceof Error)throw new Error(`Cannot parse privateKey: ${g.message}`);if(Array.isArray(g)&&(g=g[0]),g.getPrivatePEM()===null)throw new Error("privateKey value contains an invalid private key");if(!i.includes(g.type))if(g.type==="ssh-rsa"){let _=a.indexOf("ssh-rsa"),y=a.indexOf("rsa-sha2-256"),x=a.indexOf("rsa-sha2-512");_===-1&&(_=1/0),[_,y,x].sort(zm).forEach(I=>{if(I===-1)return;let O;switch(I){case _:O="ssh-rsa";break;case y:O="rsa-sha2-256";break;case x:O="rsa-sha2-512";break;default:return}r[O]=g,i.push(O)})}else r[g.type]=g,i.push(g.type)}let c={kex:Ei(o.kex,Rm,Om).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:i,cs:{cipher:Ei(o.cipher,vm,Lm),mac:Ei(o.hmac,Nm,Dm),compress:Ei(o.compress,km,Um),lang:[]},sc:void 0};c.sc=c.cs,typeof e=="function"&&this.on("connection",e);let f=typeof t.debug=="function"?t.debug:void 0,u=t.ident?Buffer.from(t.ident):void 0,h=new Fm(c);this._srv=new Bm(d=>{if(this._connections>=this.maxConnections){d.destroy();return}++this._connections,d.once("close",()=>{--this._connections});let g;if(f){let _=`[${process.hrtime().join(".")}] `;g=y=>{f(`${_}${y}`)}}new Is(d,r,u,h,g,this,t)}).on("error",d=>{this.emit("error",d)}).on("listening",()=>{this.emit("listening")}).on("close",()=>{this.emit("close")}),this._connections=0,this.maxConnections=1/0}injectSocket(t){this._srv.emit("connection",t)}listen(...t){return this._srv.listen(...t),this}address(){return this._srv.address()}getConnections(t){return this._srv.getConnections(t),this}close(t){return this._srv.close(t),this}ref(){return this._srv.ref(),this}unref(){return this._srv.unref(),this}};Zt.KEEPALIVE_CLIENT_INTERVAL=15e3;Zt.KEEPALIVE_CLIENT_COUNT_MAX=3;var Is=class extends _i{constructor(t,e,r,i,s,o,a){super();let c=0,f=!1,u=[],h,d,g,_=[];this._sock=t,this._chanMgr=new Gm(this),this._debug=s,this.noMoreSessions=!1,this.authenticated=!1;function y(z){}this.on("error",y);let x=s?(z,S,w)=>{s(`Debug output from client: ${JSON.stringify(w)}`)}:void 0,I=typeof a.keepaliveInterval=="number"&&isFinite(a.keepaliveInterval)&&a.keepaliveInterval>0?a.keepaliveInterval:typeof Zt.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(Zt.KEEPALIVE_CLIENT_INTERVAL)&&Zt.KEEPALIVE_CLIENT_INTERVAL>0?Zt.KEEPALIVE_CLIENT_INTERVAL:-1,O=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof Zt.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(Zt.KEEPALIVE_CLIENT_COUNT_MAX)&&Zt.KEEPALIVE_CLIENT_COUNT_MAX>=0?Zt.KEEPALIVE_CLIENT_COUNT_MAX:-1,$=0;I!==-1&&O!==-1&&(this.once("ready",()=>{let z=()=>{clearInterval(d)};this.on("close",z).on("end",z),d=setInterval(()=>{if(++$>O){clearInterval(d);let S=new Error("Keepalive timeout");S.level="client-timeout",this.emit("error",S),this.end()}else L.ping()},I)}),g=()=>{d&&d.refresh(),$=0});let L=this._protocol=new Qm({server:!0,hostKeys:e,ident:r,offer:i,onPacket:g,greeting:a.greeting,banner:a.banner,onWrite:z=>{xs(t)&&t.write(z)},onError:z=>{L._destruct||t.removeAllListeners("data"),this.emit("error",z);try{t.end()}catch{}},onHeader:z=>{this.removeListener("error",y);let S={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:z};if(!o.emit("connection",this,S)){L.disconnect(Nn.BY_APPLICATION),t.end();return}z.greeting&&this.emit("greeting",z.greeting)},onHandshakeComplete:z=>{++c>1&&this.emit("rekey"),this.emit("handshake",z)},debug:s,messageHandlers:{DEBUG:x,DISCONNECT:(z,S,w)=>{if(S!==Nn.BY_APPLICATION){w||(w=Tm[S],w===void 0&&(w=`Unexpected disconnection reason: ${S}`));let U=new Error(w);U.code=S,this.emit("error",U)}t.end()},CHANNEL_OPEN:(z,S)=>{if(S.type==="session"&&this.noMoreSessions||!this.authenticated){let re=Rn.ADMINISTRATIVELY_PROHIBITED;return L.channelOpenFail(S.sender,re)}let w=-1,U,W=!1,Q,oe=()=>{W||(W=!0,U===void 0&&(w===-1?U=Rn.RESOURCE_SHORTAGE:U=Rn.CONNECT_FAILED),w!==-1&&this._chanMgr.remove(w),L.channelOpenFail(S.sender,U,""))},te=()=>(w=this._chanMgr.add(),w===-1&&(U=Rn.RESOURCE_SHORTAGE,s&&s("Automatic rejection of incoming channel open: no channels available")),w!==-1),Z=S.data;switch(S.type){case"session":if(Qt(this,"session")&&te()){Q=()=>{if(W)return;W=!0;let re=new Ar(this,S,w);return this._chanMgr.update(w,re),L.channelOpenConfirm(S.sender,w,Fr,Qr),re},this.emit("session",Q,oe);return}break;case"direct-tcpip":if(Qt(this,"tcpip")&&te()){Q=()=>{if(W)return;W=!0;let re={type:void 0,incoming:{id:w,window:Fr,packetSize:Qr,state:"open"},outgoing:{id:S.sender,window:S.window,packetSize:S.packetSize,state:"open"}},ae=new Pn(this,re,{server:!0});return this._chanMgr.update(w,ae),L.channelOpenConfirm(S.sender,w,Fr,Qr),ae},this.emit("tcpip",Q,oe,Z);return}break;case"direct-streamlocal@openssh.com":if(Qt(this,"openssh.streamlocal")&&te()){Q=()=>{if(W)return;W=!0;let re={type:void 0,incoming:{id:w,window:Fr,packetSize:Qr,state:"open"},outgoing:{id:S.sender,window:S.window,packetSize:S.packetSize,state:"open"}},ae=new Pn(this,re,{server:!0});return this._chanMgr.update(w,ae),L.channelOpenConfirm(S.sender,w,Fr,Qr),ae},this.emit("openssh.streamlocal",Q,oe,Z);return}break;default:U=Rn.UNKNOWN_CHANNEL_TYPE,s&&s(`Automatic rejection of unsupported incoming channel open type: ${S.type}`)}U===void 0&&(U=Rn.ADMINISTRATIVELY_PROHIBITED,s&&s(`Automatic rejection of unexpected incoming channel open for: ${S.type}`)),oe()},CHANNEL_OPEN_CONFIRMATION:(z,S)=>{let w=this._chanMgr.get(S.recipient);if(typeof w!="function")return;let U={type:w.type,incoming:{id:S.recipient,window:Fr,packetSize:Qr,state:"open"},outgoing:{id:S.sender,window:S.window,packetSize:S.packetSize,state:"open"}},W=new Pn(this,U,{server:!0});this._chanMgr.update(S.recipient,W),w(void 0,W)},CHANNEL_OPEN_FAILURE:(z,S,w,U)=>{let W=this._chanMgr.get(S);if(typeof W!="function")return;Ym(this,S,{reason:w,description:U},W)},CHANNEL_DATA:(z,S,w)=>{let U=this._chanMgr.get(S);if(!(typeof U!="object"||U===null)&&!(U.constructor===Ar&&(U=U._channel,!U))&&U.incoming.window!==0){if(U.incoming.window-=w.length,U.push(w)===!1){U._waitChanDrain=!0;return}U.incoming.window<=Km&&qm(U)}},CHANNEL_EXTENDED_DATA:(z,S,w,U)=>{},CHANNEL_WINDOW_ADJUST:(z,S,w)=>{let U=this._chanMgr.get(S);typeof U!="object"||U===null||U.constructor===Ar&&(U=U._channel,!U)||(U.outgoing.window+=w,U._waitWindow&&(U._waitWindow=!1,U._chunk?U._write(U._chunk,null,U._chunkcb):U._chunkcb?U._chunkcb():U._chunkErr?U.stderr._write(U._chunkErr,null,U._chunkcbErr):U._chunkcbErr&&U._chunkcbErr()))},CHANNEL_SUCCESS:(z,S)=>{let w=this._chanMgr.get(S);typeof w!="object"||w===null||w.constructor===Ar&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!1)},CHANNEL_FAILURE:(z,S)=>{let w=this._chanMgr.get(S);typeof w!="object"||w===null||w.constructor===Ar&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!0)},CHANNEL_REQUEST:(z,S,w,U,W)=>{let Q=this._chanMgr.get(S);if(typeof Q!="object"||Q===null)return;let oe=!1,te,Z;if(Q.constructor!==Ar){U&&L.channelFailure(Q.outgoing.id);return}if(U&&(w!=="shell"&&w!=="exec"&&w!=="subsystem"&&(te=()=>{oe||Q._ending||Q._channel||(oe=!0,L.channelSuccess(Q._chanInfo.outgoing.id))}),Z=()=>{oe||Q._ending||Q._channel||(oe=!0,L.channelFailure(Q._chanInfo.outgoing.id))}),Q._ending){Z&&Z();return}switch(w){case"env":if(Qt(Q,"env")){Q.emit("env",te,Z,{key:W.name,val:W.value});return}break;case"pty-req":if(Qt(Q,"pty")){Q.emit("pty",te,Z,W);return}break;case"window-change":Qt(Q,"window-change")?Q.emit("window-change",te,Z,W):Z&&Z();break;case"x11-req":if(Qt(Q,"x11")){Q.emit("x11",te,Z,W);return}break;case"signal":if(Qt(Q,"signal")){Q.emit("signal",te,Z,{name:W});return}break;case"auth-agent-req@openssh.com":if(Qt(Q,"auth-agent")){Q.emit("auth-agent",te,Z);return}break;case"shell":if(Qt(Q,"shell")){te=()=>{if(oe||Q._ending||Q._channel)return;oe=!0,U&&L.channelSuccess(Q._chanInfo.outgoing.id);let re=new Pn(this,Q._chanInfo,{server:!0});return re.subtype=Q.subtype=w,Q._channel=re,re},Q.emit("shell",te,Z);return}break;case"exec":if(Qt(Q,"exec")){te=()=>{if(oe||Q._ending||Q._channel)return;oe=!0,U&&L.channelSuccess(Q._chanInfo.outgoing.id);let re=new Pn(this,Q._chanInfo,{server:!0});return re.subtype=Q.subtype=w,Q._channel=re,re},Q.emit("exec",te,Z,{command:W});return}break;case"subsystem":{let re=W==="sftp";if(te=()=>{if(oe||Q._ending||Q._channel)return;oe=!0,U&&L.channelSuccess(Q._chanInfo.outgoing.id);let ae;return re?ae=new $m(this,Q._chanInfo,{server:!0,debug:s}):(ae=new Pn(this,Q._chanInfo,{server:!0}),ae.subtype=Q.subtype=`${w}:${W}`),Q._channel=ae,ae},W==="sftp"){if(Qt(Q,"sftp")){Q.emit("sftp",te,Z);return}re=!1}if(Qt(Q,"subsystem")){Q.emit("subsystem",te,Z,{name:W});return}break}}s&&s(`Automatic rejection of incoming channel request: ${w}`),Z&&Z()},CHANNEL_EOF:(z,S)=>{let w=this._chanMgr.get(S);typeof w!="object"||w===null||w.constructor===Ar&&(w._ending||(w._ending=!0,w.emit("eof"),w.emit("end")),w=w._channel,!w)||w.incoming.state==="open"&&(w.incoming.state="eof",w.readable&&w.push(null))},CHANNEL_CLOSE:(z,S)=>{let w=this._chanMgr.get(S);typeof w!="object"||w===null||w.constructor===Ar&&(w._ending=!0,w.emit("close"),w=w._channel,!w)||Vm(this,S,w)},SERVICE_REQUEST:(z,S)=>{if(c===0||f||this.authenticated||S!=="ssh-userauth"){L.disconnect(Nn.SERVICE_NOT_AVAILABLE),t.end();return}f=!0,L.serviceAccept(S)},USERAUTH_REQUEST:(z,S,w,U,W)=>{if(c===0||this.authenticated||h&&(h.username!==S||h.service!==w)||U!=="password"&&U!=="publickey"&&U!=="hostbased"&&U!=="keyboard-interactive"&&U!=="none"||u.length===jm){L.disconnect(Nn.PROTOCOL_ERROR),t.end();return}else if(w!=="ssh-connection"){L.disconnect(Nn.SERVICE_NOT_AVAILABLE),t.end();return}let Q;switch(U){case"keyboard-interactive":Q=new Ss(L,S,w,U,W,j);break;case"publickey":Q=new ka(L,S,w,U,W,j);break;case"hostbased":Q=new Ra(L,S,w,U,W,j);break;case"password":if(h&&h instanceof ws&&h._changeCb){let oe=h._changeCb;h._changeCb=void 0,oe(W.newPassword);return}Q=new ws(L,S,w,U,W,j);break;case"none":Q=new $r(L,S,w,U,j);break}if(h)if(h._initialResponse)h._multistep&&!h._finalResponse&&(h._cleanup&&h._cleanup(),h.emit("abort"));else return u.push(Q);h=Q,Qt(this,"authentication")?this.emit("authentication",h):h.reject()},USERAUTH_INFO_RESPONSE:(z,S)=>{h&&h instanceof Ss&&h._onInfoResponse(S)},GLOBAL_REQUEST:(z,S,w,U)=>{let W={type:null,buf:null};function Q(oe,te){W.type=oe,W.buf=te,J()}if(w&&_.push(W),(S==="tcpip-forward"||S==="cancel-tcpip-forward"||S==="no-more-sessions@openssh.com"||S==="streamlocal-forward@openssh.com"||S==="cancel-streamlocal-forward@openssh.com")&&Qt(this,"request")&&this.authenticated){let oe,te;if(w){let Z=!1;oe=re=>{if(Z)return;Z=!0;let ae;S==="tcpip-forward"&&U.bindPort===0&&typeof re=="number"&&(ae=Buffer.allocUnsafe(4),Wm(ae,re,0)),Q("SUCCESS",ae)},te=()=>{Z||(Z=!0,Q("FAILURE"))}}if(S==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,oe&&oe();return}this.emit("request",oe,te,S,U)}else w&&Q("FAILURE")}}});t.pause(),Mm.then(()=>{L.start(),t.on("data",z=>{try{L.parse(z,0,z.length)}catch(S){this.emit("error",S);try{xs(t)&&t.end()}catch{}}}),t.resume()}).catch(z=>{this.emit("error",z);try{xs(t)&&t.end()}catch{}}),t.on("error",z=>{z.level="socket",this.emit("error",z)}).once("end",()=>{s&&s("Socket ended"),L.cleanup(),this.emit("end")}).once("close",()=>{s&&s("Socket closed"),L.cleanup(),this.emit("close");let z=new Error("No response from server");this._chanMgr.cleanup(z)});let j=(z,S,w,U)=>{h===z&&!this.authenticated&&(S?(h=void 0,this.authenticated=!0,L.authSuccess(),u=[],this.emit("ready")):(L.authFailure(w,U),u.length&&(h=u.pop(),Qt(this,"authentication")?this.emit("authentication",h):h.reject())))};function J(){for(;_.length>0&&_[0].type;){let z=_.shift();z.type==="SUCCESS"&&L.requestSuccess(z.buf),z.type==="FAILURE"&&L.requestFailure()}}}end(){return this._sock&&xs(this._sock)&&(this._protocol.disconnect(Nn.BY_APPLICATION),this._sock.end()),this}x11(t,e,r){return va(this,"x11",{originAddr:t,originPort:e},r),this}forwardOut(t,e,r,i,s){return va(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:r,remotePort:i},s),this}openssh_forwardOutStreamLocal(t,e){return va(this,"forwarded-streamlocal@openssh.com",{socketPath:t},e),this}rekey(t){let e;try{this._protocol.rekey()}catch(r){e=r}typeof t=="function"&&(e?process.nextTick(t,e):this.once("rekey",t))}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function va(n,t,e,r){let i=Fr,s=Qr;typeof e=="function"&&(r=e,e={});let o=(c,f)=>{r(c,f)};o.type=t;let a=n._chanMgr.add(o);if(a===-1){r(new Error("No free channels available"));return}switch(t){case"forwarded-tcpip":n._protocol.forwardedTcpip(a,i,s,e);break;case"x11":n._protocol.x11(a,i,s,e);break;case"forwarded-streamlocal@openssh.com":n._protocol.openssh_forwardedStreamLocal(a,i,s,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function zm(n,t){return n-t}Na.exports=Zt;Na.exports.IncomingClient=Is});var fd=ot((Kb,cd)=>{"use strict";var{createCipheriv:Xm,generateKeyPair:Jm,generateKeyPairSync:Zm,getCurves:eA,randomBytes:sd}=require("crypto"),{Ber:pt}=Gn(),tA=js().pbkdf,{CIPHER_INFO:rA}=Lr(),nA=16,iA=16,sA=eA(),oA=new Map(Object.entries(rA));function od(n,t){if(typeof n!="string")throw new TypeError("Key type must be a string");let e={type:"spki",format:"der"},r={type:"pkcs8",format:"der"};switch(n.toLowerCase()){case"rsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for RSA key");let i=t.bits;if(!Number.isInteger(i))throw new TypeError("RSA bits must be an integer");if(i<=0||i>16384)throw new RangeError("RSA bits must be non-zero and <= 16384");return["rsa",{modulusLength:i,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ecdsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for ECDSA key");if(!Number.isInteger(t.bits))throw new TypeError("ECDSA bits must be an integer");let i;switch(t.bits){case 256:i="prime256v1";break;case 384:i="secp384r1";break;case 521:i="secp521r1";break;default:throw new Error("ECDSA bits must be 256, 384, or 521")}if(!sA.includes(i))throw new Error("Unsupported ECDSA bits value");return["ec",{namedCurve:i,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ed25519":return["ed25519",{publicKeyEncoding:e,privateKeyEncoding:r}];default:throw new Error(`Unsupported key type: ${n}`)}}function aA(n,t,e){switch(n){case"rsa":{let r=new pt.Reader(e);if(r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");if(r.readSequence(),r.readOID()!=="1.2.840.113549.1.1.1")throw new Error("Bad RSA private OID");if(r.readByte()!==pt.Null)throw new Error("Malformed RSA private key (expected null)");if(r.readByte()!==0)throw new Error("Malformed RSA private key (expected zero-length null)");if(r=new pt.Reader(r.readString(pt.OctetString,!0)),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");let i=r.readString(pt.Integer,!0),s=r.readString(pt.Integer,!0),o=r.readString(pt.Integer,!0),a=r.readString(pt.Integer,!0),c=r.readString(pt.Integer,!0);r.readString(pt.Integer,!0),r.readString(pt.Integer,!0);let f=r.readString(pt.Integer,!0),u=Buffer.from("ssh-rsa"),h=Buffer.allocUnsafe(4+u.length+4+i.length+4+s.length+4+o.length+4+f.length+4+a.length+4+c.length),d=0;h.writeUInt32BE(u.length,d+=0),h.set(u,d+=4),h.writeUInt32BE(i.length,d+=u.length),h.set(i,d+=4),h.writeUInt32BE(s.length,d+=i.length),h.set(s,d+=4),h.writeUInt32BE(o.length,d+=s.length),h.set(o,d+=4),h.writeUInt32BE(f.length,d+=o.length),h.set(f,d+=4),h.writeUInt32BE(a.length,d+=f.length),h.set(a,d+=4),h.writeUInt32BE(c.length,d+=a.length),h.set(c,d+=4);let g=Buffer.allocUnsafe(4+u.length+4+s.length+4+i.length);return d=0,g.writeUInt32BE(u.length,d+=0),g.set(u,d+=4),g.writeUInt32BE(s.length,d+=u.length),g.set(s,d+=4),g.writeUInt32BE(i.length,d+=s.length),g.set(i,d+=4),{sshName:u.toString(),priv:h,pub:g}}case"ec":{let r=new pt.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA public OID");r.readOID();let i=r.readString(pt.BitString,!0);{let d=0;for(;d<i.length&&i[d]===0;++d);d>0&&(i=i.slice(d))}if(r=new pt.Reader(e),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in ECDSA private key");if(r.readSequence(),r.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA private OID");let s=r.readOID(),o;switch(s){case"1.2.840.10045.3.1.7":o="nistp256";break;case"1.3.132.0.34":o="nistp384";break;case"1.3.132.0.35":o="nistp521";break;default:throw new Error("Unsupported curve in ECDSA private key")}if(r=new pt.Reader(r.readString(pt.OctetString,!0)),r.readSequence(),r.readInt()!==1)throw new Error("Unsupported version in ECDSA private key");let a=Buffer.concat([Buffer.from([0]),r.readString(pt.OctetString,!0)]),c=Buffer.from(`ecdsa-sha2-${o}`);o=Buffer.from(o);let f=Buffer.allocUnsafe(4+c.length+4+o.length+4+i.length+4+a.length),u=0;f.writeUInt32BE(c.length,u+=0),f.set(c,u+=4),f.writeUInt32BE(o.length,u+=c.length),f.set(o,u+=4),f.writeUInt32BE(i.length,u+=o.length),f.set(i,u+=4),f.writeUInt32BE(a.length,u+=i.length),f.set(a,u+=4);let h=Buffer.allocUnsafe(4+c.length+4+o.length+4+i.length);return u=0,h.writeUInt32BE(c.length,u+=0),h.set(c,u+=4),h.writeUInt32BE(o.length,u+=c.length),h.set(o,u+=4),h.writeUInt32BE(i.length,u+=o.length),h.set(i,u+=4),{sshName:c.toString(),priv:f,pub:h}}case"ed25519":{let r=new pt.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let i=r.readString(pt.BitString,!0);{let u=0;for(;u<i.length&&i[u]===0;++u);u>0&&(i=i.slice(u))}if(r=new pt.Reader(e),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in ED25519 private key");if(r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 private OID");r=new pt.Reader(r.readString(pt.OctetString,!0));let s=r.readString(pt.OctetString,!0),o=Buffer.from("ssh-ed25519"),a=Buffer.allocUnsafe(4+o.length+4+i.length+4+(s.length+i.length)),c=0;a.writeUInt32BE(o.length,c+=0),a.set(o,c+=4),a.writeUInt32BE(i.length,c+=o.length),a.set(i,c+=4),a.writeUInt32BE(s.length+i.length,c+=i.length),a.set(s,c+=4),a.set(i,c+=s.length);let f=Buffer.allocUnsafe(4+o.length+4+i.length);return c=0,f.writeUInt32BE(o.length,c+=0),f.set(o,c+=4),f.writeUInt32BE(i.length,c+=o.length),f.set(i,c+=4),{sshName:o.toString(),priv:a,pub:f}}}}function ad(n,t,e,r){let i="new",s,o="";if(typeof r=="object"&&r!==null&&(typeof r.comment=="string"&&r.comment&&(o=r.comment),typeof r.format=="string"&&r.format&&(i=r.format),r.passphrase)){let a;if(typeof r.passphrase=="string")a=Buffer.from(r.passphrase);else if(Buffer.isBuffer(r.passphrase))a=r.passphrase;else throw new Error("Invalid passphrase");if(r.cipher===void 0)throw new Error("Missing cipher name");let c=oA.get(r.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(i==="new"){let f=iA;if(r.rounds!==void 0){if(!Number.isInteger(r.rounds))throw new TypeError("rounds must be an integer");r.rounds>0&&(f=r.rounds)}let u=Buffer.allocUnsafe(c.keyLen+c.ivLen),h=sd(nA);if(tA(a,a.length,h,h.length,u,u.length,f)!==0)return new Error("Failed to generate information to encrypt key");let g=Buffer.allocUnsafe(4+h.length+4);{let _=0;g.writeUInt32BE(h.length,_+=0),g.set(h,_+=4),g.writeUInt32BE(f,_+=h.length)}s={cipher:c,cipherName:r.cipher,kdfName:"bcrypt",kdfOptions:g,key:u.slice(0,c.keyLen),iv:u.slice(c.keyLen)}}}switch(i){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
69
- `,c,f=Buffer.from(s?s.cipherName:"none"),u=Buffer.from(s?s.kdfName:"none"),h=s?s.kdfOptions:Buffer.alloc(0),d=s?s.cipher.blockLen:8,g=aA(n,t,e),_=sd(4),y=Buffer.from(o),x=8+g.priv.length+4+y.length,I=[];for(let J=1;(x+I.length)%d;++J)I.push(J&255);I=Buffer.from(I);let O=Buffer.allocUnsafe(x+I.length),$;{let J=0;O.set(_,J+=0),O.set(_,J+=4),O.set(g.priv,J+=4),O.writeUInt32BE(y.length,J+=g.priv.length),O.set(y,J+=4),O.set(I,J+=y.length)}if(s){let J={authTagLength:s.cipher.authLen},z=Xm(s.cipher.sslName,s.key,s.iv,J);z.setAutoPadding(!1),O=Buffer.concat([z.update(O),z.final()]),s.cipher.authLen>0?$=z.getAuthTag():$=Buffer.alloc(0),s.key.fill(0),s.iv.fill(0)}else $=Buffer.alloc(0);let L=Buffer.from("openssh-key-v1\0"),j=Buffer.allocUnsafe(L.length+4+f.length+4+u.length+4+h.length+4+4+g.pub.length+4+O.length+$.length);{let J=0;j.set(L,J+=0),j.writeUInt32BE(f.length,J+=L.length),j.set(f,J+=4),j.writeUInt32BE(u.length,J+=f.length),j.set(u,J+=4),j.writeUInt32BE(h.length,J+=u.length),j.set(h,J+=4),j.writeUInt32BE(1,J+=h.length),j.writeUInt32BE(g.pub.length,J+=4),j.set(g.pub,J+=4),j.writeUInt32BE(O.length,J+=g.pub.length),j.set(O,J+=4),j.set($,J+=O.length)}{let J=j.base64Slice(0,j.length),z=J.replace(/.{64}/g,`$&
70
- `);J.length&63&&(z+=`
71
- `),a+=z}{let J=g.pub.base64Slice(0,g.pub.length);c=`${g.sshName} ${J}${o?` ${o}`:""}`}return a+=`-----END OPENSSH PRIVATE KEY-----
72
- `,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function cA(){}cd.exports={generateKeyPair:(n,t,e)=>{typeof t=="function"&&(e=t,t=void 0),typeof e!="function"&&(e=cA);let r=od(n,t);Jm(...r,(i,s,o)=>{if(i)return e(i);let a;try{a=ad(r[0],s,o,t)}catch(c){return e(c)}e(null,a)})},generateKeyPairSync:(n,t)=>{let e=od(n,t),{publicKey:r,privateKey:i}=Zm(...e);return ad(e[0],r,i,t)}}});var Pa=ot((Gb,ud)=>{"use strict";var{AgentProtocol:fA,BaseAgent:uA,createAgent:lA,CygwinAgent:hA,OpenSSHAgent:dA,PageantAgent:pA}=Ho(),{SSHTTPAgent:gA,SSHTTPSAgent:mA}=rd(),{parseKey:AA}=Dr(),{flagsToString:EA,OPEN_MODE:_A,STATUS_CODE:yA,stringToFlags:bA}=li();ud.exports={AgentProtocol:fA,BaseAgent:uA,createAgent:lA,Client:Ia(),CygwinAgent:hA,HTTPAgent:gA,HTTPSAgent:mA,OpenSSHAgent:dA,PageantAgent:pA,Server:id(),utils:{parseKey:AA,...fd(),sftp:{flagsToString:EA,OPEN_MODE:_A,STATUS_CODE:yA,stringToFlags:bA}}}});function Ka(n){return n==="1"||n==="true"}function Ga(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Wd(){return Ka(process.env.DEV_MODE)||Ka(process.env.RENDER_PERF)}function tr(n){let t=Wd();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=Ga(),r=s=>{let o=Ga()-e;console.log(`[perf][${n}] ${s}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(s="done")=>{r(s)}}}var RA=tr("HoneyPot");pr();var hb=tr("SshClient");var Pd=require("node:events"),Td=Xt(Pa(),1);var Cd=require("node:events");pr();var ld=require("node:events"),Wr=Xt(require("node:fs"),1),Er=Xt(require("node:path"),1),rn=require("node:zlib");var Cs=Xt(require("node:path"),1);function gt(n){if(!n||n.trim()==="")return"/";let t=Cs.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function xA(n){return n.split("/").filter(Boolean)}function Ut(n,t){let e=gt(t);if(e==="/")return n;let r=xA(e),i=n;for(let s of r){if(i.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=i.children.get(s);if(!o)throw new Error(`Path '${e}' does not exist.`);i=o}return i}function Tn(n,t,e,r){let i=gt(t);if(i==="/")throw new Error("Root path has no parent directory.");let s=Cs.posix.dirname(i),o=Cs.posix.basename(i);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(s);let a=Ut(n,s);if(a.type!=="directory")throw new Error(`Parent path '${s}' is not a directory.`);return{parent:a,name:o}}var Ta=class n extends ld.EventEmitter{root;mode;snapshotFile;constructor(t={}){if(super(),this.mode=t.mode??"memory",this.mode==="fs"){if(!t.snapshotPath)throw new Error('VirtualFileSystem: "snapshotPath" is required when mode is "fs".');this.snapshotFile=Er.resolve(t.snapshotPath,"vfs-snapshot.json")}else this.snapshotFile=null;this.root=this.makeDir("",493)}makeDir(t,e){let r=new Date;return{type:"directory",name:t,mode:e,createdAt:r,updatedAt:r,children:new Map}}makeFile(t,e,r,i){let s=new Date;return{type:"file",name:t,content:e,mode:r,compressed:i,createdAt:s,updatedAt:s}}mkdirRecursive(t,e){let r=gt(t);if(r==="/")return;let i=r.split("/").filter(Boolean),s=this.root,o="";for(let a of i){o+=`/${a}`;let c=s.children.get(a);if(!c)c=this.makeDir(a,e),s.children.set(a,c),this.emit("dir:create",{path:o,mode:e});else if(c.type!=="directory")throw new Error(`Cannot create directory '${o}': path is a file.`);s=c}}async restoreMirror(){if(!(this.mode!=="fs"||!this.snapshotFile)&&Wr.existsSync(this.snapshotFile))try{let t=Wr.readFileSync(this.snapshotFile,"utf8"),e=JSON.parse(t);this.root=this.deserializeDir(e.root,""),this.emit("snapshot:restore",{path:this.snapshotFile})}catch(t){console.warn(`[VirtualFileSystem] Could not restore snapshot from ${this.snapshotFile}:`,t instanceof Error?t.message:String(t))}}async flushMirror(){if(this.mode!=="fs"||!this.snapshotFile){this.emit("mirror:flush");return}let t=Er.dirname(this.snapshotFile);Wr.mkdirSync(t,{recursive:!0});let e=this.toSnapshot();Wr.writeFileSync(this.snapshotFile,JSON.stringify(e),"utf8"),this.emit("mirror:flush",{path:this.snapshotFile})}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}mkdir(t,e=493){let r=gt(t),i=(()=>{try{return Ut(this.root,r)}catch{return null}})();if(i&&i.type!=="directory")throw new Error(`Cannot create directory '${r}': path is a file.`);this.mkdirRecursive(r,e)}writeFile(t,e,r={}){let i=gt(t),{parent:s,name:o}=Tn(this.root,i,!0,d=>this.mkdirRecursive(d,493)),a=s.children.get(o);if(a?.type==="directory")throw new Error(`Cannot write file '${i}': path is a directory.`);let c=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),f=r.compress??!1,u=f?(0,rn.gzipSync)(c):c,h=r.mode??420;if(a){let d=a;d.content=u,d.compressed=f,d.mode=h,d.updatedAt=new Date}else s.children.set(o,this.makeFile(o,u,h,f));this.emit("file:write",{path:i,size:u.length})}readFile(t){let e=gt(t),r=Ut(this.root,e);if(r.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=r,s=i.compressed?(0,rn.gunzipSync)(i.content):i.content;return this.emit("file:read",{path:e,size:s.length}),s.toString("utf8")}readFileRaw(t){let e=gt(t),r=Ut(this.root,e);if(r.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=r,s=i.compressed?(0,rn.gunzipSync)(i.content):i.content;return this.emit("file:read",{path:e,size:s.length}),s}exists(t){try{return Ut(this.root,gt(t)),!0}catch{return!1}}chmod(t,e){Ut(this.root,gt(t)).mode=e}stat(t){let e=gt(t),r=Ut(this.root,e),i=e==="/"?"":Er.posix.basename(e);if(r.type==="file"){let o=r;return{type:"file",name:i,path:e,mode:o.mode,createdAt:o.createdAt,updatedAt:o.updatedAt,compressed:o.compressed,size:o.content.length}}let s=r;return{type:"directory",name:i,path:e,mode:s.mode,createdAt:s.createdAt,updatedAt:s.updatedAt,childrenCount:s.children.size}}list(t="/"){let e=gt(t),r=Ut(this.root,e);if(r.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Array.from(r.children.keys()).sort()}tree(t="/"){let e=gt(t),r=Ut(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let i=t==="/"?"/":Er.posix.basename(e);return this.renderTreeLines(r,i)}renderTreeLines(t,e){let r=[e],i=Array.from(t.children.keys()).sort();for(let s=0;s<i.length;s++){let o=i[s],a=t.children.get(o),c=s===i.length-1,f=c?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",u=c?" ":"\u2502 ";if(r.push(`${f}${o}`),a.type==="directory"){let h=this.renderTreeLines(a,"").split(`
73
- `).slice(1).map(d=>`${u}${d}`);r.push(...h)}}return r.join(`
74
- `)}getUsageBytes(t="/"){return this.computeUsage(Ut(this.root,gt(t)))}computeUsage(t){if(t.type==="file")return t.content.length;let e=0;for(let r of t.children.values())e+=this.computeUsage(r);return e}compressFile(t){let e=Ut(this.root,gt(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=(0,rn.gzipSync)(r.content),r.compressed=!0,r.updatedAt=new Date)}decompressFile(t){let e=Ut(this.root,gt(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=(0,rn.gunzipSync)(r.content),r.compressed=!1,r.updatedAt=new Date)}symlink(t,e){let r=gt(e),i=t.startsWith("/")?gt(t):t,{parent:s,name:o}=Tn(this.root,r,!0,c=>this.mkdirRecursive(c,493)),a={type:"file",name:o,content:Buffer.from(i,"utf8"),mode:41471,compressed:!1,createdAt:new Date,updatedAt:new Date};s.children.set(o,a),this.emit("symlink:create",{link:r,target:i})}isSymlink(t){try{let e=Ut(this.root,gt(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=gt(t);for(let i=0;i<e;i++){try{let s=Ut(this.root,r);if(s.type==="file"&&s.mode===41471){let o=s.content.toString("utf8");r=o.startsWith("/")?o:gt(Er.posix.join(Er.posix.dirname(r),o));continue}}catch{break}return r}throw new Error(`Too many levels of symbolic links: ${t}`)}remove(t,e={}){let r=gt(t);if(r==="/")throw new Error("Cannot remove root directory.");let i=Ut(this.root,r);if(i.type==="directory"){let a=i;if(!e.recursive&&a.children.size>0)throw new Error(`Directory '${r}' is not empty. Use recursive option.`)}let{parent:s,name:o}=Tn(this.root,r,!1,()=>{});s.children.delete(o),this.emit("node:remove",{path:r})}move(t,e){let r=gt(t),i=gt(e);if(r==="/"||i==="/")throw new Error("Cannot move root directory.");let s=Ut(this.root,r);if(this.exists(i))throw new Error(`Destination '${i}' already exists.`);this.mkdirRecursive(Er.posix.dirname(i),493);let{parent:o,name:a}=Tn(this.root,i,!1,()=>{}),{parent:c,name:f}=Tn(this.root,r,!1,()=>{});c.children.delete(f),s.name=a,o.children.set(a,s)}toSnapshot(){return{root:this.serializeDir(this.root)}}serializeDir(t){let e=[];for(let r of t.children.values())e.push(r.type==="file"?this.serializeFile(r):this.serializeDir(r));return{type:"directory",name:t.name,mode:t.mode,createdAt:t.createdAt.toISOString(),updatedAt:t.updatedAt.toISOString(),children:e}}serializeFile(t){return{type:"file",name:t.name,mode:t.mode,createdAt:t.createdAt.toISOString(),updatedAt:t.updatedAt.toISOString(),compressed:t.compressed,contentBase64:t.content.toString("base64")}}static fromSnapshot(t){let e=new n;return e.root=e.deserializeDir(t.root,""),e}importSnapshot(t){this.root=this.deserializeDir(t.root,""),this.emit("snapshot:import")}deserializeDir(t,e){let r={type:"directory",name:e,mode:t.mode,createdAt:new Date(t.createdAt),updatedAt:new Date(t.updatedAt),children:new Map};for(let i of t.children)if(i.type==="file"){let s=i;r.children.set(s.name,{type:"file",name:s.name,mode:s.mode,createdAt:new Date(s.createdAt),updatedAt:new Date(s.updatedAt),compressed:s.compressed,content:Buffer.from(s.contentBase64,"base64")})}else{let s=this.deserializeDir(i,i.name);r.children.set(i.name,s)}return r}},La=Ta;var qr=require("node:crypto"),dd=require("node:events"),pd=Xt(require("node:path"),1);function SA(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var wt=tr("VirtualUserManager"),yi=class n extends dd.EventEmitter{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;wt.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=SA();usersPath="/virtual-env-js/.auth/htpasswd";sudoersPath="/virtual-env-js/.auth/sudoers";quotasPath="/virtual-env-js/.auth/quotas";authDirPath="/virtual-env-js/.auth";users=new Map;sudoers=new Set;quotas=new Map;activeSessions=new Map;nextTty=0;async initialize(){wt.mark("initialize"),this.loadFromVfs(),this.loadSudoersFromVfs(),this.loadQuotasFromVfs();let e=!1;this.users.has("root")||(this.users.set("root",this.createRecord("root","")),e=!0),this.sudoers.add("root"),e&&await this.persist(),this.emit("initialized")}async setQuotaBytes(e,r){if(wt.mark("setQuotaBytes"),this.validateUsername(e),!this.users.has(e))throw new Error(`quota: user '${e}' does not exist`);if(!Number.isFinite(r)||r<0)throw new Error("quota: maxBytes must be a non-negative number");this.quotas.set(e,Math.floor(r)),await this.persist()}async clearQuota(e){wt.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return wt.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){wt.mark("getUsageBytes");let r=`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,i){wt.mark("assertWriteWithinQuota");let s=this.quotas.get(e);if(s===void 0)return;let o=hd(r),a=hd(`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let f=this.getUsageBytes(e),u=0;if(this.vfs.exists(o)){let g=this.vfs.stat(o);g.type==="file"&&(u=g.size)}let h=Buffer.isBuffer(i)?i.length:Buffer.byteLength(i,"utf8"),d=f-u+h;if(d>s)throw new Error(`quota exceeded for '${e}': ${d}/${s} bytes`)}verifyPassword(e,r){wt.mark("verifyPassword");let i=this.users.get(e);return i?this.hashPassword(r)===i.passwordHash:!1}async addUser(e,r){if(wt.mark("addUser"),this.validateUsername(e),this.validatePassword(r),this.users.has(e))return;this.users.set(e,this.createRecord(e,r)),this.autoSudoForNewUsers&&this.sudoers.add(e);let i=`/home/${e}`;this.vfs.exists(i)||(this.vfs.mkdir(i,493),this.vfs.writeFile(`${i}/README.txt`,`Welcome to the virtual environment, ${e}`)),await this.persist(),this.emit("user:add",{username:e})}getPasswordHash(e){wt.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(wt.mark("setPassword"),this.validateUsername(e),this.validatePassword(r),!this.users.has(e))throw new Error(`passwd: user '${e}' does not exist`);this.users.set(e,this.createRecord(e,r)),await this.persist()}async deleteUser(e){if(wt.mark("deleteUser"),this.validateUsername(e),e==="root")throw new Error("deluser: cannot delete root");if(!this.users.delete(e))throw new Error(`deluser: user '${e}' does not exist`);this.sudoers.delete(e),this.emit("user:delete",{username:e}),await this.persist()}isSudoer(e){return wt.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(wt.mark("addSudoer"),this.validateUsername(e),!this.users.has(e))throw new Error(`sudoers: user '${e}' does not exist`);this.sudoers.add(e),await this.persist()}async removeSudoer(e){if(wt.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){wt.mark("registerSession");let i={id:(0,qr.randomUUID)(),username:e,tty:`pts/${this.nextTty++}`,remoteAddress:r,startedAt:new Date().toISOString()};return this.activeSessions.set(i.id,i),this.emit("session:register",{sessionId:i.id,username:e,remoteAddress:r}),i}unregisterSession(e){if(wt.mark("unregisterSession"),!e)return;let r=this.activeSessions.get(e);this.activeSessions.delete(e),r&&this.emit("session:unregister",{sessionId:e,username:r.username}),this.activeSessions.delete(e)}updateSession(e,r,i){if(wt.mark("updateSession"),!e)return;let s=this.activeSessions.get(e);s&&this.activeSessions.set(e,{...s,username:r,remoteAddress:i})}listActiveSessions(){return wt.mark("listActiveSessions"),Array.from(this.activeSessions.values()).sort((e,r)=>e.startedAt.localeCompare(r.startedAt))}loadFromVfs(){if(this.users.clear(),!this.vfs.exists(this.usersPath))return;let e=this.vfs.readFile(this.usersPath);for(let r of e.split(`
75
- `)){let i=r.trim();if(i.length===0)continue;let s=i.split(":");if(s.length<3)continue;let[o,a,c]=s;!o||!a||!c||this.users.set(o,{username:o,salt:a,passwordHash:c})}}loadSudoersFromVfs(){if(this.sudoers.clear(),!this.vfs.exists(this.sudoersPath))return;let e=this.vfs.readFile(this.sudoersPath);for(let r of e.split(`
76
- `)){let i=r.trim();i.length>0&&this.sudoers.add(i)}}loadQuotasFromVfs(){if(this.quotas.clear(),!this.vfs.exists(this.quotasPath))return;let e=this.vfs.readFile(this.quotasPath);for(let r of e.split(`
77
- `)){let i=r.trim();if(i.length===0)continue;let[s,o]=i.split(":"),a=Number.parseInt(o??"",10);!s||!Number.isFinite(a)||a<0||this.quotas.set(s,a)}}async persist(){this.vfs.exists(this.authDirPath)||this.vfs.mkdir(this.authDirPath,448);let e=Array.from(this.users.values()).sort((o,a)=>o.username.localeCompare(a.username)).map(o=>[o.username,o.salt,o.passwordHash].join(":")).join(`
78
- `),r=Array.from(this.sudoers.values()).sort().join(`
14
+ ${e}`}};var Ug=2**32,gu=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();fi.ERR_OUT_OF_RANGE=class Au extends RangeError{constructor(t,e,n,i){super(),Error.captureStackTrace(this,Au),us(e,'Missing "range" argument');let s=i?t:`The value of "${t}" is out of range.`,o;Number.isInteger(n)&&Math.abs(n)>Ug?o=hu(String(n)):typeof n=="bigint"?(o=String(n),(n>gu||n<-gu)&&(o=hu(o)),o+="n"):o=Lg(n),s+=` It must be ${e}. Received ${o}`,this.message=s}};var ds=class r extends TypeError{constructor(t,e,n){super(),Error.captureStackTrace(this,r),us(typeof t=="string","'name' must be a string");let i;typeof e=="string"&&e.startsWith("not ")?(i="must not be",e=e.replace(/^not /,"")):i="must be";let s;if(t.endsWith(" argument"))s=`The ${t} ${i} ${pu(e,"type")}`;else{let o=t.includes(".")?"property":"argument";s=`The "${t}" ${o} ${i} ${pu(e,"type")}`}s+=`. Received type ${typeof n}`,this.message=s}};fi.ERR_INVALID_ARG_TYPE=ds;fi.validateNumber=function(t,e){if(typeof t!="number")throw new ds(e,"number",t)}});var li=ot((qy,Nu)=>{"use strict";var Dg=require("events"),Dr=require("fs"),{constants:Gt}=Dr,{Readable:wu,Writable:ia}=require("stream"),{inherits:Iu,types:{isDate:Jo}}=require("util"),Og=Buffer[Symbol.species],{bufferCopy:Ur,bufferSlice:Cn,makeBufferParser:Mg,writeUInt32BE:H}=or(),Ir={SIZE:1,UIDGID:2,PERMISSIONS:4,ACMODTIME:8,EXTENDED:2147483648},Be=Buffer.alloc(28),Ze={OK:0,EOF:1,NO_SUCH_FILE:2,PERMISSION_DENIED:3,FAILURE:4,BAD_MESSAGE:5,NO_CONNECTION:6,CONNECTION_LOST:7,OP_UNSUPPORTED:8},Fg=new Map(Object.values(Ze).map(r=>[r,1])),$g={[Ze.OK]:"No error",[Ze.EOF]:"End of file",[Ze.NO_SUCH_FILE]:"No such file or directory",[Ze.PERMISSION_DENIED]:"Permission denied",[Ze.FAILURE]:"Failure",[Ze.BAD_MESSAGE]:"Bad message",[Ze.NO_CONNECTION]:"No connection",[Ze.CONNECTION_LOST]:"Connection lost",[Ze.OP_UNSUPPORTED]:"Operation unsupported"},ve={INIT:1,OPEN:3,CLOSE:4,READ:5,WRITE:6,LSTAT:7,FSTAT:8,SETSTAT:9,FSETSTAT:10,OPENDIR:11,READDIR:12,REMOVE:13,MKDIR:14,RMDIR:15,REALPATH:16,STAT:17,RENAME:18,READLINK:19,SYMLINK:20,EXTENDED:200},Yt={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},Se={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},_u=2*1024,ct=2**32-1,Hg=Buffer.from([0,0,0,5,ve.INIT,0,0,0,3]),Qg=Buffer.from([0,0,0,5,Yt.VERSION,0,0,0,3]),Wg=/^SSH-2.0-(?:OpenSSH|dropbear)/,zo=256*1024,T=Mg(),qg={readable:!1,writable:!1,push:r=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function Cu(){}var Zo=class extends Dg{constructor(t,e,n){super(),(typeof n!="object"||!n)&&(n={});let i=t._protocol._remoteIdentRaw;this.server=!!n.server,this._debug=typeof n.debug=="function"?n.debug:void 0,this._isOpenSSH=i&&Wg.test(i),this._version=-1,this._extensions={},this._biOpt=n.biOpt,this._pktLenBytes=0,this._pktLen=0,this._pktPos=0,this._pktType=0,this._pktData=void 0,this._writeReqid=-1,this._requests={},this._maxInPktLen=zo,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?zo:34e3)-_u,this._maxWriteLen=(this._isOpenSSH?zo:34e3)-_u,this.maxOpenHandles=void 0,this._client=t,this._protocol=t._protocol,this._callbacks=[],this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this._waitWindow=!1,this._chunkcb=void 0,this._buffer=[],this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this.stderr=qg,this.readable=!0}push(t){if(t===null){if(Ru(this),!this.readable)return;this.readable=!1,this.emit("end");return}let e=0;for(;e<t.length;){if(this._pktLenBytes<4){let o=Math.min(4-this._pktLenBytes,t.length-e);for(this._pktLenBytes+=o;o--;)this._pktLen=(this._pktLen<<8)+t[e++];if(this._pktLenBytes<4)return;if(this._pktLen===0)return nt(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return nt(this,`Packet length ${this._pktLen} exceeds max length of ${a}`)}if(e>=t.length)return}if(this._pktPos<this._pktLen){let o=Math.min(this._pktLen-this._pktPos,t.length-e);if(e!==0||o!==t.length?o===this._pktLen?this._pkt=new Og(t.buffer,t.byteOffset+e,o):(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._pktPos)):o===this._pktLen?this._pkt=t:(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(t,this._pktPos)),e+=o,this._pktPos+=o,this._pktPos<this._pktLen)return}let n=this._pkt[0],i=this._pkt;this._pktLen=0,this._pktLenBytes=0,this._pkt=void 0,this._pktPos=0;let s=this.server?jg[n]:Yg[n];if(!s)return nt(this,`Unknown packet type ${n}`);if(this._version===-1){if(this.server){if(n!==ve.INIT)return nt(this,`Expected INIT packet, got ${n}`)}else if(n!==Yt.VERSION)return nt(this,`Expected VERSION packet, got ${n}`)}if(s(this,i)===!1)return}}end(){this.destroy()}destroy(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._protocol.channelClose(this.outgoing.id))}_init(){this._init=Cu,this.server||ze(this,Hg)}createReadStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new Cr(this,t,e)}createWriteStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new sr(this,t,e)}open(t,e,n,i){if(this.server)throw new Error("Client-only method called in server mode");typeof n=="function"&&(i=n,n=void 0);let s=typeof e=="number"?e:ku(e);if(s===null)throw new Error(`Unknown flags string: ${e}`);let o=0,a=0;(typeof n=="string"||typeof n=="number")&&(n={mode:n}),typeof n=="object"&&n!==null&&(n=Jr(n),o=n.flags,a=n.nb);let c=Buffer.byteLength(t),f=9,l=Buffer.allocUnsafe(13+c+4+4+a);H(l,l.length-4,0),l[4]=ve.OPEN;let u=this._writeReqid=this._writeReqid+1&ct;H(l,u,5),H(l,c,f),l.utf8Write(t,f+=4,c),H(l,s,f+=c),H(l,o,f+=4),a&&(f+=4,a===Be.length?l.set(Be,f):Ur(Be,l,0,a,f),f+=a),this._requests[u]={cb:i};let h=ze(this,l);this._debug&&this._debug(`SFTP: Outbound: ${h?"Buffered":"Sending"} OPEN`)}close(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let n=t.length,i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.CLOSE;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.set(t,i+=4),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} CLOSE`)}read(t,e,n,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(n>=e.length)throw new Error("offset is out of bounds");if(n+i>e.length)throw new Error("length extends beyond buffer");if(s===null)throw new Error("null position currently unsupported");vu(this,t,e,n,i,s,o)}readData(t,e,n,i,s,o){this.read(t,e,n,i,s,o)}write(t,e,n,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(n>e.length)throw new Error("offset is out of bounds");if(n+i>e.length)throw new Error("length extends beyond buffer");if(s===null)throw new Error("null position currently unsupported");if(!i){o&&process.nextTick(o,void 0,0);return}let a=this._maxWriteLen,c=Math.max(i-a,0),f=s;c&&(i=a);let l=t.length,u=9,h=Buffer.allocUnsafe(13+l+8+4+i);H(h,h.length-4,0),h[4]=ve.WRITE;let g=this._writeReqid=this._writeReqid+1&ct;H(h,g,5),H(h,l,u),h.set(t,u+=4),u+=l;for(let _=7;_>=0;--_)h[u+_]=s&255,s/=256;H(h,i,u+=8),Ur(e,h,n,n+i,u+=4),this._requests[g]={cb:_=>{_?typeof o=="function"&&o(_):c?this.write(t,e,n+i,c,f+i,o):typeof o=="function"&&o(void 0,n+i)}};let b=ze(this,h);if(this._debug){let _=b?"Sent":"Buffered";this._debug(`SFTP: Outbound: ${_} WRITE (id:${g})`)}}writeData(t,e,n,i,s,o){this.write(t,e,n,i,s,o)}fastGet(t,e,n,i){if(this.server)throw new Error("Client-only method called in server mode");bu(this,Dr,t,e,n,i)}fastPut(t,e,n,i){if(this.server)throw new Error("Client-only method called in server mode");bu(Dr,this,t,e,n,i)}readFile(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof n=="function"?i=n:typeof e=="function"&&(i=e,e=void 0),typeof e=="string")e={encoding:e,flag:"r"};else if(!e)e={encoding:null,flag:"r"};else if(typeof e!="object")throw new TypeError("Bad arguments");let s=e.encoding;if(s&&!Buffer.isEncoding(s))throw new Error(`Unknown encoding: ${s}`);let o,a,c,f=0,l,u=0,h=e.flag||"r",g=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(l,a,0,8192,u,b)):this.read(l,a,f,o-f,u,b)},b=(x,S)=>{let N;if(x){if(N=x.code===Ze.EOF,!N)return this.close(l,()=>i&&i(x))}else N=!1;if(N||o===0&&S===0)return _();u+=S,f+=S,o!==0?f===o?_():g():(c.push(Cn(a,0,S)),g())};b._wantEOFError=!0;let _=()=>{this.close(l,x=>(o===0?a=Buffer.concat(c,f):f<o&&(a=Cn(a,0,f)),s&&(a=a.toString(s)),i&&i(x,a)))};this.open(t,h,438,(x,S)=>{if(x)return i&&i(x);l=S;let N=(O,P)=>{if(O){this.stat(t,(W,X)=>{if(W)return this.close(l,()=>{i&&i(O)});N(null,X)});return}if(o=P.size||0,o===0)return c=[],g();a=Buffer.allocUnsafe(o),g()};this.fstat(l,N)})}writeFile(t,e,n,i){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof i=="function"?s=i:typeof n=="function"&&(s=n,n=void 0),typeof n=="string")n={encoding:n,mode:438,flag:"w"};else if(!n)n={encoding:"utf8",mode:438,flag:"w"};else if(typeof n!="object")throw new TypeError("Bad arguments");if(n.encoding&&!Buffer.isEncoding(n.encoding))throw new Error(`Unknown encoding: ${n.encoding}`);let o=n.flag||"w";this.open(t,o,n.mode,(a,c)=>{if(a)s&&s(a);else{let f=Buffer.isBuffer(e)?e:Buffer.from(""+e,n.encoding||"utf8"),l=/a/.test(o)?null:0;if(l===null){let u=(h,g)=>{if(h){this.stat(t,(b,_)=>{if(b)return this.close(c,()=>{s&&s(h)});u(null,_)});return}ea(this,c,f,0,f.length,g.size,s)};this.fstat(c,u);return}ea(this,c,f,0,f.length,l,s)}})}appendFile(t,e,n,i){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof i=="function"?s=i:typeof n=="function"&&(s=n,n=void 0),typeof n=="string")n={encoding:n,mode:438,flag:"a"};else if(!n)n={encoding:"utf8",mode:438,flag:"a"};else if(typeof n!="object")throw new TypeError("Bad arguments");n.flag||(n=Object.assign({flag:"a"},n)),this.writeFile(t,e,n,s)}exists(t,e){if(this.server)throw new Error("Client-only method called in server mode");this.stat(t,n=>{e&&e(!n)})}unlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.REMOVE;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.utf8Write(t,i+=4,n),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REMOVE`)}rename(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=Buffer.byteLength(e),o=9,a=Buffer.allocUnsafe(13+i+4+s);H(a,a.length-4,0),a[4]=ve.RENAME;let c=this._writeReqid=this._writeReqid+1&ct;H(a,c,5),H(a,i,o),a.utf8Write(t,o+=4,i),H(a,s,o+=i),a.utf8Write(e,o+=4,s),this._requests[c]={cb:n};let f=ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} RENAME`)}mkdir(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");let i=0,s=0;typeof e=="function"&&(n=e,e=void 0),typeof e=="object"&&e!==null&&(e=Jr(e),i=e.flags,s=e.nb);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+s);H(c,c.length-4,0),c[4]=ve.MKDIR;let f=this._writeReqid=this._writeReqid+1&ct;H(c,f,5),H(c,o,a),c.utf8Write(t,a+=4,o),H(c,i,a+=o),s&&(a+=4,s===Be.length?c.set(Be,a):Ur(Be,c,0,s,a),a+=s),this._requests[f]={cb:n};let l=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} MKDIR`)}rmdir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.RMDIR;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.utf8Write(t,i+=4,n),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} RMDIR`)}readdir(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");typeof e=="function"&&(n=e,e={}),(typeof e!="object"||e===null)&&(e={});let i=!(e&&e.full);if(!Buffer.isBuffer(t)&&typeof t!="string")throw new Error("missing directory handle or path");if(typeof t=="string"){let l=[],u=0,h=(g,b)=>{if(g)return n(g);this.readdir(b,e,(_,x)=>{let S=_&&_.code===Ze.EOF;if(_&&!S)return this.close(b,()=>n(_));if(S)return this.close(b,N=>{if(N)return n(N);n(void 0,l)});for(let N=0;N<x.length;++N,++u)l[u]=x[N];h(void 0,b)})};return this.opendir(t,h)}let s=t.length,o=9,a=Buffer.allocUnsafe(13+s);H(a,a.length-4,0),a[4]=ve.READDIR;let c=this._writeReqid=this._writeReqid+1&ct;H(a,c,5),H(a,s,o),a.set(t,o+=4),this._requests[c]={cb:i?(l,u)=>{if(typeof n=="function"){if(l)return n(l);for(let h=u.length-1;h>=0;--h)(u[h].filename==="."||u[h].filename==="..")&&u.splice(h,1);n(void 0,u)}}:n};let f=ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} READDIR`)}fstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let n=t.length,i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.FSTAT;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.set(t,i+=4),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} FSTAT`)}stat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.STAT;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.utf8Write(t,i+=4,n),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STAT`)}lstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.LSTAT;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.utf8Write(t,i+=4,n),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} LSTAT`)}opendir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.OPENDIR;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.utf8Write(t,i+=4,n),this._requests[o]={cb:e};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} OPENDIR`)}setstat(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");let i=0,s=0;typeof e=="object"&&e!==null?(e=Jr(e),i=e.flags,s=e.nb):typeof e=="function"&&(n=e);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+s);H(c,c.length-4,0),c[4]=ve.SETSTAT;let f=this._writeReqid=this._writeReqid+1&ct;H(c,f,5),H(c,o,a),c.utf8Write(t,a+=4,o),H(c,i,a+=o),s&&(a+=4,s===Be.length?c.set(Be,a):Ur(Be,c,0,s,a),a+=s),this._requests[f]={cb:n};let l=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} SETSTAT`)}fsetstat(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let i=0,s=0;typeof e=="object"&&e!==null?(e=Jr(e),i=e.flags,s=e.nb):typeof e=="function"&&(n=e);let o=t.length,a=9,c=Buffer.allocUnsafe(13+o+4+s);H(c,c.length-4,0),c[4]=ve.FSETSTAT;let f=this._writeReqid=this._writeReqid+1&ct;H(c,f,5),H(c,o,a),c.set(t,a+=4),H(c,i,a+=o),s&&(a+=4,s===Be.length?c.set(Be,a):Ur(Be,c,0,s,a),a+=s),this._requests[f]={cb:n};let l=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} FSETSTAT`)}futimes(t,e,n,i){return this.fsetstat(t,{atime:wn(e),mtime:wn(n)},i)}utimes(t,e,n,i){return this.setstat(t,{atime:wn(e),mtime:wn(n)},i)}fchown(t,e,n,i){return this.fsetstat(t,{uid:e,gid:n},i)}chown(t,e,n,i){return this.setstat(t,{uid:e,gid:n},i)}fchmod(t,e,n){return this.fsetstat(t,{mode:e},n)}chmod(t,e,n){return this.setstat(t,{mode:e},n)}readlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.READLINK;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.utf8Write(t,i+=4,n),this._requests[o]={cb:(c,f)=>{if(typeof e=="function"){if(c)return e(c);if(!f||!f.length)return e(new Error("Response missing link info"));e(void 0,f[0].filename)}}};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} READLINK`)}symlink(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),s=Buffer.byteLength(t),o=9,a=Buffer.allocUnsafe(13+i+4+s);H(a,a.length-4,0),a[4]=ve.SYMLINK;let c=this._writeReqid=this._writeReqid+1&ct;H(a,c,5),this._isOpenSSH?(H(a,s,o),a.utf8Write(t,o+=4,s),H(a,i,o+=s),a.utf8Write(e,o+=4,i)):(H(a,i,o),a.utf8Write(e,o+=4,i),H(a,s,o+=i),a.utf8Write(t,o+=4,s)),this._requests[c]={cb:n};let f=ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} SYMLINK`)}realpath(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=ve.REALPATH;let o=this._writeReqid=this._writeReqid+1&ct;H(s,o,5),H(s,n,i),s.utf8Write(t,i+=4,n),this._requests[o]={cb:(c,f)=>{if(typeof e=="function"){if(c)return e(c);if(!f||!f.length)return e(new Error("Response missing path info"));e(void 0,f[0].filename)}}};let a=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REALPATH`)}ext_openssh_rename(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");let i=this._extensions["posix-rename@openssh.com"];if(!i||i!=="1")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(41+s+4+o);H(c,c.length-4,0),c[4]=ve.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ct;H(c,f,5),H(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),H(c,s,a+=24),c.utf8Write(t,a+=4,s),H(c,o,a+=s),c.utf8Write(e,a+=4,o),this._requests[f]={cb:n};let l=ze(this,c);if(this._debug){let u=l?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${u} posix-rename@openssh.com`)}}ext_openssh_statvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=this._extensions["statvfs@openssh.com"];if(!n||n!=="2")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),s=9,o=Buffer.allocUnsafe(36+i);H(o,o.length-4,0),o[4]=ve.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ct;H(o,a,5),H(o,19,s),o.utf8Write("statvfs@openssh.com",s+=4,19),H(o,i,s+=19),o.utf8Write(t,s+=4,i),this._requests[a]={extended:"statvfs@openssh.com",cb:e};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} statvfs@openssh.com`)}}ext_openssh_fstatvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let n=this._extensions["fstatvfs@openssh.com"];if(!n||n!=="2")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let i=t.length,s=9,o=Buffer.allocUnsafe(37+i);H(o,o.length-4,0),o[4]=ve.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ct;H(o,a,5),H(o,20,s),o.utf8Write("fstatvfs@openssh.com",s+=4,20),H(o,i,s+=20),o.set(t,s+=4),this._requests[a]={extended:"fstatvfs@openssh.com",cb:e};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} fstatvfs@openssh.com`)}}ext_openssh_hardlink(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["hardlink@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(37+s+4+o);H(c,c.length-4,0),c[4]=ve.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ct;H(c,f,5),H(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),H(c,s,a+=20),c.utf8Write(t,a+=4,s),H(c,o,a+=s),c.utf8Write(e,a+=4,o),this._requests[f]={cb:n};let l=ze(this,c);if(this._debug){let u=l?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${u} hardlink@openssh.com`)}}ext_openssh_fsync(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["fsync@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let i=t.length,s=9,o=Buffer.allocUnsafe(34+i);H(o,o.length-4,0),o[4]=ve.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ct;H(o,a,5),H(o,17,s),o.utf8Write("fsync@openssh.com",s+=4,17),H(o,i,s+=17),o.set(t,s+=4),this._requests[a]={cb:e};let c=ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${c?"Buffered":"Sending"} fsync@openssh.com`)}ext_openssh_lsetstat(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["lsetstat@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let s=0,o=0;typeof e=="object"&&e!==null?(e=Jr(e),s=e.flags,o=e.nb):typeof e=="function"&&(n=e);let a=Buffer.byteLength(t),c=9,f=Buffer.allocUnsafe(37+a+4+o);H(f,f.length-4,0),f[4]=ve.EXTENDED;let l=this._writeReqid=this._writeReqid+1&ct;H(f,l,5),H(f,20,c),f.utf8Write("lsetstat@openssh.com",c+=4,20),H(f,a,c+=20),f.utf8Write(t,c+=4,a),H(f,s,c+=a),o&&(c+=4,o===Be.length?f.set(Be,c):Ur(Be,f,0,o,c),c+=o),this._requests[l]={cb:n};let u=ze(this,f);if(this._debug){let h=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} lsetstat@openssh.com`)}}ext_openssh_expandPath(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["expand-path@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),s=9,o=Buffer.allocUnsafe(40+i);H(o,o.length-4,0),o[4]=ve.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ct;H(o,a,5),H(o,23,s),o.utf8Write("expand-path@openssh.com",s+=4,23),H(o,i,s+=20),o.utf8Write(t,s+=4,i),this._requests[a]={cb:(f,l)=>{if(typeof e=="function"){if(f)return e(f);if(!l||!l.length)return e(new Error("Response missing expanded path"));e(void 0,l[0].filename)}}};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} expand-path@openssh.com`)}}ext_copy_data(t,e,n,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["copy-data"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("Source handle is not a Buffer");if(!Buffer.isBuffer(i))throw new Error("Destination handle is not a Buffer");let c=0,f=Buffer.allocUnsafe(26+t.length+8+8+4+i.length+8);H(f,f.length-4,c),c+=4,f[c]=ve.EXTENDED,++c;let l=this._writeReqid=this._writeReqid+1&ct;H(f,l,c),c+=4,H(f,9,c),c+=4,f.utf8Write("copy-data",c,9),c+=9,H(f,t.length,c),c+=4,f.set(t,c),c+=t.length;for(let h=7;h>=0;--h)f[c+h]=e&255,e/=256;c+=8;for(let h=7;h>=0;--h)f[c+h]=n&255,n/=256;c+=8,H(f,i.length,c),c+=4,f.set(i,c),c+=i.length;for(let h=7;h>=0;--h)f[c+h]=s&255,s/=256;this._requests[l]={cb:o};let u=ze(this,f);if(this._debug){let h=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} copy-data`)}}ext_home_dir(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["home-directory"]!=="1")throw new Error("Server does not support this extended request");if(typeof t!="string")throw new TypeError("username is not a string");let i=0,s=Buffer.byteLength(t),o=Buffer.allocUnsafe(31+s);H(o,o.length-4,i),i+=4,o[i]=ve.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&ct;H(o,a,i),i+=4,H(o,14,i),i+=4,o.utf8Write("home-directory",i,14),i+=14,H(o,s,i),i+=4,o.utf8Write(t,i,s),i+=s,this._requests[a]={cb:(f,l)=>{if(typeof e=="function"){if(f)return e(f);if(!l||!l.length)return e(new Error("Response missing home directory"));e(void 0,l[0].filename)}}};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} home-directory`)}}ext_users_groups(t,e,n){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["users-groups-by-id@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Array.isArray(t))throw new TypeError("uids is not an array");for(let f of t)if(!Number.isInteger(f)||f<0||f>2**32-1)throw new Error("uid values must all be 32-bit unsigned integers");if(!Array.isArray(e))throw new TypeError("gids is not an array");for(let f of e)if(!Number.isInteger(f)||f<0||f>2**32-1)throw new Error("gid values must all be 32-bit unsigned integers");let s=0,o=Buffer.allocUnsafe(47+4*t.length+4+4*e.length);H(o,o.length-4,s),s+=4,o[s]=ve.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&ct;H(o,a,s),s+=4,H(o,30,s),s+=4,o.utf8Write("users-groups-by-id@openssh.com",s,30),s+=30,H(o,4*t.length,s),s+=4;for(let f of t)H(o,f,s),s+=4;H(o,4*e.length,s),s+=4;for(let f of e)H(o,f,s),s+=4;this._requests[a]={extended:"users-groups-by-id@openssh.com",cb:n};let c=ze(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} users-groups-by-id@openssh.com`)}}handle(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(!Buffer.isBuffer(e))throw new Error("handle is not a Buffer");let n=e.length;if(n>256)throw new Error("handle too large (> 256 bytes)");let i=9,s=Buffer.allocUnsafe(13+n);H(s,s.length-4,0),s[4]=Yt.HANDLE,H(s,t,5),H(s,n,i),n&&s.set(e,i+=4);let o=ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${o?"Buffered":"Sending"} HANDLE`)}status(t,e,n){if(!this.server)throw new Error("Server-only method called in client mode");if(!Fg.has(e))throw new Error(`Bad status code: ${e}`);n||(n="");let i=Buffer.byteLength(n),s=9,o=Buffer.allocUnsafe(17+i+4);H(o,o.length-4,0),o[4]=Yt.STATUS,H(o,t,5),H(o,e,s),H(o,i,s+=4),s+=4,i&&(o.utf8Write(n,s,i),s+=i),H(o,0,s);let a=ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STATUS`)}data(t,e,n){if(!this.server)throw new Error("Server-only method called in client mode");let i=Buffer.isBuffer(e);if(!i&&typeof e!="string")throw new Error("data is not a Buffer or string");let s;!i&&!n&&(n=void 0,s=!0);let o=i?e.length:Buffer.byteLength(e,n),a=9,c=Buffer.allocUnsafe(13+o);H(c,c.length-4,0),c[4]=Yt.DATA,H(c,t,5),H(c,o,a),o&&(i?c.set(e,a+=4):s?c.utf8Write(e,a+=4,o):c.write(e,a+=4,o,n));let f=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} DATA`)}name(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(!Array.isArray(e)){if(typeof e!="object"||e===null)throw new Error("names is not an object or array");e=[e]}let n=e.length,i=0,s,o=[];for(let l=0;l<n;++l){let u=e[l],h=!u||!u.filename||typeof u.filename!="string"?"":u.filename;i+=4+Buffer.byteLength(h);let g=!u||!u.longname||typeof u.longname!="string"?"":u.longname;if(i+=4+Buffer.byteLength(g),typeof u.attrs=="object"&&u.attrs!==null){if(s=Jr(u.attrs),i+=4+s.nb,s.nb){let b;s.nb===Be.length?b=new Uint8Array(Be):(b=new Uint8Array(s.nb),Ur(Be,b,0,s.nb,0)),s.bytes=b}o.push(s)}else i+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+i);H(c,c.length-4,0),c[4]=Yt.NAME,H(c,t,5),H(c,n,a),a+=4;for(let l=0;l<n;++l){let u=e[l];{let g=!u||!u.filename||typeof u.filename!="string"?"":u.filename,b=Buffer.byteLength(g);H(c,b,a),a+=4,b&&(c.utf8Write(g,a,b),a+=b)}{let g=!u||!u.longname||typeof u.longname!="string"?"":u.longname,b=Buffer.byteLength(g);H(c,b,a),a+=4,b&&(c.utf8Write(g,a,b),a+=b)}let h=o[l];h?(H(c,h.flags,a),a+=4,h.flags&&h.bytes&&(c.set(h.bytes,a),a+=h.nb)):(H(c,0,a),a+=4)}let f=ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} NAME`)}attrs(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(typeof e!="object"||e===null)throw new Error("attrs is not an object");e=Jr(e);let n=e.flags,i=e.nb,s=9,o=Buffer.allocUnsafe(13+i);H(o,o.length-4,0),o[4]=Yt.ATTRS,H(o,t,5),H(o,n,s),i&&(s+=4,i===Be.length?o.set(Be,s):Ur(Be,o,0,i,s),s+=i);let a=ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function Kg(r){try{return Buffer.allocUnsafe(r)}catch(t){return t}}function vu(r,t,e,n,i,s,o,a){let c=r._maxReadLen,f=Math.max(i-c,0);f&&(i=c);let l=t.length,u=9,h=s,g=Buffer.allocUnsafe(13+l+8+4);H(g,g.length-4,0),g[4]=ve.READ;let b=r._writeReqid=r._writeReqid+1&ct;H(g,b,5),H(g,l,u),g.set(t,u+=4),u+=l;for(let S=7;S>=0;--S)g[u+S]=h&255,h/=256;H(g,i,u+=8),typeof o!="function"&&(o=Cu);let _=a||{nb:0,position:s,off:n,origOff:n,len:void 0,overflow:void 0,cb:(S,N,O)=>{let P=_.len,W=_.overflow;if(S){if(o._wantEOFError||S.code!==Ze.EOF)return o(S)}else{if(O>P)return o(new Error("Received more data than requested"));if(O===P&&W){_.nb+=O,_.position+=O,_.off+=O,vu(r,t,e,_.off,W,_.position,o,_);return}}O=O||0,_.origOff===0&&e.length===_.nb?N=e:N=Cn(e,_.origOff,_.origOff+_.nb+O),o(void 0,_.nb+O,N,_.position)},buffer:void 0};_.len=i,_.overflow=f,_.buffer=Cn(e,n,n+i),r._requests[b]=_;let x=ze(r,g);r._debug&&r._debug(`SFTP: Outbound: ${x?"Buffered":"Sending"} READ`)}function bu(r,t,e,n,i,s){let o=64,a=32768,c,f,l;typeof i=="function"?s=i:typeof i=="object"&&i!==null&&(typeof i.concurrency=="number"&&i.concurrency>0&&!isNaN(i.concurrency)&&(o=i.concurrency),typeof i.chunkSize=="number"&&i.chunkSize>0&&!isNaN(i.chunkSize)&&(a=i.chunkSize),typeof i.fileSize=="number"&&i.fileSize>0&&!isNaN(i.fileSize)&&(l=i.fileSize),typeof i.step=="function"&&(c=i.step),(typeof i.mode=="string"||typeof i.mode=="number")&&(f=sa(i.mode)));let u,h=0,g=0,b=!1,_,x,S,N=a*o;function O(P){if(b)return;b=!0;let W=0,X;_||x?(X=()=>{--W===0&&s(P)},_&&(r===Dr||r.outgoing.state==="open")&&++W,x&&(t===Dr||t.outgoing.state==="open")&&++W,_&&(r===Dr||r.outgoing.state==="open")&&r.close(_,X),x&&(t===Dr||t.outgoing.state==="open")&&t.close(x,X)):s(P)}r.open(e,"r",(P,W)=>{if(P)return O(P);_=W,l===void 0?r.fstat(_,X):X(null,{size:l});function X(G,w){if(G){if(r!==Dr){r.stat(e,(I,D)=>{if(I)return O(G);X(null,D)});return}return O(G)}u=w.size,t.open(n,"w",(I,D)=>{if(I)return O(I);if(x=D,u<=0)return O();for(;N>u;){if(o===1){N=u;break}N-=a,--o}if(S=Kg(N),S instanceof Error)return O(S);f!==void 0?t.fchmod(x,f,function Z(re){if(re){t.chmod(n,f,ce=>Z());return}te()}):te();function q(Z,re,ce,U,C,k){if(Z)return O(Z);C=C||0,t.write(x,S,C,re,U,M);function M(Y){if(Y)return O(Y);if(g+=re,c&&c(g,re,u),re<k)return ae(C,U+re,k-re);if(g===u){t.close(x,ee=>{if(x=void 0,ee)return O(ee);r.close(_,Ye=>{if(_=void 0,Ye)return O(Ye);s()})});return}if(h>=u)return;let oe=h+a>u?u-h:a;ae(C,h,oe),h+=oe}}function Q(Z,re,ce){return(U,C,k)=>{q(U,C,k,re,Z,ce)}}function ae(Z,re,ce){r.read(_,S,Z,ce,re,Q(Z,re,ce))}function te(){let Z=0,re=0;for(;h<u&&Z<o;){let ce=h+a>u?u-h:a;ae(re,h,ce),re+=ce,h+=ce,++Z}}})}})}function ea(r,t,e,n,i,s,o){let a=typeof o=="function"?o:void 0;r.write(t,e,n,i,s,(c,f)=>{if(c)return r.close(t,()=>{a&&a(c)});f===i?r.close(t,a):(n+=f,i-=f,s+=f,ea(r,t,e,n,i,s,a))})}var ps=class{constructor(t){this.mode=t&&t.mode,this.uid=t&&t.uid,this.gid=t&&t.gid,this.size=t&&t.size,this.atime=t&&t.atime,this.mtime=t&&t.mtime,this.extended=t&&t.extended}isDirectory(){return(this.mode&Gt.S_IFMT)===Gt.S_IFDIR}isFile(){return(this.mode&Gt.S_IFMT)===Gt.S_IFREG}isBlockDevice(){return(this.mode&Gt.S_IFMT)===Gt.S_IFBLK}isCharacterDevice(){return(this.mode&Gt.S_IFMT)===Gt.S_IFCHR}isSymbolicLink(){return(this.mode&Gt.S_IFMT)===Gt.S_IFLNK}isFIFO(){return(this.mode&Gt.S_IFMT)===Gt.S_IFIFO}isSocket(){return(this.mode&Gt.S_IFMT)===Gt.S_IFSOCK}};function Jr(r){let t=0,e=0;if(typeof r=="object"&&r!==null){if(typeof r.size=="number"){t|=Ir.SIZE;let n=r.size;Be[e++]=n/72057594037927940,Be[e++]=n/281474976710656,Be[e++]=n/1099511627776,Be[e++]=n/4294967296,Be[e++]=n/16777216,Be[e++]=n/65536,Be[e++]=n/256,Be[e++]=n}if(typeof r.uid=="number"&&typeof r.gid=="number"){t|=Ir.UIDGID;let n=r.uid,i=r.gid;Be[e++]=n>>>24,Be[e++]=n>>>16,Be[e++]=n>>>8,Be[e++]=n,Be[e++]=i>>>24,Be[e++]=i>>>16,Be[e++]=i>>>8,Be[e++]=i}if(typeof r.mode=="number"||typeof r.mode=="string"){let n=sa(r.mode);t|=Ir.PERMISSIONS,Be[e++]=n>>>24,Be[e++]=n>>>16,Be[e++]=n>>>8,Be[e++]=n}if((typeof r.atime=="number"||Jo(r.atime))&&(typeof r.mtime=="number"||Jo(r.mtime))){let n=wn(r.atime),i=wn(r.mtime);t|=Ir.ACMODTIME,Be[e++]=n>>>24,Be[e++]=n>>>16,Be[e++]=n>>>8,Be[e++]=n,Be[e++]=i>>>24,Be[e++]=i>>>16,Be[e++]=i>>>8,Be[e++]=i}}return{flags:t,nb:e}}function wn(r){if(typeof r=="number"&&r===r)return r;if(Jo(r))return parseInt(r.getTime()/1e3,10);throw new Error(`Cannot parse time: ${r}`)}function sa(r){if(typeof r=="number"&&r===r)return r;if(typeof r=="string")return sa(parseInt(r,8));throw new Error(`Cannot parse mode: ${r}`)}var ta={r:Se.READ,"r+":Se.READ|Se.WRITE,w:Se.TRUNC|Se.CREAT|Se.WRITE,wx:Se.TRUNC|Se.CREAT|Se.WRITE|Se.EXCL,xw:Se.TRUNC|Se.CREAT|Se.WRITE|Se.EXCL,"w+":Se.TRUNC|Se.CREAT|Se.READ|Se.WRITE,"wx+":Se.TRUNC|Se.CREAT|Se.READ|Se.WRITE|Se.EXCL,"xw+":Se.TRUNC|Se.CREAT|Se.READ|Se.WRITE|Se.EXCL,a:Se.APPEND|Se.CREAT|Se.WRITE,ax:Se.APPEND|Se.CREAT|Se.WRITE|Se.EXCL,xa:Se.APPEND|Se.CREAT|Se.WRITE|Se.EXCL,"a+":Se.APPEND|Se.CREAT|Se.READ|Se.WRITE,"ax+":Se.APPEND|Se.CREAT|Se.READ|Se.WRITE|Se.EXCL,"xa+":Se.APPEND|Se.CREAT|Se.READ|Se.WRITE|Se.EXCL};function ku(r){let t=ta[r];return t!==void 0?t:null}var Vg=(()=>{let r=Object.keys(ta);return t=>{for(let e=0;e<r.length;++e){let n=r[e];if(ta[n]===t)return n}return null}})();function In(r){let t=T.readUInt32BE();if(t===void 0)return;let e=new ps;if(t&Ir.SIZE){let n=T.readUInt64BE(r);if(n===void 0)return;e.size=n}if(t&Ir.UIDGID){let n=T.readUInt32BE(),i=T.readUInt32BE();if(i===void 0)return;e.uid=n,e.gid=i}if(t&Ir.PERMISSIONS){let n=T.readUInt32BE();if(n===void 0)return;e.mode=n}if(t&Ir.ACMODTIME){let n=T.readUInt32BE(),i=T.readUInt32BE();if(i===void 0)return;e.atime=n,e.mtime=i}if(t&Ir.EXTENDED){let n=T.readUInt32BE();if(n===void 0)return;let i={};for(let s=0;s<n;++s){let o=T.readString(!0),a=T.readString();if(a===void 0)return;i[o]=a}e.extended=i}return e}function ze(r,t){let e=Bu(r,t);return e!==void 0?(r._buffer.push(e),!1):!0}function Bu(r,t){let e=r.outgoing;if(e.state!=="open")return;if(e.window===0)return r._waitWindow=!0,r._chunkcb=yu,t;let n,i=t.length,s=0;for(;i-s>0&&e.window>0;){let o=Math.min(i-s,e.window,e.packetSize);e.window-=o,e.window===0&&(r._waitWindow=!0,r._chunkcb=yu),s===0&&o===i?r._protocol.channelData(r.outgoing.id,t):r._protocol.channelData(r.outgoing.id,Cn(t,s,s+o)),s+=o}return i-s>0&&(s>0?n=Cn(t,s,i):n=t),n}function yu(){this._chunkcb=void 0;let r=this._buffer,t=0;for(;t<r.length;){let e=r[t],n=Bu(this,e);if(n!==void 0){n!==e&&(r[t]=n),t>0&&(this._buffer=r.slice(t));return}++t}t>0&&(this._buffer=[])}function nt(r,t,e){let n=new Error(t);return n.level="sftp-protocol",!e&&r._debug&&r._debug(`SFTP: Inbound: ${t}`),r.emit("error",n),r.destroy(),Ru(r),!1}function Ru(r){let t=Object.keys(r._requests);if(t.length===0)return;let e=r._requests;r._requests={};let n=new Error("No response from server");for(let i=0;i<t.length;++i){let s=e[t[i]];typeof s.cb=="function"&&s.cb(n)}}function Gg(r,t){let e=9,n=Buffer.allocUnsafe(31);H(n,n.length-4,0),n[4]=ve.EXTENDED;let i=r._writeReqid=r._writeReqid+1&ct;H(n,i,5),H(n,18,e),n.utf8Write("limits@openssh.com",e+=4,18),r._requests[i]={extended:"limits@openssh.com",cb:t};let s=ze(r,n);if(r._debug){let o=s?"Buffered":"Sending";r._debug(`SFTP: Outbound: ${o} limits@openssh.com`)}}var Yg={[Yt.VERSION]:(r,t)=>{if(r._version!==-1)return nt(r,"Duplicate VERSION packet");let e={};T.init(t,1);let n=T.readUInt32BE();for(;T.avail();){let i=T.readString(!0),s=T.readString(!0);if(s===void 0){n=void 0;break}e[i]=s}if(T.clear(),n===void 0)return nt(r,"Malformed VERSION packet");if(r._debug){let i=Object.keys(e);i.length?r._debug(`SFTP: Inbound: Received VERSION (v${n}, exts:${i})`):r._debug(`SFTP: Inbound: Received VERSION (v${n})`)}if(r._version=n,r._extensions=e,e["limits@openssh.com"]==="1")return Gg(r,(i,s)=>{i||(s.maxPktLen>0&&(r._maxOutPktLen=s.maxPktLen),s.maxReadLen>0&&(r._maxReadLen=s.maxReadLen),s.maxWriteLen>0&&(r._maxWriteLen=s.maxWriteLen),r.maxOpenHandles=s.maxOpenHandles>0?s.maxOpenHandles:1/0),r.emit("ready")});r.emit("ready")},[Yt.STATUS]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readUInt32BE(),i=T.readString(!0);if(T.clear(),r._debug){let o=JSON.stringify(i);r._debug(`SFTP: Inbound: Received STATUS (id:${e}, ${n}, ${o})`)}let s=r._requests[e];if(delete r._requests[e],s&&typeof s.cb=="function"){if(n===Ze.OK){s.cb();return}let o=new Error(i||$g[n]||"Unknown status");o.code=n,s.cb(o)}},[Yt.HANDLE]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString();if(T.clear(),n===void 0)return e!==void 0&&delete r._requests[e],nt(r,"Malformed HANDLE packet");r._debug&&r._debug(`SFTP: Inbound: Received HANDLE (id:${e})`);let i=r._requests[e];delete r._requests[e],i&&typeof i.cb=="function"&&i.cb(void 0,n)},[Yt.DATA]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n;if(e!==void 0&&(n=r._requests[e],delete r._requests[e]),n&&typeof n.cb=="function")if(n.buffer){let i=T.readString(n.buffer);if(T.clear(),i!==void 0){r._debug&&r._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i})`),n.cb(void 0,n.buffer,i);return}}else{let i=T.readString();if(T.clear(),i!==void 0){r._debug&&r._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i.length})`),n.cb(void 0,i);return}}else{let i=T.skipString();if(T.clear(),i!==void 0){r._debug&&r._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i})`);return}}return nt(r,"Malformed DATA packet")},[Yt.NAME]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n;e!==void 0&&(n=r._requests[e],delete r._requests[e]);let i=T.readUInt32BE();if(i!==void 0){let s=[];for(let o=0;o<i;++o){let a=T.readString(!0),c=T.readString(!0),f=In(r._biOpt);if(f===void 0){s=void 0;break}s.push({filename:a,longname:c,attrs:f})}if(s!==void 0){r._debug&&r._debug(`SFTP: Inbound: Received NAME (id:${e}, ${s.length})`),T.clear(),n&&typeof n.cb=="function"&&n.cb(void 0,s);return}}return T.clear(),nt(r,"Malformed NAME packet")},[Yt.ATTRS]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n;e!==void 0&&(n=r._requests[e],delete r._requests[e]);let i=In(r._biOpt);if(T.clear(),i!==void 0){r._debug&&r._debug(`SFTP: Inbound: Received ATTRS (id:${e})`),n&&typeof n.cb=="function"&&n.cb(void 0,i);return}return nt(r,"Malformed ATTRS packet")},[Yt.EXTENDED]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE();if(e!==void 0){let n=r._requests[e];if(n)switch(delete r._requests[e],n.extended){case"statvfs@openssh.com":case"fstatvfs@openssh.com":{let i=r._biOpt,s={f_bsize:T.readUInt64BE(i),f_frsize:T.readUInt64BE(i),f_blocks:T.readUInt64BE(i),f_bfree:T.readUInt64BE(i),f_bavail:T.readUInt64BE(i),f_files:T.readUInt64BE(i),f_ffree:T.readUInt64BE(i),f_favail:T.readUInt64BE(i),f_sid:T.readUInt64BE(i),f_flag:T.readUInt64BE(i),f_namemax:T.readUInt64BE(i)};if(s.f_namemax===void 0)break;r._debug&&r._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${n.extended})`),T.clear(),typeof n.cb=="function"&&n.cb(void 0,s);return}case"limits@openssh.com":{let i={maxPktLen:T.readUInt64BE(),maxReadLen:T.readUInt64BE(),maxWriteLen:T.readUInt64BE(),maxOpenHandles:T.readUInt64BE()};if(i.maxOpenHandles===void 0)break;r._debug&&r._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${n.extended})`),T.clear(),typeof n.cb=="function"&&n.cb(void 0,i);return}case"users-groups-by-id@openssh.com":{let i=T.readUInt32BE();if(i===void 0)break;let s=new Array(i);for(let c=0;c<s.length;++c)s[c]=T.readString(!0);let o=T.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=T.readString(!0);if(a.length>0&&a[a.length-1]===void 0)break;r._debug&&r._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${n.extended})`),T.clear(),typeof n.cb=="function"&&n.cb(void 0,s,a);return}default:r._debug&&r._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),T.clear(),typeof n.cb=="function"&&n.cb();return}else{r._debug&&r._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),T.clear();return}}return T.clear(),nt(r,"Malformed EXTENDED_REPLY packet")}},jg={[ve.INIT]:(r,t)=>{if(r._version!==-1)return nt(r,"Duplicate INIT packet");let e={};T.init(t,1);let n=T.readUInt32BE();for(;T.avail();){let i=T.readString(!0),s=T.readString(!0);if(s===void 0){n=void 0;break}e[i]=s}if(T.clear(),n===void 0)return nt(r,"Malformed INIT packet");if(r._debug){let i=Object.keys(e);i.length?r._debug(`SFTP: Inbound: Received INIT (v${n}, exts:${i})`):r._debug(`SFTP: Inbound: Received INIT (v${n})`)}ze(r,Qg),r._version=n,r._extensions=e,r.emit("ready")},[ve.OPEN]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0),i=T.readUInt32BE(),s=In(r._biOpt);if(T.clear(),s===void 0)return nt(r,"Malformed OPEN packet");r._debug&&r._debug(`SFTP: Inbound: Received OPEN (id:${e})`),r.emit("OPEN",e,n,i,s)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.CLOSE]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString();if(T.clear(),n===void 0||n.length>256)return nt(r,"Malformed CLOSE packet");r._debug&&r._debug(`SFTP: Inbound: Received CLOSE (id:${e})`),r.emit("CLOSE",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.READ]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(),i=T.readUInt64BE(r._biOpt),s=T.readUInt32BE();if(T.clear(),s===void 0||n.length>256)return nt(r,"Malformed READ packet");r._debug&&r._debug(`SFTP: Inbound: Received READ (id:${e})`),r.emit("READ",e,n,i,s)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.WRITE]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(),i=T.readUInt64BE(r._biOpt),s=T.readString();if(T.clear(),s===void 0||n.length>256)return nt(r,"Malformed WRITE packet");r._debug&&r._debug(`SFTP: Inbound: Received WRITE (id:${e})`),r.emit("WRITE",e,n,i,s)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.LSTAT]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0);if(T.clear(),n===void 0)return nt(r,"Malformed LSTAT packet");r._debug&&r._debug(`SFTP: Inbound: Received LSTAT (id:${e})`),r.emit("LSTAT",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.FSTAT]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString();if(T.clear(),n===void 0||n.length>256)return nt(r,"Malformed FSTAT packet");r._debug&&r._debug(`SFTP: Inbound: Received FSTAT (id:${e})`),r.emit("FSTAT",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.SETSTAT]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0),i=In(r._biOpt);if(T.clear(),i===void 0)return nt(r,"Malformed SETSTAT packet");r._debug&&r._debug(`SFTP: Inbound: Received SETSTAT (id:${e})`),r.emit("SETSTAT",e,n,i)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.FSETSTAT]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(),i=In(r._biOpt);if(T.clear(),i===void 0||n.length>256)return nt(r,"Malformed FSETSTAT packet");r._debug&&r._debug(`SFTP: Inbound: Received FSETSTAT (id:${e})`),r.emit("FSETSTAT",e,n,i)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.OPENDIR]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0);if(T.clear(),n===void 0)return nt(r,"Malformed OPENDIR packet");r._debug&&r._debug(`SFTP: Inbound: Received OPENDIR (id:${e})`),r.emit("OPENDIR",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.READDIR]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString();if(T.clear(),n===void 0||n.length>256)return nt(r,"Malformed READDIR packet");r._debug&&r._debug(`SFTP: Inbound: Received READDIR (id:${e})`),r.emit("READDIR",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.REMOVE]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0);if(T.clear(),n===void 0)return nt(r,"Malformed REMOVE packet");r._debug&&r._debug(`SFTP: Inbound: Received REMOVE (id:${e})`),r.emit("REMOVE",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.MKDIR]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0),i=In(r._biOpt);if(T.clear(),i===void 0)return nt(r,"Malformed MKDIR packet");r._debug&&r._debug(`SFTP: Inbound: Received MKDIR (id:${e})`),r.emit("MKDIR",e,n,i)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.RMDIR]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0);if(T.clear(),n===void 0)return nt(r,"Malformed RMDIR packet");r._debug&&r._debug(`SFTP: Inbound: Received RMDIR (id:${e})`),r.emit("RMDIR",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.REALPATH]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0);if(T.clear(),n===void 0)return nt(r,"Malformed REALPATH packet");r._debug&&r._debug(`SFTP: Inbound: Received REALPATH (id:${e})`),r.emit("REALPATH",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.STAT]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0);if(T.clear(),n===void 0)return nt(r,"Malformed STAT packet");r._debug&&r._debug(`SFTP: Inbound: Received STAT (id:${e})`),r.emit("STAT",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.RENAME]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0),i=T.readString(!0);if(T.clear(),i===void 0)return nt(r,"Malformed RENAME packet");r._debug&&r._debug(`SFTP: Inbound: Received RENAME (id:${e})`),r.emit("RENAME",e,n,i)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.READLINK]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0);if(T.clear(),n===void 0)return nt(r,"Malformed READLINK packet");r._debug&&r._debug(`SFTP: Inbound: Received READLINK (id:${e})`),r.emit("READLINK",e,n)||r.status(e,Ze.OP_UNSUPPORTED)},[ve.SYMLINK]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0),i=T.readString(!0);if(T.clear(),i===void 0)return nt(r,"Malformed SYMLINK packet");r._debug&&r._debug(`SFTP: Inbound: Received SYMLINK (id:${e})`);let s;r._isOpenSSH?s=r.emit("SYMLINK",e,i,n):s=r.emit("SYMLINK",e,n,i),s||r.status(e,Ze.OP_UNSUPPORTED)},[ve.EXTENDED]:(r,t)=>{T.init(t,1);let e=T.readUInt32BE(),n=T.readString(!0);if(n===void 0)return T.clear(),nt(r,"Malformed EXTENDED packet");let i;T.avail()&&(i=T.readRaw()),T.clear(),r._debug&&r._debug(`SFTP: Inbound: Received EXTENDED (id:${e})`),r.emit("EXTENDED",e,n,i)||r.status(e,Ze.OP_UNSUPPORTED)}},{ERR_INVALID_ARG_TYPE:zg,ERR_OUT_OF_RANGE:hs,validateNumber:Xg}=Eu(),xu=128,qt,ra=[];function Jg(r){ra.length>0?qt=ra.pop():qt=Buffer.allocUnsafe(r),qt.used=0}function na(r,t){if(!Number.isSafeInteger(r))throw Xg(r,t),Number.isInteger(r)?new hs(t,">= 0 and <= 2 ** 53 - 1",r):new hs(t,"an integer",r);if(r<0)throw new hs(t,">= 0 and <= 2 ** 53 - 1",r)}function Xo(r){return r+7&-8}function Cr(r,t,e){if(e===void 0)e={};else if(typeof e=="string")e={encoding:e};else{if(e===null||typeof e!="object")throw new TypeError('"options" argument must be a string or an object');e=Object.create(e)}if(e.highWaterMark===void 0&&(e.highWaterMark=64*1024),e.emitClose=!1,e.autoDestroy=!1,wu.call(this,e),this.path=t,this.flags=e.flags===void 0?"r":e.flags,this.mode=e.mode===void 0?438:e.mode,this.start=e.start,this.end=e.end,this.autoClose=e.autoClose===void 0?!0:e.autoClose,this.pos=0,this.bytesRead=0,this.isClosed=!1,this.handle=e.handle===void 0?null:e.handle,this.sftp=r,this._opening=!1,this.start!==void 0&&(na(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(na(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new hs("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}Iu(Cr,wu);Cr.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(r,t)=>{if(this._opening=!1,r){this.emit("error",r),this.autoClose&&this.destroy();return}this.handle=t,this.emit("open",t),this.emit("ready"),this.read()}))};Cr.prototype._read=function(r){if(!Buffer.isBuffer(this.handle))return this.once("open",()=>this._read(r));if(this.destroyed)return;(!qt||qt.length-qt.used<xu)&&Jg(this.readableHighWaterMark||this._readableState.highWaterMark);let t=qt,e=Math.min(qt.length-qt.used,r),n=qt.used;if(this.end!==void 0&&(e=Math.min(this.end-this.pos+1,e)),e<=0)return this.push(null);this.sftp.read(this.handle,qt,qt.used,e,this.pos,(i,s)=>{if(i){this.emit("error",i),this.autoClose&&this.destroy();return}let o=null;if(n+e===t.used&&t===qt)t.used=Xo(t.used+s-e);else{let a=n+e&-8,c=Xo(n+s);a-c>=xu&&ra.push(t.slice(c,a))}s>0&&(this.bytesRead+=s,o=t.slice(n,n+s)),this.pos+=s,this.push(o)}),qt.used=Xo(qt.used+e)};Cr.prototype._destroy=function(r,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",Su.bind(null,this,t,r));return}Su(this,t,r),this.handle=null,this._opening=!1};function Su(r,t,e){if(!r.handle)return n();r.sftp.close(r.handle,n);function n(i){i=i||e,t(i),r.isClosed=!0,i||r.emit("close")}}Cr.prototype.close=function(r){this.destroy(null,r)};Object.defineProperty(Cr.prototype,"pending",{get(){return this.handle===null},configurable:!0});function sr(r,t,e){if(e===void 0)e={};else if(typeof e=="string")e={encoding:e};else{if(e===null||typeof e!="object")throw new TypeError('"options" argument must be a string or an object');e=Object.create(e)}e.emitClose=!1,e.autoDestroy=!1,ia.call(this,e),this.path=t,this.flags=e.flags===void 0?"w":e.flags,this.mode=e.mode===void 0?438:e.mode,this.start=e.start,this.autoClose=e.autoClose===void 0?!0:e.autoClose,this.pos=0,this.bytesWritten=0,this.isClosed=!1,this.handle=e.handle===void 0?null:e.handle,this.sftp=r,this._opening=!1,this.start!==void 0&&(na(this.start,"start"),this.pos=this.start),e.encoding&&this.setDefaultEncoding(e.encoding),this.on("finish",function(){this._writableState.finalCalled||this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}Iu(sr,ia);sr.prototype._final=function(r){this.autoClose&&this.destroy(),r()};sr.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(r,t)=>{if(this._opening=!1,r){this.emit("error",r),this.autoClose&&this.destroy();return}this.handle=t;let e=n=>{if(n){this.sftp.chmod(this.path,this.mode,i=>e());return}if(this.flags[0]==="a"){let i=(s,o)=>{if(s){this.sftp.stat(this.path,(a,c)=>{if(a){this.destroy(),this.emit("error",s);return}i(null,c)});return}this.pos=o.size,this.emit("open",t),this.emit("ready")};this.sftp.fstat(t,i);return}this.emit("open",t),this.emit("ready")};this.sftp.fchmod(t,this.mode,e)}))};sr.prototype._write=function(r,t,e){if(!Buffer.isBuffer(r)){let n=new zg("data","Buffer",r);return this.emit("error",n)}if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._write(r,t,e)});this.sftp.write(this.handle,r,0,r.length,this.pos,(n,i)=>{if(n)return this.autoClose&&this.destroy(),e(n);this.bytesWritten+=i,e()}),this.pos+=r.length};sr.prototype._writev=function(r,t){if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._writev(r,t)});let e=this.sftp,n=this.handle,i=r.length,s=(o,a)=>{if(o)return this.destroy(),t(o);this.bytesWritten+=a,--i===0&&t()};for(let o=0;o<r.length;++o){let a=r[o].chunk;e.write(n,a,0,a.length,this.pos,s),this.pos+=a.length}};typeof ia.prototype.destroy!="function"&&(sr.prototype.destroy=Cr.prototype.destroy);sr.prototype._destroy=Cr.prototype._destroy;sr.prototype.close=function(r){if(r){if(this.isClosed){process.nextTick(r);return}this.on("close",r)}this.autoClose||this.on("finish",this.destroy.bind(this)),this.end()};sr.prototype.destroySoon=sr.prototype.end;Object.defineProperty(sr.prototype,"pending",{get(){return this.handle===null},configurable:!0});Nu.exports={flagsToString:Vg,OPEN_MODE:Se,SFTP:Zo,Stats:ps,STATUS_CODE:Ze,stringToFlags:ku}});var ua=ot((Ky,Uu)=>{"use strict";var{Duplex:Zg,Readable:e0,Writable:t0}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:Pu}}=xr(),{bufferSlice:gs}=or(),r0=32*1024,ui=2*1024*1024,fa=ui/2,oa=class extends e0{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=fa&&la(this._channel))}},aa=class extends t0{constructor(t){super({highWaterMark:ui}),this._channel=t}_write(t,e,n){let i=this._channel,s=i._client._protocol,o=i.outgoing,a=o.packetSize,c=o.id,f=o.window,l=t.length,u=0;if(o.state==="open"){for(;l-u>0&&f>0;){let h=l-u;h>f&&(h=f),h>a&&(h=a),u===0&&h===l?s.channelExtData(c,t,Pu):s.channelExtData(c,gs(t,u,u+h),Pu),u+=h,f-=h}if(o.window=f,l-u>0){f===0&&(i._waitWindow=!0),u>0?i._chunkErr=gs(t,u,l):i._chunkErr=t,i._chunkcbErr=n;return}n()}}},ca=class extends Zg{constructor(t,e,n){let i={highWaterMark:ui,allowHalfOpen:!n||n&&n.allowHalfOpen!==!1,emitClose:!1};super(i),this.allowHalfOpen=i.allowHalfOpen;let s=!!(n&&n.server);this.server=s,this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this._callbacks=[],this._client=t,this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this.stdin=this.stdout=this,s?this.stderr=new aa(this):this.stderr=new oa(this,i),this._waitWindow=!1,this._waitChanDrain=!1,this._chunk=void 0,this._chunkcb=void 0,this._chunkErr=void 0,this._chunkcbErr=void 0,this.on("finish",Tu).on("prefinish",Tu),this.on("end",Lu).on("close",Lu)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=fa&&la(this))}_write(t,e,n){let i=this._client._protocol,s=this.outgoing,o=s.packetSize,a=s.id,c=s.window,f=t.length,l=0;if(s.state==="open"){for(;f-l>0&&c>0;){let u=f-l;u>c&&(u=c),u>o&&(u=o),l===0&&u===f?i.channelData(a,t):i.channelData(a,gs(t,l,l+u)),l+=u,c-=u}if(s.window=c,f-l>0){c===0&&(this._waitWindow=!0),l>0?this._chunk=gs(t,l,f):this._chunk=t,this._chunkcb=n;return}n()}}eof(){this.outgoing.state==="open"&&(this.outgoing.state="eof",this._client._protocol.channelEOF(this.outgoing.id))}close(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._client._protocol.channelClose(this.outgoing.id))}destroy(){return this.end(),this.close(),this}setWindow(t,e,n,i){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&(this.subtype==="shell"||this.subtype==="exec")&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.windowChange(this.outgoing.id,t,e,n,i)}signal(t){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.signal(this.outgoing.id,t)}exit(t,e,n){if(!this.server)throw new Error("Server-only method called in client mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&(typeof t=="number"?this._client._protocol.exitStatus(this.outgoing.id,t):this._client._protocol.exitSignal(this.outgoing.id,t,e,n))}};function Tu(){this.eof(),(this.server||!this.allowHalfOpen)&&this.close(),this.writable=!1}function Lu(){this.readable=!1}function la(r){if(r.outgoing.state==="closed")return;let t=ui-r.incoming.window;t<=0||(r.incoming.window+=t,r._client._protocol.channelWindowAdjust(r.outgoing.id,t))}Uu.exports={Channel:ca,MAX_WINDOW:ui,PACKET_SIZE:r0,windowAdjust:la,WINDOW_THRESHOLD:fa}});var pa=ot((Vy,Mu)=>{"use strict";var{SFTP:n0}=li(),di=2**32-1;function Du(r,t,e,n){if(r._chanMgr.remove(t),typeof n!="function")return;let i;e instanceof Error?i=e:typeof e=="object"&&e!==null?(i=new Error(`(SSH) Channel open failure: ${e.description}`),i.reason=e.reason):(i=new Error("(SSH) Channel open failure: server closed channel unexpectedly"),i.reason=""),n(i)}function Ou(r,t,e,n,i){if(typeof e=="function"){Du(r,t,n,e);return}if(typeof e!="object"||e===null||e.incoming&&e.incoming.state==="closed"||(r._chanMgr.remove(t),e.server&&e.constructor.name==="Session"))return;e.incoming.state="closed",e.readable&&e.push(null),e.server?e.stderr.writable&&e.stderr.end():e.stderr.readable&&e.stderr.push(null),e.constructor!==n0&&(e.outgoing.state==="open"||e.outgoing.state==="eof")&&!i&&e.close(),e.outgoing.state==="closing"&&(e.outgoing.state="closed");let s=e._readableState,o=e._writableState;o&&!o.ending&&!o.finished&&!i&&e.end();let a=e._callbacks;e._callbacks=[];for(let c=0;c<a.length;++c)a[c](!0);if(e.server)!e.readable||e.destroyed||s&&s.endEmitted?e.emit("close"):e.once("end",()=>e.emit("close"));else{let c;switch(e.type){case"direct-streamlocal@openssh.com":case"direct-tcpip":c=()=>e.emit("close");break;default:{let l=e._exit;c=()=>{l.code===null?e.emit("close",l.code,l.signal,l.dump,l.desc):e.emit("close",l.code)}}}!e.readable||e.destroyed||s&&s.endEmitted?c():e.once("end",c);let f=e.stderr._readableState;!e.stderr.readable||e.stderr.destroyed||f&&f.endEmitted?e.stderr.emit("close"):e.stderr.once("end",()=>e.stderr.emit("close"))}}var ha=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<di)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let n=this._channels;for(let i=0;i<di;++i)if(n[i]===void 0){e=i;break}}return e===void 0?-1:(this._channels[e]=t||!0,++this._count,e)}update(t,e){if(typeof t!="number"||t<0||t>=di||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);e&&this._channels[t]&&(this._channels[t]=e)}get(t){if(typeof t!="number"||t<0||t>=di||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=di||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);this._channels[t]&&(delete this._channels[t],this._count&&--this._count)}cleanup(t){let e=this._channels;this._channels={},this._cur=-1,this._count=0;let n=Object.keys(e),i=this._client;for(let s=0;s<n.length;++s){let o=+n[s],a=e[o];Ou(i,o,a._channel||a,t,!0)}}},da=(()=>{let r=Object.prototype.toString;return t=>r.call(t)==="[object RegExp]"})();function i0(r,t,e){if(Array.isArray(r)&&r.length>0){for(let n=0;n<r.length;++n)if(e.indexOf(r[n])===-1)throw new Error(`Unsupported algorithm: ${r[n]}`);return r}if(typeof r=="object"&&r!==null){let n=Object.keys(r),i=t;for(let s=0;s<n.length;++s){let o=n[s],a=r[o];switch(o){case"append":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let f=a[c];if(typeof f=="string"){if(!f||i.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);i===t&&(i=i.slice()),i.push(f)}else if(da(f))for(let l=0;l<e.length;++l){let u=e[l];if(f.test(u)){if(i.indexOf(u)!==-1)continue;i===t&&(i=i.slice()),i.push(u)}}}break;case"prepend":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=a.length;c>=0;--c){let f=a[c];if(typeof f=="string"){if(!f||i.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);i===t&&(i=i.slice()),i.unshift(f)}else if(da(f))for(let l=e.length;l>=0;--l){let u=e[l];if(f.test(u)){if(i.indexOf(u)!==-1)continue;i===t&&(i=i.slice()),i.unshift(u)}}}break;case"remove":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let f=a[c];if(typeof f=="string"){if(!f)continue;let l=i.indexOf(f);if(l===-1)continue;i===t&&(i=i.slice()),i.splice(l,1)}else if(da(f))for(let l=0;l<i.length;++l)f.test(i[l])&&(i===t&&(i=i.slice()),i.splice(l,1),--l)}break}}return i}return t}Mu.exports={ChannelManager:ha,generateAlgorithmList:i0,onChannelOpenFailure:Du,onCHANNEL_CLOSE:Ou,isWritable:r=>r&&r.writable&&r._readableState&&r._readableState.ended===!1}});var ya=ot((Gy,id)=>{"use strict";var{createHash:s0,getHashes:o0,randomFillSync:a0}=require("crypto"),{Socket:c0}=require("net"),{lookup:f0}=require("dns"),l0=require("events"),u0=o0(),{COMPAT:td,CHANNEL_EXTENDED_DATATYPE:{STDERR:d0},CHANNEL_OPEN_FAILURE:hi,DEFAULT_CIPHER:Fu,DEFAULT_COMPRESSION:$u,DEFAULT_KEX:Hu,DEFAULT_MAC:Qu,DEFAULT_SERVER_HOST_KEY:Wu,DISCONNECT_REASON:qu,DISCONNECT_REASON_BY_VALUE:h0,SUPPORTED_CIPHER:p0,SUPPORTED_COMPRESSION:g0,SUPPORTED_KEX:m0,SUPPORTED_MAC:A0,SUPPORTED_SERVER_HOST_KEY:E0}=xr(),{init:_0}=Nr(),b0=jo(),{parseKey:Es}=Lr(),{SFTP:y0}=li(),{bufferCopy:Ku,makeBufferParser:rd,makeError:x0,readUInt32BE:S0,sigSSHToASN1:w0,writeUInt32BE:ga}=or(),{AgentContext:Vu,createAgent:Gu,isAgent:Yu}=Lo(),{Channel:nd,MAX_WINDOW:_s,PACKET_SIZE:bs,windowAdjust:ju,WINDOW_THRESHOLD:zu}=ua(),{ChannelManager:I0,generateAlgorithmList:pi,isWritable:Ct,onChannelOpenFailure:C0,onCHANNEL_CLOSE:v0}=pa(),ms=rd(),As=rd(),gi=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,_a=r=>{},ba=class extends l0{constructor(){super(),this.config={host:void 0,port:void 0,localAddress:void 0,localPort:void 0,forceIPv4:void 0,forceIPv6:void 0,keepaliveCountMax:void 0,keepaliveInterval:void 0,readyTimeout:void 0,ident:void 0,username:void 0,password:void 0,privateKey:void 0,tryKeyboard:void 0,agent:void 0,allowAgentFwd:void 0,authHandler:void 0,hostHashAlgo:void 0,hostHashCb:void 0,strictVendor:void 0,debug:void 0},this._agent=void 0,this._readyTimeout=void 0,this._chanMgr=void 0,this._callbacks=void 0,this._forwarding=void 0,this._forwardingUnix=void 0,this._acceptX11=void 0,this._agentFwdEnabled=void 0,this._remoteVer=void 0,this._protocol=void 0,this._sock=void 0,this._resetKA=void 0}connect(t){if(this._sock&&Ct(this._sock))return this.once("close",()=>{this.connect(t)}),this.end(),this;this.config.host=t.hostname||t.host||"localhost",this.config.port=t.port||22,this.config.localAddress=typeof t.localAddress=="string"?t.localAddress:void 0,this.config.localPort=typeof t.localPort=="string"||typeof t.localPort=="number"?t.localPort:void 0,this.config.forceIPv4=t.forceIPv4||!1,this.config.forceIPv6=t.forceIPv6||!1,this.config.keepaliveCountMax=typeof t.keepaliveCountMax=="number"&&t.keepaliveCountMax>=0?t.keepaliveCountMax:3,this.config.keepaliveInterval=typeof t.keepaliveInterval=="number"&&t.keepaliveInterval>0?t.keepaliveInterval:0,this.config.readyTimeout=typeof t.readyTimeout=="number"&&t.readyTimeout>=0?t.readyTimeout:2e4,this.config.ident=typeof t.ident=="string"||Buffer.isBuffer(t.ident)?t.ident:void 0;let e={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:[]},sc:void 0},n=!0;if(typeof t.algorithms=="object"&&t.algorithms!==null&&(e.kex=pi(t.algorithms.kex,Hu,m0),e.kex!==Hu&&(n=!1),e.serverHostKey=pi(t.algorithms.serverHostKey,Wu,E0),e.serverHostKey!==Wu&&(n=!1),e.cs.cipher=pi(t.algorithms.cipher,Fu,p0),e.cs.cipher!==Fu&&(n=!1),e.cs.mac=pi(t.algorithms.hmac,Qu,A0),e.cs.mac!==Qu&&(n=!1),e.cs.compress=pi(t.algorithms.compress,$u,g0),e.cs.compress!==$u&&(n=!1),n||(e.sc=e.cs)),typeof t.username=="string")this.config.username=t.username;else if(typeof t.user=="string")this.config.username=t.user;else throw new Error("Invalid username");this.config.password=typeof t.password=="string"?t.password:void 0,this.config.privateKey=typeof t.privateKey=="string"||Buffer.isBuffer(t.privateKey)?t.privateKey:void 0,this.config.localHostname=typeof t.localHostname=="string"?t.localHostname:void 0,this.config.localUsername=typeof t.localUsername=="string"?t.localUsername:void 0,this.config.tryKeyboard=t.tryKeyboard===!0,typeof t.agent=="string"&&t.agent.length?this.config.agent=Gu(t.agent):Yu(t.agent)?this.config.agent=t.agent:this.config.agent=void 0,this.config.allowAgentFwd=t.agentForward===!0&&this.config.agent!==void 0;let i=this.config.authHandler=typeof t.authHandler=="function"||Array.isArray(t.authHandler)?t.authHandler:void 0;this.config.strictVendor=typeof t.strictVendor=="boolean"?t.strictVendor:!0;let s=this.config.debug=typeof t.debug=="function"?t.debug:void 0;if(t.agentForward===!0&&!this.config.allowAgentFwd)throw new Error("You must set a valid agent path to allow agent forwarding");let o=this._callbacks=[];this._chanMgr=new I0(this),this._forwarding={},this._forwardingUnix={},this._acceptX11=0,this._agentFwdEnabled=!1,this._agent=this.config.agent?this.config.agent:void 0,this._remoteVer=void 0;let a;if(this.config.privateKey){if(a=Es(this.config.privateKey,t.passphrase),a instanceof Error)throw new Error(`Cannot parse privateKey: ${a.message}`);if(Array.isArray(a)&&(a=a[0]),a.getPrivatePEM()===null)throw new Error("privateKey value does not contain a (valid) private key")}let c;if(typeof t.hostVerifier=="function"){let U=t.hostVerifier,C;u0.indexOf(t.hostHash)!==-1&&(C=t.hostHash),c=(k,M)=>{C&&(k=s0(C).update(k).digest("hex"));let Y=U(k,M);Y!==void 0&&M(Y)}}let f=this._sock=t.sock||new c0,l=!1,u=!1;this._protocol&&this._protocol.cleanup();let h=s?(U,C,k)=>{s(`Debug output from server: ${JSON.stringify(k)}`)}:void 0,g,b=this._protocol=new b0({ident:this.config.ident,offer:n?void 0:e,onWrite:U=>{Ct(f)&&f.write(U)},onError:U=>{U.level==="handshake"&&clearTimeout(this._readyTimeout),b._destruct||f.removeAllListeners("data"),this.emit("error",U);try{f.end()}catch{}},onHeader:U=>{u=!0,this._remoteVer=U.versions.software,U.greeting&&this.emit("greeting",U.greeting)},onHandshakeComplete:U=>{this.emit("handshake",U),l||(l=!0,b.service("ssh-userauth"))},debug:s,hostVerifier:c,messageHandlers:{DEBUG:h,DISCONNECT:(U,C,k)=>{if(C!==qu.BY_APPLICATION){k||(k=h0[C],k===void 0&&(k=`Unexpected disconnection reason: ${C}`));let M=new Error(k);M.code=C,this.emit("error",M)}f.end()},SERVICE_ACCEPT:(U,C)=>{C==="ssh-userauth"&&Z()},EXT_INFO:(U,C)=>{if(g===void 0){for(let k of C)if(k.name==="server-sig-algs"){g=k.algs;return}g=null}},USERAUTH_BANNER:(U,C)=>{this.emit("banner",C)},USERAUTH_SUCCESS:U=>{P(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:(U,C,k)=>{if(w.keyAlgos){let M=w.keyAlgos[0][0];if(s&&s(`Client: ${w.type} (${M}) auth failed`),w.keyAlgos.shift(),w.keyAlgos.length){let[Y,oe]=w.keyAlgos[0];switch(w.type){case"agent":b.authPK(w.username,w.agentCtx.currentKey(),Y);return;case"publickey":b.authPK(w.username,w.key,Y);return;case"hostbased":b.authHostbased(w.username,w.key,w.localHostname,w.localUsername,Y,(ee,Ye)=>{let gt=w.key.sign(ee,oe);if(gt instanceof Error)return gt.message=`Error while signing with key: ${gt.message}`,gt.level="client-authentication",this.emit("error",gt),Z();Ye(gt)});return}}else w.keyAlgos=void 0}if(w.type==="agent"){let M=w.agentCtx.pos();return s&&s(`Client: Agent key #${M+1} failed`),re()}s&&s(`Client: ${w.type} auth failed`),I=k,D=C,Z()},USERAUTH_PASSWD_CHANGEREQ:(U,C)=>{w.type==="password"&&this.emit("change password",C,k=>{b.authPassword(this.config.username,this.config.password,k)})},USERAUTH_PK_OK:U=>{let C,k;if(w.keyAlgos&&([C,k]=w.keyAlgos[0]),w.type==="agent"){let M=w.agentCtx.currentKey();b.authPK(w.username,M,C,(Y,oe)=>{let ee={hash:k};w.agentCtx.sign(M,Y,ee,(Ye,gt)=>{if(Ye)Ye.level="agent",this.emit("error",Ye);else return oe(gt);re()})})}else w.type==="publickey"&&b.authPK(w.username,w.key,C,(M,Y)=>{let oe=w.key.sign(M,k);if(oe instanceof Error)return oe.message=`Error signing data with key: ${oe.message}`,oe.level="client-authentication",this.emit("error",oe),Z();Y(oe)})},USERAUTH_INFO_REQUEST:(U,C,k,M)=>{if(w.type==="keyboard-interactive"){if((Array.isArray(M)?M.length:0)===0){s&&s("Client: Sending automatic USERAUTH_INFO_RESPONSE"),b.authInfoRes();return}w.prompt(C,k,"",M,oe=>{b.authInfoRes(oe)})}},REQUEST_SUCCESS:(U,C)=>{o.length&&o.shift()(!1,C)},REQUEST_FAILURE:U=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:(U,C,k,M)=>{C==="hostkeys-00@openssh.com"?(P0(this,M,(Y,oe)=>{Y||this.emit("hostkeys",oe)}),k&&b.requestSuccess()):k&&b.requestFailure()},CHANNEL_OPEN:(U,C)=>{R0(this,C)},CHANNEL_OPEN_CONFIRMATION:(U,C)=>{let k=this._chanMgr.get(C.recipient);if(typeof k!="function")return;let M=k.type==="sftp",oe={type:M?"session":k.type,incoming:{id:C.recipient,window:_s,packetSize:bs,state:"open"},outgoing:{id:C.sender,window:C.window,packetSize:C.packetSize,state:"open"}},ee=M?new y0(this,oe,{debug:s}):new nd(this,oe);this._chanMgr.update(C.recipient,ee),k(void 0,ee)},CHANNEL_OPEN_FAILURE:(U,C,k,M)=>{let Y=this._chanMgr.get(C);if(typeof Y!="function")return;C0(this,C,{reason:k,description:M},Y)},CHANNEL_DATA:(U,C,k)=>{let M=this._chanMgr.get(C);if(!(typeof M!="object"||M===null)&&M.incoming.window!==0){if(M.incoming.window-=k.length,M.push(k)===!1){M._waitChanDrain=!0;return}M.incoming.window<=zu&&ju(M)}},CHANNEL_EXTENDED_DATA:(U,C,k,M)=>{if(M!==d0)return;let Y=this._chanMgr.get(C);if(!(typeof Y!="object"||Y===null)&&Y.incoming.window!==0){if(Y.incoming.window-=k.length,!Y.stderr.push(k)){Y._waitChanDrain=!0;return}Y.incoming.window<=zu&&ju(Y)}},CHANNEL_WINDOW_ADJUST:(U,C,k)=>{let M=this._chanMgr.get(C);typeof M!="object"||M===null||(M.outgoing.window+=k,M._waitWindow&&(M._waitWindow=!1,M._chunk?M._write(M._chunk,null,M._chunkcb):M._chunkcb?M._chunkcb():M._chunkErr?M.stderr._write(M._chunkErr,null,M._chunkcbErr):M._chunkcbErr&&M._chunkcbErr()))},CHANNEL_SUCCESS:(U,C)=>{let k=this._chanMgr.get(C);typeof k!="object"||k===null||(this._resetKA(),k._callbacks.length&&k._callbacks.shift()(!1))},CHANNEL_FAILURE:(U,C)=>{let k=this._chanMgr.get(C);typeof k!="object"||k===null||(this._resetKA(),k._callbacks.length&&k._callbacks.shift()(!0))},CHANNEL_REQUEST:(U,C,k,M,Y)=>{let oe=this._chanMgr.get(C);if(typeof oe!="object"||oe===null)return;let ee=oe._exit;if(ee.code===void 0){switch(k){case"exit-status":oe.emit("exit",ee.code=Y);return;case"exit-signal":oe.emit("exit",ee.code=null,ee.signal=`SIG${Y.signal}`,ee.dump=Y.coreDumped,ee.desc=Y.errorMessage);return}M&&U.channelFailure(oe.outgoing.id)}},CHANNEL_EOF:(U,C)=>{let k=this._chanMgr.get(C);typeof k!="object"||k===null||k.incoming.state==="open"&&(k.incoming.state="eof",k.readable&&k.push(null),k.stderr.readable&&k.stderr.push(null))},CHANNEL_CLOSE:(U,C)=>{v0(this,C,this._chanMgr.get(C))}}});f.pause();let _=this.config.keepaliveInterval,x=this.config.keepaliveCountMax,S=0,N,O=()=>{if(++S>x){if(clearInterval(N),f.readable){let U=new Error("Keepalive timeout");U.level="client-timeout",this.emit("error",U),f.destroy()}return}Ct(f)?(o.push(P),b.ping()):clearInterval(N)};function P(){_>0&&(S=0,clearInterval(N),Ct(f)&&(N=setInterval(O,_)))}this._resetKA=P;let W=(()=>{let U=!1;return()=>{if(!U&&(U=!0,G&&!u)){let C=x0("Connection lost before handshake","protocol",!0);this.emit("error",C)}}})(),X=(()=>{let U=!1;return()=>{U||(U=!0,G=!0,s&&s("Socket connected"),this.emit("connect"),_0.then(()=>{b.start(),f.on("data",C=>{try{b.parse(C,0,C.length)}catch(k){this.emit("error",k);try{Ct(f)&&f.end()}catch{}}}),f.stderr&&typeof f.stderr.resume=="function"&&f.stderr.resume(),f.resume()}).catch(C=>{this.emit("error",C);try{Ct(f)&&f.end()}catch{}}))}})(),G=!1;f.on("connect",X).on("timeout",()=>{this.emit("timeout")}).on("error",U=>{s&&s(`Socket error: ${U.message}`),clearTimeout(this._readyTimeout),U.level="client-socket",this.emit("error",U)}).on("end",()=>{s&&s("Socket ended"),W(),b.cleanup(),clearTimeout(this._readyTimeout),clearInterval(N),this.emit("end")}).on("close",()=>{s&&s("Socket closed"),W(),b.cleanup(),clearTimeout(this._readyTimeout),clearInterval(N),this.emit("close");let U=o;o=this._callbacks=[];let C=new Error("No response from server");for(let k=0;k<U.length;++k)U[k](C);this._chanMgr.cleanup(C)});let w,I=null,D=null,q=["none"];this.config.password!==void 0&&q.push("password"),a!==void 0&&q.push("publickey"),this._agent!==void 0&&q.push("agent"),this.config.tryKeyboard&&q.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&q.push("hostbased"),Array.isArray(i)?i=ed(i):typeof i!="function"&&(i=ed(q));let Q=!1,ae=U=>{if(!Q){if(Q=!0,U===!1){let C=new Error("All configured authentication methods failed");C.level="client-authentication",this.emit("error",C),this.end();return}if(typeof U=="string"){let C=U;if(q.indexOf(C)===-1)return te(`Authentication method not allowed: ${C}`);let k=this.config.username;switch(C){case"password":U={type:C,username:k,password:this.config.password};break;case"publickey":U={type:C,username:k,key:a};break;case"hostbased":U={type:C,username:k,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":U={type:C,username:k,agentCtx:new Vu(this._agent)};break;case"keyboard-interactive":U={type:C,username:k,prompt:(...M)=>this.emit("keyboard-interactive",...M)};break;case"none":U={type:C,username:k};break;default:return te(`Skipping unsupported authentication method: ${U}`)}}else{if(typeof U!="object"||U===null)return te(`Skipping invalid authentication attempt: ${U}`);{let C=U.username;if(typeof C!="string")return te(`Skipping invalid authentication attempt: ${U}`);let k=U.type;switch(k){case"password":{let{password:M}=U;if(typeof M!="string"&&!Buffer.isBuffer(M))return te("Skipping invalid password auth attempt");U={type:k,username:C,password:M};break}case"publickey":{let M=Es(U.key,U.passphrase);if(M instanceof Error)return te("Skipping invalid key auth attempt");if(!M.isPrivateKey())return te("Skipping non-private key");U={type:k,username:C,key:M};break}case"hostbased":{let{localHostname:M,localUsername:Y}=U,oe=Es(U.key,U.passphrase);if(oe instanceof Error||typeof M!="string"||typeof Y!="string")return te("Skipping invalid hostbased auth attempt");if(!oe.isPrivateKey())return te("Skipping non-private key");U={type:k,username:C,key:oe,localHostname:M,localUsername:Y};break}case"agent":{let M=U.agent;if(typeof M=="string"&&M.length)M=Gu(M);else if(!Yu(M))return te(`Skipping invalid agent: ${U.agent}`);U={type:k,username:C,agentCtx:new Vu(M)};break}case"keyboard-interactive":{let{prompt:M}=U;if(typeof M!="function")return te("Skipping invalid keyboard-interactive auth attempt");U={type:k,username:C,prompt:M};break}case"none":U={type:k,username:C};break;default:return te(`Skipping unsupported authentication method: ${U}`)}}}w=U;try{let C=w.username;switch(w.type){case"password":b.authPassword(C,w.password);break;case"publickey":{let k;if(w.keyAlgos=Ea(this,w.key,g),w.keyAlgos)if(w.keyAlgos.length)k=w.keyAlgos[0][0];else return te("Skipping key authentication (no mutual hash algorithm)");b.authPK(C,w.key,k);break}case"hostbased":{let k,M;if(w.keyAlgos=Ea(this,w.key,g),w.keyAlgos)if(w.keyAlgos.length)[k,M]=w.keyAlgos[0];else return te("Skipping hostbased authentication (no mutual hash algorithm)");b.authHostbased(C,w.key,w.localHostname,w.localUsername,k,(Y,oe)=>{let ee=w.key.sign(Y,M);if(ee instanceof Error)return ee.message=`Error while signing with key: ${ee.message}`,ee.level="client-authentication",this.emit("error",ee),Z();oe(ee)});break}case"agent":w.agentCtx.init(k=>{if(k)return k.level="agent",this.emit("error",k),Z();re()});break;case"keyboard-interactive":b.authKeyboard(C);break;case"none":b.authNone(C);break}}finally{Q=!1}}};function te(U){s&&s(U),process.nextTick(Z)}function Z(){Q=!1;let U=i(D,I,ae);Q||U===void 0||ae(U)}let re=()=>{if(w.type==="agent"){let U=w.agentCtx.nextKey();if(U===!1)s&&s("Agent: No more keys left to try"),s&&s("Client: agent auth failed"),Z();else{let C=w.agentCtx.pos(),k;if(w.keyAlgos=Ea(this,U,g),w.keyAlgos)if(w.keyAlgos.length)k=w.keyAlgos[0][0];else{s&&s(`Agent: Skipping key #${C+1} (no mutual hash algorithm)`),re();return}s&&s(`Agent: Trying key #${C+1}`),b.authPK(w.username,U,k)}}},ce=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let U=new Error("Timed out while waiting for handshake");U.level="client-timeout",this.emit("error",U),f.destroy()},this.config.readyTimeout))};if(t.sock)ce(),typeof f.connecting=="boolean"&&f.connecting||X();else{let U=this.config.host,C=this.config.forceIPv4,k=this.config.forceIPv6;s&&s(`Client: Trying ${U} on port ${this.config.port} ...`);let M=()=>{ce(),f.connect({host:U,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),f.setMaxListeners(0),f.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!C&&!k||C&&k?M():f0(U,C?4:6,(Y,oe,ee)=>{if(Y){let Ye=C?"IPv4":"IPv6",gt=new Error(`Error while looking up ${Ye} address for '${U}': ${Y}`);clearTimeout(this._readyTimeout),gt.level="client-dns",this.emit("error",gt),this.emit("close");return}U=oe,M()})}return this}end(){return this._sock&&Ct(this._sock)&&(this._protocol.disconnect(qu.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&Ct(this._sock)&&this._sock.destroy(),this}exec(t,e,n){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");typeof e=="function"&&(n=e,e={});let i={allowHalfOpen:e.allowHalfOpen!==!1};return vn(this,"session",i,(s,o)=>{if(s){n(s);return}let a=[];function c(f){if(f){o.close(),n(f);return}a.length&&a.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&a.push(()=>Zu(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&ma(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>Ju(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>Xu(o,e.x11,c))),a.push(()=>B0(o,t,e,n)),a.shift()()}),this}shell(t,e,n){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");return typeof t=="function"?(n=t,t=e=void 0):typeof e=="function"&&(n=e,e=void 0),t&&(t.x11!==void 0||t.env!==void 0)&&(e=t,t=void 0),vn(this,"session",(i,s)=>{if(i){n(i);return}let o=[];function a(c){if(c){s.close(),n(c);return}o.length&&o.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&o.push(()=>Zu(s,a)),t!==!1&&o.push(()=>Ju(s,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&ma(s,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>Xu(s,e.x11,a))),o.push(()=>k0(s,n)),o.shift()()}),this}subsys(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");return vn(this,"session",(n,i)=>{if(n){e(n);return}Aa(i,t,(s,o)=>{if(s){e(s);return}e(void 0,o)})}),this}forwardIn(t,e,n){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let i=typeof n=="function";return i&&this._callbacks.push((s,o)=>{if(s){n(s!==!0?s:new Error(`Unable to bind to ${t}:${e}`));return}let a=e;e===0&&o&&o.length>=4&&(a=S0(o,0),this._protocol._compatFlags&td.DYN_RPORT_BUG||(e=a)),this._forwarding[`${t}:${e}`]=a,n(void 0,a)}),this._protocol.tcpipForward(t,e,i),this}unforwardIn(t,e,n){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let i=typeof n=="function";return i&&this._callbacks.push(s=>{if(s){n(s!==!0?s:new Error(`Unable to unbind from ${t}:${e}`));return}delete this._forwarding[`${t}:${e}`],n()}),this._protocol.cancelTcpipForward(t,e,i),this}forwardOut(t,e,n,i,s){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:n,dstPort:i};return typeof s!="function"&&(s=_a),vn(this,"direct-tcpip",o,s),this}openssh_noMoreSessions(t){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let e=typeof t=="function";return!this.config.strictVendor||this.config.strictVendor&&gi.test(this._remoteVer)?(e&&this._callbacks.push(n=>{if(n){t(n!==!0?n:new Error("Unable to disable future sessions"));return}t()}),this._protocol.openssh_noMoreSessions(e),this):e?(process.nextTick(t,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardInStreamLocal(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let n=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&gi.test(this._remoteVer)?(n&&this._callbacks.push(i=>{if(i){e(i!==!0?i:new Error(`Unable to bind to ${t}`));return}this._forwardingUnix[t]=!0,e()}),this._protocol.openssh_streamLocalForward(t,n),this):n?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_unforwardInStreamLocal(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");let n=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&gi.test(this._remoteVer)?(n&&this._callbacks.push(i=>{if(i){e(i!==!0?i:new Error(`Unable to unbind from ${t}`));return}delete this._forwardingUnix[t],e()}),this._protocol.openssh_cancelStreamLocalForward(t,n),this):n?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardOutStreamLocal(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=_a),!this.config.strictVendor||this.config.strictVendor&&gi.test(this._remoteVer)?(vn(this,"direct-streamlocal@openssh.com",{socketPath:t},e),this):(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this)}sftp(t,e){if(!this._sock||!Ct(this._sock))throw new Error("Not connected");return typeof t=="function"&&(e=t,t=void 0),vn(this,"sftp",(n,i)=>{if(n){e(n);return}let s=(o,a)=>{if(o){e(o);return}function c(){i.removeListener("ready",f),i.removeListener("error",l),i.removeListener("exit",u),i.removeListener("close",u)}function f(){c(),e(void 0,i)}function l(h){c(),e(h)}function u(h,g){c();let b;typeof h=="number"?b=`Received exit code ${h} while establishing SFTP session`:g!==void 0?b=`Received signal ${g} while establishing SFTP session`:b="Received unexpected SFTP session termination";let _=new Error(b);_.code=h,_.signal=g,e(_)}i.on("ready",f).on("error",l).on("exit",u).on("close",u),i._init()};typeof t=="object"&&t!==null?ma(i,t,o=>{if(o){e(o);return}Aa(i,"sftp",s)}):Aa(i,"sftp",s)}),this}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function vn(r,t,e,n){let i=_s,s=bs;typeof e=="function"&&(n=e,e={});let o=(c,f)=>{n(c,f)};o.type=t;let a=r._chanMgr.add(o);if(a===-1){n(new Error("No free channels available"));return}switch(t){case"session":case"sftp":r._protocol.session(a,i,s);break;case"direct-tcpip":r._protocol.directTcpip(a,i,s,e);break;case"direct-streamlocal@openssh.com":r._protocol.openssh_directStreamLocal(a,i,s,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function Xu(r,t,e){let n={single:!1,protocol:"MIT-MAGIC-COOKIE-1",cookie:void 0,screen:0};typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.single=="boolean"&&(n.single=t.single),typeof t.screen=="number"&&(n.screen=t.screen),typeof t.protocol=="string"&&(n.protocol=t.protocol),typeof t.cookie=="string"?n.cookie=t.cookie:Buffer.isBuffer(t.cookie)&&(n.cookie=t.cookie.hexSlice(0,t.cookie.length))),n.cookie===void 0&&(n.cookie=N0());let i=typeof e=="function";if(r.outgoing.state!=="open"){i&&e(new Error("Channel is not open"));return}i&&r._callbacks.push(s=>{if(s){e(s!==!0?s:new Error("Unable to request X11"));return}r._hasX11=!0,++r._client._acceptX11,r.once("close",()=>{r._client._acceptX11&&--r._client._acceptX11}),e()}),r._client._protocol.x11Forward(r.outgoing.id,n,i)}function Ju(r,t,e){let n=24,i=80,s=640,o=480,a="vt100",c=null;typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.rows=="number"&&(n=t.rows),typeof t.cols=="number"&&(i=t.cols),typeof t.width=="number"&&(s=t.width),typeof t.height=="number"&&(o=t.height),typeof t.term=="string"&&(a=t.term),typeof t.modes=="object"&&(c=t.modes));let f=typeof e=="function";if(r.outgoing.state!=="open"){f&&e(new Error("Channel is not open"));return}f&&r._callbacks.push(l=>{if(l){e(l!==!0?l:new Error("Unable to request a pseudo-terminal"));return}e()}),r._client._protocol.pty(r.outgoing.id,n,i,o,s,a,c,f)}function Zu(r,t){let e=typeof t=="function";if(r.outgoing.state!=="open"){e&&t(new Error("Channel is not open"));return}if(r._client._agentFwdEnabled){e&&t(!1);return}r._client._agentFwdEnabled=!0,r._callbacks.push(n=>{if(n){r._client._agentFwdEnabled=!1,e&&t(n!==!0?n:new Error("Unable to request agent forwarding"));return}e&&t()}),r._client._protocol.openssh_agentForward(r.outgoing.id,!0)}function k0(r,t){if(r.outgoing.state!=="open"){t(new Error("Channel is not open"));return}r._callbacks.push(e=>{if(e){t(e!==!0?e:new Error("Unable to open shell"));return}r.subtype="shell",t(void 0,r)}),r._client._protocol.shell(r.outgoing.id,!0)}function B0(r,t,e,n){if(r.outgoing.state!=="open"){n(new Error("Channel is not open"));return}r._callbacks.push(i=>{if(i){n(i!==!0?i:new Error("Unable to exec"));return}r.subtype="exec",r.allowHalfOpen=e.allowHalfOpen!==!1,n(void 0,r)}),r._client._protocol.exec(r.outgoing.id,t,!0)}function ma(r,t,e){let n=typeof e=="function";if(r.outgoing.state!=="open"){n&&e(new Error("Channel is not open"));return}n&&r._callbacks.push(s=>{if(s){e(s!==!0?s:new Error("Unable to set environment"));return}e()});let i=Object.keys(t||{});for(let s=0;s<i.length;++s){let o=i[s],a=t[o];r._client._protocol.env(r.outgoing.id,o,a,n)}}function Aa(r,t,e){if(r.outgoing.state!=="open"){e(new Error("Channel is not open"));return}r._callbacks.push(n=>{if(n){e(n!==!0?n:new Error(`Unable to start subsystem: ${t}`));return}r.subtype="subsystem",e(void 0,r)}),r._client._protocol.subsystem(r.outgoing.id,t,!0)}function R0(r,t){let e=-1,n,i=()=>{let c={type:t.type,incoming:{id:e,window:_s,packetSize:bs,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},f=new nd(r,c);return r._chanMgr.update(e,f),r._protocol.channelOpenConfirm(t.sender,e,_s,bs),f},s=()=>{n===void 0&&(e===-1?n=hi.RESOURCE_SHORTAGE:n=hi.CONNECT_FAILED),e!==-1&&r._chanMgr.remove(e),r._protocol.channelOpenFail(t.sender,n,"")},o=()=>(e=r._chanMgr.add(),e===-1&&(n=hi.RESOURCE_SHORTAGE,r.config.debug&&r.config.debug("Client: Automatic rejection of incoming channel open: no channels available")),e!==-1),a=t.data;switch(t.type){case"forwarded-tcpip":{let c=r._forwarding[`${a.destIP}:${a.destPort}`];if(c!==void 0&&o()){a.destPort===0&&(a.destPort=c),r.emit("tcp connection",a,i,s);return}break}case"forwarded-streamlocal@openssh.com":if(r._forwardingUnix[a.socketPath]!==void 0&&o()){r.emit("unix connection",a,i,s);return}break;case"auth-agent@openssh.com":if(r._agentFwdEnabled&&typeof r._agent.getStream=="function"&&o()){r._agent.getStream((c,f)=>{if(c)return s();let l=i();l.pipe(f).pipe(l)});return}break;case"x11":if(r._acceptX11!==0&&o()){r.emit("x11",a,i,s);return}break;default:n=hi.UNKNOWN_CHANNEL_TYPE,r.config.debug&&r.config.debug(`Client: Automatic rejection of unsupported incoming channel open type: ${t.type}`)}n===void 0&&(n=hi.ADMINISTRATIVELY_PROHIBITED,r.config.debug&&r.config.debug("Client: Automatic rejection of unexpected incoming channel open for: "+t.type)),s()}var N0=(()=>{let r=Buffer.allocUnsafe(16);return()=>(a0(r,0,16),r.hexSlice(0,16))})();function ed(r){if(!Array.isArray(r))throw new Error("authList must be an array");let t=0;return(e,n,i)=>t===r.length?!1:r[t++]}function P0(r,t,e){if(!r._sock||!Ct(r._sock))return;if(typeof e!="function"&&(e=_a),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let n=[];for(let i of t){let s=Es(i);if(s instanceof Error)throw s;n.push(s)}if(!r.config.strictVendor||r.config.strictVendor&&gi.test(r._remoteVer)){r._callbacks.push((i,s)=>{if(i){e(i!==!0?i:new Error("Server failed to prove supplied keys"));return}let o=[],a=0;for(ms.init(s,0);ms.avail()&&a!==n.length;){let c=n[a++],f=c.getPublicSSH(),l=ms.readString();As.init(l,0);let u=As.readString(!0),h=As.readString(),g;if(u!==c.type)if(c.type==="ssh-rsa")switch(u){case"rsa-sha2-256":g="sha256";break;case"rsa-sha2-512":g="sha512";break;default:continue}else continue;let b=r._protocol._kex.sessionID,_=Buffer.allocUnsafe(37+b.length+4+f.length),x=0;ga(_,29,x),_.utf8Write("hostkeys-prove-00@openssh.com",x+=4,29),ga(_,b.length,x+=29),Ku(b,_,0,b.length,x+=4),ga(_,f.length,x+=b.length),Ku(f,_,0,f.length,x+=4),(h=w0(h,u))&&c.verify(_,h,g)===!0&&o.push(c)}As.clear(),ms.clear(),e(null,o)}),r._protocol.openssh_hostKeysProve(n);return}process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version"))}function Ea(r,t,e){switch(t.type){case"ssh-rsa":if(r._protocol._compatFlags&td.IMPLY_RSA_SHA2_SIGALGS&&(Array.isArray(e)?e=["rsa-sha2-256","rsa-sha2-512",...e]:e=["rsa-sha2-256","rsa-sha2-512"]),Array.isArray(e)){if(e.indexOf("rsa-sha2-256")!==-1)return[["rsa-sha2-256","sha256"]];if(e.indexOf("rsa-sha2-512")!==-1)return[["rsa-sha2-512","sha512"]];if(e.indexOf("ssh-rsa")===-1)return[]}return[["ssh-rsa","sha1"]]}}id.exports=ba});var od=ot(sd=>{"use strict";var{Agent:Sa}=require("http"),{Agent:T0}=require("https"),{connect:L0}=require("tls"),xa;for(let r of[Sa,T0]){class t extends r{constructor(n,i){super(i),this._connectCfg=n,this._defaultSrcIP=i&&i.srcIP||"localhost"}createConnection(n,i){let s=n&&n.localAddress||this._defaultSrcIP,o=n&&n.localPort||0,a=n.host,c=n.port;xa===void 0&&(xa=ya());let f=new xa,l=!1;f.on("ready",()=>{f.forwardOut(s,o,a,c,(u,h)=>{if(l=!0,u)return f.end(),i(u);h.once("close",()=>f.end()),i(null,U0(h,r,n))})}).on("error",i).on("close",()=>{l||i(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}sd[r===Sa?"SSHTTPAgent":"SSHTTPSAgent"]=t}function mi(){}function U0(r,t,e){if(t===Sa)return r.setKeepAlive=mi,r.setNoDelay=mi,r.setTimeout=mi,r.ref=mi,r.unref=mi,r.destroySoon=r.destroy,r;e.socket=r;let n=L0(e),i=(()=>{let s=!1;return()=>{s||(s=!0,r.isPaused()&&r.resume())}})();return n.on("end",i).on("close",i),n}});var cd=ot((jy,va)=>{"use strict";var{Server:D0}=require("net"),Ei=require("events"),{listenerCount:Ft}=Ei,{CHANNEL_OPEN_FAILURE:kn,DEFAULT_CIPHER:O0,DEFAULT_COMPRESSION:M0,DEFAULT_KEX:F0,DEFAULT_MAC:$0,DEFAULT_SERVER_HOST_KEY:H0,DISCONNECT_REASON:Bn,DISCONNECT_REASON_BY_VALUE:Q0,SUPPORTED_CIPHER:W0,SUPPORTED_COMPRESSION:q0,SUPPORTED_KEX:K0,SUPPORTED_MAC:V0,SUPPORTED_SERVER_HOST_KEY:G0}=xr(),{init:Y0}=Nr(),{KexInit:j0}=ns(),{parseKey:ad}=Lr(),z0=jo(),{SFTP:X0}=li(),{writeUInt32BE:J0}=or(),{Channel:Rn,MAX_WINDOW:Or,PACKET_SIZE:Mr,windowAdjust:Z0,WINDOW_THRESHOLD:em}=ua(),{ChannelManager:tm,generateAlgorithmList:Ai,isWritable:ys,onChannelOpenFailure:rm,onCHANNEL_CLOSE:nm}=pa(),im=10,Fr=class extends Ei{constructor(t,e,n,i,s){super(),this.username=this.user=e,this.service=n,this.method=i,this._initialResponse=!1,this._finalResponse=!1,this._multistep=!1,this._cbfinal=(o,a,c)=>{this._finalResponse||(this._finalResponse=!0,s(this,o,a,c))},this._protocol=t}accept(){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!0)}reject(t,e){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!1,t,e)}},xs=class extends Fr{constructor(t,e,n,i,s,o){super(t,e,n,i,o),this._multistep=!0,this._cb=void 0,this._onInfoResponse=a=>{let c=this._cb;c&&(this._cb=void 0,c(a))},this.submethods=s,this.on("abort",()=>{this._cb&&this._cb(new Error("Authentication request aborted"))})}prompt(t,e,n,i){Array.isArray(t)||(t=[t]),typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"?(i=n,n=void 0):typeof i!="function"&&(i=void 0);for(let s=0;s<t.length;++s)typeof t[s]=="string"&&(t[s]={prompt:t[s],echo:!0});this._cb=i,this._initialResponse=!0,this._protocol.authInfoReq(e,n,t)}},Ia=class extends Fr{constructor(t,e,n,i,s,o){super(t,e,n,i,o),this.key={algo:s.keyAlgo,data:s.key},this.hashAlgo=s.hashAlgo,this.signature=s.signature,this.blob=s.blob}accept(){this.signature?Fr.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},Ca=class extends Fr{constructor(t,e,n,i,s,o){super(t,e,n,i,o),this.key={algo:s.keyAlgo,data:s.key},this.hashAlgo=s.hashAlgo,this.signature=s.signature,this.blob=s.blob,this.localHostname=s.localHostname,this.localUsername=s.localUsername}},Ss=class extends Fr{constructor(t,e,n,i,s,o){super(t,e,n,i,o),this.password=s,this._changeCb=void 0}requestChange(t,e){if(this._changeCb)throw new Error("Change request already in progress");if(typeof t!="string")throw new Error("prompt argument must be a string");if(typeof e!="function")throw new Error("Callback argument must be a function");this._changeCb=e,this._protocol.authPasswdChg(t)}},gr=class extends Ei{constructor(t,e,n){super(),this.type="session",this.subtype=void 0,this.server=!0,this._ending=!1,this._channel=void 0,this._chanInfo={type:"session",incoming:{id:n,window:Or,packetSize:Mr,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},Jt=class extends Ei{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new Error("Missing configuration object");let n=Object.create(null),i=[],s=t.hostKeys;if(!Array.isArray(s))throw new Error("hostKeys must be an array");let o=typeof t.algorithms=="object"&&t.algorithms!==null?t.algorithms:{},a=Ai(o.serverHostKey,H0,G0);for(let h=0;h<s.length;++h){let g;if(Buffer.isBuffer(s[h])||typeof s[h]=="string"?g=ad(s[h]):g=ad(s[h].key,s[h].passphrase),g instanceof Error)throw new Error(`Cannot parse privateKey: ${g.message}`);if(Array.isArray(g)&&(g=g[0]),g.getPrivatePEM()===null)throw new Error("privateKey value contains an invalid private key");if(!i.includes(g.type))if(g.type==="ssh-rsa"){let b=a.indexOf("ssh-rsa"),_=a.indexOf("rsa-sha2-256"),x=a.indexOf("rsa-sha2-512");b===-1&&(b=1/0),[b,_,x].sort(sm).forEach(S=>{if(S===-1)return;let N;switch(S){case b:N="ssh-rsa";break;case _:N="rsa-sha2-256";break;case x:N="rsa-sha2-512";break;default:return}n[N]=g,i.push(N)})}else n[g.type]=g,i.push(g.type)}let c={kex:Ai(o.kex,F0,K0).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:i,cs:{cipher:Ai(o.cipher,O0,W0),mac:Ai(o.hmac,$0,V0),compress:Ai(o.compress,M0,q0),lang:[]},sc:void 0};c.sc=c.cs,typeof e=="function"&&this.on("connection",e);let f=typeof t.debug=="function"?t.debug:void 0,l=t.ident?Buffer.from(t.ident):void 0,u=new j0(c);this._srv=new D0(h=>{if(this._connections>=this.maxConnections){h.destroy();return}++this._connections,h.once("close",()=>{--this._connections});let g;if(f){let b=`[${process.hrtime().join(".")}] `;g=_=>{f(`${b}${_}`)}}new ws(h,n,l,u,g,this,t)}).on("error",h=>{this.emit("error",h)}).on("listening",()=>{this.emit("listening")}).on("close",()=>{this.emit("close")}),this._connections=0,this.maxConnections=1/0}injectSocket(t){this._srv.emit("connection",t)}listen(...t){return this._srv.listen(...t),this}address(){return this._srv.address()}getConnections(t){return this._srv.getConnections(t),this}close(t){return this._srv.close(t),this}ref(){return this._srv.ref(),this}unref(){return this._srv.unref(),this}};Jt.KEEPALIVE_CLIENT_INTERVAL=15e3;Jt.KEEPALIVE_CLIENT_COUNT_MAX=3;var ws=class extends Ei{constructor(t,e,n,i,s,o,a){super();let c=0,f=!1,l=[],u,h,g,b=[];this._sock=t,this._chanMgr=new tm(this),this._debug=s,this.noMoreSessions=!1,this.authenticated=!1;function _(G){}this.on("error",_);let x=s?(G,w,I)=>{s(`Debug output from client: ${JSON.stringify(I)}`)}:void 0,S=typeof a.keepaliveInterval=="number"&&isFinite(a.keepaliveInterval)&&a.keepaliveInterval>0?a.keepaliveInterval:typeof Jt.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(Jt.KEEPALIVE_CLIENT_INTERVAL)&&Jt.KEEPALIVE_CLIENT_INTERVAL>0?Jt.KEEPALIVE_CLIENT_INTERVAL:-1,N=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof Jt.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(Jt.KEEPALIVE_CLIENT_COUNT_MAX)&&Jt.KEEPALIVE_CLIENT_COUNT_MAX>=0?Jt.KEEPALIVE_CLIENT_COUNT_MAX:-1,O=0;S!==-1&&N!==-1&&(this.once("ready",()=>{let G=()=>{clearInterval(h)};this.on("close",G).on("end",G),h=setInterval(()=>{if(++O>N){clearInterval(h);let w=new Error("Keepalive timeout");w.level="client-timeout",this.emit("error",w),this.end()}else P.ping()},S)}),g=()=>{h&&h.refresh(),O=0});let P=this._protocol=new z0({server:!0,hostKeys:e,ident:n,offer:i,onPacket:g,greeting:a.greeting,banner:a.banner,onWrite:G=>{ys(t)&&t.write(G)},onError:G=>{P._destruct||t.removeAllListeners("data"),this.emit("error",G);try{t.end()}catch{}},onHeader:G=>{this.removeListener("error",_);let w={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:G};if(!o.emit("connection",this,w)){P.disconnect(Bn.BY_APPLICATION),t.end();return}G.greeting&&this.emit("greeting",G.greeting)},onHandshakeComplete:G=>{++c>1&&this.emit("rekey"),this.emit("handshake",G)},debug:s,messageHandlers:{DEBUG:x,DISCONNECT:(G,w,I)=>{if(w!==Bn.BY_APPLICATION){I||(I=Q0[w],I===void 0&&(I=`Unexpected disconnection reason: ${w}`));let D=new Error(I);D.code=w,this.emit("error",D)}t.end()},CHANNEL_OPEN:(G,w)=>{if(w.type==="session"&&this.noMoreSessions||!this.authenticated){let re=kn.ADMINISTRATIVELY_PROHIBITED;return P.channelOpenFail(w.sender,re)}let I=-1,D,q=!1,Q,ae=()=>{q||(q=!0,D===void 0&&(I===-1?D=kn.RESOURCE_SHORTAGE:D=kn.CONNECT_FAILED),I!==-1&&this._chanMgr.remove(I),P.channelOpenFail(w.sender,D,""))},te=()=>(I=this._chanMgr.add(),I===-1&&(D=kn.RESOURCE_SHORTAGE,s&&s("Automatic rejection of incoming channel open: no channels available")),I!==-1),Z=w.data;switch(w.type){case"session":if(Ft(this,"session")&&te()){Q=()=>{if(q)return;q=!0;let re=new gr(this,w,I);return this._chanMgr.update(I,re),P.channelOpenConfirm(w.sender,I,Or,Mr),re},this.emit("session",Q,ae);return}break;case"direct-tcpip":if(Ft(this,"tcpip")&&te()){Q=()=>{if(q)return;q=!0;let re={type:void 0,incoming:{id:I,window:Or,packetSize:Mr,state:"open"},outgoing:{id:w.sender,window:w.window,packetSize:w.packetSize,state:"open"}},ce=new Rn(this,re,{server:!0});return this._chanMgr.update(I,ce),P.channelOpenConfirm(w.sender,I,Or,Mr),ce},this.emit("tcpip",Q,ae,Z);return}break;case"direct-streamlocal@openssh.com":if(Ft(this,"openssh.streamlocal")&&te()){Q=()=>{if(q)return;q=!0;let re={type:void 0,incoming:{id:I,window:Or,packetSize:Mr,state:"open"},outgoing:{id:w.sender,window:w.window,packetSize:w.packetSize,state:"open"}},ce=new Rn(this,re,{server:!0});return this._chanMgr.update(I,ce),P.channelOpenConfirm(w.sender,I,Or,Mr),ce},this.emit("openssh.streamlocal",Q,ae,Z);return}break;default:D=kn.UNKNOWN_CHANNEL_TYPE,s&&s(`Automatic rejection of unsupported incoming channel open type: ${w.type}`)}D===void 0&&(D=kn.ADMINISTRATIVELY_PROHIBITED,s&&s(`Automatic rejection of unexpected incoming channel open for: ${w.type}`)),ae()},CHANNEL_OPEN_CONFIRMATION:(G,w)=>{let I=this._chanMgr.get(w.recipient);if(typeof I!="function")return;let D={type:I.type,incoming:{id:w.recipient,window:Or,packetSize:Mr,state:"open"},outgoing:{id:w.sender,window:w.window,packetSize:w.packetSize,state:"open"}},q=new Rn(this,D,{server:!0});this._chanMgr.update(w.recipient,q),I(void 0,q)},CHANNEL_OPEN_FAILURE:(G,w,I,D)=>{let q=this._chanMgr.get(w);if(typeof q!="function")return;rm(this,w,{reason:I,description:D},q)},CHANNEL_DATA:(G,w,I)=>{let D=this._chanMgr.get(w);if(!(typeof D!="object"||D===null)&&!(D.constructor===gr&&(D=D._channel,!D))&&D.incoming.window!==0){if(D.incoming.window-=I.length,D.push(I)===!1){D._waitChanDrain=!0;return}D.incoming.window<=em&&Z0(D)}},CHANNEL_EXTENDED_DATA:(G,w,I,D)=>{},CHANNEL_WINDOW_ADJUST:(G,w,I)=>{let D=this._chanMgr.get(w);typeof D!="object"||D===null||D.constructor===gr&&(D=D._channel,!D)||(D.outgoing.window+=I,D._waitWindow&&(D._waitWindow=!1,D._chunk?D._write(D._chunk,null,D._chunkcb):D._chunkcb?D._chunkcb():D._chunkErr?D.stderr._write(D._chunkErr,null,D._chunkcbErr):D._chunkcbErr&&D._chunkcbErr()))},CHANNEL_SUCCESS:(G,w)=>{let I=this._chanMgr.get(w);typeof I!="object"||I===null||I.constructor===gr&&(I=I._channel,!I)||I._callbacks.length&&I._callbacks.shift()(!1)},CHANNEL_FAILURE:(G,w)=>{let I=this._chanMgr.get(w);typeof I!="object"||I===null||I.constructor===gr&&(I=I._channel,!I)||I._callbacks.length&&I._callbacks.shift()(!0)},CHANNEL_REQUEST:(G,w,I,D,q)=>{let Q=this._chanMgr.get(w);if(typeof Q!="object"||Q===null)return;let ae=!1,te,Z;if(Q.constructor!==gr){D&&P.channelFailure(Q.outgoing.id);return}if(D&&(I!=="shell"&&I!=="exec"&&I!=="subsystem"&&(te=()=>{ae||Q._ending||Q._channel||(ae=!0,P.channelSuccess(Q._chanInfo.outgoing.id))}),Z=()=>{ae||Q._ending||Q._channel||(ae=!0,P.channelFailure(Q._chanInfo.outgoing.id))}),Q._ending){Z&&Z();return}switch(I){case"env":if(Ft(Q,"env")){Q.emit("env",te,Z,{key:q.name,val:q.value});return}break;case"pty-req":if(Ft(Q,"pty")){Q.emit("pty",te,Z,q);return}break;case"window-change":Ft(Q,"window-change")?Q.emit("window-change",te,Z,q):Z&&Z();break;case"x11-req":if(Ft(Q,"x11")){Q.emit("x11",te,Z,q);return}break;case"signal":if(Ft(Q,"signal")){Q.emit("signal",te,Z,{name:q});return}break;case"auth-agent-req@openssh.com":if(Ft(Q,"auth-agent")){Q.emit("auth-agent",te,Z);return}break;case"shell":if(Ft(Q,"shell")){te=()=>{if(ae||Q._ending||Q._channel)return;ae=!0,D&&P.channelSuccess(Q._chanInfo.outgoing.id);let re=new Rn(this,Q._chanInfo,{server:!0});return re.subtype=Q.subtype=I,Q._channel=re,re},Q.emit("shell",te,Z);return}break;case"exec":if(Ft(Q,"exec")){te=()=>{if(ae||Q._ending||Q._channel)return;ae=!0,D&&P.channelSuccess(Q._chanInfo.outgoing.id);let re=new Rn(this,Q._chanInfo,{server:!0});return re.subtype=Q.subtype=I,Q._channel=re,re},Q.emit("exec",te,Z,{command:q});return}break;case"subsystem":{let re=q==="sftp";if(te=()=>{if(ae||Q._ending||Q._channel)return;ae=!0,D&&P.channelSuccess(Q._chanInfo.outgoing.id);let ce;return re?ce=new X0(this,Q._chanInfo,{server:!0,debug:s}):(ce=new Rn(this,Q._chanInfo,{server:!0}),ce.subtype=Q.subtype=`${I}:${q}`),Q._channel=ce,ce},q==="sftp"){if(Ft(Q,"sftp")){Q.emit("sftp",te,Z);return}re=!1}if(Ft(Q,"subsystem")){Q.emit("subsystem",te,Z,{name:q});return}break}}s&&s(`Automatic rejection of incoming channel request: ${I}`),Z&&Z()},CHANNEL_EOF:(G,w)=>{let I=this._chanMgr.get(w);typeof I!="object"||I===null||I.constructor===gr&&(I._ending||(I._ending=!0,I.emit("eof"),I.emit("end")),I=I._channel,!I)||I.incoming.state==="open"&&(I.incoming.state="eof",I.readable&&I.push(null))},CHANNEL_CLOSE:(G,w)=>{let I=this._chanMgr.get(w);typeof I!="object"||I===null||I.constructor===gr&&(I._ending=!0,I.emit("close"),I=I._channel,!I)||nm(this,w,I)},SERVICE_REQUEST:(G,w)=>{if(c===0||f||this.authenticated||w!=="ssh-userauth"){P.disconnect(Bn.SERVICE_NOT_AVAILABLE),t.end();return}f=!0,P.serviceAccept(w)},USERAUTH_REQUEST:(G,w,I,D,q)=>{if(c===0||this.authenticated||u&&(u.username!==w||u.service!==I)||D!=="password"&&D!=="publickey"&&D!=="hostbased"&&D!=="keyboard-interactive"&&D!=="none"||l.length===im){P.disconnect(Bn.PROTOCOL_ERROR),t.end();return}else if(I!=="ssh-connection"){P.disconnect(Bn.SERVICE_NOT_AVAILABLE),t.end();return}let Q;switch(D){case"keyboard-interactive":Q=new xs(P,w,I,D,q,W);break;case"publickey":Q=new Ia(P,w,I,D,q,W);break;case"hostbased":Q=new Ca(P,w,I,D,q,W);break;case"password":if(u&&u instanceof Ss&&u._changeCb){let ae=u._changeCb;u._changeCb=void 0,ae(q.newPassword);return}Q=new Ss(P,w,I,D,q,W);break;case"none":Q=new Fr(P,w,I,D,W);break}if(u)if(u._initialResponse)u._multistep&&!u._finalResponse&&(u._cleanup&&u._cleanup(),u.emit("abort"));else return l.push(Q);u=Q,Ft(this,"authentication")?this.emit("authentication",u):u.reject()},USERAUTH_INFO_RESPONSE:(G,w)=>{u&&u instanceof xs&&u._onInfoResponse(w)},GLOBAL_REQUEST:(G,w,I,D)=>{let q={type:null,buf:null};function Q(ae,te){q.type=ae,q.buf=te,X()}if(I&&b.push(q),(w==="tcpip-forward"||w==="cancel-tcpip-forward"||w==="no-more-sessions@openssh.com"||w==="streamlocal-forward@openssh.com"||w==="cancel-streamlocal-forward@openssh.com")&&Ft(this,"request")&&this.authenticated){let ae,te;if(I){let Z=!1;ae=re=>{if(Z)return;Z=!0;let ce;w==="tcpip-forward"&&D.bindPort===0&&typeof re=="number"&&(ce=Buffer.allocUnsafe(4),J0(ce,re,0)),Q("SUCCESS",ce)},te=()=>{Z||(Z=!0,Q("FAILURE"))}}if(w==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,ae&&ae();return}this.emit("request",ae,te,w,D)}else I&&Q("FAILURE")}}});t.pause(),Y0.then(()=>{P.start(),t.on("data",G=>{try{P.parse(G,0,G.length)}catch(w){this.emit("error",w);try{ys(t)&&t.end()}catch{}}}),t.resume()}).catch(G=>{this.emit("error",G);try{ys(t)&&t.end()}catch{}}),t.on("error",G=>{G.level="socket",this.emit("error",G)}).once("end",()=>{s&&s("Socket ended"),P.cleanup(),this.emit("end")}).once("close",()=>{s&&s("Socket closed"),P.cleanup(),this.emit("close");let G=new Error("No response from server");this._chanMgr.cleanup(G)});let W=(G,w,I,D)=>{u===G&&!this.authenticated&&(w?(u=void 0,this.authenticated=!0,P.authSuccess(),l=[],this.emit("ready")):(P.authFailure(I,D),l.length&&(u=l.pop(),Ft(this,"authentication")?this.emit("authentication",u):u.reject())))};function X(){for(;b.length>0&&b[0].type;){let G=b.shift();G.type==="SUCCESS"&&P.requestSuccess(G.buf),G.type==="FAILURE"&&P.requestFailure()}}}end(){return this._sock&&ys(this._sock)&&(this._protocol.disconnect(Bn.BY_APPLICATION),this._sock.end()),this}x11(t,e,n){return wa(this,"x11",{originAddr:t,originPort:e},n),this}forwardOut(t,e,n,i,s){return wa(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:n,remotePort:i},s),this}openssh_forwardOutStreamLocal(t,e){return wa(this,"forwarded-streamlocal@openssh.com",{socketPath:t},e),this}rekey(t){let e;try{this._protocol.rekey()}catch(n){e=n}typeof t=="function"&&(e?process.nextTick(t,e):this.once("rekey",t))}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function wa(r,t,e,n){let i=Or,s=Mr;typeof e=="function"&&(n=e,e={});let o=(c,f)=>{n(c,f)};o.type=t;let a=r._chanMgr.add(o);if(a===-1){n(new Error("No free channels available"));return}switch(t){case"forwarded-tcpip":r._protocol.forwardedTcpip(a,i,s,e);break;case"x11":r._protocol.x11(a,i,s,e);break;case"forwarded-streamlocal@openssh.com":r._protocol.openssh_forwardedStreamLocal(a,i,s,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function sm(r,t){return r-t}va.exports=Jt;va.exports.IncomingClient=ws});var hd=ot((zy,dd)=>{"use strict";var{createCipheriv:om,generateKeyPair:am,generateKeyPairSync:cm,getCurves:fm,randomBytes:fd}=require("crypto"),{Ber:ht}=Kn(),lm=Ks().pbkdf,{CIPHER_INFO:um}=Nr(),dm=16,hm=16,pm=fm(),gm=new Map(Object.entries(um));function ld(r,t){if(typeof r!="string")throw new TypeError("Key type must be a string");let e={type:"spki",format:"der"},n={type:"pkcs8",format:"der"};switch(r.toLowerCase()){case"rsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for RSA key");let i=t.bits;if(!Number.isInteger(i))throw new TypeError("RSA bits must be an integer");if(i<=0||i>16384)throw new RangeError("RSA bits must be non-zero and <= 16384");return["rsa",{modulusLength:i,publicKeyEncoding:e,privateKeyEncoding:n}]}case"ecdsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for ECDSA key");if(!Number.isInteger(t.bits))throw new TypeError("ECDSA bits must be an integer");let i;switch(t.bits){case 256:i="prime256v1";break;case 384:i="secp384r1";break;case 521:i="secp521r1";break;default:throw new Error("ECDSA bits must be 256, 384, or 521")}if(!pm.includes(i))throw new Error("Unsupported ECDSA bits value");return["ec",{namedCurve:i,publicKeyEncoding:e,privateKeyEncoding:n}]}case"ed25519":return["ed25519",{publicKeyEncoding:e,privateKeyEncoding:n}];default:throw new Error(`Unsupported key type: ${r}`)}}function mm(r,t,e){switch(r){case"rsa":{let n=new ht.Reader(e);if(n.readSequence(),n.readInt()!==0)throw new Error("Unsupported version in RSA private key");if(n.readSequence(),n.readOID()!=="1.2.840.113549.1.1.1")throw new Error("Bad RSA private OID");if(n.readByte()!==ht.Null)throw new Error("Malformed RSA private key (expected null)");if(n.readByte()!==0)throw new Error("Malformed RSA private key (expected zero-length null)");if(n=new ht.Reader(n.readString(ht.OctetString,!0)),n.readSequence(),n.readInt()!==0)throw new Error("Unsupported version in RSA private key");let i=n.readString(ht.Integer,!0),s=n.readString(ht.Integer,!0),o=n.readString(ht.Integer,!0),a=n.readString(ht.Integer,!0),c=n.readString(ht.Integer,!0);n.readString(ht.Integer,!0),n.readString(ht.Integer,!0);let f=n.readString(ht.Integer,!0),l=Buffer.from("ssh-rsa"),u=Buffer.allocUnsafe(4+l.length+4+i.length+4+s.length+4+o.length+4+f.length+4+a.length+4+c.length),h=0;u.writeUInt32BE(l.length,h+=0),u.set(l,h+=4),u.writeUInt32BE(i.length,h+=l.length),u.set(i,h+=4),u.writeUInt32BE(s.length,h+=i.length),u.set(s,h+=4),u.writeUInt32BE(o.length,h+=s.length),u.set(o,h+=4),u.writeUInt32BE(f.length,h+=o.length),u.set(f,h+=4),u.writeUInt32BE(a.length,h+=f.length),u.set(a,h+=4),u.writeUInt32BE(c.length,h+=a.length),u.set(c,h+=4);let g=Buffer.allocUnsafe(4+l.length+4+s.length+4+i.length);return h=0,g.writeUInt32BE(l.length,h+=0),g.set(l,h+=4),g.writeUInt32BE(s.length,h+=l.length),g.set(s,h+=4),g.writeUInt32BE(i.length,h+=s.length),g.set(i,h+=4),{sshName:l.toString(),priv:u,pub:g}}case"ec":{let n=new ht.Reader(t);if(n.readSequence(),n.readSequence(),n.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA public OID");n.readOID();let i=n.readString(ht.BitString,!0);{let h=0;for(;h<i.length&&i[h]===0;++h);h>0&&(i=i.slice(h))}if(n=new ht.Reader(e),n.readSequence(),n.readInt()!==0)throw new Error("Unsupported version in ECDSA private key");if(n.readSequence(),n.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA private OID");let s=n.readOID(),o;switch(s){case"1.2.840.10045.3.1.7":o="nistp256";break;case"1.3.132.0.34":o="nistp384";break;case"1.3.132.0.35":o="nistp521";break;default:throw new Error("Unsupported curve in ECDSA private key")}if(n=new ht.Reader(n.readString(ht.OctetString,!0)),n.readSequence(),n.readInt()!==1)throw new Error("Unsupported version in ECDSA private key");let a=Buffer.concat([Buffer.from([0]),n.readString(ht.OctetString,!0)]),c=Buffer.from(`ecdsa-sha2-${o}`);o=Buffer.from(o);let f=Buffer.allocUnsafe(4+c.length+4+o.length+4+i.length+4+a.length),l=0;f.writeUInt32BE(c.length,l+=0),f.set(c,l+=4),f.writeUInt32BE(o.length,l+=c.length),f.set(o,l+=4),f.writeUInt32BE(i.length,l+=o.length),f.set(i,l+=4),f.writeUInt32BE(a.length,l+=i.length),f.set(a,l+=4);let u=Buffer.allocUnsafe(4+c.length+4+o.length+4+i.length);return l=0,u.writeUInt32BE(c.length,l+=0),u.set(c,l+=4),u.writeUInt32BE(o.length,l+=c.length),u.set(o,l+=4),u.writeUInt32BE(i.length,l+=o.length),u.set(i,l+=4),{sshName:c.toString(),priv:f,pub:u}}case"ed25519":{let n=new ht.Reader(t);if(n.readSequence(),n.readSequence(),n.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let i=n.readString(ht.BitString,!0);{let l=0;for(;l<i.length&&i[l]===0;++l);l>0&&(i=i.slice(l))}if(n=new ht.Reader(e),n.readSequence(),n.readInt()!==0)throw new Error("Unsupported version in ED25519 private key");if(n.readSequence(),n.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 private OID");n=new ht.Reader(n.readString(ht.OctetString,!0));let s=n.readString(ht.OctetString,!0),o=Buffer.from("ssh-ed25519"),a=Buffer.allocUnsafe(4+o.length+4+i.length+4+(s.length+i.length)),c=0;a.writeUInt32BE(o.length,c+=0),a.set(o,c+=4),a.writeUInt32BE(i.length,c+=o.length),a.set(i,c+=4),a.writeUInt32BE(s.length+i.length,c+=i.length),a.set(s,c+=4),a.set(i,c+=s.length);let f=Buffer.allocUnsafe(4+o.length+4+i.length);return c=0,f.writeUInt32BE(o.length,c+=0),f.set(o,c+=4),f.writeUInt32BE(i.length,c+=o.length),f.set(i,c+=4),{sshName:o.toString(),priv:a,pub:f}}}}function ud(r,t,e,n){let i="new",s,o="";if(typeof n=="object"&&n!==null&&(typeof n.comment=="string"&&n.comment&&(o=n.comment),typeof n.format=="string"&&n.format&&(i=n.format),n.passphrase)){let a;if(typeof n.passphrase=="string")a=Buffer.from(n.passphrase);else if(Buffer.isBuffer(n.passphrase))a=n.passphrase;else throw new Error("Invalid passphrase");if(n.cipher===void 0)throw new Error("Missing cipher name");let c=gm.get(n.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(i==="new"){let f=hm;if(n.rounds!==void 0){if(!Number.isInteger(n.rounds))throw new TypeError("rounds must be an integer");n.rounds>0&&(f=n.rounds)}let l=Buffer.allocUnsafe(c.keyLen+c.ivLen),u=fd(dm);if(lm(a,a.length,u,u.length,l,l.length,f)!==0)return new Error("Failed to generate information to encrypt key");let g=Buffer.allocUnsafe(4+u.length+4);{let b=0;g.writeUInt32BE(u.length,b+=0),g.set(u,b+=4),g.writeUInt32BE(f,b+=u.length)}s={cipher:c,cipherName:n.cipher,kdfName:"bcrypt",kdfOptions:g,key:l.slice(0,c.keyLen),iv:l.slice(c.keyLen)}}}switch(i){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
15
+ `,c,f=Buffer.from(s?s.cipherName:"none"),l=Buffer.from(s?s.kdfName:"none"),u=s?s.kdfOptions:Buffer.alloc(0),h=s?s.cipher.blockLen:8,g=mm(r,t,e),b=fd(4),_=Buffer.from(o),x=8+g.priv.length+4+_.length,S=[];for(let X=1;(x+S.length)%h;++X)S.push(X&255);S=Buffer.from(S);let N=Buffer.allocUnsafe(x+S.length),O;{let X=0;N.set(b,X+=0),N.set(b,X+=4),N.set(g.priv,X+=4),N.writeUInt32BE(_.length,X+=g.priv.length),N.set(_,X+=4),N.set(S,X+=_.length)}if(s){let X={authTagLength:s.cipher.authLen},G=om(s.cipher.sslName,s.key,s.iv,X);G.setAutoPadding(!1),N=Buffer.concat([G.update(N),G.final()]),s.cipher.authLen>0?O=G.getAuthTag():O=Buffer.alloc(0),s.key.fill(0),s.iv.fill(0)}else O=Buffer.alloc(0);let P=Buffer.from("openssh-key-v1\0"),W=Buffer.allocUnsafe(P.length+4+f.length+4+l.length+4+u.length+4+4+g.pub.length+4+N.length+O.length);{let X=0;W.set(P,X+=0),W.writeUInt32BE(f.length,X+=P.length),W.set(f,X+=4),W.writeUInt32BE(l.length,X+=f.length),W.set(l,X+=4),W.writeUInt32BE(u.length,X+=l.length),W.set(u,X+=4),W.writeUInt32BE(1,X+=u.length),W.writeUInt32BE(g.pub.length,X+=4),W.set(g.pub,X+=4),W.writeUInt32BE(N.length,X+=g.pub.length),W.set(N,X+=4),W.set(O,X+=N.length)}{let X=W.base64Slice(0,W.length),G=X.replace(/.{64}/g,`$&
16
+ `);X.length&63&&(G+=`
17
+ `),a+=G}{let X=g.pub.base64Slice(0,g.pub.length);c=`${g.sshName} ${X}${o?` ${o}`:""}`}return a+=`-----END OPENSSH PRIVATE KEY-----
18
+ `,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function Am(){}dd.exports={generateKeyPair:(r,t,e)=>{typeof t=="function"&&(e=t,t=void 0),typeof e!="function"&&(e=Am);let n=ld(r,t);am(...n,(i,s,o)=>{if(i)return e(i);let a;try{a=ud(n[0],s,o,t)}catch(c){return e(c)}e(null,a)})},generateKeyPairSync:(r,t)=>{let e=ld(r,t),{publicKey:n,privateKey:i}=cm(...e);return ud(e[0],n,i,t)}}});var ka=ot((Xy,pd)=>{"use strict";var{AgentProtocol:Em,BaseAgent:_m,createAgent:bm,CygwinAgent:ym,OpenSSHAgent:xm,PageantAgent:Sm}=Lo(),{SSHTTPAgent:wm,SSHTTPSAgent:Im}=od(),{parseKey:Cm}=Lr(),{flagsToString:vm,OPEN_MODE:km,STATUS_CODE:Bm,stringToFlags:Rm}=li();pd.exports={AgentProtocol:Em,BaseAgent:_m,createAgent:bm,Client:ya(),CygwinAgent:ym,HTTPAgent:wm,HTTPSAgent:Im,OpenSSHAgent:xm,PageantAgent:Sm,Server:cd(),utils:{parseKey:Cm,...hd(),sftp:{flagsToString:vm,OPEN_MODE:km,STATUS_CODE:Bm,stringToFlags:Rm}}}});function Ga(r){return r==="1"||r==="true"}function Ya(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function th(){return Ga(process.env.DEV_MODE)||Ga(process.env.RENDER_PERF)}function er(r){let t=th();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=Ya(),n=s=>{let o=Ya()-e;console.log(`[perf][${r}] ${s}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:n,done:(s="done")=>{n(s)}}}var jm=er("HoneyPot");var dr=$t(require("node:path"),1),rh=["/virtual-env-js/.auth"];function ue(r,t){return!t||t.trim()===""?r:t.startsWith("/")?dr.posix.normalize(t):dr.posix.normalize(dr.posix.join(r,t))}function nh(r){let t=r.startsWith("/")?dr.posix.normalize(r):dr.posix.normalize(`/${r}`);return rh.some(e=>t===e||t.startsWith(`${e}/`))}function Oe(r,t,e){if(r!=="root"&&nh(t))throw new Error(`${e}: permission denied: ${t}`)}function ja(r){let e=(r.split("?")[0]?.split("#")[0]??r).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function ih(r,t){let e=Array.from({length:r.length+1},()=>Array(t.length+1).fill(0));for(let n=0;n<=r.length;n+=1)e[n][0]=n;for(let n=0;n<=t.length;n+=1)e[0][n]=n;for(let n=1;n<=r.length;n+=1)for(let i=1;i<=t.length;i+=1){let s=r[n-1]===t[i-1]?0:1;e[n][i]=Math.min(e[n-1][i]+1,e[n][i-1]+1,e[n-1][i-1]+s)}return e[r.length][t.length]}function za(r,t,e){let n=ue(t,e);if(r.exists(n))return n;let i=dr.posix.dirname(n),s=dr.posix.basename(n),o=r.list(i),a=o.filter(f=>f.toLowerCase()===s.toLowerCase());if(a.length===1)return dr.posix.join(i,a[0]);let c=o.filter(f=>ih(f.toLowerCase(),s.toLowerCase())<=1);return c.length===1?dr.posix.join(i,c[0]):n}function Xa(r,t,e){return t.map(n=>{let i=ue(r,n);return e(i).type==="directory"?`${n}/`:n}).join(" ")}function fn(r){return r.packageManager}async function Ja(r,t,e,n,i,s,o){let a={exitCode:0},c=0;for(;c<r.length;){let f=r[c];if(a=await sh(f.pipeline,t,e,n,i,s,o),o.lastExitCode=a.exitCode??0,a.closeSession||a.switchUser)return a;let l=f.op;if(!(!l||l===";")){if(l==="&&"){if((a.exitCode??0)!==0)for(;c<r.length&&r[c]?.op==="&&";)c++}else if(l==="||"&&(a.exitCode??0)===0)for(;c<r.length&&r[c]?.op==="||";)c++}c++}return a}async function sh(r,t,e,n,i,s,o){if(!r.isValid)return{stderr:r.error||"Syntax error",exitCode:1};if(r.commands.length===0)return{exitCode:0};let a=o??{vars:{},lastExitCode:0};return r.commands.length===1?oh(r.commands[0],t,e,n,i,s,a):ah(r.commands,t,e,n,i,s,a)}async function oh(r,t,e,n,i,s,o){let a;if(r.inputFile){let f=ue(i,r.inputFile);try{a=s.vfs.readFile(f)}catch{return{stderr:`${r.inputFile}: No such file or directory`,exitCode:1}}}let c=await Ps(r.name,r.args,t,e,n,i,s,a,o);if(r.outputFile){let f=ue(i,r.outputFile),l=c.stdout||"";try{if(r.appendOutput){let u=(()=>{try{return s.vfs.readFile(f)}catch{return""}})();s.writeFileAsUser(t,f,u+l)}else s.writeFileAsUser(t,f,l);return{...c,stdout:""}}catch{return{...c,stderr:`Failed to write to ${r.outputFile}`,exitCode:1}}}return c}async function ah(r,t,e,n,i,s,o){let a="",c=0;for(let f=0;f<r.length;f++){let l=r[f];if(f===0&&l.inputFile){let h=ue(i,l.inputFile);try{a=s.vfs.readFile(h)}catch{return{stderr:`${l.inputFile}: No such file or directory`,exitCode:1}}}let u=await Ps(l.name,l.args,t,e,n,i,s,a,o);if(c=u.exitCode??0,f===r.length-1&&l.outputFile){let h=ue(i,l.outputFile),g=u.stdout||"";try{if(l.appendOutput){let b=(()=>{try{return s.vfs.readFile(h)}catch{return""}})();s.writeFileAsUser(t,h,b+g)}else s.writeFileAsUser(t,h,g);a=""}catch{return{stderr:`Failed to write to ${l.outputFile}`,exitCode:1}}}else a=u.stdout||"";if(u.stderr&&c!==0)return{stderr:u.stderr,exitCode:c};if(u.closeSession||u.switchUser)return u}return{stdout:a,exitCode:c}}function Za(r){let t=r.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:ch(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function ch(r){let t=fh(r),e=[];for(let n of t){let s={pipeline:{commands:lh(n.text.trim()),isValid:!0}};n.op&&(s.op=n.op),e.push(s)}return e}function fh(r){let t=[],e="",n=0,i=!1,s="",o=0,a=c=>{e.trim()&&t.push({text:e,op:c}),e=""};for(;o<r.length;){let c=r[o],f=r.slice(o,o+2);if((c==='"'||c==="'")&&!i){i=!0,s=c,e+=c,o++;continue}if(i&&c===s){i=!1,e+=c,o++;continue}if(i){e+=c,o++;continue}if(c==="("){n++,e+=c,o++;continue}if(c===")"){n--,e+=c,o++;continue}if(n>0){e+=c,o++;continue}if(f==="&&"){a("&&"),o+=2;continue}if(f==="||"){a("||"),o+=2;continue}if(c===";"){a(";"),o++;continue}e+=c,o++}return a(),t}function lh(r){return uh(r).map(dh)}function uh(r){let t=[],e="",n=!1,i="";for(let o=0;o<r.length;o++){let a=r[o];if((a==='"'||a==="'")&&!n){n=!0,i=a,e+=a;continue}if(n&&a===i){n=!1,e+=a;continue}if(n){e+=a;continue}if(a==="|"&&r[o+1]!=="|"){if(!e.trim())throw new Error("Syntax error near unexpected token '|'");t.push(e.trim()),e=""}else e+=a}let s=e.trim();if(!s&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return s&&t.push(s),t}function dh(r){let t=hh(r);if(t.length===0)return{name:"",args:[]};let e=[],n,i,s=!1,o=0;for(;o<t.length;){let c=t[o];if(c==="<"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after <");n=t[o],o++}else if(c===">>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >>");i=t[o],s=!0,o++}else if(c===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");i=t[o],s=!1,o++}else e.push(c),o++}return{name:(e[0]??"").toLowerCase(),args:e.slice(1),inputFile:n,outputFile:i,appendOutput:s}}function hh(r){let t=[],e="",n=!1,i="",s=0;for(;s<r.length;){let o=r[s],a=r[s+1];if((o==='"'||o==="'")&&!n){n=!0,i=o,s++;continue}if(n&&o===i){n=!1,i="",s++;continue}if(n){e+=o,s++;continue}if(o===" "){e&&(t.push(e),e=""),s++;continue}if((o===">"||o==="<")&&!n){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),s+=2):(t.push(o),s++);continue}e+=o,s++}return e&&t.push(e),t}var ec={name:"adduser",description:"Add a new user",category:"users",params:["<username> <password>"],run:async({authUser:r,shell:t,args:e})=>{if(r!=="root")return{stderr:"adduser: permission denied",exitCode:1};let[n,i]=e;return!n||!i?{stderr:"adduser: usage: adduser <username> <password>",exitCode:1}:(await t.users.addUser(n,i),{stdout:`adduser: user '${n}' created`,exitCode:0})}};function tc(r){return Array.isArray(r)?r:[r]}function Ci(r,t){if(r===t)return{matched:!0,inlineValue:null};let e=`${t}=`;return r.startsWith(e)?{matched:!0,inlineValue:r.slice(e.length)}:{matched:!1,inlineValue:null}}function ph(r,t={}){let e=new Set(t.flags??[]),n=new Set(t.flagsWithValue??[]),i=[],s=!1;for(let o=0;o<r.length;o+=1){let a=r[o];if(s){i.push(a);continue}if(a==="--"){s=!0;continue}let c=!1;for(let f of e){let{matched:l}=Ci(a,f);if(l){c=!0;break}}if(!c){for(let f of n){let l=Ci(a,f);if(l.matched){c=!0,l.inlineValue===null&&o+1<r.length&&(o+=1);break}}c||i.push(a)}}return i}function se(r,t){let e=tc(t);for(let n of r)for(let i of e)if(Ci(n,i).matched)return!0;return!1}function Ht(r,t){let e=tc(t);for(let n=0;n<r.length;n+=1){let i=r[n];for(let s of e){let o=Ci(i,s);if(!o.matched)continue;if(o.inlineValue!==null)return o.inlineValue;let a=r[n+1];return a!==void 0&&a!=="--"?a:!0}}}function tr(r,t,e={}){return ph(r,e)[t]}function Qt(r,t={}){let e=new Set,n=new Map,i=[],s=new Set(t.flags??[]),o=new Set(t.flagsWithValue??[]),a=!1;for(let c=0;c<r.length;c+=1){let f=r[c];if(a){i.push(f);continue}if(f==="--"){a=!0;continue}if(s.has(f)){e.add(f);continue}if(o.has(f)){let u=r[c+1];u&&!u.startsWith("-")?(n.set(f,u),c+=1):n.set(f,"");continue}let l=Array.from(o).find(u=>f.startsWith(`${u}=`));if(l){n.set(l,f.slice(l.length+1));continue}i.push(f)}return{flags:e,flagsWithValues:n,positionals:i}}var rc={name:"alias",description:"Define or display aliases",category:"shell",params:["[name[=value] ...]"],run:({args:r,env:t})=>{if(!t)return{exitCode:0};if(r.length===0)return{stdout:Object.entries(t.vars).filter(([i])=>i.startsWith("__alias_")).map(([i,s])=>`alias ${i.slice(8)}='${s}'`).join(`
19
+ `)||"",exitCode:0};let e=[];for(let n of r){let i=n.indexOf("=");if(i===-1){let s=t.vars[`__alias_${n}`];if(s)e.push(`alias ${n}='${s}'`);else return{stderr:`alias: ${n}: not found`,exitCode:1}}else{let s=n.slice(0,i),o=n.slice(i+1).replace(/^['"]|['"]$/g,"");t.vars[`__alias_${s}`]=o}}return{stdout:e.join(`
20
+ `)||void 0,exitCode:0}}},nc={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:r,env:t})=>{if(!t)return{exitCode:0};if(se(r,["-a"])){for(let e of Object.keys(t.vars))e.startsWith("__alias_")&&delete t.vars[e];return{exitCode:0}}for(let e of r)delete t.vars[`__alias_${e}`];return{exitCode:0}}};function ln(r,t,e){if(r[r.length-1]==="]"&&(r=r.slice(0,-1)),r[0]==="["&&(r=r.slice(1)),r.length===0)return!1;if(r[0]==="!")return!ln(r.slice(1),t,e);let n=r.indexOf("-a");if(n!==-1)return ln(r.slice(0,n),t,e)&&ln(r.slice(n+1),t,e);let i=r.indexOf("-o");if(i!==-1)return ln(r.slice(0,i),t,e)||ln(r.slice(i+1),t,e);if(r.length===2){let[s,o=""]=r,c=(f=>f.startsWith("/")?f:`${e}/${f}`.replace(/\/+/g,"/"))(o);switch(s){case"-e":return t.vfs.exists(c);case"-f":return t.vfs.exists(c)&&t.vfs.stat(c).type==="file";case"-d":return t.vfs.exists(c)&&t.vfs.stat(c).type==="directory";case"-r":return t.vfs.exists(c);case"-w":return t.vfs.exists(c);case"-x":return t.vfs.exists(c)&&!!(t.vfs.stat(c).mode&73);case"-s":return t.vfs.exists(c)&&t.vfs.stat(c).type==="file"&&t.vfs.stat(c).size>0;case"-z":return o.length===0;case"-n":return o.length>0;case"-L":return t.vfs.isSymlink(c)}}if(r.length===3){let[s="",o,a=""]=r,c=Number(s),f=Number(a);switch(o){case"=":case"==":return s===a;case"!=":return s!==a;case"<":return s<a;case">":return s>a;case"-eq":return c===f;case"-ne":return c!==f;case"-lt":return c<f;case"-le":return c<=f;case"-gt":return c>f;case"-ge":return c>=f}}return r.length===1?(r[0]??"").length>0:!1}var ic={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:r,shell:t,cwd:e})=>{try{return{exitCode:ln([...r],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var sc={name:"source",aliases:["."],description:"Execute commands from a file in the current shell environment",category:"shell",params:["<file> [args...]"],run:async({args:r,authUser:t,hostname:e,cwd:n,shell:i,env:s})=>{let o=r[0];if(!o)return{stderr:"source: missing filename",exitCode:1};let a=ue(n,o);if(!i.vfs.exists(a))return{stderr:`source: ${o}: No such file or directory`,exitCode:1};let c=i.vfs.readFile(a),f=0;for(let l of c.split(`
21
+ `)){let u=l.trim();if(!u||u.startsWith("#"))continue;let h=await St(u,t,e,"shell",n,i,void 0,s);if(f=h.exitCode??0,h.closeSession||h.switchUser)return h}return{exitCode:f}}};var oc={name:"history",description:"Display command history",category:"shell",params:["[n]"],run:({args:r,shell:t})=>{let e="/virtual-env-js/.bash_history";if(!t.vfs.exists(e))return{stdout:"",exitCode:0};let i=t.vfs.readFile(e).split(`
22
+ `).filter(Boolean),s=r[0],o=s?parseInt(s,10):null,a=o&&!Number.isNaN(o)?i.slice(-o):i,c=i.length-a.length+1;return{stdout:a.map((l,u)=>`${String(c+u).padStart(5)} ${l}`).join(`
23
+ `),exitCode:0}}};var ac={name:"apt",aliases:["apt-get"],description:"Package manager",category:"system",params:["<install|remove|update|upgrade|search|show|list> [pkg...]"],run:({args:r,shell:t,authUser:e})=>{let n=fn(t);if(!n)return{stderr:"apt: package manager not initialised",exitCode:1};let i=r[0]?.toLowerCase(),s=r.slice(1),o=se(s,["-q","--quiet","-qq"]),a=se(s,["--purge"]),c=s.filter(l=>!l.startsWith("-"));if(["install","remove","purge","upgrade","update"].includes(i??"")&&e!=="root")return{stderr:`E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
24
+ E: Unable to acquire the dpkg frontend lock, are you root?`,exitCode:100};switch(i){case"install":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:l,exitCode:u}=n.install(c,{quiet:o});return{stdout:l||void 0,exitCode:u}}case"remove":case"purge":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:l,exitCode:u}=n.remove(c,{purge:i==="purge"||a,quiet:o});return{stdout:l||void 0,exitCode:u}}case"update":return{stdout:["Hit:1 fortune://packages.fortune.local aurora InRelease","Hit:2 fortune://security.fortune.local aurora-security InRelease","Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","All packages are up to date."].join(`
25
+ `),exitCode:0};case"upgrade":return{stdout:["Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","Calculating upgrade... Done","0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded."].join(`
26
+ `),exitCode:0};case"search":{let l=c[0];if(!l)return{stderr:"apt: search requires a term",exitCode:1};let u=n.search(l);return u.length===0?{stdout:`Sorting... Done
27
+ Full Text Search... Done
28
+ (no results)`,exitCode:0}:{stdout:`Sorting... Done
29
+ Full Text Search... Done
30
+ ${u.map(g=>`${g.name}/${g.section??"misc"} ${g.version} amd64
31
+ ${g.shortDesc??g.description}`).join(`
32
+ `)}`,exitCode:0}}case"show":{let l=c[0];if(!l)return{stderr:"apt: show requires a package name",exitCode:1};let u=n.show(l);return u?{stdout:u,exitCode:0}:{stderr:`N: Unable to locate package ${l}`,exitCode:100}}case"list":{if(se(s,["--installed"])){let g=n.listInstalled();return g.length===0?{stdout:`Listing... Done
33
+ (no packages installed)`,exitCode:0}:{stdout:`Listing... Done
34
+ ${g.map(_=>`${_.name}/${_.section} ${_.version} ${_.architecture} [installed]`).join(`
35
+ `)}`,exitCode:0}}return{stdout:`Listing... Done
36
+ ${n.listAvailable().map(g=>`${g.name}/${g.section??"misc"} ${g.version} amd64`).join(`
37
+ `)}`,exitCode:0}}default:return{stdout:["Usage: apt [options] command","","Commands:"," install <pkg...> Install packages"," remove <pkg...> Remove packages"," purge <pkg...> Remove packages and config files"," update Refresh package index"," upgrade Upgrade all packages"," search <term> Search in package descriptions"," show <pkg> Show package details"," list [--installed] List packages"].join(`
38
+ `),exitCode:0}}}},cc={name:"apt-cache",description:"Query the package cache",category:"system",params:["<search|show|policy> [pkg]"],run:({args:r,shell:t})=>{let e=fn(t);if(!e)return{stderr:"apt-cache: package manager not initialised",exitCode:1};let n=r[0]?.toLowerCase(),i=r[1];switch(n){case"search":return i?{stdout:e.search(i).map(o=>`${o.name} - ${o.shortDesc??o.description}`).join(`
39
+ `)||"(no results)",exitCode:0}:{stderr:"Need a search term",exitCode:1};case"show":{if(!i)return{stderr:"Need a package name",exitCode:1};let s=e.show(i);return s?{stdout:s,exitCode:0}:{stderr:`N: Unable to locate package ${i}`,exitCode:100}}case"policy":{if(!i)return{stderr:"Need a package name",exitCode:1};let s=e.findInRegistry(i);if(!s)return{stderr:`N: Unable to locate package ${i}`,exitCode:100};let o=e.isInstalled(i);return{stdout:[`${i}:`,` Installed: ${o?s.version:"(none)"}`,` Candidate: ${s.version}`," Version table:",` ${s.version} 500`," 500 fortune://packages.fortune.local aurora/main amd64 Packages"].join(`
40
+ `),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${n??""}'`,exitCode:1}}}};var fc={name:"awk",description:"Pattern scanning and processing language (minimal)",category:"text",params:["[-F <sep>] '<program>' [file]"],run:({args:r,stdin:t})=>{let e=Ht(r,["-F"])??" ",n=r.find(c=>!c.startsWith("-")&&c!==e);if(!n)return{stderr:"awk: no program",exitCode:1};let i=n.match(/^\{?\s*print\s+([^}]+)\s*\}?$/);if(!i)return{stderr:`awk: unsupported program: ${n}`,exitCode:1};let s=i[1].split(/\s*,\s*/).map(c=>c.trim());return{stdout:(t??"").split(`
41
+ `).filter(Boolean).map(c=>{let f=c.split(e===" "?/\s+/:e);return s.map(l=>{if(l==="$0")return c;let u=parseInt(l.replace("$",""),10);return Number.isNaN(u)?l.replace(/"/g,""):f[u-1]??""}).join(e===" "?" ":e)}).join(`
42
+ `),exitCode:0}}};var lc={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:r,stdin:t})=>{let e=se(r,["-d","--decode"]),n=t??"";if(e)try{return{stdout:Buffer.from(n.trim(),"base64").toString("utf8"),exitCode:0}}catch{return{stderr:"base64: invalid input",exitCode:1}}return{stdout:Buffer.from(n).toString("base64"),exitCode:0}}};var uc={name:"cat",description:"Concatenate and print files",category:"files",params:["[-n] [-b] <file...>"],run:({authUser:r,shell:t,cwd:e,args:n,stdin:i})=>{let s=se(n,["-n","--number"]),o=se(n,["-b","--number-nonblank"]),a=n.filter(h=>!h.startsWith("-"));if(a.length===0&&i!==void 0)return{stdout:i,exitCode:0};if(a.length===0)return{stderr:"cat: missing file operand",exitCode:1};let c=[];for(let h of a){let g=za(t.vfs,e,h);Oe(r,g,"cat"),c.push(t.vfs.readFile(g))}let f=c.join("");if(!s&&!o)return{stdout:f,exitCode:0};let l=1;return{stdout:f.split(`
43
+ `).map(h=>o&&h.trim()===""?h:`${String(l++).padStart(6)} ${h}`).join(`
44
+ `),exitCode:0}}};var dc={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:r,shell:t,cwd:e,args:n,mode:i})=>{let s=ue(e,n[0]??"/virtual-env-js");return Oe(r,s,"cd"),t.vfs.stat(s).type!=="directory"?{stderr:`cd: not a directory: ${s}`,exitCode:1}:i==="exec"?{exitCode:0}:{nextCwd:s,exitCode:0}}};function gh(r,t){let e=/^([ugoa]*)([+\-=])([rwx]*)$/,n=t.split(","),i=r;for(let s of n){let o=s.trim().match(e);if(!o)return null;let[,a="a",c,f=""]=o,l=a===""||a==="a"?["u","g","o"]:a.split(""),u={u:{r:256,w:128,x:64},g:{r:32,w:16,x:8},o:{r:4,w:2,x:1}};for(let h of l)for(let g of f.split("")){let b=u[h]?.[g];if(b!==void 0){if(c==="+")i|=b;else if(c==="-")i&=~b;else if(c==="="){let _=Object.values(u[h]??{}).reduce((x,S)=>x|S,0);i=i&~_|b}}}}return i}var hc={name:"chmod",description:"Change file permissions",category:"files",params:["<mode> <file>"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let[i,s]=n;if(!i||!s)return{stderr:"chmod: missing operand",exitCode:1};let o=ue(e,s);try{if(Oe(r,o,"chmod"),!t.vfs.exists(o))return{stderr:`chmod: ${s}: No such file or directory`,exitCode:1};let a,c=parseInt(i,8);if(!Number.isNaN(c)&&/^[0-7]+$/.test(i))a=c;else{let f=t.vfs.stat(o).mode,l=gh(f,i);if(l===null)return{stderr:`chmod: invalid mode: ${i}`,exitCode:1};a=l}return t.vfs.chmod(o,a),{exitCode:0}}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}};var pc={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var gc={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let i=se(n,["-r","-R","--recursive"]),s=n.filter(l=>!l.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let c=ue(e,o),f=ue(e,a);try{if(Oe(r,c,"cp"),Oe(r,f,"cp"),!t.vfs.exists(c))return{stderr:`cp: ${o}: No such file or directory`,exitCode:1};if(t.vfs.stat(c).type==="directory"){if(!i)return{stderr:`cp: ${o}: is a directory (use -r)`,exitCode:1};let u=(g,b)=>{t.vfs.mkdir(b,493);for(let _ of t.vfs.list(g)){let x=`${g}/${_}`,S=`${b}/${_}`;if(t.vfs.stat(x).type==="directory")u(x,S);else{let O=t.vfs.readFileRaw(x);t.writeFileAsUser(r,S,O)}}},h=t.vfs.exists(f)&&t.vfs.stat(f).type==="directory"?`${f}/${o.split("/").pop()}`:f;u(c,h)}else{let u=t.vfs.exists(f)&&t.vfs.stat(f).type==="directory"?`${f}/${o.split("/").pop()}`:f,h=t.vfs.readFileRaw(c);t.writeFileAsUser(r,u,h)}return{exitCode:0}}catch(l){return{stderr:`cp: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};var mc={name:"curl",description:"Transfer data from or to a server (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:r,cwd:t,args:e,shell:n})=>{let{flagsWithValues:i,positionals:s}=Qt(e,{flagsWithValue:["-o","--output","-X","--request","-d","--data","-H","--header","-u","--user"]});if(se(e,["--help","-h"]))return{stdout:["Usage: curl [options] <url>"," -o, --output <file> Write to file"," -X, --request <method> HTTP method"," -d, --data <data> POST data"," -H, --header <hdr> Extra header"," -s, --silent Silent mode"," -I, --head Fetch headers only"," -L, --location Follow redirects"," -v, --verbose Verbose"].join(`
45
+ `),exitCode:0};let o=s[0];if(!o)return{stderr:"curl: no URL specified",exitCode:1};let a=i.get("-o")??i.get("--output")??null,c=(i.get("-X")??i.get("--request")??"GET").toUpperCase(),f=i.get("-d")??i.get("--data")??null,l=i.get("-H")??i.get("--header")??null,u=se(e,["-s","--silent"]),h=se(e,["-I","--head"]),g=se(e,["-L","--location"]),b=se(e,["-v","--verbose"]),_={"User-Agent":"curl/7.88.1"};if(l){let W=l.indexOf(":");W!==-1&&(_[l.slice(0,W).trim()]=l.slice(W+1).trim())}let x=f&&c==="GET"?"POST":c,S={method:x,headers:_,redirect:g?"follow":"manual"};f&&(_["Content-Type"]??="application/x-www-form-urlencoded",S.body=f);let N=[];b&&(N.push(`* Trying ${o}...`,"* Connected"),N.push(`> ${x} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let O;try{O=await fetch(o,S)}catch(W){return{stderr:`curl: (6) Could not resolve host: ${W instanceof Error?W.message:String(W)}`,exitCode:6}}if(b&&N.push(`< HTTP/1.1 ${O.status} ${O.statusText}`),h){let W=[`HTTP/1.1 ${O.status} ${O.statusText}`];for(let[X,G]of O.headers.entries())W.push(`${X}: ${G}`);return{stdout:`${W.join(`\r
46
+ `)}\r
47
+ `,exitCode:0}}let P;try{P=await O.text()}catch{return{stderr:"curl: failed to read response body",exitCode:1}}if(a){let W=ue(t,a);return Oe(r,W,"curl"),n.writeFileAsUser(r,W,P),u||N.push(` % Total % Received
48
+ 100 ${P.length} 100 ${P.length}`),{stderr:N.join(`
49
+ `)||void 0,exitCode:O.ok?0:22}}return{stdout:P,stderr:N.length>0?N.join(`
50
+ `):void 0,exitCode:O.ok?0:22}}};var Ac={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:r,stdin:t})=>{let e=Ht(r,["-d"])??" ",i=(Ht(r,["-f"])??"1").split(",").map(a=>{let[c,f]=a.split("-").map(Number);return f!==void 0?{from:(c??1)-1,to:f-1}:{from:(c??1)-1,to:(c??1)-1}});return{stdout:(t??"").split(`
51
+ `).map(a=>{let c=a.split(e),f=[];for(let l of i)for(let u=l.from;u<=Math.min(l.to,c.length-1);u++)f.push(c[u]??"");return f.join(e)}).join(`
52
+ `),exitCode:0}}};var Ec={name:"date",description:"Print current date and time",category:"system",params:["[+format]"],run:({args:r})=>{let t=new Date,e=r[0];return e?.startsWith("+")?{stdout:e.slice(1).replace("%Y",String(t.getFullYear())).replace("%m",String(t.getMonth()+1).padStart(2,"0")).replace("%d",String(t.getDate()).padStart(2,"0")).replace("%H",String(t.getHours()).padStart(2,"0")).replace("%M",String(t.getMinutes()).padStart(2,"0")).replace("%S",String(t.getSeconds()).padStart(2,"0")).replace("%s",String(Math.floor(t.getTime()/1e3))),exitCode:0}:{stdout:t.toString(),exitCode:0}}};var _c={name:"deluser",description:"Delete a user",category:"users",params:["<username>"],run:async({authUser:r,args:t,shell:e})=>{if(r!=="root")return{stderr:"deluser: permission denied",exitCode:1};let[n]=t;return n?(await e.users.deleteUser(n),{stdout:`deluser: user '${n}' deleted`,exitCode:0}):{stderr:"deluser: usage: deluser <username>",exitCode:1}}};var bc={name:"df",description:"Report filesystem disk space usage",category:"system",params:["[-h]"],run:({shell:r})=>{let e=(r.vfs.getUsageBytes()/1024).toFixed(0),n="1048576",i=String(Number(n)-Number(e)),s=Math.round(Number(e)/Number(n)*100),o="Filesystem 1K-blocks Used Available Use% Mounted on",a=`virtual-fs ${n.padStart(9)} ${e.padStart(7)} ${i.padStart(9)} ${s}% /`;return{stdout:`${o}
53
+ ${a}`,exitCode:0}}};var yc={name:"diff",description:"Compare files line by line",category:"text",params:["<file1> <file2>"],run:({shell:r,cwd:t,args:e})=>{let[n,i]=e;if(!n||!i)return{stderr:"diff: missing operand",exitCode:1};let s=ue(t,n),o=ue(t,i),a,c;try{a=r.vfs.readFile(s).split(`
54
+ `)}catch{return{stderr:`diff: ${n}: No such file or directory`,exitCode:2}}try{c=r.vfs.readFile(o).split(`
55
+ `)}catch{return{stderr:`diff: ${i}: No such file or directory`,exitCode:2}}let f=[],l=Math.max(a.length,c.length);for(let u=0;u<l;u++){let h=a[u],g=c[u];h!==g&&(h!==void 0&&f.push(`< ${h}`),g!==void 0&&f.push(`> ${g}`))}return{stdout:f.join(`
56
+ `),exitCode:f.length>0?1:0}}};var xc={name:"dpkg",description:"Debian package manager low-level tool",category:"system",params:["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"],run:({args:r,authUser:t,shell:e})=>{let n=fn(e);if(!n)return{stderr:"dpkg: package manager not initialised",exitCode:1};let i=se(r,["-l","--list"]),s=se(r,["-s","--status"]),o=se(r,["-L","--listfiles"]),a=se(r,["-r","--remove"]),c=se(r,["-P","--purge"]),{positionals:f}=Qt(r,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(i){let l=n.listInstalled();if(l.length===0)return{stdout:["Desired=Unknown/Install/Remove/Purge/Hold","|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend","|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)","||/ Name Version Architecture Description","+++-==============-===============-============-========================================","(no packages installed)"].join(`
57
+ `),exitCode:0};let u=["Desired=Unknown/Install/Remove/Purge/Hold","|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend","|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)","||/ Name Version Architecture Description","+++-==============-===============-============-========================================"],h=l.map(g=>{let b=g.name.padEnd(14).slice(0,14),_=g.version.padEnd(15).slice(0,15),x=g.architecture.padEnd(12).slice(0,12),S=(g.description||"").slice(0,40);return`ii ${b} ${_} ${x} ${S}`});return{stdout:[...u,...h].join(`
58
+ `),exitCode:0}}if(s){let l=f[0];if(!l)return{stderr:"dpkg: -s needs a package name",exitCode:1};let u=n.show(l);return u?{stdout:u,exitCode:0}:{stderr:`dpkg-query: package '${l}' is not installed and no information is available`,exitCode:1}}if(o){let l=f[0];if(!l)return{stderr:"dpkg: -L needs a package name",exitCode:1};let u=n.listInstalled().find(h=>h.name===l);return u?u.files.length===0?{stdout:"/.keep",exitCode:0}:{stdout:u.files.join(`
59
+ `),exitCode:0}:{stderr:`dpkg-query: package '${l}' is not installed`,exitCode:1}}if(a||c){if(t!=="root")return{stderr:"dpkg: error: requested operation requires superuser privilege",exitCode:2};if(f.length===0)return{stderr:"dpkg: error: need an action option",exitCode:2};let{output:l,exitCode:u}=n.remove(f,{purge:c});return{stdout:l||void 0,exitCode:u}}return{stdout:["Usage: dpkg [<option>...] <command>","","Commands:"," -l, --list List packages matching given pattern"," -s, --status <pkg>... Report status of specified package"," -L, --listfiles <pkg>... List files owned by package"," -r, --remove <pkg>... Remove <pkg> but leave its configuration"," -P, --purge <pkg>... Remove <pkg> and its configuration"].join(`
60
+ `),exitCode:0}}},Sc={name:"dpkg-query",description:"Show information about installed packages",category:"system",params:["-W [pkg] | -l [pattern]"],run:({args:r,shell:t})=>{let e=fn(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let n=se(r,["-l"]),i=se(r,["-W","--show"]),{positionals:s}=Qt(r,{flags:["-l","-W","--show"]});if(n||i){let o=e.listInstalled(),a=s[0],c=a?o.filter(l=>l.name.includes(a)):o;return i?{stdout:c.map(l=>`${l.name} ${l.version}`).join(`
61
+ `),exitCode:0}:{stdout:c.map(l=>{let u=l.name.padEnd(14).slice(0,14),h=l.version.padEnd(15).slice(0,15);return`ii ${u} ${h} amd64 ${(l.description||"").slice(0,40)}`}).join(`
62
+ `)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var wc={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:r,cwd:t,args:e})=>{let n=se(e,["-h"]),i=se(e,["-s"]),s=e.find(l=>!l.startsWith("-"))??".",o=ue(t,s),a=l=>n?`${(l/1024).toFixed(1)}K`:String(Math.ceil(l/1024));if(!r.vfs.exists(o))return{stderr:`du: ${s}: No such file or directory`,exitCode:1};if(i||r.vfs.stat(o).type==="file")return{stdout:`${a(r.vfs.getUsageBytes(o))} ${s}`,exitCode:0};let c=[],f=(l,u)=>{let h=0;for(let g of r.vfs.list(l)){let b=`${l}/${g}`,_=`${u}/${g}`,x=r.vfs.stat(b);x.type==="directory"?h+=f(b,_):(h+=x.size,i||c.push(`${a(x.size)} ${_}`))}return c.push(`${a(h)} ${u}`),h};return f(o,s),{stdout:c.join(`
63
+ `),exitCode:0}}};function mh(r){return r.replace(/\\n/g,`
64
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\a/g,"\x07").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\v/g,"\v").replace(/\\0(\d{1,3})/g,(t,e)=>String.fromCharCode(parseInt(e,8)))}var Ic={name:"echo",description:"Display text",category:"shell",params:["[-n] [-e] [text...]"],run:({args:r,stdin:t,env:e})=>{let{flags:n,positionals:i}=Qt(r,{flags:["-n","-e","-E"]}),s=n.has("-n"),o=n.has("-e"),c=(i.length>0?i.join(" "):t??"").replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g,(l,u)=>e?.vars[u]??""),f=o?mh(c):c;return{stdout:s?f:`${f}
65
+ `,exitCode:0}}};var Cc={name:"env",description:"Print environment variables",category:"shell",params:[],run:({env:r,authUser:t})=>{let e={...r.vars,USER:t,HOME:`/home/${t}`};return{stdout:Object.entries(e).map(([n,i])=>`${n}=${i}`).join(`
66
+ `),exitCode:0}}};var vc={name:"exit",aliases:["bye"],params:[],run:()=>({closeSession:!0,exitCode:0})};var kc={name:"export",description:"Set shell environment variable",category:"shell",params:["[VAR=value]"],run:({args:r,env:t})=>{if(r.length===0)return{stdout:Object.entries(t.vars).map(([n,i])=>`declare -x ${n}="${i}"`).join(`
67
+ `),exitCode:0};for(let e of r)if(e.includes("=")){let n=e.indexOf("="),i=e.slice(0,n),s=e.slice(n+1);t.vars[i]=s}return{exitCode:0}}};var Bc={name:"find",description:"Search for files",category:"files",params:["[path] [-name <pattern>] [-type f|d]"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let i=Ht(n,["-name"]),s=Ht(n,["-type"]),a=n.filter(h=>!h.startsWith("-")&&h!==i&&h!==s)[0]??".",c=ue(e,a);try{if(Oe(r,c,"find"),!t.vfs.exists(c))return{stderr:`find: ${a}: No such file or directory`,exitCode:1}}catch(h){return{stderr:`find: ${h instanceof Error?h.message:String(h)}`,exitCode:1}}let f=i?new RegExp(`^${i.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,l=[],u=(h,g)=>{let b=t.vfs.stat(h),_=!s||s==="f"&&b.type==="file"||s==="d"&&b.type==="directory",x=!f||f.test(h.split("/").pop()??"");if(_&&x&&l.push(g),b.type==="directory")for(let S of t.vfs.list(h)){let N=`${h}/${S}`,O=`${g}/${S}`;u(N,O)}};return u(c,a),{stdout:l.join(`
68
+ `),exitCode:0}}};var vi=$t(require("node:os"),1);var Rc={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:r})=>{let t=se(r,["-h","--human"]),e=se(r,["-m"]),n=se(r,["-g"]),i=vi.totalmem(),s=vi.freemem(),o=i-s,a=Math.floor(i*.02),c=Math.floor(i*.05),f=Math.floor(s*.95),l=Math.floor(i*.5),u=_=>t?_>=1024*1024*1024?`${(_/(1024*1024*1024)).toFixed(1)}G`:_>=1024*1024?`${(_/(1024*1024)).toFixed(1)}M`:`${(_/1024).toFixed(1)}K`:String(Math.floor(n?_/(1024*1024*1024):e?_/(1024*1024):_/1024)),h=" total used free shared buff/cache available",g=`Mem: ${u(i).padStart(12)} ${u(o).padStart(11)} ${u(s).padStart(11)} ${u(a).padStart(11)} ${u(c).padStart(11)} ${u(f).padStart(11)}`,b=`Swap: ${u(l).padStart(12)} ${u(0).padStart(11)} ${u(l).padStart(11)}`;return{stdout:[h,g,b].join(`
69
+ `),exitCode:0}}};var Nc={name:"grep",description:"Search text patterns",category:"text",params:["[-i] [-v] [-n] [-r] <pattern> [file...]"],run:({authUser:r,shell:t,cwd:e,args:n,stdin:i})=>{let{flags:s,positionals:o}=Qt(n,{flags:["-i","-v","-n","-r"]}),a=s.has("-i"),c=s.has("-v"),f=s.has("-n"),l=s.has("-r"),u=o[0],h=o.slice(1);if(!u)return{stderr:"grep: no pattern specified",exitCode:1};let g;try{let S=a?"mi":"m";g=new RegExp(u,S)}catch{return{stderr:`grep: invalid regex: ${u}`,exitCode:1}}let b=(S,N="")=>{let O=S.split(`
70
+ `),P=[];for(let W=0;W<O.length;W++){let X=O[W]??"",G=g.test(X);if(c?!G:G){let I=f?`${W+1}:`:"";P.push(`${N}${I}${X}`)}}return P},_=S=>{if(!t.vfs.exists(S))return[];if(t.vfs.stat(S).type==="file")return[S];if(!l)return[];let O=[],P=W=>{for(let X of t.vfs.list(W)){let G=`${W}/${X}`;t.vfs.stat(G).type==="file"?O.push(G):P(G)}};return P(S),O},x=[];if(h.length===0){if(!i)return{stdout:"",exitCode:1};x.push(...b(i))}else{let S=h.flatMap(N=>{let O=ue(e,N);return _(O).map(P=>({file:N,path:P}))});for(let{file:N,path:O}of S)try{Oe(r,O,"grep");let P=t.vfs.readFile(O),W=S.length>1?`${N}:`:"";x.push(...b(P,W))}catch{return{stderr:`grep: ${N}: No such file or directory`,exitCode:1}}}return{stdout:x.length>0?x.join(`
71
+ `):"",exitCode:x.length>0?0:1}}};var Pc={name:"groups",description:"Print group memberships",category:"system",params:["[user]"],run:({authUser:r,shell:t,args:e})=>{let n=e[0]??r;return{stdout:t.users.isSudoer(n)?`${n} sudo root`:n,exitCode:0}}};var Tc={name:"gzip",description:"Compress files",category:"archive",params:["<file>"],run:({shell:r,cwd:t,args:e})=>{let n=e[0];if(!n)return{stderr:"gzip: no file specified",exitCode:1};let i=ue(t,n);try{return r.vfs.compressFile(i),{exitCode:0}}catch{return{stderr:`gzip: ${n}: No such file or directory`,exitCode:1}}}},Lc={name:"gunzip",description:"Decompress files",category:"archive",params:["<file>"],aliases:["zcat"],run:({shell:r,cwd:t,args:e})=>{let n=e[0];if(!n)return{stderr:"gunzip: no file specified",exitCode:1};let i=ue(t,n);try{return r.vfs.decompressFile(i),{exitCode:0}}catch{return{stderr:`gunzip: ${n}: No such file or directory`,exitCode:1}}}};var Uc={name:"head",description:"Output first lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:r,shell:t,cwd:e,args:n,stdin:i})=>{let s=Ht(n,["-n"]),o=typeof s=="string"?parseInt(s,10):10,a=n.filter(l=>!l.startsWith("-")&&l!==s),c=l=>l.split(`
72
+ `).slice(0,o).join(`
73
+ `);if(a.length===0)return{stdout:c(i??""),exitCode:0};let f=[];for(let l of a){let u=ue(e,l);try{Oe(r,u,"head"),f.push(c(t.vfs.readFile(u)))}catch{return{stderr:`head: ${l}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
74
+ `),exitCode:0}}};var Dc=["navigation","files","text","archive","system","network","shell","users","misc"],Ah={navigation:"Navigation",files:"Files & Filesystem",text:"Text Processing",archive:"Archive & Compression",system:"System",network:"Network",shell:"Shell",users:"Users & Permissions",misc:"Miscellaneous"};function Eh(r,t){return r.length>=t?r:r+" ".repeat(t-r.length)}function Oc(r){return{name:"help",description:"Display this help message",category:"shell",params:["[command]"],run:({args:t})=>{let e=Mc();if(t[0]){let o=e.find(f=>f.name===t[0]||f.aliases?.includes(t[0]));if(!o)return{stderr:`help: no help for '${t[0]}'`,exitCode:1};let a=o.aliases?.length?` aliases: ${o.aliases.join(", ")}
75
+ `:"",c=o.params.map(f=>` ${o.name} ${f}`).join(`
76
+ `);return{stdout:[`\x1B[1m${o.name}\x1B[0m \u2014 ${o.description??"no description"}`,a,"Usage:",c||` ${o.name}`].filter(Boolean).join(`
77
+ `),exitCode:0}}let n={};for(let o of e){let a=o.category??"misc";n[a]||(n[a]=[]),n[a].push(o)}let i=[];i.push("\x1B[1mAvailable commands\x1B[0m"),i.push("");let s=[...Dc.filter(o=>n[o]),...Object.keys(n).filter(o=>!Dc.includes(o))];for(let o of s){let a=n[o];if(!a||a.length===0)continue;i.push(`\x1B[33m${Ah[o]??o}\x1B[0m`);let c=[...a].sort((f,l)=>f.name.localeCompare(l.name));for(let f of c)i.push(` \x1B[36m${Eh(f.name,14)}\x1B[0m ${f.description??""}`)}return{stdout:i.join(`
78
+ `),exitCode:0}}}}var Fc={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:r})=>({stdout:r,exitCode:0})};var $c={name:"htop",description:"System monitor",category:"system",params:[],run:({mode:r})=>r==="exec"?{stderr:"htop: interactive terminal required",exitCode:1}:{openHtop:!0,exitCode:0}};var Hc={name:"id",description:"Print user identity",category:"system",params:["[user]"],run:({authUser:r,shell:t,args:e})=>{let n=e[0]??r,i=n==="root"?0:1e3,s=i,a=t.users.isSudoer(n)?`${s}(${n}),0(root)`:`${s}(${n})`;return{stdout:`uid=${i}(${n}) gid=${s}(${n}) groups=${a}`,exitCode:0}}};var Qc={name:"kill",description:"Send signal to process",category:"system",params:["[-9] <pid>"],run:({args:r})=>r.find(e=>!e.startsWith("-"))?{stdout:"",exitCode:0}:{stderr:"kill: no pid specified",exitCode:1}};var Wc={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let i=se(n,["-s","--symbolic"]),s=n.filter(l=>!l.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let c=ue(e,a),f=i?o:ue(e,o);try{if(Oe(r,c,"ln"),i)t.vfs.symlink(f,c);else{let l=ue(e,o);if(Oe(r,l,"ln"),!t.vfs.exists(l))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let u=t.vfs.readFile(l);t.writeFileAsUser(r,c,u)}return{exitCode:0}}catch(l){return{stderr:`ln: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};function _h(r,t){let e=t?"d":"-",i=[[256,"r"],[128,"w"],[64,"x"],[32,"r"],[16,"w"],[8,"x"],[4,"r"],[2,"w"],[1,"x"]].map(([s,o])=>r&s?o:"-").join("");return`${e}${i}`}function bh(r){return r.toISOString().replace("T"," ").slice(0,16)}var qc={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let i=se(n,["-l","--long"]),s=se(n,["-a","--all"]),o=tr(n,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=ue(e,o??e);Oe(r,a,"ls");let c=t.vfs.list(a).filter(l=>s||!l.startsWith("."));return{stdout:i?c.map(l=>{let u=ue(a,l),h=t.vfs.stat(u),g=h.type==="file"?h.size:h.childrenCount;return`${_h(h.mode,h.type==="directory")} 1 ${g} ${bh(h.updatedAt)} ${l}${h.type==="directory"?"/":""}`}).join(`
79
+ `):Xa(a,c,l=>t.vfs.stat(l)),exitCode:0}}};var Kc={name:"lsb_release",description:"Print distribution-specific information",category:"system",params:["[-a] [-i] [-d] [-r] [-c]"],run:({args:r,shell:t})=>{let e=t.properties?.os??"Fortune GNU/Linux x64",n="aurora",i="1.0";try{let u=t.vfs.readFile("/etc/os-release");for(let h of u.split(`
80
+ `))h.startsWith("PRETTY_NAME=")&&(e=h.slice(12).replace(/^"|"$/g,"").trim()),h.startsWith("VERSION_CODENAME=")&&(n=h.slice(17).trim()),h.startsWith("VERSION_ID=")&&(i=h.slice(11).replace(/^"|"$/g,"").trim())}catch{}let s=se(r,["-a","--all"]),o=se(r,["-i","--id"]),a=se(r,["-d","--description"]),c=se(r,["-r","--release"]),f=se(r,["-c","--codename"]);if(s||r.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${e}`,`Release: ${i}`,`Codename: ${n}`].join(`
81
+ `),exitCode:0};let l=[];return o&&l.push("Distributor ID: Fortune"),a&&l.push(`Description: ${e}`),c&&l.push(`Release: ${i}`),f&&l.push(`Codename: ${n}`),{stdout:l.join(`
82
+ `),exitCode:0}}};var yh={ls:`LS(1) User Commands LS(1)
83
+
84
+ NAME
85
+ ls - list directory contents
86
+
87
+ SYNOPSIS
88
+ ls [OPTION]... [FILE]...
89
+
90
+ DESCRIPTION
91
+ List information about the FILEs (the current directory by default).
92
+
93
+ OPTIONS
94
+ -l use a long listing format
95
+ -a do not ignore entries starting with .
96
+ -h with -l, print human readable sizes
97
+ -r reverse order while sorting
98
+ -t sort by modification time
99
+
100
+ AUTHOR
101
+ Written by Richard M. Stallman and David MacKenzie.`,cat:`CAT(1) User Commands CAT(1)
102
+
103
+ NAME
104
+ cat - concatenate files and print on the standard output
105
+
106
+ SYNOPSIS
107
+ cat [OPTION]... [FILE]...
108
+
109
+ DESCRIPTION
110
+ Concatenate FILE(s) to standard output.
111
+
112
+ OPTIONS
113
+ -n, --number number all output lines
114
+ -b, --number-nonblank number nonempty output lines`,grep:`GREP(1) User Commands GREP(1)
115
+
116
+ NAME
117
+ grep, egrep, fgrep - print lines that match patterns
118
+
119
+ SYNOPSIS
120
+ grep [OPTION]... PATTERNS [FILE]...
121
+
122
+ OPTIONS
123
+ -i, --ignore-case ignore case distinctions in patterns and data
124
+ -v, --invert-match select non-matching lines
125
+ -n, --line-number print line number with output lines
126
+ -r, --recursive read all files under each directory, recursively`,apt:`APT(8) APT APT(8)
127
+
128
+ NAME
129
+ apt - command-line interface
130
+
131
+ SYNOPSIS
132
+ apt [options] command
133
+
134
+ DESCRIPTION
135
+ apt provides a high-level commandline interface for the package
136
+ management system.
137
+
138
+ COMMANDS
139
+ install pkg... Install packages
140
+ remove pkg... Remove packages
141
+ update Download package information
142
+ upgrade Upgrade installed packages
143
+ search term Search in package descriptions
144
+ show pkg Show package information
145
+ list List packages`,ssh:`SSH(1) OpenSSH SSH(1)
146
+
147
+ NAME
148
+ ssh - OpenSSH remote login client
149
+
150
+ SYNOPSIS
151
+ ssh [-p port] [user@]hostname [command]
152
+
153
+ DESCRIPTION
154
+ ssh (SSH client) is a program for logging into a remote machine and
155
+ for executing commands on a remote machine.`,curl:`CURL(1) User Commands CURL(1)
156
+
157
+ NAME
158
+ curl - transfer a URL
159
+
160
+ SYNOPSIS
161
+ curl [options / URLs]
162
+
163
+ DESCRIPTION
164
+ curl is a tool for transferring data with URL syntax.
165
+
166
+ OPTIONS
167
+ -o, --output <file> Write output to <file>
168
+ -X, --request <method> Specify request method
169
+ -d, --data <data> HTTP POST data
170
+ -H, --header <header> Pass custom header
171
+ -s, --silent Silent mode
172
+ -I, --head Show document info only
173
+ -L, --location Follow redirects
174
+ -v, --verbose Make the operation more talkative`,chmod:`CHMOD(1) User Commands CHMOD(1)
175
+
176
+ NAME
177
+ chmod - change file mode bits
178
+
179
+ SYNOPSIS
180
+ chmod [OPTION]... MODE[,MODE]... FILE...
181
+ chmod [OPTION]... OCTAL-MODE FILE...
182
+
183
+ DESCRIPTION
184
+ Change the file mode bits of each given file according to MODE.
185
+
186
+ EXAMPLES
187
+ chmod 755 script.sh rwxr-xr-x
188
+ chmod 644 file.txt rw-r--r--
189
+ chmod +x script.sh add execute permission`,tar:`TAR(1) GNU tar Manual TAR(1)
190
+
191
+ NAME
192
+ tar - an archiving utility
193
+
194
+ SYNOPSIS
195
+ tar [OPTION...] [FILE]...
196
+
197
+ DESCRIPTION
198
+ tar saves many files together into a single tape or disk archive,
199
+ and can restore individual files from the archive.
200
+
201
+ OPTIONS
202
+ -c, --create create a new archive
203
+ -x, --extract extract files from an archive
204
+ -z, --gzip filter the archive through gzip
205
+ -f, --file=ARCHIVE use archive file or device ARCHIVE
206
+ -v, --verbose verbosely list files processed
207
+ -t, --list list the contents of an archive`},Vc={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:({args:r,shell:t})=>{let e=r[0];if(!e)return{stderr:"What manual page do you want?",exitCode:1};let n=`/usr/share/man/man1/${e}.1`;if(t.vfs.exists(n))return{stdout:t.vfs.readFile(n),exitCode:0};let i=yh[e.toLowerCase()];return i?{stdout:i,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var Gc={name:"mkdir",description:"Make directories",category:"files",params:["<dir>"],run:({authUser:r,shell:t,cwd:e,args:n})=>{if(n.length===0)return{stderr:"mkdir: missing operand",exitCode:1};for(let i=0;i<n.length;i++){let s=tr(n,i);if(!s)return{stderr:"mkdir: missing operand",exitCode:1};let o=ue(e,s);Oe(r,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var Yc={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let i=n.filter(f=>!f.startsWith("-")),[s,o]=i;if(!s||!o)return{stderr:"mv: missing operand",exitCode:1};let a=ue(e,s),c=ue(e,o);try{if(Oe(r,a,"mv"),Oe(r,c,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${s}: No such file or directory`,exitCode:1};let f=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${s.split("/").pop()}`:c;return t.vfs.move(a,f),{exitCode:0}}catch(f){return{stderr:`mv: ${f instanceof Error?f.message:String(f)}`,exitCode:1}}}};var jc=$t(require("node:path"),1);var zc={name:"nano",description:"Text editor",category:"shell",params:["<file>"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let i=n[0];if(!i)return{stderr:"nano: missing file operand",exitCode:1};let s=ue(e,i);Oe(r,s,"nano");let o=t.vfs.exists(s)?t.vfs.readFile(s):"",a=jc.posix.basename(s)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:s,tempPath:c,initialContent:o},exitCode:0}}};var _r=require("node:fs"),Rt=$t(require("node:os"),1),nf=$t(require("node:path"),1);function xh(r){let t=Math.max(1,Math.floor(r/60)),e=Math.floor(t/1440),n=Math.floor(t%1440/60),i=t%60,s=[];return e>0&&s.push(`${e} day${e>1?"s":""}`),n>0&&s.push(`${n} hour${n>1?"s":""}`),(i>0||s.length===0)&&s.push(`${i} min${i>1?"s":""}`),s.join(", ")}function Xc(r){return`\x1B[${r}m \x1B[0m`}function Sh(){let r=[40,41,42,43,44,45,46,47].map(Xc).join(""),t=[100,101,102,103,104,105,106,107].map(Xc).join("");return[r,t]}function Jc(r,t,e){if(r.trim().length===0)return r;let n={r:255,g:255,b:255},i={r:168,g:85,b:247},s=e<=1?0:t/(e-1),o=Math.round(n.r+(i.r-n.r)*s),a=Math.round(n.g+(i.g-n.g)*s),c=Math.round(n.b+(i.b-n.b)*s);return`\x1B[38;2;${o};${a};${c}m${r}\x1B[0m`}function wh(r){if(r.trim().length===0)return r;let t=r.indexOf(":");if(t===-1)return r.includes("@")?Zc(r):r;let e=r.substring(0,t+1),n=r.substring(t+1);return Zc(e)+n}function Zc(r){let t=new RegExp("\x1B\\[[\\d;]*m","g"),e=r.replace(t,"");if(e.trim().length===0)return r;let n={r:255,g:255,b:255},i={r:168,g:85,b:247},s="";for(let o=0;o<e.length;o+=1){let a=e.length<=1?0:o/(e.length-1),c=Math.round(n.r+(i.r-n.r)*a),f=Math.round(n.g+(i.g-n.g)*a),l=Math.round(n.b+(i.b-n.b)*a);s+=`\x1B[38;2;${c};${f};${l}m${e[o]}\x1B[0m`}return s}function ef(r){return Math.max(0,Math.round(r/(1024*1024)))}function tf(){try{let r=(0,_r.readFileSync)("/etc/os-release","utf8");for(let t of r.split(`
208
+ `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function rf(r){try{let t=(0,_r.readFileSync)(r,"utf8").split(`
209
+ `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function Ih(r){let t=rf("/sys/devices/virtual/dmi/id/sys_vendor"),e=rf("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||r}function Ch(){let r=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of r)if((0,_r.existsSync)(t))try{return(0,_r.readFileSync)(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function vh(){let r=["/snap","/var/lib/snapd/snaps"];for(let t of r)if((0,_r.existsSync)(t))try{return(0,_r.readdirSync)(t,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}}function kh(){let r=Ch(),t=vh();return r!==void 0&&t!==void 0?`${r} (dpkg), ${t} (snap)`:r!==void 0?`${r} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function Bh(){let r=Rt.cpus();if(r.length===0)return"unknown";let t=r[0];if(!t)return"unknown";let e=(t.speed/1e3).toFixed(2);return`${t.model} (${r.length}) @ ${e}GHz`}function Rh(r){return!r||r.trim().length===0?"unknown":nf.posix.basename(r.trim())}function Nh(r){let t=Rt.totalmem(),e=Rt.freemem(),n=Math.max(0,t-e),i=r.shellProps,s=process.uptime();return r.uptimeSeconds===void 0&&(r.uptimeSeconds=Math.round(s)),{user:r.user,host:r.host,osName:i?.os??r.osName??`${tf()??Rt.type()} ${Rt.arch()}`,kernel:i?.kernel??r.kernel??Rt.release(),uptimeSeconds:r.uptimeSeconds??Rt.uptime(),packages:r.packages??kh(),shell:Rh(r.shell),shellProps:r.shellProps??{kernel:r.kernel??Rt.release(),os:r.osName??`${tf()??Rt.type()} ${Rt.arch()}`,arch:Rt.arch()},resolution:r.resolution??"n/a (ssh)",terminal:r.terminal??"unknown",cpu:r.cpu??Bh(),gpu:r.gpu??"n/a",memoryUsedMiB:r.memoryUsedMiB??ef(n),memoryTotalMiB:r.memoryTotalMiB??ef(t)}}function sf(r){let t=Nh(r),e=xh(t.uptimeSeconds),n=Sh(),i=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],s=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${Ih(t.host)}`,`Kernel: ${t.kernel}`,`Uptime: ${e}`,`Packages: ${t.packages}`,`Shell: ${t.shell}`,`Resolution: ${t.resolution}`,`Terminal: ${t.terminal}`,`CPU: ${t.cpu}`,`GPU: ${t.gpu}`,`Memory: ${t.memoryUsedMiB}MiB / ${t.memoryTotalMiB}MiB`,"",n[0],n[1]],o=Math.max(i.length,s.length),a=[];for(let c=0;c<o;c+=1){let f=i[c]??"",l=s[c]??"";if(l.length>0){let u=Jc(f.padEnd(31," "),c,i.length),h=wh(l);a.push(`${u} ${h}`);continue}a.push(Jc(f,c,i.length))}return a.join(`
210
+ `)}var Ts={PATH:"/usr/local/bin:/usr/bin:/bin",HOME:"/home/user",SHELL:"/bin/sh",TERM:"xterm-256color",USER:"user"};function of(r){return Ts.USER=r,Ts.HOME=`/home/${r}`,{...Ts}}var af={name:"set",description:"Display or set shell variables",category:"shell",params:["[VAR=value]"],run:({args:r,env:t})=>{if(r.length===0)return{stdout:Object.entries(t.vars).map(([n,i])=>`${n}=${i}`).join(`
211
+ `),exitCode:0};for(let e of r)if(e.includes("=")){let n=e.indexOf("=");t.vars[e.slice(0,n)]=e.slice(n+1)}return{exitCode:0}}};var cf={name:"neofetch",description:"System info display",category:"misc",params:["[--off]"],run:({args:r,authUser:t,hostname:e,shell:n})=>{let i=of(t);return se(r,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:se(r,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:sf({user:t,host:e,shell:i.SHELL,shellProps:n.properties,terminal:i.TERM,uptimeSeconds:Math.floor((Date.now()-n.startTime)/1e3),packages:`${n.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}}};var ff={name:"passwd",description:"Change user password",category:"users",params:["<username> <password>"],run:async({authUser:r,args:t,shell:e})=>{let[n,i]=t;return!n||!i?{stderr:"passwd: usage: passwd <username> <password>",exitCode:1}:r!=="root"&&r!==n?{stderr:"passwd: permission denied",exitCode:1}:(await e.users.setPassword(n,i),{stdout:`passwd: password updated for '${n}'`,exitCode:0})}};var lf={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:r})=>{let{flagsWithValues:t,positionals:e}=Qt(r,{flagsWithValue:["-c","-i","-W"]}),n=e[0]??"localhost",i=t.get("-c"),s=i?Math.max(1,parseInt(i,10)||4):4,o=[`PING ${n}: 56 data bytes`];for(let a=0;a<s;a++){let c=(Math.random()*10+1).toFixed(3);o.push(`64 bytes from ${n}: icmp_seq=${a} ttl=64 time=${c} ms`)}return o.push(`--- ${n} ping statistics ---`),o.push(`${s} packets transmitted, ${s} received, 0% packet loss`),{stdout:o.join(`
212
+ `),exitCode:0}}};var uf={name:"ps",description:"Report process status",category:"system",params:["[-a] [-u] [-x] [aux]"],run:({authUser:r,shell:t,args:e})=>{let n=t.users.listActiveSessions(),i=se(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),s=se(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(i){let l=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],u=1e3;for(let h of n){let g=h.username.padEnd(10).slice(0,10),b=(Math.random()*.5).toFixed(1),_=Math.floor(Math.random()*2e4+5e3),x=Math.floor(Math.random()*5e3+1e3);l.push(`${g} ${String(u).padStart(6)} 0.0 ${b.padStart(4)} ${String(_).padStart(6)} ${String(x).padStart(5)} ${h.tty.padEnd(8)} Ss 00:00 0:00 bash`),u++}return l.push(`root ${String(u).padStart(6)} 0.0 0.0 0 0 ? S 00:00 0:00 ps`),{stdout:l.join(`
213
+ `),exitCode:0}}let a=[" PID TTY TIME CMD"],c=1e3;for(let f of n)!s&&f.username!==r||(a.push(`${String(c).padStart(5)} ${f.tty.padEnd(12)} 00:00:00 ${f.username===r?"bash":`bash (${f.username})`}`),c++);return a.push(`${String(c).padStart(5)} pts/0 00:00:00 ps`),{stdout:a.join(`
214
+ `),exitCode:0}}};var df={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:r})=>({stdout:r,exitCode:0})};var hf={name:"rm",description:"Remove files or directories",category:"files",params:["[-r|-rf] <path>"],run:({authUser:r,shell:t,cwd:e,args:n})=>{if(n.length===0)return{stderr:"rm: missing operand",exitCode:1};let i=se(n,["-r","-rf","-fr"]),s=[];for(let o=0;;o+=1){let a=tr(n,o,{flags:["-r","-rf","-fr"]});if(!a)break;s.push(a)}if(s.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of s){let a=ue(e,o);Oe(r,a,"rm"),t.vfs.remove(a,{recursive:i})}return{exitCode:0}}};var pf={name:"sed",description:"Stream editor for filtering and transforming text",category:"text",params:["-e <expr> [file]","s/pattern/replace/[g]"],run:({authUser:r,shell:t,cwd:e,args:n,stdin:i})=>{let s=se(n,["-i"]),o=Ht(n,["-e"])??n.find(x=>!x.startsWith("-")),a=n.filter(x=>!x.startsWith("-")&&x!==o).pop();if(!o)return{stderr:"sed: no expression",exitCode:1};let c=i??"";if(a){let x=ue(e,a);try{c=t.vfs.readFile(x)}catch{return{stderr:`sed: ${a}: No such file or directory`,exitCode:1}}}let f=o.match(/^s([^a-zA-Z0-9])(.+?)\1(.*?)\1([gi]*)$/);if(!f)return{stderr:`sed: unrecognized command: ${o}`,exitCode:1};let[,,l,u,h]=f,g=(h??"").includes("i")?"gi":(h??"").includes("g")?"g":"",b;try{b=new RegExp(l,g||"")}catch{return{stderr:`sed: invalid regex: ${l}`,exitCode:1}}let _=((h??"").includes("g")||g.includes("g"),c.replace(b,u??""));if(s&&a){let x=ue(e,a);return t.writeFileAsUser(r,x,_),{exitCode:0}}return{stdout:_,exitCode:0}}};function Ph(r,t,e){return r.replace(/\$\?/g,String(e)).replace(/\$\{([^}:]+):-([^}]*)\}/g,(n,i,s)=>t[i]??s).replace(/\$\{([^}]+)\}/g,(n,i)=>t[i]??"").replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g,(n,i)=>t[i]??"").replace(/^~(\/|$)/,`${t.HOME??"/home/user"}$1`)}async function Us(r,t,e,n){if(r.includes("$(")){let i=/\$\(([^)]+)\)/g,s=[...r.matchAll(i)];for(let o of s){let a=o[1]?.trim()??"",f=((await St(a,n.authUser,n.hostname,n.mode,n.cwd,n.shell,void 0,n.env)).stdout??"").replace(/\n$/,"");r=r.replace(o[0],f)}}return Ph(r,t,e)}function Kr(r){let t=[],e=0;for(;e<r.length;){let n=r[e].trim();if(!n||n.startsWith("#")){e++;continue}if(n.startsWith("if ")||n==="if"){let i=n.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),s=[],o=[],a=[],c="then",f="";for(e++;e<r.length&&r[e]?.trim()!=="fi";){let l=r[e].trim();l.startsWith("elif ")?(c="elif",f=l.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),o.push({cond:f,body:[]})):l==="else"?c="else":l!=="then"&&(c==="then"?s.push(l):c==="elif"&&o.length>0?o[o.length-1].body.push(l):a.push(l)),e++}t.push({type:"if",cond:i,then:s,elif:o,else_:a})}else if(n.startsWith("for ")){let i=n.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(i){let s=[];for(e++;e<r.length&&r[e]?.trim()!=="done";){let o=r[e].trim().replace(/^do\s+/,"");o&&o!=="do"&&s.push(o),e++}t.push({type:"for",var:i[1],list:i[2],body:s})}else t.push({type:"cmd",line:n})}else if(n.startsWith("while ")){let i=n.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),s=[];for(e++;e<r.length&&r[e]?.trim()!=="done";){let o=r[e].trim().replace(/^do\s+/,"");o&&o!=="do"&&s.push(o),e++}t.push({type:"while",cond:i,body:s})}else t.push({type:"cmd",line:n});e++}return t}async function Ls(r,t){let e=await Us(r,t.env.vars,t.env.lastExitCode,t),n=e.match(/^\[?\s*(.+?)\s*\]?$/);if(n){let s=n[1],o=s.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,f,l]=o,u=ue(t.cwd,l);if(f==="f")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="file";if(f==="d")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="directory";if(f==="e")return t.shell.vfs.exists(u);if(f==="z")return(l??"").length===0;if(f==="n")return(l??"").length>0}let a=s.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,f,l,u]=a;if(l==="=="||l==="=")return f===u;if(l==="!=")return f!==u}let c=s.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,f,l,u]=c,h=Number(f),g=Number(u);if(l==="-eq")return h===g;if(l==="-ne")return h!==g;if(l==="-lt")return h<g;if(l==="-le")return h<=g;if(l==="-gt")return h>g;if(l==="-ge")return h>=g}}return((await St(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function Vr(r,t){let e={exitCode:0},n="";for(let i of r)if(i.type==="cmd"){let s=await Us(i.line,t.env.vars,t.env.lastExitCode,t),o=await St(s,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env);if(t.env.lastExitCode=o.exitCode??0,o.stdout&&(n+=`${o.stdout}
215
+ `),o.stderr)return{...o,stdout:n.trim()};e=o}else if(i.type==="if"){let s=!1;if(await Ls(i.cond,t)){let o=await Vr(Kr(i.then),t);o.stdout&&(n+=`${o.stdout}
216
+ `),s=!0}else{for(let o of i.elif)if(await Ls(o.cond,t)){let a=await Vr(Kr(o.body),t);a.stdout&&(n+=`${a.stdout}
217
+ `),s=!0;break}if(!s&&i.else_.length>0){let o=await Vr(Kr(i.else_),t);o.stdout&&(n+=`${o.stdout}
218
+ `)}}}else if(i.type==="for"){let o=(await Us(i.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/);for(let a of o){t.env.vars[i.var]=a;let c=await Vr(Kr(i.body),t);if(c.stdout&&(n+=`${c.stdout}
219
+ `),c.closeSession)return c}}else if(i.type==="while"){let s=0;for(;s<1e3&&await Ls(i.cond,t);){let o=await Vr(Kr(i.body),t);if(o.stdout&&(n+=`${o.stdout}
220
+ `),o.closeSession)return o;s++}}return{...e,stdout:n.trim()||e.stdout}}var gf={name:"sh",aliases:["bash"],description:"Execute shell script or command",category:"shell",params:["-c <script>","[<file>]"],run:async r=>{let{args:t,shell:e,cwd:n}=r;if(se(t,"-c")){let s=t[t.indexOf("-c")+1]??"";if(!s)return{stderr:"sh: -c requires a script",exitCode:1};let o=s.split(/[;\n]/).map(c=>c.trim()).filter(c=>c&&!c.startsWith("#")),a=Kr(o);return Vr(a,r)}let i=t[0];if(i){let s=ue(n,i);if(!e.vfs.exists(s))return{stderr:`sh: ${i}: No such file or directory`,exitCode:1};let a=e.vfs.readFile(s).split(`
221
+ `).map(f=>f.trim()).filter(f=>f&&!f.startsWith("#")),c=Kr(a);return Vr(c,r)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var mf={name:"sleep",description:"Delay execution",category:"system",params:["<seconds>"],run:async({args:r})=>{let t=parseFloat(r[0]??"1");return Number.isNaN(t)||t<0?{stderr:"sleep: invalid time",exitCode:1}:(await new Promise(e=>setTimeout(e,t*1e3)),{exitCode:0})}};var Af={name:"sort",description:"Sort lines of text",category:"text",params:["[-r] [-n] [-u] [-k <col>] [file...]"],run:({authUser:r,shell:t,cwd:e,args:n,stdin:i})=>{let s=se(n,["-r"]),o=se(n,["-n"]),a=se(n,["-u"]),c=n.filter(b=>!b.startsWith("-")),u=[...(c.length>0?c.map(b=>{try{return Oe(r,ue(e,b),"sort"),t.vfs.readFile(ue(e,b))}catch{return""}}).join(`
222
+ `):i??"").split(`
223
+ `).filter(Boolean)].sort((b,_)=>o?Number(b)-Number(_):b.localeCompare(_)),h=s?u.reverse():u;return{stdout:(a?[...new Set(h)]:h).join(`
224
+ `),exitCode:0}}};var Ef={name:"su",description:"Switch user",category:"users",params:["- <username>"],run:({authUser:r,shell:t,args:e})=>{let n=t.users,i=tr(e,0,{flags:["-"]});return i?!n.isSudoer(r)&&r!=="root"?{stderr:"su: permission denied",exitCode:1}:!n.verifyPassword(i,tr(e,1)??"")&&r!=="root"?{stderr:"su: authentication failure",exitCode:1}:{switchUser:i,nextCwd:`/home/${i}`,exitCode:0}:{stderr:"su: missing username",exitCode:1}}};function Th(r){let{flags:t,flagsWithValues:e,positionals:n}=Qt(r,{flags:["-i","-S"],flagsWithValue:["-u","--user"]}),i=t.has("-i"),s=e.get("-u")||e.get("--user")||"root",o=n.length>0?n.join(" "):null;return{targetUser:s,loginShell:i,commandLine:o}}var _f={name:"sudo",description:"Execute as superuser",category:"users",params:["<command...>"],run:async({authUser:r,hostname:t,mode:e,cwd:n,shell:i,args:s})=>{let{targetUser:o,loginShell:a,commandLine:c}=Th(s);if(r!=="root"&&!i.users.isSudoer(r))return{stderr:"sudo: permission denied",exitCode:1};let f=o||"root",l=`[sudo] password for ${r}: `;return r==="root"?!c&&a?{switchUser:f,nextCwd:`/home/${f}`,exitCode:0}:c?St(c,f,t,e,a?`/home/${f}`:n,i):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:r,targetUser:f,commandLine:c,loginShell:a,prompt:l},exitCode:0}}};var bf={name:"tail",description:"Output last lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:r,shell:t,cwd:e,args:n,stdin:i})=>{let s=Ht(n,["-n"]),o=typeof s=="string"?parseInt(s,10):10,a=n.filter(l=>!l.startsWith("-")&&l!==s),c=l=>{let u=l.split(`
225
+ `);return u.slice(Math.max(0,u.length-o)).join(`
226
+ `)};if(a.length===0)return{stdout:c(i??""),exitCode:0};let f=[];for(let l of a){let u=ue(e,l);try{Oe(r,u,"tail"),f.push(c(t.vfs.readFile(u)))}catch{return{stderr:`tail: ${l}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
227
+ `),exitCode:0}}};var yf={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let i=se(n,["-c"]),s=se(n,["-x"]),o=se(n,["-t"]),a=n.findIndex(l=>l.includes("f")),c=a!==-1?n[a+1]:n.find(l=>l.endsWith(".tar")||l.endsWith(".tar.gz")||l.endsWith(".tgz"));if(!c)return{stderr:"tar: no archive specified",exitCode:1};let f=ue(e,c);if(i){let l=n.filter(h=>!h.startsWith("-")&&h!==c),u={};for(let h of l){let g=ue(e,h);try{if(t.vfs.stat(g).type==="file")u[h]=t.vfs.readFile(g);else{let _=(x,S)=>{for(let N of t.vfs.list(x)){let O=`${x}/${N}`,P=`${S}/${N}`;t.vfs.stat(O).type==="file"?u[P]=t.vfs.readFile(O):_(O,P)}};_(g,h)}}catch{return{stderr:`tar: ${h}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(r,f,JSON.stringify(u)),{exitCode:0}}if(o||s){let l;try{l=JSON.parse(t.vfs.readFile(f))}catch{return{stderr:`tar: ${c}: cannot open archive`,exitCode:1}}if(o)return{stdout:Object.keys(l).join(`
228
+ `),exitCode:0};for(let[u,h]of Object.entries(l))t.writeFileAsUser(r,ue(e,u),h);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var xf={name:"tee",description:"Read stdin, write to stdout and files",category:"text",params:["[-a] <file...>"],run:({authUser:r,shell:t,cwd:e,args:n,stdin:i})=>{let s=se(n,["-a"]),o=n.filter(c=>!c.startsWith("-")),a=i??"";for(let c of o){let f=ue(e,c);if(s){let l=(()=>{try{return t.vfs.readFile(f)}catch{return""}})();t.writeFileAsUser(r,f,l+a)}else t.writeFileAsUser(r,f,a)}return{stdout:a,exitCode:0}}};var Sf={name:"touch",description:"Create or update files",category:"files",params:["<file>"],run:({authUser:r,shell:t,cwd:e,args:n})=>{if(n.length===0)return{stderr:"touch: missing file operand",exitCode:1};for(let i of n){let s=ue(e,i);Oe(r,s,"touch"),t.vfs.exists(s)||t.writeFileAsUser(r,s,"")}return{exitCode:0}}};var wf={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] <set1> [set2]"],run:({args:r,stdin:t})=>{let e=se(r,["-d"]),n=r.filter(a=>!a.startsWith("-")),i=n[0]??"",s=n[1]??"",o=t??"";if(e)for(let a of i)o=o.split(a).join("");else if(s)for(let a=0;a<i.length;a++)o=o.split(i[a]).join(s[a]??s[s.length-1]??"");return{stdout:o,exitCode:0}}};var If={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:r,shell:t,cwd:e,args:n})=>{let i=ue(e,tr(n,0)??e);return Oe(r,i,"tree"),{stdout:t.vfs.tree(i),exitCode:0}}};var Cf={name:"type",description:"Describe how a command would be interpreted",category:"shell",params:["<command...>"],run:({args:r,shell:t,env:e})=>{if(r.length===0)return{stderr:"type: missing argument",exitCode:1};let n=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),i=[],s=0;for(let o of r){if(ki(o)){i.push(`${o} is a shell builtin`);continue}let a=!1;for(let c of n){let f=`${c}/${o}`;if(t.vfs.exists(f)){i.push(`${o} is ${f}`),a=!0;break}}a||(i.push(`${o}: not found`),s=1)}return{stdout:i.join(`
229
+ `),exitCode:s}}};var vf={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:r,args:t})=>{let e=se(t,["-a"]),n="Linux",i=r.properties?.kernel??"5.15.0",s=r.properties?.arch??"x86_64",o=r.hostname;return e?{stdout:`${n} ${o} ${i} #1 SMP ${s} GNU/Linux`,exitCode:0}:se(t,["-r"])?{stdout:i,exitCode:0}:se(t,["-m"])?{stdout:s,exitCode:0}:{stdout:n,exitCode:0}}};var kf={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:r,stdin:t})=>{let e=se(r,["-c"]),n=se(r,["-d"]),i=se(r,["-u"]),s=(t??"").split(`
230
+ `),o=[],a=0;for(;a<s.length;){let c=a;for(;c<s.length&&s[c]===s[a];)c++;let f=c-a,l=s[a];if(n&&f===1){a=c;continue}if(i&&f>1){a=c;continue}o.push(e?`${String(f).padStart(4)} ${l}`:l),a=c}return{stdout:o.join(`
231
+ `),exitCode:0}}};var Bf={name:"unset",description:"Remove shell variable",category:"shell",params:["<VAR>"],run:({args:r,env:t})=>{for(let e of r)delete t.vars[e];return{exitCode:0}}};var Rf={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:r,shell:t})=>{let e=se(r,["-p"]),n=se(r,["-s"]),i=Math.floor((Date.now()-t.startTime)/1e3),s=Math.floor(i/86400),o=Math.floor(i%86400/3600),a=Math.floor(i%3600/60);if(n)return{stdout:new Date(t.startTime).toISOString().slice(0,19).replace("T"," "),exitCode:0};if(e){let h=[];return s>0&&h.push(`${s} day${s>1?"s":""}`),o>0&&h.push(`${o} hour${o>1?"s":""}`),h.push(`${a} minute${a!==1?"s":""}`),{stdout:`up ${h.join(", ")}`,exitCode:0}}let c=new Date().toTimeString().slice(0,8),f=s>0?`${s} day${s>1?"s":""}, ${String(o).padStart(2)}:${String(a).padStart(2,"0")}`:`${String(o).padStart(2)}:${String(a).padStart(2,"0")}`,l=t.users.listActiveSessions().length,u=(Math.random()*.5).toFixed(2);return{stdout:` ${c} up ${f}, ${l} user${l!==1?"s":""}, load average: ${u}, ${u}, ${u}`,exitCode:0}}};var Nf={name:"wc",description:"Count words/lines/bytes",category:"text",params:["[-l] [-w] [-c] [file...]"],run:({authUser:r,shell:t,cwd:e,args:n,stdin:i})=>{let s=se(n,["-l"]),o=se(n,["-w"]),a=se(n,["-c"]),c=!s&&!o&&!a,f=n.filter(h=>!h.startsWith("-")),l=(h,g)=>{let b=h.split(`
232
+ `).length-(h.endsWith(`
233
+ `)?1:0),_=h.trim().split(/\s+/).filter(Boolean).length,x=Buffer.byteLength(h,"utf8"),S=[];return(c||s)&&S.push(String(b).padStart(7)),(c||o)&&S.push(String(_).padStart(7)),(c||a)&&S.push(String(x).padStart(7)),g&&S.push(` ${g}`),S.join("")};if(f.length===0)return{stdout:l(i??"",""),exitCode:0};let u=[];for(let h of f){let g=ue(e,h);try{Oe(r,g,"wc");let b=t.vfs.readFile(g);u.push(l(b,h))}catch{return{stderr:`wc: ${h}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
234
+ `),exitCode:0}}};var Pf={name:"wget",description:"File downloader (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:r,cwd:t,args:e,shell:n})=>{let{flagsWithValues:i,positionals:s}=Qt(e,{flagsWithValue:["-O","--output-document","-o","--output-file","-P","--directory-prefix","--tries","--timeout"]});if(se(e,["-h","--help"]))return{stdout:["Usage: wget [option]... [URL]..."," -O, --output-document=FILE Write to FILE ('-' for stdout)"," -P, --directory-prefix=DIR Save files in DIR"," -q, --quiet Quiet mode"," -v, --verbose Verbose output (default)"," -c, --continue Continue partial download"," --tries=N Retry N times"," --timeout=N Timeout in seconds"].join(`
235
+ `),exitCode:0};if(se(e,["-V","--version"]))return{stdout:"GNU Wget 1.21.3 (virtual) built on Fortune GNU/Linux.",exitCode:0};let o=s[0];if(!o)return{stderr:`wget: missing URL
236
+ Usage: wget [OPTION]... [URL]...`,exitCode:1};let a=i.get("-O")??i.get("--output-document")??null,c=i.get("-P")??i.get("--directory-prefix")??null,f=se(e,["-q","--quiet"]),l=a==="-"?null:a??ja(o),u=l?ue(t,c?`${c}/${l}`:l):null;u&&Oe(r,u,"wget");let h=[];f||(h.push(`--${new Date().toISOString()}-- ${o}`),h.push(`Resolving ${new URL(o).host}...`),h.push(`Connecting to ${new URL(o).host}...`));let g;try{g=await fetch(o,{headers:{"User-Agent":"Wget/1.21.3 (Fortune GNU/Linux)"}})}catch(_){let x=_ instanceof Error?_.message:String(_);return h.push(`wget: unable to resolve host: ${x}`),{stderr:h.join(`
237
+ `),exitCode:4}}if(!g.ok)return h.push(`ERROR ${g.status}: ${g.statusText}`),{stderr:h.join(`
238
+ `),exitCode:8};let b;try{b=await g.text()}catch{return{stderr:"wget: failed to read response",exitCode:1}}if(!f){let _=g.headers.get("content-type")??"application/octet-stream";h.push(`HTTP request sent, awaiting response... ${g.status} ${g.statusText}`),h.push(`Length: ${b.length} [${_}]`)}return a==="-"?{stdout:b,stderr:h.join(`
239
+ `)||void 0,exitCode:0}:u?(n.writeFileAsUser(r,u,b),f||h.push(`Saving to: '${u}'
240
+ ${u} 100%[==================>] ${b.length} B`),{stderr:h.join(`
241
+ `)||void 0,exitCode:0}):{stdout:b,exitCode:0}}};var Tf={name:"which",description:"Locate a command in PATH",category:"shell",params:["<command...>"],run:({args:r,shell:t,env:e})=>{if(r.length===0)return{stderr:"which: missing argument",exitCode:1};let n=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),i=[],s=!1;for(let o of r){let a=!1;for(let c of n){let f=`${c}/${o}`;if(t.vfs.exists(f)&&t.vfs.stat(f).type==="file"){i.push(f),a=!0;break}}a||(s=!0)}return i.length===0?{exitCode:1}:{stdout:i.join(`
242
+ `),exitCode:s?1:0}}};function Bi(r){let t=r.toLocaleString("en-US",{weekday:"short"}),e=r.toLocaleString("en-US",{month:"short"}),n=r.getDate().toString().padStart(2,"0"),i=r.getHours().toString().padStart(2,"0"),s=r.getMinutes().toString().padStart(2,"0"),o=r.getSeconds().toString().padStart(2,"0"),a=r.getFullYear();return`${t} ${e} ${n} ${i}:${s}:${o} ${a}`}var Lf={name:"who",description:"Show active sessions",category:"system",params:[],run:({shell:r})=>({stdout:r.users.listActiveSessions().map(e=>{let n=new Date(e.startedAt),i=Number.isNaN(n.getTime())?e.startedAt:Bi(n);return`${e.username} ${e.tty} ${i} (${e.remoteAddress||"unknown"})`}).join(`
243
+ `),exitCode:0})};var Uf={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:r})=>({stdout:r,exitCode:0})};var Df={name:"xargs",description:"Build and execute command lines from stdin",category:"text",params:["[command] [args...]"],run:async({authUser:r,hostname:t,mode:e,cwd:n,args:i,stdin:s,shell:o,env:a})=>{let c=i[0]??"echo",f=i.slice(1),l=(s??"").trim().split(/\s+/).filter(Boolean);if(l.length===0)return{exitCode:0};let u=[c,...f,...l].join(" ");return St(u,r,t,e,n,o,void 0,a)}};var Lh=[df,dc,qc,If,uc,Sf,hf,Gc,gc,Yc,Wc,hc,Bc,Nc,pf,fc,Af,kf,Nf,Uc,bf,Ac,wf,xf,Df,yc,yf,Tc,Lc,lc,Uf,Lf,Fc,Hc,Pc,vf,uf,Qc,bc,wc,Ec,mf,lf,Ic,Cc,kc,af,Bf,gf,pc,vc,zc,$c,mc,Pf,ec,ff,_c,_f,Ef,cf,ac,cc,xc,Sc,Tf,Cf,Vc,rc,nc,ic,sc,oc,Rf,Rc,Kc],Of=[],Qn=new Map,Ri=null,Uh=Oc(()=>Os().map(r=>r.name));function Ds(){Qn.clear();for(let r of Os()){Qn.set(r.name,r);for(let t of r.aliases??[])Qn.set(t,r)}Ri=Array.from(Qn.keys()).sort()}function Os(){return[...Lh,...Of,Uh]}function Mf(r){let t={...r,name:r.name.trim().toLowerCase(),aliases:r.aliases?.map(n=>n.trim().toLowerCase())};if([t.name,...t.aliases??[]].some(n=>n.length===0||/\s/.test(n)))throw new Error("Command names must be non-empty and contain no spaces");Of.push(t),Ds()}function Ff(r,t,e){return{name:r,params:t,run:e}}function $f(){return Ri||Ds(),Ri}function Mc(){return Os()}function ki(r){return Ri||Ds(),Qn.get(r.toLowerCase())}function Dh(r){let t=[],e="",n=!1,i="";for(let s=0;s<r.length;s++){let o=r[s]||"",a=s>0?r[s-1]:"";if((o==='"'||o==="'")&&a!=="\\"){if(!n){n=!0,i=o;continue}if(o===i){n=!1,i="";continue}}if(/\s/.test(o)&&!n){e.length>0&&(t.push(e),e="");continue}e+=o}return e.length>0&&t.push(e),t}function Oh(r){let t=Dh(r.trim());return{commandName:t[0]?.toLowerCase()??"",args:t.slice(1)}}function Wn(r,t){return{vars:{PATH:"/usr/local/bin:/usr/bin:/bin",HOME:`/home/${r}`,USER:r,LOGNAME:r,SHELL:"/bin/sh",TERM:"xterm-256color",HOSTNAME:t,PS1:"\\u@\\h:\\w\\$ "},lastExitCode:0}}async function Ps(r,t,e,n,i,s,o,a,c){let f=c.vars[`__alias_${r}`];if(f)return St(`${f} ${t.join(" ")}`,e,n,i,s,o,a,c);let l=ki(r);if(!l)return{stderr:`${r}: command not found`,exitCode:127};try{return await l.run({authUser:e,hostname:n,activeSessions:o.users.listActiveSessions(),rawInput:[r,...t].join(" "),mode:i,args:t,stdin:a,cwd:s,shell:o,env:c})}catch(u){return{stderr:u instanceof Error?u.message:"Command failed",exitCode:1}}}async function St(r,t,e,n,i,s,o,a){let c=r.trim();if(c.length===0)return{exitCode:0};let f=a??Wn(t,e),l=c;if(l.includes("$(")){let x="",S=!1,N=0;for(;N<l.length;){let O=l[N];if(O==="'"&&!S){S=!0,x+=O,N++;continue}if(O==="'"&&S){S=!1,x+=O,N++;continue}if(!S&&O==="$"&&l[N+1]==="("){let P=0,W=N+1;for(;W<l.length;){if(l[W]==="(")P++;else if(l[W]===")"&&(P--,P===0))break;W++}let X=l.slice(N+2,W).trim(),w=((await St(X,t,e,n,i,s,void 0,f)).stdout??"").replace(/\n$/,"");x+=w,N=W+1;continue}x+=O,N++}l=x}let u=l.split(/\s+/)[0]??"",h=f.vars[`__alias_${u}`];if(h&&(l=l.replace(u,h)),/(?<![|&])[|](?![|])/.test(l)||l.includes(">")||l.includes("<")||l.includes("&&")||l.includes("||")||l.includes(";")){let x=Za(l);if(!x.isValid)return{stderr:x.error||"Syntax error",exitCode:1};try{return await Ja(x.statements,t,e,n,i,s,f)}catch(S){return{stderr:S instanceof Error?S.message:"Execution failed",exitCode:1}}}let{commandName:g,args:b}=Oh(l),_=ki(g);if(!_)return{stderr:`${g}: command not found`,exitCode:127};try{return await _.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:l,mode:n,args:b,stdin:o,cwd:i,shell:s,env:f})}catch(x){return{stderr:x instanceof Error?x.message:"Command failed",exitCode:1}}}var Ay=er("SshClient");var qd=require("node:events"),Kd=$t(ka(),1);var Md=require("node:events");var xd=require("node:events"),$r=$t(require("node:fs"),1),mr=$t(require("node:path"),1),Zr=require("node:zlib");var Na=Buffer.from([86,70,83,33]),Nm=1,gd=1,md=2,Ba=class{chunks=[];write(t){this.chunks.push(t)}writeUint8(t){let e=Buffer.allocUnsafe(1);e.writeUInt8(t,0),this.chunks.push(e)}writeUint16(t){let e=Buffer.allocUnsafe(2);e.writeUInt16LE(t,0),this.chunks.push(e)}writeUint32(t){let e=Buffer.allocUnsafe(4);e.writeUInt32LE(t,0),this.chunks.push(e)}writeFloat64(t){let e=Buffer.allocUnsafe(8);e.writeDoubleBE(t,0),this.chunks.push(e)}writeString(t){let e=Buffer.from(t,"utf8");this.writeUint16(e.length),this.chunks.push(e)}writeBytes(t){this.writeUint32(t.length),this.chunks.push(t)}toBuffer(){return Buffer.concat(this.chunks)}};function Ad(r,t){if(t.type==="file"){let e=t;r.writeUint8(gd),r.writeString(e.name),r.writeUint32(e.mode),r.writeFloat64(e.createdAt.getTime()),r.writeFloat64(e.updatedAt.getTime()),r.writeUint8(e.compressed?1:0),r.writeBytes(e.content)}else{let e=t;r.writeUint8(md),r.writeString(e.name),r.writeUint32(e.mode),r.writeFloat64(e.createdAt.getTime()),r.writeFloat64(e.updatedAt.getTime());let n=Array.from(e.children.values());r.writeUint32(n.length);for(let i of n)Ad(r,i)}}function Ed(r){let t=new Ba;return t.write(Na),t.writeUint8(Nm),Ad(t,r),t.toBuffer()}var Ra=class{constructor(t){this.buf=t}buf;pos=0;readUint8(){return this.buf.readUInt8(this.pos++)}readUint16(){let t=this.buf.readUInt16LE(this.pos);return this.pos+=2,t}readUint32(){let t=this.buf.readUInt32LE(this.pos);return this.pos+=4,t}readFloat64(){let t=this.buf.readDoubleBE(this.pos);return this.pos+=8,t}readString(){let t=this.readUint16(),e=this.buf.toString("utf8",this.pos,this.pos+t);return this.pos+=t,e}readBytes(){let t=this.readUint32(),e=this.buf.slice(this.pos,this.pos+t);return this.pos+=t,e}remaining(){return this.buf.length-this.pos}};function _d(r){let t=r.readUint8(),e=r.readString(),n=r.readUint32(),i=new Date(r.readFloat64()),s=new Date(r.readFloat64());if(t===gd){let o=r.readUint8()===1,a=r.readBytes();return{type:"file",name:e,mode:n,createdAt:i,updatedAt:s,compressed:o,content:a}}if(t===md){let o=r.readUint32(),a=new Map;for(let c=0;c<o;c++){let f=_d(r);a.set(f.name,f)}return{type:"directory",name:e,mode:n,createdAt:i,updatedAt:s,children:a}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function bd(r){if(r.length<5)throw new Error("[VFS binary] Buffer too short");if(!r.slice(0,4).equals(Na))throw new Error("[VFS binary] Invalid magic \u2014 not a VFS binary snapshot");let e=new Ra(r);for(let i=0;i<5;i++)e.readUint8();let n=_d(e);if(n.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return n}function yd(r){return r.length>=4&&r.slice(0,4).equals(Na)}var Is=$t(require("node:path"),1);function pt(r){if(!r||r.trim()==="")return"/";let t=Is.posix.normalize(r.startsWith("/")?r:`/${r}`);return t===""?"/":t}function Pm(r){return r.split("/").filter(Boolean)}function Lt(r,t){let e=pt(t);if(e==="/")return r;let n=Pm(e),i=r;for(let s of n){if(i.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=i.children.get(s);if(!o)throw new Error(`Path '${e}' does not exist.`);i=o}return i}function Nn(r,t,e,n){let i=pt(t);if(i==="/")throw new Error("Root path has no parent directory.");let s=Is.posix.dirname(i),o=Is.posix.basename(i);if(!o)throw new Error(`Invalid path '${t}'.`);e&&n(s);let a=Lt(r,s);if(a.type!=="directory")throw new Error(`Parent path '${s}' is not a directory.`);return{parent:a,name:o}}var Pa=class r extends xd.EventEmitter{root;mode;snapshotFile;constructor(t={}){if(super(),this.mode=t.mode??"memory",this.mode==="fs"){if(!t.snapshotPath)throw new Error('VirtualFileSystem: "snapshotPath" is required when mode is "fs".');this.snapshotFile=mr.resolve(t.snapshotPath,"vfs-snapshot.vfsb")}else this.snapshotFile=null;this.root=this.makeDir("",493)}makeDir(t,e){let n=new Date;return{type:"directory",name:t,mode:e,createdAt:n,updatedAt:n,children:new Map}}makeFile(t,e,n,i){let s=new Date;return{type:"file",name:t,content:e,mode:n,compressed:i,createdAt:s,updatedAt:s}}mkdirRecursive(t,e){let n=pt(t);if(n==="/")return;let i=n.split("/").filter(Boolean),s=this.root,o="";for(let a of i){o+=`/${a}`;let c=s.children.get(a);if(!c)c=this.makeDir(a,e),s.children.set(a,c),this.emit("dir:create",{path:o,mode:e});else if(c.type!=="directory")throw new Error(`Cannot create directory '${o}': path is a file.`);s=c}}async restoreMirror(){if(!(this.mode!=="fs"||!this.snapshotFile)&&$r.existsSync(this.snapshotFile))try{let t=$r.readFileSync(this.snapshotFile);if(yd(t))this.root=bd(t);else{let e=JSON.parse(t.toString("utf8"));this.root=this.deserializeDir(e.root,""),console.info("[VirtualFileSystem] Migrating legacy JSON snapshot to binary format.")}this.emit("snapshot:restore",{path:this.snapshotFile})}catch(t){console.warn(`[VirtualFileSystem] Could not restore snapshot from ${this.snapshotFile}:`,t instanceof Error?t.message:String(t))}}async flushMirror(){if(this.mode!=="fs"||!this.snapshotFile){this.emit("mirror:flush");return}let t=mr.dirname(this.snapshotFile);$r.mkdirSync(t,{recursive:!0});let e=Ed(this.root);$r.writeFileSync(this.snapshotFile,e),this.emit("mirror:flush",{path:this.snapshotFile})}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}mkdir(t,e=493){let n=pt(t),i=(()=>{try{return Lt(this.root,n)}catch{return null}})();if(i&&i.type!=="directory")throw new Error(`Cannot create directory '${n}': path is a file.`);this.mkdirRecursive(n,e)}writeFile(t,e,n={}){let i=pt(t),{parent:s,name:o}=Nn(this.root,i,!0,h=>this.mkdirRecursive(h,493)),a=s.children.get(o);if(a?.type==="directory")throw new Error(`Cannot write file '${i}': path is a directory.`);let c=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),f=n.compress??!1,l=f?(0,Zr.gzipSync)(c):c,u=n.mode??420;if(a){let h=a;h.content=l,h.compressed=f,h.mode=u,h.updatedAt=new Date}else s.children.set(o,this.makeFile(o,l,u,f));this.emit("file:write",{path:i,size:l.length})}readFile(t){let e=pt(t),n=Lt(this.root,e);if(n.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=n,s=i.compressed?(0,Zr.gunzipSync)(i.content):i.content;return this.emit("file:read",{path:e,size:s.length}),s.toString("utf8")}readFileRaw(t){let e=pt(t),n=Lt(this.root,e);if(n.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=n,s=i.compressed?(0,Zr.gunzipSync)(i.content):i.content;return this.emit("file:read",{path:e,size:s.length}),s}exists(t){try{return Lt(this.root,pt(t)),!0}catch{return!1}}chmod(t,e){Lt(this.root,pt(t)).mode=e}stat(t){let e=pt(t),n=Lt(this.root,e),i=e==="/"?"":mr.posix.basename(e);if(n.type==="file"){let o=n;return{type:"file",name:i,path:e,mode:o.mode,createdAt:o.createdAt,updatedAt:o.updatedAt,compressed:o.compressed,size:o.content.length}}let s=n;return{type:"directory",name:i,path:e,mode:s.mode,createdAt:s.createdAt,updatedAt:s.updatedAt,childrenCount:s.children.size}}list(t="/"){let e=pt(t),n=Lt(this.root,e);if(n.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Array.from(n.children.keys()).sort()}tree(t="/"){let e=pt(t),n=Lt(this.root,e);if(n.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let i=t==="/"?"/":mr.posix.basename(e);return this.renderTreeLines(n,i)}renderTreeLines(t,e){let n=[e],i=Array.from(t.children.keys()).sort();for(let s=0;s<i.length;s++){let o=i[s],a=t.children.get(o),c=s===i.length-1,f=c?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",l=c?" ":"\u2502 ";if(n.push(`${f}${o}`),a.type==="directory"){let u=this.renderTreeLines(a,"").split(`
244
+ `).slice(1).map(h=>`${l}${h}`);n.push(...u)}}return n.join(`
245
+ `)}getUsageBytes(t="/"){return this.computeUsage(Lt(this.root,pt(t)))}computeUsage(t){if(t.type==="file")return t.content.length;let e=0;for(let n of t.children.values())e+=this.computeUsage(n);return e}compressFile(t){let e=Lt(this.root,pt(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let n=e;n.compressed||(n.content=(0,Zr.gzipSync)(n.content),n.compressed=!0,n.updatedAt=new Date)}decompressFile(t){let e=Lt(this.root,pt(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let n=e;n.compressed&&(n.content=(0,Zr.gunzipSync)(n.content),n.compressed=!1,n.updatedAt=new Date)}symlink(t,e){let n=pt(e),i=t.startsWith("/")?pt(t):t,{parent:s,name:o}=Nn(this.root,n,!0,c=>this.mkdirRecursive(c,493)),a={type:"file",name:o,content:Buffer.from(i,"utf8"),mode:41471,compressed:!1,createdAt:new Date,updatedAt:new Date};s.children.set(o,a),this.emit("symlink:create",{link:n,target:i})}isSymlink(t){try{let e=Lt(this.root,pt(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let n=pt(t);for(let i=0;i<e;i++){try{let s=Lt(this.root,n);if(s.type==="file"&&s.mode===41471){let o=s.content.toString("utf8");n=o.startsWith("/")?o:pt(mr.posix.join(mr.posix.dirname(n),o));continue}}catch{break}return n}throw new Error(`Too many levels of symbolic links: ${t}`)}remove(t,e={}){let n=pt(t);if(n==="/")throw new Error("Cannot remove root directory.");let i=Lt(this.root,n);if(i.type==="directory"){let a=i;if(!e.recursive&&a.children.size>0)throw new Error(`Directory '${n}' is not empty. Use recursive option.`)}let{parent:s,name:o}=Nn(this.root,n,!1,()=>{});s.children.delete(o),this.emit("node:remove",{path:n})}move(t,e){let n=pt(t),i=pt(e);if(n==="/"||i==="/")throw new Error("Cannot move root directory.");let s=Lt(this.root,n);if(this.exists(i))throw new Error(`Destination '${i}' already exists.`);this.mkdirRecursive(mr.posix.dirname(i),493);let{parent:o,name:a}=Nn(this.root,i,!1,()=>{}),{parent:c,name:f}=Nn(this.root,n,!1,()=>{});c.children.delete(f),s.name=a,o.children.set(a,s)}toSnapshot(){return{root:this.serializeDir(this.root)}}serializeDir(t){let e=[];for(let n of t.children.values())e.push(n.type==="file"?this.serializeFile(n):this.serializeDir(n));return{type:"directory",name:t.name,mode:t.mode,createdAt:t.createdAt.toISOString(),updatedAt:t.updatedAt.toISOString(),children:e}}serializeFile(t){return{type:"file",name:t.name,mode:t.mode,createdAt:t.createdAt.toISOString(),updatedAt:t.updatedAt.toISOString(),compressed:t.compressed,contentBase64:t.content.toString("base64")}}static fromSnapshot(t){let e=new r;return e.root=e.deserializeDir(t.root,""),e}importSnapshot(t){this.root=this.deserializeDir(t.root,""),this.emit("snapshot:import")}deserializeDir(t,e){let n={type:"directory",name:e,mode:t.mode,createdAt:new Date(t.createdAt),updatedAt:new Date(t.updatedAt),children:new Map};for(let i of t.children)if(i.type==="file"){let s=i;n.children.set(s.name,{type:"file",name:s.name,mode:s.mode,createdAt:new Date(s.createdAt),updatedAt:new Date(s.updatedAt),compressed:s.compressed,content:Buffer.from(s.contentBase64,"base64")})}else{let s=this.deserializeDir(i,i.name);n.children.set(i.name,s)}return n}},Ta=Pa;var Hr=require("node:crypto"),wd=require("node:events"),Id=$t(require("node:path"),1);function Tm(){let r=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!r&&!["0","false","no","off"].includes(r.toLowerCase())}var wt=er("VirtualUserManager"),_i=class r extends wd.EventEmitter{constructor(e,n=!0){super();this.vfs=e;this.autoSudoForNewUsers=n;wt.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=Tm();usersPath="/virtual-env-js/.auth/htpasswd";sudoersPath="/virtual-env-js/.auth/sudoers";quotasPath="/virtual-env-js/.auth/quotas";authDirPath="/virtual-env-js/.auth";users=new Map;sudoers=new Set;quotas=new Map;activeSessions=new Map;nextTty=0;async initialize(){wt.mark("initialize"),this.loadFromVfs(),this.loadSudoersFromVfs(),this.loadQuotasFromVfs();let e=!1;this.users.has("root")||(this.users.set("root",this.createRecord("root","")),e=!0),this.sudoers.add("root"),e&&await this.persist(),this.emit("initialized")}async setQuotaBytes(e,n){if(wt.mark("setQuotaBytes"),this.validateUsername(e),!this.users.has(e))throw new Error(`quota: user '${e}' does not exist`);if(!Number.isFinite(n)||n<0)throw new Error("quota: maxBytes must be a non-negative number");this.quotas.set(e,Math.floor(n)),await this.persist()}async clearQuota(e){wt.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return wt.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){wt.mark("getUsageBytes");let n=`/home/${e}`;return this.vfs.exists(n)?this.vfs.getUsageBytes(n):0}assertWriteWithinQuota(e,n,i){wt.mark("assertWriteWithinQuota");let s=this.quotas.get(e);if(s===void 0)return;let o=Sd(n),a=Sd(`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let f=this.getUsageBytes(e),l=0;if(this.vfs.exists(o)){let g=this.vfs.stat(o);g.type==="file"&&(l=g.size)}let u=Buffer.isBuffer(i)?i.length:Buffer.byteLength(i,"utf8"),h=f-l+u;if(h>s)throw new Error(`quota exceeded for '${e}': ${h}/${s} bytes`)}verifyPassword(e,n){wt.mark("verifyPassword");let i=this.users.get(e);return i?this.hashPassword(n)===i.passwordHash:!1}async addUser(e,n){if(wt.mark("addUser"),this.validateUsername(e),this.validatePassword(n),this.users.has(e))return;this.users.set(e,this.createRecord(e,n)),this.autoSudoForNewUsers&&this.sudoers.add(e);let i=`/home/${e}`;this.vfs.exists(i)||(this.vfs.mkdir(i,493),this.vfs.writeFile(`${i}/README.txt`,`Welcome to the virtual environment, ${e}`)),await this.persist(),this.emit("user:add",{username:e})}getPasswordHash(e){wt.mark("getPasswordHash");let n=this.users.get(e);return n?n.passwordHash:null}async setPassword(e,n){if(wt.mark("setPassword"),this.validateUsername(e),this.validatePassword(n),!this.users.has(e))throw new Error(`passwd: user '${e}' does not exist`);this.users.set(e,this.createRecord(e,n)),await this.persist()}async deleteUser(e){if(wt.mark("deleteUser"),this.validateUsername(e),e==="root")throw new Error("deluser: cannot delete root");if(!this.users.delete(e))throw new Error(`deluser: user '${e}' does not exist`);this.sudoers.delete(e),this.emit("user:delete",{username:e}),await this.persist()}isSudoer(e){return wt.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(wt.mark("addSudoer"),this.validateUsername(e),!this.users.has(e))throw new Error(`sudoers: user '${e}' does not exist`);this.sudoers.add(e),await this.persist()}async removeSudoer(e){if(wt.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,n){wt.mark("registerSession");let i={id:(0,Hr.randomUUID)(),username:e,tty:`pts/${this.nextTty++}`,remoteAddress:n,startedAt:new Date().toISOString()};return this.activeSessions.set(i.id,i),this.emit("session:register",{sessionId:i.id,username:e,remoteAddress:n}),i}unregisterSession(e){if(wt.mark("unregisterSession"),!e)return;let n=this.activeSessions.get(e);this.activeSessions.delete(e),n&&this.emit("session:unregister",{sessionId:e,username:n.username}),this.activeSessions.delete(e)}updateSession(e,n,i){if(wt.mark("updateSession"),!e)return;let s=this.activeSessions.get(e);s&&this.activeSessions.set(e,{...s,username:n,remoteAddress:i})}listActiveSessions(){return wt.mark("listActiveSessions"),Array.from(this.activeSessions.values()).sort((e,n)=>e.startedAt.localeCompare(n.startedAt))}listUsers(){return Array.from(this.users.keys()).sort()}loadFromVfs(){if(this.users.clear(),!this.vfs.exists(this.usersPath))return;let e=this.vfs.readFile(this.usersPath);for(let n of e.split(`
246
+ `)){let i=n.trim();if(i.length===0)continue;let s=i.split(":");if(s.length<3)continue;let[o,a,c]=s;!o||!a||!c||this.users.set(o,{username:o,salt:a,passwordHash:c})}}loadSudoersFromVfs(){if(this.sudoers.clear(),!this.vfs.exists(this.sudoersPath))return;let e=this.vfs.readFile(this.sudoersPath);for(let n of e.split(`
247
+ `)){let i=n.trim();i.length>0&&this.sudoers.add(i)}}loadQuotasFromVfs(){if(this.quotas.clear(),!this.vfs.exists(this.quotasPath))return;let e=this.vfs.readFile(this.quotasPath);for(let n of e.split(`
248
+ `)){let i=n.trim();if(i.length===0)continue;let[s,o]=i.split(":"),a=Number.parseInt(o??"",10);!s||!Number.isFinite(a)||a<0||this.quotas.set(s,a)}}async persist(){this.vfs.exists(this.authDirPath)||this.vfs.mkdir(this.authDirPath,448);let e=Array.from(this.users.values()).sort((o,a)=>o.username.localeCompare(a.username)).map(o=>[o.username,o.salt,o.passwordHash].join(":")).join(`
249
+ `),n=Array.from(this.sudoers.values()).sort().join(`
79
250
  `),i=Array.from(this.quotas.entries()).sort(([o],[a])=>o.localeCompare(a)).map(([o,a])=>`${o}:${a}`).join(`
80
251
  `),s=!1;s=this.writeIfChanged(this.usersPath,e.length>0?`${e}
81
- `:"",384)||s,s=this.writeIfChanged(this.sudoersPath,r.length>0?`${r}
252
+ `:"",384)||s,s=this.writeIfChanged(this.sudoersPath,n.length>0?`${n}
82
253
  `:"",384)||s,s=this.writeIfChanged(this.quotasPath,i.length>0?`${i}
83
- `:"",384)||s,s&&await this.vfs.flushMirror()}writeIfChanged(e,r,i){return this.vfs.exists(e)&&this.vfs.readFile(e)===r?(this.vfs.chmod(e,i),!1):(this.vfs.writeFile(e,r,{mode:i}),!0)}createRecord(e,r){let i=`${e}:${r}`,s=n.recordCache.get(i);if(s)return s;let o=(0,qr.randomBytes)(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r)};return n.recordCache.set(i,a),a}hasPassword(e){if(wt.mark("hasPassword"),this.getPasswordHash(e)===this.hashPassword(""))return!1;let r=this.users.get(e);return!!r&&!!r.passwordHash}hashPassword(e){return n.fastPasswordHash?(0,qr.createHash)("sha256").update(`${e}`).digest("hex"):(0,qr.scryptSync)(e,"",32).toString("hex")}validateUsername(e){if(!e||e.trim()==="")throw new Error("invalid username");if(!/^[a-z_][a-z0-9_-]{0,31}$/i.test(e))throw new Error("invalid username")}validatePassword(e){if(!e||e.trim()==="")throw new Error("invalid password")}authorizedKeys=new Map;addAuthorizedKey(e,r,i){wt.mark("addAuthorizedKey");let s=this.authorizedKeys.get(e)??[];s.push({algo:r,data:i}),this.authorizedKeys.set(e,s),this.emit("key:add",{username:e,algo:r})}removeAuthorizedKeys(e){this.authorizedKeys.delete(e),this.emit("key:remove",{username:e})}getAuthorizedKeys(e){return this.authorizedKeys.get(e)??[]}};function hd(n){let t=pd.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}var Ln=require("node:fs/promises"),Oa=Xt(require("node:path"),1);pr();var yd=require("node:child_process");var gd=require("node:fs/promises"),Bs=Xt(require("node:path"),1);function Ua(n){return`'${n.replace(/'/g,"'\\''")}'`}function bi(n){return n.replace(/\r\n/g,`
254
+ `:"",384)||s,s&&await this.vfs.flushMirror()}writeIfChanged(e,n,i){return this.vfs.exists(e)&&this.vfs.readFile(e)===n?(this.vfs.chmod(e,i),!1):(this.vfs.writeFile(e,n,{mode:i}),!0)}createRecord(e,n){let i=`${e}:${n}`,s=r.recordCache.get(i);if(s)return s;let o=(0,Hr.randomBytes)(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(n)};return r.recordCache.set(i,a),a}hasPassword(e){if(wt.mark("hasPassword"),this.getPasswordHash(e)===this.hashPassword(""))return!1;let n=this.users.get(e);return!!n&&!!n.passwordHash}hashPassword(e){return r.fastPasswordHash?(0,Hr.createHash)("sha256").update(`${e}`).digest("hex"):(0,Hr.scryptSync)(e,"",32).toString("hex")}validateUsername(e){if(!e||e.trim()==="")throw new Error("invalid username");if(!/^[a-z_][a-z0-9_-]{0,31}$/i.test(e))throw new Error("invalid username")}validatePassword(e){if(!e||e.trim()==="")throw new Error("invalid password")}authorizedKeys=new Map;addAuthorizedKey(e,n,i){wt.mark("addAuthorizedKey");let s=this.authorizedKeys.get(e)??[];s.push({algo:n,data:i}),this.authorizedKeys.set(e,s),this.emit("key:add",{username:e,algo:n})}removeAuthorizedKeys(e){this.authorizedKeys.delete(e),this.emit("key:remove",{username:e})}getAuthorizedKeys(e){return this.authorizedKeys.get(e)??[]}};function Sd(r){let t=Id.posix.normalize(r);return t.startsWith("/")?t:`/${t}`}var La=[{name:"vim",version:"2:9.0.1378-2",section:"editors",description:"Vi IMproved - enhanced vi editor",shortDesc:"Vi IMproved",installedSizeKb:3812,files:[{path:"/usr/bin/vim",content:`#!/bin/sh
255
+ echo 'vim: use nano for editing in this environment'
256
+ `,mode:493},{path:"/usr/bin/vi",content:`#!/bin/sh
257
+ exec vim "$@"
258
+ `,mode:493},{path:"/usr/share/doc/vim/README",content:`Vim editor \u2014 virtual package.
259
+ `}]},{name:"git",version:"1:2.39.2-1",section:"vcs",description:"Fast, scalable, distributed revision control system",shortDesc:"fast distributed version control system",installedSizeKb:11240,files:[{path:"/usr/bin/git",content:`#!/bin/sh
260
+ echo 'git: virtual stub \u2014 no host access'
261
+ `,mode:493},{path:"/usr/share/doc/git/README.Debian",content:`Git virtual package for Fortune GNU/Linux.
262
+ `}]},{name:"python3",version:"3.11.2-1+b1",section:"python",description:"Interactive high-level object-oriented language (version 3)",shortDesc:"interactive high-level object-oriented language",installedSizeKb:512,depends:["python3-minimal"],files:[{path:"/usr/bin/python3",content:`#!/bin/sh
263
+ echo 'Python 3.11.2 (virtual)'
264
+ `,mode:493},{path:"/usr/bin/python3.11",content:`#!/bin/sh
265
+ exec python3 "$@"
266
+ `,mode:493},{path:"/usr/lib/python3.11/.keep",content:""}]},{name:"python3-minimal",version:"3.11.2-1+b1",section:"python",description:"Minimal subset of the Python language (version 3)",shortDesc:"minimal subset of Python language",installedSizeKb:196,files:[{path:"/usr/lib/python3-minimal/.keep",content:""}]},{name:"nodejs",version:"18.19.0+dfsg-6",section:"javascript",description:"Evented I/O for V8 javascript - runtime executable",shortDesc:"Node.js JavaScript runtime",installedSizeKb:15360,files:[{path:"/usr/bin/node",content:`#!/bin/sh
267
+ echo 'node v18.19.0 (virtual)'
268
+ `,mode:493},{path:"/usr/bin/nodejs",content:`#!/bin/sh
269
+ exec node "$@"
270
+ `,mode:493},{path:"/usr/share/doc/nodejs/README",content:`Node.js virtual package.
271
+ `}]},{name:"npm",version:"9.2.0~ds1-2",section:"javascript",description:"package manager for Node.js",shortDesc:"package manager for Node.js",installedSizeKb:9814,depends:["nodejs"],files:[{path:"/usr/bin/npm",content:`#!/bin/sh
272
+ echo 'npm 9.2.0 (virtual)'
273
+ `,mode:493}]},{name:"curl",version:"7.88.1-10+deb12u5",section:"web",description:"command line tool for transferring data with URL syntax",shortDesc:"command line tool for transferring data",installedSizeKb:368,files:[{path:"/usr/bin/curl",content:`#!/bin/sh
274
+ exec builtin curl "$@"
275
+ `,mode:493}]},{name:"wget",version:"1.21.3-1+b2",section:"web",description:"Retrieves files from the web",shortDesc:"retrieves files from the web",installedSizeKb:952,files:[{path:"/usr/bin/wget",content:`#!/bin/sh
276
+ exec builtin wget "$@"
277
+ `,mode:493}]},{name:"htop",version:"3.2.2-2",section:"utils",description:"interactive processes viewer",shortDesc:"interactive process viewer",installedSizeKb:412,files:[{path:"/usr/bin/htop",content:`#!/bin/sh
278
+ exec builtin htop
279
+ `,mode:493}]},{name:"openssh-client",version:"1:9.2p1-2+deb12u2",section:"net",description:"Secure Shell (SSH) client",shortDesc:"secure shell (SSH) client",installedSizeKb:4540,files:[{path:"/usr/bin/ssh",content:`#!/bin/sh
280
+ echo 'ssh: virtual stub'
281
+ `,mode:493},{path:"/usr/bin/ssh-keygen",content:`#!/bin/sh
282
+ echo 'ssh-keygen: virtual stub'
283
+ `,mode:493},{path:"/etc/ssh/ssh_config",content:`Host *
284
+ StrictHostKeyChecking ask
285
+ `}]},{name:"openssh-server",version:"1:9.2p1-2+deb12u2",section:"net",description:"Secure Shell server (sshd)",shortDesc:"secure shell server",installedSizeKb:1732,depends:["openssh-client"],files:[{path:"/usr/sbin/sshd",content:`#!/bin/sh
286
+ echo 'sshd: virtual \u2014 server already running'
287
+ `,mode:493},{path:"/etc/ssh/sshd_config",content:`Port 22
288
+ PermitRootLogin yes
289
+ PasswordAuthentication yes
290
+ `}]},{name:"net-tools",version:"2.10-0.1",section:"net",description:"NET-3 networking toolkit (ifconfig, netstat, route)",shortDesc:"networking toolkit",installedSizeKb:988,files:[{path:"/usr/bin/ifconfig",content:`#!/bin/sh
291
+ echo 'eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500'
292
+ echo ' inet 10.0.0.2 netmask 255.255.255.0 broadcast 10.0.0.255'
293
+ echo ' ether 02:42:0a:00:00:02 txqueuelen 0 (Ethernet)'
294
+ `,mode:493},{path:"/usr/bin/netstat",content:`#!/bin/sh
295
+ echo 'Active Internet connections (only servers)'
296
+ echo 'Proto Recv-Q Send-Q Local Address Foreign Address State'
297
+ `,mode:493},{path:"/usr/bin/route",content:`#!/bin/sh
298
+ echo 'Kernel IP routing table'
299
+ echo 'Destination Gateway Genmask Flags Metric Ref Use Iface'
300
+ echo '0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 eth0'
301
+ `,mode:493}]},{name:"iputils-ping",version:"3:20221126-1",section:"net",description:"Tools to test the reachability of network hosts",shortDesc:"test reachability of network hosts",installedSizeKb:164,files:[{path:"/usr/bin/ping",content:`#!/bin/sh
302
+ exec builtin ping "$@"
303
+ `,mode:493}]},{name:"jq",version:"1.6-2.1",section:"utils",description:"Lightweight and flexible command-line JSON processor",shortDesc:"command-line JSON processor",installedSizeKb:296,files:[{path:"/usr/bin/jq",content:`#!/bin/sh
304
+ echo 'jq: virtual stub \u2014 pipe JSON here'
305
+ `,mode:493}]},{name:"build-essential",version:"12.9",section:"devel",description:"Informational list of build-essential packages",shortDesc:"build-essential meta-package",installedSizeKb:12,depends:["gcc","g++","make"],files:[{path:"/usr/share/doc/build-essential/README",content:`Build-essential virtual meta-package.
306
+ `}]},{name:"gcc",version:"4:12.2.0-3",section:"devel",description:"GNU C compiler",shortDesc:"GNU C compiler",installedSizeKb:24448,files:[{path:"/usr/bin/gcc",content:`#!/bin/sh
307
+ echo 'gcc (Fortune GNU/Linux) 12.2.0 (virtual)'
308
+ `,mode:493},{path:"/usr/bin/gcc-12",content:`#!/bin/sh
309
+ exec gcc "$@"
310
+ `,mode:493}]},{name:"g++",version:"4:12.2.0-3",section:"devel",description:"GNU C++ compiler",shortDesc:"GNU C++ compiler",installedSizeKb:1024,depends:["gcc"],files:[{path:"/usr/bin/g++",content:`#!/bin/sh
311
+ echo 'g++ (Fortune GNU/Linux) 12.2.0 (virtual)'
312
+ `,mode:493}]},{name:"make",version:"4.3-4.1",section:"devel",description:"Utility for directing compilation",shortDesc:"build utility",installedSizeKb:504,files:[{path:"/usr/bin/make",content:`#!/bin/sh
313
+ echo 'make: *** No targets specified and no makefile found. Stop.'
314
+ exit 2
315
+ `,mode:493}]},{name:"less",version:"590-2",section:"text",description:"Pager program similar to more",shortDesc:"pager program",installedSizeKb:328,files:[{path:"/usr/bin/less",content:`#!/bin/sh
316
+ cat "$@"
317
+ `,mode:493}]},{name:"unzip",version:"6.0-28",section:"utils",description:"De-archiver for .zip files",shortDesc:"de-archiver for .zip files",installedSizeKb:464,files:[{path:"/usr/bin/unzip",content:`#!/bin/sh
318
+ echo 'unzip: virtual stub'
319
+ `,mode:493}]},{name:"rsync",version:"3.2.7-1",section:"net",description:"Fast, versatile, remote (and local) file-copying tool",shortDesc:"fast remote file copy program",installedSizeKb:716,files:[{path:"/usr/bin/rsync",content:`#!/bin/sh
320
+ echo 'rsync: virtual stub'
321
+ `,mode:493}]},{name:"tmux",version:"3.3a-3",section:"utils",description:"Terminal multiplexer",shortDesc:"terminal multiplexer",installedSizeKb:812,files:[{path:"/usr/bin/tmux",content:`#!/bin/sh
322
+ echo 'tmux: terminal multiplexer (virtual stub)'
323
+ `,mode:493}]},{name:"tree",version:"2.1.0-1",section:"utils",description:"Displays an indented directory tree, in color",shortDesc:"list files in tree format",installedSizeKb:108,files:[{path:"/usr/bin/tree",content:`#!/bin/sh
324
+ exec builtin tree "$@"
325
+ `,mode:493}]},{name:"ca-certificates",version:"20230311",section:"misc",description:"Common CA certificates",shortDesc:"common CA certificates",installedSizeKb:388,files:[{path:"/etc/ssl/certs/.keep",content:""},{path:"/etc/ssl/private/.keep",content:""},{path:"/usr/share/ca-certificates/.keep",content:""}],onInstall:r=>{r.exists("/etc/ssl")||r.mkdir("/etc/ssl",493),r.exists("/etc/ssl/certs")||r.mkdir("/etc/ssl/certs",493)}},{name:"locales",version:"2.36-9+deb12u3",section:"localization",description:"GNU C Library: National Language (locale) data",shortDesc:"locale data",installedSizeKb:16484,files:[{path:"/etc/locale.gen",content:`en_US.UTF-8 UTF-8
326
+ `},{path:"/etc/default/locale",content:`LANG=en_US.UTF-8
327
+ LANGUAGE=en_US:en
328
+ `}]},{name:"sudo",version:"1.9.13p3-1+deb12u1",section:"admin",description:"Provide limited super user privileges to specific users",shortDesc:"super user privilege execution",installedSizeKb:2304,files:[{path:"/usr/bin/sudo",content:`#!/bin/sh
329
+ exec builtin sudo "$@"
330
+ `,mode:493},{path:"/etc/sudoers",content:`root ALL=(ALL:ALL) ALL
331
+ %sudo ALL=(ALL:ALL) ALL
332
+ `}]},{name:"systemd",version:"252.22-1~deb12u1",section:"admin",description:"System and service manager",shortDesc:"system and service manager",installedSizeKb:26624,files:[{path:"/usr/bin/systemctl",content:`#!/bin/sh
333
+ echo 'systemd is not running in this virtual container.'
334
+ exit 1
335
+ `,mode:493},{path:"/usr/bin/journalctl",content:`#!/bin/sh
336
+ echo 'journalctl: virtual stub'
337
+ `,mode:493}]}],bi=class{constructor(t,e){this.vfs=t;this.users=e}vfs;users;installed=new Map;registryPath="/var/lib/dpkg/status";logPath="/var/log/dpkg.log";aptLogPath="/var/log/apt/history.log";load(){if(!this.vfs.exists(this.registryPath))return;let t=this.vfs.readFile(this.registryPath);if(!t.trim())return;let e=t.split(/\n\n+/);for(let n of e){if(!n.trim())continue;let i=this.parseFields(n),s=i.Package;s&&this.installed.set(s,{name:s,version:i.Version??"unknown",architecture:i.Architecture??"amd64",maintainer:i.Maintainer??"Fortune Maintainers",description:i.Description??"",section:i.Section??"misc",installedSizeKb:Number(i["Installed-Size"]??0),installedAt:i["X-Installed-At"]??new Date().toISOString(),files:(i["X-Files"]??"").split("|").filter(Boolean)})}}persist(){let t=[];for(let e of this.installed.values())t.push([`Package: ${e.name}`,"Status: install ok installed","Priority: optional",`Section: ${e.section}`,`Installed-Size: ${e.installedSizeKb}`,`Maintainer: ${e.maintainer}`,`Architecture: ${e.architecture}`,`Version: ${e.version}`,`Description: ${e.description}`,`X-Installed-At: ${e.installedAt}`,`X-Files: ${e.files.join("|")}`].join(`
338
+ `));this.vfs.writeFile(this.registryPath,`${t.join(`
339
+
340
+ `)}
341
+ `)}parseFields(t){let e={};for(let n of t.split(`
342
+ `)){let i=n.indexOf(": ");i!==-1&&(e[n.slice(0,i)]=n.slice(i+2))}return e}log(t){let n=`${new Date().toISOString().replace("T"," ").slice(0,19)} ${t}
343
+ `,i=this.vfs.exists(this.logPath)?this.vfs.readFile(this.logPath):"";this.vfs.writeFile(this.logPath,i+n)}aptLog(t,e){let n=new Date().toISOString(),i=this.vfs.exists(this.aptLogPath)?this.vfs.readFile(this.aptLogPath):"",s=[`Start-Date: ${n}`,`Commandline: apt-get ${t} ${e.join(" ")}`,`${t==="install"?"Install":"Remove"}: ${e.join(", ")}`,`End-Date: ${n}`,""].join(`
344
+ `);this.vfs.writeFile(this.aptLogPath,i+s)}findInRegistry(t){return La.find(e=>e.name.toLowerCase()===t.toLowerCase())}listAvailable(){return[...La].sort((t,e)=>t.name.localeCompare(e.name))}listInstalled(){return[...this.installed.values()].sort((t,e)=>t.name.localeCompare(e.name))}isInstalled(t){return this.installed.has(t.toLowerCase())}installedCount(){return this.installed.size}install(t,e={}){let n=[],i=[],s=[],o=(c,f=new Set)=>{if(f.has(c)||(f.add(c),this.isInstalled(c)))return;let l=this.findInRegistry(c);if(!l){s.push(c);return}for(let u of l.depends??[])o(u,f);i.find(u=>u.name===l.name)||i.push(l)};for(let c of t)o(c);if(s.length>0)return{output:`E: Unable to locate package ${s.join(", ")}`,exitCode:100};if(i.length===0)return{output:t.map(c=>`${c} is already the newest version.`).join(`
345
+ `),exitCode:0};let a=i.reduce((c,f)=>c+(f.installedSizeKb??0),0);e.quiet||n.push("Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","The following NEW packages will be installed:",` ${i.map(c=>c.name).join(" ")}`,`0 upgraded, ${i.length} newly installed, 0 to remove and 0 not upgraded.`,`Need to get 0 B/${a} kB of archives.`,`After this operation, ${a} kB of additional disk space will be used.`,"");for(let c of i){e.quiet||(n.push(`Selecting previously unselected package ${c.name}.`),n.push("(Reading database ... 12345 files and directories currently installed.)"),n.push(`Preparing to unpack .../archives/${c.name}_${c.version}_amd64.deb ...`),n.push(`Unpacking ${c.name} (${c.version}) ...`));for(let l of c.files??[]){let u=l.path.slice(0,l.path.lastIndexOf("/"));u&&!this.vfs.exists(u)&&this.vfs.mkdir(u,493),this.vfs.writeFile(l.path,l.content,{mode:l.mode??420})}c.onInstall?.(this.vfs,this.users),e.quiet||n.push(`Setting up ${c.name} (${c.version}) ...`);let f=new Date().toISOString();this.installed.set(c.name,{name:c.name,version:c.version,architecture:c.architecture??"amd64",maintainer:c.maintainer??"Fortune Maintainers <pkg@fortune.local>",description:c.description,section:c.section??"misc",installedSizeKb:c.installedSizeKb??0,installedAt:f,files:(c.files??[]).map(l=>l.path)}),this.log(`install ${c.name} ${c.version}`)}return this.aptLog("install",i.map(c=>c.name)),this.persist(),e.quiet||n.push("Processing triggers for man-db (2.11.2-2) ..."),{output:n.join(`
346
+ `),exitCode:0}}remove(t,e={}){let n=[],i=[];for(let s of t){let o=this.installed.get(s.toLowerCase());o?i.push(o):n.push(`Package '${s}' is not installed, so not removed`)}if(i.length===0)return{output:n.join(`
347
+ `)||"Nothing to remove.",exitCode:0};e.quiet||n.push("Reading package lists... Done","Building dependency tree... Done","The following packages will be REMOVED:",` ${i.map(s=>s.name).join(" ")}`,`0 upgraded, 0 newly installed, ${i.length} to remove and 0 not upgraded.`);for(let s of i){e.quiet||n.push(`Removing ${s.name} (${s.version}) ...`);for(let a of s.files)if(!(!e.purge&&(a.startsWith("/etc/")||a.endsWith(".conf"))))try{this.vfs.exists(a)&&this.vfs.remove(a)}catch{}this.findInRegistry(s.name)?.onRemove?.(this.vfs),this.installed.delete(s.name),this.log(`remove ${s.name} ${s.version}`)}return this.aptLog("remove",i.map(s=>s.name)),this.persist(),{output:n.join(`
348
+ `),exitCode:0}}search(t){let e=t.toLowerCase();return La.filter(n=>n.name.includes(e)||n.description.toLowerCase().includes(e)||(n.shortDesc??"").toLowerCase().includes(e)).sort((n,i)=>n.name.localeCompare(i.name))}show(t){let e=this.findInRegistry(t);if(!e)return null;let n=this.installed.get(t);return[`Package: ${e.name}`,`Version: ${e.version}`,`Architecture: ${e.architecture??"amd64"}`,`Maintainer: ${e.maintainer??"Fortune Maintainers <pkg@fortune.local>"}`,`Installed-Size: ${e.installedSizeKb??0}`,`Depends: ${(e.depends??[]).join(", ")||"(none)"}`,`Section: ${e.section??"misc"}`,"Priority: optional",`Description: ${e.description}`,`Status: ${n?"install ok installed":"install ok not-installed"}`].join(`
349
+ `)}};var Pn=$t(require("node:os"),1);function we(r,t,e=493){r.exists(t)||r.mkdir(t,e)}function it(r,t,e,n=420){r.exists(t)||r.writeFile(t,e,{mode:n})}function Lm(r,t,e){we(r,"/etc"),it(r,"/etc/os-release",`${['NAME="Fortune GNU/Linux"',`PRETTY_NAME="${e.os}"`,"ID=fortune","ID_LIKE=debian",'HOME_URL="https://github.com/itsrealfortune/typescript-virtual-container"',"VERSION_CODENAME=aurora",'VERSION_ID="1.0"'].join(`
350
+ `)}
351
+ `),it(r,"/etc/debian_version",`12.0
352
+ `),it(r,"/etc/hostname",`${t}
353
+ `),it(r,"/etc/shells",`/bin/sh
354
+ /bin/bash
355
+ /usr/bin/bash
356
+ `),it(r,"/etc/profile",`${["export PATH=/usr/local/bin:/usr/bin:/bin","export PS1='\\u@\\h:\\w\\$ '"].join(`
357
+ `)}
358
+ `),it(r,"/etc/issue",`Fortune GNU/Linux 1.0 \\n \\l
359
+ `),it(r,"/etc/motd",["",`Welcome to ${e.os}`,`Kernel: ${e.kernel}`,""].join(`
360
+ `)),we(r,"/etc/apt"),we(r,"/etc/apt/sources.list.d"),it(r,"/etc/apt/sources.list",`${["# Fortune GNU/Linux package sources","deb [virtual] fortune://packages.fortune.local aurora main contrib","deb [virtual] fortune://security.fortune.local aurora-security main"].join(`
361
+ `)}
362
+ `),we(r,"/etc/network"),it(r,"/etc/network/interfaces",`${["auto lo","iface lo inet loopback","","auto eth0","iface eth0 inet dhcp"].join(`
363
+ `)}
364
+ `),it(r,"/etc/resolv.conf",`nameserver 1.1.1.1
365
+ nameserver 8.8.8.8
366
+ `),it(r,"/etc/hosts",`${["127.0.0.1 localhost",`127.0.1.1 ${t}`,"::1 localhost ip6-localhost ip6-loopback"].join(`
367
+ `)}
368
+ `),we(r,"/etc/cron.d"),we(r,"/etc/init.d"),we(r,"/etc/systemd"),we(r,"/etc/systemd/system")}function Ua(r,t){let e=t.listUsers(),n=["root:x:0:0:root:/root:/bin/bash","daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin","www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin","nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin"],i=1e3;for(let a of e)a!=="root"&&(n.push(`${a}:x:${i}:${i}::/home/${a}:/bin/bash`),i++);r.writeFile("/etc/passwd",`${n.join(`
369
+ `)}
370
+ `);let s=["root:x:0:","daemon:x:1:",`sudo:x:27:${e.filter(a=>t.isSudoer(a)).join(",")}`,`users:x:100:${e.filter(a=>a!=="root").join(",")}`,"nogroup:x:65534:"];r.writeFile("/etc/group",`${s.join(`
371
+ `)}
372
+ `);let o=["root:*:19000:0:99999:7:::","daemon:*:19000:0:99999:7:::"];for(let a of e)a!=="root"&&o.push(`${a}:!:19000:0:99999:7:::`);r.writeFile("/etc/shadow",`${o.join(`
373
+ `)}
374
+ `,{mode:416})}function Da(r,t,e,n){we(r,"/proc");let i=Math.floor((Date.now()-n)/1e3);r.writeFile("/proc/uptime",`${i}.00 ${Math.floor(i*.9)}.00
375
+ `);let s=Math.floor(Pn.totalmem()/1024),o=Math.floor(Pn.freemem()/1024),a=Math.floor(o*.95);r.writeFile("/proc/meminfo",`${[`MemTotal: ${String(s).padStart(10)} kB`,`MemFree: ${String(o).padStart(10)} kB`,`MemAvailable: ${String(a).padStart(10)} kB`,`Buffers: ${String(Math.floor(s*.02)).padStart(10)} kB`,`Cached: ${String(Math.floor(s*.15)).padStart(10)} kB`,`SwapTotal: ${String(Math.floor(s*.5)).padStart(10)} kB`,`SwapFree: ${String(Math.floor(s*.5)).padStart(10)} kB`].join(`
376
+ `)}
377
+ `);let c=Pn.cpus(),f=[];for(let u=0;u<c.length;u++){let h=c[u];if(!h)continue;let g=h.speed.toFixed(3);f.push(`processor : ${u}`,`model name : ${h.model}`,`cpu MHz : ${g}`,"cache size : 8192 KB","")}r.writeFile("/proc/cpuinfo",`${f.join(`
378
+ `)}
379
+ `),r.writeFile("/proc/version",`Linux version ${t.kernel} (fortune@build) (gcc version 12.2.0) #1 SMP
380
+ `),r.writeFile("/proc/hostname",`${e}
381
+ `);let l=(Math.random()*.5).toFixed(2);r.writeFile("/proc/loadavg",`${l} ${l} ${l} 1/1 1
382
+ `),we(r,"/proc/net"),it(r,"/proc/net/dev",`${["Inter-| Receive | Transmit"," face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed"," lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"," eth0: 131072 1024 0 0 0 0 0 0 65536 512 0 0 0 0 0 0"].join(`
383
+ `)}
384
+ `)}function Um(r,t){we(r,"/sys"),we(r,"/sys/devices"),we(r,"/sys/devices/virtual"),we(r,"/sys/devices/virtual/dmi"),we(r,"/sys/devices/virtual/dmi/id"),it(r,"/sys/devices/virtual/dmi/id/sys_vendor",`Fortune Systems
385
+ `),it(r,"/sys/devices/virtual/dmi/id/product_name",`VirtualContainer v1
386
+ `),it(r,"/sys/devices/virtual/dmi/id/board_name",`fortune-board
387
+ `),we(r,"/sys/class"),we(r,"/sys/class/net"),we(r,"/sys/kernel"),it(r,"/sys/kernel/hostname",`fortune-vm
388
+ `),it(r,"/sys/kernel/osrelease",`${t.kernel}
389
+ `),it(r,"/sys/kernel/ostype",`Linux
390
+ `)}function Dm(r){we(r,"/dev"),it(r,"/dev/null","",438),it(r,"/dev/zero","",438),it(r,"/dev/random","",292),it(r,"/dev/urandom","",292),we(r,"/dev/pts"),we(r,"/dev/shm")}function Om(r){we(r,"/usr"),we(r,"/usr/bin"),we(r,"/usr/sbin"),we(r,"/usr/local"),we(r,"/usr/local/bin"),we(r,"/usr/local/lib"),we(r,"/usr/local/share"),we(r,"/usr/share"),we(r,"/usr/share/doc"),we(r,"/usr/share/man"),we(r,"/usr/share/man/man1"),we(r,"/usr/lib");let t=["sh","bash","ls","cat","echo","grep","find","sort","head","tail","cut","tr","sed","awk","wc","tee","tar","gzip","gunzip","touch","mkdir","rm","mv","cp","chmod","ln","pwd","env","date","sleep","id","whoami","hostname","uname","ps","kill","df","du","curl","wget","nano","diff","uniq","xargs","base64"];for(let e of t)it(r,`/usr/bin/${e}`,`#!/bin/sh
391
+ exec builtin ${e} "$@"
392
+ `,493);it(r,"/usr/bin/lsb_release",`#!/bin/sh
393
+ exec lsb_release "$@"
394
+ `,493)}function Mm(r){we(r,"/var"),we(r,"/var/log"),we(r,"/var/tmp"),we(r,"/var/run"),we(r,"/var/cache"),we(r,"/var/cache/apt"),we(r,"/var/cache/apt/archives"),we(r,"/var/lib"),we(r,"/var/lib/apt"),we(r,"/var/lib/apt/lists"),we(r,"/var/lib/dpkg"),we(r,"/var/lib/dpkg/info"),it(r,"/var/lib/dpkg/status",""),it(r,"/var/lib/dpkg/available",""),it(r,"/var/log/syslog",`${new Date().toUTCString()} fortune kernel: Virtual container started
395
+ `),it(r,"/var/log/auth.log",""),it(r,"/var/log/dpkg.log",""),it(r,"/var/log/apt/history.log",""),it(r,"/var/log/apt/term.log","")}function Fm(r){r.exists("/bin")||r.symlink("/usr/bin","/bin"),r.exists("/sbin")||r.symlink("/usr/sbin","/sbin"),r.exists("/lib")||we(r,"/lib"),r.exists("/lib64")||we(r,"/lib64")}function $m(r){we(r,"/tmp",1023)}function Hm(r){we(r,"/root",448),it(r,"/root/.bashrc",`${["# root .bashrc","export PS1='\\[\\033[0;31m\\]\\u@\\h\\[\\033[0m\\]:\\[\\033[0;34m\\]\\w\\[\\033[0m\\]# '","export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","alias ll='ls -la'","alias la='ls -A'"].join(`
396
+ `)}
397
+ `),it(r,"/root/.profile",`[ -f ~/.bashrc ] && . ~/.bashrc
398
+ `),r.exists("/home/root")||r.symlink("/root","/home/root")}function Qm(r){we(r,"/opt"),we(r,"/srv"),we(r,"/mnt"),we(r,"/media")}function Cd(r,t,e,n,i){Lm(r,e,n),Um(r,n),Dm(r),Om(r),Mm(r),Fm(r),$m(r),Hm(r),Qm(r),Da(r,n,e,i),Ua(r,t)}var Tn=require("node:fs/promises"),Ma=$t(require("node:path"),1);var Pd=require("node:child_process");var vd=require("node:fs/promises"),Cs=$t(require("node:path"),1);function Oa(r){return`'${r.replace(/'/g,"'\\''")}'`}function yi(r){return r.replace(/\r\n/g,`
84
399
  `).replace(/\r/g,`
85
400
  `).replace(/\n/g,`\r
86
- `)}function md(n,t){let e=Number.isFinite(t.cols)&&t.cols>0?Math.floor(t.cols):80,r=Number.isFinite(t.rows)&&t.rows>0?Math.floor(t.rows):24;return`stty cols ${e} rows ${r} 2>/dev/null; ${n}`}function Ad(n,t){return!t||t.trim()===""||t==="."?n:t.startsWith("/")?Bs.posix.normalize(t):Bs.posix.normalize(Bs.posix.join(n,t))}async function Ed(n){try{let e=(await(0,gd.readFile)(`/proc/${n}/task/${n}/children`,"utf8")).trim().split(/\s+/).filter(Boolean).map(i=>Number.parseInt(i,10)).filter(i=>Number.isInteger(i)&&i>0),r=await Promise.all(e.map(i=>Ed(i)));return[...e,...r.flat()]}catch{return[]}}async function _d(n=process.pid){let t=await Ed(n),e=Array.from(new Set(t)).sort((r,i)=>r-i);return e.length===0?null:e.join(",")}function bd(n,t,e){let r=md(n,t),i=(0,yd.spawn)("script",["-qfec",r,"/dev/null"],{stdio:["pipe","pipe","pipe"],env:{...process.env,TERM:process.env.TERM??"xterm-256color"}});return i.stdout.on("data",s=>{e.write(s.toString("utf8"))}),i.stderr.on("data",s=>{e.write(s.toString("utf8"))}),i}function xd(n,t,e){return bd(`nano -- ${Ua(n)}`,t,e)}function Sd(n,t,e){return bd(`htop -p ${Ua(n)}`,t,e)}Hs();function wd(n,t,e){let r=n==="root",i=r?"\x1B[31;1m":"\x1B[35;1m",s="\x1B[37;1m",o="\x1B[34;1m",a="\x1B[0m";return`${s}[${i}${n}${s}@${o}${t}${a} ${e}${s}]${a}${r?"#":"$"} `}function Id(n,t,e,r,i,s="unknown",o={cols:80,rows:24},a){let c="",f=0,u=wA(a.vfs),h=null,d="",g=`/home/${e}`,_=qn(e,r),y=null,x=null,I=()=>{let C=`/home/${e}`,v=g===C?"~":Oa.posix.basename(g)||"/";return wd(e,r,v)},O=Array.from(new Set(Ou())).sort();console.log(`[${i}] Shell started for user '${e}' at ${s}`),(async()=>{let C=`/home/${e}/.bashrc`;if(a.vfs.exists(C))try{let v=a.vfs.readFile(C);for(let D of v.split(`
87
- `)){let G=D.trim();!G||G.startsWith("#")||await kt(G,e,r,"shell",g,a,void 0,_)}}catch{}})();function $(){let C=I();t.write(`\r${C}${c}\x1B[K`);let v=c.length-f;v>0&&t.write(`\x1B[${v}D`)}function L(){t.write("\r\x1B[K")}function j(C){x={...C,buffer:""},L(),t.write(C.prompt)}async function J(C){if(!x)return;let v=x;if(x=null,!C){t.write(`\r
401
+ `)}function kd(r,t){let e=Number.isFinite(t.cols)&&t.cols>0?Math.floor(t.cols):80,n=Number.isFinite(t.rows)&&t.rows>0?Math.floor(t.rows):24;return`stty cols ${e} rows ${n} 2>/dev/null; ${r}`}function Bd(r,t){return!t||t.trim()===""||t==="."?r:t.startsWith("/")?Cs.posix.normalize(t):Cs.posix.normalize(Cs.posix.join(r,t))}async function Rd(r){try{let e=(await(0,vd.readFile)(`/proc/${r}/task/${r}/children`,"utf8")).trim().split(/\s+/).filter(Boolean).map(i=>Number.parseInt(i,10)).filter(i=>Number.isInteger(i)&&i>0),n=await Promise.all(e.map(i=>Rd(i)));return[...e,...n.flat()]}catch{return[]}}async function Nd(r=process.pid){let t=await Rd(r),e=Array.from(new Set(t)).sort((n,i)=>n-i);return e.length===0?null:e.join(",")}function Td(r,t,e){let n=kd(r,t),i=(0,Pd.spawn)("script",["-qfec",n,"/dev/null"],{stdio:["pipe","pipe","pipe"],env:{...process.env,TERM:process.env.TERM??"xterm-256color"}});return i.stdout.on("data",s=>{e.write(s.toString("utf8"))}),i.stderr.on("data",s=>{e.write(s.toString("utf8"))}),i}function Ld(r,t,e){return Td(`nano -- ${Oa(r)}`,t,e)}function Ud(r,t,e){return Td(`htop -p ${Oa(r)}`,t,e)}function Dd(r,t,e){let n=r==="root",i=n?"\x1B[31;1m":"\x1B[35;1m",s="\x1B[37;1m",o="\x1B[34;1m",a="\x1B[0m";return`${s}[${i}${r}${s}@${o}${t}${a} ${e}${s}]${a}${n?"#":"$"} `}function Od(r,t,e,n,i,s="unknown",o={cols:80,rows:24},a){let c="",f=0,l=Wm(a.vfs),u=null,h="",g=`/home/${e}`,b=Wn(e,n),_=null,x=null,S=()=>{let C=`/home/${e}`,k=g===C?"~":Ma.posix.basename(g)||"/";return Dd(e,n,k)},N=Array.from(new Set($f())).sort();console.log(`[${i}] Shell started for user '${e}' at ${s}`),(async()=>{let C=`/home/${e}/.bashrc`;if(a.vfs.exists(C))try{let k=a.vfs.readFile(C);for(let M of k.split(`
402
+ `)){let Y=M.trim();!Y||Y.startsWith("#")||await St(Y,e,n,"shell",g,a,void 0,b)}}catch{}})();function O(){let C=S();t.write(`\r${C}${c}\x1B[K`);let k=c.length-f;k>0&&t.write(`\x1B[${k}D`)}function P(){t.write("\r\x1B[K")}function W(C){x={...C,buffer:""},P(),t.write(C.prompt)}async function X(C){if(!x)return;let k=x;if(x=null,!C){t.write(`\r
88
403
  Sorry, try again.\r
89
- `),$();return}if(!v.commandLine){e=v.targetUser,g=`/home/${e}`,a.users.updateSession(i,e,s),t.write(`\r
90
- `),$();return}let D=v.loginShell?`/home/${v.targetUser}`:g,G=await Promise.resolve(kt(v.commandLine,v.targetUser,r,"shell",D,a));if(t.write(`\r
91
- `),G.openEditor){await S(G.openEditor.targetPath,G.openEditor.initialContent,G.openEditor.tempPath);return}if(G.openHtop){await w();return}G.clearScreen&&t.write("\x1B[2J\x1B[H"),G.stdout&&t.write(`${bi(G.stdout)}\r
92
- `),G.stderr&&t.write(`${bi(G.stderr)}\r
93
- `),G.switchUser?(e=G.switchUser,g=G.nextCwd??`/home/${e}`,a.users.updateSession(i,e,s)):G.nextCwd&&(g=G.nextCwd),await a.vfs.flushMirror(),$()}async function z(){if(!y)return;let C=y;if(C.kind==="nano"){try{let v=await(0,Ln.readFile)(C.tempPath,"utf8");a.writeFileAsUser(e,C.targetPath,v),await a.vfs.flushMirror()}catch{}await(0,Ln.unlink)(C.tempPath).catch(()=>{})}y=null,c="",f=0,t.write(`\r
94
- `),$()}async function S(C,v,D){a.vfs.exists(C)&&await(0,Ln.writeFile)(D,v,"utf8");let G=xd(D,o,t);G.on("error",se=>{t.write(`nano: ${se.message}\r
95
- `),z()}),G.on("close",()=>{z()}),y={kind:"nano",targetPath:C,tempPath:D,process:G}}async function w(){let C=await _d();if(!C){t.write(`htop: no child_process processes to display\r
96
- `);return}let v=Sd(C,o,t);v.on("error",D=>{t.write(`htop: ${D.message}\r
97
- `),z()}),v.on("close",()=>{z()}),y={kind:"htop",targetPath:"",tempPath:"",process:v}}function U(C){c=C,f=c.length,$()}function W(C){c=`${c.slice(0,f)}${C}${c.slice(f)}`,f+=C.length,$()}function Q(C,v){let D=v;for(;D>0&&!/\s/.test(C[D-1]);)D-=1;let G=v;for(;G<C.length&&!/\s/.test(C[G]);)G+=1;return{start:D,end:G}}function oe(C){let v=C.lastIndexOf("/"),D=v>=0?C.slice(0,v+1):"",G=v>=0?C.slice(v+1):C,se=Ad(g,D||".");try{return a.vfs.list(se).filter(ee=>!ee.startsWith(".")).filter(ee=>ee.startsWith(G)).map(ee=>{let Ve=Oa.posix.join(se,ee),ur=a.vfs.stat(Ve).type==="directory"?"/":"";return`${D}${ee}${ur}`}).sort()}catch{return[]}}function te(){let{start:C,end:v}=Q(c,f),D=c.slice(C,f);if(D.length===0)return;let se=c.slice(0,C).trim().length===0?O.filter(mt=>mt.startsWith(D)):[],ee=oe(D),Ve=Array.from(new Set([...se,...ee])).sort();if(Ve.length!==0){if(Ve.length===1){let mt=Ve[0],ur=mt.endsWith("/")?"":" ";c=`${c.slice(0,C)}${mt}${ur}${c.slice(v)}`,f=C+mt.length+ur.length,$();return}t.write(`\r
98
- `),t.write(`${Ve.join(" ")}\r
99
- `),$()}}function Z(C){if(C.length===0)return;u.push(C),u.length>500&&(u=u.slice(u.length-500));let v=u.length>0?`${u.join(`
404
+ `),O();return}if(!k.commandLine){e=k.targetUser,g=`/home/${e}`,a.users.updateSession(i,e,s),t.write(`\r
405
+ `),O();return}let M=k.loginShell?`/home/${k.targetUser}`:g,Y=await Promise.resolve(St(k.commandLine,k.targetUser,n,"shell",M,a));if(t.write(`\r
406
+ `),Y.openEditor){await w(Y.openEditor.targetPath,Y.openEditor.initialContent,Y.openEditor.tempPath);return}if(Y.openHtop){await I();return}Y.clearScreen&&t.write("\x1B[2J\x1B[H"),Y.stdout&&t.write(`${yi(Y.stdout)}\r
407
+ `),Y.stderr&&t.write(`${yi(Y.stderr)}\r
408
+ `),Y.switchUser?(e=Y.switchUser,g=Y.nextCwd??`/home/${e}`,a.users.updateSession(i,e,s)):Y.nextCwd&&(g=Y.nextCwd),await a.vfs.flushMirror(),O()}async function G(){if(!_)return;let C=_;if(C.kind==="nano"){try{let k=await(0,Tn.readFile)(C.tempPath,"utf8");a.writeFileAsUser(e,C.targetPath,k),await a.vfs.flushMirror()}catch{}await(0,Tn.unlink)(C.tempPath).catch(()=>{})}_=null,c="",f=0,t.write(`\r
409
+ `),O()}async function w(C,k,M){a.vfs.exists(C)&&await(0,Tn.writeFile)(M,k,"utf8");let Y=Ld(M,o,t);Y.on("error",oe=>{t.write(`nano: ${oe.message}\r
410
+ `),G()}),Y.on("close",()=>{G()}),_={kind:"nano",targetPath:C,tempPath:M,process:Y}}async function I(){let C=await Nd();if(!C){t.write(`htop: no child_process processes to display\r
411
+ `);return}let k=Ud(C,o,t);k.on("error",M=>{t.write(`htop: ${M.message}\r
412
+ `),G()}),k.on("close",()=>{G()}),_={kind:"htop",targetPath:"",tempPath:"",process:k}}function D(C){c=C,f=c.length,O()}function q(C){c=`${c.slice(0,f)}${C}${c.slice(f)}`,f+=C.length,O()}function Q(C,k){let M=k;for(;M>0&&!/\s/.test(C[M-1]);)M-=1;let Y=k;for(;Y<C.length&&!/\s/.test(C[Y]);)Y+=1;return{start:M,end:Y}}function ae(C){let k=C.lastIndexOf("/"),M=k>=0?C.slice(0,k+1):"",Y=k>=0?C.slice(k+1):C,oe=Bd(g,M||".");try{return a.vfs.list(oe).filter(ee=>!ee.startsWith(".")).filter(ee=>ee.startsWith(Y)).map(ee=>{let Ye=Ma.posix.join(oe,ee),lr=a.vfs.stat(Ye).type==="directory"?"/":"";return`${M}${ee}${lr}`}).sort()}catch{return[]}}function te(){let{start:C,end:k}=Q(c,f),M=c.slice(C,f);if(M.length===0)return;let oe=c.slice(0,C).trim().length===0?N.filter(gt=>gt.startsWith(M)):[],ee=ae(M),Ye=Array.from(new Set([...oe,...ee])).sort();if(Ye.length!==0){if(Ye.length===1){let gt=Ye[0],lr=gt.endsWith("/")?"":" ";c=`${c.slice(0,C)}${gt}${lr}${c.slice(k)}`,f=C+gt.length+lr.length,O();return}t.write(`\r
413
+ `),t.write(`${Ye.join(" ")}\r
414
+ `),O()}}function Z(C){if(C.length===0)return;l.push(C),l.length>500&&(l=l.slice(l.length-500));let k=l.length>0?`${l.join(`
100
415
  `)}
101
- `:"";a.vfs.writeFile("/virtual-env-js/.bash_history",v)}function re(){let C=`/virtual-env-js/.lastlog/${e}.json`;if(!a.vfs.exists(C))return null;try{return JSON.parse(a.vfs.readFile(C))}catch{return null}}function ae(C){let v="/virtual-env-js/.lastlog";a.vfs.exists(v)||a.vfs.mkdir(v,448);let D=`${v}/${e}.json`;a.vfs.writeFile(D,JSON.stringify({at:C,from:s}))}function T(){let C=re(),v=new Date().toISOString();if(t.write(`Linux ${r} ${n.kernel} ${n.arch}\r
416
+ `:"";a.vfs.writeFile("/virtual-env-js/.bash_history",k)}function re(){let C=`/virtual-env-js/.lastlog/${e}.json`;if(!a.vfs.exists(C))return null;try{return JSON.parse(a.vfs.readFile(C))}catch{return null}}function ce(C){let k="/virtual-env-js/.lastlog";a.vfs.exists(k)||a.vfs.mkdir(k,448);let M=`${k}/${e}.json`;a.vfs.writeFile(M,JSON.stringify({at:C,from:s}))}function U(){let C=re(),k=new Date().toISOString();if(t.write(`Linux ${n} ${r.kernel} ${r.arch}\r
102
417
  `),t.write(`\r
103
418
  `),t.write(`The programs included with the Fortune GNU/Linux system are free software;\r
104
419
  `),t.write(`the exact distribution terms for each program are described in the\r
@@ -106,25 +421,25 @@ Sorry, try again.\r
106
421
  `),t.write(`\r
107
422
  `),t.write(`Fortune GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent\r
108
423
  `),t.write(`permitted by applicable law.\r
109
- `),C){let D=new Date(C.at),G=Number.isNaN(D.getTime())?C.at:Ri(D);t.write(`Last login: ${G} from ${C.from||"unknown"}\r
424
+ `),C){let M=new Date(C.at),Y=Number.isNaN(M.getTime())?C.at:Bi(M);t.write(`Last login: ${Y} from ${C.from||"unknown"}\r
110
425
  `)}t.write(`\r
111
- `),ae(v)}T(),$(),t.on("data",async C=>{if(y){y.process.stdin.write(C);return}if(x){let D=C.toString("utf8");for(let G=0;G<D.length;G+=1){let se=D[G];if(se===""){x=null,t.write(`^C\r
112
- `),$();return}if(se==="\x7F"||se==="\b"){x.buffer=x.buffer.slice(0,-1);continue}if(se==="\r"||se===`
113
- `){let ee=x.buffer;x.buffer="";let Ve=a.users.verifyPassword(x.username,ee);await J(Ve);return}se>=" "&&(x.buffer+=se)}return}let v=C.toString("utf8");for(let D=0;D<v.length;D+=1){let G=v[D];if(G===""){c="",f=0,h=null,d="",t.write(`bye\r
426
+ `),ce(k)}U(),O(),t.on("data",async C=>{if(_){_.process.stdin.write(C);return}if(x){let M=C.toString("utf8");for(let Y=0;Y<M.length;Y+=1){let oe=M[Y];if(oe===""){x=null,t.write(`^C\r
427
+ `),O();return}if(oe==="\x7F"||oe==="\b"){x.buffer=x.buffer.slice(0,-1);continue}if(oe==="\r"||oe===`
428
+ `){let ee=x.buffer;x.buffer="";let Ye=a.users.verifyPassword(x.username,ee);await X(Ye);return}oe>=" "&&(x.buffer+=oe)}return}let k=C.toString("utf8");for(let M=0;M<k.length;M+=1){let Y=k[M];if(Y===""){c="",f=0,u=null,h="",t.write(`bye\r
114
429
  `),Z("bye"),await a.vfs.flushMirror(),t.write(`logout\r
115
- `),t.exit(0),t.end();return}if(G===" "){te();continue}if(G==="\x1B"){let se=v[D+1],ee=v[D+2],Ve=v[D+3];if(se==="["&&ee){if(ee==="A"){D+=2,u.length>0&&(h===null?(d=c,h=u.length-1):h>0&&(h-=1),U(u[h]??""));continue}if(ee==="B"){D+=2,h!==null&&(h<u.length-1?(h+=1,U(u[h]??"")):(h=null,U(d)));continue}if(ee==="C"){D+=2,f<c.length&&(f+=1,t.write("\x1B[C"));continue}if(ee==="D"){D+=2,f>0&&(f-=1,t.write("\x1B[D"));continue}if(ee==="3"&&Ve==="~"){D+=3,f<c.length&&(c=`${c.slice(0,f)}${c.slice(f+1)}`,$());continue}}}if(G===""){c="",f=0,h=null,d="",t.write(`^C\r
116
- `),$();continue}if(G==="\r"||G===`
117
- `){let se=c.trim();if(c="",f=0,h=null,d="",t.write(`\r
118
- `),se.length>0){let ee=await Promise.resolve(kt(se,e,r,"shell",g,a,void 0,_));if(Z(se),ee.openEditor){await S(ee.openEditor.targetPath,ee.openEditor.initialContent,ee.openEditor.tempPath);return}if(ee.openHtop){await w();return}if(ee.sudoChallenge){j(ee.sudoChallenge);return}if(ee.clearScreen&&t.write("\x1B[2J\x1B[H"),ee.stdout&&t.write(`${bi(ee.stdout)}\r
119
- `),ee.stderr&&t.write(`${bi(ee.stderr)}\r
430
+ `),t.exit(0),t.end();return}if(Y===" "){te();continue}if(Y==="\x1B"){let oe=k[M+1],ee=k[M+2],Ye=k[M+3];if(oe==="["&&ee){if(ee==="A"){M+=2,l.length>0&&(u===null?(h=c,u=l.length-1):u>0&&(u-=1),D(l[u]??""));continue}if(ee==="B"){M+=2,u!==null&&(u<l.length-1?(u+=1,D(l[u]??"")):(u=null,D(h)));continue}if(ee==="C"){M+=2,f<c.length&&(f+=1,t.write("\x1B[C"));continue}if(ee==="D"){M+=2,f>0&&(f-=1,t.write("\x1B[D"));continue}if(ee==="3"&&Ye==="~"){M+=3,f<c.length&&(c=`${c.slice(0,f)}${c.slice(f+1)}`,O());continue}}}if(Y===""){c="",f=0,u=null,h="",t.write(`^C\r
431
+ `),O();continue}if(Y==="\r"||Y===`
432
+ `){let oe=c.trim();if(c="",f=0,u=null,h="",t.write(`\r
433
+ `),oe.length>0){let ee=await Promise.resolve(St(oe,e,n,"shell",g,a,void 0,b));if(Z(oe),ee.openEditor){await w(ee.openEditor.targetPath,ee.openEditor.initialContent,ee.openEditor.tempPath);return}if(ee.openHtop){await I();return}if(ee.sudoChallenge){W(ee.sudoChallenge);return}if(ee.clearScreen&&t.write("\x1B[2J\x1B[H"),ee.stdout&&t.write(`${yi(ee.stdout)}\r
434
+ `),ee.stderr&&t.write(`${yi(ee.stderr)}\r
120
435
  `),ee.closeSession){t.write(`logout\r
121
- `),t.exit(ee.exitCode??0),t.end();return}ee.nextCwd&&(g=ee.nextCwd),ee.switchUser&&(e=ee.switchUser,g=ee.nextCwd??`/home/${e}`,a.users.updateSession(i,e,s),c="",f=0),await a.vfs.flushMirror()}$();continue}if(G==="\x7F"||G==="\b"){f>0&&(c=`${c.slice(0,f-1)}${c.slice(f)}`,f-=1,$());continue}W(G)}}),t.on("close",()=>{y&&(y.process.kill("SIGTERM"),y=null)})}function wA(n){let t="/virtual-env-js/.bash_history";return n.exists(t)?n.readFile(t).split(`
122
- `).map(r=>r.trim()).filter(r=>r.length>0):(n.writeFile(t,""),[])}var IA={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},xi=tr("VirtualShell");function CA(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var kr=class extends Cd.EventEmitter{vfs;users;hostname;properties;initialized;constructor(t,e,r){super(),xi.mark("constructor"),this.hostname=t,this.properties=e||IA,this.vfs=new La(r??{}),this.users=new yi(this.vfs,CA());let i=this.vfs,s=this.users;this.initialized=(async()=>{await i.restoreMirror(),await s.initialize(),this.emit("initialized")})()}async ensureInitialized(){xi.mark("ensureInitialized"),await this.initialized}addCommand(t,e,r){let i=t.trim().toLowerCase();if(i.length===0||/\s/.test(i))throw new Error("Command name must be non-empty and contain no spaces");Lu(Uu(i,e,r))}executeCommand(t,e,r){xi.mark("executeCommand"),kt(t,e,this.hostname,"shell",r,this),this.emit("command",{command:t,user:e,cwd:r})}startInteractiveSession(t,e,r,i,s){xi.mark("startInteractiveSession"),this.emit("session:start",{user:e,sessionId:r,remoteAddress:i}),Id(this.properties,t,e,this.hostname,r,i,s,this)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,r){xi.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,r),this.vfs.writeFile(e,r)}};pr();function Bd(n){return n.replace(/\r\n/g,`
436
+ `),t.exit(ee.exitCode??0),t.end();return}ee.nextCwd&&(g=ee.nextCwd),ee.switchUser&&(e=ee.switchUser,g=ee.nextCwd??`/home/${e}`,a.users.updateSession(i,e,s),c="",f=0),await a.vfs.flushMirror()}O();continue}if(Y==="\x7F"||Y==="\b"){f>0&&(c=`${c.slice(0,f-1)}${c.slice(f)}`,f-=1,O());continue}q(Y)}}),t.on("close",()=>{_&&(_.process.kill("SIGTERM"),_=null)})}function Wm(r){let t="/virtual-env-js/.bash_history";return r.exists(t)?r.readFile(t).split(`
437
+ `).map(n=>n.trim()).filter(n=>n.length>0):(r.writeFile(t,""),[])}var qm={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},xi=er("VirtualShell");function Km(){let r=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return r?!["0","false","no","off"].includes(r.toLowerCase()):!0}var vr=class extends Md.EventEmitter{vfs;users;packageManager;hostname;properties;startTime;initialized;constructor(t,e,n){super(),xi.mark("constructor"),this.hostname=t,this.properties=e||qm,this.startTime=Date.now(),this.vfs=new Ta(n??{}),this.users=new _i(this.vfs,Km()),this.packageManager=new bi(this.vfs,this.users);let i=this.vfs,s=this.users,o=this.packageManager,a=this.properties,c=this.hostname,f=this.startTime;this.initialized=(async()=>{await i.restoreMirror(),await s.initialize(),Cd(i,s,c,a,f),o.load(),this.emit("initialized")})()}async ensureInitialized(){xi.mark("ensureInitialized"),await this.initialized}addCommand(t,e,n){let i=t.trim().toLowerCase();if(i.length===0||/\s/.test(i))throw new Error("Command name must be non-empty and contain no spaces");Mf(Ff(i,e,n))}executeCommand(t,e,n){xi.mark("executeCommand"),St(t,e,this.hostname,"shell",n,this),this.emit("command",{command:t,user:e,cwd:n})}startInteractiveSession(t,e,n,i,s){xi.mark("startInteractiveSession"),this.emit("session:start",{user:e,sessionId:n,remoteAddress:i}),Od(this.properties,t,e,this.hostname,n,i,s,this)}refreshProcFs(){Da(this.vfs,this.properties,this.hostname,this.startTime)}syncPasswd(){Ua(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,n){xi.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,n),this.vfs.writeFile(e,n)}};function Fd(r){return r.replace(/\r\n/g,`
123
438
  `).replace(/\r/g,`
124
439
  `).replace(/\n/g,`\r
125
- `)}function vd(n,t,e,r,i){Promise.resolve(kt(t,e,r,"exec",`/home/${e}`,i,void 0,qn(e,r))).then(s=>{s.stdout&&n.write(`${Bd(s.stdout)}\r
126
- `),s.stderr&&n.stderr.write(`${Bd(s.stderr)}\r
127
- `),n.exit(s.exitCode??0),i.vfs.flushMirror(),n.end()}).catch(s=>{console.error("Exec error:",s),n.stderr.write(`Error: ${String(s)}\r
128
- `),n.exit(1),n.end()})}var kd=require("node:crypto"),Kr=require("node:fs"),vs=require("node:path");function ks(n=process.cwd()){let t=(0,vs.resolve)(n,".ssh-mimic","host_rsa");if((0,Kr.existsSync)(t))return(0,Kr.readFileSync)(t,"utf8");let e=(0,kd.generateKeyPairSync)("rsa",{modulusLength:2048,privateKeyEncoding:{type:"pkcs1",format:"pem"},publicKeyEncoding:{type:"pkcs1",format:"pem"}}).privateKey;return(0,Kr.mkdirSync)((0,vs.dirname)(t),{recursive:!0}),(0,Kr.writeFileSync)(t,e,{mode:384}),e}var Rd=require("node:events"),On=Xt(require("node:path"),1),Nd=Xt(Pa(),1);var He={OK:0,EOF:1,NO_SUCH_FILE:2,PERMISSION_DENIED:3,FAILURE:4,BAD_MESSAGE:5,NO_CONNECTION:6,CONNECTION_LOST:7,OP_UNSUPPORTED:8},Un={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},Da=tr("SftpMimic"),Dn=class extends Rd.EventEmitter{port;server;hostname;shell;vfs;users;nextHandleId=0;handles=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r,vfs:i,users:s}){if(super(),Da.mark("constructor"),this.port=t,this.server=null,this.hostname=e,this.shell=null,r)this.vfs=r.vfs,this.users=r.users,this.hostname=r.hostname,this.shell=r;else if(i&&s)this.vfs=i,this.users=s;else{let o=new kr(e);this.vfs=o.vfs,this.users=o.users,this.shell=o}}getVfs(){return this.shell?.vfs??this.vfs}getUsers(){return this.shell?.users??this.users}async start(){Da.mark("start");let t=ks();return this.shell?await this.shell.ensureInitialized():await this.users.initialize(),this.server=new Nd.Server({hostKeys:[t],ident:`SSH-2.0-${this.hostname}`},e=>{let r=["password","keyboard-interactive"],i="root",s=null,o="unknown";this.emit("client:connect"),e.on("error",c=>{console.error("[SFTP] Client error:",c)});let a=c=>{i=c,s=this.getUsers().registerSession(i,o).id;let f="/home";this.getVfs().exists(f)||this.getVfs().mkdir(f,493);let u=`/home/${i}`;this.getVfs().exists(u)||(this.getVfs().mkdir(u,493),this.getVfs().writeFile(`${u}/README.txt`,`Welcome to ${this.hostname}`),this.getVfs().flushMirror())};e.on("authentication",c=>{let f=c.username||"root";if(o=c.ip??o,console.log(`[SFTP] Auth attempt: user=${f}, method=${c.method}, ip=${o}`),c.method==="password"){if(!this.getUsers().hasPassword(f)){a(f),this.emit("auth:success",{username:i,remoteAddress:o}),c.accept();return}if(!this.getUsers().verifyPassword(f,c.password??"")){this.emit("auth:failure",{username:f,remoteAddress:o}),c.reject(r);return}a(f),this.emit("auth:success",{username:i,remoteAddress:o}),c.accept();return}if(c.method==="keyboard-interactive"){let u=c;if(!this.getUsers().hasPassword(f)){a(f),this.emit("auth:success",{username:i,remoteAddress:o}),u.accept();return}u.prompt([{prompt:"Password: ",echo:!1}],h=>{let d=h[0]??"";if(!this.getUsers().verifyPassword(f,d)){this.emit("auth:failure",{username:f,remoteAddress:o}),u.reject(r);return}a(f),this.emit("auth:success",{username:i,remoteAddress:o}),u.accept()});return}c.reject(r)}),e.on("close",()=>{this.getUsers().unregisterSession(s),this.emit("client:disconnect",{user:i}),s=null}),e.on("ready",()=>{e.on("session",(c,f)=>{let u=c();u.on("error",h=>{console.error(`[SFTP] Session error for user=${i}:`,h)}),u.on("sftp",h=>{let d=h();this.attachSftpHandlers(d,i)})})})}),new Promise((e,r)=>{this.server?.once("error",i=>r(i)),this.server?.listen(this.port,"0.0.0.0",()=>{let i=this.server?.address(),s=i&&typeof i=="object"&&"port"in i?i.port:this.port;console.log(`SFTP Mimic listening on port ${s}`),this.emit("start",{port:s}),e(s)})})}stop(){Da.mark("stop"),this.server&&this.server.close(()=>{console.log("SFTP Mimic stopped"),this.emit("stop")})}resolveRequestPath(t,e){let r=`/home/${e}`;if(!t||t===".")return r;if(!t.startsWith("/")){let i=On.posix.join(r,t);return On.posix.normalize(i)}return On.posix.normalize(t)}isPathWithinHome(t,e){let r=`/home/${e}`,i=On.posix.normalize(t);return!!(i===r||i.startsWith(`${r}/`))}createAttrs(t){let e=t.mode&511;return{mode:(t.type==="directory"?16384:32768)|e,size:t.type==="file"?t.size:0,uid:0,gid:0,atime:Math.floor(t.createdAt.getTime()/1e3),mtime:Math.floor(t.updatedAt.getTime()/1e3)}}openHandle(t){let e=++this.nextHandleId,r=Buffer.alloc(4);return r.writeUInt32BE(e,0),this.handles.set(r.toString("hex"),t),r}getHandle(t){return this.handles.get(t.toString("hex"))}closeHandle(t){this.handles.delete(t.toString("hex"))}attachSftpHandlers(t,e){let r=()=>this.getVfs(),i=()=>this.getUsers();t.on("OPEN",(s,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(s,He.PERMISSION_DENIED);return}let f=a,u=!!(f&Un.READ),h=!!(f&Un.WRITE||f&Un.APPEND),d=!!(f&Un.CREAT),g=!!(f&Un.TRUNC);try{if(!r().exists(c)){if(!d){t.status(s,He.NO_SUCH_FILE);return}r().writeFile(c,Buffer.alloc(0))}if(r().stat(c).type==="directory"){t.status(s,He.FAILURE);return}let y=Buffer.from(r().readFile(c),"utf8");if(g&&(y=Buffer.alloc(0)),f&Un.APPEND){let I=this.openHandle({type:"file",path:c,flags:f,buffer:y});t.handle(s,I);return}let x=this.openHandle({type:"file",path:c,flags:f,buffer:y});t.handle(s,x)}catch(_){console.error("SFTP OPEN error:",_),t.status(s,He.FAILURE)}}),t.on("READ",(s,o,a,c)=>{let f=this.getHandle(o);if(!f||f.type!=="file"){t.status(s,He.FAILURE);return}if(a>=f.buffer.length){t.status(s,He.EOF);return}let u=f.buffer.slice(a,a+c);t.data(s,u)}),t.on("WRITE",async(s,o,a,c)=>{let f=this.getHandle(o);if(!f||f.type!=="file"){t.status(s,He.FAILURE);return}let u=a+c.length;if(u>f.buffer.length){let h=Buffer.alloc(u);f.buffer.copy(h,0,0,f.buffer.length),f.buffer=h}c.copy(f.buffer,a),t.status(s,He.OK)}),t.on("FSTAT",(s,o)=>{let a=this.getHandle(o);if(!a){t.status(s,He.FAILURE);return}try{let c=r().stat(a.path);t.attrs(s,this.createAttrs(c))}catch{t.status(s,He.FAILURE)}}),t.on("CLOSE",async(s,o)=>{let a=this.getHandle(o);if(!a){t.status(s,He.FAILURE);return}if(a.type==="file")try{i().assertWriteWithinQuota(e,a.path,a.buffer),r().writeFile(a.path,a.buffer),r().flushMirror()}catch(c){console.error("SFTP CLOSE write error:",c),t.status(s,He.FAILURE),this.closeHandle(o);return}this.closeHandle(o),t.status(s,He.OK)}),t.on("OPENDIR",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,He.PERMISSION_DENIED);return}try{if(r().stat(a).type!=="directory"){t.status(s,He.FAILURE);return}let f=r().list(a),u=this.openHandle({type:"dir",path:a,entries:f,index:0});t.handle(s,u)}catch{t.status(s,He.NO_SUCH_FILE)}}),t.on("READDIR",(s,o)=>{let a=this.getHandle(o);if(!a||a.type!=="dir"){t.status(s,He.FAILURE);return}if(a.index>=a.entries.length){t.status(s,He.EOF);return}let c=a.entries[a.index++],f=On.posix.join(a.path,c),u=r().stat(f),h=this.createAttrs(u),d=`${u.type==="directory"?"d":"-"}${(u.mode&511).toString(8)} ${c}`;return t.name(s,[{filename:c,longname:d,attrs:h}])}),t.on("STAT",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,He.PERMISSION_DENIED);return}try{let c=r().stat(a);t.attrs(s,this.createAttrs(c))}catch{t.status(s,He.NO_SUCH_FILE)}}),t.on("LSTAT",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,He.PERMISSION_DENIED);return}try{let c=r().stat(a);t.attrs(s,this.createAttrs(c))}catch{t.status(s,He.NO_SUCH_FILE)}}),t.on("FSETSTAT",(s,o,a)=>{let c=this.getHandle(o);if(!c){t.status(s,He.FAILURE);return}try{a.mode!==void 0&&r().chmod(c.path,a.mode),t.status(s,He.OK)}catch{t.status(s,He.FAILURE)}}),t.on("SETSTAT",(s,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(s,He.PERMISSION_DENIED);return}try{a.mode!==void 0&&r().chmod(c,a.mode),t.status(s,He.OK)}catch{t.status(s,He.FAILURE)}}),t.on("REALPATH",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,He.PERMISSION_DENIED);return}t.name(s,[{filename:a,longname:a,attrs:{mode:16877,uid:0,gid:0,size:0,atime:0,mtime:0}}])}),t.on("MKDIR",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,He.PERMISSION_DENIED);return}try{r().mkdir(a,493),r().flushMirror(),t.status(s,He.OK)}catch{t.status(s,He.FAILURE)}}),t.on("RMDIR",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,He.PERMISSION_DENIED);return}try{r().remove(a,{recursive:!1}),r().flushMirror(),t.status(s,He.OK)}catch{t.status(s,He.FAILURE)}}),t.on("REMOVE",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,He.PERMISSION_DENIED);return}try{r().remove(a,{recursive:!1}),r().flushMirror(),t.status(s,He.OK)}catch{t.status(s,He.FAILURE)}}),t.on("RENAME",(s,o,a)=>{let c=this.resolveRequestPath(o,e),f=this.resolveRequestPath(a,e);if(!this.isPathWithinHome(c,e)||!this.isPathWithinHome(f,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, from=${c}, to=${f}`),t.status(s,He.PERMISSION_DENIED);return}try{r().move(c,f),r().flushMirror(),t.status(s,He.OK)}catch{t.status(s,He.FAILURE)}}),t.on("READLINK",s=>{t.status(s,He.OP_UNSUPPORTED)}),t.on("SYMLINK",s=>{t.status(s,He.OP_UNSUPPORTED)}),t.on("error",s=>{console.error(`[SFTP] Stream error for user=${e}:`,s)}),t.on("close",()=>{console.log(`[SFTP] Stream closed for user=${e}`),this.handles.clear()}),t.on("end",()=>{console.log(`[SFTP] end event for user=${e}`),this.handles.clear()}),t.on("END",()=>{console.log(`[SFTP] END event for user=${e}`),this.handles.clear()})}};var Ha=tr("SshMimic"),Si=class extends Pd.EventEmitter{port;server;shell;maxAuthAttempts;lockoutDurationMs;authAttempts=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r=new kr(e),maxAuthAttempts:i=5,lockoutDurationMs:s=6e4}){super(),Ha.mark("constructor"),this.port=t,this.server=null,this.shell=r,this.maxAuthAttempts=i,this.lockoutDurationMs=s}isLockedOut(t){let e=this.authAttempts.get(t);return e?Date.now()<e.lockedUntil?!0:(e.lockedUntil>0&&this.authAttempts.delete(t),!1):!1}recordFailure(t){let e=this.authAttempts.get(t)??{attempts:0,lockedUntil:0};e.attempts+=1,e.attempts>=this.maxAuthAttempts&&(e.lockedUntil=Date.now()+this.lockoutDurationMs,this.emit("auth:lockout",{ip:t,until:new Date(e.lockedUntil)})),this.authAttempts.set(t,e)}recordSuccess(t){this.authAttempts.delete(t)}ensureHomeDir(t){let e=`/home/${t}`;this.shell.vfs.exists(e)||(this.shell.vfs.mkdir(e,493),this.shell.vfs.writeFile(`${e}/README.txt`,`Welcome to ${this.shell.hostname}
129
- `),this.shell.vfs.flushMirror())}async start(){Ha.mark("start");let t=this.shell,e=ks();return await t.ensureInitialized(),this.server=new Td.Server({hostKeys:[e],ident:`SSH-2.0-${t.hostname}`},r=>{let i="root",s="unknown",o=null;this.emit("client:connect"),r.on("authentication",a=>{let c=a.username||"root";if(s=a.ip??s,this.isLockedOut(s)){this.emit("auth:failure",{username:c,remoteAddress:s,reason:"lockout"}),a.reject();return}if(a.method==="password"){if(!t.users.hasPassword(c)){console.log(`User ${c} has no password set, allowing login without verification`),i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s}),this.ensureHomeDir(i),a.accept();return}if(!a.password||a.password===""||!t.users.verifyPassword(c,a.password)){this.recordFailure(s),this.emit("auth:failure",{username:c,remoteAddress:s}),a.reject();return}i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s}),this.ensureHomeDir(i),a.accept();return}if(a.method==="publickey"){let f=t.users.getAuthorizedKeys(c);if(f.length===0){a.reject();return}let u=a.key;if(!f.some(d=>d.algo===u.algo&&d.data.equals(u.data))){this.recordFailure(s),this.emit("auth:failure",{username:c,remoteAddress:s,method:"publickey"}),a.reject();return}a.signature&&(i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s,method:"publickey"}),this.ensureHomeDir(i)),a.accept();return}a.reject(["password","publickey"])}),r.on("close",()=>{t.users.unregisterSession(o),this.emit("client:disconnect",{user:i}),o=null}),r.on("ready",()=>{r.on("session",a=>{let c=a(),f={cols:80,rows:24};c.on("pty",(u,h,d)=>{f.cols=d?.cols??f.cols,f.rows=d?.rows??f.rows,u()}),c.on("window-change",(u,h,d)=>{f.cols=d?.cols??f.cols,f.rows=d?.rows??f.rows}),c.on("shell",u=>{let h=u();t?.startInteractiveSession(h,i,o,s,f)}),c.on("exec",(u,h,d)=>{let g=u();g&&vd(g,d.command.trim(),i,t.hostname,t)})})})}),new Promise((r,i)=>{this.server?.once("error",s=>i(s)),this.server?.listen(this.port,"0.0.0.0",()=>{console.log(`SSH Mimic listening on port ${this.port}`),this.emit("start",{port:this.port}),r(this.port)})})}stop(){Ha.mark("stop"),this.server&&this.server.close(()=>{console.log("SSH Mimic stopped"),this.emit("stop")})}clearLockout(t){this.authAttempts.delete(t)}};it();var Ma=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",Fa=new kr(Ma);Fa.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));new Si({port:2222,hostname:Ma,shell:Fa}).start().catch(n=>{console.error("Failed to start SSH Mimic:",n),process.exit(1)});new Dn({port:2223,hostname:Ma,shell:Fa}).start().catch(n=>{console.error("Failed to start SFTP Mimic:",n),process.exit(1)});process.on("uncaughtException",n=>{console.log("Oh my god, something terrible happened: ",n)});process.on("unhandledRejection",(n,t)=>{console.log(" Oh Lord! We forgot to handle a promise rejection here: ",t),console.log(" The error was: ",n)});
440
+ `)}function $d(r,t,e,n,i){Promise.resolve(St(t,e,n,"exec",`/home/${e}`,i,void 0,Wn(e,n))).then(s=>{s.stdout&&r.write(`${Fd(s.stdout)}\r
441
+ `),s.stderr&&r.stderr.write(`${Fd(s.stderr)}\r
442
+ `),r.exit(s.exitCode??0),i.vfs.flushMirror(),r.end()}).catch(s=>{console.error("Exec error:",s),r.stderr.write(`Error: ${String(s)}\r
443
+ `),r.exit(1),r.end()})}var Hd=require("node:crypto"),Qr=require("node:fs"),vs=require("node:path");function ks(r=process.cwd()){let t=(0,vs.resolve)(r,".ssh-mimic","host_rsa");if((0,Qr.existsSync)(t))return(0,Qr.readFileSync)(t,"utf8");let e=(0,Hd.generateKeyPairSync)("rsa",{modulusLength:2048,privateKeyEncoding:{type:"pkcs1",format:"pem"},publicKeyEncoding:{type:"pkcs1",format:"pem"}}).privateKey;return(0,Qr.mkdirSync)((0,vs.dirname)(t),{recursive:!0}),(0,Qr.writeFileSync)(t,e,{mode:384}),e}var Qd=require("node:events"),Un=$t(require("node:path"),1),Wd=$t(ka(),1);var Me={OK:0,EOF:1,NO_SUCH_FILE:2,PERMISSION_DENIED:3,FAILURE:4,BAD_MESSAGE:5,NO_CONNECTION:6,CONNECTION_LOST:7,OP_UNSUPPORTED:8},Ln={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},Fa=er("SftpMimic"),Dn=class extends Qd.EventEmitter{port;server;hostname;shell;vfs;users;nextHandleId=0;handles=new Map;constructor({port:t,hostname:e="typescript-vm",shell:n,vfs:i,users:s}){if(super(),Fa.mark("constructor"),this.port=t,this.server=null,this.hostname=e,this.shell=null,n)this.vfs=n.vfs,this.users=n.users,this.hostname=n.hostname,this.shell=n;else if(i&&s)this.vfs=i,this.users=s;else{let o=new vr(e);this.vfs=o.vfs,this.users=o.users,this.shell=o}}getVfs(){return this.shell?.vfs??this.vfs}getUsers(){return this.shell?.users??this.users}async start(){Fa.mark("start");let t=ks();return this.shell?await this.shell.ensureInitialized():await this.users.initialize(),this.server=new Wd.Server({hostKeys:[t],ident:`SSH-2.0-${this.hostname}`},e=>{let n=["password","keyboard-interactive"],i="root",s=null,o="unknown";this.emit("client:connect"),e.on("error",c=>{console.error("[SFTP] Client error:",c)});let a=c=>{i=c,s=this.getUsers().registerSession(i,o).id;let f="/home";this.getVfs().exists(f)||this.getVfs().mkdir(f,493);let l=`/home/${i}`;this.getVfs().exists(l)||(this.getVfs().mkdir(l,493),this.getVfs().writeFile(`${l}/README.txt`,`Welcome to ${this.hostname}`),this.getVfs().flushMirror())};e.on("authentication",c=>{let f=c.username||"root";if(o=c.ip??o,console.log(`[SFTP] Auth attempt: user=${f}, method=${c.method}, ip=${o}`),c.method==="password"){if(!this.getUsers().hasPassword(f)){a(f),this.emit("auth:success",{username:i,remoteAddress:o}),c.accept();return}if(!this.getUsers().verifyPassword(f,c.password??"")){this.emit("auth:failure",{username:f,remoteAddress:o}),c.reject(n);return}a(f),this.emit("auth:success",{username:i,remoteAddress:o}),c.accept();return}if(c.method==="keyboard-interactive"){let l=c;if(!this.getUsers().hasPassword(f)){a(f),this.emit("auth:success",{username:i,remoteAddress:o}),l.accept();return}l.prompt([{prompt:"Password: ",echo:!1}],u=>{let h=u[0]??"";if(!this.getUsers().verifyPassword(f,h)){this.emit("auth:failure",{username:f,remoteAddress:o}),l.reject(n);return}a(f),this.emit("auth:success",{username:i,remoteAddress:o}),l.accept()});return}c.reject(n)}),e.on("close",()=>{this.getUsers().unregisterSession(s),this.emit("client:disconnect",{user:i}),s=null}),e.on("ready",()=>{e.on("session",(c,f)=>{let l=c();l.on("error",u=>{console.error(`[SFTP] Session error for user=${i}:`,u)}),l.on("sftp",u=>{let h=u();this.attachSftpHandlers(h,i)})})})}),new Promise((e,n)=>{this.server?.once("error",i=>n(i)),this.server?.listen(this.port,"0.0.0.0",()=>{let i=this.server?.address(),s=i&&typeof i=="object"&&"port"in i?i.port:this.port;console.log(`SFTP Mimic listening on port ${s}`),this.emit("start",{port:s}),e(s)})})}stop(){Fa.mark("stop"),this.server&&this.server.close(()=>{console.log("SFTP Mimic stopped"),this.emit("stop")})}resolveRequestPath(t,e){let n=`/home/${e}`;if(!t||t===".")return n;if(!t.startsWith("/")){let i=Un.posix.join(n,t);return Un.posix.normalize(i)}return Un.posix.normalize(t)}isPathWithinHome(t,e){let n=`/home/${e}`,i=Un.posix.normalize(t);return!!(i===n||i.startsWith(`${n}/`))}createAttrs(t){let e=t.mode&511;return{mode:(t.type==="directory"?16384:32768)|e,size:t.type==="file"?t.size:0,uid:0,gid:0,atime:Math.floor(t.createdAt.getTime()/1e3),mtime:Math.floor(t.updatedAt.getTime()/1e3)}}openHandle(t){let e=++this.nextHandleId,n=Buffer.alloc(4);return n.writeUInt32BE(e,0),this.handles.set(n.toString("hex"),t),n}getHandle(t){return this.handles.get(t.toString("hex"))}closeHandle(t){this.handles.delete(t.toString("hex"))}attachSftpHandlers(t,e){let n=()=>this.getVfs(),i=()=>this.getUsers();t.on("OPEN",(s,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(s,Me.PERMISSION_DENIED);return}let f=a,l=!!(f&Ln.READ),u=!!(f&Ln.WRITE||f&Ln.APPEND),h=!!(f&Ln.CREAT),g=!!(f&Ln.TRUNC);try{if(!n().exists(c)){if(!h){t.status(s,Me.NO_SUCH_FILE);return}n().writeFile(c,Buffer.alloc(0))}if(n().stat(c).type==="directory"){t.status(s,Me.FAILURE);return}let _=Buffer.from(n().readFile(c),"utf8");if(g&&(_=Buffer.alloc(0)),f&Ln.APPEND){let S=this.openHandle({type:"file",path:c,flags:f,buffer:_});t.handle(s,S);return}let x=this.openHandle({type:"file",path:c,flags:f,buffer:_});t.handle(s,x)}catch(b){console.error("SFTP OPEN error:",b),t.status(s,Me.FAILURE)}}),t.on("READ",(s,o,a,c)=>{let f=this.getHandle(o);if(!f||f.type!=="file"){t.status(s,Me.FAILURE);return}if(a>=f.buffer.length){t.status(s,Me.EOF);return}let l=f.buffer.slice(a,a+c);t.data(s,l)}),t.on("WRITE",async(s,o,a,c)=>{let f=this.getHandle(o);if(!f||f.type!=="file"){t.status(s,Me.FAILURE);return}let l=a+c.length;if(l>f.buffer.length){let u=Buffer.alloc(l);f.buffer.copy(u,0,0,f.buffer.length),f.buffer=u}c.copy(f.buffer,a),t.status(s,Me.OK)}),t.on("FSTAT",(s,o)=>{let a=this.getHandle(o);if(!a){t.status(s,Me.FAILURE);return}try{let c=n().stat(a.path);t.attrs(s,this.createAttrs(c))}catch{t.status(s,Me.FAILURE)}}),t.on("CLOSE",async(s,o)=>{let a=this.getHandle(o);if(!a){t.status(s,Me.FAILURE);return}if(a.type==="file")try{i().assertWriteWithinQuota(e,a.path,a.buffer),n().writeFile(a.path,a.buffer),n().flushMirror()}catch(c){console.error("SFTP CLOSE write error:",c),t.status(s,Me.FAILURE),this.closeHandle(o);return}this.closeHandle(o),t.status(s,Me.OK)}),t.on("OPENDIR",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,Me.PERMISSION_DENIED);return}try{if(n().stat(a).type!=="directory"){t.status(s,Me.FAILURE);return}let f=n().list(a),l=this.openHandle({type:"dir",path:a,entries:f,index:0});t.handle(s,l)}catch{t.status(s,Me.NO_SUCH_FILE)}}),t.on("READDIR",(s,o)=>{let a=this.getHandle(o);if(!a||a.type!=="dir"){t.status(s,Me.FAILURE);return}if(a.index>=a.entries.length){t.status(s,Me.EOF);return}let c=a.entries[a.index++],f=Un.posix.join(a.path,c),l=n().stat(f),u=this.createAttrs(l),h=`${l.type==="directory"?"d":"-"}${(l.mode&511).toString(8)} ${c}`;return t.name(s,[{filename:c,longname:h,attrs:u}])}),t.on("STAT",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,Me.PERMISSION_DENIED);return}try{let c=n().stat(a);t.attrs(s,this.createAttrs(c))}catch{t.status(s,Me.NO_SUCH_FILE)}}),t.on("LSTAT",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,Me.PERMISSION_DENIED);return}try{let c=n().stat(a);t.attrs(s,this.createAttrs(c))}catch{t.status(s,Me.NO_SUCH_FILE)}}),t.on("FSETSTAT",(s,o,a)=>{let c=this.getHandle(o);if(!c){t.status(s,Me.FAILURE);return}try{a.mode!==void 0&&n().chmod(c.path,a.mode),t.status(s,Me.OK)}catch{t.status(s,Me.FAILURE)}}),t.on("SETSTAT",(s,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(s,Me.PERMISSION_DENIED);return}try{a.mode!==void 0&&n().chmod(c,a.mode),t.status(s,Me.OK)}catch{t.status(s,Me.FAILURE)}}),t.on("REALPATH",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,Me.PERMISSION_DENIED);return}t.name(s,[{filename:a,longname:a,attrs:{mode:16877,uid:0,gid:0,size:0,atime:0,mtime:0}}])}),t.on("MKDIR",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,Me.PERMISSION_DENIED);return}try{n().mkdir(a,493),n().flushMirror(),t.status(s,Me.OK)}catch{t.status(s,Me.FAILURE)}}),t.on("RMDIR",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,Me.PERMISSION_DENIED);return}try{n().remove(a,{recursive:!1}),n().flushMirror(),t.status(s,Me.OK)}catch{t.status(s,Me.FAILURE)}}),t.on("REMOVE",(s,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(s,Me.PERMISSION_DENIED);return}try{n().remove(a,{recursive:!1}),n().flushMirror(),t.status(s,Me.OK)}catch{t.status(s,Me.FAILURE)}}),t.on("RENAME",(s,o,a)=>{let c=this.resolveRequestPath(o,e),f=this.resolveRequestPath(a,e);if(!this.isPathWithinHome(c,e)||!this.isPathWithinHome(f,e)){console.warn(`[SFTP] Path traversal attempt blocked: user=${e}, from=${c}, to=${f}`),t.status(s,Me.PERMISSION_DENIED);return}try{n().move(c,f),n().flushMirror(),t.status(s,Me.OK)}catch{t.status(s,Me.FAILURE)}}),t.on("READLINK",s=>{t.status(s,Me.OP_UNSUPPORTED)}),t.on("SYMLINK",s=>{t.status(s,Me.OP_UNSUPPORTED)}),t.on("error",s=>{console.error(`[SFTP] Stream error for user=${e}:`,s)}),t.on("close",()=>{console.log(`[SFTP] Stream closed for user=${e}`),this.handles.clear()}),t.on("end",()=>{console.log(`[SFTP] end event for user=${e}`),this.handles.clear()}),t.on("END",()=>{console.log(`[SFTP] END event for user=${e}`),this.handles.clear()})}};var $a=er("SshMimic"),Si=class extends qd.EventEmitter{port;server;shell;maxAuthAttempts;lockoutDurationMs;authAttempts=new Map;constructor({port:t,hostname:e="typescript-vm",shell:n=new vr(e),maxAuthAttempts:i=5,lockoutDurationMs:s=6e4}){super(),$a.mark("constructor"),this.port=t,this.server=null,this.shell=n,this.maxAuthAttempts=i,this.lockoutDurationMs=s}isLockedOut(t){let e=this.authAttempts.get(t);return e?Date.now()<e.lockedUntil?!0:(e.lockedUntil>0&&this.authAttempts.delete(t),!1):!1}recordFailure(t){let e=this.authAttempts.get(t)??{attempts:0,lockedUntil:0};e.attempts+=1,e.attempts>=this.maxAuthAttempts&&(e.lockedUntil=Date.now()+this.lockoutDurationMs,this.emit("auth:lockout",{ip:t,until:new Date(e.lockedUntil)})),this.authAttempts.set(t,e)}recordSuccess(t){this.authAttempts.delete(t)}ensureHomeDir(t){let e=`/home/${t}`;this.shell.vfs.exists(e)||(this.shell.vfs.mkdir(e,493),this.shell.vfs.writeFile(`${e}/README.txt`,`Welcome to ${this.shell.hostname}
444
+ `),this.shell.vfs.flushMirror())}async start(){$a.mark("start");let t=this.shell,e=ks();return await t.ensureInitialized(),this.server=new Kd.Server({hostKeys:[e],ident:`SSH-2.0-${t.hostname}`},n=>{let i="root",s="unknown",o=null;this.emit("client:connect"),n.on("authentication",a=>{let c=a.username||"root";if(s=a.ip??s,this.isLockedOut(s)){this.emit("auth:failure",{username:c,remoteAddress:s,reason:"lockout"}),a.reject();return}if(a.method==="password"){if(!t.users.hasPassword(c)){console.log(`User ${c} has no password set, allowing login without verification`),i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s}),this.ensureHomeDir(i),a.accept();return}if(!a.password||a.password===""||!t.users.verifyPassword(c,a.password)){this.recordFailure(s),this.emit("auth:failure",{username:c,remoteAddress:s}),a.reject();return}i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s}),this.ensureHomeDir(i),a.accept();return}if(a.method==="publickey"){let f=t.users.getAuthorizedKeys(c);if(f.length===0){a.reject();return}let l=a.key;if(!f.some(h=>h.algo===l.algo&&h.data.equals(l.data))){this.recordFailure(s),this.emit("auth:failure",{username:c,remoteAddress:s,method:"publickey"}),a.reject();return}a.signature&&(i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s,method:"publickey"}),this.ensureHomeDir(i)),a.accept();return}a.reject(["password","publickey"])}),n.on("close",()=>{t.users.unregisterSession(o),this.emit("client:disconnect",{user:i}),o=null}),n.on("ready",()=>{n.on("session",a=>{let c=a(),f={cols:80,rows:24};c.on("pty",(l,u,h)=>{f.cols=h?.cols??f.cols,f.rows=h?.rows??f.rows,l()}),c.on("window-change",(l,u,h)=>{f.cols=h?.cols??f.cols,f.rows=h?.rows??f.rows}),c.on("shell",l=>{let u=l();t?.startInteractiveSession(u,i,o,s,f)}),c.on("exec",(l,u,h)=>{let g=l();g&&$d(g,h.command.trim(),i,t.hostname,t)})})})}),new Promise((n,i)=>{this.server?.once("error",s=>i(s)),this.server?.listen(this.port,"0.0.0.0",()=>{console.log(`SSH Mimic listening on port ${this.port}`),this.emit("start",{port:this.port}),n(this.port)})})}stop(){$a.mark("stop"),this.server&&this.server.close(()=>{console.log("SSH Mimic stopped"),this.emit("stop")})}clearLockout(t){this.authAttempts.delete(t)}};var Ha=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",Qa=new vr(Ha,void 0,{mode:"fs",snapshotPath:".vfs"});Qa.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));new Si({port:2222,hostname:Ha,shell:Qa}).start().catch(r=>{console.error("Failed to start SSH Mimic:",r),process.exit(1)});new Dn({port:2223,hostname:Ha,shell:Qa}).start().catch(r=>{console.error("Failed to start SFTP Mimic:",r),process.exit(1)});process.on("uncaughtException",r=>{console.log("Oh my god, something terrible happened: ",r)});process.on("unhandledRejection",(r,t)=>{console.log(" Oh Lord! We forgot to handle a promise rejection here: ",t),console.log(" The error was: ",r)});
130
445
  //# sourceMappingURL=standalone.js.map