typescript-virtual-container 1.4.3 → 1.4.5

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 (382) hide show
  1. package/.vscode/settings.json +2 -1
  2. package/README.md +137 -19
  3. package/benchmark-results.txt +21 -21
  4. package/builds/self-standalone.js +322 -266
  5. package/builds/self-standalone.js.map +4 -4
  6. package/builds/standalone-wo-sftp.js +268 -212
  7. package/builds/standalone-wo-sftp.js.map +4 -4
  8. package/builds/standalone.js +268 -212
  9. package/builds/standalone.js.map +4 -4
  10. package/builds/web-full-api.min.js +5 -5
  11. package/builds/web-full-api.min.js.map +3 -3
  12. package/builds/web.min.js +5 -5
  13. package/builds/web.min.js.map +3 -3
  14. package/bun.lock +101 -6
  15. package/dist/Honeypot/index.js +1 -0
  16. package/dist/Honeypot/index.js.map +1 -0
  17. package/dist/SSHClient/index.js +1 -0
  18. package/dist/SSHClient/index.js.map +1 -0
  19. package/dist/SSHMimic/exec.js +1 -0
  20. package/dist/SSHMimic/exec.js.map +1 -0
  21. package/dist/SSHMimic/executor.js +1 -0
  22. package/dist/SSHMimic/executor.js.map +1 -0
  23. package/dist/SSHMimic/hostKey.js +1 -0
  24. package/dist/SSHMimic/hostKey.js.map +1 -0
  25. package/dist/SSHMimic/index.js +1 -0
  26. package/dist/SSHMimic/index.js.map +1 -0
  27. package/dist/SSHMimic/loginBanner.js +1 -0
  28. package/dist/SSHMimic/loginBanner.js.map +1 -0
  29. package/dist/SSHMimic/loginFormat.js +1 -0
  30. package/dist/SSHMimic/loginFormat.js.map +1 -0
  31. package/dist/SSHMimic/prompt.js +1 -0
  32. package/dist/SSHMimic/prompt.js.map +1 -0
  33. package/dist/SSHMimic/sftp.js +1 -0
  34. package/dist/SSHMimic/sftp.js.map +1 -0
  35. package/dist/VirtualFileSystem/binaryPack.js +1 -0
  36. package/dist/VirtualFileSystem/binaryPack.js.map +1 -0
  37. package/dist/VirtualFileSystem/index.d.ts.map +1 -1
  38. package/dist/VirtualFileSystem/index.js +1 -0
  39. package/dist/VirtualFileSystem/index.js.map +1 -0
  40. package/dist/VirtualFileSystem/internalTypes.js +1 -0
  41. package/dist/VirtualFileSystem/internalTypes.js.map +1 -0
  42. package/dist/VirtualFileSystem/path.js +1 -0
  43. package/dist/VirtualFileSystem/path.js.map +1 -0
  44. package/dist/VirtualPackageManager/index.js +1 -0
  45. package/dist/VirtualPackageManager/index.js.map +1 -0
  46. package/dist/VirtualShell/index.js +1 -0
  47. package/dist/VirtualShell/index.js.map +1 -0
  48. package/dist/VirtualShell/shell.js +1 -0
  49. package/dist/VirtualShell/shell.js.map +1 -0
  50. package/dist/VirtualShell/shellParser.d.ts.map +1 -1
  51. package/dist/VirtualShell/shellParser.js +3 -1
  52. package/dist/VirtualShell/shellParser.js.map +1 -0
  53. package/dist/VirtualUserManager/index.js +1 -0
  54. package/dist/VirtualUserManager/index.js.map +1 -0
  55. package/dist/commands/adduser.js +1 -0
  56. package/dist/commands/adduser.js.map +1 -0
  57. package/dist/commands/alias.js +1 -0
  58. package/dist/commands/alias.js.map +1 -0
  59. package/dist/commands/apt.js +1 -0
  60. package/dist/commands/apt.js.map +1 -0
  61. package/dist/commands/awk.d.ts.map +1 -1
  62. package/dist/commands/awk.js +2 -2
  63. package/dist/commands/awk.js.map +1 -0
  64. package/dist/commands/base64.js +1 -0
  65. package/dist/commands/base64.js.map +1 -0
  66. package/dist/commands/cat.js +1 -0
  67. package/dist/commands/cat.js.map +1 -0
  68. package/dist/commands/cd.js +3 -2
  69. package/dist/commands/cd.js.map +1 -0
  70. package/dist/commands/chmod.js +1 -0
  71. package/dist/commands/chmod.js.map +1 -0
  72. package/dist/commands/clear.js +1 -0
  73. package/dist/commands/clear.js.map +1 -0
  74. package/dist/commands/command-helpers.js +1 -0
  75. package/dist/commands/command-helpers.js.map +1 -0
  76. package/dist/commands/cp.js +1 -0
  77. package/dist/commands/cp.js.map +1 -0
  78. package/dist/commands/curl.js +1 -0
  79. package/dist/commands/curl.js.map +1 -0
  80. package/dist/commands/cut.js +1 -0
  81. package/dist/commands/cut.js.map +1 -0
  82. package/dist/commands/date.js +1 -0
  83. package/dist/commands/date.js.map +1 -0
  84. package/dist/commands/declare.js +1 -0
  85. package/dist/commands/declare.js.map +1 -0
  86. package/dist/commands/deluser.js +1 -0
  87. package/dist/commands/deluser.js.map +1 -0
  88. package/dist/commands/df.js +1 -0
  89. package/dist/commands/df.js.map +1 -0
  90. package/dist/commands/diff.js +1 -0
  91. package/dist/commands/diff.js.map +1 -0
  92. package/dist/commands/dpkg.js +1 -0
  93. package/dist/commands/dpkg.js.map +1 -0
  94. package/dist/commands/du.js +1 -0
  95. package/dist/commands/du.js.map +1 -0
  96. package/dist/commands/echo.js +1 -0
  97. package/dist/commands/echo.js.map +1 -0
  98. package/dist/commands/env.js +1 -0
  99. package/dist/commands/env.js.map +1 -0
  100. package/dist/commands/exit.js +1 -0
  101. package/dist/commands/exit.js.map +1 -0
  102. package/dist/commands/export.js +1 -0
  103. package/dist/commands/export.js.map +1 -0
  104. package/dist/commands/find.js +1 -0
  105. package/dist/commands/find.js.map +1 -0
  106. package/dist/commands/free.js +1 -0
  107. package/dist/commands/free.js.map +1 -0
  108. package/dist/commands/grep.js +1 -0
  109. package/dist/commands/grep.js.map +1 -0
  110. package/dist/commands/groups.js +1 -0
  111. package/dist/commands/groups.js.map +1 -0
  112. package/dist/commands/gzip.js +1 -0
  113. package/dist/commands/gzip.js.map +1 -0
  114. package/dist/commands/head.js +1 -0
  115. package/dist/commands/head.js.map +1 -0
  116. package/dist/commands/help.js +1 -0
  117. package/dist/commands/help.js.map +1 -0
  118. package/dist/commands/helpers.d.ts.map +1 -1
  119. package/dist/commands/helpers.js +4 -0
  120. package/dist/commands/helpers.js.map +1 -0
  121. package/dist/commands/history.js +1 -0
  122. package/dist/commands/history.js.map +1 -0
  123. package/dist/commands/hostname.js +1 -0
  124. package/dist/commands/hostname.js.map +1 -0
  125. package/dist/commands/htop.js +1 -0
  126. package/dist/commands/htop.js.map +1 -0
  127. package/dist/commands/id.js +1 -0
  128. package/dist/commands/id.js.map +1 -0
  129. package/dist/commands/index.js +1 -0
  130. package/dist/commands/index.js.map +1 -0
  131. package/dist/commands/kill.js +1 -0
  132. package/dist/commands/kill.js.map +1 -0
  133. package/dist/commands/ln.js +1 -0
  134. package/dist/commands/ln.js.map +1 -0
  135. package/dist/commands/ls.d.ts.map +1 -1
  136. package/dist/commands/ls.js +171 -37
  137. package/dist/commands/ls.js.map +1 -0
  138. package/dist/commands/lsb-release.js +1 -0
  139. package/dist/commands/lsb-release.js.map +1 -0
  140. package/dist/commands/man.js +1 -0
  141. package/dist/commands/man.js.map +1 -0
  142. package/dist/commands/mkdir.js +1 -0
  143. package/dist/commands/mkdir.js.map +1 -0
  144. package/dist/commands/mv.js +1 -0
  145. package/dist/commands/mv.js.map +1 -0
  146. package/dist/commands/nano.js +1 -0
  147. package/dist/commands/nano.js.map +1 -0
  148. package/dist/commands/neofetch.js +1 -0
  149. package/dist/commands/neofetch.js.map +1 -0
  150. package/dist/commands/node.js +1 -0
  151. package/dist/commands/node.js.map +1 -0
  152. package/dist/commands/npm.js +1 -0
  153. package/dist/commands/npm.js.map +1 -0
  154. package/dist/commands/passwd.js +1 -0
  155. package/dist/commands/passwd.js.map +1 -0
  156. package/dist/commands/ping.js +1 -0
  157. package/dist/commands/ping.js.map +1 -0
  158. package/dist/commands/printf.js +1 -0
  159. package/dist/commands/printf.js.map +1 -0
  160. package/dist/commands/ps.js +1 -0
  161. package/dist/commands/ps.js.map +1 -0
  162. package/dist/commands/pwd.js +1 -0
  163. package/dist/commands/pwd.js.map +1 -0
  164. package/dist/commands/python.js +1 -0
  165. package/dist/commands/python.js.map +1 -0
  166. package/dist/commands/read.js +1 -0
  167. package/dist/commands/read.js.map +1 -0
  168. package/dist/commands/registry.js +1 -0
  169. package/dist/commands/registry.js.map +1 -0
  170. package/dist/commands/rm.js +1 -0
  171. package/dist/commands/rm.js.map +1 -0
  172. package/dist/commands/runtime.d.ts.map +1 -1
  173. package/dist/commands/runtime.js +37 -0
  174. package/dist/commands/runtime.js.map +1 -0
  175. package/dist/commands/sed.js +1 -0
  176. package/dist/commands/sed.js.map +1 -0
  177. package/dist/commands/seq.js +1 -0
  178. package/dist/commands/seq.js.map +1 -0
  179. package/dist/commands/set.js +1 -0
  180. package/dist/commands/set.js.map +1 -0
  181. package/dist/commands/sh.d.ts.map +1 -1
  182. package/dist/commands/sh.js +9 -4
  183. package/dist/commands/sh.js.map +1 -0
  184. package/dist/commands/shift.js +1 -0
  185. package/dist/commands/shift.js.map +1 -0
  186. package/dist/commands/sleep.js +1 -0
  187. package/dist/commands/sleep.js.map +1 -0
  188. package/dist/commands/sort.js +1 -0
  189. package/dist/commands/sort.js.map +1 -0
  190. package/dist/commands/source.js +1 -0
  191. package/dist/commands/source.js.map +1 -0
  192. package/dist/commands/stat.js +1 -0
  193. package/dist/commands/stat.js.map +1 -0
  194. package/dist/commands/su.js +1 -0
  195. package/dist/commands/su.js.map +1 -0
  196. package/dist/commands/sudo.js +1 -0
  197. package/dist/commands/sudo.js.map +1 -0
  198. package/dist/commands/tail.js +1 -0
  199. package/dist/commands/tail.js.map +1 -0
  200. package/dist/commands/tar.js +1 -0
  201. package/dist/commands/tar.js.map +1 -0
  202. package/dist/commands/tee.js +1 -0
  203. package/dist/commands/tee.js.map +1 -0
  204. package/dist/commands/test.d.ts.map +1 -1
  205. package/dist/commands/test.js +1 -0
  206. package/dist/commands/test.js.map +1 -0
  207. package/dist/commands/touch.js +1 -0
  208. package/dist/commands/touch.js.map +1 -0
  209. package/dist/commands/tr.js +1 -0
  210. package/dist/commands/tr.js.map +1 -0
  211. package/dist/commands/tree.js +1 -0
  212. package/dist/commands/tree.js.map +1 -0
  213. package/dist/commands/true.js +1 -0
  214. package/dist/commands/true.js.map +1 -0
  215. package/dist/commands/type.js +1 -0
  216. package/dist/commands/type.js.map +1 -0
  217. package/dist/commands/uname.js +1 -0
  218. package/dist/commands/uname.js.map +1 -0
  219. package/dist/commands/uniq.js +1 -0
  220. package/dist/commands/uniq.js.map +1 -0
  221. package/dist/commands/unset.js +1 -0
  222. package/dist/commands/unset.js.map +1 -0
  223. package/dist/commands/uptime.js +1 -0
  224. package/dist/commands/uptime.js.map +1 -0
  225. package/dist/commands/wc.js +2 -1
  226. package/dist/commands/wc.js.map +1 -0
  227. package/dist/commands/wget.js +1 -0
  228. package/dist/commands/wget.js.map +1 -0
  229. package/dist/commands/which.js +1 -0
  230. package/dist/commands/which.js.map +1 -0
  231. package/dist/commands/who.js +1 -0
  232. package/dist/commands/who.js.map +1 -0
  233. package/dist/commands/whoami.js +1 -0
  234. package/dist/commands/whoami.js.map +1 -0
  235. package/dist/commands/xargs.js +1 -0
  236. package/dist/commands/xargs.js.map +1 -0
  237. package/dist/index.js +1 -0
  238. package/dist/index.js.map +1 -0
  239. package/dist/modules/linuxRootfs.d.ts +35 -17
  240. package/dist/modules/linuxRootfs.d.ts.map +1 -1
  241. package/dist/modules/linuxRootfs.js +332 -152
  242. package/dist/modules/linuxRootfs.js.map +1 -0
  243. package/dist/modules/neofetch.js +1 -0
  244. package/dist/modules/neofetch.js.map +1 -0
  245. package/dist/modules/shellInteractive.js +1 -0
  246. package/dist/modules/shellInteractive.js.map +1 -0
  247. package/dist/modules/shellRuntime.js +1 -0
  248. package/dist/modules/shellRuntime.js.map +1 -0
  249. package/dist/self-standalone.js +1 -0
  250. package/dist/self-standalone.js.map +1 -0
  251. package/dist/standalone-wo-sftp.js +1 -0
  252. package/dist/standalone-wo-sftp.js.map +1 -0
  253. package/dist/standalone.js +1 -0
  254. package/dist/standalone.js.map +1 -0
  255. package/dist/types/commands.d.ts +1 -1
  256. package/dist/types/commands.d.ts.map +1 -1
  257. package/dist/types/commands.js +1 -0
  258. package/dist/types/commands.js.map +1 -0
  259. package/dist/types/pipeline.js +1 -0
  260. package/dist/types/pipeline.js.map +1 -0
  261. package/dist/types/streams.js +1 -0
  262. package/dist/types/streams.js.map +1 -0
  263. package/dist/types/vfs.js +1 -0
  264. package/dist/types/vfs.js.map +1 -0
  265. package/dist/utils/expand.d.ts +2 -2
  266. package/dist/utils/expand.d.ts.map +1 -1
  267. package/dist/utils/expand.js +336 -124
  268. package/dist/utils/expand.js.map +1 -0
  269. package/dist/utils/perfLogger.js +1 -0
  270. package/dist/utils/perfLogger.js.map +1 -0
  271. package/dist/utils/tokenize.js +1 -0
  272. package/dist/utils/tokenize.js.map +1 -0
  273. package/dist/utils/vfsDiff.js +1 -0
  274. package/dist/utils/vfsDiff.js.map +1 -0
  275. package/dist/web-api.js +1 -0
  276. package/dist/web-api.js.map +1 -0
  277. package/dist/web-full.js +1 -0
  278. package/dist/web-full.js.map +1 -0
  279. package/dist/web.js +1 -0
  280. package/dist/web.js.map +1 -0
  281. package/docs/.nojekyll +1 -0
  282. package/docs/assets/hierarchy.js +1 -0
  283. package/docs/assets/highlight.css +162 -0
  284. package/docs/assets/icons.js +18 -0
  285. package/docs/assets/icons.svg +1 -0
  286. package/docs/assets/main.js +60 -0
  287. package/docs/assets/navigation.js +1 -0
  288. package/docs/assets/search.js +1 -0
  289. package/docs/assets/style.css +1633 -0
  290. package/docs/classes/HoneyPot.html +31 -0
  291. package/docs/classes/SshClient.html +66 -0
  292. package/docs/classes/VirtualFileSystem.html +262 -0
  293. package/docs/classes/VirtualPackageManager.html +63 -0
  294. package/docs/classes/VirtualSftpServer.html +169 -0
  295. package/docs/classes/VirtualShell.html +265 -0
  296. package/docs/classes/VirtualSshServer.html +177 -0
  297. package/docs/classes/VirtualUserManager.html +276 -0
  298. package/docs/docs/.nojekyll +1 -0
  299. package/docs/docs/assets/hierarchy.js +1 -0
  300. package/docs/docs/assets/highlight.css +162 -0
  301. package/docs/docs/assets/icons.js +18 -0
  302. package/docs/docs/assets/icons.svg +1 -0
  303. package/docs/docs/assets/main.js +60 -0
  304. package/docs/docs/assets/navigation.js +1 -0
  305. package/docs/docs/assets/search.js +1 -0
  306. package/docs/docs/assets/style.css +1633 -0
  307. package/docs/docs/hierarchy.html +1 -0
  308. package/docs/docs/index.html +1842 -0
  309. package/docs/docs/media/LICENSE +21 -0
  310. package/docs/docs/modules.html +1 -0
  311. package/docs/functions/assertDiff.html +6 -0
  312. package/docs/functions/diffSnapshots.html +7 -0
  313. package/docs/functions/formatDiff.html +6 -0
  314. package/docs/functions/getArg.html +13 -0
  315. package/docs/functions/getFlag.html +15 -0
  316. package/docs/functions/ifFlag.html +11 -0
  317. package/docs/hierarchy.html +1 -0
  318. package/docs/index.html +1842 -0
  319. package/docs/interfaces/AuditLogEntry.html +6 -0
  320. package/docs/interfaces/CommandContext.html +22 -0
  321. package/docs/interfaces/CommandResult.html +26 -0
  322. package/docs/interfaces/ExecStream.html +11 -0
  323. package/docs/interfaces/HoneyPotStats.html +14 -0
  324. package/docs/interfaces/InstalledPackage.html +20 -0
  325. package/docs/interfaces/NanoEditorSession.html +8 -0
  326. package/docs/interfaces/PackageDefinition.html +30 -0
  327. package/docs/interfaces/PackageFile.html +8 -0
  328. package/docs/interfaces/RemoveOptions.html +4 -0
  329. package/docs/interfaces/ShellEnv.html +6 -0
  330. package/docs/interfaces/ShellModule.html +14 -0
  331. package/docs/interfaces/ShellProperties.html +14 -0
  332. package/docs/interfaces/ShellStream.html +11 -0
  333. package/docs/interfaces/SudoChallenge.html +24 -0
  334. package/docs/interfaces/VfsBaseNode.html +12 -0
  335. package/docs/interfaces/VfsDiff.html +10 -0
  336. package/docs/interfaces/VfsDiffEntry.html +6 -0
  337. package/docs/interfaces/VfsDiffModified.html +10 -0
  338. package/docs/interfaces/VfsDirectoryNode.html +15 -0
  339. package/docs/interfaces/VfsFileNode.html +17 -0
  340. package/docs/interfaces/VfsOptions.html +12 -0
  341. package/docs/interfaces/VfsSnapshot.html +3 -0
  342. package/docs/interfaces/VfsSnapshotBaseNode.html +8 -0
  343. package/docs/interfaces/VfsSnapshotDirectoryNode.html +10 -0
  344. package/docs/interfaces/VfsSnapshotFileNode.html +12 -0
  345. package/docs/interfaces/WriteFileOptions.html +6 -0
  346. package/docs/media/LICENSE +21 -0
  347. package/docs/modules.html +1 -0
  348. package/docs/types/CommandMode.html +2 -0
  349. package/docs/types/CommandOutcome.html +2 -0
  350. package/docs/types/VfsNodeStats.html +2 -0
  351. package/docs/types/VfsNodeType.html +2 -0
  352. package/docs/types/VfsPersistenceMode.html +5 -0
  353. package/docs/types/VfsSnapshotNode.html +2 -0
  354. package/examples/web.min.js +5 -5
  355. package/package.json +7 -4
  356. package/src/VirtualFileSystem/index.ts +11 -9
  357. package/src/VirtualShell/shellParser.ts +3 -2
  358. package/src/bun.d.ts +1 -0
  359. package/src/commands/awk.ts +1 -2
  360. package/src/commands/cd.ts +2 -2
  361. package/src/commands/helpers.ts +3 -0
  362. package/src/commands/ls.ts +210 -41
  363. package/src/commands/runtime.ts +56 -3
  364. package/src/commands/sh.ts +7 -4
  365. package/src/commands/test.ts +4 -2
  366. package/src/commands/wc.ts +1 -1
  367. package/src/modules/linuxRootfs.ts +420 -231
  368. package/src/types/commands.ts +1 -1
  369. package/src/utils/expand.ts +256 -76
  370. package/tests/command-helpers.test.ts +80 -0
  371. package/tests/commands-admin-net.test.ts +441 -0
  372. package/tests/commands-advanced.test.ts +456 -0
  373. package/tests/commands-core.test.ts +562 -0
  374. package/tests/commands-missing.test.ts +570 -0
  375. package/tests/commands-specific-units.test.ts +327 -0
  376. package/tests/commands-text-sys.test.ts +445 -0
  377. package/tests/expand.test.ts +170 -0
  378. package/tests/helpers.test.ts +75 -0
  379. package/tests/test-helper.ts +79 -0
  380. package/tsconfig.json +3 -0
  381. package/typedoc.json +8 -0
  382. package/tests/bun-test-shim.ts +0 -9
@@ -1,61 +1,61 @@
1
- "use strict";var sp=Object.create;var Pc=Object.defineProperty;var op=Object.getOwnPropertyDescriptor;var ap=Object.getOwnPropertyNames;var cp=Object.getPrototypeOf,fp=Object.prototype.hasOwnProperty;var ct=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var lp=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ap(t))!fp.call(n,s)&&s!==e&&Pc(n,s,{get:()=>t[s],enumerable:!(r=op(t,s))||r.enumerable});return n};var Kt=(n,t,e)=>(e=n!=null?sp(cp(n)):{},lp(t||!n||!n.__esModule?Pc(e,"default",{value:n,enumerable:!0}):e,n));var ls=ct((Nx,Vl)=>{Vl.exports={newInvalidAsn1Error:function(n){var t=new Error;return t.name="InvalidAsn1Error",t.message=n||"",t}}});var us=ct((Px,Gl)=>{Gl.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 Io=ct((Tx,zl)=>{"use strict";var ds=require("buffer"),Br=ds.Buffer,un={},dn;for(dn in ds)ds.hasOwnProperty(dn)&&(dn==="SlowBuffer"||dn==="Buffer"||(un[dn]=ds[dn]));var Rr=un.Buffer={};for(dn in Br)Br.hasOwnProperty(dn)&&(dn==="allocUnsafe"||dn==="allocUnsafeSlow"||(Rr[dn]=Br[dn]));un.Buffer.prototype=Br.prototype;(!Rr.from||Rr.from===Uint8Array.from)&&(Rr.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 Br(n,t,e)});Rr.alloc||(Rr.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=Br(n);return!t||t.length===0?r.fill(0):typeof e=="string"?r.fill(t,e):r.fill(t),r});if(!un.kStringMaxLength)try{un.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}un.constants||(un.constants={MAX_LENGTH:un.kMaxLength},un.kStringMaxLength&&(un.constants.MAX_STRING_LENGTH=un.kStringMaxLength));zl.exports=un});var Xl=ct((Lx,jl)=>{var ug=require("assert"),Yl=Io().Buffer,pi=us(),dg=ls(),Nr=dg.newInvalidAsn1Error;function jt(n){if(!n||!Yl.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(jt.prototype,"length",{enumerable:!0,get:function(){return this._len}});Object.defineProperty(jt.prototype,"offset",{enumerable:!0,get:function(){return this._offset}});Object.defineProperty(jt.prototype,"remain",{get:function(){return this._size-this._offset}});Object.defineProperty(jt.prototype,"buffer",{get:function(){return this._buf.slice(this._offset)}});jt.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};jt.prototype.peek=function(){return this.readByte(!0)};jt.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 Nr("Indefinite length not supported");if(t>4)throw Nr("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};jt.prototype.readSequence=function(n){var t=this.peek();if(t===null)return null;if(n!==void 0&&n!==t)throw Nr("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)};jt.prototype.readInt=function(){return this._readTag(pi.Integer)};jt.prototype.readBoolean=function(){return this._readTag(pi.Boolean)!==0};jt.prototype.readEnumeration=function(){return this._readTag(pi.Enumeration)};jt.prototype.readString=function(n,t){n||(n=pi.OctetString);var e=this.peek();if(e===null)return null;if(e!==n)throw Nr("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?Yl.alloc(0):"";var s=this._buf.slice(this._offset,this._offset+this.length);return this._offset+=this.length,t?s:s.toString("utf8")};jt.prototype.readOID=function(n){n||(n=pi.OID);var t=this.readString(n,!0);if(t===null)return null;for(var e=[],r=0,s=0;s<t.length;s++){var i=t[s]&255;r<<=7,r+=i&127,(i&128)===0&&(e.push(r),r=0)}return r=e.shift(),e.unshift(r%40),e.unshift(r/40>>0),e.join(".")};jt.prototype._readTag=function(n){ug.ok(n!==void 0);var t=this.peek();if(t===null)return null;if(t!==n)throw Nr("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 Nr("Integer too long: "+this.length);if(this.length>this._size-e)return null;this._offset=e;for(var r=this._buf[this._offset],s=0,i=0;i<this.length;i++)s<<=8,s|=this._buf[this._offset++]&255;return(r&128)===128&&i!==4&&(s-=1<<i*8),s>>0};jl.exports=jt});var Zl=ct((Dx,Jl)=>{var qn=require("assert"),hs=Io().Buffer,Kn=us(),hg=ls(),ps=hg.newInvalidAsn1Error,pg={size:1024,growthFactor:8};function gg(n,t){qn.ok(n),qn.equal(typeof n,"object"),qn.ok(t),qn.equal(typeof t,"object");var e=Object.getOwnPropertyNames(n);return e.forEach(function(r){if(!t[r]){var s=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(t,r,s)}}),t}function Vt(n){n=gg(pg,n||{}),this._buf=hs.alloc(n.size||1024),this._size=this._buf.length,this._offset=0,this._options=n,this._seq=[]}Object.defineProperty(Vt.prototype,"buffer",{get:function(){if(this._seq.length)throw ps(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});Vt.prototype.writeByte=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=n};Vt.prototype.writeInt=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Kn.Integer);for(var e=4;((n&4286578688)===0||(n&4286578688)===-8388608)&&e>1;)e--,n<<=8;if(e>4)throw ps("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};Vt.prototype.writeNull=function(){this.writeByte(Kn.Null),this.writeByte(0)};Vt.prototype.writeEnumeration=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Kn.Enumeration),this.writeInt(n,t)};Vt.prototype.writeBoolean=function(n,t){if(typeof n!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Kn.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=n?255:0};Vt.prototype.writeString=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string (was: "+typeof n+")");typeof t!="number"&&(t=Kn.OctetString);var e=hs.byteLength(n);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(n,this._offset),this._offset+=e)};Vt.prototype.writeBuffer=function(n,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!hs.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};Vt.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)})};Vt.prototype.writeOID=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Kn.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("."),s=[];s.push(parseInt(r[0],10)*40+parseInt(r[1],10)),r.slice(2).forEach(function(o){e(s,parseInt(o,10))});var i=this;this._ensure(2+s.length),this.writeByte(t),this.writeLength(s.length),s.forEach(function(o){i.writeByte(o)})};Vt.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 ps("Length too long (> 4 bytes)")};Vt.prototype.startSequence=function(n){typeof n!="number"&&(n=Kn.Sequence|Kn.Constructor),this.writeByte(n),this._seq.push(this._offset),this._ensure(3),this._offset+=3};Vt.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 ps("Sequence too long")};Vt.prototype._shift=function(n,t,e){qn.ok(n!==void 0),qn.ok(t!==void 0),qn.ok(e),this._buf.copy(this._buf,n+e,n,n+t),this._offset+=e};Vt.prototype._ensure=function(n){if(qn.ok(n),this._size-this._offset<n){var t=this._size*this._options.growthFactor;t-this._offset<n&&(t+=n);var e=hs.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};Jl.exports=Vt});var eu=ct((Ux,As)=>{var Co=ls(),vo=us(),mg=Xl(),Ag=Zl();As.exports={Reader:mg,Writer:Ag};for(gs in vo)vo.hasOwnProperty(gs)&&(As.exports[gs]=vo[gs]);var gs;for(ms in Co)Co.hasOwnProperty(ms)&&(As.exports[ms]=Co[ms]);var ms});var gi=ct(($x,tu)=>{var ko=eu();tu.exports={Ber:ko,BerReader:ko.Reader,BerWriter:ko.Writer}});var nu=ct((Mx,Es)=>{(function(n){"use strict";var t=function(g){var A,m=new Float64Array(16);if(g)for(A=0;A<g.length;A++)m[A]=g[A];return m},e=function(){throw new Error("no PRNG")},r=new Uint8Array(16),s=new Uint8Array(32);s[0]=9;var i=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 p(g,A,m,d){g[A]=m>>24&255,g[A+1]=m>>16&255,g[A+2]=m>>8&255,g[A+3]=m&255,g[A+4]=d>>24&255,g[A+5]=d>>16&255,g[A+6]=d>>8&255,g[A+7]=d&255}function _(g,A,m,d,y){var L,O=0;for(L=0;L<y;L++)O|=g[A+L]^m[d+L];return(1&O-1>>>8)-1}function E(g,A,m,d){return _(g,A,m,d,16)}function b(g,A,m,d){return _(g,A,m,d,32)}function v(g,A,m,d){for(var y=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,L=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,O=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,ae=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,me=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,he=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,nt=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ge=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Te=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Le=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,He=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,De=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,$e=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,Ue=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,Ae=y,be=L,pe=O,Ee=J,ye=ae,de=me,Q=he,W=nt,re=ge,X=Te,Z=Le,oe=He,Ce=Oe,Qe=De,qe=$e,We=Ue,w,Ve=0;Ve<20;Ve+=2)w=Ae+Ce|0,ye^=w<<7|w>>>25,w=ye+Ae|0,re^=w<<9|w>>>23,w=re+ye|0,Ce^=w<<13|w>>>19,w=Ce+re|0,Ae^=w<<18|w>>>14,w=de+be|0,X^=w<<7|w>>>25,w=X+de|0,Qe^=w<<9|w>>>23,w=Qe+X|0,be^=w<<13|w>>>19,w=be+Qe|0,de^=w<<18|w>>>14,w=Z+Q|0,qe^=w<<7|w>>>25,w=qe+Z|0,pe^=w<<9|w>>>23,w=pe+qe|0,Q^=w<<13|w>>>19,w=Q+pe|0,Z^=w<<18|w>>>14,w=We+oe|0,Ee^=w<<7|w>>>25,w=Ee+We|0,W^=w<<9|w>>>23,w=W+Ee|0,oe^=w<<13|w>>>19,w=oe+W|0,We^=w<<18|w>>>14,w=Ae+Ee|0,be^=w<<7|w>>>25,w=be+Ae|0,pe^=w<<9|w>>>23,w=pe+be|0,Ee^=w<<13|w>>>19,w=Ee+pe|0,Ae^=w<<18|w>>>14,w=de+ye|0,Q^=w<<7|w>>>25,w=Q+de|0,W^=w<<9|w>>>23,w=W+Q|0,ye^=w<<13|w>>>19,w=ye+W|0,de^=w<<18|w>>>14,w=Z+X|0,oe^=w<<7|w>>>25,w=oe+Z|0,re^=w<<9|w>>>23,w=re+oe|0,X^=w<<13|w>>>19,w=X+re|0,Z^=w<<18|w>>>14,w=We+qe|0,Ce^=w<<7|w>>>25,w=Ce+We|0,Qe^=w<<9|w>>>23,w=Qe+Ce|0,qe^=w<<13|w>>>19,w=qe+Qe|0,We^=w<<18|w>>>14;Ae=Ae+y|0,be=be+L|0,pe=pe+O|0,Ee=Ee+J|0,ye=ye+ae|0,de=de+me|0,Q=Q+he|0,W=W+nt|0,re=re+ge|0,X=X+Te|0,Z=Z+Le|0,oe=oe+He|0,Ce=Ce+Oe|0,Qe=Qe+De|0,qe=qe+$e|0,We=We+Ue|0,g[0]=Ae>>>0&255,g[1]=Ae>>>8&255,g[2]=Ae>>>16&255,g[3]=Ae>>>24&255,g[4]=be>>>0&255,g[5]=be>>>8&255,g[6]=be>>>16&255,g[7]=be>>>24&255,g[8]=pe>>>0&255,g[9]=pe>>>8&255,g[10]=pe>>>16&255,g[11]=pe>>>24&255,g[12]=Ee>>>0&255,g[13]=Ee>>>8&255,g[14]=Ee>>>16&255,g[15]=Ee>>>24&255,g[16]=ye>>>0&255,g[17]=ye>>>8&255,g[18]=ye>>>16&255,g[19]=ye>>>24&255,g[20]=de>>>0&255,g[21]=de>>>8&255,g[22]=de>>>16&255,g[23]=de>>>24&255,g[24]=Q>>>0&255,g[25]=Q>>>8&255,g[26]=Q>>>16&255,g[27]=Q>>>24&255,g[28]=W>>>0&255,g[29]=W>>>8&255,g[30]=W>>>16&255,g[31]=W>>>24&255,g[32]=re>>>0&255,g[33]=re>>>8&255,g[34]=re>>>16&255,g[35]=re>>>24&255,g[36]=X>>>0&255,g[37]=X>>>8&255,g[38]=X>>>16&255,g[39]=X>>>24&255,g[40]=Z>>>0&255,g[41]=Z>>>8&255,g[42]=Z>>>16&255,g[43]=Z>>>24&255,g[44]=oe>>>0&255,g[45]=oe>>>8&255,g[46]=oe>>>16&255,g[47]=oe>>>24&255,g[48]=Ce>>>0&255,g[49]=Ce>>>8&255,g[50]=Ce>>>16&255,g[51]=Ce>>>24&255,g[52]=Qe>>>0&255,g[53]=Qe>>>8&255,g[54]=Qe>>>16&255,g[55]=Qe>>>24&255,g[56]=qe>>>0&255,g[57]=qe>>>8&255,g[58]=qe>>>16&255,g[59]=qe>>>24&255,g[60]=We>>>0&255,g[61]=We>>>8&255,g[62]=We>>>16&255,g[63]=We>>>24&255}function U(g,A,m,d){for(var y=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,L=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,O=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,ae=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,me=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,he=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,nt=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ge=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Te=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Le=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,He=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,De=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,$e=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,Ue=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,Ae=y,be=L,pe=O,Ee=J,ye=ae,de=me,Q=he,W=nt,re=ge,X=Te,Z=Le,oe=He,Ce=Oe,Qe=De,qe=$e,We=Ue,w,Ve=0;Ve<20;Ve+=2)w=Ae+Ce|0,ye^=w<<7|w>>>25,w=ye+Ae|0,re^=w<<9|w>>>23,w=re+ye|0,Ce^=w<<13|w>>>19,w=Ce+re|0,Ae^=w<<18|w>>>14,w=de+be|0,X^=w<<7|w>>>25,w=X+de|0,Qe^=w<<9|w>>>23,w=Qe+X|0,be^=w<<13|w>>>19,w=be+Qe|0,de^=w<<18|w>>>14,w=Z+Q|0,qe^=w<<7|w>>>25,w=qe+Z|0,pe^=w<<9|w>>>23,w=pe+qe|0,Q^=w<<13|w>>>19,w=Q+pe|0,Z^=w<<18|w>>>14,w=We+oe|0,Ee^=w<<7|w>>>25,w=Ee+We|0,W^=w<<9|w>>>23,w=W+Ee|0,oe^=w<<13|w>>>19,w=oe+W|0,We^=w<<18|w>>>14,w=Ae+Ee|0,be^=w<<7|w>>>25,w=be+Ae|0,pe^=w<<9|w>>>23,w=pe+be|0,Ee^=w<<13|w>>>19,w=Ee+pe|0,Ae^=w<<18|w>>>14,w=de+ye|0,Q^=w<<7|w>>>25,w=Q+de|0,W^=w<<9|w>>>23,w=W+Q|0,ye^=w<<13|w>>>19,w=ye+W|0,de^=w<<18|w>>>14,w=Z+X|0,oe^=w<<7|w>>>25,w=oe+Z|0,re^=w<<9|w>>>23,w=re+oe|0,X^=w<<13|w>>>19,w=X+re|0,Z^=w<<18|w>>>14,w=We+qe|0,Ce^=w<<7|w>>>25,w=Ce+We|0,Qe^=w<<9|w>>>23,w=Qe+Ce|0,qe^=w<<13|w>>>19,w=qe+Qe|0,We^=w<<18|w>>>14;g[0]=Ae>>>0&255,g[1]=Ae>>>8&255,g[2]=Ae>>>16&255,g[3]=Ae>>>24&255,g[4]=de>>>0&255,g[5]=de>>>8&255,g[6]=de>>>16&255,g[7]=de>>>24&255,g[8]=Z>>>0&255,g[9]=Z>>>8&255,g[10]=Z>>>16&255,g[11]=Z>>>24&255,g[12]=We>>>0&255,g[13]=We>>>8&255,g[14]=We>>>16&255,g[15]=We>>>24&255,g[16]=Q>>>0&255,g[17]=Q>>>8&255,g[18]=Q>>>16&255,g[19]=Q>>>24&255,g[20]=W>>>0&255,g[21]=W>>>8&255,g[22]=W>>>16&255,g[23]=W>>>24&255,g[24]=re>>>0&255,g[25]=re>>>8&255,g[26]=re>>>16&255,g[27]=re>>>24&255,g[28]=X>>>0&255,g[29]=X>>>8&255,g[30]=X>>>16&255,g[31]=X>>>24&255}function H(g,A,m,d){v(g,A,m,d)}function C(g,A,m,d){U(g,A,m,d)}var F=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function V(g,A,m,d,y,L,O){var J=new Uint8Array(16),ae=new Uint8Array(64),me,he;for(he=0;he<16;he++)J[he]=0;for(he=0;he<8;he++)J[he]=L[he];for(;y>=64;){for(H(ae,J,O,F),he=0;he<64;he++)g[A+he]=m[d+he]^ae[he];for(me=1,he=8;he<16;he++)me=me+(J[he]&255)|0,J[he]=me&255,me>>>=8;y-=64,A+=64,d+=64}if(y>0)for(H(ae,J,O,F),he=0;he<y;he++)g[A+he]=m[d+he]^ae[he];return 0}function N(g,A,m,d,y){var L=new Uint8Array(16),O=new Uint8Array(64),J,ae;for(ae=0;ae<16;ae++)L[ae]=0;for(ae=0;ae<8;ae++)L[ae]=d[ae];for(;m>=64;){for(H(O,L,y,F),ae=0;ae<64;ae++)g[A+ae]=O[ae];for(J=1,ae=8;ae<16;ae++)J=J+(L[ae]&255)|0,L[ae]=J&255,J>>>=8;m-=64,A+=64}if(m>0)for(H(O,L,y,F),ae=0;ae<m;ae++)g[A+ae]=O[ae];return 0}function x(g,A,m,d,y){var L=new Uint8Array(32);C(L,d,y,F);for(var O=new Uint8Array(8),J=0;J<8;J++)O[J]=d[J+16];return N(g,A,m,O,L)}function S(g,A,m,d,y,L,O){var J=new Uint8Array(32);C(J,L,O,F);for(var ae=new Uint8Array(8),me=0;me<8;me++)ae[me]=L[me+16];return V(g,A,m,d,y,ae,J)}var I=function(g){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,y,L,O,J,ae;A=g[0]&255|(g[1]&255)<<8,this.r[0]=A&8191,m=g[2]&255|(g[3]&255)<<8,this.r[1]=(A>>>13|m<<3)&8191,d=g[4]&255|(g[5]&255)<<8,this.r[2]=(m>>>10|d<<6)&7939,y=g[6]&255|(g[7]&255)<<8,this.r[3]=(d>>>7|y<<9)&8191,L=g[8]&255|(g[9]&255)<<8,this.r[4]=(y>>>4|L<<12)&255,this.r[5]=L>>>1&8190,O=g[10]&255|(g[11]&255)<<8,this.r[6]=(L>>>14|O<<2)&8191,J=g[12]&255|(g[13]&255)<<8,this.r[7]=(O>>>11|J<<5)&8065,ae=g[14]&255|(g[15]&255)<<8,this.r[8]=(J>>>8|ae<<8)&8191,this.r[9]=ae>>>5&127,this.pad[0]=g[16]&255|(g[17]&255)<<8,this.pad[1]=g[18]&255|(g[19]&255)<<8,this.pad[2]=g[20]&255|(g[21]&255)<<8,this.pad[3]=g[22]&255|(g[23]&255)<<8,this.pad[4]=g[24]&255|(g[25]&255)<<8,this.pad[5]=g[26]&255|(g[27]&255)<<8,this.pad[6]=g[28]&255|(g[29]&255)<<8,this.pad[7]=g[30]&255|(g[31]&255)<<8};I.prototype.blocks=function(g,A,m){for(var d=this.fin?0:2048,y,L,O,J,ae,me,he,nt,ge,Te,Le,He,Oe,De,$e,Ue,Ae,be,pe,Ee=this.h[0],ye=this.h[1],de=this.h[2],Q=this.h[3],W=this.h[4],re=this.h[5],X=this.h[6],Z=this.h[7],oe=this.h[8],Ce=this.h[9],Qe=this.r[0],qe=this.r[1],We=this.r[2],w=this.r[3],Ve=this.r[4],rt=this.r[5],it=this.r[6],Ke=this.r[7],Ze=this.r[8],et=this.r[9];m>=16;)y=g[A+0]&255|(g[A+1]&255)<<8,Ee+=y&8191,L=g[A+2]&255|(g[A+3]&255)<<8,ye+=(y>>>13|L<<3)&8191,O=g[A+4]&255|(g[A+5]&255)<<8,de+=(L>>>10|O<<6)&8191,J=g[A+6]&255|(g[A+7]&255)<<8,Q+=(O>>>7|J<<9)&8191,ae=g[A+8]&255|(g[A+9]&255)<<8,W+=(J>>>4|ae<<12)&8191,re+=ae>>>1&8191,me=g[A+10]&255|(g[A+11]&255)<<8,X+=(ae>>>14|me<<2)&8191,he=g[A+12]&255|(g[A+13]&255)<<8,Z+=(me>>>11|he<<5)&8191,nt=g[A+14]&255|(g[A+15]&255)<<8,oe+=(he>>>8|nt<<8)&8191,Ce+=nt>>>5|d,ge=0,Te=ge,Te+=Ee*Qe,Te+=ye*(5*et),Te+=de*(5*Ze),Te+=Q*(5*Ke),Te+=W*(5*it),ge=Te>>>13,Te&=8191,Te+=re*(5*rt),Te+=X*(5*Ve),Te+=Z*(5*w),Te+=oe*(5*We),Te+=Ce*(5*qe),ge+=Te>>>13,Te&=8191,Le=ge,Le+=Ee*qe,Le+=ye*Qe,Le+=de*(5*et),Le+=Q*(5*Ze),Le+=W*(5*Ke),ge=Le>>>13,Le&=8191,Le+=re*(5*it),Le+=X*(5*rt),Le+=Z*(5*Ve),Le+=oe*(5*w),Le+=Ce*(5*We),ge+=Le>>>13,Le&=8191,He=ge,He+=Ee*We,He+=ye*qe,He+=de*Qe,He+=Q*(5*et),He+=W*(5*Ze),ge=He>>>13,He&=8191,He+=re*(5*Ke),He+=X*(5*it),He+=Z*(5*rt),He+=oe*(5*Ve),He+=Ce*(5*w),ge+=He>>>13,He&=8191,Oe=ge,Oe+=Ee*w,Oe+=ye*We,Oe+=de*qe,Oe+=Q*Qe,Oe+=W*(5*et),ge=Oe>>>13,Oe&=8191,Oe+=re*(5*Ze),Oe+=X*(5*Ke),Oe+=Z*(5*it),Oe+=oe*(5*rt),Oe+=Ce*(5*Ve),ge+=Oe>>>13,Oe&=8191,De=ge,De+=Ee*Ve,De+=ye*w,De+=de*We,De+=Q*qe,De+=W*Qe,ge=De>>>13,De&=8191,De+=re*(5*et),De+=X*(5*Ze),De+=Z*(5*Ke),De+=oe*(5*it),De+=Ce*(5*rt),ge+=De>>>13,De&=8191,$e=ge,$e+=Ee*rt,$e+=ye*Ve,$e+=de*w,$e+=Q*We,$e+=W*qe,ge=$e>>>13,$e&=8191,$e+=re*Qe,$e+=X*(5*et),$e+=Z*(5*Ze),$e+=oe*(5*Ke),$e+=Ce*(5*it),ge+=$e>>>13,$e&=8191,Ue=ge,Ue+=Ee*it,Ue+=ye*rt,Ue+=de*Ve,Ue+=Q*w,Ue+=W*We,ge=Ue>>>13,Ue&=8191,Ue+=re*qe,Ue+=X*Qe,Ue+=Z*(5*et),Ue+=oe*(5*Ze),Ue+=Ce*(5*Ke),ge+=Ue>>>13,Ue&=8191,Ae=ge,Ae+=Ee*Ke,Ae+=ye*it,Ae+=de*rt,Ae+=Q*Ve,Ae+=W*w,ge=Ae>>>13,Ae&=8191,Ae+=re*We,Ae+=X*qe,Ae+=Z*Qe,Ae+=oe*(5*et),Ae+=Ce*(5*Ze),ge+=Ae>>>13,Ae&=8191,be=ge,be+=Ee*Ze,be+=ye*Ke,be+=de*it,be+=Q*rt,be+=W*Ve,ge=be>>>13,be&=8191,be+=re*w,be+=X*We,be+=Z*qe,be+=oe*Qe,be+=Ce*(5*et),ge+=be>>>13,be&=8191,pe=ge,pe+=Ee*et,pe+=ye*Ze,pe+=de*Ke,pe+=Q*it,pe+=W*rt,ge=pe>>>13,pe&=8191,pe+=re*Ve,pe+=X*w,pe+=Z*We,pe+=oe*qe,pe+=Ce*Qe,ge+=pe>>>13,pe&=8191,ge=(ge<<2)+ge|0,ge=ge+Te|0,Te=ge&8191,ge=ge>>>13,Le+=ge,Ee=Te,ye=Le,de=He,Q=Oe,W=De,re=$e,X=Ue,Z=Ae,oe=be,Ce=pe,A+=16,m-=16;this.h[0]=Ee,this.h[1]=ye,this.h[2]=de,this.h[3]=Q,this.h[4]=W,this.h[5]=re,this.h[6]=X,this.h[7]=Z,this.h[8]=oe,this.h[9]=Ce},I.prototype.finish=function(g,A){var m=new Uint16Array(10),d,y,L,O;if(this.leftover){for(O=this.leftover,this.buffer[O++]=1;O<16;O++)this.buffer[O]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(d=this.h[1]>>>13,this.h[1]&=8191,O=2;O<10;O++)this.h[O]+=d,d=this.h[O]>>>13,this.h[O]&=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,O=1;O<10;O++)m[O]=this.h[O]+d,d=m[O]>>>13,m[O]&=8191;for(m[9]-=8192,y=(d^1)-1,O=0;O<10;O++)m[O]&=y;for(y=~y,O=0;O<10;O++)this.h[O]=this.h[O]&y|m[O];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,L=this.h[0]+this.pad[0],this.h[0]=L&65535,O=1;O<8;O++)L=(this.h[O]+this.pad[O]|0)+(L>>>16)|0,this.h[O]=L&65535;g[A+0]=this.h[0]>>>0&255,g[A+1]=this.h[0]>>>8&255,g[A+2]=this.h[1]>>>0&255,g[A+3]=this.h[1]>>>8&255,g[A+4]=this.h[2]>>>0&255,g[A+5]=this.h[2]>>>8&255,g[A+6]=this.h[3]>>>0&255,g[A+7]=this.h[3]>>>8&255,g[A+8]=this.h[4]>>>0&255,g[A+9]=this.h[4]>>>8&255,g[A+10]=this.h[5]>>>0&255,g[A+11]=this.h[5]>>>8&255,g[A+12]=this.h[6]>>>0&255,g[A+13]=this.h[6]>>>8&255,g[A+14]=this.h[7]>>>0&255,g[A+15]=this.h[7]>>>8&255},I.prototype.update=function(g,A,m){var d,y;if(this.leftover){for(y=16-this.leftover,y>m&&(y=m),d=0;d<y;d++)this.buffer[this.leftover+d]=g[A+d];if(m-=y,A+=y,this.leftover+=y,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(m>=16&&(y=m-m%16,this.blocks(g,A,y),A+=y,m-=y),m){for(d=0;d<m;d++)this.buffer[this.leftover+d]=g[A+d];this.leftover+=m}};function k(g,A,m,d,y,L){var O=new I(L);return O.update(m,d,y),O.finish(g,A),0}function R(g,A,m,d,y,L){var O=new Uint8Array(16);return k(O,0,m,d,y,L),E(g,A,O,0)}function ne(g,A,m,d,y){var L;if(m<32)return-1;for(S(g,0,A,0,m,d,y),k(g,16,g,32,m-32,g),L=0;L<16;L++)g[L]=0;return 0}function z(g,A,m,d,y){var L,O=new Uint8Array(32);if(m<32||(x(O,0,32,d,y),R(A,16,A,32,m-32,O)!==0))return-1;for(S(g,0,A,0,m,d,y),L=0;L<32;L++)g[L]=0;return 0}function Y(g,A){var m;for(m=0;m<16;m++)g[m]=A[m]|0}function te(g){var A,m,d=1;for(A=0;A<16;A++)m=g[A]+d+65535,d=Math.floor(m/65536),g[A]=m-d*65536;g[0]+=d-1+37*(d-1)}function ce(g,A,m){for(var d,y=~(m-1),L=0;L<16;L++)d=y&(g[L]^A[L]),g[L]^=d,A[L]^=d}function $(g,A){var m,d,y,L=t(),O=t();for(m=0;m<16;m++)O[m]=A[m];for(te(O),te(O),te(O),d=0;d<2;d++){for(L[0]=O[0]-65517,m=1;m<15;m++)L[m]=O[m]-65535-(L[m-1]>>16&1),L[m-1]&=65535;L[15]=O[15]-32767-(L[14]>>16&1),y=L[15]>>16&1,L[14]&=65535,ce(O,L,1-y)}for(m=0;m<16;m++)g[2*m]=O[m]&255,g[2*m+1]=O[m]>>8}function B(g,A){var m=new Uint8Array(32),d=new Uint8Array(32);return $(m,g),$(d,A),b(m,0,d,0)}function T(g){var A=new Uint8Array(32);return $(A,g),A[0]&1}function q(g,A){var m;for(m=0;m<16;m++)g[m]=A[2*m]+(A[2*m+1]<<8);g[15]&=32767}function ee(g,A,m){for(var d=0;d<16;d++)g[d]=A[d]+m[d]}function fe(g,A,m){for(var d=0;d<16;d++)g[d]=A[d]-m[d]}function ie(g,A,m){var d,y,L=0,O=0,J=0,ae=0,me=0,he=0,nt=0,ge=0,Te=0,Le=0,He=0,Oe=0,De=0,$e=0,Ue=0,Ae=0,be=0,pe=0,Ee=0,ye=0,de=0,Q=0,W=0,re=0,X=0,Z=0,oe=0,Ce=0,Qe=0,qe=0,We=0,w=m[0],Ve=m[1],rt=m[2],it=m[3],Ke=m[4],Ze=m[5],et=m[6],kt=m[7],lt=m[8],It=m[9],Ct=m[10],vt=m[11],Dt=m[12],Qt=m[13],Wt=m[14],qt=m[15];d=A[0],L+=d*w,O+=d*Ve,J+=d*rt,ae+=d*it,me+=d*Ke,he+=d*Ze,nt+=d*et,ge+=d*kt,Te+=d*lt,Le+=d*It,He+=d*Ct,Oe+=d*vt,De+=d*Dt,$e+=d*Qt,Ue+=d*Wt,Ae+=d*qt,d=A[1],O+=d*w,J+=d*Ve,ae+=d*rt,me+=d*it,he+=d*Ke,nt+=d*Ze,ge+=d*et,Te+=d*kt,Le+=d*lt,He+=d*It,Oe+=d*Ct,De+=d*vt,$e+=d*Dt,Ue+=d*Qt,Ae+=d*Wt,be+=d*qt,d=A[2],J+=d*w,ae+=d*Ve,me+=d*rt,he+=d*it,nt+=d*Ke,ge+=d*Ze,Te+=d*et,Le+=d*kt,He+=d*lt,Oe+=d*It,De+=d*Ct,$e+=d*vt,Ue+=d*Dt,Ae+=d*Qt,be+=d*Wt,pe+=d*qt,d=A[3],ae+=d*w,me+=d*Ve,he+=d*rt,nt+=d*it,ge+=d*Ke,Te+=d*Ze,Le+=d*et,He+=d*kt,Oe+=d*lt,De+=d*It,$e+=d*Ct,Ue+=d*vt,Ae+=d*Dt,be+=d*Qt,pe+=d*Wt,Ee+=d*qt,d=A[4],me+=d*w,he+=d*Ve,nt+=d*rt,ge+=d*it,Te+=d*Ke,Le+=d*Ze,He+=d*et,Oe+=d*kt,De+=d*lt,$e+=d*It,Ue+=d*Ct,Ae+=d*vt,be+=d*Dt,pe+=d*Qt,Ee+=d*Wt,ye+=d*qt,d=A[5],he+=d*w,nt+=d*Ve,ge+=d*rt,Te+=d*it,Le+=d*Ke,He+=d*Ze,Oe+=d*et,De+=d*kt,$e+=d*lt,Ue+=d*It,Ae+=d*Ct,be+=d*vt,pe+=d*Dt,Ee+=d*Qt,ye+=d*Wt,de+=d*qt,d=A[6],nt+=d*w,ge+=d*Ve,Te+=d*rt,Le+=d*it,He+=d*Ke,Oe+=d*Ze,De+=d*et,$e+=d*kt,Ue+=d*lt,Ae+=d*It,be+=d*Ct,pe+=d*vt,Ee+=d*Dt,ye+=d*Qt,de+=d*Wt,Q+=d*qt,d=A[7],ge+=d*w,Te+=d*Ve,Le+=d*rt,He+=d*it,Oe+=d*Ke,De+=d*Ze,$e+=d*et,Ue+=d*kt,Ae+=d*lt,be+=d*It,pe+=d*Ct,Ee+=d*vt,ye+=d*Dt,de+=d*Qt,Q+=d*Wt,W+=d*qt,d=A[8],Te+=d*w,Le+=d*Ve,He+=d*rt,Oe+=d*it,De+=d*Ke,$e+=d*Ze,Ue+=d*et,Ae+=d*kt,be+=d*lt,pe+=d*It,Ee+=d*Ct,ye+=d*vt,de+=d*Dt,Q+=d*Qt,W+=d*Wt,re+=d*qt,d=A[9],Le+=d*w,He+=d*Ve,Oe+=d*rt,De+=d*it,$e+=d*Ke,Ue+=d*Ze,Ae+=d*et,be+=d*kt,pe+=d*lt,Ee+=d*It,ye+=d*Ct,de+=d*vt,Q+=d*Dt,W+=d*Qt,re+=d*Wt,X+=d*qt,d=A[10],He+=d*w,Oe+=d*Ve,De+=d*rt,$e+=d*it,Ue+=d*Ke,Ae+=d*Ze,be+=d*et,pe+=d*kt,Ee+=d*lt,ye+=d*It,de+=d*Ct,Q+=d*vt,W+=d*Dt,re+=d*Qt,X+=d*Wt,Z+=d*qt,d=A[11],Oe+=d*w,De+=d*Ve,$e+=d*rt,Ue+=d*it,Ae+=d*Ke,be+=d*Ze,pe+=d*et,Ee+=d*kt,ye+=d*lt,de+=d*It,Q+=d*Ct,W+=d*vt,re+=d*Dt,X+=d*Qt,Z+=d*Wt,oe+=d*qt,d=A[12],De+=d*w,$e+=d*Ve,Ue+=d*rt,Ae+=d*it,be+=d*Ke,pe+=d*Ze,Ee+=d*et,ye+=d*kt,de+=d*lt,Q+=d*It,W+=d*Ct,re+=d*vt,X+=d*Dt,Z+=d*Qt,oe+=d*Wt,Ce+=d*qt,d=A[13],$e+=d*w,Ue+=d*Ve,Ae+=d*rt,be+=d*it,pe+=d*Ke,Ee+=d*Ze,ye+=d*et,de+=d*kt,Q+=d*lt,W+=d*It,re+=d*Ct,X+=d*vt,Z+=d*Dt,oe+=d*Qt,Ce+=d*Wt,Qe+=d*qt,d=A[14],Ue+=d*w,Ae+=d*Ve,be+=d*rt,pe+=d*it,Ee+=d*Ke,ye+=d*Ze,de+=d*et,Q+=d*kt,W+=d*lt,re+=d*It,X+=d*Ct,Z+=d*vt,oe+=d*Dt,Ce+=d*Qt,Qe+=d*Wt,qe+=d*qt,d=A[15],Ae+=d*w,be+=d*Ve,pe+=d*rt,Ee+=d*it,ye+=d*Ke,de+=d*Ze,Q+=d*et,W+=d*kt,re+=d*lt,X+=d*It,Z+=d*Ct,oe+=d*vt,Ce+=d*Dt,Qe+=d*Qt,qe+=d*Wt,We+=d*qt,L+=38*be,O+=38*pe,J+=38*Ee,ae+=38*ye,me+=38*de,he+=38*Q,nt+=38*W,ge+=38*re,Te+=38*X,Le+=38*Z,He+=38*oe,Oe+=38*Ce,De+=38*Qe,$e+=38*qe,Ue+=38*We,y=1,d=L+y+65535,y=Math.floor(d/65536),L=d-y*65536,d=O+y+65535,y=Math.floor(d/65536),O=d-y*65536,d=J+y+65535,y=Math.floor(d/65536),J=d-y*65536,d=ae+y+65535,y=Math.floor(d/65536),ae=d-y*65536,d=me+y+65535,y=Math.floor(d/65536),me=d-y*65536,d=he+y+65535,y=Math.floor(d/65536),he=d-y*65536,d=nt+y+65535,y=Math.floor(d/65536),nt=d-y*65536,d=ge+y+65535,y=Math.floor(d/65536),ge=d-y*65536,d=Te+y+65535,y=Math.floor(d/65536),Te=d-y*65536,d=Le+y+65535,y=Math.floor(d/65536),Le=d-y*65536,d=He+y+65535,y=Math.floor(d/65536),He=d-y*65536,d=Oe+y+65535,y=Math.floor(d/65536),Oe=d-y*65536,d=De+y+65535,y=Math.floor(d/65536),De=d-y*65536,d=$e+y+65535,y=Math.floor(d/65536),$e=d-y*65536,d=Ue+y+65535,y=Math.floor(d/65536),Ue=d-y*65536,d=Ae+y+65535,y=Math.floor(d/65536),Ae=d-y*65536,L+=y-1+37*(y-1),y=1,d=L+y+65535,y=Math.floor(d/65536),L=d-y*65536,d=O+y+65535,y=Math.floor(d/65536),O=d-y*65536,d=J+y+65535,y=Math.floor(d/65536),J=d-y*65536,d=ae+y+65535,y=Math.floor(d/65536),ae=d-y*65536,d=me+y+65535,y=Math.floor(d/65536),me=d-y*65536,d=he+y+65535,y=Math.floor(d/65536),he=d-y*65536,d=nt+y+65535,y=Math.floor(d/65536),nt=d-y*65536,d=ge+y+65535,y=Math.floor(d/65536),ge=d-y*65536,d=Te+y+65535,y=Math.floor(d/65536),Te=d-y*65536,d=Le+y+65535,y=Math.floor(d/65536),Le=d-y*65536,d=He+y+65535,y=Math.floor(d/65536),He=d-y*65536,d=Oe+y+65535,y=Math.floor(d/65536),Oe=d-y*65536,d=De+y+65535,y=Math.floor(d/65536),De=d-y*65536,d=$e+y+65535,y=Math.floor(d/65536),$e=d-y*65536,d=Ue+y+65535,y=Math.floor(d/65536),Ue=d-y*65536,d=Ae+y+65535,y=Math.floor(d/65536),Ae=d-y*65536,L+=y-1+37*(y-1),g[0]=L,g[1]=O,g[2]=J,g[3]=ae,g[4]=me,g[5]=he,g[6]=nt,g[7]=ge,g[8]=Te,g[9]=Le,g[10]=He,g[11]=Oe,g[12]=De,g[13]=$e,g[14]=Ue,g[15]=Ae}function je(g,A){ie(g,A,A)}function ft(g,A){var m=t(),d;for(d=0;d<16;d++)m[d]=A[d];for(d=253;d>=0;d--)je(m,m),d!==2&&d!==4&&ie(m,m,A);for(d=0;d<16;d++)g[d]=m[d]}function nn(g,A){var m=t(),d;for(d=0;d<16;d++)m[d]=A[d];for(d=250;d>=0;d--)je(m,m),d!==1&&ie(m,m,A);for(d=0;d<16;d++)g[d]=m[d]}function mr(g,A,m){var d=new Uint8Array(32),y=new Float64Array(80),L,O,J=t(),ae=t(),me=t(),he=t(),nt=t(),ge=t();for(O=0;O<31;O++)d[O]=A[O];for(d[31]=A[31]&127|64,d[0]&=248,q(y,m),O=0;O<16;O++)ae[O]=y[O],he[O]=J[O]=me[O]=0;for(J[0]=he[0]=1,O=254;O>=0;--O)L=d[O>>>3]>>>(O&7)&1,ce(J,ae,L),ce(me,he,L),ee(nt,J,me),fe(J,J,me),ee(me,ae,he),fe(ae,ae,he),je(he,nt),je(ge,J),ie(J,me,J),ie(me,ae,nt),ee(nt,J,me),fe(J,J,me),je(ae,J),fe(me,he,ge),ie(J,me,a),ee(J,J,he),ie(me,me,J),ie(J,he,ge),ie(he,ae,y),je(ae,nt),ce(J,ae,L),ce(me,he,L);for(O=0;O<16;O++)y[O+16]=J[O],y[O+32]=me[O],y[O+48]=ae[O],y[O+64]=he[O];var Te=y.subarray(32),Le=y.subarray(16);return ft(Te,Te),ie(Le,Le,Te),$(g,Le),0}function Ar(g,A){return mr(g,A,s)}function Nn(g,A){return e(A,32),Ar(g,A)}function Er(g,A,m){var d=new Uint8Array(32);return mr(d,m,A),C(g,r,d,F)}var ni=ne,Yi=z;function ri(g,A,m,d,y,L){var O=new Uint8Array(32);return Er(O,y,L),ni(g,A,m,d,O)}function yr(g,A,m,d,y,L){var O=new Uint8Array(32);return Er(O,y,L),Yi(g,A,m,d,O)}var _r=[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 j(g,A,m,d){for(var y=new Int32Array(16),L=new Int32Array(16),O,J,ae,me,he,nt,ge,Te,Le,He,Oe,De,$e,Ue,Ae,be,pe,Ee,ye,de,Q,W,re,X,Z,oe,Ce=g[0],Qe=g[1],qe=g[2],We=g[3],w=g[4],Ve=g[5],rt=g[6],it=g[7],Ke=A[0],Ze=A[1],et=A[2],kt=A[3],lt=A[4],It=A[5],Ct=A[6],vt=A[7],Dt=0;d>=128;){for(ye=0;ye<16;ye++)de=8*ye+Dt,y[ye]=m[de+0]<<24|m[de+1]<<16|m[de+2]<<8|m[de+3],L[ye]=m[de+4]<<24|m[de+5]<<16|m[de+6]<<8|m[de+7];for(ye=0;ye<80;ye++)if(O=Ce,J=Qe,ae=qe,me=We,he=w,nt=Ve,ge=rt,Te=it,Le=Ke,He=Ze,Oe=et,De=kt,$e=lt,Ue=It,Ae=Ct,be=vt,Q=it,W=vt,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=(w>>>14|lt<<18)^(w>>>18|lt<<14)^(lt>>>9|w<<23),W=(lt>>>14|w<<18)^(lt>>>18|w<<14)^(w>>>9|lt<<23),re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=w&Ve^~w&rt,W=lt&It^~lt&Ct,re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=_r[ye*2],W=_r[ye*2+1],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=y[ye%16],W=L[ye%16],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,pe=Z&65535|oe<<16,Ee=re&65535|X<<16,Q=pe,W=Ee,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=(Ce>>>28|Ke<<4)^(Ke>>>2|Ce<<30)^(Ke>>>7|Ce<<25),W=(Ke>>>28|Ce<<4)^(Ce>>>2|Ke<<30)^(Ce>>>7|Ke<<25),re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=Ce&Qe^Ce&qe^Qe&qe,W=Ke&Ze^Ke&et^Ze&et,re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,Te=Z&65535|oe<<16,be=re&65535|X<<16,Q=me,W=De,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=pe,W=Ee,re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,me=Z&65535|oe<<16,De=re&65535|X<<16,Qe=O,qe=J,We=ae,w=me,Ve=he,rt=nt,it=ge,Ce=Te,Ze=Le,et=He,kt=Oe,lt=De,It=$e,Ct=Ue,vt=Ae,Ke=be,ye%16===15)for(de=0;de<16;de++)Q=y[de],W=L[de],re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=y[(de+9)%16],W=L[(de+9)%16],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,pe=y[(de+1)%16],Ee=L[(de+1)%16],Q=(pe>>>1|Ee<<31)^(pe>>>8|Ee<<24)^pe>>>7,W=(Ee>>>1|pe<<31)^(Ee>>>8|pe<<24)^(Ee>>>7|pe<<25),re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,pe=y[(de+14)%16],Ee=L[(de+14)%16],Q=(pe>>>19|Ee<<13)^(Ee>>>29|pe<<3)^pe>>>6,W=(Ee>>>19|pe<<13)^(pe>>>29|Ee<<3)^(Ee>>>6|pe<<26),re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,y[de]=Z&65535|oe<<16,L[de]=re&65535|X<<16;Q=Ce,W=Ke,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=g[0],W=A[0],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[0]=Ce=Z&65535|oe<<16,A[0]=Ke=re&65535|X<<16,Q=Qe,W=Ze,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=g[1],W=A[1],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[1]=Qe=Z&65535|oe<<16,A[1]=Ze=re&65535|X<<16,Q=qe,W=et,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=g[2],W=A[2],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[2]=qe=Z&65535|oe<<16,A[2]=et=re&65535|X<<16,Q=We,W=kt,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=g[3],W=A[3],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[3]=We=Z&65535|oe<<16,A[3]=kt=re&65535|X<<16,Q=w,W=lt,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=g[4],W=A[4],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[4]=w=Z&65535|oe<<16,A[4]=lt=re&65535|X<<16,Q=Ve,W=It,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=g[5],W=A[5],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[5]=Ve=Z&65535|oe<<16,A[5]=It=re&65535|X<<16,Q=rt,W=Ct,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=g[6],W=A[6],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[6]=rt=Z&65535|oe<<16,A[6]=Ct=re&65535|X<<16,Q=it,W=vt,re=W&65535,X=W>>>16,Z=Q&65535,oe=Q>>>16,Q=g[7],W=A[7],re+=W&65535,X+=W>>>16,Z+=Q&65535,oe+=Q>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[7]=it=Z&65535|oe<<16,A[7]=vt=re&65535|X<<16,Dt+=128,d-=128}return d}function ue(g,A,m){var d=new Int32Array(8),y=new Int32Array(8),L=new Uint8Array(256),O,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,y[0]=4089235720,y[1]=2227873595,y[2]=4271175723,y[3]=1595750129,y[4]=2917565137,y[5]=725511199,y[6]=4215389547,y[7]=327033209,j(d,y,A,m),m%=128,O=0;O<m;O++)L[O]=A[J-m+O];for(L[m]=128,m=256-128*(m<112?1:0),L[m-9]=0,p(L,m-8,J/536870912|0,J<<3),j(d,y,L,m),O=0;O<8;O++)p(g,8*O,d[O],y[O]);return 0}function xe(g,A){var m=t(),d=t(),y=t(),L=t(),O=t(),J=t(),ae=t(),me=t(),he=t();fe(m,g[1],g[0]),fe(he,A[1],A[0]),ie(m,m,he),ee(d,g[0],g[1]),ee(he,A[0],A[1]),ie(d,d,he),ie(y,g[3],A[3]),ie(y,y,f),ie(L,g[2],A[2]),ee(L,L,L),fe(O,d,m),fe(J,L,y),ee(ae,L,y),ee(me,d,m),ie(g[0],O,J),ie(g[1],me,ae),ie(g[2],ae,J),ie(g[3],O,me)}function Pe(g,A,m){var d;for(d=0;d<4;d++)ce(g[d],A[d],m)}function Xe(g,A){var m=t(),d=t(),y=t();ft(y,A[2]),ie(m,A[0],y),ie(d,A[1],y),$(g,d),g[31]^=T(m)<<7}function Pt(g,A,m){var d,y;for(Y(g[0],i),Y(g[1],o),Y(g[2],o),Y(g[3],i),y=255;y>=0;--y)d=m[y/8|0]>>(y&7)&1,Pe(g,A,d),xe(A,g),xe(g,g),Pe(g,A,d)}function _n(g,A){var m=[t(),t(),t(),t()];Y(m[0],l),Y(m[1],u),Y(m[2],o),ie(m[3],l,u),Pt(g,m,A)}function rn(g,A,m){var d=new Uint8Array(64),y=[t(),t(),t(),t()],L;for(m||e(A,32),ue(d,A,32),d[0]&=248,d[31]&=127,d[31]|=64,_n(y,d),Xe(g,y),L=0;L<32;L++)A[L+32]=g[L];return 0}var br=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 at(g,A){var m,d,y,L;for(d=63;d>=32;--d){for(m=0,y=d-32,L=d-12;y<L;++y)A[y]+=m-16*A[d]*br[y-(d-32)],m=A[y]+128>>8,A[y]-=m*256;A[y]+=m,A[d]=0}for(m=0,y=0;y<32;y++)A[y]+=m-(A[31]>>4)*br[y],m=A[y]>>8,A[y]&=255;for(y=0;y<32;y++)A[y]-=m*br[y];for(d=0;d<32;d++)A[d+1]+=A[d]>>8,g[d]=A[d]&255}function Ut(g){var A=new Float64Array(64),m;for(m=0;m<64;m++)A[m]=g[m];for(m=0;m<64;m++)g[m]=0;at(g,A)}function Lt(g,A,m,d){var y=new Uint8Array(64),L=new Uint8Array(64),O=new Uint8Array(64),J,ae,me=new Float64Array(64),he=[t(),t(),t(),t()];ue(y,d,32),y[0]&=248,y[31]&=127,y[31]|=64;var nt=m+64;for(J=0;J<m;J++)g[64+J]=A[J];for(J=0;J<32;J++)g[32+J]=y[32+J];for(ue(O,g.subarray(32),m+32),Ut(O),_n(he,O),Xe(g,he),J=32;J<64;J++)g[J]=d[J];for(ue(L,g,m+64),Ut(L),J=0;J<64;J++)me[J]=0;for(J=0;J<32;J++)me[J]=O[J];for(J=0;J<32;J++)for(ae=0;ae<32;ae++)me[J+ae]+=L[J]*y[ae];return at(g.subarray(32),me),nt}function St(g,A){var m=t(),d=t(),y=t(),L=t(),O=t(),J=t(),ae=t();return Y(g[2],o),q(g[1],A),je(y,g[1]),ie(L,y,c),fe(y,y,g[2]),ee(L,g[2],L),je(O,L),je(J,O),ie(ae,J,O),ie(m,ae,y),ie(m,m,L),nn(m,m),ie(m,m,y),ie(m,m,L),ie(m,m,L),ie(g[0],m,L),je(d,g[0]),ie(d,d,L),B(d,y)&&ie(g[0],g[0],h),je(d,g[0]),ie(d,d,L),B(d,y)?-1:(T(g[0])===A[31]>>7&&fe(g[0],i,g[0]),ie(g[3],g[0],g[1]),0)}function ht(g,A,m,d){var y,L,O=new Uint8Array(32),J=new Uint8Array(64),ae=[t(),t(),t(),t()],me=[t(),t(),t(),t()];if(L=-1,m<64||St(me,d))return-1;for(y=0;y<m;y++)g[y]=A[y];for(y=0;y<32;y++)g[y+32]=d[y];if(ue(J,g,m),Ut(J),Pt(ae,me,J),_n(me,A.subarray(32)),xe(ae,me),Xe(O,ae),m-=64,b(A,0,O,0)){for(y=0;y<m;y++)g[y]=0;return-1}for(y=0;y<m;y++)g[y]=A[y+64];return L=m,L}var fn=32,wt=24,ir=32,xr=16,ii=32,ji=32,si=32,oi=32,fo=32,Bc=wt,np=ir,rp=xr,Pn=64,sr=32,Sr=64,lo=32,uo=64;n.lowlevel={crypto_core_hsalsa20:C,crypto_stream_xor:S,crypto_stream:x,crypto_stream_salsa20_xor:V,crypto_stream_salsa20:N,crypto_onetimeauth:k,crypto_onetimeauth_verify:R,crypto_verify_16:E,crypto_verify_32:b,crypto_secretbox:ne,crypto_secretbox_open:z,crypto_scalarmult:mr,crypto_scalarmult_base:Ar,crypto_box_beforenm:Er,crypto_box_afternm:ni,crypto_box:ri,crypto_box_open:yr,crypto_box_keypair:Nn,crypto_hash:ue,crypto_sign:Lt,crypto_sign_keypair:rn,crypto_sign_open:ht,crypto_secretbox_KEYBYTES:fn,crypto_secretbox_NONCEBYTES:wt,crypto_secretbox_ZEROBYTES:ir,crypto_secretbox_BOXZEROBYTES:xr,crypto_scalarmult_BYTES:ii,crypto_scalarmult_SCALARBYTES:ji,crypto_box_PUBLICKEYBYTES:si,crypto_box_SECRETKEYBYTES:oi,crypto_box_BEFORENMBYTES:fo,crypto_box_NONCEBYTES:Bc,crypto_box_ZEROBYTES:np,crypto_box_BOXZEROBYTES:rp,crypto_sign_BYTES:Pn,crypto_sign_PUBLICKEYBYTES:sr,crypto_sign_SECRETKEYBYTES:Sr,crypto_sign_SEEDBYTES:lo,crypto_hash_BYTES:uo};function Rc(g,A){if(g.length!==fn)throw new Error("bad key size");if(A.length!==wt)throw new Error("bad nonce size")}function ip(g,A){if(g.length!==si)throw new Error("bad public key size");if(A.length!==oi)throw new Error("bad secret key size")}function sn(){var g,A;for(A=0;A<arguments.length;A++)if((g=Object.prototype.toString.call(arguments[A]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+g+", use Uint8Array")}function Nc(g){for(var A=0;A<g.length;A++)g[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(g){var A=new Uint8Array(g);return e(A,g),A},n.secretbox=function(g,A,m){sn(g,A,m),Rc(m,A);for(var d=new Uint8Array(ir+g.length),y=new Uint8Array(d.length),L=0;L<g.length;L++)d[L+ir]=g[L];return ne(y,d,d.length,A,m),y.subarray(xr)},n.secretbox.open=function(g,A,m){sn(g,A,m),Rc(m,A);for(var d=new Uint8Array(xr+g.length),y=new Uint8Array(d.length),L=0;L<g.length;L++)d[L+xr]=g[L];return d.length<32||z(y,d,d.length,A,m)!==0?!1:y.subarray(ir)},n.secretbox.keyLength=fn,n.secretbox.nonceLength=wt,n.secretbox.overheadLength=xr,n.scalarMult=function(g,A){if(sn(g,A),g.length!==ji)throw new Error("bad n size");if(A.length!==ii)throw new Error("bad p size");var m=new Uint8Array(ii);return mr(m,g,A),m},n.scalarMult.base=function(g){if(sn(g),g.length!==ji)throw new Error("bad n size");var A=new Uint8Array(ii);return Ar(A,g),A},n.scalarMult.scalarLength=ji,n.scalarMult.groupElementLength=ii,n.box=function(g,A,m,d){var y=n.box.before(m,d);return n.secretbox(g,A,y)},n.box.before=function(g,A){sn(g,A),ip(g,A);var m=new Uint8Array(fo);return Er(m,g,A),m},n.box.after=n.secretbox,n.box.open=function(g,A,m,d){var y=n.box.before(m,d);return n.secretbox.open(g,A,y)},n.box.open.after=n.secretbox.open,n.box.keyPair=function(){var g=new Uint8Array(si),A=new Uint8Array(oi);return Nn(g,A),{publicKey:g,secretKey:A}},n.box.keyPair.fromSecretKey=function(g){if(sn(g),g.length!==oi)throw new Error("bad secret key size");var A=new Uint8Array(si);return Ar(A,g),{publicKey:A,secretKey:new Uint8Array(g)}},n.box.publicKeyLength=si,n.box.secretKeyLength=oi,n.box.sharedKeyLength=fo,n.box.nonceLength=Bc,n.box.overheadLength=n.secretbox.overheadLength,n.sign=function(g,A){if(sn(g,A),A.length!==Sr)throw new Error("bad secret key size");var m=new Uint8Array(Pn+g.length);return Lt(m,g,g.length,A),m},n.sign.open=function(g,A){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(sn(g,A),A.length!==sr)throw new Error("bad public key size");var m=new Uint8Array(g.length),d=ht(m,g,g.length,A);if(d<0)return null;for(var y=new Uint8Array(d),L=0;L<y.length;L++)y[L]=m[L];return y},n.sign.detached=function(g,A){for(var m=n.sign(g,A),d=new Uint8Array(Pn),y=0;y<d.length;y++)d[y]=m[y];return d},n.sign.detached.verify=function(g,A,m){if(sn(g,A,m),A.length!==Pn)throw new Error("bad signature size");if(m.length!==sr)throw new Error("bad public key size");var d=new Uint8Array(Pn+g.length),y=new Uint8Array(Pn+g.length),L;for(L=0;L<Pn;L++)d[L]=A[L];for(L=0;L<g.length;L++)d[L+Pn]=g[L];return ht(y,d,d.length,m)>=0},n.sign.keyPair=function(){var g=new Uint8Array(sr),A=new Uint8Array(Sr);return rn(g,A),{publicKey:g,secretKey:A}},n.sign.keyPair.fromSecretKey=function(g){if(sn(g),g.length!==Sr)throw new Error("bad secret key size");for(var A=new Uint8Array(sr),m=0;m<A.length;m++)A[m]=g[32+m];return{publicKey:A,secretKey:new Uint8Array(g)}},n.sign.keyPair.fromSeed=function(g){if(sn(g),g.length!==lo)throw new Error("bad seed size");for(var A=new Uint8Array(sr),m=new Uint8Array(Sr),d=0;d<32;d++)m[d]=g[d];return rn(A,m,!0),{publicKey:A,secretKey:m}},n.sign.publicKeyLength=sr,n.sign.secretKeyLength=Sr,n.sign.seedLength=lo,n.sign.signatureLength=Pn,n.hash=function(g){sn(g);var A=new Uint8Array(uo);return ue(A,g,g.length),A},n.hash.hashLength=uo,n.verify=function(g,A){return sn(g,A),g.length===0||A.length===0||g.length!==A.length?!1:_(g,0,A,0,g.length)===0},n.setPRNG=function(g){e=g},(function(){var g=typeof self<"u"?self.crypto||self.msCrypto:null;if(g&&g.getRandomValues){var A=65536;n.setPRNG(function(m,d){var y,L=new Uint8Array(d);for(y=0;y<d;y+=A)g.getRandomValues(L.subarray(y,y+Math.min(d-y,A)));for(y=0;y<d;y++)m[y]=L[y];Nc(L)})}else typeof require<"u"&&(g=require("crypto"),g&&g.randomBytes&&n.setPRNG(function(m,d){var y,L=g.randomBytes(d);for(y=0;y<d;y++)m[y]=L[y];Nc(L)}))})()})(typeof Es<"u"&&Es.exports?Es.exports:self.nacl=self.nacl||{})});var Po=ct((Ox,ru)=>{"use strict";var Bo=nu().lowlevel.crypto_hash,Un=0,lr=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 _s(n,t,e){return(n[0][t[e+3]]+n[1][t[e+2]]^n[2][t[e+1]])+n[3][t[e]]}lr.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]^=_s(this.S,t,0)^this.P[e],n[0]^=_s(this.S,t,4)^this.P[e+1];var r=n[0];n[0]=n[1]^this.P[17],n[1]=r};lr.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]^=_s(this.S,t,0)^this.P[e],n[0]^=_s(this.S,t,4)^this.P[e-1];var r=n[0];n[0]=n[1]^this.P[0],n[1]=r};function fr(n,t){var e,r=0;for(e=0;e<4;e++,Un++)Un>=t&&(Un=0),r=r<<8|n[Un];return r}lr.prototype.expand0state=function(n,t){var e=new Uint32Array(2),r,s,i=new Uint8Array(e.buffer);for(r=0,Un=0;r<18;r++)this.P[r]^=fr(n,t);for(Un=0,r=0;r<18;r+=2)this.encipher(e,i),this.P[r]=e[0],this.P[r+1]=e[1];for(r=0;r<4;r++)for(s=0;s<256;s+=2)this.encipher(e,i),this.S[r][s]=e[0],this.S[r][s+1]=e[1]};lr.prototype.expandstate=function(n,t,e,r){var s=new Uint32Array(2),i,o;for(i=0,Un=0;i<18;i++)this.P[i]^=fr(e,r);for(i=0,Un=0;i<18;i+=2)s[0]^=fr(n,t),s[1]^=fr(n,t),this.encipher(s),this.P[i]=s[0],this.P[i+1]=s[1];for(i=0;i<4;i++)for(o=0;o<256;o+=2)s[0]^=fr(n,t),s[1]^=fr(n,t),this.encipher(s),this.S[i][o]=s[0],this.S[i][o+1]=s[1];Un=0};lr.prototype.enc=function(n,t){for(var e=0;e<t;e++)this.encipher(n.subarray(e*2))};lr.prototype.dec=function(n,t){for(var e=0;e<t;e++)this.decipher(n.subarray(e*2))};var ys=8,Ro=32;function No(n,t,e){var r=new lr,s=new Uint32Array(ys),i,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),i=0;i<64;i++)r.expand0state(t,64),r.expand0state(n,64);for(i=0;i<ys;i++)s[i]=fr(o,o.byteLength);for(i=0;i<64;i++)r.enc(s,s.byteLength/8);for(i=0;i<ys;i++)e[4*i+3]=s[i]>>>24,e[4*i+2]=s[i]>>>16,e[4*i+1]=s[i]>>>8,e[4*i+0]=s[i]}function Eg(n,t,e,r,s,i,o){var a=new Uint8Array(64),c=new Uint8Array(64),f=new Uint8Array(Ro),l=new Uint8Array(Ro),u=new Uint8Array(r+4),h,p,_,E,b,v,U=i;if(o<1||t===0||r===0||i===0||i>f.byteLength*f.byteLength||r>1<<20)return-1;for(E=Math.floor((i+f.byteLength-1)/f.byteLength),_=Math.floor((i+E-1)/E),h=0;h<r;h++)u[h]=e[h];for(Bo(a,n,t),v=1;i>0;v++){for(u[r+0]=v>>>24,u[r+1]=v>>>16,u[r+2]=v>>>8,u[r+3]=v,Bo(c,u,r+4),No(a,c,l),h=f.byteLength;h--;)f[h]=l[h];for(h=1;h<o;h++)for(Bo(c,l,l.byteLength),No(a,c,l),p=0;p<f.byteLength;p++)f[p]^=l[p];for(_=Math.min(_,i),h=0;h<_&&(b=h*E+(v-1),!(b>=U));h++)s[b]=f[h];i-=h}return 0}ru.exports={BLOCKS:ys,HASHSIZE:Ro,hash:No,pbkdf:Eg}});var Mn=ct((Fx,xs)=>{"use strict";var $n=require("crypto"),Tr;try{Tr=require("cpu-features")()}catch{}var{bindingAvailable:iu,CIPHER_INFO:yg,MAC_INFO:_g}=Gn(),su=(()=>{if(typeof $n.sign=="function"&&typeof $n.verify=="function"){let n=`-----BEGIN PRIVATE KEY-----\r
1
+ "use strict";var dp=Object.create;var Oc=Object.defineProperty;var hp=Object.getOwnPropertyDescriptor;var pp=Object.getOwnPropertyNames;var gp=Object.getPrototypeOf,mp=Object.prototype.hasOwnProperty;var lt=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var Ap=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of pp(t))!mp.call(n,s)&&s!==e&&Oc(n,s,{get:()=>t[s],enumerable:!(r=hp(t,s))||r.enumerable});return n};var zt=(n,t,e)=>(e=n!=null?dp(gp(n)):{},Ap(t||!n||!n.__esModule?Oc(e,"default",{value:n,enumerable:!0}):e,n));var gs=lt((ex,Zf)=>{Zf.exports={newInvalidAsn1Error:function(n){var t=new Error;return t.name="InvalidAsn1Error",t.message=n||"",t}}});var ms=lt((tx,eu)=>{eu.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 Po=lt((nx,tu)=>{"use strict";var As=require("buffer"),Tr=As.Buffer,pn={},gn;for(gn in As)As.hasOwnProperty(gn)&&(gn==="SlowBuffer"||gn==="Buffer"||(pn[gn]=As[gn]));var Lr=pn.Buffer={};for(gn in Tr)Tr.hasOwnProperty(gn)&&(gn==="allocUnsafe"||gn==="allocUnsafeSlow"||(Lr[gn]=Tr[gn]));pn.Buffer.prototype=Tr.prototype;(!Lr.from||Lr.from===Uint8Array.from)&&(Lr.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 Tr(n,t,e)});Lr.alloc||(Lr.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=Tr(n);return!t||t.length===0?r.fill(0):typeof e=="string"?r.fill(t,e):r.fill(t),r});if(!pn.kStringMaxLength)try{pn.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}pn.constants||(pn.constants={MAX_LENGTH:pn.kMaxLength},pn.kStringMaxLength&&(pn.constants.MAX_STRING_LENGTH=pn.kStringMaxLength));tu.exports=pn});var iu=lt((rx,ru)=>{var Rg=require("assert"),nu=Po().Buffer,Ai=ms(),Ng=gs(),$r=Ng.newInvalidAsn1Error;function Jt(n){if(!n||!nu.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(Jt.prototype,"length",{enumerable:!0,get:function(){return this._len}});Object.defineProperty(Jt.prototype,"offset",{enumerable:!0,get:function(){return this._offset}});Object.defineProperty(Jt.prototype,"remain",{get:function(){return this._size-this._offset}});Object.defineProperty(Jt.prototype,"buffer",{get:function(){return this._buf.slice(this._offset)}});Jt.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};Jt.prototype.peek=function(){return this.readByte(!0)};Jt.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 $r("Indefinite length not supported");if(t>4)throw $r("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};Jt.prototype.readSequence=function(n){var t=this.peek();if(t===null)return null;if(n!==void 0&&n!==t)throw $r("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)};Jt.prototype.readInt=function(){return this._readTag(Ai.Integer)};Jt.prototype.readBoolean=function(){return this._readTag(Ai.Boolean)!==0};Jt.prototype.readEnumeration=function(){return this._readTag(Ai.Enumeration)};Jt.prototype.readString=function(n,t){n||(n=Ai.OctetString);var e=this.peek();if(e===null)return null;if(e!==n)throw $r("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?nu.alloc(0):"";var s=this._buf.slice(this._offset,this._offset+this.length);return this._offset+=this.length,t?s:s.toString("utf8")};Jt.prototype.readOID=function(n){n||(n=Ai.OID);var t=this.readString(n,!0);if(t===null)return null;for(var e=[],r=0,s=0;s<t.length;s++){var i=t[s]&255;r<<=7,r+=i&127,(i&128)===0&&(e.push(r),r=0)}return r=e.shift(),e.unshift(r%40),e.unshift(r/40>>0),e.join(".")};Jt.prototype._readTag=function(n){Rg.ok(n!==void 0);var t=this.peek();if(t===null)return null;if(t!==n)throw $r("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 $r("Integer too long: "+this.length);if(this.length>this._size-e)return null;this._offset=e;for(var r=this._buf[this._offset],s=0,i=0;i<this.length;i++)s<<=8,s|=this._buf[this._offset++]&255;return(r&128)===128&&i!==4&&(s-=1<<i*8),s>>0};ru.exports=Jt});var ou=lt((ix,su)=>{var Gn=require("assert"),ys=Po().Buffer,Yn=ms(),Pg=gs(),Es=Pg.newInvalidAsn1Error,Tg={size:1024,growthFactor:8};function Lg(n,t){Gn.ok(n),Gn.equal(typeof n,"object"),Gn.ok(t),Gn.equal(typeof t,"object");var e=Object.getOwnPropertyNames(n);return e.forEach(function(r){if(!t[r]){var s=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(t,r,s)}}),t}function Gt(n){n=Lg(Tg,n||{}),this._buf=ys.alloc(n.size||1024),this._size=this._buf.length,this._offset=0,this._options=n,this._seq=[]}Object.defineProperty(Gt.prototype,"buffer",{get:function(){if(this._seq.length)throw Es(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});Gt.prototype.writeByte=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=n};Gt.prototype.writeInt=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Yn.Integer);for(var e=4;((n&4286578688)===0||(n&4286578688)===-8388608)&&e>1;)e--,n<<=8;if(e>4)throw Es("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};Gt.prototype.writeNull=function(){this.writeByte(Yn.Null),this.writeByte(0)};Gt.prototype.writeEnumeration=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Yn.Enumeration),this.writeInt(n,t)};Gt.prototype.writeBoolean=function(n,t){if(typeof n!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Yn.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=n?255:0};Gt.prototype.writeString=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string (was: "+typeof n+")");typeof t!="number"&&(t=Yn.OctetString);var e=ys.byteLength(n);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(n,this._offset),this._offset+=e)};Gt.prototype.writeBuffer=function(n,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!ys.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};Gt.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)})};Gt.prototype.writeOID=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Yn.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("."),s=[];s.push(parseInt(r[0],10)*40+parseInt(r[1],10)),r.slice(2).forEach(function(o){e(s,parseInt(o,10))});var i=this;this._ensure(2+s.length),this.writeByte(t),this.writeLength(s.length),s.forEach(function(o){i.writeByte(o)})};Gt.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 Es("Length too long (> 4 bytes)")};Gt.prototype.startSequence=function(n){typeof n!="number"&&(n=Yn.Sequence|Yn.Constructor),this.writeByte(n),this._seq.push(this._offset),this._ensure(3),this._offset+=3};Gt.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 Es("Sequence too long")};Gt.prototype._shift=function(n,t,e){Gn.ok(n!==void 0),Gn.ok(t!==void 0),Gn.ok(e),this._buf.copy(this._buf,n+e,n,n+t),this._offset+=e};Gt.prototype._ensure=function(n){if(Gn.ok(n),this._size-this._offset<n){var t=this._size*this._options.growthFactor;t-this._offset<n&&(t+=n);var e=ys.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};su.exports=Gt});var au=lt((sx,Ss)=>{var To=gs(),Lo=ms(),$g=iu(),Dg=ou();Ss.exports={Reader:$g,Writer:Dg};for(_s in Lo)Lo.hasOwnProperty(_s)&&(Ss.exports[_s]=Lo[_s]);var _s;for(bs in To)To.hasOwnProperty(bs)&&(Ss.exports[bs]=To[bs]);var bs});var yi=lt((ox,cu)=>{var $o=au();cu.exports={Ber:$o,BerReader:$o.Reader,BerWriter:$o.Writer}});var lu=lt((ax,xs)=>{(function(n){"use strict";var t=function(g){var y,m=new Float64Array(16);if(g)for(y=0;y<g.length;y++)m[y]=g[y];return m},e=function(){throw new Error("no PRNG")},r=new Uint8Array(16),s=new Uint8Array(32);s[0]=9;var i=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]),l=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),f=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 p(g,y,m,d){g[y]=m>>24&255,g[y+1]=m>>16&255,g[y+2]=m>>8&255,g[y+3]=m&255,g[y+4]=d>>24&255,g[y+5]=d>>16&255,g[y+6]=d>>8&255,g[y+7]=d&255}function A(g,y,m,d,_){var $,F=0;for($=0;$<_;$++)F|=g[y+$]^m[d+$];return(1&F-1>>>8)-1}function E(g,y,m,d){return A(g,y,m,d,16)}function S(g,y,m,d){return A(g,y,m,d,32)}function x(g,y,m,d){for(var _=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,$=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,F=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,ae=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,ye=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,ge=y[0]&255|(y[1]&255)<<8|(y[2]&255)<<16|(y[3]&255)<<24,rt=y[4]&255|(y[5]&255)<<8|(y[6]&255)<<16|(y[7]&255)<<24,Ae=y[8]&255|(y[9]&255)<<8|(y[10]&255)<<16|(y[11]&255)<<24,Le=y[12]&255|(y[13]&255)<<8|(y[14]&255)<<16|(y[15]&255)<<24,$e=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Qe=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,Fe=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,De=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Me=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,Ue=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,Ee=_,Se=$,me=F,_e=J,be=ae,pe=ye,W=ge,q=rt,re=Ae,X=Le,Z=$e,oe=Qe,ke=Fe,We=De,Ke=Me,qe=Ue,I,ze=0;ze<20;ze+=2)I=Ee+ke|0,be^=I<<7|I>>>25,I=be+Ee|0,re^=I<<9|I>>>23,I=re+be|0,ke^=I<<13|I>>>19,I=ke+re|0,Ee^=I<<18|I>>>14,I=pe+Se|0,X^=I<<7|I>>>25,I=X+pe|0,We^=I<<9|I>>>23,I=We+X|0,Se^=I<<13|I>>>19,I=Se+We|0,pe^=I<<18|I>>>14,I=Z+W|0,Ke^=I<<7|I>>>25,I=Ke+Z|0,me^=I<<9|I>>>23,I=me+Ke|0,W^=I<<13|I>>>19,I=W+me|0,Z^=I<<18|I>>>14,I=qe+oe|0,_e^=I<<7|I>>>25,I=_e+qe|0,q^=I<<9|I>>>23,I=q+_e|0,oe^=I<<13|I>>>19,I=oe+q|0,qe^=I<<18|I>>>14,I=Ee+_e|0,Se^=I<<7|I>>>25,I=Se+Ee|0,me^=I<<9|I>>>23,I=me+Se|0,_e^=I<<13|I>>>19,I=_e+me|0,Ee^=I<<18|I>>>14,I=pe+be|0,W^=I<<7|I>>>25,I=W+pe|0,q^=I<<9|I>>>23,I=q+W|0,be^=I<<13|I>>>19,I=be+q|0,pe^=I<<18|I>>>14,I=Z+X|0,oe^=I<<7|I>>>25,I=oe+Z|0,re^=I<<9|I>>>23,I=re+oe|0,X^=I<<13|I>>>19,I=X+re|0,Z^=I<<18|I>>>14,I=qe+Ke|0,ke^=I<<7|I>>>25,I=ke+qe|0,We^=I<<9|I>>>23,I=We+ke|0,Ke^=I<<13|I>>>19,I=Ke+We|0,qe^=I<<18|I>>>14;Ee=Ee+_|0,Se=Se+$|0,me=me+F|0,_e=_e+J|0,be=be+ae|0,pe=pe+ye|0,W=W+ge|0,q=q+rt|0,re=re+Ae|0,X=X+Le|0,Z=Z+$e|0,oe=oe+Qe|0,ke=ke+Fe|0,We=We+De|0,Ke=Ke+Me|0,qe=qe+Ue|0,g[0]=Ee>>>0&255,g[1]=Ee>>>8&255,g[2]=Ee>>>16&255,g[3]=Ee>>>24&255,g[4]=Se>>>0&255,g[5]=Se>>>8&255,g[6]=Se>>>16&255,g[7]=Se>>>24&255,g[8]=me>>>0&255,g[9]=me>>>8&255,g[10]=me>>>16&255,g[11]=me>>>24&255,g[12]=_e>>>0&255,g[13]=_e>>>8&255,g[14]=_e>>>16&255,g[15]=_e>>>24&255,g[16]=be>>>0&255,g[17]=be>>>8&255,g[18]=be>>>16&255,g[19]=be>>>24&255,g[20]=pe>>>0&255,g[21]=pe>>>8&255,g[22]=pe>>>16&255,g[23]=pe>>>24&255,g[24]=W>>>0&255,g[25]=W>>>8&255,g[26]=W>>>16&255,g[27]=W>>>24&255,g[28]=q>>>0&255,g[29]=q>>>8&255,g[30]=q>>>16&255,g[31]=q>>>24&255,g[32]=re>>>0&255,g[33]=re>>>8&255,g[34]=re>>>16&255,g[35]=re>>>24&255,g[36]=X>>>0&255,g[37]=X>>>8&255,g[38]=X>>>16&255,g[39]=X>>>24&255,g[40]=Z>>>0&255,g[41]=Z>>>8&255,g[42]=Z>>>16&255,g[43]=Z>>>24&255,g[44]=oe>>>0&255,g[45]=oe>>>8&255,g[46]=oe>>>16&255,g[47]=oe>>>24&255,g[48]=ke>>>0&255,g[49]=ke>>>8&255,g[50]=ke>>>16&255,g[51]=ke>>>24&255,g[52]=We>>>0&255,g[53]=We>>>8&255,g[54]=We>>>16&255,g[55]=We>>>24&255,g[56]=Ke>>>0&255,g[57]=Ke>>>8&255,g[58]=Ke>>>16&255,g[59]=Ke>>>24&255,g[60]=qe>>>0&255,g[61]=qe>>>8&255,g[62]=qe>>>16&255,g[63]=qe>>>24&255}function R(g,y,m,d){for(var _=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,$=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,F=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,ae=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,ye=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,ge=y[0]&255|(y[1]&255)<<8|(y[2]&255)<<16|(y[3]&255)<<24,rt=y[4]&255|(y[5]&255)<<8|(y[6]&255)<<16|(y[7]&255)<<24,Ae=y[8]&255|(y[9]&255)<<8|(y[10]&255)<<16|(y[11]&255)<<24,Le=y[12]&255|(y[13]&255)<<8|(y[14]&255)<<16|(y[15]&255)<<24,$e=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Qe=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,Fe=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,De=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Me=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,Ue=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,Ee=_,Se=$,me=F,_e=J,be=ae,pe=ye,W=ge,q=rt,re=Ae,X=Le,Z=$e,oe=Qe,ke=Fe,We=De,Ke=Me,qe=Ue,I,ze=0;ze<20;ze+=2)I=Ee+ke|0,be^=I<<7|I>>>25,I=be+Ee|0,re^=I<<9|I>>>23,I=re+be|0,ke^=I<<13|I>>>19,I=ke+re|0,Ee^=I<<18|I>>>14,I=pe+Se|0,X^=I<<7|I>>>25,I=X+pe|0,We^=I<<9|I>>>23,I=We+X|0,Se^=I<<13|I>>>19,I=Se+We|0,pe^=I<<18|I>>>14,I=Z+W|0,Ke^=I<<7|I>>>25,I=Ke+Z|0,me^=I<<9|I>>>23,I=me+Ke|0,W^=I<<13|I>>>19,I=W+me|0,Z^=I<<18|I>>>14,I=qe+oe|0,_e^=I<<7|I>>>25,I=_e+qe|0,q^=I<<9|I>>>23,I=q+_e|0,oe^=I<<13|I>>>19,I=oe+q|0,qe^=I<<18|I>>>14,I=Ee+_e|0,Se^=I<<7|I>>>25,I=Se+Ee|0,me^=I<<9|I>>>23,I=me+Se|0,_e^=I<<13|I>>>19,I=_e+me|0,Ee^=I<<18|I>>>14,I=pe+be|0,W^=I<<7|I>>>25,I=W+pe|0,q^=I<<9|I>>>23,I=q+W|0,be^=I<<13|I>>>19,I=be+q|0,pe^=I<<18|I>>>14,I=Z+X|0,oe^=I<<7|I>>>25,I=oe+Z|0,re^=I<<9|I>>>23,I=re+oe|0,X^=I<<13|I>>>19,I=X+re|0,Z^=I<<18|I>>>14,I=qe+Ke|0,ke^=I<<7|I>>>25,I=ke+qe|0,We^=I<<9|I>>>23,I=We+ke|0,Ke^=I<<13|I>>>19,I=Ke+We|0,qe^=I<<18|I>>>14;g[0]=Ee>>>0&255,g[1]=Ee>>>8&255,g[2]=Ee>>>16&255,g[3]=Ee>>>24&255,g[4]=pe>>>0&255,g[5]=pe>>>8&255,g[6]=pe>>>16&255,g[7]=pe>>>24&255,g[8]=Z>>>0&255,g[9]=Z>>>8&255,g[10]=Z>>>16&255,g[11]=Z>>>24&255,g[12]=qe>>>0&255,g[13]=qe>>>8&255,g[14]=qe>>>16&255,g[15]=qe>>>24&255,g[16]=W>>>0&255,g[17]=W>>>8&255,g[18]=W>>>16&255,g[19]=W>>>24&255,g[20]=q>>>0&255,g[21]=q>>>8&255,g[22]=q>>>16&255,g[23]=q>>>24&255,g[24]=re>>>0&255,g[25]=re>>>8&255,g[26]=re>>>16&255,g[27]=re>>>24&255,g[28]=X>>>0&255,g[29]=X>>>8&255,g[30]=X>>>16&255,g[31]=X>>>24&255}function H(g,y,m,d){x(g,y,m,d)}function C(g,y,m,d){R(g,y,m,d)}var U=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function Q(g,y,m,d,_,$,F){var J=new Uint8Array(16),ae=new Uint8Array(64),ye,ge;for(ge=0;ge<16;ge++)J[ge]=0;for(ge=0;ge<8;ge++)J[ge]=$[ge];for(;_>=64;){for(H(ae,J,F,U),ge=0;ge<64;ge++)g[y+ge]=m[d+ge]^ae[ge];for(ye=1,ge=8;ge<16;ge++)ye=ye+(J[ge]&255)|0,J[ge]=ye&255,ye>>>=8;_-=64,y+=64,d+=64}if(_>0)for(H(ae,J,F,U),ge=0;ge<_;ge++)g[y+ge]=m[d+ge]^ae[ge];return 0}function B(g,y,m,d,_){var $=new Uint8Array(16),F=new Uint8Array(64),J,ae;for(ae=0;ae<16;ae++)$[ae]=0;for(ae=0;ae<8;ae++)$[ae]=d[ae];for(;m>=64;){for(H(F,$,_,U),ae=0;ae<64;ae++)g[y+ae]=F[ae];for(J=1,ae=8;ae<16;ae++)J=J+($[ae]&255)|0,$[ae]=J&255,J>>>=8;m-=64,y+=64}if(m>0)for(H(F,$,_,U),ae=0;ae<m;ae++)g[y+ae]=F[ae];return 0}function b(g,y,m,d,_){var $=new Uint8Array(32);C($,d,_,U);for(var F=new Uint8Array(8),J=0;J<8;J++)F[J]=d[J+16];return B(g,y,m,F,$)}function w(g,y,m,d,_,$,F){var J=new Uint8Array(32);C(J,$,F,U);for(var ae=new Uint8Array(8),ye=0;ye<8;ye++)ae[ye]=$[ye+16];return Q(g,y,m,d,_,ae,J)}var k=function(g){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 y,m,d,_,$,F,J,ae;y=g[0]&255|(g[1]&255)<<8,this.r[0]=y&8191,m=g[2]&255|(g[3]&255)<<8,this.r[1]=(y>>>13|m<<3)&8191,d=g[4]&255|(g[5]&255)<<8,this.r[2]=(m>>>10|d<<6)&7939,_=g[6]&255|(g[7]&255)<<8,this.r[3]=(d>>>7|_<<9)&8191,$=g[8]&255|(g[9]&255)<<8,this.r[4]=(_>>>4|$<<12)&255,this.r[5]=$>>>1&8190,F=g[10]&255|(g[11]&255)<<8,this.r[6]=($>>>14|F<<2)&8191,J=g[12]&255|(g[13]&255)<<8,this.r[7]=(F>>>11|J<<5)&8065,ae=g[14]&255|(g[15]&255)<<8,this.r[8]=(J>>>8|ae<<8)&8191,this.r[9]=ae>>>5&127,this.pad[0]=g[16]&255|(g[17]&255)<<8,this.pad[1]=g[18]&255|(g[19]&255)<<8,this.pad[2]=g[20]&255|(g[21]&255)<<8,this.pad[3]=g[22]&255|(g[23]&255)<<8,this.pad[4]=g[24]&255|(g[25]&255)<<8,this.pad[5]=g[26]&255|(g[27]&255)<<8,this.pad[6]=g[28]&255|(g[29]&255)<<8,this.pad[7]=g[30]&255|(g[31]&255)<<8};k.prototype.blocks=function(g,y,m){for(var d=this.fin?0:2048,_,$,F,J,ae,ye,ge,rt,Ae,Le,$e,Qe,Fe,De,Me,Ue,Ee,Se,me,_e=this.h[0],be=this.h[1],pe=this.h[2],W=this.h[3],q=this.h[4],re=this.h[5],X=this.h[6],Z=this.h[7],oe=this.h[8],ke=this.h[9],We=this.r[0],Ke=this.r[1],qe=this.r[2],I=this.r[3],ze=this.r[4],it=this.r[5],st=this.r[6],Ve=this.r[7],et=this.r[8],tt=this.r[9];m>=16;)_=g[y+0]&255|(g[y+1]&255)<<8,_e+=_&8191,$=g[y+2]&255|(g[y+3]&255)<<8,be+=(_>>>13|$<<3)&8191,F=g[y+4]&255|(g[y+5]&255)<<8,pe+=($>>>10|F<<6)&8191,J=g[y+6]&255|(g[y+7]&255)<<8,W+=(F>>>7|J<<9)&8191,ae=g[y+8]&255|(g[y+9]&255)<<8,q+=(J>>>4|ae<<12)&8191,re+=ae>>>1&8191,ye=g[y+10]&255|(g[y+11]&255)<<8,X+=(ae>>>14|ye<<2)&8191,ge=g[y+12]&255|(g[y+13]&255)<<8,Z+=(ye>>>11|ge<<5)&8191,rt=g[y+14]&255|(g[y+15]&255)<<8,oe+=(ge>>>8|rt<<8)&8191,ke+=rt>>>5|d,Ae=0,Le=Ae,Le+=_e*We,Le+=be*(5*tt),Le+=pe*(5*et),Le+=W*(5*Ve),Le+=q*(5*st),Ae=Le>>>13,Le&=8191,Le+=re*(5*it),Le+=X*(5*ze),Le+=Z*(5*I),Le+=oe*(5*qe),Le+=ke*(5*Ke),Ae+=Le>>>13,Le&=8191,$e=Ae,$e+=_e*Ke,$e+=be*We,$e+=pe*(5*tt),$e+=W*(5*et),$e+=q*(5*Ve),Ae=$e>>>13,$e&=8191,$e+=re*(5*st),$e+=X*(5*it),$e+=Z*(5*ze),$e+=oe*(5*I),$e+=ke*(5*qe),Ae+=$e>>>13,$e&=8191,Qe=Ae,Qe+=_e*qe,Qe+=be*Ke,Qe+=pe*We,Qe+=W*(5*tt),Qe+=q*(5*et),Ae=Qe>>>13,Qe&=8191,Qe+=re*(5*Ve),Qe+=X*(5*st),Qe+=Z*(5*it),Qe+=oe*(5*ze),Qe+=ke*(5*I),Ae+=Qe>>>13,Qe&=8191,Fe=Ae,Fe+=_e*I,Fe+=be*qe,Fe+=pe*Ke,Fe+=W*We,Fe+=q*(5*tt),Ae=Fe>>>13,Fe&=8191,Fe+=re*(5*et),Fe+=X*(5*Ve),Fe+=Z*(5*st),Fe+=oe*(5*it),Fe+=ke*(5*ze),Ae+=Fe>>>13,Fe&=8191,De=Ae,De+=_e*ze,De+=be*I,De+=pe*qe,De+=W*Ke,De+=q*We,Ae=De>>>13,De&=8191,De+=re*(5*tt),De+=X*(5*et),De+=Z*(5*Ve),De+=oe*(5*st),De+=ke*(5*it),Ae+=De>>>13,De&=8191,Me=Ae,Me+=_e*it,Me+=be*ze,Me+=pe*I,Me+=W*qe,Me+=q*Ke,Ae=Me>>>13,Me&=8191,Me+=re*We,Me+=X*(5*tt),Me+=Z*(5*et),Me+=oe*(5*Ve),Me+=ke*(5*st),Ae+=Me>>>13,Me&=8191,Ue=Ae,Ue+=_e*st,Ue+=be*it,Ue+=pe*ze,Ue+=W*I,Ue+=q*qe,Ae=Ue>>>13,Ue&=8191,Ue+=re*Ke,Ue+=X*We,Ue+=Z*(5*tt),Ue+=oe*(5*et),Ue+=ke*(5*Ve),Ae+=Ue>>>13,Ue&=8191,Ee=Ae,Ee+=_e*Ve,Ee+=be*st,Ee+=pe*it,Ee+=W*ze,Ee+=q*I,Ae=Ee>>>13,Ee&=8191,Ee+=re*qe,Ee+=X*Ke,Ee+=Z*We,Ee+=oe*(5*tt),Ee+=ke*(5*et),Ae+=Ee>>>13,Ee&=8191,Se=Ae,Se+=_e*et,Se+=be*Ve,Se+=pe*st,Se+=W*it,Se+=q*ze,Ae=Se>>>13,Se&=8191,Se+=re*I,Se+=X*qe,Se+=Z*Ke,Se+=oe*We,Se+=ke*(5*tt),Ae+=Se>>>13,Se&=8191,me=Ae,me+=_e*tt,me+=be*et,me+=pe*Ve,me+=W*st,me+=q*it,Ae=me>>>13,me&=8191,me+=re*ze,me+=X*I,me+=Z*qe,me+=oe*Ke,me+=ke*We,Ae+=me>>>13,me&=8191,Ae=(Ae<<2)+Ae|0,Ae=Ae+Le|0,Le=Ae&8191,Ae=Ae>>>13,$e+=Ae,_e=Le,be=$e,pe=Qe,W=Fe,q=De,re=Me,X=Ue,Z=Ee,oe=Se,ke=me,y+=16,m-=16;this.h[0]=_e,this.h[1]=be,this.h[2]=pe,this.h[3]=W,this.h[4]=q,this.h[5]=re,this.h[6]=X,this.h[7]=Z,this.h[8]=oe,this.h[9]=ke},k.prototype.finish=function(g,y){var m=new Uint16Array(10),d,_,$,F;if(this.leftover){for(F=this.leftover,this.buffer[F++]=1;F<16;F++)this.buffer[F]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(d=this.h[1]>>>13,this.h[1]&=8191,F=2;F<10;F++)this.h[F]+=d,d=this.h[F]>>>13,this.h[F]&=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,F=1;F<10;F++)m[F]=this.h[F]+d,d=m[F]>>>13,m[F]&=8191;for(m[9]-=8192,_=(d^1)-1,F=0;F<10;F++)m[F]&=_;for(_=~_,F=0;F<10;F++)this.h[F]=this.h[F]&_|m[F];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,$=this.h[0]+this.pad[0],this.h[0]=$&65535,F=1;F<8;F++)$=(this.h[F]+this.pad[F]|0)+($>>>16)|0,this.h[F]=$&65535;g[y+0]=this.h[0]>>>0&255,g[y+1]=this.h[0]>>>8&255,g[y+2]=this.h[1]>>>0&255,g[y+3]=this.h[1]>>>8&255,g[y+4]=this.h[2]>>>0&255,g[y+5]=this.h[2]>>>8&255,g[y+6]=this.h[3]>>>0&255,g[y+7]=this.h[3]>>>8&255,g[y+8]=this.h[4]>>>0&255,g[y+9]=this.h[4]>>>8&255,g[y+10]=this.h[5]>>>0&255,g[y+11]=this.h[5]>>>8&255,g[y+12]=this.h[6]>>>0&255,g[y+13]=this.h[6]>>>8&255,g[y+14]=this.h[7]>>>0&255,g[y+15]=this.h[7]>>>8&255},k.prototype.update=function(g,y,m){var d,_;if(this.leftover){for(_=16-this.leftover,_>m&&(_=m),d=0;d<_;d++)this.buffer[this.leftover+d]=g[y+d];if(m-=_,y+=_,this.leftover+=_,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(m>=16&&(_=m-m%16,this.blocks(g,y,_),y+=_,m-=_),m){for(d=0;d<m;d++)this.buffer[this.leftover+d]=g[y+d];this.leftover+=m}};function v(g,y,m,d,_,$){var F=new k($);return F.update(m,d,_),F.finish(g,y),0}function P(g,y,m,d,_,$){var F=new Uint8Array(16);return v(F,0,m,d,_,$),E(g,y,F,0)}function ne(g,y,m,d,_){var $;if(m<32)return-1;for(w(g,0,y,0,m,d,_),v(g,16,g,32,m-32,g),$=0;$<16;$++)g[$]=0;return 0}function G(g,y,m,d,_){var $,F=new Uint8Array(32);if(m<32||(b(F,0,32,d,_),P(y,16,y,32,m-32,F)!==0))return-1;for(w(g,0,y,0,m,d,_),$=0;$<32;$++)g[$]=0;return 0}function Y(g,y){var m;for(m=0;m<16;m++)g[m]=y[m]|0}function te(g){var y,m,d=1;for(y=0;y<16;y++)m=g[y]+d+65535,d=Math.floor(m/65536),g[y]=m-d*65536;g[0]+=d-1+37*(d-1)}function le(g,y,m){for(var d,_=~(m-1),$=0;$<16;$++)d=_&(g[$]^y[$]),g[$]^=d,y[$]^=d}function M(g,y){var m,d,_,$=t(),F=t();for(m=0;m<16;m++)F[m]=y[m];for(te(F),te(F),te(F),d=0;d<2;d++){for($[0]=F[0]-65517,m=1;m<15;m++)$[m]=F[m]-65535-($[m-1]>>16&1),$[m-1]&=65535;$[15]=F[15]-32767-($[14]>>16&1),_=$[15]>>16&1,$[14]&=65535,le(F,$,1-_)}for(m=0;m<16;m++)g[2*m]=F[m]&255,g[2*m+1]=F[m]>>8}function N(g,y){var m=new Uint8Array(32),d=new Uint8Array(32);return M(m,g),M(d,y),S(m,0,d,0)}function L(g){var y=new Uint8Array(32);return M(y,g),y[0]&1}function K(g,y){var m;for(m=0;m<16;m++)g[m]=y[2*m]+(y[2*m+1]<<8);g[15]&=32767}function ee(g,y,m){for(var d=0;d<16;d++)g[d]=y[d]+m[d]}function ue(g,y,m){for(var d=0;d<16;d++)g[d]=y[d]-m[d]}function ie(g,y,m){var d,_,$=0,F=0,J=0,ae=0,ye=0,ge=0,rt=0,Ae=0,Le=0,$e=0,Qe=0,Fe=0,De=0,Me=0,Ue=0,Ee=0,Se=0,me=0,_e=0,be=0,pe=0,W=0,q=0,re=0,X=0,Z=0,oe=0,ke=0,We=0,Ke=0,qe=0,I=m[0],ze=m[1],it=m[2],st=m[3],Ve=m[4],et=m[5],tt=m[6],Rt=m[7],ut=m[8],kt=m[9],vt=m[10],Bt=m[11],Ut=m[12],qt=m[13],Kt=m[14],Vt=m[15];d=y[0],$+=d*I,F+=d*ze,J+=d*it,ae+=d*st,ye+=d*Ve,ge+=d*et,rt+=d*tt,Ae+=d*Rt,Le+=d*ut,$e+=d*kt,Qe+=d*vt,Fe+=d*Bt,De+=d*Ut,Me+=d*qt,Ue+=d*Kt,Ee+=d*Vt,d=y[1],F+=d*I,J+=d*ze,ae+=d*it,ye+=d*st,ge+=d*Ve,rt+=d*et,Ae+=d*tt,Le+=d*Rt,$e+=d*ut,Qe+=d*kt,Fe+=d*vt,De+=d*Bt,Me+=d*Ut,Ue+=d*qt,Ee+=d*Kt,Se+=d*Vt,d=y[2],J+=d*I,ae+=d*ze,ye+=d*it,ge+=d*st,rt+=d*Ve,Ae+=d*et,Le+=d*tt,$e+=d*Rt,Qe+=d*ut,Fe+=d*kt,De+=d*vt,Me+=d*Bt,Ue+=d*Ut,Ee+=d*qt,Se+=d*Kt,me+=d*Vt,d=y[3],ae+=d*I,ye+=d*ze,ge+=d*it,rt+=d*st,Ae+=d*Ve,Le+=d*et,$e+=d*tt,Qe+=d*Rt,Fe+=d*ut,De+=d*kt,Me+=d*vt,Ue+=d*Bt,Ee+=d*Ut,Se+=d*qt,me+=d*Kt,_e+=d*Vt,d=y[4],ye+=d*I,ge+=d*ze,rt+=d*it,Ae+=d*st,Le+=d*Ve,$e+=d*et,Qe+=d*tt,Fe+=d*Rt,De+=d*ut,Me+=d*kt,Ue+=d*vt,Ee+=d*Bt,Se+=d*Ut,me+=d*qt,_e+=d*Kt,be+=d*Vt,d=y[5],ge+=d*I,rt+=d*ze,Ae+=d*it,Le+=d*st,$e+=d*Ve,Qe+=d*et,Fe+=d*tt,De+=d*Rt,Me+=d*ut,Ue+=d*kt,Ee+=d*vt,Se+=d*Bt,me+=d*Ut,_e+=d*qt,be+=d*Kt,pe+=d*Vt,d=y[6],rt+=d*I,Ae+=d*ze,Le+=d*it,$e+=d*st,Qe+=d*Ve,Fe+=d*et,De+=d*tt,Me+=d*Rt,Ue+=d*ut,Ee+=d*kt,Se+=d*vt,me+=d*Bt,_e+=d*Ut,be+=d*qt,pe+=d*Kt,W+=d*Vt,d=y[7],Ae+=d*I,Le+=d*ze,$e+=d*it,Qe+=d*st,Fe+=d*Ve,De+=d*et,Me+=d*tt,Ue+=d*Rt,Ee+=d*ut,Se+=d*kt,me+=d*vt,_e+=d*Bt,be+=d*Ut,pe+=d*qt,W+=d*Kt,q+=d*Vt,d=y[8],Le+=d*I,$e+=d*ze,Qe+=d*it,Fe+=d*st,De+=d*Ve,Me+=d*et,Ue+=d*tt,Ee+=d*Rt,Se+=d*ut,me+=d*kt,_e+=d*vt,be+=d*Bt,pe+=d*Ut,W+=d*qt,q+=d*Kt,re+=d*Vt,d=y[9],$e+=d*I,Qe+=d*ze,Fe+=d*it,De+=d*st,Me+=d*Ve,Ue+=d*et,Ee+=d*tt,Se+=d*Rt,me+=d*ut,_e+=d*kt,be+=d*vt,pe+=d*Bt,W+=d*Ut,q+=d*qt,re+=d*Kt,X+=d*Vt,d=y[10],Qe+=d*I,Fe+=d*ze,De+=d*it,Me+=d*st,Ue+=d*Ve,Ee+=d*et,Se+=d*tt,me+=d*Rt,_e+=d*ut,be+=d*kt,pe+=d*vt,W+=d*Bt,q+=d*Ut,re+=d*qt,X+=d*Kt,Z+=d*Vt,d=y[11],Fe+=d*I,De+=d*ze,Me+=d*it,Ue+=d*st,Ee+=d*Ve,Se+=d*et,me+=d*tt,_e+=d*Rt,be+=d*ut,pe+=d*kt,W+=d*vt,q+=d*Bt,re+=d*Ut,X+=d*qt,Z+=d*Kt,oe+=d*Vt,d=y[12],De+=d*I,Me+=d*ze,Ue+=d*it,Ee+=d*st,Se+=d*Ve,me+=d*et,_e+=d*tt,be+=d*Rt,pe+=d*ut,W+=d*kt,q+=d*vt,re+=d*Bt,X+=d*Ut,Z+=d*qt,oe+=d*Kt,ke+=d*Vt,d=y[13],Me+=d*I,Ue+=d*ze,Ee+=d*it,Se+=d*st,me+=d*Ve,_e+=d*et,be+=d*tt,pe+=d*Rt,W+=d*ut,q+=d*kt,re+=d*vt,X+=d*Bt,Z+=d*Ut,oe+=d*qt,ke+=d*Kt,We+=d*Vt,d=y[14],Ue+=d*I,Ee+=d*ze,Se+=d*it,me+=d*st,_e+=d*Ve,be+=d*et,pe+=d*tt,W+=d*Rt,q+=d*ut,re+=d*kt,X+=d*vt,Z+=d*Bt,oe+=d*Ut,ke+=d*qt,We+=d*Kt,Ke+=d*Vt,d=y[15],Ee+=d*I,Se+=d*ze,me+=d*it,_e+=d*st,be+=d*Ve,pe+=d*et,W+=d*tt,q+=d*Rt,re+=d*ut,X+=d*kt,Z+=d*vt,oe+=d*Bt,ke+=d*Ut,We+=d*qt,Ke+=d*Kt,qe+=d*Vt,$+=38*Se,F+=38*me,J+=38*_e,ae+=38*be,ye+=38*pe,ge+=38*W,rt+=38*q,Ae+=38*re,Le+=38*X,$e+=38*Z,Qe+=38*oe,Fe+=38*ke,De+=38*We,Me+=38*Ke,Ue+=38*qe,_=1,d=$+_+65535,_=Math.floor(d/65536),$=d-_*65536,d=F+_+65535,_=Math.floor(d/65536),F=d-_*65536,d=J+_+65535,_=Math.floor(d/65536),J=d-_*65536,d=ae+_+65535,_=Math.floor(d/65536),ae=d-_*65536,d=ye+_+65535,_=Math.floor(d/65536),ye=d-_*65536,d=ge+_+65535,_=Math.floor(d/65536),ge=d-_*65536,d=rt+_+65535,_=Math.floor(d/65536),rt=d-_*65536,d=Ae+_+65535,_=Math.floor(d/65536),Ae=d-_*65536,d=Le+_+65535,_=Math.floor(d/65536),Le=d-_*65536,d=$e+_+65535,_=Math.floor(d/65536),$e=d-_*65536,d=Qe+_+65535,_=Math.floor(d/65536),Qe=d-_*65536,d=Fe+_+65535,_=Math.floor(d/65536),Fe=d-_*65536,d=De+_+65535,_=Math.floor(d/65536),De=d-_*65536,d=Me+_+65535,_=Math.floor(d/65536),Me=d-_*65536,d=Ue+_+65535,_=Math.floor(d/65536),Ue=d-_*65536,d=Ee+_+65535,_=Math.floor(d/65536),Ee=d-_*65536,$+=_-1+37*(_-1),_=1,d=$+_+65535,_=Math.floor(d/65536),$=d-_*65536,d=F+_+65535,_=Math.floor(d/65536),F=d-_*65536,d=J+_+65535,_=Math.floor(d/65536),J=d-_*65536,d=ae+_+65535,_=Math.floor(d/65536),ae=d-_*65536,d=ye+_+65535,_=Math.floor(d/65536),ye=d-_*65536,d=ge+_+65535,_=Math.floor(d/65536),ge=d-_*65536,d=rt+_+65535,_=Math.floor(d/65536),rt=d-_*65536,d=Ae+_+65535,_=Math.floor(d/65536),Ae=d-_*65536,d=Le+_+65535,_=Math.floor(d/65536),Le=d-_*65536,d=$e+_+65535,_=Math.floor(d/65536),$e=d-_*65536,d=Qe+_+65535,_=Math.floor(d/65536),Qe=d-_*65536,d=Fe+_+65535,_=Math.floor(d/65536),Fe=d-_*65536,d=De+_+65535,_=Math.floor(d/65536),De=d-_*65536,d=Me+_+65535,_=Math.floor(d/65536),Me=d-_*65536,d=Ue+_+65535,_=Math.floor(d/65536),Ue=d-_*65536,d=Ee+_+65535,_=Math.floor(d/65536),Ee=d-_*65536,$+=_-1+37*(_-1),g[0]=$,g[1]=F,g[2]=J,g[3]=ae,g[4]=ye,g[5]=ge,g[6]=rt,g[7]=Ae,g[8]=Le,g[9]=$e,g[10]=Qe,g[11]=Fe,g[12]=De,g[13]=Me,g[14]=Ue,g[15]=Ee}function Xe(g,y){ie(g,y,y)}function ft(g,y){var m=t(),d;for(d=0;d<16;d++)m[d]=y[d];for(d=253;d>=0;d--)Xe(m,m),d!==2&&d!==4&&ie(m,m,y);for(d=0;d<16;d++)g[d]=m[d]}function on(g,y){var m=t(),d;for(d=0;d<16;d++)m[d]=y[d];for(d=250;d>=0;d--)Xe(m,m),d!==1&&ie(m,m,y);for(d=0;d<16;d++)g[d]=m[d]}function yr(g,y,m){var d=new Uint8Array(32),_=new Float64Array(80),$,F,J=t(),ae=t(),ye=t(),ge=t(),rt=t(),Ae=t();for(F=0;F<31;F++)d[F]=y[F];for(d[31]=y[31]&127|64,d[0]&=248,K(_,m),F=0;F<16;F++)ae[F]=_[F],ge[F]=J[F]=ye[F]=0;for(J[0]=ge[0]=1,F=254;F>=0;--F)$=d[F>>>3]>>>(F&7)&1,le(J,ae,$),le(ye,ge,$),ee(rt,J,ye),ue(J,J,ye),ee(ye,ae,ge),ue(ae,ae,ge),Xe(ge,rt),Xe(Ae,J),ie(J,ye,J),ie(ye,ae,rt),ee(rt,J,ye),ue(J,J,ye),Xe(ae,J),ue(ye,ge,Ae),ie(J,ye,a),ee(J,J,ge),ie(ye,ye,J),ie(J,ge,Ae),ie(ge,ae,_),Xe(ae,rt),le(J,ae,$),le(ye,ge,$);for(F=0;F<16;F++)_[F+16]=J[F],_[F+32]=ye[F],_[F+48]=ae[F],_[F+64]=ge[F];var Le=_.subarray(32),$e=_.subarray(16);return ft(Le,Le),ie($e,$e,Le),M(g,$e),0}function Er(g,y){return yr(g,y,s)}function Tn(g,y){return e(y,32),Er(g,y)}function _r(g,y,m){var d=new Uint8Array(32);return yr(d,m,y),C(g,r,d,U)}var si=ne,Ji=G;function oi(g,y,m,d,_,$){var F=new Uint8Array(32);return _r(F,_,$),si(g,y,m,d,F)}function br(g,y,m,d,_,$){var F=new Uint8Array(32);return _r(F,_,$),Ji(g,y,m,d,F)}var Sr=[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 j(g,y,m,d){for(var _=new Int32Array(16),$=new Int32Array(16),F,J,ae,ye,ge,rt,Ae,Le,$e,Qe,Fe,De,Me,Ue,Ee,Se,me,_e,be,pe,W,q,re,X,Z,oe,ke=g[0],We=g[1],Ke=g[2],qe=g[3],I=g[4],ze=g[5],it=g[6],st=g[7],Ve=y[0],et=y[1],tt=y[2],Rt=y[3],ut=y[4],kt=y[5],vt=y[6],Bt=y[7],Ut=0;d>=128;){for(be=0;be<16;be++)pe=8*be+Ut,_[be]=m[pe+0]<<24|m[pe+1]<<16|m[pe+2]<<8|m[pe+3],$[be]=m[pe+4]<<24|m[pe+5]<<16|m[pe+6]<<8|m[pe+7];for(be=0;be<80;be++)if(F=ke,J=We,ae=Ke,ye=qe,ge=I,rt=ze,Ae=it,Le=st,$e=Ve,Qe=et,Fe=tt,De=Rt,Me=ut,Ue=kt,Ee=vt,Se=Bt,W=st,q=Bt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=(I>>>14|ut<<18)^(I>>>18|ut<<14)^(ut>>>9|I<<23),q=(ut>>>14|I<<18)^(ut>>>18|I<<14)^(I>>>9|ut<<23),re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,W=I&ze^~I&it,q=ut&kt^~ut&vt,re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,W=Sr[be*2],q=Sr[be*2+1],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,W=_[be%16],q=$[be%16],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,me=Z&65535|oe<<16,_e=re&65535|X<<16,W=me,q=_e,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=(ke>>>28|Ve<<4)^(Ve>>>2|ke<<30)^(Ve>>>7|ke<<25),q=(Ve>>>28|ke<<4)^(ke>>>2|Ve<<30)^(ke>>>7|Ve<<25),re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,W=ke&We^ke&Ke^We&Ke,q=Ve&et^Ve&tt^et&tt,re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,Le=Z&65535|oe<<16,Se=re&65535|X<<16,W=ye,q=De,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=me,q=_e,re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,ye=Z&65535|oe<<16,De=re&65535|X<<16,We=F,Ke=J,qe=ae,I=ye,ze=ge,it=rt,st=Ae,ke=Le,et=$e,tt=Qe,Rt=Fe,ut=De,kt=Me,vt=Ue,Bt=Ee,Ve=Se,be%16===15)for(pe=0;pe<16;pe++)W=_[pe],q=$[pe],re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=_[(pe+9)%16],q=$[(pe+9)%16],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,me=_[(pe+1)%16],_e=$[(pe+1)%16],W=(me>>>1|_e<<31)^(me>>>8|_e<<24)^me>>>7,q=(_e>>>1|me<<31)^(_e>>>8|me<<24)^(_e>>>7|me<<25),re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,me=_[(pe+14)%16],_e=$[(pe+14)%16],W=(me>>>19|_e<<13)^(_e>>>29|me<<3)^me>>>6,q=(_e>>>19|me<<13)^(me>>>29|_e<<3)^(_e>>>6|me<<26),re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,_[pe]=Z&65535|oe<<16,$[pe]=re&65535|X<<16;W=ke,q=Ve,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=g[0],q=y[0],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[0]=ke=Z&65535|oe<<16,y[0]=Ve=re&65535|X<<16,W=We,q=et,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=g[1],q=y[1],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[1]=We=Z&65535|oe<<16,y[1]=et=re&65535|X<<16,W=Ke,q=tt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=g[2],q=y[2],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[2]=Ke=Z&65535|oe<<16,y[2]=tt=re&65535|X<<16,W=qe,q=Rt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=g[3],q=y[3],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[3]=qe=Z&65535|oe<<16,y[3]=Rt=re&65535|X<<16,W=I,q=ut,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=g[4],q=y[4],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[4]=I=Z&65535|oe<<16,y[4]=ut=re&65535|X<<16,W=ze,q=kt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=g[5],q=y[5],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[5]=ze=Z&65535|oe<<16,y[5]=kt=re&65535|X<<16,W=it,q=vt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=g[6],q=y[6],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[6]=it=Z&65535|oe<<16,y[6]=vt=re&65535|X<<16,W=st,q=Bt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=g[7],q=y[7],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,g[7]=st=Z&65535|oe<<16,y[7]=Bt=re&65535|X<<16,Ut+=128,d-=128}return d}function he(g,y,m){var d=new Int32Array(8),_=new Int32Array(8),$=new Uint8Array(256),F,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,_[0]=4089235720,_[1]=2227873595,_[2]=4271175723,_[3]=1595750129,_[4]=2917565137,_[5]=725511199,_[6]=4215389547,_[7]=327033209,j(d,_,y,m),m%=128,F=0;F<m;F++)$[F]=y[J-m+F];for($[m]=128,m=256-128*(m<112?1:0),$[m-9]=0,p($,m-8,J/536870912|0,J<<3),j(d,_,$,m),F=0;F<8;F++)p(g,8*F,d[F],_[F]);return 0}function xe(g,y){var m=t(),d=t(),_=t(),$=t(),F=t(),J=t(),ae=t(),ye=t(),ge=t();ue(m,g[1],g[0]),ue(ge,y[1],y[0]),ie(m,m,ge),ee(d,g[0],g[1]),ee(ge,y[0],y[1]),ie(d,d,ge),ie(_,g[3],y[3]),ie(_,_,l),ie($,g[2],y[2]),ee($,$,$),ue(F,d,m),ue(J,$,_),ee(ae,$,_),ee(ye,d,m),ie(g[0],F,J),ie(g[1],ye,ae),ie(g[2],ae,J),ie(g[3],F,ye)}function Te(g,y,m){var d;for(d=0;d<4;d++)le(g[d],y[d],m)}function Je(g,y){var m=t(),d=t(),_=t();ft(_,y[2]),ie(m,y[0],_),ie(d,y[1],_),M(g,d),g[31]^=L(m)<<7}function Lt(g,y,m){var d,_;for(Y(g[0],i),Y(g[1],o),Y(g[2],o),Y(g[3],i),_=255;_>=0;--_)d=m[_/8|0]>>(_&7)&1,Te(g,y,d),xe(y,g),xe(g,g),Te(g,y,d)}function In(g,y){var m=[t(),t(),t(),t()];Y(m[0],f),Y(m[1],u),Y(m[2],o),ie(m[3],f,u),Lt(g,m,y)}function an(g,y,m){var d=new Uint8Array(64),_=[t(),t(),t(),t()],$;for(m||e(y,32),he(d,y,32),d[0]&=248,d[31]&=127,d[31]|=64,In(_,d),Je(g,_),$=0;$<32;$++)y[$+32]=g[$];return 0}var xr=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 at(g,y){var m,d,_,$;for(d=63;d>=32;--d){for(m=0,_=d-32,$=d-12;_<$;++_)y[_]+=m-16*y[d]*xr[_-(d-32)],m=y[_]+128>>8,y[_]-=m*256;y[_]+=m,y[d]=0}for(m=0,_=0;_<32;_++)y[_]+=m-(y[31]>>4)*xr[_],m=y[_]>>8,y[_]&=255;for(_=0;_<32;_++)y[_]-=m*xr[_];for(d=0;d<32;d++)y[d+1]+=y[d]>>8,g[d]=y[d]&255}function Mt(g){var y=new Float64Array(64),m;for(m=0;m<64;m++)y[m]=g[m];for(m=0;m<64;m++)g[m]=0;at(g,y)}function Dt(g,y,m,d){var _=new Uint8Array(64),$=new Uint8Array(64),F=new Uint8Array(64),J,ae,ye=new Float64Array(64),ge=[t(),t(),t(),t()];he(_,d,32),_[0]&=248,_[31]&=127,_[31]|=64;var rt=m+64;for(J=0;J<m;J++)g[64+J]=y[J];for(J=0;J<32;J++)g[32+J]=_[32+J];for(he(F,g.subarray(32),m+32),Mt(F),In(ge,F),Je(g,ge),J=32;J<64;J++)g[J]=d[J];for(he($,g,m+64),Mt($),J=0;J<64;J++)ye[J]=0;for(J=0;J<32;J++)ye[J]=F[J];for(J=0;J<32;J++)for(ae=0;ae<32;ae++)ye[J+ae]+=$[J]*_[ae];return at(g.subarray(32),ye),rt}function It(g,y){var m=t(),d=t(),_=t(),$=t(),F=t(),J=t(),ae=t();return Y(g[2],o),K(g[1],y),Xe(_,g[1]),ie($,_,c),ue(_,_,g[2]),ee($,g[2],$),Xe(F,$),Xe(J,F),ie(ae,J,F),ie(m,ae,_),ie(m,m,$),on(m,m),ie(m,m,_),ie(m,m,$),ie(m,m,$),ie(g[0],m,$),Xe(d,g[0]),ie(d,d,$),N(d,_)&&ie(g[0],g[0],h),Xe(d,g[0]),ie(d,d,$),N(d,_)?-1:(L(g[0])===y[31]>>7&&ue(g[0],i,g[0]),ie(g[3],g[0],g[1]),0)}function gt(g,y,m,d){var _,$,F=new Uint8Array(32),J=new Uint8Array(64),ae=[t(),t(),t(),t()],ye=[t(),t(),t(),t()];if($=-1,m<64||It(ye,d))return-1;for(_=0;_<m;_++)g[_]=y[_];for(_=0;_<32;_++)g[_+32]=d[_];if(he(J,g,m),Mt(J),Lt(ae,ye,J),In(ye,y.subarray(32)),xe(ae,ye),Je(F,ae),m-=64,S(y,0,F,0)){for(_=0;_<m;_++)g[_]=0;return-1}for(_=0;_<m;_++)g[_]=y[_+64];return $=m,$}var dn=32,Ct=24,ar=32,wr=16,ai=32,Zi=32,ci=32,li=32,go=32,Dc=Ct,lp=ar,fp=wr,Ln=64,cr=32,Ir=64,mo=32,Ao=64;n.lowlevel={crypto_core_hsalsa20:C,crypto_stream_xor:w,crypto_stream:b,crypto_stream_salsa20_xor:Q,crypto_stream_salsa20:B,crypto_onetimeauth:v,crypto_onetimeauth_verify:P,crypto_verify_16:E,crypto_verify_32:S,crypto_secretbox:ne,crypto_secretbox_open:G,crypto_scalarmult:yr,crypto_scalarmult_base:Er,crypto_box_beforenm:_r,crypto_box_afternm:si,crypto_box:oi,crypto_box_open:br,crypto_box_keypair:Tn,crypto_hash:he,crypto_sign:Dt,crypto_sign_keypair:an,crypto_sign_open:gt,crypto_secretbox_KEYBYTES:dn,crypto_secretbox_NONCEBYTES:Ct,crypto_secretbox_ZEROBYTES:ar,crypto_secretbox_BOXZEROBYTES:wr,crypto_scalarmult_BYTES:ai,crypto_scalarmult_SCALARBYTES:Zi,crypto_box_PUBLICKEYBYTES:ci,crypto_box_SECRETKEYBYTES:li,crypto_box_BEFORENMBYTES:go,crypto_box_NONCEBYTES:Dc,crypto_box_ZEROBYTES:lp,crypto_box_BOXZEROBYTES:fp,crypto_sign_BYTES:Ln,crypto_sign_PUBLICKEYBYTES:cr,crypto_sign_SECRETKEYBYTES:Ir,crypto_sign_SEEDBYTES:mo,crypto_hash_BYTES:Ao};function Uc(g,y){if(g.length!==dn)throw new Error("bad key size");if(y.length!==Ct)throw new Error("bad nonce size")}function up(g,y){if(g.length!==ci)throw new Error("bad public key size");if(y.length!==li)throw new Error("bad secret key size")}function cn(){var g,y;for(y=0;y<arguments.length;y++)if((g=Object.prototype.toString.call(arguments[y]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+g+", use Uint8Array")}function Mc(g){for(var y=0;y<g.length;y++)g[y]=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(g){var y=new Uint8Array(g);return e(y,g),y},n.secretbox=function(g,y,m){cn(g,y,m),Uc(m,y);for(var d=new Uint8Array(ar+g.length),_=new Uint8Array(d.length),$=0;$<g.length;$++)d[$+ar]=g[$];return ne(_,d,d.length,y,m),_.subarray(wr)},n.secretbox.open=function(g,y,m){cn(g,y,m),Uc(m,y);for(var d=new Uint8Array(wr+g.length),_=new Uint8Array(d.length),$=0;$<g.length;$++)d[$+wr]=g[$];return d.length<32||G(_,d,d.length,y,m)!==0?!1:_.subarray(ar)},n.secretbox.keyLength=dn,n.secretbox.nonceLength=Ct,n.secretbox.overheadLength=wr,n.scalarMult=function(g,y){if(cn(g,y),g.length!==Zi)throw new Error("bad n size");if(y.length!==ai)throw new Error("bad p size");var m=new Uint8Array(ai);return yr(m,g,y),m},n.scalarMult.base=function(g){if(cn(g),g.length!==Zi)throw new Error("bad n size");var y=new Uint8Array(ai);return Er(y,g),y},n.scalarMult.scalarLength=Zi,n.scalarMult.groupElementLength=ai,n.box=function(g,y,m,d){var _=n.box.before(m,d);return n.secretbox(g,y,_)},n.box.before=function(g,y){cn(g,y),up(g,y);var m=new Uint8Array(go);return _r(m,g,y),m},n.box.after=n.secretbox,n.box.open=function(g,y,m,d){var _=n.box.before(m,d);return n.secretbox.open(g,y,_)},n.box.open.after=n.secretbox.open,n.box.keyPair=function(){var g=new Uint8Array(ci),y=new Uint8Array(li);return Tn(g,y),{publicKey:g,secretKey:y}},n.box.keyPair.fromSecretKey=function(g){if(cn(g),g.length!==li)throw new Error("bad secret key size");var y=new Uint8Array(ci);return Er(y,g),{publicKey:y,secretKey:new Uint8Array(g)}},n.box.publicKeyLength=ci,n.box.secretKeyLength=li,n.box.sharedKeyLength=go,n.box.nonceLength=Dc,n.box.overheadLength=n.secretbox.overheadLength,n.sign=function(g,y){if(cn(g,y),y.length!==Ir)throw new Error("bad secret key size");var m=new Uint8Array(Ln+g.length);return Dt(m,g,g.length,y),m},n.sign.open=function(g,y){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(cn(g,y),y.length!==cr)throw new Error("bad public key size");var m=new Uint8Array(g.length),d=gt(m,g,g.length,y);if(d<0)return null;for(var _=new Uint8Array(d),$=0;$<_.length;$++)_[$]=m[$];return _},n.sign.detached=function(g,y){for(var m=n.sign(g,y),d=new Uint8Array(Ln),_=0;_<d.length;_++)d[_]=m[_];return d},n.sign.detached.verify=function(g,y,m){if(cn(g,y,m),y.length!==Ln)throw new Error("bad signature size");if(m.length!==cr)throw new Error("bad public key size");var d=new Uint8Array(Ln+g.length),_=new Uint8Array(Ln+g.length),$;for($=0;$<Ln;$++)d[$]=y[$];for($=0;$<g.length;$++)d[$+Ln]=g[$];return gt(_,d,d.length,m)>=0},n.sign.keyPair=function(){var g=new Uint8Array(cr),y=new Uint8Array(Ir);return an(g,y),{publicKey:g,secretKey:y}},n.sign.keyPair.fromSecretKey=function(g){if(cn(g),g.length!==Ir)throw new Error("bad secret key size");for(var y=new Uint8Array(cr),m=0;m<y.length;m++)y[m]=g[32+m];return{publicKey:y,secretKey:new Uint8Array(g)}},n.sign.keyPair.fromSeed=function(g){if(cn(g),g.length!==mo)throw new Error("bad seed size");for(var y=new Uint8Array(cr),m=new Uint8Array(Ir),d=0;d<32;d++)m[d]=g[d];return an(y,m,!0),{publicKey:y,secretKey:m}},n.sign.publicKeyLength=cr,n.sign.secretKeyLength=Ir,n.sign.seedLength=mo,n.sign.signatureLength=Ln,n.hash=function(g){cn(g);var y=new Uint8Array(Ao);return he(y,g,g.length),y},n.hash.hashLength=Ao,n.verify=function(g,y){return cn(g,y),g.length===0||y.length===0||g.length!==y.length?!1:A(g,0,y,0,g.length)===0},n.setPRNG=function(g){e=g},(function(){var g=typeof self<"u"?self.crypto||self.msCrypto:null;if(g&&g.getRandomValues){var y=65536;n.setPRNG(function(m,d){var _,$=new Uint8Array(d);for(_=0;_<d;_+=y)g.getRandomValues($.subarray(_,_+Math.min(d-_,y)));for(_=0;_<d;_++)m[_]=$[_];Mc($)})}else typeof require<"u"&&(g=require("crypto"),g&&g.randomBytes&&n.setPRNG(function(m,d){var _,$=g.randomBytes(d);for(_=0;_<d;_++)m[_]=$[_];Mc($)}))})()})(typeof xs<"u"&&xs.exports?xs.exports:self.nacl=self.nacl||{})});var Oo=lt((cx,fu)=>{"use strict";var Do=lu().lowlevel.crypto_hash,Mn=0,ur=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 Is(n,t,e){return(n[0][t[e+3]]+n[1][t[e+2]]^n[2][t[e+1]])+n[3][t[e]]}ur.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]^=Is(this.S,t,0)^this.P[e],n[0]^=Is(this.S,t,4)^this.P[e+1];var r=n[0];n[0]=n[1]^this.P[17],n[1]=r};ur.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]^=Is(this.S,t,0)^this.P[e],n[0]^=Is(this.S,t,4)^this.P[e-1];var r=n[0];n[0]=n[1]^this.P[0],n[1]=r};function fr(n,t){var e,r=0;for(e=0;e<4;e++,Mn++)Mn>=t&&(Mn=0),r=r<<8|n[Mn];return r}ur.prototype.expand0state=function(n,t){var e=new Uint32Array(2),r,s,i=new Uint8Array(e.buffer);for(r=0,Mn=0;r<18;r++)this.P[r]^=fr(n,t);for(Mn=0,r=0;r<18;r+=2)this.encipher(e,i),this.P[r]=e[0],this.P[r+1]=e[1];for(r=0;r<4;r++)for(s=0;s<256;s+=2)this.encipher(e,i),this.S[r][s]=e[0],this.S[r][s+1]=e[1]};ur.prototype.expandstate=function(n,t,e,r){var s=new Uint32Array(2),i,o;for(i=0,Mn=0;i<18;i++)this.P[i]^=fr(e,r);for(i=0,Mn=0;i<18;i+=2)s[0]^=fr(n,t),s[1]^=fr(n,t),this.encipher(s),this.P[i]=s[0],this.P[i+1]=s[1];for(i=0;i<4;i++)for(o=0;o<256;o+=2)s[0]^=fr(n,t),s[1]^=fr(n,t),this.encipher(s),this.S[i][o]=s[0],this.S[i][o+1]=s[1];Mn=0};ur.prototype.enc=function(n,t){for(var e=0;e<t;e++)this.encipher(n.subarray(e*2))};ur.prototype.dec=function(n,t){for(var e=0;e<t;e++)this.decipher(n.subarray(e*2))};var ws=8,Uo=32;function Mo(n,t,e){var r=new ur,s=new Uint32Array(ws),i,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),i=0;i<64;i++)r.expand0state(t,64),r.expand0state(n,64);for(i=0;i<ws;i++)s[i]=fr(o,o.byteLength);for(i=0;i<64;i++)r.enc(s,s.byteLength/8);for(i=0;i<ws;i++)e[4*i+3]=s[i]>>>24,e[4*i+2]=s[i]>>>16,e[4*i+1]=s[i]>>>8,e[4*i+0]=s[i]}function Ug(n,t,e,r,s,i,o){var a=new Uint8Array(64),c=new Uint8Array(64),l=new Uint8Array(Uo),f=new Uint8Array(Uo),u=new Uint8Array(r+4),h,p,A,E,S,x,R=i;if(o<1||t===0||r===0||i===0||i>l.byteLength*l.byteLength||r>1<<20)return-1;for(E=Math.floor((i+l.byteLength-1)/l.byteLength),A=Math.floor((i+E-1)/E),h=0;h<r;h++)u[h]=e[h];for(Do(a,n,t),x=1;i>0;x++){for(u[r+0]=x>>>24,u[r+1]=x>>>16,u[r+2]=x>>>8,u[r+3]=x,Do(c,u,r+4),Mo(a,c,f),h=l.byteLength;h--;)l[h]=f[h];for(h=1;h<o;h++)for(Do(c,f,f.byteLength),Mo(a,c,f),p=0;p<l.byteLength;p++)l[p]^=f[p];for(A=Math.min(A,i),h=0;h<A&&(S=h*E+(x-1),!(S>=R));h++)s[S]=l[h];i-=h}return 0}fu.exports={BLOCKS:ws,HASHSIZE:Uo,hash:Mo,pbkdf:Ug}});var Fn=lt((lx,ks)=>{"use strict";var On=require("crypto"),Ur;try{Ur=require("cpu-features")()}catch{}var{bindingAvailable:uu,CIPHER_INFO:Mg,MAC_INFO:Og}=Xn(),du=(()=>{if(typeof On.sign=="function"&&typeof On.verify=="function"){let n=`-----BEGIN PRIVATE KEY-----\r
2
2
  MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
3
- -----END PRIVATE KEY-----`,t=Buffer.from("a"),e,r;try{e=$n.sign(null,t,n),r=$n.verify(null,t,n,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&r===!0}return!1})(),ou=typeof $n.diffieHellman=="function"&&typeof $n.generateKeyPairSync=="function"&&typeof $n.createPublicKey=="function",bs=["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"];ou&&(bs.unshift("curve25519-sha256"),bs.unshift("curve25519-sha256@libssh.org"));var bg=bs.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),To=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];su&&To.unshift("ssh-ed25519");var xg=To.concat(["ssh-dss"]),au=(()=>{let n=$n.getCiphers();return t=>n.includes(yg[t].sslName)})(),Vn=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];Tr&&Tr.flags&&!Tr.flags.aes?iu?Vn.unshift("chacha20-poly1305@openssh.com"):Vn.push("chacha20-poly1305@openssh.com"):iu&&Tr&&Tr.arch==="x86"?Vn.splice(4,0,"chacha20-poly1305@openssh.com"):Vn.push("chacha20-poly1305@openssh.com");Vn=Vn.filter(au);var Sg=Vn.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(au)),cu=(()=>{let n=$n.getHashes();return t=>n.includes(_g[t].sslName)})(),fu=["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(cu),wg=fu.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(cu)),lu=["none","zlib@openssh.com","zlib"],Ig=lu.concat([]),Pr={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};xs.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:Pr,COMPAT_CHECKS:[["Cisco-1.25",Pr.BAD_DHGEX],[/^Cisco-1[.]/,Pr.BUG_DHGEX_LARGE],[/^[0-9.]+$/,Pr.OLD_EXIT],[/^OpenSSH_5[.][0-9]+/,Pr.DYN_RPORT_BUG],[/^OpenSSH_7[.]4/,Pr.IMPLY_RSA_SHA2_SIGALGS]],DEFAULT_KEX:bs,SUPPORTED_KEX:bg,DEFAULT_SERVER_HOST_KEY:To,SUPPORTED_SERVER_HOST_KEY:xg,DEFAULT_CIPHER:Vn,SUPPORTED_CIPHER:Sg,DEFAULT_MAC:fu,SUPPORTED_MAC:wg,DEFAULT_COMPRESSION:lu,SUPPORTED_COMPRESSION:Ig,curve25519Supported:ou,eddsaSupported:su};xs.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(xs.exports.DISCONNECT_REASON)).reduce((n,[t,e])=>({...n,[e]:t}),{})});var gn=ct((Hx,pu)=>{"use strict";var hn=gi().Ber,Ss,hu=Buffer[Symbol.species],Cg=Object.getPrototypeOf(Uint8Array.prototype).fill;function uu(n,t){return n[t++]*16777216+n[t++]*65536+n[t++]*256+n[t]}function mi(n,t,e,r,s){s||(s=0),r>n.length&&(r=n.length);let i=r-e,o=t.length-s;return i>o&&(i=o),t.set(new Uint8Array(n.buffer,n.byteOffset+e,i),s),i}function Ai(n,t,e){return e===void 0&&(e=n.length),new hu(n.buffer,n.byteOffset+t,e-t)}function Do(){let n=0,t,e={init:(r,s)=>{t=r,n=typeof s=="number"?s: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,s)=>{typeof r=="number"&&(s=r,r=void 0);let i=e.readUInt32BE();if(i!==void 0&&!(t.length-n<i||typeof s=="number"&&i>s))return r?Buffer.isBuffer(r)?mi(t,r,n,n+=i):t.utf8Slice(n,n+=i):Ai(t,n,n+=i)},readRaw:r=>{if(t){if(typeof r!="number")return Ai(t,n,n+=t.length-n);if(t.length-n>=r)return Ai(t,n,n+=r)}}};return e}function du(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 Lo(n,t,e){return n[e++]=t>>>24,n[e++]=t>>>16,n[e++]=t>>>8,n[e++]=t,e}var ws=Do();pu.exports={bufferCopy:mi,bufferSlice:Ai,FastBuffer:hu,bufferFill:(n,t,e,r)=>Cg.call(n,t,e,r),makeError:du,doFatalError:(n,t,e,r)=>{let s;return Ss===void 0&&({DISCONNECT_REASON:Ss}=Mn()),t instanceof Error?(s=t,typeof e!="number"?r=Ss.PROTOCOL_ERROR:r=e):s=du(t,e,!0),typeof r!="number"&&(r=Ss.PROTOCOL_ERROR),n.disconnect(r),n._destruct(),n._onError(s),1/0},readUInt32BE:uu,writeUInt32BE:Lo,writeUInt32LE:(n,t,e)=>(n[e++]=t,n[e++]=t>>>8,n[e++]=t>>>16,n[e++]=t>>>24,e),makeBufferParser:Do,bufferParser:Do(),readString:(n,t,e,r)=>{typeof e=="number"&&(r=e,e=void 0),t===void 0&&(t=0);let s=n.length-t;if(t<0||t>=n.length||s<4)return;let i=uu(n,t);if(s<4+i||typeof r=="number"&&i>r)return;t+=4;let o=t+i;return n._pos=o,e?Buffer.isBuffer(e)?mi(n,e,t,o):n.utf8Slice(t,o):Ai(n,t,o)},sigSSHToASN1:(n,t)=>{switch(t){case"ssh-dss":{if(n.length>40)return n;let e=new hn.Writer;e.startSequence();let r=n.slice(0,20),s=n.slice(20);if(r[0]&128){let i=Buffer.allocUnsafe(21);i[0]=0,r.copy(i,1),r=i}else r[0]===0&&!(r[1]&128)&&(r=r.slice(1));if(s[0]&128){let i=Buffer.allocUnsafe(21);i[0]=0,s.copy(i,1),s=i}else s[0]===0&&!(s[1]&128)&&(s=s.slice(1));return e.writeBuffer(r,hn.Integer),e.writeBuffer(s,hn.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{ws.init(n,0);let e=ws.readString(),r=ws.readString();if(ws.clear(),e===void 0||r===void 0)return;let s=new hn.Writer;return s.startSequence(),s.writeBuffer(e,hn.Integer),s.writeBuffer(r,hn.Integer),s.endSequence(),s.buffer}default:return n}},convertSignature:(n,t)=>{switch(t){case"ssh-dss":{if(n.length<=40)return n;let e=new hn.Reader(n);e.readSequence();let r=e.readString(hn.Integer,!0),s=e.readString(hn.Integer,!0),i=0,o=0;if(r.length<20){let c=Buffer.allocUnsafe(20);c.set(r,1),r=c,r[0]=0}if(s.length<20){let c=Buffer.allocUnsafe(20);c.set(s,1),s=c,s[0]=0}r.length>20&&r[0]===0&&(i=1),s.length>20&&s[0]===0&&(o=1);let a=Buffer.allocUnsafe(r.length-i+(s.length-o));return mi(r,a,i,r.length,0),mi(s,a,o,s.length,r.length-i),a}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{if(n[0]===0)return n;let e=new hn.Reader(n);e.readSequence();let r=e.readString(hn.Integer,!0),s=e.readString(hn.Integer,!0);if(r===null||s===null)return;let i=Buffer.allocUnsafe(4+r.length+4+s.length);return Lo(i,r.length,0),i.set(r,4),Lo(i,s.length,4+r.length),i.set(s,8+r.length),i}}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 gu=ct((Is,$o)=>{var Uo=(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,s;e.ready=new Promise(function(j,ue){r=j,s=ue});var i={},o;for(o in e)e.hasOwnProperty(o)&&(i[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,p,_,E;f?(l=c?require("path").dirname(l)+"/":__dirname+"/",u=function(j,ue){var xe=Nn(j);return xe?ue?xe:xe.toString():(_||(_=require("fs")),E||(E=require("path")),j=E.normalize(j),_.readFileSync(j,ue?null:"utf8"))},p=function(j){return j=u(j,!0),j.buffer||(j=new Uint8Array(j)),F(j.buffer),j},h=function(j,ue,xe){var Pe=Nn(j);Pe&&ue(Pe),_||(_=require("fs")),E||(E=require("path")),j=E.normalize(j),_.readFile(j,function(Xe,Pt){Xe?xe(Xe):ue(Pt.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),n&&(l=n),l.indexOf("blob:")!==0?l=l.substr(0,l.lastIndexOf("/")+1):l="",u=function(j){try{var ue=new XMLHttpRequest;return ue.open("GET",j,!1),ue.send(null),ue.responseText}catch(Xe){if(j=Nn(j)){ue=[];for(var xe=0;xe<j.length;xe++){var Pe=j[xe];255<Pe&&(mr&&F(!1,"Character code "+Pe+" ("+String.fromCharCode(Pe)+") at offset "+xe+" not in 0x00-0xFF."),Pe&=255),ue.push(String.fromCharCode(Pe))}return ue.join("")}throw Xe}},c&&(p=function(j){try{var ue=new XMLHttpRequest;return ue.open("GET",j,!1),ue.responseType="arraybuffer",ue.send(null),new Uint8Array(ue.response)}catch(xe){if(j=Nn(j))return j;throw xe}}),h=function(j,ue,xe){var Pe=new XMLHttpRequest;Pe.open("GET",j,!0),Pe.responseType="arraybuffer",Pe.onload=function(){if(Pe.status==200||Pe.status==0&&Pe.response)ue(Pe.response);else{var Xe=Nn(j);Xe?ue(Xe.buffer):xe()}},Pe.onerror=xe,Pe.send(null)}),e.print||console.log.bind(console);var b=e.printErr||console.warn.bind(console);for(o in i)i.hasOwnProperty(o)&&(e[o]=i[o]);i=null;var v;e.wasmBinary&&(v=e.wasmBinary);var U=e.noExitRuntime||!0;typeof WebAssembly!="object"&&q("no native wasm support detected");var H,C=!1;function F(j,ue){j||q("Assertion failed: "+ue)}function V(j){var ue=e["_"+j];return F(ue,"Cannot call unknown function "+j+", make sure it is exported"),ue}function N(j,ue,xe,Pe){var Xe={string:function(at){var Ut=0;if(at!=null&&at!==0){var Lt=(at.length<<2)+1;Ut=ri(Lt);var St=Ut,ht=k;if(0<Lt){Lt=St+Lt-1;for(var fn=0;fn<at.length;++fn){var wt=at.charCodeAt(fn);if(55296<=wt&&57343>=wt){var ir=at.charCodeAt(++fn);wt=65536+((wt&1023)<<10)|ir&1023}if(127>=wt){if(St>=Lt)break;ht[St++]=wt}else{if(2047>=wt){if(St+1>=Lt)break;ht[St++]=192|wt>>6}else{if(65535>=wt){if(St+2>=Lt)break;ht[St++]=224|wt>>12}else{if(St+3>=Lt)break;ht[St++]=240|wt>>18,ht[St++]=128|wt>>12&63}ht[St++]=128|wt>>6&63}ht[St++]=128|wt&63}}ht[St]=0}}return Ut},array:function(at){var Ut=ri(at.length);return I.set(at,Ut),Ut}},Pt=V(j),_n=[];if(j=0,Pe)for(var rn=0;rn<Pe.length;rn++){var br=Xe[xe[rn]];br?(j===0&&(j=ni()),_n[rn]=br(Pe[rn])):_n[rn]=Pe[rn]}return xe=Pt.apply(null,_n),xe=(function(at){if(ue==="string")if(at){for(var Ut=k,Lt=at+NaN,St=at;Ut[St]&&!(St>=Lt);)++St;if(16<St-at&&Ut.subarray&&x)at=x.decode(Ut.subarray(at,St));else{for(Lt="";at<St;){var ht=Ut[at++];if(ht&128){var fn=Ut[at++]&63;if((ht&224)==192)Lt+=String.fromCharCode((ht&31)<<6|fn);else{var wt=Ut[at++]&63;ht=(ht&240)==224?(ht&15)<<12|fn<<6|wt:(ht&7)<<18|fn<<12|wt<<6|Ut[at++]&63,65536>ht?Lt+=String.fromCharCode(ht):(ht-=65536,Lt+=String.fromCharCode(55296|ht>>10,56320|ht&1023))}}else Lt+=String.fromCharCode(ht)}at=Lt}}else at="";else at=ue==="boolean"?!!at:at;return at})(xe),j!==0&&Yi(j),xe}var x=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,S,I,k;function R(){var j=H.buffer;S=j,e.HEAP8=I=new Int8Array(j),e.HEAP16=new Int16Array(j),e.HEAP32=new Int32Array(j),e.HEAPU8=k=new Uint8Array(j),e.HEAPU16=new Uint16Array(j),e.HEAPU32=new Uint32Array(j),e.HEAPF32=new Float32Array(j),e.HEAPF64=new Float64Array(j)}var ne,z=[],Y=[],te=[];function ce(){var j=e.preRun.shift();z.unshift(j)}var $=0,B=null,T=null;e.preloadedImages={},e.preloadedAudios={};function q(j){throw e.onAbort&&e.onAbort(j),b(j),C=!0,j=new WebAssembly.RuntimeError("abort("+j+"). Build with -s ASSERTIONS=1 for more info."),s(j),j}var ee="data:application/octet-stream;base64,",fe;if(fe="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==",!fe.startsWith(ee)){var ie=fe;fe=e.locateFile?e.locateFile(ie,l):l+ie}function je(){var j=fe;try{if(j==fe&&v)return new Uint8Array(v);var ue=Nn(j);if(ue)return ue;if(p)return p(j);throw"both async and sync fetching of the wasm failed"}catch(xe){q(xe)}}function ft(){if(!v&&(a||c)){if(typeof fetch=="function"&&!fe.startsWith("file://"))return fetch(fe,{credentials:"same-origin"}).then(function(j){if(!j.ok)throw"failed to load wasm binary file at '"+fe+"'";return j.arrayBuffer()}).catch(function(){return je()});if(h)return new Promise(function(j,ue){h(fe,function(xe){j(new Uint8Array(xe))},ue)})}return Promise.resolve().then(function(){return je()})}function nn(j){for(;0<j.length;){var ue=j.shift();if(typeof ue=="function")ue(e);else{var xe=ue.m;typeof xe=="number"?ue.l===void 0?ne.get(xe)():ne.get(xe)(ue.l):xe(ue.l===void 0?null:ue.l)}}}var mr=!1,Ar=typeof atob=="function"?atob:function(j){var ue="",xe=0;j=j.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var Pe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),Xe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),Pt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),_n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++));Pe=Pe<<2|Xe>>4,Xe=(Xe&15)<<4|Pt>>2;var rn=(Pt&3)<<6|_n;ue+=String.fromCharCode(Pe),Pt!==64&&(ue+=String.fromCharCode(Xe)),_n!==64&&(ue+=String.fromCharCode(rn))}while(xe<j.length);return ue};function Nn(j){if(j.startsWith(ee)){if(j=j.slice(ee.length),typeof f=="boolean"&&f){var ue=Buffer.from(j,"base64");ue=new Uint8Array(ue.buffer,ue.byteOffset,ue.byteLength)}else try{var xe=Ar(j),Pe=new Uint8Array(xe.length);for(j=0;j<xe.length;++j)Pe[j]=xe.charCodeAt(j);ue=Pe}catch{throw Error("Converting base64 string to bytes failed.")}return ue}}var Er={a:function(j){var ue=k.length;if(j>>>=0,2147483648<j)return!1;for(var xe=1;4>=xe;xe*=2){var Pe=ue*(1+.2/xe);Pe=Math.min(Pe,j+100663296),Pe=Math.max(j,Pe),0<Pe%65536&&(Pe+=65536-Pe%65536);e:{try{H.grow(Math.min(2147483648,Pe)-S.byteLength+65535>>>16),R();var Xe=1;break e}catch{}Xe=void 0}if(Xe)return!0}return!1}};(function(){function j(Xe){e.asm=Xe.exports,H=e.asm.b,R(),ne=e.asm.j,Y.unshift(e.asm.c),$--,e.monitorRunDependencies&&e.monitorRunDependencies($),$==0&&(B!==null&&(clearInterval(B),B=null),T&&(Xe=T,T=null,Xe()))}function ue(Xe){j(Xe.instance)}function xe(Xe){return ft().then(function(Pt){return WebAssembly.instantiate(Pt,Pe)}).then(Xe,function(Pt){b("failed to asynchronously prepare wasm: "+Pt),q(Pt)})}var Pe={a:Er};if($++,e.monitorRunDependencies&&e.monitorRunDependencies($),e.instantiateWasm)try{return e.instantiateWasm(Pe,j)}catch(Xe){return b("Module.instantiateWasm callback failed with error: "+Xe),!1}return(function(){return v||typeof WebAssembly.instantiateStreaming!="function"||fe.startsWith(ee)||fe.startsWith("file://")||typeof fetch!="function"?xe(ue):fetch(fe,{credentials:"same-origin"}).then(function(Xe){return WebAssembly.instantiateStreaming(Xe,Pe).then(ue,function(Pt){return b("wasm streaming compile failed: "+Pt),b("falling back to ArrayBuffer instantiation"),xe(ue)})})})().catch(s),{}})(),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 ni=e.stackSave=function(){return(ni=e.stackSave=e.asm.e).apply(null,arguments)},Yi=e.stackRestore=function(){return(Yi=e.stackRestore=e.asm.f).apply(null,arguments)},ri=e.stackAlloc=function(){return(ri=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(j,ue,xe,Pe){xe=xe||[];var Xe=xe.every(function(Pt){return Pt==="number"});return ue!=="string"&&Xe&&!Pe?V(j):function(){return N(j,ue,xe,arguments)}};var yr;T=function j(){yr||_r(),yr||(T=j)};function _r(){function j(){if(!yr&&(yr=!0,e.calledRun=!0,!C)){if(nn(Y),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var ue=e.postRun.shift();te.unshift(ue)}nn(te)}}if(!(0<$)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)ce();nn(z),0<$||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),j()},1)):j())}}if(e.run=_r,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return _r(),t.ready})})();typeof Is=="object"&&typeof $o=="object"?$o.exports=Uo:typeof define=="function"&&define.amd?define([],function(){return Uo}):typeof Is=="object"&&(Is.createPoly1305=Uo)});var Gn=ct((Qx,_u)=>{"use strict";var{createCipheriv:Dr,createDecipheriv:Cs,createHmac:Mo,randomFillSync:ur,timingSafeEqual:Oo}=require("crypto"),{readUInt32BE:yi,writeUInt32BE:an}=gn(),zn=Buffer[Symbol.species],mu=2**32-1,Au=Buffer.alloc(0),Lr=Buffer.alloc(4),vs=new Map,dr=35e3,Fo,ta,na,ra,ia,sa,oa;try{Fo=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:ta,ChaChaPolyCipher:na,GenericCipher:ra,AESGCMDecipher:ia,ChaChaPolyDecipher:sa,GenericDecipher:oa}=Fo}catch{}var Ft=1,vg=(()=>{function n(t,e,r,s,i,o,a){return{sslName:t,blockLen:e,keyLen:r,ivLen:s!==0||a&Ft?s:e,authLen:i,discardLen:o,stream:!!(a&Ft)}}return{"chacha20-poly1305@openssh.com":n("chacha20",8,64,0,16,0,Ft),"aes128-gcm":n("aes-128-gcm",16,16,12,16,0,Ft),"aes256-gcm":n("aes-256-gcm",16,32,12,16,0,Ft),"aes128-gcm@openssh.com":n("aes-128-gcm",16,16,12,16,0,Ft),"aes256-gcm@openssh.com":n("aes-256-gcm",16,32,12,16,0,Ft),"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,Ft),"aes192-ctr":n("aes-192-ctr",16,24,16,0,0,Ft),"aes256-ctr":n("aes-256-ctr",16,32,16,0,0,Ft),"3des-ctr":n("des-ede3",8,24,8,0,0,Ft),"blowfish-ctr":n("bf-ecb",8,16,8,0,0,Ft),"cast128-ctr":n("cast5-ecb",8,16,8,0,0,Ft),arcfour:n("rc4",8,16,0,0,1536,Ft),arcfour128:n("rc4",8,16,0,0,1536,Ft),arcfour256:n("rc4",8,32,0,0,1536,Ft),arcfour512:n("rc4",8,64,0,0,1536,Ft)}})(),kg=(()=>{function n(t,e,r,s){return{sslName:t,len:e,actualLen:r,isETM:s}}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)}})(),Ho=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 s=Buffer.allocUnsafe(e);return an(s,e-4,0),s[4]=r,ur(s,5+t,r),s}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Eu=Buffer.alloc(32),Jt=Buffer.alloc(16),Ei,_i,aa,Qo=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 s=Buffer.allocUnsafe(e);return an(s,e-4,0),s[4]=r,ur(s,5+t,r),s}encrypt(t){if(this._dead)return;Jt[0]=0,an(Jt,this.outSeqno,12);let e=Dr("chacha20",this._encKeyMain,Jt).update(Eu),r=Dr("chacha20",this._encKeyPktLen,Jt).update(t.slice(0,4));this._onWrite(r),Jt[0]=1;let s=Dr("chacha20",this._encKeyMain,Jt).update(t.slice(4));this._onWrite(s),aa(_i,r,r.length,s,s.length,e);let i=Buffer.allocUnsafe(16);i.set(new Uint8Array(Ei.HEAPU8.buffer,_i,16),0),this._onWrite(i),this.outSeqno=this.outSeqno+1>>>0}},Wo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new na(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 s=Buffer.allocUnsafe(e+16);return an(s,e-4,0),s[4]=r,ur(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},qo=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 s=Buffer.allocUnsafe(e);return an(s,e-4,0),s[4]=r,ur(s,5+t,r),s}encrypt(t){if(this._dead)return;let e=Dr(this._encSSLName,this._encKey,this._encIV);e.setAutoPadding(!1);let r=t.slice(0,4);e.setAAD(r),this._onWrite(r);let s=e.update(t.slice(4));this._onWrite(s);let i=e.final();i.length&&this._onWrite(i);let o=e.getAuthTag();this._onWrite(o),yu(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},Ko=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new ta(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 s=Buffer.allocUnsafe(e+16);return an(s,e-4,0),s[4]=r,ur(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Vo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=Dr(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 s=vs.get(r);s===void 0&&(s=Buffer.alloc(r),vs.set(r,s)),this._cipherInstance.update(s)}}free(){this._dead=!0}allocPacket(t){let e=this._encBlockLen,r=5+t,s=e-(r-this._aadLen&e-1);s<4&&(s+=e),r+=s;let i=Buffer.allocUnsafe(r);return an(i,r-4,0),i[4]=s,ur(i,5+t,s),i}encrypt(t){if(this._dead)return;let e;if(this._macETM){let s=new Uint8Array(t.buffer,t.byteOffset,4),i=this._cipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+4,t.length-4));this._onWrite(s),this._onWrite(i),e=Mo(this._macSSLName,this._macKey),an(Lr,this.outSeqno,0),e.update(Lr),e.update(s),e.update(i)}else{let s=this._cipherInstance.update(t);this._onWrite(s),e=Mo(this._macSSLName,this._macKey),an(Lr,this.outSeqno,0),e.update(Lr),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}},Go=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 ra(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,s=e-(r-this._aadLen&e-1);s<4&&(s+=e),r+=s;let i=Buffer.allocUnsafe(r+this._macLen);return an(i,r-4,0),i[4]=s,ur(i,5+t,s),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new zn(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},zo=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 i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len>dr||this._len<8||(4+this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._packetPos<this._len){let i=Math.min(this._len-this._packetPos,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),e+=i,this._packetPos+=i,this._packetPos<this._len)return}let s=this._packet?new zn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):Au;this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Yo=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;Jt[0]=0,an(Jt,this.inSeqno,12);let c=Cs("chacha20",this._decKeyPktLen,Jt).update(this._lenBuf);if(this._len=yi(c,0),this._len>dr||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}Jt[0]=0,an(Jt,this.inSeqno,12);let s=Dr("chacha20",this._decKeyMain,Jt).update(Eu);if(aa(_i,this._lenBuf,4,this._packet,this._packet.length,s),this._calcMac.set(new Uint8Array(Ei.HEAPU8.buffer,_i,16),0),!Oo(this._calcMac,this._mac))throw new Error("Invalid MAC");Jt[0]=1;let i=Cs("chacha20",this._decKeyMain,Jt).update(this._packet),o=new zn(i.buffer,i.byteOffset+1,i.length-i[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}}}},jo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new sa(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 i=Math.min(4-this._lenPos,r-e);for(;i--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;if(this._len=this._instance.decryptLen(this._lenBuf,this.inSeqno),this._len>dr||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._pktLen<this._len){let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._macPos,r-e);if(e!==0||i!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._macPos):this._mac.set(t,this._macPos),e+=i,this._macPos+=i,this._macPos<16)return}this._instance.decrypt(this._packet,this._mac,this.inSeqno);let s=new zn(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 i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Xo=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 i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>dr||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=Cs(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(Bg(this._len))}if(this._pktLen<this._len){if(e>=r)return;let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=this._decipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+e,i)):o=this._decipherInstance.update(t),o.length&&(i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),this._packetPos+=o.length),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._tagPos,r-e);if(e!==0||i!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._tagPos):this._tag.set(t,this._tagPos),e+=i,this._tagPos+=i,this._tagPos<16)return}{this._decipherInstance.setAuthTag(this._tag);let i=this._decipherInstance.final();i.length&&(this._packet?this._packet.set(i,this._packetPos):this._packet=i)}let s=this._packet?new zn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):Au;this.inSeqno=this.inSeqno+1>>>0,yu(this._decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tagPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Jo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new ia(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 i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>dr||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 i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._tagPos,r-e);if(e!==0||i!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._tagPos):this._tag.set(t,this._tagPos),e+=i,this._tagPos+=i,this._tagPos<16)return}this._instance.decrypt(this._packet,this._len,this._tag);let s=new zn(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 i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Zo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=Cs(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 s=vs.get(r);s===void 0&&(s=Buffer.alloc(r),vs.set(r,s)),this._decipherInstance.update(s)}}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=yi(this._block,0):(a=this._decipherInstance.update(this._block),this._len=yi(a,0),c=4+this._len-this._blockSize),this._len>dr||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=Mo(this._macSSLName,this._macKey),an(Lr,this.inSeqno,0),this._macInstance.update(Lr),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 s=this._macInstance.digest();if(this._macActualLen<s.length&&(s=new Uint8Array(s.buffer,s.byteOffset,this._macActualLen)),!Rg(s,this._mac))throw new Error("Invalid MAC");let i=new zn(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(i);if(o!==void 0)return o===!1?e:o}}}},ea=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new oa(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 i=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||i!==r||i<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._blockPos):this._block.set(t,this._blockPos),e+=i,this._blockPos+=i,this._blockPos<this._block.length)return;let o;if(this._macETM?this._len=o=yi(this._block,0):(this._instance.decryptBlock(this._block),this._len=yi(this._block,0),o=4+this._len-this._block.length),this._len>dr||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 i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||i!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._macPos):this._mac.set(t,this._macPos),e+=i,this._macPos+=i,this._macPos<this._macActualLen)return}this._instance.decrypt(this._packet,this.inSeqno,this._block,this._mac);let s=new zn(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 i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}};function yu(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 Bg=(()=>{let n=Buffer.alloc(4);return t=>(n[0]=t>>>24,n[1]=t>>>16,n[2]=t>>>8,n[3]=t,n)})();function Rg(n,t){return n.length!==t.length?(Oo(n,n),!1):Oo(n,t)}function Ng(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>mu)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return ta&&!e?new Ko(n):new qo(n);case"chacha20":return na&&!e?new Wo(n):new Qo(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 ra&&!e?new Go(n):new Vo(n)}}}function Pg(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>mu)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return ia&&!e?new Jo(n):new Xo(n);case"chacha20":return sa&&!e?new jo(n):new Yo(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 oa&&!e?new ea(n):new Zo(n)}}}_u.exports={CIPHER_INFO:vg,MAC_INFO:kg,bindingAvailable:!!Fo,init:new Promise(async(n,t)=>{try{Ei=await gu()(),_i=Ei._malloc(16),aa=Ei.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}n()}),NullCipher:Ho,createCipher:Ng,NullDecipher:zo,createDecipher:Pg}});var jn=ct((Wx,Ru)=>{"use strict";var{createDecipheriv:fa,createECDH:Tg,createHash:xi,createHmac:Lg,createSign:Dg,createVerify:Ug,getCiphers:$g,sign:bu,verify:xu}=require("crypto"),Mg=$g(),{Ber:Re}=gi(),Og=Po().pbkdf,{CIPHER_INFO:Si}=Gn(),{eddsaSupported:la,SUPPORTED_CIPHER:Fg}=Mn(),{bufferSlice:hr,makeBufferParser:Hg,readString:ve,readUInt32BE:bi,writeUInt32BE:Mt}=gn(),On=Symbol("Hash Algorithm"),mn=Symbol("Private key PEM"),Cn=Symbol("Public key PEM"),Yn=Symbol("Public key SSH"),Ur=Symbol("Decrypted Key"),ca=Object.create(null);{let n=Object.keys(Si);for(let t=0;t<n.length;++t){let e=Si[n[t]].sslName;!e||ca[e]||(ca[e]=Si[n[t]])}}var ks=Hg();function An(n,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
3
+ -----END PRIVATE KEY-----`,t=Buffer.from("a"),e,r;try{e=On.sign(null,t,n),r=On.verify(null,t,n,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&r===!0}return!1})(),hu=typeof On.diffieHellman=="function"&&typeof On.generateKeyPairSync=="function"&&typeof On.createPublicKey=="function",Cs=["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"];hu&&(Cs.unshift("curve25519-sha256"),Cs.unshift("curve25519-sha256@libssh.org"));var Fg=Cs.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),Fo=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];du&&Fo.unshift("ssh-ed25519");var Hg=Fo.concat(["ssh-dss"]),pu=(()=>{let n=On.getCiphers();return t=>n.includes(Mg[t].sslName)})(),jn=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];Ur&&Ur.flags&&!Ur.flags.aes?uu?jn.unshift("chacha20-poly1305@openssh.com"):jn.push("chacha20-poly1305@openssh.com"):uu&&Ur&&Ur.arch==="x86"?jn.splice(4,0,"chacha20-poly1305@openssh.com"):jn.push("chacha20-poly1305@openssh.com");jn=jn.filter(pu);var Qg=jn.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(pu)),gu=(()=>{let n=On.getHashes();return t=>n.includes(Og[t].sslName)})(),mu=["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(gu),Wg=mu.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(gu)),Au=["none","zlib@openssh.com","zlib"],qg=Au.concat([]),Dr={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};ks.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:Dr,COMPAT_CHECKS:[["Cisco-1.25",Dr.BAD_DHGEX],[/^Cisco-1[.]/,Dr.BUG_DHGEX_LARGE],[/^[0-9.]+$/,Dr.OLD_EXIT],[/^OpenSSH_5[.][0-9]+/,Dr.DYN_RPORT_BUG],[/^OpenSSH_7[.]4/,Dr.IMPLY_RSA_SHA2_SIGALGS]],DEFAULT_KEX:Cs,SUPPORTED_KEX:Fg,DEFAULT_SERVER_HOST_KEY:Fo,SUPPORTED_SERVER_HOST_KEY:Hg,DEFAULT_CIPHER:jn,SUPPORTED_CIPHER:Qg,DEFAULT_MAC:mu,SUPPORTED_MAC:Wg,DEFAULT_COMPRESSION:Au,SUPPORTED_COMPRESSION:qg,curve25519Supported:hu,eddsaSupported:du};ks.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(ks.exports.DISCONNECT_REASON)).reduce((n,[t,e])=>({...n,[e]:t}),{})});var _n=lt((fx,bu)=>{"use strict";var mn=yi().Ber,vs,_u=Buffer[Symbol.species],Kg=Object.getPrototypeOf(Uint8Array.prototype).fill;function yu(n,t){return n[t++]*16777216+n[t++]*65536+n[t++]*256+n[t]}function Ei(n,t,e,r,s){s||(s=0),r>n.length&&(r=n.length);let i=r-e,o=t.length-s;return i>o&&(i=o),t.set(new Uint8Array(n.buffer,n.byteOffset+e,i),s),i}function _i(n,t,e){return e===void 0&&(e=n.length),new _u(n.buffer,n.byteOffset+t,e-t)}function Qo(){let n=0,t,e={init:(r,s)=>{t=r,n=typeof s=="number"?s: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,s)=>{typeof r=="number"&&(s=r,r=void 0);let i=e.readUInt32BE();if(i!==void 0&&!(t.length-n<i||typeof s=="number"&&i>s))return r?Buffer.isBuffer(r)?Ei(t,r,n,n+=i):t.utf8Slice(n,n+=i):_i(t,n,n+=i)},readRaw:r=>{if(t){if(typeof r!="number")return _i(t,n,n+=t.length-n);if(t.length-n>=r)return _i(t,n,n+=r)}}};return e}function Eu(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 Ho(n,t,e){return n[e++]=t>>>24,n[e++]=t>>>16,n[e++]=t>>>8,n[e++]=t,e}var Bs=Qo();bu.exports={bufferCopy:Ei,bufferSlice:_i,FastBuffer:_u,bufferFill:(n,t,e,r)=>Kg.call(n,t,e,r),makeError:Eu,doFatalError:(n,t,e,r)=>{let s;return vs===void 0&&({DISCONNECT_REASON:vs}=Fn()),t instanceof Error?(s=t,typeof e!="number"?r=vs.PROTOCOL_ERROR:r=e):s=Eu(t,e,!0),typeof r!="number"&&(r=vs.PROTOCOL_ERROR),n.disconnect(r),n._destruct(),n._onError(s),1/0},readUInt32BE:yu,writeUInt32BE:Ho,writeUInt32LE:(n,t,e)=>(n[e++]=t,n[e++]=t>>>8,n[e++]=t>>>16,n[e++]=t>>>24,e),makeBufferParser:Qo,bufferParser:Qo(),readString:(n,t,e,r)=>{typeof e=="number"&&(r=e,e=void 0),t===void 0&&(t=0);let s=n.length-t;if(t<0||t>=n.length||s<4)return;let i=yu(n,t);if(s<4+i||typeof r=="number"&&i>r)return;t+=4;let o=t+i;return n._pos=o,e?Buffer.isBuffer(e)?Ei(n,e,t,o):n.utf8Slice(t,o):_i(n,t,o)},sigSSHToASN1:(n,t)=>{switch(t){case"ssh-dss":{if(n.length>40)return n;let e=new mn.Writer;e.startSequence();let r=n.slice(0,20),s=n.slice(20);if(r[0]&128){let i=Buffer.allocUnsafe(21);i[0]=0,r.copy(i,1),r=i}else r[0]===0&&!(r[1]&128)&&(r=r.slice(1));if(s[0]&128){let i=Buffer.allocUnsafe(21);i[0]=0,s.copy(i,1),s=i}else s[0]===0&&!(s[1]&128)&&(s=s.slice(1));return e.writeBuffer(r,mn.Integer),e.writeBuffer(s,mn.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{Bs.init(n,0);let e=Bs.readString(),r=Bs.readString();if(Bs.clear(),e===void 0||r===void 0)return;let s=new mn.Writer;return s.startSequence(),s.writeBuffer(e,mn.Integer),s.writeBuffer(r,mn.Integer),s.endSequence(),s.buffer}default:return n}},convertSignature:(n,t)=>{switch(t){case"ssh-dss":{if(n.length<=40)return n;let e=new mn.Reader(n);e.readSequence();let r=e.readString(mn.Integer,!0),s=e.readString(mn.Integer,!0),i=0,o=0;if(r.length<20){let c=Buffer.allocUnsafe(20);c.set(r,1),r=c,r[0]=0}if(s.length<20){let c=Buffer.allocUnsafe(20);c.set(s,1),s=c,s[0]=0}r.length>20&&r[0]===0&&(i=1),s.length>20&&s[0]===0&&(o=1);let a=Buffer.allocUnsafe(r.length-i+(s.length-o));return Ei(r,a,i,r.length,0),Ei(s,a,o,s.length,r.length-i),a}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{if(n[0]===0)return n;let e=new mn.Reader(n);e.readSequence();let r=e.readString(mn.Integer,!0),s=e.readString(mn.Integer,!0);if(r===null||s===null)return;let i=Buffer.allocUnsafe(4+r.length+4+s.length);return Ho(i,r.length,0),i.set(r,4),Ho(i,s.length,4+r.length),i.set(s,8+r.length),i}}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 Su=lt((Rs,qo)=>{var Wo=(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,s;e.ready=new Promise(function(j,he){r=j,s=he});var i={},o;for(o in e)e.hasOwnProperty(o)&&(i[o]=e[o]);var a=typeof window=="object",c=typeof importScripts=="function",l=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",f="",u,h,p,A,E;l?(f=c?require("path").dirname(f)+"/":__dirname+"/",u=function(j,he){var xe=Tn(j);return xe?he?xe:xe.toString():(A||(A=require("fs")),E||(E=require("path")),j=E.normalize(j),A.readFileSync(j,he?null:"utf8"))},p=function(j){return j=u(j,!0),j.buffer||(j=new Uint8Array(j)),U(j.buffer),j},h=function(j,he,xe){var Te=Tn(j);Te&&he(Te),A||(A=require("fs")),E||(E=require("path")),j=E.normalize(j),A.readFile(j,function(Je,Lt){Je?xe(Je):he(Lt.buffer)})},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),e.inspect=function(){return"[Emscripten Module object]"}):(a||c)&&(c?f=self.location.href:typeof document<"u"&&document.currentScript&&(f=document.currentScript.src),n&&(f=n),f.indexOf("blob:")!==0?f=f.substr(0,f.lastIndexOf("/")+1):f="",u=function(j){try{var he=new XMLHttpRequest;return he.open("GET",j,!1),he.send(null),he.responseText}catch(Je){if(j=Tn(j)){he=[];for(var xe=0;xe<j.length;xe++){var Te=j[xe];255<Te&&(yr&&U(!1,"Character code "+Te+" ("+String.fromCharCode(Te)+") at offset "+xe+" not in 0x00-0xFF."),Te&=255),he.push(String.fromCharCode(Te))}return he.join("")}throw Je}},c&&(p=function(j){try{var he=new XMLHttpRequest;return he.open("GET",j,!1),he.responseType="arraybuffer",he.send(null),new Uint8Array(he.response)}catch(xe){if(j=Tn(j))return j;throw xe}}),h=function(j,he,xe){var Te=new XMLHttpRequest;Te.open("GET",j,!0),Te.responseType="arraybuffer",Te.onload=function(){if(Te.status==200||Te.status==0&&Te.response)he(Te.response);else{var Je=Tn(j);Je?he(Je.buffer):xe()}},Te.onerror=xe,Te.send(null)}),e.print||console.log.bind(console);var S=e.printErr||console.warn.bind(console);for(o in i)i.hasOwnProperty(o)&&(e[o]=i[o]);i=null;var x;e.wasmBinary&&(x=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&K("no native wasm support detected");var H,C=!1;function U(j,he){j||K("Assertion failed: "+he)}function Q(j){var he=e["_"+j];return U(he,"Cannot call unknown function "+j+", make sure it is exported"),he}function B(j,he,xe,Te){var Je={string:function(at){var Mt=0;if(at!=null&&at!==0){var Dt=(at.length<<2)+1;Mt=oi(Dt);var It=Mt,gt=v;if(0<Dt){Dt=It+Dt-1;for(var dn=0;dn<at.length;++dn){var Ct=at.charCodeAt(dn);if(55296<=Ct&&57343>=Ct){var ar=at.charCodeAt(++dn);Ct=65536+((Ct&1023)<<10)|ar&1023}if(127>=Ct){if(It>=Dt)break;gt[It++]=Ct}else{if(2047>=Ct){if(It+1>=Dt)break;gt[It++]=192|Ct>>6}else{if(65535>=Ct){if(It+2>=Dt)break;gt[It++]=224|Ct>>12}else{if(It+3>=Dt)break;gt[It++]=240|Ct>>18,gt[It++]=128|Ct>>12&63}gt[It++]=128|Ct>>6&63}gt[It++]=128|Ct&63}}gt[It]=0}}return Mt},array:function(at){var Mt=oi(at.length);return k.set(at,Mt),Mt}},Lt=Q(j),In=[];if(j=0,Te)for(var an=0;an<Te.length;an++){var xr=Je[xe[an]];xr?(j===0&&(j=si()),In[an]=xr(Te[an])):In[an]=Te[an]}return xe=Lt.apply(null,In),xe=(function(at){if(he==="string")if(at){for(var Mt=v,Dt=at+NaN,It=at;Mt[It]&&!(It>=Dt);)++It;if(16<It-at&&Mt.subarray&&b)at=b.decode(Mt.subarray(at,It));else{for(Dt="";at<It;){var gt=Mt[at++];if(gt&128){var dn=Mt[at++]&63;if((gt&224)==192)Dt+=String.fromCharCode((gt&31)<<6|dn);else{var Ct=Mt[at++]&63;gt=(gt&240)==224?(gt&15)<<12|dn<<6|Ct:(gt&7)<<18|dn<<12|Ct<<6|Mt[at++]&63,65536>gt?Dt+=String.fromCharCode(gt):(gt-=65536,Dt+=String.fromCharCode(55296|gt>>10,56320|gt&1023))}}else Dt+=String.fromCharCode(gt)}at=Dt}}else at="";else at=he==="boolean"?!!at:at;return at})(xe),j!==0&&Ji(j),xe}var b=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,w,k,v;function P(){var j=H.buffer;w=j,e.HEAP8=k=new Int8Array(j),e.HEAP16=new Int16Array(j),e.HEAP32=new Int32Array(j),e.HEAPU8=v=new Uint8Array(j),e.HEAPU16=new Uint16Array(j),e.HEAPU32=new Uint32Array(j),e.HEAPF32=new Float32Array(j),e.HEAPF64=new Float64Array(j)}var ne,G=[],Y=[],te=[];function le(){var j=e.preRun.shift();G.unshift(j)}var M=0,N=null,L=null;e.preloadedImages={},e.preloadedAudios={};function K(j){throw e.onAbort&&e.onAbort(j),S(j),C=!0,j=new WebAssembly.RuntimeError("abort("+j+"). Build with -s ASSERTIONS=1 for more info."),s(j),j}var ee="data:application/octet-stream;base64,",ue;if(ue="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==",!ue.startsWith(ee)){var ie=ue;ue=e.locateFile?e.locateFile(ie,f):f+ie}function Xe(){var j=ue;try{if(j==ue&&x)return new Uint8Array(x);var he=Tn(j);if(he)return he;if(p)return p(j);throw"both async and sync fetching of the wasm failed"}catch(xe){K(xe)}}function ft(){if(!x&&(a||c)){if(typeof fetch=="function"&&!ue.startsWith("file://"))return fetch(ue,{credentials:"same-origin"}).then(function(j){if(!j.ok)throw"failed to load wasm binary file at '"+ue+"'";return j.arrayBuffer()}).catch(function(){return Xe()});if(h)return new Promise(function(j,he){h(ue,function(xe){j(new Uint8Array(xe))},he)})}return Promise.resolve().then(function(){return Xe()})}function on(j){for(;0<j.length;){var he=j.shift();if(typeof he=="function")he(e);else{var xe=he.m;typeof xe=="number"?he.l===void 0?ne.get(xe)():ne.get(xe)(he.l):xe(he.l===void 0?null:he.l)}}}var yr=!1,Er=typeof atob=="function"?atob:function(j){var he="",xe=0;j=j.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var Te="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),Je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),Lt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),In="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++));Te=Te<<2|Je>>4,Je=(Je&15)<<4|Lt>>2;var an=(Lt&3)<<6|In;he+=String.fromCharCode(Te),Lt!==64&&(he+=String.fromCharCode(Je)),In!==64&&(he+=String.fromCharCode(an))}while(xe<j.length);return he};function Tn(j){if(j.startsWith(ee)){if(j=j.slice(ee.length),typeof l=="boolean"&&l){var he=Buffer.from(j,"base64");he=new Uint8Array(he.buffer,he.byteOffset,he.byteLength)}else try{var xe=Er(j),Te=new Uint8Array(xe.length);for(j=0;j<xe.length;++j)Te[j]=xe.charCodeAt(j);he=Te}catch{throw Error("Converting base64 string to bytes failed.")}return he}}var _r={a:function(j){var he=v.length;if(j>>>=0,2147483648<j)return!1;for(var xe=1;4>=xe;xe*=2){var Te=he*(1+.2/xe);Te=Math.min(Te,j+100663296),Te=Math.max(j,Te),0<Te%65536&&(Te+=65536-Te%65536);e:{try{H.grow(Math.min(2147483648,Te)-w.byteLength+65535>>>16),P();var Je=1;break e}catch{}Je=void 0}if(Je)return!0}return!1}};(function(){function j(Je){e.asm=Je.exports,H=e.asm.b,P(),ne=e.asm.j,Y.unshift(e.asm.c),M--,e.monitorRunDependencies&&e.monitorRunDependencies(M),M==0&&(N!==null&&(clearInterval(N),N=null),L&&(Je=L,L=null,Je()))}function he(Je){j(Je.instance)}function xe(Je){return ft().then(function(Lt){return WebAssembly.instantiate(Lt,Te)}).then(Je,function(Lt){S("failed to asynchronously prepare wasm: "+Lt),K(Lt)})}var Te={a:_r};if(M++,e.monitorRunDependencies&&e.monitorRunDependencies(M),e.instantiateWasm)try{return e.instantiateWasm(Te,j)}catch(Je){return S("Module.instantiateWasm callback failed with error: "+Je),!1}return(function(){return x||typeof WebAssembly.instantiateStreaming!="function"||ue.startsWith(ee)||ue.startsWith("file://")||typeof fetch!="function"?xe(he):fetch(ue,{credentials:"same-origin"}).then(function(Je){return WebAssembly.instantiateStreaming(Je,Te).then(he,function(Lt){return S("wasm streaming compile failed: "+Lt),S("falling back to ArrayBuffer instantiation"),xe(he)})})})().catch(s),{}})(),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 si=e.stackSave=function(){return(si=e.stackSave=e.asm.e).apply(null,arguments)},Ji=e.stackRestore=function(){return(Ji=e.stackRestore=e.asm.f).apply(null,arguments)},oi=e.stackAlloc=function(){return(oi=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(j,he,xe,Te){xe=xe||[];var Je=xe.every(function(Lt){return Lt==="number"});return he!=="string"&&Je&&!Te?Q(j):function(){return B(j,he,xe,arguments)}};var br;L=function j(){br||Sr(),br||(L=j)};function Sr(){function j(){if(!br&&(br=!0,e.calledRun=!0,!C)){if(on(Y),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var he=e.postRun.shift();te.unshift(he)}on(te)}}if(!(0<M)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)le();on(G),0<M||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),j()},1)):j())}}if(e.run=Sr,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return Sr(),t.ready})})();typeof Rs=="object"&&typeof qo=="object"?qo.exports=Wo:typeof define=="function"&&define.amd?define([],function(){return Wo}):typeof Rs=="object"&&(Rs.createPoly1305=Wo)});var Xn=lt((ux,ku)=>{"use strict";var{createCipheriv:Or,createDecipheriv:Ns,createHmac:Ko,randomFillSync:dr,timingSafeEqual:Vo}=require("crypto"),{readUInt32BE:Si,writeUInt32BE:fn}=_n(),Jn=Buffer[Symbol.species],xu=2**32-1,wu=Buffer.alloc(0),Mr=Buffer.alloc(4),Ps=new Map,hr=35e3,zo,ca,la,fa,ua,da,ha;try{zo=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:ca,ChaChaPolyCipher:la,GenericCipher:fa,AESGCMDecipher:ua,ChaChaPolyDecipher:da,GenericDecipher:ha}=zo}catch{}var Qt=1,Vg=(()=>{function n(t,e,r,s,i,o,a){return{sslName:t,blockLen:e,keyLen:r,ivLen:s!==0||a&Qt?s:e,authLen:i,discardLen:o,stream:!!(a&Qt)}}return{"chacha20-poly1305@openssh.com":n("chacha20",8,64,0,16,0,Qt),"aes128-gcm":n("aes-128-gcm",16,16,12,16,0,Qt),"aes256-gcm":n("aes-256-gcm",16,32,12,16,0,Qt),"aes128-gcm@openssh.com":n("aes-128-gcm",16,16,12,16,0,Qt),"aes256-gcm@openssh.com":n("aes-256-gcm",16,32,12,16,0,Qt),"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,Qt),"aes192-ctr":n("aes-192-ctr",16,24,16,0,0,Qt),"aes256-ctr":n("aes-256-ctr",16,32,16,0,0,Qt),"3des-ctr":n("des-ede3",8,24,8,0,0,Qt),"blowfish-ctr":n("bf-ecb",8,16,8,0,0,Qt),"cast128-ctr":n("cast5-ecb",8,16,8,0,0,Qt),arcfour:n("rc4",8,16,0,0,1536,Qt),arcfour128:n("rc4",8,16,0,0,1536,Qt),arcfour256:n("rc4",8,32,0,0,1536,Qt),arcfour512:n("rc4",8,64,0,0,1536,Qt)}})(),zg=(()=>{function n(t,e,r,s){return{sslName:t,len:e,actualLen:r,isETM:s}}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)}})(),Go=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 s=Buffer.allocUnsafe(e);return fn(s,e-4,0),s[4]=r,dr(s,5+t,r),s}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Iu=Buffer.alloc(32),en=Buffer.alloc(16),bi,xi,pa,Yo=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 s=Buffer.allocUnsafe(e);return fn(s,e-4,0),s[4]=r,dr(s,5+t,r),s}encrypt(t){if(this._dead)return;en[0]=0,fn(en,this.outSeqno,12);let e=Or("chacha20",this._encKeyMain,en).update(Iu),r=Or("chacha20",this._encKeyPktLen,en).update(t.slice(0,4));this._onWrite(r),en[0]=1;let s=Or("chacha20",this._encKeyMain,en).update(t.slice(4));this._onWrite(s),pa(xi,r,r.length,s,s.length,e);let i=Buffer.allocUnsafe(16);i.set(new Uint8Array(bi.HEAPU8.buffer,xi,16),0),this._onWrite(i),this.outSeqno=this.outSeqno+1>>>0}},jo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new la(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 s=Buffer.allocUnsafe(e+16);return fn(s,e-4,0),s[4]=r,dr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Xo=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 s=Buffer.allocUnsafe(e);return fn(s,e-4,0),s[4]=r,dr(s,5+t,r),s}encrypt(t){if(this._dead)return;let e=Or(this._encSSLName,this._encKey,this._encIV);e.setAutoPadding(!1);let r=t.slice(0,4);e.setAAD(r),this._onWrite(r);let s=e.update(t.slice(4));this._onWrite(s);let i=e.final();i.length&&this._onWrite(i);let o=e.getAuthTag();this._onWrite(o),Cu(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},Jo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new ca(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 s=Buffer.allocUnsafe(e+16);return fn(s,e-4,0),s[4]=r,dr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Zo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=Or(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 s=Ps.get(r);s===void 0&&(s=Buffer.alloc(r),Ps.set(r,s)),this._cipherInstance.update(s)}}free(){this._dead=!0}allocPacket(t){let e=this._encBlockLen,r=5+t,s=e-(r-this._aadLen&e-1);s<4&&(s+=e),r+=s;let i=Buffer.allocUnsafe(r);return fn(i,r-4,0),i[4]=s,dr(i,5+t,s),i}encrypt(t){if(this._dead)return;let e;if(this._macETM){let s=new Uint8Array(t.buffer,t.byteOffset,4),i=this._cipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+4,t.length-4));this._onWrite(s),this._onWrite(i),e=Ko(this._macSSLName,this._macKey),fn(Mr,this.outSeqno,0),e.update(Mr),e.update(s),e.update(i)}else{let s=this._cipherInstance.update(t);this._onWrite(s),e=Ko(this._macSSLName,this._macKey),fn(Mr,this.outSeqno,0),e.update(Mr),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}},ea=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 fa(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,s=e-(r-this._aadLen&e-1);s<4&&(s+=e),r+=s;let i=Buffer.allocUnsafe(r+this._macLen);return fn(i,r-4,0),i[4]=s,dr(i,5+t,s),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new Jn(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},ta=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 i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len>hr||this._len<8||(4+this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._packetPos<this._len){let i=Math.min(this._len-this._packetPos,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),e+=i,this._packetPos+=i,this._packetPos<this._len)return}let s=this._packet?new Jn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):wu;this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},na=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;en[0]=0,fn(en,this.inSeqno,12);let c=Ns("chacha20",this._decKeyPktLen,en).update(this._lenBuf);if(this._len=Si(c,0),this._len>hr||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}en[0]=0,fn(en,this.inSeqno,12);let s=Or("chacha20",this._decKeyMain,en).update(Iu);if(pa(xi,this._lenBuf,4,this._packet,this._packet.length,s),this._calcMac.set(new Uint8Array(bi.HEAPU8.buffer,xi,16),0),!Vo(this._calcMac,this._mac))throw new Error("Invalid MAC");en[0]=1;let i=Ns("chacha20",this._decKeyMain,en).update(this._packet),o=new Jn(i.buffer,i.byteOffset+1,i.length-i[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}}}},ra=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new da(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 i=Math.min(4-this._lenPos,r-e);for(;i--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;if(this._len=this._instance.decryptLen(this._lenBuf,this.inSeqno),this._len>hr||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._pktLen<this._len){let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._macPos,r-e);if(e!==0||i!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._macPos):this._mac.set(t,this._macPos),e+=i,this._macPos+=i,this._macPos<16)return}this._instance.decrypt(this._packet,this._mac,this.inSeqno);let s=new Jn(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 i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},ia=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 i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>hr||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=Ns(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(Gg(this._len))}if(this._pktLen<this._len){if(e>=r)return;let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=this._decipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+e,i)):o=this._decipherInstance.update(t),o.length&&(i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),this._packetPos+=o.length),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._tagPos,r-e);if(e!==0||i!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._tagPos):this._tag.set(t,this._tagPos),e+=i,this._tagPos+=i,this._tagPos<16)return}{this._decipherInstance.setAuthTag(this._tag);let i=this._decipherInstance.final();i.length&&(this._packet?this._packet.set(i,this._packetPos):this._packet=i)}let s=this._packet?new Jn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):wu;this.inSeqno=this.inSeqno+1>>>0,Cu(this._decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tagPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},sa=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new ua(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 i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>hr||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 i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._tagPos,r-e);if(e!==0||i!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._tagPos):this._tag.set(t,this._tagPos),e+=i,this._tagPos+=i,this._tagPos<16)return}this._instance.decrypt(this._packet,this._len,this._tag);let s=new Jn(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 i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},oa=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=Ns(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 s=Ps.get(r);s===void 0&&(s=Buffer.alloc(r),Ps.set(r,s)),this._decipherInstance.update(s)}}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=Si(this._block,0):(a=this._decipherInstance.update(this._block),this._len=Si(a,0),c=4+this._len-this._blockSize),this._len>hr||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=Ko(this._macSSLName,this._macKey),fn(Mr,this.inSeqno,0),this._macInstance.update(Mr),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 s=this._macInstance.digest();if(this._macActualLen<s.length&&(s=new Uint8Array(s.buffer,s.byteOffset,this._macActualLen)),!Yg(s,this._mac))throw new Error("Invalid MAC");let i=new Jn(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(i);if(o!==void 0)return o===!1?e:o}}}},aa=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new ha(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 i=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||i!==r||i<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._blockPos):this._block.set(t,this._blockPos),e+=i,this._blockPos+=i,this._blockPos<this._block.length)return;let o;if(this._macETM?this._len=o=Si(this._block,0):(this._instance.decryptBlock(this._block),this._len=Si(this._block,0),o=4+this._len-this._block.length),this._len>hr||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 i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||i!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._macPos):this._mac.set(t,this._macPos),e+=i,this._macPos+=i,this._macPos<this._macActualLen)return}this._instance.decrypt(this._packet,this.inSeqno,this._block,this._mac);let s=new Jn(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 i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}};function Cu(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 Gg=(()=>{let n=Buffer.alloc(4);return t=>(n[0]=t>>>24,n[1]=t>>>16,n[2]=t>>>8,n[3]=t,n)})();function Yg(n,t){return n.length!==t.length?(Vo(n,n),!1):Vo(n,t)}function jg(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>xu)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return ca&&!e?new Jo(n):new Xo(n);case"chacha20":return la&&!e?new jo(n):new Yo(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 fa&&!e?new ea(n):new Zo(n)}}}function Xg(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>xu)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return ua&&!e?new sa(n):new ia(n);case"chacha20":return da&&!e?new ra(n):new na(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 ha&&!e?new aa(n):new oa(n)}}}ku.exports={CIPHER_INFO:Vg,MAC_INFO:zg,bindingAvailable:!!zo,init:new Promise(async(n,t)=>{try{bi=await Su()(),xi=bi._malloc(16),pa=bi.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}n()}),NullCipher:Go,createCipher:jg,NullDecipher:ta,createDecipher:Xg}});var er=lt((dx,Uu)=>{"use strict";var{createDecipheriv:ma,createECDH:Jg,createHash:Ii,createHmac:Zg,createSign:em,createVerify:tm,getCiphers:nm,sign:vu,verify:Bu}=require("crypto"),rm=nm(),{Ber:Ne}=yi(),im=Oo().pbkdf,{CIPHER_INFO:Ci}=Xn(),{eddsaSupported:Aa,SUPPORTED_CIPHER:sm}=Fn(),{bufferSlice:pr,makeBufferParser:om,readString:ve,readUInt32BE:wi,writeUInt32BE:Ft}=_n(),Hn=Symbol("Hash Algorithm"),bn=Symbol("Private key PEM"),Bn=Symbol("Public key PEM"),Zn=Symbol("Public key SSH"),Fr=Symbol("Decrypted Key"),ga=Object.create(null);{let n=Object.keys(Ci);for(let t=0;t<n.length;++t){let e=Ci[n[t]].sslName;!e||ga[e]||(ga[e]=Ci[n[t]])}}var Ts=om();function Sn(n,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
4
4
  `);return t.length&63&&(e+=`
5
5
  `),`-----BEGIN ${n} KEY-----
6
- ${e}-----END ${n} KEY-----`}function wi(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return e.set(n,0),e.set(t,n.length),e}function ua(n,t){let e=n.length,r=n._pos||0;for(let s=0;s<t;++s){let i=e-r;if(r>=e||i<4)return!1;let o=bi(n,r);if(i<4+o)return!1;r+=4+o}return n._pos=r,!0}function Ii(n,t){let e=new Re.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.113549.1.1.1"),e.writeNull(),e.endSequence(),e.startSequence(Re.BitString),e.writeByte(0),e.startSequence(),e.writeBuffer(n,Re.Integer),e.writeBuffer(t,Re.Integer),e.endSequence(),e.endSequence(),e.endSequence(),An("PUBLIC",e.buffer)}function Ci(n,t){let e=Buffer.allocUnsafe(15+t.length+4+n.length);Mt(e,7,0),e.utf8Write("ssh-rsa",4,7);let r=11;return Mt(e,t.length,r),e.set(t,r+=4),Mt(e,n.length,r+=t.length),e.set(n,r+4),e}var Su=(()=>{function n(r,s,i,o,a,c,f,l){let u=new Re.Writer;return u.startSequence(),u.writeInt(0,Re.Integer),u.writeBuffer(r,Re.Integer),u.writeBuffer(s,Re.Integer),u.writeBuffer(i,Re.Integer),u.writeBuffer(o,Re.Integer),u.writeBuffer(a,Re.Integer),u.writeBuffer(c,Re.Integer),u.writeBuffer(f,Re.Integer),u.writeBuffer(l,Re.Integer),u.endSequence(),u.buffer}function t(r){return BigInt(`0x${r.hexSlice(0,r.length)}`)}function e(r){let s=r.toString(16);if((s.length&1)!==0)s=`0${s}`;else{let i=s.charCodeAt(0);(i===56||i===57||i>=97&&i<=102)&&(s=`00${s}`)}return Buffer.from(s,"hex")}return function(s,i,o,a,c,f){let l=t(o),u=e(l%(t(c)-1n)),h=e(l%(t(f)-1n));return An("RSA PRIVATE",n(s,i,o,c,f,u,h,a))}})();function vi(n,t,e,r){let s=new Re.Writer;return s.startSequence(),s.startSequence(),s.writeOID("1.2.840.10040.4.1"),s.startSequence(),s.writeBuffer(n,Re.Integer),s.writeBuffer(t,Re.Integer),s.writeBuffer(e,Re.Integer),s.endSequence(),s.endSequence(),s.startSequence(Re.BitString),s.writeByte(0),s.writeBuffer(r,Re.Integer),s.endSequence(),s.endSequence(),An("PUBLIC",s.buffer)}function ki(n,t,e,r){let s=Buffer.allocUnsafe(15+n.length+4+t.length+4+e.length+4+r.length);Mt(s,7,0),s.utf8Write("ssh-dss",4,7);let i=11;return Mt(s,n.length,i),s.set(n,i+=4),Mt(s,t.length,i+=n.length),s.set(t,i+=4),Mt(s,e.length,i+=t.length),s.set(e,i+=4),Mt(s,r.length,i+=e.length),s.set(r,i+4),s}function wu(n,t,e,r,s){let i=new Re.Writer;return i.startSequence(),i.writeInt(0,Re.Integer),i.writeBuffer(n,Re.Integer),i.writeBuffer(t,Re.Integer),i.writeBuffer(e,Re.Integer),i.writeBuffer(r,Re.Integer),i.writeBuffer(s,Re.Integer),i.endSequence(),An("DSA PRIVATE",i.buffer)}function Iu(n){let t=new Re.Writer;return t.startSequence(),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Re.BitString),t.writeByte(0),t._ensure(n.length),t._buf.set(n,t._offset),t._offset+=n.length,t.endSequence(),t.endSequence(),An("PUBLIC",t.buffer)}function Cu(n){let t=Buffer.allocUnsafe(19+n.length);return Mt(t,11,0),t.utf8Write("ssh-ed25519",4,11),Mt(t,n.length,15),t.set(n,19),t}function Qg(n){let t=new Re.Writer;return t.startSequence(),t.writeInt(0,Re.Integer),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Re.OctetString),t.writeBuffer(n,Re.OctetString),t.endSequence(),t.endSequence(),An("PRIVATE",t.buffer)}function da(n,t){let e=new Re.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.10045.2.1"),e.writeOID(n),e.endSequence(),e.startSequence(Re.BitString),e.writeByte(0),e._ensure(t.length),e._buf.set(t,e._offset),e._offset+=t.length,e.endSequence(),e.endSequence(),An("PUBLIC",e.buffer)}function ha(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 Mt(r,19,0),r.utf8Write(`ecdsa-sha2-${e}`,4,19),Mt(r,8,23),r.utf8Write(e,27,8),Mt(r,t.length,35),r.set(t,39),r}function Wg(n,t,e){let r=new Re.Writer;return r.startSequence(),r.writeInt(1,Re.Integer),r.writeBuffer(e,Re.OctetString),r.startSequence(160),r.writeOID(n),r.endSequence(),r.startSequence(161),r.startSequence(Re.BitString),r.writeByte(0),r._ensure(t.length),r._buf.set(t,r._offset),r._offset+=t.length,r.endSequence(),r.endSequence(),r.endSequence(),An("EC PRIVATE",r.buffer)}function qg(n,t){let e=Tg(n);return e.setPrivateKey(t),e.getPublicKey()}var Bi={sign:typeof bu=="function"?function(t,e){let r=this[mn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[On]);try{return bu(e,t,r)}catch(s){return s}}:function(t,e){let r=this[mn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[On]);let s=Dg(e);s.update(t);try{return s.sign(r)}catch(i){return i}},verify:typeof xu=="function"?function(t,e,r){let s=this[Cn];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[On]);try{return xu(r,t,s,e)}catch(i){return i}}:function(t,e,r){let s=this[Cn];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[On]);let i=Ug(r);i.update(t);try{return i.verify(s,e)}catch(o){return o}},isPrivateKey:function(){return this[mn]!==null},getPrivatePEM:function(){return this[mn]},getPublicPEM:function(){return this[Cn]},getPublicSSH:function(){return this[Yn]},equals:function(t){let e=Bu(t);return e instanceof Error?!1:this.type===e.type&&this[mn]===e[mn]&&this[Cn]===e[Cn]&&this[Yn].equals(e[Yn])}};function Bs(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[mn]=e,this[Cn]=r,this[Yn]=s,this[On]=i,this[Ur]=o}Bs.prototype=Bi;{let t=function(e,r,s){let i=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=bi(e,0),a=bi(e,4);if(o!==a)return s?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 u,h,p,_,E=ve(e,e._pos,!0);if(E===void 0)return new Error("Malformed OpenSSH private key");switch(E){case"ssh-rsa":{let v=ve(e,e._pos);if(v===void 0)return new Error("Malformed OpenSSH private key");let U=ve(e,e._pos);if(U===void 0)return new Error("Malformed OpenSSH private key");let H=ve(e,e._pos);if(H===void 0)return new Error("Malformed OpenSSH private key");let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let F=ve(e,e._pos);if(F===void 0)return new Error("Malformed OpenSSH private key");let V=ve(e,e._pos);if(V===void 0)return new Error("Malformed OpenSSH private key");p=Ii(v,U),_=Ci(v,U),h=Su(v,U,H,C,F,V),u="sha1";break}case"ssh-dss":{let v=ve(e,e._pos);if(v===void 0)return new Error("Malformed OpenSSH private key");let U=ve(e,e._pos);if(U===void 0)return new Error("Malformed OpenSSH private key");let H=ve(e,e._pos);if(H===void 0)return new Error("Malformed OpenSSH private key");let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let F=ve(e,e._pos);if(F===void 0)return new Error("Malformed OpenSSH private key");p=vi(v,U,H,C),_=ki(v,U,H,C),h=wu(v,U,H,C,F),u="sha1";break}case"ssh-ed25519":{if(!la)return new Error(`Unsupported OpenSSH private key type: ${E}`);let v=ve(e,e._pos);if(v===void 0||v.length!==32)return new Error("Malformed OpenSSH private key");let U=ve(e,e._pos);if(U===void 0||U.length!==64)return new Error("Malformed OpenSSH private key");p=Iu(v),_=Cu(v),h=Qg(hr(U,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"),!ua(e,1))return new Error("Malformed OpenSSH private key");let v=ve(e,e._pos);if(v===void 0)return new Error("Malformed OpenSSH private key");let U=ve(e,e._pos);if(U===void 0)return new Error("Malformed OpenSSH private key");p=da(f,v),_=ha(f,v),h=Wg(f,v,U);break}default:return new Error(`Unsupported OpenSSH private key type: ${E}`)}let b=ve(e,e._pos,!0);if(b===void 0)return new Error("Malformed OpenSSH private key");i.push(new Bs(E,b,h,p,_,u,s))}let l=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++l%255)return new Error("Malformed OpenSSH private key");return i},n=/^-----BEGIN OPENSSH PRIVATE KEY-----(?:\r\n|\n)([\s\S]+)(?:\r\n|\n)-----END OPENSSH PRIVATE KEY-----$/;Bs.parse=(e,r)=>{let s=n.exec(e);if(s===null)return null;let i,o=Buffer.from(s[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=ve(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&Fg.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let f=ve(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 l,u,h;c!=="none"&&(l=Si[c]);let p=ve(o,o._pos);if(p===void 0)return new Error("Malformed OpenSSH private key");if(p.length)switch(f){case"none":return new Error("Malformed OpenSSH private key");case"bcrypt":{let E=ve(p,0);if(E===void 0||p._pos+4>p.length)return new Error("Malformed OpenSSH private key");let b=bi(p,p._pos),v=Buffer.allocUnsafe(l.keyLen+l.ivLen);if(Og(r,r.length,E,E.length,v,v.length,b)!==0)return new Error("Failed to generate information to decrypt key");u=hr(v,0,l.keyLen),h=hr(v,l.keyLen,v.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 _=bi(o,o._pos);if(o._pos+=4,_>0){for(let b=0;b<_;++b){let v=ve(o,o._pos);if(v===void 0)return new Error("Malformed OpenSSH private key");if(ve(v,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let E=ve(o,o._pos);if(E===void 0)return new Error("Malformed OpenSSH private key");if(u!==void 0){if(E.length<l.blockLen||E.length%l.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let b={authTagLength:l.authLen},v=fa(l.sslName,u,h,b);if(v.setAutoPadding(!1),l.authLen>0){if(o.length-o._pos<l.authLen)return new Error("Malformed OpenSSH private key");v.setAuthTag(hr(o,o._pos,o._pos+=l.authLen))}E=wi(v.update(E),v.final())}catch(b){return b}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");i=t(E,_,u!==void 0)}else i=[];return i instanceof Error?i:i[0]}}function Rs(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[mn]=e,this[Cn]=r,this[Yn]=s,this[On]=i,this[Ur]=o}Rs.prototype=Bi;{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-----$/;Rs.parse=(t,e)=>{let r=n.exec(t);if(r===null)return null;let s=Buffer.from(r[3],"base64"),i=r[2],o=!1;if(i!==void 0){i=i.split(/\r\n|\n/g);for(let _=0;_<i.length;++_){let E=i[_],b=E.indexOf(":");if(E.slice(0,b)==="DEK-Info"){let v=E.slice(b+2);if(b=v.indexOf(","),b===-1)continue;let U=v.slice(0,b).toLowerCase();if(Mg.indexOf(U)===-1)return new Error(`Cipher (${U}) not supported for encrypted OpenSSH private key`);let H=ca[U];if(!H)return new Error(`Cipher (${U}) not supported for encrypted OpenSSH private key`);let C=Buffer.from(v.slice(b+1),"hex");if(C.length!==H.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let F=hr(C,0,8),V=xi("md5").update(e).update(F).digest();for(;V.length<H.keyLen;)V=wi(V,xi("md5").update(V).update(e).update(F).digest());V.length>H.keyLen&&(V=hr(V,0,H.keyLen));try{let N=fa(U,V,C);N.setAutoPadding(!1),s=wi(N.update(s),N.final()),o=!0}catch(N){return N}}}}let a,c,f,l,u,h,p="Malformed OpenSSH private key";switch(o&&(p+=". Bad passphrase?"),r[1]){case"RSA":a="ssh-rsa",c=An("RSA PRIVATE",s);try{h=new Re.Reader(s),h.readSequence(),h.readInt();let _=h.readString(Re.Integer,!0);if(_===null)return new Error(p);let E=h.readString(Re.Integer,!0);if(E===null)return new Error(p);f=Ii(_,E),l=Ci(_,E)}catch{return new Error(p)}u="sha1";break;case"DSA":a="ssh-dss",c=An("DSA PRIVATE",s);try{h=new Re.Reader(s),h.readSequence(),h.readInt();let _=h.readString(Re.Integer,!0);if(_===null)return new Error(p);let E=h.readString(Re.Integer,!0);if(E===null)return new Error(p);let b=h.readString(Re.Integer,!0);if(b===null)return new Error(p);let v=h.readString(Re.Integer,!0);if(v===null)return new Error(p);f=vi(_,E,b,v),l=ki(_,E,b,v)}catch{return new Error(p)}u="sha1";break;case"EC":{let _,E,b;try{h=new Re.Reader(s),h.readSequence(),h.readInt(),E=h.readString(Re.OctetString,!0),h.readByte();let U=h.readLength();if(U!==null){if(h._offset=U,b=h.readOID(),b===null)return new Error(p);switch(b){case"1.2.840.10045.3.1.7":_="prime256v1",a="ecdsa-sha2-nistp256",u="sha256";break;case"1.3.132.0.34":_="secp384r1",a="ecdsa-sha2-nistp384",u="sha384";break;case"1.3.132.0.35":_="secp521r1",a="ecdsa-sha2-nistp521",u="sha512";break;default:return new Error(`Unsupported private key EC OID: ${b}`)}}else return new Error(p)}catch{return new Error(p)}c=An("EC PRIVATE",s);let v=qg(_,E);f=da(b,v),l=ha(b,v);break}}return new Rs(a,"",c,f,l,u,o)}}function Ns(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[mn]=e,this[Cn]=r,this[Yn]=s,this[On]=i,this[Ur]=o}Ns.prototype=Bi;{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]),s=/^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]+)/;Ns.parse=(i,o)=>{let a=s.exec(i);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 I=Si[c],k=wi(xi("sha1").update(e).update(o).digest(),xi("sha1").update(r).update(o).digest());k.length>I.keyLen&&(k=hr(k,0,I.keyLen));try{let R=fa(I.sslName,k,t);R.setAutoPadding(!1),l=wi(R.update(l),R.final())}catch(R){return R}}let u=a[1],h=a[3],p=Buffer.from(a[4],"base64"),_=a[6],E=u.length,b=c.length,v=Buffer.byteLength(h),U=p.length,H=l.length,C=Buffer.allocUnsafe(4+E+4+b+4+v+4+U+4+H),F=0;if(Mt(C,E,F),C.utf8Write(u,F+=4,E),Mt(C,b,F+=E),C.utf8Write(c,F+=4,b),Mt(C,v,F+=b),C.utf8Write(h,F+=4,v),Mt(C,U,F+=v),C.set(p,F+=4),Mt(C,H,F+=U),C.set(l,F+4),o||(o=n),Lg("sha1",xi("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(C).digest("hex")!==_)return f?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let N,x,S;switch(p._pos=0,ua(p,1),u){case"ssh-rsa":{let I=ve(p,p._pos);if(I===void 0)return new Error("Malformed PPK public key");let k=ve(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let R=ve(l,0);if(R===void 0)return new Error("Malformed PPK private key");let ne=ve(l,l._pos);if(ne===void 0)return new Error("Malformed PPK private key");let z=ve(l,l._pos);if(z===void 0)return new Error("Malformed PPK private key");let Y=ve(l,l._pos);if(Y===void 0)return new Error("Malformed PPK private key");N=Ii(k,I),x=Ci(k,I),S=Su(k,I,R,Y,ne,z);break}case"ssh-dss":{let I=ve(p,p._pos);if(I===void 0)return new Error("Malformed PPK public key");let k=ve(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let R=ve(p,p._pos);if(R===void 0)return new Error("Malformed PPK public key");let ne=ve(p,p._pos);if(ne===void 0)return new Error("Malformed PPK public key");let z=ve(l,0);if(z===void 0)return new Error("Malformed PPK private key");N=vi(I,k,R,ne),x=ki(I,k,R,ne),S=wu(I,k,R,ne,z);break}}return new Ns(u,h,S,N,x,"sha1",f)}}function Ts(n,t,e,r,s){this.type=n,this.comment=t,this[mn]=null,this[Cn]=e,this[Yn]=r,this[On]=s,this[Ur]=!1}Ts.prototype=Bi;{let n;la?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],s=e[2],i=Buffer.from(e[3],"base64"),o=e[4]||"",a=ve(i,i._pos,!0);return a===void 0||a.indexOf(s)!==0?new Error("Malformed OpenSSH public key"):pa(i,s,o,r)}}function Ps(n,t,e,r,s){this.type=n,this.comment=t,this[mn]=null,this[Cn]=e,this[Yn]=r,this[On]=s,this[Ur]=!1}Ps.prototype=Bi;{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;Ps.parse=s=>{let i=n.exec(s);if(i===null)return null;let o=i[1],a=0,c="";for(;i=e.exec(o);){let p=i[1],_=i[2].replace(r,"");if(_.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,p.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 l=ve(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 p=ve(f,f._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let _=ve(f,f._pos);if(_===void 0)return new Error("Malformed RFC4716 public key");u=Ii(_,p),h=Ci(_,p);break}case"ssh-dss":{let p=ve(f,f._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let _=ve(f,f._pos);if(_===void 0)return new Error("Malformed RFC4716 public key");let E=ve(f,f._pos);if(E===void 0)return new Error("Malformed RFC4716 public key");let b=ve(f,f._pos);if(b===void 0)return new Error("Malformed RFC4716 public key");u=vi(p,_,E,b),h=ki(p,_,E,b);break}default:return new Error("Malformed RFC4716 public key")}return new Ps(l,c,u,h,"sha1")}}function pa(n,t,e,r){if(!vu(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let s,i,o=null,a=null;switch(t){case"ssh-rsa":{let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=ve(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");o=Ii(f,c),a=Ci(f,c),s="sha1";break}case"ssh-dss":{let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=ve(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");let l=ve(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");let u=ve(n,n._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");o=vi(c,f,l,u),a=ki(c,f,l,u),s="sha1";break}case"ssh-ed25519":{let c=ve(n,n._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=Iu(c),a=Cu(c),s=null;break}case"ecdsa-sha2-nistp256":s="sha256",i="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":s===void 0&&(s="sha384",i="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(s===void 0&&(s="sha512",i="1.3.132.0.35"),!ua(n,1))return new Error("Malformed OpenSSH public key");let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=da(i,c),a=ha(i,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new Ts(r,e,o,a,s)}function vu(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(la)return!0;default:return!1}}function ku(n){return n?typeof n[Ur]=="boolean":!1}function Bu(n,t){if(ku(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=Bs.parse(n,t))!==null||(r=Rs.parse(n,t))!==null||(r=Ns.parse(n,t))!==null||(r=Ts.parse(n))!==null||(r=Ps.parse(n))!==null)return r;if(e){ks.init(e,0);let s=ks.readString(!0);s!==void 0&&(n=ks.readRaw(),n!==void 0&&(r=pa(n,s,"",s),r instanceof Error&&(r=null))),ks.clear()}return r||new Error("Unsupported key format")}Ru.exports={isParsedKey:ku,isSupportedKeyType:vu,parseDERKey:(n,t)=>pa(n,t,"",t),parseKey:Bu}});var _a=ct((Gx,Fu)=>{"use strict";var{Socket:Lu}=require("net"),{Duplex:Du}=require("stream"),{resolve:Kg}=require("path"),{readFile:Nu}=require("fs"),{execFile:Vg,spawn:Gg}=require("child_process"),{isParsedKey:Pu,parseKey:Ri}=jn(),{makeBufferParser:zg,readUInt32BE:ya,writeUInt32BE:Zt,writeUInt32LE:Tu}=gn();function Ni(n){let t=!1;return(...e)=>{t||(t=!0,n(...e))}}function Yg(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return n.copy(e,0),t.copy(e,n.length),e}function ma(){}var jg=Buffer.alloc(0),xt=zg(),Pi=class{getIdentities(t){t(new Error("Missing getIdentities() implementation"))}sign(t,e,r,s){typeof r=="function"&&(s=r),s(new Error("Missing sign() implementation"))}},Mr=class extends Pi{constructor(t){super(),this.socketPath=t}getStream(t){t=Ni(t);let e=new Lu;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=Ni(t),this.getStream((e,r)=>{function s(o){if(r)try{r.destroy()}catch{}o||(o=new Error("Failed to retrieve identities from agent")),t(o)}if(e)return s(e);let i=new Aa(!0);i.on("error",s),i.pipe(r).pipe(i),r.on("close",s).on("end",s).on("error",s),i.getIdentities((o,a)=>{if(o)return s(o);try{r.destroy()}catch{}t(null,a)})})}sign(t,e,r,s){typeof r=="function"?(s=r,r=void 0):(typeof r!="object"||r===null)&&(r=void 0),s=Ni(s),this.getStream((i,o)=>{function a(f){if(o)try{o.destroy()}catch{}f||(f=new Error("Failed to sign data with agent")),s(f)}if(i)return a(i);let c=new Aa(!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,l)=>{if(f)return a(f);try{o.destroy()}catch{}s(null,l)})})}},Uu=(()=>{let o=Kg(__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 Du{constructor(){super(),this.proc=void 0,this.buffer=null}_read(u){}_write(u,h,p){if(this.buffer===null)this.buffer=u;else{let v=Buffer.allocUnsafe(this.buffer.length+u.length);this.buffer.copy(v,0),u.copy(v,this.buffer.length),this.buffer=v}if(this.buffer.length<4)return p();let _=ya(this.buffer,0);if(this.buffer.length-4<_)return p();if(u=this.buffer.slice(0,4+_),this.buffer.length>4+_)return p(new Error("Unexpected multiple agent requests"));this.buffer=null;let E,b=this.proc=Gg(o,[u.length]);b.stdout.on("data",v=>{this.push(v)}),b.on("error",v=>{E=v,p(E)}),b.on("close",v=>{if(this.proc=void 0,!E){if(E=a[v])return p(E);p()}}),b.stdin.end(u)}_final(u){c(this),u()}_destroy(u,h){c(this),h()}}return class extends Mr{getStream(u){u(null,new f)}}})(),$u=(()=>{let n=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends Mr{getStream(e){e=Ni(e);let r=this.socketPath,s=!1;Nu(r,function i(o,a){if(o){if(s)return e(new Error("Invalid cygwin unix socket path"));Vg("cygpath",["-w",r],(V,N,x)=>{if(V||N.length===0)return e(new Error("Invalid cygwin unix socket path"));s=!0,r=N.toString().replace(/[\r\n]/g,""),Nu(r,i)});return}let c=n.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let f,l=0,u=!1,h=[],p,_=Buffer.alloc(12),E=parseInt(c[1],10),b=c[2].replace(/-/g,""),v=Buffer.allocUnsafe(16);for(let V=0,N=0;N<32;++V,N+=2)v[V]=parseInt(b.substring(N,N+2),16);for(let V=0;V<16;V+=4)Tu(v,ya(v,V),V);F();function U(){l=0,f="secret",p.write(v)}function H(V){if(l+=V.length,f==="secret"){l===16&&(l=0,f="creds",p.write(_));return}if(f==="creds"&&(u||h.push(V),l===12)){if(p.removeListener("connect",U),p.removeListener("data",H),p.removeListener("error",C),p.removeListener("end",C),p.removeListener("close",C),u)return e(null,p);u=!0,_=Buffer.concat(h),Tu(_,process.pid,0),p.on("error",()=>{}),p.destroy(),F()}}function C(){e(new Error("Problem negotiating cygwin unix socket security"))}function F(){p=new Lu,p.on("connect",U),p.on("data",H),p.on("error",C),p.on("end",C),p.on("close",C),p.connect(E)}})}}})(),Xg=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function Mu(n){return process.platform==="win32"&&!Xg.test(n)?n==="pageant"?new Uu:new $u(n):new Mr(n)}var Aa=(()=>{function f(x){let S;for(;x[U].length;){let I=x[U][0][u];if(I===void 0)break;x[U].shift(),S=x.push(I)}return S}let l=Symbol("Inbound Request Type"),u=Symbol("Inbound Request Response"),h=Symbol("Inbound Request Context");class p{constructor(S,I){this[l]=S,this[u]=void 0,this[h]=I}hasResponded(){return this[u]!==void 0}getType(){return this[l]}getContext(){return this[h]}}function _(x,S,I){return S[u]=I,f(x)}function E(x){if(x[C]=null,x[H]===0){let S=x[U];if(S&&S.length){x[U]=[];for(let I of S)I.cb(new Error("No reply from server"))}}try{x.end()}catch{}setImmediate(()=>{x[N]||x.emit("end"),x[V]||x.emit("close")})}function b(){this[V]=!0}function v(){this[N]=!0}let U=Symbol("Requests"),H=Symbol("Agent Protocol Role"),C=Symbol("Agent Protocol Buffer"),F=Symbol("Agent Protocol Current Message Length"),V=Symbol("Agent Protocol Closed"),N=Symbol("Agent Protocol Ended");return class extends Du{constructor(S){super({autoDestroy:!0,emitClose:!1}),this[H]=S?0:1,this[U]=[],this[C]=null,this[F]=-1,this.once("end",v),this.once("close",b)}_read(S){}_write(S,I,k){this[C]===null?this[C]=S:this[C]=Yg(this[C],S);let R=this[C],ne=R.length,z=0;for(;z<ne&&!(ne<5||(this[F]===-1&&(this[F]=ya(R,z)),ne<4+this[F]));){let Y=R[z+=4];if(++z,this[H]===0){if(this[U].length===0)return k(new Error("Received unexpected message from server"));let te=this[U].shift();switch(Y){case 5:te.cb(new Error("Agent responded with failure"));break;case 12:{if(te.type!==11)return k(new Error("Agent responded with wrong message type"));xt.init(R,z);let ce=xt.readUInt32BE();if(ce===void 0)return xt.clear(),k(new Error("Malformed agent response"));let $=[];for(let B=0;B<ce;++B){let T=xt.readString();if(T===void 0)return xt.clear(),k(new Error("Malformed agent response"));let q=xt.readString(!0);if(q===void 0)return xt.clear(),k(new Error("Malformed agent response"));T=Ri(T),!(T instanceof Error)&&(T.comment=T.comment||q,$.push(T))}z=xt.pos(),xt.clear(),te.cb(null,$);break}case 14:{if(te.type!==13)return k(new Error("Agent responded with wrong message type"));xt.init(R,z);let ce=xt.readString();if(z=xt.pos(),xt.clear(),ce===void 0)return k(new Error("Malformed agent response"));if(xt.init(ce,0),xt.readString(!0),ce=xt.readString(),xt.clear(),ce===void 0)return k(new Error("Malformed OpenSSH signature format"));te.cb(null,ce);break}default:return k(new Error("Agent responded with unsupported message type"))}}else switch(Y){case 11:{let te=new p(Y);this[U].push(te),this.emit("identities",te);break}case 13:{xt.init(R,z);let te=xt.readString(),ce=xt.readString(),$=xt.readUInt32BE();if(z=xt.pos(),xt.clear(),$===void 0){let ee=new p(Y);return this[U].push(ee),this.failureReply(ee)}if(te=Ri(te),te instanceof Error){let ee=new p(Y);return this[U].push(ee),this.failureReply(ee)}let B={hash:void 0},T;te.type==="ssh-rsa"&&($&2?(T="rsa-sha2-256",B.hash="sha256"):$&4&&(T="rsa-sha2-512",B.hash="sha512")),T===void 0&&(T=te.type);let q=new p(Y,T);this[U].push(q),this.emit("sign",q,te,ce,B);break}default:{let te=new p(Y);this[U].push(te),this.failureReply(te)}}if(this[F]=-1,z===ne){this[C]=null;break}else this[C]=R=R.slice(z),ne=R.length,z=0}k()}_destroy(S,I){E(this),I()}_final(S){E(this),S()}sign(S,I,k,R){if(this[H]!==0)throw new Error("Client-only method called with server role");typeof k=="function"?(R=k,k=void 0):(typeof k!="object"||k===null)&&(k=void 0);let ne=0;if(S=Ri(S),S instanceof Error)throw new Error("Invalid public key argument");if(S.type==="ssh-rsa"&&k)switch(k.hash){case"sha256":ne=2;break;case"sha512":ne=4;break}S=S.getPublicSSH();let z=13,Y=S.length,te=I.length,ce=0,$=Buffer.allocUnsafe(9+Y+4+te+4);return Zt($,$.length-4,ce),$[ce+=4]=z,Zt($,Y,++ce),S.copy($,ce+=4),Zt($,te,ce+=Y),I.copy($,ce+=4),Zt($,ne,ce+=te),typeof R!="function"&&(R=ma),this[U].push({type:z,cb:R}),this.push($)}getIdentities(S){if(this[H]!==0)throw new Error("Client-only method called with server role");let I=11,k=0,R=Buffer.allocUnsafe(5);return Zt(R,R.length-4,k),R[k+=4]=I,typeof S!="function"&&(S=ma),this[U].push({type:I,cb:S}),this.push(R)}failureReply(S){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(S instanceof p))throw new Error("Wrong request argument");if(S.hasResponded())return!0;let I=0,k=Buffer.allocUnsafe(5);return Zt(k,k.length-4,I),k[I+=4]=5,_(this,S,k)}getIdentitiesReply(S,I){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(S instanceof p))throw new Error("Wrong request argument");if(S.hasResponded())return!0;if(S.getType()!==11)throw new Error("Invalid response to request");if(!Array.isArray(I))throw new Error("Keys argument must be an array");let k=4,R=[];for(let Y=0;Y<I.length;++Y){let te=I[Y];if(typeof te!="object"||te===null)throw new Error(`Invalid key entry: ${te}`);let ce,$;if(Pu(te))ce=te;else if(Pu(te.pubKey))ce=te.pubKey;else if(typeof te.pubKey!="object"||te.pubKey===null||({pubKey:ce,comment:$}=te.pubKey,ce=Ri(ce),ce instanceof Error))continue;$=ce.comment||$,ce=ce.getPublicSSH(),k+=4+ce.length,$&&typeof $=="string"?$=Buffer.from($):Buffer.isBuffer($)||($=jg),k+=4+$.length,R.push({pubKey:ce,comment:$})}let ne=0,z=Buffer.allocUnsafe(5+k);Zt(z,z.length-4,ne),z[ne+=4]=12,Zt(z,R.length,++ne),ne+=4;for(let Y=0;Y<R.length;++Y){let{pubKey:te,comment:ce}=R[Y];Zt(z,te.length,ne),te.copy(z,ne+=4),Zt(z,ce.length,ne+=te.length),ne+=4,ce.length&&(ce.copy(z,ne),ne+=ce.length)}return _(this,S,z)}signReply(S,I){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(S instanceof p))throw new Error("Wrong request argument");if(S.hasResponded())return!0;if(S.getType()!==13)throw new Error("Invalid response to request");if(!Buffer.isBuffer(I))throw new Error("Signature argument must be a Buffer");if(I.length===0)throw new Error("Signature argument must be non-empty");let k=0,R=S.getContext(),ne=Buffer.byteLength(R),z=Buffer.allocUnsafe(13+ne+4+I.length);return Zt(z,z.length-4,k),z[k+=4]=14,Zt(z,4+ne+4+I.length,++k),Zt(z,ne,k+=4),z.utf8Write(R,k+=4,ne),Zt(z,I.length,k+=ne),I.copy(z,k+=4),_(this,S,z)}}})(),ga=Symbol("Agent"),En=Symbol("Agent Keys"),Fn=Symbol("Agent Keys Index"),$r=Symbol("Agent Init Callbacks"),Ea=class{constructor(t){if(typeof t=="string")t=Mu(t);else if(!Ou(t))throw new Error("Invalid agent argument");this[ga]=t,this[En]=null,this[Fn]=-1,this[$r]=null}init(t){if(typeof t!="function"&&(t=ma),this[En]===null)if(this[$r]===null){this[$r]=[t];let e=(...r)=>{process.nextTick(()=>{let s=this[$r];this[$r]=null;for(let i of s)i(...r)})};this[ga].getIdentities(Ni((r,s)=>{if(r)return e(r);if(!Array.isArray(s))return e(new Error("Agent implementation failed to provide keys"));let i=[];for(let o of s)o=Ri(o),!(o instanceof Error)&&i.push(o);this[En]=i,this[Fn]=-1,e()}))}else this[$r].push(t);else process.nextTick(t)}nextKey(){return this[En]===null||++this[Fn]>=this[En].length?!1:this[En][this[Fn]]}currentKey(){return this[En]===null||this[Fn]>=this[En].length?null:this[En][this[Fn]]}pos(){return this[En]===null||this[Fn]>=this[En].length?-1:this[Fn]}reset(){this[Fn]=-1}sign(...t){this[ga].sign(...t)}};function Ou(n){return n instanceof Pi}Fu.exports={AgentContext:Ea,AgentProtocol:Aa,BaseAgent:Pi,createAgent:Mu,CygwinAgent:$u,isAgent:Ou,OpenSSHAgent:Mr,PageantAgent:Uu}});var Ca=ct((zx,Hu)=>{"use strict";var{kMaxLength:Jg}=require("buffer"),{createInflate:Zg,constants:{DEFLATE:em,INFLATE:tm,Z_DEFAULT_CHUNK:nm,Z_DEFAULT_COMPRESSION:rm,Z_DEFAULT_MEMLEVEL:im,Z_DEFAULT_STRATEGY:sm,Z_DEFAULT_WINDOWBITS:om,Z_PARTIAL_FLUSH:am}}=require("zlib"),cm=Zg()._handle.constructor;function fm(){throw new Error("Should not get here")}function lm(n,t,e){let r=this._owner,s=new Error(n);s.errno=t,s.code=e,r._err=s}function Ia(n){n._handle&&(n._handle.close(),n._handle=null)}var Ls=class{constructor(t){let e=om,r=rm,s=im,i=sm,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=nm,this._maxOutputLength=Jg,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new cm(t),this._handle._owner=this,this._handle.onerror=lm,this._handle.init(e,r,s,i,this._writeState,fm,o)}writeSync(t,e){let r=this._handle;if(!r)throw new Error("Invalid Zlib instance");let s=t.length,i=this._chunkSize-this._outOffset,o=0,a,c,f,l=0,u=this._writeState,h=this._outBuffer,p=this._outOffset,_=this._chunkSize;for(;;){if(r.writeSync(am,t,o,s,h,p,i),this._err)throw this._err;a=u[0],c=u[1];let b=s-c,v=i-a;if(v>0){let U=p===0&&v===h.length?h:h.slice(p,p+v);if(p+=v,f?f.push===void 0?f=[f,U]:f.push(U):f=U,l+=U.byteLength,l>this._maxOutputLength)throw Ia(this),new Error(`Output length exceeded maximum of ${this._maxOutputLength}`)}else if(v!==0)throw new Error("have should not go down");if((a===0||p>=_)&&(i=_,p=0,h=Buffer.allocUnsafe(_)),a===0)o+=b,s=c;else break}if(this._outBuffer=h,this._outOffset=p,l===0&&(f=Buffer.alloc(0)),e)return f.totalLen=l,f;if(f.push===void 0)return f;let E=Buffer.allocUnsafe(l);for(let b=0,v=0;b<f.length;++b){let U=f[b];E.set(U,v),v+=U.length}return E}},ba=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new Ls(em)}cleanup(){this._zlib&&Ia(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),s=this._protocol._cipher.allocPacket(r.totalLen);if(r.push===void 0)s.set(r,5);else for(let i=0,o=5;i<r.length;++i){let a=r[i];s.set(a,o),o+=a.length}return s}return t}},xa=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}},Sa=class{constructor(){this._zlib=new Ls(tm)}cleanup(){this._zlib&&Ia(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},wa=class{cleanup(){}read(t){return t}};Hu.exports={PacketReader:wa,PacketWriter:xa,ZlibPacketReader:Sa,ZlibPacketWriter:ba}});var Vu=ct((Yx,Ku)=>{"use strict";var{bufferSlice:va,bufferParser:D,doFatalError:gt,sigSSHToASN1:Qu,writeUInt32BE:Wu}=gn(),{CHANNEL_OPEN_FAILURE:um,COMPAT:dm,MESSAGE:Et,TERMINAL_MODE:qu}=Mn(),{parseKey:hm}=jn(),pm=Array.from(Object.entries(qu)).reduce((n,[t,e])=>({...n,[t]:e}),{});Ku.exports={[Et.DISCONNECT]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString(!0),s=D.readString();if(D.clear(),s===void 0)return gt(n,"Inbound: Malformed DISCONNECT packet");n._debug&&n._debug(`Inbound: Received DISCONNECT (${e}, "${r}")`);let i=n._handlers.DISCONNECT;i&&i(n,e,r)},[Et.IGNORE]:(n,t)=>{n._debug&&n._debug("Inbound: Received IGNORE")},[Et.UNIMPLEMENTED]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return gt(n,"Inbound: Malformed UNIMPLEMENTED packet");n._debug&&n._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[Et.DEBUG]:(n,t)=>{D.init(t,1);let e=D.readBool(),r=D.readString(!0),s=D.readString();if(D.clear(),s===void 0)return gt(n,"Inbound: Malformed DEBUG packet");n._debug&&n._debug("Inbound: Received DEBUG");let i=n._handlers.DEBUG;i&&i(n,e,r)},[Et.SERVICE_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0);if(D.clear(),e===void 0)return gt(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)},[Et.SERVICE_ACCEPT]:(n,t)=>{D.init(t,1);let e=D.readString(!0);if(D.clear(),e===void 0)return gt(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)},[Et.EXT_INFO]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r;if(e!==void 0){r=[];for(let i=0;i<e;++i){let o=D.readString(!0),a=D.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(D.clear(),r===void 0)return gt(n,"Inbound: Malformed EXT_INFO packet");n._debug&&n._debug("Inbound: Received EXT_INFO");let s=n._handlers.EXT_INFO;s&&s(n,r)},[Et.USERAUTH_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readString(!0),s=D.readString(!0),i,o;switch(s){case"none":i=null;break;case"password":{let c=D.readBool();if(c!==void 0&&(i=D.readString(!0),i!==void 0&&c)){let f=D.readString(!0);f!==void 0?i={oldPassword:i,newPassword:f}:i=void 0}break}case"publickey":{let c=D.readBool();if(c!==void 0){let f=D.readString(!0),l=f,u=D.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 p=D.pos(),_=D.readString();if(_!==void 0&&(_.length>4+f.length+4&&_.utf8Slice(4,4+f.length)===f&&(_=va(_,4+f.length+4)),_=Qu(_,l),_)){let E=n._kex.sessionID,b=Buffer.allocUnsafe(4+E.length+p);Wu(b,E.length,0),b.set(E,4),b.set(new Uint8Array(t.buffer,t.byteOffset,p),4+E.length),i={keyAlgo:l,key:u,signature:_,blob:b,hashAlgo:h}}}else i={keyAlgo:l,key:u,hashAlgo:h},o="publickey -- check"}break}case"hostbased":{let c=D.readString(!0),f=c,l=D.readString(),u=D.readString(!0),h=D.readString(!0),p;switch(c){case"rsa-sha2-256":f="ssh-rsa",p="sha256";break;case"rsa-sha2-512":f="ssh-rsa",p="sha512";break}let _=D.pos(),E=D.readString();if(E!==void 0&&(E.length>4+c.length+4&&E.utf8Slice(4,4+c.length)===c&&(E=va(E,4+c.length+4)),E=Qu(E,f),E!==void 0)){let b=n._kex.sessionID,v=Buffer.allocUnsafe(4+b.length+_);Wu(v,b.length,0),v.set(b,4),v.set(new Uint8Array(t.buffer,t.byteOffset,_),4+b.length),i={keyAlgo:f,key:l,signature:E,blob:v,localHostname:u,localUsername:h,hashAlgo:p}}break}case"keyboard-interactive":D.skipString(),i=D.readList();break;default:s!==void 0&&(i=D.readRaw())}if(D.clear(),i===void 0)return gt(n,"Inbound: Malformed USERAUTH_REQUEST packet");o===void 0&&(o=s),n._authsQueue.push(s),n._debug&&n._debug(`Inbound: Received USERAUTH_REQUEST (${o})`);let a=n._handlers.USERAUTH_REQUEST;a&&a(n,e,r,s,i)},[Et.USERAUTH_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readList(),r=D.readBool();if(D.clear(),r===void 0)return gt(n,"Inbound: Malformed USERAUTH_FAILURE packet");n._debug&&n._debug(`Inbound: Received USERAUTH_FAILURE (${e})`),n._authsQueue.shift();let s=n._handlers.USERAUTH_FAILURE;s&&s(n,e,r)},[Et.USERAUTH_SUCCESS]:(n,t)=>{n._debug&&n._debug("Inbound: Received USERAUTH_SUCCESS"),n._authsQueue.shift();let e=n._handlers.USERAUTH_SUCCESS;e&&e(n)},[Et.USERAUTH_BANNER]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return gt(n,"Inbound: Malformed USERAUTH_BANNER packet");n._debug&&n._debug("Inbound: Received USERAUTH_BANNER");let s=n._handlers.USERAUTH_BANNER;s&&s(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":{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return gt(n,"Inbound: Malformed USERAUTH_PASSWD_CHANGEREQ packet");n._debug&&n._debug("Inbound: Received USERAUTH_PASSWD_CHANGEREQ");let s=n._handlers.USERAUTH_PASSWD_CHANGEREQ;s&&s(n,e);break}case"publickey":{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return gt(n,"Inbound: Malformed USERAUTH_PK_OK packet");n._debug&&n._debug("Inbound: Received USERAUTH_PK_OK"),n._authsQueue.shift();let s=n._handlers.USERAUTH_PK_OK;s&&s(n,e,r);break}case"keyboard-interactive":{D.init(t,1);let e=D.readString(!0),r=D.readString(!0);D.readString();let s=D.readUInt32BE(),i;if(s!==void 0){i=new Array(s);let a;for(a=0;a<s;++a){let c=D.readString(!0),f=D.readBool();if(f===void 0)break;i[a]={prompt:c,echo:f}}a!==s&&(i=void 0)}if(D.clear(),i===void 0)return gt(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,i);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 gt(n,"Inbound: Received unexpected payload type 61");D.init(t,1);let e=D.readUInt32BE(),r;if(e!==void 0){r=new Array(e);let i;for(i=0;i<e;++i){let o=D.readString(!0);if(o===void 0)break;r[i]=o}i!==e&&(r=void 0)}if(D.clear(),r===void 0)return gt(n,"Inbound: Malformed USERAUTH_INFO_RESPONSE packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_RESPONSE");let s=n._handlers.USERAUTH_INFO_RESPONSE;s&&s(n,r)},[Et.GLOBAL_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readBool(),s;if(r!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=D.readString(!0),a=D.readUInt32BE();a!==void 0&&(s={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=D.readString(!0);o!==void 0&&(s={socketPath:o});break}case"no-more-sessions@openssh.com":s=null;break;case"hostkeys-00@openssh.com":{for(s=[];D.avail()>0;){let o=D.readString();if(o===void 0){s=void 0;break}let a=hm(o);a instanceof Error||s.push(a)}break}default:s=D.readRaw()}if(D.clear(),s===void 0)return gt(n,"Inbound: Malformed GLOBAL_REQUEST packet");n._debug&&n._debug(`Inbound: GLOBAL_REQUEST (${e})`);let i=n._handlers.GLOBAL_REQUEST;i?i(n,e,r,s):n.requestFailure()},[Et.REQUEST_SUCCESS]:(n,t)=>{let e=t.length>1?va(t,1):null;n._debug&&n._debug("Inbound: REQUEST_SUCCESS");let r=n._handlers.REQUEST_SUCCESS;r&&r(n,e)},[Et.REQUEST_FAILURE]:(n,t)=>{n._debug&&n._debug("Inbound: Received REQUEST_FAILURE");let e=n._handlers.REQUEST_FAILURE;e&&e(n)},[Et.CHANNEL_OPEN]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readUInt32BE(),s=D.readUInt32BE(),i=D.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=D.readString(!0),f=D.readUInt32BE(),l=D.readString(!0),u=D.readUInt32BE();u!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{destIP:c,destPort:f,srcIP:l,srcPort:u}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=D.readString(!0);c!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{socketPath:c}});break}case"x11":{let c=D.readString(!0),f=D.readUInt32BE();f!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{srcIP:c,srcPort:f}});break}default:o={type:e,sender:r,window:s,packetSize:i,data:{}}}if(D.clear(),o===void 0)return gt(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,um.ADMINISTRATIVELY_PROHIBITED,"","")},[Et.CHANNEL_OPEN_CONFIRMATION]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readUInt32BE(),i=D.readUInt32BE(),o=D.avail()?D.readRaw():void 0;if(D.clear(),i===void 0)return gt(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:s,packetSize:i,data:o})},[Et.CHANNEL_OPEN_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readString(!0),i=D.readString();if(D.clear(),i===void 0)return gt(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,s)},[Et.CHANNEL_WINDOW_ADJUST]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE();if(D.clear(),r===void 0)return gt(n,"Inbound: Malformed CHANNEL_WINDOW_ADJUST packet");n._debug&&n._debug(`Inbound: CHANNEL_WINDOW_ADJUST (r:${e}, ${r})`);let s=n._handlers.CHANNEL_WINDOW_ADJUST;s&&s(n,e,r)},[Et.CHANNEL_DATA]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString();if(D.clear(),r===void 0)return gt(n,"Inbound: Malformed CHANNEL_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_DATA (r:${e}, ${r.length})`);let s=n._handlers.CHANNEL_DATA;s&&s(n,e,r)},[Et.CHANNEL_EXTENDED_DATA]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readString();if(D.clear(),s===void 0)return gt(n,"Inbound: Malformed CHANNEL_EXTENDED_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_EXTENDED_DATA (r:${e}, ${s.length})`);let i=n._handlers.CHANNEL_EXTENDED_DATA;i&&i(n,e,s,r)},[Et.CHANNEL_EOF]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return gt(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)},[Et.CHANNEL_CLOSE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return gt(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)},[Et.CHANNEL_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString(!0),s=D.readBool(),i;if(s!==void 0)switch(r){case"exit-status":i=D.readUInt32BE(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"exit-signal":{let a,c;if(n._compatFlags&dm.OLD_EXIT){let l=D.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=D.readString(!0),c=D.readBool(),c===void 0&&(a=void 0);let f=D.readString(!0);D.skipString()!==void 0&&(i={signal:a,coreDumped:c,errorMessage:f}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a})`);break}case"pty-req":{let a=D.readString(!0),c=D.readUInt32BE(),f=D.readUInt32BE(),l=D.readUInt32BE(),u=D.readUInt32BE(),h=D.readString();if(h!==void 0){D.init(h,1);let p={};for(;D.avail();){let _=D.readByte();if(_===qu.TTY_OP_END)break;let E=pm[_],b=D.readUInt32BE();if(_===void 0||E===void 0||b===void 0){p=void 0;break}p[E]=b}p!==void 0&&(i={term:a,cols:c,rows:f,width:l,height:u,modes:p})}n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"window-change":{let a=D.readUInt32BE(),c=D.readUInt32BE(),f=D.readUInt32BE(),l=D.readUInt32BE();l!==void 0&&(i={cols:a,rows:c,width:f,height:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"x11-req":{let a=D.readBool(),c=D.readString(!0),f=D.readString(),l=D.readUInt32BE();l!==void 0&&(i={single:a,protocol:c,cookie:f,screen:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"env":{let a=D.readString(!0),c=D.readString(!0);c!==void 0&&(i={name:a,value:c}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a}=${c})`);break}case"shell":i=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;case"exec":i=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"subsystem":i=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"signal":i=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"xon-xoff":i=D.readBool(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"auth-agent-req@openssh.com":i=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;default:i=D.avail()?D.readRaw():null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`)}if(D.clear(),i===void 0)return gt(n,"Inbound: Malformed CHANNEL_REQUEST packet");let o=n._handlers.CHANNEL_REQUEST;o&&o(n,e,r,s,i)},[Et.CHANNEL_SUCCESS]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return gt(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)},[Et.CHANNEL_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return gt(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 Ds=ct((jx,Gu)=>{"use strict";var ka=new Array(256);[Us().HANDLERS,Vu()].forEach(n=>{for(let[t,e]of Object.entries(n))t=+t,isFinite(t)&&t>=0&&t<ka.length&&(ka[t]=e)});Gu.exports=ka});var Us=ct((Jx,rd)=>{"use strict";var{createDiffieHellman:gm,createDiffieHellmanGroup:mm,createECDH:Am,createHash:Ra,createPublicKey:Em,diffieHellman:ym,generateKeyPairSync:_m,randomFillSync:bm}=require("crypto"),{Ber:zu}=gi(),{COMPAT:Na,curve25519Supported:xm,DEFAULT_KEX:Yu,DEFAULT_SERVER_HOST_KEY:ju,DEFAULT_CIPHER:$s,DEFAULT_MAC:Ms,DEFAULT_COMPRESSION:Os,DISCONNECT_REASON:ze,MESSAGE:dt}=Mn(),{CIPHER_INFO:Hr,createCipher:Sm,createDecipher:wm,MAC_INFO:Xu}=Gn(),{parseDERKey:Im}=jn(),{bufferFill:Cm,bufferParser:Ge,convertSignature:vm,doFatalError:Ye,FastBuffer:km,sigSSHToASN1:Bm,writeUInt32BE:Ot}=gn(),{PacketReader:Ju,PacketWriter:Zu,ZlibPacketReader:Fs,ZlibPacketWriter:Hs}=Ca(),Or,Rm=2048,Nm=8192,Pm=Buffer.alloc(0);function ed(n){let t;if(n._compatFlags&Na.BAD_DHGEX){let e=n._offer.lists.kex,r=e.array,s=!1;for(let i=0;i<r.length;++i)r[i].includes("group-exchange")&&(s||(s=!0,r=r.slice()),r.splice(i--,1));if(s){let i=17+n._offer.totalSize+1+4,o=Buffer.from(r.join(","));i-=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(i),Ot(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]=dt.KEXINIT,bm(t,1,16),Cm(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 td(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(Ge.init(t,17),(e.kex=Ge.readList())===void 0||(e.serverHostKey=Ge.readList())===void 0||(e.cs.cipher=Ge.readList())===void 0||(e.sc.cipher=Ge.readList())===void 0||(e.cs.mac=Ge.readList())===void 0||(e.sc.mac=Ge.readList())===void 0||(e.cs.compress=Ge.readList())===void 0||(e.sc.compress=Ge.readList())===void 0||(e.cs.lang=Ge.readList())===void 0||(e.sc.lang=Ge.readList())===void 0)return Ge.clear(),Ye(n,"Received malformed KEXINIT","handshake",ze.KEY_EXCHANGE_FAILED);let r=Ge.pos(),s=r<t.length&&t[r]===1;Ge.clear();let i=n._offer,o=e,a=i.lists.kex.array;if(n._compatFlags&Na.BAD_DHGEX){let C=!1;for(let F=0;F<a.length;++F)a[F].indexOf("group-exchange")!==-1&&(C||(C=!0,a=a.slice()),a.splice(F--,1))}let c,f,l,u=n._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(n._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),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&&(u&&u("Handshake: strict KEX mode enabled"),n._decipher.inSeqno!==1)))return u&&u("Handshake: KEXINIT not first packet in strict KEX mode"),Ye(n,"Handshake failed: KEXINIT not first packet in strict KEX mode","handshake",ze.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"),Ye(n,"Handshake failed: no matching key exchange algorithm","handshake",ze.KEY_EXCHANGE_FAILED);e.kex=c[l],u&&u(`Handshake: KEX algorithm: ${c[l]}`),s&&(!o.kex.length||c[l]!==o.kex[0])&&(n._skipNextInboundPacket=!0);let p=i.lists.serverHostKey.array;for(u&&u(`Handshake: (local) Host key format: ${p}`),u&&u(`Handshake: (remote) Host key format: ${o.serverHostKey}`),n._server?(f=p,c=o.serverHostKey):(f=o.serverHostKey,c=p),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching host key format"),Ye(n,"Handshake failed: no matching host key format","handshake",ze.KEY_EXCHANGE_FAILED);e.serverHostKey=c[l],u&&u(`Handshake: Host key format: ${c[l]}`);let _=i.lists.cs.cipher.array;for(u&&u(`Handshake: (local) C->S cipher: ${_}`),u&&u(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),n._server?(f=_,c=o.cs.cipher):(f=o.cs.cipher,c=_),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S cipher"),Ye(n,"Handshake failed: no matching C->S cipher","handshake",ze.KEY_EXCHANGE_FAILED);e.cs.cipher=c[l],u&&u(`Handshake: C->S Cipher: ${c[l]}`);let E=i.lists.sc.cipher.array;for(u&&u(`Handshake: (local) S->C cipher: ${E}`),u&&u(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),n._server?(f=E,c=o.sc.cipher):(f=o.sc.cipher,c=E),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C cipher"),Ye(n,"Handshake failed: no matching S->C cipher","handshake",ze.KEY_EXCHANGE_FAILED);e.sc.cipher=c[l],u&&u(`Handshake: S->C cipher: ${c[l]}`);let b=i.lists.cs.mac.array;if(u&&u(`Handshake: (local) C->S MAC: ${b}`),u&&u(`Handshake: (remote) C->S MAC: ${o.cs.mac}`),Hr[e.cs.cipher].authLen>0)e.cs.mac="",u&&u("Handshake: C->S MAC: <implicit>");else{for(n._server?(f=b,c=o.cs.mac):(f=o.cs.mac,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 MAC"),Ye(n,"Handshake failed: no matching C->S MAC","handshake",ze.KEY_EXCHANGE_FAILED);e.cs.mac=c[l],u&&u(`Handshake: C->S MAC: ${c[l]}`)}let v=i.lists.sc.mac.array;if(u&&u(`Handshake: (local) S->C MAC: ${v}`),u&&u(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),Hr[e.sc.cipher].authLen>0)e.sc.mac="",u&&u("Handshake: S->C MAC: <implicit>");else{for(n._server?(f=v,c=o.sc.mac):(f=o.sc.mac,c=v),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C MAC"),Ye(n,"Handshake failed: no matching S->C MAC","handshake",ze.KEY_EXCHANGE_FAILED);e.sc.mac=c[l],u&&u(`Handshake: S->C MAC: ${c[l]}`)}let U=i.lists.cs.compress.array;for(u&&u(`Handshake: (local) C->S compression: ${U}`),u&&u(`Handshake: (remote) C->S compression: ${o.cs.compress}`),n._server?(f=U,c=o.cs.compress):(f=o.cs.compress,c=U),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S compression"),Ye(n,"Handshake failed: no matching C->S compression","handshake",ze.KEY_EXCHANGE_FAILED);e.cs.compress=c[l],u&&u(`Handshake: C->S compression: ${c[l]}`);let H=i.lists.sc.compress.array;for(u&&u(`Handshake: (local) S->C compression: ${H}`),u&&u(`Handshake: (remote) S->C compression: ${o.sc.compress}`),n._server?(f=H,c=o.sc.compress):(f=o.sc.compress,c=H),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C compression"),Ye(n,"Handshake failed: no matching S->C compression","handshake",ze.KEY_EXCHANGE_FAILED);e.sc.compress=c[l],u&&u(`Handshake: S->C compression: ${c[l]}`),e.cs.lang="",e.sc.lang="",n._kex&&(n._kexinit||ed(n),n._decipher._onPayload=nd.bind(n,{firstPacket:!1})),n._kex=Tm(e,n,t),n._kex.remoteExtInfoEnabled=h,n._kex.start()}var Tm=(()=>{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,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",Ye(this._protocol,u,ze.KEY_EXCHANGE_FAILED);let h=Ra(this.hashName);vn(h,c?this._remoteIdentRaw:this._identRaw),vn(h,c?this._identRaw:this._remoteIdentRaw),vn(h,c?this._remoteKexinit:this._kexinit),vn(h,c?this._kexinit:this._remoteKexinit);let p=c?this._hostKey.getPublicSSH():this._hostKey;if(vn(h,p),this.type==="groupex"){let H=this.getDHParams(),C=Buffer.allocUnsafe(4);Ot(C,this._minBits,0),h.update(C),Ot(C,this._prefBits,0),h.update(C),Ot(C,this._maxBits,0),h.update(C),vn(h,H.prime),vn(h,H.generator)}vn(h,c?l:this.getPublicKey());let _=c?this.getPublicKey():l;vn(h,_),vn(h,u);let E=h.digest();if(c){let H;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":H="sha256";break;case"rsa-sha2-512":H="sha512";break}this._protocol._debug&&this._protocol._debug("Generating signature ...");let C=this._hostKey.sign(E,H);if(C instanceof Error)return Ye(this._protocol,`Handshake failed: signature generation failed for ${this._hostKey.type} host key: ${C.message}`,"handshake",ze.KEY_EXCHANGE_FAILED);if(C=vm(C,this._hostKey.type),C===!1)return Ye(this._protocol,`Handshake failed: signature conversion failed for ${this._hostKey.type} host key`,"handshake",ze.KEY_EXCHANGE_FAILED);let F=this.negotiated.serverHostKey,V=Buffer.byteLength(F),N=4+V+4+C.length,x=this._protocol._packetRW.write.allocStartKEX,S=this._protocol._packetRW.write.alloc(5+p.length+4+_.length+4+N,!0);if(S[x]=dt.KEXDH_REPLY,Ot(S,p.length,++x),S.set(p,x+=4),Ot(S,_.length,x+=p.length),S.set(_,x+=4),Ot(S,N,x+=_.length),Ot(S,V,x+=4),S.utf8Write(F,x+=4,V),Ot(S,C.length,x+=V),S.set(C,x+=4),this._protocol._debug){let I;switch(this.type){case"group":I="KEXDH_REPLY";break;case"groupex":I="KEXDH_GEX_REPLY";break;default:I="KEXECDH_REPLY"}this._protocol._debug(`Outbound: Sending ${I}`)}this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(S,!0))}else{Ge.init(this._sig,0);let H=Ge.readString(!0);if(!H)return Ye(this._protocol,"Malformed packet while reading signature","handshake",ze.KEY_EXCHANGE_FAILED);if(H!==f.serverHostKey)return Ye(this._protocol,`Wrong signature type: ${H}, expected: ${f.serverHostKey}`,"handshake",ze.KEY_EXCHANGE_FAILED);let C=Ge.readString();if(Ge.clear(),C===void 0)return Ye(this._protocol,"Malformed packet while reading signature","handshake",ze.KEY_EXCHANGE_FAILED);if(!(C=Bm(C,H)))return Ye(this._protocol,"Malformed signature","handshake",ze.KEY_EXCHANGE_FAILED);let F;{Ge.init(this._hostKey,0);let x=Ge.readString(!0),S=this._hostKey.slice(Ge.pos());if(Ge.clear(),F=Im(S,x),F instanceof Error)return F.level="handshake",Ye(this._protocol,F,ze.KEY_EXCHANGE_FAILED)}let V;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":V="sha256";break;case"rsa-sha2-512":V="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let N=F.verify(E,C,V);if(N!==!0)return N instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${N.stack}`):this._protocol._debug&&this._protocol._debug("Signature verification failed"),Ye(this._protocol,"Handshake failed: signature verification failed","handshake",ze.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Verified signature")}(c||!a)&&Qs(this);let b,v,U=H=>{if(b)return Qs(this),b.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=Sm(b),this._protocol._packetRW.write=v,b=void 0,v=void 0,this._protocol._onHandshakeComplete(f),!1;this.sessionID||(this.sessionID=E);{let te=Buffer.allocUnsafe(4+u.length);Ot(te,u.length,0),te.set(u,4),u=te}let C=Hr[f.cs.cipher],F=Hr[f.sc.cipher],V=Fr(C.ivLen,this.hashName,u,E,this.sessionID,"A"),N=Fr(F.ivLen,this.hashName,u,E,this.sessionID,"B"),x=Fr(C.keyLen,this.hashName,u,E,this.sessionID,"C"),S=Fr(F.keyLen,this.hashName,u,E,this.sessionID,"D"),I,k;C.authLen||(I=Xu[f.cs.mac],k=Fr(I.len,this.hashName,u,E,this.sessionID,"E"));let R,ne;F.authLen||(R=Xu[f.sc.mac],ne=Fr(R.len,this.hashName,u,E,this.sessionID,"F"));let z={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?C:F,decipherIV:c?V:N,decipherKey:c?x:S,macInfo:c?I:R,macKey:c?k:ne},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?F:C,cipherIV:c?N:V,cipherKey:c?S:x,macInfo:c?R:I,macKey:c?ne:k}};this._protocol._decipher.free(),b=z,this._protocol._decipher=wm(z);let Y={read:void 0,write:void 0};switch(f.cs.compress){case"zlib":c?Y.read=new Fs:Y.write=new Hs(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Y.read=new Fs:Y.write=new Hs(this._protocol);break}default:c?Y.read=new Ju:Y.write=new Zu(this._protocol)}switch(f.sc.compress){case"zlib":c?Y.write=new Hs(this._protocol):Y.read=new Fs;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Y.write=new Hs(this._protocol):Y.read=new Fs;break}default:c?Y.write=new Zu(this._protocol):Y.read=new Ju}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=Y.read,v=Y.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,H?!1:U()};if((c||a)&&(this.finish=U),!c)return U(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]=dt.KEXDH_INIT,Ot(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 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!==dt.KEXDH_INIT)return Ye(this._protocol,`Received packet ${c} instead of ${dt.KEXDH_INIT}`,"handshake",ze.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Init"),Ge.init(a,1);let f=Ge.readString();if(Ge.clear(),f===void 0)return Ye(this._protocol,"Received malformed KEX*_INIT","handshake",ze.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!==dt.KEXDH_REPLY)return Ye(this._protocol,`Received packet ${c} instead of ${dt.KEXDH_REPLY}`,"handshake",ze.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ge.init(a,1);let f,l,u;if((f=Ge.readString())===void 0||(l=Ge.readString())===void 0||(u=Ge.readString())===void 0)return Ge.clear(),Ye(this._protocol,"Received malformed KEX*_REPLY","handshake",ze.KEY_EXCHANGE_FAILED);Ge.clear(),Ge.init(f,0);let h=Ge.readString(!0);if(Ge.clear(),h===void 0)return Ye(this._protocol,"Received malformed host public key","handshake",ze.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 Ye(this._protocol,"Host key does not match negotiated type","handshake",ze.KEY_EXCHANGE_FAILED)}this._hostKey=f,this._dhData=l,this._sig=u;let p=!1,_;if(this._protocol._hostVerifier===void 0?(_=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):_=this._protocol._hostVerifier(f,E=>{if(!p){if(p=!0,E===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ye(this._protocol,"Host denied (verification failed)","handshake",ze.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,this._receivedNEWKEYS?this.finish():Qs(this)}}),_===void 0){++this._step;return}if(p=!0,_===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ye(this._protocol,"Host denied (verification failed)","handshake",ze.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,Qs(this)}++this._step;break;case 2:return c!==dt.NEWKEYS?Ye(this._protocol,`Received packet ${c} instead of ${dt.NEWKEYS}`,"handshake",ze.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",ze.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=_m("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 zu.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(zu.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(ym({privateKey:this._keys.privateKey,publicKey:Em({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=Am(this.curveName),this._public=this._dh.generateKeys())}}class s extends t{constructor(a,...c){super(...c),this.type="groupex",this.hashName=a,this._prime=null,this._generator=null,this._minBits=Rm,this._prefBits=Lm(this.negotiated),this._protocol._compatFlags&Na.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=Nm}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]=dt.KEXDH_GEX_REQUEST,Ot(c,this._minBits,++a),Ot(c,this._prefBits,a+=4),Ot(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=gm(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!==dt.KEXDH_GEX_REQUEST?Ye(this._protocol,`Received packet ${c} instead of `+dt.KEXDH_GEX_REQUEST,"handshake",ze.KEY_EXCHANGE_FAILED):Ye(this._protocol,"Group exchange not implemented for server","handshake",ze.KEY_EXCHANGE_FAILED);if(c!==dt.KEXDH_GEX_GROUP)return Ye(this._protocol,`Received packet ${c} instead of ${dt.KEXDH_GEX_GROUP}`,"handshake",ze.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ge.init(a,1);let f,l;if((f=Ge.readString())===void 0||(l=Ge.readString())===void 0)return Ge.clear(),Ye(this._protocol,"Received malformed KEXDH_GEX_GROUP","handshake",ze.KEY_EXCHANGE_FAILED);Ge.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,p=this._protocol._packetRW.write.alloc(5+u.length,!0);p[h]=dt.KEXDH_GEX_INIT,Ot(p,u.length,++h),p.set(u,h+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(p,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==dt.KEXDH_GEX_INIT?Ye(this._protocol,`Received packet ${c} instead of ${dt.KEXDH_GEX_INIT}`,"handshake",ze.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Received DH GEX Init"),Ye(this._protocol,"Group exchange not implemented for server","handshake",ze.KEY_EXCHANGE_FAILED));if(c!==dt.KEXDH_GEX_REPLY)return Ye(this._protocol,`Received packet ${c} instead of ${dt.KEXDH_GEX_REPLY}`,"handshake",ze.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=dt.KEXDH_REPLY,this.parse=t.prototype.parse,this.parse(a)}}}class i 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]=dt.KEXDH_INIT,Ot(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=mm(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(!xm)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 i("modp2","sha1",...a);case"diffie-hellman-group14-sha1":return new i("modp14","sha1",...a);case"diffie-hellman-group14-sha256":return new i("modp14","sha256",...a);case"diffie-hellman-group15-sha512":return new i("modp15","sha512",...a);case"diffie-hellman-group16-sha512":return new i("modp16","sha512",...a);case"diffie-hellman-group17-sha512":return new i("modp17","sha512",...a);case"diffie-hellman-group18-sha512":return new i("modp18","sha512",...a);case"diffie-hellman-group-exchange-sha1":return new s("sha1",...a);case"diffie-hellman-group-exchange-sha256":return new s("sha256",...a)}throw new Error(`Unsupported key exchange algorithm: ${c}`)}throw new Error(`Invalid key exchange type: ${c}`)}})(),Ba=(()=>{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},s=0;for(let a of n){let c,f,l,u;if(typeof a=="string")c=r,f=e[a],l=u=a;else{let p=a[0];c=r[p],u=a[1],f=e[p][u],l=`${p}.${u}`}let h={array:void 0,buffer:void 0};if(Buffer.isBuffer(f))h.array=(""+f).split(","),h.buffer=f,s+=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}`);s+=4+h.buffer.length}c[u]=h}let i=Buffer.allocUnsafe(s);r.all=i;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=Ot(i,c.length,o),i.set(c,o),o+=c.length}this.totalSize=s,this.lists=r}copyAllTo(e,r){let s=this.lists.all;if(typeof r!="number")throw new TypeError(`Invalid offset value: ${typeof r}`);if(e.length-r<s.length)throw new Error("Insufficient space to copy list");return e.set(s,r),s.length}}})(),vn=(()=>{let n=Buffer.allocUnsafe(4);return(t,e)=>{Ot(n,e.length,0),t.update(n),t.update(e)}})();function Fr(n,t,e,r,s,i){let o;if(n){let a=Ra(t).update(e).update(r).update(i).update(s).digest();for(;a.length<n;){let c=Ra(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 km(a.buffer,a.byteOffset,n)}else o=Pm;return o}function nd(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 dt.IGNORE:case dt.UNIMPLEMENTED:case dt.DEBUG:return Or||(Or=Ds()),Or[e](this,t)}switch(e){case dt.DISCONNECT:return Or||(Or=Ds()),Or[e](this,t);case dt.KEXINIT:return n.firstPacket?(n.firstPacket=!1,td(this,t)):Ye(this,"Received extra KEXINIT during handshake","handshake",ze.KEY_EXCHANGE_FAILED);default:if(e<20||e>49)return Ye(this,`Received unexpected packet type ${e}`,"handshake",ze.KEY_EXCHANGE_FAILED)}return this._kex.parse(t)}function Lm(n){let t=Hr[n.cs.cipher],e=Hr[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 Qs(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]=dt.NEWKEYS,n._protocol._cipher.encrypt(n._protocol._packetRW.write.finalize(e,!0)),n._sentNEWKEYS=!0,n._protocol._strictMode&&(n._protocol._cipher.outSeqno=0)}}rd.exports={KexInit:Ba,kexinit:ed,onKEXPayload:nd,DEFAULT_KEXINIT_CLIENT:new Ba({kex:Yu.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:ju,cs:{cipher:$s,mac:Ms,compress:Os,lang:[]},sc:{cipher:$s,mac:Ms,compress:Os,lang:[]}}),DEFAULT_KEXINIT_SERVER:new Ba({kex:Yu.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:ju,cs:{cipher:$s,mac:Ms,compress:Os,lang:[]},sc:{cipher:$s,mac:Ms,compress:Os,lang:[]}}),HANDLERS:{[dt.KEXINIT]:td}}});var id=ct((Zx,Dm)=>{Dm.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 Da=ct((eS,Ad)=>{"use strict";var{inspect:ld}=require("util"),{bindingAvailable:Um,NullCipher:$m,NullDecipher:Mm}=Gn(),{COMPAT_CHECKS:Om,DISCONNECT_REASON:ud,eddsaSupported:Fm,MESSAGE:Se,SIGNALS:sd,TERMINAL_MODE:Ta}=Mn(),{DEFAULT_KEXINIT_CLIENT:Hm,DEFAULT_KEXINIT_SERVER:Qm,KexInit:od,kexinit:dd,onKEXPayload:Wm}=Us(),{parseKey:ad}=jn(),qm=Ds(),{bufferCopy:Ws,bufferFill:Km,bufferSlice:hd,convertSignature:cd,sendPacket:we,writeUInt32BE:P}=gn(),{PacketReader:Vm,PacketWriter:Gm,ZlibPacketReader:pd,ZlibPacketWriter:gd}=Ca(),zm=id().version,Ym=new Map(Object.values(ud).map(n=>[n,1])),md=Buffer.from(`SSH-2.0-ssh2js${zm}`),jm=Buffer.from(`${md}\r
7
- `),Xm=8192,Jm=1024,fd=Buffer.from([Se.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]),Zm=Buffer.from([Ta.TTY_OP_END]);function Pa(){}var La=class{constructor(t){let e=t.onWrite;if(typeof e!="function")throw new Error("Missing onWrite function");this._onWrite=p=>{e(p)};let r=t.onError;if(typeof r!="function")throw new Error("Missing onError function");this._onError=p=>{r(p)};let s=t.debug;this._debug=typeof s=="function"?p=>{s(p)}:void 0;let i=t.onHeader;this._onHeader=typeof i=="function"?(...p)=>{i(...p)}:Pa;let o=t.onPacket;this._onPacket=typeof o=="function"?()=>{o()}:Pa;let a=t.onHandshakeComplete;typeof a!="function"&&(a=Pa);let c;this._onHandshakeComplete=(...p)=>{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 E=0;E<_.length;++E){let b=_[E],v=this._packetRW.write.finalize(b);if(v===b){let U=this._cipher.allocPacket(b.length);U.set(b,5),v=U}we(this,v)}this._debug&&this._debug("... finished draining outbound queue")}c&&this._server&&this._kex.remoteExtInfoEnabled&&o0(this),a(...p)},this._queue=void 0;let f=t.messageHandlers;typeof f=="object"&&f!==null?this._handlers=f:this._handlers={},this._onPayload=r0.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
6
+ ${e}-----END ${n} KEY-----`}function ki(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return e.set(n,0),e.set(t,n.length),e}function ya(n,t){let e=n.length,r=n._pos||0;for(let s=0;s<t;++s){let i=e-r;if(r>=e||i<4)return!1;let o=wi(n,r);if(i<4+o)return!1;r+=4+o}return n._pos=r,!0}function vi(n,t){let e=new Ne.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.113549.1.1.1"),e.writeNull(),e.endSequence(),e.startSequence(Ne.BitString),e.writeByte(0),e.startSequence(),e.writeBuffer(n,Ne.Integer),e.writeBuffer(t,Ne.Integer),e.endSequence(),e.endSequence(),e.endSequence(),Sn("PUBLIC",e.buffer)}function Bi(n,t){let e=Buffer.allocUnsafe(15+t.length+4+n.length);Ft(e,7,0),e.utf8Write("ssh-rsa",4,7);let r=11;return Ft(e,t.length,r),e.set(t,r+=4),Ft(e,n.length,r+=t.length),e.set(n,r+4),e}var Ru=(()=>{function n(r,s,i,o,a,c,l,f){let u=new Ne.Writer;return u.startSequence(),u.writeInt(0,Ne.Integer),u.writeBuffer(r,Ne.Integer),u.writeBuffer(s,Ne.Integer),u.writeBuffer(i,Ne.Integer),u.writeBuffer(o,Ne.Integer),u.writeBuffer(a,Ne.Integer),u.writeBuffer(c,Ne.Integer),u.writeBuffer(l,Ne.Integer),u.writeBuffer(f,Ne.Integer),u.endSequence(),u.buffer}function t(r){return BigInt(`0x${r.hexSlice(0,r.length)}`)}function e(r){let s=r.toString(16);if((s.length&1)!==0)s=`0${s}`;else{let i=s.charCodeAt(0);(i===56||i===57||i>=97&&i<=102)&&(s=`00${s}`)}return Buffer.from(s,"hex")}return function(s,i,o,a,c,l){let f=t(o),u=e(f%(t(c)-1n)),h=e(f%(t(l)-1n));return Sn("RSA PRIVATE",n(s,i,o,c,l,u,h,a))}})();function Ri(n,t,e,r){let s=new Ne.Writer;return s.startSequence(),s.startSequence(),s.writeOID("1.2.840.10040.4.1"),s.startSequence(),s.writeBuffer(n,Ne.Integer),s.writeBuffer(t,Ne.Integer),s.writeBuffer(e,Ne.Integer),s.endSequence(),s.endSequence(),s.startSequence(Ne.BitString),s.writeByte(0),s.writeBuffer(r,Ne.Integer),s.endSequence(),s.endSequence(),Sn("PUBLIC",s.buffer)}function Ni(n,t,e,r){let s=Buffer.allocUnsafe(15+n.length+4+t.length+4+e.length+4+r.length);Ft(s,7,0),s.utf8Write("ssh-dss",4,7);let i=11;return Ft(s,n.length,i),s.set(n,i+=4),Ft(s,t.length,i+=n.length),s.set(t,i+=4),Ft(s,e.length,i+=t.length),s.set(e,i+=4),Ft(s,r.length,i+=e.length),s.set(r,i+4),s}function Nu(n,t,e,r,s){let i=new Ne.Writer;return i.startSequence(),i.writeInt(0,Ne.Integer),i.writeBuffer(n,Ne.Integer),i.writeBuffer(t,Ne.Integer),i.writeBuffer(e,Ne.Integer),i.writeBuffer(r,Ne.Integer),i.writeBuffer(s,Ne.Integer),i.endSequence(),Sn("DSA PRIVATE",i.buffer)}function Pu(n){let t=new Ne.Writer;return t.startSequence(),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Ne.BitString),t.writeByte(0),t._ensure(n.length),t._buf.set(n,t._offset),t._offset+=n.length,t.endSequence(),t.endSequence(),Sn("PUBLIC",t.buffer)}function Tu(n){let t=Buffer.allocUnsafe(19+n.length);return Ft(t,11,0),t.utf8Write("ssh-ed25519",4,11),Ft(t,n.length,15),t.set(n,19),t}function am(n){let t=new Ne.Writer;return t.startSequence(),t.writeInt(0,Ne.Integer),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Ne.OctetString),t.writeBuffer(n,Ne.OctetString),t.endSequence(),t.endSequence(),Sn("PRIVATE",t.buffer)}function Ea(n,t){let e=new Ne.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.10045.2.1"),e.writeOID(n),e.endSequence(),e.startSequence(Ne.BitString),e.writeByte(0),e._ensure(t.length),e._buf.set(t,e._offset),e._offset+=t.length,e.endSequence(),e.endSequence(),Sn("PUBLIC",e.buffer)}function _a(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 Ft(r,19,0),r.utf8Write(`ecdsa-sha2-${e}`,4,19),Ft(r,8,23),r.utf8Write(e,27,8),Ft(r,t.length,35),r.set(t,39),r}function cm(n,t,e){let r=new Ne.Writer;return r.startSequence(),r.writeInt(1,Ne.Integer),r.writeBuffer(e,Ne.OctetString),r.startSequence(160),r.writeOID(n),r.endSequence(),r.startSequence(161),r.startSequence(Ne.BitString),r.writeByte(0),r._ensure(t.length),r._buf.set(t,r._offset),r._offset+=t.length,r.endSequence(),r.endSequence(),r.endSequence(),Sn("EC PRIVATE",r.buffer)}function lm(n,t){let e=Jg(n);return e.setPrivateKey(t),e.getPublicKey()}var Pi={sign:typeof vu=="function"?function(t,e){let r=this[bn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Hn]);try{return vu(e,t,r)}catch(s){return s}}:function(t,e){let r=this[bn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Hn]);let s=em(e);s.update(t);try{return s.sign(r)}catch(i){return i}},verify:typeof Bu=="function"?function(t,e,r){let s=this[Bn];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Hn]);try{return Bu(r,t,s,e)}catch(i){return i}}:function(t,e,r){let s=this[Bn];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Hn]);let i=tm(r);i.update(t);try{return i.verify(s,e)}catch(o){return o}},isPrivateKey:function(){return this[bn]!==null},getPrivatePEM:function(){return this[bn]},getPublicPEM:function(){return this[Bn]},getPublicSSH:function(){return this[Zn]},equals:function(t){let e=Du(t);return e instanceof Error?!1:this.type===e.type&&this[bn]===e[bn]&&this[Bn]===e[Bn]&&this[Zn].equals(e[Zn])}};function Ls(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[bn]=e,this[Bn]=r,this[Zn]=s,this[Hn]=i,this[Fr]=o}Ls.prototype=Pi;{let t=function(e,r,s){let i=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=wi(e,0),a=wi(e,4);if(o!==a)return s?new Error("OpenSSH key integrity check failed -- bad passphrase?"):new Error("OpenSSH key integrity check failed");e._pos=8;let c,l;for(c=0;c<r;++c){let u,h,p,A,E=ve(e,e._pos,!0);if(E===void 0)return new Error("Malformed OpenSSH private key");switch(E){case"ssh-rsa":{let x=ve(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let R=ve(e,e._pos);if(R===void 0)return new Error("Malformed OpenSSH private key");let H=ve(e,e._pos);if(H===void 0)return new Error("Malformed OpenSSH private key");let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let U=ve(e,e._pos);if(U===void 0)return new Error("Malformed OpenSSH private key");let Q=ve(e,e._pos);if(Q===void 0)return new Error("Malformed OpenSSH private key");p=vi(x,R),A=Bi(x,R),h=Ru(x,R,H,C,U,Q),u="sha1";break}case"ssh-dss":{let x=ve(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let R=ve(e,e._pos);if(R===void 0)return new Error("Malformed OpenSSH private key");let H=ve(e,e._pos);if(H===void 0)return new Error("Malformed OpenSSH private key");let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let U=ve(e,e._pos);if(U===void 0)return new Error("Malformed OpenSSH private key");p=Ri(x,R,H,C),A=Ni(x,R,H,C),h=Nu(x,R,H,C,U),u="sha1";break}case"ssh-ed25519":{if(!Aa)return new Error(`Unsupported OpenSSH private key type: ${E}`);let x=ve(e,e._pos);if(x===void 0||x.length!==32)return new Error("Malformed OpenSSH private key");let R=ve(e,e._pos);if(R===void 0||R.length!==64)return new Error("Malformed OpenSSH private key");p=Pu(x),A=Tu(x),h=am(pr(R,0,32)),u=null;break}case"ecdsa-sha2-nistp256":u="sha256",l="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":u===void 0&&(u="sha384",l="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(u===void 0&&(u="sha512",l="1.3.132.0.35"),!ya(e,1))return new Error("Malformed OpenSSH private key");let x=ve(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let R=ve(e,e._pos);if(R===void 0)return new Error("Malformed OpenSSH private key");p=Ea(l,x),A=_a(l,x),h=cm(l,x,R);break}default:return new Error(`Unsupported OpenSSH private key type: ${E}`)}let S=ve(e,e._pos,!0);if(S===void 0)return new Error("Malformed OpenSSH private key");i.push(new Ls(E,S,h,p,A,u,s))}let f=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++f%255)return new Error("Malformed OpenSSH private key");return i},n=/^-----BEGIN OPENSSH PRIVATE KEY-----(?:\r\n|\n)([\s\S]+)(?:\r\n|\n)-----END OPENSSH PRIVATE KEY-----$/;Ls.parse=(e,r)=>{let s=n.exec(e);if(s===null)return null;let i,o=Buffer.from(s[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=ve(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&sm.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let l=ve(o,o._pos,!0);if(l===void 0)return new Error("Malformed OpenSSH private key");if(l!=="none"){if(c==="none")return new Error("Malformed OpenSSH private key");if(l!=="bcrypt")return new Error(`Unsupported kdf name for OpenSSH key: ${l}`);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 f,u,h;c!=="none"&&(f=Ci[c]);let p=ve(o,o._pos);if(p===void 0)return new Error("Malformed OpenSSH private key");if(p.length)switch(l){case"none":return new Error("Malformed OpenSSH private key");case"bcrypt":{let E=ve(p,0);if(E===void 0||p._pos+4>p.length)return new Error("Malformed OpenSSH private key");let S=wi(p,p._pos),x=Buffer.allocUnsafe(f.keyLen+f.ivLen);if(im(r,r.length,E,E.length,x,x.length,S)!==0)return new Error("Failed to generate information to decrypt key");u=pr(x,0,f.keyLen),h=pr(x,f.keyLen,x.length);break}}else if(l!=="none")return new Error("Malformed OpenSSH private key");if(o._pos+3>=o.length)return new Error("Malformed OpenSSH private key");let A=wi(o,o._pos);if(o._pos+=4,A>0){for(let S=0;S<A;++S){let x=ve(o,o._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");if(ve(x,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let E=ve(o,o._pos);if(E===void 0)return new Error("Malformed OpenSSH private key");if(u!==void 0){if(E.length<f.blockLen||E.length%f.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let S={authTagLength:f.authLen},x=ma(f.sslName,u,h,S);if(x.setAutoPadding(!1),f.authLen>0){if(o.length-o._pos<f.authLen)return new Error("Malformed OpenSSH private key");x.setAuthTag(pr(o,o._pos,o._pos+=f.authLen))}E=ki(x.update(E),x.final())}catch(S){return S}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");i=t(E,A,u!==void 0)}else i=[];return i instanceof Error?i:i[0]}}function $s(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[bn]=e,this[Bn]=r,this[Zn]=s,this[Hn]=i,this[Fr]=o}$s.prototype=Pi;{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-----$/;$s.parse=(t,e)=>{let r=n.exec(t);if(r===null)return null;let s=Buffer.from(r[3],"base64"),i=r[2],o=!1;if(i!==void 0){i=i.split(/\r\n|\n/g);for(let A=0;A<i.length;++A){let E=i[A],S=E.indexOf(":");if(E.slice(0,S)==="DEK-Info"){let x=E.slice(S+2);if(S=x.indexOf(","),S===-1)continue;let R=x.slice(0,S).toLowerCase();if(rm.indexOf(R)===-1)return new Error(`Cipher (${R}) not supported for encrypted OpenSSH private key`);let H=ga[R];if(!H)return new Error(`Cipher (${R}) not supported for encrypted OpenSSH private key`);let C=Buffer.from(x.slice(S+1),"hex");if(C.length!==H.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let U=pr(C,0,8),Q=Ii("md5").update(e).update(U).digest();for(;Q.length<H.keyLen;)Q=ki(Q,Ii("md5").update(Q).update(e).update(U).digest());Q.length>H.keyLen&&(Q=pr(Q,0,H.keyLen));try{let B=ma(R,Q,C);B.setAutoPadding(!1),s=ki(B.update(s),B.final()),o=!0}catch(B){return B}}}}let a,c,l,f,u,h,p="Malformed OpenSSH private key";switch(o&&(p+=". Bad passphrase?"),r[1]){case"RSA":a="ssh-rsa",c=Sn("RSA PRIVATE",s);try{h=new Ne.Reader(s),h.readSequence(),h.readInt();let A=h.readString(Ne.Integer,!0);if(A===null)return new Error(p);let E=h.readString(Ne.Integer,!0);if(E===null)return new Error(p);l=vi(A,E),f=Bi(A,E)}catch{return new Error(p)}u="sha1";break;case"DSA":a="ssh-dss",c=Sn("DSA PRIVATE",s);try{h=new Ne.Reader(s),h.readSequence(),h.readInt();let A=h.readString(Ne.Integer,!0);if(A===null)return new Error(p);let E=h.readString(Ne.Integer,!0);if(E===null)return new Error(p);let S=h.readString(Ne.Integer,!0);if(S===null)return new Error(p);let x=h.readString(Ne.Integer,!0);if(x===null)return new Error(p);l=Ri(A,E,S,x),f=Ni(A,E,S,x)}catch{return new Error(p)}u="sha1";break;case"EC":{let A,E,S;try{h=new Ne.Reader(s),h.readSequence(),h.readInt(),E=h.readString(Ne.OctetString,!0),h.readByte();let R=h.readLength();if(R!==null){if(h._offset=R,S=h.readOID(),S===null)return new Error(p);switch(S){case"1.2.840.10045.3.1.7":A="prime256v1",a="ecdsa-sha2-nistp256",u="sha256";break;case"1.3.132.0.34":A="secp384r1",a="ecdsa-sha2-nistp384",u="sha384";break;case"1.3.132.0.35":A="secp521r1",a="ecdsa-sha2-nistp521",u="sha512";break;default:return new Error(`Unsupported private key EC OID: ${S}`)}}else return new Error(p)}catch{return new Error(p)}c=Sn("EC PRIVATE",s);let x=lm(A,E);l=Ea(S,x),f=_a(S,x);break}}return new $s(a,"",c,l,f,u,o)}}function Ds(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[bn]=e,this[Bn]=r,this[Zn]=s,this[Hn]=i,this[Fr]=o}Ds.prototype=Pi;{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]),s=/^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]+)/;Ds.parse=(i,o)=>{let a=s.exec(i);if(a===null)return null;let c=a[2],l=c!=="none";if(l&&!o)return new Error("Encrypted PPK private key detected, but no passphrase given");let f=Buffer.from(a[5],"base64");if(l){let k=Ci[c],v=ki(Ii("sha1").update(e).update(o).digest(),Ii("sha1").update(r).update(o).digest());v.length>k.keyLen&&(v=pr(v,0,k.keyLen));try{let P=ma(k.sslName,v,t);P.setAutoPadding(!1),f=ki(P.update(f),P.final())}catch(P){return P}}let u=a[1],h=a[3],p=Buffer.from(a[4],"base64"),A=a[6],E=u.length,S=c.length,x=Buffer.byteLength(h),R=p.length,H=f.length,C=Buffer.allocUnsafe(4+E+4+S+4+x+4+R+4+H),U=0;if(Ft(C,E,U),C.utf8Write(u,U+=4,E),Ft(C,S,U+=E),C.utf8Write(c,U+=4,S),Ft(C,x,U+=S),C.utf8Write(h,U+=4,x),Ft(C,R,U+=x),C.set(p,U+=4),Ft(C,H,U+=R),C.set(f,U+4),o||(o=n),Zg("sha1",Ii("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(C).digest("hex")!==A)return l?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let B,b,w;switch(p._pos=0,ya(p,1),u){case"ssh-rsa":{let k=ve(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let v=ve(p,p._pos);if(v===void 0)return new Error("Malformed PPK public key");let P=ve(f,0);if(P===void 0)return new Error("Malformed PPK private key");let ne=ve(f,f._pos);if(ne===void 0)return new Error("Malformed PPK private key");let G=ve(f,f._pos);if(G===void 0)return new Error("Malformed PPK private key");let Y=ve(f,f._pos);if(Y===void 0)return new Error("Malformed PPK private key");B=vi(v,k),b=Bi(v,k),w=Ru(v,k,P,Y,ne,G);break}case"ssh-dss":{let k=ve(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let v=ve(p,p._pos);if(v===void 0)return new Error("Malformed PPK public key");let P=ve(p,p._pos);if(P===void 0)return new Error("Malformed PPK public key");let ne=ve(p,p._pos);if(ne===void 0)return new Error("Malformed PPK public key");let G=ve(f,0);if(G===void 0)return new Error("Malformed PPK private key");B=Ri(k,v,P,ne),b=Ni(k,v,P,ne),w=Nu(k,v,P,ne,G);break}}return new Ds(u,h,w,B,b,"sha1",l)}}function Ms(n,t,e,r,s){this.type=n,this.comment=t,this[bn]=null,this[Bn]=e,this[Zn]=r,this[Hn]=s,this[Fr]=!1}Ms.prototype=Pi;{let n;Aa?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].*)?)$/,Ms.parse=t=>{let e=n.exec(t);if(e===null)return null;let r=e[1],s=e[2],i=Buffer.from(e[3],"base64"),o=e[4]||"",a=ve(i,i._pos,!0);return a===void 0||a.indexOf(s)!==0?new Error("Malformed OpenSSH public key"):ba(i,s,o,r)}}function Us(n,t,e,r,s){this.type=n,this.comment=t,this[bn]=null,this[Bn]=e,this[Zn]=r,this[Hn]=s,this[Fr]=!1}Us.prototype=Pi;{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;Us.parse=s=>{let i=n.exec(s);if(i===null)return null;let o=i[1],a=0,c="";for(;i=e.exec(o);){let p=i[1],A=i[2].replace(r,"");if(A.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,p.toLowerCase()==="comment"&&(c=A,c.length>1&&c.charCodeAt(0)===34&&c.charCodeAt(c.length-1)===34&&(c=c.slice(1,-1)))}let l=o.slice(a);if(!t.test(l))return new Error("Malformed RFC4716 public key");l=Buffer.from(l,"base64");let f=ve(l,0,!0);if(f===void 0)return new Error("Malformed RFC4716 public key");let u=null,h=null;switch(f){case"ssh-rsa":{let p=ve(l,l._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let A=ve(l,l._pos);if(A===void 0)return new Error("Malformed RFC4716 public key");u=vi(A,p),h=Bi(A,p);break}case"ssh-dss":{let p=ve(l,l._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let A=ve(l,l._pos);if(A===void 0)return new Error("Malformed RFC4716 public key");let E=ve(l,l._pos);if(E===void 0)return new Error("Malformed RFC4716 public key");let S=ve(l,l._pos);if(S===void 0)return new Error("Malformed RFC4716 public key");u=Ri(p,A,E,S),h=Ni(p,A,E,S);break}default:return new Error("Malformed RFC4716 public key")}return new Us(f,c,u,h,"sha1")}}function ba(n,t,e,r){if(!Lu(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let s,i,o=null,a=null;switch(t){case"ssh-rsa":{let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let l=ve(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");o=vi(l,c),a=Bi(l,c),s="sha1";break}case"ssh-dss":{let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let l=ve(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");let f=ve(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");let u=ve(n,n._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");o=Ri(c,l,f,u),a=Ni(c,l,f,u),s="sha1";break}case"ssh-ed25519":{let c=ve(n,n._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=Pu(c),a=Tu(c),s=null;break}case"ecdsa-sha2-nistp256":s="sha256",i="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":s===void 0&&(s="sha384",i="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(s===void 0&&(s="sha512",i="1.3.132.0.35"),!ya(n,1))return new Error("Malformed OpenSSH public key");let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=Ea(i,c),a=_a(i,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new Ms(r,e,o,a,s)}function Lu(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(Aa)return!0;default:return!1}}function $u(n){return n?typeof n[Fr]=="boolean":!1}function Du(n,t){if($u(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=Ls.parse(n,t))!==null||(r=$s.parse(n,t))!==null||(r=Ds.parse(n,t))!==null||(r=Ms.parse(n))!==null||(r=Us.parse(n))!==null)return r;if(e){Ts.init(e,0);let s=Ts.readString(!0);s!==void 0&&(n=Ts.readRaw(),n!==void 0&&(r=ba(n,s,"",s),r instanceof Error&&(r=null))),Ts.clear()}return r||new Error("Unsupported key format")}Uu.exports={isParsedKey:$u,isSupportedKeyType:Lu,parseDERKey:(n,t)=>ba(n,t,"",t),parseKey:Du}});var ka=lt((mx,zu)=>{"use strict";var{Socket:Hu}=require("net"),{Duplex:Qu}=require("stream"),{resolve:fm}=require("path"),{readFile:Mu}=require("fs"),{execFile:um,spawn:dm}=require("child_process"),{isParsedKey:Ou,parseKey:Ti}=er(),{makeBufferParser:hm,readUInt32BE:Ca,writeUInt32BE:tn,writeUInt32LE:Fu}=_n();function Li(n){let t=!1;return(...e)=>{t||(t=!0,n(...e))}}function pm(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return n.copy(e,0),t.copy(e,n.length),e}function xa(){}var gm=Buffer.alloc(0),wt=hm(),$i=class{getIdentities(t){t(new Error("Missing getIdentities() implementation"))}sign(t,e,r,s){typeof r=="function"&&(s=r),s(new Error("Missing sign() implementation"))}},Qr=class extends $i{constructor(t){super(),this.socketPath=t}getStream(t){t=Li(t);let e=new Hu;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=Li(t),this.getStream((e,r)=>{function s(o){if(r)try{r.destroy()}catch{}o||(o=new Error("Failed to retrieve identities from agent")),t(o)}if(e)return s(e);let i=new wa(!0);i.on("error",s),i.pipe(r).pipe(i),r.on("close",s).on("end",s).on("error",s),i.getIdentities((o,a)=>{if(o)return s(o);try{r.destroy()}catch{}t(null,a)})})}sign(t,e,r,s){typeof r=="function"?(s=r,r=void 0):(typeof r!="object"||r===null)&&(r=void 0),s=Li(s),this.getStream((i,o)=>{function a(l){if(o)try{o.destroy()}catch{}l||(l=new Error("Failed to sign data with agent")),s(l)}if(i)return a(i);let c=new wa(!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,(l,f)=>{if(l)return a(l);try{o.destroy()}catch{}s(null,f)})})}},Wu=(()=>{let o=fm(__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(f){f.buffer=null,f.proc&&(f.proc.kill(),f.proc=void 0)}class l extends Qu{constructor(){super(),this.proc=void 0,this.buffer=null}_read(u){}_write(u,h,p){if(this.buffer===null)this.buffer=u;else{let x=Buffer.allocUnsafe(this.buffer.length+u.length);this.buffer.copy(x,0),u.copy(x,this.buffer.length),this.buffer=x}if(this.buffer.length<4)return p();let A=Ca(this.buffer,0);if(this.buffer.length-4<A)return p();if(u=this.buffer.slice(0,4+A),this.buffer.length>4+A)return p(new Error("Unexpected multiple agent requests"));this.buffer=null;let E,S=this.proc=dm(o,[u.length]);S.stdout.on("data",x=>{this.push(x)}),S.on("error",x=>{E=x,p(E)}),S.on("close",x=>{if(this.proc=void 0,!E){if(E=a[x])return p(E);p()}}),S.stdin.end(u)}_final(u){c(this),u()}_destroy(u,h){c(this),h()}}return class extends Qr{getStream(u){u(null,new l)}}})(),qu=(()=>{let n=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends Qr{getStream(e){e=Li(e);let r=this.socketPath,s=!1;Mu(r,function i(o,a){if(o){if(s)return e(new Error("Invalid cygwin unix socket path"));um("cygpath",["-w",r],(Q,B,b)=>{if(Q||B.length===0)return e(new Error("Invalid cygwin unix socket path"));s=!0,r=B.toString().replace(/[\r\n]/g,""),Mu(r,i)});return}let c=n.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let l,f=0,u=!1,h=[],p,A=Buffer.alloc(12),E=parseInt(c[1],10),S=c[2].replace(/-/g,""),x=Buffer.allocUnsafe(16);for(let Q=0,B=0;B<32;++Q,B+=2)x[Q]=parseInt(S.substring(B,B+2),16);for(let Q=0;Q<16;Q+=4)Fu(x,Ca(x,Q),Q);U();function R(){f=0,l="secret",p.write(x)}function H(Q){if(f+=Q.length,l==="secret"){f===16&&(f=0,l="creds",p.write(A));return}if(l==="creds"&&(u||h.push(Q),f===12)){if(p.removeListener("connect",R),p.removeListener("data",H),p.removeListener("error",C),p.removeListener("end",C),p.removeListener("close",C),u)return e(null,p);u=!0,A=Buffer.concat(h),Fu(A,process.pid,0),p.on("error",()=>{}),p.destroy(),U()}}function C(){e(new Error("Problem negotiating cygwin unix socket security"))}function U(){p=new Hu,p.on("connect",R),p.on("data",H),p.on("error",C),p.on("end",C),p.on("close",C),p.connect(E)}})}}})(),mm=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function Ku(n){return process.platform==="win32"&&!mm.test(n)?n==="pageant"?new Wu:new qu(n):new Qr(n)}var wa=(()=>{function l(b){let w;for(;b[R].length;){let k=b[R][0][u];if(k===void 0)break;b[R].shift(),w=b.push(k)}return w}let f=Symbol("Inbound Request Type"),u=Symbol("Inbound Request Response"),h=Symbol("Inbound Request Context");class p{constructor(w,k){this[f]=w,this[u]=void 0,this[h]=k}hasResponded(){return this[u]!==void 0}getType(){return this[f]}getContext(){return this[h]}}function A(b,w,k){return w[u]=k,l(b)}function E(b){if(b[C]=null,b[H]===0){let w=b[R];if(w&&w.length){b[R]=[];for(let k of w)k.cb(new Error("No reply from server"))}}try{b.end()}catch{}setImmediate(()=>{b[B]||b.emit("end"),b[Q]||b.emit("close")})}function S(){this[Q]=!0}function x(){this[B]=!0}let R=Symbol("Requests"),H=Symbol("Agent Protocol Role"),C=Symbol("Agent Protocol Buffer"),U=Symbol("Agent Protocol Current Message Length"),Q=Symbol("Agent Protocol Closed"),B=Symbol("Agent Protocol Ended");return class extends Qu{constructor(w){super({autoDestroy:!0,emitClose:!1}),this[H]=w?0:1,this[R]=[],this[C]=null,this[U]=-1,this.once("end",x),this.once("close",S)}_read(w){}_write(w,k,v){this[C]===null?this[C]=w:this[C]=pm(this[C],w);let P=this[C],ne=P.length,G=0;for(;G<ne&&!(ne<5||(this[U]===-1&&(this[U]=Ca(P,G)),ne<4+this[U]));){let Y=P[G+=4];if(++G,this[H]===0){if(this[R].length===0)return v(new Error("Received unexpected message from server"));let te=this[R].shift();switch(Y){case 5:te.cb(new Error("Agent responded with failure"));break;case 12:{if(te.type!==11)return v(new Error("Agent responded with wrong message type"));wt.init(P,G);let le=wt.readUInt32BE();if(le===void 0)return wt.clear(),v(new Error("Malformed agent response"));let M=[];for(let N=0;N<le;++N){let L=wt.readString();if(L===void 0)return wt.clear(),v(new Error("Malformed agent response"));let K=wt.readString(!0);if(K===void 0)return wt.clear(),v(new Error("Malformed agent response"));L=Ti(L),!(L instanceof Error)&&(L.comment=L.comment||K,M.push(L))}G=wt.pos(),wt.clear(),te.cb(null,M);break}case 14:{if(te.type!==13)return v(new Error("Agent responded with wrong message type"));wt.init(P,G);let le=wt.readString();if(G=wt.pos(),wt.clear(),le===void 0)return v(new Error("Malformed agent response"));if(wt.init(le,0),wt.readString(!0),le=wt.readString(),wt.clear(),le===void 0)return v(new Error("Malformed OpenSSH signature format"));te.cb(null,le);break}default:return v(new Error("Agent responded with unsupported message type"))}}else switch(Y){case 11:{let te=new p(Y);this[R].push(te),this.emit("identities",te);break}case 13:{wt.init(P,G);let te=wt.readString(),le=wt.readString(),M=wt.readUInt32BE();if(G=wt.pos(),wt.clear(),M===void 0){let ee=new p(Y);return this[R].push(ee),this.failureReply(ee)}if(te=Ti(te),te instanceof Error){let ee=new p(Y);return this[R].push(ee),this.failureReply(ee)}let N={hash:void 0},L;te.type==="ssh-rsa"&&(M&2?(L="rsa-sha2-256",N.hash="sha256"):M&4&&(L="rsa-sha2-512",N.hash="sha512")),L===void 0&&(L=te.type);let K=new p(Y,L);this[R].push(K),this.emit("sign",K,te,le,N);break}default:{let te=new p(Y);this[R].push(te),this.failureReply(te)}}if(this[U]=-1,G===ne){this[C]=null;break}else this[C]=P=P.slice(G),ne=P.length,G=0}v()}_destroy(w,k){E(this),k()}_final(w){E(this),w()}sign(w,k,v,P){if(this[H]!==0)throw new Error("Client-only method called with server role");typeof v=="function"?(P=v,v=void 0):(typeof v!="object"||v===null)&&(v=void 0);let ne=0;if(w=Ti(w),w instanceof Error)throw new Error("Invalid public key argument");if(w.type==="ssh-rsa"&&v)switch(v.hash){case"sha256":ne=2;break;case"sha512":ne=4;break}w=w.getPublicSSH();let G=13,Y=w.length,te=k.length,le=0,M=Buffer.allocUnsafe(9+Y+4+te+4);return tn(M,M.length-4,le),M[le+=4]=G,tn(M,Y,++le),w.copy(M,le+=4),tn(M,te,le+=Y),k.copy(M,le+=4),tn(M,ne,le+=te),typeof P!="function"&&(P=xa),this[R].push({type:G,cb:P}),this.push(M)}getIdentities(w){if(this[H]!==0)throw new Error("Client-only method called with server role");let k=11,v=0,P=Buffer.allocUnsafe(5);return tn(P,P.length-4,v),P[v+=4]=k,typeof w!="function"&&(w=xa),this[R].push({type:k,cb:w}),this.push(P)}failureReply(w){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof p))throw new Error("Wrong request argument");if(w.hasResponded())return!0;let k=0,v=Buffer.allocUnsafe(5);return tn(v,v.length-4,k),v[k+=4]=5,A(this,w,v)}getIdentitiesReply(w,k){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof p))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(k))throw new Error("Keys argument must be an array");let v=4,P=[];for(let Y=0;Y<k.length;++Y){let te=k[Y];if(typeof te!="object"||te===null)throw new Error(`Invalid key entry: ${te}`);let le,M;if(Ou(te))le=te;else if(Ou(te.pubKey))le=te.pubKey;else if(typeof te.pubKey!="object"||te.pubKey===null||({pubKey:le,comment:M}=te.pubKey,le=Ti(le),le instanceof Error))continue;M=le.comment||M,le=le.getPublicSSH(),v+=4+le.length,M&&typeof M=="string"?M=Buffer.from(M):Buffer.isBuffer(M)||(M=gm),v+=4+M.length,P.push({pubKey:le,comment:M})}let ne=0,G=Buffer.allocUnsafe(5+v);tn(G,G.length-4,ne),G[ne+=4]=12,tn(G,P.length,++ne),ne+=4;for(let Y=0;Y<P.length;++Y){let{pubKey:te,comment:le}=P[Y];tn(G,te.length,ne),te.copy(G,ne+=4),tn(G,le.length,ne+=te.length),ne+=4,le.length&&(le.copy(G,ne),ne+=le.length)}return A(this,w,G)}signReply(w,k){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof p))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(k))throw new Error("Signature argument must be a Buffer");if(k.length===0)throw new Error("Signature argument must be non-empty");let v=0,P=w.getContext(),ne=Buffer.byteLength(P),G=Buffer.allocUnsafe(13+ne+4+k.length);return tn(G,G.length-4,v),G[v+=4]=14,tn(G,4+ne+4+k.length,++v),tn(G,ne,v+=4),G.utf8Write(P,v+=4,ne),tn(G,k.length,v+=ne),k.copy(G,v+=4),A(this,w,G)}}})(),Sa=Symbol("Agent"),xn=Symbol("Agent Keys"),Qn=Symbol("Agent Keys Index"),Hr=Symbol("Agent Init Callbacks"),Ia=class{constructor(t){if(typeof t=="string")t=Ku(t);else if(!Vu(t))throw new Error("Invalid agent argument");this[Sa]=t,this[xn]=null,this[Qn]=-1,this[Hr]=null}init(t){if(typeof t!="function"&&(t=xa),this[xn]===null)if(this[Hr]===null){this[Hr]=[t];let e=(...r)=>{process.nextTick(()=>{let s=this[Hr];this[Hr]=null;for(let i of s)i(...r)})};this[Sa].getIdentities(Li((r,s)=>{if(r)return e(r);if(!Array.isArray(s))return e(new Error("Agent implementation failed to provide keys"));let i=[];for(let o of s)o=Ti(o),!(o instanceof Error)&&i.push(o);this[xn]=i,this[Qn]=-1,e()}))}else this[Hr].push(t);else process.nextTick(t)}nextKey(){return this[xn]===null||++this[Qn]>=this[xn].length?!1:this[xn][this[Qn]]}currentKey(){return this[xn]===null||this[Qn]>=this[xn].length?null:this[xn][this[Qn]]}pos(){return this[xn]===null||this[Qn]>=this[xn].length?-1:this[Qn]}reset(){this[Qn]=-1}sign(...t){this[Sa].sign(...t)}};function Vu(n){return n instanceof $i}zu.exports={AgentContext:Ia,AgentProtocol:wa,BaseAgent:$i,createAgent:Ku,CygwinAgent:qu,isAgent:Vu,OpenSSHAgent:Qr,PageantAgent:Wu}});var Ta=lt((Ax,Gu)=>{"use strict";var{kMaxLength:Am}=require("buffer"),{createInflate:ym,constants:{DEFLATE:Em,INFLATE:_m,Z_DEFAULT_CHUNK:bm,Z_DEFAULT_COMPRESSION:Sm,Z_DEFAULT_MEMLEVEL:xm,Z_DEFAULT_STRATEGY:wm,Z_DEFAULT_WINDOWBITS:Im,Z_PARTIAL_FLUSH:Cm}}=require("zlib"),km=ym()._handle.constructor;function vm(){throw new Error("Should not get here")}function Bm(n,t,e){let r=this._owner,s=new Error(n);s.errno=t,s.code=e,r._err=s}function Pa(n){n._handle&&(n._handle.close(),n._handle=null)}var Os=class{constructor(t){let e=Im,r=Sm,s=xm,i=wm,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=bm,this._maxOutputLength=Am,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new km(t),this._handle._owner=this,this._handle.onerror=Bm,this._handle.init(e,r,s,i,this._writeState,vm,o)}writeSync(t,e){let r=this._handle;if(!r)throw new Error("Invalid Zlib instance");let s=t.length,i=this._chunkSize-this._outOffset,o=0,a,c,l,f=0,u=this._writeState,h=this._outBuffer,p=this._outOffset,A=this._chunkSize;for(;;){if(r.writeSync(Cm,t,o,s,h,p,i),this._err)throw this._err;a=u[0],c=u[1];let S=s-c,x=i-a;if(x>0){let R=p===0&&x===h.length?h:h.slice(p,p+x);if(p+=x,l?l.push===void 0?l=[l,R]:l.push(R):l=R,f+=R.byteLength,f>this._maxOutputLength)throw Pa(this),new Error(`Output length exceeded maximum of ${this._maxOutputLength}`)}else if(x!==0)throw new Error("have should not go down");if((a===0||p>=A)&&(i=A,p=0,h=Buffer.allocUnsafe(A)),a===0)o+=S,s=c;else break}if(this._outBuffer=h,this._outOffset=p,f===0&&(l=Buffer.alloc(0)),e)return l.totalLen=f,l;if(l.push===void 0)return l;let E=Buffer.allocUnsafe(f);for(let S=0,x=0;S<l.length;++S){let R=l[S];E.set(R,x),x+=R.length}return E}},va=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new Os(Em)}cleanup(){this._zlib&&Pa(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),s=this._protocol._cipher.allocPacket(r.totalLen);if(r.push===void 0)s.set(r,5);else for(let i=0,o=5;i<r.length;++i){let a=r[i];s.set(a,o),o+=a.length}return s}return t}},Ba=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}},Ra=class{constructor(){this._zlib=new Os(_m)}cleanup(){this._zlib&&Pa(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},Na=class{cleanup(){}read(t){return t}};Gu.exports={PacketReader:Na,PacketWriter:Ba,ZlibPacketReader:Ra,ZlibPacketWriter:va}});var Zu=lt((yx,Ju)=>{"use strict";var{bufferSlice:La,bufferParser:D,doFatalError:At,sigSSHToASN1:Yu,writeUInt32BE:ju}=_n(),{CHANNEL_OPEN_FAILURE:Rm,COMPAT:Nm,MESSAGE:_t,TERMINAL_MODE:Xu}=Fn(),{parseKey:Pm}=er(),Tm=Array.from(Object.entries(Xu)).reduce((n,[t,e])=>({...n,[t]:e}),{});Ju.exports={[_t.DISCONNECT]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString(!0),s=D.readString();if(D.clear(),s===void 0)return At(n,"Inbound: Malformed DISCONNECT packet");n._debug&&n._debug(`Inbound: Received DISCONNECT (${e}, "${r}")`);let i=n._handlers.DISCONNECT;i&&i(n,e,r)},[_t.IGNORE]:(n,t)=>{n._debug&&n._debug("Inbound: Received IGNORE")},[_t.UNIMPLEMENTED]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return At(n,"Inbound: Malformed UNIMPLEMENTED packet");n._debug&&n._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[_t.DEBUG]:(n,t)=>{D.init(t,1);let e=D.readBool(),r=D.readString(!0),s=D.readString();if(D.clear(),s===void 0)return At(n,"Inbound: Malformed DEBUG packet");n._debug&&n._debug("Inbound: Received DEBUG");let i=n._handlers.DEBUG;i&&i(n,e,r)},[_t.SERVICE_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0);if(D.clear(),e===void 0)return At(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)},[_t.SERVICE_ACCEPT]:(n,t)=>{D.init(t,1);let e=D.readString(!0);if(D.clear(),e===void 0)return At(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)},[_t.EXT_INFO]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r;if(e!==void 0){r=[];for(let i=0;i<e;++i){let o=D.readString(!0),a=D.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(D.clear(),r===void 0)return At(n,"Inbound: Malformed EXT_INFO packet");n._debug&&n._debug("Inbound: Received EXT_INFO");let s=n._handlers.EXT_INFO;s&&s(n,r)},[_t.USERAUTH_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readString(!0),s=D.readString(!0),i,o;switch(s){case"none":i=null;break;case"password":{let c=D.readBool();if(c!==void 0&&(i=D.readString(!0),i!==void 0&&c)){let l=D.readString(!0);l!==void 0?i={oldPassword:i,newPassword:l}:i=void 0}break}case"publickey":{let c=D.readBool();if(c!==void 0){let l=D.readString(!0),f=l,u=D.readString(),h;switch(l){case"rsa-sha2-256":f="ssh-rsa",h="sha256";break;case"rsa-sha2-512":f="ssh-rsa",h="sha512";break}if(c){let p=D.pos(),A=D.readString();if(A!==void 0&&(A.length>4+l.length+4&&A.utf8Slice(4,4+l.length)===l&&(A=La(A,4+l.length+4)),A=Yu(A,f),A)){let E=n._kex.sessionID,S=Buffer.allocUnsafe(4+E.length+p);ju(S,E.length,0),S.set(E,4),S.set(new Uint8Array(t.buffer,t.byteOffset,p),4+E.length),i={keyAlgo:f,key:u,signature:A,blob:S,hashAlgo:h}}}else i={keyAlgo:f,key:u,hashAlgo:h},o="publickey -- check"}break}case"hostbased":{let c=D.readString(!0),l=c,f=D.readString(),u=D.readString(!0),h=D.readString(!0),p;switch(c){case"rsa-sha2-256":l="ssh-rsa",p="sha256";break;case"rsa-sha2-512":l="ssh-rsa",p="sha512";break}let A=D.pos(),E=D.readString();if(E!==void 0&&(E.length>4+c.length+4&&E.utf8Slice(4,4+c.length)===c&&(E=La(E,4+c.length+4)),E=Yu(E,l),E!==void 0)){let S=n._kex.sessionID,x=Buffer.allocUnsafe(4+S.length+A);ju(x,S.length,0),x.set(S,4),x.set(new Uint8Array(t.buffer,t.byteOffset,A),4+S.length),i={keyAlgo:l,key:f,signature:E,blob:x,localHostname:u,localUsername:h,hashAlgo:p}}break}case"keyboard-interactive":D.skipString(),i=D.readList();break;default:s!==void 0&&(i=D.readRaw())}if(D.clear(),i===void 0)return At(n,"Inbound: Malformed USERAUTH_REQUEST packet");o===void 0&&(o=s),n._authsQueue.push(s),n._debug&&n._debug(`Inbound: Received USERAUTH_REQUEST (${o})`);let a=n._handlers.USERAUTH_REQUEST;a&&a(n,e,r,s,i)},[_t.USERAUTH_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readList(),r=D.readBool();if(D.clear(),r===void 0)return At(n,"Inbound: Malformed USERAUTH_FAILURE packet");n._debug&&n._debug(`Inbound: Received USERAUTH_FAILURE (${e})`),n._authsQueue.shift();let s=n._handlers.USERAUTH_FAILURE;s&&s(n,e,r)},[_t.USERAUTH_SUCCESS]:(n,t)=>{n._debug&&n._debug("Inbound: Received USERAUTH_SUCCESS"),n._authsQueue.shift();let e=n._handlers.USERAUTH_SUCCESS;e&&e(n)},[_t.USERAUTH_BANNER]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return At(n,"Inbound: Malformed USERAUTH_BANNER packet");n._debug&&n._debug("Inbound: Received USERAUTH_BANNER");let s=n._handlers.USERAUTH_BANNER;s&&s(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":{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return At(n,"Inbound: Malformed USERAUTH_PASSWD_CHANGEREQ packet");n._debug&&n._debug("Inbound: Received USERAUTH_PASSWD_CHANGEREQ");let s=n._handlers.USERAUTH_PASSWD_CHANGEREQ;s&&s(n,e);break}case"publickey":{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return At(n,"Inbound: Malformed USERAUTH_PK_OK packet");n._debug&&n._debug("Inbound: Received USERAUTH_PK_OK"),n._authsQueue.shift();let s=n._handlers.USERAUTH_PK_OK;s&&s(n,e,r);break}case"keyboard-interactive":{D.init(t,1);let e=D.readString(!0),r=D.readString(!0);D.readString();let s=D.readUInt32BE(),i;if(s!==void 0){i=new Array(s);let a;for(a=0;a<s;++a){let c=D.readString(!0),l=D.readBool();if(l===void 0)break;i[a]={prompt:c,echo:l}}a!==s&&(i=void 0)}if(D.clear(),i===void 0)return At(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,i);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 At(n,"Inbound: Received unexpected payload type 61");D.init(t,1);let e=D.readUInt32BE(),r;if(e!==void 0){r=new Array(e);let i;for(i=0;i<e;++i){let o=D.readString(!0);if(o===void 0)break;r[i]=o}i!==e&&(r=void 0)}if(D.clear(),r===void 0)return At(n,"Inbound: Malformed USERAUTH_INFO_RESPONSE packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_RESPONSE");let s=n._handlers.USERAUTH_INFO_RESPONSE;s&&s(n,r)},[_t.GLOBAL_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readBool(),s;if(r!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=D.readString(!0),a=D.readUInt32BE();a!==void 0&&(s={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=D.readString(!0);o!==void 0&&(s={socketPath:o});break}case"no-more-sessions@openssh.com":s=null;break;case"hostkeys-00@openssh.com":{for(s=[];D.avail()>0;){let o=D.readString();if(o===void 0){s=void 0;break}let a=Pm(o);a instanceof Error||s.push(a)}break}default:s=D.readRaw()}if(D.clear(),s===void 0)return At(n,"Inbound: Malformed GLOBAL_REQUEST packet");n._debug&&n._debug(`Inbound: GLOBAL_REQUEST (${e})`);let i=n._handlers.GLOBAL_REQUEST;i?i(n,e,r,s):n.requestFailure()},[_t.REQUEST_SUCCESS]:(n,t)=>{let e=t.length>1?La(t,1):null;n._debug&&n._debug("Inbound: REQUEST_SUCCESS");let r=n._handlers.REQUEST_SUCCESS;r&&r(n,e)},[_t.REQUEST_FAILURE]:(n,t)=>{n._debug&&n._debug("Inbound: Received REQUEST_FAILURE");let e=n._handlers.REQUEST_FAILURE;e&&e(n)},[_t.CHANNEL_OPEN]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readUInt32BE(),s=D.readUInt32BE(),i=D.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=D.readString(!0),l=D.readUInt32BE(),f=D.readString(!0),u=D.readUInt32BE();u!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{destIP:c,destPort:l,srcIP:f,srcPort:u}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=D.readString(!0);c!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{socketPath:c}});break}case"x11":{let c=D.readString(!0),l=D.readUInt32BE();l!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{srcIP:c,srcPort:l}});break}default:o={type:e,sender:r,window:s,packetSize:i,data:{}}}if(D.clear(),o===void 0)return At(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,Rm.ADMINISTRATIVELY_PROHIBITED,"","")},[_t.CHANNEL_OPEN_CONFIRMATION]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readUInt32BE(),i=D.readUInt32BE(),o=D.avail()?D.readRaw():void 0;if(D.clear(),i===void 0)return At(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:s,packetSize:i,data:o})},[_t.CHANNEL_OPEN_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readString(!0),i=D.readString();if(D.clear(),i===void 0)return At(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,s)},[_t.CHANNEL_WINDOW_ADJUST]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE();if(D.clear(),r===void 0)return At(n,"Inbound: Malformed CHANNEL_WINDOW_ADJUST packet");n._debug&&n._debug(`Inbound: CHANNEL_WINDOW_ADJUST (r:${e}, ${r})`);let s=n._handlers.CHANNEL_WINDOW_ADJUST;s&&s(n,e,r)},[_t.CHANNEL_DATA]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString();if(D.clear(),r===void 0)return At(n,"Inbound: Malformed CHANNEL_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_DATA (r:${e}, ${r.length})`);let s=n._handlers.CHANNEL_DATA;s&&s(n,e,r)},[_t.CHANNEL_EXTENDED_DATA]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readString();if(D.clear(),s===void 0)return At(n,"Inbound: Malformed CHANNEL_EXTENDED_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_EXTENDED_DATA (r:${e}, ${s.length})`);let i=n._handlers.CHANNEL_EXTENDED_DATA;i&&i(n,e,s,r)},[_t.CHANNEL_EOF]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return At(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)},[_t.CHANNEL_CLOSE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return At(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)},[_t.CHANNEL_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString(!0),s=D.readBool(),i;if(s!==void 0)switch(r){case"exit-status":i=D.readUInt32BE(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"exit-signal":{let a,c;if(n._compatFlags&Nm.OLD_EXIT){let f=D.readUInt32BE();switch(f){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:f!==void 0&&(a=`UNKNOWN (${f})`)}c=!1}else a=D.readString(!0),c=D.readBool(),c===void 0&&(a=void 0);let l=D.readString(!0);D.skipString()!==void 0&&(i={signal:a,coreDumped:c,errorMessage:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a})`);break}case"pty-req":{let a=D.readString(!0),c=D.readUInt32BE(),l=D.readUInt32BE(),f=D.readUInt32BE(),u=D.readUInt32BE(),h=D.readString();if(h!==void 0){D.init(h,1);let p={};for(;D.avail();){let A=D.readByte();if(A===Xu.TTY_OP_END)break;let E=Tm[A],S=D.readUInt32BE();if(A===void 0||E===void 0||S===void 0){p=void 0;break}p[E]=S}p!==void 0&&(i={term:a,cols:c,rows:l,width:f,height:u,modes:p})}n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"window-change":{let a=D.readUInt32BE(),c=D.readUInt32BE(),l=D.readUInt32BE(),f=D.readUInt32BE();f!==void 0&&(i={cols:a,rows:c,width:l,height:f}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"x11-req":{let a=D.readBool(),c=D.readString(!0),l=D.readString(),f=D.readUInt32BE();f!==void 0&&(i={single:a,protocol:c,cookie:l,screen:f}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"env":{let a=D.readString(!0),c=D.readString(!0);c!==void 0&&(i={name:a,value:c}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a}=${c})`);break}case"shell":i=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;case"exec":i=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"subsystem":i=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"signal":i=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"xon-xoff":i=D.readBool(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"auth-agent-req@openssh.com":i=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;default:i=D.avail()?D.readRaw():null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`)}if(D.clear(),i===void 0)return At(n,"Inbound: Malformed CHANNEL_REQUEST packet");let o=n._handlers.CHANNEL_REQUEST;o&&o(n,e,r,s,i)},[_t.CHANNEL_SUCCESS]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return At(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)},[_t.CHANNEL_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return At(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 Fs=lt((Ex,ed)=>{"use strict";var $a=new Array(256);[Hs().HANDLERS,Zu()].forEach(n=>{for(let[t,e]of Object.entries(n))t=+t,isFinite(t)&&t>=0&&t<$a.length&&($a[t]=e)});ed.exports=$a});var Hs=lt((bx,fd)=>{"use strict";var{createDiffieHellman:Lm,createDiffieHellmanGroup:$m,createECDH:Dm,createHash:Ua,createPublicKey:Um,diffieHellman:Mm,generateKeyPairSync:Om,randomFillSync:Fm}=require("crypto"),{Ber:td}=yi(),{COMPAT:Ma,curve25519Supported:Hm,DEFAULT_KEX:nd,DEFAULT_SERVER_HOST_KEY:rd,DEFAULT_CIPHER:Qs,DEFAULT_MAC:Ws,DEFAULT_COMPRESSION:qs,DISCONNECT_REASON:Ye,MESSAGE:pt}=Fn(),{CIPHER_INFO:Kr,createCipher:Qm,createDecipher:Wm,MAC_INFO:id}=Xn(),{parseDERKey:qm}=er(),{bufferFill:Km,bufferParser:Ge,convertSignature:Vm,doFatalError:je,FastBuffer:zm,sigSSHToASN1:Gm,writeUInt32BE:Ht}=_n(),{PacketReader:sd,PacketWriter:od,ZlibPacketReader:Ks,ZlibPacketWriter:Vs}=Ta(),Wr,Ym=2048,jm=8192,Xm=Buffer.alloc(0);function ad(n){let t;if(n._compatFlags&Ma.BAD_DHGEX){let e=n._offer.lists.kex,r=e.array,s=!1;for(let i=0;i<r.length;++i)r[i].includes("group-exchange")&&(s||(s=!0,r=r.slice()),r.splice(i--,1));if(s){let i=17+n._offer.totalSize+1+4,o=Buffer.from(r.join(","));i-=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(i),Ht(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]=pt.KEXINIT,Fm(t,1,16),Km(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 cd(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(Ge.init(t,17),(e.kex=Ge.readList())===void 0||(e.serverHostKey=Ge.readList())===void 0||(e.cs.cipher=Ge.readList())===void 0||(e.sc.cipher=Ge.readList())===void 0||(e.cs.mac=Ge.readList())===void 0||(e.sc.mac=Ge.readList())===void 0||(e.cs.compress=Ge.readList())===void 0||(e.sc.compress=Ge.readList())===void 0||(e.cs.lang=Ge.readList())===void 0||(e.sc.lang=Ge.readList())===void 0)return Ge.clear(),je(n,"Received malformed KEXINIT","handshake",Ye.KEY_EXCHANGE_FAILED);let r=Ge.pos(),s=r<t.length&&t[r]===1;Ge.clear();let i=n._offer,o=e,a=i.lists.kex.array;if(n._compatFlags&Ma.BAD_DHGEX){let C=!1;for(let U=0;U<a.length;++U)a[U].indexOf("group-exchange")!==-1&&(C||(C=!0,a=a.slice()),a.splice(U--,1))}let c,l,f,u=n._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(n._server?(l=a,c=o.kex,h=c.indexOf("ext-info-c")!==-1):(l=o.kex,c=a,h=l.indexOf("ext-info-s")!==-1),n._strictMode===void 0&&(n._server?n._strictMode=c.indexOf("kex-strict-c-v00@openssh.com")!==-1:n._strictMode=l.indexOf("kex-strict-s-v00@openssh.com")!==-1,n._strictMode&&(u&&u("Handshake: strict KEX mode enabled"),n._decipher.inSeqno!==1)))return u&&u("Handshake: KEXINIT not first packet in strict KEX mode"),je(n,"Handshake failed: KEXINIT not first packet in strict KEX mode","handshake",Ye.KEY_EXCHANGE_FAILED);for(f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: no matching key exchange algorithm"),je(n,"Handshake failed: no matching key exchange algorithm","handshake",Ye.KEY_EXCHANGE_FAILED);e.kex=c[f],u&&u(`Handshake: KEX algorithm: ${c[f]}`),s&&(!o.kex.length||c[f]!==o.kex[0])&&(n._skipNextInboundPacket=!0);let p=i.lists.serverHostKey.array;for(u&&u(`Handshake: (local) Host key format: ${p}`),u&&u(`Handshake: (remote) Host key format: ${o.serverHostKey}`),n._server?(l=p,c=o.serverHostKey):(l=o.serverHostKey,c=p),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching host key format"),je(n,"Handshake failed: no matching host key format","handshake",Ye.KEY_EXCHANGE_FAILED);e.serverHostKey=c[f],u&&u(`Handshake: Host key format: ${c[f]}`);let A=i.lists.cs.cipher.array;for(u&&u(`Handshake: (local) C->S cipher: ${A}`),u&&u(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),n._server?(l=A,c=o.cs.cipher):(l=o.cs.cipher,c=A),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching C->S cipher"),je(n,"Handshake failed: no matching C->S cipher","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.cipher=c[f],u&&u(`Handshake: C->S Cipher: ${c[f]}`);let E=i.lists.sc.cipher.array;for(u&&u(`Handshake: (local) S->C cipher: ${E}`),u&&u(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),n._server?(l=E,c=o.sc.cipher):(l=o.sc.cipher,c=E),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching S->C cipher"),je(n,"Handshake failed: no matching S->C cipher","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.cipher=c[f],u&&u(`Handshake: S->C cipher: ${c[f]}`);let S=i.lists.cs.mac.array;if(u&&u(`Handshake: (local) C->S MAC: ${S}`),u&&u(`Handshake: (remote) C->S MAC: ${o.cs.mac}`),Kr[e.cs.cipher].authLen>0)e.cs.mac="",u&&u("Handshake: C->S MAC: <implicit>");else{for(n._server?(l=S,c=o.cs.mac):(l=o.cs.mac,c=S),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching C->S MAC"),je(n,"Handshake failed: no matching C->S MAC","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.mac=c[f],u&&u(`Handshake: C->S MAC: ${c[f]}`)}let x=i.lists.sc.mac.array;if(u&&u(`Handshake: (local) S->C MAC: ${x}`),u&&u(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),Kr[e.sc.cipher].authLen>0)e.sc.mac="",u&&u("Handshake: S->C MAC: <implicit>");else{for(n._server?(l=x,c=o.sc.mac):(l=o.sc.mac,c=x),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching S->C MAC"),je(n,"Handshake failed: no matching S->C MAC","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.mac=c[f],u&&u(`Handshake: S->C MAC: ${c[f]}`)}let R=i.lists.cs.compress.array;for(u&&u(`Handshake: (local) C->S compression: ${R}`),u&&u(`Handshake: (remote) C->S compression: ${o.cs.compress}`),n._server?(l=R,c=o.cs.compress):(l=o.cs.compress,c=R),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching C->S compression"),je(n,"Handshake failed: no matching C->S compression","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.compress=c[f],u&&u(`Handshake: C->S compression: ${c[f]}`);let H=i.lists.sc.compress.array;for(u&&u(`Handshake: (local) S->C compression: ${H}`),u&&u(`Handshake: (remote) S->C compression: ${o.sc.compress}`),n._server?(l=H,c=o.sc.compress):(l=o.sc.compress,c=H),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching S->C compression"),je(n,"Handshake failed: no matching S->C compression","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.compress=c[f],u&&u(`Handshake: S->C compression: ${c[f]}`),e.cs.lang="",e.sc.lang="",n._kex&&(n._kexinit||ad(n),n._decipher._onPayload=ld.bind(n,{firstPacket:!1})),n._kex=Jm(e,n,t),n._kex.remoteExtInfoEnabled=h,n._kex.start()}var Jm=(()=>{function n(o){let a=0,c=o.length;for(;o[a]===0;)++a,--c;let l;return o[a]&128?(l=Buffer.allocUnsafe(1+c),l[0]=0,o.copy(l,1,a),o=l):c!==o.length&&(l=Buffer.allocUnsafe(c),o.copy(l,0,a),o=l),o}class t{constructor(a,c,l){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=l,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,l=this.negotiated,f=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",je(this._protocol,u,Ye.KEY_EXCHANGE_FAILED);let h=Ua(this.hashName);Rn(h,c?this._remoteIdentRaw:this._identRaw),Rn(h,c?this._identRaw:this._remoteIdentRaw),Rn(h,c?this._remoteKexinit:this._kexinit),Rn(h,c?this._kexinit:this._remoteKexinit);let p=c?this._hostKey.getPublicSSH():this._hostKey;if(Rn(h,p),this.type==="groupex"){let H=this.getDHParams(),C=Buffer.allocUnsafe(4);Ht(C,this._minBits,0),h.update(C),Ht(C,this._prefBits,0),h.update(C),Ht(C,this._maxBits,0),h.update(C),Rn(h,H.prime),Rn(h,H.generator)}Rn(h,c?f:this.getPublicKey());let A=c?this.getPublicKey():f;Rn(h,A),Rn(h,u);let E=h.digest();if(c){let H;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":H="sha256";break;case"rsa-sha2-512":H="sha512";break}this._protocol._debug&&this._protocol._debug("Generating signature ...");let C=this._hostKey.sign(E,H);if(C instanceof Error)return je(this._protocol,`Handshake failed: signature generation failed for ${this._hostKey.type} host key: ${C.message}`,"handshake",Ye.KEY_EXCHANGE_FAILED);if(C=Vm(C,this._hostKey.type),C===!1)return je(this._protocol,`Handshake failed: signature conversion failed for ${this._hostKey.type} host key`,"handshake",Ye.KEY_EXCHANGE_FAILED);let U=this.negotiated.serverHostKey,Q=Buffer.byteLength(U),B=4+Q+4+C.length,b=this._protocol._packetRW.write.allocStartKEX,w=this._protocol._packetRW.write.alloc(5+p.length+4+A.length+4+B,!0);if(w[b]=pt.KEXDH_REPLY,Ht(w,p.length,++b),w.set(p,b+=4),Ht(w,A.length,b+=p.length),w.set(A,b+=4),Ht(w,B,b+=A.length),Ht(w,Q,b+=4),w.utf8Write(U,b+=4,Q),Ht(w,C.length,b+=Q),w.set(C,b+=4),this._protocol._debug){let k;switch(this.type){case"group":k="KEXDH_REPLY";break;case"groupex":k="KEXDH_GEX_REPLY";break;default:k="KEXECDH_REPLY"}this._protocol._debug(`Outbound: Sending ${k}`)}this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(w,!0))}else{Ge.init(this._sig,0);let H=Ge.readString(!0);if(!H)return je(this._protocol,"Malformed packet while reading signature","handshake",Ye.KEY_EXCHANGE_FAILED);if(H!==l.serverHostKey)return je(this._protocol,`Wrong signature type: ${H}, expected: ${l.serverHostKey}`,"handshake",Ye.KEY_EXCHANGE_FAILED);let C=Ge.readString();if(Ge.clear(),C===void 0)return je(this._protocol,"Malformed packet while reading signature","handshake",Ye.KEY_EXCHANGE_FAILED);if(!(C=Gm(C,H)))return je(this._protocol,"Malformed signature","handshake",Ye.KEY_EXCHANGE_FAILED);let U;{Ge.init(this._hostKey,0);let b=Ge.readString(!0),w=this._hostKey.slice(Ge.pos());if(Ge.clear(),U=qm(w,b),U instanceof Error)return U.level="handshake",je(this._protocol,U,Ye.KEY_EXCHANGE_FAILED)}let Q;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":Q="sha256";break;case"rsa-sha2-512":Q="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let B=U.verify(E,C,Q);if(B!==!0)return B instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${B.stack}`):this._protocol._debug&&this._protocol._debug("Signature verification failed"),je(this._protocol,"Handshake failed: signature verification failed","handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Verified signature")}(c||!a)&&zs(this);let S,x,R=H=>{if(S)return zs(this),S.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=Qm(S),this._protocol._packetRW.write=x,S=void 0,x=void 0,this._protocol._onHandshakeComplete(l),!1;this.sessionID||(this.sessionID=E);{let te=Buffer.allocUnsafe(4+u.length);Ht(te,u.length,0),te.set(u,4),u=te}let C=Kr[l.cs.cipher],U=Kr[l.sc.cipher],Q=qr(C.ivLen,this.hashName,u,E,this.sessionID,"A"),B=qr(U.ivLen,this.hashName,u,E,this.sessionID,"B"),b=qr(C.keyLen,this.hashName,u,E,this.sessionID,"C"),w=qr(U.keyLen,this.hashName,u,E,this.sessionID,"D"),k,v;C.authLen||(k=id[l.cs.mac],v=qr(k.len,this.hashName,u,E,this.sessionID,"E"));let P,ne;U.authLen||(P=id[l.sc.mac],ne=qr(P.len,this.hashName,u,E,this.sessionID,"F"));let G={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?C:U,decipherIV:c?Q:B,decipherKey:c?b:w,macInfo:c?k:P,macKey:c?v:ne},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?U:C,cipherIV:c?B:Q,cipherKey:c?w:b,macInfo:c?P:k,macKey:c?ne:v}};this._protocol._decipher.free(),S=G,this._protocol._decipher=Wm(G);let Y={read:void 0,write:void 0};switch(l.cs.compress){case"zlib":c?Y.read=new Ks:Y.write=new Vs(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Y.read=new Ks:Y.write=new Vs(this._protocol);break}default:c?Y.read=new sd:Y.write=new od(this._protocol)}switch(l.sc.compress){case"zlib":c?Y.write=new Vs(this._protocol):Y.read=new Ks;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Y.write=new Vs(this._protocol):Y.read=new Ks;break}default:c?Y.write=new od(this._protocol):Y.read=new sd}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=Y.read,x=Y.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,H?!1:R()};if((c||a)&&(this.finish=R),!c)return R(a)}start(){if(!this._protocol._server){if(this._protocol._debug){let f;this.type==="group"?f="KEXDH_INIT":f="KEXECDH_INIT",this._protocol._debug(`Outbound: Sending ${f}`)}let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,l=this._protocol._packetRW.write.alloc(5+a.length,!0);l[c]=pt.KEXDH_INIT,Ht(l,a.length,++c),l.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(l,!0))}}getPublicKey(){this.generateKeys();let a=this._public;if(a)return this.convertPublicKey(a)}convertPublicKey(a){let c,l=0,f=a.length;for(;a[l]===0;)++l,--f;return a[l]&128?(c=Buffer.allocUnsafe(1+f),c[0]=0,a.copy(c,1,l),c):(f!==a.length&&(c=Buffer.allocUnsafe(f),a.copy(c,0,l),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!==pt.KEXDH_INIT)return je(this._protocol,`Received packet ${c} instead of ${pt.KEXDH_INIT}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Init"),Ge.init(a,1);let l=Ge.readString();if(Ge.clear(),l===void 0)return je(this._protocol,"Received malformed KEX*_INIT","handshake",Ye.KEY_EXCHANGE_FAILED);this._dhData=l;let f=this._protocol._hostKeys[this.negotiated.serverHostKey];Array.isArray(f)&&(f=f[0]),this._hostKey=f,this.finish()}else{if(c!==pt.KEXDH_REPLY)return je(this._protocol,`Received packet ${c} instead of ${pt.KEXDH_REPLY}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ge.init(a,1);let l,f,u;if((l=Ge.readString())===void 0||(f=Ge.readString())===void 0||(u=Ge.readString())===void 0)return Ge.clear(),je(this._protocol,"Received malformed KEX*_REPLY","handshake",Ye.KEY_EXCHANGE_FAILED);Ge.clear(),Ge.init(l,0);let h=Ge.readString(!0);if(Ge.clear(),h===void 0)return je(this._protocol,"Received malformed host public key","handshake",Ye.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 je(this._protocol,"Host key does not match negotiated type","handshake",Ye.KEY_EXCHANGE_FAILED)}this._hostKey=l,this._dhData=f,this._sig=u;let p=!1,A;if(this._protocol._hostVerifier===void 0?(A=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):A=this._protocol._hostVerifier(l,E=>{if(!p){if(p=!0,E===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),je(this._protocol,"Host denied (verification failed)","handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,this._receivedNEWKEYS?this.finish():zs(this)}}),A===void 0){++this._step;return}if(p=!0,A===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),je(this._protocol,"Host denied (verification failed)","handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,zs(this)}++this._step;break;case 2:return c!==pt.NEWKEYS?je(this._protocol,`Received packet ${c} instead of ${pt.NEWKEYS}`,"handshake",Ye.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 je(this._protocol,`Received unexpected packet ${c} after NEWKEYS`,"handshake",Ye.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=Om("x25519"))}getPublicKey(){return this.generateKeys(),this._keys.publicKey.export({type:"spki",format:"der"}).slice(-32)}convertPublicKey(a){let c,l=0,f=a.length;for(;a[l]===0;)++l,--f;return a.length===32||f!==a.length&&(c=Buffer.allocUnsafe(f),a.copy(c,0,l),a=c),a}computeSecret(a){this.generateKeys();try{let c=new td.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(td.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(Mm({privateKey:this._keys.privateKey,publicKey:Um({key:c.buffer,type:"spki",format:"der"})}))}catch(c){return c}}}class r extends t{constructor(a,c,...l){super(...l),this.type="ecdh",this.curveName=a,this.hashName=c}generateKeys(){this._dh||(this._dh=Dm(this.curveName),this._public=this._dh.generateKeys())}}class s extends t{constructor(a,...c){super(...c),this.type="groupex",this.hashName=a,this._prime=null,this._generator=null,this._minBits=Ym,this._prefBits=Zm(this.negotiated),this._protocol._compatFlags&Ma.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=jm}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]=pt.KEXDH_GEX_REQUEST,Ht(c,this._minBits,++a),Ht(c,this._prefBits,a+=4),Ht(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=Lm(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!==pt.KEXDH_GEX_REQUEST?je(this._protocol,`Received packet ${c} instead of `+pt.KEXDH_GEX_REQUEST,"handshake",Ye.KEY_EXCHANGE_FAILED):je(this._protocol,"Group exchange not implemented for server","handshake",Ye.KEY_EXCHANGE_FAILED);if(c!==pt.KEXDH_GEX_GROUP)return je(this._protocol,`Received packet ${c} instead of ${pt.KEXDH_GEX_GROUP}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ge.init(a,1);let l,f;if((l=Ge.readString())===void 0||(f=Ge.readString())===void 0)return Ge.clear(),je(this._protocol,"Received malformed KEXDH_GEX_GROUP","handshake",Ye.KEY_EXCHANGE_FAILED);Ge.clear(),this.setDHParams(l,f),this.generateKeys();let u=this.getPublicKey();this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_INIT");let h=this._protocol._packetRW.write.allocStartKEX,p=this._protocol._packetRW.write.alloc(5+u.length,!0);p[h]=pt.KEXDH_GEX_INIT,Ht(p,u.length,++h),p.set(u,h+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(p,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==pt.KEXDH_GEX_INIT?je(this._protocol,`Received packet ${c} instead of ${pt.KEXDH_GEX_INIT}`,"handshake",Ye.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Received DH GEX Init"),je(this._protocol,"Group exchange not implemented for server","handshake",Ye.KEY_EXCHANGE_FAILED));if(c!==pt.KEXDH_GEX_REPLY)return je(this._protocol,`Received packet ${c} instead of ${pt.KEXDH_GEX_REPLY}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=pt.KEXDH_REPLY,this.parse=t.prototype.parse,this.parse(a)}}}class i extends t{constructor(a,c,...l){super(...l),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,l=this._protocol._packetRW.write.alloc(5+a.length,!0);l[c]=pt.KEXDH_INIT,Ht(l,a.length,++c),l.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(l,!0))}}generateKeys(){this._dh||(this._dh=$m(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(!Hm)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 i("modp2","sha1",...a);case"diffie-hellman-group14-sha1":return new i("modp14","sha1",...a);case"diffie-hellman-group14-sha256":return new i("modp14","sha256",...a);case"diffie-hellman-group15-sha512":return new i("modp15","sha512",...a);case"diffie-hellman-group16-sha512":return new i("modp16","sha512",...a);case"diffie-hellman-group17-sha512":return new i("modp17","sha512",...a);case"diffie-hellman-group18-sha512":return new i("modp18","sha512",...a);case"diffie-hellman-group-exchange-sha1":return new s("sha1",...a);case"diffie-hellman-group-exchange-sha256":return new s("sha256",...a)}throw new Error(`Unsupported key exchange algorithm: ${c}`)}throw new Error(`Invalid key exchange type: ${c}`)}})(),Da=(()=>{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},s=0;for(let a of n){let c,l,f,u;if(typeof a=="string")c=r,l=e[a],f=u=a;else{let p=a[0];c=r[p],u=a[1],l=e[p][u],f=`${p}.${u}`}let h={array:void 0,buffer:void 0};if(Buffer.isBuffer(l))h.array=(""+l).split(","),h.buffer=l,s+=4+l.length;else{if(typeof l=="string"&&(l=l.split(",")),Array.isArray(l))h.array=l,h.buffer=Buffer.from(l.join(","));else throw new TypeError(`Invalid \`${f}\` type: ${typeof l}`);s+=4+h.buffer.length}c[u]=h}let i=Buffer.allocUnsafe(s);r.all=i;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=Ht(i,c.length,o),i.set(c,o),o+=c.length}this.totalSize=s,this.lists=r}copyAllTo(e,r){let s=this.lists.all;if(typeof r!="number")throw new TypeError(`Invalid offset value: ${typeof r}`);if(e.length-r<s.length)throw new Error("Insufficient space to copy list");return e.set(s,r),s.length}}})(),Rn=(()=>{let n=Buffer.allocUnsafe(4);return(t,e)=>{Ht(n,e.length,0),t.update(n),t.update(e)}})();function qr(n,t,e,r,s,i){let o;if(n){let a=Ua(t).update(e).update(r).update(i).update(s).digest();for(;a.length<n;){let c=Ua(t).update(e).update(r).update(a).digest(),l=Buffer.allocUnsafe(a.length+c.length);l.set(a,0),l.set(c,a.length),a=l}a.length===n?o=a:o=new zm(a.buffer,a.byteOffset,n)}else o=Xm;return o}function ld(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 pt.IGNORE:case pt.UNIMPLEMENTED:case pt.DEBUG:return Wr||(Wr=Fs()),Wr[e](this,t)}switch(e){case pt.DISCONNECT:return Wr||(Wr=Fs()),Wr[e](this,t);case pt.KEXINIT:return n.firstPacket?(n.firstPacket=!1,cd(this,t)):je(this,"Received extra KEXINIT during handshake","handshake",Ye.KEY_EXCHANGE_FAILED);default:if(e<20||e>49)return je(this,`Received unexpected packet type ${e}`,"handshake",Ye.KEY_EXCHANGE_FAILED)}return this._kex.parse(t)}function Zm(n){let t=Kr[n.cs.cipher],e=Kr[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 zs(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]=pt.NEWKEYS,n._protocol._cipher.encrypt(n._protocol._packetRW.write.finalize(e,!0)),n._sentNEWKEYS=!0,n._protocol._strictMode&&(n._protocol._cipher.outSeqno=0)}}fd.exports={KexInit:Da,kexinit:ad,onKEXPayload:ld,DEFAULT_KEXINIT_CLIENT:new Da({kex:nd.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:rd,cs:{cipher:Qs,mac:Ws,compress:qs,lang:[]},sc:{cipher:Qs,mac:Ws,compress:qs,lang:[]}}),DEFAULT_KEXINIT_SERVER:new Da({kex:nd.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:rd,cs:{cipher:Qs,mac:Ws,compress:qs,lang:[]},sc:{cipher:Qs,mac:Ws,compress:qs,lang:[]}}),HANDLERS:{[pt.KEXINIT]:cd}}});var ud=lt((Sx,e0)=>{e0.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 Qa=lt((xx,wd)=>{"use strict";var{inspect:Ad}=require("util"),{bindingAvailable:t0,NullCipher:n0,NullDecipher:r0}=Xn(),{COMPAT_CHECKS:i0,DISCONNECT_REASON:yd,eddsaSupported:s0,MESSAGE:we,SIGNALS:dd,TERMINAL_MODE:Fa}=Fn(),{DEFAULT_KEXINIT_CLIENT:o0,DEFAULT_KEXINIT_SERVER:a0,KexInit:hd,kexinit:Ed,onKEXPayload:c0}=Hs(),{parseKey:pd}=er(),l0=Fs(),{bufferCopy:Gs,bufferFill:f0,bufferSlice:_d,convertSignature:gd,sendPacket:Ie,writeUInt32BE:T}=_n(),{PacketReader:u0,PacketWriter:d0,ZlibPacketReader:bd,ZlibPacketWriter:Sd}=Ta(),h0=ud().version,p0=new Map(Object.values(yd).map(n=>[n,1])),xd=Buffer.from(`SSH-2.0-ssh2js${h0}`),g0=Buffer.from(`${xd}\r
7
+ `),m0=8192,A0=1024,md=Buffer.from([we.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]),y0=Buffer.from([Fa.TTY_OP_END]);function Oa(){}var Ha=class{constructor(t){let e=t.onWrite;if(typeof e!="function")throw new Error("Missing onWrite function");this._onWrite=p=>{e(p)};let r=t.onError;if(typeof r!="function")throw new Error("Missing onError function");this._onError=p=>{r(p)};let s=t.debug;this._debug=typeof s=="function"?p=>{s(p)}:void 0;let i=t.onHeader;this._onHeader=typeof i=="function"?(...p)=>{i(...p)}:Oa;let o=t.onPacket;this._onPacket=typeof o=="function"?()=>{o()}:Oa;let a=t.onHandshakeComplete;typeof a!="function"&&(a=Oa);let c;this._onHandshakeComplete=(...p)=>{this._debug&&this._debug("Handshake completed"),c===void 0?c=!0:c=!1;let A=this._queue;if(A){this._queue=void 0,this._debug&&this._debug(`Draining outbound queue (${A.length}) ...`);for(let E=0;E<A.length;++E){let S=A[E],x=this._packetRW.write.finalize(S);if(x===S){let R=this._cipher.allocPacket(S.length);R.set(S,5),x=R}Ie(this,x)}this._debug&&this._debug("... finished draining outbound queue")}c&&this._server&&this._kex.remoteExtInfoEnabled&&I0(this),a(...p)},this._queue=void 0;let l=t.messageHandlers;typeof l=="object"&&l!==null?this._handlers=l:this._handlers={},this._onPayload=S0.bind(this),this._server=!!t.server,this._banner=void 0;let f;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&&(f=t.greeting.slice(-2)===`\r
8
8
  `?t.greeting:`${t.greeting}\r
9
9
  `),typeof t.banner=="string"&&t.banner.length&&(this._banner=t.banner.slice(-2)===`\r
10
10
  `?t.banner:`${t.banner}\r
11
- `)}else this._hostKeys=void 0;let u=t.offer;typeof u!="object"||u===null?u=this._server?Qm:Hm:u.constructor!==od&&(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 od(u)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=u,this._cipher=new $m(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new Vm,write:new Gm(this)},this._hostVerifier=!this._server&&typeof t.hostVerifier=="function"?t.hostVerifier:void 0,this._parse=t0,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 p=Buffer.allocUnsafe(8+t.ident.length);p.latin1Write("SSH-2.0-",0,8),p.set(t.ident,8),this._identRaw=p,h=Buffer.allocUnsafe(p.length+2),h.set(p,0),h[h.length-2]=13,h[h.length-1]=10}else this._identRaw=md,h=jm;this._compatFlags=0,this._debug&&(Um?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${ld(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,r){for(;e<r;)e=this._parse(t,e,r)}disconnect(t){let r=this._packetRW.write.allocStartKEX,s=this._packetRW.write.alloc(13,!0),i=r+13;Ym.has(t)||(t=ud.PROTOCOL_ERROR),s[r]=Se.DISCONNECT,P(s,t,++r),s.fill(0,r+=4,i),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),we(this,this._packetRW.write.finalize(s,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(fd.length);e.set(fd,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),we(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],dd(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]=Se.REQUEST_SUCCESS,r.set(t,++e)):(r=this._packetRW.write.alloc(1),r[e]=Se.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),we(this,this._packetRW.write.finalize(r))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=Se.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),we(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_SUCCESS,P(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelFailure(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_FAILURE,P(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelEOF(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_EOF,P(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelClose(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_CLOSE,P(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelWindowAdjust(t,e){let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(9);s[r]=Se.CHANNEL_WINDOW_ADJUST,P(s,t,++r),P(s,e,r+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),we(this,this._packetRW.write.finalize(s))}channelData(t,e){let r=Buffer.isBuffer(e),s=r?e.length:Buffer.byteLength(e),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(9+s);o[i]=Se.CHANNEL_DATA,P(o,t,++i),P(o,s,i+=4),r?o.set(e,i+=4):o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_DATA (r:${t}, ${s})`),we(this,this._packetRW.write.finalize(o))}channelExtData(t,e,r){let s=Buffer.isBuffer(e),i=s?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(13+i);a[o]=Se.CHANNEL_EXTENDED_DATA,P(a,t,++o),P(a,r,o+=4),P(a,i,o+=4),s?a.set(e,o+=4):a.utf8Write(e,o+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_EXTENDED_DATA (r:${t})`),we(this,this._packetRW.write.finalize(a))}channelOpenConfirm(t,e,r,s){let i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(17);o[i]=Se.CHANNEL_OPEN_CONFIRMATION,P(o,t,++i),P(o,e,i+=4),P(o,r,i+=4),P(o,s,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),we(this,this._packetRW.write.finalize(o))}channelOpenFail(t,e,r){typeof r!="string"&&(r="");let s=Buffer.byteLength(r),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(13+s+4);o[i]=Se.CHANNEL_OPEN_FAILURE,P(o,t,++i),P(o,e,i+=4),P(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),P(o,0,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),we(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,s=this._packetRW.write.alloc(5+e);s[r]=Se.SERVICE_REQUEST,P(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),we(this,this._packetRW.write.finalize(s))}authPassword(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=Buffer.byteLength(e),o=r?Buffer.byteLength(r):0,a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+s+4+14+4+8+1+4+i+(r?4+o:0));c[a]=Se.USERAUTH_REQUEST,P(c,s,++a),c.utf8Write(t,a+=4,s),P(c,14,a+=s),c.utf8Write("ssh-connection",a+=4,14),P(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=r?1:0,P(c,i,++a),Buffer.isBuffer(e)?Ws(e,c,0,i,a+=4):c.utf8Write(e,a+=4,i),r?(P(c,o,a+=i),Buffer.isBuffer(r)?Ws(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"),we(this,this._packetRW.write.finalize(c))}authPK(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");if(e=ad(e),e instanceof Error)throw new Error("Invalid key");let i=e.type;e=e.getPublicSSH(),typeof r=="function"&&(s=r,r=void 0),r||(r=i);let o=Buffer.byteLength(t),a=Buffer.byteLength(r),c=e.length,f=this._kex.sessionID,l=f.length,u=(s?4+l:0)+1+4+o+4+14+4+9+1+4+a+4+c,h,p;if(s?(h=Buffer.allocUnsafe(u),p=0,P(h,l,p),h.set(f,p+=4),p+=l):(h=this._packetRW.write.alloc(u),p=this._packetRW.write.allocStart),h[p]=Se.USERAUTH_REQUEST,P(h,o,++p),h.utf8Write(t,p+=4,o),P(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),P(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=s?1:0,P(h,a,++p),h.utf8Write(r,p+=4,a),P(h,c,p+=a),h.set(e,p+=4),!s){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),we(this,this._packetRW.write.finalize(h));return}s(h,_=>{if(_=cd(_,i),_===!1)throw new Error("Error while converting handshake signature");let E=_.length;p=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(5+o+4+14+4+9+1+4+a+4+c+4+4+a+4+E),h[p]=Se.USERAUTH_REQUEST,P(h,o,++p),h.utf8Write(t,p+=4,o),P(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),P(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=1,P(h,a,++p),h.utf8Write(r,p+=4,a),P(h,c,p+=a),h.set(e,p+=4),P(h,4+a+4+E,p+=c),P(h,a,p+=4),h.utf8Write(r,p+=4,a),P(h,E,p+=a),h.set(_,p+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),we(this,this._packetRW.write.finalize(h))})}authHostbased(t,e,r,s,i,o){if(this._server)throw new Error("Client-only method called in server mode");if(e=ad(e),e instanceof Error)throw new Error("Invalid key");let a=e.type;e=e.getPublicSSH(),typeof i=="function"&&(o=i,i=void 0),i||(i=a);let c=Buffer.byteLength(t),f=Buffer.byteLength(i),l=e.length,u=this._kex.sessionID,h=u.length,p=Buffer.byteLength(r),_=Buffer.byteLength(s),E=Buffer.allocUnsafe(4+h+1+4+c+4+14+4+9+4+f+4+l+4+p+4+_),b=0;P(E,h,b),E.set(u,b+=4),E[b+=h]=Se.USERAUTH_REQUEST,P(E,c,++b),E.utf8Write(t,b+=4,c),P(E,14,b+=c),E.utf8Write("ssh-connection",b+=4,14),P(E,9,b+=14),E.utf8Write("hostbased",b+=4,9),P(E,f,b+=9),E.utf8Write(i,b+=4,f),P(E,l,b+=f),E.set(e,b+=4),P(E,p,b+=l),E.utf8Write(r,b+=4,p),P(E,_,b+=p),E.utf8Write(s,b+=4,_),o(E,v=>{if(v=cd(v,a),!v)throw new Error("Error while converting handshake signature");let U=v.length,H=E.length-h-4;b=this._packetRW.write.allocStart;let C=this._packetRW.write.alloc(H+4+4+f+4+U);Ws(E,C,4+h,E.length,b),P(C,4+f+4+U,b+=H),P(C,f,b+=4),C.utf8Write(i,b+=4,f),P(C,U,b+=f),C.set(v,b+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),we(this,this._packetRW.write.finalize(C))})}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,s=this._packetRW.write.alloc(5+e+4+14+4+20+4+4);s[r]=Se.USERAUTH_REQUEST,P(s,e,++r),s.utf8Write(t,r+=4,e),P(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),P(s,20,r+=14),s.utf8Write("keyboard-interactive",r+=4,20),P(s,0,r+=20),P(s,0,r+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),we(this,this._packetRW.write.finalize(s))}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,s=this._packetRW.write.alloc(5+e+4+14+4+4);s[r]=Se.USERAUTH_REQUEST,P(s,e,++r),s.utf8Write(t,r+=4,e),P(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),P(s,4,r+=14),s.utf8Write("none",r+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),we(this,this._packetRW.write.finalize(s))}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 s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);if(i[s]=Se.USERAUTH_INFO_RESPONSE,t){P(i,t.length,++s),s+=4;for(let o=0;o<t.length;++o){let a=r[o];P(i,a,s),s+=4,a&&(i.utf8Write(t[o],s,a),s+=a)}}else P(i,0,++s);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),we(this,this._packetRW.write.finalize(i))}tcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+s+4);o[i]=Se.GLOBAL_REQUEST,P(o,13,++i),o.utf8Write("tcpip-forward",i+=4,13),o[i+=13]=r===void 0||r===!0?1:0,P(o,s,++i),o.utf8Write(t,i+=4,s),P(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),we(this,this._packetRW.write.finalize(o))}cancelTcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(30+s+4);o[i]=Se.GLOBAL_REQUEST,P(o,20,++i),o.utf8Write("cancel-tcpip-forward",i+=4,20),o[i+=20]=r===void 0||r===!0?1:0,P(o,s,++i),o.utf8Write(t,i+=4,s),P(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),we(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),s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(41+r);i[s]=Se.GLOBAL_REQUEST,P(i,31,++s),i.utf8Write("streamlocal-forward@openssh.com",s+=4,31),i[s+=31]=e===void 0||e===!0?1:0,P(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),we(this,this._packetRW.write.finalize(i))}openssh_cancelStreamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(48+r);i[s]=Se.GLOBAL_REQUEST,P(i,38,++s),i.utf8Write("cancel-streamlocal-forward@openssh.com",s+=4,38),i[s+=38]=e===void 0||e===!0?1:0,P(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),we(this,this._packetRW.write.finalize(i))}directTcpip(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(s.srcIP),o=Buffer.byteLength(s.dstIP),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(33+i+4+4+o+4);c[a]=Se.CHANNEL_OPEN,P(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),P(c,t,a+=12),P(c,e,a+=4),P(c,r,a+=4),P(c,o,a+=4),c.utf8Write(s.dstIP,a+=4,o),P(c,s.dstPort,a+=o),P(c,i,a+=4),c.utf8Write(s.srcIP,a+=4,i),P(c,s.srcPort,a+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),we(this,this._packetRW.write.finalize(c))}openssh_directStreamLocal(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(s.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(51+i+4+4);a[o]=Se.CHANNEL_OPEN,P(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),P(a,t,o+=30),P(a,e,o+=4),P(a,r,o+=4),P(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),Km(a,0,o+=i,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),we(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]=Se.GLOBAL_REQUEST,P(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)"),we(this,this._packetRW.write.finalize(r))}session(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(24);i[s]=Se.CHANNEL_OPEN,P(i,7,++s),i.utf8Write("session",s+=4,7),P(i,t,s+=7),P(i,e,s+=4),P(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),we(this,this._packetRW.write.finalize(i))}windowChange(t,e,r,s,i){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]=Se.CHANNEL_REQUEST,P(a,t,++o),P(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,P(a,r,++o),P(a,e,o+=4),P(a,i,o+=4),P(a,s,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),we(this,this._packetRW.write.finalize(a))}pty(t,e,r,s,i,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=Zm);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]=Se.CHANNEL_REQUEST,P(h,t,++u),P(h,7,u+=4),h.utf8Write("pty-req",u+=4,7),h[u+=7]=c===void 0||c===!0?1:0,P(h,f,++u),h.utf8Write(o,u+=4,f),P(h,r,u+=f),P(h,e,u+=4),P(h,i,u+=4),P(h,s,u+=4),P(h,l,u+=4),u+=4,Array.isArray(a))for(let p=0;p<l;++p)h[u++]=a[p];else Buffer.isBuffer(a)&&h.set(a,u);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),we(this,this._packetRW.write.finalize(h))}shell(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(15);s[r]=Se.CHANNEL_REQUEST,P(s,t,++r),P(s,5,r+=4),s.utf8Write("shell",r+=4,5),s[r+=5]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, shell)`),we(this,this._packetRW.write.finalize(s))}exec(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.isBuffer(e),i=s?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(18+i);a[o]=Se.CHANNEL_REQUEST,P(a,t,++o),P(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=r===void 0||r===!0?1:0,P(a,i,++o),s?a.set(e,o+=4):a.utf8Write(e,o+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exec: ${e})`),we(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)),sd[e]!==1)throw new Error(`Invalid signal: ${r}`);let s=e.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(20+s);o[i]=Se.CHANNEL_REQUEST,P(o,t,++i),P(o,6,i+=4),o.utf8Write("signal",i+=4,6),o[i+=6]=0,P(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),we(this,this._packetRW.write.finalize(o))}env(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=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+i+4+a);f[c]=Se.CHANNEL_REQUEST,P(f,t,++c),P(f,3,c+=4),f.utf8Write("env",c+=4,3),f[c+=3]=s===void 0||s===!0?1:0,P(f,i,++c),f.utf8Write(e,c+=4,i),P(f,a,c+=i),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})`),we(this,this._packetRW.write.finalize(f))}x11Forward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=e.protocol,i=e.cookie,o=Buffer.isBuffer(s),a=o?s.length:Buffer.byteLength(s),c=Buffer.isBuffer(i),f=c?i.length:Buffer.byteLength(i),l=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(22+a+4+f+4);u[l]=Se.CHANNEL_REQUEST,P(u,t,++l),P(u,7,l+=4),u.utf8Write("x11-req",l+=4,7),u[l+=7]=r===void 0||r===!0?1:0,u[++l]=e.single?1:0,P(u,a,++l),o?u.set(s,l+=4):u.utf8Write(s,l+=4,a),P(u,f,l+=a),c?u.set(i,l+=4):u.latin1Write(i,l+=4,f),P(u,e.screen||0,l+=f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),we(this,this._packetRW.write.finalize(u))}subsystem(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+s);o[i]=Se.CHANNEL_REQUEST,P(o,t,++i),P(o,9,i+=4),o.utf8Write("subsystem",i+=4,9),o[i+=9]=r===void 0||r===!0?1:0,P(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),we(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,s=this._packetRW.write.alloc(36);s[r]=Se.CHANNEL_REQUEST,P(s,t,++r),P(s,26,r+=4),s.utf8Write("auth-agent-req@openssh.com",r+=4,26),s[r+=26]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, auth-agent-req@openssh.com)`),we(this,this._packetRW.write.finalize(s))}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 s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(35+e);i[s]=Se.GLOBAL_REQUEST,P(i,29,++s),i.utf8Write("hostkeys-prove-00@openssh.com",s+=4,29),i[s+=29]=1,++s;for(let o of r)P(i,o.length,s),Ws(o,i,0,o.length,s+=4),s+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),we(this,this._packetRW.write.finalize(i))}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,s=this._packetRW.write.alloc(5+e);if(s[r]=Se.SERVICE_ACCEPT,P(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),we(this,this._packetRW.write.finalize(s)),this._server&&this._banner&&t==="ssh-userauth"){let i=this._banner;this._banner=void 0;let o=Buffer.byteLength(i);r=this._packetRW.write.allocStart;let a=this._packetRW.write.alloc(5+o+4);a[r]=Se.USERAUTH_BANNER,P(a,o,++r),a.utf8Write(i,r+=4,o),P(a,0,r+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),we(this,this._packetRW.write.finalize(a))}}forwardedTcpip(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.boundAddr),o=Buffer.byteLength(s.remoteAddr),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(36+i+4+4+o+4);c[a]=Se.CHANNEL_OPEN,P(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),P(c,t,a+=15),P(c,e,a+=4),P(c,r,a+=4),P(c,i,a+=4),c.utf8Write(s.boundAddr,a+=4,i),P(c,s.boundPort,a+=i),P(c,o,a+=4),c.utf8Write(s.remoteAddr,a+=4,o),P(c,s.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),we(this,this._packetRW.write.finalize(c))}x11(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.originAddr),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(24+i+4);a[o]=Se.CHANNEL_OPEN,P(a,3,++o),a.utf8Write("x11",o+=4,3),P(a,t,o+=3),P(a,e,o+=4),P(a,r,o+=4),P(a,i,o+=4),a.utf8Write(s.originAddr,o+=4,i),P(a,s.originPort,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),we(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 s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(39);i[s]=Se.CHANNEL_OPEN,P(i,22,++s),i.utf8Write("auth-agent@openssh.com",s+=4,22),P(i,t,s+=22),P(i,e,s+=4),P(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),we(this,this._packetRW.write.finalize(i))}openssh_forwardedStreamLocal(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(54+i+4);a[o]=Se.CHANNEL_OPEN,P(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),P(a,t,o+=33),P(a,e,o+=4),P(a,r,o+=4),P(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),P(a,0,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),we(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,s=this._packetRW.write.alloc(25);s[r]=Se.CHANNEL_REQUEST,P(s,t,++r),P(s,11,r+=4),s.utf8Write("exit-status",r+=4,11),s[r+=11]=0,P(s,e,++r),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),we(this,this._packetRW.write.finalize(s))}exitSignal(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=e;if(typeof i!="string"||!i)throw new Error(`Invalid signal: ${i}`);let o=e.toUpperCase();if(o.slice(0,3)==="SIG"&&(o=o.slice(3)),sd[o]!==1)throw new Error(`Invalid signal: ${i}`);let a=Buffer.byteLength(o),c=s?Buffer.byteLength(s):0,f=this._packetRW.write.allocStart,l=this._packetRW.write.alloc(25+a+1+4+c+4);l[f]=Se.CHANNEL_REQUEST,P(l,t,++f),P(l,11,f+=4),l.utf8Write("exit-signal",f+=4,11),l[f+=11]=0,P(l,a,++f),l.utf8Write(o,f+=4,a),l[f+=a]=r?1:0,P(l,c,++f),f+=4,c&&(l.utf8Write(s,f,c),f+=c),P(l,0,f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),we(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 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 s=r.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+s+1);o[i]=Se.USERAUTH_FAILURE,P(o,s,++i),o.utf8Write(r,i+=4,s),o[i+=s]=e===!0?1:0,this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_FAILURE"),we(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]=Se.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),we(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new pd),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new gd(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),s=e.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+r+4+s);o[i]=Se.USERAUTH_PK_OK,P(o,r,++i),o.utf8Write(t,i+=4,r),P(o,s,i+=r),o.set(e,i+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),we(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,s=this._packetRW.write.alloc(5+e+4);s[r]=Se.USERAUTH_PASSWD_CHANGEREQ,P(s,e,++r),s.utf8Write(t,r+=4,e),P(s,0,r+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),we(this,this._packetRW.write.finalize(s))}authInfoReq(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let s=0,i=t?Buffer.byteLength(t):0,o=e?Buffer.byteLength(e):0;for(let f=0;f<r.length;++f)s+=4+Buffer.byteLength(r[f].prompt)+1;let a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+i+4+o+4+4+s);c[a]=Se.USERAUTH_INFO_REQUEST,P(c,i,++a),a+=4,t&&(c.utf8Write(t,a,i),a+=i),P(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),P(c,0,a),P(c,r.length,a+=4),a+=4;for(let f=0;f<r.length;++f){let l=r[f],u=Buffer.byteLength(l.prompt);P(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"),we(this,this._packetRW.write.finalize(c))}},e0=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function t0(n,t,e){let r,s;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),s=this._buffer.length,t=0):(r=n,s=0);let i=t,o=t,a=t,c=!1,f=0,l=0;for(;t<r.length;++t){let u=r[t];if(u===13){c=!0;continue}if(u===10){if(a>o&&a-o>4&&r[o]===83&&r[o+1]===83&&r[o+2]===72&&r[o+3]===45){let h=r.latin1Slice(i,a+1),p=o===i?h:h.slice(o-i),_=e0.exec(p);if(!_)throw new Error("Invalid identification string");let E={greeting:o===i?"":h.slice(0,o-i),identRaw:p,versions:{protocol:_[1],software:_[2]},comments:_[3]};return this._remoteIdentRaw=Buffer.from(p),this._debug&&this._debug(`Remote ident: ${ld(p)}`),this._compatFlags=i0(E),this._buffer=void 0,this._decipher=new Mm(0,Wm.bind(this,{firstPacket:!0})),this._parse=n0,this._onHeader(E),this._destruct?(dd(this),t+1-s):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++l>Jm)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>=Xm)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=hd(r,i)),t-s}function n0(n,t,e){return this._decipher.decrypt(n,t,e)}function r0(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===Se.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new gd(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new pd));let e=qm[t];if(e===void 0){this._debug&&this._debug(`Inbound: Unsupported message type: ${t}`);return}return e(this,n)}function i0(n){let t=n.versions.software,e=0;for(let r of Om)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 s=0;s<t.length;++s){let i=t[s];if(i==="TTY_OP_END")continue;let o=Ta[i];if(o===void 0)continue;let a=n[i];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++]=Ta.TTY_OP_END,r<e.length?hd(e,0,r):e}function o0(n){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";Fm&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),r=n._packetRW.write.allocStart,s=n._packetRW.write.alloc(28+e);s[r]=Se.EXT_INFO,P(s,1,++r),P(s,15,r+=4),s.utf8Write("server-sig-algs",r+=4,15),P(s,e,r+=15),s.utf8Write(t,r+=4,e),n._debug&&n._debug("Outbound: Sending EXT_INFO"),we(n,n._packetRW.write.finalize(s))}Ad.exports=La});var Sd=ct(Ti=>{"use strict";var qs=require("assert"),{inspect:a0}=require("util");function Ed(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 yd(n,t){if(qs(typeof t=="string","`thing` has to be of type string"),Array.isArray(n)){let e=n.length;return qs(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)}`}Ti.ERR_INTERNAL_ASSERTION=class bd extends Error{constructor(t){super(),Error.captureStackTrace(this,bd);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?a0:o0:u.constructor!==hd&&(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 hd(u)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=u,this._cipher=new n0(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new u0,write:new d0(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 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 p=Buffer.allocUnsafe(8+t.ident.length);p.latin1Write("SSH-2.0-",0,8),p.set(t.ident,8),this._identRaw=p,h=Buffer.allocUnsafe(p.length+2),h.set(p,0),h[h.length-2]=13,h[h.length-1]=10}else this._identRaw=xd,h=g0;this._compatFlags=0,this._debug&&(t0?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${Ad(this._identRaw.toString())}`),this.start=()=>{this.start=void 0,f&&this._onWrite(f),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,r){for(;e<r;)e=this._parse(t,e,r)}disconnect(t){let r=this._packetRW.write.allocStartKEX,s=this._packetRW.write.alloc(13,!0),i=r+13;p0.has(t)||(t=yd.PROTOCOL_ERROR),s[r]=we.DISCONNECT,T(s,t,++r),s.fill(0,r+=4,i),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),Ie(this,this._packetRW.write.finalize(s,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(md.length);e.set(md,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),Ie(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],Ed(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]=we.REQUEST_SUCCESS,r.set(t,++e)):(r=this._packetRW.write.alloc(1),r[e]=we.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),Ie(this,this._packetRW.write.finalize(r))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=we.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),Ie(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=we.CHANNEL_SUCCESS,T(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),Ie(this,this._packetRW.write.finalize(r))}channelFailure(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=we.CHANNEL_FAILURE,T(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),Ie(this,this._packetRW.write.finalize(r))}channelEOF(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=we.CHANNEL_EOF,T(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),Ie(this,this._packetRW.write.finalize(r))}channelClose(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=we.CHANNEL_CLOSE,T(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),Ie(this,this._packetRW.write.finalize(r))}channelWindowAdjust(t,e){let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(9);s[r]=we.CHANNEL_WINDOW_ADJUST,T(s,t,++r),T(s,e,r+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),Ie(this,this._packetRW.write.finalize(s))}channelData(t,e){let r=Buffer.isBuffer(e),s=r?e.length:Buffer.byteLength(e),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(9+s);o[i]=we.CHANNEL_DATA,T(o,t,++i),T(o,s,i+=4),r?o.set(e,i+=4):o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_DATA (r:${t}, ${s})`),Ie(this,this._packetRW.write.finalize(o))}channelExtData(t,e,r){let s=Buffer.isBuffer(e),i=s?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(13+i);a[o]=we.CHANNEL_EXTENDED_DATA,T(a,t,++o),T(a,r,o+=4),T(a,i,o+=4),s?a.set(e,o+=4):a.utf8Write(e,o+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_EXTENDED_DATA (r:${t})`),Ie(this,this._packetRW.write.finalize(a))}channelOpenConfirm(t,e,r,s){let i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(17);o[i]=we.CHANNEL_OPEN_CONFIRMATION,T(o,t,++i),T(o,e,i+=4),T(o,r,i+=4),T(o,s,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),Ie(this,this._packetRW.write.finalize(o))}channelOpenFail(t,e,r){typeof r!="string"&&(r="");let s=Buffer.byteLength(r),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(13+s+4);o[i]=we.CHANNEL_OPEN_FAILURE,T(o,t,++i),T(o,e,i+=4),T(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),T(o,0,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),Ie(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,s=this._packetRW.write.alloc(5+e);s[r]=we.SERVICE_REQUEST,T(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),Ie(this,this._packetRW.write.finalize(s))}authPassword(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=Buffer.byteLength(e),o=r?Buffer.byteLength(r):0,a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+s+4+14+4+8+1+4+i+(r?4+o:0));c[a]=we.USERAUTH_REQUEST,T(c,s,++a),c.utf8Write(t,a+=4,s),T(c,14,a+=s),c.utf8Write("ssh-connection",a+=4,14),T(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=r?1:0,T(c,i,++a),Buffer.isBuffer(e)?Gs(e,c,0,i,a+=4):c.utf8Write(e,a+=4,i),r?(T(c,o,a+=i),Buffer.isBuffer(r)?Gs(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"),Ie(this,this._packetRW.write.finalize(c))}authPK(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");if(e=pd(e),e instanceof Error)throw new Error("Invalid key");let i=e.type;e=e.getPublicSSH(),typeof r=="function"&&(s=r,r=void 0),r||(r=i);let o=Buffer.byteLength(t),a=Buffer.byteLength(r),c=e.length,l=this._kex.sessionID,f=l.length,u=(s?4+f:0)+1+4+o+4+14+4+9+1+4+a+4+c,h,p;if(s?(h=Buffer.allocUnsafe(u),p=0,T(h,f,p),h.set(l,p+=4),p+=f):(h=this._packetRW.write.alloc(u),p=this._packetRW.write.allocStart),h[p]=we.USERAUTH_REQUEST,T(h,o,++p),h.utf8Write(t,p+=4,o),T(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),T(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=s?1:0,T(h,a,++p),h.utf8Write(r,p+=4,a),T(h,c,p+=a),h.set(e,p+=4),!s){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),Ie(this,this._packetRW.write.finalize(h));return}s(h,A=>{if(A=gd(A,i),A===!1)throw new Error("Error while converting handshake signature");let E=A.length;p=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(5+o+4+14+4+9+1+4+a+4+c+4+4+a+4+E),h[p]=we.USERAUTH_REQUEST,T(h,o,++p),h.utf8Write(t,p+=4,o),T(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),T(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=1,T(h,a,++p),h.utf8Write(r,p+=4,a),T(h,c,p+=a),h.set(e,p+=4),T(h,4+a+4+E,p+=c),T(h,a,p+=4),h.utf8Write(r,p+=4,a),T(h,E,p+=a),h.set(A,p+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),Ie(this,this._packetRW.write.finalize(h))})}authHostbased(t,e,r,s,i,o){if(this._server)throw new Error("Client-only method called in server mode");if(e=pd(e),e instanceof Error)throw new Error("Invalid key");let a=e.type;e=e.getPublicSSH(),typeof i=="function"&&(o=i,i=void 0),i||(i=a);let c=Buffer.byteLength(t),l=Buffer.byteLength(i),f=e.length,u=this._kex.sessionID,h=u.length,p=Buffer.byteLength(r),A=Buffer.byteLength(s),E=Buffer.allocUnsafe(4+h+1+4+c+4+14+4+9+4+l+4+f+4+p+4+A),S=0;T(E,h,S),E.set(u,S+=4),E[S+=h]=we.USERAUTH_REQUEST,T(E,c,++S),E.utf8Write(t,S+=4,c),T(E,14,S+=c),E.utf8Write("ssh-connection",S+=4,14),T(E,9,S+=14),E.utf8Write("hostbased",S+=4,9),T(E,l,S+=9),E.utf8Write(i,S+=4,l),T(E,f,S+=l),E.set(e,S+=4),T(E,p,S+=f),E.utf8Write(r,S+=4,p),T(E,A,S+=p),E.utf8Write(s,S+=4,A),o(E,x=>{if(x=gd(x,a),!x)throw new Error("Error while converting handshake signature");let R=x.length,H=E.length-h-4;S=this._packetRW.write.allocStart;let C=this._packetRW.write.alloc(H+4+4+l+4+R);Gs(E,C,4+h,E.length,S),T(C,4+l+4+R,S+=H),T(C,l,S+=4),C.utf8Write(i,S+=4,l),T(C,R,S+=l),C.set(x,S+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),Ie(this,this._packetRW.write.finalize(C))})}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,s=this._packetRW.write.alloc(5+e+4+14+4+20+4+4);s[r]=we.USERAUTH_REQUEST,T(s,e,++r),s.utf8Write(t,r+=4,e),T(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),T(s,20,r+=14),s.utf8Write("keyboard-interactive",r+=4,20),T(s,0,r+=20),T(s,0,r+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),Ie(this,this._packetRW.write.finalize(s))}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,s=this._packetRW.write.alloc(5+e+4+14+4+4);s[r]=we.USERAUTH_REQUEST,T(s,e,++r),s.utf8Write(t,r+=4,e),T(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),T(s,4,r+=14),s.utf8Write("none",r+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),Ie(this,this._packetRW.write.finalize(s))}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 s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);if(i[s]=we.USERAUTH_INFO_RESPONSE,t){T(i,t.length,++s),s+=4;for(let o=0;o<t.length;++o){let a=r[o];T(i,a,s),s+=4,a&&(i.utf8Write(t[o],s,a),s+=a)}}else T(i,0,++s);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),Ie(this,this._packetRW.write.finalize(i))}tcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+s+4);o[i]=we.GLOBAL_REQUEST,T(o,13,++i),o.utf8Write("tcpip-forward",i+=4,13),o[i+=13]=r===void 0||r===!0?1:0,T(o,s,++i),o.utf8Write(t,i+=4,s),T(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),Ie(this,this._packetRW.write.finalize(o))}cancelTcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(30+s+4);o[i]=we.GLOBAL_REQUEST,T(o,20,++i),o.utf8Write("cancel-tcpip-forward",i+=4,20),o[i+=20]=r===void 0||r===!0?1:0,T(o,s,++i),o.utf8Write(t,i+=4,s),T(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),Ie(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),s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(41+r);i[s]=we.GLOBAL_REQUEST,T(i,31,++s),i.utf8Write("streamlocal-forward@openssh.com",s+=4,31),i[s+=31]=e===void 0||e===!0?1:0,T(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),Ie(this,this._packetRW.write.finalize(i))}openssh_cancelStreamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(48+r);i[s]=we.GLOBAL_REQUEST,T(i,38,++s),i.utf8Write("cancel-streamlocal-forward@openssh.com",s+=4,38),i[s+=38]=e===void 0||e===!0?1:0,T(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),Ie(this,this._packetRW.write.finalize(i))}directTcpip(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(s.srcIP),o=Buffer.byteLength(s.dstIP),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(33+i+4+4+o+4);c[a]=we.CHANNEL_OPEN,T(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),T(c,t,a+=12),T(c,e,a+=4),T(c,r,a+=4),T(c,o,a+=4),c.utf8Write(s.dstIP,a+=4,o),T(c,s.dstPort,a+=o),T(c,i,a+=4),c.utf8Write(s.srcIP,a+=4,i),T(c,s.srcPort,a+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),Ie(this,this._packetRW.write.finalize(c))}openssh_directStreamLocal(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(s.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(51+i+4+4);a[o]=we.CHANNEL_OPEN,T(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),T(a,t,o+=30),T(a,e,o+=4),T(a,r,o+=4),T(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),f0(a,0,o+=i,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),Ie(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]=we.GLOBAL_REQUEST,T(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)"),Ie(this,this._packetRW.write.finalize(r))}session(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(24);i[s]=we.CHANNEL_OPEN,T(i,7,++s),i.utf8Write("session",s+=4,7),T(i,t,s+=7),T(i,e,s+=4),T(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),Ie(this,this._packetRW.write.finalize(i))}windowChange(t,e,r,s,i){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]=we.CHANNEL_REQUEST,T(a,t,++o),T(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,T(a,r,++o),T(a,e,o+=4),T(a,i,o+=4),T(a,s,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),Ie(this,this._packetRW.write.finalize(a))}pty(t,e,r,s,i,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=w0(a)),(!a||!a.length)&&(a=y0);let l=o.length,f=a.length,u=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(21+l+4+4+4+4+4+f);if(h[u]=we.CHANNEL_REQUEST,T(h,t,++u),T(h,7,u+=4),h.utf8Write("pty-req",u+=4,7),h[u+=7]=c===void 0||c===!0?1:0,T(h,l,++u),h.utf8Write(o,u+=4,l),T(h,r,u+=l),T(h,e,u+=4),T(h,i,u+=4),T(h,s,u+=4),T(h,f,u+=4),u+=4,Array.isArray(a))for(let p=0;p<f;++p)h[u++]=a[p];else Buffer.isBuffer(a)&&h.set(a,u);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),Ie(this,this._packetRW.write.finalize(h))}shell(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(15);s[r]=we.CHANNEL_REQUEST,T(s,t,++r),T(s,5,r+=4),s.utf8Write("shell",r+=4,5),s[r+=5]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, shell)`),Ie(this,this._packetRW.write.finalize(s))}exec(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.isBuffer(e),i=s?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(18+i);a[o]=we.CHANNEL_REQUEST,T(a,t,++o),T(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=r===void 0||r===!0?1:0,T(a,i,++o),s?a.set(e,o+=4):a.utf8Write(e,o+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exec: ${e})`),Ie(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)),dd[e]!==1)throw new Error(`Invalid signal: ${r}`);let s=e.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(20+s);o[i]=we.CHANNEL_REQUEST,T(o,t,++i),T(o,6,i+=4),o.utf8Write("signal",i+=4,6),o[i+=6]=0,T(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),Ie(this,this._packetRW.write.finalize(o))}env(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),o=Buffer.isBuffer(r),a=o?r.length:Buffer.byteLength(r),c=this._packetRW.write.allocStart,l=this._packetRW.write.alloc(17+i+4+a);l[c]=we.CHANNEL_REQUEST,T(l,t,++c),T(l,3,c+=4),l.utf8Write("env",c+=4,3),l[c+=3]=s===void 0||s===!0?1:0,T(l,i,++c),l.utf8Write(e,c+=4,i),T(l,a,c+=i),o?l.set(r,c+=4):l.utf8Write(r,c+=4,a),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, env: ${e}=${r})`),Ie(this,this._packetRW.write.finalize(l))}x11Forward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=e.protocol,i=e.cookie,o=Buffer.isBuffer(s),a=o?s.length:Buffer.byteLength(s),c=Buffer.isBuffer(i),l=c?i.length:Buffer.byteLength(i),f=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(22+a+4+l+4);u[f]=we.CHANNEL_REQUEST,T(u,t,++f),T(u,7,f+=4),u.utf8Write("x11-req",f+=4,7),u[f+=7]=r===void 0||r===!0?1:0,u[++f]=e.single?1:0,T(u,a,++f),o?u.set(s,f+=4):u.utf8Write(s,f+=4,a),T(u,l,f+=a),c?u.set(i,f+=4):u.latin1Write(i,f+=4,l),T(u,e.screen||0,f+=l),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),Ie(this,this._packetRW.write.finalize(u))}subsystem(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+s);o[i]=we.CHANNEL_REQUEST,T(o,t,++i),T(o,9,i+=4),o.utf8Write("subsystem",i+=4,9),o[i+=9]=r===void 0||r===!0?1:0,T(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),Ie(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,s=this._packetRW.write.alloc(36);s[r]=we.CHANNEL_REQUEST,T(s,t,++r),T(s,26,r+=4),s.utf8Write("auth-agent-req@openssh.com",r+=4,26),s[r+=26]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, auth-agent-req@openssh.com)`),Ie(this,this._packetRW.write.finalize(s))}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 s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(35+e);i[s]=we.GLOBAL_REQUEST,T(i,29,++s),i.utf8Write("hostkeys-prove-00@openssh.com",s+=4,29),i[s+=29]=1,++s;for(let o of r)T(i,o.length,s),Gs(o,i,0,o.length,s+=4),s+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),Ie(this,this._packetRW.write.finalize(i))}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,s=this._packetRW.write.alloc(5+e);if(s[r]=we.SERVICE_ACCEPT,T(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),Ie(this,this._packetRW.write.finalize(s)),this._server&&this._banner&&t==="ssh-userauth"){let i=this._banner;this._banner=void 0;let o=Buffer.byteLength(i);r=this._packetRW.write.allocStart;let a=this._packetRW.write.alloc(5+o+4);a[r]=we.USERAUTH_BANNER,T(a,o,++r),a.utf8Write(i,r+=4,o),T(a,0,r+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),Ie(this,this._packetRW.write.finalize(a))}}forwardedTcpip(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.boundAddr),o=Buffer.byteLength(s.remoteAddr),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(36+i+4+4+o+4);c[a]=we.CHANNEL_OPEN,T(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),T(c,t,a+=15),T(c,e,a+=4),T(c,r,a+=4),T(c,i,a+=4),c.utf8Write(s.boundAddr,a+=4,i),T(c,s.boundPort,a+=i),T(c,o,a+=4),c.utf8Write(s.remoteAddr,a+=4,o),T(c,s.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),Ie(this,this._packetRW.write.finalize(c))}x11(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.originAddr),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(24+i+4);a[o]=we.CHANNEL_OPEN,T(a,3,++o),a.utf8Write("x11",o+=4,3),T(a,t,o+=3),T(a,e,o+=4),T(a,r,o+=4),T(a,i,o+=4),a.utf8Write(s.originAddr,o+=4,i),T(a,s.originPort,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),Ie(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 s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(39);i[s]=we.CHANNEL_OPEN,T(i,22,++s),i.utf8Write("auth-agent@openssh.com",s+=4,22),T(i,t,s+=22),T(i,e,s+=4),T(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),Ie(this,this._packetRW.write.finalize(i))}openssh_forwardedStreamLocal(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(54+i+4);a[o]=we.CHANNEL_OPEN,T(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),T(a,t,o+=33),T(a,e,o+=4),T(a,r,o+=4),T(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),T(a,0,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),Ie(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,s=this._packetRW.write.alloc(25);s[r]=we.CHANNEL_REQUEST,T(s,t,++r),T(s,11,r+=4),s.utf8Write("exit-status",r+=4,11),s[r+=11]=0,T(s,e,++r),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),Ie(this,this._packetRW.write.finalize(s))}exitSignal(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=e;if(typeof i!="string"||!i)throw new Error(`Invalid signal: ${i}`);let o=e.toUpperCase();if(o.slice(0,3)==="SIG"&&(o=o.slice(3)),dd[o]!==1)throw new Error(`Invalid signal: ${i}`);let a=Buffer.byteLength(o),c=s?Buffer.byteLength(s):0,l=this._packetRW.write.allocStart,f=this._packetRW.write.alloc(25+a+1+4+c+4);f[l]=we.CHANNEL_REQUEST,T(f,t,++l),T(f,11,l+=4),f.utf8Write("exit-signal",l+=4,11),f[l+=11]=0,T(f,a,++l),f.utf8Write(o,l+=4,a),f[l+=a]=r?1:0,T(f,c,++l),l+=4,c&&(f.utf8Write(s,l,c),l+=c),T(f,0,l),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),Ie(this,this._packetRW.write.finalize(f))}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 s=r.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+s+1);o[i]=we.USERAUTH_FAILURE,T(o,s,++i),o.utf8Write(r,i+=4,s),o[i+=s]=e===!0?1:0,this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_FAILURE"),Ie(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]=we.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),Ie(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new bd),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new Sd(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),s=e.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+r+4+s);o[i]=we.USERAUTH_PK_OK,T(o,r,++i),o.utf8Write(t,i+=4,r),T(o,s,i+=r),o.set(e,i+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),Ie(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,s=this._packetRW.write.alloc(5+e+4);s[r]=we.USERAUTH_PASSWD_CHANGEREQ,T(s,e,++r),s.utf8Write(t,r+=4,e),T(s,0,r+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),Ie(this,this._packetRW.write.finalize(s))}authInfoReq(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let s=0,i=t?Buffer.byteLength(t):0,o=e?Buffer.byteLength(e):0;for(let l=0;l<r.length;++l)s+=4+Buffer.byteLength(r[l].prompt)+1;let a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+i+4+o+4+4+s);c[a]=we.USERAUTH_INFO_REQUEST,T(c,i,++a),a+=4,t&&(c.utf8Write(t,a,i),a+=i),T(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),T(c,0,a),T(c,r.length,a+=4),a+=4;for(let l=0;l<r.length;++l){let f=r[l],u=Buffer.byteLength(f.prompt);T(c,u,a),a+=4,u&&(c.utf8Write(f.prompt,a,u),a+=u),c[a++]=f.echo?1:0}this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_REQUEST"),Ie(this,this._packetRW.write.finalize(c))}},E0=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function _0(n,t,e){let r,s;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),s=this._buffer.length,t=0):(r=n,s=0);let i=t,o=t,a=t,c=!1,l=0,f=0;for(;t<r.length;++t){let u=r[t];if(u===13){c=!0;continue}if(u===10){if(a>o&&a-o>4&&r[o]===83&&r[o+1]===83&&r[o+2]===72&&r[o+3]===45){let h=r.latin1Slice(i,a+1),p=o===i?h:h.slice(o-i),A=E0.exec(p);if(!A)throw new Error("Invalid identification string");let E={greeting:o===i?"":h.slice(0,o-i),identRaw:p,versions:{protocol:A[1],software:A[2]},comments:A[3]};return this._remoteIdentRaw=Buffer.from(p),this._debug&&this._debug(`Remote ident: ${Ad(p)}`),this._compatFlags=x0(E),this._buffer=void 0,this._decipher=new r0(0,c0.bind(this,{firstPacket:!0})),this._parse=b0,this._onHeader(E),this._destruct?(Ed(this),t+1-s):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++f>A0)throw new Error("Max greeting lines exceeded");c=!1,o=t+1,l=0}else{if(c)throw new Error("Invalid header: expected newline");if(++l>=m0)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=_d(r,i)),t-s}function b0(n,t,e){return this._decipher.decrypt(n,t,e)}function S0(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===we.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new Sd(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new bd));let e=l0[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 i0)typeof r[0]=="string"?t===r[0]&&(e|=r[1]):r[0].test(t)&&(e|=r[1]);return e}function w0(n){let t=Object.keys(n),e=Buffer.allocUnsafe(5*t.length+1),r=0;for(let s=0;s<t.length;++s){let i=t[s];if(i==="TTY_OP_END")continue;let o=Fa[i];if(o===void 0)continue;let a=n[i];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++]=Fa.TTY_OP_END,r<e.length?_d(e,0,r):e}function I0(n){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";s0&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),r=n._packetRW.write.allocStart,s=n._packetRW.write.alloc(28+e);s[r]=we.EXT_INFO,T(s,1,++r),T(s,15,r+=4),s.utf8Write("server-sig-algs",r+=4,15),T(s,e,r+=15),s.utf8Write(t,r+=4,e),n._debug&&n._debug("Outbound: Sending EXT_INFO"),Ie(n,n._packetRW.write.finalize(s))}wd.exports=Ha});var Rd=lt(Di=>{"use strict";var Ys=require("assert"),{inspect:C0}=require("util");function Id(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 Cd(n,t){if(Ys(typeof t=="string","`thing` has to be of type string"),Array.isArray(n)){let e=n.length;return Ys(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)}`}Di.ERR_INTERNAL_ASSERTION=class vd extends Error{constructor(t){super(),Error.captureStackTrace(this,vd);let e=`This is caused by either a bug in ssh2 or incorrect usage of ssh2 internals.
12
12
  Please open an issue with this stack trace at https://github.com/mscdex/ssh2/issues
13
13
  `;this.message=t===void 0?e:`${t}
14
- ${e}`}};var c0=2**32,_d=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();Ti.ERR_OUT_OF_RANGE=class xd extends RangeError{constructor(t,e,r,s){super(),Error.captureStackTrace(this,xd),qs(e,'Missing "range" argument');let i=s?t:`The value of "${t}" is out of range.`,o;Number.isInteger(r)&&Math.abs(r)>c0?o=Ed(String(r)):typeof r=="bigint"?(o=String(r),(r>_d||r<-_d)&&(o=Ed(o)),o+="n"):o=a0(r),i+=` It must be ${e}. Received ${o}`,this.message=i}};var Ks=class n extends TypeError{constructor(t,e,r){super(),Error.captureStackTrace(this,n),qs(typeof t=="string","'name' must be a string");let s;typeof e=="string"&&e.startsWith("not ")?(s="must not be",e=e.replace(/^not /,"")):s="must be";let i;if(t.endsWith(" argument"))i=`The ${t} ${s} ${yd(e,"type")}`;else{let o=t.includes(".")?"property":"argument";i=`The "${t}" ${o} ${s} ${yd(e,"type")}`}i+=`. Received type ${typeof r}`,this.message=i}};Ti.ERR_INVALID_ARG_TYPE=Ks;Ti.validateNumber=function(t,e){if(typeof t!="number")throw new Ks(e,"number",t)}});var Li=ct((nS,Ud)=>{"use strict";var f0=require("events"),Jn=require("fs"),{constants:en}=Jn,{Readable:Bd,Writable:qa}=require("stream"),{inherits:Rd,types:{isDate:Ma}}=require("util"),l0=Buffer[Symbol.species],{bufferCopy:Xn,bufferSlice:qr,makeBufferParser:u0,writeUInt32BE:K}=gn(),Hn={SIZE:1,UIDGID:2,PERMISSIONS:4,ACMODTIME:8,EXTENDED:2147483648},Ne=Buffer.alloc(28),tt={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},d0=new Map(Object.values(tt).map(n=>[n,1])),h0={[tt.OK]:"No error",[tt.EOF]:"End of file",[tt.NO_SUCH_FILE]:"No such file or directory",[tt.PERMISSION_DENIED]:"Permission denied",[tt.FAILURE]:"Failure",[tt.BAD_MESSAGE]:"Bad message",[tt.NO_CONNECTION]:"No connection",[tt.CONNECTION_LOST]:"Connection lost",[tt.OP_UNSUPPORTED]:"Operation unsupported"},ke={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},tn={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},Ie={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},wd=2*1024,ut=2**32-1,p0=Buffer.from([0,0,0,5,ke.INIT,0,0,0,3]),g0=Buffer.from([0,0,0,5,tn.VERSION,0,0,0,3]),m0=/^SSH-2.0-(?:OpenSSH|dropbear)/,Ua=256*1024,M=u0(),A0={readable:!1,writable:!1,push:n=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function Nd(){}var Oa=class extends f0{constructor(t,e,r){super(),(typeof r!="object"||!r)&&(r={});let s=t._protocol._remoteIdentRaw;this.server=!!r.server,this._debug=typeof r.debug=="function"?r.debug:void 0,this._isOpenSSH=s&&m0.test(s),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=Ua,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?Ua:34e3)-wd,this._maxWriteLen=(this._isOpenSSH?Ua:34e3)-wd,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=A0,this.readable=!0}push(t){if(t===null){if(Dd(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 st(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return st(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 l0(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],s=this._pkt;this._pktLen=0,this._pktLenBytes=0,this._pkt=void 0,this._pktPos=0;let i=this.server?x0[r]:b0[r];if(!i)return st(this,`Unknown packet type ${r}`);if(this._version===-1){if(this.server){if(r!==ke.INIT)return st(this,`Expected INIT packet, got ${r}`)}else if(r!==tn.VERSION)return st(this,`Expected VERSION packet, got ${r}`)}if(i(this,s)===!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=Nd,this.server||Je(this,p0)}createReadStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new Qn(this,t,e)}createWriteStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new pn(this,t,e)}open(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");typeof r=="function"&&(s=r,r=void 0);let i=typeof e=="number"?e:Td(e);if(i===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=pr(r),o=r.flags,a=r.nb);let c=Buffer.byteLength(t),f=9,l=Buffer.allocUnsafe(13+c+4+4+a);K(l,l.length-4,0),l[4]=ke.OPEN;let u=this._writeReqid=this._writeReqid+1&ut;K(l,u,5),K(l,c,f),l.utf8Write(t,f+=4,c),K(l,i,f+=c),K(l,o,f+=4),a&&(f+=4,a===Ne.length?l.set(Ne,f):Xn(Ne,l,0,a,f),f+=a),this._requests[u]={cb:s};let h=Je(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 r=t.length,s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.CLOSE;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Je(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} CLOSE`)}read(t,e,r,s,i,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+s>e.length)throw new Error("length extends beyond buffer");if(i===null)throw new Error("null position currently unsupported");Pd(this,t,e,r,s,i,o)}readData(t,e,r,s,i,o){this.read(t,e,r,s,i,o)}write(t,e,r,s,i,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+s>e.length)throw new Error("length extends beyond buffer");if(i===null)throw new Error("null position currently unsupported");if(!s){o&&process.nextTick(o,void 0,0);return}let a=this._maxWriteLen,c=Math.max(s-a,0),f=i;c&&(s=a);let l=t.length,u=9,h=Buffer.allocUnsafe(13+l+8+4+s);K(h,h.length-4,0),h[4]=ke.WRITE;let p=this._writeReqid=this._writeReqid+1&ut;K(h,p,5),K(h,l,u),h.set(t,u+=4),u+=l;for(let E=7;E>=0;--E)h[u+E]=i&255,i/=256;K(h,s,u+=8),Xn(e,h,r,r+s,u+=4),this._requests[p]={cb:E=>{E?typeof o=="function"&&o(E):c?this.write(t,e,r+s,c,f+s,o):typeof o=="function"&&o(void 0,r+s)}};let _=Je(this,h);if(this._debug){let E=_?"Sent":"Buffered";this._debug(`SFTP: Outbound: ${E} WRITE (id:${p})`)}}writeData(t,e,r,s,i,o){this.write(t,e,r,s,i,o)}fastGet(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");Id(this,Jn,t,e,r,s)}fastPut(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");Id(Jn,this,t,e,r,s)}readFile(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof r=="function"?s=r:typeof e=="function"&&(s=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 i=e.encoding;if(i&&!Buffer.isEncoding(i))throw new Error(`Unknown encoding: ${i}`);let o,a,c,f=0,l,u=0,h=e.flag||"r",p=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(l,a,0,8192,u,_)):this.read(l,a,f,o-f,u,_)},_=(b,v)=>{let U;if(b){if(U=b.code===tt.EOF,!U)return this.close(l,()=>s&&s(b))}else U=!1;if(U||o===0&&v===0)return E();u+=v,f+=v,o!==0?f===o?E():p():(c.push(qr(a,0,v)),p())};_._wantEOFError=!0;let E=()=>{this.close(l,b=>(o===0?a=Buffer.concat(c,f):f<o&&(a=qr(a,0,f)),i&&(a=a.toString(i)),s&&s(b,a)))};this.open(t,h,438,(b,v)=>{if(b)return s&&s(b);l=v;let U=(H,C)=>{if(H){this.stat(t,(F,V)=>{if(F)return this.close(l,()=>{s&&s(H)});U(null,V)});return}if(o=C.size||0,o===0)return c=[],p();a=Buffer.allocUnsafe(o),p()};this.fstat(l,U)})}writeFile(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof s=="function"?i=s:typeof r=="function"&&(i=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)i&&i(a);else{let f=Buffer.isBuffer(e)?e:Buffer.from(""+e,r.encoding||"utf8"),l=/a/.test(o)?null:0;if(l===null){let u=(h,p)=>{if(h){this.stat(t,(_,E)=>{if(_)return this.close(c,()=>{i&&i(h)});u(null,E)});return}Fa(this,c,f,0,f.length,p.size,i)};this.fstat(c,u);return}Fa(this,c,f,0,f.length,l,i)}})}appendFile(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof s=="function"?i=s:typeof r=="function"&&(i=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,i)}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),s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.REMOVE;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Je(this,i);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 s=Buffer.byteLength(t),i=Buffer.byteLength(e),o=9,a=Buffer.allocUnsafe(13+s+4+i);K(a,a.length-4,0),a[4]=ke.RENAME;let c=this._writeReqid=this._writeReqid+1&ut;K(a,c,5),K(a,s,o),a.utf8Write(t,o+=4,s),K(a,i,o+=s),a.utf8Write(e,o+=4,i),this._requests[c]={cb:r};let f=Je(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 s=0,i=0;typeof e=="function"&&(r=e,e=void 0),typeof e=="object"&&e!==null&&(e=pr(e),s=e.flags,i=e.nb);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);K(c,c.length-4,0),c[4]=ke.MKDIR;let f=this._writeReqid=this._writeReqid+1&ut;K(c,f,5),K(c,o,a),c.utf8Write(t,a+=4,o),K(c,s,a+=o),i&&(a+=4,i===Ne.length?c.set(Ne,a):Xn(Ne,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Je(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 r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.RMDIR;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Je(this,i);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 s=!(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=(p,_)=>{if(p)return r(p);this.readdir(_,e,(E,b)=>{let v=E&&E.code===tt.EOF;if(E&&!v)return this.close(_,()=>r(E));if(v)return this.close(_,U=>{if(U)return r(U);r(void 0,l)});for(let U=0;U<b.length;++U,++u)l[u]=b[U];h(void 0,_)})};return this.opendir(t,h)}let i=t.length,o=9,a=Buffer.allocUnsafe(13+i);K(a,a.length-4,0),a[4]=ke.READDIR;let c=this._writeReqid=this._writeReqid+1&ut;K(a,c,5),K(a,i,o),a.set(t,o+=4),this._requests[c]={cb:s?(l,u)=>{if(typeof r=="function"){if(l)return r(l);for(let h=u.length-1;h>=0;--h)(u[h].filename==="."||u[h].filename==="..")&&u.splice(h,1);r(void 0,u)}}:r};let f=Je(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,s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.FSTAT;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Je(this,i);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),s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.STAT;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Je(this,i);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),s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.LSTAT;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Je(this,i);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),s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.OPENDIR;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Je(this,i);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 s=0,i=0;typeof e=="object"&&e!==null?(e=pr(e),s=e.flags,i=e.nb):typeof e=="function"&&(r=e);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);K(c,c.length-4,0),c[4]=ke.SETSTAT;let f=this._writeReqid=this._writeReqid+1&ut;K(c,f,5),K(c,o,a),c.utf8Write(t,a+=4,o),K(c,s,a+=o),i&&(a+=4,i===Ne.length?c.set(Ne,a):Xn(Ne,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Je(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"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 s=0,i=0;typeof e=="object"&&e!==null?(e=pr(e),s=e.flags,i=e.nb):typeof e=="function"&&(r=e);let o=t.length,a=9,c=Buffer.allocUnsafe(13+o+4+i);K(c,c.length-4,0),c[4]=ke.FSETSTAT;let f=this._writeReqid=this._writeReqid+1&ut;K(c,f,5),K(c,o,a),c.set(t,a+=4),K(c,s,a+=o),i&&(a+=4,i===Ne.length?c.set(Ne,a):Xn(Ne,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Je(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} FSETSTAT`)}futimes(t,e,r,s){return this.fsetstat(t,{atime:Qr(e),mtime:Qr(r)},s)}utimes(t,e,r,s){return this.setstat(t,{atime:Qr(e),mtime:Qr(r)},s)}fchown(t,e,r,s){return this.fsetstat(t,{uid:e,gid:r},s)}chown(t,e,r,s){return this.setstat(t,{uid:e,gid:r},s)}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),s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.READLINK;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.utf8Write(t,s+=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=Je(this,i);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 s=Buffer.byteLength(e),i=Buffer.byteLength(t),o=9,a=Buffer.allocUnsafe(13+s+4+i);K(a,a.length-4,0),a[4]=ke.SYMLINK;let c=this._writeReqid=this._writeReqid+1&ut;K(a,c,5),this._isOpenSSH?(K(a,i,o),a.utf8Write(t,o+=4,i),K(a,s,o+=i),a.utf8Write(e,o+=4,s)):(K(a,s,o),a.utf8Write(e,o+=4,s),K(a,i,o+=s),a.utf8Write(t,o+=4,i)),this._requests[c]={cb:r};let f=Je(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),s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=ke.REALPATH;let o=this._writeReqid=this._writeReqid+1&ut;K(i,o,5),K(i,r,s),i.utf8Write(t,s+=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=Je(this,i);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 s=this._extensions["posix-rename@openssh.com"];if(!s||s!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(41+i+4+o);K(c,c.length-4,0),c[4]=ke.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ut;K(c,f,5),K(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),K(c,i,a+=24),c.utf8Write(t,a+=4,i),K(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[f]={cb:r};let l=Je(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 r=this._extensions["statvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),i=9,o=Buffer.allocUnsafe(36+s);K(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ut;K(o,a,5),K(o,19,i),o.utf8Write("statvfs@openssh.com",i+=4,19),K(o,s,i+=19),o.utf8Write(t,i+=4,s),this._requests[a]={extended:"statvfs@openssh.com",cb:e};let c=Je(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 s=t.length,i=9,o=Buffer.allocUnsafe(37+s);K(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ut;K(o,a,5),K(o,20,i),o.utf8Write("fstatvfs@openssh.com",i+=4,20),K(o,s,i+=20),o.set(t,i+=4),this._requests[a]={extended:"fstatvfs@openssh.com",cb:e};let c=Je(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 i=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(37+i+4+o);K(c,c.length-4,0),c[4]=ke.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ut;K(c,f,5),K(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),K(c,i,a+=20),c.utf8Write(t,a+=4,i),K(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[f]={cb:r};let l=Je(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 s=t.length,i=9,o=Buffer.allocUnsafe(34+s);K(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ut;K(o,a,5),K(o,17,i),o.utf8Write("fsync@openssh.com",i+=4,17),K(o,s,i+=17),o.set(t,i+=4),this._requests[a]={cb:e};let c=Je(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 i=0,o=0;typeof e=="object"&&e!==null?(e=pr(e),i=e.flags,o=e.nb):typeof e=="function"&&(r=e);let a=Buffer.byteLength(t),c=9,f=Buffer.allocUnsafe(37+a+4+o);K(f,f.length-4,0),f[4]=ke.EXTENDED;let l=this._writeReqid=this._writeReqid+1&ut;K(f,l,5),K(f,20,c),f.utf8Write("lsetstat@openssh.com",c+=4,20),K(f,a,c+=20),f.utf8Write(t,c+=4,a),K(f,i,c+=a),o&&(c+=4,o===Ne.length?f.set(Ne,c):Xn(Ne,f,0,o,c),c+=o),this._requests[l]={cb:r};let u=Je(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 s=Buffer.byteLength(t),i=9,o=Buffer.allocUnsafe(40+s);K(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ut;K(o,a,5),K(o,23,i),o.utf8Write("expand-path@openssh.com",i+=4,23),K(o,s,i+=20),o.utf8Write(t,i+=4,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 expanded path"));e(void 0,l[0].filename)}}};let c=Je(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,s,i,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(s))throw new Error("Destination handle is not a Buffer");let c=0,f=Buffer.allocUnsafe(26+t.length+8+8+4+s.length+8);K(f,f.length-4,c),c+=4,f[c]=ke.EXTENDED,++c;let l=this._writeReqid=this._writeReqid+1&ut;K(f,l,c),c+=4,K(f,9,c),c+=4,f.utf8Write("copy-data",c,9),c+=9,K(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]=r&255,r/=256;c+=8,K(f,s.length,c),c+=4,f.set(s,c),c+=s.length;for(let h=7;h>=0;--h)f[c+h]=i&255,i/=256;this._requests[l]={cb:o};let u=Je(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 s=0,i=Buffer.byteLength(t),o=Buffer.allocUnsafe(31+i);K(o,o.length-4,s),s+=4,o[s]=ke.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&ut;K(o,a,s),s+=4,K(o,14,s),s+=4,o.utf8Write("home-directory",s,14),s+=14,K(o,i,s),s+=4,o.utf8Write(t,s,i),s+=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 home directory"));e(void 0,l[0].filename)}}};let c=Je(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 i=0,o=Buffer.allocUnsafe(47+4*t.length+4+4*e.length);K(o,o.length-4,i),i+=4,o[i]=ke.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&ut;K(o,a,i),i+=4,K(o,30,i),i+=4,o.utf8Write("users-groups-by-id@openssh.com",i,30),i+=30,K(o,4*t.length,i),i+=4;for(let f of t)K(o,f,i),i+=4;K(o,4*e.length,i),i+=4;for(let f of e)K(o,f,i),i+=4;this._requests[a]={extended:"users-groups-by-id@openssh.com",cb:r};let c=Je(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 s=9,i=Buffer.allocUnsafe(13+r);K(i,i.length-4,0),i[4]=tn.HANDLE,K(i,t,5),K(i,r,s),r&&i.set(e,s+=4);let o=Je(this,i);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(!d0.has(e))throw new Error(`Bad status code: ${e}`);r||(r="");let s=Buffer.byteLength(r),i=9,o=Buffer.allocUnsafe(17+s+4);K(o,o.length-4,0),o[4]=tn.STATUS,K(o,t,5),K(o,e,i),K(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),K(o,0,i);let a=Je(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 s=Buffer.isBuffer(e);if(!s&&typeof e!="string")throw new Error("data is not a Buffer or string");let i;!s&&!r&&(r=void 0,i=!0);let o=s?e.length:Buffer.byteLength(e,r),a=9,c=Buffer.allocUnsafe(13+o);K(c,c.length-4,0),c[4]=tn.DATA,K(c,t,5),K(c,o,a),o&&(s?c.set(e,a+=4):i?c.utf8Write(e,a+=4,o):c.write(e,a+=4,o,r));let f=Je(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,s=0,i,o=[];for(let l=0;l<r;++l){let u=e[l],h=!u||!u.filename||typeof u.filename!="string"?"":u.filename;s+=4+Buffer.byteLength(h);let p=!u||!u.longname||typeof u.longname!="string"?"":u.longname;if(s+=4+Buffer.byteLength(p),typeof u.attrs=="object"&&u.attrs!==null){if(i=pr(u.attrs),s+=4+i.nb,i.nb){let _;i.nb===Ne.length?_=new Uint8Array(Ne):(_=new Uint8Array(i.nb),Xn(Ne,_,0,i.nb,0)),i.bytes=_}o.push(i)}else s+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+s);K(c,c.length-4,0),c[4]=tn.NAME,K(c,t,5),K(c,r,a),a+=4;for(let l=0;l<r;++l){let u=e[l];{let p=!u||!u.filename||typeof u.filename!="string"?"":u.filename,_=Buffer.byteLength(p);K(c,_,a),a+=4,_&&(c.utf8Write(p,a,_),a+=_)}{let p=!u||!u.longname||typeof u.longname!="string"?"":u.longname,_=Buffer.byteLength(p);K(c,_,a),a+=4,_&&(c.utf8Write(p,a,_),a+=_)}let h=o[l];h?(K(c,h.flags,a),a+=4,h.flags&&h.bytes&&(c.set(h.bytes,a),a+=h.nb)):(K(c,0,a),a+=4)}let f=Je(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=pr(e);let r=e.flags,s=e.nb,i=9,o=Buffer.allocUnsafe(13+s);K(o,o.length-4,0),o[4]=tn.ATTRS,K(o,t,5),K(o,r,i),s&&(i+=4,s===Ne.length?o.set(Ne,i):Xn(Ne,o,0,s,i),i+=s);let a=Je(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function E0(n){try{return Buffer.allocUnsafe(n)}catch(t){return t}}function Pd(n,t,e,r,s,i,o,a){let c=n._maxReadLen,f=Math.max(s-c,0);f&&(s=c);let l=t.length,u=9,h=i,p=Buffer.allocUnsafe(13+l+8+4);K(p,p.length-4,0),p[4]=ke.READ;let _=n._writeReqid=n._writeReqid+1&ut;K(p,_,5),K(p,l,u),p.set(t,u+=4),u+=l;for(let v=7;v>=0;--v)p[u+v]=h&255,h/=256;K(p,s,u+=8),typeof o!="function"&&(o=Nd);let E=a||{nb:0,position:i,off:r,origOff:r,len:void 0,overflow:void 0,cb:(v,U,H)=>{let C=E.len,F=E.overflow;if(v){if(o._wantEOFError||v.code!==tt.EOF)return o(v)}else{if(H>C)return o(new Error("Received more data than requested"));if(H===C&&F){E.nb+=H,E.position+=H,E.off+=H,Pd(n,t,e,E.off,F,E.position,o,E);return}}H=H||0,E.origOff===0&&e.length===E.nb?U=e:U=qr(e,E.origOff,E.origOff+E.nb+H),o(void 0,E.nb+H,U,E.position)},buffer:void 0};E.len=s,E.overflow=f,E.buffer=qr(e,r,r+s),n._requests[_]=E;let b=Je(n,p);n._debug&&n._debug(`SFTP: Outbound: ${b?"Buffered":"Sending"} READ`)}function Id(n,t,e,r,s,i){let o=64,a=32768,c,f,l;typeof s=="function"?i=s:typeof s=="object"&&s!==null&&(typeof s.concurrency=="number"&&s.concurrency>0&&!isNaN(s.concurrency)&&(o=s.concurrency),typeof s.chunkSize=="number"&&s.chunkSize>0&&!isNaN(s.chunkSize)&&(a=s.chunkSize),typeof s.fileSize=="number"&&s.fileSize>0&&!isNaN(s.fileSize)&&(l=s.fileSize),typeof s.step=="function"&&(c=s.step),(typeof s.mode=="string"||typeof s.mode=="number")&&(f=Ka(s.mode)));let u,h=0,p=0,_=!1,E,b,v,U=a*o;function H(C){if(_)return;_=!0;let F=0,V;E||b?(V=()=>{--F===0&&i(C)},E&&(n===Jn||n.outgoing.state==="open")&&++F,b&&(t===Jn||t.outgoing.state==="open")&&++F,E&&(n===Jn||n.outgoing.state==="open")&&n.close(E,V),b&&(t===Jn||t.outgoing.state==="open")&&t.close(b,V)):i(C)}n.open(e,"r",(C,F)=>{if(C)return H(C);E=F,l===void 0?n.fstat(E,V):V(null,{size:l});function V(N,x){if(N){if(n!==Jn){n.stat(e,(S,I)=>{if(S)return H(N);V(null,I)});return}return H(N)}u=x.size,t.open(r,"w",(S,I)=>{if(S)return H(S);if(b=I,u<=0)return H();for(;U>u;){if(o===1){U=u;break}U-=a,--o}if(v=E0(U),v instanceof Error)return H(v);f!==void 0?t.fchmod(b,f,function Y(te){if(te){t.chmod(r,f,ce=>Y());return}z()}):z();function k(Y,te,ce,$,B,T){if(Y)return H(Y);B=B||0,t.write(b,v,B,te,$,q);function q(ee){if(ee)return H(ee);if(p+=te,c&&c(p,te,u),te<T)return ne(B,$+te,T-te);if(p===u){t.close(b,ie=>{if(b=void 0,ie)return H(ie);n.close(E,je=>{if(E=void 0,je)return H(je);i()})});return}if(h>=u)return;let fe=h+a>u?u-h:a;ne(B,h,fe),h+=fe}}function R(Y,te,ce){return($,B,T)=>{k($,B,T,te,Y,ce)}}function ne(Y,te,ce){n.read(E,v,Y,ce,te,R(Y,te,ce))}function z(){let Y=0,te=0;for(;h<u&&Y<o;){let ce=h+a>u?u-h:a;ne(te,h,ce),te+=ce,h+=ce,++Y}}})}})}function Fa(n,t,e,r,s,i,o){let a=typeof o=="function"?o:void 0;n.write(t,e,r,s,i,(c,f)=>{if(c)return n.close(t,()=>{a&&a(c)});f===s?n.close(t,a):(r+=f,s-=f,i+=f,Fa(n,t,e,r,s,i,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&en.S_IFMT)===en.S_IFDIR}isFile(){return(this.mode&en.S_IFMT)===en.S_IFREG}isBlockDevice(){return(this.mode&en.S_IFMT)===en.S_IFBLK}isCharacterDevice(){return(this.mode&en.S_IFMT)===en.S_IFCHR}isSymbolicLink(){return(this.mode&en.S_IFMT)===en.S_IFLNK}isFIFO(){return(this.mode&en.S_IFMT)===en.S_IFIFO}isSocket(){return(this.mode&en.S_IFMT)===en.S_IFSOCK}};function pr(n){let t=0,e=0;if(typeof n=="object"&&n!==null){if(typeof n.size=="number"){t|=Hn.SIZE;let r=n.size;Ne[e++]=r/72057594037927940,Ne[e++]=r/281474976710656,Ne[e++]=r/1099511627776,Ne[e++]=r/4294967296,Ne[e++]=r/16777216,Ne[e++]=r/65536,Ne[e++]=r/256,Ne[e++]=r}if(typeof n.uid=="number"&&typeof n.gid=="number"){t|=Hn.UIDGID;let r=n.uid,s=n.gid;Ne[e++]=r>>>24,Ne[e++]=r>>>16,Ne[e++]=r>>>8,Ne[e++]=r,Ne[e++]=s>>>24,Ne[e++]=s>>>16,Ne[e++]=s>>>8,Ne[e++]=s}if(typeof n.mode=="number"||typeof n.mode=="string"){let r=Ka(n.mode);t|=Hn.PERMISSIONS,Ne[e++]=r>>>24,Ne[e++]=r>>>16,Ne[e++]=r>>>8,Ne[e++]=r}if((typeof n.atime=="number"||Ma(n.atime))&&(typeof n.mtime=="number"||Ma(n.mtime))){let r=Qr(n.atime),s=Qr(n.mtime);t|=Hn.ACMODTIME,Ne[e++]=r>>>24,Ne[e++]=r>>>16,Ne[e++]=r>>>8,Ne[e++]=r,Ne[e++]=s>>>24,Ne[e++]=s>>>16,Ne[e++]=s>>>8,Ne[e++]=s}}return{flags:t,nb:e}}function Qr(n){if(typeof n=="number"&&n===n)return n;if(Ma(n))return parseInt(n.getTime()/1e3,10);throw new Error(`Cannot parse time: ${n}`)}function Ka(n){if(typeof n=="number"&&n===n)return n;if(typeof n=="string")return Ka(parseInt(n,8));throw new Error(`Cannot parse mode: ${n}`)}var Ha={r:Ie.READ,"r+":Ie.READ|Ie.WRITE,w:Ie.TRUNC|Ie.CREAT|Ie.WRITE,wx:Ie.TRUNC|Ie.CREAT|Ie.WRITE|Ie.EXCL,xw:Ie.TRUNC|Ie.CREAT|Ie.WRITE|Ie.EXCL,"w+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE,"wx+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,"xw+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,a:Ie.APPEND|Ie.CREAT|Ie.WRITE,ax:Ie.APPEND|Ie.CREAT|Ie.WRITE|Ie.EXCL,xa:Ie.APPEND|Ie.CREAT|Ie.WRITE|Ie.EXCL,"a+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE,"ax+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,"xa+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL};function Td(n){let t=Ha[n];return t!==void 0?t:null}var y0=(()=>{let n=Object.keys(Ha);return t=>{for(let e=0;e<n.length;++e){let r=n[e];if(Ha[r]===t)return r}return null}})();function Wr(n){let t=M.readUInt32BE();if(t===void 0)return;let e=new Gs;if(t&Hn.SIZE){let r=M.readUInt64BE(n);if(r===void 0)return;e.size=r}if(t&Hn.UIDGID){let r=M.readUInt32BE(),s=M.readUInt32BE();if(s===void 0)return;e.uid=r,e.gid=s}if(t&Hn.PERMISSIONS){let r=M.readUInt32BE();if(r===void 0)return;e.mode=r}if(t&Hn.ACMODTIME){let r=M.readUInt32BE(),s=M.readUInt32BE();if(s===void 0)return;e.atime=r,e.mtime=s}if(t&Hn.EXTENDED){let r=M.readUInt32BE();if(r===void 0)return;let s={};for(let i=0;i<r;++i){let o=M.readString(!0),a=M.readString();if(a===void 0)return;s[o]=a}e.extended=s}return e}function Je(n,t){let e=Ld(n,t);return e!==void 0?(n._buffer.push(e),!1):!0}function Ld(n,t){let e=n.outgoing;if(e.state!=="open")return;if(e.window===0)return n._waitWindow=!0,n._chunkcb=Cd,t;let r,s=t.length,i=0;for(;s-i>0&&e.window>0;){let o=Math.min(s-i,e.window,e.packetSize);e.window-=o,e.window===0&&(n._waitWindow=!0,n._chunkcb=Cd),i===0&&o===s?n._protocol.channelData(n.outgoing.id,t):n._protocol.channelData(n.outgoing.id,qr(t,i,i+o)),i+=o}return s-i>0&&(i>0?r=qr(t,i,s):r=t),r}function Cd(){this._chunkcb=void 0;let n=this._buffer,t=0;for(;t<n.length;){let e=n[t],r=Ld(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 st(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(),Dd(n),!1}function Dd(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 s=0;s<t.length;++s){let i=e[t[s]];typeof i.cb=="function"&&i.cb(r)}}function _0(n,t){let e=9,r=Buffer.allocUnsafe(31);K(r,r.length-4,0),r[4]=ke.EXTENDED;let s=n._writeReqid=n._writeReqid+1&ut;K(r,s,5),K(r,18,e),r.utf8Write("limits@openssh.com",e+=4,18),n._requests[s]={extended:"limits@openssh.com",cb:t};let i=Je(n,r);if(n._debug){let o=i?"Buffered":"Sending";n._debug(`SFTP: Outbound: ${o} limits@openssh.com`)}}var b0={[tn.VERSION]:(n,t)=>{if(n._version!==-1)return st(n,"Duplicate VERSION packet");let e={};M.init(t,1);let r=M.readUInt32BE();for(;M.avail();){let s=M.readString(!0),i=M.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(M.clear(),r===void 0)return st(n,"Malformed VERSION packet");if(n._debug){let s=Object.keys(e);s.length?n._debug(`SFTP: Inbound: Received VERSION (v${r}, exts:${s})`):n._debug(`SFTP: Inbound: Received VERSION (v${r})`)}if(n._version=r,n._extensions=e,e["limits@openssh.com"]==="1")return _0(n,(s,i)=>{s||(i.maxPktLen>0&&(n._maxOutPktLen=i.maxPktLen),i.maxReadLen>0&&(n._maxReadLen=i.maxReadLen),i.maxWriteLen>0&&(n._maxWriteLen=i.maxWriteLen),n.maxOpenHandles=i.maxOpenHandles>0?i.maxOpenHandles:1/0),n.emit("ready")});n.emit("ready")},[tn.STATUS]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readUInt32BE(),s=M.readString(!0);if(M.clear(),n._debug){let o=JSON.stringify(s);n._debug(`SFTP: Inbound: Received STATUS (id:${e}, ${r}, ${o})`)}let i=n._requests[e];if(delete n._requests[e],i&&typeof i.cb=="function"){if(r===tt.OK){i.cb();return}let o=new Error(s||h0[r]||"Unknown status");o.code=r,i.cb(o)}},[tn.HANDLE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0)return e!==void 0&&delete n._requests[e],st(n,"Malformed HANDLE packet");n._debug&&n._debug(`SFTP: Inbound: Received HANDLE (id:${e})`);let s=n._requests[e];delete n._requests[e],s&&typeof s.cb=="function"&&s.cb(void 0,r)},[tn.DATA]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;if(e!==void 0&&(r=n._requests[e],delete n._requests[e]),r&&typeof r.cb=="function")if(r.buffer){let s=M.readString(r.buffer);if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`),r.cb(void 0,r.buffer,s);return}}else{let s=M.readString();if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s.length})`),r.cb(void 0,s);return}}else{let s=M.skipString();if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`);return}}return st(n,"Malformed DATA packet")},[tn.NAME]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=M.readUInt32BE();if(s!==void 0){let i=[];for(let o=0;o<s;++o){let a=M.readString(!0),c=M.readString(!0),f=Wr(n._biOpt);if(f===void 0){i=void 0;break}i.push({filename:a,longname:c,attrs:f})}if(i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received NAME (id:${e}, ${i.length})`),M.clear(),r&&typeof r.cb=="function"&&r.cb(void 0,i);return}}return M.clear(),st(n,"Malformed NAME packet")},[tn.ATTRS]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=Wr(n._biOpt);if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received ATTRS (id:${e})`),r&&typeof r.cb=="function"&&r.cb(void 0,s);return}return st(n,"Malformed ATTRS packet")},[tn.EXTENDED]:(n,t)=>{M.init(t,1);let e=M.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 s=n._biOpt,i={f_bsize:M.readUInt64BE(s),f_frsize:M.readUInt64BE(s),f_blocks:M.readUInt64BE(s),f_bfree:M.readUInt64BE(s),f_bavail:M.readUInt64BE(s),f_files:M.readUInt64BE(s),f_ffree:M.readUInt64BE(s),f_favail:M.readUInt64BE(s),f_sid:M.readUInt64BE(s),f_flag:M.readUInt64BE(s),f_namemax:M.readUInt64BE(s)};if(i.f_namemax===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,i);return}case"limits@openssh.com":{let s={maxPktLen:M.readUInt64BE(),maxReadLen:M.readUInt64BE(),maxWriteLen:M.readUInt64BE(),maxOpenHandles:M.readUInt64BE()};if(s.maxOpenHandles===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,s);return}case"users-groups-by-id@openssh.com":{let s=M.readUInt32BE();if(s===void 0)break;let i=new Array(s);for(let c=0;c<i.length;++c)i[c]=M.readString(!0);let o=M.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=M.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})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,i,a);return}default:n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),M.clear(),typeof r.cb=="function"&&r.cb();return}else{n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),M.clear();return}}return M.clear(),st(n,"Malformed EXTENDED_REPLY packet")}},x0={[ke.INIT]:(n,t)=>{if(n._version!==-1)return st(n,"Duplicate INIT packet");let e={};M.init(t,1);let r=M.readUInt32BE();for(;M.avail();){let s=M.readString(!0),i=M.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(M.clear(),r===void 0)return st(n,"Malformed INIT packet");if(n._debug){let s=Object.keys(e);s.length?n._debug(`SFTP: Inbound: Received INIT (v${r}, exts:${s})`):n._debug(`SFTP: Inbound: Received INIT (v${r})`)}Je(n,g0),n._version=r,n._extensions=e,n.emit("ready")},[ke.OPEN]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readUInt32BE(),i=Wr(n._biOpt);if(M.clear(),i===void 0)return st(n,"Malformed OPEN packet");n._debug&&n._debug(`SFTP: Inbound: Received OPEN (id:${e})`),n.emit("OPEN",e,r,s,i)||n.status(e,tt.OP_UNSUPPORTED)},[ke.CLOSE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return st(n,"Malformed CLOSE packet");n._debug&&n._debug(`SFTP: Inbound: Received CLOSE (id:${e})`),n.emit("CLOSE",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.READ]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=M.readUInt64BE(n._biOpt),i=M.readUInt32BE();if(M.clear(),i===void 0||r.length>256)return st(n,"Malformed READ packet");n._debug&&n._debug(`SFTP: Inbound: Received READ (id:${e})`),n.emit("READ",e,r,s,i)||n.status(e,tt.OP_UNSUPPORTED)},[ke.WRITE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=M.readUInt64BE(n._biOpt),i=M.readString();if(M.clear(),i===void 0||r.length>256)return st(n,"Malformed WRITE packet");n._debug&&n._debug(`SFTP: Inbound: Received WRITE (id:${e})`),n.emit("WRITE",e,r,s,i)||n.status(e,tt.OP_UNSUPPORTED)},[ke.LSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed LSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received LSTAT (id:${e})`),n.emit("LSTAT",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.FSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return st(n,"Malformed FSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSTAT (id:${e})`),n.emit("FSTAT",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.SETSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=Wr(n._biOpt);if(M.clear(),s===void 0)return st(n,"Malformed SETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received SETSTAT (id:${e})`),n.emit("SETSTAT",e,r,s)||n.status(e,tt.OP_UNSUPPORTED)},[ke.FSETSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=Wr(n._biOpt);if(M.clear(),s===void 0||r.length>256)return st(n,"Malformed FSETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSETSTAT (id:${e})`),n.emit("FSETSTAT",e,r,s)||n.status(e,tt.OP_UNSUPPORTED)},[ke.OPENDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed OPENDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received OPENDIR (id:${e})`),n.emit("OPENDIR",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.READDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return st(n,"Malformed READDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received READDIR (id:${e})`),n.emit("READDIR",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.REMOVE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed REMOVE packet");n._debug&&n._debug(`SFTP: Inbound: Received REMOVE (id:${e})`),n.emit("REMOVE",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.MKDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=Wr(n._biOpt);if(M.clear(),s===void 0)return st(n,"Malformed MKDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received MKDIR (id:${e})`),n.emit("MKDIR",e,r,s)||n.status(e,tt.OP_UNSUPPORTED)},[ke.RMDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed RMDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received RMDIR (id:${e})`),n.emit("RMDIR",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.REALPATH]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed REALPATH packet");n._debug&&n._debug(`SFTP: Inbound: Received REALPATH (id:${e})`),n.emit("REALPATH",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.STAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed STAT packet");n._debug&&n._debug(`SFTP: Inbound: Received STAT (id:${e})`),n.emit("STAT",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.RENAME]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readString(!0);if(M.clear(),s===void 0)return st(n,"Malformed RENAME packet");n._debug&&n._debug(`SFTP: Inbound: Received RENAME (id:${e})`),n.emit("RENAME",e,r,s)||n.status(e,tt.OP_UNSUPPORTED)},[ke.READLINK]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed READLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received READLINK (id:${e})`),n.emit("READLINK",e,r)||n.status(e,tt.OP_UNSUPPORTED)},[ke.SYMLINK]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readString(!0);if(M.clear(),s===void 0)return st(n,"Malformed SYMLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received SYMLINK (id:${e})`);let i;n._isOpenSSH?i=n.emit("SYMLINK",e,s,r):i=n.emit("SYMLINK",e,r,s),i||n.status(e,tt.OP_UNSUPPORTED)},[ke.EXTENDED]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(r===void 0)return M.clear(),st(n,"Malformed EXTENDED packet");let s;M.avail()&&(s=M.readRaw()),M.clear(),n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED (id:${e})`),n.emit("EXTENDED",e,r,s)||n.status(e,tt.OP_UNSUPPORTED)}},{ERR_INVALID_ARG_TYPE:S0,ERR_OUT_OF_RANGE:Vs,validateNumber:w0}=Sd(),vd=128,Xt,Qa=[];function I0(n){Qa.length>0?Xt=Qa.pop():Xt=Buffer.allocUnsafe(n),Xt.used=0}function Wa(n,t){if(!Number.isSafeInteger(n))throw w0(n,t),Number.isInteger(n)?new Vs(t,">= 0 and <= 2 ** 53 - 1",n):new Vs(t,"an integer",n);if(n<0)throw new Vs(t,">= 0 and <= 2 ** 53 - 1",n)}function $a(n){return n+7&-8}function Qn(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,Bd.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&&(Wa(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(Wa(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new Vs("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}Rd(Qn,Bd);Qn.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()}))};Qn.prototype._read=function(n){if(!Buffer.isBuffer(this.handle))return this.once("open",()=>this._read(n));if(this.destroyed)return;(!Xt||Xt.length-Xt.used<vd)&&I0(this.readableHighWaterMark||this._readableState.highWaterMark);let t=Xt,e=Math.min(Xt.length-Xt.used,n),r=Xt.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,Xt,Xt.used,e,this.pos,(s,i)=>{if(s){this.emit("error",s),this.autoClose&&this.destroy();return}let o=null;if(r+e===t.used&&t===Xt)t.used=$a(t.used+i-e);else{let a=r+e&-8,c=$a(r+i);a-c>=vd&&Qa.push(t.slice(c,a))}i>0&&(this.bytesRead+=i,o=t.slice(r,r+i)),this.pos+=i,this.push(o)}),Xt.used=$a(Xt.used+e)};Qn.prototype._destroy=function(n,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",kd.bind(null,this,t,n));return}kd(this,t,n),this.handle=null,this._opening=!1};function kd(n,t,e){if(!n.handle)return r();n.sftp.close(n.handle,r);function r(s){s=s||e,t(s),n.isClosed=!0,s||n.emit("close")}}Qn.prototype.close=function(n){this.destroy(null,n)};Object.defineProperty(Qn.prototype,"pending",{get(){return this.handle===null},configurable:!0});function pn(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,qa.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&&(Wa(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()}Rd(pn,qa);pn.prototype._final=function(n){this.autoClose&&this.destroy(),n()};pn.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,s=>e());return}if(this.flags[0]==="a"){let s=(i,o)=>{if(i){this.sftp.stat(this.path,(a,c)=>{if(a){this.destroy(),this.emit("error",i);return}s(null,c)});return}this.pos=o.size,this.emit("open",t),this.emit("ready")};this.sftp.fstat(t,s);return}this.emit("open",t),this.emit("ready")};this.sftp.fchmod(t,this.mode,e)}))};pn.prototype._write=function(n,t,e){if(!Buffer.isBuffer(n)){let r=new S0("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,s)=>{if(r)return this.autoClose&&this.destroy(),e(r);this.bytesWritten+=s,e()}),this.pos+=n.length};pn.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,s=n.length,i=(o,a)=>{if(o)return this.destroy(),t(o);this.bytesWritten+=a,--s===0&&t()};for(let o=0;o<n.length;++o){let a=n[o].chunk;e.write(r,a,0,a.length,this.pos,i),this.pos+=a.length}};typeof qa.prototype.destroy!="function"&&(pn.prototype.destroy=Qn.prototype.destroy);pn.prototype._destroy=Qn.prototype._destroy;pn.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()};pn.prototype.destroySoon=pn.prototype.end;Object.defineProperty(pn.prototype,"pending",{get(){return this.handle===null},configurable:!0});Ud.exports={flagsToString:y0,OPEN_MODE:Ie,SFTP:Oa,Stats:Gs,STATUS_CODE:tt,stringToFlags:Td}});var Xa=ct((rS,Fd)=>{"use strict";var{Duplex:C0,Readable:v0,Writable:k0}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:$d}}=Mn(),{bufferSlice:zs}=gn(),B0=32*1024,Di=2*1024*1024,Ya=Di/2,Va=class extends v0{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=Ya&&ja(this._channel))}},Ga=class extends k0{constructor(t){super({highWaterMark:Di}),this._channel=t}_write(t,e,r){let s=this._channel,i=s._client._protocol,o=s.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?i.channelExtData(c,t,$d):i.channelExtData(c,zs(t,u,u+h),$d),u+=h,f-=h}if(o.window=f,l-u>0){f===0&&(s._waitWindow=!0),u>0?s._chunkErr=zs(t,u,l):s._chunkErr=t,s._chunkcbErr=r;return}r()}}},za=class extends C0{constructor(t,e,r){let s={highWaterMark:Di,allowHalfOpen:!r||r&&r.allowHalfOpen!==!1,emitClose:!1};super(s),this.allowHalfOpen=s.allowHalfOpen;let i=!!(r&&r.server);this.server=i,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,i?this.stderr=new Ga(this):this.stderr=new Va(this,s),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",Md).on("prefinish",Md),this.on("end",Od).on("close",Od)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=Ya&&ja(this))}_write(t,e,r){let s=this._client._protocol,i=this.outgoing,o=i.packetSize,a=i.id,c=i.window,f=t.length,l=0;if(i.state==="open"){for(;f-l>0&&c>0;){let u=f-l;u>c&&(u=c),u>o&&(u=o),l===0&&u===f?s.channelData(a,t):s.channelData(a,zs(t,l,l+u)),l+=u,c-=u}if(i.window=c,f-l>0){c===0&&(this._waitWindow=!0),l>0?this._chunk=zs(t,l,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,s){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,s)}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 Md(){this.eof(),(this.server||!this.allowHalfOpen)&&this.close(),this.writable=!1}function Od(){this.readable=!1}function ja(n){if(n.outgoing.state==="closed")return;let t=Di-n.incoming.window;t<=0||(n.incoming.window+=t,n._client._protocol.channelWindowAdjust(n.outgoing.id,t))}Fd.exports={Channel:za,MAX_WINDOW:Di,PACKET_SIZE:B0,windowAdjust:ja,WINDOW_THRESHOLD:Ya}});var ec=ct((iS,Wd)=>{"use strict";var{SFTP:R0}=Li(),Ui=2**32-1;function Hd(n,t,e,r){if(n._chanMgr.remove(t),typeof r!="function")return;let s;e instanceof Error?s=e:typeof e=="object"&&e!==null?(s=new Error(`(SSH) Channel open failure: ${e.description}`),s.reason=e.reason):(s=new Error("(SSH) Channel open failure: server closed channel unexpectedly"),s.reason=""),r(s)}function Qd(n,t,e,r,s){if(typeof e=="function"){Hd(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!==R0&&(e.outgoing.state==="open"||e.outgoing.state==="eof")&&!s&&e.close(),e.outgoing.state==="closing"&&(e.outgoing.state="closed");let i=e._readableState,o=e._writableState;o&&!o.ending&&!o.finished&&!s&&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||i&&i.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||i&&i.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 Za=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<Ui)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let r=this._channels;for(let s=0;s<Ui;++s)if(r[s]===void 0){e=s;break}}return e===void 0?-1:(this._channels[e]=t||!0,++this._count,e)}update(t,e){if(typeof t!="number"||t<0||t>=Ui||!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>=Ui||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=Ui||!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),s=this._client;for(let i=0;i<r.length;++i){let o=+r[i],a=e[o];Qd(s,o,a._channel||a,t,!0)}}},Ja=(()=>{let n=Object.prototype.toString;return t=>n.call(t)==="[object RegExp]"})();function N0(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),s=t;for(let i=0;i<r.length;++i){let o=r[i],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||s.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);s===t&&(s=s.slice()),s.push(f)}else if(Ja(f))for(let l=0;l<e.length;++l){let u=e[l];if(f.test(u)){if(s.indexOf(u)!==-1)continue;s===t&&(s=s.slice()),s.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||s.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);s===t&&(s=s.slice()),s.unshift(f)}else if(Ja(f))for(let l=e.length;l>=0;--l){let u=e[l];if(f.test(u)){if(s.indexOf(u)!==-1)continue;s===t&&(s=s.slice()),s.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=s.indexOf(f);if(l===-1)continue;s===t&&(s=s.slice()),s.splice(l,1)}else if(Ja(f))for(let l=0;l<s.length;++l)f.test(s[l])&&(s===t&&(s=s.slice()),s.splice(l,1),--l)}break}}return s}return t}Wd.exports={ChannelManager:Za,generateAlgorithmList:N0,onChannelOpenFailure:Hd,onCHANNEL_CLOSE:Qd,isWritable:n=>n&&n.writable&&n._readableState&&n._readableState.ended===!1}});var ac=ct((sS,fh)=>{"use strict";var{createHash:P0,getHashes:T0,randomFillSync:L0}=require("crypto"),{Socket:D0}=require("net"),{lookup:U0}=require("dns"),$0=require("events"),M0=T0(),{COMPAT:oh,CHANNEL_EXTENDED_DATATYPE:{STDERR:O0},CHANNEL_OPEN_FAILURE:$i,DEFAULT_CIPHER:qd,DEFAULT_COMPRESSION:Kd,DEFAULT_KEX:Vd,DEFAULT_MAC:Gd,DEFAULT_SERVER_HOST_KEY:zd,DISCONNECT_REASON:Yd,DISCONNECT_REASON_BY_VALUE:F0,SUPPORTED_CIPHER:H0,SUPPORTED_COMPRESSION:Q0,SUPPORTED_KEX:W0,SUPPORTED_MAC:q0,SUPPORTED_SERVER_HOST_KEY:K0}=Mn(),{init:V0}=Gn(),G0=Da(),{parseKey:Xs}=jn(),{SFTP:z0}=Li(),{bufferCopy:jd,makeBufferParser:ah,makeError:Y0,readUInt32BE:j0,sigSSHToASN1:X0,writeUInt32BE:tc}=gn(),{AgentContext:Xd,createAgent:Jd,isAgent:Zd}=_a(),{Channel:ch,MAX_WINDOW:Js,PACKET_SIZE:Zs,windowAdjust:eh,WINDOW_THRESHOLD:th}=Xa(),{ChannelManager:J0,generateAlgorithmList:Mi,isWritable:Tt,onChannelOpenFailure:Z0,onCHANNEL_CLOSE:eA}=ec(),Ys=ah(),js=ah(),Oi=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,sc=n=>{},oc=class extends $0{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&&Tt(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=Mi(t.algorithms.kex,Vd,W0),e.kex!==Vd&&(r=!1),e.serverHostKey=Mi(t.algorithms.serverHostKey,zd,K0),e.serverHostKey!==zd&&(r=!1),e.cs.cipher=Mi(t.algorithms.cipher,qd,H0),e.cs.cipher!==qd&&(r=!1),e.cs.mac=Mi(t.algorithms.hmac,Gd,q0),e.cs.mac!==Gd&&(r=!1),e.cs.compress=Mi(t.algorithms.compress,Kd,Q0),e.cs.compress!==Kd&&(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=Jd(t.agent):Zd(t.agent)?this.config.agent=t.agent:this.config.agent=void 0,this.config.allowAgentFwd=t.agentForward===!0&&this.config.agent!==void 0;let s=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 i=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 J0(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=Xs(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.hostVerifier,B;M0.indexOf(t.hostHash)!==-1&&(B=t.hostHash),c=(T,q)=>{B&&(T=P0(B).update(T).digest("hex"));let ee=$(T,q);ee!==void 0&&q(ee)}}let f=this._sock=t.sock||new D0,l=!1,u=!1;this._protocol&&this._protocol.cleanup();let h=i?($,B,T)=>{i(`Debug output from server: ${JSON.stringify(T)}`)}:void 0,p,_=this._protocol=new G0({ident:this.config.ident,offer:r?void 0:e,onWrite:$=>{Tt(f)&&f.write($)},onError:$=>{$.level==="handshake"&&clearTimeout(this._readyTimeout),_._destruct||f.removeAllListeners("data"),this.emit("error",$);try{f.end()}catch{}},onHeader:$=>{u=!0,this._remoteVer=$.versions.software,$.greeting&&this.emit("greeting",$.greeting)},onHandshakeComplete:$=>{this.emit("handshake",$),l||(l=!0,_.service("ssh-userauth"))},debug:i,hostVerifier:c,messageHandlers:{DEBUG:h,DISCONNECT:($,B,T)=>{if(B!==Yd.BY_APPLICATION){T||(T=F0[B],T===void 0&&(T=`Unexpected disconnection reason: ${B}`));let q=new Error(T);q.code=B,this.emit("error",q)}f.end()},SERVICE_ACCEPT:($,B)=>{B==="ssh-userauth"&&Y()},EXT_INFO:($,B)=>{if(p===void 0){for(let T of B)if(T.name==="server-sig-algs"){p=T.algs;return}p=null}},USERAUTH_BANNER:($,B)=>{this.emit("banner",B)},USERAUTH_SUCCESS:$=>{C(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:($,B,T)=>{if(x.keyAlgos){let q=x.keyAlgos[0][0];if(i&&i(`Client: ${x.type} (${q}) auth failed`),x.keyAlgos.shift(),x.keyAlgos.length){let[ee,fe]=x.keyAlgos[0];switch(x.type){case"agent":_.authPK(x.username,x.agentCtx.currentKey(),ee);return;case"publickey":_.authPK(x.username,x.key,ee);return;case"hostbased":_.authHostbased(x.username,x.key,x.localHostname,x.localUsername,ee,(ie,je)=>{let ft=x.key.sign(ie,fe);if(ft instanceof Error)return ft.message=`Error while signing with key: ${ft.message}`,ft.level="client-authentication",this.emit("error",ft),Y();je(ft)});return}}else x.keyAlgos=void 0}if(x.type==="agent"){let q=x.agentCtx.pos();return i&&i(`Client: Agent key #${q+1} failed`),te()}i&&i(`Client: ${x.type} auth failed`),S=T,I=B,Y()},USERAUTH_PASSWD_CHANGEREQ:($,B)=>{x.type==="password"&&this.emit("change password",B,T=>{_.authPassword(this.config.username,this.config.password,T)})},USERAUTH_PK_OK:$=>{let B,T;if(x.keyAlgos&&([B,T]=x.keyAlgos[0]),x.type==="agent"){let q=x.agentCtx.currentKey();_.authPK(x.username,q,B,(ee,fe)=>{let ie={hash:T};x.agentCtx.sign(q,ee,ie,(je,ft)=>{if(je)je.level="agent",this.emit("error",je);else return fe(ft);te()})})}else x.type==="publickey"&&_.authPK(x.username,x.key,B,(q,ee)=>{let fe=x.key.sign(q,T);if(fe instanceof Error)return fe.message=`Error signing data with key: ${fe.message}`,fe.level="client-authentication",this.emit("error",fe),Y();ee(fe)})},USERAUTH_INFO_REQUEST:($,B,T,q)=>{if(x.type==="keyboard-interactive"){if((Array.isArray(q)?q.length:0)===0){i&&i("Client: Sending automatic USERAUTH_INFO_RESPONSE"),_.authInfoRes();return}x.prompt(B,T,"",q,fe=>{_.authInfoRes(fe)})}},REQUEST_SUCCESS:($,B)=>{o.length&&o.shift()(!1,B)},REQUEST_FAILURE:$=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:($,B,T,q)=>{B==="hostkeys-00@openssh.com"?(sA(this,q,(ee,fe)=>{ee||this.emit("hostkeys",fe)}),T&&_.requestSuccess()):T&&_.requestFailure()},CHANNEL_OPEN:($,B)=>{rA(this,B)},CHANNEL_OPEN_CONFIRMATION:($,B)=>{let T=this._chanMgr.get(B.recipient);if(typeof T!="function")return;let q=T.type==="sftp",fe={type:q?"session":T.type,incoming:{id:B.recipient,window:Js,packetSize:Zs,state:"open"},outgoing:{id:B.sender,window:B.window,packetSize:B.packetSize,state:"open"}},ie=q?new z0(this,fe,{debug:i}):new ch(this,fe);this._chanMgr.update(B.recipient,ie),T(void 0,ie)},CHANNEL_OPEN_FAILURE:($,B,T,q)=>{let ee=this._chanMgr.get(B);if(typeof ee!="function")return;Z0(this,B,{reason:T,description:q},ee)},CHANNEL_DATA:($,B,T)=>{let q=this._chanMgr.get(B);if(!(typeof q!="object"||q===null)&&q.incoming.window!==0){if(q.incoming.window-=T.length,q.push(T)===!1){q._waitChanDrain=!0;return}q.incoming.window<=th&&eh(q)}},CHANNEL_EXTENDED_DATA:($,B,T,q)=>{if(q!==O0)return;let ee=this._chanMgr.get(B);if(!(typeof ee!="object"||ee===null)&&ee.incoming.window!==0){if(ee.incoming.window-=T.length,!ee.stderr.push(T)){ee._waitChanDrain=!0;return}ee.incoming.window<=th&&eh(ee)}},CHANNEL_WINDOW_ADJUST:($,B,T)=>{let q=this._chanMgr.get(B);typeof q!="object"||q===null||(q.outgoing.window+=T,q._waitWindow&&(q._waitWindow=!1,q._chunk?q._write(q._chunk,null,q._chunkcb):q._chunkcb?q._chunkcb():q._chunkErr?q.stderr._write(q._chunkErr,null,q._chunkcbErr):q._chunkcbErr&&q._chunkcbErr()))},CHANNEL_SUCCESS:($,B)=>{let T=this._chanMgr.get(B);typeof T!="object"||T===null||(this._resetKA(),T._callbacks.length&&T._callbacks.shift()(!1))},CHANNEL_FAILURE:($,B)=>{let T=this._chanMgr.get(B);typeof T!="object"||T===null||(this._resetKA(),T._callbacks.length&&T._callbacks.shift()(!0))},CHANNEL_REQUEST:($,B,T,q,ee)=>{let fe=this._chanMgr.get(B);if(typeof fe!="object"||fe===null)return;let ie=fe._exit;if(ie.code===void 0){switch(T){case"exit-status":fe.emit("exit",ie.code=ee);return;case"exit-signal":fe.emit("exit",ie.code=null,ie.signal=`SIG${ee.signal}`,ie.dump=ee.coreDumped,ie.desc=ee.errorMessage);return}q&&$.channelFailure(fe.outgoing.id)}},CHANNEL_EOF:($,B)=>{let T=this._chanMgr.get(B);typeof T!="object"||T===null||T.incoming.state==="open"&&(T.incoming.state="eof",T.readable&&T.push(null),T.stderr.readable&&T.stderr.push(null))},CHANNEL_CLOSE:($,B)=>{eA(this,B,this._chanMgr.get(B))}}});f.pause();let E=this.config.keepaliveInterval,b=this.config.keepaliveCountMax,v=0,U,H=()=>{if(++v>b){if(clearInterval(U),f.readable){let $=new Error("Keepalive timeout");$.level="client-timeout",this.emit("error",$),f.destroy()}return}Tt(f)?(o.push(C),_.ping()):clearInterval(U)};function C(){E>0&&(v=0,clearInterval(U),Tt(f)&&(U=setInterval(H,E)))}this._resetKA=C;let F=(()=>{let $=!1;return()=>{if(!$&&($=!0,N&&!u)){let B=Y0("Connection lost before handshake","protocol",!0);this.emit("error",B)}}})(),V=(()=>{let $=!1;return()=>{$||($=!0,N=!0,i&&i("Socket connected"),this.emit("connect"),V0.then(()=>{_.start(),f.on("data",B=>{try{_.parse(B,0,B.length)}catch(T){this.emit("error",T);try{Tt(f)&&f.end()}catch{}}}),f.stderr&&typeof f.stderr.resume=="function"&&f.stderr.resume(),f.resume()}).catch(B=>{this.emit("error",B);try{Tt(f)&&f.end()}catch{}}))}})(),N=!1;f.on("connect",V).on("timeout",()=>{this.emit("timeout")}).on("error",$=>{i&&i(`Socket error: ${$.message}`),clearTimeout(this._readyTimeout),$.level="client-socket",this.emit("error",$)}).on("end",()=>{i&&i("Socket ended"),F(),_.cleanup(),clearTimeout(this._readyTimeout),clearInterval(U),this.emit("end")}).on("close",()=>{i&&i("Socket closed"),F(),_.cleanup(),clearTimeout(this._readyTimeout),clearInterval(U),this.emit("close");let $=o;o=this._callbacks=[];let B=new Error("No response from server");for(let T=0;T<$.length;++T)$[T](B);this._chanMgr.cleanup(B)});let x,S=null,I=null,k=["none"];this.config.password!==void 0&&k.push("password"),a!==void 0&&k.push("publickey"),this._agent!==void 0&&k.push("agent"),this.config.tryKeyboard&&k.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&k.push("hostbased"),Array.isArray(s)?s=sh(s):typeof s!="function"&&(s=sh(k));let R=!1,ne=$=>{if(!R){if(R=!0,$===!1){let B=new Error("All configured authentication methods failed");B.level="client-authentication",this.emit("error",B),this.end();return}if(typeof $=="string"){let B=$;if(k.indexOf(B)===-1)return z(`Authentication method not allowed: ${B}`);let T=this.config.username;switch(B){case"password":$={type:B,username:T,password:this.config.password};break;case"publickey":$={type:B,username:T,key:a};break;case"hostbased":$={type:B,username:T,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":$={type:B,username:T,agentCtx:new Xd(this._agent)};break;case"keyboard-interactive":$={type:B,username:T,prompt:(...q)=>this.emit("keyboard-interactive",...q)};break;case"none":$={type:B,username:T};break;default:return z(`Skipping unsupported authentication method: ${$}`)}}else{if(typeof $!="object"||$===null)return z(`Skipping invalid authentication attempt: ${$}`);{let B=$.username;if(typeof B!="string")return z(`Skipping invalid authentication attempt: ${$}`);let T=$.type;switch(T){case"password":{let{password:q}=$;if(typeof q!="string"&&!Buffer.isBuffer(q))return z("Skipping invalid password auth attempt");$={type:T,username:B,password:q};break}case"publickey":{let q=Xs($.key,$.passphrase);if(q instanceof Error)return z("Skipping invalid key auth attempt");if(!q.isPrivateKey())return z("Skipping non-private key");$={type:T,username:B,key:q};break}case"hostbased":{let{localHostname:q,localUsername:ee}=$,fe=Xs($.key,$.passphrase);if(fe instanceof Error||typeof q!="string"||typeof ee!="string")return z("Skipping invalid hostbased auth attempt");if(!fe.isPrivateKey())return z("Skipping non-private key");$={type:T,username:B,key:fe,localHostname:q,localUsername:ee};break}case"agent":{let q=$.agent;if(typeof q=="string"&&q.length)q=Jd(q);else if(!Zd(q))return z(`Skipping invalid agent: ${$.agent}`);$={type:T,username:B,agentCtx:new Xd(q)};break}case"keyboard-interactive":{let{prompt:q}=$;if(typeof q!="function")return z("Skipping invalid keyboard-interactive auth attempt");$={type:T,username:B,prompt:q};break}case"none":$={type:T,username:B};break;default:return z(`Skipping unsupported authentication method: ${$}`)}}}x=$;try{let B=x.username;switch(x.type){case"password":_.authPassword(B,x.password);break;case"publickey":{let T;if(x.keyAlgos=ic(this,x.key,p),x.keyAlgos)if(x.keyAlgos.length)T=x.keyAlgos[0][0];else return z("Skipping key authentication (no mutual hash algorithm)");_.authPK(B,x.key,T);break}case"hostbased":{let T,q;if(x.keyAlgos=ic(this,x.key,p),x.keyAlgos)if(x.keyAlgos.length)[T,q]=x.keyAlgos[0];else return z("Skipping hostbased authentication (no mutual hash algorithm)");_.authHostbased(B,x.key,x.localHostname,x.localUsername,T,(ee,fe)=>{let ie=x.key.sign(ee,q);if(ie instanceof Error)return ie.message=`Error while signing with key: ${ie.message}`,ie.level="client-authentication",this.emit("error",ie),Y();fe(ie)});break}case"agent":x.agentCtx.init(T=>{if(T)return T.level="agent",this.emit("error",T),Y();te()});break;case"keyboard-interactive":_.authKeyboard(B);break;case"none":_.authNone(B);break}}finally{R=!1}}};function z($){i&&i($),process.nextTick(Y)}function Y(){R=!1;let $=s(I,S,ne);R||$===void 0||ne($)}let te=()=>{if(x.type==="agent"){let $=x.agentCtx.nextKey();if($===!1)i&&i("Agent: No more keys left to try"),i&&i("Client: agent auth failed"),Y();else{let B=x.agentCtx.pos(),T;if(x.keyAlgos=ic(this,$,p),x.keyAlgos)if(x.keyAlgos.length)T=x.keyAlgos[0][0];else{i&&i(`Agent: Skipping key #${B+1} (no mutual hash algorithm)`),te();return}i&&i(`Agent: Trying key #${B+1}`),_.authPK(x.username,$,T)}}},ce=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let $=new Error("Timed out while waiting for handshake");$.level="client-timeout",this.emit("error",$),f.destroy()},this.config.readyTimeout))};if(t.sock)ce(),typeof f.connecting=="boolean"&&f.connecting||V();else{let $=this.config.host,B=this.config.forceIPv4,T=this.config.forceIPv6;i&&i(`Client: Trying ${$} on port ${this.config.port} ...`);let q=()=>{ce(),f.connect({host:$,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),f.setMaxListeners(0),f.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!B&&!T||B&&T?q():U0($,B?4:6,(ee,fe,ie)=>{if(ee){let je=B?"IPv4":"IPv6",ft=new Error(`Error while looking up ${je} address for '${$}': ${ee}`);clearTimeout(this._readyTimeout),ft.level="client-dns",this.emit("error",ft),this.emit("close");return}$=fe,q()})}return this}end(){return this._sock&&Tt(this._sock)&&(this._protocol.disconnect(Yd.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&Tt(this._sock)&&this._sock.destroy(),this}exec(t,e,r){if(!this._sock||!Tt(this._sock))throw new Error("Not connected");typeof e=="function"&&(r=e,e={});let s={allowHalfOpen:e.allowHalfOpen!==!1};return Kr(this,"session",s,(i,o)=>{if(i){r(i);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(()=>ih(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&nc(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>rh(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>nh(o,e.x11,c))),a.push(()=>nA(o,t,e,r)),a.shift()()}),this}shell(t,e,r){if(!this._sock||!Tt(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),Kr(this,"session",(s,i)=>{if(s){r(s);return}let o=[];function a(c){if(c){i.close(),r(c);return}o.length&&o.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&o.push(()=>ih(i,a)),t!==!1&&o.push(()=>rh(i,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&nc(i,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>nh(i,e.x11,a))),o.push(()=>tA(i,r)),o.shift()()}),this}subsys(t,e){if(!this._sock||!Tt(this._sock))throw new Error("Not connected");return Kr(this,"session",(r,s)=>{if(r){e(r);return}rc(s,t,(i,o)=>{if(i){e(i);return}e(void 0,o)})}),this}forwardIn(t,e,r){if(!this._sock||!Tt(this._sock))throw new Error("Not connected");let s=typeof r=="function";return s&&this._callbacks.push((i,o)=>{if(i){r(i!==!0?i:new Error(`Unable to bind to ${t}:${e}`));return}let a=e;e===0&&o&&o.length>=4&&(a=j0(o,0),this._protocol._compatFlags&oh.DYN_RPORT_BUG||(e=a)),this._forwarding[`${t}:${e}`]=a,r(void 0,a)}),this._protocol.tcpipForward(t,e,s),this}unforwardIn(t,e,r){if(!this._sock||!Tt(this._sock))throw new Error("Not connected");let s=typeof r=="function";return s&&this._callbacks.push(i=>{if(i){r(i!==!0?i:new Error(`Unable to unbind from ${t}:${e}`));return}delete this._forwarding[`${t}:${e}`],r()}),this._protocol.cancelTcpipForward(t,e,s),this}forwardOut(t,e,r,s,i){if(!this._sock||!Tt(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:r,dstPort:s};return typeof i!="function"&&(i=sc),Kr(this,"direct-tcpip",o,i),this}openssh_noMoreSessions(t){if(!this._sock||!Tt(this._sock))throw new Error("Not connected");let e=typeof t=="function";return!this.config.strictVendor||this.config.strictVendor&&Oi.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||!Tt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Oi.test(this._remoteVer)?(r&&this._callbacks.push(s=>{if(s){e(s!==!0?s: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||!Tt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Oi.test(this._remoteVer)?(r&&this._callbacks.push(s=>{if(s){e(s!==!0?s: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||!Tt(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=sc),!this.config.strictVendor||this.config.strictVendor&&Oi.test(this._remoteVer)?(Kr(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||!Tt(this._sock))throw new Error("Not connected");return typeof t=="function"&&(e=t,t=void 0),Kr(this,"sftp",(r,s)=>{if(r){e(r);return}let i=(o,a)=>{if(o){e(o);return}function c(){s.removeListener("ready",f),s.removeListener("error",l),s.removeListener("exit",u),s.removeListener("close",u)}function f(){c(),e(void 0,s)}function l(h){c(),e(h)}function u(h,p){c();let _;typeof h=="number"?_=`Received exit code ${h} while establishing SFTP session`:p!==void 0?_=`Received signal ${p} while establishing SFTP session`:_="Received unexpected SFTP session termination";let E=new Error(_);E.code=h,E.signal=p,e(E)}s.on("ready",f).on("error",l).on("exit",u).on("close",u),s._init()};typeof t=="object"&&t!==null?nc(s,t,o=>{if(o){e(o);return}rc(s,"sftp",i)}):rc(s,"sftp",i)}),this}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function Kr(n,t,e,r){let s=Js,i=Zs;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,s,i);break;case"direct-tcpip":n._protocol.directTcpip(a,s,i,e);break;case"direct-streamlocal@openssh.com":n._protocol.openssh_directStreamLocal(a,s,i,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function nh(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=iA());let s=typeof e=="function";if(n.outgoing.state!=="open"){s&&e(new Error("Channel is not open"));return}s&&n._callbacks.push(i=>{if(i){e(i!==!0?i: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,s)}function rh(n,t,e){let r=24,s=80,i=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"&&(s=t.cols),typeof t.width=="number"&&(i=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(l=>{if(l){e(l!==!0?l:new Error("Unable to request a pseudo-terminal"));return}e()}),n._client._protocol.pty(n.outgoing.id,r,s,o,i,a,c,f)}function ih(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 tA(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 nA(n,t,e,r){if(n.outgoing.state!=="open"){r(new Error("Channel is not open"));return}n._callbacks.push(s=>{if(s){r(s!==!0?s: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 nc(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(i=>{if(i){e(i!==!0?i:new Error("Unable to set environment"));return}e()});let s=Object.keys(t||{});for(let i=0;i<s.length;++i){let o=s[i],a=t[o];n._client._protocol.env(n.outgoing.id,o,a,r)}}function rc(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 rA(n,t){let e=-1,r,s=()=>{let c={type:t.type,incoming:{id:e,window:Js,packetSize:Zs,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},f=new ch(n,c);return n._chanMgr.update(e,f),n._protocol.channelOpenConfirm(t.sender,e,Js,Zs),f},i=()=>{r===void 0&&(e===-1?r=$i.RESOURCE_SHORTAGE:r=$i.CONNECT_FAILED),e!==-1&&n._chanMgr.remove(e),n._protocol.channelOpenFail(t.sender,r,"")},o=()=>(e=n._chanMgr.add(),e===-1&&(r=$i.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,s,i);return}break}case"forwarded-streamlocal@openssh.com":if(n._forwardingUnix[a.socketPath]!==void 0&&o()){n.emit("unix connection",a,s,i);return}break;case"auth-agent@openssh.com":if(n._agentFwdEnabled&&typeof n._agent.getStream=="function"&&o()){n._agent.getStream((c,f)=>{if(c)return i();let l=s();l.pipe(f).pipe(l)});return}break;case"x11":if(n._acceptX11!==0&&o()){n.emit("x11",a,s,i);return}break;default:r=$i.UNKNOWN_CHANNEL_TYPE,n.config.debug&&n.config.debug(`Client: Automatic rejection of unsupported incoming channel open type: ${t.type}`)}r===void 0&&(r=$i.ADMINISTRATIVELY_PROHIBITED,n.config.debug&&n.config.debug("Client: Automatic rejection of unexpected incoming channel open for: "+t.type)),i()}var iA=(()=>{let n=Buffer.allocUnsafe(16);return()=>(L0(n,0,16),n.hexSlice(0,16))})();function sh(n){if(!Array.isArray(n))throw new Error("authList must be an array");let t=0;return(e,r,s)=>t===n.length?!1:n[t++]}function sA(n,t,e){if(!n._sock||!Tt(n._sock))return;if(typeof e!="function"&&(e=sc),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let r=[];for(let s of t){let i=Xs(s);if(i instanceof Error)throw i;r.push(i)}if(!n.config.strictVendor||n.config.strictVendor&&Oi.test(n._remoteVer)){n._callbacks.push((s,i)=>{if(s){e(s!==!0?s:new Error("Server failed to prove supplied keys"));return}let o=[],a=0;for(Ys.init(i,0);Ys.avail()&&a!==r.length;){let c=r[a++],f=c.getPublicSSH(),l=Ys.readString();js.init(l,0);let u=js.readString(!0),h=js.readString(),p;if(u!==c.type)if(c.type==="ssh-rsa")switch(u){case"rsa-sha2-256":p="sha256";break;case"rsa-sha2-512":p="sha512";break;default:continue}else continue;let _=n._protocol._kex.sessionID,E=Buffer.allocUnsafe(37+_.length+4+f.length),b=0;tc(E,29,b),E.utf8Write("hostkeys-prove-00@openssh.com",b+=4,29),tc(E,_.length,b+=29),jd(_,E,0,_.length,b+=4),tc(E,f.length,b+=_.length),jd(f,E,0,f.length,b+=4),(h=X0(h,u))&&c.verify(E,h,p)===!0&&o.push(c)}js.clear(),Ys.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 ic(n,t,e){switch(t.type){case"ssh-rsa":if(n._protocol._compatFlags&oh.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"]]}}fh.exports=oc});var uh=ct(lh=>{"use strict";var{Agent:fc}=require("http"),{Agent:oA}=require("https"),{connect:aA}=require("tls"),cc;for(let n of[fc,oA]){class t extends n{constructor(r,s){super(s),this._connectCfg=r,this._defaultSrcIP=s&&s.srcIP||"localhost"}createConnection(r,s){let i=r&&r.localAddress||this._defaultSrcIP,o=r&&r.localPort||0,a=r.host,c=r.port;cc===void 0&&(cc=ac());let f=new cc,l=!1;f.on("ready",()=>{f.forwardOut(i,o,a,c,(u,h)=>{if(l=!0,u)return f.end(),s(u);h.once("close",()=>f.end()),s(null,cA(h,n,r))})}).on("error",s).on("close",()=>{l||s(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}lh[n===fc?"SSHTTPAgent":"SSHTTPSAgent"]=t}function Fi(){}function cA(n,t,e){if(t===fc)return n.setKeepAlive=Fi,n.setNoDelay=Fi,n.setTimeout=Fi,n.ref=Fi,n.unref=Fi,n.destroySoon=n.destroy,n;e.socket=n;let r=aA(e),s=(()=>{let i=!1;return()=>{i||(i=!0,n.isPaused()&&n.resume())}})();return r.on("end",s).on("close",s),r}});var hh=ct((aS,hc)=>{"use strict";var{Server:fA}=require("net"),Qi=require("events"),{listenerCount:Gt}=Qi,{CHANNEL_OPEN_FAILURE:Vr,DEFAULT_CIPHER:lA,DEFAULT_COMPRESSION:uA,DEFAULT_KEX:dA,DEFAULT_MAC:hA,DEFAULT_SERVER_HOST_KEY:pA,DISCONNECT_REASON:Gr,DISCONNECT_REASON_BY_VALUE:gA,SUPPORTED_CIPHER:mA,SUPPORTED_COMPRESSION:AA,SUPPORTED_KEX:EA,SUPPORTED_MAC:yA,SUPPORTED_SERVER_HOST_KEY:_A}=Mn(),{init:bA}=Gn(),{KexInit:xA}=Us(),{parseKey:dh}=jn(),SA=Da(),{SFTP:wA}=Li(),{writeUInt32BE:IA}=gn(),{Channel:zr,MAX_WINDOW:Zn,PACKET_SIZE:er,windowAdjust:CA,WINDOW_THRESHOLD:vA}=Xa(),{ChannelManager:kA,generateAlgorithmList:Hi,isWritable:eo,onChannelOpenFailure:BA,onCHANNEL_CLOSE:RA}=ec(),NA=10,tr=class extends Qi{constructor(t,e,r,s,i){super(),this.username=this.user=e,this.service=r,this.method=s,this._initialResponse=!1,this._finalResponse=!1,this._multistep=!1,this._cbfinal=(o,a,c)=>{this._finalResponse||(this._finalResponse=!0,i(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)}},to=class extends tr{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this._multistep=!0,this._cb=void 0,this._onInfoResponse=a=>{let c=this._cb;c&&(this._cb=void 0,c(a))},this.submethods=i,this.on("abort",()=>{this._cb&&this._cb(new Error("Authentication request aborted"))})}prompt(t,e,r,s){Array.isArray(t)||(t=[t]),typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"?(s=r,r=void 0):typeof s!="function"&&(s=void 0);for(let i=0;i<t.length;++i)typeof t[i]=="string"&&(t[i]={prompt:t[i],echo:!0});this._cb=s,this._initialResponse=!0,this._protocol.authInfoReq(e,r,t)}},uc=class extends tr{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.key={algo:i.keyAlgo,data:i.key},this.hashAlgo=i.hashAlgo,this.signature=i.signature,this.blob=i.blob}accept(){this.signature?tr.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},dc=class extends tr{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.key={algo:i.keyAlgo,data:i.key},this.hashAlgo=i.hashAlgo,this.signature=i.signature,this.blob=i.blob,this.localHostname=i.localHostname,this.localUsername=i.localUsername}},no=class extends tr{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.password=i,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)}},kn=class extends Qi{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:Zn,packetSize:er,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},cn=class extends Qi{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new Error("Missing configuration object");let r=Object.create(null),s=[],i=t.hostKeys;if(!Array.isArray(i))throw new Error("hostKeys must be an array");let o=typeof t.algorithms=="object"&&t.algorithms!==null?t.algorithms:{},a=Hi(o.serverHostKey,pA,_A);for(let h=0;h<i.length;++h){let p;if(Buffer.isBuffer(i[h])||typeof i[h]=="string"?p=dh(i[h]):p=dh(i[h].key,i[h].passphrase),p instanceof Error)throw new Error(`Cannot parse privateKey: ${p.message}`);if(Array.isArray(p)&&(p=p[0]),p.getPrivatePEM()===null)throw new Error("privateKey value contains an invalid private key");if(!s.includes(p.type))if(p.type==="ssh-rsa"){let _=a.indexOf("ssh-rsa"),E=a.indexOf("rsa-sha2-256"),b=a.indexOf("rsa-sha2-512");_===-1&&(_=1/0),[_,E,b].sort(PA).forEach(v=>{if(v===-1)return;let U;switch(v){case _:U="ssh-rsa";break;case E:U="rsa-sha2-256";break;case b:U="rsa-sha2-512";break;default:return}r[U]=p,s.push(U)})}else r[p.type]=p,s.push(p.type)}let c={kex:Hi(o.kex,dA,EA).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:s,cs:{cipher:Hi(o.cipher,lA,mA),mac:Hi(o.hmac,hA,yA),compress:Hi(o.compress,uA,AA),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 xA(c);this._srv=new fA(h=>{if(this._connections>=this.maxConnections){h.destroy();return}++this._connections,h.once("close",()=>{--this._connections});let p;if(f){let _=`[${process.hrtime().join(".")}] `;p=E=>{f(`${_}${E}`)}}new ro(h,r,l,u,p,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}};cn.KEEPALIVE_CLIENT_INTERVAL=15e3;cn.KEEPALIVE_CLIENT_COUNT_MAX=3;var ro=class extends Qi{constructor(t,e,r,s,i,o,a){super();let c=0,f=!1,l=[],u,h,p,_=[];this._sock=t,this._chanMgr=new kA(this),this._debug=i,this.noMoreSessions=!1,this.authenticated=!1;function E(N){}this.on("error",E);let b=i?(N,x,S)=>{i(`Debug output from client: ${JSON.stringify(S)}`)}:void 0,v=typeof a.keepaliveInterval=="number"&&isFinite(a.keepaliveInterval)&&a.keepaliveInterval>0?a.keepaliveInterval:typeof cn.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(cn.KEEPALIVE_CLIENT_INTERVAL)&&cn.KEEPALIVE_CLIENT_INTERVAL>0?cn.KEEPALIVE_CLIENT_INTERVAL:-1,U=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof cn.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(cn.KEEPALIVE_CLIENT_COUNT_MAX)&&cn.KEEPALIVE_CLIENT_COUNT_MAX>=0?cn.KEEPALIVE_CLIENT_COUNT_MAX:-1,H=0;v!==-1&&U!==-1&&(this.once("ready",()=>{let N=()=>{clearInterval(h)};this.on("close",N).on("end",N),h=setInterval(()=>{if(++H>U){clearInterval(h);let x=new Error("Keepalive timeout");x.level="client-timeout",this.emit("error",x),this.end()}else C.ping()},v)}),p=()=>{h&&h.refresh(),H=0});let C=this._protocol=new SA({server:!0,hostKeys:e,ident:r,offer:s,onPacket:p,greeting:a.greeting,banner:a.banner,onWrite:N=>{eo(t)&&t.write(N)},onError:N=>{C._destruct||t.removeAllListeners("data"),this.emit("error",N);try{t.end()}catch{}},onHeader:N=>{this.removeListener("error",E);let x={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:N};if(!o.emit("connection",this,x)){C.disconnect(Gr.BY_APPLICATION),t.end();return}N.greeting&&this.emit("greeting",N.greeting)},onHandshakeComplete:N=>{++c>1&&this.emit("rekey"),this.emit("handshake",N)},debug:i,messageHandlers:{DEBUG:b,DISCONNECT:(N,x,S)=>{if(x!==Gr.BY_APPLICATION){S||(S=gA[x],S===void 0&&(S=`Unexpected disconnection reason: ${x}`));let I=new Error(S);I.code=x,this.emit("error",I)}t.end()},CHANNEL_OPEN:(N,x)=>{if(x.type==="session"&&this.noMoreSessions||!this.authenticated){let te=Vr.ADMINISTRATIVELY_PROHIBITED;return C.channelOpenFail(x.sender,te)}let S=-1,I,k=!1,R,ne=()=>{k||(k=!0,I===void 0&&(S===-1?I=Vr.RESOURCE_SHORTAGE:I=Vr.CONNECT_FAILED),S!==-1&&this._chanMgr.remove(S),C.channelOpenFail(x.sender,I,""))},z=()=>(S=this._chanMgr.add(),S===-1&&(I=Vr.RESOURCE_SHORTAGE,i&&i("Automatic rejection of incoming channel open: no channels available")),S!==-1),Y=x.data;switch(x.type){case"session":if(Gt(this,"session")&&z()){R=()=>{if(k)return;k=!0;let te=new kn(this,x,S);return this._chanMgr.update(S,te),C.channelOpenConfirm(x.sender,S,Zn,er),te},this.emit("session",R,ne);return}break;case"direct-tcpip":if(Gt(this,"tcpip")&&z()){R=()=>{if(k)return;k=!0;let te={type:void 0,incoming:{id:S,window:Zn,packetSize:er,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},ce=new zr(this,te,{server:!0});return this._chanMgr.update(S,ce),C.channelOpenConfirm(x.sender,S,Zn,er),ce},this.emit("tcpip",R,ne,Y);return}break;case"direct-streamlocal@openssh.com":if(Gt(this,"openssh.streamlocal")&&z()){R=()=>{if(k)return;k=!0;let te={type:void 0,incoming:{id:S,window:Zn,packetSize:er,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},ce=new zr(this,te,{server:!0});return this._chanMgr.update(S,ce),C.channelOpenConfirm(x.sender,S,Zn,er),ce},this.emit("openssh.streamlocal",R,ne,Y);return}break;default:I=Vr.UNKNOWN_CHANNEL_TYPE,i&&i(`Automatic rejection of unsupported incoming channel open type: ${x.type}`)}I===void 0&&(I=Vr.ADMINISTRATIVELY_PROHIBITED,i&&i(`Automatic rejection of unexpected incoming channel open for: ${x.type}`)),ne()},CHANNEL_OPEN_CONFIRMATION:(N,x)=>{let S=this._chanMgr.get(x.recipient);if(typeof S!="function")return;let I={type:S.type,incoming:{id:x.recipient,window:Zn,packetSize:er,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},k=new zr(this,I,{server:!0});this._chanMgr.update(x.recipient,k),S(void 0,k)},CHANNEL_OPEN_FAILURE:(N,x,S,I)=>{let k=this._chanMgr.get(x);if(typeof k!="function")return;BA(this,x,{reason:S,description:I},k)},CHANNEL_DATA:(N,x,S)=>{let I=this._chanMgr.get(x);if(!(typeof I!="object"||I===null)&&!(I.constructor===kn&&(I=I._channel,!I))&&I.incoming.window!==0){if(I.incoming.window-=S.length,I.push(S)===!1){I._waitChanDrain=!0;return}I.incoming.window<=vA&&CA(I)}},CHANNEL_EXTENDED_DATA:(N,x,S,I)=>{},CHANNEL_WINDOW_ADJUST:(N,x,S)=>{let I=this._chanMgr.get(x);typeof I!="object"||I===null||I.constructor===kn&&(I=I._channel,!I)||(I.outgoing.window+=S,I._waitWindow&&(I._waitWindow=!1,I._chunk?I._write(I._chunk,null,I._chunkcb):I._chunkcb?I._chunkcb():I._chunkErr?I.stderr._write(I._chunkErr,null,I._chunkcbErr):I._chunkcbErr&&I._chunkcbErr()))},CHANNEL_SUCCESS:(N,x)=>{let S=this._chanMgr.get(x);typeof S!="object"||S===null||S.constructor===kn&&(S=S._channel,!S)||S._callbacks.length&&S._callbacks.shift()(!1)},CHANNEL_FAILURE:(N,x)=>{let S=this._chanMgr.get(x);typeof S!="object"||S===null||S.constructor===kn&&(S=S._channel,!S)||S._callbacks.length&&S._callbacks.shift()(!0)},CHANNEL_REQUEST:(N,x,S,I,k)=>{let R=this._chanMgr.get(x);if(typeof R!="object"||R===null)return;let ne=!1,z,Y;if(R.constructor!==kn){I&&C.channelFailure(R.outgoing.id);return}if(I&&(S!=="shell"&&S!=="exec"&&S!=="subsystem"&&(z=()=>{ne||R._ending||R._channel||(ne=!0,C.channelSuccess(R._chanInfo.outgoing.id))}),Y=()=>{ne||R._ending||R._channel||(ne=!0,C.channelFailure(R._chanInfo.outgoing.id))}),R._ending){Y&&Y();return}switch(S){case"env":if(Gt(R,"env")){R.emit("env",z,Y,{key:k.name,val:k.value});return}break;case"pty-req":if(Gt(R,"pty")){R.emit("pty",z,Y,k);return}break;case"window-change":Gt(R,"window-change")?R.emit("window-change",z,Y,k):Y&&Y();break;case"x11-req":if(Gt(R,"x11")){R.emit("x11",z,Y,k);return}break;case"signal":if(Gt(R,"signal")){R.emit("signal",z,Y,{name:k});return}break;case"auth-agent-req@openssh.com":if(Gt(R,"auth-agent")){R.emit("auth-agent",z,Y);return}break;case"shell":if(Gt(R,"shell")){z=()=>{if(ne||R._ending||R._channel)return;ne=!0,I&&C.channelSuccess(R._chanInfo.outgoing.id);let te=new zr(this,R._chanInfo,{server:!0});return te.subtype=R.subtype=S,R._channel=te,te},R.emit("shell",z,Y);return}break;case"exec":if(Gt(R,"exec")){z=()=>{if(ne||R._ending||R._channel)return;ne=!0,I&&C.channelSuccess(R._chanInfo.outgoing.id);let te=new zr(this,R._chanInfo,{server:!0});return te.subtype=R.subtype=S,R._channel=te,te},R.emit("exec",z,Y,{command:k});return}break;case"subsystem":{let te=k==="sftp";if(z=()=>{if(ne||R._ending||R._channel)return;ne=!0,I&&C.channelSuccess(R._chanInfo.outgoing.id);let ce;return te?ce=new wA(this,R._chanInfo,{server:!0,debug:i}):(ce=new zr(this,R._chanInfo,{server:!0}),ce.subtype=R.subtype=`${S}:${k}`),R._channel=ce,ce},k==="sftp"){if(Gt(R,"sftp")){R.emit("sftp",z,Y);return}te=!1}if(Gt(R,"subsystem")){R.emit("subsystem",z,Y,{name:k});return}break}}i&&i(`Automatic rejection of incoming channel request: ${S}`),Y&&Y()},CHANNEL_EOF:(N,x)=>{let S=this._chanMgr.get(x);typeof S!="object"||S===null||S.constructor===kn&&(S._ending||(S._ending=!0,S.emit("eof"),S.emit("end")),S=S._channel,!S)||S.incoming.state==="open"&&(S.incoming.state="eof",S.readable&&S.push(null))},CHANNEL_CLOSE:(N,x)=>{let S=this._chanMgr.get(x);typeof S!="object"||S===null||S.constructor===kn&&(S._ending=!0,S.emit("close"),S=S._channel,!S)||RA(this,x,S)},SERVICE_REQUEST:(N,x)=>{if(c===0||f||this.authenticated||x!=="ssh-userauth"){C.disconnect(Gr.SERVICE_NOT_AVAILABLE),t.end();return}f=!0,C.serviceAccept(x)},USERAUTH_REQUEST:(N,x,S,I,k)=>{if(c===0||this.authenticated||u&&(u.username!==x||u.service!==S)||I!=="password"&&I!=="publickey"&&I!=="hostbased"&&I!=="keyboard-interactive"&&I!=="none"||l.length===NA){C.disconnect(Gr.PROTOCOL_ERROR),t.end();return}else if(S!=="ssh-connection"){C.disconnect(Gr.SERVICE_NOT_AVAILABLE),t.end();return}let R;switch(I){case"keyboard-interactive":R=new to(C,x,S,I,k,F);break;case"publickey":R=new uc(C,x,S,I,k,F);break;case"hostbased":R=new dc(C,x,S,I,k,F);break;case"password":if(u&&u instanceof no&&u._changeCb){let ne=u._changeCb;u._changeCb=void 0,ne(k.newPassword);return}R=new no(C,x,S,I,k,F);break;case"none":R=new tr(C,x,S,I,F);break}if(u)if(u._initialResponse)u._multistep&&!u._finalResponse&&(u._cleanup&&u._cleanup(),u.emit("abort"));else return l.push(R);u=R,Gt(this,"authentication")?this.emit("authentication",u):u.reject()},USERAUTH_INFO_RESPONSE:(N,x)=>{u&&u instanceof to&&u._onInfoResponse(x)},GLOBAL_REQUEST:(N,x,S,I)=>{let k={type:null,buf:null};function R(ne,z){k.type=ne,k.buf=z,V()}if(S&&_.push(k),(x==="tcpip-forward"||x==="cancel-tcpip-forward"||x==="no-more-sessions@openssh.com"||x==="streamlocal-forward@openssh.com"||x==="cancel-streamlocal-forward@openssh.com")&&Gt(this,"request")&&this.authenticated){let ne,z;if(S){let Y=!1;ne=te=>{if(Y)return;Y=!0;let ce;x==="tcpip-forward"&&I.bindPort===0&&typeof te=="number"&&(ce=Buffer.allocUnsafe(4),IA(ce,te,0)),R("SUCCESS",ce)},z=()=>{Y||(Y=!0,R("FAILURE"))}}if(x==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,ne&&ne();return}this.emit("request",ne,z,x,I)}else S&&R("FAILURE")}}});t.pause(),bA.then(()=>{C.start(),t.on("data",N=>{try{C.parse(N,0,N.length)}catch(x){this.emit("error",x);try{eo(t)&&t.end()}catch{}}}),t.resume()}).catch(N=>{this.emit("error",N);try{eo(t)&&t.end()}catch{}}),t.on("error",N=>{N.level="socket",this.emit("error",N)}).once("end",()=>{i&&i("Socket ended"),C.cleanup(),this.emit("end")}).once("close",()=>{i&&i("Socket closed"),C.cleanup(),this.emit("close");let N=new Error("No response from server");this._chanMgr.cleanup(N)});let F=(N,x,S,I)=>{u===N&&!this.authenticated&&(x?(u=void 0,this.authenticated=!0,C.authSuccess(),l=[],this.emit("ready")):(C.authFailure(S,I),l.length&&(u=l.pop(),Gt(this,"authentication")?this.emit("authentication",u):u.reject())))};function V(){for(;_.length>0&&_[0].type;){let N=_.shift();N.type==="SUCCESS"&&C.requestSuccess(N.buf),N.type==="FAILURE"&&C.requestFailure()}}}end(){return this._sock&&eo(this._sock)&&(this._protocol.disconnect(Gr.BY_APPLICATION),this._sock.end()),this}x11(t,e,r){return lc(this,"x11",{originAddr:t,originPort:e},r),this}forwardOut(t,e,r,s,i){return lc(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:r,remotePort:s},i),this}openssh_forwardOutStreamLocal(t,e){return lc(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 lc(n,t,e,r){let s=Zn,i=er;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,s,i,e);break;case"x11":n._protocol.x11(a,s,i,e);break;case"forwarded-streamlocal@openssh.com":n._protocol.openssh_forwardedStreamLocal(a,s,i,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function PA(n,t){return n-t}hc.exports=cn;hc.exports.IncomingClient=ro});var Eh=ct((cS,Ah)=>{"use strict";var{createCipheriv:TA,generateKeyPair:LA,generateKeyPairSync:DA,getCurves:UA,randomBytes:ph}=require("crypto"),{Ber:_t}=gi(),$A=Po().pbkdf,{CIPHER_INFO:MA}=Gn(),OA=16,FA=16,HA=UA(),QA=new Map(Object.entries(MA));function gh(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 s=t.bits;if(!Number.isInteger(s))throw new TypeError("RSA bits must be an integer");if(s<=0||s>16384)throw new RangeError("RSA bits must be non-zero and <= 16384");return["rsa",{modulusLength:s,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 s;switch(t.bits){case 256:s="prime256v1";break;case 384:s="secp384r1";break;case 521:s="secp521r1";break;default:throw new Error("ECDSA bits must be 256, 384, or 521")}if(!HA.includes(s))throw new Error("Unsupported ECDSA bits value");return["ec",{namedCurve:s,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ed25519":return["ed25519",{publicKeyEncoding:e,privateKeyEncoding:r}];default:throw new Error(`Unsupported key type: ${n}`)}}function WA(n,t,e){switch(n){case"rsa":{let r=new _t.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()!==_t.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 _t.Reader(r.readString(_t.OctetString,!0)),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");let s=r.readString(_t.Integer,!0),i=r.readString(_t.Integer,!0),o=r.readString(_t.Integer,!0),a=r.readString(_t.Integer,!0),c=r.readString(_t.Integer,!0);r.readString(_t.Integer,!0),r.readString(_t.Integer,!0);let f=r.readString(_t.Integer,!0),l=Buffer.from("ssh-rsa"),u=Buffer.allocUnsafe(4+l.length+4+s.length+4+i.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(s.length,h+=l.length),u.set(s,h+=4),u.writeUInt32BE(i.length,h+=s.length),u.set(i,h+=4),u.writeUInt32BE(o.length,h+=i.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 p=Buffer.allocUnsafe(4+l.length+4+i.length+4+s.length);return h=0,p.writeUInt32BE(l.length,h+=0),p.set(l,h+=4),p.writeUInt32BE(i.length,h+=l.length),p.set(i,h+=4),p.writeUInt32BE(s.length,h+=i.length),p.set(s,h+=4),{sshName:l.toString(),priv:u,pub:p}}case"ec":{let r=new _t.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 s=r.readString(_t.BitString,!0);{let h=0;for(;h<s.length&&s[h]===0;++h);h>0&&(s=s.slice(h))}if(r=new _t.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 i=r.readOID(),o;switch(i){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 _t.Reader(r.readString(_t.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(_t.OctetString,!0)]),c=Buffer.from(`ecdsa-sha2-${o}`);o=Buffer.from(o);let f=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.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(s.length,l+=o.length),f.set(s,l+=4),f.writeUInt32BE(a.length,l+=s.length),f.set(a,l+=4);let u=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.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(s.length,l+=o.length),u.set(s,l+=4),{sshName:c.toString(),priv:f,pub:u}}case"ed25519":{let r=new _t.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let s=r.readString(_t.BitString,!0);{let l=0;for(;l<s.length&&s[l]===0;++l);l>0&&(s=s.slice(l))}if(r=new _t.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 _t.Reader(r.readString(_t.OctetString,!0));let i=r.readString(_t.OctetString,!0),o=Buffer.from("ssh-ed25519"),a=Buffer.allocUnsafe(4+o.length+4+s.length+4+(i.length+s.length)),c=0;a.writeUInt32BE(o.length,c+=0),a.set(o,c+=4),a.writeUInt32BE(s.length,c+=o.length),a.set(s,c+=4),a.writeUInt32BE(i.length+s.length,c+=s.length),a.set(i,c+=4),a.set(s,c+=i.length);let f=Buffer.allocUnsafe(4+o.length+4+s.length);return c=0,f.writeUInt32BE(o.length,c+=0),f.set(o,c+=4),f.writeUInt32BE(s.length,c+=o.length),f.set(s,c+=4),{sshName:o.toString(),priv:a,pub:f}}}}function mh(n,t,e,r){let s="new",i,o="";if(typeof r=="object"&&r!==null&&(typeof r.comment=="string"&&r.comment&&(o=r.comment),typeof r.format=="string"&&r.format&&(s=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=QA.get(r.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(s==="new"){let f=FA;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 l=Buffer.allocUnsafe(c.keyLen+c.ivLen),u=ph(OA);if($A(a,a.length,u,u.length,l,l.length,f)!==0)return new Error("Failed to generate information to encrypt key");let p=Buffer.allocUnsafe(4+u.length+4);{let _=0;p.writeUInt32BE(u.length,_+=0),p.set(u,_+=4),p.writeUInt32BE(f,_+=u.length)}i={cipher:c,cipherName:r.cipher,kdfName:"bcrypt",kdfOptions:p,key:l.slice(0,c.keyLen),iv:l.slice(c.keyLen)}}}switch(s){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
15
- `,c,f=Buffer.from(i?i.cipherName:"none"),l=Buffer.from(i?i.kdfName:"none"),u=i?i.kdfOptions:Buffer.alloc(0),h=i?i.cipher.blockLen:8,p=WA(n,t,e),_=ph(4),E=Buffer.from(o),b=8+p.priv.length+4+E.length,v=[];for(let V=1;(b+v.length)%h;++V)v.push(V&255);v=Buffer.from(v);let U=Buffer.allocUnsafe(b+v.length),H;{let V=0;U.set(_,V+=0),U.set(_,V+=4),U.set(p.priv,V+=4),U.writeUInt32BE(E.length,V+=p.priv.length),U.set(E,V+=4),U.set(v,V+=E.length)}if(i){let V={authTagLength:i.cipher.authLen},N=TA(i.cipher.sslName,i.key,i.iv,V);N.setAutoPadding(!1),U=Buffer.concat([N.update(U),N.final()]),i.cipher.authLen>0?H=N.getAuthTag():H=Buffer.alloc(0),i.key.fill(0),i.iv.fill(0)}else H=Buffer.alloc(0);let C=Buffer.from("openssh-key-v1\0"),F=Buffer.allocUnsafe(C.length+4+f.length+4+l.length+4+u.length+4+4+p.pub.length+4+U.length+H.length);{let V=0;F.set(C,V+=0),F.writeUInt32BE(f.length,V+=C.length),F.set(f,V+=4),F.writeUInt32BE(l.length,V+=f.length),F.set(l,V+=4),F.writeUInt32BE(u.length,V+=l.length),F.set(u,V+=4),F.writeUInt32BE(1,V+=u.length),F.writeUInt32BE(p.pub.length,V+=4),F.set(p.pub,V+=4),F.writeUInt32BE(U.length,V+=p.pub.length),F.set(U,V+=4),F.set(H,V+=U.length)}{let V=F.base64Slice(0,F.length),N=V.replace(/.{64}/g,`$&
16
- `);V.length&63&&(N+=`
17
- `),a+=N}{let V=p.pub.base64Slice(0,p.pub.length);c=`${p.sshName} ${V}${o?` ${o}`:""}`}return a+=`-----END OPENSSH PRIVATE KEY-----
18
- `,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function qA(){}Ah.exports={generateKeyPair:(n,t,e)=>{typeof t=="function"&&(e=t,t=void 0),typeof e!="function"&&(e=qA);let r=gh(n,t);LA(...r,(s,i,o)=>{if(s)return e(s);let a;try{a=mh(r[0],i,o,t)}catch(c){return e(c)}e(null,a)})},generateKeyPairSync:(n,t)=>{let e=gh(n,t),{publicKey:r,privateKey:s}=DA(...e);return mh(e[0],r,s,t)}}});var pc=ct((fS,yh)=>{"use strict";var{AgentProtocol:KA,BaseAgent:VA,createAgent:GA,CygwinAgent:zA,OpenSSHAgent:YA,PageantAgent:jA}=_a(),{SSHTTPAgent:XA,SSHTTPSAgent:JA}=uh(),{parseKey:ZA}=jn(),{flagsToString:eE,OPEN_MODE:tE,STATUS_CODE:nE,stringToFlags:rE}=Li();yh.exports={AgentProtocol:KA,BaseAgent:VA,createAgent:GA,Client:ac(),CygwinAgent:zA,HTTPAgent:XA,HTTPSAgent:JA,OpenSSHAgent:YA,PageantAgent:jA,Server:hh(),utils:{parseKey:ZA,...Eh(),sftp:{flagsToString:eE,OPEN_MODE:tE,STATUS_CODE:nE,stringToFlags:rE}}}});function Tc(n){return n==="1"||n==="true"}function Lc(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function up(){return Tc(process.env.DEV_MODE)||Tc(process.env.RENDER_PERF)}function ln(n){let t=up();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=Lc(),r=i=>{let o=Lc()-e;console.log(`[perf][${n}] ${i}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(i="done")=>{r(i)}}}var wE=ln("HoneyPot");var Dc={name:"adduser",description:"Add a new user",category:"users",params:["<username>"],run:({authUser:n,shell:t,args:e})=>{if(n!=="root")return{stderr:`adduser: permission denied
14
+ ${e}`}};var k0=2**32,kd=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();Di.ERR_OUT_OF_RANGE=class Bd extends RangeError{constructor(t,e,r,s){super(),Error.captureStackTrace(this,Bd),Ys(e,'Missing "range" argument');let i=s?t:`The value of "${t}" is out of range.`,o;Number.isInteger(r)&&Math.abs(r)>k0?o=Id(String(r)):typeof r=="bigint"?(o=String(r),(r>kd||r<-kd)&&(o=Id(o)),o+="n"):o=C0(r),i+=` It must be ${e}. Received ${o}`,this.message=i}};var js=class n extends TypeError{constructor(t,e,r){super(),Error.captureStackTrace(this,n),Ys(typeof t=="string","'name' must be a string");let s;typeof e=="string"&&e.startsWith("not ")?(s="must not be",e=e.replace(/^not /,"")):s="must be";let i;if(t.endsWith(" argument"))i=`The ${t} ${s} ${Cd(e,"type")}`;else{let o=t.includes(".")?"property":"argument";i=`The "${t}" ${o} ${s} ${Cd(e,"type")}`}i+=`. Received type ${typeof r}`,this.message=i}};Di.ERR_INVALID_ARG_TYPE=js;Di.validateNumber=function(t,e){if(typeof t!="number")throw new js(e,"number",t)}});var Ui=lt((Ix,Wd)=>{"use strict";var v0=require("events"),nr=require("fs"),{constants:nn}=nr,{Readable:Dd,Writable:Xa}=require("stream"),{inherits:Ud,types:{isDate:Ka}}=require("util"),B0=Buffer[Symbol.species],{bufferCopy:tr,bufferSlice:Gr,makeBufferParser:R0,writeUInt32BE:V}=_n(),Wn={SIZE:1,UIDGID:2,PERMISSIONS:4,ACMODTIME:8,EXTENDED:2147483648},Pe=Buffer.alloc(28),nt={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},N0=new Map(Object.values(nt).map(n=>[n,1])),P0={[nt.OK]:"No error",[nt.EOF]:"End of file",[nt.NO_SUCH_FILE]:"No such file or directory",[nt.PERMISSION_DENIED]:"Permission denied",[nt.FAILURE]:"Failure",[nt.BAD_MESSAGE]:"Bad message",[nt.NO_CONNECTION]:"No connection",[nt.CONNECTION_LOST]:"Connection lost",[nt.OP_UNSUPPORTED]:"Operation unsupported"},Be={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},rn={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},Ce={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},Nd=2*1024,dt=2**32-1,T0=Buffer.from([0,0,0,5,Be.INIT,0,0,0,3]),L0=Buffer.from([0,0,0,5,rn.VERSION,0,0,0,3]),$0=/^SSH-2.0-(?:OpenSSH|dropbear)/,Wa=256*1024,O=R0(),D0={readable:!1,writable:!1,push:n=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function Md(){}var Va=class extends v0{constructor(t,e,r){super(),(typeof r!="object"||!r)&&(r={});let s=t._protocol._remoteIdentRaw;this.server=!!r.server,this._debug=typeof r.debug=="function"?r.debug:void 0,this._isOpenSSH=s&&$0.test(s),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=Wa,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?Wa:34e3)-Nd,this._maxWriteLen=(this._isOpenSSH?Wa:34e3)-Nd,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=D0,this.readable=!0}push(t){if(t===null){if(Qd(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 ot(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return ot(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 B0(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],s=this._pkt;this._pktLen=0,this._pktLenBytes=0,this._pkt=void 0,this._pktPos=0;let i=this.server?H0[r]:F0[r];if(!i)return ot(this,`Unknown packet type ${r}`);if(this._version===-1){if(this.server){if(r!==Be.INIT)return ot(this,`Expected INIT packet, got ${r}`)}else if(r!==rn.VERSION)return ot(this,`Expected VERSION packet, got ${r}`)}if(i(this,s)===!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=Md,this.server||Ze(this,T0)}createReadStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new qn(this,t,e)}createWriteStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new An(this,t,e)}open(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");typeof r=="function"&&(s=r,r=void 0);let i=typeof e=="number"?e:Fd(e);if(i===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=gr(r),o=r.flags,a=r.nb);let c=Buffer.byteLength(t),l=9,f=Buffer.allocUnsafe(13+c+4+4+a);V(f,f.length-4,0),f[4]=Be.OPEN;let u=this._writeReqid=this._writeReqid+1&dt;V(f,u,5),V(f,c,l),f.utf8Write(t,l+=4,c),V(f,i,l+=c),V(f,o,l+=4),a&&(l+=4,a===Pe.length?f.set(Pe,l):tr(Pe,f,0,a,l),l+=a),this._requests[u]={cb:s};let h=Ze(this,f);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 r=t.length,s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.CLOSE;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Ze(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} CLOSE`)}read(t,e,r,s,i,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+s>e.length)throw new Error("length extends beyond buffer");if(i===null)throw new Error("null position currently unsupported");Od(this,t,e,r,s,i,o)}readData(t,e,r,s,i,o){this.read(t,e,r,s,i,o)}write(t,e,r,s,i,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+s>e.length)throw new Error("length extends beyond buffer");if(i===null)throw new Error("null position currently unsupported");if(!s){o&&process.nextTick(o,void 0,0);return}let a=this._maxWriteLen,c=Math.max(s-a,0),l=i;c&&(s=a);let f=t.length,u=9,h=Buffer.allocUnsafe(13+f+8+4+s);V(h,h.length-4,0),h[4]=Be.WRITE;let p=this._writeReqid=this._writeReqid+1&dt;V(h,p,5),V(h,f,u),h.set(t,u+=4),u+=f;for(let E=7;E>=0;--E)h[u+E]=i&255,i/=256;V(h,s,u+=8),tr(e,h,r,r+s,u+=4),this._requests[p]={cb:E=>{E?typeof o=="function"&&o(E):c?this.write(t,e,r+s,c,l+s,o):typeof o=="function"&&o(void 0,r+s)}};let A=Ze(this,h);if(this._debug){let E=A?"Sent":"Buffered";this._debug(`SFTP: Outbound: ${E} WRITE (id:${p})`)}}writeData(t,e,r,s,i,o){this.write(t,e,r,s,i,o)}fastGet(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");Pd(this,nr,t,e,r,s)}fastPut(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");Pd(nr,this,t,e,r,s)}readFile(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof r=="function"?s=r:typeof e=="function"&&(s=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 i=e.encoding;if(i&&!Buffer.isEncoding(i))throw new Error(`Unknown encoding: ${i}`);let o,a,c,l=0,f,u=0,h=e.flag||"r",p=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(f,a,0,8192,u,A)):this.read(f,a,l,o-l,u,A)},A=(S,x)=>{let R;if(S){if(R=S.code===nt.EOF,!R)return this.close(f,()=>s&&s(S))}else R=!1;if(R||o===0&&x===0)return E();u+=x,l+=x,o!==0?l===o?E():p():(c.push(Gr(a,0,x)),p())};A._wantEOFError=!0;let E=()=>{this.close(f,S=>(o===0?a=Buffer.concat(c,l):l<o&&(a=Gr(a,0,l)),i&&(a=a.toString(i)),s&&s(S,a)))};this.open(t,h,438,(S,x)=>{if(S)return s&&s(S);f=x;let R=(H,C)=>{if(H){this.stat(t,(U,Q)=>{if(U)return this.close(f,()=>{s&&s(H)});R(null,Q)});return}if(o=C.size||0,o===0)return c=[],p();a=Buffer.allocUnsafe(o),p()};this.fstat(f,R)})}writeFile(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof s=="function"?i=s:typeof r=="function"&&(i=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)i&&i(a);else{let l=Buffer.isBuffer(e)?e:Buffer.from(""+e,r.encoding||"utf8"),f=/a/.test(o)?null:0;if(f===null){let u=(h,p)=>{if(h){this.stat(t,(A,E)=>{if(A)return this.close(c,()=>{i&&i(h)});u(null,E)});return}za(this,c,l,0,l.length,p.size,i)};this.fstat(c,u);return}za(this,c,l,0,l.length,f,i)}})}appendFile(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof s=="function"?i=s:typeof r=="function"&&(i=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,i)}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),s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.REMOVE;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(this,i);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 s=Buffer.byteLength(t),i=Buffer.byteLength(e),o=9,a=Buffer.allocUnsafe(13+s+4+i);V(a,a.length-4,0),a[4]=Be.RENAME;let c=this._writeReqid=this._writeReqid+1&dt;V(a,c,5),V(a,s,o),a.utf8Write(t,o+=4,s),V(a,i,o+=s),a.utf8Write(e,o+=4,i),this._requests[c]={cb:r};let l=Ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} RENAME`)}mkdir(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=0,i=0;typeof e=="function"&&(r=e,e=void 0),typeof e=="object"&&e!==null&&(e=gr(e),s=e.flags,i=e.nb);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);V(c,c.length-4,0),c[4]=Be.MKDIR;let l=this._writeReqid=this._writeReqid+1&dt;V(c,l,5),V(c,o,a),c.utf8Write(t,a+=4,o),V(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):tr(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let f=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} MKDIR`)}rmdir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.RMDIR;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(this,i);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 s=!(e&&e.full);if(!Buffer.isBuffer(t)&&typeof t!="string")throw new Error("missing directory handle or path");if(typeof t=="string"){let f=[],u=0,h=(p,A)=>{if(p)return r(p);this.readdir(A,e,(E,S)=>{let x=E&&E.code===nt.EOF;if(E&&!x)return this.close(A,()=>r(E));if(x)return this.close(A,R=>{if(R)return r(R);r(void 0,f)});for(let R=0;R<S.length;++R,++u)f[u]=S[R];h(void 0,A)})};return this.opendir(t,h)}let i=t.length,o=9,a=Buffer.allocUnsafe(13+i);V(a,a.length-4,0),a[4]=Be.READDIR;let c=this._writeReqid=this._writeReqid+1&dt;V(a,c,5),V(a,i,o),a.set(t,o+=4),this._requests[c]={cb:s?(f,u)=>{if(typeof r=="function"){if(f)return r(f);for(let h=u.length-1;h>=0;--h)(u[h].filename==="."||u[h].filename==="..")&&u.splice(h,1);r(void 0,u)}}:r};let l=Ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${l?"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,s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.FSTAT;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Ze(this,i);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),s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.STAT;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(this,i);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),s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.LSTAT;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(this,i);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),s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.OPENDIR;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(this,i);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 s=0,i=0;typeof e=="object"&&e!==null?(e=gr(e),s=e.flags,i=e.nb):typeof e=="function"&&(r=e);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);V(c,c.length-4,0),c[4]=Be.SETSTAT;let l=this._writeReqid=this._writeReqid+1&dt;V(c,l,5),V(c,o,a),c.utf8Write(t,a+=4,o),V(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):tr(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let f=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"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 s=0,i=0;typeof e=="object"&&e!==null?(e=gr(e),s=e.flags,i=e.nb):typeof e=="function"&&(r=e);let o=t.length,a=9,c=Buffer.allocUnsafe(13+o+4+i);V(c,c.length-4,0),c[4]=Be.FSETSTAT;let l=this._writeReqid=this._writeReqid+1&dt;V(c,l,5),V(c,o,a),c.set(t,a+=4),V(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):tr(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let f=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} FSETSTAT`)}futimes(t,e,r,s){return this.fsetstat(t,{atime:Vr(e),mtime:Vr(r)},s)}utimes(t,e,r,s){return this.setstat(t,{atime:Vr(e),mtime:Vr(r)},s)}fchown(t,e,r,s){return this.fsetstat(t,{uid:e,gid:r},s)}chown(t,e,r,s){return this.setstat(t,{uid:e,gid:r},s)}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),s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.READLINK;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:(c,l)=>{if(typeof e=="function"){if(c)return e(c);if(!l||!l.length)return e(new Error("Response missing link info"));e(void 0,l[0].filename)}}};let a=Ze(this,i);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 s=Buffer.byteLength(e),i=Buffer.byteLength(t),o=9,a=Buffer.allocUnsafe(13+s+4+i);V(a,a.length-4,0),a[4]=Be.SYMLINK;let c=this._writeReqid=this._writeReqid+1&dt;V(a,c,5),this._isOpenSSH?(V(a,i,o),a.utf8Write(t,o+=4,i),V(a,s,o+=i),a.utf8Write(e,o+=4,s)):(V(a,s,o),a.utf8Write(e,o+=4,s),V(a,i,o+=s),a.utf8Write(t,o+=4,i)),this._requests[c]={cb:r};let l=Ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} SYMLINK`)}realpath(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=Be.REALPATH;let o=this._writeReqid=this._writeReqid+1&dt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:(c,l)=>{if(typeof e=="function"){if(c)return e(c);if(!l||!l.length)return e(new Error("Response missing path info"));e(void 0,l[0].filename)}}};let a=Ze(this,i);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 s=this._extensions["posix-rename@openssh.com"];if(!s||s!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(41+i+4+o);V(c,c.length-4,0),c[4]=Be.EXTENDED;let l=this._writeReqid=this._writeReqid+1&dt;V(c,l,5),V(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),V(c,i,a+=24),c.utf8Write(t,a+=4,i),V(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[l]={cb:r};let f=Ze(this,c);if(this._debug){let u=f?"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 r=this._extensions["statvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),i=9,o=Buffer.allocUnsafe(36+s);V(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&dt;V(o,a,5),V(o,19,i),o.utf8Write("statvfs@openssh.com",i+=4,19),V(o,s,i+=19),o.utf8Write(t,i+=4,s),this._requests[a]={extended:"statvfs@openssh.com",cb:e};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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 s=t.length,i=9,o=Buffer.allocUnsafe(37+s);V(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&dt;V(o,a,5),V(o,20,i),o.utf8Write("fstatvfs@openssh.com",i+=4,20),V(o,s,i+=20),o.set(t,i+=4),this._requests[a]={extended:"fstatvfs@openssh.com",cb:e};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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 i=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(37+i+4+o);V(c,c.length-4,0),c[4]=Be.EXTENDED;let l=this._writeReqid=this._writeReqid+1&dt;V(c,l,5),V(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),V(c,i,a+=20),c.utf8Write(t,a+=4,i),V(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[l]={cb:r};let f=Ze(this,c);if(this._debug){let u=f?"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 s=t.length,i=9,o=Buffer.allocUnsafe(34+s);V(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&dt;V(o,a,5),V(o,17,i),o.utf8Write("fsync@openssh.com",i+=4,17),V(o,s,i+=17),o.set(t,i+=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 i=0,o=0;typeof e=="object"&&e!==null?(e=gr(e),i=e.flags,o=e.nb):typeof e=="function"&&(r=e);let a=Buffer.byteLength(t),c=9,l=Buffer.allocUnsafe(37+a+4+o);V(l,l.length-4,0),l[4]=Be.EXTENDED;let f=this._writeReqid=this._writeReqid+1&dt;V(l,f,5),V(l,20,c),l.utf8Write("lsetstat@openssh.com",c+=4,20),V(l,a,c+=20),l.utf8Write(t,c+=4,a),V(l,i,c+=a),o&&(c+=4,o===Pe.length?l.set(Pe,c):tr(Pe,l,0,o,c),c+=o),this._requests[f]={cb:r};let u=Ze(this,l);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 s=Buffer.byteLength(t),i=9,o=Buffer.allocUnsafe(40+s);V(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&dt;V(o,a,5),V(o,23,i),o.utf8Write("expand-path@openssh.com",i+=4,23),V(o,s,i+=20),o.utf8Write(t,i+=4,s),this._requests[a]={cb:(l,f)=>{if(typeof e=="function"){if(l)return e(l);if(!f||!f.length)return e(new Error("Response missing expanded path"));e(void 0,f[0].filename)}}};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} expand-path@openssh.com`)}}ext_copy_data(t,e,r,s,i,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(s))throw new Error("Destination handle is not a Buffer");let c=0,l=Buffer.allocUnsafe(26+t.length+8+8+4+s.length+8);V(l,l.length-4,c),c+=4,l[c]=Be.EXTENDED,++c;let f=this._writeReqid=this._writeReqid+1&dt;V(l,f,c),c+=4,V(l,9,c),c+=4,l.utf8Write("copy-data",c,9),c+=9,V(l,t.length,c),c+=4,l.set(t,c),c+=t.length;for(let h=7;h>=0;--h)l[c+h]=e&255,e/=256;c+=8;for(let h=7;h>=0;--h)l[c+h]=r&255,r/=256;c+=8,V(l,s.length,c),c+=4,l.set(s,c),c+=s.length;for(let h=7;h>=0;--h)l[c+h]=i&255,i/=256;this._requests[f]={cb:o};let u=Ze(this,l);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 s=0,i=Buffer.byteLength(t),o=Buffer.allocUnsafe(31+i);V(o,o.length-4,s),s+=4,o[s]=Be.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&dt;V(o,a,s),s+=4,V(o,14,s),s+=4,o.utf8Write("home-directory",s,14),s+=14,V(o,i,s),s+=4,o.utf8Write(t,s,i),s+=i,this._requests[a]={cb:(l,f)=>{if(typeof e=="function"){if(l)return e(l);if(!f||!f.length)return e(new Error("Response missing home directory"));e(void 0,f[0].filename)}}};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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 l of t)if(!Number.isInteger(l)||l<0||l>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 l of e)if(!Number.isInteger(l)||l<0||l>2**32-1)throw new Error("gid values must all be 32-bit unsigned integers");let i=0,o=Buffer.allocUnsafe(47+4*t.length+4+4*e.length);V(o,o.length-4,i),i+=4,o[i]=Be.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&dt;V(o,a,i),i+=4,V(o,30,i),i+=4,o.utf8Write("users-groups-by-id@openssh.com",i,30),i+=30,V(o,4*t.length,i),i+=4;for(let l of t)V(o,l,i),i+=4;V(o,4*e.length,i),i+=4;for(let l of e)V(o,l,i),i+=4;this._requests[a]={extended:"users-groups-by-id@openssh.com",cb:r};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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 s=9,i=Buffer.allocUnsafe(13+r);V(i,i.length-4,0),i[4]=rn.HANDLE,V(i,t,5),V(i,r,s),r&&i.set(e,s+=4);let o=Ze(this,i);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(!N0.has(e))throw new Error(`Bad status code: ${e}`);r||(r="");let s=Buffer.byteLength(r),i=9,o=Buffer.allocUnsafe(17+s+4);V(o,o.length-4,0),o[4]=rn.STATUS,V(o,t,5),V(o,e,i),V(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),V(o,0,i);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 s=Buffer.isBuffer(e);if(!s&&typeof e!="string")throw new Error("data is not a Buffer or string");let i;!s&&!r&&(r=void 0,i=!0);let o=s?e.length:Buffer.byteLength(e,r),a=9,c=Buffer.allocUnsafe(13+o);V(c,c.length-4,0),c[4]=rn.DATA,V(c,t,5),V(c,o,a),o&&(s?c.set(e,a+=4):i?c.utf8Write(e,a+=4,o):c.write(e,a+=4,o,r));let l=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"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,s=0,i,o=[];for(let f=0;f<r;++f){let u=e[f],h=!u||!u.filename||typeof u.filename!="string"?"":u.filename;s+=4+Buffer.byteLength(h);let p=!u||!u.longname||typeof u.longname!="string"?"":u.longname;if(s+=4+Buffer.byteLength(p),typeof u.attrs=="object"&&u.attrs!==null){if(i=gr(u.attrs),s+=4+i.nb,i.nb){let A;i.nb===Pe.length?A=new Uint8Array(Pe):(A=new Uint8Array(i.nb),tr(Pe,A,0,i.nb,0)),i.bytes=A}o.push(i)}else s+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+s);V(c,c.length-4,0),c[4]=rn.NAME,V(c,t,5),V(c,r,a),a+=4;for(let f=0;f<r;++f){let u=e[f];{let p=!u||!u.filename||typeof u.filename!="string"?"":u.filename,A=Buffer.byteLength(p);V(c,A,a),a+=4,A&&(c.utf8Write(p,a,A),a+=A)}{let p=!u||!u.longname||typeof u.longname!="string"?"":u.longname,A=Buffer.byteLength(p);V(c,A,a),a+=4,A&&(c.utf8Write(p,a,A),a+=A)}let h=o[f];h?(V(c,h.flags,a),a+=4,h.flags&&h.bytes&&(c.set(h.bytes,a),a+=h.nb)):(V(c,0,a),a+=4)}let l=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"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=gr(e);let r=e.flags,s=e.nb,i=9,o=Buffer.allocUnsafe(13+s);V(o,o.length-4,0),o[4]=rn.ATTRS,V(o,t,5),V(o,r,i),s&&(i+=4,s===Pe.length?o.set(Pe,i):tr(Pe,o,0,s,i),i+=s);let a=Ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function U0(n){try{return Buffer.allocUnsafe(n)}catch(t){return t}}function Od(n,t,e,r,s,i,o,a){let c=n._maxReadLen,l=Math.max(s-c,0);l&&(s=c);let f=t.length,u=9,h=i,p=Buffer.allocUnsafe(13+f+8+4);V(p,p.length-4,0),p[4]=Be.READ;let A=n._writeReqid=n._writeReqid+1&dt;V(p,A,5),V(p,f,u),p.set(t,u+=4),u+=f;for(let x=7;x>=0;--x)p[u+x]=h&255,h/=256;V(p,s,u+=8),typeof o!="function"&&(o=Md);let E=a||{nb:0,position:i,off:r,origOff:r,len:void 0,overflow:void 0,cb:(x,R,H)=>{let C=E.len,U=E.overflow;if(x){if(o._wantEOFError||x.code!==nt.EOF)return o(x)}else{if(H>C)return o(new Error("Received more data than requested"));if(H===C&&U){E.nb+=H,E.position+=H,E.off+=H,Od(n,t,e,E.off,U,E.position,o,E);return}}H=H||0,E.origOff===0&&e.length===E.nb?R=e:R=Gr(e,E.origOff,E.origOff+E.nb+H),o(void 0,E.nb+H,R,E.position)},buffer:void 0};E.len=s,E.overflow=l,E.buffer=Gr(e,r,r+s),n._requests[A]=E;let S=Ze(n,p);n._debug&&n._debug(`SFTP: Outbound: ${S?"Buffered":"Sending"} READ`)}function Pd(n,t,e,r,s,i){let o=64,a=32768,c,l,f;typeof s=="function"?i=s:typeof s=="object"&&s!==null&&(typeof s.concurrency=="number"&&s.concurrency>0&&!isNaN(s.concurrency)&&(o=s.concurrency),typeof s.chunkSize=="number"&&s.chunkSize>0&&!isNaN(s.chunkSize)&&(a=s.chunkSize),typeof s.fileSize=="number"&&s.fileSize>0&&!isNaN(s.fileSize)&&(f=s.fileSize),typeof s.step=="function"&&(c=s.step),(typeof s.mode=="string"||typeof s.mode=="number")&&(l=Ja(s.mode)));let u,h=0,p=0,A=!1,E,S,x,R=a*o;function H(C){if(A)return;A=!0;let U=0,Q;E||S?(Q=()=>{--U===0&&i(C)},E&&(n===nr||n.outgoing.state==="open")&&++U,S&&(t===nr||t.outgoing.state==="open")&&++U,E&&(n===nr||n.outgoing.state==="open")&&n.close(E,Q),S&&(t===nr||t.outgoing.state==="open")&&t.close(S,Q)):i(C)}n.open(e,"r",(C,U)=>{if(C)return H(C);E=U,f===void 0?n.fstat(E,Q):Q(null,{size:f});function Q(B,b){if(B){if(n!==nr){n.stat(e,(w,k)=>{if(w)return H(B);Q(null,k)});return}return H(B)}u=b.size,t.open(r,"w",(w,k)=>{if(w)return H(w);if(S=k,u<=0)return H();for(;R>u;){if(o===1){R=u;break}R-=a,--o}if(x=U0(R),x instanceof Error)return H(x);l!==void 0?t.fchmod(S,l,function Y(te){if(te){t.chmod(r,l,le=>Y());return}G()}):G();function v(Y,te,le,M,N,L){if(Y)return H(Y);N=N||0,t.write(S,x,N,te,M,K);function K(ee){if(ee)return H(ee);if(p+=te,c&&c(p,te,u),te<L)return ne(N,M+te,L-te);if(p===u){t.close(S,ie=>{if(S=void 0,ie)return H(ie);n.close(E,Xe=>{if(E=void 0,Xe)return H(Xe);i()})});return}if(h>=u)return;let ue=h+a>u?u-h:a;ne(N,h,ue),h+=ue}}function P(Y,te,le){return(M,N,L)=>{v(M,N,L,te,Y,le)}}function ne(Y,te,le){n.read(E,x,Y,le,te,P(Y,te,le))}function G(){let Y=0,te=0;for(;h<u&&Y<o;){let le=h+a>u?u-h:a;ne(te,h,le),te+=le,h+=le,++Y}}})}})}function za(n,t,e,r,s,i,o){let a=typeof o=="function"?o:void 0;n.write(t,e,r,s,i,(c,l)=>{if(c)return n.close(t,()=>{a&&a(c)});l===s?n.close(t,a):(r+=l,s-=l,i+=l,za(n,t,e,r,s,i,a))})}var Js=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&nn.S_IFMT)===nn.S_IFDIR}isFile(){return(this.mode&nn.S_IFMT)===nn.S_IFREG}isBlockDevice(){return(this.mode&nn.S_IFMT)===nn.S_IFBLK}isCharacterDevice(){return(this.mode&nn.S_IFMT)===nn.S_IFCHR}isSymbolicLink(){return(this.mode&nn.S_IFMT)===nn.S_IFLNK}isFIFO(){return(this.mode&nn.S_IFMT)===nn.S_IFIFO}isSocket(){return(this.mode&nn.S_IFMT)===nn.S_IFSOCK}};function gr(n){let t=0,e=0;if(typeof n=="object"&&n!==null){if(typeof n.size=="number"){t|=Wn.SIZE;let r=n.size;Pe[e++]=r/72057594037927940,Pe[e++]=r/281474976710656,Pe[e++]=r/1099511627776,Pe[e++]=r/4294967296,Pe[e++]=r/16777216,Pe[e++]=r/65536,Pe[e++]=r/256,Pe[e++]=r}if(typeof n.uid=="number"&&typeof n.gid=="number"){t|=Wn.UIDGID;let r=n.uid,s=n.gid;Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r,Pe[e++]=s>>>24,Pe[e++]=s>>>16,Pe[e++]=s>>>8,Pe[e++]=s}if(typeof n.mode=="number"||typeof n.mode=="string"){let r=Ja(n.mode);t|=Wn.PERMISSIONS,Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r}if((typeof n.atime=="number"||Ka(n.atime))&&(typeof n.mtime=="number"||Ka(n.mtime))){let r=Vr(n.atime),s=Vr(n.mtime);t|=Wn.ACMODTIME,Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r,Pe[e++]=s>>>24,Pe[e++]=s>>>16,Pe[e++]=s>>>8,Pe[e++]=s}}return{flags:t,nb:e}}function Vr(n){if(typeof n=="number"&&n===n)return n;if(Ka(n))return parseInt(n.getTime()/1e3,10);throw new Error(`Cannot parse time: ${n}`)}function Ja(n){if(typeof n=="number"&&n===n)return n;if(typeof n=="string")return Ja(parseInt(n,8));throw new Error(`Cannot parse mode: ${n}`)}var Ga={r:Ce.READ,"r+":Ce.READ|Ce.WRITE,w:Ce.TRUNC|Ce.CREAT|Ce.WRITE,wx:Ce.TRUNC|Ce.CREAT|Ce.WRITE|Ce.EXCL,xw:Ce.TRUNC|Ce.CREAT|Ce.WRITE|Ce.EXCL,"w+":Ce.TRUNC|Ce.CREAT|Ce.READ|Ce.WRITE,"wx+":Ce.TRUNC|Ce.CREAT|Ce.READ|Ce.WRITE|Ce.EXCL,"xw+":Ce.TRUNC|Ce.CREAT|Ce.READ|Ce.WRITE|Ce.EXCL,a:Ce.APPEND|Ce.CREAT|Ce.WRITE,ax:Ce.APPEND|Ce.CREAT|Ce.WRITE|Ce.EXCL,xa:Ce.APPEND|Ce.CREAT|Ce.WRITE|Ce.EXCL,"a+":Ce.APPEND|Ce.CREAT|Ce.READ|Ce.WRITE,"ax+":Ce.APPEND|Ce.CREAT|Ce.READ|Ce.WRITE|Ce.EXCL,"xa+":Ce.APPEND|Ce.CREAT|Ce.READ|Ce.WRITE|Ce.EXCL};function Fd(n){let t=Ga[n];return t!==void 0?t:null}var M0=(()=>{let n=Object.keys(Ga);return t=>{for(let e=0;e<n.length;++e){let r=n[e];if(Ga[r]===t)return r}return null}})();function zr(n){let t=O.readUInt32BE();if(t===void 0)return;let e=new Js;if(t&Wn.SIZE){let r=O.readUInt64BE(n);if(r===void 0)return;e.size=r}if(t&Wn.UIDGID){let r=O.readUInt32BE(),s=O.readUInt32BE();if(s===void 0)return;e.uid=r,e.gid=s}if(t&Wn.PERMISSIONS){let r=O.readUInt32BE();if(r===void 0)return;e.mode=r}if(t&Wn.ACMODTIME){let r=O.readUInt32BE(),s=O.readUInt32BE();if(s===void 0)return;e.atime=r,e.mtime=s}if(t&Wn.EXTENDED){let r=O.readUInt32BE();if(r===void 0)return;let s={};for(let i=0;i<r;++i){let o=O.readString(!0),a=O.readString();if(a===void 0)return;s[o]=a}e.extended=s}return e}function Ze(n,t){let e=Hd(n,t);return e!==void 0?(n._buffer.push(e),!1):!0}function Hd(n,t){let e=n.outgoing;if(e.state!=="open")return;if(e.window===0)return n._waitWindow=!0,n._chunkcb=Td,t;let r,s=t.length,i=0;for(;s-i>0&&e.window>0;){let o=Math.min(s-i,e.window,e.packetSize);e.window-=o,e.window===0&&(n._waitWindow=!0,n._chunkcb=Td),i===0&&o===s?n._protocol.channelData(n.outgoing.id,t):n._protocol.channelData(n.outgoing.id,Gr(t,i,i+o)),i+=o}return s-i>0&&(i>0?r=Gr(t,i,s):r=t),r}function Td(){this._chunkcb=void 0;let n=this._buffer,t=0;for(;t<n.length;){let e=n[t],r=Hd(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 ot(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(),Qd(n),!1}function Qd(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 s=0;s<t.length;++s){let i=e[t[s]];typeof i.cb=="function"&&i.cb(r)}}function O0(n,t){let e=9,r=Buffer.allocUnsafe(31);V(r,r.length-4,0),r[4]=Be.EXTENDED;let s=n._writeReqid=n._writeReqid+1&dt;V(r,s,5),V(r,18,e),r.utf8Write("limits@openssh.com",e+=4,18),n._requests[s]={extended:"limits@openssh.com",cb:t};let i=Ze(n,r);if(n._debug){let o=i?"Buffered":"Sending";n._debug(`SFTP: Outbound: ${o} limits@openssh.com`)}}var F0={[rn.VERSION]:(n,t)=>{if(n._version!==-1)return ot(n,"Duplicate VERSION packet");let e={};O.init(t,1);let r=O.readUInt32BE();for(;O.avail();){let s=O.readString(!0),i=O.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(O.clear(),r===void 0)return ot(n,"Malformed VERSION packet");if(n._debug){let s=Object.keys(e);s.length?n._debug(`SFTP: Inbound: Received VERSION (v${r}, exts:${s})`):n._debug(`SFTP: Inbound: Received VERSION (v${r})`)}if(n._version=r,n._extensions=e,e["limits@openssh.com"]==="1")return O0(n,(s,i)=>{s||(i.maxPktLen>0&&(n._maxOutPktLen=i.maxPktLen),i.maxReadLen>0&&(n._maxReadLen=i.maxReadLen),i.maxWriteLen>0&&(n._maxWriteLen=i.maxWriteLen),n.maxOpenHandles=i.maxOpenHandles>0?i.maxOpenHandles:1/0),n.emit("ready")});n.emit("ready")},[rn.STATUS]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readUInt32BE(),s=O.readString(!0);if(O.clear(),n._debug){let o=JSON.stringify(s);n._debug(`SFTP: Inbound: Received STATUS (id:${e}, ${r}, ${o})`)}let i=n._requests[e];if(delete n._requests[e],i&&typeof i.cb=="function"){if(r===nt.OK){i.cb();return}let o=new Error(s||P0[r]||"Unknown status");o.code=r,i.cb(o)}},[rn.HANDLE]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString();if(O.clear(),r===void 0)return e!==void 0&&delete n._requests[e],ot(n,"Malformed HANDLE packet");n._debug&&n._debug(`SFTP: Inbound: Received HANDLE (id:${e})`);let s=n._requests[e];delete n._requests[e],s&&typeof s.cb=="function"&&s.cb(void 0,r)},[rn.DATA]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r;if(e!==void 0&&(r=n._requests[e],delete n._requests[e]),r&&typeof r.cb=="function")if(r.buffer){let s=O.readString(r.buffer);if(O.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`),r.cb(void 0,r.buffer,s);return}}else{let s=O.readString();if(O.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s.length})`),r.cb(void 0,s);return}}else{let s=O.skipString();if(O.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`);return}}return ot(n,"Malformed DATA packet")},[rn.NAME]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=O.readUInt32BE();if(s!==void 0){let i=[];for(let o=0;o<s;++o){let a=O.readString(!0),c=O.readString(!0),l=zr(n._biOpt);if(l===void 0){i=void 0;break}i.push({filename:a,longname:c,attrs:l})}if(i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received NAME (id:${e}, ${i.length})`),O.clear(),r&&typeof r.cb=="function"&&r.cb(void 0,i);return}}return O.clear(),ot(n,"Malformed NAME packet")},[rn.ATTRS]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=zr(n._biOpt);if(O.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received ATTRS (id:${e})`),r&&typeof r.cb=="function"&&r.cb(void 0,s);return}return ot(n,"Malformed ATTRS packet")},[rn.EXTENDED]:(n,t)=>{O.init(t,1);let e=O.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 s=n._biOpt,i={f_bsize:O.readUInt64BE(s),f_frsize:O.readUInt64BE(s),f_blocks:O.readUInt64BE(s),f_bfree:O.readUInt64BE(s),f_bavail:O.readUInt64BE(s),f_files:O.readUInt64BE(s),f_ffree:O.readUInt64BE(s),f_favail:O.readUInt64BE(s),f_sid:O.readUInt64BE(s),f_flag:O.readUInt64BE(s),f_namemax:O.readUInt64BE(s)};if(i.f_namemax===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),O.clear(),typeof r.cb=="function"&&r.cb(void 0,i);return}case"limits@openssh.com":{let s={maxPktLen:O.readUInt64BE(),maxReadLen:O.readUInt64BE(),maxWriteLen:O.readUInt64BE(),maxOpenHandles:O.readUInt64BE()};if(s.maxOpenHandles===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),O.clear(),typeof r.cb=="function"&&r.cb(void 0,s);return}case"users-groups-by-id@openssh.com":{let s=O.readUInt32BE();if(s===void 0)break;let i=new Array(s);for(let c=0;c<i.length;++c)i[c]=O.readString(!0);let o=O.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=O.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})`),O.clear(),typeof r.cb=="function"&&r.cb(void 0,i,a);return}default:n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),O.clear(),typeof r.cb=="function"&&r.cb();return}else{n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),O.clear();return}}return O.clear(),ot(n,"Malformed EXTENDED_REPLY packet")}},H0={[Be.INIT]:(n,t)=>{if(n._version!==-1)return ot(n,"Duplicate INIT packet");let e={};O.init(t,1);let r=O.readUInt32BE();for(;O.avail();){let s=O.readString(!0),i=O.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(O.clear(),r===void 0)return ot(n,"Malformed INIT packet");if(n._debug){let s=Object.keys(e);s.length?n._debug(`SFTP: Inbound: Received INIT (v${r}, exts:${s})`):n._debug(`SFTP: Inbound: Received INIT (v${r})`)}Ze(n,L0),n._version=r,n._extensions=e,n.emit("ready")},[Be.OPEN]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0),s=O.readUInt32BE(),i=zr(n._biOpt);if(O.clear(),i===void 0)return ot(n,"Malformed OPEN packet");n._debug&&n._debug(`SFTP: Inbound: Received OPEN (id:${e})`),n.emit("OPEN",e,r,s,i)||n.status(e,nt.OP_UNSUPPORTED)},[Be.CLOSE]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString();if(O.clear(),r===void 0||r.length>256)return ot(n,"Malformed CLOSE packet");n._debug&&n._debug(`SFTP: Inbound: Received CLOSE (id:${e})`),n.emit("CLOSE",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.READ]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(),s=O.readUInt64BE(n._biOpt),i=O.readUInt32BE();if(O.clear(),i===void 0||r.length>256)return ot(n,"Malformed READ packet");n._debug&&n._debug(`SFTP: Inbound: Received READ (id:${e})`),n.emit("READ",e,r,s,i)||n.status(e,nt.OP_UNSUPPORTED)},[Be.WRITE]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(),s=O.readUInt64BE(n._biOpt),i=O.readString();if(O.clear(),i===void 0||r.length>256)return ot(n,"Malformed WRITE packet");n._debug&&n._debug(`SFTP: Inbound: Received WRITE (id:${e})`),n.emit("WRITE",e,r,s,i)||n.status(e,nt.OP_UNSUPPORTED)},[Be.LSTAT]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0);if(O.clear(),r===void 0)return ot(n,"Malformed LSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received LSTAT (id:${e})`),n.emit("LSTAT",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.FSTAT]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString();if(O.clear(),r===void 0||r.length>256)return ot(n,"Malformed FSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSTAT (id:${e})`),n.emit("FSTAT",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.SETSTAT]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0),s=zr(n._biOpt);if(O.clear(),s===void 0)return ot(n,"Malformed SETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received SETSTAT (id:${e})`),n.emit("SETSTAT",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)},[Be.FSETSTAT]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(),s=zr(n._biOpt);if(O.clear(),s===void 0||r.length>256)return ot(n,"Malformed FSETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSETSTAT (id:${e})`),n.emit("FSETSTAT",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)},[Be.OPENDIR]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0);if(O.clear(),r===void 0)return ot(n,"Malformed OPENDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received OPENDIR (id:${e})`),n.emit("OPENDIR",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.READDIR]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString();if(O.clear(),r===void 0||r.length>256)return ot(n,"Malformed READDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received READDIR (id:${e})`),n.emit("READDIR",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.REMOVE]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0);if(O.clear(),r===void 0)return ot(n,"Malformed REMOVE packet");n._debug&&n._debug(`SFTP: Inbound: Received REMOVE (id:${e})`),n.emit("REMOVE",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.MKDIR]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0),s=zr(n._biOpt);if(O.clear(),s===void 0)return ot(n,"Malformed MKDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received MKDIR (id:${e})`),n.emit("MKDIR",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)},[Be.RMDIR]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0);if(O.clear(),r===void 0)return ot(n,"Malformed RMDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received RMDIR (id:${e})`),n.emit("RMDIR",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.REALPATH]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0);if(O.clear(),r===void 0)return ot(n,"Malformed REALPATH packet");n._debug&&n._debug(`SFTP: Inbound: Received REALPATH (id:${e})`),n.emit("REALPATH",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.STAT]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0);if(O.clear(),r===void 0)return ot(n,"Malformed STAT packet");n._debug&&n._debug(`SFTP: Inbound: Received STAT (id:${e})`),n.emit("STAT",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.RENAME]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0),s=O.readString(!0);if(O.clear(),s===void 0)return ot(n,"Malformed RENAME packet");n._debug&&n._debug(`SFTP: Inbound: Received RENAME (id:${e})`),n.emit("RENAME",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)},[Be.READLINK]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0);if(O.clear(),r===void 0)return ot(n,"Malformed READLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received READLINK (id:${e})`),n.emit("READLINK",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Be.SYMLINK]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0),s=O.readString(!0);if(O.clear(),s===void 0)return ot(n,"Malformed SYMLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received SYMLINK (id:${e})`);let i;n._isOpenSSH?i=n.emit("SYMLINK",e,s,r):i=n.emit("SYMLINK",e,r,s),i||n.status(e,nt.OP_UNSUPPORTED)},[Be.EXTENDED]:(n,t)=>{O.init(t,1);let e=O.readUInt32BE(),r=O.readString(!0);if(r===void 0)return O.clear(),ot(n,"Malformed EXTENDED packet");let s;O.avail()&&(s=O.readRaw()),O.clear(),n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED (id:${e})`),n.emit("EXTENDED",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)}},{ERR_INVALID_ARG_TYPE:Q0,ERR_OUT_OF_RANGE:Xs,validateNumber:W0}=Rd(),Ld=128,Zt,Ya=[];function q0(n){Ya.length>0?Zt=Ya.pop():Zt=Buffer.allocUnsafe(n),Zt.used=0}function ja(n,t){if(!Number.isSafeInteger(n))throw W0(n,t),Number.isInteger(n)?new Xs(t,">= 0 and <= 2 ** 53 - 1",n):new Xs(t,"an integer",n);if(n<0)throw new Xs(t,">= 0 and <= 2 ** 53 - 1",n)}function qa(n){return n+7&-8}function qn(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,Dd.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&&(ja(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(ja(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new Xs("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}Ud(qn,Dd);qn.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()}))};qn.prototype._read=function(n){if(!Buffer.isBuffer(this.handle))return this.once("open",()=>this._read(n));if(this.destroyed)return;(!Zt||Zt.length-Zt.used<Ld)&&q0(this.readableHighWaterMark||this._readableState.highWaterMark);let t=Zt,e=Math.min(Zt.length-Zt.used,n),r=Zt.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,Zt,Zt.used,e,this.pos,(s,i)=>{if(s){this.emit("error",s),this.autoClose&&this.destroy();return}let o=null;if(r+e===t.used&&t===Zt)t.used=qa(t.used+i-e);else{let a=r+e&-8,c=qa(r+i);a-c>=Ld&&Ya.push(t.slice(c,a))}i>0&&(this.bytesRead+=i,o=t.slice(r,r+i)),this.pos+=i,this.push(o)}),Zt.used=qa(Zt.used+e)};qn.prototype._destroy=function(n,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",$d.bind(null,this,t,n));return}$d(this,t,n),this.handle=null,this._opening=!1};function $d(n,t,e){if(!n.handle)return r();n.sftp.close(n.handle,r);function r(s){s=s||e,t(s),n.isClosed=!0,s||n.emit("close")}}qn.prototype.close=function(n){this.destroy(null,n)};Object.defineProperty(qn.prototype,"pending",{get(){return this.handle===null},configurable:!0});function An(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,Xa.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&&(ja(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()}Ud(An,Xa);An.prototype._final=function(n){this.autoClose&&this.destroy(),n()};An.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,s=>e());return}if(this.flags[0]==="a"){let s=(i,o)=>{if(i){this.sftp.stat(this.path,(a,c)=>{if(a){this.destroy(),this.emit("error",i);return}s(null,c)});return}this.pos=o.size,this.emit("open",t),this.emit("ready")};this.sftp.fstat(t,s);return}this.emit("open",t),this.emit("ready")};this.sftp.fchmod(t,this.mode,e)}))};An.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,s)=>{if(r)return this.autoClose&&this.destroy(),e(r);this.bytesWritten+=s,e()}),this.pos+=n.length};An.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,s=n.length,i=(o,a)=>{if(o)return this.destroy(),t(o);this.bytesWritten+=a,--s===0&&t()};for(let o=0;o<n.length;++o){let a=n[o].chunk;e.write(r,a,0,a.length,this.pos,i),this.pos+=a.length}};typeof Xa.prototype.destroy!="function"&&(An.prototype.destroy=qn.prototype.destroy);An.prototype._destroy=qn.prototype._destroy;An.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()};An.prototype.destroySoon=An.prototype.end;Object.defineProperty(An.prototype,"pending",{get(){return this.handle===null},configurable:!0});Wd.exports={flagsToString:M0,OPEN_MODE:Ce,SFTP:Va,Stats:Js,STATUS_CODE:nt,stringToFlags:Fd}});var ic=lt((Cx,zd)=>{"use strict";var{Duplex:K0,Readable:V0,Writable:z0}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:qd}}=Fn(),{bufferSlice:Zs}=_n(),G0=32*1024,Mi=2*1024*1024,nc=Mi/2,Za=class extends V0{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=nc&&rc(this._channel))}},ec=class extends z0{constructor(t){super({highWaterMark:Mi}),this._channel=t}_write(t,e,r){let s=this._channel,i=s._client._protocol,o=s.outgoing,a=o.packetSize,c=o.id,l=o.window,f=t.length,u=0;if(o.state==="open"){for(;f-u>0&&l>0;){let h=f-u;h>l&&(h=l),h>a&&(h=a),u===0&&h===f?i.channelExtData(c,t,qd):i.channelExtData(c,Zs(t,u,u+h),qd),u+=h,l-=h}if(o.window=l,f-u>0){l===0&&(s._waitWindow=!0),u>0?s._chunkErr=Zs(t,u,f):s._chunkErr=t,s._chunkcbErr=r;return}r()}}},tc=class extends K0{constructor(t,e,r){let s={highWaterMark:Mi,allowHalfOpen:!r||r&&r.allowHalfOpen!==!1,emitClose:!1};super(s),this.allowHalfOpen=s.allowHalfOpen;let i=!!(r&&r.server);this.server=i,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,i?this.stderr=new ec(this):this.stderr=new Za(this,s),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",Kd).on("prefinish",Kd),this.on("end",Vd).on("close",Vd)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=nc&&rc(this))}_write(t,e,r){let s=this._client._protocol,i=this.outgoing,o=i.packetSize,a=i.id,c=i.window,l=t.length,f=0;if(i.state==="open"){for(;l-f>0&&c>0;){let u=l-f;u>c&&(u=c),u>o&&(u=o),f===0&&u===l?s.channelData(a,t):s.channelData(a,Zs(t,f,f+u)),f+=u,c-=u}if(i.window=c,l-f>0){c===0&&(this._waitWindow=!0),f>0?this._chunk=Zs(t,f,l):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,s){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,s)}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 Kd(){this.eof(),(this.server||!this.allowHalfOpen)&&this.close(),this.writable=!1}function Vd(){this.readable=!1}function rc(n){if(n.outgoing.state==="closed")return;let t=Mi-n.incoming.window;t<=0||(n.incoming.window+=t,n._client._protocol.channelWindowAdjust(n.outgoing.id,t))}zd.exports={Channel:tc,MAX_WINDOW:Mi,PACKET_SIZE:G0,windowAdjust:rc,WINDOW_THRESHOLD:nc}});var ac=lt((kx,jd)=>{"use strict";var{SFTP:Y0}=Ui(),Oi=2**32-1;function Gd(n,t,e,r){if(n._chanMgr.remove(t),typeof r!="function")return;let s;e instanceof Error?s=e:typeof e=="object"&&e!==null?(s=new Error(`(SSH) Channel open failure: ${e.description}`),s.reason=e.reason):(s=new Error("(SSH) Channel open failure: server closed channel unexpectedly"),s.reason=""),r(s)}function Yd(n,t,e,r,s){if(typeof e=="function"){Gd(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!==Y0&&(e.outgoing.state==="open"||e.outgoing.state==="eof")&&!s&&e.close(),e.outgoing.state==="closing"&&(e.outgoing.state="closed");let i=e._readableState,o=e._writableState;o&&!o.ending&&!o.finished&&!s&&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||i&&i.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 f=e._exit;c=()=>{f.code===null?e.emit("close",f.code,f.signal,f.dump,f.desc):e.emit("close",f.code)}}}!e.readable||e.destroyed||i&&i.endEmitted?c():e.once("end",c);let l=e.stderr._readableState;!e.stderr.readable||e.stderr.destroyed||l&&l.endEmitted?e.stderr.emit("close"):e.stderr.once("end",()=>e.stderr.emit("close"))}}var oc=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<Oi)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let r=this._channels;for(let s=0;s<Oi;++s)if(r[s]===void 0){e=s;break}}return e===void 0?-1:(this._channels[e]=t||!0,++this._count,e)}update(t,e){if(typeof t!="number"||t<0||t>=Oi||!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>=Oi||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=Oi||!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),s=this._client;for(let i=0;i<r.length;++i){let o=+r[i],a=e[o];Yd(s,o,a._channel||a,t,!0)}}},sc=(()=>{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),s=t;for(let i=0;i<r.length;++i){let o=r[i],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 l=a[c];if(typeof l=="string"){if(!l||s.indexOf(l)!==-1)continue;if(e.indexOf(l)===-1)throw new Error(`Unsupported algorithm: ${l}`);s===t&&(s=s.slice()),s.push(l)}else if(sc(l))for(let f=0;f<e.length;++f){let u=e[f];if(l.test(u)){if(s.indexOf(u)!==-1)continue;s===t&&(s=s.slice()),s.push(u)}}}break;case"prepend":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=a.length;c>=0;--c){let l=a[c];if(typeof l=="string"){if(!l||s.indexOf(l)!==-1)continue;if(e.indexOf(l)===-1)throw new Error(`Unsupported algorithm: ${l}`);s===t&&(s=s.slice()),s.unshift(l)}else if(sc(l))for(let f=e.length;f>=0;--f){let u=e[f];if(l.test(u)){if(s.indexOf(u)!==-1)continue;s===t&&(s=s.slice()),s.unshift(u)}}}break;case"remove":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let l=a[c];if(typeof l=="string"){if(!l)continue;let f=s.indexOf(l);if(f===-1)continue;s===t&&(s=s.slice()),s.splice(f,1)}else if(sc(l))for(let f=0;f<s.length;++f)l.test(s[f])&&(s===t&&(s=s.slice()),s.splice(f,1),--f)}break}}return s}return t}jd.exports={ChannelManager:oc,generateAlgorithmList:j0,onChannelOpenFailure:Gd,onCHANNEL_CLOSE:Yd,isWritable:n=>n&&n.writable&&n._readableState&&n._readableState.ended===!1}});var pc=lt((vx,mh)=>{"use strict";var{createHash:X0,getHashes:J0,randomFillSync:Z0}=require("crypto"),{Socket:eA}=require("net"),{lookup:tA}=require("dns"),nA=require("events"),rA=J0(),{COMPAT:hh,CHANNEL_EXTENDED_DATATYPE:{STDERR:iA},CHANNEL_OPEN_FAILURE:Fi,DEFAULT_CIPHER:Xd,DEFAULT_COMPRESSION:Jd,DEFAULT_KEX:Zd,DEFAULT_MAC:eh,DEFAULT_SERVER_HOST_KEY:th,DISCONNECT_REASON:nh,DISCONNECT_REASON_BY_VALUE:sA,SUPPORTED_CIPHER:oA,SUPPORTED_COMPRESSION:aA,SUPPORTED_KEX:cA,SUPPORTED_MAC:lA,SUPPORTED_SERVER_HOST_KEY:fA}=Fn(),{init:uA}=Xn(),dA=Qa(),{parseKey:no}=er(),{SFTP:hA}=Ui(),{bufferCopy:rh,makeBufferParser:ph,makeError:pA,readUInt32BE:gA,sigSSHToASN1:mA,writeUInt32BE:cc}=_n(),{AgentContext:ih,createAgent:sh,isAgent:oh}=ka(),{Channel:gh,MAX_WINDOW:ro,PACKET_SIZE:io,windowAdjust:ah,WINDOW_THRESHOLD:ch}=ic(),{ChannelManager:AA,generateAlgorithmList:Hi,isWritable:$t,onChannelOpenFailure:yA,onCHANNEL_CLOSE:EA}=ac(),eo=ph(),to=ph(),Qi=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,dc=n=>{},hc=class extends nA{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&&$t(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=Hi(t.algorithms.kex,Zd,cA),e.kex!==Zd&&(r=!1),e.serverHostKey=Hi(t.algorithms.serverHostKey,th,fA),e.serverHostKey!==th&&(r=!1),e.cs.cipher=Hi(t.algorithms.cipher,Xd,oA),e.cs.cipher!==Xd&&(r=!1),e.cs.mac=Hi(t.algorithms.hmac,eh,lA),e.cs.mac!==eh&&(r=!1),e.cs.compress=Hi(t.algorithms.compress,Jd,aA),e.cs.compress!==Jd&&(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=sh(t.agent):oh(t.agent)?this.config.agent=t.agent:this.config.agent=void 0,this.config.allowAgentFwd=t.agentForward===!0&&this.config.agent!==void 0;let s=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 i=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 AA(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=no(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 M=t.hostVerifier,N;rA.indexOf(t.hostHash)!==-1&&(N=t.hostHash),c=(L,K)=>{N&&(L=X0(N).update(L).digest("hex"));let ee=M(L,K);ee!==void 0&&K(ee)}}let l=this._sock=t.sock||new eA,f=!1,u=!1;this._protocol&&this._protocol.cleanup();let h=i?(M,N,L)=>{i(`Debug output from server: ${JSON.stringify(L)}`)}:void 0,p,A=this._protocol=new dA({ident:this.config.ident,offer:r?void 0:e,onWrite:M=>{$t(l)&&l.write(M)},onError:M=>{M.level==="handshake"&&clearTimeout(this._readyTimeout),A._destruct||l.removeAllListeners("data"),this.emit("error",M);try{l.end()}catch{}},onHeader:M=>{u=!0,this._remoteVer=M.versions.software,M.greeting&&this.emit("greeting",M.greeting)},onHandshakeComplete:M=>{this.emit("handshake",M),f||(f=!0,A.service("ssh-userauth"))},debug:i,hostVerifier:c,messageHandlers:{DEBUG:h,DISCONNECT:(M,N,L)=>{if(N!==nh.BY_APPLICATION){L||(L=sA[N],L===void 0&&(L=`Unexpected disconnection reason: ${N}`));let K=new Error(L);K.code=N,this.emit("error",K)}l.end()},SERVICE_ACCEPT:(M,N)=>{N==="ssh-userauth"&&Y()},EXT_INFO:(M,N)=>{if(p===void 0){for(let L of N)if(L.name==="server-sig-algs"){p=L.algs;return}p=null}},USERAUTH_BANNER:(M,N)=>{this.emit("banner",N)},USERAUTH_SUCCESS:M=>{C(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:(M,N,L)=>{if(b.keyAlgos){let K=b.keyAlgos[0][0];if(i&&i(`Client: ${b.type} (${K}) auth failed`),b.keyAlgos.shift(),b.keyAlgos.length){let[ee,ue]=b.keyAlgos[0];switch(b.type){case"agent":A.authPK(b.username,b.agentCtx.currentKey(),ee);return;case"publickey":A.authPK(b.username,b.key,ee);return;case"hostbased":A.authHostbased(b.username,b.key,b.localHostname,b.localUsername,ee,(ie,Xe)=>{let ft=b.key.sign(ie,ue);if(ft instanceof Error)return ft.message=`Error while signing with key: ${ft.message}`,ft.level="client-authentication",this.emit("error",ft),Y();Xe(ft)});return}}else b.keyAlgos=void 0}if(b.type==="agent"){let K=b.agentCtx.pos();return i&&i(`Client: Agent key #${K+1} failed`),te()}i&&i(`Client: ${b.type} auth failed`),w=L,k=N,Y()},USERAUTH_PASSWD_CHANGEREQ:(M,N)=>{b.type==="password"&&this.emit("change password",N,L=>{A.authPassword(this.config.username,this.config.password,L)})},USERAUTH_PK_OK:M=>{let N,L;if(b.keyAlgos&&([N,L]=b.keyAlgos[0]),b.type==="agent"){let K=b.agentCtx.currentKey();A.authPK(b.username,K,N,(ee,ue)=>{let ie={hash:L};b.agentCtx.sign(K,ee,ie,(Xe,ft)=>{if(Xe)Xe.level="agent",this.emit("error",Xe);else return ue(ft);te()})})}else b.type==="publickey"&&A.authPK(b.username,b.key,N,(K,ee)=>{let ue=b.key.sign(K,L);if(ue instanceof Error)return ue.message=`Error signing data with key: ${ue.message}`,ue.level="client-authentication",this.emit("error",ue),Y();ee(ue)})},USERAUTH_INFO_REQUEST:(M,N,L,K)=>{if(b.type==="keyboard-interactive"){if((Array.isArray(K)?K.length:0)===0){i&&i("Client: Sending automatic USERAUTH_INFO_RESPONSE"),A.authInfoRes();return}b.prompt(N,L,"",K,ue=>{A.authInfoRes(ue)})}},REQUEST_SUCCESS:(M,N)=>{o.length&&o.shift()(!1,N)},REQUEST_FAILURE:M=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:(M,N,L,K)=>{N==="hostkeys-00@openssh.com"?(wA(this,K,(ee,ue)=>{ee||this.emit("hostkeys",ue)}),L&&A.requestSuccess()):L&&A.requestFailure()},CHANNEL_OPEN:(M,N)=>{SA(this,N)},CHANNEL_OPEN_CONFIRMATION:(M,N)=>{let L=this._chanMgr.get(N.recipient);if(typeof L!="function")return;let K=L.type==="sftp",ue={type:K?"session":L.type,incoming:{id:N.recipient,window:ro,packetSize:io,state:"open"},outgoing:{id:N.sender,window:N.window,packetSize:N.packetSize,state:"open"}},ie=K?new hA(this,ue,{debug:i}):new gh(this,ue);this._chanMgr.update(N.recipient,ie),L(void 0,ie)},CHANNEL_OPEN_FAILURE:(M,N,L,K)=>{let ee=this._chanMgr.get(N);if(typeof ee!="function")return;yA(this,N,{reason:L,description:K},ee)},CHANNEL_DATA:(M,N,L)=>{let K=this._chanMgr.get(N);if(!(typeof K!="object"||K===null)&&K.incoming.window!==0){if(K.incoming.window-=L.length,K.push(L)===!1){K._waitChanDrain=!0;return}K.incoming.window<=ch&&ah(K)}},CHANNEL_EXTENDED_DATA:(M,N,L,K)=>{if(K!==iA)return;let ee=this._chanMgr.get(N);if(!(typeof ee!="object"||ee===null)&&ee.incoming.window!==0){if(ee.incoming.window-=L.length,!ee.stderr.push(L)){ee._waitChanDrain=!0;return}ee.incoming.window<=ch&&ah(ee)}},CHANNEL_WINDOW_ADJUST:(M,N,L)=>{let K=this._chanMgr.get(N);typeof K!="object"||K===null||(K.outgoing.window+=L,K._waitWindow&&(K._waitWindow=!1,K._chunk?K._write(K._chunk,null,K._chunkcb):K._chunkcb?K._chunkcb():K._chunkErr?K.stderr._write(K._chunkErr,null,K._chunkcbErr):K._chunkcbErr&&K._chunkcbErr()))},CHANNEL_SUCCESS:(M,N)=>{let L=this._chanMgr.get(N);typeof L!="object"||L===null||(this._resetKA(),L._callbacks.length&&L._callbacks.shift()(!1))},CHANNEL_FAILURE:(M,N)=>{let L=this._chanMgr.get(N);typeof L!="object"||L===null||(this._resetKA(),L._callbacks.length&&L._callbacks.shift()(!0))},CHANNEL_REQUEST:(M,N,L,K,ee)=>{let ue=this._chanMgr.get(N);if(typeof ue!="object"||ue===null)return;let ie=ue._exit;if(ie.code===void 0){switch(L){case"exit-status":ue.emit("exit",ie.code=ee);return;case"exit-signal":ue.emit("exit",ie.code=null,ie.signal=`SIG${ee.signal}`,ie.dump=ee.coreDumped,ie.desc=ee.errorMessage);return}K&&M.channelFailure(ue.outgoing.id)}},CHANNEL_EOF:(M,N)=>{let L=this._chanMgr.get(N);typeof L!="object"||L===null||L.incoming.state==="open"&&(L.incoming.state="eof",L.readable&&L.push(null),L.stderr.readable&&L.stderr.push(null))},CHANNEL_CLOSE:(M,N)=>{EA(this,N,this._chanMgr.get(N))}}});l.pause();let E=this.config.keepaliveInterval,S=this.config.keepaliveCountMax,x=0,R,H=()=>{if(++x>S){if(clearInterval(R),l.readable){let M=new Error("Keepalive timeout");M.level="client-timeout",this.emit("error",M),l.destroy()}return}$t(l)?(o.push(C),A.ping()):clearInterval(R)};function C(){E>0&&(x=0,clearInterval(R),$t(l)&&(R=setInterval(H,E)))}this._resetKA=C;let U=(()=>{let M=!1;return()=>{if(!M&&(M=!0,B&&!u)){let N=pA("Connection lost before handshake","protocol",!0);this.emit("error",N)}}})(),Q=(()=>{let M=!1;return()=>{M||(M=!0,B=!0,i&&i("Socket connected"),this.emit("connect"),uA.then(()=>{A.start(),l.on("data",N=>{try{A.parse(N,0,N.length)}catch(L){this.emit("error",L);try{$t(l)&&l.end()}catch{}}}),l.stderr&&typeof l.stderr.resume=="function"&&l.stderr.resume(),l.resume()}).catch(N=>{this.emit("error",N);try{$t(l)&&l.end()}catch{}}))}})(),B=!1;l.on("connect",Q).on("timeout",()=>{this.emit("timeout")}).on("error",M=>{i&&i(`Socket error: ${M.message}`),clearTimeout(this._readyTimeout),M.level="client-socket",this.emit("error",M)}).on("end",()=>{i&&i("Socket ended"),U(),A.cleanup(),clearTimeout(this._readyTimeout),clearInterval(R),this.emit("end")}).on("close",()=>{i&&i("Socket closed"),U(),A.cleanup(),clearTimeout(this._readyTimeout),clearInterval(R),this.emit("close");let M=o;o=this._callbacks=[];let N=new Error("No response from server");for(let L=0;L<M.length;++L)M[L](N);this._chanMgr.cleanup(N)});let b,w=null,k=null,v=["none"];this.config.password!==void 0&&v.push("password"),a!==void 0&&v.push("publickey"),this._agent!==void 0&&v.push("agent"),this.config.tryKeyboard&&v.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&v.push("hostbased"),Array.isArray(s)?s=dh(s):typeof s!="function"&&(s=dh(v));let P=!1,ne=M=>{if(!P){if(P=!0,M===!1){let N=new Error("All configured authentication methods failed");N.level="client-authentication",this.emit("error",N),this.end();return}if(typeof M=="string"){let N=M;if(v.indexOf(N)===-1)return G(`Authentication method not allowed: ${N}`);let L=this.config.username;switch(N){case"password":M={type:N,username:L,password:this.config.password};break;case"publickey":M={type:N,username:L,key:a};break;case"hostbased":M={type:N,username:L,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":M={type:N,username:L,agentCtx:new ih(this._agent)};break;case"keyboard-interactive":M={type:N,username:L,prompt:(...K)=>this.emit("keyboard-interactive",...K)};break;case"none":M={type:N,username:L};break;default:return G(`Skipping unsupported authentication method: ${M}`)}}else{if(typeof M!="object"||M===null)return G(`Skipping invalid authentication attempt: ${M}`);{let N=M.username;if(typeof N!="string")return G(`Skipping invalid authentication attempt: ${M}`);let L=M.type;switch(L){case"password":{let{password:K}=M;if(typeof K!="string"&&!Buffer.isBuffer(K))return G("Skipping invalid password auth attempt");M={type:L,username:N,password:K};break}case"publickey":{let K=no(M.key,M.passphrase);if(K instanceof Error)return G("Skipping invalid key auth attempt");if(!K.isPrivateKey())return G("Skipping non-private key");M={type:L,username:N,key:K};break}case"hostbased":{let{localHostname:K,localUsername:ee}=M,ue=no(M.key,M.passphrase);if(ue instanceof Error||typeof K!="string"||typeof ee!="string")return G("Skipping invalid hostbased auth attempt");if(!ue.isPrivateKey())return G("Skipping non-private key");M={type:L,username:N,key:ue,localHostname:K,localUsername:ee};break}case"agent":{let K=M.agent;if(typeof K=="string"&&K.length)K=sh(K);else if(!oh(K))return G(`Skipping invalid agent: ${M.agent}`);M={type:L,username:N,agentCtx:new ih(K)};break}case"keyboard-interactive":{let{prompt:K}=M;if(typeof K!="function")return G("Skipping invalid keyboard-interactive auth attempt");M={type:L,username:N,prompt:K};break}case"none":M={type:L,username:N};break;default:return G(`Skipping unsupported authentication method: ${M}`)}}}b=M;try{let N=b.username;switch(b.type){case"password":A.authPassword(N,b.password);break;case"publickey":{let L;if(b.keyAlgos=uc(this,b.key,p),b.keyAlgos)if(b.keyAlgos.length)L=b.keyAlgos[0][0];else return G("Skipping key authentication (no mutual hash algorithm)");A.authPK(N,b.key,L);break}case"hostbased":{let L,K;if(b.keyAlgos=uc(this,b.key,p),b.keyAlgos)if(b.keyAlgos.length)[L,K]=b.keyAlgos[0];else return G("Skipping hostbased authentication (no mutual hash algorithm)");A.authHostbased(N,b.key,b.localHostname,b.localUsername,L,(ee,ue)=>{let ie=b.key.sign(ee,K);if(ie instanceof Error)return ie.message=`Error while signing with key: ${ie.message}`,ie.level="client-authentication",this.emit("error",ie),Y();ue(ie)});break}case"agent":b.agentCtx.init(L=>{if(L)return L.level="agent",this.emit("error",L),Y();te()});break;case"keyboard-interactive":A.authKeyboard(N);break;case"none":A.authNone(N);break}}finally{P=!1}}};function G(M){i&&i(M),process.nextTick(Y)}function Y(){P=!1;let M=s(k,w,ne);P||M===void 0||ne(M)}let te=()=>{if(b.type==="agent"){let M=b.agentCtx.nextKey();if(M===!1)i&&i("Agent: No more keys left to try"),i&&i("Client: agent auth failed"),Y();else{let N=b.agentCtx.pos(),L;if(b.keyAlgos=uc(this,M,p),b.keyAlgos)if(b.keyAlgos.length)L=b.keyAlgos[0][0];else{i&&i(`Agent: Skipping key #${N+1} (no mutual hash algorithm)`),te();return}i&&i(`Agent: Trying key #${N+1}`),A.authPK(b.username,M,L)}}},le=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let M=new Error("Timed out while waiting for handshake");M.level="client-timeout",this.emit("error",M),l.destroy()},this.config.readyTimeout))};if(t.sock)le(),typeof l.connecting=="boolean"&&l.connecting||Q();else{let M=this.config.host,N=this.config.forceIPv4,L=this.config.forceIPv6;i&&i(`Client: Trying ${M} on port ${this.config.port} ...`);let K=()=>{le(),l.connect({host:M,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),l.setMaxListeners(0),l.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!N&&!L||N&&L?K():tA(M,N?4:6,(ee,ue,ie)=>{if(ee){let Xe=N?"IPv4":"IPv6",ft=new Error(`Error while looking up ${Xe} address for '${M}': ${ee}`);clearTimeout(this._readyTimeout),ft.level="client-dns",this.emit("error",ft),this.emit("close");return}M=ue,K()})}return this}end(){return this._sock&&$t(this._sock)&&(this._protocol.disconnect(nh.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&$t(this._sock)&&this._sock.destroy(),this}exec(t,e,r){if(!this._sock||!$t(this._sock))throw new Error("Not connected");typeof e=="function"&&(r=e,e={});let s={allowHalfOpen:e.allowHalfOpen!==!1};return Yr(this,"session",s,(i,o)=>{if(i){r(i);return}let a=[];function c(l){if(l){o.close(),r(l);return}a.length&&a.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&a.push(()=>uh(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&lc(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>fh(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>lh(o,e.x11,c))),a.push(()=>bA(o,t,e,r)),a.shift()()}),this}shell(t,e,r){if(!this._sock||!$t(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),Yr(this,"session",(s,i)=>{if(s){r(s);return}let o=[];function a(c){if(c){i.close(),r(c);return}o.length&&o.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&o.push(()=>uh(i,a)),t!==!1&&o.push(()=>fh(i,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&lc(i,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>lh(i,e.x11,a))),o.push(()=>_A(i,r)),o.shift()()}),this}subsys(t,e){if(!this._sock||!$t(this._sock))throw new Error("Not connected");return Yr(this,"session",(r,s)=>{if(r){e(r);return}fc(s,t,(i,o)=>{if(i){e(i);return}e(void 0,o)})}),this}forwardIn(t,e,r){if(!this._sock||!$t(this._sock))throw new Error("Not connected");let s=typeof r=="function";return s&&this._callbacks.push((i,o)=>{if(i){r(i!==!0?i:new Error(`Unable to bind to ${t}:${e}`));return}let a=e;e===0&&o&&o.length>=4&&(a=gA(o,0),this._protocol._compatFlags&hh.DYN_RPORT_BUG||(e=a)),this._forwarding[`${t}:${e}`]=a,r(void 0,a)}),this._protocol.tcpipForward(t,e,s),this}unforwardIn(t,e,r){if(!this._sock||!$t(this._sock))throw new Error("Not connected");let s=typeof r=="function";return s&&this._callbacks.push(i=>{if(i){r(i!==!0?i:new Error(`Unable to unbind from ${t}:${e}`));return}delete this._forwarding[`${t}:${e}`],r()}),this._protocol.cancelTcpipForward(t,e,s),this}forwardOut(t,e,r,s,i){if(!this._sock||!$t(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:r,dstPort:s};return typeof i!="function"&&(i=dc),Yr(this,"direct-tcpip",o,i),this}openssh_noMoreSessions(t){if(!this._sock||!$t(this._sock))throw new Error("Not connected");let e=typeof t=="function";return!this.config.strictVendor||this.config.strictVendor&&Qi.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||!$t(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Qi.test(this._remoteVer)?(r&&this._callbacks.push(s=>{if(s){e(s!==!0?s: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||!$t(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Qi.test(this._remoteVer)?(r&&this._callbacks.push(s=>{if(s){e(s!==!0?s: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||!$t(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=dc),!this.config.strictVendor||this.config.strictVendor&&Qi.test(this._remoteVer)?(Yr(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||!$t(this._sock))throw new Error("Not connected");return typeof t=="function"&&(e=t,t=void 0),Yr(this,"sftp",(r,s)=>{if(r){e(r);return}let i=(o,a)=>{if(o){e(o);return}function c(){s.removeListener("ready",l),s.removeListener("error",f),s.removeListener("exit",u),s.removeListener("close",u)}function l(){c(),e(void 0,s)}function f(h){c(),e(h)}function u(h,p){c();let A;typeof h=="number"?A=`Received exit code ${h} while establishing SFTP session`:p!==void 0?A=`Received signal ${p} while establishing SFTP session`:A="Received unexpected SFTP session termination";let E=new Error(A);E.code=h,E.signal=p,e(E)}s.on("ready",l).on("error",f).on("exit",u).on("close",u),s._init()};typeof t=="object"&&t!==null?lc(s,t,o=>{if(o){e(o);return}fc(s,"sftp",i)}):fc(s,"sftp",i)}),this}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function Yr(n,t,e,r){let s=ro,i=io;typeof e=="function"&&(r=e,e={});let o=(c,l)=>{r(c,l)};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,s,i);break;case"direct-tcpip":n._protocol.directTcpip(a,s,i,e);break;case"direct-streamlocal@openssh.com":n._protocol.openssh_directStreamLocal(a,s,i,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function lh(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=xA());let s=typeof e=="function";if(n.outgoing.state!=="open"){s&&e(new Error("Channel is not open"));return}s&&n._callbacks.push(i=>{if(i){e(i!==!0?i: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,s)}function fh(n,t,e){let r=24,s=80,i=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"&&(s=t.cols),typeof t.width=="number"&&(i=t.width),typeof t.height=="number"&&(o=t.height),typeof t.term=="string"&&(a=t.term),typeof t.modes=="object"&&(c=t.modes));let l=typeof e=="function";if(n.outgoing.state!=="open"){l&&e(new Error("Channel is not open"));return}l&&n._callbacks.push(f=>{if(f){e(f!==!0?f:new Error("Unable to request a pseudo-terminal"));return}e()}),n._client._protocol.pty(n.outgoing.id,r,s,o,i,a,c,l)}function uh(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 _A(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 bA(n,t,e,r){if(n.outgoing.state!=="open"){r(new Error("Channel is not open"));return}n._callbacks.push(s=>{if(s){r(s!==!0?s: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 lc(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(i=>{if(i){e(i!==!0?i:new Error("Unable to set environment"));return}e()});let s=Object.keys(t||{});for(let i=0;i<s.length;++i){let o=s[i],a=t[o];n._client._protocol.env(n.outgoing.id,o,a,r)}}function fc(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 SA(n,t){let e=-1,r,s=()=>{let c={type:t.type,incoming:{id:e,window:ro,packetSize:io,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},l=new gh(n,c);return n._chanMgr.update(e,l),n._protocol.channelOpenConfirm(t.sender,e,ro,io),l},i=()=>{r===void 0&&(e===-1?r=Fi.RESOURCE_SHORTAGE:r=Fi.CONNECT_FAILED),e!==-1&&n._chanMgr.remove(e),n._protocol.channelOpenFail(t.sender,r,"")},o=()=>(e=n._chanMgr.add(),e===-1&&(r=Fi.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,s,i);return}break}case"forwarded-streamlocal@openssh.com":if(n._forwardingUnix[a.socketPath]!==void 0&&o()){n.emit("unix connection",a,s,i);return}break;case"auth-agent@openssh.com":if(n._agentFwdEnabled&&typeof n._agent.getStream=="function"&&o()){n._agent.getStream((c,l)=>{if(c)return i();let f=s();f.pipe(l).pipe(f)});return}break;case"x11":if(n._acceptX11!==0&&o()){n.emit("x11",a,s,i);return}break;default:r=Fi.UNKNOWN_CHANNEL_TYPE,n.config.debug&&n.config.debug(`Client: Automatic rejection of unsupported incoming channel open type: ${t.type}`)}r===void 0&&(r=Fi.ADMINISTRATIVELY_PROHIBITED,n.config.debug&&n.config.debug("Client: Automatic rejection of unexpected incoming channel open for: "+t.type)),i()}var xA=(()=>{let n=Buffer.allocUnsafe(16);return()=>(Z0(n,0,16),n.hexSlice(0,16))})();function dh(n){if(!Array.isArray(n))throw new Error("authList must be an array");let t=0;return(e,r,s)=>t===n.length?!1:n[t++]}function wA(n,t,e){if(!n._sock||!$t(n._sock))return;if(typeof e!="function"&&(e=dc),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let r=[];for(let s of t){let i=no(s);if(i instanceof Error)throw i;r.push(i)}if(!n.config.strictVendor||n.config.strictVendor&&Qi.test(n._remoteVer)){n._callbacks.push((s,i)=>{if(s){e(s!==!0?s:new Error("Server failed to prove supplied keys"));return}let o=[],a=0;for(eo.init(i,0);eo.avail()&&a!==r.length;){let c=r[a++],l=c.getPublicSSH(),f=eo.readString();to.init(f,0);let u=to.readString(!0),h=to.readString(),p;if(u!==c.type)if(c.type==="ssh-rsa")switch(u){case"rsa-sha2-256":p="sha256";break;case"rsa-sha2-512":p="sha512";break;default:continue}else continue;let A=n._protocol._kex.sessionID,E=Buffer.allocUnsafe(37+A.length+4+l.length),S=0;cc(E,29,S),E.utf8Write("hostkeys-prove-00@openssh.com",S+=4,29),cc(E,A.length,S+=29),rh(A,E,0,A.length,S+=4),cc(E,l.length,S+=A.length),rh(l,E,0,l.length,S+=4),(h=mA(h,u))&&c.verify(E,h,p)===!0&&o.push(c)}to.clear(),eo.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 uc(n,t,e){switch(t.type){case"ssh-rsa":if(n._protocol._compatFlags&hh.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"]]}}mh.exports=hc});var yh=lt(Ah=>{"use strict";var{Agent:mc}=require("http"),{Agent:IA}=require("https"),{connect:CA}=require("tls"),gc;for(let n of[mc,IA]){class t extends n{constructor(r,s){super(s),this._connectCfg=r,this._defaultSrcIP=s&&s.srcIP||"localhost"}createConnection(r,s){let i=r&&r.localAddress||this._defaultSrcIP,o=r&&r.localPort||0,a=r.host,c=r.port;gc===void 0&&(gc=pc());let l=new gc,f=!1;l.on("ready",()=>{l.forwardOut(i,o,a,c,(u,h)=>{if(f=!0,u)return l.end(),s(u);h.once("close",()=>l.end()),s(null,kA(h,n,r))})}).on("error",s).on("close",()=>{f||s(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}Ah[n===mc?"SSHTTPAgent":"SSHTTPSAgent"]=t}function Wi(){}function kA(n,t,e){if(t===mc)return n.setKeepAlive=Wi,n.setNoDelay=Wi,n.setTimeout=Wi,n.ref=Wi,n.unref=Wi,n.destroySoon=n.destroy,n;e.socket=n;let r=CA(e),s=(()=>{let i=!1;return()=>{i||(i=!0,n.isPaused()&&n.resume())}})();return r.on("end",s).on("close",s),r}});var _h=lt((Rx,_c)=>{"use strict";var{Server:vA}=require("net"),Ki=require("events"),{listenerCount:Yt}=Ki,{CHANNEL_OPEN_FAILURE:jr,DEFAULT_CIPHER:BA,DEFAULT_COMPRESSION:RA,DEFAULT_KEX:NA,DEFAULT_MAC:PA,DEFAULT_SERVER_HOST_KEY:TA,DISCONNECT_REASON:Xr,DISCONNECT_REASON_BY_VALUE:LA,SUPPORTED_CIPHER:$A,SUPPORTED_COMPRESSION:DA,SUPPORTED_KEX:UA,SUPPORTED_MAC:MA,SUPPORTED_SERVER_HOST_KEY:OA}=Fn(),{init:FA}=Xn(),{KexInit:HA}=Hs(),{parseKey:Eh}=er(),QA=Qa(),{SFTP:WA}=Ui(),{writeUInt32BE:qA}=_n(),{Channel:Jr,MAX_WINDOW:rr,PACKET_SIZE:ir,windowAdjust:KA,WINDOW_THRESHOLD:VA}=ic(),{ChannelManager:zA,generateAlgorithmList:qi,isWritable:so,onChannelOpenFailure:GA,onCHANNEL_CLOSE:YA}=ac(),jA=10,sr=class extends Ki{constructor(t,e,r,s,i){super(),this.username=this.user=e,this.service=r,this.method=s,this._initialResponse=!1,this._finalResponse=!1,this._multistep=!1,this._cbfinal=(o,a,c)=>{this._finalResponse||(this._finalResponse=!0,i(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)}},oo=class extends sr{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this._multistep=!0,this._cb=void 0,this._onInfoResponse=a=>{let c=this._cb;c&&(this._cb=void 0,c(a))},this.submethods=i,this.on("abort",()=>{this._cb&&this._cb(new Error("Authentication request aborted"))})}prompt(t,e,r,s){Array.isArray(t)||(t=[t]),typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"?(s=r,r=void 0):typeof s!="function"&&(s=void 0);for(let i=0;i<t.length;++i)typeof t[i]=="string"&&(t[i]={prompt:t[i],echo:!0});this._cb=s,this._initialResponse=!0,this._protocol.authInfoReq(e,r,t)}},yc=class extends sr{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.key={algo:i.keyAlgo,data:i.key},this.hashAlgo=i.hashAlgo,this.signature=i.signature,this.blob=i.blob}accept(){this.signature?sr.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},Ec=class extends sr{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.key={algo:i.keyAlgo,data:i.key},this.hashAlgo=i.hashAlgo,this.signature=i.signature,this.blob=i.blob,this.localHostname=i.localHostname,this.localUsername=i.localUsername}},ao=class extends sr{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.password=i,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)}},Nn=class extends Ki{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:rr,packetSize:ir,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},un=class extends Ki{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new Error("Missing configuration object");let r=Object.create(null),s=[],i=t.hostKeys;if(!Array.isArray(i))throw new Error("hostKeys must be an array");let o=typeof t.algorithms=="object"&&t.algorithms!==null?t.algorithms:{},a=qi(o.serverHostKey,TA,OA);for(let h=0;h<i.length;++h){let p;if(Buffer.isBuffer(i[h])||typeof i[h]=="string"?p=Eh(i[h]):p=Eh(i[h].key,i[h].passphrase),p instanceof Error)throw new Error(`Cannot parse privateKey: ${p.message}`);if(Array.isArray(p)&&(p=p[0]),p.getPrivatePEM()===null)throw new Error("privateKey value contains an invalid private key");if(!s.includes(p.type))if(p.type==="ssh-rsa"){let A=a.indexOf("ssh-rsa"),E=a.indexOf("rsa-sha2-256"),S=a.indexOf("rsa-sha2-512");A===-1&&(A=1/0),[A,E,S].sort(XA).forEach(x=>{if(x===-1)return;let R;switch(x){case A:R="ssh-rsa";break;case E:R="rsa-sha2-256";break;case S:R="rsa-sha2-512";break;default:return}r[R]=p,s.push(R)})}else r[p.type]=p,s.push(p.type)}let c={kex:qi(o.kex,NA,UA).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:s,cs:{cipher:qi(o.cipher,BA,$A),mac:qi(o.hmac,PA,MA),compress:qi(o.compress,RA,DA),lang:[]},sc:void 0};c.sc=c.cs,typeof e=="function"&&this.on("connection",e);let l=typeof t.debug=="function"?t.debug:void 0,f=t.ident?Buffer.from(t.ident):void 0,u=new HA(c);this._srv=new vA(h=>{if(this._connections>=this.maxConnections){h.destroy();return}++this._connections,h.once("close",()=>{--this._connections});let p;if(l){let A=`[${process.hrtime().join(".")}] `;p=E=>{l(`${A}${E}`)}}new co(h,r,f,u,p,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}};un.KEEPALIVE_CLIENT_INTERVAL=15e3;un.KEEPALIVE_CLIENT_COUNT_MAX=3;var co=class extends Ki{constructor(t,e,r,s,i,o,a){super();let c=0,l=!1,f=[],u,h,p,A=[];this._sock=t,this._chanMgr=new zA(this),this._debug=i,this.noMoreSessions=!1,this.authenticated=!1;function E(B){}this.on("error",E);let S=i?(B,b,w)=>{i(`Debug output from client: ${JSON.stringify(w)}`)}:void 0,x=typeof a.keepaliveInterval=="number"&&isFinite(a.keepaliveInterval)&&a.keepaliveInterval>0?a.keepaliveInterval:typeof un.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(un.KEEPALIVE_CLIENT_INTERVAL)&&un.KEEPALIVE_CLIENT_INTERVAL>0?un.KEEPALIVE_CLIENT_INTERVAL:-1,R=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof un.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(un.KEEPALIVE_CLIENT_COUNT_MAX)&&un.KEEPALIVE_CLIENT_COUNT_MAX>=0?un.KEEPALIVE_CLIENT_COUNT_MAX:-1,H=0;x!==-1&&R!==-1&&(this.once("ready",()=>{let B=()=>{clearInterval(h)};this.on("close",B).on("end",B),h=setInterval(()=>{if(++H>R){clearInterval(h);let b=new Error("Keepalive timeout");b.level="client-timeout",this.emit("error",b),this.end()}else C.ping()},x)}),p=()=>{h&&h.refresh(),H=0});let C=this._protocol=new QA({server:!0,hostKeys:e,ident:r,offer:s,onPacket:p,greeting:a.greeting,banner:a.banner,onWrite:B=>{so(t)&&t.write(B)},onError:B=>{C._destruct||t.removeAllListeners("data"),this.emit("error",B);try{t.end()}catch{}},onHeader:B=>{this.removeListener("error",E);let b={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:B};if(!o.emit("connection",this,b)){C.disconnect(Xr.BY_APPLICATION),t.end();return}B.greeting&&this.emit("greeting",B.greeting)},onHandshakeComplete:B=>{++c>1&&this.emit("rekey"),this.emit("handshake",B)},debug:i,messageHandlers:{DEBUG:S,DISCONNECT:(B,b,w)=>{if(b!==Xr.BY_APPLICATION){w||(w=LA[b],w===void 0&&(w=`Unexpected disconnection reason: ${b}`));let k=new Error(w);k.code=b,this.emit("error",k)}t.end()},CHANNEL_OPEN:(B,b)=>{if(b.type==="session"&&this.noMoreSessions||!this.authenticated){let te=jr.ADMINISTRATIVELY_PROHIBITED;return C.channelOpenFail(b.sender,te)}let w=-1,k,v=!1,P,ne=()=>{v||(v=!0,k===void 0&&(w===-1?k=jr.RESOURCE_SHORTAGE:k=jr.CONNECT_FAILED),w!==-1&&this._chanMgr.remove(w),C.channelOpenFail(b.sender,k,""))},G=()=>(w=this._chanMgr.add(),w===-1&&(k=jr.RESOURCE_SHORTAGE,i&&i("Automatic rejection of incoming channel open: no channels available")),w!==-1),Y=b.data;switch(b.type){case"session":if(Yt(this,"session")&&G()){P=()=>{if(v)return;v=!0;let te=new Nn(this,b,w);return this._chanMgr.update(w,te),C.channelOpenConfirm(b.sender,w,rr,ir),te},this.emit("session",P,ne);return}break;case"direct-tcpip":if(Yt(this,"tcpip")&&G()){P=()=>{if(v)return;v=!0;let te={type:void 0,incoming:{id:w,window:rr,packetSize:ir,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},le=new Jr(this,te,{server:!0});return this._chanMgr.update(w,le),C.channelOpenConfirm(b.sender,w,rr,ir),le},this.emit("tcpip",P,ne,Y);return}break;case"direct-streamlocal@openssh.com":if(Yt(this,"openssh.streamlocal")&&G()){P=()=>{if(v)return;v=!0;let te={type:void 0,incoming:{id:w,window:rr,packetSize:ir,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},le=new Jr(this,te,{server:!0});return this._chanMgr.update(w,le),C.channelOpenConfirm(b.sender,w,rr,ir),le},this.emit("openssh.streamlocal",P,ne,Y);return}break;default:k=jr.UNKNOWN_CHANNEL_TYPE,i&&i(`Automatic rejection of unsupported incoming channel open type: ${b.type}`)}k===void 0&&(k=jr.ADMINISTRATIVELY_PROHIBITED,i&&i(`Automatic rejection of unexpected incoming channel open for: ${b.type}`)),ne()},CHANNEL_OPEN_CONFIRMATION:(B,b)=>{let w=this._chanMgr.get(b.recipient);if(typeof w!="function")return;let k={type:w.type,incoming:{id:b.recipient,window:rr,packetSize:ir,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},v=new Jr(this,k,{server:!0});this._chanMgr.update(b.recipient,v),w(void 0,v)},CHANNEL_OPEN_FAILURE:(B,b,w,k)=>{let v=this._chanMgr.get(b);if(typeof v!="function")return;GA(this,b,{reason:w,description:k},v)},CHANNEL_DATA:(B,b,w)=>{let k=this._chanMgr.get(b);if(!(typeof k!="object"||k===null)&&!(k.constructor===Nn&&(k=k._channel,!k))&&k.incoming.window!==0){if(k.incoming.window-=w.length,k.push(w)===!1){k._waitChanDrain=!0;return}k.incoming.window<=VA&&KA(k)}},CHANNEL_EXTENDED_DATA:(B,b,w,k)=>{},CHANNEL_WINDOW_ADJUST:(B,b,w)=>{let k=this._chanMgr.get(b);typeof k!="object"||k===null||k.constructor===Nn&&(k=k._channel,!k)||(k.outgoing.window+=w,k._waitWindow&&(k._waitWindow=!1,k._chunk?k._write(k._chunk,null,k._chunkcb):k._chunkcb?k._chunkcb():k._chunkErr?k.stderr._write(k._chunkErr,null,k._chunkcbErr):k._chunkcbErr&&k._chunkcbErr()))},CHANNEL_SUCCESS:(B,b)=>{let w=this._chanMgr.get(b);typeof w!="object"||w===null||w.constructor===Nn&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!1)},CHANNEL_FAILURE:(B,b)=>{let w=this._chanMgr.get(b);typeof w!="object"||w===null||w.constructor===Nn&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!0)},CHANNEL_REQUEST:(B,b,w,k,v)=>{let P=this._chanMgr.get(b);if(typeof P!="object"||P===null)return;let ne=!1,G,Y;if(P.constructor!==Nn){k&&C.channelFailure(P.outgoing.id);return}if(k&&(w!=="shell"&&w!=="exec"&&w!=="subsystem"&&(G=()=>{ne||P._ending||P._channel||(ne=!0,C.channelSuccess(P._chanInfo.outgoing.id))}),Y=()=>{ne||P._ending||P._channel||(ne=!0,C.channelFailure(P._chanInfo.outgoing.id))}),P._ending){Y&&Y();return}switch(w){case"env":if(Yt(P,"env")){P.emit("env",G,Y,{key:v.name,val:v.value});return}break;case"pty-req":if(Yt(P,"pty")){P.emit("pty",G,Y,v);return}break;case"window-change":Yt(P,"window-change")?P.emit("window-change",G,Y,v):Y&&Y();break;case"x11-req":if(Yt(P,"x11")){P.emit("x11",G,Y,v);return}break;case"signal":if(Yt(P,"signal")){P.emit("signal",G,Y,{name:v});return}break;case"auth-agent-req@openssh.com":if(Yt(P,"auth-agent")){P.emit("auth-agent",G,Y);return}break;case"shell":if(Yt(P,"shell")){G=()=>{if(ne||P._ending||P._channel)return;ne=!0,k&&C.channelSuccess(P._chanInfo.outgoing.id);let te=new Jr(this,P._chanInfo,{server:!0});return te.subtype=P.subtype=w,P._channel=te,te},P.emit("shell",G,Y);return}break;case"exec":if(Yt(P,"exec")){G=()=>{if(ne||P._ending||P._channel)return;ne=!0,k&&C.channelSuccess(P._chanInfo.outgoing.id);let te=new Jr(this,P._chanInfo,{server:!0});return te.subtype=P.subtype=w,P._channel=te,te},P.emit("exec",G,Y,{command:v});return}break;case"subsystem":{let te=v==="sftp";if(G=()=>{if(ne||P._ending||P._channel)return;ne=!0,k&&C.channelSuccess(P._chanInfo.outgoing.id);let le;return te?le=new WA(this,P._chanInfo,{server:!0,debug:i}):(le=new Jr(this,P._chanInfo,{server:!0}),le.subtype=P.subtype=`${w}:${v}`),P._channel=le,le},v==="sftp"){if(Yt(P,"sftp")){P.emit("sftp",G,Y);return}te=!1}if(Yt(P,"subsystem")){P.emit("subsystem",G,Y,{name:v});return}break}}i&&i(`Automatic rejection of incoming channel request: ${w}`),Y&&Y()},CHANNEL_EOF:(B,b)=>{let w=this._chanMgr.get(b);typeof w!="object"||w===null||w.constructor===Nn&&(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:(B,b)=>{let w=this._chanMgr.get(b);typeof w!="object"||w===null||w.constructor===Nn&&(w._ending=!0,w.emit("close"),w=w._channel,!w)||YA(this,b,w)},SERVICE_REQUEST:(B,b)=>{if(c===0||l||this.authenticated||b!=="ssh-userauth"){C.disconnect(Xr.SERVICE_NOT_AVAILABLE),t.end();return}l=!0,C.serviceAccept(b)},USERAUTH_REQUEST:(B,b,w,k,v)=>{if(c===0||this.authenticated||u&&(u.username!==b||u.service!==w)||k!=="password"&&k!=="publickey"&&k!=="hostbased"&&k!=="keyboard-interactive"&&k!=="none"||f.length===jA){C.disconnect(Xr.PROTOCOL_ERROR),t.end();return}else if(w!=="ssh-connection"){C.disconnect(Xr.SERVICE_NOT_AVAILABLE),t.end();return}let P;switch(k){case"keyboard-interactive":P=new oo(C,b,w,k,v,U);break;case"publickey":P=new yc(C,b,w,k,v,U);break;case"hostbased":P=new Ec(C,b,w,k,v,U);break;case"password":if(u&&u instanceof ao&&u._changeCb){let ne=u._changeCb;u._changeCb=void 0,ne(v.newPassword);return}P=new ao(C,b,w,k,v,U);break;case"none":P=new sr(C,b,w,k,U);break}if(u)if(u._initialResponse)u._multistep&&!u._finalResponse&&(u._cleanup&&u._cleanup(),u.emit("abort"));else return f.push(P);u=P,Yt(this,"authentication")?this.emit("authentication",u):u.reject()},USERAUTH_INFO_RESPONSE:(B,b)=>{u&&u instanceof oo&&u._onInfoResponse(b)},GLOBAL_REQUEST:(B,b,w,k)=>{let v={type:null,buf:null};function P(ne,G){v.type=ne,v.buf=G,Q()}if(w&&A.push(v),(b==="tcpip-forward"||b==="cancel-tcpip-forward"||b==="no-more-sessions@openssh.com"||b==="streamlocal-forward@openssh.com"||b==="cancel-streamlocal-forward@openssh.com")&&Yt(this,"request")&&this.authenticated){let ne,G;if(w){let Y=!1;ne=te=>{if(Y)return;Y=!0;let le;b==="tcpip-forward"&&k.bindPort===0&&typeof te=="number"&&(le=Buffer.allocUnsafe(4),qA(le,te,0)),P("SUCCESS",le)},G=()=>{Y||(Y=!0,P("FAILURE"))}}if(b==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,ne&&ne();return}this.emit("request",ne,G,b,k)}else w&&P("FAILURE")}}});t.pause(),FA.then(()=>{C.start(),t.on("data",B=>{try{C.parse(B,0,B.length)}catch(b){this.emit("error",b);try{so(t)&&t.end()}catch{}}}),t.resume()}).catch(B=>{this.emit("error",B);try{so(t)&&t.end()}catch{}}),t.on("error",B=>{B.level="socket",this.emit("error",B)}).once("end",()=>{i&&i("Socket ended"),C.cleanup(),this.emit("end")}).once("close",()=>{i&&i("Socket closed"),C.cleanup(),this.emit("close");let B=new Error("No response from server");this._chanMgr.cleanup(B)});let U=(B,b,w,k)=>{u===B&&!this.authenticated&&(b?(u=void 0,this.authenticated=!0,C.authSuccess(),f=[],this.emit("ready")):(C.authFailure(w,k),f.length&&(u=f.pop(),Yt(this,"authentication")?this.emit("authentication",u):u.reject())))};function Q(){for(;A.length>0&&A[0].type;){let B=A.shift();B.type==="SUCCESS"&&C.requestSuccess(B.buf),B.type==="FAILURE"&&C.requestFailure()}}}end(){return this._sock&&so(this._sock)&&(this._protocol.disconnect(Xr.BY_APPLICATION),this._sock.end()),this}x11(t,e,r){return Ac(this,"x11",{originAddr:t,originPort:e},r),this}forwardOut(t,e,r,s,i){return Ac(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:r,remotePort:s},i),this}openssh_forwardOutStreamLocal(t,e){return Ac(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 Ac(n,t,e,r){let s=rr,i=ir;typeof e=="function"&&(r=e,e={});let o=(c,l)=>{r(c,l)};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,s,i,e);break;case"x11":n._protocol.x11(a,s,i,e);break;case"forwarded-streamlocal@openssh.com":n._protocol.openssh_forwardedStreamLocal(a,s,i,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function XA(n,t){return n-t}_c.exports=un;_c.exports.IncomingClient=co});var Ih=lt((Nx,wh)=>{"use strict";var{createCipheriv:JA,generateKeyPair:ZA,generateKeyPairSync:ey,getCurves:ty,randomBytes:bh}=require("crypto"),{Ber:xt}=yi(),ny=Oo().pbkdf,{CIPHER_INFO:ry}=Xn(),iy=16,sy=16,oy=ty(),ay=new Map(Object.entries(ry));function Sh(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 s=t.bits;if(!Number.isInteger(s))throw new TypeError("RSA bits must be an integer");if(s<=0||s>16384)throw new RangeError("RSA bits must be non-zero and <= 16384");return["rsa",{modulusLength:s,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 s;switch(t.bits){case 256:s="prime256v1";break;case 384:s="secp384r1";break;case 521:s="secp521r1";break;default:throw new Error("ECDSA bits must be 256, 384, or 521")}if(!oy.includes(s))throw new Error("Unsupported ECDSA bits value");return["ec",{namedCurve:s,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ed25519":return["ed25519",{publicKeyEncoding:e,privateKeyEncoding:r}];default:throw new Error(`Unsupported key type: ${n}`)}}function cy(n,t,e){switch(n){case"rsa":{let r=new xt.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()!==xt.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 xt.Reader(r.readString(xt.OctetString,!0)),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");let s=r.readString(xt.Integer,!0),i=r.readString(xt.Integer,!0),o=r.readString(xt.Integer,!0),a=r.readString(xt.Integer,!0),c=r.readString(xt.Integer,!0);r.readString(xt.Integer,!0),r.readString(xt.Integer,!0);let l=r.readString(xt.Integer,!0),f=Buffer.from("ssh-rsa"),u=Buffer.allocUnsafe(4+f.length+4+s.length+4+i.length+4+o.length+4+l.length+4+a.length+4+c.length),h=0;u.writeUInt32BE(f.length,h+=0),u.set(f,h+=4),u.writeUInt32BE(s.length,h+=f.length),u.set(s,h+=4),u.writeUInt32BE(i.length,h+=s.length),u.set(i,h+=4),u.writeUInt32BE(o.length,h+=i.length),u.set(o,h+=4),u.writeUInt32BE(l.length,h+=o.length),u.set(l,h+=4),u.writeUInt32BE(a.length,h+=l.length),u.set(a,h+=4),u.writeUInt32BE(c.length,h+=a.length),u.set(c,h+=4);let p=Buffer.allocUnsafe(4+f.length+4+i.length+4+s.length);return h=0,p.writeUInt32BE(f.length,h+=0),p.set(f,h+=4),p.writeUInt32BE(i.length,h+=f.length),p.set(i,h+=4),p.writeUInt32BE(s.length,h+=i.length),p.set(s,h+=4),{sshName:f.toString(),priv:u,pub:p}}case"ec":{let r=new xt.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 s=r.readString(xt.BitString,!0);{let h=0;for(;h<s.length&&s[h]===0;++h);h>0&&(s=s.slice(h))}if(r=new xt.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 i=r.readOID(),o;switch(i){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 xt.Reader(r.readString(xt.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(xt.OctetString,!0)]),c=Buffer.from(`ecdsa-sha2-${o}`);o=Buffer.from(o);let l=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length+4+a.length),f=0;l.writeUInt32BE(c.length,f+=0),l.set(c,f+=4),l.writeUInt32BE(o.length,f+=c.length),l.set(o,f+=4),l.writeUInt32BE(s.length,f+=o.length),l.set(s,f+=4),l.writeUInt32BE(a.length,f+=s.length),l.set(a,f+=4);let u=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length);return f=0,u.writeUInt32BE(c.length,f+=0),u.set(c,f+=4),u.writeUInt32BE(o.length,f+=c.length),u.set(o,f+=4),u.writeUInt32BE(s.length,f+=o.length),u.set(s,f+=4),{sshName:c.toString(),priv:l,pub:u}}case"ed25519":{let r=new xt.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let s=r.readString(xt.BitString,!0);{let f=0;for(;f<s.length&&s[f]===0;++f);f>0&&(s=s.slice(f))}if(r=new xt.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 xt.Reader(r.readString(xt.OctetString,!0));let i=r.readString(xt.OctetString,!0),o=Buffer.from("ssh-ed25519"),a=Buffer.allocUnsafe(4+o.length+4+s.length+4+(i.length+s.length)),c=0;a.writeUInt32BE(o.length,c+=0),a.set(o,c+=4),a.writeUInt32BE(s.length,c+=o.length),a.set(s,c+=4),a.writeUInt32BE(i.length+s.length,c+=s.length),a.set(i,c+=4),a.set(s,c+=i.length);let l=Buffer.allocUnsafe(4+o.length+4+s.length);return c=0,l.writeUInt32BE(o.length,c+=0),l.set(o,c+=4),l.writeUInt32BE(s.length,c+=o.length),l.set(s,c+=4),{sshName:o.toString(),priv:a,pub:l}}}}function xh(n,t,e,r){let s="new",i,o="";if(typeof r=="object"&&r!==null&&(typeof r.comment=="string"&&r.comment&&(o=r.comment),typeof r.format=="string"&&r.format&&(s=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=ay.get(r.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(s==="new"){let l=sy;if(r.rounds!==void 0){if(!Number.isInteger(r.rounds))throw new TypeError("rounds must be an integer");r.rounds>0&&(l=r.rounds)}let f=Buffer.allocUnsafe(c.keyLen+c.ivLen),u=bh(iy);if(ny(a,a.length,u,u.length,f,f.length,l)!==0)return new Error("Failed to generate information to encrypt key");let p=Buffer.allocUnsafe(4+u.length+4);{let A=0;p.writeUInt32BE(u.length,A+=0),p.set(u,A+=4),p.writeUInt32BE(l,A+=u.length)}i={cipher:c,cipherName:r.cipher,kdfName:"bcrypt",kdfOptions:p,key:f.slice(0,c.keyLen),iv:f.slice(c.keyLen)}}}switch(s){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
15
+ `,c,l=Buffer.from(i?i.cipherName:"none"),f=Buffer.from(i?i.kdfName:"none"),u=i?i.kdfOptions:Buffer.alloc(0),h=i?i.cipher.blockLen:8,p=cy(n,t,e),A=bh(4),E=Buffer.from(o),S=8+p.priv.length+4+E.length,x=[];for(let Q=1;(S+x.length)%h;++Q)x.push(Q&255);x=Buffer.from(x);let R=Buffer.allocUnsafe(S+x.length),H;{let Q=0;R.set(A,Q+=0),R.set(A,Q+=4),R.set(p.priv,Q+=4),R.writeUInt32BE(E.length,Q+=p.priv.length),R.set(E,Q+=4),R.set(x,Q+=E.length)}if(i){let Q={authTagLength:i.cipher.authLen},B=JA(i.cipher.sslName,i.key,i.iv,Q);B.setAutoPadding(!1),R=Buffer.concat([B.update(R),B.final()]),i.cipher.authLen>0?H=B.getAuthTag():H=Buffer.alloc(0),i.key.fill(0),i.iv.fill(0)}else H=Buffer.alloc(0);let C=Buffer.from("openssh-key-v1\0"),U=Buffer.allocUnsafe(C.length+4+l.length+4+f.length+4+u.length+4+4+p.pub.length+4+R.length+H.length);{let Q=0;U.set(C,Q+=0),U.writeUInt32BE(l.length,Q+=C.length),U.set(l,Q+=4),U.writeUInt32BE(f.length,Q+=l.length),U.set(f,Q+=4),U.writeUInt32BE(u.length,Q+=f.length),U.set(u,Q+=4),U.writeUInt32BE(1,Q+=u.length),U.writeUInt32BE(p.pub.length,Q+=4),U.set(p.pub,Q+=4),U.writeUInt32BE(R.length,Q+=p.pub.length),U.set(R,Q+=4),U.set(H,Q+=R.length)}{let Q=U.base64Slice(0,U.length),B=Q.replace(/.{64}/g,`$&
16
+ `);Q.length&63&&(B+=`
17
+ `),a+=B}{let Q=p.pub.base64Slice(0,p.pub.length);c=`${p.sshName} ${Q}${o?` ${o}`:""}`}return a+=`-----END OPENSSH PRIVATE KEY-----
18
+ `,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function ly(){}wh.exports={generateKeyPair:(n,t,e)=>{typeof t=="function"&&(e=t,t=void 0),typeof e!="function"&&(e=ly);let r=Sh(n,t);ZA(...r,(s,i,o)=>{if(s)return e(s);let a;try{a=xh(r[0],i,o,t)}catch(c){return e(c)}e(null,a)})},generateKeyPairSync:(n,t)=>{let e=Sh(n,t),{publicKey:r,privateKey:s}=ey(...e);return xh(e[0],r,s,t)}}});var bc=lt((Px,Ch)=>{"use strict";var{AgentProtocol:fy,BaseAgent:uy,createAgent:dy,CygwinAgent:hy,OpenSSHAgent:py,PageantAgent:gy}=ka(),{SSHTTPAgent:my,SSHTTPSAgent:Ay}=yh(),{parseKey:yy}=er(),{flagsToString:Ey,OPEN_MODE:_y,STATUS_CODE:by,stringToFlags:Sy}=Ui();Ch.exports={AgentProtocol:fy,BaseAgent:uy,createAgent:dy,Client:pc(),CygwinAgent:hy,HTTPAgent:my,HTTPSAgent:Ay,OpenSSHAgent:py,PageantAgent:gy,Server:_h(),utils:{parseKey:yy,...Ih(),sftp:{flagsToString:Ey,OPEN_MODE:_y,STATUS_CODE:by,stringToFlags:Sy}}}});function Fc(n){return n==="1"||n==="true"}function Hc(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function yp(){return Fc(process.env.DEV_MODE)||Fc(process.env.RENDER_PERF)}function hn(n){let t=yp();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=Hc(),r=i=>{let o=Hc()-e;console.log(`[perf][${n}] ${i}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(i="done")=>{r(i)}}}var Ky=hn("HoneyPot");var Qc={name:"adduser",description:"Add a new user",category:"users",params:["<username>"],run:({authUser:n,shell:t,args:e})=>{if(n!=="root")return{stderr:`adduser: permission denied
19
19
  `,exitCode:1};let r=e[0];if(!r)return{stderr:`Usage: adduser <username>
20
20
  `,exitCode:1};if(t.users.listUsers().includes(r))return{stderr:`adduser: user '${r}' already exists
21
21
  `,exitCode:1};let s="",i="new";return{sudoChallenge:{username:r,targetUser:r,commandLine:null,loginShell:!1,prompt:"New password: ",mode:"passwd",onPassword:async(a,c)=>i==="new"?a.length<1?{result:{stderr:`adduser: password cannot be empty
22
22
  `,exitCode:1}}:(s=a,i="retype",{result:null,nextPrompt:"Retype new password: "}):a!==s?{result:{stderr:`adduser: passwords do not match \u2014 user not created
23
23
  `,exitCode:1}}:(await c.users.addUser(r,s),{result:{stdout:`${[`Adding user '${r}' ...`,`Adding new group '${r}' (1001) ...`,`Adding new user '${r}' (1001) with group '${r}' ...`,`Creating home directory '/home/${r}' ...`,`passwd: password set for '${r}'`,"adduser: done."].join(`
24
24
  `)}
25
- `,exitCode:0}})},exitCode:0}}};function Uc(n){return Array.isArray(n)?n:[n]}function Xi(n,t){if(n===t)return{matched:!0,inlineValue:null};let e=`${t}=`;return n.startsWith(e)?{matched:!0,inlineValue:n.slice(e.length)}:t.length===2&&t.startsWith("-")&&!t.startsWith("--")&&n.startsWith(t)&&n.length>t.length?{matched:!0,inlineValue:n.slice(t.length)}:{matched:!1,inlineValue:null}}function dp(n,t={}){let e=new Set(t.flags??[]),r=new Set(t.flagsWithValue??[]),s=[],i=!1;for(let o=0;o<n.length;o+=1){let a=n[o];if(i){s.push(a);continue}if(a==="--"){i=!0;continue}let c=!1;for(let f of e){let{matched:l}=Xi(a,f);if(l){c=!0;break}}if(!c){for(let f of r){let l=Xi(a,f);if(l.matched){c=!0,l.inlineValue===null&&o+1<n.length&&(o+=1);break}}c||s.push(a)}}return s}function se(n,t){let e=Uc(t);for(let r of n)for(let s of e)if(Xi(r,s).matched)return!0;return!1}function zt(n,t){let e=Uc(t);for(let r=0;r<n.length;r+=1){let s=n[r];for(let i of e){let o=Xi(s,i);if(!o.matched)continue;if(o.inlineValue!==null)return o.inlineValue;let a=n[r+1];return a!==void 0&&a!=="--"?a:!0}}}function Tn(n,t,e={}){return dp(n,e)[t]}function Yt(n,t={}){let e=new Set,r=new Map,s=[],i=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){s.push(f);continue}if(f==="--"){a=!0;continue}if(i.has(f)){e.add(f);continue}if(o.has(f)){let u=n[c+1];u&&!u.startsWith("-")?(r.set(f,u),c+=1):r.set(f,"");continue}let l=Array.from(o).find(u=>f.startsWith(`${u}=`));if(l){r.set(l,f.slice(l.length+1));continue}s.push(f)}return{flags:e,flagsWithValues:r,positionals:s}}var $c={name:"alias",description:"Define or display aliases",category:"shell",params:["[name[=value] ...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(n.length===0)return{stdout:Object.entries(t.vars).filter(([s])=>s.startsWith("__alias_")).map(([s,i])=>`alias ${s.slice(8)}='${i}'`).join(`
25
+ `,exitCode:0}})},exitCode:0}}};function Wc(n){return Array.isArray(n)?n:[n]}function es(n,t){if(n===t)return{matched:!0,inlineValue:null};let e=`${t}=`;return n.startsWith(e)?{matched:!0,inlineValue:n.slice(e.length)}:t.length===2&&t.startsWith("-")&&!t.startsWith("--")&&n.startsWith(t)&&n.length>t.length?{matched:!0,inlineValue:n.slice(t.length)}:{matched:!1,inlineValue:null}}function Ep(n,t={}){let e=new Set(t.flags??[]),r=new Set(t.flagsWithValue??[]),s=[],i=!1;for(let o=0;o<n.length;o+=1){let a=n[o];if(i){s.push(a);continue}if(a==="--"){i=!0;continue}let c=!1;for(let l of e){let{matched:f}=es(a,l);if(f){c=!0;break}}if(!c){for(let l of r){let f=es(a,l);if(f.matched){c=!0,f.inlineValue===null&&o+1<n.length&&(o+=1);break}}c||s.push(a)}}return s}function se(n,t){let e=Wc(t);for(let r of n)for(let s of e)if(es(r,s).matched)return!0;return!1}function jt(n,t){let e=Wc(t);for(let r=0;r<n.length;r+=1){let s=n[r];for(let i of e){let o=es(s,i);if(!o.matched)continue;if(o.inlineValue!==null)return o.inlineValue;let a=n[r+1];return a!==void 0&&a!=="--"?a:!0}}}function $n(n,t,e={}){return Ep(n,e)[t]}function Xt(n,t={}){let e=new Set,r=new Map,s=[],i=new Set(t.flags??[]),o=new Set(t.flagsWithValue??[]),a=!1;for(let c=0;c<n.length;c+=1){let l=n[c];if(a){s.push(l);continue}if(l==="--"){a=!0;continue}if(i.has(l)){e.add(l);continue}if(o.has(l)){let u=n[c+1];u&&!u.startsWith("-")?(r.set(l,u),c+=1):r.set(l,"");continue}let f=Array.from(o).find(u=>l.startsWith(`${u}=`));if(f){r.set(f,l.slice(f.length+1));continue}s.push(l)}return{flags:e,flagsWithValues:r,positionals:s}}var qc={name:"alias",description:"Define or display aliases",category:"shell",params:["[name[=value] ...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(n.length===0)return{stdout:Object.entries(t.vars).filter(([s])=>s.startsWith("__alias_")).map(([s,i])=>`alias ${s.slice(8)}='${i}'`).join(`
26
26
  `)||"",exitCode:0};let e=[];for(let r of n){let s=r.indexOf("=");if(s===-1){let i=t.vars[`__alias_${r}`];if(i)e.push(`alias ${r}='${i}'`);else return{stderr:`alias: ${r}: not found`,exitCode:1}}else{let i=r.slice(0,s),o=r.slice(s+1).replace(/^['"]|['"]$/g,"");t.vars[`__alias_${i}`]=o}}return{stdout:e.join(`
27
- `)||void 0,exitCode:0}}},Mc={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(se(n,["-a"])){for(let e of Object.keys(t.vars))e.startsWith("__alias_")&&delete t.vars[e];return{exitCode:0}}for(let e of n)delete t.vars[`__alias_${e}`];return{exitCode:0}}};var bn=Kt(require("node:path"),1),hp=["/.virtual-env-js/.auth","/etc/htpasswd"];function le(n,t){return!t||t.trim()===""?n:t.startsWith("/")?bn.posix.normalize(t):bn.posix.normalize(bn.posix.join(n,t))}function pp(n){let t=n.startsWith("/")?bn.posix.normalize(n):bn.posix.normalize(`/${n}`);return hp.some(e=>t===e||t.startsWith(`${e}/`))}function Me(n,t,e){if(n!=="root"&&pp(t))throw new Error(`${e}: permission denied: ${t}`)}function Oc(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function gp(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 s=1;s<=t.length;s+=1){let i=n[r-1]===t[s-1]?0:1;e[r][s]=Math.min(e[r-1][s]+1,e[r][s-1]+1,e[r-1][s-1]+i)}return e[n.length][t.length]}function Fc(n,t,e){let r=le(t,e);if(n.exists(r))return r;let s=bn.posix.dirname(r),i=bn.posix.basename(r),o=n.list(s),a=o.filter(f=>f.toLowerCase()===i.toLowerCase());if(a.length===1)return bn.posix.join(s,a[0]);let c=o.filter(f=>gp(f.toLowerCase(),i.toLowerCase())<=1);return c.length===1?bn.posix.join(s,c[0]):r}function Hc(n,t,e){return t.map(r=>{let s=le(n,r);return e(s).type==="directory"?`${r}/`:r}).join(" ")}function wr(n){return n.packageManager}var Qc={name:"apt",aliases:["apt-get"],description:"Package manager",category:"package",params:["<install|remove|update|upgrade|search|show|list> [pkg...]"],run:({args:n,shell:t,authUser:e})=>{let r=wr(t);if(!r)return{stderr:"apt: package manager not initialised",exitCode:1};let s=n[0]?.toLowerCase(),i=n.slice(1),o=se(i,["-q","--quiet","-qq"]),a=se(i,["--purge"]),c=i.filter(l=>!l.startsWith("-"));if(["install","remove","purge","upgrade","update"].includes(s??"")&&e!=="root")return{stderr:`E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
28
- E: Unable to acquire the dpkg frontend lock, are you root?`,exitCode:100};switch(s){case"install":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:l,exitCode:u}=r.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}=r.remove(c,{purge:s==="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(`
27
+ `)||void 0,exitCode:0}}},Kc={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(se(n,["-a"])){for(let e of Object.keys(t.vars))e.startsWith("__alias_")&&delete t.vars[e];return{exitCode:0}}for(let e of n)delete t.vars[`__alias_${e}`];return{exitCode:0}}};var yn=zt(require("node:path"),1),_p=["/.virtual-env-js/.auth","/etc/htpasswd"];function de(n,t){return!t||t.trim()===""?n:t.startsWith("~")?yn.posix.normalize(`/home/${t.slice(1)}`):t.startsWith("/")?yn.posix.normalize(t):yn.posix.normalize(yn.posix.join(n,t))}function bp(n){let t=n.startsWith("/")?yn.posix.normalize(n):yn.posix.normalize(`/${n}`);return _p.some(e=>t===e||t.startsWith(`${e}/`))}function Oe(n,t,e){if(n!=="root"&&bp(t))throw new Error(`${e}: permission denied: ${t}`)}function Vc(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function Sp(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 s=1;s<=t.length;s+=1){let i=n[r-1]===t[s-1]?0:1;e[r][s]=Math.min(e[r-1][s]+1,e[r][s-1]+1,e[r-1][s-1]+i)}return e[n.length][t.length]}function zc(n,t,e){let r=de(t,e);if(n.exists(r))return r;let s=yn.posix.dirname(r),i=yn.posix.basename(r),o=n.list(s),a=o.filter(l=>l.toLowerCase()===i.toLowerCase());if(a.length===1)return yn.posix.join(s,a[0]);let c=o.filter(l=>Sp(l.toLowerCase(),i.toLowerCase())<=1);return c.length===1?yn.posix.join(s,c[0]):r}function Cr(n){return n.packageManager}var Gc={name:"apt",aliases:["apt-get"],description:"Package manager",category:"package",params:["<install|remove|update|upgrade|search|show|list> [pkg...]"],run:({args:n,shell:t,authUser:e})=>{let r=Cr(t);if(!r)return{stderr:"apt: package manager not initialised",exitCode:1};let s=n[0]?.toLowerCase(),i=n.slice(1),o=se(i,["-q","--quiet","-qq"]),a=se(i,["--purge"]),c=i.filter(f=>!f.startsWith("-"));if(["install","remove","purge","upgrade","update"].includes(s??"")&&e!=="root")return{stderr:`E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
28
+ E: Unable to acquire the dpkg frontend lock, are you root?`,exitCode:100};switch(s){case"install":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:f,exitCode:u}=r.install(c,{quiet:o});return{stdout:f||void 0,exitCode:u}}case"remove":case"purge":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:f,exitCode:u}=r.remove(c,{purge:s==="purge"||a,quiet:o});return{stdout:f||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(`
29
29
  `),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(`
30
- `),exitCode:0};case"search":{let l=c[0];if(!l)return{stderr:"apt: search requires a term",exitCode:1};let u=r.search(l);return u.length===0?{stdout:`Sorting... Done
30
+ `),exitCode:0};case"search":{let f=c[0];if(!f)return{stderr:"apt: search requires a term",exitCode:1};let u=r.search(f);return u.length===0?{stdout:`Sorting... Done
31
31
  Full Text Search... Done
32
32
  (no results)`,exitCode:0}:{stdout:`Sorting... Done
33
33
  Full Text Search... Done
34
34
  ${u.map(p=>`${p.name}/${p.section??"misc"} ${p.version} amd64
35
35
  ${p.shortDesc??p.description}`).join(`
36
- `)}`,exitCode:0}}case"show":{let l=c[0];if(!l)return{stderr:"apt: show requires a package name",exitCode:1};let u=r.show(l);return u?{stdout:u,exitCode:0}:{stderr:`N: Unable to locate package ${l}`,exitCode:100}}case"list":{if(se(i,["--installed"])){let p=r.listInstalled();return p.length===0?{stdout:`Listing... Done
36
+ `)}`,exitCode:0}}case"show":{let f=c[0];if(!f)return{stderr:"apt: show requires a package name",exitCode:1};let u=r.show(f);return u?{stdout:u,exitCode:0}:{stderr:`N: Unable to locate package ${f}`,exitCode:100}}case"list":{if(se(i,["--installed"])){let p=r.listInstalled();return p.length===0?{stdout:`Listing... Done
37
37
  (no packages installed)`,exitCode:0}:{stdout:`Listing... Done
38
38
  ${p.map(E=>`${E.name}/${E.section} ${E.version} ${E.architecture} [installed]`).join(`
39
39
  `)}`,exitCode:0}}return{stdout:`Listing... Done
40
40
  ${r.listAvailable().map(p=>`${p.name}/${p.section??"misc"} ${p.version} amd64`).join(`
41
41
  `)}`,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(`
42
- `),exitCode:0}}}},Wc={name:"apt-cache",description:"Query the package cache",category:"package",params:["<search|show|policy> [pkg]"],run:({args:n,shell:t})=>{let e=wr(t);if(!e)return{stderr:"apt-cache: package manager not initialised",exitCode:1};let r=n[0]?.toLowerCase(),s=n[1];switch(r){case"search":return s?{stdout:e.search(s).map(o=>`${o.name} - ${o.shortDesc??o.description}`).join(`
42
+ `),exitCode:0}}}},Yc={name:"apt-cache",description:"Query the package cache",category:"package",params:["<search|show|policy> [pkg]"],run:({args:n,shell:t})=>{let e=Cr(t);if(!e)return{stderr:"apt-cache: package manager not initialised",exitCode:1};let r=n[0]?.toLowerCase(),s=n[1];switch(r){case"search":return s?{stdout:e.search(s).map(o=>`${o.name} - ${o.shortDesc??o.description}`).join(`
43
43
  `)||"(no results)",exitCode:0}:{stderr:"Need a search term",exitCode:1};case"show":{if(!s)return{stderr:"Need a package name",exitCode:1};let i=e.show(s);return i?{stdout:i,exitCode:0}:{stderr:`N: Unable to locate package ${s}`,exitCode:100}}case"policy":{if(!s)return{stderr:"Need a package name",exitCode:1};let i=e.findInRegistry(s);if(!i)return{stderr:`N: Unable to locate package ${s}`,exitCode:100};let o=e.isInstalled(s);return{stdout:[`${s}:`,` Installed: ${o?i.version:"(none)"}`,` Candidate: ${i.version}`," Version table:",` ${i.version} 500`," 500 fortune://packages.fortune.local aurora/main amd64 Packages"].join(`
44
- `),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var qc={name:"awk",description:"Pattern scanning and processing language",category:"text",params:["[-F <sep>] '<program>' [file]"],run:({authUser:n,args:t,stdin:e,cwd:r,shell:s})=>{let i=zt(t,["-F"])??" ",o=t.filter(C=>!C.startsWith("-")&&C!==i),a=o[0],c=o[1];if(!a)return{stderr:"awk: no program",exitCode:1};let f=e??"";if(c){let C=le(r,c);try{Me(n,C,"awk"),f=s.vfs.readFile(C)}catch{return{stderr:`awk: ${c}: No such file or directory`,exitCode:1}}}let l=f.split(`
45
- `);l[l.length-1]===""&&l.pop();let u=[],h=a.trim();if(!h.startsWith("{")&&!h.includes("{"))u.push({pattern:h,action:"print $0"});else{let C=/([^{]*)\{([^}]*)\}/g,F=C.exec(h);for(;F!==null;)u.push({pattern:F[1].trim(),action:F[2].trim()}),F=C.exec(h);u.length===0&&u.push({pattern:"",action:h.replace(/[{}]/g,"").trim()})}let p=[],_=u.find(C=>C.pattern==="BEGIN"),E=u.find(C=>C.pattern==="END"),b=u.filter(C=>C.pattern!=="BEGIN"&&C.pattern!=="END");function v(C){return i===" "?C.trim().split(/\s+/).filter(Boolean):C.split(i)}function U(C,F,V){let N=v(F),x=N.length,S=k=>{if(k=k.trim(),k==="NR")return String(V);if(k==="NF")return String(x);if(k==="$0")return F;if(k==="$NF")return N[x-1]??"";if(/^\$\d+$/.test(k))return N[parseInt(k.slice(1),10)-1]??"";let R=k.replace(/\bNR\b/g,String(V)).replace(/\bNF\b/g,String(x));if(/^[\d\s+\-*/()]+$/.test(R))try{return String(Function(`"use strict"; return (${R});`)())}catch{}return k.replace(/"/g,"")},I=C.split(";").map(k=>k.trim()).filter(Boolean);for(let k of I)if(k==="print"||k==="print $0")p.push(F);else if(k.startsWith("print ")){let R=k.slice(6).split(/\s*,\s*/);p.push(R.map(S).join(" "))}}function H(C,F,V){if(!C||C==="1")return!0;let N=C.match(/^NR\s*([=!<>]=?|==)\s*(\d+)$/);if(N){let I=N[1],k=parseInt(N[2],10);switch(I){case"==":return V===k;case"!=":return V!==k;case">":return V>k;case">=":return V>=k;case"<":return V<k;case"<=":return V<=k}}let x=C.match(/^NR%(\d+)==(\d+)$/);if(x)return V%parseInt(x[1],10)===parseInt(x[2],10);if(C.startsWith("/")&&C.endsWith("/"))try{return new RegExp(C.slice(1,-1)).test(F)}catch{return!1}let S=C.match(/^\$(\d+)~\/(.*)\/$/);if(S){let k=v(F)[parseInt(S[1],10)-1]??"";try{return new RegExp(S[2]).test(k)}catch{return!1}}return!1}_&&U(_.action,"",0);for(let C=1;C<=l.length;C++){let F=l[C-1];for(let V of b)H(V.pattern,F,C)&&U(V.action,F,C)}return E&&U(E.action,"",l.length+1),{stdout:p.join(`
44
+ `),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var jc={name:"awk",description:"Pattern scanning and processing language",category:"text",params:["[-F <sep>] '<program>' [file]"],run:({authUser:n,args:t,stdin:e,cwd:r,shell:s})=>{let i=jt(t,["-F"])??" ",o=t.filter(C=>!C.startsWith("-")&&C!==i),a=o[0],c=o[1];if(!a)return{stderr:"awk: no program",exitCode:1};let l=e??"";if(c){let C=de(r,c);try{Oe(n,C,"awk"),l=s.vfs.readFile(C)}catch{return{stderr:`awk: ${c}: No such file or directory`,exitCode:1}}}let f=l.split(`
45
+ `);f[f.length-1]===""&&f.pop();let u=[],h=a.trim();if(!h.startsWith("{")&&!h.includes("{"))u.push({pattern:h,action:"print $0"});else{let C=/([^{]*)\{([^}]*)\}/g,U=C.exec(h);for(;U!==null;)u.push({pattern:U[1].trim(),action:U[2].trim()}),U=C.exec(h);u.length===0&&u.push({pattern:"",action:h.replace(/[{}]/g,"").trim()})}let p=[],A=u.find(C=>C.pattern==="BEGIN"),E=u.find(C=>C.pattern==="END"),S=u.filter(C=>C.pattern!=="BEGIN"&&C.pattern!=="END");function x(C){return i===" "?C.trim().split(/\s+/).filter(Boolean):C.split(i)}function R(C,U,Q){let B=x(U),b=B.length,w=v=>{if(v=v.trim(),v==="NR")return String(Q);if(v==="NF")return String(b);if(v==="$0")return U;if(v==="$NF")return B[b-1]??"";if(/^\$\d+$/.test(v))return B[parseInt(v.slice(1),10)-1]??"";let P=v.replace(/\bNR\b/g,String(Q)).replace(/\bNF\b/g,String(b));if(/^[\d\s+\-*/()]+$/.test(P))try{return String(Function(`"use strict"; return (${P});`)())}catch{}return v.replace(/"/g,"")},k=C.split(";").map(v=>v.trim()).filter(Boolean);for(let v of k)if(v==="print"||v==="print $0")p.push(U);else if(v.startsWith("print ")){let P=v.slice(6).split(/\s*,\s*/);p.push(P.map(w).join(" "))}}function H(C,U,Q){if(!C||C==="1")return!0;let B=C.match(/^NR\s*([=!<>]=?|==)\s*(\d+)$/);if(B){let k=B[1],v=parseInt(B[2],10);switch(k){case"==":return Q===v;case"!=":return Q!==v;case">":return Q>v;case">=":return Q>=v;case"<":return Q<v;case"<=":return Q<=v}}let b=C.match(/^NR%(\d+)==(\d+)$/);if(b)return Q%parseInt(b[1],10)===parseInt(b[2],10);if(C.startsWith("/")&&C.endsWith("/"))try{return new RegExp(C.slice(1,-1)).test(U)}catch{return!1}let w=C.match(/^\$(\d+)~\/(.*)\/$/);if(w){let v=x(U)[parseInt(w[1],10)-1]??"";try{return new RegExp(w[2]).test(v)}catch{return!1}}return!1}A&&R(A.action,"",0);for(let C=1;C<=f.length;C++){let U=f[C-1];for(let Q of S)H(Q.pattern,U,C)&&R(Q.action,U,C)}return E&&R(E.action,"",f.length+1),{stdout:p.join(`
46
46
  `)+(p.length>0?`
47
- `:""),exitCode:0}}};var Kc={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=se(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}}};var Vc={name:"cat",description:"Concatenate and print files",category:"files",params:["[-n] [-b] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=se(r,["-n","--number"]),o=se(r,["-b","--number-nonblank"]),a=r.filter(h=>!h.startsWith("-"));if(a.length===0&&s!==void 0)return{stdout:s,exitCode:0};if(a.length===0)return{stderr:"cat: missing file operand",exitCode:1};let c=[];for(let h of a){let p=Fc(t.vfs,e,h);Me(n,p,"cat"),c.push(t.vfs.readFile(p))}let f=c.join("");if(!i&&!o)return{stdout:f,exitCode:0};let l=1;return{stdout:f.split(`
48
- `).map(h=>o&&h.trim()===""?h:`${String(l++).padStart(6)} ${h}`).join(`
49
- `),exitCode:0}}};var Gc={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r,mode:s})=>{let i=le(e,r[0]??"/virtual-env-js");return Me(n,i,"cd"),t.vfs.stat(i).type!=="directory"?{stderr:`cd: not a directory: ${i}`,exitCode:1}:{nextCwd:i,exitCode:0}}};function mp(n,t){let e=/^([ugoa]*)([+\-=])([rwx]*)$/,r=t.split(","),s=n;for(let i of r){let o=i.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 p of f.split("")){let _=u[h]?.[p];if(_!==void 0){if(c==="+")s|=_;else if(c==="-")s&=~_;else if(c==="="){let E=Object.values(u[h]??{}).reduce((b,v)=>b|v,0);s=s&~E|_}}}}return s}var zc={name:"chmod",description:"Change file permissions",category:"files",params:["<mode> <file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let[s,i]=r;if(!s||!i)return{stderr:"chmod: missing operand",exitCode:1};let o=le(e,i);try{if(Me(n,o,"chmod"),!t.vfs.exists(o))return{stderr:`chmod: ${i}: No such file or directory`,exitCode:1};let a,c=parseInt(s,8);if(!Number.isNaN(c)&&/^[0-7]+$/.test(s))a=c;else{let f=t.vfs.stat(o).mode,l=mp(f,s);if(l===null)return{stderr:`chmod: invalid mode: ${s}`,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 Yc={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var jc={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-r","-R","--recursive"]),i=r.filter(l=>!l.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let c=le(e,o),f=le(e,a);try{if(Me(n,c,"cp"),Me(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(!s)return{stderr:`cp: ${o}: is a directory (use -r)`,exitCode:1};let u=(p,_)=>{t.vfs.mkdir(_,493);for(let E of t.vfs.list(p)){let b=`${p}/${E}`,v=`${_}/${E}`;if(t.vfs.stat(b).type==="directory")u(b,v);else{let H=t.vfs.readFileRaw(b);t.writeFileAsUser(n,v,H)}}},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(n,u,h)}return{exitCode:0}}catch(l){return{stderr:`cp: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};var Xc={name:"curl",description:"Transfer data from or to a server (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:s,positionals:i}=Yt(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(`
50
- `),exitCode:0};let o=i[0];if(!o)return{stderr:"curl: no URL specified",exitCode:1};let a=s.get("-o")??s.get("--output")??null,c=(s.get("-X")??s.get("--request")??"GET").toUpperCase(),f=s.get("-d")??s.get("--data")??null,l=s.get("-H")??s.get("--header")??null,u=se(e,["-s","--silent"]),h=se(e,["-I","--head"]),p=se(e,["-L","--location"]),_=se(e,["-v","--verbose"]),E={"User-Agent":"curl/7.88.1"};if(l){let F=l.indexOf(":");F!==-1&&(E[l.slice(0,F).trim()]=l.slice(F+1).trim())}let b=f&&c==="GET"?"POST":c,v={method:b,headers:E,redirect:p?"follow":"manual"};f&&(E["Content-Type"]??="application/x-www-form-urlencoded",v.body=f);let U=[];_&&(U.push(`* Trying ${o}...`,"* Connected"),U.push(`> ${b} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let H;try{let F=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;H=await fetch(F,v)}catch(F){return{stderr:`curl: (6) Could not resolve host: ${F instanceof Error?F.message:String(F)}`,exitCode:6}}if(_&&U.push(`< HTTP/1.1 ${H.status} ${H.statusText}`),h){let F=[`HTTP/1.1 ${H.status} ${H.statusText}`];for(let[V,N]of H.headers.entries())F.push(`${V}: ${N}`);return{stdout:`${F.join(`\r
47
+ `:""),exitCode:0}}};var Xc={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=se(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}}};var Jc={name:"cat",description:"Concatenate and print files",category:"files",params:["[-n] [-b] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=se(r,["-n","--number"]),o=se(r,["-b","--number-nonblank"]),a=r.filter(h=>!h.startsWith("-"));if(a.length===0&&s!==void 0)return{stdout:s,exitCode:0};if(a.length===0)return{stderr:"cat: missing file operand",exitCode:1};let c=[];for(let h of a){let p=zc(t.vfs,e,h);Oe(n,p,"cat"),c.push(t.vfs.readFile(p))}let l=c.join("");if(!i&&!o)return{stdout:l,exitCode:0};let f=1;return{stdout:l.split(`
48
+ `).map(h=>o&&h.trim()===""?h:`${String(f++).padStart(6)} ${h}`).join(`
49
+ `),exitCode:0}}};var Zc={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=de(e,r[0]??"~");return Oe(n,s,"cd"),t.vfs.stat(s).type!=="directory"?{stderr:`cd: not a directory: ${s}`,exitCode:1}:{nextCwd:s,exitCode:0}}};function xp(n,t){let e=/^([ugoa]*)([+\-=])([rwx]*)$/,r=t.split(","),s=n;for(let i of r){let o=i.trim().match(e);if(!o)return null;let[,a="a",c,l=""]=o,f=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 f)for(let p of l.split("")){let A=u[h]?.[p];if(A!==void 0){if(c==="+")s|=A;else if(c==="-")s&=~A;else if(c==="="){let E=Object.values(u[h]??{}).reduce((S,x)=>S|x,0);s=s&~E|A}}}}return s}var el={name:"chmod",description:"Change file permissions",category:"files",params:["<mode> <file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let[s,i]=r;if(!s||!i)return{stderr:"chmod: missing operand",exitCode:1};let o=de(e,i);try{if(Oe(n,o,"chmod"),!t.vfs.exists(o))return{stderr:`chmod: ${i}: No such file or directory`,exitCode:1};let a,c=parseInt(s,8);if(!Number.isNaN(c)&&/^[0-7]+$/.test(s))a=c;else{let l=t.vfs.stat(o).mode,f=xp(l,s);if(f===null)return{stderr:`chmod: invalid mode: ${s}`,exitCode:1};a=f}return t.vfs.chmod(o,a),{exitCode:0}}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}};var tl={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var nl={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-r","-R","--recursive"]),i=r.filter(f=>!f.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let c=de(e,o),l=de(e,a);try{if(Oe(n,c,"cp"),Oe(n,l,"cp"),!t.vfs.exists(c))return{stderr:`cp: ${o}: No such file or directory`,exitCode:1};if(t.vfs.stat(c).type==="directory"){if(!s)return{stderr:`cp: ${o}: is a directory (use -r)`,exitCode:1};let u=(p,A)=>{t.vfs.mkdir(A,493);for(let E of t.vfs.list(p)){let S=`${p}/${E}`,x=`${A}/${E}`;if(t.vfs.stat(S).type==="directory")u(S,x);else{let H=t.vfs.readFileRaw(S);t.writeFileAsUser(n,x,H)}}},h=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${o.split("/").pop()}`:l;u(c,h)}else{let u=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${o.split("/").pop()}`:l,h=t.vfs.readFileRaw(c);t.writeFileAsUser(n,u,h)}return{exitCode:0}}catch(f){return{stderr:`cp: ${f instanceof Error?f.message:String(f)}`,exitCode:1}}}};var rl={name:"curl",description:"Transfer data from or to a server (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:s,positionals:i}=Xt(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(`
50
+ `),exitCode:0};let o=i[0];if(!o)return{stderr:"curl: no URL specified",exitCode:1};let a=s.get("-o")??s.get("--output")??null,c=(s.get("-X")??s.get("--request")??"GET").toUpperCase(),l=s.get("-d")??s.get("--data")??null,f=s.get("-H")??s.get("--header")??null,u=se(e,["-s","--silent"]),h=se(e,["-I","--head"]),p=se(e,["-L","--location"]),A=se(e,["-v","--verbose"]),E={"User-Agent":"curl/7.88.1"};if(f){let U=f.indexOf(":");U!==-1&&(E[f.slice(0,U).trim()]=f.slice(U+1).trim())}let S=l&&c==="GET"?"POST":c,x={method:S,headers:E,redirect:p?"follow":"manual"};l&&(E["Content-Type"]??="application/x-www-form-urlencoded",x.body=l);let R=[];A&&(R.push(`* Trying ${o}...`,"* Connected"),R.push(`> ${S} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let H;try{let U=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;H=await fetch(U,x)}catch(U){return{stderr:`curl: (6) Could not resolve host: ${U instanceof Error?U.message:String(U)}`,exitCode:6}}if(A&&R.push(`< HTTP/1.1 ${H.status} ${H.statusText}`),h){let U=[`HTTP/1.1 ${H.status} ${H.statusText}`];for(let[Q,B]of H.headers.entries())U.push(`${Q}: ${B}`);return{stdout:`${U.join(`\r
51
51
  `)}\r
52
- `,exitCode:0}}let C;try{C=await H.text()}catch{return{stderr:"curl: failed to read response body",exitCode:1}}if(a){let F=le(t,a);return Me(n,F,"curl"),r.writeFileAsUser(n,F,C),u||U.push(` % Total % Received
53
- 100 ${C.length} 100 ${C.length}`),{stderr:U.join(`
54
- `)||void 0,exitCode:H.ok?0:22}}return{stdout:C,stderr:U.length>0?U.join(`
55
- `):void 0,exitCode:H.ok?0:22}}};var Jc={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=zt(n,["-d"])??" ",s=(zt(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(`
56
- `).map(a=>{let c=a.split(e),f=[];for(let l of s)for(let u=l.from;u<=Math.min(l.to,c.length-1);u++)f.push(c[u]??"");return f.join(e)}).join(`
57
- `),exitCode:0}}};var Zc={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 ef={name:"declare",aliases:["local","typeset"],description:"Declare variables and give them attributes",category:"shell",params:["[-i] [-r] [-x] [-a] [name[=value]...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=se(n,["-i"]),r=se(n,["-r"]),s=se(n,["-x"]);if(n.filter(a=>!a.startsWith("-")).length===0)return{stdout:Object.entries(t.vars).map(([c,f])=>`declare -- ${c}="${f}"`).join(`
58
- `),exitCode:0};let o=n.filter(a=>!a.startsWith("-"));for(let a of o){let c=a.indexOf("=");if(c===-1)a in t.vars||(t.vars[a]="");else{let f=a.slice(0,c),l=a.slice(c+1);if(e){let u=parseInt(l,10);l=Number.isNaN(u)?"0":String(u)}t.vars[f]=l}}return{exitCode:0}}};var tf={name:"deluser",description:"Delete a user",category:"users",params:["[-f] <username>"],run:async({authUser:n,args:t,shell:e})=>{if(n!=="root")return{stderr:`deluser: permission denied
52
+ `,exitCode:0}}let C;try{C=await H.text()}catch{return{stderr:"curl: failed to read response body",exitCode:1}}if(a){let U=de(t,a);return Oe(n,U,"curl"),r.writeFileAsUser(n,U,C),u||R.push(` % Total % Received
53
+ 100 ${C.length} 100 ${C.length}`),{stderr:R.join(`
54
+ `)||void 0,exitCode:H.ok?0:22}}return{stdout:C,stderr:R.length>0?R.join(`
55
+ `):void 0,exitCode:H.ok?0:22}}};var il={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=jt(n,["-d"])??" ",s=(jt(n,["-f"])??"1").split(",").map(a=>{let[c,l]=a.split("-").map(Number);return l!==void 0?{from:(c??1)-1,to:l-1}:{from:(c??1)-1,to:(c??1)-1}});return{stdout:(t??"").split(`
56
+ `).map(a=>{let c=a.split(e),l=[];for(let f of s)for(let u=f.from;u<=Math.min(f.to,c.length-1);u++)l.push(c[u]??"");return l.join(e)}).join(`
57
+ `),exitCode:0}}};var sl={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 ol={name:"declare",aliases:["local","typeset"],description:"Declare variables and give them attributes",category:"shell",params:["[-i] [-r] [-x] [-a] [name[=value]...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=se(n,["-i"]),r=se(n,["-r"]),s=se(n,["-x"]);if(n.filter(a=>!a.startsWith("-")).length===0)return{stdout:Object.entries(t.vars).map(([c,l])=>`declare -- ${c}="${l}"`).join(`
58
+ `),exitCode:0};let o=n.filter(a=>!a.startsWith("-"));for(let a of o){let c=a.indexOf("=");if(c===-1)a in t.vars||(t.vars[a]="");else{let l=a.slice(0,c),f=a.slice(c+1);if(e){let u=parseInt(f,10);f=Number.isNaN(u)?"0":String(u)}t.vars[l]=f}}return{exitCode:0}}};var al={name:"deluser",description:"Delete a user",category:"users",params:["[-f] <username>"],run:async({authUser:n,args:t,shell:e})=>{if(n!=="root")return{stderr:`deluser: permission denied
59
59
  `,exitCode:1};let r=t.includes("-f")||t.includes("--force")||t.includes("-y"),s=t.find(o=>!o.startsWith("-"));if(!s)return{stderr:`Usage: deluser [-f] <username>
60
60
  `,exitCode:1};if(!e.users.listUsers().includes(s))return{stderr:`deluser: user '${s}' does not exist
61
61
  `,exitCode:1};if(s==="root")return{stderr:`deluser: cannot remove the root account
@@ -65,222 +65,278 @@ deluser: done.
65
65
  `,exitCode:1}}:(await a.users.deleteUser(s),{result:{stdout:`Removing user '${s}' ...
66
66
  deluser: done.
67
67
  `,exitCode:0}});return{sudoChallenge:{username:s,targetUser:s,commandLine:null,loginShell:!1,prompt:`Warning: deleting user '${s}'.
68
- Type the username to confirm: `,mode:"confirm",onPassword:i},exitCode:0}}};var nf={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",s=String(Number(r)-Number(e)),i=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)} ${s.padStart(9)} ${i}% /`;return{stdout:`${o}
69
- ${a}`,exitCode:0}}};var rf={name:"diff",description:"Compare files line by line",category:"text",params:["<file1> <file2>"],run:({shell:n,cwd:t,args:e})=>{let[r,s]=e;if(!r||!s)return{stderr:"diff: missing operand",exitCode:1};let i=le(t,r),o=le(t,s),a,c;try{a=n.vfs.readFile(i).split(`
68
+ Type the username to confirm: `,mode:"confirm",onPassword:i},exitCode:0}}};var cl={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",s=String(Number(r)-Number(e)),i=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)} ${s.padStart(9)} ${i}% /`;return{stdout:`${o}
69
+ ${a}`,exitCode:0}}};var ll={name:"diff",description:"Compare files line by line",category:"text",params:["<file1> <file2>"],run:({shell:n,cwd:t,args:e})=>{let[r,s]=e;if(!r||!s)return{stderr:"diff: missing operand",exitCode:1};let i=de(t,r),o=de(t,s),a,c;try{a=n.vfs.readFile(i).split(`
70
70
  `)}catch{return{stderr:`diff: ${r}: No such file or directory`,exitCode:2}}try{c=n.vfs.readFile(o).split(`
71
- `)}catch{return{stderr:`diff: ${s}: 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],p=c[u];h!==p&&(h!==void 0&&f.push(`< ${h}`),p!==void 0&&f.push(`> ${p}`))}return{stdout:f.join(`
72
- `),exitCode:f.length>0?1:0}}};var sf={name:"dpkg",description:"Debian package manager low-level tool",category:"package",params:["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"],run:({args:n,authUser:t,shell:e})=>{let r=wr(e);if(!r)return{stderr:"dpkg: package manager not initialised",exitCode:1};let s=se(n,["-l","--list"]),i=se(n,["-s","--status"]),o=se(n,["-L","--listfiles"]),a=se(n,["-r","--remove"]),c=se(n,["-P","--purge"]),{positionals:f}=Yt(n,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(s){let l=r.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(`
73
- `),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(p=>{let _=p.name.padEnd(14).slice(0,14),E=p.version.padEnd(15).slice(0,15),b=p.architecture.padEnd(12).slice(0,12),v=(p.description||"").slice(0,40);return`ii ${_} ${E} ${b} ${v}`});return{stdout:[...u,...h].join(`
74
- `),exitCode:0}}if(i){let l=f[0];if(!l)return{stderr:"dpkg: -s needs a package name",exitCode:1};let u=r.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=r.listInstalled().find(h=>h.name===l);return u?u.files.length===0?{stdout:"/.keep",exitCode:0}:{stdout:u.files.join(`
75
- `),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}=r.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(`
76
- `),exitCode:0}}},of={name:"dpkg-query",description:"Show information about installed packages",category:"package",params:["-W [pkg] | -l [pattern]"],run:({args:n,shell:t})=>{let e=wr(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let r=se(n,["-l"]),s=se(n,["-W","--show"]),{positionals:i}=Yt(n,{flags:["-l","-W","--show"]});if(r||s){let o=e.listInstalled(),a=i[0],c=a?o.filter(l=>l.name.includes(a)):o;return s?{stdout:c.map(l=>`${l.name} ${l.version}`).join(`
77
- `),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(`
78
- `)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var af={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=se(e,["-h"]),s=se(e,["-s"]),i=e.find(l=>!l.startsWith("-"))??".",o=le(t,i),a=l=>r?`${(l/1024).toFixed(1)}K`:String(Math.ceil(l/1024));if(!n.vfs.exists(o))return{stderr:`du: ${i}: No such file or directory`,exitCode:1};if(s||n.vfs.stat(o).type==="file")return{stdout:`${a(n.vfs.getUsageBytes(o))} ${i}`,exitCode:0};let c=[],f=(l,u)=>{let h=0;for(let p of n.vfs.list(l)){let _=`${l}/${p}`,E=`${u}/${p}`,b=n.vfs.stat(_);b.type==="directory"?h+=f(_,E):(h+=b.size,s||c.push(`${a(b.size)} ${E}`))}return c.push(`${a(h)} ${u}`),h};return f(o,i),{stdout:c.join(`
79
- `),exitCode:0}}};function Ap(n,t){let e=n.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\b/g,(r,s)=>{let i=t[s];return i!==void 0&&i!==""?i:"0"});if(!/^[\d\s+\-*/%()^!&|<>=,. ]+$/.test(e))return NaN;try{let r=Function(`"use strict"; return (${e.replace(/\*\*/g,"**")});`)();return typeof r=="number"?Math.trunc(r):NaN}catch{return NaN}}function Ep(n,t){let e=[],r=0;for(;r<n.length;){let s=n.indexOf("'",r);if(s===-1){e.push(t(n.slice(r)));break}e.push(t(n.slice(r,s)));let i=n.indexOf("'",s+1);if(i===-1){e.push(n.slice(s));break}e.push(n.slice(s,i+1)),r=i+1}return e.join("")}function ho(n,t,e=0,r){let s=r??t.HOME??"/home/user";return Ep(n,i=>{let o=i;return o=o.replace(/(^|[\s:])~(\/|$)/g,(a,c,f)=>`${c}${s}${f}`),o=o.replace(/\$\?/g,String(e)),o=o.replace(/\$\$/g,"1"),o=o.replace(/\$#/g,"0"),o=o.replace(/\$\(\(([^)]+(?:\([^)]*\)[^)]*)*)\)\)/g,(a,c)=>{let f=Ap(c,t);return Number.isNaN(f)?"0":String(f)}),o=o.replace(/\$\{#([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>String((t[c]??"").length)),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\}/g,(a,c,f)=>t[c]!==void 0&&t[c]!==""?t[c]:f),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):=([^}]*)\}/g,(a,c,f)=>((t[c]===void 0||t[c]==="")&&(t[c]=f),t[c])),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):\+([^}]*)\}/g,(a,c,f)=>t[c]!==void 0&&t[c]!==""?f:""),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>t[c]??""),o=o.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g,(a,c)=>t[c]??""),o})}async function Ji(n,t,e,r){if(n.includes("$(")){let s="",i=!1,o=0;for(;o<n.length;){let a=n[o];if(a==="'"&&!i){i=!0,s+=a,o++;continue}if(a==="'"&&i){i=!1,s+=a,o++;continue}if(!i&&a==="$"&&n[o+1]==="("){if(n[o+2]==="("){s+=a,o++;continue}let c=0,f=o+1;for(;f<n.length;){if(n[f]==="(")c++;else if(n[f]===")"&&(c--,c===0))break;f++}let l=n.slice(o+2,f).trim(),u=(await r(l)).replace(/\n$/,"");s+=u,o=f+1;continue}s+=a,o++}n=s}return ho(n,t,e)}function yp(n){return n.replace(/\\n/g,`
80
- `).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 cf={name:"echo",description:"Display text",category:"shell",params:["[-n] [-e] [text...]"],run:({args:n,stdin:t,env:e})=>{let{flags:r,positionals:s}=Yt(n,{flags:["-n","-e","-E"]}),i=r.has("-n"),o=r.has("-e"),a=s.length>0?s.join(" "):t??"",c=ho(a,e?.vars??{},e?.lastExitCode??0),f=o?yp(c):c;return{stdout:i?f:`${f}
81
- `,exitCode:0}}};var ff={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,s])=>`${r}=${s}`).join(`
82
- `),exitCode:0}}};var lf={name:"exit",aliases:["bye"],description:"Exit the shell session",category:"shell",params:["[code]"],run:({args:n})=>({closeSession:!0,exitCode:parseInt(n[0]??"0",10)||0})};var uf={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,s])=>`declare -x ${r}="${s}"`).join(`
83
- `),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("="),s=e.slice(0,r),i=e.slice(r+1);t.vars[s]=i}return{exitCode:0}}};var df={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 s=zt(r,["-name"]),i=zt(r,["-type"]),a=r.filter(h=>!h.startsWith("-")&&h!==s&&h!==i)[0]??".",c=le(e,a);try{if(Me(n,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=s?new RegExp(`^${s.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,l=[],u=(h,p)=>{let _=t.vfs.stat(h),E=!i||i==="f"&&_.type==="file"||i==="d"&&_.type==="directory",b=!f||f.test(h.split("/").pop()??"");if(E&&b&&l.push(p),_.type==="directory")for(let v of t.vfs.list(h)){let U=`${h}/${v}`,H=`${p}/${v}`;u(U,H)}};return u(c,a),{stdout:l.join(`
84
- `),exitCode:0}}};var Zi=Kt(require("node:os"),1);var hf={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:n})=>{let t=se(n,["-h","--human"]),e=se(n,["-m"]),r=se(n,["-g"]),s=Zi.totalmem(),i=Zi.freemem(),o=s-i,a=Math.floor(s*.02),c=Math.floor(s*.05),f=Math.floor(i*.95),l=Math.floor(s*.5),u=E=>t?E>=1024*1024*1024?`${(E/(1024*1024*1024)).toFixed(1)}G`:E>=1024*1024?`${(E/(1024*1024)).toFixed(1)}M`:`${(E/1024).toFixed(1)}K`:String(Math.floor(r?E/(1024*1024*1024):e?E/(1024*1024):E/1024)),h=" total used free shared buff/cache available",p=`Mem: ${u(s).padStart(12)} ${u(o).padStart(11)} ${u(i).padStart(11)} ${u(a).padStart(11)} ${u(c).padStart(11)} ${u(f).padStart(11)}`,_=`Swap: ${u(l).padStart(12)} ${u(0).padStart(11)} ${u(l).padStart(11)}`;return{stdout:[h,p,_].join(`
85
- `),exitCode:0}}};var pf={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:s})=>{let{flags:i,positionals:o}=Yt(r,{flags:["-i","-v","-n","-r","-c","-l","-L","-q","--quiet","--silent"]}),a=i.has("-i"),c=i.has("-v"),f=i.has("-n"),l=i.has("-r"),u=i.has("-c"),h=i.has("-l"),p=i.has("-q")||i.has("--quiet")||i.has("--silent"),_=o[0],E=o.slice(1);if(!_)return{stderr:"grep: no pattern specified",exitCode:1};let b;try{let C=a?"mi":"m";b=new RegExp(_,C)}catch{return{stderr:`grep: invalid regex: ${_}`,exitCode:1}}let v=(C,F="")=>{let V=C.split(`
86
- `),N=[];for(let x=0;x<V.length;x++){let S=V[x]??"",I=b.test(S);if(c?!I:I){let R=f?`${x+1}:`:"";N.push(`${F}${R}${S}`)}}return N},U=C=>{if(!t.vfs.exists(C))return[];if(t.vfs.stat(C).type==="file")return[C];if(!l)return[];let V=[],N=x=>{for(let S of t.vfs.list(x)){let I=`${x}/${S}`;t.vfs.stat(I).type==="file"?V.push(I):N(I)}};return N(C),V},H=[];if(E.length===0){if(!s)return{stdout:"",exitCode:1};let C=v(s);if(u)return{stdout:`${C.length}
87
- `,exitCode:C.length>0?0:1};if(p)return{exitCode:C.length>0?0:1};H.push(...C)}else{let C=E.flatMap(F=>{let V=le(e,F);return U(V).map(N=>({file:F,path:N}))});for(let{file:F,path:V}of C)try{Me(n,V,"grep");let N=t.vfs.readFile(V),x=C.length>1?`${F}:`:"",S=v(N,x);u?H.push(C.length>1?`${F}:${S.length}`:String(S.length)):h?S.length>0&&H.push(F):H.push(...S)}catch{return{stderr:`grep: ${F}: No such file or directory`,exitCode:1}}}return{stdout:H.length>0?`${H.join(`
71
+ `)}catch{return{stderr:`diff: ${s}: No such file or directory`,exitCode:2}}let l=[],f=Math.max(a.length,c.length);for(let u=0;u<f;u++){let h=a[u],p=c[u];h!==p&&(h!==void 0&&l.push(`< ${h}`),p!==void 0&&l.push(`> ${p}`))}return{stdout:l.join(`
72
+ `),exitCode:l.length>0?1:0}}};var fl={name:"dpkg",description:"Debian package manager low-level tool",category:"package",params:["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"],run:({args:n,authUser:t,shell:e})=>{let r=Cr(e);if(!r)return{stderr:"dpkg: package manager not initialised",exitCode:1};let s=se(n,["-l","--list"]),i=se(n,["-s","--status"]),o=se(n,["-L","--listfiles"]),a=se(n,["-r","--remove"]),c=se(n,["-P","--purge"]),{positionals:l}=Xt(n,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(s){let f=r.listInstalled();if(f.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(`
73
+ `),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=f.map(p=>{let A=p.name.padEnd(14).slice(0,14),E=p.version.padEnd(15).slice(0,15),S=p.architecture.padEnd(12).slice(0,12),x=(p.description||"").slice(0,40);return`ii ${A} ${E} ${S} ${x}`});return{stdout:[...u,...h].join(`
74
+ `),exitCode:0}}if(i){let f=l[0];if(!f)return{stderr:"dpkg: -s needs a package name",exitCode:1};let u=r.show(f);return u?{stdout:u,exitCode:0}:{stderr:`dpkg-query: package '${f}' is not installed and no information is available`,exitCode:1}}if(o){let f=l[0];if(!f)return{stderr:"dpkg: -L needs a package name",exitCode:1};let u=r.listInstalled().find(h=>h.name===f);return u?u.files.length===0?{stdout:"/.keep",exitCode:0}:{stdout:u.files.join(`
75
+ `),exitCode:0}:{stderr:`dpkg-query: package '${f}' is not installed`,exitCode:1}}if(a||c){if(t!=="root")return{stderr:"dpkg: error: requested operation requires superuser privilege",exitCode:2};if(l.length===0)return{stderr:"dpkg: error: need an action option",exitCode:2};let{output:f,exitCode:u}=r.remove(l,{purge:c});return{stdout:f||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(`
76
+ `),exitCode:0}}},ul={name:"dpkg-query",description:"Show information about installed packages",category:"package",params:["-W [pkg] | -l [pattern]"],run:({args:n,shell:t})=>{let e=Cr(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let r=se(n,["-l"]),s=se(n,["-W","--show"]),{positionals:i}=Xt(n,{flags:["-l","-W","--show"]});if(r||s){let o=e.listInstalled(),a=i[0],c=a?o.filter(f=>f.name.includes(a)):o;return s?{stdout:c.map(f=>`${f.name} ${f.version}`).join(`
77
+ `),exitCode:0}:{stdout:c.map(f=>{let u=f.name.padEnd(14).slice(0,14),h=f.version.padEnd(15).slice(0,15);return`ii ${u} ${h} amd64 ${(f.description||"").slice(0,40)}`}).join(`
78
+ `)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var dl={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=se(e,["-h"]),s=se(e,["-s"]),i=e.find(f=>!f.startsWith("-"))??".",o=de(t,i),a=f=>r?`${(f/1024).toFixed(1)}K`:String(Math.ceil(f/1024));if(!n.vfs.exists(o))return{stderr:`du: ${i}: No such file or directory`,exitCode:1};if(s||n.vfs.stat(o).type==="file")return{stdout:`${a(n.vfs.getUsageBytes(o))} ${i}`,exitCode:0};let c=[],l=(f,u)=>{let h=0;for(let p of n.vfs.list(f)){let A=`${f}/${p}`,E=`${u}/${p}`,S=n.vfs.stat(A);S.type==="directory"?h+=l(A,E):(h+=S.size,s||c.push(`${a(S.size)} ${E}`))}return c.push(`${a(h)} ${u}`),h};return l(o,i),{stdout:c.join(`
79
+ `),exitCode:0}}};function wp(n,t){let e=[],r=0;for(;r<n.length;){let s=n[r];if(/\s/.test(s)){r++;continue}if(s==="+"){e.push({type:"plus"}),r++;continue}if(s==="-"){e.push({type:"minus"}),r++;continue}if(s==="*"){if(n[r+1]==="*"){e.push({type:"pow"}),r+=2;continue}e.push({type:"mul"}),r++;continue}if(s==="/"){e.push({type:"div"}),r++;continue}if(s==="%"){e.push({type:"mod"}),r++;continue}if(s==="("){e.push({type:"lparen"}),r++;continue}if(s===")"){e.push({type:"rparen"}),r++;continue}if(/\d/.test(s)){let i=r+1;for(;i<n.length&&/\d/.test(n[i]);)i++;e.push({type:"number",value:Number(n.slice(r,i))}),r=i;continue}if(/[A-Za-z_]/.test(s)){let i=r+1;for(;i<n.length&&/[A-Za-z0-9_]/.test(n[i]);)i++;let o=n.slice(r,i),a=t[o],c=a===void 0||a===""?0:Number(a);e.push({type:"number",value:Number.isFinite(c)?c:0}),r=i;continue}return[]}return e}function yo(n,t){let e=n.trim();if(e.length===0||e.length>1024)return NaN;let r=wp(e,t);if(r.length===0)return NaN;let s=0,i=()=>r[s],o=()=>r[s++],a=()=>{let p=o();if(!p)return NaN;if(p.type==="number")return p.value;if(p.type==="lparen"){let A=u();return r[s]?.type!=="rparen"?NaN:(s++,A)}return NaN},c=()=>{let p=i();return p?.type==="plus"?(o(),c()):p?.type==="minus"?(o(),-c()):a()},l=()=>{let p=c();for(;i()?.type==="pow";){o();let A=c();p=p**A}return p},f=()=>{let p=l();for(;;){let A=i();if(A?.type==="mul"){o(),p*=l();continue}if(A?.type==="div"){o();let E=l();p=E===0?NaN:p/E;continue}if(A?.type==="mod"){o();let E=l();p=E===0?NaN:p%E;continue}return p}},u=()=>{let p=f();for(;;){let A=i();if(A?.type==="plus"){o(),p+=f();continue}if(A?.type==="minus"){o(),p-=f();continue}return p}},h=u();return!Number.isFinite(h)||s!==r.length?NaN:Math.trunc(h)}function Ip(n,t){let e=[],r=0;for(;r<n.length;){let s=n.indexOf("'",r);if(s===-1){e.push(t(n.slice(r)));break}e.push(t(n.slice(r,s)));let i=n.indexOf("'",s+1);if(i===-1){e.push(n.slice(s));break}e.push(n.slice(s,i+1)),r=i+1}return e.join("")}function ns(n){function r(s,i){if(i>8)return[s];let o=0,a=-1;for(let c=0;c<s.length;c++){let l=s[c];if(l==="{"&&s[c-1]!=="$")o===0&&(a=c),o++;else if(l==="}"&&(o--,o===0&&a!==-1)){let f=s.slice(0,a),u=s.slice(a+1,c),h=s.slice(c+1),p=u.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$/)||u.match(/^([a-z])\.\.([a-z])$/);if(p){let x=[];if(/\d/.test(p[1])){let C=parseInt(p[1],10),U=parseInt(p[2],10),Q=p[3]?parseInt(p[3],10):1,B=C<=U?Q:-Q;for(let b=C;C<=U?b<=U:b>=U;b+=B)x.push(String(b))}else{let C=p[1].charCodeAt(0),U=p[2].charCodeAt(0),Q=C<=U?1:-1;for(let B=C;C<=U?B<=U:B>=U;B+=Q)x.push(String.fromCharCode(B))}let R=x.map(C=>`${f}${C}${h}`),H=[];for(let C of R)if(H.push(...r(C,i+1)),H.length>256)return[s];return H}let A=[],E="",S=0;for(let x of u)x==="{"?(S++,E+=x):x==="}"?(S--,E+=x):x===","&&S===0?(A.push(E),E=""):E+=x;if(A.push(E),A.length>1){let x=[];for(let R of A)if(x.push(...r(`${f}${R}${h}`,i+1)),x.length>256)return[s];return x}break}}return[s]}return r(n,0)}function Cp(n,t){let e="",r=0;for(;r<n.length;){if(n[r]==="$"&&n[r+1]==="("&&n[r+2]==="("){let s=r+3,i=0;for(;s<n.length;){let o=n[s];if(o==="(")i++;else if(o===")"){if(i>0)i--;else if(n[s+1]===")"){let a=n.slice(r+3,s),c=yo(a,t);e+=Number.isNaN(c)?"0":String(c),r=s+2;break}}s++}if(s>=n.length){e+=n.slice(r);break}continue}e+=n[r],r++}return e}function ts(n,t,e=0,r){let s=r??t.HOME??"/home/user";return Ip(n,i=>{let o=i;return o=o.replace(/(^|[\s:])~(\/|$)/g,(a,c,l)=>`${c}${s}${l}`),o=o.replace(/\$\?/g,String(e)),o=o.replace(/\$\$/g,"1"),o=o.replace(/\$#/g,"0"),o=Cp(o,t),o=o.replace(/\$\{#([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>String((t[c]??"").length)),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\}/g,(a,c,l)=>t[c]!==void 0&&t[c]!==""?t[c]:l),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):=([^}]*)\}/g,(a,c,l)=>((t[c]===void 0||t[c]==="")&&(t[c]=l),t[c])),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):\+([^}]*)\}/g,(a,c,l)=>t[c]!==void 0&&t[c]!==""?l:""),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>t[c]??""),o=o.replace(/\$([A-Za-z_][A-Za-z0-9_]*|\d+)/g,(a,c)=>t[c]??""),o})}async function rs(n,t,e,r){let s="__shellExpandDepth",o=Number(t[s]??"0");if(o>=8)return ts(n,t,e);t[s]=String(o+1);try{if(n.includes("$(")){let a="",c=!1,l=0;for(;l<n.length;){let f=n[l];if(f==="'"&&!c){c=!0,a+=f,l++;continue}if(f==="'"&&c){c=!1,a+=f,l++;continue}if(!c&&f==="$"&&n[l+1]==="("){if(n[l+2]==="("){a+=f,l++;continue}let u=0,h=l+1;for(;h<n.length;){if(n[h]==="(")u++;else if(n[h]===")"&&(u--,u===0))break;h++}let p=n.slice(l+2,h).trim(),A=(await r(p)).replace(/\n$/,"");a+=A,l=h+1;continue}a+=f,l++}n=a}return ts(n,t,e)}finally{o<=0?delete t[s]:t[s]=String(o)}}function kp(n){return n.replace(/\\n/g,`
80
+ `).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 hl={name:"echo",description:"Display text",category:"shell",params:["[-n] [-e] [text...]"],run:({args:n,stdin:t,env:e})=>{let{flags:r,positionals:s}=Xt(n,{flags:["-n","-e","-E"]}),i=r.has("-n"),o=r.has("-e"),a=s.length>0?s.join(" "):t??"",c=ts(a,e?.vars??{},e?.lastExitCode??0),l=o?kp(c):c;return{stdout:i?l:`${l}
81
+ `,exitCode:0}}};var pl={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,s])=>`${r}=${s}`).join(`
82
+ `),exitCode:0}}};var gl={name:"exit",aliases:["bye"],description:"Exit the shell session",category:"shell",params:["[code]"],run:({args:n})=>({closeSession:!0,exitCode:parseInt(n[0]??"0",10)||0})};var ml={name:"export",description:"Set shell environment variable",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0||n.length===1&&n[0]==="-p"){let e=Object.entries(t.vars).filter(([r])=>r&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)).map(([r,s])=>`declare -x ${r}="${s}"`).join(`
83
+ `);return{stdout:e?`${e}
84
+ `:"",exitCode:0}}for(let e of n.filter(r=>r!=="-p"))if(e.includes("=")){let r=e.indexOf("="),s=e.slice(0,r),i=e.slice(r+1);t.vars[s]=i}return{exitCode:0}}};var Al={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 s=jt(r,["-name"]),i=jt(r,["-type"]),a=r.filter(h=>!h.startsWith("-")&&h!==s&&h!==i)[0]??".",c=de(e,a);try{if(Oe(n,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 l=s?new RegExp(`^${s.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,f=[],u=(h,p)=>{let A=t.vfs.stat(h),E=!i||i==="f"&&A.type==="file"||i==="d"&&A.type==="directory",S=!l||l.test(h.split("/").pop()??"");if(E&&S&&f.push(p),A.type==="directory")for(let x of t.vfs.list(h)){let R=`${h}/${x}`,H=`${p}/${x}`;u(R,H)}};return u(c,a),{stdout:f.join(`
85
+ `),exitCode:0}}};var is=zt(require("node:os"),1);var yl={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:n})=>{let t=se(n,["-h","--human"]),e=se(n,["-m"]),r=se(n,["-g"]),s=is.totalmem(),i=is.freemem(),o=s-i,a=Math.floor(s*.02),c=Math.floor(s*.05),l=Math.floor(i*.95),f=Math.floor(s*.5),u=E=>t?E>=1024*1024*1024?`${(E/(1024*1024*1024)).toFixed(1)}G`:E>=1024*1024?`${(E/(1024*1024)).toFixed(1)}M`:`${(E/1024).toFixed(1)}K`:String(Math.floor(r?E/(1024*1024*1024):e?E/(1024*1024):E/1024)),h=" total used free shared buff/cache available",p=`Mem: ${u(s).padStart(12)} ${u(o).padStart(11)} ${u(i).padStart(11)} ${u(a).padStart(11)} ${u(c).padStart(11)} ${u(l).padStart(11)}`,A=`Swap: ${u(f).padStart(12)} ${u(0).padStart(11)} ${u(f).padStart(11)}`;return{stdout:[h,p,A].join(`
86
+ `),exitCode:0}}};var El={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:s})=>{let{flags:i,positionals:o}=Xt(r,{flags:["-i","-v","-n","-r","-c","-l","-L","-q","--quiet","--silent"]}),a=i.has("-i"),c=i.has("-v"),l=i.has("-n"),f=i.has("-r"),u=i.has("-c"),h=i.has("-l"),p=i.has("-q")||i.has("--quiet")||i.has("--silent"),A=o[0],E=o.slice(1);if(!A)return{stderr:"grep: no pattern specified",exitCode:1};let S;try{let C=a?"mi":"m";S=new RegExp(A,C)}catch{return{stderr:`grep: invalid regex: ${A}`,exitCode:1}}let x=(C,U="")=>{let Q=C.split(`
87
+ `),B=[];for(let b=0;b<Q.length;b++){let w=Q[b]??"",k=S.test(w);if(c?!k:k){let P=l?`${b+1}:`:"";B.push(`${U}${P}${w}`)}}return B},R=C=>{if(!t.vfs.exists(C))return[];if(t.vfs.stat(C).type==="file")return[C];if(!f)return[];let Q=[],B=b=>{for(let w of t.vfs.list(b)){let k=`${b}/${w}`;t.vfs.stat(k).type==="file"?Q.push(k):B(k)}};return B(C),Q},H=[];if(E.length===0){if(!s)return{stdout:"",exitCode:1};let C=x(s);if(u)return{stdout:`${C.length}
88
+ `,exitCode:C.length>0?0:1};if(p)return{exitCode:C.length>0?0:1};H.push(...C)}else{let C=E.flatMap(U=>{let Q=de(e,U);return R(Q).map(B=>({file:U,path:B}))});for(let{file:U,path:Q}of C)try{Oe(n,Q,"grep");let B=t.vfs.readFile(Q),b=C.length>1?`${U}:`:"",w=x(B,b);u?H.push(C.length>1?`${U}:${w.length}`:String(w.length)):h?w.length>0&&H.push(U):H.push(...w)}catch{return{stderr:`grep: ${U}: No such file or directory`,exitCode:1}}}return{stdout:H.length>0?`${H.join(`
88
89
  `)}
89
- `:"",exitCode:H.length>0?0:1}}};var gf={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 mf={name:"gzip",description:"Compress files",category:"archive",params:["[-k] [-d] <file>"],run:({shell:n,cwd:t,args:e})=>{if(!n.packageManager.isInstalled("gzip"))return{stderr:`bash: gzip: command not found
90
+ `:"",exitCode:H.length>0?0:1}}};var _l={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 bl={name:"gzip",description:"Compress files",category:"archive",params:["[-k] [-d] <file>"],run:({shell:n,cwd:t,args:e})=>{if(!n.packageManager.isInstalled("gzip"))return{stderr:`bash: gzip: command not found
90
91
  Hint: install it with: apt install gzip
91
- `,exitCode:127};let r=e.includes("-k")||e.includes("--keep"),s=e.includes("-d"),i=e.find(f=>!f.startsWith("-"));if(!i)return{stderr:`gzip: no file specified
92
- `,exitCode:1};let o=le(t,i);if(s){if(!i.endsWith(".gz"))return{stderr:`gzip: ${i}: unknown suffix -- ignored
92
+ `,exitCode:127};let r=e.includes("-k")||e.includes("--keep"),s=e.includes("-d"),i=e.find(l=>!l.startsWith("-"));if(!i)return{stderr:`gzip: no file specified
93
+ `,exitCode:1};let o=de(t,i);if(s){if(!i.endsWith(".gz"))return{stderr:`gzip: ${i}: unknown suffix -- ignored
93
94
  `,exitCode:1};if(!n.vfs.exists(o))return{stderr:`gzip: ${i}: No such file or directory
94
- `,exitCode:1};let f=n.vfs.readFile(o),l=o.slice(0,-3);return n.vfs.writeFile(l,f),r||n.vfs.remove(o),{exitCode:0}}if(!n.vfs.exists(o))return{stderr:`gzip: ${i}: No such file or directory
95
+ `,exitCode:1};let l=n.vfs.readFile(o),f=o.slice(0,-3);return n.vfs.writeFile(f,l),r||n.vfs.remove(o),{exitCode:0}}if(!n.vfs.exists(o))return{stderr:`gzip: ${i}: No such file or directory
95
96
  `,exitCode:1};if(i.endsWith(".gz"))return{stderr:`gzip: ${i}: already has .gz suffix -- unchanged
96
- `,exitCode:1};let a=n.vfs.readFileRaw(o),c=`${o}.gz`;return n.vfs.writeFile(c,a,{compress:!0}),r||n.vfs.remove(o),{exitCode:0}}},Af={name:"gunzip",description:"Decompress files",category:"archive",aliases:["zcat"],params:["[-k] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-k")||e.includes("--keep"),s=e.find(c=>!c.startsWith("-"));if(!s)return{stderr:`gunzip: no file specified
97
- `,exitCode:1};let i=le(t,s);if(!n.vfs.exists(i))return{stderr:`gunzip: ${s}: No such file or directory
97
+ `,exitCode:1};let a=n.vfs.readFileRaw(o),c=`${o}.gz`;return n.vfs.writeFile(c,a,{compress:!0}),r||n.vfs.remove(o),{exitCode:0}}},Sl={name:"gunzip",description:"Decompress files",category:"archive",aliases:["zcat"],params:["[-k] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-k")||e.includes("--keep"),s=e.find(c=>!c.startsWith("-"));if(!s)return{stderr:`gunzip: no file specified
98
+ `,exitCode:1};let i=de(t,s);if(!n.vfs.exists(i))return{stderr:`gunzip: ${s}: No such file or directory
98
99
  `,exitCode:1};if(!s.endsWith(".gz"))return{stderr:`gunzip: ${s}: unknown suffix -- ignored
99
- `,exitCode:1};let o=n.vfs.readFile(i),a=i.slice(0,-3);return n.vfs.writeFile(a,o),r||n.vfs.remove(i),{exitCode:0}}};var Ef={name:"head",description:"Output first lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=zt(r,["-n"]),o=r.find(u=>/^-\d+$/.test(u)),a=typeof i=="string"?parseInt(i,10):o?parseInt(o.slice(1),10):10,c=r.filter(u=>!u.startsWith("-")&&u!==i&&u!==String(a)),f=u=>{let h=u.split(`
100
+ `,exitCode:1};let o=n.vfs.readFile(i),a=i.slice(0,-3);return n.vfs.writeFile(a,o),r||n.vfs.remove(i),{exitCode:0}}};var xl={name:"head",description:"Output first lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=jt(r,["-n"]),o=r.find(u=>/^-\d+$/.test(u)),a=typeof i=="string"?parseInt(i,10):o?parseInt(o.slice(1),10):10,c=r.filter(u=>!u.startsWith("-")&&u!==i&&u!==String(a)),l=u=>{let h=u.split(`
100
101
  `),p=h.slice(0,a);return p.join(`
101
102
  `)+(u.endsWith(`
102
103
  `)&&p.length===h.slice(0,a).length?`
103
- `:"")};if(c.length===0)return{stdout:f(s??""),exitCode:0};let l=[];for(let u of c){let h=le(e,u);try{Me(n,h,"head"),l.push(f(t.vfs.readFile(h)))}catch{return{stderr:`head: ${u}: No such file or directory`,exitCode:1}}}return{stdout:l.join(`
104
- `),exitCode:0}}};var yf=["navigation","files","text","archive","system","package","network","shell","users","misc"],bf={navigation:"Navigation",files:"Files & Filesystem",text:"Text Processing",archive:"Archive & Compression",system:"System",package:"Package Management",network:"Network",shell:"Shell & Scripting",users:"Users & Permissions",misc:"Miscellaneous"},xf="\x1B[1m",xn="\x1B[0m",_p="\x1B[36m",bp="\x1B[33m",ai="\x1B[2m",xp="\x1B[32m";function _f(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function Sp(n){let t=n.aliases?.length?` ${ai}(${n.aliases.join(", ")})${xn}`:"";return` ${_p}${_f(n.name,16)}${xn}${t}${_f("",(n.aliases?.length,0))} ${n.description??""}`}function wp(n){let t={};for(let i of n){let o=i.category??"misc";t[o]||(t[o]=[]),t[o].push(i)}let e=[`${xf}Available commands${xn}`,`${ai}Type 'help <command>' for detailed usage.${xn}`,""],r=[...yf.filter(i=>t[i]),...Object.keys(t).filter(i=>!yf.includes(i)).sort()];for(let i of r){let o=t[i];if(!o?.length)continue;e.push(`${bp}${bf[i]??i}${xn}`);let a=[...o].sort((c,f)=>c.name.localeCompare(f.name));for(let c of a)e.push(Sp(c));e.push("")}let s=n.length;return e.push(`${ai}${s} commands available.${xn}`),e.join(`
105
- `)}function Ip(n){let t=[];if(t.push(`${xf}${n.name}${xn} \u2014 ${n.description??"no description"}`),n.aliases?.length&&t.push(`${ai}Aliases: ${n.aliases.join(", ")}${xn}`),t.push(""),t.push(`${xp}Usage:${xn}`),n.params.length)for(let r of n.params)t.push(` ${n.name} ${r}`);else t.push(` ${n.name}`);let e=bf[n.category??"misc"]??n.category??"misc";return t.push(""),t.push(`${ai}Category: ${e}${xn}`),t.join(`
106
- `)}function Sf(n){return{name:"help",description:"List all commands, or show usage for a specific command",category:"shell",params:["[command]"],run:({args:t})=>{let e=po();if(t[0]){let r=t[0].toLowerCase(),s=e.find(i=>i.name===r||i.aliases?.includes(r));return s?{stdout:Ip(s),exitCode:0}:{stderr:`help: no help entry for '${t[0]}'`,exitCode:1}}return{stdout:wp(e),exitCode:0}}}}var wf={name:"history",description:"Display command history",category:"shell",params:["[n]"],run:({args:n,shell:t,authUser:e})=>{let r=`/home/${e}/.bash_history`;if(!t.vfs.exists(r))return{stdout:"",exitCode:0};let i=t.vfs.readFile(r).split(`
107
- `).filter(Boolean),o=n[0],a=o?parseInt(o,10):null,c=a&&!Number.isNaN(a)?i.slice(-a):i,f=i.length-c.length+1;return{stdout:c.map((u,h)=>`${String(f+h).padStart(5)} ${u}`).join(`
108
- `),exitCode:0}}};var If={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})};var Cf={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 vf={name:"id",description:"Print user identity",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n,s=r==="root"?0:1e3,i=s,a=t.users.isSudoer(r)?`${i}(${r}),0(root)`:`${i}(${r})`;return{stdout:`uid=${s}(${r}) gid=${i}(${r}) groups=${a}`,exitCode:0}}};var kf={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 Bf={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-s","--symbolic"]),i=r.filter(l=>!l.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let c=le(e,a),f=s?o:le(e,o);try{if(Me(n,c,"ln"),s)t.vfs.symlink(f,c);else{let l=le(e,o);if(Me(n,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(n,c,u)}return{exitCode:0}}catch(l){return{stderr:`ln: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}},Rf={name:"readlink",description:"Print resolved path of symbolic link",category:"files",params:["[-f] <path>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-f")||e.includes("-e"),s=e.find(a=>!a.startsWith("-"));if(!s)return{stderr:`readlink: missing operand
109
- `,exitCode:1};let i=le(t,s);return n.vfs.exists(i)?n.vfs.isSymlink(i)?{stdout:`${n.vfs.resolveSymlink(i)}
104
+ `:"")};if(c.length===0)return{stdout:l(s??""),exitCode:0};let f=[];for(let u of c){let h=de(e,u);try{Oe(n,h,"head"),f.push(l(t.vfs.readFile(h)))}catch{return{stderr:`head: ${u}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
105
+ `),exitCode:0}}};var wl=["navigation","files","text","archive","system","package","network","shell","users","misc"],Cl={navigation:"Navigation",files:"Files & Filesystem",text:"Text Processing",archive:"Archive & Compression",system:"System",package:"Package Management",network:"Network",shell:"Shell & Scripting",users:"Users & Permissions",misc:"Miscellaneous"},kl="\x1B[1m",Cn="\x1B[0m",vp="\x1B[36m",Bp="\x1B[33m",fi="\x1B[2m",Rp="\x1B[32m";function Il(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function Np(n){let t=n.aliases?.length?` ${fi}(${n.aliases.join(", ")})${Cn}`:"";return` ${vp}${Il(n.name,16)}${Cn}${t}${Il("",(n.aliases?.length,0))} ${n.description??""}`}function Pp(n){let t={};for(let i of n){let o=i.category??"misc";t[o]||(t[o]=[]),t[o].push(i)}let e=[`${kl}Available commands${Cn}`,`${fi}Type 'help <command>' for detailed usage.${Cn}`,""],r=[...wl.filter(i=>t[i]),...Object.keys(t).filter(i=>!wl.includes(i)).sort()];for(let i of r){let o=t[i];if(!o?.length)continue;e.push(`${Bp}${Cl[i]??i}${Cn}`);let a=[...o].sort((c,l)=>c.name.localeCompare(l.name));for(let c of a)e.push(Np(c));e.push("")}let s=n.length;return e.push(`${fi}${s} commands available.${Cn}`),e.join(`
106
+ `)}function Tp(n){let t=[];if(t.push(`${kl}${n.name}${Cn} \u2014 ${n.description??"no description"}`),n.aliases?.length&&t.push(`${fi}Aliases: ${n.aliases.join(", ")}${Cn}`),t.push(""),t.push(`${Rp}Usage:${Cn}`),n.params.length)for(let r of n.params)t.push(` ${n.name} ${r}`);else t.push(` ${n.name}`);let e=Cl[n.category??"misc"]??n.category??"misc";return t.push(""),t.push(`${fi}Category: ${e}${Cn}`),t.join(`
107
+ `)}function vl(n){return{name:"help",description:"List all commands, or show usage for a specific command",category:"shell",params:["[command]"],run:({args:t})=>{let e=Eo();if(t[0]){let r=t[0].toLowerCase(),s=e.find(i=>i.name===r||i.aliases?.includes(r));return s?{stdout:Tp(s),exitCode:0}:{stderr:`help: no help entry for '${t[0]}'`,exitCode:1}}return{stdout:Pp(e),exitCode:0}}}}var Bl={name:"history",description:"Display command history",category:"shell",params:["[n]"],run:({args:n,shell:t,authUser:e})=>{let r=`/home/${e}/.bash_history`;if(!t.vfs.exists(r))return{stdout:"",exitCode:0};let i=t.vfs.readFile(r).split(`
108
+ `).filter(Boolean),o=n[0],a=o?parseInt(o,10):null,c=a&&!Number.isNaN(a)?i.slice(-a):i,l=i.length-c.length+1;return{stdout:c.map((u,h)=>`${String(l+h).padStart(5)} ${u}`).join(`
109
+ `),exitCode:0}}};var Rl={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})};var Nl={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 Pl={name:"id",description:"Print user identity",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n,s=r==="root"?0:1e3,i=s,a=t.users.isSudoer(r)?`${i}(${r}),0(root)`:`${i}(${r})`;return{stdout:`uid=${s}(${r}) gid=${i}(${r}) groups=${a}`,exitCode:0}}};var Tl={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 Ll={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-s","--symbolic"]),i=r.filter(f=>!f.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let c=de(e,a),l=s?o:de(e,o);try{if(Oe(n,c,"ln"),s)t.vfs.symlink(l,c);else{let f=de(e,o);if(Oe(n,f,"ln"),!t.vfs.exists(f))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let u=t.vfs.readFile(f);t.writeFileAsUser(n,c,u)}return{exitCode:0}}catch(f){return{stderr:`ln: ${f instanceof Error?f.message:String(f)}`,exitCode:1}}}},$l={name:"readlink",description:"Print resolved path of symbolic link",category:"files",params:["[-f] <path>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-f")||e.includes("-e"),s=e.find(a=>!a.startsWith("-"));if(!s)return{stderr:`readlink: missing operand
110
+ `,exitCode:1};let i=de(t,s);return n.vfs.exists(i)?n.vfs.isSymlink(i)?{stdout:`${n.vfs.resolveSymlink(i)}
110
111
  `,exitCode:0}:{stderr:`readlink: ${s}: not a symbolic link
111
112
  `,exitCode:1}:{stderr:`readlink: ${s}: No such file or directory
112
- `,exitCode:1}}};var Nf={name:"stat",description:"Display file status",category:"files",params:["[-c <format>] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.findIndex(v=>v==="-c"||v==="--format"),s=r!==-1?e[r+1]:void 0,i=e.find(v=>!v.startsWith("-")&&v!==s);if(!i)return{stderr:`stat: missing operand
113
- `,exitCode:1};let o=le(t,i);if(!n.vfs.exists(o))return{stderr:`stat: cannot stat '${i}': No such file or directory
114
- `,exitCode:1};let a=n.vfs.stat(o),c=a.type==="directory",f=n.vfs.isSymlink(o),l=n.vfs.isSymlink(o),u=v=>{let U=[256,128,64,32,16,8,4,2,1],H=["r","w","x","r","w","x","r","w","x"];return(c?"d":l?"l":"-")+U.map((C,F)=>v&C?H[F]:"-").join("")},h=a.mode.toString(8).padStart(4,"0"),p=u(a.mode),_="size"in a?a.size:0,E=v=>v.toISOString().replace("T"," ").replace(/\.\d+Z$/," +0000");return s?{stdout:`${s.replace("%n",i).replace("%s",String(_)).replace("%a",h.slice(1)).replace("%A",p).replace("%F",l?"symbolic link":c?"directory":"regular file").replace("%y",E(a.updatedAt)).replace("%z",E(a.updatedAt))}
115
- `,exitCode:0}:{stdout:`${[` File: ${i}${l?` -> ${n.vfs.resolveSymlink(o)}`:""}`,` Size: ${_}${" ".repeat(3)}${l?"symbolic link":c?"directory":"regular file"}`,`Access: (${h}/${p}) Uid: ( 0/ root) Gid: ( 0/ root)`,`Modify: ${E(a.updatedAt)}`,`Change: ${E(a.updatedAt)}`].join(`
113
+ `,exitCode:1}}};var Dl={name:"seq",description:"Print a sequence of numbers",category:"text",params:["[FIRST [INCREMENT]] LAST"],run:({args:n})=>{let t=n.filter(u=>!u.startsWith("-")||/^-[\d.]/.test(u)).map(Number),e=(()=>{let u=n.indexOf("-s");return u!==-1?n[u+1]??`
114
+ `:`
115
+ `})(),r=(()=>{let u=n.indexOf("-f");return u!==-1?n[u+1]??"%g":null})(),s=n.includes("-w"),i=1,o=1,a;if(t.length===1?a=t[0]:t.length===2?(i=t[0],a=t[1]):(i=t[0],o=t[1],a=t[2]),o===0)return{stderr:`seq: zero increment
116
+ `,exitCode:1};if(o>0&&i>a||o<0&&i<a)return{stdout:"",exitCode:0};let c=[],l=1e5,f=0;for(let u=i;(o>0?u<=a:u>=a)&&!(++f>l);u=Math.round((u+o)*1e10)/1e10){let h;if(r?h=r.replace("%g",String(u)).replace("%f",u.toFixed(6)).replace("%d",String(Math.trunc(u))):h=Number.isInteger(u)?String(u):u.toPrecision(12).replace(/\.?0+$/,""),s){let p=String(Math.trunc(a)).length;h=h.padStart(p,"0")}c.push(h)}return{stdout:`${c.join(e)}
117
+ `,exitCode:0}}};var Ul={name:"stat",description:"Display file status",category:"files",params:["[-c <format>] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.findIndex(x=>x==="-c"||x==="--format"),s=r!==-1?e[r+1]:void 0,i=e.find(x=>!x.startsWith("-")&&x!==s);if(!i)return{stderr:`stat: missing operand
118
+ `,exitCode:1};let o=de(t,i);if(!n.vfs.exists(o))return{stderr:`stat: cannot stat '${i}': No such file or directory
119
+ `,exitCode:1};let a=n.vfs.stat(o),c=a.type==="directory",l=n.vfs.isSymlink(o),f=n.vfs.isSymlink(o),u=x=>{let R=[256,128,64,32,16,8,4,2,1],H=["r","w","x","r","w","x","r","w","x"];return(c?"d":f?"l":"-")+R.map((C,U)=>x&C?H[U]:"-").join("")},h=a.mode.toString(8).padStart(4,"0"),p=u(a.mode),A="size"in a?a.size:0,E=x=>x.toISOString().replace("T"," ").replace(/\.\d+Z$/," +0000");return s?{stdout:`${s.replace("%n",i).replace("%s",String(A)).replace("%a",h.slice(1)).replace("%A",p).replace("%F",f?"symbolic link":c?"directory":"regular file").replace("%y",E(a.updatedAt)).replace("%z",E(a.updatedAt))}
120
+ `,exitCode:0}:{stdout:`${[` File: ${i}${f?` -> ${n.vfs.resolveSymlink(o)}`:""}`,` Size: ${A}${" ".repeat(3)}${f?"symbolic link":c?"directory":"regular file"}`,`Access: (${h}/${p}) Uid: ( 0/ root) Gid: ( 0/ root)`,`Modify: ${E(a.updatedAt)}`,`Change: ${E(a.updatedAt)}`].join(`
116
121
  `)}
117
- `,exitCode:0}}};function Pf(n,t){let e=t?"d":"-",s=[[256,"r"],[128,"w"],[64,"x"],[32,"r"],[16,"w"],[8,"x"],[4,"r"],[2,"w"],[1,"x"]].map(([i,o])=>n&i?o:"-").join("");return`${e}${s}`}function Tf(n){return n.toISOString().replace("T"," ").slice(0,16)}var Lf={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-l","--long"]),i=se(r,["-a","--all"]),o=Tn(r,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=le(e,o??e);if(Me(n,a,"ls"),t.vfs.exists(a)){let l=t.vfs.stat(a);if(l.type==="file"||t.vfs.isSymlink(a)){if(s){let u=a.split("/").pop()??a,h=l.type==="file"?l.size:0;return{stdout:`${Pf(l.mode,!1)} 1 root root ${h} ${Tf(l.updatedAt)} ${u}
118
- `,exitCode:0}}return{stdout:a.split("/").pop()??a,exitCode:0}}}let c=t.vfs.list(a).filter(l=>i||!l.startsWith("."));return{stdout:s?c.map(l=>{let u=le(a,l),h=t.vfs.stat(u),p=h.type==="file"?h.size:h.childrenCount;return`${Pf(h.mode,h.type==="directory")} 1 ${p} ${Tf(h.updatedAt)} ${l}${h.type==="directory"?"/":""}`}).join(`
119
- `):Hc(a,c,l=>t.vfs.stat(l)),exitCode:0}}};var Df={name:"lsb_release",description:"Print distribution-specific information",category:"system",params:["[-a] [-i] [-d] [-r] [-c]"],run:({args:n,shell:t})=>{let e=t.properties?.os??"Fortune GNU/Linux x64",r="aurora",s="1.0";try{let u=t.vfs.readFile("/etc/os-release");for(let h of u.split(`
120
- `))h.startsWith("PRETTY_NAME=")&&(e=h.slice(12).replace(/^"|"$/g,"").trim()),h.startsWith("VERSION_CODENAME=")&&(r=h.slice(17).trim()),h.startsWith("VERSION_ID=")&&(s=h.slice(11).replace(/^"|"$/g,"").trim())}catch{}let i=se(n,["-a","--all"]),o=se(n,["-i","--id"]),a=se(n,["-d","--description"]),c=se(n,["-r","--release"]),f=se(n,["-c","--codename"]);if(i||n.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${e}`,`Release: ${s}`,`Codename: ${r}`].join(`
121
- `),exitCode:0};let l=[];return o&&l.push("Distributor ID: Fortune"),a&&l.push(`Description: ${e}`),c&&l.push(`Release: ${s}`),f&&l.push(`Codename: ${r}`),{stdout:l.join(`
122
- `),exitCode:0}}};var Rp={},Cp={gunzip:"gzip"},es=new Map,vp=new URL("./manuals/",Rp.url);async function kp(n){return new Function("moduleName","return import(moduleName)")(n)}async function Bp(n){let t=n.toLowerCase(),e=Cp[t]??t,r=`builtin:${e}`;if(es.has(r))return es.get(r)??null;try{let s=await kp("node:fs/promises"),i=new URL(`${e}.txt`,vp),a=(await s.readFile(i,"utf8")).replace(/\n$/,"");return es.set(r,a),a}catch{return es.set(r,null),null}}var Uf={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:async({args:n,shell:t})=>{let e=n[0];if(!e)return{stderr:"What manual page do you want?",exitCode:1};let r=`/usr/share/man/man1/${e}.1`;if(t.vfs.exists(r))return{stdout:t.vfs.readFile(r),exitCode:0};let s=await Bp(e);return s?{stdout:s,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var $f={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 s=0;s<r.length;s++){let i=Tn(r,s);if(!i)return{stderr:"mkdir: missing operand",exitCode:1};let o=le(e,i);Me(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var Mf={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=r.filter(f=>!f.startsWith("-")),[i,o]=s;if(!i||!o)return{stderr:"mv: missing operand",exitCode:1};let a=le(e,i),c=le(e,o);try{if(Me(n,a,"mv"),Me(n,c,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${i}: No such file or directory`,exitCode:1};let f=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${i.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 Of=Kt(require("node:path"),1);var Ff={name:"nano",description:"Text editor",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=r[0];if(!s)return{stderr:"nano: missing file operand",exitCode:1};let i=le(e,s);Me(n,i,"nano");let o=t.vfs.exists(i)?t.vfs.readFile(i):"",a=Of.posix.basename(i)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:i,tempPath:c,initialContent:o},exitCode:0}}};var Ln=require("node:fs"),$t=Kt(require("node:os"),1),Gf=Kt(require("node:path"),1);function Np(n){let t=Math.max(1,Math.floor(n/60)),e=Math.floor(t/1440),r=Math.floor(t%1440/60),s=t%60,i=[];return e>0&&i.push(`${e} day${e>1?"s":""}`),r>0&&i.push(`${r} hour${r>1?"s":""}`),(s>0||i.length===0)&&i.push(`${s} min${s>1?"s":""}`),i.join(", ")}function Hf(n){return`\x1B[${n}m \x1B[0m`}function Pp(){let n=[40,41,42,43,44,45,46,47].map(Hf).join(""),t=[100,101,102,103,104,105,106,107].map(Hf).join("");return[n,t]}function Qf(n,t,e){if(n.trim().length===0)return n;let r={r:255,g:255,b:255},s={r:168,g:85,b:247},i=e<=1?0:t/(e-1),o=Math.round(r.r+(s.r-r.r)*i),a=Math.round(r.g+(s.g-r.g)*i),c=Math.round(r.b+(s.b-r.b)*i);return`\x1B[38;2;${o};${a};${c}m${n}\x1B[0m`}function Tp(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?Wf(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return Wf(e)+r}function Wf(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},s={r:168,g:85,b:247},i="";for(let o=0;o<e.length;o+=1){let a=e.length<=1?0:o/(e.length-1),c=Math.round(r.r+(s.r-r.r)*a),f=Math.round(r.g+(s.g-r.g)*a),l=Math.round(r.b+(s.b-r.b)*a);i+=`\x1B[38;2;${c};${f};${l}m${e[o]}\x1B[0m`}return i}function qf(n){return Math.max(0,Math.round(n/(1024*1024)))}function Kf(){try{let n=(0,Ln.readFileSync)("/etc/os-release","utf8");for(let t of n.split(`
123
- `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function Vf(n){try{let t=(0,Ln.readFileSync)(n,"utf8").split(`
124
- `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function Lp(n){let t=Vf("/sys/devices/virtual/dmi/id/sys_vendor"),e=Vf("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function Dp(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if((0,Ln.existsSync)(t))try{return(0,Ln.readFileSync)(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function Up(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if((0,Ln.existsSync)(t))try{return(0,Ln.readdirSync)(t,{withFileTypes:!0}).filter(s=>s.isDirectory()).length}catch{}}function $p(){let n=Dp(),t=Up();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function Mp(){let n=$t.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":Gf.posix.basename(n.trim())}function Fp(n){let t=$t.totalmem(),e=$t.freemem(),r=Math.max(0,t-e),s=n.shellProps,i=process.uptime();return n.uptimeSeconds===void 0&&(n.uptimeSeconds=Math.round(i)),{user:n.user,host:n.host,osName:s?.os??n.osName??`${Kf()??$t.type()} ${$t.arch()}`,kernel:s?.kernel??n.kernel??$t.release(),uptimeSeconds:n.uptimeSeconds??$t.uptime(),packages:n.packages??$p(),shell:Op(n.shell),shellProps:n.shellProps??{kernel:n.kernel??$t.release(),os:n.osName??`${Kf()??$t.type()} ${$t.arch()}`,arch:$t.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??Mp(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??qf(r),memoryTotalMiB:n.memoryTotalMiB??qf(t)}}function zf(n){let t=Fp(n),e=Np(t.uptimeSeconds),r=Pp(),s=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],i=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${Lp(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`,"",r[0],r[1]],o=Math.max(s.length,i.length),a=[];for(let c=0;c<o;c+=1){let f=s[c]??"",l=i[c]??"";if(l.length>0){let u=Qf(f.padEnd(31," "),c,s.length),h=Tp(l);a.push(`${u} ${h}`);continue}a.push(Qf(f,c,s.length))}return a.join(`
125
- `)}var Yf={name:"neofetch",description:"System info display",category:"system",params:["[--off]"],run:({args:n,authUser:t,hostname:e,shell:r,env:s})=>r.packageManager.isInstalled("neofetch")?se(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:se(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:zf({user:t,host:e,shell:s.vars.SHELL,shellProps:r.properties,terminal:s.vars.TERM,uptimeSeconds:Math.floor((Date.now()-r.startTime)/1e3),packages:`${r.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}:{stderr:`bash: neofetch: command not found
122
+ `,exitCode:0}}};var Lp="\x1B[0m",$p="\x1B[1;34m",Dp="\x1B[1;36m",Up="\x1B[1;32m",Mp="",Op="\x1B[30;42m",Fp="\x1B[37;44m",Hp="\x1B[34;42m";function kr(n,t){return t?`${t}${n}${Lp}`:n}function bo(n,t,e){if(e)return Dp;if(t==="directory"){let r=!!(n&512),s=!!(n&2);return r&&s?Op:r?Fp:s?Hp:$p}return n&73?Up:Mp}function Ml(n,t,e){let r;e?r="l":t==="directory"?r="d":r="-";let s=l=>n&l?"r":"-",i=l=>n&l?"w":"-",o=(()=>{let l=!!(n&64);return n&2048?l?"s":"S":l?"x":"-"})(),a=(()=>{let l=!!(n&8);return n&1024?l?"s":"S":l?"x":"-"})(),c=(()=>{let l=!!(n&1);return t==="directory"&&n&512?l?"t":"T":l?"x":"-"})();return`${r}${s(256)}${i(128)}${o}${s(32)}${i(16)}${a}${s(4)}${i(2)}${c}`}var Qp=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function _o(n){let t=new Date,e=4320*3600*1e3,r=Math.abs(t.getTime()-n.getTime())<e,s=String(n.getDate()).padStart(2," "),i=Qp[n.getMonth()]??"";if(r){let o=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0");return`${s} ${i.padEnd(3)} ${o}:${a}`}return`${s} ${i.padEnd(3)} ${n.getFullYear()}`}function ss(n,t){try{return n.readFile(t)}catch{return"?"}}function Wp(n,t,e){let r=t==="/"?"":t;return e.map(s=>{let i=`${r}/${s}`,o=n.isSymlink(i),a;try{a=n.stat(i)}catch{return s}let c=bo(a.mode,a.type,o);return kr(s,c)}).join(" ")}function qp(n,t,e){let r=t==="/"?"":t,s=e.map(u=>{let h=`${r}/${u}`,p=n.isSymlink(h),A;try{A=n.stat(h)}catch{return{perms:"----------",nlink:"1",size:"0",date:_o(new Date),label:u}}let E=p?41471:A.mode,S=Ml(E,A.type,p),x=A.type==="directory"?String((A.childrenCount??0)+2):"1",R=p?ss(n,h).length:A.type==="file"?A.size??0:(A.childrenCount??0)*4096,H=String(R),C=_o(A.updatedAt),U=bo(E,A.type,p),Q=p?`${kr(u,U)} -> ${ss(n,h)}`:kr(u,U);return{perms:S,nlink:x,size:H,date:C,label:Q}}),i=Math.max(...s.map(u=>u.nlink.length)),o=Math.max(...s.map(u=>u.size.length)),a="root",c="root",l=e.length*8,f=s.map(u=>`${u.perms} ${u.nlink.padStart(i)} ${a} ${c} ${u.size.padStart(o)} ${u.date} ${u.label}`);return`total ${l}
123
+ ${f.join(`
124
+ `)}`}var Ol={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-l","--long","-la","-al"]),i=se(r,["-a","--all","-la","-al"]),o=$n(r,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=de(e,o??e);if(Oe(n,a,"ls"),t.vfs.exists(a)){let f=t.vfs.stat(a),u=t.vfs.isSymlink(a);if(f.type==="file"||u){let h=a.split("/").pop()??a,p=bo(u?41471:f.mode,f.type,u);if(s){let A=u?41471:f.mode,E=u?ss(t.vfs,a).length:f.size??0,S=Ml(A,f.type,u),x=u?`${kr(h,p)} -> ${ss(t.vfs,a)}`:kr(h,p);return{stdout:`${S} 1 root root ${E} ${_o(f.updatedAt)} ${x}
125
+ `,exitCode:0}}return{stdout:`${kr(h,p)}
126
+ `,exitCode:0}}}let c=t.vfs.list(a).filter(f=>i||!f.startsWith("."));return{stdout:`${s?qp(t.vfs,a,c):Wp(t.vfs,a,c)}
127
+ `,exitCode:0}}};var Fl={name:"lsb_release",description:"Print distribution-specific information",category:"system",params:["[-a] [-i] [-d] [-r] [-c]"],run:({args:n,shell:t})=>{let e=t.properties?.os??"Fortune GNU/Linux x64",r="aurora",s="1.0";try{let u=t.vfs.readFile("/etc/os-release");for(let h of u.split(`
128
+ `))h.startsWith("PRETTY_NAME=")&&(e=h.slice(12).replace(/^"|"$/g,"").trim()),h.startsWith("VERSION_CODENAME=")&&(r=h.slice(17).trim()),h.startsWith("VERSION_ID=")&&(s=h.slice(11).replace(/^"|"$/g,"").trim())}catch{}let i=se(n,["-a","--all"]),o=se(n,["-i","--id"]),a=se(n,["-d","--description"]),c=se(n,["-r","--release"]),l=se(n,["-c","--codename"]);if(i||n.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${e}`,`Release: ${s}`,`Codename: ${r}`].join(`
129
+ `),exitCode:0};let f=[];return o&&f.push("Distributor ID: Fortune"),a&&f.push(`Description: ${e}`),c&&f.push(`Release: ${s}`),l&&f.push(`Codename: ${r}`),{stdout:f.join(`
130
+ `),exitCode:0}}};var Yp={},Kp={gunzip:"gzip"},os=new Map,Vp=new URL("./manuals/",Yp.url);async function zp(n){return new Function("moduleName","return import(moduleName)")(n)}async function Gp(n){let t=n.toLowerCase(),e=Kp[t]??t,r=`builtin:${e}`;if(os.has(r))return os.get(r)??null;try{let s=await zp("node:fs/promises"),i=new URL(`${e}.txt`,Vp),a=(await s.readFile(i,"utf8")).replace(/\n$/,"");return os.set(r,a),a}catch{return os.set(r,null),null}}var Hl={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:async({args:n,shell:t})=>{let e=n[0];if(!e)return{stderr:"What manual page do you want?",exitCode:1};let r=`/usr/share/man/man1/${e}.1`;if(t.vfs.exists(r))return{stdout:t.vfs.readFile(r),exitCode:0};let s=await Gp(e);return s?{stdout:s,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var Ql={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 s=0;s<r.length;s++){let i=$n(r,s);if(!i)return{stderr:"mkdir: missing operand",exitCode:1};let o=de(e,i);Oe(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var Wl={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=r.filter(l=>!l.startsWith("-")),[i,o]=s;if(!i||!o)return{stderr:"mv: missing operand",exitCode:1};let a=de(e,i),c=de(e,o);try{if(Oe(n,a,"mv"),Oe(n,c,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${i}: No such file or directory`,exitCode:1};let l=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${i.split("/").pop()}`:c;return t.vfs.move(a,l),{exitCode:0}}catch(l){return{stderr:`mv: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};var ql=zt(require("node:path"),1);var Kl={name:"nano",description:"Text editor",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=r[0];if(!s)return{stderr:"nano: missing file operand",exitCode:1};let i=de(e,s);Oe(n,i,"nano");let o=t.vfs.exists(i)?t.vfs.readFile(i):"",a=ql.posix.basename(i)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:i,tempPath:c,initialContent:o},exitCode:0}}};var Dn=require("node:fs"),Ot=zt(require("node:os"),1),Jl=zt(require("node:path"),1);function jp(n){let t=Math.max(1,Math.floor(n/60)),e=Math.floor(t/1440),r=Math.floor(t%1440/60),s=t%60,i=[];return e>0&&i.push(`${e} day${e>1?"s":""}`),r>0&&i.push(`${r} hour${r>1?"s":""}`),(s>0||i.length===0)&&i.push(`${s} min${s>1?"s":""}`),i.join(", ")}function Vl(n){return`\x1B[${n}m \x1B[0m`}function Xp(){let n=[40,41,42,43,44,45,46,47].map(Vl).join(""),t=[100,101,102,103,104,105,106,107].map(Vl).join("");return[n,t]}function zl(n,t,e){if(n.trim().length===0)return n;let r={r:255,g:255,b:255},s={r:168,g:85,b:247},i=e<=1?0:t/(e-1),o=Math.round(r.r+(s.r-r.r)*i),a=Math.round(r.g+(s.g-r.g)*i),c=Math.round(r.b+(s.b-r.b)*i);return`\x1B[38;2;${o};${a};${c}m${n}\x1B[0m`}function Jp(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?Gl(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return Gl(e)+r}function Gl(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},s={r:168,g:85,b:247},i="";for(let o=0;o<e.length;o+=1){let a=e.length<=1?0:o/(e.length-1),c=Math.round(r.r+(s.r-r.r)*a),l=Math.round(r.g+(s.g-r.g)*a),f=Math.round(r.b+(s.b-r.b)*a);i+=`\x1B[38;2;${c};${l};${f}m${e[o]}\x1B[0m`}return i}function Yl(n){return Math.max(0,Math.round(n/(1024*1024)))}function jl(){try{let n=(0,Dn.readFileSync)("/etc/os-release","utf8");for(let t of n.split(`
131
+ `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function Xl(n){try{let t=(0,Dn.readFileSync)(n,"utf8").split(`
132
+ `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function Zp(n){let t=Xl("/sys/devices/virtual/dmi/id/sys_vendor"),e=Xl("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function eg(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if((0,Dn.existsSync)(t))try{return(0,Dn.readFileSync)(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function tg(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if((0,Dn.existsSync)(t))try{return(0,Dn.readdirSync)(t,{withFileTypes:!0}).filter(s=>s.isDirectory()).length}catch{}}function ng(){let n=eg(),t=tg();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function rg(){let n=Ot.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 ig(n){return!n||n.trim().length===0?"unknown":Jl.posix.basename(n.trim())}function sg(n){let t=Ot.totalmem(),e=Ot.freemem(),r=Math.max(0,t-e),s=n.shellProps,i=process.uptime();return n.uptimeSeconds===void 0&&(n.uptimeSeconds=Math.round(i)),{user:n.user,host:n.host,osName:s?.os??n.osName??`${jl()??Ot.type()} ${Ot.arch()}`,kernel:s?.kernel??n.kernel??Ot.release(),uptimeSeconds:n.uptimeSeconds??Ot.uptime(),packages:n.packages??ng(),shell:ig(n.shell),shellProps:n.shellProps??{kernel:n.kernel??Ot.release(),os:n.osName??`${jl()??Ot.type()} ${Ot.arch()}`,arch:Ot.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??rg(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??Yl(r),memoryTotalMiB:n.memoryTotalMiB??Yl(t)}}function Zl(n){let t=sg(n),e=jp(t.uptimeSeconds),r=Xp(),s=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],i=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${Zp(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`,"",r[0],r[1]],o=Math.max(s.length,i.length),a=[];for(let c=0;c<o;c+=1){let l=s[c]??"",f=i[c]??"";if(f.length>0){let u=zl(l.padEnd(31," "),c,s.length),h=Jp(f);a.push(`${u} ${h}`);continue}a.push(zl(l,c,s.length))}return a.join(`
133
+ `)}var ef={name:"neofetch",description:"System info display",category:"system",params:["[--off]"],run:({args:n,authUser:t,hostname:e,shell:r,env:s})=>r.packageManager.isInstalled("neofetch")?se(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:se(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:Zl({user:t,host:e,shell:s.vars.SHELL,shellProps:r.properties,terminal:s.vars.TERM,uptimeSeconds:Math.floor((Date.now()-r.startTime)/1e3),packages:`${r.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}:{stderr:`bash: neofetch: command not found
126
134
  Hint: install it with: apt install neofetch
127
- `,exitCode:127}};var go=Kt(require("node:vm"),1);var ts="v18.19.0",jf={node:ts,npm:"9.2.0",v8:"10.2.154.26-node.22"};function Hp(n,t){let e={version:ts,versions:jf,platform:"linux",arch:"x64",env:{NODE_ENV:"production",HOME:"/root",PATH:"/usr/local/bin:/usr/bin:/bin"},argv:["node"],stdout:{write:i=>(n.push(i),!0)},stderr:{write:i=>(t.push(i),!0)},exit:(i=0)=>{throw new ns(i)},cwd:()=>"/root",hrtime:()=>[0,0]},r={log:(...i)=>n.push(i.map(Sn).join(" ")),error:(...i)=>t.push(i.map(Sn).join(" ")),warn:(...i)=>t.push(i.map(Sn).join(" ")),info:(...i)=>n.push(i.map(Sn).join(" ")),dir:i=>n.push(Sn(i))},s=i=>{switch(i){case"path":return{join:(...o)=>o.join("/").replace(/\/+/g,"/"),resolve:(...o)=>`/${o.join("/").replace(/^\/+/,"")}`,dirname:o=>o.split("/").slice(0,-1).join("/")||"/",basename:o=>o.split("/").pop()??"",extname:o=>{let a=o.split("/").pop()??"",c=a.lastIndexOf(".");return c>0?a.slice(c):""},sep:"/",delimiter:":"};case"os":return{platform:()=>"linux",arch:()=>"x64",type:()=>"Linux",hostname:()=>"fortune-vm",homedir:()=>"/root",tmpdir:()=>"/tmp",EOL:`
128
- `};case"util":return{format:(...o)=>o.map(Sn).join(" "),inspect:o=>Sn(o)};case"fs":case"fs/promises":throw new Error(`Cannot require '${i}': filesystem access not available in virtual runtime`);case"child_process":case"net":case"http":case"https":throw new Error(`Cannot require '${i}': not available in virtual runtime`);default:throw new Error(`Cannot find module '${i}'`)}};return s.resolve=i=>{throw new Error(`Cannot resolve '${i}'`)},s.cache={},s.extensions={},go.default.createContext({console:r,process:e,require:s,Math,JSON,Object,Array,String,Number,Boolean,Symbol,Date,RegExp,Error,TypeError,RangeError,SyntaxError,Promise,Map,Set,WeakMap,WeakSet,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI,setTimeout:()=>{},clearTimeout:()=>{},setInterval:()=>{},clearInterval:()=>{},queueMicrotask:()=>{},globalThis:void 0,undefined:void 0,Infinity:1/0,NaN:NaN})}var ns=class{constructor(t){this.code=t}code};function Sn(n){if(n===null)return"null";if(n===void 0)return"undefined";if(typeof n=="string")return n;if(typeof n=="function")return`[Function: ${n.name||"(anonymous)"}]`;if(Array.isArray(n))return`[ ${n.map(Sn).join(", ")} ]`;if(n instanceof Error)return`${n.name}: ${n.message}`;if(typeof n=="object")try{return`{ ${Object.entries(n).map(([e,r])=>`${e}: ${Sn(r)}`).join(", ")} }`}catch{return"[Object]"}return String(n)}function rs(n){let t=[],e=[],r=Hp(t,e),s=0;try{let i=go.default.runInContext(n,r,{timeout:5e3});i!==void 0&&t.length===0&&t.push(Sn(i))}catch(i){i instanceof ns?s=i.code:i instanceof Error?(e.push(`${i.name}: ${i.message}`),s=1):(e.push(String(i)),s=1)}return{stdout:t.length?`${t.join(`
135
+ `,exitCode:127}};var So=zt(require("node:vm"),1);var as="v18.19.0",tf={node:as,npm:"9.2.0",v8:"10.2.154.26-node.22"};function og(n,t){let e={version:as,versions:tf,platform:"linux",arch:"x64",env:{NODE_ENV:"production",HOME:"/root",PATH:"/usr/local/bin:/usr/bin:/bin"},argv:["node"],stdout:{write:i=>(n.push(i),!0)},stderr:{write:i=>(t.push(i),!0)},exit:(i=0)=>{throw new cs(i)},cwd:()=>"/root",hrtime:()=>[0,0]},r={log:(...i)=>n.push(i.map(kn).join(" ")),error:(...i)=>t.push(i.map(kn).join(" ")),warn:(...i)=>t.push(i.map(kn).join(" ")),info:(...i)=>n.push(i.map(kn).join(" ")),dir:i=>n.push(kn(i))},s=i=>{switch(i){case"path":return{join:(...o)=>o.join("/").replace(/\/+/g,"/"),resolve:(...o)=>`/${o.join("/").replace(/^\/+/,"")}`,dirname:o=>o.split("/").slice(0,-1).join("/")||"/",basename:o=>o.split("/").pop()??"",extname:o=>{let a=o.split("/").pop()??"",c=a.lastIndexOf(".");return c>0?a.slice(c):""},sep:"/",delimiter:":"};case"os":return{platform:()=>"linux",arch:()=>"x64",type:()=>"Linux",hostname:()=>"fortune-vm",homedir:()=>"/root",tmpdir:()=>"/tmp",EOL:`
136
+ `};case"util":return{format:(...o)=>o.map(kn).join(" "),inspect:o=>kn(o)};case"fs":case"fs/promises":throw new Error(`Cannot require '${i}': filesystem access not available in virtual runtime`);case"child_process":case"net":case"http":case"https":throw new Error(`Cannot require '${i}': not available in virtual runtime`);default:throw new Error(`Cannot find module '${i}'`)}};return s.resolve=i=>{throw new Error(`Cannot resolve '${i}'`)},s.cache={},s.extensions={},So.default.createContext({console:r,process:e,require:s,Math,JSON,Object,Array,String,Number,Boolean,Symbol,Date,RegExp,Error,TypeError,RangeError,SyntaxError,Promise,Map,Set,WeakMap,WeakSet,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI,setTimeout:()=>{},clearTimeout:()=>{},setInterval:()=>{},clearInterval:()=>{},queueMicrotask:()=>{},globalThis:void 0,undefined:void 0,Infinity:1/0,NaN:NaN})}var cs=class{constructor(t){this.code=t}code};function kn(n){if(n===null)return"null";if(n===void 0)return"undefined";if(typeof n=="string")return n;if(typeof n=="function")return`[Function: ${n.name||"(anonymous)"}]`;if(Array.isArray(n))return`[ ${n.map(kn).join(", ")} ]`;if(n instanceof Error)return`${n.name}: ${n.message}`;if(typeof n=="object")try{return`{ ${Object.entries(n).map(([e,r])=>`${e}: ${kn(r)}`).join(", ")} }`}catch{return"[Object]"}return String(n)}function ls(n){let t=[],e=[],r=og(t,e),s=0;try{let i=So.default.runInContext(n,r,{timeout:5e3});i!==void 0&&t.length===0&&t.push(kn(i))}catch(i){i instanceof cs?s=i.code:i instanceof Error?(e.push(`${i.name}: ${i.message}`),s=1):(e.push(String(i)),s=1)}return{stdout:t.length?`${t.join(`
129
137
  `)}
130
138
  `:"",stderr:e.length?`${e.join(`
131
139
  `)}
132
- `:"",exitCode:s}}function Qp(n){let t=n.trim();return!t.includes(`
133
- `)&&!t.startsWith("const ")&&!t.startsWith("let ")&&!t.startsWith("var ")&&!t.startsWith("function ")&&!t.startsWith("class ")&&!t.startsWith("if ")&&!t.startsWith("for ")&&!t.startsWith("while ")&&!t.startsWith("import ")&&!t.startsWith("//")?rs(t):rs(`(async () => { ${n} })()`)}var Xf={name:"node",description:"JavaScript runtime (virtual)",category:"system",params:["[--version] [-e <expr>] [-p <expr>] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("nodejs"))return{stderr:`bash: node: command not found
140
+ `:"",exitCode:s}}function ag(n){let t=n.trim();return!t.includes(`
141
+ `)&&!t.startsWith("const ")&&!t.startsWith("let ")&&!t.startsWith("var ")&&!t.startsWith("function ")&&!t.startsWith("class ")&&!t.startsWith("if ")&&!t.startsWith("for ")&&!t.startsWith("while ")&&!t.startsWith("import ")&&!t.startsWith("//")?ls(t):ls(`(async () => { ${n} })()`)}var nf={name:"node",description:"JavaScript runtime (virtual)",category:"system",params:["[--version] [-e <expr>] [-p <expr>] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("nodejs"))return{stderr:`bash: node: command not found
134
142
  Hint: install it with: apt install nodejs
135
- `,exitCode:127};if(se(n,["--version","-v"]))return{stdout:`${ts}
136
- `,exitCode:0};if(se(n,["--versions"]))return{stdout:`${JSON.stringify(jf,null,2)}
143
+ `,exitCode:127};if(se(n,["--version","-v"]))return{stdout:`${as}
144
+ `,exitCode:0};if(se(n,["--versions"]))return{stdout:`${JSON.stringify(tf,null,2)}
137
145
  `,exitCode:0};let r=n.findIndex(o=>o==="-e"||o==="--eval");if(r!==-1){let o=n[r+1];if(!o)return{stderr:`node: -e requires an argument
138
- `,exitCode:1};let{stdout:a,stderr:c,exitCode:f}=rs(o);return{stdout:a||void 0,stderr:c||void 0,exitCode:f}}let s=n.findIndex(o=>o==="-p"||o==="--print");if(s!==-1){let o=n[s+1];if(!o)return{stderr:`node: -p requires an argument
139
- `,exitCode:1};let{stdout:a,stderr:c,exitCode:f}=rs(o);return{stdout:a||(f===0?`
140
- `:void 0),stderr:c||void 0,exitCode:f}}let i=n.find(o=>!o.startsWith("-"));if(i){let o=le(e,i);if(!t.vfs.exists(o))return{stderr:`node: cannot open file '${i}': No such file or directory
141
- `,exitCode:1};let a=t.vfs.readFile(o),{stdout:c,stderr:f,exitCode:l}=Qp(a);return{stdout:c||void 0,stderr:f||void 0,exitCode:l}}return{stdout:[`Welcome to Node.js ${ts}.`,'Type ".exit" to exit the REPL.',"> "].join(`
142
- `),exitCode:0}}};var is="9.2.0",Wp="18.19.0",Jf={name:"npm",description:"Node.js package manager (virtual)",category:"system",params:["<command> [args]"],run:({args:n,shell:t})=>{if(!t.packageManager.isInstalled("npm"))return{stderr:`bash: npm: command not found
146
+ `,exitCode:1};let{stdout:a,stderr:c,exitCode:l}=ls(o);return{stdout:a||void 0,stderr:c||void 0,exitCode:l}}let s=n.findIndex(o=>o==="-p"||o==="--print");if(s!==-1){let o=n[s+1];if(!o)return{stderr:`node: -p requires an argument
147
+ `,exitCode:1};let{stdout:a,stderr:c,exitCode:l}=ls(o);return{stdout:a||(l===0?`
148
+ `:void 0),stderr:c||void 0,exitCode:l}}let i=n.find(o=>!o.startsWith("-"));if(i){let o=de(e,i);if(!t.vfs.exists(o))return{stderr:`node: cannot open file '${i}': No such file or directory
149
+ `,exitCode:1};let a=t.vfs.readFile(o),{stdout:c,stderr:l,exitCode:f}=ag(a);return{stdout:c||void 0,stderr:l||void 0,exitCode:f}}return{stdout:[`Welcome to Node.js ${as}.`,'Type ".exit" to exit the REPL.',"> "].join(`
150
+ `),exitCode:0}}};var fs="9.2.0",cg="18.19.0",rf={name:"npm",description:"Node.js package manager (virtual)",category:"system",params:["<command> [args]"],run:({args:n,shell:t})=>{if(!t.packageManager.isInstalled("npm"))return{stderr:`bash: npm: command not found
143
151
  Hint: install it with: apt install npm
144
- `,exitCode:127};if(se(n,["--version","-v"]))return{stdout:`${is}
145
- `,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${is}', node: '${Wp}', v8: '10.2.154.26' }
152
+ `,exitCode:127};if(se(n,["--version","-v"]))return{stdout:`${fs}
153
+ `,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${fs}', node: '${cg}', v8: '10.2.154.26' }
146
154
  `,exitCode:0};case"install":case"i":case"add":return{stderr:`npm warn: package installation is not available in the virtual runtime.
147
155
  npm warn: This environment simulates npm CLI behaviour only.
148
156
  `,exitCode:1};case"run":case"exec":case"x":return{stderr:`npm error: script execution is not available in the virtual runtime.
149
157
  `,exitCode:1};case"init":return{stdout:`Wrote to /home/user/package.json
150
158
  `,exitCode:0};case"list":case"ls":return{stdout:`${e==="ls"||e==="list"?"virtual-env@1.0.0":""}
151
159
  \u2514\u2500\u2500 (empty)
152
- `,exitCode:0};case"help":case void 0:return{stdout:`${[`npm ${is}`,"","Usage: npm <command>","","Commands:"," install (not available in virtual runtime)"," run (not available in virtual runtime)"," exec (not available in virtual runtime)"," list List installed packages"," version Print versions"," --version Print npm version"].join(`
160
+ `,exitCode:0};case"help":case void 0:return{stdout:`${[`npm ${fs}`,"","Usage: npm <command>","","Commands:"," install (not available in virtual runtime)"," run (not available in virtual runtime)"," exec (not available in virtual runtime)"," list List installed packages"," version Print versions"," --version Print npm version"].join(`
153
161
  `)}
154
162
  `,exitCode:0};default:return{stderr:`npm error: unknown command: ${e}
155
- `,exitCode:1}}}},Zf={name:"npx",description:"Node.js package runner (virtual)",category:"system",params:["<package> [args]"],run:({args:n,shell:t})=>t.packageManager.isInstalled("npm")?se(n,["--version"])?{stdout:`${is}
163
+ `,exitCode:1}}}},sf={name:"npx",description:"Node.js package runner (virtual)",category:"system",params:["<package> [args]"],run:({args:n,shell:t})=>t.packageManager.isInstalled("npm")?se(n,["--version"])?{stdout:`${fs}
156
164
  `,exitCode:0}:{stderr:`npx: package execution is not available in the virtual runtime.
157
165
  `,exitCode:1}:{stderr:`bash: npx: command not found
158
166
  Hint: install it with: apt install npm
159
- `,exitCode:127}};var el={name:"passwd",description:"Change user password",category:"users",params:["[username]"],run:async({authUser:n,args:t,shell:e,stdin:r})=>{let s=t[0]??n;if(n!=="root"&&n!==s)return{stderr:"passwd: permission denied",exitCode:1};if(!e.users.listUsers().includes(s))return{stderr:`passwd: user '${s}' does not exist`,exitCode:1};if(r!==void 0&&r.trim().length>0){let i=r.trim().split(`
167
+ `,exitCode:127}};var of={name:"passwd",description:"Change user password",category:"users",params:["[username]"],run:async({authUser:n,args:t,shell:e,stdin:r})=>{let s=t[0]??n;if(n!=="root"&&n!==s)return{stderr:"passwd: permission denied",exitCode:1};if(!e.users.listUsers().includes(s))return{stderr:`passwd: user '${s}' does not exist`,exitCode:1};if(r!==void 0&&r.trim().length>0){let i=r.trim().split(`
160
168
  `)[0];return await e.users.setPassword(s,i),{stdout:`passwd: password updated successfully
161
- `,exitCode:0}}return{passwordChallenge:{prompt:"New password: ",confirmPrompt:"Retype new password: ",action:"passwd",targetUsername:s},exitCode:0}}};var tl={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:n})=>{let{flagsWithValues:t,positionals:e}=Yt(n,{flagsWithValue:["-c","-i","-W"]}),r=e[0]??"localhost",s=t.get("-c"),i=s?Math.max(1,parseInt(s,10)||4):4,o=[`PING ${r}: 56 data bytes`];for(let a=0;a<i;a++){let c=(Math.random()*10+1).toFixed(3);o.push(`64 bytes from ${r}: icmp_seq=${a} ttl=64 time=${c} ms`)}return o.push(`--- ${r} ping statistics ---`),o.push(`${i} packets transmitted, ${i} received, 0% packet loss`),{stdout:o.join(`
162
- `),exitCode:0}}};function qp(n,t){let e=0,r="",s=0;for(;s<n.length;){if(n[s]==="\\"&&s+1<n.length)switch(n[s+1]){case"n":r+=`
163
- `,s+=2;continue;case"t":r+=" ",s+=2;continue;case"r":r+="\r",s+=2;continue;case"\\":r+="\\",s+=2;continue;case"a":r+="\x07",s+=2;continue;case"b":r+="\b",s+=2;continue;case"f":r+="\f",s+=2;continue;case"v":r+="\v",s+=2;continue;default:r+=n[s],s++;continue}if(n[s]==="%"&&s+1<n.length){let i=s+1,o=!1;n[i]==="-"&&(o=!0,i++);let a=!1;n[i]==="0"&&(a=!0,i++);let c=0;for(;i<n.length&&/\d/.test(n[i]);)c=c*10+parseInt(n[i],10),i++;let f=-1;if(n[i]===".")for(i++,f=0;i<n.length&&/\d/.test(n[i]);)f=f*10+parseInt(n[i],10),i++;let l=n[i],u=t[e++]??"",h=(p,_=" ")=>{if(c<=0||p.length>=c)return p;let E=_.repeat(c-p.length);return o?p+E:E+p};switch(l){case"s":{let p=String(u);f>=0&&(p=p.slice(0,f)),r+=h(p);break}case"d":case"i":r+=h(String(parseInt(u,10)||0),a?"0":" ");break;case"f":{let p=f>=0?f:6;r+=h((parseFloat(u)||0).toFixed(p));break}case"o":r+=h((parseInt(u,10)||0).toString(8),a?"0":" ");break;case"x":r+=h((parseInt(u,10)||0).toString(16),a?"0":" ");break;case"X":r+=h((parseInt(u,10)||0).toString(16).toUpperCase(),a?"0":" ");break;case"%":r+="%",e--;break;default:r+=n[s],s++;continue}s=i+1;continue}r+=n[s],s++}return r}var nl={name:"printf",description:"Format and print data",category:"shell",params:["<format> [args...]"],run:({args:n})=>{let t=n[0];return t?{stdout:qp(t,n.slice(1)),exitCode:0}:{stderr:"printf: missing format string",exitCode:1}}};var rl={name:"ps",description:"Report process status",category:"system",params:["[-a] [-u] [-x] [aux]"],run:({authUser:n,shell:t,args:e})=>{let r=t.users.listActiveSessions(),s=se(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),i=se(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(s){let l=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],u=1e3;for(let h of r){let p=h.username.padEnd(10).slice(0,10),_=(Math.random()*.5).toFixed(1),E=Math.floor(Math.random()*2e4+5e3),b=Math.floor(Math.random()*5e3+1e3);l.push(`${p} ${String(u).padStart(6)} 0.0 ${_.padStart(4)} ${String(E).padStart(6)} ${String(b).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(`
164
- `),exitCode:0}}let a=[" PID TTY TIME CMD"],c=1e3;for(let f of r)!i&&f.username!==n||(a.push(`${String(c).padStart(5)} ${f.tty.padEnd(12)} 00:00:00 ${f.username===n?"bash":`bash (${f.username})`}`),c++);return a.push(`${String(c).padStart(5)} pts/0 00:00:00 ps`),{stdout:a.join(`
165
- `),exitCode:0}}};var il={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})};var Kp="Python 3.11.2";var ss="3.11.2 (default, Mar 13 2023, 12:18:29) [GCC 12.2.0]",G={__pytype__:"none"};function At(n=[]){return{__pytype__:"dict",data:new Map(n)}}function mo(n,t,e=1){return{__pytype__:"range",start:n,stop:t,step:e}}function pt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="dict"}function Cr(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="range"}function wn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="func"}function Ao(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="class"}function ci(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="instance"}function Dn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="none"}function Rt(n){return n===null||Dn(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?`'${n.replace(/'/g,"\\'")}'`:Array.isArray(n)?`[${n.map(Rt).join(", ")}]`:pt(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Rt(e)}`).join(", ")}}`:Cr(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:wn(n)?`<function ${n.name} at 0x...>`:Ao(n)?`<class '${n.name}'>`:ci(n)?`<${n.cls.name} object at 0x...>`:String(n)}function Be(n){return n===null||Dn(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?n:Array.isArray(n)?`[${n.map(Rt).join(", ")}]`:pt(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Rt(e)}`).join(", ")}}`:Cr(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:Rt(n)}function on(n){return n===null||Dn(n)?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"||Array.isArray(n)?n.length>0:pt(n)?n.data.size>0:Cr(n)?ol(n)>0:!0}function ol(n){if(n.step===0)return 0;let t=Math.ceil((n.stop-n.start)/n.step);return Math.max(0,t)}function Vp(n){let t=[];for(let e=n.start;(n.step>0?e<n.stop:e>n.stop)&&(t.push(e),!(t.length>1e4));e+=n.step);return t}function Bt(n){if(Array.isArray(n))return n;if(typeof n=="string")return[...n];if(Cr(n))return Vp(n);if(pt(n))return[...n.data.keys()];throw new mt("TypeError",`'${or(n)}' object is not iterable`)}function or(n){return n===null||Dn(n)?"NoneType":typeof n=="boolean"?"bool":typeof n=="number"?Number.isInteger(n)?"int":"float":typeof n=="string"?"str":Array.isArray(n)?"list":pt(n)?"dict":Cr(n)?"range":wn(n)?"function":Ao(n)?"type":ci(n)?n.cls.name:"object"}var mt=class{constructor(t,e){this.type=t;this.message=e}type;message;toString(){return`${this.type}: ${this.message}`}},Ir=class{constructor(t){this.value=t}value},fi=class{},li=class{},ui=class{constructor(t){this.code=t}code};function Gp(n){let t=new Map,e=At([["sep","/"],["linesep",`
166
- `],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??G:G,path:At([["join",G],["exists",G],["dirname",G],["basename",G]]),listdir:()=>[]},t.set("__builtins__",G),t.set("__name__","__main__"),t.set("__cwd__",n),t}function zp(n){let t=At([["sep","/"],["curdir","."]]),e=At([["sep","/"],["linesep",`
167
- `],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function Yp(){return At([["version",ss],["version_info",At([["major",3],["minor",11],["micro",2]].map(([n,t])=>[n,t]))],["platform","linux"],["executable","/usr/bin/python3"],["prefix","/usr"],["path",["/usr/lib/python3.11","/usr/lib/python3.11/lib-dynload"]],["argv",[""]],["maxsize",9007199254740991]])}function jp(){return At([["pi",Math.PI],["e",Math.E],["tau",Math.PI*2],["inf",1/0],["nan",NaN],["sqrt",G],["floor",G],["ceil",G],["log",G],["pow",G],["sin",G],["cos",G],["tan",G],["fabs",G],["factorial",G]])}function Xp(){return At([["dumps",G],["loads",G]])}function Jp(){return At([["match",G],["search",G],["findall",G],["sub",G],["split",G],["compile",G]])}var sl={os:zp,sys:()=>Yp(),math:()=>jp(),json:()=>Xp(),re:()=>Jp(),random:()=>At([["random",G],["randint",G],["choice",G],["shuffle",G]]),time:()=>At([["time",G],["sleep",G],["ctime",G]]),datetime:()=>At([["datetime",G],["date",G],["timedelta",G]]),collections:()=>At([["Counter",G],["defaultdict",G],["OrderedDict",G]]),itertools:()=>At([["chain",G],["product",G],["combinations",G],["permutations",G]]),functools:()=>At([["reduce",G],["partial",G],["lru_cache",G]]),string:()=>At([["ascii_letters","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"],["digits","0123456789"],["punctuation","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"]])},os=class{constructor(t){this.cwd=t}cwd;output=[];stderr=[];modules=new Map;getOutput(){return this.output.join(`
169
+ `,exitCode:0}}return{passwordChallenge:{prompt:"New password: ",confirmPrompt:"Retype new password: ",action:"passwd",targetUsername:s},exitCode:0}}};var af={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:n})=>{let{flagsWithValues:t,positionals:e}=Xt(n,{flagsWithValue:["-c","-i","-W"]}),r=e[0]??"localhost",s=t.get("-c"),i=s?Math.max(1,parseInt(s,10)||4):4,o=[`PING ${r}: 56 data bytes`];for(let a=0;a<i;a++){let c=(Math.random()*10+1).toFixed(3);o.push(`64 bytes from ${r}: icmp_seq=${a} ttl=64 time=${c} ms`)}return o.push(`--- ${r} ping statistics ---`),o.push(`${i} packets transmitted, ${i} received, 0% packet loss`),{stdout:o.join(`
170
+ `),exitCode:0}}};function lg(n,t){let e=0,r="",s=0;for(;s<n.length;){if(n[s]==="\\"&&s+1<n.length)switch(n[s+1]){case"n":r+=`
171
+ `,s+=2;continue;case"t":r+=" ",s+=2;continue;case"r":r+="\r",s+=2;continue;case"\\":r+="\\",s+=2;continue;case"a":r+="\x07",s+=2;continue;case"b":r+="\b",s+=2;continue;case"f":r+="\f",s+=2;continue;case"v":r+="\v",s+=2;continue;default:r+=n[s],s++;continue}if(n[s]==="%"&&s+1<n.length){let i=s+1,o=!1;n[i]==="-"&&(o=!0,i++);let a=!1;n[i]==="0"&&(a=!0,i++);let c=0;for(;i<n.length&&/\d/.test(n[i]);)c=c*10+parseInt(n[i],10),i++;let l=-1;if(n[i]===".")for(i++,l=0;i<n.length&&/\d/.test(n[i]);)l=l*10+parseInt(n[i],10),i++;let f=n[i],u=t[e++]??"",h=(p,A=" ")=>{if(c<=0||p.length>=c)return p;let E=A.repeat(c-p.length);return o?p+E:E+p};switch(f){case"s":{let p=String(u);l>=0&&(p=p.slice(0,l)),r+=h(p);break}case"d":case"i":r+=h(String(parseInt(u,10)||0),a?"0":" ");break;case"f":{let p=l>=0?l:6;r+=h((parseFloat(u)||0).toFixed(p));break}case"o":r+=h((parseInt(u,10)||0).toString(8),a?"0":" ");break;case"x":r+=h((parseInt(u,10)||0).toString(16),a?"0":" ");break;case"X":r+=h((parseInt(u,10)||0).toString(16).toUpperCase(),a?"0":" ");break;case"%":r+="%",e--;break;default:r+=n[s],s++;continue}s=i+1;continue}r+=n[s],s++}return r}var cf={name:"printf",description:"Format and print data",category:"shell",params:["<format> [args...]"],run:({args:n})=>{let t=n[0];return t?{stdout:lg(t,n.slice(1)),exitCode:0}:{stderr:"printf: missing format string",exitCode:1}}};var lf={name:"ps",description:"Report process status",category:"system",params:["[-a] [-u] [-x] [aux]"],run:({authUser:n,shell:t,args:e})=>{let r=t.users.listActiveSessions(),s=se(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),i=se(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(s){let f=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],u=1e3;for(let h of r){let p=h.username.padEnd(10).slice(0,10),A=(Math.random()*.5).toFixed(1),E=Math.floor(Math.random()*2e4+5e3),S=Math.floor(Math.random()*5e3+1e3);f.push(`${p} ${String(u).padStart(6)} 0.0 ${A.padStart(4)} ${String(E).padStart(6)} ${String(S).padStart(5)} ${h.tty.padEnd(8)} Ss 00:00 0:00 bash`),u++}return f.push(`root ${String(u).padStart(6)} 0.0 0.0 0 0 ? S 00:00 0:00 ps`),{stdout:f.join(`
172
+ `),exitCode:0}}let a=[" PID TTY TIME CMD"],c=1e3;for(let l of r)!i&&l.username!==n||(a.push(`${String(c).padStart(5)} ${l.tty.padEnd(12)} 00:00:00 ${l.username===n?"bash":`bash (${l.username})`}`),c++);return a.push(`${String(c).padStart(5)} pts/0 00:00:00 ps`),{stdout:a.join(`
173
+ `),exitCode:0}}};var ff={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})};var fg="Python 3.11.2";var us="3.11.2 (default, Mar 13 2023, 12:18:29) [GCC 12.2.0]",z={__pytype__:"none"};function Et(n=[]){return{__pytype__:"dict",data:new Map(n)}}function xo(n,t,e=1){return{__pytype__:"range",start:n,stop:t,step:e}}function mt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="dict"}function Br(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="range"}function vn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="func"}function wo(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="class"}function ui(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="instance"}function Un(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="none"}function Pt(n){return n===null||Un(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?`'${n.replace(/'/g,"\\'")}'`:Array.isArray(n)?`[${n.map(Pt).join(", ")}]`:mt(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Pt(e)}`).join(", ")}}`:Br(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:vn(n)?`<function ${n.name} at 0x...>`:wo(n)?`<class '${n.name}'>`:ui(n)?`<${n.cls.name} object at 0x...>`:String(n)}function Re(n){return n===null||Un(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?n:Array.isArray(n)?`[${n.map(Pt).join(", ")}]`:mt(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Pt(e)}`).join(", ")}}`:Br(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:Pt(n)}function ln(n){return n===null||Un(n)?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"||Array.isArray(n)?n.length>0:mt(n)?n.data.size>0:Br(n)?df(n)>0:!0}function df(n){if(n.step===0)return 0;let t=Math.ceil((n.stop-n.start)/n.step);return Math.max(0,t)}function ug(n){let t=[];for(let e=n.start;(n.step>0?e<n.stop:e>n.stop)&&(t.push(e),!(t.length>1e4));e+=n.step);return t}function Nt(n){if(Array.isArray(n))return n;if(typeof n=="string")return[...n];if(Br(n))return ug(n);if(mt(n))return[...n.data.keys()];throw new yt("TypeError",`'${lr(n)}' object is not iterable`)}function lr(n){return n===null||Un(n)?"NoneType":typeof n=="boolean"?"bool":typeof n=="number"?Number.isInteger(n)?"int":"float":typeof n=="string"?"str":Array.isArray(n)?"list":mt(n)?"dict":Br(n)?"range":vn(n)?"function":wo(n)?"type":ui(n)?n.cls.name:"object"}var yt=class{constructor(t,e){this.type=t;this.message=e}type;message;toString(){return`${this.type}: ${this.message}`}},vr=class{constructor(t){this.value=t}value},di=class{},hi=class{},pi=class{constructor(t){this.code=t}code};function dg(n){let t=new Map,e=Et([["sep","/"],["linesep",`
174
+ `],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??z:z,path:Et([["join",z],["exists",z],["dirname",z],["basename",z]]),listdir:()=>[]},t.set("__builtins__",z),t.set("__name__","__main__"),t.set("__cwd__",n),t}function hg(n){let t=Et([["sep","/"],["curdir","."]]),e=Et([["sep","/"],["linesep",`
175
+ `],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function pg(){return Et([["version",us],["version_info",Et([["major",3],["minor",11],["micro",2]].map(([n,t])=>[n,t]))],["platform","linux"],["executable","/usr/bin/python3"],["prefix","/usr"],["path",["/usr/lib/python3.11","/usr/lib/python3.11/lib-dynload"]],["argv",[""]],["maxsize",9007199254740991]])}function gg(){return Et([["pi",Math.PI],["e",Math.E],["tau",Math.PI*2],["inf",1/0],["nan",NaN],["sqrt",z],["floor",z],["ceil",z],["log",z],["pow",z],["sin",z],["cos",z],["tan",z],["fabs",z],["factorial",z]])}function mg(){return Et([["dumps",z],["loads",z]])}function Ag(){return Et([["match",z],["search",z],["findall",z],["sub",z],["split",z],["compile",z]])}var uf={os:hg,sys:()=>pg(),math:()=>gg(),json:()=>mg(),re:()=>Ag(),random:()=>Et([["random",z],["randint",z],["choice",z],["shuffle",z]]),time:()=>Et([["time",z],["sleep",z],["ctime",z]]),datetime:()=>Et([["datetime",z],["date",z],["timedelta",z]]),collections:()=>Et([["Counter",z],["defaultdict",z],["OrderedDict",z]]),itertools:()=>Et([["chain",z],["product",z],["combinations",z],["permutations",z]]),functools:()=>Et([["reduce",z],["partial",z],["lru_cache",z]]),string:()=>Et([["ascii_letters","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"],["digits","0123456789"],["punctuation","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"]])},ds=class{constructor(t){this.cwd=t}cwd;output=[];stderr=[];modules=new Map;getOutput(){return this.output.join(`
168
176
  `)+(this.output.length?`
169
177
  `:"")}getStderr(){return this.stderr.join(`
170
178
  `)+(this.stderr.length?`
171
- `:"")}splitArgs(t){let e=[],r=0,s="",i=!1,o="";for(let a=0;a<t.length;a++){let c=t[a];i?(s+=c,c===o&&t[a-1]!=="\\"&&(i=!1)):c==='"'||c==="'"?(i=!0,o=c,s+=c):"([{".includes(c)?(r++,s+=c):")]}".includes(c)?(r--,s+=c):c===","&&r===0?(e.push(s.trim()),s=""):s+=c}return s.trim()&&e.push(s.trim()),e}pyEval(t,e){if(t=t.trim(),!t||t==="None")return G;if(t==="True")return!0;if(t==="False")return!1;if(t==="...")return G;if(/^-?\d+$/.test(t))return parseInt(t,10);if(/^-?\d+\.\d*$/.test(t))return parseFloat(t);if(/^0x[0-9a-fA-F]+$/.test(t))return parseInt(t,16);if(/^0o[0-7]+$/.test(t))return parseInt(t.slice(2),8);if(/^('''[\s\S]*'''|"""[\s\S]*""")$/.test(t))return t.slice(3,-3);if(/^(['"])(.*)\1$/s.test(t))return t.slice(1,-1).replace(/\\n/g,`
172
- `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');let r=t.match(/^f(['"])([\s\S]*)\1$/);if(r){let f=r[2];return f=f.replace(/\{([^{}]+)\}/g,(l,u)=>{try{return Be(this.pyEval(u.trim(),e))}catch{return`{${u}}`}}),f}let s=t.match(/^b(['"])(.*)\1$/s);if(s)return s[2];if(t.startsWith("[")&&t.endsWith("]")){let f=t.slice(1,-1).trim();if(!f)return[];let l=f.match(/^(.+?)\s+for\s+(\w+)\s+in\s+(.+?)(?:\s+if\s+(.+))?$/);if(l){let[,u,h,p,_]=l,E=Bt(this.pyEval(p.trim(),e)),b=[];for(let v of E){let U=new Map(e);U.set(h,v),!(_&&!on(this.pyEval(_,U)))&&b.push(this.pyEval(u.trim(),U))}return b}return this.splitArgs(f).map(u=>this.pyEval(u,e))}if(t.startsWith("(")&&t.endsWith(")")){let f=t.slice(1,-1).trim();if(!f)return[];let l=this.splitArgs(f);return l.length===1&&!f.endsWith(",")?this.pyEval(l[0],e):l.map(u=>this.pyEval(u,e))}if(t.startsWith("{")&&t.endsWith("}")){let f=t.slice(1,-1).trim();if(!f)return At();let l=At();for(let u of this.splitArgs(f)){let h=u.indexOf(":");if(h===-1)continue;let p=Be(this.pyEval(u.slice(0,h).trim(),e)),_=this.pyEval(u.slice(h+1).trim(),e);l.data.set(p,_)}return l}let i=t.match(/^not\s+(.+)$/);if(i)return!on(this.pyEval(i[1],e));let o=[["or"],["and"],["in","not in","is not","is","==","!=","<=",">=","<",">"],["+","-"],["**"],["*","//","/","%"]];for(let f of o){let l=this.tryBinaryOp(t,f,e);if(l!==void 0)return l}if(t.startsWith("-")){let f=this.pyEval(t.slice(1),e);if(typeof f=="number")return-f}if(process.env.PY_DEBUG&&console.error("eval:",JSON.stringify(t)),t.endsWith("]")&&!t.startsWith("[")){let f=this.findMatchingBracket(t,"[");if(f!==-1){let l=this.pyEval(t.slice(0,f),e),u=t.slice(f+1,-1);return this.subscript(l,u,e)}}let a=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/);if(a){let[,f,l]=a,u=(l?.trim()?this.splitArgs(l):[]).map(h=>this.pyEval(h,e));return this.callBuiltin(f,u,e)}let c=this.findDotAccess(t);if(c){let{objExpr:f,attr:l,callPart:u}=c,h=this.pyEval(f,e);if(u!==void 0){let p=u.slice(1,-1),_=p.trim()?this.splitArgs(p).map(E=>this.pyEval(E,e)):[];return this.callMethod(h,l,_,e)}return this.getAttr(h,l,e)}if(/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)){if(e.has(t))return e.get(t);throw new mt("NameError",`name '${t}' is not defined`)}if(/^[A-Za-z_][A-Za-z0-9_.]+$/.test(t)){let f=t.split("."),l=e.get(f[0])??(()=>{throw new mt("NameError",`name '${f[0]}' is not defined`)})();for(let u of f.slice(1))l=this.getAttr(l,u,e);return l}return G}findMatchingBracket(t,e){let r=e==="["?"]":e==="("?")":"}",s=0;for(let i=t.length-1;i>=0;i--)if(t[i]===r&&s++,t[i]===e&&(s--,s===0))return i;return-1}findDotAccess(t){let e=0,r=!1,s="";for(let i=t.length-1;i>0;i--){let o=t[i];if(r){o===s&&t[i-1]!=="\\"&&(r=!1);continue}if(o==='"'||o==="'"){r=!0,s=o;continue}if(")]}".includes(o)){e++;continue}if("([{".includes(o)){e--;continue}if(e!==0||o!==".")continue;let a=t.slice(0,i).trim(),f=t.slice(i+1).match(/^(\w+)(\([\s\S]*\))?$/);if(f&&!/^-?\d+$/.test(a))return{objExpr:a,attr:f[1],callPart:f[2]}}return null}tryBinaryOp(t,e,r){let s=0,i=!1,o="";for(let a=t.length-1;a>=0;a--){let c=t[a];if(i){c===o&&t[a-1]!=="\\"&&(i=!1);continue}if(c==='"'||c==="'"){i=!0,o=c;continue}if(")]}".includes(c)){s++;continue}if("([{".includes(c)){s--;continue}if(s===0){for(let f of e)if(t.slice(a,a+f.length)===f){if(f==="*"&&(t[a+1]==="*"||t[a-1]==="*"))continue;let l=t[a-1],u=t[a+f.length];if(/^[a-z]/.test(f)&&(l&&/\w/.test(l)||u&&/\w/.test(u)))continue;let p=t.slice(0,a).trim(),_=t.slice(a+f.length).trim();if(!p||!_)continue;return this.applyBinaryOp(f,p,_,r)}}}}applyBinaryOp(t,e,r,s){if(t==="and"){let a=this.pyEval(e,s);return on(a)?this.pyEval(r,s):a}if(t==="or"){let a=this.pyEval(e,s);return on(a)?a:this.pyEval(r,s)}let i=this.pyEval(e,s),o=this.pyEval(r,s);switch(t){case"+":return typeof i=="string"&&typeof o=="string"?i+o:Array.isArray(i)&&Array.isArray(o)?[...i,...o]:i+o;case"-":return i-o;case"*":if(typeof i=="string"&&typeof o=="number")return i.repeat(o);if(Array.isArray(i)&&typeof o=="number"){let a=[];for(let c=0;c<o;c++)a.push(...i);return a}return i*o;case"/":{if(o===0)throw new mt("ZeroDivisionError","division by zero");return i/o}case"//":{if(o===0)throw new mt("ZeroDivisionError","integer division or modulo by zero");return Math.floor(i/o)}case"%":{if(typeof i=="string")return this.pyStringFormat(i,Array.isArray(o)?o:[o]);if(o===0)throw new mt("ZeroDivisionError","integer division or modulo by zero");return i%o}case"**":return i**o;case"==":return Rt(i)===Rt(o)||i===o;case"!=":return Rt(i)!==Rt(o)&&i!==o;case"<":return i<o;case"<=":return i<=o;case">":return i>o;case">=":return i>=o;case"in":return this.pyIn(o,i);case"not in":return!this.pyIn(o,i);case"is":return i===o||Dn(i)&&Dn(o);case"is not":return!(i===o||Dn(i)&&Dn(o))}return G}pyIn(t,e){return typeof t=="string"?typeof e=="string"&&t.includes(e):Array.isArray(t)?t.some(r=>Rt(r)===Rt(e)):pt(t)?t.data.has(Be(e)):!1}subscript(t,e,r){if(e.includes(":")){let i=e.split(":").map(c=>c.trim()),o=i[0]?this.pyEval(i[0],r):void 0,a=i[1]?this.pyEval(i[1],r):void 0;return typeof t=="string"||Array.isArray(t)?t.slice(o,a):G}let s=this.pyEval(e,r);if(Array.isArray(t)){let i=s;return i<0&&(i=t.length+i),t[i]??G}if(typeof t=="string"){let i=s;return i<0&&(i=t.length+i),t[i]??G}if(pt(t))return t.data.get(Be(s))??G;throw new mt("TypeError",`'${or(t)}' is not subscriptable`)}getAttr(t,e,r){return pt(t)?t.data.has(e)?t.data.get(e):e==="path"&&t.path?t.path:G:ci(t)?t.attrs.get(e)??G:typeof t=="string"?{__class__:{__pytype__:"class",name:"str"}}[e]??G:G}callMethod(t,e,r,s){if(typeof t=="string")switch(e){case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();case"strip":return(r[0]?t.replace(new RegExp(`[${r[0]}]+`,"g"),""):t).trim();case"lstrip":return t.trimStart();case"rstrip":return t.trimEnd();case"split":return t.split(typeof r[0]=="string"?r[0]:/\s+/).filter((i,o)=>o>0||i!=="");case"splitlines":return t.split(`
173
- `);case"join":return Bt(r[0]??[]).map(Be).join(t);case"replace":return t.replaceAll(Be(r[0]??""),Be(r[1]??""));case"startswith":return t.startsWith(Be(r[0]??""));case"endswith":return t.endsWith(Be(r[0]??""));case"find":return t.indexOf(Be(r[0]??""));case"index":{let i=t.indexOf(Be(r[0]??""));if(i===-1)throw new mt("ValueError","substring not found");return i}case"count":return t.split(Be(r[0]??"")).length-1;case"format":return this.pyStringFormat(t,r);case"encode":return t;case"decode":return t;case"isdigit":return/^\d+$/.test(t);case"isalpha":return/^[a-zA-Z]+$/.test(t);case"isalnum":return/^[a-zA-Z0-9]+$/.test(t);case"isspace":return/^\s+$/.test(t);case"isupper":return t===t.toUpperCase()&&t!==t.toLowerCase();case"islower":return t===t.toLowerCase()&&t!==t.toUpperCase();case"center":{let i=r[0]??0,o=Be(r[1]??" ");return t.padStart(Math.floor((i+t.length)/2),o).padEnd(i,o)}case"ljust":return t.padEnd(r[0]??0,Be(r[1]??" "));case"rjust":return t.padStart(r[0]??0,Be(r[1]??" "));case"zfill":return t.padStart(r[0]??0,"0");case"title":return t.replace(/\b\w/g,i=>i.toUpperCase());case"capitalize":return t[0]?.toUpperCase()+t.slice(1).toLowerCase();case"swapcase":return[...t].map(i=>i===i.toUpperCase()?i.toLowerCase():i.toUpperCase()).join("")}if(Array.isArray(t))switch(e){case"append":return t.push(r[0]??G),G;case"extend":for(let i of Bt(r[0]??[]))t.push(i);return G;case"insert":return t.splice(r[0]??0,0,r[1]??G),G;case"pop":{let i=r[0]!==void 0?r[0]:-1,o=i<0?t.length+i:i;return t.splice(o,1)[0]??G}case"remove":{let i=t.findIndex(o=>Rt(o)===Rt(r[0]??G));return i!==-1&&t.splice(i,1),G}case"index":{let i=t.findIndex(o=>Rt(o)===Rt(r[0]??G));if(i===-1)throw new mt("ValueError","is not in list");return i}case"count":return t.filter(i=>Rt(i)===Rt(r[0]??G)).length;case"sort":return t.sort((i,o)=>typeof i=="number"&&typeof o=="number"?i-o:Be(i).localeCompare(Be(o))),G;case"reverse":return t.reverse(),G;case"copy":return[...t];case"clear":return t.splice(0),G}if(pt(t))switch(e){case"keys":return[...t.data.keys()];case"values":return[...t.data.values()];case"items":return[...t.data.entries()].map(([i,o])=>[i,o]);case"get":return t.data.get(Be(r[0]??""))??r[1]??G;case"update":{if(pt(r[0]??G))for(let[i,o]of r[0].data)t.data.set(i,o);return G}case"pop":{let i=Be(r[0]??""),o=t.data.get(i)??r[1]??G;return t.data.delete(i),o}case"clear":return t.data.clear(),G;case"copy":return At([...t.data.entries()]);case"setdefault":{let i=Be(r[0]??"");return t.data.has(i)||t.data.set(i,r[1]??G),t.data.get(i)??G}}if(pt(t)&&t.data.has("name")&&t.data.get("name")==="posix")switch(e){case"getcwd":return this.cwd;case"getenv":return typeof r[0]=="string"?process.env[r[0]]??r[1]??G:G;case"listdir":return[];case"path":return t}if(pt(t))switch(e){case"join":return r.map(Be).join("/").replace(/\/+/g,"/");case"exists":return!1;case"dirname":return Be(r[0]??"").split("/").slice(0,-1).join("/")||"/";case"basename":return Be(r[0]??"").split("/").pop()??"";case"abspath":return Be(r[0]??"");case"splitext":{let i=Be(r[0]??""),o=i.lastIndexOf(".");return o>0?[i.slice(0,o),i.slice(o)]:[i,""]}case"isfile":return!1;case"isdir":return!1}if(pt(t)&&t.data.has("version")&&t.data.get("version")===ss&&e==="exit")throw new ui(r[0]??0);if(pt(t)){let i={sqrt:Math.sqrt,floor:Math.floor,ceil:Math.ceil,fabs:Math.abs,log:Math.log,log2:Math.log2,log10:Math.log10,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,atan2:Math.atan2,pow:Math.pow,exp:Math.exp,hypot:Math.hypot};if(e in i){let o=i[e];return o(...r.map(a=>a))}if(e==="factorial"){let o=r[0]??0,a=1;for(;o>1;)a*=o--;return a}if(e==="gcd"){let o=Math.abs(r[0]??0),a=Math.abs(r[1]??0);for(;a;)[o,a]=[a,o%a];return o}}if(pt(t)){if(e==="dumps"){let i=pt(r[1]??G)?r[1]:void 0,o=i?i.data.get("indent"):void 0;return JSON.stringify(this.pyToJs(r[0]??G),null,o)}if(e==="loads")return this.jsToPy(JSON.parse(Be(r[0]??"")))}if(ci(t)){let i=t.attrs.get(e)??t.cls.methods.get(e)??G;if(wn(i)){let o=new Map(i.closure);return o.set("self",t),i.params.slice(1).forEach((a,c)=>o.set(a,r[c]??G)),this.execBlock(i.body,o)}}throw new mt("AttributeError",`'${or(t)}' object has no attribute '${e}'`)}pyStringFormat(t,e){let r=0;return t.replace(/%([diouxXeEfFgGcrs%])/g,(s,i)=>{if(i==="%")return"%";let o=e[r++];switch(i){case"d":case"i":return String(Math.trunc(o));case"f":return o.toFixed(6);case"s":return Be(o??G);case"r":return Rt(o??G);default:return String(o)}})}pyToJs(t){return Dn(t)?null:pt(t)?Object.fromEntries([...t.data.entries()].map(([e,r])=>[e,this.pyToJs(r)])):Array.isArray(t)?t.map(e=>this.pyToJs(e)):t}jsToPy(t){return t==null?G:typeof t=="boolean"||typeof t=="number"||typeof t=="string"?t:Array.isArray(t)?t.map(e=>this.jsToPy(e)):typeof t=="object"?At(Object.entries(t).map(([e,r])=>[e,this.jsToPy(r)])):G}callBuiltin(t,e,r){if(r.has(t)){let s=r.get(t)??G;return wn(s)?this.callFunc(s,e,r):Ao(s)?this.instantiate(s,e,r):s}switch(t){case"print":return this.output.push(e.map(Be).join(" ")+`
174
- `.replace(/\\n/g,"")),G;case"input":return this.output.push(Be(e[0]??"")),"";case"int":{if(e.length===0)return 0;let s=e[1]??10,i=parseInt(Be(e[0]??0),s);return Number.isNaN(i)?(()=>{throw new mt("ValueError","invalid literal for int()")})():i}case"float":{if(e.length===0)return 0;let s=parseFloat(Be(e[0]??0));return Number.isNaN(s)?(()=>{throw new mt("ValueError","could not convert to float")})():s}case"str":return e.length===0?"":Be(e[0]??G);case"bool":return e.length===0?!1:on(e[0]??G);case"list":return e.length===0?[]:Bt(e[0]??[]);case"tuple":return e.length===0?[]:Bt(e[0]??[]);case"set":return e.length===0?[]:[...new Set(Bt(e[0]??[]).map(Rt))].map(s=>Bt(e[0]??[]).find(o=>Rt(o)===s)??G);case"dict":return e.length===0?At():pt(e[0]??G)?e[0]:At();case"bytes":return typeof e[0]=="string"?e[0]:Be(e[0]??"");case"bytearray":return e.length===0?"":Be(e[0]??"");case"type":return e.length===1?`<class '${or(e[0]??G)}'>`:G;case"isinstance":return or(e[0]??G)===Be(e[1]??"");case"issubclass":return!1;case"callable":return wn(e[0]??G);case"hasattr":return pt(e[0]??G)?e[0].data.has(Be(e[1]??"")):!1;case"getattr":return pt(e[0]??G)?e[0].data.get(Be(e[1]??""))??e[2]??G:e[2]??G;case"setattr":return pt(e[0]??G)&&e[0].data.set(Be(e[1]??""),e[2]??G),G;case"len":{let s=e[0]??G;if(typeof s=="string"||Array.isArray(s))return s.length;if(pt(s))return s.data.size;if(Cr(s))return ol(s);throw new mt("TypeError",`object of type '${or(s)}' has no len()`)}case"range":return e.length===1?mo(0,e[0]):e.length===2?mo(e[0],e[1]):mo(e[0],e[1],e[2]);case"enumerate":{let s=e[1]??0;return Bt(e[0]??[]).map((i,o)=>[o+s,i])}case"zip":{let s=e.map(Bt),i=Math.min(...s.map(o=>o.length));return Array.from({length:i},(o,a)=>s.map(c=>c[a]??G))}case"map":{let s=e[0]??G;return Bt(e[1]??[]).map(i=>wn(s)?this.callFunc(s,[i],r):G)}case"filter":{let s=e[0]??G;return Bt(e[1]??[]).filter(i=>wn(s)?on(this.callFunc(s,[i],r)):on(i))}case"reduce":{let s=e[0]??G,i=Bt(e[1]??[]);if(i.length===0)return e[2]??G;let o=e[2]!==void 0?e[2]:i[0];for(let a of e[2]!==void 0?i:i.slice(1))o=wn(s)?this.callFunc(s,[o,a],r):G;return o}case"sorted":{let s=[...Bt(e[0]??[])],i=e[1]??G,o=pt(i)?i.data.get("key")??G:i;return s.sort((a,c)=>{let f=wn(o)?this.callFunc(o,[a],r):a,l=wn(o)?this.callFunc(o,[c],r):c;return typeof f=="number"&&typeof l=="number"?f-l:Be(f).localeCompare(Be(l))}),s}case"reversed":return[...Bt(e[0]??[])].reverse();case"any":return Bt(e[0]??[]).some(on);case"all":return Bt(e[0]??[]).every(on);case"sum":return Bt(e[0]??[]).reduce((s,i)=>s+i,e[1]??0);case"max":return(e.length===1?Bt(e[0]??[]):e).reduce((i,o)=>i>=o?i:o);case"min":return(e.length===1?Bt(e[0]??[]):e).reduce((i,o)=>i<=o?i:o);case"abs":return Math.abs(e[0]??0);case"round":return e[1]!==void 0?parseFloat(e[0].toFixed(e[1])):Math.round(e[0]??0);case"divmod":{let s=e[0],i=e[1];return[Math.floor(s/i),s%i]}case"pow":return e[0]**e[1];case"hex":return`0x${e[0].toString(16)}`;case"oct":return`0o${e[0].toString(8)}`;case"bin":return`0b${e[0].toString(2)}`;case"ord":return Be(e[0]??"").charCodeAt(0);case"chr":return String.fromCharCode(e[0]??0);case"id":return Math.floor(Math.random()*4294967295);case"hash":return typeof e[0]=="number"?e[0]:Be(e[0]??"").split("").reduce((s,i)=>s*31+i.charCodeAt(0)|0,0);case"open":throw new mt("PermissionError","open() not available in virtual runtime");case"repr":return Rt(e[0]??G);case"iter":return e[0]??G;case"next":return Array.isArray(e[0])&&e[0].length>0?e[0].shift():e[1]??(()=>{throw new mt("StopIteration","")})();case"vars":return At([...r.entries()].map(([s,i])=>[s,i]));case"globals":return At([...r.entries()].map(([s,i])=>[s,i]));case"locals":return At([...r.entries()].map(([s,i])=>[s,i]));case"dir":{if(e.length===0)return[...r.keys()];let s=e[0]??G;return typeof s=="string"?["upper","lower","strip","split","join","replace","find","format","encode","startswith","endswith","count","isdigit","isalpha","title","capitalize"]:Array.isArray(s)?["append","extend","insert","pop","remove","index","count","sort","reverse","copy","clear"]:pt(s)?["keys","values","items","get","update","pop","clear","copy","setdefault"]:[]}case"Exception":case"ValueError":case"TypeError":case"KeyError":case"IndexError":case"AttributeError":case"NameError":case"RuntimeError":case"StopIteration":case"NotImplementedError":case"OSError":case"IOError":throw new mt(t,Be(e[0]??""));case"exec":return this.execScript(Be(e[0]??""),r),G;case"eval":return this.pyEval(Be(e[0]??""),r);default:throw new mt("NameError",`name '${t}' is not defined`)}}callFunc(t,e,r){let s=new Map(t.closure);t.params.forEach((i,o)=>{if(i.startsWith("*")){s.set(i.slice(1),e.slice(o));return}s.set(i,e[o]??G)});try{return this.execBlock(t.body,s)}catch(i){if(i instanceof Ir)return i.value;throw i}}instantiate(t,e,r){let s={__pytype__:"instance",cls:t,attrs:new Map};return t.methods.get("__init__")&&this.callMethod(s,"__init__",e,r),s}execScript(t,e){let r=t.split(`
175
- `);this.execLines(r,0,e)}execLines(t,e,r){let s=e;for(;s<t.length;){let i=t[s];if(!i.trim()||i.trim().startsWith("#")){s++;continue}s=this.execStatement(t,s,r)}return s}execBlock(t,e){try{this.execLines(t,0,e)}catch(r){if(r instanceof Ir)return r.value;throw r}return G}getIndent(t){let e=0;for(let r of t)if(r===" ")e++;else if(r===" ")e+=4;else break;return e}collectBlock(t,e,r){let s=[];for(let i=e;i<t.length;i++){let o=t[i];if(!o.trim()){s.push("");continue}if(this.getIndent(o)<=r)break;s.push(o.slice(r+4))}return s}execStatement(t,e,r){let s=t[e],i=s.trim(),o=this.getIndent(s);if(i==="pass")return e+1;if(i==="break")throw new fi;if(i==="continue")throw new li;let a=i.match(/^return(?:\s+(.+))?$/);if(a)throw new Ir(a[1]?this.pyEval(a[1],r):G);let c=i.match(/^raise(?:\s+(.+))?$/);if(c){if(c[1]){let N=this.pyEval(c[1],r);throw new mt(typeof N=="string"?N:or(N),Be(N))}throw new mt("RuntimeError","")}let f=i.match(/^assert\s+(.+?)(?:,\s*(.+))?$/);if(f){if(!on(this.pyEval(f[1],r)))throw new mt("AssertionError",f[2]?Be(this.pyEval(f[2],r)):"");return e+1}let l=i.match(/^del\s+(.+)$/);if(l)return r.delete(l[1].trim()),e+1;let u=i.match(/^import\s+(\w+)(?:\s+as\s+(\w+))?$/);if(u){let[,N,x]=u,S=sl[N];if(S){let I=S(this.cwd);this.modules.set(N,I),r.set(x??N,I)}return e+1}let h=i.match(/^from\s+(\w+)\s+import\s+(.+)$/);if(h){let[,N,x]=h,S=sl[N];if(S){let I=S(this.cwd);if(x?.trim()==="*")for(let[k,R]of I.data)r.set(k,R);else for(let k of x.split(",").map(R=>R.trim()))r.set(k,I.data.get(k)??G)}return e+1}let p=i.match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(p){let[,N,x]=p,S=x.split(",").map(R=>R.trim()).filter(Boolean),I=this.collectBlock(t,e+1,o),k={__pytype__:"func",name:N,params:S,body:I,closure:new Map(r)};return r.set(N,k),e+1+I.length}let _=i.match(/^class\s+(\w+)(?:\(([^)]*)\))?\s*:$/);if(_){let[,N,x]=_,S=x?x.split(",").map(ne=>ne.trim()):[],I=this.collectBlock(t,e+1,o),k={__pytype__:"class",name:N,methods:new Map,bases:S},R=0;for(;R<I.length;){let z=I[R].trim().match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(z){let[,Y,te]=z,ce=te.split(",").map(B=>B.trim()).filter(Boolean),$=this.collectBlock(I,R+1,0);k.methods.set(Y,{__pytype__:"func",name:Y,params:ce,body:$,closure:new Map(r)}),R+=1+$.length}else R++}return r.set(N,k),e+1+I.length}if(i.startsWith("if ")&&i.endsWith(":")){let N=i.slice(3,-1).trim(),x=this.collectBlock(t,e+1,o),S=x.length+1;if(on(this.pyEval(N,r))){this.execBlock(x,new Map(r).also?.(R=>{for(let[ne,z]of r)R.set(ne,z)})??r),this.runBlockInScope(x,r);let k=e+1+x.length;for(;k<t.length;){let R=t[k].trim();if(this.getIndent(t[k])<o||!R.startsWith("elif")&&!R.startsWith("else"))break;let ne=this.collectBlock(t,k+1,o);k+=1+ne.length}return k}let I=e+1+x.length;for(;I<t.length;){let k=t[I],R=k.trim();if(this.getIndent(k)!==o)break;let ne=R.match(/^elif\s+(.+):$/);if(ne){let z=this.collectBlock(t,I+1,o);if(on(this.pyEval(ne[1],r))){for(this.runBlockInScope(z,r),I+=1+z.length;I<t.length;){let Y=t[I].trim();if(this.getIndent(t[I])!==o||!Y.startsWith("elif")&&!Y.startsWith("else"))break;let te=this.collectBlock(t,I+1,o);I+=1+te.length}return I}I+=1+z.length;continue}if(R==="else:"){let z=this.collectBlock(t,I+1,o);return this.runBlockInScope(z,r),I+1+z.length}break}return I}let E=i.match(/^for\s+(.+?)\s+in\s+(.+?)\s*:$/);if(E){let[,N,x]=E,S=Bt(this.pyEval(x.trim(),r)),I=this.collectBlock(t,e+1,o),k=[],R=e+1+I.length;R<t.length&&t[R]?.trim()==="else:"&&(k=this.collectBlock(t,R+1,o),R+=1+k.length);let ne=!1;for(let z of S){if(N.includes(",")){let Y=N.split(",").map(ce=>ce.trim()),te=Array.isArray(z)?z:[z];Y.forEach((ce,$)=>r.set(ce,te[$]??G))}else r.set(N.trim(),z);try{this.runBlockInScope(I,r)}catch(Y){if(Y instanceof fi){ne=!0;break}if(Y instanceof li)continue;throw Y}}return!ne&&k.length&&this.runBlockInScope(k,r),R}let b=i.match(/^while\s+(.+?)\s*:$/);if(b){let N=b[1],x=this.collectBlock(t,e+1,o),S=0;for(;on(this.pyEval(N,r))&&S++<1e5;)try{this.runBlockInScope(x,r)}catch(I){if(I instanceof fi)break;if(I instanceof li)continue;throw I}return e+1+x.length}if(i==="try:"){let N=this.collectBlock(t,e+1,o),x=e+1+N.length,S=[],I=[],k=[];for(;x<t.length;){let ne=t[x],z=ne.trim();if(this.getIndent(ne)!==o)break;if(z.startsWith("except")){let Y=z.match(/^except(?:\s+(\w+)(?:\s+as\s+(\w+))?)?\s*:$/),te=Y?.[1]??null,ce=Y?.[2],$=this.collectBlock(t,x+1,o);S.push({exc:te,body:$}),ce&&r.set(ce,""),x+=1+$.length}else if(z==="else:")k=this.collectBlock(t,x+1,o),x+=1+k.length;else if(z==="finally:")I=this.collectBlock(t,x+1,o),x+=1+I.length;else break}let R=null;try{this.runBlockInScope(N,r),k.length&&this.runBlockInScope(k,r)}catch(ne){if(ne instanceof mt){R=ne;let z=!1;for(let Y of S)if(Y.exc===null||Y.exc===ne.type||Y.exc==="Exception"){this.runBlockInScope(Y.body,r),z=!0;break}if(!z)throw ne}else throw ne}finally{I.length&&this.runBlockInScope(I,r)}return x}let v=i.match(/^with\s+(.+?)\s+as\s+(\w+)\s*:$/);if(v){let N=this.collectBlock(t,e+1,o);return r.set(v[2],G),this.runBlockInScope(N,r),e+1+N.length}let U=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(\+=|-=|\*=|\/\/=|\/=|%=|\*\*=|&=|\|=)\s*(.+)$/);if(U){let[,N,x,S]=U,I=r.get(N)??0,k=this.pyEval(S,r),R;switch(x){case"+=":R=typeof I=="string"?I+Be(k):I+k;break;case"-=":R=I-k;break;case"*=":R=I*k;break;case"/=":R=I/k;break;case"//=":R=Math.floor(I/k);break;case"%=":R=I%k;break;case"**=":R=I**k;break;default:R=k}return r.set(N,R),e+1}let H=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\[(.+)\]\s*=\s*(.+)$/);if(H){let[,N,x,S]=H,I=r.get(N)??G,k=this.pyEval(S,r)??G,R=this.pyEval(x,r)??G;return Array.isArray(I)?I[R]=k:pt(I)&&I.data.set(Be(R),k),e+1}let C=i.match(/^([A-Za-z_][A-Za-z0-9_.]+)\s*=\s*(.+)$/);if(C){let N=C[1].lastIndexOf(".");if(N!==-1){let x=C[1].slice(0,N),S=C[1].slice(N+1),I=this.pyEval(C[2],r),k=this.pyEval(x,r);return pt(k)?k.data.set(S,I):ci(k)&&k.attrs.set(S,I),e+1}}let F=i.match(/^([A-Za-z_][A-Za-z0-9_,\s]*),\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$/);if(F){let N=this.pyEval(F[3],r),x=i.split("=")[0].split(",").map(I=>I.trim()),S=Bt(N);return x.forEach((I,k)=>r.set(I,S[k]??G)),e+1}let V=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^=]+)?\s*=\s*(.+)$/);if(V){let[,N,x]=V;return r.set(N,this.pyEval(x,r)),e+1}try{this.pyEval(i,r)}catch(N){if(N instanceof mt||N instanceof ui)throw N}return e+1}runBlockInScope(t,e){this.execLines(t,0,e)}run(t){let e=Gp(this.cwd);try{this.execScript(t,e)}catch(r){return r instanceof ui?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:r.code}:r instanceof mt?(this.stderr.push(r.toString()),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1}):r instanceof Ir?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}:(this.stderr.push(`RuntimeError: ${r}`),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1})}return{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}}},al={name:"python3",aliases:["python"],description:"Python 3 interpreter (virtual)",category:"system",params:["[--version] [-c <code>] [-V] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("python3"))return{stderr:`bash: python3: command not found
179
+ `:"")}splitArgs(t){let e=[],r=0,s="",i=!1,o="";for(let a=0;a<t.length;a++){let c=t[a];i?(s+=c,c===o&&t[a-1]!=="\\"&&(i=!1)):c==='"'||c==="'"?(i=!0,o=c,s+=c):"([{".includes(c)?(r++,s+=c):")]}".includes(c)?(r--,s+=c):c===","&&r===0?(e.push(s.trim()),s=""):s+=c}return s.trim()&&e.push(s.trim()),e}pyEval(t,e){if(t=t.trim(),!t||t==="None")return z;if(t==="True")return!0;if(t==="False")return!1;if(t==="...")return z;if(/^-?\d+$/.test(t))return parseInt(t,10);if(/^-?\d+\.\d*$/.test(t))return parseFloat(t);if(/^0x[0-9a-fA-F]+$/.test(t))return parseInt(t,16);if(/^0o[0-7]+$/.test(t))return parseInt(t.slice(2),8);if(/^('''[\s\S]*'''|"""[\s\S]*""")$/.test(t))return t.slice(3,-3);if(/^(['"])(.*)\1$/s.test(t))return t.slice(1,-1).replace(/\\n/g,`
180
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');let r=t.match(/^f(['"])([\s\S]*)\1$/);if(r){let l=r[2];return l=l.replace(/\{([^{}]+)\}/g,(f,u)=>{try{return Re(this.pyEval(u.trim(),e))}catch{return`{${u}}`}}),l}let s=t.match(/^b(['"])(.*)\1$/s);if(s)return s[2];if(t.startsWith("[")&&t.endsWith("]")){let l=t.slice(1,-1).trim();if(!l)return[];let f=l.match(/^(.+?)\s+for\s+(\w+)\s+in\s+(.+?)(?:\s+if\s+(.+))?$/);if(f){let[,u,h,p,A]=f,E=Nt(this.pyEval(p.trim(),e)),S=[];for(let x of E){let R=new Map(e);R.set(h,x),!(A&&!ln(this.pyEval(A,R)))&&S.push(this.pyEval(u.trim(),R))}return S}return this.splitArgs(l).map(u=>this.pyEval(u,e))}if(t.startsWith("(")&&t.endsWith(")")){let l=t.slice(1,-1).trim();if(!l)return[];let f=this.splitArgs(l);return f.length===1&&!l.endsWith(",")?this.pyEval(f[0],e):f.map(u=>this.pyEval(u,e))}if(t.startsWith("{")&&t.endsWith("}")){let l=t.slice(1,-1).trim();if(!l)return Et();let f=Et();for(let u of this.splitArgs(l)){let h=u.indexOf(":");if(h===-1)continue;let p=Re(this.pyEval(u.slice(0,h).trim(),e)),A=this.pyEval(u.slice(h+1).trim(),e);f.data.set(p,A)}return f}let i=t.match(/^not\s+(.+)$/);if(i)return!ln(this.pyEval(i[1],e));let o=[["or"],["and"],["in","not in","is not","is","==","!=","<=",">=","<",">"],["+","-"],["**"],["*","//","/","%"]];for(let l of o){let f=this.tryBinaryOp(t,l,e);if(f!==void 0)return f}if(t.startsWith("-")){let l=this.pyEval(t.slice(1),e);if(typeof l=="number")return-l}if(process.env.PY_DEBUG&&console.error("eval:",JSON.stringify(t)),t.endsWith("]")&&!t.startsWith("[")){let l=this.findMatchingBracket(t,"[");if(l!==-1){let f=this.pyEval(t.slice(0,l),e),u=t.slice(l+1,-1);return this.subscript(f,u,e)}}let a=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/);if(a){let[,l,f]=a,u=(f?.trim()?this.splitArgs(f):[]).map(h=>this.pyEval(h,e));return this.callBuiltin(l,u,e)}let c=this.findDotAccess(t);if(c){let{objExpr:l,attr:f,callPart:u}=c,h=this.pyEval(l,e);if(u!==void 0){let p=u.slice(1,-1),A=p.trim()?this.splitArgs(p).map(E=>this.pyEval(E,e)):[];return this.callMethod(h,f,A,e)}return this.getAttr(h,f,e)}if(/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)){if(e.has(t))return e.get(t);throw new yt("NameError",`name '${t}' is not defined`)}if(/^[A-Za-z_][A-Za-z0-9_.]+$/.test(t)){let l=t.split("."),f=e.get(l[0])??(()=>{throw new yt("NameError",`name '${l[0]}' is not defined`)})();for(let u of l.slice(1))f=this.getAttr(f,u,e);return f}return z}findMatchingBracket(t,e){let r=e==="["?"]":e==="("?")":"}",s=0;for(let i=t.length-1;i>=0;i--)if(t[i]===r&&s++,t[i]===e&&(s--,s===0))return i;return-1}findDotAccess(t){let e=0,r=!1,s="";for(let i=t.length-1;i>0;i--){let o=t[i];if(r){o===s&&t[i-1]!=="\\"&&(r=!1);continue}if(o==='"'||o==="'"){r=!0,s=o;continue}if(")]}".includes(o)){e++;continue}if("([{".includes(o)){e--;continue}if(e!==0||o!==".")continue;let a=t.slice(0,i).trim(),l=t.slice(i+1).match(/^(\w+)(\([\s\S]*\))?$/);if(l&&!/^-?\d+$/.test(a))return{objExpr:a,attr:l[1],callPart:l[2]}}return null}tryBinaryOp(t,e,r){let s=0,i=!1,o="";for(let a=t.length-1;a>=0;a--){let c=t[a];if(i){c===o&&t[a-1]!=="\\"&&(i=!1);continue}if(c==='"'||c==="'"){i=!0,o=c;continue}if(")]}".includes(c)){s++;continue}if("([{".includes(c)){s--;continue}if(s===0){for(let l of e)if(t.slice(a,a+l.length)===l){if(l==="*"&&(t[a+1]==="*"||t[a-1]==="*"))continue;let f=t[a-1],u=t[a+l.length];if(/^[a-z]/.test(l)&&(f&&/\w/.test(f)||u&&/\w/.test(u)))continue;let p=t.slice(0,a).trim(),A=t.slice(a+l.length).trim();if(!p||!A)continue;return this.applyBinaryOp(l,p,A,r)}}}}applyBinaryOp(t,e,r,s){if(t==="and"){let a=this.pyEval(e,s);return ln(a)?this.pyEval(r,s):a}if(t==="or"){let a=this.pyEval(e,s);return ln(a)?a:this.pyEval(r,s)}let i=this.pyEval(e,s),o=this.pyEval(r,s);switch(t){case"+":return typeof i=="string"&&typeof o=="string"?i+o:Array.isArray(i)&&Array.isArray(o)?[...i,...o]:i+o;case"-":return i-o;case"*":if(typeof i=="string"&&typeof o=="number")return i.repeat(o);if(Array.isArray(i)&&typeof o=="number"){let a=[];for(let c=0;c<o;c++)a.push(...i);return a}return i*o;case"/":{if(o===0)throw new yt("ZeroDivisionError","division by zero");return i/o}case"//":{if(o===0)throw new yt("ZeroDivisionError","integer division or modulo by zero");return Math.floor(i/o)}case"%":{if(typeof i=="string")return this.pyStringFormat(i,Array.isArray(o)?o:[o]);if(o===0)throw new yt("ZeroDivisionError","integer division or modulo by zero");return i%o}case"**":return i**o;case"==":return Pt(i)===Pt(o)||i===o;case"!=":return Pt(i)!==Pt(o)&&i!==o;case"<":return i<o;case"<=":return i<=o;case">":return i>o;case">=":return i>=o;case"in":return this.pyIn(o,i);case"not in":return!this.pyIn(o,i);case"is":return i===o||Un(i)&&Un(o);case"is not":return!(i===o||Un(i)&&Un(o))}return z}pyIn(t,e){return typeof t=="string"?typeof e=="string"&&t.includes(e):Array.isArray(t)?t.some(r=>Pt(r)===Pt(e)):mt(t)?t.data.has(Re(e)):!1}subscript(t,e,r){if(e.includes(":")){let i=e.split(":").map(c=>c.trim()),o=i[0]?this.pyEval(i[0],r):void 0,a=i[1]?this.pyEval(i[1],r):void 0;return typeof t=="string"||Array.isArray(t)?t.slice(o,a):z}let s=this.pyEval(e,r);if(Array.isArray(t)){let i=s;return i<0&&(i=t.length+i),t[i]??z}if(typeof t=="string"){let i=s;return i<0&&(i=t.length+i),t[i]??z}if(mt(t))return t.data.get(Re(s))??z;throw new yt("TypeError",`'${lr(t)}' is not subscriptable`)}getAttr(t,e,r){return mt(t)?t.data.has(e)?t.data.get(e):e==="path"&&t.path?t.path:z:ui(t)?t.attrs.get(e)??z:typeof t=="string"?{__class__:{__pytype__:"class",name:"str"}}[e]??z:z}callMethod(t,e,r,s){if(typeof t=="string")switch(e){case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();case"strip":return(r[0]?t.replace(new RegExp(`[${r[0]}]+`,"g"),""):t).trim();case"lstrip":return t.trimStart();case"rstrip":return t.trimEnd();case"split":return t.split(typeof r[0]=="string"?r[0]:/\s+/).filter((i,o)=>o>0||i!=="");case"splitlines":return t.split(`
181
+ `);case"join":return Nt(r[0]??[]).map(Re).join(t);case"replace":return t.replaceAll(Re(r[0]??""),Re(r[1]??""));case"startswith":return t.startsWith(Re(r[0]??""));case"endswith":return t.endsWith(Re(r[0]??""));case"find":return t.indexOf(Re(r[0]??""));case"index":{let i=t.indexOf(Re(r[0]??""));if(i===-1)throw new yt("ValueError","substring not found");return i}case"count":return t.split(Re(r[0]??"")).length-1;case"format":return this.pyStringFormat(t,r);case"encode":return t;case"decode":return t;case"isdigit":return/^\d+$/.test(t);case"isalpha":return/^[a-zA-Z]+$/.test(t);case"isalnum":return/^[a-zA-Z0-9]+$/.test(t);case"isspace":return/^\s+$/.test(t);case"isupper":return t===t.toUpperCase()&&t!==t.toLowerCase();case"islower":return t===t.toLowerCase()&&t!==t.toUpperCase();case"center":{let i=r[0]??0,o=Re(r[1]??" ");return t.padStart(Math.floor((i+t.length)/2),o).padEnd(i,o)}case"ljust":return t.padEnd(r[0]??0,Re(r[1]??" "));case"rjust":return t.padStart(r[0]??0,Re(r[1]??" "));case"zfill":return t.padStart(r[0]??0,"0");case"title":return t.replace(/\b\w/g,i=>i.toUpperCase());case"capitalize":return t[0]?.toUpperCase()+t.slice(1).toLowerCase();case"swapcase":return[...t].map(i=>i===i.toUpperCase()?i.toLowerCase():i.toUpperCase()).join("")}if(Array.isArray(t))switch(e){case"append":return t.push(r[0]??z),z;case"extend":for(let i of Nt(r[0]??[]))t.push(i);return z;case"insert":return t.splice(r[0]??0,0,r[1]??z),z;case"pop":{let i=r[0]!==void 0?r[0]:-1,o=i<0?t.length+i:i;return t.splice(o,1)[0]??z}case"remove":{let i=t.findIndex(o=>Pt(o)===Pt(r[0]??z));return i!==-1&&t.splice(i,1),z}case"index":{let i=t.findIndex(o=>Pt(o)===Pt(r[0]??z));if(i===-1)throw new yt("ValueError","is not in list");return i}case"count":return t.filter(i=>Pt(i)===Pt(r[0]??z)).length;case"sort":return t.sort((i,o)=>typeof i=="number"&&typeof o=="number"?i-o:Re(i).localeCompare(Re(o))),z;case"reverse":return t.reverse(),z;case"copy":return[...t];case"clear":return t.splice(0),z}if(mt(t))switch(e){case"keys":return[...t.data.keys()];case"values":return[...t.data.values()];case"items":return[...t.data.entries()].map(([i,o])=>[i,o]);case"get":return t.data.get(Re(r[0]??""))??r[1]??z;case"update":{if(mt(r[0]??z))for(let[i,o]of r[0].data)t.data.set(i,o);return z}case"pop":{let i=Re(r[0]??""),o=t.data.get(i)??r[1]??z;return t.data.delete(i),o}case"clear":return t.data.clear(),z;case"copy":return Et([...t.data.entries()]);case"setdefault":{let i=Re(r[0]??"");return t.data.has(i)||t.data.set(i,r[1]??z),t.data.get(i)??z}}if(mt(t)&&t.data.has("name")&&t.data.get("name")==="posix")switch(e){case"getcwd":return this.cwd;case"getenv":return typeof r[0]=="string"?process.env[r[0]]??r[1]??z:z;case"listdir":return[];case"path":return t}if(mt(t))switch(e){case"join":return r.map(Re).join("/").replace(/\/+/g,"/");case"exists":return!1;case"dirname":return Re(r[0]??"").split("/").slice(0,-1).join("/")||"/";case"basename":return Re(r[0]??"").split("/").pop()??"";case"abspath":return Re(r[0]??"");case"splitext":{let i=Re(r[0]??""),o=i.lastIndexOf(".");return o>0?[i.slice(0,o),i.slice(o)]:[i,""]}case"isfile":return!1;case"isdir":return!1}if(mt(t)&&t.data.has("version")&&t.data.get("version")===us&&e==="exit")throw new pi(r[0]??0);if(mt(t)){let i={sqrt:Math.sqrt,floor:Math.floor,ceil:Math.ceil,fabs:Math.abs,log:Math.log,log2:Math.log2,log10:Math.log10,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,atan2:Math.atan2,pow:Math.pow,exp:Math.exp,hypot:Math.hypot};if(e in i){let o=i[e];return o(...r.map(a=>a))}if(e==="factorial"){let o=r[0]??0,a=1;for(;o>1;)a*=o--;return a}if(e==="gcd"){let o=Math.abs(r[0]??0),a=Math.abs(r[1]??0);for(;a;)[o,a]=[a,o%a];return o}}if(mt(t)){if(e==="dumps"){let i=mt(r[1]??z)?r[1]:void 0,o=i?i.data.get("indent"):void 0;return JSON.stringify(this.pyToJs(r[0]??z),null,o)}if(e==="loads")return this.jsToPy(JSON.parse(Re(r[0]??"")))}if(ui(t)){let i=t.attrs.get(e)??t.cls.methods.get(e)??z;if(vn(i)){let o=new Map(i.closure);return o.set("self",t),i.params.slice(1).forEach((a,c)=>o.set(a,r[c]??z)),this.execBlock(i.body,o)}}throw new yt("AttributeError",`'${lr(t)}' object has no attribute '${e}'`)}pyStringFormat(t,e){let r=0;return t.replace(/%([diouxXeEfFgGcrs%])/g,(s,i)=>{if(i==="%")return"%";let o=e[r++];switch(i){case"d":case"i":return String(Math.trunc(o));case"f":return o.toFixed(6);case"s":return Re(o??z);case"r":return Pt(o??z);default:return String(o)}})}pyToJs(t){return Un(t)?null:mt(t)?Object.fromEntries([...t.data.entries()].map(([e,r])=>[e,this.pyToJs(r)])):Array.isArray(t)?t.map(e=>this.pyToJs(e)):t}jsToPy(t){return t==null?z:typeof t=="boolean"||typeof t=="number"||typeof t=="string"?t:Array.isArray(t)?t.map(e=>this.jsToPy(e)):typeof t=="object"?Et(Object.entries(t).map(([e,r])=>[e,this.jsToPy(r)])):z}callBuiltin(t,e,r){if(r.has(t)){let s=r.get(t)??z;return vn(s)?this.callFunc(s,e,r):wo(s)?this.instantiate(s,e,r):s}switch(t){case"print":return this.output.push(e.map(Re).join(" ")+`
182
+ `.replace(/\\n/g,"")),z;case"input":return this.output.push(Re(e[0]??"")),"";case"int":{if(e.length===0)return 0;let s=e[1]??10,i=parseInt(Re(e[0]??0),s);return Number.isNaN(i)?(()=>{throw new yt("ValueError","invalid literal for int()")})():i}case"float":{if(e.length===0)return 0;let s=parseFloat(Re(e[0]??0));return Number.isNaN(s)?(()=>{throw new yt("ValueError","could not convert to float")})():s}case"str":return e.length===0?"":Re(e[0]??z);case"bool":return e.length===0?!1:ln(e[0]??z);case"list":return e.length===0?[]:Nt(e[0]??[]);case"tuple":return e.length===0?[]:Nt(e[0]??[]);case"set":return e.length===0?[]:[...new Set(Nt(e[0]??[]).map(Pt))].map(s=>Nt(e[0]??[]).find(o=>Pt(o)===s)??z);case"dict":return e.length===0?Et():mt(e[0]??z)?e[0]:Et();case"bytes":return typeof e[0]=="string"?e[0]:Re(e[0]??"");case"bytearray":return e.length===0?"":Re(e[0]??"");case"type":return e.length===1?`<class '${lr(e[0]??z)}'>`:z;case"isinstance":return lr(e[0]??z)===Re(e[1]??"");case"issubclass":return!1;case"callable":return vn(e[0]??z);case"hasattr":return mt(e[0]??z)?e[0].data.has(Re(e[1]??"")):!1;case"getattr":return mt(e[0]??z)?e[0].data.get(Re(e[1]??""))??e[2]??z:e[2]??z;case"setattr":return mt(e[0]??z)&&e[0].data.set(Re(e[1]??""),e[2]??z),z;case"len":{let s=e[0]??z;if(typeof s=="string"||Array.isArray(s))return s.length;if(mt(s))return s.data.size;if(Br(s))return df(s);throw new yt("TypeError",`object of type '${lr(s)}' has no len()`)}case"range":return e.length===1?xo(0,e[0]):e.length===2?xo(e[0],e[1]):xo(e[0],e[1],e[2]);case"enumerate":{let s=e[1]??0;return Nt(e[0]??[]).map((i,o)=>[o+s,i])}case"zip":{let s=e.map(Nt),i=Math.min(...s.map(o=>o.length));return Array.from({length:i},(o,a)=>s.map(c=>c[a]??z))}case"map":{let s=e[0]??z;return Nt(e[1]??[]).map(i=>vn(s)?this.callFunc(s,[i],r):z)}case"filter":{let s=e[0]??z;return Nt(e[1]??[]).filter(i=>vn(s)?ln(this.callFunc(s,[i],r)):ln(i))}case"reduce":{let s=e[0]??z,i=Nt(e[1]??[]);if(i.length===0)return e[2]??z;let o=e[2]!==void 0?e[2]:i[0];for(let a of e[2]!==void 0?i:i.slice(1))o=vn(s)?this.callFunc(s,[o,a],r):z;return o}case"sorted":{let s=[...Nt(e[0]??[])],i=e[1]??z,o=mt(i)?i.data.get("key")??z:i;return s.sort((a,c)=>{let l=vn(o)?this.callFunc(o,[a],r):a,f=vn(o)?this.callFunc(o,[c],r):c;return typeof l=="number"&&typeof f=="number"?l-f:Re(l).localeCompare(Re(f))}),s}case"reversed":return[...Nt(e[0]??[])].reverse();case"any":return Nt(e[0]??[]).some(ln);case"all":return Nt(e[0]??[]).every(ln);case"sum":return Nt(e[0]??[]).reduce((s,i)=>s+i,e[1]??0);case"max":return(e.length===1?Nt(e[0]??[]):e).reduce((i,o)=>i>=o?i:o);case"min":return(e.length===1?Nt(e[0]??[]):e).reduce((i,o)=>i<=o?i:o);case"abs":return Math.abs(e[0]??0);case"round":return e[1]!==void 0?parseFloat(e[0].toFixed(e[1])):Math.round(e[0]??0);case"divmod":{let s=e[0],i=e[1];return[Math.floor(s/i),s%i]}case"pow":return e[0]**e[1];case"hex":return`0x${e[0].toString(16)}`;case"oct":return`0o${e[0].toString(8)}`;case"bin":return`0b${e[0].toString(2)}`;case"ord":return Re(e[0]??"").charCodeAt(0);case"chr":return String.fromCharCode(e[0]??0);case"id":return Math.floor(Math.random()*4294967295);case"hash":return typeof e[0]=="number"?e[0]:Re(e[0]??"").split("").reduce((s,i)=>s*31+i.charCodeAt(0)|0,0);case"open":throw new yt("PermissionError","open() not available in virtual runtime");case"repr":return Pt(e[0]??z);case"iter":return e[0]??z;case"next":return Array.isArray(e[0])&&e[0].length>0?e[0].shift():e[1]??(()=>{throw new yt("StopIteration","")})();case"vars":return Et([...r.entries()].map(([s,i])=>[s,i]));case"globals":return Et([...r.entries()].map(([s,i])=>[s,i]));case"locals":return Et([...r.entries()].map(([s,i])=>[s,i]));case"dir":{if(e.length===0)return[...r.keys()];let s=e[0]??z;return typeof s=="string"?["upper","lower","strip","split","join","replace","find","format","encode","startswith","endswith","count","isdigit","isalpha","title","capitalize"]:Array.isArray(s)?["append","extend","insert","pop","remove","index","count","sort","reverse","copy","clear"]:mt(s)?["keys","values","items","get","update","pop","clear","copy","setdefault"]:[]}case"Exception":case"ValueError":case"TypeError":case"KeyError":case"IndexError":case"AttributeError":case"NameError":case"RuntimeError":case"StopIteration":case"NotImplementedError":case"OSError":case"IOError":throw new yt(t,Re(e[0]??""));case"exec":return this.execScript(Re(e[0]??""),r),z;case"eval":return this.pyEval(Re(e[0]??""),r);default:throw new yt("NameError",`name '${t}' is not defined`)}}callFunc(t,e,r){let s=new Map(t.closure);t.params.forEach((i,o)=>{if(i.startsWith("*")){s.set(i.slice(1),e.slice(o));return}s.set(i,e[o]??z)});try{return this.execBlock(t.body,s)}catch(i){if(i instanceof vr)return i.value;throw i}}instantiate(t,e,r){let s={__pytype__:"instance",cls:t,attrs:new Map};return t.methods.get("__init__")&&this.callMethod(s,"__init__",e,r),s}execScript(t,e){let r=t.split(`
183
+ `);this.execLines(r,0,e)}execLines(t,e,r){let s=e;for(;s<t.length;){let i=t[s];if(!i.trim()||i.trim().startsWith("#")){s++;continue}s=this.execStatement(t,s,r)}return s}execBlock(t,e){try{this.execLines(t,0,e)}catch(r){if(r instanceof vr)return r.value;throw r}return z}getIndent(t){let e=0;for(let r of t)if(r===" ")e++;else if(r===" ")e+=4;else break;return e}collectBlock(t,e,r){let s=[];for(let i=e;i<t.length;i++){let o=t[i];if(!o.trim()){s.push("");continue}if(this.getIndent(o)<=r)break;s.push(o.slice(r+4))}return s}execStatement(t,e,r){let s=t[e],i=s.trim(),o=this.getIndent(s);if(i==="pass")return e+1;if(i==="break")throw new di;if(i==="continue")throw new hi;let a=i.match(/^return(?:\s+(.+))?$/);if(a)throw new vr(a[1]?this.pyEval(a[1],r):z);let c=i.match(/^raise(?:\s+(.+))?$/);if(c){if(c[1]){let B=this.pyEval(c[1],r);throw new yt(typeof B=="string"?B:lr(B),Re(B))}throw new yt("RuntimeError","")}let l=i.match(/^assert\s+(.+?)(?:,\s*(.+))?$/);if(l){if(!ln(this.pyEval(l[1],r)))throw new yt("AssertionError",l[2]?Re(this.pyEval(l[2],r)):"");return e+1}let f=i.match(/^del\s+(.+)$/);if(f)return r.delete(f[1].trim()),e+1;let u=i.match(/^import\s+(\w+)(?:\s+as\s+(\w+))?$/);if(u){let[,B,b]=u,w=uf[B];if(w){let k=w(this.cwd);this.modules.set(B,k),r.set(b??B,k)}return e+1}let h=i.match(/^from\s+(\w+)\s+import\s+(.+)$/);if(h){let[,B,b]=h,w=uf[B];if(w){let k=w(this.cwd);if(b?.trim()==="*")for(let[v,P]of k.data)r.set(v,P);else for(let v of b.split(",").map(P=>P.trim()))r.set(v,k.data.get(v)??z)}return e+1}let p=i.match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(p){let[,B,b]=p,w=b.split(",").map(P=>P.trim()).filter(Boolean),k=this.collectBlock(t,e+1,o),v={__pytype__:"func",name:B,params:w,body:k,closure:new Map(r)};return r.set(B,v),e+1+k.length}let A=i.match(/^class\s+(\w+)(?:\(([^)]*)\))?\s*:$/);if(A){let[,B,b]=A,w=b?b.split(",").map(ne=>ne.trim()):[],k=this.collectBlock(t,e+1,o),v={__pytype__:"class",name:B,methods:new Map,bases:w},P=0;for(;P<k.length;){let G=k[P].trim().match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(G){let[,Y,te]=G,le=te.split(",").map(N=>N.trim()).filter(Boolean),M=this.collectBlock(k,P+1,0);v.methods.set(Y,{__pytype__:"func",name:Y,params:le,body:M,closure:new Map(r)}),P+=1+M.length}else P++}return r.set(B,v),e+1+k.length}if(i.startsWith("if ")&&i.endsWith(":")){let B=i.slice(3,-1).trim(),b=this.collectBlock(t,e+1,o),w=b.length+1;if(ln(this.pyEval(B,r))){this.execBlock(b,new Map(r).also?.(P=>{for(let[ne,G]of r)P.set(ne,G)})??r),this.runBlockInScope(b,r);let v=e+1+b.length;for(;v<t.length;){let P=t[v].trim();if(this.getIndent(t[v])<o||!P.startsWith("elif")&&!P.startsWith("else"))break;let ne=this.collectBlock(t,v+1,o);v+=1+ne.length}return v}let k=e+1+b.length;for(;k<t.length;){let v=t[k],P=v.trim();if(this.getIndent(v)!==o)break;let ne=P.match(/^elif\s+(.+):$/);if(ne){let G=this.collectBlock(t,k+1,o);if(ln(this.pyEval(ne[1],r))){for(this.runBlockInScope(G,r),k+=1+G.length;k<t.length;){let Y=t[k].trim();if(this.getIndent(t[k])!==o||!Y.startsWith("elif")&&!Y.startsWith("else"))break;let te=this.collectBlock(t,k+1,o);k+=1+te.length}return k}k+=1+G.length;continue}if(P==="else:"){let G=this.collectBlock(t,k+1,o);return this.runBlockInScope(G,r),k+1+G.length}break}return k}let E=i.match(/^for\s+(.+?)\s+in\s+(.+?)\s*:$/);if(E){let[,B,b]=E,w=Nt(this.pyEval(b.trim(),r)),k=this.collectBlock(t,e+1,o),v=[],P=e+1+k.length;P<t.length&&t[P]?.trim()==="else:"&&(v=this.collectBlock(t,P+1,o),P+=1+v.length);let ne=!1;for(let G of w){if(B.includes(",")){let Y=B.split(",").map(le=>le.trim()),te=Array.isArray(G)?G:[G];Y.forEach((le,M)=>r.set(le,te[M]??z))}else r.set(B.trim(),G);try{this.runBlockInScope(k,r)}catch(Y){if(Y instanceof di){ne=!0;break}if(Y instanceof hi)continue;throw Y}}return!ne&&v.length&&this.runBlockInScope(v,r),P}let S=i.match(/^while\s+(.+?)\s*:$/);if(S){let B=S[1],b=this.collectBlock(t,e+1,o),w=0;for(;ln(this.pyEval(B,r))&&w++<1e5;)try{this.runBlockInScope(b,r)}catch(k){if(k instanceof di)break;if(k instanceof hi)continue;throw k}return e+1+b.length}if(i==="try:"){let B=this.collectBlock(t,e+1,o),b=e+1+B.length,w=[],k=[],v=[];for(;b<t.length;){let ne=t[b],G=ne.trim();if(this.getIndent(ne)!==o)break;if(G.startsWith("except")){let Y=G.match(/^except(?:\s+(\w+)(?:\s+as\s+(\w+))?)?\s*:$/),te=Y?.[1]??null,le=Y?.[2],M=this.collectBlock(t,b+1,o);w.push({exc:te,body:M}),le&&r.set(le,""),b+=1+M.length}else if(G==="else:")v=this.collectBlock(t,b+1,o),b+=1+v.length;else if(G==="finally:")k=this.collectBlock(t,b+1,o),b+=1+k.length;else break}let P=null;try{this.runBlockInScope(B,r),v.length&&this.runBlockInScope(v,r)}catch(ne){if(ne instanceof yt){P=ne;let G=!1;for(let Y of w)if(Y.exc===null||Y.exc===ne.type||Y.exc==="Exception"){this.runBlockInScope(Y.body,r),G=!0;break}if(!G)throw ne}else throw ne}finally{k.length&&this.runBlockInScope(k,r)}return b}let x=i.match(/^with\s+(.+?)\s+as\s+(\w+)\s*:$/);if(x){let B=this.collectBlock(t,e+1,o);return r.set(x[2],z),this.runBlockInScope(B,r),e+1+B.length}let R=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(\+=|-=|\*=|\/\/=|\/=|%=|\*\*=|&=|\|=)\s*(.+)$/);if(R){let[,B,b,w]=R,k=r.get(B)??0,v=this.pyEval(w,r),P;switch(b){case"+=":P=typeof k=="string"?k+Re(v):k+v;break;case"-=":P=k-v;break;case"*=":P=k*v;break;case"/=":P=k/v;break;case"//=":P=Math.floor(k/v);break;case"%=":P=k%v;break;case"**=":P=k**v;break;default:P=v}return r.set(B,P),e+1}let H=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\[(.+)\]\s*=\s*(.+)$/);if(H){let[,B,b,w]=H,k=r.get(B)??z,v=this.pyEval(w,r)??z,P=this.pyEval(b,r)??z;return Array.isArray(k)?k[P]=v:mt(k)&&k.data.set(Re(P),v),e+1}let C=i.match(/^([A-Za-z_][A-Za-z0-9_.]+)\s*=\s*(.+)$/);if(C){let B=C[1].lastIndexOf(".");if(B!==-1){let b=C[1].slice(0,B),w=C[1].slice(B+1),k=this.pyEval(C[2],r),v=this.pyEval(b,r);return mt(v)?v.data.set(w,k):ui(v)&&v.attrs.set(w,k),e+1}}let U=i.match(/^([A-Za-z_][A-Za-z0-9_,\s]*),\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$/);if(U){let B=this.pyEval(U[3],r),b=i.split("=")[0].split(",").map(k=>k.trim()),w=Nt(B);return b.forEach((k,v)=>r.set(k,w[v]??z)),e+1}let Q=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^=]+)?\s*=\s*(.+)$/);if(Q){let[,B,b]=Q;return r.set(B,this.pyEval(b,r)),e+1}try{this.pyEval(i,r)}catch(B){if(B instanceof yt||B instanceof pi)throw B}return e+1}runBlockInScope(t,e){this.execLines(t,0,e)}run(t){let e=dg(this.cwd);try{this.execScript(t,e)}catch(r){return r instanceof pi?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:r.code}:r instanceof yt?(this.stderr.push(r.toString()),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1}):r instanceof vr?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}:(this.stderr.push(`RuntimeError: ${r}`),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1})}return{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}}},hf={name:"python3",aliases:["python"],description:"Python 3 interpreter (virtual)",category:"system",params:["[--version] [-c <code>] [-V] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("python3"))return{stderr:`bash: python3: command not found
176
184
  Hint: install it with: apt install python3
177
- `,exitCode:127};if(se(n,["--version","-V"]))return{stdout:`${Kp}
178
- `,exitCode:0};if(se(n,["--version-full"]))return{stdout:`${ss}
185
+ `,exitCode:127};if(se(n,["--version","-V"]))return{stdout:`${fg}
186
+ `,exitCode:0};if(se(n,["--version-full"]))return{stdout:`${us}
179
187
  `,exitCode:0};let r=n.indexOf("-c");if(r!==-1){let i=n[r+1];if(!i)return{stderr:`python3: -c requires a code argument
180
188
  `,exitCode:1};let o=i.replace(/\\n/g,`
181
- `).replace(/\\t/g," "),a=new os(e),{stdout:c,stderr:f,exitCode:l}=a.run(o);return{stdout:c||void 0,stderr:f||void 0,exitCode:l}}let s=n.find(i=>!i.startsWith("-"));if(s){let i=le(e,s);if(!t.vfs.exists(i))return{stderr:`python3: can't open file '${s}': [Errno 2] No such file or directory
182
- `,exitCode:2};let o=t.vfs.readFile(i),a=new os(e),{stdout:c,stderr:f,exitCode:l}=a.run(o);return{stdout:c||void 0,stderr:f||void 0,exitCode:l}}return{stdout:`${ss}
189
+ `).replace(/\\t/g," "),a=new ds(e),{stdout:c,stderr:l,exitCode:f}=a.run(o);return{stdout:c||void 0,stderr:l||void 0,exitCode:f}}let s=n.find(i=>!i.startsWith("-"));if(s){let i=de(e,s);if(!t.vfs.exists(i))return{stderr:`python3: can't open file '${s}': [Errno 2] No such file or directory
190
+ `,exitCode:2};let o=t.vfs.readFile(i),a=new ds(e),{stdout:c,stderr:l,exitCode:f}=a.run(o);return{stdout:c||void 0,stderr:l||void 0,exitCode:f}}return{stdout:`${us}
183
191
  Type "help", "copyright", "credits" or "license" for more information.
184
- >>> `,exitCode:0}}};var cl={name:"read",description:"Read a line from stdin into variables",category:"shell",params:["[-r] [-p prompt] <var...>"],run:({args:n,stdin:t,env:e})=>{let r=n.indexOf("-p"),s=n.filter((a,c)=>a!=="-r"&&a!=="-p"&&n[c-1]!=="-p"),i=(t??"").split(`
192
+ >>> `,exitCode:0}}};var pf={name:"read",description:"Read a line from stdin into variables",category:"shell",params:["[-r] [-p prompt] <var...>"],run:({args:n,stdin:t,env:e})=>{let r=n.indexOf("-p"),s=n.filter((a,c)=>a!=="-r"&&a!=="-p"&&n[c-1]!=="-p"),i=(t??"").split(`
185
193
  `)[0]??"",o=se(n,["-r"])?i:i.replace(/\\(?:\r?\n|.)/g,a=>a[1]===`
186
- `||a[1]==="\r"?"":a[1]);if(!e)return{exitCode:0};if(s.length===0)e.vars.REPLY=o;else if(s.length===1)e.vars[s[0]]=o;else{let a=o.split(/\s+/);for(let c=0;c<s.length;c++)e.vars[s[c]]=c<s.length-1?a[c]??"":a.slice(c).join(" ")}return{exitCode:0}}};var fl={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 s=se(r,["-r","-rf","-fr"]),i=[];for(let o=0;;o+=1){let a=Tn(r,o,{flags:["-r","-rf","-fr"]});if(!a)break;i.push(a)}if(i.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of i){let a=le(e,o);Me(n,a,"rm"),t.vfs.remove(a,{recursive:s})}return{exitCode:0}}};var ll={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:s})=>{let i=se(r,["-i"]),o=zt(r,["-e"])??r.find(b=>!b.startsWith("-")),a=r.filter(b=>!b.startsWith("-")&&b!==o).pop();if(!o)return{stderr:"sed: no expression",exitCode:1};let c=s??"";if(a){let b=le(e,a);try{c=t.vfs.readFile(b)}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,p=(h??"").includes("i")?"gi":(h??"").includes("g")?"g":"",_;try{_=new RegExp(l,p||"")}catch{return{stderr:`sed: invalid regex: ${l}`,exitCode:1}}let E=((h??"").includes("g")||p.includes("g"),c.replace(_,u??""));if(i&&a){let b=le(e,a);return t.writeFileAsUser(n,b,E),{exitCode:0}}return{stdout:E,exitCode:0}}};var ul={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,s])=>`${r}=${s}`).join(`
187
- `),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}}};async function dl(n,t,e,r,s,i,o){let a={exitCode:0},c=[],f=s,l=0;for(;l<n.length;){let h=n[l];if(a=await Zp(h.pipeline,t,e,r,f,i,o),o.lastExitCode=a.exitCode??0,a.nextCwd&&(a.exitCode??0)===0&&(f=a.nextCwd),a.stdout&&c.push(a.stdout),a.closeSession||a.switchUser)return{...a,stdout:c.join("")||a.stdout};let p=h.op;if(!(!p||p===";")){if(p==="&&"){if((a.exitCode??0)!==0)for(;l<n.length&&n[l]?.op==="&&";)l++}else if(p==="||"&&(a.exitCode??0)===0)for(;l<n.length&&n[l]?.op==="||";)l++}l++}let u=c.join("");return{...a,stdout:u||a.stdout,nextCwd:f!==s?f:void 0}}async function Zp(n,t,e,r,s,i,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?eg(n.commands[0],t,e,r,s,i,a):tg(n.commands,t,e,r,s,i,a)}async function eg(n,t,e,r,s,i,o){let a;if(n.inputFile){let f=le(s,n.inputFile);try{a=i.vfs.readFile(f)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let c=await as(n.name,n.args,t,e,r,s,i,a,o);if(n.outputFile){let f=le(s,n.outputFile),l=c.stdout||"";try{if(n.appendOutput){let u=(()=>{try{return i.vfs.readFile(f)}catch{return""}})();i.writeFileAsUser(t,f,u+l)}else i.writeFileAsUser(t,f,l);return{...c,stdout:""}}catch{return{...c,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return c}async function tg(n,t,e,r,s,i,o){let a="",c=0;for(let f=0;f<n.length;f++){let l=n[f];if(f===0&&l.inputFile){let h=le(s,l.inputFile);try{a=i.vfs.readFile(h)}catch{return{stderr:`${l.inputFile}: No such file or directory`,exitCode:1}}}let u=await as(l.name,l.args,t,e,r,s,i,a,o);if(c=u.exitCode??0,f===n.length-1&&l.outputFile){let h=le(s,l.outputFile),p=u.stdout||"";try{if(l.appendOutput){let _=(()=>{try{return i.vfs.readFile(h)}catch{return""}})();i.writeFileAsUser(t,h,_+p)}else i.writeFileAsUser(t,h,p);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 di(n){let t=[],e="",r=!1,s="",i=0;for(;i<n.length;){let o=n[i],a=n[i+1];if((o==='"'||o==="'")&&!r){r=!0,s=o,i++;continue}if(r&&o===s){r=!1,s="",i++;continue}if(r){e+=o,i++;continue}if(o===" "){e&&(t.push(e),e=""),i++;continue}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),i+=2):(t.push(o),i++);continue}e+=o,i++}return e&&t.push(e),t}function hl(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:ng(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function ng(n){let t=rg(n),e=[];for(let r of t){let i={pipeline:{commands:ig(r.text.trim()),isValid:!0}};r.op&&(i.op=r.op),e.push(i)}return e}function rg(n){let t=[],e="",r=0,s=!1,i="",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==="'")&&!s){s=!0,i=c,e+=c,o++;continue}if(s&&c===i){s=!1,e+=c,o++;continue}if(s){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 ig(n){return sg(n).map(og)}function sg(n){let t=[],e="",r=!1,s="";for(let o=0;o<n.length;o++){let a=n[o];if((a==='"'||a==="'")&&!r){r=!0,s=a,e+=a;continue}if(r&&a===s){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 i=e.trim();if(!i&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return i&&t.push(i),t}function og(n){let t=di(n);if(t.length===0)return{name:"",args:[]};let e=[],r,s,i=!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 >>");s=t[o],i=!0,o++}else if(c===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");s=t[o],i=!1,o++}else e.push(c),o++}return{name:(e[0]??"").toLowerCase(),args:e.slice(1),inputFile:r,outputFile:s,appendOutput:i}}function vr(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}}function pl(n,t,e,r){if(n.startsWith("/")){if(!e.vfs.exists(n))return null;try{let i=e.vfs.stat(n);return i.type!=="file"||!(i.mode&73)||(n.startsWith("/sbin/")||n.startsWith("/usr/sbin/"))&&r!=="root"?null:n}catch{return null}}let s=(t.vars.PATH??"/usr/local/bin:/usr/bin:/bin").split(":");for(let i of s){if((i==="/sbin"||i==="/usr/sbin")&&r!=="root")continue;let o=`${i}/${n}`;if(e.vfs.exists(o))try{let a=e.vfs.stat(o);if(a.type!=="file"||!(a.mode&73))continue;return o}catch{}}return null}async function as(n,t,e,r,s,i,o,a,c){let f=c.vars[`__alias_${n}`];if(f)return yt(`${f} ${t.join(" ")}`,e,r,s,i,o,a,c);let l=In(n);if(!l){let u=pl(n,c,o,e);if(u){let h=o.vfs.readFile(u),p=h.match(/exec\s+builtin\s+(\S+)/);if(p){let E=In(p[1]);if(E)return await E.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:s,args:t,stdin:a,cwd:i,shell:o,env:c})}let _=In("sh");if(_)return await _.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(h)}`,mode:s,args:["-c",h,"--",...t],stdin:a,cwd:i,shell:o,env:c})}return{stderr:`${n}: command not found`,exitCode:127}}try{return await l.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:s,args:t,stdin:a,cwd:i,shell:o,env:c})}catch(u){return{stderr:u instanceof Error?u.message:"Command failed",exitCode:1}}}async function yt(n,t,e,r,s,i,o,a){let c=n.trim();if(c.length===0)return{exitCode:0};let f=a??vr(t,e),u=di(c)[0]?.toLowerCase()??"",h=f.vars[`__alias_${u}`],p=h?c.replace(u,h):c;if(/(?<![|&])[|](?![|])/.test(p)||p.includes(">")||p.includes("<")||p.includes("&&")||p.includes("||")||p.includes(";")){let C=hl(p);if(!C.isValid)return{stderr:C.error||"Syntax error",exitCode:1};try{return await dl(C.statements,t,e,r,s,i,f)}catch(F){return{stderr:F instanceof Error?F.message:"Execution failed",exitCode:1}}}let E=await Ji(p,f.vars,f.lastExitCode,C=>yt(C,t,e,r,s,i,void 0,f).then(F=>F.stdout??"")),b=di(E.trim()),v=b[0]?.toLowerCase()??"",U=b.slice(1),H=In(v);if(!H){let C=pl(v,f,i,t);if(C){let F=i.vfs.readFile(C),V=F.match(/exec\s+builtin\s+(\S+)/);if(V){let x=V[1],S=In(x);if(S)return await S.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:[v,...U].join(" "),mode:r,args:U,stdin:o,cwd:s,shell:i,env:f})}let N=In("sh");if(N)return await N.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(F)}`,mode:r,args:["-c",F,"--",...U],stdin:o,cwd:s,shell:i,env:f})}return{stderr:`${v}: command not found`,exitCode:127}}try{return await H.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:E,mode:r,args:U,stdin:o,cwd:s,shell:i,env:f})}catch(C){return{stderr:C instanceof Error?C.message:"Command failed",exitCode:1}}}async function yo(n,t,e,r){return Ji(n,t,e,s=>yt(s,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(i=>i.stdout??""))}function ar(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 s=r.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),i=[],o=[],a=[],c="then",f="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let l=n[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"?i.push(l):c==="elif"&&o.length>0?o[o.length-1].body.push(l):a.push(l)),e++}t.push({type:"if",cond:s,then_:i,elif:o,else_:a})}else if(r.startsWith("for ")){let s=r.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(s){let i=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let o=n[e].trim().replace(/^do\s+/,"");o&&o!=="do"&&i.push(o),e++}t.push({type:"for",var:s[1],list:s[2],body:i})}else t.push({type:"cmd",line:r})}else if(r.startsWith("while ")){let s=r.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),i=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let o=n[e].trim().replace(/^do\s+/,"");o&&o!=="do"&&i.push(o),e++}t.push({type:"while",cond:s,body:i})}else t.push({type:"cmd",line:r});e++}return t}async function Eo(n,t){let e=await yo(n,t.env.vars,t.env.lastExitCode,t),r=e.match(/^\[?\s*(.+?)\s*\]?$/);if(r){let i=r[1],o=i.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,f,l]=o,u=le(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=i.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,f,l,u]=a;if(l==="=="||l==="=")return f===u;if(l==="!=")return f!==u}let c=i.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,f,l,u]=c,h=Number(f),p=Number(u);if(l==="-eq")return h===p;if(l==="-ne")return h!==p;if(l==="-lt")return h<p;if(l==="-le")return h<=p;if(l==="-gt")return h>p;if(l==="-ge")return h>=p}}return((await yt(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function cr(n,t){let e={exitCode:0},r="";for(let s of n)if(s.type==="cmd"){let i=await yo(s.line,t.env.vars,t.env.lastExitCode,t),o=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)/,a=i.trim().split(/\s+/);if(a.length>0&&o.test(a[0])&&a.every(l=>o.test(l))){for(let l of a){let u=l.match(o);t.env.vars[u[1]]=u[2]}t.env.lastExitCode=0;continue}let c=await yt(i,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env);if(t.env.lastExitCode=c.exitCode??0,c.stdout&&(r+=`${c.stdout}
188
- `),c.stderr)return{...c,stdout:r.trim()};e=c}else if(s.type==="if"){let i=!1;if(await Eo(s.cond,t)){let o=await cr(ar(s.then_),t);o.stdout&&(r+=`${o.stdout}
189
- `),i=!0}else{for(let o of s.elif)if(await Eo(o.cond,t)){let a=await cr(ar(o.body),t);a.stdout&&(r+=`${a.stdout}
190
- `),i=!0;break}if(!i&&s.else_.length>0){let o=await cr(ar(s.else_),t);o.stdout&&(r+=`${o.stdout}
191
- `)}}}else if(s.type==="for"){let o=(await yo(s.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/);for(let a of o){t.env.vars[s.var]=a;let c=await cr(ar(s.body),t);if(c.stdout&&(r+=`${c.stdout}
192
- `),c.closeSession)return c}}else if(s.type==="while"){let i=0;for(;i<1e3&&await Eo(s.cond,t);){let o=await cr(ar(s.body),t);if(o.stdout&&(r+=`${o.stdout}
193
- `),o.closeSession)return o;i++}}return{...e,stdout:r.trim()||e.stdout}}var gl={name:"sh",aliases:["bash"],description:"Execute shell script or command",category:"shell",params:["-c <script>","[<file>]"],run:async n=>{let{args:t,shell:e,cwd:r}=n;if(se(t,"-c")){let i=t[t.indexOf("-c")+1]??"";if(!i)return{stderr:"sh: -c requires a script",exitCode:1};let o=i.split(/[;\n]/).map(c=>c.trim()).filter(c=>c&&!c.startsWith("#")),a=ar(o);return cr(a,n)}let s=t[0];if(s){let i=le(r,s);if(!e.vfs.exists(i))return{stderr:`sh: ${s}: No such file or directory`,exitCode:1};let a=e.vfs.readFile(i).split(`
194
- `).map(f=>f.trim()).filter(f=>f&&!f.startsWith("#")),c=ar(a);return cr(c,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var ml={name:"shift",description:"Shift positional parameters",category:"shell",params:["[n]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=parseInt(n[0]??"1",10)||1,r=t.vars.__argv?.split("\0").filter(Boolean)??[];t.vars.__argv=r.slice(e).join("\0");let s=r.slice(e);for(let i=1;i<=9;i++)t.vars[String(i)]=s[i-1]??"";return{exitCode:0}}},Al={name:"trap",description:"Trap signals and events",category:"shell",params:["[action] [signal...]"],run:({args:n,env:t})=>{if(!t||n.length===0)return{exitCode:0};let e=n[0]??"",r=n.slice(1);for(let s of r)t.vars[`__trap_${s.toUpperCase()}`]=e;return{exitCode:0}}},El={name:"return",description:"Return from a shell function",category:"shell",params:["[n]"],run:({args:n,env:t})=>{let e=parseInt(n[0]??"0",10);return t&&(t.lastExitCode=e),{exitCode:e}}};var yl={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 _l={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:s})=>{let i=se(r,["-r"]),o=se(r,["-n"]),a=se(r,["-u"]),c=r.filter(_=>!_.startsWith("-")),u=[...(c.length>0?c.map(_=>{try{return Me(n,le(e,_),"sort"),t.vfs.readFile(le(e,_))}catch{return""}}).join(`
194
+ `||a[1]==="\r"?"":a[1]);if(!e)return{exitCode:0};if(s.length===0)e.vars.REPLY=o;else if(s.length===1)e.vars[s[0]]=o;else{let a=o.split(/\s+/);for(let c=0;c<s.length;c++)e.vars[s[c]]=c<s.length-1?a[c]??"":a.slice(c).join(" ")}return{exitCode:0}}};var gf={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 s=se(r,["-r","-rf","-fr"]),i=[];for(let o=0;;o+=1){let a=$n(r,o,{flags:["-r","-rf","-fr"]});if(!a)break;i.push(a)}if(i.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of i){let a=de(e,o);Oe(n,a,"rm"),t.vfs.remove(a,{recursive:s})}return{exitCode:0}}};var mf={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:s})=>{let i=se(r,["-i"]),o=jt(r,["-e"])??r.find(S=>!S.startsWith("-")),a=r.filter(S=>!S.startsWith("-")&&S!==o).pop();if(!o)return{stderr:"sed: no expression",exitCode:1};let c=s??"";if(a){let S=de(e,a);try{c=t.vfs.readFile(S)}catch{return{stderr:`sed: ${a}: No such file or directory`,exitCode:1}}}let l=o.match(/^s([^a-zA-Z0-9])(.+?)\1(.*?)\1([gi]*)$/);if(!l)return{stderr:`sed: unrecognized command: ${o}`,exitCode:1};let[,,f,u,h]=l,p=(h??"").includes("i")?"gi":(h??"").includes("g")?"g":"",A;try{A=new RegExp(f,p||"")}catch{return{stderr:`sed: invalid regex: ${f}`,exitCode:1}}let E=((h??"").includes("g")||p.includes("g"),c.replace(A,u??""));if(i&&a){let S=de(e,a);return t.writeFileAsUser(n,S,E),{exitCode:0}}return{stdout:E,exitCode:0}}};var Af={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,s])=>`${r}=${s}`).join(`
195
+ `),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}}};async function yf(n,t,e,r,s,i,o){let a={exitCode:0},c=[],l=s,f=0;for(;f<n.length;){let h=n[f];if(a=await yg(h.pipeline,t,e,r,l,i,o),o.lastExitCode=a.exitCode??0,a.nextCwd&&(a.exitCode??0)===0&&(l=a.nextCwd),a.stdout&&c.push(a.stdout),a.closeSession||a.switchUser)return{...a,stdout:c.join("")||a.stdout};let p=h.op;if(!(!p||p===";")){if(p==="&&"){if((a.exitCode??0)!==0)for(;f<n.length&&n[f]?.op==="&&";)f++}else if(p==="||"&&(a.exitCode??0)===0)for(;f<n.length&&n[f]?.op==="||";)f++}f++}let u=c.join("");return{...a,stdout:u||a.stdout,nextCwd:l!==s?l:void 0}}async function yg(n,t,e,r,s,i,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?Eg(n.commands[0],t,e,r,s,i,a):_g(n.commands,t,e,r,s,i,a)}async function Eg(n,t,e,r,s,i,o){let a;if(n.inputFile){let l=de(s,n.inputFile);try{a=i.vfs.readFile(l)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let c=await Rr(n.name,n.args,t,e,r,s,i,a,o);if(n.outputFile){let l=de(s,n.outputFile),f=c.stdout||"";try{if(n.appendOutput){let u=(()=>{try{return i.vfs.readFile(l)}catch{return""}})();i.writeFileAsUser(t,l,u+f)}else i.writeFileAsUser(t,l,f);return{...c,stdout:""}}catch{return{...c,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return c}async function _g(n,t,e,r,s,i,o){let a="",c=0;for(let l=0;l<n.length;l++){let f=n[l];if(l===0&&f.inputFile){let h=de(s,f.inputFile);try{a=i.vfs.readFile(h)}catch{return{stderr:`${f.inputFile}: No such file or directory`,exitCode:1}}}let u=await Rr(f.name,f.args,t,e,r,s,i,a,o);if(c=u.exitCode??0,l===n.length-1&&f.outputFile){let h=de(s,f.outputFile),p=u.stdout||"";try{if(f.appendOutput){let A=(()=>{try{return i.vfs.readFile(h)}catch{return""}})();i.writeFileAsUser(t,h,A+p)}else i.writeFileAsUser(t,h,p);a=""}catch{return{stderr:`Failed to write to ${f.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 gi(n){let t=[],e="",r=!1,s="",i=0;for(;i<n.length;){let o=n[i],a=n[i+1];if((o==='"'||o==="'")&&!r){r=!0,s=o,i++;continue}if(r&&o===s){r=!1,s="",i++;continue}if(r){e+=o,i++;continue}if(o===" "){e&&(t.push(e),e=""),i++;continue}if(!r&&o==="2"&&a===">"){let c=n.slice(i+1);if(c.startsWith(">>&1")||c.startsWith(">> &1")){e&&(t.push(e),e=""),t.push("2>>&1"),i+=5;continue}if(c.startsWith(">&1")){e&&(t.push(e),e=""),t.push("2>&1"),i+=4;continue}if(c.startsWith(">>")){e&&(t.push(e),e=""),t.push("2>>"),i+=3;continue}if(c.startsWith(">")){e&&(t.push(e),e=""),t.push("2>"),i+=2;continue}}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),i+=2):(t.push(o),i++);continue}e+=o,i++}return e&&t.push(e),t}function Ef(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:bg(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function bg(n){let t=Sg(n),e=[];for(let r of t){let i={pipeline:{commands:xg(r.text.trim()),isValid:!0}};r.op&&(i.op=r.op),e.push(i)}return e}function Sg(n){let t=[],e="",r=0,s=!1,i="",o=0,a=c=>{e.trim()&&t.push({text:e,op:c}),e=""};for(;o<n.length;){let c=n[o],l=n.slice(o,o+2);if((c==='"'||c==="'")&&!s){s=!0,i=c,e+=c,o++;continue}if(s&&c===i){s=!1,e+=c,o++;continue}if(s){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(l==="&&"){a("&&"),o+=2;continue}if(l==="||"){a("||"),o+=2;continue}if(c===";"){a(";"),o++;continue}e+=c,o++}return a(),t}function xg(n){return wg(n).map(Ig)}function wg(n){let t=[],e="",r=!1,s="";for(let o=0;o<n.length;o++){let a=n[o];if((a==='"'||a==="'")&&!r){r=!0,s=a,e+=a;continue}if(r&&a===s){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 i=e.trim();if(!i&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return i&&t.push(i),t}function Ig(n){let t=gi(n);if(t.length===0)return{name:"",args:[]};let e=[],r,s,i=!1,o=0,a,c=!1,l=!1;for(;o<t.length;){let h=t[o];if(h==="<"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after <");r=t[o],o++}else if(h===">>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >>");s=t[o],i=!0,o++}else if(h===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");s=t[o],i=!1,o++}else if(h==="2>&1")l=!0,o++;else if(h==="2>>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after 2>>");a=t[o],c=!0,o++}else if(h==="2>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after 2>");a=t[o],c=!1,o++}else e.push(h),o++}let f=e[0]??"";return{name:/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(f)?f:f.toLowerCase(),args:e.slice(1),inputFile:r,outputFile:s,appendOutput:i,stderrFile:a,stderrAppend:c,stderrToStdout:l}}function Nr(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}}function _f(n,t,e,r){if(n.startsWith("/")){if(!e.vfs.exists(n))return null;try{let i=e.vfs.stat(n);return i.type!=="file"||!(i.mode&73)||(n.startsWith("/sbin/")||n.startsWith("/usr/sbin/"))&&r!=="root"?null:n}catch{return null}}let s=(t.vars.PATH??"/usr/local/bin:/usr/bin:/bin").split(":");for(let i of s){if((i==="/sbin"||i==="/usr/sbin")&&r!=="root")continue;let o=`${i}/${n}`;if(e.vfs.exists(o))try{let a=e.vfs.stat(o);if(a.type!=="file"||!(a.mode&73))continue;return o}catch{}}return null}async function Rr(n,t,e,r,s,i,o,a,c){let l=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/,f=[n,...t],u=0;for(;u<f.length&&l.test(f[u]);)u+=1;if(u>0){let A=f.slice(0,u).map(x=>x.match(l)),E=f.slice(u),S=[];for(let[,x,R]of A)S.push([x,c.vars[x]]),c.vars[x]=R;if(E.length===0)return{exitCode:0};try{return await Rr(E[0],E.slice(1),e,r,s,i,o,a,c)}finally{for(let[x,R]of S)R===void 0?delete c.vars[x]:c.vars[x]=R}}let h=c.vars[`__alias_${n}`];if(h)return St(`${h} ${t.join(" ")}`,e,r,s,i,o,a,c);let p=En(n);if(!p){let A=_f(n,c,o,e);if(A){let E=o.vfs.readFile(A),S=E.match(/exec\s+builtin\s+(\S+)/);if(S){let R=En(S[1]);if(R)return await R.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:s,args:t,stdin:a,cwd:i,shell:o,env:c})}let x=En("sh");if(x)return await x.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(E)}`,mode:s,args:["-c",E,"--",...t],stdin:a,cwd:i,shell:o,env:c})}return{stderr:`${n}: command not found`,exitCode:127}}try{return await p.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:s,args:t,stdin:a,cwd:i,shell:o,env:c})}catch(A){return{stderr:A instanceof Error?A.message:"Command failed",exitCode:1}}}async function St(n,t,e,r,s,i,o,a){let c=n.trim();if(c.length===0)return{exitCode:0};let l=a??Nr(t,e),u=gi(c)[0]?.toLowerCase()??"",h=l.vars[`__alias_${u}`],p=h?c.replace(u,h):c,A=/\bfor\s+\w+\s+in\b/.test(p)||/\bwhile\s+/.test(p)||/\bif\s+/.test(p)||/\w+\s*\(\s*\)\s*\{/.test(p)||/\bfunction\s+\w+/.test(p)||/\(\(\s*.+\s*\)\)/.test(p),E=/(?<![|&])[|](?![|])/.test(p)||p.includes(">")||p.includes("<")||p.includes("&&")||p.includes("||")||p.includes(";");if(A&&u!=="sh"&&u!=="bash"||E){if(A&&u!=="sh"&&u!=="bash"){let B=En("sh");if(B)return await B.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:p,mode:r,args:["-c",p],stdin:void 0,cwd:s,shell:i,env:l})}let Q=Ef(p);if(!Q.isValid)return{stderr:Q.error||"Syntax error",exitCode:1};try{return await yf(Q.statements,t,e,r,s,i,l)}catch(B){return{stderr:B instanceof Error?B.message:"Execution failed",exitCode:1}}}let S=await rs(p,l.vars,l.lastExitCode,Q=>St(Q,t,e,r,s,i,void 0,l).then(B=>B.stdout??"")),x=gi(S.trim());if(x.length===0)return{exitCode:0};if(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(x[0]))return Rr(x[0],x.slice(1),t,e,r,s,i,o,l);let H=x[0]?.toLowerCase()??"",C=x.slice(1).flatMap(ns),U=En(H);if(!U){let Q=_f(H,l,i,t);if(Q){let B=i.vfs.readFile(Q),b=B.match(/exec\s+builtin\s+(\S+)/);if(b){let k=b[1],v=En(k);if(v)return await v.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:[H,...C].join(" "),mode:r,args:C,stdin:o,cwd:s,shell:i,env:l})}let w=En("sh");if(w)return await w.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(B)}`,mode:r,args:["-c",B,"--",...C],stdin:o,cwd:s,shell:i,env:l})}return{stderr:`${H}: command not found`,exitCode:127}}try{return await U.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:S,mode:r,args:C,stdin:o,cwd:s,shell:i,env:l})}catch(Q){return{stderr:Q instanceof Error?Q.message:"Command failed",exitCode:1}}}async function Co(n,t,e,r){return rs(n,t,e,s=>St(s,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(i=>i.stdout??""))}function Vn(n){let t=[],e=0;for(;e<n.length;){let r=n[e].trim();if(!r||r.startsWith("#")){e++;continue}let s=r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{(.+)\}\s*$/),i=s??(r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{?\s*$/)||r.match(/^function\s+(\w+)\s*\{?\s*$/));if(i){let a=i[1],c=[];if(s){c.push(...s[2].split(";").map(l=>l.trim()).filter(Boolean)),t.push({type:"func",name:a,body:c}),e++;continue}for(e++;e<n.length&&n[e]?.trim()!=="}"&&e<n.length+1;){let l=n[e].trim().replace(/^do\s+/,"");l&&l!=="{"&&c.push(l),e++}e++,t.push({type:"func",name:a,body:c});continue}let o=r.match(/^\(\(\s*(.+?)\s*\)\)$/);if(o){t.push({type:"arith",expr:o[1]}),e++;continue}if(r.startsWith("if ")||r==="if"){let a=r.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),c=[],l=[],f=[],u="then",h="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let p=n[e].trim();p.startsWith("elif ")?(u="elif",h=p.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),l.push({cond:h,body:[]})):p==="else"?u="else":p!=="then"&&(u==="then"?c.push(p):u==="elif"&&l.length>0?l[l.length-1].body.push(p):f.push(p)),e++}t.push({type:"if",cond:a,then_:c,elif:l,else_:f})}else if(r.startsWith("for ")){let a=r.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(a){let c=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let l=n[e].trim().replace(/^do\s+/,"");l&&l!=="do"&&c.push(l),e++}t.push({type:"for",var:a[1],list:a[2],body:c})}else t.push({type:"cmd",line:r})}else if(r.startsWith("while ")){let a=r.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),c=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let l=n[e].trim().replace(/^do\s+/,"");l&&l!=="do"&&c.push(l),e++}t.push({type:"while",cond:a,body:c})}else t.push({type:"cmd",line:r});e++}return t}async function Io(n,t){let e=await Co(n,t.env.vars,t.env.lastExitCode,t),r=e.match(/^\[?\s*(.+?)\s*\]?$/);if(r){let i=r[1],o=i.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,l,f]=o,u=de(t.cwd,f);if(l==="f")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="file";if(l==="d")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="directory";if(l==="e")return t.shell.vfs.exists(u);if(l==="z")return(f??"").length===0;if(l==="n")return(f??"").length>0}let a=i.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,l,f,u]=a;if(f==="=="||f==="=")return l===u;if(f==="!=")return l!==u}let c=i.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,l,f,u]=c,h=Number(l),p=Number(u);if(f==="-eq")return h===p;if(f==="-ne")return h!==p;if(f==="-lt")return h<p;if(f==="-le")return h<=p;if(f==="-gt")return h>p;if(f==="-ge")return h>=p}}return((await St(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function zn(n,t){let e={exitCode:0},r="";for(let s of n)if(s.type==="cmd"){let i=await Co(s.line,t.env.vars,t.env.lastExitCode,t),o=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)/,a=i.trim().split(/\s+/);if(a.length>0&&o.test(a[0])&&a.every(f=>o.test(f))){for(let f of a){let u=f.match(o);t.env.vars[u[1]]=u[2]}t.env.lastExitCode=0;continue}let c=await(async()=>{let l=i.trim().split(/\s+/)[0]??"",f=t.env.vars[`__func_${l}`];if(f){let u=i.trim().split(/\s+/).slice(1),h={...t.env.vars};u.forEach((E,S)=>{t.env.vars[String(S+1)]=E}),t.env.vars[0]=l;let p=f.split(`
196
+ `),A=await zn(Vn(p),t);for(let E=1;E<=u.length;E++)delete t.env.vars[String(E)];return Object.assign(t.env.vars,{...h,...t.env.vars}),A}return St(i,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)})();if(t.env.lastExitCode=c.exitCode??0,c.stdout&&(r+=`${c.stdout}
197
+ `),c.stderr)return{...c,stdout:r.trim()};e=c}else if(s.type==="if"){let i=!1;if(await Io(s.cond,t)){let o=await zn(Vn(s.then_),t);o.stdout&&(r+=`${o.stdout}
198
+ `),i=!0}else{for(let o of s.elif)if(await Io(o.cond,t)){let a=await zn(Vn(o.body),t);a.stdout&&(r+=`${a.stdout}
199
+ `),i=!0;break}if(!i&&s.else_.length>0){let o=await zn(Vn(s.else_),t);o.stdout&&(r+=`${o.stdout}
200
+ `)}}}else if(s.type==="func")t.env.vars[`__func_${s.name}`]=s.body.join(`
201
+ `);else if(s.type==="arith"){let i=s.expr.trim(),o=i.match(/^(\w+)\s*(\+\+|--)$/);if(o){let a=parseInt(t.env.vars[o[1]]??"0",10);t.env.vars[o[1]]=String(o[2]==="++"?a+1:a-1)}else{let a=i.match(/^(\w+)\s*([+\-*/])=\s*(.+)$/);if(a){let c=parseInt(t.env.vars[a[1]]??"0",10),l=parseInt(a[3],10),f={"+":c+l,"-":c-l,"*":c*l,"/":Math.floor(c/l)};t.env.vars[a[1]]=String(f[a[2]]??c)}else{let c=yo(i,t.env.vars);Number.isNaN(c)||(t.env.lastExitCode=c===0?1:0)}}}else if(s.type==="for"){let o=(await Co(s.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/).flatMap(ns);for(let a of o){t.env.vars[s.var]=a;let c=await zn(Vn(s.body),t);if(c.stdout&&(r+=`${c.stdout}
202
+ `),c.closeSession)return c}}else if(s.type==="while"){let i=0;for(;i<1e3&&await Io(s.cond,t);){let o=await zn(Vn(s.body),t);if(o.stdout&&(r+=`${o.stdout}
203
+ `),o.closeSession)return o;i++}}return{...e,stdout:r.trim()||e.stdout}}function bf(n){let t=[],e="",r=0,s=!1,i=!1,o=0;for(;o<n.length;){let c=n[o];if(!s&&!i){if(c==="'"){s=!0,e+=c,o++;continue}if(c==='"'){i=!0,e+=c,o++;continue}if(c==="{"){r++,e+=c,o++;continue}if(c==="}"){if(r--,e+=c,o++,r===0){let l=e.trim();for(l&&t.push(l),e="";o<n.length&&(n[o]===";"||n[o]===" ");)o++}continue}if(r===0&&(c===";"||c===`
204
+ `)){let l=e.trim();l&&!l.startsWith("#")&&t.push(l),e="",o++;continue}}else s&&c==="'"?s=!1:i&&c==='"'&&(i=!1);e+=c,o++}let a=e.trim();return a&&!a.startsWith("#")&&t.push(a),t}var Sf={name:"sh",aliases:["bash"],description:"Execute shell script or command",category:"shell",params:["-c <script>","[<file>]"],run:async n=>{let{args:t,shell:e,cwd:r}=n;if(se(t,"-c")){let i=t[t.indexOf("-c")+1]??"";if(!i)return{stderr:"sh: -c requires a script",exitCode:1};let o=bf(i),a=Vn(o);return zn(a,n)}let s=t[0];if(s){let i=de(r,s);if(!e.vfs.exists(i))return{stderr:`sh: ${s}: No such file or directory`,exitCode:1};let o=e.vfs.readFile(i),a=bf(o),c=Vn(a);return zn(c,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var xf={name:"shift",description:"Shift positional parameters",category:"shell",params:["[n]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=parseInt(n[0]??"1",10)||1,r=t.vars.__argv?.split("\0").filter(Boolean)??[];t.vars.__argv=r.slice(e).join("\0");let s=r.slice(e);for(let i=1;i<=9;i++)t.vars[String(i)]=s[i-1]??"";return{exitCode:0}}},wf={name:"trap",description:"Trap signals and events",category:"shell",params:["[action] [signal...]"],run:({args:n,env:t})=>{if(!t||n.length===0)return{exitCode:0};let e=n[0]??"",r=n.slice(1);for(let s of r)t.vars[`__trap_${s.toUpperCase()}`]=e;return{exitCode:0}}},If={name:"return",description:"Return from a shell function",category:"shell",params:["[n]"],run:({args:n,env:t})=>{let e=parseInt(n[0]??"0",10);return t&&(t.lastExitCode=e),{exitCode:e}}};var Cf={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 kf={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:s})=>{let i=se(r,["-r"]),o=se(r,["-n"]),a=se(r,["-u"]),c=r.filter(A=>!A.startsWith("-")),u=[...(c.length>0?c.map(A=>{try{return Oe(n,de(e,A),"sort"),t.vfs.readFile(de(e,A))}catch{return""}}).join(`
195
205
  `):s??"").split(`
196
- `).filter(Boolean)].sort((_,E)=>o?Number(_)-Number(E):_.localeCompare(E)),h=i?u.reverse():u;return{stdout:(a?[...new Set(h)]:h).join(`
197
- `),exitCode:0}}};var bl={name:"source",aliases:["."],description:"Execute commands from a file in the current shell environment",category:"shell",params:["<file> [args...]"],run:async({args:n,authUser:t,hostname:e,cwd:r,shell:s,env:i})=>{let o=n[0];if(!o)return{stderr:"source: missing filename",exitCode:1};let a=le(r,o);if(!s.vfs.exists(a))return{stderr:`source: ${o}: No such file or directory`,exitCode:1};let c=s.vfs.readFile(a),f=0;for(let l of c.split(`
198
- `)){let u=l.trim();if(!u||u.startsWith("#"))continue;let h=await yt(u,t,e,"shell",r,s,void 0,i);if(f=h.exitCode??0,h.closeSession||h.switchUser)return h}return{exitCode:f}}};var xl={name:"su",description:"Switch user",category:"users",params:["[-] [-c <cmd>] [username]"],run:async({authUser:n,shell:t,args:e,hostname:r,mode:s,cwd:i})=>{let o=e.includes("-")||e.includes("-l")||e.includes("--login"),a=e.indexOf("-c"),c=a!==-1?e[a+1]:void 0,l=e.filter((u,h)=>h!==a&&h!==a+1).filter(u=>u!=="-"&&u!=="-l"&&u!=="--login").find(u=>!u.startsWith("-"))??"root";return t.users.listUsers().includes(l)?n==="root"?c?yt(c,l,r,s,o?`/home/${l}`:i,t):{switchUser:l,nextCwd:o?`/home/${l}`:void 0,exitCode:0}:t.users.isSudoer(n)?{sudoChallenge:{username:l,targetUser:l,commandLine:c??null,loginShell:o,prompt:"Password: "},exitCode:0}:{stderr:`su: permission denied
199
- `,exitCode:1}:{stderr:`su: user '${l}' does not exist
200
- `,exitCode:1}}};function ag(n){let{flags:t,flagsWithValues:e,positionals:r}=Yt(n,{flags:["-i","-S"],flagsWithValue:["-u","--user"]}),s=t.has("-i"),i=e.get("-u")||e.get("--user")||"root",o=r.length>0?r.join(" "):null;return{targetUser:i,loginShell:s,commandLine:o}}var Sl={name:"sudo",description:"Execute as superuser",category:"users",params:["<command...>"],run:async({authUser:n,hostname:t,mode:e,cwd:r,shell:s,args:i})=>{let{targetUser:o,loginShell:a,commandLine:c}=ag(i);if(n!=="root"&&!s.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let f=o||"root",l=`[sudo] password for ${n}: `;return n==="root"?!c&&a?{switchUser:f,nextCwd:`/home/${f}`,exitCode:0}:c?yt(c,f,t,e,a?`/home/${f}`:r,s):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:n,targetUser:f,commandLine:c,loginShell:a,prompt:l},exitCode:0}}};var wl={name:"tail",description:"Output last lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=zt(r,["-n"]),o=r.find(u=>/^-\d+$/.test(u)),a=typeof i=="string"?parseInt(i,10):o?parseInt(o.slice(1),10):10,c=r.filter(u=>!u.startsWith("-")&&u!==i&&u!==String(a)),f=u=>{let h=u.split(`
206
+ `).filter(Boolean)].sort((A,E)=>o?Number(A)-Number(E):A.localeCompare(E)),h=i?u.reverse():u;return{stdout:(a?[...new Set(h)]:h).join(`
207
+ `),exitCode:0}}};var vf={name:"source",aliases:["."],description:"Execute commands from a file in the current shell environment",category:"shell",params:["<file> [args...]"],run:async({args:n,authUser:t,hostname:e,cwd:r,shell:s,env:i})=>{let o=n[0];if(!o)return{stderr:"source: missing filename",exitCode:1};let a=de(r,o);if(!s.vfs.exists(a))return{stderr:`source: ${o}: No such file or directory`,exitCode:1};let c=s.vfs.readFile(a),l=0;for(let f of c.split(`
208
+ `)){let u=f.trim();if(!u||u.startsWith("#"))continue;let h=await St(u,t,e,"shell",r,s,void 0,i);if(l=h.exitCode??0,h.closeSession||h.switchUser)return h}return{exitCode:l}}};var Bf={name:"su",description:"Switch user",category:"users",params:["[-] [-c <cmd>] [username]"],run:async({authUser:n,shell:t,args:e,hostname:r,mode:s,cwd:i})=>{let o=e.includes("-")||e.includes("-l")||e.includes("--login"),a=e.indexOf("-c"),c=a!==-1?e[a+1]:void 0,f=e.filter((u,h)=>h!==a&&h!==a+1).filter(u=>u!=="-"&&u!=="-l"&&u!=="--login").find(u=>!u.startsWith("-"))??"root";return t.users.listUsers().includes(f)?n==="root"?c?St(c,f,r,s,o?`/home/${f}`:i,t):{switchUser:f,nextCwd:o?`/home/${f}`:void 0,exitCode:0}:t.users.isSudoer(n)?{sudoChallenge:{username:f,targetUser:f,commandLine:c??null,loginShell:o,prompt:"Password: "},exitCode:0}:{stderr:`su: permission denied
209
+ `,exitCode:1}:{stderr:`su: user '${f}' does not exist
210
+ `,exitCode:1}}};function Cg(n){let{flags:t,flagsWithValues:e,positionals:r}=Xt(n,{flags:["-i","-S"],flagsWithValue:["-u","--user"]}),s=t.has("-i"),i=e.get("-u")||e.get("--user")||"root",o=r.length>0?r.join(" "):null;return{targetUser:i,loginShell:s,commandLine:o}}var Rf={name:"sudo",description:"Execute as superuser",category:"users",params:["<command...>"],run:async({authUser:n,hostname:t,mode:e,cwd:r,shell:s,args:i})=>{let{targetUser:o,loginShell:a,commandLine:c}=Cg(i);if(n!=="root"&&!s.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let l=o||"root",f=`[sudo] password for ${n}: `;return n==="root"?!c&&a?{switchUser:l,nextCwd:`/home/${l}`,exitCode:0}:c?St(c,l,t,e,a?`/home/${l}`:r,s):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:n,targetUser:l,commandLine:c,loginShell:a,prompt:f},exitCode:0}}};var Nf={name:"tail",description:"Output last lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=jt(r,["-n"]),o=r.find(u=>/^-\d+$/.test(u)),a=typeof i=="string"?parseInt(i,10):o?parseInt(o.slice(1),10):10,c=r.filter(u=>!u.startsWith("-")&&u!==i&&u!==String(a)),l=u=>{let h=u.split(`
201
211
  `),p=u.endsWith(`
202
- `),_=p?h.slice(0,-1):h;return _.slice(Math.max(0,_.length-a)).join(`
212
+ `),A=p?h.slice(0,-1):h;return A.slice(Math.max(0,A.length-a)).join(`
203
213
  `)+(p?`
204
- `:"")};if(c.length===0)return{stdout:f(s??""),exitCode:0};let l=[];for(let u of c){let h=le(e,u);try{Me(n,h,"tail"),l.push(f(t.vfs.readFile(h)))}catch{return{stderr:`tail: ${u}: No such file or directory`,exitCode:1}}}return{stdout:l.join(`
205
- `),exitCode:0}}};var Il={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=[],i=!1;for(let h of r)if(/^-[a-zA-Z]{2,}$/.test(h))for(let p of h.slice(1))s.push(`-${p}`);else if(!i&&/^[cxtdru]{1,}[a-zA-Z]*$/.test(h)&&!h.includes("/")&&!h.startsWith("-")){i=!0;for(let p of h)s.push(`-${p}`)}else s.push(h);let o=s.includes("-c"),a=s.includes("-x"),c=s.includes("-t"),f=s.indexOf("-f"),l=f!==-1?s[f+1]:s.find(h=>h.endsWith(".tar")||h.endsWith(".tar.gz")||h.endsWith(".tgz"));if(!o&&!a&&!c)return{stderr:`tar: must specify -c, -x, or -t
206
- `,exitCode:1};if(!l)return{stderr:`tar: no archive specified
207
- `,exitCode:1};let u=le(e,l);if(o){let h=new Set;f!==-1&&h.add(f+1);let p=s.filter((E,b)=>!E.startsWith("-")&&E!==l&&!h.has(b)),_={};for(let E of p){let b=le(e,E);try{if(t.vfs.stat(b).type==="file")_[E]=t.vfs.readFile(b);else{let U=(H,C)=>{for(let F of t.vfs.list(H)){let V=`${H}/${F}`,N=`${C}/${F}`;t.vfs.stat(V).type==="file"?_[N]=t.vfs.readFile(V):U(V,N)}};U(b,E)}}catch{return{stderr:`tar: ${E}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,u,JSON.stringify(_)),{exitCode:0}}if(c||a){let h;try{h=JSON.parse(t.vfs.readFile(u))}catch{return{stderr:`tar: ${l}: cannot open archive`,exitCode:1}}if(c)return{stdout:Object.keys(h).join(`
208
- `),exitCode:0};for(let[p,_]of Object.entries(h))t.writeFileAsUser(n,le(e,p),_);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var Cl={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:s})=>{let i=se(r,["-a"]),o=r.filter(c=>!c.startsWith("-")),a=s??"";for(let c of o){let f=le(e,c);if(i){let l=(()=>{try{return t.vfs.readFile(f)}catch{return""}})();t.writeFileAsUser(n,f,l+a)}else t.writeFileAsUser(n,f,a)}return{stdout:a,exitCode:0}}};function kr(n,t,e){if(n[n.length-1]==="]"&&(n=n.slice(0,-1)),n[0]==="["&&(n=n.slice(1)),n.length===0)return!1;if(n[0]==="!")return!kr(n.slice(1),t,e);let r=n.indexOf("-a");if(r!==-1)return kr(n.slice(0,r),t,e)&&kr(n.slice(r+1),t,e);let s=n.indexOf("-o");if(s!==-1)return kr(n.slice(0,s),t,e)||kr(n.slice(s+1),t,e);if(n.length===2){let[i,o=""]=n,c=(f=>f.startsWith("/")?f:`${e}/${f}`.replace(/\/+/g,"/"))(o);switch(i){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(n.length===3){let[i="",o,a=""]=n,c=Number(i),f=Number(a);switch(o){case"=":case"==":return i===a;case"!=":return i!==a;case"<":return i<a;case">":return i>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 n.length===1?(n[0]??"").length>0:!1}var vl={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:n,shell:t,cwd:e})=>{try{return{exitCode:kr([...n],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var kl={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 s of r){let i=le(e,s);Me(n,i,"touch"),t.vfs.exists(i)||t.writeFileAsUser(n,i,"")}return{exitCode:0}}};function cg(n){return n.replace(/\\n/g,`
209
- `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function Bl(n){let t=[],e=cg(n),r=0;for(;r<e.length;){if(r+2<e.length&&e[r+1]==="-"){let s=e.charCodeAt(r),i=e.charCodeAt(r+2);if(s<=i){for(let o=s;o<=i;o++)t.push(String.fromCharCode(o));r+=3;continue}}t.push(e[r]),r++}return t}var Rl={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] [-s] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=se(n,["-d"]),r=se(n,["-s"]),s=n.filter(c=>!c.startsWith("-")),i=Bl(s[0]??""),o=Bl(s[1]??""),a=t??"";if(e){let c=new Set(i);a=[...a].filter(f=>!c.has(f)).join("")}else if(o.length>0){let c=new Map;for(let f=0;f<i.length;f++)c.set(i[f],o[f]??o[o.length-1]??"");a=[...a].map(f=>c.get(f)??f).join("")}if(r&&o.length>0){let c=new Set(o);a=a.replace(/(.)\1+/g,(f,l)=>c.has(l)?l:f)}return{stdout:a,exitCode:0}}};var Nl={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=le(e,Tn(r,0)??e);return Me(n,s,"tree"),{stdout:t.vfs.tree(s),exitCode:0}}};var Pl={name:"true",description:"Return success exit code",category:"shell",params:[],run:()=>({exitCode:0})},Tl={name:"false",description:"Return failure exit code",category:"shell",params:[],run:()=>({exitCode:1})};var Ll={name:"type",description:"Describe how a command would be interpreted",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"type: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),s=[],i=0;for(let o of n){if(In(o)){s.push(`${o} is a shell builtin`);continue}let a=!1;for(let c of r){let f=`${c}/${o}`;if(t.vfs.exists(f)){s.push(`${o} is ${f}`),a=!0;break}}a||(s.push(`${o}: not found`),i=1)}return{stdout:s.join(`
210
- `),exitCode:i}}};var Dl={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=se(t,["-a"]),r="Linux",s=n.properties?.kernel??"5.15.0",i=n.properties?.arch??"x86_64",o=n.hostname;return e?{stdout:`${r} ${o} ${s} #1 SMP ${i} GNU/Linux`,exitCode:0}:se(t,["-r"])?{stdout:s,exitCode:0}:se(t,["-m"])?{stdout:i,exitCode:0}:{stdout:r,exitCode:0}}};var Ul={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=se(n,["-c"]),r=se(n,["-d"]),s=se(n,["-u"]),i=(t??"").split(`
211
- `),o=[],a=0;for(;a<i.length;){let c=a;for(;c<i.length&&i[c]===i[a];)c++;let f=c-a,l=i[a];if(r&&f===1){a=c;continue}if(s&&f>1){a=c;continue}o.push(e?`${String(f).padStart(4)} ${l}`:l),a=c}return{stdout:o.join(`
212
- `),exitCode:0}}};var $l={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 Ml={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:n,shell:t})=>{let e=se(n,["-p"]),r=se(n,["-s"]),s=Math.floor((Date.now()-t.startTime)/1e3),i=Math.floor(s/86400),o=Math.floor(s%86400/3600),a=Math.floor(s%3600/60);if(r)return{stdout:new Date(t.startTime).toISOString().slice(0,19).replace("T"," "),exitCode:0};if(e){let h=[];return i>0&&h.push(`${i} day${i>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=i>0?`${i} day${i>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 Ol={name:"wc",description:"Count words/lines/bytes",category:"text",params:["[-l] [-w] [-c] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=se(r,["-l"]),o=se(r,["-w"]),a=se(r,["-c"]),c=!i&&!o&&!a,f=r.filter(h=>!h.startsWith("-")),l=(h,p)=>{let _=h.split(`
213
- `).length-(h.endsWith(`
214
- `)?1:0),E=h.trim().split(/\s+/).filter(Boolean).length,b=Buffer.byteLength(h,"utf8"),v=[];return(c||i)&&v.push(String(_).padStart(7)),(c||o)&&v.push(String(E).padStart(7)),(c||a)&&v.push(String(b).padStart(7)),p&&v.push(` ${p}`),v.join("")};if(f.length===0)return{stdout:l(s??"",""),exitCode:0};let u=[];for(let h of f){let p=le(e,h);try{Me(n,p,"wc");let _=t.vfs.readFile(p);u.push(l(_,h))}catch{return{stderr:`wc: ${h}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
215
- `),exitCode:0}}};var Fl={name:"wget",description:"File downloader (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:s,positionals:i}=Yt(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(`
214
+ `:"")};if(c.length===0)return{stdout:l(s??""),exitCode:0};let f=[];for(let u of c){let h=de(e,u);try{Oe(n,h,"tail"),f.push(l(t.vfs.readFile(h)))}catch{return{stderr:`tail: ${u}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
215
+ `),exitCode:0}}};var Pf={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=[],i=!1;for(let h of r)if(/^-[a-zA-Z]{2,}$/.test(h))for(let p of h.slice(1))s.push(`-${p}`);else if(!i&&/^[cxtdru]{1,}[a-zA-Z]*$/.test(h)&&!h.includes("/")&&!h.startsWith("-")){i=!0;for(let p of h)s.push(`-${p}`)}else s.push(h);let o=s.includes("-c"),a=s.includes("-x"),c=s.includes("-t"),l=s.indexOf("-f"),f=l!==-1?s[l+1]:s.find(h=>h.endsWith(".tar")||h.endsWith(".tar.gz")||h.endsWith(".tgz"));if(!o&&!a&&!c)return{stderr:`tar: must specify -c, -x, or -t
216
+ `,exitCode:1};if(!f)return{stderr:`tar: no archive specified
217
+ `,exitCode:1};let u=de(e,f);if(o){let h=new Set;l!==-1&&h.add(l+1);let p=s.filter((E,S)=>!E.startsWith("-")&&E!==f&&!h.has(S)),A={};for(let E of p){let S=de(e,E);try{if(t.vfs.stat(S).type==="file")A[E]=t.vfs.readFile(S);else{let R=(H,C)=>{for(let U of t.vfs.list(H)){let Q=`${H}/${U}`,B=`${C}/${U}`;t.vfs.stat(Q).type==="file"?A[B]=t.vfs.readFile(Q):R(Q,B)}};R(S,E)}}catch{return{stderr:`tar: ${E}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,u,JSON.stringify(A)),{exitCode:0}}if(c||a){let h;try{h=JSON.parse(t.vfs.readFile(u))}catch{return{stderr:`tar: ${f}: cannot open archive`,exitCode:1}}if(c)return{stdout:Object.keys(h).join(`
218
+ `),exitCode:0};for(let[p,A]of Object.entries(h))t.writeFileAsUser(n,de(e,p),A);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var Tf={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:s})=>{let i=se(r,["-a"]),o=r.filter(c=>!c.startsWith("-")),a=s??"";for(let c of o){let l=de(e,c);if(i){let f=(()=>{try{return t.vfs.readFile(l)}catch{return""}})();t.writeFileAsUser(n,l,f+a)}else t.writeFileAsUser(n,l,a)}return{stdout:a,exitCode:0}}};function Pr(n,t,e){if(n[n.length-1]==="]"&&(n=n.slice(0,-1)),n[0]==="["&&(n=n.slice(1)),n.length===0)return!1;if(n[0]==="!")return!Pr(n.slice(1),t,e);let r=n.indexOf("-a");if(r!==-1)return Pr(n.slice(0,r),t,e)&&Pr(n.slice(r+1),t,e);let s=n.indexOf("-o");if(s!==-1)return Pr(n.slice(0,s),t,e)||Pr(n.slice(s+1),t,e);if(n.length===2){let[i,o=""]=n,c=(l=>l.startsWith("/")?l:`${e}/${l}`.replace(/\/+/g,"/"))(o);switch(i){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(n.length===3){let[i="",o,a=""]=n,c=Number(i),l=Number(a);switch(o){case"=":case"==":return i===a;case"!=":return i!==a;case"<":return i<a;case">":return i>a;case"-eq":return c===l;case"-ne":return c!==l;case"-lt":return c<l;case"-le":return c<=l;case"-gt":return c>l;case"-ge":return c>=l}}return n.length===1?(n[0]??"").length>0:!1}var Lf={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:n,shell:t,cwd:e})=>{try{return{exitCode:Pr([...n],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var $f={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 s of r){let i=de(e,s);Oe(n,i,"touch"),t.vfs.exists(i)||t.writeFileAsUser(n,i,"")}return{exitCode:0}}};function kg(n){return n.replace(/\\n/g,`
219
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function Df(n){let t=[],e=kg(n),r=0;for(;r<e.length;){if(r+2<e.length&&e[r+1]==="-"){let s=e.charCodeAt(r),i=e.charCodeAt(r+2);if(s<=i){for(let o=s;o<=i;o++)t.push(String.fromCharCode(o));r+=3;continue}}t.push(e[r]),r++}return t}var Uf={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] [-s] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=se(n,["-d"]),r=se(n,["-s"]),s=n.filter(c=>!c.startsWith("-")),i=Df(s[0]??""),o=Df(s[1]??""),a=t??"";if(e){let c=new Set(i);a=[...a].filter(l=>!c.has(l)).join("")}else if(o.length>0){let c=new Map;for(let l=0;l<i.length;l++)c.set(i[l],o[l]??o[o.length-1]??"");a=[...a].map(l=>c.get(l)??l).join("")}if(r&&o.length>0){let c=new Set(o);a=a.replace(/(.)\1+/g,(l,f)=>c.has(f)?f:l)}return{stdout:a,exitCode:0}}};var Mf={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=de(e,$n(r,0)??e);return Oe(n,s,"tree"),{stdout:t.vfs.tree(s),exitCode:0}}};var Of={name:"true",description:"Return success exit code",category:"shell",params:[],run:()=>({exitCode:0})},Ff={name:"false",description:"Return failure exit code",category:"shell",params:[],run:()=>({exitCode:1})};var Hf={name:"type",description:"Describe how a command would be interpreted",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"type: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),s=[],i=0;for(let o of n){if(En(o)){s.push(`${o} is a shell builtin`);continue}let a=!1;for(let c of r){let l=`${c}/${o}`;if(t.vfs.exists(l)){s.push(`${o} is ${l}`),a=!0;break}}a||(s.push(`${o}: not found`),i=1)}return{stdout:s.join(`
220
+ `),exitCode:i}}};var Qf={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=se(t,["-a"]),r="Linux",s=n.properties?.kernel??"5.15.0",i=n.properties?.arch??"x86_64",o=n.hostname;return e?{stdout:`${r} ${o} ${s} #1 SMP ${i} GNU/Linux`,exitCode:0}:se(t,["-r"])?{stdout:s,exitCode:0}:se(t,["-m"])?{stdout:i,exitCode:0}:{stdout:r,exitCode:0}}};var Wf={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=se(n,["-c"]),r=se(n,["-d"]),s=se(n,["-u"]),i=(t??"").split(`
221
+ `),o=[],a=0;for(;a<i.length;){let c=a;for(;c<i.length&&i[c]===i[a];)c++;let l=c-a,f=i[a];if(r&&l===1){a=c;continue}if(s&&l>1){a=c;continue}o.push(e?`${String(l).padStart(4)} ${f}`:f),a=c}return{stdout:o.join(`
222
+ `),exitCode:0}}};var qf={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 Kf={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:n,shell:t})=>{let e=se(n,["-p"]),r=se(n,["-s"]),s=Math.floor((Date.now()-t.startTime)/1e3),i=Math.floor(s/86400),o=Math.floor(s%86400/3600),a=Math.floor(s%3600/60);if(r)return{stdout:new Date(t.startTime).toISOString().slice(0,19).replace("T"," "),exitCode:0};if(e){let h=[];return i>0&&h.push(`${i} day${i>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),l=i>0?`${i} day${i>1?"s":""}, ${String(o).padStart(2)}:${String(a).padStart(2,"0")}`:`${String(o).padStart(2)}:${String(a).padStart(2,"0")}`,f=t.users.listActiveSessions().length,u=(Math.random()*.5).toFixed(2);return{stdout:` ${c} up ${l}, ${f} user${f!==1?"s":""}, load average: ${u}, ${u}, ${u}`,exitCode:0}}};var Vf={name:"wc",description:"Count words/lines/bytes",category:"text",params:["[-l] [-w] [-c] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=se(r,["-l"]),o=se(r,["-w"]),a=se(r,["-c"]),c=!i&&!o&&!a,l=r.filter(h=>!h.startsWith("-")),f=(h,p)=>{let A=h.length===0?0:h.trim().split(`
223
+ `).length,E=h.trim().split(/\s+/).filter(Boolean).length,S=Buffer.byteLength(h,"utf8"),x=[];return(c||i)&&x.push(String(A).padStart(7)),(c||o)&&x.push(String(E).padStart(7)),(c||a)&&x.push(String(S).padStart(7)),p&&x.push(` ${p}`),x.join("")};if(l.length===0)return{stdout:f(s??"",""),exitCode:0};let u=[];for(let h of l){let p=de(e,h);try{Oe(n,p,"wc");let A=t.vfs.readFile(p);u.push(f(A,h))}catch{return{stderr:`wc: ${h}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
224
+ `),exitCode:0}}};var zf={name:"wget",description:"File downloader (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:s,positionals:i}=Xt(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(`
216
225
  `),exitCode:0};if(se(e,["-V","--version"]))return{stdout:"GNU Wget 1.21.3 (virtual) built on Fortune GNU/Linux.",exitCode:0};let o=i[0];if(!o)return{stderr:`wget: missing URL
217
226
  Usage: wget [OPTION]... [URL]...`,exitCode:1};let a=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;if(!a)return{stderr:`wget: missing URL
218
- Usage: wget [OPTION]... [URL]...`,exitCode:1};let c=s.get("-O")??s.get("--output-document")??null,f=s.get("-P")??s.get("--directory-prefix")??null,l=se(e,["-q","--quiet"]),u=c==="-"?null:c??Oc(a),h=u?le(t,f?`${f}/${u}`:u):null;h&&Me(n,h,"wget");let p=[];l||(p.push(`--${new Date().toISOString()}-- ${a}`),p.push(`Resolving ${new URL(a).host}...`),p.push(`Connecting to ${new URL(a).host}...`));let _;try{_=await fetch(a,{headers:{"User-Agent":"Wget/1.21.3 (Fortune GNU/Linux)"}})}catch(b){let v=b instanceof Error?b.message:String(b);return p.push(`wget: unable to resolve host: ${v}`),{stderr:p.join(`
219
- `),exitCode:4}}if(!_.ok)return p.push(`ERROR ${_.status}: ${_.statusText}`),{stderr:p.join(`
220
- `),exitCode:8};let E;try{E=await _.text()}catch{return{stderr:"wget: failed to read response",exitCode:1}}if(!l){let b=_.headers.get("content-type")??"application/octet-stream";p.push(`HTTP request sent, awaiting response... ${_.status} ${_.statusText}`),p.push(`Length: ${E.length} [${b}]`)}return c==="-"?{stdout:E,stderr:p.join(`
221
- `)||void 0,exitCode:0}:h?(r.writeFileAsUser(n,h,E),l||p.push(`Saving to: '${h}'
227
+ Usage: wget [OPTION]... [URL]...`,exitCode:1};let c=s.get("-O")??s.get("--output-document")??null,l=s.get("-P")??s.get("--directory-prefix")??null,f=se(e,["-q","--quiet"]),u=c==="-"?null:c??Vc(a),h=u?de(t,l?`${l}/${u}`:u):null;h&&Oe(n,h,"wget");let p=[];f||(p.push(`--${new Date().toISOString()}-- ${a}`),p.push(`Resolving ${new URL(a).host}...`),p.push(`Connecting to ${new URL(a).host}...`));let A;try{A=await fetch(a,{headers:{"User-Agent":"Wget/1.21.3 (Fortune GNU/Linux)"}})}catch(S){let x=S instanceof Error?S.message:String(S);return p.push(`wget: unable to resolve host: ${x}`),{stderr:p.join(`
228
+ `),exitCode:4}}if(!A.ok)return p.push(`ERROR ${A.status}: ${A.statusText}`),{stderr:p.join(`
229
+ `),exitCode:8};let E;try{E=await A.text()}catch{return{stderr:"wget: failed to read response",exitCode:1}}if(!f){let S=A.headers.get("content-type")??"application/octet-stream";p.push(`HTTP request sent, awaiting response... ${A.status} ${A.statusText}`),p.push(`Length: ${E.length} [${S}]`)}return c==="-"?{stdout:E,stderr:p.join(`
230
+ `)||void 0,exitCode:0}:h?(r.writeFileAsUser(n,h,E),f||p.push(`Saving to: '${h}'
222
231
  ${h} 100%[==================>] ${E.length} B`),{stderr:p.join(`
223
- `)||void 0,exitCode:0}):{stdout:E,exitCode:0}}};var Hl={name:"which",description:"Locate a command in PATH",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"which: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),s=[],i=!1;for(let o of n){let a=!1;for(let c of r){let f=`${c}/${o}`;if(t.vfs.exists(f)&&t.vfs.stat(f).type==="file"){s.push(f),a=!0;break}}a||(i=!0)}return s.length===0?{exitCode:1}:{stdout:s.join(`
224
- `),exitCode:i?1:0}}};function cs(n){let t=n.toLocaleString("en-US",{weekday:"short"}),e=n.toLocaleString("en-US",{month:"short"}),r=n.getDate().toString().padStart(2,"0"),s=n.getHours().toString().padStart(2,"0"),i=n.getMinutes().toString().padStart(2,"0"),o=n.getSeconds().toString().padStart(2,"0"),a=n.getFullYear();return`${t} ${e} ${r} ${s}:${i}:${o} ${a}`}var Ql={name:"who",description:"Show active sessions",category:"system",params:[],run:({shell:n})=>({stdout:n.users.listActiveSessions().map(e=>{let r=new Date(e.startedAt),s=Number.isNaN(r.getTime())?e.startedAt:cs(r);return`${e.username} ${e.tty} ${s} (${e.remoteAddress||"unknown"})`}).join(`
225
- `),exitCode:0})};var Wl={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})};var ql={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:s,stdin:i,shell:o,env:a})=>{let c=s[0]??"echo",f=s.slice(1),l=(i??"").trim().split(/\s+/).filter(Boolean);if(l.length===0)return{exitCode:0};let u=[c,...f,...l].join(" ");return yt(u,n,t,e,r,o,void 0,a)}};var fg=[il,Gc,Lf,Nl,Vc,kl,fl,$f,jc,Mf,Bf,Rf,zc,Nf,df,pf,ll,qc,_l,Ul,Ol,Ef,wl,Jc,Rl,Cl,ql,rf,Il,mf,Af,Kc,Wl,Ql,If,vf,gf,Dl,rl,kf,nf,af,Zc,yl,tl,cf,ff,uf,ul,$l,gl,Yc,lf,Ff,Cf,Xc,Fl,Dc,el,tf,Sl,xl,Yf,Qc,Wc,sf,of,Hl,Ll,Uf,$c,Mc,vl,bl,wf,nl,cl,ef,ml,Al,El,Pl,Tl,Jf,Zf,Xf,al,Ml,hf,Df],Kl=[],hi=new Map,fs=null,lg=Sf(()=>bo().map(n=>n.name));function _o(){hi.clear();for(let n of bo()){hi.set(n.name,n);for(let t of n.aliases??[])hi.set(t,n)}fs=Array.from(hi.keys()).sort()}function bo(){return[...fg,...Kl,lg]}function xo(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");Kl.push(t),_o()}function So(n,t,e){return{name:n,params:t,run:e}}function wo(){return fs||_o(),fs}function po(){return bo()}function In(n){return fs||_o(),hi.get(n.toLowerCase())}var Bx=ln("SshClient");var ep=require("node:events"),tp=Kt(pc(),1);var Vh=require("node:events");var Yr=Kt(require("node:os"),1);function _e(n,t,e=493){n.exists(t)||n.mkdir(t,e)}function ot(n,t,e,r=420){n.exists(t)||n.writeFile(t,e,{mode:r})}function iE(n,t,e){_e(n,"/etc"),ot(n,"/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(`
232
+ `)||void 0,exitCode:0}):{stdout:E,exitCode:0}}};var Gf={name:"which",description:"Locate a command in PATH",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"which: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),s=[],i=!1;for(let o of n){let a=!1;for(let c of r){let l=`${c}/${o}`;if(t.vfs.exists(l)&&t.vfs.stat(l).type==="file"){s.push(l),a=!0;break}}a||(i=!0)}return s.length===0?{exitCode:1}:{stdout:s.join(`
233
+ `),exitCode:i?1:0}}};function hs(n){let t=n.toLocaleString("en-US",{weekday:"short"}),e=n.toLocaleString("en-US",{month:"short"}),r=n.getDate().toString().padStart(2,"0"),s=n.getHours().toString().padStart(2,"0"),i=n.getMinutes().toString().padStart(2,"0"),o=n.getSeconds().toString().padStart(2,"0"),a=n.getFullYear();return`${t} ${e} ${r} ${s}:${i}:${o} ${a}`}var Yf={name:"who",description:"Show active sessions",category:"system",params:[],run:({shell:n})=>({stdout:n.users.listActiveSessions().map(e=>{let r=new Date(e.startedAt),s=Number.isNaN(r.getTime())?e.startedAt:hs(r);return`${e.username} ${e.tty} ${s} (${e.remoteAddress||"unknown"})`}).join(`
234
+ `),exitCode:0})};var jf={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})};var Xf={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:s,stdin:i,shell:o,env:a})=>{let c=s[0]??"echo",l=s.slice(1),f=(i??"").trim().split(/\s+/).filter(Boolean);if(f.length===0)return{exitCode:0};let u=[c,...l,...f].join(" ");return St(u,n,t,e,r,o,void 0,a)}};var vg=[ff,Zc,Ol,Mf,Jc,$f,gf,Ql,nl,Wl,Ll,$l,el,Dl,Ul,Al,El,mf,jc,kf,Wf,Vf,xl,Nf,il,Uf,Tf,Xf,ll,Pf,bl,Sl,Xc,jf,Yf,Rl,Pl,_l,Qf,lf,Tl,cl,dl,sl,Cf,af,hl,pl,ml,Af,qf,Sf,tl,gl,Kl,Nl,rl,zf,Qc,of,al,Rf,Bf,ef,Gc,Yc,fl,ul,Gf,Hf,Hl,qc,Kc,Lf,vf,Bl,cf,pf,ol,xf,wf,If,Of,Ff,rf,sf,nf,hf,Kf,yl,Fl],Jf=[],mi=new Map,ps=null,Bg=vl(()=>vo().map(n=>n.name));function ko(){mi.clear();for(let n of vo()){mi.set(n.name,n);for(let t of n.aliases??[])mi.set(t,n)}ps=Array.from(mi.keys()).sort()}function vo(){return[...vg,...Jf,Bg]}function Bo(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");Jf.push(t),ko()}function Ro(n,t,e){return{name:n,params:t,run:e}}function No(){return ps||ko(),ps}function Eo(){return vo()}function En(n){return ps||ko(),mi.get(n.toLowerCase())}var JS=hn("SshClient");var ap=require("node:events"),cp=zt(bc(),1);var Zh=require("node:events");var mr=zt(require("node:os"),1);function ce(n,t,e=493){n.exists(t)||n.mkdir(t,e)}function fe(n,t,e,r=420){n.exists(t)||n.writeFile(t,e,{mode:r})}function bt(n,t,e){n.writeFile(t,e)}function xy(n){let t=2166136261;for(let e=0;e<n.length;e++)t^=n.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function wy(n,t,e){ce(n,"/etc"),fe(n,"/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(`
226
235
  `)}
227
- `),ot(n,"/etc/debian_version",`12.0
228
- `),ot(n,"/etc/hostname",`${t}
229
- `),ot(n,"/etc/shells",`/bin/sh
236
+ `),fe(n,"/etc/debian_version",`12.0
237
+ `),fe(n,"/etc/hostname",`${t}
238
+ `),fe(n,"/etc/shells",`/bin/sh
230
239
  /bin/bash
231
240
  /usr/bin/bash
232
- `),ot(n,"/etc/profile",`${["export PATH=/usr/local/bin:/usr/bin:/bin","export PS1='\\u@\\h:\\w\\$ '"].join(`
241
+ `),fe(n,"/etc/profile",`${["export PATH=/usr/local/bin:/usr/bin:/bin","export PS1='\\u@\\h:\\w\\$ '"].join(`
233
242
  `)}
234
- `),ot(n,"/etc/issue",`Fortune GNU/Linux 1.0 \\n \\l
235
- `),ot(n,"/etc/motd",["",`Welcome to ${e.os}`,`Kernel: ${e.kernel}`,""].join(`
236
- `)),_e(n,"/etc/apt"),_e(n,"/etc/apt/sources.list.d"),ot(n,"/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(`
243
+ `),fe(n,"/etc/issue",`Fortune GNU/Linux 1.0 \\n \\l
244
+ `),fe(n,"/etc/motd",["",`Welcome to ${e.os}`,`Kernel: ${e.kernel}`,""].join(`
245
+ `)),ce(n,"/etc/apt"),ce(n,"/etc/apt/sources.list.d"),fe(n,"/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(`
237
246
  `)}
238
- `),_e(n,"/etc/network"),ot(n,"/etc/network/interfaces",`${["auto lo","iface lo inet loopback","","auto eth0","iface eth0 inet dhcp"].join(`
247
+ `),ce(n,"/etc/network"),fe(n,"/etc/network/interfaces",`${["auto lo","iface lo inet loopback","","auto eth0","iface eth0 inet dhcp"].join(`
239
248
  `)}
240
- `),ot(n,"/etc/resolv.conf",`nameserver 1.1.1.1
249
+ `),fe(n,"/etc/resolv.conf",`nameserver 1.1.1.1
241
250
  nameserver 8.8.8.8
242
- `),ot(n,"/etc/hosts",`${["127.0.0.1 localhost",`127.0.1.1 ${t}`,"::1 localhost ip6-localhost ip6-loopback"].join(`
251
+ `),fe(n,"/etc/hosts",`${["127.0.0.1 localhost",`127.0.1.1 ${t}`,"::1 localhost ip6-localhost ip6-loopback"].join(`
243
252
  `)}
244
- `),_e(n,"/etc/cron.d"),_e(n,"/etc/init.d"),_e(n,"/etc/systemd"),_e(n,"/etc/systemd/system")}function gc(n,t){let e=t.listUsers(),r=["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"],s=1e3;for(let a of e)a!=="root"&&(r.push(`${a}:x:${s}:${s}::/home/${a}:/bin/bash`),s++);n.writeFile("/etc/passwd",`${r.join(`
253
+ `),ce(n,"/etc/cron.d"),ce(n,"/etc/init.d"),ce(n,"/etc/systemd"),ce(n,"/etc/systemd/system"),fe(n,"/etc/fstab",`${["# <file system> <mount point> <type> <options> <dump> <pass>","UUID=00000000-0000-0000-0000-000000000001 / ext4 errors=remount-ro 0 1","UUID=00000000-0000-0000-0000-000000000002 /boot ext4 defaults 0 2","UUID=00000000-0000-0000-0000-000000000003 none swap sw 0 0","tmpfs /tmp tmpfs defaults,noatime 0 0","tmpfs /run tmpfs defaults,noatime 0 0"].join(`
254
+ `)}
255
+ `),fe(n,"/etc/login.defs",`${["MAIL_DIR /var/mail","PASS_MAX_DAYS 99999","PASS_MIN_DAYS 0","PASS_WARN_AGE 7","UID_MIN 1000","UID_MAX 60000","GID_MIN 1000","GID_MAX 60000","CREATE_HOME yes","UMASK 022","USERGROUPS_ENAB yes","ENCRYPT_METHOD SHA512"].join(`
256
+ `)}
257
+ `),ce(n,"/etc/security"),fe(n,"/etc/security/limits.conf",`# /etc/security/limits.conf
258
+ `),fe(n,"/etc/security/access.conf",`# /etc/security/access.conf
259
+ `),ce(n,"/etc/pam.d"),fe(n,"/etc/pam.d/common-auth",`auth required pam_unix.so
260
+ `),fe(n,"/etc/pam.d/common-account",`account required pam_unix.so
261
+ `),fe(n,"/etc/pam.d/common-password",`password required pam_unix.so obscure sha512
262
+ `),fe(n,"/etc/pam.d/common-session",`session required pam_unix.so
263
+ `),fe(n,"/etc/pam.d/sshd",`@include common-auth
264
+ @include common-account
265
+ @include common-session
266
+ `),ce(n,"/etc/sudoers.d"),fe(n,"/etc/sudoers",`root ALL=(ALL:ALL) ALL
267
+ %sudo ALL=(ALL:ALL) ALL
268
+ `,288),fe(n,"/etc/ld.so.conf",`include /etc/ld.so.conf.d/*.conf
269
+ `),ce(n,"/etc/ld.so.conf.d"),fe(n,"/etc/ld.so.conf.d/x86_64-linux-gnu.conf",`/lib/x86_64-linux-gnu
270
+ /usr/lib/x86_64-linux-gnu
271
+ `),fe(n,"/etc/locale.conf",`LANG=en_US.UTF-8
272
+ `),fe(n,"/etc/timezone",`UTC
273
+ `),fe(n,"/etc/localtime",`UTC
274
+ `)}function Sc(n,t){let e=t.listUsers(),r=["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"],s=1e3;for(let a of e)a!=="root"&&(r.push(`${a}:x:${s}:${s}::/home/${a}:/bin/bash`),s++);n.writeFile("/etc/passwd",`${r.join(`
245
275
  `)}
246
276
  `);let i=["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:"];n.writeFile("/etc/group",`${i.join(`
247
277
  `)}
248
278
  `);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:::`);n.writeFile("/etc/shadow",`${o.join(`
249
279
  `)}
250
- `,{mode:416})}function _h(n){let t=n.match(/(\d+)$/);return 1e3+(t?.[1]?parseInt(t[1],10):0)}function bh(n,t,e,r,s,i,o){let a=`/proc/${t}`;_e(n,a),_e(n,`${a}/fd`),_e(n,`${a}/fdinfo`);let c=Math.floor((Date.now()-new Date(i).getTime())/1e3);n.writeFile(`${a}/cmdline`,`${s.replace(/\s+/g,"\0")}\0`),n.writeFile(`${a}/comm`,s.split(/\s+/)[0]??"bash"),n.writeFile(`${a}/status`,`${[`Name: ${s.split(/\s+/)[0]??"bash"}`,"State: S (sleeping)",`Pid: ${t}`,"PPid: 1","Uid: 0 0 0 0","Gid: 0 0 0 0","VmRSS: 4096 kB","VmSize: 16384 kB","Threads: 1"].join(`
280
+ `,{mode:416})}function kh(n){let t=n.match(/(\d+)$/);return 1e3+(t?.[1]?parseInt(t[1],10):0)}function vh(n,t,e,r,s,i,o){let a=`/proc/${t}`;ce(n,a),ce(n,`${a}/fd`),ce(n,`${a}/fdinfo`);let c=Math.floor((Date.now()-new Date(i).getTime())/1e3),l=s.split(/\s+/)[0]??"bash";bt(n,`${a}/cmdline`,`${s.replace(/\s+/g,"\0")}\0`),bt(n,`${a}/comm`,l),bt(n,`${a}/status`,`${[`Name: ${l}`,"State: S (sleeping)",`Pid: ${t}`,"PPid: 1","Uid: 0 0 0 0","Gid: 0 0 0 0","VmRSS: 4096 kB","VmSize: 16384 kB","Threads: 1"].join(`
281
+ `)}
282
+ `),bt(n,`${a}/stat`,`${t} (${l}) S 1 ${t} ${t} 0 -1 4194304 0 0 0 0 ${c} 0 0 0 20 0 1 0 0 16384 4096 0
283
+ `),bt(n,`${a}/environ`,`${Object.entries(o).map(([f,u])=>`${f}=${u}`).join("\0")}\0`),bt(n,`${a}/cwd`,`/home/${e}\0`),bt(n,`${a}/exe`,"/bin/bash\0");for(let f of["0","1","2"])fe(n,`${a}/fd/${f}`,"")}function Iy(n,t){ce(n,"/proc/boot"),fe(n,"/proc/boot/log",`${["[ 0.000000] Linux virtual kernel booting...","[ 0.000120] init memory subsystem","[ 0.000240] mount /proc /sys /dev","[ 0.000420] start init","[ 0.000680] system ready"].join(`
251
284
  `)}
252
- `),n.writeFile(`${a}/stat`,`${t} (${s.split(/\s+/)[0]??"bash"}) S 1 ${t} ${t} 0 -1 4194304 0 0 0 0 ${c} 0 0 0 20 0 1 0 0 16384 4096 0
253
- `),n.writeFile(`${a}/environ`,`${Object.entries(o).map(([f,l])=>`${f}=${l}`).join("\0")}\0`),n.writeFile(`${a}/cwd`,`/home/${e}\0`),n.writeFile(`${a}/exe`,"/bin/bash\0"),n.writeFile(`${a}/fd/0`,""),n.writeFile(`${a}/fd/1`,""),n.writeFile(`${a}/fd/2`,"")}function io(n,t,e,r,s){_e(n,"/proc");let i=Math.floor((Date.now()-r)/1e3);n.writeFile("/proc/uptime",`${i}.00 ${Math.floor(i*.9)}.00
254
- `);let o=Math.floor(Yr.totalmem()/1024),a=Math.floor(Yr.freemem()/1024),c=Math.floor(a*.95);n.writeFile("/proc/meminfo",`${[`MemTotal: ${String(o).padStart(10)} kB`,`MemFree: ${String(a).padStart(10)} kB`,`MemAvailable: ${String(c).padStart(10)} kB`,`Buffers: ${String(Math.floor(o*.02)).padStart(10)} kB`,`Cached: ${String(Math.floor(o*.15)).padStart(10)} kB`,`SwapTotal: ${String(Math.floor(o*.5)).padStart(10)} kB`,`SwapFree: ${String(Math.floor(o*.5)).padStart(10)} kB`].join(`
285
+ `),fe(n,"/proc/boot/version",`Linux ${t.kernel} (virtual)
286
+ `)}function lo(n,t,e,r,s=[]){ce(n,"/proc");let i=Math.floor((Date.now()-r)/1e3),o=Math.floor(i*.9);bt(n,"/proc/uptime",`${i}.00 ${o}.00
287
+ `);let a=Math.floor(mr.totalmem()/1024),c=Math.floor(mr.freemem()/1024),l=Math.floor(c*.95);bt(n,"/proc/meminfo",`${[`MemTotal: ${String(a).padStart(10)} kB`,`MemFree: ${String(c).padStart(10)} kB`,`MemAvailable: ${String(l).padStart(10)} kB`,`Buffers: ${String(Math.floor(a*.02)).padStart(10)} kB`,`Cached: ${String(Math.floor(a*.15)).padStart(10)} kB`,`SwapTotal: ${String(Math.floor(a*.5)).padStart(10)} kB`,`SwapFree: ${String(Math.floor(a*.5)).padStart(10)} kB`].join(`
255
288
  `)}
256
- `);let f=Yr.cpus(),l=[];for(let b=0;b<f.length;b++){let v=f[b];if(!v)continue;let U=v.speed.toFixed(3);l.push(`processor : ${b}`,`model name : ${v.model}`,`cpu MHz : ${U}`,"cache size : 8192 KB","")}n.writeFile("/proc/cpuinfo",`${l.join(`
289
+ `);let f=mr.cpus(),u=[];for(let x=0;x<f.length;x++){let R=f[x];R&&u.push(`processor : ${x}`,`model name : ${R.model}`,`cpu MHz : ${R.speed.toFixed(3)}`,"cache size : 8192 KB","")}bt(n,"/proc/cpuinfo",`${u.join(`
257
290
  `)}
258
- `),n.writeFile("/proc/version",`Linux version ${t.kernel} (fortune@build) (gcc version 12.2.0) #1 SMP
259
- `),n.writeFile("/proc/hostname",`${e}
260
- `);let u=(Math.random()*.5).toFixed(2),h=1+(s?.length??0);n.writeFile("/proc/loadavg",`${u} ${u} ${u} ${h}/${h} 1
261
- `),_e(n,"/proc/net"),ot(n,"/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(`
291
+ `),bt(n,"/proc/version",`Linux version ${t.kernel} (fortune@build) (gcc version 12.2.0) #1 SMP
292
+ `),bt(n,"/proc/hostname",`${e}
293
+ `);let h=(Math.random()*.5).toFixed(2),p=1+s.length;bt(n,"/proc/loadavg",`${h} ${h} ${h} ${p}/${p} 1
294
+ `),ce(n,"/proc/net"),fe(n,"/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(`
262
295
  `)}
263
- `),bh(n,1,"root","pts/0","/sbin/init",new Date(r).toISOString(),{});let p=s??[];for(let b of p){let v=_h(b.tty);bh(n,v,b.username,b.tty,"bash",b.startedAt,{USER:b.username,HOME:`/home/${b.username}`,TERM:"xterm-256color",SHELL:"/bin/bash"})}let _=p.length>0?_h(p[p.length-1].tty):1;if(n.exists("/proc/self"))try{n.remove("/proc/self")}catch{}let E=`/proc/${_}`;if(n.exists(E)){_e(n,"/proc/self"),_e(n,"/proc/self/fd");for(let b of n.list(E)){let v=`${E}/${b}`,U=`/proc/self/${b}`;try{n.stat(v).type==="file"&&n.writeFile(U,n.readFile(v))}catch{}}n.writeFile("/proc/self/status",n.exists(`${E}/status`)?n.readFile(`${E}/status`):"")}else _e(n,"/proc/self"),n.writeFile("/proc/self/cmdline","bash\0"),n.writeFile("/proc/self/comm","bash"),n.writeFile("/proc/self/status",`Name: bash
296
+ `),fe(n,"/proc/net/if_inet6",""),fe(n,"/proc/net/tcp",` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
297
+ `),fe(n,"/proc/net/tcp6",` sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
298
+ `),bt(n,"/proc/cmdline",`BOOT_IMAGE=/boot/vmlinuz-${t.kernel} root=/dev/sda2 ro quiet splash
299
+ `),fe(n,"/proc/filesystems",`${["nodev sysfs","nodev tmpfs","nodev proc","nodev devtmpfs"," ext4"," vfat","nodev squashfs","nodev overlay"].join(`
300
+ `)}
301
+ `);let A=`${["sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0","proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0","devtmpfs /dev devtmpfs rw,nosuid,size=8192k,nr_inodes=4096,mode=755 0 0","tmpfs /run tmpfs rw,nosuid,nodev,noexec,relatime,size=204800k,mode=755 0 0","tmpfs /tmp tmpfs rw,nosuid,nodev,noatime 0 0","/dev/sda2 / ext4 rw,relatime,errors=remount-ro 0 0","/dev/sda1 /boot ext4 rw,relatime 0 0","tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0","devpts /dev/pts devpts rw,nosuid,noexec,relatime,mode=620,ptmxmode=000 0 0","squashfs /snap/core squashfs ro,nodev,relatime 0 0"].join(`
302
+ `)}
303
+ `;bt(n,"/proc/mounts",A),ce(n,"/proc/self"),bt(n,"/proc/self/mounts",A),bt(n,"/proc/partitions",`${["major minor #blocks name",""," 8 0 41943040 sda"," 8 1 524288 sda1"," 8 2 41417216 sda2"," 7 0 10485760 loop0"].join(`
304
+ `)}
305
+ `),bt(n,"/proc/swaps",`Filename Type Size Used Priority
306
+ /dev/sda3 partition ${Math.floor(mr.totalmem()/2048)} 0 -2
307
+ `),ce(n,"/proc/sys"),ce(n,"/proc/sys/kernel"),ce(n,"/proc/sys/net"),ce(n,"/proc/sys/vm"),fe(n,"/proc/sys/kernel/hostname",`${e}
308
+ `),fe(n,"/proc/sys/kernel/ostype",`Linux
309
+ `),fe(n,"/proc/sys/kernel/osrelease",`${t.kernel}
310
+ `),fe(n,"/proc/sys/kernel/pid_max",`32768
311
+ `),fe(n,"/proc/sys/kernel/threads-max",`65536
312
+ `),fe(n,"/proc/sys/kernel/randomize_va_space",`2
313
+ `),fe(n,"/proc/sys/kernel/dmesg_restrict",`0
314
+ `),fe(n,"/proc/sys/net/ipv4/ip_forward",`0
315
+ `),fe(n,"/proc/sys/vm/swappiness",`60
316
+ `),fe(n,"/proc/sys/vm/overcommit_memory",`0
317
+ `),vh(n,1,"root","pts/0","/sbin/init",new Date(r).toISOString(),{});for(let x of s){let R=kh(x.tty);vh(n,R,x.username,x.tty,"bash",x.startedAt,{USER:x.username,HOME:`/home/${x.username}`,TERM:"xterm-256color",SHELL:"/bin/bash"})}let E=s.length>0?kh(s[s.length-1].tty):1;if(n.exists("/proc/self"))try{n.remove("/proc/self")}catch{}let S=`/proc/${E}`;if(ce(n,"/proc/self"),ce(n,"/proc/self/fd"),n.exists(S))for(let x of n.list(S)){let R=`${S}/${x}`,H=`/proc/self/${x}`;try{n.stat(R).type==="file"&&bt(n,H,n.readFile(R))}catch{}}else bt(n,"/proc/self/cmdline","bash\0"),bt(n,"/proc/self/comm","bash"),bt(n,"/proc/self/status",`Name: bash
264
318
  State: S (sleeping)
265
319
  Pid: 1
266
320
  PPid: 0
267
- `),n.writeFile("/proc/self/environ",""),n.writeFile("/proc/self/cwd","/root\0"),n.writeFile("/proc/self/exe","/bin/bash\0")}function sE(n,t){_e(n,"/sys"),_e(n,"/sys/devices"),_e(n,"/sys/devices/virtual"),_e(n,"/sys/devices/virtual/dmi"),_e(n,"/sys/devices/virtual/dmi/id"),ot(n,"/sys/devices/virtual/dmi/id/sys_vendor",`Fortune Systems
268
- `),ot(n,"/sys/devices/virtual/dmi/id/product_name",`VirtualContainer v1
269
- `),ot(n,"/sys/devices/virtual/dmi/id/board_name",`fortune-board
270
- `),_e(n,"/sys/class"),_e(n,"/sys/class/net"),_e(n,"/sys/kernel"),ot(n,"/sys/kernel/hostname",`fortune-vm
271
- `),ot(n,"/sys/kernel/osrelease",`${t.kernel}
272
- `),ot(n,"/sys/kernel/ostype",`Linux
273
- `)}function oE(n){_e(n,"/dev"),ot(n,"/dev/null","",438),ot(n,"/dev/zero","",438),ot(n,"/dev/random","",292),ot(n,"/dev/urandom","",292),_e(n,"/dev/pts"),_e(n,"/dev/shm")}function aE(n){_e(n,"/usr"),_e(n,"/usr/bin"),_e(n,"/usr/sbin"),_e(n,"/usr/local"),_e(n,"/usr/local/bin"),_e(n,"/usr/local/lib"),_e(n,"/usr/local/share"),_e(n,"/usr/share"),_e(n,"/usr/share/doc"),_e(n,"/usr/share/man"),_e(n,"/usr/share/man/man1"),_e(n,"/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)ot(n,`/usr/bin/${e}`,`#!/bin/sh
321
+ `),bt(n,"/proc/self/environ",""),bt(n,"/proc/self/cwd","/root\0"),bt(n,"/proc/self/exe","/bin/bash\0")}function Cy(n,t,e){ce(n,"/sys"),ce(n,"/sys/devices"),ce(n,"/sys/devices/virtual"),ce(n,"/sys/devices/virtual/dmi"),ce(n,"/sys/devices/virtual/dmi/id");let r=xy(t),s=`VirtualNode-${(r%1e4).toString().padStart(4,"0")}`,i={bios_vendor:"Virtual BIOS",bios_version:"1.0",bios_date:"01/01/2025",sys_vendor:"Fortune Systems",product_name:s,product_family:"VirtualContainer",product_version:"v1",product_uuid:`${r.toString(16).padStart(8,"0")}-0000-0000-0000-000000000000`,product_serial:`SN-${r}`,chassis_type:"3",chassis_vendor:"Virtual",chassis_version:"v1",board_name:"fortune-board",modalias:`dmi:bvnVirtual:bvr1.0:svnFortune:pn${s}`};for(let[o,a]of Object.entries(i))fe(n,`/sys/devices/virtual/dmi/id/${o}`,`${a}
322
+ `);ce(n,"/sys/class"),ce(n,"/sys/class/net"),ce(n,"/sys/kernel"),fe(n,"/sys/kernel/hostname",`${t}
323
+ `),fe(n,"/sys/kernel/osrelease",`${e.kernel}
324
+ `),fe(n,"/sys/kernel/ostype",`Linux
325
+ `)}function ky(n){ce(n,"/dev"),fe(n,"/dev/null","",438),fe(n,"/dev/zero","",438),fe(n,"/dev/full","",438),fe(n,"/dev/random","",292),fe(n,"/dev/urandom","",292),fe(n,"/dev/mem","",416),fe(n,"/dev/console","",384),fe(n,"/dev/tty","",438),fe(n,"/dev/tty0","",400),fe(n,"/dev/tty1","",400),fe(n,"/dev/ttyS0","",432);for(let t=0;t<8;t++)fe(n,`/dev/loop${t}`,"",432);ce(n,"/dev/loop-control"),fe(n,"/dev/sda","",432),fe(n,"/dev/sda1","",432),fe(n,"/dev/sda2","",432),ce(n,"/dev/pts"),ce(n,"/dev/shm"),fe(n,"/dev/stdin","",438),fe(n,"/dev/stdout","",438),fe(n,"/dev/stderr","",438)}function vy(n){ce(n,"/usr"),ce(n,"/usr/bin"),ce(n,"/usr/sbin"),ce(n,"/usr/local"),ce(n,"/usr/local/bin"),ce(n,"/usr/local/lib"),ce(n,"/usr/local/share"),ce(n,"/usr/share"),ce(n,"/usr/share/doc"),ce(n,"/usr/share/man"),ce(n,"/usr/share/man/man1"),ce(n,"/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)fe(n,`/usr/bin/${e}`,`#!/bin/sh
274
326
  exec builtin ${e} "$@"
275
- `,493);ot(n,"/usr/bin/lsb_release",`#!/bin/sh
327
+ `,493);fe(n,"/usr/bin/lsb_release",`#!/bin/sh
276
328
  exec lsb_release "$@"
277
- `,493)}function cE(n){_e(n,"/var"),_e(n,"/var/log"),_e(n,"/var/tmp"),_e(n,"/var/run"),_e(n,"/var/cache"),_e(n,"/var/cache/apt"),_e(n,"/var/cache/apt/archives"),_e(n,"/var/lib"),_e(n,"/var/lib/apt"),_e(n,"/var/lib/apt/lists"),_e(n,"/var/lib/dpkg"),_e(n,"/var/lib/dpkg/info"),ot(n,"/var/lib/dpkg/status",""),ot(n,"/var/lib/dpkg/available",""),ot(n,"/var/log/syslog",`${new Date().toUTCString()} fortune kernel: Virtual container started
278
- `),ot(n,"/var/log/auth.log",""),ot(n,"/var/log/dpkg.log",""),ot(n,"/var/log/apt/history.log",""),ot(n,"/var/log/apt/term.log","")}function fE(n){n.exists("/bin")||n.symlink("/usr/bin","/bin"),n.exists("/sbin")||n.symlink("/usr/sbin","/sbin"),n.exists("/lib")||_e(n,"/lib"),n.exists("/lib64")||_e(n,"/lib64")}function lE(n){_e(n,"/tmp",1023)}function uE(n){_e(n,"/root",448),ot(n,"/home/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(`
329
+ `,493)}function By(n){ce(n,"/var"),ce(n,"/var/log"),ce(n,"/var/log/apt"),ce(n,"/var/tmp"),ce(n,"/var/cache"),ce(n,"/var/cache/apt"),ce(n,"/var/cache/apt/archives"),ce(n,"/var/lib"),ce(n,"/var/lib/apt"),ce(n,"/var/lib/apt/lists"),ce(n,"/var/lib/dpkg"),ce(n,"/var/lib/dpkg/info"),ce(n,"/var/lib/misc"),ce(n,"/var/spool"),ce(n,"/var/spool/cron"),ce(n,"/var/mail"),fe(n,"/var/lib/dpkg/status",""),fe(n,"/var/lib/dpkg/available",""),fe(n,"/var/log/syslog",`${new Date().toUTCString()} fortune kernel: Virtual container started
330
+ `),fe(n,"/var/log/auth.log",""),fe(n,"/var/log/kern.log",""),fe(n,"/var/log/dpkg.log",""),fe(n,"/var/log/apt/history.log",""),fe(n,"/var/log/apt/term.log",""),ce(n,"/run"),ce(n,"/run/lock"),ce(n,"/run/systemd"),ce(n,"/run/user"),fe(n,"/run/utmp","")}function Ry(n){n.exists("/bin")||n.symlink("/usr/bin","/bin"),n.exists("/sbin")||n.symlink("/usr/sbin","/sbin"),n.exists("/var/run")||n.symlink("/run","/var/run"),ce(n,"/lib"),ce(n,"/lib64"),ce(n,"/lib/x86_64-linux-gnu"),ce(n,"/lib/modules")}function Ny(n){ce(n,"/tmp",1023)}function Py(n){ce(n,"/root",448),fe(n,"/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(`
331
+ `)}
332
+ `),fe(n,"/root/.profile",`[ -f ~/.bashrc ] && . ~/.bashrc
333
+ `)}function Ty(n,t){ce(n,"/opt"),ce(n,"/srv"),ce(n,"/mnt"),ce(n,"/media"),ce(n,"/home"),ce(n,"/boot"),ce(n,"/boot/grub"),ce(n,"/boot/grub/grub.cfg.d"),fe(n,"/boot/grub/grub.cfg",`${["# GRUB configuration (virtual)","set default=0","set timeout=5","",'menuentry "Fortune GNU/Linux" {'," linux /vmlinuz root=/dev/sda2 ro quiet splash"," initrd /initrd.img","}"].join(`
279
334
  `)}
280
- `),ot(n,"/home/root/.profile",`[ -f ~/.bashrc ] && . ~/.bashrc
281
- `)}function dE(n){_e(n,"/opt"),_e(n,"/srv"),_e(n,"/mnt"),_e(n,"/media")}function xh(n,t,e,r,s){iE(n,e,r),sE(n,r),oE(n),aE(n),cE(n),fE(n),lE(n),uE(n),dE(n),io(n,r,e,s,[]),gc(n,t)}var Rh=require("node:events"),nr=Kt(require("node:fs"),1),Bn=Kt(require("node:path"),1),gr=require("node:zlib");var Ec=Buffer.from([86,70,83,33]),hE=1,Sh=1,wh=2,mc=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 Ih(n,t){if(t.type==="file"){let e=t;n.writeUint8(Sh),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt.getTime()),n.writeFloat64(e.updatedAt.getTime()),n.writeUint8(e.compressed?1:0),n.writeBytes(e.content)}else{let e=t;n.writeUint8(wh),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt.getTime()),n.writeFloat64(e.updatedAt.getTime());let r=Array.from(e.children.values());n.writeUint32(r.length);for(let s of r)Ih(n,s)}}function Ch(n){let t=new mc;return t.write(Ec),t.writeUint8(hE),Ih(t,n),t.toBuffer()}var Ac=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 vh(n){let t=n.readUint8(),e=n.readString(),r=n.readUint32(),s=new Date(n.readFloat64()),i=new Date(n.readFloat64());if(t===Sh){let o=n.readUint8()===1,a=n.readBytes();return{type:"file",name:e,mode:r,createdAt:s,updatedAt:i,compressed:o,content:a}}if(t===wh){let o=n.readUint32(),a=new Map;for(let c=0;c<o;c++){let f=vh(n);a.set(f.name,f)}return{type:"directory",name:e,mode:r,createdAt:s,updatedAt:i,children:a}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function kh(n){if(n.length<5)throw new Error("[VFS binary] Buffer too short");if(!n.slice(0,4).equals(Ec))throw new Error("[VFS binary] Invalid magic \u2014 not a VFS binary snapshot");let e=new Ac(n);for(let s=0;s<5;s++)e.readUint8();let r=vh(e);if(r.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return r}function Bh(n){return n.length>=4&&n.slice(0,4).equals(Ec)}var so=Kt(require("node:path"),1);function bt(n){if(!n||n.trim()==="")return"/";let t=so.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function pE(n){return n.split("/").filter(Boolean)}function Ht(n,t){let e=bt(t);if(e==="/")return n;let r=pE(e),s=n;for(let i of r){if(s.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=s.children.get(i);if(!o)throw new Error(`Path '${e}' does not exist.`);s=o}return s}function jr(n,t,e,r){let s=bt(t);if(s==="/")throw new Error("Root path has no parent directory.");let i=so.posix.dirname(s),o=so.posix.basename(s);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(i);let a=Ht(n,i);if(a.type!=="directory")throw new Error(`Parent path '${i}' is not a directory.`);return{parent:a,name:o}}var yc=class n extends Rh.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=Bn.resolve(t.snapshotPath,"vfs-snapshot.vfsb")}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,s){let i=new Date;return{type:"file",name:t,content:e,mode:r,compressed:s,createdAt:i,updatedAt:i}}mkdirRecursive(t,e){let r=bt(t);if(r==="/")return;let s=r.split("/").filter(Boolean),i=this.root,o="";for(let a of s){o+=`/${a}`;let c=i.children.get(a);if(!c)c=this.makeDir(a,e),i.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.`);i=c}}async restoreMirror(){if(!(this.mode!=="fs"||!this.snapshotFile)&&nr.existsSync(this.snapshotFile))try{let t=nr.readFileSync(this.snapshotFile);if(Bh(t))this.root=kh(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=Bn.dirname(this.snapshotFile);nr.mkdirSync(t,{recursive:!0});let e=Ch(this.root);nr.writeFileSync(this.snapshotFile,e),this.emit("mirror:flush",{path:this.snapshotFile})}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}mkdir(t,e=493){let r=bt(t),s=(()=>{try{return Ht(this.root,r)}catch{return null}})();if(s&&s.type!=="directory")throw new Error(`Cannot create directory '${r}': path is a file.`);this.mkdirRecursive(r,e)}writeFile(t,e,r={}){let s=bt(t),{parent:i,name:o}=jr(this.root,s,!0,h=>this.mkdirRecursive(h,493)),a=i.children.get(o);if(a?.type==="directory")throw new Error(`Cannot write file '${s}': path is a directory.`);let c=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),f=r.compress??!1,l=f?(0,gr.gzipSync)(c):c,u=r.mode??420;if(a){let h=a;h.content=l,h.compressed=f,h.mode=u,h.updatedAt=new Date}else i.children.set(o,this.makeFile(o,l,u,f));this.emit("file:write",{path:s,size:l.length})}readFile(t){let e=bt(t),r=Ht(this.root,e);if(r.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=r,i=s.compressed?(0,gr.gunzipSync)(s.content):s.content;return this.emit("file:read",{path:e,size:i.length}),i.toString("utf8")}readFileRaw(t){let e=bt(t),r=Ht(this.root,e);if(r.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=r,i=s.compressed?(0,gr.gunzipSync)(s.content):s.content;return this.emit("file:read",{path:e,size:i.length}),i}exists(t){try{return Ht(this.root,bt(t)),!0}catch{return!1}}chmod(t,e){Ht(this.root,bt(t)).mode=e}stat(t){let e=bt(t),r=Ht(this.root,e),s=e==="/"?"":Bn.posix.basename(e);if(r.type==="file"){let o=r;return{type:"file",name:s,path:e,mode:o.mode,createdAt:o.createdAt,updatedAt:o.updatedAt,compressed:o.compressed,size:o.content.length}}let i=r;return{type:"directory",name:s,path:e,mode:i.mode,createdAt:i.createdAt,updatedAt:i.updatedAt,childrenCount:i.children.size}}list(t="/"){let e=bt(t),r=Ht(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=bt(t),r=Ht(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let s=t==="/"?"/":Bn.posix.basename(e);return this.renderTreeLines(r,s)}renderTreeLines(t,e){let r=[e],s=Array.from(t.children.keys()).sort();for(let i=0;i<s.length;i++){let o=s[i],a=t.children.get(o),c=i===s.length-1,f=c?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",l=c?" ":"\u2502 ";if(r.push(`${f}${o}`),a.type==="directory"){let u=this.renderTreeLines(a,"").split(`
282
- `).slice(1).map(h=>`${l}${h}`);r.push(...u)}}return r.join(`
283
- `)}getUsageBytes(t="/"){return this.computeUsage(Ht(this.root,bt(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=Ht(this.root,bt(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=(0,gr.gzipSync)(r.content),r.compressed=!0,r.updatedAt=new Date)}decompressFile(t){let e=Ht(this.root,bt(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=(0,gr.gunzipSync)(r.content),r.compressed=!1,r.updatedAt=new Date)}symlink(t,e){let r=bt(e),s=t.startsWith("/")?bt(t):t,{parent:i,name:o}=jr(this.root,r,!0,c=>this.mkdirRecursive(c,493)),a={type:"file",name:o,content:Buffer.from(s,"utf8"),mode:41471,compressed:!1,createdAt:new Date,updatedAt:new Date};i.children.set(o,a),this.emit("symlink:create",{link:r,target:s})}isSymlink(t){try{let e=Ht(this.root,bt(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=bt(t);for(let s=0;s<e;s++){try{let i=Ht(this.root,r);if(i.type==="file"&&i.mode===41471){let o=i.content.toString("utf8");r=o.startsWith("/")?o:bt(Bn.posix.join(Bn.posix.dirname(r),o));continue}}catch{break}return r}throw new Error(`Too many levels of symbolic links: ${t}`)}remove(t,e={}){let r=bt(t);if(r==="/")throw new Error("Cannot remove root directory.");let s=Ht(this.root,r);if(s.type==="directory"){let a=s;if(!e.recursive&&a.children.size>0)throw new Error(`Directory '${r}' is not empty. Use recursive option.`)}let{parent:i,name:o}=jr(this.root,r,!1,()=>{});i.children.delete(o),this.emit("node:remove",{path:r})}move(t,e){let r=bt(t),s=bt(e);if(r==="/"||s==="/")throw new Error("Cannot move root directory.");let i=Ht(this.root,r);if(this.exists(s))throw new Error(`Destination '${s}' already exists.`);this.mkdirRecursive(Bn.posix.dirname(s),493);let{parent:o,name:a}=jr(this.root,s,!1,()=>{}),{parent:c,name:f}=jr(this.root,r,!1,()=>{});c.children.delete(f),i.name=a,o.children.set(a,i)}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 s of t.children)if(s.type==="file"){let i=s;r.children.set(i.name,{type:"file",name:i.name,mode:i.mode,createdAt:new Date(i.createdAt),updatedAt:new Date(i.updatedAt),compressed:i.compressed,content:Buffer.from(i.contentBase64,"base64")})}else{let i=this.deserializeDir(s,s.name);r.children.set(s.name,i)}return r}},_c=yc;var bc=[{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
335
+ `);let e=t.kernel;fe(n,`/boot/vmlinuz-${e}`,"",420),fe(n,`/boot/initrd.img-${e}`,"",420),fe(n,`/boot/System.map-${e}`,`${e} virtual
336
+ `,420),fe(n,`/boot/config-${e}`,`# Linux kernel config ${e}
337
+ `,420),n.exists("/vmlinuz")||n.symlink(`/boot/vmlinuz-${e}`,"/vmlinuz"),n.exists("/vmlinuz.old")||n.symlink(`/boot/vmlinuz-${e}`,"/vmlinuz.old"),n.exists("/initrd.img")||n.symlink(`/boot/initrd.img-${e}`,"/initrd.img"),n.exists("/initrd.img.old")||n.symlink(`/boot/initrd.img-${e}`,"/initrd.img.old"),ce(n,"/snap"),ce(n,"/snap/bin"),ce(n,"/lost+found",448)}function Bh(n,t,e,r,s,i=[]){wy(n,e,r),Cy(n,e,r),ky(n),vy(n),By(n),Ry(n),Ny(n),Py(n),Ty(n,r),Iy(n,r),lo(n,r,e,s,i),Sc(n,t)}var Uh=require("node:events"),ct=zt(require("node:fs"),1),sn=zt(require("node:path"),1),Ar=require("node:zlib");var Ic=Buffer.from([86,70,83,33]),Ly=1,Rh=1,Nh=2,xc=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 Ph(n,t){if(t.type==="file"){let e=t;n.writeUint8(Rh),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt.getTime()),n.writeFloat64(e.updatedAt.getTime()),n.writeUint8(e.compressed?1:0),n.writeBytes(e.content)}else{let e=t;n.writeUint8(Nh),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt.getTime()),n.writeFloat64(e.updatedAt.getTime());let r=Array.from(e.children.values());n.writeUint32(r.length);for(let s of r)Ph(n,s)}}function Th(n){let t=new xc;return t.write(Ic),t.writeUint8(Ly),Ph(t,n),t.toBuffer()}var wc=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 Lh(n){let t=n.readUint8(),e=n.readString(),r=n.readUint32(),s=new Date(n.readFloat64()),i=new Date(n.readFloat64());if(t===Rh){let o=n.readUint8()===1,a=n.readBytes();return{type:"file",name:e,mode:r,createdAt:s,updatedAt:i,compressed:o,content:a}}if(t===Nh){let o=n.readUint32(),a=new Map;for(let c=0;c<o;c++){let l=Lh(n);a.set(l.name,l)}return{type:"directory",name:e,mode:r,createdAt:s,updatedAt:i,children:a}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function $h(n){if(n.length<5)throw new Error("[VFS binary] Buffer too short");if(!n.slice(0,4).equals(Ic))throw new Error("[VFS binary] Invalid magic \u2014 not a VFS binary snapshot");let e=new wc(n);for(let s=0;s<5;s++)e.readUint8();let r=Lh(e);if(r.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return r}function Dh(n){return n.length>=4&&n.slice(0,4).equals(Ic)}var fo=zt(require("node:path"),1);function ht(n){if(!n||n.trim()==="")return"/";let t=fo.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function $y(n){return n.split("/").filter(Boolean)}function Wt(n,t){let e=ht(t);if(e==="/")return n;let r=$y(e),s=n;for(let i of r){if(s.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=s.children.get(i);if(!o)throw new Error(`Path '${e}' does not exist.`);s=o}return s}function Zr(n,t,e,r){let s=ht(t);if(s==="/")throw new Error("Root path has no parent directory.");let i=fo.posix.dirname(s),o=fo.posix.basename(s);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(i);let a=Wt(n,i);if(a.type!=="directory")throw new Error(`Parent path '${i}' is not a directory.`);return{parent:a,name:o}}var Cc=class n extends Uh.EventEmitter{root;mode;snapshotFile;mounts=new Map;static isBrowser=typeof process>"u"||typeof process.versions?.node>"u";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=sn.resolve(t.snapshotPath,"vfs-snapshot.vfsb")}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,s){let i=new Date;return{type:"file",name:t,content:e,mode:r,compressed:s,createdAt:i,updatedAt:i}}mkdirRecursive(t,e){let r=ht(t);if(r==="/")return;let s=r.split("/").filter(Boolean),i=this.root,o="";for(let a of s){o+=`/${a}`;let c=i.children.get(a);if(!c)c=this.makeDir(a,e),i.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.`);i=c}}async restoreMirror(){if(!(this.mode!=="fs"||!this.snapshotFile)&&ct.existsSync(this.snapshotFile))try{let t=ct.readFileSync(this.snapshotFile);if(Dh(t))this.root=$h(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=sn.dirname(this.snapshotFile);ct.mkdirSync(t,{recursive:!0});let e=Th(this.root);ct.writeFileSync(this.snapshotFile,e),this.emit("mirror:flush",{path:this.snapshotFile})}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}mount(t,e,{readOnly:r=!0}={}){if(n.isBrowser)return;let s=ht(t),i=sn.resolve(e);if(!ct.existsSync(i))throw new Error(`VirtualFileSystem.mount: host path does not exist: "${i}"`);if(!ct.statSync(i).isDirectory())throw new Error(`VirtualFileSystem.mount: host path is not a directory: "${i}"`);this.mkdir(s),this.mounts.set(s,{hostPath:i,readOnly:r}),this.emit("mount",{vPath:s,hostPath:i,readOnly:r})}unmount(t){let e=ht(t);this.mounts.delete(e)&&this.emit("unmount",{vPath:e})}getMounts(){return[...this.mounts.entries()].map(([t,e])=>({vPath:t,...e}))}resolveMount(t){let e=ht(t),r=[...this.mounts.entries()].sort(([s],[i])=>i.length-s.length);for(let[s,i]of r)if(e===s||e.startsWith(`${s}/`)){let o=e.slice(s.length).replace(/^\//,""),a=o?sn.join(i.hostPath,o):i.hostPath;return{hostPath:i.hostPath,readOnly:i.readOnly,relPath:o,fullHostPath:a}}return null}mkdir(t,e=493){let r=ht(t),s=(()=>{try{return Wt(this.root,r)}catch{return null}})();if(s&&s.type!=="directory")throw new Error(`Cannot create directory '${r}': path is a file.`);this.mkdirRecursive(r,e)}writeFile(t,e,r={}){let s=this.resolveMount(t);if(s){if(s.readOnly)throw new Error(`EROFS: read-only file system, open '${s.fullHostPath}'`);let p=sn.dirname(s.fullHostPath);ct.existsSync(p)||ct.mkdirSync(p,{recursive:!0}),ct.writeFileSync(s.fullHostPath,Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"));return}let i=ht(t),{parent:o,name:a}=Zr(this.root,i,!0,p=>this.mkdirRecursive(p,493)),c=o.children.get(a);if(c?.type==="directory")throw new Error(`Cannot write file '${i}': path is a directory.`);let l=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),f=r.compress??!1,u=f?(0,Ar.gzipSync)(l):l,h=r.mode??420;if(c){let p=c;p.content=u,p.compressed=f,p.mode=h,p.updatedAt=new Date}else o.children.set(a,this.makeFile(a,u,h,f));this.emit("file:write",{path:i,size:u.length})}readFile(t){let e=this.resolveMount(t);if(e){if(!ct.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return ct.readFileSync(e.fullHostPath,"utf8")}let r=ht(t),s=Wt(this.root,r);if(s.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=s,o=i.compressed?(0,Ar.gunzipSync)(i.content):i.content;return this.emit("file:read",{path:r,size:o.length}),o.toString("utf8")}readFileRaw(t){let e=this.resolveMount(t);if(e){if(!ct.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return ct.readFileSync(e.fullHostPath)}let r=ht(t),s=Wt(this.root,r);if(s.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=s,o=i.compressed?(0,Ar.gunzipSync)(i.content):i.content;return this.emit("file:read",{path:r,size:o.length}),o}exists(t){let e=this.resolveMount(t);if(e)return ct.existsSync(e.fullHostPath);try{return Wt(this.root,ht(t)),!0}catch{return!1}}chmod(t,e){Wt(this.root,ht(t)).mode=e}stat(t){let e=this.resolveMount(t);if(e){if(!ct.existsSync(e.fullHostPath))throw new Error(`ENOENT: stat '${e.fullHostPath}'`);let a=ct.statSync(e.fullHostPath),c=e.relPath.split("/").pop()??e.fullHostPath.split("/").pop()??"",l=a.mtime;return a.isDirectory()?{type:"directory",name:c,path:ht(t),mode:493,createdAt:a.birthtime,updatedAt:l,childrenCount:ct.readdirSync(e.fullHostPath).length}:{type:"file",name:c,path:ht(t),mode:e.readOnly?292:420,createdAt:a.birthtime,updatedAt:l,compressed:!1,size:a.size}}let r=ht(t),s=Wt(this.root,r),i=r==="/"?"":sn.posix.basename(r);if(s.type==="file"){let a=s;return{type:"file",name:i,path:r,mode:a.mode,createdAt:a.createdAt,updatedAt:a.updatedAt,compressed:a.compressed,size:a.content.length}}let o=s;return{type:"directory",name:i,path:r,mode:o.mode,createdAt:o.createdAt,updatedAt:o.updatedAt,childrenCount:o.children.size}}list(t="/"){let e=this.resolveMount(t);if(e){if(!ct.existsSync(e.fullHostPath))return[];try{return ct.readdirSync(e.fullHostPath).sort()}catch{return[]}}let r=ht(t),s=Wt(this.root,r);if(s.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Array.from(s.children.keys()).sort()}tree(t="/"){let e=ht(t),r=Wt(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let s=t==="/"?"/":sn.posix.basename(e);return this.renderTreeLines(r,s)}renderTreeLines(t,e){let r=[e],s=Array.from(t.children.keys()).sort();for(let i=0;i<s.length;i++){let o=s[i],a=t.children.get(o),c=i===s.length-1,l=c?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",f=c?" ":"\u2502 ";if(r.push(`${l}${o}`),a.type==="directory"){let u=this.renderTreeLines(a,"").split(`
338
+ `).slice(1).map(h=>`${f}${h}`);r.push(...u)}}return r.join(`
339
+ `)}getUsageBytes(t="/"){return this.computeUsage(Wt(this.root,ht(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=Wt(this.root,ht(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=(0,Ar.gzipSync)(r.content),r.compressed=!0,r.updatedAt=new Date)}decompressFile(t){let e=Wt(this.root,ht(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=(0,Ar.gunzipSync)(r.content),r.compressed=!1,r.updatedAt=new Date)}symlink(t,e){let r=ht(e),s=t.startsWith("/")?ht(t):t,{parent:i,name:o}=Zr(this.root,r,!0,c=>this.mkdirRecursive(c,493)),a={type:"file",name:o,content:Buffer.from(s,"utf8"),mode:41471,compressed:!1,createdAt:new Date,updatedAt:new Date};i.children.set(o,a),this.emit("symlink:create",{link:r,target:s})}isSymlink(t){try{let e=Wt(this.root,ht(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=ht(t);for(let s=0;s<e;s++){try{let i=Wt(this.root,r);if(i.type==="file"&&i.mode===41471){let o=i.content.toString("utf8");r=o.startsWith("/")?o:ht(sn.posix.join(sn.posix.dirname(r),o));continue}}catch{break}return r}throw new Error(`Too many levels of symbolic links: ${t}`)}remove(t,e={}){let r=this.resolveMount(t);if(r){if(r.readOnly)throw new Error(`EROFS: read-only file system, unlink '${r.fullHostPath}'`);if(!ct.existsSync(r.fullHostPath))throw new Error(`ENOENT: no such file or directory, unlink '${r.fullHostPath}'`);ct.statSync(r.fullHostPath).isDirectory()?ct.rmSync(r.fullHostPath,{recursive:e.recursive??!1}):ct.unlinkSync(r.fullHostPath);return}let s=ht(t);if(s==="/")throw new Error("Cannot remove root directory.");let i=Wt(this.root,s);if(i.type==="directory"){let c=i;if(!e.recursive&&c.children.size>0)throw new Error(`Directory '${s}' is not empty. Use recursive option.`)}let{parent:o,name:a}=Zr(this.root,s,!1,()=>{});o.children.delete(a),this.emit("node:remove",{path:s})}move(t,e){let r=ht(t),s=ht(e);if(r==="/"||s==="/")throw new Error("Cannot move root directory.");let i=Wt(this.root,r);if(this.exists(s))throw new Error(`Destination '${s}' already exists.`);this.mkdirRecursive(sn.posix.dirname(s),493);let{parent:o,name:a}=Zr(this.root,s,!1,()=>{}),{parent:c,name:l}=Zr(this.root,r,!1,()=>{});c.children.delete(l),i.name=a,o.children.set(a,i)}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 s of t.children)if(s.type==="file"){let i=s;r.children.set(i.name,{type:"file",name:i.name,mode:i.mode,createdAt:new Date(i.createdAt),updatedAt:new Date(i.updatedAt),compressed:i.compressed,content:Buffer.from(i.contentBase64,"base64")})}else{let i=this.deserializeDir(s,s.name);r.children.set(s.name,i)}return r}},kc=Cc;var vc=[{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
284
340
  echo 'vim: use nano for editing in this environment'
285
341
  `,mode:493},{path:"/usr/bin/vi",content:`#!/bin/sh
286
342
  exec vim "$@"
@@ -369,19 +425,19 @@ echo 'journalctl: virtual stub'
369
425
  echo 'gzip: virtual stub'
370
426
  `,mode:493}]},{name:"neofetch",version:"7.1.0-1",section:"utils",description:"A command-line system information tool written in bash 3.2+",shortDesc:"command-line system information tool",installedSizeKb:256,files:[{path:"/usr/bin/neofetch",content:`#!/bin/sh
371
427
  echo 'neofetch: virtual stub'
372
- `,mode:493}]}],Wi=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 r of e){if(!r.trim())continue;let s=this.parseFields(r),i=s.Package;i&&this.installed.set(i,{name:i,version:s.Version??"unknown",architecture:s.Architecture??"amd64",maintainer:s.Maintainer??"Fortune Maintainers",description:s.Description??"",section:s.Section??"misc",installedSizeKb:Number(s["Installed-Size"]??0),installedAt:s["X-Installed-At"]??new Date().toISOString(),files:(s["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(`
428
+ `,mode:493}]}],Vi=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 r of e){if(!r.trim())continue;let s=this.parseFields(r),i=s.Package;i&&this.installed.set(i,{name:i,version:s.Version??"unknown",architecture:s.Architecture??"amd64",maintainer:s.Maintainer??"Fortune Maintainers",description:s.Description??"",section:s.Section??"misc",installedSizeKb:Number(s["Installed-Size"]??0),installedAt:s["X-Installed-At"]??new Date().toISOString(),files:(s["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(`
373
429
  `));this.vfs.writeFile(this.registryPath,`${t.join(`
374
430
 
375
431
  `)}
376
432
  `)}parseFields(t){let e={};for(let r of t.split(`
377
433
  `)){let s=r.indexOf(": ");s!==-1&&(e[r.slice(0,s)]=r.slice(s+2))}return e}log(t){let r=`${new Date().toISOString().replace("T"," ").slice(0,19)} ${t}
378
434
  `,s=this.vfs.exists(this.logPath)?this.vfs.readFile(this.logPath):"";this.vfs.writeFile(this.logPath,s+r)}aptLog(t,e){let r=new Date().toISOString(),s=this.vfs.exists(this.aptLogPath)?this.vfs.readFile(this.aptLogPath):"",i=[`Start-Date: ${r}`,`Commandline: apt-get ${t} ${e.join(" ")}`,`${t==="install"?"Install":"Remove"}: ${e.join(", ")}`,`End-Date: ${r}`,""].join(`
379
- `);this.vfs.writeFile(this.aptLogPath,s+i)}findInRegistry(t){return bc.find(e=>e.name.toLowerCase()===t.toLowerCase())}listAvailable(){return[...bc].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 r=[],s=[],i=[],o=(c,f=new Set)=>{if(f.has(c)||(f.add(c),this.isInstalled(c)))return;let l=this.findInRegistry(c);if(!l){i.push(c);return}for(let u of l.depends??[])o(u,f);s.find(u=>u.name===l.name)||s.push(l)};for(let c of t)o(c);if(i.length>0)return{output:`E: Unable to locate package ${i.join(", ")}`,exitCode:100};if(s.length===0)return{output:t.map(c=>`${c} is already the newest version.`).join(`
380
- `),exitCode:0};let a=s.reduce((c,f)=>c+(f.installedSizeKb??0),0);e.quiet||r.push("Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","The following NEW packages will be installed:",` ${s.map(c=>c.name).join(" ")}`,`0 upgraded, ${s.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 s){e.quiet||(r.push(`Selecting previously unselected package ${c.name}.`),r.push("(Reading database ... 12345 files and directories currently installed.)"),r.push(`Preparing to unpack .../archives/${c.name}_${c.version}_amd64.deb ...`),r.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||r.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",s.map(c=>c.name)),this.persist(),e.quiet||r.push("Processing triggers for man-db (2.11.2-2) ..."),{output:r.join(`
435
+ `);this.vfs.writeFile(this.aptLogPath,s+i)}findInRegistry(t){return vc.find(e=>e.name.toLowerCase()===t.toLowerCase())}listAvailable(){return[...vc].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 r=[],s=[],i=[],o=(c,l=new Set)=>{if(l.has(c)||(l.add(c),this.isInstalled(c)))return;let f=this.findInRegistry(c);if(!f){i.push(c);return}for(let u of f.depends??[])o(u,l);s.find(u=>u.name===f.name)||s.push(f)};for(let c of t)o(c);if(i.length>0)return{output:`E: Unable to locate package ${i.join(", ")}`,exitCode:100};if(s.length===0)return{output:t.map(c=>`${c} is already the newest version.`).join(`
436
+ `),exitCode:0};let a=s.reduce((c,l)=>c+(l.installedSizeKb??0),0);e.quiet||r.push("Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","The following NEW packages will be installed:",` ${s.map(c=>c.name).join(" ")}`,`0 upgraded, ${s.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 s){e.quiet||(r.push(`Selecting previously unselected package ${c.name}.`),r.push("(Reading database ... 12345 files and directories currently installed.)"),r.push(`Preparing to unpack .../archives/${c.name}_${c.version}_amd64.deb ...`),r.push(`Unpacking ${c.name} (${c.version}) ...`));for(let f of c.files??[]){let u=f.path.slice(0,f.path.lastIndexOf("/"));u&&!this.vfs.exists(u)&&this.vfs.mkdir(u,493),this.vfs.writeFile(f.path,f.content,{mode:f.mode??420})}c.onInstall?.(this.vfs,this.users),e.quiet||r.push(`Setting up ${c.name} (${c.version}) ...`);let l=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:l,files:(c.files??[]).map(f=>f.path)}),this.log(`install ${c.name} ${c.version}`)}return this.aptLog("install",s.map(c=>c.name)),this.persist(),e.quiet||r.push("Processing triggers for man-db (2.11.2-2) ..."),{output:r.join(`
381
437
  `),exitCode:0}}remove(t,e={}){let r=[],s=[];for(let i of t){let o=this.installed.get(i.toLowerCase());o?s.push(o):r.push(`Package '${i}' is not installed, so not removed`)}if(s.length===0)return{output:r.join(`
382
438
  `)||"Nothing to remove.",exitCode:0};e.quiet||r.push("Reading package lists... Done","Building dependency tree... Done","The following packages will be REMOVED:",` ${s.map(i=>i.name).join(" ")}`,`0 upgraded, 0 newly installed, ${s.length} to remove and 0 not upgraded.`);for(let i of s){e.quiet||r.push(`Removing ${i.name} (${i.version}) ...`);for(let a of i.files)if(!(!e.purge&&(a.startsWith("/etc/")||a.endsWith(".conf"))))try{this.vfs.exists(a)&&this.vfs.remove(a)}catch{}this.findInRegistry(i.name)?.onRemove?.(this.vfs),this.installed.delete(i.name),this.log(`remove ${i.name} ${i.version}`)}return this.aptLog("remove",s.map(i=>i.name)),this.persist(),{output:r.join(`
383
- `),exitCode:0}}search(t){let e=t.toLowerCase();return bc.filter(r=>r.name.includes(e)||r.description.toLowerCase().includes(e)||(r.shortDesc??"").toLowerCase().includes(e)).sort((r,s)=>r.name.localeCompare(s.name))}show(t){let e=this.findInRegistry(t);if(!e)return null;let r=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: ${r?"install ok installed":"install ok not-installed"}`].join(`
384
- `)}};var yn=require("node:crypto"),Ph=require("node:events"),Th=Kt(require("node:path"),1);function gE(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var Nt=ln("VirtualUserManager"),qi=class n extends Ph.EventEmitter{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;Nt.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=gE();usersPath="/etc/htpasswd";sudoersPath="/etc/sudoers";quotasPath="/etc/quotas";authDirPath="/.virtual-env-js/.auth";users=new Map;sudoers=new Set;quotas=new Map;activeSessions=new Map;nextTty=0;async initialize(){Nt.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(Nt.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){Nt.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return Nt.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){Nt.mark("getUsageBytes");let r=`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,s){Nt.mark("assertWriteWithinQuota");let i=this.quotas.get(e);if(i===void 0)return;let o=Nh(r),a=Nh(`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let f=this.getUsageBytes(e),l=0;if(this.vfs.exists(o)){let p=this.vfs.stat(o);p.type==="file"&&(l=p.size)}let u=Buffer.isBuffer(s)?s.length:Buffer.byteLength(s,"utf8"),h=f-l+u;if(h>i)throw new Error(`quota exceeded for '${e}': ${h}/${i} bytes`)}verifyPassword(e,r){Nt.mark("verifyPassword");let s=this.users.get(e);if(!s)return this.hashPassword(r,""),!1;let i=this.hashPassword(r,s.salt),o=s.passwordHash;try{let a=Buffer.from(i,"hex"),c=Buffer.from(o,"hex");return a.length!==c.length?!1:(0,yn.timingSafeEqual)(a,c)}catch{return i===o}}async addUser(e,r){if(Nt.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 s=`/home/${e}`;this.vfs.exists(s)||(this.vfs.mkdir(s,493),this.vfs.writeFile(`${s}/README.txt`,`Welcome to the virtual environment, ${e}`)),await this.persist(),this.emit("user:add",{username:e})}getPasswordHash(e){Nt.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(Nt.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(Nt.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 Nt.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(Nt.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(Nt.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){Nt.mark("registerSession");let s={id:(0,yn.randomUUID)(),username:e,tty:`pts/${this.nextTty++}`,remoteAddress:r,startedAt:new Date().toISOString()};return this.activeSessions.set(s.id,s),this.emit("session:register",{sessionId:s.id,username:e,remoteAddress:r}),s}unregisterSession(e){if(Nt.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,s){if(Nt.mark("updateSession"),!e)return;let i=this.activeSessions.get(e);i&&this.activeSessions.set(e,{...i,username:r,remoteAddress:s})}listActiveSessions(){return Nt.mark("listActiveSessions"),Array.from(this.activeSessions.values()).sort((e,r)=>e.startedAt.localeCompare(r.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 r of e.split(`
439
+ `),exitCode:0}}search(t){let e=t.toLowerCase();return vc.filter(r=>r.name.includes(e)||r.description.toLowerCase().includes(e)||(r.shortDesc??"").toLowerCase().includes(e)).sort((r,s)=>r.name.localeCompare(s.name))}show(t){let e=this.findInRegistry(t);if(!e)return null;let r=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: ${r?"install ok installed":"install ok not-installed"}`].join(`
440
+ `)}};var wn=require("node:crypto"),Oh=require("node:events"),Fh=zt(require("node:path"),1);function Dy(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var Tt=hn("VirtualUserManager"),zi=class n extends Oh.EventEmitter{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;Tt.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=Dy();usersPath="/etc/htpasswd";sudoersPath="/etc/sudoers";quotasPath="/etc/quotas";authDirPath="/.virtual-env-js/.auth";users=new Map;sudoers=new Set;quotas=new Map;activeSessions=new Map;nextTty=0;async initialize(){Tt.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(Tt.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){Tt.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return Tt.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){Tt.mark("getUsageBytes");let r=`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,s){Tt.mark("assertWriteWithinQuota");let i=this.quotas.get(e);if(i===void 0)return;let o=Mh(r),a=Mh(`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let l=this.getUsageBytes(e),f=0;if(this.vfs.exists(o)){let p=this.vfs.stat(o);p.type==="file"&&(f=p.size)}let u=Buffer.isBuffer(s)?s.length:Buffer.byteLength(s,"utf8"),h=l-f+u;if(h>i)throw new Error(`quota exceeded for '${e}': ${h}/${i} bytes`)}verifyPassword(e,r){Tt.mark("verifyPassword");let s=this.users.get(e);if(!s)return this.hashPassword(r,""),!1;let i=this.hashPassword(r,s.salt),o=s.passwordHash;try{let a=Buffer.from(i,"hex"),c=Buffer.from(o,"hex");return a.length!==c.length?!1:(0,wn.timingSafeEqual)(a,c)}catch{return i===o}}async addUser(e,r){if(Tt.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 s=`/home/${e}`;this.vfs.exists(s)||(this.vfs.mkdir(s,493),this.vfs.writeFile(`${s}/README.txt`,`Welcome to the virtual environment, ${e}`)),await this.persist(),this.emit("user:add",{username:e})}getPasswordHash(e){Tt.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(Tt.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(Tt.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 Tt.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(Tt.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(Tt.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){Tt.mark("registerSession");let s={id:(0,wn.randomUUID)(),username:e,tty:`pts/${this.nextTty++}`,remoteAddress:r,startedAt:new Date().toISOString()};return this.activeSessions.set(s.id,s),this.emit("session:register",{sessionId:s.id,username:e,remoteAddress:r}),s}unregisterSession(e){if(Tt.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,s){if(Tt.mark("updateSession"),!e)return;let i=this.activeSessions.get(e);i&&this.activeSessions.set(e,{...i,username:r,remoteAddress:s})}listActiveSessions(){return Tt.mark("listActiveSessions"),Array.from(this.activeSessions.values()).sort((e,r)=>e.startedAt.localeCompare(r.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 r of e.split(`
385
441
  `)){let s=r.trim();if(s.length===0)continue;let i=s.split(":");if(i.length<3)continue;let[o,a,c]=i;!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(`
386
442
  `)){let s=r.trim();s.length>0&&this.sudoers.add(s)}}loadQuotasFromVfs(){if(this.quotas.clear(),!this.vfs.exists(this.quotasPath))return;let e=this.vfs.readFile(this.quotasPath);for(let r of e.split(`
387
443
  `)){let s=r.trim();if(s.length===0)continue;let[i,o]=s.split(":"),a=Number.parseInt(o??"",10);!i||!Number.isFinite(a)||a<0||this.quotas.set(i,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(`
@@ -390,45 +446,45 @@ echo 'neofetch: virtual stub'
390
446
  `),i=!1;i=this.writeIfChanged(this.usersPath,e.length>0?`${e}
391
447
  `:"",384)||i,i=this.writeIfChanged(this.sudoersPath,r.length>0?`${r}
392
448
  `:"",384)||i,i=this.writeIfChanged(this.quotasPath,s.length>0?`${s}
393
- `:"",384)||i,i&&await this.vfs.flushMirror()}writeIfChanged(e,r,s){return this.vfs.exists(e)&&this.vfs.readFile(e)===r?(this.vfs.chmod(e,s),!1):(this.vfs.writeFile(e,r,{mode:s}),!0)}createRecord(e,r){let s=(0,yn.createHash)("sha256").update(e).update(":").update(r).digest("hex"),i=n.recordCache.get(s);if(i)return i;let o=(0,yn.randomBytes)(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r,o)};return n.recordCache.set(s,a),a}hasPassword(e){Nt.mark("hasPassword");let r=this.users.get(e);if(!r)return!1;let s=this.hashPassword("",r.salt);return r.passwordHash===s?!1:!!r.passwordHash}hashPassword(e,r=""){return n.fastPasswordHash?(0,yn.createHash)("sha256").update(r).update(e).digest("hex"):(0,yn.scryptSync)(e,r||"",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,s){Nt.mark("addAuthorizedKey");let i=this.authorizedKeys.get(e)??[];i.push({algo:r,data:s}),this.authorizedKeys.set(e,i),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 Nh(n){let t=Th.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}var Xr=require("node:fs/promises"),Sc=Kt(require("node:path"),1);var Oh=require("node:child_process");var Lh=require("node:fs/promises"),oo=Kt(require("node:path"),1);function xc(n){return`'${n.replace(/'/g,"'\\''")}'`}function Ki(n){return n.replace(/\r\n/g,`
449
+ `:"",384)||i,i&&await this.vfs.flushMirror()}writeIfChanged(e,r,s){return this.vfs.exists(e)&&this.vfs.readFile(e)===r?(this.vfs.chmod(e,s),!1):(this.vfs.writeFile(e,r,{mode:s}),!0)}createRecord(e,r){let s=(0,wn.createHash)("sha256").update(e).update(":").update(r).digest("hex"),i=n.recordCache.get(s);if(i)return i;let o=(0,wn.randomBytes)(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r,o)};return n.recordCache.set(s,a),a}hasPassword(e){Tt.mark("hasPassword");let r=this.users.get(e);if(!r)return!1;let s=this.hashPassword("",r.salt);return r.passwordHash===s?!1:!!r.passwordHash}hashPassword(e,r=""){return n.fastPasswordHash?(0,wn.createHash)("sha256").update(r).update(e).digest("hex"):(0,wn.scryptSync)(e,r||"",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,s){Tt.mark("addAuthorizedKey");let i=this.authorizedKeys.get(e)??[];i.push({algo:r,data:s}),this.authorizedKeys.set(e,i),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 Mh(n){let t=Fh.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}var ei=require("node:fs/promises"),Rc=zt(require("node:path"),1);var Vh=require("node:child_process");var Hh=require("node:fs/promises"),uo=zt(require("node:path"),1);function Bc(n){return`'${n.replace(/'/g,"'\\''")}'`}function Gi(n){return n.replace(/\r\n/g,`
394
450
  `).replace(/\r/g,`
395
451
  `).replace(/\n/g,`\r
396
- `)}function Dh(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 Uh(n,t){return!t||t.trim()===""||t==="."?n:t.startsWith("/")?oo.posix.normalize(t):oo.posix.normalize(oo.posix.join(n,t))}async function $h(n){try{let e=(await(0,Lh.readFile)(`/proc/${n}/task/${n}/children`,"utf8")).trim().split(/\s+/).filter(Boolean).map(s=>Number.parseInt(s,10)).filter(s=>Number.isInteger(s)&&s>0),r=await Promise.all(e.map(s=>$h(s)));return[...e,...r.flat()]}catch{return[]}}async function Mh(n=process.pid){let t=await $h(n),e=Array.from(new Set(t)).sort((r,s)=>r-s);return e.length===0?null:e.join(",")}function Fh(n,t,e){let r=Dh(n,t),s=(0,Oh.spawn)("script",["-qfec",r,"/dev/null"],{stdio:["pipe","pipe","pipe"],env:{...process.env,TERM:process.env.TERM??"xterm-256color"}});return s.stdout.on("data",i=>{e.write(i.toString("utf8"))}),s.stderr.on("data",i=>{e.write(i.toString("utf8"))}),s}function Hh(n,t,e){return Fh(`nano -- ${xc(n)}`,t,e)}function Qh(n,t,e){return Fh(`htop -p ${xc(n)}`,t,e)}function Wh(n,t,e){let r=[`Linux ${n} ${t.kernel} ${t.arch}`,"","The programs included with the Fortune GNU/Linux system are free software;","the exact distribution terms for each program are described in the","individual files in /usr/share/doc/*/copyright.","","Fortune GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent","permitted by applicable law."];if(e){let s=new Date(e.at),i=Number.isNaN(s.getTime())?e.at:cs(s);r.push(`Last login: ${i} from ${e.from||"unknown"}`)}return r.push(""),`${r.map(s=>`${s}\r
397
- `).join("")}`}function qh(n,t,e){let r=n==="root",s=r?"\x1B[31;1m":"\x1B[35;1m",i="\x1B[37;1m",o="\x1B[34;1m",a="\x1B[0m";return`${i}[${s}${n}${i}@${o}${t}${a} ${e}${i}]${a}${r?"#":"$"} `}function Kh(n,t,e,r,s,i="unknown",o={cols:80,rows:24},a){let c="",f=0,l=mE(a.vfs,e),u=null,h="",p=`/home/${e}`,_=vr(e,r),E=null,b=null,v=()=>{let B=`/home/${e}`,T=p===B?"~":Sc.posix.basename(p)||"/";return qh(e,r,T)},U=Array.from(new Set(wo())).sort();console.log(`[${s}] Shell started for user '${e}' at ${i}`),(async()=>{let B=`/home/${e}/.bashrc`;if(a.vfs.exists(B))try{let T=a.vfs.readFile(B);for(let q of T.split(`
398
- `)){let ee=q.trim();!ee||ee.startsWith("#")||await yt(ee,e,r,"shell",p,a,void 0,_)}}catch{}})();function H(){let B=v();t.write(`\r${B}${c}\x1B[K`);let T=c.length-f;T>0&&t.write(`\x1B[${T}D`)}function C(){t.write("\r\x1B[K")}function F(B){b={...B,buffer:""},C(),t.write(B.prompt)}async function V(B){if(!b)return;let T=b;if(b=null,!B){t.write(`\r
452
+ `)}function Qh(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 Wh(n,t){return!t||t.trim()===""||t==="."?n:t.startsWith("/")?uo.posix.normalize(t):uo.posix.normalize(uo.posix.join(n,t))}async function qh(n){try{let e=(await(0,Hh.readFile)(`/proc/${n}/task/${n}/children`,"utf8")).trim().split(/\s+/).filter(Boolean).map(s=>Number.parseInt(s,10)).filter(s=>Number.isInteger(s)&&s>0),r=await Promise.all(e.map(s=>qh(s)));return[...e,...r.flat()]}catch{return[]}}async function Kh(n=process.pid){let t=await qh(n),e=Array.from(new Set(t)).sort((r,s)=>r-s);return e.length===0?null:e.join(",")}function zh(n,t,e){let r=Qh(n,t),s=(0,Vh.spawn)("script",["-qfec",r,"/dev/null"],{stdio:["pipe","pipe","pipe"],env:{...process.env,TERM:process.env.TERM??"xterm-256color"}});return s.stdout.on("data",i=>{e.write(i.toString("utf8"))}),s.stderr.on("data",i=>{e.write(i.toString("utf8"))}),s}function Gh(n,t,e){return zh(`nano -- ${Bc(n)}`,t,e)}function Yh(n,t,e){return zh(`htop -p ${Bc(n)}`,t,e)}function jh(n,t,e){let r=[`Linux ${n} ${t.kernel} ${t.arch}`,"","The programs included with the Fortune GNU/Linux system are free software;","the exact distribution terms for each program are described in the","individual files in /usr/share/doc/*/copyright.","","Fortune GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent","permitted by applicable law."];if(e){let s=new Date(e.at),i=Number.isNaN(s.getTime())?e.at:hs(s);r.push(`Last login: ${i} from ${e.from||"unknown"}`)}return r.push(""),`${r.map(s=>`${s}\r
453
+ `).join("")}`}function Xh(n,t,e){let r=n==="root",s=r?"\x1B[31;1m":"\x1B[35;1m",i="\x1B[37;1m",o="\x1B[34;1m",a="\x1B[0m";return`${i}[${s}${n}${i}@${o}${t}${a} ${e}${i}]${a}${r?"#":"$"} `}function Jh(n,t,e,r,s,i="unknown",o={cols:80,rows:24},a){let c="",l=0,f=Uy(a.vfs,e),u=null,h="",p=`/home/${e}`,A=Nr(e,r),E=null,S=null,x=()=>{let N=`/home/${e}`,L=p===N?"~":Rc.posix.basename(p)||"/";return Xh(e,r,L)},R=Array.from(new Set(No())).sort();console.log(`[${s}] Shell started for user '${e}' at ${i}`),(async()=>{let N=`/home/${e}/.bashrc`;if(a.vfs.exists(N))try{let L=a.vfs.readFile(N);for(let K of L.split(`
454
+ `)){let ee=K.trim();!ee||ee.startsWith("#")||await St(ee,e,r,"shell",p,a,void 0,A)}}catch{}})();function H(){let N=x();t.write(`\r${N}${c}\x1B[K`);let L=c.length-l;L>0&&t.write(`\x1B[${L}D`)}function C(){t.write("\r\x1B[K")}function U(N){S={...N,buffer:""},C(),t.write(N.prompt)}async function Q(N){if(!S)return;let L=S;if(S=null,!N){t.write(`\r
399
455
  Sorry, try again.\r
400
- `),H();return}if(!T.commandLine){e=T.targetUser,T.loginShell&&(p=`/home/${e}`),a.users.updateSession(s,e,i),t.write(`\r
401
- `),H();return}let q=T.loginShell?`/home/${T.targetUser}`:p,ee=await Promise.resolve(yt(T.commandLine,T.targetUser,r,"shell",q,a));if(t.write(`\r
402
- `),ee.openEditor){await x(ee.openEditor.targetPath,ee.openEditor.initialContent,ee.openEditor.tempPath);return}if(ee.openHtop){await S();return}ee.clearScreen&&t.write("\x1B[2J\x1B[H"),ee.stdout&&t.write(`${Ki(ee.stdout)}\r
403
- `),ee.stderr&&t.write(`${Ki(ee.stderr)}\r
404
- `),ee.switchUser?(e=ee.switchUser,p=ee.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i)):ee.nextCwd&&(p=ee.nextCwd),await a.vfs.flushMirror(),H()}async function N(){if(!E)return;let B=E;if(B.kind==="nano"){try{let T=await(0,Xr.readFile)(B.tempPath,"utf8");a.writeFileAsUser(e,B.targetPath,T),await a.vfs.flushMirror()}catch{}await(0,Xr.unlink)(B.tempPath).catch(()=>{})}E=null,c="",f=0,t.write(`\r
405
- `),H()}async function x(B,T,q){a.vfs.exists(B)&&await(0,Xr.writeFile)(q,T,"utf8");let ee=Hh(q,o,t);ee.on("error",fe=>{t.write(`nano: ${fe.message}\r
406
- `),N()}),ee.on("close",()=>{N()}),E={kind:"nano",targetPath:B,tempPath:q,process:ee}}async function S(){let B=await Mh();if(!B){t.write(`htop: no child_process processes to display\r
407
- `);return}let T=Qh(B,o,t);T.on("error",q=>{t.write(`htop: ${q.message}\r
408
- `),N()}),T.on("close",()=>{N()}),E={kind:"htop",targetPath:"",tempPath:"",process:T}}function I(B){c=B,f=c.length,H()}function k(B){c=`${c.slice(0,f)}${B}${c.slice(f)}`,f+=B.length,H()}function R(B,T){let q=T;for(;q>0&&!/\s/.test(B[q-1]);)q-=1;let ee=T;for(;ee<B.length&&!/\s/.test(B[ee]);)ee+=1;return{start:q,end:ee}}function ne(B){let T=B.lastIndexOf("/"),q=T>=0?B.slice(0,T+1):"",ee=T>=0?B.slice(T+1):B,fe=Uh(p,q||".");try{return a.vfs.list(fe).filter(ie=>!ie.startsWith(".")).filter(ie=>ie.startsWith(ee)).map(ie=>{let je=Sc.posix.join(fe,ie),nn=a.vfs.stat(je).type==="directory"?"/":"";return`${q}${ie}${nn}`}).sort()}catch{return[]}}function z(){let{start:B,end:T}=R(c,f),q=c.slice(B,f);if(q.length===0)return;let fe=c.slice(0,B).trim().length===0?U.filter(ft=>ft.startsWith(q)):[],ie=ne(q),je=Array.from(new Set([...fe,...ie])).sort();if(je.length!==0){if(je.length===1){let ft=je[0],nn=ft.endsWith("/")?"":" ";c=`${c.slice(0,B)}${ft}${nn}${c.slice(T)}`,f=B+ft.length+nn.length,H();return}t.write(`\r
409
- `),t.write(`${je.join(" ")}\r
410
- `),H()}}function Y(B){if(B.length===0)return;l.push(B),l.length>500&&(l=l.slice(l.length-500));let T=l.length>0?`${l.join(`
456
+ `),H();return}if(!L.commandLine){e=L.targetUser,L.loginShell&&(p=`/home/${e}`),a.users.updateSession(s,e,i),t.write(`\r
457
+ `),H();return}let K=L.loginShell?`/home/${L.targetUser}`:p,ee=await Promise.resolve(St(L.commandLine,L.targetUser,r,"shell",K,a));if(t.write(`\r
458
+ `),ee.openEditor){await b(ee.openEditor.targetPath,ee.openEditor.initialContent,ee.openEditor.tempPath);return}if(ee.openHtop){await w();return}ee.clearScreen&&t.write("\x1B[2J\x1B[H"),ee.stdout&&t.write(`${Gi(ee.stdout)}\r
459
+ `),ee.stderr&&t.write(`${Gi(ee.stderr)}\r
460
+ `),ee.switchUser?(e=ee.switchUser,p=ee.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i)):ee.nextCwd&&(p=ee.nextCwd),await a.vfs.flushMirror(),H()}async function B(){if(!E)return;let N=E;if(N.kind==="nano"){try{let L=await(0,ei.readFile)(N.tempPath,"utf8");a.writeFileAsUser(e,N.targetPath,L),await a.vfs.flushMirror()}catch{}await(0,ei.unlink)(N.tempPath).catch(()=>{})}E=null,c="",l=0,t.write(`\r
461
+ `),H()}async function b(N,L,K){a.vfs.exists(N)&&await(0,ei.writeFile)(K,L,"utf8");let ee=Gh(K,o,t);ee.on("error",ue=>{t.write(`nano: ${ue.message}\r
462
+ `),B()}),ee.on("close",()=>{B()}),E={kind:"nano",targetPath:N,tempPath:K,process:ee}}async function w(){let N=await Kh();if(!N){t.write(`htop: no child_process processes to display\r
463
+ `);return}let L=Yh(N,o,t);L.on("error",K=>{t.write(`htop: ${K.message}\r
464
+ `),B()}),L.on("close",()=>{B()}),E={kind:"htop",targetPath:"",tempPath:"",process:L}}function k(N){c=N,l=c.length,H()}function v(N){c=`${c.slice(0,l)}${N}${c.slice(l)}`,l+=N.length,H()}function P(N,L){let K=L;for(;K>0&&!/\s/.test(N[K-1]);)K-=1;let ee=L;for(;ee<N.length&&!/\s/.test(N[ee]);)ee+=1;return{start:K,end:ee}}function ne(N){let L=N.lastIndexOf("/"),K=L>=0?N.slice(0,L+1):"",ee=L>=0?N.slice(L+1):N,ue=Wh(p,K||".");try{return a.vfs.list(ue).filter(ie=>!ie.startsWith(".")).filter(ie=>ie.startsWith(ee)).map(ie=>{let Xe=Rc.posix.join(ue,ie),on=a.vfs.stat(Xe).type==="directory"?"/":"";return`${K}${ie}${on}`}).sort()}catch{return[]}}function G(){let{start:N,end:L}=P(c,l),K=c.slice(N,l);if(K.length===0)return;let ue=c.slice(0,N).trim().length===0?R.filter(ft=>ft.startsWith(K)):[],ie=ne(K),Xe=Array.from(new Set([...ue,...ie])).sort();if(Xe.length!==0){if(Xe.length===1){let ft=Xe[0],on=ft.endsWith("/")?"":" ";c=`${c.slice(0,N)}${ft}${on}${c.slice(L)}`,l=N+ft.length+on.length,H();return}t.write(`\r
465
+ `),t.write(`${Xe.join(" ")}\r
466
+ `),H()}}function Y(N){if(N.length===0)return;f.push(N),f.length>500&&(f=f.slice(f.length-500));let L=f.length>0?`${f.join(`
411
467
  `)}
412
- `:"";a.vfs.writeFile(`/home/${e}/.bash_history`,T)}function te(){let B=`/home/${e}/.lastlog.json`;if(!a.vfs.exists(B))return null;try{return JSON.parse(a.vfs.readFile(B))}catch{return null}}function ce(B){let T=`/home/${e}/.lastlog`;a.vfs.writeFile(T,JSON.stringify({at:B,from:i}))}function $(){let B=te(),T=new Date().toISOString();t.write(Wh(r,n,B)),ce(T)}$(),H(),t.on("data",async B=>{if(E){E.process.stdin.write(B);return}if(b){let q=B.toString("utf8");for(let ee=0;ee<q.length;ee+=1){let fe=q[ee];if(fe===""){b=null,t.write(`^C\r
413
- `),H();return}if(fe==="\x7F"||fe==="\b"){b.buffer=b.buffer.slice(0,-1);continue}if(fe==="\r"||fe===`
414
- `){let ie=b.buffer;if(b.buffer="",b.onPassword){let{result:ft,nextPrompt:nn}=await b.onPassword(ie,a);t.write(`\r
415
- `),ft!==null?(b=null,ft.stdout&&t.write(ft.stdout.replace(/\n/g,`\r
468
+ `:"";a.vfs.writeFile(`/home/${e}/.bash_history`,L)}function te(){let N=`/home/${e}/.lastlog.json`;if(!a.vfs.exists(N))return null;try{return JSON.parse(a.vfs.readFile(N))}catch{return null}}function le(N){let L=`/home/${e}/.lastlog`;a.vfs.writeFile(L,JSON.stringify({at:N,from:i}))}function M(){let N=te(),L=new Date().toISOString();t.write(jh(r,n,N)),le(L)}M(),H(),t.on("data",async N=>{if(E){E.process.stdin.write(N);return}if(S){let K=N.toString("utf8");for(let ee=0;ee<K.length;ee+=1){let ue=K[ee];if(ue===""){S=null,t.write(`^C\r
469
+ `),H();return}if(ue==="\x7F"||ue==="\b"){S.buffer=S.buffer.slice(0,-1);continue}if(ue==="\r"||ue===`
470
+ `){let ie=S.buffer;if(S.buffer="",S.onPassword){let{result:ft,nextPrompt:on}=await S.onPassword(ie,a);t.write(`\r
471
+ `),ft!==null?(S=null,ft.stdout&&t.write(ft.stdout.replace(/\n/g,`\r
416
472
  `)),ft.stderr&&t.write(ft.stderr.replace(/\n/g,`\r
417
- `)),H()):(nn&&(b.prompt=nn),t.write(b.prompt));return}let je=a.users.verifyPassword(b.username,ie);await V(je);return}fe>=" "&&(b.buffer+=fe)}return}let T=B.toString("utf8");for(let q=0;q<T.length;q+=1){let ee=T[q];if(ee===""){c="",f=0,u=null,h="",t.write(`bye\r
473
+ `)),H()):(on&&(S.prompt=on),t.write(S.prompt));return}let Xe=a.users.verifyPassword(S.username,ie);await Q(Xe);return}ue>=" "&&(S.buffer+=ue)}return}let L=N.toString("utf8");for(let K=0;K<L.length;K+=1){let ee=L[K];if(ee===""){c="",l=0,u=null,h="",t.write(`bye\r
418
474
  `),Y("bye"),await a.vfs.flushMirror(),t.write(`logout\r
419
- `),t.exit(0),t.end();return}if(ee===" "){z();continue}if(ee==="\x1B"){let fe=T[q+1],ie=T[q+2],je=T[q+3];if(fe==="["&&ie){if(ie==="A"){q+=2,l.length>0&&(u===null?(h=c,u=l.length-1):u>0&&(u-=1),I(l[u]??""));continue}if(ie==="B"){q+=2,u!==null&&(u<l.length-1?(u+=1,I(l[u]??"")):(u=null,I(h)));continue}if(ie==="C"){q+=2,f<c.length&&(f+=1,t.write("\x1B[C"));continue}if(ie==="D"){q+=2,f>0&&(f-=1,t.write("\x1B[D"));continue}if(ie==="3"&&je==="~"){q+=3,f<c.length&&(c=`${c.slice(0,f)}${c.slice(f+1)}`,H());continue}}}if(ee===""){c="",f=0,u=null,h="",t.write(`^C\r
475
+ `),t.exit(0),t.end();return}if(ee===" "){G();continue}if(ee==="\x1B"){let ue=L[K+1],ie=L[K+2],Xe=L[K+3];if(ue==="["&&ie){if(ie==="A"){K+=2,f.length>0&&(u===null?(h=c,u=f.length-1):u>0&&(u-=1),k(f[u]??""));continue}if(ie==="B"){K+=2,u!==null&&(u<f.length-1?(u+=1,k(f[u]??"")):(u=null,k(h)));continue}if(ie==="C"){K+=2,l<c.length&&(l+=1,t.write("\x1B[C"));continue}if(ie==="D"){K+=2,l>0&&(l-=1,t.write("\x1B[D"));continue}if(ie==="3"&&Xe==="~"){K+=3,l<c.length&&(c=`${c.slice(0,l)}${c.slice(l+1)}`,H());continue}}}if(ee===""){c="",l=0,u=null,h="",t.write(`^C\r
420
476
  `),H();continue}if(ee==="\r"||ee===`
421
- `){let fe=c.trim();if(c="",f=0,u=null,h="",t.write(`\r
422
- `),fe.length>0){let ie=await Promise.resolve(yt(fe,e,r,"shell",p,a,void 0,_));if(Y(fe),ie.openEditor){await x(ie.openEditor.targetPath,ie.openEditor.initialContent,ie.openEditor.tempPath);return}if(ie.openHtop){await S();return}if(ie.sudoChallenge){F(ie.sudoChallenge);return}if(ie.clearScreen&&t.write("\x1B[2J\x1B[H"),ie.stdout&&t.write(`${Ki(ie.stdout)}\r
423
- `),ie.stderr&&t.write(`${Ki(ie.stderr)}\r
477
+ `){let ue=c.trim();if(c="",l=0,u=null,h="",t.write(`\r
478
+ `),ue.length>0){let ie=await Promise.resolve(St(ue,e,r,"shell",p,a,void 0,A));if(Y(ue),ie.openEditor){await b(ie.openEditor.targetPath,ie.openEditor.initialContent,ie.openEditor.tempPath);return}if(ie.openHtop){await w();return}if(ie.sudoChallenge){U(ie.sudoChallenge);return}if(ie.clearScreen&&t.write("\x1B[2J\x1B[H"),ie.stdout&&t.write(`${Gi(ie.stdout)}\r
479
+ `),ie.stderr&&t.write(`${Gi(ie.stderr)}\r
424
480
  `),ie.closeSession){t.write(`logout\r
425
- `),t.exit(ie.exitCode??0),t.end();return}ie.nextCwd&&(p=ie.nextCwd),ie.switchUser&&(e=ie.switchUser,p=ie.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i),c="",f=0),await a.vfs.flushMirror()}H();continue}if(ee==="\x7F"||ee==="\b"){f>0&&(c=`${c.slice(0,f-1)}${c.slice(f)}`,f-=1,H());continue}k(ee)}}),t.on("close",()=>{E&&(E.process.kill("SIGTERM"),E=null)})}function mE(n,t){let e=`/home/${t}/.bash_history`;return n.exists(e)?n.readFile(e).split(`
426
- `).map(s=>s.trim()).filter(s=>s.length>0):(n.writeFile(e,""),[])}function AE(n){return typeof n=="object"&&n!==null&&"vfsInstance"in n&&Gh(n.vfsInstance)}function Gh(n){if(typeof n!="object"||n===null)return!1;let t=n;return typeof t.restoreMirror=="function"&&typeof t.flushMirror=="function"&&typeof t.writeFile=="function"&&typeof t.readFile=="function"&&typeof t.mkdir=="function"&&typeof t.exists=="function"&&typeof t.stat=="function"&&typeof t.list=="function"&&typeof t.remove=="function"&&typeof t.copy=="function"&&typeof t.move=="function"&&typeof t.touch=="function"}var EE={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},Vi=ln("VirtualShell");function yE(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var Wn=class extends Vh.EventEmitter{vfs;users;packageManager;hostname;properties;startTime;initialized;constructor(t,e,r){super(),Vi.mark("constructor"),this.hostname=t,this.properties=e||EE,this.startTime=Date.now(),Gh(r)?this.vfs=r:AE(r)?this.vfs=r.vfsInstance:this.vfs=new _c(r??{}),this.users=new qi(this.vfs,yE()),this.packageManager=new Wi(this.vfs,this.users);let s=this.vfs,i=this.users,o=this.packageManager,a=this.properties,c=this.hostname,f=this.startTime;this.initialized=(async()=>{await s.restoreMirror(),await i.initialize(),xh(s,i,c,a,f),o.load(),this.emit("initialized")})()}async ensureInitialized(){Vi.mark("ensureInitialized"),await this.initialized}addCommand(t,e,r){let s=t.trim().toLowerCase();if(s.length===0||/\s/.test(s))throw new Error("Command name must be non-empty and contain no spaces");xo(So(s,e,r))}executeCommand(t,e,r){Vi.mark("executeCommand"),yt(t,e,this.hostname,"shell",r,this),this.emit("command",{command:t,user:e,cwd:r})}startInteractiveSession(t,e,r,s,i){Vi.mark("startInteractiveSession"),this.emit("session:start",{user:e,sessionId:r,remoteAddress:s}),Kh(this.properties,t,e,this.hostname,r,s,i,this),this.refreshProcSessions()}refreshProcFs(){io(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}refreshProcSessions(){io(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){gc(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,r){Vi.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,r),this.vfs.writeFile(e,r)}};function zh(n){return n.replace(/\r\n/g,`
481
+ `),t.exit(ie.exitCode??0),t.end();return}ie.nextCwd&&(p=ie.nextCwd),ie.switchUser&&(e=ie.switchUser,p=ie.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i),c="",l=0),await a.vfs.flushMirror()}H();continue}if(ee==="\x7F"||ee==="\b"){l>0&&(c=`${c.slice(0,l-1)}${c.slice(l)}`,l-=1,H());continue}v(ee)}}),t.on("close",()=>{E&&(E.process.kill("SIGTERM"),E=null)})}function Uy(n,t){let e=`/home/${t}/.bash_history`;return n.exists(e)?n.readFile(e).split(`
482
+ `).map(s=>s.trim()).filter(s=>s.length>0):(n.writeFile(e,""),[])}function My(n){return typeof n=="object"&&n!==null&&"vfsInstance"in n&&ep(n.vfsInstance)}function ep(n){if(typeof n!="object"||n===null)return!1;let t=n;return typeof t.restoreMirror=="function"&&typeof t.flushMirror=="function"&&typeof t.writeFile=="function"&&typeof t.readFile=="function"&&typeof t.mkdir=="function"&&typeof t.exists=="function"&&typeof t.stat=="function"&&typeof t.list=="function"&&typeof t.remove=="function"&&typeof t.copy=="function"&&typeof t.move=="function"&&typeof t.touch=="function"}var Oy={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},Yi=hn("VirtualShell");function Fy(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var Kn=class extends Zh.EventEmitter{vfs;users;packageManager;hostname;properties;startTime;initialized;constructor(t,e,r){super(),Yi.mark("constructor"),this.hostname=t,this.properties=e||Oy,this.startTime=Date.now(),ep(r)?this.vfs=r:My(r)?this.vfs=r.vfsInstance:this.vfs=new kc(r??{}),this.users=new zi(this.vfs,Fy()),this.packageManager=new Vi(this.vfs,this.users);let s=this.vfs,i=this.users,o=this.packageManager,a=this.properties,c=this.hostname,l=this.startTime;this.initialized=(async()=>{await s.restoreMirror(),await i.initialize(),Bh(s,i,c,a,l),o.load(),this.emit("initialized")})()}async ensureInitialized(){Yi.mark("ensureInitialized"),await this.initialized}addCommand(t,e,r){let s=t.trim().toLowerCase();if(s.length===0||/\s/.test(s))throw new Error("Command name must be non-empty and contain no spaces");Bo(Ro(s,e,r))}executeCommand(t,e,r){Yi.mark("executeCommand"),St(t,e,this.hostname,"shell",r,this),this.emit("command",{command:t,user:e,cwd:r})}startInteractiveSession(t,e,r,s,i){Yi.mark("startInteractiveSession"),this.emit("session:start",{user:e,sessionId:r,remoteAddress:s}),Jh(this.properties,t,e,this.hostname,r,s,i,this),this.refreshProcSessions()}refreshProcFs(){lo(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}mount(t,e,r={}){this.vfs.mount(t,e,r)}unmount(t){this.vfs.unmount(t)}getMounts(){return this.vfs.getMounts()}refreshProcSessions(){lo(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){Sc(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,r){Yi.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,r),this.vfs.writeFile(e,r)}};function tp(n){return n.replace(/\r\n/g,`
427
483
  `).replace(/\r/g,`
428
484
  `).replace(/\n/g,`\r
429
- `)}function Yh(n,t,e,r,s){Promise.resolve(yt(t,e,r,"exec",`/home/${e}`,s,void 0,vr(e,r))).then(i=>{i.stdout&&n.write(`${zh(i.stdout)}\r
430
- `),i.stderr&&n.stderr.write(`${zh(i.stderr)}\r
485
+ `)}function np(n,t,e,r,s){Promise.resolve(St(t,e,r,"exec",`/home/${e}`,s,void 0,Nr(e,r))).then(i=>{i.stdout&&n.write(`${tp(i.stdout)}\r
486
+ `),i.stderr&&n.stderr.write(`${tp(i.stderr)}\r
431
487
  `),n.exit(i.exitCode??0),s.vfs.flushMirror(),n.end()}).catch(i=>{console.error("Exec error:",i),n.stderr.write(`Error: ${String(i)}\r
432
- `),n.exit(1),n.end()})}var jh=require("node:crypto"),rr=require("node:fs"),ao=require("node:path");function co(n=process.cwd()){let t=(0,ao.resolve)(n,".ssh-mimic","host_rsa");if((0,rr.existsSync)(t))return(0,rr.readFileSync)(t,"utf8");let e=(0,jh.generateKeyPairSync)("rsa",{modulusLength:2048,privateKeyEncoding:{type:"pkcs1",format:"pem"},publicKeyEncoding:{type:"pkcs1",format:"pem"}}).privateKey;return(0,rr.mkdirSync)((0,ao.dirname)(t),{recursive:!0}),(0,rr.writeFileSync)(t,e,{mode:384}),e}var Xh=require("node:events"),ei=Kt(require("node:path"),1),Jh=Kt(pc(),1);var Ic=!!process.env.DEV_MODE,Jr=Ic?console.log.bind(console):()=>{},Rn=Ic?console.warn.bind(console):()=>{},Gi=Ic?console.error.bind(console):()=>{},Fe={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},Zr={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},wc=ln("SftpMimic"),ti=class extends Xh.EventEmitter{port;server;hostname;shell;vfs;users;nextHandleId=0;handles=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r,vfs:s,users:i}){if(super(),wc.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(s&&i)this.vfs=s,this.users=i;else{let o=new Wn(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(){wc.mark("start");let t=co();return this.shell?await this.shell.ensureInitialized():await this.users.initialize(),this.server=new Jh.Server({hostKeys:[t],ident:`SSH-2.0-${this.hostname}`},e=>{let r=["password","keyboard-interactive"],s="root",i=null,o="unknown";this.emit("client:connect"),e.on("error",c=>{Gi("[SFTP] Client error:",c)});let a=c=>{s=c,i=this.getUsers().registerSession(s,o).id;let f="/home";this.getVfs().exists(f)||this.getVfs().mkdir(f,493);let l=`/home/${s}`;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,Jr(`[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:s,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:s,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:s,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(r);return}a(f),this.emit("auth:success",{username:s,remoteAddress:o}),l.accept()});return}c.reject(r)}),e.on("close",()=>{this.getUsers().unregisterSession(i),this.emit("client:disconnect",{user:s}),i=null}),e.on("ready",()=>{e.on("session",(c,f)=>{let l=c();l.on("error",u=>{Gi(`[SFTP] Session error for user=${s}:`,u)}),l.on("sftp",u=>{let h=u();this.attachSftpHandlers(h,s)})})})}),new Promise((e,r)=>{this.server?.once("error",s=>r(s)),this.server?.listen(this.port,"0.0.0.0",()=>{let s=this.server?.address(),i=s&&typeof s=="object"&&"port"in s?s.port:this.port;Jr(`SFTP Mimic listening on port ${i}`),this.emit("start",{port:i}),e(i)})})}stop(){wc.mark("stop"),this.server&&this.server.close(()=>{Jr("SFTP Mimic stopped"),this.emit("stop")})}resolveRequestPath(t,e){let r=`/home/${e}`;if(!t||t===".")return r;if(!t.startsWith("/")){let s=ei.posix.join(r,t);return ei.posix.normalize(s)}return ei.posix.normalize(t)}isPathWithinHome(t,e){let r=`/home/${e}`,s=ei.posix.normalize(t);return!!(s===r||s.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(),s=()=>this.getUsers();t.on("OPEN",(i,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(i,Fe.PERMISSION_DENIED);return}let f=a,l=!!(f&Zr.READ),u=!!(f&Zr.WRITE||f&Zr.APPEND),h=!!(f&Zr.CREAT),p=!!(f&Zr.TRUNC);try{if(!r().exists(c)){if(!h){t.status(i,Fe.NO_SUCH_FILE);return}r().writeFile(c,Buffer.alloc(0))}if(r().stat(c).type==="directory"){t.status(i,Fe.FAILURE);return}let E=Buffer.from(r().readFile(c),"utf8");if(p&&(E=Buffer.alloc(0)),f&Zr.APPEND){let v=this.openHandle({type:"file",path:c,flags:f,buffer:E});t.handle(i,v);return}let b=this.openHandle({type:"file",path:c,flags:f,buffer:E});t.handle(i,b)}catch(_){Gi("SFTP OPEN error:",_),t.status(i,Fe.FAILURE)}}),t.on("READ",(i,o,a,c)=>{let f=this.getHandle(o);if(!f||f.type!=="file"){t.status(i,Fe.FAILURE);return}if(a>=f.buffer.length){t.status(i,Fe.EOF);return}let l=f.buffer.slice(a,a+c);t.data(i,l)}),t.on("WRITE",async(i,o,a,c)=>{let f=this.getHandle(o);if(!f||f.type!=="file"){t.status(i,Fe.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(i,Fe.OK)}),t.on("FSTAT",(i,o)=>{let a=this.getHandle(o);if(!a){t.status(i,Fe.FAILURE);return}try{let c=r().stat(a.path);t.attrs(i,this.createAttrs(c))}catch{t.status(i,Fe.FAILURE)}}),t.on("CLOSE",async(i,o)=>{let a=this.getHandle(o);if(!a){t.status(i,Fe.FAILURE);return}if(a.type==="file")try{s().assertWriteWithinQuota(e,a.path,a.buffer),r().writeFile(a.path,a.buffer),r().flushMirror()}catch(c){Gi("SFTP CLOSE write error:",c),t.status(i,Fe.FAILURE),this.closeHandle(o);return}this.closeHandle(o),t.status(i,Fe.OK)}),t.on("OPENDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,Fe.PERMISSION_DENIED);return}try{if(r().stat(a).type!=="directory"){t.status(i,Fe.FAILURE);return}let f=r().list(a),l=this.openHandle({type:"dir",path:a,entries:f,index:0});t.handle(i,l)}catch{t.status(i,Fe.NO_SUCH_FILE)}}),t.on("READDIR",(i,o)=>{let a=this.getHandle(o);if(!a||a.type!=="dir"){t.status(i,Fe.FAILURE);return}if(a.index>=a.entries.length){t.status(i,Fe.EOF);return}let c=a.entries[a.index++],f=ei.posix.join(a.path,c),l=r().stat(f),u=this.createAttrs(l),h=`${l.type==="directory"?"d":"-"}${(l.mode&511).toString(8)} ${c}`;return t.name(i,[{filename:c,longname:h,attrs:u}])}),t.on("STAT",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,Fe.PERMISSION_DENIED);return}try{let c=r().stat(a);t.attrs(i,this.createAttrs(c))}catch{t.status(i,Fe.NO_SUCH_FILE)}}),t.on("LSTAT",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,Fe.PERMISSION_DENIED);return}try{let c=r().stat(a);t.attrs(i,this.createAttrs(c))}catch{t.status(i,Fe.NO_SUCH_FILE)}}),t.on("FSETSTAT",(i,o,a)=>{let c=this.getHandle(o);if(!c){t.status(i,Fe.FAILURE);return}try{a.mode!==void 0&&r().chmod(c.path,a.mode),t.status(i,Fe.OK)}catch{t.status(i,Fe.FAILURE)}}),t.on("SETSTAT",(i,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(i,Fe.PERMISSION_DENIED);return}try{a.mode!==void 0&&r().chmod(c,a.mode),t.status(i,Fe.OK)}catch{t.status(i,Fe.FAILURE)}}),t.on("REALPATH",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,Fe.PERMISSION_DENIED);return}t.name(i,[{filename:a,longname:a,attrs:{mode:16877,uid:0,gid:0,size:0,atime:0,mtime:0}}])}),t.on("MKDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,Fe.PERMISSION_DENIED);return}try{r().mkdir(a,493),r().flushMirror(),t.status(i,Fe.OK)}catch{t.status(i,Fe.FAILURE)}}),t.on("RMDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,Fe.PERMISSION_DENIED);return}try{r().remove(a,{recursive:!1}),r().flushMirror(),t.status(i,Fe.OK)}catch{t.status(i,Fe.FAILURE)}}),t.on("REMOVE",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,Fe.PERMISSION_DENIED);return}try{r().remove(a,{recursive:!1}),r().flushMirror(),t.status(i,Fe.OK)}catch{t.status(i,Fe.FAILURE)}}),t.on("RENAME",(i,o,a)=>{let c=this.resolveRequestPath(o,e),f=this.resolveRequestPath(a,e);if(!this.isPathWithinHome(c,e)||!this.isPathWithinHome(f,e)){Rn(`[SFTP] Path traversal attempt blocked: user=${e}, from=${c}, to=${f}`),t.status(i,Fe.PERMISSION_DENIED);return}try{r().move(c,f),r().flushMirror(),t.status(i,Fe.OK)}catch{t.status(i,Fe.FAILURE)}}),t.on("READLINK",i=>{t.status(i,Fe.OP_UNSUPPORTED)}),t.on("SYMLINK",i=>{t.status(i,Fe.OP_UNSUPPORTED)}),t.on("error",i=>{Gi(`[SFTP] Stream error for user=${e}:`,i)}),t.on("close",()=>{Jr(`[SFTP] Stream closed for user=${e}`),this.handles.clear()}),t.on("end",()=>{Jr(`[SFTP] end event for user=${e}`),this.handles.clear()}),t.on("END",()=>{Jr(`[SFTP] END event for user=${e}`),this.handles.clear()})}};var Cc=ln("SshMimic"),_E=!!process.env.DEV_MODE,Zh=_E?console.log.bind(console):()=>{},zi=class extends ep.EventEmitter{port;server;shell;maxAuthAttempts;lockoutDurationMs;authAttempts=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r=new Wn(e),maxAuthAttempts:s=5,lockoutDurationMs:i=6e4}){super(),Cc.mark("constructor"),this.port=t,this.server=null,this.shell=r,this.maxAuthAttempts=s,this.lockoutDurationMs=i}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}
433
- `),this.shell.vfs.flushMirror())}async start(){Cc.mark("start");let t=this.shell,e=co();return await t.ensureInitialized(),this.server=new tp.Server({hostKeys:[e],ident:`SSH-2.0-${t.hostname}`},r=>{let s="root",i="unknown",o=null;this.emit("client:connect"),r.on("authentication",a=>{let c=a.username||"root";if(i=a.ip??i,this.isLockedOut(i)){this.emit("auth:failure",{username:c,remoteAddress:i,reason:"lockout"}),a.reject();return}if(a.method==="password"){if(!t.users.hasPassword(c)){s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i}),this.ensureHomeDir(s),a.accept();return}if(!a.password||a.password===""||!t.users.verifyPassword(c,a.password)){this.recordFailure(i),this.emit("auth:failure",{username:c,remoteAddress:i}),a.reject();return}s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i}),this.ensureHomeDir(s),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(i),this.emit("auth:failure",{username:c,remoteAddress:i,method:"publickey"}),a.reject();return}a.signature&&(s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i,method:"publickey"}),this.ensureHomeDir(s)),a.accept();return}a.reject(["password","publickey"])}),r.on("close",()=>{t.users.unregisterSession(o),this.emit("client:disconnect",{user:s}),o=null}),r.on("ready",()=>{r.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,s,o,i,f)}),c.on("exec",(l,u,h)=>{let p=l();p&&Yh(p,h.command.trim(),s,t.hostname,t)})})})}),new Promise((r,s)=>{this.server?.once("error",i=>s(i)),this.server?.listen(this.port,"0.0.0.0",()=>{Zh(`SSH Mimic listening on port ${this.port}`),this.emit("start",{port:this.port}),r(this.port)})})}stop(){Cc.mark("stop"),this.server&&this.server.close(()=>{Zh("SSH Mimic stopped"),this.emit("stop")})}clearLockout(t){this.authAttempts.delete(t)}};var vc=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",kc=new Wn(vc,void 0,{mode:"fs",snapshotPath:".vfs"});kc.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));new zi({port:2222,hostname:vc,shell:kc}).start().catch(n=>{console.error("Failed to start SSH Mimic:",n),process.exit(1)});new ti({port:2223,hostname:vc,shell:kc}).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)});
488
+ `),n.exit(1),n.end()})}var rp=require("node:crypto"),or=require("node:fs"),ho=require("node:path");function po(n=process.cwd()){let t=(0,ho.resolve)(n,".ssh-mimic","host_rsa");if((0,or.existsSync)(t))return(0,or.readFileSync)(t,"utf8");let e=(0,rp.generateKeyPairSync)("rsa",{modulusLength:2048,privateKeyEncoding:{type:"pkcs1",format:"pem"},publicKeyEncoding:{type:"pkcs1",format:"pem"}}).privateKey;return(0,or.mkdirSync)((0,ho.dirname)(t),{recursive:!0}),(0,or.writeFileSync)(t,e,{mode:384}),e}var ip=require("node:events"),ri=zt(require("node:path"),1),sp=zt(bc(),1);var Pc=!!process.env.DEV_MODE,ti=Pc?console.log.bind(console):()=>{},Pn=Pc?console.warn.bind(console):()=>{},ji=Pc?console.error.bind(console):()=>{},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},ni={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},Nc=hn("SftpMimic"),ii=class extends ip.EventEmitter{port;server;hostname;shell;vfs;users;nextHandleId=0;handles=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r,vfs:s,users:i}){if(super(),Nc.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(s&&i)this.vfs=s,this.users=i;else{let o=new Kn(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(){Nc.mark("start");let t=po();return this.shell?await this.shell.ensureInitialized():await this.users.initialize(),this.server=new sp.Server({hostKeys:[t],ident:`SSH-2.0-${this.hostname}`},e=>{let r=["password","keyboard-interactive"],s="root",i=null,o="unknown";this.emit("client:connect"),e.on("error",c=>{ji("[SFTP] Client error:",c)});let a=c=>{s=c,i=this.getUsers().registerSession(s,o).id;let l="/home";this.getVfs().exists(l)||this.getVfs().mkdir(l,493);let f=`/home/${s}`;this.getVfs().exists(f)||(this.getVfs().mkdir(f,493),this.getVfs().writeFile(`${f}/README.txt`,`Welcome to ${this.hostname}`),this.getVfs().flushMirror())};e.on("authentication",c=>{let l=c.username||"root";if(o=c.ip??o,ti(`[SFTP] Auth attempt: user=${l}, method=${c.method}, ip=${o}`),c.method==="password"){if(!this.getUsers().hasPassword(l)){a(l),this.emit("auth:success",{username:s,remoteAddress:o}),c.accept();return}if(!this.getUsers().verifyPassword(l,c.password??"")){this.emit("auth:failure",{username:l,remoteAddress:o}),c.reject(r);return}a(l),this.emit("auth:success",{username:s,remoteAddress:o}),c.accept();return}if(c.method==="keyboard-interactive"){let f=c;if(!this.getUsers().hasPassword(l)){a(l),this.emit("auth:success",{username:s,remoteAddress:o}),f.accept();return}f.prompt([{prompt:"Password: ",echo:!1}],u=>{let h=u[0]??"";if(!this.getUsers().verifyPassword(l,h)){this.emit("auth:failure",{username:l,remoteAddress:o}),f.reject(r);return}a(l),this.emit("auth:success",{username:s,remoteAddress:o}),f.accept()});return}c.reject(r)}),e.on("close",()=>{this.getUsers().unregisterSession(i),this.emit("client:disconnect",{user:s}),i=null}),e.on("ready",()=>{e.on("session",(c,l)=>{let f=c();f.on("error",u=>{ji(`[SFTP] Session error for user=${s}:`,u)}),f.on("sftp",u=>{let h=u();this.attachSftpHandlers(h,s)})})})}),new Promise((e,r)=>{this.server?.once("error",s=>r(s)),this.server?.listen(this.port,"0.0.0.0",()=>{let s=this.server?.address(),i=s&&typeof s=="object"&&"port"in s?s.port:this.port;ti(`SFTP Mimic listening on port ${i}`),this.emit("start",{port:i}),e(i)})})}stop(){Nc.mark("stop"),this.server&&this.server.close(()=>{ti("SFTP Mimic stopped"),this.emit("stop")})}resolveRequestPath(t,e){let r=`/home/${e}`;if(!t||t===".")return r;if(!t.startsWith("/")){let s=ri.posix.join(r,t);return ri.posix.normalize(s)}return ri.posix.normalize(t)}isPathWithinHome(t,e){let r=`/home/${e}`,s=ri.posix.normalize(t);return!!(s===r||s.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(),s=()=>this.getUsers();t.on("OPEN",(i,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(i,He.PERMISSION_DENIED);return}let l=a,f=!!(l&ni.READ),u=!!(l&ni.WRITE||l&ni.APPEND),h=!!(l&ni.CREAT),p=!!(l&ni.TRUNC);try{if(!r().exists(c)){if(!h){t.status(i,He.NO_SUCH_FILE);return}r().writeFile(c,Buffer.alloc(0))}if(r().stat(c).type==="directory"){t.status(i,He.FAILURE);return}let E=Buffer.from(r().readFile(c),"utf8");if(p&&(E=Buffer.alloc(0)),l&ni.APPEND){let x=this.openHandle({type:"file",path:c,flags:l,buffer:E});t.handle(i,x);return}let S=this.openHandle({type:"file",path:c,flags:l,buffer:E});t.handle(i,S)}catch(A){ji("SFTP OPEN error:",A),t.status(i,He.FAILURE)}}),t.on("READ",(i,o,a,c)=>{let l=this.getHandle(o);if(!l||l.type!=="file"){t.status(i,He.FAILURE);return}if(a>=l.buffer.length){t.status(i,He.EOF);return}let f=l.buffer.slice(a,a+c);t.data(i,f)}),t.on("WRITE",async(i,o,a,c)=>{let l=this.getHandle(o);if(!l||l.type!=="file"){t.status(i,He.FAILURE);return}let f=a+c.length;if(f>l.buffer.length){let u=Buffer.alloc(f);l.buffer.copy(u,0,0,l.buffer.length),l.buffer=u}c.copy(l.buffer,a),t.status(i,He.OK)}),t.on("FSTAT",(i,o)=>{let a=this.getHandle(o);if(!a){t.status(i,He.FAILURE);return}try{let c=r().stat(a.path);t.attrs(i,this.createAttrs(c))}catch{t.status(i,He.FAILURE)}}),t.on("CLOSE",async(i,o)=>{let a=this.getHandle(o);if(!a){t.status(i,He.FAILURE);return}if(a.type==="file")try{s().assertWriteWithinQuota(e,a.path,a.buffer),r().writeFile(a.path,a.buffer),r().flushMirror()}catch(c){ji("SFTP CLOSE write error:",c),t.status(i,He.FAILURE),this.closeHandle(o);return}this.closeHandle(o),t.status(i,He.OK)}),t.on("OPENDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{if(r().stat(a).type!=="directory"){t.status(i,He.FAILURE);return}let l=r().list(a),f=this.openHandle({type:"dir",path:a,entries:l,index:0});t.handle(i,f)}catch{t.status(i,He.NO_SUCH_FILE)}}),t.on("READDIR",(i,o)=>{let a=this.getHandle(o);if(!a||a.type!=="dir"){t.status(i,He.FAILURE);return}if(a.index>=a.entries.length){t.status(i,He.EOF);return}let c=a.entries[a.index++],l=ri.posix.join(a.path,c),f=r().stat(l),u=this.createAttrs(f),h=`${f.type==="directory"?"d":"-"}${(f.mode&511).toString(8)} ${c}`;return t.name(i,[{filename:c,longname:h,attrs:u}])}),t.on("STAT",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{let c=r().stat(a);t.attrs(i,this.createAttrs(c))}catch{t.status(i,He.NO_SUCH_FILE)}}),t.on("LSTAT",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{let c=r().stat(a);t.attrs(i,this.createAttrs(c))}catch{t.status(i,He.NO_SUCH_FILE)}}),t.on("FSETSTAT",(i,o,a)=>{let c=this.getHandle(o);if(!c){t.status(i,He.FAILURE);return}try{a.mode!==void 0&&r().chmod(c.path,a.mode),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("SETSTAT",(i,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(i,He.PERMISSION_DENIED);return}try{a.mode!==void 0&&r().chmod(c,a.mode),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("REALPATH",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}t.name(i,[{filename:a,longname:a,attrs:{mode:16877,uid:0,gid:0,size:0,atime:0,mtime:0}}])}),t.on("MKDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{r().mkdir(a,493),r().flushMirror(),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("RMDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{r().remove(a,{recursive:!1}),r().flushMirror(),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("REMOVE",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{r().remove(a,{recursive:!1}),r().flushMirror(),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("RENAME",(i,o,a)=>{let c=this.resolveRequestPath(o,e),l=this.resolveRequestPath(a,e);if(!this.isPathWithinHome(c,e)||!this.isPathWithinHome(l,e)){Pn(`[SFTP] Path traversal attempt blocked: user=${e}, from=${c}, to=${l}`),t.status(i,He.PERMISSION_DENIED);return}try{r().move(c,l),r().flushMirror(),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("READLINK",i=>{t.status(i,He.OP_UNSUPPORTED)}),t.on("SYMLINK",i=>{t.status(i,He.OP_UNSUPPORTED)}),t.on("error",i=>{ji(`[SFTP] Stream error for user=${e}:`,i)}),t.on("close",()=>{ti(`[SFTP] Stream closed for user=${e}`),this.handles.clear()}),t.on("end",()=>{ti(`[SFTP] end event for user=${e}`),this.handles.clear()}),t.on("END",()=>{ti(`[SFTP] END event for user=${e}`),this.handles.clear()})}};var Tc=hn("SshMimic"),Hy=!!process.env.DEV_MODE,op=Hy?console.log.bind(console):()=>{},Xi=class extends ap.EventEmitter{port;server;shell;maxAuthAttempts;lockoutDurationMs;authAttempts=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r=new Kn(e),maxAuthAttempts:s=5,lockoutDurationMs:i=6e4}){super(),Tc.mark("constructor"),this.port=t,this.server=null,this.shell=r,this.maxAuthAttempts=s,this.lockoutDurationMs=i}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}
489
+ `),this.shell.vfs.flushMirror())}async start(){Tc.mark("start");let t=this.shell,e=po();return await t.ensureInitialized(),this.server=new cp.Server({hostKeys:[e],ident:`SSH-2.0-${t.hostname}`},r=>{let s="root",i="unknown",o=null;this.emit("client:connect"),r.on("authentication",a=>{let c=a.username||"root";if(i=a.ip??i,this.isLockedOut(i)){this.emit("auth:failure",{username:c,remoteAddress:i,reason:"lockout"}),a.reject();return}if(a.method==="password"){if(!t.users.hasPassword(c)){s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i}),this.ensureHomeDir(s),a.accept();return}if(!a.password||a.password===""||!t.users.verifyPassword(c,a.password)){this.recordFailure(i),this.emit("auth:failure",{username:c,remoteAddress:i}),a.reject();return}s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i}),this.ensureHomeDir(s),a.accept();return}if(a.method==="publickey"){let l=t.users.getAuthorizedKeys(c);if(l.length===0){a.reject();return}let f=a.key;if(!l.some(h=>h.algo===f.algo&&h.data.equals(f.data))){this.recordFailure(i),this.emit("auth:failure",{username:c,remoteAddress:i,method:"publickey"}),a.reject();return}a.signature&&(s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i,method:"publickey"}),this.ensureHomeDir(s)),a.accept();return}a.reject(["password","publickey"])}),r.on("close",()=>{t.users.unregisterSession(o),this.emit("client:disconnect",{user:s}),o=null}),r.on("ready",()=>{r.on("session",a=>{let c=a(),l={cols:80,rows:24};c.on("pty",(f,u,h)=>{l.cols=h?.cols??l.cols,l.rows=h?.rows??l.rows,f()}),c.on("window-change",(f,u,h)=>{l.cols=h?.cols??l.cols,l.rows=h?.rows??l.rows}),c.on("shell",f=>{let u=f();t?.startInteractiveSession(u,s,o,i,l)}),c.on("exec",(f,u,h)=>{let p=f();p&&np(p,h.command.trim(),s,t.hostname,t)})})})}),new Promise((r,s)=>{this.server?.once("error",i=>s(i)),this.server?.listen(this.port,"0.0.0.0",()=>{op(`SSH Mimic listening on port ${this.port}`),this.emit("start",{port:this.port}),r(this.port)})})}stop(){Tc.mark("stop"),this.server&&this.server.close(()=>{op("SSH Mimic stopped"),this.emit("stop")})}clearLockout(t){this.authAttempts.delete(t)}};var Lc=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",$c=new Kn(Lc,void 0,{mode:"fs",snapshotPath:".vfs"});$c.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));new Xi({port:2222,hostname:Lc,shell:$c}).start().catch(n=>{console.error("Failed to start SSH Mimic:",n),process.exit(1)});new ii({port:2223,hostname:Lc,shell:$c}).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)});
434
490
  //# sourceMappingURL=standalone.js.map